@dynamic-labs/legacy-react-native-extension 5.4.0 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -11,10 +11,10 @@ import { requireOptionalNativeModule, requireNativeModule } from 'expo-modules-c
11
11
  import { Passkey } from 'react-native-passkey';
12
12
  import { createURL, getInitialURL, addEventListener, openURL } from 'expo-linking';
13
13
  import { openAuthSessionAsync } from 'expo-web-browser';
14
- import { getGenericPassword, resetGenericPassword, setGenericPassword } from 'react-native-keychain';
14
+ import { resetGenericPassword, getGenericPassword, setGenericPassword } from 'react-native-keychain';
15
15
  import { createPasskey, PasskeyStamper } from '@turnkey/react-native-passkey-stamper';
16
16
 
17
- var version = "5.4.0";
17
+ var version = "5.5.0";
18
18
 
19
19
  function _extends() {
20
20
  return _extends = Object.assign ? Object.assign.bind() : function (n) {
@@ -539,6 +539,7 @@ const getKeychain = () => {
539
539
  getPublicKey: () => Promise.reject(keychainUnavailableError),
540
540
  hasKey: () => Promise.reject(keychainUnavailableError),
541
541
  isAvailable: () => Promise.resolve(false),
542
+ pruneToPublicKey: () => Promise.reject(keychainUnavailableError),
542
543
  sign: () => Promise.reject(keychainUnavailableError)
543
544
  };
544
545
  return unavailableKeychain;
@@ -774,6 +775,184 @@ const setupPlatformHandler = core => {
774
775
  });
775
776
  };
776
777
 
