@dynamic-labs-sdk/client 1.6.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/android/build.gradle +231 -0
  2. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  3. package/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  4. package/android/gradle.properties +8 -0
  5. package/android/gradlew +251 -0
  6. package/android/gradlew.bat +94 -0
  7. package/android/settings.gradle +30 -0
  8. package/android/src/main/java/xyz/dynamic/client/DynamicClientPackage.kt +52 -0
  9. package/android/src/main/java/xyz/dynamic/client/keychain/KeyStoreKeyManager.kt +147 -0
  10. package/android/src/main/java/xyz/dynamic/client/keychain/KeychainModule.kt +85 -0
  11. package/android/src/main/java/xyz/dynamic/client/manifest/ReactNativeManifestModule.kt +25 -0
  12. package/android/src/main/java/xyz/dynamic/client/webview/DynamicWebViewClient.kt +83 -0
  13. package/android/src/main/java/xyz/dynamic/client/webview/DynamicWebViewHost.kt +518 -0
  14. package/android/src/main/java/xyz/dynamic/client/webview/DynamicWebViewModule.kt +147 -0
  15. package/android/src/test/java/xyz/dynamic/client/keychain/KeyStoreKeyManagerTest.kt +288 -0
  16. package/android/src/test/java/xyz/dynamic/client/webview/DynamicWebViewClientTest.kt +196 -0
  17. package/android/src/test/java/xyz/dynamic/client/webview/DynamicWebViewHostOpenTest.kt +347 -0
  18. package/android/src/test/java/xyz/dynamic/client/webview/DynamicWebViewHostTest.kt +171 -0
  19. package/android/src/test/java/xyz/dynamic/client/webview/DynamicWebViewModuleTest.kt +191 -0
  20. package/dist/{InvalidParamError-BIptAjbC.native.esm.js → InvalidParamError-Bc6OZBog.native.esm.js} +91 -829
  21. package/dist/InvalidParamError-Bc6OZBog.native.esm.js.map +1 -0
  22. package/dist/{InvalidParamError-BZ0LHaml.esm.js → InvalidParamError-IHYLdzFd.esm.js} +108 -381
  23. package/dist/InvalidParamError-IHYLdzFd.esm.js.map +1 -0
  24. package/dist/{InvalidParamError-DyXEKMWn.cjs → InvalidParamError-S56rFFDP.cjs} +108 -450
  25. package/dist/InvalidParamError-S56rFFDP.cjs.map +1 -0
  26. package/dist/{NotWaasWalletAccountError-nT4jrLbp.esm.js → NotWaasWalletAccountError-BP-bODbJ.native.esm.js} +4 -4
  27. package/dist/NotWaasWalletAccountError-BP-bODbJ.native.esm.js.map +1 -0
  28. package/dist/{NotWaasWalletAccountError-BbOA5rPd.native.esm.js → NotWaasWalletAccountError-BYEL2l-W.esm.js} +4 -4
  29. package/dist/NotWaasWalletAccountError-BYEL2l-W.esm.js.map +1 -0
  30. package/dist/{NotWaasWalletAccountError-CElqwdQO.cjs → NotWaasWalletAccountError-CbhIKUDM.cjs} +4 -4
  31. package/dist/NotWaasWalletAccountError-CbhIKUDM.cjs.map +1 -0
  32. package/dist/core.cjs +11 -11
  33. package/dist/core.cjs.map +1 -1
  34. package/dist/core.esm.js +5 -5
  35. package/dist/core.native.esm.js +7 -7
  36. package/dist/core.native.esm.js.map +1 -1
  37. package/dist/errors/WebViewLoadFailedError.d.ts +1 -1
  38. package/dist/errors/WebViewLoadFailedError.d.ts.map +1 -1
  39. package/dist/exports/index.d.ts +2 -0
  40. package/dist/exports/index.d.ts.map +1 -1
  41. package/dist/{getNetworkProviderFromNetworkId-DbI5MZhq.cjs → getNetworkProviderFromNetworkId-BDdcpGHH.cjs} +56 -55
  42. package/dist/{getNetworkProviderFromNetworkId-DbI5MZhq.cjs.map → getNetworkProviderFromNetworkId-BDdcpGHH.cjs.map} +1 -1
  43. package/dist/{getNetworkProviderFromNetworkId-BkAPIdRC.esm.js → getNetworkProviderFromNetworkId-D8rWYXlT.esm.js} +54 -54
  44. package/dist/{getNetworkProviderFromNetworkId-BkAPIdRC.esm.js.map → getNetworkProviderFromNetworkId-D8rWYXlT.esm.js.map} +1 -1
  45. package/dist/{getNetworkProviderFromNetworkId-B7DIqT2T.native.esm.js → getNetworkProviderFromNetworkId-DVmF7pH2.native.esm.js} +312 -41
  46. package/dist/getNetworkProviderFromNetworkId-DVmF7pH2.native.esm.js.map +1 -0
  47. package/dist/{getSignedSessionId-BF6n8gve.cjs → getSignedSessionId-BBaBCi9S.cjs} +3 -3
  48. package/dist/{getSignedSessionId-BF6n8gve.cjs.map → getSignedSessionId-BBaBCi9S.cjs.map} +1 -1
  49. package/dist/{getSignedSessionId-y3YtxFHZ.esm.js → getSignedSessionId-CND07Eca.esm.js} +3 -3
  50. package/dist/{getSignedSessionId-y3YtxFHZ.esm.js.map → getSignedSessionId-CND07Eca.esm.js.map} +1 -1
  51. package/dist/{getSignedSessionId-1TV-x__C.native.esm.js → getSignedSessionId-RwV7JPn8.native.esm.js} +3 -3
  52. package/dist/{getSignedSessionId-1TV-x__C.native.esm.js.map → getSignedSessionId-RwV7JPn8.native.esm.js.map} +1 -1
  53. package/dist/getVerifiedCredentialForWalletAccount-BVrGV8qf.native.esm.js +701 -0
  54. package/dist/getVerifiedCredentialForWalletAccount-BVrGV8qf.native.esm.js.map +1 -0
  55. package/dist/{getVerifiedCredentialForWalletAccount-etV50QRH.esm.js → getVerifiedCredentialForWalletAccount-BiOS65Tk.esm.js} +2 -2
  56. package/dist/{getVerifiedCredentialForWalletAccount-etV50QRH.esm.js.map → getVerifiedCredentialForWalletAccount-BiOS65Tk.esm.js.map} +1 -1
  57. package/dist/{getVerifiedCredentialForWalletAccount-BfJ29erz.cjs → getVerifiedCredentialForWalletAccount-FrxYWSuD.cjs} +3 -2
  58. package/dist/{getVerifiedCredentialForWalletAccount-BfJ29erz.cjs.map → getVerifiedCredentialForWalletAccount-FrxYWSuD.cjs.map} +1 -1
  59. package/dist/index.cjs +35 -35
  60. package/dist/index.cjs.map +1 -1
  61. package/dist/index.esm.js +14 -14
  62. package/dist/index.esm.js.map +1 -1
  63. package/dist/index.native.esm.js +14 -14
  64. package/dist/index.native.esm.js.map +1 -1
  65. package/dist/isMfaRequiredForAction-BPL_dgIM.esm.js +318 -0
  66. package/dist/isMfaRequiredForAction-BPL_dgIM.esm.js.map +1 -0
  67. package/dist/isMfaRequiredForAction-BolTrtCO.cjs +405 -0
  68. package/dist/isMfaRequiredForAction-BolTrtCO.cjs.map +1 -0
  69. package/dist/{isMfaRequiredForAction-B2vKX31S.native.esm.js → isMfaRequiredForAction-DQDoPsi6.native.esm.js} +2 -2
  70. package/dist/{isMfaRequiredForAction-B2vKX31S.native.esm.js.map → isMfaRequiredForAction-DQDoPsi6.native.esm.js.map} +1 -1
  71. package/dist/modules/apiClient/apiClient.types.d.ts +0 -12
  72. package/dist/modules/apiClient/apiClient.types.d.ts.map +1 -1
  73. package/dist/modules/apiClient/createApiClient.d.ts.map +1 -1
  74. package/dist/modules/auth/logoutReason.d.ts +1 -1
  75. package/dist/modules/auth/logoutReason.d.ts.map +1 -1
  76. package/dist/modules/auth/logoutWithReason/logoutWithReason.d.ts.map +1 -1
  77. package/dist/modules/deviceRegistration/getRegisteredDevices/getRegisteredDevices.d.ts.map +1 -1
  78. package/dist/modules/user/refreshAuth/refreshAuth.d.ts.map +1 -1
  79. package/dist/modules/waas/backupWaasKeySharesToGoogleDrive/backupWaasKeySharesToGoogleDrive.d.ts +12 -1
  80. package/dist/modules/waas/backupWaasKeySharesToGoogleDrive/backupWaasKeySharesToGoogleDrive.d.ts.map +1 -1
  81. package/dist/modules/waas/createWaasClient/createWaasClient.d.ts.map +1 -1
  82. package/dist/modules/waas/createWaasClient/translateNativeOpenError.d.ts.map +1 -1
  83. package/dist/modules/waas/createWaasProvider/createWaasProvider.d.ts.map +1 -1
  84. package/dist/modules/waas/waas.types.d.ts +1 -0
  85. package/dist/modules/waas/waas.types.d.ts.map +1 -1
  86. package/dist/modules/wallets/walletProvider/events/onWalletProviderEvent/onWalletProviderEvent.d.ts +1 -2
  87. package/dist/modules/wallets/walletProvider/events/onWalletProviderEvent/onWalletProviderEvent.d.ts.map +1 -1
  88. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  89. package/dist/waas.cjs +7 -4
  90. package/dist/waas.cjs.map +1 -1
  91. package/dist/waas.esm.js +6 -4
  92. package/dist/waas.esm.js.map +1 -1
  93. package/dist/waas.native.esm.js +6 -4
  94. package/dist/waas.native.esm.js.map +1 -1
  95. package/dist/waasCore.cjs +10 -5
  96. package/dist/waasCore.cjs.map +1 -1
  97. package/dist/waasCore.esm.js +10 -5
  98. package/dist/waasCore.esm.js.map +1 -1
  99. package/dist/waasCore.native.esm.js +10 -8
  100. package/dist/waasCore.native.esm.js.map +1 -1
  101. package/dynamic-labs-sdk-client.podspec +27 -0
  102. package/ios/DynamicClientKeychain.h +4 -0
  103. package/ios/DynamicClientKeychain.mm +101 -0
  104. package/ios/DynamicClientManifest.h +4 -0
  105. package/ios/DynamicClientManifest.mm +45 -0
  106. package/ios/DynamicClientWebView.h +5 -0
  107. package/ios/DynamicClientWebView.mm +143 -0
  108. package/ios/DynamicWebViewImpl.swift +603 -0
  109. package/ios/LiveSecKeyAPI.swift +86 -0
  110. package/ios/ReactNativeManifestImpl.swift +20 -0
  111. package/ios/SecKeyAPI.swift +57 -0
  112. package/ios/SecureEnclaveKeyManager.swift +191 -0
  113. package/package.json +16 -5
  114. package/react-native.config.cjs +14 -0
  115. package/src/turboModules/NativeDynamicWebView.native.spec.ts +61 -0
  116. package/src/turboModules/NativeDynamicWebView.ts +40 -0
  117. package/src/turboModules/NativeKeychain.native.spec.ts +47 -0
  118. package/src/turboModules/NativeKeychain.ts +19 -0
  119. package/src/turboModules/NativeReactNativeManifest.native.spec.ts +55 -0
  120. package/src/turboModules/NativeReactNativeManifest.ts +28 -0
  121. package/dist/InvalidParamError-BIptAjbC.native.esm.js.map +0 -1
  122. package/dist/InvalidParamError-BZ0LHaml.esm.js.map +0 -1
  123. package/dist/InvalidParamError-DyXEKMWn.cjs.map +0 -1
  124. package/dist/NotWaasWalletAccountError-BbOA5rPd.native.esm.js.map +0 -1
  125. package/dist/NotWaasWalletAccountError-CElqwdQO.cjs.map +0 -1
  126. package/dist/NotWaasWalletAccountError-nT4jrLbp.esm.js.map +0 -1
  127. package/dist/getNetworkProviderFromNetworkId-B7DIqT2T.native.esm.js.map +0 -1
  128. package/dist/getVerifiedCredentialForWalletAccount-CLyC2nOl.native.esm.js +0 -269
  129. package/dist/getVerifiedCredentialForWalletAccount-CLyC2nOl.native.esm.js.map +0 -1
  130. package/dist/isMfaRequiredForAction-Dy4-S3mr.esm.js +0 -79
  131. package/dist/isMfaRequiredForAction-Dy4-S3mr.esm.js.map +0 -1
  132. package/dist/isMfaRequiredForAction-K2Jh-3-j.cjs +0 -96
  133. package/dist/isMfaRequiredForAction-K2Jh-3-j.cjs.map +0 -1
  134. package/dist/modules/apiClient/utils/sessionExpiryLogoutMiddleware/createSessionExpiryLogoutMiddleware.d.ts +0 -27
  135. package/dist/modules/apiClient/utils/sessionExpiryLogoutMiddleware/createSessionExpiryLogoutMiddleware.d.ts.map +0 -1
