@dynamic-labs-sdk/client 1.23.0 → 1.24.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 (120) hide show
  1. package/dist/{NativeModuleNotLinkedError-DIpQjh_K.native.esm.js → NativeModuleNotLinkedError-CJy_4-6r.native.esm.js} +3 -3
  2. package/dist/{NativeModuleNotLinkedError-DIpQjh_K.native.esm.js.map → NativeModuleNotLinkedError-CJy_4-6r.native.esm.js.map} +1 -1
  3. package/dist/{consumeMfaTokenIfRequiredForAction-pUcqlY3s.cjs → consumeMfaTokenIfRequiredForAction-B6nFE5IO.cjs} +2 -2
  4. package/dist/{consumeMfaTokenIfRequiredForAction-pUcqlY3s.cjs.map → consumeMfaTokenIfRequiredForAction-B6nFE5IO.cjs.map} +1 -1
  5. package/dist/{consumeMfaTokenIfRequiredForAction-jsAdDyDj.esm.js → consumeMfaTokenIfRequiredForAction-DXTH4qki.esm.js} +2 -2
  6. package/dist/{consumeMfaTokenIfRequiredForAction-jsAdDyDj.esm.js.map → consumeMfaTokenIfRequiredForAction-DXTH4qki.esm.js.map} +1 -1
  7. package/dist/core.cjs +7 -6
  8. package/dist/core.cjs.map +1 -1
  9. package/dist/core.esm.js +7 -7
  10. package/dist/core.esm.js.map +1 -1
  11. package/dist/core.native.esm.js +6 -6
  12. package/dist/core.native.esm.js.map +1 -1
  13. package/dist/exports/core.d.ts +2 -0
  14. package/dist/exports/core.d.ts.map +1 -1
  15. package/dist/exports/waas.d.ts +2 -1
  16. package/dist/exports/waas.d.ts.map +1 -1
  17. package/dist/{getNetworkProviderFromNetworkId-DPFHY3b8.cjs → getNetworkProviderFromNetworkId-CZjFA5G8.cjs} +64 -2
  18. package/dist/getNetworkProviderFromNetworkId-CZjFA5G8.cjs.map +1 -0
  19. package/dist/{getNetworkProviderFromNetworkId-DTNPpR5H.esm.js → getNetworkProviderFromNetworkId-CjdC5HjA.esm.js} +59 -3
  20. package/dist/getNetworkProviderFromNetworkId-CjdC5HjA.esm.js.map +1 -0
  21. package/dist/{getNetworkProviderFromNetworkId-YcalZlDG.native.esm.js → getNetworkProviderFromNetworkId-R8IKGc6s.native.esm.js} +59 -261
  22. package/dist/getNetworkProviderFromNetworkId-R8IKGc6s.native.esm.js.map +1 -0
  23. package/dist/{getSignedSessionId-BjhgfsJD.native.esm.js → getSignedSessionId-B6Eqmue0.native.esm.js} +3 -3
  24. package/dist/{getSignedSessionId-BjhgfsJD.native.esm.js.map → getSignedSessionId-B6Eqmue0.native.esm.js.map} +1 -1
  25. package/dist/{getSignedSessionId-Btl5p_7b.esm.js → getSignedSessionId-BYR70F5w.esm.js} +2 -2
  26. package/dist/{getSignedSessionId-Btl5p_7b.esm.js.map → getSignedSessionId-BYR70F5w.esm.js.map} +1 -1
  27. package/dist/{getSignedSessionId-VX7LkxVJ.cjs → getSignedSessionId-BpUNqL9z.cjs} +2 -2
  28. package/dist/{getSignedSessionId-VX7LkxVJ.cjs.map → getSignedSessionId-BpUNqL9z.cjs.map} +1 -1
  29. package/dist/{getWalletProviderByKey-5sZK6kAJ.esm.js → getWalletProviderByKey-BVVFLnfy.esm.js} +2 -2
  30. package/dist/{getWalletProviderByKey-5sZK6kAJ.esm.js.map → getWalletProviderByKey-BVVFLnfy.esm.js.map} +1 -1
  31. package/dist/getWalletProviderByKey-CqdhcE7y.native.esm.js +279 -0
  32. package/dist/getWalletProviderByKey-CqdhcE7y.native.esm.js.map +1 -0
  33. package/dist/{getWalletProviderByKey--K4N2u-M.cjs → getWalletProviderByKey-D2ElEmJR.cjs} +2 -2
  34. package/dist/{getWalletProviderByKey--K4N2u-M.cjs.map → getWalletProviderByKey-D2ElEmJR.cjs.map} +1 -1
  35. package/dist/index.cjs +17 -67
  36. package/dist/index.cjs.map +1 -1
  37. package/dist/index.esm.js +16 -66
  38. package/dist/index.esm.js.map +1 -1
  39. package/dist/index.native.esm.js +16 -66
  40. package/dist/index.native.esm.js.map +1 -1
  41. package/dist/{isDynamicWaasEnabled-MtEVK3ov.cjs → isDynamicWaasEnabled-B7_FiTkx.cjs} +2 -2
  42. package/dist/{isDynamicWaasEnabled-MtEVK3ov.cjs.map → isDynamicWaasEnabled-B7_FiTkx.cjs.map} +1 -1
  43. package/dist/{isDynamicWaasEnabled-sI3vpWvA.esm.js → isDynamicWaasEnabled-Ck0VFh7Z.esm.js} +2 -2
  44. package/dist/{isDynamicWaasEnabled-sI3vpWvA.esm.js.map → isDynamicWaasEnabled-Ck0VFh7Z.esm.js.map} +1 -1
  45. package/dist/{isDynamicWaasEnabled-BR_pG4jM.native.esm.js → isDynamicWaasEnabled-yo_LqzH5.native.esm.js} +2 -2
  46. package/dist/{isDynamicWaasEnabled-BR_pG4jM.native.esm.js.map → isDynamicWaasEnabled-yo_LqzH5.native.esm.js.map} +1 -1
  47. package/dist/{isMfaRequiredForAction-BiPVqg49.cjs → isMfaRequiredForAction-B3FO4Zbn.cjs} +2 -2
  48. package/dist/{isMfaRequiredForAction-BiPVqg49.cjs.map → isMfaRequiredForAction-B3FO4Zbn.cjs.map} +1 -1
  49. package/dist/{isMfaRequiredForAction-DJ2UX11y.esm.js → isMfaRequiredForAction-CnO4g-V0.esm.js} +2 -2
  50. package/dist/{isMfaRequiredForAction-DJ2UX11y.esm.js.map → isMfaRequiredForAction-CnO4g-V0.esm.js.map} +1 -1
  51. package/dist/{isMfaRequiredForAction-GWZny7T2.native.esm.js → isMfaRequiredForAction-Zi7_K00W.native.esm.js} +2 -2
  52. package/dist/{isMfaRequiredForAction-GWZny7T2.native.esm.js.map → isMfaRequiredForAction-Zi7_K00W.native.esm.js.map} +1 -1
  53. package/dist/{isUserOnboardingComplete-OvzVH1rg.esm.js → isUserOnboardingComplete-DZk1nVHO.esm.js} +3 -3
  54. package/dist/{isUserOnboardingComplete-OvzVH1rg.esm.js.map → isUserOnboardingComplete-DZk1nVHO.esm.js.map} +1 -1
  55. package/dist/{isUserOnboardingComplete-Hzz6fwTk.native.esm.js → isUserOnboardingComplete-DcRl6Q1f.native.esm.js} +3 -3
  56. package/dist/{isUserOnboardingComplete-Hzz6fwTk.native.esm.js.map → isUserOnboardingComplete-DcRl6Q1f.native.esm.js.map} +1 -1
  57. package/dist/{isUserOnboardingComplete-D1hw1c5_.cjs → isUserOnboardingComplete-Dnx30meW.cjs} +3 -3
  58. package/dist/{isUserOnboardingComplete-D1hw1c5_.cjs.map → isUserOnboardingComplete-Dnx30meW.cjs.map} +1 -1
  59. package/dist/{migrateFromFireblocks-BiLoNIkA.native.esm.js → migrateFromFireblocks-COEK_Acn.native.esm.js} +13 -13
  60. package/dist/migrateFromFireblocks-COEK_Acn.native.esm.js.map +1 -0
  61. package/dist/{migrateFromFireblocks-NRfLh1JL.cjs → migrateFromFireblocks-CdSxWZav.cjs} +13 -13
  62. package/dist/migrateFromFireblocks-CdSxWZav.cjs.map +1 -0
  63. package/dist/{migrateFromFireblocks-Y5pPtmew.esm.js → migrateFromFireblocks-nkmSeZrn.esm.js} +14 -14
  64. package/dist/migrateFromFireblocks-nkmSeZrn.esm.js.map +1 -0
  65. package/dist/modules/auth/getActionAuthorizationTokens/getActionAuthorizationTokens.d.ts +29 -0
  66. package/dist/modules/auth/getActionAuthorizationTokens/getActionAuthorizationTokens.d.ts.map +1 -0
  67. package/dist/modules/auth/getActionAuthorizationTokens/index.d.ts +2 -0
  68. package/dist/modules/auth/getActionAuthorizationTokens/index.d.ts.map +1 -0
  69. package/dist/modules/auth/logoutReason.d.ts +1 -1
  70. package/dist/modules/auth/logoutReason.d.ts.map +1 -1
  71. package/dist/modules/flow/prepareFlowSigning/prepareFlowSigning.d.ts +2 -2
  72. package/dist/modules/waas/businessAccounts/addBusinessAccountMember/addBusinessAccountMember.d.ts +13 -12
  73. package/dist/modules/waas/businessAccounts/addBusinessAccountMember/addBusinessAccountMember.d.ts.map +1 -1
  74. package/dist/modules/waas/businessAccounts/addBusinessAccountSigner/addBusinessAccountSigner.d.ts +4 -4
  75. package/dist/modules/waas/businessAccounts/addBusinessAccountSigner/addBusinessAccountSigner.d.ts.map +1 -1
  76. package/dist/modules/waas/businessAccounts/addWalletToBusinessAccount/addWalletToBusinessAccount.d.ts +7 -2
  77. package/dist/modules/waas/businessAccounts/addWalletToBusinessAccount/addWalletToBusinessAccount.d.ts.map +1 -1
  78. package/dist/modules/waas/businessAccounts/assertTargetIdentity.d.ts +14 -0
  79. package/dist/modules/waas/businessAccounts/assertTargetIdentity.d.ts.map +1 -0
  80. package/dist/modules/waas/businessAccounts/businessAccounts.constants.d.ts +5 -0
  81. package/dist/modules/waas/businessAccounts/businessAccounts.constants.d.ts.map +1 -0
  82. package/dist/modules/waas/businessAccounts/businessAccounts.types.d.ts +15 -1
  83. package/dist/modules/waas/businessAccounts/businessAccounts.types.d.ts.map +1 -1
  84. package/dist/modules/waas/businessAccounts/transferBusinessAccountOwnership/transferBusinessAccountOwnership.d.ts.map +1 -1
  85. package/dist/modules/waas/businessAccounts/updateBusinessAccount/index.d.ts +2 -0
  86. package/dist/modules/waas/businessAccounts/updateBusinessAccount/index.d.ts.map +1 -0
  87. package/dist/modules/waas/businessAccounts/updateBusinessAccount/updateBusinessAccount.d.ts +26 -0
  88. package/dist/modules/waas/businessAccounts/updateBusinessAccount/updateBusinessAccount.d.ts.map +1 -0
  89. package/dist/modules/waas/createWaasProvider/createWaasProvider.d.ts.map +1 -1
  90. package/dist/modules/waas/waas.types.d.ts +2 -2
  91. package/dist/modules/waas/waas.types.d.ts.map +1 -1
  92. package/dist/modules/wallets/verifyWalletAccount/verifyWalletAccount.d.ts +1 -1
  93. package/dist/modules/wallets/verifyWalletAccountForSignInOrTransfer/verifyWalletAccountForSignInOrTransfer.d.ts.map +1 -1
  94. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  95. package/dist/{updateAuthFromVerifyResponse-ChnvPY0m.cjs → updateAuthFromVerifyResponse-BSORoVT0.cjs} +3 -3
  96. package/dist/{updateAuthFromVerifyResponse-ChnvPY0m.cjs.map → updateAuthFromVerifyResponse-BSORoVT0.cjs.map} +1 -1
  97. package/dist/{updateAuthFromVerifyResponse-Ct1Y6O_T.esm.js → updateAuthFromVerifyResponse-D0Tt9-Z-.esm.js} +3 -3
  98. package/dist/{updateAuthFromVerifyResponse-Ct1Y6O_T.esm.js.map → updateAuthFromVerifyResponse-D0Tt9-Z-.esm.js.map} +1 -1
  99. package/dist/waas.cjs +123 -41
  100. package/dist/waas.cjs.map +1 -1
  101. package/dist/waas.esm.js +124 -43
  102. package/dist/waas.esm.js.map +1 -1
  103. package/dist/waas.native.esm.js +123 -42
  104. package/dist/waas.native.esm.js.map +1 -1
  105. package/dist/waasCore.cjs +53 -15
  106. package/dist/waasCore.cjs.map +1 -1
  107. package/dist/waasCore.esm.js +53 -15
  108. package/dist/waasCore.esm.js.map +1 -1
  109. package/dist/waasCore.native.esm.js +52 -14
  110. package/dist/waasCore.native.esm.js.map +1 -1
  111. package/ios/DynamicClientScreenshotProtection.mm +11 -0
  112. package/package.json +3 -3
  113. package/dist/getNetworkProviderFromNetworkId-DPFHY3b8.cjs.map +0 -1
  114. package/dist/getNetworkProviderFromNetworkId-DTNPpR5H.esm.js.map +0 -1
  115. package/dist/getNetworkProviderFromNetworkId-YcalZlDG.native.esm.js.map +0 -1
  116. package/dist/getWalletProviderByKey-BhcBoGMW.native.esm.js +0 -20
  117. package/dist/getWalletProviderByKey-BhcBoGMW.native.esm.js.map +0 -1
  118. package/dist/migrateFromFireblocks-BiLoNIkA.native.esm.js.map +0 -1
  119. package/dist/migrateFromFireblocks-NRfLh1JL.cjs.map +0 -1
  120. package/dist/migrateFromFireblocks-Y5pPtmew.esm.js.map +0 -1
