@dynamic-labs-sdk/client 1.23.0 → 1.23.1

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 (102) hide show
  1. package/dist/{NativeModuleNotLinkedError-DIpQjh_K.native.esm.js → NativeModuleNotLinkedError-DLP1hpcM.native.esm.js} +3 -3
  2. package/dist/{NativeModuleNotLinkedError-DIpQjh_K.native.esm.js.map → NativeModuleNotLinkedError-DLP1hpcM.native.esm.js.map} +1 -1
  3. package/dist/{consumeMfaTokenIfRequiredForAction-jsAdDyDj.esm.js → consumeMfaTokenIfRequiredForAction-D2oiQdpj.esm.js} +2 -2
  4. package/dist/{consumeMfaTokenIfRequiredForAction-jsAdDyDj.esm.js.map → consumeMfaTokenIfRequiredForAction-D2oiQdpj.esm.js.map} +1 -1
  5. package/dist/{consumeMfaTokenIfRequiredForAction-pUcqlY3s.cjs → consumeMfaTokenIfRequiredForAction-DJAdtHe3.cjs} +2 -2
  6. package/dist/{consumeMfaTokenIfRequiredForAction-pUcqlY3s.cjs.map → consumeMfaTokenIfRequiredForAction-DJAdtHe3.cjs.map} +1 -1
  7. package/dist/core.cjs +6 -6
  8. package/dist/core.esm.js +8 -8
  9. package/dist/core.esm.js.map +1 -1
  10. package/dist/core.native.esm.js +5 -5
  11. package/dist/exports/waas.d.ts +1 -0
  12. package/dist/exports/waas.d.ts.map +1 -1
  13. package/dist/{getNetworkProviderFromNetworkId-DPFHY3b8.cjs → getNetworkProviderFromNetworkId-BVP0ghId.cjs} +2 -2
  14. package/dist/{getNetworkProviderFromNetworkId-DPFHY3b8.cjs.map → getNetworkProviderFromNetworkId-BVP0ghId.cjs.map} +1 -1
  15. package/dist/{getNetworkProviderFromNetworkId-YcalZlDG.native.esm.js → getNetworkProviderFromNetworkId-Bh4_-rhf.native.esm.js} +3 -261
  16. package/dist/getNetworkProviderFromNetworkId-Bh4_-rhf.native.esm.js.map +1 -0
  17. package/dist/{getNetworkProviderFromNetworkId-DTNPpR5H.esm.js → getNetworkProviderFromNetworkId-OfuaqHXU.esm.js} +6 -6
  18. package/dist/getNetworkProviderFromNetworkId-OfuaqHXU.esm.js.map +1 -0
  19. package/dist/{getSignedSessionId-BjhgfsJD.native.esm.js → getSignedSessionId-2jmv21__.native.esm.js} +3 -3
  20. package/dist/{getSignedSessionId-BjhgfsJD.native.esm.js.map → getSignedSessionId-2jmv21__.native.esm.js.map} +1 -1
  21. package/dist/{getSignedSessionId-Btl5p_7b.esm.js → getSignedSessionId-CDEQ6TMC.esm.js} +2 -2
  22. package/dist/{getSignedSessionId-Btl5p_7b.esm.js.map → getSignedSessionId-CDEQ6TMC.esm.js.map} +1 -1
  23. package/dist/{getSignedSessionId-VX7LkxVJ.cjs → getSignedSessionId-_ZPqzvm5.cjs} +2 -2
  24. package/dist/{getSignedSessionId-VX7LkxVJ.cjs.map → getSignedSessionId-_ZPqzvm5.cjs.map} +1 -1
  25. package/dist/getWalletProviderByKey-0VBVdu30.native.esm.js +279 -0
  26. package/dist/getWalletProviderByKey-0VBVdu30.native.esm.js.map +1 -0
  27. package/dist/{getWalletProviderByKey-5sZK6kAJ.esm.js → getWalletProviderByKey-BIHCI8S6.esm.js} +2 -2
  28. package/dist/{getWalletProviderByKey-5sZK6kAJ.esm.js.map → getWalletProviderByKey-BIHCI8S6.esm.js.map} +1 -1
  29. package/dist/{getWalletProviderByKey--K4N2u-M.cjs → getWalletProviderByKey-F5wxlC_k.cjs} +2 -2
  30. package/dist/{getWalletProviderByKey--K4N2u-M.cjs.map → getWalletProviderByKey-F5wxlC_k.cjs.map} +1 -1
  31. package/dist/index.cjs +14 -8
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.esm.js +17 -11
  34. package/dist/index.esm.js.map +1 -1
  35. package/dist/index.native.esm.js +14 -8
  36. package/dist/index.native.esm.js.map +1 -1
  37. package/dist/{isDynamicWaasEnabled-sI3vpWvA.esm.js → isDynamicWaasEnabled-OlDJAGIi.esm.js} +2 -2
  38. package/dist/{isDynamicWaasEnabled-sI3vpWvA.esm.js.map → isDynamicWaasEnabled-OlDJAGIi.esm.js.map} +1 -1
  39. package/dist/{isDynamicWaasEnabled-MtEVK3ov.cjs → isDynamicWaasEnabled-YigU-EAT.cjs} +2 -2
  40. package/dist/{isDynamicWaasEnabled-MtEVK3ov.cjs.map → isDynamicWaasEnabled-YigU-EAT.cjs.map} +1 -1
  41. package/dist/{isDynamicWaasEnabled-BR_pG4jM.native.esm.js → isDynamicWaasEnabled-cVxCp5BV.native.esm.js} +2 -2
  42. package/dist/{isDynamicWaasEnabled-BR_pG4jM.native.esm.js.map → isDynamicWaasEnabled-cVxCp5BV.native.esm.js.map} +1 -1
  43. package/dist/{isMfaRequiredForAction-DJ2UX11y.esm.js → isMfaRequiredForAction-Bn2HCYvZ.esm.js} +2 -2
  44. package/dist/{isMfaRequiredForAction-DJ2UX11y.esm.js.map → isMfaRequiredForAction-Bn2HCYvZ.esm.js.map} +1 -1
  45. package/dist/{isMfaRequiredForAction-BiPVqg49.cjs → isMfaRequiredForAction-BtPXuiSY.cjs} +2 -2
  46. package/dist/{isMfaRequiredForAction-BiPVqg49.cjs.map → isMfaRequiredForAction-BtPXuiSY.cjs.map} +1 -1
  47. package/dist/{isMfaRequiredForAction-GWZny7T2.native.esm.js → isMfaRequiredForAction-DjC0wQJ4.native.esm.js} +2 -2
  48. package/dist/{isMfaRequiredForAction-GWZny7T2.native.esm.js.map → isMfaRequiredForAction-DjC0wQJ4.native.esm.js.map} +1 -1
  49. package/dist/{isUserOnboardingComplete-Hzz6fwTk.native.esm.js → isUserOnboardingComplete-BCZpska8.native.esm.js} +3 -3
  50. package/dist/{isUserOnboardingComplete-Hzz6fwTk.native.esm.js.map → isUserOnboardingComplete-BCZpska8.native.esm.js.map} +1 -1
  51. package/dist/{isUserOnboardingComplete-D1hw1c5_.cjs → isUserOnboardingComplete-Bi7tw1lk.cjs} +3 -3
  52. package/dist/{isUserOnboardingComplete-D1hw1c5_.cjs.map → isUserOnboardingComplete-Bi7tw1lk.cjs.map} +1 -1
  53. package/dist/{isUserOnboardingComplete-OvzVH1rg.esm.js → isUserOnboardingComplete-DScTOOg_.esm.js} +3 -3
  54. package/dist/{isUserOnboardingComplete-OvzVH1rg.esm.js.map → isUserOnboardingComplete-DScTOOg_.esm.js.map} +1 -1
  55. package/dist/{migrateFromFireblocks-BiLoNIkA.native.esm.js → migrateFromFireblocks-7aKNa_3P.native.esm.js} +3 -3
  56. package/dist/{migrateFromFireblocks-BiLoNIkA.native.esm.js.map → migrateFromFireblocks-7aKNa_3P.native.esm.js.map} +1 -1
  57. package/dist/{migrateFromFireblocks-NRfLh1JL.cjs → migrateFromFireblocks-BnHU2AZJ.cjs} +4 -4
  58. package/dist/{migrateFromFireblocks-NRfLh1JL.cjs.map → migrateFromFireblocks-BnHU2AZJ.cjs.map} +1 -1
  59. package/dist/{migrateFromFireblocks-Y5pPtmew.esm.js → migrateFromFireblocks-DkQj3aYU.esm.js} +4 -4
  60. package/dist/{migrateFromFireblocks-Y5pPtmew.esm.js.map → migrateFromFireblocks-DkQj3aYU.esm.js.map} +1 -1
  61. package/dist/modules/auth/getActionAuthorizationTokens/getActionAuthorizationTokens.d.ts +29 -0
  62. package/dist/modules/auth/getActionAuthorizationTokens/getActionAuthorizationTokens.d.ts.map +1 -0
  63. package/dist/modules/auth/getActionAuthorizationTokens/index.d.ts +2 -0
  64. package/dist/modules/auth/getActionAuthorizationTokens/index.d.ts.map +1 -0
  65. package/dist/modules/auth/logoutReason.d.ts +1 -1
  66. package/dist/modules/auth/logoutReason.d.ts.map +1 -1
  67. package/dist/modules/waas/businessAccounts/addBusinessAccountMember/addBusinessAccountMember.d.ts +7 -2
  68. package/dist/modules/waas/businessAccounts/addBusinessAccountMember/addBusinessAccountMember.d.ts.map +1 -1
  69. package/dist/modules/waas/businessAccounts/addWalletToBusinessAccount/addWalletToBusinessAccount.d.ts +6 -1
  70. package/dist/modules/waas/businessAccounts/addWalletToBusinessAccount/addWalletToBusinessAccount.d.ts.map +1 -1
  71. package/dist/modules/waas/businessAccounts/businessAccounts.constants.d.ts +5 -0
  72. package/dist/modules/waas/businessAccounts/businessAccounts.constants.d.ts.map +1 -0
  73. package/dist/modules/waas/businessAccounts/transferBusinessAccountOwnership/transferBusinessAccountOwnership.d.ts.map +1 -1
  74. package/dist/modules/waas/businessAccounts/updateBusinessAccount/index.d.ts +2 -0
  75. package/dist/modules/waas/businessAccounts/updateBusinessAccount/index.d.ts.map +1 -0
  76. package/dist/modules/waas/businessAccounts/updateBusinessAccount/updateBusinessAccount.d.ts +26 -0
  77. package/dist/modules/waas/businessAccounts/updateBusinessAccount/updateBusinessAccount.d.ts.map +1 -0
  78. package/dist/modules/waas/createWaasProvider/createWaasProvider.d.ts.map +1 -1
  79. package/dist/modules/wallets/verifyWalletAccount/verifyWalletAccount.d.ts +1 -1
  80. package/dist/modules/wallets/verifyWalletAccountForSignInOrTransfer/verifyWalletAccountForSignInOrTransfer.d.ts.map +1 -1
  81. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  82. package/dist/{updateAuthFromVerifyResponse-ChnvPY0m.cjs → updateAuthFromVerifyResponse-B2QePeNz.cjs} +3 -3
  83. package/dist/{updateAuthFromVerifyResponse-ChnvPY0m.cjs.map → updateAuthFromVerifyResponse-B2QePeNz.cjs.map} +1 -1
  84. package/dist/{updateAuthFromVerifyResponse-Ct1Y6O_T.esm.js → updateAuthFromVerifyResponse-wHGRunTk.esm.js} +3 -3
  85. package/dist/{updateAuthFromVerifyResponse-Ct1Y6O_T.esm.js.map → updateAuthFromVerifyResponse-wHGRunTk.esm.js.map} +1 -1
  86. package/dist/waas.cjs +87 -30
  87. package/dist/waas.cjs.map +1 -1
  88. package/dist/waas.esm.js +88 -32
  89. package/dist/waas.esm.js.map +1 -1
  90. package/dist/waas.native.esm.js +87 -31
  91. package/dist/waas.native.esm.js.map +1 -1
  92. package/dist/waasCore.cjs +53 -15
  93. package/dist/waasCore.cjs.map +1 -1
  94. package/dist/waasCore.esm.js +53 -15
  95. package/dist/waasCore.esm.js.map +1 -1
  96. package/dist/waasCore.native.esm.js +52 -14
  97. package/dist/waasCore.native.esm.js.map +1 -1
  98. package/package.json +3 -3
  99. package/dist/getNetworkProviderFromNetworkId-DTNPpR5H.esm.js.map +0 -1
  100. package/dist/getNetworkProviderFromNetworkId-YcalZlDG.native.esm.js.map +0 -1
  101. package/dist/getWalletProviderByKey-BhcBoGMW.native.esm.js +0 -20
  102. package/dist/getWalletProviderByKey-BhcBoGMW.native.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-DLP1hpcM.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-0VBVdu30.native.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getWalletProviderByKey-0VBVdu30.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 === walletProvider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1
