/** * Type definitions for Veil SDK */ /** * Supported tokens */ export type Token = 'ETH' | 'USDC'; /** * Encrypted message format (x25519-xsalsa20-poly1305) */ export interface EncryptedMessage { version: string; nonce: string; ephemPublicKey: string; ciphertext: string; } /** * Contract addresses for a network */ export interface NetworkAddresses { entry: `0x${string}`; ethPool: `0x${string}`; ethQueue: `0x${string}`; usdcPool: `0x${string}`; usdcQueue: `0x${string}`; usdcToken: `0x${string}`; forwarderFactory: `0x${string}`; chainId: number; relayUrl: string; } /** * Options for building a register transaction */ export interface RegisterTxOptions { depositKey: string; } /** * Options for building a deposit transaction */ export interface DepositTxOptions { depositKey: string; fallbackReceiver: `0x${string}`; amount: string; token?: Token; } /** * Transaction data returned by build functions */ export interface TransactionData { to: `0x${string}`; data: `0x${string}`; value?: bigint; } /** * Pool configuration */ export interface PoolConfig { decimals: number; displayDecimals: number; symbol: string; name: string; } /** * Pending deposit from queue contract */ export interface PendingDeposit { nonce: string; status: 'pending' | 'accepted' | 'rejected' | 'refunded'; amount: string; amountWei: string; timestamp: string; } /** * Result from getQueueBalance */ export interface QueueBalanceResult { address: string; queueBalance: string; queueBalanceWei: string; pendingDeposits: PendingDeposit[]; pendingCount: number; } /** * UTXO info for private balance */ export interface UtxoInfo { index: number; amount: string; amountWei: string; isSpent: boolean; } /** * Result from getPrivateBalance */ export interface PrivateBalanceResult { privateBalance: string; privateBalanceWei: string; utxoCount: number; spentCount: number; unspentCount: number; utxos: UtxoInfo[]; } // ============================================================================= // Relay Types // ============================================================================= /** * Pool type for relay operations */ export type RelayPool = 'eth' | 'usdc'; /** * Type of relay transaction */ export type RelayType = 'withdraw' | 'transfer'; /** * Proof arguments for relay transaction */ export interface RelayProofArgs { proof: string; root: string; inputNullifiers: string[]; outputCommitments: [string, string]; publicAmount: string; extDataHash: string; } /** * External data for relay transaction */ export interface RelayExtData { recipient: string; extAmount: string; relayer: string; fee: string; encryptedOutput1: string; encryptedOutput2: string; } /** * Metadata for relay transaction (optional) */ export interface RelayMetadata { amount?: string; amountAtomic?: string; recipient?: string; inputUtxoCount?: number; outputUtxoCount?: number; x402?: boolean; payerIndex?: string; } /** * Request body for relay service */ export interface RelayRequest { type: RelayType; proofArgs: RelayProofArgs; extData: RelayExtData; metadata?: RelayMetadata; } /** * Response from relay service */ export interface RelayResponse { success: boolean; transactionHash: string; blockNumber: string; gasUsed: string; status: string; network: string; } /** * Error response from relay service */ export interface RelayErrorResponse { error: string; message?: string; retryAfter?: number; network?: string; } /** * Options for submitRelay function */ export interface SubmitRelayOptions { /** Type of transaction: 'withdraw' or 'transfer' */ type: RelayType; /** Pool to use: 'eth' or 'usdc' */ pool?: RelayPool; /** Proof arguments generated by ZK prover */ proofArgs: RelayProofArgs; /** External data for the transaction */ extData: RelayExtData; /** Optional metadata */ metadata?: RelayMetadata; /** Custom relay URL (overrides default) */ relayUrl?: string; } // ============================================================================= // Withdraw/Transfer Types // ============================================================================= /** * Options for building a withdrawal proof */ export interface BuildWithdrawProofOptions { /** Amount to withdraw (human readable, e.g., "0.1") */ amount: string; /** Recipient address for withdrawal */ recipient: `0x${string}`; /** User's keypair for signing */ keypair: import('./keypair.js').Keypair; /** Pool to withdraw from (default: 'eth') */ pool?: RelayPool; /** Optional RPC URL */ rpcUrl?: string; /** Optional relay URL */ relayUrl?: string; /** * Optional proving key directory/base URL or resolver. * * Browsers default to `/keys`, expecting files like * `/keys/transaction2.wasm` and `/keys/transaction2.zkey`. */ provingKeyPath?: import('./prover.js').ProvingKeyPath; /** Progress callback */ onProgress?: (stage: string, detail?: string) => void; } /** * Options for building a transfer proof */ export interface BuildTransferProofOptions { /** Amount to transfer (human readable, e.g., "0.1") */ amount: string; /** Recipient's address (must be registered) */ recipientAddress: `0x${string}`; /** Sender's keypair */ senderKeypair: import('./keypair.js').Keypair; /** Pool to transfer in (default: 'eth') */ pool?: RelayPool; /** Optional RPC URL */ rpcUrl?: string; /** * Optional proving key directory/base URL or resolver. * * Browsers default to `/keys`, expecting files like * `/keys/transaction2.wasm` and `/keys/transaction2.zkey`. */ provingKeyPath?: import('./prover.js').ProvingKeyPath; /** Progress callback */ onProgress?: (stage: string, detail?: string) => void; } /** * Result from building a withdrawal or transfer proof */ export interface ProofBuildResult { /** Proof arguments for on-chain verification */ proofArgs: RelayProofArgs; /** External data for transaction */ extData: RelayExtData; /** Number of input UTXOs used */ inputCount: number; /** Number of output UTXOs created */ outputCount: number; /** Amount being withdrawn/transferred */ amount: string; } /** * Result from executing a withdrawal */ export interface WithdrawResult { /** Whether the withdrawal was successful */ success: boolean; /** Transaction hash */ transactionHash: string; /** Block number of the transaction */ blockNumber: string; /** Amount withdrawn */ amount: string; /** Recipient address */ recipient: string; } /** * Result from executing a transfer */ export interface TransferResult { /** Whether the transfer was successful */ success: boolean; /** Transaction hash */ transactionHash: string; /** Block number of the transaction */ blockNumber: string; /** Amount transferred */ amount: string; /** Recipient address */ recipient: string; } /** * UTXO selection result */ export interface UtxoSelectionResult { /** Selected UTXOs */ selectedUtxos: import('./utxo.js').Utxo[]; /** Total amount of selected UTXOs (wei) */ totalSelected: bigint; /** Change amount to return to sender (wei) */ changeAmount: bigint; } // ============================================================================= // Subaccount Types // ============================================================================= /** * Supported subaccount assets */ export type SubaccountAsset = 'eth' | 'usdc'; /** * Deterministically derived subaccount slot metadata */ export interface SubaccountSlot { slot: number; childOwner: `0x${string}`; childDepositKey: string; salt: `0x${string}`; forwarderAddress: `0x${string}`; } /** * Relay-backed forwarder deploy request */ export interface SubaccountDeployRequest { rootPrivateKey: `0x${string}`; slot: number; relayUrl?: string; rpcUrl?: string; } /** * Relay-backed forwarder sweep request */ export interface SubaccountSweepRequest { forwarderAddress: `0x${string}`; asset: SubaccountAsset; relayUrl?: string; } /** * Relay response for subaccount deploy/sweep operations */ export interface SubaccountRelayResult { success: boolean; transactionHash: string; blockNumber: string; gasUsed: string; status: string; network: string; } /** * Human-readable and wei-denominated balance */ export interface SubaccountAssetBalance { balance: string; balanceWei: string; } /** * Forwarder wallet balances for both supported assets */ export interface SubaccountBalances { eth: SubaccountAssetBalance; usdc: SubaccountAssetBalance; } /** * Private pool balance summary for a specific asset */ export interface SubaccountPrivateBalanceStatus { privateBalance: string; privateBalanceWei: string; utxoCount: number; spentCount: number; unspentCount: number; } /** * Private pool balances for both supported assets */ export interface SubaccountPrivateBalances { eth: SubaccountPrivateBalanceStatus; usdc: SubaccountPrivateBalanceStatus; } /** * Queue status for a specific asset */ export interface SubaccountQueueStatus { asset: SubaccountAsset; queueBalance: string; queueBalanceWei: string; pendingCount: number; pendingDeposits: PendingDeposit[]; } /** * Combined subaccount status result */ export interface SubaccountStatusResult { slot: SubaccountSlot; deployed: boolean; balances: SubaccountBalances; privateBalances: SubaccountPrivateBalances; queues: { eth: SubaccountQueueStatus; usdc: SubaccountQueueStatus; }; } /** * Typed data for forwarder withdraw signing */ export interface SubaccountWithdrawTypedData { domain: { name: 'VeilForwarder'; version: string; chainId: number; verifyingContract: `0x${string}`; }; types: { Withdraw: Array<{ name: 'token' | 'to' | 'amount' | 'nonce' | 'deadline'; type: 'address' | 'uint256'; }>; }; primaryType: 'Withdraw'; message: { token: `0x${string}`; to: `0x${string}`; amount: bigint; nonce: bigint; deadline: bigint; }; } /** * Options for merging a subaccount's private balance back to the main wallet */ export interface SubaccountMergeOptions { /** Root private key (VEIL_KEY) */ rootPrivateKey: `0x${string}`; /** Subaccount slot (0-2) */ slot: number; /** Pool to merge in (default: 'eth') */ pool?: RelayPool; /** Optional RPC URL */ rpcUrl?: string; /** Optional relay URL */ relayUrl?: string; /** * Optional proving key directory/base URL or resolver. * * Browsers default to `/keys`, expecting files like * `/keys/transaction2.wasm` and `/keys/transaction2.zkey`. */ provingKeyPath?: import('./prover.js').ProvingKeyPath; /** Progress callback */ onProgress?: (stage: string, detail?: string) => void; } /** * Result from merging a subaccount's balance to the main wallet */ export interface SubaccountMergeResult { /** Whether the merge was successful */ success: boolean; /** Transaction hash */ transactionHash: string; /** Block number of the transaction */ blockNumber: string; /** Amount merged (human-readable) */ amount: string; /** Subaccount slot that was merged */ slot: number; /** Pool the merge was executed in */ pool: RelayPool; } /** * Built recovery transaction and signing metadata */ export interface SubaccountRecoveryResult { transaction: TransactionData; forwarderAddress: `0x${string}`; asset: SubaccountAsset; amount: string; amountWei: string; nonce: string; deadline: string; recipient: `0x${string}`; tokenAddress: `0x${string}`; signature: `0x${string}`; }