@dynamic-labs-sdk/client 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/dist/{InvalidParamError-DEmLKJKZ.cjs → InvalidParamError-DKJhDrK8.cjs} +1007 -116
  2. package/dist/InvalidParamError-DKJhDrK8.cjs.map +1 -0
  3. package/dist/{InvalidParamError-BPMi0iWC.esm.js → InvalidParamError-DWjMfOZ5.esm.js} +800 -92
  4. package/dist/InvalidParamError-DWjMfOZ5.esm.js.map +1 -0
  5. package/dist/{InvalidParamError-CDmVW2DS.native.esm.js → InvalidParamError-DkAMYJOW.native.esm.js} +833 -92
  6. package/dist/InvalidParamError-DkAMYJOW.native.esm.js.map +1 -0
  7. package/dist/{NotWaasWalletAccountError-Cntietge.esm.js → NotWaasWalletAccountError-BVrvQzLz.native.esm.js} +4 -4
  8. package/dist/NotWaasWalletAccountError-BVrvQzLz.native.esm.js.map +1 -0
  9. package/dist/{NotWaasWalletAccountError-Chpne8_Q.native.esm.js → NotWaasWalletAccountError-C7NUlvvM.esm.js} +4 -4
  10. package/dist/NotWaasWalletAccountError-C7NUlvvM.esm.js.map +1 -0
  11. package/dist/{NotWaasWalletAccountError-BZsBHRQe.cjs → NotWaasWalletAccountError-CHzpa9kk.cjs} +4 -4
  12. package/dist/NotWaasWalletAccountError-CHzpa9kk.cjs.map +1 -0
  13. package/dist/core.cjs +45 -23
  14. package/dist/core.cjs.map +1 -1
  15. package/dist/core.esm.js +29 -8
  16. package/dist/core.esm.js.map +1 -1
  17. package/dist/core.native.esm.js +27 -6
  18. package/dist/core.native.esm.js.map +1 -1
  19. package/dist/exports/core.d.ts +4 -0
  20. package/dist/exports/core.d.ts.map +1 -1
  21. package/dist/exports/index.d.ts +12 -0
  22. package/dist/exports/index.d.ts.map +1 -1
  23. package/dist/{getNetworkProviderFromNetworkId-szJOsbQN.cjs → getNetworkProviderFromNetworkId-BJ27N-7S.cjs} +44 -341
  24. package/dist/getNetworkProviderFromNetworkId-BJ27N-7S.cjs.map +1 -0
  25. package/dist/{getNetworkProviderFromNetworkId-JGrKwBj7.native.esm.js → getNetworkProviderFromNetworkId-Bs1kQdWk.native.esm.js} +38 -299
  26. package/dist/getNetworkProviderFromNetworkId-Bs1kQdWk.native.esm.js.map +1 -0
  27. package/dist/{getNetworkProviderFromNetworkId-CEeFL-gV.esm.js → getNetworkProviderFromNetworkId-Cqp9eRSs.esm.js} +42 -270
  28. package/dist/getNetworkProviderFromNetworkId-Cqp9eRSs.esm.js.map +1 -0
  29. package/dist/{getSignedSessionId-BOx1nFt_.esm.js → getSignedSessionId-CDdKrnw6.esm.js} +3 -3
  30. package/dist/{getSignedSessionId-BOx1nFt_.esm.js.map → getSignedSessionId-CDdKrnw6.esm.js.map} +1 -1
  31. package/dist/{getSignedSessionId-BxOK-Tdo.cjs → getSignedSessionId-CHDHr-hY.cjs} +3 -3
  32. package/dist/{getSignedSessionId-BxOK-Tdo.cjs.map → getSignedSessionId-CHDHr-hY.cjs.map} +1 -1
  33. package/dist/{getSignedSessionId-B5DikCap.native.esm.js → getSignedSessionId-D3KQrN8W.native.esm.js} +3 -3
  34. package/dist/{getSignedSessionId-B5DikCap.native.esm.js.map → getSignedSessionId-D3KQrN8W.native.esm.js.map} +1 -1
  35. package/dist/getVerifiedCredentialForWalletAccount-BuUCX040.esm.js +269 -0
  36. package/dist/getVerifiedCredentialForWalletAccount-BuUCX040.esm.js.map +1 -0
  37. package/dist/getVerifiedCredentialForWalletAccount-Ciac5d5L.native.esm.js +269 -0
  38. package/dist/getVerifiedCredentialForWalletAccount-Ciac5d5L.native.esm.js.map +1 -0
  39. package/dist/getVerifiedCredentialForWalletAccount-gCx0smU8.cjs +346 -0
  40. package/dist/getVerifiedCredentialForWalletAccount-gCx0smU8.cjs.map +1 -0
  41. package/dist/index.cjs +580 -253
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.esm.js +514 -194
  44. package/dist/index.esm.js.map +1 -1
  45. package/dist/index.native.esm.js +511 -191
  46. package/dist/index.native.esm.js.map +1 -1
  47. package/dist/{isMfaRequiredForAction-DUvZEpjA.native.esm.js → isMfaRequiredForAction-B0xNvBpU.native.esm.js} +2 -2
  48. package/dist/{isMfaRequiredForAction-DUvZEpjA.native.esm.js.map → isMfaRequiredForAction-B0xNvBpU.native.esm.js.map} +1 -1
  49. package/dist/{isMfaRequiredForAction-6N6JB7wa.cjs → isMfaRequiredForAction-CLMvTTwl.cjs} +2 -2
  50. package/dist/{isMfaRequiredForAction-6N6JB7wa.cjs.map → isMfaRequiredForAction-CLMvTTwl.cjs.map} +1 -1
  51. package/dist/{isMfaRequiredForAction-D9p_du8C.esm.js → isMfaRequiredForAction-C_QPI1LH.esm.js} +2 -2
  52. package/dist/{isMfaRequiredForAction-D9p_du8C.esm.js.map → isMfaRequiredForAction-C_QPI1LH.esm.js.map} +1 -1
  53. package/dist/modules/apiClient/apiClient.types.d.ts +12 -0
  54. package/dist/modules/apiClient/apiClient.types.d.ts.map +1 -1
  55. package/dist/modules/apiClient/createApiClient.d.ts.map +1 -1
  56. package/dist/modules/apiClient/utils/sessionExpiryLogoutMiddleware/createSessionExpiryLogoutMiddleware.d.ts +27 -0
  57. package/dist/modules/apiClient/utils/sessionExpiryLogoutMiddleware/createSessionExpiryLogoutMiddleware.d.ts.map +1 -0
  58. package/dist/modules/auth/isSignedIn/isSignedIn.d.ts +11 -1
  59. package/dist/modules/auth/isSignedIn/isSignedIn.d.ts.map +1 -1
  60. package/dist/modules/auth/logoutReason.d.ts +1 -1
  61. package/dist/modules/auth/logoutReason.d.ts.map +1 -1
  62. package/dist/modules/auth/logoutWithReason/logoutWithReason.d.ts.map +1 -1
  63. package/dist/modules/balances/getBalances/getBalances.d.ts +9 -45
  64. package/dist/modules/balances/getBalances/getBalances.d.ts.map +1 -1
  65. package/dist/modules/balances/getMultichainBalances/getMultichainBalances.d.ts +13 -20
  66. package/dist/modules/balances/getMultichainBalances/getMultichainBalances.d.ts.map +1 -1
  67. package/dist/modules/balances/getMultichainTokenBalances/getMultichainTokenBalances.d.ts +26 -0
  68. package/dist/modules/balances/getMultichainTokenBalances/getMultichainTokenBalances.d.ts.map +1 -0
  69. package/dist/modules/balances/getMultichainTokenBalances/index.d.ts +2 -0
  70. package/dist/modules/balances/getMultichainTokenBalances/index.d.ts.map +1 -0
  71. package/dist/modules/balances/getTokenBalances/getTokenBalances.d.ts +56 -0
  72. package/dist/modules/balances/getTokenBalances/getTokenBalances.d.ts.map +1 -0
  73. package/dist/modules/balances/getTokenBalances/index.d.ts +3 -0
  74. package/dist/modules/balances/getTokenBalances/index.d.ts.map +1 -0
  75. package/dist/modules/deviceRegistration/getRegisteredDevices/getRegisteredDevices.d.ts.map +1 -1
  76. package/dist/modules/funding/moonpay/errors/MoonPayCurrenciesFetchError.d.ts +5 -0
  77. package/dist/modules/funding/moonpay/errors/MoonPayCurrenciesFetchError.d.ts.map +1 -0
  78. package/dist/modules/funding/moonpay/errors/MoonPayInvalidUrlError.d.ts +5 -0
  79. package/dist/modules/funding/moonpay/errors/MoonPayInvalidUrlError.d.ts.map +1 -0
  80. package/dist/modules/funding/moonpay/errors/MoonPayProviderNotAvailableError.d.ts +5 -0
  81. package/dist/modules/funding/moonpay/errors/MoonPayProviderNotAvailableError.d.ts.map +1 -0
  82. package/dist/modules/funding/moonpay/getMoonPayCurrencies/getMoonPayCurrencies.d.ts +14 -0
  83. package/dist/modules/funding/moonpay/getMoonPayCurrencies/getMoonPayCurrencies.d.ts.map +1 -0
  84. package/dist/modules/funding/moonpay/getMoonPayCurrencies/index.d.ts +2 -0
  85. package/dist/modules/funding/moonpay/getMoonPayCurrencies/index.d.ts.map +1 -0
  86. package/dist/modules/funding/moonpay/getMoonPayUrl/getMoonPayUrl.d.ts +15 -0
  87. package/dist/modules/funding/moonpay/getMoonPayUrl/getMoonPayUrl.d.ts.map +1 -0
  88. package/dist/modules/funding/moonpay/getMoonPayUrl/index.d.ts +2 -0
  89. package/dist/modules/funding/moonpay/getMoonPayUrl/index.d.ts.map +1 -0
  90. package/dist/modules/funding/moonpay/moonpay.types.d.ts +26 -0
  91. package/dist/modules/funding/moonpay/moonpay.types.d.ts.map +1 -0
  92. package/dist/modules/legacyWalletBook/getWalletConnectCatalog/getChainFromWalletSchema/getChainFromWalletSchema.d.ts +12 -0
  93. package/dist/modules/legacyWalletBook/getWalletConnectCatalog/getChainFromWalletSchema/getChainFromWalletSchema.d.ts.map +1 -1
  94. package/dist/modules/legacyWalletBook/getWalletConnectCatalog/getChainsFromWalletSchema/getChainsFromWalletSchema.d.ts +26 -0
  95. package/dist/modules/legacyWalletBook/getWalletConnectCatalog/getChainsFromWalletSchema/getChainsFromWalletSchema.d.ts.map +1 -0
  96. package/dist/modules/legacyWalletBook/hasUsableDeeplink/hasUsableDeeplink.d.ts +18 -0
  97. package/dist/modules/legacyWalletBook/hasUsableDeeplink/hasUsableDeeplink.d.ts.map +1 -0
  98. package/dist/modules/legacyWalletBook/legacyWalletBook.types.d.ts +2 -2
  99. package/dist/modules/legacyWalletBook/legacyWalletBook.types.d.ts.map +1 -1
  100. package/dist/modules/swap/executeSwapTransaction/executeSwapTransaction.d.ts +13 -1
  101. package/dist/modules/swap/executeSwapTransaction/executeSwapTransaction.d.ts.map +1 -1
  102. package/dist/modules/user/refreshAuth/refreshAuth.d.ts.map +1 -1
  103. package/dist/modules/walletOptionsCatalogue/buildMetaMaskSdkUriOptions/buildMetaMaskSdkUriOptions.d.ts +27 -0
  104. package/dist/modules/walletOptionsCatalogue/buildMetaMaskSdkUriOptions/buildMetaMaskSdkUriOptions.d.ts.map +1 -0
  105. package/dist/modules/walletOptionsCatalogue/buildWalletConnectOptions/buildWalletConnectOptions.d.ts +26 -0
  106. package/dist/modules/walletOptionsCatalogue/buildWalletConnectOptions/buildWalletConnectOptions.d.ts.map +1 -0
  107. package/dist/modules/walletOptionsCatalogue/buildWalletOption/buildWalletOption.d.ts +11 -4
  108. package/dist/modules/walletOptionsCatalogue/buildWalletOption/buildWalletOption.d.ts.map +1 -1
  109. package/dist/modules/walletOptionsCatalogue/buildWithWalletProviderOptions/buildWithWalletProviderOptions.d.ts.map +1 -1
  110. package/dist/modules/walletOptionsCatalogue/getInstallationLinkForCurrentPlatform/getInstallationLinkForCurrentPlatform.d.ts +35 -0
  111. package/dist/modules/walletOptionsCatalogue/getInstallationLinkForCurrentPlatform/getInstallationLinkForCurrentPlatform.d.ts.map +1 -0
  112. package/dist/modules/walletOptionsCatalogue/getInstallationLinkForCurrentPlatform/index.d.ts +2 -0
  113. package/dist/modules/walletOptionsCatalogue/getInstallationLinkForCurrentPlatform/index.d.ts.map +1 -0
  114. package/dist/modules/walletOptionsCatalogue/getWalletOptionsCatalogue/getWalletOptionsCatalogue.d.ts +6 -1
  115. package/dist/modules/walletOptionsCatalogue/getWalletOptionsCatalogue/getWalletOptionsCatalogue.d.ts.map +1 -1
  116. package/dist/modules/walletOptionsCatalogue/walletOptionsCatalogue.types.d.ts +11 -0
  117. package/dist/modules/walletOptionsCatalogue/walletOptionsCatalogue.types.d.ts.map +1 -1
  118. package/dist/modules/wallets/constants.d.ts +7 -0
  119. package/dist/modules/wallets/constants.d.ts.map +1 -1
  120. package/dist/modules/wallets/getAvailableWalletProvidersData/getAvailableWalletProvidersData.d.ts.map +1 -1
  121. package/dist/modules/wallets/hasWalletProviderConnectMethod/hasWalletProviderConnectMethod.d.ts +26 -0
  122. package/dist/modules/wallets/hasWalletProviderConnectMethod/hasWalletProviderConnectMethod.d.ts.map +1 -0
  123. package/dist/modules/wallets/hasWalletProviderConnectMethod/index.d.ts +2 -0
  124. package/dist/modules/wallets/hasWalletProviderConnectMethod/index.d.ts.map +1 -0
  125. package/dist/modules/wallets/isAnyWalletAccountConnected/index.d.ts +2 -0
  126. package/dist/modules/wallets/isAnyWalletAccountConnected/index.d.ts.map +1 -0
  127. package/dist/modules/wallets/isAnyWalletAccountConnected/isAnyWalletAccountConnected.d.ts +14 -0
  128. package/dist/modules/wallets/isAnyWalletAccountConnected/isAnyWalletAccountConnected.d.ts.map +1 -0
  129. package/dist/modules/wallets/networks/getBalance/getBalance.d.ts +6 -17
  130. package/dist/modules/wallets/networks/getBalance/getBalance.d.ts.map +1 -1
  131. package/dist/modules/wallets/networks/getNativeBalance/getNativeBalance.d.ts +24 -0
  132. package/dist/modules/wallets/networks/getNativeBalance/getNativeBalance.d.ts.map +1 -0
  133. package/dist/modules/wallets/networks/getNativeBalance/index.d.ts +2 -0
  134. package/dist/modules/wallets/networks/getNativeBalance/index.d.ts.map +1 -0
  135. package/dist/modules/wallets/walletProvider/walletProvider.types.d.ts +10 -0
  136. package/dist/modules/wallets/walletProvider/walletProvider.types.d.ts.map +1 -1
  137. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  138. package/dist/utils/getChainFromWalletBookIdentifier/getChainFromWalletBookIdentifier.d.ts +22 -0
  139. package/dist/utils/getChainFromWalletBookIdentifier/getChainFromWalletBookIdentifier.d.ts.map +1 -0
  140. package/dist/utils/getChainFromWalletBookIdentifier/index.d.ts +2 -0
  141. package/dist/utils/getChainFromWalletBookIdentifier/index.d.ts.map +1 -0
  142. package/dist/utils/getNativeLinkScheme/getNativeLinkScheme.d.ts +18 -0
  143. package/dist/utils/getNativeLinkScheme/getNativeLinkScheme.d.ts.map +1 -0
  144. package/dist/utils/getNativeLinkScheme/index.d.ts +3 -0
  145. package/dist/utils/getNativeLinkScheme/index.d.ts.map +1 -0
  146. package/dist/utils/isMobile/isMobile.d.ts +8 -0
  147. package/dist/utils/isMobile/isMobile.d.ts.map +1 -1
  148. package/dist/waas.cjs +8 -9
  149. package/dist/waas.cjs.map +1 -1
  150. package/dist/waas.esm.js +3 -3
  151. package/dist/waas.native.esm.js +3 -3
  152. package/dist/waasCore.cjs +3 -4
  153. package/dist/waasCore.cjs.map +1 -1
  154. package/dist/waasCore.esm.js +3 -3
  155. package/dist/waasCore.native.esm.js +3 -3
  156. package/package.json +4 -4
  157. package/dist/InvalidParamError-BPMi0iWC.esm.js.map +0 -1
  158. package/dist/InvalidParamError-CDmVW2DS.native.esm.js.map +0 -1
  159. package/dist/InvalidParamError-DEmLKJKZ.cjs.map +0 -1
  160. package/dist/NotWaasWalletAccountError-BZsBHRQe.cjs.map +0 -1
  161. package/dist/NotWaasWalletAccountError-Chpne8_Q.native.esm.js.map +0 -1
  162. package/dist/NotWaasWalletAccountError-Cntietge.esm.js.map +0 -1
  163. package/dist/getNetworkProviderFromNetworkId-CEeFL-gV.esm.js.map +0 -1
  164. package/dist/getNetworkProviderFromNetworkId-JGrKwBj7.native.esm.js.map +0 -1
  165. package/dist/getNetworkProviderFromNetworkId-szJOsbQN.cjs.map +0 -1
  166. package/dist/getVerifiedCredentialForWalletAccount-B46O0B48.cjs +0 -887
  167. package/dist/getVerifiedCredentialForWalletAccount-B46O0B48.cjs.map +0 -1
  168. package/dist/getVerifiedCredentialForWalletAccount-CyykSi-M.native.esm.js +0 -701
  169. package/dist/getVerifiedCredentialForWalletAccount-CyykSi-M.native.esm.js.map +0 -1
  170. package/dist/getVerifiedCredentialForWalletAccount-DzwIoeHm.esm.js +0 -701
  171. package/dist/getVerifiedCredentialForWalletAccount-DzwIoeHm.esm.js.map +0 -1
  172. package/dist/modules/walletOptionsCatalogue/buildUriDeeplinkOptions/buildUriDeeplinkOptions.d.ts +0 -28
  173. package/dist/modules/walletOptionsCatalogue/buildUriDeeplinkOptions/buildUriDeeplinkOptions.d.ts.map +0 -1
  174. package/dist/modules/walletOptionsCatalogue/buildUriDeeplinkOptions/index.d.ts +0 -2
  175. package/dist/modules/walletOptionsCatalogue/buildUriDeeplinkOptions/index.d.ts.map +0 -1
  176. package/dist/modules/walletOptionsCatalogue/buildUriDeeplinkOptions/resolveUriConnectionType/index.d.ts +0 -2
  177. package/dist/modules/walletOptionsCatalogue/buildUriDeeplinkOptions/resolveUriConnectionType/index.d.ts.map +0 -1
  178. package/dist/modules/walletOptionsCatalogue/buildUriDeeplinkOptions/resolveUriConnectionType/resolveUriConnectionType.d.ts +0 -17
  179. package/dist/modules/walletOptionsCatalogue/buildUriDeeplinkOptions/resolveUriConnectionType/resolveUriConnectionType.d.ts.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getVerifiedCredentialForWalletAccount-BuUCX040.esm.js","names":["newState: Partial<DynamicCoreState>","walletProvider"],"sources":["../src/modules/wallets/emitWalletAccountsChangedEvent/emitWalletAccountsChangedEvent.ts","../src/modules/auth/updateAuthFromVerifyResponse/checkAndRaiseWalletAccountsChangedEvent/checkAndRaiseWalletAccountsChangedEvent.ts","../src/modules/mfa/isUserMissingMfaAuth/isUserMissingMfaAuth.ts","../src/modules/wallets/getWalletProviders/getWalletProviders.ts","../src/modules/waas/isWaasWalletProvider/isWaasWalletProvider.ts","../src/modules/waas/findWaasWalletProviderByChain/findWaasWalletProviderByChain.ts","../src/modules/waas/isWaasWalletAccount/isWaasWalletAccount.ts","../src/modules/waas/restoreUserSharesForAllWalletAccounts/restoreUserSharesForAllWalletAccounts.ts","../src/modules/auth/decodeJwt/decodeJwt.ts","../src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/normalizeScopes/normalizeScopes.ts","../src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/parseElevatedAccessToken/parseElevatedAccessToken.ts","../src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/upsertElevatedAccessToken/upsertElevatedAccessToken.ts","../src/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.ts","../src/modules/wallets/getWalletProviderByKey/getWalletProviderByKey.ts","../src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.ts"],"sourcesContent":["import type { DynamicClient } from '../../../client/types';\nimport { emitEvent } from '../../clientEvents';\nimport { getWalletAccounts } from '../getWalletAccounts';\n\n/**\n * Emits the `walletAccountsChanged` event.\n * @not-instrumented\n */\nexport const emitWalletAccountsChangedEvent = (client: DynamicClient): void => {\n const walletAccounts = getWalletAccounts(client);\n\n emitEvent(\n {\n args: { walletAccounts },\n event: 'walletAccountsChanged',\n },\n client\n );\n};\n","import { getCore } from '../../../../client/core/getCore';\nimport type { DynamicClient } from '../../../../client/types';\nimport { emitWalletAccountsChangedEvent } from '../../../wallets/emitWalletAccountsChangedEvent';\nimport { getWalletAccountsFromState } from '../../../wallets/getWalletAccounts/getWalletAccountsFromState';\n\ntype CheckAndRaiseWalletAccountsChangedEventParams = {\n previousState: Readonly<DynamicCoreState>;\n};\n\n/** @not-instrumented */\nexport const checkAndRaiseWalletAccountsChangedEvent = (\n { previousState }: CheckAndRaiseWalletAccountsChangedEventParams,\n client: DynamicClient\n) => {\n const core = getCore(client);\n\n const walletAccountsHashBefore = getWalletAccountsHash(previousState, client);\n\n const walletAccountsHashAfter = getWalletAccountsHash(\n core.state.get(),\n client\n );\n\n if (walletAccountsHashBefore !== walletAccountsHashAfter) {\n emitWalletAccountsChangedEvent(client);\n }\n};\n\n \n \nconst getWalletAccountsHash = (\n state: Readonly<DynamicCoreState>,\n client: DynamicClient\n) =>\n getWalletAccountsFromState(state, client)\n .map((walletAccount) => JSON.stringify(walletAccount))\n .sort()\n .join('-');\n","import { getDefaultClient } from '../../../client/defaultClient';\nimport { assertDefined } from '../../../utils/assertDefined';\n\n/**\n * Checks if the user requires additional MFA authentication.\n *\n * This function determines if the current user session requires\n * additional multi-factor authentication to access certain features.\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns True if the user needs additional MFA authentication, false otherwise.\n * @not-instrumented\n */\nexport const isUserMissingMfaAuth = (client = getDefaultClient()) => {\n const user = client.user;\n\n assertDefined(user, 'User not logged in');\n\n return Boolean(user.scope?.includes('requiresAdditionalAuth'));\n};\n","import type { DynamicClient } from '../../../client/types';\nimport { getWalletProviderRegistry } from '../walletProviderRegistry';\n\n/**\n * Get all available wallet providers to interact with internally.\n * @not-instrumented\n */\nexport const getWalletProviders = (client: DynamicClient) => {\n const walletProviderRegistry = getWalletProviderRegistry(client);\n\n return walletProviderRegistry.listProviders();\n};\n","import type { WalletProvider } from '../../wallets/walletProvider';\nimport { DYNAMIC_WAAS_METADATA } from '../constants';\nimport type { WaasWalletProvider } from '../waas.types';\n\n/** @not-instrumented */\nexport const isWaasWalletProvider = (\n walletProvider: WalletProvider\n): walletProvider is WaasWalletProvider => {\n return walletProvider.key.includes(\n DYNAMIC_WAAS_METADATA.normalizedWalletName\n );\n};\n","import { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport type { DynamicClient } from '../../../client/types/DynamicClient';\nimport type { Chain } from '../../chain';\nimport { getWalletProviders } from '../../wallets/getWalletProviders';\nimport { formatWalletProviderKey } from '../../wallets/utils/formatWalletProviderKey';\nimport { DYNAMIC_WAAS_METADATA } from '../constants';\nimport { isWaasWalletProvider } from '../isWaasWalletProvider';\nimport type { WaasWalletProvider } from '../waas.types';\n\ntype FindWaasWalletProviderByChainParams = {\n chain: Chain;\n};\n\n/** @not-instrumented */\nexport const findWaasWalletProviderByChain = (\n { chain }: FindWaasWalletProviderByChainParams,\n client: DynamicClient\n): WaasWalletProvider | null => {\n const providers = getWalletProviders(client);\n\n const waasProviderKey = formatWalletProviderKey({\n chain,\n displayName: DYNAMIC_WAAS_METADATA.displayName,\n walletProviderType: WalletProviderEnum.EmbeddedWallet,\n });\n\n const waasProvider = providers.find(\n (provider) => provider.key === waasProviderKey && provider.chain === chain\n );\n\n if (!waasProvider || !isWaasWalletProvider(waasProvider)) {\n return null;\n }\n\n return waasProvider;\n};\n","import type { WalletAccount } from '../../wallets/walletAccount';\nimport { DYNAMIC_WAAS_METADATA } from '../constants';\n\ntype IsWaasWalletAccountParams = {\n walletAccount: WalletAccount;\n};\n\n/**\n * This function determines whether the provided wallet account is a Dynamic\n * WaaS wallet account.\n *\n * @param params.walletAccount - The wallet account to check.\n * @returns True if the wallet account is a WaaS wallet account, false otherwise.\n * @not-instrumented\n */\nexport const isWaasWalletAccount = ({\n walletAccount,\n}: IsWaasWalletAccountParams): boolean => {\n return walletAccount.walletProviderKey.includes(\n DYNAMIC_WAAS_METADATA.normalizedWalletName\n );\n};\n","import type { DynamicClient } from '../../../client/types';\nimport { isUserMissingMfaAuth } from '../../mfa/isUserMissingMfaAuth';\nimport { getWalletAccounts } from '../../wallets/getWalletAccounts';\nimport { findWaasWalletProviderByChain } from '../findWaasWalletProviderByChain';\nimport { isWaasWalletAccount } from '../isWaasWalletAccount';\n\n/** @not-instrumented */\nexport const restoreUserSharesForAllWalletAccounts = async (\n client: DynamicClient\n) => {\n /**\n * Restoring the user shares will fails if the user is missing the MFA auth.\n * This early return prevents the attempt to restore the user shares to fail\n * when we know it will fails and just add noise to the logs.\n */\n if (isUserMissingMfaAuth(client)) {\n return;\n }\n\n const walletAccounts = getWalletAccounts(client);\n\n const waasWalletAccounts = walletAccounts.filter((walletAccount) =>\n isWaasWalletAccount({ walletAccount })\n );\n\n await Promise.all(\n waasWalletAccounts.map(async (walletAccount) => {\n const provider = findWaasWalletProviderByChain(\n { chain: walletAccount.chain },\n client\n );\n\n /**\n * The environment might not have the embedded wallet extensions installed.\n * In that case there is no provider for the chain and we can skip restoring the user share.\n */\n if (!provider) return;\n\n return provider.restoreUserShareForWalletAccount({ walletAccount });\n })\n );\n};\n","import { InvalidParamError } from '../../../errors/InvalidParamError';\n\nexport type JwtPayload = {\n [key: string]: unknown;\n exp: number;\n iat: number;\n scope: string;\n singleUse?: boolean;\n sub: string;\n};\n\n/**\n * Decodes a JWT token and returns the full payload.\n *\n * This function extracts and returns the complete JWT payload including scopes,\n * expiration time, and other claims.\n *\n * @param jwt - The JWT token string.\n * @returns The decoded JWT payload object.\n * @throws InvalidParamError if the token is invalid or cannot be decoded.\n *\n * @example\n * ```typescript\n * const payload = decodeJwt(jwt);\n * // Returns: { scopes: ['wallet:export'], exp: 1234567890, ... }\n * ```\n * @not-instrumented\n */\n// eslint-disable-next-line custom-rules/require-single-object-param\nexport const decodeJwt = (jwt: string): JwtPayload => {\n try {\n // JWT format: header.payload.signature\n const parts = jwt.split('.');\n if (parts.length !== 3) {\n throw new InvalidParamError('Invalid JWT format');\n }\n\n // Decode the payload (second part)\n // Base64URL decode: replace URL-safe characters and decode\n const base64Payload = parts[1].replaceAll('-', '+').replaceAll('_', '/');\n // Add padding if needed\n const paddedPayload =\n base64Payload + '='.repeat((4 - (base64Payload.length % 4)) % 4);\n const decodedPayload = atob(paddedPayload);\n const claims = JSON.parse(decodedPayload) as JwtPayload;\n\n return claims;\n } catch (error) {\n if (error instanceof InvalidParamError) {\n throw error;\n }\n throw new InvalidParamError(\n `Failed to decode JWT: ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n }\n};\n","/**\n * Normalizes scopes by deduplicating and sorting them.\n * This creates a canonical representation for comparison.\n *\n * @param scopes - Array of scope strings (may contain duplicates)\n * @returns Normalized, sorted array of unique scopes\n * @not-instrumented\n */\n// eslint-disable-next-line custom-rules/require-single-object-param\nexport const normalizeScopes = (scopes: string[]): string[] => {\n return [...new Set(scopes)].sort((a, b) => a.localeCompare(b));\n};\n","import { decodeJwt } from '../../../decodeJwt';\nimport type { ParsedElevatedAccessToken } from '../elevatedAccessTokens.types';\nimport { normalizeScopes } from '../normalizeScopes';\n\nexport type ParseElevatedAccessTokenOptions = {\n /** JWT string containing the elevated access token. */\n token: string;\n};\n\n/**\n * Validates and parses an elevated access token from a JWT string.\n * Extracts scopes, expiration, and validates the token structure.\n *\n * Policy decisions:\n * - Tokens without scopes are rejected (returns null)\n * - Tokens with empty scopes array are rejected (returns null)\n * - Tokens without exp field are rejected (returns null)\n * - Expired tokens are rejected (returns null)\n *\n * @returns Parsed token data or null if token is invalid/expired\n * @not-instrumented\n */\nexport const parseElevatedAccessToken = ({\n token,\n}: ParseElevatedAccessTokenOptions): ParsedElevatedAccessToken | null => {\n const payload = decodeJwt(token);\n const rawScopeClaim = payload?.scope;\n const processedScopes = rawScopeClaim?.split(' ') ?? [];\n const filteredScopes = processedScopes.filter((s) => s.length > 0);\n const singleUse = payload.singleUse ?? false;\n\n // Reject tokens without scopes or with empty scopes\n if (!filteredScopes || filteredScopes.length === 0) {\n return null;\n }\n\n // Reject tokens without exp field\n if (!payload.exp) {\n return null;\n }\n\n // Convert exp (seconds) to Date (milliseconds)\n const expiresAt = new Date(payload.exp * 1000);\n\n // Reject expired tokens\n if (expiresAt <= new Date()) {\n return null;\n }\n\n return {\n expiresAt,\n normalizedScopes: normalizeScopes(filteredScopes),\n scopes: filteredScopes,\n singleUse,\n token,\n };\n};\n","import type {\n ElevatedAccessToken,\n ParsedElevatedAccessToken,\n} from '../elevatedAccessTokens.types';\nimport { normalizeScopes } from '../normalizeScopes';\n\n/**\n * Upserts an elevated access token into the current tokens array.\n *\n * Policy: Only one token per normalized scope-set is allowed.\n * If a token with the same normalized scopes exists, it is replaced.\n * This ensures we don't accumulate multiple tokens for the same scope combination.\n *\n * @param currentTokens - Current array of elevated access tokens\n * @param newToken - New token to upsert\n * @returns Updated array of tokens with the new token upserted\n * @not-instrumented\n */\nexport const upsertElevatedAccessToken = ({\n currentTokens,\n newToken,\n}: {\n currentTokens: ElevatedAccessToken[];\n newToken: ParsedElevatedAccessToken;\n}): ElevatedAccessToken[] => {\n const newScopeKey = normalizeScopes(newToken.scopes).join(' ');\n\n // Remove any existing token with the same normalized scopes\n const filteredTokens = currentTokens.filter((existingToken) => {\n const existingScopeKey = normalizeScopes(existingToken.scopes).join(' ');\n return existingScopeKey !== newScopeKey;\n });\n\n // Add the new token\n return [\n ...filteredTokens,\n {\n expiresAt: newToken.expiresAt,\n scopes: newToken.scopes,\n singleUse: newToken.singleUse,\n token: newToken.token,\n },\n ];\n};\n","import type { VerifyResponse } from '@dynamic-labs/sdk-api-core';\n\nimport { getCore } from '../../../client/core/getCore';\nimport type { DynamicCoreState } from '../../../client/core/types';\nimport type { DynamicClient } from '../../../client/types';\nimport { setCookie } from '../../../utils/setCookie';\nimport { isCookieEnabled } from '../../projectSettings/isCookieEnabled';\nimport { restoreUserSharesForAllWalletAccounts } from '../../waas/restoreUserSharesForAllWalletAccounts';\nimport { DYNAMIC_AUTH_COOKIE_NAME } from '../consts';\nimport { checkAndRaiseWalletAccountsChangedEvent } from './checkAndRaiseWalletAccountsChangedEvent';\nimport { parseElevatedAccessToken } from './elevatedAccessTokens/parseElevatedAccessToken';\nimport { upsertElevatedAccessToken } from './elevatedAccessTokens/upsertElevatedAccessToken';\n\ntype UpdateAuthFromVerifyResponseParams = {\n response: VerifyResponse;\n};\n\n/** @not-instrumented */\nexport const updateAuthFromVerifyResponse = (\n { response }: UpdateAuthFromVerifyResponseParams,\n client: DynamicClient\n) => {\n const core = getCore(client);\n\n const previousState = { ...core.state.get() };\n\n const { user, minifiedJwt, jwt, expiresAt, mfaToken, elevatedAccessToken } =\n response;\n\n // Expires at is in seconds, so we need to convert it to milliseconds\n const sessionExpiresAt = new Date(expiresAt * 1000);\n\n const newState: Partial<DynamicCoreState> = {\n legacyToken: jwt ?? null,\n sessionExpiresAt: sessionExpiresAt,\n token: minifiedJwt ?? null,\n user,\n };\n\n // only override the mfaToken if a new one is provided in the response\n if (mfaToken) {\n newState.mfaToken = mfaToken;\n }\n\n // Add elevated access token to the array if a new one is provided in the response\n // Policy: Only one token per normalized scope-set is allowed (old tokens are replaced)\n // Always preserve existing tokens to ensure they're synced to storage\n const currentTokens = core.state.get().elevatedAccessTokens || [];\n newState.elevatedAccessTokens = currentTokens;\n \n if (elevatedAccessToken) {\n const parsedToken = parseElevatedAccessToken({\n token: elevatedAccessToken,\n });\n if (parsedToken) {\n newState.elevatedAccessTokens = upsertElevatedAccessToken({\n currentTokens,\n newToken: parsedToken,\n });\n }\n }\n\n core.state.set(newState);\n\n /**\n * For customers using a sandbox environment with cookies enabled, we need to set the cookie\n * programmatically because Redcoast won't set the cookie via headers. We set the cookie programmatically\n * so customers can access the cookie from document.cookie consistently between sandbox and live environments.\n */\n if (minifiedJwt && isCookieEnabled(client)) {\n const expireDate = sessionExpiresAt.toUTCString();\n\n setCookie(\n `${DYNAMIC_AUTH_COOKIE_NAME}=${minifiedJwt}; expires=${expireDate}; path=/; SameSite=Lax`\n );\n }\n\n checkAndRaiseWalletAccountsChangedEvent({ previousState }, client);\n\n // if the user is logging in, we should restore user shares\n // for all wallet accounts for performance reasons\n const isUserLoggingIn = !previousState.user && Boolean(newState.user);\n if (isUserLoggingIn) {\n void restoreUserSharesForAllWalletAccounts(client);\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/** @not-instrumented */\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","import type { DynamicClient } from '../../../../client/types/DynamicClient';\nimport type { WalletAccount } from '../../walletAccount';\n\ntype GetVerifiedCredentialForWalletAccountParams = {\n walletAccount: WalletAccount;\n};\n\n/** @not-instrumented */\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"],"mappings":";;;;;;;;AAQA,MAAa,kCAAkC,WAAgC;AAG7E,WACE;EACE,MAAM,EAAE,gBAJW,kBAAkB,OAAO,EAIpB;EACxB,OAAO;EACR,EACD,OACD;;;;;;ACPH,MAAa,2CACX,EAAE,iBACF,WACG;CACH,MAAM,OAAO,QAAQ,OAAO;AAS5B,KAPiC,sBAAsB,eAAe,OAAO,KAE7C,sBAC9B,KAAK,MAAM,KAAK,EAChB,OACD,CAGC,gCAA+B,OAAO;;AAM1C,MAAM,yBACJ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AM,oBAAoB,MACrC,OAAO,GAAG,OAAO,cAAc,qBACjC"}
@@ -0,0 +1,269 @@
1
+ import { C as getWalletAccountsFromState, L as setCookie, N as emitEvent, S as getWalletAccounts, X as assertDefined, Y as isCookieEnabled, ct as getDefaultClient, d as DYNAMIC_AUTH_COOKIE_NAME, ft as getCore, g as NoWalletProviderFoundError, i as DYNAMIC_WAAS_METADATA, m as getWalletProviderRegistry, t as InvalidParamError, w as formatWalletProviderKey } from "./InvalidParamError-DkAMYJOW.native.esm.js";
2
+ import { WalletProviderEnum } from "@dynamic-labs/sdk-api-core";
3
+
4
+ //#region src/modules/wallets/emitWalletAccountsChangedEvent/emitWalletAccountsChangedEvent.ts
5
+ /**
6
+ * Emits the `walletAccountsChanged` event.
7
+ * @not-instrumented
8
+ */
9
+ const emitWalletAccountsChangedEvent = (client) => {
10
+ emitEvent({
11
+ args: { walletAccounts: getWalletAccounts(client) },
12
+ event: "walletAccountsChanged"
13
+ }, client);
14
+ };
15
+
16
+ //#endregion
17
+ //#region src/modules/auth/updateAuthFromVerifyResponse/checkAndRaiseWalletAccountsChangedEvent/checkAndRaiseWalletAccountsChangedEvent.ts
18
+ /** @not-instrumented */
19
+ const checkAndRaiseWalletAccountsChangedEvent = ({ previousState }, client) => {
20
+ const core = getCore(client);
21
+ if (getWalletAccountsHash(previousState, client) !== getWalletAccountsHash(core.state.get(), client)) emitWalletAccountsChangedEvent(client);
22
+ };
23
+ const getWalletAccountsHash = (state, client) => getWalletAccountsFromState(state, client).map((walletAccount) => JSON.stringify(walletAccount)).sort().join("-");
24
+
25
+ //#endregion
26
+ //#region src/modules/mfa/isUserMissingMfaAuth/isUserMissingMfaAuth.ts
27
+ /**
28
+ * Checks if the user requires additional MFA authentication.
29
+ *
30
+ * This function determines if the current user session requires
31
+ * additional multi-factor authentication to access certain features.
32
+ *
33
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
34
+ * @returns True if the user needs additional MFA authentication, false otherwise.
35
+ * @not-instrumented
36
+ */
37
+ const isUserMissingMfaAuth = (client = getDefaultClient()) => {
38
+ const user = client.user;
39
+ assertDefined(user, "User not logged in");
40
+ return Boolean(user.scope?.includes("requiresAdditionalAuth"));
41
+ };
42
+
43
+ //#endregion
44
+ //#region src/modules/wallets/getWalletProviders/getWalletProviders.ts
45
+ /**
46
+ * Get all available wallet providers to interact with internally.
47
+ * @not-instrumented
48
+ */
49
+ const getWalletProviders = (client) => {
50
+ return getWalletProviderRegistry(client).listProviders();
51
+ };
52
+
53
+ //#endregion
54
+ //#region src/modules/waas/isWaasWalletProvider/isWaasWalletProvider.ts
55
+ /** @not-instrumented */
56
+ const isWaasWalletProvider = (walletProvider) => {
57
+ return walletProvider.key.includes(DYNAMIC_WAAS_METADATA.normalizedWalletName);
58
+ };
59
+
60
+ //#endregion
61
+ //#region src/modules/waas/findWaasWalletProviderByChain/findWaasWalletProviderByChain.ts
62
+ /** @not-instrumented */
63
+ const findWaasWalletProviderByChain = ({ chain }, client) => {
64
+ const providers = getWalletProviders(client);
65
+ const waasProviderKey = formatWalletProviderKey({
66
+ chain,
67
+ displayName: DYNAMIC_WAAS_METADATA.displayName,
68
+ walletProviderType: WalletProviderEnum.EmbeddedWallet
69
+ });
70
+ const waasProvider = providers.find((provider) => provider.key === waasProviderKey && provider.chain === chain);
71
+ if (!waasProvider || !isWaasWalletProvider(waasProvider)) return null;
72
+ return waasProvider;
73
+ };
74
+
75
+ //#endregion
76
+ //#region src/modules/waas/isWaasWalletAccount/isWaasWalletAccount.ts
77
+ /**
78
+ * This function determines whether the provided wallet account is a Dynamic
79
+ * WaaS wallet account.
80
+ *
81
+ * @param params.walletAccount - The wallet account to check.
82
+ * @returns True if the wallet account is a WaaS wallet account, false otherwise.
83
+ * @not-instrumented
84
+ */
85
+ const isWaasWalletAccount = ({ walletAccount }) => {
86
+ return walletAccount.walletProviderKey.includes(DYNAMIC_WAAS_METADATA.normalizedWalletName);
87
+ };
88
+
89
+ //#endregion
90
+ //#region src/modules/waas/restoreUserSharesForAllWalletAccounts/restoreUserSharesForAllWalletAccounts.ts
91
+ /** @not-instrumented */
92
+ const restoreUserSharesForAllWalletAccounts = async (client) => {
93
+ /**
94
+ * Restoring the user shares will fails if the user is missing the MFA auth.
95
+ * This early return prevents the attempt to restore the user shares to fail
96
+ * when we know it will fails and just add noise to the logs.
97
+ */
98
+ if (isUserMissingMfaAuth(client)) return;
99
+ const waasWalletAccounts = getWalletAccounts(client).filter((walletAccount) => isWaasWalletAccount({ walletAccount }));
100
+ await Promise.all(waasWalletAccounts.map(async (walletAccount) => {
101
+ const provider = findWaasWalletProviderByChain({ chain: walletAccount.chain }, client);
102
+ /**
103
+ * The environment might not have the embedded wallet extensions installed.
104
+ * In that case there is no provider for the chain and we can skip restoring the user share.
105
+ */
106
+ if (!provider) return;
107
+ return provider.restoreUserShareForWalletAccount({ walletAccount });
108
+ }));
109
+ };
110
+
111
+ //#endregion
112
+ //#region src/modules/auth/decodeJwt/decodeJwt.ts
113
+ /**
114
+ * Decodes a JWT token and returns the full payload.
115
+ *
116
+ * This function extracts and returns the complete JWT payload including scopes,
117
+ * expiration time, and other claims.
118
+ *
119
+ * @param jwt - The JWT token string.
120
+ * @returns The decoded JWT payload object.
121
+ * @throws InvalidParamError if the token is invalid or cannot be decoded.
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * const payload = decodeJwt(jwt);
126
+ * // Returns: { scopes: ['wallet:export'], exp: 1234567890, ... }
127
+ * ```
128
+ * @not-instrumented
129
+ */
130
+ const decodeJwt = (jwt) => {
131
+ try {
132
+ const parts = jwt.split(".");
133
+ if (parts.length !== 3) throw new InvalidParamError("Invalid JWT format");
134
+ const base64Payload = parts[1].replaceAll("-", "+").replaceAll("_", "/");
135
+ const paddedPayload = base64Payload + "=".repeat((4 - base64Payload.length % 4) % 4);
136
+ const decodedPayload = atob(paddedPayload);
137
+ return JSON.parse(decodedPayload);
138
+ } catch (error) {
139
+ if (error instanceof InvalidParamError) throw error;
140
+ throw new InvalidParamError(`Failed to decode JWT: ${error instanceof Error ? error.message : String(error)}`);
141
+ }
142
+ };
143
+
144
+ //#endregion
145
+ //#region src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/normalizeScopes/normalizeScopes.ts
146
+ /**
147
+ * Normalizes scopes by deduplicating and sorting them.
148
+ * This creates a canonical representation for comparison.
149
+ *
150
+ * @param scopes - Array of scope strings (may contain duplicates)
151
+ * @returns Normalized, sorted array of unique scopes
152
+ * @not-instrumented
153
+ */
154
+ const normalizeScopes = (scopes) => {
155
+ return [...new Set(scopes)].sort((a, b) => a.localeCompare(b));
156
+ };
157
+
158
+ //#endregion
159
+ //#region src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/parseElevatedAccessToken/parseElevatedAccessToken.ts
160
+ /**
161
+ * Validates and parses an elevated access token from a JWT string.
162
+ * Extracts scopes, expiration, and validates the token structure.
163
+ *
164
+ * Policy decisions:
165
+ * - Tokens without scopes are rejected (returns null)
166
+ * - Tokens with empty scopes array are rejected (returns null)
167
+ * - Tokens without exp field are rejected (returns null)
168
+ * - Expired tokens are rejected (returns null)
169
+ *
170
+ * @returns Parsed token data or null if token is invalid/expired
171
+ * @not-instrumented
172
+ */
173
+ const parseElevatedAccessToken = ({ token }) => {
174
+ const payload = decodeJwt(token);
175
+ const filteredScopes = ((payload?.scope)?.split(" ") ?? []).filter((s) => s.length > 0);
176
+ const singleUse = payload.singleUse ?? false;
177
+ if (!filteredScopes || filteredScopes.length === 0) return null;
178
+ if (!payload.exp) return null;
179
+ const expiresAt = /* @__PURE__ */ new Date(payload.exp * 1e3);
180
+ if (expiresAt <= /* @__PURE__ */ new Date()) return null;
181
+ return {
182
+ expiresAt,
183
+ normalizedScopes: normalizeScopes(filteredScopes),
184
+ scopes: filteredScopes,
185
+ singleUse,
186
+ token
187
+ };
188
+ };
189
+
190
+ //#endregion
191
+ //#region src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/upsertElevatedAccessToken/upsertElevatedAccessToken.ts
192
+ /**
193
+ * Upserts an elevated access token into the current tokens array.
194
+ *
195
+ * Policy: Only one token per normalized scope-set is allowed.
196
+ * If a token with the same normalized scopes exists, it is replaced.
197
+ * This ensures we don't accumulate multiple tokens for the same scope combination.
198
+ *
199
+ * @param currentTokens - Current array of elevated access tokens
200
+ * @param newToken - New token to upsert
201
+ * @returns Updated array of tokens with the new token upserted
202
+ * @not-instrumented
203
+ */
204
+ const upsertElevatedAccessToken = ({ currentTokens, newToken }) => {
205
+ const newScopeKey = normalizeScopes(newToken.scopes).join(" ");
206
+ return [...currentTokens.filter((existingToken) => {
207
+ return normalizeScopes(existingToken.scopes).join(" ") !== newScopeKey;
208
+ }), {
209
+ expiresAt: newToken.expiresAt,
210
+ scopes: newToken.scopes,
211
+ singleUse: newToken.singleUse,
212
+ token: newToken.token
213
+ }];
214
+ };
215
+
216
+ //#endregion
217
+ //#region src/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.ts
218
+ /** @not-instrumented */
219
+ const updateAuthFromVerifyResponse = ({ response }, client) => {
220
+ const core = getCore(client);
221
+ const previousState = { ...core.state.get() };
222
+ const { user, minifiedJwt, jwt, expiresAt, mfaToken, elevatedAccessToken } = response;
223
+ const sessionExpiresAt = /* @__PURE__ */ new Date(expiresAt * 1e3);
224
+ const newState = {
225
+ legacyToken: jwt ?? null,
226
+ sessionExpiresAt,
227
+ token: minifiedJwt ?? null,
228
+ user
229
+ };
230
+ if (mfaToken) newState.mfaToken = mfaToken;
231
+ const currentTokens = core.state.get().elevatedAccessTokens || [];
232
+ newState.elevatedAccessTokens = currentTokens;
233
+ if (elevatedAccessToken) {
234
+ const parsedToken = parseElevatedAccessToken({ token: elevatedAccessToken });
235
+ if (parsedToken) newState.elevatedAccessTokens = upsertElevatedAccessToken({
236
+ currentTokens,
237
+ newToken: parsedToken
238
+ });
239
+ }
240
+ core.state.set(newState);
241
+ /**
242
+ * For customers using a sandbox environment with cookies enabled, we need to set the cookie
243
+ * programmatically because Redcoast won't set the cookie via headers. We set the cookie programmatically
244
+ * so customers can access the cookie from document.cookie consistently between sandbox and live environments.
245
+ */
246
+ if (minifiedJwt && isCookieEnabled(client)) setCookie(`${DYNAMIC_AUTH_COOKIE_NAME}=${minifiedJwt}; expires=${sessionExpiresAt.toUTCString()}; path=/; SameSite=Lax`);
247
+ checkAndRaiseWalletAccountsChangedEvent({ previousState }, client);
248
+ if (!previousState.user && Boolean(newState.user)) restoreUserSharesForAllWalletAccounts(client);
249
+ };
250
+
251
+ //#endregion
252
+ //#region src/modules/wallets/getWalletProviderByKey/getWalletProviderByKey.ts
253
+ /** @not-instrumented */
254
+ const getWalletProviderByKey = ({ walletProviderKey }, client) => {
255
+ const walletProvider = getWalletProviders(client).find((walletProvider$1) => walletProvider$1.key === walletProviderKey);
256
+ if (!walletProvider) throw new NoWalletProviderFoundError({ walletProviderKey });
257
+ return walletProvider;
258
+ };
259
+
260
+ //#endregion
261
+ //#region src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.ts
262
+ /** @not-instrumented */
263
+ const getVerifiedCredentialForWalletAccount = ({ walletAccount }, client) => {
264
+ return client.user?.verifiedCredentials.find((vc) => vc.id === walletAccount.verifiedCredentialId);
265
+ };
266
+
267
+ //#endregion
268
+ export { parseElevatedAccessToken as a, findWaasWalletProviderByChain as c, isUserMissingMfaAuth as d, checkAndRaiseWalletAccountsChangedEvent as f, upsertElevatedAccessToken as i, isWaasWalletProvider as l, getWalletProviderByKey as n, restoreUserSharesForAllWalletAccounts as o, emitWalletAccountsChangedEvent as p, updateAuthFromVerifyResponse as r, isWaasWalletAccount as s, getVerifiedCredentialForWalletAccount as t, getWalletProviders as u };
269
+ //# sourceMappingURL=getVerifiedCredentialForWalletAccount-Ciac5d5L.native.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getVerifiedCredentialForWalletAccount-Ciac5d5L.native.esm.js","names":["newState: Partial<DynamicCoreState>","walletProvider"],"sources":["../src/modules/wallets/emitWalletAccountsChangedEvent/emitWalletAccountsChangedEvent.ts","../src/modules/auth/updateAuthFromVerifyResponse/checkAndRaiseWalletAccountsChangedEvent/checkAndRaiseWalletAccountsChangedEvent.ts","../src/modules/mfa/isUserMissingMfaAuth/isUserMissingMfaAuth.ts","../src/modules/wallets/getWalletProviders/getWalletProviders.ts","../src/modules/waas/isWaasWalletProvider/isWaasWalletProvider.ts","../src/modules/waas/findWaasWalletProviderByChain/findWaasWalletProviderByChain.ts","../src/modules/waas/isWaasWalletAccount/isWaasWalletAccount.ts","../src/modules/waas/restoreUserSharesForAllWalletAccounts/restoreUserSharesForAllWalletAccounts.ts","../src/modules/auth/decodeJwt/decodeJwt.ts","../src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/normalizeScopes/normalizeScopes.ts","../src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/parseElevatedAccessToken/parseElevatedAccessToken.ts","../src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/upsertElevatedAccessToken/upsertElevatedAccessToken.ts","../src/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.ts","../src/modules/wallets/getWalletProviderByKey/getWalletProviderByKey.ts","../src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.ts"],"sourcesContent":["import type { DynamicClient } from '../../../client/types';\nimport { emitEvent } from '../../clientEvents';\nimport { getWalletAccounts } from '../getWalletAccounts';\n\n/**\n * Emits the `walletAccountsChanged` event.\n * @not-instrumented\n */\nexport const emitWalletAccountsChangedEvent = (client: DynamicClient): void => {\n const walletAccounts = getWalletAccounts(client);\n\n emitEvent(\n {\n args: { walletAccounts },\n event: 'walletAccountsChanged',\n },\n client\n );\n};\n","import { getCore } from '../../../../client/core/getCore';\nimport type { DynamicClient } from '../../../../client/types';\nimport { emitWalletAccountsChangedEvent } from '../../../wallets/emitWalletAccountsChangedEvent';\nimport { getWalletAccountsFromState } from '../../../wallets/getWalletAccounts/getWalletAccountsFromState';\n\ntype CheckAndRaiseWalletAccountsChangedEventParams = {\n previousState: Readonly<DynamicCoreState>;\n};\n\n/** @not-instrumented */\nexport const checkAndRaiseWalletAccountsChangedEvent = (\n { previousState }: CheckAndRaiseWalletAccountsChangedEventParams,\n client: DynamicClient\n) => {\n const core = getCore(client);\n\n const walletAccountsHashBefore = getWalletAccountsHash(previousState, client);\n\n const walletAccountsHashAfter = getWalletAccountsHash(\n core.state.get(),\n client\n );\n\n if (walletAccountsHashBefore !== walletAccountsHashAfter) {\n emitWalletAccountsChangedEvent(client);\n }\n};\n\n \n \nconst getWalletAccountsHash = (\n state: Readonly<DynamicCoreState>,\n client: DynamicClient\n) =>\n getWalletAccountsFromState(state, client)\n .map((walletAccount) => JSON.stringify(walletAccount))\n .sort()\n .join('-');\n","import { getDefaultClient } from '../../../client/defaultClient';\nimport { assertDefined } from '../../../utils/assertDefined';\n\n/**\n * Checks if the user requires additional MFA authentication.\n *\n * This function determines if the current user session requires\n * additional multi-factor authentication to access certain features.\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns True if the user needs additional MFA authentication, false otherwise.\n * @not-instrumented\n */\nexport const isUserMissingMfaAuth = (client = getDefaultClient()) => {\n const user = client.user;\n\n assertDefined(user, 'User not logged in');\n\n return Boolean(user.scope?.includes('requiresAdditionalAuth'));\n};\n","import type { DynamicClient } from '../../../client/types';\nimport { getWalletProviderRegistry } from '../walletProviderRegistry';\n\n/**\n * Get all available wallet providers to interact with internally.\n * @not-instrumented\n */\nexport const getWalletProviders = (client: DynamicClient) => {\n const walletProviderRegistry = getWalletProviderRegistry(client);\n\n return walletProviderRegistry.listProviders();\n};\n","import type { WalletProvider } from '../../wallets/walletProvider';\nimport { DYNAMIC_WAAS_METADATA } from '../constants';\nimport type { WaasWalletProvider } from '../waas.types';\n\n/** @not-instrumented */\nexport const isWaasWalletProvider = (\n walletProvider: WalletProvider\n): walletProvider is WaasWalletProvider => {\n return walletProvider.key.includes(\n DYNAMIC_WAAS_METADATA.normalizedWalletName\n );\n};\n","import { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport type { DynamicClient } from '../../../client/types/DynamicClient';\nimport type { Chain } from '../../chain';\nimport { getWalletProviders } from '../../wallets/getWalletProviders';\nimport { formatWalletProviderKey } from '../../wallets/utils/formatWalletProviderKey';\nimport { DYNAMIC_WAAS_METADATA } from '../constants';\nimport { isWaasWalletProvider } from '../isWaasWalletProvider';\nimport type { WaasWalletProvider } from '../waas.types';\n\ntype FindWaasWalletProviderByChainParams = {\n chain: Chain;\n};\n\n/** @not-instrumented */\nexport const findWaasWalletProviderByChain = (\n { chain }: FindWaasWalletProviderByChainParams,\n client: DynamicClient\n): WaasWalletProvider | null => {\n const providers = getWalletProviders(client);\n\n const waasProviderKey = formatWalletProviderKey({\n chain,\n displayName: DYNAMIC_WAAS_METADATA.displayName,\n walletProviderType: WalletProviderEnum.EmbeddedWallet,\n });\n\n const waasProvider = providers.find(\n (provider) => provider.key === waasProviderKey && provider.chain === chain\n );\n\n if (!waasProvider || !isWaasWalletProvider(waasProvider)) {\n return null;\n }\n\n return waasProvider;\n};\n","import type { WalletAccount } from '../../wallets/walletAccount';\nimport { DYNAMIC_WAAS_METADATA } from '../constants';\n\ntype IsWaasWalletAccountParams = {\n walletAccount: WalletAccount;\n};\n\n/**\n * This function determines whether the provided wallet account is a Dynamic\n * WaaS wallet account.\n *\n * @param params.walletAccount - The wallet account to check.\n * @returns True if the wallet account is a WaaS wallet account, false otherwise.\n * @not-instrumented\n */\nexport const isWaasWalletAccount = ({\n walletAccount,\n}: IsWaasWalletAccountParams): boolean => {\n return walletAccount.walletProviderKey.includes(\n DYNAMIC_WAAS_METADATA.normalizedWalletName\n );\n};\n","import type { DynamicClient } from '../../../client/types';\nimport { isUserMissingMfaAuth } from '../../mfa/isUserMissingMfaAuth';\nimport { getWalletAccounts } from '../../wallets/getWalletAccounts';\nimport { findWaasWalletProviderByChain } from '../findWaasWalletProviderByChain';\nimport { isWaasWalletAccount } from '../isWaasWalletAccount';\n\n/** @not-instrumented */\nexport const restoreUserSharesForAllWalletAccounts = async (\n client: DynamicClient\n) => {\n /**\n * Restoring the user shares will fails if the user is missing the MFA auth.\n * This early return prevents the attempt to restore the user shares to fail\n * when we know it will fails and just add noise to the logs.\n */\n if (isUserMissingMfaAuth(client)) {\n return;\n }\n\n const walletAccounts = getWalletAccounts(client);\n\n const waasWalletAccounts = walletAccounts.filter((walletAccount) =>\n isWaasWalletAccount({ walletAccount })\n );\n\n await Promise.all(\n waasWalletAccounts.map(async (walletAccount) => {\n const provider = findWaasWalletProviderByChain(\n { chain: walletAccount.chain },\n client\n );\n\n /**\n * The environment might not have the embedded wallet extensions installed.\n * In that case there is no provider for the chain and we can skip restoring the user share.\n */\n if (!provider) return;\n\n return provider.restoreUserShareForWalletAccount({ walletAccount });\n })\n );\n};\n","import { InvalidParamError } from '../../../errors/InvalidParamError';\n\nexport type JwtPayload = {\n [key: string]: unknown;\n exp: number;\n iat: number;\n scope: string;\n singleUse?: boolean;\n sub: string;\n};\n\n/**\n * Decodes a JWT token and returns the full payload.\n *\n * This function extracts and returns the complete JWT payload including scopes,\n * expiration time, and other claims.\n *\n * @param jwt - The JWT token string.\n * @returns The decoded JWT payload object.\n * @throws InvalidParamError if the token is invalid or cannot be decoded.\n *\n * @example\n * ```typescript\n * const payload = decodeJwt(jwt);\n * // Returns: { scopes: ['wallet:export'], exp: 1234567890, ... }\n * ```\n * @not-instrumented\n */\n// eslint-disable-next-line custom-rules/require-single-object-param\nexport const decodeJwt = (jwt: string): JwtPayload => {\n try {\n // JWT format: header.payload.signature\n const parts = jwt.split('.');\n if (parts.length !== 3) {\n throw new InvalidParamError('Invalid JWT format');\n }\n\n // Decode the payload (second part)\n // Base64URL decode: replace URL-safe characters and decode\n const base64Payload = parts[1].replaceAll('-', '+').replaceAll('_', '/');\n // Add padding if needed\n const paddedPayload =\n base64Payload + '='.repeat((4 - (base64Payload.length % 4)) % 4);\n const decodedPayload = atob(paddedPayload);\n const claims = JSON.parse(decodedPayload) as JwtPayload;\n\n return claims;\n } catch (error) {\n if (error instanceof InvalidParamError) {\n throw error;\n }\n throw new InvalidParamError(\n `Failed to decode JWT: ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n }\n};\n","/**\n * Normalizes scopes by deduplicating and sorting them.\n * This creates a canonical representation for comparison.\n *\n * @param scopes - Array of scope strings (may contain duplicates)\n * @returns Normalized, sorted array of unique scopes\n * @not-instrumented\n */\n// eslint-disable-next-line custom-rules/require-single-object-param\nexport const normalizeScopes = (scopes: string[]): string[] => {\n return [...new Set(scopes)].sort((a, b) => a.localeCompare(b));\n};\n","import { decodeJwt } from '../../../decodeJwt';\nimport type { ParsedElevatedAccessToken } from '../elevatedAccessTokens.types';\nimport { normalizeScopes } from '../normalizeScopes';\n\nexport type ParseElevatedAccessTokenOptions = {\n /** JWT string containing the elevated access token. */\n token: string;\n};\n\n/**\n * Validates and parses an elevated access token from a JWT string.\n * Extracts scopes, expiration, and validates the token structure.\n *\n * Policy decisions:\n * - Tokens without scopes are rejected (returns null)\n * - Tokens with empty scopes array are rejected (returns null)\n * - Tokens without exp field are rejected (returns null)\n * - Expired tokens are rejected (returns null)\n *\n * @returns Parsed token data or null if token is invalid/expired\n * @not-instrumented\n */\nexport const parseElevatedAccessToken = ({\n token,\n}: ParseElevatedAccessTokenOptions): ParsedElevatedAccessToken | null => {\n const payload = decodeJwt(token);\n const rawScopeClaim = payload?.scope;\n const processedScopes = rawScopeClaim?.split(' ') ?? [];\n const filteredScopes = processedScopes.filter((s) => s.length > 0);\n const singleUse = payload.singleUse ?? false;\n\n // Reject tokens without scopes or with empty scopes\n if (!filteredScopes || filteredScopes.length === 0) {\n return null;\n }\n\n // Reject tokens without exp field\n if (!payload.exp) {\n return null;\n }\n\n // Convert exp (seconds) to Date (milliseconds)\n const expiresAt = new Date(payload.exp * 1000);\n\n // Reject expired tokens\n if (expiresAt <= new Date()) {\n return null;\n }\n\n return {\n expiresAt,\n normalizedScopes: normalizeScopes(filteredScopes),\n scopes: filteredScopes,\n singleUse,\n token,\n };\n};\n","import type {\n ElevatedAccessToken,\n ParsedElevatedAccessToken,\n} from '../elevatedAccessTokens.types';\nimport { normalizeScopes } from '../normalizeScopes';\n\n/**\n * Upserts an elevated access token into the current tokens array.\n *\n * Policy: Only one token per normalized scope-set is allowed.\n * If a token with the same normalized scopes exists, it is replaced.\n * This ensures we don't accumulate multiple tokens for the same scope combination.\n *\n * @param currentTokens - Current array of elevated access tokens\n * @param newToken - New token to upsert\n * @returns Updated array of tokens with the new token upserted\n * @not-instrumented\n */\nexport const upsertElevatedAccessToken = ({\n currentTokens,\n newToken,\n}: {\n currentTokens: ElevatedAccessToken[];\n newToken: ParsedElevatedAccessToken;\n}): ElevatedAccessToken[] => {\n const newScopeKey = normalizeScopes(newToken.scopes).join(' ');\n\n // Remove any existing token with the same normalized scopes\n const filteredTokens = currentTokens.filter((existingToken) => {\n const existingScopeKey = normalizeScopes(existingToken.scopes).join(' ');\n return existingScopeKey !== newScopeKey;\n });\n\n // Add the new token\n return [\n ...filteredTokens,\n {\n expiresAt: newToken.expiresAt,\n scopes: newToken.scopes,\n singleUse: newToken.singleUse,\n token: newToken.token,\n },\n ];\n};\n","import type { VerifyResponse } from '@dynamic-labs/sdk-api-core';\n\nimport { getCore } from '../../../client/core/getCore';\nimport type { DynamicCoreState } from '../../../client/core/types';\nimport type { DynamicClient } from '../../../client/types';\nimport { setCookie } from '../../../utils/setCookie';\nimport { isCookieEnabled } from '../../projectSettings/isCookieEnabled';\nimport { restoreUserSharesForAllWalletAccounts } from '../../waas/restoreUserSharesForAllWalletAccounts';\nimport { DYNAMIC_AUTH_COOKIE_NAME } from '../consts';\nimport { checkAndRaiseWalletAccountsChangedEvent } from './checkAndRaiseWalletAccountsChangedEvent';\nimport { parseElevatedAccessToken } from './elevatedAccessTokens/parseElevatedAccessToken';\nimport { upsertElevatedAccessToken } from './elevatedAccessTokens/upsertElevatedAccessToken';\n\ntype UpdateAuthFromVerifyResponseParams = {\n response: VerifyResponse;\n};\n\n/** @not-instrumented */\nexport const updateAuthFromVerifyResponse = (\n { response }: UpdateAuthFromVerifyResponseParams,\n client: DynamicClient\n) => {\n const core = getCore(client);\n\n const previousState = { ...core.state.get() };\n\n const { user, minifiedJwt, jwt, expiresAt, mfaToken, elevatedAccessToken } =\n response;\n\n // Expires at is in seconds, so we need to convert it to milliseconds\n const sessionExpiresAt = new Date(expiresAt * 1000);\n\n const newState: Partial<DynamicCoreState> = {\n legacyToken: jwt ?? null,\n sessionExpiresAt: sessionExpiresAt,\n token: minifiedJwt ?? null,\n user,\n };\n\n // only override the mfaToken if a new one is provided in the response\n if (mfaToken) {\n newState.mfaToken = mfaToken;\n }\n\n // Add elevated access token to the array if a new one is provided in the response\n // Policy: Only one token per normalized scope-set is allowed (old tokens are replaced)\n // Always preserve existing tokens to ensure they're synced to storage\n const currentTokens = core.state.get().elevatedAccessTokens || [];\n newState.elevatedAccessTokens = currentTokens;\n \n if (elevatedAccessToken) {\n const parsedToken = parseElevatedAccessToken({\n token: elevatedAccessToken,\n });\n if (parsedToken) {\n newState.elevatedAccessTokens = upsertElevatedAccessToken({\n currentTokens,\n newToken: parsedToken,\n });\n }\n }\n\n core.state.set(newState);\n\n /**\n * For customers using a sandbox environment with cookies enabled, we need to set the cookie\n * programmatically because Redcoast won't set the cookie via headers. We set the cookie programmatically\n * so customers can access the cookie from document.cookie consistently between sandbox and live environments.\n */\n if (minifiedJwt && isCookieEnabled(client)) {\n const expireDate = sessionExpiresAt.toUTCString();\n\n setCookie(\n `${DYNAMIC_AUTH_COOKIE_NAME}=${minifiedJwt}; expires=${expireDate}; path=/; SameSite=Lax`\n );\n }\n\n checkAndRaiseWalletAccountsChangedEvent({ previousState }, client);\n\n // if the user is logging in, we should restore user shares\n // for all wallet accounts for performance reasons\n const isUserLoggingIn = !previousState.user && Boolean(newState.user);\n if (isUserLoggingIn) {\n void restoreUserSharesForAllWalletAccounts(client);\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/** @not-instrumented */\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","import type { DynamicClient } from '../../../../client/types/DynamicClient';\nimport type { WalletAccount } from '../../walletAccount';\n\ntype GetVerifiedCredentialForWalletAccountParams = {\n walletAccount: WalletAccount;\n};\n\n/** @not-instrumented */\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"],"mappings":";;;;;;;;AAQA,MAAa,kCAAkC,WAAgC;AAG7E,WACE;EACE,MAAM,EAAE,gBAJW,kBAAkB,OAAO,EAIpB;EACxB,OAAO;EACR,EACD,OACD;;;;;;ACPH,MAAa,2CACX,EAAE,iBACF,WACG;CACH,MAAM,OAAO,QAAQ,OAAO;AAS5B,KAPiC,sBAAsB,eAAe,OAAO,KAE7C,sBAC9B,KAAK,MAAM,KAAK,EAChB,OACD,CAGC,gCAA+B,OAAO;;AAM1C,MAAM,yBACJ,OACA,WAEA,2BAA2B,OAAO,OAAO,CACtC,KAAK,kBAAkB,KAAK,UAAU,cAAc,CAAC,CACrD,MAAM,CACN,KAAK,IAAI;;;;;;;;;;;;;;ACxBd,MAAa,wBAAwB,SAAS,kBAAkB,KAAK;CACnE,MAAM,OAAO,OAAO;AAEpB,eAAc,MAAM,qBAAqB;AAE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