- import { D as NoWalletProviderFoundError, f as getWalletProviders } from "./updateAuthFromVerifyResponse-Ct1Y6O_T.esm.js";
1
+ import { D as NoWalletProviderFoundError, f as getWalletProviders } from "./updateAuthFromVerifyResponse-wHGRunTk.esm.js";
2
2
 
3
3
  //#region src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.ts
4
4
  /** @notInstrumented */
@@ -17,4 +17,4 @@ const getWalletProviderByKey = ({ walletProviderKey }, client) => {
17
17
 
18
18
  //#endregion
19
19
  export { getVerifiedCredentialForWalletAccount as n, getWalletProviderByKey as t };
20
- //# sourceMappingURL=getWalletProviderByKey-5sZK6kAJ.esm.js.map
20
+ //# sourceMappingURL=getWalletProviderByKey-BIHCI8S6.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getWalletProviderByKey-5sZK6kAJ.esm.js","names":["walletProvider"],"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,iBAFkB,mBAAmB,OAAO,CAEX,MACpC,qBAAmBA,iBAAe,QAAQ,kBAC5C;AAED,KAAI,CAAC,eACH,OAAM,IAAI,2BAA2B,EAAE,mBAAmB,CAAC;AAG7D,QAAO"}
1
+ {"version":3,"file":"getWalletProviderByKey-BIHCI8S6.esm.js","names":["walletProvider"],"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,iBAFkB,mBAAmB,OAAO,CAEX,MACpC,qBAAmBA,iBAAe,QAAQ,kBAC5C;AAED,KAAI,CAAC,eACH,OAAM,IAAI,2BAA2B,EAAE,mBAAmB,CAAC;AAG7D,QAAO"}
@@ -1,4 +1,4 @@
1
- const require_updateAuthFromVerifyResponse = require('./updateAuthFromVerifyResponse-ChnvPY0m.cjs');
1
+ const require_updateAuthFromVerifyResponse = require('./updateAuthFromVerifyResponse-B2QePeNz.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-F5wxlC_k.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-F5wxlC_k.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-B2QePeNz.cjs');
2
+ const require_getNetworkProviderFromNetworkId = require('./getNetworkProviderFromNetworkId-BVP0ghId.cjs');
3
+ const require_isDynamicWaasEnabled = require('./isDynamicWaasEnabled-YigU-EAT.cjs');
4
+ const require_isUserOnboardingComplete = require('./isUserOnboardingComplete-Bi7tw1lk.cjs');
5
+ const require_getWalletProviderByKey = require('./getWalletProviderByKey-F5wxlC_k.cjs');
6
+ const require_isMfaRequiredForAction = require('./isMfaRequiredForAction-BtPXuiSY.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");
@@ -8159,7 +8159,13 @@ const isSameAddress = ({ chain, left, right }) => require_updateAuthFromVerifyRe
8159
8159
  //#region src/modules/wallets/verifyWalletAccountForSignInOrTransfer/verifyWalletAccountForSignInOrTransfer.ts
8160
8160
  /** @notInstrumented */
8161
8161
  const verifyWalletAccountForSignInOrTransfer = async ({ walletAccount, isTransfer, requestedScopes }, client) => {
8162
- if (walletAccount.verifiedCredentialId) throw new WalletAccountAlreadyVerifiedError(walletAccount.address);
8162
+ /**
8163
+ * A wallet that is already verified can still be used for step-up
8164
+ * authentication: the user proves ownership again to mint an elevated
8165
+ * access token for the requested scope. Skip the already-verified guard
8166
+ * when scopes are provided so the call reaches walletsVerify.
8167
+ */
8168
+ if (walletAccount.verifiedCredentialId && !requestedScopes) throw new WalletAccountAlreadyVerifiedError(walletAccount.address);
8163
8169
  const walletProvider = require_updateAuthFromVerifyResponse.getWalletProviderFromWalletAccount({ walletAccount }, client);
8164
8170
  const { messageToSign, signature } = await __proveWalletAccountOwnership_wrapped({ walletAccount }, client);
8165
8171
  const formattedSignature = walletAccount.hardwareWalletVendor ? formatSignatureForHardwareWallet({
@@ -8228,7 +8234,7 @@ const verifyWalletAccountForSignInOrTransfer = async ({ walletAccount, isTransfe
8228
8234
  * @param [params.requestedScopes] - Optional token scopes to request during verification.
8229
8235
  * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
8230
8236
  * @returns A promise that resolves to the verified wallet account.
8231
- * @throws WalletAccountAlreadyVerifiedError If the wallet is already verified.
8237
+ * @throws WalletAccountAlreadyVerifiedError If the wallet is already verified and no requestedScopes are provided.
8232
8238
  * @throws WalletAlreadyLinkedToAnotherUserError If the wallet is linked to another user.
8233
8239
  * @see connectWithWalletProvider
8234
8240
  * @see connectAndVerifyWithWalletProvider