UNPKG

@thirdweb-dev/wallets

Version:

<p align="center"> <br /> <a href="https://thirdweb.com"><img src="https://github.com/thirdweb-dev/js/blob/main/legacy_packages/sdk/logo.svg?raw=true" width="200" alt=""/></a> <br /> </p> <h1 align="center">thirdweb Wallet SDK</h1> <p align="center"> <a h

312 lines • 10.8 kB
import { AuthParams, EmbeddedWalletAdditionalOptions, EmbeddedWalletConnectionArgs } from "../connectors/embedded-wallet/types"; import { ConnectParams, Connector } from "../interfaces/connector"; import { AbstractClientWallet, WalletOptions } from "./base"; export type EmbeddedWalletOptions = WalletOptions<EmbeddedWalletAdditionalOptions>; export type { AuthParams, AuthResult, EmbeddedWalletAdditionalOptions, EmbeddedWalletConnectionArgs, EmbeddedWalletOauthStrategy, } from "../connectors/embedded-wallet/types"; /** * Wallet interface to connect [Embedded Wallet](https://portal.thirdweb.com/wallets/embedded-wallet/overview) which allows developers to implement seamless onboarding and login flows for their users. * * @example * ```javascript * import { EmbeddedWallet } from "@thirdweb-dev/wallets"; * import { Ethereum } from "@thirdweb-dev/chains"; * * const wallet = new EmbeddedWallet({ * chain: Ethereum, // chain to connect to * clientId: "YOUR_CLIENT_ID", // client ID * }); * * const authResult = await wallet.authenticate({ * strategy: "google", * }); * * const walletAddress = await wallet.connect({ authResult }); * console.log("Connected as", walletAddress); * ``` * @wallet */ export declare class EmbeddedWallet extends AbstractClientWallet<EmbeddedWalletAdditionalOptions, EmbeddedWalletConnectionArgs> { /** * @internal */ connector?: Connector; /** * @internal */ static id: string; /** * @internal */ static meta: { name: string; iconURL: string; }; /** * Sends a verification email to the provided email address. * * @param email - The email address to which the verification email will be sent. * @param clientId - Your thirdweb client ID * @returns Information on the user's status and whether they are a new user. * * @example * ```typescript * EmbeddedWallet.sendVerificationEmail({ email: 'test@example.com', clientId: 'yourClientId' }) * .then(() => console.log('Verification email sent successfully.')) * .catch(error => console.error('Failed to send verification email:', error)); * ``` */ static sendVerificationEmail(options: { email: string; clientId: string; }): Promise<import("..").SendEmailOtpReturnType>; /** * Sends a verification sms to the provider phone number. * * @param phoneNumber - The phone number to which the verification sms will be sent. The phone number must contain the country code. * @param clientId - Your thirdweb client ID * @returns Information on the user's status and whether they are a new user. * * @example * ```typescript * const result = await EmbeddedWallet.sendVerificationEmail({ * phoneNumber: '+1234567890', * clientId: 'yourClientId' * }); * ``` */ static sendVerificationSms(options: { phoneNumber: string; clientId: string; }): Promise<import("..").SendEmailOtpReturnType>; /** * @internal */ get walletName(): "Embedded Wallet"; /** * @internal */ chain: EmbeddedWalletAdditionalOptions["chain"]; /** * The options for instantiating an `EmbeddedWallet` * * @param options - * The options object contains the following properties: * * ### clientId (required) * The chain to connect to by default. * * Must be a `Chain` object, from the [`@thirdweb-dev/chains`](https://www.npmjs.com/package/\@thirdweb-dev/chains) package. * * ### chain (required) * The chain to connect to by default. * * Must be a `Chain` object, from the [`@thirdweb-dev/chains`](https://www.npmjs.com/package/\@thirdweb-dev/chains) package. * * * ### chains (optional) * Provide an array of chains you want to support. * * Must be an array of `Chain` objects, from the [`@thirdweb-dev/chains`](https://www.npmjs.com/package/\@thirdweb-dev/chains) package. */ constructor(options: EmbeddedWalletOptions); protected getConnector(): Promise<Connector>; /** * auto connect the wallet if the wallet was previously connected and session is still valid */ autoConnect(connectOptions?: ConnectParams<EmbeddedWalletConnectionArgs> | undefined): Promise<string>; /** * @internal */ getConnectParams(): ConnectParams<EmbeddedWalletConnectionArgs> | undefined; /** * Get the email associated with the currently connected wallet. * @example * ```ts * ```javascript * const email = await wallet.getEmail(); * ``` */ getEmail(): Promise<string | undefined>; /** * Get the phone number associated with the currently connected wallet. * @example * ```ts * ```javascript * const email = await wallet.getPhoneNumber(); * ``` */ getPhoneNumber(): Promise<string | undefined>; /** * Get the instance of `EmbeddedWalletSdk` used by the wallet. */ getEmbeddedWalletSDK(): Promise<import("..").EmbeddedWalletSdk>; getRecoveryInformation(): Promise<import("..").AuthDetails>; /** * Send a verification code to the user's email for verification. * Use this as a prestep before calling `authenticate` with the `email_verification` strategy. * * ```javascript * const result = await wallet.sendVerificationEmail({ * email: "alice@example.com", * }); * ``` * * This method is also available as a static method on the `EmbeddedWallet` class. * ```javascript * const result = await EmbeddedWallet.sendVerificationEmail({ * email: "alice@example.com", * }) * ``` * * @param options - The `options` object contains the following properties: * ### email (required) * The email address to send verification email to. * * @returns object containing below properties: * * ```ts * { * isNewDevice: boolean; * isNewUser: boolean; * recoveryShareManagement: "USER_MANAGED" | "AWS_MANAGED"; * } * ``` * * ### isNewDevice * If user has not logged in from this device before, this will be true. * * ### isNewUser * If user is logging in for the first time, this will be true. * * ### recoveryShareManagement * Recovery share management type. Can be either `USER_MANAGED` or `AWS_MANAGED`. * */ sendVerificationEmail(options: { email: string; }): Promise<import("..").SendEmailOtpReturnType>; /** * Send a verification code to the user's phone number for verification. The phone number must contain the country code. * Use this as a pre-step before calling `authenticate` with the `phone_number_verification` strategy. * * ```js * const result = await wallet.sendVerificationSms({ * phoneNumber: "+1234567890", * }); * ``` * * This method is also available as a static method on the `EmbeddedWallet` class. * ```javascript * const result = await EmbeddedWallet.sendVerificationSms({ * phoneNumber: "+1234567890", * }); * ``` * * @param options - The `options` object contains the following properties: * ### phoneNumber (required) * The phone number to send verification SMS to. The phone number must contain the country code. * * @returns object containing below properties: * * ```ts * { * isNewDevice: boolean; * isNewUser: boolean; * recoveryShareManagement: "USER_MANAGED" | "AWS_MANAGED"; * } * ``` * * ### isNewDevice * If user has not logged in from this device before, this will be true. * * ### isNewUser * If user is logging in for the first time, this will be true. * * ### recoveryShareManagement * Recovery share management type. Can be either `USER_MANAGED` or `AWS_MANAGED`. */ sendVerificationSms(options: { phoneNumber: string; }): Promise<import("..").SendEmailOtpReturnType>; /** * Authenticate the user with any of the available auth strategies. * * @example * ```javascript * const authResult = await wallet.authenticate({ * strategy: "google", * }); * ``` * * @param params - * Choose one of the available auth strategy, which comes with different required arguments. * ```ts * // email verification * type EmailVerificationAuthParams = { * strategy: "email_verification"; * email: string; * verificationCode: string; * recoveryCode?: string; * }; * * export type EmbeddedWalletOauthStrategy = "google" | "apple" | "facebook"; * * type OauthAuthParams = { * strategy: EmbeddedWalletOauthStrategy; * openedWindow?: Window; * closeOpenedWindow?: (window: Window) => void; * }; * * // bring your own authentication * type JwtAuthParams = { * strategy: "jwt"; * jwt: string; * encryptionKey?: string; * }; * * // open iframe to send and input the verification code only * type IframeOtpAuthParams = { * strategy: "iframe_email_verification"; * email: string; * }; * * // open iframe to enter email and verification code * type IframeAuthParams = { * strategy: "iframe"; * }; * ``` * * @returns * The `authResult` object - which you can pass to the `connect` method to connect to the wallet. * * ```ts * const authResult = await wallet.authenticate(authOptions); * await wallet.connect({ authResult }); * ``` */ authenticate(params: AuthParams): Promise<import("../connectors/embedded-wallet/types").AuthResult>; /** * @internal */ getLastUsedAuthStrategy(): Promise<AuthParams["strategy"] | null>; /** * After authenticating, you can connect to the wallet by passing the `authResult` to the `connect` method. * * ```ts * const authResult = await wallet.authenticate(authOptions); * * await wallet.connect({ authResult }); * ``` * * @param connectOptions - The `connectOptions` object contains the following properties: * * ### authResult (required) * * The `authResult` object is returned from the `authenticate` method. * * @returns The address of the connected wallet. */ connect(connectOptions?: ConnectParams<EmbeddedWalletConnectionArgs> | undefined): Promise<string>; } export { supportedSmsCountries } from "../connectors/embedded-wallet/implementations/lib/auth/supported-sms-countries"; //# sourceMappingURL=embedded-wallet.d.ts.map