x402-core-mantle 2.1.1-mantle

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 (64) hide show
  1. package/README.md +293 -0
  2. package/dist/cjs/client/index.d.ts +243 -0
  3. package/dist/cjs/client/index.js +413 -0
  4. package/dist/cjs/client/index.js.map +1 -0
  5. package/dist/cjs/facilitator/index.d.ts +192 -0
  6. package/dist/cjs/facilitator/index.js +398 -0
  7. package/dist/cjs/facilitator/index.js.map +1 -0
  8. package/dist/cjs/http/index.d.ts +52 -0
  9. package/dist/cjs/http/index.js +827 -0
  10. package/dist/cjs/http/index.js.map +1 -0
  11. package/dist/cjs/index.d.ts +3 -0
  12. package/dist/cjs/index.js +31 -0
  13. package/dist/cjs/index.js.map +1 -0
  14. package/dist/cjs/mechanisms-CzuGzYsS.d.ts +270 -0
  15. package/dist/cjs/server/index.d.ts +2 -0
  16. package/dist/cjs/server/index.js +1305 -0
  17. package/dist/cjs/server/index.js.map +1 -0
  18. package/dist/cjs/types/index.d.ts +1 -0
  19. package/dist/cjs/types/index.js +66 -0
  20. package/dist/cjs/types/index.js.map +1 -0
  21. package/dist/cjs/types/v1/index.d.ts +1 -0
  22. package/dist/cjs/types/v1/index.js +19 -0
  23. package/dist/cjs/types/v1/index.js.map +1 -0
  24. package/dist/cjs/utils/index.d.ts +48 -0
  25. package/dist/cjs/utils/index.js +116 -0
  26. package/dist/cjs/utils/index.js.map +1 -0
  27. package/dist/cjs/x402HTTPResourceServer-D1YtlH_r.d.ts +719 -0
  28. package/dist/esm/chunk-BJTO5JO5.mjs +11 -0
  29. package/dist/esm/chunk-BJTO5JO5.mjs.map +1 -0
  30. package/dist/esm/chunk-TDLQZ6MP.mjs +86 -0
  31. package/dist/esm/chunk-TDLQZ6MP.mjs.map +1 -0
  32. package/dist/esm/chunk-VE37GDG2.mjs +7 -0
  33. package/dist/esm/chunk-VE37GDG2.mjs.map +1 -0
  34. package/dist/esm/chunk-X4W4S5RB.mjs +39 -0
  35. package/dist/esm/chunk-X4W4S5RB.mjs.map +1 -0
  36. package/dist/esm/chunk-Z4QX3O5V.mjs +748 -0
  37. package/dist/esm/chunk-Z4QX3O5V.mjs.map +1 -0
  38. package/dist/esm/client/index.d.mts +243 -0
  39. package/dist/esm/client/index.mjs +260 -0
  40. package/dist/esm/client/index.mjs.map +1 -0
  41. package/dist/esm/facilitator/index.d.mts +192 -0
  42. package/dist/esm/facilitator/index.mjs +373 -0
  43. package/dist/esm/facilitator/index.mjs.map +1 -0
  44. package/dist/esm/http/index.d.mts +52 -0
  45. package/dist/esm/http/index.mjs +29 -0
  46. package/dist/esm/http/index.mjs.map +1 -0
  47. package/dist/esm/index.d.mts +3 -0
  48. package/dist/esm/index.mjs +8 -0
  49. package/dist/esm/index.mjs.map +1 -0
  50. package/dist/esm/mechanisms-CzuGzYsS.d.mts +270 -0
  51. package/dist/esm/server/index.d.mts +2 -0
  52. package/dist/esm/server/index.mjs +563 -0
  53. package/dist/esm/server/index.mjs.map +1 -0
  54. package/dist/esm/types/index.d.mts +1 -0
  55. package/dist/esm/types/index.mjs +10 -0
  56. package/dist/esm/types/index.mjs.map +1 -0
  57. package/dist/esm/types/v1/index.d.mts +1 -0
  58. package/dist/esm/types/v1/index.mjs +1 -0
  59. package/dist/esm/types/v1/index.mjs.map +1 -0
  60. package/dist/esm/utils/index.d.mts +48 -0
  61. package/dist/esm/utils/index.mjs +20 -0
  62. package/dist/esm/utils/index.mjs.map +1 -0
  63. package/dist/esm/x402HTTPResourceServer-BIfIK5HS.d.mts +719 -0
  64. package/package.json +129 -0
@@ -0,0 +1,52 @@
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 };
@@ -0,0 +1,29 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,3 @@
1
+ declare const x402Version = 2;
2
+
3
+ export { x402Version };
@@ -0,0 +1,8 @@
1
+ import {
2
+ x402Version
3
+ } from "./chunk-VE37GDG2.mjs";
4
+ import "./chunk-BJTO5JO5.mjs";
5
+ export {
6
+ x402Version
7
+ };
8
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -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,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';