@@ -0,0 +1,279 @@
1
+ import { C as DYNAMIC_AUTH_COOKIE_NAME, H as createApiClient, J as getSecureCookieAttribute, O as NoWalletProviderFoundError, R as emitEvent, St as getCore, Z as createStorageKeySchema, _ as instrumentFunction, dt as isCookieEnabled, ft as assertDefined, k as getWalletAccounts, ot as CLIENT_SDK_NAME, p as getWalletProviders, q as setCookie, st as DYNAMIC_LOGOUT_REASON_HEADER, vt as getDefaultClient, w as getWalletProviderFromWalletAccount, xt as BaseError } from "./NativeModuleNotLinkedError-CJy_4-6r.native.esm.js";
2
+ import * as z from "zod/mini";
3
+
4
+ //#region src/utils/retryOnFail/InvalidRetryOnFailCallError.ts
5
+ /**
6
+ * This error is thrown when the `retryOnFail` function is called with an invalid
7
+ * number of retries (i.e. less than 0).
8
+ */
9
+ var InvalidRetryOnFailCallError = class extends BaseError {
10
+ constructor(maxRetries) {
11
+ super({
12
+ cause: null,
13
+ code: "invalid_retry_on_fail_call_error",
14
+ docsUrl: null,
15
+ name: "InvalidRetryOnFailCallError",
16
+ shortMessage: `Invalid retries parameter for retryOnFail call: ${maxRetries}`
17
+ });
18
+ }
19
+ };
20
+
21
+ //#endregion
22
+ //#region src/utils/retryOnFail/retryOnFail.ts
23
+ /** @notInstrumented */
24
+ const retryOnFail = async ({ delay = 0, fn, maxRetries }) => {
25
+ for (let retry = 0; retry <= maxRetries; retry++) try {
26
+ return await fn();
27
+ } catch (error) {
28
+ if (retry >= maxRetries) throw error;
29
+ if (delay > 0) await new Promise((resolve) => setTimeout(resolve, delay));
30
+ }
31
+ /**
32
+ * Reaching this point should never happen and this
33
+ * error is thrown to help us debug the issue.
34
+ */
35
+ throw new InvalidRetryOnFailCallError(maxRetries);
36
+ };
37
+
38
+ //#endregion
39
+ //#region src/modules/auth/isSignedIn/isSignedIn.ts
40
+ /**
41
+ * Checks if the user is currently signed in to the Dynamic client.
42
+ *
43
+ * The client is considered to be in a signed in state if a user has
44
+ * authenticated or if the client has at least one wallet connected.
45
+ *
46
+ * @deprecated What counts as "signed in" is your app's business logic, not the
47
+ * SDK's. This helper bakes in one opinion (a user OR any connected wallet),
48
+ * which rarely matches every app and forces a dependency on us for every
49
+ * variation. Compose your own check from the underlying primitives instead —
50
+ * e.g. `Boolean(client.user) || isAnyWalletAccountConnected(client)` — and
51
+ * layer in whatever your app requires (device registration, completed
52
+ * onboarding, satisfied MFA, a required embedded wallet, …). See the
53
+ * "Check if signed in" guide:
54
+ * https://www.dynamic.xyz/docs/javascript/user-session-management
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * if (isSignedIn()) {
59
+ * console.log('User is authenticated or has a wallet connected');
60
+ * }
61
+ * ```
62
+ *
63
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
64
+ * @returns True if the user is signed in, false otherwise.
65
+ * @see logout
66
+ * @see isAnyWalletAccountConnected
67
+ * @notInstrumented
68
+ */
69
+ const isSignedIn = (client = getDefaultClient()) => Boolean(client.user || getWalletAccounts(client).length > 0);
70
+
71
+ //#endregion
72
+ //#region src/modules/projectSettings/fetchProjectSettings/projectSettingsExpirationScheme.ts
73
+ /**
74
+ * The schema to track the expiration time of the project settings.
75
+ */
76
+ const projectSettingsExpirationStorageKeySchema = createStorageKeySchema({
77
+ key: "projectSettingsExpiration",
78
+ schema: z.number()
79
+ });
80
+
81
+ //#endregion
82
+ //#region src/modules/projectSettings/fetchProjectSettings/fetchProjectSettings.ts
83
+ /**
84
+ * Expiration time of the project settings in milliseconds.
85
+ */
86
+ const PROJECT_SETTINGS_EXPIRATION_TIME = 1e3 * 60 * 5;
87
+ /**
88
+ * Fetches and updates the project settings from the API.
89
+ *
90
+ * This function retrieves the latest project configuration settings
91
+ * from Dynamic's servers, including authentication options, enabled chains,
92
+ * and security configurations. The settings are cached for performance.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * const settings = await fetchProjectSettings();
97
+ * console.log('Enabled chains:', settings.chains);
98
+ * ```
99
+ *
100
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
101
+ * @returns A promise that resolves to the updated project settings.
102
+ * @see createDynamicClient
103
+ * @see initializeClient
104
+ * @notInstrumented
105
+ * @noHook Internal settings fetch that is not part of the public hook surface.
106
+ */
107
+ const fetchProjectSettings = async (client = getDefaultClient()) => {
108
+ const core = getCore(client);
109
+ const currentExpiration = await core.storage.getItem(projectSettingsExpirationStorageKeySchema);
110
+ if (Boolean(client.projectSettings) && !(currentExpiration && currentExpiration < Date.now()) && isSignedIn(client)) return client.projectSettings;
111
+ const apiClient = createApiClient({}, client);
112
+ core.logger.debug("[fetchProjectSettings] Fetching project settings...");
113
+ const doFetch = async () => apiClient.getEnvironmentSettings({
114
+ environmentId: core.environmentId,
115
+ sdkVersion: `${CLIENT_SDK_NAME}/${core.version}`
116
+ }, { credentials: "omit" });
117
+ const projectSettings = await retryOnFail({
118
+ fn: doFetch,
119
+ maxRetries: 2
120
+ });
121
+ core.state.set({ projectSettings: projectSettings ?? null });
122
+ await core.storage.setItem(projectSettingsExpirationStorageKeySchema, Date.now() + PROJECT_SETTINGS_EXPIRATION_TIME);
123
+ return projectSettings;
124
+ };
125
+
126
+ //#endregion
127
+ //#region src/modules/sessionKeys/generateSessionKeys/generateSessionKeys.ts
128
+ /** @notInstrumented */
129
+ const generateSessionKeys = async (client) => {
130
+ const core = getCore(client);
131
+ const currentState = core.state.get();
132
+ const isRotation = Boolean(currentState.sessionKeys);
133
+ const logContext = {
134
+ environmentId: core.environmentId,
135
+ operation: isRotation ? "rotate" : "create",
136
+ userId: currentState.user?.id ?? null
137
+ };
138
+ core.logger.info(isRotation ? "[generateSessionKeys] Rotating session key..." : "[generateSessionKeys] Creating session key...", logContext);
139
+ await core.keychain.removeKey("session");
140
+ const publicKey = await core.keychain.generateKey("session");
141
+ assertDefined(publicKey, "Public key not found");
142
+ core.state.set({ sessionKeys: publicKey });
143
+ core.logger.info(isRotation ? "[generateSessionKeys] Session key rotated" : "[generateSessionKeys] Session key created", logContext);
144
+ return { publicKey };
145
+ };
146
+
147
+ //#endregion
148
+ //#region src/modules/wallets/utils/getAvailableWalletProvidersFromWalletAccounts/getAvailableWalletProvidersFromWalletAccounts.ts
149
+ /** @notInstrumented */
150
+ const getAvailableWalletProvidersFromWalletAccounts = (client) => {
151
+ const core = getCore(client);
152
+ const walletProvidersMap = /* @__PURE__ */ new Map();
153
+ getWalletAccounts(client).forEach((walletAccount) => {
154
+ if (walletProvidersMap.has(walletAccount.walletProviderKey)) return;
155
+ try {
156
+ const walletProvider = getWalletProviderFromWalletAccount({ walletAccount }, client);
157
+ walletProvidersMap.set(walletAccount.walletProviderKey, walletProvider);
158
+ } catch (error) {
159
+ core.logger.debug("Wallet provider not found for wallet account", {
160
+ error,
161
+ walletAccount: walletAccount.address
162
+ });
163
+ }
164
+ });
165
+ return Array.from(walletProvidersMap.values());
166
+ };
167
+
168
+ //#endregion
169
+ //#region src/modules/wallets/destroyWalletProviders/destroyWalletProviders.ts
170
+ /**
171
+ * Tear down every wallet provider on the client.
172
+ *
173
+ * Each provider's `destroy` is responsible for its own local + remote
174
+ * cleanup. We swallow errors so a failing destroy on one provider does not
175
+ * block teardown of the others (e.g. during logout).
176
+ *
177
+ * @notInstrumented
178
+ */
179
+ const destroyWalletProviders = async ({ reason }, client) => {
180
+ const core = getCore(client);
181
+ const walletProviders = getAvailableWalletProvidersFromWalletAccounts(client);
182
+ await Promise.all(walletProviders.map(async (walletProvider) => {
183
+ if (!walletProvider.destroy) return;
184
+ try {
185
+ await walletProvider.destroy({ reason });
186
+ } catch (err) {
187
+ core.logger.error(`Error destroying wallet provider ${walletProvider.key}`, err);
188
+ }
189
+ }));
190
+ };
191
+
192
+ //#endregion
193
+ //#region src/modules/auth/logoutWithReason/logoutWithReason.ts
194
+ /**
195
+ * Logs the user out with an explicit reason.
196
+ *
197
+ * Revokes the session, clears auth state, terminates wallet providers, and
198
+ * emits the `logout` client event with the given reason. The reason is also
199
+ * captured as an argument on the function-instrumentation event, which is
200
+ * how Datadog distinguishes between different logout causes.
201
+ *
202
+ * Use this instead of the public `logout` when triggering a logout from
203
+ * internal or extension code — the caller owns the reason string, so the
204
+ * telemetry correctly attributes *why* the logout happened.
205
+ *
206
+ * @param params - The logout params.
207
+ * @param params.reason - Why the logout is being triggered. Extension authors
208
+ * needing a reason outside the SDK catalog can cast with `as LogoutReason`.
209
+ * @param client - The Dynamic client instance.
210
+ * @instrumented
211
+ */
212
+ const logoutWithReason = async ({ reason }, client) => {
213
+ const core = getCore(client);
214
+ core.logger.debug("[logoutWithReason] Logging out...", { reason });
215
+ await destroyWalletProviders({ reason }, client);
216
+ if (client.user !== null) {
217
+ const apiClient = createApiClient({ headers: { [DYNAMIC_LOGOUT_REASON_HEADER]: reason } }, client);
218
+ try {
219
+ await apiClient.revokeSession({ environmentId: core.environmentId });
220
+ } catch (error) {
221
+ core.logger.error("Failed to revoke session", error);
222
+ }
223
+ /**
224
+ * This deletes the auth cookie if it exists.
225
+ * If the cookie doesn't exist, this sets a new cookie that expires immediately.
226
+ */
227
+ if (isCookieEnabled(client)) setCookie(`${DYNAMIC_AUTH_COOKIE_NAME}=; Max-Age=-99999999; path=/; SameSite=Lax${getSecureCookieAttribute()}`);
228
+ }
229
+ await core.keychain.removeKey("session");
230
+ core.state.set({
231
+ captchaToken: null,
232
+ elevatedAccessTokens: [],
233
+ legacyToken: null,
234
+ mfaToken: null,
235
+ sessionExpiresAt: null,
236
+ sessionKeys: null,
237
+ token: null,
238
+ unverifiedWalletAccounts: [],
239
+ user: null
240
+ });
241
+ emitEvent({
242
+ args: { reason },
243
+ event: "logout"
244
+ }, client);
245
+ fetchProjectSettings(client);
246
+ generateSessionKeys(client);
247
+ };
248
+ const __logoutWithReason_impl = logoutWithReason;
249
+ const __logoutWithReason_wrapped = instrumentFunction({
250
+ fn: __logoutWithReason_impl,
251
+ functionName: "logoutWithReason",
252
+ getCore: () => {
253
+ try {
254
+ return getCore(getDefaultClient());
255
+ } catch {
256
+ return;
257
+ }
258
+ }
259
+ });
260
+
261
+ //#endregion
262
+ //#region src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.ts
263
+ /** @notInstrumented */
264
+ const getVerifiedCredentialForWalletAccount = ({ walletAccount }, client) => {
265
+ return client.user?.verifiedCredentials.find((vc) => vc.id === walletAccount.verifiedCredentialId);
266
+ };
267
+
268
+ //#endregion
269
+ //#region src/modules/wallets/getWalletProviderByKey/getWalletProviderByKey.ts
270
+ /** @notInstrumented */
271
+ const getWalletProviderByKey = ({ walletProviderKey }, client) => {
272
+ const walletProvider = getWalletProviders(client).find((walletProvider$1) => walletProvider$1.key === walletProviderKey);
273
+ if (!walletProvider) throw new NoWalletProviderFoundError({ walletProviderKey });
274
+ return walletProvider;
275
+ };
276
+
277
+ //#endregion
278
+ export { fetchProjectSettings as a, generateSessionKeys as i, getVerifiedCredentialForWalletAccount as n, isSignedIn as o, __logoutWithReason_wrapped as r, retryOnFail as s, getWalletProviderByKey as t };
279
+ //# sourceMappingURL=getWalletProviderByKey-CqdhcE7y.native.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getWalletProviderByKey-CqdhcE7y.native.esm.js","names":["walletProvidersMap: Map<string, WalletProvider>","walletProvider"],"sources":["../src/utils/retryOnFail/InvalidRetryOnFailCallError.ts","../src/utils/retryOnFail/retryOnFail.ts","../src/modules/auth/isSignedIn/isSignedIn.ts","../src/modules/projectSettings/fetchProjectSettings/projectSettingsExpirationScheme.ts","../src/modules/projectSettings/fetchProjectSettings/fetchProjectSettings.ts","../src/modules/sessionKeys/generateSessionKeys/generateSessionKeys.ts","../src/modules/wallets/utils/getAvailableWalletProvidersFromWalletAccounts/getAvailableWalletProvidersFromWalletAccounts.ts","../src/modules/wallets/destroyWalletProviders/destroyWalletProviders.ts","../src/modules/auth/logoutWithReason/logoutWithReason.ts","../src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.ts","../src/modules/wallets/getWalletProviderByKey/getWalletProviderByKey.ts"],"sourcesContent":["import { BaseError } from '../../errors/base';\n\n/**\n * This error is thrown when the `retryOnFail` function is called with an invalid\n * number of retries (i.e. less than 0).\n */\nexport class InvalidRetryOnFailCallError extends BaseError {\n // eslint-disable-next-line custom-rules/require-single-object-param\n constructor(maxRetries: number) {\n super({\n cause: null,\n code: 'invalid_retry_on_fail_call_error',\n docsUrl: null,\n name: 'InvalidRetryOnFailCallError',\n shortMessage: `Invalid retries parameter for retryOnFail call: ${maxRetries}`,\n });\n }\n}\n","import { InvalidRetryOnFailCallError } from './InvalidRetryOnFailCallError';\n\nexport type RetryOnFailParams<T> = {\n /**\n * The delay between retries in milliseconds.\n */\n delay?: number;\n /**\n * The function to call.\n */\n fn: () => Promise<T>;\n /**\n * The maximum number of retries.\n *\n * When set to 0, the function will be called only once and is\n * therefore equivalent to calling the function directly.\n */\n maxRetries: number;\n};\n\n/** @notInstrumented */\nexport const retryOnFail = async <T>({\n delay = 0,\n fn,\n maxRetries,\n}: RetryOnFailParams<T>) => {\n for (let retry = 0; retry <= maxRetries; retry++) {\n try {\n return await fn();\n } catch (error) {\n if (retry >= maxRetries) {\n throw error;\n }\n\n if (delay > 0) {\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n }\n }\n\n /**\n * Reaching this point should never happen and this\n * error is thrown to help us debug the issue.\n */\n throw new InvalidRetryOnFailCallError(maxRetries);\n};\n","import { getDefaultClient } from '../../../client/defaultClient';\nimport { getWalletAccounts } from '../../wallets/getWalletAccounts';\n\n/**\n * Checks if the user is currently signed in to the Dynamic client.\n *\n * The client is considered to be in a signed in state if a user has\n * authenticated or if the client has at least one wallet connected.\n *\n * @deprecated What counts as \"signed in\" is your app's business logic, not the\n * SDK's. This helper bakes in one opinion (a user OR any connected wallet),\n * which rarely matches every app and forces a dependency on us for every\n * variation. Compose your own check from the underlying primitives instead —\n * e.g. `Boolean(client.user) || isAnyWalletAccountConnected(client)` — and\n * layer in whatever your app requires (device registration, completed\n * onboarding, satisfied MFA, a required embedded wallet, …). See the\n * \"Check if signed in\" guide:\n * https://www.dynamic.xyz/docs/javascript/user-session-management\n *\n * @example\n * ```ts\n * if (isSignedIn()) {\n * console.log('User is authenticated or has a wallet connected');\n * }\n * ```\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns True if the user is signed in, false otherwise.\n * @see logout\n * @see isAnyWalletAccountConnected\n * @notInstrumented\n */\nexport const isSignedIn = (client = getDefaultClient()) =>\n Boolean(client.user || getWalletAccounts(client).length > 0);\n","import * as z from 'zod/mini';\n\nimport { createStorageKeySchema } from '../../../services/storage';\n\n/**\n * The schema to track the expiration time of the project settings.\n */\nexport const projectSettingsExpirationStorageKeySchema = createStorageKeySchema(\n {\n key: 'projectSettingsExpiration',\n schema: z.number(),\n }\n);\n","import { getCore } from '../../../client/core/getCore';\nimport { getDefaultClient } from '../../../client/defaultClient';\nimport { retryOnFail } from '../../../utils/retryOnFail';\nimport { createApiClient } from '../../apiClient';\nimport { CLIENT_SDK_NAME } from '../../apiClient/constants';\nimport { isSignedIn } from '../../auth/isSignedIn';\nimport { projectSettingsExpirationStorageKeySchema } from './projectSettingsExpirationScheme';\n\n/**\n * Expiration time of the project settings in milliseconds.\n */\nexport const PROJECT_SETTINGS_EXPIRATION_TIME = 1000 * 60 * 5; // 5 minutes\n\n/**\n * Fetches and updates the project settings from the API.\n *\n * This function retrieves the latest project configuration settings\n * from Dynamic's servers, including authentication options, enabled chains,\n * and security configurations. The settings are cached for performance.\n *\n * @example\n * ```ts\n * const settings = await fetchProjectSettings();\n * console.log('Enabled chains:', settings.chains);\n * ```\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to the updated project settings.\n * @see createDynamicClient\n * @see initializeClient\n * @notInstrumented\n * @noHook Internal settings fetch that is not part of the public hook surface.\n */\nexport const fetchProjectSettings = async (client = getDefaultClient()) => {\n const core = getCore(client);\n\n const currentExpiration = await core.storage.getItem(\n projectSettingsExpirationStorageKeySchema\n );\n\n const hasProjectSettings = Boolean(client.projectSettings);\n const isExpired = currentExpiration && currentExpiration < Date.now();\n\n // We want to cache the project settings if its valid and user is connected.\n // This avoids unnecessary API calls and speeds up the initial load.\n if (hasProjectSettings && !isExpired && isSignedIn(client)) {\n return client.projectSettings;\n }\n\n const apiClient = createApiClient({}, client);\n\n core.logger.debug('[fetchProjectSettings] Fetching project settings...');\n\n const doFetch = async () =>\n apiClient.getEnvironmentSettings(\n {\n environmentId: core.environmentId,\n sdkVersion: `${CLIENT_SDK_NAME}/${core.version}`,\n },\n {\n credentials: 'omit',\n }\n );\n\n const projectSettings = await retryOnFail({\n fn: doFetch,\n maxRetries: 2,\n });\n\n core.state.set({ projectSettings: projectSettings ?? null });\n\n await core.storage.setItem(\n projectSettingsExpirationStorageKeySchema,\n Date.now() + PROJECT_SETTINGS_EXPIRATION_TIME\n );\n\n return projectSettings;\n};\n","import { getCore } from '../../../client/core/getCore';\nimport type { DynamicClient } from '../../../client/types';\nimport { assertDefined } from '../../../utils/assertDefined';\nimport type { SessionKeys } from '../sessionKeys.types';\n\n/** @notInstrumented */\nexport const generateSessionKeys = async (\n client: DynamicClient\n): Promise<SessionKeys> => {\n const core = getCore(client);\n\n const currentState = core.state.get();\n\n const isRotation = Boolean(currentState.sessionKeys);\n\n const logContext = {\n environmentId: core.environmentId,\n operation: isRotation ? 'rotate' : 'create',\n userId: currentState.user?.id ?? null,\n };\n\n core.logger.info(\n isRotation\n ? '[generateSessionKeys] Rotating session key...'\n : '[generateSessionKeys] Creating session key...',\n logContext\n );\n\n await core.keychain.removeKey('session');\n\n const publicKey = await core.keychain.generateKey('session');\n\n assertDefined(publicKey, 'Public key not found');\n\n core.state.set({\n sessionKeys: publicKey,\n });\n\n core.logger.info(\n isRotation\n ? '[generateSessionKeys] Session key rotated'\n : '[generateSessionKeys] Session key created',\n logContext\n );\n\n return { publicKey };\n};\n","import { getCore } from '../../../../client/core/getCore';\nimport type { DynamicClient } from '../../../../client/types';\nimport { getWalletAccounts } from '../../getWalletAccounts';\nimport type { WalletProvider } from '../../walletProvider';\nimport { getWalletProviderFromWalletAccount } from '../getWalletProviderFromWalletAccount';\n\n/** @notInstrumented */\nexport const getAvailableWalletProvidersFromWalletAccounts = (\n client: DynamicClient\n) => {\n const core = getCore(client);\n\n const walletProvidersMap: Map<string, WalletProvider> = new Map();\n\n const walletAccounts = getWalletAccounts(client);\n\n walletAccounts.forEach((walletAccount) => {\n if (walletProvidersMap.has(walletAccount.walletProviderKey)) {\n return;\n }\n\n try {\n const walletProvider = getWalletProviderFromWalletAccount(\n {\n walletAccount,\n },\n client\n );\n\n walletProvidersMap.set(walletAccount.walletProviderKey, walletProvider);\n } catch (error) {\n core.logger.debug('Wallet provider not found for wallet account', {\n error,\n walletAccount: walletAccount.address,\n });\n }\n });\n\n return Array.from(walletProvidersMap.values());\n};\n","import { getCore } from '../../../client/core/getCore';\nimport type { DynamicClient } from '../../../client/types/DynamicClient';\nimport type { LogoutReason } from '../../auth/logoutReason';\nimport { getAvailableWalletProvidersFromWalletAccounts } from '../utils/getAvailableWalletProvidersFromWalletAccounts';\n\n/**\n * Tear down every wallet provider on the client.\n *\n * Each provider's `destroy` is responsible for its own local + remote\n * cleanup. We swallow errors so a failing destroy on one provider does not\n * block teardown of the others (e.g. during logout).\n *\n * @notInstrumented\n */\nexport const destroyWalletProviders = async (\n { reason }: { reason?: LogoutReason },\n client: DynamicClient\n) => {\n const core = getCore(client);\n\n const walletProviders = getAvailableWalletProvidersFromWalletAccounts(client);\n\n await Promise.all(\n walletProviders.map(async (walletProvider) => {\n if (!walletProvider.destroy) return;\n try {\n await walletProvider.destroy({ reason });\n } catch (err) {\n core.logger.error(\n `Error destroying wallet provider ${walletProvider.key}`,\n err\n );\n }\n })\n );\n};\n","import type { DynamicClient } from '../../../client/types';\nimport { getCore } from '../../../client/core/getCore';\nimport { getSecureCookieAttribute } from '../../../utils/getSecureCookieAttribute';\nimport { setCookie } from '../../../utils/setCookie';\nimport { createApiClient } from '../../apiClient';\nimport { DYNAMIC_LOGOUT_REASON_HEADER } from '../../apiClient/constants';\nimport { emitEvent } from '../../clientEvents';\nimport { fetchProjectSettings } from '../../projectSettings/fetchProjectSettings';\nimport { isCookieEnabled } from '../../projectSettings/isCookieEnabled';\nimport { generateSessionKeys } from '../../sessionKeys/generateSessionKeys';\nimport { destroyWalletProviders } from '../../wallets/destroyWalletProviders';\nimport { DYNAMIC_AUTH_COOKIE_NAME } from '../consts';\nimport type { LogoutReason } from '../logoutReason';\n\n/**\n * Logs the user out with an explicit reason.\n *\n * Revokes the session, clears auth state, terminates wallet providers, and\n * emits the `logout` client event with the given reason. The reason is also\n * captured as an argument on the function-instrumentation event, which is\n * how Datadog distinguishes between different logout causes.\n *\n * Use this instead of the public `logout` when triggering a logout from\n * internal or extension code — the caller owns the reason string, so the\n * telemetry correctly attributes *why* the logout happened.\n *\n * @param params - The logout params.\n * @param params.reason - Why the logout is being triggered. Extension authors\n * needing a reason outside the SDK catalog can cast with `as LogoutReason`.\n * @param client - The Dynamic client instance.\n * @instrumented\n */\nexport const logoutWithReason = async (\n { reason }: { reason: LogoutReason },\n client: DynamicClient\n) => {\n const core = getCore(client);\n\n core.logger.debug('[logoutWithReason] Logging out...', { reason });\n\n await destroyWalletProviders({ reason }, client);\n\n if (client.user !== null) {\n // Forward the logout reason so the backend can attribute the revocation in\n // Datadog instead of it being inferred from downstream 401s.\n const apiClient = createApiClient(\n { headers: { [DYNAMIC_LOGOUT_REASON_HEADER]: reason } },\n client\n );\n\n try {\n await apiClient.revokeSession({\n environmentId: core.environmentId,\n });\n } catch (error) {\n core.logger.error('Failed to revoke session', error);\n }\n\n /**\n * This deletes the auth cookie if it exists.\n * If the cookie doesn't exist, this sets a new cookie that expires immediately.\n */\n if (isCookieEnabled(client)) {\n // Match the Secure attribute used when the cookie was written so the\n // deletion cookie is accepted consistently in a secure context.\n const secureAttribute = getSecureCookieAttribute();\n\n setCookie(\n `${DYNAMIC_AUTH_COOKIE_NAME}=; Max-Age=-99999999; path=/; SameSite=Lax${secureAttribute}`\n );\n }\n }\n\n await core.keychain.removeKey('session');\n\n core.state.set({\n captchaToken: null,\n elevatedAccessTokens: [],\n legacyToken: null,\n mfaToken: null,\n sessionExpiresAt: null,\n sessionKeys: null,\n token: null,\n unverifiedWalletAccounts: [],\n user: null,\n });\n\n emitEvent({ args: { reason }, event: 'logout' }, client);\n\n // Refetch project settings\n void fetchProjectSettings(client);\n\n // Regenerate session keys\n void generateSessionKeys(client);\n};\n","import type { DynamicClient } from '../../../../client/types/DynamicClient';\nimport type { WalletAccount } from '../../walletAccount';\n\ntype GetVerifiedCredentialForWalletAccountParams = {\n walletAccount: WalletAccount;\n};\n\n/** @notInstrumented */\nexport const getVerifiedCredentialForWalletAccount = (\n { walletAccount }: GetVerifiedCredentialForWalletAccountParams,\n client: DynamicClient\n) => {\n return client.user?.verifiedCredentials.find(\n (vc) => vc.id === walletAccount.verifiedCredentialId\n );\n};\n","import type { DynamicClient } from '../../../client/types';\nimport { NoWalletProviderFoundError } from '../../../errors/NoWalletProviderFoundError';\nimport { getWalletProviders } from '../getWalletProviders';\n\ntype GetWalletProviderByKeyParams = {\n walletProviderKey: string;\n};\n\n/** @notInstrumented */\nexport const getWalletProviderByKey = (\n { walletProviderKey }: GetWalletProviderByKeyParams,\n client: DynamicClient\n) => {\n const walletProviders = getWalletProviders(client);\n\n const walletProvider = walletProviders.find(\n (walletProvider) => walletProvider.key === walletProviderKey\n );\n\n if (!walletProvider) {\n throw new NoWalletProviderFoundError({ walletProviderKey });\n }\n\n return walletProvider;\n};\n"],"mappings":"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"}
@@ -1,4 +1,4 @@
1
- const require_updateAuthFromVerifyResponse = require('./updateAuthFromVerifyResponse-ChnvPY0m.cjs');
1
+ const require_updateAuthFromVerifyResponse = require('./updateAuthFromVerifyResponse-BSORoVT0.cjs');
2
2
 
