import { type PublicClient, type WalletClient, type Chain, type Transport, type Account } from 'viem'; import { type SecureFetchGuard } from './secure-fetch.js'; /** Verify that a settlement receipt contains a USDC Transfer event matching expectations. * * Decodes Transfer event logs from the receipt and checks: * - Transfer emitted from the expected USDC contract address * - Recipient (`to`) matches the expected payTo address * - Amount (`value`) >= the expected payment amount * * @returns true if a matching Transfer event was found, false otherwise */ export declare function verifySettlementReceipt(receipt: { logs: ReadonlyArray<{ address: string; topics: ReadonlyArray; data: string; }>; }, expectedPayTo: string, expectedAsset: string, expectedAmount: bigint): boolean; /** Parameters for executing a payment via a smart account (UserOp path). * The callback receives the pre-encoded USDC calldata and returns the tx hash. */ export interface SmartAccountTransferParams { usdcAddress: `0x${string}`; payTo: `0x${string}`; amount: bigint; /** Full ABI-encoded transferWithAuthorization calldata (bytes variant, 0xcf092995) */ calldata: `0x${string}`; } /** Callback that submits a UserOp to execute transferWithAuthorization from the smart account. * Returns the transaction hash of the settled UserOp. */ export type SmartAccountTransferCallback = (params: SmartAccountTransferParams) => Promise<`0x${string}`>; export interface Fetch402Options { method?: string; headers?: Record; body?: string; maxAmount?: bigint; autoReputation?: boolean; /** Smart account address for SIWx identity (address field in SIWE message). * When set, the client will attempt SIWx authentication before paying. * The EOA signs the SIWE message, but the smart account address is used * so the server can look up agreements by smart account. */ smartAccount?: `0x${string}`; /** M-7: Override the USDC EIP-712 domain name/version if needed. * Defaults to known production values ('USD Coin', '2'). * Override if the USDC contract on your chain uses different domain parameters. */ usdcDomain?: { name: string; version: string; }; /** When true, throws PAYMENT_FAILED if the server doesn't return a valid X-Payment-Tx * header or if the on-chain settlement receipt shows a revert. Default: false (advisory). */ strictSettlement?: boolean; /** Callback to execute payment via a smart account UserOp. * When provided, the payment goes through the smart account (with guardian guardrails) * instead of the x402 facilitator settling from the EOA. */ smartAccountTransfer?: SmartAccountTransferCallback; /** SSRF guard for the (untrusted) target URL: validates each connection hop (HTTPS + * non-private IP) and returns a dispatcher pinned to the validated IP (anti DNS-rebinding). * The AzethKit client methods (kit.fetch402 / kit.smartFetch402) inject a default guard * (createDefaultSsrfGuard) when this is omitted, so SDK-direct callers are secure by * default (F11). Pass a custom guard to override. The low-level fetch402()/smartFetch402() * functions do NOT default it — they apply only what is passed here. (F9) */ secureGuard?: SecureFetchGuard; /** Opt OUT of the AzethKit client methods' default SSRF guard. Only for intentional * private/local discovery you fully trust — disables HTTPS enforcement, private-IP * blocking, and the DNS-rebinding connection pin. Ignored by the low-level functions. (F11) */ unsafelyDisableSsrfGuard?: boolean; } export interface Fetch402Result { response: Response; paymentMade: boolean; amount?: bigint; txHash?: `0x${string}`; /** Response time in milliseconds (measured from paid request to response) */ responseTimeMs?: number; /** Whether on-chain settlement was verified after payment. * True if the server returned an X-Payment-Tx header and the tx receipt shows success. */ settlementVerified: boolean; /** How access was obtained. * - 'x402': Standard x402 payment flow (ERC-3009 authorization signed and submitted) * - 'smart-account': Payment via smart account UserOp (guardian guardrails enforced) * - 'session': Access granted via SIWx identity (prior payment session) * - 'agreement': Access granted via an active on-chain payment agreement * (server-discriminated via the X-Access-Grant response header; providers that * do not emit the header report 'session' — exact pre-F4 behavior) * - 'none': No payment was required (non-402 response) */ paymentMethod: 'x402' | 'smart-account' | 'session' | 'agreement' | 'none'; } /** Fetch a URL, automatically paying x402 requirements * * Flow: * 1. Make initial request * 2. If 402 returned, parse payment requirements from X-Payment-Required header * 3. If SIWx extension present and smartAccount provided, attempt identity proof * 4. If SIWx grants access, return (no payment needed) * 5. If smartAccountTransfer callback provided, pay via smart account UserOp * (guardian guardrails enforced on-chain). Throws on failure — NO EOA fallback. * 6. Otherwise (no smart account), sign ERC-3009 transferWithAuthorization from EOA * 7. Retry with payment proof header * * SECURITY: When a smart account is configured (smartAccountTransfer + smartAccount), * the EOA payment path is unreachable. This prevents guardian guardrail bypass. */ export declare function fetch402(publicClient: PublicClient, walletClient: WalletClient, account: `0x${string}`, url: string, options?: Fetch402Options): Promise; //# sourceMappingURL=x402.d.ts.map