@privy-io/js-sdk-core
Version: 
Vanilla JS client for the Privy Auth API
1,212 lines (1,196 loc) • 317 kB
TypeScript
import { Chain, RpcConfig } from '@privy-io/chains';
export * from '@privy-io/chains';
import * as _privy_io_public_api from '@privy-io/public-api';
import { PasskeyAuthenticateInputType, PrivyEmbeddedWalletAccount, PrivyEthereumEmbeddedWalletAccount, PrivySolanaEmbeddedWalletAccount, PrivyUser, PrivySmartWalletConfigurationResponse, PrivyAuthenticatedUser, OAuthProviderType, SmartWalletType, CoinbaseOnRampInitInput, PrivyMoonpayOnRampSignInput, MfaPasskeyInitInputType, MfaSmsInitInputType, Route, PrivyBitcoinSegwitEmbeddedWalletAccount as PrivyBitcoinSegwitEmbeddedWalletAccount$1, PrivyBitcoinTaprootEmbeddedWalletAccount as PrivyBitcoinTaprootEmbeddedWalletAccount$1, PrivySmartWalletAccount, PrivyCoinbaseOnRampInitResponse, PrivyCoinbaseOnRampInitInput, WalletResponseType, WalletApiCreateInputType, WalletApiRpcResponseType, WalletApiRpcInputType, WalletUpdateInputType, PrivyUnifiedWalletAccount } from '@privy-io/public-api';
export { BICONOMY, COINBASE_SMART_WALLET, KERNEL, LIGHT_ACCOUNT, OAuthProviderType, SAFE, SmartWalletType, THIRDWEB } from '@privy-io/public-api';
import EventEmitter from 'eventemitter3';
import { PrivyErrorCode } from '@privy-io/api-base';
import { PrivyBitcoinSegwitEmbeddedWalletAccount, PrivyBitcoinTaprootEmbeddedWalletAccount, PrivySolanaEmbeddedWalletAccount as PrivySolanaEmbeddedWalletAccount$1, PrivyAuthenticatedUser as PrivyAuthenticatedUser$1, PrivyEthereumEmbeddedWalletAccount as PrivyEthereumEmbeddedWalletAccount$1 } from '@privy-io/public-api/schemas';
import { Transaction, VersionedTransaction, Connection, SendOptions } from '@solana/web3.js';
import { AuthenticationResponseJSON, RegistrationResponseJSON } from '@simplewebauthn/types';
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import * as libphonenumber_js_min from 'libphonenumber-js/min';
import { CountryCode, AsYouType } from 'libphonenumber-js/min';
export { CountryCode, getCountryCallingCode } from 'libphonenumber-js/min';
import { BigNumber, BigNumberish } from '@ethersproject/bignumber';
import { UnsignedTransaction } from '@ethersproject/transactions';
import { Hex, TypedDataDefinition } from 'viem';
type LogLevel = 'NONE' | 'ERROR' | 'WARN' | 'INFO' | 'DEBUG';
/**
 * Interface for a logger for the privy client SDK
 */
type Logger = {
    readonly level: LogLevel;
    readonly info: Console['log'];
    readonly warn: Console['warn'];
    readonly error: Console['error'];
    readonly debug: Console['debug'];
};
declare enum PrivyEmbeddedWalletErrorCode {
    MISSING_OR_INVALID_PRIVY_APP_ID = "missing_or_invalid_privy_app_id",
    MISSING_OR_INVALID_PRIVY_ACCOUNT_ID = "missing_or_invalid_privy_account_id",
    INVALID_DATA = "invalid_data",
    LINKED_TO_ANOTHER_USER = "linked_to_another_user",
    ALLOWLIST_REJECTED = "allowlist_rejected",
    OAUTH_USER_DENIED = "oauth_user_denied",
    UNKNOWN_AUTH_ERROR = "unknown_auth_error",
    USER_EXITED_AUTH_FLOW = "exited_auth_flow",
    MUST_BE_AUTHENTICATED = "must_be_authenticated",
    UNKNOWN_CONNECT_WALLET_ERROR = "unknown_connect_wallet_error",
    GENERIC_CONNECT_WALLET_ERROR = "generic_connect_wallet_error",
    CLIENT_REQUEST_TIMEOUT = "client_request_timeout",
    INVALID_CREDENTIALS = "invalid_credentials"
}
declare abstract class PrivyError extends Error {
    /**
     * Privy error type.
     */
    abstract type: string;
    /**
     * Original Error object, it the error originated client-side.
     */
    cause?: Error;
    /**
     * An optional error code, often included in Privy API responses.
     */
    privyErrorCode?: PrivyEmbeddedWalletErrorCode;
    /**
     * @param type Privy error type.
     * @param message Human-readable message.
     * @param cause Source of this error.
     */
    protected constructor(message: string, cause?: unknown, privyErrorCode?: PrivyEmbeddedWalletErrorCode);
    toString(): string;
}
/**
 * A ProviderRpcError combines the necessary bits of the {PrivyError} with the
 * EIP-compliant ProviderRpcError. This is meant to be a type around errors raised
 * by the ethereum provider.
 */