@@ -1,40 +1,12 @@
1
- //#region rolldown:runtime
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
- key = keys[i];
12
- if (!__hasOwnProp.call(to, key) && key !== except) {
13
- __defProp(to, key, {
14
- get: ((k) => from[k]).bind(null, key),
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- }
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
- value: mod,
24
- enumerable: true
25
- }) : target, mod));
26
-
27
- //#endregion
1
+ const require_isMfaRequiredForAction = require('./isMfaRequiredForAction-BolTrtCO.cjs');
28
2
  let _dynamic_labs_sdk_api_core = require("@dynamic-labs/sdk-api-core");
29
- let zod_mini = require("zod/mini");
30
- zod_mini = __toESM(zod_mini);
31
3
 
32
4
  //#region package.json
33
5
  var name = "@dynamic-labs-sdk/client";
34
- var version = "1.6.0";
6
+ var version = "1.8.0";
35
7
  var dependencies = {
36
8
  "@dynamic-labs-sdk/assert-package-version": "workspace:*",
37
- "@dynamic-labs-wallet/browser-wallet-client": "1.0.7",
9
+ "@dynamic-labs-wallet/browser-wallet-client": "1.0.16",
38
10
  "@dynamic-labs-wallet/forward-mpc-client": "0.10.1",
39
11
  "@dynamic-labs/sdk-api-core": "catalog:",
40
12
  "@simplewebauthn/browser": "13.1.0",
@@ -941,6 +913,110 @@ const createDeviceSignatureHeadersMiddleware = (client) => {
941
913
  } };
