@t402/core 2.6.1 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/http/index.d.ts +1 -1
- package/dist/cjs/server/index.d.ts +1 -1
- package/dist/cjs/server/index.js.map +1 -1
- package/dist/cjs/{t402HTTPResourceServer-BIEvnbwL.d.ts → t402HTTPResourceServer-4RFYtBnw.d.ts} +1 -1
- package/dist/esm/http/index.d.mts +1 -1
- package/dist/esm/server/index.d.mts +1 -1
- package/dist/esm/{t402HTTPResourceServer-Jmmvy9kc.d.mts → t402HTTPResourceServer-CaF4mNy6.d.mts} +1 -1
- package/package.json +1 -1
package/dist/cjs/http/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as PaymentRequired, S as SettleResponse, a as PaymentPayload, P as PaymentRequirements } from '../mechanisms-dYCiYgko.js';
|
|
2
|
-
export { C as CompiledRoute, D as DynamicPayTo, a as DynamicPrice, F as FacilitatorClient, b as FacilitatorConfig, H as HTTPAdapter, c as HTTPFacilitatorClient, d as HTTPProcessResult, e as HTTPRequestContext, f as HTTPResponseInstructions, P as PaymentOption, g as PaywallConfig, h as PaywallProvider, i as ProcessSettleFailureResponse, j as ProcessSettleResultResponse, k as ProcessSettleSuccessResponse, R as RouteConfig, l as RouteConfigurationError, m as RouteValidationError, n as RoutesConfig, S as SettleOptions, U as UnpaidResponseBody, o as UnpaidResponseResult, t as t402HTTPResourceServer } from '../t402HTTPResourceServer-
|
|
2
|
+
export { C as CompiledRoute, D as DynamicPayTo, a as DynamicPrice, F as FacilitatorClient, b as FacilitatorConfig, H as HTTPAdapter, c as HTTPFacilitatorClient, d as HTTPProcessResult, e as HTTPRequestContext, f as HTTPResponseInstructions, P as PaymentOption, g as PaywallConfig, h as PaywallProvider, i as ProcessSettleFailureResponse, j as ProcessSettleResultResponse, k as ProcessSettleSuccessResponse, R as RouteConfig, l as RouteConfigurationError, m as RouteValidationError, n as RoutesConfig, S as SettleOptions, U as UnpaidResponseBody, o as UnpaidResponseResult, t as t402HTTPResourceServer } from '../t402HTTPResourceServer-4RFYtBnw.js';
|
|
3
3
|
export { f as t402HTTPClient } from '../t402HTTPClient-CHaMMGBY.js';
|
|
4
4
|
import 'zod';
|
|
5
5
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { C as CompiledRoute, F as FacilitatorClient, b as FacilitatorConfig, H as HTTPAdapter, c as HTTPFacilitatorClient, d as HTTPProcessResult, e as HTTPRequestContext, f as HTTPResponseInstructions, g as PaywallConfig, h as PaywallProvider, i as ProcessSettleFailureResponse, j as ProcessSettleResultResponse, k as ProcessSettleSuccessResponse,
|
|
1
|
+
export { A as AfterSettleHook, p as AfterVerifyHook, B as BeforeSettleHook, q as BeforeVerifyHook, C as CompiledRoute, F as FacilitatorClient, b as FacilitatorConfig, H as HTTPAdapter, c as HTTPFacilitatorClient, d as HTTPProcessResult, e as HTTPRequestContext, f as HTTPResponseInstructions, O as OnSettleFailureHook, r as OnVerifyFailureHook, g as PaywallConfig, h as PaywallProvider, i as ProcessSettleFailureResponse, j as ProcessSettleResultResponse, k as ProcessSettleSuccessResponse, s as ResourceConfig, u as ResourceInfo, R as RouteConfig, l as RouteConfigurationError, m as RouteValidationError, n as RoutesConfig, v as SettleContext, w as SettleFailureContext, S as SettleOptions, x as SettleResultContext, U as UnpaidResponseBody, o as UnpaidResponseResult, V as VerifyContext, y as VerifyFailureContext, z as VerifyResultContext, t as t402HTTPResourceServer, E as t402ResourceServer } from '../t402HTTPResourceServer-4RFYtBnw.js';
|
|
2
2
|
import '../mechanisms-dYCiYgko.js';
|
|
3
3
|
import 'zod';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/index.ts","../../../src/utils/index.ts","../../../src/errors.ts","../../../src/http/httpFacilitatorClient.ts","../../../src/index.ts","../../../src/server/t402ResourceServer.ts","../../../src/types/schemas.ts","../../../src/http/index.ts","../../../src/http/t402HTTPResourceServer.ts"],"sourcesContent":["export { t402ResourceServer } from \"./t402ResourceServer\";\nexport type { ResourceConfig, ResourceInfo } from \"./t402ResourceServer\";\n\nexport { HTTPFacilitatorClient } from \"../http/httpFacilitatorClient\";\nexport type { FacilitatorClient, FacilitatorConfig, SettleOptions } from \"../http/httpFacilitatorClient\";\n\nexport { t402HTTPResourceServer, RouteConfigurationError } from \"../http/t402HTTPResourceServer\";\nexport type {\n HTTPRequestContext,\n HTTPResponseInstructions,\n HTTPProcessResult,\n PaywallConfig,\n PaywallProvider,\n RouteConfig,\n CompiledRoute,\n HTTPAdapter,\n RoutesConfig,\n UnpaidResponseBody,\n UnpaidResponseResult,\n ProcessSettleResultResponse,\n ProcessSettleSuccessResponse,\n ProcessSettleFailureResponse,\n RouteValidationError,\n} from \"../http/t402HTTPResourceServer\";\n","import { Network } from \"../types\";\n\n// ============================================================================\n// Cryptographically Secure Random Utilities\n// ============================================================================\n\n/**\n * Get the crypto object, works in both browser and Node.js (19+)\n *\n * @returns The crypto object\n * @throws Error if crypto API is not available\n */\nfunction getCrypto(): Crypto {\n const cryptoObj = globalThis.crypto;\n\n if (!cryptoObj || typeof cryptoObj.getRandomValues !== \"function\") {\n throw new Error(\n \"Crypto API not available. \" + \"Node.js 19+ or a browser with Web Crypto API is required.\",\n );\n }\n\n return cryptoObj;\n}\n\n/**\n * Generate a cryptographically secure random integer in range [0, max)\n *\n * Uses rejection sampling to ensure uniform distribution.\n *\n * @param max - Exclusive upper bound (must be > 0 and <= 2^32)\n * @returns Random integer in [0, max)\n * @throws Error if max is invalid or crypto unavailable\n */\nexport function cryptoRandomInt(max: number): number {\n if (max <= 0 || max > 0xffffffff || !Number.isInteger(max)) {\n throw new Error(`Invalid max value: ${max}. Must be positive integer <= 2^32`);\n }\n\n const crypto = getCrypto();\n const array = new Uint32Array(1);\n\n // Rejection sampling to avoid modulo bias\n const limit = Math.floor(0xffffffff / max) * max;\n let value: number;\n\n do {\n crypto.getRandomValues(array);\n value = array[0];\n } while (value >= limit);\n\n return value % max;\n}\n\n/**\n * Generate a cryptographically secure random BigInt\n *\n * @param bits - Number of bits (default 64, max 256)\n * @returns Random BigInt with specified number of bits\n * @throws Error if bits is invalid or crypto unavailable\n */\nexport function cryptoRandomBigInt(bits: number = 64): bigint {\n if (bits <= 0 || bits > 256) {\n throw new Error(`Invalid bits value: ${bits}. Must be 1-256`);\n }\n\n const crypto = getCrypto();\n const bytes = Math.ceil(bits / 8);\n const array = new Uint8Array(bytes);\n crypto.getRandomValues(array);\n\n // Convert bytes to BigInt\n let result = 0n;\n for (let i = 0; i < bytes; i++) {\n result = (result << 8n) | BigInt(array[i]);\n }\n\n // Mask to exact bit count\n const mask = (1n << BigInt(bits)) - 1n;\n return result & mask;\n}\n\n/**\n * Generate a cryptographically secure random hex string\n *\n * @param bytes - Number of random bytes (default 16)\n * @returns Hex-encoded random string\n * @throws Error if bytes is invalid or crypto unavailable\n */\nexport function cryptoRandomHex(bytes: number = 16): string {\n if (bytes <= 0 || bytes > 128) {\n throw new Error(`Invalid bytes value: ${bytes}. Must be 1-128`);\n }\n\n const crypto = getCrypto();\n const array = new Uint8Array(bytes);\n crypto.getRandomValues(array);\n\n return Array.from(array)\n .map(b => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\n// ============================================================================\n// Network and Scheme Utilities\n// ============================================================================\n\n/**\n * Scheme data structure for facilitator storage\n */\nexport interface SchemeData<T> {\n facilitator: T;\n networks: Set<Network>;\n pattern: Network;\n}\n\nexport const findSchemesByNetwork = <T>(\n map: Map<string, Map<string, T>>,\n network: Network,\n): Map<string, T> | undefined => {\n // Direct match first\n let implementationsByScheme = map.get(network);\n\n if (!implementationsByScheme) {\n // Try pattern matching for registered network patterns\n for (const [registeredNetworkPattern, implementations] of map.entries()) {\n // Convert the registered network pattern to a regex\n // e.g., \"eip155:*\" becomes /^eip155:.*$/\n const pattern = registeredNetworkPattern\n .replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\") // Escape special regex chars except *\n .replace(/\\\\\\*/g, \".*\"); // Replace escaped * with .*\n\n const regex = new RegExp(`^${pattern}$`);\n\n if (regex.test(network)) {\n implementationsByScheme = implementations;\n break;\n }\n }\n }\n\n return implementationsByScheme;\n};\n\nexport const findByNetworkAndScheme = <T>(\n map: Map<string, Map<string, T>>,\n scheme: string,\n network: Network,\n): T | undefined => {\n return findSchemesByNetwork(map, network)?.get(scheme);\n};\n\n/**\n * Finds a facilitator by scheme and network using pattern matching.\n * Works with new SchemeData storage structure.\n *\n * @param schemeMap - Map of scheme names to SchemeData\n * @param scheme - The scheme to find\n * @param network - The network to match against\n * @returns The facilitator if found, undefined otherwise\n */\nexport const findFacilitatorBySchemeAndNetwork = <T>(\n schemeMap: Map<string, SchemeData<T>>,\n scheme: string,\n network: Network,\n): T | undefined => {\n const schemeData = schemeMap.get(scheme);\n if (!schemeData) return undefined;\n\n // Check if network is in the stored networks set\n if (schemeData.networks.has(network)) {\n return schemeData.facilitator;\n }\n\n // Try pattern matching\n const patternRegex = new RegExp(\"^\" + schemeData.pattern.replace(\"*\", \".*\") + \"$\");\n if (patternRegex.test(network)) {\n return schemeData.facilitator;\n }\n\n return undefined;\n};\n\nexport const Base64EncodedRegex = /^[A-Za-z0-9+/]*={0,2}$/;\n\n/**\n * Encodes a string to base64 format\n *\n * @param data - The string to be encoded to base64\n * @returns The base64 encoded string\n */\nexport function safeBase64Encode(data: string): string {\n if (typeof globalThis !== \"undefined\" && typeof globalThis.btoa === \"function\") {\n return globalThis.btoa(data);\n }\n return Buffer.from(data).toString(\"base64\");\n}\n\n/**\n * Decodes a base64 string back to its original format\n *\n * @param data - The base64 encoded string to be decoded\n * @returns The decoded string in UTF-8 format\n */\nexport function safeBase64Decode(data: string): string {\n if (typeof globalThis !== \"undefined\" && typeof globalThis.atob === \"function\") {\n return globalThis.atob(data);\n }\n return Buffer.from(data, \"base64\").toString(\"utf-8\");\n}\n\n/**\n * Deep equality comparison for payment requirements\n * Uses a normalized JSON.stringify for consistent comparison\n *\n * @param obj1 - First object to compare\n * @param obj2 - Second object to compare\n * @returns True if objects are deeply equal\n */\nexport function deepEqual(obj1: unknown, obj2: unknown): boolean {\n // Normalize and stringify both objects for comparison\n // This handles nested objects, arrays, and different property orders\n const normalize = (obj: unknown): string => {\n // Handle primitives and null/undefined\n if (obj === null || obj === undefined) return JSON.stringify(obj);\n if (typeof obj !== \"object\") return JSON.stringify(obj);\n\n // Handle arrays\n if (Array.isArray(obj)) {\n return JSON.stringify(\n obj.map(item =>\n typeof item === \"object\" && item !== null ? JSON.parse(normalize(item)) : item,\n ),\n );\n }\n\n // Handle objects - sort keys and recursively normalize values\n const sorted: Record<string, unknown> = {};\n Object.keys(obj as Record<string, unknown>)\n .sort()\n .forEach(key => {\n const value = (obj as Record<string, unknown>)[key];\n sorted[key] =\n typeof value === \"object\" && value !== null ? JSON.parse(normalize(value)) : value;\n });\n return JSON.stringify(sorted);\n };\n\n try {\n return normalize(obj1) === normalize(obj2);\n } catch {\n // Fallback to simple comparison if normalization fails\n return JSON.stringify(obj1) === JSON.stringify(obj2);\n }\n}\n","/**\n * T402PaymentError - Structured error class for the T402 payment protocol.\n *\n * Wraps upstream errors with payment-specific context: phase, retryability,\n * and optional HTTP status code.\n */\n\nexport type PaymentPhase = \"signing\" | \"submission\" | \"verification\" | \"settlement\" | \"unknown\";\n\nexport class T402PaymentError extends Error {\n readonly cause?: Error;\n readonly phase: PaymentPhase;\n readonly retryable: boolean;\n readonly code?: number;\n\n constructor(\n message: string,\n options?: {\n cause?: Error;\n phase?: PaymentPhase;\n retryable?: boolean;\n code?: number;\n },\n ) {\n super(message);\n this.name = \"T402PaymentError\";\n this.cause = options?.cause;\n this.phase = options?.phase ?? \"unknown\";\n this.retryable = options?.retryable ?? false;\n this.code = options?.code;\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, T402PaymentError);\n }\n }\n\n isRetryable(): boolean {\n return this.retryable;\n }\n\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n message: this.message,\n phase: this.phase,\n retryable: this.retryable,\n code: this.code,\n cause: this.cause?.message,\n };\n }\n}\n","import { PaymentPayload, PaymentRequirements } from \"../types/payments\";\nimport { VerifyResponse, SettleResponse, SupportedResponse } from \"../types/facilitator\";\nimport { T402PaymentError } from \"../errors\";\n\nconst DEFAULT_FACILITATOR_URL = \"https://facilitator.t402.io\";\n\nexport interface SettleOptions {\n /** Optional idempotency key for replay protection */\n idempotencyKey?: string;\n}\n\nexport interface FacilitatorConfig {\n url?: string;\n createAuthHeaders?: () => Promise<{\n verify: Record<string, string>;\n settle: Record<string, string>;\n supported: Record<string, string>;\n }>;\n}\n\n/**\n * Interface for facilitator clients\n * Can be implemented for HTTP-based or local facilitators\n */\nexport interface FacilitatorClient {\n /**\n * Verify a payment with the facilitator\n *\n * @param paymentPayload - The payment to verify\n * @param paymentRequirements - The requirements to verify against\n * @returns Verification response\n */\n verify(\n paymentPayload: PaymentPayload,\n paymentRequirements: PaymentRequirements,\n ): Promise<VerifyResponse>;\n\n /**\n * Settle a payment with the facilitator\n *\n * @param paymentPayload - The payment to settle\n * @param paymentRequirements - The requirements for settlement\n * @param options - Optional settings including idempotency key\n * @returns Settlement response\n */\n settle(\n paymentPayload: PaymentPayload,\n paymentRequirements: PaymentRequirements,\n options?: SettleOptions,\n ): Promise<SettleResponse>;\n\n /**\n * Get supported payment kinds and extensions from the facilitator\n *\n * @returns Supported payment kinds and extensions\n */\n getSupported(): Promise<SupportedResponse>;\n}\n\n/**\n * HTTP-based client for interacting with t402 facilitator services\n * Handles HTTP communication with facilitator endpoints\n */\nexport class HTTPFacilitatorClient implements FacilitatorClient {\n readonly url: string;\n private readonly _createAuthHeaders?: FacilitatorConfig[\"createAuthHeaders\"];\n\n /**\n * Creates a new HTTPFacilitatorClient instance.\n *\n * @param config - Configuration options for the facilitator client\n */\n constructor(config?: FacilitatorConfig) {\n this.url = config?.url || DEFAULT_FACILITATOR_URL;\n this._createAuthHeaders = config?.createAuthHeaders;\n }\n\n /**\n * Verify a payment with the facilitator\n *\n * @param paymentPayload - The payment to verify\n * @param paymentRequirements - The requirements to verify against\n * @returns Verification response\n */\n async verify(\n paymentPayload: PaymentPayload,\n paymentRequirements: PaymentRequirements,\n ): Promise<VerifyResponse> {\n let headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n\n if (this._createAuthHeaders) {\n const authHeaders = await this.createAuthHeaders(\"verify\");\n headers = { ...headers, ...authHeaders.headers };\n }\n\n const response = await fetch(`${this.url}/verify`, {\n method: \"POST\",\n headers,\n body: JSON.stringify({\n t402Version: paymentPayload.t402Version,\n paymentPayload: this.toJsonSafe(paymentPayload),\n paymentRequirements: this.toJsonSafe(paymentRequirements),\n }),\n });\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n throw new T402PaymentError(`Facilitator verify failed (${response.status}): ${errorText}`, {\n phase: \"verification\",\n code: response.status,\n retryable: response.status >= 500 || response.status === 429,\n });\n }\n\n return (await response.json()) as VerifyResponse;\n }\n\n /**\n * Settle a payment with the facilitator\n *\n * @param paymentPayload - The payment to settle\n * @param paymentRequirements - The requirements for settlement\n * @param options - Optional settings including idempotency key\n * @returns Settlement response\n */\n async settle(\n paymentPayload: PaymentPayload,\n paymentRequirements: PaymentRequirements,\n options?: SettleOptions,\n ): Promise<SettleResponse> {\n let headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n\n if (options?.idempotencyKey) {\n headers[\"Idempotency-Key\"] = options.idempotencyKey;\n }\n\n if (this._createAuthHeaders) {\n const authHeaders = await this.createAuthHeaders(\"settle\");\n headers = { ...headers, ...authHeaders.headers };\n }\n\n const response = await fetch(`${this.url}/settle`, {\n method: \"POST\",\n headers,\n body: JSON.stringify({\n t402Version: paymentPayload.t402Version,\n paymentPayload: this.toJsonSafe(paymentPayload),\n paymentRequirements: this.toJsonSafe(paymentRequirements),\n }),\n });\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n throw new T402PaymentError(`Facilitator settle failed (${response.status}): ${errorText}`, {\n phase: \"settlement\",\n code: response.status,\n retryable: response.status >= 500 || response.status === 429,\n });\n }\n\n return (await response.json()) as SettleResponse;\n }\n\n /**\n * Get supported payment kinds and extensions from the facilitator\n *\n * @returns Supported payment kinds and extensions\n */\n async getSupported(): Promise<SupportedResponse> {\n let headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n\n if (this._createAuthHeaders) {\n const authHeaders = await this.createAuthHeaders(\"supported\");\n headers = { ...headers, ...authHeaders.headers };\n }\n\n const response = await fetch(`${this.url}/supported`, {\n method: \"GET\",\n headers,\n });\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n throw new T402PaymentError(\n `Facilitator getSupported failed (${response.status}): ${errorText}`,\n {\n phase: \"unknown\",\n code: response.status,\n retryable: response.status >= 500 || response.status === 429,\n },\n );\n }\n\n return (await response.json()) as SupportedResponse;\n }\n\n /**\n * Creates authentication headers for a specific path.\n *\n * @param path - The path to create authentication headers for (e.g., \"verify\", \"settle\", \"supported\")\n * @returns An object containing the authentication headers for the specified path\n */\n async createAuthHeaders(path: string): Promise<{\n headers: Record<string, string>;\n }> {\n if (this._createAuthHeaders) {\n const authHeaders = (await this._createAuthHeaders()) as Record<\n string,\n Record<string, string>\n >;\n return {\n headers: authHeaders[path] ?? {},\n };\n }\n return {\n headers: {},\n };\n }\n\n /**\n * Helper to convert objects to JSON-safe format.\n * Handles BigInt and other non-JSON types.\n *\n * @param obj - The object to convert\n * @returns The JSON-safe representation of the object\n */\n private toJsonSafe(obj: unknown): unknown {\n return JSON.parse(\n JSON.stringify(obj, (_, value) => (typeof value === \"bigint\" ? value.toString() : value)),\n );\n }\n}\n","export const t402Version = 2;\n\n// Payment error\nexport { T402PaymentError } from \"./errors\";\nexport type { PaymentPhase } from \"./errors\";\n","import {\n SettleResponse,\n VerifyResponse,\n SupportedResponse,\n SupportedKind,\n} from \"../types/facilitator\";\nimport { PaymentPayload, PaymentRequirements, PaymentRequired } from \"../types/payments\";\nimport { SchemeNetworkServer } from \"../types/mechanisms\";\nimport { Price, Network, ResourceServerExtension } from \"../types\";\nimport { deepEqual, findByNetworkAndScheme } from \"../utils\";\nimport { FacilitatorClient, HTTPFacilitatorClient } from \"../http/httpFacilitatorClient\";\nimport { t402Version } from \"..\";\n\n/**\n * Configuration for a protected resource\n * Only contains payment-specific configuration, not resource metadata\n */\nexport interface ResourceConfig {\n scheme: string;\n payTo: string; // Payment recipient address\n price: Price;\n network: Network;\n maxTimeoutSeconds?: number;\n}\n\n/**\n * Resource information for PaymentRequired response\n */\nexport interface ResourceInfo {\n url: string;\n description: string;\n mimeType: string;\n}\n\n/**\n * Lifecycle Hook Context Interfaces\n */\n\nexport interface VerifyContext {\n paymentPayload: PaymentPayload;\n requirements: PaymentRequirements;\n}\n\nexport interface VerifyResultContext extends VerifyContext {\n result: VerifyResponse;\n}\n\nexport interface VerifyFailureContext extends VerifyContext {\n error: Error;\n}\n\nexport interface SettleContext {\n paymentPayload: PaymentPayload;\n requirements: PaymentRequirements;\n}\n\nexport interface SettleResultContext extends SettleContext {\n result: SettleResponse;\n}\n\nexport interface SettleFailureContext extends SettleContext {\n error: Error;\n}\n\n/**\n * Lifecycle Hook Type Definitions\n */\n\nexport type BeforeVerifyHook = (\n context: VerifyContext,\n) => Promise<void | { abort: true; reason: string }>;\n\nexport type AfterVerifyHook = (context: VerifyResultContext) => Promise<void>;\n\nexport type OnVerifyFailureHook = (\n context: VerifyFailureContext,\n) => Promise<void | { recovered: true; result: VerifyResponse }>;\n\nexport type BeforeSettleHook = (\n context: SettleContext,\n) => Promise<void | { abort: true; reason: string }>;\n\nexport type AfterSettleHook = (context: SettleResultContext) => Promise<void>;\n\nexport type OnSettleFailureHook = (\n context: SettleFailureContext,\n) => Promise<void | { recovered: true; result: SettleResponse }>;\n\n/**\n * Core t402 protocol server for resource protection\n * Transport-agnostic implementation of the t402 payment protocol\n */\nexport class t402ResourceServer {\n private facilitatorClients: FacilitatorClient[];\n private registeredServerSchemes: Map<string, Map<string, SchemeNetworkServer>> = new Map();\n private supportedResponsesMap: Map<number, Map<string, Map<string, SupportedResponse>>> =\n new Map();\n private facilitatorClientsMap: Map<number, Map<string, Map<string, FacilitatorClient>>> =\n new Map();\n private registeredExtensions: Map<string, ResourceServerExtension> = new Map();\n\n private beforeVerifyHooks: BeforeVerifyHook[] = [];\n private afterVerifyHooks: AfterVerifyHook[] = [];\n private onVerifyFailureHooks: OnVerifyFailureHook[] = [];\n private beforeSettleHooks: BeforeSettleHook[] = [];\n private afterSettleHooks: AfterSettleHook[] = [];\n private onSettleFailureHooks: OnSettleFailureHook[] = [];\n\n /**\n * Creates a new t402ResourceServer instance.\n *\n * @param facilitatorClients - Optional facilitator client(s) for payment processing\n */\n constructor(facilitatorClients?: FacilitatorClient | FacilitatorClient[]) {\n // Normalize facilitator clients to array\n if (!facilitatorClients) {\n // No clients provided, create a default HTTP client\n this.facilitatorClients = [new HTTPFacilitatorClient()];\n } else if (Array.isArray(facilitatorClients)) {\n // Array of clients provided\n this.facilitatorClients =\n facilitatorClients.length > 0 ? facilitatorClients : [new HTTPFacilitatorClient()];\n } else {\n // Single client provided\n this.facilitatorClients = [facilitatorClients];\n }\n }\n\n /**\n * Register a scheme/network server implementation.\n *\n * @param network - The network identifier\n * @param server - The scheme/network server implementation\n * @returns The t402ResourceServer instance for chaining\n */\n register(network: Network, server: SchemeNetworkServer): t402ResourceServer {\n if (!this.registeredServerSchemes.has(network)) {\n this.registeredServerSchemes.set(network, new Map());\n }\n\n const serverByScheme = this.registeredServerSchemes.get(network)!;\n if (!serverByScheme.has(server.scheme)) {\n serverByScheme.set(server.scheme, server);\n }\n\n return this;\n }\n\n /**\n * Check if a scheme is registered for a given network.\n *\n * @param network - The network identifier\n * @param scheme - The payment scheme name\n * @returns True if the scheme is registered for the network, false otherwise\n */\n hasRegisteredScheme(network: Network, scheme: string): boolean {\n return !!findByNetworkAndScheme(this.registeredServerSchemes, scheme, network);\n }\n\n /**\n * Registers a resource service extension that can enrich extension declarations.\n *\n * @param extension - The extension to register\n * @returns The t402ResourceServer instance for chaining\n */\n registerExtension(extension: ResourceServerExtension): this {\n this.registeredExtensions.set(extension.key, extension);\n return this;\n }\n\n /**\n * Enriches declared extensions using registered extension hooks.\n *\n * @param declaredExtensions - Extensions declared on the route\n * @param transportContext - Transport-specific context (HTTP, A2A, MCP, etc.)\n * @returns Enriched extensions map\n */\n enrichExtensions(\n declaredExtensions: Record<string, unknown>,\n transportContext: unknown,\n ): Record<string, unknown> {\n const enriched: Record<string, unknown> = {};\n\n for (const [key, declaration] of Object.entries(declaredExtensions)) {\n const extension = this.registeredExtensions.get(key);\n\n if (extension?.enrichDeclaration) {\n enriched[key] = extension.enrichDeclaration(declaration, transportContext);\n } else {\n enriched[key] = declaration;\n }\n }\n\n return enriched;\n }\n\n /**\n * Register a hook to execute before payment verification.\n * Can abort verification by returning { abort: true, reason: string }\n *\n * @param hook - The hook function to register\n * @returns The t402ResourceServer instance for chaining\n */\n onBeforeVerify(hook: BeforeVerifyHook): t402ResourceServer {\n this.beforeVerifyHooks.push(hook);\n return this;\n }\n\n /**\n * Register a hook to execute after successful payment verification.\n *\n * @param hook - The hook function to register\n * @returns The t402ResourceServer instance for chaining\n */\n onAfterVerify(hook: AfterVerifyHook): t402ResourceServer {\n this.afterVerifyHooks.push(hook);\n return this;\n }\n\n /**\n * Register a hook to execute when payment verification fails.\n * Can recover from failure by returning { recovered: true, result: VerifyResponse }\n *\n * @param hook - The hook function to register\n * @returns The t402ResourceServer instance for chaining\n */\n onVerifyFailure(hook: OnVerifyFailureHook): t402ResourceServer {\n this.onVerifyFailureHooks.push(hook);\n return this;\n }\n\n /**\n * Register a hook to execute before payment settlement.\n * Can abort settlement by returning { abort: true, reason: string }\n *\n * @param hook - The hook function to register\n * @returns The t402ResourceServer instance for chaining\n */\n onBeforeSettle(hook: BeforeSettleHook): t402ResourceServer {\n this.beforeSettleHooks.push(hook);\n return this;\n }\n\n /**\n * Register a hook to execute after successful payment settlement.\n *\n * @param hook - The hook function to register\n * @returns The t402ResourceServer instance for chaining\n */\n onAfterSettle(hook: AfterSettleHook): t402ResourceServer {\n this.afterSettleHooks.push(hook);\n return this;\n }\n\n /**\n * Register a hook to execute when payment settlement fails.\n * Can recover from failure by returning { recovered: true, result: SettleResponse }\n *\n * @param hook - The hook function to register\n * @returns The t402ResourceServer instance for chaining\n */\n onSettleFailure(hook: OnSettleFailureHook): t402ResourceServer {\n this.onSettleFailureHooks.push(hook);\n return this;\n }\n\n /**\n * Initialize by fetching supported kinds from all facilitators\n * Creates mappings for supported responses and facilitator clients\n * Earlier facilitators in the array get precedence\n */\n async initialize(): Promise<void> {\n // Clear existing mappings\n this.supportedResponsesMap.clear();\n this.facilitatorClientsMap.clear();\n\n // Fetch supported kinds from all facilitator clients\n // Process in order to give precedence to earlier facilitators\n for (const facilitatorClient of this.facilitatorClients) {\n try {\n const supported = await facilitatorClient.getSupported();\n\n // Process each supported kind (now flat array with version in each element)\n for (const kind of supported.kinds) {\n const t402Version = kind.t402Version;\n\n // Get or create version map for supported responses\n if (!this.supportedResponsesMap.has(t402Version)) {\n this.supportedResponsesMap.set(t402Version, new Map());\n }\n const responseVersionMap = this.supportedResponsesMap.get(t402Version)!;\n\n // Get or create version map for facilitator clients\n if (!this.facilitatorClientsMap.has(t402Version)) {\n this.facilitatorClientsMap.set(t402Version, new Map());\n }\n const clientVersionMap = this.facilitatorClientsMap.get(t402Version)!;\n\n // Get or create network map for responses\n if (!responseVersionMap.has(kind.network)) {\n responseVersionMap.set(kind.network, new Map());\n }\n const responseNetworkMap = responseVersionMap.get(kind.network)!;\n\n // Get or create network map for clients\n if (!clientVersionMap.has(kind.network)) {\n clientVersionMap.set(kind.network, new Map());\n }\n const clientNetworkMap = clientVersionMap.get(kind.network)!;\n\n // Only store if not already present (gives precedence to earlier facilitators)\n if (!responseNetworkMap.has(kind.scheme)) {\n responseNetworkMap.set(kind.scheme, supported);\n clientNetworkMap.set(kind.scheme, facilitatorClient);\n }\n }\n } catch (error) {\n // Log error but continue with other facilitators\n console.warn(`Failed to fetch supported kinds from facilitator: ${error}`);\n }\n }\n }\n\n /**\n * Get supported kind for a specific version, network, and scheme\n *\n * @param t402Version - The t402 version\n * @param network - The network identifier\n * @param scheme - The payment scheme\n * @returns The supported kind or undefined if not found\n */\n getSupportedKind(\n t402Version: number,\n network: Network,\n scheme: string,\n ): SupportedKind | undefined {\n const versionMap = this.supportedResponsesMap.get(t402Version);\n if (!versionMap) return undefined;\n\n const supportedResponse = findByNetworkAndScheme(versionMap, scheme, network);\n if (!supportedResponse) return undefined;\n\n // Find the specific kind from the response (kinds are flat array with version in each element)\n return supportedResponse.kinds.find(\n kind =>\n kind.t402Version === t402Version && kind.network === network && kind.scheme === scheme,\n );\n }\n\n /**\n * Get facilitator extensions for a specific version, network, and scheme\n *\n * @param t402Version - The t402 version\n * @param network - The network identifier\n * @param scheme - The payment scheme\n * @returns The facilitator extensions or empty array if not found\n */\n getFacilitatorExtensions(t402Version: number, network: Network, scheme: string): string[] {\n const versionMap = this.supportedResponsesMap.get(t402Version);\n if (!versionMap) return [];\n\n const supportedResponse = findByNetworkAndScheme(versionMap, scheme, network);\n return supportedResponse?.extensions || [];\n }\n\n /**\n * Build payment requirements for a protected resource\n *\n * @param resourceConfig - Configuration for the protected resource\n * @returns Array of payment requirements\n */\n async buildPaymentRequirements(resourceConfig: ResourceConfig): Promise<PaymentRequirements[]> {\n const requirements: PaymentRequirements[] = [];\n\n // Find the matching server implementation\n const scheme = resourceConfig.scheme;\n const SchemeNetworkServer = findByNetworkAndScheme(\n this.registeredServerSchemes,\n scheme,\n resourceConfig.network,\n );\n\n if (!SchemeNetworkServer) {\n // No server implementation registered for this scheme/network combination\n // Return empty requirements - caller must register appropriate scheme servers\n console.warn(\n `No server implementation registered for scheme: ${scheme}, network: ${resourceConfig.network}`,\n );\n return requirements;\n }\n\n // Find the matching supported kind from facilitator\n const supportedKind = this.getSupportedKind(\n t402Version,\n resourceConfig.network,\n SchemeNetworkServer.scheme,\n );\n\n if (!supportedKind) {\n throw new Error(\n `Facilitator does not support ${SchemeNetworkServer.scheme} on ${resourceConfig.network}. ` +\n `Make sure to call initialize() to fetch supported kinds from facilitators.`,\n );\n }\n\n // Get facilitator extensions for this combination\n const facilitatorExtensions = this.getFacilitatorExtensions(\n t402Version,\n resourceConfig.network,\n SchemeNetworkServer.scheme,\n );\n\n // Parse the price using the scheme's price parser\n const parsedPrice = await SchemeNetworkServer.parsePrice(\n resourceConfig.price,\n resourceConfig.network,\n );\n\n // Build base payment requirements from resource config\n const baseRequirements: PaymentRequirements = {\n scheme: SchemeNetworkServer.scheme,\n network: resourceConfig.network,\n amount: parsedPrice.amount,\n asset: parsedPrice.asset,\n payTo: resourceConfig.payTo,\n maxTimeoutSeconds: resourceConfig.maxTimeoutSeconds || 300, // Default 5 minutes\n extra: {\n ...parsedPrice.extra,\n },\n };\n\n // Delegate to the implementation for scheme-specific enhancements\n // Note: enhancePaymentRequirements expects t402Version in the kind, so we add it back\n const requirement = await SchemeNetworkServer.enhancePaymentRequirements(\n baseRequirements,\n {\n ...supportedKind,\n t402Version,\n },\n facilitatorExtensions,\n );\n\n requirements.push(requirement);\n return requirements;\n }\n\n /**\n * Build payment requirements from multiple payment options\n * This method handles resolving dynamic payTo/price functions and builds requirements for each option\n *\n * @param paymentOptions - Array of payment options to convert\n * @param context - HTTP request context for resolving dynamic functions\n * @returns Array of payment requirements (one per option)\n */\n async buildPaymentRequirementsFromOptions<TContext = unknown>(\n paymentOptions: Array<{\n scheme: string;\n payTo: string | ((context: TContext) => string | Promise<string>);\n price: Price | ((context: TContext) => Price | Promise<Price>);\n network: Network;\n maxTimeoutSeconds?: number;\n }>,\n context: TContext,\n ): Promise<PaymentRequirements[]> {\n const allRequirements: PaymentRequirements[] = [];\n\n for (const option of paymentOptions) {\n // Resolve dynamic payTo and price if they are functions\n const resolvedPayTo =\n typeof option.payTo === \"function\" ? await option.payTo(context) : option.payTo;\n const resolvedPrice =\n typeof option.price === \"function\" ? await option.price(context) : option.price;\n\n const resourceConfig: ResourceConfig = {\n scheme: option.scheme,\n payTo: resolvedPayTo,\n price: resolvedPrice,\n network: option.network,\n maxTimeoutSeconds: option.maxTimeoutSeconds,\n };\n\n // Use existing buildPaymentRequirements for each option\n const requirements = await this.buildPaymentRequirements(resourceConfig);\n allRequirements.push(...requirements);\n }\n\n return allRequirements;\n }\n\n /**\n * Create a payment required response\n *\n * @param requirements - Payment requirements\n * @param resourceInfo - Resource information\n * @param error - Error message\n * @param extensions - Optional extensions\n * @returns Payment required response object\n */\n createPaymentRequiredResponse(\n requirements: PaymentRequirements[],\n resourceInfo: ResourceInfo,\n error?: string,\n extensions?: Record<string, unknown>,\n ): PaymentRequired {\n // V2 response with resource at top level\n const response: PaymentRequired = {\n t402Version: 2,\n error,\n resource: resourceInfo,\n accepts: requirements as PaymentRequirements[],\n };\n\n // Add extensions if provided\n if (extensions && Object.keys(extensions).length > 0) {\n response.extensions = extensions;\n }\n\n return response;\n }\n\n /**\n * Verify a payment against requirements\n *\n * @param paymentPayload - The payment payload to verify\n * @param requirements - The payment requirements\n * @returns Verification response\n */\n async verifyPayment(\n paymentPayload: PaymentPayload,\n requirements: PaymentRequirements,\n ): Promise<VerifyResponse> {\n const context: VerifyContext = {\n paymentPayload,\n requirements,\n };\n\n // Execute beforeVerify hooks\n for (const hook of this.beforeVerifyHooks) {\n const result = await hook(context);\n if (result && \"abort\" in result && result.abort) {\n return {\n isValid: false,\n invalidReason: result.reason,\n };\n }\n }\n\n try {\n // Find the facilitator that supports this payment type\n const facilitatorClient = this.getFacilitatorClient(\n paymentPayload.t402Version,\n requirements.network,\n requirements.scheme,\n );\n\n let verifyResult: VerifyResponse;\n\n if (!facilitatorClient) {\n // Fallback: try all facilitators if no specific support found\n let lastError: Error | undefined;\n\n for (const client of this.facilitatorClients) {\n try {\n verifyResult = await client.verify(paymentPayload, requirements);\n break;\n } catch (error) {\n lastError = error as Error;\n }\n }\n\n if (!verifyResult!) {\n throw (\n lastError ||\n new Error(\n `No facilitator supports ${requirements.scheme} on ${requirements.network} for v${paymentPayload.t402Version}`,\n )\n );\n }\n } else {\n // Use the specific facilitator that supports this payment\n verifyResult = await facilitatorClient.verify(paymentPayload, requirements);\n }\n\n // Execute afterVerify hooks\n const resultContext: VerifyResultContext = {\n ...context,\n result: verifyResult,\n };\n\n for (const hook of this.afterVerifyHooks) {\n await hook(resultContext);\n }\n\n return verifyResult;\n } catch (error) {\n const failureContext: VerifyFailureContext = {\n ...context,\n error: error as Error,\n };\n\n // Execute onVerifyFailure hooks\n for (const hook of this.onVerifyFailureHooks) {\n const result = await hook(failureContext);\n if (result && \"recovered\" in result && result.recovered) {\n return result.result;\n }\n }\n\n throw error;\n }\n }\n\n /**\n * Settle a verified payment\n *\n * @param paymentPayload - The payment payload to settle\n * @param requirements - The payment requirements\n * @returns Settlement response\n */\n async settlePayment(\n paymentPayload: PaymentPayload,\n requirements: PaymentRequirements,\n ): Promise<SettleResponse> {\n const context: SettleContext = {\n paymentPayload,\n requirements,\n };\n\n // Execute beforeSettle hooks\n for (const hook of this.beforeSettleHooks) {\n const result = await hook(context);\n if (result && \"abort\" in result && result.abort) {\n throw new Error(`Settlement aborted: ${result.reason}`);\n }\n }\n\n try {\n // Find the facilitator that supports this payment type\n const facilitatorClient = this.getFacilitatorClient(\n paymentPayload.t402Version,\n requirements.network,\n requirements.scheme,\n );\n\n let settleResult: SettleResponse;\n\n if (!facilitatorClient) {\n // Fallback: try all facilitators if no specific support found\n let lastError: Error | undefined;\n\n for (const client of this.facilitatorClients) {\n try {\n settleResult = await client.settle(paymentPayload, requirements);\n break;\n } catch (error) {\n lastError = error as Error;\n }\n }\n\n if (!settleResult!) {\n throw (\n lastError ||\n new Error(\n `No facilitator supports ${requirements.scheme} on ${requirements.network} for v${paymentPayload.t402Version}`,\n )\n );\n }\n } else {\n // Use the specific facilitator that supports this payment\n settleResult = await facilitatorClient.settle(paymentPayload, requirements);\n }\n\n // Execute afterSettle hooks\n const resultContext: SettleResultContext = {\n ...context,\n result: settleResult,\n };\n\n for (const hook of this.afterSettleHooks) {\n await hook(resultContext);\n }\n\n return settleResult;\n } catch (error) {\n const failureContext: SettleFailureContext = {\n ...context,\n error: error as Error,\n };\n\n // Execute onSettleFailure hooks\n for (const hook of this.onSettleFailureHooks) {\n const result = await hook(failureContext);\n if (result && \"recovered\" in result && result.recovered) {\n return result.result;\n }\n }\n\n throw error;\n }\n }\n\n /**\n * Find matching payment requirements for a payment\n *\n * @param availableRequirements - Array of available payment requirements\n * @param paymentPayload - The payment payload\n * @returns Matching payment requirements or undefined\n */\n findMatchingRequirements(\n availableRequirements: PaymentRequirements[],\n paymentPayload: PaymentPayload,\n ): PaymentRequirements | undefined {\n switch (paymentPayload.t402Version) {\n case 2:\n // For v2, match by accepted requirements\n return availableRequirements.find(paymentRequirements =>\n deepEqual(paymentRequirements, paymentPayload.accepted),\n );\n case 1:\n // For v1, match by scheme and network\n return availableRequirements.find(\n req =>\n req.scheme === paymentPayload.accepted.scheme &&\n req.network === paymentPayload.accepted.network,\n );\n default:\n throw new Error(\n `Unsupported t402 version: ${(paymentPayload as PaymentPayload).t402Version}`,\n );\n }\n }\n\n /**\n * Process a payment request\n *\n * @param paymentPayload - Optional payment payload if provided\n * @param resourceConfig - Configuration for the protected resource\n * @param resourceInfo - Information about the resource being accessed\n * @param extensions - Optional extensions to include in the response\n * @returns Processing result\n */\n async processPaymentRequest(\n paymentPayload: PaymentPayload | null,\n resourceConfig: ResourceConfig,\n resourceInfo: ResourceInfo,\n extensions?: Record<string, unknown>,\n ): Promise<{\n success: boolean;\n requiresPayment?: PaymentRequired;\n verificationResult?: VerifyResponse;\n settlementResult?: SettleResponse;\n error?: string;\n }> {\n const requirements = await this.buildPaymentRequirements(resourceConfig);\n\n if (!paymentPayload) {\n return {\n success: false,\n requiresPayment: this.createPaymentRequiredResponse(\n requirements,\n resourceInfo,\n \"Payment required\",\n extensions,\n ),\n };\n }\n\n // Find matching requirements\n const matchingRequirements = this.findMatchingRequirements(requirements, paymentPayload);\n if (!matchingRequirements) {\n return {\n success: false,\n requiresPayment: this.createPaymentRequiredResponse(\n requirements,\n resourceInfo,\n \"No matching payment requirements found\",\n extensions,\n ),\n };\n }\n\n // Verify payment\n const verificationResult = await this.verifyPayment(paymentPayload, matchingRequirements);\n if (!verificationResult.isValid) {\n return {\n success: false,\n error: verificationResult.invalidReason,\n verificationResult,\n };\n }\n\n // Payment verified, ready for settlement\n return {\n success: true,\n verificationResult,\n };\n }\n\n /**\n * Get facilitator client for a specific version, network, and scheme\n *\n * @param t402Version - The t402 version\n * @param network - The network identifier\n * @param scheme - The payment scheme\n * @returns The facilitator client or undefined if not found\n */\n private getFacilitatorClient(\n t402Version: number,\n network: Network,\n scheme: string,\n ): FacilitatorClient | undefined {\n const versionMap = this.facilitatorClientsMap.get(t402Version);\n if (!versionMap) return undefined;\n\n // Use findByNetworkAndScheme for pattern matching\n return findByNetworkAndScheme(versionMap, scheme, network);\n }\n}\n\nexport default t402ResourceServer;\n","import { z } from \"zod\";\n\n/**\n * Zod schemas for T402 protocol types.\n * Used for runtime validation of incoming data.\n */\n\n// Network format: \"namespace:reference\" (CAIP-2)\nexport const NetworkSchema = z.string().regex(/^[a-z0-9-]+:[a-zA-Z0-9-]+$/, {\n message: \"Network must be in CAIP-2 format (e.g., 'eip155:1', 'solana:mainnet')\",\n});\n\n// Resource info for V2 protocol\nexport const ResourceInfoSchema = z.object({\n url: z.string().url({ message: \"Resource URL must be a valid URL\" }),\n description: z.string().optional(),\n mimeType: z.string().optional(),\n});\n\n// Payment requirements (what the server needs)\nexport const PaymentRequirementsSchema = z.object({\n scheme: z.string().min(1, { message: \"Scheme is required\" }),\n network: NetworkSchema,\n asset: z.string().min(1, { message: \"Asset address is required\" }),\n amount: z.string().regex(/^\\d+$/, { message: \"Amount must be a non-negative integer string\" }),\n payTo: z.string().min(1, { message: \"PayTo address is required\" }),\n maxTimeoutSeconds: z\n .number()\n .int()\n .positive({ message: \"maxTimeoutSeconds must be a positive integer\" }),\n extra: z.record(z.unknown()),\n});\n\n// Payment required response (402 response)\nexport const PaymentRequiredSchema = z.object({\n t402Version: z.literal(2, {\n errorMap: () => ({ message: \"t402Version must be 2 for V2 protocol\" }),\n }),\n error: z.string().optional(),\n resource: ResourceInfoSchema,\n accepts: z\n .array(PaymentRequirementsSchema)\n .min(1, { message: \"At least one payment option is required\" }),\n extensions: z.record(z.unknown()).optional(),\n});\n\n// Payment payload (client's signed payment)\nexport const PaymentPayloadSchema = z.object({\n t402Version: z.literal(2, {\n errorMap: () => ({ message: \"t402Version must be 2 for V2 protocol\" }),\n }),\n resource: ResourceInfoSchema.optional(),\n accepted: PaymentRequirementsSchema,\n payload: z.record(z.unknown()),\n extensions: z.record(z.unknown()).optional(),\n});\n\n// Verify response from facilitator\nexport const VerifyResponseSchema = z.object({\n isValid: z.boolean(),\n invalidReason: z.string().optional(),\n payer: z.string().optional(),\n});\n\n// Settle response from facilitator\nexport const SettleResponseSchema = z.object({\n success: z.boolean(),\n transaction: z.string(),\n network: NetworkSchema,\n errorReason: z.string().optional(),\n payer: z.string().optional(),\n confirmations: z.string().optional(),\n});\n\n// V1 schemas for backward compatibility\nexport const PaymentRequirementsV1Schema = z.object({\n scheme: z.string().min(1),\n network: z.string().min(1),\n asset: z.string().min(1),\n amount: z.string().regex(/^\\d+$/),\n payTo: z.string().min(1),\n maxTimeoutSeconds: z.number().int().positive(),\n extra: z.record(z.unknown()).optional(),\n});\n\nexport const PaymentPayloadV1Schema = z.object({\n t402Version: z.literal(1).optional(),\n accepted: PaymentRequirementsV1Schema,\n payload: z.record(z.unknown()),\n});\n\n// Type inference helpers\nexport type ValidatedPaymentPayload = z.infer<typeof PaymentPayloadSchema>;\nexport type ValidatedPaymentRequired = z.infer<typeof PaymentRequiredSchema>;\nexport type ValidatedPaymentRequirements = z.infer<typeof PaymentRequirementsSchema>;\nexport type ValidatedVerifyResponse = z.infer<typeof VerifyResponseSchema>;\nexport type ValidatedSettleResponse = z.infer<typeof SettleResponseSchema>;\n\n/**\n * Parse and validate a PaymentPayload.\n *\n * @param data - The data to parse\n * @returns The validated payment payload\n * @throws ZodError if validation fails\n */\nexport function parsePaymentPayload(data: unknown): ValidatedPaymentPayload {\n return PaymentPayloadSchema.parse(data);\n}\n\n/**\n * Parse and validate a PaymentRequired response.\n *\n * @param data - The data to parse\n * @returns The validated payment required response\n * @throws ZodError if validation fails\n */\nexport function parsePaymentRequired(data: unknown): ValidatedPaymentRequired {\n return PaymentRequiredSchema.parse(data);\n}\n\n/**\n * Parse and validate PaymentRequirements.\n *\n * @param data - The data to parse\n * @returns The validated payment requirements\n * @throws ZodError if validation fails\n */\nexport function parsePaymentRequirements(data: unknown): ValidatedPaymentRequirements {\n return PaymentRequirementsSchema.parse(data);\n}\n\n/**\n * Safely parse a PaymentPayload, returning a result object.\n *\n * @param data - The data to parse\n * @returns The safe parse result\n */\nexport function safeParsePaymentPayload(\n data: unknown,\n): z.SafeParseReturnType<unknown, ValidatedPaymentPayload> {\n return PaymentPayloadSchema.safeParse(data);\n}\n\n/**\n * Safely parse a PaymentRequired response, returning a result object.\n *\n * @param data - The data to parse\n * @returns The safe parse result\n */\nexport function safeParsePaymentRequired(\n data: unknown,\n): z.SafeParseReturnType<unknown, ValidatedPaymentRequired> {\n return PaymentRequiredSchema.safeParse(data);\n}\n\n/**\n * Safely parse PaymentRequirements, returning a result object.\n *\n * @param data - The data to parse\n * @returns The safe parse result\n */\nexport function safeParsePaymentRequirements(\n data: unknown,\n): z.SafeParseReturnType<unknown, ValidatedPaymentRequirements> {\n return PaymentRequirementsSchema.safeParse(data);\n}\n","import { SettleResponse } from \"../types\";\nimport { PaymentPayload, PaymentRequired, PaymentRequirements } from \"../types/payments\";\nimport {\n PaymentPayloadSchema,\n PaymentRequiredSchema,\n SettleResponseSchema,\n} from \"../types/schemas\";\nimport { Base64EncodedRegex, safeBase64Decode, safeBase64Encode } from \"../utils\";\n\n// HTTP Methods that typically use query parameters\nexport type QueryParamMethods = \"GET\" | \"HEAD\" | \"DELETE\";\n\n// HTTP Methods that typically use request body\nexport type BodyMethods = \"POST\" | \"PUT\" | \"PATCH\";\n\n/**\n * Encodes a payment payload as a base64 header value.\n *\n * @param paymentPayload - The payment payload to encode\n * @returns Base64 encoded string representation of the payment payload\n */\nexport function encodePaymentSignatureHeader(paymentPayload: PaymentPayload): string {\n return safeBase64Encode(JSON.stringify(paymentPayload));\n}\n\n/**\n * Decodes a base64 payment signature header into a payment payload.\n * Validates the payload structure using Zod schema.\n *\n * @param paymentSignatureHeader - The base64 encoded payment signature header\n * @returns The decoded and validated payment payload\n * @throws Error if the header is invalid or fails schema validation\n */\nexport function decodePaymentSignatureHeader(paymentSignatureHeader: string): PaymentPayload {\n if (!Base64EncodedRegex.test(paymentSignatureHeader)) {\n throw new Error(\"Invalid payment signature header\");\n }\n const parsed = JSON.parse(safeBase64Decode(paymentSignatureHeader));\n // Validate structure with Zod, then cast to TypeScript type\n // (Zod validates the structure; TypeScript types add template literal constraints)\n PaymentPayloadSchema.parse(parsed);\n return parsed as PaymentPayload;\n}\n\n/**\n * Encodes a payment required object as a base64 header value.\n *\n * @param paymentRequired - The payment required object to encode\n * @returns Base64 encoded string representation of the payment required object\n */\nexport function encodePaymentRequiredHeader(paymentRequired: PaymentRequired): string {\n return safeBase64Encode(JSON.stringify(paymentRequired));\n}\n\n/**\n * Decodes a base64 payment required header into a payment required object.\n * Validates the structure using Zod schema.\n *\n * @param paymentRequiredHeader - The base64 encoded payment required header\n * @returns The decoded and validated payment required object\n * @throws Error if the header is invalid or fails schema validation\n */\nexport function decodePaymentRequiredHeader(paymentRequiredHeader: string): PaymentRequired {\n if (!Base64EncodedRegex.test(paymentRequiredHeader)) {\n throw new Error(\"Invalid payment required header\");\n }\n const parsed = JSON.parse(safeBase64Decode(paymentRequiredHeader));\n // Validate structure with Zod, then cast to TypeScript type\n PaymentRequiredSchema.parse(parsed);\n return parsed as PaymentRequired;\n}\n\n/**\n * Encodes a payment response as a base64 header value.\n *\n * @param paymentResponse - The payment response to encode\n * @returns Base64 encoded string representation of the payment response\n */\nexport function encodePaymentResponseHeader(\n paymentResponse: SettleResponse & { requirements: PaymentRequirements },\n): string {\n return safeBase64Encode(JSON.stringify(paymentResponse));\n}\n\n/**\n * Decodes a base64 payment response header into a settle response.\n * Validates the structure using Zod schema.\n *\n * @param paymentResponseHeader - The base64 encoded payment response header\n * @returns The decoded and validated settle response\n * @throws Error if the header is invalid or fails schema validation\n */\nexport function decodePaymentResponseHeader(paymentResponseHeader: string): SettleResponse {\n if (!Base64EncodedRegex.test(paymentResponseHeader)) {\n throw new Error(\"Invalid payment response header\");\n }\n const parsed = JSON.parse(safeBase64Decode(paymentResponseHeader));\n // Validate structure with Zod, then cast to TypeScript type\n SettleResponseSchema.parse(parsed);\n return parsed as SettleResponse;\n}\n\n// Export HTTP service classes (values)\nexport { t402HTTPResourceServer, RouteConfigurationError } from \"./t402HTTPResourceServer\";\nexport { HTTPFacilitatorClient } from \"./httpFacilitatorClient\";\nexport { t402HTTPClient } from \"./t402HTTPClient\";\nexport { StreamingClient } from \"./streamingClient\";\nexport { IntentClient } from \"./intentClient\";\n\n// Export HTTP types (type-only exports for isolatedModules compatibility)\nexport type {\n HTTPAdapter,\n HTTPRequestContext,\n HTTPResponseInstructions,\n HTTPProcessResult,\n PaywallConfig,\n PaywallProvider,\n PaymentOption,\n RouteConfig,\n RoutesConfig,\n CompiledRoute,\n DynamicPayTo,\n DynamicPrice,\n UnpaidResponseBody,\n UnpaidResponseResult,\n ProcessSettleResultResponse,\n ProcessSettleSuccessResponse,\n ProcessSettleFailureResponse,\n RouteValidationError,\n} from \"./t402HTTPResourceServer\";\nexport type { FacilitatorClient, FacilitatorConfig, SettleOptions } from \"./httpFacilitatorClient\";\n\n// Streaming types\nexport type {\n StreamStatus,\n StreamMetadata,\n Stream,\n StreamUpdate,\n StreamStats,\n OpenStreamRequest,\n UpdateStreamRequest,\n CloseStreamRequest,\n ListStreamsParams,\n OpenStreamResponse,\n UpdateStreamResponse,\n CloseStreamResponse,\n GetStreamResponse,\n ListStreamsResponse,\n PauseResumeResponse,\n StreamingClientConfig,\n} from \"./streamingClient\";\n\n// Intent types\nexport type {\n IntentStatus,\n IntentPriority,\n RouteStepType,\n RouteStep,\n Route,\n Intent,\n CreateIntentRequest,\n SelectRouteRequest,\n ExecuteIntentRequest,\n CancelIntentRequest,\n ListIntentsParams,\n CreateIntentResponse,\n SelectRouteResponse,\n ExecuteIntentResponse,\n GetIntentResponse,\n ListIntentsResponse,\n CancelIntentResponse,\n RefreshRoutesResponse,\n IntentStats,\n IntentClientConfig,\n} from \"./intentClient\";\n","import { t402ResourceServer } from \"../server\";\nimport {\n decodePaymentSignatureHeader,\n encodePaymentRequiredHeader,\n encodePaymentResponseHeader,\n} from \".\";\nimport {\n PaymentPayload,\n PaymentRequired,\n SettleResponse,\n Price,\n Network,\n PaymentRequirements,\n} from \"../types\";\nimport { t402Version } from \"..\";\n\n/**\n * Framework-agnostic HTTP adapter interface\n * Implementations provide framework-specific HTTP operations\n */\nexport interface HTTPAdapter {\n getHeader(name: string): string | undefined;\n getMethod(): string;\n getPath(): string;\n getUrl(): string;\n getAcceptHeader(): string;\n getUserAgent(): string;\n\n /**\n * Get query parameters from the request URL\n *\n * @returns Record of query parameter key-value pairs\n */\n getQueryParams?(): Record<string, string | string[]>;\n\n /**\n * Get a specific query parameter by name\n *\n * @param name - The query parameter name\n * @returns The query parameter value(s) or undefined\n */\n getQueryParam?(name: string): string | string[] | undefined;\n\n /**\n * Get the parsed request body\n * Framework adapters should parse JSON/form data appropriately\n *\n * @returns The parsed request body\n */\n getBody?(): unknown;\n}\n\n/**\n * Paywall configuration for HTML responses\n */\nexport interface PaywallConfig {\n appName?: string;\n appLogo?: string;\n sessionTokenEndpoint?: string;\n currentUrl?: string;\n testnet?: boolean;\n}\n\n/**\n * Paywall provider interface for generating HTML\n */\nexport interface PaywallProvider {\n generateHtml(paymentRequired: PaymentRequired, config?: PaywallConfig): string;\n}\n\n/**\n * Dynamic payTo function that receives HTTP request context\n */\nexport type DynamicPayTo = (context: HTTPRequestContext) => string | Promise<string>;\n\n/**\n * Dynamic price function that receives HTTP request context\n */\nexport type DynamicPrice = (context: HTTPRequestContext) => Price | Promise<Price>;\n\n/**\n * Result of the unpaid response callback containing content type and body.\n */\nexport interface UnpaidResponseResult {\n /**\n * The content type for the response (e.g., 'application/json', 'text/plain').\n */\n contentType: string;\n\n /**\n * The response body to include in the 402 response.\n */\n body: unknown;\n}\n\n/**\n * Dynamic function to generate a custom response for unpaid requests.\n * Receives the HTTP request context and returns the content type and body to include in the 402 response.\n */\nexport type UnpaidResponseBody = (\n context: HTTPRequestContext,\n) => UnpaidResponseResult | Promise<UnpaidResponseResult>;\n\n/**\n * A single payment option for a route\n * Represents one way a client can pay for access to the resource\n */\nexport interface PaymentOption {\n scheme: string;\n payTo: string | DynamicPayTo;\n price: Price | DynamicPrice;\n network: Network;\n maxTimeoutSeconds?: number;\n extra?: Record<string, unknown>;\n}\n\n/**\n * Route configuration for HTTP endpoints\n *\n * The 'accepts' field defines payment options for the route.\n * Can be a single PaymentOption or an array of PaymentOptions for multiple payment methods.\n */\nexport interface RouteConfig {\n // Payment option(s): single or array\n accepts: PaymentOption | PaymentOption[];\n\n // HTTP-specific metadata\n resource?: string;\n description?: string;\n mimeType?: string;\n customPaywallHtml?: string;\n\n /**\n * Optional callback to generate a custom response for unpaid API requests.\n * This allows servers to return preview data, error messages, or other content\n * when a request lacks payment.\n *\n * For browser requests (Accept: text/html), the paywall HTML takes precedence.\n * This callback is only used for API clients.\n *\n * If not provided, defaults to { contentType: 'application/json', body: {} }.\n *\n * @returns An object containing both contentType and body for the 402 response\n */\n unpaidResponseBody?: UnpaidResponseBody;\n\n // Extensions\n extensions?: Record<string, unknown>;\n}\n\n/**\n * Routes configuration - maps path patterns to route configs\n */\nexport type RoutesConfig = Record<string, RouteConfig> | RouteConfig;\n\n/**\n * Compiled route for efficient matching\n */\nexport interface CompiledRoute {\n verb: string;\n regex: RegExp;\n config: RouteConfig;\n}\n\n/**\n * HTTP request context that encapsulates all request data\n */\nexport interface HTTPRequestContext {\n adapter: HTTPAdapter;\n path: string;\n method: string;\n paymentHeader?: string;\n}\n\n/**\n * HTTP response instructions for the framework middleware\n */\nexport interface HTTPResponseInstructions {\n status: number;\n headers: Record<string, string>;\n body?: unknown; // e.g. Paywall for web browser requests, but could be any other type\n isHtml?: boolean; // e.g. if body is a paywall, then isHtml is true\n}\n\n/**\n * Result of processing an HTTP request for payment\n */\nexport type HTTPProcessResult =\n | { type: \"no-payment-required\" }\n | {\n type: \"payment-verified\";\n paymentPayload: PaymentPayload;\n paymentRequirements: PaymentRequirements;\n }\n | { type: \"payment-error\"; response: HTTPResponseInstructions };\n\n/**\n * Result of processSettlement\n */\nexport type ProcessSettleSuccessResponse = SettleResponse & {\n success: true;\n headers: Record<string, string>;\n requirements: PaymentRequirements;\n};\n\nexport type ProcessSettleFailureResponse = SettleResponse & {\n success: false;\n errorReason: string;\n};\n\nexport type ProcessSettleResultResponse =\n | ProcessSettleSuccessResponse\n | ProcessSettleFailureResponse;\n\n/**\n * Represents a validation error for a specific route's payment configuration.\n */\nexport interface RouteValidationError {\n /** The route pattern (e.g., \"GET /api/weather\") */\n routePattern: string;\n /** The payment scheme that failed validation */\n scheme: string;\n /** The network that failed validation */\n network: Network;\n /** The type of validation failure */\n reason: \"missing_scheme\" | \"missing_facilitator\";\n /** Human-readable error message */\n message: string;\n}\n\n/**\n * Error thrown when route configuration validation fails.\n */\nexport class RouteConfigurationError extends Error {\n /** The validation errors that caused this exception */\n public readonly errors: RouteValidationError[];\n\n /**\n * Creates a new RouteConfigurationError with the given validation errors.\n *\n * @param errors - The validation errors that caused this exception.\n */\n constructor(errors: RouteValidationError[]) {\n const message = `t402 Route Configuration Errors:\\n${errors.map(e => ` - ${e.message}`).join(\"\\n\")}`;\n super(message);\n this.name = \"RouteConfigurationError\";\n this.errors = errors;\n }\n}\n\n/**\n * HTTP-enhanced t402 resource server\n * Provides framework-agnostic HTTP protocol handling\n */\nexport class t402HTTPResourceServer {\n private ResourceServer: t402ResourceServer;\n private compiledRoutes: CompiledRoute[] = [];\n private routesConfig: RoutesConfig;\n private paywallProvider?: PaywallProvider;\n\n /**\n * Creates a new t402HTTPResourceServer instance.\n *\n * @param ResourceServer - The core t402ResourceServer instance to use\n * @param routes - Route configuration for payment-protected endpoints\n */\n constructor(ResourceServer: t402ResourceServer, routes: RoutesConfig) {\n this.ResourceServer = ResourceServer;\n this.routesConfig = routes;\n\n // Handle both single route and multiple routes\n const normalizedRoutes =\n typeof routes === \"object\" && !(\"accepts\" in routes)\n ? (routes as Record<string, RouteConfig>)\n : { \"*\": routes as RouteConfig };\n\n for (const [pattern, config] of Object.entries(normalizedRoutes)) {\n const parsed = this.parseRoutePattern(pattern);\n this.compiledRoutes.push({\n verb: parsed.verb,\n regex: parsed.regex,\n config,\n });\n }\n }\n\n /**\n * Initialize the HTTP resource server.\n *\n * This method initializes the underlying resource server (fetching facilitator support)\n * and then validates that all route payment configurations have corresponding\n * registered schemes and facilitator support.\n *\n * @throws RouteConfigurationError if any route's payment options don't have\n * corresponding registered schemes or facilitator support\n *\n * @example\n * ```typescript\n * const httpServer = new t402HTTPResourceServer(server, routes);\n * await httpServer.initialize();\n * ```\n */\n async initialize(): Promise<void> {\n // First, initialize the underlying resource server (fetches facilitator support)\n await this.ResourceServer.initialize();\n\n // Then validate route configuration\n const errors = this.validateRouteConfiguration();\n if (errors.length > 0) {\n throw new RouteConfigurationError(errors);\n }\n }\n\n /**\n * Register a custom paywall provider for generating HTML\n *\n * @param provider - PaywallProvider instance\n * @returns This service instance for chaining\n */\n registerPaywallProvider(provider: PaywallProvider): this {\n this.paywallProvider = provider;\n return this;\n }\n\n /**\n * Process HTTP request and return response instructions\n * This is the main entry point for framework middleware\n *\n * @param context - HTTP request context\n * @param paywallConfig - Optional paywall configuration\n * @returns Process result indicating next action for middleware\n */\n async processHTTPRequest(\n context: HTTPRequestContext,\n paywallConfig?: PaywallConfig,\n ): Promise<HTTPProcessResult> {\n const { adapter, path, method } = context;\n\n // Find matching route\n const routeConfig = this.getRouteConfig(path, method);\n if (!routeConfig) {\n return { type: \"no-payment-required\" }; // No payment required for this route\n }\n\n // Normalize accepts field to array of payment options\n const paymentOptions = this.normalizePaymentOptions(routeConfig);\n\n // Check for payment header (v1 or v2)\n const paymentPayload = this.extractPayment(adapter);\n\n // Create resource info, using config override if provided\n const resourceInfo = {\n url: routeConfig.resource || context.adapter.getUrl(),\n description: routeConfig.description || \"\",\n mimeType: routeConfig.mimeType || \"\",\n };\n\n // Build requirements from all payment options\n // (this method handles resolving dynamic functions internally)\n const requirements = await this.ResourceServer.buildPaymentRequirementsFromOptions(\n paymentOptions,\n context,\n );\n\n let extensions = routeConfig.extensions;\n if (extensions) {\n extensions = this.ResourceServer.enrichExtensions(extensions, context);\n }\n\n const paymentRequired = this.ResourceServer.createPaymentRequiredResponse(\n requirements,\n resourceInfo,\n !paymentPayload ? \"Payment required\" : undefined,\n extensions,\n );\n\n // If no payment provided\n if (!paymentPayload) {\n // Resolve custom unpaid response body if provided\n const unpaidBody = routeConfig.unpaidResponseBody\n ? await routeConfig.unpaidResponseBody(context)\n : undefined;\n\n return {\n type: \"payment-error\",\n response: this.createHTTPResponse(\n paymentRequired,\n this.isWebBrowser(adapter),\n paywallConfig,\n routeConfig.customPaywallHtml,\n unpaidBody,\n ),\n };\n }\n\n // Verify payment\n try {\n const matchingRequirements = this.ResourceServer.findMatchingRequirements(\n paymentRequired.accepts,\n paymentPayload,\n );\n\n if (!matchingRequirements) {\n const errorResponse = this.ResourceServer.createPaymentRequiredResponse(\n requirements,\n resourceInfo,\n \"No matching payment requirements\",\n routeConfig.extensions,\n );\n return {\n type: \"payment-error\",\n response: this.createHTTPResponse(errorResponse, false, paywallConfig),\n };\n }\n\n const verifyResult = await this.ResourceServer.verifyPayment(\n paymentPayload,\n matchingRequirements,\n );\n\n if (!verifyResult.isValid) {\n const errorResponse = this.ResourceServer.createPaymentRequiredResponse(\n requirements,\n resourceInfo,\n verifyResult.invalidReason,\n routeConfig.extensions,\n );\n return {\n type: \"payment-error\",\n response: this.createHTTPResponse(errorResponse, false, paywallConfig),\n };\n }\n\n // Payment is valid, return data needed for settlement\n return {\n type: \"payment-verified\",\n paymentPayload,\n paymentRequirements: matchingRequirements,\n };\n } catch (error) {\n const errorResponse = this.ResourceServer.createPaymentRequiredResponse(\n requirements,\n resourceInfo,\n error instanceof Error ? error.message : \"Payment verification failed\",\n routeConfig.extensions,\n );\n return {\n type: \"payment-error\",\n response: this.createHTTPResponse(errorResponse, false, paywallConfig),\n };\n }\n }\n\n /**\n * Process settlement after successful response\n *\n * @param paymentPayload - The verified payment payload\n * @param requirements - The matching payment requirements\n * @returns ProcessSettleResultResponse - SettleResponse with headers if success or errorReason if failure\n */\n async processSettlement(\n paymentPayload: PaymentPayload,\n requirements: PaymentRequirements,\n ): Promise<ProcessSettleResultResponse> {\n try {\n const settleResponse = await this.ResourceServer.settlePayment(paymentPayload, requirements);\n\n if (!settleResponse.success) {\n return {\n ...settleResponse,\n success: false,\n errorReason: settleResponse.errorReason || \"Settlement failed\",\n };\n }\n\n return {\n ...settleResponse,\n success: true,\n headers: this.createSettlementHeaders(settleResponse, requirements),\n requirements,\n };\n } catch (error) {\n throw new Error(error instanceof Error ? error.message : \"Settlement failed\");\n }\n }\n\n /**\n * Check if a request requires payment based on route configuration\n *\n * @param context - HTTP request context\n * @returns True if the route requires payment, false otherwise\n */\n requiresPayment(context: HTTPRequestContext): boolean {\n const routeConfig = this.getRouteConfig(context.path, context.method);\n return routeConfig !== undefined;\n }\n\n /**\n * Normalizes a RouteConfig's accepts field into an array of PaymentOptions\n * Handles both single PaymentOption and array formats\n *\n * @param routeConfig - Route configuration\n * @returns Array of payment options\n */\n private normalizePaymentOptions(routeConfig: RouteConfig): PaymentOption[] {\n return Array.isArray(routeConfig.accepts) ? routeConfig.accepts : [routeConfig.accepts];\n }\n\n /**\n * Validates that all payment options in routes have corresponding registered schemes\n * and facilitator support.\n *\n * @returns Array of validation errors (empty if all routes are valid)\n */\n private validateRouteConfiguration(): RouteValidationError[] {\n const errors: RouteValidationError[] = [];\n\n // Normalize routes to array of [pattern, config] pairs\n const normalizedRoutes =\n typeof this.routesConfig === \"object\" && !(\"accepts\" in this.routesConfig)\n ? Object.entries(this.routesConfig as Record<string, RouteConfig>)\n : [[\"*\", this.routesConfig as RouteConfig] as [string, RouteConfig]];\n\n for (const [pattern, config] of normalizedRoutes) {\n const paymentOptions = this.normalizePaymentOptions(config);\n\n for (const option of paymentOptions) {\n // Check 1: Is scheme registered?\n if (!this.ResourceServer.hasRegisteredScheme(option.network, option.scheme)) {\n errors.push({\n routePattern: pattern,\n scheme: option.scheme,\n network: option.network,\n reason: \"missing_scheme\",\n message: `Route \"${pattern}\": No scheme implementation registered for \"${option.scheme}\" on network \"${option.network}\"`,\n });\n // Skip facilitator check if scheme isn't registered\n continue;\n }\n\n // Check 2: Does facilitator support this scheme/network combination?\n const supportedKind = this.ResourceServer.getSupportedKind(\n t402Version,\n option.network,\n option.scheme,\n );\n\n if (!supportedKind) {\n errors.push({\n routePattern: pattern,\n scheme: option.scheme,\n network: option.network,\n reason: \"missing_facilitator\",\n message: `Route \"${pattern}\": Facilitator does not support scheme \"${option.scheme}\" on network \"${option.network}\"`,\n });\n }\n }\n }\n\n return errors;\n }\n\n /**\n * Get route configuration for a request\n *\n * @param path - Request path\n * @param method - HTTP method\n * @returns Route configuration or undefined if no match\n */\n private getRouteConfig(path: string, method: string): RouteConfig | undefined {\n const normalizedPath = this.normalizePath(path);\n const upperMethod = method.toUpperCase();\n\n const matchingRoute = this.compiledRoutes.find(\n route =>\n route.regex.test(normalizedPath) && (route.verb === \"*\" || route.verb === upperMethod),\n );\n\n return matchingRoute?.config;\n }\n\n /**\n * Extract payment from HTTP headers (handles v1 and v2)\n *\n * @param adapter - HTTP adapter\n * @returns Decoded payment payload or null\n */\n private extractPayment(adapter: HTTPAdapter): PaymentPayload | null {\n // Check v2 header first (PAYMENT-SIGNATURE), then v1 fallback (X-PAYMENT)\n const header =\n adapter.getHeader(\"payment-signature\") ||\n adapter.getHeader(\"PAYMENT-SIGNATURE\") ||\n adapter.getHeader(\"x-payment\") ||\n adapter.getHeader(\"X-PAYMENT\");\n\n if (header) {\n try {\n return decodePaymentSignatureHeader(header);\n } catch (error) {\n console.warn(\"Failed to decode payment header:\", error);\n }\n }\n\n return null;\n }\n\n /**\n * Check if request is from a web browser\n *\n * @param adapter - HTTP adapter\n * @returns True if request appears to be from a browser\n */\n private isWebBrowser(adapter: HTTPAdapter): boolean {\n const accept = adapter.getAcceptHeader();\n const userAgent = adapter.getUserAgent();\n return accept.includes(\"text/html\") && userAgent.includes(\"Mozilla\");\n }\n\n /**\n * Create HTTP response instructions from payment required\n *\n * @param paymentRequired - Payment requirements\n * @param isWebBrowser - Whether request is from browser\n * @param paywallConfig - Paywall configuration\n * @param customHtml - Custom HTML template\n * @param unpaidResponse - Optional custom response (content type and body) for unpaid API requests\n * @returns Response instructions\n */\n private createHTTPResponse(\n paymentRequired: PaymentRequired,\n isWebBrowser: boolean,\n paywallConfig?: PaywallConfig,\n customHtml?: string,\n unpaidResponse?: UnpaidResponseResult,\n ): HTTPResponseInstructions {\n if (isWebBrowser) {\n const html = this.generatePaywallHTML(paymentRequired, paywallConfig, customHtml);\n return {\n status: 402,\n headers: { \"Content-Type\": \"text/html\" },\n body: html,\n isHtml: true,\n };\n }\n\n const response = this.createHTTPPaymentRequiredResponse(paymentRequired);\n\n // Use callback result if provided, otherwise default to JSON with empty object\n const contentType = unpaidResponse ? unpaidResponse.contentType : \"application/json\";\n const body = unpaidResponse ? unpaidResponse.body : {};\n\n return {\n status: 402,\n headers: {\n \"Content-Type\": contentType,\n ...response.headers,\n },\n body,\n };\n }\n\n /**\n * Create HTTP payment required response (v1 puts in body, v2 puts in header)\n *\n * @param paymentRequired - Payment required object\n * @returns Headers and body for the HTTP response\n */\n private createHTTPPaymentRequiredResponse(paymentRequired: PaymentRequired): {\n headers: Record<string, string>;\n } {\n return {\n headers: {\n \"PAYMENT-REQUIRED\": encodePaymentRequiredHeader(paymentRequired),\n },\n };\n }\n\n /**\n * Create settlement response headers\n *\n * @param settleResponse - Settlement response\n * @param requirements - Payment requirements that were settled\n * @returns Headers to add to response\n */\n private createSettlementHeaders(\n settleResponse: SettleResponse,\n requirements: PaymentRequirements,\n ): Record<string, string> {\n const encoded = encodePaymentResponseHeader({\n ...settleResponse,\n requirements,\n });\n return { \"PAYMENT-RESPONSE\": encoded };\n }\n\n /**\n * Parse route pattern into verb and regex\n *\n * @param pattern - Route pattern like \"GET /api/*\" or \"/api/[id]\"\n * @returns Parsed pattern with verb and regex\n */\n private parseRoutePattern(pattern: string): { verb: string; regex: RegExp } {\n const [verb, path] = pattern.includes(\" \") ? pattern.split(/\\s+/) : [\"*\", pattern];\n\n const regex = new RegExp(\n `^${\n path\n .replace(/[$()+.?^{|}]/g, \"\\\\$&\") // Escape regex special chars\n .replace(/\\*/g, \".*?\") // Wildcards\n .replace(/\\[([^\\]]+)\\]/g, \"[^/]+\") // Parameters\n .replace(/\\//g, \"\\\\/\") // Escape slashes\n }$`,\n \"i\",\n );\n\n return { verb: verb.toUpperCase(), regex };\n }\n\n /**\n * Normalize path for matching\n *\n * @param path - Raw path from request\n * @returns Normalized path\n */\n private normalizePath(path: string): string {\n try {\n const pathWithoutQuery = path.split(/[?#]/)[0];\n const decodedPath = decodeURIComponent(pathWithoutQuery);\n return decodedPath\n .replace(/\\\\/g, \"/\")\n .replace(/\\/+/g, \"/\")\n .replace(/(.+?)\\/+$/, \"$1\");\n } catch {\n return path;\n }\n }\n\n /**\n * Generate paywall HTML for browser requests\n *\n * @param paymentRequired - Payment required response\n * @param paywallConfig - Optional paywall configuration\n * @param customHtml - Optional custom HTML template\n * @returns HTML string\n */\n private generatePaywallHTML(\n paymentRequired: PaymentRequired,\n paywallConfig?: PaywallConfig,\n customHtml?: string,\n ): string {\n if (customHtml) {\n return customHtml;\n }\n\n // Use custom paywall provider if set\n if (this.paywallProvider) {\n return this.paywallProvider.generateHtml(paymentRequired, paywallConfig);\n }\n\n // Try to use @t402/paywall if available (optional dependency)\n try {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const paywall = require(\"@t402/paywall\");\n const displayAmount = this.getDisplayAmount(paymentRequired);\n const resource = paymentRequired.resource;\n\n return paywall.getPaywallHtml({\n amount: displayAmount,\n paymentRequired,\n currentUrl: resource?.url || paywallConfig?.currentUrl || \"\",\n testnet: paywallConfig?.testnet ?? true,\n appName: paywallConfig?.appName,\n appLogo: paywallConfig?.appLogo,\n sessionTokenEndpoint: paywallConfig?.sessionTokenEndpoint,\n });\n } catch {\n // @t402/paywall not installed, fall back to basic HTML\n }\n\n // Fallback: Basic HTML paywall\n const resource = paymentRequired.resource;\n const displayAmount = this.getDisplayAmount(paymentRequired);\n\n return `\n <!DOCTYPE html>\n <html>\n <head>\n <title>Payment Required</title>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n </head>\n <body>\n <div style=\"max-width: 600px; margin: 50px auto; padding: 20px; font-family: system-ui, -apple-system, sans-serif;\">\n ${paywallConfig?.appLogo ? `<img src=\"${paywallConfig.appLogo}\" alt=\"${paywallConfig.appName || \"App\"}\" style=\"max-width: 200px; margin-bottom: 20px;\">` : \"\"}\n <h1>Payment Required</h1>\n ${resource ? `<p><strong>Resource:</strong> ${resource.description || resource.url}</p>` : \"\"}\n <p><strong>Amount:</strong> $${displayAmount.toFixed(2)} USDC</p>\n <div id=\"payment-widget\" \n data-requirements='${JSON.stringify(paymentRequired)}'\n data-app-name=\"${paywallConfig?.appName || \"\"}\"\n data-testnet=\"${paywallConfig?.testnet || false}\">\n <!-- Install @t402/paywall for full wallet integration -->\n <p style=\"margin-top: 2rem; padding: 1rem; background: #fef3c7; border-radius: 0.5rem;\">\n <strong>Note:</strong> Install <code>@t402/paywall</code> for full wallet connection and payment UI.\n </p>\n </div>\n </div>\n </body>\n </html>\n `;\n }\n\n /**\n * Extract display amount from payment requirements.\n *\n * @param paymentRequired - The payment required object\n * @returns The display amount in decimal format\n */\n private getDisplayAmount(paymentRequired: PaymentRequired): number {\n const accepts = paymentRequired.accepts;\n if (accepts && accepts.length > 0) {\n const firstReq = accepts[0];\n if (\"amount\" in firstReq) {\n // V2 format\n return parseFloat(firstReq.amount) / 1000000; // Assuming USDC with 6 decimals\n }\n }\n return 0;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmHO,IAAM,uBAAuB,CAClC,KACA,YAC+B;AAE/B,MAAI,0BAA0B,IAAI,IAAI,OAAO;AAE7C,MAAI,CAAC,yBAAyB;AAE5B,eAAW,CAAC,0BAA0B,eAAe,KAAK,IAAI,QAAQ,GAAG;AAGvE,YAAM,UAAU,yBACb,QAAQ,uBAAuB,MAAM,EACrC,QAAQ,SAAS,IAAI;AAExB,YAAM,QAAQ,IAAI,OAAO,IAAI,OAAO,GAAG;AAEvC,UAAI,MAAM,KAAK,OAAO,GAAG;AACvB,kCAA0B;AAC1B;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEO,IAAM,yBAAyB,CACpC,KACA,QACA,YACkB;AAClB,SAAO,qBAAqB,KAAK,OAAO,GAAG,IAAI,MAAM;AACvD;AAiCO,IAAM,qBAAqB;AAQ3B,SAAS,iBAAiB,MAAsB;AACrD,MAAI,OAAO,eAAe,eAAe,OAAO,WAAW,SAAS,YAAY;AAC9E,WAAO,WAAW,KAAK,IAAI;AAAA,EAC7B;AACA,SAAO,OAAO,KAAK,IAAI,EAAE,SAAS,QAAQ;AAC5C;AAQO,SAAS,iBAAiB,MAAsB;AACrD,MAAI,OAAO,eAAe,eAAe,OAAO,WAAW,SA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CAAC,CAAC;AAAA;AAAA,sCAE7B,KAAK,UAAU,eAAe,CAAC;AAAA,kCACnC,eAAe,WAAW,EAAE;AAAA,iCAC7B,eAAe,WAAW,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAU9D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,iBAAiB,iBAA0C;AACjE,UAAM,UAAU,gBAAgB;AAChC,QAAI,WAAW,QAAQ,SAAS,GAAG;AACjC,YAAM,WAAW,QAAQ,CAAC;AAC1B,UAAI,YAAY,UAAU;AAExB,eAAO,WAAW,SAAS,MAAM,IAAI;AAAA,MACvC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":["t402Version","displayAmount","resource"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/server/index.ts","../../../src/utils/index.ts","../../../src/errors.ts","../../../src/http/httpFacilitatorClient.ts","../../../src/index.ts","../../../src/server/t402ResourceServer.ts","../../../src/types/schemas.ts","../../../src/http/index.ts","../../../src/http/t402HTTPResourceServer.ts"],"sourcesContent":["export { t402ResourceServer } from \"./t402ResourceServer\";\nexport type {\n ResourceConfig,\n ResourceInfo,\n BeforeVerifyHook,\n AfterVerifyHook,\n OnVerifyFailureHook,\n BeforeSettleHook,\n AfterSettleHook,\n OnSettleFailureHook,\n VerifyContext,\n VerifyResultContext,\n VerifyFailureContext,\n SettleContext,\n SettleResultContext,\n SettleFailureContext,\n} from \"./t402ResourceServer\";\n\nexport { HTTPFacilitatorClient } from \"../http/httpFacilitatorClient\";\nexport type { FacilitatorClient, FacilitatorConfig, SettleOptions } from \"../http/httpFacilitatorClient\";\n\nexport { t402HTTPResourceServer, RouteConfigurationError } from \"../http/t402HTTPResourceServer\";\nexport type {\n HTTPRequestContext,\n HTTPResponseInstructions,\n HTTPProcessResult,\n PaywallConfig,\n PaywallProvider,\n RouteConfig,\n CompiledRoute,\n HTTPAdapter,\n RoutesConfig,\n UnpaidResponseBody,\n UnpaidResponseResult,\n ProcessSettleResultResponse,\n ProcessSettleSuccessResponse,\n ProcessSettleFailureResponse,\n RouteValidationError,\n} from \"../http/t402HTTPResourceServer\";\n","import { Network } from \"../types\";\n\n// ============================================================================\n// Cryptographically Secure Random Utilities\n// ============================================================================\n\n/**\n * Get the crypto object, works in both browser and Node.js (19+)\n *\n * @returns The crypto object\n * @throws Error if crypto API is not available\n */\nfunction getCrypto(): Crypto {\n const cryptoObj = globalThis.crypto;\n\n if (!cryptoObj || typeof cryptoObj.getRandomValues !== \"function\") {\n throw new Error(\n \"Crypto API not available. \" + \"Node.js 19+ or a browser with Web Crypto API is required.\",\n );\n }\n\n return cryptoObj;\n}\n\n/**\n * Generate a cryptographically secure random integer in range [0, max)\n *\n * Uses rejection sampling to ensure uniform distribution.\n *\n * @param max - Exclusive upper bound (must be > 0 and <= 2^32)\n * @returns Random integer in [0, max)\n * @throws Error if max is invalid or crypto unavailable\n */\nexport function cryptoRandomInt(max: number): number {\n if (max <= 0 || max > 0xffffffff || !Number.isInteger(max)) {\n throw new Error(`Invalid max value: ${max}. Must be positive integer <= 2^32`);\n }\n\n const crypto = getCrypto();\n const array = new Uint32Array(1);\n\n // Rejection sampling to avoid modulo bias\n const limit = Math.floor(0xffffffff / max) * max;\n let value: number;\n\n do {\n crypto.getRandomValues(array);\n value = array[0];\n } while (value >= limit);\n\n return value % max;\n}\n\n/**\n * Generate a cryptographically secure random BigInt\n *\n * @param bits - Number of bits (default 64, max 256)\n * @returns Random BigInt with specified number of bits\n * @throws Error if bits is invalid or crypto unavailable\n */\nexport function cryptoRandomBigInt(bits: number = 64): bigint {\n if (bits <= 0 || bits > 256) {\n throw new Error(`Invalid bits value: ${bits}. Must be 1-256`);\n }\n\n const crypto = getCrypto();\n const bytes = Math.ceil(bits / 8);\n const array = new Uint8Array(bytes);\n crypto.getRandomValues(array);\n\n // Convert bytes to BigInt\n let result = 0n;\n for (let i = 0; i < bytes; i++) {\n result = (result << 8n) | BigInt(array[i]);\n }\n\n // Mask to exact bit count\n const mask = (1n << BigInt(bits)) - 1n;\n return result & mask;\n}\n\n/**\n * Generate a cryptographically secure random hex string\n *\n * @param bytes - Number of random bytes (default 16)\n * @returns Hex-encoded random string\n * @throws Error if bytes is invalid or crypto unavailable\n */\nexport function cryptoRandomHex(bytes: number = 16): string {\n if (bytes <= 0 || bytes > 128) {\n throw new Error(`Invalid bytes value: ${bytes}. Must be 1-128`);\n }\n\n const crypto = getCrypto();\n const array = new Uint8Array(bytes);\n crypto.getRandomValues(array);\n\n return Array.from(array)\n .map(b => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\n// ============================================================================\n// Network and Scheme Utilities\n// ============================================================================\n\n/**\n * Scheme data structure for facilitator storage\n */\nexport interface SchemeData<T> {\n facilitator: T;\n networks: Set<Network>;\n pattern: Network;\n}\n\nexport const findSchemesByNetwork = <T>(\n map: Map<string, Map<string, T>>,\n network: Network,\n): Map<string, T> | undefined => {\n // Direct match first\n let implementationsByScheme = map.get(network);\n\n if (!implementationsByScheme) {\n // Try pattern matching for registered network patterns\n for (const [registeredNetworkPattern, implementations] of map.entries()) {\n // Convert the registered network pattern to a regex\n // e.g., \"eip155:*\" becomes /^eip155:.*$/\n const pattern = registeredNetworkPattern\n .replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\") // Escape special regex chars except *\n .replace(/\\\\\\*/g, \".*\"); // Replace escaped * with .*\n\n const regex = new RegExp(`^${pattern}$`);\n\n if (regex.test(network)) {\n implementationsByScheme = implementations;\n break;\n }\n }\n }\n\n return implementationsByScheme;\n};\n\nexport const findByNetworkAndScheme = <T>(\n map: Map<string, Map<string, T>>,\n scheme: string,\n network: Network,\n): T | undefined => {\n return findSchemesByNetwork(map, network)?.get(scheme);\n};\n\n/**\n * Finds a facilitator by scheme and network using pattern matching.\n * Works with new SchemeData storage structure.\n *\n * @param schemeMap - Map of scheme names to SchemeData\n * @param scheme - The scheme to find\n * @param network - The network to match against\n * @returns The facilitator if found, undefined otherwise\n */\nexport const findFacilitatorBySchemeAndNetwork = <T>(\n schemeMap: Map<string, SchemeData<T>>,\n scheme: string,\n network: Network,\n): T | undefined => {\n const schemeData = schemeMap.get(scheme);\n if (!schemeData) return undefined;\n\n // Check if network is in the stored networks set\n if (schemeData.networks.has(network)) {\n return schemeData.facilitator;\n }\n\n // Try pattern matching\n const patternRegex = new RegExp(\"^\" + schemeData.pattern.replace(\"*\", \".*\") + \"$\");\n if (patternRegex.test(network)) {\n return schemeData.facilitator;\n }\n\n return undefined;\n};\n\nexport const Base64EncodedRegex = /^[A-Za-z0-9+/]*={0,2}$/;\n\n/**\n * Encodes a string to base64 format\n *\n * @param data - The string to be encoded to base64\n * @returns The base64 encoded string\n */\nexport function safeBase64Encode(data: string): string {\n if (typeof globalThis !== \"undefined\" && typeof globalThis.btoa === \"function\") {\n return globalThis.btoa(data);\n }\n return Buffer.from(data).toString(\"base64\");\n}\n\n/**\n * Decodes a base64 string back to its original format\n *\n * @param data - The base64 encoded string to be decoded\n * @returns The decoded string in UTF-8 format\n */\nexport function safeBase64Decode(data: string): string {\n if (typeof globalThis !== \"undefined\" && typeof globalThis.atob === \"function\") {\n return globalThis.atob(data);\n }\n return Buffer.from(data, \"base64\").toString(\"utf-8\");\n}\n\n/**\n * Deep equality comparison for payment requirements\n * Uses a normalized JSON.stringify for consistent comparison\n *\n * @param obj1 - First object to compare\n * @param obj2 - Second object to compare\n * @returns True if objects are deeply equal\n */\nexport function deepEqual(obj1: unknown, obj2: unknown): boolean {\n // Normalize and stringify both objects for comparison\n // This handles nested objects, arrays, and different property orders\n const normalize = (obj: unknown): string => {\n // Handle primitives and null/undefined\n if (obj === null || obj === undefined) return JSON.stringify(obj);\n if (typeof obj !== \"object\") return JSON.stringify(obj);\n\n // Handle arrays\n if (Array.isArray(obj)) {\n return JSON.stringify(\n obj.map(item =>\n typeof item === \"object\" && item !== null ? JSON.parse(normalize(item)) : item,\n ),\n );\n }\n\n // Handle objects - sort keys and recursively normalize values\n const sorted: Record<string, unknown> = {};\n Object.keys(obj as Record<string, unknown>)\n .sort()\n .forEach(key => {\n const value = (obj as Record<string, unknown>)[key];\n sorted[key] =\n typeof value === \"object\" && value !== null ? JSON.parse(normalize(value)) : value;\n });\n return JSON.stringify(sorted);\n };\n\n try {\n return normalize(obj1) === normalize(obj2);\n } catch {\n // Fallback to simple comparison if normalization fails\n return JSON.stringify(obj1) === JSON.stringify(obj2);\n }\n}\n","/**\n * T402PaymentError - Structured error class for the T402 payment protocol.\n *\n * Wraps upstream errors with payment-specific context: phase, retryability,\n * and optional HTTP status code.\n */\n\nexport type PaymentPhase = \"signing\" | \"submission\" | \"verification\" | \"settlement\" | \"unknown\";\n\nexport class T402PaymentError extends Error {\n readonly cause?: Error;\n readonly phase: PaymentPhase;\n readonly retryable: boolean;\n readonly code?: number;\n\n constructor(\n message: string,\n options?: {\n cause?: Error;\n phase?: PaymentPhase;\n retryable?: boolean;\n code?: number;\n },\n ) {\n super(message);\n this.name = \"T402PaymentError\";\n this.cause = options?.cause;\n this.phase = options?.phase ?? \"unknown\";\n this.retryable = options?.retryable ?? false;\n this.code = options?.code;\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, T402PaymentError);\n }\n }\n\n isRetryable(): boolean {\n return this.retryable;\n }\n\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n message: this.message,\n phase: this.phase,\n retryable: this.retryable,\n code: this.code,\n cause: this.cause?.message,\n };\n }\n}\n","import { PaymentPayload, PaymentRequirements } from \"../types/payments\";\nimport { VerifyResponse, SettleResponse, SupportedResponse } from \"../types/facilitator\";\nimport { T402PaymentError } from \"../errors\";\n\nconst DEFAULT_FACILITATOR_URL = \"https://facilitator.t402.io\";\n\nexport interface SettleOptions {\n /** Optional idempotency key for replay protection */\n idempotencyKey?: string;\n}\n\nexport interface FacilitatorConfig {\n url?: string;\n createAuthHeaders?: () => Promise<{\n verify: Record<string, string>;\n settle: Record<string, string>;\n supported: Record<string, string>;\n }>;\n}\n\n/**\n * Interface for facilitator clients\n * Can be implemented for HTTP-based or local facilitators\n */\nexport interface FacilitatorClient {\n /**\n * Verify a payment with the facilitator\n *\n * @param paymentPayload - The payment to verify\n * @param paymentRequirements - The requirements to verify against\n * @returns Verification response\n */\n verify(\n paymentPayload: PaymentPayload,\n paymentRequirements: PaymentRequirements,\n ): Promise<VerifyResponse>;\n\n /**\n * Settle a payment with the facilitator\n *\n * @param paymentPayload - The payment to settle\n * @param paymentRequirements - The requirements for settlement\n * @param options - Optional settings including idempotency key\n * @returns Settlement response\n */\n settle(\n paymentPayload: PaymentPayload,\n paymentRequirements: PaymentRequirements,\n options?: SettleOptions,\n ): Promise<SettleResponse>;\n\n /**\n * Get supported payment kinds and extensions from the facilitator\n *\n * @returns Supported payment kinds and extensions\n */\n getSupported(): Promise<SupportedResponse>;\n}\n\n/**\n * HTTP-based client for interacting with t402 facilitator services\n * Handles HTTP communication with facilitator endpoints\n */\nexport class HTTPFacilitatorClient implements FacilitatorClient {\n readonly url: string;\n private readonly _createAuthHeaders?: FacilitatorConfig[\"createAuthHeaders\"];\n\n /**\n * Creates a new HTTPFacilitatorClient instance.\n *\n * @param config - Configuration options for the facilitator client\n */\n constructor(config?: FacilitatorConfig) {\n this.url = config?.url || DEFAULT_FACILITATOR_URL;\n this._createAuthHeaders = config?.createAuthHeaders;\n }\n\n /**\n * Verify a payment with the facilitator\n *\n * @param paymentPayload - The payment to verify\n * @param paymentRequirements - The requirements to verify against\n * @returns Verification response\n */\n async verify(\n paymentPayload: PaymentPayload,\n paymentRequirements: PaymentRequirements,\n ): Promise<VerifyResponse> {\n let headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n\n if (this._createAuthHeaders) {\n const authHeaders = await this.createAuthHeaders(\"verify\");\n headers = { ...headers, ...authHeaders.headers };\n }\n\n const response = await fetch(`${this.url}/verify`, {\n method: \"POST\",\n headers,\n body: JSON.stringify({\n t402Version: paymentPayload.t402Version,\n paymentPayload: this.toJsonSafe(paymentPayload),\n paymentRequirements: this.toJsonSafe(paymentRequirements),\n }),\n });\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n throw new T402PaymentError(`Facilitator verify failed (${response.status}): ${errorText}`, {\n phase: \"verification\",\n code: response.status,\n retryable: response.status >= 500 || response.status === 429,\n });\n }\n\n return (await response.json()) as VerifyResponse;\n }\n\n /**\n * Settle a payment with the facilitator\n *\n * @param paymentPayload - The payment to settle\n * @param paymentRequirements - The requirements for settlement\n * @param options - Optional settings including idempotency key\n * @returns Settlement response\n */\n async settle(\n paymentPayload: PaymentPayload,\n paymentRequirements: PaymentRequirements,\n options?: SettleOptions,\n ): Promise<SettleResponse> {\n let headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n\n if (options?.idempotencyKey) {\n headers[\"Idempotency-Key\"] = options.idempotencyKey;\n }\n\n if (this._createAuthHeaders) {\n const authHeaders = await this.createAuthHeaders(\"settle\");\n headers = { ...headers, ...authHeaders.headers };\n }\n\n const response = await fetch(`${this.url}/settle`, {\n method: \"POST\",\n headers,\n body: JSON.stringify({\n t402Version: paymentPayload.t402Version,\n paymentPayload: this.toJsonSafe(paymentPayload),\n paymentRequirements: this.toJsonSafe(paymentRequirements),\n }),\n });\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n throw new T402PaymentError(`Facilitator settle failed (${response.status}): ${errorText}`, {\n phase: \"settlement\",\n code: response.status,\n retryable: response.status >= 500 || response.status === 429,\n });\n }\n\n return (await response.json()) as SettleResponse;\n }\n\n /**\n * Get supported payment kinds and extensions from the facilitator\n *\n * @returns Supported payment kinds and extensions\n */\n async getSupported(): Promise<SupportedResponse> {\n let headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n\n if (this._createAuthHeaders) {\n const authHeaders = await this.createAuthHeaders(\"supported\");\n headers = { ...headers, ...authHeaders.headers };\n }\n\n const response = await fetch(`${this.url}/supported`, {\n method: \"GET\",\n headers,\n });\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n throw new T402PaymentError(\n `Facilitator getSupported failed (${response.status}): ${errorText}`,\n {\n phase: \"unknown\",\n code: response.status,\n retryable: response.status >= 500 || response.status === 429,\n },\n );\n }\n\n return (await response.json()) as SupportedResponse;\n }\n\n /**\n * Creates authentication headers for a specific path.\n *\n * @param path - The path to create authentication headers for (e.g., \"verify\", \"settle\", \"supported\")\n * @returns An object containing the authentication headers for the specified path\n */\n async createAuthHeaders(path: string): Promise<{\n headers: Record<string, string>;\n }> {\n if (this._createAuthHeaders) {\n const authHeaders = (await this._createAuthHeaders()) as Record<\n string,\n Record<string, string>\n >;\n return {\n headers: authHeaders[path] ?? {},\n };\n }\n return {\n headers: {},\n };\n }\n\n /**\n * Helper to convert objects to JSON-safe format.\n * Handles BigInt and other non-JSON types.\n *\n * @param obj - The object to convert\n * @returns The JSON-safe representation of the object\n */\n private toJsonSafe(obj: unknown): unknown {\n return JSON.parse(\n JSON.stringify(obj, (_, value) => (typeof value === \"bigint\" ? value.toString() : value)),\n );\n }\n}\n","export const t402Version = 2;\n\n// Payment error\nexport { T402PaymentError } from \"./errors\";\nexport type { PaymentPhase } from \"./errors\";\n","import {\n SettleResponse,\n VerifyResponse,\n SupportedResponse,\n SupportedKind,\n} from \"../types/facilitator\";\nimport { PaymentPayload, PaymentRequirements, PaymentRequired } from \"../types/payments\";\nimport { SchemeNetworkServer } from \"../types/mechanisms\";\nimport { Price, Network, ResourceServerExtension } from \"../types\";\nimport { deepEqual, findByNetworkAndScheme } from \"../utils\";\nimport { FacilitatorClient, HTTPFacilitatorClient } from \"../http/httpFacilitatorClient\";\nimport { t402Version } from \"..\";\n\n/**\n * Configuration for a protected resource\n * Only contains payment-specific configuration, not resource metadata\n */\nexport interface ResourceConfig {\n scheme: string;\n payTo: string; // Payment recipient address\n price: Price;\n network: Network;\n maxTimeoutSeconds?: number;\n}\n\n/**\n * Resource information for PaymentRequired response\n */\nexport interface ResourceInfo {\n url: string;\n description: string;\n mimeType: string;\n}\n\n/**\n * Lifecycle Hook Context Interfaces\n */\n\nexport interface VerifyContext {\n paymentPayload: PaymentPayload;\n requirements: PaymentRequirements;\n}\n\nexport interface VerifyResultContext extends VerifyContext {\n result: VerifyResponse;\n}\n\nexport interface VerifyFailureContext extends VerifyContext {\n error: Error;\n}\n\nexport interface SettleContext {\n paymentPayload: PaymentPayload;\n requirements: PaymentRequirements;\n}\n\nexport interface SettleResultContext extends SettleContext {\n result: SettleResponse;\n}\n\nexport interface SettleFailureContext extends SettleContext {\n error: Error;\n}\n\n/**\n * Lifecycle Hook Type Definitions\n */\n\nexport type BeforeVerifyHook = (\n context: VerifyContext,\n) => Promise<void | { abort: true; reason: string }>;\n\nexport type AfterVerifyHook = (context: VerifyResultContext) => Promise<void>;\n\nexport type OnVerifyFailureHook = (\n context: VerifyFailureContext,\n) => Promise<void | { recovered: true; result: VerifyResponse }>;\n\nexport type BeforeSettleHook = (\n context: SettleContext,\n) => Promise<void | { abort: true; reason: string }>;\n\nexport type AfterSettleHook = (context: SettleResultContext) => Promise<void>;\n\nexport type OnSettleFailureHook = (\n context: SettleFailureContext,\n) => Promise<void | { recovered: true; result: SettleResponse }>;\n\n/**\n * Core t402 protocol server for resource protection\n * Transport-agnostic implementation of the t402 payment protocol\n */\nexport class t402ResourceServer {\n private facilitatorClients: FacilitatorClient[];\n private registeredServerSchemes: Map<string, Map<string, SchemeNetworkServer>> = new Map();\n private supportedResponsesMap: Map<number, Map<string, Map<string, SupportedResponse>>> =\n new Map();\n private facilitatorClientsMap: Map<number, Map<string, Map<string, FacilitatorClient>>> =\n new Map();\n private registeredExtensions: Map<string, ResourceServerExtension> = new Map();\n\n private beforeVerifyHooks: BeforeVerifyHook[] = [];\n private afterVerifyHooks: AfterVerifyHook[] = [];\n private onVerifyFailureHooks: OnVerifyFailureHook[] = [];\n private beforeSettleHooks: BeforeSettleHook[] = [];\n private afterSettleHooks: AfterSettleHook[] = [];\n private onSettleFailureHooks: OnSettleFailureHook[] = [];\n\n /**\n * Creates a new t402ResourceServer instance.\n *\n * @param facilitatorClients - Optional facilitator client(s) for payment processing\n */\n constructor(facilitatorClients?: FacilitatorClient | FacilitatorClient[]) {\n // Normalize facilitator clients to array\n if (!facilitatorClients) {\n // No clients provided, create a default HTTP client\n this.facilitatorClients = [new HTTPFacilitatorClient()];\n } else if (Array.isArray(facilitatorClients)) {\n // Array of clients provided\n this.facilitatorClients =\n facilitatorClients.length > 0 ? facilitatorClients : [new HTTPFacilitatorClient()];\n } else {\n // Single client provided\n this.facilitatorClients = [facilitatorClients];\n }\n }\n\n /**\n * Register a scheme/network server implementation.\n *\n * @param network - The network identifier\n * @param server - The scheme/network server implementation\n * @returns The t402ResourceServer instance for chaining\n */\n register(network: Network, server: SchemeNetworkServer): t402ResourceServer {\n if (!this.registeredServerSchemes.has(network)) {\n this.registeredServerSchemes.set(network, new Map());\n }\n\n const serverByScheme = this.registeredServerSchemes.get(network)!;\n if (!serverByScheme.has(server.scheme)) {\n serverByScheme.set(server.scheme, server);\n }\n\n return this;\n }\n\n /**\n * Check if a scheme is registered for a given network.\n *\n * @param network - The network identifier\n * @param scheme - The payment scheme name\n * @returns True if the scheme is registered for the network, false otherwise\n */\n hasRegisteredScheme(network: Network, scheme: string): boolean {\n return !!findByNetworkAndScheme(this.registeredServerSchemes, scheme, network);\n }\n\n /**\n * Registers a resource service extension that can enrich extension declarations.\n *\n * @param extension - The extension to register\n * @returns The t402ResourceServer instance for chaining\n */\n registerExtension(extension: ResourceServerExtension): this {\n this.registeredExtensions.set(extension.key, extension);\n return this;\n }\n\n /**\n * Enriches declared extensions using registered extension hooks.\n *\n * @param declaredExtensions - Extensions declared on the route\n * @param transportContext - Transport-specific context (HTTP, A2A, MCP, etc.)\n * @returns Enriched extensions map\n */\n enrichExtensions(\n declaredExtensions: Record<string, unknown>,\n transportContext: unknown,\n ): Record<string, unknown> {\n const enriched: Record<string, unknown> = {};\n\n for (const [key, declaration] of Object.entries(declaredExtensions)) {\n const extension = this.registeredExtensions.get(key);\n\n if (extension?.enrichDeclaration) {\n enriched[key] = extension.enrichDeclaration(declaration, transportContext);\n } else {\n enriched[key] = declaration;\n }\n }\n\n return enriched;\n }\n\n /**\n * Register a hook to execute before payment verification.\n * Can abort verification by returning { abort: true, reason: string }\n *\n * @param hook - The hook function to register\n * @returns The t402ResourceServer instance for chaining\n */\n onBeforeVerify(hook: BeforeVerifyHook): t402ResourceServer {\n this.beforeVerifyHooks.push(hook);\n return this;\n }\n\n /**\n * Register a hook to execute after successful payment verification.\n *\n * @param hook - The hook function to register\n * @returns The t402ResourceServer instance for chaining\n */\n onAfterVerify(hook: AfterVerifyHook): t402ResourceServer {\n this.afterVerifyHooks.push(hook);\n return this;\n }\n\n /**\n * Register a hook to execute when payment verification fails.\n * Can recover from failure by returning { recovered: true, result: VerifyResponse }\n *\n * @param hook - The hook function to register\n * @returns The t402ResourceServer instance for chaining\n */\n onVerifyFailure(hook: OnVerifyFailureHook): t402ResourceServer {\n this.onVerifyFailureHooks.push(hook);\n return this;\n }\n\n /**\n * Register a hook to execute before payment settlement.\n * Can abort settlement by returning { abort: true, reason: string }\n *\n * @param hook - The hook function to register\n * @returns The t402ResourceServer instance for chaining\n */\n onBeforeSettle(hook: BeforeSettleHook): t402ResourceServer {\n this.beforeSettleHooks.push(hook);\n return this;\n }\n\n /**\n * Register a hook to execute after successful payment settlement.\n *\n * @param hook - The hook function to register\n * @returns The t402ResourceServer instance for chaining\n */\n onAfterSettle(hook: AfterSettleHook): t402ResourceServer {\n this.afterSettleHooks.push(hook);\n return this;\n }\n\n /**\n * Register a hook to execute when payment settlement fails.\n * Can recover from failure by returning { recovered: true, result: SettleResponse }\n *\n * @param hook - The hook function to register\n * @returns The t402ResourceServer instance for chaining\n */\n onSettleFailure(hook: OnSettleFailureHook): t402ResourceServer {\n this.onSettleFailureHooks.push(hook);\n return this;\n }\n\n /**\n * Initialize by fetching supported kinds from all facilitators\n * Creates mappings for supported responses and facilitator clients\n * Earlier facilitators in the array get precedence\n */\n async initialize(): Promise<void> {\n // Clear existing mappings\n this.supportedResponsesMap.clear();\n this.facilitatorClientsMap.clear();\n\n // Fetch supported kinds from all facilitator clients\n // Process in order to give precedence to earlier facilitators\n for (const facilitatorClient of this.facilitatorClients) {\n try {\n const supported = await facilitatorClient.getSupported();\n\n // Process each supported kind (now flat array with version in each element)\n for (const kind of supported.kinds) {\n const t402Version = kind.t402Version;\n\n // Get or create version map for supported responses\n if (!this.supportedResponsesMap.has(t402Version)) {\n this.supportedResponsesMap.set(t402Version, new Map());\n }\n const responseVersionMap = this.supportedResponsesMap.get(t402Version)!;\n\n // Get or create version map for facilitator clients\n if (!this.facilitatorClientsMap.has(t402Version)) {\n this.facilitatorClientsMap.set(t402Version, new Map());\n }\n const clientVersionMap = this.facilitatorClientsMap.get(t402Version)!;\n\n // Get or create network map for responses\n if (!responseVersionMap.has(kind.network)) {\n responseVersionMap.set(kind.network, new Map());\n }\n const responseNetworkMap = responseVersionMap.get(kind.network)!;\n\n // Get or create network map for clients\n if (!clientVersionMap.has(kind.network)) {\n clientVersionMap.set(kind.network, new Map());\n }\n const clientNetworkMap = clientVersionMap.get(kind.network)!;\n\n // Only store if not already present (gives precedence to earlier facilitators)\n if (!responseNetworkMap.has(kind.scheme)) {\n responseNetworkMap.set(kind.scheme, supported);\n clientNetworkMap.set(kind.scheme, facilitatorClient);\n }\n }\n } catch (error) {\n // Log error but continue with other facilitators\n console.warn(`Failed to fetch supported kinds from facilitator: ${error}`);\n }\n }\n }\n\n /**\n * Get supported kind for a specific version, network, and scheme\n *\n * @param t402Version - The t402 version\n * @param network - The network identifier\n * @param scheme - The payment scheme\n * @returns The supported kind or undefined if not found\n */\n getSupportedKind(\n t402Version: number,\n network: Network,\n scheme: string,\n ): SupportedKind | undefined {\n const versionMap = this.supportedResponsesMap.get(t402Version);\n if (!versionMap) return undefined;\n\n const supportedResponse = findByNetworkAndScheme(versionMap, scheme, network);\n if (!supportedResponse) return undefined;\n\n // Find the specific kind from the response (kinds are flat array with version in each element)\n return supportedResponse.kinds.find(\n kind =>\n kind.t402Version === t402Version && kind.network === network && kind.scheme === scheme,\n );\n }\n\n /**\n * Get facilitator extensions for a specific version, network, and scheme\n *\n * @param t402Version - The t402 version\n * @param network - The network identifier\n * @param scheme - The payment scheme\n * @returns The facilitator extensions or empty array if not found\n */\n getFacilitatorExtensions(t402Version: number, network: Network, scheme: string): string[] {\n const versionMap = this.supportedResponsesMap.get(t402Version);\n if (!versionMap) return [];\n\n const supportedResponse = findByNetworkAndScheme(versionMap, scheme, network);\n return supportedResponse?.extensions || [];\n }\n\n /**\n * Build payment requirements for a protected resource\n *\n * @param resourceConfig - Configuration for the protected resource\n * @returns Array of payment requirements\n */\n async buildPaymentRequirements(resourceConfig: ResourceConfig): Promise<PaymentRequirements[]> {\n const requirements: PaymentRequirements[] = [];\n\n // Find the matching server implementation\n const scheme = resourceConfig.scheme;\n const SchemeNetworkServer = findByNetworkAndScheme(\n this.registeredServerSchemes,\n scheme,\n resourceConfig.network,\n );\n\n if (!SchemeNetworkServer) {\n // No server implementation registered for this scheme/network combination\n // Return empty requirements - caller must register appropriate scheme servers\n console.warn(\n `No server implementation registered for scheme: ${scheme}, network: ${resourceConfig.network}`,\n );\n return requirements;\n }\n\n // Find the matching supported kind from facilitator\n const supportedKind = this.getSupportedKind(\n t402Version,\n resourceConfig.network,\n SchemeNetworkServer.scheme,\n );\n\n if (!supportedKind) {\n throw new Error(\n `Facilitator does not support ${SchemeNetworkServer.scheme} on ${resourceConfig.network}. ` +\n `Make sure to call initialize() to fetch supported kinds from facilitators.`,\n );\n }\n\n // Get facilitator extensions for this combination\n const facilitatorExtensions = this.getFacilitatorExtensions(\n t402Version,\n resourceConfig.network,\n SchemeNetworkServer.scheme,\n );\n\n // Parse the price using the scheme's price parser\n const parsedPrice = await SchemeNetworkServer.parsePrice(\n resourceConfig.price,\n resourceConfig.network,\n );\n\n // Build base payment requirements from resource config\n const baseRequirements: PaymentRequirements = {\n scheme: SchemeNetworkServer.scheme,\n network: resourceConfig.network,\n amount: parsedPrice.amount,\n asset: parsedPrice.asset,\n payTo: resourceConfig.payTo,\n maxTimeoutSeconds: resourceConfig.maxTimeoutSeconds || 300, // Default 5 minutes\n extra: {\n ...parsedPrice.extra,\n },\n };\n\n // Delegate to the implementation for scheme-specific enhancements\n // Note: enhancePaymentRequirements expects t402Version in the kind, so we add it back\n const requirement = await SchemeNetworkServer.enhancePaymentRequirements(\n baseRequirements,\n {\n ...supportedKind,\n t402Version,\n },\n facilitatorExtensions,\n );\n\n requirements.push(requirement);\n return requirements;\n }\n\n /**\n * Build payment requirements from multiple payment options\n * This method handles resolving dynamic payTo/price functions and builds requirements for each option\n *\n * @param paymentOptions - Array of payment options to convert\n * @param context - HTTP request context for resolving dynamic functions\n * @returns Array of payment requirements (one per option)\n */\n async buildPaymentRequirementsFromOptions<TContext = unknown>(\n paymentOptions: Array<{\n scheme: string;\n payTo: string | ((context: TContext) => string | Promise<string>);\n price: Price | ((context: TContext) => Price | Promise<Price>);\n network: Network;\n maxTimeoutSeconds?: number;\n }>,\n context: TContext,\n ): Promise<PaymentRequirements[]> {\n const allRequirements: PaymentRequirements[] = [];\n\n for (const option of paymentOptions) {\n // Resolve dynamic payTo and price if they are functions\n const resolvedPayTo =\n typeof option.payTo === \"function\" ? await option.payTo(context) : option.payTo;\n const resolvedPrice =\n typeof option.price === \"function\" ? await option.price(context) : option.price;\n\n const resourceConfig: ResourceConfig = {\n scheme: option.scheme,\n payTo: resolvedPayTo,\n price: resolvedPrice,\n network: option.network,\n maxTimeoutSeconds: option.maxTimeoutSeconds,\n };\n\n // Use existing buildPaymentRequirements for each option\n const requirements = await this.buildPaymentRequirements(resourceConfig);\n allRequirements.push(...requirements);\n }\n\n return allRequirements;\n }\n\n /**\n * Create a payment required response\n *\n * @param requirements - Payment requirements\n * @param resourceInfo - Resource information\n * @param error - Error message\n * @param extensions - Optional extensions\n * @returns Payment required response object\n */\n createPaymentRequiredResponse(\n requirements: PaymentRequirements[],\n resourceInfo: ResourceInfo,\n error?: string,\n extensions?: Record<string, unknown>,\n ): PaymentRequired {\n // V2 response with resource at top level\n const response: PaymentRequired = {\n t402Version: 2,\n error,\n resource: resourceInfo,\n accepts: requirements as PaymentRequirements[],\n };\n\n // Add extensions if provided\n if (extensions && Object.keys(extensions).length > 0) {\n response.extensions = extensions;\n }\n\n return response;\n }\n\n /**\n * Verify a payment against requirements\n *\n * @param paymentPayload - The payment payload to verify\n * @param requirements - The payment requirements\n * @returns Verification response\n */\n async verifyPayment(\n paymentPayload: PaymentPayload,\n requirements: PaymentRequirements,\n ): Promise<VerifyResponse> {\n const context: VerifyContext = {\n paymentPayload,\n requirements,\n };\n\n // Execute beforeVerify hooks\n for (const hook of this.beforeVerifyHooks) {\n const result = await hook(context);\n if (result && \"abort\" in result && result.abort) {\n return {\n isValid: false,\n invalidReason: result.reason,\n };\n }\n }\n\n try {\n // Find the facilitator that supports this payment type\n const facilitatorClient = this.getFacilitatorClient(\n paymentPayload.t402Version,\n requirements.network,\n requirements.scheme,\n );\n\n let verifyResult: VerifyResponse;\n\n if (!facilitatorClient) {\n // Fallback: try all facilitators if no specific support found\n let lastError: Error | undefined;\n\n for (const client of this.facilitatorClients) {\n try {\n verifyResult = await client.verify(paymentPayload, requirements);\n break;\n } catch (error) {\n lastError = error as Error;\n }\n }\n\n if (!verifyResult!) {\n throw (\n lastError ||\n new Error(\n `No facilitator supports ${requirements.scheme} on ${requirements.network} for v${paymentPayload.t402Version}`,\n )\n );\n }\n } else {\n // Use the specific facilitator that supports this payment\n verifyResult = await facilitatorClient.verify(paymentPayload, requirements);\n }\n\n // Execute afterVerify hooks\n const resultContext: VerifyResultContext = {\n ...context,\n result: verifyResult,\n };\n\n for (const hook of this.afterVerifyHooks) {\n await hook(resultContext);\n }\n\n return verifyResult;\n } catch (error) {\n const failureContext: VerifyFailureContext = {\n ...context,\n error: error as Error,\n };\n\n // Execute onVerifyFailure hooks\n for (const hook of this.onVerifyFailureHooks) {\n const result = await hook(failureContext);\n if (result && \"recovered\" in result && result.recovered) {\n return result.result;\n }\n }\n\n throw error;\n }\n }\n\n /**\n * Settle a verified payment\n *\n * @param paymentPayload - The payment payload to settle\n * @param requirements - The payment requirements\n * @returns Settlement response\n */\n async settlePayment(\n paymentPayload: PaymentPayload,\n requirements: PaymentRequirements,\n ): Promise<SettleResponse> {\n const context: SettleContext = {\n paymentPayload,\n requirements,\n };\n\n // Execute beforeSettle hooks\n for (const hook of this.beforeSettleHooks) {\n const result = await hook(context);\n if (result && \"abort\" in result && result.abort) {\n throw new Error(`Settlement aborted: ${result.reason}`);\n }\n }\n\n try {\n // Find the facilitator that supports this payment type\n const facilitatorClient = this.getFacilitatorClient(\n paymentPayload.t402Version,\n requirements.network,\n requirements.scheme,\n );\n\n let settleResult: SettleResponse;\n\n if (!facilitatorClient) {\n // Fallback: try all facilitators if no specific support found\n let lastError: Error | undefined;\n\n for (const client of this.facilitatorClients) {\n try {\n settleResult = await client.settle(paymentPayload, requirements);\n break;\n } catch (error) {\n lastError = error as Error;\n }\n }\n\n if (!settleResult!) {\n throw (\n lastError ||\n new Error(\n `No facilitator supports ${requirements.scheme} on ${requirements.network} for v${paymentPayload.t402Version}`,\n )\n );\n }\n } else {\n // Use the specific facilitator that supports this payment\n settleResult = await facilitatorClient.settle(paymentPayload, requirements);\n }\n\n // Execute afterSettle hooks\n const resultContext: SettleResultContext = {\n ...context,\n result: settleResult,\n };\n\n for (const hook of this.afterSettleHooks) {\n await hook(resultContext);\n }\n\n return settleResult;\n } catch (error) {\n const failureContext: SettleFailureContext = {\n ...context,\n error: error as Error,\n };\n\n // Execute onSettleFailure hooks\n for (const hook of this.onSettleFailureHooks) {\n const result = await hook(failureContext);\n if (result && \"recovered\" in result && result.recovered) {\n return result.result;\n }\n }\n\n throw error;\n }\n }\n\n /**\n * Find matching payment requirements for a payment\n *\n * @param availableRequirements - Array of available payment requirements\n * @param paymentPayload - The payment payload\n * @returns Matching payment requirements or undefined\n */\n findMatchingRequirements(\n availableRequirements: PaymentRequirements[],\n paymentPayload: PaymentPayload,\n ): PaymentRequirements | undefined {\n switch (paymentPayload.t402Version) {\n case 2:\n // For v2, match by accepted requirements\n return availableRequirements.find(paymentRequirements =>\n deepEqual(paymentRequirements, paymentPayload.accepted),\n );\n case 1:\n // For v1, match by scheme and network\n return availableRequirements.find(\n req =>\n req.scheme === paymentPayload.accepted.scheme &&\n req.network === paymentPayload.accepted.network,\n );\n default:\n throw new Error(\n `Unsupported t402 version: ${(paymentPayload as PaymentPayload).t402Version}`,\n );\n }\n }\n\n /**\n * Process a payment request\n *\n * @param paymentPayload - Optional payment payload if provided\n * @param resourceConfig - Configuration for the protected resource\n * @param resourceInfo - Information about the resource being accessed\n * @param extensions - Optional extensions to include in the response\n * @returns Processing result\n */\n async processPaymentRequest(\n paymentPayload: PaymentPayload | null,\n resourceConfig: ResourceConfig,\n resourceInfo: ResourceInfo,\n extensions?: Record<string, unknown>,\n ): Promise<{\n success: boolean;\n requiresPayment?: PaymentRequired;\n verificationResult?: VerifyResponse;\n settlementResult?: SettleResponse;\n error?: string;\n }> {\n const requirements = await this.buildPaymentRequirements(resourceConfig);\n\n if (!paymentPayload) {\n return {\n success: false,\n requiresPayment: this.createPaymentRequiredResponse(\n requirements,\n resourceInfo,\n \"Payment required\",\n extensions,\n ),\n };\n }\n\n // Find matching requirements\n const matchingRequirements = this.findMatchingRequirements(requirements, paymentPayload);\n if (!matchingRequirements) {\n return {\n success: false,\n requiresPayment: this.createPaymentRequiredResponse(\n requirements,\n resourceInfo,\n \"No matching payment requirements found\",\n extensions,\n ),\n };\n }\n\n // Verify payment\n const verificationResult = await this.verifyPayment(paymentPayload, matchingRequirements);\n if (!verificationResult.isValid) {\n return {\n success: false,\n error: verificationResult.invalidReason,\n verificationResult,\n };\n }\n\n // Payment verified, ready for settlement\n return {\n success: true,\n verificationResult,\n };\n }\n\n /**\n * Get facilitator client for a specific version, network, and scheme\n *\n * @param t402Version - The t402 version\n * @param network - The network identifier\n * @param scheme - The payment scheme\n * @returns The facilitator client or undefined if not found\n */\n private getFacilitatorClient(\n t402Version: number,\n network: Network,\n scheme: string,\n ): FacilitatorClient | undefined {\n const versionMap = this.facilitatorClientsMap.get(t402Version);\n if (!versionMap) return undefined;\n\n // Use findByNetworkAndScheme for pattern matching\n return findByNetworkAndScheme(versionMap, scheme, network);\n }\n}\n\nexport default t402ResourceServer;\n","import { z } from \"zod\";\n\n/**\n * Zod schemas for T402 protocol types.\n * Used for runtime validation of incoming data.\n */\n\n// Network format: \"namespace:reference\" (CAIP-2)\nexport const NetworkSchema = z.string().regex(/^[a-z0-9-]+:[a-zA-Z0-9-]+$/, {\n message: \"Network must be in CAIP-2 format (e.g., 'eip155:1', 'solana:mainnet')\",\n});\n\n// Resource info for V2 protocol\nexport const ResourceInfoSchema = z.object({\n url: z.string().url({ message: \"Resource URL must be a valid URL\" }),\n description: z.string().optional(),\n mimeType: z.string().optional(),\n});\n\n// Payment requirements (what the server needs)\nexport const PaymentRequirementsSchema = z.object({\n scheme: z.string().min(1, { message: \"Scheme is required\" }),\n network: NetworkSchema,\n asset: z.string().min(1, { message: \"Asset address is required\" }),\n amount: z.string().regex(/^\\d+$/, { message: \"Amount must be a non-negative integer string\" }),\n payTo: z.string().min(1, { message: \"PayTo address is required\" }),\n maxTimeoutSeconds: z\n .number()\n .int()\n .positive({ message: \"maxTimeoutSeconds must be a positive integer\" }),\n extra: z.record(z.unknown()),\n});\n\n// Payment required response (402 response)\nexport const PaymentRequiredSchema = z.object({\n t402Version: z.literal(2, {\n errorMap: () => ({ message: \"t402Version must be 2 for V2 protocol\" }),\n }),\n error: z.string().optional(),\n resource: ResourceInfoSchema,\n accepts: z\n .array(PaymentRequirementsSchema)\n .min(1, { message: \"At least one payment option is required\" }),\n extensions: z.record(z.unknown()).optional(),\n});\n\n// Payment payload (client's signed payment)\nexport const PaymentPayloadSchema = z.object({\n t402Version: z.literal(2, {\n errorMap: () => ({ message: \"t402Version must be 2 for V2 protocol\" }),\n }),\n resource: ResourceInfoSchema.optional(),\n accepted: PaymentRequirementsSchema,\n payload: z.record(z.unknown()),\n extensions: z.record(z.unknown()).optional(),\n});\n\n// Verify response from facilitator\nexport const VerifyResponseSchema = z.object({\n isValid: z.boolean(),\n invalidReason: z.string().optional(),\n payer: z.string().optional(),\n});\n\n// Settle response from facilitator\nexport const SettleResponseSchema = z.object({\n success: z.boolean(),\n transaction: z.string(),\n network: NetworkSchema,\n errorReason: z.string().optional(),\n payer: z.string().optional(),\n confirmations: z.string().optional(),\n});\n\n// V1 schemas for backward compatibility\nexport const PaymentRequirementsV1Schema = z.object({\n scheme: z.string().min(1),\n network: z.string().min(1),\n asset: z.string().min(1),\n amount: z.string().regex(/^\\d+$/),\n payTo: z.string().min(1),\n maxTimeoutSeconds: z.number().int().positive(),\n extra: z.record(z.unknown()).optional(),\n});\n\nexport const PaymentPayloadV1Schema = z.object({\n t402Version: z.literal(1).optional(),\n accepted: PaymentRequirementsV1Schema,\n payload: z.record(z.unknown()),\n});\n\n// Type inference helpers\nexport type ValidatedPaymentPayload = z.infer<typeof PaymentPayloadSchema>;\nexport type ValidatedPaymentRequired = z.infer<typeof PaymentRequiredSchema>;\nexport type ValidatedPaymentRequirements = z.infer<typeof PaymentRequirementsSchema>;\nexport type ValidatedVerifyResponse = z.infer<typeof VerifyResponseSchema>;\nexport type ValidatedSettleResponse = z.infer<typeof SettleResponseSchema>;\n\n/**\n * Parse and validate a PaymentPayload.\n *\n * @param data - The data to parse\n * @returns The validated payment payload\n * @throws ZodError if validation fails\n */\nexport function parsePaymentPayload(data: unknown): ValidatedPaymentPayload {\n return PaymentPayloadSchema.parse(data);\n}\n\n/**\n * Parse and validate a PaymentRequired response.\n *\n * @param data - The data to parse\n * @returns The validated payment required response\n * @throws ZodError if validation fails\n */\nexport function parsePaymentRequired(data: unknown): ValidatedPaymentRequired {\n return PaymentRequiredSchema.parse(data);\n}\n\n/**\n * Parse and validate PaymentRequirements.\n *\n * @param data - The data to parse\n * @returns The validated payment requirements\n * @throws ZodError if validation fails\n */\nexport function parsePaymentRequirements(data: unknown): ValidatedPaymentRequirements {\n return PaymentRequirementsSchema.parse(data);\n}\n\n/**\n * Safely parse a PaymentPayload, returning a result object.\n *\n * @param data - The data to parse\n * @returns The safe parse result\n */\nexport function safeParsePaymentPayload(\n data: unknown,\n): z.SafeParseReturnType<unknown, ValidatedPaymentPayload> {\n return PaymentPayloadSchema.safeParse(data);\n}\n\n/**\n * Safely parse a PaymentRequired response, returning a result object.\n *\n * @param data - The data to parse\n * @returns The safe parse result\n */\nexport function safeParsePaymentRequired(\n data: unknown,\n): z.SafeParseReturnType<unknown, ValidatedPaymentRequired> {\n return PaymentRequiredSchema.safeParse(data);\n}\n\n/**\n * Safely parse PaymentRequirements, returning a result object.\n *\n * @param data - The data to parse\n * @returns The safe parse result\n */\nexport function safeParsePaymentRequirements(\n data: unknown,\n): z.SafeParseReturnType<unknown, ValidatedPaymentRequirements> {\n return PaymentRequirementsSchema.safeParse(data);\n}\n","import { SettleResponse } from \"../types\";\nimport { PaymentPayload, PaymentRequired, PaymentRequirements } from \"../types/payments\";\nimport {\n PaymentPayloadSchema,\n PaymentRequiredSchema,\n SettleResponseSchema,\n} from \"../types/schemas\";\nimport { Base64EncodedRegex, safeBase64Decode, safeBase64Encode } from \"../utils\";\n\n// HTTP Methods that typically use query parameters\nexport type QueryParamMethods = \"GET\" | \"HEAD\" | \"DELETE\";\n\n// HTTP Methods that typically use request body\nexport type BodyMethods = \"POST\" | \"PUT\" | \"PATCH\";\n\n/**\n * Encodes a payment payload as a base64 header value.\n *\n * @param paymentPayload - The payment payload to encode\n * @returns Base64 encoded string representation of the payment payload\n */\nexport function encodePaymentSignatureHeader(paymentPayload: PaymentPayload): string {\n return safeBase64Encode(JSON.stringify(paymentPayload));\n}\n\n/**\n * Decodes a base64 payment signature header into a payment payload.\n * Validates the payload structure using Zod schema.\n *\n * @param paymentSignatureHeader - The base64 encoded payment signature header\n * @returns The decoded and validated payment payload\n * @throws Error if the header is invalid or fails schema validation\n */\nexport function decodePaymentSignatureHeader(paymentSignatureHeader: string): PaymentPayload {\n if (!Base64EncodedRegex.test(paymentSignatureHeader)) {\n throw new Error(\"Invalid payment signature header\");\n }\n const parsed = JSON.parse(safeBase64Decode(paymentSignatureHeader));\n // Validate structure with Zod, then cast to TypeScript type\n // (Zod validates the structure; TypeScript types add template literal constraints)\n PaymentPayloadSchema.parse(parsed);\n return parsed as PaymentPayload;\n}\n\n/**\n * Encodes a payment required object as a base64 header value.\n *\n * @param paymentRequired - The payment required object to encode\n * @returns Base64 encoded string representation of the payment required object\n */\nexport function encodePaymentRequiredHeader(paymentRequired: PaymentRequired): string {\n return safeBase64Encode(JSON.stringify(paymentRequired));\n}\n\n/**\n * Decodes a base64 payment required header into a payment required object.\n * Validates the structure using Zod schema.\n *\n * @param paymentRequiredHeader - The base64 encoded payment required header\n * @returns The decoded and validated payment required object\n * @throws Error if the header is invalid or fails schema validation\n */\nexport function decodePaymentRequiredHeader(paymentRequiredHeader: string): PaymentRequired {\n if (!Base64EncodedRegex.test(paymentRequiredHeader)) {\n throw new Error(\"Invalid payment required header\");\n }\n const parsed = JSON.parse(safeBase64Decode(paymentRequiredHeader));\n // Validate structure with Zod, then cast to TypeScript type\n PaymentRequiredSchema.parse(parsed);\n return parsed as PaymentRequired;\n}\n\n/**\n * Encodes a payment response as a base64 header value.\n *\n * @param paymentResponse - The payment response to encode\n * @returns Base64 encoded string representation of the payment response\n */\nexport function encodePaymentResponseHeader(\n paymentResponse: SettleResponse & { requirements: PaymentRequirements },\n): string {\n return safeBase64Encode(JSON.stringify(paymentResponse));\n}\n\n/**\n * Decodes a base64 payment response header into a settle response.\n * Validates the structure using Zod schema.\n *\n * @param paymentResponseHeader - The base64 encoded payment response header\n * @returns The decoded and validated settle response\n * @throws Error if the header is invalid or fails schema validation\n */\nexport function decodePaymentResponseHeader(paymentResponseHeader: string): SettleResponse {\n if (!Base64EncodedRegex.test(paymentResponseHeader)) {\n throw new Error(\"Invalid payment response header\");\n }\n const parsed = JSON.parse(safeBase64Decode(paymentResponseHeader));\n // Validate structure with Zod, then cast to TypeScript type\n SettleResponseSchema.parse(parsed);\n return parsed as SettleResponse;\n}\n\n// Export HTTP service classes (values)\nexport { t402HTTPResourceServer, RouteConfigurationError } from \"./t402HTTPResourceServer\";\nexport { HTTPFacilitatorClient } from \"./httpFacilitatorClient\";\nexport { t402HTTPClient } from \"./t402HTTPClient\";\nexport { StreamingClient } from \"./streamingClient\";\nexport { IntentClient } from \"./intentClient\";\n\n// Export HTTP types (type-only exports for isolatedModules compatibility)\nexport type {\n HTTPAdapter,\n HTTPRequestContext,\n HTTPResponseInstructions,\n HTTPProcessResult,\n PaywallConfig,\n PaywallProvider,\n PaymentOption,\n RouteConfig,\n RoutesConfig,\n CompiledRoute,\n DynamicPayTo,\n DynamicPrice,\n UnpaidResponseBody,\n UnpaidResponseResult,\n ProcessSettleResultResponse,\n ProcessSettleSuccessResponse,\n ProcessSettleFailureResponse,\n RouteValidationError,\n} from \"./t402HTTPResourceServer\";\nexport type { FacilitatorClient, FacilitatorConfig, SettleOptions } from \"./httpFacilitatorClient\";\n\n// Streaming types\nexport type {\n StreamStatus,\n StreamMetadata,\n Stream,\n StreamUpdate,\n StreamStats,\n OpenStreamRequest,\n UpdateStreamRequest,\n CloseStreamRequest,\n ListStreamsParams,\n OpenStreamResponse,\n UpdateStreamResponse,\n CloseStreamResponse,\n GetStreamResponse,\n ListStreamsResponse,\n PauseResumeResponse,\n StreamingClientConfig,\n} from \"./streamingClient\";\n\n// Intent types\nexport type {\n IntentStatus,\n IntentPriority,\n RouteStepType,\n RouteStep,\n Route,\n Intent,\n CreateIntentRequest,\n SelectRouteRequest,\n ExecuteIntentRequest,\n CancelIntentRequest,\n ListIntentsParams,\n CreateIntentResponse,\n SelectRouteResponse,\n ExecuteIntentResponse,\n GetIntentResponse,\n ListIntentsResponse,\n CancelIntentResponse,\n RefreshRoutesResponse,\n IntentStats,\n IntentClientConfig,\n} from \"./intentClient\";\n","import { t402ResourceServer } from \"../server\";\nimport {\n decodePaymentSignatureHeader,\n encodePaymentRequiredHeader,\n encodePaymentResponseHeader,\n} from \".\";\nimport {\n PaymentPayload,\n PaymentRequired,\n SettleResponse,\n Price,\n Network,\n PaymentRequirements,\n} from \"../types\";\nimport { t402Version } from \"..\";\n\n/**\n * Framework-agnostic HTTP adapter interface\n * Implementations provide framework-specific HTTP operations\n */\nexport interface HTTPAdapter {\n getHeader(name: string): string | undefined;\n getMethod(): string;\n getPath(): string;\n getUrl(): string;\n getAcceptHeader(): string;\n getUserAgent(): string;\n\n /**\n * Get query parameters from the request URL\n *\n * @returns Record of query parameter key-value pairs\n */\n getQueryParams?(): Record<string, string | string[]>;\n\n /**\n * Get a specific query parameter by name\n *\n * @param name - The query parameter name\n * @returns The query parameter value(s) or undefined\n */\n getQueryParam?(name: string): string | string[] | undefined;\n\n /**\n * Get the parsed request body\n * Framework adapters should parse JSON/form data appropriately\n *\n * @returns The parsed request body\n */\n getBody?(): unknown;\n}\n\n/**\n * Paywall configuration for HTML responses\n */\nexport interface PaywallConfig {\n appName?: string;\n appLogo?: string;\n sessionTokenEndpoint?: string;\n currentUrl?: string;\n testnet?: boolean;\n}\n\n/**\n * Paywall provider interface for generating HTML\n */\nexport interface PaywallProvider {\n generateHtml(paymentRequired: PaymentRequired, config?: PaywallConfig): string;\n}\n\n/**\n * Dynamic payTo function that receives HTTP request context\n */\nexport type DynamicPayTo = (context: HTTPRequestContext) => string | Promise<string>;\n\n/**\n * Dynamic price function that receives HTTP request context\n */\nexport type DynamicPrice = (context: HTTPRequestContext) => Price | Promise<Price>;\n\n/**\n * Result of the unpaid response callback containing content type and body.\n */\nexport interface UnpaidResponseResult {\n /**\n * The content type for the response (e.g., 'application/json', 'text/plain').\n */\n contentType: string;\n\n /**\n * The response body to include in the 402 response.\n */\n body: unknown;\n}\n\n/**\n * Dynamic function to generate a custom response for unpaid requests.\n * Receives the HTTP request context and returns the content type and body to include in the 402 response.\n */\nexport type UnpaidResponseBody = (\n context: HTTPRequestContext,\n) => UnpaidResponseResult | Promise<UnpaidResponseResult>;\n\n/**\n * A single payment option for a route\n * Represents one way a client can pay for access to the resource\n */\nexport interface PaymentOption {\n scheme: string;\n payTo: string | DynamicPayTo;\n price: Price | DynamicPrice;\n network: Network;\n maxTimeoutSeconds?: number;\n extra?: Record<string, unknown>;\n}\n\n/**\n * Route configuration for HTTP endpoints\n *\n * The 'accepts' field defines payment options for the route.\n * Can be a single PaymentOption or an array of PaymentOptions for multiple payment methods.\n */\nexport interface RouteConfig {\n // Payment option(s): single or array\n accepts: PaymentOption | PaymentOption[];\n\n // HTTP-specific metadata\n resource?: string;\n description?: string;\n mimeType?: string;\n customPaywallHtml?: string;\n\n /**\n * Optional callback to generate a custom response for unpaid API requests.\n * This allows servers to return preview data, error messages, or other content\n * when a request lacks payment.\n *\n * For browser requests (Accept: text/html), the paywall HTML takes precedence.\n * This callback is only used for API clients.\n *\n * If not provided, defaults to { contentType: 'application/json', body: {} }.\n *\n * @returns An object containing both contentType and body for the 402 response\n */\n unpaidResponseBody?: UnpaidResponseBody;\n\n // Extensions\n extensions?: Record<string, unknown>;\n}\n\n/**\n * Routes configuration - maps path patterns to route configs\n */\nexport type RoutesConfig = Record<string, RouteConfig> | RouteConfig;\n\n/**\n * Compiled route for efficient matching\n */\nexport interface CompiledRoute {\n verb: string;\n regex: RegExp;\n config: RouteConfig;\n}\n\n/**\n * HTTP request context that encapsulates all request data\n */\nexport interface HTTPRequestContext {\n adapter: HTTPAdapter;\n path: string;\n method: string;\n paymentHeader?: string;\n}\n\n/**\n * HTTP response instructions for the framework middleware\n */\nexport interface HTTPResponseInstructions {\n status: number;\n headers: Record<string, string>;\n body?: unknown; // e.g. Paywall for web browser requests, but could be any other type\n isHtml?: boolean; // e.g. if body is a paywall, then isHtml is true\n}\n\n/**\n * Result of processing an HTTP request for payment\n */\nexport type HTTPProcessResult =\n | { type: \"no-payment-required\" }\n | {\n type: \"payment-verified\";\n paymentPayload: PaymentPayload;\n paymentRequirements: PaymentRequirements;\n }\n | { type: \"payment-error\"; response: HTTPResponseInstructions };\n\n/**\n * Result of processSettlement\n */\nexport type ProcessSettleSuccessResponse = SettleResponse & {\n success: true;\n headers: Record<string, string>;\n requirements: PaymentRequirements;\n};\n\nexport type ProcessSettleFailureResponse = SettleResponse & {\n success: false;\n errorReason: string;\n};\n\nexport type ProcessSettleResultResponse =\n | ProcessSettleSuccessResponse\n | ProcessSettleFailureResponse;\n\n/**\n * Represents a validation error for a specific route's payment configuration.\n */\nexport interface RouteValidationError {\n /** The route pattern (e.g., \"GET /api/weather\") */\n routePattern: string;\n /** The payment scheme that failed validation */\n scheme: string;\n /** The network that failed validation */\n network: Network;\n /** The type of validation failure */\n reason: \"missing_scheme\" | \"missing_facilitator\";\n /** Human-readable error message */\n message: string;\n}\n\n/**\n * Error thrown when route configuration validation fails.\n */\nexport class RouteConfigurationError extends Error {\n /** The validation errors that caused this exception */\n public readonly errors: RouteValidationError[];\n\n /**\n * Creates a new RouteConfigurationError with the given validation errors.\n *\n * @param errors - The validation errors that caused this exception.\n */\n constructor(errors: RouteValidationError[]) {\n const message = `t402 Route Configuration Errors:\\n${errors.map(e => ` - ${e.message}`).join(\"\\n\")}`;\n super(message);\n this.name = \"RouteConfigurationError\";\n this.errors = errors;\n }\n}\n\n/**\n * HTTP-enhanced t402 resource server\n * Provides framework-agnostic HTTP protocol handling\n */\nexport class t402HTTPResourceServer {\n private ResourceServer: t402ResourceServer;\n private compiledRoutes: CompiledRoute[] = [];\n private routesConfig: RoutesConfig;\n private paywallProvider?: PaywallProvider;\n\n /**\n * Creates a new t402HTTPResourceServer instance.\n *\n * @param ResourceServer - The core t402ResourceServer instance to use\n * @param routes - Route configuration for payment-protected endpoints\n */\n constructor(ResourceServer: t402ResourceServer, routes: RoutesConfig) {\n this.ResourceServer = ResourceServer;\n this.routesConfig = routes;\n\n // Handle both single route and multiple routes\n const normalizedRoutes =\n typeof routes === \"object\" && !(\"accepts\" in routes)\n ? (routes as Record<string, RouteConfig>)\n : { \"*\": routes as RouteConfig };\n\n for (const [pattern, config] of Object.entries(normalizedRoutes)) {\n const parsed = this.parseRoutePattern(pattern);\n this.compiledRoutes.push({\n verb: parsed.verb,\n regex: parsed.regex,\n config,\n });\n }\n }\n\n /**\n * Initialize the HTTP resource server.\n *\n * This method initializes the underlying resource server (fetching facilitator support)\n * and then validates that all route payment configurations have corresponding\n * registered schemes and facilitator support.\n *\n * @throws RouteConfigurationError if any route's payment options don't have\n * corresponding registered schemes or facilitator support\n *\n * @example\n * ```typescript\n * const httpServer = new t402HTTPResourceServer(server, routes);\n * await httpServer.initialize();\n * ```\n */\n async initialize(): Promise<void> {\n // First, initialize the underlying resource server (fetches facilitator support)\n await this.ResourceServer.initialize();\n\n // Then validate route configuration\n const errors = this.validateRouteConfiguration();\n if (errors.length > 0) {\n throw new RouteConfigurationError(errors);\n }\n }\n\n /**\n * Register a custom paywall provider for generating HTML\n *\n * @param provider - PaywallProvider instance\n * @returns This service instance for chaining\n */\n registerPaywallProvider(provider: PaywallProvider): this {\n this.paywallProvider = provider;\n return this;\n }\n\n /**\n * Process HTTP request and return response instructions\n * This is the main entry point for framework middleware\n *\n * @param context - HTTP request context\n * @param paywallConfig - Optional paywall configuration\n * @returns Process result indicating next action for middleware\n */\n async processHTTPRequest(\n context: HTTPRequestContext,\n paywallConfig?: PaywallConfig,\n ): Promise<HTTPProcessResult> {\n const { adapter, path, method } = context;\n\n // Find matching route\n const routeConfig = this.getRouteConfig(path, method);\n if (!routeConfig) {\n return { type: \"no-payment-required\" }; // No payment required for this route\n }\n\n // Normalize accepts field to array of payment options\n const paymentOptions = this.normalizePaymentOptions(routeConfig);\n\n // Check for payment header (v1 or v2)\n const paymentPayload = this.extractPayment(adapter);\n\n // Create resource info, using config override if provided\n const resourceInfo = {\n url: routeConfig.resource || context.adapter.getUrl(),\n description: routeConfig.description || \"\",\n mimeType: routeConfig.mimeType || \"\",\n };\n\n // Build requirements from all payment options\n // (this method handles resolving dynamic functions internally)\n const requirements = await this.ResourceServer.buildPaymentRequirementsFromOptions(\n paymentOptions,\n context,\n );\n\n let extensions = routeConfig.extensions;\n if (extensions) {\n extensions = this.ResourceServer.enrichExtensions(extensions, context);\n }\n\n const paymentRequired = this.ResourceServer.createPaymentRequiredResponse(\n requirements,\n resourceInfo,\n !paymentPayload ? \"Payment required\" : undefined,\n extensions,\n );\n\n // If no payment provided\n if (!paymentPayload) {\n // Resolve custom unpaid response body if provided\n const unpaidBody = routeConfig.unpaidResponseBody\n ? await routeConfig.unpaidResponseBody(context)\n : undefined;\n\n return {\n type: \"payment-error\",\n response: this.createHTTPResponse(\n paymentRequired,\n this.isWebBrowser(adapter),\n paywallConfig,\n routeConfig.customPaywallHtml,\n unpaidBody,\n ),\n };\n }\n\n // Verify payment\n try {\n const matchingRequirements = this.ResourceServer.findMatchingRequirements(\n paymentRequired.accepts,\n paymentPayload,\n );\n\n if (!matchingRequirements) {\n const errorResponse = this.ResourceServer.createPaymentRequiredResponse(\n requirements,\n resourceInfo,\n \"No matching payment requirements\",\n routeConfig.extensions,\n );\n return {\n type: \"payment-error\",\n response: this.createHTTPResponse(errorResponse, false, paywallConfig),\n };\n }\n\n const verifyResult = await this.ResourceServer.verifyPayment(\n paymentPayload,\n matchingRequirements,\n );\n\n if (!verifyResult.isValid) {\n const errorResponse = this.ResourceServer.createPaymentRequiredResponse(\n requirements,\n resourceInfo,\n verifyResult.invalidReason,\n routeConfig.extensions,\n );\n return {\n type: \"payment-error\",\n response: this.createHTTPResponse(errorResponse, false, paywallConfig),\n };\n }\n\n // Payment is valid, return data needed for settlement\n return {\n type: \"payment-verified\",\n paymentPayload,\n paymentRequirements: matchingRequirements,\n };\n } catch (error) {\n const errorResponse = this.ResourceServer.createPaymentRequiredResponse(\n requirements,\n resourceInfo,\n error instanceof Error ? error.message : \"Payment verification failed\",\n routeConfig.extensions,\n );\n return {\n type: \"payment-error\",\n response: this.createHTTPResponse(errorResponse, false, paywallConfig),\n };\n }\n }\n\n /**\n * Process settlement after successful response\n *\n * @param paymentPayload - The verified payment payload\n * @param requirements - The matching payment requirements\n * @returns ProcessSettleResultResponse - SettleResponse with headers if success or errorReason if failure\n */\n async processSettlement(\n paymentPayload: PaymentPayload,\n requirements: PaymentRequirements,\n ): Promise<ProcessSettleResultResponse> {\n try {\n const settleResponse = await this.ResourceServer.settlePayment(paymentPayload, requirements);\n\n if (!settleResponse.success) {\n return {\n ...settleResponse,\n success: false,\n errorReason: settleResponse.errorReason || \"Settlement failed\",\n };\n }\n\n return {\n ...settleResponse,\n success: true,\n headers: this.createSettlementHeaders(settleResponse, requirements),\n requirements,\n };\n } catch (error) {\n throw new Error(error instanceof Error ? error.message : \"Settlement failed\");\n }\n }\n\n /**\n * Check if a request requires payment based on route configuration\n *\n * @param context - HTTP request context\n * @returns True if the route requires payment, false otherwise\n */\n requiresPayment(context: HTTPRequestContext): boolean {\n const routeConfig = this.getRouteConfig(context.path, context.method);\n return routeConfig !== undefined;\n }\n\n /**\n * Normalizes a RouteConfig's accepts field into an array of PaymentOptions\n * Handles both single PaymentOption and array formats\n *\n * @param routeConfig - Route configuration\n * @returns Array of payment options\n */\n private normalizePaymentOptions(routeConfig: RouteConfig): PaymentOption[] {\n return Array.isArray(routeConfig.accepts) ? routeConfig.accepts : [routeConfig.accepts];\n }\n\n /**\n * Validates that all payment options in routes have corresponding registered schemes\n * and facilitator support.\n *\n * @returns Array of validation errors (empty if all routes are valid)\n */\n private validateRouteConfiguration(): RouteValidationError[] {\n const errors: RouteValidationError[] = [];\n\n // Normalize routes to array of [pattern, config] pairs\n const normalizedRoutes =\n typeof this.routesConfig === \"object\" && !(\"accepts\" in this.routesConfig)\n ? Object.entries(this.routesConfig as Record<string, RouteConfig>)\n : [[\"*\", this.routesConfig as RouteConfig] as [string, RouteConfig]];\n\n for (const [pattern, config] of normalizedRoutes) {\n const paymentOptions = this.normalizePaymentOptions(config);\n\n for (const option of paymentOptions) {\n // Check 1: Is scheme registered?\n if (!this.ResourceServer.hasRegisteredScheme(option.network, option.scheme)) {\n errors.push({\n routePattern: pattern,\n scheme: option.scheme,\n network: option.network,\n reason: \"missing_scheme\",\n message: `Route \"${pattern}\": No scheme implementation registered for \"${option.scheme}\" on network \"${option.network}\"`,\n });\n // Skip facilitator check if scheme isn't registered\n continue;\n }\n\n // Check 2: Does facilitator support this scheme/network combination?\n const supportedKind = this.ResourceServer.getSupportedKind(\n t402Version,\n option.network,\n option.scheme,\n );\n\n if (!supportedKind) {\n errors.push({\n routePattern: pattern,\n scheme: option.scheme,\n network: option.network,\n reason: \"missing_facilitator\",\n message: `Route \"${pattern}\": Facilitator does not support scheme \"${option.scheme}\" on network \"${option.network}\"`,\n });\n }\n }\n }\n\n return errors;\n }\n\n /**\n * Get route configuration for a request\n *\n * @param path - Request path\n * @param method - HTTP method\n * @returns Route configuration or undefined if no match\n */\n private getRouteConfig(path: string, method: string): RouteConfig | undefined {\n const normalizedPath = this.normalizePath(path);\n const upperMethod = method.toUpperCase();\n\n const matchingRoute = this.compiledRoutes.find(\n route =>\n route.regex.test(normalizedPath) && (route.verb === \"*\" || route.verb === upperMethod),\n );\n\n return matchingRoute?.config;\n }\n\n /**\n * Extract payment from HTTP headers (handles v1 and v2)\n *\n * @param adapter - HTTP adapter\n * @returns Decoded payment payload or null\n */\n private extractPayment(adapter: HTTPAdapter): PaymentPayload | null {\n // Check v2 header first (PAYMENT-SIGNATURE), then v1 fallback (X-PAYMENT)\n const header =\n adapter.getHeader(\"payment-signature\") ||\n adapter.getHeader(\"PAYMENT-SIGNATURE\") ||\n adapter.getHeader(\"x-payment\") ||\n adapter.getHeader(\"X-PAYMENT\");\n\n if (header) {\n try {\n return decodePaymentSignatureHeader(header);\n } catch (error) {\n console.warn(\"Failed to decode payment header:\", error);\n }\n }\n\n return null;\n }\n\n /**\n * Check if request is from a web browser\n *\n * @param adapter - HTTP adapter\n * @returns True if request appears to be from a browser\n */\n private isWebBrowser(adapter: HTTPAdapter): boolean {\n const accept = adapter.getAcceptHeader();\n const userAgent = adapter.getUserAgent();\n return accept.includes(\"text/html\") && userAgent.includes(\"Mozilla\");\n }\n\n /**\n * Create HTTP response instructions from payment required\n *\n * @param paymentRequired - Payment requirements\n * @param isWebBrowser - Whether request is from browser\n * @param paywallConfig - Paywall configuration\n * @param customHtml - Custom HTML template\n * @param unpaidResponse - Optional custom response (content type and body) for unpaid API requests\n * @returns Response instructions\n */\n private createHTTPResponse(\n paymentRequired: PaymentRequired,\n isWebBrowser: boolean,\n paywallConfig?: PaywallConfig,\n customHtml?: string,\n unpaidResponse?: UnpaidResponseResult,\n ): HTTPResponseInstructions {\n if (isWebBrowser) {\n const html = this.generatePaywallHTML(paymentRequired, paywallConfig, customHtml);\n return {\n status: 402,\n headers: { \"Content-Type\": \"text/html\" },\n body: html,\n isHtml: true,\n };\n }\n\n const response = this.createHTTPPaymentRequiredResponse(paymentRequired);\n\n // Use callback result if provided, otherwise default to JSON with empty object\n const contentType = unpaidResponse ? unpaidResponse.contentType : \"application/json\";\n const body = unpaidResponse ? unpaidResponse.body : {};\n\n return {\n status: 402,\n headers: {\n \"Content-Type\": contentType,\n ...response.headers,\n },\n body,\n };\n }\n\n /**\n * Create HTTP payment required response (v1 puts in body, v2 puts in header)\n *\n * @param paymentRequired - Payment required object\n * @returns Headers and body for the HTTP response\n */\n private createHTTPPaymentRequiredResponse(paymentRequired: PaymentRequired): {\n headers: Record<string, string>;\n } {\n return {\n headers: {\n \"PAYMENT-REQUIRED\": encodePaymentRequiredHeader(paymentRequired),\n },\n };\n }\n\n /**\n * Create settlement response headers\n *\n * @param settleResponse - Settlement response\n * @param requirements - Payment requirements that were settled\n * @returns Headers to add to response\n */\n private createSettlementHeaders(\n settleResponse: SettleResponse,\n requirements: PaymentRequirements,\n ): Record<string, string> {\n const encoded = encodePaymentResponseHeader({\n ...settleResponse,\n requirements,\n });\n return { \"PAYMENT-RESPONSE\": encoded };\n }\n\n /**\n * Parse route pattern into verb and regex\n *\n * @param pattern - Route pattern like \"GET /api/*\" or \"/api/[id]\"\n * @returns Parsed pattern with verb and regex\n */\n private parseRoutePattern(pattern: string): { verb: string; regex: RegExp } {\n const [verb, path] = pattern.includes(\" \") ? pattern.split(/\\s+/) : [\"*\", pattern];\n\n const regex = new RegExp(\n `^${\n path\n .replace(/[$()+.?^{|}]/g, \"\\\\$&\") // Escape regex special chars\n .replace(/\\*/g, \".*?\") // Wildcards\n .replace(/\\[([^\\]]+)\\]/g, \"[^/]+\") // Parameters\n .replace(/\\//g, \"\\\\/\") // Escape slashes\n }$`,\n \"i\",\n );\n\n return { verb: verb.toUpperCase(), regex };\n }\n\n /**\n * Normalize path for matching\n *\n * @param path - Raw path from request\n * @returns Normalized path\n */\n private normalizePath(path: string): string {\n try {\n const pathWithoutQuery = path.split(/[?#]/)[0];\n const decodedPath = decodeURIComponent(pathWithoutQuery);\n return decodedPath\n .replace(/\\\\/g, \"/\")\n .replace(/\\/+/g, \"/\")\n .replace(/(.+?)\\/+$/, \"$1\");\n } catch {\n return path;\n }\n }\n\n /**\n * Generate paywall HTML for browser requests\n *\n * @param paymentRequired - Payment required response\n * @param paywallConfig - Optional paywall configuration\n * @param customHtml - Optional custom HTML template\n * @returns HTML string\n */\n private generatePaywallHTML(\n paymentRequired: PaymentRequired,\n paywallConfig?: PaywallConfig,\n customHtml?: string,\n ): string {\n if (customHtml) {\n return customHtml;\n }\n\n // Use custom paywall provider if set\n if (this.paywallProvider) {\n return this.paywallProvider.generateHtml(paymentRequired, paywallConfig);\n }\n\n // Try to use @t402/paywall if available (optional dependency)\n try {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const paywall = require(\"@t402/paywall\");\n const displayAmount = this.getDisplayAmount(paymentRequired);\n const resource = paymentRequired.resource;\n\n return paywall.getPaywallHtml({\n amount: displayAmount,\n paymentRequired,\n currentUrl: resource?.url || paywallConfig?.currentUrl || \"\",\n testnet: paywallConfig?.testnet ?? true,\n appName: paywallConfig?.appName,\n appLogo: paywallConfig?.appLogo,\n sessionTokenEndpoint: paywallConfig?.sessionTokenEndpoint,\n });\n } catch {\n // @t402/paywall not installed, fall back to basic HTML\n }\n\n // Fallback: Basic HTML paywall\n const resource = paymentRequired.resource;\n const displayAmount = this.getDisplayAmount(paymentRequired);\n\n return `\n <!DOCTYPE html>\n <html>\n <head>\n <title>Payment Required</title>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n </head>\n <body>\n <div style=\"max-width: 600px; margin: 50px auto; padding: 20px; font-family: system-ui, -apple-system, sans-serif;\">\n ${paywallConfig?.appLogo ? `<img src=\"${paywallConfig.appLogo}\" alt=\"${paywallConfig.appName || \"App\"}\" style=\"max-width: 200px; margin-bottom: 20px;\">` : \"\"}\n <h1>Payment Required</h1>\n ${resource ? `<p><strong>Resource:</strong> ${resource.description || resource.url}</p>` : \"\"}\n <p><strong>Amount:</strong> $${displayAmount.toFixed(2)} USDC</p>\n <div id=\"payment-widget\" \n data-requirements='${JSON.stringify(paymentRequired)}'\n data-app-name=\"${paywallConfig?.appName || \"\"}\"\n data-testnet=\"${paywallConfig?.testnet || false}\">\n <!-- Install @t402/paywall for full wallet integration -->\n <p style=\"margin-top: 2rem; padding: 1rem; background: #fef3c7; border-radius: 0.5rem;\">\n <strong>Note:</strong> Install <code>@t402/paywall</code> for full wallet connection and payment UI.\n </p>\n </div>\n </div>\n </body>\n </html>\n `;\n }\n\n /**\n * Extract display amount from payment requirements.\n *\n * @param paymentRequired - The payment required object\n * @returns The display amount in decimal format\n */\n private getDisplayAmount(paymentRequired: PaymentRequired): number {\n const accepts = paymentRequired.accepts;\n if (accepts && accepts.length > 0) {\n const firstReq = accepts[0];\n if (\"amount\" in firstReq) {\n // V2 format\n return parseFloat(firstReq.amount) / 1000000; // Assuming USDC with 6 decimals\n }\n }\n return 0;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;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I;AAAA,MACvC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":["t402Version","displayAmount","resource"]}
|
package/dist/cjs/{t402HTTPResourceServer-BIEvnbwL.d.ts → t402HTTPResourceServer-4RFYtBnw.d.ts}
RENAMED
|
@@ -721,4 +721,4 @@ declare class t402HTTPResourceServer {
|
|
|
721
721
|
private getDisplayAmount;
|
|
722
722
|
}
|
|
723
723
|
|
|
724
|
-
export { type CompiledRoute as C, type DynamicPayTo as D, type FacilitatorClient as F, type HTTPAdapter as H, type PaymentOption as P, type RouteConfig as R, type SettleOptions as S, type UnpaidResponseBody as U, type DynamicPrice as a, type FacilitatorConfig as b, HTTPFacilitatorClient as c, type HTTPProcessResult as d, type HTTPRequestContext as e, type HTTPResponseInstructions as f, type PaywallConfig as g, type PaywallProvider as h, type ProcessSettleFailureResponse as i, type ProcessSettleResultResponse as j, type ProcessSettleSuccessResponse as k, RouteConfigurationError as l, type RouteValidationError as m, type RoutesConfig as n, type UnpaidResponseResult as o, type
|
|
724
|
+
export { type AfterSettleHook as A, type BeforeSettleHook as B, type CompiledRoute as C, type DynamicPayTo as D, t402ResourceServer as E, type FacilitatorClient as F, type HTTPAdapter as H, type OnSettleFailureHook as O, type PaymentOption as P, type RouteConfig as R, type SettleOptions as S, type UnpaidResponseBody as U, type VerifyContext as V, type DynamicPrice as a, type FacilitatorConfig as b, HTTPFacilitatorClient as c, type HTTPProcessResult as d, type HTTPRequestContext as e, type HTTPResponseInstructions as f, type PaywallConfig as g, type PaywallProvider as h, type ProcessSettleFailureResponse as i, type ProcessSettleResultResponse as j, type ProcessSettleSuccessResponse as k, RouteConfigurationError as l, type RouteValidationError as m, type RoutesConfig as n, type UnpaidResponseResult as o, type AfterVerifyHook as p, type BeforeVerifyHook as q, type OnVerifyFailureHook as r, type ResourceConfig as s, t402HTTPResourceServer as t, type ResourceInfo as u, type SettleContext as v, type SettleFailureContext as w, type SettleResultContext as x, type VerifyFailureContext as y, type VerifyResultContext as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as PaymentRequired, S as SettleResponse, a as PaymentPayload, P as PaymentRequirements } from '../mechanisms-dYCiYgko.mjs';
|
|
2
|
-
export { C as CompiledRoute, D as DynamicPayTo, a as DynamicPrice, F as FacilitatorClient, b as FacilitatorConfig, H as HTTPAdapter, c as HTTPFacilitatorClient, d as HTTPProcessResult, e as HTTPRequestContext, f as HTTPResponseInstructions, P as PaymentOption, g as PaywallConfig, h as PaywallProvider, i as ProcessSettleFailureResponse, j as ProcessSettleResultResponse, k as ProcessSettleSuccessResponse, R as RouteConfig, l as RouteConfigurationError, m as RouteValidationError, n as RoutesConfig, S as SettleOptions, U as UnpaidResponseBody, o as UnpaidResponseResult, t as t402HTTPResourceServer } from '../t402HTTPResourceServer-
|
|
2
|
+
export { C as CompiledRoute, D as DynamicPayTo, a as DynamicPrice, F as FacilitatorClient, b as FacilitatorConfig, H as HTTPAdapter, c as HTTPFacilitatorClient, d as HTTPProcessResult, e as HTTPRequestContext, f as HTTPResponseInstructions, P as PaymentOption, g as PaywallConfig, h as PaywallProvider, i as ProcessSettleFailureResponse, j as ProcessSettleResultResponse, k as ProcessSettleSuccessResponse, R as RouteConfig, l as RouteConfigurationError, m as RouteValidationError, n as RoutesConfig, S as SettleOptions, U as UnpaidResponseBody, o as UnpaidResponseResult, t as t402HTTPResourceServer } from '../t402HTTPResourceServer-CaF4mNy6.mjs';
|
|
3
3
|
export { f as t402HTTPClient } from '../t402HTTPClient-DbIXpGXL.mjs';
|
|
4
4
|
import 'zod';
|
|
5
5
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { C as CompiledRoute, F as FacilitatorClient, b as FacilitatorConfig, H as HTTPAdapter, c as HTTPFacilitatorClient, d as HTTPProcessResult, e as HTTPRequestContext, f as HTTPResponseInstructions, g as PaywallConfig, h as PaywallProvider, i as ProcessSettleFailureResponse, j as ProcessSettleResultResponse, k as ProcessSettleSuccessResponse,
|
|
1
|
+
export { A as AfterSettleHook, p as AfterVerifyHook, B as BeforeSettleHook, q as BeforeVerifyHook, C as CompiledRoute, F as FacilitatorClient, b as FacilitatorConfig, H as HTTPAdapter, c as HTTPFacilitatorClient, d as HTTPProcessResult, e as HTTPRequestContext, f as HTTPResponseInstructions, O as OnSettleFailureHook, r as OnVerifyFailureHook, g as PaywallConfig, h as PaywallProvider, i as ProcessSettleFailureResponse, j as ProcessSettleResultResponse, k as ProcessSettleSuccessResponse, s as ResourceConfig, u as ResourceInfo, R as RouteConfig, l as RouteConfigurationError, m as RouteValidationError, n as RoutesConfig, v as SettleContext, w as SettleFailureContext, S as SettleOptions, x as SettleResultContext, U as UnpaidResponseBody, o as UnpaidResponseResult, V as VerifyContext, y as VerifyFailureContext, z as VerifyResultContext, t as t402HTTPResourceServer, E as t402ResourceServer } from '../t402HTTPResourceServer-CaF4mNy6.mjs';
|
|
2
2
|
import '../mechanisms-dYCiYgko.mjs';
|
|
3
3
|
import 'zod';
|
package/dist/esm/{t402HTTPResourceServer-Jmmvy9kc.d.mts → t402HTTPResourceServer-CaF4mNy6.d.mts}
RENAMED
|
@@ -721,4 +721,4 @@ declare class t402HTTPResourceServer {
|
|
|
721
721
|
private getDisplayAmount;
|
|
722
722
|
}
|
|
723
723
|
|
|
724
|
-
export { type CompiledRoute as C, type DynamicPayTo as D, type FacilitatorClient as F, type HTTPAdapter as H, type PaymentOption as P, type RouteConfig as R, type SettleOptions as S, type UnpaidResponseBody as U, type DynamicPrice as a, type FacilitatorConfig as b, HTTPFacilitatorClient as c, type HTTPProcessResult as d, type HTTPRequestContext as e, type HTTPResponseInstructions as f, type PaywallConfig as g, type PaywallProvider as h, type ProcessSettleFailureResponse as i, type ProcessSettleResultResponse as j, type ProcessSettleSuccessResponse as k, RouteConfigurationError as l, type RouteValidationError as m, type RoutesConfig as n, type UnpaidResponseResult as o, type
|
|
724
|
+
export { type AfterSettleHook as A, type BeforeSettleHook as B, type CompiledRoute as C, type DynamicPayTo as D, t402ResourceServer as E, type FacilitatorClient as F, type HTTPAdapter as H, type OnSettleFailureHook as O, type PaymentOption as P, type RouteConfig as R, type SettleOptions as S, type UnpaidResponseBody as U, type VerifyContext as V, type DynamicPrice as a, type FacilitatorConfig as b, HTTPFacilitatorClient as c, type HTTPProcessResult as d, type HTTPRequestContext as e, type HTTPResponseInstructions as f, type PaywallConfig as g, type PaywallProvider as h, type ProcessSettleFailureResponse as i, type ProcessSettleResultResponse as j, type ProcessSettleSuccessResponse as k, RouteConfigurationError as l, type RouteValidationError as m, type RoutesConfig as n, type UnpaidResponseResult as o, type AfterVerifyHook as p, type BeforeVerifyHook as q, type OnVerifyFailureHook as r, type ResourceConfig as s, t402HTTPResourceServer as t, type ResourceInfo as u, type SettleContext as v, type SettleFailureContext as w, type SettleResultContext as x, type VerifyFailureContext as y, type VerifyResultContext as z };
|