@dynamic-labs-sdk/client 1.6.0 → 1.8.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.
Files changed (135) hide show
  1. package/android/build.gradle +231 -0
  2. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  3. package/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  4. package/android/gradle.properties +8 -0
  5. package/android/gradlew +251 -0
  6. package/android/gradlew.bat +94 -0
  7. package/android/settings.gradle +30 -0
  8. package/android/src/main/java/xyz/dynamic/client/DynamicClientPackage.kt +52 -0
  9. package/android/src/main/java/xyz/dynamic/client/keychain/KeyStoreKeyManager.kt +147 -0
  10. package/android/src/main/java/xyz/dynamic/client/keychain/KeychainModule.kt +85 -0
  11. package/android/src/main/java/xyz/dynamic/client/manifest/ReactNativeManifestModule.kt +25 -0
  12. package/android/src/main/java/xyz/dynamic/client/webview/DynamicWebViewClient.kt +83 -0
  13. package/android/src/main/java/xyz/dynamic/client/webview/DynamicWebViewHost.kt +518 -0
  14. package/android/src/main/java/xyz/dynamic/client/webview/DynamicWebViewModule.kt +147 -0
  15. package/android/src/test/java/xyz/dynamic/client/keychain/KeyStoreKeyManagerTest.kt +288 -0
  16. package/android/src/test/java/xyz/dynamic/client/webview/DynamicWebViewClientTest.kt +196 -0
  17. package/android/src/test/java/xyz/dynamic/client/webview/DynamicWebViewHostOpenTest.kt +347 -0
  18. package/android/src/test/java/xyz/dynamic/client/webview/DynamicWebViewHostTest.kt +171 -0
  19. package/android/src/test/java/xyz/dynamic/client/webview/DynamicWebViewModuleTest.kt +191 -0
  20. package/dist/{InvalidParamError-BIptAjbC.native.esm.js → InvalidParamError-Bc6OZBog.native.esm.js} +91 -829
  21. package/dist/InvalidParamError-Bc6OZBog.native.esm.js.map +1 -0
  22. package/dist/{InvalidParamError-BZ0LHaml.esm.js → InvalidParamError-IHYLdzFd.esm.js} +108 -381
  23. package/dist/InvalidParamError-IHYLdzFd.esm.js.map +1 -0
  24. package/dist/{InvalidParamError-DyXEKMWn.cjs → InvalidParamError-S56rFFDP.cjs} +108 -450
  25. package/dist/InvalidParamError-S56rFFDP.cjs.map +1 -0
  26. package/dist/{NotWaasWalletAccountError-nT4jrLbp.esm.js → NotWaasWalletAccountError-BP-bODbJ.native.esm.js} +4 -4
  27. package/dist/NotWaasWalletAccountError-BP-bODbJ.native.esm.js.map +1 -0
  28. package/dist/{NotWaasWalletAccountError-BbOA5rPd.native.esm.js → NotWaasWalletAccountError-BYEL2l-W.esm.js} +4 -4
  29. package/dist/NotWaasWalletAccountError-BYEL2l-W.esm.js.map +1 -0
  30. package/dist/{NotWaasWalletAccountError-CElqwdQO.cjs → NotWaasWalletAccountError-CbhIKUDM.cjs} +4 -4
  31. package/dist/NotWaasWalletAccountError-CbhIKUDM.cjs.map +1 -0
  32. package/dist/core.cjs +11 -11
  33. package/dist/core.cjs.map +1 -1
  34. package/dist/core.esm.js +5 -5
  35. package/dist/core.native.esm.js +7 -7
  36. package/dist/core.native.esm.js.map +1 -1
  37. package/dist/errors/WebViewLoadFailedError.d.ts +1 -1
  38. package/dist/errors/WebViewLoadFailedError.d.ts.map +1 -1
  39. package/dist/exports/index.d.ts +2 -0
  40. package/dist/exports/index.d.ts.map +1 -1
  41. package/dist/{getNetworkProviderFromNetworkId-DbI5MZhq.cjs → getNetworkProviderFromNetworkId-BDdcpGHH.cjs} +56 -55
  42. package/dist/{getNetworkProviderFromNetworkId-DbI5MZhq.cjs.map → getNetworkProviderFromNetworkId-BDdcpGHH.cjs.map} +1 -1
  43. package/dist/{getNetworkProviderFromNetworkId-BkAPIdRC.esm.js → getNetworkProviderFromNetworkId-D8rWYXlT.esm.js} +54 -54
  44. package/dist/{getNetworkProviderFromNetworkId-BkAPIdRC.esm.js.map → getNetworkProviderFromNetworkId-D8rWYXlT.esm.js.map} +1 -1
  45. package/dist/{getNetworkProviderFromNetworkId-B7DIqT2T.native.esm.js → getNetworkProviderFromNetworkId-DVmF7pH2.native.esm.js} +312 -41
  46. package/dist/getNetworkProviderFromNetworkId-DVmF7pH2.native.esm.js.map +1 -0
  47. package/dist/{getSignedSessionId-BF6n8gve.cjs → getSignedSessionId-BBaBCi9S.cjs} +3 -3
  48. package/dist/{getSignedSessionId-BF6n8gve.cjs.map → getSignedSessionId-BBaBCi9S.cjs.map} +1 -1
  49. package/dist/{getSignedSessionId-y3YtxFHZ.esm.js → getSignedSessionId-CND07Eca.esm.js} +3 -3
  50. package/dist/{getSignedSessionId-y3YtxFHZ.esm.js.map → getSignedSessionId-CND07Eca.esm.js.map} +1 -1
  51. package/dist/{getSignedSessionId-1TV-x__C.native.esm.js → getSignedSessionId-RwV7JPn8.native.esm.js} +3 -3
  52. package/dist/{getSignedSessionId-1TV-x__C.native.esm.js.map → getSignedSessionId-RwV7JPn8.native.esm.js.map} +1 -1
  53. package/dist/getVerifiedCredentialForWalletAccount-BVrGV8qf.native.esm.js +701 -0
  54. package/dist/getVerifiedCredentialForWalletAccount-BVrGV8qf.native.esm.js.map +1 -0
  55. package/dist/{getVerifiedCredentialForWalletAccount-etV50QRH.esm.js → getVerifiedCredentialForWalletAccount-BiOS65Tk.esm.js} +2 -2
  56. package/dist/{getVerifiedCredentialForWalletAccount-etV50QRH.esm.js.map → getVerifiedCredentialForWalletAccount-BiOS65Tk.esm.js.map} +1 -1
  57. package/dist/{getVerifiedCredentialForWalletAccount-BfJ29erz.cjs → getVerifiedCredentialForWalletAccount-FrxYWSuD.cjs} +3 -2
  58. package/dist/{getVerifiedCredentialForWalletAccount-BfJ29erz.cjs.map → getVerifiedCredentialForWalletAccount-FrxYWSuD.cjs.map} +1 -1
  59. package/dist/index.cjs +35 -35
  60. package/dist/index.cjs.map +1 -1
  61. package/dist/index.esm.js +14 -14
  62. package/dist/index.esm.js.map +1 -1
  63. package/dist/index.native.esm.js +14 -14
  64. package/dist/index.native.esm.js.map +1 -1
  65. package/dist/isMfaRequiredForAction-BPL_dgIM.esm.js +318 -0
  66. package/dist/isMfaRequiredForAction-BPL_dgIM.esm.js.map +1 -0
  67. package/dist/isMfaRequiredForAction-BolTrtCO.cjs +405 -0
  68. package/dist/isMfaRequiredForAction-BolTrtCO.cjs.map +1 -0
  69. package/dist/{isMfaRequiredForAction-B2vKX31S.native.esm.js → isMfaRequiredForAction-DQDoPsi6.native.esm.js} +2 -2
  70. package/dist/{isMfaRequiredForAction-B2vKX31S.native.esm.js.map → isMfaRequiredForAction-DQDoPsi6.native.esm.js.map} +1 -1
  71. package/dist/modules/apiClient/apiClient.types.d.ts +0 -12
  72. package/dist/modules/apiClient/apiClient.types.d.ts.map +1 -1
  73. package/dist/modules/apiClient/createApiClient.d.ts.map +1 -1
  74. package/dist/modules/auth/logoutReason.d.ts +1 -1
  75. package/dist/modules/auth/logoutReason.d.ts.map +1 -1
  76. package/dist/modules/auth/logoutWithReason/logoutWithReason.d.ts.map +1 -1
  77. package/dist/modules/deviceRegistration/getRegisteredDevices/getRegisteredDevices.d.ts.map +1 -1
  78. package/dist/modules/user/refreshAuth/refreshAuth.d.ts.map +1 -1
  79. package/dist/modules/waas/backupWaasKeySharesToGoogleDrive/backupWaasKeySharesToGoogleDrive.d.ts +12 -1
  80. package/dist/modules/waas/backupWaasKeySharesToGoogleDrive/backupWaasKeySharesToGoogleDrive.d.ts.map +1 -1
  81. package/dist/modules/waas/createWaasClient/createWaasClient.d.ts.map +1 -1
  82. package/dist/modules/waas/createWaasClient/translateNativeOpenError.d.ts.map +1 -1
  83. package/dist/modules/waas/createWaasProvider/createWaasProvider.d.ts.map +1 -1
  84. package/dist/modules/waas/waas.types.d.ts +1 -0
  85. package/dist/modules/waas/waas.types.d.ts.map +1 -1
  86. package/dist/modules/wallets/walletProvider/events/onWalletProviderEvent/onWalletProviderEvent.d.ts +1 -2
  87. package/dist/modules/wallets/walletProvider/events/onWalletProviderEvent/onWalletProviderEvent.d.ts.map +1 -1
  88. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  89. package/dist/waas.cjs +7 -4
  90. package/dist/waas.cjs.map +1 -1
  91. package/dist/waas.esm.js +6 -4
  92. package/dist/waas.esm.js.map +1 -1
  93. package/dist/waas.native.esm.js +6 -4
  94. package/dist/waas.native.esm.js.map +1 -1
  95. package/dist/waasCore.cjs +10 -5
  96. package/dist/waasCore.cjs.map +1 -1
  97. package/dist/waasCore.esm.js +10 -5
  98. package/dist/waasCore.esm.js.map +1 -1
  99. package/dist/waasCore.native.esm.js +10 -8
  100. package/dist/waasCore.native.esm.js.map +1 -1
  101. package/dynamic-labs-sdk-client.podspec +27 -0
  102. package/ios/DynamicClientKeychain.h +4 -0
  103. package/ios/DynamicClientKeychain.mm +101 -0
  104. package/ios/DynamicClientManifest.h +4 -0
  105. package/ios/DynamicClientManifest.mm +45 -0
  106. package/ios/DynamicClientWebView.h +5 -0
  107. package/ios/DynamicClientWebView.mm +143 -0
  108. package/ios/DynamicWebViewImpl.swift +603 -0
  109. package/ios/LiveSecKeyAPI.swift +86 -0
  110. package/ios/ReactNativeManifestImpl.swift +20 -0
  111. package/ios/SecKeyAPI.swift +57 -0
  112. package/ios/SecureEnclaveKeyManager.swift +191 -0
  113. package/package.json +16 -5
  114. package/react-native.config.cjs +14 -0
  115. package/src/turboModules/NativeDynamicWebView.native.spec.ts +61 -0
  116. package/src/turboModules/NativeDynamicWebView.ts +40 -0
  117. package/src/turboModules/NativeKeychain.native.spec.ts +47 -0
  118. package/src/turboModules/NativeKeychain.ts +19 -0
  119. package/src/turboModules/NativeReactNativeManifest.native.spec.ts +55 -0
  120. package/src/turboModules/NativeReactNativeManifest.ts +28 -0
  121. package/dist/InvalidParamError-BIptAjbC.native.esm.js.map +0 -1
  122. package/dist/InvalidParamError-BZ0LHaml.esm.js.map +0 -1
  123. package/dist/InvalidParamError-DyXEKMWn.cjs.map +0 -1
  124. package/dist/NotWaasWalletAccountError-BbOA5rPd.native.esm.js.map +0 -1
  125. package/dist/NotWaasWalletAccountError-CElqwdQO.cjs.map +0 -1
  126. package/dist/NotWaasWalletAccountError-nT4jrLbp.esm.js.map +0 -1
  127. package/dist/getNetworkProviderFromNetworkId-B7DIqT2T.native.esm.js.map +0 -1
  128. package/dist/getVerifiedCredentialForWalletAccount-CLyC2nOl.native.esm.js +0 -269
  129. package/dist/getVerifiedCredentialForWalletAccount-CLyC2nOl.native.esm.js.map +0 -1
  130. package/dist/isMfaRequiredForAction-Dy4-S3mr.esm.js +0 -79
  131. package/dist/isMfaRequiredForAction-Dy4-S3mr.esm.js.map +0 -1
  132. package/dist/isMfaRequiredForAction-K2Jh-3-j.cjs +0 -96
  133. package/dist/isMfaRequiredForAction-K2Jh-3-j.cjs.map +0 -1
  134. package/dist/modules/apiClient/utils/sessionExpiryLogoutMiddleware/createSessionExpiryLogoutMiddleware.d.ts +0 -27
  135. package/dist/modules/apiClient/utils/sessionExpiryLogoutMiddleware/createSessionExpiryLogoutMiddleware.d.ts.map +0 -1