declare class ProviderRpcError extends PrivyError {
    type: string;
    readonly code: number;
    readonly data?: unknown;
    constructor(message: string, code: number, data?: unknown);
}
declare class PrivyIframeError extends Error {
    type: PrivyIframeErrorTypesType;
    constructor(type: PrivyIframeErrorTypesType, message: string);
}
declare class PrivyConnectorError extends PrivyError {
    type: string;
    constructor(message: string, cause?: unknown, privyErrorCode?: PrivyEmbeddedWalletErrorCode);
}
declare class EmbeddedProviderError extends Error {
    code: number;
    data?: unknown;
    constructor(message: string, code: number, data?: unknown);
}
declare const ProviderErrors: {
    E32002_CONNECTION_ALREADY_PENDING: {
        eipCode: number;
        message: string;
        detail: string;
        retryable: boolean;
    };
    E32002_REQUEST_ALREADY_PENDING: {
        eipCode: number;
        message: string;
        detail: string;
        retryable: boolean;
    };
    E32002_WALLET_LOCKED: {
        eipCode: number;
        message: string;
        detail: string;
        retryable: boolean;
    };
    E4001_USER_REJECTED_REQUEST: {
        eipCode: number;
        message: string;
        detail: string;
        retryable: boolean;
    };
    E4001_DEFAULT_USER_REJECTED_REQUEST: {
        eipCode: number;
        message: string;
        detail: string;
        default: boolean;
        retryable: boolean;
    };
    E4100_DEFAULT_UNAUTHORIZED: {
        eipCode: number;
        message: string;
        detail: string;
        default: boolean;
        retryable: boolean;
    };
    E4200_DEFAULT_UNSUPPORTED_METHOD: {
        eipCode: number;
        message: string;
        detail: string;
        default: boolean;
        retryable: boolean;
    };
    E4900_DEFAULT_DISCONNECTED: {
        eipCode: number;
        message: string;
        detail: string;
        default: boolean;
        retryable: boolean;
    };
    E4901_DEFAULT_CHAIN_DISCONNECTED: {
        eipCode: number;
        message: string;
        detail: string;
        default: boolean;
        retryable: boolean;
    };
    E32700_DEFAULT_PARSE_ERROR: {
        eipCode: number;
        message: string;
        detail: string;
        default: boolean;
        retryable: boolean;
    };
    E32600_DEFAULT_INVALID_REQUEST: {
        eipCode: number;
        message: string;
        detail: string;
        default: boolean;
        retryable: boolean;
    };
    E32601_DEFAULT_METHOD_NOT_FOUND: {
        eipCode: number;
        message: string;
        detail: string;
        default: boolean;
        retryable: boolean;
    };
    E32602_DEFAULT_INVALID_PARAMS: {
        eipCode: number;
        message: string;
        detail: string;
        default: boolean;
        retryable: boolean;
    };
    E32603_DEFAULT_INTERNAL_ERROR: {
        eipCode: number;
        message: string;
        detail: string;
        default: boolean;
        retryable: boolean;
    };
    E32000_DEFAULT_INVALID_INPUT: {
        eipCode: number;
        message: string;
        detail: string;
        default: boolean;
        retryable: boolean;
    };
    E32001_DEFAULT_RESOURCE_NOT_FOUND: {
        eipCode: number;
        message: string;
        detail: string;
        default: boolean;
        retryable: boolean;
    };
    E32002_DEFAULT_RESOURCE_UNAVAILABLE: {
        eipCode: number;
        message: string;
        detail: string;
        default: boolean;
        retryable: boolean;
    };
    E32003_DEFAULT_TRANSACTION_REJECTED: {
        eipCode: number;
        message: string;
        detail: string;
        default: boolean;
        retryable: boolean;
    };
    E32004_DEFAULT_METHOD_NOT_SUPPORTED: {
        eipCode: number;
        message: string;
        detail: string;
        default: boolean;
        retryable: boolean;
    };
    E32005_DEFAULT_LIMIT_EXCEEDED: {
        eipCode: number;
        message: string;
        detail: string;
        default: boolean;
        retryable: boolean;
    };
    E32006_DEFAULT_JSON_RPC_VERSION_NOT_SUPPORTED: {
        eipCode: number;
        message: string;
        detail: string;
        default: boolean;
        retryable: boolean;
    };
    UNKNOWN_ERROR: {
        eipCode: number;
        message: string;
        detail: string;
        retryable: boolean;
    };
};
declare function errorIndicatesRecoveryIsNeeded(error: unknown): error is PrivyIframeError;
declare function errorIndicatesMfaTimeout(error: unknown): error is PrivyIframeError;
declare function errorIndicatesMfaVerificationFailed(error: unknown): error is PrivyIframeError;
declare function errorIndicatesMaxMfaRetries(error: unknown): error is PrivyIframeError;
declare function errorIndicatesMfaRateLimit(error: unknown): error is PrivyIframeError;
/**
 * Represents an error message meant to display within the UI
 */
type UiErrorMessage = {
    /**
     * Main message to convey, one line
     */
    message: string;
    /**
     * Additional detail that may be relevant if it cannot be conveyed in the message
     */
    detail: string;
    /**
     * Whether this error is expected to be retryable
     */
    retryable: boolean;
};
type ProviderError = UiErrorMessage & {
    /**
     * The EIP code, either [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193#provider-errors)
     * or [EIP-1474](https://eips.ethereum.org/EIPS/eip-1474#error-codes)
     */
    eipCode: number;
    /**
     * Whether the contents (message & detail) are the default specified by the
     * EIP or if this is a custom message from our own semantic understanding of
     * the error.
     */
    default?: boolean;
};
/**
 * A PrivyProviderRpcError is a classified {ProviderRpcError}. When relevant,
 * we will attempt to replace the original messaging with our best guess of what
 * is going on.
 */