778
+ /**
779
+ * expo-secure-store is an OPTIONAL peer dependency (see package.json) —
780
+ * most apps never had it and shouldn't have to install it. `require`
781
+ * inside a `try`/`catch` — not a static `import` — is Metro's own
782
+ * documented mechanism for this: `collectDependencies.js`'s
783
+ * `isOptionalDependency` recognizes a `require()` call sitting directly in
784
+ * a try block and marks that dependency `optional`, so an unresolvable
785
+ * module there does not fail the bundle — it only throws (here, caught) if
786
+ * actually reached at runtime. This needs `allowOptionalDependencies`
787
+ * enabled in the consumer's Metro transformer config; `@expo/metro-config`
788
+ * (what every consumer of this package uses, since expo-linking/
789
+ * expo-web-browser/expo-modules-core are already required peers) turns it
790
+ * on by default. Cached after the first call: a host app either has it
791
+ * installed or it doesn't, for the lifetime of the process.
792
+ */
793
+ let cachedLegacyStore;
794
+ const getLegacyExpoSecureStore = () => {
795
+ if (cachedLegacyStore === undefined) {
796
+ try {
797
+ // Deliberately not installed anywhere in this workspace, even for
798
+ // lint (see doc comment above): a root-only install still hoists into
799
+ // every app's node_modules, and expo-modules-autolinking picks it up
800
+ // from there regardless of whether that app declares it — forcing an
801
+ // unwanted native rebuild on every consumer.
802
+ // eslint-disable-next-line @typescript-eslint/no-var-requires, global-require, import/no-extraneous-dependencies
803
+ cachedLegacyStore = require('expo-secure-store');
804
+ } catch (_a) {
805
+ cachedLegacyStore = null;
806
+ }
807
+ }
808
+ return cachedLegacyStore;
809
+ };
810
+ /**
811
+ * Reads a value written by a previous SDK version into the legacy
812
+ * expo-secure-store backend. Both a missing module and a read failure
813
+ * (e.g. Android Keystore decryption error after a backup restore) are
814
+ * treated as "no legacy value" — the entry is unrecoverable either way, so
815
+ * the caller falls through to a clean miss instead of failing the whole
816
+ * request.
817
+ */
818
+ const readLegacyItem = key => __awaiter(void 0, void 0, void 0, function* () {
819
+ const legacyStore = getLegacyExpoSecureStore();
820
+ if (!legacyStore) return null;
821
+ try {
822
+ return yield legacyStore.getItemAsync(key);
823
+ } catch (_a) {
824
+ return null;
825
+ }
826
+ });
827
+ /**
828
+ * Best-effort delete of a legacy expo-secure-store entry. Logged, not
829
+ * thrown: the legacy backend is optional, so its absence or failure must
830
+ * not fail an otherwise-successful keychain operation. The tradeoff is
831
+ * that a persistently-failing legacy delete can leave a stale entry that
832
+ * resurrects through `getItem`'s migration path on a later boot — accepted
833
+ * because this only affects the narrow population still holding data from
834
+ * before the keychain switch.
835
+ */
836
+ const deleteLegacyItem = key => __awaiter(void 0, void 0, void 0, function* () {
837
+ const legacyStore = getLegacyExpoSecureStore();
838
+ if (!legacyStore) return;
839
+ try {
840
+ yield legacyStore.deleteItemAsync(key);
841
+ } catch (error) {
842
+ logger.warn('[legacy-expo-secure-store-recovery] failed to delete legacy entry', {
843
+ error,
844
+ key
845
+ });
846
+ }
847
+ });
848
+ /**
849
+ * Serializes storage operations per key so a lazy migration write-back
850
+ * (triggered by a read) can never interleave with a concurrent write or
851
+ * delete for the same key — e.g. a read that promotes a stale legacy value
852
+ * must not clobber a write that lands in between the read's keychain check
853
+ * and its migration write. Operations on different keys still run fully
854
+ * concurrently.
855
+ */
856
+ const createKeyedOperationQueue = () => {
857
+ const tailByKey = new Map();
858
+ const queueOperationForKey = (key, operation) => {
859
+ var _a;
860
+ const tail = (_a = tailByKey.get(key)) !== null && _a !== void 0 ? _a : Promise.resolve();
861
+ const result = tail.then(operation);
862
+ // Chain the next operation after this one, swallowing the outcome so
863
+ // a rejection doesn't break the chain for subsequent operations.
864
+ const settled = result.then(() => undefined, () => undefined);
865
+ tailByKey.set(key, settled);
866
+ // Drop the tail entry once it settles if no newer operation replaced
867
+ // it, so the map doesn't retain an entry per key forever.
868
+ settled.then(() => {
869
+ if (tailByKey.get(key) === settled) {
870
+ tailByKey.delete(key);
871
+ }
872
+ });
873
+ return result;
874
+ };
875
+ return {
876
+ queueOperationForKey
877
+ };
878
+ };
879
+ /**
880
+ * Decorates the react-native-keychain-backed storage bridge with recovery
881
+ * of sessions persisted by SDK versions that stored secure values in
882
+ * expo-secure-store, before the bridge switched to react-native-keychain.
883
+ *
884
+ * expo-secure-store and react-native-keychain are two separate,
885
+ * mutually-unreadable storage backends: even though both ultimately sit on
886
+ * top of the platform Keychain/Keystore, each library manages its own
887
+ * service/account naming (iOS) and its own encryption key (Android). An
888
+ * app that upgrades straight from an old SDK version has its session
889
+ * stranded in expo-secure-store, invisible to react-native-keychain,
890
+ * unless something explicitly reads the old backend's own API.
891
+ *
892
+ * expo-secure-store stays an OPTIONAL peer dependency — see
893
+ * `getLegacyExpoSecureStore`'s doc comment for how the lazy require stays
894
+ * Metro-bundle-safe without it. Recovery itself never rejects and never
895
+ * blocks: a missing/failed legacy read or delete is treated as a clean
896
+ * miss (see `readLegacyItem` and `deleteLegacyItem`).
897
+ *
898
+ * Every piece of state and behavior this migration needs is self-contained
899
+ * in this one factory: delete this file (and the rest of
900
+ * `legacyExpoSecureStoreRecovery/`), drop the `expo-secure-store` optional
901
+ * peer dependency from package.json, and replace the call to
902
+ * `withLegacyExpoSecureStoreRecovery` in `setupStorageHandler` with
903
+ * `{ getItem: getKeychainItem, setItem: setKeychainItem, deleteItem: deleteKeychainItem }`
904
+ * once this migration window has closed.
905
+ */
906
+ const withLegacyExpoSecureStoreRecovery = ({
907
+ deleteKeychainItem,
908
+ getKeychainItem,
909
+ setKeychainItem
910
+ }) => {
911
+ const {
912
+ queueOperationForKey
913
+ } = createKeyedOperationQueue();
914
+ return {
915
+ deleteItem: key => queueOperationForKey(key, () => __awaiter(void 0, void 0, void 0, function* () {
916
+ // Both backends must be attempted even if one fails, or a
917
+ // surviving copy would resurrect a value the SDK believes is gone
918
+ // (e.g. a stale session after logout) — either straight from the
919
+ // keychain, or via getItem's legacy-migration fallback. Only the
920
+ // keychain outcome is surfaced: deleteLegacyItem already logs its
921
+ // own failures instead of rejecting (see its doc comment).
922
+ const [keychainResult] = yield Promise.allSettled([deleteKeychainItem(key), deleteLegacyItem(key)]);
923
+ if (keychainResult.status === 'rejected') {
924
+ throw keychainResult.reason;
925
+ }
926
+ })),
927
+ getItem: key => queueOperationForKey(key, () => __awaiter(void 0, void 0, void 0, function* () {
928
+ const stored = yield getKeychainItem(key);
929
+ if (stored !== null) return stored;
930
+ const legacyValue = yield readLegacyItem(key);
931
+ if (legacyValue === null) return null;
932
+ // Lazy migration is best-effort: promote the legacy value into the
933
+ // keychain so the next read is a direct hit, then drop the legacy
934
+ // copy. A keychain write failure must not fail this read when a
935
+ // valid legacy value is already in hand — the next miss simply
936
+ // re-attempts the migration.
937
+ try {
938
+ yield setKeychainItem(key, legacyValue);
939
+ yield deleteLegacyItem(key);
940
+ } catch (_a) {
941
+ // ignore migration failures and still return the legacy value
942
+ }
943
+ return legacyValue;
944
+ })),
945
+ setItem: (key, data) => queueOperationForKey(key, () => __awaiter(void 0, void 0, void 0, function* () {
946
+ yield setKeychainItem(key, data);
947
+ // Drop any pre-migration legacy copy left over from a previous SDK
948
+ // version — best-effort, so a delete hiccup doesn't fail the
949
+ // write. Otherwise, if the fresh keychain entry were ever lost, a
950
+ // stale legacy value could resurrect through getItem's fallback.
951
+ yield deleteLegacyItem(key);
952
+ }))
953
+ };
954
+ };
955
+
777
956
  const REACT_NATIVE_KEYCHAIN_NOT_AVAILABLE_DOCS_URL = 'https://docs.dynamic.xyz/overview/migrations/react-native-expo-secure-store-to-keychain';
