@dynamic-labs/sdk-react-core 2.1.0-alpha.1 → 2.1.0-alpha.11
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 +92 -0
- package/package.cjs +2 -2
- package/package.js +2 -2
- package/package.json +13 -14
- package/src/index.cjs +8 -2
- package/src/index.d.ts +2 -1
- package/src/index.js +4 -1
- package/src/lib/Main.cjs +7 -0
- package/src/lib/Main.js +7 -0
- package/src/lib/components/Alert/Alert.cjs +2 -2
- package/src/lib/components/Alert/Alert.js +2 -2
- package/src/lib/components/Alert/Alert.types.d.ts +1 -0
- package/src/lib/components/EmailForm/EmailForm.cjs +1 -1
- package/src/lib/components/EmailForm/EmailForm.js +1 -1
- package/src/lib/components/PhoneNumberField/PhoneNumberField.cjs +1 -1
- package/src/lib/components/PhoneNumberField/PhoneNumberField.js +1 -1
- package/src/lib/components/Portal/Portal.cjs +2 -1
- package/src/lib/components/Portal/Portal.js +2 -1
- package/src/lib/components/RadioButton/RadioButton.cjs +14 -0
- package/src/lib/components/RadioButton/RadioButton.d.ts +5 -0
- package/src/lib/components/RadioButton/RadioButton.js +10 -0
- package/src/lib/components/RadioButton/index.d.ts +1 -0
- package/src/lib/components/Tooltip/Tooltip.cjs +2 -1
- package/src/lib/components/Tooltip/Tooltip.js +2 -1
- package/src/lib/components/UserProfile/parts/UserProfileField/UserProfileField.cjs +1 -1
- package/src/lib/components/UserProfile/parts/UserProfileField/UserProfileField.d.ts +2 -1
- package/src/lib/components/UserProfile/parts/UserProfileField/UserProfileField.js +1 -1
- package/src/lib/components/index.d.ts +1 -0
- package/src/lib/context/DynamicContext/DynamicContext.cjs +23 -7
- package/src/lib/context/DynamicContext/DynamicContext.d.ts +5 -0
- package/src/lib/context/DynamicContext/DynamicContext.js +20 -4
- package/src/lib/context/DynamicContext/hooks/useTieCallbacksToEvents/useTieCallbacksToEvents.cjs +2 -2
- package/src/lib/context/DynamicContext/hooks/useTieCallbacksToEvents/useTieCallbacksToEvents.js +2 -2
- package/src/lib/context/DynamicContext/types/index.d.ts +0 -1
- package/src/lib/context/DynamicContext/useCustomerCallbacks/useCustomerCallbacks.cjs +5 -2
- package/src/lib/context/DynamicContext/useCustomerCallbacks/useCustomerCallbacks.js +5 -2
- package/src/lib/context/DynamicContext/useDynamicContext/useDynamicContext.cjs +2 -1
- package/src/lib/context/DynamicContext/useDynamicContext/useDynamicContext.d.ts +1 -1
- package/src/lib/context/DynamicContext/useDynamicContext/useDynamicContext.js +2 -1
- package/src/lib/context/ErrorBoundary/ErrorBoundary.cjs +64 -0
- package/src/lib/context/ErrorBoundary/ErrorBoundary.d.ts +3 -0
- package/src/lib/context/ErrorBoundary/ErrorBoundary.js +60 -0
- package/src/lib/context/ErrorBoundary/ErrorBoundaryBase.cjs +40 -0
- package/src/lib/context/ErrorBoundary/ErrorBoundaryBase.d.ts +14 -0
- package/src/lib/context/ErrorBoundary/ErrorBoundaryBase.js +36 -0
- package/src/lib/context/ErrorBoundary/ErrorBoundaryContext.cjs +24 -0
- package/src/lib/context/ErrorBoundary/ErrorBoundaryContext.d.ts +5 -0
- package/src/lib/context/ErrorBoundary/ErrorBoundaryContext.js +18 -0
- package/src/lib/context/ErrorBoundary/ErrorBoundaryExclude.cjs +17 -0
- package/src/lib/context/ErrorBoundary/ErrorBoundaryExclude.d.ts +4 -0
- package/src/lib/context/ErrorBoundary/ErrorBoundaryExclude.js +13 -0
- package/src/lib/context/ErrorBoundary/ErrorBoundaryInclude.cjs +17 -0
- package/src/lib/context/ErrorBoundary/ErrorBoundaryInclude.d.ts +4 -0
- package/src/lib/context/ErrorBoundary/ErrorBoundaryInclude.js +13 -0
- package/src/lib/context/ErrorBoundary/index.d.ts +3 -0
- package/src/lib/context/ErrorBoundary/types.d.ts +13 -0
- package/src/lib/context/ViewContext/ViewContext.cjs +2 -2
- package/src/lib/context/ViewContext/ViewContext.js +2 -2
- package/src/lib/context/ViewContext/types/index.d.ts +7 -2
- package/src/lib/data/api/chains/balances.cjs +38 -0
- package/src/lib/data/api/chains/balances.d.ts +8 -0
- package/src/lib/data/api/chains/balances.js +34 -0
- package/src/lib/data/api/chains/index.d.ts +1 -0
- package/src/lib/data/api/user/user.cjs +16 -0
- package/src/lib/data/api/user/user.js +16 -1
- package/src/lib/data/api/wallets/wallets.cjs +26 -6
- package/src/lib/data/api/wallets/wallets.d.ts +4 -0
- package/src/lib/data/api/wallets/wallets.js +26 -7
- package/src/lib/events/dynamicEvents.d.ts +1 -1
- package/src/lib/layout/DynamicAuthLayout/Header/header.cjs +6 -0
- package/src/lib/layout/DynamicAuthLayout/Header/header.js +6 -0
- package/src/lib/locale/en/translation.cjs +45 -4
- package/src/lib/locale/en/translation.d.ts +44 -3
- package/src/lib/locale/en/translation.js +45 -4
- package/src/lib/shared/types/dynamicEventsCallbacks.d.ts +2 -1
- package/src/lib/shared/types/general.d.ts +1 -0
- package/src/lib/shared/utils/classes/storage/localStorage.cjs +2 -2
- package/src/lib/shared/utils/classes/storage/localStorage.js +2 -2
- package/src/lib/styles/index.shadow.cjs +1 -1
- package/src/lib/styles/index.shadow.js +1 -1
- package/src/lib/utils/constants/errors.cjs +2 -2
- package/src/lib/utils/constants/errors.d.ts +1 -0
- package/src/lib/utils/constants/errors.js +2 -2
- package/src/lib/utils/functions/addPasskeyIdentifierToWalletConnector/addPasskeyIdentifierToWalletConnector.cjs +14 -0
- package/src/lib/utils/functions/addPasskeyIdentifierToWalletConnector/addPasskeyIdentifierToWalletConnector.d.ts +3 -0
- package/src/lib/utils/functions/addPasskeyIdentifierToWalletConnector/addPasskeyIdentifierToWalletConnector.js +10 -0
- package/src/lib/utils/functions/addPasskeyIdentifierToWalletConnector/index.d.ts +1 -0
- package/src/lib/utils/functions/createUserProfile/createUserProfile.cjs +1 -2
- package/src/lib/utils/functions/createUserProfile/createUserProfile.js +1 -2
- package/src/lib/utils/functions/findEmbeddedWalletFromVerifiedCredentials/findEmbeddedWalletFromVerifiedCredentials.cjs +3 -4
- package/src/lib/utils/functions/findEmbeddedWalletFromVerifiedCredentials/findEmbeddedWalletFromVerifiedCredentials.d.ts +1 -1
- package/src/lib/utils/functions/findEmbeddedWalletFromVerifiedCredentials/findEmbeddedWalletFromVerifiedCredentials.js +4 -5
- package/src/lib/utils/functions/findTurnkeyWallet/findTurnkeyWallet.cjs +12 -9
- package/src/lib/utils/functions/findTurnkeyWallet/findTurnkeyWallet.d.ts +8 -2
- package/src/lib/utils/functions/findTurnkeyWallet/findTurnkeyWallet.js +13 -10
- package/src/lib/utils/functions/findTurnkeyWallet/index.d.ts +1 -1
- package/src/lib/utils/functions/getUserVerifiedCredentialType/getUserVerifiedCredentialType.cjs +5 -5
- package/src/lib/utils/functions/getUserVerifiedCredentialType/getUserVerifiedCredentialType.d.ts +3 -2
- package/src/lib/utils/functions/getUserVerifiedCredentialType/getUserVerifiedCredentialType.js +5 -5
- package/src/lib/utils/functions/hasEmbeddedWallet/hasEmbeddedWallet.cjs +7 -2
- package/src/lib/utils/functions/hasEmbeddedWallet/hasEmbeddedWallet.js +7 -2
- package/src/lib/utils/functions/index.d.ts +2 -1
- package/src/lib/utils/functions/serializeWalletConnectors/index.d.ts +1 -0
- package/src/lib/utils/functions/serializeWalletConnectors/serializeWalletConnectors.cjs +32 -0
- package/src/lib/utils/functions/serializeWalletConnectors/serializeWalletConnectors.d.ts +2 -0
- package/src/lib/utils/functions/serializeWalletConnectors/serializeWalletConnectors.js +28 -0
- package/src/lib/utils/hooks/index.d.ts +2 -0
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.cjs +22 -17
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.js +22 -17
- package/src/lib/utils/hooks/useConfirmationModal/useConfirmationModal.cjs +2 -1
- package/src/lib/utils/hooks/useConfirmationModal/useConfirmationModal.js +2 -1
- package/src/lib/utils/hooks/useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.cjs +22 -18
- package/src/lib/utils/hooks/useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.d.ts +7 -2
- package/src/lib/utils/hooks/useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.js +22 -18
- package/src/lib/utils/hooks/useDynamicLayoutData/useDynamicLayoutData.cjs +8 -0
- package/src/lib/utils/hooks/useDynamicLayoutData/useDynamicLayoutData.js +8 -0
- package/src/lib/utils/hooks/useDynamicScopes/useDynamicScopes.cjs +3 -3
- package/src/lib/utils/hooks/useDynamicScopes/useDynamicScopes.js +3 -3
- package/src/lib/utils/hooks/useElementById/useElementById.cjs +33 -18
- package/src/lib/utils/hooks/useElementById/useElementById.d.ts +3 -1
- package/src/lib/utils/hooks/useElementById/useElementById.js +33 -18
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.cjs +46 -11
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.d.ts +23 -2
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.js +46 -11
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useCoinbaseMPC/useCoinbaseMPC.cjs +6 -6
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useCoinbaseMPC/useCoinbaseMPC.d.ts +1 -1
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useCoinbaseMPC/useCoinbaseMPC.js +6 -6
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useMPCEmbeddedWallet.cjs +13 -9
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useMPCEmbeddedWallet.d.ts +3 -2
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useMPCEmbeddedWallet.js +13 -9
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.cjs +4 -0
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.d.ts +2 -0
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.js +3 -1
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.cjs +192 -50
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.d.ts +26 -8
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.js +197 -55
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useTurnkey/useTurnkey.cjs +45 -18
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useTurnkey/useTurnkey.d.ts +4 -1
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useTurnkey/useTurnkey.js +45 -18
- package/src/lib/utils/hooks/useIsTurnkeyWallet/useIsTurnkeyWallet.cjs +2 -2
- package/src/lib/utils/hooks/useIsTurnkeyWallet/useIsTurnkeyWallet.js +2 -2
- package/src/lib/utils/hooks/useMergeUserAccounts/index.d.ts +1 -0
- package/src/lib/utils/hooks/useMergeUserAccounts/useMergeUserAccounts.cjs +99 -0
- package/src/lib/utils/hooks/useMergeUserAccounts/useMergeUserAccounts.d.ts +4 -0
- package/src/lib/utils/hooks/useMergeUserAccounts/useMergeUserAccounts.js +95 -0
- package/src/lib/utils/hooks/usePasskeyRecovery/usePasskeyRecovery.cjs +2 -1
- package/src/lib/utils/hooks/usePasskeyRecovery/usePasskeyRecovery.js +2 -1
- package/src/lib/utils/hooks/usePrimaryWalletId/usePrimaryWalletId.cjs +13 -4
- package/src/lib/utils/hooks/usePrimaryWalletId/usePrimaryWalletId.d.ts +10 -2
- package/src/lib/utils/hooks/usePrimaryWalletId/usePrimaryWalletId.js +13 -4
- package/src/lib/utils/hooks/useSendDynamicProps/useSendDynamicProps.cjs +6 -13
- package/src/lib/utils/hooks/useSendDynamicProps/useSendDynamicProps.d.ts +1 -3
- package/src/lib/utils/hooks/useSendDynamicProps/useSendDynamicProps.js +6 -12
- package/src/lib/utils/hooks/useTokenBalances/index.d.ts +1 -0
- package/src/lib/utils/hooks/useTokenBalances/useTokenBalances.cjs +141 -0
- package/src/lib/utils/hooks/useTokenBalances/useTokenBalances.d.ts +12 -0
- package/src/lib/utils/hooks/useTokenBalances/useTokenBalances.js +137 -0
- package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.cjs +5 -0
- package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.js +6 -1
- package/src/lib/utils/hooks/useWalletConnectorOptions/useWalletConnectorOptions.cjs +25 -2
- package/src/lib/utils/hooks/useWalletConnectorOptions/useWalletConnectorOptions.js +25 -2
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.cjs +2 -4
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.d.ts +2 -1
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.js +2 -4
- package/src/lib/views/CollectUserDataView/UserDataFields/UserField/UserField.cjs +3 -3
- package/src/lib/views/CollectUserDataView/UserDataFields/UserField/UserField.js +3 -3
- package/src/lib/views/CollectUserDataView/useFields.cjs +1 -0
- package/src/lib/views/CollectUserDataView/useFields.d.ts +2 -0
- package/src/lib/views/CollectUserDataView/useFields.js +1 -0
- package/src/lib/views/EmailVerification/EmailVerification.cjs +38 -11
- package/src/lib/views/EmailVerification/EmailVerification.js +38 -11
- package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/EmbeddedRevealView.cjs +1 -1
- package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/EmbeddedRevealView.js +1 -1
- package/src/lib/views/EmbeddedReveal/utils/turnkeyExport/turnkeyExport.cjs +6 -5
- package/src/lib/views/EmbeddedReveal/utils/turnkeyExport/turnkeyExport.js +6 -5
- package/src/lib/views/MergeUserAccountsConflictsView/MergeUserAccountsConflictsView.cjs +126 -0
- package/src/lib/views/MergeUserAccountsConflictsView/MergeUserAccountsConflictsView.d.ts +6 -0
- package/src/lib/views/MergeUserAccountsConflictsView/MergeUserAccountsConflictsView.js +122 -0
- package/src/lib/views/MergeUserAccountsConflictsView/index.d.ts +1 -0
- package/src/lib/views/MergeUserAccountsView/MergeUserAccountsView.cjs +123 -0
- package/src/lib/views/MergeUserAccountsView/MergeUserAccountsView.d.ts +4 -0
- package/src/lib/views/MergeUserAccountsView/MergeUserAccountsView.js +119 -0
- package/src/lib/views/MergeUserAccountsView/index.d.ts +1 -0
- package/src/lib/views/MergeUserAccountsWithSameEmailView/MergeUserAccountsWithSameEmailView.cjs +3 -3
- package/src/lib/views/MergeUserAccountsWithSameEmailView/MergeUserAccountsWithSameEmailView.js +3 -3
- package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.cjs +2 -3
- package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.js +2 -3
- package/src/lib/views/Passkey/EmbeddedAuthChoiceCards/EmbeddedAuthChoiceCards.cjs +2 -1
- package/src/lib/views/Passkey/EmbeddedAuthChoiceCards/EmbeddedAuthChoiceCards.js +2 -1
- package/src/lib/views/Passkey/PasskeyIntroView/PasskeyIntroView.cjs +9 -9
- package/src/lib/views/Passkey/PasskeyIntroView/PasskeyIntroView.d.ts +6 -1
- package/src/lib/views/Passkey/PasskeyIntroView/PasskeyIntroView.js +9 -9
- package/src/lib/views/Passkey/PasskeyRecovery/InitRecovery/PasskeyInitRecovery.cjs +2 -1
- package/src/lib/views/Passkey/PasskeyRecovery/InitRecovery/PasskeyInitRecovery.js +2 -1
- package/src/lib/views/Passkey/utils/{createEmbeddedWalletWithPasskey/createEmbeddedWalletWithPasskey.cjs → createEmbeddedWalletRequest/createEmbeddedWalletRequest.cjs} +18 -19
- package/src/lib/views/Passkey/utils/{createEmbeddedWalletWithPasskey/createEmbeddedWalletWithPasskey.d.ts → createEmbeddedWalletRequest/createEmbeddedWalletRequest.d.ts} +7 -3
- package/src/lib/views/Passkey/utils/{createEmbeddedWalletWithPasskey/createEmbeddedWalletWithPasskey.js → createEmbeddedWalletRequest/createEmbeddedWalletRequest.js} +18 -19
- package/src/lib/views/Passkey/utils/createEmbeddedWalletRequest/index.d.ts +1 -0
- package/src/lib/views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.cjs +16 -0
- package/src/lib/views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.d.ts +2 -0
- package/src/lib/views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.js +12 -0
- package/src/lib/views/Passkey/utils/findPrimaryEmbeddedChain/index.d.ts +1 -0
- package/src/lib/views/Passkey/utils/index.d.ts +1 -2
- package/src/lib/views/Passkey/utils/passkeyRecovery/passkeyRecovery.cjs +9 -9
- package/src/lib/views/Passkey/utils/passkeyRecovery/passkeyRecovery.js +9 -9
- package/src/lib/views/WalletList/WalletList.cjs +3 -6
- package/src/lib/views/WalletList/WalletList.js +3 -6
- package/src/lib/views/WalletLockedView/WalletLockedView.cjs +2 -8
- package/src/lib/views/WalletLockedView/WalletLockedView.js +2 -8
- package/src/lib/views/viewToComponentMap.cjs +4 -0
- package/src/lib/views/viewToComponentMap.d.ts +6 -2
- package/src/lib/views/viewToComponentMap.js +4 -0
- package/src/lib/widgets/DynamicWidget/components/PromptModal/PromptModal.cjs +2 -1
- package/src/lib/widgets/DynamicWidget/components/PromptModal/PromptModal.js +2 -1
- package/src/lib/widgets/DynamicWidget/hooks/useFetchNameService/useFetchNameService.cjs +1 -1
- package/src/lib/widgets/DynamicWidget/hooks/useFetchNameService/useFetchNameService.js +1 -1
- package/src/lib/utils/functions/isEmbeddedWalletPresent/index.d.ts +0 -1
- package/src/lib/utils/functions/isEmbeddedWalletPresent/isEmbeddedWalletPresent.cjs +0 -19
- package/src/lib/utils/functions/isEmbeddedWalletPresent/isEmbeddedWalletPresent.d.ts +0 -1
- package/src/lib/utils/functions/isEmbeddedWalletPresent/isEmbeddedWalletPresent.js +0 -15
- package/src/lib/views/Passkey/utils/createEmbeddedWalletWithPasskey/index.d.ts +0 -1
- package/src/lib/views/Passkey/utils/createPregeneratedWallet/createPregeneratedWallet.cjs +0 -65
- package/src/lib/views/Passkey/utils/createPregeneratedWallet/createPregeneratedWallet.d.ts +0 -16
- package/src/lib/views/Passkey/utils/createPregeneratedWallet/createPregeneratedWallet.js +0 -61
- package/src/lib/views/Passkey/utils/createPregeneratedWallet/index.d.ts +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../../../../_virtual/_tslib.js';
|
|
3
|
-
import { useCallback
|
|
3
|
+
import { useCallback } from 'react';
|
|
4
|
+
import { JwtVerifiedCredentialFormatEnum } from '@dynamic-labs/sdk-api-core';
|
|
4
5
|
import { DynamicError } from '@dynamic-labs/utils';
|
|
5
6
|
import '../../../../context/DynamicContext/DynamicContext.js';
|
|
6
|
-
import '@dynamic-labs/sdk-api-core';
|
|
7
7
|
import { logger } from '../../../../shared/logger.js';
|
|
8
8
|
import '@dynamic-labs/iconic';
|
|
9
9
|
import '@dynamic-labs/wallet-connector-core';
|
|
@@ -19,17 +19,20 @@ import '../../../../events/dynamicEvents.js';
|
|
|
19
19
|
import '../../../../context/CaptchaContext/CaptchaContext.js';
|
|
20
20
|
import '../../../../context/ErrorContext/ErrorContext.js';
|
|
21
21
|
import { findEmbeddedWalletFromVerifiedCredentials } from '../../../functions/findEmbeddedWalletFromVerifiedCredentials/findEmbeddedWalletFromVerifiedCredentials.js';
|
|
22
|
-
import {
|
|
22
|
+
import { findTurnkeyWalletByPrimaryChain } from '../../../functions/findTurnkeyWallet/findTurnkeyWallet.js';
|
|
23
23
|
import '@dynamic-labs/multi-wallet';
|
|
24
24
|
import { getAuthToken } from '../../../functions/getAuthToken/getAuthToken.js';
|
|
25
25
|
import 'react-international-phone';
|
|
26
26
|
import { getUserWalletsFromVerifiedCredentials } from '../../../functions/getUserWalletsFromVerifiedCredentials/getUserWalletsFromVerifiedCredentials.js';
|
|
27
|
+
import { addPasskeyIdentifierToWalletConnector } from '../../../functions/addPasskeyIdentifierToWalletConnector/addPasskeyIdentifierToWalletConnector.js';
|
|
27
28
|
import 'viem';
|
|
28
29
|
import 'viem/chains';
|
|
29
30
|
import { getEOAWallet } from '../../../functions/getEOAWallet/getEOAWallet.js';
|
|
30
31
|
import '../../../../config/ApiEndpoint.js';
|
|
31
|
-
import { initEmbeddedWalletSession } from '../../../../data/api/embeddedWallets/embeddedWallets.js';
|
|
32
|
+
import { completePasskeyRecovery, getUserPasskeys, initEmbeddedWalletSession } from '../../../../data/api/embeddedWallets/embeddedWallets.js';
|
|
32
33
|
import '../../../../locale/locale.js';
|
|
34
|
+
import { updateJWTAndCreateUserProfile } from '../../../functions/updateJWTAndCreateUserProfile/updateJWTAndCreateUserProfile.js';
|
|
35
|
+
import { getUserVerifiedCredentialType } from '../../../functions/getUserVerifiedCredentialType/getUserVerifiedCredentialType.js';
|
|
33
36
|
import { hasEmbeddedWallet } from '../../../functions/hasEmbeddedWallet/hasEmbeddedWallet.js';
|
|
34
37
|
import { getEmbeddedWalletAuthHandler } from '../../../functions/getEmbeddedWalletAuthHandler/getEmbeddedWalletAuthHandler.js';
|
|
35
38
|
import { getEmbeddedWalletSessionExpiration } from '../../../functions/getEmbeddedWalletSessionExpiration/getEmbeddedWalletSessionExpiration.js';
|
|
@@ -40,13 +43,14 @@ import '../../../../context/VerificationContext/VerificationContext.js';
|
|
|
40
43
|
import 'react-dom';
|
|
41
44
|
import { useElementById } from '../../useElementById/useElementById.js';
|
|
42
45
|
import { useWalletContext } from '../../../../context/WalletContext/WalletContext.js';
|
|
46
|
+
import { useIsTurnkeyWallet } from '../../useIsTurnkeyWallet/useIsTurnkeyWallet.js';
|
|
43
47
|
import { validateUserIsLoggedIn } from '../../../validations/validateUserIsLoggedIn/validateUserIsLoggedIn.js';
|
|
44
48
|
import { validateTurnkeyProviderEnabled } from '../../../validations/validateTurnkeyProviderEnabled/validateTurnkeyProviderEnabled.js';
|
|
45
|
-
import { SESSION_RESTORED, INVALID_REQUEST, INVALID_WALLET_DATA, SESSION_CREATED,
|
|
46
|
-
import { useIsTurnkeyWallet } from '../../useIsTurnkeyWallet/useIsTurnkeyWallet.js';
|
|
49
|
+
import { ACTIVE_SESSION, SESSION_RESTORED, INVALID_REQUEST, INVALID_WALLET_DATA, SESSION_CREATED, USER_NOT_LOGGED_IN, ERROR_SENDING_CODE, CODE_SENT } from '../../../constants/errors.js';
|
|
47
50
|
import { canRestoreEmbeddedWalletSession, restoreEmbeddedWalletSession } from '../../../../views/Passkey/utils/passkeyRecovery/passkeyRecovery.js';
|
|
51
|
+
import { cleanupExport, initExport, exportCredential } from '../../../../views/EmbeddedReveal/utils/turnkeyExport/turnkeyExport.js';
|
|
48
52
|
import { useTurnkey } from './useTurnkey/useTurnkey.js';
|
|
49
|
-
import { iframeContainerId, iframeElementId } from './constants.js';
|
|
53
|
+
import { iframeContainerId, iframeElementId, revealIframeElementId, revealIframeContainerId } from './constants.js';
|
|
50
54
|
import '../../../../context/ThemeContext/ThemeContext.js';
|
|
51
55
|
import '@dynamic-labs/types';
|
|
52
56
|
import 'yup';
|
|
@@ -88,30 +92,47 @@ import '../../../../views/TransactionConfirmationView/helpers/transactionErrorMe
|
|
|
88
92
|
import '../../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.js';
|
|
89
93
|
import { useInternalDynamicContext } from '../../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.js';
|
|
90
94
|
|
|
91
|
-
// Hook exposed to customers
|
|
95
|
+
// Hook exposed to customers
|
|
92
96
|
/**
|
|
97
|
+
*
|
|
93
98
|
* @returns {
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
99
|
+
* createEmbeddedWallet, - creates Secure enclave embedded wallet according to the settings
|
|
100
|
+
* createOrRestoreSession, - creates or restores a embedded wallet session
|
|
101
|
+
* createPasskey, - creates a new passkey both for an existing wallet or a wallet to be created
|
|
102
|
+
* getPasskeys, - gets all passkeys for the user
|
|
103
|
+
* isLoadingEmbeddedWallet, - loading state of the embedded wallet
|
|
104
|
+
* isSessionActive, - checks if the embedded wallet session is active
|
|
105
|
+
* revealEmbeddedWalletKey - export the recovery phrase or private key of the embedded wallet
|
|
106
|
+
* sendOneTimeCode, - sends a one-time code to the user so they can create a session or add a new passkey
|
|
107
|
+
* userHasEmbeddedWallet, - checks if the user has an embedded wallet
|
|
97
108
|
* }
|
|
98
109
|
*/
|
|
99
110
|
const useSecureEnclaveEmbeddedWallet = () => {
|
|
100
|
-
var _a, _b;
|
|
101
|
-
const { projectSettings, onboardingOnlyJwt, primaryWallet, user, environmentId, } = useInternalDynamicContext();
|
|
111
|
+
var _a, _b, _c, _d;
|
|
112
|
+
const { projectSettings, authToken, onboardingOnlyJwt, primaryWallet, user, environmentId, walletConnectorOptions, setUser, } = useInternalDynamicContext();
|
|
102
113
|
const { createTurnkeyWallet } = useTurnkey();
|
|
103
114
|
const { hasRecoveryEmail } = useIsTurnkeyWallet();
|
|
104
|
-
const
|
|
115
|
+
const { createRootElement } = useElementById();
|
|
105
116
|
const { isLoadingEmbeddedWallet, setIsLoadingEmbeddedWallet } = useWalletContext();
|
|
106
117
|
const wallet = getEOAWallet(primaryWallet, (user === null || user === void 0 ? void 0 : user.verifiedCredentials) || []);
|
|
118
|
+
/**
|
|
119
|
+
* Checks if the user has a secure enclave embedded wallet or not
|
|
120
|
+
* @returns boolean
|
|
121
|
+
*/
|
|
107
122
|
const userHasEmbeddedWallet = useCallback(() => hasEmbeddedWallet(getAuthToken() || onboardingOnlyJwt, 'turnkey'), [onboardingOnlyJwt]);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Creates a new secure enclave embedded wallet according to the settings from the dashboard
|
|
125
|
+
* @param chain - optional chain parameter to create the wallet for
|
|
126
|
+
* @param options - optional parameter contained more settings for the wallet creation
|
|
127
|
+
* @returns Promise<Wallet | undefined>
|
|
128
|
+
*/
|
|
129
|
+
const createEmbeddedWallet = useCallback((chains, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
130
|
+
var _e, _f;
|
|
131
|
+
const jwt = (_e = getAuthToken()) !== null && _e !== void 0 ? _e : onboardingOnlyJwt;
|
|
111
132
|
const { decodedJwt } = validateUserIsLoggedIn(jwt);
|
|
112
133
|
const userWaletsCredentials = getUserWalletsFromVerifiedCredentials(jwt);
|
|
113
|
-
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(jwt,
|
|
114
|
-
const isManualMode = ((
|
|
134
|
+
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(jwt, chains);
|
|
135
|
+
const isManualMode = ((_f = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _f === void 0 ? void 0 : _f.automaticEmbeddedWalletCreation) === false;
|
|
115
136
|
// if user has a wallet and it's not embedded,
|
|
116
137
|
// throw error to follow another flow and set up the right wallet
|
|
117
138
|
// However, if the user is in manual mode continue.
|
|
@@ -121,91 +142,209 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
121
142
|
throw new DynamicError('Manual mode must be enabled to create an embedded wallet for this user');
|
|
122
143
|
}
|
|
123
144
|
validateTurnkeyProviderEnabled(projectSettings);
|
|
124
|
-
setIsLoadingEmbeddedWallet(true);
|
|
125
145
|
// TEMP: immediately disable loading state
|
|
126
146
|
setIsLoadingEmbeddedWallet(false);
|
|
127
|
-
|
|
128
|
-
return wallet;
|
|
147
|
+
return createTurnkeyWallet(jwt, decodedJwt, chains, options);
|
|
129
148
|
}), [
|
|
130
149
|
createTurnkeyWallet,
|
|
131
150
|
onboardingOnlyJwt,
|
|
132
151
|
projectSettings,
|
|
133
152
|
setIsLoadingEmbeddedWallet,
|
|
134
153
|
]);
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
154
|
+
/**
|
|
155
|
+
* Creates or restores a secure enclave embedded wallet session
|
|
156
|
+
* If it detects that the session is possible to be restored, it will restore it
|
|
157
|
+
* @param oneTimeCode - optional one-time code parameter. If not informed it tries to restore a session
|
|
158
|
+
* @returns Promise<'session_created' | 'session_restored'> - returns a string indicating the status of the session
|
|
159
|
+
*/
|
|
160
|
+
const createOrRestoreSession = useCallback((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
161
|
+
var _g, _h, _j, _k, _l, _m, _o;
|
|
162
|
+
const jwt = (_g = getAuthToken()) !== null && _g !== void 0 ? _g : onboardingOnlyJwt;
|
|
138
163
|
const { decodedJwt } = validateUserIsLoggedIn(jwt);
|
|
139
164
|
const turnkeyRecoveryHandler = getEmbeddedWalletAuthHandler(wallet === null || wallet === void 0 ? void 0 : wallet.connector);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
165
|
+
if (turnkeyRecoveryHandler.isSessionActive()) {
|
|
166
|
+
return ACTIVE_SESSION;
|
|
167
|
+
}
|
|
168
|
+
const turnkeyAuthIframeContainerRef = createRootElement(iframeContainerId);
|
|
169
|
+
// try to restore session if possible
|
|
170
|
+
if (canRestoreEmbeddedWalletSession((_h = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _h === void 0 ? void 0 : _h.sessionKeyDuration)) {
|
|
143
171
|
try {
|
|
144
|
-
yield restoreEmbeddedWalletSession({
|
|
172
|
+
const sessionRestored = yield restoreEmbeddedWalletSession({
|
|
145
173
|
authToken: jwt,
|
|
146
174
|
iframeContainer: turnkeyAuthIframeContainerRef.current,
|
|
147
175
|
iframeElementId,
|
|
148
|
-
sessionExpiration: getEmbeddedWalletSessionExpiration((
|
|
176
|
+
sessionExpiration: getEmbeddedWalletSessionExpiration((_k = (_j = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _j === void 0 ? void 0 : _j.embeddedWallets) === null || _k === void 0 ? void 0 : _k.sessionKeyDuration),
|
|
149
177
|
wallet: primaryWallet,
|
|
150
178
|
});
|
|
151
|
-
|
|
179
|
+
if (sessionRestored)
|
|
180
|
+
return SESSION_RESTORED;
|
|
152
181
|
}
|
|
153
182
|
catch (err) {
|
|
154
183
|
logger.error('Failed to restore embedded wallet', err);
|
|
155
184
|
}
|
|
156
185
|
}
|
|
157
|
-
|
|
158
|
-
if (!oneTimeCode) {
|
|
186
|
+
if (!(options === null || options === void 0 ? void 0 : options.oneTimeCode)) {
|
|
159
187
|
throw new DynamicError('One-time code is required to create a session.', INVALID_REQUEST);
|
|
160
188
|
}
|
|
189
|
+
// tries to create a new session with the informed one-time code
|
|
161
190
|
// verify user has a turnkey wallet and email VC
|
|
162
191
|
if (!userHasEmbeddedWallet() || !hasRecoveryEmail) {
|
|
163
192
|
throw new DynamicError('User does not have a secure enclave wallet or a verified email', INVALID_WALLET_DATA);
|
|
164
193
|
}
|
|
165
|
-
const organizationId = (
|
|
166
|
-
yield turnkeyRecoveryHandler.verifyRecoveryCode(oneTimeCode, organizationId);
|
|
194
|
+
const organizationId = (_o = (_m = (_l = decodedJwt.verifiedCredentials) === null || _l === void 0 ? void 0 : _l.find(({ walletName }) => walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey'))) === null || _m === void 0 ? void 0 : _m.walletProperties) === null || _o === void 0 ? void 0 : _o.turnkeySubOrganizationId;
|
|
195
|
+
yield turnkeyRecoveryHandler.verifyRecoveryCode(options.oneTimeCode, organizationId);
|
|
167
196
|
const sessionSettings = {
|
|
168
197
|
createdAt: new Date().getTime(),
|
|
169
|
-
emailCode: oneTimeCode,
|
|
198
|
+
emailCode: options.oneTimeCode,
|
|
170
199
|
userId: turnkeyRecoveryHandler.recoveryUserId,
|
|
171
200
|
};
|
|
172
201
|
LocalStorage.setToLS(EMBEDDED_WALLET_SESSION_SETTINGS, sessionSettings);
|
|
173
202
|
return SESSION_CREATED;
|
|
174
203
|
}), [
|
|
204
|
+
createRootElement,
|
|
175
205
|
hasRecoveryEmail,
|
|
176
206
|
onboardingOnlyJwt,
|
|
177
207
|
primaryWallet,
|
|
178
208
|
(_b = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _a === void 0 ? void 0 : _a.embeddedWallets) === null || _b === void 0 ? void 0 : _b.sessionKeyDuration,
|
|
179
|
-
turnkeyAuthIframeContainerRef,
|
|
180
209
|
userHasEmbeddedWallet,
|
|
181
210
|
wallet === null || wallet === void 0 ? void 0 : wallet.connector,
|
|
182
211
|
]);
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
212
|
+
/**
|
|
213
|
+
* Creates a new passkey both for an existing wallet or a wallet to be created
|
|
214
|
+
* @param options - optional parameter to inform a one-time code to create a session,
|
|
215
|
+
* @returns Promise<WebAuthnAttestation>
|
|
216
|
+
*/
|
|
217
|
+
const createPasskey = useCallback((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
218
|
+
var _p, _q;
|
|
219
|
+
const { decodedJwt, jwt } = validateUserIsLoggedIn(getAuthToken() || onboardingOnlyJwt);
|
|
220
|
+
validateTurnkeyProviderEnabled(projectSettings);
|
|
221
|
+
const turnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_p = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _p === void 0 ? void 0 : _p.chainConfigurations, decodedJwt.verifiedCredentials);
|
|
222
|
+
if (!(turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletConnector)) {
|
|
223
|
+
throw new DynamicError('Wallet connector not found', INVALID_WALLET_DATA);
|
|
224
|
+
}
|
|
225
|
+
const walletConnector = turnkeyWallet.walletConnector;
|
|
226
|
+
walletConnector.setEmail(user === null || user === void 0 ? void 0 : user.email);
|
|
227
|
+
if (user && !(user === null || user === void 0 ? void 0 : user.email)) {
|
|
228
|
+
addPasskeyIdentifierToWalletConnector(walletConnector, user);
|
|
189
229
|
}
|
|
190
|
-
|
|
191
|
-
|
|
230
|
+
const hasEmailVC = getUserVerifiedCredentialType(decodedJwt, JwtVerifiedCredentialFormatEnum.Email);
|
|
231
|
+
// return a new passkey if the user doesn't have a wallet yet or
|
|
232
|
+
// none of the requirements to add a passkey to an existing wallet are met
|
|
233
|
+
if (!('id' in turnkeyWallet) || !hasEmailVC) {
|
|
234
|
+
return walletConnector.getWebAuthnAttestation();
|
|
192
235
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
236
|
+
const organizationId = (_q = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletProperties) === null || _q === void 0 ? void 0 : _q.turnkeySubOrganizationId;
|
|
237
|
+
if (!organizationId) {
|
|
238
|
+
throw new DynamicError('No sub organization id found for the wallet', INVALID_WALLET_DATA);
|
|
239
|
+
}
|
|
240
|
+
const turnkAuthenticatorHandler = getEmbeddedWalletAuthHandler(walletConnector);
|
|
241
|
+
// add new passkey to the wallet through an active session
|
|
242
|
+
yield createOrRestoreSession(options);
|
|
243
|
+
const { attestation, challenge, displayName } = yield walletConnector.getWebAuthnAttestation();
|
|
244
|
+
yield turnkAuthenticatorHandler.addPasskeyAuthenticator({
|
|
245
|
+
attestation,
|
|
246
|
+
challenge,
|
|
247
|
+
organizationId,
|
|
248
|
+
});
|
|
249
|
+
const passkeyResponse = yield completePasskeyRecovery({
|
|
250
|
+
attestation: attestation,
|
|
251
|
+
challenge,
|
|
252
|
+
environmentId,
|
|
253
|
+
userJwt: jwt,
|
|
254
|
+
walletId: turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.id,
|
|
255
|
+
});
|
|
256
|
+
const { jwt: updatedJwt, minifiedJwt } = passkeyResponse;
|
|
257
|
+
setUser(updateJWTAndCreateUserProfile(updatedJwt, minifiedJwt));
|
|
258
|
+
return { attestation, challenge, displayName };
|
|
259
|
+
}), [
|
|
260
|
+
createOrRestoreSession,
|
|
261
|
+
environmentId,
|
|
262
|
+
onboardingOnlyJwt,
|
|
263
|
+
projectSettings,
|
|
264
|
+
setUser,
|
|
265
|
+
user,
|
|
266
|
+
walletConnectorOptions,
|
|
267
|
+
]);
|
|
268
|
+
/**
|
|
269
|
+
* Gets all passkeys for the user
|
|
270
|
+
* @returns Promise<Passkey[]>
|
|
271
|
+
*/
|
|
272
|
+
const getPasskeys = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
273
|
+
var _r;
|
|
274
|
+
const { jwt } = validateUserIsLoggedIn((_r = getAuthToken()) !== null && _r !== void 0 ? _r : onboardingOnlyJwt);
|
|
275
|
+
const data = yield getUserPasskeys({
|
|
276
|
+
environmentId: environmentId,
|
|
277
|
+
userJwt: jwt,
|
|
278
|
+
});
|
|
279
|
+
return data.passkeys;
|
|
280
|
+
}), [environmentId, onboardingOnlyJwt]);
|
|
281
|
+
/**
|
|
282
|
+
* Checks if the embedded wallet session is active
|
|
283
|
+
* @returns boolean
|
|
284
|
+
*/
|
|
285
|
+
const isSessionActive = (_d = ((wallet === null || wallet === void 0 ? void 0 : wallet.connector) &&
|
|
286
|
+
'getAuthenticatorHandler' in wallet.connector &&
|
|
287
|
+
((_c = getEmbeddedWalletAuthHandler(wallet.connector)) === null || _c === void 0 ? void 0 : _c.isSessionActive()))) !== null && _d !== void 0 ? _d : false;
|
|
288
|
+
/**
|
|
289
|
+
* export the recovery phrase or private key of the embedded wallet
|
|
290
|
+
* @param options - optional parameter object containing the type of key to reveal 'recoveryPhrase' | 'privateKey'
|
|
291
|
+
* and the html container id to render the iframe into
|
|
292
|
+
* @returns Promise<string> - returns the embedded wallet recovery phrase or private key
|
|
293
|
+
*/
|
|
294
|
+
const revealEmbeddedWalletKey = (_s) => __awaiter(void 0, [_s], void 0, function* ({ type, htmlContainerId, }) {
|
|
295
|
+
var _t, _u;
|
|
296
|
+
if (!user) {
|
|
297
|
+
throw new DynamicError('User is not logged in', USER_NOT_LOGGED_IN);
|
|
298
|
+
}
|
|
299
|
+
yield cleanupExport({
|
|
300
|
+
wallet,
|
|
301
|
+
});
|
|
302
|
+
const turnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_t = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _t === void 0 ? void 0 : _t.chainConfigurations, user === null || user === void 0 ? void 0 : user.verifiedCredentials);
|
|
303
|
+
const turnkeyHDWalletId = (_u = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletProperties) === null || _u === void 0 ? void 0 : _u.turnkeyHDWalletId;
|
|
304
|
+
if (type === 'recoveryPhrase' && !turnkeyHDWalletId) {
|
|
305
|
+
type = 'privateKey';
|
|
306
|
+
}
|
|
307
|
+
const iframeContainerElement = createRootElement(revealIframeElementId, htmlContainerId || revealIframeContainerId);
|
|
308
|
+
// hide the iframe container until the export is done
|
|
309
|
+
// since it will show unrelated turnkey content
|
|
310
|
+
iframeContainerElement.current.style.display = 'none';
|
|
311
|
+
yield initExport({
|
|
312
|
+
iframeContainer: iframeContainerElement.current,
|
|
313
|
+
iframeElementId: revealIframeElementId,
|
|
314
|
+
wallet,
|
|
315
|
+
});
|
|
316
|
+
yield exportCredential({
|
|
317
|
+
address: type === 'privateKey' ? wallet === null || wallet === void 0 ? void 0 : wallet.address : undefined,
|
|
318
|
+
authToken,
|
|
319
|
+
environmentId,
|
|
320
|
+
userEmail: user === null || user === void 0 ? void 0 : user.email,
|
|
321
|
+
wallet,
|
|
322
|
+
});
|
|
323
|
+
// show the iframe container after the export is done
|
|
324
|
+
// to show the exported content only
|
|
325
|
+
iframeContainerElement.current.style.display = 'block';
|
|
326
|
+
return true;
|
|
327
|
+
});
|
|
328
|
+
/**
|
|
329
|
+
* Sends a one-time code to the user so they can create a session or add a new passkey
|
|
330
|
+
* @returns Promise<'code_sent'>
|
|
331
|
+
*/
|
|
332
|
+
const sendOneTimeCode = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
333
|
+
var _v, _w, _x;
|
|
334
|
+
const { jwt, decodedJwt } = validateUserIsLoggedIn((_v = getAuthToken()) !== null && _v !== void 0 ? _v : onboardingOnlyJwt);
|
|
197
335
|
validateTurnkeyProviderEnabled(projectSettings);
|
|
198
|
-
const targetTurnkeyWallet =
|
|
199
|
-
if (!targetTurnkeyWallet || !targetTurnkeyWallet
|
|
336
|
+
const targetTurnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_w = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _w === void 0 ? void 0 : _w.chainConfigurations, decodedJwt.verifiedCredentials);
|
|
337
|
+
if (!targetTurnkeyWallet || !('id' in targetTurnkeyWallet)) {
|
|
200
338
|
throw new DynamicError('User does not have a valid secure enclave wallet', INVALID_WALLET_DATA);
|
|
201
339
|
}
|
|
202
|
-
const turnkeyAuthenticatorHandler = getEmbeddedWalletAuthHandler(
|
|
340
|
+
const turnkeyAuthenticatorHandler = getEmbeddedWalletAuthHandler(targetTurnkeyWallet === null || targetTurnkeyWallet === void 0 ? void 0 : targetTurnkeyWallet.walletConnector);
|
|
203
341
|
const targetTurnkeyWalletId = targetTurnkeyWallet.id;
|
|
204
342
|
const isSessionActive = turnkeyAuthenticatorHandler.isSessionActive();
|
|
205
343
|
if (isSessionActive) {
|
|
206
344
|
throw new DynamicError('Session is active. No need to create a new one', ACTIVE_SESSION);
|
|
207
345
|
}
|
|
208
|
-
const
|
|
346
|
+
const turnkeyAuthIframeContainerRef = createRootElement(iframeContainerId);
|
|
347
|
+
const publicKey = yield turnkeyAuthenticatorHandler.initRecovery('email', turnkeyAuthIframeContainerRef.current, iframeElementId, getEmbeddedWalletSessionExpiration((_x = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _x === void 0 ? void 0 : _x.sessionKeyDuration));
|
|
209
348
|
if (!publicKey) {
|
|
210
349
|
throw new DynamicError(ERROR_SENDING_CODE);
|
|
211
350
|
}
|
|
@@ -219,17 +358,20 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
219
358
|
turnkeyAuthenticatorHandler.recoveryUserId = response.turnkeyUserId;
|
|
220
359
|
return CODE_SENT;
|
|
221
360
|
}), [
|
|
361
|
+
createRootElement,
|
|
222
362
|
environmentId,
|
|
223
363
|
onboardingOnlyJwt,
|
|
224
364
|
projectSettings,
|
|
225
|
-
|
|
226
|
-
wallet === null || wallet === void 0 ? void 0 : wallet.connector,
|
|
365
|
+
walletConnectorOptions,
|
|
227
366
|
]);
|
|
228
367
|
return {
|
|
229
368
|
createEmbeddedWallet,
|
|
230
369
|
createOrRestoreSession,
|
|
370
|
+
createPasskey,
|
|
371
|
+
getPasskeys,
|
|
231
372
|
isLoadingEmbeddedWallet,
|
|
232
373
|
isSessionActive,
|
|
374
|
+
revealEmbeddedWalletKey,
|
|
233
375
|
sendOneTimeCode,
|
|
234
376
|
userHasEmbeddedWallet,
|
|
235
377
|
};
|
|
@@ -40,6 +40,8 @@ require('react-dom');
|
|
|
40
40
|
var useCreateDynamicEmbeddedWalletMutation = require('../../../useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.cjs');
|
|
41
41
|
require('../../../../../context/WalletContext/WalletContext.cjs');
|
|
42
42
|
var smartWallet = require('../../../useWalletConnectors/utils/smartWallet/smartWallet.cjs');
|
|
43
|
+
var findPrimaryEmbeddedChain = require('../../../../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.cjs');
|
|
44
|
+
var findPasskeyEmailWalletConnector = require('../../../../../views/Passkey/utils/findPasskeyEmailWalletConnector/findPasskeyEmailWalletConnector.cjs');
|
|
43
45
|
require('../../../../../context/ThemeContext/ThemeContext.cjs');
|
|
44
46
|
require('@dynamic-labs/types');
|
|
45
47
|
require('yup');
|
|
@@ -86,11 +88,13 @@ const useTurnkey = () => {
|
|
|
86
88
|
const { projectSettings, setPrimaryWalletId, walletConnectorOptions, setShowAuthFlow, environmentId, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
87
89
|
const { setView } = ViewContext.useViewContext();
|
|
88
90
|
const { createDynamicEmbeddedWalletMutation } = useCreateDynamicEmbeddedWalletMutation.useCreateDynamicEmbeddedWalletMutation();
|
|
89
|
-
const
|
|
91
|
+
const startHeadlessEmbeddedWalletCreationFlow = React.useCallback((jwt, decodedJwt, chains, options) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
90
92
|
yield createDynamicEmbeddedWalletMutation({
|
|
91
93
|
authToken: jwt,
|
|
94
|
+
chains,
|
|
92
95
|
decodedJwt,
|
|
93
96
|
environmentId,
|
|
97
|
+
options,
|
|
94
98
|
walletConnectorOptions,
|
|
95
99
|
withAuthenticator: false,
|
|
96
100
|
});
|
|
@@ -105,12 +109,12 @@ const useTurnkey = () => {
|
|
|
105
109
|
walletConnectorOptions,
|
|
106
110
|
setShowAuthFlow,
|
|
107
111
|
]);
|
|
108
|
-
const
|
|
112
|
+
const startPasskeyEmbeddedWalletCreationFlow = React.useCallback((chains) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
109
113
|
setShowAuthFlow(true, {
|
|
110
114
|
ignoreIfIsEmbeddedWidget: false,
|
|
111
115
|
performMultiWalletChecks: false,
|
|
112
116
|
});
|
|
113
|
-
setView('passkey-intro');
|
|
117
|
+
setView('passkey-intro', { chains });
|
|
114
118
|
return new Promise((resolve, reject) => {
|
|
115
119
|
dynamicEvents.dynamicEvents.once('embeddedWalletCreated', (wallet) => resolve(wallet));
|
|
116
120
|
dynamicEvents.dynamicEvents.once('embeddedWalletFailed', (error) => {
|
|
@@ -159,27 +163,49 @@ const useTurnkey = () => {
|
|
|
159
163
|
};
|
|
160
164
|
return Promise.resolve(passkeyWallet);
|
|
161
165
|
}), [setPrimaryWalletId, walletConnectorOptions]);
|
|
162
|
-
const createTurnkeyWallet = React.useCallback((jwt, decodedJwt,
|
|
163
|
-
var _e, _f;
|
|
166
|
+
const createTurnkeyWallet = React.useCallback((jwt, decodedJwt, chains, options) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
167
|
+
var _e, _f, _g, _h;
|
|
164
168
|
const isManualMode = ((_e = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _e === void 0 ? void 0 : _e.automaticEmbeddedWalletCreation) === false;
|
|
165
|
-
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials.findEmbeddedWalletFromVerifiedCredentials(jwt,
|
|
166
|
-
const
|
|
169
|
+
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials.findEmbeddedWalletFromVerifiedCredentials(jwt, chains);
|
|
170
|
+
const userWalletsCredentials = getUserWalletsFromVerifiedCredentials.getUserWalletsFromVerifiedCredentials(jwt);
|
|
167
171
|
// If the user doesn't have a wallet, or if the customer is in Manual
|
|
168
172
|
// Mode, we should attempt to create a new wallet. Note that if in manual
|
|
169
173
|
// mode, the check for the existance of an embedded wallet was arbitrarily
|
|
170
174
|
// added as a safeguard given the pre-existing condition we're overriding.
|
|
171
|
-
if (!(
|
|
175
|
+
if (!(userWalletsCredentials === null || userWalletsCredentials === void 0 ? void 0 : userWalletsCredentials.length) ||
|
|
172
176
|
(!embeddedWalletVerifiedCredential && isManualMode)) {
|
|
173
177
|
const hasEmailVC = getUserVerifiedCredentialType.getUserVerifiedCredentialType(decodedJwt, sdkApiCore.JwtVerifiedCredentialFormatEnum.Email);
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
178
|
+
if ((!((_f = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _f === void 0 ? void 0 : _f.forceAuthenticatorAtSignup) &&
|
|
179
|
+
hasEmailVC) ||
|
|
180
|
+
(options === null || options === void 0 ? void 0 : options.webAuthnAttestation)) {
|
|
181
|
+
// create embedded wallet fully headless
|
|
182
|
+
return startHeadlessEmbeddedWalletCreationFlow(jwt, decodedJwt, chains, options);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
// show the passkey view to create an embedded wallet
|
|
186
|
+
return startPasskeyEmbeddedWalletCreationFlow(chains);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
// the pregenerated wallet must have been created at this point in the
|
|
191
|
+
// backend if this called as part of a new user sign up.
|
|
192
|
+
if (embeddedWalletVerifiedCredential &&
|
|
193
|
+
decodedJwt.newUser &&
|
|
194
|
+
((_g = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _g === void 0 ? void 0 : _g.automaticEmbeddedWalletCreation)) {
|
|
195
|
+
const walletConnector = findPasskeyEmailWalletConnector.findPasskeyEmailWalletConnector(walletConnectorOptions, findPrimaryEmbeddedChain.findPrimaryEmbeddedChain(projectSettings));
|
|
196
|
+
if (!walletConnector) {
|
|
197
|
+
throw new Error('Could not find the Embedded wallet connector');
|
|
198
|
+
}
|
|
199
|
+
const wallet = {
|
|
200
|
+
address: (yield walletConnector.getAddress()) || '',
|
|
201
|
+
authenticated: Boolean((_h = embeddedWalletVerifiedCredential === null || embeddedWalletVerifiedCredential === void 0 ? void 0 : embeddedWalletVerifiedCredential.walletProperties) === null || _h === void 0 ? void 0 : _h.isAuthenticatorAttached),
|
|
202
|
+
chain: walletConnector.connectedChain || '',
|
|
203
|
+
connected: true,
|
|
204
|
+
connector: walletConnector,
|
|
205
|
+
id: embeddedWalletVerifiedCredential.id,
|
|
206
|
+
};
|
|
207
|
+
dynamicEvents.dynamicEvents.emit('embeddedWalletCreated', wallet, embeddedWalletVerifiedCredential, jwt);
|
|
180
208
|
}
|
|
181
|
-
// show the passkey view to create an embedded wallet
|
|
182
|
-
return startEmbeddedWalletCreationFlow();
|
|
183
209
|
}
|
|
184
210
|
setShowAuthFlow(false, { performMultiWalletChecks: false });
|
|
185
211
|
// if user logged in with MM for example, just continue the flow
|
|
@@ -192,8 +218,9 @@ const useTurnkey = () => {
|
|
|
192
218
|
projectSettings,
|
|
193
219
|
returnEmbeddedWallet,
|
|
194
220
|
setShowAuthFlow,
|
|
195
|
-
|
|
196
|
-
|
|
221
|
+
startHeadlessEmbeddedWalletCreationFlow,
|
|
222
|
+
startPasskeyEmbeddedWalletCreationFlow,
|
|
223
|
+
walletConnectorOptions,
|
|
197
224
|
]);
|
|
198
225
|
return {
|
|
199
226
|
createTurnkeyWallet,
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { DynamicJwt, ChainEnum } from '@dynamic-labs/sdk-api-core';
|
|
2
|
+
import { WebAuthnAttestation } from '@dynamic-labs/wallet-connector-core';
|
|
2
3
|
import { Wallet } from '../../../../../shared';
|
|
3
4
|
export declare const useTurnkey: () => {
|
|
4
|
-
readonly createTurnkeyWallet: (jwt: string, decodedJwt: DynamicJwt,
|
|
5
|
+
readonly createTurnkeyWallet: (jwt: string, decodedJwt: DynamicJwt, chains?: ChainEnum[], options?: {
|
|
6
|
+
webAuthnAttestation: WebAuthnAttestation;
|
|
7
|
+
}) => Promise<Wallet | undefined>;
|
|
5
8
|
};
|
|
@@ -36,6 +36,8 @@ import 'react-dom';
|
|
|
36
36
|
import { useCreateDynamicEmbeddedWalletMutation } from '../../../useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.js';
|
|
37
37
|
import '../../../../../context/WalletContext/WalletContext.js';
|
|
38
38
|
import { findSmartWallet, initializeSmartWallet } from '../../../useWalletConnectors/utils/smartWallet/smartWallet.js';
|
|
39
|
+
import { findPrimaryEmbeddedChain } from '../../../../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.js';
|
|
40
|
+
import { findPasskeyEmailWalletConnector } from '../../../../../views/Passkey/utils/findPasskeyEmailWalletConnector/findPasskeyEmailWalletConnector.js';
|
|
39
41
|
import '../../../../../context/ThemeContext/ThemeContext.js';
|
|
40
42
|
import '@dynamic-labs/types';
|
|
41
43
|
import 'yup';
|
|
@@ -82,11 +84,13 @@ const useTurnkey = () => {
|
|
|
82
84
|
const { projectSettings, setPrimaryWalletId, walletConnectorOptions, setShowAuthFlow, environmentId, } = useInternalDynamicContext();
|
|
83
85
|
const { setView } = useViewContext();
|
|
84
86
|
const { createDynamicEmbeddedWalletMutation } = useCreateDynamicEmbeddedWalletMutation();
|
|
85
|
-
const
|
|
87
|
+
const startHeadlessEmbeddedWalletCreationFlow = useCallback((jwt, decodedJwt, chains, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
88
|
yield createDynamicEmbeddedWalletMutation({
|
|
87
89
|
authToken: jwt,
|
|
90
|
+
chains,
|
|
88
91
|
decodedJwt,
|
|
89
92
|
environmentId,
|
|
93
|
+
options,
|
|
90
94
|
walletConnectorOptions,
|
|
91
95
|
withAuthenticator: false,
|
|
92
96
|
});
|
|
@@ -101,12 +105,12 @@ const useTurnkey = () => {
|
|
|
101
105
|
walletConnectorOptions,
|
|
102
106
|
setShowAuthFlow,
|
|
103
107
|
]);
|
|
104
|
-
const
|
|
108
|
+
const startPasskeyEmbeddedWalletCreationFlow = useCallback((chains) => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
109
|
setShowAuthFlow(true, {
|
|
106
110
|
ignoreIfIsEmbeddedWidget: false,
|
|
107
111
|
performMultiWalletChecks: false,
|
|
108
112
|
});
|
|
109
|
-
setView('passkey-intro');
|
|
113
|
+
setView('passkey-intro', { chains });
|
|
110
114
|
return new Promise((resolve, reject) => {
|
|
111
115
|
dynamicEvents.once('embeddedWalletCreated', (wallet) => resolve(wallet));
|
|
112
116
|
dynamicEvents.once('embeddedWalletFailed', (error) => {
|
|
@@ -155,27 +159,49 @@ const useTurnkey = () => {
|
|
|
155
159
|
};
|
|
156
160
|
return Promise.resolve(passkeyWallet);
|
|
157
161
|
}), [setPrimaryWalletId, walletConnectorOptions]);
|
|
158
|
-
const createTurnkeyWallet = useCallback((jwt, decodedJwt,
|
|
159
|
-
var _e, _f;
|
|
162
|
+
const createTurnkeyWallet = useCallback((jwt, decodedJwt, chains, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
163
|
+
var _e, _f, _g, _h;
|
|
160
164
|
const isManualMode = ((_e = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _e === void 0 ? void 0 : _e.automaticEmbeddedWalletCreation) === false;
|
|
161
|
-
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(jwt,
|
|
162
|
-
const
|
|
165
|
+
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(jwt, chains);
|
|
166
|
+
const userWalletsCredentials = getUserWalletsFromVerifiedCredentials(jwt);
|
|
163
167
|
// If the user doesn't have a wallet, or if the customer is in Manual
|
|
164
168
|
// Mode, we should attempt to create a new wallet. Note that if in manual
|
|
165
169
|
// mode, the check for the existance of an embedded wallet was arbitrarily
|
|
166
170
|
// added as a safeguard given the pre-existing condition we're overriding.
|
|
167
|
-
if (!(
|
|
171
|
+
if (!(userWalletsCredentials === null || userWalletsCredentials === void 0 ? void 0 : userWalletsCredentials.length) ||
|
|
168
172
|
(!embeddedWalletVerifiedCredential && isManualMode)) {
|
|
169
173
|
const hasEmailVC = getUserVerifiedCredentialType(decodedJwt, JwtVerifiedCredentialFormatEnum.Email);
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
if ((!((_f = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _f === void 0 ? void 0 : _f.forceAuthenticatorAtSignup) &&
|
|
175
|
+
hasEmailVC) ||
|
|
176
|
+
(options === null || options === void 0 ? void 0 : options.webAuthnAttestation)) {
|
|
177
|
+
// create embedded wallet fully headless
|
|
178
|
+
return startHeadlessEmbeddedWalletCreationFlow(jwt, decodedJwt, chains, options);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
// show the passkey view to create an embedded wallet
|
|
182
|
+
return startPasskeyEmbeddedWalletCreationFlow(chains);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
// the pregenerated wallet must have been created at this point in the
|
|
187
|
+
// backend if this called as part of a new user sign up.
|
|
188
|
+
if (embeddedWalletVerifiedCredential &&
|
|
189
|
+
decodedJwt.newUser &&
|
|
190
|
+
((_g = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _g === void 0 ? void 0 : _g.automaticEmbeddedWalletCreation)) {
|
|
191
|
+
const walletConnector = findPasskeyEmailWalletConnector(walletConnectorOptions, findPrimaryEmbeddedChain(projectSettings));
|
|
192
|
+
if (!walletConnector) {
|
|
193
|
+
throw new Error('Could not find the Embedded wallet connector');
|
|
194
|
+
}
|
|
195
|
+
const wallet = {
|
|
196
|
+
address: (yield walletConnector.getAddress()) || '',
|
|
197
|
+
authenticated: Boolean((_h = embeddedWalletVerifiedCredential === null || embeddedWalletVerifiedCredential === void 0 ? void 0 : embeddedWalletVerifiedCredential.walletProperties) === null || _h === void 0 ? void 0 : _h.isAuthenticatorAttached),
|
|
198
|
+
chain: walletConnector.connectedChain || '',
|
|
199
|
+
connected: true,
|
|
200
|
+
connector: walletConnector,
|
|
201
|
+
id: embeddedWalletVerifiedCredential.id,
|
|
202
|
+
};
|
|
203
|
+
dynamicEvents.emit('embeddedWalletCreated', wallet, embeddedWalletVerifiedCredential, jwt);
|
|
176
204
|
}
|
|
177
|
-
// show the passkey view to create an embedded wallet
|
|
178
|
-
return startEmbeddedWalletCreationFlow();
|
|
179
205
|
}
|
|
180
206
|
setShowAuthFlow(false, { performMultiWalletChecks: false });
|
|
181
207
|
// if user logged in with MM for example, just continue the flow
|
|
@@ -188,8 +214,9 @@ const useTurnkey = () => {
|
|
|
188
214
|
projectSettings,
|
|
189
215
|
returnEmbeddedWallet,
|
|
190
216
|
setShowAuthFlow,
|
|
191
|
-
|
|
192
|
-
|
|
217
|
+
startHeadlessEmbeddedWalletCreationFlow,
|
|
218
|
+
startPasskeyEmbeddedWalletCreationFlow,
|
|
219
|
+
walletConnectorOptions,
|
|
193
220
|
]);
|
|
194
221
|
return {
|
|
195
222
|
createTurnkeyWallet,
|