declare class PrivyProviderRpcError extends ProviderRpcError {
    details: ProviderError;
    constructor(error: unknown);
}
type ProviderConnectInfo = {
    chainId: string;
};
type OnConnectEventHandler = (connectInfo: ProviderConnectInfo) => void;
type OnDisconnectEventHandler = (error: ProviderRpcError) => void;
type OnChainChangedEventHandler = (chainId: string | number) => void;
type OnAccountsChangedEventHandler = (accounts: string[]) => void;
type ProviderMessage = {
    type: string;
    data: unknown;
};
type OnMessageEventHandler = (message: ProviderMessage) => void;
type EIP1193OnEventHandler = OnConnectEventHandler | OnDisconnectEventHandler | OnChainChangedEventHandler | OnAccountsChangedEventHandler | OnMessageEventHandler;
interface EIP1193Provider {
    request: (request: {
        method: string;
        params?: Array<unknown> | undefined;
    }) => Promise<unknown>;
    on: (eventName: string, listener: EIP1193OnEventHandler) => unknown;
    removeListener: (eventName: string | symbol, listener: (...args: unknown[]) => void) => unknown;
}
type RequestArguments = {
    method: string;
    params?: Array<any> | undefined;
};
type OnNeedsRecovery = (input: {
    recoveryMethod: EmbeddedWalletRecoveryOptions;
    onRecovered: () => void;
}) => Promise<void> | void;
declare class EmbeddedWalletProvider extends EventEmitter implements EIP1193Provider {
    request(request: RequestArguments): Promise<any>;
    /**
     * Backfills a transaction that may not specify a `chainId` with the provider's `this._chianId`
     */
    private ensureChainId;
    /**
     * If a chainId is provided that differs from the current `this._chainId`,
     * the new chain and StaticJsonRpcProvider will be set
     */
    private internalSwitchEthereumChain;
    private handlePopulateTransaction;
    private handleSendTransaction;
    private handleEstimateGas;
    private handleSwitchEthereumChain;
    private handleIFrameRpc;
    private handleJsonRpc;
    toJSON(): string;
}
type AuthAction = 'login' | 'link';
type Method = 'email' | 'sms' | 'oauth' | 'siwe' | 'passkey' | 'farcaster' | 'siws';
type ClientErrorCode = `failed_to_complete_${AuthAction}_with_oauth` | `${AuthAction}_with_oauth_returned_with_invalid_credentials` | `${AuthAction}_with_oauth_was_cancelled_by_user` | 'attempted_rpc_call_before_logged_in' | 'attempted_submit_otp_before_sending' | 'attempted_to_set_password_before_connected' | 'attempted_to_set_password_but_password_already_set' | `attempted_login_with_${Method}_while_already_logged_in` | `attempted_link_${Method}_before_logged_in` | 'attempted_link_cross_app_before_logged_in' | 'attempted_login_with_cross_app_while_already_logged_in' | 'attempted_cross_app_request_before_logged_in' | 'attempted_update_before_logged_in' | 'attempted_update_email_without_a_linked_email' | 'attempted_update_phone_without_a_linked_phone' | 'cross_app_invalid_app' | 'cross_app_read_only' | 'cross_app_invalid_wallet' | 'cross_app_request_error' | `attempted_unlink_siwe_before_logged_in` | 'oauth_session_failed' | 'oauth_session_timeout' | 'user_signer_sign_error' | 'embedded_wallet_needs_recovery' | 'embedded_wallet_creation_error' | 'embedded_wallet_recovery_error' | 'embedded_wallet_set_password_error' | 'embedded_wallet_set_recovery_error' | 'unknown_embedded_wallet_error' | 'embedded_wallet_does_not_exist' | 'embedded_wallet_already_exists' | 'embedded_wallet_webview_not_loaded' | 'embedded_wallet_request_error' | 'delegated_actions_before_logged_in' | 'delegated_actions_wallet_not_found' | 'delegated_actions_no_wallet_to_revoke' | 'no_passkey_found_for_challenge' | 'pkce_state_code_mismatch' | 'failed_to_create_passkey' | 'failed_to_generate_farcaster_uri' | 'failed_to_generate_farcaster_channel_token' | 'farcaster_polling_timeout' | 'farcaster_polling_canceled' | 'unsupported_recovery_method' | 'attempted_to_create_guest_account_for_logged_in_user' | 'attempted_to_read_storage_before_client_initialized' | 'third_party_auth_error' | 'invalid_native_app_id' | 'unsupported_mfa_method' | 'unsupported_chain_type' | 'invalid_mfa_code' | 'invalid_passkey_response' | 'storage_error' | 'smart_wallet_client_error' | 'chain_not_supported' | 'mfa_canceled' | 'configuration_error' | 'failed_to_fetch_moonpay_transaction_status';
type ErrorBody<T extends PrivyErrorCode | ClientErrorCode> = {
    error: string;
    code: T;
};
type ServerErrorBody = ErrorBody<PrivyErrorCode>;
declare class PrivyApiError extends Error {
    error: string;
    code: PrivyErrorCode;
    constructor({ error, code }: ServerErrorBody);
}
declare class PrivyClientError extends Error {
    error: string;
    code: ClientErrorCode;
    constructor({ error, code }: ErrorBody<ClientErrorCode>);
}
declare class MoonpayApiError extends Error {
    error: string;
    code: ClientErrorCode;
    response: Response;
    constructor({ error, code, response }: ErrorBody<ClientErrorCode> & {
        response: Response;
    });
}
/**
 * This type converts the {@link PrivyErrorCode} enum into a string literal union type,
 * in order to match the structure of {@link ClientErrorCode}.
 *
 * Note this is valid because the {@link PrivyErrorCode} enum is a string enum.
 */
type PrivyApiErrorCode = `${PrivyErrorCode}`;
/**
 * All possible error codes, be it from the API or the client, plus an `'unknown_error'`
 * code for unexpected errors.
 */
type ErrorCode = PrivyApiErrorCode | ClientErrorCode | 'unknown_error';
/**
 * A partial map of error codes to error messages, with a `default` message as a fallback.
 */
type ErrorMessageMap = Partial<Record<ErrorCode, string>> & {
    default: string;
};
/**
 * Takes a message map and return an error formatter, that takes an error and
 * returns the corresponding error message.
 *
 * Valid errors are all those in the classes {@link PrivyApiError} and {@link PrivyClientError}.
 * Any other error will be treated as an unknown error.
 *
 * @param messageMap The partial map used to format error messages by their error code.
 * @returns
 */
declare const createErrorFormatter: (messageMap: ErrorMessageMap) => (error: unknown) => string;
declare function errorIndicatesMfaCanceled(error: unknown): unknown;
type MfaMethod = 'sms' | 'totp' | 'passkey';
type MfaSubmitArgs = {
    mfaMethod: MfaMethod;
    mfaCode: string | PasskeyAuthenticateInputType['authenticator_response'];
    relyingParty: string;
};
type MfaPromise = {
    current: {
        resolve: (args: MfaSubmitArgs) => void;
        reject: (error: PrivyClientError) => void;
    } | null;
};
type MfaSubmitPromise = {
    current: {
        resolve: (x: undefined) => void;
        reject: (error: PrivyIframeError) => void;
    } | null;
};
/**
 * We support a subset of the provider methods found here:
 *
 *     https://ethereum.org/en/developers/docs/apis/json-rpc/#json-rpc-methods
 *
 * For now, we're focused on signing-related methods because the iframe (this code)
 * is the only place that has access to the private key and thus is the only one
 * who can create signatures. All other methods do not need the private key and
 * can therefore be implemented by clients of the iframe.
 */