778
957
  const REACT_NATIVE_KEYCHAIN_NOT_AVAILABLE_MESSAGE = 'react-native-keychain native module is not available. ' + 'Install and link the peer dependency, then rebuild the native app. ' + `See ${REACT_NATIVE_KEYCHAIN_NOT_AVAILABLE_DOCS_URL}`;
779
958
  const assertValidSource = source => {
@@ -786,27 +965,51 @@ const assertReactNativeKeychainAvailable = () => {
786
965
  throw new Error(REACT_NATIVE_KEYCHAIN_NOT_AVAILABLE_MESSAGE);
787
966
  }
788
967
  };
968
+ /**
969
+ * Answers the webview-controller's secure-storage bridge requests with
970
+ * react-native-keychain (iOS Keychain / Android Keystore-backed storage),
971
+ * which has no practical value-size limit — values of any size are stored
972
+ * as one direct entry.
973
+ *
974
+ * A session persisted by an SDK version predating the keychain switch is
975
+ * recovered on a keychain miss via `withLegacyExpoSecureStoreRecovery`
976
+ * instead of signing the app out on upgrade. See that module's doc comment
977
+ * for how to retire the migration once it's no longer needed.
978
+ */
789
979
  const setupStorageHandler = core => {
790
980
  assertReactNativeKeychainAvailable();
791
981
  const storageRequestChannel = createRequestChannel(core.messageTransport);
982
+ const recoverable = withLegacyExpoSecureStoreRecovery({
983
+ deleteKeychainItem: key => __awaiter(void 0, void 0, void 0, function* () {
984
+ yield resetGenericPassword({
985
+ service: key
986
+ });
987
+ }),
988
+ getKeychainItem: key => __awaiter(void 0, void 0, void 0, function* () {
989
+ const stored = yield getGenericPassword({
990
+ service: key
991
+ });
992
+ return stored ? stored.password : null;
993
+ }),
994
+ setKeychainItem: (key, data) => __awaiter(void 0, void 0, void 0, function* () {
995
+ yield setGenericPassword(key, data, {
996
+ service: key
997
+ });
998
+ })
999
+ });
792
1000
  storageRequestChannel.handle('getItem', _a => __awaiter(void 0, [_a], void 0, function* ({
793
1001
  key,
794
1002
  source
795
1003
  }) {
796
1004
  assertValidSource(source);
797
- const stored = yield getGenericPassword({
798
- service: key
799
- });
800
- return stored ? stored.password : null;
1005
+ return recoverable.getItem(key);
801
1006
  }));
802
1007
  storageRequestChannel.handle('deleteItem', _b => __awaiter(void 0, [_b], void 0, function* ({
803
1008
  key,
804
1009
  source
805
1010
  }) {
806
1011
  assertValidSource(source);
807
- yield resetGenericPassword({
808
- service: key
809
- });
1012
+ yield recoverable.deleteItem(key);
810
1013
  }));
811
1014
  storageRequestChannel.handle('setItem', _c => __awaiter(void 0, [_c], void 0, function* ({
812
1015
  key,
@@ -814,9 +1017,7 @@ const setupStorageHandler = core => {
814
1017
  source
815
1018
  }) {
816
1019
  assertValidSource(source);
817
- yield setGenericPassword(key, data, {
818
- service: key
819
- });
1020
+ yield recoverable.setItem(key, data);
820
1021
  }));
821
1022
  };
822
1023
 
@@ -883,6 +1084,19 @@ const setupKeychainHandler = core => {
883
1084
  }) {
884
1085
  return keychain.deleteKey(key);
885
1086
  }));
