@privy-io/react-auth
Version:
React client for the Privy Auth API
323 lines (307 loc) • 12.3 kB
text/typescript
import { g as SessionSignerInput, W as Wallet, f as SignMessageModalUIOptions, S as SolanaChain, h as SolanaStandardWallet, C as CreateWalletOptions, e as SendTransactionModalUIOptions, i as SolanaFundingConfig } from './types-D7U23FgR.js';
export { j as SolanaAdapterConnector, t as toSolanaWalletConnectors } from './types-D7U23FgR.js';
import { SolanaSignAndSendTransactionFeature, SolanaSignTransactionFeature, SolanaSignMessageFeature } from '@solana/wallet-standard-features';
import { WalletAccount, WalletIcon, WalletVersion } from '@wallet-standard/base';
import { StandardConnectFeature, StandardDisconnectFeature, StandardEventsFeature } from '@wallet-standard/features';
import EventEmitter from 'eventemitter3';
import { SolanaSignAndSendTransactionOptions, SolanaSignTransactionOptions, ConnectedStandardSolanaWallet } from '@privy-io/js-sdk-core';
export { ConnectedStandardSolanaWallet } from '@privy-io/js-sdk-core';
import { P as PrivyEvents } from './events-context-BYT6PpDG.js';
import '@coinbase/wallet-sdk';
import '@simplewebauthn/browser';
import '@solana/kit';
import 'react';
import 'viem';
import '@privy-io/api-types';
import '@base-org/account';
interface UseImportWalletInterface {
/**
* Imports a private key to be used as an embedded wallet for the user
* This method will error if the user exits in the middle of the flow.
*
* @param o Input object
* @param o.privateKey The base58 private key of the solana wallet to import
* @param o.additionalSigners Optional additional signers for the wallet. Only supported for TEE wallets.
*
* @returns The imported wallet
*/
importWallet: (input: {
privateKey: string;
additionalSigners?: SessionSignerInput;
}) => Promise<Wallet>;
}
/**
* Use this hook to import an external solana wallet into an embedded wallet via its private key
*
* @returns The `importWallet` method
*/
declare const useImportWallet: () => UseImportWalletInterface;
declare const useSolanaFundingPlugin: () => void;
declare const useSolanaLedgerPlugin: () => void;
/**
* Object representation of a Privy Solana wallet account.
*/
declare class PrivyWalletAccount implements WalletAccount {
#private;
get address(): string;
get publicKey(): Uint8Array;
get chains(): `${string}:${string}`[];
get features(): `${string}:${string}`[];
get label(): string | undefined;
get icon(): `data:image/svg+xml;base64,${string}` | `data:image/webp;base64,${string}` | `data:image/png;base64,${string}` | `data:image/gif;base64,${string}` | undefined;
constructor({ address, publicKey, label, icon }: Omit<WalletAccount, 'chains' | 'features'>);
}
/**
* Standard wallet implementation interface
*/
interface StandardWalletImplementation {
/**
* Sign a message.
*/
signMessage(args: {
message: Uint8Array;
address: string;
options?: {
uiOptions?: SignMessageModalUIOptions;
};
}): Promise<{
signature: Uint8Array;
}>;
/**
* Sign and send a transaction.
*/
signAndSendTransaction(args: {
transaction: Uint8Array;
address: string;
chain: SolanaChain;
sponsor?: boolean;
options?: SolanaSignAndSendTransactionOptions;
}): Promise<{
signature: Uint8Array;
}>;
/**
* Sign a transaction without sending it to the network.
*/
signTransaction(args: {
transaction: Uint8Array;
address: string;
chain: SolanaChain;
options?: SolanaSignTransactionOptions;
}): Promise<{
signedTransaction: Uint8Array;
}>;
}
type StandardWalletInjectionEvents = {
accountChanged: (accounts?: Array<{
address: string;
}>) => void;
};
/**
* Event emitter for the provider solana injection.
* This provides all the methods to sign messages, transactions, etc.
* Implementation is updated everytime the references to the wallets change.
*/
declare class StandardWalletInjection extends EventEmitter<StandardWalletInjectionEvents> {
#private;
constructor(implementation: StandardWalletImplementation);
setImplementation(implementation: StandardWalletImplementation): void;
signMessage(args: Parameters<StandardWalletImplementation['signMessage']>[0]): Promise<{
signature: Uint8Array;
}>;
signAndSendTransaction(args: Parameters<StandardWalletImplementation['signAndSendTransaction']>[0]): Promise<{
signature: Uint8Array;
}>;
signTransaction(args: Parameters<StandardWalletImplementation['signTransaction']>[0]): Promise<{
signedTransaction: Uint8Array;
}>;
}
type PrivyFeature = {
'privy:': {
privy: StandardWalletImplementation;
};
};
/**
* Privy standard wallet implementation.
*/
declare class PrivyStandardWallet implements SolanaStandardWallet {
#private;
get version(): "1.0.0";
get name(): string;
get icon(): `data:image/svg+xml;base64,${string}` | `data:image/webp;base64,${string}` | `data:image/png;base64,${string}` | `data:image/gif;base64,${string}`;
get chains(): ("solana:mainnet" | "solana:devnet" | "solana:testnet")[];
get features(): StandardConnectFeature & StandardDisconnectFeature & StandardEventsFeature & SolanaSignAndSendTransactionFeature & SolanaSignTransactionFeature & SolanaSignMessageFeature & PrivyFeature;
get accounts(): PrivyWalletAccount[];
get isPrivyWallet(): boolean;
constructor({ name, icon, version, injection, wallets, }: {
name: string;
icon: WalletIcon;
version: WalletVersion;
injection: StandardWalletInjection;
wallets: Array<{
address: string;
}>;
});
}
/**
* Use this hook to get the wallets that implement the Solana Standard Wallet interface.
*/
interface UseWallets {
/**
* Whether the wallets are ready to be used.
*/
ready: boolean;
/**
* The connected wallets.
*/
wallets: ConnectedStandardSolanaWallet[];
}
declare function useWallets(): UseWallets;
/**
* Use this hook to get the wallets that implement the Solana Standard Wallet interface.
*/
interface UseSolanaStandardWalletsInterface {
/**
* Whether the wallets are ready to be used.
*/
ready: boolean;
/**
* The wallets that implement the Solana Standard Wallet interface.
*/
wallets: SolanaStandardWallet[];
}
/**
* Use this hook to get Privy's implementation of the Standard Wallet interface for all solana wallets.
* */
declare function useSolanaStandardWallets(): UseSolanaStandardWalletsInterface;
interface UseCreateWalletInterface {
/**
* Creates a Solana embedded wallet for the current user.
*
* This method will error if the user already has an embedded wallet or if they
* exit in the middle of the flow.
*
* @returns Promise for the {@link Wallet} object for the newly created Solana embedded wallet
*/
createWallet: (options?: CreateWalletOptions) => Promise<{
wallet: Wallet;
}>;
}
declare function useCreateWallet(): UseCreateWalletInterface;
/**
* Hook to export a Solana wallet.
*/
interface UseExportWalletInterface {
/**
* Shows the user a Privy modal, from which they can copy their embedded solana wallet's private
* key for easy export to another wallet client (e.g. Phantom, Backpack). The private key is loaded
* on an iframe running on a separate domain from your app, meaning your app cannot access it.
*
* This method will error if the user is not authenticated or does not have an embedded solana wallet.
* @param options {@link {address: string}} (optional) wallet address to export the private key for
* @returns Promise that resolves once the user exits the modal
*/
exportWallet: (options?: {
address: string;
}) => Promise<void>;
}
declare function useExportWallet(): UseExportWalletInterface;
type SignMessageInput = {
message: Uint8Array;
wallet: ConnectedStandardSolanaWallet;
options?: {
uiOptions?: SignMessageModalUIOptions;
};
};
type SignMessageOutput = {
signature: Uint8Array;
};
/**
* Use this hook to sign a message using a Solana embedded wallet.
*/
type UseSignMessage = {
/**
* Prompts a user to sign a message using a Solana standard wallet.
*/
signMessage(input: SignMessageInput): Promise<SignMessageOutput>;
signMessage(...inputs: SignMessageInput[]): Promise<SignMessageOutput[]>;
};
declare function useSignMessage(): UseSignMessage;
type SignTransactionInput = {
transaction: Uint8Array;
wallet: ConnectedStandardSolanaWallet;
chain?: SolanaChain;
options?: SolanaSignTransactionOptions & {
uiOptions?: SendTransactionModalUIOptions;
};
};
type SignTransactionOutput = {
signedTransaction: Uint8Array;
};
/**
* Use this hook to sign a transaction using a Solana embedded wallet.
*/
type UseSignTransaction = {
/**
* Prompts a user to sign a transaction using a Solana standard wallet.
*/
signTransaction(input: SignTransactionInput): Promise<SignTransactionOutput>;
signTransaction(...inputs: SignTransactionInput[]): Promise<SignTransactionOutput[]>;
};
/**
* Use this hook to sign a transaction using a Solana embedded wallet.
*/
declare function useSignTransaction(): UseSignTransaction;
type SignAndSendTransactionInput = {
transaction: Uint8Array;
wallet: ConnectedStandardSolanaWallet;
chain?: SolanaChain;
options?: SolanaSignAndSendTransactionOptions & {
uiOptions?: SendTransactionModalUIOptions;
sponsor?: boolean;
};
};
type SignAndSendTransactionOutput = {
signature: Uint8Array;
};
/**
* Use this hook to sign and send a transaction using a Solana standard wallet.
*/
type UseSignAndSendTransaction = {
/**
* Prompts a user to sign and send a transaction using a Solana standard wallet.
*/
signAndSendTransaction(input: SignAndSendTransactionInput): Promise<SignAndSendTransactionOutput>;
signAndSendTransaction(...inputs: SignAndSendTransactionInput[]): Promise<SignAndSendTransactionOutput[]>;
};
declare function useSignAndSendTransaction(): UseSignAndSendTransaction;
/**
* Method to fund a user's Solana wallet via Privy's funding feature by inputting a valid wallet address.
* You can access the fields and methods documented here via the {@link useFundWallet} hook.
*/
interface UseFundWalletInterface {
/**
* Prompt the user to go through the funding flow and for a specified Solana wallet.
*
* This will open the modal with a prompt for the user to select a funding method (if multiple are enabled).
*
* Once the user continues to the funding flow, Privy will display the funding status screen, and wait
* for the transaction to complete.
*
* Note: Even after a successful funding, funds can take a few minutes to arrive in the user's wallet.
*
* @param address The wallet address to fund
* @param options {@link SolanaFundingConfig} Funding configuration to specify chain and funding amount
*/
fundWallet: ({ address, options, }: {
address: string;
options?: SolanaFundingConfig;
}) => Promise<void>;
}
/**
* Hook to fund a Solana wallet via Privy's fiat on-ramp integration given the wallet address.
*
* @param callbacks.onUserExited {@link PrivyEvents} Callback that will execute when a funding flow is exited. This fires when a user closes a funding flow modal, for any reason.
* @returns fundWallet - function to on-ramp funds to any given Solana wallet
*/
declare function useFundWallet(callbacks?: PrivyEvents['fundSolanaWallet']): UseFundWalletInterface;
export { PrivyStandardWallet, SolanaFundingConfig, SolanaStandardWallet, type UseFundWalletInterface, type UseImportWalletInterface, type UseSignAndSendTransaction, type UseSignMessage, type UseSignTransaction, type UseSolanaStandardWalletsInterface as UseStandardWallets, type UseWallets, useCreateWallet, useExportWallet, useFundWallet, useImportWallet, useSignAndSendTransaction, useSignMessage, useSignTransaction, useSolanaFundingPlugin, useSolanaLedgerPlugin, useSolanaStandardWallets as useStandardWallets, useWallets };