type Quantity = string | number | bigint;
type UnsignedTransactionRequest = {
    from?: string;
    to?: string;
    nonce?: Quantity;
    gasLimit?: Quantity;
    gasPrice?: Quantity;
    data?: ArrayLike<number> | string;
    value?: Quantity;
    chainId?: number;
    type?: number;
    accessList?: Array<{
        address: string;
        storageKeys: Array<string>;
    }> | Array<[string, Array<string>]> | Record<string, Array<string>>;
    maxPriorityFeePerGas?: Quantity;
    maxFeePerGas?: Quantity;
};
/**
 * {@link UnsignedTransactionRequest} specifies the `chainId` field as optional,
 * which matches ethers, wagmi, and a bunch of other libraries.
 *
 * However, we need the transaction's `chainId` to ensure it does price conversion, quote
 * labeling, etc. importantly.
 *
 * > Note:
 * > If the developer does not set a `chainId` in their `UnsignedTransactionRequest`,
 * > we default to the embedded provider's  current `chainId`
 */
type UnsignedTransactionRequestWithChainId = UnsignedTransactionRequest & {
    chainId: number;
};
interface eth_populateTransactionRequestResponse {
    method: 'eth_populateTransactionRequest';
    data: UnsignedTransactionRequest;
}
interface eth_signResponse {
    method: 'eth_sign';
    data: string;
}
interface personal_signResponse {
    method: 'personal_sign';
    data: string;
}
interface eth_signTransactionResponse {
    method: 'eth_signTransaction';
    data: string;
}
interface eth_signTypedData_v4Response {
    method: 'eth_signTypedData_v4';
    data: string;
}
type RpcResponseType = eth_signTransactionResponse | eth_populateTransactionRequestResponse | eth_signResponse | personal_signResponse | eth_signTypedData_v4Response;
interface SolanaRpcResponseType {
    data: {
        signature: string;
    };
}
type BaseBitcoinRpcResponseType = {
    method: string;
    data: any;
};
/**
 * The Privy SDK(s) will return the signature as a `Uint8Array`, but the iframe must serialize it to
 * a `string` in order to pass it over the message bus. You can see how this is done in the signature handler.
 *
 * The Privy SDK(s) themselves must then deserialize the `string` to a `Uint8Array` before
 * returning the signature to the caller.
 */