1087
+ keychainRequestChannel.handle('keychain_pruneToPublicKey', _f => __awaiter(void 0, [_f], void 0, function* ({
1088
+ key,
1089
+ publicKey
1090
+ }) {
1091
+ // Absent on a native binary that predates the operation (an OTA JS
1092
+ // update can run on one). Rejecting is the same answer the webview
1093
+ // already handles for any host without it: the session is served
1094
+ // unchanged, only the ambiguity is left unresolved.
1095
+ if (!keychain.pruneToPublicKey) {
1096
+ throw new Error('keychain_pruneToPublicKey is not available in this native build');
1097
+ }
1098
+ return keychain.pruneToPublicKey(key, publicKey);
1099
+ }));
886
1100
  };
887
1101
 
888
1102
  const defaultWebviewUrl = `https://webview.dynamicauth.com/${version}`;
@@ -35,5 +35,9 @@ public class KeychainModule: Module {
35
35
  AsyncFunction("deleteKey") { (key: String) in
36
36
  self.keyManager.deleteKey(tag: key)
37
37
  }
38
+
39
+ AsyncFunction("pruneToPublicKey") { (key: String, publicKey: String) -> Bool in
40
+ self.keyManager.pruneToPublicKey(tag: key, expectedPublicKey: publicKey)
41
+ }
38
42
  }
39
43
  }