3
3
  //#region src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.ts
4
4
  /** @notInstrumented */
@@ -28,4 +28,4 @@ Object.defineProperty(exports, 'getWalletProviderByKey', {
28
28
  return getWalletProviderByKey;
29
29
  }
30
30
  });
31
- //# sourceMappingURL=getWalletProviderByKey--K4N2u-M.cjs.map
31
+ //# sourceMappingURL=getWalletProviderByKey-D2ElEmJR.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getWalletProviderByKey--K4N2u-M.cjs","names":["getWalletProviders","walletProvider","NoWalletProviderFoundError"],"sources":["../src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.ts","../src/modules/wallets/getWalletProviderByKey/getWalletProviderByKey.ts"],"sourcesContent":["import type { DynamicClient } from '../../../../client/types/DynamicClient';\nimport type { WalletAccount } from '../../walletAccount';\n\ntype GetVerifiedCredentialForWalletAccountParams = {\n walletAccount: WalletAccount;\n};\n\n/** @notInstrumented */\nexport const getVerifiedCredentialForWalletAccount = (\n { walletAccount }: GetVerifiedCredentialForWalletAccountParams,\n client: DynamicClient\n) => {\n return client.user?.verifiedCredentials.find(\n (vc) => vc.id === walletAccount.verifiedCredentialId\n );\n};\n","import type { DynamicClient } from '../../../client/types';\nimport { NoWalletProviderFoundError } from '../../../errors/NoWalletProviderFoundError';\nimport { getWalletProviders } from '../getWalletProviders';\n\ntype GetWalletProviderByKeyParams = {\n walletProviderKey: string;\n};\n\n/** @notInstrumented */\nexport const getWalletProviderByKey = (\n { walletProviderKey }: GetWalletProviderByKeyParams,\n client: DynamicClient\n) => {\n const walletProviders = getWalletProviders(client);\n\n const walletProvider = walletProviders.find(\n (walletProvider) => walletProvider.key === walletProviderKey\n );\n\n if (!walletProvider) {\n throw new NoWalletProviderFoundError({ walletProviderKey });\n }\n\n return walletProvider;\n};\n"],"mappings":";;;;AAQA,MAAa,yCACX,EAAE,iBACF,WACG;AACH,QAAO,OAAO,MAAM,oBAAoB,MACrC,OAAO,GAAG,OAAO,cAAc,qBACjC;;;;;;ACLH,MAAa,0BACX,EAAE,qBACF,WACG;CAGH,MAAM,iBAFkBA,wDAAmB,OAAO,CAEX,MACpC,qBAAmBC,iBAAe,QAAQ,kBAC5C;AAED,KAAI,CAAC,eACH,OAAM,IAAIC,gEAA2B,EAAE,mBAAmB,CAAC;AAG7D,QAAO"}
1
+ {"version":3,"file":"getWalletProviderByKey-D2ElEmJR.cjs","names":["getWalletProviders","walletProvider","NoWalletProviderFoundError"],"sources":["../src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.ts","../src/modules/wallets/getWalletProviderByKey/getWalletProviderByKey.ts"],"sourcesContent":["import type { DynamicClient } from '../../../../client/types/DynamicClient';\nimport type { WalletAccount } from '../../walletAccount';\n\ntype GetVerifiedCredentialForWalletAccountParams = {\n walletAccount: WalletAccount;\n};\n\n/** @notInstrumented */\nexport const getVerifiedCredentialForWalletAccount = (\n { walletAccount }: GetVerifiedCredentialForWalletAccountParams,\n client: DynamicClient\n) => {\n return client.user?.verifiedCredentials.find(\n (vc) => vc.id === walletAccount.verifiedCredentialId\n );\n};\n","import type { DynamicClient } from '../../../client/types';\nimport { NoWalletProviderFoundError } from '../../../errors/NoWalletProviderFoundError';\nimport { getWalletProviders } from '../getWalletProviders';\n\ntype GetWalletProviderByKeyParams = {\n walletProviderKey: string;\n};\n\n/** @notInstrumented */\nexport const getWalletProviderByKey = (\n { walletProviderKey }: GetWalletProviderByKeyParams,\n client: DynamicClient\n) => {\n const walletProviders = getWalletProviders(client);\n\n const walletProvider = walletProviders.find(\n (walletProvider) => walletProvider.key === walletProviderKey\n );\n\n if (!walletProvider) {\n throw new NoWalletProviderFoundError({ walletProviderKey });\n }\n\n return walletProvider;\n};\n"],"mappings":";;;;AAQA,MAAa,yCACX,EAAE,iBACF,WACG;AACH,QAAO,OAAO,MAAM,oBAAoB,MACrC,OAAO,GAAG,OAAO,cAAc,qBACjC;;;;;;ACLH,MAAa,0BACX,EAAE,qBACF,WACG;CAGH,MAAM,iBAFkBA,wDAAmB,OAAO,CAEX,MACpC,qBAAmBC,iBAAe,QAAQ,kBAC5C;AAED,KAAI,CAAC,eACH,OAAM,IAAIC,gEAA2B,EAAE,mBAAmB,CAAC;AAG7D,QAAO"}
package/dist/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
- const require_updateAuthFromVerifyResponse = require('./updateAuthFromVerifyResponse-ChnvPY0m.cjs');
2
- const require_getNetworkProviderFromNetworkId = require('./getNetworkProviderFromNetworkId-DPFHY3b8.cjs');
3
- const require_isDynamicWaasEnabled = require('./isDynamicWaasEnabled-MtEVK3ov.cjs');
4
- const require_isUserOnboardingComplete = require('./isUserOnboardingComplete-D1hw1c5_.cjs');
5
- const require_getWalletProviderByKey = require('./getWalletProviderByKey--K4N2u-M.cjs');
6
- const require_isMfaRequiredForAction = require('./isMfaRequiredForAction-BiPVqg49.cjs');
1
+ const require_updateAuthFromVerifyResponse = require('./updateAuthFromVerifyResponse-BSORoVT0.cjs');
2
+ const require_getNetworkProviderFromNetworkId = require('./getNetworkProviderFromNetworkId-CZjFA5G8.cjs');
3
+ const require_isDynamicWaasEnabled = require('./isDynamicWaasEnabled-B7_FiTkx.cjs');
4
+ const require_isUserOnboardingComplete = require('./isUserOnboardingComplete-Dnx30meW.cjs');
5
+ const require_getWalletProviderByKey = require('./getWalletProviderByKey-D2ElEmJR.cjs');
6
+ const require_isMfaRequiredForAction = require('./isMfaRequiredForAction-B3FO4Zbn.cjs');
7
7
  let _dynamic_labs_sdk_assert_package_version = require("@dynamic-labs-sdk/assert-package-version");
