x402-express-mantle 1.0.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.
Files changed (127) hide show
  1. package/README.md +155 -0
  2. package/lib/cjs/client/index.d.ts +243 -0
  3. package/lib/cjs/client/index.js +413 -0
  4. package/lib/cjs/client/index.js.map +1 -0
  5. package/lib/cjs/exact/client/index.d.ts +37 -0
  6. package/lib/cjs/exact/client/index.js +281 -0
  7. package/lib/cjs/exact/client/index.js.map +1 -0
  8. package/lib/cjs/exact/facilitator/index.d.ts +110 -0
  9. package/lib/cjs/exact/facilitator/index.js +714 -0
  10. package/lib/cjs/exact/facilitator/index.js.map +1 -0
  11. package/lib/cjs/exact/server/index.d.ts +87 -0
  12. package/lib/cjs/exact/server/index.js +209 -0
  13. package/lib/cjs/exact/server/index.js.map +1 -0
  14. package/lib/cjs/exact/v1/client/index.d.ts +33 -0
  15. package/lib/cjs/exact/v1/client/index.js +169 -0
  16. package/lib/cjs/exact/v1/client/index.js.map +1 -0
  17. package/lib/cjs/exact/v1/facilitator/index.d.ts +71 -0
  18. package/lib/cjs/exact/v1/facilitator/index.js +384 -0
  19. package/lib/cjs/exact/v1/facilitator/index.js.map +1 -0
  20. package/lib/cjs/facilitator/index.d.ts +192 -0
  21. package/lib/cjs/facilitator/index.js +398 -0
  22. package/lib/cjs/facilitator/index.js.map +1 -0
  23. package/lib/cjs/http/index.d.ts +52 -0
  24. package/lib/cjs/http/index.js +827 -0
  25. package/lib/cjs/http/index.js.map +1 -0
  26. package/lib/cjs/index.d.ts +145 -0
  27. package/lib/cjs/index.js +314 -0
  28. package/lib/cjs/index.js.map +1 -0
  29. package/lib/cjs/mechanisms-CzuGzYsS.d.ts +270 -0
  30. package/lib/cjs/scheme-MoBRXFM8.d.ts +29 -0
  31. package/lib/cjs/server/index.d.ts +2 -0
  32. package/lib/cjs/server/index.js +1305 -0
  33. package/lib/cjs/server/index.js.map +1 -0
  34. package/lib/cjs/signer-5OVDxViv.d.ts +79 -0
  35. package/lib/cjs/signer-BMkbhFYE.d.ts +123 -0
  36. package/lib/cjs/types/index.d.ts +1 -0
  37. package/lib/cjs/types/index.js +66 -0
  38. package/lib/cjs/types/index.js.map +1 -0
  39. package/lib/cjs/types/v1/index.d.ts +1 -0
  40. package/lib/cjs/types/v1/index.js +19 -0
  41. package/lib/cjs/types/v1/index.js.map +1 -0
  42. package/lib/cjs/utils/index.d.ts +48 -0
  43. package/lib/cjs/utils/index.js +116 -0
  44. package/lib/cjs/utils/index.js.map +1 -0
  45. package/lib/cjs/v1/index.d.ts +12 -0
  46. package/lib/cjs/v1/index.js +180 -0
  47. package/lib/cjs/v1/index.js.map +1 -0
  48. package/lib/cjs/x402HTTPResourceServer-D1YtlH_r.d.ts +719 -0
  49. package/lib/esm/chunk-3CEIVWNN.mjs +339 -0
  50. package/lib/esm/chunk-3CEIVWNN.mjs.map +1 -0
  51. package/lib/esm/chunk-BJTO5JO5.mjs +11 -0
  52. package/lib/esm/chunk-BJTO5JO5.mjs.map +1 -0
  53. package/lib/esm/chunk-EEA7DKZI.mjs +111 -0
  54. package/lib/esm/chunk-EEA7DKZI.mjs.map +1 -0
  55. package/lib/esm/chunk-FOUXRQAV.mjs +88 -0
  56. package/lib/esm/chunk-FOUXRQAV.mjs.map +1 -0
  57. package/lib/esm/chunk-IKSTWKEM.mjs +157 -0
  58. package/lib/esm/chunk-IKSTWKEM.mjs.map +1 -0
  59. package/lib/esm/chunk-JYZWCLMP.mjs +305 -0
  60. package/lib/esm/chunk-JYZWCLMP.mjs.map +1 -0
  61. package/lib/esm/chunk-PNSAJQCF.mjs +108 -0
  62. package/lib/esm/chunk-PNSAJQCF.mjs.map +1 -0
  63. package/lib/esm/chunk-PSA4YVU2.mjs +92 -0
  64. package/lib/esm/chunk-PSA4YVU2.mjs.map +1 -0
  65. package/lib/esm/chunk-QLXM7BIB.mjs +23 -0
  66. package/lib/esm/chunk-QLXM7BIB.mjs.map +1 -0
  67. package/lib/esm/chunk-TDLQZ6MP.mjs +86 -0
  68. package/lib/esm/chunk-TDLQZ6MP.mjs.map +1 -0
  69. package/lib/esm/chunk-VE37GDG2.mjs +7 -0
  70. package/lib/esm/chunk-VE37GDG2.mjs.map +1 -0
  71. package/lib/esm/chunk-WWACQNRQ.mjs +7 -0
  72. package/lib/esm/chunk-WWACQNRQ.mjs.map +1 -0
  73. package/lib/esm/chunk-X4W4S5RB.mjs +39 -0
  74. package/lib/esm/chunk-X4W4S5RB.mjs.map +1 -0
  75. package/lib/esm/chunk-Z4QX3O5V.mjs +748 -0
  76. package/lib/esm/chunk-Z4QX3O5V.mjs.map +1 -0
  77. package/lib/esm/chunk-ZYXTTU74.mjs +88 -0
  78. package/lib/esm/chunk-ZYXTTU74.mjs.map +1 -0
  79. package/lib/esm/client/index.d.mts +243 -0
  80. package/lib/esm/client/index.mjs +260 -0
  81. package/lib/esm/client/index.mjs.map +1 -0
  82. package/lib/esm/exact/client/index.d.mts +37 -0
  83. package/lib/esm/exact/client/index.mjs +36 -0
  84. package/lib/esm/exact/client/index.mjs.map +1 -0
  85. package/lib/esm/exact/facilitator/index.d.mts +110 -0
  86. package/lib/esm/exact/facilitator/index.mjs +350 -0
  87. package/lib/esm/exact/facilitator/index.mjs.map +1 -0
  88. package/lib/esm/exact/server/index.d.mts +87 -0
  89. package/lib/esm/exact/server/index.mjs +129 -0
  90. package/lib/esm/exact/server/index.mjs.map +1 -0
  91. package/lib/esm/exact/v1/client/index.d.mts +33 -0
  92. package/lib/esm/exact/v1/client/index.mjs +8 -0
  93. package/lib/esm/exact/v1/client/index.mjs.map +1 -0
  94. package/lib/esm/exact/v1/facilitator/index.d.mts +71 -0
  95. package/lib/esm/exact/v1/facilitator/index.mjs +8 -0
  96. package/lib/esm/exact/v1/facilitator/index.mjs.map +1 -0
  97. package/lib/esm/facilitator/index.d.mts +192 -0
  98. package/lib/esm/facilitator/index.mjs +373 -0
  99. package/lib/esm/facilitator/index.mjs.map +1 -0
  100. package/lib/esm/http/index.d.mts +52 -0
  101. package/lib/esm/http/index.mjs +29 -0
  102. package/lib/esm/http/index.mjs.map +1 -0
  103. package/lib/esm/index.d.mts +145 -0
  104. package/lib/esm/index.mjs +277 -0
  105. package/lib/esm/index.mjs.map +1 -0
  106. package/lib/esm/mechanisms-CzuGzYsS.d.mts +270 -0
  107. package/lib/esm/scheme-fjF-9LhT.d.mts +29 -0
  108. package/lib/esm/server/index.d.mts +2 -0
  109. package/lib/esm/server/index.mjs +563 -0
  110. package/lib/esm/server/index.mjs.map +1 -0
  111. package/lib/esm/signer-5OVDxViv.d.mts +79 -0
  112. package/lib/esm/signer-BMkbhFYE.d.mts +123 -0
  113. package/lib/esm/types/index.d.mts +1 -0
  114. package/lib/esm/types/index.mjs +10 -0
  115. package/lib/esm/types/index.mjs.map +1 -0
  116. package/lib/esm/types/v1/index.d.mts +1 -0
  117. package/lib/esm/types/v1/index.mjs +1 -0
  118. package/lib/esm/types/v1/index.mjs.map +1 -0
  119. package/lib/esm/utils/index.d.mts +48 -0
  120. package/lib/esm/utils/index.mjs +20 -0
  121. package/lib/esm/utils/index.mjs.map +1 -0
  122. package/lib/esm/v1/index.d.mts +12 -0
  123. package/lib/esm/v1/index.mjs +13 -0
  124. package/lib/esm/v1/index.mjs.map +1 -0
  125. package/lib/esm/x402HTTPResourceServer-BIfIK5HS.d.mts +719 -0
  126. package/package.json +39 -0
  127. package/src/index.js +4 -0
@@ -0,0 +1,270 @@
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 };
@@ -0,0 +1,29 @@
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 };
@@ -0,0 +1,2 @@
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';