@@ -51,6 +51,17 @@ public class SecureEnclaveKeyManager {
51
51
  public func generateKeyPair(tag: String) throws -> String {
52
52
  let tagData = tag.data(using: .utf8)!
53
53
 
54
+ // The keychain's uniqueness constraint for `kSecClassKey` includes
55
+ // `kSecAttrApplicationLabel` (the public key hash), so an application tag
56
+ // does NOT identify a single item: generating without deleting first
57
+ // leaves several Secure Enclave keys under the same tag. They then
58
+ // accumulate on every regeneration, and `SecItemCopyMatching` resolves
59
+ // `hasKey`/`getPublicKey`/`sign` to an arbitrary one of them — which
60
+ // silently signs with a key the server does not know. Replace instead,
61
+ // matching `KeyStoreKeyManager.generateKeyPair` on Android (where an
62
+ // alias is unique by definition).
63
+ deleteKey(tag: tag)
64
+
54
65
  let access = SecAccessControlCreateWithFlags(
55
66
  kCFAllocatorDefault,
56
67
  kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly,
@@ -139,6 +150,70 @@ public class SecureEnclaveKeyManager {
139
150
  SecItemDelete(query as CFDictionary)
140
151
  }
141
152
 
153
+ /// Keeps only the key under `tag` whose public key equals
154
+ /// `expectedPublicKey`, deleting every other key stored under the same tag.
155
+ /// Returns true when a matching key remains.
156
+ ///
157
+ /// An application tag identifies a SET of keys (see `generateKeyPair`), and a
158
+ /// lookup resolves to an unspecified member of that set, so a device that
159
+ /// accumulated keys can sign with one the server does not know. When the
160
+ /// caller knows which public key the session was issued for, this removes
161
+ /// the ambiguity instead of leaving it to chance.
162
+ ///
163
+ /// `expectedPublicKey` is accepted in any encoding the SDK has historically
164
+ /// produced or persisted: base64url or hex, compressed (33 bytes) or
165
+ /// uncompressed (65 bytes) SEC1. Everything is normalised to compressed form
166
+ /// before comparison, so callers do not have to know which one they hold.
167
+ /// Nothing is deleted when no key matches — a caller passing a stale or
168
+ /// wrongly-encoded key must not be able to wipe a usable key.
169
+ public func pruneToPublicKey(tag: String, expectedPublicKey: String) -> Bool {
170
+ guard let expected = Self.normalizedCompressedPublicKey(expectedPublicKey)
171
+ else {
172
+ return false
173
+ }
174
+
175
+ var query = baseQuery(for: tag, returning: true)
176
+ query[kSecMatchLimit as String] = kSecMatchLimitAll
177
+
178
+ var items: CFTypeRef?
179
+ guard SecItemCopyMatching(query as CFDictionary, &items) == errSecSuccess,
180
+ let keys = items as? [SecKey]
181
+ else {
182
+ return false
183
+ }
184
+
185
+ var matching: [SecKey] = []
186
+ var others: [SecKey] = []
187
+
188
+ for privateKey in keys {
189
+ guard let publicKey = SecKeyCopyPublicKey(privateKey),
190
+ let data = try? exportPublicKey(publicKey),
191
+ let compressed = Self.compressSec1PublicKey(data)
192
+ else {
193
+ // Unreadable keys are left alone: they cannot be confirmed as the
194
+ // wrong key either.
195
+ continue
196
+ }
197
+
198
+ if compressed == expected {
199
+ matching.append(privateKey)
200
+ } else {
201
+ others.append(privateKey)
202
+ }
203
+ }
204
+
205
+ guard !matching.isEmpty else { return false }
206
+
207
+ for privateKey in others {
208
+ SecItemDelete([
209
+ kSecClass as String: kSecClassKey,
210
+ kSecValueRef as String: privateKey,
211
+ ] as CFDictionary)
212
+ }
213
+
214
+ return true
215
+ }
216
+
142
217
  // MARK: - Private helpers
143
218
 
144
219
  private func baseQuery(for tag: String, returning returnRef: Bool) -> [String: Any] {
@@ -164,6 +239,52 @@ public class SecureEnclaveKeyManager {
164
239
  return data as Data
165
240
  }
166
241
 
242
+ /// Decodes a public key given in base64url or hex and returns it in
243
+ /// compressed SEC1 form (33 bytes: 02/03 || x), the only representation in
244
+ /// which two encodings of the same key are guaranteed to be byte-equal.
245
+ static func normalizedCompressedPublicKey(_ encoded: String) -> Data? {
246
+ let candidates = [try? base64urlDecode(encoded), hexDecode(encoded)]
247
+
248
+ for case let data? in candidates {
249
+ if let compressed = compressSec1PublicKey(data) {
250
+ return compressed
251
+ }
252
+ }
253
+ return nil
254
+ }
255
+
256
+ /// Compresses an uncompressed SEC1 point (04 || x || y) to 02/03 || x, where
257
+ /// the prefix encodes the parity of y. Already-compressed input is returned
258
+ /// unchanged.
259
+ static func compressSec1PublicKey(_ data: Data) -> Data? {
260
+ if data.count == 33, data[data.startIndex] == 0x02 || data[data.startIndex] == 0x03 {
261
+ return data
262
+ }
263
+
264
+ guard data.count == 65, data[data.startIndex] == 0x04 else { return nil }
265
+
266
+ let x = data[(data.startIndex + 1)..<(data.startIndex + 33)]
267
+ let yLastByte = data[data.startIndex + 64]
268
+ let prefix: UInt8 = (yLastByte % 2 == 0) ? 0x02 : 0x03
269
+
270
+ return Data([prefix]) + x
271
+ }
272
+
273
+ private static func hexDecode(_ string: String) -> Data? {
274
+ let characters = Array(string)
275
+ guard characters.count % 2 == 0, !characters.isEmpty else { return nil }
276
+
277
+ var data = Data(capacity: characters.count / 2)
278
+ for index in stride(from: 0, to: characters.count, by: 2) {
279
+ guard let byte = UInt8(String(characters[index...(index + 1)]), radix: 16)
280
+ else {
281
+ return nil
282
+ }
283
+ data.append(byte)
284
+ }
285
+ return data
286
+ }
287
+
167
288
  private func base64urlEncode(_ data: Data) -> String {
168
289
  data.base64EncodedString()
169
290
  .replacingOccurrences(of: "+", with: "-")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/legacy-react-native-extension",
3
- "version": "5.4.0",
3
+ "version": "5.5.0",
4
4
  "main": "./index.cjs",
5
5
  "module": "./index.js",
6
6
  "types": "./src/index.d.ts",
@@ -18,11 +18,11 @@
18
18
  "@turnkey/react-native-passkey-stamper": "1.2.7",
19
19
  "@react-native-documents/picker": "^11.0.0",
20
20
  "react-native-fs": ">=2.20.0",
21
- "@dynamic-labs/assert-package-version": "5.4.0",
22
- "@dynamic-labs/legacy-client": "5.4.0",
23
- "@dynamic-labs/logger": "5.4.0",
24
- "@dynamic-labs/message-transport": "5.4.0",
25
- "@dynamic-labs/webview-messages": "5.4.0"
21
+ "@dynamic-labs/assert-package-version": "5.5.0",
22
+ "@dynamic-labs/legacy-client": "5.5.0",
23
+ "@dynamic-labs/logger": "5.5.0",
24
+ "@dynamic-labs/message-transport": "5.5.0",
25
+ "@dynamic-labs/webview-messages": "5.5.0"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "react": ">=18.0.0 <20.0.0",
@@ -31,7 +31,13 @@
31
31
  "react-native-webview": "^13.6.4",
32
32
  "expo-linking": ">=6.2.2",
33
33
  "expo-web-browser": ">=12.0.0",
34
- "expo-modules-core": ">=2.0.0"
34
+ "expo-modules-core": ">=2.0.0",
35
+ "expo-secure-store": ">=11.0.0"
36
+ },
37
+ "peerDependenciesMeta": {
38
+ "expo-secure-store": {
39
+ "optional": true
40
+ }
35
41
  },
36
42
  "codegenConfig": {
37
43
  "name": "DynamicClientSpec",
@@ -1,4 +1,15 @@
1
1
  import { Core } from '@dynamic-labs/legacy-client';
2
2
  export declare const REACT_NATIVE_KEYCHAIN_NOT_AVAILABLE_DOCS_URL = "https://docs.dynamic.xyz/overview/migrations/react-native-expo-secure-store-to-keychain";
3
3
  export declare const REACT_NATIVE_KEYCHAIN_NOT_AVAILABLE_MESSAGE: string;
4
+ /**
5
+ * Answers the webview-controller's secure-storage bridge requests with
6
+ * react-native-keychain (iOS Keychain / Android Keystore-backed storage),
7
+ * which has no practical value-size limit — values of any size are stored
8
+ * as one direct entry.
9
+ *
10
+ * A session persisted by an SDK version predating the keychain switch is
11
+ * recovered on a keychain miss via `withLegacyExpoSecureStoreRecovery`
12
+ * instead of signing the app out on upgrade. See that module's doc comment
13
+ * for how to retire the migration once it's no longer needed.
14
+ */
4
15
  export declare const setupStorageHandler: (core: Core) => void;
@@ -0,0 +1,2 @@
1
+ export { withLegacyExpoSecureStoreRecovery } from './withLegacyExpoSecureStoreRecovery';
2
+ export type { KeychainBridge, RecoverableStorageHandler, } from './withLegacyExpoSecureStoreRecovery';
@@ -0,0 +1,38 @@
1
+ export type KeychainBridge = {
2
+ deleteKeychainItem: (key: string) => Promise<void>;
3
+ getKeychainItem: (key: string) => Promise<string | null>;
4
+ setKeychainItem: (key: string, data: string) => Promise<void>;
5
+ };
6
+ export type RecoverableStorageHandler = {
7
+ deleteItem: (key: string) => Promise<void>;
8
+ getItem: (key: string) => Promise<string | null>;
9
+ setItem: (key: string, data: string) => Promise<void>;
10
+ };
11
+ /**
12
+ * Decorates the react-native-keychain-backed storage bridge with recovery
13
+ * of sessions persisted by SDK versions that stored secure values in
14
+ * expo-secure-store, before the bridge switched to react-native-keychain.
15
+ *
16
+ * expo-secure-store and react-native-keychain are two separate,
17
+ * mutually-unreadable storage backends: even though both ultimately sit on
18
+ * top of the platform Keychain/Keystore, each library manages its own
19
+ * service/account naming (iOS) and its own encryption key (Android). An
20
+ * app that upgrades straight from an old SDK version has its session
21
+ * stranded in expo-secure-store, invisible to react-native-keychain,
22
+ * unless something explicitly reads the old backend's own API.
23
+ *
24
+ * expo-secure-store stays an OPTIONAL peer dependency — see
25
+ * `getLegacyExpoSecureStore`'s doc comment for how the lazy require stays
26
+ * Metro-bundle-safe without it. Recovery itself never rejects and never
27
+ * blocks: a missing/failed legacy read or delete is treated as a clean
28
+ * miss (see `readLegacyItem` and `deleteLegacyItem`).
29
+ *
30
+ * Every piece of state and behavior this migration needs is self-contained
31
+ * in this one factory: delete this file (and the rest of
32
+ * `legacyExpoSecureStoreRecovery/`), drop the `expo-secure-store` optional
33
+ * peer dependency from package.json, and replace the call to
34
+ * `withLegacyExpoSecureStoreRecovery` in `setupStorageHandler` with
35
+ * `{ getItem: getKeychainItem, setItem: setKeychainItem, deleteItem: deleteKeychainItem }`
36
+ * once this migration window has closed.
37
+ */
38
+ export declare const withLegacyExpoSecureStoreRecovery: ({ deleteKeychainItem, getKeychainItem, setKeychainItem, }: KeychainBridge) => RecoverableStorageHandler;
@@ -11,6 +11,12 @@ type KeychainNativeModule = {
11
11
  signature: string;
12
12
  }>;
13
13
  deleteKey: (key: string) => Promise<void>;
14
+ /**
15
+ * Optional: an over-the-air JS update can run on a native binary that
16
+ * predates this operation, so callers must tolerate it being missing —
17
+ * the webview treats a rejection as "the host did not prune" and carries on.
18
+ */
19
+ pruneToPublicKey?: (key: string, publicKey: string) => Promise<boolean>;
14
20
  };
15
21
  /**
16
22
  * Reports whether the Keychain native module is linked into the currently