@dynamic-labs-sdk/client 1.30.2 → 1.30.3

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 (331) hide show
  1. package/dist/{updateAuthFromVerifyResponse-CTvWpZLa.native.esm.js → apiClient-BAKktP8E.native.esm.js} +557 -465
  2. package/dist/apiClient-BAKktP8E.native.esm.js.map +1 -0
  3. package/dist/client/types/DynamicClient.d.ts +1 -1
  4. package/dist/client/types/DynamicClient.d.ts.map +1 -1
  5. package/dist/core.cjs +61 -61
  6. package/dist/core.cjs.map +1 -1
  7. package/dist/core.esm.js +5 -5
  8. package/dist/core.native.esm.js +5 -5
  9. package/dist/errors/WaasRbacStaleRetryUnsafeError.d.ts +36 -0
  10. package/dist/errors/WaasRbacStaleRetryUnsafeError.d.ts.map +1 -0
  11. package/dist/exports/index.d.ts +16 -4
  12. package/dist/exports/index.d.ts.map +1 -1
  13. package/dist/exports/waas.d.ts +3 -2
  14. package/dist/exports/waas.d.ts.map +1 -1
  15. package/dist/{getNetworkProviderFromNetworkId--X0cb1ad.native.esm.js → getNetworkProviderFromNetworkId-Bk5ssM29.native.esm.js} +3 -3
  16. package/dist/{getNetworkProviderFromNetworkId--X0cb1ad.native.esm.js.map → getNetworkProviderFromNetworkId-Bk5ssM29.native.esm.js.map} +1 -1
  17. package/dist/{getNetworkProviderFromNetworkId-CamHn2s3.esm.js → getNetworkProviderFromNetworkId-CHlaSDGa.esm.js} +2 -2
  18. package/dist/{getNetworkProviderFromNetworkId-CamHn2s3.esm.js.map → getNetworkProviderFromNetworkId-CHlaSDGa.esm.js.map} +1 -1
  19. package/dist/{getNetworkProviderFromNetworkId-igDf2OPy.cjs → getNetworkProviderFromNetworkId-D3308b6r.cjs} +51 -51
  20. package/dist/{getNetworkProviderFromNetworkId-igDf2OPy.cjs.map → getNetworkProviderFromNetworkId-D3308b6r.cjs.map} +1 -1
  21. package/dist/{getSignedSessionId-DY-ietfO.esm.js → getSignedSessionId-B_iFJpYg.esm.js} +3 -3
  22. package/dist/{getSignedSessionId-DY-ietfO.esm.js.map → getSignedSessionId-B_iFJpYg.esm.js.map} +1 -1
  23. package/dist/{getSignedSessionId-DGa_pu-i.cjs → getSignedSessionId-CW2VWZxK.cjs} +11 -11
  24. package/dist/{getSignedSessionId-DGa_pu-i.cjs.map → getSignedSessionId-CW2VWZxK.cjs.map} +1 -1
  25. package/dist/{getSignedSessionId--XNTxNFo.native.esm.js → getSignedSessionId-D-KMuDMG.native.esm.js} +3 -3
  26. package/dist/{getSignedSessionId--XNTxNFo.native.esm.js.map → getSignedSessionId-D-KMuDMG.native.esm.js.map} +1 -1
  27. package/dist/{getWalletProviderByKey-DzpmoNlv.cjs → getVerifiedCredentialForWalletAccount-DZS1-K7H.cjs} +10 -10
  28. package/dist/getVerifiedCredentialForWalletAccount-DZS1-K7H.cjs.map +1 -0
  29. package/dist/{getWalletProviderByKey-xqyD3ybv.esm.js → getVerifiedCredentialForWalletAccount-Dqb6bpAF.esm.js} +10 -10
  30. package/dist/getVerifiedCredentialForWalletAccount-Dqb6bpAF.esm.js.map +1 -0
  31. package/dist/index.cjs +677 -666
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.esm.js +46 -17
  34. package/dist/index.esm.js.map +1 -1
  35. package/dist/index.native.esm.js +46 -17
  36. package/dist/index.native.esm.js.map +1 -1
  37. package/dist/{isMfaRequiredForAction-CatS60F6.esm.js → isMfaRequiredForAction-B0pOYhvq.esm.js} +2 -2
  38. package/dist/isMfaRequiredForAction-B0pOYhvq.esm.js.map +1 -0
  39. package/dist/{isMfaRequiredForAction-DKfoMhEk.cjs → isMfaRequiredForAction-BSclknqX.cjs} +11 -11
  40. package/dist/isMfaRequiredForAction-BSclknqX.cjs.map +1 -0
  41. package/dist/{isMfaRequiredForAction-BcJvy7Gw.native.esm.js → isMfaRequiredForAction-BvYKQLus.native.esm.js} +2 -2
  42. package/dist/isMfaRequiredForAction-BvYKQLus.native.esm.js.map +1 -0
  43. package/dist/{isUserOnboardingComplete-jkAQQVdP.esm.js → isUserOnboardingComplete-CfG3LQ6q.native.esm.js} +47 -4
  44. package/dist/isUserOnboardingComplete-CfG3LQ6q.native.esm.js.map +1 -0
  45. package/dist/{isUserOnboardingComplete-jv_idxWY.cjs → isUserOnboardingComplete-CwZbDdOC.cjs} +63 -14
  46. package/dist/isUserOnboardingComplete-CwZbDdOC.cjs.map +1 -0
  47. package/dist/{isUserOnboardingComplete-BWVuE4Jg.native.esm.js → isUserOnboardingComplete-DtGJK_dW.esm.js} +47 -4
  48. package/dist/isUserOnboardingComplete-DtGJK_dW.esm.js.map +1 -0
  49. package/dist/{updateAuthFromVerifyResponse-BLgNMqwN.esm.js → logoutWithReason-CIsCVAUE.esm.js} +679 -587
  50. package/dist/logoutWithReason-CIsCVAUE.esm.js.map +1 -0
  51. package/dist/{updateAuthFromVerifyResponse-Dsw-eAro.cjs → logoutWithReason-DEM0fiik.cjs} +691 -587
  52. package/dist/logoutWithReason-DEM0fiik.cjs.map +1 -0
  53. package/dist/{getWalletProviderByKey-Cl6WDOoD.native.esm.js → logoutWithReason-vnu8SeVK.native.esm.js} +19 -19
  54. package/dist/logoutWithReason-vnu8SeVK.native.esm.js.map +1 -0
  55. package/dist/migrateFromFireblocks-BOx3tLrP.cjs +163 -0
  56. package/dist/migrateFromFireblocks-BOx3tLrP.cjs.map +1 -0
  57. package/dist/migrateFromFireblocks-BvDbMJWJ.native.esm.js +128 -0
  58. package/dist/migrateFromFireblocks-BvDbMJWJ.native.esm.js.map +1 -0
  59. package/dist/migrateFromFireblocks-_Vt4cY3Y.esm.js +128 -0
  60. package/dist/migrateFromFireblocks-_Vt4cY3Y.esm.js.map +1 -0
  61. package/dist/modules/apiClient/apiClient.types.d.ts +1 -1
  62. package/dist/modules/apiClient/apiClient.types.d.ts.map +1 -1
  63. package/dist/modules/apiClient/createApiClient.d.ts.map +1 -1
  64. package/dist/modules/apiClient/utils/rbacStaleMiddleware/createRbacStaleMiddleware.d.ts +10 -0
  65. package/dist/modules/apiClient/utils/rbacStaleMiddleware/createRbacStaleMiddleware.d.ts.map +1 -0
  66. package/dist/modules/auth/auth.types.d.ts +45 -0
  67. package/dist/modules/auth/auth.types.d.ts.map +1 -0
  68. package/dist/modules/auth/checkStepUpAuth/checkStepUpAuth.d.ts +2 -1
  69. package/dist/modules/auth/checkStepUpAuth/checkStepUpAuth.d.ts.map +1 -1
  70. package/dist/modules/auth/consts.d.ts +9 -0
  71. package/dist/modules/auth/consts.d.ts.map +1 -1
  72. package/dist/modules/auth/createVisit/createVisit.d.ts.map +1 -1
  73. package/dist/modules/auth/externalAuth/requestExternalAuthElevatedToken/requestExternalAuthElevatedToken.d.ts +1 -1
  74. package/dist/modules/auth/externalAuth/requestExternalAuthElevatedToken/requestExternalAuthElevatedToken.d.ts.map +1 -1
  75. package/dist/modules/auth/externalAuth/signInWithExternalJwt/signInWithExternalJwt.d.ts +1 -1
  76. package/dist/modules/auth/externalAuth/signInWithExternalJwt/signInWithExternalJwt.d.ts.map +1 -1
  77. package/dist/modules/auth/getActionAuthorizationTokens/getActionAuthorizationTokens.d.ts +2 -1
  78. package/dist/modules/auth/getActionAuthorizationTokens/getActionAuthorizationTokens.d.ts.map +1 -1
  79. package/dist/modules/auth/mergeUserAccounts/mergeUserAccounts.d.ts +4 -3
  80. package/dist/modules/auth/mergeUserAccounts/mergeUserAccounts.d.ts.map +1 -1
  81. package/dist/modules/auth/passkeys/getPasskeys/getPasskeys.d.ts +1 -1
  82. package/dist/modules/auth/passkeys/getPasskeys/getPasskeys.d.ts.map +1 -1
  83. package/dist/modules/auth/passkeys/registerPasskey/registerPasskey.d.ts +2 -1
  84. package/dist/modules/auth/passkeys/registerPasskey/registerPasskey.d.ts.map +1 -1
  85. package/dist/modules/auth/passkeys/serverAuthenticatePasskey/serverAuthenticatePasskey.d.ts +3 -1
  86. package/dist/modules/auth/passkeys/serverAuthenticatePasskey/serverAuthenticatePasskey.d.ts.map +1 -1
  87. package/dist/modules/auth/passkeys/serverRegisterPasskey/serverRegisterPasskey.d.ts +2 -1
  88. package/dist/modules/auth/passkeys/serverRegisterPasskey/serverRegisterPasskey.d.ts.map +1 -1
  89. package/dist/modules/auth/passkeys/signInWithPasskey/signInWithPasskey.d.ts +1 -1
  90. package/dist/modules/auth/passkeys/signInWithPasskey/signInWithPasskey.d.ts.map +1 -1
  91. package/dist/modules/auth/social/oauth/completeSocialAuthentication/completeSocialAuthentication.d.ts +1 -1
  92. package/dist/modules/auth/social/oauth/completeSocialAuthentication/completeSocialAuthentication.d.ts.map +1 -1
  93. package/dist/modules/auth/social/oauth/completeSocialRedirect/completeSocialRedirect.types.d.ts +1 -1
  94. package/dist/modules/auth/social/oauth/completeSocialRedirect/completeSocialRedirect.types.d.ts.map +1 -1
  95. package/dist/modules/auth/social/oauth/processSocialCallback/processSocialCallback.d.ts +1 -1
  96. package/dist/modules/auth/social/oauth/processSocialCallback/processSocialCallback.d.ts.map +1 -1
  97. package/dist/modules/auth/social/oauth/signInWithSocialPopUp/signInWithSocialPopUp.types.d.ts +1 -1
  98. package/dist/modules/auth/social/oauth/signInWithSocialPopUp/signInWithSocialPopUp.types.d.ts.map +1 -1
  99. package/dist/modules/auth/social/oauth/unlinkSocialAccount/unlinkSocialAccount.d.ts +1 -1
  100. package/dist/modules/auth/social/oauth/unlinkSocialAccount/unlinkSocialAccount.d.ts.map +1 -1
  101. package/dist/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.d.ts +1 -1
  102. package/dist/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.d.ts.map +1 -1
  103. package/dist/modules/balances/balances.types.d.ts +59 -0
  104. package/dist/modules/balances/balances.types.d.ts.map +1 -0
  105. package/dist/modules/balances/getMultichainTokenBalances/getMultichainTokenBalances.d.ts +1 -1
  106. package/dist/modules/balances/getMultichainTokenBalances/getMultichainTokenBalances.d.ts.map +1 -1
  107. package/dist/modules/balances/getTokenBalances/getTokenBalances.d.ts +1 -1
  108. package/dist/modules/balances/getTokenBalances/getTokenBalances.d.ts.map +1 -1
  109. package/dist/modules/checkout/broadcastCheckoutTransaction/broadcastCheckoutTransaction.d.ts +1 -1
  110. package/dist/modules/checkout/broadcastCheckoutTransaction/broadcastCheckoutTransaction.d.ts.map +1 -1
  111. package/dist/modules/checkout/checkout.types.d.ts +10 -2
  112. package/dist/modules/checkout/checkout.types.d.ts.map +1 -1
  113. package/dist/modules/deviceRegistration/completeDeviceRegistration/completeDeviceRegistration.d.ts +1 -1
  114. package/dist/modules/deviceRegistration/completeDeviceRegistration/completeDeviceRegistration.d.ts.map +1 -1
  115. package/dist/modules/deviceRegistration/deviceRegistration.types.d.ts +9 -0
  116. package/dist/modules/deviceRegistration/deviceRegistration.types.d.ts.map +1 -0
  117. package/dist/modules/deviceRegistration/getRegisteredDevices/getRegisteredDevices.d.ts +1 -1
  118. package/dist/modules/deviceRegistration/getRegisteredDevices/getRegisteredDevices.d.ts.map +1 -1
  119. package/dist/modules/funding/coinbase/coinbase.types.d.ts +2 -40
  120. package/dist/modules/funding/coinbase/coinbase.types.d.ts.map +1 -1
  121. package/dist/modules/funding/coinbase/createCoinbaseExchangeTransfer/createCoinbaseExchangeTransfer.d.ts +1 -1
  122. package/dist/modules/funding/coinbase/createCoinbaseExchangeTransfer/createCoinbaseExchangeTransfer.d.ts.map +1 -1
  123. package/dist/modules/funding/coinbase/utils/validateUserCredentialsForCoinbaseOnrampOrder/validateUserCredentialsForCoinbaseOnrampOrder.d.ts +2 -2
  124. package/dist/modules/funding/coinbase/utils/validateUserCredentialsForCoinbaseOnrampOrder/validateUserCredentialsForCoinbaseOnrampOrder.d.ts.map +1 -1
  125. package/dist/modules/funding/cryptoDotCom/cryptoDotCom.types.d.ts +2 -2
  126. package/dist/modules/funding/cryptoDotCom/cryptoDotCom.types.d.ts.map +1 -1
  127. package/dist/modules/funding/funding.types.d.ts +26 -0
  128. package/dist/modules/funding/funding.types.d.ts.map +1 -0
  129. package/dist/modules/funding/kraken/createKrakenExchangeTransfer/createKrakenExchangeTransfer.d.ts +4 -4
  130. package/dist/modules/funding/kraken/createKrakenExchangeTransfer/createKrakenExchangeTransfer.d.ts.map +1 -1
  131. package/dist/modules/mfa/authenticateMfaRecoveryCode/authenticateMfaRecoveryCode.d.ts +3 -1
  132. package/dist/modules/mfa/authenticateMfaRecoveryCode/authenticateMfaRecoveryCode.d.ts.map +1 -1
  133. package/dist/modules/mfa/authenticatePasskeyMFA/authenticatePasskeyMFA.d.ts +3 -1
  134. package/dist/modules/mfa/authenticatePasskeyMFA/authenticatePasskeyMFA.d.ts.map +1 -1
  135. package/dist/modules/mfa/authenticateTotpMfaDevice/authenticateTotpMfaDevice.d.ts +3 -1
  136. package/dist/modules/mfa/authenticateTotpMfaDevice/authenticateTotpMfaDevice.d.ts.map +1 -1
  137. package/dist/modules/mfa/createNewMfaRecoveryCodes/createNewMfaRecoveryCodes.d.ts +1 -1
  138. package/dist/modules/mfa/createNewMfaRecoveryCodes/createNewMfaRecoveryCodes.d.ts.map +1 -1
  139. package/dist/modules/mfa/getMfaDevices/getMfaDevices.d.ts +1 -1
  140. package/dist/modules/mfa/getMfaDevices/getMfaDevices.d.ts.map +1 -1
  141. package/dist/modules/mfa/getMfaMethods/getMfaMethods.d.ts +1 -1
  142. package/dist/modules/mfa/getMfaMethods/getMfaMethods.d.ts.map +1 -1
  143. package/dist/modules/mfa/getMfaRecoveryCodes/getMfaRecoveryCodes.d.ts +1 -1
  144. package/dist/modules/mfa/getMfaRecoveryCodes/getMfaRecoveryCodes.d.ts.map +1 -1
  145. package/dist/modules/mfa/isMfaRequiredForAction/isMfaRequiredForAction.d.ts +1 -1
  146. package/dist/modules/mfa/isMfaRequiredForAction/isMfaRequiredForAction.d.ts.map +1 -1
  147. package/dist/modules/mfa/mfa.consts.d.ts +10 -0
  148. package/dist/modules/mfa/mfa.consts.d.ts.map +1 -0
  149. package/dist/modules/mfa/mfa.types.d.ts +66 -1
  150. package/dist/modules/mfa/mfa.types.d.ts.map +1 -1
  151. package/dist/modules/mfa/registerTotpMfaDevice/registerTotpMfaDevice.d.ts +1 -1
  152. package/dist/modules/mfa/registerTotpMfaDevice/registerTotpMfaDevice.d.ts.map +1 -1
  153. package/dist/modules/otp/verifyOTP/verifyOTP.d.ts +2 -1
  154. package/dist/modules/otp/verifyOTP/verifyOTP.d.ts.map +1 -1
  155. package/dist/modules/otp/verifyOTP/verifyOTPForUserSignIn/verifyOTPForUserSignIn.d.ts +1 -1
  156. package/dist/modules/otp/verifyOTP/verifyOTPForUserSignIn/verifyOTPForUserSignIn.d.ts.map +1 -1
  157. package/dist/modules/projectSettings/fetchProjectSettings/fetchProjectSettings.d.ts +1 -1
  158. package/dist/modules/projectSettings/fetchProjectSettings/fetchProjectSettings.d.ts.map +1 -1
  159. package/dist/modules/projectSettings/projectSettings.types.d.ts +15 -0
  160. package/dist/modules/projectSettings/projectSettings.types.d.ts.map +1 -0
  161. package/dist/modules/simulation/simulation.types.d.ts +27 -1
  162. package/dist/modules/simulation/simulation.types.d.ts.map +1 -1
  163. package/dist/modules/storageSync/schema.d.ts +2 -2
  164. package/dist/modules/storageSync/schema.d.ts.map +1 -1
  165. package/dist/modules/swap/swap.types.d.ts +15 -2
  166. package/dist/modules/swap/swap.types.d.ts.map +1 -1
  167. package/dist/modules/user/refreshAuth/refreshAuth.d.ts +2 -2
  168. package/dist/modules/user/refreshAuth/refreshAuth.d.ts.map +1 -1
  169. package/dist/modules/user/refreshUser/refreshUser.d.ts +3 -3
  170. package/dist/modules/user/refreshUser/refreshUser.d.ts.map +1 -1
  171. package/dist/modules/user/user.consts.d.ts +19 -0
  172. package/dist/modules/user/user.consts.d.ts.map +1 -0
  173. package/dist/modules/user/user.types.d.ts +22 -2
  174. package/dist/modules/user/user.types.d.ts.map +1 -1
  175. package/dist/modules/waas/businessAccounts/businessAccounts.types.d.ts +1 -1
  176. package/dist/modules/waas/businessAccounts/businessAccounts.types.d.ts.map +1 -1
  177. package/dist/modules/waas/createWaasProvider/createWaasProvider.d.ts.map +1 -1
  178. package/dist/modules/waas/getWalletAccountShareSets/getWalletAccountShareSets.d.ts +2 -2
  179. package/dist/modules/waas/getWalletAccountShareSets/getWalletAccountShareSets.d.ts.map +1 -1
  180. package/dist/modules/waas/injectWaasVerifiedCredentialFields/injectWaasVerifiedCredentialFields.d.ts +3 -1
  181. package/dist/modules/waas/injectWaasVerifiedCredentialFields/injectWaasVerifiedCredentialFields.d.ts.map +1 -1
  182. package/dist/modules/waas/policies/applyPolicyLayerBatch/applyPolicyLayerBatch.d.ts +2 -1
  183. package/dist/modules/waas/policies/applyPolicyLayerBatch/applyPolicyLayerBatch.d.ts.map +1 -1
  184. package/dist/modules/waas/policies/buildAllowAddressesRule/buildAllowAddressesRule.d.ts +1 -2
  185. package/dist/modules/waas/policies/buildAllowAddressesRule/buildAllowAddressesRule.d.ts.map +1 -1
  186. package/dist/modules/waas/policies/buildAllowPolicyRule/buildAllowPolicyRule.d.ts +1 -2
  187. package/dist/modules/waas/policies/buildAllowPolicyRule/buildAllowPolicyRule.d.ts.map +1 -1
  188. package/dist/modules/waas/policies/buildBlockExportRule/buildBlockExportRule.d.ts +1 -2
  189. package/dist/modules/waas/policies/buildBlockExportRule/buildBlockExportRule.d.ts.map +1 -1
  190. package/dist/modules/waas/policies/buildDenyAddressesRule/buildDenyAddressesRule.d.ts +1 -2
  191. package/dist/modules/waas/policies/buildDenyAddressesRule/buildDenyAddressesRule.d.ts.map +1 -1
  192. package/dist/modules/waas/policies/buildDenyPolicyRule/buildDenyPolicyRule.d.ts +1 -2
  193. package/dist/modules/waas/policies/buildDenyPolicyRule/buildDenyPolicyRule.d.ts.map +1 -1
  194. package/dist/modules/waas/policies/buildMaxAmountPerTransactionRule/buildMaxAmountPerTransactionRule.d.ts +1 -2
  195. package/dist/modules/waas/policies/buildMaxAmountPerTransactionRule/buildMaxAmountPerTransactionRule.d.ts.map +1 -1
  196. package/dist/modules/waas/policies/buildOperationForExistingRule/buildOperationForExistingRule.d.ts +3 -2
  197. package/dist/modules/waas/policies/buildOperationForExistingRule/buildOperationForExistingRule.d.ts.map +1 -1
  198. package/dist/modules/waas/policies/buildOperationsForRule/buildOperationsForRule.d.ts +2 -2
  199. package/dist/modules/waas/policies/buildOperationsForRule/buildOperationsForRule.d.ts.map +1 -1
  200. package/dist/modules/waas/policies/createPolicy/createPolicy.d.ts +2 -1
  201. package/dist/modules/waas/policies/createPolicy/createPolicy.d.ts.map +1 -1
  202. package/dist/modules/waas/policies/desugarPolicyRules/desugarPolicyRules.d.ts +1 -2
  203. package/dist/modules/waas/policies/desugarPolicyRules/desugarPolicyRules.d.ts.map +1 -1
  204. package/dist/modules/waas/policies/expandPolicyRules/expandPolicyRules.d.ts +2 -2
  205. package/dist/modules/waas/policies/expandPolicyRules/expandPolicyRules.d.ts.map +1 -1
  206. package/dist/modules/waas/policies/fillOmittedRuleValues/fillOmittedRuleValues.d.ts +1 -2
  207. package/dist/modules/waas/policies/fillOmittedRuleValues/fillOmittedRuleValues.d.ts.map +1 -1
  208. package/dist/modules/waas/policies/findMatchedRuleKind/findMatchedRuleKind.d.ts +1 -2
  209. package/dist/modules/waas/policies/findMatchedRuleKind/findMatchedRuleKind.d.ts.map +1 -1
  210. package/dist/modules/waas/policies/getAccountPolicyLayer/getAccountPolicyLayer.d.ts +1 -1
  211. package/dist/modules/waas/policies/getAccountPolicyLayer/getAccountPolicyLayer.d.ts.map +1 -1
  212. package/dist/modules/waas/policies/getPolicy/getPolicy.d.ts +2 -2
  213. package/dist/modules/waas/policies/getPolicy/getPolicy.d.ts.map +1 -1
  214. package/dist/modules/waas/policies/getResolvedPolicyLayer/getResolvedPolicyLayer.d.ts +1 -1
  215. package/dist/modules/waas/policies/getResolvedPolicyLayer/getResolvedPolicyLayer.d.ts.map +1 -1
  216. package/dist/modules/waas/policies/getSignerPolicyLayer/getSignerPolicyLayer.d.ts +1 -1
  217. package/dist/modules/waas/policies/getSignerPolicyLayer/getSignerPolicyLayer.d.ts.map +1 -1
  218. package/dist/modules/waas/policies/getWalletPolicyLayer/getWalletPolicyLayer.d.ts +1 -1
  219. package/dist/modules/waas/policies/getWalletPolicyLayer/getWalletPolicyLayer.d.ts.map +1 -1
  220. package/dist/modules/waas/policies/hasAddresses/hasAddresses.d.ts +1 -1
  221. package/dist/modules/waas/policies/hasAddresses/hasAddresses.d.ts.map +1 -1
  222. package/dist/modules/waas/policies/hasUnrecognizedFields/hasUnrecognizedFields.d.ts +1 -1
  223. package/dist/modules/waas/policies/hasUnrecognizedFields/hasUnrecognizedFields.d.ts.map +1 -1
  224. package/dist/modules/waas/policies/isPolicyRuleDeletionMarker/isPolicyRuleDeletionMarker.d.ts +1 -2
  225. package/dist/modules/waas/policies/isPolicyRuleDeletionMarker/isPolicyRuleDeletionMarker.d.ts.map +1 -1
  226. package/dist/modules/waas/policies/matchExistingRules/matchExistingRules.d.ts +1 -1
  227. package/dist/modules/waas/policies/matchExistingRules/matchExistingRules.d.ts.map +1 -1
  228. package/dist/modules/waas/policies/policies.types.d.ts +17 -1
  229. package/dist/modules/waas/policies/policies.types.d.ts.map +1 -1
  230. package/dist/modules/waas/policies/policyRuleKinds.d.ts +1 -2
  231. package/dist/modules/waas/policies/policyRuleKinds.d.ts.map +1 -1
  232. package/dist/modules/waas/policies/readAllowAddressesRule/readAllowAddressesRule.d.ts +1 -2
  233. package/dist/modules/waas/policies/readAllowAddressesRule/readAllowAddressesRule.d.ts.map +1 -1
  234. package/dist/modules/waas/policies/readBlockExportRule/readBlockExportRule.d.ts +1 -2
  235. package/dist/modules/waas/policies/readBlockExportRule/readBlockExportRule.d.ts.map +1 -1
  236. package/dist/modules/waas/policies/readCoveredRule/readCoveredRule.d.ts +1 -2
  237. package/dist/modules/waas/policies/readCoveredRule/readCoveredRule.d.ts.map +1 -1
  238. package/dist/modules/waas/policies/readDenyAddressesRule/readDenyAddressesRule.d.ts +1 -2
  239. package/dist/modules/waas/policies/readDenyAddressesRule/readDenyAddressesRule.d.ts.map +1 -1
  240. package/dist/modules/waas/policies/readMaxAmountPerTransactionRule/readMaxAmountPerTransactionRule.d.ts +1 -2
  241. package/dist/modules/waas/policies/readMaxAmountPerTransactionRule/readMaxAmountPerTransactionRule.d.ts.map +1 -1
  242. package/dist/modules/waas/policies/removeAccountPolicyRule/removeAccountPolicyRule.d.ts +1 -1
  243. package/dist/modules/waas/policies/removeAccountPolicyRule/removeAccountPolicyRule.d.ts.map +1 -1
  244. package/dist/modules/waas/policies/removePolicyRules/removePolicyRules.d.ts +2 -1
  245. package/dist/modules/waas/policies/removePolicyRules/removePolicyRules.d.ts.map +1 -1
  246. package/dist/modules/waas/policies/removeSignerPolicyRule/removeSignerPolicyRule.d.ts +1 -1
  247. package/dist/modules/waas/policies/removeSignerPolicyRule/removeSignerPolicyRule.d.ts.map +1 -1
  248. package/dist/modules/waas/policies/removeWalletPolicyRule/removeWalletPolicyRule.d.ts +1 -1
  249. package/dist/modules/waas/policies/removeWalletPolicyRule/removeWalletPolicyRule.d.ts.map +1 -1
  250. package/dist/modules/waas/policies/resolveRuleName/resolveRuleName.d.ts +1 -2
  251. package/dist/modules/waas/policies/resolveRuleName/resolveRuleName.d.ts.map +1 -1
  252. package/dist/modules/waas/policies/sortRulesByRuleId/sortRulesByRuleId.d.ts +1 -1
  253. package/dist/modules/waas/policies/sortRulesByRuleId/sortRulesByRuleId.d.ts.map +1 -1
  254. package/dist/modules/waas/policies/upsertAccountPolicyRule/upsertAccountPolicyRule.d.ts +2 -1
  255. package/dist/modules/waas/policies/upsertAccountPolicyRule/upsertAccountPolicyRule.d.ts.map +1 -1
  256. package/dist/modules/waas/policies/upsertSignerPolicyRule/upsertSignerPolicyRule.d.ts +2 -1
  257. package/dist/modules/waas/policies/upsertSignerPolicyRule/upsertSignerPolicyRule.d.ts.map +1 -1
  258. package/dist/modules/waas/policies/upsertWalletPolicyRule/upsertWalletPolicyRule.d.ts +2 -1
  259. package/dist/modules/waas/policies/upsertWalletPolicyRule/upsertWalletPolicyRule.d.ts.map +1 -1
  260. package/dist/modules/waas/waas.consts.d.ts +23 -0
  261. package/dist/modules/waas/waas.consts.d.ts.map +1 -0
  262. package/dist/modules/waas/waas.types.d.ts +29 -1
  263. package/dist/modules/waas/waas.types.d.ts.map +1 -1
  264. package/dist/modules/wallets/getWalletAccounts/getWalletAccountsFromState/getWalletAccountsFromState.d.ts +2 -2
  265. package/dist/modules/wallets/getWalletAccounts/getWalletAccountsFromState/getWalletAccountsFromState.d.ts.map +1 -1
  266. package/dist/modules/wallets/networks/getTransactionHistory/getTransactionHistory.d.ts +2 -2
  267. package/dist/modules/wallets/networks/getTransactionHistory/getTransactionHistory.d.ts.map +1 -1
  268. package/dist/modules/wallets/screenTransaction/screenTransaction.d.ts +1 -1
  269. package/dist/modules/wallets/screenTransaction/screenTransaction.d.ts.map +1 -1
  270. package/dist/modules/wallets/userHasEmbeddedWalletForChain/userHasEmbeddedWalletForChain.d.ts +2 -2
  271. package/dist/modules/wallets/userHasEmbeddedWalletForChain/userHasEmbeddedWalletForChain.d.ts.map +1 -1
  272. package/dist/modules/wallets/userHasExternalWallet/userHasExternalWallet.d.ts +2 -2
  273. package/dist/modules/wallets/userHasExternalWallet/userHasExternalWallet.d.ts.map +1 -1
  274. package/dist/modules/wallets/utils/formatWalletProviderKey/formatWalletProviderKey.d.ts +1 -1
  275. package/dist/modules/wallets/utils/formatWalletProviderKey/formatWalletProviderKey.d.ts.map +1 -1
  276. package/dist/modules/wallets/verifyMessageSignatureOwnership/verifyMessageSignatureOwnership.d.ts +5 -3
  277. package/dist/modules/wallets/verifyMessageSignatureOwnership/verifyMessageSignatureOwnership.d.ts.map +1 -1
  278. package/dist/modules/wallets/verifyWalletAccount/verifyWalletAccount.d.ts +1 -1
  279. package/dist/modules/wallets/verifyWalletAccount/verifyWalletAccount.d.ts.map +1 -1
  280. package/dist/modules/wallets/verifyWalletAccountForSignInOrTransfer/verifyWalletAccountForSignInOrTransfer.d.ts +1 -1
  281. package/dist/modules/wallets/verifyWalletAccountForSignInOrTransfer/verifyWalletAccountForSignInOrTransfer.d.ts.map +1 -1
  282. package/dist/modules/wallets/walletProvider/walletProvider.types.d.ts +4 -2
  283. package/dist/modules/wallets/walletProvider/walletProvider.types.d.ts.map +1 -1
  284. package/dist/modules/wallets/wallets.types.d.ts +47 -0
  285. package/dist/modules/wallets/wallets.types.d.ts.map +1 -0
  286. package/dist/modules/yield/yield.types.d.ts +8 -0
  287. package/dist/modules/yield/yield.types.d.ts.map +1 -1
  288. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  289. package/dist/waas-BYn7tsbq.cjs +2465 -0
  290. package/dist/waas-BYn7tsbq.cjs.map +1 -0
  291. package/dist/waas-CBrqSieN.esm.js +2148 -0
  292. package/dist/waas-CBrqSieN.esm.js.map +1 -0
  293. package/dist/waas-ChgbzsYO.native.esm.js +2148 -0
  294. package/dist/waas-ChgbzsYO.native.esm.js.map +1 -0
  295. package/dist/waas.cjs +60 -2185
  296. package/dist/waas.esm.js +5 -2126
  297. package/dist/waas.native.esm.js +5 -2126
  298. package/dist/waasCore.cjs +63 -33
  299. package/dist/waasCore.cjs.map +1 -1
  300. package/dist/waasCore.esm.js +43 -13
  301. package/dist/waasCore.esm.js.map +1 -1
  302. package/dist/waasCore.native.esm.js +43 -13
  303. package/dist/waasCore.native.esm.js.map +1 -1
  304. package/package.json +3 -3
  305. package/dist/getWalletProviderByKey-Cl6WDOoD.native.esm.js.map +0 -1
  306. package/dist/getWalletProviderByKey-DzpmoNlv.cjs.map +0 -1
  307. package/dist/getWalletProviderByKey-xqyD3ybv.esm.js.map +0 -1
  308. package/dist/isDynamicWaasEnabled-CMccs1-6.cjs +0 -136
  309. package/dist/isDynamicWaasEnabled-CMccs1-6.cjs.map +0 -1
  310. package/dist/isDynamicWaasEnabled-DSqgpEcX.native.esm.js +0 -113
  311. package/dist/isDynamicWaasEnabled-DSqgpEcX.native.esm.js.map +0 -1
  312. package/dist/isDynamicWaasEnabled-DYORq7Jc.esm.js +0 -113
  313. package/dist/isDynamicWaasEnabled-DYORq7Jc.esm.js.map +0 -1
  314. package/dist/isMfaRequiredForAction-BcJvy7Gw.native.esm.js.map +0 -1
  315. package/dist/isMfaRequiredForAction-CatS60F6.esm.js.map +0 -1
  316. package/dist/isMfaRequiredForAction-DKfoMhEk.cjs.map +0 -1
  317. package/dist/isUserOnboardingComplete-BWVuE4Jg.native.esm.js.map +0 -1
  318. package/dist/isUserOnboardingComplete-jkAQQVdP.esm.js.map +0 -1
  319. package/dist/isUserOnboardingComplete-jv_idxWY.cjs.map +0 -1
  320. package/dist/migrateFromFireblocks-B-WUs34v.native.esm.js +0 -65
  321. package/dist/migrateFromFireblocks-B-WUs34v.native.esm.js.map +0 -1
  322. package/dist/migrateFromFireblocks-D4E9bT2H.esm.js +0 -65
  323. package/dist/migrateFromFireblocks-D4E9bT2H.esm.js.map +0 -1
  324. package/dist/migrateFromFireblocks-zp5Jbq2J.cjs +0 -82
  325. package/dist/migrateFromFireblocks-zp5Jbq2J.cjs.map +0 -1
  326. package/dist/updateAuthFromVerifyResponse-BLgNMqwN.esm.js.map +0 -1
  327. package/dist/updateAuthFromVerifyResponse-CTvWpZLa.native.esm.js.map +0 -1
  328. package/dist/updateAuthFromVerifyResponse-Dsw-eAro.cjs.map +0 -1
  329. package/dist/waas.cjs.map +0 -1
  330. package/dist/waas.esm.js.map +0 -1
  331. package/dist/waas.native.esm.js.map +0 -1
