@dynamic-labs-sdk/client 0.1.0-alpha.9 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +308 -0
- package/InvalidParamError.cjs.js +2 -2
- package/InvalidParamError.esm.js +1 -1
- package/NotWaasWalletAccountError.cjs.js +7 -7
- package/NotWaasWalletAccountError.esm.js +2 -2
- package/constants.cjs.js +493 -9
- package/constants.cjs2.js +15 -0
- package/constants.esm.js +468 -7
- package/constants.esm2.js +11 -0
- package/core.cjs.js +96 -41
- package/core.esm.js +47 -10
- package/filterDuplicates.cjs.js +8 -0
- package/filterDuplicates.esm.js +6 -0
- package/getNetworkProviderFromNetworkId.cjs.js +178 -20
- package/getNetworkProviderFromNetworkId.esm.js +150 -3
- package/getSignedSessionId.cjs.js +7 -7
- package/getSignedSessionId.esm.js +2 -2
- package/getVerifiedCredentialForWalletAccount.cjs.js +515 -0
- package/getVerifiedCredentialForWalletAccount.esm.js +491 -0
- package/index.cjs.js +1235 -471
- package/index.esm.js +1033 -282
- package/isMfaRequiredForAction.cjs.js +15 -8
- package/isMfaRequiredForAction.esm.js +8 -2
- package/package.json +4 -4
- package/src/client/core/createCore/createCore.d.ts.map +1 -1
- package/src/client/core/createCore/getInitialState.d.ts.map +1 -1
- package/src/client/core/types/DynamicCore.d.ts +8 -0
- package/src/client/core/types/DynamicCore.d.ts.map +1 -1
- package/src/client/createDynamicClient/createDynamicClient.d.ts.map +1 -1
- package/src/client/types/DynamicClientConfig.d.ts +6 -1
- package/src/client/types/DynamicClientConfig.d.ts.map +1 -1
- package/src/constants.d.ts +1 -0
- package/src/constants.d.ts.map +1 -1
- package/src/errors/APIError/APIError.d.ts.map +1 -1
- package/src/errors/InvalidWalletProviderKeyError.d.ts +5 -0
- package/src/errors/InvalidWalletProviderKeyError.d.ts.map +1 -0
- package/src/errors/MissingUserVerificationError.d.ts +12 -0
- package/src/errors/MissingUserVerificationError.d.ts.map +1 -0
- package/src/errors/NoSmartWalletAccountSignerFoundError.d.ts +5 -0
- package/src/errors/NoSmartWalletAccountSignerFoundError.d.ts.map +1 -0
- package/src/errors/WalletAccountNotSelectedError.d.ts.map +1 -1
- package/src/exports/core.d.ts +102 -2
- package/src/exports/core.d.ts.map +1 -1
- package/src/exports/index.d.ts +25 -7
- package/src/exports/index.d.ts.map +1 -1
- package/src/exports/waas.d.ts +2 -0
- package/src/exports/waas.d.ts.map +1 -1
- package/src/modules/apiClient/createApiClient.d.ts.map +1 -1
- package/src/modules/auth/createVisit/createVisit.d.ts.map +1 -1
- package/src/modules/auth/logout/logout.d.ts.map +1 -1
- package/src/modules/auth/passkeys/getPasskeyAuthenticationOptions/getPasskeyAuthenticationOptions.d.ts +4 -1
- package/src/modules/auth/passkeys/getPasskeyAuthenticationOptions/getPasskeyAuthenticationOptions.d.ts.map +1 -1
- package/src/modules/auth/passkeys/getPasskeyAuthenticationSignInOptions/getPasskeyAuthenticationSignInOptions.d.ts +4 -1
- package/src/modules/auth/passkeys/getPasskeyAuthenticationSignInOptions/getPasskeyAuthenticationSignInOptions.d.ts.map +1 -1
- package/src/modules/auth/passkeys/registerPasskey/registerPasskey.d.ts +7 -1
- package/src/modules/auth/passkeys/registerPasskey/registerPasskey.d.ts.map +1 -1
- package/src/modules/auth/passkeys/serverRegisterPasskey/serverRegisterPasskey.d.ts +3 -1
- package/src/modules/auth/passkeys/serverRegisterPasskey/serverRegisterPasskey.d.ts.map +1 -1
- package/src/modules/auth/passkeys/signInWithPasskey/signInWithPasskey.d.ts +4 -1
- package/src/modules/auth/passkeys/signInWithPasskey/signInWithPasskey.d.ts.map +1 -1
- package/src/modules/auth/social/getUserSocialAccounts/getUserSocialAccounts.d.ts +9 -0
- package/src/modules/auth/social/getUserSocialAccounts/getUserSocialAccounts.d.ts.map +1 -0
- package/src/modules/auth/social/getUserSocialAccounts/index.d.ts +2 -0
- package/src/modules/auth/social/getUserSocialAccounts/index.d.ts.map +1 -0
- package/src/modules/auth/social/oauth/{signInWithSocialRedirect/signInWithSocialRedirect.d.ts → authenticateWithSocial/authenticateWithSocial.d.ts} +5 -3
- package/src/modules/auth/social/oauth/authenticateWithSocial/authenticateWithSocial.d.ts.map +1 -0
- package/src/modules/auth/social/oauth/authenticateWithSocial/buildOAuthUrl/addOAuthUrlParams/addOAuthUrlParams.d.ts.map +1 -0
- package/src/modules/auth/social/oauth/authenticateWithSocial/buildOAuthUrl/addOAuthUrlParams/index.d.ts.map +1 -0
- package/src/modules/auth/social/oauth/authenticateWithSocial/buildOAuthUrl/buildOAuthUrl.d.ts.map +1 -0
- package/src/modules/auth/social/oauth/authenticateWithSocial/buildOAuthUrl/getOAuthBaseUrl/getOAuthBaseUrl.d.ts.map +1 -0
- package/src/modules/auth/social/oauth/authenticateWithSocial/buildOAuthUrl/getOAuthBaseUrl/index.d.ts.map +1 -0
- package/src/modules/auth/social/oauth/{signInWithSocialRedirect → authenticateWithSocial}/buildOAuthUrl/index.d.ts.map +1 -1
- package/src/modules/auth/social/oauth/authenticateWithSocial/index.d.ts +2 -0
- package/src/modules/auth/social/oauth/{signInWithSocialRedirect → authenticateWithSocial}/index.d.ts.map +1 -1
- package/src/modules/auth/social/oauth/{completeSocialRedirectSignIn/completeSocialRedirectSignIn.d.ts → completeSocialAuthentication/completeSocialAuthentication.d.ts} +3 -3
- package/src/modules/auth/social/oauth/completeSocialAuthentication/completeSocialAuthentication.d.ts.map +1 -0
- package/src/modules/auth/social/oauth/completeSocialAuthentication/index.d.ts +2 -0
- package/src/modules/auth/social/oauth/{completeSocialRedirectSignIn → completeSocialAuthentication}/index.d.ts.map +1 -1
- package/src/modules/auth/social/oauth/redirectStateStorageSchema/index.d.ts +1 -1
- package/src/modules/auth/social/oauth/redirectStateStorageSchema/index.d.ts.map +1 -1
- package/src/modules/auth/social/oauth/redirectStateStorageSchema/redirectStateStorageSchema.d.ts +1 -1
- package/src/modules/auth/social/oauth/redirectStateStorageSchema/redirectStateStorageSchema.d.ts.map +1 -1
- package/src/modules/auth/social/oauth/unlinkSocialAccount/index.d.ts +2 -0
- package/src/modules/auth/social/oauth/unlinkSocialAccount/index.d.ts.map +1 -0
- package/src/modules/auth/social/oauth/unlinkSocialAccount/unlinkSocialAccount.d.ts +14 -0
- package/src/modules/auth/social/oauth/unlinkSocialAccount/unlinkSocialAccount.d.ts.map +1 -0
- package/src/modules/auth/social/removeDynamicOauthParamsFromUrl/index.d.ts +2 -0
- package/src/modules/auth/social/removeDynamicOauthParamsFromUrl/index.d.ts.map +1 -0
- package/src/modules/auth/social/removeDynamicOauthParamsFromUrl/removeDynamicOauthParamsFromUrl.d.ts +2 -0
- package/src/modules/auth/social/removeDynamicOauthParamsFromUrl/removeDynamicOauthParamsFromUrl.d.ts.map +1 -0
- package/src/modules/auth/social/social.types.d.ts +9 -0
- package/src/modules/auth/social/social.types.d.ts.map +1 -1
- package/src/modules/auth/updateAuthFromVerifyResponse/checkAndRaiseWalletAccountsChangedEvent/checkAndRaiseWalletAccountsChangedEvent.d.ts.map +1 -1
- package/src/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.d.ts.map +1 -1
- package/src/modules/balances/getMultichainBalances/getMultichainBalances.d.ts +1 -2
- package/src/modules/balances/getMultichainBalances/getMultichainBalances.d.ts.map +1 -1
- package/src/modules/balances/getMultichainBalances/index.d.ts +1 -1
- package/src/modules/balances/getMultichainBalances/index.d.ts.map +1 -1
- package/src/modules/funding/coinbase/addCoinbaseOnrampOrderEventListener/addCoinbaseOnrampOrderEventListener.d.ts +18 -0
- package/src/modules/funding/coinbase/addCoinbaseOnrampOrderEventListener/addCoinbaseOnrampOrderEventListener.d.ts.map +1 -0
- package/src/modules/funding/coinbase/addCoinbaseOnrampOrderEventListener/index.d.ts +2 -0
- package/src/modules/funding/coinbase/addCoinbaseOnrampOrderEventListener/index.d.ts.map +1 -0
- package/src/modules/funding/coinbase/coinbase.types.d.ts +269 -0
- package/src/modules/funding/coinbase/coinbase.types.d.ts.map +1 -0
- package/src/modules/funding/coinbase/createCoinbaseOnrampOrder/createCoinbaseOnrampOrder.d.ts +11 -0
- package/src/modules/funding/coinbase/createCoinbaseOnrampOrder/createCoinbaseOnrampOrder.d.ts.map +1 -0
- package/src/modules/funding/coinbase/createCoinbaseOnrampOrder/index.d.ts +2 -0
- package/src/modules/funding/coinbase/createCoinbaseOnrampOrder/index.d.ts.map +1 -0
- package/src/modules/funding/coinbase/getCoinbaseBuyUrl/getCoinbaseBuyUrl.d.ts +10 -0
- package/src/modules/funding/coinbase/getCoinbaseBuyUrl/getCoinbaseBuyUrl.d.ts.map +1 -0
- package/src/modules/funding/coinbase/getCoinbaseBuyUrl/index.d.ts +2 -0
- package/src/modules/funding/coinbase/getCoinbaseBuyUrl/index.d.ts.map +1 -0
- package/src/modules/funding/coinbase/getMissingVerificationForCoinbaseOnrampOrder/getMissingVerificationForCoinbaseOnrampOrder.d.ts +23 -0
- package/src/modules/funding/coinbase/getMissingVerificationForCoinbaseOnrampOrder/getMissingVerificationForCoinbaseOnrampOrder.d.ts.map +1 -0
- package/src/modules/funding/coinbase/getMissingVerificationForCoinbaseOnrampOrder/index.d.ts +2 -0
- package/src/modules/funding/coinbase/getMissingVerificationForCoinbaseOnrampOrder/index.d.ts.map +1 -0
- package/src/modules/funding/coinbase/utils/validateUserCredentialsForCoinbaseOnrampOrder/index.d.ts +2 -0
- package/src/modules/funding/coinbase/utils/validateUserCredentialsForCoinbaseOnrampOrder/index.d.ts.map +1 -0
- package/src/modules/funding/coinbase/utils/validateUserCredentialsForCoinbaseOnrampOrder/validateUserCredentialsForCoinbaseOnrampOrder.d.ts +4 -0
- package/src/modules/funding/coinbase/utils/validateUserCredentialsForCoinbaseOnrampOrder/validateUserCredentialsForCoinbaseOnrampOrder.d.ts.map +1 -0
- package/src/modules/funding/cryptoDotCom/createCryptoDotComPayment/createCryptoDotComPayment.d.ts +10 -0
- package/src/modules/funding/cryptoDotCom/createCryptoDotComPayment/createCryptoDotComPayment.d.ts.map +1 -0
- package/src/modules/funding/cryptoDotCom/createCryptoDotComPayment/index.d.ts +2 -0
- package/src/modules/funding/cryptoDotCom/createCryptoDotComPayment/index.d.ts.map +1 -0
- package/src/modules/funding/cryptoDotCom/cryptoDotCom.types.d.ts +8 -0
- package/src/modules/funding/cryptoDotCom/cryptoDotCom.types.d.ts.map +1 -0
- package/src/modules/initializeClient/consts.d.ts +5 -0
- package/src/modules/initializeClient/consts.d.ts.map +1 -0
- package/src/modules/initializeClient/initializeClient.d.ts.map +1 -1
- package/src/modules/initializeClient/waitForProjectSettings/index.d.ts +2 -0
- package/src/modules/initializeClient/waitForProjectSettings/index.d.ts.map +1 -0
- package/src/modules/initializeClient/waitForProjectSettings/waitForProjectSettings.d.ts +3 -0
- package/src/modules/initializeClient/waitForProjectSettings/waitForProjectSettings.d.ts.map +1 -0
- package/src/modules/mfa/authenticatePasskeyMFA/authenticatePasskeyMFA.d.ts +2 -1
- package/src/modules/mfa/authenticatePasskeyMFA/authenticatePasskeyMFA.d.ts.map +1 -1
- package/src/modules/otp/verifyOTP/verifyOTP.d.ts +3 -2
- package/src/modules/otp/verifyOTP/verifyOTP.d.ts.map +1 -1
- package/src/modules/projectSettings/fetchProjectSettings/fetchProjectSettings.d.ts.map +1 -1
- package/src/modules/projectSettings/fetchProjectSettings/projectSettingsExpirationScheme.d.ts +1 -1
- package/src/modules/projectSettings/fetchProjectSettings/projectSettingsExpirationScheme.d.ts.map +1 -1
- package/src/modules/storageSync/hydrateStateWithStorage/hydrateStateWithStorage.d.ts.map +1 -1
- package/src/modules/storageSync/schema.d.ts +15 -2
- package/src/modules/storageSync/schema.d.ts.map +1 -1
- package/src/modules/storageSync/syncStateWithStorage/syncStateWithStorage.d.ts.map +1 -1
- package/src/modules/user/deleteUser/deleteUser.d.ts +11 -0
- package/src/modules/user/deleteUser/deleteUser.d.ts.map +1 -0
- package/src/modules/user/deleteUser/index.d.ts +2 -0
- package/src/modules/user/deleteUser/index.d.ts.map +1 -0
- package/src/modules/waas/constants.d.ts +2 -2
- package/src/modules/waas/constants.d.ts.map +1 -1
- package/src/modules/waas/createWaasProvider/createWaasProvider.d.ts.map +1 -1
- package/src/modules/waas/createWaasWalletAccounts/createWaasWalletAccounts.d.ts.map +1 -1
- package/src/modules/waas/delegateWaasKeyShares/delegateWaasKeyShares.d.ts.map +1 -1
- package/src/modules/waas/getWaasWalletProviderByChain/getWaasWalletProviderByChain.d.ts.map +1 -1
- package/src/modules/waas/hasDelegatedAccess/hasDelegatedAccess.d.ts +14 -0
- package/src/modules/waas/hasDelegatedAccess/hasDelegatedAccess.d.ts.map +1 -0
- package/src/modules/waas/hasDelegatedAccess/index.d.ts +2 -0
- package/src/modules/waas/hasDelegatedAccess/index.d.ts.map +1 -0
- package/src/modules/waas/isWaasWalletAccount/isWaasWalletAccount.d.ts.map +1 -1
- package/src/modules/waas/isWaasWalletProvider/isWaasWalletProvider.d.ts.map +1 -1
- package/src/modules/waas/revokeWaasDelegation/index.d.ts +2 -0
- package/src/modules/waas/revokeWaasDelegation/index.d.ts.map +1 -0
- package/src/modules/waas/revokeWaasDelegation/revokeWaasDelegation.d.ts +16 -0
- package/src/modules/waas/revokeWaasDelegation/revokeWaasDelegation.d.ts.map +1 -0
- package/src/modules/waas/waas.types.d.ts +4 -0
- package/src/modules/waas/waas.types.d.ts.map +1 -1
- package/src/modules/wallets/connectWithWalletProvider/connectWithWalletProvider.d.ts +4 -3
- package/src/modules/wallets/connectWithWalletProvider/connectWithWalletProvider.d.ts.map +1 -1
- package/src/modules/wallets/constants.d.ts.map +1 -1
- package/src/modules/wallets/getAvailableWalletProvidersData/getAvailableWalletProvidersData.d.ts +2 -6
- package/src/modules/wallets/getAvailableWalletProvidersData/getAvailableWalletProvidersData.d.ts.map +1 -1
- package/src/modules/wallets/getOwnerWalletAccountForSmartWalletAccount/getOwnerWalletAccountForSmartWalletAccount.d.ts +7 -0
- package/src/modules/wallets/getOwnerWalletAccountForSmartWalletAccount/getOwnerWalletAccountForSmartWalletAccount.d.ts.map +1 -0
- package/src/modules/wallets/getOwnerWalletAccountForSmartWalletAccount/index.d.ts +2 -0
- package/src/modules/wallets/getOwnerWalletAccountForSmartWalletAccount/index.d.ts.map +1 -0
- package/src/modules/wallets/getWalletAccountAddressByType/getWalletAccountAddressByType.d.ts +8 -0
- package/src/modules/wallets/getWalletAccountAddressByType/getWalletAccountAddressByType.d.ts.map +1 -0
- package/src/modules/wallets/getWalletAccountAddressByType/index.d.ts +2 -0
- package/src/modules/wallets/getWalletAccountAddressByType/index.d.ts.map +1 -0
- package/src/modules/wallets/getWalletAccounts/getWalletAccounts.d.ts.map +1 -1
- package/src/modules/wallets/getWalletAccounts/getWalletAccountsFromState/getWalletAccountsFromState.d.ts +9 -1
- package/src/modules/wallets/getWalletAccounts/getWalletAccountsFromState/getWalletAccountsFromState.d.ts.map +1 -1
- package/src/modules/wallets/getWalletProviderDataByKey/getWalletProviderDataByKey.d.ts +14 -0
- package/src/modules/wallets/getWalletProviderDataByKey/getWalletProviderDataByKey.d.ts.map +1 -0
- package/src/modules/wallets/getWalletProviderDataByKey/index.d.ts +2 -0
- package/src/modules/wallets/getWalletProviderDataByKey/index.d.ts.map +1 -0
- package/src/modules/wallets/isWalletAccountVerified/index.d.ts +2 -0
- package/src/modules/wallets/isWalletAccountVerified/index.d.ts.map +1 -0
- package/src/modules/wallets/isWalletAccountVerified/isWalletAccountVerified.d.ts +13 -0
- package/src/modules/wallets/isWalletAccountVerified/isWalletAccountVerified.d.ts.map +1 -0
- package/src/modules/wallets/networks/getNetworkDataForNetworkId/getNetworkDataForNetworkId.d.ts +10 -0
- package/src/modules/wallets/networks/getNetworkDataForNetworkId/getNetworkDataForNetworkId.d.ts.map +1 -0
- package/src/modules/wallets/networks/getNetworkDataForNetworkId/index.d.ts +2 -0
- package/src/modules/wallets/networks/getNetworkDataForNetworkId/index.d.ts.map +1 -0
- package/src/modules/wallets/networks/getTransactionHistory/getTransactionHistory.d.ts +26 -0
- package/src/modules/wallets/networks/getTransactionHistory/getTransactionHistory.d.ts.map +1 -0
- package/src/modules/wallets/networks/getTransactionHistory/index.d.ts +3 -0
- package/src/modules/wallets/networks/getTransactionHistory/index.d.ts.map +1 -0
- package/src/modules/wallets/networks/lastKnownNetworkRegistry/createLastKnownNetworkRegistry/createLastKnownNetworkRegistry.d.ts.map +1 -1
- package/src/modules/wallets/networks/lastKnownNetworkRegistry/createLastKnownNetworkRegistry/schema.d.ts +1 -1
- package/src/modules/wallets/networks/lastKnownNetworkRegistry/createLastKnownNetworkRegistry/schema.d.ts.map +1 -1
- package/src/modules/wallets/proveWalletAccountOwnership/proveWalletAccountOwnership.d.ts +1 -1
- package/src/modules/wallets/proveWalletAccountOwnership/proveWalletAccountOwnership.d.ts.map +1 -1
- package/src/modules/wallets/removeWalletAccount/removeWalletAccount.d.ts.map +1 -1
- package/src/modules/wallets/unverifiedWalletAccounts/removeUnverifiedWalletAccount/removeUnverifiedWalletAccount.d.ts.map +1 -1
- package/src/modules/wallets/unverifiedWalletAccounts/schema.d.ts +5 -0
- package/src/modules/wallets/unverifiedWalletAccounts/schema.d.ts.map +1 -1
- package/src/modules/wallets/unverifiedWalletAccounts/setUnverifiedWalletAccounts/setUnverifiedWalletAccounts.d.ts +2 -0
- package/src/modules/wallets/unverifiedWalletAccounts/setUnverifiedWalletAccounts/setUnverifiedWalletAccounts.d.ts.map +1 -1
- package/src/modules/wallets/utils/convertUnverifiedWalletAccountToWalletAccount/convertUnverifiedWalletAccountToWalletAccount.d.ts +5 -1
- package/src/modules/wallets/utils/convertUnverifiedWalletAccountToWalletAccount/convertUnverifiedWalletAccountToWalletAccount.d.ts.map +1 -1
- package/src/modules/wallets/utils/convertVerifiedCredentialToWalletAccount/convertVerifiedCredentialToWalletAccount.d.ts +6 -1
- package/src/modules/wallets/utils/convertVerifiedCredentialToWalletAccount/convertVerifiedCredentialToWalletAccount.d.ts.map +1 -1
- package/src/modules/wallets/utils/formatSignInMessage/formatSignInMessage.d.ts +9 -7
- package/src/modules/wallets/utils/formatSignInMessage/formatSignInMessage.d.ts.map +1 -1
- package/src/modules/wallets/utils/formatWalletAccountId/formatWalletAccountId.d.ts +9 -0
- package/src/modules/wallets/utils/formatWalletAccountId/formatWalletAccountId.d.ts.map +1 -0
- package/src/modules/wallets/utils/formatWalletAccountId/index.d.ts +2 -0
- package/src/modules/wallets/utils/formatWalletAccountId/index.d.ts.map +1 -0
- package/src/modules/wallets/utils/formatWalletProviderKey/formatWalletProviderKey.d.ts +17 -2
- package/src/modules/wallets/utils/formatWalletProviderKey/formatWalletProviderKey.d.ts.map +1 -1
- package/src/modules/wallets/utils/getAddressesWithTypesFromConnectionResult/getAddressesWithTypesFromConnectionResult.d.ts +4 -0
- package/src/modules/wallets/utils/getAddressesWithTypesFromConnectionResult/getAddressesWithTypesFromConnectionResult.d.ts.map +1 -0
- package/src/modules/wallets/utils/getAddressesWithTypesFromConnectionResult/index.d.ts +2 -0
- package/src/modules/wallets/utils/getAddressesWithTypesFromConnectionResult/index.d.ts.map +1 -0
- package/src/modules/wallets/utils/getChainIdForAccountVerification/getChainIdForAccountVerification.d.ts.map +1 -1
- package/src/modules/wallets/utils/getInjectedProviderFromWindow/getInjectedProviderFromWindow.d.ts +2 -0
- package/src/modules/wallets/utils/getInjectedProviderFromWindow/getInjectedProviderFromWindow.d.ts.map +1 -0
- package/src/modules/wallets/utils/getInjectedProviderFromWindow/index.d.ts +2 -0
- package/src/modules/wallets/utils/getInjectedProviderFromWindow/index.d.ts.map +1 -0
- package/src/modules/wallets/utils/getSignInMessage/createSignInMessageStatement/createSignInMessageStatement.d.ts +3 -0
- package/src/modules/wallets/utils/getSignInMessage/createSignInMessageStatement/createSignInMessageStatement.d.ts.map +1 -0
- package/src/modules/wallets/utils/getSignInMessage/createSignInMessageStatement/index.d.ts +2 -0
- package/src/modules/wallets/utils/getSignInMessage/createSignInMessageStatement/index.d.ts.map +1 -0
- package/src/modules/wallets/utils/getSignInMessage/getSignInMessage.d.ts.map +1 -1
- package/src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.d.ts +8 -0
- package/src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.d.ts.map +1 -0
- package/src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/index.d.ts +2 -0
- package/src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/index.d.ts.map +1 -0
- package/src/modules/wallets/utils/normalizeWalletNameWithChain/index.d.ts +2 -0
- package/src/modules/wallets/utils/normalizeWalletNameWithChain/index.d.ts.map +1 -0
- package/src/modules/wallets/utils/normalizeWalletNameWithChain/normalizeWalletNameWithChain.d.ts +12 -0
- package/src/modules/wallets/utils/normalizeWalletNameWithChain/normalizeWalletNameWithChain.d.ts.map +1 -0
- package/src/modules/wallets/verifySignInMessage/index.d.ts +2 -0
- package/src/modules/wallets/verifySignInMessage/index.d.ts.map +1 -0
- package/src/modules/wallets/verifySignInMessage/verifySignInMessage.d.ts +22 -0
- package/src/modules/wallets/verifySignInMessage/verifySignInMessage.d.ts.map +1 -0
- package/src/modules/wallets/verifyWalletAccount/verifyWalletAccount.d.ts.map +1 -1
- package/src/modules/wallets/walletAccount/index.d.ts +1 -1
- package/src/modules/wallets/walletAccount/index.d.ts.map +1 -1
- package/src/modules/wallets/walletAccount/walletAccount.types.d.ts +8 -0
- package/src/modules/wallets/walletAccount/walletAccount.types.d.ts.map +1 -1
- package/src/modules/wallets/walletProvider/index.d.ts +1 -1
- package/src/modules/wallets/walletProvider/index.d.ts.map +1 -1
- package/src/modules/wallets/walletProvider/splitWalletProviderKey/index.d.ts +2 -0
- package/src/modules/wallets/walletProvider/splitWalletProviderKey/index.d.ts.map +1 -0
- package/src/modules/wallets/walletProvider/splitWalletProviderKey/splitWalletProviderKey.d.ts +9 -0
- package/src/modules/wallets/walletProvider/splitWalletProviderKey/splitWalletProviderKey.d.ts.map +1 -0
- package/src/modules/wallets/walletProvider/walletProvider.types.d.ts +24 -8
- package/src/modules/wallets/walletProvider/walletProvider.types.d.ts.map +1 -1
- package/src/modules/wallets/walletProvider/walletProviderKeyMap/getWalletProviderKeyFromVerifiedCredential/getWalletProviderKeyFromVerifiedCredential.d.ts +10 -0
- package/src/modules/wallets/walletProvider/walletProviderKeyMap/getWalletProviderKeyFromVerifiedCredential/getWalletProviderKeyFromVerifiedCredential.d.ts.map +1 -0
- package/src/modules/wallets/walletProvider/walletProviderKeyMap/getWalletProviderKeyFromVerifiedCredential/index.d.ts +2 -0
- package/src/modules/wallets/walletProvider/walletProviderKeyMap/getWalletProviderKeyFromVerifiedCredential/index.d.ts.map +1 -0
- package/src/modules/wallets/walletProvider/walletProviderKeyMap/schema.d.ts +3 -0
- package/src/modules/wallets/walletProvider/walletProviderKeyMap/schema.d.ts.map +1 -0
- package/src/modules/wallets/walletProvider/walletProviderKeyMap/state.d.ts +16 -0
- package/src/modules/wallets/walletProvider/walletProviderKeyMap/state.d.ts.map +1 -0
- package/src/modules/wallets/walletProvider/walletProviderKeyMap/updateWalletProviderKeysForVerifiedCredentials/index.d.ts +2 -0
- package/src/modules/wallets/walletProvider/walletProviderKeyMap/updateWalletProviderKeysForVerifiedCredentials/index.d.ts.map +1 -0
- package/src/modules/wallets/walletProvider/walletProviderKeyMap/updateWalletProviderKeysForVerifiedCredentials/updateWalletProviderKeysForVerifiedCredentials.d.ts +7 -0
- package/src/modules/wallets/walletProvider/walletProviderKeyMap/updateWalletProviderKeysForVerifiedCredentials/updateWalletProviderKeysForVerifiedCredentials.d.ts.map +1 -0
- package/src/modules/wallets/walletProvider/walletProviderKeyMap/walletProviderKeyMap.types.d.ts +12 -0
- package/src/modules/wallets/walletProvider/walletProviderKeyMap/walletProviderKeyMap.types.d.ts.map +1 -0
- package/src/services/asyncTrack/asyncTrack.types.d.ts +5 -1
- package/src/services/asyncTrack/asyncTrack.types.d.ts.map +1 -1
- package/src/services/asyncTrack/createAsyncTrack.d.ts.map +1 -1
- package/src/services/storage/index.d.ts +1 -1
- package/src/services/storage/index.d.ts.map +1 -1
- package/src/utils/debouncedMutex/createDebouncedMutex/createDebouncedMutex.d.ts +3 -0
- package/src/utils/debouncedMutex/createDebouncedMutex/createDebouncedMutex.d.ts.map +1 -0
- package/src/utils/debouncedMutex/createDebouncedMutex/index.d.ts +2 -0
- package/src/utils/debouncedMutex/createDebouncedMutex/index.d.ts.map +1 -0
- package/src/utils/debouncedMutex/debouncedMutex.types.d.ts +39 -0
- package/src/utils/debouncedMutex/debouncedMutex.types.d.ts.map +1 -0
- package/src/utils/debouncedMutex/index.d.ts +2 -0
- package/src/utils/debouncedMutex/index.d.ts.map +1 -0
- package/waas.cjs.js +86 -38
- package/waas.esm.js +62 -16
- package/waasCore.cjs.js +21 -10
- package/waasCore.esm.js +15 -4
- package/getWalletProviderByKey.cjs.js +0 -74
- package/getWalletProviderByKey.esm.js +0 -69
- package/logout.cjs.js +0 -1086
- package/logout.esm.js +0 -1020
- package/src/modules/apiClient/utils/logoutOnUnauthorizedRequestMiddleware/index.d.ts +0 -2
- package/src/modules/apiClient/utils/logoutOnUnauthorizedRequestMiddleware/index.d.ts.map +0 -1
- package/src/modules/apiClient/utils/logoutOnUnauthorizedRequestMiddleware/logoutOnUnauthorizedRequestMiddleware.d.ts +0 -4
- package/src/modules/apiClient/utils/logoutOnUnauthorizedRequestMiddleware/logoutOnUnauthorizedRequestMiddleware.d.ts.map +0 -1
- package/src/modules/auth/social/oauth/completeSocialRedirectSignIn/completeSocialRedirectSignIn.d.ts.map +0 -1
- package/src/modules/auth/social/oauth/completeSocialRedirectSignIn/index.d.ts +0 -2
- package/src/modules/auth/social/oauth/signInWithSocialRedirect/buildOAuthUrl/addOAuthUrlParams/addOAuthUrlParams.d.ts.map +0 -1
- package/src/modules/auth/social/oauth/signInWithSocialRedirect/buildOAuthUrl/addOAuthUrlParams/index.d.ts.map +0 -1
- package/src/modules/auth/social/oauth/signInWithSocialRedirect/buildOAuthUrl/buildOAuthUrl.d.ts.map +0 -1
- package/src/modules/auth/social/oauth/signInWithSocialRedirect/buildOAuthUrl/getOAuthBaseUrl/getOAuthBaseUrl.d.ts.map +0 -1
- package/src/modules/auth/social/oauth/signInWithSocialRedirect/buildOAuthUrl/getOAuthBaseUrl/index.d.ts.map +0 -1
- package/src/modules/auth/social/oauth/signInWithSocialRedirect/index.d.ts +0 -2
- package/src/modules/auth/social/oauth/signInWithSocialRedirect/signInWithSocialRedirect.d.ts.map +0 -1
- package/src/modules/wallets/utils/createWalletAccountId/createWalletAccountId.d.ts +0 -3
- package/src/modules/wallets/utils/createWalletAccountId/createWalletAccountId.d.ts.map +0 -1
- package/src/modules/wallets/utils/createWalletAccountId/index.d.ts +0 -2
- package/src/modules/wallets/utils/createWalletAccountId/index.d.ts.map +0 -1
- /package/src/modules/auth/social/oauth/{signInWithSocialRedirect → authenticateWithSocial}/buildOAuthUrl/addOAuthUrlParams/addOAuthUrlParams.d.ts +0 -0
- /package/src/modules/auth/social/oauth/{signInWithSocialRedirect → authenticateWithSocial}/buildOAuthUrl/addOAuthUrlParams/index.d.ts +0 -0
- /package/src/modules/auth/social/oauth/{signInWithSocialRedirect → authenticateWithSocial}/buildOAuthUrl/buildOAuthUrl.d.ts +0 -0
- /package/src/modules/auth/social/oauth/{signInWithSocialRedirect → authenticateWithSocial}/buildOAuthUrl/getOAuthBaseUrl/getOAuthBaseUrl.d.ts +0 -0
- /package/src/modules/auth/social/oauth/{signInWithSocialRedirect → authenticateWithSocial}/buildOAuthUrl/getOAuthBaseUrl/index.d.ts +0 -0
- /package/src/modules/auth/social/oauth/{signInWithSocialRedirect → authenticateWithSocial}/buildOAuthUrl/index.d.ts +0 -0
package/logout.cjs.js
DELETED
|
@@ -1,1086 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
4
|
-
var buffer = require('buffer');
|
|
5
|
-
var z = require('zod/mini');
|
|
6
|
-
|
|
7
|
-
function _interopNamespaceDefault(e) {
|
|
8
|
-
var n = Object.create(null);
|
|
9
|
-
if (e) {
|
|
10
|
-
Object.keys(e).forEach(function (k) {
|
|
11
|
-
if (k !== 'default') {
|
|
12
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () { return e[k]; }
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
n.default = e;
|
|
21
|
-
return Object.freeze(n);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
|
|
25
|
-
|
|
26
|
-
var name = "@dynamic-labs-sdk/client";
|
|
27
|
-
var version = "0.1.0-alpha.9";
|
|
28
|
-
var dependencies = {
|
|
29
|
-
"@dynamic-labs/sdk-api-core": "0.0.762"};
|
|
30
|
-
|
|
31
|
-
const getCore = (client)=>{
|
|
32
|
-
// @ts-expect-error - this was hidden from the public API
|
|
33
|
-
return client.__core;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
function _extends() {
|
|
37
|
-
_extends = Object.assign || function assign(target) {
|
|
38
|
-
for(var i = 1; i < arguments.length; i++){
|
|
39
|
-
var source = arguments[i];
|
|
40
|
-
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
41
|
-
}
|
|
42
|
-
return target;
|
|
43
|
-
};
|
|
44
|
-
return _extends.apply(this, arguments);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const getDetails = ({ details, cause })=>{
|
|
48
|
-
if (cause instanceof BaseError) {
|
|
49
|
-
return cause.details;
|
|
50
|
-
}
|
|
51
|
-
if (cause == null ? void 0 : cause.message) {
|
|
52
|
-
return cause.message;
|
|
53
|
-
}
|
|
54
|
-
return details;
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* Formats the error message with all available information
|
|
58
|
-
*/ const formatMessage = ({ shortMessage, details, docsUrl, metaMessages })=>{
|
|
59
|
-
return [
|
|
60
|
-
shortMessage,
|
|
61
|
-
'',
|
|
62
|
-
...metaMessages ? [
|
|
63
|
-
...metaMessages,
|
|
64
|
-
''
|
|
65
|
-
] : [],
|
|
66
|
-
...docsUrl ? [
|
|
67
|
-
`Docs: ${docsUrl}`
|
|
68
|
-
] : [],
|
|
69
|
-
...details ? [
|
|
70
|
-
`Details: ${details}`
|
|
71
|
-
] : [],
|
|
72
|
-
`Version: ${version}`,
|
|
73
|
-
`Timestamp: ${new Date().toISOString()}`
|
|
74
|
-
].join('\n');
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Base error class that provides structured error handling with detailed information
|
|
78
|
-
*/ class BaseError extends Error {
|
|
79
|
-
/**
|
|
80
|
-
* Walks the cause chain of the error and returns the root error
|
|
81
|
-
*/ walk() {
|
|
82
|
-
const cause = this.cause;
|
|
83
|
-
if (cause instanceof BaseError) {
|
|
84
|
-
return cause.walk();
|
|
85
|
-
}
|
|
86
|
-
return cause;
|
|
87
|
-
}
|
|
88
|
-
toString() {
|
|
89
|
-
return this.formattedMessage;
|
|
90
|
-
}
|
|
91
|
-
constructor(args){
|
|
92
|
-
const details = getDetails(args);
|
|
93
|
-
const formattedMessage = formatMessage(_extends({}, args, {
|
|
94
|
-
details
|
|
95
|
-
}));
|
|
96
|
-
var _args_shortMessage;
|
|
97
|
-
super((_args_shortMessage = args.shortMessage) != null ? _args_shortMessage : formattedMessage, args.cause ? {
|
|
98
|
-
cause: args.cause
|
|
99
|
-
} : undefined);
|
|
100
|
-
this.name = 'BaseError';
|
|
101
|
-
this.formattedMessage = formattedMessage;
|
|
102
|
-
this.details = details;
|
|
103
|
-
var _args_name;
|
|
104
|
-
this.name = (_args_name = args.name) != null ? _args_name : this.name;
|
|
105
|
-
var _args_cause;
|
|
106
|
-
this.cause = (_args_cause = args.cause) != null ? _args_cause : this.cause;
|
|
107
|
-
this.code = args.code;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
class ClientNotFoundError extends BaseError {
|
|
112
|
-
constructor(){
|
|
113
|
-
super({
|
|
114
|
-
cause: null,
|
|
115
|
-
code: 'client_not_found_error',
|
|
116
|
-
docsUrl: null,
|
|
117
|
-
name: 'ClientNotFoundError',
|
|
118
|
-
shortMessage: 'No Dynamic client has been created yet. Make sure you have called createDynamicClient() first.'
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
let defaultClient = null;
|
|
124
|
-
let numOfInitializedClients = 0;
|
|
125
|
-
/**
|
|
126
|
-
* Returns the DynamicClient instance that was initialized with createDynamicClient.
|
|
127
|
-
*
|
|
128
|
-
* If more than one instance of DynamicClient was initialized, you should not use this function.
|
|
129
|
-
* Instead, you should pass the client instance you stored to the function that needs it.
|
|
130
|
-
*/ const getDefaultClient = ()=>{
|
|
131
|
-
if (!defaultClient) {
|
|
132
|
-
throw new ClientNotFoundError();
|
|
133
|
-
}
|
|
134
|
-
if (numOfInitializedClients > 1) {
|
|
135
|
-
const core = getCore(defaultClient);
|
|
136
|
-
core.logger.debug('Multiple instances of DynamicClient found. If you are only using one client (recommended), make sure you are not calling ' + '"createDynamicClient" multiple times. If you are using multiple clients, make sure you are passing which client to use as ' + 'the last param of all Dynamic functions.');
|
|
137
|
-
}
|
|
138
|
-
return defaultClient;
|
|
139
|
-
};
|
|
140
|
-
const setDefaultClient = (client)=>{
|
|
141
|
-
defaultClient = client;
|
|
142
|
-
numOfInitializedClients++;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Sefelly sets the cookie in the browser.
|
|
147
|
-
*/ const setCookie = (cookie)=>{
|
|
148
|
-
// eslint-disable-next-line no-restricted-globals
|
|
149
|
-
document.cookie = cookie;
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const DYNAMIC_API_VERSION_HEADER = 'x-dyn-api-version';
|
|
153
|
-
const DYNAMIC_REQUEST_ID_HEADER = 'x-dyn-request-id';
|
|
154
|
-
const DYNAMIC_SDK_VERSION_HEADER = 'x-dyn-version';
|
|
155
|
-
const MFA_TOKEN_HEADER = 'x-mfa-auth-token';
|
|
156
|
-
const SESSION_PUBLIC_KEY_HEADER = 'x-dyn-session-public-key';
|
|
157
|
-
const DYNAMIC_SDK_API_VERSION = dependencies['@dynamic-labs/sdk-api-core'];
|
|
158
|
-
const CLIENT_SDK_NAME = 'ClientSDK';
|
|
159
|
-
|
|
160
|
-
const randomString = (length)=>{
|
|
161
|
-
const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
162
|
-
let result = '';
|
|
163
|
-
for(let i = length; i > 0; --i){
|
|
164
|
-
result += CHARS[Math.floor(Math.random() * CHARS.length)];
|
|
165
|
-
}
|
|
166
|
-
return result;
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
class ValueMustBeDefinedError extends BaseError {
|
|
170
|
-
constructor(message){
|
|
171
|
-
super({
|
|
172
|
-
cause: null,
|
|
173
|
-
code: 'value_must_be_defined_error',
|
|
174
|
-
docsUrl: null,
|
|
175
|
-
name: 'ValueMustBeDefined',
|
|
176
|
-
shortMessage: message
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Asserts that a value is not null or undefined, throwing an error if it is.
|
|
183
|
-
* This function acts as a type guard, narrowing the type to exclude null and undefined.
|
|
184
|
-
*
|
|
185
|
-
* @template T - The type of the value being checked
|
|
186
|
-
* @param value - The value to check for null or undefined
|
|
187
|
-
* @param message - The error message to throw if the value is null or undefined
|
|
188
|
-
* @throws Throws an error with the provided message if value is null or undefined
|
|
189
|
-
* @example
|
|
190
|
-
* ```typescript
|
|
191
|
-
* const maybeString: string | null = getValue();
|
|
192
|
-
* assertDefined(maybeString, 'String value is required');
|
|
193
|
-
* // maybeString is now typed as string (null is excluded)
|
|
194
|
-
* ```
|
|
195
|
-
*/ function assertDefined(value, message) {
|
|
196
|
-
if (value === null || value === undefined) {
|
|
197
|
-
throw new ValueMustBeDefinedError(message);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Returns true if the client is using Dynamic cookies or a BYO JWT cookie.
|
|
203
|
-
*/ const isCookieEnabled = (client)=>{
|
|
204
|
-
var _securitySettings_auth, _securitySettings_externalAuth;
|
|
205
|
-
assertDefined(client.projectSettings, 'Project settings are not defined');
|
|
206
|
-
const securitySettings = client.projectSettings.security;
|
|
207
|
-
if (!securitySettings) return false;
|
|
208
|
-
// client uses Dynamic cookies
|
|
209
|
-
const dynamicCookiesEnabled = (((_securitySettings_auth = securitySettings.auth) == null ? void 0 : _securitySettings_auth.storage) || []).includes(sdkApiCore.AuthStorageEnum.Cookie);
|
|
210
|
-
// BYO JWT client puts their non-Dynamic JWT in a cookie
|
|
211
|
-
const byoJwtCookieEnabled = Boolean((_securitySettings_externalAuth = securitySettings.externalAuth) == null ? void 0 : _securitySettings_externalAuth.cookieName);
|
|
212
|
-
// should return true for both of these scenarios
|
|
213
|
-
// because we also need to do `credentials: true` in api.ts when
|
|
214
|
-
// a byo jwt client sets their named cookie for their jwt and
|
|
215
|
-
// needs to send it to our backend
|
|
216
|
-
return dynamicCookiesEnabled || byoJwtCookieEnabled;
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
const getBuffer = ()=>typeof Buffer !== 'undefined' ? Buffer : buffer.Buffer;
|
|
220
|
-
|
|
221
|
-
const getSessionKeys = (client)=>{
|
|
222
|
-
const core = getCore(client);
|
|
223
|
-
const encodedKeys = core.state.get().sessionKeys;
|
|
224
|
-
if (!encodedKeys) {
|
|
225
|
-
return undefined;
|
|
226
|
-
}
|
|
227
|
-
try {
|
|
228
|
-
const decodedKeys = JSON.parse(getBuffer().from(encodedKeys, 'base64').toString());
|
|
229
|
-
return decodedKeys;
|
|
230
|
-
} catch (error) {
|
|
231
|
-
core.logger.error('Error decoding session keys', error);
|
|
232
|
-
return undefined;
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
class APIError extends BaseError {
|
|
237
|
-
static async fromResponse(response) {
|
|
238
|
-
const errorBody = await response.json();
|
|
239
|
-
if ('code' in errorBody && typeof errorBody.code === 'string' && 'error' in errorBody && typeof errorBody.error === 'string') {
|
|
240
|
-
return new APIError(errorBody.error, errorBody.code);
|
|
241
|
-
}
|
|
242
|
-
return null;
|
|
243
|
-
}
|
|
244
|
-
constructor(message, code){
|
|
245
|
-
super({
|
|
246
|
-
cause: null,
|
|
247
|
-
code,
|
|
248
|
-
docsUrl: null,
|
|
249
|
-
name: 'APIError',
|
|
250
|
-
shortMessage: message
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
class InvalidExternalAuthError extends BaseError {
|
|
256
|
-
constructor({ cause }){
|
|
257
|
-
super({
|
|
258
|
-
cause,
|
|
259
|
-
code: 'invalid_external_auth_error',
|
|
260
|
-
docsUrl: 'https://www.dynamic.xyz/docs/external-auth/third-party-auth-overview',
|
|
261
|
-
name: 'InvalidExternalAuthError',
|
|
262
|
-
shortMessage: 'Error authenticating with external JWT'
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
class MfaInvalidOtpError extends BaseError {
|
|
268
|
-
constructor({ cause }){
|
|
269
|
-
super({
|
|
270
|
-
cause,
|
|
271
|
-
code: 'mfa_invalid_otp_error',
|
|
272
|
-
docsUrl: null,
|
|
273
|
-
name: 'MfaInvalidOtpError',
|
|
274
|
-
shortMessage: 'Invalid OTP'
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
class MfaRateLimitedError extends BaseError {
|
|
280
|
-
constructor({ cause }){
|
|
281
|
-
super({
|
|
282
|
-
cause,
|
|
283
|
-
code: 'mfa_rate_limited_error',
|
|
284
|
-
docsUrl: null,
|
|
285
|
-
name: 'MfaRateLimitedError',
|
|
286
|
-
shortMessage: 'Rate limited'
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
class SandboxMaximumThresholdReachedError extends BaseError {
|
|
292
|
-
constructor({ cause }){
|
|
293
|
-
super({
|
|
294
|
-
cause,
|
|
295
|
-
code: 'sandbox_maximum_threshold_reached_error',
|
|
296
|
-
docsUrl: 'https://www.dynamic.xyz/docs/developer-dashboard/sandbox-vs-live#sandbox-vs-live',
|
|
297
|
-
name: 'SandboxMaximumThresholdReachedError',
|
|
298
|
-
shortMessage: 'Your sandbox environment has reached the maximum MAU. Please use a live environment for production traffic.'
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Default error mapper for the client that handles common API error codes.
|
|
305
|
-
*
|
|
306
|
-
* This mapper transforms specific API error codes into more specific error types:
|
|
307
|
-
* - `mfa_invalid_code` → `MfaInvalidOtpError`
|
|
308
|
-
* - `mfa_rate_limited` → `MfaRateLimitedError`
|
|
309
|
-
*
|
|
310
|
-
* @param error - The error to be mapped
|
|
311
|
-
* @returns A transformed error if the error code matches a known pattern, or null if no transformation is needed
|
|
312
|
-
*
|
|
313
|
-
* @example
|
|
314
|
-
* ```typescript
|
|
315
|
-
* // This will be automatically applied to all API errors
|
|
316
|
-
* const apiClient = createApiClient({}, client);
|
|
317
|
-
*
|
|
318
|
-
* // The clientErrorMapper will automatically convert mfa_invalid_code errors
|
|
319
|
-
* // to MfaInvalidOtpError instances
|
|
320
|
-
* ```
|
|
321
|
-
*/ const clientErrorMapper = (error)=>{
|
|
322
|
-
if (error instanceof APIError) {
|
|
323
|
-
if (error.code === 'mfa_invalid_code') {
|
|
324
|
-
return new MfaInvalidOtpError({
|
|
325
|
-
cause: error
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
if (error.code === 'mfa_rate_limited') {
|
|
329
|
-
return new MfaRateLimitedError({
|
|
330
|
-
cause: error
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
if (error.code === 'invalid_external_auth') {
|
|
334
|
-
return new InvalidExternalAuthError({
|
|
335
|
-
cause: error
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
if (error.code === 'sandbox_maximum_threshold_reached') {
|
|
339
|
-
return new SandboxMaximumThresholdReachedError({
|
|
340
|
-
cause: error
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
return null;
|
|
345
|
-
};
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Creates middleware that converts HTTP error responses to APIError instances
|
|
349
|
-
* and optionally applies custom error mappers to transform them into specific error types.
|
|
350
|
-
*
|
|
351
|
-
* @param options.errorMappers - Array of error mappers to apply to API errors
|
|
352
|
-
* @returns A middleware function that handles error conversion and mapping
|
|
353
|
-
*/ const createConvertToApiErrorMiddleware = ({ errorMappers = [] })=>({
|
|
354
|
-
post: async (context)=>{
|
|
355
|
-
if (context.response.status >= 400) {
|
|
356
|
-
const apiError = await APIError.fromResponse(context.response);
|
|
357
|
-
if (apiError) {
|
|
358
|
-
let errorToThrow = apiError;
|
|
359
|
-
for (const mapper of errorMappers){
|
|
360
|
-
const newError = mapper(apiError);
|
|
361
|
-
if (newError) {
|
|
362
|
-
errorToThrow = newError;
|
|
363
|
-
break;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
throw errorToThrow;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
return context.response;
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
const createLogoutOnUnauthorizedRequestMiddleware = (client)=>({
|
|
374
|
-
post: async (context)=>{
|
|
375
|
-
/**
|
|
376
|
-
* We should logout the user if the request is unauthorized.
|
|
377
|
-
* But we need to ignore the revoke session request to prevent infinite logout loops
|
|
378
|
-
* because the revoke session request will be performed by the logout function below.
|
|
379
|
-
*/ if (context.response.status === 401 && !context.url.endsWith('/revoke')) {
|
|
380
|
-
await logout(client);
|
|
381
|
-
}
|
|
382
|
-
return context.response;
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Returns a new instance of the SDK API client.
|
|
388
|
-
*
|
|
389
|
-
* This is not meant for storing, as it is very light we can create it whenever needed.
|
|
390
|
-
*/ const createApiClient = (options = {}, client)=>{
|
|
391
|
-
var _getSessionKeys;
|
|
392
|
-
const core = getCore(client);
|
|
393
|
-
const coreState = core.state.get();
|
|
394
|
-
const settings = {
|
|
395
|
-
basePath: core.apiBaseUrl,
|
|
396
|
-
headers: _extends({
|
|
397
|
-
'Content-Type': 'application/json',
|
|
398
|
-
[DYNAMIC_API_VERSION_HEADER]: DYNAMIC_SDK_API_VERSION,
|
|
399
|
-
[DYNAMIC_REQUEST_ID_HEADER]: randomString(50),
|
|
400
|
-
[DYNAMIC_SDK_VERSION_HEADER]: `${CLIENT_SDK_NAME}/${version}`
|
|
401
|
-
}, core.getApiHeaders(), options.headers)
|
|
402
|
-
};
|
|
403
|
-
if (client.token) {
|
|
404
|
-
settings.headers.Authorization = `Bearer ${client.token}`;
|
|
405
|
-
}
|
|
406
|
-
if (client.projectSettings && isCookieEnabled(client)) {
|
|
407
|
-
settings.credentials = 'include';
|
|
408
|
-
}
|
|
409
|
-
if (options.includeMfaToken && coreState.mfaToken) {
|
|
410
|
-
settings.headers[MFA_TOKEN_HEADER] = coreState.mfaToken;
|
|
411
|
-
}
|
|
412
|
-
const sessionPublicKey = (_getSessionKeys = getSessionKeys(client)) == null ? void 0 : _getSessionKeys.publicKey;
|
|
413
|
-
// This check is required to avoid overriding the session public key header
|
|
414
|
-
// that is set by any of our other SDKs using the Dynamic Client SDK.
|
|
415
|
-
const isSessionPublicKeyHeaderPresent = settings.headers[SESSION_PUBLIC_KEY_HEADER] !== undefined;
|
|
416
|
-
if (sessionPublicKey && !isSessionPublicKeyHeaderPresent) {
|
|
417
|
-
settings.headers[SESSION_PUBLIC_KEY_HEADER] = sessionPublicKey;
|
|
418
|
-
}
|
|
419
|
-
return new sdkApiCore.SDKApi(new sdkApiCore.Configuration(_extends({}, settings, {
|
|
420
|
-
fetchApi: core.fetch,
|
|
421
|
-
middleware: [
|
|
422
|
-
createLogoutOnUnauthorizedRequestMiddleware(client),
|
|
423
|
-
createConvertToApiErrorMiddleware({
|
|
424
|
-
errorMappers: [
|
|
425
|
-
...options.errorMappers || [],
|
|
426
|
-
clientErrorMapper
|
|
427
|
-
]
|
|
428
|
-
})
|
|
429
|
-
]
|
|
430
|
-
})));
|
|
431
|
-
};
|
|
432
|
-
|
|
433
|
-
/**
|
|
434
|
-
* Adds an event listener for Dynamic client events.
|
|
435
|
-
*
|
|
436
|
-
* This function allows you to listen for various events emitted by the Dynamic client,
|
|
437
|
-
* such as authentication state changes, wallet connections, and more.
|
|
438
|
-
*
|
|
439
|
-
* @param params.event - The event name to listen for.
|
|
440
|
-
* @param params.listener - The callback function to execute when the event is fired.
|
|
441
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
442
|
-
* @returns A function that can be called to remove the listener.
|
|
443
|
-
*/ const onEvent = ({ event, listener }, client = getDefaultClient())=>{
|
|
444
|
-
const { eventEmitter } = getCore(client);
|
|
445
|
-
eventEmitter.on(event, listener);
|
|
446
|
-
return ()=>{
|
|
447
|
-
eventEmitter.off(event, listener);
|
|
448
|
-
};
|
|
449
|
-
};
|
|
450
|
-
/**
|
|
451
|
-
* Removes an event listener from Dynamic client events.
|
|
452
|
-
*
|
|
453
|
-
* This function unsubscribes a previously registered event listener
|
|
454
|
-
* from the specified Dynamic client event.
|
|
455
|
-
*
|
|
456
|
-
* @param params.event - The event name to remove the listener from.
|
|
457
|
-
* @param params.listener - The callback function to remove.
|
|
458
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
459
|
-
*/ const offEvent = ({ event, listener }, client = getDefaultClient())=>{
|
|
460
|
-
const { eventEmitter } = getCore(client);
|
|
461
|
-
eventEmitter.off(event, listener);
|
|
462
|
-
};
|
|
463
|
-
/**
|
|
464
|
-
* Adds a one-time event listener for Dynamic client events.
|
|
465
|
-
*
|
|
466
|
-
* This function listens for an event that will automatically remove itself
|
|
467
|
-
* after being triggered once.
|
|
468
|
-
*
|
|
469
|
-
* @param params.event - The event name to listen for.
|
|
470
|
-
* @param params.listener - The callback function to execute when the event is fired.
|
|
471
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
472
|
-
* @returns A function that can be called to remove the listener before it fires.
|
|
473
|
-
*/ const onceEvent = ({ event, listener }, client = getDefaultClient())=>{
|
|
474
|
-
const { eventEmitter } = getCore(client);
|
|
475
|
-
eventEmitter.once(event, listener);
|
|
476
|
-
return ()=>{
|
|
477
|
-
eventEmitter.off(event, listener);
|
|
478
|
-
};
|
|
479
|
-
};
|
|
480
|
-
/**
|
|
481
|
-
* Emits a Dynamic client event.
|
|
482
|
-
*
|
|
483
|
-
* This function triggers an event that will be received by all registered
|
|
484
|
-
* listeners for the specified event type.
|
|
485
|
-
*
|
|
486
|
-
* @param params.event - The event name to emit.
|
|
487
|
-
* @param params.args - The arguments to pass to event listeners.
|
|
488
|
-
* @param client - The Dynamic client instance.
|
|
489
|
-
*/ const emitEvent = ({ event, args }, client)=>{
|
|
490
|
-
const { eventEmitter } = getCore(client);
|
|
491
|
-
eventEmitter.emit(event, args);
|
|
492
|
-
};
|
|
493
|
-
|
|
494
|
-
/**
|
|
495
|
-
* This error is thrown when the `retryOnFail` function is called with an invalid
|
|
496
|
-
* number of retries (i.e. less than 0).
|
|
497
|
-
*/ class InvalidRetryOnFailCallError extends BaseError {
|
|
498
|
-
constructor(maxRetries){
|
|
499
|
-
super({
|
|
500
|
-
cause: null,
|
|
501
|
-
code: 'invalid_retry_on_fail_call_error',
|
|
502
|
-
docsUrl: null,
|
|
503
|
-
name: 'InvalidRetryOnFailCallError',
|
|
504
|
-
shortMessage: `Invalid retries parameter for retryOnFail call: ${maxRetries}`
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
const retryOnFail = async ({ delay = 0, fn, maxRetries })=>{
|
|
510
|
-
for(let retry = 0; retry <= maxRetries; retry++){
|
|
511
|
-
try {
|
|
512
|
-
return await fn();
|
|
513
|
-
} catch (error) {
|
|
514
|
-
if (retry >= maxRetries) {
|
|
515
|
-
throw error;
|
|
516
|
-
}
|
|
517
|
-
if (delay > 0) {
|
|
518
|
-
await new Promise((resolve)=>setTimeout(resolve, delay));
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* Reaching this point should never happen and this
|
|
524
|
-
* error is thrown to help us debug the issue.
|
|
525
|
-
*/ throw new InvalidRetryOnFailCallError(maxRetries);
|
|
526
|
-
};
|
|
527
|
-
|
|
528
|
-
const normalizeAddress = (address, chain)=>{
|
|
529
|
-
let normalizedAddress = address;
|
|
530
|
-
if (normalizedAddress == null ? void 0 : normalizedAddress.startsWith('0x')) {
|
|
531
|
-
normalizedAddress = normalizedAddress.slice(2);
|
|
532
|
-
}
|
|
533
|
-
/**
|
|
534
|
-
* These are standard from CAIP-2: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md
|
|
535
|
-
* see also: https://github.com/ChainAgnostic/namespaces
|
|
536
|
-
* note: no standard namespace currently exists for flow
|
|
537
|
-
*/ const chainsThatRequireLowercaseAddress = [
|
|
538
|
-
'EVM',
|
|
539
|
-
'FLOW'
|
|
540
|
-
];
|
|
541
|
-
normalizedAddress = chainsThatRequireLowercaseAddress.includes(chain) ? normalizedAddress == null ? void 0 : normalizedAddress.toLowerCase() : normalizedAddress;
|
|
542
|
-
return normalizedAddress;
|
|
543
|
-
};
|
|
544
|
-
|
|
545
|
-
const createWalletAccountId = (chain, address)=>`${chain}-${normalizeAddress(address, chain)}`;
|
|
546
|
-
|
|
547
|
-
const convertUnverifiedWalletAccountToWalletAccount = (unverifiedWalletAccount)=>({
|
|
548
|
-
address: unverifiedWalletAccount.address,
|
|
549
|
-
chain: unverifiedWalletAccount.chain,
|
|
550
|
-
id: createWalletAccountId(unverifiedWalletAccount.chain, unverifiedWalletAccount.address),
|
|
551
|
-
lastSelectedAt: unverifiedWalletAccount.lastSelectedAt,
|
|
552
|
-
verifiedCredentialId: null,
|
|
553
|
-
walletProviderKey: unverifiedWalletAccount.walletProviderKey
|
|
554
|
-
});
|
|
555
|
-
|
|
556
|
-
const CHAINS_INFO_MAP = {
|
|
557
|
-
ALGO: {
|
|
558
|
-
apiChainName: 'algo',
|
|
559
|
-
blockchainName: 'Algorand',
|
|
560
|
-
verifiedCredentialChainName: 'algorand'
|
|
561
|
-
},
|
|
562
|
-
BTC: {
|
|
563
|
-
apiChainName: 'btc',
|
|
564
|
-
blockchainName: 'Bitcoin',
|
|
565
|
-
verifiedCredentialChainName: 'bip122'
|
|
566
|
-
},
|
|
567
|
-
COSMOS: {
|
|
568
|
-
apiChainName: 'cosmos',
|
|
569
|
-
blockchainName: 'Cosmos',
|
|
570
|
-
verifiedCredentialChainName: 'cosmos'
|
|
571
|
-
},
|
|
572
|
-
EVM: {
|
|
573
|
-
apiChainName: 'evm',
|
|
574
|
-
// eslint-disable-next-line custom-rules/ban-ethereum-eth-terms
|
|
575
|
-
blockchainName: 'Ethereum',
|
|
576
|
-
verifiedCredentialChainName: 'eip155'
|
|
577
|
-
},
|
|
578
|
-
FLOW: {
|
|
579
|
-
apiChainName: 'flow',
|
|
580
|
-
blockchainName: 'Flow',
|
|
581
|
-
verifiedCredentialChainName: 'flow'
|
|
582
|
-
},
|
|
583
|
-
SOL: {
|
|
584
|
-
apiChainName: 'solana',
|
|
585
|
-
blockchainName: 'Solana',
|
|
586
|
-
verifiedCredentialChainName: 'solana',
|
|
587
|
-
waasChainNameOverride: 'SVM'
|
|
588
|
-
},
|
|
589
|
-
SPARK: {
|
|
590
|
-
apiChainName: 'spark',
|
|
591
|
-
blockchainName: 'Spark',
|
|
592
|
-
verifiedCredentialChainName: 'spark'
|
|
593
|
-
},
|
|
594
|
-
STARK: {
|
|
595
|
-
apiChainName: 'starknet',
|
|
596
|
-
blockchainName: 'Starknet',
|
|
597
|
-
verifiedCredentialChainName: 'starknet'
|
|
598
|
-
},
|
|
599
|
-
SUI: {
|
|
600
|
-
apiChainName: 'sui',
|
|
601
|
-
blockchainName: 'Sui',
|
|
602
|
-
verifiedCredentialChainName: 'sui'
|
|
603
|
-
}
|
|
604
|
-
};
|
|
605
|
-
|
|
606
|
-
const getChainFromVerifiedCredentialChain = (verifiedCredentialChain)=>{
|
|
607
|
-
const chains = Object.keys(CHAINS_INFO_MAP);
|
|
608
|
-
const chain = chains.find((chain)=>CHAINS_INFO_MAP[chain].verifiedCredentialChainName === verifiedCredentialChain);
|
|
609
|
-
assertDefined(chain, `Unknown chain: ${verifiedCredentialChain}`);
|
|
610
|
-
return chain;
|
|
611
|
-
};
|
|
612
|
-
|
|
613
|
-
/**
|
|
614
|
-
* Format the wallet name and chain to get a wallet provider key.
|
|
615
|
-
*/ const formatWalletProviderKey = (walletName, chain)=>{
|
|
616
|
-
const sanitizedWalletName = walletName.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
|
|
617
|
-
return `${sanitizedWalletName}${chain.toLocaleLowerCase()}`;
|
|
618
|
-
};
|
|
619
|
-
|
|
620
|
-
const convertVerifiedCredentialToWalletAccount = (verified)=>{
|
|
621
|
-
assertDefined(verified.address, 'Missing address in verified credential');
|
|
622
|
-
assertDefined(verified.chain, 'Missing chain in verified credential');
|
|
623
|
-
assertDefined(verified.walletName, 'Missing wallet name in verified credential');
|
|
624
|
-
const chain = getChainFromVerifiedCredentialChain(verified.chain);
|
|
625
|
-
const hasChainInWalletName = verified.walletName.endsWith(chain.toLowerCase());
|
|
626
|
-
// we need to make sure the walletProviderKey follows the correct format ([walletName][chain])
|
|
627
|
-
// some walletNames will follow the legacy format (e.g. "phantom" instead of "phantomsol", "metamask" instead of "metamaskevm")
|
|
628
|
-
// so we need to make sure we parse it correctly
|
|
629
|
-
const walletProviderKey = hasChainInWalletName ? verified.walletName : formatWalletProviderKey(verified.walletName, chain);
|
|
630
|
-
var _verified_lastSelectedAt;
|
|
631
|
-
return {
|
|
632
|
-
address: verified.address,
|
|
633
|
-
chain,
|
|
634
|
-
id: createWalletAccountId(chain, verified.address),
|
|
635
|
-
lastSelectedAt: (_verified_lastSelectedAt = verified.lastSelectedAt) != null ? _verified_lastSelectedAt : null,
|
|
636
|
-
verifiedCredentialId: verified.id,
|
|
637
|
-
walletProviderKey
|
|
638
|
-
};
|
|
639
|
-
};
|
|
640
|
-
|
|
641
|
-
const getWalletAccountsFromState = (state)=>{
|
|
642
|
-
const { unverifiedWalletAccounts, user } = state;
|
|
643
|
-
const walletAccountsMap = new Map();
|
|
644
|
-
/**
|
|
645
|
-
* Handle the unverified wallet accounts before the user verified credentials
|
|
646
|
-
* so the later verified wallet accounts can override the unverified wallet accounts
|
|
647
|
-
*/ unverifiedWalletAccounts.forEach((unverifiedWalletAccount)=>{
|
|
648
|
-
const walletAccount = convertUnverifiedWalletAccountToWalletAccount(unverifiedWalletAccount);
|
|
649
|
-
walletAccountsMap.set(walletAccount.id, walletAccount);
|
|
650
|
-
});
|
|
651
|
-
var _user_verifiedCredentials;
|
|
652
|
-
/**
|
|
653
|
-
* Handle user verified credentials
|
|
654
|
-
*/ const verifiedCredentials = (_user_verifiedCredentials = user == null ? void 0 : user.verifiedCredentials) != null ? _user_verifiedCredentials : [];
|
|
655
|
-
verifiedCredentials.filter((verified)=>verified.format === sdkApiCore.JwtVerifiedCredentialFormatEnum.Blockchain).map((verifiedWalletAccount)=>convertVerifiedCredentialToWalletAccount(verifiedWalletAccount)).forEach((verifiedWalletAccount)=>walletAccountsMap.set(verifiedWalletAccount.id, verifiedWalletAccount));
|
|
656
|
-
return Array.from(walletAccountsMap.values());
|
|
657
|
-
};
|
|
658
|
-
|
|
659
|
-
/**
|
|
660
|
-
* Retrieves all wallet accounts associated with the current session.
|
|
661
|
-
*
|
|
662
|
-
* This function returns both verified and unverified wallet accounts,
|
|
663
|
-
* combining data from user credentials and local unverified accounts.
|
|
664
|
-
* You can differentiate between verified and unverified wallet accounts by
|
|
665
|
-
* checking the `verifiedCredentialId` property.
|
|
666
|
-
*
|
|
667
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
668
|
-
* @returns An array of wallet accounts associated with the session.
|
|
669
|
-
*/ const getWalletAccounts = (client = getDefaultClient())=>getWalletAccountsFromState(getCore(client).state.get());
|
|
670
|
-
|
|
671
|
-
/**
|
|
672
|
-
* Checks if the user is currently signed in to the Dynamic client.
|
|
673
|
-
*
|
|
674
|
-
* The client is considered to be in a signed in state if a user has
|
|
675
|
-
* authenticated or if the client has at least one wallet connected.
|
|
676
|
-
*
|
|
677
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
678
|
-
* @returns True if the user is signed in, false otherwise.
|
|
679
|
-
*/ const isSignedIn = (client = getDefaultClient())=>Boolean(client.user || getWalletAccounts(client).length > 0);
|
|
680
|
-
|
|
681
|
-
const createStorageKeySchema = (params)=>{
|
|
682
|
-
return params;
|
|
683
|
-
};
|
|
684
|
-
|
|
685
|
-
/**
|
|
686
|
-
* The schema to track the expiration time of the project settings.
|
|
687
|
-
*/ const projectSettingsExpirationScheme = createStorageKeySchema({
|
|
688
|
-
key: 'projectSettingsExpiration',
|
|
689
|
-
schema: z__namespace.number()
|
|
690
|
-
});
|
|
691
|
-
|
|
692
|
-
/**
|
|
693
|
-
* Expiration time of the project settings in milliseconds.
|
|
694
|
-
*/ const PROJECT_SETTINGS_EXPIRATION_TIME = 1000 * 60 * 5; // 5 minutes
|
|
695
|
-
/**
|
|
696
|
-
* Fetches and updates the project settings from the API.
|
|
697
|
-
*
|
|
698
|
-
* This function retrieves the latest project configuration settings
|
|
699
|
-
* from Dynamic's servers, including authentication options, enabled chains,
|
|
700
|
-
* and security configurations. The settings are cached for performance.
|
|
701
|
-
*
|
|
702
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
703
|
-
* @returns A promise that resolves to the updated project settings.
|
|
704
|
-
*/ const fetchProjectSettings = async (client = getDefaultClient())=>{
|
|
705
|
-
const core = getCore(client);
|
|
706
|
-
const currentExpiration = await core.storage.getItem(projectSettingsExpirationScheme);
|
|
707
|
-
const hasProjectSettings = Boolean(client.projectSettings);
|
|
708
|
-
const isExpired = currentExpiration && currentExpiration < Date.now();
|
|
709
|
-
// We want to cache the project settings if its valid and user is connected.
|
|
710
|
-
// This avoids unnecessary API calls and speeds up the initial load.
|
|
711
|
-
if (hasProjectSettings && !isExpired && isSignedIn(client)) {
|
|
712
|
-
return client.projectSettings;
|
|
713
|
-
}
|
|
714
|
-
const apiClient = createApiClient({}, client);
|
|
715
|
-
const doFetch = async ()=>apiClient.getEnvironmentSettings({
|
|
716
|
-
environmentId: core.environmentId,
|
|
717
|
-
sdkVersion: `${CLIENT_SDK_NAME}/${core.version}`
|
|
718
|
-
}, {
|
|
719
|
-
credentials: 'omit'
|
|
720
|
-
});
|
|
721
|
-
const projectSettings = await retryOnFail({
|
|
722
|
-
fn: doFetch,
|
|
723
|
-
maxRetries: 2
|
|
724
|
-
});
|
|
725
|
-
core.state.set({
|
|
726
|
-
projectSettings: projectSettings != null ? projectSettings : null
|
|
727
|
-
});
|
|
728
|
-
await core.storage.setItem(projectSettingsExpirationScheme, Date.now() + PROJECT_SETTINGS_EXPIRATION_TIME);
|
|
729
|
-
return projectSettings;
|
|
730
|
-
};
|
|
731
|
-
|
|
732
|
-
/**
|
|
733
|
-
* Takes a base64url-encoded string (e.g. "nMueRPiAm51YXEjRtka8S_8Ura3HaqbmqDqMJCZmvkM")
|
|
734
|
-
* and return the corresponding bytes, as an array buffer.
|
|
735
|
-
*/ const base64UrlDecode = (s)=>{
|
|
736
|
-
// Go from base64url encoding to base64 encoding
|
|
737
|
-
s = (s == null ? void 0 : s.replace(/-/g, '+').replace(/_/g, '/')) || '';
|
|
738
|
-
// use `atob` to decode base64
|
|
739
|
-
return Uint8Array.from(atob(s), (c)=>c.charCodeAt(0));
|
|
740
|
-
};
|
|
741
|
-
|
|
742
|
-
/**
|
|
743
|
-
* Converts an ArrayBuffer to a hex-encoded string
|
|
744
|
-
*/ const bufferToHex = (buffer)=>[
|
|
745
|
-
...new Uint8Array(buffer)
|
|
746
|
-
].map((x)=>x.toString(16).padStart(2, '0')).join('');
|
|
747
|
-
|
|
748
|
-
/**
|
|
749
|
-
* Accepts a public key array buffer, and returns a buffer with the compressed version of the public key
|
|
750
|
-
*/ const compressRawPublicKey = (rawPublicKey)=>{
|
|
751
|
-
const rawPublicKeyBytes = new Uint8Array(rawPublicKey);
|
|
752
|
-
const len = rawPublicKeyBytes.byteLength;
|
|
753
|
-
// Drop the y coordinate
|
|
754
|
-
const compressedBytes = rawPublicKeyBytes.slice(0, 1 + len >>> 1);
|
|
755
|
-
// Encode the parity of `y` in first bit
|
|
756
|
-
compressedBytes[0] = 0x2 | rawPublicKeyBytes[len - 1] & 0x01;
|
|
757
|
-
return compressedBytes.buffer;
|
|
758
|
-
};
|
|
759
|
-
|
|
760
|
-
const p256Keygen = async ()=>{
|
|
761
|
-
// Create a new P-256 keypair
|
|
762
|
-
const p256Keypair = await crypto.subtle.generateKey({
|
|
763
|
-
name: 'ECDSA',
|
|
764
|
-
namedCurve: 'P-256'
|
|
765
|
-
}, true, [
|
|
766
|
-
'sign',
|
|
767
|
-
'verify'
|
|
768
|
-
]);
|
|
769
|
-
// Export the raw public key. By default this will export in uncompressed format
|
|
770
|
-
const rawPublicKey = await crypto.subtle.exportKey('raw', p256Keypair.publicKey);
|
|
771
|
-
// We need to export with JWK format because exporting EC private keys with "raw" isn't supported
|
|
772
|
-
const privateKeyJwk = await crypto.subtle.exportKey('jwk', p256Keypair.privateKey);
|
|
773
|
-
const compressedPublicKeyBuffer = compressRawPublicKey(rawPublicKey);
|
|
774
|
-
const privateKeyBuffer = base64UrlDecode(privateKeyJwk.d);
|
|
775
|
-
return {
|
|
776
|
-
private: bufferToHex(privateKeyBuffer),
|
|
777
|
-
privateJwk: privateKeyJwk,
|
|
778
|
-
public: bufferToHex(compressedPublicKeyBuffer)
|
|
779
|
-
};
|
|
780
|
-
};
|
|
781
|
-
|
|
782
|
-
const generateSessionKeys = async (client)=>{
|
|
783
|
-
const { private: privateKey, public: publicKey, privateJwk: privateKeyJwk } = await p256Keygen();
|
|
784
|
-
const core = getCore(client);
|
|
785
|
-
// stringify and encode the session keys to store in storage
|
|
786
|
-
const stringifiedSessionKeys = JSON.stringify({
|
|
787
|
-
privateKey,
|
|
788
|
-
privateKeyJwk,
|
|
789
|
-
publicKey,
|
|
790
|
-
registered: false
|
|
791
|
-
});
|
|
792
|
-
const encodedSessionKeys = getBuffer().from(stringifiedSessionKeys).toString('base64');
|
|
793
|
-
core.state.set({
|
|
794
|
-
sessionKeys: encodedSessionKeys
|
|
795
|
-
});
|
|
796
|
-
return {
|
|
797
|
-
privateKey,
|
|
798
|
-
privateKeyJwk,
|
|
799
|
-
publicKey
|
|
800
|
-
};
|
|
801
|
-
};
|
|
802
|
-
|
|
803
|
-
class NoWalletProviderFoundError extends BaseError {
|
|
804
|
-
constructor({ walletProviderKey }){
|
|
805
|
-
super({
|
|
806
|
-
cause: null,
|
|
807
|
-
code: 'no_wallet_provider_found_error',
|
|
808
|
-
docsUrl: null,
|
|
809
|
-
name: 'NoWalletProviderFoundError',
|
|
810
|
-
shortMessage: `No wallet provider found with key: ${walletProviderKey}`
|
|
811
|
-
});
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
/**
|
|
816
|
-
* Creates a service accessor function that manages service instantiation and caching.
|
|
817
|
-
* The returned function will either retrieve an existing service from the registry or
|
|
818
|
-
* create a new one using the provided builder function.
|
|
819
|
-
*
|
|
820
|
-
* @template - The type of service to be created/accessed
|
|
821
|
-
* @param key - Unique identifier for the service in the registry
|
|
822
|
-
* @param builder - Function that creates the service instance when called with a DynamicClient
|
|
823
|
-
*/ const createRuntimeServiceAccessKey = (key, builder)=>(client)=>{
|
|
824
|
-
const { runtimeServices } = getCore(client);
|
|
825
|
-
const currentService = runtimeServices.getByKey(key);
|
|
826
|
-
if (currentService) {
|
|
827
|
-
return currentService;
|
|
828
|
-
}
|
|
829
|
-
const service = builder(client);
|
|
830
|
-
runtimeServices.register(key, service);
|
|
831
|
-
return service;
|
|
832
|
-
};
|
|
833
|
-
|
|
834
|
-
/**
|
|
835
|
-
* Creates a new wallet provider registry that manages wallet providers with priority-based registration.
|
|
836
|
-
*
|
|
837
|
-
* @returns The wallet provider registry instance
|
|
838
|
-
*
|
|
839
|
-
* @example
|
|
840
|
-
* ```typescript
|
|
841
|
-
* const registry = createWalletProviderRegistry();
|
|
842
|
-
*
|
|
843
|
-
* registry.register({
|
|
844
|
-
* priority: WalletProviderPriority.WALLET_SDK,
|
|
845
|
-
* walletProvider: myWalletProvider
|
|
846
|
-
* });
|
|
847
|
-
*
|
|
848
|
-
* const provider = registry.getByKey('my-wallet-key');
|
|
849
|
-
* const providers = registry.listProviders();
|
|
850
|
-
* ```
|
|
851
|
-
*/ const createWalletProviderRegistry = (client)=>{
|
|
852
|
-
const registry = new Map();
|
|
853
|
-
return {
|
|
854
|
-
getByKey: (key)=>{
|
|
855
|
-
var _registry_get;
|
|
856
|
-
return (_registry_get = registry.get(key)) == null ? void 0 : _registry_get.walletProvider;
|
|
857
|
-
},
|
|
858
|
-
listProviders: ()=>Array.from(registry.values()).map((v)=>v.walletProvider),
|
|
859
|
-
register: (args)=>{
|
|
860
|
-
const existingEntry = registry.get(args.walletProvider.key);
|
|
861
|
-
if (existingEntry) {
|
|
862
|
-
if (existingEntry.priority < args.priority) {
|
|
863
|
-
registry.set(args.walletProvider.key, args);
|
|
864
|
-
emitEvent({
|
|
865
|
-
args: {
|
|
866
|
-
walletProviderKey: args.walletProvider.key
|
|
867
|
-
},
|
|
868
|
-
event: 'walletProviderChanged'
|
|
869
|
-
}, client);
|
|
870
|
-
}
|
|
871
|
-
} else {
|
|
872
|
-
registry.set(args.walletProvider.key, args);
|
|
873
|
-
emitEvent({
|
|
874
|
-
args: {
|
|
875
|
-
walletProvider: args.walletProvider
|
|
876
|
-
},
|
|
877
|
-
event: 'walletProviderRegistered'
|
|
878
|
-
}, client);
|
|
879
|
-
emitEvent({
|
|
880
|
-
args: {
|
|
881
|
-
walletProviderKey: args.walletProvider.key
|
|
882
|
-
},
|
|
883
|
-
event: 'walletProviderChanged'
|
|
884
|
-
}, client);
|
|
885
|
-
}
|
|
886
|
-
},
|
|
887
|
-
unregister: (key)=>{
|
|
888
|
-
registry.delete(key);
|
|
889
|
-
emitEvent({
|
|
890
|
-
args: {
|
|
891
|
-
walletProviderKey: key
|
|
892
|
-
},
|
|
893
|
-
event: 'walletProviderUnregistered'
|
|
894
|
-
}, client);
|
|
895
|
-
}
|
|
896
|
-
};
|
|
897
|
-
};
|
|
898
|
-
|
|
899
|
-
/**
|
|
900
|
-
* This function provides access to a shared instance of the wallet provider registry.
|
|
901
|
-
*
|
|
902
|
-
* It ensures that the same registry instance is used throughout the client to maintaining
|
|
903
|
-
* consistency of registered wallet providers across different parts of the codebase.
|
|
904
|
-
*
|
|
905
|
-
* @returns The wallet provider registry instance
|
|
906
|
-
*
|
|
907
|
-
* @example
|
|
908
|
-
* ```typescript
|
|
909
|
-
* // Get the registry instance
|
|
910
|
-
* const registry = getWalletProviderRegistry();
|
|
911
|
-
*
|
|
912
|
-
* // Register a wallet provider
|
|
913
|
-
* registry.register({
|
|
914
|
-
* priority: WalletProviderPriority.WALLET_SDK,
|
|
915
|
-
* walletProvider: myWalletProvider
|
|
916
|
-
* });
|
|
917
|
-
*
|
|
918
|
-
* // Retrieve a specific provider
|
|
919
|
-
* const provider = registry.getByKey('metamaskevm');
|
|
920
|
-
* ```
|
|
921
|
-
*/ const getWalletProviderRegistry = createRuntimeServiceAccessKey('walletProviderRegistry', (client)=>createWalletProviderRegistry(client));
|
|
922
|
-
|
|
923
|
-
exports.WalletProviderPriority = void 0;
|
|
924
|
-
(function(WalletProviderPriority) {
|
|
925
|
-
/**
|
|
926
|
-
* Highest priority should be used by wallet providers that implement
|
|
927
|
-
* the most reliable wallet integration.
|
|
928
|
-
* example: The SDK provided by the wallet provider.
|
|
929
|
-
*/ WalletProviderPriority[WalletProviderPriority["WALLET_SDK"] = 100] = "WALLET_SDK";
|
|
930
|
-
/**
|
|
931
|
-
* Medium priority should be used by wallet providers that implement
|
|
932
|
-
* a wallet integration via some reliable standard.
|
|
933
|
-
* example: A wallet provider that uses EIP6963 announcement.
|
|
934
|
-
*/ WalletProviderPriority[WalletProviderPriority["WALLET_SELF_ANNOUNCEMENT_STANDARD"] = 50] = "WALLET_SELF_ANNOUNCEMENT_STANDARD";
|
|
935
|
-
/**
|
|
936
|
-
* Low priority should be used by wallet providers that implement
|
|
937
|
-
* a wallet integration on a less reliable standard.
|
|
938
|
-
* example: A wallet provider that uses window.ethereum, where the
|
|
939
|
-
* window key can be overridden by other extensions.
|
|
940
|
-
*/ WalletProviderPriority[WalletProviderPriority["WINDOW_INJECT"] = 20] = "WINDOW_INJECT";
|
|
941
|
-
})(exports.WalletProviderPriority || (exports.WalletProviderPriority = {}));
|
|
942
|
-
|
|
943
|
-
const getWalletProviderFromWalletAccount = ({ walletAccount }, client)=>{
|
|
944
|
-
const walletProviderRegistry = getWalletProviderRegistry(client);
|
|
945
|
-
const walletProvider = walletProviderRegistry.getByKey(walletAccount.walletProviderKey);
|
|
946
|
-
if (!walletProvider) {
|
|
947
|
-
throw new NoWalletProviderFoundError({
|
|
948
|
-
walletProviderKey: walletAccount.walletProviderKey
|
|
949
|
-
});
|
|
950
|
-
}
|
|
951
|
-
return walletProvider;
|
|
952
|
-
};
|
|
953
|
-
|
|
954
|
-
const getAvailableWalletProvidersFromWalletAccounts = (client)=>{
|
|
955
|
-
const core = getCore(client);
|
|
956
|
-
const walletProvidersMap = new Map();
|
|
957
|
-
const walletAccounts = getWalletAccounts(client);
|
|
958
|
-
walletAccounts.forEach((walletAccount)=>{
|
|
959
|
-
if (walletProvidersMap.has(walletAccount.walletProviderKey)) {
|
|
960
|
-
return;
|
|
961
|
-
}
|
|
962
|
-
try {
|
|
963
|
-
const walletProvider = getWalletProviderFromWalletAccount({
|
|
964
|
-
walletAccount
|
|
965
|
-
}, client);
|
|
966
|
-
walletProvidersMap.set(walletAccount.walletProviderKey, walletProvider);
|
|
967
|
-
} catch (error) {
|
|
968
|
-
core.logger.debug('Wallet provider not found for wallet account', {
|
|
969
|
-
error,
|
|
970
|
-
walletAccount: walletAccount.address
|
|
971
|
-
});
|
|
972
|
-
}
|
|
973
|
-
});
|
|
974
|
-
return Array.from(walletProvidersMap.values());
|
|
975
|
-
};
|
|
976
|
-
|
|
977
|
-
/**
|
|
978
|
-
* Disconnect and terminate each wallet provider, if available.
|
|
979
|
-
*/ const disconnectAndTerminateWalletProviders = async (client)=>{
|
|
980
|
-
const core = getCore(client);
|
|
981
|
-
const walletProviders = getAvailableWalletProvidersFromWalletAccounts(client);
|
|
982
|
-
await Promise.all(walletProviders.map(async (walletProvider)=>{
|
|
983
|
-
if (walletProvider.terminate) {
|
|
984
|
-
await walletProvider.terminate();
|
|
985
|
-
}
|
|
986
|
-
if (walletProvider.disconnect) {
|
|
987
|
-
try {
|
|
988
|
-
await walletProvider.disconnect();
|
|
989
|
-
} catch (err) {
|
|
990
|
-
core.logger.error(`Error disconnecting from wallet ${walletProvider.key}`, err);
|
|
991
|
-
}
|
|
992
|
-
}
|
|
993
|
-
}));
|
|
994
|
-
};
|
|
995
|
-
|
|
996
|
-
const DYNAMIC_AUTH_COOKIE_NAME = 'DYNAMIC_JWT_TOKEN';
|
|
997
|
-
|
|
998
|
-
/**
|
|
999
|
-
* Logs out the current user and clears all authentication data.
|
|
1000
|
-
*
|
|
1001
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1002
|
-
* @returns A promise that resolves when the logout process is complete.
|
|
1003
|
-
*/ const logout = async (client = getDefaultClient())=>{
|
|
1004
|
-
const core = getCore(client);
|
|
1005
|
-
await disconnectAndTerminateWalletProviders(client);
|
|
1006
|
-
if (client.user !== null) {
|
|
1007
|
-
const apiClient = createApiClient({}, client);
|
|
1008
|
-
try {
|
|
1009
|
-
await apiClient.revokeSession({
|
|
1010
|
-
environmentId: core.environmentId
|
|
1011
|
-
});
|
|
1012
|
-
} catch (error) {
|
|
1013
|
-
core.logger.error('Failed to revoke session', error);
|
|
1014
|
-
}
|
|
1015
|
-
/**
|
|
1016
|
-
* This deletes the auth cookie if it exists.
|
|
1017
|
-
* If the cookie doesn't exist, this sets a new cookie that expires immediately.
|
|
1018
|
-
*/ if (isCookieEnabled(client)) {
|
|
1019
|
-
setCookie(`${DYNAMIC_AUTH_COOKIE_NAME}=; Max-Age=-99999999; path=/; SameSite=Lax`);
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
1022
|
-
core.state.set({
|
|
1023
|
-
captchaToken: null,
|
|
1024
|
-
legacyToken: null,
|
|
1025
|
-
mfaToken: null,
|
|
1026
|
-
sessionExpiresAt: null,
|
|
1027
|
-
sessionKeys: null,
|
|
1028
|
-
token: null,
|
|
1029
|
-
unverifiedWalletAccounts: [],
|
|
1030
|
-
user: null
|
|
1031
|
-
});
|
|
1032
|
-
emitEvent({
|
|
1033
|
-
event: 'logout'
|
|
1034
|
-
}, client);
|
|
1035
|
-
// Refetch project settings
|
|
1036
|
-
void fetchProjectSettings(client);
|
|
1037
|
-
// Regenerate session keys
|
|
1038
|
-
void generateSessionKeys(client);
|
|
1039
|
-
};
|
|
1040
|
-
|
|
1041
|
-
exports.APIError = APIError;
|
|
1042
|
-
exports.BaseError = BaseError;
|
|
1043
|
-
exports.CHAINS_INFO_MAP = CHAINS_INFO_MAP;
|
|
1044
|
-
exports.CLIENT_SDK_NAME = CLIENT_SDK_NAME;
|
|
1045
|
-
exports.ClientNotFoundError = ClientNotFoundError;
|
|
1046
|
-
exports.DYNAMIC_AUTH_COOKIE_NAME = DYNAMIC_AUTH_COOKIE_NAME;
|
|
1047
|
-
exports.DYNAMIC_SDK_API_VERSION = DYNAMIC_SDK_API_VERSION;
|
|
1048
|
-
exports.InvalidExternalAuthError = InvalidExternalAuthError;
|
|
1049
|
-
exports.MfaInvalidOtpError = MfaInvalidOtpError;
|
|
1050
|
-
exports.MfaRateLimitedError = MfaRateLimitedError;
|
|
1051
|
-
exports.NoWalletProviderFoundError = NoWalletProviderFoundError;
|
|
1052
|
-
exports.SandboxMaximumThresholdReachedError = SandboxMaximumThresholdReachedError;
|
|
1053
|
-
exports.ValueMustBeDefinedError = ValueMustBeDefinedError;
|
|
1054
|
-
exports._extends = _extends;
|
|
1055
|
-
exports.assertDefined = assertDefined;
|
|
1056
|
-
exports.bufferToHex = bufferToHex;
|
|
1057
|
-
exports.createApiClient = createApiClient;
|
|
1058
|
-
exports.createRuntimeServiceAccessKey = createRuntimeServiceAccessKey;
|
|
1059
|
-
exports.createStorageKeySchema = createStorageKeySchema;
|
|
1060
|
-
exports.createWalletAccountId = createWalletAccountId;
|
|
1061
|
-
exports.dependencies = dependencies;
|
|
1062
|
-
exports.emitEvent = emitEvent;
|
|
1063
|
-
exports.fetchProjectSettings = fetchProjectSettings;
|
|
1064
|
-
exports.formatWalletProviderKey = formatWalletProviderKey;
|
|
1065
|
-
exports.generateSessionKeys = generateSessionKeys;
|
|
1066
|
-
exports.getBuffer = getBuffer;
|
|
1067
|
-
exports.getChainFromVerifiedCredentialChain = getChainFromVerifiedCredentialChain;
|
|
1068
|
-
exports.getCore = getCore;
|
|
1069
|
-
exports.getDefaultClient = getDefaultClient;
|
|
1070
|
-
exports.getSessionKeys = getSessionKeys;
|
|
1071
|
-
exports.getWalletAccounts = getWalletAccounts;
|
|
1072
|
-
exports.getWalletAccountsFromState = getWalletAccountsFromState;
|
|
1073
|
-
exports.getWalletProviderFromWalletAccount = getWalletProviderFromWalletAccount;
|
|
1074
|
-
exports.getWalletProviderRegistry = getWalletProviderRegistry;
|
|
1075
|
-
exports.isCookieEnabled = isCookieEnabled;
|
|
1076
|
-
exports.isSignedIn = isSignedIn;
|
|
1077
|
-
exports.logout = logout;
|
|
1078
|
-
exports.name = name;
|
|
1079
|
-
exports.normalizeAddress = normalizeAddress;
|
|
1080
|
-
exports.offEvent = offEvent;
|
|
1081
|
-
exports.onEvent = onEvent;
|
|
1082
|
-
exports.onceEvent = onceEvent;
|
|
1083
|
-
exports.randomString = randomString;
|
|
1084
|
-
exports.setCookie = setCookie;
|
|
1085
|
-
exports.setDefaultClient = setDefaultClient;
|
|
1086
|
-
exports.version = version;
|