942
914
  };
943
915
 
916
+ //#endregion
917
+ //#region src/errors/UnauthorizedError.ts
918
+ var UnauthorizedError = class extends BaseError {
919
+ constructor({ cause }) {
920
+ super({
921
+ cause,
922
+ code: "unauthorized_error",
923
+ docsUrl: null,
924
+ name: "UnauthorizedError",
925
+ shortMessage: "Unauthorized"
926
+ });
927
+ }
928
+ };
929
+
930
+ //#endregion
931
+ //#region src/modules/apiClient/utils/unauthorizedMiddleware/createUnauthorizedMiddleware.ts
932
+ /** @not-instrumented */
933
+ const createUnauthorizedMiddleware = () => ({ post: async (context) => {
934
+ if (context.response.status === 401) {
935
+ let cause = null;
936
+ try {
937
+ const errorBody = await context.response.clone().json();
938
+ if (errorBody && "error" in errorBody && typeof errorBody.error === "string") cause = new Error(errorBody.error);
939
+ } catch {}
940
+ throw new UnauthorizedError({ cause });
941
+ }
942
+ return context.response;
943
+ } });
944
+
945
+ //#endregion
946
+ //#region src/modules/apiClient/createApiClient.ts
947
+ /**
948
+ * Returns a new instance of the SDK API client.
949
+ *
950
+ * This is not meant for storing, as it is very light we can create it whenever needed.
951
+ * @not-instrumented
952
+ */
953
+ const createApiClient = (options = {}, client) => {
954
+ const core = getCore(client);
955
+ const coreState = core.state.get();
956
+ const settings = {
957
+ basePath: core.apiBaseUrl,
958
+ headers: {
959
+ "Content-Type": "application/json",
960
+ [DYNAMIC_API_VERSION_HEADER]: `API/${DYNAMIC_SDK_API_VERSION}`,
961
+ [DYNAMIC_REQUEST_ID_HEADER]: randomString({ length: 50 }),
962
+ [DYNAMIC_SDK_SESSION_ID_HEADER]: core.sdkSessionId,
963
+ [DYNAMIC_SDK_VERSION_HEADER]: `${CLIENT_SDK_NAME}/${version}`,
964
+ ...core.getApiHeaders(),
965
+ ...options.headers
966
+ }
967
+ };
968
+ if (core.metadata?.universalLink) settings.headers["Origin"] = core.metadata.universalLink;
969
+ if (client.token) settings.headers.Authorization = `Bearer ${client.token}`;
970
+ if (client.projectSettings && isCookieEnabled(client)) settings.credentials = "include";
971
+ if (options.includeMfaToken && coreState.mfaToken) settings.headers[MFA_TOKEN_HEADER] = coreState.mfaToken;
972
+ if (options.elevatedAccessTokenScope) {
973
+ const elevatedToken = __getElevatedAccessToken_wrapped({ scope: options.elevatedAccessTokenScope }, client);
974
+ if (elevatedToken) settings.headers[ELEVATED_ACCESS_TOKEN_HEADER] = elevatedToken;
975
+ }
976
+ const sessionPublicKey = getSessionKeys(client)?.publicKey;
977
+ const isSessionPublicKeyHeaderPresent = settings.headers[SESSION_PUBLIC_KEY_HEADER] !== void 0;
978
+ if (sessionPublicKey && !isSessionPublicKeyHeaderPresent) settings.headers[SESSION_PUBLIC_KEY_HEADER] = sessionPublicKey;
979
+ return new _dynamic_labs_sdk_api_core.SDKApi(new _dynamic_labs_sdk_api_core.Configuration({
980
+ ...settings,
981
+ fetchApi: core.fetch,
982
+ middleware: [
983
+ createDeviceSignatureHeadersMiddleware(client),
984
+ createConvertToApiErrorMiddleware({ errorMappers: [...options.errorMappers || [], clientErrorMapper] }),
985
+ createUnauthorizedMiddleware()
986
+ ]
987
+ }));
988
+ };
989
+
990
+ //#endregion
991
+ //#region src/utils/getNonce/fetchAndStoreNonces/fetchAndStoreNonces.ts
992
+ /**
993
+ * Fetches a batch of nonces from the API.
994
+ *
995
+ * Prefetching is critical for iOS deep link wallet providers (e.g. Phantom
996
+ * redirect). On iOS, a network request (like fetching a nonce) between a user
997
+ * action and a deeplink call will break the gesture chain, causing iOS to
998
+ * silently ignore the deeplink. By prefetching nonces ahead of time,
999
+ * `getNonce` can return synchronously from cache and the deeplink fires
1000
+ * without an interrupting network round-trip.
1001
+ *
1002
+ * New nonces are **appended** to the existing pool so that unconsumed entries
1003
+ * are not discarded by a background refetch.
1004
+ * @not-instrumented
1005
+ */
1006
+ const fetchAndStoreNonces = async (client) => {
1007
+ const core = getCore(client);
1008
+ const { environmentId } = core;
1009
+ const { nonces } = await createApiClient({}, client).getNonces({
1010
+ count: NONCE_POOL_SIZE,
1011
+ environmentId
1012
+ });
1013
+ const existing = core.state.get().prefetchedNonces;
1014
+ core.state.set({
1015
+ prefetchedNonces: [...existing, ...nonces],
1016
+ prefetchedNoncesExpiration: Date.now() + NONCE_POOL_EXPIRATION_TIME
1017
+ });
1018
+ };
1019
+
944
1020
  //#endregion
