├── .clang-format ├── .editorconfig ├── .eslintrc.js ├── .gitattributes ├── .github ├── PULL_REQUEST_TEMPLATE.md ├── actions │ └── setup │ │ └── action.yml └── workflows │ ├── ci.yml │ └── verify-android.yaml ├── .gitignore ├── .husky └── pre-commit ├── .nvmrc ├── .watchmanconfig ├── .yarn ├── plugins │ └── @yarnpkg │ │ ├── plugin-interactive-tools.cjs │ │ └── plugin-workspace-tools.cjs └── releases │ └── yarn-3.6.1.cjs ├── .yarnrc.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── android ├── CMakeLists.txt ├── build.gradle ├── consumer-rules.pro ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ ├── fabric │ └── com │ │ └── fastsecurestorage │ │ └── FastSecureStorageModule.kt │ ├── main │ ├── AndroidManifest.xml │ ├── AndroidManifestNew.xml │ ├── cpp │ │ └── cpp-adapter.cpp │ └── java │ │ └── com │ │ └── fastsecurestorage │ │ ├── FastSecureStorageImpl.kt │ │ └── FastSecureStoragePackage.kt │ └── paper │ └── com │ └── fastsecurestorage │ └── FastSecureStorageModule.kt ├── babel.config.js ├── clang.sh ├── cpp ├── SecureStorageHostObject.cpp ├── SecureStorageHostObject.h └── macros.h ├── example ├── .bundle │ └── config ├── .watchmanconfig ├── Gemfile ├── README.md ├── android │ ├── app │ │ ├── build.gradle │ │ ├── debug.keystore │ │ ├── proguard-rules.pro │ │ └── src │ │ │ ├── debug │ │ │ └── AndroidManifest.xml │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── fastsecurestorage │ │ │ │ └── example │ │ │ │ ├── MainActivity.kt │ │ │ │ └── MainApplication.kt │ │ │ └── res │ │ │ ├── drawable │ │ │ └── rn_edit_text_material.xml │ │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ └── values │ │ │ ├── strings.xml │ │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── react-native-fast-secure-storage │ │ └── cpp │ │ │ ├── .gitignore │ │ │ ├── build.gradle.kts │ │ │ ├── proguard-rules.pro │ │ │ └── src │ │ │ ├── androidTest │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── cpp │ │ │ │ └── ExampleInstrumentedTest.kt │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ └── res │ │ │ │ ├── drawable │ │ │ │ ├── ic_launcher_background.xml │ │ │ │ └── ic_launcher_foreground.xml │ │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ │ ├── values-night │ │ │ │ └── themes.xml │ │ │ │ └── values │ │ │ │ ├── colors.xml │ │ │ │ ├── strings.xml │ │ │ │ └── themes.xml │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── cpp │ │ │ └── ExampleUnitTest.kt │ └── settings.gradle ├── app.json ├── babel.config.js ├── index.js ├── ios │ ├── .xcode.env │ ├── FastSecureStorageExample.xcodeproj │ │ ├── project.pbxproj │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── FastSecureStorageExample.xcscheme │ ├── FastSecureStorageExample.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ ├── FastSecureStorageExample │ │ ├── AppDelegate.h │ │ ├── AppDelegate.mm │ │ ├── Images.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ └── Contents.json │ │ ├── Info.plist │ │ ├── LaunchScreen.storyboard │ │ ├── PrivacyInfo.xcprivacy │ │ └── main.m │ ├── FastSecureStorageExampleTests │ │ ├── FastSecureStorageExampleTests.m │ │ └── Info.plist │ ├── Podfile │ └── Podfile.lock ├── jest.config.js ├── metro.config.js ├── package.json ├── react-native.config.js └── src │ ├── App.tsx │ └── Reactangle.tsx ├── ios ├── FastSecureStorage.h ├── FastSecureStorage.mm ├── SecureStorage.h └── SecureStorage.mm ├── jest └── index.js ├── package.json ├── react-native-fast-secure-storage.podspec ├── src ├── SecureStorage.ts ├── __tests__ │ └── index.test.tsx ├── enums.ts ├── index.tsx ├── spec │ └── NativeFastSecureStorage.ts └── types.ts ├── tsconfig.build.json ├── tsconfig.json ├── turbo.json └── yarn.lock /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | AccessModifierOffset: -1 3 | AlignAfterOpenBracket: AlwaysBreak 4 | AlignConsecutiveAssignments: false 5 | AlignConsecutiveDeclarations: false 6 | AlignEscapedNewlinesLeft: true 7 | AlignOperands: false 8 | AlignTrailingComments: false 9 | AllowAllParametersOfDeclarationOnNextLine: false 10 | AllowShortBlocksOnASingleLine: false 11 | AllowShortCaseLabelsOnASingleLine: false 12 | AllowShortFunctionsOnASingleLine: Empty 13 | AllowShortIfStatementsOnASingleLine: false 14 | AllowShortLoopsOnASingleLine: false 15 | AlwaysBreakAfterReturnType: None 16 | AlwaysBreakBeforeMultilineStrings: true 17 | AlwaysBreakTemplateDeclarations: true 18 | BinPackArguments: false 19 | BinPackParameters: false 20 | BraceWrapping: 21 | AfterClass: false 22 | AfterControlStatement: false 23 | AfterEnum: false 24 | AfterFunction: false 25 | AfterNamespace: false 26 | AfterObjCDeclaration: false 27 | AfterStruct: false 28 | AfterUnion: false 29 | BeforeCatch: false 30 | BeforeElse: false 31 | IndentBraces: false 32 | BreakBeforeBinaryOperators: None 33 | BreakBeforeBraces: Attach 34 | BreakBeforeTernaryOperators: true 35 | BreakConstructorInitializersBeforeComma: false 36 | BreakAfterJavaFieldAnnotations: false 37 | BreakStringLiterals: false 38 | ColumnLimit: 80 39 | CommentPragmas: "^ IWYU pragma:" 40 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 41 | ConstructorInitializerIndentWidth: 4 42 | ContinuationIndentWidth: 4 43 | Cpp11BracedListStyle: true 44 | DerivePointerAlignment: false 45 | DisableFormat: false 46 | ForEachMacros: [FOR_EACH_RANGE, FOR_EACH] 47 | IncludeCategories: 48 | - Regex: '^<.*\.h(pp)?>' 49 | Priority: 1 50 | - Regex: "^<.*" 51 | Priority: 2 52 | - Regex: ".*" 53 | Priority: 3 54 | IndentCaseLabels: true 55 | IndentWidth: 2 56 | IndentWrappedFunctionNames: false 57 | KeepEmptyLinesAtTheStartOfBlocks: false 58 | MacroBlockBegin: "" 59 | MacroBlockEnd: "" 60 | MaxEmptyLinesToKeep: 1 61 | NamespaceIndentation: None 62 | ObjCBlockIndentWidth: 2 63 | ObjCSpaceAfterProperty: true 64 | ObjCSpaceBeforeProtocolList: true 65 | PenaltyBreakBeforeFirstCallParameter: 1 66 | PenaltyBreakComment: 300 67 | PenaltyBreakFirstLessLess: 120 68 | PenaltyBreakString: 1000 69 | PenaltyExcessCharacter: 1000000 70 | PenaltyReturnTypeOnItsOwnLine: 200 71 | PointerAlignment: Right 72 | ReflowComments: true 73 | SortIncludes: true 74 | SpaceAfterCStyleCast: false 75 | SpaceBeforeAssignmentOperators: true 76 | SpaceBeforeParens: ControlStatements 77 | SpaceInEmptyParentheses: false 78 | SpacesBeforeTrailingComments: 1 79 | SpacesInAngles: false 80 | SpacesInContainerLiterals: true 81 | SpacesInCStyleCastParentheses: false 82 | SpacesInParentheses: false 83 | SpacesInSquareBrackets: false 84 | Standard: Cpp11 85 | TabWidth: 8 86 | UseTab: Never 87 | --- 88 | Language: ObjC 89 | ColumnLimit: 100 90 | BreakBeforeBraces: WebKit -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | 9 | indent_style = space 10 | indent_size = 2 11 | 12 | end_of_line = lf 13 | charset = utf-8 14 | trim_trailing_whitespace = true 15 | insert_final_newline = true 16 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | plugins: [ 4 | "@typescript-eslint", 5 | "eslint-comments", 6 | "import", 7 | "jest", 8 | "jest", 9 | "prettier", 10 | "react-native", 11 | "react-perf", 12 | "react", 13 | ], 14 | extends: [ 15 | "@react-native", 16 | "prettier", 17 | "eslint:recommended", 18 | "plugin:@typescript-eslint/recommended", 19 | "plugin:import/typescript", 20 | "plugin:eslint-comments/recommended", 21 | "plugin:react-perf/recommended", 22 | ], 23 | settings: { 24 | "import/parsers": { 25 | "@typescript-eslint/parser": [".ts", ".tsx"], 26 | }, 27 | "import/resolver": { 28 | typescript: { 29 | alwaysTryTypes: true, 30 | project: "/tsconfig.json", 31 | }, 32 | }, 33 | }, 34 | rules: { 35 | "prettier/prettier": [ 36 | "error", 37 | { 38 | quoteProps: "consistent", 39 | trailingComma: "all", 40 | }, 41 | ], 42 | // react-hooks 43 | "react-hooks/exhaustive-deps": "warn", 44 | // react 45 | "react/react-in-jsx-scope": "off", 46 | "react/jsx-sort-props": [ 47 | "error", 48 | { 49 | callbacksLast: true, 50 | shorthandFirst: true, 51 | shorthandLast: false, 52 | ignoreCase: true, 53 | noSortAlphabetically: false, 54 | reservedFirst: ["ref", "key"], 55 | }, 56 | ], 57 | "react/jsx-no-bind": [ 58 | "warn", 59 | { 60 | // should be an error, but we need to fix a lot of places 61 | ignoreDOMComponents: false, 62 | ignoreRefs: false, 63 | allowArrowFunctions: false, 64 | allowFunctions: false, 65 | allowBind: false, 66 | }, 67 | ], 68 | // react-perf 69 | "react-perf/jsx-no-new-function-as-prop": "off", // because we have jsx-no-bind 70 | "react-perf/jsx-no-jsx-as-prop": "warn", 71 | "react-perf/jsx-no-new-array-as-prop": "warn", 72 | "react-perf/jsx-no-new-object-as-prop": "warn", 73 | // typescript 74 | "@typescript-eslint/consistent-type-imports": [ 75 | "error", 76 | { prefer: "type-imports" }, 77 | ], 78 | "@typescript-eslint/no-import-type-side-effects": "error", 79 | "@typescript-eslint/no-var-requires": "warn", 80 | // import 81 | "sort-imports": [ 82 | "error", 83 | { 84 | // sort destructure imports 85 | ignoreCase: false, 86 | ignoreDeclarationSort: true, 87 | ignoreMemberSort: false, 88 | memberSyntaxSortOrder: ["none", "all", "single", "multiple"], 89 | allowSeparatedGroups: true, 90 | }, 91 | ], 92 | "import/order": [ 93 | "error", 94 | { 95 | "groups": [ 96 | "builtin", 97 | "external", 98 | "internal", 99 | "parent", 100 | "sibling", 101 | "index", 102 | "type", 103 | ], 104 | "alphabetize": { 105 | order: "asc", 106 | caseInsensitive: true, 107 | }, 108 | "newlines-between": "always", 109 | }, 110 | ], 111 | "import/no-cycle": ["error", { maxDepth: "∞" }], 112 | // eslint-comments 113 | "eslint-comments/no-unused-disable": "error", 114 | // eslint 115 | "curly": "error", 116 | "eqeqeq": ["error", "always"], // check “===” 117 | "no-nested-ternary": "error", 118 | "padding-line-between-statements": [ 119 | "error", 120 | { 121 | blankLine: "always", 122 | prev: "*", 123 | next: ["return", "try", "throw", "function", "for", "while", "do"], 124 | }, 125 | { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, 126 | { 127 | blankLine: "any", 128 | prev: ["const", "let", "var"], 129 | next: ["const", "let", "var"], 130 | }, 131 | { blankLine: "always", prev: "*", next: "if" }, 132 | { blankLine: "any", prev: "if", next: "if" }, 133 | ], 134 | "no-param-reassign": "error", 135 | "max-lines": ["warn", { max: 300 }], 136 | }, 137 | overrides: [ 138 | { 139 | files: ["src/specs/**"], 140 | rules: { 141 | "@typescript-eslint/ban-types": [ 142 | "error", 143 | { 144 | extendDefaults: true, 145 | types: { 146 | "{}": false, 147 | }, 148 | }, 149 | ], 150 | }, 151 | }, 152 | { 153 | files: [ 154 | "**/react-native.config.js", 155 | "**/metro.config.js", 156 | "**/babel.config.js", 157 | ], 158 | rules: { 159 | "import/no-commonjs": "off", 160 | "@typescript-eslint/no-require-imports": "off", 161 | "@typescript-eslint/no-var-requires": "off", 162 | }, 163 | }, 164 | ], 165 | env: { 166 | "react-native/react-native": true, 167 | "jest/globals": true, 168 | }, 169 | ignorePatterns: ["node_modules/**", "lib/**", "scripts/**", "docs/build/**"], 170 | }; 171 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## 📜 Description 2 | 3 | 4 | 5 | ## 💡 Motivation and Context 6 | 7 | 8 | 9 | 10 | ## 📢 Changelog 11 | 12 | 13 | 14 | 15 | 16 | ### JS 17 | 18 | - 19 | - 20 | 21 | ### iOS 22 | 23 | - 24 | - 25 | 26 | ### Android 27 | 28 | - 29 | - 30 | 31 | ## 🤔 How Has This Been Tested? 32 | 33 | 34 | 35 | 36 | 37 | ## 📸 Screenshots (if appropriate): 38 | 39 | 40 | 41 | 42 | ## 📝 Checklist 43 | 44 | - [ ] CI successfully passed -------------------------------------------------------------------------------- /.github/actions/setup/action.yml: -------------------------------------------------------------------------------- 1 | name: Setup 2 | description: Setup Node.js and install dependencies 3 | 4 | runs: 5 | using: composite 6 | steps: 7 | - name: Setup Node.js 8 | uses: actions/setup-node@v3 9 | with: 10 | node-version-file: .nvmrc 11 | 12 | - name: Cache dependencies 13 | id: yarn-cache 14 | uses: actions/cache@v4 15 | with: 16 | path: | 17 | **/node_modules 18 | .yarn/install-state.gz 19 | key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}-${{ hashFiles('**/package.json', '!node_modules/**') }} 20 | restore-keys: | 21 | ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} 22 | ${{ runner.os }}-yarn- 23 | 24 | - name: Install dependencies 25 | if: steps.yarn-cache.outputs.cache-hit != 'true' 26 | run: yarn install --immutable 27 | shell: bash 28 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: 5 | - main 6 | pull_request: 7 | branches: 8 | - main 9 | merge_group: 10 | types: 11 | - checks_requested 12 | 13 | jobs: 14 | lint: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v3 19 | 20 | - name: Setup 21 | uses: ./.github/actions/setup 22 | 23 | - name: Lint files 24 | run: yarn lint 25 | 26 | - name: Typecheck files 27 | run: yarn typecheck 28 | 29 | test: 30 | runs-on: ubuntu-latest 31 | steps: 32 | - name: Checkout 33 | uses: actions/checkout@v3 34 | 35 | - name: Setup 36 | uses: ./.github/actions/setup 37 | 38 | - name: Run unit tests 39 | run: yarn test --maxWorkers=2 --coverage 40 | 41 | build-library: 42 | runs-on: ubuntu-latest 43 | steps: 44 | - name: Checkout 45 | uses: actions/checkout@v3 46 | 47 | - name: Setup 48 | uses: ./.github/actions/setup 49 | 50 | - name: Build package 51 | run: yarn prepare 52 | 53 | build-ios: 54 | runs-on: macos-14 55 | env: 56 | TURBO_CACHE_DIR: .turbo/ios 57 | steps: 58 | - name: Checkout 59 | uses: actions/checkout@v4 60 | 61 | - name: Setup Xcode 62 | uses: maxim-lobanov/setup-xcode@v1 63 | with: 64 | xcode-version: "15.4" 65 | 66 | - name: Setup 67 | uses: ./.github/actions/setup 68 | 69 | - name: Cache turborepo for iOS 70 | uses: actions/cache@v4 71 | with: 72 | path: ${{ env.TURBO_CACHE_DIR }} 73 | key: ${{ runner.os }}-turborepo-ios-${{ hashFiles('yarn.lock') }} 74 | restore-keys: | 75 | ${{ runner.os }}-turborepo-ios- 76 | 77 | - name: Check turborepo cache for iOS 78 | run: | 79 | TURBO_CACHE_STATUS=$(node -p "($(yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status") 80 | 81 | if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then 82 | echo "turbo_cache_hit=1" >> $GITHUB_ENV 83 | fi 84 | 85 | - name: Cache cocoapods 86 | if: env.turbo_cache_hit != 1 87 | id: cocoapods-cache 88 | uses: actions/cache@v4 89 | with: 90 | path: | 91 | **/ios/Pods 92 | key: ${{ runner.os }}-cocoapods-${{ hashFiles('example/ios/Podfile.lock') }} 93 | restore-keys: | 94 | ${{ runner.os }}-cocoapods- 95 | 96 | - name: Install cocoapods 97 | run: | 98 | cd example/ios 99 | pod install 100 | env: 101 | NO_FLIPPER: 1 102 | 103 | - name: Build example for iOS 104 | run: | 105 | yarn turbo build:ios --cache-dir="{{ env.TURBO_CACHE_DIR }}" 106 | -------------------------------------------------------------------------------- /.github/workflows/verify-android.yaml: -------------------------------------------------------------------------------- 1 | name: 📱 Validate Android 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | paths: 8 | - ".github/workflows/verify-android.yml" 9 | - "android/**" 10 | - "cpp/**" 11 | pull_request: 12 | branches: 13 | - main 14 | paths: 15 | - ".github/workflows/verify-android.yml" 16 | - "android/**" 17 | - "cpp/**" 18 | 19 | jobs: 20 | ktlint: 21 | runs-on: ubuntu-latest 22 | name: 🔎 Kotlin Lint 23 | steps: 24 | - uses: actions/checkout@v4 25 | - uses: touchlab-lab/ktlint-action-setup@1.0.0 26 | with: 27 | ktlint_version: 1.3.1 28 | - run: ktlint "android/src/**/*.kt" 29 | build-android: 30 | runs-on: ubuntu-latest 31 | name: 🚀 Build Android 32 | env: 33 | TURBO_CACHE_DIR: .turbo/android 34 | steps: 35 | - name: Checkout 36 | uses: actions/checkout@v3 37 | 38 | - name: Setup 39 | uses: ./.github/actions/setup 40 | 41 | - name: Cache turborepo for Android 42 | uses: actions/cache@v4 43 | with: 44 | path: ${{ env.TURBO_CACHE_DIR }} 45 | key: ${{ runner.os }}-turborepo-android-${{ hashFiles('yarn.lock') }} 46 | restore-keys: | 47 | ${{ runner.os }}-turborepo-android- 48 | 49 | - name: Check turborepo cache for Android 50 | run: | 51 | TURBO_CACHE_STATUS=$(node -p "($(yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status") 52 | 53 | if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then 54 | echo "turbo_cache_hit=1" >> $GITHUB_ENV 55 | fi 56 | 57 | - name: Install JDK 58 | if: env.turbo_cache_hit != 1 59 | uses: actions/setup-java@v3 60 | with: 61 | distribution: 'zulu' 62 | java-version: '17' 63 | 64 | - name: Finalize Android SDK 65 | if: env.turbo_cache_hit != 1 66 | run: | 67 | /bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null" 68 | 69 | - name: Cache Gradle 70 | if: env.turbo_cache_hit != 1 71 | uses: actions/cache@v4 72 | with: 73 | path: | 74 | ~/.gradle/wrapper 75 | ~/.gradle/caches 76 | key: ${{ runner.os }}-gradle-${{ hashFiles('example/android/gradle/wrapper/gradle-wrapper.properties') }} 77 | restore-keys: | 78 | ${{ runner.os }}-gradle- 79 | 80 | - name: Build example for Android 81 | env: 82 | JAVA_OPTS: "-XX:MaxHeapSize=6g" 83 | run: | 84 | yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}" -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # XDE 6 | .expo/ 7 | 8 | # VSCode 9 | .vscode/ 10 | jsconfig.json 11 | 12 | # Xcode 13 | # 14 | build/ 15 | *.pbxuser 16 | !default.pbxuser 17 | *.mode1v3 18 | !default.mode1v3 19 | *.mode2v3 20 | !default.mode2v3 21 | *.perspectivev3 22 | !default.perspectivev3 23 | xcuserdata 24 | *.xccheckout 25 | *.moved-aside 26 | DerivedData 27 | *.hmap 28 | *.ipa 29 | *.xcuserstate 30 | project.xcworkspace 31 | .xcode.env.local 32 | 33 | # Android/IJ 34 | # 35 | .classpath 36 | .cxx 37 | .gradle 38 | .idea 39 | .project 40 | .settings 41 | local.properties 42 | android.iml 43 | 44 | # Cocoapods 45 | # 46 | example/ios/Pods 47 | 48 | # Ruby 49 | example/vendor/ 50 | 51 | # node.js 52 | # 53 | node_modules/ 54 | npm-debug.log 55 | yarn-debug.log 56 | yarn-error.log 57 | 58 | # BUCK 59 | buck-out/ 60 | \.buckd/ 61 | android/app/libs 62 | android/keystores/debug.keystore 63 | 64 | # Yarn 65 | .yarn/* 66 | !.yarn/patches 67 | !.yarn/plugins 68 | !.yarn/releases 69 | !.yarn/sdks 70 | !.yarn/versions 71 | 72 | # Expo 73 | .expo/ 74 | 75 | # Turborepo 76 | .turbo/ 77 | 78 | # generated by bob 79 | lib/ 80 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | yarn lint && yarn tsc -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v18 2 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | nodeLinker: node-modules 2 | nmHoistingLimits: workspaces 3 | 4 | plugins: 5 | - path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs 6 | spec: "@yarnpkg/plugin-interactive-tools" 7 | - path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs 8 | spec: "@yarnpkg/plugin-workspace-tools" 9 | 10 | yarnPath: .yarn/releases/yarn-3.6.1.cjs 11 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 2 | # Contributor Covenant Code of Conduct 3 | 4 | ## Our Pledge 5 | 6 | We as members, contributors, and leaders pledge to make participation in our 7 | community a harassment-free experience for everyone, regardless of age, body 8 | size, visible or invisible disability, ethnicity, sex characteristics, gender 9 | identity and expression, level of experience, education, socio-economic status, 10 | nationality, personal appearance, race, caste, color, religion, or sexual 11 | identity and orientation. 12 | 13 | We pledge to act and interact in ways that contribute to an open, welcoming, 14 | diverse, inclusive, and healthy community. 15 | 16 | ## Our Standards 17 | 18 | Examples of behavior that contributes to a positive environment for our 19 | community include: 20 | 21 | * Demonstrating empathy and kindness toward other people 22 | * Being respectful of differing opinions, viewpoints, and experiences 23 | * Giving and gracefully accepting constructive feedback 24 | * Accepting responsibility and apologizing to those affected by our mistakes, 25 | and learning from the experience 26 | * Focusing on what is best not just for us as individuals, but for the overall 27 | community 28 | 29 | Examples of unacceptable behavior include: 30 | 31 | * The use of sexualized language or imagery, and sexual attention or advances of 32 | any kind 33 | * Trolling, insulting or derogatory comments, and personal or political attacks 34 | * Public or private harassment 35 | * Publishing others' private information, such as a physical or email address, 36 | without their explicit permission 37 | * Other conduct which could reasonably be considered inappropriate in a 38 | professional setting 39 | 40 | ## Enforcement Responsibilities 41 | 42 | Community leaders are responsible for clarifying and enforcing our standards of 43 | acceptable behavior and will take appropriate and fair corrective action in 44 | response to any behavior that they deem inappropriate, threatening, offensive, 45 | or harmful. 46 | 47 | Community leaders have the right and responsibility to remove, edit, or reject 48 | comments, commits, code, wiki edits, issues, and other contributions that are 49 | not aligned to this Code of Conduct, and will communicate reasons for moderation 50 | decisions when appropriate. 51 | 52 | ## Scope 53 | 54 | This Code of Conduct applies within all community spaces, and also applies when 55 | an individual is officially representing the community in public spaces. 56 | Examples of representing our community include using an official e-mail address, 57 | posting via an official social media account, or acting as an appointed 58 | representative at an online or offline event. 59 | 60 | ## Enforcement 61 | 62 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 63 | reported to the community leaders responsible for enforcement at 64 | [INSERT CONTACT METHOD]. 65 | All complaints will be reviewed and investigated promptly and fairly. 66 | 67 | All community leaders are obligated to respect the privacy and security of the 68 | reporter of any incident. 69 | 70 | ## Enforcement Guidelines 71 | 72 | Community leaders will follow these Community Impact Guidelines in determining 73 | the consequences for any action they deem in violation of this Code of Conduct: 74 | 75 | ### 1. Correction 76 | 77 | **Community Impact**: Use of inappropriate language or other behavior deemed 78 | unprofessional or unwelcome in the community. 79 | 80 | **Consequence**: A private, written warning from community leaders, providing 81 | clarity around the nature of the violation and an explanation of why the 82 | behavior was inappropriate. A public apology may be requested. 83 | 84 | ### 2. Warning 85 | 86 | **Community Impact**: A violation through a single incident or series of 87 | actions. 88 | 89 | **Consequence**: A warning with consequences for continued behavior. No 90 | interaction with the people involved, including unsolicited interaction with 91 | those enforcing the Code of Conduct, for a specified period of time. This 92 | includes avoiding interactions in community spaces as well as external channels 93 | like social media. Violating these terms may lead to a temporary or permanent 94 | ban. 95 | 96 | ### 3. Temporary Ban 97 | 98 | **Community Impact**: A serious violation of community standards, including 99 | sustained inappropriate behavior. 100 | 101 | **Consequence**: A temporary ban from any sort of interaction or public 102 | communication with the community for a specified period of time. No public or 103 | private interaction with the people involved, including unsolicited interaction 104 | with those enforcing the Code of Conduct, is allowed during this period. 105 | Violating these terms may lead to a permanent ban. 106 | 107 | ### 4. Permanent Ban 108 | 109 | **Community Impact**: Demonstrating a pattern of violation of community 110 | standards, including sustained inappropriate behavior, harassment of an 111 | individual, or aggression toward or disparagement of classes of individuals. 112 | 113 | **Consequence**: A permanent ban from any sort of public interaction within the 114 | community. 115 | 116 | ## Attribution 117 | 118 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 119 | version 2.1, available at 120 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. 121 | 122 | Community Impact Guidelines were inspired by 123 | [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. 124 | 125 | For answers to common questions about this code of conduct, see the FAQ at 126 | [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at 127 | [https://www.contributor-covenant.org/translations][translations]. 128 | 129 | [homepage]: https://www.contributor-covenant.org 130 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html 131 | [Mozilla CoC]: https://github.com/mozilla/diversity 132 | [FAQ]: https://www.contributor-covenant.org/faq 133 | [translations]: https://www.contributor-covenant.org/translations 134 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are always welcome, no matter how large or small! 4 | 5 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. Before contributing, please read the [code of conduct](./CODE_OF_CONDUCT.md). 6 | 7 | ## Development workflow 8 | 9 | This project is a monorepo managed using [Yarn workspaces](https://yarnpkg.com/features/workspaces). It contains the following packages: 10 | 11 | - The library package in the root directory. 12 | - An example app in the `example/` directory. 13 | 14 | To get started with the project, run `yarn` in the root directory to install the required dependencies for each package: 15 | 16 | ```sh 17 | yarn 18 | ``` 19 | 20 | > Since the project relies on Yarn workspaces, you cannot use [`npm`](https://github.com/npm/cli) for development. 21 | 22 | The [example app](/example/) demonstrates usage of the library. You need to run it to test any changes you make. 23 | 24 | It is configured to use the local version of the library, so any changes you make to the library's source code will be reflected in the example app. Changes to the library's JavaScript code will be reflected in the example app without a rebuild, but native code changes will require a rebuild of the example app. 25 | 26 | If you want to use Android Studio or XCode to edit the native code, you can open the `example/android` or `example/ios` directories respectively in those editors. To edit the Objective-C or Swift files, open `example/ios/FastSecureStorageExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-fast-secure-storage`. 27 | 28 | To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `react-native-fast-secure-storage` under `Android`. 29 | 30 | You can use various commands from the root directory to work with the project. 31 | 32 | To start the packager: 33 | 34 | ```sh 35 | yarn example start 36 | ``` 37 | 38 | To run the example app on Android: 39 | 40 | ```sh 41 | yarn example android 42 | ``` 43 | 44 | To run the example app on iOS: 45 | 46 | ```sh 47 | yarn example ios 48 | ``` 49 | 50 | By default, the example is configured to build with the old architecture. To run the example with the new architecture, you can do the following: 51 | 52 | 1. For Android, run: 53 | 54 | ```sh 55 | ORG_GRADLE_PROJECT_newArchEnabled=true yarn example android 56 | ``` 57 | 58 | 2. For iOS, run: 59 | 60 | ```sh 61 | cd example/ios 62 | RCT_NEW_ARCH_ENABLED=1 pod install 63 | cd - 64 | yarn example ios 65 | ``` 66 | 67 | If you are building for a different architecture than your previous build, make sure to remove the build folders first. You can run the following command to cleanup all build folders: 68 | 69 | ```sh 70 | yarn clean 71 | ``` 72 | 73 | To confirm that the app is running with the new architecture, you can check the Metro logs for a message like this: 74 | 75 | ```sh 76 | Running "FastSecureStorageExample" with {"fabric":true,"initialProps":{"concurrentRoot":true},"rootTag":1} 77 | ``` 78 | 79 | Note the `"fabric":true` and `"concurrentRoot":true` properties. 80 | 81 | Make sure your code passes TypeScript and ESLint. Run the following to verify: 82 | 83 | ```sh 84 | yarn typecheck 85 | yarn lint 86 | ``` 87 | 88 | To fix formatting errors, run the following: 89 | 90 | ```sh 91 | yarn lint --fix 92 | ``` 93 | 94 | Remember to add tests for your change if possible. Run the unit tests by: 95 | 96 | ```sh 97 | yarn test 98 | ``` 99 | 100 | ### Commit message convention 101 | 102 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages: 103 | 104 | - `fix`: bug fixes, e.g. fix crash due to deprecated method. 105 | - `feat`: new features, e.g. add new method to the module. 106 | - `refactor`: code refactor, e.g. migrate from class components to hooks. 107 | - `docs`: changes into documentation, e.g. add usage example for the module.. 108 | - `test`: adding or updating tests, e.g. add integration tests using detox. 109 | - `chore`: tooling changes, e.g. change CI config. 110 | 111 | Our pre-commit hooks verify that your commit message matches this format when committing. 112 | 113 | ### Linting and tests 114 | 115 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/) 116 | 117 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing. 118 | 119 | Our pre-commit hooks verify that the linter and tests pass when committing. 120 | 121 | ### Publishing to npm 122 | 123 | We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc. 124 | 125 | To publish new versions, run the following: 126 | 127 | ```sh 128 | yarn release 129 | ``` 130 | 131 | ### Scripts 132 | 133 | The `package.json` file contains various scripts for common tasks: 134 | 135 | - `yarn`: setup project by installing dependencies. 136 | - `yarn typecheck`: type-check files with TypeScript. 137 | - `yarn lint`: lint files with ESLint. 138 | - `yarn test`: run unit tests with Jest. 139 | - `yarn example start`: start the Metro server for the example app. 140 | - `yarn example android`: run the example app on Android. 141 | - `yarn example ios`: run the example app on iOS. 142 | 143 | ### Sending a pull request 144 | 145 | > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github). 146 | 147 | When you're sending a pull request: 148 | 149 | - Prefer small pull requests focused on one change. 150 | - Verify that linters and tests are passing. 151 | - Review the documentation to make sure it looks good. 152 | - Follow the pull request template when opening a pull request. 153 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue. 154 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 IvanIhnatsiuk 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-fast-secure-storage 2 | 3 | `react-native-fast-secure-storage` is a fast, secure, and extensible key-value storage solution for React Native applications. 4 | This library provides a simple API to securely store sensitive data, leveraging the best practices for data encryption and performance. 5 | 6 | ## Features 7 | 8 | - Fast and efficient key-value storage 9 | - Secure data encryption 10 | - Simple asynchronous API 11 | - Cross-platform support (iOS and Android) 12 | - Supports both strings and binary data 13 | 14 | ## Installation 15 | 16 | ```sh 17 | npm install react-native-fast-secure-storage 18 | ``` 19 | or 20 | ```sh 21 | yarn add react-native-fast-secure-storage 22 | ``` 23 | 24 | ### API 25 | 26 | - [setItem](#setitem) 27 | - [getItem](#getitem) 28 | - [clearStorage](#clearstorage) 29 | - [setItems](#setitems) 30 | - [getAllKeys](#getallkeys) 31 | - [getAllItems](#getallitems) 32 | - [removeItem](#removeitem) 33 | - [clearStorage](#clearStorage) 34 | - [hasItem](#hasitem) 35 | - [getItemSync](#getitemsync) 36 | - [setItemSync](#setitemsync) 37 | - [hasItemSync](#hasitemsync) 38 | - [removeItemSync](#removeitemsync) 39 | 40 | ## Methods 41 | 42 | ### setItem 43 | 44 | Stores an item in the secure storage. 45 | 46 | - key: The key of the item. 47 | - value: The value of the item. 48 | - accessible: (Optional) The accessibility level of the item. Default is ACCESSIBLE.WHEN_UNLOCKED. 49 | 50 | ```ts 51 | import SecureStorage, { ACCESSIBLE } from "react-native-fast-secure-storage"; 52 | 53 | const result = await SecureStorage.setItem("key1", "value1", ACCESSIBLE.WHEN_UNLOCKED) 54 | ``` 55 | 56 | ### getItem 57 | Retrieves an item from the secure storage. 58 | 59 | - key: The key of the item to retrieve. 60 | 61 | ```ts 62 | import SecureStorage from "react-native-fast-secure-storage"; 63 | 64 | const result = await SecureStorage.getItem("key1") 65 | 66 | console.log(result); // output: value1 67 | ``` 68 | 69 | This method throws an error if there is no stored value for this key or the value is empty. 70 | 71 | ### clearStorage 72 | 73 | Clears all items from the secure storage. 74 | 75 | 76 | ```ts 77 | import SecureStorage from "react-native-fast-secure-storage"; 78 | 79 | await SecureStorage.clearStorage() 80 | ``` 81 | 82 | ### setItems 83 | 84 | Stores multiple items in the secure storage. 85 | 86 | - items: An array of items to set. 87 | 88 | ```ts 89 | import SecureStorage, { ACCESSIBLE } from "react-native-fast-secure-storage"; 90 | const testItems = [ 91 | { 92 | key: "key1", 93 | value: "value1", 94 | accessibleValue: ACCESSIBLE.WHEN_UNLOCKED 95 | }, 96 | { 97 | key: "key2", 98 | value: "value2", 99 | accessibleValue: ACCESSIBLE.WHEN_UNLOCKED 100 | }, 101 | ]; 102 | 103 | await SecureStorage.setItems(testItems); 104 | ``` 105 | 106 | ### getAllKeys 107 | 108 | Retrieves all keys from the secure storage. 109 | 110 | ```ts 111 | import SecureStorage, { ACCESSIBLE } from "react-native-fast-secure-storage"; 112 | const testItems = [ 113 | { 114 | key: "key1", 115 | value: "value1", 116 | accessibleValue: ACCESSIBLE.WHEN_UNLOCKED 117 | }, 118 | { 119 | key: "key2", 120 | value: "value2", 121 | accessibleValue: ACCESSIBLE.WHEN_UNLOCKED 122 | }, 123 | ]; 124 | 125 | await SecureStorage.setItems(testItems); 126 | 127 | const keys = SecureStorage.getAllKeys(); 128 | 129 | console.log(keys); // output: ["ke1", "key2"] 130 | ``` 131 | 132 | ### getAllItems 133 | 134 | Retrieves all items from the secure storage. 135 | 136 | ```ts 137 | import SecureStorage, { ACCESSIBLE } from "react-native-fast-secure-storage"; 138 | const testItems = [ 139 | { 140 | key: "key1", 141 | value: "value1", 142 | accessibleValue: ACCESSIBLE.WHEN_UNLOCKED 143 | }, 144 | { 145 | key: "key2", 146 | value: "value2", 147 | accessibleValue: ACCESSIBLE.WHEN_UNLOCKED 148 | }, 149 | ]; 150 | 151 | await SecureStorage.setItems(testItems); 152 | 153 | const secureStorageItems = SecureStorage.getAllKeys(); 154 | 155 | console.log(secureStorageItems); // output: [{ key: "key1", value: "value1" }, {key: "key2", value: "value2" }] 156 | ``` 157 | 158 | ### removeItem 159 | 160 | Removes an item from the secure storage. 161 | 162 | - key: The key of the item to remove. 163 | 164 | ```ts 165 | import SecureStorage from "react-native-fast-secure-storage"; 166 | 167 | await SecureStorage.setItem("key1", "value1"); 168 | 169 | await SecureStorage.deleteItem("key1"); 170 | 171 | try { 172 | await SecureStorage.getItem("key1") 173 | } cath(e) { 174 | console.log(e) // output: value does not exist 175 | } 176 | 177 | ``` 178 | 179 | ### hasItem 180 | 181 | - key: The key of the item to check. 182 | 183 | ```ts 184 | import SecureStorage from "react-native-fast-secure-storage"; 185 | 186 | await SecureStorage.setItem("key1", "value1"); 187 | 188 | const result = await SecureStorage.hasItem("key1"); 189 | 190 | console.log(result) // output: true 191 | 192 | ``` 193 | 194 | ## Synchronous Methods 195 | 196 | ### getItemSync 197 | 198 | Synchronously retrieves an item from the secure storage. 199 | 200 | - key: The key of the item to retrieve. 201 | 202 | ```ts 203 | import SecureStorage from 'react-native-fast-secure-storage'; 204 | 205 | const value = secureStorage.getItemSync('key1'); 206 | console.log(value); // Output: 'value1' 207 | ``` 208 | 209 | ### setItemSync 210 | 211 | Stores an item in the secure storage synchronously. 212 | 213 | - key: The key of the item. 214 | - value: The value of the item. 215 | - accessible: (Optional) The accessibility level of the item. Default is ACCESSIBLE.WHEN_UNLOCKED. 216 | 217 | ```ts 218 | 219 | const setResult = secureStorage.setItemSync('key1', 'value1'); 220 | console.log(setResult); // Output: true 221 | 222 | ``` 223 | 224 | ### hasItemSync 225 | 226 | Checks if an item exists in the secure storage synchronously. 227 | 228 | - key: The key of the item to check. 229 | 230 | ```ts 231 | 232 | const setResult = secureStorage.setItemSync('key1', 'value1'); 233 | const exists = secureStorage.hasItemSync('key1'); 234 | console.log(exists); // Output: true 235 | 236 | ``` 237 | 238 | ### removeItemSync 239 | 240 | Removes an item from the secure storage synchronously. 241 | 242 | - key: The key of the item to remove. 243 | 244 | ```ts 245 | 246 | const setResult = secureStorage.setItemSync('key1', 'value1'); 247 | 248 | const removeResult = secureStorage.removeItemSync('key1'); 249 | 250 | ``` 251 | 252 | ## Testing 253 | 254 | This library includes a built in mock for Jest. To use it, add the following code to the jest setup file: 255 | 256 | ```ts 257 | jest.mock('react-native-fast-secure-storage', () => require("react-native-fast-secure-storage/jest")); 258 | ``` 259 | 260 | ## Contributing 261 | 262 | See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. 263 | 264 | ## License 265 | 266 | MIT 267 | 268 | --- 269 | 270 | Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob) 271 | # react-native-fast-secure-storage 272 | -------------------------------------------------------------------------------- /android/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9.0) 2 | 3 | set (PACKAGE_NAME "react-native-fast-secure-storage") 4 | project(PACKAGE_NAME) 5 | 6 | set (CMAKE_VERBOSE_MAKEFILE ON) 7 | set (CMAKE_CXX_STANDARD 17) 8 | set (BUILD_DIR ${CMAKE_SOURCE_DIR}/build) 9 | 10 | add_library( 11 | ${PACKAGE_NAME} 12 | SHARED 13 | src/main/cpp/cpp-adapter.cpp 14 | ../cpp/macros.h 15 | ../cpp/SecureStorageHostObject.cpp 16 | ../cpp/SecureStorageHostObject.h 17 | ) 18 | 19 | include_directories( 20 | ../cpp 21 | ) 22 | 23 | set_target_properties( 24 | ${PACKAGE_NAME} PROPERTIES 25 | CXX_STANDARD 17 26 | CXX_EXTENSIONS OFF 27 | POSITION_INDEPENDENT_CODE ON 28 | ) 29 | 30 | find_package(ReactAndroid REQUIRED CONFIG) 31 | find_package(fbjni REQUIRED CONFIG) 32 | find_library(log-lib log) 33 | 34 | if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76) 35 | target_link_libraries( 36 | ${PACKAGE_NAME} 37 | ${log-lib} 38 | fbjni::fbjni 39 | ReactAndroid::jsi 40 | ReactAndroid::reactnative 41 | android 42 | ) 43 | else() 44 | target_link_libraries( 45 | ${PACKAGE_NAME} 46 | ${log-lib} 47 | fbjni::fbjni 48 | ReactAndroid::jsi 49 | ReactAndroid::turbomodulejsijni 50 | ReactAndroid::react_nativemodule_core 51 | android 52 | ) 53 | endif() 54 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | // Buildscript is evaluated before everything else so we can't use getExtOrDefault 3 | def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["FastSecureStorage_kotlinVersion"] 4 | 5 | repositories { 6 | google() 7 | mavenCentral() 8 | } 9 | 10 | dependencies { 11 | classpath "com.android.tools.build:gradle:7.2.2" 12 | // noinspection DifferentKotlinGradleVersion 13 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 14 | } 15 | } 16 | 17 | def reactNativeArchitectures() { 18 | def value = rootProject.getProperties().get("reactNativeArchitectures") 19 | return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] 20 | } 21 | 22 | def isNewArchitectureEnabled() { 23 | return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true" 24 | } 25 | 26 | apply plugin: "com.android.library" 27 | apply plugin: "kotlin-android" 28 | 29 | if (isNewArchitectureEnabled()) { 30 | apply plugin: "com.facebook.react" 31 | } 32 | 33 | def resolveBuildType() { 34 | Gradle gradle = getGradle() 35 | String tskReqStr = gradle.getStartParameter().getTaskRequests()['args'].toString() 36 | 37 | return tskReqStr.contains('Release') ? 'release' : 'debug' 38 | } 39 | 40 | def getExtOrDefault(name) { 41 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["FastSecureStorage_" + name] 42 | } 43 | 44 | def getExtOrIntegerDefault(name) { 45 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["FastSecureStorage_" + name]).toInteger() 46 | } 47 | 48 | def supportsNamespace() { 49 | def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.') 50 | def major = parsed[0].toInteger() 51 | def minor = parsed[1].toInteger() 52 | 53 | // Namespace support was added in 7.3.0 54 | return (major == 7 && minor >= 3) || major >= 8 55 | } 56 | 57 | android { 58 | if (supportsNamespace()) { 59 | namespace "com.fastsecurestorage" 60 | 61 | sourceSets { 62 | main { 63 | manifest.srcFile "src/main/AndroidManifestNew.xml" 64 | } 65 | } 66 | } 67 | 68 | if (rootProject.hasProperty("ndkPath")) { 69 | ndkPath rootProject.ext.ndkPath 70 | } 71 | if (rootProject.hasProperty("ndkVersion")) { 72 | ndkVersion rootProject.ext.ndkVersion 73 | } 74 | 75 | compileSdkVersion getExtOrIntegerDefault("compileSdkVersion") 76 | 77 | defaultConfig { 78 | minSdkVersion getExtOrIntegerDefault("minSdkVersion") 79 | targetSdkVersion getExtOrIntegerDefault("targetSdkVersion") 80 | 81 | consumerProguardFiles "consumer-rules.pro" 82 | 83 | buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() 84 | externalNativeBuild { 85 | cmake { 86 | cppFlags "-O2 -frtti -fexceptions -Wall -Wno-unused-variable -fstack-protector-all" 87 | arguments "-DANDROID_STL=c++_shared" 88 | abiFilters (*reactNativeArchitectures()) 89 | } 90 | } 91 | 92 | packagingOptions { 93 | doNotStrip resolveBuildType() == 'debug' ? "**/**/*.so" : '' 94 | excludes = [ 95 | "META-INF", 96 | "META-INF/**", 97 | "**/libjsi.so", 98 | "**/libreact_nativemodule_core.so", 99 | "**/libturbomodulejsijni.so", 100 | "**/libc++_shared.so", 101 | "**/libreactnative.so", 102 | "**/libfbjni.so" 103 | ] 104 | } 105 | } 106 | 107 | externalNativeBuild { 108 | cmake { 109 | path "CMakeLists.txt" 110 | } 111 | } 112 | 113 | buildFeatures { 114 | prefab true 115 | buildConfig true 116 | } 117 | 118 | buildTypes { 119 | release { 120 | minifyEnabled false 121 | } 122 | } 123 | 124 | lintOptions { 125 | disable "GradleCompatible" 126 | } 127 | 128 | compileOptions { 129 | sourceCompatibility JavaVersion.VERSION_1_8 130 | targetCompatibility JavaVersion.VERSION_1_8 131 | } 132 | 133 | sourceSets { 134 | main { 135 | if (isNewArchitectureEnabled()) { 136 | java.srcDirs += [ 137 | "src/fabric", 138 | // This is needed to build Kotlin project with NewArch enabled 139 | "${project.buildDir}/generated/source/codegen/java" 140 | ] 141 | } else { 142 | java.srcDirs += ["src/paper"] 143 | } 144 | } 145 | } 146 | } 147 | 148 | repositories { 149 | mavenCentral() 150 | google() 151 | } 152 | 153 | def kotlin_version = getExtOrDefault("kotlinVersion") 154 | 155 | dependencies { 156 | // For < 0.71, this will be from the local maven repo 157 | // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin 158 | //noinspection GradleDynamicVersion 159 | implementation "com.facebook.react:react-native:+" 160 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 161 | implementation "androidx.security:security-crypto-ktx:1.1.0-alpha06" 162 | } 163 | 164 | if (isNewArchitectureEnabled()) { 165 | react { 166 | jsRootDir = file("../src/") 167 | libraryName = "FastSecureStorage" 168 | codegenJavaPackageName = "com.fastsecurestorage" 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /android/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -keep class com.fastsecurestorage.** { *; } -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | FastSecureStorage_kotlinVersion=1.9.2 2 | FastSecureStorage_minSdkVersion=21 3 | FastSecureStorage_targetSdkVersion=34 4 | FastSecureStorage_compileSdkVersion=34 5 | FastSecureStorage_ndkversion=26.1.10909125 6 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /android/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Stop when "xargs" is not available. 209 | if ! command -v xargs >/dev/null 2>&1 210 | then 211 | die "xargs is not available" 212 | fi 213 | 214 | # Use "xargs" to parse quoted args. 215 | # 216 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 217 | # 218 | # In Bash we could simply go: 219 | # 220 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 221 | # set -- "${ARGS[@]}" "$@" 222 | # 223 | # but POSIX shell has neither arrays nor command substitution, so instead we 224 | # post-process each arg (as a line of input to sed) to backslash-escape any 225 | # character that might be a shell metacharacter, then use eval to reverse 226 | # that process (while maintaining the separation between arguments), and wrap 227 | # the whole thing up as a single "set" statement. 228 | # 229 | # This will of course break if any of these variables contains a newline or 230 | # an unmatched quote. 231 | # 232 | 233 | eval "set -- $( 234 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 235 | xargs -n1 | 236 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 237 | tr '\n' ' ' 238 | )" '"$@"' 239 | 240 | exec "$JAVACMD" "$@" 241 | -------------------------------------------------------------------------------- /android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if %ERRORLEVEL% equ 0 goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if %ERRORLEVEL% equ 0 goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | set EXIT_CODE=%ERRORLEVEL% 84 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 85 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 86 | exit /b %EXIT_CODE% 87 | 88 | :mainEnd 89 | if "%OS%"=="Windows_NT" endlocal 90 | 91 | :omega 92 | -------------------------------------------------------------------------------- /android/src/fabric/com/fastsecurestorage/FastSecureStorageModule.kt: -------------------------------------------------------------------------------- 1 | package com.fastsecurestorage 2 | 3 | import android.util.Log 4 | import com.facebook.react.bridge.ReactApplicationContext 5 | 6 | class FastSecureStorageModule( 7 | reactContext: ReactApplicationContext, 8 | ) : NativeFastSecureStorageSpec(reactContext) { 9 | private val fastSecureStorage = FastSecureStorageImpl(reactContext) 10 | 11 | override fun getName(): String = FastSecureStorageImpl.NAME 12 | 13 | override fun install(): Boolean { 14 | try { 15 | System.loadLibrary("react-native-fast-secure-storage") 16 | fastSecureStorage.install(reactApplicationContext) 17 | return true 18 | } catch (exception: Exception) { 19 | Log.e(FastSecureStorageImpl.NAME, "Failed to install JSI Bindings!", exception) 20 | return false 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifestNew.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /android/src/main/cpp/cpp-adapter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "SecureStorageHostObject.h" 8 | 9 | using namespace facebook; 10 | 11 | static JavaVM *java_vm; 12 | static jclass java_class; 13 | static jobject java_object; 14 | 15 | /** 16 | * A simple callback function that allows us to detach current JNI Environment 17 | * when the thread 18 | * See https://stackoverflow.com/a/30026231 for detailed explanation 19 | */ 20 | 21 | void DeferThreadDetach(JNIEnv *env) { 22 | static pthread_key_t thread_key; 23 | 24 | // Set up a Thread Specific Data key, and a callback that 25 | // will be executed when a thread is destroyed. 26 | // This is only done once, across all threads, and the value 27 | // associated with the key for any given thread will initially 28 | // be NULL. 29 | static auto run_once = [] { 30 | const auto err = pthread_key_create(&thread_key, [](void *ts_env) { 31 | if (ts_env) { 32 | java_vm->DetachCurrentThread(); 33 | } 34 | }); 35 | if (err) { 36 | // Failed to create TSD key. Throw an exception if you want to. 37 | } 38 | return 0; 39 | }(); 40 | 41 | // For the callback to actually be executed when a thread exits 42 | // we need to associate a non-NULL value with the key on that thread. 43 | // We can use the JNIEnv* as that value. 44 | const auto ts_env = pthread_getspecific(thread_key); 45 | if (!ts_env) { 46 | if (pthread_setspecific(thread_key, env)) { 47 | // Failed to set thread-specific value for key. Throw an exception if you 48 | // want to. 49 | } 50 | } 51 | } 52 | 53 | /** 54 | * Get a JNIEnv* valid for this thread, regardless of whether 55 | * we're on a native thread or a Java thread. 56 | * If the calling thread is not currently attached to the JVM 57 | * it will be attached, and then automatically detached when the 58 | * thread is destroyed. 59 | * 60 | * See https://stackoverflow.com/a/30026231 for detailed explanation 61 | */ 62 | JNIEnv *GetJniEnv() { 63 | JNIEnv *env = nullptr; 64 | // We still call GetEnv first to detect if the thread already 65 | // is attached. This is done to avoid setting up a DetachCurrentThread 66 | // call on a Java thread. 67 | 68 | // g_vm is a global. 69 | auto get_env_result = java_vm->GetEnv((void **)&env, JNI_VERSION_1_6); 70 | if (get_env_result == JNI_EDETACHED) { 71 | if (java_vm->AttachCurrentThread(&env, NULL) == JNI_OK) { 72 | DeferThreadDetach(env); 73 | } else { 74 | // Failed to attach thread. Throw an exception if you want to. 75 | } 76 | } else if (get_env_result == JNI_EVERSION) { 77 | // Unsupported JNI version. Throw an exception if you want to. 78 | } 79 | return env; 80 | } 81 | 82 | jstring string2jstring(JNIEnv *env, const std::string str) { 83 | return (*env).NewStringUTF(str.c_str()); 84 | } 85 | 86 | bool setItem( 87 | const std::string key, 88 | const std::string value, 89 | const int accessibleValue) { 90 | JNIEnv *jniEnv = GetJniEnv(); 91 | java_class = jniEnv->GetObjectClass(java_object); 92 | jmethodID setMethodID = jniEnv->GetMethodID( 93 | java_class, "setItem", "(Ljava/lang/String;Ljava/lang/String;)Z"); 94 | jvalue params[2]; 95 | params[0].l = string2jstring(jniEnv, key); 96 | params[1].l = string2jstring(jniEnv, value); 97 | 98 | auto result = jniEnv->CallBooleanMethodA(java_object, setMethodID, params); 99 | 100 | jthrowable exObj = jniEnv->ExceptionOccurred(); 101 | 102 | if (exObj) { 103 | jclass clazz = jniEnv->GetObjectClass(exObj); 104 | jniEnv->ExceptionClear(); 105 | jmethodID getMessage = 106 | jniEnv->GetMethodID(clazz, "toString", "()Ljava/lang/String;"); 107 | 108 | auto message = (jstring)jniEnv->CallObjectMethod(exObj, getMessage); 109 | const char *mstr = jniEnv->GetStringUTFChars(message, NULL); 110 | throw std::runtime_error(std::string(mstr)); 111 | } 112 | 113 | return result; 114 | } 115 | 116 | bool hasItem(const std::string key) { 117 | JNIEnv *jniEnv = GetJniEnv(); 118 | java_class = jniEnv->GetObjectClass(java_object); 119 | jmethodID hasItemMethodID = 120 | jniEnv->GetMethodID(java_class, "hasItem", "(Ljava/lang/String;)Z"); 121 | jvalue params[1]; 122 | params[0].l = string2jstring(jniEnv, key); 123 | 124 | bool result = 125 | jniEnv->CallBooleanMethodA(java_object, hasItemMethodID, params); 126 | jthrowable exObj = jniEnv->ExceptionOccurred(); 127 | 128 | if (exObj) { 129 | jniEnv->ExceptionClear(); 130 | 131 | jclass clazz = jniEnv->GetObjectClass(exObj); 132 | jmethodID getMessage = 133 | jniEnv->GetMethodID(clazz, "toString", "()Ljava/lang/String;"); 134 | auto message = (jstring)jniEnv->CallObjectMethod(exObj, getMessage); 135 | const char *mstr = jniEnv->GetStringUTFChars(message, NULL); 136 | throw std::runtime_error(std::string(mstr)); 137 | return result; 138 | } 139 | return result; 140 | } 141 | 142 | std::string getItem(const std::string key) { 143 | JNIEnv *jniEnv = GetJniEnv(); 144 | java_class = jniEnv->GetObjectClass(java_object); 145 | jmethodID getItemMethodID = jniEnv->GetMethodID( 146 | java_class, "getItem", "(Ljava/lang/String;)Ljava/lang/String;"); 147 | jvalue params[1]; 148 | params[0].l = string2jstring(jniEnv, key); 149 | 150 | auto result = 151 | (jstring)jniEnv->CallObjectMethodA(java_object, getItemMethodID, params); 152 | jthrowable exObj = jniEnv->ExceptionOccurred(); 153 | if (exObj) { 154 | jniEnv->ExceptionClear(); 155 | 156 | jclass clazz = jniEnv->GetObjectClass(exObj); 157 | jmethodID getMessage = 158 | jniEnv->GetMethodID(clazz, "toString", "()Ljava/lang/String;"); 159 | auto message = (jstring)jniEnv->CallObjectMethod(exObj, getMessage); 160 | const char *mstr = jniEnv->GetStringUTFChars(message, NULL); 161 | throw std::runtime_error(std::string(mstr)); 162 | } 163 | 164 | std::string str = jniEnv->GetStringUTFChars((jstring)result, NULL); 165 | 166 | if (str.empty()) { 167 | return ""; 168 | } 169 | 170 | return str; 171 | } 172 | 173 | bool deleteItem(const std::string key) { 174 | JNIEnv *jniEnv = GetJniEnv(); 175 | java_class = jniEnv->GetObjectClass(java_object); 176 | jmethodID deleteMethodID = 177 | jniEnv->GetMethodID(java_class, "removeItem", "(Ljava/lang/String;)Z"); 178 | jvalue params[1]; 179 | params[0].l = string2jstring(jniEnv, key); 180 | 181 | bool result = jniEnv->CallBooleanMethodA(java_object, deleteMethodID, params); 182 | jthrowable exObj = jniEnv->ExceptionOccurred(); 183 | 184 | if (exObj) { 185 | jniEnv->ExceptionClear(); 186 | 187 | jclass clazz = jniEnv->GetObjectClass(exObj); 188 | jmethodID getMessage = 189 | jniEnv->GetMethodID(clazz, "toString", "()Ljava/lang/String;"); 190 | auto message = (jstring)jniEnv->CallObjectMethod(exObj, getMessage); 191 | const char *mstr = jniEnv->GetStringUTFChars(message, NULL); 192 | throw std::runtime_error(std::string(mstr)); 193 | return result; 194 | } 195 | return result; 196 | } 197 | 198 | void clearStorage() { 199 | JNIEnv *jniEnv = GetJniEnv(); 200 | java_class = jniEnv->GetObjectClass(java_object); 201 | jmethodID clearMethodID = 202 | jniEnv->GetMethodID(java_class, "clearStorage", "()V"); 203 | jvalue params[0]; 204 | jniEnv->CallVoidMethodA(java_object, clearMethodID, params); 205 | 206 | jthrowable exObj = jniEnv->ExceptionOccurred(); 207 | 208 | if (exObj) { 209 | jniEnv->ExceptionClear(); 210 | 211 | jclass clazz = jniEnv->GetObjectClass(exObj); 212 | jmethodID getMessage = 213 | jniEnv->GetMethodID(clazz, "toString", "()Ljava/lang/String;"); 214 | auto message = (jstring)jniEnv->CallObjectMethod(exObj, getMessage); 215 | const char *mstr = jniEnv->GetStringUTFChars(message, NULL); 216 | throw std::runtime_error(std::string(mstr)); 217 | } 218 | } 219 | 220 | std::string getAllKeys() { 221 | JNIEnv *jniEnv = GetJniEnv(); 222 | java_class = jniEnv->GetObjectClass(java_object); 223 | jmethodID getAllKeysMethodId = 224 | jniEnv->GetMethodID(java_class, "getAllKeys", "()Ljava/lang/String;"); 225 | jvalue params[0]; 226 | auto result = (jstring)jniEnv->CallObjectMethodA( 227 | java_object, getAllKeysMethodId, params); 228 | jthrowable exObj = jniEnv->ExceptionOccurred(); 229 | 230 | if (exObj) { 231 | jniEnv->ExceptionClear(); 232 | 233 | jclass clazz = jniEnv->GetObjectClass(exObj); 234 | jmethodID getMessage = 235 | jniEnv->GetMethodID(clazz, "toString", "()Ljava/lang/String;"); 236 | auto message = (jstring)jniEnv->CallObjectMethod(exObj, getMessage); 237 | const char *mstr = jniEnv->GetStringUTFChars(message, NULL); 238 | throw std::runtime_error(std::string(mstr)); 239 | } 240 | std::string str = jniEnv->GetStringUTFChars((jstring)result, NULL); 241 | 242 | if (str.empty()) { 243 | return ""; 244 | } 245 | 246 | return str; 247 | } 248 | 249 | std::string getAllItems() { 250 | JNIEnv *jniEnv = GetJniEnv(); 251 | java_class = jniEnv->GetObjectClass(java_object); 252 | jmethodID getAllItemsMethodId = 253 | jniEnv->GetMethodID(java_class, "getAllItems", "()Ljava/lang/String;"); 254 | jvalue params[0]; 255 | auto result = (jstring)jniEnv->CallObjectMethodA( 256 | java_object, getAllItemsMethodId, params); 257 | jthrowable exObj = jniEnv->ExceptionOccurred(); 258 | 259 | if (exObj) { 260 | jniEnv->ExceptionClear(); 261 | 262 | jclass clazz = jniEnv->GetObjectClass(exObj); 263 | jmethodID getMessage = 264 | jniEnv->GetMethodID(clazz, "toString", "()Ljava/lang/String;"); 265 | auto message = (jstring)jniEnv->CallObjectMethod(exObj, getMessage); 266 | const char *mstr = jniEnv->GetStringUTFChars(message, NULL); 267 | throw std::runtime_error(std::string(mstr)); 268 | } 269 | 270 | std::string str = jniEnv->GetStringUTFChars((jstring)result, NULL); 271 | 272 | if (str.empty()) { 273 | return ""; 274 | } 275 | 276 | return str; 277 | } 278 | 279 | struct FastSecureStorageImpl : jni::JavaClass { 280 | static constexpr auto kJavaDescriptor = 281 | "Lcom/fastsecurestorage/FastSecureStorageImpl;"; 282 | 283 | static void registerNatives() { 284 | javaClassStatic()->registerNatives({ 285 | makeNativeMethod( 286 | "installNativeJsi", FastSecureStorageImpl::installNativeJsi), 287 | }); 288 | } 289 | 290 | private: 291 | static void installNativeJsi( 292 | jni::alias_ref thiz, 293 | jlong jsiPtr, 294 | jni::alias_ref 295 | jsCallInvokerHolder) { 296 | auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker(); 297 | auto runtime = reinterpret_cast(jsiPtr); 298 | jni::Environment::current()->GetJavaVM(&java_vm); 299 | java_object = jni::Environment::current()->NewGlobalRef(thiz.get()); 300 | if (runtime) { 301 | securestorageHostObject::install( 302 | *runtime, 303 | jsCallInvoker, 304 | &setItem, 305 | &getItem, 306 | &deleteItem, 307 | &clearStorage, 308 | &getAllKeys, 309 | &getAllItems, 310 | &hasItem); 311 | } 312 | } 313 | }; 314 | 315 | JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { 316 | java_vm = vm; 317 | return facebook::jni::initialize( 318 | vm, [] { FastSecureStorageImpl::registerNatives(); }); 319 | } 320 | -------------------------------------------------------------------------------- /android/src/main/java/com/fastsecurestorage/FastSecureStorageImpl.kt: -------------------------------------------------------------------------------- 1 | package com.fastsecurestorage 2 | 3 | import android.content.SharedPreferences 4 | import androidx.security.crypto.EncryptedSharedPreferences 5 | import androidx.security.crypto.MasterKey 6 | import com.facebook.react.bridge.ReactApplicationContext 7 | import com.facebook.react.bridge.ReactContext 8 | import com.facebook.react.common.annotations.FrameworkAPI 9 | import com.facebook.react.turbomodule.core.CallInvokerHolderImpl 10 | import org.json.JSONArray 11 | import org.json.JSONObject 12 | import java.io.FileNotFoundException 13 | import java.io.IOException 14 | import java.security.GeneralSecurityException 15 | 16 | @OptIn(FrameworkAPI::class) 17 | class FastSecureStorageImpl( 18 | private val context: ReactApplicationContext, 19 | ) { 20 | private var sharedPreferences: SharedPreferences? = null 21 | 22 | private external fun installNativeJsi( 23 | jsContextNativePointer: Long, 24 | jsCallInvokerHolder: CallInvokerHolderImpl, 25 | ) 26 | 27 | init { 28 | try { 29 | this.sharedPreferences = this.secureSharedPreferences 30 | } catch (e: Exception) { 31 | e.printStackTrace() 32 | } 33 | } 34 | 35 | fun setItem( 36 | alias: String, 37 | value: String, 38 | ): Boolean { 39 | try { 40 | sharedPreferences?.edit()?.putString(alias, value)?.apply() 41 | return true 42 | } catch (e: Exception) { 43 | return false 44 | } 45 | } 46 | 47 | fun getAllKeys(): String { 48 | val keys = this.sharedPreferences?.all?.keys ?: return JSONArray().toString() 49 | 50 | return JSONArray(keys).toString() 51 | } 52 | 53 | fun getAllItems(): String { 54 | val entries = this.sharedPreferences?.all?.entries ?: return JSONArray().toString() 55 | 56 | val keyValueList = 57 | entries.map { element -> 58 | val jsonObject = JSONObject() 59 | jsonObject.put("key", element.key) 60 | jsonObject.put("value", element.value) 61 | } 62 | 63 | return JSONArray(keyValueList).toString() 64 | } 65 | 66 | fun hasItem(key: String): Boolean = this.sharedPreferences?.contains(key) ?: false 67 | 68 | @get:Throws(GeneralSecurityException::class, IOException::class) 69 | private val secureSharedPreferences: SharedPreferences 70 | get() { 71 | val key = 72 | MasterKey 73 | .Builder(context) 74 | .setKeyScheme(MasterKey.KeyScheme.AES256_GCM) 75 | .build() 76 | 77 | return EncryptedSharedPreferences.create( 78 | context, 79 | "secret_shared_prefs", 80 | key, 81 | EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, 82 | EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM, 83 | ) 84 | } 85 | 86 | fun getItem(key: String): String { 87 | try { 88 | val value = 89 | sharedPreferences!!.getString(key, null) 90 | if (value == null) { 91 | throw FileNotFoundException("$key has not been set") 92 | } else { 93 | return value 94 | } 95 | } catch (e: Exception) { 96 | e.printStackTrace() 97 | return "" 98 | } 99 | } 100 | 101 | fun removeItem(key: String): Boolean { 102 | try { 103 | if (!hasItem(key)) { 104 | return true 105 | } 106 | sharedPreferences?.edit()?.remove(key)?.apply() 107 | return true 108 | } catch (e: Exception) { 109 | return false 110 | } 111 | } 112 | 113 | fun clearStorage() { 114 | try { 115 | if (this.sharedPreferences 116 | ?.all 117 | ?.keys 118 | ?.size == 0 119 | ) { 120 | return 121 | } 122 | 123 | this.sharedPreferences 124 | ?.edit() 125 | ?.clear() 126 | ?.apply() 127 | } catch (e: Exception) { 128 | e.printStackTrace() 129 | } 130 | } 131 | 132 | fun install(context: ReactContext) { 133 | val jsContextPointer = context.javaScriptContextHolder!!.get() 134 | val jsCallInvokerHolder = 135 | context.catalystInstance.jsCallInvokerHolder 136 | installNativeJsi(jsContextPointer, jsCallInvokerHolder as CallInvokerHolderImpl) 137 | } 138 | 139 | companion object { 140 | const val NAME: String = "FastSecureStorage" 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /android/src/main/java/com/fastsecurestorage/FastSecureStoragePackage.kt: -------------------------------------------------------------------------------- 1 | package com.fastsecurestorage 2 | 3 | import com.facebook.react.TurboReactPackage 4 | import com.facebook.react.bridge.NativeModule 5 | import com.facebook.react.bridge.ReactApplicationContext 6 | import com.facebook.react.module.model.ReactModuleInfo 7 | import com.facebook.react.module.model.ReactModuleInfoProvider 8 | 9 | class FastSecureStoragePackage : TurboReactPackage() { 10 | override fun getModule( 11 | name: String, 12 | reactContext: ReactApplicationContext, 13 | ): NativeModule? = 14 | if (name == FastSecureStorageImpl.NAME) { 15 | FastSecureStorageModule(reactContext) 16 | } else { 17 | null 18 | } 19 | 20 | override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = 21 | ReactModuleInfoProvider { 22 | val moduleInfos: MutableMap = 23 | HashMap() 24 | moduleInfos[FastSecureStorageImpl.NAME] = 25 | ReactModuleInfo( 26 | FastSecureStorageImpl.NAME, 27 | FastSecureStorageImpl.NAME, 28 | false, // canOverrideExistingModule 29 | false, // needsEagerInit 30 | true, // hasConstants 31 | false, // isCxxModule 32 | true, // isTurboModule 33 | ) 34 | moduleInfos 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /android/src/paper/com/fastsecurestorage/FastSecureStorageModule.kt: -------------------------------------------------------------------------------- 1 | package com.fastsecurestorage 2 | 3 | import android.util.Log 4 | import com.facebook.react.bridge.ReactApplicationContext 5 | import com.facebook.react.bridge.ReactContextBaseJavaModule 6 | import com.facebook.react.bridge.ReactMethod 7 | import com.facebook.react.module.annotations.ReactModule 8 | 9 | @ReactModule(name = FastSecureStorageImpl.NAME) 10 | class FastSecureStorageModule( 11 | reactContext: ReactApplicationContext, 12 | ) : ReactContextBaseJavaModule( 13 | reactContext, 14 | ) { 15 | private val fastSecureStorage = FastSecureStorageImpl(reactContext) 16 | 17 | @ReactMethod(isBlockingSynchronousMethod = true) 18 | fun install(): Boolean { 19 | try { 20 | System.loadLibrary("react-native-fast-secure-storage") 21 | fastSecureStorage.install(reactApplicationContext) 22 | return true 23 | } catch (exception: Exception) { 24 | Log.e(FastSecureStorageImpl.NAME, "Failed to install JSI Bindings!", exception) 25 | return false 26 | } 27 | } 28 | 29 | override fun getName(): String = FastSecureStorageImpl.NAME 30 | } 31 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | ["module:react-native-builder-bob/babel-preset", { modules: "commonjs" }], 4 | ], 5 | }; 6 | -------------------------------------------------------------------------------- /clang.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | find ./ios -iname *.h -o -iname *.cpp -o -iname *.m -o -iname *.mm | grep -v -e Pods -e build | xargs clang-format -i -n --Werror 4 | find ./android/src/main -iname *.h -o -iname *.cpp -o -iname *.m -o -iname *.mm | grep -v -e Pods -e build | xargs clang-format -i -n --Werror 5 | find ./cpp -iname *.h -o -iname *.cpp -o -iname *.m -o -iname *.mm | grep -v -e Pods -e build | xargs clang-format -i -n --Werror -------------------------------------------------------------------------------- /cpp/SecureStorageHostObject.cpp: -------------------------------------------------------------------------------- 1 | #import "SecureStorageHostObject.h" 2 | #include 3 | #include 4 | #import "macros.h" 5 | 6 | namespace securestorageHostObject { 7 | using namespace facebook; 8 | using namespace jsi; 9 | using namespace std; 10 | 11 | function _set; 12 | function _get; 13 | function _del; 14 | function _clearStorage; 15 | function _getAllKeys; 16 | function _getAllItems; 17 | function _hasItem; 18 | 19 | jsi::Value generateJSError(jsi::Runtime &runtime, string errorMessage) { 20 | auto errorCtr = runtime.global().getPropertyAsFunction(runtime, "Error"); 21 | return errorCtr.callAsConstructor( 22 | runtime, jsi::String::createFromUtf8(runtime, errorMessage)); 23 | } 24 | 25 | struct KeyValue { 26 | string key; 27 | string value; 28 | int accessibleValue; 29 | }; 30 | 31 | void install( 32 | jsi::Runtime &runtime, 33 | shared_ptr jsCallInvoker, 34 | function setItemFn, 35 | function getItemFn, 36 | function delItemFn, 37 | function clearStorageFn, 38 | function getAllkeysFn, 39 | function getAllItemsFn, 40 | function hasItemFn) 41 | 42 | { 43 | _set = setItemFn; 44 | _get = getItemFn; 45 | _del = delItemFn; 46 | _clearStorage = clearStorageFn; 47 | _getAllKeys = getAllkeysFn; 48 | _getAllItems = getAllItemsFn; 49 | _hasItem = hasItemFn; 50 | auto setItem = CREATE_HOST_FN("setItem", 3) { 51 | if (!arguments[0].isString()) { 52 | throw jsi::JSError(runtime, "setItem: key must be a string value!"); 53 | } 54 | 55 | if (!arguments[1].isString()) { 56 | throw jsi::JSError(runtime, "setItem: value must be a string value!"); 57 | } 58 | 59 | const std::string key = arguments[0].getString(runtime).utf8(runtime); 60 | const std::string value = arguments[1].getString(runtime).utf8(runtime); 61 | const int accessible = arguments[2].getNumber(); 62 | auto promise = runtime.global().getPropertyAsFunction(runtime, "Promise"); 63 | return promise.callAsConstructor( 64 | runtime, 65 | Function::createFromHostFunction( 66 | runtime, 67 | PropNameID::forAscii(runtime, "executor"), 68 | 2, 69 | [key, value, accessible, jsCallInvoker = jsCallInvoker]( 70 | Runtime &runtime, 71 | const Value &thisValue, 72 | const Value *args, 73 | size_t) -> Value { 74 | auto resolve = make_shared(runtime, args[0]); 75 | auto reject = make_shared(runtime, args[1]); 76 | std::thread([key, 77 | value, 78 | accessible, 79 | resolve = std::move(resolve), 80 | reject = std::move(reject), 81 | jsCallInvoker = jsCallInvoker, 82 | &runtime]() { 83 | bool result = _set(key, value, accessible); 84 | jsCallInvoker->invokeAsync( 85 | [resolve, reject, result, &runtime]() { 86 | if (result) { 87 | resolve->asObject(runtime).asFunction(runtime).call( 88 | runtime, result); 89 | } else { 90 | reject->asObject(runtime).asFunction(runtime).call( 91 | runtime, result); 92 | } 93 | }); 94 | }).detach(); 95 | return Value(); 96 | })); 97 | }); 98 | 99 | auto setItems = CREATE_HOST_FN("setItems", 1) { 100 | if (!arguments[0].getObject(runtime).isArray(runtime)) { 101 | throw jsi::JSError(runtime, "setitems: items must be an array"); 102 | } 103 | auto items = arguments[0].getObject(runtime).getArray(runtime); 104 | std::vector itemsArray; 105 | size_t size = items.size(runtime); 106 | itemsArray.reserve(size); 107 | for (int i = 0; i < size; i++) { 108 | auto item = items.getValueAtIndex(runtime, i).getObject(runtime); 109 | const auto key = 110 | item.getProperty(runtime, "key").asString(runtime).utf8(runtime); 111 | const auto value = 112 | item.getProperty(runtime, "value").asString(runtime).utf8(runtime); 113 | const auto accessibleValue = 114 | item.getProperty(runtime, "accessibleValue").getNumber(); 115 | itemsArray.push_back({key, value, static_cast(accessibleValue)}); 116 | } 117 | 118 | auto promise = runtime.global().getPropertyAsFunction(runtime, "Promise"); 119 | return promise.callAsConstructor( 120 | runtime, 121 | Function::createFromHostFunction( 122 | runtime, 123 | PropNameID::forAscii(runtime, "executor"), 124 | 2, 125 | [itemsArray, jsCallInvoker = jsCallInvoker]( 126 | Runtime &runtime, 127 | const Value &thisValue, 128 | const Value *args, 129 | size_t) -> Value { 130 | auto resolve = make_shared(runtime, args[0]); 131 | auto reject = make_shared(runtime, args[1]); 132 | std::thread([itemsArray, 133 | resolve = std::move(resolve), 134 | reject = std::move(reject), 135 | jsCallInvoker = jsCallInvoker, 136 | &runtime]() { 137 | try { 138 | for (const auto &item : itemsArray) { 139 | _set(item.key, item.value, item.accessibleValue); 140 | } 141 | jsCallInvoker->invokeAsync([resolve, reject, &runtime]() { 142 | resolve->asObject(runtime).asFunction(runtime).call( 143 | runtime); 144 | }); 145 | } catch (const std::exception &exception) { 146 | jsCallInvoker->invokeAsync([reject, &runtime, &exception]() { 147 | auto error = generateJSError(runtime, exception.what()); 148 | reject->asObject(runtime).asFunction(runtime).call( 149 | runtime, error); 150 | }); 151 | } 152 | }).detach(); 153 | return Value(); 154 | })); 155 | 156 | return Value(); 157 | }); 158 | 159 | auto getItem = CREATE_HOST_FN("getItem", 1) { 160 | if (!arguments[0].isString()) { 161 | throw jsi::JSError(runtime, "getItem: key must be a string value!"); 162 | } 163 | 164 | std::string key = arguments[0].getString(runtime).utf8(runtime); 165 | 166 | auto promise = runtime.global().getPropertyAsFunction(runtime, "Promise"); 167 | return promise.callAsConstructor( 168 | runtime, 169 | Function::createFromHostFunction( 170 | runtime, 171 | PropNameID::forAscii(runtime, "executor"), 172 | 4, 173 | [key, jsCallInvoker = jsCallInvoker]( 174 | Runtime &runtime, 175 | const Value &thisValue, 176 | const Value *args, 177 | size_t) -> Value { 178 | auto resolve = make_shared(runtime, args[0]); 179 | auto reject = make_shared(runtime, args[1]); 180 | std::thread([key, 181 | resolve = std::move(resolve), 182 | reject = std::move(reject), 183 | jsCallInvoker, 184 | &runtime]() { 185 | try { 186 | auto result = _get(key); 187 | jsCallInvoker->invokeAsync( 188 | [resolve, reject, result, &runtime]() { 189 | if (!result.empty()) { 190 | resolve->asObject(runtime).asFunction(runtime).call( 191 | runtime, result); 192 | } else { 193 | auto error = 194 | generateJSError(runtime, "Value does not exist"); 195 | reject->asObject(runtime).asFunction(runtime).call( 196 | runtime, error); 197 | } 198 | }); 199 | } catch (const std::exception &exception) { 200 | jsCallInvoker->invokeAsync([reject, &runtime, &exception]() { 201 | auto error = generateJSError(runtime, exception.what()); 202 | reject->asObject(runtime).asFunction(runtime).call( 203 | runtime, error); 204 | }); 205 | } 206 | }).detach(); 207 | return jsi::Value(); 208 | })); 209 | }); 210 | 211 | auto getAllKeys = CREATE_HOST_FN("getAllKeys", 1) { 212 | auto promise = runtime.global().getPropertyAsFunction(runtime, "Promise"); 213 | return promise.callAsConstructor( 214 | runtime, 215 | Function::createFromHostFunction( 216 | runtime, 217 | PropNameID::forAscii(runtime, "executor"), 218 | 1, 219 | [jsCallInvoker = jsCallInvoker]( 220 | Runtime &runtime, 221 | const Value &thisValue, 222 | const Value *args, 223 | size_t) -> Value { 224 | auto resolve = make_shared(runtime, args[0]); 225 | auto reject = make_shared(runtime, args[1]); 226 | std::thread([resolve = std::move(resolve), 227 | reject = std::move(reject), 228 | jsCallInvoker, 229 | &runtime]() { 230 | try { 231 | auto result = _getAllKeys(); 232 | jsCallInvoker->invokeAsync( 233 | [resolve, reject, result, &runtime]() { 234 | if (!result.empty()) { 235 | resolve->asObject(runtime).asFunction(runtime).call( 236 | runtime, result); 237 | } else { 238 | auto error = 239 | generateJSError(runtime, "Value does not exist"); 240 | reject->asObject(runtime).asFunction(runtime).call( 241 | runtime, error); 242 | } 243 | }); 244 | } catch (const std::exception &exception) { 245 | jsCallInvoker->invokeAsync([reject, &runtime, &exception]() { 246 | auto error = generateJSError(runtime, exception.what()); 247 | reject->asObject(runtime).asFunction(runtime).call( 248 | runtime, error); 249 | }); 250 | } 251 | }).detach(); 252 | return jsi::Value(); 253 | })); 254 | }); 255 | 256 | auto getAllItems = CREATE_HOST_FN("getAllItems", 0) { 257 | auto promise = runtime.global().getPropertyAsFunction(runtime, "Promise"); 258 | return promise.callAsConstructor( 259 | runtime, 260 | Function::createFromHostFunction( 261 | runtime, 262 | PropNameID::forAscii(runtime, "executor"), 263 | 1, 264 | [jsCallInvoker = jsCallInvoker]( 265 | Runtime &runtime, 266 | const Value &thisValue, 267 | const Value *args, 268 | size_t) -> Value { 269 | auto resolve = make_shared(runtime, args[0]); 270 | auto reject = make_shared(runtime, args[1]); 271 | std::thread([resolve = std::move(resolve), 272 | reject = std::move(reject), 273 | jsCallInvoker, 274 | &runtime]() { 275 | try { 276 | auto result = _getAllItems(); 277 | jsCallInvoker->invokeAsync( 278 | [resolve, reject, result, &runtime]() { 279 | resolve->asObject(runtime).asFunction(runtime).call( 280 | runtime, result); 281 | }); 282 | } catch (const std::exception &exception) { 283 | jsCallInvoker->invokeAsync([reject, &runtime, &exception]() { 284 | auto error = generateJSError(runtime, exception.what()); 285 | reject->asObject(runtime).asFunction(runtime).call( 286 | runtime, error); 287 | }); 288 | } 289 | }).detach(); 290 | return jsi::Value(); 291 | })); 292 | }); 293 | 294 | auto hasItem = CREATE_HOST_FN("hasItem", 1) { 295 | if (!arguments[0].isString()) { 296 | throw jsi::JSError(runtime, "hasItem: key must be a string!"); 297 | } 298 | auto key = arguments[0].getString(runtime).utf8(runtime); 299 | auto promise = runtime.global().getPropertyAsFunction(runtime, "Promise"); 300 | return promise.callAsConstructor( 301 | runtime, 302 | Function::createFromHostFunction( 303 | runtime, 304 | PropNameID::forAscii(runtime, "executor"), 305 | 2, 306 | [key, jsCallInvoker = jsCallInvoker]( 307 | Runtime &runtime, 308 | const Value &thisValue, 309 | const Value *args, 310 | size_t) -> Value { 311 | auto resolve = make_shared(runtime, args[0]); 312 | auto reject = make_shared(runtime, args[1]); 313 | std::thread([key, 314 | resolve = std::move(resolve), 315 | reject = std::move(reject), 316 | jsCallInvoker, 317 | &runtime]() { 318 | try { 319 | bool result = _hasItem(key); 320 | jsCallInvoker->invokeAsync([resolve, result, &runtime]() { 321 | resolve->asObject(runtime).asFunction(runtime).call( 322 | runtime, result); 323 | }); 324 | } catch (const std::exception &exception) { 325 | jsCallInvoker->invokeAsync([reject, &runtime, &exception]() { 326 | reject->asObject(runtime).asFunction(runtime).call( 327 | runtime, exception.what()); 328 | }); 329 | } 330 | }).detach(); 331 | return jsi::Value(); 332 | })); 333 | 334 | return Value(); 335 | }); 336 | 337 | auto removeItem = CREATE_HOST_FN("removeItem", 1) { 338 | if (!arguments[0].isString()) { 339 | throw jsi::JSError(runtime, "removeItem: key must be a string value"); 340 | } 341 | std::string key = arguments[0].getString(runtime).utf8(runtime); 342 | auto promise = runtime.global().getPropertyAsFunction(runtime, "Promise"); 343 | return promise.callAsConstructor( 344 | runtime, 345 | Function::createFromHostFunction( 346 | runtime, 347 | PropNameID::forAscii(runtime, "executor"), 348 | 2, 349 | [key, jsCallInvoker = jsCallInvoker]( 350 | Runtime &runtime, 351 | const Value &thisValue, 352 | const Value *args, 353 | size_t) -> Value { 354 | auto resolve = make_shared(runtime, args[0]); 355 | auto reject = make_shared(runtime, args[1]); 356 | std::thread([key, 357 | resolve = std::move(resolve), 358 | reject = std::move(reject), 359 | jsCallInvoker, 360 | &runtime]() { 361 | try { 362 | bool result = _del(key); 363 | jsCallInvoker->invokeAsync([resolve, result, &runtime]() { 364 | resolve->asObject(runtime).asFunction(runtime).call( 365 | runtime, result); 366 | }); 367 | } catch (const std::exception &exception) { 368 | jsCallInvoker->invokeAsync([reject, &runtime, &exception]() { 369 | reject->asObject(runtime).asFunction(runtime).call( 370 | runtime, exception.what()); 371 | }); 372 | } 373 | }).detach(); 374 | return jsi::Value(); 375 | })); 376 | 377 | return Value(); 378 | }); 379 | 380 | auto clearStorage = CREATE_HOST_FN("clearStorage", 0) { 381 | auto promise = runtime.global().getPropertyAsFunction(runtime, "Promise"); 382 | return promise.callAsConstructor( 383 | runtime, 384 | Function::createFromHostFunction( 385 | runtime, 386 | PropNameID::forAscii(runtime, "executor"), 387 | 1, 388 | [jsCallInvoker = jsCallInvoker]( 389 | Runtime &runtime, 390 | const Value &thisValue, 391 | const Value *args, 392 | size_t) -> Value { 393 | auto resolve = make_shared(runtime, args[0]); 394 | auto reject = make_shared(runtime, args[1]); 395 | std::thread([resolve = std::move(resolve), 396 | jsCallInvoker, 397 | &runtime]() { 398 | _clearStorage(); 399 | jsCallInvoker->invokeAsync([resolve, &runtime]() { 400 | resolve->asObject(runtime).asFunction(runtime).call(runtime); 401 | }); 402 | }).detach(); 403 | return jsi::Value(); 404 | })); 405 | 406 | return Value(); 407 | }); 408 | 409 | auto hasItemSync = CREATE_HOST_FN("hasItemSync", 1) { 410 | if (!arguments[0].isString()) { 411 | throw jsi::JSError(runtime, "hasItemSync: key must be a string value!"); 412 | } 413 | 414 | const std::string key = arguments[0].getString(runtime).utf8(runtime); 415 | 416 | auto result = _hasItem(key); 417 | 418 | return Value(result); 419 | }); 420 | 421 | auto setItemSync = CREATE_HOST_FN("setItemSync", 3) { 422 | if (!arguments[0].isString()) { 423 | throw jsi::JSError(runtime, "setItemSync: key must be a string value!"); 424 | } 425 | 426 | if (!arguments[1].isString()) { 427 | throw jsi::JSError(runtime, "setItemSync: value must be a string value!"); 428 | } 429 | 430 | const std::string key = arguments[0].getString(runtime).utf8(runtime); 431 | const std::string value = arguments[1].getString(runtime).utf8(runtime); 432 | const int accessible = arguments[2].getNumber(); 433 | 434 | auto result = _set(key, value, accessible); 435 | 436 | return Value(result); 437 | }); 438 | 439 | auto removeItemSync = CREATE_HOST_FN("removeItemSync", 1) { 440 | if (!arguments[0].isString()) { 441 | throw jsi::JSError( 442 | runtime, "removeItemSync: key must be a string value!"); 443 | } 444 | 445 | const std::string key = arguments[0].getString(runtime).utf8(runtime); 446 | 447 | auto result = _del(key); 448 | 449 | return Value(result); 450 | }); 451 | 452 | auto getItemSync = CREATE_HOST_FN("getItemSync", 1) { 453 | if (!arguments[0].isString()) { 454 | throw jsi::JSError(runtime, "getItemSync: key must be a string value!"); 455 | } 456 | 457 | const std::string key = arguments[0].getString(runtime).utf8(runtime); 458 | 459 | auto value = _get(key); 460 | 461 | return Value(runtime, jsi::String::createFromUtf8(runtime, value)); 462 | }); 463 | 464 | jsi::Object module = jsi::Object(runtime); 465 | 466 | module.setProperty(runtime, "setItem", setItem); 467 | module.setProperty(runtime, "getItem", getItem); 468 | module.setProperty(runtime, "hasItem", hasItem); 469 | module.setProperty(runtime, "removeItem", removeItem); 470 | module.setProperty(runtime, "clearStorage", clearStorage); 471 | module.setProperty(runtime, "setItems", setItems); 472 | module.setProperty(runtime, "getAllKeys", getAllKeys); 473 | module.setProperty(runtime, "getAllItems", getAllItems); 474 | module.setProperty(runtime, "hasItemSync", hasItemSync); 475 | module.setProperty(runtime, "setItemSync", setItemSync); 476 | module.setProperty(runtime, "removeItemSync", removeItemSync); 477 | module.setProperty(runtime, "getItemSync", getItemSync); 478 | 479 | runtime.global().setProperty(runtime, "__SecureStorage", std::move(module)); 480 | } 481 | } // namespace securestorageHostObject 482 | -------------------------------------------------------------------------------- /cpp/SecureStorageHostObject.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace securestorageHostObject { 5 | namespace react = facebook::react; 6 | namespace jsi = facebook::jsi; 7 | using namespace std; 8 | 9 | void install( 10 | jsi::Runtime &rt, 11 | shared_ptr jsCallInvoker, 12 | function setItemFn, 13 | function getItemFn, 14 | function deleteItemFn, 15 | function clearStorageFn, 16 | function getAllKeysFn, 17 | function getAllItemsFn, 18 | function hasItemFn); 19 | } // namespace securestorageHostObject 20 | -------------------------------------------------------------------------------- /cpp/macros.h: -------------------------------------------------------------------------------- 1 | #ifndef macros_h 2 | #define macros_h 3 | 4 | #define CREATE_HOST_FN(name, basecount) \ 5 | jsi::Function::createFromHostFunction( \ 6 | runtime, \ 7 | jsi::PropNameID::forAscii(runtime, name), \ 8 | basecount, \ 9 | [=](jsi::Runtime &runtime, const jsi::Value &thisValue, const jsi::Value *arguments, size_t count) -> jsi::Value 10 | 11 | #endif /* macros_h */ -------------------------------------------------------------------------------- /example/.bundle/config: -------------------------------------------------------------------------------- 1 | BUNDLE_PATH: "vendor/bundle" 2 | BUNDLE_FORCE_RUBY_PLATFORM: 1 3 | -------------------------------------------------------------------------------- /example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /example/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version 4 | ruby ">= 2.6.10" 5 | 6 | # Exclude problematic versions of cocoapods and activesupport that causes build failures. 7 | gem 'cocoapods', '>= 1.13', '!= 1.15.0', '!= 1.15.1' 8 | gem 'activesupport', '>= 6.1.7.5', '!= 7.1.0' 9 | gem 'xcodeproj', '< 1.26.0' -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | This is a new [**React Native**](https://reactnative.dev) project, bootstrapped using [`@react-native-community/cli`](https://github.com/react-native-community/cli). 2 | 3 | # Getting Started 4 | 5 | >**Note**: Make sure you have completed the [React Native - Environment Setup](https://reactnative.dev/docs/environment-setup) instructions till "Creating a new application" step, before proceeding. 6 | 7 | ## Step 1: Start the Metro Server 8 | 9 | First, you will need to start **Metro**, the JavaScript _bundler_ that ships _with_ React Native. 10 | 11 | To start Metro, run the following command from the _root_ of your React Native project: 12 | 13 | ```bash 14 | # using npm 15 | npm start 16 | 17 | # OR using Yarn 18 | yarn start 19 | ``` 20 | 21 | ## Step 2: Start your Application 22 | 23 | Let Metro Bundler run in its _own_ terminal. Open a _new_ terminal from the _root_ of your React Native project. Run the following command to start your _Android_ or _iOS_ app: 24 | 25 | ### For Android 26 | 27 | ```bash 28 | # using npm 29 | npm run android 30 | 31 | # OR using Yarn 32 | yarn android 33 | ``` 34 | 35 | ### For iOS 36 | 37 | ```bash 38 | # using npm 39 | npm run ios 40 | 41 | # OR using Yarn 42 | yarn ios 43 | ``` 44 | 45 | If everything is set up _correctly_, you should see your new app running in your _Android Emulator_ or _iOS Simulator_ shortly provided you have set up your emulator/simulator correctly. 46 | 47 | This is one way to run your app — you can also run it directly from within Android Studio and Xcode respectively. 48 | 49 | ## Step 3: Modifying your App 50 | 51 | Now that you have successfully run the app, let's modify it. 52 | 53 | 1. Open `App.tsx` in your text editor of choice and edit some lines. 54 | 2. For **Android**: Press the R key twice or select **"Reload"** from the **Developer Menu** (Ctrl + M (on Window and Linux) or Cmd ⌘ + M (on macOS)) to see your changes! 55 | 56 | For **iOS**: Hit Cmd ⌘ + R in your iOS Simulator to reload the app and see your changes! 57 | 58 | ## Congratulations! :tada: 59 | 60 | You've successfully run and modified your React Native App. :partying_face: 61 | 62 | ### Now what? 63 | 64 | - If you want to add this new React Native code to an existing application, check out the [Integration guide](https://reactnative.dev/docs/integration-with-existing-apps). 65 | - If you're curious to learn more about React Native, check out the [Introduction to React Native](https://reactnative.dev/docs/getting-started). 66 | 67 | # Troubleshooting 68 | 69 | If you can't get this to work, see the [Troubleshooting](https://reactnative.dev/docs/troubleshooting) page. 70 | 71 | # Learn More 72 | 73 | To learn more about React Native, take a look at the following resources: 74 | 75 | - [React Native Website](https://reactnative.dev) - learn more about React Native. 76 | - [Getting Started](https://reactnative.dev/docs/environment-setup) - an **overview** of React Native and how setup your environment. 77 | - [Learn the Basics](https://reactnative.dev/docs/getting-started) - a **guided tour** of the React Native **basics**. 78 | - [Blog](https://reactnative.dev/blog) - read the latest official React Native **Blog** posts. 79 | - [`@facebook/react-native`](https://github.com/facebook/react-native) - the Open Source; GitHub **repository** for React Native. 80 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | apply plugin: "org.jetbrains.kotlin.android" 3 | apply plugin: "com.facebook.react" 4 | 5 | /** 6 | * This is the configuration block to customize your React Native Android app. 7 | * By default you don't need to apply any configuration, just uncomment the lines you need. 8 | */ 9 | react { 10 | /* Folders */ 11 | // The root of your project, i.e. where "package.json" lives. Default is '../..' 12 | // root = file("../../") 13 | // The folder where the react-native NPM package is. Default is ../../node_modules/react-native 14 | // reactNativeDir = file("../../node_modules/react-native") 15 | // The folder where the react-native Codegen package is. Default is ../../node_modules/@react-native/codegen 16 | // codegenDir = file("../../node_modules/@react-native/codegen") 17 | // The cli.js file which is the React Native CLI entrypoint. Default is ../../node_modules/react-native/cli.js 18 | // cliFile = file("../../node_modules/react-native/cli.js") 19 | 20 | /* Variants */ 21 | // The list of variants to that are debuggable. For those we're going to 22 | // skip the bundling of the JS bundle and the assets. By default is just 'debug'. 23 | // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants. 24 | // debuggableVariants = ["liteDebug", "prodDebug"] 25 | 26 | /* Bundling */ 27 | // A list containing the node command and its flags. Default is just 'node'. 28 | // nodeExecutableAndArgs = ["node"] 29 | // 30 | // The command to run when bundling. By default is 'bundle' 31 | // bundleCommand = "ram-bundle" 32 | // 33 | // The path to the CLI configuration file. Default is empty. 34 | // bundleConfig = file(../rn-cli.config.js) 35 | // 36 | // The name of the generated asset file containing your JS bundle 37 | // bundleAssetName = "MyApplication.android.bundle" 38 | // 39 | // The entry file for bundle generation. Default is 'index.android.js' or 'index.js' 40 | // entryFile = file("../js/MyApplication.android.js") 41 | // 42 | // A list of extra flags to pass to the 'bundle' commands. 43 | // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle 44 | // extraPackagerArgs = [] 45 | 46 | /* Hermes Commands */ 47 | // The hermes compiler command to run. By default it is 'hermesc' 48 | // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc" 49 | // 50 | // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map" 51 | // hermesFlags = ["-O", "-output-source-map"] 52 | 53 | /* Autolinking */ 54 | autolinkLibrariesWithApp() 55 | } 56 | 57 | /** 58 | * Set this to true to Run Proguard on Release builds to minify the Java bytecode. 59 | */ 60 | def enableProguardInReleaseBuilds = true 61 | 62 | /** 63 | * The preferred build flavor of JavaScriptCore (JSC) 64 | * 65 | * For example, to use the international variant, you can use: 66 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` 67 | * 68 | * The international variant includes ICU i18n library and necessary data 69 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that 70 | * give correct results when using with locales other than en-US. Note that 71 | * this variant is about 6MiB larger per architecture than default. 72 | */ 73 | def jscFlavor = 'org.webkit:android-jsc:+' 74 | 75 | android { 76 | ndkVersion rootProject.ext.ndkVersion 77 | buildToolsVersion rootProject.ext.buildToolsVersion 78 | compileSdk rootProject.ext.compileSdkVersion 79 | 80 | namespace "fastsecurestorage.example" 81 | defaultConfig { 82 | applicationId "fastsecurestorage.example" 83 | minSdkVersion rootProject.ext.minSdkVersion 84 | targetSdkVersion rootProject.ext.targetSdkVersion 85 | versionCode 1 86 | versionName "1.0" 87 | } 88 | signingConfigs { 89 | debug { 90 | storeFile file('debug.keystore') 91 | storePassword 'android' 92 | keyAlias 'androiddebugkey' 93 | keyPassword 'android' 94 | } 95 | } 96 | buildTypes { 97 | debug { 98 | signingConfig signingConfigs.debug 99 | } 100 | release { 101 | // Caution! In production, you need to generate your own keystore file. 102 | // see https://reactnative.dev/docs/signed-apk-android. 103 | signingConfig signingConfigs.debug 104 | minifyEnabled enableProguardInReleaseBuilds 105 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 106 | } 107 | } 108 | } 109 | 110 | dependencies { 111 | // The version of react-native is set by the React Native Gradle Plugin 112 | implementation("com.facebook.react:react-android") 113 | 114 | if (hermesEnabled.toBoolean()) { 115 | implementation("com.facebook.react:hermes-android") 116 | } else { 117 | implementation jscFlavor 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /example/android/app/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/app/debug.keystore -------------------------------------------------------------------------------- /example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 13 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/fastsecurestorage/example/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package fastsecurestorage.example 2 | 3 | import com.facebook.react.ReactActivity 4 | import com.facebook.react.ReactActivityDelegate 5 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled 6 | import com.facebook.react.defaults.DefaultReactActivityDelegate 7 | 8 | class MainActivity : ReactActivity() { 9 | 10 | /** 11 | * Returns the name of the main component registered from JavaScript. This is used to schedule 12 | * rendering of the component. 13 | */ 14 | override fun getMainComponentName(): String = "FastSecureStorageExample" 15 | 16 | /** 17 | * Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate] 18 | * which allows you to enable New Architecture with a single boolean flags [fabricEnabled] 19 | */ 20 | override fun createReactActivityDelegate(): ReactActivityDelegate = 21 | DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled) 22 | } 23 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/fastsecurestorage/example/MainApplication.kt: -------------------------------------------------------------------------------- 1 | package fastsecurestorage.example 2 | 3 | import android.app.Application 4 | import com.facebook.react.PackageList 5 | import com.facebook.react.ReactApplication 6 | import com.facebook.react.ReactHost 7 | import com.facebook.react.ReactNativeHost 8 | import com.facebook.react.ReactPackage 9 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load 10 | import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost 11 | import com.facebook.react.defaults.DefaultReactNativeHost 12 | import com.facebook.react.soloader.OpenSourceMergedSoMapping 13 | import com.facebook.soloader.SoLoader 14 | 15 | class MainApplication : Application(), ReactApplication { 16 | 17 | override val reactNativeHost: ReactNativeHost = 18 | object : DefaultReactNativeHost(this) { 19 | override fun getPackages(): List = 20 | PackageList(this).packages.apply { 21 | // Packages that cannot be autolinked yet can be added manually here, for example: 22 | // add(MyReactNativePackage()) 23 | } 24 | 25 | override fun getJSMainModuleName(): String = "index" 26 | 27 | override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG 28 | 29 | override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED 30 | override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED 31 | } 32 | 33 | override val reactHost: ReactHost 34 | get() = getDefaultReactHost(applicationContext, reactNativeHost) 35 | 36 | override fun onCreate() { 37 | super.onCreate() 38 | SoLoader.init(this, OpenSourceMergedSoMapping) 39 | if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { 40 | // If you opted-in for the New Architecture, we load the native entry point for this app. 41 | load() 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/rn_edit_text_material.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 22 | 23 | 24 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | FastSecureStorageExample 3 | 4 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | buildToolsVersion = "35.0.0" 4 | minSdkVersion = 24 5 | compileSdkVersion = 35 6 | targetSdkVersion = 35 7 | ndkVersion = "26.1.10909125" 8 | kotlinVersion = "1.9.24" 9 | } 10 | repositories { 11 | google() 12 | mavenCentral() 13 | } 14 | dependencies { 15 | classpath("com.android.tools.build:gradle") 16 | classpath("com.facebook.react:react-native-gradle-plugin") 17 | classpath("org.jetbrains.kotlin:kotlin-gradle-plugin") 18 | } 19 | } 20 | 21 | apply plugin: "com.facebook.react.rootproject" 22 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx512m -XX:MaxMetaspaceSize=256m 13 | org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | # AndroidX package structure to make it clearer which packages are bundled with the 21 | # Android operating system, and which are packaged with your app's APK 22 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 23 | android.useAndroidX=true 24 | 25 | # Use this property to specify which architecture you want to build. 26 | # You can also override it from the CLI using 27 | # ./gradlew -PreactNativeArchitectures=x86_64 28 | reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64 29 | 30 | # Use this property to enable support to the new architecture. 31 | # This will allow you to use TurboModules and the Fabric render in 32 | # your application. You should enable this flag either if you want 33 | # to write custom TurboModules/Fabric components OR use libraries that 34 | # are providing them. 35 | newArchEnabled=true 36 | 37 | # Use this property to enable or disable the Hermes JS engine. 38 | # If set to false, you will be using JSC instead. 39 | hermesEnabled=true 40 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 87 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s 88 | ' "$PWD" ) || exit 89 | 90 | # Use the maximum available, or set MAX_FD != -1 to use that value. 91 | MAX_FD=maximum 92 | 93 | warn () { 94 | echo "$*" 95 | } >&2 96 | 97 | die () { 98 | echo 99 | echo "$*" 100 | echo 101 | exit 1 102 | } >&2 103 | 104 | # OS specific support (must be 'true' or 'false'). 105 | cygwin=false 106 | msys=false 107 | darwin=false 108 | nonstop=false 109 | case "$( uname )" in #( 110 | CYGWIN* ) cygwin=true ;; #( 111 | Darwin* ) darwin=true ;; #( 112 | MSYS* | MINGW* ) msys=true ;; #( 113 | NONSTOP* ) nonstop=true ;; 114 | esac 115 | 116 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 117 | 118 | 119 | # Determine the Java command to use to start the JVM. 120 | if [ -n "$JAVA_HOME" ] ; then 121 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 122 | # IBM's JDK on AIX uses strange locations for the executables 123 | JAVACMD=$JAVA_HOME/jre/sh/java 124 | else 125 | JAVACMD=$JAVA_HOME/bin/java 126 | fi 127 | if [ ! -x "$JAVACMD" ] ; then 128 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 129 | 130 | Please set the JAVA_HOME variable in your environment to match the 131 | location of your Java installation." 132 | fi 133 | else 134 | JAVACMD=java 135 | if ! command -v java >/dev/null 2>&1 136 | then 137 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 138 | 139 | Please set the JAVA_HOME variable in your environment to match the 140 | location of your Java installation." 141 | fi 142 | fi 143 | 144 | # Increase the maximum file descriptors if we can. 145 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 146 | case $MAX_FD in #( 147 | max*) 148 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 149 | # shellcheck disable=SC2039,SC3045 150 | MAX_FD=$( ulimit -H -n ) || 151 | warn "Could not query maximum file descriptor limit" 152 | esac 153 | case $MAX_FD in #( 154 | '' | soft) :;; #( 155 | *) 156 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 157 | # shellcheck disable=SC2039,SC3045 158 | ulimit -n "$MAX_FD" || 159 | warn "Could not set maximum file descriptor limit to $MAX_FD" 160 | esac 161 | fi 162 | 163 | # Collect all arguments for the java command, stacking in reverse order: 164 | # * args from the command line 165 | # * the main class name 166 | # * -classpath 167 | # * -D...appname settings 168 | # * --module-path (only if needed) 169 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 170 | 171 | # For Cygwin or MSYS, switch paths to Windows format before running java 172 | if "$cygwin" || "$msys" ; then 173 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 174 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 175 | 176 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 177 | 178 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 179 | for arg do 180 | if 181 | case $arg in #( 182 | -*) false ;; # don't mess with options #( 183 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 184 | [ -e "$t" ] ;; #( 185 | *) false ;; 186 | esac 187 | then 188 | arg=$( cygpath --path --ignore --mixed "$arg" ) 189 | fi 190 | # Roll the args list around exactly as many times as the number of 191 | # args, so each arg winds up back in the position where it started, but 192 | # possibly modified. 193 | # 194 | # NB: a `for` loop captures its iteration list before it begins, so 195 | # changing the positional parameters here affects neither the number of 196 | # iterations, nor the values presented in `arg`. 197 | shift # remove old arg 198 | set -- "$@" "$arg" # push replacement arg 199 | done 200 | fi 201 | 202 | 203 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 204 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 205 | 206 | # Collect all arguments for the java command: 207 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 208 | # and any embedded shellness will be escaped. 209 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 210 | # treated as '${Hostname}' itself on the command line. 211 | 212 | set -- \ 213 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 214 | -classpath "$CLASSPATH" \ 215 | org.gradle.wrapper.GradleWrapperMain \ 216 | "$@" 217 | 218 | # Stop when "xargs" is not available. 219 | if ! command -v xargs >/dev/null 2>&1 220 | then 221 | die "xargs is not available" 222 | fi 223 | 224 | # Use "xargs" to parse quoted args. 225 | # 226 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 227 | # 228 | # In Bash we could simply go: 229 | # 230 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 231 | # set -- "${ARGS[@]}" "$@" 232 | # 233 | # but POSIX shell has neither arrays nor command substitution, so instead we 234 | # post-process each arg (as a line of input to sed) to backslash-escape any 235 | # character that might be a shell metacharacter, then use eval to reverse 236 | # that process (while maintaining the separation between arguments), and wrap 237 | # the whole thing up as a single "set" statement. 238 | # 239 | # This will of course break if any of these variables contains a newline or 240 | # an unmatched quote. 241 | # 242 | 243 | eval "set -- $( 244 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 245 | xargs -n1 | 246 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 247 | tr '\n' ' ' 248 | )" '"$@"' 249 | 250 | exec "$JAVACMD" "$@" 251 | -------------------------------------------------------------------------------- /example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 1>&2 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 48 | echo. 1>&2 49 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 50 | echo location of your Java installation. 1>&2 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 1>&2 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 62 | echo. 1>&2 63 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 64 | echo location of your Java installation. 1>&2 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("com.android.application") 3 | id("org.jetbrains.kotlin.android") 4 | } 5 | 6 | android { 7 | namespace = "com.example.cpp" 8 | compileSdk = 34 9 | 10 | defaultConfig { 11 | applicationId = "com.example.cpp" 12 | minSdk = 24 13 | targetSdk = 34 14 | versionCode = 1 15 | versionName = "1.0" 16 | 17 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 18 | } 19 | 20 | buildTypes { 21 | release { 22 | isMinifyEnabled = false 23 | proguardFiles( 24 | getDefaultProguardFile("proguard-android-optimize.txt"), 25 | "proguard-rules.pro" 26 | ) 27 | } 28 | } 29 | compileOptions { 30 | sourceCompatibility = JavaVersion.VERSION_1_8 31 | targetCompatibility = JavaVersion.VERSION_1_8 32 | } 33 | kotlinOptions { 34 | jvmTarget = "1.8" 35 | } 36 | } 37 | 38 | dependencies { 39 | 40 | implementation("androidx.core:core-ktx:1.10.1") 41 | implementation("androidx.appcompat:appcompat:1.6.1") 42 | implementation("com.google.android.material:material:1.10.0") 43 | testImplementation("junit:junit:4.13.2") 44 | androidTestImplementation("androidx.test.ext:junit:1.1.5") 45 | androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") 46 | } 47 | -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/androidTest/java/com/example/cpp/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.cpp 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.example.cpp", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/main/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | 31 | -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IvanIhnatsiuk/react-native-fast-secure-storage/1136a11ba1ac5275d184694a5936f78671107514/example/android/react-native-fast-secure-storage/cpp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | 17 | -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | 11 | -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | cpp 3 | -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | 17 | -------------------------------------------------------------------------------- /example/android/react-native-fast-secure-storage/cpp/src/test/java/com/example/cpp/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.cpp 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { includeBuild("../node_modules/@react-native/gradle-plugin") } 2 | plugins { id("com.facebook.react.settings") } 3 | extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() } 4 | rootProject.name = 'fastsecurestorage.example' 5 | include ':app' 6 | includeBuild('../node_modules/@react-native/gradle-plugin') 7 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "FastSecureStorageExample", 3 | "displayName": "FastSecureStorageExample" 4 | } 5 | -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | 3 | const { getConfig } = require("react-native-builder-bob/babel-config"); 4 | 5 | const pkg = require("../package.json"); 6 | 7 | const root = path.resolve(__dirname, ".."); 8 | 9 | module.exports = getConfig( 10 | { 11 | presets: ["module:@react-native/babel-preset"], 12 | }, 13 | { root, pkg }, 14 | ); 15 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | import { AppRegistry } from "react-native"; 2 | 3 | import { name as appName } from "./app.json"; 4 | import App from "./src/App"; 5 | 6 | AppRegistry.registerComponent(appName, () => App); 7 | -------------------------------------------------------------------------------- /example/ios/.xcode.env: -------------------------------------------------------------------------------- 1 | # This `.xcode.env` file is versioned and is used to source the environment 2 | # used when running script phases inside Xcode. 3 | # To customize your local environment, you can create an `.xcode.env.local` 4 | # file that is not versioned. 5 | 6 | # NODE_BINARY variable contains the PATH to the node executable. 7 | # 8 | # Customize the NODE_BINARY variable here. 9 | # For example, to use nvm with brew, add the following line 10 | # . "$(brew --prefix nvm)/nvm.sh" --no-use 11 | export NODE_BINARY=$(command -v node) 12 | -------------------------------------------------------------------------------- /example/ios/FastSecureStorageExample.xcodeproj/xcshareddata/xcschemes/FastSecureStorageExample.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 53 | 55 | 61 | 62 | 63 | 64 | 70 | 72 | 78 | 79 | 80 | 81 | 83 | 84 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /example/ios/FastSecureStorageExample.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/ios/FastSecureStorageExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/FastSecureStorageExample/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface AppDelegate : RCTAppDelegate 5 | 6 | @end 7 | -------------------------------------------------------------------------------- /example/ios/FastSecureStorageExample/AppDelegate.mm: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | 3 | #import 4 | 5 | @implementation AppDelegate 6 | 7 | - (BOOL)application:(UIApplication *)application 8 | didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 9 | { 10 | self.moduleName = @"FastSecureStorageExample"; 11 | // You can add your custom initial props in the dictionary below. 12 | // They will be passed down to the ViewController used by React Native. 13 | self.initialProps = @{}; 14 | 15 | return [super application:application didFinishLaunchingWithOptions:launchOptions]; 16 | } 17 | 18 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge 19 | { 20 | return [self bundleURL]; 21 | } 22 | 23 | - (NSURL *)bundleURL 24 | { 25 | #if DEBUG 26 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; 27 | #else 28 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 29 | #endif 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /example/ios/FastSecureStorageExample/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ios-marketing", 45 | "scale" : "1x", 46 | "size" : "1024x1024" 47 | } 48 | ], 49 | "info" : { 50 | "author" : "xcode", 51 | "version" : 1 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /example/ios/FastSecureStorageExample/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /example/ios/FastSecureStorageExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | FastSecureStorageExample 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(MARKETING_VERSION) 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | $(CURRENT_PROJECT_VERSION) 25 | LSRequiresIPhoneOS 26 | 27 | NSAppTransportSecurity 28 | 29 | 30 | NSAllowsArbitraryLoads 31 | 32 | NSAllowsLocalNetworking 33 | 34 | 35 | NSLocationWhenInUseUsageDescription 36 | 37 | UILaunchStoryboardName 38 | LaunchScreen 39 | UIRequiredDeviceCapabilities 40 | 41 | arm64 42 | 43 | UISupportedInterfaceOrientations 44 | 45 | UIInterfaceOrientationPortrait 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | UIViewControllerBasedStatusBarAppearance 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /example/ios/FastSecureStorageExample/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 24 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /example/ios/FastSecureStorageExample/PrivacyInfo.xcprivacy: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSPrivacyAccessedAPITypes 6 | 7 | 8 | NSPrivacyAccessedAPIType 9 | NSPrivacyAccessedAPICategoryFileTimestamp 10 | NSPrivacyAccessedAPITypeReasons 11 | 12 | C617.1 13 | 14 | 15 | 16 | NSPrivacyAccessedAPIType 17 | NSPrivacyAccessedAPICategoryUserDefaults 18 | NSPrivacyAccessedAPITypeReasons 19 | 20 | CA92.1 21 | 22 | 23 | 24 | NSPrivacyAccessedAPIType 25 | NSPrivacyAccessedAPICategorySystemBootTime 26 | NSPrivacyAccessedAPITypeReasons 27 | 28 | 35F9.1 29 | 30 | 31 | 32 | NSPrivacyCollectedDataTypes 33 | 34 | NSPrivacyTracking 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example/ios/FastSecureStorageExample/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "AppDelegate.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | @autoreleasepool { 8 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /example/ios/FastSecureStorageExampleTests/FastSecureStorageExampleTests.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | #import 5 | #import 6 | 7 | #define TIMEOUT_SECONDS 600 8 | #define TEXT_TO_LOOK_FOR @"Welcome to React" 9 | 10 | @interface FastSecureStorageExampleTests : XCTestCase 11 | 12 | @end 13 | 14 | @implementation FastSecureStorageExampleTests 15 | 16 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL (^)(UIView *view))test 17 | { 18 | if (test(view)) { 19 | return YES; 20 | } 21 | for (UIView *subview in [view subviews]) { 22 | if ([self findSubviewInView:subview matching:test]) { 23 | return YES; 24 | } 25 | } 26 | return NO; 27 | } 28 | 29 | - (void)testRendersWelcomeScreen 30 | { 31 | UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController]; 32 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; 33 | BOOL foundElement = NO; 34 | 35 | __block NSString *redboxError = nil; 36 | #ifdef DEBUG 37 | RCTSetLogFunction( 38 | ^(RCTLogLevel level, 39 | RCTLogSource source, 40 | NSString *fileName, 41 | NSNumber *lineNumber, 42 | NSString *message) { 43 | if (level >= RCTLogLevelError) { 44 | redboxError = message; 45 | } 46 | }); 47 | #endif 48 | 49 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { 50 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode 51 | beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 52 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes 53 | beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 54 | 55 | foundElement = 56 | [self findSubviewInView:vc.view 57 | matching:^BOOL(UIView *view) { 58 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { 59 | return YES; 60 | } 61 | return NO; 62 | }]; 63 | } 64 | 65 | #ifdef DEBUG 66 | RCTSetLogFunction(RCTDefaultLogFunction); 67 | #endif 68 | 69 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); 70 | XCTAssertTrue( 71 | foundElement, 72 | @"Couldn't find element with text '%@' in %d seconds", 73 | TEXT_TO_LOOK_FOR, 74 | TIMEOUT_SECONDS); 75 | } 76 | 77 | @end 78 | -------------------------------------------------------------------------------- /example/ios/FastSecureStorageExampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /example/ios/Podfile: -------------------------------------------------------------------------------- 1 | # Resolve react_native_pods.rb with node to allow for hoisting 2 | require Pod::Executable.execute_command('node', ['-p', 3 | 'require.resolve( 4 | "react-native/scripts/react_native_pods.rb", 5 | {paths: [process.argv[1]]}, 6 | )', __dir__]).strip 7 | 8 | platform :ios, min_ios_version_supported 9 | prepare_react_native_project! 10 | 11 | linkage = ENV['USE_FRAMEWORKS'] 12 | if linkage != nil 13 | Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green 14 | use_frameworks! :linkage => linkage.to_sym 15 | end 16 | 17 | target 'FastSecureStorageExample' do 18 | config = use_native_modules! 19 | 20 | use_react_native!( 21 | :path => config[:reactNativePath], 22 | # An absolute path to your application root. 23 | :app_path => "#{Pod::Config.instance.installation_root}/.." 24 | ) 25 | 26 | target 'FastSecureStorageExampleTests' do 27 | inherit! :complete 28 | # Pods for testing 29 | end 30 | 31 | post_install do |installer| 32 | # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202 33 | react_native_post_install( 34 | installer, 35 | config[:reactNativePath], 36 | :mac_catalyst_enabled => false, 37 | # :ccache_enabled => true 38 | ) 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /example/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: "react-native", 3 | }; 4 | -------------------------------------------------------------------------------- /example/metro.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | 3 | const { getDefaultConfig } = require("@react-native/metro-config"); 4 | const { getConfig } = require("react-native-builder-bob/metro-config"); 5 | 6 | const pkg = require("../package.json"); 7 | 8 | const root = path.resolve(__dirname, ".."); 9 | 10 | /** 11 | * Metro configuration 12 | * https://facebook.github.io/metro/docs/configuration 13 | * 14 | * @type {import('metro-config').MetroConfig} 15 | */ 16 | module.exports = getConfig(getDefaultConfig(__dirname), { 17 | root, 18 | pkg, 19 | project: __dirname, 20 | }); 21 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-fast-secure-storage-example", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "android": "react-native run-android", 7 | "ios": "react-native run-ios", 8 | "start": "react-native start", 9 | "build:android": "react-native build-android --extra-params \"--no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a\"", 10 | "build:ios": "react-native build-ios --scheme FastSecureStorageExample --mode Debug --extra-params \"-sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO\"" 11 | }, 12 | "dependencies": { 13 | "react": "18.3.1", 14 | "react-native": "0.76.5" 15 | }, 16 | "devDependencies": { 17 | "@babel/core": "^7.25.2", 18 | "@babel/preset-env": "^7.25.3", 19 | "@babel/runtime": "^7.25.0", 20 | "@react-native-community/cli": "15.0.1", 21 | "@react-native-community/cli-platform-android": "15.0.1", 22 | "@react-native-community/cli-platform-ios": "15.0.1", 23 | "@react-native/babel-preset": "0.76.5", 24 | "@react-native/eslint-config": "0.76.5", 25 | "@react-native/metro-config": "0.76.5", 26 | "@react-native/typescript-config": "0.76.5", 27 | "react-native-builder-bob": "^0.29.1" 28 | }, 29 | "engines": { 30 | "node": ">=18" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /example/react-native.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | 3 | const pkg = require("../package.json"); 4 | 5 | module.exports = { 6 | project: { 7 | ios: { 8 | automaticPodsInstallation: true, 9 | }, 10 | }, 11 | dependencies: { 12 | [pkg.name]: { 13 | root: path.join(__dirname, ".."), 14 | }, 15 | }, 16 | }; 17 | -------------------------------------------------------------------------------- /example/src/App.tsx: -------------------------------------------------------------------------------- 1 | import { useCallback, useEffect, useState } from "react"; 2 | import { Button, ScrollView, StyleSheet, Text, TextInput } from "react-native"; 3 | import SecureStorage, { ACCESSIBLE } from "react-native-fast-secure-storage"; 4 | 5 | import { Rectangle } from "./Reactangle"; 6 | 7 | const testItems = new Array(100).fill(0).map((_, index) => { 8 | return { 9 | key: `key_${index}`, 10 | value: `test_key_${index}`, 11 | accessibleValue: ACCESSIBLE.WHEN_UNLOCKED, 12 | }; 13 | }); 14 | 15 | export default function App() { 16 | const [result, setResult] = useState(); 17 | const [hasItem, setHasItem] = useState(false); 18 | const [text, setText] = useState(""); 19 | 20 | const getTestValue = useCallback(async () => { 21 | const startTime = new Date().getTime(); 22 | 23 | try { 24 | const value = await SecureStorage.getItem("test"); 25 | 26 | console.log(value); 27 | 28 | setResult(value); 29 | } catch (error) { 30 | if (error instanceof Error) { 31 | setResult(error.message); 32 | } 33 | } 34 | console.log("Time taken:", new Date().getTime() - startTime); 35 | }, []); 36 | 37 | const setTestValue = useCallback(async () => { 38 | const startTime = new Date().getTime(); 39 | 40 | await SecureStorage.setItem("test", "test value"); 41 | console.log("Time taken:", new Date().getTime() - startTime); 42 | const value = await SecureStorage.getItem("test"); 43 | 44 | setResult(value); 45 | }, []); 46 | 47 | const setMultipleItems = useCallback(async () => { 48 | const startTime = new Date().getTime(); 49 | 50 | await SecureStorage.setItems(testItems); 51 | console.log("Time taken:", new Date().getTime() - startTime); 52 | }, []); 53 | 54 | const getAllKeys = useCallback(async () => { 55 | console.log(await SecureStorage.getAllKeys()); 56 | }, []); 57 | 58 | const getAllItems = useCallback(async () => { 59 | console.log(await SecureStorage.getAllItems()); 60 | }, []); 61 | 62 | const deleteValue = useCallback(async () => { 63 | await SecureStorage.removeItem("test"); 64 | getTestValue(); 65 | }, [getTestValue]); 66 | 67 | const checkHasItem = useCallback(async () => { 68 | setHasItem(await SecureStorage.hasItem("test")); 69 | }, []); 70 | 71 | const setItemSync = useCallback(() => { 72 | SecureStorage.setItemSync("test", "test value"); 73 | getTestValue(); 74 | }, [getTestValue]); 75 | 76 | const removeItemSync = useCallback(() => { 77 | SecureStorage.removeItemSync("test"); 78 | getTestValue(); 79 | }, [getTestValue]); 80 | 81 | const getItemSync = useCallback(() => { 82 | const value = SecureStorage.getItemSync("test"); 83 | 84 | setResult(value as string); 85 | }, []); 86 | 87 | useEffect(() => { 88 | getTestValue(); 89 | }, [getTestValue]); 90 | 91 | return ( 92 | 93 | 94 | {result} 95 | {hasItem ? "Item exists" : "Item does not exist"} 96 | 101 |