@@ -1,12 +1,154 @@
1
- import { $ as instrumentFunction, D as CHAINS_INFO_MAP, S as getWalletAccounts, T as normalizeWalletNameWithChain, X as assertDefined, c as createApiClient, ct as getDefaultClient, dt as BaseError, f as getWalletProviderFromWalletAccount, ft as getCore, h as createRuntimeServiceAccessKey } from "./InvalidParamError-BIptAjbC.native.esm.js";
2
- import { f as checkAndRaiseWalletAccountsChangedEvent, p as emitWalletAccountsChangedEvent } from "./getVerifiedCredentialForWalletAccount-CLyC2nOl.native.esm.js";
3
- import { i as NativeModuleNotLinkedError } from "./isMfaRequiredForAction-B2vKX31S.native.esm.js";
1
+ import { B as getCore, C as isCookieEnabled, D as instrumentFunction, I as getDefaultClient, N as CLIENT_SDK_NAME, c as CHAINS_INFO_MAP, u as createApiClient, w as assertDefined, z as BaseError } from "./InvalidParamError-Bc6OZBog.native.esm.js";
2
+ import { D as emitEvent, S as normalizeWalletNameWithChain, b as getWalletAccounts, f as checkAndRaiseWalletAccountsChangedEvent, h as getWalletProviderFromWalletAccount, j as setCookie, m as DYNAMIC_AUTH_COOKIE_NAME, p as emitWalletAccountsChangedEvent, v as createRuntimeServiceAccessKey } from "./getVerifiedCredentialForWalletAccount-BVrGV8qf.native.esm.js";
3
+ import { i as NativeModuleNotLinkedError } from "./isMfaRequiredForAction-DQDoPsi6.native.esm.js";
4
4
  import { AuthModeEnum } from "@dynamic-labs/sdk-api-core";