945
1021
  //#region src/utils/setCookie/setCookie.ts
946
1022
  /**
@@ -1022,41 +1098,6 @@ const emitEvent = ({ event, args }, client) => {
1022
1098
  eventEmitter.emit(event, args);
1023
1099
  };
1024
1100
 
1025
- //#endregion
1026
- //#region src/utils/retryOnFail/InvalidRetryOnFailCallError.ts
1027
- /**
1028
- * This error is thrown when the `retryOnFail` function is called with an invalid
1029
- * number of retries (i.e. less than 0).
1030
- */
1031
- var InvalidRetryOnFailCallError = class extends BaseError {
1032
- constructor(maxRetries) {
1033
- super({
1034
- cause: null,
1035
- code: "invalid_retry_on_fail_call_error",
1036
- docsUrl: null,
1037
- name: "InvalidRetryOnFailCallError",
1038
- shortMessage: `Invalid retries parameter for retryOnFail call: ${maxRetries}`
1039
- });
1040
- }
1041
- };
1042
-
1043
- //#endregion
1044
- //#region src/utils/retryOnFail/retryOnFail.ts
1045
- /** @not-instrumented */
1046
- const retryOnFail = async ({ delay = 0, fn, maxRetries }) => {
1047
- for (let retry = 0; retry <= maxRetries; retry++) try {
1048
- return await fn();
1049
- } catch (error) {
1050
- if (retry >= maxRetries) throw error;
1051
- if (delay > 0) await new Promise((resolve) => setTimeout(resolve, delay));
1052
- }
1053
- /**
1054
- * Reaching this point should never happen and this
1055
- * error is thrown to help us debug the issue.
1056
- */
1057
- throw new InvalidRetryOnFailCallError(maxRetries);
1058
- };
1059
-
1060
1101
  //#endregion