interface bitcoin_signResponse extends BaseBitcoinRpcResponseType {
    method: 'sign';
    data: {
        signature: string;
    };
}
interface bitcoin_signTransactionResponse extends BaseBitcoinRpcResponseType {
    method: 'signTransaction';
    data: {
        signedTransaction: string;
    };
}
type BitcoinRpcResponseType = bitcoin_signResponse | bitcoin_signTransactionResponse;
type PrivyEventType = 'privy:iframe:ready' | 'privy:user-signer:sign' | 'privy:wallets:create' | 'privy:wallets:add' | 'privy:wallets:set-recovery' | 'privy:wallets:connect' | 'privy:wallets:recover' | 'privy:wallets:rpc' | 'privy:wallet:create' | 'privy:wallet:connect' | 'privy:wallet:recover' | 'privy:wallet:rpc' | 'privy:solana-wallet:create' | 'privy:solana-wallet:create-additional' | 'privy:solana-wallet:connect' | 'privy:solana-wallet:recover' | 'privy:solana-wallet:rpc' | 'privy:delegated-actions:consent' | 'privy:mfa:verify' | 'privy:mfa:init-enrollment' | 'privy:mfa:submit-enrollment' | 'privy:mfa:unenroll' | 'privy:mfa:clear';
type EmbeddedWalletRecoveryOptions = PrivyEmbeddedWalletAccount['recovery_method'];
type IEmbeddedWalletRecoveryOptions = EmbeddedWalletRecoveryOptions | 'icloud-native';
type PasswordRecoveryInput = {
    recoveryMethod: 'user-passcode';
    password: string;
};
type AppKeyRecoveryInput = {
    recoveryMethod: 'recovery-encryption-key';
    recoveryKey: string;
};
type CloudRecoveryInput = {
    recoveryMethod: 'google-drive' | 'icloud';
    recoveryAccessToken: string;
};
type ICloudNativeRecoveryInput = {
    recoveryMethod: 'icloud-native';
    recoverySecretOverride: string;
    iCloudRecordNameOverride: string;
};
type SetRecoveryInput = {
    wallet: PrivyEthereumEmbeddedWalletAccount | PrivySolanaEmbeddedWalletAccount;
} & (PasswordRecoveryInput | CloudRecoveryInput | ICloudNativeRecoveryInput | PrivyRecoveryInput | AppKeyRecoveryInput);
interface SetRecoveryOutput {
    /** User object with the updated embedded wallet */
    user: PrivyUser;
    /**
     * Provider for the embedded ethereum wallet.
     *
     * This value will be `null` if and only if the wallet passed in the input is not an Ethereum wallet.
     * @deprecated Get the provider instance from the `getProvider(...)` method instead.
     */
    provider: EmbeddedWalletProvider | null;
}
type BaseProxyRequest = {
    accessToken: string;
} & Partial<MfaSubmitArgs>;
type PrivyResponseBaseEventType<E extends PrivyEventType, D extends PrivyResponseDataType> = {
    id: string;
    event: E;
    data: D;
};
type ChainType = 'ethereum' | 'solana' | 'bitcoin-taproot' | 'bitcoin-segwit';
type BaseWalletsRequestData = BaseProxyRequest;
type IframeReadyResponseDataType = Record<string, never>;
type IframeReadyResponseEventType = PrivyResponseBaseEventType<'privy:iframe:ready', IframeReadyResponseDataType>;
type WalletsCreateResponseDataType = {
    address: string;
};
type WalletsCreateResponseEventType = PrivyResponseBaseEventType<'privy:wallets:create', WalletsCreateResponseDataType>;
type EntropyIdVerifier = 'ethereum-address-verifier' | 'solana-address-verifier';
type UserSignerSignResponseDataType = {
    /** The signature */
    signature: string;
};
type UserSignerSignResponseEventType = PrivyResponseBaseEventType<'privy:user-signer:sign', UserSignerSignResponseDataType>;
type WalletsAddResponseDataType = {
    address: string;
};
type WalletsAddResponseEventType = PrivyResponseBaseEventType<'privy:wallets:add', WalletsAddResponseDataType>;
type WalletsSetRecoveryBaseRequestDataType = BaseWalletsRequestData & {
    /**
     * Key with which to look up the existing entropy
     */
    entropyId: string;
    /**
     * Source of the `entropyId` property. This field determines how the entropyId will
     * be used. Possible values include:
     * - ethereum-address-verifier: the entropyId is the address of the Ethereum wallet derived
     * at index 0 for this entropy
     * - solana-address-verifier: the entropyId is a the address of the Solana wallet derived
     * at index 0 for this entropy
     *
     * When this field is a wallet address, we can verify reconstitution was successful by
     * deriving the specified wallet and comparing the address to the `entropyId`
     */
    entropyIdVerifier: EntropyIdVerifier;
    existingRecoveryMethod?: EmbeddedWalletRecoveryOptions;
};
type WalletsSetRecoveryPasswordDataType = WalletsSetRecoveryBaseRequestDataType & {
    recoveryMethod: 'user-passcode';
    recoveryPassword: string;
};
type WalletsSetRecoveryGoogleDriveDataType = WalletsSetRecoveryBaseRequestDataType & {
    recoveryMethod: 'google-drive';
    recoveryAccessToken: string;
};
type WalletsSetRecoveryICloudDataType = WalletsSetRecoveryBaseRequestDataType & {
    recoveryMethod: 'icloud';
    recoveryAccessToken: string;
};
type WalletsSetRecoveryICloudNativeDataType = WalletsSetRecoveryBaseRequestDataType & {
    recoveryMethod: 'icloud-native';
    recoverySecretOverride: string;
    iCloudRecordNameOverride: string;
};
type WalletsRecoveryEncyrptionKeyDataType = WalletsSetRecoveryBaseRequestDataType & {
    recoveryMethod: 'recovery-encryption-key';
    recoveryKey: string;
};
type WalletsSetRecoveryRequestDataType = Omit<WalletsSetRecoveryPasswordDataType, 'chainType'> | Omit<WalletsSetRecoveryGoogleDriveDataType, 'chainType'> | Omit<WalletsSetRecoveryICloudDataType, 'chainType'> | Omit<WalletsSetRecoveryICloudNativeDataType, 'chainType'> | Omit<WalletsRecoveryEncyrptionKeyDataType, 'chainType'>;
type WalletsSetRecoveryResponseDataType = {
    entropyId: string;
    entropyIdVerifier: EntropyIdVerifier;
    recoveryMethod: WalletsSetRecoveryRequestDataType['recoveryMethod'];
};
type WalletsSetRecoveryResponseEventType = PrivyResponseBaseEventType<'privy:wallets:set-recovery', WalletsSetRecoveryResponseDataType>;
type WalletsConnectResponseDataType = {
    entropyId: string;
};
type WalletsConnectResponseEventType = PrivyResponseBaseEventType<'privy:wallets:connect', WalletsConnectResponseDataType>;
type WalletsRecoverResponseDataType = {
    entropyId: string;
};
type WalletsRecoverResponseEventType = PrivyResponseBaseEventType<'privy:wallets:recover', WalletsRecoverResponseDataType>;
type WalletsRpcEthereumResponseDataType = {
    chainType: 'ethereum';
    response: RpcResponseType;
};
type WalletsRpcSolanaResponseDataType = {
    chainType: 'solana';
    response: SolanaRpcResponseType;
};
type WalletsRpcBitcoinResponseDataType = {
    chainType: 'bitcoin-taproot' | 'bitcoin-segwit';
    response: BitcoinRpcResponseType;
};
type WalletsRpcResponseDataType = {
    address: string;
} & (WalletsRpcEthereumResponseDataType | WalletsRpcSolanaResponseDataType | WalletsRpcBitcoinResponseDataType);
type WalletsRpcResponseEventType = PrivyResponseBaseEventType<'privy:wallets:rpc', WalletsRpcResponseDataType>;
type WalletCreateResponseDataType = {
    address: string;
};
type WalletCreateResponseEventType = PrivyResponseBaseEventType<'privy:wallet:create', WalletCreateResponseDataType>;
type WalletConnectResponseDataType = {
    address: string;
};
type WalletConnectResponseEventType = PrivyResponseBaseEventType<'privy:wallet:connect', WalletConnectResponseDataType>;
type WalletRecoverResponseDataType = {
    address: string;
};
type WalletRecoverResponseEventType = PrivyResponseBaseEventType<'privy:wallet:recover', WalletRecoverResponseDataType>;
type WalletRpcResponseDataType = {
    address: string;
    response: RpcResponseType;
};
type WalletRpcResponseEventType = PrivyResponseBaseEventType<'privy:wallet:rpc', WalletRpcResponseDataType>;
type SolanaWalletCreateResponseDataType = {
    publicKey: string;
};
type SolanaWalletCreateResponseEventType = PrivyResponseBaseEventType<'privy:solana-wallet:create', SolanaWalletCreateResponseDataType>;
type SolanaWalletCreateAdditionalResponseDataType = {
    publicKey: string;
};
type SolanaWalletCreateAdditionalResponseEventType = PrivyResponseBaseEventType<'privy:solana-wallet:create-additional', SolanaWalletCreateAdditionalResponseDataType>;
type SolanaWalletConnectResponseDataType = {
    publicKey: string;
};
type SolanaWalletConnectResponseEventType = PrivyResponseBaseEventType<'privy:solana-wallet:connect', SolanaWalletConnectResponseDataType>;
type SolanaWalletRecoverResponseDataType = {
    publicKey: string;
};
type SolanaWalletRecoverResponseEventType = PrivyResponseBaseEventType<'privy:solana-wallet:recover', SolanaWalletRecoverResponseDataType>;
type SolanaWalletRpcResponseDataType = {
    publicKey: string;
    response: SolanaRpcResponseType;
};
type SolanaWalletRpcResponseEventType = PrivyResponseBaseEventType<'privy:solana-wallet:rpc', SolanaWalletRpcResponseDataType>;
type RootWalletForDelegation = {
    /** Address of the root wallet for the entropy being delegated. */
    address: string;
    /** Chain type of the root wallet for the entropy being delegated. */
    chainType: 'ethereum' | 'solana';
    /** Whether or not the root wallet for the entropy being delegated is imported. */
    imported: boolean;
};
type DelegatedWallet = {
    /** Address for a wallet to delegate. */
    address: string;
    /** Chain type for a wallet to delegate. */
    chainType: 'ethereum' | 'solana';
    /** HD index for the wallet to delegate. */
    walletIndex: number;
};
type DelegatedActionsConsentResponseDataType = {
    success: boolean;
};
type DelegatedActionsConsentResponseEventType = PrivyResponseBaseEventType<'privy:delegated-actions:consent', DelegatedActionsConsentResponseDataType>;
type MfaVerifyResponseDataType = Record<string, never>;
type MfaVerifyResponseEventType = PrivyResponseBaseEventType<'privy:mfa:verify', MfaVerifyResponseDataType>;
type MfaInitEnrollmentResponseDataType = {
    method: string;
    secret?: string;
    authUrl?: string;
};
type MfaInitEnrollmentResponseEventType = PrivyResponseBaseEventType<'privy:mfa:init-enrollment', MfaInitEnrollmentResponseDataType>;
type MfaSubmitEnrollmentResponseDataType = Record<string, never>;
type MfaSubmitEnrollmentResponseEventType = PrivyResponseBaseEventType<'privy:mfa:submit-enrollment', MfaSubmitEnrollmentResponseDataType>;
type MfaUnenrollResponseDataType = Record<string, never>;
type MfaUnenrollResponseEventType = PrivyResponseBaseEventType<'privy:mfa:unenroll', MfaUnenrollResponseDataType>;
type MfaClearResponseDataType = Record<string, never>;
type MfaClearResponseEventType = PrivyResponseBaseEventType<'privy:mfa:clear', MfaClearResponseDataType>;
type PrivyResponseDataType = IframeReadyResponseDataType | UserSignerSignResponseDataType | WalletsCreateResponseDataType | WalletsAddResponseDataType | WalletsSetRecoveryResponseDataType | WalletsConnectResponseDataType | WalletsRecoverResponseDataType | WalletsRpcResponseDataType | WalletCreateResponseDataType | WalletConnectResponseDataType | WalletRecoverResponseDataType | WalletRpcResponseDataType | SolanaWalletCreateResponseDataType | SolanaWalletConnectResponseDataType | SolanaWalletRecoverResponseDataType | SolanaWalletRpcResponseDataType | DelegatedActionsConsentResponseDataType | MfaVerifyResponseDataType | MfaInitEnrollmentResponseDataType | MfaSubmitEnrollmentResponseDataType | MfaUnenrollResponseDataType | MfaClearResponseDataType;
declare const PrivyIframeErrorTypes: readonly ["error", "invalid_request_arguments", "wallet_not_on_device", "invalid_recovery_pin", "insufficient_funds", "mfa_timeout", "missing_or_invalid_mfa", "mfa_verification_max_attempts_reached"];
type PrivyIframeErrorTypesType = (typeof PrivyIframeErrorTypes)[number];
type PrivyErrorResponseEventType = PrivyResponseBaseEventType<PrivyEventType, PrivyResponseDataType> & {
    error: {
        type: PrivyIframeErrorTypesType;
        message: string;
    };
};
type PrivyResponseEvent = IframeReadyResponseEventType | PrivyErrorResponseEventType | UserSignerSignResponseEventType | WalletsCreateResponseEventType | WalletsAddResponseEventType | WalletsSetRecoveryResponseEventType | WalletsConnectResponseEventType | WalletsRecoverResponseEventType | WalletsRpcResponseEventType | WalletCreateResponseEventType | WalletConnectResponseEventType | WalletRecoverResponseEventType | WalletRpcResponseEventType | SolanaWalletCreateResponseEventType | SolanaWalletCreateAdditionalResponseEventType | SolanaWalletConnectResponseEventType | SolanaWalletRecoverResponseEventType | SolanaWalletRpcResponseEventType | DelegatedActionsConsentResponseEventType | MfaVerifyResponseEventType | MfaInitEnrollmentResponseEventType | MfaSubmitEnrollmentResponseEventType | MfaUnenrollResponseEventType | MfaClearResponseEventType;
type EmbeddedWalletMessagePoster = {
    postMessage: (message: any, targetOrigin: string, transfer?: Transferable) => void;
    reload: () => void;
};
type PreparedTransactionRequestEIP1559 = UnsignedTransactionRequest & {
    from: string;
    to: string;
    nonce: Quantity;
    chainId: number;
    gasLimit: Quantity;
    type: 2;
    maxFeePerGas: Quantity;
};
type PreparedTransactionRequestLegacy = UnsignedTransactionRequest & {
    from: string;
    to: string;
    nonce: Quantity;
    chainId: number;
    gasLimit: Quantity;
    type: 0 | 1;
    gasPrice: Quantity;
};
type PreparedTransactionRequest = PreparedTransactionRequestEIP1559 | PreparedTransactionRequestLegacy;
interface Storage {
    get(key: string): unknown | Promise<unknown>;
    put(key: string, value: unknown): void | Promise<void>;
    del(key: string): void | Promise<void>;
    getKeys(): string[] | Promise<string[]>;
}
type NonEmptyArray<T> = [T, ...T[]];
declare class AppApi {
    private _smartWalletConfig;
    getConfig(): {
        id: string;
        name: string;
        logo_url: string | null;
        icon_url: string | null;
        terms_and_conditions_url: string | null;
        privacy_policy_url: string | null;
        require_users_accept_terms: boolean | null;
        theme: string;
        accent_color: string | null;
        show_wallet_login_first: boolean;
        allowed_domains: string[];
        allowed_native_app_ids: string[];
        allowed_native_app_url_schemes: string[];
        wallet_auth: boolean;
        email_auth: boolean;
        sms_auth: boolean;
        google_oauth: boolean;
        twitter_oauth: boolean;
        discord_oauth: boolean;
        github_oauth: boolean;
        spotify_oauth: boolean;
        instagram_oauth: boolean;
        tiktok_oauth: boolean;
        linkedin_oauth: boolean;
        apple_oauth: boolean;
        farcaster_auth: boolean;
        passkey_auth: boolean;
        passkeys_for_signup_enabled: boolean;
        telegram_auth: boolean;
        guest_auth: boolean;
        solana_wallet_auth: boolean;
        custom_jwt_auth: boolean;
        disable_plus_emails: boolean;
        allowlist_enabled: boolean;
        allowlist_config: {
            error_title: string | null;
            error_detail: string | null;
            cta_text: string | null;
            cta_link: string | null;
        };
        wallet_connect_cloud_project_id: string | null;
        custom_api_url: string | null;
        embedded_wallet_config: {
            mode: "legacy-embedded-wallets-only" | "user-controlled-server-wallets-only";
            solana: {
                create_on_login: "users-without-wallets" | "all-users" | "off";
            };
            create_on_login: "users-without-wallets" | "all-users" | "off";
            ethereum: {
                create_on_login: "users-without-wallets" | "all-users" | "off";
            };
            user_owned_recovery_options: ("user-passcode" | "google-drive" | "icloud")[];
            require_user_owned_recovery_on_create?: boolean | undefined;
            require_user_password_on_create?: boolean | undefined;
        };
        enforce_wallet_uis: boolean;
        legacy_wallet_ui_config: boolean;
        fiat_on_ramp_enabled: boolean;
        captcha_enabled: boolean;
        twitter_oauth_on_mobile_enabled: boolean;
        mfa_methods: ("sms" | "totp" | "passkey")[];
        verification_key: string;
        max_linked_wallets_per_user: number | null;
        farcaster_link_wallets_enabled: boolean;
        whatsapp_enabled: boolean;
        captcha_site_key?: string | undefined;
        telegram_auth_config?: {
            bot_id: string;
            bot_name: string;
            link_enabled: boolean;
            seamless_auth_enabled: boolean;
        } | undefined;
        funding_config?: {
            options: {
                method: string;
                provider: string;
            }[];
            default_recommended_currency: {
                chain: string;
                asset?: "native-currency" | "USDC" | undefined;
            };
            default_recommended_amount: string;
            methods: ("moonpay" | "coinbase-onramp" | "external")[];
            prompt_funding_on_wallet_creation: boolean;
            cross_chain_bridging_enabled: boolean;
        } | undefined;
    } | undefined;
    getSmartWalletConfig(): Promise<PrivySmartWalletConfigurationResponse>;
    get appId(): string;
}
declare class CrossAppApi {
    /** Defines the format of the storage key for provider access tokens */
    private static providerAccessTokenStorageKey;
    /**
     * Updates the stored token information of a given cross-app provider.
     * @param providerAppId the Privy app ID to which the oauth tokens correspond.
     * @param tokens should be the result of cross app authentication (be it login or linking).
     */
    updateOnCrossAppAuthentication(providerAppId: string, tokens: OAuthTokens): Promise<void>;
    /**
     * Returns the last known access token for a given cross-app provider.
     * @param providerAppId the Privy app ID on which you want to act.
     */
    getProviderAccessToken(providerAppId: string): Promise<string | null>;
    /**
     * Fetches the metadata of all cross-app connections for the current app.
     */
    getCrossAppConnections(): Promise<_privy_io_public_api.PrivyCrossAppConnectionsResponse>;
}
type OAuthTokens = NonNullable<PrivyAuthenticatedUser['oauth_tokens']>;
declare class DelegatedWalletsApi {
    /**
     * Revokes delegation permission of all the wallets associated with the user.
     */
    revoke(): Promise<void>;
}
type SignMessageRequestArguments = {
    method: 'signMessage';
    params: {
        message: string;
    };
};
type SignAndSendTransactionRequestArguments = {
    method: 'signAndSendTransaction';
    params: {
        transaction: Transaction | VersionedTransaction;
        connection: Connection;
        options?: SendOptions;
    };
};
type SignTransactionRequestArguments<T extends Transaction | VersionedTransaction = Transaction> = {
    method: 'signTransaction';
    params: {
        transaction: T;
    };
};
/**
 * Privy embedded wallet provider for Solana accounts.
 *
 * Currently only supports signing messages.
 */
