UNPKG

@dynamic-labs/sdk-react-core

Version:

A React SDK for implementing wallet web3 authentication and authorization to your website.

69 lines (66 loc) 3.34 kB
'use client' import { __awaiter } from '../../../../../../_virtual/_tslib.js'; import { DynamicError } from '@dynamic-labs/utils'; import '@dynamic-labs/sdk-api-core'; import '../../../../config/ApiEndpoint.js'; import '../../../../store/state/projectSettings/projectSettings.js'; import { findEmbeddedWalletFromVerifiedCredentials } from '../../../../utils/functions/findEmbeddedWalletFromVerifiedCredentials/findEmbeddedWalletFromVerifiedCredentials.js'; import '../../../../utils/constants/values.js'; import '@dynamic-labs/multi-wallet'; import '../../../../shared/logger.js'; import '../../../../utils/constants/colors.js'; import 'react-international-phone'; import '@dynamic-labs/iconic'; import '@dynamic-labs/wallet-connector-core'; import 'react'; import 'react/jsx-runtime'; import '../../../../context/ViewContext/ViewContext.js'; import '@dynamic-labs/wallet-book'; import '../../../../shared/consts/index.js'; import '../../../../store/state/nonce/nonce.js'; import { addPasskeyIdentifierToWalletConnector } from '../../../../utils/functions/addPasskeyIdentifierToWalletConnector/addPasskeyIdentifierToWalletConnector.js'; import '../../../../store/state/dynamicContextProps/dynamicContextProps.js'; import '../../../../store/state/primaryWalletId/primaryWalletId.js'; import '../../../../store/state/user/user.js'; import '../../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js'; import { createTurnkeyEmbeddedWallet } from '../../../../data/api/embeddedWallets/embeddedWallets.js'; import '../../../../locale/locale.js'; const createEmbeddedWalletRequest = (_a) => __awaiter(void 0, [_a], void 0, function* ({ user, walletConnector, environmentId, chains, sessionPublicKey, webAuthnAttestation, withAuthenticator, }) { if (!walletConnector) { throw new DynamicError('Connector is missing. Please make sure you added EthereumWalletConnectors and/or SolanaWalletConnectors to DynamicProvider settings'); } if (!user) { throw new DynamicError('User is not defined'); } walletConnector.setEmail(user.email); let authenticatorBody; if (withAuthenticator || webAuthnAttestation !== undefined) { if (!user.email) { addPasskeyIdentifierToWalletConnector(walletConnector, user); } const { attestation, challenge, displayName } = webAuthnAttestation || (yield walletConnector.getWebAuthnAttestation()); authenticatorBody = { attestation: attestation, challenge, passkeyAlias: displayName, }; } const updatedUser = yield createTurnkeyEmbeddedWallet(Object.assign({ chains, environmentId, sessionPublicKey }, authenticatorBody)); if (!updatedUser) { throw new DynamicError('Failed to create embedded wallet'); } const primaryChain = walletConnector.connectedChain; const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(updatedUser, [primaryChain]); if (!embeddedWalletVerifiedCredential) { throw new DynamicError('EmbeddedWalletVerifiedCredential not found'); } walletConnector.setVerifiedCredentials(updatedUser.verifiedCredentials); return { embeddedWalletVerifiedCredential, updatedUser, walletConnector, }; }); export { createEmbeddedWalletRequest };