@faremeter/types 0.16.0 → 0.17.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/src/client.d.ts +66 -1
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +52 -1
- package/dist/src/evm.d.ts +18 -0
- package/dist/src/evm.d.ts.map +1 -1
- package/dist/src/evm.js +18 -0
- package/dist/src/facilitator.d.ts +25 -4
- package/dist/src/facilitator.d.ts.map +1 -1
- package/dist/src/facilitator.js +1 -1
- package/dist/src/index.d.ts +43 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +43 -0
- package/dist/src/literal.d.ts +8 -0
- package/dist/src/literal.d.ts.map +1 -1
- package/dist/src/literal.js +8 -0
- package/dist/src/solana.d.ts +58 -0
- package/dist/src/solana.d.ts.map +1 -1
- package/dist/src/solana.js +70 -0
- package/dist/src/validation.d.ts +13 -0
- package/dist/src/validation.d.ts.map +1 -1
- package/dist/src/validation.js +13 -0
- package/dist/src/x402-adapters.d.ts +130 -0
- package/dist/src/x402-adapters.d.ts.map +1 -0
- package/dist/src/x402-adapters.js +297 -0
- package/dist/src/x402-adapters.test.d.ts +3 -0
- package/dist/src/x402-adapters.test.d.ts.map +1 -0
- package/dist/src/x402-adapters.test.js +912 -0
- package/dist/src/x402.d.ts +113 -9
- package/dist/src/x402.d.ts.map +1 -1
- package/dist/src/x402.js +121 -4
- package/dist/src/x402v2.d.ts +190 -0
- package/dist/src/x402v2.d.ts.map +1 -0
- package/dist/src/x402v2.js +81 -0
- package/dist/src/x402v2.test.d.ts +3 -0
- package/dist/src/x402v2.test.d.ts.map +1 -0
- package/dist/src/x402v2.test.js +63 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -1
package/dist/src/x402.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP header name for v1 client payment payloads.
|
|
3
|
+
*/
|
|
4
|
+
export declare const X_PAYMENT_HEADER = "X-PAYMENT";
|
|
5
|
+
/**
|
|
6
|
+
* HTTP header name for v1 server payment responses.
|
|
7
|
+
*/
|
|
8
|
+
export declare const X_PAYMENT_RESPONSE_HEADER = "X-PAYMENT-RESPONSE";
|
|
1
9
|
export declare const x402PaymentId: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
2
10
|
scheme: string;
|
|
3
11
|
network: string;
|
|
@@ -10,10 +18,10 @@ export declare const x402PaymentRequirements: import("arktype/internal/methods/o
|
|
|
10
18
|
maxAmountRequired: string;
|
|
11
19
|
resource: string;
|
|
12
20
|
description: string;
|
|
13
|
-
mimeType: string;
|
|
14
21
|
payTo: string;
|
|
15
22
|
maxTimeoutSeconds: number;
|
|
16
23
|
asset: string;
|
|
24
|
+
mimeType?: string;
|
|
17
25
|
outputSchema?: object;
|
|
18
26
|
extra?: object;
|
|
19
27
|
}, {}>;
|
|
@@ -26,16 +34,44 @@ export declare const x402PaymentRequiredResponse: import("arktype/internal/metho
|
|
|
26
34
|
maxAmountRequired: string;
|
|
27
35
|
resource: string;
|
|
28
36
|
description: string;
|
|
29
|
-
mimeType: string;
|
|
30
37
|
payTo: string;
|
|
31
38
|
maxTimeoutSeconds: number;
|
|
32
39
|
asset: string;
|
|
40
|
+
mimeType?: string;
|
|
33
41
|
outputSchema?: object;
|
|
34
42
|
extra?: object;
|
|
35
43
|
}[];
|
|
36
|
-
error
|
|
44
|
+
error: string;
|
|
37
45
|
}, {}>;
|
|
38
46
|
export type x402PaymentRequiredResponse = typeof x402PaymentRequiredResponse.infer;
|
|
47
|
+
/**
|
|
48
|
+
* Lenient payment required response parser that accepts optional error field.
|
|
49
|
+
* Use this when parsing incoming data from older servers that may not include
|
|
50
|
+
* the error field.
|
|
51
|
+
*/
|
|
52
|
+
export declare const x402PaymentRequiredResponseLenient: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
53
|
+
x402Version: number;
|
|
54
|
+
accepts: {
|
|
55
|
+
scheme: string;
|
|
56
|
+
network: string;
|
|
57
|
+
maxAmountRequired: string;
|
|
58
|
+
resource: string;
|
|
59
|
+
description: string;
|
|
60
|
+
payTo: string;
|
|
61
|
+
maxTimeoutSeconds: number;
|
|
62
|
+
asset: string;
|
|
63
|
+
mimeType?: string;
|
|
64
|
+
outputSchema?: object;
|
|
65
|
+
extra?: object;
|
|
66
|
+
}[];
|
|
67
|
+
error?: string;
|
|
68
|
+
}, {}>;
|
|
69
|
+
export type x402PaymentRequiredResponseLenient = typeof x402PaymentRequiredResponseLenient.infer;
|
|
70
|
+
/**
|
|
71
|
+
* Normalize a lenient payment required response to spec-compliant field values.
|
|
72
|
+
* Defaults error to empty string when missing.
|
|
73
|
+
*/
|
|
74
|
+
export declare function normalizePaymentRequiredResponse(res: x402PaymentRequiredResponseLenient): x402PaymentRequiredResponse;
|
|
39
75
|
export declare const x402PaymentPayload: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
40
76
|
x402Version: number;
|
|
41
77
|
scheme: string;
|
|
@@ -52,17 +88,16 @@ export declare const x402PaymentHeaderToPayload: import("arktype/internal/method
|
|
|
52
88
|
asset?: string;
|
|
53
89
|
}>, {}>;
|
|
54
90
|
export declare const x402VerifyRequest: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
55
|
-
x402Version: number;
|
|
56
91
|
paymentRequirements: {
|
|
57
92
|
scheme: string;
|
|
58
93
|
network: string;
|
|
59
94
|
maxAmountRequired: string;
|
|
60
95
|
resource: string;
|
|
61
96
|
description: string;
|
|
62
|
-
mimeType: string;
|
|
63
97
|
payTo: string;
|
|
64
98
|
maxTimeoutSeconds: number;
|
|
65
99
|
asset: string;
|
|
100
|
+
mimeType?: string;
|
|
66
101
|
outputSchema?: object;
|
|
67
102
|
extra?: object;
|
|
68
103
|
};
|
|
@@ -78,21 +113,37 @@ export declare const x402VerifyRequest: import("arktype/internal/methods/object.
|
|
|
78
113
|
export type x402VerifyRequest = typeof x402VerifyRequest.infer;
|
|
79
114
|
export declare const x402VerifyResponse: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
80
115
|
isValid: boolean;
|
|
81
|
-
|
|
116
|
+
payer: string;
|
|
117
|
+
invalidReason?: string;
|
|
82
118
|
}, {}>;
|
|
83
119
|
export type x402VerifyResponse = typeof x402VerifyResponse.infer;
|
|
120
|
+
/**
|
|
121
|
+
* Lenient verify response parser that accepts optional payer field.
|
|
122
|
+
* Use this when parsing incoming data from older facilitators that may
|
|
123
|
+
* not include the payer field.
|
|
124
|
+
*/
|
|
125
|
+
export declare const x402VerifyResponseLenient: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
126
|
+
isValid: boolean;
|
|
127
|
+
invalidReason?: string | null;
|
|
128
|
+
payer?: string;
|
|
129
|
+
}, {}>;
|
|
130
|
+
export type x402VerifyResponseLenient = typeof x402VerifyResponseLenient.infer;
|
|
131
|
+
/**
|
|
132
|
+
* Normalize a lenient verify response to spec-compliant field values.
|
|
133
|
+
* Defaults payer to empty string and strips null from invalidReason.
|
|
134
|
+
*/
|
|
135
|
+
export declare function normalizeVerifyResponse(res: x402VerifyResponseLenient): x402VerifyResponse;
|
|
84
136
|
export declare const x402SettleRequest: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
85
|
-
x402Version: number;
|
|
86
137
|
paymentRequirements: {
|
|
87
138
|
scheme: string;
|
|
88
139
|
network: string;
|
|
89
140
|
maxAmountRequired: string;
|
|
90
141
|
resource: string;
|
|
91
142
|
description: string;
|
|
92
|
-
mimeType: string;
|
|
93
143
|
payTo: string;
|
|
94
144
|
maxTimeoutSeconds: number;
|
|
95
145
|
asset: string;
|
|
146
|
+
mimeType?: string;
|
|
96
147
|
outputSchema?: object;
|
|
97
148
|
extra?: object;
|
|
98
149
|
};
|
|
@@ -106,13 +157,55 @@ export declare const x402SettleRequest: import("arktype/internal/methods/object.
|
|
|
106
157
|
};
|
|
107
158
|
}, {}>;
|
|
108
159
|
export type x402SettleRequest = typeof x402SettleRequest.infer;
|
|
109
|
-
|
|
160
|
+
/**
|
|
161
|
+
* Legacy settle response type with pre-spec field names (txHash, networkId, error).
|
|
162
|
+
* Use x402SettleResponse for spec-compliant field names (transaction, network, errorReason).
|
|
163
|
+
*
|
|
164
|
+
* This type exists for backward compatibility when interfacing with older clients
|
|
165
|
+
* that use legacy field names.
|
|
166
|
+
*/
|
|
167
|
+
export declare const x402SettleResponseLegacy: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
110
168
|
success: boolean;
|
|
111
169
|
txHash: string | null;
|
|
112
170
|
networkId: string | null;
|
|
113
171
|
error?: string | null;
|
|
172
|
+
payer?: string;
|
|
173
|
+
}, {}>;
|
|
174
|
+
export type x402SettleResponseLegacy = typeof x402SettleResponseLegacy.infer;
|
|
175
|
+
/**
|
|
176
|
+
* Spec-compliant settle response per x402-specification-v1.md Section 5.3.
|
|
177
|
+
* Field names: transaction, network, errorReason (not txHash, networkId, error)
|
|
178
|
+
*/
|
|
179
|
+
export declare const x402SettleResponse: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
180
|
+
success: boolean;
|
|
181
|
+
transaction: string;
|
|
182
|
+
network: string;
|
|
183
|
+
payer: string;
|
|
184
|
+
errorReason?: string;
|
|
114
185
|
}, {}>;
|
|
115
186
|
export type x402SettleResponse = typeof x402SettleResponse.infer;
|
|
187
|
+
/**
|
|
188
|
+
* Lenient settle response parser that accepts either legacy or spec-compliant
|
|
189
|
+
* field names. Use this when parsing incoming data that may come from older
|
|
190
|
+
* clients using legacy field names.
|
|
191
|
+
*/
|
|
192
|
+
export declare const x402SettleResponseLenient: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
193
|
+
success: boolean;
|
|
194
|
+
errorReason?: string | null;
|
|
195
|
+
error?: string | null;
|
|
196
|
+
transaction?: string | null;
|
|
197
|
+
txHash?: string | null;
|
|
198
|
+
network?: string | null;
|
|
199
|
+
networkId?: string | null;
|
|
200
|
+
payer?: string;
|
|
201
|
+
}, {}>;
|
|
202
|
+
export type x402SettleResponseLenient = typeof x402SettleResponseLenient.infer;
|
|
203
|
+
/**
|
|
204
|
+
* Normalize a lenient settle response to spec-compliant field names.
|
|
205
|
+
* Converts legacy field names (txHash, networkId, error) to spec-compliant
|
|
206
|
+
* names (transaction, network, errorReason).
|
|
207
|
+
*/
|
|
208
|
+
export declare function normalizeSettleResponse(res: x402SettleResponseLenient): x402SettleResponse;
|
|
116
209
|
export declare const x402SupportedKind: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
117
210
|
x402Version: number;
|
|
118
211
|
scheme: string;
|
|
@@ -129,6 +222,17 @@ export declare const x402SupportedResponse: import("arktype/internal/methods/obj
|
|
|
129
222
|
}[];
|
|
130
223
|
}, {}>;
|
|
131
224
|
export type x402SupportedResponse = typeof x402SupportedResponse.infer;
|
|
225
|
+
/**
|
|
226
|
+
* Creates a matcher function for filtering payment requirements.
|
|
227
|
+
*
|
|
228
|
+
* The matcher performs case-insensitive matching on scheme, network,
|
|
229
|
+
* and asset fields.
|
|
230
|
+
*
|
|
231
|
+
* @param scheme - Accepted payment scheme names
|
|
232
|
+
* @param network - Accepted network identifiers
|
|
233
|
+
* @param asset - Accepted asset addresses
|
|
234
|
+
* @returns Object with the matcher tuple and isMatchingRequirement function
|
|
235
|
+
*/
|
|
132
236
|
export declare function generateRequirementsMatcher(scheme: string[], network: string[], asset: string[]): {
|
|
133
237
|
matchTuple: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
134
238
|
scheme: (In: string) => import("arktype/internal/attributes.ts").To<Lowercase<string>>;
|
package/dist/src/x402.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"x402.d.ts","sourceRoot":"","sources":["../../src/x402.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa;;;;MAIxB,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC,KAAK,CAAC;AAEvD,eAAO,MAAM,uBAAuB;;;;;;;;;;;;MAYlC,CAAC;AAEH,MAAM,MAAM,uBAAuB,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MAAM,MAAM,qBAAqB,GAAG,OAAO,qBAAqB,CAAC,KAAK,CAAC;AAEvE;;;;;;;;;;GAUG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,EAAE,MAAM,EAAE,EACjB,KAAK,EAAE,MAAM,EAAE;;;;;;;;;;;EAgBhB"}
|
package/dist/src/x402.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { type } from "arktype";
|
|
2
2
|
import { caseInsensitiveLiteral } from "./literal.js";
|
|
3
3
|
import { isValidationError } from "./validation.js";
|
|
4
|
+
/**
|
|
5
|
+
* HTTP header name for v1 client payment payloads.
|
|
6
|
+
*/
|
|
7
|
+
export const X_PAYMENT_HEADER = "X-PAYMENT";
|
|
8
|
+
/**
|
|
9
|
+
* HTTP header name for v1 server payment responses.
|
|
10
|
+
*/
|
|
11
|
+
export const X_PAYMENT_RESPONSE_HEADER = "X-PAYMENT-RESPONSE";
|
|
4
12
|
export const x402PaymentId = type({
|
|
5
13
|
scheme: "string",
|
|
6
14
|
network: "string",
|
|
@@ -12,7 +20,7 @@ export const x402PaymentRequirements = type({
|
|
|
12
20
|
maxAmountRequired: "string.numeric",
|
|
13
21
|
resource: "string.url",
|
|
14
22
|
description: "string",
|
|
15
|
-
mimeType: "string",
|
|
23
|
+
"mimeType?": "string",
|
|
16
24
|
outputSchema: "object?",
|
|
17
25
|
payTo: "string",
|
|
18
26
|
maxTimeoutSeconds: "number.integer",
|
|
@@ -22,8 +30,29 @@ export const x402PaymentRequirements = type({
|
|
|
22
30
|
export const x402PaymentRequiredResponse = type({
|
|
23
31
|
x402Version: "number.integer",
|
|
24
32
|
accepts: x402PaymentRequirements.array(),
|
|
25
|
-
error: "string
|
|
33
|
+
error: "string",
|
|
26
34
|
});
|
|
35
|
+
/**
|
|
36
|
+
* Lenient payment required response parser that accepts optional error field.
|
|
37
|
+
* Use this when parsing incoming data from older servers that may not include
|
|
38
|
+
* the error field.
|
|
39
|
+
*/
|
|
40
|
+
export const x402PaymentRequiredResponseLenient = type({
|
|
41
|
+
x402Version: "number.integer",
|
|
42
|
+
accepts: x402PaymentRequirements.array(),
|
|
43
|
+
"error?": "string",
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* Normalize a lenient payment required response to spec-compliant field values.
|
|
47
|
+
* Defaults error to empty string when missing.
|
|
48
|
+
*/
|
|
49
|
+
export function normalizePaymentRequiredResponse(res) {
|
|
50
|
+
return {
|
|
51
|
+
x402Version: res.x402Version,
|
|
52
|
+
accepts: res.accepts,
|
|
53
|
+
error: res.error ?? "",
|
|
54
|
+
};
|
|
55
|
+
}
|
|
27
56
|
export const x402PaymentPayload = type({
|
|
28
57
|
x402Version: "number.integer",
|
|
29
58
|
scheme: "string",
|
|
@@ -36,22 +65,99 @@ export const x402PaymentHeaderToPayload = type("string.base64")
|
|
|
36
65
|
.to("string.json.parse")
|
|
37
66
|
.to(x402PaymentPayload);
|
|
38
67
|
export const x402VerifyRequest = type({
|
|
39
|
-
x402Version: "number.integer",
|
|
40
68
|
paymentHeader: "string?",
|
|
41
69
|
paymentPayload: x402PaymentPayload.optional(),
|
|
42
70
|
paymentRequirements: x402PaymentRequirements,
|
|
43
71
|
});
|
|
44
72
|
export const x402VerifyResponse = type({
|
|
73
|
+
isValid: "boolean",
|
|
74
|
+
"invalidReason?": "string",
|
|
75
|
+
payer: "string",
|
|
76
|
+
});
|
|
77
|
+
/**
|
|
78
|
+
* Lenient verify response parser that accepts optional payer field.
|
|
79
|
+
* Use this when parsing incoming data from older facilitators that may
|
|
80
|
+
* not include the payer field.
|
|
81
|
+
*/
|
|
82
|
+
export const x402VerifyResponseLenient = type({
|
|
45
83
|
isValid: "boolean",
|
|
46
84
|
"invalidReason?": "string | null",
|
|
85
|
+
"payer?": "string",
|
|
47
86
|
});
|
|
87
|
+
/**
|
|
88
|
+
* Normalize a lenient verify response to spec-compliant field values.
|
|
89
|
+
* Defaults payer to empty string and strips null from invalidReason.
|
|
90
|
+
*/
|
|
91
|
+
export function normalizeVerifyResponse(res) {
|
|
92
|
+
const result = {
|
|
93
|
+
isValid: res.isValid,
|
|
94
|
+
payer: res.payer ?? "",
|
|
95
|
+
};
|
|
96
|
+
const invalidReason = res.invalidReason;
|
|
97
|
+
if (invalidReason !== undefined && invalidReason !== null) {
|
|
98
|
+
result.invalidReason = invalidReason;
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
48
102
|
export const x402SettleRequest = x402VerifyRequest;
|
|
49
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Legacy settle response type with pre-spec field names (txHash, networkId, error).
|
|
105
|
+
* Use x402SettleResponse for spec-compliant field names (transaction, network, errorReason).
|
|
106
|
+
*
|
|
107
|
+
* This type exists for backward compatibility when interfacing with older clients
|
|
108
|
+
* that use legacy field names.
|
|
109
|
+
*/
|
|
110
|
+
export const x402SettleResponseLegacy = type({
|
|
50
111
|
success: "boolean",
|
|
51
112
|
"error?": "string | null",
|
|
52
113
|
txHash: "string | null",
|
|
53
114
|
networkId: "string | null",
|
|
115
|
+
"payer?": "string",
|
|
116
|
+
});
|
|
117
|
+
/**
|
|
118
|
+
* Spec-compliant settle response per x402-specification-v1.md Section 5.3.
|
|
119
|
+
* Field names: transaction, network, errorReason (not txHash, networkId, error)
|
|
120
|
+
*/
|
|
121
|
+
export const x402SettleResponse = type({
|
|
122
|
+
success: "boolean",
|
|
123
|
+
"errorReason?": "string",
|
|
124
|
+
transaction: "string",
|
|
125
|
+
network: "string",
|
|
126
|
+
payer: "string",
|
|
54
127
|
});
|
|
128
|
+
/**
|
|
129
|
+
* Lenient settle response parser that accepts either legacy or spec-compliant
|
|
130
|
+
* field names. Use this when parsing incoming data that may come from older
|
|
131
|
+
* clients using legacy field names.
|
|
132
|
+
*/
|
|
133
|
+
export const x402SettleResponseLenient = type({
|
|
134
|
+
success: "boolean",
|
|
135
|
+
"errorReason?": "string | null",
|
|
136
|
+
"error?": "string | null",
|
|
137
|
+
"transaction?": "string | null",
|
|
138
|
+
"txHash?": "string | null",
|
|
139
|
+
"network?": "string | null",
|
|
140
|
+
"networkId?": "string | null",
|
|
141
|
+
"payer?": "string",
|
|
142
|
+
});
|
|
143
|
+
/**
|
|
144
|
+
* Normalize a lenient settle response to spec-compliant field names.
|
|
145
|
+
* Converts legacy field names (txHash, networkId, error) to spec-compliant
|
|
146
|
+
* names (transaction, network, errorReason).
|
|
147
|
+
*/
|
|
148
|
+
export function normalizeSettleResponse(res) {
|
|
149
|
+
const result = {
|
|
150
|
+
success: res.success,
|
|
151
|
+
transaction: res.transaction ?? res.txHash ?? "",
|
|
152
|
+
network: res.network ?? res.networkId ?? "",
|
|
153
|
+
payer: res.payer ?? "",
|
|
154
|
+
};
|
|
155
|
+
const errorReason = res.errorReason ?? res.error;
|
|
156
|
+
if (errorReason !== undefined && errorReason !== null) {
|
|
157
|
+
result.errorReason = errorReason;
|
|
158
|
+
}
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
55
161
|
export const x402SupportedKind = type({
|
|
56
162
|
x402Version: "number.integer",
|
|
57
163
|
scheme: "string",
|
|
@@ -61,6 +167,17 @@ export const x402SupportedKind = type({
|
|
|
61
167
|
export const x402SupportedResponse = type({
|
|
62
168
|
kinds: x402SupportedKind.array(),
|
|
63
169
|
});
|
|
170
|
+
/**
|
|
171
|
+
* Creates a matcher function for filtering payment requirements.
|
|
172
|
+
*
|
|
173
|
+
* The matcher performs case-insensitive matching on scheme, network,
|
|
174
|
+
* and asset fields.
|
|
175
|
+
*
|
|
176
|
+
* @param scheme - Accepted payment scheme names
|
|
177
|
+
* @param network - Accepted network identifiers
|
|
178
|
+
* @param asset - Accepted asset addresses
|
|
179
|
+
* @returns Object with the matcher tuple and isMatchingRequirement function
|
|
180
|
+
*/
|
|
64
181
|
export function generateRequirementsMatcher(scheme, network, asset) {
|
|
65
182
|
const matchTuple = type({
|
|
66
183
|
scheme: caseInsensitiveLiteral(...scheme),
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP header name for v2 client payment signatures.
|
|
3
|
+
*/
|
|
4
|
+
export declare const V2_PAYMENT_HEADER = "PAYMENT-SIGNATURE";
|
|
5
|
+
/**
|
|
6
|
+
* HTTP header name for v2 402 payment required responses.
|
|
7
|
+
*/
|
|
8
|
+
export declare const V2_PAYMENT_REQUIRED_HEADER = "PAYMENT-REQUIRED";
|
|
9
|
+
/**
|
|
10
|
+
* HTTP header name for v2 server payment responses.
|
|
11
|
+
*/
|
|
12
|
+
export declare const V2_PAYMENT_RESPONSE_HEADER = "PAYMENT-RESPONSE";
|
|
13
|
+
export declare const x402ResourceInfo: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
14
|
+
url: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
mimeType?: string;
|
|
17
|
+
}, {}>;
|
|
18
|
+
export type x402ResourceInfo = typeof x402ResourceInfo.infer;
|
|
19
|
+
export declare const x402PaymentRequirements: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
20
|
+
scheme: string;
|
|
21
|
+
network: string;
|
|
22
|
+
amount: string;
|
|
23
|
+
asset: string;
|
|
24
|
+
payTo: string;
|
|
25
|
+
maxTimeoutSeconds: number;
|
|
26
|
+
extra?: object;
|
|
27
|
+
}, {}>;
|
|
28
|
+
export type x402PaymentRequirements = typeof x402PaymentRequirements.infer;
|
|
29
|
+
export declare const x402PaymentRequiredResponse: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
30
|
+
x402Version: 2;
|
|
31
|
+
resource: {
|
|
32
|
+
url: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
mimeType?: string;
|
|
35
|
+
};
|
|
36
|
+
accepts: {
|
|
37
|
+
scheme: string;
|
|
38
|
+
network: string;
|
|
39
|
+
amount: string;
|
|
40
|
+
asset: string;
|
|
41
|
+
payTo: string;
|
|
42
|
+
maxTimeoutSeconds: number;
|
|
43
|
+
extra?: object;
|
|
44
|
+
}[];
|
|
45
|
+
error?: string;
|
|
46
|
+
extensions?: object;
|
|
47
|
+
}, {}>;
|
|
48
|
+
export type x402PaymentRequiredResponse = typeof x402PaymentRequiredResponse.infer;
|
|
49
|
+
export declare const x402PaymentPayload: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
50
|
+
x402Version: 2;
|
|
51
|
+
accepted: {
|
|
52
|
+
scheme: string;
|
|
53
|
+
network: string;
|
|
54
|
+
amount: string;
|
|
55
|
+
asset: string;
|
|
56
|
+
payTo: string;
|
|
57
|
+
maxTimeoutSeconds: number;
|
|
58
|
+
extra?: object;
|
|
59
|
+
};
|
|
60
|
+
payload: object;
|
|
61
|
+
resource?: {
|
|
62
|
+
url: string;
|
|
63
|
+
description?: string;
|
|
64
|
+
mimeType?: string;
|
|
65
|
+
};
|
|
66
|
+
extensions?: object;
|
|
67
|
+
}, {}>;
|
|
68
|
+
export type x402PaymentPayload = typeof x402PaymentPayload.infer;
|
|
69
|
+
export declare const x402PaymentHeaderToPayload: import("arktype/internal/methods/object.ts").ObjectType<(In: string) => import("arktype/internal/attributes.ts").To<{
|
|
70
|
+
x402Version: 2;
|
|
71
|
+
accepted: {
|
|
72
|
+
scheme: string;
|
|
73
|
+
network: string;
|
|
74
|
+
amount: string;
|
|
75
|
+
asset: string;
|
|
76
|
+
payTo: string;
|
|
77
|
+
maxTimeoutSeconds: number;
|
|
78
|
+
extra?: object;
|
|
79
|
+
};
|
|
80
|
+
payload: object;
|
|
81
|
+
resource?: {
|
|
82
|
+
url: string;
|
|
83
|
+
description?: string;
|
|
84
|
+
mimeType?: string;
|
|
85
|
+
};
|
|
86
|
+
extensions?: object;
|
|
87
|
+
}>, {}>;
|
|
88
|
+
export declare const x402VerifyRequest: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
89
|
+
paymentPayload: {
|
|
90
|
+
x402Version: 2;
|
|
91
|
+
accepted: {
|
|
92
|
+
scheme: string;
|
|
93
|
+
network: string;
|
|
94
|
+
amount: string;
|
|
95
|
+
asset: string;
|
|
96
|
+
payTo: string;
|
|
97
|
+
maxTimeoutSeconds: number;
|
|
98
|
+
extra?: object;
|
|
99
|
+
};
|
|
100
|
+
payload: object;
|
|
101
|
+
resource?: {
|
|
102
|
+
url: string;
|
|
103
|
+
description?: string;
|
|
104
|
+
mimeType?: string;
|
|
105
|
+
};
|
|
106
|
+
extensions?: object;
|
|
107
|
+
};
|
|
108
|
+
paymentRequirements: {
|
|
109
|
+
scheme: string;
|
|
110
|
+
network: string;
|
|
111
|
+
amount: string;
|
|
112
|
+
asset: string;
|
|
113
|
+
payTo: string;
|
|
114
|
+
maxTimeoutSeconds: number;
|
|
115
|
+
extra?: object;
|
|
116
|
+
};
|
|
117
|
+
}, {}>;
|
|
118
|
+
export type x402VerifyRequest = typeof x402VerifyRequest.infer;
|
|
119
|
+
export declare const x402VerifyResponse: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
120
|
+
isValid: boolean;
|
|
121
|
+
invalidReason?: string;
|
|
122
|
+
payer?: string;
|
|
123
|
+
}, {}>;
|
|
124
|
+
export type x402VerifyResponse = typeof x402VerifyResponse.infer;
|
|
125
|
+
export declare const x402SettleRequest: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
126
|
+
paymentPayload: {
|
|
127
|
+
x402Version: 2;
|
|
128
|
+
accepted: {
|
|
129
|
+
scheme: string;
|
|
130
|
+
network: string;
|
|
131
|
+
amount: string;
|
|
132
|
+
asset: string;
|
|
133
|
+
payTo: string;
|
|
134
|
+
maxTimeoutSeconds: number;
|
|
135
|
+
extra?: object;
|
|
136
|
+
};
|
|
137
|
+
payload: object;
|
|
138
|
+
resource?: {
|
|
139
|
+
url: string;
|
|
140
|
+
description?: string;
|
|
141
|
+
mimeType?: string;
|
|
142
|
+
};
|
|
143
|
+
extensions?: object;
|
|
144
|
+
};
|
|
145
|
+
paymentRequirements: {
|
|
146
|
+
scheme: string;
|
|
147
|
+
network: string;
|
|
148
|
+
amount: string;
|
|
149
|
+
asset: string;
|
|
150
|
+
payTo: string;
|
|
151
|
+
maxTimeoutSeconds: number;
|
|
152
|
+
extra?: object;
|
|
153
|
+
};
|
|
154
|
+
}, {}>;
|
|
155
|
+
export type x402SettleRequest = typeof x402SettleRequest.infer;
|
|
156
|
+
export declare const x402SettleResponse: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
157
|
+
success: boolean;
|
|
158
|
+
transaction: string;
|
|
159
|
+
network: string;
|
|
160
|
+
errorReason?: string;
|
|
161
|
+
payer?: string;
|
|
162
|
+
extensions?: object;
|
|
163
|
+
}, {}>;
|
|
164
|
+
export type x402SettleResponse = typeof x402SettleResponse.infer;
|
|
165
|
+
export declare const x402SupportedKind: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
166
|
+
x402Version: 2;
|
|
167
|
+
scheme: string;
|
|
168
|
+
network: string;
|
|
169
|
+
extra?: object;
|
|
170
|
+
}, {}>;
|
|
171
|
+
export type x402SupportedKind = typeof x402SupportedKind.infer;
|
|
172
|
+
export declare const x402SupportedKindAny: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
173
|
+
x402Version: 1 | 2;
|
|
174
|
+
scheme: string;
|
|
175
|
+
network: string;
|
|
176
|
+
extra?: object;
|
|
177
|
+
}, {}>;
|
|
178
|
+
export type x402SupportedKindAny = typeof x402SupportedKindAny.infer;
|
|
179
|
+
export declare const x402SupportedResponse: import("arktype/internal/methods/object.ts").ObjectType<{
|
|
180
|
+
kinds: {
|
|
181
|
+
x402Version: 1 | 2;
|
|
182
|
+
scheme: string;
|
|
183
|
+
network: string;
|
|
184
|
+
extra?: object;
|
|
185
|
+
}[];
|
|
186
|
+
extensions: string[];
|
|
187
|
+
signers: Record<string, string[]>;
|
|
188
|
+
}, {}>;
|
|
189
|
+
export type x402SupportedResponse = typeof x402SupportedResponse.infer;
|
|
190
|
+
//# sourceMappingURL=x402v2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402v2.d.ts","sourceRoot":"","sources":["../../src/x402v2.ts"],"names":[],"m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;;;MAK5B,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,OAAO,iBAAiB,CAAC,KAAK,CAAC;AAG/D,eAAO,MAAM,oBAAoB;;;;;MAK/B,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,OAAO,oBAAoB,CAAC,KAAK,CAAC;AAErE,eAAO,MAAM,qBAAqB;;;;;;;;;MAIhC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,OAAO,qBAAqB,CAAC,KAAK,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type } from "arktype";
|
|
2
|
+
/**
|
|
3
|
+
* HTTP header name for v2 client payment signatures.
|
|
4
|
+
*/
|
|
5
|
+
export const V2_PAYMENT_HEADER = "PAYMENT-SIGNATURE";
|
|
6
|
+
/**
|
|
7
|
+
* HTTP header name for v2 402 payment required responses.
|
|
8
|
+
*/
|
|
9
|
+
export const V2_PAYMENT_REQUIRED_HEADER = "PAYMENT-REQUIRED";
|
|
10
|
+
/**
|
|
11
|
+
* HTTP header name for v2 server payment responses.
|
|
12
|
+
*/
|
|
13
|
+
export const V2_PAYMENT_RESPONSE_HEADER = "PAYMENT-RESPONSE";
|
|
14
|
+
export const x402ResourceInfo = type({
|
|
15
|
+
url: "string",
|
|
16
|
+
"description?": "string",
|
|
17
|
+
"mimeType?": "string",
|
|
18
|
+
});
|
|
19
|
+
export const x402PaymentRequirements = type({
|
|
20
|
+
scheme: "string",
|
|
21
|
+
network: "string",
|
|
22
|
+
amount: "string.numeric",
|
|
23
|
+
asset: "string",
|
|
24
|
+
payTo: "string",
|
|
25
|
+
maxTimeoutSeconds: "number.integer",
|
|
26
|
+
"extra?": "object",
|
|
27
|
+
});
|
|
28
|
+
export const x402PaymentRequiredResponse = type({
|
|
29
|
+
x402Version: "2",
|
|
30
|
+
"error?": "string",
|
|
31
|
+
resource: x402ResourceInfo,
|
|
32
|
+
accepts: x402PaymentRequirements.array(),
|
|
33
|
+
"extensions?": "object",
|
|
34
|
+
});
|
|
35
|
+
export const x402PaymentPayload = type({
|
|
36
|
+
x402Version: "2",
|
|
37
|
+
"resource?": x402ResourceInfo,
|
|
38
|
+
accepted: x402PaymentRequirements,
|
|
39
|
+
payload: "object",
|
|
40
|
+
"extensions?": "object",
|
|
41
|
+
});
|
|
42
|
+
export const x402PaymentHeaderToPayload = type("string.base64")
|
|
43
|
+
.pipe.try((x) => atob(x))
|
|
44
|
+
.to("string.json.parse")
|
|
45
|
+
.to(x402PaymentPayload);
|
|
46
|
+
export const x402VerifyRequest = type({
|
|
47
|
+
paymentPayload: x402PaymentPayload,
|
|
48
|
+
paymentRequirements: x402PaymentRequirements,
|
|
49
|
+
});
|
|
50
|
+
export const x402VerifyResponse = type({
|
|
51
|
+
isValid: "boolean",
|
|
52
|
+
"invalidReason?": "string",
|
|
53
|
+
"payer?": "string",
|
|
54
|
+
});
|
|
55
|
+
export const x402SettleRequest = x402VerifyRequest;
|
|
56
|
+
export const x402SettleResponse = type({
|
|
57
|
+
success: "boolean",
|
|
58
|
+
"errorReason?": "string",
|
|
59
|
+
"payer?": "string",
|
|
60
|
+
transaction: "string",
|
|
61
|
+
network: "string",
|
|
62
|
+
"extensions?": "object",
|
|
63
|
+
});
|
|
64
|
+
export const x402SupportedKind = type({
|
|
65
|
+
x402Version: "2",
|
|
66
|
+
scheme: "string",
|
|
67
|
+
network: "string",
|
|
68
|
+
"extra?": "object",
|
|
69
|
+
});
|
|
70
|
+
// SupportedKind that accepts either v1 or v2 version numbers
|
|
71
|
+
export const x402SupportedKindAny = type({
|
|
72
|
+
x402Version: "1 | 2",
|
|
73
|
+
scheme: "string",
|
|
74
|
+
network: "string",
|
|
75
|
+
"extra?": "object",
|
|
76
|
+
});
|
|
77
|
+
export const x402SupportedResponse = type({
|
|
78
|
+
kinds: x402SupportedKindAny.array(),
|
|
79
|
+
extensions: "string[]",
|
|
80
|
+
signers: type("Record<string, string[]>"),
|
|
81
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402v2.test.d.ts","sourceRoot":"","sources":["../../src/x402v2.test.ts"],"names":[],"mappings":""}
|