5
5
  import * as z from "zod/mini";
6
+ import AsyncStorage from "@react-native-async-storage/async-storage";
7
+ import { getGenericPassword, resetGenericPassword, setGenericPassword } from "react-native-keychain";
6
8
  import { Buffer as Buffer$1 } from "buffer";
7
9
  import EventEmitter, { EventEmitter as EventEmitter$1 } from "eventemitter3";
8
10
  import { TurboModuleRegistry } from "react-native";
9
11
 
12
+ //#region src/utils/isEqualShallow/isEqualShallow.ts
13
+ /**
14
+ * Shallow compare two objects.
15
+ *
16
+ * Source: https://github.com/pmndrs/zustand/blob/main/src/vanilla/shallow.ts
17
+ * @not-instrumented
18
+ */
19
+ const isEqualShallow = (objA, objB) => {
20
+ if (Object.is(objA, objB)) return true;
21
+ if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) return objA === objB;
22
+ if (objA instanceof Map && objB instanceof Map) {
23
+ if (objA.size !== objB.size) return false;
24
+ for (const [key, value] of objA) if (!Object.is(value, objB.get(key))) return false;
25
+ return true;
26
+ }
27
+ if (objA instanceof Set && objB instanceof Set) {
28
+ if (objA.size !== objB.size) return false;
29
+ for (const value of objA) if (!objB.has(value)) return false;
30
+ return true;
31
+ }
32
+ const keysA = Object.keys(objA);
33
+ if (keysA.length !== Object.keys(objB).length) return false;
34
+ for (const keyA of keysA) if (!Object.prototype.hasOwnProperty.call(objB, keyA) || !Object.is(objA[keyA], objB[keyA])) return false;
35
+ if (objA.constructor !== objB.constructor) return false;
36
+ return true;
37
+ };
38
+
39
+ //#endregion
40
+ //#region src/utils/observable/subscribeWithSelector/subscribeWithSelector.ts
41
+ /**
42
+ * Allows subscribing to a slice of the state.
43
+ * The slice is a computation of the states.
44
+ *
45
+ * The callback will only be called when the slice has changed.
46
+ * Change is determined by shallow comparison.
47
+ *
48
+ * Returns a function to unsubscribe the callback.
49
+ * @not-instrumented
50
+ */
51
+ const subscribeWithSelector = (observable, selector) => (callback) => {
52
+ let lastSlice = selector(observable.get());
53
+ return observable.subscribe((value) => {
54
+ const nextSlice = selector(value);
55
+ if (isEqualShallow(nextSlice, lastSlice)) return;
56
+ lastSlice = nextSlice;
57
+ callback(nextSlice);
58
+ });
59
+ };
60
+
61
+ //#endregion
62
+ //#region src/utils/retryOnFail/InvalidRetryOnFailCallError.ts
63
+ /**
64
+ * This error is thrown when the `retryOnFail` function is called with an invalid
65
+ * number of retries (i.e. less than 0).
66
+ */
67
+ var InvalidRetryOnFailCallError = class extends BaseError {
68
+ constructor(maxRetries) {
69
+ super({
70
+ cause: null,
71
+ code: "invalid_retry_on_fail_call_error",
72
+ docsUrl: null,
73
+ name: "InvalidRetryOnFailCallError",
74
+ shortMessage: `Invalid retries parameter for retryOnFail call: ${maxRetries}`
75
+ });
76
+ }
77
+ };
78
+
79
+ //#endregion
80
+ //#region src/utils/retryOnFail/retryOnFail.ts
81
+ /** @not-instrumented */
82
+ const retryOnFail = async ({ delay = 0, fn, maxRetries }) => {
83
+ for (let retry = 0; retry <= maxRetries; retry++) try {
84
+ return await fn();
85
+ } catch (error) {
86
+ if (retry >= maxRetries) throw error;
87
+ if (delay > 0) await new Promise((resolve) => setTimeout(resolve, delay));
88
+ }
89
+ /**
90
+ * Reaching this point should never happen and this
91
+ * error is thrown to help us debug the issue.
92
+ */
93
+ throw new InvalidRetryOnFailCallError(maxRetries);
94
+ };
95
+
96
+ //#endregion
97
+ //#region src/modules/auth/isSignedIn/isSignedIn.ts
98
+ /**
99
+ * Checks if the user is currently signed in to the Dynamic client.
100
+ *
101
+ * The client is considered to be in a signed in state if a user has
102
+ * authenticated or if the client has at least one wallet connected.
103
+ *
104
+ * @deprecated What counts as "signed in" is your app's business logic, not the
105
+ * SDK's. This helper bakes in one opinion (a user OR any connected wallet),
106
+ * which rarely matches every app and forces a dependency on us for every
107
+ * variation. Compose your own check from the underlying primitives instead —
108
+ * e.g. `Boolean(client.user) || isAnyWalletAccountConnected(client)` — and
109
+ * layer in whatever your app requires (device registration, completed
110
+ * onboarding, satisfied MFA, a required embedded wallet, …). See the
111
+ * "Check if signed in" guide:
112
+ * https://www.dynamic.xyz/docs/javascript/user-session-management
113
+ *
114
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
115
+ * @returns True if the user is signed in, false otherwise.
116
+ * @not-instrumented
117
+ */
118
+ const isSignedIn = (client = getDefaultClient()) => Boolean(client.user || getWalletAccounts(client).length > 0);
119
+
120
+ //#endregion
121
+ //#region src/services/storage/createLocalStorageAdapter/createLocalStorageAdapter.native.ts
122
+ const NAMESPACE = "dynamic";
123
+ const namespaceKey = (key) => `${NAMESPACE}:${key}`;
124
+ /**
125
+ * Creates a localStorage adapter for React Native.
126
+ * Routes operations based on the `storageTier` option:
127
+ * - `'default'`: uses AsyncStorage
128
+ * - `'secure'`: uses react-native-keychain
129
+ * @not-instrumented
130
+ */
131
+ const createLocalStorageAdapter = () => {
132
+ return {
133
+ getItem: async (key, options) => {
134
+ if (options.storageTier === "secure") {
135
+ const result = await getGenericPassword({ service: key });
136
+ if (!result) return null;
137
+ return result.password;
138
+ } else return AsyncStorage.getItem(namespaceKey(key));
139
+ },
140
+ removeItem: async (key, options) => {
141
+ if (options.storageTier === "secure") await resetGenericPassword({ service: key });
142
+ else await AsyncStorage.removeItem(namespaceKey(key));
143
+ },
144
+ setItem: async (key, value, options) => {
145
+ if (options.storageTier === "secure") await setGenericPassword(key, value, { service: key });
146
+ else await AsyncStorage.setItem(namespaceKey(key), value);
147
+ }
148
+ };
149
+ };
150
+
151
+ //#endregion
10
152
  //#region src/errors/InvalidStorageSet.ts
