UNPKG

@agentauth/mcp

Version:

Universal payment-enabled MCP gateway for AI agents with native x402 protocol support.

130 lines 4.27 kB
import type { WalletService } from '../wallet/walletService.js'; import { PaymentProtocol, PaymentRequiredResponse, TransactionTemplate } from './agentpay-v002.js'; /** * x402 Payment Requirement as specified by server * Based on official x402 specification v1.0 */ export interface X402PaymentRequirement { scheme: string; network: string; maxAmountRequired: string; resource: string; description: string; payTo: string; maxTimeoutSeconds: number; asset: string; mimeType?: string; outputSchema?: object | null; extra?: object | null; } /** * x402 Server Response Format * Based on official x402 specification v1.0 */ export interface X402Response { x402Version: number; accepts: X402PaymentRequirement[]; error: string | null; } /** * x402 Payment Payload for X-PAYMENT header (Exact Scheme) */ export interface X402ExactEvmPayloadAuthorization { from: string; to: string; value: string; validAfter: string; validBefore: string; nonce: string; } export interface X402ExactEvmPayload { signature: string; authorization: X402ExactEvmPayloadAuthorization; } export interface X402PaymentPayload { x402Version: number; scheme: string; network: string; payload: X402ExactEvmPayload; } /** * x402 Protocol Implementation * * Features: * - Server-driven configuration (network, asset, recipient from server) * - Zero user configuration (automatic chain detection) * - Robust error handling for unsupported networks * - Stateless transaction flow via agent retention */ export declare class X402Protocol implements PaymentProtocol { private currentChainId?; /** * Lightweight detection of x402 protocol presence * Checks for minimal x402 indicators without heavy validation */ isPaymentRequired(response: any): boolean; /** * Extract payment details from x402 response with full validation * Performs heavy validation and version support check */ extractPaymentDetails(response: any): PaymentRequiredResponse | null; /** * Sign payment transaction - for x402 exact scheme, prepares EIP-3009 authorization * The actual signature will be created in createAuthorizationHeaders using EIP-712 * This is stateless - the template contains all needed data including x402Requirement */ signPaymentTransaction(template: TransactionTemplate, walletService: WalletService): Promise<{ signedTx: string; from: string; }>; /** * Generate a random 32-byte nonce for EIP-3009 authorization */ private generateNonce; /** * Create x402 authorization headers for payment using exact scheme with EIP-3009 * Stateless - extracts requirement from the template that was passed through */ createAuthorizationHeaders(signedTx: string, from: string, walletService: WalletService, _unusedRequirement?: X402PaymentRequirement): Promise<Record<string, string>>; /** * Format payment details for user display with real-time gas estimation */ formatForUser(paymentDetails: PaymentRequiredResponse, walletBalances?: { usdc: string; eth: string; }, walletService?: any): Promise<string>; /** * Format instructions for agent */ formatForAgent(paymentDetails: PaymentRequiredResponse, originalParams?: any): string; /** * Validate payment requirement structure */ private isValidPaymentRequirement; /** * Build transaction from x402 requirement */ private buildTransactionFromRequirement; /** * Get chain configuration for network name */ private getChainConfig; /** * Get network name from current chain ID */ private getNetworkFromChainId; /** * Fix potentially truncated transaction data * x402 protocol uses server-provided data, so no fixing needed */ fixTruncatedTransactionData(template: TransactionTemplate): TransactionTemplate; /** * Validate transaction template structure and content * x402-specific validation */ validateTransactionTemplate(template: TransactionTemplate): { valid: boolean; errors: string[]; }; } //# sourceMappingURL=x402.d.ts.map