@dynamic-labs/sdk-react-core 2.1.0-alpha.8 → 2.1.0-alpha.9
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 +7 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +12 -12
- package/src/lib/components/Portal/Portal.cjs +2 -1
- package/src/lib/components/Portal/Portal.js +2 -1
- package/src/lib/components/SandboxIndicatorWrapper/SandboxIndicatorWrapper.d.ts +0 -2
- package/src/lib/components/Toolkit/components/index.d.ts +0 -6
- package/src/lib/components/Tooltip/Tooltip.cjs +2 -1
- package/src/lib/components/Tooltip/Tooltip.js +2 -1
- package/src/lib/context/DynamicContext/DynamicContext.cjs +0 -1
- package/src/lib/context/DynamicContext/DynamicContext.js +0 -1
- package/src/lib/context/DynamicContext/types/index.d.ts +0 -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/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 +1 -1
- package/src/lib/utils/functions/findTurnkeyWallet/findTurnkeyWallet.d.ts +3 -1
- package/src/lib/utils/functions/findTurnkeyWallet/findTurnkeyWallet.js +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 +1 -1
- 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 +15 -10
- package/src/lib/utils/hooks/useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.d.ts +7 -2
- package/src/lib/utils/hooks/useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.js +15 -10
- 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 +9 -4
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.d.ts +6 -3
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.js +9 -4
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useCoinbaseMPC/useCoinbaseMPC.cjs +2 -2
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useCoinbaseMPC/useCoinbaseMPC.d.ts +1 -1
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useCoinbaseMPC/useCoinbaseMPC.js +2 -2
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useMPCEmbeddedWallet.cjs +7 -7
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useMPCEmbeddedWallet.d.ts +2 -2
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useMPCEmbeddedWallet.js +7 -7
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.cjs +24 -27
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.d.ts +6 -3
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.js +24 -27
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useTurnkey/useTurnkey.cjs +16 -11
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useTurnkey/useTurnkey.d.ts +4 -1
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useTurnkey/useTurnkey.js +16 -11
- 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/usePasskeyRecovery/usePasskeyRecovery.cjs +2 -1
- package/src/lib/utils/hooks/usePasskeyRecovery/usePasskeyRecovery.js +2 -1
- 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 +5 -4
- package/src/lib/views/Passkey/PasskeyIntroView/PasskeyIntroView.d.ts +6 -1
- package/src/lib/views/Passkey/PasskeyIntroView/PasskeyIntroView.js +5 -4
- 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} +17 -18
- 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} +17 -18
- package/src/lib/views/Passkey/utils/createEmbeddedWalletRequest/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 +2 -2
- package/src/lib/views/Passkey/utils/passkeyRecovery/passkeyRecovery.js +2 -2
- package/src/lib/views/viewToComponentMap.d.ts +4 -2
- 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/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,4 +1,5 @@
|
|
|
1
1
|
import { ChainEnum } from '@dynamic-labs/sdk-api-core';
|
|
2
|
+
import { WebAuthnAttestation } from '@dynamic-labs/wallet-connector-core';
|
|
2
3
|
import { Wallet } from '../../../../shared';
|
|
3
4
|
/**
|
|
4
5
|
*
|
|
@@ -14,13 +15,15 @@ import { Wallet } from '../../../../shared';
|
|
|
14
15
|
* }
|
|
15
16
|
*/
|
|
16
17
|
export declare const useSecureEnclaveEmbeddedWallet: () => {
|
|
17
|
-
readonly createEmbeddedWallet: (
|
|
18
|
+
readonly createEmbeddedWallet: (chains?: ChainEnum[], options?: {
|
|
19
|
+
webAuthnAttestation: WebAuthnAttestation;
|
|
20
|
+
}) => Promise<Wallet | undefined>;
|
|
18
21
|
readonly createOrRestoreSession: ({ oneTimeCode }: {
|
|
19
22
|
oneTimeCode?: string;
|
|
20
23
|
}) => Promise<string>;
|
|
21
|
-
readonly createPasskey: ({ oneTimeCode }: {
|
|
24
|
+
readonly createPasskey: ({ oneTimeCode, }: {
|
|
22
25
|
oneTimeCode?: string;
|
|
23
|
-
}) => Promise<
|
|
26
|
+
}) => Promise<WebAuthnAttestation>;
|
|
24
27
|
readonly getPasskeys: () => Promise<import("@dynamic-labs/sdk-api-core").UserPasskey[]>;
|
|
25
28
|
readonly isLoadingEmbeddedWallet: boolean;
|
|
26
29
|
readonly isSessionActive: boolean;
|
|
@@ -24,6 +24,7 @@ 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';
|
|
@@ -109,7 +110,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
109
110
|
const { projectSettings, onboardingOnlyJwt, primaryWallet, user, environmentId, walletConnectorOptions, setUser, } = useInternalDynamicContext();
|
|
110
111
|
const { createTurnkeyWallet } = useTurnkey();
|
|
111
112
|
const { hasRecoveryEmail } = useIsTurnkeyWallet();
|
|
112
|
-
const
|
|
113
|
+
const { createRootElement } = useElementById();
|
|
113
114
|
const { isLoadingEmbeddedWallet, setIsLoadingEmbeddedWallet } = useWalletContext();
|
|
114
115
|
const wallet = getEOAWallet(primaryWallet, (user === null || user === void 0 ? void 0 : user.verifiedCredentials) || []);
|
|
115
116
|
/**
|
|
@@ -120,14 +121,15 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
120
121
|
/**
|
|
121
122
|
* Creates a new secure enclave embedded wallet according to the settings from the dashboard
|
|
122
123
|
* @param chain - optional chain parameter to create the wallet for
|
|
124
|
+
* @param options - optional parameter contained more settings for the wallet creation
|
|
123
125
|
* @returns Promise<Wallet | undefined>
|
|
124
126
|
*/
|
|
125
|
-
const createEmbeddedWallet = useCallback((
|
|
127
|
+
const createEmbeddedWallet = useCallback((chains, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
126
128
|
var _e, _f;
|
|
127
129
|
const jwt = (_e = getAuthToken()) !== null && _e !== void 0 ? _e : onboardingOnlyJwt;
|
|
128
130
|
const { decodedJwt } = validateUserIsLoggedIn(jwt);
|
|
129
131
|
const userWaletsCredentials = getUserWalletsFromVerifiedCredentials(jwt);
|
|
130
|
-
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(jwt,
|
|
132
|
+
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(jwt, chains);
|
|
131
133
|
const isManualMode = ((_f = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _f === void 0 ? void 0 : _f.automaticEmbeddedWalletCreation) === false;
|
|
132
134
|
// if user has a wallet and it's not embedded,
|
|
133
135
|
// throw error to follow another flow and set up the right wallet
|
|
@@ -140,7 +142,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
140
142
|
validateTurnkeyProviderEnabled(projectSettings);
|
|
141
143
|
// TEMP: immediately disable loading state
|
|
142
144
|
setIsLoadingEmbeddedWallet(false);
|
|
143
|
-
return createTurnkeyWallet(jwt, decodedJwt,
|
|
145
|
+
return createTurnkeyWallet(jwt, decodedJwt, chains, options);
|
|
144
146
|
}), [
|
|
145
147
|
createTurnkeyWallet,
|
|
146
148
|
onboardingOnlyJwt,
|
|
@@ -161,6 +163,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
161
163
|
if (turnkeyRecoveryHandler.isSessionActive()) {
|
|
162
164
|
return ACTIVE_SESSION;
|
|
163
165
|
}
|
|
166
|
+
const turnkeyAuthIframeContainerRef = createRootElement(iframeContainerId);
|
|
164
167
|
// try to restore session if possible
|
|
165
168
|
if (canRestoreEmbeddedWalletSession((_j = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _j === void 0 ? void 0 : _j.sessionKeyDuration)) {
|
|
166
169
|
try {
|
|
@@ -196,11 +199,11 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
196
199
|
LocalStorage.setToLS(EMBEDDED_WALLET_SESSION_SETTINGS, sessionSettings);
|
|
197
200
|
return SESSION_CREATED;
|
|
198
201
|
}), [
|
|
202
|
+
createRootElement,
|
|
199
203
|
hasRecoveryEmail,
|
|
200
204
|
onboardingOnlyJwt,
|
|
201
205
|
primaryWallet,
|
|
202
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,
|
|
203
|
-
turnkeyAuthIframeContainerRef,
|
|
204
207
|
userHasEmbeddedWallet,
|
|
205
208
|
wallet === null || wallet === void 0 ? void 0 : wallet.connector,
|
|
206
209
|
]);
|
|
@@ -208,14 +211,10 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
208
211
|
* Creates a new passkey both for an existing wallet or a wallet to be created
|
|
209
212
|
* @param oneTimeCode: string | undefined,
|
|
210
213
|
*
|
|
211
|
-
* @returns
|
|
212
|
-
* attestation: Attestation,
|
|
213
|
-
* challenge: string,
|
|
214
|
-
* displayName: string,
|
|
215
|
-
* }
|
|
214
|
+
* @returns Promise<WebAuthnAttestation>
|
|
216
215
|
*/
|
|
217
|
-
const createPasskey = useCallback((_q) => __awaiter(void 0, [_q], void 0, function* ({ oneTimeCode }) {
|
|
218
|
-
var _r, _s
|
|
216
|
+
const createPasskey = useCallback((_q) => __awaiter(void 0, [_q], void 0, function* ({ oneTimeCode, }) {
|
|
217
|
+
var _r, _s;
|
|
219
218
|
const { decodedJwt, jwt } = validateUserIsLoggedIn(getAuthToken() || onboardingOnlyJwt);
|
|
220
219
|
validateTurnkeyProviderEnabled(projectSettings);
|
|
221
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);
|
|
@@ -224,19 +223,16 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
224
223
|
}
|
|
225
224
|
const walletConnector = turnkeyWallet.walletConnector;
|
|
226
225
|
walletConnector.setEmail(user === null || user === void 0 ? void 0 : user.email);
|
|
227
|
-
if (!(user === null || user === void 0 ? void 0 : user.email)) {
|
|
228
|
-
|
|
229
|
-
((_s = user === null || user === void 0 ? void 0 : user.verifiedCredentials.find((vc) => vc.oauthDisplayName)) === null || _s === void 0 ? void 0 : _s.oauthDisplayName) ||
|
|
230
|
-
'';
|
|
231
|
-
walletConnector.setPasskeyIdentifier(passkeyIdentifier);
|
|
226
|
+
if (user && !(user === null || user === void 0 ? void 0 : user.email)) {
|
|
227
|
+
addPasskeyIdentifierToWalletConnector(walletConnector, user);
|
|
232
228
|
}
|
|
233
229
|
const hasEmailVC = getUserVerifiedCredentialType(decodedJwt, JwtVerifiedCredentialFormatEnum.Email);
|
|
234
230
|
// return a new passkey if the user doesn't have a wallet yet or
|
|
235
231
|
// none of the requirements to add a passkey to an existing wallet are met
|
|
236
|
-
if (!(
|
|
232
|
+
if (!('id' in turnkeyWallet) || !hasEmailVC) {
|
|
237
233
|
return walletConnector.getWebAuthnAttestation();
|
|
238
234
|
}
|
|
239
|
-
const organizationId = (
|
|
235
|
+
const organizationId = (_s = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletProperties) === null || _s === void 0 ? void 0 : _s.turnkeySubOrganizationId;
|
|
240
236
|
if (!organizationId) {
|
|
241
237
|
throw new DynamicError('No sub organization id found for the wallet', INVALID_WALLET_DATA);
|
|
242
238
|
}
|
|
@@ -275,8 +271,8 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
275
271
|
* @returns Promise<Passkey[]>
|
|
276
272
|
*/
|
|
277
273
|
const getPasskeys = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
278
|
-
var
|
|
279
|
-
const { jwt } = validateUserIsLoggedIn((
|
|
274
|
+
var _t;
|
|
275
|
+
const { jwt } = validateUserIsLoggedIn((_t = getAuthToken()) !== null && _t !== void 0 ? _t : onboardingOnlyJwt);
|
|
280
276
|
const data = yield getUserPasskeys({
|
|
281
277
|
environmentId: environmentId,
|
|
282
278
|
userJwt: jwt,
|
|
@@ -295,11 +291,11 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
295
291
|
* @returns Promise<'code_sent'>
|
|
296
292
|
*/
|
|
297
293
|
const sendOneTimeCode = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
298
|
-
var _v, _w
|
|
299
|
-
const { jwt, decodedJwt } = validateUserIsLoggedIn((
|
|
294
|
+
var _u, _v, _w;
|
|
295
|
+
const { jwt, decodedJwt } = validateUserIsLoggedIn((_u = getAuthToken()) !== null && _u !== void 0 ? _u : onboardingOnlyJwt);
|
|
300
296
|
validateTurnkeyProviderEnabled(projectSettings);
|
|
301
|
-
const targetTurnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (
|
|
302
|
-
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)) {
|
|
303
299
|
throw new DynamicError('User does not have a valid secure enclave wallet', INVALID_WALLET_DATA);
|
|
304
300
|
}
|
|
305
301
|
const turnkeyAuthenticatorHandler = getEmbeddedWalletAuthHandler(targetTurnkeyWallet === null || targetTurnkeyWallet === void 0 ? void 0 : targetTurnkeyWallet.walletConnector);
|
|
@@ -308,7 +304,8 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
308
304
|
if (isSessionActive) {
|
|
309
305
|
throw new DynamicError('Session is active. No need to create a new one', ACTIVE_SESSION);
|
|
310
306
|
}
|
|
311
|
-
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));
|
|
312
309
|
if (!publicKey) {
|
|
313
310
|
throw new DynamicError(ERROR_SENDING_CODE);
|
|
314
311
|
}
|
|
@@ -322,10 +319,10 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
322
319
|
turnkeyAuthenticatorHandler.recoveryUserId = response.turnkeyUserId;
|
|
323
320
|
return CODE_SENT;
|
|
324
321
|
}), [
|
|
322
|
+
createRootElement,
|
|
325
323
|
environmentId,
|
|
326
324
|
onboardingOnlyJwt,
|
|
327
325
|
projectSettings,
|
|
328
|
-
turnkeyAuthIframeContainerRef,
|
|
329
326
|
walletConnectorOptions,
|
|
330
327
|
]);
|
|
331
328
|
return {
|
|
@@ -88,11 +88,13 @@ const useTurnkey = () => {
|
|
|
88
88
|
const { projectSettings, setPrimaryWalletId, walletConnectorOptions, setShowAuthFlow, environmentId, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
89
89
|
const { setView } = ViewContext.useViewContext();
|
|
90
90
|
const { createDynamicEmbeddedWalletMutation } = useCreateDynamicEmbeddedWalletMutation.useCreateDynamicEmbeddedWalletMutation();
|
|
91
|
-
const
|
|
91
|
+
const startHeadlessEmbeddedWalletCreationFlow = React.useCallback((jwt, decodedJwt, chains, options) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
92
92
|
yield createDynamicEmbeddedWalletMutation({
|
|
93
93
|
authToken: jwt,
|
|
94
|
+
chains,
|
|
94
95
|
decodedJwt,
|
|
95
96
|
environmentId,
|
|
97
|
+
options,
|
|
96
98
|
walletConnectorOptions,
|
|
97
99
|
withAuthenticator: false,
|
|
98
100
|
});
|
|
@@ -107,12 +109,12 @@ const useTurnkey = () => {
|
|
|
107
109
|
walletConnectorOptions,
|
|
108
110
|
setShowAuthFlow,
|
|
109
111
|
]);
|
|
110
|
-
const
|
|
112
|
+
const startPasskeyEmbeddedWalletCreationFlow = React.useCallback((chains) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
111
113
|
setShowAuthFlow(true, {
|
|
112
114
|
ignoreIfIsEmbeddedWidget: false,
|
|
113
115
|
performMultiWalletChecks: false,
|
|
114
116
|
});
|
|
115
|
-
setView('passkey-intro');
|
|
117
|
+
setView('passkey-intro', { chains });
|
|
116
118
|
return new Promise((resolve, reject) => {
|
|
117
119
|
dynamicEvents.dynamicEvents.once('embeddedWalletCreated', (wallet) => resolve(wallet));
|
|
118
120
|
dynamicEvents.dynamicEvents.once('embeddedWalletFailed', (error) => {
|
|
@@ -161,10 +163,10 @@ const useTurnkey = () => {
|
|
|
161
163
|
};
|
|
162
164
|
return Promise.resolve(passkeyWallet);
|
|
163
165
|
}), [setPrimaryWalletId, walletConnectorOptions]);
|
|
164
|
-
const createTurnkeyWallet = React.useCallback((jwt, decodedJwt,
|
|
166
|
+
const createTurnkeyWallet = React.useCallback((jwt, decodedJwt, chains, options) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
165
167
|
var _e, _f, _g, _h;
|
|
166
168
|
const isManualMode = ((_e = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _e === void 0 ? void 0 : _e.automaticEmbeddedWalletCreation) === false;
|
|
167
|
-
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials.findEmbeddedWalletFromVerifiedCredentials(jwt,
|
|
169
|
+
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials.findEmbeddedWalletFromVerifiedCredentials(jwt, chains);
|
|
168
170
|
const userWalletsCredentials = getUserWalletsFromVerifiedCredentials.getUserWalletsFromVerifiedCredentials(jwt);
|
|
169
171
|
// If the user doesn't have a wallet, or if the customer is in Manual
|
|
170
172
|
// Mode, we should attempt to create a new wallet. Note that if in manual
|
|
@@ -173,13 +175,15 @@ const useTurnkey = () => {
|
|
|
173
175
|
if (!(userWalletsCredentials === null || userWalletsCredentials === void 0 ? void 0 : userWalletsCredentials.length) ||
|
|
174
176
|
(!embeddedWalletVerifiedCredential && isManualMode)) {
|
|
175
177
|
const hasEmailVC = getUserVerifiedCredentialType.getUserVerifiedCredentialType(decodedJwt, sdkApiCore.JwtVerifiedCredentialFormatEnum.Email);
|
|
176
|
-
if (!((_f = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _f === void 0 ? void 0 : _f.forceAuthenticatorAtSignup) &&
|
|
177
|
-
hasEmailVC)
|
|
178
|
-
|
|
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);
|
|
179
183
|
}
|
|
180
184
|
else {
|
|
181
185
|
// show the passkey view to create an embedded wallet
|
|
182
|
-
return
|
|
186
|
+
return startPasskeyEmbeddedWalletCreationFlow(chains);
|
|
183
187
|
}
|
|
184
188
|
}
|
|
185
189
|
else {
|
|
@@ -214,8 +218,9 @@ const useTurnkey = () => {
|
|
|
214
218
|
projectSettings,
|
|
215
219
|
returnEmbeddedWallet,
|
|
216
220
|
setShowAuthFlow,
|
|
217
|
-
|
|
218
|
-
|
|
221
|
+
startHeadlessEmbeddedWalletCreationFlow,
|
|
222
|
+
startPasskeyEmbeddedWalletCreationFlow,
|
|
223
|
+
walletConnectorOptions,
|
|
219
224
|
]);
|
|
220
225
|
return {
|
|
221
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
|
};
|
|
@@ -84,11 +84,13 @@ const useTurnkey = () => {
|
|
|
84
84
|
const { projectSettings, setPrimaryWalletId, walletConnectorOptions, setShowAuthFlow, environmentId, } = useInternalDynamicContext();
|
|
85
85
|
const { setView } = useViewContext();
|
|
86
86
|
const { createDynamicEmbeddedWalletMutation } = useCreateDynamicEmbeddedWalletMutation();
|
|
87
|
-
const
|
|
87
|
+
const startHeadlessEmbeddedWalletCreationFlow = useCallback((jwt, decodedJwt, chains, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
88
|
yield createDynamicEmbeddedWalletMutation({
|
|
89
89
|
authToken: jwt,
|
|
90
|
+
chains,
|
|
90
91
|
decodedJwt,
|
|
91
92
|
environmentId,
|
|
93
|
+
options,
|
|
92
94
|
walletConnectorOptions,
|
|
93
95
|
withAuthenticator: false,
|
|
94
96
|
});
|
|
@@ -103,12 +105,12 @@ const useTurnkey = () => {
|
|
|
103
105
|
walletConnectorOptions,
|
|
104
106
|
setShowAuthFlow,
|
|
105
107
|
]);
|
|
106
|
-
const
|
|
108
|
+
const startPasskeyEmbeddedWalletCreationFlow = useCallback((chains) => __awaiter(void 0, void 0, void 0, function* () {
|
|
107
109
|
setShowAuthFlow(true, {
|
|
108
110
|
ignoreIfIsEmbeddedWidget: false,
|
|
109
111
|
performMultiWalletChecks: false,
|
|
110
112
|
});
|
|
111
|
-
setView('passkey-intro');
|
|
113
|
+
setView('passkey-intro', { chains });
|
|
112
114
|
return new Promise((resolve, reject) => {
|
|
113
115
|
dynamicEvents.once('embeddedWalletCreated', (wallet) => resolve(wallet));
|
|
114
116
|
dynamicEvents.once('embeddedWalletFailed', (error) => {
|
|
@@ -157,10 +159,10 @@ const useTurnkey = () => {
|
|
|
157
159
|
};
|
|
158
160
|
return Promise.resolve(passkeyWallet);
|
|
159
161
|
}), [setPrimaryWalletId, walletConnectorOptions]);
|
|
160
|
-
const createTurnkeyWallet = useCallback((jwt, decodedJwt,
|
|
162
|
+
const createTurnkeyWallet = useCallback((jwt, decodedJwt, chains, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
161
163
|
var _e, _f, _g, _h;
|
|
162
164
|
const isManualMode = ((_e = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _e === void 0 ? void 0 : _e.automaticEmbeddedWalletCreation) === false;
|
|
163
|
-
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(jwt,
|
|
165
|
+
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(jwt, chains);
|
|
164
166
|
const userWalletsCredentials = getUserWalletsFromVerifiedCredentials(jwt);
|
|
165
167
|
// If the user doesn't have a wallet, or if the customer is in Manual
|
|
166
168
|
// Mode, we should attempt to create a new wallet. Note that if in manual
|
|
@@ -169,13 +171,15 @@ const useTurnkey = () => {
|
|
|
169
171
|
if (!(userWalletsCredentials === null || userWalletsCredentials === void 0 ? void 0 : userWalletsCredentials.length) ||
|
|
170
172
|
(!embeddedWalletVerifiedCredential && isManualMode)) {
|
|
171
173
|
const hasEmailVC = getUserVerifiedCredentialType(decodedJwt, JwtVerifiedCredentialFormatEnum.Email);
|
|
172
|
-
if (!((_f = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _f === void 0 ? void 0 : _f.forceAuthenticatorAtSignup) &&
|
|
173
|
-
hasEmailVC)
|
|
174
|
-
|
|
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);
|
|
175
179
|
}
|
|
176
180
|
else {
|
|
177
181
|
// show the passkey view to create an embedded wallet
|
|
178
|
-
return
|
|
182
|
+
return startPasskeyEmbeddedWalletCreationFlow(chains);
|
|
179
183
|
}
|
|
180
184
|
}
|
|
181
185
|
else {
|
|
@@ -210,8 +214,9 @@ const useTurnkey = () => {
|
|
|
210
214
|
projectSettings,
|
|
211
215
|
returnEmbeddedWallet,
|
|
212
216
|
setShowAuthFlow,
|
|
213
|
-
|
|
214
|
-
|
|
217
|
+
startHeadlessEmbeddedWalletCreationFlow,
|
|
218
|
+
startPasskeyEmbeddedWalletCreationFlow,
|
|
219
|
+
walletConnectorOptions,
|
|
215
220
|
]);
|
|
216
221
|
return {
|
|
217
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,
|
|
@@ -91,7 +91,8 @@ var useInternalDynamicContext = require('../../../context/DynamicContext/useDyna
|
|
|
91
91
|
const usePasskeyRecovery = () => {
|
|
92
92
|
var _a, _b;
|
|
93
93
|
const { authToken, environmentId, primaryWallet, projectSettings, setShowAuthFlow, user: user$1, setUser, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
94
|
-
const
|
|
94
|
+
const { createRootElement } = useElementById.useElementById();
|
|
95
|
+
const iframeContainerRef = createRootElement(constants.iframeContainerId);
|
|
95
96
|
const { userHasEmbeddedWallet } = useEmbeddedWallet.useEmbeddedWallet();
|
|
96
97
|
const { isTurnkeyWalletWithoutAuthenticator, hasRecoveryEmail } = useIsTurnkeyWallet.useIsTurnkeyWallet();
|
|
97
98
|
const { initAuthMethod } = useInitEmbeddedWalletAuthMethod.useInitEmbeddedWalletAuthMethod();
|
|
@@ -87,7 +87,8 @@ import { useInternalDynamicContext } from '../../../context/DynamicContext/useDy
|
|
|
87
87
|
const usePasskeyRecovery = () => {
|
|
88
88
|
var _a, _b;
|
|
89
89
|
const { authToken, environmentId, primaryWallet, projectSettings, setShowAuthFlow, user, setUser, } = useInternalDynamicContext();
|
|
90
|
-
const
|
|
90
|
+
const { createRootElement } = useElementById();
|
|
91
|
+
const iframeContainerRef = createRootElement(iframeContainerId);
|
|
91
92
|
const { userHasEmbeddedWallet } = useEmbeddedWallet();
|
|
92
93
|
const { isTurnkeyWalletWithoutAuthenticator, hasRecoveryEmail } = useIsTurnkeyWallet();
|
|
93
94
|
const { initAuthMethod } = useInitEmbeddedWalletAuthMethod();
|
|
@@ -82,8 +82,7 @@ require('../LoginView/sections/PhoneNumberSignInSection/PhoneNumberSignInSection
|
|
|
82
82
|
// The component notifies the user about the required manual network change,
|
|
83
83
|
// as the wallet does not support programmatic network change.
|
|
84
84
|
const NetworkNotSupportedSwitchManual = () => {
|
|
85
|
-
|
|
86
|
-
const { user, selectedWalletConnector: walletConnector } = useInternalDynamicContext.useInternalDynamicContext();
|
|
85
|
+
const { selectedWalletConnector: walletConnector } = useInternalDynamicContext.useInternalDynamicContext();
|
|
87
86
|
useNetworkNotSupported.useNetworkNotSupported();
|
|
88
87
|
const { t } = reactI18next.useTranslation();
|
|
89
88
|
const iconSize = 80;
|
|
@@ -92,7 +91,7 @@ const NetworkNotSupportedSwitchManual = () => {
|
|
|
92
91
|
width: pixelToRem.pixelToRem(iconSize * IconWithSpinner.iconRatio),
|
|
93
92
|
} }));
|
|
94
93
|
const walletConnectorNetworks = getWalletConnectorNetworks.getWalletConnectorNetworks(walletConnector);
|
|
95
|
-
return (jsxRuntime.jsxs("div", { "data-testid": 'network-not-supported', className: 'network-not-supported-switch-manual', children: [jsxRuntime.jsx("div", { className: 'network-not-supported-switch-manual__img-container', children:
|
|
94
|
+
return (jsxRuntime.jsxs("div", { "data-testid": 'network-not-supported', className: 'network-not-supported-switch-manual', children: [jsxRuntime.jsx("div", { className: 'network-not-supported-switch-manual__img-container', children: jsxRuntime.jsx("div", { className: 'network-not-supported-switch-manual__network-container', children: jsxRuntime.jsx(IconWithSpinner.IconWithSpinner, { Icon: icon, iconSize: iconSize, isSpinning: true }) }) }), jsxRuntime.jsxs("div", { className: 'network-not-supported-switch-manual__content', children: [jsxRuntime.jsx(Typography.Typography, { className: 'network-not-supported-switch-manual__title', weight: 'medium', variant: 'title', color: 'primary', copykey: 'dyn_network_not_supported_manual_switch.title', children: t('dyn_network_not_supported_manual_switch.title') }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_normal', color: 'secondary', copykey: walletConnectorNetworks.length
|
|
96
95
|
? 'dyn_network_not_supported_manual_switch.subtitle_network_defined'
|
|
97
96
|
: 'dyn_network_not_supported_manual_switch.subtitle_no_network_defined', children: walletConnectorNetworks.length
|
|
98
97
|
? t('dyn_network_not_supported_manual_switch.subtitle_network_defined', { network: walletConnectorNetworks[0].name })
|
|
@@ -78,8 +78,7 @@ import '../LoginView/sections/PhoneNumberSignInSection/PhoneNumberSignInSection.
|
|
|
78
78
|
// The component notifies the user about the required manual network change,
|
|
79
79
|
// as the wallet does not support programmatic network change.
|
|
80
80
|
const NetworkNotSupportedSwitchManual = () => {
|
|
81
|
-
|
|
82
|
-
const { user, selectedWalletConnector: walletConnector } = useInternalDynamicContext();
|
|
81
|
+
const { selectedWalletConnector: walletConnector } = useInternalDynamicContext();
|
|
83
82
|
useNetworkNotSupported();
|
|
84
83
|
const { t } = useTranslation();
|
|
85
84
|
const iconSize = 80;
|
|
@@ -88,7 +87,7 @@ const NetworkNotSupportedSwitchManual = () => {
|
|
|
88
87
|
width: pixelToRem(iconSize * iconRatio),
|
|
89
88
|
} }));
|
|
90
89
|
const walletConnectorNetworks = getWalletConnectorNetworks(walletConnector);
|
|
91
|
-
return (jsxs("div", { "data-testid": 'network-not-supported', className: 'network-not-supported-switch-manual', children: [jsx("div", { className: 'network-not-supported-switch-manual__img-container', children:
|
|
90
|
+
return (jsxs("div", { "data-testid": 'network-not-supported', className: 'network-not-supported-switch-manual', children: [jsx("div", { className: 'network-not-supported-switch-manual__img-container', children: jsx("div", { className: 'network-not-supported-switch-manual__network-container', children: jsx(IconWithSpinner, { Icon: icon, iconSize: iconSize, isSpinning: true }) }) }), jsxs("div", { className: 'network-not-supported-switch-manual__content', children: [jsx(Typography, { className: 'network-not-supported-switch-manual__title', weight: 'medium', variant: 'title', color: 'primary', copykey: 'dyn_network_not_supported_manual_switch.title', children: t('dyn_network_not_supported_manual_switch.title') }), jsx(Typography, { variant: 'body_normal', color: 'secondary', copykey: walletConnectorNetworks.length
|
|
92
91
|
? 'dyn_network_not_supported_manual_switch.subtitle_network_defined'
|
|
93
92
|
: 'dyn_network_not_supported_manual_switch.subtitle_no_network_defined', children: walletConnectorNetworks.length
|
|
94
93
|
? t('dyn_network_not_supported_manual_switch.subtitle_network_defined', { network: walletConnectorNetworks[0].name })
|
|
@@ -88,7 +88,8 @@ const EmbeddedAuthChoiceCards = ({ currentAction, supportedAuthenticators, }) =>
|
|
|
88
88
|
const { projectSettings } = useInternalDynamicContext.useInternalDynamicContext();
|
|
89
89
|
const { t } = reactI18next.useTranslation();
|
|
90
90
|
const { initAuthMethod, isLoading } = useInitEmbeddedWalletAuthMethod.useInitEmbeddedWalletAuthMethod();
|
|
91
|
-
const
|
|
91
|
+
const { createRootElement } = useElementById.useElementById();
|
|
92
|
+
const iframeContainerRef = createRootElement(constants.iframeContainerId);
|
|
92
93
|
const supportedAuthenticatorsMap = {
|
|
93
94
|
email: {
|
|
94
95
|
badgeKey: 'dyn_embedded_authenticator.email.badge',
|
|
@@ -84,7 +84,8 @@ const EmbeddedAuthChoiceCards = ({ currentAction, supportedAuthenticators, }) =>
|
|
|
84
84
|
const { projectSettings } = useInternalDynamicContext();
|
|
85
85
|
const { t } = useTranslation();
|
|
86
86
|
const { initAuthMethod, isLoading } = useInitEmbeddedWalletAuthMethod();
|
|
87
|
-
const
|
|
87
|
+
const { createRootElement } = useElementById();
|
|
88
|
+
const iframeContainerRef = createRootElement(iframeContainerId);
|
|
88
89
|
const supportedAuthenticatorsMap = {
|
|
89
90
|
email: {
|
|
90
91
|
badgeKey: 'dyn_embedded_authenticator.email.badge',
|
|
@@ -88,11 +88,11 @@ require('../../TransactionConfirmationView/helpers/transactionErrorMessage.cjs')
|
|
|
88
88
|
require('../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.cjs');
|
|
89
89
|
var useInternalDynamicContext = require('../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.cjs');
|
|
90
90
|
|
|
91
|
-
const PasskeyIntroView = () => {
|
|
91
|
+
const PasskeyIntroView = ({ chains }) => {
|
|
92
92
|
var _a;
|
|
93
|
-
const { walletConnectorOptions, environmentId, handleLogOut, onboardingOnlyJwt,
|
|
94
|
-
const isEmailRecoveryFlow = ((_a =
|
|
95
|
-
!getUserVerifiedCredentialType.getUserVerifiedCredentialType(
|
|
93
|
+
const { walletConnectorOptions, environmentId, handleLogOut, onboardingOnlyJwt, user, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
94
|
+
const isEmailRecoveryFlow = ((_a = user === null || user === void 0 ? void 0 : user.verifiedCredentials) === null || _a === void 0 ? void 0 : _a.length) === 1 &&
|
|
95
|
+
!getUserVerifiedCredentialType.getUserVerifiedCredentialType(user, sdkApiCore.JwtVerifiedCredentialFormatEnum.Email);
|
|
96
96
|
const { t } = reactI18next.useTranslation();
|
|
97
97
|
// TODO(GVTY-1137): send a metric when we detect passkeys are not enabled by the browser/device
|
|
98
98
|
// we removed enforcing this check since we were getting false negatives
|
|
@@ -112,6 +112,7 @@ const PasskeyIntroView = () => {
|
|
|
112
112
|
setCreateWalletWithAuthenticator(withAuthenticator);
|
|
113
113
|
yield createDynamicEmbeddedWalletMutation({
|
|
114
114
|
authToken: jwt,
|
|
115
|
+
chains,
|
|
115
116
|
decodedJwt,
|
|
116
117
|
environmentId,
|
|
117
118
|
walletConnectorOptions,
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
|
-
|
|
2
|
+
import { ChainEnum } from '@dynamic-labs/sdk-api-core';
|
|
3
|
+
type PasskeyIntroViewProps = {
|
|
4
|
+
chains?: ChainEnum[];
|
|
5
|
+
};
|
|
6
|
+
export declare const PasskeyIntroView: FC<PasskeyIntroViewProps>;
|
|
7
|
+
export {};
|
|
@@ -84,11 +84,11 @@ import '../../TransactionConfirmationView/helpers/transactionErrorMessage.js';
|
|
|
84
84
|
import '../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.js';
|
|
85
85
|
import { useInternalDynamicContext } from '../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.js';
|
|
86
86
|
|
|
87
|
-
const PasskeyIntroView = () => {
|
|
87
|
+
const PasskeyIntroView = ({ chains }) => {
|
|
88
88
|
var _a;
|
|
89
|
-
const { walletConnectorOptions, environmentId, handleLogOut, onboardingOnlyJwt,
|
|
90
|
-
const isEmailRecoveryFlow = ((_a =
|
|
91
|
-
!getUserVerifiedCredentialType(
|
|
89
|
+
const { walletConnectorOptions, environmentId, handleLogOut, onboardingOnlyJwt, user, } = useInternalDynamicContext();
|
|
90
|
+
const isEmailRecoveryFlow = ((_a = user === null || user === void 0 ? void 0 : user.verifiedCredentials) === null || _a === void 0 ? void 0 : _a.length) === 1 &&
|
|
91
|
+
!getUserVerifiedCredentialType(user, JwtVerifiedCredentialFormatEnum.Email);
|
|
92
92
|
const { t } = useTranslation();
|
|
93
93
|
// TODO(GVTY-1137): send a metric when we detect passkeys are not enabled by the browser/device
|
|
94
94
|
// we removed enforcing this check since we were getting false negatives
|
|
@@ -108,6 +108,7 @@ const PasskeyIntroView = () => {
|
|
|
108
108
|
setCreateWalletWithAuthenticator(withAuthenticator);
|
|
109
109
|
yield createDynamicEmbeddedWalletMutation({
|
|
110
110
|
authToken: jwt,
|
|
111
|
+
chains,
|
|
111
112
|
decodedJwt,
|
|
112
113
|
environmentId,
|
|
113
114
|
walletConnectorOptions,
|
|
@@ -91,7 +91,8 @@ const PasskeyInitRecovery = ({ authenticatorType, }) => {
|
|
|
91
91
|
const { setShowAuthFlow } = useInternalDynamicContext.useInternalDynamicContext();
|
|
92
92
|
const { isTurnkeyWalletWithoutAuthenticator } = useIsTurnkeyWallet.useIsTurnkeyWallet();
|
|
93
93
|
const { initAuthMethod, isLoading, error } = useInitEmbeddedWalletAuthMethod.useInitEmbeddedWalletAuthMethod();
|
|
94
|
-
const
|
|
94
|
+
const { createRootElement } = useElementById.useElementById();
|
|
95
|
+
const iframeContainerRef = createRootElement(constants.iframeContainerId);
|
|
95
96
|
const { t } = reactI18next.useTranslation();
|
|
96
97
|
const errorText = React.useMemo(() => {
|
|
97
98
|
if (!error) {
|
|
@@ -87,7 +87,8 @@ const PasskeyInitRecovery = ({ authenticatorType, }) => {
|
|
|
87
87
|
const { setShowAuthFlow } = useInternalDynamicContext();
|
|
88
88
|
const { isTurnkeyWalletWithoutAuthenticator } = useIsTurnkeyWallet();
|
|
89
89
|
const { initAuthMethod, isLoading, error } = useInitEmbeddedWalletAuthMethod();
|
|
90
|
-
const
|
|
90
|
+
const { createRootElement } = useElementById();
|
|
91
|
+
const iframeContainerRef = createRootElement(iframeContainerId);
|
|
91
92
|
const { t } = useTranslation();
|
|
92
93
|
const errorText = useMemo(() => {
|
|
93
94
|
if (!error) {
|
|
@@ -24,11 +24,11 @@ require('../../../../locale/locale.cjs');
|
|
|
24
24
|
var findEmbeddedWalletFromVerifiedCredentials = require('../../../../utils/functions/findEmbeddedWalletFromVerifiedCredentials/findEmbeddedWalletFromVerifiedCredentials.cjs');
|
|
25
25
|
require('@dynamic-labs/multi-wallet');
|
|
26
26
|
require('react-international-phone');
|
|
27
|
+
var addPasskeyIdentifierToWalletConnector = require('../../../../utils/functions/addPasskeyIdentifierToWalletConnector/addPasskeyIdentifierToWalletConnector.cjs');
|
|
27
28
|
require('viem');
|
|
28
29
|
require('viem/chains');
|
|
29
30
|
|
|
30
|
-
const
|
|
31
|
-
var _b;
|
|
31
|
+
const createEmbeddedWalletRequest = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ user, walletConnector, environmentId, authToken, chains, webAuthnAttestation, withAuthenticator, }) {
|
|
32
32
|
if (!authToken) {
|
|
33
33
|
throw new utils.DynamicError('Auth token is not defined');
|
|
34
34
|
}
|
|
@@ -39,27 +39,26 @@ const createEmbeddedWalletWithPasskey = (_a) => _tslib.__awaiter(void 0, [_a], v
|
|
|
39
39
|
throw new utils.DynamicError('User is not defined');
|
|
40
40
|
}
|
|
41
41
|
walletConnector.setEmail(user.email);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
let authenticatorBody;
|
|
43
|
+
if (withAuthenticator || webAuthnAttestation !== undefined) {
|
|
44
|
+
if (!user.email) {
|
|
45
|
+
addPasskeyIdentifierToWalletConnector.addPasskeyIdentifierToWalletConnector(walletConnector, user);
|
|
46
|
+
}
|
|
47
|
+
const { attestation, challenge, displayName } = webAuthnAttestation || (yield walletConnector.getWebAuthnAttestation());
|
|
48
|
+
authenticatorBody = {
|
|
49
|
+
attestation: attestation,
|
|
50
|
+
challenge,
|
|
51
|
+
passkeyAlias: displayName,
|
|
52
|
+
};
|
|
47
53
|
}
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
attestation: attestation,
|
|
51
|
-
chains,
|
|
52
|
-
challenge,
|
|
53
|
-
environmentId,
|
|
54
|
-
passkeyAlias: displayName,
|
|
55
|
-
userJwt: authToken,
|
|
56
|
-
});
|
|
54
|
+
const signersResponse = yield embeddedWallets.createTurnkeyEmbeddedWallet(Object.assign({ chains,
|
|
55
|
+
environmentId, userJwt: authToken }, authenticatorBody));
|
|
57
56
|
const { jwt } = signersResponse;
|
|
58
57
|
const decodedJwt = decodeJwt.decodeJwt(jwt);
|
|
59
58
|
if (decodedJwt === undefined)
|
|
60
59
|
throw new utils.DynamicError('Invalid token!');
|
|
61
60
|
const primaryChain = walletConnector.connectedChain;
|
|
62
|
-
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials.findEmbeddedWalletFromVerifiedCredentials(jwt, primaryChain);
|
|
61
|
+
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials.findEmbeddedWalletFromVerifiedCredentials(jwt, [primaryChain]);
|
|
63
62
|
if (!embeddedWalletVerifiedCredential) {
|
|
64
63
|
throw new utils.DynamicError('EmbeddedWalletVerifiedCredential not found');
|
|
65
64
|
}
|
|
@@ -73,4 +72,4 @@ const createEmbeddedWalletWithPasskey = (_a) => _tslib.__awaiter(void 0, [_a], v
|
|
|
73
72
|
};
|
|
74
73
|
});
|
|
75
74
|
|
|
76
|
-
exports.
|
|
75
|
+
exports.createEmbeddedWalletRequest = createEmbeddedWalletRequest;
|