8
8
  let _dynamic_labs_sdk_api_core = require("@dynamic-labs/sdk-api-core");
9
9
  let zod_mini = require("zod/mini");
@@ -764,62 +764,6 @@ const createNavigationHandler = () => {
764
764
  };
765
765
  };
766
766
 
767
- //#endregion
768
- //#region src/errors/UnsafeDeeplinkUrlError.ts
769
- /**
770
- * Thrown when a deeplink is opened with a URL whose scheme can execute script
771
- * in the current origin (`javascript:`, `data:`, `vbscript:`). Unlike
772
- * navigation, deeplinks legitimately use custom app schemes (e.g. `phantom:`,
773
- * `metamask:`), so this guards via a denylist of dangerous schemes rather than
774
- * an `http(s)` allowlist, preventing DOM XSS through the `window.location.assign`
775
- * sink while leaving valid wallet deeplinks untouched.
776
- */
777
- var UnsafeDeeplinkUrlError = class extends require_updateAuthFromVerifyResponse.BaseError {
778
- constructor({ scheme }) {
779
- super({
780
- cause: null,
781
- code: "unsafe_deeplink_url_error",
782
- docsUrl: null,
783
- name: "UnsafeDeeplinkUrlError",
784
- shortMessage: `Refusing to open a deeplink with an unsafe scheme "${scheme}". Script-executing schemes (javascript:, data:, vbscript:) are not allowed. This may indicate a compromised or misconfigured deeplink URL.`
785
- });
786
- }
787
- };
788
-
789
- //#endregion
790
- //#region src/utils/assertSafeDeeplinkUrl/assertSafeDeeplinkUrl.ts
791
- /**
792
- * Schemes that can execute script in the current origin and must never reach a
793
- * deeplink navigation sink. Deeplinks legitimately use arbitrary custom app
794
- * schemes (e.g. `phantom:`, `metamask:`), so a denylist of dangerous schemes is
795
- * used here instead of the `http(s)` allowlist applied to standard navigation.
796
- */
797
- const DANGEROUS_DEEPLINK_SCHEMES = new Set([
798
- "javascript:",
799
- "data:",
800
- "vbscript:",
801
- "blob:"
802
- ]);
803
- /**
804
- * Asserts that the given deeplink URL is safe to open, i.e. its scheme is not
805
- * one that can execute script (`javascript:`, `data:`, `vbscript:`, `blob:`). Used as a
806
- * defense-in-depth guard on the `window.location.assign` deeplink sink to
807
- * prevent DOM XSS, while still permitting custom wallet app schemes.
808
- *
809
- * @param url - The deeplink URL string to validate.
810
- * @throws {UnsafeDeeplinkUrlError} If the URL cannot be parsed or its scheme can execute script.
811
- * @notInstrumented
812
- */
813
- const assertSafeDeeplinkUrl = (url) => {
814
- let parsed;
815
- try {
816
- parsed = new URL(url);
817
- } catch {
818
- throw new UnsafeDeeplinkUrlError({ scheme: "unknown" });
819
- }
820
- if (DANGEROUS_DEEPLINK_SCHEMES.has(parsed.protocol)) throw new UnsafeDeeplinkUrlError({ scheme: parsed.protocol });
821
- };
822
-
823
767
  //#endregion