@@ -1,16 +1,20 @@
1
- import { AuthStorageEnum, Configuration, JwtVerifiedCredentialFormatEnum, SDKApi, WalletProviderEnum, isDeviceNonceSignatureRequiredForUrl } from "@dynamic-labs/sdk-api-core";
1
+ import { AuthStorageEnum, Configuration, JwtVerifiedCredentialFormatEnum, SDKApi, TokenScope, WalletProviderEnum, isDeviceNonceSignatureRequiredForUrl } from "@dynamic-labs/sdk-api-core";
2
2
  import * as z from "zod/mini";
3
3
 
4
4
  //#region package.json
5
5
  var name = "@dynamic-labs-sdk/client";
6
- var version = "1.30.2";
6
+ var version = "1.30.3";
7
7
 
8
8
  //#endregion
9
- //#region src/client/core/getCore/getCore.ts
10
- /** @notInstrumented */
11
- const getCore = (client) => {
12
- return client.__core;
13
- };
9
+ //#region src/modules/auth/consts.ts
10
+ const DYNAMIC_AUTH_COOKIE_NAME = "DYNAMIC_JWT_TOKEN";
11
+ /**
12
+ * Lists the scopes accepted by authentication and step-up APIs.
13
+ *
14
+ * @see authenticateTotpMfaDevice
15
+ * @see checkStepUpAuth
16
+ */
17
+ const TokenScope$1 = TokenScope;
14
18
 