1061
1102
  //#region src/errors/InvalidWalletProviderKeyError.ts
1062
1103
  var InvalidWalletProviderKeyError = class extends BaseError {
@@ -1352,95 +1393,6 @@ const getWalletAccounts = (client = getDefaultClient()) => {
1352
1393
  }, client);
1353
1394
  };
1354
1395
 
1355
- //#endregion
1356
- //#region src/modules/auth/isSignedIn/isSignedIn.ts
1357
- /**
1358
- * Checks if the user is currently signed in to the Dynamic client.
1359
- *
1360
- * The client is considered to be in a signed in state if a user has
1361
- * authenticated or if the client has at least one wallet connected.
1362
- *
1363
- * @deprecated What counts as "signed in" is your app's business logic, not the
1364
- * SDK's. This helper bakes in one opinion (a user OR any connected wallet),
1365
- * which rarely matches every app and forces a dependency on us for every
1366
- * variation. Compose your own check from the underlying primitives instead —
1367
- * e.g. `Boolean(client.user) || isAnyWalletAccountConnected(client)` — and
1368
- * layer in whatever your app requires (device registration, completed
1369
- * onboarding, satisfied MFA, a required embedded wallet, …). See the
1370
- * "Check if signed in" guide:
1371
- * https://www.dynamic.xyz/docs/javascript/user-session-management
1372
- *
1373
- * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
1374
- * @returns True if the user is signed in, false otherwise.
1375
- * @not-instrumented
1376
- */
1377
- const isSignedIn = (client = getDefaultClient()) => Boolean(client.user || getWalletAccounts(client).length > 0);
1378
-
1379
- //#endregion
1380
- //#region src/services/storage/createStorageKeySchema/createStorageKeySchema.ts
1381
- /** @not-instrumented */
1382
- const createStorageKeySchema = (params) => {
1383
- return params;
1384
- };
1385
-
1386
- //#endregion
1387
- //#region src/modules/projectSettings/fetchProjectSettings/projectSettingsExpirationScheme.ts
1388
- /**
1389
- * The schema to track the expiration time of the project settings.
1390
- */
1391
- const projectSettingsExpirationStorageKeySchema = createStorageKeySchema({
1392
- key: "projectSettingsExpiration",
1393
- schema: zod_mini.number()
1394
- });
1395
-
1396
- //#endregion
1397
- //#region src/modules/projectSettings/fetchProjectSettings/fetchProjectSettings.ts
1398
- /**
1399
- * Expiration time of the project settings in milliseconds.
1400
- */
1401
- const PROJECT_SETTINGS_EXPIRATION_TIME = 1e3 * 60 * 5;
1402
- /**
1403
- * Fetches and updates the project settings from the API.
1404
- *
1405
- * This function retrieves the latest project configuration settings
1406
- * from Dynamic's servers, including authentication options, enabled chains,
1407
- * and security configurations. The settings are cached for performance.
1408
- *
1409
- * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
1410
- * @returns A promise that resolves to the updated project settings.
1411
- * @not-instrumented
1412
- */
1413
- const fetchProjectSettings = async (client = getDefaultClient()) => {
1414
- const core = getCore(client);
1415
- const currentExpiration = await core.storage.getItem(projectSettingsExpirationStorageKeySchema);
1416
- if (Boolean(client.projectSettings) && !(currentExpiration && currentExpiration < Date.now()) && isSignedIn(client)) return client.projectSettings;
1417
- const apiClient = createApiClient({}, client);
1418
- core.logger.debug("[fetchProjectSettings] Fetching project settings...");
1419
- const doFetch = async () => apiClient.getEnvironmentSettings({
1420
- environmentId: core.environmentId,
1421
- sdkVersion: `${CLIENT_SDK_NAME}/${core.version}`
1422
- }, { credentials: "omit" });
1423
- const projectSettings = await retryOnFail({
1424
- fn: doFetch,
1425
- maxRetries: 2
1426
- });
1427
- core.state.set({ projectSettings: projectSettings ?? null });
1428
- await core.storage.setItem(projectSettingsExpirationStorageKeySchema, Date.now() + PROJECT_SETTINGS_EXPIRATION_TIME);
1429
- return projectSettings;
1430
- };
1431
-
1432
- //#endregion
1433
- //#region src/modules/sessionKeys/generateSessionKeys/generateSessionKeys.ts
1434
- /** @not-instrumented */
1435
- const generateSessionKeys = async (client) => {
1436
- const core = getCore(client);
1437
- await core.keychain.removeKey("session");
1438
- const publicKey = await core.keychain.generateKey("session");
1439
- assertDefined(publicKey, "Public key not found");
1440
- core.state.set({ sessionKeys: publicKey });
1441
- return { publicKey };
1442
- };
1443
-
1444
1396
  //#endregion
1445
1397
  //#region src/errors/NoWalletProviderFoundError.ts
