@vapi-network/mcp 0.1.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/README.md +176 -0
- package/dist/cli.js +53262 -0
- package/dist/cli.js.map +6 -0
- package/dist/server.js +49948 -0
- package/dist/server.js.map +6 -0
- package/dist/x402.js +1339 -0
- package/dist/x402.js.map +6 -0
- package/package.json +51 -0
- package/types/server.d.ts +78 -0
- package/types/x402.d.ts +137 -0
package/dist/x402.js
ADDED
|
@@ -0,0 +1,1339 @@
|
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
+
var __esm = (fn, res, err) => function __init() {
|
|
3
|
+
if (err) throw err[0];
|
|
4
|
+
try {
|
|
5
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
6
|
+
} catch (e) {
|
|
7
|
+
throw err = [e], e;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// ../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/data/isHex.js
|
|
12
|
+
function isHex(value, { strict = true } = {}) {
|
|
13
|
+
if (!value)
|
|
14
|
+
return false;
|
|
15
|
+
if (typeof value !== "string")
|
|
16
|
+
return false;
|
|
17
|
+
return strict ? /^0x[0-9a-fA-F]*$/.test(value) : value.startsWith("0x");
|
|
18
|
+
}
|
|
19
|
+
var init_isHex = __esm({
|
|
20
|
+
"../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/data/isHex.js"() {
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// ../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/data/size.js
|
|
25
|
+
function size(value) {
|
|
26
|
+
if (isHex(value, { strict: false }))
|
|
27
|
+
return Math.ceil((value.length - 2) / 2);
|
|
28
|
+
return value.length;
|
|
29
|
+
}
|
|
30
|
+
var init_size = __esm({
|
|
31
|
+
"../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/data/size.js"() {
|
|
32
|
+
init_isHex();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// ../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/errors/version.js
|
|
37
|
+
var version;
|
|
38
|
+
var init_version = __esm({
|
|
39
|
+
"../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/errors/version.js"() {
|
|
40
|
+
version = "2.55.10";
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// ../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/errors/base.js
|
|
45
|
+
function walk(err, fn) {
|
|
46
|
+
if (fn?.(err))
|
|
47
|
+
return err;
|
|
48
|
+
if (err && typeof err === "object" && "cause" in err && err.cause !== void 0)
|
|
49
|
+
return walk(err.cause, fn);
|
|
50
|
+
return fn ? null : err;
|
|
51
|
+
}
|
|
52
|
+
var errorConfig, BaseError;
|
|
53
|
+
var init_base = __esm({
|
|
54
|
+
"../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/errors/base.js"() {
|
|
55
|
+
init_version();
|
|
56
|
+
errorConfig = {
|
|
57
|
+
getDocsUrl: ({ docsBaseUrl, docsPath = "", docsSlug }) => docsPath ? `${docsBaseUrl ?? "https://viem.sh"}${docsPath}${docsSlug ? `#${docsSlug}` : ""}` : void 0,
|
|
58
|
+
version: `viem@${version}`
|
|
59
|
+
};
|
|
60
|
+
BaseError = class _BaseError extends Error {
|
|
61
|
+
constructor(shortMessage, args = {}) {
|
|
62
|
+
const details = (() => {
|
|
63
|
+
if (args.cause instanceof _BaseError)
|
|
64
|
+
return args.cause.details;
|
|
65
|
+
if (args.cause?.message)
|
|
66
|
+
return args.cause.message;
|
|
67
|
+
return args.details;
|
|
68
|
+
})();
|
|
69
|
+
const docsPath = (() => {
|
|
70
|
+
if (args.cause instanceof _BaseError)
|
|
71
|
+
return args.cause.docsPath || args.docsPath;
|
|
72
|
+
return args.docsPath;
|
|
73
|
+
})();
|
|
74
|
+
const docsUrl = errorConfig.getDocsUrl?.({ ...args, docsPath });
|
|
75
|
+
const message = [
|
|
76
|
+
shortMessage || "An error occurred.",
|
|
77
|
+
"",
|
|
78
|
+
...args.metaMessages ? [...args.metaMessages, ""] : [],
|
|
79
|
+
...docsUrl ? [`Docs: ${docsUrl}`] : [],
|
|
80
|
+
...details ? [`Details: ${details}`] : [],
|
|
81
|
+
...errorConfig.version ? [`Version: ${errorConfig.version}`] : []
|
|
82
|
+
].join("\n");
|
|
83
|
+
super(message, args.cause ? { cause: args.cause } : void 0);
|
|
84
|
+
Object.defineProperty(this, "details", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
configurable: true,
|
|
87
|
+
writable: true,
|
|
88
|
+
value: void 0
|
|
89
|
+
});
|
|
90
|
+
Object.defineProperty(this, "docsPath", {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
configurable: true,
|
|
93
|
+
writable: true,
|
|
94
|
+
value: void 0
|
|
95
|
+
});
|
|
96
|
+
Object.defineProperty(this, "metaMessages", {
|
|
97
|
+
enumerable: true,
|
|
98
|
+
configurable: true,
|
|
99
|
+
writable: true,
|
|
100
|
+
value: void 0
|
|
101
|
+
});
|
|
102
|
+
Object.defineProperty(this, "shortMessage", {
|
|
103
|
+
enumerable: true,
|
|
104
|
+
configurable: true,
|
|
105
|
+
writable: true,
|
|
106
|
+
value: void 0
|
|
107
|
+
});
|
|
108
|
+
Object.defineProperty(this, "version", {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
configurable: true,
|
|
111
|
+
writable: true,
|
|
112
|
+
value: void 0
|
|
113
|
+
});
|
|
114
|
+
Object.defineProperty(this, "name", {
|
|
115
|
+
enumerable: true,
|
|
116
|
+
configurable: true,
|
|
117
|
+
writable: true,
|
|
118
|
+
value: "BaseError"
|
|
119
|
+
});
|
|
120
|
+
this.details = details;
|
|
121
|
+
this.docsPath = docsPath;
|
|
122
|
+
this.metaMessages = args.metaMessages;
|
|
123
|
+
this.name = args.name ?? this.name;
|
|
124
|
+
this.shortMessage = shortMessage;
|
|
125
|
+
this.version = version;
|
|
126
|
+
}
|
|
127
|
+
walk(fn) {
|
|
128
|
+
return walk(this, fn);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// ../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/errors/data.js
|
|
135
|
+
var SizeExceedsPaddingSizeError;
|
|
136
|
+
var init_data = __esm({
|
|
137
|
+
"../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/errors/data.js"() {
|
|
138
|
+
init_base();
|
|
139
|
+
SizeExceedsPaddingSizeError = class extends BaseError {
|
|
140
|
+
constructor({ size: size2, targetSize, type }) {
|
|
141
|
+
super(`${type.charAt(0).toUpperCase()}${type.slice(1).toLowerCase()} size (${size2}) exceeds padding size (${targetSize}).`, { name: "SizeExceedsPaddingSizeError" });
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// ../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/data/pad.js
|
|
148
|
+
function pad(hexOrBytes, { dir, size: size2 = 32 } = {}) {
|
|
149
|
+
if (typeof hexOrBytes === "string")
|
|
150
|
+
return padHex(hexOrBytes, { dir, size: size2 });
|
|
151
|
+
return padBytes(hexOrBytes, { dir, size: size2 });
|
|
152
|
+
}
|
|
153
|
+
function padHex(hex_, { dir, size: size2 = 32 } = {}) {
|
|
154
|
+
if (size2 === null)
|
|
155
|
+
return hex_;
|
|
156
|
+
const hex = hex_.replace("0x", "");
|
|
157
|
+
if (hex.length > size2 * 2)
|
|
158
|
+
throw new SizeExceedsPaddingSizeError({
|
|
159
|
+
size: Math.ceil(hex.length / 2),
|
|
160
|
+
targetSize: size2,
|
|
161
|
+
type: "hex"
|
|
162
|
+
});
|
|
163
|
+
return `0x${hex[dir === "right" ? "padEnd" : "padStart"](size2 * 2, "0")}`;
|
|
164
|
+
}
|
|
165
|
+
function padBytes(bytes, { dir, size: size2 = 32 } = {}) {
|
|
166
|
+
if (size2 === null)
|
|
167
|
+
return bytes;
|
|
168
|
+
if (bytes.length > size2)
|
|
169
|
+
throw new SizeExceedsPaddingSizeError({
|
|
170
|
+
size: bytes.length,
|
|
171
|
+
targetSize: size2,
|
|
172
|
+
type: "bytes"
|
|
173
|
+
});
|
|
174
|
+
const paddedBytes = new Uint8Array(size2);
|
|
175
|
+
for (let i = 0; i < size2; i++) {
|
|
176
|
+
const padEnd = dir === "right";
|
|
177
|
+
paddedBytes[padEnd ? i : size2 - i - 1] = bytes[padEnd ? i : bytes.length - i - 1];
|
|
178
|
+
}
|
|
179
|
+
return paddedBytes;
|
|
180
|
+
}
|
|
181
|
+
var init_pad = __esm({
|
|
182
|
+
"../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/data/pad.js"() {
|
|
183
|
+
init_data();
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// ../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/errors/encoding.js
|
|
188
|
+
var IntegerOutOfRangeError, SizeOverflowError;
|
|
189
|
+
var init_encoding = __esm({
|
|
190
|
+
"../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/errors/encoding.js"() {
|
|
191
|
+
init_base();
|
|
192
|
+
IntegerOutOfRangeError = class extends BaseError {
|
|
193
|
+
constructor({ max, min, signed, size: size2, value }) {
|
|
194
|
+
super(`Number "${value}" is not in safe ${size2 ? `${size2 * 8}-bit ${signed ? "signed" : "unsigned"} ` : ""}integer range ${max ? `(${min} to ${max})` : `(above ${min})`}`, { name: "IntegerOutOfRangeError" });
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
SizeOverflowError = class extends BaseError {
|
|
198
|
+
constructor({ givenSize, maxSize }) {
|
|
199
|
+
super(`Size cannot exceed ${maxSize} bytes. Given size: ${givenSize} bytes.`, { name: "SizeOverflowError" });
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// ../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/encoding/fromHex.js
|
|
206
|
+
function assertSize(hexOrBytes, { size: size2 }) {
|
|
207
|
+
if (size(hexOrBytes) > size2)
|
|
208
|
+
throw new SizeOverflowError({
|
|
209
|
+
givenSize: size(hexOrBytes),
|
|
210
|
+
maxSize: size2
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
var init_fromHex = __esm({
|
|
214
|
+
"../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/encoding/fromHex.js"() {
|
|
215
|
+
init_encoding();
|
|
216
|
+
init_size();
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// ../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/encoding/toHex.js
|
|
221
|
+
function toHex(value, opts = {}) {
|
|
222
|
+
if (typeof value === "number" || typeof value === "bigint")
|
|
223
|
+
return numberToHex(value, opts);
|
|
224
|
+
if (typeof value === "string") {
|
|
225
|
+
return stringToHex(value, opts);
|
|
226
|
+
}
|
|
227
|
+
if (typeof value === "boolean")
|
|
228
|
+
return boolToHex(value, opts);
|
|
229
|
+
return bytesToHex(value, opts);
|
|
230
|
+
}
|
|
231
|
+
function boolToHex(value, opts = {}) {
|
|
232
|
+
const hex = `0x${Number(value)}`;
|
|
233
|
+
if (typeof opts.size === "number") {
|
|
234
|
+
assertSize(hex, { size: opts.size });
|
|
235
|
+
return pad(hex, { size: opts.size });
|
|
236
|
+
}
|
|
237
|
+
return hex;
|
|
238
|
+
}
|
|
239
|
+
function bytesToHex(value, opts = {}) {
|
|
240
|
+
let string = "";
|
|
241
|
+
for (let i = 0; i < value.length; i++) {
|
|
242
|
+
string += hexes[value[i]];
|
|
243
|
+
}
|
|
244
|
+
const hex = `0x${string}`;
|
|
245
|
+
if (typeof opts.size === "number") {
|
|
246
|
+
assertSize(hex, { size: opts.size });
|
|
247
|
+
return pad(hex, { dir: "right", size: opts.size });
|
|
248
|
+
}
|
|
249
|
+
return hex;
|
|
250
|
+
}
|
|
251
|
+
function numberToHex(value_, opts = {}) {
|
|
252
|
+
const { signed, size: size2 } = opts;
|
|
253
|
+
const value = BigInt(value_);
|
|
254
|
+
let maxValue;
|
|
255
|
+
if (size2) {
|
|
256
|
+
if (signed)
|
|
257
|
+
maxValue = (1n << BigInt(size2) * 8n - 1n) - 1n;
|
|
258
|
+
else
|
|
259
|
+
maxValue = 2n ** (BigInt(size2) * 8n) - 1n;
|
|
260
|
+
} else if (typeof value_ === "number") {
|
|
261
|
+
maxValue = BigInt(Number.MAX_SAFE_INTEGER);
|
|
262
|
+
}
|
|
263
|
+
const minValue = typeof maxValue === "bigint" && signed ? -maxValue - 1n : 0;
|
|
264
|
+
if (maxValue && value > maxValue || value < minValue) {
|
|
265
|
+
const suffix = typeof value_ === "bigint" ? "n" : "";
|
|
266
|
+
throw new IntegerOutOfRangeError({
|
|
267
|
+
max: maxValue ? `${maxValue}${suffix}` : void 0,
|
|
268
|
+
min: `${minValue}${suffix}`,
|
|
269
|
+
signed,
|
|
270
|
+
size: size2,
|
|
271
|
+
value: `${value_}${suffix}`
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
const hex = `0x${(signed && value < 0 ? (1n << BigInt(size2 * 8)) + BigInt(value) : value).toString(16)}`;
|
|
275
|
+
if (size2)
|
|
276
|
+
return pad(hex, { size: size2 });
|
|
277
|
+
return hex;
|
|
278
|
+
}
|
|
279
|
+
function stringToHex(value_, opts = {}) {
|
|
280
|
+
const value = encoder.encode(value_);
|
|
281
|
+
return bytesToHex(value, opts);
|
|
282
|
+
}
|
|
283
|
+
var hexes, encoder;
|
|
284
|
+
var init_toHex = __esm({
|
|
285
|
+
"../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/encoding/toHex.js"() {
|
|
286
|
+
init_encoding();
|
|
287
|
+
init_pad();
|
|
288
|
+
init_fromHex();
|
|
289
|
+
hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_v, i) => i.toString(16).padStart(2, "0"));
|
|
290
|
+
encoder = /* @__PURE__ */ new TextEncoder();
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
// ../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/encoding/toBytes.js
|
|
295
|
+
function toBytes(value, opts = {}) {
|
|
296
|
+
if (typeof value === "number" || typeof value === "bigint")
|
|
297
|
+
return numberToBytes(value, opts);
|
|
298
|
+
if (typeof value === "boolean")
|
|
299
|
+
return boolToBytes(value, opts);
|
|
300
|
+
if (isHex(value))
|
|
301
|
+
return hexToBytes(value, opts);
|
|
302
|
+
return stringToBytes(value, opts);
|
|
303
|
+
}
|
|
304
|
+
function boolToBytes(value, opts = {}) {
|
|
305
|
+
const bytes = new Uint8Array(1);
|
|
306
|
+
bytes[0] = Number(value);
|
|
307
|
+
if (typeof opts.size === "number") {
|
|
308
|
+
assertSize(bytes, { size: opts.size });
|
|
309
|
+
return pad(bytes, { size: opts.size });
|
|
310
|
+
}
|
|
311
|
+
return bytes;
|
|
312
|
+
}
|
|
313
|
+
function charCodeToBase16(char) {
|
|
314
|
+
if (char >= charCodeMap.zero && char <= charCodeMap.nine)
|
|
315
|
+
return char - charCodeMap.zero;
|
|
316
|
+
if (char >= charCodeMap.A && char <= charCodeMap.F)
|
|
317
|
+
return char - (charCodeMap.A - 10);
|
|
318
|
+
if (char >= charCodeMap.a && char <= charCodeMap.f)
|
|
319
|
+
return char - (charCodeMap.a - 10);
|
|
320
|
+
return void 0;
|
|
321
|
+
}
|
|
322
|
+
function hexToBytes(hex_, opts = {}) {
|
|
323
|
+
let hex = hex_;
|
|
324
|
+
if (opts.size) {
|
|
325
|
+
assertSize(hex, { size: opts.size });
|
|
326
|
+
hex = pad(hex, { dir: "right", size: opts.size });
|
|
327
|
+
}
|
|
328
|
+
let hexString = hex.slice(2);
|
|
329
|
+
if (hexString.length % 2)
|
|
330
|
+
hexString = `0${hexString}`;
|
|
331
|
+
const length = hexString.length / 2;
|
|
332
|
+
const bytes = new Uint8Array(length);
|
|
333
|
+
for (let index = 0, j = 0; index < length; index++) {
|
|
334
|
+
const nibbleLeft = charCodeToBase16(hexString.charCodeAt(j++));
|
|
335
|
+
const nibbleRight = charCodeToBase16(hexString.charCodeAt(j++));
|
|
336
|
+
if (nibbleLeft === void 0 || nibbleRight === void 0) {
|
|
337
|
+
throw new BaseError(`Invalid byte sequence ("${hexString[j - 2]}${hexString[j - 1]}" in "${hexString}").`);
|
|
338
|
+
}
|
|
339
|
+
bytes[index] = nibbleLeft * 16 + nibbleRight;
|
|
340
|
+
}
|
|
341
|
+
return bytes;
|
|
342
|
+
}
|
|
343
|
+
function numberToBytes(value, opts) {
|
|
344
|
+
const hex = numberToHex(value, opts);
|
|
345
|
+
return hexToBytes(hex);
|
|
346
|
+
}
|
|
347
|
+
function stringToBytes(value, opts = {}) {
|
|
348
|
+
const bytes = encoder2.encode(value);
|
|
349
|
+
if (typeof opts.size === "number") {
|
|
350
|
+
assertSize(bytes, { size: opts.size });
|
|
351
|
+
return pad(bytes, { dir: "right", size: opts.size });
|
|
352
|
+
}
|
|
353
|
+
return bytes;
|
|
354
|
+
}
|
|
355
|
+
var encoder2, charCodeMap;
|
|
356
|
+
var init_toBytes = __esm({
|
|
357
|
+
"../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/encoding/toBytes.js"() {
|
|
358
|
+
init_base();
|
|
359
|
+
init_isHex();
|
|
360
|
+
init_pad();
|
|
361
|
+
init_fromHex();
|
|
362
|
+
init_toHex();
|
|
363
|
+
encoder2 = /* @__PURE__ */ new TextEncoder();
|
|
364
|
+
charCodeMap = {
|
|
365
|
+
zero: 48,
|
|
366
|
+
nine: 57,
|
|
367
|
+
A: 65,
|
|
368
|
+
F: 70,
|
|
369
|
+
a: 97,
|
|
370
|
+
f: 102
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
// ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_u64.js
|
|
376
|
+
function fromBig(n, le = false) {
|
|
377
|
+
if (le)
|
|
378
|
+
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
|
379
|
+
return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
380
|
+
}
|
|
381
|
+
function split(lst, le = false) {
|
|
382
|
+
const len = lst.length;
|
|
383
|
+
let Ah = new Uint32Array(len);
|
|
384
|
+
let Al = new Uint32Array(len);
|
|
385
|
+
for (let i = 0; i < len; i++) {
|
|
386
|
+
const { h, l } = fromBig(lst[i], le);
|
|
387
|
+
[Ah[i], Al[i]] = [h, l];
|
|
388
|
+
}
|
|
389
|
+
return [Ah, Al];
|
|
390
|
+
}
|
|
391
|
+
var U32_MASK64, _32n, rotlSH, rotlSL, rotlBH, rotlBL;
|
|
392
|
+
var init_u64 = __esm({
|
|
393
|
+
"../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_u64.js"() {
|
|
394
|
+
U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
395
|
+
_32n = /* @__PURE__ */ BigInt(32);
|
|
396
|
+
rotlSH = (h, l, s) => h << s | l >>> 32 - s;
|
|
397
|
+
rotlSL = (h, l, s) => l << s | h >>> 32 - s;
|
|
398
|
+
rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
|
|
399
|
+
rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
// ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/utils.js
|
|
404
|
+
function isBytes(a) {
|
|
405
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
406
|
+
}
|
|
407
|
+
function anumber(n) {
|
|
408
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
409
|
+
throw new Error("positive integer expected, got " + n);
|
|
410
|
+
}
|
|
411
|
+
function abytes(b, ...lengths) {
|
|
412
|
+
if (!isBytes(b))
|
|
413
|
+
throw new Error("Uint8Array expected");
|
|
414
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
415
|
+
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
416
|
+
}
|
|
417
|
+
function aexists(instance, checkFinished = true) {
|
|
418
|
+
if (instance.destroyed)
|
|
419
|
+
throw new Error("Hash instance has been destroyed");
|
|
420
|
+
if (checkFinished && instance.finished)
|
|
421
|
+
throw new Error("Hash#digest() has already been called");
|
|
422
|
+
}
|
|
423
|
+
function aoutput(out, instance) {
|
|
424
|
+
abytes(out);
|
|
425
|
+
const min = instance.outputLen;
|
|
426
|
+
if (out.length < min) {
|
|
427
|
+
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
function u32(arr) {
|
|
431
|
+
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
432
|
+
}
|
|
433
|
+
function clean(...arrays) {
|
|
434
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
435
|
+
arrays[i].fill(0);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
function byteSwap(word) {
|
|
439
|
+
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
440
|
+
}
|
|
441
|
+
function byteSwap32(arr) {
|
|
442
|
+
for (let i = 0; i < arr.length; i++) {
|
|
443
|
+
arr[i] = byteSwap(arr[i]);
|
|
444
|
+
}
|
|
445
|
+
return arr;
|
|
446
|
+
}
|
|
447
|
+
function utf8ToBytes(str) {
|
|
448
|
+
if (typeof str !== "string")
|
|
449
|
+
throw new Error("string expected");
|
|
450
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
451
|
+
}
|
|
452
|
+
function toBytes2(data) {
|
|
453
|
+
if (typeof data === "string")
|
|
454
|
+
data = utf8ToBytes(data);
|
|
455
|
+
abytes(data);
|
|
456
|
+
return data;
|
|
457
|
+
}
|
|
458
|
+
function createHasher(hashCons) {
|
|
459
|
+
const hashC = (msg) => hashCons().update(toBytes2(msg)).digest();
|
|
460
|
+
const tmp = hashCons();
|
|
461
|
+
hashC.outputLen = tmp.outputLen;
|
|
462
|
+
hashC.blockLen = tmp.blockLen;
|
|
463
|
+
hashC.create = () => hashCons();
|
|
464
|
+
return hashC;
|
|
465
|
+
}
|
|
466
|
+
var isLE, swap32IfBE, Hash;
|
|
467
|
+
var init_utils = __esm({
|
|
468
|
+
"../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/utils.js"() {
|
|
469
|
+
isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
470
|
+
swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
471
|
+
Hash = class {
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
// ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/sha3.js
|
|
477
|
+
function keccakP(s, rounds = 24) {
|
|
478
|
+
const B = new Uint32Array(5 * 2);
|
|
479
|
+
for (let round = 24 - rounds; round < 24; round++) {
|
|
480
|
+
for (let x = 0; x < 10; x++)
|
|
481
|
+
B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
|
|
482
|
+
for (let x = 0; x < 10; x += 2) {
|
|
483
|
+
const idx1 = (x + 8) % 10;
|
|
484
|
+
const idx0 = (x + 2) % 10;
|
|
485
|
+
const B0 = B[idx0];
|
|
486
|
+
const B1 = B[idx0 + 1];
|
|
487
|
+
const Th = rotlH(B0, B1, 1) ^ B[idx1];
|
|
488
|
+
const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
|
|
489
|
+
for (let y = 0; y < 50; y += 10) {
|
|
490
|
+
s[x + y] ^= Th;
|
|
491
|
+
s[x + y + 1] ^= Tl;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
let curH = s[2];
|
|
495
|
+
let curL = s[3];
|
|
496
|
+
for (let t = 0; t < 24; t++) {
|
|
497
|
+
const shift = SHA3_ROTL[t];
|
|
498
|
+
const Th = rotlH(curH, curL, shift);
|
|
499
|
+
const Tl = rotlL(curH, curL, shift);
|
|
500
|
+
const PI = SHA3_PI[t];
|
|
501
|
+
curH = s[PI];
|
|
502
|
+
curL = s[PI + 1];
|
|
503
|
+
s[PI] = Th;
|
|
504
|
+
s[PI + 1] = Tl;
|
|
505
|
+
}
|
|
506
|
+
for (let y = 0; y < 50; y += 10) {
|
|
507
|
+
for (let x = 0; x < 10; x++)
|
|
508
|
+
B[x] = s[y + x];
|
|
509
|
+
for (let x = 0; x < 10; x++)
|
|
510
|
+
s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
|
|
511
|
+
}
|
|
512
|
+
s[0] ^= SHA3_IOTA_H[round];
|
|
513
|
+
s[1] ^= SHA3_IOTA_L[round];
|
|
514
|
+
}
|
|
515
|
+
clean(B);
|
|
516
|
+
}
|
|
517
|
+
var _0n, _1n, _2n, _7n, _256n, _0x71n, SHA3_PI, SHA3_ROTL, _SHA3_IOTA, IOTAS, SHA3_IOTA_H, SHA3_IOTA_L, rotlH, rotlL, Keccak, gen, keccak_256;
|
|
518
|
+
var init_sha3 = __esm({
|
|
519
|
+
"../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/sha3.js"() {
|
|
520
|
+
init_u64();
|
|
521
|
+
init_utils();
|
|
522
|
+
_0n = BigInt(0);
|
|
523
|
+
_1n = BigInt(1);
|
|
524
|
+
_2n = BigInt(2);
|
|
525
|
+
_7n = BigInt(7);
|
|
526
|
+
_256n = BigInt(256);
|
|
527
|
+
_0x71n = BigInt(113);
|
|
528
|
+
SHA3_PI = [];
|
|
529
|
+
SHA3_ROTL = [];
|
|
530
|
+
_SHA3_IOTA = [];
|
|
531
|
+
for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
|
|
532
|
+
[x, y] = [y, (2 * x + 3 * y) % 5];
|
|
533
|
+
SHA3_PI.push(2 * (5 * y + x));
|
|
534
|
+
SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
|
|
535
|
+
let t = _0n;
|
|
536
|
+
for (let j = 0; j < 7; j++) {
|
|
537
|
+
R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n;
|
|
538
|
+
if (R & _2n)
|
|
539
|
+
t ^= _1n << (_1n << /* @__PURE__ */ BigInt(j)) - _1n;
|
|
540
|
+
}
|
|
541
|
+
_SHA3_IOTA.push(t);
|
|
542
|
+
}
|
|
543
|
+
IOTAS = split(_SHA3_IOTA, true);
|
|
544
|
+
SHA3_IOTA_H = IOTAS[0];
|
|
545
|
+
SHA3_IOTA_L = IOTAS[1];
|
|
546
|
+
rotlH = (h, l, s) => s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s);
|
|
547
|
+
rotlL = (h, l, s) => s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s);
|
|
548
|
+
Keccak = class _Keccak extends Hash {
|
|
549
|
+
// NOTE: we accept arguments in bytes instead of bits here.
|
|
550
|
+
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
|
551
|
+
super();
|
|
552
|
+
this.pos = 0;
|
|
553
|
+
this.posOut = 0;
|
|
554
|
+
this.finished = false;
|
|
555
|
+
this.destroyed = false;
|
|
556
|
+
this.enableXOF = false;
|
|
557
|
+
this.blockLen = blockLen;
|
|
558
|
+
this.suffix = suffix;
|
|
559
|
+
this.outputLen = outputLen;
|
|
560
|
+
this.enableXOF = enableXOF;
|
|
561
|
+
this.rounds = rounds;
|
|
562
|
+
anumber(outputLen);
|
|
563
|
+
if (!(0 < blockLen && blockLen < 200))
|
|
564
|
+
throw new Error("only keccak-f1600 function is supported");
|
|
565
|
+
this.state = new Uint8Array(200);
|
|
566
|
+
this.state32 = u32(this.state);
|
|
567
|
+
}
|
|
568
|
+
clone() {
|
|
569
|
+
return this._cloneInto();
|
|
570
|
+
}
|
|
571
|
+
keccak() {
|
|
572
|
+
swap32IfBE(this.state32);
|
|
573
|
+
keccakP(this.state32, this.rounds);
|
|
574
|
+
swap32IfBE(this.state32);
|
|
575
|
+
this.posOut = 0;
|
|
576
|
+
this.pos = 0;
|
|
577
|
+
}
|
|
578
|
+
update(data) {
|
|
579
|
+
aexists(this);
|
|
580
|
+
data = toBytes2(data);
|
|
581
|
+
abytes(data);
|
|
582
|
+
const { blockLen, state } = this;
|
|
583
|
+
const len = data.length;
|
|
584
|
+
for (let pos = 0; pos < len; ) {
|
|
585
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
586
|
+
for (let i = 0; i < take; i++)
|
|
587
|
+
state[this.pos++] ^= data[pos++];
|
|
588
|
+
if (this.pos === blockLen)
|
|
589
|
+
this.keccak();
|
|
590
|
+
}
|
|
591
|
+
return this;
|
|
592
|
+
}
|
|
593
|
+
finish() {
|
|
594
|
+
if (this.finished)
|
|
595
|
+
return;
|
|
596
|
+
this.finished = true;
|
|
597
|
+
const { state, suffix, pos, blockLen } = this;
|
|
598
|
+
state[pos] ^= suffix;
|
|
599
|
+
if ((suffix & 128) !== 0 && pos === blockLen - 1)
|
|
600
|
+
this.keccak();
|
|
601
|
+
state[blockLen - 1] ^= 128;
|
|
602
|
+
this.keccak();
|
|
603
|
+
}
|
|
604
|
+
writeInto(out) {
|
|
605
|
+
aexists(this, false);
|
|
606
|
+
abytes(out);
|
|
607
|
+
this.finish();
|
|
608
|
+
const bufferOut = this.state;
|
|
609
|
+
const { blockLen } = this;
|
|
610
|
+
for (let pos = 0, len = out.length; pos < len; ) {
|
|
611
|
+
if (this.posOut >= blockLen)
|
|
612
|
+
this.keccak();
|
|
613
|
+
const take = Math.min(blockLen - this.posOut, len - pos);
|
|
614
|
+
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
|
615
|
+
this.posOut += take;
|
|
616
|
+
pos += take;
|
|
617
|
+
}
|
|
618
|
+
return out;
|
|
619
|
+
}
|
|
620
|
+
xofInto(out) {
|
|
621
|
+
if (!this.enableXOF)
|
|
622
|
+
throw new Error("XOF is not possible for this instance");
|
|
623
|
+
return this.writeInto(out);
|
|
624
|
+
}
|
|
625
|
+
xof(bytes) {
|
|
626
|
+
anumber(bytes);
|
|
627
|
+
return this.xofInto(new Uint8Array(bytes));
|
|
628
|
+
}
|
|
629
|
+
digestInto(out) {
|
|
630
|
+
aoutput(out, this);
|
|
631
|
+
if (this.finished)
|
|
632
|
+
throw new Error("digest() was already called");
|
|
633
|
+
this.writeInto(out);
|
|
634
|
+
this.destroy();
|
|
635
|
+
return out;
|
|
636
|
+
}
|
|
637
|
+
digest() {
|
|
638
|
+
return this.digestInto(new Uint8Array(this.outputLen));
|
|
639
|
+
}
|
|
640
|
+
destroy() {
|
|
641
|
+
this.destroyed = true;
|
|
642
|
+
clean(this.state);
|
|
643
|
+
}
|
|
644
|
+
_cloneInto(to) {
|
|
645
|
+
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
646
|
+
to || (to = new _Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
|
|
647
|
+
to.state32.set(this.state32);
|
|
648
|
+
to.pos = this.pos;
|
|
649
|
+
to.posOut = this.posOut;
|
|
650
|
+
to.finished = this.finished;
|
|
651
|
+
to.rounds = rounds;
|
|
652
|
+
to.suffix = suffix;
|
|
653
|
+
to.outputLen = outputLen;
|
|
654
|
+
to.enableXOF = enableXOF;
|
|
655
|
+
to.destroyed = this.destroyed;
|
|
656
|
+
return to;
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
gen = (suffix, blockLen, outputLen) => createHasher(() => new Keccak(blockLen, suffix, outputLen));
|
|
660
|
+
keccak_256 = /* @__PURE__ */ (() => gen(1, 136, 256 / 8))();
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
// ../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/hash/keccak256.js
|
|
665
|
+
function keccak256(value, to_) {
|
|
666
|
+
const to = to_ || "hex";
|
|
667
|
+
const bytes = keccak_256(isHex(value, { strict: false }) ? toBytes(value) : value);
|
|
668
|
+
if (to === "bytes")
|
|
669
|
+
return bytes;
|
|
670
|
+
return toHex(bytes);
|
|
671
|
+
}
|
|
672
|
+
var init_keccak256 = __esm({
|
|
673
|
+
"../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/hash/keccak256.js"() {
|
|
674
|
+
init_sha3();
|
|
675
|
+
init_isHex();
|
|
676
|
+
init_toBytes();
|
|
677
|
+
init_toHex();
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
|
|
681
|
+
// ../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/errors/address.js
|
|
682
|
+
var InvalidAddressError;
|
|
683
|
+
var init_address = __esm({
|
|
684
|
+
"../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/errors/address.js"() {
|
|
685
|
+
init_base();
|
|
686
|
+
InvalidAddressError = class extends BaseError {
|
|
687
|
+
constructor({ address }) {
|
|
688
|
+
super(`Address "${address}" is invalid.`, {
|
|
689
|
+
metaMessages: [
|
|
690
|
+
"- Address must be a hex value of 20 bytes (40 hex characters).",
|
|
691
|
+
"- Address must match its checksum counterpart."
|
|
692
|
+
],
|
|
693
|
+
name: "InvalidAddressError"
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
|
|
700
|
+
// ../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/lru.js
|
|
701
|
+
var LruMap;
|
|
702
|
+
var init_lru = __esm({
|
|
703
|
+
"../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/lru.js"() {
|
|
704
|
+
LruMap = class extends Map {
|
|
705
|
+
constructor(size2) {
|
|
706
|
+
super();
|
|
707
|
+
Object.defineProperty(this, "maxSize", {
|
|
708
|
+
enumerable: true,
|
|
709
|
+
configurable: true,
|
|
710
|
+
writable: true,
|
|
711
|
+
value: void 0
|
|
712
|
+
});
|
|
713
|
+
this.maxSize = size2;
|
|
714
|
+
}
|
|
715
|
+
get(key) {
|
|
716
|
+
const value = super.get(key);
|
|
717
|
+
if (super.has(key)) {
|
|
718
|
+
super.delete(key);
|
|
719
|
+
super.set(key, value);
|
|
720
|
+
}
|
|
721
|
+
return value;
|
|
722
|
+
}
|
|
723
|
+
set(key, value) {
|
|
724
|
+
if (super.has(key))
|
|
725
|
+
super.delete(key);
|
|
726
|
+
super.set(key, value);
|
|
727
|
+
if (this.maxSize && this.size > this.maxSize) {
|
|
728
|
+
const firstKey = super.keys().next().value;
|
|
729
|
+
if (firstKey !== void 0)
|
|
730
|
+
super.delete(firstKey);
|
|
731
|
+
}
|
|
732
|
+
return this;
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
|
|
738
|
+
// ../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/address/getAddress.js
|
|
739
|
+
function checksumAddress(address_, chainId) {
|
|
740
|
+
if (checksumAddressCache.has(`${address_}.${chainId}`))
|
|
741
|
+
return checksumAddressCache.get(`${address_}.${chainId}`);
|
|
742
|
+
const hexAddress = chainId ? `${chainId}${address_.toLowerCase()}` : address_.substring(2).toLowerCase();
|
|
743
|
+
const hash = keccak256(stringToBytes(hexAddress), "bytes");
|
|
744
|
+
const address = (chainId ? hexAddress.substring(`${chainId}0x`.length) : hexAddress).split("");
|
|
745
|
+
for (let i = 0; i < 40; i += 2) {
|
|
746
|
+
if (hash[i >> 1] >> 4 >= 8 && address[i]) {
|
|
747
|
+
address[i] = address[i].toUpperCase();
|
|
748
|
+
}
|
|
749
|
+
if ((hash[i >> 1] & 15) >= 8 && address[i + 1]) {
|
|
750
|
+
address[i + 1] = address[i + 1].toUpperCase();
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
const result = `0x${address.join("")}`;
|
|
754
|
+
checksumAddressCache.set(`${address_}.${chainId}`, result);
|
|
755
|
+
return result;
|
|
756
|
+
}
|
|
757
|
+
function getAddress(address, chainId) {
|
|
758
|
+
if (!isAddress(address, { strict: false }))
|
|
759
|
+
throw new InvalidAddressError({ address });
|
|
760
|
+
return checksumAddress(address, chainId);
|
|
761
|
+
}
|
|
762
|
+
var checksumAddressCache;
|
|
763
|
+
var init_getAddress = __esm({
|
|
764
|
+
"../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/address/getAddress.js"() {
|
|
765
|
+
init_address();
|
|
766
|
+
init_toBytes();
|
|
767
|
+
init_keccak256();
|
|
768
|
+
init_lru();
|
|
769
|
+
init_isAddress();
|
|
770
|
+
checksumAddressCache = /* @__PURE__ */ new LruMap(8192);
|
|
771
|
+
}
|
|
772
|
+
});
|
|
773
|
+
|
|
774
|
+
// ../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/address/isAddress.js
|
|
775
|
+
function isAddress(address, options) {
|
|
776
|
+
const { strict = true } = options ?? {};
|
|
777
|
+
const cacheKey = `${address}.${strict}`;
|
|
778
|
+
if (isAddressCache.has(cacheKey))
|
|
779
|
+
return isAddressCache.get(cacheKey);
|
|
780
|
+
const result = (() => {
|
|
781
|
+
if (!addressRegex.test(address))
|
|
782
|
+
return false;
|
|
783
|
+
if (address.toLowerCase() === address)
|
|
784
|
+
return true;
|
|
785
|
+
if (strict)
|
|
786
|
+
return checksumAddress(address) === address;
|
|
787
|
+
return true;
|
|
788
|
+
})();
|
|
789
|
+
isAddressCache.set(cacheKey, result);
|
|
790
|
+
return result;
|
|
791
|
+
}
|
|
792
|
+
var addressRegex, isAddressCache;
|
|
793
|
+
var init_isAddress = __esm({
|
|
794
|
+
"../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/utils/address/isAddress.js"() {
|
|
795
|
+
init_lru();
|
|
796
|
+
init_getAddress();
|
|
797
|
+
addressRegex = /^0x[a-fA-F0-9]{40}$/;
|
|
798
|
+
isAddressCache = /* @__PURE__ */ new LruMap(8192);
|
|
799
|
+
}
|
|
800
|
+
});
|
|
801
|
+
|
|
802
|
+
// ../../node_modules/.pnpm/viem@2.55.10_bufferutil@4.1.0_typescript@6.0.3_utf-8-validate@6.0.6_zod@4.3.6/node_modules/viem/_esm/index.js
|
|
803
|
+
init_getAddress();
|
|
804
|
+
init_toHex();
|
|
805
|
+
|
|
806
|
+
// ../x402-client/src/networks.ts
|
|
807
|
+
var BASE_MAINNET_CAIP2 = "eip155:8453";
|
|
808
|
+
var ARC_TESTNET_CAIP2 = "eip155:5042002";
|
|
809
|
+
function canonicalIdentity(usdc, eip712Domain) {
|
|
810
|
+
return Object.freeze({
|
|
811
|
+
usdc: getAddress(usdc.toLowerCase()),
|
|
812
|
+
eip712Domain: Object.freeze({ ...eip712Domain })
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
var baseMainnetUsdc = canonicalIdentity("0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", {
|
|
816
|
+
name: "USD Coin",
|
|
817
|
+
version: "2"
|
|
818
|
+
});
|
|
819
|
+
var arcTestnetUsdc = canonicalIdentity("0x3600000000000000000000000000000000000000", {
|
|
820
|
+
name: "USDC",
|
|
821
|
+
version: "2"
|
|
822
|
+
});
|
|
823
|
+
var CANONICAL_X402_USDC_NETWORKS = Object.freeze({
|
|
824
|
+
[BASE_MAINNET_CAIP2]: baseMainnetUsdc,
|
|
825
|
+
[ARC_TESTNET_CAIP2]: arcTestnetUsdc
|
|
826
|
+
});
|
|
827
|
+
function getCanonicalX402Usdc(network) {
|
|
828
|
+
if (!Object.hasOwn(CANONICAL_X402_USDC_NETWORKS, network)) {
|
|
829
|
+
return void 0;
|
|
830
|
+
}
|
|
831
|
+
return CANONICAL_X402_USDC_NETWORKS[network];
|
|
832
|
+
}
|
|
833
|
+
function browserNetwork(identity) {
|
|
834
|
+
return Object.freeze({
|
|
835
|
+
usdc: identity.usdc,
|
|
836
|
+
enabled: true,
|
|
837
|
+
eip712Domain: identity.eip712Domain
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
var BROWSER_ENABLED_X402_NETWORK_CONFIG = Object.freeze({
|
|
841
|
+
[BASE_MAINNET_CAIP2]: browserNetwork(baseMainnetUsdc),
|
|
842
|
+
[ARC_TESTNET_CAIP2]: browserNetwork(arcTestnetUsdc)
|
|
843
|
+
});
|
|
844
|
+
|
|
845
|
+
// ../x402-client/src/index.ts
|
|
846
|
+
var MAX_CHALLENGE_BYTES = 1048576;
|
|
847
|
+
var MAX_UINT256 = (1n << 256n) - 1n;
|
|
848
|
+
var MAX_METADATA_DEPTH = 8;
|
|
849
|
+
var MAX_METADATA_ENTRIES = 256;
|
|
850
|
+
var MAX_METADATA_KEYS_PER_OBJECT = 64;
|
|
851
|
+
var MAX_METADATA_ARRAY_LENGTH = 64;
|
|
852
|
+
var MAX_METADATA_STRING_LENGTH = 16384;
|
|
853
|
+
var EIP3009_AUTHORIZATION_TYPES = {
|
|
854
|
+
TransferWithAuthorization: [
|
|
855
|
+
{ name: "from", type: "address" },
|
|
856
|
+
{ name: "to", type: "address" },
|
|
857
|
+
{ name: "value", type: "uint256" },
|
|
858
|
+
{ name: "validAfter", type: "uint256" },
|
|
859
|
+
{ name: "validBefore", type: "uint256" },
|
|
860
|
+
{ name: "nonce", type: "bytes32" }
|
|
861
|
+
]
|
|
862
|
+
};
|
|
863
|
+
var X402Error = class extends Error {
|
|
864
|
+
constructor(code, message, options) {
|
|
865
|
+
super(message, options);
|
|
866
|
+
this.code = code;
|
|
867
|
+
this.name = "X402Error";
|
|
868
|
+
}
|
|
869
|
+
code;
|
|
870
|
+
};
|
|
871
|
+
function parse402Challenge(challenge, configuredNetworks, fallbackResourceUrl = "", requiredNetwork, expectedPayTo) {
|
|
872
|
+
if (!isRecord(challenge) || !Array.isArray(challenge.accepts)) {
|
|
873
|
+
throw new X402Error("invalid_challenge", "x402 challenge has no accepts array.");
|
|
874
|
+
}
|
|
875
|
+
if (challenge.x402Version !== void 0 && challenge.x402Version !== 2) {
|
|
876
|
+
throw new X402Error(
|
|
877
|
+
"unsupported_challenge",
|
|
878
|
+
`Unsupported x402 version: ${String(challenge.x402Version)}.`
|
|
879
|
+
);
|
|
880
|
+
}
|
|
881
|
+
const candidates = challenge.accepts.filter(isRecord);
|
|
882
|
+
const accepted = candidates.find((candidate) => {
|
|
883
|
+
const network2 = readString(candidate, "network");
|
|
884
|
+
const scheme = readString(candidate, "scheme");
|
|
885
|
+
if (scheme !== "exact" || !network2 || requiredNetwork && network2 !== requiredNetwork) {
|
|
886
|
+
return false;
|
|
887
|
+
}
|
|
888
|
+
const configured = configuredNetworks[network2];
|
|
889
|
+
if (!configured || configured.enabled === false) {
|
|
890
|
+
return false;
|
|
891
|
+
}
|
|
892
|
+
const asset2 = readString(candidate, "asset");
|
|
893
|
+
const payTo2 = readString(candidate, "payTo");
|
|
894
|
+
const amount = readAmount(candidate);
|
|
895
|
+
const maxTimeoutSeconds2 = readPositiveInteger(candidate.maxTimeoutSeconds);
|
|
896
|
+
const extra2 = readBoundedJsonRecord(candidate.extra);
|
|
897
|
+
const name2 = extra2 ? readString(extra2, "name") : null;
|
|
898
|
+
const version3 = extra2 ? readString(extra2, "version") : null;
|
|
899
|
+
const tokenDomain = canonicalTokenDomain(network2, configured);
|
|
900
|
+
if (!asset2 || !payTo2 || amount === null || maxTimeoutSeconds2 === null || !extra2 || !name2 || !version3 || !tokenDomain || name2 !== tokenDomain.name || version3 !== tokenDomain.version || extra2.assetTransferMethod !== void 0 && extra2.assetTransferMethod !== "eip3009") {
|
|
901
|
+
return false;
|
|
902
|
+
}
|
|
903
|
+
try {
|
|
904
|
+
return getAddress(asset2) === getAddress(configured.usdc) && (!expectedPayTo || getAddress(payTo2) === getAddress(expectedPayTo));
|
|
905
|
+
} catch {
|
|
906
|
+
return false;
|
|
907
|
+
}
|
|
908
|
+
});
|
|
909
|
+
if (!accepted) {
|
|
910
|
+
const offered = candidates.map(
|
|
911
|
+
(candidate) => `${readString(candidate, "scheme") ?? "?"}/${readString(candidate, "network") ?? "?"}`
|
|
912
|
+
).join(", ");
|
|
913
|
+
const expected = requiredNetwork ? `required network ${requiredNetwork} and its configured USDC asset` : "a configured network and USDC asset";
|
|
914
|
+
throw new X402Error(
|
|
915
|
+
"unsupported_challenge",
|
|
916
|
+
`No exact x402 payment option matches ${expected}${offered ? ` (offered: ${offered})` : ""}.`
|
|
917
|
+
);
|
|
918
|
+
}
|
|
919
|
+
const network = readString(accepted, "network");
|
|
920
|
+
const asset = readString(accepted, "asset");
|
|
921
|
+
const payTo = readString(accepted, "payTo");
|
|
922
|
+
const amountAtomic = readAmount(accepted);
|
|
923
|
+
const maxTimeoutSeconds = readPositiveInteger(accepted.maxTimeoutSeconds);
|
|
924
|
+
const extra = readBoundedJsonRecord(accepted.extra);
|
|
925
|
+
const name = extra ? readString(extra, "name") : null;
|
|
926
|
+
const version2 = extra ? readString(extra, "version") : null;
|
|
927
|
+
if (!network || !asset || !payTo || amountAtomic === null || maxTimeoutSeconds === null || !extra || !name || !version2) {
|
|
928
|
+
throw new X402Error(
|
|
929
|
+
"invalid_challenge",
|
|
930
|
+
"x402 exact payment option is missing amount, asset, payTo, maxTimeoutSeconds, or EIP-712 domain fields."
|
|
931
|
+
);
|
|
932
|
+
}
|
|
933
|
+
let resource = readResource(challenge.resource, fallbackResourceUrl);
|
|
934
|
+
if (!resource.url) resource = readResource(accepted.resource, fallbackResourceUrl);
|
|
935
|
+
if (!resource.url) {
|
|
936
|
+
throw new X402Error("invalid_challenge", "x402 challenge is missing its resource URL.");
|
|
937
|
+
}
|
|
938
|
+
const extensions = challenge.extensions === void 0 ? void 0 : readBoundedJsonRecord(challenge.extensions);
|
|
939
|
+
if (challenge.extensions !== void 0 && !extensions) {
|
|
940
|
+
throw new X402Error(
|
|
941
|
+
"invalid_challenge",
|
|
942
|
+
"x402 challenge extensions exceed the supported JSON metadata limits."
|
|
943
|
+
);
|
|
944
|
+
}
|
|
945
|
+
try {
|
|
946
|
+
parseEip155ChainId(network);
|
|
947
|
+
return {
|
|
948
|
+
x402Version: 2,
|
|
949
|
+
amountAtomic,
|
|
950
|
+
resource,
|
|
951
|
+
accepted: {
|
|
952
|
+
scheme: "exact",
|
|
953
|
+
network,
|
|
954
|
+
asset: getAddress(asset),
|
|
955
|
+
amount: amountAtomic.toString(),
|
|
956
|
+
payTo: getAddress(payTo),
|
|
957
|
+
maxTimeoutSeconds,
|
|
958
|
+
extra: { ...extra, name, version: version2 }
|
|
959
|
+
},
|
|
960
|
+
...extensions ? { extensions } : {}
|
|
961
|
+
};
|
|
962
|
+
} catch (error) {
|
|
963
|
+
if (error instanceof X402Error) throw error;
|
|
964
|
+
throw new X402Error(
|
|
965
|
+
"invalid_challenge",
|
|
966
|
+
"x402 challenge contains an invalid network or address.",
|
|
967
|
+
{ cause: error }
|
|
968
|
+
);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
async function parse402Response(response, configuredNetworks, requiredNetwork, expectedPayTo) {
|
|
972
|
+
const header = response.headers.get("payment-required");
|
|
973
|
+
let headerError;
|
|
974
|
+
if (header) {
|
|
975
|
+
try {
|
|
976
|
+
const quote = parse402Challenge(
|
|
977
|
+
decodeBase64Json(header),
|
|
978
|
+
configuredNetworks,
|
|
979
|
+
response.url,
|
|
980
|
+
requiredNetwork,
|
|
981
|
+
expectedPayTo
|
|
982
|
+
);
|
|
983
|
+
await response.body?.cancel().catch(() => void 0);
|
|
984
|
+
return quote;
|
|
985
|
+
} catch (error) {
|
|
986
|
+
headerError = error;
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
try {
|
|
990
|
+
return parse402Challenge(
|
|
991
|
+
await readBoundedJson(response, MAX_CHALLENGE_BYTES),
|
|
992
|
+
configuredNetworks,
|
|
993
|
+
response.url,
|
|
994
|
+
requiredNetwork,
|
|
995
|
+
expectedPayTo
|
|
996
|
+
);
|
|
997
|
+
} catch (error) {
|
|
998
|
+
if (headerError instanceof X402Error) throw headerError;
|
|
999
|
+
if (error instanceof X402Error) throw error;
|
|
1000
|
+
throw new X402Error(
|
|
1001
|
+
"invalid_challenge",
|
|
1002
|
+
"x402 402 response has neither a valid payment-required header nor a JSON accepts[] body.",
|
|
1003
|
+
{ cause: error }
|
|
1004
|
+
);
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
async function readBoundedJson(response, maximumBytes) {
|
|
1008
|
+
if (!response.body) throw new Error("x402 response body is empty.");
|
|
1009
|
+
const reader = response.body.getReader();
|
|
1010
|
+
const chunks = [];
|
|
1011
|
+
let total = 0;
|
|
1012
|
+
while (true) {
|
|
1013
|
+
const next = await reader.read();
|
|
1014
|
+
if (next.done) break;
|
|
1015
|
+
total += next.value.byteLength;
|
|
1016
|
+
if (total > maximumBytes) {
|
|
1017
|
+
await reader.cancel();
|
|
1018
|
+
throw new Error(`x402 response exceeds ${maximumBytes} bytes.`);
|
|
1019
|
+
}
|
|
1020
|
+
chunks.push(next.value);
|
|
1021
|
+
}
|
|
1022
|
+
const bytes = new Uint8Array(total);
|
|
1023
|
+
let offset = 0;
|
|
1024
|
+
for (const chunk of chunks) {
|
|
1025
|
+
bytes.set(chunk, offset);
|
|
1026
|
+
offset += chunk.byteLength;
|
|
1027
|
+
}
|
|
1028
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
1029
|
+
}
|
|
1030
|
+
var MAX_AUTHORIZATION_WINDOW_SECONDS = 600;
|
|
1031
|
+
function buildEip3009TypedData(args) {
|
|
1032
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(args.nonce)) {
|
|
1033
|
+
throw new Error("EIP-3009 nonce must be a random 32-byte hex value.");
|
|
1034
|
+
}
|
|
1035
|
+
if (!Number.isSafeInteger(args.nowSeconds) || args.nowSeconds < 0) {
|
|
1036
|
+
throw new Error("nowSeconds must be a non-negative integer.");
|
|
1037
|
+
}
|
|
1038
|
+
const windowSeconds = Math.min(
|
|
1039
|
+
MAX_AUTHORIZATION_WINDOW_SECONDS,
|
|
1040
|
+
args.quote.accepted.maxTimeoutSeconds
|
|
1041
|
+
);
|
|
1042
|
+
const authorization = {
|
|
1043
|
+
from: getAddress(args.from),
|
|
1044
|
+
to: args.quote.accepted.payTo,
|
|
1045
|
+
value: args.quote.amountAtomic.toString(),
|
|
1046
|
+
validAfter: "0",
|
|
1047
|
+
validBefore: (args.nowSeconds + windowSeconds).toString(),
|
|
1048
|
+
nonce: args.nonce
|
|
1049
|
+
};
|
|
1050
|
+
return {
|
|
1051
|
+
authorization,
|
|
1052
|
+
typedData: {
|
|
1053
|
+
domain: {
|
|
1054
|
+
name: args.quote.accepted.extra.name,
|
|
1055
|
+
version: args.quote.accepted.extra.version,
|
|
1056
|
+
chainId: parseEip155ChainId(args.quote.accepted.network),
|
|
1057
|
+
verifyingContract: args.quote.accepted.asset
|
|
1058
|
+
},
|
|
1059
|
+
types: EIP3009_AUTHORIZATION_TYPES,
|
|
1060
|
+
primaryType: "TransferWithAuthorization",
|
|
1061
|
+
message: {
|
|
1062
|
+
from: authorization.from,
|
|
1063
|
+
to: authorization.to,
|
|
1064
|
+
value: BigInt(authorization.value),
|
|
1065
|
+
validAfter: 0n,
|
|
1066
|
+
validBefore: BigInt(authorization.validBefore),
|
|
1067
|
+
nonce: authorization.nonce
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
};
|
|
1071
|
+
}
|
|
1072
|
+
async function buildX402Payment(args) {
|
|
1073
|
+
const nonce = args.nonce ?? randomNonce();
|
|
1074
|
+
const { authorization, typedData } = buildEip3009TypedData({
|
|
1075
|
+
from: args.signer.address,
|
|
1076
|
+
quote: args.quote,
|
|
1077
|
+
nonce,
|
|
1078
|
+
nowSeconds: args.nowSeconds ?? Math.floor(Date.now() / 1e3)
|
|
1079
|
+
});
|
|
1080
|
+
const signature = await args.signer.signTypedData(typedData);
|
|
1081
|
+
const payload = {
|
|
1082
|
+
x402Version: 2,
|
|
1083
|
+
resource: args.quote.resource,
|
|
1084
|
+
accepted: args.quote.accepted,
|
|
1085
|
+
payload: { signature, authorization },
|
|
1086
|
+
...args.quote.extensions ? { extensions: args.quote.extensions } : {}
|
|
1087
|
+
};
|
|
1088
|
+
return {
|
|
1089
|
+
payload,
|
|
1090
|
+
headers: {
|
|
1091
|
+
"PAYMENT-SIGNATURE": encodeBase64Json(payload)
|
|
1092
|
+
}
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
function assertMaxPrice(amountAtomic, maxPriceUsd) {
|
|
1096
|
+
if (maxPriceUsd === void 0) return;
|
|
1097
|
+
const maxAtomic = usdToAtomic(maxPriceUsd);
|
|
1098
|
+
if (amountAtomic > maxAtomic) {
|
|
1099
|
+
throw new X402Error(
|
|
1100
|
+
"max_price_exceeded",
|
|
1101
|
+
`x402 quote ${amountAtomic} atomic USDC exceeds maxPriceUsd ${maxPriceUsd} (${maxAtomic} atomic). Refusing to sign.`
|
|
1102
|
+
);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
function usdToAtomic(value) {
|
|
1106
|
+
const normalized = typeof value === "number" ? String(value) : value.trim();
|
|
1107
|
+
if (!/^\d+(?:\.\d{1,6})?$/.test(normalized)) {
|
|
1108
|
+
throw new Error("maxPriceUsd must be a non-negative USD amount with at most 6 decimals.");
|
|
1109
|
+
}
|
|
1110
|
+
const [whole = "0", fraction = ""] = normalized.split(".");
|
|
1111
|
+
return BigInt(whole) * 1000000n + BigInt(fraction.padEnd(6, "0"));
|
|
1112
|
+
}
|
|
1113
|
+
function parseSettlementResponse(headers) {
|
|
1114
|
+
const encoded = headers.get("payment-response");
|
|
1115
|
+
if (encoded) {
|
|
1116
|
+
try {
|
|
1117
|
+
return decodeBase64Json(encoded);
|
|
1118
|
+
} catch {
|
|
1119
|
+
return null;
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
const compatible = headers.get("x-payment-response");
|
|
1123
|
+
if (!compatible) return null;
|
|
1124
|
+
try {
|
|
1125
|
+
return JSON.parse(compatible);
|
|
1126
|
+
} catch {
|
|
1127
|
+
try {
|
|
1128
|
+
return decodeBase64Json(compatible);
|
|
1129
|
+
} catch {
|
|
1130
|
+
return null;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
function classifySettlement(value) {
|
|
1135
|
+
if (!isRecord(value) || typeof value.success !== "boolean") {
|
|
1136
|
+
return "unknown";
|
|
1137
|
+
}
|
|
1138
|
+
return value.success ? "succeeded" : "rejected";
|
|
1139
|
+
}
|
|
1140
|
+
function parseEip155ChainId(network) {
|
|
1141
|
+
const match = /^eip155:(\d+)$/.exec(network);
|
|
1142
|
+
const chainId = match ? Number(match[1]) : Number.NaN;
|
|
1143
|
+
if (!Number.isSafeInteger(chainId) || chainId <= 0) {
|
|
1144
|
+
throw new Error(`Invalid EIP-155 network identifier: ${network}.`);
|
|
1145
|
+
}
|
|
1146
|
+
return chainId;
|
|
1147
|
+
}
|
|
1148
|
+
function randomNonce() {
|
|
1149
|
+
const bytes = new Uint8Array(32);
|
|
1150
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
1151
|
+
return bytesToHex(bytes);
|
|
1152
|
+
}
|
|
1153
|
+
function readAmount(value) {
|
|
1154
|
+
const raw = value.amount ?? value.maxAmountRequired;
|
|
1155
|
+
let parsed;
|
|
1156
|
+
if (typeof raw === "string") {
|
|
1157
|
+
if (raw.length === 0 || raw.length > 78 || !/^\d+$/.test(raw)) return null;
|
|
1158
|
+
parsed = BigInt(raw);
|
|
1159
|
+
} else if (typeof raw === "number" && Number.isSafeInteger(raw) && raw > 0) {
|
|
1160
|
+
parsed = BigInt(raw);
|
|
1161
|
+
} else if (typeof raw === "bigint" && raw > 0n) {
|
|
1162
|
+
parsed = raw;
|
|
1163
|
+
} else {
|
|
1164
|
+
return null;
|
|
1165
|
+
}
|
|
1166
|
+
if (parsed === 0n || parsed > MAX_UINT256) return null;
|
|
1167
|
+
return parsed;
|
|
1168
|
+
}
|
|
1169
|
+
function readPositiveInteger(value) {
|
|
1170
|
+
if (typeof value === "number" && Number.isSafeInteger(value) && value > 0) return value;
|
|
1171
|
+
if (typeof value === "string" && /^\d+$/.test(value)) {
|
|
1172
|
+
const parsed = Number(value);
|
|
1173
|
+
return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : null;
|
|
1174
|
+
}
|
|
1175
|
+
return null;
|
|
1176
|
+
}
|
|
1177
|
+
function canonicalTokenDomain(network, configured) {
|
|
1178
|
+
const canonical = getCanonicalX402Usdc(network);
|
|
1179
|
+
try {
|
|
1180
|
+
if (canonical) {
|
|
1181
|
+
return getAddress(configured.usdc) === canonical.usdc ? canonical.eip712Domain : null;
|
|
1182
|
+
}
|
|
1183
|
+
} catch {
|
|
1184
|
+
return null;
|
|
1185
|
+
}
|
|
1186
|
+
const configuredDomain = configured.eip712Domain;
|
|
1187
|
+
if (!configuredDomain?.name || !configuredDomain.version) return null;
|
|
1188
|
+
return configuredDomain;
|
|
1189
|
+
}
|
|
1190
|
+
function readBoundedJsonRecord(value) {
|
|
1191
|
+
if (!isRecord(value)) return null;
|
|
1192
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
1193
|
+
const budget = { entries: 0 };
|
|
1194
|
+
try {
|
|
1195
|
+
const cloned = cloneBoundedJson(value, 0, seen, budget);
|
|
1196
|
+
return isRecord(cloned) ? cloned : null;
|
|
1197
|
+
} catch {
|
|
1198
|
+
return null;
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
function cloneBoundedJson(value, depth, seen, budget) {
|
|
1202
|
+
if (depth > MAX_METADATA_DEPTH || budget.entries >= MAX_METADATA_ENTRIES) {
|
|
1203
|
+
throw new Error("x402 metadata exceeds its structural limit.");
|
|
1204
|
+
}
|
|
1205
|
+
budget.entries += 1;
|
|
1206
|
+
if (value === null || typeof value === "boolean") return value;
|
|
1207
|
+
if (typeof value === "string") {
|
|
1208
|
+
if (value.length > MAX_METADATA_STRING_LENGTH) {
|
|
1209
|
+
throw new Error("x402 metadata string is too long.");
|
|
1210
|
+
}
|
|
1211
|
+
return value;
|
|
1212
|
+
}
|
|
1213
|
+
if (typeof value === "number") {
|
|
1214
|
+
if (!Number.isFinite(value)) throw new Error("x402 metadata number must be finite.");
|
|
1215
|
+
return value;
|
|
1216
|
+
}
|
|
1217
|
+
if (typeof value !== "object") {
|
|
1218
|
+
throw new Error("x402 metadata must be JSON-compatible.");
|
|
1219
|
+
}
|
|
1220
|
+
if (seen.has(value)) throw new Error("x402 metadata must not contain cycles.");
|
|
1221
|
+
seen.add(value);
|
|
1222
|
+
if (Array.isArray(value)) {
|
|
1223
|
+
if (value.length > MAX_METADATA_ARRAY_LENGTH) {
|
|
1224
|
+
throw new Error("x402 metadata array is too long.");
|
|
1225
|
+
}
|
|
1226
|
+
return value.map((item) => cloneBoundedJson(item, depth + 1, seen, budget));
|
|
1227
|
+
}
|
|
1228
|
+
const keys = Object.keys(value);
|
|
1229
|
+
if (keys.length > MAX_METADATA_KEYS_PER_OBJECT) {
|
|
1230
|
+
throw new Error("x402 metadata object has too many keys.");
|
|
1231
|
+
}
|
|
1232
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
1233
|
+
for (const key of keys) {
|
|
1234
|
+
if (key.length > 256) throw new Error("x402 metadata key is too long.");
|
|
1235
|
+
result[key] = cloneBoundedJson(
|
|
1236
|
+
value[key],
|
|
1237
|
+
depth + 1,
|
|
1238
|
+
seen,
|
|
1239
|
+
budget
|
|
1240
|
+
);
|
|
1241
|
+
}
|
|
1242
|
+
return result;
|
|
1243
|
+
}
|
|
1244
|
+
function readResource(value, fallbackUrl) {
|
|
1245
|
+
if (typeof value === "string") return { url: value };
|
|
1246
|
+
if (!isRecord(value)) return { url: fallbackUrl };
|
|
1247
|
+
const url = readString(value, "url") ?? fallbackUrl;
|
|
1248
|
+
return {
|
|
1249
|
+
url,
|
|
1250
|
+
...readString(value, "description") ? { description: readString(value, "description") } : {},
|
|
1251
|
+
...readString(value, "mimeType") ? { mimeType: readString(value, "mimeType") } : {},
|
|
1252
|
+
...readString(value, "serviceName") ? { serviceName: readString(value, "serviceName") } : {},
|
|
1253
|
+
...Array.isArray(value.tags) && value.tags.every((tag) => typeof tag === "string") ? { tags: value.tags } : {},
|
|
1254
|
+
...readString(value, "iconUrl") ? { iconUrl: readString(value, "iconUrl") } : {}
|
|
1255
|
+
};
|
|
1256
|
+
}
|
|
1257
|
+
function readString(value, key) {
|
|
1258
|
+
const field = value[key];
|
|
1259
|
+
return typeof field === "string" && field.length > 0 ? field : null;
|
|
1260
|
+
}
|
|
1261
|
+
function isRecord(value) {
|
|
1262
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1263
|
+
}
|
|
1264
|
+
function decodeBase64Json(value) {
|
|
1265
|
+
const bytes = Uint8Array.from(globalThis.atob(value), (character) => character.charCodeAt(0));
|
|
1266
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
1267
|
+
}
|
|
1268
|
+
function encodeBase64Json(value) {
|
|
1269
|
+
const bytes = new TextEncoder().encode(JSON.stringify(value));
|
|
1270
|
+
let binary = "";
|
|
1271
|
+
for (let offset = 0; offset < bytes.length; offset += 32768) {
|
|
1272
|
+
binary += String.fromCharCode(...bytes.subarray(offset, offset + 32768));
|
|
1273
|
+
}
|
|
1274
|
+
return globalThis.btoa(binary);
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
// src/x402.ts
|
|
1278
|
+
function toSharedNetworks(networks) {
|
|
1279
|
+
return Object.fromEntries(
|
|
1280
|
+
Object.entries(networks).map(([network, configured]) => [
|
|
1281
|
+
network,
|
|
1282
|
+
{
|
|
1283
|
+
usdc: configured.usdc,
|
|
1284
|
+
enabled: Boolean(configured.rpcUrl.trim()),
|
|
1285
|
+
...configured.eip712Domain ? { eip712Domain: configured.eip712Domain } : {}
|
|
1286
|
+
}
|
|
1287
|
+
])
|
|
1288
|
+
);
|
|
1289
|
+
}
|
|
1290
|
+
function parse402Challenge2(challenge, configuredNetworks, fallbackResourceUrl = "", requiredNetwork, expectedPayTo) {
|
|
1291
|
+
return parse402Challenge(
|
|
1292
|
+
challenge,
|
|
1293
|
+
toSharedNetworks(configuredNetworks),
|
|
1294
|
+
fallbackResourceUrl,
|
|
1295
|
+
requiredNetwork,
|
|
1296
|
+
expectedPayTo
|
|
1297
|
+
);
|
|
1298
|
+
}
|
|
1299
|
+
async function parse402Response2(response, configuredNetworks, requiredNetwork, expectedPayTo) {
|
|
1300
|
+
return await parse402Response(
|
|
1301
|
+
response,
|
|
1302
|
+
toSharedNetworks(configuredNetworks),
|
|
1303
|
+
requiredNetwork,
|
|
1304
|
+
expectedPayTo
|
|
1305
|
+
);
|
|
1306
|
+
}
|
|
1307
|
+
async function buildX402Payment2(args) {
|
|
1308
|
+
const payment = await buildX402Payment({
|
|
1309
|
+
signer: args.account,
|
|
1310
|
+
quote: args.quote,
|
|
1311
|
+
...args.nowSeconds === void 0 ? {} : { nowSeconds: args.nowSeconds },
|
|
1312
|
+
...args.nonce === void 0 ? {} : { nonce: args.nonce }
|
|
1313
|
+
});
|
|
1314
|
+
return {
|
|
1315
|
+
payload: payment.payload,
|
|
1316
|
+
headers: {
|
|
1317
|
+
...payment.headers,
|
|
1318
|
+
"X-PAYMENT": JSON.stringify({
|
|
1319
|
+
x402Version: 2,
|
|
1320
|
+
scheme: args.quote.accepted.scheme,
|
|
1321
|
+
network: args.quote.accepted.network,
|
|
1322
|
+
payload: payment.payload.payload
|
|
1323
|
+
})
|
|
1324
|
+
}
|
|
1325
|
+
};
|
|
1326
|
+
}
|
|
1327
|
+
export {
|
|
1328
|
+
EIP3009_AUTHORIZATION_TYPES,
|
|
1329
|
+
X402Error,
|
|
1330
|
+
assertMaxPrice,
|
|
1331
|
+
buildEip3009TypedData,
|
|
1332
|
+
buildX402Payment2 as buildX402Payment,
|
|
1333
|
+
classifySettlement,
|
|
1334
|
+
parse402Challenge2 as parse402Challenge,
|
|
1335
|
+
parse402Response2 as parse402Response,
|
|
1336
|
+
parseSettlementResponse,
|
|
1337
|
+
usdToAtomic
|
|
1338
|
+
};
|
|
1339
|
+
//# sourceMappingURL=x402.js.map
|