@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/index.cjs.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var assertPackageVersion = require('@dynamic-labs-sdk/assert-package-version');
|
|
4
|
-
var
|
|
4
|
+
var constants = require('./constants.cjs.js');
|
|
5
5
|
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
6
6
|
var getNetworkProviderFromNetworkId = require('./getNetworkProviderFromNetworkId.cjs.js');
|
|
7
|
+
var getVerifiedCredentialForWalletAccount = require('./getVerifiedCredentialForWalletAccount.cjs.js');
|
|
7
8
|
var z = require('zod/mini');
|
|
9
|
+
var isMfaRequiredForAction = require('./isMfaRequiredForAction.cjs.js');
|
|
8
10
|
var NotWaasWalletAccountError = require('./NotWaasWalletAccountError.cjs.js');
|
|
9
11
|
var EventEmitter = require('eventemitter3');
|
|
10
12
|
var browser = require('@simplewebauthn/browser');
|
|
11
13
|
var InvalidParamError = require('./InvalidParamError.cjs.js');
|
|
12
|
-
var getWalletProviderByKey = require('./getWalletProviderByKey.cjs.js');
|
|
13
|
-
var isMfaRequiredForAction = require('./isMfaRequiredForAction.cjs.js');
|
|
14
14
|
require('buffer');
|
|
15
15
|
|
|
16
16
|
function _interopNamespaceDefault(e) {
|
|
@@ -46,6 +46,163 @@ var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
|
|
|
46
46
|
user: 'userChanged'
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* This error is thrown when the `retryOnFail` function is called with an invalid
|
|
51
|
+
* number of retries (i.e. less than 0).
|
|
52
|
+
*/ class InvalidRetryOnFailCallError extends constants.BaseError {
|
|
53
|
+
constructor(maxRetries){
|
|
54
|
+
super({
|
|
55
|
+
cause: null,
|
|
56
|
+
code: 'invalid_retry_on_fail_call_error',
|
|
57
|
+
docsUrl: null,
|
|
58
|
+
name: 'InvalidRetryOnFailCallError',
|
|
59
|
+
shortMessage: `Invalid retries parameter for retryOnFail call: ${maxRetries}`
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const retryOnFail = async ({ delay = 0, fn, maxRetries })=>{
|
|
65
|
+
for(let retry = 0; retry <= maxRetries; retry++){
|
|
66
|
+
try {
|
|
67
|
+
return await fn();
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (retry >= maxRetries) {
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
if (delay > 0) {
|
|
73
|
+
await new Promise((resolve)=>setTimeout(resolve, delay));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Reaching this point should never happen and this
|
|
79
|
+
* error is thrown to help us debug the issue.
|
|
80
|
+
*/ throw new InvalidRetryOnFailCallError(maxRetries);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Checks if the user is currently signed in to the Dynamic client.
|
|
85
|
+
*
|
|
86
|
+
* The client is considered to be in a signed in state if a user has
|
|
87
|
+
* authenticated or if the client has at least one wallet connected.
|
|
88
|
+
*
|
|
89
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
90
|
+
* @returns True if the user is signed in, false otherwise.
|
|
91
|
+
*/ const isSignedIn = (client = constants.getDefaultClient())=>Boolean(client.user || getVerifiedCredentialForWalletAccount.getWalletAccounts(client).length > 0);
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The schema to track the expiration time of the project settings.
|
|
95
|
+
*/ const projectSettingsExpirationStorageKeySchema = getNetworkProviderFromNetworkId.createStorageKeySchema({
|
|
96
|
+
key: 'projectSettingsExpiration',
|
|
97
|
+
schema: z__namespace.number()
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Expiration time of the project settings in milliseconds.
|
|
102
|
+
*/ const PROJECT_SETTINGS_EXPIRATION_TIME = 1000 * 60 * 5; // 5 minutes
|
|
103
|
+
/**
|
|
104
|
+
* Fetches and updates the project settings from the API.
|
|
105
|
+
*
|
|
106
|
+
* This function retrieves the latest project configuration settings
|
|
107
|
+
* from Dynamic's servers, including authentication options, enabled chains,
|
|
108
|
+
* and security configurations. The settings are cached for performance.
|
|
109
|
+
*
|
|
110
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
111
|
+
* @returns A promise that resolves to the updated project settings.
|
|
112
|
+
*/ const fetchProjectSettings = async (client = constants.getDefaultClient())=>{
|
|
113
|
+
const core = constants.getCore(client);
|
|
114
|
+
const currentExpiration = await core.storage.getItem(projectSettingsExpirationStorageKeySchema);
|
|
115
|
+
const hasProjectSettings = Boolean(client.projectSettings);
|
|
116
|
+
const isExpired = currentExpiration && currentExpiration < Date.now();
|
|
117
|
+
// We want to cache the project settings if its valid and user is connected.
|
|
118
|
+
// This avoids unnecessary API calls and speeds up the initial load.
|
|
119
|
+
if (hasProjectSettings && !isExpired && isSignedIn(client)) {
|
|
120
|
+
return client.projectSettings;
|
|
121
|
+
}
|
|
122
|
+
const apiClient = constants.createApiClient({}, client);
|
|
123
|
+
core.logger.debug('[fetchProjectSettings] Fetching project settings...');
|
|
124
|
+
const doFetch = async ()=>apiClient.getEnvironmentSettings({
|
|
125
|
+
environmentId: core.environmentId,
|
|
126
|
+
sdkVersion: `${constants.CLIENT_SDK_NAME}/${core.version}`
|
|
127
|
+
}, {
|
|
128
|
+
credentials: 'omit'
|
|
129
|
+
});
|
|
130
|
+
const projectSettings = await retryOnFail({
|
|
131
|
+
fn: doFetch,
|
|
132
|
+
maxRetries: 2
|
|
133
|
+
});
|
|
134
|
+
core.state.set({
|
|
135
|
+
projectSettings: projectSettings != null ? projectSettings : null
|
|
136
|
+
});
|
|
137
|
+
await core.storage.setItem(projectSettingsExpirationStorageKeySchema, Date.now() + PROJECT_SETTINGS_EXPIRATION_TIME);
|
|
138
|
+
return projectSettings;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Takes a base64url-encoded string (e.g. "nMueRPiAm51YXEjRtka8S_8Ura3HaqbmqDqMJCZmvkM")
|
|
143
|
+
* and return the corresponding bytes, as an array buffer.
|
|
144
|
+
*/ const base64UrlDecode = (s)=>{
|
|
145
|
+
// Go from base64url encoding to base64 encoding
|
|
146
|
+
s = (s == null ? void 0 : s.replace(/-/g, '+').replace(/_/g, '/')) || '';
|
|
147
|
+
// use `atob` to decode base64
|
|
148
|
+
return Uint8Array.from(atob(s), (c)=>c.charCodeAt(0));
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Accepts a public key array buffer, and returns a buffer with the compressed version of the public key
|
|
153
|
+
*/ const compressRawPublicKey = (rawPublicKey)=>{
|
|
154
|
+
const rawPublicKeyBytes = new Uint8Array(rawPublicKey);
|
|
155
|
+
const len = rawPublicKeyBytes.byteLength;
|
|
156
|
+
// Drop the y coordinate
|
|
157
|
+
const compressedBytes = rawPublicKeyBytes.slice(0, 1 + len >>> 1);
|
|
158
|
+
// Encode the parity of `y` in first bit
|
|
159
|
+
compressedBytes[0] = 0x2 | rawPublicKeyBytes[len - 1] & 0x01;
|
|
160
|
+
return compressedBytes.buffer;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const p256Keygen = async ()=>{
|
|
164
|
+
// Create a new P-256 keypair
|
|
165
|
+
const p256Keypair = await crypto.subtle.generateKey({
|
|
166
|
+
name: 'ECDSA',
|
|
167
|
+
namedCurve: 'P-256'
|
|
168
|
+
}, true, [
|
|
169
|
+
'sign',
|
|
170
|
+
'verify'
|
|
171
|
+
]);
|
|
172
|
+
// Export the raw public key. By default this will export in uncompressed format
|
|
173
|
+
const rawPublicKey = await crypto.subtle.exportKey('raw', p256Keypair.publicKey);
|
|
174
|
+
// We need to export with JWK format because exporting EC private keys with "raw" isn't supported
|
|
175
|
+
const privateKeyJwk = await crypto.subtle.exportKey('jwk', p256Keypair.privateKey);
|
|
176
|
+
const compressedPublicKeyBuffer = compressRawPublicKey(rawPublicKey);
|
|
177
|
+
const privateKeyBuffer = base64UrlDecode(privateKeyJwk.d);
|
|
178
|
+
return {
|
|
179
|
+
private: isMfaRequiredForAction.bufferToHex(privateKeyBuffer),
|
|
180
|
+
privateJwk: privateKeyJwk,
|
|
181
|
+
public: isMfaRequiredForAction.bufferToHex(compressedPublicKeyBuffer)
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const generateSessionKeys = async (client)=>{
|
|
186
|
+
const { private: privateKey, public: publicKey, privateJwk: privateKeyJwk } = await p256Keygen();
|
|
187
|
+
const core = constants.getCore(client);
|
|
188
|
+
// stringify and encode the session keys to store in storage
|
|
189
|
+
const stringifiedSessionKeys = JSON.stringify({
|
|
190
|
+
privateKey,
|
|
191
|
+
privateKeyJwk,
|
|
192
|
+
publicKey,
|
|
193
|
+
registered: false
|
|
194
|
+
});
|
|
195
|
+
const encodedSessionKeys = constants.getBuffer().from(stringifiedSessionKeys).toString('base64');
|
|
196
|
+
core.state.set({
|
|
197
|
+
sessionKeys: encodedSessionKeys
|
|
198
|
+
});
|
|
199
|
+
return {
|
|
200
|
+
privateKey,
|
|
201
|
+
privateKeyJwk,
|
|
202
|
+
publicKey
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
|
|
49
206
|
/**
|
|
50
207
|
* Creates a new runtime services instance that manages service registration and retrieval.
|
|
51
208
|
*
|
|
@@ -59,6 +216,92 @@ var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
|
|
|
59
216
|
};
|
|
60
217
|
};
|
|
61
218
|
|
|
219
|
+
const getAvailableWalletProvidersFromWalletAccounts = (client)=>{
|
|
220
|
+
const core = constants.getCore(client);
|
|
221
|
+
const walletProvidersMap = new Map();
|
|
222
|
+
const walletAccounts = getVerifiedCredentialForWalletAccount.getWalletAccounts(client);
|
|
223
|
+
walletAccounts.forEach((walletAccount)=>{
|
|
224
|
+
if (walletProvidersMap.has(walletAccount.walletProviderKey)) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
try {
|
|
228
|
+
const walletProvider = getVerifiedCredentialForWalletAccount.getWalletProviderFromWalletAccount({
|
|
229
|
+
walletAccount
|
|
230
|
+
}, client);
|
|
231
|
+
walletProvidersMap.set(walletAccount.walletProviderKey, walletProvider);
|
|
232
|
+
} catch (error) {
|
|
233
|
+
core.logger.debug('Wallet provider not found for wallet account', {
|
|
234
|
+
error,
|
|
235
|
+
walletAccount: walletAccount.address
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
return Array.from(walletProvidersMap.values());
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Disconnect and terminate each wallet provider, if available.
|
|
244
|
+
*/ const disconnectAndTerminateWalletProviders = async (client)=>{
|
|
245
|
+
const core = constants.getCore(client);
|
|
246
|
+
const walletProviders = getAvailableWalletProvidersFromWalletAccounts(client);
|
|
247
|
+
await Promise.all(walletProviders.map(async (walletProvider)=>{
|
|
248
|
+
if (walletProvider.terminate) {
|
|
249
|
+
await walletProvider.terminate();
|
|
250
|
+
}
|
|
251
|
+
if (walletProvider.disconnect) {
|
|
252
|
+
try {
|
|
253
|
+
await walletProvider.disconnect();
|
|
254
|
+
} catch (err) {
|
|
255
|
+
core.logger.error(`Error disconnecting from wallet ${walletProvider.key}`, err);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}));
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Logs out the current user and clears all authentication data.
|
|
263
|
+
*
|
|
264
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
265
|
+
* @returns A promise that resolves when the logout process is complete.
|
|
266
|
+
*/ const logout = async (client = constants.getDefaultClient())=>{
|
|
267
|
+
const core = constants.getCore(client);
|
|
268
|
+
core.logger.debug('[logout] Logging out...');
|
|
269
|
+
await disconnectAndTerminateWalletProviders(client);
|
|
270
|
+
if (client.user !== null) {
|
|
271
|
+
const apiClient = constants.createApiClient({}, client);
|
|
272
|
+
try {
|
|
273
|
+
await apiClient.revokeSession({
|
|
274
|
+
environmentId: core.environmentId
|
|
275
|
+
});
|
|
276
|
+
} catch (error) {
|
|
277
|
+
core.logger.error('Failed to revoke session', error);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* This deletes the auth cookie if it exists.
|
|
281
|
+
* If the cookie doesn't exist, this sets a new cookie that expires immediately.
|
|
282
|
+
*/ if (constants.isCookieEnabled(client)) {
|
|
283
|
+
getVerifiedCredentialForWalletAccount.setCookie(`${getVerifiedCredentialForWalletAccount.DYNAMIC_AUTH_COOKIE_NAME}=; Max-Age=-99999999; path=/; SameSite=Lax`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
core.state.set({
|
|
287
|
+
captchaToken: null,
|
|
288
|
+
legacyToken: null,
|
|
289
|
+
mfaToken: null,
|
|
290
|
+
sessionExpiresAt: null,
|
|
291
|
+
sessionKeys: null,
|
|
292
|
+
token: null,
|
|
293
|
+
unverifiedWalletAccounts: [],
|
|
294
|
+
user: null
|
|
295
|
+
});
|
|
296
|
+
getVerifiedCredentialForWalletAccount.emitEvent({
|
|
297
|
+
event: 'logout'
|
|
298
|
+
}, client);
|
|
299
|
+
// Refetch project settings
|
|
300
|
+
void fetchProjectSettings(client);
|
|
301
|
+
// Regenerate session keys
|
|
302
|
+
void generateSessionKeys(client);
|
|
303
|
+
};
|
|
304
|
+
|
|
62
305
|
/**
|
|
63
306
|
* A replacement for setTimeout that supports delays longer than 2147483647ms (~24.8 days).
|
|
64
307
|
*/ const setLongTimeout = (callback, delay)=>{
|
|
@@ -87,7 +330,7 @@ var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
|
|
|
87
330
|
/**
|
|
88
331
|
* Sets up a timeout to log out the user when their token expires.
|
|
89
332
|
*/ const initializeAuth = (client)=>{
|
|
90
|
-
const core =
|
|
333
|
+
const core = constants.getCore(client);
|
|
91
334
|
let clearExpirationTimeout = null;
|
|
92
335
|
const onChangeExpiration = getNetworkProviderFromNetworkId.subscribeWithSelector(core.state, (state)=>state.sessionExpiresAt);
|
|
93
336
|
const checkExpiration = ()=>{
|
|
@@ -99,7 +342,7 @@ var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
|
|
|
99
342
|
const now = new Date();
|
|
100
343
|
const timeUntilExpiration = expiration.getTime() - now.getTime();
|
|
101
344
|
if (timeUntilExpiration <= 0) {
|
|
102
|
-
void logout
|
|
345
|
+
void logout(client);
|
|
103
346
|
return;
|
|
104
347
|
}
|
|
105
348
|
// Wait for token expiration
|
|
@@ -110,13 +353,13 @@ var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
|
|
|
110
353
|
};
|
|
111
354
|
|
|
112
355
|
const raiseStateEvents = (client)=>{
|
|
113
|
-
const core =
|
|
356
|
+
const core = constants.getCore(client);
|
|
114
357
|
core.state.subscribe((value, previous)=>{
|
|
115
358
|
const eventEntries = Object.entries(stateChangeEvents);
|
|
116
359
|
eventEntries.forEach(([key, event])=>{
|
|
117
360
|
// Check if this key had a change
|
|
118
361
|
if (getNetworkProviderFromNetworkId.isEqualShallow(value[key], previous[key])) return;
|
|
119
|
-
|
|
362
|
+
getVerifiedCredentialForWalletAccount.emitEvent({
|
|
120
363
|
args: {
|
|
121
364
|
[key]: value[key]
|
|
122
365
|
},
|
|
@@ -126,17 +369,32 @@ const raiseStateEvents = (client)=>{
|
|
|
126
369
|
});
|
|
127
370
|
};
|
|
128
371
|
|
|
129
|
-
const
|
|
372
|
+
const unverifiedWalletAccountSchema = z__namespace.object({
|
|
373
|
+
address: z__namespace.string(),
|
|
374
|
+
addressesWithTypes: z__namespace.optional(z__namespace.array(z__namespace.object({
|
|
375
|
+
address: z__namespace.string(),
|
|
376
|
+
publicKey: z__namespace.optional(z__namespace.string()),
|
|
377
|
+
type: z__namespace.custom((val)=>typeof val === 'string')
|
|
378
|
+
}))),
|
|
379
|
+
chain: z__namespace.custom((val)=>typeof val === 'string'),
|
|
380
|
+
id: z__namespace.string(),
|
|
381
|
+
lastSelectedAt: z__namespace.nullable(z__namespace.date()),
|
|
382
|
+
walletProviderKey: z__namespace.string()
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
const walletProviderKeyMapSchema = z__namespace.record(z__namespace.string(), z__namespace.string());
|
|
130
386
|
|
|
131
|
-
const stateStorageKeySchema =
|
|
387
|
+
const stateStorageKeySchema = getNetworkProviderFromNetworkId.createStorageKeySchema({
|
|
132
388
|
key: 'state',
|
|
133
389
|
schema: z__namespace.object({
|
|
134
390
|
apiVersion: z__namespace.string(),
|
|
135
391
|
projectSettings: z__namespace.custom(),
|
|
136
|
-
|
|
392
|
+
unverifiedWalletAccounts: z__namespace.array(unverifiedWalletAccountSchema),
|
|
393
|
+
user: z__namespace.custom(),
|
|
394
|
+
walletProviderKeyMap: walletProviderKeyMapSchema
|
|
137
395
|
})
|
|
138
396
|
});
|
|
139
|
-
const
|
|
397
|
+
const sessionStorageKeySchema = getNetworkProviderFromNetworkId.createStorageKeySchema({
|
|
140
398
|
key: 'session',
|
|
141
399
|
schema: z__namespace.object({
|
|
142
400
|
/**
|
|
@@ -163,10 +421,11 @@ const sessionKeySchema = logout.createStorageKeySchema({
|
|
|
163
421
|
});
|
|
164
422
|
|
|
165
423
|
const hydrateStateWithStorage = async (client)=>{
|
|
166
|
-
const core =
|
|
424
|
+
const core = constants.getCore(client);
|
|
425
|
+
const previousState = core.state.get();
|
|
167
426
|
const stateChanges = {};
|
|
168
427
|
// ================ TOKEN =================
|
|
169
|
-
const session = await core.storage.getItem(
|
|
428
|
+
const session = await core.storage.getItem(sessionStorageKeySchema);
|
|
170
429
|
const isSessionValid = (session == null ? void 0 : session.sessionExpiration) && session.sessionExpiration > Date.now();
|
|
171
430
|
if (isSessionValid) {
|
|
172
431
|
stateChanges.token = session.token;
|
|
@@ -179,25 +438,35 @@ const hydrateStateWithStorage = async (client)=>{
|
|
|
179
438
|
// ================ STATE =================
|
|
180
439
|
const storedState = await core.storage.getItem(stateStorageKeySchema);
|
|
181
440
|
// Only hydrate state if it came from an API with the same version as the current SDK
|
|
182
|
-
if ((storedState == null ? void 0 : storedState.apiVersion) === SDK_API_CORE_VERSION) {
|
|
441
|
+
if ((storedState == null ? void 0 : storedState.apiVersion) === constants.SDK_API_CORE_VERSION) {
|
|
442
|
+
stateChanges.unverifiedWalletAccounts = storedState.unverifiedWalletAccounts;
|
|
443
|
+
stateChanges.walletProviderKeyMap = storedState.walletProviderKeyMap;
|
|
183
444
|
// Variables that should only be hydrated if the session is valid
|
|
184
445
|
if (isSessionValid) {
|
|
185
446
|
stateChanges.user = storedState.user;
|
|
447
|
+
}
|
|
448
|
+
var _storedState_unverifiedWalletAccounts;
|
|
449
|
+
// if there's a session/user or connected unverified wallets, we should hydrate project settings
|
|
450
|
+
// so we don't refetch it on initial load
|
|
451
|
+
if (isSessionValid || ((_storedState_unverifiedWalletAccounts = storedState.unverifiedWalletAccounts) != null ? _storedState_unverifiedWalletAccounts : []).length > 0) {
|
|
186
452
|
stateChanges.projectSettings = storedState.projectSettings;
|
|
187
453
|
}
|
|
188
454
|
}
|
|
189
455
|
if (Object.keys(stateChanges).length > 0) {
|
|
190
456
|
core.state.set(stateChanges);
|
|
191
457
|
}
|
|
458
|
+
getVerifiedCredentialForWalletAccount.checkAndRaiseWalletAccountsChangedEvent({
|
|
459
|
+
previousState
|
|
460
|
+
}, client);
|
|
192
461
|
};
|
|
193
462
|
|
|
194
463
|
const syncStateWithStorage = (client)=>{
|
|
195
|
-
const core =
|
|
464
|
+
const core = constants.getCore(client);
|
|
196
465
|
core.state.subscribe((state)=>{
|
|
197
466
|
if (state.sessionExpiresAt === null) {
|
|
198
|
-
void core.storage.removeItem(
|
|
467
|
+
void core.storage.removeItem(sessionStorageKeySchema);
|
|
199
468
|
} else {
|
|
200
|
-
void core.storage.setItem(
|
|
469
|
+
void core.storage.setItem(sessionStorageKeySchema, {
|
|
201
470
|
captchaToken: state.captchaToken,
|
|
202
471
|
legacyToken: state.legacyToken,
|
|
203
472
|
mfaToken: state.mfaToken,
|
|
@@ -207,9 +476,11 @@ const syncStateWithStorage = (client)=>{
|
|
|
207
476
|
});
|
|
208
477
|
}
|
|
209
478
|
void core.storage.setItem(stateStorageKeySchema, {
|
|
210
|
-
apiVersion: SDK_API_CORE_VERSION,
|
|
479
|
+
apiVersion: constants.SDK_API_CORE_VERSION,
|
|
211
480
|
projectSettings: state.projectSettings,
|
|
212
|
-
|
|
481
|
+
unverifiedWalletAccounts: state.unverifiedWalletAccounts,
|
|
482
|
+
user: state.user,
|
|
483
|
+
walletProviderKeyMap: state.walletProviderKeyMap
|
|
213
484
|
});
|
|
214
485
|
});
|
|
215
486
|
};
|
|
@@ -221,7 +492,7 @@ const initializeStorageSync = async (client)=>{
|
|
|
221
492
|
syncStateWithStorage(client);
|
|
222
493
|
};
|
|
223
494
|
|
|
224
|
-
class ClientAlreadyInitializedError extends
|
|
495
|
+
class ClientAlreadyInitializedError extends constants.BaseError {
|
|
225
496
|
constructor(){
|
|
226
497
|
super({
|
|
227
498
|
cause: null,
|
|
@@ -245,8 +516,9 @@ class ClientAlreadyInitializedError extends logout.BaseError {
|
|
|
245
516
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
246
517
|
* @returns A promise that resolves when initialization is complete.
|
|
247
518
|
* @throws ClientAlreadyInitializedError If the client is already initialized.
|
|
248
|
-
*/ const initializeClient = async (client =
|
|
249
|
-
const core =
|
|
519
|
+
*/ const initializeClient = async (client = constants.getDefaultClient())=>{
|
|
520
|
+
const core = constants.getCore(client);
|
|
521
|
+
core.logger.debug('[initializeClient] Initializing client. Current init status', core.state.get().initStatus);
|
|
250
522
|
if (core.state.get().initStatus !== 'uninitialized') {
|
|
251
523
|
throw new ClientAlreadyInitializedError();
|
|
252
524
|
}
|
|
@@ -258,14 +530,14 @@ class ClientAlreadyInitializedError extends logout.BaseError {
|
|
|
258
530
|
const initializeStorageSyncPromise = initializeStorageSync(client);
|
|
259
531
|
const fetchProjectSettingsPromise = initializeStorageSyncPromise.then(async ()=>{
|
|
260
532
|
if (!core.state.get().projectSettings) {
|
|
261
|
-
await
|
|
533
|
+
await fetchProjectSettings(client);
|
|
262
534
|
}
|
|
263
535
|
});
|
|
264
536
|
/**
|
|
265
537
|
* Generate session keys if they don't exist
|
|
266
538
|
*/ const generateSessionKeysPromise = fetchProjectSettingsPromise.then(async ()=>{
|
|
267
539
|
if (!core.state.get().sessionKeys) {
|
|
268
|
-
await
|
|
540
|
+
await generateSessionKeys(client);
|
|
269
541
|
}
|
|
270
542
|
});
|
|
271
543
|
/**
|
|
@@ -280,24 +552,38 @@ class ClientAlreadyInitializedError extends logout.BaseError {
|
|
|
280
552
|
* sub2.example.com that had the original logged-in user. We need to fetch the user to refresh
|
|
281
553
|
* the user state with the correct logged-in user.
|
|
282
554
|
*/ const refreshUserStateFromCookiePromise = fetchProjectSettingsPromise.then(async ()=>{
|
|
283
|
-
|
|
284
|
-
|
|
555
|
+
/**
|
|
556
|
+
* When cookies are enabled, we need to refresh the user as part of the initialization process
|
|
557
|
+
* to ensure the user is logged in and sync the auth state with the server.
|
|
558
|
+
*
|
|
559
|
+
* This call can fail with a 401 error if the user is not logged in and the SDK should finish its initialization process
|
|
560
|
+
* without throwing an error because that is an expected behavior.
|
|
561
|
+
*/ if (constants.isCookieEnabled(client)) {
|
|
562
|
+
await NotWaasWalletAccountError.refreshUser(client).catch(async (error)=>{
|
|
563
|
+
if (error.status === 401) {
|
|
564
|
+
if (client.user) {
|
|
565
|
+
await logout(client);
|
|
566
|
+
}
|
|
567
|
+
} else {
|
|
568
|
+
throw error;
|
|
569
|
+
}
|
|
570
|
+
});
|
|
285
571
|
}
|
|
286
572
|
});
|
|
287
573
|
core.initTrack.track({
|
|
288
|
-
name:
|
|
574
|
+
name: getNetworkProviderFromNetworkId.INITIALIZE_STORAGE_SYNC_TRACKER_KEY,
|
|
289
575
|
promise: initializeStorageSyncPromise
|
|
290
576
|
});
|
|
291
577
|
core.initTrack.track({
|
|
292
|
-
name:
|
|
578
|
+
name: getNetworkProviderFromNetworkId.FETCH_PROJECT_SETTINGS_TRACKER_KEY,
|
|
293
579
|
promise: fetchProjectSettingsPromise
|
|
294
580
|
});
|
|
295
581
|
core.initTrack.track({
|
|
296
|
-
name:
|
|
582
|
+
name: getNetworkProviderFromNetworkId.GENERATE_SESSION_KEYS_TRACKER_KEY,
|
|
297
583
|
promise: generateSessionKeysPromise
|
|
298
584
|
});
|
|
299
585
|
core.initTrack.track({
|
|
300
|
-
name:
|
|
586
|
+
name: getNetworkProviderFromNetworkId.REFRESH_USER_STATE_FROM_COOKIE_TRACKER_KEY,
|
|
301
587
|
promise: refreshUserStateFromCookiePromise
|
|
302
588
|
});
|
|
303
589
|
try {
|
|
@@ -347,7 +633,7 @@ const createDeferredPromise = ()=>{
|
|
|
347
633
|
/**
|
|
348
634
|
* Checks if all processes are initialized and resolves the main promise if they are.
|
|
349
635
|
*/ const checkIfAllSettled = ()=>{
|
|
350
|
-
const allSettled = Array.from(tracker.values()).every((status)=>status === 'resolved');
|
|
636
|
+
const allSettled = Array.from(tracker.values()).every(({ status })=>status === 'resolved');
|
|
351
637
|
if (!allSettled) return;
|
|
352
638
|
allSettledPromise.resolve();
|
|
353
639
|
};
|
|
@@ -357,19 +643,28 @@ const createDeferredPromise = ()=>{
|
|
|
357
643
|
}
|
|
358
644
|
// Disable tracking in the next node tick
|
|
359
645
|
void Promise.resolve().then(()=>isTrackEnabled = false);
|
|
360
|
-
tracker.set(name,
|
|
646
|
+
tracker.set(name, {
|
|
647
|
+
promise,
|
|
648
|
+
status: 'pending'
|
|
649
|
+
});
|
|
361
650
|
promise.then(()=>{
|
|
362
|
-
tracker.set(name,
|
|
651
|
+
tracker.set(name, {
|
|
652
|
+
promise,
|
|
653
|
+
status: 'resolved'
|
|
654
|
+
});
|
|
363
655
|
eventEmitter.emit('resolved', name);
|
|
364
656
|
checkIfAllSettled();
|
|
365
657
|
}).catch((error)=>{
|
|
366
|
-
tracker.set(name,
|
|
658
|
+
tracker.set(name, {
|
|
659
|
+
promise,
|
|
660
|
+
status: 'failed'
|
|
661
|
+
});
|
|
367
662
|
eventEmitter.emit('failed', name, error);
|
|
368
663
|
allSettledPromise.reject(error);
|
|
369
664
|
});
|
|
370
665
|
};
|
|
371
666
|
const waitForAll = ()=>allSettledPromise.promise;
|
|
372
|
-
const getTracker = ()=>tracker;
|
|
667
|
+
const getTracker = (trackerKey)=>tracker.get(trackerKey);
|
|
373
668
|
return {
|
|
374
669
|
getTracker,
|
|
375
670
|
off: eventEmitter.off.bind(eventEmitter),
|
|
@@ -381,7 +676,7 @@ const createDeferredPromise = ()=>{
|
|
|
381
676
|
|
|
382
677
|
const createEventEmitter = ()=>new EventEmitter();
|
|
383
678
|
|
|
384
|
-
class UnavailableInServerSideError extends
|
|
679
|
+
class UnavailableInServerSideError extends constants.BaseError {
|
|
385
680
|
constructor(unavailableFeature){
|
|
386
681
|
super({
|
|
387
682
|
cause: null,
|
|
@@ -435,7 +730,64 @@ class UnavailableInServerSideError extends logout.BaseError {
|
|
|
435
730
|
register: (options)=>browser.startRegistration(options)
|
|
436
731
|
});
|
|
437
732
|
|
|
438
|
-
|
|
733
|
+
const createDebouncedMutex = ()=>{
|
|
734
|
+
const mutexState = new Map();
|
|
735
|
+
return async ({ lockKey, callback, debounceTime = 0 })=>{
|
|
736
|
+
const resolutionPromise = createDeferredPromise();
|
|
737
|
+
// Prefill the state for this key if it doesn't exist to avoid needing to check for existence later.
|
|
738
|
+
if (!mutexState.has(lockKey)) {
|
|
739
|
+
mutexState.set(lockKey, {
|
|
740
|
+
nextCallback: null,
|
|
741
|
+
queuePromise: Promise.resolve(),
|
|
742
|
+
resolutionPromises: [],
|
|
743
|
+
timer: null
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
const currentState = mutexState.get(lockKey);
|
|
747
|
+
// This should never happen, but we'll assert it for TS safety.
|
|
748
|
+
constants.assertDefined(currentState, `Mutex state for key ${lockKey} not found`);
|
|
749
|
+
currentState.resolutionPromises.push(resolutionPromise);
|
|
750
|
+
if (currentState.timer) {
|
|
751
|
+
clearTimeout(currentState.timer);
|
|
752
|
+
}
|
|
753
|
+
// The last invocation wins. Always.
|
|
754
|
+
currentState.nextCallback = callback;
|
|
755
|
+
const addCallbackToQueue = async ()=>{
|
|
756
|
+
currentState.queuePromise = currentState.queuePromise.then(async ()=>{
|
|
757
|
+
if (!currentState.nextCallback) {
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
// We can't just use the callback param directly because later invocations
|
|
761
|
+
// should override previous ones.
|
|
762
|
+
// Scenario to illustrate this (none of these will use the timer param for simplicity):
|
|
763
|
+
// 1. Very long running promise callback A runs
|
|
764
|
+
// 2. While it's running, we invoke callback B, which queues itself with "then" and overrides nextCallback with B.
|
|
765
|
+
// 3. While A is still running, we invoke callback C, same thing happens, now nextCallback is C.
|
|
766
|
+
// 4. A resolves, nextCallback is invoked with C.
|
|
767
|
+
// 5. After C resolves, nextCallback is invoked with null, so it doesn't run.
|
|
768
|
+
// Conclusion: B was never executed and only the last invocation runs.
|
|
769
|
+
const { nextCallback } = currentState;
|
|
770
|
+
currentState.nextCallback = null;
|
|
771
|
+
const promisesToResolve = currentState.resolutionPromises;
|
|
772
|
+
currentState.resolutionPromises = [];
|
|
773
|
+
try {
|
|
774
|
+
await nextCallback();
|
|
775
|
+
promisesToResolve.forEach((resolutionPromise)=>resolutionPromise.resolve());
|
|
776
|
+
} catch (error) {
|
|
777
|
+
promisesToResolve.forEach((resolutionPromise)=>resolutionPromise.reject(error));
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
};
|
|
781
|
+
if (debounceTime > 0) {
|
|
782
|
+
currentState.timer = setTimeout(addCallbackToQueue, debounceTime);
|
|
783
|
+
} else {
|
|
784
|
+
await addCallbackToQueue();
|
|
785
|
+
}
|
|
786
|
+
return resolutionPromise.promise;
|
|
787
|
+
};
|
|
788
|
+
};
|
|
789
|
+
|
|
790
|
+
class InvalidStorageValue extends constants.BaseError {
|
|
439
791
|
constructor(key, value){
|
|
440
792
|
super({
|
|
441
793
|
cause: null,
|
|
@@ -534,7 +886,8 @@ class InvalidStorageValue extends logout.BaseError {
|
|
|
534
886
|
sessionKeys: null,
|
|
535
887
|
token: null,
|
|
536
888
|
unverifiedWalletAccounts: [],
|
|
537
|
-
user: null
|
|
889
|
+
user: null,
|
|
890
|
+
walletProviderKeyMap: {}
|
|
538
891
|
});
|
|
539
892
|
|
|
540
893
|
/**
|
|
@@ -544,7 +897,9 @@ class InvalidStorageValue extends logout.BaseError {
|
|
|
544
897
|
var _config_coreConfig_apiBaseUrl;
|
|
545
898
|
const apiBaseUrl = (_config_coreConfig_apiBaseUrl = (_config_coreConfig = config.coreConfig) == null ? void 0 : _config_coreConfig.apiBaseUrl) != null ? _config_coreConfig_apiBaseUrl : DEFAULT_API_BASE_URL;
|
|
546
899
|
var _config_coreConfig_logger;
|
|
547
|
-
const logger = (_config_coreConfig_logger = (_config_coreConfig1 = config.coreConfig) == null ? void 0 : _config_coreConfig1.logger) != null ? _config_coreConfig_logger : getNetworkProviderFromNetworkId.createLogger(
|
|
900
|
+
const logger = (_config_coreConfig_logger = (_config_coreConfig1 = config.coreConfig) == null ? void 0 : _config_coreConfig1.logger) != null ? _config_coreConfig_logger : getNetworkProviderFromNetworkId.createLogger({
|
|
901
|
+
level: config.logLevel
|
|
902
|
+
});
|
|
548
903
|
var _config_coreConfig_storageAdapter;
|
|
549
904
|
const storage = getNetworkProviderFromNetworkId.createStorage({
|
|
550
905
|
prefix: `dynamic_${config.environmentId}`,
|
|
@@ -557,6 +912,7 @@ class InvalidStorageValue extends logout.BaseError {
|
|
|
557
912
|
var _config_coreConfig_navigate;
|
|
558
913
|
const navigate = (_config_coreConfig_navigate = (_config_coreConfig5 = config.coreConfig) == null ? void 0 : _config_coreConfig5.navigate) != null ? _config_coreConfig_navigate : createNavigationHandler();
|
|
559
914
|
const state = createObservableState(getInitialState);
|
|
915
|
+
const debouncedMutex = createDebouncedMutex();
|
|
560
916
|
const eventEmitter = createEventEmitter();
|
|
561
917
|
const initTrack = createAsyncTrack();
|
|
562
918
|
const runtimeServices = createRuntimeServices();
|
|
@@ -565,6 +921,7 @@ class InvalidStorageValue extends logout.BaseError {
|
|
|
565
921
|
var _config_coreConfig_getApiHeaders;
|
|
566
922
|
return {
|
|
567
923
|
apiBaseUrl,
|
|
924
|
+
debouncedMutex,
|
|
568
925
|
environmentId: config.environmentId,
|
|
569
926
|
eventEmitter,
|
|
570
927
|
extensions: new Set(),
|
|
@@ -579,7 +936,7 @@ class InvalidStorageValue extends logout.BaseError {
|
|
|
579
936
|
runtimeServices,
|
|
580
937
|
state,
|
|
581
938
|
storage,
|
|
582
|
-
version:
|
|
939
|
+
version: constants.version
|
|
583
940
|
};
|
|
584
941
|
};
|
|
585
942
|
|
|
@@ -622,15 +979,20 @@ class InvalidStorageValue extends logout.BaseError {
|
|
|
622
979
|
}
|
|
623
980
|
};
|
|
624
981
|
var _config_autoInitialize;
|
|
625
|
-
|
|
982
|
+
// Define if SDK should auto initialize, default to true
|
|
983
|
+
const autoInitialize = (_config_autoInitialize = config.autoInitialize) != null ? _config_autoInitialize : true;
|
|
984
|
+
// Prevent the auto initialization in SSR
|
|
985
|
+
const shouldAutoInitialize = isServerSideRendering() ? false : autoInitialize;
|
|
986
|
+
core.logger.debug('[createDynamicClient] Creating client...');
|
|
626
987
|
if (shouldAutoInitialize) {
|
|
988
|
+
core.logger.debug('[createDynamicClient] Initializing client...');
|
|
627
989
|
void initializeClient(client);
|
|
628
990
|
}
|
|
629
|
-
|
|
991
|
+
constants.setDefaultClient(client);
|
|
630
992
|
return client;
|
|
631
993
|
};
|
|
632
994
|
|
|
633
|
-
class InvalidRedirectStorageStateError extends
|
|
995
|
+
class InvalidRedirectStorageStateError extends constants.BaseError {
|
|
634
996
|
constructor(){
|
|
635
997
|
super({
|
|
636
998
|
cause: null,
|
|
@@ -642,7 +1004,7 @@ class InvalidRedirectStorageStateError extends logout.BaseError {
|
|
|
642
1004
|
}
|
|
643
1005
|
}
|
|
644
1006
|
|
|
645
|
-
class MissingRedirectStorageStateError extends
|
|
1007
|
+
class MissingRedirectStorageStateError extends constants.BaseError {
|
|
646
1008
|
constructor(){
|
|
647
1009
|
super({
|
|
648
1010
|
cause: null,
|
|
@@ -654,7 +1016,7 @@ class MissingRedirectStorageStateError extends logout.BaseError {
|
|
|
654
1016
|
}
|
|
655
1017
|
}
|
|
656
1018
|
|
|
657
|
-
class MissingSocialUrlParamError extends
|
|
1019
|
+
class MissingSocialUrlParamError extends constants.BaseError {
|
|
658
1020
|
constructor(param){
|
|
659
1021
|
super({
|
|
660
1022
|
cause: null,
|
|
@@ -666,7 +1028,20 @@ class MissingSocialUrlParamError extends logout.BaseError {
|
|
|
666
1028
|
}
|
|
667
1029
|
}
|
|
668
1030
|
|
|
669
|
-
class
|
|
1031
|
+
class MissingUserVerificationError extends constants.BaseError {
|
|
1032
|
+
constructor({ informationToVerify, message }){
|
|
1033
|
+
super({
|
|
1034
|
+
cause: null,
|
|
1035
|
+
code: 'missing_user_verification_error',
|
|
1036
|
+
docsUrl: null,
|
|
1037
|
+
name: 'MissingUserVerificationError',
|
|
1038
|
+
shortMessage: message != null ? message : `The user is missing verification for ${informationToVerify}. Please verify the user's ${informationToVerify}`
|
|
1039
|
+
});
|
|
1040
|
+
this.informationToVerify = informationToVerify;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
class NetworkSwitchingUnavailableError extends constants.BaseError {
|
|
670
1045
|
constructor({ walletProviderKey, originalError, extraMessages }){
|
|
671
1046
|
const cause = originalError instanceof Error ? originalError : null;
|
|
672
1047
|
super({
|
|
@@ -683,7 +1058,7 @@ class NetworkSwitchingUnavailableError extends logout.BaseError {
|
|
|
683
1058
|
}
|
|
684
1059
|
}
|
|
685
1060
|
|
|
686
|
-
class NoAddressFoundError extends
|
|
1061
|
+
class NoAddressFoundError extends constants.BaseError {
|
|
687
1062
|
constructor(){
|
|
688
1063
|
super({
|
|
689
1064
|
cause: null,
|
|
@@ -695,7 +1070,7 @@ class NoAddressFoundError extends logout.BaseError {
|
|
|
695
1070
|
}
|
|
696
1071
|
}
|
|
697
1072
|
|
|
698
|
-
class NoPasskeyCredentialsFoundError extends
|
|
1073
|
+
class NoPasskeyCredentialsFoundError extends constants.BaseError {
|
|
699
1074
|
constructor(){
|
|
700
1075
|
super({
|
|
701
1076
|
cause: null,
|
|
@@ -707,7 +1082,19 @@ class NoPasskeyCredentialsFoundError extends logout.BaseError {
|
|
|
707
1082
|
}
|
|
708
1083
|
}
|
|
709
1084
|
|
|
710
|
-
class
|
|
1085
|
+
class NoSmartWalletAccountSignerFoundError extends constants.BaseError {
|
|
1086
|
+
constructor(smartWalletAddress){
|
|
1087
|
+
super({
|
|
1088
|
+
cause: null,
|
|
1089
|
+
code: 'no_smart_wallet_account_signer_found_error',
|
|
1090
|
+
docsUrl: null,
|
|
1091
|
+
name: 'NoSmartWalletAccountSignerFoundError',
|
|
1092
|
+
shortMessage: `No signer wallet account found for smart wallet account ${smartWalletAddress}`
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
class NoWebAuthNSupportError extends constants.BaseError {
|
|
711
1098
|
constructor(){
|
|
712
1099
|
super({
|
|
713
1100
|
cause: null,
|
|
@@ -719,7 +1106,7 @@ class NoWebAuthNSupportError extends logout.BaseError {
|
|
|
719
1106
|
}
|
|
720
1107
|
}
|
|
721
1108
|
|
|
722
|
-
class UnrecognizedNetworkError extends
|
|
1109
|
+
class UnrecognizedNetworkError extends constants.BaseError {
|
|
723
1110
|
constructor({ networkId, originalError, walletProviderKey }){
|
|
724
1111
|
const cause = originalError instanceof Error ? originalError : null;
|
|
725
1112
|
super({
|
|
@@ -735,7 +1122,7 @@ class UnrecognizedNetworkError extends logout.BaseError {
|
|
|
735
1122
|
}
|
|
736
1123
|
}
|
|
737
1124
|
|
|
738
|
-
class UserNotAuthenticatedError extends
|
|
1125
|
+
class UserNotAuthenticatedError extends constants.BaseError {
|
|
739
1126
|
constructor({ shortMessage } = {}){
|
|
740
1127
|
super({
|
|
741
1128
|
cause: null,
|
|
@@ -747,7 +1134,7 @@ class UserNotAuthenticatedError extends logout.BaseError {
|
|
|
747
1134
|
}
|
|
748
1135
|
}
|
|
749
1136
|
|
|
750
|
-
class UserRejectedError extends
|
|
1137
|
+
class UserRejectedError extends constants.BaseError {
|
|
751
1138
|
constructor({ action }){
|
|
752
1139
|
super({
|
|
753
1140
|
cause: null,
|
|
@@ -759,7 +1146,7 @@ class UserRejectedError extends logout.BaseError {
|
|
|
759
1146
|
}
|
|
760
1147
|
}
|
|
761
1148
|
|
|
762
|
-
class WalletAccountAlreadyVerifiedError extends
|
|
1149
|
+
class WalletAccountAlreadyVerifiedError extends constants.BaseError {
|
|
763
1150
|
constructor(address){
|
|
764
1151
|
super({
|
|
765
1152
|
cause: null,
|
|
@@ -771,33 +1158,22 @@ class WalletAccountAlreadyVerifiedError extends logout.BaseError {
|
|
|
771
1158
|
}
|
|
772
1159
|
}
|
|
773
1160
|
|
|
774
|
-
class WalletAccountNotSelectedError extends
|
|
1161
|
+
class WalletAccountNotSelectedError extends constants.BaseError {
|
|
775
1162
|
constructor(params){
|
|
1163
|
+
const currentAccountInfo = params.selectedAddress ? ` (currently ${params.selectedAddress})` : '';
|
|
776
1164
|
super({
|
|
777
1165
|
cause: null,
|
|
778
1166
|
code: 'wallet_account_not_selected_error',
|
|
779
1167
|
docsUrl: null,
|
|
780
1168
|
name: 'WalletAccountNotSelected',
|
|
781
|
-
shortMessage: `This wallet only supports signing with its selected account
|
|
1169
|
+
shortMessage: `This wallet only supports signing with its selected account${currentAccountInfo}. Please select account ${params.expectedAddress} in your wallet app and try again`
|
|
782
1170
|
});
|
|
783
1171
|
this.expectedAddress = params.expectedAddress;
|
|
784
1172
|
this.selectedAddress = params.selectedAddress;
|
|
785
1173
|
}
|
|
786
1174
|
}
|
|
787
1175
|
|
|
788
|
-
class
|
|
789
|
-
constructor({ cause }){
|
|
790
|
-
super({
|
|
791
|
-
cause,
|
|
792
|
-
code: 'wallet_already_linked_to_another_user_error',
|
|
793
|
-
docsUrl: null,
|
|
794
|
-
name: 'WalletAlreadyLinkedToAnotherUserError',
|
|
795
|
-
shortMessage: 'This wallet is already linked to another user'
|
|
796
|
-
});
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
class WalletProviderMethodUnavailableError extends logout.BaseError {
|
|
1176
|
+
class WalletProviderMethodUnavailableError extends constants.BaseError {
|
|
801
1177
|
constructor({ methodName, walletProviderKey }){
|
|
802
1178
|
super({
|
|
803
1179
|
cause: null,
|
|
@@ -818,9 +1194,9 @@ class WalletProviderMethodUnavailableError extends logout.BaseError {
|
|
|
818
1194
|
* @param [params.externalJwt] - Optional external JWT token to authenticate with. Not required when using cookie based auth.
|
|
819
1195
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
820
1196
|
* @returns A promise that resolves to the authentication response from the server.
|
|
821
|
-
*/ const signInWithExternalJwt = async ({ externalJwt, sessionPublicKey } = {}, client =
|
|
822
|
-
const core =
|
|
823
|
-
const apiClient =
|
|
1197
|
+
*/ const signInWithExternalJwt = async ({ externalJwt, sessionPublicKey } = {}, client = constants.getDefaultClient())=>{
|
|
1198
|
+
const core = constants.getCore(client);
|
|
1199
|
+
const apiClient = constants.createApiClient({}, client);
|
|
824
1200
|
const response = await apiClient.externalAuthSignin({
|
|
825
1201
|
environmentId: core.environmentId,
|
|
826
1202
|
externalAuthSigninRequest: {
|
|
@@ -828,7 +1204,7 @@ class WalletProviderMethodUnavailableError extends logout.BaseError {
|
|
|
828
1204
|
sessionPublicKey
|
|
829
1205
|
}
|
|
830
1206
|
});
|
|
831
|
-
|
|
1207
|
+
getVerifiedCredentialForWalletAccount.updateAuthFromVerifyResponse({
|
|
832
1208
|
response
|
|
833
1209
|
}, client);
|
|
834
1210
|
return response;
|
|
@@ -840,9 +1216,9 @@ class WalletProviderMethodUnavailableError extends logout.BaseError {
|
|
|
840
1216
|
* @param params.passkeyId - The unique identifier of the passkey to delete.
|
|
841
1217
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
842
1218
|
* @returns A promise that resolves when the passkey is successfully deleted.
|
|
843
|
-
*/ const deletePasskey = async ({ passkeyId }, client =
|
|
844
|
-
const core =
|
|
845
|
-
const apiClient =
|
|
1219
|
+
*/ const deletePasskey = async ({ passkeyId }, client = constants.getDefaultClient())=>{
|
|
1220
|
+
const core = constants.getCore(client);
|
|
1221
|
+
const apiClient = constants.createApiClient({
|
|
846
1222
|
includeMfaToken: true
|
|
847
1223
|
}, client);
|
|
848
1224
|
await apiClient.deletePasskey({
|
|
@@ -861,9 +1237,9 @@ class WalletProviderMethodUnavailableError extends logout.BaseError {
|
|
|
861
1237
|
*
|
|
862
1238
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
863
1239
|
* @returns A promise that resolves to an array of the user's registered passkeys.
|
|
864
|
-
*/ const getPasskeys = async (client =
|
|
865
|
-
const core =
|
|
866
|
-
const apiClient =
|
|
1240
|
+
*/ const getPasskeys = async (client = constants.getDefaultClient())=>{
|
|
1241
|
+
const core = constants.getCore(client);
|
|
1242
|
+
const apiClient = constants.createApiClient({}, client);
|
|
867
1243
|
const response = await apiClient.getUserPasskeys({
|
|
868
1244
|
environmentId: core.environmentId
|
|
869
1245
|
});
|
|
@@ -871,21 +1247,22 @@ class WalletProviderMethodUnavailableError extends logout.BaseError {
|
|
|
871
1247
|
};
|
|
872
1248
|
|
|
873
1249
|
const getPasskeyRegistrationOptions = async (client)=>{
|
|
874
|
-
const core =
|
|
875
|
-
const apiClient =
|
|
1250
|
+
const core = constants.getCore(client);
|
|
1251
|
+
const apiClient = constants.createApiClient({}, client);
|
|
876
1252
|
const options = await apiClient.getPasskeyRegistrationOptions({
|
|
877
1253
|
environmentId: core.environmentId
|
|
878
1254
|
});
|
|
879
1255
|
return options;
|
|
880
1256
|
};
|
|
881
1257
|
|
|
882
|
-
const serverRegisterPasskey = async ({ registration }, client)=>{
|
|
883
|
-
const core =
|
|
884
|
-
const apiClient =
|
|
1258
|
+
const serverRegisterPasskey = async ({ registration, createMfaToken }, client)=>{
|
|
1259
|
+
const core = constants.getCore(client);
|
|
1260
|
+
const apiClient = constants.createApiClient({}, client);
|
|
885
1261
|
const response = await apiClient.registerPasskey({
|
|
886
1262
|
environmentId: core.environmentId,
|
|
887
|
-
passkeyRegisterRequest:
|
|
888
|
-
|
|
1263
|
+
passkeyRegisterRequest: constants._extends({}, registration, {
|
|
1264
|
+
createMfaToken,
|
|
1265
|
+
response: constants._extends({}, registration.response, {
|
|
889
1266
|
clientDataJson: registration.response.clientDataJSON
|
|
890
1267
|
})
|
|
891
1268
|
})
|
|
@@ -900,11 +1277,12 @@ const serverRegisterPasskey = async ({ registration }, client)=>{
|
|
|
900
1277
|
* passwordless authentication. The user will be prompted to create a passkey
|
|
901
1278
|
* using their device's biometric authentication or security key.
|
|
902
1279
|
*
|
|
1280
|
+
* @param [params.createMfaToken] - Optional configuration for MFA token creation.
|
|
903
1281
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
904
1282
|
* @returns A promise that resolves to the registration response.
|
|
905
1283
|
* @throws NoWebAuthNSupportError If WebAuthn is not supported by the browser.
|
|
906
|
-
*/ const registerPasskey = async (client =
|
|
907
|
-
const core =
|
|
1284
|
+
*/ const registerPasskey = async ({ createMfaToken } = {}, client = constants.getDefaultClient())=>{
|
|
1285
|
+
const core = constants.getCore(client);
|
|
908
1286
|
if (!core.passkey.isSupported()) {
|
|
909
1287
|
throw new NoWebAuthNSupportError();
|
|
910
1288
|
}
|
|
@@ -913,31 +1291,33 @@ const serverRegisterPasskey = async ({ registration }, client)=>{
|
|
|
913
1291
|
optionsJSON: options
|
|
914
1292
|
});
|
|
915
1293
|
const response = await serverRegisterPasskey({
|
|
1294
|
+
createMfaToken,
|
|
916
1295
|
registration
|
|
917
1296
|
}, client);
|
|
918
|
-
|
|
1297
|
+
getVerifiedCredentialForWalletAccount.updateAuthFromVerifyResponse({
|
|
919
1298
|
response
|
|
920
1299
|
}, client);
|
|
921
1300
|
return response;
|
|
922
1301
|
};
|
|
923
1302
|
|
|
924
|
-
const getPasskeyAuthenticationSignInOptions = async (client)=>{
|
|
925
|
-
const core =
|
|
926
|
-
const apiClient =
|
|
1303
|
+
const getPasskeyAuthenticationSignInOptions = async ({ relatedOriginRpId } = {}, client)=>{
|
|
1304
|
+
const core = constants.getCore(client);
|
|
1305
|
+
const apiClient = constants.createApiClient({}, client);
|
|
927
1306
|
const options = await apiClient.getPasskeyAuthenticationSigninOptions({
|
|
928
|
-
environmentId: core.environmentId
|
|
1307
|
+
environmentId: core.environmentId,
|
|
1308
|
+
relatedOriginRpId: relatedOriginRpId
|
|
929
1309
|
});
|
|
930
1310
|
return options;
|
|
931
1311
|
};
|
|
932
1312
|
|
|
933
1313
|
const serverSigninPasskey = async ({ authentication, createMfaToken }, client)=>{
|
|
934
|
-
const core =
|
|
935
|
-
const apiClient =
|
|
1314
|
+
const core = constants.getCore(client);
|
|
1315
|
+
const apiClient = constants.createApiClient({}, client);
|
|
936
1316
|
const response = await apiClient.signinWithPasskey({
|
|
937
1317
|
environmentId: core.environmentId,
|
|
938
|
-
passkeyAuthRequest:
|
|
1318
|
+
passkeyAuthRequest: constants._extends({}, authentication, {
|
|
939
1319
|
createMfaToken,
|
|
940
|
-
response:
|
|
1320
|
+
response: constants._extends({}, authentication.response, {
|
|
941
1321
|
clientDataJson: authentication.response.clientDataJSON
|
|
942
1322
|
})
|
|
943
1323
|
})
|
|
@@ -955,107 +1335,67 @@ const serverSigninPasskey = async ({ authentication, createMfaToken }, client)=>
|
|
|
955
1335
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
956
1336
|
* @returns A promise that resolves to the authentication response.
|
|
957
1337
|
* @throws NoWebAuthNSupportError If WebAuthn is not supported by the browser.
|
|
958
|
-
*/ const signInWithPasskey = async (client =
|
|
959
|
-
const core =
|
|
1338
|
+
*/ const signInWithPasskey = async ({ relatedOriginRpId } = {}, client = constants.getDefaultClient())=>{
|
|
1339
|
+
const core = constants.getCore(client);
|
|
960
1340
|
if (!core.passkey.isSupported()) {
|
|
961
1341
|
throw new NoWebAuthNSupportError();
|
|
962
1342
|
}
|
|
963
|
-
const options = await getPasskeyAuthenticationSignInOptions(
|
|
964
|
-
|
|
1343
|
+
const options = await getPasskeyAuthenticationSignInOptions({
|
|
1344
|
+
relatedOriginRpId
|
|
1345
|
+
}, client);
|
|
1346
|
+
const formattedOptions = constants._extends({}, options);
|
|
965
1347
|
const authentication = await core.passkey.authenticate({
|
|
966
1348
|
optionsJSON: formattedOptions
|
|
967
1349
|
});
|
|
968
1350
|
const response = await serverSigninPasskey({
|
|
969
1351
|
authentication
|
|
970
1352
|
}, client);
|
|
971
|
-
|
|
1353
|
+
getVerifiedCredentialForWalletAccount.updateAuthFromVerifyResponse({
|
|
972
1354
|
response
|
|
973
1355
|
}, client);
|
|
974
1356
|
return response;
|
|
975
1357
|
};
|
|
976
1358
|
|
|
977
|
-
/** The schema to track the state of the OAuth flow. */ const redirectStateStorageSchema = logout.createStorageKeySchema({
|
|
978
|
-
key: 'redirectState',
|
|
979
|
-
schema: z__namespace.object({
|
|
980
|
-
codeVerifier: z__namespace.optional(z__namespace.string()),
|
|
981
|
-
provider: z__namespace.enum(sdkApiCore.ProviderEnum),
|
|
982
|
-
state: z__namespace.string()
|
|
983
|
-
})
|
|
984
|
-
});
|
|
985
|
-
|
|
986
1359
|
/**
|
|
987
|
-
*
|
|
988
|
-
*
|
|
989
|
-
* This function processes the OAuth callback URL with authorization codes
|
|
990
|
-
* and completes the user authentication with the social provider.
|
|
1360
|
+
* Retrieves all social accounts associated with the current user.
|
|
991
1361
|
*
|
|
992
|
-
* @param params.url - The callback URL containing OAuth response parameters.
|
|
993
1362
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
994
|
-
* @returns
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
const
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
throw new MissingRedirectStorageStateError();
|
|
1012
|
-
}
|
|
1013
|
-
if (storedSocialRedirectState.state !== dynamicOauthState) {
|
|
1014
|
-
throw new InvalidRedirectStorageStateError();
|
|
1015
|
-
}
|
|
1016
|
-
const { provider, codeVerifier } = storedSocialRedirectState;
|
|
1017
|
-
await core.storage.removeItem(redirectStateStorageSchema);
|
|
1018
|
-
const response = await apiClient.oauthSignIn({
|
|
1019
|
-
environmentId: core.environmentId,
|
|
1020
|
-
oauthRequest: {
|
|
1021
|
-
captchaToken: getNetworkProviderFromNetworkId.consumeCaptchaToken(client),
|
|
1022
|
-
code: dynamicOauthCode,
|
|
1023
|
-
codeVerifier,
|
|
1024
|
-
state: dynamicOauthState
|
|
1025
|
-
},
|
|
1026
|
-
providerType: provider
|
|
1363
|
+
* @returns An array of `SocialAccount` objects associated with the user.
|
|
1364
|
+
*/ const getUserSocialAccounts = (client = constants.getDefaultClient())=>{
|
|
1365
|
+
const { user } = client;
|
|
1366
|
+
constants.assertDefined(user, 'User is not authenticated');
|
|
1367
|
+
var _user_verifiedCredentials_filter;
|
|
1368
|
+
const socialCredentials = (_user_verifiedCredentials_filter = user.verifiedCredentials.filter((credential)=>credential.format === sdkApiCore.JwtVerifiedCredentialFormatEnum.Oauth)) != null ? _user_verifiedCredentials_filter : [];
|
|
1369
|
+
return socialCredentials.map((credential)=>{
|
|
1370
|
+
var _credential_oauthAccountId, _credential_oauthDisplayName, _credential_oauthEmails, _credential_oauthAccountPhotos, _credential_oauthUsername;
|
|
1371
|
+
return {
|
|
1372
|
+
accountId: (_credential_oauthAccountId = credential.oauthAccountId) != null ? _credential_oauthAccountId : undefined,
|
|
1373
|
+
displayName: (_credential_oauthDisplayName = credential.oauthDisplayName) != null ? _credential_oauthDisplayName : undefined,
|
|
1374
|
+
emails: (_credential_oauthEmails = credential.oauthEmails) != null ? _credential_oauthEmails : [],
|
|
1375
|
+
photos: (_credential_oauthAccountPhotos = credential.oauthAccountPhotos) != null ? _credential_oauthAccountPhotos : [],
|
|
1376
|
+
provider: credential.oauthProvider,
|
|
1377
|
+
username: (_credential_oauthUsername = credential.oauthUsername) != null ? _credential_oauthUsername : undefined,
|
|
1378
|
+
verifiedCredentialId: credential.id
|
|
1379
|
+
};
|
|
1027
1380
|
});
|
|
1028
|
-
getWalletProviderByKey.updateAuthFromVerifyResponse({
|
|
1029
|
-
response
|
|
1030
|
-
}, client);
|
|
1031
|
-
return response.user;
|
|
1032
1381
|
};
|
|
1033
1382
|
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
*
|
|
1040
|
-
* @param params.url - The URL to check for OAuth redirect parameters.
|
|
1041
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1042
|
-
* @returns A promise that resolves to true if the URL is an OAuth redirect, false otherwise.
|
|
1043
|
-
*/ const detectOAuthRedirect = async ({ url }, client = logout.getDefaultClient())=>{
|
|
1044
|
-
const core = logout.getCore(client);
|
|
1045
|
-
const dynamicOauthState = url.searchParams.get('dynamicOauthState');
|
|
1046
|
-
const dynamicOauthCode = url.searchParams.get('dynamicOauthCode');
|
|
1047
|
-
if (!dynamicOauthState || !dynamicOauthCode) {
|
|
1048
|
-
return false;
|
|
1049
|
-
}
|
|
1050
|
-
// Wait for SDK to load
|
|
1051
|
-
await core.initTrack.waitForAll();
|
|
1052
|
-
const storedSocialRedirectState = await core.storage.getItem(redirectStateStorageSchema);
|
|
1053
|
-
if (!storedSocialRedirectState || storedSocialRedirectState.state !== dynamicOauthState) {
|
|
1054
|
-
return false;
|
|
1055
|
-
}
|
|
1056
|
-
return true;
|
|
1383
|
+
const removeDynamicOauthParamsFromUrl = (url)=>{
|
|
1384
|
+
const urlObject = new URL(url);
|
|
1385
|
+
urlObject.searchParams.delete('dynamicOauthState');
|
|
1386
|
+
urlObject.searchParams.delete('dynamicOauthCode');
|
|
1387
|
+
return urlObject.toString();
|
|
1057
1388
|
};
|
|
1058
1389
|
|
|
1390
|
+
/** The schema to track the state of the OAuth flow. */ const redirectStateStorageKeySchema = getNetworkProviderFromNetworkId.createStorageKeySchema({
|
|
1391
|
+
key: 'redirectState',
|
|
1392
|
+
schema: z__namespace.object({
|
|
1393
|
+
codeVerifier: z__namespace.optional(z__namespace.string()),
|
|
1394
|
+
provider: z__namespace.enum(sdkApiCore.ProviderEnum),
|
|
1395
|
+
state: z__namespace.string()
|
|
1396
|
+
})
|
|
1397
|
+
});
|
|
1398
|
+
|
|
1059
1399
|
const digestSHA256 = (str)=>{
|
|
1060
1400
|
const encoder = new TextEncoder();
|
|
1061
1401
|
const data = encoder.encode(str);
|
|
@@ -1077,9 +1417,9 @@ const digestSHA256 = (str)=>{
|
|
|
1077
1417
|
const APPLE_RESPONSE_MODE = 'form_post';
|
|
1078
1418
|
const APPLE_RESPONSE_TYPE = 'code id_token';
|
|
1079
1419
|
/** Helper function to add OAuth URL parameters to a given base URL. */ const addOAuthUrlParams = (provider, baseUrl)=>{
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1420
|
+
constants.assertDefined(provider.clientId, 'Client ID not found');
|
|
1421
|
+
constants.assertDefined(provider.provider, 'Provider type not found');
|
|
1422
|
+
constants.assertDefined(provider.redirectUrl, 'Redirect URL not found');
|
|
1083
1423
|
const providerType = provider.provider;
|
|
1084
1424
|
baseUrl.searchParams.set('client_id', provider.clientId);
|
|
1085
1425
|
baseUrl.searchParams.set('response_type', 'code');
|
|
@@ -1103,15 +1443,15 @@ const APPLE_RESPONSE_TYPE = 'code id_token';
|
|
|
1103
1443
|
};
|
|
1104
1444
|
|
|
1105
1445
|
/** Helper function to build the OAuth base URL for a given provider. */ const getOAuthBaseUrl = (provider)=>{
|
|
1106
|
-
|
|
1446
|
+
constants.assertDefined(provider.provider, 'Provider type not found');
|
|
1107
1447
|
const providerType = provider.provider;
|
|
1108
1448
|
if (providerType === sdkApiCore.ProviderEnum.Telegram) {
|
|
1109
|
-
|
|
1449
|
+
constants.assertDefined(provider.authorizationUrl, 'Telegram authorization URL not found');
|
|
1110
1450
|
return new URL(provider.authorizationUrl);
|
|
1111
1451
|
}
|
|
1112
|
-
|
|
1452
|
+
constants.assertDefined(provider.baseAuthUrl, 'Base auth URL not found');
|
|
1113
1453
|
if (providerType === sdkApiCore.ProviderEnum.Shopify) {
|
|
1114
|
-
|
|
1454
|
+
constants.assertDefined(provider.shopifyStore, 'Shopify store value not found in provider');
|
|
1115
1455
|
const loginBaseUrl = provider.baseAuthUrl.replace('{{shopifyStore}}', provider.shopifyStore);
|
|
1116
1456
|
return new URL(loginBaseUrl);
|
|
1117
1457
|
}
|
|
@@ -1125,17 +1465,17 @@ const providersRequiringPkce = [
|
|
|
1125
1465
|
/** Helper function to build the OAuth URL for a given provider. */ const buildOAuthUrl = async (/** The core instance. */ core, /** The provider to build the OAuth URL for. */ provider)=>{
|
|
1126
1466
|
const { projectSettings } = core.state.get();
|
|
1127
1467
|
// Check if the provider is supported
|
|
1128
|
-
|
|
1129
|
-
|
|
1468
|
+
constants.assertDefined(projectSettings, 'Project settings not found');
|
|
1469
|
+
constants.assertDefined(projectSettings.providers, 'Project providers not found');
|
|
1130
1470
|
const socialProvider = projectSettings.providers.find((p)=>p.provider === provider);
|
|
1131
|
-
|
|
1471
|
+
constants.assertDefined(socialProvider, `Social provider ${provider} not supported`);
|
|
1132
1472
|
// Build the OAuth URL
|
|
1133
1473
|
const loginBaseUrl = getOAuthBaseUrl(socialProvider);
|
|
1134
1474
|
const socialProviderUrl = addOAuthUrlParams(socialProvider, loginBaseUrl);
|
|
1135
1475
|
// Add PKCE and state parameters
|
|
1136
1476
|
const usingPkce = providersRequiringPkce.includes(provider);
|
|
1137
|
-
const state =
|
|
1138
|
-
const codeVerifier =
|
|
1477
|
+
const state = constants.randomString(32);
|
|
1478
|
+
const codeVerifier = constants.randomString(43);
|
|
1139
1479
|
socialProviderUrl.searchParams.set('state', state);
|
|
1140
1480
|
socialProviderUrl.searchParams.set('response_type', 'code');
|
|
1141
1481
|
if (usingPkce) {
|
|
@@ -1156,25 +1496,27 @@ const providersRequiringPkce = [
|
|
|
1156
1496
|
* This function redirects the user to the specified social provider's
|
|
1157
1497
|
* authorization page to complete OAuth authentication flow.
|
|
1158
1498
|
* After the oauth flow is complete, the user will be redirected back to your app.
|
|
1499
|
+
* You can then call `detectOAuthRedirect` to check if the user got redirected back to your app due to the oauth flow,
|
|
1500
|
+
* and finally call `completeSocialAuthentication` to complete the social authentication flow.
|
|
1159
1501
|
*
|
|
1160
1502
|
* @param params.provider - The social provider to authenticate with (e.g., 'google', 'github').
|
|
1161
1503
|
* @param params.redirectUrl - The URL to redirect back to after authentication.
|
|
1162
1504
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1163
|
-
*/ const
|
|
1164
|
-
const core =
|
|
1165
|
-
const apiClient =
|
|
1505
|
+
*/ const authenticateWithSocial = async ({ provider, redirectUrl }, client = constants.getDefaultClient())=>{
|
|
1506
|
+
const core = constants.getCore(client);
|
|
1507
|
+
const apiClient = constants.createApiClient({}, client);
|
|
1166
1508
|
await core.initTrack.waitForAll();
|
|
1167
1509
|
const providerType = provider;
|
|
1168
1510
|
const { url, state, codeVerifier } = await buildOAuthUrl(core, providerType);
|
|
1169
1511
|
await apiClient.initAuth({
|
|
1170
1512
|
environmentId: core.environmentId,
|
|
1171
1513
|
oauthInitAuthRequest: {
|
|
1172
|
-
redirectUrl,
|
|
1514
|
+
redirectUrl: removeDynamicOauthParamsFromUrl(redirectUrl),
|
|
1173
1515
|
state
|
|
1174
1516
|
},
|
|
1175
1517
|
providerType
|
|
1176
1518
|
});
|
|
1177
|
-
await core.storage.setItem(
|
|
1519
|
+
await core.storage.setItem(redirectStateStorageKeySchema, {
|
|
1178
1520
|
codeVerifier,
|
|
1179
1521
|
provider: providerType,
|
|
1180
1522
|
state
|
|
@@ -1182,6 +1524,136 @@ const providersRequiringPkce = [
|
|
|
1182
1524
|
await core.navigate(url.toString());
|
|
1183
1525
|
};
|
|
1184
1526
|
|
|
1527
|
+
/**
|
|
1528
|
+
* Completes the social authentication flow after OAuth redirect.
|
|
1529
|
+
*
|
|
1530
|
+
* This function processes the OAuth callback URL with authorization codes
|
|
1531
|
+
* and completes the user authentication with the social provider.
|
|
1532
|
+
*
|
|
1533
|
+
* @param params.url - The callback URL containing OAuth response parameters.
|
|
1534
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1535
|
+
* @returns A promise that resolves to the authenticated user or null.
|
|
1536
|
+
* @throws MissingSocialUrlParamError If required OAuth parameters are missing.
|
|
1537
|
+
* @throws InvalidRedirectStorageStateError If the stored state doesn't match.
|
|
1538
|
+
*/ const completeSocialAuthentication = async ({ url }, client = constants.getDefaultClient())=>{
|
|
1539
|
+
const core = constants.getCore(client);
|
|
1540
|
+
const apiClient = constants.createApiClient({}, client);
|
|
1541
|
+
await core.initTrack.waitForAll();
|
|
1542
|
+
const dynamicOauthState = url.searchParams.get('dynamicOauthState');
|
|
1543
|
+
const dynamicOauthCode = url.searchParams.get('dynamicOauthCode');
|
|
1544
|
+
if (!dynamicOauthState) {
|
|
1545
|
+
throw new MissingSocialUrlParamError('dynamicOauthState');
|
|
1546
|
+
}
|
|
1547
|
+
if (!dynamicOauthCode) {
|
|
1548
|
+
throw new MissingSocialUrlParamError('dynamicOauthCode');
|
|
1549
|
+
}
|
|
1550
|
+
const storedSocialRedirectState = await core.storage.getItem(redirectStateStorageKeySchema);
|
|
1551
|
+
if (!storedSocialRedirectState) {
|
|
1552
|
+
throw new MissingRedirectStorageStateError();
|
|
1553
|
+
}
|
|
1554
|
+
if (storedSocialRedirectState.state !== dynamicOauthState) {
|
|
1555
|
+
throw new InvalidRedirectStorageStateError();
|
|
1556
|
+
}
|
|
1557
|
+
const { provider, codeVerifier } = storedSocialRedirectState;
|
|
1558
|
+
await core.storage.removeItem(redirectStateStorageKeySchema);
|
|
1559
|
+
let response;
|
|
1560
|
+
// if user is alreadyauthenticated, we're verifying the social auth to link it to the user
|
|
1561
|
+
if (client.user) {
|
|
1562
|
+
response = await apiClient.oauthVerify({
|
|
1563
|
+
environmentId: core.environmentId,
|
|
1564
|
+
oauthRequest: {
|
|
1565
|
+
code: dynamicOauthCode,
|
|
1566
|
+
codeVerifier,
|
|
1567
|
+
state: dynamicOauthState
|
|
1568
|
+
},
|
|
1569
|
+
providerType: provider
|
|
1570
|
+
});
|
|
1571
|
+
} else {
|
|
1572
|
+
// if user is not authenticated, we're signing in with the social auth
|
|
1573
|
+
response = await apiClient.oauthSignIn({
|
|
1574
|
+
environmentId: core.environmentId,
|
|
1575
|
+
oauthRequest: {
|
|
1576
|
+
captchaToken: getNetworkProviderFromNetworkId.consumeCaptchaToken(client),
|
|
1577
|
+
code: dynamicOauthCode,
|
|
1578
|
+
codeVerifier,
|
|
1579
|
+
state: dynamicOauthState
|
|
1580
|
+
},
|
|
1581
|
+
providerType: provider
|
|
1582
|
+
});
|
|
1583
|
+
}
|
|
1584
|
+
getVerifiedCredentialForWalletAccount.updateAuthFromVerifyResponse({
|
|
1585
|
+
response
|
|
1586
|
+
}, client);
|
|
1587
|
+
return response.user;
|
|
1588
|
+
};
|
|
1589
|
+
|
|
1590
|
+
/**
|
|
1591
|
+
* Detects if the current URL is an OAuth redirect from a social provider.
|
|
1592
|
+
*
|
|
1593
|
+
* This function examines the URL parameters to determine if it contains
|
|
1594
|
+
* OAuth callback data from a social authentication flow.
|
|
1595
|
+
*
|
|
1596
|
+
* @param params.url - The URL to check for OAuth redirect parameters.
|
|
1597
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1598
|
+
* @returns A promise that resolves to true if the URL is an OAuth redirect, false otherwise.
|
|
1599
|
+
*/ const detectOAuthRedirect = async ({ url }, client = constants.getDefaultClient())=>{
|
|
1600
|
+
const core = constants.getCore(client);
|
|
1601
|
+
const dynamicOauthState = url.searchParams.get('dynamicOauthState');
|
|
1602
|
+
const dynamicOauthCode = url.searchParams.get('dynamicOauthCode');
|
|
1603
|
+
if (!dynamicOauthState || !dynamicOauthCode) {
|
|
1604
|
+
return false;
|
|
1605
|
+
}
|
|
1606
|
+
// Wait for SDK to load
|
|
1607
|
+
await core.initTrack.waitForAll();
|
|
1608
|
+
const storedSocialRedirectState = await core.storage.getItem(redirectStateStorageKeySchema);
|
|
1609
|
+
if (!storedSocialRedirectState || storedSocialRedirectState.state !== dynamicOauthState) {
|
|
1610
|
+
return false;
|
|
1611
|
+
}
|
|
1612
|
+
return true;
|
|
1613
|
+
};
|
|
1614
|
+
|
|
1615
|
+
/**
|
|
1616
|
+
* Get the primary wallet account.
|
|
1617
|
+
* The primary wallet account is the one that was last selected by the user.
|
|
1618
|
+
* This information is stored in both unverified and verified wallet accounts.
|
|
1619
|
+
* This function consolidates this information to determine which wallet was most recently selected.
|
|
1620
|
+
*/ const getPrimaryWalletAccount = (client = constants.getDefaultClient())=>{
|
|
1621
|
+
const walletAccounts = getVerifiedCredentialForWalletAccount.getWalletAccounts(client);
|
|
1622
|
+
const sortedLastSelectedWalletAccounts = walletAccounts.filter((walletAccount)=>Boolean(walletAccount.lastSelectedAt)).sort((a, b)=>b.lastSelectedAt.getTime() - a.lastSelectedAt.getTime());
|
|
1623
|
+
if (sortedLastSelectedWalletAccounts.length === 0) {
|
|
1624
|
+
return null;
|
|
1625
|
+
}
|
|
1626
|
+
const [primaryWalletAccount] = sortedLastSelectedWalletAccounts;
|
|
1627
|
+
return primaryWalletAccount;
|
|
1628
|
+
};
|
|
1629
|
+
|
|
1630
|
+
/**
|
|
1631
|
+
* Unlinks a social account from the user's account.
|
|
1632
|
+
*
|
|
1633
|
+
* @param params.verifiedCredentialId - The verified credential ID of the social account to unlink.
|
|
1634
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1635
|
+
* @returns A promise that resolves to the verify response.
|
|
1636
|
+
*/ const unlinkSocialAccount = async ({ verifiedCredentialId }, client = constants.getDefaultClient())=>{
|
|
1637
|
+
var _primaryWalletAccount_verifiedCredentialId;
|
|
1638
|
+
const core = constants.getCore(client);
|
|
1639
|
+
const apiClient = constants.createApiClient({}, client);
|
|
1640
|
+
// the api seems to require us to pass the primary wallet id when
|
|
1641
|
+
// unlinking a social account if the user has wallets
|
|
1642
|
+
const primaryWalletAccount = getPrimaryWalletAccount(client);
|
|
1643
|
+
const walletId = primaryWalletAccount == null ? void 0 : (_primaryWalletAccount_verifiedCredentialId = primaryWalletAccount.verifiedCredentialId) == null ? void 0 : _primaryWalletAccount_verifiedCredentialId.replace('-zerodev', '');
|
|
1644
|
+
const response = await apiClient.verifyUnlink({
|
|
1645
|
+
environmentId: core.environmentId,
|
|
1646
|
+
verifyUnlinkRequest: {
|
|
1647
|
+
verifiedCredentialId,
|
|
1648
|
+
walletId: walletId != null ? walletId : undefined
|
|
1649
|
+
}
|
|
1650
|
+
});
|
|
1651
|
+
getVerifiedCredentialForWalletAccount.updateAuthFromVerifyResponse({
|
|
1652
|
+
response
|
|
1653
|
+
}, client);
|
|
1654
|
+
return response;
|
|
1655
|
+
};
|
|
1656
|
+
|
|
1185
1657
|
/**
|
|
1186
1658
|
* Retrieves token balances across multiple blockchain networks.
|
|
1187
1659
|
*
|
|
@@ -1191,9 +1663,9 @@ const providersRequiringPkce = [
|
|
|
1191
1663
|
* @param params.balanceRequest - The balance request configuration specifying which chains, networks and addresses to query.
|
|
1192
1664
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1193
1665
|
* @returns A promise that resolves to the chain balances across multiple networks.
|
|
1194
|
-
*/ const getMultichainBalances = async ({ balanceRequest }, client =
|
|
1195
|
-
const core =
|
|
1196
|
-
const apiClient =
|
|
1666
|
+
*/ const getMultichainBalances = async ({ balanceRequest }, client = constants.getDefaultClient())=>{
|
|
1667
|
+
const core = constants.getCore(client);
|
|
1668
|
+
const apiClient = constants.createApiClient({}, client);
|
|
1197
1669
|
const response = await apiClient.postMultichainAccountBalances({
|
|
1198
1670
|
environmentId: core.environmentId,
|
|
1199
1671
|
multichainAccountBalancesRequest: balanceRequest
|
|
@@ -1201,13 +1673,239 @@ const providersRequiringPkce = [
|
|
|
1201
1673
|
return response.chainBalances;
|
|
1202
1674
|
};
|
|
1203
1675
|
|
|
1676
|
+
/**
|
|
1677
|
+
* Adds a listener for Coinbase onramp order events.
|
|
1678
|
+
*
|
|
1679
|
+
* @param params.listener - The listener function to call when an event is received.
|
|
1680
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1681
|
+
* @returns A function to remove the listener.
|
|
1682
|
+
* @throws {ValueMustBeDefinedError} If the window is not available.
|
|
1683
|
+
* @docs https://docs.cdp.coinbase.com/onramp-&-offramp/onramp-apis/apple-pay-onramp-api#events-names
|
|
1684
|
+
*/ const addCoinbaseOnrampOrderEventListener = ({ listener }, client = constants.getDefaultClient())=>{
|
|
1685
|
+
const core = constants.getCore(client);
|
|
1686
|
+
if (typeof window === 'undefined') {
|
|
1687
|
+
throw new constants.ValueMustBeDefinedError('Window is not available to listen for Coinbase onramp order events');
|
|
1688
|
+
}
|
|
1689
|
+
const handleMessageEvent = (event)=>{
|
|
1690
|
+
if (event.origin !== 'https://pay.coinbase.com') {
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
core.logger.debug('[addCoinbaseOnrampOrderEventListener] pay.coinbase.com event received', {
|
|
1694
|
+
event
|
|
1695
|
+
});
|
|
1696
|
+
try {
|
|
1697
|
+
var _coinbaseOnrampOrderEventData_eventName;
|
|
1698
|
+
const coinbaseOnrampOrderEventData = JSON.parse(event.data);
|
|
1699
|
+
if (!((_coinbaseOnrampOrderEventData_eventName = coinbaseOnrampOrderEventData.eventName) == null ? void 0 : _coinbaseOnrampOrderEventData_eventName.startsWith('onramp_api.'))) {
|
|
1700
|
+
return;
|
|
1701
|
+
}
|
|
1702
|
+
listener({
|
|
1703
|
+
data: coinbaseOnrampOrderEventData.data,
|
|
1704
|
+
eventName: coinbaseOnrampOrderEventData.eventName
|
|
1705
|
+
});
|
|
1706
|
+
} catch (error) {
|
|
1707
|
+
core.logger.debug('[addCoinbaseOnrampOrderEventListener] Failed to parse Coinbase onramp order event data', {
|
|
1708
|
+
error
|
|
1709
|
+
});
|
|
1710
|
+
}
|
|
1711
|
+
};
|
|
1712
|
+
window.addEventListener('message', handleMessageEvent);
|
|
1713
|
+
return ()=>{
|
|
1714
|
+
window.removeEventListener('message', handleMessageEvent);
|
|
1715
|
+
};
|
|
1716
|
+
};
|
|
1717
|
+
|
|
1718
|
+
function _object_without_properties_loose(source, excluded) {
|
|
1719
|
+
if (source == null) return {};
|
|
1720
|
+
var target = {};
|
|
1721
|
+
var sourceKeys = Object.keys(source);
|
|
1722
|
+
var key, i;
|
|
1723
|
+
for(i = 0; i < sourceKeys.length; i++){
|
|
1724
|
+
key = sourceKeys[i];
|
|
1725
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
1726
|
+
target[key] = source[key];
|
|
1727
|
+
}
|
|
1728
|
+
return target;
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
/**
|
|
1732
|
+
* This function is used to get a list of fields that are missing verification for a Coinbase onramp order
|
|
1733
|
+
*
|
|
1734
|
+
* - If the user is missing information for an email or phone number, the field will be returned with the error code MISSING_INFORMATION
|
|
1735
|
+
* - If the user is missing verification for an email or phone number, the field will be returned with the error code MISSING_VERIFICATION
|
|
1736
|
+
* and the existing unverified email or phone number will be included in the data field.
|
|
1737
|
+
* - If the user's phone number has not been verified in the last 60 days, the field will be returned with the error code VERIFICATION_EXPIRED
|
|
1738
|
+
* and the existing phone number will be included in the data field.
|
|
1739
|
+
*
|
|
1740
|
+
* @param params.paymentMethod - The payment method that will be used to create the onramp order
|
|
1741
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1742
|
+
* @returns FieldMissingVerificationForCoinbaseOnramp[] - An array of fields that are missing verification for a Coinbase onramp order
|
|
1743
|
+
* @throws {InvalidParamError} - If the payment method is not valid
|
|
1744
|
+
* @throws {ValueMustBeDefinedError} - If the user is not authenticated
|
|
1745
|
+
*/ const getMissingVerificationForCoinbaseOnrampOrder = ({ paymentMethod }, client = constants.getDefaultClient())=>{
|
|
1746
|
+
// adding the payment method as a param for now just so a user has to pass an object as the first param
|
|
1747
|
+
// that way, when we add more payment methods, we can easily add them to the param object
|
|
1748
|
+
// and not have to change the function signature
|
|
1749
|
+
if (paymentMethod !== 'GUEST_CHECKOUT_APPLE_PAY') {
|
|
1750
|
+
throw new InvalidParamError.InvalidParamError(`Invalid payment method: ${paymentMethod}`);
|
|
1751
|
+
}
|
|
1752
|
+
const { user } = client;
|
|
1753
|
+
constants.assertDefined(user, 'User is not authenticated');
|
|
1754
|
+
const fieldsMissingVerification = [];
|
|
1755
|
+
const emailVerifiedCredential = user.verifiedCredentials.find((credential)=>credential.format === sdkApiCore.JwtVerifiedCredentialFormatEnum.Email);
|
|
1756
|
+
if (!user.email) {
|
|
1757
|
+
// when user has no email at all (verified or not)
|
|
1758
|
+
fieldsMissingVerification.push({
|
|
1759
|
+
errorCode: 'MISSING_INFORMATION',
|
|
1760
|
+
field: 'email'
|
|
1761
|
+
});
|
|
1762
|
+
} else if (!emailVerifiedCredential) {
|
|
1763
|
+
// when user has an email but it is not verified
|
|
1764
|
+
fieldsMissingVerification.push({
|
|
1765
|
+
data: user.email,
|
|
1766
|
+
errorCode: 'MISSING_VERIFICATION',
|
|
1767
|
+
field: 'email'
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1770
|
+
const phoneVerifiedCredential = user.verifiedCredentials.find((credential)=>credential.format === sdkApiCore.JwtVerifiedCredentialFormatEnum.PhoneNumber);
|
|
1771
|
+
const phoneNumberVerifiedInPast60Days = (phoneVerifiedCredential == null ? void 0 : phoneVerifiedCredential.verifiedAt) && phoneVerifiedCredential.verifiedAt >= new Date(Date.now() - 60 * 24 * 60 * 60 * 1000);
|
|
1772
|
+
if (!user.phoneNumber) {
|
|
1773
|
+
// when user has no phone number at all (verified or not)
|
|
1774
|
+
fieldsMissingVerification.push({
|
|
1775
|
+
errorCode: 'MISSING_INFORMATION',
|
|
1776
|
+
field: 'phoneNumber'
|
|
1777
|
+
});
|
|
1778
|
+
} else if (!phoneVerifiedCredential) {
|
|
1779
|
+
// when user has a phone number but it is not verified
|
|
1780
|
+
fieldsMissingVerification.push({
|
|
1781
|
+
data: user.phoneNumber,
|
|
1782
|
+
errorCode: 'MISSING_VERIFICATION',
|
|
1783
|
+
field: 'phoneNumber'
|
|
1784
|
+
});
|
|
1785
|
+
} else if (!phoneNumberVerifiedInPast60Days) {
|
|
1786
|
+
// when user has a verified phone number but it is not verified in the last 60 days
|
|
1787
|
+
fieldsMissingVerification.push({
|
|
1788
|
+
data: user.phoneNumber,
|
|
1789
|
+
errorCode: 'VERIFICATION_EXPIRED',
|
|
1790
|
+
field: 'phoneNumber'
|
|
1791
|
+
});
|
|
1792
|
+
}
|
|
1793
|
+
return fieldsMissingVerification;
|
|
1794
|
+
};
|
|
1795
|
+
|
|
1796
|
+
const validateUserCredentialsForCoinbaseOnrampOrder = (client)=>{
|
|
1797
|
+
const { user } = client;
|
|
1798
|
+
constants.assertDefined(user, 'User is not authenticated');
|
|
1799
|
+
const fieldsMissingVerification = getMissingVerificationForCoinbaseOnrampOrder({
|
|
1800
|
+
paymentMethod: 'GUEST_CHECKOUT_APPLE_PAY'
|
|
1801
|
+
}, client);
|
|
1802
|
+
const missingEmailVerification = fieldsMissingVerification.find((field)=>field.field === 'email');
|
|
1803
|
+
if (missingEmailVerification) {
|
|
1804
|
+
throw new MissingUserVerificationError({
|
|
1805
|
+
informationToVerify: 'email',
|
|
1806
|
+
message: 'User must have a verified email to create a Coinbase onramp order'
|
|
1807
|
+
});
|
|
1808
|
+
}
|
|
1809
|
+
const missingPhoneNumberVerification = fieldsMissingVerification.find((field)=>field.field === 'phoneNumber');
|
|
1810
|
+
if (missingPhoneNumberVerification && missingPhoneNumberVerification.errorCode !== 'VERIFICATION_EXPIRED') {
|
|
1811
|
+
throw new MissingUserVerificationError({
|
|
1812
|
+
informationToVerify: 'phoneNumber',
|
|
1813
|
+
message: 'User must have a verified phone number to create a Coinbase onramp order'
|
|
1814
|
+
});
|
|
1815
|
+
}
|
|
1816
|
+
// this is a requirement for Coinbase Onramp
|
|
1817
|
+
// https://docs.cdp.coinbase.com/api-reference/v2/rest-api/onramp/create-an-onramp-order#body-phone-number-verified-at
|
|
1818
|
+
if (missingPhoneNumberVerification && missingPhoneNumberVerification.errorCode === 'VERIFICATION_EXPIRED') {
|
|
1819
|
+
throw new MissingUserVerificationError({
|
|
1820
|
+
informationToVerify: 'phoneNumber',
|
|
1821
|
+
message: "The user's phone number has not been verified in the last 60 days. Please re-verify the user's phone number"
|
|
1822
|
+
});
|
|
1823
|
+
}
|
|
1824
|
+
return user;
|
|
1825
|
+
};
|
|
1826
|
+
|
|
1827
|
+
/**
|
|
1828
|
+
* Creates a Coinbase onramp order
|
|
1829
|
+
*
|
|
1830
|
+
* @param orderParams CoinbaseCreateOnrampOrderRequest - The parameters for the onramp order.
|
|
1831
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1832
|
+
* @returns The created order
|
|
1833
|
+
* @throws {MissingUserVerificationError} If the user is missing verification for email or phone
|
|
1834
|
+
*/ const createCoinbaseOnrampOrder = async (orderParams, client = constants.getDefaultClient())=>{
|
|
1835
|
+
const user = validateUserCredentialsForCoinbaseOnrampOrder(client);
|
|
1836
|
+
const core = constants.getCore(client);
|
|
1837
|
+
const apiClient = constants.createApiClient({
|
|
1838
|
+
includeMfaToken: true
|
|
1839
|
+
}, client);
|
|
1840
|
+
const { isSandbox } = orderParams, restOrderParams = _object_without_properties_loose(orderParams, [
|
|
1841
|
+
"isSandbox"
|
|
1842
|
+
]);
|
|
1843
|
+
var _orderParams_partnerUserRef;
|
|
1844
|
+
const orderResponse = await apiClient.createCoinbaseOnrampOrder({
|
|
1845
|
+
coinbaseOnrampOrderCreateRequest: constants._extends({}, restOrderParams, {
|
|
1846
|
+
// to create a sandbox order, we need to prefix the partner user ref with 'sandbox-'
|
|
1847
|
+
// https://docs.cdp.coinbase.com/onramp-&-offramp/onramp-apis/apple-pay-onramp-api#testing
|
|
1848
|
+
partnerUserRef: (_orderParams_partnerUserRef = orderParams.partnerUserRef) != null ? _orderParams_partnerUserRef : isSandbox ? `sandbox-${user.id}` : user.id,
|
|
1849
|
+
paymentMethod: orderParams.paymentMethod
|
|
1850
|
+
}),
|
|
1851
|
+
environmentId: core.environmentId
|
|
1852
|
+
});
|
|
1853
|
+
if (!isSandbox || !orderResponse.paymentLink) {
|
|
1854
|
+
return orderResponse;
|
|
1855
|
+
}
|
|
1856
|
+
return constants._extends({}, orderResponse, {
|
|
1857
|
+
paymentLink: constants._extends({}, orderResponse.paymentLink, {
|
|
1858
|
+
url: `${orderResponse.paymentLink.url}&useApplePaySandbox=true`
|
|
1859
|
+
})
|
|
1860
|
+
});
|
|
1861
|
+
};
|
|
1862
|
+
|
|
1863
|
+
/**
|
|
1864
|
+
* Gets a Coinbase buy URL
|
|
1865
|
+
*
|
|
1866
|
+
* @param buyUrlParams CoinbaseOnrampGetBuyUrlRequest - The parameters for the buy URL.
|
|
1867
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1868
|
+
* @returns an object containing the buy URL
|
|
1869
|
+
*/ const getCoinbaseBuyUrl = async (buyUrlParams, client = constants.getDefaultClient())=>{
|
|
1870
|
+
const core = constants.getCore(client);
|
|
1871
|
+
const apiClient = constants.createApiClient({
|
|
1872
|
+
includeMfaToken: true
|
|
1873
|
+
}, client);
|
|
1874
|
+
const response = await apiClient.generateCoinbaseOnrampBuyUrl({
|
|
1875
|
+
coinbaseOnrampGetBuyUrlRequest: buyUrlParams,
|
|
1876
|
+
environmentId: core.environmentId
|
|
1877
|
+
});
|
|
1878
|
+
return response;
|
|
1879
|
+
};
|
|
1880
|
+
|
|
1881
|
+
/**
|
|
1882
|
+
* Creates a crypto.com payment
|
|
1883
|
+
*
|
|
1884
|
+
* @param paymentParams CryptoDotComPaymentCreateRequest - The parameters for the payment.
|
|
1885
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1886
|
+
* @returns The created payment
|
|
1887
|
+
*/ const createCryptoDotComPayment = async (paymentParams, client = constants.getDefaultClient())=>{
|
|
1888
|
+
const core = constants.getCore(client);
|
|
1889
|
+
const apiClient = constants.createApiClient({
|
|
1890
|
+
includeMfaToken: true
|
|
1891
|
+
}, client);
|
|
1892
|
+
const response = await apiClient.createCryptoDotComPayment({
|
|
1893
|
+
cryptoDotComPaymentCreateRequest: constants._extends({}, paymentParams, {
|
|
1894
|
+
// eslint-disable-next-line custom-rules/ban-chain-enum
|
|
1895
|
+
chain: paymentParams.chain
|
|
1896
|
+
}),
|
|
1897
|
+
environmentId: core.environmentId
|
|
1898
|
+
});
|
|
1899
|
+
return response;
|
|
1900
|
+
};
|
|
1901
|
+
|
|
1204
1902
|
/**
|
|
1205
1903
|
* Allows waiting until all modules of the client have been properly initialized
|
|
1206
1904
|
* and are ready for use.
|
|
1207
1905
|
*
|
|
1208
1906
|
* @returns a promise that resolves once the client is fully initialized.
|
|
1209
|
-
*/ const waitForClientInitialized = async (client =
|
|
1210
|
-
const core =
|
|
1907
|
+
*/ const waitForClientInitialized = async (client = constants.getDefaultClient())=>{
|
|
1908
|
+
const core = constants.getCore(client);
|
|
1211
1909
|
await core.initTrack.waitForAll();
|
|
1212
1910
|
};
|
|
1213
1911
|
|
|
@@ -1221,16 +1919,16 @@ const providersRequiringPkce = [
|
|
|
1221
1919
|
* @param params.userFields - The user fields to update.
|
|
1222
1920
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1223
1921
|
* @returns A promise that resolves to OTP verification details if verification is required, or undefined.
|
|
1224
|
-
*/ const updateUser = async ({ userFields }, client =
|
|
1225
|
-
const core =
|
|
1226
|
-
const apiClient =
|
|
1922
|
+
*/ const updateUser = async ({ userFields }, client = constants.getDefaultClient())=>{
|
|
1923
|
+
const core = constants.getCore(client);
|
|
1924
|
+
const apiClient = constants.createApiClient({
|
|
1227
1925
|
includeMfaToken: true
|
|
1228
1926
|
}, client);
|
|
1229
1927
|
const response = await apiClient.updateSelf({
|
|
1230
1928
|
environmentId: core.environmentId,
|
|
1231
1929
|
userFields
|
|
1232
1930
|
});
|
|
1233
|
-
|
|
1931
|
+
getVerifiedCredentialForWalletAccount.updateAuthFromVerifyResponse({
|
|
1234
1932
|
response
|
|
1235
1933
|
}, client);
|
|
1236
1934
|
if (response.emailVerification) {
|
|
@@ -1258,7 +1956,7 @@ const providersRequiringPkce = [
|
|
|
1258
1956
|
*
|
|
1259
1957
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1260
1958
|
* @returns A promise that resolves when the acknowledgment is complete.
|
|
1261
|
-
*/ const acknowledgeRecoveryCodes = async (client =
|
|
1959
|
+
*/ const acknowledgeRecoveryCodes = async (client = constants.getDefaultClient())=>{
|
|
1262
1960
|
return updateUser({
|
|
1263
1961
|
userFields: {
|
|
1264
1962
|
mfaBackupCodeAcknowledgement: sdkApiCore.MfaBackupCodeAcknowledgement.Complete
|
|
@@ -1275,9 +1973,9 @@ const providersRequiringPkce = [
|
|
|
1275
1973
|
* @param params.code - The recovery code to authenticate with.
|
|
1276
1974
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1277
1975
|
* @returns A promise that resolves to the MFA authentication response with token.
|
|
1278
|
-
*/ const authenticateMfaRecoveryCode = async ({ code, createMfaTokenOptions }, client =
|
|
1279
|
-
const core =
|
|
1280
|
-
const apiClient =
|
|
1976
|
+
*/ const authenticateMfaRecoveryCode = async ({ code, createMfaTokenOptions }, client = constants.getDefaultClient())=>{
|
|
1977
|
+
const core = constants.getCore(client);
|
|
1978
|
+
const apiClient = constants.createApiClient({}, client);
|
|
1281
1979
|
try {
|
|
1282
1980
|
const response = await apiClient.authMfaRecovery({
|
|
1283
1981
|
environmentId: core.environmentId,
|
|
@@ -1286,10 +1984,10 @@ const providersRequiringPkce = [
|
|
|
1286
1984
|
createMfaToken: createMfaTokenOptions
|
|
1287
1985
|
}
|
|
1288
1986
|
});
|
|
1289
|
-
|
|
1987
|
+
getVerifiedCredentialForWalletAccount.updateAuthFromVerifyResponse({
|
|
1290
1988
|
response
|
|
1291
1989
|
}, client);
|
|
1292
|
-
|
|
1990
|
+
getVerifiedCredentialForWalletAccount.emitEvent({
|
|
1293
1991
|
args: {
|
|
1294
1992
|
mfaToken: response.mfaToken
|
|
1295
1993
|
},
|
|
@@ -1297,7 +1995,7 @@ const providersRequiringPkce = [
|
|
|
1297
1995
|
}, client);
|
|
1298
1996
|
return response;
|
|
1299
1997
|
} catch (error) {
|
|
1300
|
-
|
|
1998
|
+
getVerifiedCredentialForWalletAccount.emitEvent({
|
|
1301
1999
|
args: {
|
|
1302
2000
|
error
|
|
1303
2001
|
},
|
|
@@ -1307,23 +2005,24 @@ const providersRequiringPkce = [
|
|
|
1307
2005
|
}
|
|
1308
2006
|
};
|
|
1309
2007
|
|
|
1310
|
-
const getPasskeyAuthenticationOptions = async (client)=>{
|
|
1311
|
-
const core =
|
|
1312
|
-
const apiClient =
|
|
2008
|
+
const getPasskeyAuthenticationOptions = async ({ relatedOriginRpId } = {}, client)=>{
|
|
2009
|
+
const core = constants.getCore(client);
|
|
2010
|
+
const apiClient = constants.createApiClient({}, client);
|
|
1313
2011
|
const options = await apiClient.getPasskeyAuthenticationOptions({
|
|
1314
|
-
environmentId: core.environmentId
|
|
2012
|
+
environmentId: core.environmentId,
|
|
2013
|
+
relatedOriginRpId
|
|
1315
2014
|
});
|
|
1316
2015
|
return options;
|
|
1317
2016
|
};
|
|
1318
2017
|
|
|
1319
2018
|
const serverAuthenticatePasskey = async ({ authentication, createMfaToken }, client)=>{
|
|
1320
|
-
const core =
|
|
1321
|
-
const apiClient =
|
|
2019
|
+
const core = constants.getCore(client);
|
|
2020
|
+
const apiClient = constants.createApiClient({}, client);
|
|
1322
2021
|
const response = await apiClient.authenticateMfaPasskeyDevice({
|
|
1323
2022
|
environmentId: core.environmentId,
|
|
1324
|
-
passkeyAuthRequest:
|
|
2023
|
+
passkeyAuthRequest: constants._extends({}, authentication, {
|
|
1325
2024
|
createMfaToken,
|
|
1326
|
-
response:
|
|
2025
|
+
response: constants._extends({}, authentication.response, {
|
|
1327
2026
|
clientDataJson: authentication.response.clientDataJSON
|
|
1328
2027
|
})
|
|
1329
2028
|
})
|
|
@@ -1342,22 +2041,24 @@ const serverAuthenticatePasskey = async ({ authentication, createMfaToken }, cli
|
|
|
1342
2041
|
* @returns A promise that resolves to the MFA authentication response.
|
|
1343
2042
|
* @throws NoWebAuthNSupportError If WebAuthn is not supported by the browser.
|
|
1344
2043
|
* @throws NoPasskeyCredentialsFoundError If no passkey credentials are found.
|
|
1345
|
-
*/ const authenticatePasskeyMFA = async ({ createMfaToken } = {}, client =
|
|
1346
|
-
const core =
|
|
2044
|
+
*/ const authenticatePasskeyMFA = async ({ createMfaToken, relatedOriginRpId } = {}, client = constants.getDefaultClient())=>{
|
|
2045
|
+
const core = constants.getCore(client);
|
|
1347
2046
|
try {
|
|
1348
2047
|
var _options_allowCredentials;
|
|
1349
2048
|
if (!core.passkey.isSupported()) {
|
|
1350
2049
|
throw new NoWebAuthNSupportError();
|
|
1351
2050
|
}
|
|
1352
|
-
const options = await getPasskeyAuthenticationOptions(
|
|
1353
|
-
|
|
2051
|
+
const options = await getPasskeyAuthenticationOptions({
|
|
2052
|
+
relatedOriginRpId
|
|
2053
|
+
}, client);
|
|
2054
|
+
const allowCredentials = (_options_allowCredentials = options.allowCredentials) == null ? void 0 : _options_allowCredentials.map((credential)=>constants._extends({}, credential, {
|
|
1354
2055
|
type: 'public-key'
|
|
1355
2056
|
}));
|
|
1356
2057
|
if (!(allowCredentials == null ? void 0 : allowCredentials.length)) {
|
|
1357
2058
|
throw new NoPasskeyCredentialsFoundError();
|
|
1358
2059
|
}
|
|
1359
2060
|
// Ensure allowCredentials has the required type property
|
|
1360
|
-
const formattedOptions =
|
|
2061
|
+
const formattedOptions = constants._extends({}, options, {
|
|
1361
2062
|
allowCredentials
|
|
1362
2063
|
});
|
|
1363
2064
|
const authentication = await core.passkey.authenticate({
|
|
@@ -1367,10 +2068,10 @@ const serverAuthenticatePasskey = async ({ authentication, createMfaToken }, cli
|
|
|
1367
2068
|
authentication,
|
|
1368
2069
|
createMfaToken
|
|
1369
2070
|
}, client);
|
|
1370
|
-
|
|
2071
|
+
getVerifiedCredentialForWalletAccount.updateAuthFromVerifyResponse({
|
|
1371
2072
|
response
|
|
1372
2073
|
}, client);
|
|
1373
|
-
|
|
2074
|
+
getVerifiedCredentialForWalletAccount.emitEvent({
|
|
1374
2075
|
args: {
|
|
1375
2076
|
mfaToken: response.mfaToken
|
|
1376
2077
|
},
|
|
@@ -1378,7 +2079,7 @@ const serverAuthenticatePasskey = async ({ authentication, createMfaToken }, cli
|
|
|
1378
2079
|
}, client);
|
|
1379
2080
|
return response;
|
|
1380
2081
|
} catch (error) {
|
|
1381
|
-
|
|
2082
|
+
getVerifiedCredentialForWalletAccount.emitEvent({
|
|
1382
2083
|
args: {
|
|
1383
2084
|
error
|
|
1384
2085
|
},
|
|
@@ -1399,9 +2100,9 @@ const serverAuthenticatePasskey = async ({ authentication, createMfaToken }, cli
|
|
|
1399
2100
|
* @param [params.createMfaTokenOptions] - Optional configuration for MFA token creation.
|
|
1400
2101
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1401
2102
|
* @returns A promise that resolves to the MFA authentication response.
|
|
1402
|
-
*/ const authenticateTotpMfaDevice = async ({ deviceId, code, createMfaTokenOptions }, client =
|
|
1403
|
-
const core =
|
|
1404
|
-
const apiClient =
|
|
2103
|
+
*/ const authenticateTotpMfaDevice = async ({ deviceId, code, createMfaTokenOptions }, client = constants.getDefaultClient())=>{
|
|
2104
|
+
const core = constants.getCore(client);
|
|
2105
|
+
const apiClient = constants.createApiClient({}, client);
|
|
1405
2106
|
try {
|
|
1406
2107
|
const response = await apiClient.authMfaTotpDevice({
|
|
1407
2108
|
environmentId: core.environmentId,
|
|
@@ -1411,10 +2112,10 @@ const serverAuthenticatePasskey = async ({ authentication, createMfaToken }, cli
|
|
|
1411
2112
|
id: deviceId
|
|
1412
2113
|
}
|
|
1413
2114
|
});
|
|
1414
|
-
|
|
2115
|
+
getVerifiedCredentialForWalletAccount.updateAuthFromVerifyResponse({
|
|
1415
2116
|
response
|
|
1416
2117
|
}, client);
|
|
1417
|
-
|
|
2118
|
+
getVerifiedCredentialForWalletAccount.emitEvent({
|
|
1418
2119
|
args: {
|
|
1419
2120
|
deviceId,
|
|
1420
2121
|
mfaToken: response.mfaToken
|
|
@@ -1423,7 +2124,7 @@ const serverAuthenticatePasskey = async ({ authentication, createMfaToken }, cli
|
|
|
1423
2124
|
}, client);
|
|
1424
2125
|
return response;
|
|
1425
2126
|
} catch (error) {
|
|
1426
|
-
|
|
2127
|
+
getVerifiedCredentialForWalletAccount.emitEvent({
|
|
1427
2128
|
args: {
|
|
1428
2129
|
deviceId,
|
|
1429
2130
|
error
|
|
@@ -1442,9 +2143,9 @@ const serverAuthenticatePasskey = async ({ authentication, createMfaToken }, cli
|
|
|
1442
2143
|
*
|
|
1443
2144
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1444
2145
|
* @returns A promise that resolves to the newly generated recovery codes.
|
|
1445
|
-
*/ const createNewMfaRecoveryCodes = async (client =
|
|
1446
|
-
const core =
|
|
1447
|
-
const apiClient =
|
|
2146
|
+
*/ const createNewMfaRecoveryCodes = async (client = constants.getDefaultClient())=>{
|
|
2147
|
+
const core = constants.getCore(client);
|
|
2148
|
+
const apiClient = constants.createApiClient({}, client);
|
|
1448
2149
|
return apiClient.createNewRecoveryCodes({
|
|
1449
2150
|
environmentId: core.environmentId
|
|
1450
2151
|
});
|
|
@@ -1460,11 +2161,11 @@ const serverAuthenticatePasskey = async ({ authentication, createMfaToken }, cli
|
|
|
1460
2161
|
* @param params.mfaAuthToken - The MFA authentication token required for device deletion.
|
|
1461
2162
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1462
2163
|
* @returns A promise that resolves when the MFA device is successfully deleted.
|
|
1463
|
-
*/ const deleteMfaDevice = async ({ deviceId, mfaAuthToken }, client =
|
|
1464
|
-
const core =
|
|
1465
|
-
const apiClient =
|
|
1466
|
-
|
|
1467
|
-
|
|
2164
|
+
*/ const deleteMfaDevice = async ({ deviceId, mfaAuthToken }, client = constants.getDefaultClient())=>{
|
|
2165
|
+
const core = constants.getCore(client);
|
|
2166
|
+
const apiClient = constants.createApiClient({}, client);
|
|
2167
|
+
constants.assertDefined(deviceId, 'deviceId is required');
|
|
2168
|
+
constants.assertDefined(mfaAuthToken, 'mfaAuthToken is required');
|
|
1468
2169
|
return apiClient.deleteMfaDevice({
|
|
1469
2170
|
environmentId: core.environmentId,
|
|
1470
2171
|
mfaDeviceId: deviceId,
|
|
@@ -1480,9 +2181,9 @@ const serverAuthenticatePasskey = async ({ authentication, createMfaToken }, cli
|
|
|
1480
2181
|
*
|
|
1481
2182
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1482
2183
|
* @returns A promise that resolves to an array of the user's registered MFA devices.
|
|
1483
|
-
*/ const getMfaDevices = async (client =
|
|
1484
|
-
const core =
|
|
1485
|
-
const apiClient =
|
|
2184
|
+
*/ const getMfaDevices = async (client = constants.getDefaultClient())=>{
|
|
2185
|
+
const core = constants.getCore(client);
|
|
2186
|
+
const apiClient = constants.createApiClient({}, client);
|
|
1486
2187
|
const { devices } = await apiClient.getUserMfaDevices({
|
|
1487
2188
|
environmentId: core.environmentId
|
|
1488
2189
|
});
|
|
@@ -1499,9 +2200,9 @@ const serverAuthenticatePasskey = async ({ authentication, createMfaToken }, cli
|
|
|
1499
2200
|
*
|
|
1500
2201
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1501
2202
|
* @returns A promise that resolves to the user's MFA recovery codes.
|
|
1502
|
-
*/ const getMfaRecoveryCodes = async (client =
|
|
1503
|
-
const core =
|
|
1504
|
-
const apiClient =
|
|
2203
|
+
*/ const getMfaRecoveryCodes = async (client = constants.getDefaultClient())=>{
|
|
2204
|
+
const core = constants.getCore(client);
|
|
2205
|
+
const apiClient = constants.createApiClient({}, client);
|
|
1505
2206
|
return apiClient.getRecoveryCodes({
|
|
1506
2207
|
environmentId: core.environmentId
|
|
1507
2208
|
});
|
|
@@ -1515,9 +2216,9 @@ const serverAuthenticatePasskey = async ({ authentication, createMfaToken }, cli
|
|
|
1515
2216
|
*
|
|
1516
2217
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1517
2218
|
* @returns True if recovery codes are pending acknowledgment, false otherwise.
|
|
1518
|
-
*/ const isPendingRecoveryCodesAcknowledgment = (client =
|
|
2219
|
+
*/ const isPendingRecoveryCodesAcknowledgment = (client = constants.getDefaultClient())=>{
|
|
1519
2220
|
const user = client.user;
|
|
1520
|
-
|
|
2221
|
+
constants.assertDefined(user, 'User not logged in');
|
|
1521
2222
|
return user.mfaBackupCodeAcknowledgement !== sdkApiCore.MfaBackupCodeAcknowledgement.Complete;
|
|
1522
2223
|
};
|
|
1523
2224
|
|
|
@@ -1529,10 +2230,10 @@ const serverAuthenticatePasskey = async ({ authentication, createMfaToken }, cli
|
|
|
1529
2230
|
*
|
|
1530
2231
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1531
2232
|
* @returns True if the user needs additional MFA authentication, false otherwise.
|
|
1532
|
-
*/ const isUserMissingMfaAuth = (client =
|
|
2233
|
+
*/ const isUserMissingMfaAuth = (client = constants.getDefaultClient())=>{
|
|
1533
2234
|
var _user_scope;
|
|
1534
2235
|
const user = client.user;
|
|
1535
|
-
|
|
2236
|
+
constants.assertDefined(user, 'User not logged in');
|
|
1536
2237
|
return Boolean((_user_scope = user.scope) == null ? void 0 : _user_scope.includes('requiresAdditionalAuth'));
|
|
1537
2238
|
};
|
|
1538
2239
|
|
|
@@ -1545,9 +2246,9 @@ const serverAuthenticatePasskey = async ({ authentication, createMfaToken }, cli
|
|
|
1545
2246
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1546
2247
|
* @returns A promise that resolves to the TOTP registration response containing setup information,
|
|
1547
2248
|
* like the secret key and the OTP Auth URI.
|
|
1548
|
-
*/ const registerTotpMfaDevice = async (client =
|
|
1549
|
-
const core =
|
|
1550
|
-
const apiClient =
|
|
2249
|
+
*/ const registerTotpMfaDevice = async (client = constants.getDefaultClient())=>{
|
|
2250
|
+
const core = constants.getCore(client);
|
|
2251
|
+
const apiClient = constants.createApiClient({}, client);
|
|
1551
2252
|
return apiClient.registerTotpMfaDevice({
|
|
1552
2253
|
environmentId: core.environmentId
|
|
1553
2254
|
});
|
|
@@ -1562,10 +2263,10 @@ const serverAuthenticatePasskey = async ({ authentication, createMfaToken }, cli
|
|
|
1562
2263
|
* @param params.deviceId - The unique identifier of the MFA device to set as default.
|
|
1563
2264
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1564
2265
|
* @returns A promise that resolves when the default MFA device is successfully set.
|
|
1565
|
-
*/ const setDefaultMfaDevice = async ({ deviceId }, client =
|
|
1566
|
-
const core =
|
|
1567
|
-
const apiClient =
|
|
1568
|
-
|
|
2266
|
+
*/ const setDefaultMfaDevice = async ({ deviceId }, client = constants.getDefaultClient())=>{
|
|
2267
|
+
const core = constants.getCore(client);
|
|
2268
|
+
const apiClient = constants.createApiClient({}, client);
|
|
2269
|
+
constants.assertDefined(deviceId, 'deviceId is required');
|
|
1569
2270
|
// All that this endpoint does is set the default device to the one provided.
|
|
1570
2271
|
return apiClient.updateUserMfaDevice({
|
|
1571
2272
|
environmentId: core.environmentId,
|
|
@@ -1581,9 +2282,9 @@ const serverAuthenticatePasskey = async ({ authentication, createMfaToken }, cli
|
|
|
1581
2282
|
* @param params.email - The email address to send the OTP to.
|
|
1582
2283
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1583
2284
|
* @returns A promise that resolves to an OTPVerification object containing the email and verification UUID.
|
|
1584
|
-
*/ const sendEmailOTP = async ({ email }, client =
|
|
1585
|
-
const core =
|
|
1586
|
-
const apiClient =
|
|
2285
|
+
*/ const sendEmailOTP = async ({ email }, client = constants.getDefaultClient())=>{
|
|
2286
|
+
const core = constants.getCore(client);
|
|
2287
|
+
const apiClient = constants.createApiClient({}, client);
|
|
1587
2288
|
const { verificationUUID } = await apiClient.createEmailVerification({
|
|
1588
2289
|
emailVerificationCreateRequest: {
|
|
1589
2290
|
captchaToken: getNetworkProviderFromNetworkId.consumeCaptchaToken(client),
|
|
@@ -2528,9 +3229,9 @@ const supportedCountries = {
|
|
|
2528
3229
|
* @param params.phoneNumber - The phone number to send the OTP to.
|
|
2529
3230
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
2530
3231
|
* @returns A promise that resolves to an OTPVerification object containing the phone details and verification UUID.
|
|
2531
|
-
*/ const sendSmsOTP = async ({ isoCountryCode, phoneNumber }, client =
|
|
2532
|
-
const core =
|
|
2533
|
-
const apiClient =
|
|
3232
|
+
*/ const sendSmsOTP = async ({ isoCountryCode, phoneNumber }, client = constants.getDefaultClient())=>{
|
|
3233
|
+
const core = constants.getCore(client);
|
|
3234
|
+
const apiClient = constants.createApiClient({}, client);
|
|
2534
3235
|
const phoneCountryCode = supportedCountries[isoCountryCode].code;
|
|
2535
3236
|
const { verificationUUID } = await apiClient.createSmsVerification({
|
|
2536
3237
|
environmentId: core.environmentId,
|
|
@@ -2550,8 +3251,8 @@ const supportedCountries = {
|
|
|
2550
3251
|
};
|
|
2551
3252
|
|
|
2552
3253
|
const verifyOTPForUserSignIn = async ({ otpVerification, verificationToken }, client)=>{
|
|
2553
|
-
const core =
|
|
2554
|
-
const apiClient =
|
|
3254
|
+
const core = constants.getCore(client);
|
|
3255
|
+
const apiClient = constants.createApiClient({}, client);
|
|
2555
3256
|
const verifyRequest = {
|
|
2556
3257
|
verificationToken,
|
|
2557
3258
|
verificationUUID: otpVerification.verificationUUID
|
|
@@ -2569,8 +3270,8 @@ const verifyOTPForUserSignIn = async ({ otpVerification, verificationToken }, cl
|
|
|
2569
3270
|
};
|
|
2570
3271
|
|
|
2571
3272
|
const verifyOTPForUserUpdate = async ({ otpVerification, verificationToken }, client)=>{
|
|
2572
|
-
const core =
|
|
2573
|
-
const apiClient =
|
|
3273
|
+
const core = constants.getCore(client);
|
|
3274
|
+
const apiClient = constants.createApiClient({}, client);
|
|
2574
3275
|
const verifyRequest = {
|
|
2575
3276
|
verificationToken,
|
|
2576
3277
|
verificationUUID: otpVerification.verificationUUID
|
|
@@ -2596,17 +3297,36 @@ const verifyOTPForUserUpdate = async ({ otpVerification, verificationToken }, cl
|
|
|
2596
3297
|
* @param params.otpVerification - The OTP verification object containing verification details.
|
|
2597
3298
|
* @param params.verificationToken - The token received from the OTP verification process.
|
|
2598
3299
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
2599
|
-
* @returns A promise that resolves to the
|
|
2600
|
-
*/ const verifyOTP = async ({ otpVerification, verificationToken }, client =
|
|
3300
|
+
* @returns A promise that resolves to the verify response object upon successful verification.
|
|
3301
|
+
*/ const verifyOTP = async ({ otpVerification, verificationToken }, client = constants.getDefaultClient())=>{
|
|
2601
3302
|
const verifyOTPFunction = client.user ? verifyOTPForUserUpdate : verifyOTPForUserSignIn;
|
|
2602
3303
|
const response = await verifyOTPFunction({
|
|
2603
3304
|
otpVerification,
|
|
2604
3305
|
verificationToken
|
|
2605
3306
|
}, client);
|
|
2606
|
-
|
|
3307
|
+
getVerifiedCredentialForWalletAccount.updateAuthFromVerifyResponse({
|
|
2607
3308
|
response
|
|
2608
3309
|
}, client);
|
|
2609
|
-
return response
|
|
3310
|
+
return response;
|
|
3311
|
+
};
|
|
3312
|
+
|
|
3313
|
+
/**
|
|
3314
|
+
* Deletes the current user's account permanently.
|
|
3315
|
+
*
|
|
3316
|
+
* This function performs a hard delete of the user account. Upon successful deletion,
|
|
3317
|
+
* the user will be automatically logged out and all authentication data will be cleared.
|
|
3318
|
+
*
|
|
3319
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
3320
|
+
* @returns A promise that resolves when the user account is successfully deleted.
|
|
3321
|
+
*/ const deleteUser = async (client = constants.getDefaultClient())=>{
|
|
3322
|
+
const core = constants.getCore(client);
|
|
3323
|
+
const apiClient = constants.createApiClient({
|
|
3324
|
+
includeMfaToken: true
|
|
3325
|
+
}, client);
|
|
3326
|
+
await apiClient.hardDeleteUser({
|
|
3327
|
+
environmentId: core.environmentId
|
|
3328
|
+
});
|
|
3329
|
+
await logout(client);
|
|
2610
3330
|
};
|
|
2611
3331
|
|
|
2612
3332
|
/**
|
|
@@ -2622,8 +3342,8 @@ const verifyOTPForUserUpdate = async ({ otpVerification, verificationToken }, cl
|
|
|
2622
3342
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
2623
3343
|
* @returns A promise that resolves if the wallet is available for signing.
|
|
2624
3344
|
* @throws WalletAccountNotSelectedError If the wallet account is not currently selected.
|
|
2625
|
-
*/ const assertWalletAccountSigningAvailability = async ({ walletAccount }, client =
|
|
2626
|
-
const walletProvider =
|
|
3345
|
+
*/ const assertWalletAccountSigningAvailability = async ({ walletAccount }, client = constants.getDefaultClient())=>{
|
|
3346
|
+
const walletProvider = getVerifiedCredentialForWalletAccount.getWalletProviderFromWalletAccount({
|
|
2627
3347
|
walletAccount
|
|
2628
3348
|
}, client);
|
|
2629
3349
|
const { addresses } = await walletProvider.getConnectedAddresses();
|
|
@@ -2635,50 +3355,6 @@ const verifyOTPForUserUpdate = async ({ otpVerification, verificationToken }, cl
|
|
|
2635
3355
|
}
|
|
2636
3356
|
};
|
|
2637
3357
|
|
|
2638
|
-
/*
|
|
2639
|
-
In older SDK versions we used to have the concept of "connect-only" vs "connect-and-sign".
|
|
2640
|
-
The only difference in backend is it stores some extra data for connect-only,
|
|
2641
|
-
so we can just default to using it.
|
|
2642
|
-
*/ const createVisit = async ({ walletAccount, authMode = sdkApiCore.AuthModeEnum.Only }, client)=>{
|
|
2643
|
-
const core = logout.getCore(client);
|
|
2644
|
-
const apiClient = logout.createApiClient({}, client);
|
|
2645
|
-
const walletProvider = logout.getWalletProviderFromWalletAccount({
|
|
2646
|
-
walletAccount
|
|
2647
|
-
}, client);
|
|
2648
|
-
try {
|
|
2649
|
-
const connectRequest = {
|
|
2650
|
-
address: walletAccount.address,
|
|
2651
|
-
authMode,
|
|
2652
|
-
// eslint-disable-next-line custom-rules/ban-chain-enum
|
|
2653
|
-
chain: walletProvider.chain,
|
|
2654
|
-
provider: walletProvider.getWalletProviderType(),
|
|
2655
|
-
walletName: walletAccount.walletProviderKey
|
|
2656
|
-
};
|
|
2657
|
-
await apiClient.createVisit({
|
|
2658
|
-
connectRequest,
|
|
2659
|
-
environmentId: core.environmentId
|
|
2660
|
-
});
|
|
2661
|
-
} catch (error) {
|
|
2662
|
-
core.logger.error('Error creating visit', {
|
|
2663
|
-
error
|
|
2664
|
-
});
|
|
2665
|
-
}
|
|
2666
|
-
};
|
|
2667
|
-
|
|
2668
|
-
/**
|
|
2669
|
-
* Updates the unverified wallet account in the client state.
|
|
2670
|
-
*/ const setUnverifiedWalletAccounts = ({ unverifiedWalletAccountsToUpdate }, client)=>{
|
|
2671
|
-
const core = logout.getCore(client);
|
|
2672
|
-
const unverifiedWalletAccountsToUpdateIds = unverifiedWalletAccountsToUpdate.map(({ id })=>id);
|
|
2673
|
-
const filteredUnverifiedWalletAccounts = core.state.get().unverifiedWalletAccounts.filter((unverifiedWalletAccount)=>!unverifiedWalletAccountsToUpdateIds.includes(unverifiedWalletAccount.id));
|
|
2674
|
-
core.state.set({
|
|
2675
|
-
unverifiedWalletAccounts: [
|
|
2676
|
-
...filteredUnverifiedWalletAccounts,
|
|
2677
|
-
...unverifiedWalletAccountsToUpdate
|
|
2678
|
-
]
|
|
2679
|
-
});
|
|
2680
|
-
};
|
|
2681
|
-
|
|
2682
3358
|
/**
|
|
2683
3359
|
* Asserts that a specific wallet provider method is defined, throwing an error if it's not.
|
|
2684
3360
|
* This function acts as a type guard, narrowing the type to ensure the method exists.
|
|
@@ -2703,6 +3379,10 @@ const verifyOTPForUserUpdate = async ({ otpVerification, verificationToken }, cl
|
|
|
2703
3379
|
}
|
|
2704
3380
|
}
|
|
2705
3381
|
|
|
3382
|
+
const getAddressesWithTypesFromConnectionResult = (connectionResult)=>{
|
|
3383
|
+
return connectionResult.addresses.filter((address)=>!!address.address && !!address.type);
|
|
3384
|
+
};
|
|
3385
|
+
|
|
2706
3386
|
/**
|
|
2707
3387
|
* Connects to a wallet provider and returns the connected wallet account.
|
|
2708
3388
|
*
|
|
@@ -2712,70 +3392,69 @@ const verifyOTPForUserUpdate = async ({ otpVerification, verificationToken }, cl
|
|
|
2712
3392
|
* @see connectAndVerifyWithWalletProvider
|
|
2713
3393
|
*
|
|
2714
3394
|
* @param params.walletProviderKey - The unique key identifying the wallet provider to connect to (e.g. 'metamaskevm', 'phantomsol').
|
|
2715
|
-
* @param [params.
|
|
3395
|
+
* @param [params.addToDynamicWalletAccounts] - Whether to add the connected wallet account to the user's wallet accounts. Defaults to true.
|
|
2716
3396
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
2717
3397
|
* @returns A promise that resolves to the connected wallet account.
|
|
2718
3398
|
* @throws NoAddressFoundError If the request to connect was successful but no address is connected to your app.
|
|
2719
|
-
*/ const connectWithWalletProvider = async ({ walletProviderKey,
|
|
2720
|
-
const walletProvider =
|
|
3399
|
+
*/ const connectWithWalletProvider = async ({ walletProviderKey, addToDynamicWalletAccounts = true }, client = constants.getDefaultClient())=>{
|
|
3400
|
+
const walletProvider = getVerifiedCredentialForWalletAccount.getWalletProviderByKey({
|
|
2721
3401
|
walletProviderKey
|
|
2722
3402
|
}, client);
|
|
2723
3403
|
assertWalletProviderMethodDefined(walletProvider, 'connect');
|
|
2724
|
-
const { addresses
|
|
2725
|
-
const currentAddresses =
|
|
3404
|
+
const { addresses } = await walletProvider.connect();
|
|
3405
|
+
const currentAddresses = getVerifiedCredentialForWalletAccount.getWalletAccounts(client).map(({ address })=>address);
|
|
3406
|
+
const mainAddress = (addresses == null ? void 0 : addresses.length) ? addresses[0].address : null;
|
|
2726
3407
|
/**
|
|
2727
3408
|
* This error is thrown in case the wallet has no addresses connected
|
|
2728
3409
|
* to the dapp. Then the error is thrown so the consumer can instruct the
|
|
2729
3410
|
* user on the next steps.
|
|
2730
|
-
*/ if (!
|
|
3411
|
+
*/ if (!mainAddress) {
|
|
2731
3412
|
throw new NoAddressFoundError();
|
|
2732
3413
|
}
|
|
2733
3414
|
const walletAccount = {
|
|
2734
|
-
address:
|
|
3415
|
+
address: mainAddress,
|
|
3416
|
+
addressesWithTypes: getAddressesWithTypesFromConnectionResult({
|
|
3417
|
+
addresses
|
|
3418
|
+
}),
|
|
2735
3419
|
chain: walletProvider.chain,
|
|
2736
|
-
id:
|
|
3420
|
+
id: getVerifiedCredentialForWalletAccount.formatWalletAccountId({
|
|
3421
|
+
address: mainAddress,
|
|
3422
|
+
chain: walletProvider.chain,
|
|
3423
|
+
walletProviderKey
|
|
3424
|
+
}),
|
|
2737
3425
|
lastSelectedAt: null,
|
|
2738
3426
|
verifiedCredentialId: null,
|
|
2739
|
-
walletProviderKey
|
|
3427
|
+
walletProviderKey
|
|
2740
3428
|
};
|
|
2741
|
-
if (currentAddresses.includes(
|
|
3429
|
+
if (currentAddresses.includes(mainAddress)) {
|
|
2742
3430
|
return walletAccount;
|
|
2743
3431
|
}
|
|
2744
|
-
if (
|
|
2745
|
-
setUnverifiedWalletAccounts({
|
|
3432
|
+
if (addToDynamicWalletAccounts) {
|
|
3433
|
+
getNetworkProviderFromNetworkId.setUnverifiedWalletAccounts({
|
|
2746
3434
|
unverifiedWalletAccountsToUpdate: [
|
|
2747
3435
|
walletAccount
|
|
2748
3436
|
]
|
|
2749
3437
|
}, client);
|
|
2750
|
-
|
|
3438
|
+
getVerifiedCredentialForWalletAccount.emitWalletAccountsChangedEvent(client);
|
|
2751
3439
|
/*
|
|
2752
3440
|
* send information to backend to kick off background jobs
|
|
2753
3441
|
* this is an async work, but does not need to be awaited
|
|
2754
|
-
*/ void createVisit({
|
|
3442
|
+
*/ void getNetworkProviderFromNetworkId.createVisit({
|
|
2755
3443
|
walletAccount
|
|
2756
3444
|
}, client);
|
|
2757
3445
|
}
|
|
2758
3446
|
return walletAccount;
|
|
2759
3447
|
};
|
|
2760
3448
|
|
|
2761
|
-
/**
|
|
2762
|
-
* Check if the given value is an Error object
|
|
2763
|
-
*/ const isError = (error)=>error instanceof Error;
|
|
2764
|
-
|
|
2765
|
-
/**
|
|
2766
|
-
* Check if the given value is an Error object with a specific code
|
|
2767
|
-
*/ const isErrorWithCode = (error, code)=>{
|
|
2768
|
-
if (!isError(error)) return false;
|
|
2769
|
-
return 'code' in error && error.code === code;
|
|
2770
|
-
};
|
|
2771
|
-
|
|
2772
3449
|
const getChainIdForAccountVerification = async ({ walletProvider })=>{
|
|
2773
|
-
//
|
|
2774
|
-
//
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
3450
|
+
// for some chains, we don't need to specify a chain id for account verification because it's
|
|
3451
|
+
// not required and it might break the message signature in some wallets (e.g. Trust Wallet SOL)
|
|
3452
|
+
const chainsThatDontNeedChainId = [
|
|
3453
|
+
'BTC',
|
|
3454
|
+
'SOL',
|
|
3455
|
+
'SUI'
|
|
3456
|
+
];
|
|
3457
|
+
if (chainsThatDontNeedChainId.includes(walletProvider.chain)) {
|
|
2779
3458
|
return undefined;
|
|
2780
3459
|
}
|
|
2781
3460
|
const { networkId } = await walletProvider.getActiveNetworkId();
|
|
@@ -2791,21 +3470,22 @@ const getChainIdForAccountVerification = async ({ walletProvider })=>{
|
|
|
2791
3470
|
|
|
2792
3471
|
const getSignInMessage = async ({ walletAccount }, client)=>{
|
|
2793
3472
|
var _core_metadata;
|
|
2794
|
-
const core =
|
|
2795
|
-
const apiClient =
|
|
3473
|
+
const core = constants.getCore(client);
|
|
3474
|
+
const apiClient = constants.createApiClient({}, client);
|
|
2796
3475
|
const appUrl = (_core_metadata = core.metadata) == null ? void 0 : _core_metadata.url;
|
|
2797
|
-
|
|
3476
|
+
constants.assertDefined(appUrl, 'App URL is not set');
|
|
2798
3477
|
const url = new URL(appUrl);
|
|
2799
3478
|
const { nonce } = await apiClient.getNonce({
|
|
2800
3479
|
environmentId: core.environmentId
|
|
2801
3480
|
});
|
|
2802
|
-
|
|
2803
|
-
const walletProvider =
|
|
3481
|
+
constants.assertDefined(nonce, 'Failed to get nonce');
|
|
3482
|
+
const walletProvider = getVerifiedCredentialForWalletAccount.getWalletProviderFromWalletAccount({
|
|
2804
3483
|
walletAccount
|
|
2805
3484
|
}, client);
|
|
3485
|
+
const statement = getNetworkProviderFromNetworkId.createSignInMessageStatement(client);
|
|
2806
3486
|
const messageToSign = await getNetworkProviderFromNetworkId.formatSignInMessage({
|
|
2807
3487
|
address: walletAccount.address,
|
|
2808
|
-
blockchainName:
|
|
3488
|
+
blockchainName: constants.CHAINS_INFO_MAP[walletProvider.chain].blockchainName,
|
|
2809
3489
|
chainId: await getChainIdForAccountVerification({
|
|
2810
3490
|
walletProvider
|
|
2811
3491
|
}),
|
|
@@ -2813,6 +3493,7 @@ const getSignInMessage = async ({ walletAccount }, client)=>{
|
|
|
2813
3493
|
issuedAt: new Date().toISOString(),
|
|
2814
3494
|
nonce,
|
|
2815
3495
|
requestId: core.environmentId,
|
|
3496
|
+
statement,
|
|
2816
3497
|
uri: url.toString()
|
|
2817
3498
|
});
|
|
2818
3499
|
return messageToSign;
|
|
@@ -2827,8 +3508,8 @@ const getSignInMessage = async ({ walletAccount }, client)=>{
|
|
|
2827
3508
|
* @param params.walletAccount - The wallet account to prove ownership of.
|
|
2828
3509
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
2829
3510
|
* @returns A promise that resolves to an object containing the message and signature.
|
|
2830
|
-
*/ const proveWalletAccountOwnership = async ({ walletAccount }, client =
|
|
2831
|
-
const walletProvider =
|
|
3511
|
+
*/ const proveWalletAccountOwnership = async ({ walletAccount }, client = constants.getDefaultClient())=>{
|
|
3512
|
+
const walletProvider = getVerifiedCredentialForWalletAccount.getWalletProviderFromWalletAccount({
|
|
2832
3513
|
walletAccount
|
|
2833
3514
|
}, client);
|
|
2834
3515
|
assertWalletProviderMethodDefined(walletProvider, 'signMessage');
|
|
@@ -2841,22 +3522,29 @@ const getSignInMessage = async ({ walletAccount }, client)=>{
|
|
|
2841
3522
|
});
|
|
2842
3523
|
return {
|
|
2843
3524
|
messageToSign,
|
|
2844
|
-
|
|
3525
|
+
signature
|
|
2845
3526
|
};
|
|
2846
3527
|
};
|
|
2847
3528
|
|
|
2848
3529
|
/**
|
|
2849
3530
|
* Removes an unverified wallet account from the client's state.
|
|
2850
3531
|
*/ const removeUnverifiedWalletAccount = ({ unverifiedWalletAccount }, client)=>{
|
|
2851
|
-
const core =
|
|
3532
|
+
const core = constants.getCore(client);
|
|
3533
|
+
const previousState = core.state.get();
|
|
2852
3534
|
const { unverifiedWalletAccounts } = core.state.get();
|
|
2853
3535
|
const filteredUnverifiedWalletAccounts = unverifiedWalletAccounts.filter((account)=>account.id !== unverifiedWalletAccount.id);
|
|
2854
3536
|
core.state.set({
|
|
2855
3537
|
unverifiedWalletAccounts: filteredUnverifiedWalletAccounts
|
|
2856
3538
|
});
|
|
3539
|
+
/**
|
|
3540
|
+
* We check before raising because the wallet account we are removing might still
|
|
3541
|
+
* be present in wallet accounts due to having been moved to verified credentials.
|
|
3542
|
+
*/ getVerifiedCredentialForWalletAccount.checkAndRaiseWalletAccountsChangedEvent({
|
|
3543
|
+
previousState
|
|
3544
|
+
}, client);
|
|
2857
3545
|
};
|
|
2858
3546
|
|
|
2859
|
-
const isSameAddress = (left, right, chain)=>
|
|
3547
|
+
const isSameAddress = (left, right, chain)=>getVerifiedCredentialForWalletAccount.normalizeAddress(left, chain) === getVerifiedCredentialForWalletAccount.normalizeAddress(right, chain);
|
|
2860
3548
|
|
|
2861
3549
|
/**
|
|
2862
3550
|
* Verifies ownership of a wallet account and adds it to the user's profile.
|
|
@@ -2869,54 +3557,49 @@ const isSameAddress = (left, right, chain)=>logout.normalizeAddress(left, chain)
|
|
|
2869
3557
|
* @returns A promise that resolves to the verified wallet account.
|
|
2870
3558
|
* @throws WalletAccountAlreadyVerifiedError If the wallet is already verified.
|
|
2871
3559
|
* @throws WalletAlreadyLinkedToAnotherUserError If the wallet is linked to another user.
|
|
2872
|
-
*/ const verifyWalletAccount = async ({ walletAccount }, client =
|
|
3560
|
+
*/ const verifyWalletAccount = async ({ walletAccount }, client = constants.getDefaultClient())=>{
|
|
3561
|
+
var _response_user;
|
|
2873
3562
|
if (walletAccount.verifiedCredentialId) {
|
|
2874
3563
|
throw new WalletAccountAlreadyVerifiedError(walletAccount.address);
|
|
2875
3564
|
}
|
|
2876
|
-
const
|
|
2877
|
-
const apiClient = logout.createApiClient({}, client);
|
|
2878
|
-
const walletProvider = logout.getWalletProviderFromWalletAccount({
|
|
3565
|
+
const walletProvider = getVerifiedCredentialForWalletAccount.getWalletProviderFromWalletAccount({
|
|
2879
3566
|
walletAccount
|
|
2880
3567
|
}, client);
|
|
2881
|
-
const {
|
|
3568
|
+
const { messageToSign, signature } = await proveWalletAccountOwnership({
|
|
2882
3569
|
walletAccount
|
|
2883
3570
|
}, client);
|
|
2884
|
-
const
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
*/ removeUnverifiedWalletAccount({
|
|
2902
|
-
unverifiedWalletAccount: walletAccount
|
|
2903
|
-
}, client);
|
|
2904
|
-
/**
|
|
2905
|
-
* Adds the user with the new wallet verified credential
|
|
2906
|
-
* This will add the new verified wallet account to the client`s state
|
|
2907
|
-
*/ getWalletProviderByKey.updateAuthFromVerifyResponse({
|
|
2908
|
-
response
|
|
2909
|
-
}, client);
|
|
2910
|
-
} catch (error) {
|
|
2911
|
-
if (isErrorWithCode(error, 'reassign_wallet_confirm') || isErrorWithCode(error, 'merge_accounts_confirmation')) {
|
|
2912
|
-
throw new WalletAlreadyLinkedToAnotherUserError({
|
|
2913
|
-
cause: error
|
|
2914
|
-
});
|
|
3571
|
+
const response = await getNetworkProviderFromNetworkId.verifySignInMessage({
|
|
3572
|
+
addressesWithTypes: walletAccount.addressesWithTypes,
|
|
3573
|
+
chain: walletAccount.chain,
|
|
3574
|
+
messageToSign,
|
|
3575
|
+
signature,
|
|
3576
|
+
walletAddress: walletAccount.address,
|
|
3577
|
+
walletDisplayName: walletProvider.metadata.displayName,
|
|
3578
|
+
walletProviderType: walletProvider.walletProviderType
|
|
3579
|
+
}, client);
|
|
3580
|
+
const walletVerifiedCredential = (_response_user = response.user) == null ? void 0 : _response_user.verifiedCredentials.find((verifiedCredential)=>{
|
|
3581
|
+
var _verifiedCredential_address;
|
|
3582
|
+
return isSameAddress((_verifiedCredential_address = verifiedCredential.address) != null ? _verifiedCredential_address : '', walletAccount.address, walletAccount.chain);
|
|
3583
|
+
});
|
|
3584
|
+
constants.assertDefined(walletVerifiedCredential, `After verifying, still unable to find verified wallet credential for wallet account ${walletAccount.address} on chain ${walletAccount.chain}`);
|
|
3585
|
+
getNetworkProviderFromNetworkId.updateWalletProviderKeysForVerifiedCredentials({
|
|
3586
|
+
keysToUpdate: {
|
|
3587
|
+
[walletVerifiedCredential.id]: walletProvider.key
|
|
2915
3588
|
}
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
3589
|
+
}, client);
|
|
3590
|
+
/**
|
|
3591
|
+
* Adds the user with the new wallet verified credential
|
|
3592
|
+
* This will add the new verified wallet account to the client`s state
|
|
3593
|
+
*/ getVerifiedCredentialForWalletAccount.updateAuthFromVerifyResponse({
|
|
3594
|
+
response
|
|
3595
|
+
}, client);
|
|
3596
|
+
/**
|
|
3597
|
+
* Remove the now verified wallet account from the unverified wallet accounts
|
|
3598
|
+
*/ removeUnverifiedWalletAccount({
|
|
3599
|
+
unverifiedWalletAccount: walletAccount
|
|
3600
|
+
}, client);
|
|
3601
|
+
const verifiedWalletAccount = getVerifiedCredentialForWalletAccount.getWalletAccounts(client).find(({ address })=>isSameAddress(address, walletAccount.address, walletAccount.chain));
|
|
3602
|
+
constants.assertDefined(verifiedWalletAccount, `Unable to find wallet account ${walletAccount.address} on chain ${walletAccount.chain} for verified credential ${walletVerifiedCredential.id}`);
|
|
2920
3603
|
return verifiedWalletAccount;
|
|
2921
3604
|
};
|
|
2922
3605
|
|
|
@@ -2930,9 +3613,9 @@ const isSameAddress = (left, right, chain)=>logout.normalizeAddress(left, chain)
|
|
|
2930
3613
|
* @param params.walletProviderKey - The unique key identifying the wallet provider to connect to.
|
|
2931
3614
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
2932
3615
|
* @returns A promise that resolves to the connected and verified wallet account.
|
|
2933
|
-
*/ const connectAndVerifyWithWalletProvider = async ({ walletProviderKey }, client =
|
|
3616
|
+
*/ const connectAndVerifyWithWalletProvider = async ({ walletProviderKey }, client = constants.getDefaultClient())=>{
|
|
2934
3617
|
const walletAccount = await connectWithWalletProvider({
|
|
2935
|
-
|
|
3618
|
+
addToDynamicWalletAccounts: false,
|
|
2936
3619
|
walletProviderKey
|
|
2937
3620
|
}, client);
|
|
2938
3621
|
await verifyWalletAccount({
|
|
@@ -2941,7 +3624,7 @@ const isSameAddress = (left, right, chain)=>logout.normalizeAddress(left, chain)
|
|
|
2941
3624
|
/*
|
|
2942
3625
|
* send information to backend to kick off background jobs
|
|
2943
3626
|
* this is an async work, but does not need to be awaited
|
|
2944
|
-
*/ void createVisit({
|
|
3627
|
+
*/ void getNetworkProviderFromNetworkId.createVisit({
|
|
2945
3628
|
authMode: sdkApiCore.AuthModeEnum.AndSign,
|
|
2946
3629
|
walletAccount
|
|
2947
3630
|
}, client);
|
|
@@ -2956,8 +3639,8 @@ const isSameAddress = (left, right, chain)=>logout.normalizeAddress(left, chain)
|
|
|
2956
3639
|
*
|
|
2957
3640
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
2958
3641
|
* @returns An array of wallet provider data including chain, keys, and metadata.
|
|
2959
|
-
*/ const getAvailableWalletProvidersData = (client =
|
|
2960
|
-
const allWalletProviders =
|
|
3642
|
+
*/ const getAvailableWalletProvidersData = (client = constants.getDefaultClient())=>{
|
|
3643
|
+
const allWalletProviders = getVerifiedCredentialForWalletAccount.getWalletProviders(client);
|
|
2961
3644
|
// This is to avoid returning the wallet providers that are connected via different means
|
|
2962
3645
|
// than by the "connect" method — like the Dynamic Waas providers, AA providers, or WalletConnect providers.
|
|
2963
3646
|
const filteredWalletProviders = allWalletProviders.filter((walletProvider)=>Boolean(walletProvider.connect));
|
|
@@ -2965,7 +3648,8 @@ const isSameAddress = (left, right, chain)=>logout.normalizeAddress(left, chain)
|
|
|
2965
3648
|
chain: walletProvider.chain,
|
|
2966
3649
|
groupKey: walletProvider.groupKey,
|
|
2967
3650
|
key: walletProvider.key,
|
|
2968
|
-
metadata: walletProvider.metadata
|
|
3651
|
+
metadata: walletProvider.metadata,
|
|
3652
|
+
walletProviderType: walletProvider.walletProviderType
|
|
2969
3653
|
}));
|
|
2970
3654
|
};
|
|
2971
3655
|
|
|
@@ -2978,13 +3662,54 @@ const isSameAddress = (left, right, chain)=>logout.normalizeAddress(left, chain)
|
|
|
2978
3662
|
* @param params.walletProviderKey - The unique key of the wallet provider to query.
|
|
2979
3663
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
2980
3664
|
* @returns An array of connected wallet addresses.
|
|
2981
|
-
*/ const getConnectedAddresses = ({ walletProviderKey }, client =
|
|
2982
|
-
const walletProvider =
|
|
3665
|
+
*/ const getConnectedAddresses = ({ walletProviderKey }, client = constants.getDefaultClient())=>{
|
|
3666
|
+
const walletProvider = getVerifiedCredentialForWalletAccount.getWalletProviderByKey({
|
|
2983
3667
|
walletProviderKey
|
|
2984
3668
|
}, client);
|
|
2985
3669
|
return walletProvider.getConnectedAddresses();
|
|
2986
3670
|
};
|
|
2987
3671
|
|
|
3672
|
+
const getOwnerWalletAccountForSmartWalletAccount = ({ smartWalletAccount }, client = constants.getDefaultClient())=>{
|
|
3673
|
+
const smartWalletVerifiedCredential = getVerifiedCredentialForWalletAccount.getVerifiedCredentialForWalletAccount({
|
|
3674
|
+
walletAccount: smartWalletAccount
|
|
3675
|
+
}, client);
|
|
3676
|
+
constants.assertDefined(smartWalletVerifiedCredential == null ? void 0 : smartWalletVerifiedCredential.signerRefId, 'Invalid smart wallet account');
|
|
3677
|
+
return getVerifiedCredentialForWalletAccount.getWalletAccounts(client).find((walletAccount)=>walletAccount.verifiedCredentialId === smartWalletVerifiedCredential.signerRefId);
|
|
3678
|
+
};
|
|
3679
|
+
|
|
3680
|
+
const getWalletAccountAddressByType = ({ type, walletAccount })=>{
|
|
3681
|
+
var _walletAccount_addressesWithTypes_find, _walletAccount_addressesWithTypes;
|
|
3682
|
+
return (_walletAccount_addressesWithTypes = walletAccount.addressesWithTypes) == null ? void 0 : (_walletAccount_addressesWithTypes_find = _walletAccount_addressesWithTypes.find((address)=>address.type === type)) == null ? void 0 : _walletAccount_addressesWithTypes_find.address;
|
|
3683
|
+
};
|
|
3684
|
+
|
|
3685
|
+
/**
|
|
3686
|
+
* Retrieves data for a specific wallet provider that can be used for display or connection.
|
|
3687
|
+
*
|
|
3688
|
+
* @param params.walletProviderKey - The key of the wallet provider to retrieve data for.
|
|
3689
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
3690
|
+
* @returns The data for the wallet provider.
|
|
3691
|
+
*/ const getWalletProviderDataByKey = ({ walletProviderKey }, client = constants.getDefaultClient())=>{
|
|
3692
|
+
const { chain, groupKey, key, metadata, walletProviderType } = getVerifiedCredentialForWalletAccount.getWalletProviderByKey({
|
|
3693
|
+
walletProviderKey
|
|
3694
|
+
}, client);
|
|
3695
|
+
return {
|
|
3696
|
+
chain,
|
|
3697
|
+
groupKey,
|
|
3698
|
+
key,
|
|
3699
|
+
metadata,
|
|
3700
|
+
walletProviderType
|
|
3701
|
+
};
|
|
3702
|
+
};
|
|
3703
|
+
|
|
3704
|
+
/**
|
|
3705
|
+
* Checks if a wallet account has been verified by a user.
|
|
3706
|
+
*
|
|
3707
|
+
* @param walletAccount - The wallet account to check.
|
|
3708
|
+
* @returns True if the wallet account has been verified, false otherwise.
|
|
3709
|
+
*/ const isWalletAccountVerified = ({ walletAccount })=>{
|
|
3710
|
+
return walletAccount.verifiedCredentialId !== null;
|
|
3711
|
+
};
|
|
3712
|
+
|
|
2988
3713
|
/**
|
|
2989
3714
|
* Retrieves the network configuration data for the currently active network.
|
|
2990
3715
|
*
|
|
@@ -2995,8 +3720,8 @@ const isSameAddress = (left, right, chain)=>logout.normalizeAddress(left, chain)
|
|
|
2995
3720
|
* @param params.walletAccount - The wallet account to get network data for.
|
|
2996
3721
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
2997
3722
|
* @returns A promise that resolves to the network data, or undefined if not found.
|
|
2998
|
-
*/ const getActiveNetworkData = async ({ walletAccount }, client =
|
|
2999
|
-
const walletProvider =
|
|
3723
|
+
*/ const getActiveNetworkData = async ({ walletAccount }, client = constants.getDefaultClient())=>{
|
|
3724
|
+
const walletProvider = getVerifiedCredentialForWalletAccount.getWalletProviderFromWalletAccount({
|
|
3000
3725
|
walletAccount
|
|
3001
3726
|
}, client);
|
|
3002
3727
|
const { networkId } = await walletProvider.getActiveNetworkId();
|
|
@@ -3013,8 +3738,8 @@ const isSameAddress = (left, right, chain)=>logout.normalizeAddress(left, chain)
|
|
|
3013
3738
|
* @param params.walletAccount - The wallet account to get the network ID for.
|
|
3014
3739
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
3015
3740
|
* @returns A promise that resolves to the active network ID for the wallet account.
|
|
3016
|
-
*/ const getActiveNetworkId = ({ walletAccount }, client =
|
|
3017
|
-
const walletProvider =
|
|
3741
|
+
*/ const getActiveNetworkId = ({ walletAccount }, client = constants.getDefaultClient())=>{
|
|
3742
|
+
const walletProvider = getVerifiedCredentialForWalletAccount.getWalletProviderFromWalletAccount({
|
|
3018
3743
|
walletAccount
|
|
3019
3744
|
}, client);
|
|
3020
3745
|
return walletProvider.getActiveNetworkId();
|
|
@@ -3029,8 +3754,8 @@ const isSameAddress = (left, right, chain)=>logout.normalizeAddress(left, chain)
|
|
|
3029
3754
|
* @param params.walletAccount - The wallet account to get the balance for.
|
|
3030
3755
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
3031
3756
|
* @returns A promise that resolves to an object containing the balance as a string or null.
|
|
3032
|
-
*/ const getBalance = async ({ walletAccount }, client =
|
|
3033
|
-
const walletProvider =
|
|
3757
|
+
*/ const getBalance = async ({ walletAccount }, client = constants.getDefaultClient())=>{
|
|
3758
|
+
const walletProvider = getVerifiedCredentialForWalletAccount.getWalletProviderFromWalletAccount({
|
|
3034
3759
|
walletAccount
|
|
3035
3760
|
}, client);
|
|
3036
3761
|
const { networkId } = await walletProvider.getActiveNetworkId();
|
|
@@ -3054,17 +3779,43 @@ const isSameAddress = (left, right, chain)=>logout.normalizeAddress(left, chain)
|
|
|
3054
3779
|
* @param params.networkId - The specific network ID within the chain.
|
|
3055
3780
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
3056
3781
|
* @returns A promise that resolves to an object containing the balance as a string or null.
|
|
3057
|
-
*/ const getBalanceForAddress = async ({ address, chain, networkId }, client =
|
|
3782
|
+
*/ const getBalanceForAddress = async ({ address, chain, networkId }, client = constants.getDefaultClient())=>{
|
|
3058
3783
|
const networkProvider = getNetworkProviderFromNetworkId.getNetworkProviderFromNetworkId({
|
|
3059
3784
|
chain,
|
|
3060
3785
|
networkId
|
|
3061
3786
|
}, client);
|
|
3062
|
-
|
|
3787
|
+
constants.assertDefined(networkProvider, `No network found for chain ${chain} and network id ${networkId}. Please ensure you've enabled this network in the Dashboard.`);
|
|
3063
3788
|
return networkProvider.getBalance({
|
|
3064
3789
|
address
|
|
3065
3790
|
});
|
|
3066
3791
|
};
|
|
3067
3792
|
|
|
3793
|
+
/**
|
|
3794
|
+
* Retrieves the transaction history for a given wallet address, chain and network.
|
|
3795
|
+
*
|
|
3796
|
+
* This function fetches the transaction history for a specified wallet address and chain,
|
|
3797
|
+
* returning a list of transactions associated with that address along with nextOffset for pagination.
|
|
3798
|
+
*
|
|
3799
|
+
* @param params.address - The wallet address to query transactions for.
|
|
3800
|
+
* @param params.chain - The chain to query transactions for.
|
|
3801
|
+
* @param [params.limit] - The maximum number of transactions to return.
|
|
3802
|
+
* @param params.networkId - The network ID to query transactions for.
|
|
3803
|
+
* @param [params.offset] - The offset to use for pagination.
|
|
3804
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
3805
|
+
* @returns A promise that resolves to the transaction history along with nextOffset for the given wallet address and chain.
|
|
3806
|
+
*/ const getTransactionHistory = async (params, client = constants.getDefaultClient())=>{
|
|
3807
|
+
const core = constants.getCore(client);
|
|
3808
|
+
const apiClient = constants.createApiClient({}, client);
|
|
3809
|
+
const response = await apiClient.getWalletTransactions({
|
|
3810
|
+
address: params.address,
|
|
3811
|
+
// eslint-disable-next-line custom-rules/ban-chain-enum
|
|
3812
|
+
chainName: params.chain,
|
|
3813
|
+
environmentId: core.environmentId,
|
|
3814
|
+
networkId: params.networkId
|
|
3815
|
+
});
|
|
3816
|
+
return response;
|
|
3817
|
+
};
|
|
3818
|
+
|
|
3068
3819
|
/**
|
|
3069
3820
|
* Checks if programmatic network switching is available for a wallet account.
|
|
3070
3821
|
*
|
|
@@ -3074,8 +3825,8 @@ const isSameAddress = (left, right, chain)=>logout.normalizeAddress(left, chain)
|
|
|
3074
3825
|
* @param params.walletAccount - The wallet account to check network switching support for.
|
|
3075
3826
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
3076
3827
|
* @returns True if programmatic network switching is available, false otherwise.
|
|
3077
|
-
*/ const isProgrammaticNetworkSwitchAvailable = ({ walletAccount }, client =
|
|
3078
|
-
const walletProvider =
|
|
3828
|
+
*/ const isProgrammaticNetworkSwitchAvailable = ({ walletAccount }, client = constants.getDefaultClient())=>{
|
|
3829
|
+
const walletProvider = getVerifiedCredentialForWalletAccount.getWalletProviderByKey({
|
|
3079
3830
|
walletProviderKey: walletAccount.walletProviderKey
|
|
3080
3831
|
}, client);
|
|
3081
3832
|
return walletProvider.switchActiveNetwork !== undefined;
|
|
@@ -3092,8 +3843,8 @@ const isSameAddress = (left, right, chain)=>logout.normalizeAddress(left, chain)
|
|
|
3092
3843
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
3093
3844
|
* @returns A promise that resolves when the network switch is complete.
|
|
3094
3845
|
* @throws NetworkSwitchingUnavailableError If the wallet provider doesn't support network switching.
|
|
3095
|
-
*/ const switchActiveNetwork = async ({ networkId, walletAccount }, client =
|
|
3096
|
-
const walletProvider =
|
|
3846
|
+
*/ const switchActiveNetwork = async ({ networkId, walletAccount }, client = constants.getDefaultClient())=>{
|
|
3847
|
+
const walletProvider = getVerifiedCredentialForWalletAccount.getWalletProviderByKey({
|
|
3097
3848
|
walletProviderKey: walletAccount.walletProviderKey
|
|
3098
3849
|
}, client);
|
|
3099
3850
|
if (walletProvider.switchActiveNetwork === undefined) {
|
|
@@ -3110,45 +3861,30 @@ const isSameAddress = (left, right, chain)=>logout.normalizeAddress(left, chain)
|
|
|
3110
3861
|
});
|
|
3111
3862
|
};
|
|
3112
3863
|
|
|
3113
|
-
/**
|
|
3114
|
-
* Get the primary wallet account.
|
|
3115
|
-
* The primary wallet account is the one that was last selected by the user.
|
|
3116
|
-
* This information is stored in both unverified and verified wallet accounts.
|
|
3117
|
-
* This function consolidates this information to determine which wallet was most recently selected.
|
|
3118
|
-
*/ const getPrimaryWalletAccount = (client = logout.getDefaultClient())=>{
|
|
3119
|
-
const walletAccounts = logout.getWalletAccounts(client);
|
|
3120
|
-
const sortedLastSelectedWalletAccounts = walletAccounts.filter((walletAccount)=>Boolean(walletAccount.lastSelectedAt)).sort((a, b)=>b.lastSelectedAt.getTime() - a.lastSelectedAt.getTime());
|
|
3121
|
-
if (sortedLastSelectedWalletAccounts.length === 0) {
|
|
3122
|
-
return null;
|
|
3123
|
-
}
|
|
3124
|
-
const [primaryWalletAccount] = sortedLastSelectedWalletAccounts;
|
|
3125
|
-
return primaryWalletAccount;
|
|
3126
|
-
};
|
|
3127
|
-
|
|
3128
3864
|
/**
|
|
3129
3865
|
* Make the wallet account provided as the primary wallet account.
|
|
3130
|
-
*/ const selectPrimaryWalletAccount = async ({ walletAccount }, client =
|
|
3131
|
-
const core =
|
|
3866
|
+
*/ const selectPrimaryWalletAccount = async ({ walletAccount }, client = constants.getDefaultClient())=>{
|
|
3867
|
+
const core = constants.getCore(client);
|
|
3132
3868
|
const currentPrimaryWalletAccount = getPrimaryWalletAccount(client);
|
|
3133
3869
|
if ((currentPrimaryWalletAccount == null ? void 0 : currentPrimaryWalletAccount.id) === walletAccount.id) {
|
|
3134
3870
|
return;
|
|
3135
3871
|
}
|
|
3136
3872
|
if (walletAccount.verifiedCredentialId) {
|
|
3137
|
-
const apiClient =
|
|
3873
|
+
const apiClient = constants.createApiClient({}, client);
|
|
3138
3874
|
const response = await apiClient.selectUserWallet({
|
|
3139
3875
|
environmentId: core.environmentId,
|
|
3140
3876
|
userWalletSelectionRequest: {
|
|
3141
3877
|
walletId: walletAccount.verifiedCredentialId
|
|
3142
3878
|
}
|
|
3143
3879
|
});
|
|
3144
|
-
|
|
3880
|
+
getVerifiedCredentialForWalletAccount.updateAuthFromVerifyResponse({
|
|
3145
3881
|
response
|
|
3146
3882
|
}, client);
|
|
3147
3883
|
} else {
|
|
3148
|
-
const updatedWalletAccount =
|
|
3884
|
+
const updatedWalletAccount = constants._extends({}, walletAccount, {
|
|
3149
3885
|
lastSelectedAt: new Date()
|
|
3150
3886
|
});
|
|
3151
|
-
setUnverifiedWalletAccounts({
|
|
3887
|
+
getNetworkProviderFromNetworkId.setUnverifiedWalletAccounts({
|
|
3152
3888
|
unverifiedWalletAccountsToUpdate: [
|
|
3153
3889
|
updatedWalletAccount
|
|
3154
3890
|
]
|
|
@@ -3166,9 +3902,22 @@ const isSameAddress = (left, right, chain)=>logout.normalizeAddress(left, chain)
|
|
|
3166
3902
|
* @param params.walletAccount - The wallet account to remove.
|
|
3167
3903
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
3168
3904
|
* @returns A promise that resolves when the wallet account is successfully removed.
|
|
3169
|
-
*/ const removeWalletAccount = async ({ walletAccount }, client =
|
|
3170
|
-
const core =
|
|
3171
|
-
const apiClient =
|
|
3905
|
+
*/ const removeWalletAccount = async ({ walletAccount }, client = constants.getDefaultClient())=>{
|
|
3906
|
+
const core = constants.getCore(client);
|
|
3907
|
+
const apiClient = constants.createApiClient({}, client);
|
|
3908
|
+
try {
|
|
3909
|
+
const walletProvider = getVerifiedCredentialForWalletAccount.getWalletProviderFromWalletAccount({
|
|
3910
|
+
walletAccount
|
|
3911
|
+
}, client);
|
|
3912
|
+
await (walletProvider.disconnectWalletAccount == null ? void 0 : walletProvider.disconnectWalletAccount.call(walletProvider, {
|
|
3913
|
+
walletAccount
|
|
3914
|
+
}));
|
|
3915
|
+
} catch (error) {
|
|
3916
|
+
if (error instanceof getVerifiedCredentialForWalletAccount.NoWalletProviderFoundError) {
|
|
3917
|
+
return;
|
|
3918
|
+
}
|
|
3919
|
+
throw error;
|
|
3920
|
+
}
|
|
3172
3921
|
if (!walletAccount.verifiedCredentialId) {
|
|
3173
3922
|
removeUnverifiedWalletAccount({
|
|
3174
3923
|
unverifiedWalletAccount: walletAccount
|
|
@@ -3181,7 +3930,7 @@ const isSameAddress = (left, right, chain)=>logout.normalizeAddress(left, chain)
|
|
|
3181
3930
|
walletId: walletAccount.verifiedCredentialId
|
|
3182
3931
|
}
|
|
3183
3932
|
});
|
|
3184
|
-
|
|
3933
|
+
getVerifiedCredentialForWalletAccount.updateAuthFromVerifyResponse({
|
|
3185
3934
|
response
|
|
3186
3935
|
}, client);
|
|
3187
3936
|
};
|
|
@@ -3196,8 +3945,8 @@ const isSameAddress = (left, right, chain)=>logout.normalizeAddress(left, chain)
|
|
|
3196
3945
|
* @param params.message - The message to sign.
|
|
3197
3946
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
3198
3947
|
* @returns A promise that resolves to an object containing the signature.
|
|
3199
|
-
*/ const signMessage = async ({ walletAccount, message }, client =
|
|
3200
|
-
const walletProvider =
|
|
3948
|
+
*/ const signMessage = async ({ walletAccount, message }, client = constants.getDefaultClient())=>{
|
|
3949
|
+
const walletProvider = getVerifiedCredentialForWalletAccount.getWalletProviderFromWalletAccount({
|
|
3201
3950
|
walletAccount
|
|
3202
3951
|
}, client);
|
|
3203
3952
|
assertWalletProviderMethodDefined(walletProvider, 'signMessage');
|
|
@@ -3220,8 +3969,8 @@ const isSameAddress = (left, right, chain)=>logout.normalizeAddress(left, chain)
|
|
|
3220
3969
|
* @param params.chain - The blockchain the wallet belongs to.
|
|
3221
3970
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
3222
3971
|
* @returns The matching wallet account, or undefined if not found.
|
|
3223
|
-
*/ const getWalletAccountFromAddress = ({ address, chain }, client =
|
|
3224
|
-
const walletAccounts =
|
|
3972
|
+
*/ const getWalletAccountFromAddress = ({ address, chain }, client = constants.getDefaultClient())=>{
|
|
3973
|
+
const walletAccounts = getVerifiedCredentialForWalletAccount.getWalletAccounts(client);
|
|
3225
3974
|
return walletAccounts.find((walletAccount)=>walletAccount.address === address && walletAccount.chain === chain);
|
|
3226
3975
|
};
|
|
3227
3976
|
|
|
@@ -3234,8 +3983,8 @@ const isSameAddress = (left, right, chain)=>logout.normalizeAddress(left, chain)
|
|
|
3234
3983
|
* @param params.event - The event name to remove the listener from.
|
|
3235
3984
|
* @param params.walletProviderKey - The unique key identifying the wallet provider to remove the listener from.
|
|
3236
3985
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
3237
|
-
*/ const offWalletProviderEvent = ({ callback, event, walletProviderKey }, client =
|
|
3238
|
-
const walletProvider =
|
|
3986
|
+
*/ const offWalletProviderEvent = ({ callback, event, walletProviderKey }, client = constants.getDefaultClient())=>{
|
|
3987
|
+
const walletProvider = getVerifiedCredentialForWalletAccount.getWalletProviderByKey({
|
|
3239
3988
|
walletProviderKey
|
|
3240
3989
|
}, client);
|
|
3241
3990
|
assertWalletProviderMethodDefined(walletProvider, 'events');
|
|
@@ -3252,8 +4001,8 @@ const isSameAddress = (left, right, chain)=>logout.normalizeAddress(left, chain)
|
|
|
3252
4001
|
* @param params.walletProviderKey - The unique key identifying the wallet provider to listen to.
|
|
3253
4002
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
3254
4003
|
* @returns A function that can be called to remove the listener.
|
|
3255
|
-
*/ const onWalletProviderEvent = ({ callback, event, walletProviderKey }, client =
|
|
3256
|
-
const walletProvider =
|
|
4004
|
+
*/ const onWalletProviderEvent = ({ callback, event, walletProviderKey }, client = constants.getDefaultClient())=>{
|
|
4005
|
+
const walletProvider = getVerifiedCredentialForWalletAccount.getWalletProviderByKey({
|
|
3257
4006
|
walletProviderKey
|
|
3258
4007
|
}, client);
|
|
3259
4008
|
assertWalletProviderMethodDefined(walletProvider, 'events');
|
|
@@ -3290,43 +4039,43 @@ const isIPhone = ()=>typeof window === 'undefined' || typeof navigator === 'unde
|
|
|
3290
4039
|
return /iPad/.test(navigator.userAgent) || /Mac/.test(navigator.userAgent) && maxTouchPoints === 5;
|
|
3291
4040
|
};
|
|
3292
4041
|
|
|
3293
|
-
assertPackageVersion.assertPackageVersion(
|
|
3294
|
-
|
|
3295
|
-
exports.BaseError =
|
|
3296
|
-
exports.InvalidExternalAuthError =
|
|
3297
|
-
exports.MfaInvalidOtpError =
|
|
3298
|
-
exports.MfaRateLimitedError =
|
|
3299
|
-
exports.SandboxMaximumThresholdReachedError =
|
|
3300
|
-
exports.
|
|
3301
|
-
exports.getDefaultClient = logout.getDefaultClient;
|
|
3302
|
-
exports.getWalletAccounts = logout.getWalletAccounts;
|
|
3303
|
-
exports.isSignedIn = logout.isSignedIn;
|
|
3304
|
-
exports.logout = logout.logout;
|
|
3305
|
-
exports.offEvent = logout.offEvent;
|
|
3306
|
-
exports.onEvent = logout.onEvent;
|
|
3307
|
-
exports.onceEvent = logout.onceEvent;
|
|
4042
|
+
assertPackageVersion.assertPackageVersion(constants.name, constants.version);
|
|
4043
|
+
|
|
4044
|
+
exports.BaseError = constants.BaseError;
|
|
4045
|
+
exports.InvalidExternalAuthError = constants.InvalidExternalAuthError;
|
|
4046
|
+
exports.MfaInvalidOtpError = constants.MfaInvalidOtpError;
|
|
4047
|
+
exports.MfaRateLimitedError = constants.MfaRateLimitedError;
|
|
4048
|
+
exports.SandboxMaximumThresholdReachedError = constants.SandboxMaximumThresholdReachedError;
|
|
4049
|
+
exports.getDefaultClient = constants.getDefaultClient;
|
|
3308
4050
|
Object.defineProperty(exports, "MFAAction", {
|
|
3309
4051
|
enumerable: true,
|
|
3310
4052
|
get: function () { return sdkApiCore.MFAAction; }
|
|
3311
4053
|
});
|
|
3312
4054
|
exports.NoNetworkProvidersError = getNetworkProviderFromNetworkId.NoNetworkProvidersError;
|
|
4055
|
+
exports.WalletAlreadyLinkedToAnotherUserError = getNetworkProviderFromNetworkId.WalletAlreadyLinkedToAnotherUserError;
|
|
3313
4056
|
exports.getNetworksData = getNetworkProviderFromNetworkId.getNetworksData;
|
|
3314
4057
|
exports.hasExtension = getNetworkProviderFromNetworkId.hasExtension;
|
|
3315
4058
|
exports.isCaptchaRequired = getNetworkProviderFromNetworkId.isCaptchaRequired;
|
|
3316
4059
|
exports.setCaptchaToken = getNetworkProviderFromNetworkId.setCaptchaToken;
|
|
3317
|
-
exports.
|
|
3318
|
-
exports.
|
|
3319
|
-
exports.
|
|
4060
|
+
exports.getWalletAccounts = getVerifiedCredentialForWalletAccount.getWalletAccounts;
|
|
4061
|
+
exports.offEvent = getVerifiedCredentialForWalletAccount.offEvent;
|
|
4062
|
+
exports.onEvent = getVerifiedCredentialForWalletAccount.onEvent;
|
|
4063
|
+
exports.onceEvent = getVerifiedCredentialForWalletAccount.onceEvent;
|
|
3320
4064
|
exports.consumeMfaToken = isMfaRequiredForAction.consumeMfaToken;
|
|
3321
4065
|
exports.getMfaMethods = isMfaRequiredForAction.getMfaMethods;
|
|
3322
4066
|
exports.isMfaRequiredForAction = isMfaRequiredForAction.isMfaRequiredForAction;
|
|
4067
|
+
exports.NotWaasWalletAccountError = NotWaasWalletAccountError.NotWaasWalletAccountError;
|
|
4068
|
+
exports.refreshUser = NotWaasWalletAccountError.refreshUser;
|
|
4069
|
+
exports.InvalidParamError = InvalidParamError.InvalidParamError;
|
|
3323
4070
|
exports.ClientAlreadyInitializedError = ClientAlreadyInitializedError;
|
|
3324
4071
|
exports.InvalidRedirectStorageStateError = InvalidRedirectStorageStateError;
|
|
3325
4072
|
exports.MissingRedirectStorageStateError = MissingRedirectStorageStateError;
|
|
3326
4073
|
exports.MissingSocialUrlParamError = MissingSocialUrlParamError;
|
|
4074
|
+
exports.MissingUserVerificationError = MissingUserVerificationError;
|
|
3327
4075
|
exports.NetworkSwitchingUnavailableError = NetworkSwitchingUnavailableError;
|
|
3328
4076
|
exports.NoAddressFoundError = NoAddressFoundError;
|
|
3329
4077
|
exports.NoPasskeyCredentialsFoundError = NoPasskeyCredentialsFoundError;
|
|
4078
|
+
exports.NoSmartWalletAccountSignerFoundError = NoSmartWalletAccountSignerFoundError;
|
|
3330
4079
|
exports.NoWebAuthNSupportError = NoWebAuthNSupportError;
|
|
3331
4080
|
exports.UnavailableInServerSideError = UnavailableInServerSideError;
|
|
3332
4081
|
exports.UnrecognizedNetworkError = UnrecognizedNetworkError;
|
|
@@ -3334,39 +4083,54 @@ exports.UserNotAuthenticatedError = UserNotAuthenticatedError;
|
|
|
3334
4083
|
exports.UserRejectedError = UserRejectedError;
|
|
3335
4084
|
exports.WalletAccountAlreadyVerifiedError = WalletAccountAlreadyVerifiedError;
|
|
3336
4085
|
exports.WalletAccountNotSelectedError = WalletAccountNotSelectedError;
|
|
3337
|
-
exports.WalletAlreadyLinkedToAnotherUserError = WalletAlreadyLinkedToAnotherUserError;
|
|
3338
4086
|
exports.WalletProviderMethodUnavailableError = WalletProviderMethodUnavailableError;
|
|
3339
4087
|
exports.acknowledgeRecoveryCodes = acknowledgeRecoveryCodes;
|
|
4088
|
+
exports.addCoinbaseOnrampOrderEventListener = addCoinbaseOnrampOrderEventListener;
|
|
3340
4089
|
exports.assertWalletAccountSigningAvailability = assertWalletAccountSigningAvailability;
|
|
3341
4090
|
exports.assertWalletProviderMethodDefined = assertWalletProviderMethodDefined;
|
|
3342
4091
|
exports.authenticateMfaRecoveryCode = authenticateMfaRecoveryCode;
|
|
3343
4092
|
exports.authenticatePasskeyMFA = authenticatePasskeyMFA;
|
|
3344
4093
|
exports.authenticateTotpMfaDevice = authenticateTotpMfaDevice;
|
|
3345
|
-
exports.
|
|
4094
|
+
exports.authenticateWithSocial = authenticateWithSocial;
|
|
4095
|
+
exports.completeSocialAuthentication = completeSocialAuthentication;
|
|
3346
4096
|
exports.connectAndVerifyWithWalletProvider = connectAndVerifyWithWalletProvider;
|
|
3347
4097
|
exports.connectWithWalletProvider = connectWithWalletProvider;
|
|
4098
|
+
exports.createCoinbaseOnrampOrder = createCoinbaseOnrampOrder;
|
|
4099
|
+
exports.createCryptoDotComPayment = createCryptoDotComPayment;
|
|
3348
4100
|
exports.createDynamicClient = createDynamicClient;
|
|
3349
4101
|
exports.createNewMfaRecoveryCodes = createNewMfaRecoveryCodes;
|
|
3350
4102
|
exports.deleteMfaDevice = deleteMfaDevice;
|
|
3351
4103
|
exports.deletePasskey = deletePasskey;
|
|
4104
|
+
exports.deleteUser = deleteUser;
|
|
3352
4105
|
exports.detectOAuthRedirect = detectOAuthRedirect;
|
|
4106
|
+
exports.fetchProjectSettings = fetchProjectSettings;
|
|
3353
4107
|
exports.getActiveNetworkData = getActiveNetworkData;
|
|
3354
4108
|
exports.getActiveNetworkId = getActiveNetworkId;
|
|
3355
4109
|
exports.getAvailableWalletProvidersData = getAvailableWalletProvidersData;
|
|
3356
4110
|
exports.getBalance = getBalance;
|
|
3357
4111
|
exports.getBalanceForAddress = getBalanceForAddress;
|
|
4112
|
+
exports.getCoinbaseBuyUrl = getCoinbaseBuyUrl;
|
|
3358
4113
|
exports.getConnectedAddresses = getConnectedAddresses;
|
|
3359
4114
|
exports.getMfaDevices = getMfaDevices;
|
|
3360
4115
|
exports.getMfaRecoveryCodes = getMfaRecoveryCodes;
|
|
4116
|
+
exports.getMissingVerificationForCoinbaseOnrampOrder = getMissingVerificationForCoinbaseOnrampOrder;
|
|
3361
4117
|
exports.getMultichainBalances = getMultichainBalances;
|
|
4118
|
+
exports.getOwnerWalletAccountForSmartWalletAccount = getOwnerWalletAccountForSmartWalletAccount;
|
|
3362
4119
|
exports.getPasskeys = getPasskeys;
|
|
3363
4120
|
exports.getPrimaryWalletAccount = getPrimaryWalletAccount;
|
|
4121
|
+
exports.getTransactionHistory = getTransactionHistory;
|
|
4122
|
+
exports.getUserSocialAccounts = getUserSocialAccounts;
|
|
4123
|
+
exports.getWalletAccountAddressByType = getWalletAccountAddressByType;
|
|
3364
4124
|
exports.getWalletAccountFromAddress = getWalletAccountFromAddress;
|
|
4125
|
+
exports.getWalletProviderDataByKey = getWalletProviderDataByKey;
|
|
3365
4126
|
exports.initializeClient = initializeClient;
|
|
3366
4127
|
exports.isMobile = isMobile;
|
|
3367
4128
|
exports.isPendingRecoveryCodesAcknowledgment = isPendingRecoveryCodesAcknowledgment;
|
|
3368
4129
|
exports.isProgrammaticNetworkSwitchAvailable = isProgrammaticNetworkSwitchAvailable;
|
|
4130
|
+
exports.isSignedIn = isSignedIn;
|
|
3369
4131
|
exports.isUserMissingMfaAuth = isUserMissingMfaAuth;
|
|
4132
|
+
exports.isWalletAccountVerified = isWalletAccountVerified;
|
|
4133
|
+
exports.logout = logout;
|
|
3370
4134
|
exports.offWalletProviderEvent = offWalletProviderEvent;
|
|
3371
4135
|
exports.onWalletProviderEvent = onWalletProviderEvent;
|
|
3372
4136
|
exports.proveWalletAccountOwnership = proveWalletAccountOwnership;
|
|
@@ -3379,9 +4143,9 @@ exports.sendSmsOTP = sendSmsOTP;
|
|
|
3379
4143
|
exports.setDefaultMfaDevice = setDefaultMfaDevice;
|
|
3380
4144
|
exports.signInWithExternalJwt = signInWithExternalJwt;
|
|
3381
4145
|
exports.signInWithPasskey = signInWithPasskey;
|
|
3382
|
-
exports.signInWithSocialRedirect = signInWithSocialRedirect;
|
|
3383
4146
|
exports.signMessage = signMessage;
|
|
3384
4147
|
exports.switchActiveNetwork = switchActiveNetwork;
|
|
4148
|
+
exports.unlinkSocialAccount = unlinkSocialAccount;
|
|
3385
4149
|
exports.updateUser = updateUser;
|
|
3386
4150
|
exports.verifyOTP = verifyOTP;
|
|
3387
4151
|
exports.verifyWalletAccount = verifyWalletAccount;
|