1446
1398
  var NoWalletProviderFoundError = class extends BaseError {
@@ -1596,262 +1548,10 @@ const getWalletProviderFromWalletAccount = ({ walletAccount }, client) => {
1596
1548
  return walletProvider;
1597
1549
  };
1598
1550
 
1599
- //#endregion
1600
- //#region src/modules/wallets/utils/getAvailableWalletProvidersFromWalletAccounts/getAvailableWalletProvidersFromWalletAccounts.ts
1601
- /** @not-instrumented */
1602
- const getAvailableWalletProvidersFromWalletAccounts = (client) => {
1603
- const core = getCore(client);
1604
- const walletProvidersMap = /* @__PURE__ */ new Map();
1605
- getWalletAccounts(client).forEach((walletAccount) => {
1606
- if (walletProvidersMap.has(walletAccount.walletProviderKey)) return;
1607
- try {
1608
- const walletProvider = getWalletProviderFromWalletAccount({ walletAccount }, client);
1609
- walletProvidersMap.set(walletAccount.walletProviderKey, walletProvider);
1610
- } catch (error) {
1611
- core.logger.debug("Wallet provider not found for wallet account", {
1612
- error,
1613
- walletAccount: walletAccount.address
1614
- });
1615
- }
1616
- });
1617
- return Array.from(walletProvidersMap.values());
1618
- };
1619
-
1620
- //#endregion
1621
- //#region src/modules/wallets/destroyWalletProviders/destroyWalletProviders.ts
1622
- /**
1623
- * Tear down every wallet provider on the client.
1624
- *
1625
- * Each provider's `destroy` is responsible for its own local + remote
1626
- * cleanup. We swallow errors so a failing destroy on one provider does not
1627
- * block teardown of the others (e.g. during logout).
1628
- *
1629
- * @not-instrumented
1630
- */
1631
- const destroyWalletProviders = async ({ reason }, client) => {
1632
- const core = getCore(client);
1633
- const walletProviders = getAvailableWalletProvidersFromWalletAccounts(client);
1634
- await Promise.all(walletProviders.map(async (walletProvider) => {
1635
- if (!walletProvider.destroy) return;
1636
- try {
1637
- await walletProvider.destroy({ reason });
1638
- } catch (err) {
1639
- core.logger.error(`Error destroying wallet provider ${walletProvider.key}`, err);
1640
- }
1641
- }));
1642
- };
1643
-
1644
1551
  //#endregion
1645
1552
  //#region src/modules/auth/consts.ts
1646
1553
  const DYNAMIC_AUTH_COOKIE_NAME = "DYNAMIC_JWT_TOKEN";
1647
1554
 
1648
- //#endregion
1649
- //#region src/modules/auth/logoutWithReason/logoutWithReason.ts
1650
- /**
1651
- * Logs the user out with an explicit reason.
1652
- *
1653
- * Revokes the session, clears auth state, terminates wallet providers, and
1654
- * emits the `logout` client event with the given reason. The reason is also
1655
- * captured as an argument on the function-instrumentation event, which is
1656
- * how Datadog distinguishes between different logout causes.
1657
- *
1658
- * Use this instead of the public `logout` when triggering a logout from
1659
- * internal or extension code — the caller owns the reason string, so the
1660
- * telemetry correctly attributes *why* the logout happened.
1661
- *
1662
- * @param params - The logout params.
1663
- * @param params.reason - Why the logout is being triggered. Extension authors
1664
- * needing a reason outside the SDK catalog can cast with `as LogoutReason`.
1665
- * @param client - The Dynamic client instance.
1666
- * @instrumented
1667
- */
1668
- const logoutWithReason = async ({ reason }, client) => {
1669
- const core = getCore(client);
1670
- core.logger.debug("[logoutWithReason] Logging out...", { reason });
1671
- await destroyWalletProviders({ reason }, client);
1672
- if (client.user !== null) {
1673
- const apiClient = createApiClient({ skipSessionExpiryLogout: true }, client);
1674
- try {
1675
- await apiClient.revokeSession({ environmentId: core.environmentId });
1676
- } catch (error) {
1677
- core.logger.error("Failed to revoke session", error);
1678
- }
1679
- /**
1680
- * This deletes the auth cookie if it exists.
1681
- * If the cookie doesn't exist, this sets a new cookie that expires immediately.
1682
- */
1683
- if (isCookieEnabled(client)) setCookie(`${DYNAMIC_AUTH_COOKIE_NAME}=; Max-Age=-99999999; path=/; SameSite=Lax`);
1684
- }
1685
- await core.keychain.removeKey("session");
1686
- core.state.set({
1687
- captchaToken: null,
1688
- elevatedAccessTokens: [],
1689
- legacyToken: null,
1690
- mfaToken: null,
1691
- sessionExpiresAt: null,
1692
- sessionKeys: null,
1693
- token: null,
1694
- unverifiedWalletAccounts: [],
1695
- user: null
1696
- });
1697
- emitEvent({
1698
- args: { reason },
1699
- event: "logout"
1700
- }, client);
1701
- fetchProjectSettings(client);
1702
- generateSessionKeys(client);
1703
- };
1704
- const __logoutWithReason_impl = logoutWithReason;
1705
- const __logoutWithReason_wrapped = instrumentFunction({
1706
- fn: __logoutWithReason_impl,
1707
- functionName: "logoutWithReason",
1708
- getCore: () => {
1709
- try {
1710
- return getCore(getDefaultClient());
1711
- } catch {
1712
- return;
1713
- }
1714
- }
1715
- });
1716
-
1717
- //#endregion
1718
- //#region src/modules/apiClient/utils/sessionExpiryLogoutMiddleware/createSessionExpiryLogoutMiddleware.ts
1719
- const UNAUTHORIZED_STATUS = 401;
1720
- /**
1721
- * Creates middleware that ends the local session when an *authenticated*
1722
- * request is rejected with a 401.
1723
- *
1724
- * A 401 on a request that carried an authenticated session means the backend
1725
- * rejected our credentials, so the local session is stale and must be cleared.
1726
- * The check is purely local (`client.user`) — we deliberately do not
1727
- * re-validate over the network, because the 401 itself is the rejection signal
1728
- * and re-validating would route back through this same middleware.
1729
- *
1730
- * Requests made without an authenticated session (e.g. pre-auth probes) are
1731
- * ignored — there is no session to invalidate. Endpoints that legitimately
1732
- * return 401 for non-session reasons opt out of this behavior by omitting the
1733
- * middleware (see `skipSessionExpiryLogout` on `createApiClient`).
1734
- *
1735
- * This middleware runs before the error-conversion middleware so it observes
1736
- * every 401 regardless of response body. The logout is fired as a side effect
1737
- * and the response is returned unchanged, so the downstream error middleware
1738
- * still throws the typed error to the caller.
1739
- *
1740
- * @param client - The Dynamic client instance.
1741
- * @not-instrumented
1742
- */
1743
- const createSessionExpiryLogoutMiddleware = (client) => ({ post: async (context) => {
1744
- if (context.response.status === UNAUTHORIZED_STATUS && client.user !== null) __logoutWithReason_wrapped({ reason: "session-revoked" }, client).catch((error) => {
1745
- getCore(client).logger.error("Failed to log out after unauthorized response", error);
1746
- });
1747
- return context.response;
1748
- } });
1749
-
1750
- //#endregion
1751
- //#region src/errors/UnauthorizedError.ts
1752
- var UnauthorizedError = class extends BaseError {
1753
- constructor({ cause }) {
1754
- super({
1755
- cause,
1756
- code: "unauthorized_error",
1757
- docsUrl: null,
1758
- name: "UnauthorizedError",
1759
- shortMessage: "Unauthorized"
1760
- });
1761
- }
1762
- };
1763
-
1764
- //#endregion
1765
- //#region src/modules/apiClient/utils/unauthorizedMiddleware/createUnauthorizedMiddleware.ts
1766
- /** @not-instrumented */
1767
- const createUnauthorizedMiddleware = () => ({ post: async (context) => {
1768
- if (context.response.status === 401) {
1769
- let cause = null;
1770
- try {
1771
- const errorBody = await context.response.clone().json();
1772
- if (errorBody && "error" in errorBody && typeof errorBody.error === "string") cause = new Error(errorBody.error);
1773
- } catch {}
1774
- throw new UnauthorizedError({ cause });
1775
- }
1776
- return context.response;
1777
- } });
1778
-
1779
- //#endregion
1780
- //#region src/modules/apiClient/createApiClient.ts
1781
- /**
1782
- * Returns a new instance of the SDK API client.
1783
- *
1784
- * This is not meant for storing, as it is very light we can create it whenever needed.
1785
- * @not-instrumented
1786
- */
1787
- const createApiClient = (options = {}, client) => {
1788
- const core = getCore(client);
1789
- const coreState = core.state.get();
1790
- const settings = {
1791
- basePath: core.apiBaseUrl,
1792
- headers: {
1793
- "Content-Type": "application/json",
1794
- [DYNAMIC_API_VERSION_HEADER]: `API/${DYNAMIC_SDK_API_VERSION}`,
1795
- [DYNAMIC_REQUEST_ID_HEADER]: randomString({ length: 50 }),
1796
- [DYNAMIC_SDK_SESSION_ID_HEADER]: core.sdkSessionId,
1797
- [DYNAMIC_SDK_VERSION_HEADER]: `${CLIENT_SDK_NAME}/${version}`,
1798
- ...core.getApiHeaders(),
1799
- ...options.headers
1800
- }
1801
- };
1802
- if (core.metadata?.universalLink) settings.headers["Origin"] = core.metadata.universalLink;
1803
- if (client.token) settings.headers.Authorization = `Bearer ${client.token}`;
1804
- if (client.projectSettings && isCookieEnabled(client)) settings.credentials = "include";
1805
- if (options.includeMfaToken && coreState.mfaToken) settings.headers[MFA_TOKEN_HEADER] = coreState.mfaToken;
1806
- if (options.elevatedAccessTokenScope) {
1807
- const elevatedToken = __getElevatedAccessToken_wrapped({ scope: options.elevatedAccessTokenScope }, client);
1808
- if (elevatedToken) settings.headers[ELEVATED_ACCESS_TOKEN_HEADER] = elevatedToken;
1809
- }
1810
- const sessionPublicKey = getSessionKeys(client)?.publicKey;
1811
- const isSessionPublicKeyHeaderPresent = settings.headers[SESSION_PUBLIC_KEY_HEADER] !== void 0;
1812
- if (sessionPublicKey && !isSessionPublicKeyHeaderPresent) settings.headers[SESSION_PUBLIC_KEY_HEADER] = sessionPublicKey;
1813
- return new _dynamic_labs_sdk_api_core.SDKApi(new _dynamic_labs_sdk_api_core.Configuration({
1814
- ...settings,
1815
- fetchApi: core.fetch,
1816
- middleware: [
1817
- createDeviceSignatureHeadersMiddleware(client),
1818
- ...options.skipSessionExpiryLogout ? [] : [createSessionExpiryLogoutMiddleware(client)],
1819
- createConvertToApiErrorMiddleware({ errorMappers: [...options.errorMappers || [], clientErrorMapper] }),
1820
- createUnauthorizedMiddleware()
1821
- ]
1822
- }));
1823
- };
1824
-
1825
- //#endregion
1826
- //#region src/utils/getNonce/fetchAndStoreNonces/fetchAndStoreNonces.ts
1827
- /**
1828
- * Fetches a batch of nonces from the API.
1829
- *
1830
- * Prefetching is critical for iOS deep link wallet providers (e.g. Phantom
1831
- * redirect). On iOS, a network request (like fetching a nonce) between a user
1832
- * action and a deeplink call will break the gesture chain, causing iOS to
1833
- * silently ignore the deeplink. By prefetching nonces ahead of time,
1834
- * `getNonce` can return synchronously from cache and the deeplink fires
1835
- * without an interrupting network round-trip.
1836
- *
1837
- * New nonces are **appended** to the existing pool so that unconsumed entries
1838
- * are not discarded by a background refetch.
1839
- * @not-instrumented
1840
- */
1841
- const fetchAndStoreNonces = async (client) => {
1842
- const core = getCore(client);
1843
- const { environmentId } = core;
1844
- const { nonces } = await createApiClient({}, client).getNonces({
1845
- count: NONCE_POOL_SIZE,
1846
- environmentId
1847
- });
1848
- const existing = core.state.get().prefetchedNonces;
1849
- core.state.set({
1850
- prefetchedNonces: [...existing, ...nonces],
1851
- prefetchedNoncesExpiration: Date.now() + NONCE_POOL_EXPIRATION_TIME
1852
- });
1853
- };
1854
-
1855
1555
  //#endregion
1856
1556
  //#region src/constants.ts
1857
1557
  const SDK_API_CORE_VERSION = dependencies["@dynamic-labs/sdk-api-core"];
@@ -2038,18 +1738,6 @@ Object.defineProperty(exports, '__getElevatedAccessToken_wrapped', {
2038
1738
  return __getElevatedAccessToken_wrapped;
2039
1739
  }
2040
1740
  });
