@dynamic-labs/sdk-react-core 2.1.0-alpha.4 → 2.1.0-alpha.6
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 +14 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +12 -12
- package/src/index.cjs +6 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +3 -0
- package/src/lib/Main.cjs +2 -0
- package/src/lib/Main.js +2 -0
- package/src/lib/context/DynamicContext/DynamicContext.cjs +17 -5
- package/src/lib/context/DynamicContext/DynamicContext.d.ts +5 -0
- package/src/lib/context/DynamicContext/DynamicContext.js +14 -2
- 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/utils/functions/findTurnkeyWallet/findTurnkeyWallet.cjs +2 -1
- package/src/lib/utils/functions/findTurnkeyWallet/findTurnkeyWallet.js +3 -2
- package/src/lib/utils/hooks/useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.cjs +7 -8
- package/src/lib/utils/hooks/useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.js +7 -8
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.cjs +27 -34
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.js +28 -35
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useTurnkey/useTurnkey.cjs +31 -9
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useTurnkey/useTurnkey.js +31 -9
- package/src/lib/views/EmailVerification/EmailVerification.cjs +38 -11
- package/src/lib/views/EmailVerification/EmailVerification.js +38 -11
- package/src/lib/views/Passkey/PasskeyIntroView/PasskeyIntroView.cjs +6 -7
- package/src/lib/views/Passkey/PasskeyIntroView/PasskeyIntroView.js +6 -7
- 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
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ErrorInfo, PropsWithChildren } from 'react';
|
|
2
|
+
export type ErrorBoundaryProps = PropsWithChildren<{
|
|
3
|
+
onError?: (error: Error, info: ErrorInfo) => void;
|
|
4
|
+
}>;
|
|
5
|
+
export type ErrorBoundaryState = {
|
|
6
|
+
hasError: boolean;
|
|
7
|
+
error: Error | null;
|
|
8
|
+
};
|
|
9
|
+
export type ErrorBoundaryContextType = {
|
|
10
|
+
hasError: boolean;
|
|
11
|
+
error: any;
|
|
12
|
+
isDynamicSdkError: boolean;
|
|
13
|
+
};
|
|
@@ -17,7 +17,8 @@ const findTurnkeyWalletByPrimaryChain = (walletOptions, chainConfigurations, ver
|
|
|
17
17
|
var _a;
|
|
18
18
|
const primaryEmbeddedChain = ((_a = chainConfigurations === null || chainConfigurations === void 0 ? void 0 : chainConfigurations.find((chain) => chain.primary)) === null || _a === void 0 ? void 0 : _a.name) || sdkApiCore.ChainEnum.Evm;
|
|
19
19
|
const walletConnector = findTurnkeyWalletByChain(walletOptions, values.ChainEnumToVerifiedCredentialName[primaryEmbeddedChain]);
|
|
20
|
-
const turnkeyVC = verifiedCredentials === null || verifiedCredentials === void 0 ? void 0 : verifiedCredentials.find(({ walletName, chain }) => (walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey')) &&
|
|
20
|
+
const turnkeyVC = verifiedCredentials === null || verifiedCredentials === void 0 ? void 0 : verifiedCredentials.find(({ walletName, chain }) => (walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey')) &&
|
|
21
|
+
chain === values.ChainEnumToVerifiedCredentialName[primaryEmbeddedChain]);
|
|
21
22
|
if (!turnkeyVC || !walletConnector) {
|
|
22
23
|
return undefined;
|
|
23
24
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { ChainEnum } from '@dynamic-labs/sdk-api-core';
|
|
3
3
|
import '@dynamic-labs/utils';
|
|
4
|
-
import {
|
|
4
|
+
import { ChainEnumToVerifiedCredentialName, VerifiedCredentialNameToChainEnum } from '../../constants/values.js';
|
|
5
5
|
|
|
6
6
|
const findTurnkeyWalletByChain = (walletOptions, chainName) => {
|
|
7
7
|
const chain = chainName
|
|
@@ -13,7 +13,8 @@ const findTurnkeyWalletByPrimaryChain = (walletOptions, chainConfigurations, ver
|
|
|
13
13
|
var _a;
|
|
14
14
|
const primaryEmbeddedChain = ((_a = chainConfigurations === null || chainConfigurations === void 0 ? void 0 : chainConfigurations.find((chain) => chain.primary)) === null || _a === void 0 ? void 0 : _a.name) || ChainEnum.Evm;
|
|
15
15
|
const walletConnector = findTurnkeyWalletByChain(walletOptions, ChainEnumToVerifiedCredentialName[primaryEmbeddedChain]);
|
|
16
|
-
const turnkeyVC = verifiedCredentials === null || verifiedCredentials === void 0 ? void 0 : verifiedCredentials.find(({ walletName, chain }) => (walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey')) &&
|
|
16
|
+
const turnkeyVC = verifiedCredentials === null || verifiedCredentials === void 0 ? void 0 : verifiedCredentials.find(({ walletName, chain }) => (walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey')) &&
|
|
17
|
+
chain === ChainEnumToVerifiedCredentialName[primaryEmbeddedChain]);
|
|
17
18
|
if (!turnkeyVC || !walletConnector) {
|
|
18
19
|
return undefined;
|
|
19
20
|
}
|
|
@@ -38,6 +38,7 @@ var createEmbeddedWalletWithPasskey = require('../../../views/Passkey/utils/crea
|
|
|
38
38
|
var findPasskeyEmailWalletConnector = require('../../../views/Passkey/utils/findPasskeyEmailWalletConnector/findPasskeyEmailWalletConnector.cjs');
|
|
39
39
|
var createPregeneratedWallet = require('../../../views/Passkey/utils/createPregeneratedWallet/createPregeneratedWallet.cjs');
|
|
40
40
|
var smartWallet = require('../useWalletConnectors/utils/smartWallet/smartWallet.cjs');
|
|
41
|
+
var findPrimaryEmbeddedChain = require('../../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.cjs');
|
|
41
42
|
require('../../../context/WalletContext/WalletContext.cjs');
|
|
42
43
|
require('../../../context/ThemeContext/ThemeContext.cjs');
|
|
43
44
|
require('@dynamic-labs/types');
|
|
@@ -82,19 +83,17 @@ var useInternalDynamicContext = require('../../../context/DynamicContext/useDyna
|
|
|
82
83
|
|
|
83
84
|
// This hook needs to be async that's why it's not using useMutation
|
|
84
85
|
const useCreateDynamicEmbeddedWalletMutation = () => {
|
|
85
|
-
var _a, _b
|
|
86
|
+
var _a, _b;
|
|
86
87
|
const { setPrimaryWalletId, setCallback, setUser, user, setShowAuthFlow, projectSettings, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
87
88
|
const [isLoading, setIsLoading] = React.useState(false);
|
|
88
89
|
const [error, setError] = React.useState();
|
|
89
90
|
const embeddedChainConfig = ((_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.chainConfigurations) || [];
|
|
90
|
-
const primaryEmbeddedChain =
|
|
91
|
-
? sdkApiCore.ChainEnum.Sol
|
|
92
|
-
: sdkApiCore.ChainEnum.Evm;
|
|
91
|
+
const primaryEmbeddedChain = findPrimaryEmbeddedChain.findPrimaryEmbeddedChain(projectSettings);
|
|
93
92
|
const embeddedChains = embeddedChainConfig
|
|
94
93
|
.filter((chain) => chain.enabled)
|
|
95
94
|
.map((c) => (c.name === 'SOL' ? sdkApiCore.ChainEnum.Sol : sdkApiCore.ChainEnum.Evm));
|
|
96
|
-
const createDynamicEmbeddedWalletMutation = React.useCallback((
|
|
97
|
-
var
|
|
95
|
+
const createDynamicEmbeddedWalletMutation = React.useCallback((_c) => _tslib.__awaiter(void 0, [_c], void 0, function* ({ authToken, decodedJwt, environmentId, walletConnectorOptions, withAuthenticator, }) {
|
|
96
|
+
var _d, _e;
|
|
98
97
|
setIsLoading(true);
|
|
99
98
|
const createEmbeddedWalletMethodToUse = withAuthenticator
|
|
100
99
|
? createEmbeddedWalletWithPasskey.createEmbeddedWalletWithPasskey
|
|
@@ -107,9 +106,9 @@ const useCreateDynamicEmbeddedWalletMutation = () => {
|
|
|
107
106
|
user: user !== null && user !== void 0 ? user : createUserProfile.createUserProfile(decodedJwt),
|
|
108
107
|
walletConnector: findPasskeyEmailWalletConnector.findPasskeyEmailWalletConnector(walletConnectorOptions, primaryEmbeddedChain),
|
|
109
108
|
});
|
|
110
|
-
const turnkeyVerifiedCredentials = (
|
|
109
|
+
const turnkeyVerifiedCredentials = (_d = updatedDecodedJwt === null || updatedDecodedJwt === void 0 ? void 0 : updatedDecodedJwt.verifiedCredentials) === null || _d === void 0 ? void 0 : _d.find(({ walletName }) => walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey'));
|
|
111
110
|
/** It's not authenticated if it's a turnkey wallet that still hasn't created a passkey */
|
|
112
|
-
const authenticated = Boolean((
|
|
111
|
+
const authenticated = Boolean((_e = turnkeyVerifiedCredentials === null || turnkeyVerifiedCredentials === void 0 ? void 0 : turnkeyVerifiedCredentials.walletProperties) === null || _e === void 0 ? void 0 : _e.isAuthenticatorAttached);
|
|
113
112
|
const passkeyWallet = {
|
|
114
113
|
address: (yield walletConnector.getAddress()) || '',
|
|
115
114
|
authenticated,
|
|
@@ -34,6 +34,7 @@ import { createEmbeddedWalletWithPasskey } from '../../../views/Passkey/utils/cr
|
|
|
34
34
|
import { findPasskeyEmailWalletConnector } from '../../../views/Passkey/utils/findPasskeyEmailWalletConnector/findPasskeyEmailWalletConnector.js';
|
|
35
35
|
import { createPregeneratedWallet } from '../../../views/Passkey/utils/createPregeneratedWallet/createPregeneratedWallet.js';
|
|
36
36
|
import { findSmartWallet, initializeSmartWallet } from '../useWalletConnectors/utils/smartWallet/smartWallet.js';
|
|
37
|
+
import { findPrimaryEmbeddedChain } from '../../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.js';
|
|
37
38
|
import '../../../context/WalletContext/WalletContext.js';
|
|
38
39
|
import '../../../context/ThemeContext/ThemeContext.js';
|
|
39
40
|
import '@dynamic-labs/types';
|
|
@@ -78,19 +79,17 @@ import { useInternalDynamicContext } from '../../../context/DynamicContext/useDy
|
|
|
78
79
|
|
|
79
80
|
// This hook needs to be async that's why it's not using useMutation
|
|
80
81
|
const useCreateDynamicEmbeddedWalletMutation = () => {
|
|
81
|
-
var _a, _b
|
|
82
|
+
var _a, _b;
|
|
82
83
|
const { setPrimaryWalletId, setCallback, setUser, user, setShowAuthFlow, projectSettings, } = useInternalDynamicContext();
|
|
83
84
|
const [isLoading, setIsLoading] = useState(false);
|
|
84
85
|
const [error, setError] = useState();
|
|
85
86
|
const embeddedChainConfig = ((_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.chainConfigurations) || [];
|
|
86
|
-
const primaryEmbeddedChain = (
|
|
87
|
-
? ChainEnum.Sol
|
|
88
|
-
: ChainEnum.Evm;
|
|
87
|
+
const primaryEmbeddedChain = findPrimaryEmbeddedChain(projectSettings);
|
|
89
88
|
const embeddedChains = embeddedChainConfig
|
|
90
89
|
.filter((chain) => chain.enabled)
|
|
91
90
|
.map((c) => (c.name === 'SOL' ? ChainEnum.Sol : ChainEnum.Evm));
|
|
92
|
-
const createDynamicEmbeddedWalletMutation = useCallback((
|
|
93
|
-
var
|
|
91
|
+
const createDynamicEmbeddedWalletMutation = useCallback((_c) => __awaiter(void 0, [_c], void 0, function* ({ authToken, decodedJwt, environmentId, walletConnectorOptions, withAuthenticator, }) {
|
|
92
|
+
var _d, _e;
|
|
94
93
|
setIsLoading(true);
|
|
95
94
|
const createEmbeddedWalletMethodToUse = withAuthenticator
|
|
96
95
|
? createEmbeddedWalletWithPasskey
|
|
@@ -103,9 +102,9 @@ const useCreateDynamicEmbeddedWalletMutation = () => {
|
|
|
103
102
|
user: user !== null && user !== void 0 ? user : createUserProfile(decodedJwt),
|
|
104
103
|
walletConnector: findPasskeyEmailWalletConnector(walletConnectorOptions, primaryEmbeddedChain),
|
|
105
104
|
});
|
|
106
|
-
const turnkeyVerifiedCredentials = (
|
|
105
|
+
const turnkeyVerifiedCredentials = (_d = updatedDecodedJwt === null || updatedDecodedJwt === void 0 ? void 0 : updatedDecodedJwt.verifiedCredentials) === null || _d === void 0 ? void 0 : _d.find(({ walletName }) => walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey'));
|
|
107
106
|
/** It's not authenticated if it's a turnkey wallet that still hasn't created a passkey */
|
|
108
|
-
const authenticated = Boolean((
|
|
107
|
+
const authenticated = Boolean((_e = turnkeyVerifiedCredentials === null || turnkeyVerifiedCredentials === void 0 ? void 0 : turnkeyVerifiedCredentials.walletProperties) === null || _e === void 0 ? void 0 : _e.isAuthenticatorAttached);
|
|
109
108
|
const passkeyWallet = {
|
|
110
109
|
address: (yield walletConnector.getAddress()) || '',
|
|
111
110
|
authenticated,
|
|
@@ -109,7 +109,7 @@ var useInternalDynamicContext = require('../../../../context/DynamicContext/useD
|
|
|
109
109
|
* }
|
|
110
110
|
*/
|
|
111
111
|
const useSecureEnclaveEmbeddedWallet = () => {
|
|
112
|
-
var _a, _b;
|
|
112
|
+
var _a, _b, _c, _d;
|
|
113
113
|
const { projectSettings, onboardingOnlyJwt, primaryWallet, user, environmentId, walletConnectorOptions, setUser, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
114
114
|
const { createTurnkeyWallet } = useTurnkey.useTurnkey();
|
|
115
115
|
const { hasRecoveryEmail } = useIsTurnkeyWallet.useIsTurnkeyWallet();
|
|
@@ -127,12 +127,12 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
127
127
|
* @returns Promise<Wallet | undefined>
|
|
128
128
|
*/
|
|
129
129
|
const createEmbeddedWallet = React.useCallback((chain) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
130
|
-
var
|
|
131
|
-
const jwt = (
|
|
130
|
+
var _e, _f;
|
|
131
|
+
const jwt = (_e = getAuthToken.getAuthToken()) !== null && _e !== void 0 ? _e : onboardingOnlyJwt;
|
|
132
132
|
const { decodedJwt } = validateUserIsLoggedIn.validateUserIsLoggedIn(jwt);
|
|
133
133
|
const userWaletsCredentials = getUserWalletsFromVerifiedCredentials.getUserWalletsFromVerifiedCredentials(jwt);
|
|
134
134
|
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials.findEmbeddedWalletFromVerifiedCredentials(jwt, chain);
|
|
135
|
-
const isManualMode = ((
|
|
135
|
+
const isManualMode = ((_f = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _f === void 0 ? void 0 : _f.automaticEmbeddedWalletCreation) === false;
|
|
136
136
|
// if user has a wallet and it's not embedded,
|
|
137
137
|
// throw error to follow another flow and set up the right wallet
|
|
138
138
|
// However, if the user is in manual mode continue.
|
|
@@ -157,25 +157,26 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
157
157
|
* @param oneTimeCode - optional one-time code parameter. If not informed it tries to restore a session
|
|
158
158
|
* @returns Promise<'session_created' | 'session_restored'> - returns a string indicating the status of the session
|
|
159
159
|
*/
|
|
160
|
-
const createOrRestoreSession = React.useCallback((
|
|
161
|
-
var
|
|
162
|
-
const jwt = (
|
|
160
|
+
const createOrRestoreSession = React.useCallback((_g) => _tslib.__awaiter(void 0, [_g], void 0, function* ({ oneTimeCode }) {
|
|
161
|
+
var _h, _j, _k, _l, _m, _o, _p;
|
|
162
|
+
const jwt = (_h = getAuthToken.getAuthToken()) !== null && _h !== void 0 ? _h : onboardingOnlyJwt;
|
|
163
163
|
const { decodedJwt } = validateUserIsLoggedIn.validateUserIsLoggedIn(jwt);
|
|
164
164
|
const turnkeyRecoveryHandler = getEmbeddedWalletAuthHandler.getEmbeddedWalletAuthHandler(wallet === null || wallet === void 0 ? void 0 : wallet.connector);
|
|
165
165
|
if (turnkeyRecoveryHandler.isSessionActive()) {
|
|
166
166
|
return errors.ACTIVE_SESSION;
|
|
167
167
|
}
|
|
168
168
|
// try to restore session if possible
|
|
169
|
-
if (passkeyRecovery.canRestoreEmbeddedWalletSession((
|
|
169
|
+
if (passkeyRecovery.canRestoreEmbeddedWalletSession((_j = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _j === void 0 ? void 0 : _j.sessionKeyDuration)) {
|
|
170
170
|
try {
|
|
171
|
-
yield passkeyRecovery.restoreEmbeddedWalletSession({
|
|
171
|
+
const sessionRestored = yield passkeyRecovery.restoreEmbeddedWalletSession({
|
|
172
172
|
authToken: jwt,
|
|
173
173
|
iframeContainer: turnkeyAuthIframeContainerRef.current,
|
|
174
174
|
iframeElementId: constants.iframeElementId,
|
|
175
|
-
sessionExpiration: getEmbeddedWalletSessionExpiration.getEmbeddedWalletSessionExpiration((
|
|
175
|
+
sessionExpiration: getEmbeddedWalletSessionExpiration.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),
|
|
176
176
|
wallet: primaryWallet,
|
|
177
177
|
});
|
|
178
|
-
|
|
178
|
+
if (sessionRestored)
|
|
179
|
+
return errors.SESSION_RESTORED;
|
|
179
180
|
}
|
|
180
181
|
catch (err) {
|
|
181
182
|
logger.logger.error('Failed to restore embedded wallet', err);
|
|
@@ -189,7 +190,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
189
190
|
if (!userHasEmbeddedWallet() || !hasRecoveryEmail) {
|
|
190
191
|
throw new utils.DynamicError('User does not have a secure enclave wallet or a verified email', errors.INVALID_WALLET_DATA);
|
|
191
192
|
}
|
|
192
|
-
const organizationId = (
|
|
193
|
+
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;
|
|
193
194
|
yield turnkeyRecoveryHandler.verifyRecoveryCode(oneTimeCode, organizationId);
|
|
194
195
|
const sessionSettings = {
|
|
195
196
|
createdAt: new Date().getTime(),
|
|
@@ -217,11 +218,11 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
217
218
|
* displayName: string,
|
|
218
219
|
* }
|
|
219
220
|
*/
|
|
220
|
-
const createPasskey = React.useCallback((
|
|
221
|
-
var
|
|
221
|
+
const createPasskey = React.useCallback((_q) => _tslib.__awaiter(void 0, [_q], void 0, function* ({ oneTimeCode }) {
|
|
222
|
+
var _r, _s, _t;
|
|
222
223
|
const { decodedJwt, jwt } = validateUserIsLoggedIn.validateUserIsLoggedIn(getAuthToken.getAuthToken() || onboardingOnlyJwt);
|
|
223
224
|
validateTurnkeyProviderEnabled.validateTurnkeyProviderEnabled(projectSettings);
|
|
224
|
-
const turnkeyWallet = findTurnkeyWallet.findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (
|
|
225
|
+
const turnkeyWallet = findTurnkeyWallet.findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_r = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _r === void 0 ? void 0 : _r.chainConfigurations, decodedJwt.verifiedCredentials);
|
|
225
226
|
if (!(turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletConnector)) {
|
|
226
227
|
throw new utils.DynamicError('Wallet connector not found', errors.INVALID_WALLET_DATA);
|
|
227
228
|
}
|
|
@@ -229,7 +230,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
229
230
|
walletConnector.setEmail(user === null || user === void 0 ? void 0 : user.email);
|
|
230
231
|
if (!(user === null || user === void 0 ? void 0 : user.email)) {
|
|
231
232
|
const passkeyIdentifier = (user === null || user === void 0 ? void 0 : user.phoneNumber) ||
|
|
232
|
-
((
|
|
233
|
+
((_s = user === null || user === void 0 ? void 0 : user.verifiedCredentials.find((vc) => vc.oauthDisplayName)) === null || _s === void 0 ? void 0 : _s.oauthDisplayName) ||
|
|
233
234
|
'';
|
|
234
235
|
walletConnector.setPasskeyIdentifier(passkeyIdentifier);
|
|
235
236
|
}
|
|
@@ -239,7 +240,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
239
240
|
if (!(turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.id) || !hasEmailVC) {
|
|
240
241
|
return walletConnector.getWebAuthnAttestation();
|
|
241
242
|
}
|
|
242
|
-
const organizationId = (
|
|
243
|
+
const organizationId = (_t = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletProperties) === null || _t === void 0 ? void 0 : _t.turnkeySubOrganizationId;
|
|
243
244
|
if (!organizationId) {
|
|
244
245
|
throw new utils.DynamicError('No sub organization id found for the wallet', errors.INVALID_WALLET_DATA);
|
|
245
246
|
}
|
|
@@ -278,8 +279,8 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
278
279
|
* @returns Promise<Passkey[]>
|
|
279
280
|
*/
|
|
280
281
|
const getPasskeys = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
281
|
-
var
|
|
282
|
-
const { jwt } = validateUserIsLoggedIn.validateUserIsLoggedIn((
|
|
282
|
+
var _u;
|
|
283
|
+
const { jwt } = validateUserIsLoggedIn.validateUserIsLoggedIn((_u = getAuthToken.getAuthToken()) !== null && _u !== void 0 ? _u : onboardingOnlyJwt);
|
|
283
284
|
const data = yield embeddedWallets.getUserPasskeys({
|
|
284
285
|
environmentId: environmentId,
|
|
285
286
|
userJwt: jwt,
|
|
@@ -290,26 +291,18 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
290
291
|
* Checks if the embedded wallet session is active
|
|
291
292
|
* @returns boolean
|
|
292
293
|
*/
|
|
293
|
-
const isSessionActive =
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
try {
|
|
297
|
-
const turnkeyAuthenticatorHandler = getEmbeddedWalletAuthHandler.getEmbeddedWalletAuthHandler(wallet === null || wallet === void 0 ? void 0 : wallet.connector);
|
|
298
|
-
return turnkeyAuthenticatorHandler.isSessionActive();
|
|
299
|
-
}
|
|
300
|
-
catch (err) {
|
|
301
|
-
return false;
|
|
302
|
-
}
|
|
303
|
-
}, [wallet === null || wallet === void 0 ? void 0 : wallet.connector]);
|
|
294
|
+
const isSessionActive = (_d = ((wallet === null || wallet === void 0 ? void 0 : wallet.connector) &&
|
|
295
|
+
'getAuthenticatorHandler' in wallet.connector &&
|
|
296
|
+
((_c = getEmbeddedWalletAuthHandler.getEmbeddedWalletAuthHandler(wallet.connector)) === null || _c === void 0 ? void 0 : _c.isSessionActive()))) !== null && _d !== void 0 ? _d : false;
|
|
304
297
|
/**
|
|
305
298
|
* Sends a one-time code to the user so they can create a session or add a new passkey
|
|
306
299
|
* @returns Promise<'code_sent'>
|
|
307
300
|
*/
|
|
308
301
|
const sendOneTimeCode = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
309
|
-
var
|
|
310
|
-
const { jwt, decodedJwt } = validateUserIsLoggedIn.validateUserIsLoggedIn((
|
|
302
|
+
var _v, _w, _x;
|
|
303
|
+
const { jwt, decodedJwt } = validateUserIsLoggedIn.validateUserIsLoggedIn((_v = getAuthToken.getAuthToken()) !== null && _v !== void 0 ? _v : onboardingOnlyJwt);
|
|
311
304
|
validateTurnkeyProviderEnabled.validateTurnkeyProviderEnabled(projectSettings);
|
|
312
|
-
const targetTurnkeyWallet = findTurnkeyWallet.findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (
|
|
305
|
+
const targetTurnkeyWallet = findTurnkeyWallet.findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_w = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _w === void 0 ? void 0 : _w.chainConfigurations, decodedJwt.verifiedCredentials);
|
|
313
306
|
if (!targetTurnkeyWallet || !targetTurnkeyWallet.id) {
|
|
314
307
|
throw new utils.DynamicError('User does not have a valid secure enclave wallet', errors.INVALID_WALLET_DATA);
|
|
315
308
|
}
|
|
@@ -319,7 +312,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
319
312
|
if (isSessionActive) {
|
|
320
313
|
throw new utils.DynamicError('Session is active. No need to create a new one', errors.ACTIVE_SESSION);
|
|
321
314
|
}
|
|
322
|
-
const publicKey = yield turnkeyAuthenticatorHandler.initRecovery('email', turnkeyAuthIframeContainerRef.current, 'dyn-turnkey-auth-element-id', getEmbeddedWalletSessionExpiration.getEmbeddedWalletSessionExpiration((
|
|
315
|
+
const publicKey = yield turnkeyAuthenticatorHandler.initRecovery('email', turnkeyAuthIframeContainerRef.current, 'dyn-turnkey-auth-element-id', getEmbeddedWalletSessionExpiration.getEmbeddedWalletSessionExpiration((_x = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _x === void 0 ? void 0 : _x.sessionKeyDuration));
|
|
323
316
|
if (!publicKey) {
|
|
324
317
|
throw new utils.DynamicError(errors.ERROR_SENDING_CODE);
|
|
325
318
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../../../../_virtual/_tslib.js';
|
|
3
|
-
import { useCallback
|
|
3
|
+
import { useCallback } from 'react';
|
|
4
4
|
import { JwtVerifiedCredentialFormatEnum } from '@dynamic-labs/sdk-api-core';
|
|
5
5
|
import { DynamicError } from '@dynamic-labs/utils';
|
|
6
6
|
import '../../../../context/DynamicContext/DynamicContext.js';
|
|
@@ -105,7 +105,7 @@ import { useInternalDynamicContext } from '../../../../context/DynamicContext/us
|
|
|
105
105
|
* }
|
|
106
106
|
*/
|
|
107
107
|
const useSecureEnclaveEmbeddedWallet = () => {
|
|
108
|
-
var _a, _b;
|
|
108
|
+
var _a, _b, _c, _d;
|
|
109
109
|
const { projectSettings, onboardingOnlyJwt, primaryWallet, user, environmentId, walletConnectorOptions, setUser, } = useInternalDynamicContext();
|
|
110
110
|
const { createTurnkeyWallet } = useTurnkey();
|
|
111
111
|
const { hasRecoveryEmail } = useIsTurnkeyWallet();
|
|
@@ -123,12 +123,12 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
123
123
|
* @returns Promise<Wallet | undefined>
|
|
124
124
|
*/
|
|
125
125
|
const createEmbeddedWallet = useCallback((chain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
126
|
-
var
|
|
127
|
-
const jwt = (
|
|
126
|
+
var _e, _f;
|
|
127
|
+
const jwt = (_e = getAuthToken()) !== null && _e !== void 0 ? _e : onboardingOnlyJwt;
|
|
128
128
|
const { decodedJwt } = validateUserIsLoggedIn(jwt);
|
|
129
129
|
const userWaletsCredentials = getUserWalletsFromVerifiedCredentials(jwt);
|
|
130
130
|
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(jwt, chain);
|
|
131
|
-
const isManualMode = ((
|
|
131
|
+
const isManualMode = ((_f = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _f === void 0 ? void 0 : _f.automaticEmbeddedWalletCreation) === false;
|
|
132
132
|
// if user has a wallet and it's not embedded,
|
|
133
133
|
// throw error to follow another flow and set up the right wallet
|
|
134
134
|
// However, if the user is in manual mode continue.
|
|
@@ -153,25 +153,26 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
153
153
|
* @param oneTimeCode - optional one-time code parameter. If not informed it tries to restore a session
|
|
154
154
|
* @returns Promise<'session_created' | 'session_restored'> - returns a string indicating the status of the session
|
|
155
155
|
*/
|
|
156
|
-
const createOrRestoreSession = useCallback((
|
|
157
|
-
var
|
|
158
|
-
const jwt = (
|
|
156
|
+
const createOrRestoreSession = useCallback((_g) => __awaiter(void 0, [_g], void 0, function* ({ oneTimeCode }) {
|
|
157
|
+
var _h, _j, _k, _l, _m, _o, _p;
|
|
158
|
+
const jwt = (_h = getAuthToken()) !== null && _h !== void 0 ? _h : onboardingOnlyJwt;
|
|
159
159
|
const { decodedJwt } = validateUserIsLoggedIn(jwt);
|
|
160
160
|
const turnkeyRecoveryHandler = getEmbeddedWalletAuthHandler(wallet === null || wallet === void 0 ? void 0 : wallet.connector);
|
|
161
161
|
if (turnkeyRecoveryHandler.isSessionActive()) {
|
|
162
162
|
return ACTIVE_SESSION;
|
|
163
163
|
}
|
|
164
164
|
// try to restore session if possible
|
|
165
|
-
if (canRestoreEmbeddedWalletSession((
|
|
165
|
+
if (canRestoreEmbeddedWalletSession((_j = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _j === void 0 ? void 0 : _j.sessionKeyDuration)) {
|
|
166
166
|
try {
|
|
167
|
-
yield restoreEmbeddedWalletSession({
|
|
167
|
+
const sessionRestored = yield restoreEmbeddedWalletSession({
|
|
168
168
|
authToken: jwt,
|
|
169
169
|
iframeContainer: turnkeyAuthIframeContainerRef.current,
|
|
170
170
|
iframeElementId,
|
|
171
|
-
sessionExpiration: getEmbeddedWalletSessionExpiration((
|
|
171
|
+
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),
|
|
172
172
|
wallet: primaryWallet,
|
|
173
173
|
});
|
|
174
|
-
|
|
174
|
+
if (sessionRestored)
|
|
175
|
+
return SESSION_RESTORED;
|
|
175
176
|
}
|
|
176
177
|
catch (err) {
|
|
177
178
|
logger.error('Failed to restore embedded wallet', err);
|
|
@@ -185,7 +186,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
185
186
|
if (!userHasEmbeddedWallet() || !hasRecoveryEmail) {
|
|
186
187
|
throw new DynamicError('User does not have a secure enclave wallet or a verified email', INVALID_WALLET_DATA);
|
|
187
188
|
}
|
|
188
|
-
const organizationId = (
|
|
189
|
+
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;
|
|
189
190
|
yield turnkeyRecoveryHandler.verifyRecoveryCode(oneTimeCode, organizationId);
|
|
190
191
|
const sessionSettings = {
|
|
191
192
|
createdAt: new Date().getTime(),
|
|
@@ -213,11 +214,11 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
213
214
|
* displayName: string,
|
|
214
215
|
* }
|
|
215
216
|
*/
|
|
216
|
-
const createPasskey = useCallback((
|
|
217
|
-
var
|
|
217
|
+
const createPasskey = useCallback((_q) => __awaiter(void 0, [_q], void 0, function* ({ oneTimeCode }) {
|
|
218
|
+
var _r, _s, _t;
|
|
218
219
|
const { decodedJwt, jwt } = validateUserIsLoggedIn(getAuthToken() || onboardingOnlyJwt);
|
|
219
220
|
validateTurnkeyProviderEnabled(projectSettings);
|
|
220
|
-
const turnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (
|
|
221
|
+
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
222
|
if (!(turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletConnector)) {
|
|
222
223
|
throw new DynamicError('Wallet connector not found', INVALID_WALLET_DATA);
|
|
223
224
|
}
|
|
@@ -225,7 +226,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
225
226
|
walletConnector.setEmail(user === null || user === void 0 ? void 0 : user.email);
|
|
226
227
|
if (!(user === null || user === void 0 ? void 0 : user.email)) {
|
|
227
228
|
const passkeyIdentifier = (user === null || user === void 0 ? void 0 : user.phoneNumber) ||
|
|
228
|
-
((
|
|
229
|
+
((_s = user === null || user === void 0 ? void 0 : user.verifiedCredentials.find((vc) => vc.oauthDisplayName)) === null || _s === void 0 ? void 0 : _s.oauthDisplayName) ||
|
|
229
230
|
'';
|
|
230
231
|
walletConnector.setPasskeyIdentifier(passkeyIdentifier);
|
|
231
232
|
}
|
|
@@ -235,7 +236,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
235
236
|
if (!(turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.id) || !hasEmailVC) {
|
|
236
237
|
return walletConnector.getWebAuthnAttestation();
|
|
237
238
|
}
|
|
238
|
-
const organizationId = (
|
|
239
|
+
const organizationId = (_t = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletProperties) === null || _t === void 0 ? void 0 : _t.turnkeySubOrganizationId;
|
|
239
240
|
if (!organizationId) {
|
|
240
241
|
throw new DynamicError('No sub organization id found for the wallet', INVALID_WALLET_DATA);
|
|
241
242
|
}
|
|
@@ -274,8 +275,8 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
274
275
|
* @returns Promise<Passkey[]>
|
|
275
276
|
*/
|
|
276
277
|
const getPasskeys = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
277
|
-
var
|
|
278
|
-
const { jwt } = validateUserIsLoggedIn((
|
|
278
|
+
var _u;
|
|
279
|
+
const { jwt } = validateUserIsLoggedIn((_u = getAuthToken()) !== null && _u !== void 0 ? _u : onboardingOnlyJwt);
|
|
279
280
|
const data = yield getUserPasskeys({
|
|
280
281
|
environmentId: environmentId,
|
|
281
282
|
userJwt: jwt,
|
|
@@ -286,26 +287,18 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
286
287
|
* Checks if the embedded wallet session is active
|
|
287
288
|
* @returns boolean
|
|
288
289
|
*/
|
|
289
|
-
const isSessionActive =
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
try {
|
|
293
|
-
const turnkeyAuthenticatorHandler = getEmbeddedWalletAuthHandler(wallet === null || wallet === void 0 ? void 0 : wallet.connector);
|
|
294
|
-
return turnkeyAuthenticatorHandler.isSessionActive();
|
|
295
|
-
}
|
|
296
|
-
catch (err) {
|
|
297
|
-
return false;
|
|
298
|
-
}
|
|
299
|
-
}, [wallet === null || wallet === void 0 ? void 0 : wallet.connector]);
|
|
290
|
+
const isSessionActive = (_d = ((wallet === null || wallet === void 0 ? void 0 : wallet.connector) &&
|
|
291
|
+
'getAuthenticatorHandler' in wallet.connector &&
|
|
292
|
+
((_c = getEmbeddedWalletAuthHandler(wallet.connector)) === null || _c === void 0 ? void 0 : _c.isSessionActive()))) !== null && _d !== void 0 ? _d : false;
|
|
300
293
|
/**
|
|
301
294
|
* Sends a one-time code to the user so they can create a session or add a new passkey
|
|
302
295
|
* @returns Promise<'code_sent'>
|
|
303
296
|
*/
|
|
304
297
|
const sendOneTimeCode = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
305
|
-
var
|
|
306
|
-
const { jwt, decodedJwt } = validateUserIsLoggedIn((
|
|
298
|
+
var _v, _w, _x;
|
|
299
|
+
const { jwt, decodedJwt } = validateUserIsLoggedIn((_v = getAuthToken()) !== null && _v !== void 0 ? _v : onboardingOnlyJwt);
|
|
307
300
|
validateTurnkeyProviderEnabled(projectSettings);
|
|
308
|
-
const targetTurnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (
|
|
301
|
+
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);
|
|
309
302
|
if (!targetTurnkeyWallet || !targetTurnkeyWallet.id) {
|
|
310
303
|
throw new DynamicError('User does not have a valid secure enclave wallet', INVALID_WALLET_DATA);
|
|
311
304
|
}
|
|
@@ -315,7 +308,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
315
308
|
if (isSessionActive) {
|
|
316
309
|
throw new DynamicError('Session is active. No need to create a new one', ACTIVE_SESSION);
|
|
317
310
|
}
|
|
318
|
-
const publicKey = yield turnkeyAuthenticatorHandler.initRecovery('email', turnkeyAuthIframeContainerRef.current, 'dyn-turnkey-auth-element-id', getEmbeddedWalletSessionExpiration((
|
|
311
|
+
const publicKey = yield turnkeyAuthenticatorHandler.initRecovery('email', turnkeyAuthIframeContainerRef.current, 'dyn-turnkey-auth-element-id', getEmbeddedWalletSessionExpiration((_x = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _x === void 0 ? void 0 : _x.sessionKeyDuration));
|
|
319
312
|
if (!publicKey) {
|
|
320
313
|
throw new DynamicError(ERROR_SENDING_CODE);
|
|
321
314
|
}
|
|
@@ -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');
|
|
@@ -160,26 +162,46 @@ const useTurnkey = () => {
|
|
|
160
162
|
return Promise.resolve(passkeyWallet);
|
|
161
163
|
}), [setPrimaryWalletId, walletConnectorOptions]);
|
|
162
164
|
const createTurnkeyWallet = React.useCallback((jwt, decodedJwt, chain) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
163
|
-
var _e, _f;
|
|
165
|
+
var _e, _f, _g, _h;
|
|
164
166
|
const isManualMode = ((_e = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _e === void 0 ? void 0 : _e.automaticEmbeddedWalletCreation) === false;
|
|
165
167
|
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials.findEmbeddedWalletFromVerifiedCredentials(jwt, chain);
|
|
166
|
-
const
|
|
168
|
+
const userWalletsCredentials = getUserWalletsFromVerifiedCredentials.getUserWalletsFromVerifiedCredentials(jwt);
|
|
167
169
|
// If the user doesn't have a wallet, or if the customer is in Manual
|
|
168
170
|
// Mode, we should attempt to create a new wallet. Note that if in manual
|
|
169
171
|
// mode, the check for the existance of an embedded wallet was arbitrarily
|
|
170
172
|
// added as a safeguard given the pre-existing condition we're overriding.
|
|
171
|
-
if (!(
|
|
173
|
+
if (!(userWalletsCredentials === null || userWalletsCredentials === void 0 ? void 0 : userWalletsCredentials.length) ||
|
|
172
174
|
(!embeddedWalletVerifiedCredential && isManualMode)) {
|
|
173
175
|
const hasEmailVC = getUserVerifiedCredentialType.getUserVerifiedCredentialType(decodedJwt, sdkApiCore.JwtVerifiedCredentialFormatEnum.Email);
|
|
174
|
-
// create wallet without authenticator
|
|
175
|
-
// if users log in and doesn't have an email vc they won't be able to use passkey recovery
|
|
176
|
-
// and it means that they need to create it while creating a wallet
|
|
177
176
|
if (!((_f = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _f === void 0 ? void 0 : _f.forceAuthenticatorAtSignup) &&
|
|
178
|
-
|
|
177
|
+
hasEmailVC) {
|
|
179
178
|
return startPregeneratedWalletCreationFlow(jwt, decodedJwt);
|
|
180
179
|
}
|
|
181
|
-
|
|
182
|
-
|
|
180
|
+
else {
|
|
181
|
+
// show the passkey view to create an embedded wallet
|
|
182
|
+
return startEmbeddedWalletCreationFlow();
|
|
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.findPasskeyEmailWalletConnector(walletConnectorOptions, findPrimaryEmbeddedChain.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.dynamicEvents.emit('embeddedWalletCreated', wallet, embeddedWalletVerifiedCredential, jwt);
|
|
204
|
+
}
|
|
183
205
|
}
|
|
184
206
|
setShowAuthFlow(false, { performMultiWalletChecks: false });
|
|
185
207
|
// if user logged in with MM for example, just continue the flow
|
|
@@ -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';
|
|
@@ -156,26 +158,46 @@ const useTurnkey = () => {
|
|
|
156
158
|
return Promise.resolve(passkeyWallet);
|
|
157
159
|
}), [setPrimaryWalletId, walletConnectorOptions]);
|
|
158
160
|
const createTurnkeyWallet = useCallback((jwt, decodedJwt, chain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
159
|
-
var _e, _f;
|
|
161
|
+
var _e, _f, _g, _h;
|
|
160
162
|
const isManualMode = ((_e = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _e === void 0 ? void 0 : _e.automaticEmbeddedWalletCreation) === false;
|
|
161
163
|
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(jwt, chain);
|
|
162
|
-
const
|
|
164
|
+
const userWalletsCredentials = getUserWalletsFromVerifiedCredentials(jwt);
|
|
163
165
|
// If the user doesn't have a wallet, or if the customer is in Manual
|
|
164
166
|
// Mode, we should attempt to create a new wallet. Note that if in manual
|
|
165
167
|
// mode, the check for the existance of an embedded wallet was arbitrarily
|
|
166
168
|
// added as a safeguard given the pre-existing condition we're overriding.
|
|
167
|
-
if (!(
|
|
169
|
+
if (!(userWalletsCredentials === null || userWalletsCredentials === void 0 ? void 0 : userWalletsCredentials.length) ||
|
|
168
170
|
(!embeddedWalletVerifiedCredential && isManualMode)) {
|
|
169
171
|
const hasEmailVC = getUserVerifiedCredentialType(decodedJwt, JwtVerifiedCredentialFormatEnum.Email);
|
|
170
|
-
// create wallet without authenticator
|
|
171
|
-
// if users log in and doesn't have an email vc they won't be able to use passkey recovery
|
|
172
|
-
// and it means that they need to create it while creating a wallet
|
|
173
172
|
if (!((_f = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _f === void 0 ? void 0 : _f.forceAuthenticatorAtSignup) &&
|
|
174
|
-
|
|
173
|
+
hasEmailVC) {
|
|
175
174
|
return startPregeneratedWalletCreationFlow(jwt, decodedJwt);
|
|
176
175
|
}
|
|
177
|
-
|
|
178
|
-
|
|
176
|
+
else {
|
|
177
|
+
// show the passkey view to create an embedded wallet
|
|
178
|
+
return startEmbeddedWalletCreationFlow();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
// the pregenerated wallet must have been created at this point in the
|
|
183
|
+
// backend if this called as part of a new user sign up.
|
|
184
|
+
if (embeddedWalletVerifiedCredential &&
|
|
185
|
+
decodedJwt.newUser &&
|
|
186
|
+
((_g = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _g === void 0 ? void 0 : _g.automaticEmbeddedWalletCreation)) {
|
|
187
|
+
const walletConnector = findPasskeyEmailWalletConnector(walletConnectorOptions, findPrimaryEmbeddedChain(projectSettings));
|
|
188
|
+
if (!walletConnector) {
|
|
189
|
+
throw new Error('Could not find the Embedded wallet connector');
|
|
190
|
+
}
|
|
191
|
+
const wallet = {
|
|
192
|
+
address: (yield walletConnector.getAddress()) || '',
|
|
193
|
+
authenticated: Boolean((_h = embeddedWalletVerifiedCredential === null || embeddedWalletVerifiedCredential === void 0 ? void 0 : embeddedWalletVerifiedCredential.walletProperties) === null || _h === void 0 ? void 0 : _h.isAuthenticatorAttached),
|
|
194
|
+
chain: walletConnector.connectedChain || '',
|
|
195
|
+
connected: true,
|
|
196
|
+
connector: walletConnector,
|
|
197
|
+
id: embeddedWalletVerifiedCredential.id,
|
|
198
|
+
};
|
|
199
|
+
dynamicEvents.emit('embeddedWalletCreated', wallet, embeddedWalletVerifiedCredential, jwt);
|
|
200
|
+
}
|
|
179
201
|
}
|
|
180
202
|
setShowAuthFlow(false, { performMultiWalletChecks: false });
|
|
181
203
|
// if user logged in with MM for example, just continue the flow
|