15
19
  //#endregion
16
20
  //#region src/errors/base/BaseError.ts
@@ -75,6 +79,13 @@ var BaseError = class BaseError extends Error {
75
79
  }
76
80
  };
77
81
 
82
+ //#endregion
83
+ //#region src/client/core/getCore/getCore.ts
84
+ /** @notInstrumented */
85
+ const getCore = (client) => {
86
+ return client.__core;
87
+ };
88
+
78
89
  //#endregion
79
90
  //#region src/errors/ClientNotFoundError.ts
80
91
  var ClientNotFoundError = class extends BaseError {
@@ -122,11 +133,6 @@ const setDefaultClient = (client) => {
122
133
  numOfInitializedClients++;
123
134
  };
124
135
 
125
- //#endregion
126
- //#region src/utils/getNonce/constants.ts
127
- const NONCE_POOL_EXPIRATION_TIME = 6e4 * 60 * 24;
128
- const NONCE_POOL_SIZE = 5;
129
-
130
136
  //#endregion
131
137
  //#region src/utils/getPlatform/getPlatform.ts
132
138
  /**
@@ -255,7 +261,7 @@ const getSessionKeys = (client) => {
255
261
 
256
262
  //#endregion
257
263
  //#region src/generated/dependencyCatalog.ts
258
- const dependencyCatalog = { "@dynamic-labs/sdk-api-core": "0.12.0" };
264
+ const dependencyCatalog = { "@dynamic-labs/sdk-api-core": "0.25.0" };
259
265
 
260
266
  //#endregion
261
267
  //#region src/constants.ts
@@ -534,6 +540,11 @@ const createBaseApiClient = ({ middleware = [], options = {} }, client) => {
534
540
  }));
535
541
  };
536
542
 
543
+ //#endregion
544
+ //#region src/utils/getNonce/constants.ts
545
+ const NONCE_POOL_EXPIRATION_TIME = 6e4 * 60 * 24;
546
+ const NONCE_POOL_SIZE = 5;
547
+
537
548
  //#endregion
538
549
  //#region src/services/storage/createStorageKeySchema/createStorageKeySchema.ts
539
550
  /** @notInstrumented */
@@ -631,38 +642,6 @@ const fetchAndStoreNonces = async (client) => {
631
642
  return fetchPromise;
632
643
  };
633
644
 
634
- //#endregion
635
- //#region src/utils/getSecureCookieAttribute/getSecureCookieAttribute.ts
636
- /**
637
- * Returns the cookie `Secure` attribute suffix (`'; Secure'`) when the current
638
- * document is running in a secure context, or an empty string otherwise.
639
- *
640
- * The `Secure` attribute prevents the browser from ever transmitting the cookie
641
- * over an unencrypted `http://` connection, which mitigates cleartext token
642
- * capture (CWE-614). It is intentionally omitted on insecure/localhost dev,
643
- * because browsers reject `Secure` cookies set over `http://` and that would
644
- * silently break local testing.
645
- *
646
- * Used when building the Dynamic auth JWT cookie string so the attribute is
647
- * applied consistently on both the write (sign-in/refresh) and clear (logout)
648
- * paths.
649
- *
650
- * @notInstrumented
651
- */
652
- const getSecureCookieAttribute = () => {
653
- return Boolean(globalThis.window?.isSecureContext) || globalThis.location?.protocol === "https:" ? "; Secure" : "";
654
- };
655
-
656
- //#endregion
657
- //#region src/utils/setCookie/setCookie.ts
658
- /**
659
- * Sefelly sets the cookie in the browser.
660
- * @notInstrumented
661
- */
662
- const setCookie = (cookie) => {
663
- document.cookie = cookie;
664
- };
665
-
666
645
  //#endregion
667
646
  //#region src/utils/getNonce/getNonce.ts
668
647
  /**
@@ -766,160 +745,54 @@ const createDeviceSignatureHeadersMiddleware = (client) => {
766
745
  };
767
746
 
768
747
  //#endregion
769
- //#region src/modules/apiClient/createApiClient.ts
770
- /**
771
- * Returns a new instance of the SDK API client.
772
- *
773
- * This is not meant for storing, as it is very light we can create it whenever needed.
774
- * @notInstrumented
775
- */
776
- const createApiClient = (options = {}, client) => {
777
- return createBaseApiClient({
778
- middleware: [createDeviceSignatureHeadersMiddleware(client)],
779
- options
780
- }, client);
781
- };
782
-
783
- //#endregion
784
- //#region src/modules/clientEvents/clientEvents.ts
748
+ //#region src/utils/getSecureCookieAttribute/getSecureCookieAttribute.ts
785
749
  /**
786
- * Adds an event listener for Dynamic client events.
787
- *
788
- * This function allows you to listen for various events emitted by the Dynamic client,
789
- * such as authentication state changes, wallet connections, and more.
750
+ * Returns the cookie `Secure` attribute suffix (`'; Secure'`) when the current
751
+ * document is running in a secure context, or an empty string otherwise.
790
752
  *
791
- * @example
792
- * ```ts
793
- * const unsubscribe = onEvent({
794
- * event: 'walletAdded',
795
- * listener: ({ walletAccount }) => {
796
- * console.log('Wallet added:', walletAccount.address);
797
- * },
798
- * });
753
+ * The `Secure` attribute prevents the browser from ever transmitting the cookie
754
+ * over an unencrypted `http://` connection, which mitigates cleartext token
755
+ * capture (CWE-614). It is intentionally omitted on insecure/localhost dev,
756
+ * because browsers reject `Secure` cookies set over `http://` and that would
757
+ * silently break local testing.
799
758
  *
800
- * // Later: clean up
801
- * unsubscribe();
802
- * ```
759
+ * Used when building the Dynamic auth JWT cookie string so the attribute is
760
+ * applied consistently on both the write (sign-in/refresh) and clear (logout)
761
+ * paths.
803
762
  *
804
- * @param params.event - The event name to listen for.
805
- * @param params.listener - The callback function to execute when the event is fired.
806
- * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
807
- * @returns A function that can be called to remove the listener.
808
- * @see offEvent
809
- * @see onceEvent
810
763
  * @notInstrumented
811
- * @hook Event listeners are error-prone to wire up by hand with useEffect.
812
764
  */
813
- const onEvent = ({ event, listener }, client = getDefaultClient()) => {
814
- const { eventEmitter } = getCore(client);
815
- eventEmitter.on(event, listener);
816
- return () => {
817
- eventEmitter.off(event, listener);
818
- };
765
+ const getSecureCookieAttribute = () => {
766
+ return Boolean(globalThis.window?.isSecureContext) || globalThis.location?.protocol === "https:" ? "; Secure" : "";
819
767
  };
768
+
769
+ //#endregion
770
+ //#region src/utils/setCookie/setCookie.ts
820
771
  /**
821
- * Removes an event listener from Dynamic client events.
822
- *
823
- * This function unsubscribes a previously registered event listener
824
- * from the specified Dynamic client event.
825
- *
826
- * @example
827
- * ```ts
828
- * offEvent({ event: 'walletAdded', listener: myListener });
829
- * ```
830
- *
831
- * @param params.event - The event name to remove the listener from.
832
- * @param params.listener - The callback function to remove.
833
- * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
834
- * @see onEvent
835
- * @see onceEvent
772
+ * Sefelly sets the cookie in the browser.
836
773
  * @notInstrumented
837
774
  */
838
- const offEvent = ({ event, listener }, client = getDefaultClient()) => {
839
- const { eventEmitter } = getCore(client);
840
- eventEmitter.off(event, listener);
775
+ const setCookie = (cookie) => {
776
+ document.cookie = cookie;
841
777
  };
778
+
779
+ //#endregion
780
+ //#region src/modules/mfa/isUserMissingMfaAuth/isUserMissingMfaAuth.ts
842
781
  /**
843
- * Adds a one-time event listener for Dynamic client events.
844
- *
845
- * This function listens for an event that will automatically remove itself
846
- * after being triggered once.
782
+ * Checks if the user requires additional MFA authentication.
847
783
  *
848
- * @example
849
- * ```ts
850
- * onceEvent({
851
- * event: 'logout',
852
- * listener: () => {
853
- * console.log('User logged out');
854
- * },
855
- * });
856
- * ```
784
+ * This function determines if the current user session requires
785
+ * additional multi-factor authentication to access certain features.
857
786
  *
858
- * @param params.event - The event name to listen for.
859
- * @param params.listener - The callback function to execute when the event is fired.
860
787
  * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
861
- * @returns A function that can be called to remove the listener before it fires.
862
- * @see onEvent
863
- * @see offEvent
864
- * @notInstrumented
865
- * @hook Event listeners are error-prone to wire up by hand with useEffect.
866
- */
867
- const onceEvent = ({ event, listener }, client = getDefaultClient()) => {
868
- const { eventEmitter } = getCore(client);
869
- eventEmitter.once(event, listener);
870
- return () => {
871
- eventEmitter.off(event, listener);
872
- };
873
- };
874
- /**
875
- * Emits a Dynamic client event.
876
- *
877
- * This function triggers an event that will be received by all registered
878
- * listeners for the specified event type.
879
- *
880
- * @param params.event - The event name to emit.
881
- * @param params.args - The arguments to pass to event listeners.
882
- * @param client - The Dynamic client instance.
788
+ * @returns True if the user needs additional MFA authentication, false otherwise.
883
789
  * @notInstrumented
790
+ * @hook Exposed as a hook so consumers reactively know when MFA is still required, updated when the user changes.
884
791
  */
885
- const emitEvent = ({ event, args }, client) => {
886
- const { eventEmitter } = getCore(client);
887
- eventEmitter.emit(event, args);
888
- };
889
-
890
- //#endregion
891
- //#region src/utils/retryOnFail/InvalidRetryOnFailCallError.ts
892
- /**
893
- * This error is thrown when the `retryOnFail` function is called with an invalid
894
- * number of retries (i.e. less than 0).
895
- */
896
- var InvalidRetryOnFailCallError = class extends BaseError {
897
- constructor(maxRetries) {
898
- super({
899
- cause: null,
900
- code: "invalid_retry_on_fail_call_error",
901
- docsUrl: null,
902
- name: "InvalidRetryOnFailCallError",
903
- shortMessage: `Invalid retries parameter for retryOnFail call: ${maxRetries}`
904
- });
905
- }
906
- };
907
-
908
- //#endregion
909
- //#region src/utils/retryOnFail/retryOnFail.ts
910
- /** @notInstrumented */
911
- const retryOnFail = async ({ delay = 0, fn, maxRetries }) => {
912
- for (let retry = 0; retry <= maxRetries; retry++) try {
913
- return await fn();
914
- } catch (error) {
915
- if (retry >= maxRetries) throw error;
916
- if (delay > 0) await new Promise((resolve) => setTimeout(resolve, delay));
917
- }
918
- /**
919
- * Reaching this point should never happen and this
920
- * error is thrown to help us debug the issue.
921
- */
922
- throw new InvalidRetryOnFailCallError(maxRetries);
792
+ const isUserMissingMfaAuth = (client = getDefaultClient()) => {
793
+ const user = client.user;
794
+ assertDefined(user, "User not logged in");
795
+ return Boolean(user.scope?.includes("requiresAdditionalAuth"));
923
796
  };
924
797
 
925
798
  //#endregion
@@ -1265,147 +1138,131 @@ const getWalletAccounts = (client = getDefaultClient()) => {
1265
1138
  };
1266
1139
 
1267
1140
  //#endregion
1268
- //#region src/modules/auth/isSignedIn/isSignedIn.ts
1141
+ //#region src/services/runtimeServices/createRuntimeServiceAccessKey/createRuntimeServiceAccessKey.ts
1269
1142
  /**
1270
- * Checks if the user is currently signed in to the Dynamic client.
1143
+ * Creates a service accessor function that manages service instantiation and caching.
1144
+ * The returned function will either retrieve an existing service from the registry or
1145
+ * create a new one using the provided builder function.
1271
1146
  *
1272
- * The client is considered to be in a signed in state if a user has
1273
- * authenticated or if the client has at least one wallet connected.
1147
+ * @template - The type of service to be created/accessed
1148
+ * @param key - Unique identifier for the service in the registry
1149
+ * @param builder - Function that creates the service instance when called with a DynamicClient
1150
+ * @notInstrumented
1151
+ */
1152
+ const createRuntimeServiceAccessKey = (key, builder) => (client) => {
1153
+ const { runtimeServices } = getCore(client);
1154
+ const currentService = runtimeServices.getByKey(key);
1155
+ if (currentService) return currentService;
1156
+ const service = builder(client);
1157
+ runtimeServices.register(key, service);
1158
+ return service;
1159
+ };
1160
+
1161
+ //#endregion
1162
+ //#region src/modules/clientEvents/clientEvents.ts
1163
+ /**
1164
+ * Adds an event listener for Dynamic client events.
1274
1165
  *
1275
- * @deprecated What counts as "signed in" is your app's business logic, not the
1276
- * SDK's. This helper bakes in one opinion (a user OR any connected wallet),
1277
- * which rarely matches every app and forces a dependency on us for every
1278
- * variation. Compose your own check from the underlying primitives instead —
1279
- * e.g. `Boolean(client.user) || isAnyWalletAccountConnected(client)` — and
1280
- * layer in whatever your app requires (device registration, completed
1281
- * onboarding, satisfied MFA, a required embedded wallet, …). See the
1282
- * "Check if signed in" guide:
1283
- * https://www.dynamic.xyz/docs/javascript/user-session-management
1166
+ * This function allows you to listen for various events emitted by the Dynamic client,
1167
+ * such as authentication state changes, wallet connections, and more.
1284
1168
  *
1285
1169
  * @example
1286
1170
  * ```ts
1287
- * if (isSignedIn()) {
1288
- * console.log('User is authenticated or has a wallet connected');
1289
- * }
1171
+ * const unsubscribe = onEvent({
1172
+ * event: 'walletAdded',
1173
+ * listener: ({ walletAccount }) => {
1174
+ * console.log('Wallet added:', walletAccount.address);
1175
+ * },
1176
+ * });
1177
+ *
1178
+ * // Later: clean up
1179
+ * unsubscribe();
1290
1180
  * ```
1291
1181
  *
1182
+ * @param params.event - The event name to listen for.
1183
+ * @param params.listener - The callback function to execute when the event is fired.
1292
1184
  * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
1293
- * @returns True if the user is signed in, false otherwise.
1294
- * @see logout
1295
- * @see isAnyWalletAccountConnected
1185
+ * @returns A function that can be called to remove the listener.
1186
+ * @see offEvent
1187
+ * @see onceEvent
1296
1188
  * @notInstrumented
1189
+ * @hook Event listeners are error-prone to wire up by hand with useEffect.
1297
1190
  */
1298
- const isSignedIn = (client = getDefaultClient()) => Boolean(client.user || getWalletAccounts(client).length > 0);
1299
-
1300
- //#endregion
1301
- //#region src/modules/projectSettings/fetchProjectSettings/projectSettingsExpirationScheme.ts
1302
- /**
1303
- * The schema to track the expiration time of the project settings.
1304
- */
1305
- const projectSettingsExpirationStorageKeySchema = createStorageKeySchema({
1306
- key: "projectSettingsExpiration",
1307
- schema: z.number()
1308
- });
1309
-
1310
- //#endregion
1311
- //#region src/modules/projectSettings/fetchProjectSettings/fetchProjectSettings.ts
1191
+ const onEvent = ({ event, listener }, client = getDefaultClient()) => {
1192
+ const { eventEmitter } = getCore(client);
1193
+ eventEmitter.on(event, listener);
1194
+ return () => {
1195
+ eventEmitter.off(event, listener);
1196
+ };
1197
+ };
1312
1198
  /**
1313
- * Expiration time of the project settings in milliseconds.
1199
+ * Removes an event listener from Dynamic client events.
1200
+ *
1201
+ * This function unsubscribes a previously registered event listener
1202
+ * from the specified Dynamic client event.
1203
+ *
1204
+ * @example
1205
+ * ```ts
1206
+ * offEvent({ event: 'walletAdded', listener: myListener });
1207
+ * ```
1208
+ *
1209
+ * @param params.event - The event name to remove the listener from.
1210
+ * @param params.listener - The callback function to remove.
1211
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
1212
+ * @see onEvent
1213
+ * @see onceEvent
1214
+ * @notInstrumented
1314
1215
  */
1315
- const PROJECT_SETTINGS_EXPIRATION_TIME = 1e3 * 60 * 5;
1216
+ const offEvent = ({ event, listener }, client = getDefaultClient()) => {
1217
+ const { eventEmitter } = getCore(client);
1218
+ eventEmitter.off(event, listener);
1219
+ };
1316
1220
  /**
1317
- * Fetches and updates the project settings from the API.
1221
+ * Adds a one-time event listener for Dynamic client events.
1318
1222
  *
1319
- * This function retrieves the latest project configuration settings
1320
- * from Dynamic's servers, including authentication options, enabled chains,
1321
- * and security configurations. The settings are cached for performance.
1223
+ * This function listens for an event that will automatically remove itself
1224
+ * after being triggered once.
1322
1225
  *
1323
1226
  * @example
1324
1227
  * ```ts
1325
- * const settings = await fetchProjectSettings();
1326
- * console.log('Enabled chains:', settings.chains);
1228
+ * onceEvent({
1229
+ * event: 'logout',
1230
+ * listener: () => {
1231
+ * console.log('User logged out');
1232
+ * },
1233
+ * });
1327
1234
  * ```
1328
1235
  *
1236
+ * @param params.event - The event name to listen for.
1237
+ * @param params.listener - The callback function to execute when the event is fired.
1329
1238
  * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
1330
- * @returns A promise that resolves to the updated project settings.
1331
- * @see createDynamicClient
1332
- * @see initializeClient
1239
+ * @returns A function that can be called to remove the listener before it fires.
1240
+ * @see onEvent
1241
+ * @see offEvent
1333
1242
  * @notInstrumented
1334
- * @noHook Internal settings fetch that is not part of the public hook surface.
1243
+ * @hook Event listeners are error-prone to wire up by hand with useEffect.
1335
1244
  */
1336
- const fetchProjectSettings = async (client = getDefaultClient()) => {
1337
- const core = getCore(client);
1338
- const currentExpiration = await core.storage.getItem(projectSettingsExpirationStorageKeySchema);
1339
- if (Boolean(client.projectSettings) && !(currentExpiration && currentExpiration < Date.now()) && isSignedIn(client)) return client.projectSettings;
1340
- const apiClient = createApiClient({}, client);
1341
- core.logger.debug("[fetchProjectSettings] Fetching project settings...");
1342
- const doFetch = async () => apiClient.getEnvironmentSettings({
1343
- environmentId: core.environmentId,
1344
- sdkVersion: `${CLIENT_SDK_NAME}/${core.version}`
1345
- }, { credentials: "omit" });
1346
- const projectSettings = await retryOnFail({
1347
- fn: doFetch,
1348
- maxRetries: 2
1349
- });
1350
- core.state.set({ projectSettings: projectSettings ?? null });
1351
- await core.storage.setItem(projectSettingsExpirationStorageKeySchema, Date.now() + PROJECT_SETTINGS_EXPIRATION_TIME);
1352
- return projectSettings;
1353
- };
1354
-
1355
- //#endregion
1356
- //#region src/modules/sessionKeys/generateSessionKeys/generateSessionKeys.ts
1357
- /** @notInstrumented */
1358
- const generateSessionKeys = async (client) => {
1359
- const core = getCore(client);
1360
- const currentState = core.state.get();
1361
- const isRotation = Boolean(currentState.sessionKeys);
1362
- const logContext = {
1363
- environmentId: core.environmentId,
1364
- operation: isRotation ? "rotate" : "create",
1365
- userId: currentState.user?.id ?? null
1245
+ const onceEvent = ({ event, listener }, client = getDefaultClient()) => {
1246
+ const { eventEmitter } = getCore(client);
1247
+ eventEmitter.once(event, listener);
1248
+ return () => {
1249
+ eventEmitter.off(event, listener);
1366
1250
  };
1367
- core.logger.info(isRotation ? "[generateSessionKeys] Rotating session key..." : "[generateSessionKeys] Creating session key...", logContext);
1368
- await core.keychain.removeKey("session");
1369
- const publicKey = await core.keychain.generateKey("session");
1370
- assertDefined(publicKey, "Public key not found");
1371
- core.state.set({ sessionKeys: publicKey });
1372
- core.logger.info(isRotation ? "[generateSessionKeys] Session key rotated" : "[generateSessionKeys] Session key created", logContext);
1373
- return { publicKey };
1374
- };
1375
-
1376
- //#endregion
1377
- //#region src/errors/NoWalletProviderFoundError.ts
1378
- var NoWalletProviderFoundError = class extends BaseError {
1379
- constructor({ walletProviderKey }) {
1380
- super({
1381
- cause: null,
1382
- code: "no_wallet_provider_found_error",
1383
- docsUrl: null,
1384
- name: "NoWalletProviderFoundError",
1385
- shortMessage: `No wallet provider found with key: ${walletProviderKey}`
1386
- });
1387
- }
1388
1251
  };
1389
-
1390
- //#endregion
1391
- //#region src/services/runtimeServices/createRuntimeServiceAccessKey/createRuntimeServiceAccessKey.ts
1392
1252
  /**
1393
- * Creates a service accessor function that manages service instantiation and caching.
1394
- * The returned function will either retrieve an existing service from the registry or
1395
- * create a new one using the provided builder function.
1253
+ * Emits a Dynamic client event.
1396
1254
  *
1397
- * @template - The type of service to be created/accessed
1398
- * @param key - Unique identifier for the service in the registry
1399
- * @param builder - Function that creates the service instance when called with a DynamicClient
1255
+ * This function triggers an event that will be received by all registered
1256
+ * listeners for the specified event type.
1257
+ *
1258
+ * @param params.event - The event name to emit.
1259
+ * @param params.args - The arguments to pass to event listeners.
1260
+ * @param client - The Dynamic client instance.
1400
1261
  * @notInstrumented
1401
1262
  */
1402
- const createRuntimeServiceAccessKey = (key, builder) => (client) => {
1403
- const { runtimeServices } = getCore(client);
1404
- const currentService = runtimeServices.getByKey(key);
1405
- if (currentService) return currentService;
1406
- const service = builder(client);
1407
- runtimeServices.register(key, service);
1408
- return service;
1263
+ const emitEvent = ({ event, args }, client) => {
1264
+ const { eventEmitter } = getCore(client);
1265
+ eventEmitter.emit(event, args);
1409
1266
  };
1410
1267
 
1411
1268
  //#endregion
@@ -1514,62 +1371,93 @@ const WalletProviderPriority = {
1514
1371
  };
1515
1372
 
1516
1373
  //#endregion
1517
- //#region src/modules/wallets/utils/getWalletProviderFromWalletAccount/getWalletProviderFromWalletAccount.ts
1374
+ //#region src/modules/wallets/getWalletProviders/getWalletProviders.ts
1375
+ /**
1376
+ * Get all available wallet providers to interact with internally.
1377
+ * @notInstrumented
1378
+ */
1379
+ const getWalletProviders = (client) => {
1380
+ return getWalletProviderRegistry(client).listProviders();
1381
+ };
1382
+
1383
+ //#endregion
1384
+ //#region src/modules/waas/constants.ts
1385
+ const DEFAULT_WAAS_BASE_API_URL = "https://app.dynamicauth.com";
1386
+ const DEFAULT_WAAS_BASE_MPC_RELAY_API_URL = "https://relay.dynamicauth.com";
1387
+ const DYNAMIC_WAAS_METADATA = {
1388
+ displayName: "Dynamic WaaS",
1389
+ icon: `${DYNAMIC_ICONIC_SPRITE_URL}#dynamicwaas`,
1390
+ normalizedWalletName: "dynamicwaas"
1391
+ };
1392
+
1393
+ //#endregion
1394
+ //#region src/modules/waas/isWaasWalletProvider/isWaasWalletProvider.ts
1518
1395
  /** @notInstrumented */
1519
- const getWalletProviderFromWalletAccount = ({ walletAccount }, client) => {
1520
- const walletProvider = getWalletProviderRegistry(client).getByKey(walletAccount.walletProviderKey);
1521
- if (!walletProvider) throw new NoWalletProviderFoundError({ walletProviderKey: walletAccount.walletProviderKey });
1522
- return walletProvider;
1396
+ const isWaasWalletProvider = (walletProvider) => {
1397
+ return walletProvider.key.includes(DYNAMIC_WAAS_METADATA.normalizedWalletName);
1523
1398
  };
1524
1399
 
1525
1400
  //#endregion
1526
- //#region src/modules/wallets/utils/getAvailableWalletProvidersFromWalletAccounts/getAvailableWalletProvidersFromWalletAccounts.ts
1401
+ //#region src/modules/waas/findWaasWalletProviderByChain/findWaasWalletProviderByChain.ts
1527
1402
  /** @notInstrumented */
1528
- const getAvailableWalletProvidersFromWalletAccounts = (client) => {
1529
- const core = getCore(client);
1530
- const walletProvidersMap = /* @__PURE__ */ new Map();
1531
- getWalletAccounts(client).forEach((walletAccount) => {
1532
- if (walletProvidersMap.has(walletAccount.walletProviderKey)) return;
1533
- try {
1534
- const walletProvider = getWalletProviderFromWalletAccount({ walletAccount }, client);
1535
- walletProvidersMap.set(walletAccount.walletProviderKey, walletProvider);
1536
- } catch (error) {
1537
- core.logger.debug("Wallet provider not found for wallet account", {
1538
- error,
1539
- walletAccount: walletAccount.address
1540
- });
1541
- }
1403
+ const findWaasWalletProviderByChain = ({ chain }, client) => {
1404
+ const providers = getWalletProviders(client);
1405
+ const waasProviderKey = formatWalletProviderKey({
1406
+ chain,
1407
+ displayName: DYNAMIC_WAAS_METADATA.displayName,
1408
+ walletProviderType: WalletProviderEnum.EmbeddedWallet
1542
1409
  });
1543
- return Array.from(walletProvidersMap.values());
1410
+ const waasProvider = providers.find((provider) => provider.key === waasProviderKey && provider.chain === chain);
1411
+ if (!waasProvider || !isWaasWalletProvider(waasProvider)) return null;
1412
+ return waasProvider;
1544
1413
  };
1545
1414
 
1546
1415
  //#endregion
1547
- //#region src/modules/wallets/destroyWalletProviders/destroyWalletProviders.ts
1416
+ //#region src/modules/waas/isWaasWalletAccount/isWaasWalletAccount.ts
1548
1417
  /**
1549
- * Tear down every wallet provider on the client.
1550
- *
1551
- * Each provider's `destroy` is responsible for its own local + remote
1552
- * cleanup. We swallow errors so a failing destroy on one provider does not
1553
- * block teardown of the others (e.g. during logout).
1418
+ * This function determines whether the provided wallet account is a Dynamic
1419
+ * WaaS wallet account.
1554
1420
  *
1421
+ * @param params.walletAccount - The wallet account to check.
1422
+ * @returns True if the wallet account is a WaaS wallet account, false otherwise.
1555
1423
  * @notInstrumented
1556
1424
  */
1557
- const destroyWalletProviders = async ({ reason }, client) => {
1558
- const core = getCore(client);
1559
- const walletProviders = getAvailableWalletProvidersFromWalletAccounts(client);
1560
- await Promise.all(walletProviders.map(async (walletProvider) => {
1561
- if (!walletProvider.destroy) return;
1562
- try {
1563
- await walletProvider.destroy({ reason });
1564
- } catch (err) {
1565
- core.logger.error(`Error destroying wallet provider ${walletProvider.key}`, err);
1566
- }
1567
- }));
1425
+ const isWaasWalletAccount = ({ walletAccount }) => {
1426
+ return walletAccount.walletProviderKey.includes(DYNAMIC_WAAS_METADATA.normalizedWalletName);
1568
1427
  };
1569
1428
 
1570
1429
  //#endregion
1571
- //#region src/modules/auth/consts.ts
1572
- const DYNAMIC_AUTH_COOKIE_NAME = "DYNAMIC_JWT_TOKEN";
1430
+ //#region src/modules/waas/initializeWaasClientsForEagerRecovery/initializeWaasClientsForEagerRecovery.ts
1431
+ /**
1432
+ * On login, boots the WaaS client once per chain so the SDK eagerly recovers
1433
+ * key shares itself (the `eagerlyRecoverKeyShares` capability) instead of the
1434
+ * host looping per wallet. Booting calls `initialize()`, which sends the auth
1435
+ * token the iframe needs to self-recover.
1436
+ *
1437
+ * @notInstrumented
1438
+ */
1439
+ const initializeWaasClientsForEagerRecovery = async (client) => {
1440
+ /**
1441
+ * Booting triggers recovery, which fails if the user is missing the MFA auth.
1442
+ * This early return avoids attempting a call we know will fail and just adds
1443
+ * noise to the logs.
1444
+ */
1445
+ if (isUserMissingMfaAuth(client)) return;
1446
+ const waasChains = new Set(getWalletAccounts(client).filter((walletAccount) => isWaasWalletAccount({ walletAccount })).map((walletAccount) => walletAccount.chain));
1447
+ await Promise.all([...waasChains].map(async (chain) => {
1448
+ const provider = findWaasWalletProviderByChain({ chain }, client);
1449
+ /**
1450
+ * The environment might not have the embedded wallet extensions installed.
1451
+ * In that case there is no provider for the chain and nothing to boot.
1452
+ */
1453
+ if (!provider) return;
1454
+ try {
1455
+ await provider.getWaasClient();
1456
+ } catch (error) {
1457
+ getCore(client).logger.warn("[initializeWaasClientsForEagerRecovery] failed to boot waas client", error);
1458
+ }
1459
+ }));
1460
+ };
1573
1461
 
1574
1462
  //#endregion
1575
1463
  //#region src/modules/wallets/emitWalletAccountsChangedEvent/emitWalletAccountsChangedEvent.ts
@@ -1593,6 +1481,160 @@ const checkAndRaiseWalletAccountsChangedEvent = ({ previousState }, client) => {
1593
1481
  };
1594
1482
  const getWalletAccountsHash = (state, client) => getWalletAccountsFromState(state, client).map((walletAccount) => JSON.stringify(walletAccount)).sort().join("-");
1595
1483
 
1484
+ //#endregion
1485
+ //#region src/errors/InvalidParamError.ts
1486
+ var InvalidParamError = class extends BaseError {
1487
+ constructor(message) {
1488
+ super({
1489
+ cause: null,
1490
+ code: "invalid_param_error",
1491
+ docsUrl: null,
1492
+ name: "InvalidParamError",
1493
+ shortMessage: message
1494
+ });
1495
+ }
1496
+ };
1497
+
1498
+ //#endregion
1499
+ //#region src/modules/auth/decodeJwt/decodeJwt.ts
1500
+ /**
1501
+ * Decodes a JWT token and returns the full payload.
1502
+ *
1503
+ * This function extracts and returns the complete JWT payload including scopes,
1504
+ * expiration time, and other claims.
1505
+ *
1506
+ * @param jwt - The JWT token string.
1507
+ * @returns The decoded JWT payload object.
1508
+ * @throws InvalidParamError if the token is invalid or cannot be decoded.
1509
+ *
1510
+ * @example
1511
+ * ```typescript
1512
+ * const payload = decodeJwt(jwt);
1513
+ * // Returns: { scopes: ['wallet:export'], exp: 1234567890, ... }
1514
+ * ```
1515
+ * @notInstrumented
1516
+ */
1517
+ const decodeJwt = (jwt) => {
1518
+ try {
1519
+ const parts = jwt.split(".");
1520
+ if (parts.length !== 3) throw new InvalidParamError("Invalid JWT format");
1521
+ const base64Payload = parts[1].replaceAll("-", "+").replaceAll("_", "/");
1522
+ const paddedPayload = base64Payload + "=".repeat((4 - base64Payload.length % 4) % 4);
1523
+ const decodedPayload = atob(paddedPayload);
1524
+ return JSON.parse(decodedPayload);
1525
+ } catch (error) {
1526
+ if (error instanceof InvalidParamError) throw error;
1527
+ throw new InvalidParamError(`Failed to decode JWT: ${error instanceof Error ? error.message : String(error)}`);
1528
+ }
1529
+ };
1530
+
1531
+ //#endregion
1532
+ //#region src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/normalizeScopes/normalizeScopes.ts
1533
+ /**
1534
+ * Normalizes scopes by deduplicating and sorting them.
1535
+ * This creates a canonical representation for comparison.
1536
+ *
1537
+ * @param scopes - Array of scope strings (may contain duplicates)
1538
+ * @returns Normalized, sorted array of unique scopes
1539
+ * @notInstrumented
1540
+ */
1541
+ const normalizeScopes = (scopes) => {
1542
+ return [...new Set(scopes)].sort((a, b) => a.localeCompare(b));
1543
+ };
1544
+
1545
+ //#endregion
1546
+ //#region src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/parseElevatedAccessToken/parseElevatedAccessToken.ts
1547
+ /**
1548
+ * Validates and parses an elevated access token from a JWT string.
1549
+ * Extracts scopes, expiration, and validates the token structure.
1550
+ *
1551
+ * Policy decisions:
1552
+ * - Tokens without scopes are rejected (returns null)
1553
+ * - Tokens with empty scopes array are rejected (returns null)
1554
+ * - Tokens without exp field are rejected (returns null)
1555
+ * - Expired tokens are rejected (returns null)
1556
+ *
1557
+ * @returns Parsed token data or null if token is invalid/expired
1558
+ * @notInstrumented
1559
+ */
1560
+ const parseElevatedAccessToken = ({ token }) => {
1561
+ const payload = decodeJwt(token);
1562
+ const filteredScopes = ((payload?.scope)?.split(" ") ?? []).filter((s) => s.length > 0);
1563
+ const singleUse = payload.singleUse ?? false;
1564
+ if (!filteredScopes || filteredScopes.length === 0) return null;
1565
+ if (!payload.exp) return null;
1566
+ const expiresAt = /* @__PURE__ */ new Date(payload.exp * 1e3);
1567
+ if (expiresAt <= /* @__PURE__ */ new Date()) return null;
1568
+ return {
1569
+ expiresAt,
1570
+ normalizedScopes: normalizeScopes(filteredScopes),
1571
+ scopes: filteredScopes,
1572
+ singleUse,
1573
+ token
1574
+ };
1575
+ };
1576
+
1577
+ //#endregion
1578
+ //#region src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/upsertElevatedAccessToken/upsertElevatedAccessToken.ts
1579
+ /**
1580
+ * Upserts an elevated access token into the current tokens array.
1581
+ *
1582
+ * Policy: Only one token per normalized scope-set is allowed.
1583
+ * If a token with the same normalized scopes exists, it is replaced.
1584
+ * This ensures we don't accumulate multiple tokens for the same scope combination.
1585
+ *
1586
+ * @param currentTokens - Current array of elevated access tokens
1587
+ * @param newToken - New token to upsert
1588
+ * @returns Updated array of tokens with the new token upserted
1589
+ * @notInstrumented
1590
+ */
1591
+ const upsertElevatedAccessToken = ({ currentTokens, newToken }) => {
1592
+ const newScopeKey = normalizeScopes(newToken.scopes).join(" ");
1593
+ return [...currentTokens.filter((existingToken) => {
1594
+ return normalizeScopes(existingToken.scopes).join(" ") !== newScopeKey;
1595
+ }), {
1596
+ expiresAt: newToken.expiresAt,
1597
+ scopes: newToken.scopes,
1598
+ singleUse: newToken.singleUse,
1599
+ token: newToken.token
1600
+ }];
1601
+ };
1602
+
1603
+ //#endregion
1604
+ //#region src/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.ts
1605
+ /** @notInstrumented */
1606
+ const updateAuthFromVerifyResponse = ({ response }, client) => {
1607
+ const core = getCore(client);
1608
+ const previousState = { ...core.state.get() };
1609
+ const { user, minifiedJwt, jwt, expiresAt, mfaToken, elevatedAccessToken } = response;
1610
+ const sessionExpiresAt = /* @__PURE__ */ new Date(expiresAt * 1e3);
1611
+ const newState = {
1612
+ legacyToken: jwt ?? null,
1613
+ sessionExpiresAt,
1614
+ token: minifiedJwt ?? null,
1615
+ user
1616
+ };
1617
+ if (mfaToken) newState.mfaToken = mfaToken;
1618
+ const currentTokens = core.state.get().elevatedAccessTokens || [];
1619
+ newState.elevatedAccessTokens = currentTokens;
1620
+ if (elevatedAccessToken) {
1621
+ const parsedToken = parseElevatedAccessToken({ token: elevatedAccessToken });
1622
+ if (parsedToken) newState.elevatedAccessTokens = upsertElevatedAccessToken({
1623
+ currentTokens,
1624
+ newToken: parsedToken
1625
+ });
1626
+ }
1627
+ core.state.set(newState);
1628
+ /**
1629
+ * For customers using a sandbox environment with cookies enabled, we need to set the cookie
1630
+ * programmatically because Redcoast won't set the cookie via headers. We set the cookie programmatically
1631
+ * so customers can access the cookie from document.cookie consistently between sandbox and live environments.
1632
+ */
1633
+ if (minifiedJwt && isCookieEnabled(client)) setCookie(`${DYNAMIC_AUTH_COOKIE_NAME}=${minifiedJwt}; expires=${sessionExpiresAt.toUTCString()}; path=/; SameSite=Lax${getSecureCookieAttribute()}`);
1634
+ checkAndRaiseWalletAccountsChangedEvent({ previousState }, client);
1635
+ if (!previousState.user && Boolean(newState.user)) initializeWaasClientsForEagerRecovery(client);
1636
+ };
1637
+
1596
1638
  //#endregion
1597
1639
  //#region src/modules/auth/extractSessionId/extractSessionId.ts
1598
1640
  /**
@@ -2002,67 +2044,41 @@ const instrumentFunction = ({ fn, functionName, getCore: getCore$1, selectors })
2002
2044
  };
2003
2045
 
2004
2046
  //#endregion
2005
- //#region src/modules/auth/logoutWithReason/logoutWithReason.ts
2047
+ //#region src/modules/user/refreshAuth/refreshAuth.ts
2006
2048
  /**
2007
- * Logs the user out with an explicit reason.
2049
+ * Refreshes the current session's authentication from the server.
2008
2050
  *
2009
- * Revokes the session, clears auth state, terminates wallet providers, and
2010
- * emits the `logout` client event with the given reason. The reason is also
2011
- * captured as an argument on the function-instrumentation event, which is
2012
- * how Datadog distinguishes between different logout causes.
2051
+ * This rotates the auth token via a full verify call and updates both the
2052
+ * token and the user state from the response, returning the raw
2053
+ * `VerifyResponse` (which includes the new token). Reach for this when you
2054
+ * need a fresh JWT e.g. before a call that requires a non-expired token.
2013
2055
  *
2014
- * Use this instead of the public `logout` when triggering a logout from
2015
- * internal or extension code the caller owns the reason string, so the
2016
- * telemetry correctly attributes *why* the logout happened.
2056
+ * Prefer `refreshUser` when you only need the latest user profile and do not
2057
+ * care about rotating the token: it hits the authenticated-user endpoint,
2058
+ * touches only the user state, and returns the `User` directly.
2017
2059
  *
2018
- * @param params - The logout params.
2019
- * @param params.reason - Why the logout is being triggered. Extension authors
2020
- * needing a reason outside the SDK catalog can cast with `as LogoutReason`.
2021
- * @param client - The Dynamic client instance.
2060
+ * @example
2061
+ * ```ts
2062
+ * const response = await refreshAuth();
2063
+ * console.log('Token refreshed:', response.token);
2064
+ * ```
2065
+ *
2066
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
2067
+ * @returns A promise that resolves to the verify response.
2068
+ * @see logout
2069
+ * @see refreshUser
2022
2070
  * @instrumented
2023
2071
  */
2024
- const logoutWithReason = async ({ reason }, client) => {
2072
+ const refreshAuth = async (client = getDefaultClient()) => {
2025
2073
  const core = getCore(client);
2026
- core.logger.debug("[logoutWithReason] Logging out...", { reason });
2027
- await destroyWalletProviders({ reason }, client);
2028
- if (client.user !== null) {
2029
- const apiClient = createApiClient({ headers: { [DYNAMIC_LOGOUT_REASON_HEADER]: reason } }, client);
2030
- try {
2031
- await apiClient.revokeSession({ environmentId: core.environmentId });
2032
- } catch (error) {
2033
- core.logger.error("Failed to revoke session", error);
2034
- }
2035
- /**
2036
- * This deletes the auth cookie if it exists.
2037
- * If the cookie doesn't exist, this sets a new cookie that expires immediately.
2038
- */
2039
- if (isCookieEnabled(client)) setCookie(`${DYNAMIC_AUTH_COOKIE_NAME}=; Max-Age=-99999999; path=/; SameSite=Lax${getSecureCookieAttribute()}`);
2040
- }
2041
- await core.keychain.removeKey("session");
2042
- const previousState = core.state.get();
2043
- core.state.set({
2044
- captchaToken: null,
2045
- elevatedAccessTokens: [],
2046
- legacyToken: null,
2047
- mfaToken: null,
2048
- sessionExpiresAt: null,
2049
- sessionKeys: null,
2050
- token: null,
2051
- unverifiedWalletAccounts: [],
2052
- user: null
2053
- });
2054
- emitEvent({
2055
- args: { reason },
2056
- event: "logout"
2057
- }, client);
2058
- checkAndRaiseWalletAccountsChangedEvent({ previousState }, client);
2059
- fetchProjectSettings(client);
2060
- generateSessionKeys(client);
2061
- };
2062
- const __logoutWithReason_impl = logoutWithReason;
2063
- const __logoutWithReason_wrapped = instrumentFunction({
2064
- fn: __logoutWithReason_impl,
2065
- functionName: "logoutWithReason",
2074
+ const response = await createBaseApiClient({ middleware: [createDeviceSignatureHeadersMiddleware(client)] }, client).refreshAuth({ environmentId: core.environmentId });
2075
+ updateAuthFromVerifyResponse({ response }, client);
2076
+ return response;
2077
+ };
2078
+ const __refreshAuth_impl = refreshAuth;
2079
+ const __refreshAuth_wrapped = instrumentFunction({
2080
+ fn: __refreshAuth_impl,
2081
+ functionName: "refreshAuth",
2066
2082
  getCore: () => {
2067
2083
  try {
2068
2084
  return getCore(getDefaultClient());
@@ -2073,267 +2089,343 @@ const __logoutWithReason_wrapped = instrumentFunction({
2073
2089
  });
2074
2090
 
2075
2091
  //#endregion
2076
- //#region src/modules/mfa/isUserMissingMfaAuth/isUserMissingMfaAuth.ts
2092
+ //#region src/modules/apiClient/utils/rbacStaleMiddleware/createRbacStaleMiddleware.ts
2093
+ const RBAC_STALE_CODE = "rbac_stale";
2094
+ const RBAC_STALE_RETRY_HEADER = "x-dyn-rbac-retry";
2077
2095
  /**
2078
- * Checks if the user requires additional MFA authentication.
2079
- *
2080
- * This function determines if the current user session requires
2081
- * additional multi-factor authentication to access certain features.
2082
- *
2083
- * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
2084
- * @returns True if the user needs additional MFA authentication, false otherwise.
2096
+ * Detects 403 { code: 'rbac_stale' } responses, refreshes the auth token, and
2097
+ * retries the request once with the new token. This lets business account role
2098
+ * changes take effect without revoking the user's session.
2085
2099
  * @notInstrumented
2086
- * @hook Exposed as a hook so consumers reactively know when MFA is still required, updated when the user changes.
2087
2100
  */
2088
- const isUserMissingMfaAuth = (client = getDefaultClient()) => {
2089
- const user = client.user;
2090
- assertDefined(user, "User not logged in");
2091
- return Boolean(user.scope?.includes("requiresAdditionalAuth"));
2092
- };
2101
+ const createRbacStaleMiddleware = (client) => ({ post: async (context) => {
2102
+ if (context.response.status !== 403) return context.response;
2103
+ if (context.init.headers && typeof context.init.headers === "object" && RBAC_STALE_RETRY_HEADER in context.init.headers) return context.response;
2104
+ let errorBody;
2105
+ try {
2106
+ errorBody = await context.response.clone().json();
2107
+ } catch {
2108
+ return context.response;
2109
+ }
2110
+ if (!(typeof errorBody === "object" && errorBody !== null && "code" in errorBody && errorBody.code === RBAC_STALE_CODE)) return context.response;
2111
+ try {
2112
+ await __refreshAuth_wrapped(client);
2113
+ } catch {
2114
+ return context.response;
2115
+ }
2116
+ if (!client.token) return context.response;
2117
+ const headers = { ...context.init.headers };
2118
+ delete headers[RBAC_STALE_RETRY_HEADER];
2119
+ delete headers[MFA_TOKEN_HEADER];
2120
+ delete headers[ELEVATED_ACCESS_TOKEN_HEADER];
2121
+ headers.Authorization = `Bearer ${client.token}`;
2122
+ return context.fetch(context.url, {
2123
+ ...context.init,
2124
+ headers: {
2125
+ ...headers,
2126
+ [RBAC_STALE_RETRY_HEADER]: "1"
2127
+ }
2128
+ });
2129
+ } });
2093
2130
 
2094
2131
  //#endregion
2095
- //#region src/modules/wallets/getWalletProviders/getWalletProviders.ts
2132
+ //#region src/modules/apiClient/createApiClient.ts
2096
2133
  /**
2097
- * Get all available wallet providers to interact with internally.
2134
+ * Returns a new instance of the SDK API client.
2135
+ *
2136
+ * This is not meant for storing, as it is very light we can create it whenever needed.
2098
2137
  * @notInstrumented
2099
2138
  */
2100
- const getWalletProviders = (client) => {
2101
- return getWalletProviderRegistry(client).listProviders();
2102
- };
2103
-
2104
- //#endregion
2105
- //#region src/modules/waas/constants.ts
2106
- const DEFAULT_WAAS_BASE_API_URL = "https://app.dynamicauth.com";
2107
- const DEFAULT_WAAS_BASE_MPC_RELAY_API_URL = "https://relay.dynamicauth.com";
2108
- const DYNAMIC_WAAS_METADATA = {
2109
- displayName: "Dynamic WaaS",
2110
- icon: `${DYNAMIC_ICONIC_SPRITE_URL}#dynamicwaas`,
2111
- normalizedWalletName: "dynamicwaas"
2139
+ const createApiClient = (options = {}, client) => {
2140
+ return createBaseApiClient({
2141
+ middleware: [createDeviceSignatureHeadersMiddleware(client), createRbacStaleMiddleware(client)],
2142
+ options
2143
+ }, client);
2112
2144
  };
2113
2145
 
2114
2146
  //#endregion
2115
- //#region src/modules/waas/isWaasWalletProvider/isWaasWalletProvider.ts
2116
- /** @notInstrumented */
2117
- const isWaasWalletProvider = (walletProvider) => {
2118
- return walletProvider.key.includes(DYNAMIC_WAAS_METADATA.normalizedWalletName);
2147
+ //#region src/errors/NoWalletProviderFoundError.ts
2148
+ var NoWalletProviderFoundError = class extends BaseError {
2149
+ constructor({ walletProviderKey }) {
2150
+ super({
2151
+ cause: null,
2152
+ code: "no_wallet_provider_found_error",
2153
+ docsUrl: null,
2154
+ name: "NoWalletProviderFoundError",
2155
+ shortMessage: `No wallet provider found with key: ${walletProviderKey}`
2156
+ });
2157
+ }
2119
2158
  };
2120
2159
 
2121
2160
  //#endregion
2122
- //#region src/modules/waas/findWaasWalletProviderByChain/findWaasWalletProviderByChain.ts
2161
+ //#region src/modules/wallets/utils/getWalletProviderFromWalletAccount/getWalletProviderFromWalletAccount.ts
2123
2162
  /** @notInstrumented */
2124
- const findWaasWalletProviderByChain = ({ chain }, client) => {
2125
- const providers = getWalletProviders(client);
2126
- const waasProviderKey = formatWalletProviderKey({
2127
- chain,
2128
- displayName: DYNAMIC_WAAS_METADATA.displayName,
2129
- walletProviderType: WalletProviderEnum.EmbeddedWallet
2130
- });
2131
- const waasProvider = providers.find((provider) => provider.key === waasProviderKey && provider.chain === chain);
2132
- if (!waasProvider || !isWaasWalletProvider(waasProvider)) return null;
2133
- return waasProvider;
2134
- };
2135
-
2136
- //#endregion
2137
- //#region src/modules/waas/isWaasWalletAccount/isWaasWalletAccount.ts
2138
- /**
2139
- * This function determines whether the provided wallet account is a Dynamic
2140
- * WaaS wallet account.
2141
- *
2142
- * @param params.walletAccount - The wallet account to check.
2143
- * @returns True if the wallet account is a WaaS wallet account, false otherwise.
2144
- * @notInstrumented
2145
- */
2146
- const isWaasWalletAccount = ({ walletAccount }) => {
2147
- return walletAccount.walletProviderKey.includes(DYNAMIC_WAAS_METADATA.normalizedWalletName);
2163
+ const getWalletProviderFromWalletAccount = ({ walletAccount }, client) => {
2164
+ const walletProvider = getWalletProviderRegistry(client).getByKey(walletAccount.walletProviderKey);
2165
+ if (!walletProvider) throw new NoWalletProviderFoundError({ walletProviderKey: walletAccount.walletProviderKey });
2166
+ return walletProvider;
2148
2167
  };
2149
2168
 
2150
2169
  //#endregion
2151
- //#region src/modules/waas/initializeWaasClientsForEagerRecovery/initializeWaasClientsForEagerRecovery.ts
2170
+ //#region src/utils/retryOnFail/InvalidRetryOnFailCallError.ts
2152
2171
  /**
2153
- * On login, boots the WaaS client once per chain so the SDK eagerly recovers
2154
- * key shares itself (the `eagerlyRecoverKeyShares` capability) instead of the
2155
- * host looping per wallet. Booting calls `initialize()`, which sends the auth
2156
- * token the iframe needs to self-recover.
2157
- *
2158
- * @notInstrumented
2172
+ * This error is thrown when the `retryOnFail` function is called with an invalid
2173
+ * number of retries (i.e. less than 0).
2159
2174
  */
2160
- const initializeWaasClientsForEagerRecovery = async (client) => {
2161
- /**
2162
- * Booting triggers recovery, which fails if the user is missing the MFA auth.
2163
- * This early return avoids attempting a call we know will fail and just adds
2164
- * noise to the logs.
2165
- */
2166
- if (isUserMissingMfaAuth(client)) return;
2167
- const waasChains = new Set(getWalletAccounts(client).filter((walletAccount) => isWaasWalletAccount({ walletAccount })).map((walletAccount) => walletAccount.chain));
2168
- await Promise.all([...waasChains].map(async (chain) => {
2169
- const provider = findWaasWalletProviderByChain({ chain }, client);
2170
- /**
2171
- * The environment might not have the embedded wallet extensions installed.
2172
- * In that case there is no provider for the chain and nothing to boot.
2173
- */
2174
- if (!provider) return;
2175
- try {
2176
- await provider.getWaasClient();
2177
- } catch (error) {
2178
- getCore(client).logger.warn("[initializeWaasClientsForEagerRecovery] failed to boot waas client", error);
2179
- }
2180
- }));
2181
- };
2182
-
2183
- //#endregion
2184
- //#region src/errors/InvalidParamError.ts
2185
- var InvalidParamError = class extends BaseError {
2186
- constructor(message) {
2175
+ var InvalidRetryOnFailCallError = class extends BaseError {
2176
+ constructor(maxRetries) {
2187
2177
  super({
2188
2178
  cause: null,
2189
- code: "invalid_param_error",
2179
+ code: "invalid_retry_on_fail_call_error",
2190
2180
  docsUrl: null,
2191
- name: "InvalidParamError",
2192
- shortMessage: message
2181
+ name: "InvalidRetryOnFailCallError",
2182
+ shortMessage: `Invalid retries parameter for retryOnFail call: ${maxRetries}`
2193
2183
  });
2194
2184
  }
2195
2185
  };
2196
2186
 
2197
2187
  //#endregion
2198
- //#region src/modules/auth/decodeJwt/decodeJwt.ts
2188
+ //#region src/utils/retryOnFail/retryOnFail.ts
2189
+ /** @notInstrumented */
2190
+ const retryOnFail = async ({ delay = 0, fn, maxRetries }) => {
2191
+ for (let retry = 0; retry <= maxRetries; retry++) try {
2192
+ return await fn();
2193
+ } catch (error) {
2194
+ if (retry >= maxRetries) throw error;
2195
+ if (delay > 0) await new Promise((resolve) => setTimeout(resolve, delay));
2196
+ }
2197
+ /**
2198
+ * Reaching this point should never happen and this
2199
+ * error is thrown to help us debug the issue.
2200
+ */
2201
+ throw new InvalidRetryOnFailCallError(maxRetries);
2202
+ };
2203
+
2204
+ //#endregion
2205
+ //#region src/modules/auth/isSignedIn/isSignedIn.ts
2199
2206
  /**
2200
- * Decodes a JWT token and returns the full payload.
2207
+ * Checks if the user is currently signed in to the Dynamic client.
2201
2208
  *
2202
- * This function extracts and returns the complete JWT payload including scopes,
2203
- * expiration time, and other claims.
2209
+ * The client is considered to be in a signed in state if a user has
2210
+ * authenticated or if the client has at least one wallet connected.
2204
2211
  *
2205
- * @param jwt - The JWT token string.
2206
- * @returns The decoded JWT payload object.
2207
- * @throws InvalidParamError if the token is invalid or cannot be decoded.
2212
+ * @deprecated What counts as "signed in" is your app's business logic, not the
2213
+ * SDK's. This helper bakes in one opinion (a user OR any connected wallet),
2214
+ * which rarely matches every app and forces a dependency on us for every
2215
+ * variation. Compose your own check from the underlying primitives instead —
2216
+ * e.g. `Boolean(client.user) || isAnyWalletAccountConnected(client)` — and
2217
+ * layer in whatever your app requires (device registration, completed
2218
+ * onboarding, satisfied MFA, a required embedded wallet, …). See the
2219
+ * "Check if signed in" guide:
2220
+ * https://www.dynamic.xyz/docs/javascript/user-session-management
2208
2221
  *
2209
2222
  * @example
2210
- * ```typescript
2211
- * const payload = decodeJwt(jwt);
2212
- * // Returns: { scopes: ['wallet:export'], exp: 1234567890, ... }
2223
+ * ```ts
2224
+ * if (isSignedIn()) {
2225
+ * console.log('User is authenticated or has a wallet connected');
2226
+ * }
2213
2227
  * ```
2228
+ *
2229
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
2230
+ * @returns True if the user is signed in, false otherwise.
2231
+ * @see logout
2232
+ * @see isAnyWalletAccountConnected
2214
2233
  * @notInstrumented
2215
2234
  */
2216
- const decodeJwt = (jwt) => {
2217
- try {
2218
- const parts = jwt.split(".");
2219
- if (parts.length !== 3) throw new InvalidParamError("Invalid JWT format");
2220
- const base64Payload = parts[1].replaceAll("-", "+").replaceAll("_", "/");
2221
- const paddedPayload = base64Payload + "=".repeat((4 - base64Payload.length % 4) % 4);
2222
- const decodedPayload = atob(paddedPayload);
2223
- return JSON.parse(decodedPayload);
2224
- } catch (error) {
2225
- if (error instanceof InvalidParamError) throw error;
2226
- throw new InvalidParamError(`Failed to decode JWT: ${error instanceof Error ? error.message : String(error)}`);
2227
- }
2228
- };
2235
+ const isSignedIn = (client = getDefaultClient()) => Boolean(client.user || getWalletAccounts(client).length > 0);
2229
2236
 
2230
2237
  //#endregion
2231
- //#region src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/normalizeScopes/normalizeScopes.ts
2238
+ //#region src/modules/projectSettings/fetchProjectSettings/projectSettingsExpirationScheme.ts
2232
2239
  /**
2233
- * Normalizes scopes by deduplicating and sorting them.
2234
- * This creates a canonical representation for comparison.
2235
- *
2236
- * @param scopes - Array of scope strings (may contain duplicates)
2237
- * @returns Normalized, sorted array of unique scopes
2238
- * @notInstrumented
2240
+ * The schema to track the expiration time of the project settings.
2239
2241
  */
2240
- const normalizeScopes = (scopes) => {
2241
- return [...new Set(scopes)].sort((a, b) => a.localeCompare(b));
2242
- };
2242
+ const projectSettingsExpirationStorageKeySchema = createStorageKeySchema({
2243
+ key: "projectSettingsExpiration",
2244
+ schema: z.number()
2245
+ });
2243
2246
 
2244
2247
  //#endregion
2245
- //#region src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/parseElevatedAccessToken/parseElevatedAccessToken.ts
2248
+ //#region src/modules/projectSettings/fetchProjectSettings/fetchProjectSettings.ts
2246
2249
  /**
2247
- * Validates and parses an elevated access token from a JWT string.
2248
- * Extracts scopes, expiration, and validates the token structure.
2250
+ * Expiration time of the project settings in milliseconds.
2251
+ */
2252
+ const PROJECT_SETTINGS_EXPIRATION_TIME = 1e3 * 60 * 5;
2253
+ /**
2254
+ * Fetches and updates the project settings from the API.
2249
2255
  *
2250
- * Policy decisions:
2251
- * - Tokens without scopes are rejected (returns null)
2252
- * - Tokens with empty scopes array are rejected (returns null)
2253
- * - Tokens without exp field are rejected (returns null)
2254
- * - Expired tokens are rejected (returns null)
2256
+ * This function retrieves the latest project configuration settings
2257
+ * from Dynamic's servers, including authentication options, enabled chains,
2258
+ * and security configurations. The settings are cached for performance.
2255
2259
  *
2256
- * @returns Parsed token data or null if token is invalid/expired
2260
+ * @example
2261
+ * ```ts
2262
+ * const settings = await fetchProjectSettings();
2263
+ * console.log('Enabled chains:', settings.chains);
2264
+ * ```
2265
+ *
2266
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
2267
+ * @returns A promise that resolves to the updated project settings.
2268
+ * @see createDynamicClient
2269
+ * @see initializeClient
2257
2270
  * @notInstrumented
2271
+ * @noHook Internal settings fetch that is not part of the public hook surface.
2258
2272
  */
2259
- const parseElevatedAccessToken = ({ token }) => {
2260
- const payload = decodeJwt(token);
2261
- const filteredScopes = ((payload?.scope)?.split(" ") ?? []).filter((s) => s.length > 0);
2262
- const singleUse = payload.singleUse ?? false;
2263
- if (!filteredScopes || filteredScopes.length === 0) return null;
2264
- if (!payload.exp) return null;
2265
- const expiresAt = /* @__PURE__ */ new Date(payload.exp * 1e3);
2266
- if (expiresAt <= /* @__PURE__ */ new Date()) return null;
2267
- return {
2268
- expiresAt,
2269
- normalizedScopes: normalizeScopes(filteredScopes),
2270
- scopes: filteredScopes,
2271
- singleUse,
2272
- token
2273
+ const fetchProjectSettings = async (client = getDefaultClient()) => {
2274
+ const core = getCore(client);
2275
+ const currentExpiration = await core.storage.getItem(projectSettingsExpirationStorageKeySchema);
2276
+ if (Boolean(client.projectSettings) && !(currentExpiration && currentExpiration < Date.now()) && isSignedIn(client)) return client.projectSettings;
2277
+ const apiClient = createApiClient({}, client);
2278
+ core.logger.debug("[fetchProjectSettings] Fetching project settings...");
2279
+ const doFetch = async () => apiClient.getEnvironmentSettings({
2280
+ environmentId: core.environmentId,
2281
+ sdkVersion: `${CLIENT_SDK_NAME}/${core.version}`
2282
+ }, { credentials: "omit" });
2283
+ const projectSettings = await retryOnFail({
2284
+ fn: doFetch,
2285
+ maxRetries: 2
2286
+ });
2287
+ core.state.set({ projectSettings: projectSettings ?? null });
2288
+ await core.storage.setItem(projectSettingsExpirationStorageKeySchema, Date.now() + PROJECT_SETTINGS_EXPIRATION_TIME);
2289
+ return projectSettings;
2290
+ };
2291
+
2292
+ //#endregion
2293
+ //#region src/modules/sessionKeys/generateSessionKeys/generateSessionKeys.ts
2294
+ /** @notInstrumented */
2295
+ const generateSessionKeys = async (client) => {
2296
+ const core = getCore(client);
2297
+ const currentState = core.state.get();
2298
+ const isRotation = Boolean(currentState.sessionKeys);
2299
+ const logContext = {
2300
+ environmentId: core.environmentId,
2301
+ operation: isRotation ? "rotate" : "create",
2302
+ userId: currentState.user?.id ?? null
2273
2303
  };
2304
+ core.logger.info(isRotation ? "[generateSessionKeys] Rotating session key..." : "[generateSessionKeys] Creating session key...", logContext);
2305
+ await core.keychain.removeKey("session");
2306
+ const publicKey = await core.keychain.generateKey("session");
2307
+ assertDefined(publicKey, "Public key not found");
2308
+ core.state.set({ sessionKeys: publicKey });
2309
+ core.logger.info(isRotation ? "[generateSessionKeys] Session key rotated" : "[generateSessionKeys] Session key created", logContext);
2310
+ return { publicKey };
2274
2311
  };
2275
2312
 
2276
2313
  //#endregion
2277
- //#region src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/upsertElevatedAccessToken/upsertElevatedAccessToken.ts
2314
+ //#region src/modules/wallets/utils/getAvailableWalletProvidersFromWalletAccounts/getAvailableWalletProvidersFromWalletAccounts.ts
2315
+ /** @notInstrumented */
2316
+ const getAvailableWalletProvidersFromWalletAccounts = (client) => {
2317
+ const core = getCore(client);
2318
+ const walletProvidersMap = /* @__PURE__ */ new Map();
2319
+ getWalletAccounts(client).forEach((walletAccount) => {
2320
+ if (walletProvidersMap.has(walletAccount.walletProviderKey)) return;
2321
+ try {
2322
+ const walletProvider = getWalletProviderFromWalletAccount({ walletAccount }, client);
2323
+ walletProvidersMap.set(walletAccount.walletProviderKey, walletProvider);
2324
+ } catch (error) {
2325
+ core.logger.debug("Wallet provider not found for wallet account", {
2326
+ error,
2327
+ walletAccount: walletAccount.address
2328
+ });
2329
+ }
2330
+ });
2331
+ return Array.from(walletProvidersMap.values());
2332
+ };
2333
+
2334
+ //#endregion
2335
+ //#region src/modules/wallets/destroyWalletProviders/destroyWalletProviders.ts
2278
2336
  /**
2279
- * Upserts an elevated access token into the current tokens array.
2337
+ * Tear down every wallet provider on the client.
2280
2338
  *
2281
- * Policy: Only one token per normalized scope-set is allowed.
2282
- * If a token with the same normalized scopes exists, it is replaced.
2283
- * This ensures we don't accumulate multiple tokens for the same scope combination.
2339
+ * Each provider's `destroy` is responsible for its own local + remote
2340
+ * cleanup. We swallow errors so a failing destroy on one provider does not
2341
+ * block teardown of the others (e.g. during logout).
2284
2342
  *
2285
- * @param currentTokens - Current array of elevated access tokens
2286
- * @param newToken - New token to upsert
2287
- * @returns Updated array of tokens with the new token upserted
2288
2343
  * @notInstrumented
2289
2344
  */
2290
- const upsertElevatedAccessToken = ({ currentTokens, newToken }) => {
2291
- const newScopeKey = normalizeScopes(newToken.scopes).join(" ");
2292
- return [...currentTokens.filter((existingToken) => {
2293
- return normalizeScopes(existingToken.scopes).join(" ") !== newScopeKey;
2294
- }), {
2295
- expiresAt: newToken.expiresAt,
2296
- scopes: newToken.scopes,
2297
- singleUse: newToken.singleUse,
2298
- token: newToken.token
2299
- }];
2345
+ const destroyWalletProviders = async ({ reason }, client) => {
2346
+ const core = getCore(client);
2347
+ const walletProviders = getAvailableWalletProvidersFromWalletAccounts(client);
2348
+ await Promise.all(walletProviders.map(async (walletProvider) => {
2349
+ if (!walletProvider.destroy) return;
2350
+ try {
2351
+ await walletProvider.destroy({ reason });
2352
+ } catch (err) {
2353
+ core.logger.error(`Error destroying wallet provider ${walletProvider.key}`, err);
2354
+ }
2355
+ }));
2300
2356
  };
2301
2357
 
2302
2358
  //#endregion
2303
- //#region src/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.ts
2304
- /** @notInstrumented */
2305
- const updateAuthFromVerifyResponse = ({ response }, client) => {
2359
+ //#region src/modules/auth/logoutWithReason/logoutWithReason.ts
2360
+ /**
2361
+ * Logs the user out with an explicit reason.
2362
+ *
2363
+ * Revokes the session, clears auth state, terminates wallet providers, and
2364
+ * emits the `logout` client event with the given reason. The reason is also
2365
+ * captured as an argument on the function-instrumentation event, which is
2366
+ * how Datadog distinguishes between different logout causes.
2367
+ *
2368
+ * Use this instead of the public `logout` when triggering a logout from
2369
+ * internal or extension code — the caller owns the reason string, so the
2370
+ * telemetry correctly attributes *why* the logout happened.
2371
+ *
2372
+ * @param params - The logout params.
2373
+ * @param params.reason - Why the logout is being triggered. Extension authors
2374
+ * needing a reason outside the SDK catalog can cast with `as LogoutReason`.
2375
+ * @param client - The Dynamic client instance.
2376
+ * @instrumented
2377
+ */
2378
+ const logoutWithReason = async ({ reason }, client) => {
2306
2379
  const core = getCore(client);
2307
- const previousState = { ...core.state.get() };
2308
- const { user, minifiedJwt, jwt, expiresAt, mfaToken, elevatedAccessToken } = response;
2309
- const sessionExpiresAt = /* @__PURE__ */ new Date(expiresAt * 1e3);
2310
- const newState = {
2311
- legacyToken: jwt ?? null,
2312
- sessionExpiresAt,
2313
- token: minifiedJwt ?? null,
2314
- user
2315
- };
2316
- if (mfaToken) newState.mfaToken = mfaToken;
2317
- const currentTokens = core.state.get().elevatedAccessTokens || [];
2318
- newState.elevatedAccessTokens = currentTokens;
2319
- if (elevatedAccessToken) {
2320
- const parsedToken = parseElevatedAccessToken({ token: elevatedAccessToken });
2321
- if (parsedToken) newState.elevatedAccessTokens = upsertElevatedAccessToken({
2322
- currentTokens,
2323
- newToken: parsedToken
2324
- });
2380
+ core.logger.debug("[logoutWithReason] Logging out...", { reason });
2381
+ await destroyWalletProviders({ reason }, client);
2382
+ if (client.user !== null) {
2383
+ const apiClient = createApiClient({ headers: { [DYNAMIC_LOGOUT_REASON_HEADER]: reason } }, client);
2384
+ try {
2385
+ await apiClient.revokeSession({ environmentId: core.environmentId });
2386
+ } catch (error) {
2387
+ core.logger.error("Failed to revoke session", error);
2388
+ }
2389
+ /**
2390
+ * This deletes the auth cookie if it exists.
2391
+ * If the cookie doesn't exist, this sets a new cookie that expires immediately.
2392
+ */
2393
+ if (isCookieEnabled(client)) setCookie(`${DYNAMIC_AUTH_COOKIE_NAME}=; Max-Age=-99999999; path=/; SameSite=Lax${getSecureCookieAttribute()}`);
2325
2394
  }
2326
- core.state.set(newState);
2327
- /**
2328
- * For customers using a sandbox environment with cookies enabled, we need to set the cookie
2329
- * programmatically because Redcoast won't set the cookie via headers. We set the cookie programmatically
2330
- * so customers can access the cookie from document.cookie consistently between sandbox and live environments.
2331
- */
2332
- if (minifiedJwt && isCookieEnabled(client)) setCookie(`${DYNAMIC_AUTH_COOKIE_NAME}=${minifiedJwt}; expires=${sessionExpiresAt.toUTCString()}; path=/; SameSite=Lax${getSecureCookieAttribute()}`);
2395
+ await core.keychain.removeKey("session");
2396
+ const previousState = core.state.get();
2397
+ core.state.set({
2398
+ captchaToken: null,
2399
+ elevatedAccessTokens: [],
2400
+ legacyToken: null,
2401
+ mfaToken: null,
2402
+ sessionExpiresAt: null,
2403
+ sessionKeys: null,
2404
+ token: null,
2405
+ unverifiedWalletAccounts: [],
2406
+ user: null
2407
+ });
2408
+ emitEvent({
2409
+ args: { reason },
2410
+ event: "logout"
2411
+ }, client);
2333
2412
  checkAndRaiseWalletAccountsChangedEvent({ previousState }, client);
2334
- if (!previousState.user && Boolean(newState.user)) initializeWaasClientsForEagerRecovery(client);
2413
+ fetchProjectSettings(client);
2414
+ generateSessionKeys(client);
2335
2415
  };
2416
+ const __logoutWithReason_impl = logoutWithReason;
2417
+ const __logoutWithReason_wrapped = instrumentFunction({
2418
+ fn: __logoutWithReason_impl,
2419
+ functionName: "logoutWithReason",
2420
+ getCore: () => {
2421
+ try {
2422
+ return getCore(getDefaultClient());
2423
+ } catch {
2424
+ return;
2425
+ }
2426
+ }
2427
+ });
2336
2428
 
2337
2429
  //#endregion
2338
- export { createStorageKeySchema as $, fetchProjectSettings as A, InvalidWalletProviderKeyError as B, emitWalletAccountsChangedEvent as C, name as Ct, createRuntimeServiceAccessKey as D, getWalletProviderRegistry as E, getChainFromVerifiedCredentialChain as F, onceEvent as G, emitEvent as H, CHAINS_INFO_MAP as I, getHeadersForNonceSignedByDeviceSigners as J, createApiClient as K, formatWalletAccountId as L, getWalletAccounts as M, formatWalletProviderKey as N, NoWalletProviderFoundError as O, normalizeWalletNameWithChain as P, updateNoncePoolStorage as Q, normalizeAddress as R, checkAndRaiseWalletAccountsChangedEvent as S, getCore as St, WalletProviderPriority as T, offEvent as U, retryOnFail as V, onEvent as W, getNonce as X, getDeviceSigner as Y, fetchAndStoreNonces as Z, scrubParameters as _, NONCE_POOL_SIZE as _t, InvalidParamError as a, InvalidExternalAuthError as at, getOperatingSystem as b, ClientNotFoundError as bt, findWaasWalletProviderByChain as c, DYNAMIC_ICONIC_SPRITE_URL as ct, DEFAULT_WAAS_BASE_MPC_RELAY_API_URL as d, isCookieEnabled as dt, UnauthorizedError as et, DYNAMIC_WAAS_METADATA as f, assertDefined as ft, instrumentFunction as g, getPlatform as gt, __logoutWithReason_wrapped as h, randomString as ht, decodeJwt as i, LinkCredentialError as it, isSignedIn as j, generateSessionKeys as k, isWaasWalletProvider as l, SDK_API_CORE_VERSION as lt, isUserMissingMfaAuth as m, getElevatedAccessToken as mt, upsertElevatedAccessToken as n, MfaRateLimitedError as nt, initializeWaasClientsForEagerRecovery as o, APIError as ot, getWalletProviders as p, ValueMustBeDefinedError as pt, createDeviceSignatureHeadersMiddleware as q, parseElevatedAccessToken as r, MfaInvalidOtpError as rt, isWaasWalletAccount as s, CLIENT_SDK_NAME as st, updateAuthFromVerifyResponse as t, SandboxMaximumThresholdReachedError as tt, DEFAULT_WAAS_BASE_API_URL as u, getSessionKeys as ut, DEFAULT_PII_FIELDS as v, getDefaultClient as vt, getWalletProviderFromWalletAccount as w, version as wt, extractSessionId as x, BaseError as xt, getUserAgent as y, setDefaultClient as yt, splitWalletProviderKey as z };
2339
- //# sourceMappingURL=updateAuthFromVerifyResponse-BLgNMqwN.esm.js.map
2430
+ export { updateNoncePoolStorage as $, getWalletProviders as A, normalizeWalletNameWithChain as B, initializeWaasClientsForEagerRecovery as C, BaseError as Ct, DEFAULT_WAAS_BASE_API_URL as D, isWaasWalletProvider as E, version as Et, onEvent as F, splitWalletProviderKey as G, CHAINS_INFO_MAP as H, onceEvent as I, createDeviceSignatureHeadersMiddleware as J, InvalidWalletProviderKeyError as K, createRuntimeServiceAccessKey as L, getWalletProviderRegistry as M, emitEvent as N, DEFAULT_WAAS_BASE_MPC_RELAY_API_URL as O, offEvent as P, fetchAndStoreNonces as Q, getWalletAccounts as R, emitWalletAccountsChangedEvent as S, getCore as St, findWaasWalletProviderByChain as T, name as Tt, formatWalletAccountId as U, getChainFromVerifiedCredentialChain as V, normalizeAddress as W, getDeviceSigner as X, getHeadersForNonceSignedByDeviceSigners as Y, getNonce as Z, upsertElevatedAccessToken as _, randomString as _t, retryOnFail as a, MfaInvalidOtpError as at, InvalidParamError as b, setDefaultClient as bt, createApiClient as c, APIError as ct, scrubParameters as d, SDK_API_CORE_VERSION as dt, createStorageKeySchema as et, DEFAULT_PII_FIELDS as f, getSessionKeys as ft, updateAuthFromVerifyResponse as g, getElevatedAccessToken as gt, extractSessionId as h, ValueMustBeDefinedError as ht, isSignedIn as i, MfaRateLimitedError as it, WalletProviderPriority as j, DYNAMIC_WAAS_METADATA as k, __refreshAuth_wrapped as l, CLIENT_SDK_NAME as lt, getOperatingSystem as m, assertDefined as mt, generateSessionKeys as n, UnauthorizedError as nt, getWalletProviderFromWalletAccount as o, LinkCredentialError as ot, getUserAgent as p, isCookieEnabled as pt, isUserMissingMfaAuth as q, fetchProjectSettings as r, SandboxMaximumThresholdReachedError as rt, NoWalletProviderFoundError as s, InvalidExternalAuthError as st, __logoutWithReason_wrapped as t, NONCE_POOL_SIZE as tt, instrumentFunction as u, DYNAMIC_ICONIC_SPRITE_URL as ut, parseElevatedAccessToken as v, getPlatform as vt, isWaasWalletAccount as w, TokenScope$1 as wt, checkAndRaiseWalletAccountsChangedEvent as x, ClientNotFoundError as xt, decodeJwt as y, getDefaultClient as yt, formatWalletProviderKey as z };
2431
+ //# sourceMappingURL=logoutWithReason-CIsCVAUE.esm.js.map