stablezact-pay 0.66.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 +36 -0
- package/dist/CoinleyPayment-BA2ym_mw.js +31105 -0
- package/dist/Logomark.png +0 -0
- package/dist/QRCodePayment-C50CNuFu.js +860 -0
- package/dist/appKitEVM--bpTC7Do.js +138 -0
- package/dist/appKitSolana-DUo_eFgJ.js +309 -0
- package/dist/coinley-vanilla.min.js +18324 -0
- package/dist/index-BTn5xw-W.js +302 -0
- package/dist/index-DYkC2Bui.js +24126 -0
- package/dist/index.esm.js +33 -0
- package/dist/index.umd.js +23 -0
- package/dist/polygon-C-1Q5KDX.js +2778 -0
- package/dist/style.css +1 -0
- package/dist/vite.svg +1 -0
- package/package.json +90 -0
|
@@ -0,0 +1,2778 @@
|
|
|
1
|
+
function defineChain(chain) {
|
|
2
|
+
const chainInstance = {
|
|
3
|
+
formatters: void 0,
|
|
4
|
+
fees: void 0,
|
|
5
|
+
serializers: void 0,
|
|
6
|
+
...chain
|
|
7
|
+
};
|
|
8
|
+
function extend(base) {
|
|
9
|
+
return (fnOrExtended) => {
|
|
10
|
+
const properties = typeof fnOrExtended === "function" ? fnOrExtended(base) : fnOrExtended;
|
|
11
|
+
const combined = { ...base, ...properties };
|
|
12
|
+
return Object.assign(combined, { extend: extend(combined) });
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
return Object.assign(chainInstance, {
|
|
16
|
+
extend: extend(chainInstance)
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const version = "2.45.0";
|
|
20
|
+
let errorConfig = {
|
|
21
|
+
getDocsUrl: ({ docsBaseUrl, docsPath = "", docsSlug }) => docsPath ? `${docsBaseUrl ?? "https://viem.sh"}${docsPath}${docsSlug ? `#${docsSlug}` : ""}` : void 0,
|
|
22
|
+
version: `viem@${version}`
|
|
23
|
+
};
|
|
24
|
+
class BaseError extends Error {
|
|
25
|
+
constructor(shortMessage, args = {}) {
|
|
26
|
+
var _a;
|
|
27
|
+
const details = (() => {
|
|
28
|
+
var _a2;
|
|
29
|
+
if (args.cause instanceof BaseError)
|
|
30
|
+
return args.cause.details;
|
|
31
|
+
if ((_a2 = args.cause) == null ? void 0 : _a2.message)
|
|
32
|
+
return args.cause.message;
|
|
33
|
+
return args.details;
|
|
34
|
+
})();
|
|
35
|
+
const docsPath = (() => {
|
|
36
|
+
if (args.cause instanceof BaseError)
|
|
37
|
+
return args.cause.docsPath || args.docsPath;
|
|
38
|
+
return args.docsPath;
|
|
39
|
+
})();
|
|
40
|
+
const docsUrl = (_a = errorConfig.getDocsUrl) == null ? void 0 : _a.call(errorConfig, { ...args, docsPath });
|
|
41
|
+
const message = [
|
|
42
|
+
shortMessage || "An error occurred.",
|
|
43
|
+
"",
|
|
44
|
+
...args.metaMessages ? [...args.metaMessages, ""] : [],
|
|
45
|
+
...docsUrl ? [`Docs: ${docsUrl}`] : [],
|
|
46
|
+
...details ? [`Details: ${details}`] : [],
|
|
47
|
+
...errorConfig.version ? [`Version: ${errorConfig.version}`] : []
|
|
48
|
+
].join("\n");
|
|
49
|
+
super(message, args.cause ? { cause: args.cause } : void 0);
|
|
50
|
+
Object.defineProperty(this, "details", {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
configurable: true,
|
|
53
|
+
writable: true,
|
|
54
|
+
value: void 0
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(this, "docsPath", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true,
|
|
59
|
+
writable: true,
|
|
60
|
+
value: void 0
|
|
61
|
+
});
|
|
62
|
+
Object.defineProperty(this, "metaMessages", {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
configurable: true,
|
|
65
|
+
writable: true,
|
|
66
|
+
value: void 0
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(this, "shortMessage", {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
configurable: true,
|
|
71
|
+
writable: true,
|
|
72
|
+
value: void 0
|
|
73
|
+
});
|
|
74
|
+
Object.defineProperty(this, "version", {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
configurable: true,
|
|
77
|
+
writable: true,
|
|
78
|
+
value: void 0
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(this, "name", {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
configurable: true,
|
|
83
|
+
writable: true,
|
|
84
|
+
value: "BaseError"
|
|
85
|
+
});
|
|
86
|
+
this.details = details;
|
|
87
|
+
this.docsPath = docsPath;
|
|
88
|
+
this.metaMessages = args.metaMessages;
|
|
89
|
+
this.name = args.name ?? this.name;
|
|
90
|
+
this.shortMessage = shortMessage;
|
|
91
|
+
this.version = version;
|
|
92
|
+
}
|
|
93
|
+
walk(fn) {
|
|
94
|
+
return walk(this, fn);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function walk(err, fn) {
|
|
98
|
+
if (fn == null ? void 0 : fn(err))
|
|
99
|
+
return err;
|
|
100
|
+
if (err && typeof err === "object" && "cause" in err && err.cause !== void 0)
|
|
101
|
+
return walk(err.cause, fn);
|
|
102
|
+
return fn ? null : err;
|
|
103
|
+
}
|
|
104
|
+
class IntegerOutOfRangeError extends BaseError {
|
|
105
|
+
constructor({ max, min, signed, size: size2, value }) {
|
|
106
|
+
super(`Number "${value}" is not in safe ${size2 ? `${size2 * 8}-bit ${signed ? "signed" : "unsigned"} ` : ""}integer range ${max ? `(${min} to ${max})` : `(above ${min})`}`, { name: "IntegerOutOfRangeError" });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
class SizeOverflowError extends BaseError {
|
|
110
|
+
constructor({ givenSize, maxSize }) {
|
|
111
|
+
super(`Size cannot exceed ${maxSize} bytes. Given size: ${givenSize} bytes.`, { name: "SizeOverflowError" });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function isHex(value, { strict = true } = {}) {
|
|
115
|
+
if (!value)
|
|
116
|
+
return false;
|
|
117
|
+
if (typeof value !== "string")
|
|
118
|
+
return false;
|
|
119
|
+
return strict ? /^0x[0-9a-fA-F]*$/.test(value) : value.startsWith("0x");
|
|
120
|
+
}
|
|
121
|
+
function size(value) {
|
|
122
|
+
if (isHex(value, { strict: false }))
|
|
123
|
+
return Math.ceil((value.length - 2) / 2);
|
|
124
|
+
return value.length;
|
|
125
|
+
}
|
|
126
|
+
function trim(hexOrBytes, { dir = "left" } = {}) {
|
|
127
|
+
let data = typeof hexOrBytes === "string" ? hexOrBytes.replace("0x", "") : hexOrBytes;
|
|
128
|
+
let sliceLength = 0;
|
|
129
|
+
for (let i = 0; i < data.length - 1; i++) {
|
|
130
|
+
if (data[dir === "left" ? i : data.length - i - 1].toString() === "0")
|
|
131
|
+
sliceLength++;
|
|
132
|
+
else
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
data = dir === "left" ? data.slice(sliceLength) : data.slice(0, data.length - sliceLength);
|
|
136
|
+
if (typeof hexOrBytes === "string") {
|
|
137
|
+
if (data.length === 1 && dir === "right")
|
|
138
|
+
data = `${data}0`;
|
|
139
|
+
return `0x${data.length % 2 === 1 ? `0${data}` : data}`;
|
|
140
|
+
}
|
|
141
|
+
return data;
|
|
142
|
+
}
|
|
143
|
+
class SliceOffsetOutOfBoundsError extends BaseError {
|
|
144
|
+
constructor({ offset, position, size: size2 }) {
|
|
145
|
+
super(`Slice ${position === "start" ? "starting" : "ending"} at offset "${offset}" is out-of-bounds (size: ${size2}).`, { name: "SliceOffsetOutOfBoundsError" });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
class SizeExceedsPaddingSizeError extends BaseError {
|
|
149
|
+
constructor({ size: size2, targetSize, type }) {
|
|
150
|
+
super(`${type.charAt(0).toUpperCase()}${type.slice(1).toLowerCase()} size (${size2}) exceeds padding size (${targetSize}).`, { name: "SizeExceedsPaddingSizeError" });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function pad(hexOrBytes, { dir, size: size2 = 32 } = {}) {
|
|
154
|
+
if (typeof hexOrBytes === "string")
|
|
155
|
+
return padHex(hexOrBytes, { dir, size: size2 });
|
|
156
|
+
return padBytes(hexOrBytes, { dir, size: size2 });
|
|
157
|
+
}
|
|
158
|
+
function padHex(hex_, { dir, size: size2 = 32 } = {}) {
|
|
159
|
+
if (size2 === null)
|
|
160
|
+
return hex_;
|
|
161
|
+
const hex = hex_.replace("0x", "");
|
|
162
|
+
if (hex.length > size2 * 2)
|
|
163
|
+
throw new SizeExceedsPaddingSizeError({
|
|
164
|
+
size: Math.ceil(hex.length / 2),
|
|
165
|
+
targetSize: size2,
|
|
166
|
+
type: "hex"
|
|
167
|
+
});
|
|
168
|
+
return `0x${hex[dir === "right" ? "padEnd" : "padStart"](size2 * 2, "0")}`;
|
|
169
|
+
}
|
|
170
|
+
function padBytes(bytes, { dir, size: size2 = 32 } = {}) {
|
|
171
|
+
if (size2 === null)
|
|
172
|
+
return bytes;
|
|
173
|
+
if (bytes.length > size2)
|
|
174
|
+
throw new SizeExceedsPaddingSizeError({
|
|
175
|
+
size: bytes.length,
|
|
176
|
+
targetSize: size2,
|
|
177
|
+
type: "bytes"
|
|
178
|
+
});
|
|
179
|
+
const paddedBytes = new Uint8Array(size2);
|
|
180
|
+
for (let i = 0; i < size2; i++) {
|
|
181
|
+
const padEnd = dir === "right";
|
|
182
|
+
paddedBytes[padEnd ? i : size2 - i - 1] = bytes[padEnd ? i : bytes.length - i - 1];
|
|
183
|
+
}
|
|
184
|
+
return paddedBytes;
|
|
185
|
+
}
|
|
186
|
+
const hexes$1 = /* @__PURE__ */ Array.from({ length: 256 }, (_v, i) => i.toString(16).padStart(2, "0"));
|
|
187
|
+
function toHex(value, opts = {}) {
|
|
188
|
+
if (typeof value === "number" || typeof value === "bigint")
|
|
189
|
+
return numberToHex(value, opts);
|
|
190
|
+
if (typeof value === "string") {
|
|
191
|
+
return stringToHex(value, opts);
|
|
192
|
+
}
|
|
193
|
+
if (typeof value === "boolean")
|
|
194
|
+
return boolToHex(value, opts);
|
|
195
|
+
return bytesToHex$1(value, opts);
|
|
196
|
+
}
|
|
197
|
+
function boolToHex(value, opts = {}) {
|
|
198
|
+
const hex = `0x${Number(value)}`;
|
|
199
|
+
if (typeof opts.size === "number") {
|
|
200
|
+
assertSize(hex, { size: opts.size });
|
|
201
|
+
return pad(hex, { size: opts.size });
|
|
202
|
+
}
|
|
203
|
+
return hex;
|
|
204
|
+
}
|
|
205
|
+
function bytesToHex$1(value, opts = {}) {
|
|
206
|
+
let string = "";
|
|
207
|
+
for (let i = 0; i < value.length; i++) {
|
|
208
|
+
string += hexes$1[value[i]];
|
|
209
|
+
}
|
|
210
|
+
const hex = `0x${string}`;
|
|
211
|
+
if (typeof opts.size === "number") {
|
|
212
|
+
assertSize(hex, { size: opts.size });
|
|
213
|
+
return pad(hex, { dir: "right", size: opts.size });
|
|
214
|
+
}
|
|
215
|
+
return hex;
|
|
216
|
+
}
|
|
217
|
+
function numberToHex(value_, opts = {}) {
|
|
218
|
+
const { signed, size: size2 } = opts;
|
|
219
|
+
const value = BigInt(value_);
|
|
220
|
+
let maxValue;
|
|
221
|
+
if (size2) {
|
|
222
|
+
if (signed)
|
|
223
|
+
maxValue = (1n << BigInt(size2) * 8n - 1n) - 1n;
|
|
224
|
+
else
|
|
225
|
+
maxValue = 2n ** (BigInt(size2) * 8n) - 1n;
|
|
226
|
+
} else if (typeof value_ === "number") {
|
|
227
|
+
maxValue = BigInt(Number.MAX_SAFE_INTEGER);
|
|
228
|
+
}
|
|
229
|
+
const minValue = typeof maxValue === "bigint" && signed ? -maxValue - 1n : 0;
|
|
230
|
+
if (maxValue && value > maxValue || value < minValue) {
|
|
231
|
+
const suffix = typeof value_ === "bigint" ? "n" : "";
|
|
232
|
+
throw new IntegerOutOfRangeError({
|
|
233
|
+
max: maxValue ? `${maxValue}${suffix}` : void 0,
|
|
234
|
+
min: `${minValue}${suffix}`,
|
|
235
|
+
signed,
|
|
236
|
+
size: size2,
|
|
237
|
+
value: `${value_}${suffix}`
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
const hex = `0x${(signed && value < 0 ? (1n << BigInt(size2 * 8)) + BigInt(value) : value).toString(16)}`;
|
|
241
|
+
if (size2)
|
|
242
|
+
return pad(hex, { size: size2 });
|
|
243
|
+
return hex;
|
|
244
|
+
}
|
|
245
|
+
const encoder$1 = /* @__PURE__ */ new TextEncoder();
|
|
246
|
+
function stringToHex(value_, opts = {}) {
|
|
247
|
+
const value = encoder$1.encode(value_);
|
|
248
|
+
return bytesToHex$1(value, opts);
|
|
249
|
+
}
|
|
250
|
+
const encoder = /* @__PURE__ */ new TextEncoder();
|
|
251
|
+
function toBytes$1(value, opts = {}) {
|
|
252
|
+
if (typeof value === "number" || typeof value === "bigint")
|
|
253
|
+
return numberToBytes(value, opts);
|
|
254
|
+
if (typeof value === "boolean")
|
|
255
|
+
return boolToBytes(value, opts);
|
|
256
|
+
if (isHex(value))
|
|
257
|
+
return hexToBytes$1(value, opts);
|
|
258
|
+
return stringToBytes(value, opts);
|
|
259
|
+
}
|
|
260
|
+
function boolToBytes(value, opts = {}) {
|
|
261
|
+
const bytes = new Uint8Array(1);
|
|
262
|
+
bytes[0] = Number(value);
|
|
263
|
+
if (typeof opts.size === "number") {
|
|
264
|
+
assertSize(bytes, { size: opts.size });
|
|
265
|
+
return pad(bytes, { size: opts.size });
|
|
266
|
+
}
|
|
267
|
+
return bytes;
|
|
268
|
+
}
|
|
269
|
+
const charCodeMap = {
|
|
270
|
+
zero: 48,
|
|
271
|
+
nine: 57,
|
|
272
|
+
A: 65,
|
|
273
|
+
F: 70,
|
|
274
|
+
a: 97,
|
|
275
|
+
f: 102
|
|
276
|
+
};
|
|
277
|
+
function charCodeToBase16(char) {
|
|
278
|
+
if (char >= charCodeMap.zero && char <= charCodeMap.nine)
|
|
279
|
+
return char - charCodeMap.zero;
|
|
280
|
+
if (char >= charCodeMap.A && char <= charCodeMap.F)
|
|
281
|
+
return char - (charCodeMap.A - 10);
|
|
282
|
+
if (char >= charCodeMap.a && char <= charCodeMap.f)
|
|
283
|
+
return char - (charCodeMap.a - 10);
|
|
284
|
+
return void 0;
|
|
285
|
+
}
|
|
286
|
+
function hexToBytes$1(hex_, opts = {}) {
|
|
287
|
+
let hex = hex_;
|
|
288
|
+
if (opts.size) {
|
|
289
|
+
assertSize(hex, { size: opts.size });
|
|
290
|
+
hex = pad(hex, { dir: "right", size: opts.size });
|
|
291
|
+
}
|
|
292
|
+
let hexString = hex.slice(2);
|
|
293
|
+
if (hexString.length % 2)
|
|
294
|
+
hexString = `0${hexString}`;
|
|
295
|
+
const length = hexString.length / 2;
|
|
296
|
+
const bytes = new Uint8Array(length);
|
|
297
|
+
for (let index = 0, j = 0; index < length; index++) {
|
|
298
|
+
const nibbleLeft = charCodeToBase16(hexString.charCodeAt(j++));
|
|
299
|
+
const nibbleRight = charCodeToBase16(hexString.charCodeAt(j++));
|
|
300
|
+
if (nibbleLeft === void 0 || nibbleRight === void 0) {
|
|
301
|
+
throw new BaseError(`Invalid byte sequence ("${hexString[j - 2]}${hexString[j - 1]}" in "${hexString}").`);
|
|
302
|
+
}
|
|
303
|
+
bytes[index] = nibbleLeft * 16 + nibbleRight;
|
|
304
|
+
}
|
|
305
|
+
return bytes;
|
|
306
|
+
}
|
|
307
|
+
function numberToBytes(value, opts) {
|
|
308
|
+
const hex = numberToHex(value, opts);
|
|
309
|
+
return hexToBytes$1(hex);
|
|
310
|
+
}
|
|
311
|
+
function stringToBytes(value, opts = {}) {
|
|
312
|
+
const bytes = encoder.encode(value);
|
|
313
|
+
if (typeof opts.size === "number") {
|
|
314
|
+
assertSize(bytes, { size: opts.size });
|
|
315
|
+
return pad(bytes, { dir: "right", size: opts.size });
|
|
316
|
+
}
|
|
317
|
+
return bytes;
|
|
318
|
+
}
|
|
319
|
+
function assertSize(hexOrBytes, { size: size$1 }) {
|
|
320
|
+
if (size(hexOrBytes) > size$1)
|
|
321
|
+
throw new SizeOverflowError({
|
|
322
|
+
givenSize: size(hexOrBytes),
|
|
323
|
+
maxSize: size$1
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
function hexToBigInt(hex, opts = {}) {
|
|
327
|
+
const { signed } = opts;
|
|
328
|
+
if (opts.size)
|
|
329
|
+
assertSize(hex, { size: opts.size });
|
|
330
|
+
const value = BigInt(hex);
|
|
331
|
+
if (!signed)
|
|
332
|
+
return value;
|
|
333
|
+
const size2 = (hex.length - 2) / 2;
|
|
334
|
+
const max = (1n << BigInt(size2) * 8n - 1n) - 1n;
|
|
335
|
+
if (value <= max)
|
|
336
|
+
return value;
|
|
337
|
+
return value - BigInt(`0x${"f".padStart(size2 * 2, "f")}`) - 1n;
|
|
338
|
+
}
|
|
339
|
+
function hexToNumber(hex, opts = {}) {
|
|
340
|
+
const value = hexToBigInt(hex, opts);
|
|
341
|
+
const number = Number(value);
|
|
342
|
+
if (!Number.isSafeInteger(number))
|
|
343
|
+
throw new IntegerOutOfRangeError({
|
|
344
|
+
max: `${Number.MAX_SAFE_INTEGER}`,
|
|
345
|
+
min: `${Number.MIN_SAFE_INTEGER}`,
|
|
346
|
+
signed: opts.signed,
|
|
347
|
+
size: opts.size,
|
|
348
|
+
value: `${value}n`
|
|
349
|
+
});
|
|
350
|
+
return number;
|
|
351
|
+
}
|
|
352
|
+
function defineFormatter(type, format) {
|
|
353
|
+
return ({ exclude, format: overrides }) => {
|
|
354
|
+
return {
|
|
355
|
+
exclude,
|
|
356
|
+
format: (args, action) => {
|
|
357
|
+
const formatted = format(args, action);
|
|
358
|
+
if (exclude) {
|
|
359
|
+
for (const key of exclude) {
|
|
360
|
+
delete formatted[key];
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return {
|
|
364
|
+
...formatted,
|
|
365
|
+
...overrides(args, action)
|
|
366
|
+
};
|
|
367
|
+
},
|
|
368
|
+
type
|
|
369
|
+
};
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
const transactionType = {
|
|
373
|
+
"0x0": "legacy",
|
|
374
|
+
"0x1": "eip2930",
|
|
375
|
+
"0x2": "eip1559",
|
|
376
|
+
"0x3": "eip4844",
|
|
377
|
+
"0x4": "eip7702"
|
|
378
|
+
};
|
|
379
|
+
function formatTransaction(transaction, _) {
|
|
380
|
+
const transaction_ = {
|
|
381
|
+
...transaction,
|
|
382
|
+
blockHash: transaction.blockHash ? transaction.blockHash : null,
|
|
383
|
+
blockNumber: transaction.blockNumber ? BigInt(transaction.blockNumber) : null,
|
|
384
|
+
chainId: transaction.chainId ? hexToNumber(transaction.chainId) : void 0,
|
|
385
|
+
gas: transaction.gas ? BigInt(transaction.gas) : void 0,
|
|
386
|
+
gasPrice: transaction.gasPrice ? BigInt(transaction.gasPrice) : void 0,
|
|
387
|
+
maxFeePerBlobGas: transaction.maxFeePerBlobGas ? BigInt(transaction.maxFeePerBlobGas) : void 0,
|
|
388
|
+
maxFeePerGas: transaction.maxFeePerGas ? BigInt(transaction.maxFeePerGas) : void 0,
|
|
389
|
+
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas ? BigInt(transaction.maxPriorityFeePerGas) : void 0,
|
|
390
|
+
nonce: transaction.nonce ? hexToNumber(transaction.nonce) : void 0,
|
|
391
|
+
to: transaction.to ? transaction.to : null,
|
|
392
|
+
transactionIndex: transaction.transactionIndex ? Number(transaction.transactionIndex) : null,
|
|
393
|
+
type: transaction.type ? transactionType[transaction.type] : void 0,
|
|
394
|
+
typeHex: transaction.type ? transaction.type : void 0,
|
|
395
|
+
value: transaction.value ? BigInt(transaction.value) : void 0,
|
|
396
|
+
v: transaction.v ? BigInt(transaction.v) : void 0
|
|
397
|
+
};
|
|
398
|
+
if (transaction.authorizationList)
|
|
399
|
+
transaction_.authorizationList = formatAuthorizationList(transaction.authorizationList);
|
|
400
|
+
transaction_.yParity = (() => {
|
|
401
|
+
if (transaction.yParity)
|
|
402
|
+
return Number(transaction.yParity);
|
|
403
|
+
if (typeof transaction_.v === "bigint") {
|
|
404
|
+
if (transaction_.v === 0n || transaction_.v === 27n)
|
|
405
|
+
return 0;
|
|
406
|
+
if (transaction_.v === 1n || transaction_.v === 28n)
|
|
407
|
+
return 1;
|
|
408
|
+
if (transaction_.v >= 35n)
|
|
409
|
+
return transaction_.v % 2n === 0n ? 1 : 0;
|
|
410
|
+
}
|
|
411
|
+
return void 0;
|
|
412
|
+
})();
|
|
413
|
+
if (transaction_.type === "legacy") {
|
|
414
|
+
delete transaction_.accessList;
|
|
415
|
+
delete transaction_.maxFeePerBlobGas;
|
|
416
|
+
delete transaction_.maxFeePerGas;
|
|
417
|
+
delete transaction_.maxPriorityFeePerGas;
|
|
418
|
+
delete transaction_.yParity;
|
|
419
|
+
}
|
|
420
|
+
if (transaction_.type === "eip2930") {
|
|
421
|
+
delete transaction_.maxFeePerBlobGas;
|
|
422
|
+
delete transaction_.maxFeePerGas;
|
|
423
|
+
delete transaction_.maxPriorityFeePerGas;
|
|
424
|
+
}
|
|
425
|
+
if (transaction_.type === "eip1559")
|
|
426
|
+
delete transaction_.maxFeePerBlobGas;
|
|
427
|
+
return transaction_;
|
|
428
|
+
}
|
|
429
|
+
const defineTransaction = /* @__PURE__ */ defineFormatter("transaction", formatTransaction);
|
|
430
|
+
function formatAuthorizationList(authorizationList) {
|
|
431
|
+
return authorizationList.map((authorization) => ({
|
|
432
|
+
address: authorization.address,
|
|
433
|
+
chainId: Number(authorization.chainId),
|
|
434
|
+
nonce: Number(authorization.nonce),
|
|
435
|
+
r: authorization.r,
|
|
436
|
+
s: authorization.s,
|
|
437
|
+
yParity: Number(authorization.yParity)
|
|
438
|
+
}));
|
|
439
|
+
}
|
|
440
|
+
function formatBlock(block, _) {
|
|
441
|
+
const transactions = (block.transactions ?? []).map((transaction) => {
|
|
442
|
+
if (typeof transaction === "string")
|
|
443
|
+
return transaction;
|
|
444
|
+
return formatTransaction(transaction);
|
|
445
|
+
});
|
|
446
|
+
return {
|
|
447
|
+
...block,
|
|
448
|
+
baseFeePerGas: block.baseFeePerGas ? BigInt(block.baseFeePerGas) : null,
|
|
449
|
+
blobGasUsed: block.blobGasUsed ? BigInt(block.blobGasUsed) : void 0,
|
|
450
|
+
difficulty: block.difficulty ? BigInt(block.difficulty) : void 0,
|
|
451
|
+
excessBlobGas: block.excessBlobGas ? BigInt(block.excessBlobGas) : void 0,
|
|
452
|
+
gasLimit: block.gasLimit ? BigInt(block.gasLimit) : void 0,
|
|
453
|
+
gasUsed: block.gasUsed ? BigInt(block.gasUsed) : void 0,
|
|
454
|
+
hash: block.hash ? block.hash : null,
|
|
455
|
+
logsBloom: block.logsBloom ? block.logsBloom : null,
|
|
456
|
+
nonce: block.nonce ? block.nonce : null,
|
|
457
|
+
number: block.number ? BigInt(block.number) : null,
|
|
458
|
+
size: block.size ? BigInt(block.size) : void 0,
|
|
459
|
+
timestamp: block.timestamp ? BigInt(block.timestamp) : void 0,
|
|
460
|
+
transactions,
|
|
461
|
+
totalDifficulty: block.totalDifficulty ? BigInt(block.totalDifficulty) : null
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
const defineBlock = /* @__PURE__ */ defineFormatter("block", formatBlock);
|
|
465
|
+
function formatLog(log, { args, eventName } = {}) {
|
|
466
|
+
return {
|
|
467
|
+
...log,
|
|
468
|
+
blockHash: log.blockHash ? log.blockHash : null,
|
|
469
|
+
blockNumber: log.blockNumber ? BigInt(log.blockNumber) : null,
|
|
470
|
+
blockTimestamp: log.blockTimestamp ? BigInt(log.blockTimestamp) : log.blockTimestamp === null ? null : void 0,
|
|
471
|
+
logIndex: log.logIndex ? Number(log.logIndex) : null,
|
|
472
|
+
transactionHash: log.transactionHash ? log.transactionHash : null,
|
|
473
|
+
transactionIndex: log.transactionIndex ? Number(log.transactionIndex) : null,
|
|
474
|
+
...eventName ? { args, eventName } : {}
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
const receiptStatuses = {
|
|
478
|
+
"0x0": "reverted",
|
|
479
|
+
"0x1": "success"
|
|
480
|
+
};
|
|
481
|
+
function formatTransactionReceipt(transactionReceipt, _) {
|
|
482
|
+
const receipt = {
|
|
483
|
+
...transactionReceipt,
|
|
484
|
+
blockNumber: transactionReceipt.blockNumber ? BigInt(transactionReceipt.blockNumber) : null,
|
|
485
|
+
contractAddress: transactionReceipt.contractAddress ? transactionReceipt.contractAddress : null,
|
|
486
|
+
cumulativeGasUsed: transactionReceipt.cumulativeGasUsed ? BigInt(transactionReceipt.cumulativeGasUsed) : null,
|
|
487
|
+
effectiveGasPrice: transactionReceipt.effectiveGasPrice ? BigInt(transactionReceipt.effectiveGasPrice) : null,
|
|
488
|
+
gasUsed: transactionReceipt.gasUsed ? BigInt(transactionReceipt.gasUsed) : null,
|
|
489
|
+
logs: transactionReceipt.logs ? transactionReceipt.logs.map((log) => formatLog(log)) : null,
|
|
490
|
+
to: transactionReceipt.to ? transactionReceipt.to : null,
|
|
491
|
+
transactionIndex: transactionReceipt.transactionIndex ? hexToNumber(transactionReceipt.transactionIndex) : null,
|
|
492
|
+
status: transactionReceipt.status ? receiptStatuses[transactionReceipt.status] : null,
|
|
493
|
+
type: transactionReceipt.type ? transactionType[transactionReceipt.type] || transactionReceipt.type : null
|
|
494
|
+
};
|
|
495
|
+
if (transactionReceipt.blobGasPrice)
|
|
496
|
+
receipt.blobGasPrice = BigInt(transactionReceipt.blobGasPrice);
|
|
497
|
+
if (transactionReceipt.blobGasUsed)
|
|
498
|
+
receipt.blobGasUsed = BigInt(transactionReceipt.blobGasUsed);
|
|
499
|
+
return receipt;
|
|
500
|
+
}
|
|
501
|
+
const defineTransactionReceipt = /* @__PURE__ */ defineFormatter("transactionReceipt", formatTransactionReceipt);
|
|
502
|
+
const maxUint16 = 2n ** 16n - 1n;
|
|
503
|
+
const maxUint256 = 2n ** 256n - 1n;
|
|
504
|
+
function concatHex(values) {
|
|
505
|
+
return `0x${values.reduce((acc, x) => acc + x.replace("0x", ""), "")}`;
|
|
506
|
+
}
|
|
507
|
+
class NegativeOffsetError extends BaseError {
|
|
508
|
+
constructor({ offset }) {
|
|
509
|
+
super(`Offset \`${offset}\` cannot be negative.`, {
|
|
510
|
+
name: "NegativeOffsetError"
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
class PositionOutOfBoundsError extends BaseError {
|
|
515
|
+
constructor({ length, position }) {
|
|
516
|
+
super(`Position \`${position}\` is out of bounds (\`0 < position < ${length}\`).`, { name: "PositionOutOfBoundsError" });
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
class RecursiveReadLimitExceededError extends BaseError {
|
|
520
|
+
constructor({ count, limit }) {
|
|
521
|
+
super(`Recursive read limit of \`${limit}\` exceeded (recursive read count: \`${count}\`).`, { name: "RecursiveReadLimitExceededError" });
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
const staticCursor = {
|
|
525
|
+
bytes: new Uint8Array(),
|
|
526
|
+
dataView: new DataView(new ArrayBuffer(0)),
|
|
527
|
+
position: 0,
|
|
528
|
+
positionReadCount: /* @__PURE__ */ new Map(),
|
|
529
|
+
recursiveReadCount: 0,
|
|
530
|
+
recursiveReadLimit: Number.POSITIVE_INFINITY,
|
|
531
|
+
assertReadLimit() {
|
|
532
|
+
if (this.recursiveReadCount >= this.recursiveReadLimit)
|
|
533
|
+
throw new RecursiveReadLimitExceededError({
|
|
534
|
+
count: this.recursiveReadCount + 1,
|
|
535
|
+
limit: this.recursiveReadLimit
|
|
536
|
+
});
|
|
537
|
+
},
|
|
538
|
+
assertPosition(position) {
|
|
539
|
+
if (position < 0 || position > this.bytes.length - 1)
|
|
540
|
+
throw new PositionOutOfBoundsError({
|
|
541
|
+
length: this.bytes.length,
|
|
542
|
+
position
|
|
543
|
+
});
|
|
544
|
+
},
|
|
545
|
+
decrementPosition(offset) {
|
|
546
|
+
if (offset < 0)
|
|
547
|
+
throw new NegativeOffsetError({ offset });
|
|
548
|
+
const position = this.position - offset;
|
|
549
|
+
this.assertPosition(position);
|
|
550
|
+
this.position = position;
|
|
551
|
+
},
|
|
552
|
+
getReadCount(position) {
|
|
553
|
+
return this.positionReadCount.get(position || this.position) || 0;
|
|
554
|
+
},
|
|
555
|
+
incrementPosition(offset) {
|
|
556
|
+
if (offset < 0)
|
|
557
|
+
throw new NegativeOffsetError({ offset });
|
|
558
|
+
const position = this.position + offset;
|
|
559
|
+
this.assertPosition(position);
|
|
560
|
+
this.position = position;
|
|
561
|
+
},
|
|
562
|
+
inspectByte(position_) {
|
|
563
|
+
const position = position_ ?? this.position;
|
|
564
|
+
this.assertPosition(position);
|
|
565
|
+
return this.bytes[position];
|
|
566
|
+
},
|
|
567
|
+
inspectBytes(length, position_) {
|
|
568
|
+
const position = position_ ?? this.position;
|
|
569
|
+
this.assertPosition(position + length - 1);
|
|
570
|
+
return this.bytes.subarray(position, position + length);
|
|
571
|
+
},
|
|
572
|
+
inspectUint8(position_) {
|
|
573
|
+
const position = position_ ?? this.position;
|
|
574
|
+
this.assertPosition(position);
|
|
575
|
+
return this.bytes[position];
|
|
576
|
+
},
|
|
577
|
+
inspectUint16(position_) {
|
|
578
|
+
const position = position_ ?? this.position;
|
|
579
|
+
this.assertPosition(position + 1);
|
|
580
|
+
return this.dataView.getUint16(position);
|
|
581
|
+
},
|
|
582
|
+
inspectUint24(position_) {
|
|
583
|
+
const position = position_ ?? this.position;
|
|
584
|
+
this.assertPosition(position + 2);
|
|
585
|
+
return (this.dataView.getUint16(position) << 8) + this.dataView.getUint8(position + 2);
|
|
586
|
+
},
|
|
587
|
+
inspectUint32(position_) {
|
|
588
|
+
const position = position_ ?? this.position;
|
|
589
|
+
this.assertPosition(position + 3);
|
|
590
|
+
return this.dataView.getUint32(position);
|
|
591
|
+
},
|
|
592
|
+
pushByte(byte) {
|
|
593
|
+
this.assertPosition(this.position);
|
|
594
|
+
this.bytes[this.position] = byte;
|
|
595
|
+
this.position++;
|
|
596
|
+
},
|
|
597
|
+
pushBytes(bytes) {
|
|
598
|
+
this.assertPosition(this.position + bytes.length - 1);
|
|
599
|
+
this.bytes.set(bytes, this.position);
|
|
600
|
+
this.position += bytes.length;
|
|
601
|
+
},
|
|
602
|
+
pushUint8(value) {
|
|
603
|
+
this.assertPosition(this.position);
|
|
604
|
+
this.bytes[this.position] = value;
|
|
605
|
+
this.position++;
|
|
606
|
+
},
|
|
607
|
+
pushUint16(value) {
|
|
608
|
+
this.assertPosition(this.position + 1);
|
|
609
|
+
this.dataView.setUint16(this.position, value);
|
|
610
|
+
this.position += 2;
|
|
611
|
+
},
|
|
612
|
+
pushUint24(value) {
|
|
613
|
+
this.assertPosition(this.position + 2);
|
|
614
|
+
this.dataView.setUint16(this.position, value >> 8);
|
|
615
|
+
this.dataView.setUint8(this.position + 2, value & 255);
|
|
616
|
+
this.position += 3;
|
|
617
|
+
},
|
|
618
|
+
pushUint32(value) {
|
|
619
|
+
this.assertPosition(this.position + 3);
|
|
620
|
+
this.dataView.setUint32(this.position, value);
|
|
621
|
+
this.position += 4;
|
|
622
|
+
},
|
|
623
|
+
readByte() {
|
|
624
|
+
this.assertReadLimit();
|
|
625
|
+
this._touch();
|
|
626
|
+
const value = this.inspectByte();
|
|
627
|
+
this.position++;
|
|
628
|
+
return value;
|
|
629
|
+
},
|
|
630
|
+
readBytes(length, size2) {
|
|
631
|
+
this.assertReadLimit();
|
|
632
|
+
this._touch();
|
|
633
|
+
const value = this.inspectBytes(length);
|
|
634
|
+
this.position += size2 ?? length;
|
|
635
|
+
return value;
|
|
636
|
+
},
|
|
637
|
+
readUint8() {
|
|
638
|
+
this.assertReadLimit();
|
|
639
|
+
this._touch();
|
|
640
|
+
const value = this.inspectUint8();
|
|
641
|
+
this.position += 1;
|
|
642
|
+
return value;
|
|
643
|
+
},
|
|
644
|
+
readUint16() {
|
|
645
|
+
this.assertReadLimit();
|
|
646
|
+
this._touch();
|
|
647
|
+
const value = this.inspectUint16();
|
|
648
|
+
this.position += 2;
|
|
649
|
+
return value;
|
|
650
|
+
},
|
|
651
|
+
readUint24() {
|
|
652
|
+
this.assertReadLimit();
|
|
653
|
+
this._touch();
|
|
654
|
+
const value = this.inspectUint24();
|
|
655
|
+
this.position += 3;
|
|
656
|
+
return value;
|
|
657
|
+
},
|
|
658
|
+
readUint32() {
|
|
659
|
+
this.assertReadLimit();
|
|
660
|
+
this._touch();
|
|
661
|
+
const value = this.inspectUint32();
|
|
662
|
+
this.position += 4;
|
|
663
|
+
return value;
|
|
664
|
+
},
|
|
665
|
+
get remaining() {
|
|
666
|
+
return this.bytes.length - this.position;
|
|
667
|
+
},
|
|
668
|
+
setPosition(position) {
|
|
669
|
+
const oldPosition = this.position;
|
|
670
|
+
this.assertPosition(position);
|
|
671
|
+
this.position = position;
|
|
672
|
+
return () => this.position = oldPosition;
|
|
673
|
+
},
|
|
674
|
+
_touch() {
|
|
675
|
+
if (this.recursiveReadLimit === Number.POSITIVE_INFINITY)
|
|
676
|
+
return;
|
|
677
|
+
const count = this.getReadCount();
|
|
678
|
+
this.positionReadCount.set(this.position, count + 1);
|
|
679
|
+
if (count > 0)
|
|
680
|
+
this.recursiveReadCount++;
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
function createCursor(bytes, { recursiveReadLimit = 8192 } = {}) {
|
|
684
|
+
const cursor = Object.create(staticCursor);
|
|
685
|
+
cursor.bytes = bytes;
|
|
686
|
+
cursor.dataView = new DataView(bytes.buffer ?? bytes, bytes.byteOffset, bytes.byteLength);
|
|
687
|
+
cursor.positionReadCount = /* @__PURE__ */ new Map();
|
|
688
|
+
cursor.recursiveReadLimit = recursiveReadLimit;
|
|
689
|
+
return cursor;
|
|
690
|
+
}
|
|
691
|
+
function toRlp(bytes, to = "hex") {
|
|
692
|
+
const encodable = getEncodable(bytes);
|
|
693
|
+
const cursor = createCursor(new Uint8Array(encodable.length));
|
|
694
|
+
encodable.encode(cursor);
|
|
695
|
+
if (to === "hex")
|
|
696
|
+
return bytesToHex$1(cursor.bytes);
|
|
697
|
+
return cursor.bytes;
|
|
698
|
+
}
|
|
699
|
+
function getEncodable(bytes) {
|
|
700
|
+
if (Array.isArray(bytes))
|
|
701
|
+
return getEncodableList(bytes.map((x) => getEncodable(x)));
|
|
702
|
+
return getEncodableBytes(bytes);
|
|
703
|
+
}
|
|
704
|
+
function getEncodableList(list) {
|
|
705
|
+
const bodyLength = list.reduce((acc, x) => acc + x.length, 0);
|
|
706
|
+
const sizeOfBodyLength = getSizeOfLength(bodyLength);
|
|
707
|
+
const length = (() => {
|
|
708
|
+
if (bodyLength <= 55)
|
|
709
|
+
return 1 + bodyLength;
|
|
710
|
+
return 1 + sizeOfBodyLength + bodyLength;
|
|
711
|
+
})();
|
|
712
|
+
return {
|
|
713
|
+
length,
|
|
714
|
+
encode(cursor) {
|
|
715
|
+
if (bodyLength <= 55) {
|
|
716
|
+
cursor.pushByte(192 + bodyLength);
|
|
717
|
+
} else {
|
|
718
|
+
cursor.pushByte(192 + 55 + sizeOfBodyLength);
|
|
719
|
+
if (sizeOfBodyLength === 1)
|
|
720
|
+
cursor.pushUint8(bodyLength);
|
|
721
|
+
else if (sizeOfBodyLength === 2)
|
|
722
|
+
cursor.pushUint16(bodyLength);
|
|
723
|
+
else if (sizeOfBodyLength === 3)
|
|
724
|
+
cursor.pushUint24(bodyLength);
|
|
725
|
+
else
|
|
726
|
+
cursor.pushUint32(bodyLength);
|
|
727
|
+
}
|
|
728
|
+
for (const { encode } of list) {
|
|
729
|
+
encode(cursor);
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
function getEncodableBytes(bytesOrHex) {
|
|
735
|
+
const bytes = typeof bytesOrHex === "string" ? hexToBytes$1(bytesOrHex) : bytesOrHex;
|
|
736
|
+
const sizeOfBytesLength = getSizeOfLength(bytes.length);
|
|
737
|
+
const length = (() => {
|
|
738
|
+
if (bytes.length === 1 && bytes[0] < 128)
|
|
739
|
+
return 1;
|
|
740
|
+
if (bytes.length <= 55)
|
|
741
|
+
return 1 + bytes.length;
|
|
742
|
+
return 1 + sizeOfBytesLength + bytes.length;
|
|
743
|
+
})();
|
|
744
|
+
return {
|
|
745
|
+
length,
|
|
746
|
+
encode(cursor) {
|
|
747
|
+
if (bytes.length === 1 && bytes[0] < 128) {
|
|
748
|
+
cursor.pushBytes(bytes);
|
|
749
|
+
} else if (bytes.length <= 55) {
|
|
750
|
+
cursor.pushByte(128 + bytes.length);
|
|
751
|
+
cursor.pushBytes(bytes);
|
|
752
|
+
} else {
|
|
753
|
+
cursor.pushByte(128 + 55 + sizeOfBytesLength);
|
|
754
|
+
if (sizeOfBytesLength === 1)
|
|
755
|
+
cursor.pushUint8(bytes.length);
|
|
756
|
+
else if (sizeOfBytesLength === 2)
|
|
757
|
+
cursor.pushUint16(bytes.length);
|
|
758
|
+
else if (sizeOfBytesLength === 3)
|
|
759
|
+
cursor.pushUint24(bytes.length);
|
|
760
|
+
else
|
|
761
|
+
cursor.pushUint32(bytes.length);
|
|
762
|
+
cursor.pushBytes(bytes);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
function getSizeOfLength(length) {
|
|
768
|
+
if (length < 2 ** 8)
|
|
769
|
+
return 1;
|
|
770
|
+
if (length < 2 ** 16)
|
|
771
|
+
return 2;
|
|
772
|
+
if (length < 2 ** 24)
|
|
773
|
+
return 3;
|
|
774
|
+
if (length < 2 ** 32)
|
|
775
|
+
return 4;
|
|
776
|
+
throw new BaseError("Length is too large.");
|
|
777
|
+
}
|
|
778
|
+
const etherUnits = {
|
|
779
|
+
gwei: 9,
|
|
780
|
+
wei: 18
|
|
781
|
+
};
|
|
782
|
+
const gweiUnits = {
|
|
783
|
+
ether: -9,
|
|
784
|
+
wei: 9
|
|
785
|
+
};
|
|
786
|
+
function formatUnits(value, decimals) {
|
|
787
|
+
let display = value.toString();
|
|
788
|
+
const negative = display.startsWith("-");
|
|
789
|
+
if (negative)
|
|
790
|
+
display = display.slice(1);
|
|
791
|
+
display = display.padStart(decimals, "0");
|
|
792
|
+
let [integer, fraction] = [
|
|
793
|
+
display.slice(0, display.length - decimals),
|
|
794
|
+
display.slice(display.length - decimals)
|
|
795
|
+
];
|
|
796
|
+
fraction = fraction.replace(/(0+)$/, "");
|
|
797
|
+
return `${negative ? "-" : ""}${integer || "0"}${fraction ? `.${fraction}` : ""}`;
|
|
798
|
+
}
|
|
799
|
+
function formatGwei(wei, unit = "wei") {
|
|
800
|
+
return formatUnits(wei, gweiUnits[unit]);
|
|
801
|
+
}
|
|
802
|
+
function prettyPrint(args) {
|
|
803
|
+
const entries = Object.entries(args).map(([key, value]) => {
|
|
804
|
+
if (value === void 0 || value === false)
|
|
805
|
+
return null;
|
|
806
|
+
return [key, value];
|
|
807
|
+
}).filter(Boolean);
|
|
808
|
+
const maxLength = entries.reduce((acc, [key]) => Math.max(acc, key.length), 0);
|
|
809
|
+
return entries.map(([key, value]) => ` ${`${key}:`.padEnd(maxLength + 1)} ${value}`).join("\n");
|
|
810
|
+
}
|
|
811
|
+
class InvalidLegacyVError extends BaseError {
|
|
812
|
+
constructor({ v }) {
|
|
813
|
+
super(`Invalid \`v\` value "${v}". Expected 27 or 28.`, {
|
|
814
|
+
name: "InvalidLegacyVError"
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
class InvalidSerializableTransactionError extends BaseError {
|
|
819
|
+
constructor({ transaction }) {
|
|
820
|
+
super("Cannot infer a transaction type from provided transaction.", {
|
|
821
|
+
metaMessages: [
|
|
822
|
+
"Provided Transaction:",
|
|
823
|
+
"{",
|
|
824
|
+
prettyPrint(transaction),
|
|
825
|
+
"}",
|
|
826
|
+
"",
|
|
827
|
+
"To infer the type, either provide:",
|
|
828
|
+
"- a `type` to the Transaction, or",
|
|
829
|
+
"- an EIP-1559 Transaction with `maxFeePerGas`, or",
|
|
830
|
+
"- an EIP-2930 Transaction with `gasPrice` & `accessList`, or",
|
|
831
|
+
"- an EIP-4844 Transaction with `blobs`, `blobVersionedHashes`, `sidecars`, or",
|
|
832
|
+
"- an EIP-7702 Transaction with `authorizationList`, or",
|
|
833
|
+
"- a Legacy Transaction with `gasPrice`"
|
|
834
|
+
],
|
|
835
|
+
name: "InvalidSerializableTransactionError"
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
class InvalidStorageKeySizeError extends BaseError {
|
|
840
|
+
constructor({ storageKey }) {
|
|
841
|
+
super(`Size for storage key "${storageKey}" is invalid. Expected 32 bytes. Got ${Math.floor((storageKey.length - 2) / 2)} bytes.`, { name: "InvalidStorageKeySizeError" });
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
function serializeAuthorizationList(authorizationList) {
|
|
845
|
+
if (!authorizationList || authorizationList.length === 0)
|
|
846
|
+
return [];
|
|
847
|
+
const serializedAuthorizationList = [];
|
|
848
|
+
for (const authorization of authorizationList) {
|
|
849
|
+
const { chainId, nonce, ...signature } = authorization;
|
|
850
|
+
const contractAddress = authorization.address;
|
|
851
|
+
serializedAuthorizationList.push([
|
|
852
|
+
chainId ? toHex(chainId) : "0x",
|
|
853
|
+
contractAddress,
|
|
854
|
+
nonce ? toHex(nonce) : "0x",
|
|
855
|
+
...toYParitySignatureArray({}, signature)
|
|
856
|
+
]);
|
|
857
|
+
}
|
|
858
|
+
return serializedAuthorizationList;
|
|
859
|
+
}
|
|
860
|
+
function blobsToCommitments(parameters) {
|
|
861
|
+
const { kzg } = parameters;
|
|
862
|
+
const to = parameters.to ?? (typeof parameters.blobs[0] === "string" ? "hex" : "bytes");
|
|
863
|
+
const blobs = typeof parameters.blobs[0] === "string" ? parameters.blobs.map((x) => hexToBytes$1(x)) : parameters.blobs;
|
|
864
|
+
const commitments = [];
|
|
865
|
+
for (const blob of blobs)
|
|
866
|
+
commitments.push(Uint8Array.from(kzg.blobToKzgCommitment(blob)));
|
|
867
|
+
return to === "bytes" ? commitments : commitments.map((x) => bytesToHex$1(x));
|
|
868
|
+
}
|
|
869
|
+
function blobsToProofs(parameters) {
|
|
870
|
+
const { kzg } = parameters;
|
|
871
|
+
const to = parameters.to ?? (typeof parameters.blobs[0] === "string" ? "hex" : "bytes");
|
|
872
|
+
const blobs = typeof parameters.blobs[0] === "string" ? parameters.blobs.map((x) => hexToBytes$1(x)) : parameters.blobs;
|
|
873
|
+
const commitments = typeof parameters.commitments[0] === "string" ? parameters.commitments.map((x) => hexToBytes$1(x)) : parameters.commitments;
|
|
874
|
+
const proofs = [];
|
|
875
|
+
for (let i = 0; i < blobs.length; i++) {
|
|
876
|
+
const blob = blobs[i];
|
|
877
|
+
const commitment = commitments[i];
|
|
878
|
+
proofs.push(Uint8Array.from(kzg.computeBlobKzgProof(blob, commitment)));
|
|
879
|
+
}
|
|
880
|
+
return to === "bytes" ? proofs : proofs.map((x) => bytesToHex$1(x));
|
|
881
|
+
}
|
|
882
|
+
const crypto = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
883
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
884
|
+
function isBytes(a) {
|
|
885
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
886
|
+
}
|
|
887
|
+
function anumber(n) {
|
|
888
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
889
|
+
throw new Error("positive integer expected, got " + n);
|
|
890
|
+
}
|
|
891
|
+
function abytes(b, ...lengths) {
|
|
892
|
+
if (!isBytes(b))
|
|
893
|
+
throw new Error("Uint8Array expected");
|
|
894
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
895
|
+
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
896
|
+
}
|
|
897
|
+
function ahash(h) {
|
|
898
|
+
if (typeof h !== "function" || typeof h.create !== "function")
|
|
899
|
+
throw new Error("Hash should be wrapped by utils.createHasher");
|
|
900
|
+
anumber(h.outputLen);
|
|
901
|
+
anumber(h.blockLen);
|
|
902
|
+
}
|
|
903
|
+
function aexists(instance, checkFinished = true) {
|
|
904
|
+
if (instance.destroyed)
|
|
905
|
+
throw new Error("Hash instance has been destroyed");
|
|
906
|
+
if (checkFinished && instance.finished)
|
|
907
|
+
throw new Error("Hash#digest() has already been called");
|
|
908
|
+
}
|
|
909
|
+
function aoutput(out, instance) {
|
|
910
|
+
abytes(out);
|
|
911
|
+
const min = instance.outputLen;
|
|
912
|
+
if (out.length < min) {
|
|
913
|
+
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
function u32(arr) {
|
|
917
|
+
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
918
|
+
}
|
|
919
|
+
function clean(...arrays) {
|
|
920
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
921
|
+
arrays[i].fill(0);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
function createView(arr) {
|
|
925
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
926
|
+
}
|
|
927
|
+
function rotr(word, shift) {
|
|
928
|
+
return word << 32 - shift | word >>> shift;
|
|
929
|
+
}
|
|
930
|
+
const isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
931
|
+
function byteSwap(word) {
|
|
932
|
+
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
933
|
+
}
|
|
934
|
+
function byteSwap32(arr) {
|
|
935
|
+
for (let i = 0; i < arr.length; i++) {
|
|
936
|
+
arr[i] = byteSwap(arr[i]);
|
|
937
|
+
}
|
|
938
|
+
return arr;
|
|
939
|
+
}
|
|
940
|
+
const swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
941
|
+
const hasHexBuiltin = /* @__PURE__ */ (() => (
|
|
942
|
+
// @ts-ignore
|
|
943
|
+
typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
|
|
944
|
+
))();
|
|
945
|
+
const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
946
|
+
function bytesToHex(bytes) {
|
|
947
|
+
abytes(bytes);
|
|
948
|
+
if (hasHexBuiltin)
|
|
949
|
+
return bytes.toHex();
|
|
950
|
+
let hex = "";
|
|
951
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
952
|
+
hex += hexes[bytes[i]];
|
|
953
|
+
}
|
|
954
|
+
return hex;
|
|
955
|
+
}
|
|
956
|
+
const asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
957
|
+
function asciiToBase16(ch) {
|
|
958
|
+
if (ch >= asciis._0 && ch <= asciis._9)
|
|
959
|
+
return ch - asciis._0;
|
|
960
|
+
if (ch >= asciis.A && ch <= asciis.F)
|
|
961
|
+
return ch - (asciis.A - 10);
|
|
962
|
+
if (ch >= asciis.a && ch <= asciis.f)
|
|
963
|
+
return ch - (asciis.a - 10);
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
function hexToBytes(hex) {
|
|
967
|
+
if (typeof hex !== "string")
|
|
968
|
+
throw new Error("hex string expected, got " + typeof hex);
|
|
969
|
+
if (hasHexBuiltin)
|
|
970
|
+
return Uint8Array.fromHex(hex);
|
|
971
|
+
const hl = hex.length;
|
|
972
|
+
const al = hl / 2;
|
|
973
|
+
if (hl % 2)
|
|
974
|
+
throw new Error("hex string expected, got unpadded hex of length " + hl);
|
|
975
|
+
const array = new Uint8Array(al);
|
|
976
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
977
|
+
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
978
|
+
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
979
|
+
if (n1 === void 0 || n2 === void 0) {
|
|
980
|
+
const char = hex[hi] + hex[hi + 1];
|
|
981
|
+
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
982
|
+
}
|
|
983
|
+
array[ai] = n1 * 16 + n2;
|
|
984
|
+
}
|
|
985
|
+
return array;
|
|
986
|
+
}
|
|
987
|
+
function utf8ToBytes(str) {
|
|
988
|
+
if (typeof str !== "string")
|
|
989
|
+
throw new Error("string expected");
|
|
990
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
991
|
+
}
|
|
992
|
+
function toBytes(data) {
|
|
993
|
+
if (typeof data === "string")
|
|
994
|
+
data = utf8ToBytes(data);
|
|
995
|
+
abytes(data);
|
|
996
|
+
return data;
|
|
997
|
+
}
|
|
998
|
+
function concatBytes(...arrays) {
|
|
999
|
+
let sum = 0;
|
|
1000
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
1001
|
+
const a = arrays[i];
|
|
1002
|
+
abytes(a);
|
|
1003
|
+
sum += a.length;
|
|
1004
|
+
}
|
|
1005
|
+
const res = new Uint8Array(sum);
|
|
1006
|
+
for (let i = 0, pad2 = 0; i < arrays.length; i++) {
|
|
1007
|
+
const a = arrays[i];
|
|
1008
|
+
res.set(a, pad2);
|
|
1009
|
+
pad2 += a.length;
|
|
1010
|
+
}
|
|
1011
|
+
return res;
|
|
1012
|
+
}
|
|
1013
|
+
class Hash {
|
|
1014
|
+
}
|
|
1015
|
+
function createHasher(hashCons) {
|
|
1016
|
+
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
1017
|
+
const tmp = hashCons();
|
|
1018
|
+
hashC.outputLen = tmp.outputLen;
|
|
1019
|
+
hashC.blockLen = tmp.blockLen;
|
|
1020
|
+
hashC.create = () => hashCons();
|
|
1021
|
+
return hashC;
|
|
1022
|
+
}
|
|
1023
|
+
function randomBytes(bytesLength = 32) {
|
|
1024
|
+
if (crypto && typeof crypto.getRandomValues === "function") {
|
|
1025
|
+
return crypto.getRandomValues(new Uint8Array(bytesLength));
|
|
1026
|
+
}
|
|
1027
|
+
if (crypto && typeof crypto.randomBytes === "function") {
|
|
1028
|
+
return Uint8Array.from(crypto.randomBytes(bytesLength));
|
|
1029
|
+
}
|
|
1030
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
1031
|
+
}
|
|
1032
|
+
function setBigUint64(view, byteOffset, value, isLE2) {
|
|
1033
|
+
if (typeof view.setBigUint64 === "function")
|
|
1034
|
+
return view.setBigUint64(byteOffset, value, isLE2);
|
|
1035
|
+
const _32n2 = BigInt(32);
|
|
1036
|
+
const _u32_max = BigInt(4294967295);
|
|
1037
|
+
const wh = Number(value >> _32n2 & _u32_max);
|
|
1038
|
+
const wl = Number(value & _u32_max);
|
|
1039
|
+
const h = isLE2 ? 4 : 0;
|
|
1040
|
+
const l = isLE2 ? 0 : 4;
|
|
1041
|
+
view.setUint32(byteOffset + h, wh, isLE2);
|
|
1042
|
+
view.setUint32(byteOffset + l, wl, isLE2);
|
|
1043
|
+
}
|
|
1044
|
+
function Chi(a, b, c) {
|
|
1045
|
+
return a & b ^ ~a & c;
|
|
1046
|
+
}
|
|
1047
|
+
function Maj(a, b, c) {
|
|
1048
|
+
return a & b ^ a & c ^ b & c;
|
|
1049
|
+
}
|
|
1050
|
+
class HashMD extends Hash {
|
|
1051
|
+
constructor(blockLen, outputLen, padOffset, isLE2) {
|
|
1052
|
+
super();
|
|
1053
|
+
this.finished = false;
|
|
1054
|
+
this.length = 0;
|
|
1055
|
+
this.pos = 0;
|
|
1056
|
+
this.destroyed = false;
|
|
1057
|
+
this.blockLen = blockLen;
|
|
1058
|
+
this.outputLen = outputLen;
|
|
1059
|
+
this.padOffset = padOffset;
|
|
1060
|
+
this.isLE = isLE2;
|
|
1061
|
+
this.buffer = new Uint8Array(blockLen);
|
|
1062
|
+
this.view = createView(this.buffer);
|
|
1063
|
+
}
|
|
1064
|
+
update(data) {
|
|
1065
|
+
aexists(this);
|
|
1066
|
+
data = toBytes(data);
|
|
1067
|
+
abytes(data);
|
|
1068
|
+
const { view, buffer, blockLen } = this;
|
|
1069
|
+
const len = data.length;
|
|
1070
|
+
for (let pos = 0; pos < len; ) {
|
|
1071
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
1072
|
+
if (take === blockLen) {
|
|
1073
|
+
const dataView = createView(data);
|
|
1074
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
1075
|
+
this.process(dataView, pos);
|
|
1076
|
+
continue;
|
|
1077
|
+
}
|
|
1078
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
1079
|
+
this.pos += take;
|
|
1080
|
+
pos += take;
|
|
1081
|
+
if (this.pos === blockLen) {
|
|
1082
|
+
this.process(view, 0);
|
|
1083
|
+
this.pos = 0;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
this.length += data.length;
|
|
1087
|
+
this.roundClean();
|
|
1088
|
+
return this;
|
|
1089
|
+
}
|
|
1090
|
+
digestInto(out) {
|
|
1091
|
+
aexists(this);
|
|
1092
|
+
aoutput(out, this);
|
|
1093
|
+
this.finished = true;
|
|
1094
|
+
const { buffer, view, blockLen, isLE: isLE2 } = this;
|
|
1095
|
+
let { pos } = this;
|
|
1096
|
+
buffer[pos++] = 128;
|
|
1097
|
+
clean(this.buffer.subarray(pos));
|
|
1098
|
+
if (this.padOffset > blockLen - pos) {
|
|
1099
|
+
this.process(view, 0);
|
|
1100
|
+
pos = 0;
|
|
1101
|
+
}
|
|
1102
|
+
for (let i = pos; i < blockLen; i++)
|
|
1103
|
+
buffer[i] = 0;
|
|
1104
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE2);
|
|
1105
|
+
this.process(view, 0);
|
|
1106
|
+
const oview = createView(out);
|
|
1107
|
+
const len = this.outputLen;
|
|
1108
|
+
if (len % 4)
|
|
1109
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
1110
|
+
const outLen = len / 4;
|
|
1111
|
+
const state = this.get();
|
|
1112
|
+
if (outLen > state.length)
|
|
1113
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
1114
|
+
for (let i = 0; i < outLen; i++)
|
|
1115
|
+
oview.setUint32(4 * i, state[i], isLE2);
|
|
1116
|
+
}
|
|
1117
|
+
digest() {
|
|
1118
|
+
const { buffer, outputLen } = this;
|
|
1119
|
+
this.digestInto(buffer);
|
|
1120
|
+
const res = buffer.slice(0, outputLen);
|
|
1121
|
+
this.destroy();
|
|
1122
|
+
return res;
|
|
1123
|
+
}
|
|
1124
|
+
_cloneInto(to) {
|
|
1125
|
+
to || (to = new this.constructor());
|
|
1126
|
+
to.set(...this.get());
|
|
1127
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
1128
|
+
to.destroyed = destroyed;
|
|
1129
|
+
to.finished = finished;
|
|
1130
|
+
to.length = length;
|
|
1131
|
+
to.pos = pos;
|
|
1132
|
+
if (length % blockLen)
|
|
1133
|
+
to.buffer.set(buffer);
|
|
1134
|
+
return to;
|
|
1135
|
+
}
|
|
1136
|
+
clone() {
|
|
1137
|
+
return this._cloneInto();
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
const SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
1141
|
+
1779033703,
|
|
1142
|
+
3144134277,
|
|
1143
|
+
1013904242,
|
|
1144
|
+
2773480762,
|
|
1145
|
+
1359893119,
|
|
1146
|
+
2600822924,
|
|
1147
|
+
528734635,
|
|
1148
|
+
1541459225
|
|
1149
|
+
]);
|
|
1150
|
+
const SHA512_IV = /* @__PURE__ */ Uint32Array.from([
|
|
1151
|
+
1779033703,
|
|
1152
|
+
4089235720,
|
|
1153
|
+
3144134277,
|
|
1154
|
+
2227873595,
|
|
1155
|
+
1013904242,
|
|
1156
|
+
4271175723,
|
|
1157
|
+
2773480762,
|
|
1158
|
+
1595750129,
|
|
1159
|
+
1359893119,
|
|
1160
|
+
2917565137,
|
|
1161
|
+
2600822924,
|
|
1162
|
+
725511199,
|
|
1163
|
+
528734635,
|
|
1164
|
+
4215389547,
|
|
1165
|
+
1541459225,
|
|
1166
|
+
327033209
|
|
1167
|
+
]);
|
|
1168
|
+
const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
1169
|
+
const _32n = /* @__PURE__ */ BigInt(32);
|
|
1170
|
+
function fromBig(n, le = false) {
|
|
1171
|
+
if (le)
|
|
1172
|
+
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
|
1173
|
+
return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
1174
|
+
}
|
|
1175
|
+
function split(lst, le = false) {
|
|
1176
|
+
const len = lst.length;
|
|
1177
|
+
let Ah = new Uint32Array(len);
|
|
1178
|
+
let Al = new Uint32Array(len);
|
|
1179
|
+
for (let i = 0; i < len; i++) {
|
|
1180
|
+
const { h, l } = fromBig(lst[i], le);
|
|
1181
|
+
[Ah[i], Al[i]] = [h, l];
|
|
1182
|
+
}
|
|
1183
|
+
return [Ah, Al];
|
|
1184
|
+
}
|
|
1185
|
+
const shrSH = (h, _l, s) => h >>> s;
|
|
1186
|
+
const shrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
1187
|
+
const rotrSH = (h, l, s) => h >>> s | l << 32 - s;
|
|
1188
|
+
const rotrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
1189
|
+
const rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
1190
|
+
const rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
1191
|
+
const rotlSH = (h, l, s) => h << s | l >>> 32 - s;
|
|
1192
|
+
const rotlSL = (h, l, s) => l << s | h >>> 32 - s;
|
|
1193
|
+
const rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
|
|
1194
|
+
const rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
|
|
1195
|
+
function add(Ah, Al, Bh, Bl) {
|
|
1196
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
|
1197
|
+
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
|
1198
|
+
}
|
|
1199
|
+
const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
1200
|
+
const add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
1201
|
+
const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
1202
|
+
const add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
|
|
1203
|
+
const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
1204
|
+
const add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
1205
|
+
const SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
1206
|
+
1116352408,
|
|
1207
|
+
1899447441,
|
|
1208
|
+
3049323471,
|
|
1209
|
+
3921009573,
|
|
1210
|
+
961987163,
|
|
1211
|
+
1508970993,
|
|
1212
|
+
2453635748,
|
|
1213
|
+
2870763221,
|
|
1214
|
+
3624381080,
|
|
1215
|
+
310598401,
|
|
1216
|
+
607225278,
|
|
1217
|
+
1426881987,
|
|
1218
|
+
1925078388,
|
|
1219
|
+
2162078206,
|
|
1220
|
+
2614888103,
|
|
1221
|
+
3248222580,
|
|
1222
|
+
3835390401,
|
|
1223
|
+
4022224774,
|
|
1224
|
+
264347078,
|
|
1225
|
+
604807628,
|
|
1226
|
+
770255983,
|
|
1227
|
+
1249150122,
|
|
1228
|
+
1555081692,
|
|
1229
|
+
1996064986,
|
|
1230
|
+
2554220882,
|
|
1231
|
+
2821834349,
|
|
1232
|
+
2952996808,
|
|
1233
|
+
3210313671,
|
|
1234
|
+
3336571891,
|
|
1235
|
+
3584528711,
|
|
1236
|
+
113926993,
|
|
1237
|
+
338241895,
|
|
1238
|
+
666307205,
|
|
1239
|
+
773529912,
|
|
1240
|
+
1294757372,
|
|
1241
|
+
1396182291,
|
|
1242
|
+
1695183700,
|
|
1243
|
+
1986661051,
|
|
1244
|
+
2177026350,
|
|
1245
|
+
2456956037,
|
|
1246
|
+
2730485921,
|
|
1247
|
+
2820302411,
|
|
1248
|
+
3259730800,
|
|
1249
|
+
3345764771,
|
|
1250
|
+
3516065817,
|
|
1251
|
+
3600352804,
|
|
1252
|
+
4094571909,
|
|
1253
|
+
275423344,
|
|
1254
|
+
430227734,
|
|
1255
|
+
506948616,
|
|
1256
|
+
659060556,
|
|
1257
|
+
883997877,
|
|
1258
|
+
958139571,
|
|
1259
|
+
1322822218,
|
|
1260
|
+
1537002063,
|
|
1261
|
+
1747873779,
|
|
1262
|
+
1955562222,
|
|
1263
|
+
2024104815,
|
|
1264
|
+
2227730452,
|
|
1265
|
+
2361852424,
|
|
1266
|
+
2428436474,
|
|
1267
|
+
2756734187,
|
|
1268
|
+
3204031479,
|
|
1269
|
+
3329325298
|
|
1270
|
+
]);
|
|
1271
|
+
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
1272
|
+
class SHA256 extends HashMD {
|
|
1273
|
+
constructor(outputLen = 32) {
|
|
1274
|
+
super(64, outputLen, 8, false);
|
|
1275
|
+
this.A = SHA256_IV[0] | 0;
|
|
1276
|
+
this.B = SHA256_IV[1] | 0;
|
|
1277
|
+
this.C = SHA256_IV[2] | 0;
|
|
1278
|
+
this.D = SHA256_IV[3] | 0;
|
|
1279
|
+
this.E = SHA256_IV[4] | 0;
|
|
1280
|
+
this.F = SHA256_IV[5] | 0;
|
|
1281
|
+
this.G = SHA256_IV[6] | 0;
|
|
1282
|
+
this.H = SHA256_IV[7] | 0;
|
|
1283
|
+
}
|
|
1284
|
+
get() {
|
|
1285
|
+
const { A, B, C, D, E, F, G, H } = this;
|
|
1286
|
+
return [A, B, C, D, E, F, G, H];
|
|
1287
|
+
}
|
|
1288
|
+
// prettier-ignore
|
|
1289
|
+
set(A, B, C, D, E, F, G, H) {
|
|
1290
|
+
this.A = A | 0;
|
|
1291
|
+
this.B = B | 0;
|
|
1292
|
+
this.C = C | 0;
|
|
1293
|
+
this.D = D | 0;
|
|
1294
|
+
this.E = E | 0;
|
|
1295
|
+
this.F = F | 0;
|
|
1296
|
+
this.G = G | 0;
|
|
1297
|
+
this.H = H | 0;
|
|
1298
|
+
}
|
|
1299
|
+
process(view, offset) {
|
|
1300
|
+
for (let i = 0; i < 16; i++, offset += 4)
|
|
1301
|
+
SHA256_W[i] = view.getUint32(offset, false);
|
|
1302
|
+
for (let i = 16; i < 64; i++) {
|
|
1303
|
+
const W15 = SHA256_W[i - 15];
|
|
1304
|
+
const W2 = SHA256_W[i - 2];
|
|
1305
|
+
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
1306
|
+
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
1307
|
+
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
1308
|
+
}
|
|
1309
|
+
let { A, B, C, D, E, F, G, H } = this;
|
|
1310
|
+
for (let i = 0; i < 64; i++) {
|
|
1311
|
+
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
1312
|
+
const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
1313
|
+
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
1314
|
+
const T2 = sigma0 + Maj(A, B, C) | 0;
|
|
1315
|
+
H = G;
|
|
1316
|
+
G = F;
|
|
1317
|
+
F = E;
|
|
1318
|
+
E = D + T1 | 0;
|
|
1319
|
+
D = C;
|
|
1320
|
+
C = B;
|
|
1321
|
+
B = A;
|
|
1322
|
+
A = T1 + T2 | 0;
|
|
1323
|
+
}
|
|
1324
|
+
A = A + this.A | 0;
|
|
1325
|
+
B = B + this.B | 0;
|
|
1326
|
+
C = C + this.C | 0;
|
|
1327
|
+
D = D + this.D | 0;
|
|
1328
|
+
E = E + this.E | 0;
|
|
1329
|
+
F = F + this.F | 0;
|
|
1330
|
+
G = G + this.G | 0;
|
|
1331
|
+
H = H + this.H | 0;
|
|
1332
|
+
this.set(A, B, C, D, E, F, G, H);
|
|
1333
|
+
}
|
|
1334
|
+
roundClean() {
|
|
1335
|
+
clean(SHA256_W);
|
|
1336
|
+
}
|
|
1337
|
+
destroy() {
|
|
1338
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
1339
|
+
clean(this.buffer);
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
const K512 = /* @__PURE__ */ (() => split([
|
|
1343
|
+
"0x428a2f98d728ae22",
|
|
1344
|
+
"0x7137449123ef65cd",
|
|
1345
|
+
"0xb5c0fbcfec4d3b2f",
|
|
1346
|
+
"0xe9b5dba58189dbbc",
|
|
1347
|
+
"0x3956c25bf348b538",
|
|
1348
|
+
"0x59f111f1b605d019",
|
|
1349
|
+
"0x923f82a4af194f9b",
|
|
1350
|
+
"0xab1c5ed5da6d8118",
|
|
1351
|
+
"0xd807aa98a3030242",
|
|
1352
|
+
"0x12835b0145706fbe",
|
|
1353
|
+
"0x243185be4ee4b28c",
|
|
1354
|
+
"0x550c7dc3d5ffb4e2",
|
|
1355
|
+
"0x72be5d74f27b896f",
|
|
1356
|
+
"0x80deb1fe3b1696b1",
|
|
1357
|
+
"0x9bdc06a725c71235",
|
|
1358
|
+
"0xc19bf174cf692694",
|
|
1359
|
+
"0xe49b69c19ef14ad2",
|
|
1360
|
+
"0xefbe4786384f25e3",
|
|
1361
|
+
"0x0fc19dc68b8cd5b5",
|
|
1362
|
+
"0x240ca1cc77ac9c65",
|
|
1363
|
+
"0x2de92c6f592b0275",
|
|
1364
|
+
"0x4a7484aa6ea6e483",
|
|
1365
|
+
"0x5cb0a9dcbd41fbd4",
|
|
1366
|
+
"0x76f988da831153b5",
|
|
1367
|
+
"0x983e5152ee66dfab",
|
|
1368
|
+
"0xa831c66d2db43210",
|
|
1369
|
+
"0xb00327c898fb213f",
|
|
1370
|
+
"0xbf597fc7beef0ee4",
|
|
1371
|
+
"0xc6e00bf33da88fc2",
|
|
1372
|
+
"0xd5a79147930aa725",
|
|
1373
|
+
"0x06ca6351e003826f",
|
|
1374
|
+
"0x142929670a0e6e70",
|
|
1375
|
+
"0x27b70a8546d22ffc",
|
|
1376
|
+
"0x2e1b21385c26c926",
|
|
1377
|
+
"0x4d2c6dfc5ac42aed",
|
|
1378
|
+
"0x53380d139d95b3df",
|
|
1379
|
+
"0x650a73548baf63de",
|
|
1380
|
+
"0x766a0abb3c77b2a8",
|
|
1381
|
+
"0x81c2c92e47edaee6",
|
|
1382
|
+
"0x92722c851482353b",
|
|
1383
|
+
"0xa2bfe8a14cf10364",
|
|
1384
|
+
"0xa81a664bbc423001",
|
|
1385
|
+
"0xc24b8b70d0f89791",
|
|
1386
|
+
"0xc76c51a30654be30",
|
|
1387
|
+
"0xd192e819d6ef5218",
|
|
1388
|
+
"0xd69906245565a910",
|
|
1389
|
+
"0xf40e35855771202a",
|
|
1390
|
+
"0x106aa07032bbd1b8",
|
|
1391
|
+
"0x19a4c116b8d2d0c8",
|
|
1392
|
+
"0x1e376c085141ab53",
|
|
1393
|
+
"0x2748774cdf8eeb99",
|
|
1394
|
+
"0x34b0bcb5e19b48a8",
|
|
1395
|
+
"0x391c0cb3c5c95a63",
|
|
1396
|
+
"0x4ed8aa4ae3418acb",
|
|
1397
|
+
"0x5b9cca4f7763e373",
|
|
1398
|
+
"0x682e6ff3d6b2b8a3",
|
|
1399
|
+
"0x748f82ee5defb2fc",
|
|
1400
|
+
"0x78a5636f43172f60",
|
|
1401
|
+
"0x84c87814a1f0ab72",
|
|
1402
|
+
"0x8cc702081a6439ec",
|
|
1403
|
+
"0x90befffa23631e28",
|
|
1404
|
+
"0xa4506cebde82bde9",
|
|
1405
|
+
"0xbef9a3f7b2c67915",
|
|
1406
|
+
"0xc67178f2e372532b",
|
|
1407
|
+
"0xca273eceea26619c",
|
|
1408
|
+
"0xd186b8c721c0c207",
|
|
1409
|
+
"0xeada7dd6cde0eb1e",
|
|
1410
|
+
"0xf57d4f7fee6ed178",
|
|
1411
|
+
"0x06f067aa72176fba",
|
|
1412
|
+
"0x0a637dc5a2c898a6",
|
|
1413
|
+
"0x113f9804bef90dae",
|
|
1414
|
+
"0x1b710b35131c471b",
|
|
1415
|
+
"0x28db77f523047d84",
|
|
1416
|
+
"0x32caab7b40c72493",
|
|
1417
|
+
"0x3c9ebe0a15c9bebc",
|
|
1418
|
+
"0x431d67c49c100d4c",
|
|
1419
|
+
"0x4cc5d4becb3e42b6",
|
|
1420
|
+
"0x597f299cfc657e2a",
|
|
1421
|
+
"0x5fcb6fab3ad6faec",
|
|
1422
|
+
"0x6c44198c4a475817"
|
|
1423
|
+
].map((n) => BigInt(n))))();
|
|
1424
|
+
const SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
|
|
1425
|
+
const SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
|
|
1426
|
+
const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
1427
|
+
const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
1428
|
+
class SHA512 extends HashMD {
|
|
1429
|
+
constructor(outputLen = 64) {
|
|
1430
|
+
super(128, outputLen, 16, false);
|
|
1431
|
+
this.Ah = SHA512_IV[0] | 0;
|
|
1432
|
+
this.Al = SHA512_IV[1] | 0;
|
|
1433
|
+
this.Bh = SHA512_IV[2] | 0;
|
|
1434
|
+
this.Bl = SHA512_IV[3] | 0;
|
|
1435
|
+
this.Ch = SHA512_IV[4] | 0;
|
|
1436
|
+
this.Cl = SHA512_IV[5] | 0;
|
|
1437
|
+
this.Dh = SHA512_IV[6] | 0;
|
|
1438
|
+
this.Dl = SHA512_IV[7] | 0;
|
|
1439
|
+
this.Eh = SHA512_IV[8] | 0;
|
|
1440
|
+
this.El = SHA512_IV[9] | 0;
|
|
1441
|
+
this.Fh = SHA512_IV[10] | 0;
|
|
1442
|
+
this.Fl = SHA512_IV[11] | 0;
|
|
1443
|
+
this.Gh = SHA512_IV[12] | 0;
|
|
1444
|
+
this.Gl = SHA512_IV[13] | 0;
|
|
1445
|
+
this.Hh = SHA512_IV[14] | 0;
|
|
1446
|
+
this.Hl = SHA512_IV[15] | 0;
|
|
1447
|
+
}
|
|
1448
|
+
// prettier-ignore
|
|
1449
|
+
get() {
|
|
1450
|
+
const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
1451
|
+
return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
|
|
1452
|
+
}
|
|
1453
|
+
// prettier-ignore
|
|
1454
|
+
set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
|
|
1455
|
+
this.Ah = Ah | 0;
|
|
1456
|
+
this.Al = Al | 0;
|
|
1457
|
+
this.Bh = Bh | 0;
|
|
1458
|
+
this.Bl = Bl | 0;
|
|
1459
|
+
this.Ch = Ch | 0;
|
|
1460
|
+
this.Cl = Cl | 0;
|
|
1461
|
+
this.Dh = Dh | 0;
|
|
1462
|
+
this.Dl = Dl | 0;
|
|
1463
|
+
this.Eh = Eh | 0;
|
|
1464
|
+
this.El = El | 0;
|
|
1465
|
+
this.Fh = Fh | 0;
|
|
1466
|
+
this.Fl = Fl | 0;
|
|
1467
|
+
this.Gh = Gh | 0;
|
|
1468
|
+
this.Gl = Gl | 0;
|
|
1469
|
+
this.Hh = Hh | 0;
|
|
1470
|
+
this.Hl = Hl | 0;
|
|
1471
|
+
}
|
|
1472
|
+
process(view, offset) {
|
|
1473
|
+
for (let i = 0; i < 16; i++, offset += 4) {
|
|
1474
|
+
SHA512_W_H[i] = view.getUint32(offset);
|
|
1475
|
+
SHA512_W_L[i] = view.getUint32(offset += 4);
|
|
1476
|
+
}
|
|
1477
|
+
for (let i = 16; i < 80; i++) {
|
|
1478
|
+
const W15h = SHA512_W_H[i - 15] | 0;
|
|
1479
|
+
const W15l = SHA512_W_L[i - 15] | 0;
|
|
1480
|
+
const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
|
|
1481
|
+
const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
|
|
1482
|
+
const W2h = SHA512_W_H[i - 2] | 0;
|
|
1483
|
+
const W2l = SHA512_W_L[i - 2] | 0;
|
|
1484
|
+
const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
|
|
1485
|
+
const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
|
|
1486
|
+
const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
|
|
1487
|
+
const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
|
|
1488
|
+
SHA512_W_H[i] = SUMh | 0;
|
|
1489
|
+
SHA512_W_L[i] = SUMl | 0;
|
|
1490
|
+
}
|
|
1491
|
+
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
1492
|
+
for (let i = 0; i < 80; i++) {
|
|
1493
|
+
const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
|
|
1494
|
+
const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
|
|
1495
|
+
const CHIh = Eh & Fh ^ ~Eh & Gh;
|
|
1496
|
+
const CHIl = El & Fl ^ ~El & Gl;
|
|
1497
|
+
const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
|
|
1498
|
+
const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
|
|
1499
|
+
const T1l = T1ll | 0;
|
|
1500
|
+
const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
|
|
1501
|
+
const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
|
|
1502
|
+
const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
|
|
1503
|
+
const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
|
|
1504
|
+
Hh = Gh | 0;
|
|
1505
|
+
Hl = Gl | 0;
|
|
1506
|
+
Gh = Fh | 0;
|
|
1507
|
+
Gl = Fl | 0;
|
|
1508
|
+
Fh = Eh | 0;
|
|
1509
|
+
Fl = El | 0;
|
|
1510
|
+
({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
1511
|
+
Dh = Ch | 0;
|
|
1512
|
+
Dl = Cl | 0;
|
|
1513
|
+
Ch = Bh | 0;
|
|
1514
|
+
Cl = Bl | 0;
|
|
1515
|
+
Bh = Ah | 0;
|
|
1516
|
+
Bl = Al | 0;
|
|
1517
|
+
const All = add3L(T1l, sigma0l, MAJl);
|
|
1518
|
+
Ah = add3H(All, T1h, sigma0h, MAJh);
|
|
1519
|
+
Al = All | 0;
|
|
1520
|
+
}
|
|
1521
|
+
({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
1522
|
+
({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
|
1523
|
+
({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
1524
|
+
({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
1525
|
+
({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
1526
|
+
({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
1527
|
+
({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
1528
|
+
({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
1529
|
+
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
1530
|
+
}
|
|
1531
|
+
roundClean() {
|
|
1532
|
+
clean(SHA512_W_H, SHA512_W_L);
|
|
1533
|
+
}
|
|
1534
|
+
destroy() {
|
|
1535
|
+
clean(this.buffer);
|
|
1536
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
const sha256$2 = /* @__PURE__ */ createHasher(() => new SHA256());
|
|
1540
|
+
const sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
|
|
1541
|
+
const sha256$1 = sha256$2;
|
|
1542
|
+
function sha256(value, to_) {
|
|
1543
|
+
const to = to_ || "hex";
|
|
1544
|
+
const bytes = sha256$1(isHex(value, { strict: false }) ? toBytes$1(value) : value);
|
|
1545
|
+
if (to === "bytes")
|
|
1546
|
+
return bytes;
|
|
1547
|
+
return toHex(bytes);
|
|
1548
|
+
}
|
|
1549
|
+
function commitmentToVersionedHash(parameters) {
|
|
1550
|
+
const { commitment, version: version2 = 1 } = parameters;
|
|
1551
|
+
const to = parameters.to ?? (typeof commitment === "string" ? "hex" : "bytes");
|
|
1552
|
+
const versionedHash = sha256(commitment, "bytes");
|
|
1553
|
+
versionedHash.set([version2], 0);
|
|
1554
|
+
return to === "bytes" ? versionedHash : bytesToHex$1(versionedHash);
|
|
1555
|
+
}
|
|
1556
|
+
function commitmentsToVersionedHashes(parameters) {
|
|
1557
|
+
const { commitments, version: version2 } = parameters;
|
|
1558
|
+
const to = parameters.to ?? (typeof commitments[0] === "string" ? "hex" : "bytes");
|
|
1559
|
+
const hashes = [];
|
|
1560
|
+
for (const commitment of commitments) {
|
|
1561
|
+
hashes.push(commitmentToVersionedHash({
|
|
1562
|
+
commitment,
|
|
1563
|
+
to,
|
|
1564
|
+
version: version2
|
|
1565
|
+
}));
|
|
1566
|
+
}
|
|
1567
|
+
return hashes;
|
|
1568
|
+
}
|
|
1569
|
+
const blobsPerTransaction = 6;
|
|
1570
|
+
const bytesPerFieldElement = 32;
|
|
1571
|
+
const fieldElementsPerBlob = 4096;
|
|
1572
|
+
const bytesPerBlob = bytesPerFieldElement * fieldElementsPerBlob;
|
|
1573
|
+
const maxBytesPerTransaction = bytesPerBlob * blobsPerTransaction - // terminator byte (0x80).
|
|
1574
|
+
1 - // zero byte (0x00) appended to each field element.
|
|
1575
|
+
1 * fieldElementsPerBlob * blobsPerTransaction;
|
|
1576
|
+
const versionedHashVersionKzg = 1;
|
|
1577
|
+
class BlobSizeTooLargeError extends BaseError {
|
|
1578
|
+
constructor({ maxSize, size: size2 }) {
|
|
1579
|
+
super("Blob size is too large.", {
|
|
1580
|
+
metaMessages: [`Max: ${maxSize} bytes`, `Given: ${size2} bytes`],
|
|
1581
|
+
name: "BlobSizeTooLargeError"
|
|
1582
|
+
});
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
class EmptyBlobError extends BaseError {
|
|
1586
|
+
constructor() {
|
|
1587
|
+
super("Blob data must not be empty.", { name: "EmptyBlobError" });
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
class InvalidVersionedHashSizeError extends BaseError {
|
|
1591
|
+
constructor({ hash, size: size2 }) {
|
|
1592
|
+
super(`Versioned hash "${hash}" size is invalid.`, {
|
|
1593
|
+
metaMessages: ["Expected: 32", `Received: ${size2}`],
|
|
1594
|
+
name: "InvalidVersionedHashSizeError"
|
|
1595
|
+
});
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
class InvalidVersionedHashVersionError extends BaseError {
|
|
1599
|
+
constructor({ hash, version: version2 }) {
|
|
1600
|
+
super(`Versioned hash "${hash}" version is invalid.`, {
|
|
1601
|
+
metaMessages: [
|
|
1602
|
+
`Expected: ${versionedHashVersionKzg}`,
|
|
1603
|
+
`Received: ${version2}`
|
|
1604
|
+
],
|
|
1605
|
+
name: "InvalidVersionedHashVersionError"
|
|
1606
|
+
});
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
function toBlobs(parameters) {
|
|
1610
|
+
const to = parameters.to ?? (typeof parameters.data === "string" ? "hex" : "bytes");
|
|
1611
|
+
const data = typeof parameters.data === "string" ? hexToBytes$1(parameters.data) : parameters.data;
|
|
1612
|
+
const size_ = size(data);
|
|
1613
|
+
if (!size_)
|
|
1614
|
+
throw new EmptyBlobError();
|
|
1615
|
+
if (size_ > maxBytesPerTransaction)
|
|
1616
|
+
throw new BlobSizeTooLargeError({
|
|
1617
|
+
maxSize: maxBytesPerTransaction,
|
|
1618
|
+
size: size_
|
|
1619
|
+
});
|
|
1620
|
+
const blobs = [];
|
|
1621
|
+
let active = true;
|
|
1622
|
+
let position = 0;
|
|
1623
|
+
while (active) {
|
|
1624
|
+
const blob = createCursor(new Uint8Array(bytesPerBlob));
|
|
1625
|
+
let size2 = 0;
|
|
1626
|
+
while (size2 < fieldElementsPerBlob) {
|
|
1627
|
+
const bytes = data.slice(position, position + (bytesPerFieldElement - 1));
|
|
1628
|
+
blob.pushByte(0);
|
|
1629
|
+
blob.pushBytes(bytes);
|
|
1630
|
+
if (bytes.length < 31) {
|
|
1631
|
+
blob.pushByte(128);
|
|
1632
|
+
active = false;
|
|
1633
|
+
break;
|
|
1634
|
+
}
|
|
1635
|
+
size2++;
|
|
1636
|
+
position += 31;
|
|
1637
|
+
}
|
|
1638
|
+
blobs.push(blob);
|
|
1639
|
+
}
|
|
1640
|
+
return to === "bytes" ? blobs.map((x) => x.bytes) : blobs.map((x) => bytesToHex$1(x.bytes));
|
|
1641
|
+
}
|
|
1642
|
+
function toBlobSidecars(parameters) {
|
|
1643
|
+
const { data, kzg, to } = parameters;
|
|
1644
|
+
const blobs = parameters.blobs ?? toBlobs({ data, to });
|
|
1645
|
+
const commitments = parameters.commitments ?? blobsToCommitments({ blobs, kzg, to });
|
|
1646
|
+
const proofs = parameters.proofs ?? blobsToProofs({ blobs, commitments, kzg, to });
|
|
1647
|
+
const sidecars = [];
|
|
1648
|
+
for (let i = 0; i < blobs.length; i++)
|
|
1649
|
+
sidecars.push({
|
|
1650
|
+
blob: blobs[i],
|
|
1651
|
+
commitment: commitments[i],
|
|
1652
|
+
proof: proofs[i]
|
|
1653
|
+
});
|
|
1654
|
+
return sidecars;
|
|
1655
|
+
}
|
|
1656
|
+
class InvalidAddressError extends BaseError {
|
|
1657
|
+
constructor({ address }) {
|
|
1658
|
+
super(`Address "${address}" is invalid.`, {
|
|
1659
|
+
metaMessages: [
|
|
1660
|
+
"- Address must be a hex value of 20 bytes (40 hex characters).",
|
|
1661
|
+
"- Address must match its checksum counterpart."
|
|
1662
|
+
],
|
|
1663
|
+
name: "InvalidAddressError"
|
|
1664
|
+
});
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
class InvalidChainIdError extends BaseError {
|
|
1668
|
+
constructor({ chainId }) {
|
|
1669
|
+
super(typeof chainId === "number" ? `Chain ID "${chainId}" is invalid.` : "Chain ID is invalid.", { name: "InvalidChainIdError" });
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
class ExecutionRevertedError extends BaseError {
|
|
1673
|
+
constructor({ cause, message } = {}) {
|
|
1674
|
+
var _a;
|
|
1675
|
+
const reason = (_a = message == null ? void 0 : message.replace("execution reverted: ", "")) == null ? void 0 : _a.replace("execution reverted", "");
|
|
1676
|
+
super(`Execution reverted ${reason ? `with reason: ${reason}` : "for an unknown reason"}.`, {
|
|
1677
|
+
cause,
|
|
1678
|
+
name: "ExecutionRevertedError"
|
|
1679
|
+
});
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
Object.defineProperty(ExecutionRevertedError, "code", {
|
|
1683
|
+
enumerable: true,
|
|
1684
|
+
configurable: true,
|
|
1685
|
+
writable: true,
|
|
1686
|
+
value: 3
|
|
1687
|
+
});
|
|
1688
|
+
Object.defineProperty(ExecutionRevertedError, "nodeMessage", {
|
|
1689
|
+
enumerable: true,
|
|
1690
|
+
configurable: true,
|
|
1691
|
+
writable: true,
|
|
1692
|
+
value: /execution reverted|gas required exceeds allowance/
|
|
1693
|
+
});
|
|
1694
|
+
class FeeCapTooHighError extends BaseError {
|
|
1695
|
+
constructor({ cause, maxFeePerGas } = {}) {
|
|
1696
|
+
super(`The fee cap (\`maxFeePerGas\`${maxFeePerGas ? ` = ${formatGwei(maxFeePerGas)} gwei` : ""}) cannot be higher than the maximum allowed value (2^256-1).`, {
|
|
1697
|
+
cause,
|
|
1698
|
+
name: "FeeCapTooHighError"
|
|
1699
|
+
});
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
Object.defineProperty(FeeCapTooHighError, "nodeMessage", {
|
|
1703
|
+
enumerable: true,
|
|
1704
|
+
configurable: true,
|
|
1705
|
+
writable: true,
|
|
1706
|
+
value: /max fee per gas higher than 2\^256-1|fee cap higher than 2\^256-1/
|
|
1707
|
+
});
|
|
1708
|
+
class FeeCapTooLowError extends BaseError {
|
|
1709
|
+
constructor({ cause, maxFeePerGas } = {}) {
|
|
1710
|
+
super(`The fee cap (\`maxFeePerGas\`${maxFeePerGas ? ` = ${formatGwei(maxFeePerGas)}` : ""} gwei) cannot be lower than the block base fee.`, {
|
|
1711
|
+
cause,
|
|
1712
|
+
name: "FeeCapTooLowError"
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
Object.defineProperty(FeeCapTooLowError, "nodeMessage", {
|
|
1717
|
+
enumerable: true,
|
|
1718
|
+
configurable: true,
|
|
1719
|
+
writable: true,
|
|
1720
|
+
value: /max fee per gas less than block base fee|fee cap less than block base fee|transaction is outdated/
|
|
1721
|
+
});
|
|
1722
|
+
class NonceTooHighError extends BaseError {
|
|
1723
|
+
constructor({ cause, nonce } = {}) {
|
|
1724
|
+
super(`Nonce provided for the transaction ${nonce ? `(${nonce}) ` : ""}is higher than the next one expected.`, { cause, name: "NonceTooHighError" });
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
Object.defineProperty(NonceTooHighError, "nodeMessage", {
|
|
1728
|
+
enumerable: true,
|
|
1729
|
+
configurable: true,
|
|
1730
|
+
writable: true,
|
|
1731
|
+
value: /nonce too high/
|
|
1732
|
+
});
|
|
1733
|
+
class NonceTooLowError extends BaseError {
|
|
1734
|
+
constructor({ cause, nonce } = {}) {
|
|
1735
|
+
super([
|
|
1736
|
+
`Nonce provided for the transaction ${nonce ? `(${nonce}) ` : ""}is lower than the current nonce of the account.`,
|
|
1737
|
+
"Try increasing the nonce or find the latest nonce with `getTransactionCount`."
|
|
1738
|
+
].join("\n"), { cause, name: "NonceTooLowError" });
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
Object.defineProperty(NonceTooLowError, "nodeMessage", {
|
|
1742
|
+
enumerable: true,
|
|
1743
|
+
configurable: true,
|
|
1744
|
+
writable: true,
|
|
1745
|
+
value: /nonce too low|transaction already imported|already known/
|
|
1746
|
+
});
|
|
1747
|
+
class NonceMaxValueError extends BaseError {
|
|
1748
|
+
constructor({ cause, nonce } = {}) {
|
|
1749
|
+
super(`Nonce provided for the transaction ${nonce ? `(${nonce}) ` : ""}exceeds the maximum allowed nonce.`, { cause, name: "NonceMaxValueError" });
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
Object.defineProperty(NonceMaxValueError, "nodeMessage", {
|
|
1753
|
+
enumerable: true,
|
|
1754
|
+
configurable: true,
|
|
1755
|
+
writable: true,
|
|
1756
|
+
value: /nonce has max value/
|
|
1757
|
+
});
|
|
1758
|
+
class InsufficientFundsError extends BaseError {
|
|
1759
|
+
constructor({ cause } = {}) {
|
|
1760
|
+
super([
|
|
1761
|
+
"The total cost (gas * gas fee + value) of executing this transaction exceeds the balance of the account."
|
|
1762
|
+
].join("\n"), {
|
|
1763
|
+
cause,
|
|
1764
|
+
metaMessages: [
|
|
1765
|
+
"This error could arise when the account does not have enough funds to:",
|
|
1766
|
+
" - pay for the total gas fee,",
|
|
1767
|
+
" - pay for the value to send.",
|
|
1768
|
+
" ",
|
|
1769
|
+
"The cost of the transaction is calculated as `gas * gas fee + value`, where:",
|
|
1770
|
+
" - `gas` is the amount of gas needed for transaction to execute,",
|
|
1771
|
+
" - `gas fee` is the gas fee,",
|
|
1772
|
+
" - `value` is the amount of ether to send to the recipient."
|
|
1773
|
+
],
|
|
1774
|
+
name: "InsufficientFundsError"
|
|
1775
|
+
});
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
Object.defineProperty(InsufficientFundsError, "nodeMessage", {
|
|
1779
|
+
enumerable: true,
|
|
1780
|
+
configurable: true,
|
|
1781
|
+
writable: true,
|
|
1782
|
+
value: /insufficient funds|exceeds transaction sender account balance/
|
|
1783
|
+
});
|
|
1784
|
+
class IntrinsicGasTooHighError extends BaseError {
|
|
1785
|
+
constructor({ cause, gas } = {}) {
|
|
1786
|
+
super(`The amount of gas ${gas ? `(${gas}) ` : ""}provided for the transaction exceeds the limit allowed for the block.`, {
|
|
1787
|
+
cause,
|
|
1788
|
+
name: "IntrinsicGasTooHighError"
|
|
1789
|
+
});
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
Object.defineProperty(IntrinsicGasTooHighError, "nodeMessage", {
|
|
1793
|
+
enumerable: true,
|
|
1794
|
+
configurable: true,
|
|
1795
|
+
writable: true,
|
|
1796
|
+
value: /intrinsic gas too high|gas limit reached/
|
|
1797
|
+
});
|
|
1798
|
+
class IntrinsicGasTooLowError extends BaseError {
|
|
1799
|
+
constructor({ cause, gas } = {}) {
|
|
1800
|
+
super(`The amount of gas ${gas ? `(${gas}) ` : ""}provided for the transaction is too low.`, {
|
|
1801
|
+
cause,
|
|
1802
|
+
name: "IntrinsicGasTooLowError"
|
|
1803
|
+
});
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
Object.defineProperty(IntrinsicGasTooLowError, "nodeMessage", {
|
|
1807
|
+
enumerable: true,
|
|
1808
|
+
configurable: true,
|
|
1809
|
+
writable: true,
|
|
1810
|
+
value: /intrinsic gas too low/
|
|
1811
|
+
});
|
|
1812
|
+
class TransactionTypeNotSupportedError extends BaseError {
|
|
1813
|
+
constructor({ cause }) {
|
|
1814
|
+
super("The transaction type is not supported for this chain.", {
|
|
1815
|
+
cause,
|
|
1816
|
+
name: "TransactionTypeNotSupportedError"
|
|
1817
|
+
});
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
Object.defineProperty(TransactionTypeNotSupportedError, "nodeMessage", {
|
|
1821
|
+
enumerable: true,
|
|
1822
|
+
configurable: true,
|
|
1823
|
+
writable: true,
|
|
1824
|
+
value: /transaction type not valid/
|
|
1825
|
+
});
|
|
1826
|
+
class TipAboveFeeCapError extends BaseError {
|
|
1827
|
+
constructor({ cause, maxPriorityFeePerGas, maxFeePerGas } = {}) {
|
|
1828
|
+
super([
|
|
1829
|
+
`The provided tip (\`maxPriorityFeePerGas\`${maxPriorityFeePerGas ? ` = ${formatGwei(maxPriorityFeePerGas)} gwei` : ""}) cannot be higher than the fee cap (\`maxFeePerGas\`${maxFeePerGas ? ` = ${formatGwei(maxFeePerGas)} gwei` : ""}).`
|
|
1830
|
+
].join("\n"), {
|
|
1831
|
+
cause,
|
|
1832
|
+
name: "TipAboveFeeCapError"
|
|
1833
|
+
});
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
Object.defineProperty(TipAboveFeeCapError, "nodeMessage", {
|
|
1837
|
+
enumerable: true,
|
|
1838
|
+
configurable: true,
|
|
1839
|
+
writable: true,
|
|
1840
|
+
value: /max priority fee per gas higher than max fee per gas|tip higher than fee cap/
|
|
1841
|
+
});
|
|
1842
|
+
class UnknownNodeError extends BaseError {
|
|
1843
|
+
constructor({ cause }) {
|
|
1844
|
+
super(`An error occurred while executing: ${cause == null ? void 0 : cause.shortMessage}`, {
|
|
1845
|
+
cause,
|
|
1846
|
+
name: "UnknownNodeError"
|
|
1847
|
+
});
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
class LruMap extends Map {
|
|
1851
|
+
constructor(size2) {
|
|
1852
|
+
super();
|
|
1853
|
+
Object.defineProperty(this, "maxSize", {
|
|
1854
|
+
enumerable: true,
|
|
1855
|
+
configurable: true,
|
|
1856
|
+
writable: true,
|
|
1857
|
+
value: void 0
|
|
1858
|
+
});
|
|
1859
|
+
this.maxSize = size2;
|
|
1860
|
+
}
|
|
1861
|
+
get(key) {
|
|
1862
|
+
const value = super.get(key);
|
|
1863
|
+
if (super.has(key) && value !== void 0) {
|
|
1864
|
+
this.delete(key);
|
|
1865
|
+
super.set(key, value);
|
|
1866
|
+
}
|
|
1867
|
+
return value;
|
|
1868
|
+
}
|
|
1869
|
+
set(key, value) {
|
|
1870
|
+
super.set(key, value);
|
|
1871
|
+
if (this.maxSize && this.size > this.maxSize) {
|
|
1872
|
+
const firstKey = this.keys().next().value;
|
|
1873
|
+
if (firstKey)
|
|
1874
|
+
this.delete(firstKey);
|
|
1875
|
+
}
|
|
1876
|
+
return this;
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
const _0n = BigInt(0);
|
|
1880
|
+
const _1n = BigInt(1);
|
|
1881
|
+
const _2n = BigInt(2);
|
|
1882
|
+
const _7n = BigInt(7);
|
|
1883
|
+
const _256n = BigInt(256);
|
|
1884
|
+
const _0x71n = BigInt(113);
|
|
1885
|
+
const SHA3_PI = [];
|
|
1886
|
+
const SHA3_ROTL = [];
|
|
1887
|
+
const _SHA3_IOTA = [];
|
|
1888
|
+
for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
|
|
1889
|
+
[x, y] = [y, (2 * x + 3 * y) % 5];
|
|
1890
|
+
SHA3_PI.push(2 * (5 * y + x));
|
|
1891
|
+
SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
|
|
1892
|
+
let t = _0n;
|
|
1893
|
+
for (let j = 0; j < 7; j++) {
|
|
1894
|
+
R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n;
|
|
1895
|
+
if (R & _2n)
|
|
1896
|
+
t ^= _1n << (_1n << /* @__PURE__ */ BigInt(j)) - _1n;
|
|
1897
|
+
}
|
|
1898
|
+
_SHA3_IOTA.push(t);
|
|
1899
|
+
}
|
|
1900
|
+
const IOTAS = split(_SHA3_IOTA, true);
|
|
1901
|
+
const SHA3_IOTA_H = IOTAS[0];
|
|
1902
|
+
const SHA3_IOTA_L = IOTAS[1];
|
|
1903
|
+
const rotlH = (h, l, s) => s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s);
|
|
1904
|
+
const rotlL = (h, l, s) => s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s);
|
|
1905
|
+
function keccakP(s, rounds = 24) {
|
|
1906
|
+
const B = new Uint32Array(5 * 2);
|
|
1907
|
+
for (let round = 24 - rounds; round < 24; round++) {
|
|
1908
|
+
for (let x = 0; x < 10; x++)
|
|
1909
|
+
B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
|
|
1910
|
+
for (let x = 0; x < 10; x += 2) {
|
|
1911
|
+
const idx1 = (x + 8) % 10;
|
|
1912
|
+
const idx0 = (x + 2) % 10;
|
|
1913
|
+
const B0 = B[idx0];
|
|
1914
|
+
const B1 = B[idx0 + 1];
|
|
1915
|
+
const Th = rotlH(B0, B1, 1) ^ B[idx1];
|
|
1916
|
+
const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
|
|
1917
|
+
for (let y = 0; y < 50; y += 10) {
|
|
1918
|
+
s[x + y] ^= Th;
|
|
1919
|
+
s[x + y + 1] ^= Tl;
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
let curH = s[2];
|
|
1923
|
+
let curL = s[3];
|
|
1924
|
+
for (let t = 0; t < 24; t++) {
|
|
1925
|
+
const shift = SHA3_ROTL[t];
|
|
1926
|
+
const Th = rotlH(curH, curL, shift);
|
|
1927
|
+
const Tl = rotlL(curH, curL, shift);
|
|
1928
|
+
const PI = SHA3_PI[t];
|
|
1929
|
+
curH = s[PI];
|
|
1930
|
+
curL = s[PI + 1];
|
|
1931
|
+
s[PI] = Th;
|
|
1932
|
+
s[PI + 1] = Tl;
|
|
1933
|
+
}
|
|
1934
|
+
for (let y = 0; y < 50; y += 10) {
|
|
1935
|
+
for (let x = 0; x < 10; x++)
|
|
1936
|
+
B[x] = s[y + x];
|
|
1937
|
+
for (let x = 0; x < 10; x++)
|
|
1938
|
+
s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
|
|
1939
|
+
}
|
|
1940
|
+
s[0] ^= SHA3_IOTA_H[round];
|
|
1941
|
+
s[1] ^= SHA3_IOTA_L[round];
|
|
1942
|
+
}
|
|
1943
|
+
clean(B);
|
|
1944
|
+
}
|
|
1945
|
+
class Keccak extends Hash {
|
|
1946
|
+
// NOTE: we accept arguments in bytes instead of bits here.
|
|
1947
|
+
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
|
1948
|
+
super();
|
|
1949
|
+
this.pos = 0;
|
|
1950
|
+
this.posOut = 0;
|
|
1951
|
+
this.finished = false;
|
|
1952
|
+
this.destroyed = false;
|
|
1953
|
+
this.enableXOF = false;
|
|
1954
|
+
this.blockLen = blockLen;
|
|
1955
|
+
this.suffix = suffix;
|
|
1956
|
+
this.outputLen = outputLen;
|
|
1957
|
+
this.enableXOF = enableXOF;
|
|
1958
|
+
this.rounds = rounds;
|
|
1959
|
+
anumber(outputLen);
|
|
1960
|
+
if (!(0 < blockLen && blockLen < 200))
|
|
1961
|
+
throw new Error("only keccak-f1600 function is supported");
|
|
1962
|
+
this.state = new Uint8Array(200);
|
|
1963
|
+
this.state32 = u32(this.state);
|
|
1964
|
+
}
|
|
1965
|
+
clone() {
|
|
1966
|
+
return this._cloneInto();
|
|
1967
|
+
}
|
|
1968
|
+
keccak() {
|
|
1969
|
+
swap32IfBE(this.state32);
|
|
1970
|
+
keccakP(this.state32, this.rounds);
|
|
1971
|
+
swap32IfBE(this.state32);
|
|
1972
|
+
this.posOut = 0;
|
|
1973
|
+
this.pos = 0;
|
|
1974
|
+
}
|
|
1975
|
+
update(data) {
|
|
1976
|
+
aexists(this);
|
|
1977
|
+
data = toBytes(data);
|
|
1978
|
+
abytes(data);
|
|
1979
|
+
const { blockLen, state } = this;
|
|
1980
|
+
const len = data.length;
|
|
1981
|
+
for (let pos = 0; pos < len; ) {
|
|
1982
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
1983
|
+
for (let i = 0; i < take; i++)
|
|
1984
|
+
state[this.pos++] ^= data[pos++];
|
|
1985
|
+
if (this.pos === blockLen)
|
|
1986
|
+
this.keccak();
|
|
1987
|
+
}
|
|
1988
|
+
return this;
|
|
1989
|
+
}
|
|
1990
|
+
finish() {
|
|
1991
|
+
if (this.finished)
|
|
1992
|
+
return;
|
|
1993
|
+
this.finished = true;
|
|
1994
|
+
const { state, suffix, pos, blockLen } = this;
|
|
1995
|
+
state[pos] ^= suffix;
|
|
1996
|
+
if ((suffix & 128) !== 0 && pos === blockLen - 1)
|
|
1997
|
+
this.keccak();
|
|
1998
|
+
state[blockLen - 1] ^= 128;
|
|
1999
|
+
this.keccak();
|
|
2000
|
+
}
|
|
2001
|
+
writeInto(out) {
|
|
2002
|
+
aexists(this, false);
|
|
2003
|
+
abytes(out);
|
|
2004
|
+
this.finish();
|
|
2005
|
+
const bufferOut = this.state;
|
|
2006
|
+
const { blockLen } = this;
|
|
2007
|
+
for (let pos = 0, len = out.length; pos < len; ) {
|
|
2008
|
+
if (this.posOut >= blockLen)
|
|
2009
|
+
this.keccak();
|
|
2010
|
+
const take = Math.min(blockLen - this.posOut, len - pos);
|
|
2011
|
+
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
|
2012
|
+
this.posOut += take;
|
|
2013
|
+
pos += take;
|
|
2014
|
+
}
|
|
2015
|
+
return out;
|
|
2016
|
+
}
|
|
2017
|
+
xofInto(out) {
|
|
2018
|
+
if (!this.enableXOF)
|
|
2019
|
+
throw new Error("XOF is not possible for this instance");
|
|
2020
|
+
return this.writeInto(out);
|
|
2021
|
+
}
|
|
2022
|
+
xof(bytes) {
|
|
2023
|
+
anumber(bytes);
|
|
2024
|
+
return this.xofInto(new Uint8Array(bytes));
|
|
2025
|
+
}
|
|
2026
|
+
digestInto(out) {
|
|
2027
|
+
aoutput(out, this);
|
|
2028
|
+
if (this.finished)
|
|
2029
|
+
throw new Error("digest() was already called");
|
|
2030
|
+
this.writeInto(out);
|
|
2031
|
+
this.destroy();
|
|
2032
|
+
return out;
|
|
2033
|
+
}
|
|
2034
|
+
digest() {
|
|
2035
|
+
return this.digestInto(new Uint8Array(this.outputLen));
|
|
2036
|
+
}
|
|
2037
|
+
destroy() {
|
|
2038
|
+
this.destroyed = true;
|
|
2039
|
+
clean(this.state);
|
|
2040
|
+
}
|
|
2041
|
+
_cloneInto(to) {
|
|
2042
|
+
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
2043
|
+
to || (to = new Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
|
|
2044
|
+
to.state32.set(this.state32);
|
|
2045
|
+
to.pos = this.pos;
|
|
2046
|
+
to.posOut = this.posOut;
|
|
2047
|
+
to.finished = this.finished;
|
|
2048
|
+
to.rounds = rounds;
|
|
2049
|
+
to.suffix = suffix;
|
|
2050
|
+
to.outputLen = outputLen;
|
|
2051
|
+
to.enableXOF = enableXOF;
|
|
2052
|
+
to.destroyed = this.destroyed;
|
|
2053
|
+
return to;
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
const gen = (suffix, blockLen, outputLen) => createHasher(() => new Keccak(blockLen, suffix, outputLen));
|
|
2057
|
+
const keccak_256 = /* @__PURE__ */ (() => gen(1, 136, 256 / 8))();
|
|
2058
|
+
function keccak256(value, to_) {
|
|
2059
|
+
const bytes = keccak_256(isHex(value, { strict: false }) ? toBytes$1(value) : value);
|
|
2060
|
+
return bytes;
|
|
2061
|
+
}
|
|
2062
|
+
const checksumAddressCache = /* @__PURE__ */ new LruMap(8192);
|
|
2063
|
+
function checksumAddress(address_, chainId) {
|
|
2064
|
+
if (checksumAddressCache.has(`${address_}.${chainId}`))
|
|
2065
|
+
return checksumAddressCache.get(`${address_}.${chainId}`);
|
|
2066
|
+
const hexAddress = address_.substring(2).toLowerCase();
|
|
2067
|
+
const hash = keccak256(stringToBytes(hexAddress));
|
|
2068
|
+
const address = hexAddress.split("");
|
|
2069
|
+
for (let i = 0; i < 40; i += 2) {
|
|
2070
|
+
if (hash[i >> 1] >> 4 >= 8 && address[i]) {
|
|
2071
|
+
address[i] = address[i].toUpperCase();
|
|
2072
|
+
}
|
|
2073
|
+
if ((hash[i >> 1] & 15) >= 8 && address[i + 1]) {
|
|
2074
|
+
address[i + 1] = address[i + 1].toUpperCase();
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
const result = `0x${address.join("")}`;
|
|
2078
|
+
checksumAddressCache.set(`${address_}.${chainId}`, result);
|
|
2079
|
+
return result;
|
|
2080
|
+
}
|
|
2081
|
+
const addressRegex = /^0x[a-fA-F0-9]{40}$/;
|
|
2082
|
+
const isAddressCache = /* @__PURE__ */ new LruMap(8192);
|
|
2083
|
+
function isAddress(address, options) {
|
|
2084
|
+
const { strict = true } = options ?? {};
|
|
2085
|
+
const cacheKey = `${address}.${strict}`;
|
|
2086
|
+
if (isAddressCache.has(cacheKey))
|
|
2087
|
+
return isAddressCache.get(cacheKey);
|
|
2088
|
+
const result = (() => {
|
|
2089
|
+
if (!addressRegex.test(address))
|
|
2090
|
+
return false;
|
|
2091
|
+
if (address.toLowerCase() === address)
|
|
2092
|
+
return true;
|
|
2093
|
+
if (strict)
|
|
2094
|
+
return checksumAddress(address) === address;
|
|
2095
|
+
return true;
|
|
2096
|
+
})();
|
|
2097
|
+
isAddressCache.set(cacheKey, result);
|
|
2098
|
+
return result;
|
|
2099
|
+
}
|
|
2100
|
+
function slice(value, start, end, { strict } = {}) {
|
|
2101
|
+
if (isHex(value, { strict: false }))
|
|
2102
|
+
return sliceHex(value, start, end, {
|
|
2103
|
+
strict
|
|
2104
|
+
});
|
|
2105
|
+
return sliceBytes(value, start, end, {
|
|
2106
|
+
strict
|
|
2107
|
+
});
|
|
2108
|
+
}
|
|
2109
|
+
function assertEndOffset(value, start, end) {
|
|
2110
|
+
if (size(value) !== end - start) {
|
|
2111
|
+
throw new SliceOffsetOutOfBoundsError({
|
|
2112
|
+
offset: end,
|
|
2113
|
+
position: "end",
|
|
2114
|
+
size: size(value)
|
|
2115
|
+
});
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
function sliceBytes(value_, start, end, { strict } = {}) {
|
|
2119
|
+
const value = value_.slice(start, end);
|
|
2120
|
+
if (strict)
|
|
2121
|
+
assertEndOffset(value, start, end);
|
|
2122
|
+
return value;
|
|
2123
|
+
}
|
|
2124
|
+
function sliceHex(value_, start, end, { strict } = {}) {
|
|
2125
|
+
const value = `0x${value_.replace("0x", "").slice(start * 2, end * 2)}`;
|
|
2126
|
+
if (strict)
|
|
2127
|
+
assertEndOffset(value, start, end);
|
|
2128
|
+
return value;
|
|
2129
|
+
}
|
|
2130
|
+
function assertTransactionEIP7702(transaction) {
|
|
2131
|
+
const { authorizationList } = transaction;
|
|
2132
|
+
if (authorizationList) {
|
|
2133
|
+
for (const authorization of authorizationList) {
|
|
2134
|
+
const { chainId } = authorization;
|
|
2135
|
+
const address = authorization.address;
|
|
2136
|
+
if (!isAddress(address))
|
|
2137
|
+
throw new InvalidAddressError({ address });
|
|
2138
|
+
if (chainId < 0)
|
|
2139
|
+
throw new InvalidChainIdError({ chainId });
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
assertTransactionEIP1559(transaction);
|
|
2143
|
+
}
|
|
2144
|
+
function assertTransactionEIP4844(transaction) {
|
|
2145
|
+
const { blobVersionedHashes } = transaction;
|
|
2146
|
+
if (blobVersionedHashes) {
|
|
2147
|
+
if (blobVersionedHashes.length === 0)
|
|
2148
|
+
throw new EmptyBlobError();
|
|
2149
|
+
for (const hash of blobVersionedHashes) {
|
|
2150
|
+
const size_ = size(hash);
|
|
2151
|
+
const version2 = hexToNumber(slice(hash, 0, 1));
|
|
2152
|
+
if (size_ !== 32)
|
|
2153
|
+
throw new InvalidVersionedHashSizeError({ hash, size: size_ });
|
|
2154
|
+
if (version2 !== versionedHashVersionKzg)
|
|
2155
|
+
throw new InvalidVersionedHashVersionError({
|
|
2156
|
+
hash,
|
|
2157
|
+
version: version2
|
|
2158
|
+
});
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
assertTransactionEIP1559(transaction);
|
|
2162
|
+
}
|
|
2163
|
+
function assertTransactionEIP1559(transaction) {
|
|
2164
|
+
const { chainId, maxPriorityFeePerGas, maxFeePerGas, to } = transaction;
|
|
2165
|
+
if (chainId <= 0)
|
|
2166
|
+
throw new InvalidChainIdError({ chainId });
|
|
2167
|
+
if (to && !isAddress(to))
|
|
2168
|
+
throw new InvalidAddressError({ address: to });
|
|
2169
|
+
if (maxFeePerGas && maxFeePerGas > maxUint256)
|
|
2170
|
+
throw new FeeCapTooHighError({ maxFeePerGas });
|
|
2171
|
+
if (maxPriorityFeePerGas && maxFeePerGas && maxPriorityFeePerGas > maxFeePerGas)
|
|
2172
|
+
throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas });
|
|
2173
|
+
}
|
|
2174
|
+
function assertTransactionEIP2930(transaction) {
|
|
2175
|
+
const { chainId, maxPriorityFeePerGas, gasPrice, maxFeePerGas, to } = transaction;
|
|
2176
|
+
if (chainId <= 0)
|
|
2177
|
+
throw new InvalidChainIdError({ chainId });
|
|
2178
|
+
if (to && !isAddress(to))
|
|
2179
|
+
throw new InvalidAddressError({ address: to });
|
|
2180
|
+
if (maxPriorityFeePerGas || maxFeePerGas)
|
|
2181
|
+
throw new BaseError("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");
|
|
2182
|
+
if (gasPrice && gasPrice > maxUint256)
|
|
2183
|
+
throw new FeeCapTooHighError({ maxFeePerGas: gasPrice });
|
|
2184
|
+
}
|
|
2185
|
+
function assertTransactionLegacy(transaction) {
|
|
2186
|
+
const { chainId, maxPriorityFeePerGas, gasPrice, maxFeePerGas, to } = transaction;
|
|
2187
|
+
if (to && !isAddress(to))
|
|
2188
|
+
throw new InvalidAddressError({ address: to });
|
|
2189
|
+
if (typeof chainId !== "undefined" && chainId <= 0)
|
|
2190
|
+
throw new InvalidChainIdError({ chainId });
|
|
2191
|
+
if (maxPriorityFeePerGas || maxFeePerGas)
|
|
2192
|
+
throw new BaseError("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");
|
|
2193
|
+
if (gasPrice && gasPrice > maxUint256)
|
|
2194
|
+
throw new FeeCapTooHighError({ maxFeePerGas: gasPrice });
|
|
2195
|
+
}
|
|
2196
|
+
function getTransactionType(transaction) {
|
|
2197
|
+
if (transaction.type)
|
|
2198
|
+
return transaction.type;
|
|
2199
|
+
if (typeof transaction.authorizationList !== "undefined")
|
|
2200
|
+
return "eip7702";
|
|
2201
|
+
if (typeof transaction.blobs !== "undefined" || typeof transaction.blobVersionedHashes !== "undefined" || typeof transaction.maxFeePerBlobGas !== "undefined" || typeof transaction.sidecars !== "undefined")
|
|
2202
|
+
return "eip4844";
|
|
2203
|
+
if (typeof transaction.maxFeePerGas !== "undefined" || typeof transaction.maxPriorityFeePerGas !== "undefined") {
|
|
2204
|
+
return "eip1559";
|
|
2205
|
+
}
|
|
2206
|
+
if (typeof transaction.gasPrice !== "undefined") {
|
|
2207
|
+
if (typeof transaction.accessList !== "undefined")
|
|
2208
|
+
return "eip2930";
|
|
2209
|
+
return "legacy";
|
|
2210
|
+
}
|
|
2211
|
+
throw new InvalidSerializableTransactionError({ transaction });
|
|
2212
|
+
}
|
|
2213
|
+
function serializeAccessList(accessList) {
|
|
2214
|
+
if (!accessList || accessList.length === 0)
|
|
2215
|
+
return [];
|
|
2216
|
+
const serializedAccessList = [];
|
|
2217
|
+
for (let i = 0; i < accessList.length; i++) {
|
|
2218
|
+
const { address, storageKeys } = accessList[i];
|
|
2219
|
+
for (let j = 0; j < storageKeys.length; j++) {
|
|
2220
|
+
if (storageKeys[j].length - 2 !== 64) {
|
|
2221
|
+
throw new InvalidStorageKeySizeError({ storageKey: storageKeys[j] });
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
if (!isAddress(address, { strict: false })) {
|
|
2225
|
+
throw new InvalidAddressError({ address });
|
|
2226
|
+
}
|
|
2227
|
+
serializedAccessList.push([address, storageKeys]);
|
|
2228
|
+
}
|
|
2229
|
+
return serializedAccessList;
|
|
2230
|
+
}
|
|
2231
|
+
function serializeTransaction$1(transaction, signature) {
|
|
2232
|
+
const type = getTransactionType(transaction);
|
|
2233
|
+
if (type === "eip1559")
|
|
2234
|
+
return serializeTransactionEIP1559(transaction, signature);
|
|
2235
|
+
if (type === "eip2930")
|
|
2236
|
+
return serializeTransactionEIP2930(transaction, signature);
|
|
2237
|
+
if (type === "eip4844")
|
|
2238
|
+
return serializeTransactionEIP4844(transaction, signature);
|
|
2239
|
+
if (type === "eip7702")
|
|
2240
|
+
return serializeTransactionEIP7702(transaction, signature);
|
|
2241
|
+
return serializeTransactionLegacy(transaction, signature);
|
|
2242
|
+
}
|
|
2243
|
+
function serializeTransactionEIP7702(transaction, signature) {
|
|
2244
|
+
const { authorizationList, chainId, gas, nonce, to, value, maxFeePerGas, maxPriorityFeePerGas, accessList, data } = transaction;
|
|
2245
|
+
assertTransactionEIP7702(transaction);
|
|
2246
|
+
const serializedAccessList = serializeAccessList(accessList);
|
|
2247
|
+
const serializedAuthorizationList = serializeAuthorizationList(authorizationList);
|
|
2248
|
+
return concatHex([
|
|
2249
|
+
"0x04",
|
|
2250
|
+
toRlp([
|
|
2251
|
+
numberToHex(chainId),
|
|
2252
|
+
nonce ? numberToHex(nonce) : "0x",
|
|
2253
|
+
maxPriorityFeePerGas ? numberToHex(maxPriorityFeePerGas) : "0x",
|
|
2254
|
+
maxFeePerGas ? numberToHex(maxFeePerGas) : "0x",
|
|
2255
|
+
gas ? numberToHex(gas) : "0x",
|
|
2256
|
+
to ?? "0x",
|
|
2257
|
+
value ? numberToHex(value) : "0x",
|
|
2258
|
+
data ?? "0x",
|
|
2259
|
+
serializedAccessList,
|
|
2260
|
+
serializedAuthorizationList,
|
|
2261
|
+
...toYParitySignatureArray(transaction, signature)
|
|
2262
|
+
])
|
|
2263
|
+
]);
|
|
2264
|
+
}
|
|
2265
|
+
function serializeTransactionEIP4844(transaction, signature) {
|
|
2266
|
+
const { chainId, gas, nonce, to, value, maxFeePerBlobGas, maxFeePerGas, maxPriorityFeePerGas, accessList, data } = transaction;
|
|
2267
|
+
assertTransactionEIP4844(transaction);
|
|
2268
|
+
let blobVersionedHashes = transaction.blobVersionedHashes;
|
|
2269
|
+
let sidecars = transaction.sidecars;
|
|
2270
|
+
if (transaction.blobs && (typeof blobVersionedHashes === "undefined" || typeof sidecars === "undefined")) {
|
|
2271
|
+
const blobs2 = typeof transaction.blobs[0] === "string" ? transaction.blobs : transaction.blobs.map((x) => bytesToHex$1(x));
|
|
2272
|
+
const kzg = transaction.kzg;
|
|
2273
|
+
const commitments2 = blobsToCommitments({
|
|
2274
|
+
blobs: blobs2,
|
|
2275
|
+
kzg
|
|
2276
|
+
});
|
|
2277
|
+
if (typeof blobVersionedHashes === "undefined")
|
|
2278
|
+
blobVersionedHashes = commitmentsToVersionedHashes({
|
|
2279
|
+
commitments: commitments2
|
|
2280
|
+
});
|
|
2281
|
+
if (typeof sidecars === "undefined") {
|
|
2282
|
+
const proofs2 = blobsToProofs({ blobs: blobs2, commitments: commitments2, kzg });
|
|
2283
|
+
sidecars = toBlobSidecars({ blobs: blobs2, commitments: commitments2, proofs: proofs2 });
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
const serializedAccessList = serializeAccessList(accessList);
|
|
2287
|
+
const serializedTransaction = [
|
|
2288
|
+
numberToHex(chainId),
|
|
2289
|
+
nonce ? numberToHex(nonce) : "0x",
|
|
2290
|
+
maxPriorityFeePerGas ? numberToHex(maxPriorityFeePerGas) : "0x",
|
|
2291
|
+
maxFeePerGas ? numberToHex(maxFeePerGas) : "0x",
|
|
2292
|
+
gas ? numberToHex(gas) : "0x",
|
|
2293
|
+
to ?? "0x",
|
|
2294
|
+
value ? numberToHex(value) : "0x",
|
|
2295
|
+
data ?? "0x",
|
|
2296
|
+
serializedAccessList,
|
|
2297
|
+
maxFeePerBlobGas ? numberToHex(maxFeePerBlobGas) : "0x",
|
|
2298
|
+
blobVersionedHashes ?? [],
|
|
2299
|
+
...toYParitySignatureArray(transaction, signature)
|
|
2300
|
+
];
|
|
2301
|
+
const blobs = [];
|
|
2302
|
+
const commitments = [];
|
|
2303
|
+
const proofs = [];
|
|
2304
|
+
if (sidecars)
|
|
2305
|
+
for (let i = 0; i < sidecars.length; i++) {
|
|
2306
|
+
const { blob, commitment, proof } = sidecars[i];
|
|
2307
|
+
blobs.push(blob);
|
|
2308
|
+
commitments.push(commitment);
|
|
2309
|
+
proofs.push(proof);
|
|
2310
|
+
}
|
|
2311
|
+
return concatHex([
|
|
2312
|
+
"0x03",
|
|
2313
|
+
sidecars ? (
|
|
2314
|
+
// If sidecars are enabled, envelope turns into a "wrapper":
|
|
2315
|
+
toRlp([serializedTransaction, blobs, commitments, proofs])
|
|
2316
|
+
) : (
|
|
2317
|
+
// If sidecars are disabled, standard envelope is used:
|
|
2318
|
+
toRlp(serializedTransaction)
|
|
2319
|
+
)
|
|
2320
|
+
]);
|
|
2321
|
+
}
|
|
2322
|
+
function serializeTransactionEIP1559(transaction, signature) {
|
|
2323
|
+
const { chainId, gas, nonce, to, value, maxFeePerGas, maxPriorityFeePerGas, accessList, data } = transaction;
|
|
2324
|
+
assertTransactionEIP1559(transaction);
|
|
2325
|
+
const serializedAccessList = serializeAccessList(accessList);
|
|
2326
|
+
const serializedTransaction = [
|
|
2327
|
+
numberToHex(chainId),
|
|
2328
|
+
nonce ? numberToHex(nonce) : "0x",
|
|
2329
|
+
maxPriorityFeePerGas ? numberToHex(maxPriorityFeePerGas) : "0x",
|
|
2330
|
+
maxFeePerGas ? numberToHex(maxFeePerGas) : "0x",
|
|
2331
|
+
gas ? numberToHex(gas) : "0x",
|
|
2332
|
+
to ?? "0x",
|
|
2333
|
+
value ? numberToHex(value) : "0x",
|
|
2334
|
+
data ?? "0x",
|
|
2335
|
+
serializedAccessList,
|
|
2336
|
+
...toYParitySignatureArray(transaction, signature)
|
|
2337
|
+
];
|
|
2338
|
+
return concatHex([
|
|
2339
|
+
"0x02",
|
|
2340
|
+
toRlp(serializedTransaction)
|
|
2341
|
+
]);
|
|
2342
|
+
}
|
|
2343
|
+
function serializeTransactionEIP2930(transaction, signature) {
|
|
2344
|
+
const { chainId, gas, data, nonce, to, value, accessList, gasPrice } = transaction;
|
|
2345
|
+
assertTransactionEIP2930(transaction);
|
|
2346
|
+
const serializedAccessList = serializeAccessList(accessList);
|
|
2347
|
+
const serializedTransaction = [
|
|
2348
|
+
numberToHex(chainId),
|
|
2349
|
+
nonce ? numberToHex(nonce) : "0x",
|
|
2350
|
+
gasPrice ? numberToHex(gasPrice) : "0x",
|
|
2351
|
+
gas ? numberToHex(gas) : "0x",
|
|
2352
|
+
to ?? "0x",
|
|
2353
|
+
value ? numberToHex(value) : "0x",
|
|
2354
|
+
data ?? "0x",
|
|
2355
|
+
serializedAccessList,
|
|
2356
|
+
...toYParitySignatureArray(transaction, signature)
|
|
2357
|
+
];
|
|
2358
|
+
return concatHex([
|
|
2359
|
+
"0x01",
|
|
2360
|
+
toRlp(serializedTransaction)
|
|
2361
|
+
]);
|
|
2362
|
+
}
|
|
2363
|
+
function serializeTransactionLegacy(transaction, signature) {
|
|
2364
|
+
const { chainId = 0, gas, data, nonce, to, value, gasPrice } = transaction;
|
|
2365
|
+
assertTransactionLegacy(transaction);
|
|
2366
|
+
let serializedTransaction = [
|
|
2367
|
+
nonce ? numberToHex(nonce) : "0x",
|
|
2368
|
+
gasPrice ? numberToHex(gasPrice) : "0x",
|
|
2369
|
+
gas ? numberToHex(gas) : "0x",
|
|
2370
|
+
to ?? "0x",
|
|
2371
|
+
value ? numberToHex(value) : "0x",
|
|
2372
|
+
data ?? "0x"
|
|
2373
|
+
];
|
|
2374
|
+
if (signature) {
|
|
2375
|
+
const v = (() => {
|
|
2376
|
+
if (signature.v >= 35n) {
|
|
2377
|
+
const inferredChainId = (signature.v - 35n) / 2n;
|
|
2378
|
+
if (inferredChainId > 0)
|
|
2379
|
+
return signature.v;
|
|
2380
|
+
return 27n + (signature.v === 35n ? 0n : 1n);
|
|
2381
|
+
}
|
|
2382
|
+
if (chainId > 0)
|
|
2383
|
+
return BigInt(chainId * 2) + BigInt(35n + signature.v - 27n);
|
|
2384
|
+
const v2 = 27n + (signature.v === 27n ? 0n : 1n);
|
|
2385
|
+
if (signature.v !== v2)
|
|
2386
|
+
throw new InvalidLegacyVError({ v: signature.v });
|
|
2387
|
+
return v2;
|
|
2388
|
+
})();
|
|
2389
|
+
const r = trim(signature.r);
|
|
2390
|
+
const s = trim(signature.s);
|
|
2391
|
+
serializedTransaction = [
|
|
2392
|
+
...serializedTransaction,
|
|
2393
|
+
numberToHex(v),
|
|
2394
|
+
r === "0x00" ? "0x" : r,
|
|
2395
|
+
s === "0x00" ? "0x" : s
|
|
2396
|
+
];
|
|
2397
|
+
} else if (chainId > 0) {
|
|
2398
|
+
serializedTransaction = [
|
|
2399
|
+
...serializedTransaction,
|
|
2400
|
+
numberToHex(chainId),
|
|
2401
|
+
"0x",
|
|
2402
|
+
"0x"
|
|
2403
|
+
];
|
|
2404
|
+
}
|
|
2405
|
+
return toRlp(serializedTransaction);
|
|
2406
|
+
}
|
|
2407
|
+
function toYParitySignatureArray(transaction, signature_) {
|
|
2408
|
+
const signature = signature_ ?? transaction;
|
|
2409
|
+
const { v, yParity } = signature;
|
|
2410
|
+
if (typeof signature.r === "undefined")
|
|
2411
|
+
return [];
|
|
2412
|
+
if (typeof signature.s === "undefined")
|
|
2413
|
+
return [];
|
|
2414
|
+
if (typeof v === "undefined" && typeof yParity === "undefined")
|
|
2415
|
+
return [];
|
|
2416
|
+
const r = trim(signature.r);
|
|
2417
|
+
const s = trim(signature.s);
|
|
2418
|
+
const yParity_ = (() => {
|
|
2419
|
+
if (typeof yParity === "number")
|
|
2420
|
+
return yParity ? numberToHex(1) : "0x";
|
|
2421
|
+
if (v === 0n)
|
|
2422
|
+
return "0x";
|
|
2423
|
+
if (v === 1n)
|
|
2424
|
+
return numberToHex(1);
|
|
2425
|
+
return v === 27n ? "0x" : numberToHex(1);
|
|
2426
|
+
})();
|
|
2427
|
+
return [yParity_, r === "0x00" ? "0x" : r, s === "0x00" ? "0x" : s];
|
|
2428
|
+
}
|
|
2429
|
+
const contracts = {
|
|
2430
|
+
gasPriceOracle: { address: "0x420000000000000000000000000000000000000F" },
|
|
2431
|
+
l1Block: { address: "0x4200000000000000000000000000000000000015" },
|
|
2432
|
+
l2CrossDomainMessenger: {
|
|
2433
|
+
address: "0x4200000000000000000000000000000000000007"
|
|
2434
|
+
},
|
|
2435
|
+
l2Erc721Bridge: { address: "0x4200000000000000000000000000000000000014" },
|
|
2436
|
+
l2StandardBridge: { address: "0x4200000000000000000000000000000000000010" },
|
|
2437
|
+
l2ToL1MessagePasser: {
|
|
2438
|
+
address: "0x4200000000000000000000000000000000000016"
|
|
2439
|
+
}
|
|
2440
|
+
};
|
|
2441
|
+
const formatters = {
|
|
2442
|
+
block: /* @__PURE__ */ defineBlock({
|
|
2443
|
+
format(args) {
|
|
2444
|
+
var _a;
|
|
2445
|
+
const transactions = (_a = args.transactions) == null ? void 0 : _a.map((transaction) => {
|
|
2446
|
+
if (typeof transaction === "string")
|
|
2447
|
+
return transaction;
|
|
2448
|
+
const formatted = formatTransaction(transaction);
|
|
2449
|
+
if (formatted.typeHex === "0x7e") {
|
|
2450
|
+
formatted.isSystemTx = transaction.isSystemTx;
|
|
2451
|
+
formatted.mint = transaction.mint ? hexToBigInt(transaction.mint) : void 0;
|
|
2452
|
+
formatted.sourceHash = transaction.sourceHash;
|
|
2453
|
+
formatted.type = "deposit";
|
|
2454
|
+
}
|
|
2455
|
+
return formatted;
|
|
2456
|
+
});
|
|
2457
|
+
return {
|
|
2458
|
+
transactions,
|
|
2459
|
+
stateRoot: args.stateRoot
|
|
2460
|
+
};
|
|
2461
|
+
}
|
|
2462
|
+
}),
|
|
2463
|
+
transaction: /* @__PURE__ */ defineTransaction({
|
|
2464
|
+
format(args) {
|
|
2465
|
+
const transaction = {};
|
|
2466
|
+
if (args.type === "0x7e") {
|
|
2467
|
+
transaction.isSystemTx = args.isSystemTx;
|
|
2468
|
+
transaction.mint = args.mint ? hexToBigInt(args.mint) : void 0;
|
|
2469
|
+
transaction.sourceHash = args.sourceHash;
|
|
2470
|
+
transaction.type = "deposit";
|
|
2471
|
+
}
|
|
2472
|
+
return transaction;
|
|
2473
|
+
}
|
|
2474
|
+
}),
|
|
2475
|
+
transactionReceipt: /* @__PURE__ */ defineTransactionReceipt({
|
|
2476
|
+
format(args) {
|
|
2477
|
+
return {
|
|
2478
|
+
l1GasPrice: args.l1GasPrice ? hexToBigInt(args.l1GasPrice) : null,
|
|
2479
|
+
l1GasUsed: args.l1GasUsed ? hexToBigInt(args.l1GasUsed) : null,
|
|
2480
|
+
l1Fee: args.l1Fee ? hexToBigInt(args.l1Fee) : null,
|
|
2481
|
+
l1FeeScalar: args.l1FeeScalar ? Number(args.l1FeeScalar) : null
|
|
2482
|
+
};
|
|
2483
|
+
}
|
|
2484
|
+
})
|
|
2485
|
+
};
|
|
2486
|
+
function serializeTransaction(transaction, signature) {
|
|
2487
|
+
if (isDeposit(transaction))
|
|
2488
|
+
return serializeTransactionDeposit(transaction);
|
|
2489
|
+
return serializeTransaction$1(transaction, signature);
|
|
2490
|
+
}
|
|
2491
|
+
const serializers = {
|
|
2492
|
+
transaction: serializeTransaction
|
|
2493
|
+
};
|
|
2494
|
+
function serializeTransactionDeposit(transaction) {
|
|
2495
|
+
assertTransactionDeposit(transaction);
|
|
2496
|
+
const { sourceHash, data, from, gas, isSystemTx, mint, to, value } = transaction;
|
|
2497
|
+
const serializedTransaction = [
|
|
2498
|
+
sourceHash,
|
|
2499
|
+
from,
|
|
2500
|
+
to ?? "0x",
|
|
2501
|
+
mint ? toHex(mint) : "0x",
|
|
2502
|
+
value ? toHex(value) : "0x",
|
|
2503
|
+
gas ? toHex(gas) : "0x",
|
|
2504
|
+
isSystemTx ? "0x1" : "0x",
|
|
2505
|
+
data ?? "0x"
|
|
2506
|
+
];
|
|
2507
|
+
return concatHex([
|
|
2508
|
+
"0x7e",
|
|
2509
|
+
toRlp(serializedTransaction)
|
|
2510
|
+
]);
|
|
2511
|
+
}
|
|
2512
|
+
function isDeposit(transaction) {
|
|
2513
|
+
if (transaction.type === "deposit")
|
|
2514
|
+
return true;
|
|
2515
|
+
if (typeof transaction.sourceHash !== "undefined")
|
|
2516
|
+
return true;
|
|
2517
|
+
return false;
|
|
2518
|
+
}
|
|
2519
|
+
function assertTransactionDeposit(transaction) {
|
|
2520
|
+
const { from, to } = transaction;
|
|
2521
|
+
if (from && !isAddress(from))
|
|
2522
|
+
throw new InvalidAddressError({ address: from });
|
|
2523
|
+
if (to && !isAddress(to))
|
|
2524
|
+
throw new InvalidAddressError({ address: to });
|
|
2525
|
+
}
|
|
2526
|
+
const chainConfig = {
|
|
2527
|
+
blockTime: 2e3,
|
|
2528
|
+
contracts,
|
|
2529
|
+
formatters,
|
|
2530
|
+
serializers
|
|
2531
|
+
};
|
|
2532
|
+
const arbitrum = /* @__PURE__ */ defineChain({
|
|
2533
|
+
id: 42161,
|
|
2534
|
+
name: "Arbitrum One",
|
|
2535
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
2536
|
+
blockTime: 250,
|
|
2537
|
+
rpcUrls: {
|
|
2538
|
+
default: {
|
|
2539
|
+
http: ["https://arb1.arbitrum.io/rpc"]
|
|
2540
|
+
}
|
|
2541
|
+
},
|
|
2542
|
+
blockExplorers: {
|
|
2543
|
+
default: {
|
|
2544
|
+
name: "Arbiscan",
|
|
2545
|
+
url: "https://arbiscan.io",
|
|
2546
|
+
apiUrl: "https://api.arbiscan.io/api"
|
|
2547
|
+
}
|
|
2548
|
+
},
|
|
2549
|
+
contracts: {
|
|
2550
|
+
multicall3: {
|
|
2551
|
+
address: "0xca11bde05977b3631167028862be2a173976ca11",
|
|
2552
|
+
blockCreated: 7654707
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
});
|
|
2556
|
+
const avalanche = /* @__PURE__ */ defineChain({
|
|
2557
|
+
id: 43114,
|
|
2558
|
+
name: "Avalanche",
|
|
2559
|
+
blockTime: 1700,
|
|
2560
|
+
nativeCurrency: {
|
|
2561
|
+
decimals: 18,
|
|
2562
|
+
name: "Avalanche",
|
|
2563
|
+
symbol: "AVAX"
|
|
2564
|
+
},
|
|
2565
|
+
rpcUrls: {
|
|
2566
|
+
default: { http: ["https://api.avax.network/ext/bc/C/rpc"] }
|
|
2567
|
+
},
|
|
2568
|
+
blockExplorers: {
|
|
2569
|
+
default: {
|
|
2570
|
+
name: "SnowTrace",
|
|
2571
|
+
url: "https://snowtrace.io",
|
|
2572
|
+
apiUrl: "https://api.snowtrace.io"
|
|
2573
|
+
}
|
|
2574
|
+
},
|
|
2575
|
+
contracts: {
|
|
2576
|
+
multicall3: {
|
|
2577
|
+
address: "0xca11bde05977b3631167028862be2a173976ca11",
|
|
2578
|
+
blockCreated: 11907934
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
});
|
|
2582
|
+
const bsc = /* @__PURE__ */ defineChain({
|
|
2583
|
+
id: 56,
|
|
2584
|
+
name: "BNB Smart Chain",
|
|
2585
|
+
blockTime: 750,
|
|
2586
|
+
nativeCurrency: {
|
|
2587
|
+
decimals: 18,
|
|
2588
|
+
name: "BNB",
|
|
2589
|
+
symbol: "BNB"
|
|
2590
|
+
},
|
|
2591
|
+
rpcUrls: {
|
|
2592
|
+
default: { http: ["https://56.rpc.thirdweb.com"] }
|
|
2593
|
+
},
|
|
2594
|
+
blockExplorers: {
|
|
2595
|
+
default: {
|
|
2596
|
+
name: "BscScan",
|
|
2597
|
+
url: "https://bscscan.com",
|
|
2598
|
+
apiUrl: "https://api.bscscan.com/api"
|
|
2599
|
+
}
|
|
2600
|
+
},
|
|
2601
|
+
contracts: {
|
|
2602
|
+
multicall3: {
|
|
2603
|
+
address: "0xca11bde05977b3631167028862be2a173976ca11",
|
|
2604
|
+
blockCreated: 15921452
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
});
|
|
2608
|
+
const mainnet = /* @__PURE__ */ defineChain({
|
|
2609
|
+
id: 1,
|
|
2610
|
+
name: "Ethereum",
|
|
2611
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
2612
|
+
blockTime: 12e3,
|
|
2613
|
+
rpcUrls: {
|
|
2614
|
+
default: {
|
|
2615
|
+
http: ["https://eth.merkle.io"]
|
|
2616
|
+
}
|
|
2617
|
+
},
|
|
2618
|
+
blockExplorers: {
|
|
2619
|
+
default: {
|
|
2620
|
+
name: "Etherscan",
|
|
2621
|
+
url: "https://etherscan.io",
|
|
2622
|
+
apiUrl: "https://api.etherscan.io/api"
|
|
2623
|
+
}
|
|
2624
|
+
},
|
|
2625
|
+
contracts: {
|
|
2626
|
+
ensUniversalResolver: {
|
|
2627
|
+
address: "0xeeeeeeee14d718c2b47d9923deab1335e144eeee",
|
|
2628
|
+
blockCreated: 23085558
|
|
2629
|
+
},
|
|
2630
|
+
multicall3: {
|
|
2631
|
+
address: "0xca11bde05977b3631167028862be2a173976ca11",
|
|
2632
|
+
blockCreated: 14353601
|
|
2633
|
+
}
|
|
2634
|
+
}
|
|
2635
|
+
});
|
|
2636
|
+
const sourceId = 1;
|
|
2637
|
+
const optimism = /* @__PURE__ */ defineChain({
|
|
2638
|
+
...chainConfig,
|
|
2639
|
+
id: 10,
|
|
2640
|
+
name: "OP Mainnet",
|
|
2641
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
2642
|
+
rpcUrls: {
|
|
2643
|
+
default: {
|
|
2644
|
+
http: ["https://mainnet.optimism.io"]
|
|
2645
|
+
}
|
|
2646
|
+
},
|
|
2647
|
+
blockExplorers: {
|
|
2648
|
+
default: {
|
|
2649
|
+
name: "Optimism Explorer",
|
|
2650
|
+
url: "https://optimistic.etherscan.io",
|
|
2651
|
+
apiUrl: "https://api-optimistic.etherscan.io/api"
|
|
2652
|
+
}
|
|
2653
|
+
},
|
|
2654
|
+
contracts: {
|
|
2655
|
+
...chainConfig.contracts,
|
|
2656
|
+
disputeGameFactory: {
|
|
2657
|
+
[sourceId]: {
|
|
2658
|
+
address: "0xe5965Ab5962eDc7477C8520243A95517CD252fA9"
|
|
2659
|
+
}
|
|
2660
|
+
},
|
|
2661
|
+
l2OutputOracle: {
|
|
2662
|
+
[sourceId]: {
|
|
2663
|
+
address: "0xdfe97868233d1aa22e815a266982f2cf17685a27"
|
|
2664
|
+
}
|
|
2665
|
+
},
|
|
2666
|
+
multicall3: {
|
|
2667
|
+
address: "0xca11bde05977b3631167028862be2a173976ca11",
|
|
2668
|
+
blockCreated: 4286263
|
|
2669
|
+
},
|
|
2670
|
+
portal: {
|
|
2671
|
+
[sourceId]: {
|
|
2672
|
+
address: "0xbEb5Fc579115071764c7423A4f12eDde41f106Ed"
|
|
2673
|
+
}
|
|
2674
|
+
},
|
|
2675
|
+
l1StandardBridge: {
|
|
2676
|
+
[sourceId]: {
|
|
2677
|
+
address: "0x99C9fc46f92E8a1c0deC1b1747d010903E884bE1"
|
|
2678
|
+
}
|
|
2679
|
+
}
|
|
2680
|
+
},
|
|
2681
|
+
sourceId
|
|
2682
|
+
});
|
|
2683
|
+
const polygon = /* @__PURE__ */ defineChain({
|
|
2684
|
+
id: 137,
|
|
2685
|
+
name: "Polygon",
|
|
2686
|
+
blockTime: 2e3,
|
|
2687
|
+
nativeCurrency: { name: "POL", symbol: "POL", decimals: 18 },
|
|
2688
|
+
rpcUrls: {
|
|
2689
|
+
default: {
|
|
2690
|
+
http: ["https://polygon-rpc.com"]
|
|
2691
|
+
}
|
|
2692
|
+
},
|
|
2693
|
+
blockExplorers: {
|
|
2694
|
+
default: {
|
|
2695
|
+
name: "PolygonScan",
|
|
2696
|
+
url: "https://polygonscan.com",
|
|
2697
|
+
apiUrl: "https://api.etherscan.io/v2/api"
|
|
2698
|
+
}
|
|
2699
|
+
},
|
|
2700
|
+
contracts: {
|
|
2701
|
+
multicall3: {
|
|
2702
|
+
address: "0xca11bde05977b3631167028862be2a173976ca11",
|
|
2703
|
+
blockCreated: 25770160
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
});
|
|
2707
|
+
export {
|
|
2708
|
+
Hash as $,
|
|
2709
|
+
sha256 as A,
|
|
2710
|
+
BaseError as B,
|
|
2711
|
+
pad as C,
|
|
2712
|
+
defineChain as D,
|
|
2713
|
+
chainConfig as E,
|
|
2714
|
+
trim as F,
|
|
2715
|
+
formatTransaction as G,
|
|
2716
|
+
serializeTransaction as H,
|
|
2717
|
+
InvalidChainIdError as I,
|
|
2718
|
+
serializeAccessList as J,
|
|
2719
|
+
toYParitySignatureArray as K,
|
|
2720
|
+
FeeCapTooHighError as L,
|
|
2721
|
+
maxUint256 as M,
|
|
2722
|
+
contracts as N,
|
|
2723
|
+
prettyPrint as O,
|
|
2724
|
+
formatGwei as P,
|
|
2725
|
+
ExecutionRevertedError as Q,
|
|
2726
|
+
FeeCapTooLowError as R,
|
|
2727
|
+
NonceTooHighError as S,
|
|
2728
|
+
TipAboveFeeCapError as T,
|
|
2729
|
+
NonceTooLowError as U,
|
|
2730
|
+
NonceMaxValueError as V,
|
|
2731
|
+
InsufficientFundsError as W,
|
|
2732
|
+
IntrinsicGasTooHighError as X,
|
|
2733
|
+
IntrinsicGasTooLowError as Y,
|
|
2734
|
+
TransactionTypeNotSupportedError as Z,
|
|
2735
|
+
UnknownNodeError as _,
|
|
2736
|
+
avalanche as a,
|
|
2737
|
+
ahash as a0,
|
|
2738
|
+
toBytes as a1,
|
|
2739
|
+
clean as a2,
|
|
2740
|
+
aexists as a3,
|
|
2741
|
+
abytes as a4,
|
|
2742
|
+
bytesToHex as a5,
|
|
2743
|
+
hexToBytes as a6,
|
|
2744
|
+
isBytes as a7,
|
|
2745
|
+
concatBytes as a8,
|
|
2746
|
+
anumber as a9,
|
|
2747
|
+
randomBytes as aa,
|
|
2748
|
+
sha512 as ab,
|
|
2749
|
+
sha256$2 as ac,
|
|
2750
|
+
sha256$1 as ad,
|
|
2751
|
+
keccak_256 as ae,
|
|
2752
|
+
arbitrum as b,
|
|
2753
|
+
bsc as c,
|
|
2754
|
+
defineFormatter as d,
|
|
2755
|
+
bytesToHex$1 as e,
|
|
2756
|
+
maxUint16 as f,
|
|
2757
|
+
defineTransactionReceipt as g,
|
|
2758
|
+
hexToBytes$1 as h,
|
|
2759
|
+
hexToBigInt as i,
|
|
2760
|
+
hexToNumber as j,
|
|
2761
|
+
formatLog as k,
|
|
2762
|
+
defineTransaction as l,
|
|
2763
|
+
mainnet as m,
|
|
2764
|
+
numberToHex as n,
|
|
2765
|
+
optimism as o,
|
|
2766
|
+
polygon as p,
|
|
2767
|
+
defineBlock as q,
|
|
2768
|
+
formatUnits as r,
|
|
2769
|
+
etherUnits as s,
|
|
2770
|
+
toHex as t,
|
|
2771
|
+
isAddress as u,
|
|
2772
|
+
InvalidAddressError as v,
|
|
2773
|
+
serializeTransaction$1 as w,
|
|
2774
|
+
concatHex as x,
|
|
2775
|
+
toRlp as y,
|
|
2776
|
+
toBytes$1 as z
|
|
2777
|
+
};
|
|
2778
|
+
//# sourceMappingURL=polygon-C-1Q5KDX.js.map
|