import type { PublicClient, Chain, Transport } from 'viem'; import type { SIWxStorage } from '@x402/extensions/sign-in-with-x'; import type { AgreementKeeper } from './agreement-keeper.js'; /** Configuration for agreement-aware SIWx storage */ export interface AzethSIWxStorageConfig { /** viem public client for on-chain reads */ publicClient: PublicClient; /** The service's payment recipient address */ servicePayee: `0x${string}`; /** Token address the service accepts (e.g., USDC) */ serviceToken?: `0x${string}`; /** PaymentAgreementModule contract address */ moduleAddress?: `0x${string}`; /** Minimum agreement amount per interval */ minAgreementAmount?: bigint; } /** How a hasPaid() grant was satisfied: a prior payment record (session) or an on-chain agreement */ export type GrantKind = 'session' | 'agreement'; export declare class AzethSIWxStorage implements SIWxStorage { private readonly paymentRecords; private readonly usedNonces; /** Which tier satisfied the most recent hasPaid() grant, keyed per `${resource}:${address}` */ private readonly grantKinds; private readonly config; private keeper; constructor(config: AzethSIWxStorageConfig); /** Inject the agreement keeper after construction. * Called from server startup to avoid circular initialization. */ setKeeper(keeper: AgreementKeeper): void; /** Check if an address has paid for a resource. * * Two-tier lookup: * 1. Check in-memory payment records (x402 settlement — permanent grant) * 2. Check on-chain agreements (subscription — re-verified every ~60s via cache TTL) * * Settlement grants (recordPayment) are permanent for the session. * Agreement grants are NOT cached permanently — they are re-verified on each * call via findActiveAgreementForPayee (which uses a 60s TTL cache internally). * This ensures that if a payer's balance drops to zero, their access is revoked * within ~60s instead of being permanently granted. */ hasPaid(resource: string, address: string): Promise; /** Record that an address has paid for a resource */ recordPayment(resource: string, address: string): void; /** Check if a nonce has been used (replay prevention) */ hasUsedNonce(nonce: string): boolean; /** Record a nonce as used */ recordNonce(nonce: string): void; /** Look up which tier satisfied the most recent hasPaid() grant for a resource+address. * * Keyed per resource+address (never "last grant globally") so two concurrent * payers on the same resource can never cross-label each other. * * @param resource - Resource path (pathname, same key hasPaid uses) * @param address - Payer address (case-insensitive) * @returns 'session' (prior payment record), 'agreement' (on-chain agreement), * or undefined if hasPaid never granted for this pair */ getGrantKind(resource: string, address: string): GrantKind | undefined; /** Record which tier satisfied a hasPaid() grant, with FIFO eviction */ private recordGrantKind; /** Synchronous payment record helper */ private recordPaymentSync; } //# sourceMappingURL=storage.d.ts.map