x402-express-mantle 1.0.0 → 1.0.3
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/README.md +52 -30
- package/lib/cjs/index.d.ts +119 -81
- package/lib/cjs/index.js +3 -3
- package/lib/esm/index.d.mts +5 -5
- package/lib/esm/index.mjs +3 -3
- package/package.json +17 -5
- package/lib/cjs/client/index.d.ts +0 -243
- package/lib/cjs/client/index.js +0 -413
- package/lib/cjs/client/index.js.map +0 -1
- package/lib/cjs/exact/client/index.d.ts +0 -37
- package/lib/cjs/exact/client/index.js +0 -281
- package/lib/cjs/exact/client/index.js.map +0 -1
- package/lib/cjs/exact/facilitator/index.d.ts +0 -110
- package/lib/cjs/exact/facilitator/index.js +0 -714
- package/lib/cjs/exact/facilitator/index.js.map +0 -1
- package/lib/cjs/exact/server/index.d.ts +0 -87
- package/lib/cjs/exact/server/index.js +0 -209
- package/lib/cjs/exact/server/index.js.map +0 -1
- package/lib/cjs/exact/v1/client/index.d.ts +0 -33
- package/lib/cjs/exact/v1/client/index.js +0 -169
- package/lib/cjs/exact/v1/client/index.js.map +0 -1
- package/lib/cjs/exact/v1/facilitator/index.d.ts +0 -71
- package/lib/cjs/exact/v1/facilitator/index.js +0 -384
- package/lib/cjs/exact/v1/facilitator/index.js.map +0 -1
- package/lib/cjs/facilitator/index.d.ts +0 -192
- package/lib/cjs/facilitator/index.js +0 -398
- package/lib/cjs/facilitator/index.js.map +0 -1
- package/lib/cjs/http/index.d.ts +0 -52
- package/lib/cjs/http/index.js +0 -827
- package/lib/cjs/http/index.js.map +0 -1
- package/lib/cjs/mechanisms-CzuGzYsS.d.ts +0 -270
- package/lib/cjs/scheme-MoBRXFM8.d.ts +0 -29
- package/lib/cjs/server/index.d.ts +0 -2
- package/lib/cjs/server/index.js +0 -1305
- package/lib/cjs/server/index.js.map +0 -1
- package/lib/cjs/signer-5OVDxViv.d.ts +0 -79
- package/lib/cjs/signer-BMkbhFYE.d.ts +0 -123
- package/lib/cjs/types/index.d.ts +0 -1
- package/lib/cjs/types/index.js +0 -66
- package/lib/cjs/types/index.js.map +0 -1
- package/lib/cjs/types/v1/index.d.ts +0 -1
- package/lib/cjs/types/v1/index.js +0 -19
- package/lib/cjs/types/v1/index.js.map +0 -1
- package/lib/cjs/utils/index.d.ts +0 -48
- package/lib/cjs/utils/index.js +0 -116
- package/lib/cjs/utils/index.js.map +0 -1
- package/lib/cjs/v1/index.d.ts +0 -12
- package/lib/cjs/v1/index.js +0 -180
- package/lib/cjs/v1/index.js.map +0 -1
- package/lib/cjs/x402HTTPResourceServer-D1YtlH_r.d.ts +0 -719
- package/lib/esm/chunk-3CEIVWNN.mjs +0 -339
- package/lib/esm/chunk-3CEIVWNN.mjs.map +0 -1
- package/lib/esm/chunk-BJTO5JO5.mjs +0 -11
- package/lib/esm/chunk-BJTO5JO5.mjs.map +0 -1
- package/lib/esm/chunk-EEA7DKZI.mjs +0 -111
- package/lib/esm/chunk-EEA7DKZI.mjs.map +0 -1
- package/lib/esm/chunk-FOUXRQAV.mjs +0 -88
- package/lib/esm/chunk-FOUXRQAV.mjs.map +0 -1
- package/lib/esm/chunk-IKSTWKEM.mjs +0 -157
- package/lib/esm/chunk-IKSTWKEM.mjs.map +0 -1
- package/lib/esm/chunk-JYZWCLMP.mjs +0 -305
- package/lib/esm/chunk-JYZWCLMP.mjs.map +0 -1
- package/lib/esm/chunk-PNSAJQCF.mjs +0 -108
- package/lib/esm/chunk-PNSAJQCF.mjs.map +0 -1
- package/lib/esm/chunk-PSA4YVU2.mjs +0 -92
- package/lib/esm/chunk-PSA4YVU2.mjs.map +0 -1
- package/lib/esm/chunk-QLXM7BIB.mjs +0 -23
- package/lib/esm/chunk-QLXM7BIB.mjs.map +0 -1
- package/lib/esm/chunk-TDLQZ6MP.mjs +0 -86
- package/lib/esm/chunk-TDLQZ6MP.mjs.map +0 -1
- package/lib/esm/chunk-VE37GDG2.mjs +0 -7
- package/lib/esm/chunk-VE37GDG2.mjs.map +0 -1
- package/lib/esm/chunk-WWACQNRQ.mjs +0 -7
- package/lib/esm/chunk-WWACQNRQ.mjs.map +0 -1
- package/lib/esm/chunk-X4W4S5RB.mjs +0 -39
- package/lib/esm/chunk-X4W4S5RB.mjs.map +0 -1
- package/lib/esm/chunk-Z4QX3O5V.mjs +0 -748
- package/lib/esm/chunk-Z4QX3O5V.mjs.map +0 -1
- package/lib/esm/chunk-ZYXTTU74.mjs +0 -88
- package/lib/esm/chunk-ZYXTTU74.mjs.map +0 -1
- package/lib/esm/client/index.d.mts +0 -243
- package/lib/esm/client/index.mjs +0 -260
- package/lib/esm/client/index.mjs.map +0 -1
- package/lib/esm/exact/client/index.d.mts +0 -37
- package/lib/esm/exact/client/index.mjs +0 -36
- package/lib/esm/exact/client/index.mjs.map +0 -1
- package/lib/esm/exact/facilitator/index.d.mts +0 -110
- package/lib/esm/exact/facilitator/index.mjs +0 -350
- package/lib/esm/exact/facilitator/index.mjs.map +0 -1
- package/lib/esm/exact/server/index.d.mts +0 -87
- package/lib/esm/exact/server/index.mjs +0 -129
- package/lib/esm/exact/server/index.mjs.map +0 -1
- package/lib/esm/exact/v1/client/index.d.mts +0 -33
- package/lib/esm/exact/v1/client/index.mjs +0 -8
- package/lib/esm/exact/v1/client/index.mjs.map +0 -1
- package/lib/esm/exact/v1/facilitator/index.d.mts +0 -71
- package/lib/esm/exact/v1/facilitator/index.mjs +0 -8
- package/lib/esm/exact/v1/facilitator/index.mjs.map +0 -1
- package/lib/esm/facilitator/index.d.mts +0 -192
- package/lib/esm/facilitator/index.mjs +0 -373
- package/lib/esm/facilitator/index.mjs.map +0 -1
- package/lib/esm/http/index.d.mts +0 -52
- package/lib/esm/http/index.mjs +0 -29
- package/lib/esm/http/index.mjs.map +0 -1
- package/lib/esm/mechanisms-CzuGzYsS.d.mts +0 -270
- package/lib/esm/scheme-fjF-9LhT.d.mts +0 -29
- package/lib/esm/server/index.d.mts +0 -2
- package/lib/esm/server/index.mjs +0 -563
- package/lib/esm/server/index.mjs.map +0 -1
- package/lib/esm/signer-5OVDxViv.d.mts +0 -79
- package/lib/esm/signer-BMkbhFYE.d.mts +0 -123
- package/lib/esm/types/index.d.mts +0 -1
- package/lib/esm/types/index.mjs +0 -10
- package/lib/esm/types/index.mjs.map +0 -1
- package/lib/esm/types/v1/index.d.mts +0 -1
- package/lib/esm/types/v1/index.mjs +0 -1
- package/lib/esm/types/v1/index.mjs.map +0 -1
- package/lib/esm/utils/index.d.mts +0 -48
- package/lib/esm/utils/index.mjs +0 -20
- package/lib/esm/utils/index.mjs.map +0 -1
- package/lib/esm/v1/index.d.mts +0 -12
- package/lib/esm/v1/index.mjs +0 -13
- package/lib/esm/v1/index.mjs.map +0 -1
- package/lib/esm/x402HTTPResourceServer-BIfIK5HS.d.mts +0 -719
- package/src/index.js +0 -4
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/facilitator/x402Facilitator.ts"],"sourcesContent":["import { x402Version } from \"..\";\nimport { SettleResponse, VerifyResponse } from \"../types/facilitator\";\nimport { SchemeNetworkFacilitator } from \"../types/mechanisms\";\nimport { PaymentPayload, PaymentRequirements } from \"../types/payments\";\nimport { Network } from \"../types\";\nimport { type SchemeData } from \"../utils\";\n\n/**\n * Facilitator Hook Context Interfaces\n */\n\nexport interface FacilitatorVerifyContext {\n paymentPayload: PaymentPayload;\n requirements: PaymentRequirements;\n}\n\nexport interface FacilitatorVerifyResultContext extends FacilitatorVerifyContext {\n result: VerifyResponse;\n}\n\nexport interface FacilitatorVerifyFailureContext extends FacilitatorVerifyContext {\n error: Error;\n}\n\nexport interface FacilitatorSettleContext {\n paymentPayload: PaymentPayload;\n requirements: PaymentRequirements;\n}\n\nexport interface FacilitatorSettleResultContext extends FacilitatorSettleContext {\n result: SettleResponse;\n}\n\nexport interface FacilitatorSettleFailureContext extends FacilitatorSettleContext {\n error: Error;\n}\n\n/**\n * Facilitator Hook Type Definitions\n */\n\nexport type FacilitatorBeforeVerifyHook = (\n context: FacilitatorVerifyContext,\n) => Promise<void | { abort: true; reason: string }>;\n\nexport type FacilitatorAfterVerifyHook = (context: FacilitatorVerifyResultContext) => Promise<void>;\n\nexport type FacilitatorOnVerifyFailureHook = (\n context: FacilitatorVerifyFailureContext,\n) => Promise<void | { recovered: true; result: VerifyResponse }>;\n\nexport type FacilitatorBeforeSettleHook = (\n context: FacilitatorSettleContext,\n) => Promise<void | { abort: true; reason: string }>;\n\nexport type FacilitatorAfterSettleHook = (context: FacilitatorSettleResultContext) => Promise<void>;\n\nexport type FacilitatorOnSettleFailureHook = (\n context: FacilitatorSettleFailureContext,\n) => Promise<void | { recovered: true; result: SettleResponse }>;\n\n/**\n * Facilitator client for the x402 payment protocol.\n * Manages payment scheme registration, verification, and settlement.\n */\nexport class x402Facilitator {\n private readonly registeredFacilitatorSchemes: Map<\n number,\n SchemeData<SchemeNetworkFacilitator>[] // Array to support multiple facilitators per version\n > = new Map();\n private readonly extensions: string[] = [];\n\n private beforeVerifyHooks: FacilitatorBeforeVerifyHook[] = [];\n private afterVerifyHooks: FacilitatorAfterVerifyHook[] = [];\n private onVerifyFailureHooks: FacilitatorOnVerifyFailureHook[] = [];\n private beforeSettleHooks: FacilitatorBeforeSettleHook[] = [];\n private afterSettleHooks: FacilitatorAfterSettleHook[] = [];\n private onSettleFailureHooks: FacilitatorOnSettleFailureHook[] = [];\n\n /**\n * Registers a scheme facilitator for the current x402 version.\n * Networks are stored and used for getSupported() - no need to specify them later.\n *\n * @param networks - Single network or array of networks this facilitator supports\n * @param facilitator - The scheme network facilitator to register\n * @returns The x402Facilitator instance for chaining\n */\n register(networks: Network | Network[], facilitator: SchemeNetworkFacilitator): x402Facilitator {\n const networksArray = Array.isArray(networks) ? networks : [networks];\n return this._registerScheme(x402Version, networksArray, facilitator);\n }\n\n /**\n * Registers a scheme facilitator for x402 version 1.\n * Networks are stored and used for getSupported() - no need to specify them later.\n *\n * @param networks - Single network or array of networks this facilitator supports\n * @param facilitator - The scheme network facilitator to register\n * @returns The x402Facilitator instance for chaining\n */\n registerV1(\n networks: Network | Network[],\n facilitator: SchemeNetworkFacilitator,\n ): x402Facilitator {\n const networksArray = Array.isArray(networks) ? networks : [networks];\n return this._registerScheme(1, networksArray, facilitator);\n }\n\n /**\n * Registers a protocol extension.\n *\n * @param extension - The extension name to register (e.g., \"bazaar\", \"sign_in_with_x\")\n * @returns The x402Facilitator instance for chaining\n */\n registerExtension(extension: string): x402Facilitator {\n // Check if already registered\n if (!this.extensions.includes(extension)) {\n this.extensions.push(extension);\n }\n return this;\n }\n\n /**\n * Gets the list of registered extensions.\n *\n * @returns Array of extension names\n */\n getExtensions(): string[] {\n return [...this.extensions];\n }\n\n /**\n * Register a hook to execute before facilitator payment verification.\n * Can abort verification by returning { abort: true, reason: string }\n *\n * @param hook - The hook function to register\n * @returns The x402Facilitator instance for chaining\n */\n onBeforeVerify(hook: FacilitatorBeforeVerifyHook): x402Facilitator {\n this.beforeVerifyHooks.push(hook);\n return this;\n }\n\n /**\n * Register a hook to execute after successful facilitator payment verification (isValid: true).\n * This hook is NOT called when verification fails (isValid: false) - use onVerifyFailure for that.\n *\n * @param hook - The hook function to register\n * @returns The x402Facilitator instance for chaining\n */\n onAfterVerify(hook: FacilitatorAfterVerifyHook): x402Facilitator {\n this.afterVerifyHooks.push(hook);\n return this;\n }\n\n /**\n * Register a hook to execute when facilitator payment verification fails.\n * Called when: verification returns isValid: false, or an exception is thrown during verification.\n * Can recover from failure by returning { recovered: true, result: VerifyResponse }\n *\n * @param hook - The hook function to register\n * @returns The x402Facilitator instance for chaining\n */\n onVerifyFailure(hook: FacilitatorOnVerifyFailureHook): x402Facilitator {\n this.onVerifyFailureHooks.push(hook);\n return this;\n }\n\n /**\n * Register a hook to execute before facilitator payment settlement.\n * Can abort settlement by returning { abort: true, reason: string }\n *\n * @param hook - The hook function to register\n * @returns The x402Facilitator instance for chaining\n */\n onBeforeSettle(hook: FacilitatorBeforeSettleHook): x402Facilitator {\n this.beforeSettleHooks.push(hook);\n return this;\n }\n\n /**\n * Register a hook to execute after successful facilitator payment settlement.\n *\n * @param hook - The hook function to register\n * @returns The x402Facilitator instance for chaining\n */\n onAfterSettle(hook: FacilitatorAfterSettleHook): x402Facilitator {\n this.afterSettleHooks.push(hook);\n return this;\n }\n\n /**\n * Register a hook to execute when facilitator 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 x402Facilitator instance for chaining\n */\n onSettleFailure(hook: FacilitatorOnSettleFailureHook): x402Facilitator {\n this.onSettleFailureHooks.push(hook);\n return this;\n }\n\n /**\n * Gets supported payment kinds, extensions, and signers.\n * Uses networks registered during register() calls - no parameters needed.\n * Returns flat array format for backward compatibility with V1 clients.\n *\n * @returns Supported response with kinds as array (with version in each element), extensions, and signers\n */\n getSupported(): {\n kinds: Array<{\n x402Version: number;\n scheme: string;\n network: string;\n extra?: Record<string, unknown>;\n }>;\n extensions: string[];\n signers: Record<string, string[]>;\n } {\n const kinds: Array<{\n x402Version: number;\n scheme: string;\n network: string;\n extra?: Record<string, unknown>;\n }> = [];\n const signersByFamily: Record<string, Set<string>> = {};\n\n // Iterate over registered scheme data (array supports multiple facilitators per version)\n for (const [version, schemeDataArray] of this.registeredFacilitatorSchemes) {\n for (const schemeData of schemeDataArray) {\n const { facilitator, networks } = schemeData;\n const scheme = facilitator.scheme;\n\n // Iterate over stored concrete networks\n for (const network of networks) {\n const extra = facilitator.getExtra(network);\n kinds.push({\n x402Version: version,\n scheme,\n network,\n ...(extra && { extra }),\n });\n\n // Collect signers by CAIP family for this network\n const family = facilitator.caipFamily;\n if (!signersByFamily[family]) {\n signersByFamily[family] = new Set();\n }\n facilitator.getSigners(network).forEach(signer => signersByFamily[family].add(signer));\n }\n }\n }\n\n // Convert signer sets to arrays\n const signers: Record<string, string[]> = {};\n for (const [family, signerSet] of Object.entries(signersByFamily)) {\n signers[family] = Array.from(signerSet);\n }\n\n return {\n kinds,\n extensions: this.extensions,\n signers,\n };\n }\n\n /**\n * Verifies a payment payload against requirements.\n *\n * @param paymentPayload - The payment payload to verify\n * @param paymentRequirements - The payment requirements to verify against\n * @returns Promise resolving to the verification response\n */\n async verify(\n paymentPayload: PaymentPayload,\n paymentRequirements: PaymentRequirements,\n ): Promise<VerifyResponse> {\n const context: FacilitatorVerifyContext = {\n paymentPayload,\n requirements: paymentRequirements,\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 const schemeDataArray = this.registeredFacilitatorSchemes.get(paymentPayload.x402Version);\n if (!schemeDataArray) {\n throw new Error(\n `No facilitator registered for x402 version: ${paymentPayload.x402Version}`,\n );\n }\n\n // Find matching facilitator from array\n let schemeNetworkFacilitator: SchemeNetworkFacilitator | undefined;\n for (const schemeData of schemeDataArray) {\n if (schemeData.facilitator.scheme === paymentRequirements.scheme) {\n // Check if network matches\n if (schemeData.networks.has(paymentRequirements.network)) {\n schemeNetworkFacilitator = schemeData.facilitator;\n break;\n }\n // Try pattern matching\n const patternRegex = new RegExp(\"^\" + schemeData.pattern.replace(\"*\", \".*\") + \"$\");\n if (patternRegex.test(paymentRequirements.network)) {\n schemeNetworkFacilitator = schemeData.facilitator;\n break;\n }\n }\n }\n\n if (!schemeNetworkFacilitator) {\n throw new Error(\n `No facilitator registered for scheme: ${paymentRequirements.scheme} and network: ${paymentRequirements.network}`,\n );\n }\n\n const verifyResult = await schemeNetworkFacilitator.verify(\n paymentPayload,\n paymentRequirements,\n );\n\n // Check if verification failed (isValid: false)\n if (!verifyResult.isValid) {\n const failureContext: FacilitatorVerifyFailureContext = {\n ...context,\n error: new Error(verifyResult.invalidReason || \"Verification failed\"),\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 // If recovered, execute afterVerify hooks with recovered result\n const recoveredContext: FacilitatorVerifyResultContext = {\n ...context,\n result: result.result,\n };\n for (const hook of this.afterVerifyHooks) {\n await hook(recoveredContext);\n }\n return result.result;\n }\n }\n\n return verifyResult;\n }\n\n // Execute afterVerify hooks only for successful verification\n const resultContext: FacilitatorVerifyResultContext = {\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: FacilitatorVerifyFailureContext = {\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 * Settles a payment based on the payload and requirements.\n *\n * @param paymentPayload - The payment payload to settle\n * @param paymentRequirements - The payment requirements for settlement\n * @returns Promise resolving to the settlement response\n */\n async settle(\n paymentPayload: PaymentPayload,\n paymentRequirements: PaymentRequirements,\n ): Promise<SettleResponse> {\n const context: FacilitatorSettleContext = {\n paymentPayload,\n requirements: paymentRequirements,\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 const schemeDataArray = this.registeredFacilitatorSchemes.get(paymentPayload.x402Version);\n if (!schemeDataArray) {\n throw new Error(\n `No facilitator registered for x402 version: ${paymentPayload.x402Version}`,\n );\n }\n\n // Find matching facilitator from array\n let schemeNetworkFacilitator: SchemeNetworkFacilitator | undefined;\n for (const schemeData of schemeDataArray) {\n if (schemeData.facilitator.scheme === paymentRequirements.scheme) {\n // Check if network matches\n if (schemeData.networks.has(paymentRequirements.network)) {\n schemeNetworkFacilitator = schemeData.facilitator;\n break;\n }\n // Try pattern matching\n const patternRegex = new RegExp(\"^\" + schemeData.pattern.replace(\"*\", \".*\") + \"$\");\n if (patternRegex.test(paymentRequirements.network)) {\n schemeNetworkFacilitator = schemeData.facilitator;\n break;\n }\n }\n }\n\n if (!schemeNetworkFacilitator) {\n throw new Error(\n `No facilitator registered for scheme: ${paymentRequirements.scheme} and network: ${paymentRequirements.network}`,\n );\n }\n\n const settleResult = await schemeNetworkFacilitator.settle(\n paymentPayload,\n paymentRequirements,\n );\n\n // Execute afterSettle hooks\n const resultContext: FacilitatorSettleResultContext = {\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: FacilitatorSettleFailureContext = {\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 * Internal method to register a scheme facilitator.\n *\n * @param x402Version - The x402 protocol version\n * @param networks - Array of concrete networks this facilitator supports\n * @param facilitator - The scheme network facilitator to register\n * @returns The x402Facilitator instance for chaining\n */\n private _registerScheme(\n x402Version: number,\n networks: Network[],\n facilitator: SchemeNetworkFacilitator,\n ): x402Facilitator {\n if (!this.registeredFacilitatorSchemes.has(x402Version)) {\n this.registeredFacilitatorSchemes.set(x402Version, []);\n }\n const schemeDataArray = this.registeredFacilitatorSchemes.get(x402Version)!;\n\n // Add new scheme data (supports multiple facilitators with same scheme name)\n schemeDataArray.push({\n facilitator,\n networks: new Set(networks),\n pattern: this.derivePattern(networks),\n });\n\n return this;\n }\n\n /**\n * Derives a wildcard pattern from an array of networks.\n * If all networks share the same namespace, returns wildcard pattern.\n * Otherwise returns the first network for exact matching.\n *\n * @param networks - Array of networks\n * @returns Derived pattern for matching\n */\n private derivePattern(networks: Network[]): Network {\n if (networks.length === 0) return \"\" as Network;\n if (networks.length === 1) return networks[0];\n\n // Extract namespaces (e.g., \"eip155\" from \"eip155:84532\")\n const namespaces = networks.map(n => n.split(\":\")[0]);\n const uniqueNamespaces = new Set(namespaces);\n\n // If all same namespace, use wildcard\n if (uniqueNamespaces.size === 1) {\n return `${namespaces[0]}:*` as Network;\n }\n\n // Mixed namespaces - use first network for exact matching\n return networks[0];\n }\n}\n"],"mappings":";;;;;;AAiEO,IAAM,kBAAN,MAAsB;AAAA,EAAtB;AACL,SAAiB,+BAGb,oBAAI,IAAI;AACZ,SAAiB,aAAuB,CAAC;AAEzC,SAAQ,oBAAmD,CAAC;AAC5D,SAAQ,mBAAiD,CAAC;AAC1D,SAAQ,uBAAyD,CAAC;AAClE,SAAQ,oBAAmD,CAAC;AAC5D,SAAQ,mBAAiD,CAAC;AAC1D,SAAQ,uBAAyD,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUlE,SAAS,UAA+B,aAAwD;AAC9F,UAAM,gBAAgB,MAAM,QAAQ,QAAQ,IAAI,WAAW,CAAC,QAAQ;AACpE,WAAO,KAAK,gBAAgB,aAAa,eAAe,WAAW;AAAA,EACrE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,WACE,UACA,aACiB;AACjB,UAAM,gBAAgB,MAAM,QAAQ,QAAQ,IAAI,WAAW,CAAC,QAAQ;AACpE,WAAO,KAAK,gBAAgB,GAAG,eAAe,WAAW;AAAA,EAC3D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,kBAAkB,WAAoC;AAEpD,QAAI,CAAC,KAAK,WAAW,SAAS,SAAS,GAAG;AACxC,WAAK,WAAW,KAAK,SAAS;AAAA,IAChC;AACA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,gBAA0B;AACxB,WAAO,CAAC,GAAG,KAAK,UAAU;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,eAAe,MAAoD;AACjE,SAAK,kBAAkB,KAAK,IAAI;A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AAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUQ,gBACNC,cACA,UACA,aACiB;AACjB,QAAI,CAAC,KAAK,6BAA6B,IAAIA,YAAW,GAAG;AACvD,WAAK,6BAA6B,IAAIA,cAAa,CAAC,CAAC;AAAA,IACvD;AACA,UAAM,kBAAkB,KAAK,6BAA6B,IAAIA,YAAW;AAGzE,oBAAgB,KAAK;AAAA,MACnB;AAAA,MACA,UAAU,IAAI,IAAI,QAAQ;AAAA,MAC1B,SAAS,KAAK,cAAc,QAAQ;AAAA,IACtC,CAAC;AAED,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUQ,cAAc,UAA8B;AAClD,QAAI,SAAS,WAAW,EAAG,QAAO;AAClC,QAAI,SAAS,WAAW,EAAG,QAAO,SAAS,CAAC;AAG5C,UAAM,aAAa,SAAS,IAAI,OAAK,EAAE,MAAM,GAAG,EAAE,CAAC,CAAC;AACpD,UAAM,mBAAmB,IAAI,IAAI,UAAU;AAG3C,QAAI,iBAAiB,SAAS,GAAG;AAC/B,aAAO,GAAG,WAAW,CAAC,CAAC;AAAA,IACzB;AAGA,WAAO,SAAS,CAAC;AAAA,EACnB;AACF;","names":["hook","x402Version"]}
|
package/lib/esm/http/index.d.mts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { P as PaymentPayload, c as PaymentRequired, S as SettleResponse, a as PaymentRequirements } from '../mechanisms-CzuGzYsS.mjs';
|
|
2
|
-
export { C as CompiledRoute, D as DynamicPayTo, g as DynamicPrice, F as FacilitatorClient, o as FacilitatorConfig, H as HTTPAdapter, n as HTTPFacilitatorClient, c as HTTPProcessResult, a as HTTPRequestContext, b as HTTPResponseInstructions, e as PaymentOption, P as PaywallConfig, d as PaywallProvider, k as ProcessSettleFailureResponse, i as ProcessSettleResultResponse, j as ProcessSettleSuccessResponse, R as RouteConfig, m as RouteConfigurationError, l as RouteValidationError, f as RoutesConfig, U as UnpaidResponseBody, h as UnpaidResponseResult, x as x402HTTPResourceServer } from '../x402HTTPResourceServer-BIfIK5HS.mjs';
|
|
3
|
-
export { x402HTTPClient } from '../client/index.mjs';
|
|
4
|
-
|
|
5
|
-
type QueryParamMethods = "GET" | "HEAD" | "DELETE";
|
|
6
|
-
type BodyMethods = "POST" | "PUT" | "PATCH";
|
|
7
|
-
/**
|
|
8
|
-
* Encodes a payment payload as a base64 header value.
|
|
9
|
-
*
|
|
10
|
-
* @param paymentPayload - The payment payload to encode
|
|
11
|
-
* @returns Base64 encoded string representation of the payment payload
|
|
12
|
-
*/
|
|
13
|
-
declare function encodePaymentSignatureHeader(paymentPayload: PaymentPayload): string;
|
|
14
|
-
/**
|
|
15
|
-
* Decodes a base64 payment signature header into a payment payload.
|
|
16
|
-
*
|
|
17
|
-
* @param paymentSignatureHeader - The base64 encoded payment signature header
|
|
18
|
-
* @returns The decoded payment payload
|
|
19
|
-
*/
|
|
20
|
-
declare function decodePaymentSignatureHeader(paymentSignatureHeader: string): PaymentPayload;
|
|
21
|
-
/**
|
|
22
|
-
* Encodes a payment required object as a base64 header value.
|
|
23
|
-
*
|
|
24
|
-
* @param paymentRequired - The payment required object to encode
|
|
25
|
-
* @returns Base64 encoded string representation of the payment required object
|
|
26
|
-
*/
|
|
27
|
-
declare function encodePaymentRequiredHeader(paymentRequired: PaymentRequired): string;
|
|
28
|
-
/**
|
|
29
|
-
* Decodes a base64 payment required header into a payment required object.
|
|
30
|
-
*
|
|
31
|
-
* @param paymentRequiredHeader - The base64 encoded payment required header
|
|
32
|
-
* @returns The decoded payment required object
|
|
33
|
-
*/
|
|
34
|
-
declare function decodePaymentRequiredHeader(paymentRequiredHeader: string): PaymentRequired;
|
|
35
|
-
/**
|
|
36
|
-
* Encodes a payment response as a base64 header value.
|
|
37
|
-
*
|
|
38
|
-
* @param paymentResponse - The payment response to encode
|
|
39
|
-
* @returns Base64 encoded string representation of the payment response
|
|
40
|
-
*/
|
|
41
|
-
declare function encodePaymentResponseHeader(paymentResponse: SettleResponse & {
|
|
42
|
-
requirements: PaymentRequirements;
|
|
43
|
-
}): string;
|
|
44
|
-
/**
|
|
45
|
-
* Decodes a base64 payment response header into a settle response.
|
|
46
|
-
*
|
|
47
|
-
* @param paymentResponseHeader - The base64 encoded payment response header
|
|
48
|
-
* @returns The decoded settle response
|
|
49
|
-
*/
|
|
50
|
-
declare function decodePaymentResponseHeader(paymentResponseHeader: string): SettleResponse;
|
|
51
|
-
|
|
52
|
-
export { type BodyMethods, type QueryParamMethods, decodePaymentRequiredHeader, decodePaymentResponseHeader, decodePaymentSignatureHeader, encodePaymentRequiredHeader, encodePaymentResponseHeader, encodePaymentSignatureHeader };
|
package/lib/esm/http/index.mjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HTTPFacilitatorClient,
|
|
3
|
-
RouteConfigurationError,
|
|
4
|
-
decodePaymentRequiredHeader,
|
|
5
|
-
decodePaymentResponseHeader,
|
|
6
|
-
decodePaymentSignatureHeader,
|
|
7
|
-
encodePaymentRequiredHeader,
|
|
8
|
-
encodePaymentResponseHeader,
|
|
9
|
-
encodePaymentSignatureHeader,
|
|
10
|
-
x402HTTPClient,
|
|
11
|
-
x402HTTPResourceServer
|
|
12
|
-
} from "../chunk-Z4QX3O5V.mjs";
|
|
13
|
-
import "../chunk-VE37GDG2.mjs";
|
|
14
|
-
import "../chunk-X4W4S5RB.mjs";
|
|
15
|
-
import "../chunk-TDLQZ6MP.mjs";
|
|
16
|
-
import "../chunk-BJTO5JO5.mjs";
|
|
17
|
-
export {
|
|
18
|
-
HTTPFacilitatorClient,
|
|
19
|
-
RouteConfigurationError,
|
|
20
|
-
decodePaymentRequiredHeader,
|
|
21
|
-
decodePaymentResponseHeader,
|
|
22
|
-
decodePaymentSignatureHeader,
|
|
23
|
-
encodePaymentRequiredHeader,
|
|
24
|
-
encodePaymentResponseHeader,
|
|
25
|
-
encodePaymentSignatureHeader,
|
|
26
|
-
x402HTTPClient,
|
|
27
|
-
x402HTTPResourceServer
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
type PaymentRequirementsV1 = {
|
|
2
|
-
scheme: string;
|
|
3
|
-
network: Network;
|
|
4
|
-
maxAmountRequired: string;
|
|
5
|
-
resource: string;
|
|
6
|
-
description: string;
|
|
7
|
-
mimeType: string;
|
|
8
|
-
outputSchema: Record<string, unknown>;
|
|
9
|
-
payTo: string;
|
|
10
|
-
maxTimeoutSeconds: number;
|
|
11
|
-
asset: string;
|
|
12
|
-
extra: Record<string, unknown>;
|
|
13
|
-
};
|
|
14
|
-
type PaymentRequiredV1 = {
|
|
15
|
-
x402Version: 1;
|
|
16
|
-
error?: string;
|
|
17
|
-
accepts: PaymentRequirementsV1[];
|
|
18
|
-
};
|
|
19
|
-
type PaymentPayloadV1 = {
|
|
20
|
-
x402Version: 1;
|
|
21
|
-
scheme: string;
|
|
22
|
-
network: Network;
|
|
23
|
-
payload: Record<string, unknown>;
|
|
24
|
-
};
|
|
25
|
-
type VerifyRequestV1 = {
|
|
26
|
-
paymentPayload: PaymentPayloadV1;
|
|
27
|
-
paymentRequirements: PaymentRequirementsV1;
|
|
28
|
-
};
|
|
29
|
-
type SettleRequestV1 = {
|
|
30
|
-
paymentPayload: PaymentPayloadV1;
|
|
31
|
-
paymentRequirements: PaymentRequirementsV1;
|
|
32
|
-
};
|
|
33
|
-
type SettleResponseV1 = {
|
|
34
|
-
success: boolean;
|
|
35
|
-
errorReason?: string;
|
|
36
|
-
payer?: string;
|
|
37
|
-
transaction: string;
|
|
38
|
-
network: Network;
|
|
39
|
-
};
|
|
40
|
-
type SupportedResponseV1 = {
|
|
41
|
-
kinds: {
|
|
42
|
-
x402Version: number;
|
|
43
|
-
scheme: string;
|
|
44
|
-
network: Network;
|
|
45
|
-
extra?: Record<string, unknown>;
|
|
46
|
-
}[];
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
interface ResourceServerExtension {
|
|
50
|
-
key: string;
|
|
51
|
-
enrichDeclaration?: (declaration: unknown, transportContext: unknown) => unknown;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
type Network = `${string}:${string}`;
|
|
55
|
-
type Money = string | number;
|
|
56
|
-
type AssetAmount = {
|
|
57
|
-
asset: string;
|
|
58
|
-
amount: string;
|
|
59
|
-
extra?: Record<string, unknown>;
|
|
60
|
-
};
|
|
61
|
-
type Price = Money | AssetAmount;
|
|
62
|
-
|
|
63
|
-
interface ResourceInfo {
|
|
64
|
-
url: string;
|
|
65
|
-
description: string;
|
|
66
|
-
mimeType: string;
|
|
67
|
-
}
|
|
68
|
-
type PaymentRequirements = {
|
|
69
|
-
scheme: string;
|
|
70
|
-
network: Network;
|
|
71
|
-
asset: string;
|
|
72
|
-
amount: string;
|
|
73
|
-
payTo: string;
|
|
74
|
-
maxTimeoutSeconds: number;
|
|
75
|
-
extra: Record<string, unknown>;
|
|
76
|
-
};
|
|
77
|
-
type PaymentRequired = {
|
|
78
|
-
x402Version: number;
|
|
79
|
-
error?: string;
|
|
80
|
-
resource: ResourceInfo;
|
|
81
|
-
accepts: PaymentRequirements[];
|
|
82
|
-
extensions?: Record<string, unknown>;
|
|
83
|
-
};
|
|
84
|
-
type PaymentPayload = {
|
|
85
|
-
x402Version: number;
|
|
86
|
-
resource: ResourceInfo;
|
|
87
|
-
accepted: PaymentRequirements;
|
|
88
|
-
payload: Record<string, unknown>;
|
|
89
|
-
extensions?: Record<string, unknown>;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
type VerifyRequest = {
|
|
93
|
-
paymentPayload: PaymentPayload;
|
|
94
|
-
paymentRequirements: PaymentRequirements;
|
|
95
|
-
};
|
|
96
|
-
type VerifyResponse = {
|
|
97
|
-
isValid: boolean;
|
|
98
|
-
invalidReason?: string;
|
|
99
|
-
payer?: string;
|
|
100
|
-
};
|
|
101
|
-
type SettleRequest = {
|
|
102
|
-
paymentPayload: PaymentPayload;
|
|
103
|
-
paymentRequirements: PaymentRequirements;
|
|
104
|
-
};
|
|
105
|
-
type SettleResponse = {
|
|
106
|
-
success: boolean;
|
|
107
|
-
errorReason?: string;
|
|
108
|
-
payer?: string;
|
|
109
|
-
transaction: string;
|
|
110
|
-
network: Network;
|
|
111
|
-
};
|
|
112
|
-
type SupportedKind = {
|
|
113
|
-
x402Version: number;
|
|
114
|
-
scheme: string;
|
|
115
|
-
network: Network;
|
|
116
|
-
extra?: Record<string, unknown>;
|
|
117
|
-
};
|
|
118
|
-
type SupportedResponse = {
|
|
119
|
-
kinds: SupportedKind[];
|
|
120
|
-
extensions: string[];
|
|
121
|
-
signers: Record<string, string[]>;
|
|
122
|
-
};
|
|
123
|
-
/**
|
|
124
|
-
* Error thrown when payment verification fails.
|
|
125
|
-
*/
|
|
126
|
-
declare class VerifyError extends Error {
|
|
127
|
-
readonly invalidReason?: string;
|
|
128
|
-
readonly payer?: string;
|
|
129
|
-
readonly statusCode: number;
|
|
130
|
-
/**
|
|
131
|
-
* Creates a VerifyError from a failed verification response.
|
|
132
|
-
*
|
|
133
|
-
* @param statusCode - HTTP status code from the facilitator
|
|
134
|
-
* @param response - The verify response containing error details
|
|
135
|
-
*/
|
|
136
|
-
constructor(statusCode: number, response: VerifyResponse);
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Error thrown when payment settlement fails.
|
|
140
|
-
*/
|
|
141
|
-
declare class SettleError extends Error {
|
|
142
|
-
readonly errorReason?: string;
|
|
143
|
-
readonly payer?: string;
|
|
144
|
-
readonly transaction: string;
|
|
145
|
-
readonly network: Network;
|
|
146
|
-
readonly statusCode: number;
|
|
147
|
-
/**
|
|
148
|
-
* Creates a SettleError from a failed settlement response.
|
|
149
|
-
*
|
|
150
|
-
* @param statusCode - HTTP status code from the facilitator
|
|
151
|
-
* @param response - The settle response containing error details
|
|
152
|
-
*/
|
|
153
|
-
constructor(statusCode: number, response: SettleResponse);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Money parser function that converts a numeric amount to an AssetAmount
|
|
158
|
-
* Receives the amount as a decimal number (e.g., 1.50 for $1.50)
|
|
159
|
-
* Returns null to indicate "cannot handle this amount", causing fallback to next parser
|
|
160
|
-
* Always returns a Promise for consistency - use async/await
|
|
161
|
-
*
|
|
162
|
-
* @param amount - The decimal amount (e.g., 1.50)
|
|
163
|
-
* @param network - The network identifier for context
|
|
164
|
-
* @returns AssetAmount or null to try next parser
|
|
165
|
-
*/
|
|
166
|
-
type MoneyParser = (amount: number, network: Network) => Promise<AssetAmount | null>;
|
|
167
|
-
interface SchemeNetworkClient {
|
|
168
|
-
readonly scheme: string;
|
|
169
|
-
createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements): Promise<Pick<PaymentPayload, "x402Version" | "payload">>;
|
|
170
|
-
}
|
|
171
|
-
interface SchemeNetworkFacilitator {
|
|
172
|
-
readonly scheme: string;
|
|
173
|
-
/**
|
|
174
|
-
* CAIP family pattern that this facilitator supports.
|
|
175
|
-
* Used to group signers by blockchain family in the supported response.
|
|
176
|
-
*
|
|
177
|
-
* @example
|
|
178
|
-
* // EVM facilitators
|
|
179
|
-
* readonly caipFamily = "eip155:*";
|
|
180
|
-
*
|
|
181
|
-
* @example
|
|
182
|
-
* // SVM facilitators
|
|
183
|
-
* readonly caipFamily = "solana:*";
|
|
184
|
-
*/
|
|
185
|
-
readonly caipFamily: string;
|
|
186
|
-
/**
|
|
187
|
-
* Get mechanism-specific extra data needed for the supported kinds endpoint.
|
|
188
|
-
* This method is called when building the facilitator's supported response.
|
|
189
|
-
*
|
|
190
|
-
* @param network - The network identifier for context
|
|
191
|
-
* @returns Extra data object or undefined if no extra data is needed
|
|
192
|
-
*
|
|
193
|
-
* @example
|
|
194
|
-
* // EVM schemes return undefined (no extra data needed)
|
|
195
|
-
* getExtra(network: Network): undefined {
|
|
196
|
-
* return undefined;
|
|
197
|
-
* }
|
|
198
|
-
*
|
|
199
|
-
* @example
|
|
200
|
-
* // SVM schemes return feePayer address
|
|
201
|
-
* getExtra(network: Network): Record<string, unknown> | undefined {
|
|
202
|
-
* return { feePayer: this.signer.address };
|
|
203
|
-
* }
|
|
204
|
-
*/
|
|
205
|
-
getExtra(network: Network): Record<string, unknown> | undefined;
|
|
206
|
-
/**
|
|
207
|
-
* Get signer addresses used by this facilitator for a given network.
|
|
208
|
-
* These are included in the supported response to help clients understand
|
|
209
|
-
* which addresses might sign/pay for transactions.
|
|
210
|
-
*
|
|
211
|
-
* Supports multiple addresses for load balancing, key rotation, and high availability.
|
|
212
|
-
*
|
|
213
|
-
* @param network - The network identifier
|
|
214
|
-
* @returns Array of signer addresses (wallet addresses, fee payer addresses, etc.)
|
|
215
|
-
*
|
|
216
|
-
* @example
|
|
217
|
-
* // EVM facilitator
|
|
218
|
-
* getSigners(network: string): string[] {
|
|
219
|
-
* return [...this.signer.getAddresses()];
|
|
220
|
-
* }
|
|
221
|
-
*
|
|
222
|
-
* @example
|
|
223
|
-
* // SVM facilitator
|
|
224
|
-
* getSigners(network: string): string[] {
|
|
225
|
-
* return [...this.signer.getAddresses()];
|
|
226
|
-
* }
|
|
227
|
-
*/
|
|
228
|
-
getSigners(network: string): string[];
|
|
229
|
-
verify(payload: PaymentPayload, requirements: PaymentRequirements): Promise<VerifyResponse>;
|
|
230
|
-
settle(payload: PaymentPayload, requirements: PaymentRequirements): Promise<SettleResponse>;
|
|
231
|
-
}
|
|
232
|
-
interface SchemeNetworkServer {
|
|
233
|
-
readonly scheme: string;
|
|
234
|
-
/**
|
|
235
|
-
* Convert a user-friendly price to the scheme's specific amount and asset format
|
|
236
|
-
* Always returns a Promise for consistency
|
|
237
|
-
*
|
|
238
|
-
* @param price - User-friendly price (e.g., "$0.10", "0.10", { amount: "100000", asset: "USDC" })
|
|
239
|
-
* @param network - The network identifier for context
|
|
240
|
-
* @returns Promise that resolves to the converted amount, asset identifier, and any extra metadata
|
|
241
|
-
*
|
|
242
|
-
* @example
|
|
243
|
-
* // For EVM networks with USDC:
|
|
244
|
-
* await parsePrice("$0.10", "eip155:8453") => { amount: "100000", asset: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" }
|
|
245
|
-
*
|
|
246
|
-
* // For custom schemes:
|
|
247
|
-
* await parsePrice("10 points", "custom:network") => { amount: "10", asset: "points" }
|
|
248
|
-
*/
|
|
249
|
-
parsePrice(price: Price, network: Network): Promise<AssetAmount>;
|
|
250
|
-
/**
|
|
251
|
-
* Build payment requirements for this scheme/network combination
|
|
252
|
-
*
|
|
253
|
-
* @param paymentRequirements - Base payment requirements with amount/asset already set
|
|
254
|
-
* @param supportedKind - The supported kind from facilitator's /supported endpoint
|
|
255
|
-
* @param supportedKind.x402Version - The x402 version
|
|
256
|
-
* @param supportedKind.scheme - The payment scheme
|
|
257
|
-
* @param supportedKind.network - The network identifier
|
|
258
|
-
* @param supportedKind.extra - Optional extra metadata
|
|
259
|
-
* @param facilitatorExtensions - Extensions supported by the facilitator
|
|
260
|
-
* @returns Enhanced payment requirements ready to be sent to clients
|
|
261
|
-
*/
|
|
262
|
-
enhancePaymentRequirements(paymentRequirements: PaymentRequirements, supportedKind: {
|
|
263
|
-
x402Version: number;
|
|
264
|
-
scheme: string;
|
|
265
|
-
network: Network;
|
|
266
|
-
extra?: Record<string, unknown>;
|
|
267
|
-
}, facilitatorExtensions: string[]): Promise<PaymentRequirements>;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
export { type AssetAmount as A, type Money as M, type Network as N, type PaymentPayload as P, type ResourceServerExtension as R, type SettleResponse as S, type VerifyResponse as V, type PaymentRequirements as a, type SchemeNetworkFacilitator as b, type PaymentRequired as c, type SchemeNetworkClient as d, type SupportedResponse as e, type SchemeNetworkServer as f, type SupportedKind as g, type Price as h, type PaymentRequirementsV1 as i, type PaymentRequiredV1 as j, type PaymentPayloadV1 as k, type VerifyRequestV1 as l, type SettleRequestV1 as m, type SettleResponseV1 as n, type SupportedResponseV1 as o, type VerifyRequest as p, type SettleRequest as q, VerifyError as r, SettleError as s, type MoneyParser as t };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { SchemeNetworkClient, PaymentRequirements, PaymentPayload } from '@x402/core/types';
|
|
2
|
-
import { C as ClientSvmSigner, a as ClientSvmConfig } from './signer-BMkbhFYE.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* SVM client implementation for the Exact payment scheme.
|
|
6
|
-
*/
|
|
7
|
-
declare class ExactSvmScheme implements SchemeNetworkClient {
|
|
8
|
-
private readonly signer;
|
|
9
|
-
private readonly config?;
|
|
10
|
-
readonly scheme = "exact";
|
|
11
|
-
/**
|
|
12
|
-
* Creates a new ExactSvmClient instance.
|
|
13
|
-
*
|
|
14
|
-
* @param signer - The SVM signer for client operations
|
|
15
|
-
* @param config - Optional configuration with custom RPC URL
|
|
16
|
-
* @returns ExactSvmClient instance
|
|
17
|
-
*/
|
|
18
|
-
constructor(signer: ClientSvmSigner, config?: ClientSvmConfig | undefined);
|
|
19
|
-
/**
|
|
20
|
-
* Creates a payment payload for the Exact scheme.
|
|
21
|
-
*
|
|
22
|
-
* @param x402Version - The x402 protocol version
|
|
23
|
-
* @param paymentRequirements - The payment requirements
|
|
24
|
-
* @returns Promise resolving to a payment payload
|
|
25
|
-
*/
|
|
26
|
-
createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements): Promise<Pick<PaymentPayload, "x402Version" | "payload">>;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { ExactSvmScheme as E };
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export { C as CompiledRoute, F as FacilitatorClient, o as FacilitatorConfig, H as HTTPAdapter, n as HTTPFacilitatorClient, c as HTTPProcessResult, a as HTTPRequestContext, b as HTTPResponseInstructions, P as PaywallConfig, d as PaywallProvider, k as ProcessSettleFailureResponse, i as ProcessSettleResultResponse, j as ProcessSettleSuccessResponse, q as ResourceConfig, r as ResourceInfo, R as RouteConfig, m as RouteConfigurationError, l as RouteValidationError, f as RoutesConfig, U as UnpaidResponseBody, h as UnpaidResponseResult, x as x402HTTPResourceServer, p as x402ResourceServer } from '../x402HTTPResourceServer-BIfIK5HS.mjs';
|
|
2
|
-
import '../mechanisms-CzuGzYsS.mjs';
|