/** * Ports & Adapters Architecture for Chain I/O * * Defines stable interfaces (ports) that business logic depends on, * independent of how signatures/submissions happen. * * Based on EIP-1193, EIP-155, ERC-1271, ERC-4337, EIP-712, CAIP-2/10, and viem. */ import type { Abi, Address, Hex, Chain } from 'viem'; /** * Chain configuration */ export type ChainId = number; export interface ChainConfig { id: ChainId; rpcUrl: string; name: string; chain?: Chain; bundlerUrl?: string; paymasterUrl?: string; } /** * ReadClient - Safe for server-side use (cacheable, no signatures) * Handles all read operations: contract calls, block queries, etc. */ export interface ReadClient { /** * Get the chain ID */ chainId(): Promise; /** * Read from a contract (view/pure functions) */ call(args: { to: Address; abi: Abi; functionName: string; args?: readonly unknown[]; blockTag?: 'latest' | 'pending' | bigint; }): Promise; /** * Get current block number */ getBlockNumber(): Promise; /** * Get block data */ getBlock(blockTag?: 'latest' | 'pending' | bigint): Promise; /** * Get transaction count (nonce) for an address */ getTransactionCount(address: Address, blockTag?: 'pending' | 'latest'): Promise; /** * Estimate gas for a transaction */ estimateGas(args: { to: Address; data: Hex; value?: bigint; account?: Address; }): Promise; /** * Get gas price */ getGasPrice(): Promise; /** * Encode function data (offline, no RPC call) */ encodeFunctionData(args: { abi: Abi; functionName: string; args?: readonly unknown[]; }): Promise; } /** * Signer - Who approves (EOA or ERC-1271 contract wallet) * Handles message and typed data signing */ export interface Signer { /** * Get the address that will sign * May be EOA (EIP-191/712) or ERC-1271 contract wallet */ getAddress(): Promise
; /** * Sign a message (EIP-191) */ signMessage(input: string | Uint8Array): Promise; /** * Sign typed data (EIP-712) */ signTypedData>(args: { domain: any; types: any; primaryType: string; message: TTypedData; }): Promise; /** * True if signature can be validated via ERC-1271 on-chain for this address */ isContractSigner(): Promise; } /** * Transaction request */ export type TxRequest = { to: Address; data: Hex; value?: bigint; gas?: bigint; gasPrice?: bigint; maxFeePerGas?: bigint; maxPriorityFeePerGas?: bigint; nonce?: number; }; /** * Gas policy for transaction submission */ export interface GasPolicy { mode: 'self' | 'sponsored'; maxFeePerGasWei?: bigint; maxPriorityFeePerGasWei?: bigint; } /** * Transaction send result */ export interface TxSendResult { hash: Hex; kind: 'tx' | 'userOp'; blockNumber?: bigint; receipt?: any; events?: any[]; } /** * TxSender - How submission happens (direct RPC vs AA bundler) * Handles transaction submission */ export interface TxSender { /** * Send a single transaction * For EOA: returns tx hash after eth_sendRawTransaction * For AA: returns userOp hash or eventual tx hash depending on mode */ send(tx: TxRequest, opts?: { gasPolicy?: GasPolicy; simulation?: boolean; metadata?: Record; }): Promise; /** * Optional batch send * For AA, becomes a single UserOperation with multiple calls * For EOA, can be sequential or batched via multicall */ sendBatch(txs: TxRequest[], opts?: { gasPolicy?: GasPolicy; simulation?: boolean; metadata?: Record; }): Promise; } /** * AccountProvider - Composes ReadClient, Signer, and TxSender * Convenience interface that provides all chain operations */ export interface AccountProvider extends ReadClient, Signer, TxSender { /** * Get chain configuration */ chain(): ChainConfig; } /** * PreparedCall - Serializable transaction plan * Server builds this, browser executes it */ export type PreparedCall = { chainId: ChainId; description?: string; steps: TxRequest[]; requiresTypedData?: { domain: Record; types: Record; message: Record; }; constraints?: { requireAA?: boolean; requireSponsoredGas?: boolean; deadline?: number; }; }; //# sourceMappingURL=types.d.ts.map