import { Log } from 'viem'; /** * ClientEvmSigner - Used by x402 clients to sign payment authorizations. * * Typically a viem LocalAccount: * ```typescript * const account = privateKeyToAccount('0x...'); * ``` * * Or composed via `toClientEvmSigner(account, publicClient)`. */ type ClientEvmSigner = { readonly address: `0x${string}`; signTypedData(message: { domain: Record; types: Record; primaryType: string; message: Record; }): Promise<`0x${string}`>; /** * Optional on-chain reads. * Required only for extension enrichment (EIP-2612 / ERC-20 approval). */ readContract?(args: { address: `0x${string}`; abi: readonly unknown[]; functionName: string; args?: readonly unknown[]; }): Promise; /** * Optional: Signs a raw EIP-1559 transaction without broadcasting. * Required for ERC-20 approval gas sponsoring when the token lacks EIP-2612. */ signTransaction?(args: { to: `0x${string}`; data: `0x${string}`; nonce: number; gas: bigint; maxFeePerGas: bigint; maxPriorityFeePerGas: bigint; chainId: number; }): Promise<`0x${string}`>; /** * Optional: Gets the current transaction count (nonce) for an address. * Required for ERC-20 approval gas sponsoring. */ getTransactionCount?(args: { address: `0x${string}`; }): Promise; /** * Optional: Estimates current gas fees per gas. * Required for ERC-20 approval gas sponsoring. */ estimateFeesPerGas?(): Promise<{ maxFeePerGas: bigint; maxPriorityFeePerGas: bigint; }>; }; /** * FacilitatorEvmSigner - Used by x402 facilitators to verify and settle payments * This is typically a viem PublicClient + WalletClient combination that can * read contract state, verify signatures, write transactions, and wait for receipts * * Supports multiple addresses for load balancing, key rotation, and high availability */ type FacilitatorEvmSigner = { /** * Get all addresses this facilitator can use for signing * Enables dynamic address selection for load balancing and key rotation */ getAddresses(): readonly `0x${string}`[]; readContract(args: { address: `0x${string}`; abi: readonly unknown[]; functionName: string; args?: readonly unknown[]; }): Promise; verifyTypedData(args: { address: `0x${string}`; domain: Record; types: Record; primaryType: string; message: Record; signature: `0x${string}`; }): Promise; writeContract(args: { address: `0x${string}`; abi: readonly unknown[]; functionName: string; args: readonly unknown[]; gas?: bigint; dataSuffix?: `0x${string}`; }): Promise<`0x${string}`>; sendTransaction(args: { to: `0x${string}`; data: `0x${string}`; }): Promise<`0x${string}`>; waitForTransactionReceipt(args: { hash: `0x${string}`; }): Promise<{ status: string; logs?: readonly Log[]; }>; getCode(args: { address: `0x${string}`; }): Promise<`0x${string}` | undefined>; }; /** * Composes a ClientEvmSigner from a local account and a public client. * * Use this when your signer (e.g., `privateKeyToAccount`) doesn't have * `readContract`. The `publicClient` provides the on-chain read capability. * * Alternatively, use a local account with an explicit public client: * ```typescript * const account = privateKeyToAccount('0x...'); * const publicClient = createPublicClient({ chain: baseSepolia, transport: http() }); * const signer = toClientEvmSigner(account, publicClient); * ``` * * @param signer - A signer with `address` and `signTypedData` (and optionally `readContract`) * @param publicClient - A client with optional read/nonce/fee helpers * @param publicClient.readContract - The readContract method from the public client * @param publicClient.getTransactionCount - Optional getTransactionCount for ERC-20 approval * @param publicClient.estimateFeesPerGas - Optional estimateFeesPerGas for ERC-20 approval * @returns A ClientEvmSigner with any available optional capabilities * * @example * ```typescript * const account = privateKeyToAccount("0x..."); * const publicClient = createPublicClient({ chain: baseSepolia, transport: http() }); * const signer = toClientEvmSigner(account, publicClient); * ``` */ declare function toClientEvmSigner(signer: Omit & { readContract?: ClientEvmSigner["readContract"]; }, publicClient?: { readContract(args: { address: `0x${string}`; abi: readonly unknown[]; functionName: string; args?: readonly unknown[]; }): Promise; getTransactionCount?(args: { address: `0x${string}`; }): Promise; estimateFeesPerGas?(): Promise<{ maxFeePerGas: bigint; maxPriorityFeePerGas: bigint; }>; }): ClientEvmSigner; /** * Converts a viem client with single address to a FacilitatorEvmSigner * Wraps the single address in a getAddresses() function for compatibility * * @param client - The client to convert (must have 'address' property) * @returns FacilitatorEvmSigner with getAddresses() support */ declare function toFacilitatorEvmSigner(client: Omit & { address: `0x${string}`; }): FacilitatorEvmSigner; export { type ClientEvmSigner as C, type FacilitatorEvmSigner as F, toFacilitatorEvmSigner as a, toClientEvmSigner as t };