@dynamic-labs/sdk-react-core 2.1.0-alpha.1 → 2.1.0-alpha.10
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 +79 -0
- package/package.cjs +2 -2
- package/package.js +2 -2
- package/package.json +13 -14
- package/src/index.cjs +6 -2
- package/src/index.d.ts +2 -1
- package/src/index.js +3 -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/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/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 +0 -2
- package/src/lib/utils/constants/errors.js +1 -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 +1 -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 +14 -10
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.d.ts +14 -2
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.js +14 -10
- 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 +8 -8
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useMPCEmbeddedWallet.d.ts +2 -2
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useMPCEmbeddedWallet.js +8 -8
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.cjs +148 -46
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.d.ts +21 -8
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.js +152 -50
- 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/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/utils/turnkeyExport/turnkeyExport.cjs +2 -2
- package/src/lib/views/EmbeddedReveal/utils/turnkeyExport/turnkeyExport.js +2 -2
- 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';
|
|
@@ -42,7 +45,7 @@ import { useElementById } from '../../useElementById/useElementById.js';
|
|
|
42
45
|
import { useWalletContext } from '../../../../context/WalletContext/WalletContext.js';
|
|
43
46
|
import { validateUserIsLoggedIn } from '../../../validations/validateUserIsLoggedIn/validateUserIsLoggedIn.js';
|
|
44
47
|
import { validateTurnkeyProviderEnabled } from '../../../validations/validateTurnkeyProviderEnabled/validateTurnkeyProviderEnabled.js';
|
|
45
|
-
import { SESSION_RESTORED, INVALID_REQUEST, INVALID_WALLET_DATA, SESSION_CREATED,
|
|
48
|
+
import { ACTIVE_SESSION, SESSION_RESTORED, INVALID_REQUEST, INVALID_WALLET_DATA, SESSION_CREATED, ERROR_SENDING_CODE, CODE_SENT } from '../../../constants/errors.js';
|
|
46
49
|
import { useIsTurnkeyWallet } from '../../useIsTurnkeyWallet/useIsTurnkeyWallet.js';
|
|
47
50
|
import { canRestoreEmbeddedWalletSession, restoreEmbeddedWalletSession } from '../../../../views/Passkey/utils/passkeyRecovery/passkeyRecovery.js';
|
|
48
51
|
import { useTurnkey } from './useTurnkey/useTurnkey.js';
|
|
@@ -88,30 +91,46 @@ import '../../../../views/TransactionConfirmationView/helpers/transactionErrorMe
|
|
|
88
91
|
import '../../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.js';
|
|
89
92
|
import { useInternalDynamicContext } from '../../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.js';
|
|
90
93
|
|
|
91
|
-
// Hook exposed to customers
|
|
94
|
+
// Hook exposed to customers
|
|
92
95
|
/**
|
|
96
|
+
*
|
|
93
97
|
* @returns {
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
98
|
+
* createEmbeddedWallet, - creates Secure enclave embedded wallet according to the settings
|
|
99
|
+
* createOrRestoreSession, - creates or restores a embedded wallet session
|
|
100
|
+
* createPasskey, - creates a new passkey both for an existing wallet or a wallet to be created
|
|
101
|
+
* getPasskeys, - gets all passkeys for the user
|
|
102
|
+
* isLoadingEmbeddedWallet, - loading state of the embedded wallet
|
|
103
|
+
* isSessionActive, - checks if the embedded wallet session is active
|
|
104
|
+
* sendOneTimeCode, - sends a one-time code to the user so they can create a session or add a new passkey
|
|
105
|
+
* userHasEmbeddedWallet, - checks if the user has an embedded wallet
|
|
97
106
|
* }
|
|
98
107
|
*/
|
|
99
108
|
const useSecureEnclaveEmbeddedWallet = () => {
|
|
100
|
-
var _a, _b;
|
|
101
|
-
const { projectSettings, onboardingOnlyJwt, primaryWallet, user, environmentId, } = useInternalDynamicContext();
|
|
109
|
+
var _a, _b, _c, _d;
|
|
110
|
+
const { projectSettings, onboardingOnlyJwt, primaryWallet, user, environmentId, walletConnectorOptions, setUser, } = useInternalDynamicContext();
|
|
102
111
|
const { createTurnkeyWallet } = useTurnkey();
|
|
103
112
|
const { hasRecoveryEmail } = useIsTurnkeyWallet();
|
|
104
|
-
const
|
|
113
|
+
const { createRootElement } = useElementById();
|
|
105
114
|
const { isLoadingEmbeddedWallet, setIsLoadingEmbeddedWallet } = useWalletContext();
|
|
106
115
|
const wallet = getEOAWallet(primaryWallet, (user === null || user === void 0 ? void 0 : user.verifiedCredentials) || []);
|
|
116
|
+
/**
|
|
117
|
+
* Checks if the user has an embedded wallet or not
|
|
118
|
+
* @returns boolean
|
|
119
|
+
*/
|
|
107
120
|
const userHasEmbeddedWallet = useCallback(() => hasEmbeddedWallet(getAuthToken() || onboardingOnlyJwt, 'turnkey'), [onboardingOnlyJwt]);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Creates a new secure enclave embedded wallet according to the settings from the dashboard
|
|
123
|
+
* @param chain - optional chain parameter to create the wallet for
|
|
124
|
+
* @param options - optional parameter contained more settings for the wallet creation
|
|
125
|
+
* @returns Promise<Wallet | undefined>
|
|
126
|
+
*/
|
|
127
|
+
const createEmbeddedWallet = useCallback((chains, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
128
|
+
var _e, _f;
|
|
129
|
+
const jwt = (_e = getAuthToken()) !== null && _e !== void 0 ? _e : onboardingOnlyJwt;
|
|
111
130
|
const { decodedJwt } = validateUserIsLoggedIn(jwt);
|
|
112
131
|
const userWaletsCredentials = getUserWalletsFromVerifiedCredentials(jwt);
|
|
113
|
-
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(jwt,
|
|
114
|
-
const isManualMode = ((
|
|
132
|
+
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(jwt, chains);
|
|
133
|
+
const isManualMode = ((_f = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _f === void 0 ? void 0 : _f.automaticEmbeddedWalletCreation) === false;
|
|
115
134
|
// if user has a wallet and it's not embedded,
|
|
116
135
|
// throw error to follow another flow and set up the right wallet
|
|
117
136
|
// However, if the user is in manual mode continue.
|
|
@@ -121,48 +140,56 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
121
140
|
throw new DynamicError('Manual mode must be enabled to create an embedded wallet for this user');
|
|
122
141
|
}
|
|
123
142
|
validateTurnkeyProviderEnabled(projectSettings);
|
|
124
|
-
setIsLoadingEmbeddedWallet(true);
|
|
125
143
|
// TEMP: immediately disable loading state
|
|
126
144
|
setIsLoadingEmbeddedWallet(false);
|
|
127
|
-
|
|
128
|
-
return wallet;
|
|
145
|
+
return createTurnkeyWallet(jwt, decodedJwt, chains, options);
|
|
129
146
|
}), [
|
|
130
147
|
createTurnkeyWallet,
|
|
131
148
|
onboardingOnlyJwt,
|
|
132
149
|
projectSettings,
|
|
133
150
|
setIsLoadingEmbeddedWallet,
|
|
134
151
|
]);
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
152
|
+
/**
|
|
153
|
+
* Creates or restores a secure enclave embedded wallet session
|
|
154
|
+
* If it detects that the session is possible to be restored, it will restore it
|
|
155
|
+
* @param oneTimeCode - optional one-time code parameter. If not informed it tries to restore a session
|
|
156
|
+
* @returns Promise<'session_created' | 'session_restored'> - returns a string indicating the status of the session
|
|
157
|
+
*/
|
|
158
|
+
const createOrRestoreSession = useCallback((_g) => __awaiter(void 0, [_g], void 0, function* ({ oneTimeCode }) {
|
|
159
|
+
var _h, _j, _k, _l, _m, _o, _p;
|
|
160
|
+
const jwt = (_h = getAuthToken()) !== null && _h !== void 0 ? _h : onboardingOnlyJwt;
|
|
138
161
|
const { decodedJwt } = validateUserIsLoggedIn(jwt);
|
|
139
162
|
const turnkeyRecoveryHandler = getEmbeddedWalletAuthHandler(wallet === null || wallet === void 0 ? void 0 : wallet.connector);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
163
|
+
if (turnkeyRecoveryHandler.isSessionActive()) {
|
|
164
|
+
return ACTIVE_SESSION;
|
|
165
|
+
}
|
|
166
|
+
const turnkeyAuthIframeContainerRef = createRootElement(iframeContainerId);
|
|
167
|
+
// try to restore session if possible
|
|
168
|
+
if (canRestoreEmbeddedWalletSession((_j = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _j === void 0 ? void 0 : _j.sessionKeyDuration)) {
|
|
143
169
|
try {
|
|
144
|
-
yield restoreEmbeddedWalletSession({
|
|
170
|
+
const sessionRestored = yield restoreEmbeddedWalletSession({
|
|
145
171
|
authToken: jwt,
|
|
146
172
|
iframeContainer: turnkeyAuthIframeContainerRef.current,
|
|
147
173
|
iframeElementId,
|
|
148
|
-
sessionExpiration: getEmbeddedWalletSessionExpiration((
|
|
174
|
+
sessionExpiration: getEmbeddedWalletSessionExpiration((_l = (_k = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _k === void 0 ? void 0 : _k.embeddedWallets) === null || _l === void 0 ? void 0 : _l.sessionKeyDuration),
|
|
149
175
|
wallet: primaryWallet,
|
|
150
176
|
});
|
|
151
|
-
|
|
177
|
+
if (sessionRestored)
|
|
178
|
+
return SESSION_RESTORED;
|
|
152
179
|
}
|
|
153
180
|
catch (err) {
|
|
154
181
|
logger.error('Failed to restore embedded wallet', err);
|
|
155
182
|
}
|
|
156
183
|
}
|
|
157
|
-
// creates a new session
|
|
158
184
|
if (!oneTimeCode) {
|
|
159
185
|
throw new DynamicError('One-time code is required to create a session.', INVALID_REQUEST);
|
|
160
186
|
}
|
|
187
|
+
// tries to create a new session with the informed one-time code
|
|
161
188
|
// verify user has a turnkey wallet and email VC
|
|
162
189
|
if (!userHasEmbeddedWallet() || !hasRecoveryEmail) {
|
|
163
190
|
throw new DynamicError('User does not have a secure enclave wallet or a verified email', INVALID_WALLET_DATA);
|
|
164
191
|
}
|
|
165
|
-
const organizationId = (
|
|
192
|
+
const organizationId = (_p = (_o = (_m = decodedJwt.verifiedCredentials) === null || _m === void 0 ? void 0 : _m.find(({ walletName }) => walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey'))) === null || _o === void 0 ? void 0 : _o.walletProperties) === null || _p === void 0 ? void 0 : _p.turnkeySubOrganizationId;
|
|
166
193
|
yield turnkeyRecoveryHandler.verifyRecoveryCode(oneTimeCode, organizationId);
|
|
167
194
|
const sessionSettings = {
|
|
168
195
|
createdAt: new Date().getTime(),
|
|
@@ -172,40 +199,113 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
172
199
|
LocalStorage.setToLS(EMBEDDED_WALLET_SESSION_SETTINGS, sessionSettings);
|
|
173
200
|
return SESSION_CREATED;
|
|
174
201
|
}), [
|
|
202
|
+
createRootElement,
|
|
175
203
|
hasRecoveryEmail,
|
|
176
204
|
onboardingOnlyJwt,
|
|
177
205
|
primaryWallet,
|
|
178
206
|
(_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
207
|
userHasEmbeddedWallet,
|
|
181
208
|
wallet === null || wallet === void 0 ? void 0 : wallet.connector,
|
|
182
209
|
]);
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
210
|
+
/**
|
|
211
|
+
* Creates a new passkey both for an existing wallet or a wallet to be created
|
|
212
|
+
* @param oneTimeCode: string | undefined,
|
|
213
|
+
*
|
|
214
|
+
* @returns Promise<WebAuthnAttestation>
|
|
215
|
+
*/
|
|
216
|
+
const createPasskey = useCallback((_q) => __awaiter(void 0, [_q], void 0, function* ({ oneTimeCode, }) {
|
|
217
|
+
var _r, _s;
|
|
218
|
+
const { decodedJwt, jwt } = validateUserIsLoggedIn(getAuthToken() || onboardingOnlyJwt);
|
|
219
|
+
validateTurnkeyProviderEnabled(projectSettings);
|
|
220
|
+
const turnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_r = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _r === void 0 ? void 0 : _r.chainConfigurations, decodedJwt.verifiedCredentials);
|
|
221
|
+
if (!(turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletConnector)) {
|
|
222
|
+
throw new DynamicError('Wallet connector not found', INVALID_WALLET_DATA);
|
|
223
|
+
}
|
|
224
|
+
const walletConnector = turnkeyWallet.walletConnector;
|
|
225
|
+
walletConnector.setEmail(user === null || user === void 0 ? void 0 : user.email);
|
|
226
|
+
if (user && !(user === null || user === void 0 ? void 0 : user.email)) {
|
|
227
|
+
addPasskeyIdentifierToWalletConnector(walletConnector, user);
|
|
189
228
|
}
|
|
190
|
-
|
|
191
|
-
|
|
229
|
+
const hasEmailVC = getUserVerifiedCredentialType(decodedJwt, JwtVerifiedCredentialFormatEnum.Email);
|
|
230
|
+
// return a new passkey if the user doesn't have a wallet yet or
|
|
231
|
+
// none of the requirements to add a passkey to an existing wallet are met
|
|
232
|
+
if (!('id' in turnkeyWallet) || !hasEmailVC) {
|
|
233
|
+
return walletConnector.getWebAuthnAttestation();
|
|
192
234
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
235
|
+
const organizationId = (_s = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletProperties) === null || _s === void 0 ? void 0 : _s.turnkeySubOrganizationId;
|
|
236
|
+
if (!organizationId) {
|
|
237
|
+
throw new DynamicError('No sub organization id found for the wallet', INVALID_WALLET_DATA);
|
|
238
|
+
}
|
|
239
|
+
const turnkAuthenticatorHandler = getEmbeddedWalletAuthHandler(walletConnector);
|
|
240
|
+
// add new passkey to the wallet through an active session
|
|
241
|
+
yield createOrRestoreSession({ oneTimeCode });
|
|
242
|
+
const { attestation, challenge, displayName } = yield walletConnector.getWebAuthnAttestation();
|
|
243
|
+
yield turnkAuthenticatorHandler.addPasskeyAuthenticator({
|
|
244
|
+
attestation,
|
|
245
|
+
challenge,
|
|
246
|
+
organizationId,
|
|
247
|
+
});
|
|
248
|
+
const passkeyResponse = yield completePasskeyRecovery({
|
|
249
|
+
attestation: attestation,
|
|
250
|
+
challenge,
|
|
251
|
+
environmentId,
|
|
252
|
+
userJwt: jwt,
|
|
253
|
+
walletId: turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.id,
|
|
254
|
+
});
|
|
255
|
+
const { jwt: updatedJwt, minifiedJwt } = passkeyResponse;
|
|
256
|
+
setUser(updateJWTAndCreateUserProfile(updatedJwt, minifiedJwt));
|
|
257
|
+
return { attestation, challenge, displayName };
|
|
258
|
+
}), [
|
|
259
|
+
createOrRestoreSession,
|
|
260
|
+
environmentId,
|
|
261
|
+
onboardingOnlyJwt,
|
|
262
|
+
projectSettings,
|
|
263
|
+
setUser,
|
|
264
|
+
user === null || user === void 0 ? void 0 : user.email,
|
|
265
|
+
user === null || user === void 0 ? void 0 : user.phoneNumber,
|
|
266
|
+
user === null || user === void 0 ? void 0 : user.verifiedCredentials,
|
|
267
|
+
walletConnectorOptions,
|
|
268
|
+
]);
|
|
269
|
+
/**
|
|
270
|
+
* Gets all passkeys for the user
|
|
271
|
+
* @returns Promise<Passkey[]>
|
|
272
|
+
*/
|
|
273
|
+
const getPasskeys = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
274
|
+
var _t;
|
|
275
|
+
const { jwt } = validateUserIsLoggedIn((_t = getAuthToken()) !== null && _t !== void 0 ? _t : onboardingOnlyJwt);
|
|
276
|
+
const data = yield getUserPasskeys({
|
|
277
|
+
environmentId: environmentId,
|
|
278
|
+
userJwt: jwt,
|
|
279
|
+
});
|
|
280
|
+
return data.passkeys;
|
|
281
|
+
}), [environmentId, onboardingOnlyJwt]);
|
|
282
|
+
/**
|
|
283
|
+
* Checks if the embedded wallet session is active
|
|
284
|
+
* @returns boolean
|
|
285
|
+
*/
|
|
286
|
+
const isSessionActive = (_d = ((wallet === null || wallet === void 0 ? void 0 : wallet.connector) &&
|
|
287
|
+
'getAuthenticatorHandler' in wallet.connector &&
|
|
288
|
+
((_c = getEmbeddedWalletAuthHandler(wallet.connector)) === null || _c === void 0 ? void 0 : _c.isSessionActive()))) !== null && _d !== void 0 ? _d : false;
|
|
289
|
+
/**
|
|
290
|
+
* Sends a one-time code to the user so they can create a session or add a new passkey
|
|
291
|
+
* @returns Promise<'code_sent'>
|
|
292
|
+
*/
|
|
293
|
+
const sendOneTimeCode = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
294
|
+
var _u, _v, _w;
|
|
295
|
+
const { jwt, decodedJwt } = validateUserIsLoggedIn((_u = getAuthToken()) !== null && _u !== void 0 ? _u : onboardingOnlyJwt);
|
|
197
296
|
validateTurnkeyProviderEnabled(projectSettings);
|
|
198
|
-
const targetTurnkeyWallet =
|
|
199
|
-
if (!targetTurnkeyWallet || !targetTurnkeyWallet
|
|
297
|
+
const targetTurnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_v = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _v === void 0 ? void 0 : _v.chainConfigurations, decodedJwt.verifiedCredentials);
|
|
298
|
+
if (!targetTurnkeyWallet || !('id' in targetTurnkeyWallet)) {
|
|
200
299
|
throw new DynamicError('User does not have a valid secure enclave wallet', INVALID_WALLET_DATA);
|
|
201
300
|
}
|
|
202
|
-
const turnkeyAuthenticatorHandler = getEmbeddedWalletAuthHandler(
|
|
301
|
+
const turnkeyAuthenticatorHandler = getEmbeddedWalletAuthHandler(targetTurnkeyWallet === null || targetTurnkeyWallet === void 0 ? void 0 : targetTurnkeyWallet.walletConnector);
|
|
203
302
|
const targetTurnkeyWalletId = targetTurnkeyWallet.id;
|
|
204
303
|
const isSessionActive = turnkeyAuthenticatorHandler.isSessionActive();
|
|
205
304
|
if (isSessionActive) {
|
|
206
305
|
throw new DynamicError('Session is active. No need to create a new one', ACTIVE_SESSION);
|
|
207
306
|
}
|
|
208
|
-
const
|
|
307
|
+
const turnkeyAuthIframeContainerRef = createRootElement(iframeContainerId);
|
|
308
|
+
const publicKey = yield turnkeyAuthenticatorHandler.initRecovery('email', turnkeyAuthIframeContainerRef.current, iframeElementId, getEmbeddedWalletSessionExpiration((_w = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _w === void 0 ? void 0 : _w.sessionKeyDuration));
|
|
209
309
|
if (!publicKey) {
|
|
210
310
|
throw new DynamicError(ERROR_SENDING_CODE);
|
|
211
311
|
}
|
|
@@ -219,15 +319,17 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
219
319
|
turnkeyAuthenticatorHandler.recoveryUserId = response.turnkeyUserId;
|
|
220
320
|
return CODE_SENT;
|
|
221
321
|
}), [
|
|
322
|
+
createRootElement,
|
|
222
323
|
environmentId,
|
|
223
324
|
onboardingOnlyJwt,
|
|
224
325
|
projectSettings,
|
|
225
|
-
|
|
226
|
-
wallet === null || wallet === void 0 ? void 0 : wallet.connector,
|
|
326
|
+
walletConnectorOptions,
|
|
227
327
|
]);
|
|
228
328
|
return {
|
|
229
329
|
createEmbeddedWallet,
|
|
230
330
|
createOrRestoreSession,
|
|
331
|
+
createPasskey,
|
|
332
|
+
getPasskeys,
|
|
231
333
|
isLoadingEmbeddedWallet,
|
|
232
334
|
isSessionActive,
|
|
233
335
|
sendOneTimeCode,
|
|
@@ -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,
|
|
@@ -78,7 +78,7 @@ var useInternalDynamicContext = require('../../../context/DynamicContext/useDyna
|
|
|
78
78
|
|
|
79
79
|
const useIsTurnkeyWallet = () => {
|
|
80
80
|
var _a;
|
|
81
|
-
const { primaryWallet, user
|
|
81
|
+
const { primaryWallet, user } = useInternalDynamicContext.useInternalDynamicContext();
|
|
82
82
|
const wallet = getEOAWallet.getEOAWallet(primaryWallet, (user === null || user === void 0 ? void 0 : user.verifiedCredentials) || []);
|
|
83
83
|
const getTurnkeyVerifiedCredential = () => {
|
|
84
84
|
if (!wallet || !user) {
|
|
@@ -115,7 +115,7 @@ const useIsTurnkeyWallet = () => {
|
|
|
115
115
|
const isTurnkeyWalletWithoutAuthenticator = (isTurnkeyWallet && !hasTurnkeyVerifiedCredentialAuthenticator) ||
|
|
116
116
|
isUnclaimedTurnkeyTheSignerOfScw;
|
|
117
117
|
const hasRecoveryEmail = isTurnkeyWallet &&
|
|
118
|
-
Boolean(getUserVerifiedCredentialType.getUserVerifiedCredentialType(
|
|
118
|
+
Boolean(getUserVerifiedCredentialType.getUserVerifiedCredentialType(user, sdkApiCore.JwtVerifiedCredentialFormatEnum.Email));
|
|
119
119
|
return {
|
|
120
120
|
hasRecoveryEmail,
|
|
121
121
|
hasTurnkeyVerifiedCredentialAuthenticator,
|
|
@@ -74,7 +74,7 @@ import { useInternalDynamicContext } from '../../../context/DynamicContext/useDy
|
|
|
74
74
|
|
|
75
75
|
const useIsTurnkeyWallet = () => {
|
|
76
76
|
var _a;
|
|
77
|
-
const { primaryWallet, user
|
|
77
|
+
const { primaryWallet, user } = useInternalDynamicContext();
|
|
78
78
|
const wallet = getEOAWallet(primaryWallet, (user === null || user === void 0 ? void 0 : user.verifiedCredentials) || []);
|
|
79
79
|
const getTurnkeyVerifiedCredential = () => {
|
|
80
80
|
if (!wallet || !user) {
|
|
@@ -111,7 +111,7 @@ const useIsTurnkeyWallet = () => {
|
|
|
111
111
|
const isTurnkeyWalletWithoutAuthenticator = (isTurnkeyWallet && !hasTurnkeyVerifiedCredentialAuthenticator) ||
|
|
112
112
|
isUnclaimedTurnkeyTheSignerOfScw;
|
|
113
113
|
const hasRecoveryEmail = isTurnkeyWallet &&
|
|
114
|
-
Boolean(getUserVerifiedCredentialType(
|
|
114
|
+
Boolean(getUserVerifiedCredentialType(user, JwtVerifiedCredentialFormatEnum.Email));
|
|
115
115
|
return {
|
|
116
116
|
hasRecoveryEmail,
|
|
117
117
|
hasTurnkeyVerifiedCredentialAuthenticator,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useMergeUserAccounts } from './useMergeUserAccounts';
|