UNPKG

@coinbase/agentkit

Version:

Coinbase AgentKit core primitives

170 lines (169 loc) 6.08 kB
import { Abi, ContractFunctionArgs, ContractFunctionName, Hex, ReadContractParameters, ReadContractReturnType, TransactionReceipt, TransactionRequest } from "viem"; import { Network } from "../network"; import { PrivyWalletConfig, PrivyWalletExport } from "./privyShared"; import { WalletProvider } from "./walletProvider"; /** * Configuration options for the Privy Embedded Wallet provider. */ export interface PrivyEvmDelegatedEmbeddedWalletConfig extends PrivyWalletConfig { /** The ID of the delegated wallet */ walletId: string; /** The network ID to connect to (e.g., "base-mainnet") */ networkId?: string; /** The chain ID to connect to */ chainId?: string; /** The wallet type to use */ walletType: "embedded"; } /** * A wallet provider that uses Privy's embedded wallets with delegation. * This provider extends the EvmWalletProvider to provide Privy-specific wallet functionality * while maintaining compatibility with the base wallet provider interface. */ export declare class PrivyEvmDelegatedEmbeddedWalletProvider extends WalletProvider { #private; /** * Private constructor to enforce use of factory method. * * @param config - The configuration options for the wallet provider */ private constructor(); /** * Creates and configures a new PrivyEvmDelegatedEmbeddedWalletProvider instance. * * @param config - The configuration options for the Privy wallet * @returns A configured PrivyEvmDelegatedEmbeddedWalletProvider instance * * @example * ```typescript * const provider = await PrivyEvmDelegatedEmbeddedWalletProvider.configureWithWallet({ * appId: "your-app-id", * appSecret: "your-app-secret", * authorizationPrivateKey: "your-auth-key", * walletId: "privy-wallet-id", * networkId: "base-mainnet" * }); * ``` */ static configureWithWallet(config: PrivyEvmDelegatedEmbeddedWalletConfig): Promise<PrivyEvmDelegatedEmbeddedWalletProvider>; /** * Gets the address of the wallet. * * @returns The address of the wallet. */ getAddress(): string; /** * Gets the network of the wallet. * * @returns The network of the wallet. */ getNetwork(): Network; /** * Gets the name of the wallet provider. * * @returns The name of the wallet provider. */ getName(): string; /** * Gets the balance of the wallet. * * @returns The balance of the wallet in wei */ getBalance(): Promise<bigint>; /** * Signs a message. * * @param message - The message to sign. * @returns The signed message. */ signMessage(message: string): Promise<Hex>; /** * Signs typed data according to EIP-712. * * @param typedData - The typed data object to sign * @param typedData.domain - The domain object containing contract and chain information * @param typedData.types - The type definitions for the structured data * @param typedData.primaryType - The primary type being signed * @param typedData.message - The actual data to sign * @returns A Address that resolves to the signed typed data as a hex string */ signTypedData(typedData: { domain: Record<string, unknown>; types: Record<string, Array<{ name: string; type: string; }>>; primaryType: string; message: Record<string, unknown>; }): Promise<Hex>; /** * Signs a transaction. * * @param transaction - The transaction to sign. * @returns The signed transaction. */ signTransaction(transaction: TransactionRequest): Promise<Hex>; /** * Sends a transaction. * * @param transaction - The transaction to send. * @returns The hash of the transaction. */ sendTransaction(transaction: TransactionRequest): Promise<Hex>; /** * Waits for a transaction receipt. * * @param txHash - The hash of the transaction to wait for. * @returns The transaction receipt. */ waitForTransactionReceipt(txHash: Hex): Promise<TransactionReceipt>; /** * Reads data from a smart contract. * * @param params - Parameters for reading the contract * @param params.address - The address of the contract * @param params.abi - The ABI of the contract * @param params.functionName - The name of the function to call * @param params.args - The arguments to pass to the function * @returns A Address that resolves to the contract function's return value */ readContract<const abi extends Abi | readonly unknown[], functionName extends ContractFunctionName<abi, "pure" | "view">, const args extends ContractFunctionArgs<abi, "pure" | "view", functionName>>(params: ReadContractParameters<abi, functionName, args>): Promise<ReadContractReturnType<abi, functionName, args>>; /** * Transfer the native asset of the network. * * @param to - The destination address. * @param value - The amount to transfer in Wei. * @returns The transaction hash. */ nativeTransfer(to: string, value: string): Promise<Hex>; /** * Exports the wallet information. * * @returns The wallet data */ exportWallet(): PrivyWalletExport; /** * Generate Privy authorization signature for API requests * * @param url - The URL for the request * @param body - The request body * @returns The generated signature */ private generatePrivySignature; /** * Get Privy headers for API requests * * @param url - The URL for the request * @param body - The request body * @returns The headers for the request */ private getPrivyHeaders; /** * Execute a Privy API request. * * @param body - The request body to send to the Privy API * @returns A promise that resolves to the response data * @throws Error if the request fails */ private executePrivyRequest; }