824
768
  //#region src/services/openDeeplink/createWebDeeplinkOpener/createWebDeeplinkOpener.ts
825
769
  /**
@@ -839,7 +783,7 @@ const assertSafeDeeplinkUrl = (url) => {
839
783
  const createWebDeeplinkOpener = () => {
840
784
  if (require_getNetworkProviderFromNetworkId.isServerSideRendering()) return () => Promise.reject(new require_getNetworkProviderFromNetworkId.UnavailableInServerSideError("createWebDeeplinkOpener"));
841
785
  return async (url) => {
842
- assertSafeDeeplinkUrl(url);
786
+ require_getNetworkProviderFromNetworkId.assertSafeDeeplinkUrl(url);
843
787
  window.location.assign(url);
844
788
  };
845
789
  };
@@ -3901,8 +3845,8 @@ const prepareFlowSigning = async ({ assertBalanceForGasCost, assertBalanceForTra
3901
3845
  environmentId,
3902
3846
  flowId,
3903
3847
  flowPrepareSigningRequest: {
3904
- assertBalanceForGasCost: assertBalanceForGasCost ?? false,
3905
- assertBalanceForTransferAmount: assertBalanceForTransferAmount ?? false
3848
+ assertBalanceForGasCost: assertBalanceForGasCost ?? true,
3849
+ assertBalanceForTransferAmount: assertBalanceForTransferAmount ?? true
3906
3850
  },
3907
3851
  xDynamicFlowSessionToken: sessionToken
3908
3852
  }),
@@ -8159,7 +8103,13 @@ const isSameAddress = ({ chain, left, right }) => require_updateAuthFromVerifyRe
8159
8103
  //#region src/modules/wallets/verifyWalletAccountForSignInOrTransfer/verifyWalletAccountForSignInOrTransfer.ts
8160
8104
  /** @notInstrumented */