declare class EmbeddedSolanaWalletProvider {
    request(request: SignMessageRequestArguments): Promise<{
        signature: string;
    }>;
    request(request: SignAndSendTransactionRequestArguments): Promise<{
        signature: string;
    }>;
    request<T extends Transaction | VersionedTransaction>(request: SignTransactionRequestArguments<T>): Promise<{
        signedTransaction: T;
    }>;
    /**
     * Legacy API for reading the public key for this provider.
     *
     * @deprecated
     */
    get _publicKey(): string;
    /**
     * Preemptively check if the wallet is connected and trigger recovery if needed,
     * either automatically or via an onNeedsRecovery callback.
     */
    private connectAndRecover;
    private handleIFrameRpc;
    private handleSignAndSendTransaction;
    private handleSignTransaction;
    /**
     * Pretty log output for when an instance of this class is `console.log`'d
     */
    toJSON(): string;
}
/**
 * Privy embedded wallet provider for Bitcoin accounts.
 *
 * Currently only supports signing messages.
 */
declare class EmbeddedBitcoinWalletProvider {
    /**
     * Sign an arbitrary message
     *
     * @param o the input object
     * @param o.message a byte array to sign
     *
     * @returns a base64-endoed signature
     */
    sign({ message }: {
        message: Uint8Array;
    }): Promise<{
        signature: string;
    }>;
    /**
     * Sign an encoded transaction
     *
     * @param o the input object
     * @param o.txPSBT a bitcoin transaction in PSBT format, hex-encoded
     *
     * @returns a hex-encoded signed transaction
     */
    signTransaction({ psbt }: {
        psbt: string;
    }): Promise<{
        signedTransaction: string;
    }>;
    private request;
    private handleIFrameRpc;
    /**
     * Pretty log output for when an instance of this class is `console.log`'d
     */
    toJSON(): string;
}
/** Options for creating the Solana embedded wallet */
type CreateSolanaOpts = {
    /**
     * The user's existing Ethereum embedded wallet if they have one. This parameter
     * MUST be set if the user has an Ethereum embedded wallet, otherwise Solana creation
     * will fail in the iframe.
     */
    ethereumAccount?: PrivyEthereumEmbeddedWalletAccount$1;
};
declare class EmbeddedWalletApi {
    /**
     * Add a new embedded wallet account.
     *
     * Requires that the user already have created an embedded wallet via `create`.
     *
     * @param o input options
     * @param o.chainType the type of wallet to create
     * @param o.hdWalletIndex the index of the wallet to create
     * @param o.entropyId the key used to look up the existing wallet
     * @param o.entropyIdVerifier the method used to verify the entropy ID
     *
     * @returns the updated user
     */
    add(opts: {
        chainType: ChainType;
        hdWalletIndex: number;
        entropyId: string;
        entropyIdVerifier: EntropyIdVerifier;
    }): Promise<{
        user: {
            id: string;
            mfa_methods: ({
                type: "sms";
                verified_at: number;
            } | {
                type: "totp";
                verified_at: number;
            } | {
                type: "passkey";
                verified_at: number;
            })[];
            linked_accounts: ({
                type: "email";
                address: string;
                verified_at: number;
                first_verified_at: number | null;
                latest_verified_at: number | null;
            } | {
                type: "phone";
                verified_at: number;
                first_verified_at: number | null;
                latest_verified_at: number | null;
                phoneNumber: string;
            } | {
                type: "wallet";
                address: string;
                verified_at: number;
                first_verified_at: number | null;
                latest_verified_at: number | null;
                chain_type: "ethereum";
                wallet_client: "unknown";
                chain_id?: string | undefined;
                wallet_client_type?: string | undefined;
                connector_type?: string | undefined;
            } | {
                type: "smart_wallet";
                address: string;
                smart_wallet_type: "safe" | "kernel" | "biconomy" | "light_account" | "coinbase_smart_wallet" | "thirdweb";
                verified_at: number;
                first_verified_at: number | null;
                latest_verified_at: number | null;
            } | {
                type: "wallet";
                address: string;
                verified_at: number;
                first_verified_at: number | null;
                latest_verified_at: number | null;
                chain_type: "solana";
                wallet_client: "unknown";
                wallet_client_type?: string | undefined;
                connector_type?: string | undefined;
            } | {
                type: "farcaster";
                fid: number;
                verified_at: number;
                first_verified_at: number | null;
                latest_verified_at: number | null;
                owner_address: string;
                username?: string | undefined;
                display_name?: string | undefined;
                bio?: string | undefined;
                profile_picture?: string | undefined;
                profile_picture_url?: string | undefined;
                homepage_url?: string | undefined;
                signer_public_key?: string | undefined;
            } | {
                type: "passkey";
                verified_at: number;
                first_verified_at: number | null;
                latest_verified_at: number | null;
                credential_id: string;
                enrolled_in_mfa: boolean;
                created_with_browser?: string | undefined;
                created_with_os?: string | undefined;
                created_with_device?: string | undefined;
                authenticator_name?: string | undefined;
            } | {
                telegramUserId: string;
                firstName: string | null | undefined;
                type: "telegram";
                verified_at: number;
                first_verified_at: number | null;
                latest_verified_at: number | null;
                telegram_user_id: string;
                username?: string | null | undefined;
                first_name?: string | null | undefined;
                last_name?: string | null | undefined;
                photo_url?: string | null | undefined;
            } | {
                type: "wallet";
                id: string | null;
                address: string;
                chain_id: string;
                verified_at: number;
                first_verified_at: number | null;
                latest_verified_at: number | null;
                chain_type: "ethereum";
                wallet_client: "privy";
                wallet_client_type: "privy";
                connector_type: "embedded";
                imported: boolean;
                delegated: boolean;
                wallet_index: number;
                recovery_method: "user-passcode" | "google-drive" | "icloud" | "privy" | "recovery-encryption-key" | "privy-v2";
            } | {
                type: "wallet";
                id: string | null;
                address: string;
                public_key: string;
                chain_id: string;
                verified_at: number;
                first_verified_at: number | null;
                latest_verified_at: number | null;
                chain_type: "solana";
                wallet_client: "privy";
                wallet_client_type: "privy";
                connector_type: "embedded";
                imported: boolean;
                delegated: boolean;
                wallet_index: number;
                recovery_method: "user-passcode" | "google-drive" | "icloud" | "privy" | "recovery-encryption-key" | "privy-v2";
            } | {
                type: "wallet";
                id: string | null;
                address: string;
                public_key: string;
                chain_id: string;
                verified_at: number;
                first_verified_at: number | null;
                latest_verified_at: number | null;
                chain_type: "bitcoin-segwit";
                wallet_client: "privy";
                wallet_client_type: "privy";
                connector_type: "embedded";
                imported: boolean;
                delegated: boolean;
                wallet_index: number;
                recovery_method: "user-passcode" | "google-drive" | "icloud" | "privy" | "recovery-encryption-key" | "privy-v2";
            } | {
                type: "wallet";
                id: string | null;
                address: string;
                public_key: string;
                chain_id: string;
                verified_at: number;
                first_verified_at: number | null;
                latest_verified_at: number | null;
                chain_type: "bitcoin-taproot";
                wallet_client: "privy";
                wallet_client_type: "privy";
                connector_type: "embedded";
                imported: boolean;
                delegated: boolean;
                wallet_index: number;
                recovery_method: "user-passcode" | "google-drive" | "icloud" | "privy" | "recovery-encryption-key" | "privy-v2";
            } | {
                type: "google_oauth";
                name: string | null;
                email: string;
                verified_at: number;
                first_verified_at: number | null;
                latest_verified_at: number | null;
                subject: string;
            } | {
                type: "twitter_oauth";
                name: string | null;
                username: string | null;
                verified_at: number;
                first_verified_at: number | null;
                latest_verified_at: number | null;
                profile_picture_url: string | null;
                subject: string;
            } | {
                type: "discord_oauth";
                email: string | null;
                username: string | null;
                verified_at: number;
                first_verified_at: number | null;
                latest_verified_at: number | null;
                subject: string;
            } | {
                type: "github_oauth";
                name: string | null;
                email: string | null;
                username: string | null;
                verified_at: number;
                first_verified_at: number | null;
                latest_verified_at: number | null;
                subject: string;
            } | {
                type: "linkedin_oauth";
                email: string | null;
                verified_at: number;
                first_verified_at: number | null;
                latest_verified_at: number | null;
                subject: string;
                name?: string | undefined;
                vanity_name?: string | undefined;
            } | {
                type: "spotify_oauth";
                name: string | null;
                email: string | null;
                verified_at: number;
                first_verified_at: number | null;
                latest_verified_at: number | null;
                subject: string;
            } | {
                type: "instagram_oauth";
                username: string | null;
                verified_at: number;
                first_verified_at: number | null;
                latest_verified_at: number | null;
                subject: string;
            } | {