2041
- Object.defineProperty(exports, '__logoutWithReason_wrapped', {
2042
- enumerable: true,
2043
- get: function () {
2044
- return __logoutWithReason_wrapped;
2045
- }
2046
- });
2047
- Object.defineProperty(exports, '__toESM', {
2048
- enumerable: true,
2049
- get: function () {
2050
- return __toESM;
2051
- }
2052
- });
2053
1741
  Object.defineProperty(exports, 'assertDefined', {
2054
1742
  enumerable: true,
2055
1743
  get: function () {
@@ -2074,12 +1762,6 @@ Object.defineProperty(exports, 'createRuntimeServiceAccessKey', {
2074
1762
  return createRuntimeServiceAccessKey;
2075
1763
  }
2076
1764
  });
2077
- Object.defineProperty(exports, 'createStorageKeySchema', {
2078
- enumerable: true,
2079
- get: function () {
2080
- return createStorageKeySchema;
2081
- }
2082
- });
2083
1765
  Object.defineProperty(exports, 'emitEvent', {
2084
1766
  enumerable: true,
2085
1767
  get: function () {
@@ -2098,12 +1780,6 @@ Object.defineProperty(exports, 'fetchAndStoreNonces', {
2098
1780
  return fetchAndStoreNonces;
2099
1781
  }
2100
1782
  });
2101
- Object.defineProperty(exports, 'fetchProjectSettings', {
2102
- enumerable: true,
2103
- get: function () {
2104
- return fetchProjectSettings;
2105
- }
2106
- });
2107
1783
  Object.defineProperty(exports, 'formatWalletAccountId', {
2108
1784
  enumerable: true,
2109
1785
  get: function () {
@@ -2116,12 +1792,6 @@ Object.defineProperty(exports, 'formatWalletProviderKey', {
2116
1792
  return formatWalletProviderKey;
2117
1793
  }
2118
1794
  });
2119
- Object.defineProperty(exports, 'generateSessionKeys', {
2120
- enumerable: true,
2121
- get: function () {
2122
- return generateSessionKeys;
2123
- }
2124
- });
2125
1795
  Object.defineProperty(exports, 'getChainFromVerifiedCredentialChain', {
2126
1796
  enumerable: true,
2127
1797
  get: function () {
@@ -2206,12 +1876,6 @@ Object.defineProperty(exports, 'isCookieEnabled', {
2206
1876
  return isCookieEnabled;
2207
1877
  }
2208
1878
  });
2209
- Object.defineProperty(exports, 'isSignedIn', {
2210
- enumerable: true,
2211
- get: function () {
2212
- return isSignedIn;
2213
- }
2214
- });
2215
1879
  Object.defineProperty(exports, 'name', {
2216
1880
  enumerable: true,
2217
1881
  get: function () {
@@ -2254,12 +1918,6 @@ Object.defineProperty(exports, 'randomString', {
2254
1918
  return randomString;
2255
1919
  }
2256
1920
  });
2257
- Object.defineProperty(exports, 'retryOnFail', {
2258
- enumerable: true,
2259
- get: function () {
2260
- return retryOnFail;
2261
- }
2262
- });
2263
1921
  Object.defineProperty(exports, 'scrubParameters', {
2264
1922
  enumerable: true,
2265
1923
  get: function () {
@@ -2290,4 +1948,4 @@ Object.defineProperty(exports, 'version', {
2290
1948
  return version;
2291
1949
  }
2292
1950
  });
2293
- //# sourceMappingURL=InvalidParamError-DyXEKMWn.cjs.map
1951
+ //# sourceMappingURL=InvalidParamError-S56rFFDP.cjs.map