11
153
  var InvalidStorageSet = class extends BaseError {
12
154
  constructor({ key, value }) {
@@ -105,54 +247,183 @@ const createStorage = ({ prefix = "", storageAdapter }) => {
105
247
  };
106
248
 
107
249
  //#endregion
108
- //#region src/utils/isEqualShallow/isEqualShallow.ts
250
+ //#region src/services/storage/createStorageKeySchema/createStorageKeySchema.ts
251
+ /** @not-instrumented */
252
+ const createStorageKeySchema = (params) => {
253
+ return params;
254
+ };
255
+
256
+ //#endregion
257
+ //#region src/modules/projectSettings/fetchProjectSettings/projectSettingsExpirationScheme.ts
109
258
  /**
110
- * Shallow compare two objects.
259
+ * The schema to track the expiration time of the project settings.
260
+ */
261
+ const projectSettingsExpirationStorageKeySchema = createStorageKeySchema({
262
+ key: "projectSettingsExpiration",
263
+ schema: z.number()
264
+ });
265
+
266
+ //#endregion
267
+ //#region src/modules/projectSettings/fetchProjectSettings/fetchProjectSettings.ts
268
+ /**
269
+ * Expiration time of the project settings in milliseconds.
270
+ */
271
+ const PROJECT_SETTINGS_EXPIRATION_TIME = 1e3 * 60 * 5;
272
+ /**
273
+ * Fetches and updates the project settings from the API.
111
274
  *
112
- * Source: https://github.com/pmndrs/zustand/blob/main/src/vanilla/shallow.ts
275
+ * This function retrieves the latest project configuration settings
276
+ * from Dynamic's servers, including authentication options, enabled chains,
277
+ * and security configurations. The settings are cached for performance.
278
+ *
279
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
280
+ * @returns A promise that resolves to the updated project settings.
113
281
  * @not-instrumented
114
282
  */
115
- const isEqualShallow = (objA, objB) => {
116
- if (Object.is(objA, objB)) return true;
117
- if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) return objA === objB;
118
- if (objA instanceof Map && objB instanceof Map) {
119
- if (objA.size !== objB.size) return false;
120
- for (const [key, value] of objA) if (!Object.is(value, objB.get(key))) return false;
121
- return true;
122
- }
123
- if (objA instanceof Set && objB instanceof Set) {
124
- if (objA.size !== objB.size) return false;
125
- for (const value of objA) if (!objB.has(value)) return false;
126
- return true;
127
- }
128
- const keysA = Object.keys(objA);
129
- if (keysA.length !== Object.keys(objB).length) return false;
130
- for (const keyA of keysA) if (!Object.prototype.hasOwnProperty.call(objB, keyA) || !Object.is(objA[keyA], objB[keyA])) return false;
131
- if (objA.constructor !== objB.constructor) return false;
132
- return true;
283
+ const fetchProjectSettings = async (client = getDefaultClient()) => {
284
+ const core = getCore(client);
285
+ const currentExpiration = await core.storage.getItem(projectSettingsExpirationStorageKeySchema);
286
+ if (Boolean(client.projectSettings) && !(currentExpiration && currentExpiration < Date.now()) && isSignedIn(client)) return client.projectSettings;
287
+ const apiClient = createApiClient({}, client);
288
+ core.logger.debug("[fetchProjectSettings] Fetching project settings...");
289
+ const doFetch = async () => apiClient.getEnvironmentSettings({
290
+ environmentId: core.environmentId,
291
+ sdkVersion: `${CLIENT_SDK_NAME}/${core.version}`
292
+ }, { credentials: "omit" });
293
+ const projectSettings = await retryOnFail({
294
+ fn: doFetch,
295
+ maxRetries: 2
296
+ });
297
+ core.state.set({ projectSettings: projectSettings ?? null });
298
+ await core.storage.setItem(projectSettingsExpirationStorageKeySchema, Date.now() + PROJECT_SETTINGS_EXPIRATION_TIME);
299
+ return projectSettings;
133
300
  };
134
301
 
135
302
  //#endregion
136
- //#region src/utils/observable/subscribeWithSelector/subscribeWithSelector.ts
303
+ //#region src/modules/sessionKeys/generateSessionKeys/generateSessionKeys.ts
304
+ /** @not-instrumented */
305
+ const generateSessionKeys = async (client) => {
306
+ const core = getCore(client);
307
+ await core.keychain.removeKey("session");
308
+ const publicKey = await core.keychain.generateKey("session");
309
+ assertDefined(publicKey, "Public key not found");
310
+ core.state.set({ sessionKeys: publicKey });
311
+ return { publicKey };
312
+ };
313
+
314
+ //#endregion
315
+ //#region src/modules/wallets/utils/getAvailableWalletProvidersFromWalletAccounts/getAvailableWalletProvidersFromWalletAccounts.ts
316
+ /** @not-instrumented */
317
+ const getAvailableWalletProvidersFromWalletAccounts = (client) => {
318
+ const core = getCore(client);
319
+ const walletProvidersMap = /* @__PURE__ */ new Map();
320
+ getWalletAccounts(client).forEach((walletAccount) => {
321
+ if (walletProvidersMap.has(walletAccount.walletProviderKey)) return;
322
+ try {
323
+ const walletProvider = getWalletProviderFromWalletAccount({ walletAccount }, client);
324
+ walletProvidersMap.set(walletAccount.walletProviderKey, walletProvider);
325
+ } catch (error) {
326
+ core.logger.debug("Wallet provider not found for wallet account", {
327
+ error,
328
+ walletAccount: walletAccount.address
329
+ });
330
+ }
331
+ });
332
+ return Array.from(walletProvidersMap.values());
333
+ };
334
+
335
+ //#endregion
336
+ //#region src/modules/wallets/destroyWalletProviders/destroyWalletProviders.ts
137
337
  /**
138
- * Allows subscribing to a slice of the state.
139
- * The slice is a computation of the states.
338
+ * Tear down every wallet provider on the client.
140
339
  *
141
- * The callback will only be called when the slice has changed.
142
- * Change is determined by shallow comparison.
340
+ * Each provider's `destroy` is responsible for its own local + remote
341
+ * cleanup. We swallow errors so a failing destroy on one provider does not
342
+ * block teardown of the others (e.g. during logout).
143
343
  *
144
- * Returns a function to unsubscribe the callback.
145
344
  * @not-instrumented
146
345
  */
147
- const subscribeWithSelector = (observable, selector) => (callback) => {
148
- let lastSlice = selector(observable.get());
149
- return observable.subscribe((value) => {
150
- const nextSlice = selector(value);
151
- if (isEqualShallow(nextSlice, lastSlice)) return;
152
- lastSlice = nextSlice;
153
- callback(nextSlice);
346
+ const destroyWalletProviders = async ({ reason }, client) => {
347
+ const core = getCore(client);
348
+ const walletProviders = getAvailableWalletProvidersFromWalletAccounts(client);
349
+ await Promise.all(walletProviders.map(async (walletProvider) => {
350
+ if (!walletProvider.destroy) return;
351
+ try {
352
+ await walletProvider.destroy({ reason });
353
+ } catch (err) {
354
+ core.logger.error(`Error destroying wallet provider ${walletProvider.key}`, err);
355
+ }
356
+ }));
357
+ };
358
+
359
+ //#endregion
360
+ //#region src/modules/auth/logoutWithReason/logoutWithReason.ts
361
+ /**
362
+ * Logs the user out with an explicit reason.
363
+ *
364
+ * Revokes the session, clears auth state, terminates wallet providers, and
365
+ * emits the `logout` client event with the given reason. The reason is also
366
+ * captured as an argument on the function-instrumentation event, which is
367
+ * how Datadog distinguishes between different logout causes.
368
+ *
369
+ * Use this instead of the public `logout` when triggering a logout from
370
+ * internal or extension code — the caller owns the reason string, so the
371
+ * telemetry correctly attributes *why* the logout happened.
372
+ *
373
+ * @param params - The logout params.
374
+ * @param params.reason - Why the logout is being triggered. Extension authors
375
+ * needing a reason outside the SDK catalog can cast with `as LogoutReason`.
376
+ * @param client - The Dynamic client instance.
377
+ * @instrumented
378
+ */
379
+ const logoutWithReason = async ({ reason }, client) => {
380
+ const core = getCore(client);
381
+ core.logger.debug("[logoutWithReason] Logging out...", { reason });
382
+ await destroyWalletProviders({ reason }, client);
383
+ if (client.user !== null) {
384
+ const apiClient = createApiClient({}, client);
385
+ try {
386
+ await apiClient.revokeSession({ environmentId: core.environmentId });
387
+ } catch (error) {
388
+ core.logger.error("Failed to revoke session", error);
389
+ }
390
+ /**
391
+ * This deletes the auth cookie if it exists.
392
+ * If the cookie doesn't exist, this sets a new cookie that expires immediately.
393
+ */
394
+ if (isCookieEnabled(client)) setCookie(`${DYNAMIC_AUTH_COOKIE_NAME}=; Max-Age=-99999999; path=/; SameSite=Lax`);
395
+ }
396
+ await core.keychain.removeKey("session");
397
+ core.state.set({
398
+ captchaToken: null,
399
+ elevatedAccessTokens: [],
400
+ legacyToken: null,
401
+ mfaToken: null,
402
+ sessionExpiresAt: null,
403
+ sessionKeys: null,
404
+ token: null,
405
+ unverifiedWalletAccounts: [],
406
+ user: null
154
407
  });
408
+ emitEvent({
409
+ args: { reason },
410
+ event: "logout"
411
+ }, client);
412
+ fetchProjectSettings(client);
413
+ generateSessionKeys(client);
155
414
  };
415
+ const __logoutWithReason_impl = logoutWithReason;
416
+ const __logoutWithReason_wrapped = instrumentFunction({
417
+ fn: __logoutWithReason_impl,
418
+ functionName: "logoutWithReason",
419
+ getCore: () => {
420
+ try {
421
+ return getCore(getDefaultClient());
422
+ } catch {
423
+ return;
424
+ }
425
+ }
426
+ });
156
427
 
157
428
  //#endregion
158
429
  //#region src/utils/getBuffer/getBuffer.ts
@@ -304,7 +575,7 @@ const createLogger = (options = {}) => {
304
575
 
305
576
  //#endregion
306
577
  //#region src/turboModules/NativeKeychain.ts
307
- var NativeKeychain_default = TurboModuleRegistry.getEnforcing("Keychain");
578
+ var NativeKeychain_default = TurboModuleRegistry.getEnforcing("DynamicClientKeychain");
308
579
 
309
580
  //#endregion
310
581
  //#region src/utils/base64urlFromBytes/base64urlFromBytes.ts
@@ -443,7 +714,7 @@ var KeyNotFoundError = class extends BaseError {
443
714
  * @not-instrumented
444
715
  */
445
716
  const createKeychainService = () => {
446
- if (NativeKeychain_default == null) throw new NativeModuleNotLinkedError({ moduleName: "Keychain" });
717
+ if (NativeKeychain_default == null) throw new NativeModuleNotLinkedError({ moduleName: "DynamicClientKeychain" });
447
718
  const nativeModule = NativeKeychain_default;
448
719
  const generateKey = async (keyName) => {
449
720
  return bufferToHex(compressRawPublicKey(bytesFromBase64url((await nativeModule.generateKeyPair(keyName)).publicKey).buffer));
@@ -1111,5 +1382,5 @@ const getNetworkProviderFromNetworkId = ({ networkId, chain }, client) => {
1111
1382
  };
1112
1383
 
1113
1384
  //#endregion
1114
- export { GENERATE_SESSION_KEYS_TRACKER_KEY as A, createKeychainService as C, CannotTrackError as D, CrossTabBroadcastMessageSchema as E, getBuffer as F, subscribeWithSelector as I, isEqualShallow as L, REFRESH_USER_STATE_FROM_COOKIE_TRACKER_KEY as M, REFRESH_USER_STATE_FROM_VALID_TOKEN_TRACKER_KEY as N, createDeferredPromise as O, isServerSideRendering as P, createStorage as R, createRealtimeService as S, createCrossTabBroadcast as T, getAppMetadata as _, verifyMessageSignatureOwnership as a, NoNetworkProvidersError as b, formatSignInMessage as c, setUnverifiedWalletAccounts as d, createVisit as f, isCaptchaRequired as g, consumeCaptchaToken as h, getNetworksData as i, INITIALIZE_STORAGE_SYNC_TRACKER_KEY as j, FETCH_PROJECT_SETTINGS_TRACKER_KEY as k, reconcileWalletAccountsAgainstClient as l, __setCaptchaToken_wrapped as m, getNetworkProviders as n, removeUnverifiedWalletAccount as o, hasExtension as p, getNetworkProviderBuilderRegistry as r, createSignInMessageStatement as s, getNetworkProviderFromNetworkId as t, updateWalletProviderKeysForVerifiedCredentials as u, MethodNotImplementedError as v, createLogger as w, getKeychainIndexedDBName as x, WalletAlreadyLinkedToAnotherUserError as y, InvalidStorageSet as z };
1115
- //# sourceMappingURL=getNetworkProviderFromNetworkId-B7DIqT2T.native.esm.js.map
1385
+ export { GENERATE_SESSION_KEYS_TRACKER_KEY as A, createStorage as B, createKeychainService as C, CannotTrackError as D, CrossTabBroadcastMessageSchema as E, getBuffer as F, subscribeWithSelector as G, createLocalStorageAdapter as H, __logoutWithReason_wrapped as I, isEqualShallow as K, generateSessionKeys as L, REFRESH_USER_STATE_FROM_COOKIE_TRACKER_KEY as M, REFRESH_USER_STATE_FROM_VALID_TOKEN_TRACKER_KEY as N, createDeferredPromise as O, isServerSideRendering as P, fetchProjectSettings as R, createRealtimeService as S, createCrossTabBroadcast as T, isSignedIn as U, InvalidStorageSet as V, retryOnFail as W, getAppMetadata as _, verifyMessageSignatureOwnership as a, NoNetworkProvidersError as b, formatSignInMessage as c, setUnverifiedWalletAccounts as d, createVisit as f, isCaptchaRequired as g, consumeCaptchaToken as h, getNetworksData as i, INITIALIZE_STORAGE_SYNC_TRACKER_KEY as j, FETCH_PROJECT_SETTINGS_TRACKER_KEY as k, reconcileWalletAccountsAgainstClient as l, __setCaptchaToken_wrapped as m, getNetworkProviders as n, removeUnverifiedWalletAccount as o, hasExtension as p, getNetworkProviderBuilderRegistry as r, createSignInMessageStatement as s, getNetworkProviderFromNetworkId as t, updateWalletProviderKeysForVerifiedCredentials as u, MethodNotImplementedError as v, createLogger as w, getKeychainIndexedDBName as x, WalletAlreadyLinkedToAnotherUserError as y, createStorageKeySchema as z };
1386
+ //# sourceMappingURL=getNetworkProviderFromNetworkId-DVmF7pH2.native.esm.js.map