8161
8105
  const verifyWalletAccountForSignInOrTransfer = async ({ walletAccount, isTransfer, requestedScopes }, client) => {
8162
- if (walletAccount.verifiedCredentialId) throw new WalletAccountAlreadyVerifiedError(walletAccount.address);
8106
+ /**
8107
+ * A wallet that is already verified can still be used for step-up
8108
+ * authentication: the user proves ownership again to mint an elevated
8109
+ * access token for the requested scope. Skip the already-verified guard
8110
+ * when scopes are provided so the call reaches walletsVerify.
8111
+ */
8112
+ if (walletAccount.verifiedCredentialId && !requestedScopes) throw new WalletAccountAlreadyVerifiedError(walletAccount.address);
8163
8113
  const walletProvider = require_updateAuthFromVerifyResponse.getWalletProviderFromWalletAccount({ walletAccount }, client);
8164
8114
  const { messageToSign, signature } = await __proveWalletAccountOwnership_wrapped({ walletAccount }, client);
8165
8115
  const formattedSignature = walletAccount.hardwareWalletVendor ? formatSignatureForHardwareWallet({
@@ -8228,7 +8178,7 @@ const verifyWalletAccountForSignInOrTransfer = async ({ walletAccount, isTransfe
8228
8178
  * @param [params.requestedScopes] - Optional token scopes to request during verification.
8229
8179
  * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
8230
8180
  * @returns A promise that resolves to the verified wallet account.
8231
- * @throws WalletAccountAlreadyVerifiedError If the wallet is already verified.
8181
+ * @throws WalletAccountAlreadyVerifiedError If the wallet is already verified and no requestedScopes are provided.
8232
8182
  * @throws WalletAlreadyLinkedToAnotherUserError If the wallet is linked to another user.
8233
8183
  * @see connectWithWalletProvider
8234
8184
  * @see connectAndVerifyWithWalletProvider