@arp-protocol/cli 0.0.0-stage → 0.0.3

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.
@@ -0,0 +1,1033 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ BaseError,
4
+ BytesSizeMismatchError,
5
+ FeeCapTooHighError,
6
+ InvalidAddressError,
7
+ InvalidChainIdError,
8
+ InvalidLegacyVError,
9
+ InvalidSerializableTransactionError,
10
+ InvalidStorageKeySizeError,
11
+ TipAboveFeeCapError,
12
+ bytesRegex,
13
+ bytesToHex,
14
+ checksumAddress,
15
+ concat,
16
+ concatHex,
17
+ createCursor,
18
+ encodeAbiParameters,
19
+ hexToBigInt,
20
+ hexToBytes,
21
+ hexToNumber,
22
+ integerRegex,
23
+ isAddress,
24
+ isHex,
25
+ keccak256,
26
+ maxUint256,
27
+ numberToHex,
28
+ size,
29
+ slice,
30
+ stringToHex,
31
+ stringify,
32
+ toBytes,
33
+ toHex,
34
+ trim
35
+ } from "./cli-mhzh9z8k.js";
36
+ import {
37
+ secp256k1,
38
+ sha256
39
+ } from "./cli-d3dy7cxe.js";
40
+
41
+ // ../../packages/protocol/dist/identifiers.js
42
+ var DECIMAL = /^(0|[1-9][0-9]*)$/;
43
+ var ERC8004_REGISTRY = /^eip155:([1-9][0-9]*):(0x[0-9a-fA-F]{40})$/;
44
+ var CAIP19_ERC721 = /^eip155:([1-9][0-9]*)\/erc721:(0x[0-9a-fA-F]{40})\/(0|[1-9][0-9]*)$/;
45
+
46
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/accounts/generatePrivateKey.js
47
+ function generatePrivateKey() {
48
+ return toHex(secp256k1.utils.randomPrivateKey());
49
+ }
50
+
51
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/accounts/utils/publicKeyToAddress.js
52
+ function publicKeyToAddress(publicKey) {
53
+ const address = keccak256(`0x${publicKey.substring(4)}`).substring(26);
54
+ return checksumAddress(`0x${address}`);
55
+ }
56
+
57
+ // ../../node_modules/.bun/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/sha256.js
58
+ var sha2562 = sha256;
59
+
60
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/utils/hash/sha256.js
61
+ function sha2563(value, to_) {
62
+ const to = to_ || "hex";
63
+ const bytes = sha2562(isHex(value, { strict: false }) ? toBytes(value) : value);
64
+ if (to === "bytes")
65
+ return bytes;
66
+ return toHex(bytes);
67
+ }
68
+
69
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/accounts/toAccount.js
70
+ function toAccount(source) {
71
+ if (typeof source === "string") {
72
+ if (!isAddress(source, { strict: false }))
73
+ throw new InvalidAddressError({ address: source });
74
+ return {
75
+ address: source,
76
+ type: "json-rpc"
77
+ };
78
+ }
79
+ if (!isAddress(source.address, { strict: false }))
80
+ throw new InvalidAddressError({ address: source.address });
81
+ return {
82
+ address: source.address,
83
+ nonceManager: source.nonceManager,
84
+ sign: source.sign,
85
+ signAuthorization: source.signAuthorization,
86
+ signMessage: source.signMessage,
87
+ signTransaction: source.signTransaction,
88
+ signTypedData: source.signTypedData,
89
+ source: "custom",
90
+ type: "local"
91
+ };
92
+ }
93
+
94
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/utils/signature/serializeSignature.js
95
+ function serializeSignature({ r, s, to = "hex", v, yParity }) {
96
+ const yParity_ = (() => {
97
+ if (yParity === 0 || yParity === 1)
98
+ return yParity;
99
+ if (v && (v === 27n || v === 28n || v >= 35n))
100
+ return v % 2n === 0n ? 1 : 0;
101
+ throw new Error("Invalid `v` or `yParity` value");
102
+ })();
103
+ const signature = `0x${new secp256k1.Signature(hexToBigInt(r), hexToBigInt(s)).toCompactHex()}${yParity_ === 0 ? "1b" : "1c"}`;
104
+ if (to === "hex")
105
+ return signature;
106
+ return hexToBytes(signature);
107
+ }
108
+
109
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/accounts/utils/sign.js
110
+ var extraEntropy = false;
111
+ async function sign({ hash, privateKey, to = "object" }) {
112
+ const { r, s, recovery } = secp256k1.sign(hash.slice(2), privateKey.slice(2), {
113
+ lowS: true,
114
+ extraEntropy: isHex(extraEntropy, { strict: false }) ? hexToBytes(extraEntropy) : extraEntropy
115
+ });
116
+ const signature = {
117
+ r: numberToHex(r, { size: 32 }),
118
+ s: numberToHex(s, { size: 32 }),
119
+ v: recovery ? 28n : 27n,
120
+ yParity: recovery
121
+ };
122
+ return (() => {
123
+ if (to === "bytes" || to === "hex")
124
+ return serializeSignature({ ...signature, to });
125
+ return signature;
126
+ })();
127
+ }
128
+
129
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/utils/encoding/toRlp.js
130
+ function toRlp(bytes, to = "hex") {
131
+ const encodable = getEncodable(bytes);
132
+ const cursor = createCursor(new Uint8Array(encodable.length));
133
+ encodable.encode(cursor);
134
+ if (to === "hex")
135
+ return bytesToHex(cursor.bytes);
136
+ return cursor.bytes;
137
+ }
138
+ function getEncodable(bytes) {
139
+ if (Array.isArray(bytes))
140
+ return getEncodableList(bytes.map((x) => getEncodable(x)));
141
+ return getEncodableBytes(bytes);
142
+ }
143
+ function getEncodableList(list) {
144
+ const bodyLength = list.reduce((acc, x) => acc + x.length, 0);
145
+ const sizeOfBodyLength = getSizeOfLength(bodyLength);
146
+ const length = (() => {
147
+ if (bodyLength <= 55)
148
+ return 1 + bodyLength;
149
+ return 1 + sizeOfBodyLength + bodyLength;
150
+ })();
151
+ return {
152
+ length,
153
+ encode(cursor) {
154
+ if (bodyLength <= 55) {
155
+ cursor.pushByte(192 + bodyLength);
156
+ } else {
157
+ cursor.pushByte(192 + 55 + sizeOfBodyLength);
158
+ if (sizeOfBodyLength === 1)
159
+ cursor.pushUint8(bodyLength);
160
+ else if (sizeOfBodyLength === 2)
161
+ cursor.pushUint16(bodyLength);
162
+ else if (sizeOfBodyLength === 3)
163
+ cursor.pushUint24(bodyLength);
164
+ else
165
+ cursor.pushUint32(bodyLength);
166
+ }
167
+ for (const { encode } of list) {
168
+ encode(cursor);
169
+ }
170
+ }
171
+ };
172
+ }
173
+ function getEncodableBytes(bytesOrHex) {
174
+ const bytes = typeof bytesOrHex === "string" ? hexToBytes(bytesOrHex) : bytesOrHex;
175
+ const sizeOfBytesLength = getSizeOfLength(bytes.length);
176
+ const length = (() => {
177
+ if (bytes.length === 1 && bytes[0] < 128)
178
+ return 1;
179
+ if (bytes.length <= 55)
180
+ return 1 + bytes.length;
181
+ return 1 + sizeOfBytesLength + bytes.length;
182
+ })();
183
+ return {
184
+ length,
185
+ encode(cursor) {
186
+ if (bytes.length === 1 && bytes[0] < 128) {
187
+ cursor.pushBytes(bytes);
188
+ } else if (bytes.length <= 55) {
189
+ cursor.pushByte(128 + bytes.length);
190
+ cursor.pushBytes(bytes);
191
+ } else {
192
+ cursor.pushByte(128 + 55 + sizeOfBytesLength);
193
+ if (sizeOfBytesLength === 1)
194
+ cursor.pushUint8(bytes.length);
195
+ else if (sizeOfBytesLength === 2)
196
+ cursor.pushUint16(bytes.length);
197
+ else if (sizeOfBytesLength === 3)
198
+ cursor.pushUint24(bytes.length);
199
+ else
200
+ cursor.pushUint32(bytes.length);
201
+ cursor.pushBytes(bytes);
202
+ }
203
+ }
204
+ };
205
+ }
206
+ function getSizeOfLength(length) {
207
+ if (length < 2 ** 8)
208
+ return 1;
209
+ if (length < 2 ** 16)
210
+ return 2;
211
+ if (length < 2 ** 24)
212
+ return 3;
213
+ if (length < 2 ** 32)
214
+ return 4;
215
+ throw new BaseError("Length is too large.");
216
+ }
217
+
218
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/utils/authorization/hashAuthorization.js
219
+ function hashAuthorization(parameters) {
220
+ const { chainId, nonce, to } = parameters;
221
+ const address = parameters.contractAddress ?? parameters.address;
222
+ const hash = keccak256(concatHex([
223
+ "0x05",
224
+ toRlp([
225
+ chainId ? numberToHex(chainId) : "0x",
226
+ address,
227
+ nonce ? numberToHex(nonce) : "0x"
228
+ ])
229
+ ]));
230
+ if (to === "bytes")
231
+ return hexToBytes(hash);
232
+ return hash;
233
+ }
234
+
235
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/accounts/utils/signAuthorization.js
236
+ async function signAuthorization(parameters) {
237
+ const { chainId, nonce, privateKey, to = "object" } = parameters;
238
+ const address = parameters.contractAddress ?? parameters.address;
239
+ const signature = await sign({
240
+ hash: hashAuthorization({ address, chainId, nonce }),
241
+ privateKey,
242
+ to
243
+ });
244
+ if (to === "object")
245
+ return {
246
+ address,
247
+ chainId,
248
+ nonce,
249
+ ...signature
250
+ };
251
+ return signature;
252
+ }
253
+
254
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/constants/strings.js
255
+ var presignMessagePrefix = `\x19Ethereum Signed Message:
256
+ `;
257
+
258
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/utils/signature/toPrefixedMessage.js
259
+ function toPrefixedMessage(message_) {
260
+ const message = (() => {
261
+ if (typeof message_ === "string")
262
+ return stringToHex(message_);
263
+ if (typeof message_.raw === "string")
264
+ return message_.raw;
265
+ return bytesToHex(message_.raw);
266
+ })();
267
+ const prefix = stringToHex(`${presignMessagePrefix}${size(message)}`);
268
+ return concat([prefix, message]);
269
+ }
270
+
271
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/utils/signature/hashMessage.js
272
+ function hashMessage(message, to_) {
273
+ return keccak256(toPrefixedMessage(message), to_);
274
+ }
275
+
276
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/accounts/utils/signMessage.js
277
+ async function signMessage({ message, privateKey }) {
278
+ return await sign({ hash: hashMessage(message), privateKey, to: "hex" });
279
+ }
280
+
281
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/utils/authorization/serializeAuthorizationList.js
282
+ function serializeAuthorizationList(authorizationList) {
283
+ if (!authorizationList || authorizationList.length === 0)
284
+ return [];
285
+ const serializedAuthorizationList = [];
286
+ for (const authorization of authorizationList) {
287
+ const { chainId, nonce, ...signature } = authorization;
288
+ const contractAddress = authorization.address;
289
+ serializedAuthorizationList.push([
290
+ chainId ? toHex(chainId) : "0x",
291
+ contractAddress,
292
+ nonce ? toHex(nonce) : "0x",
293
+ ...toYParitySignatureArray({}, signature)
294
+ ]);
295
+ }
296
+ return serializedAuthorizationList;
297
+ }
298
+
299
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/utils/blob/blobsToCommitments.js
300
+ function blobsToCommitments(parameters) {
301
+ const { kzg } = parameters;
302
+ const to = parameters.to ?? (typeof parameters.blobs[0] === "string" ? "hex" : "bytes");
303
+ const blobs = typeof parameters.blobs[0] === "string" ? parameters.blobs.map((x) => hexToBytes(x)) : parameters.blobs;
304
+ const commitments = [];
305
+ for (const blob of blobs)
306
+ commitments.push(Uint8Array.from(kzg.blobToKzgCommitment(blob)));
307
+ return to === "bytes" ? commitments : commitments.map((x) => bytesToHex(x));
308
+ }
309
+
310
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/utils/blob/blobsToProofs.js
311
+ function blobsToProofs(parameters) {
312
+ const { kzg } = parameters;
313
+ const to = parameters.to ?? (typeof parameters.blobs[0] === "string" ? "hex" : "bytes");
314
+ const blobs = typeof parameters.blobs[0] === "string" ? parameters.blobs.map((x) => hexToBytes(x)) : parameters.blobs;
315
+ const commitments = typeof parameters.commitments[0] === "string" ? parameters.commitments.map((x) => hexToBytes(x)) : parameters.commitments;
316
+ const proofs = [];
317
+ for (let i = 0;i < blobs.length; i++) {
318
+ const blob = blobs[i];
319
+ const commitment = commitments[i];
320
+ proofs.push(Uint8Array.from(kzg.computeBlobKzgProof(blob, commitment)));
321
+ }
322
+ return to === "bytes" ? proofs : proofs.map((x) => bytesToHex(x));
323
+ }
324
+
325
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/utils/blob/commitmentToVersionedHash.js
326
+ function commitmentToVersionedHash(parameters) {
327
+ const { commitment, version = 1 } = parameters;
328
+ const to = parameters.to ?? (typeof commitment === "string" ? "hex" : "bytes");
329
+ const versionedHash = sha2563(commitment, "bytes");
330
+ versionedHash.set([version], 0);
331
+ return to === "bytes" ? versionedHash : bytesToHex(versionedHash);
332
+ }
333
+
334
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/utils/blob/commitmentsToVersionedHashes.js
335
+ function commitmentsToVersionedHashes(parameters) {
336
+ const { commitments, version } = parameters;
337
+ const to = parameters.to ?? (typeof commitments[0] === "string" ? "hex" : "bytes");
338
+ const hashes = [];
339
+ for (const commitment of commitments) {
340
+ hashes.push(commitmentToVersionedHash({
341
+ commitment,
342
+ to,
343
+ version
344
+ }));
345
+ }
346
+ return hashes;
347
+ }
348
+
349
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/constants/blob.js
350
+ var blobsPerTransaction = 6;
351
+ var bytesPerFieldElement = 32;
352
+ var fieldElementsPerBlob = 4096;
353
+ var bytesPerBlob = bytesPerFieldElement * fieldElementsPerBlob;
354
+ var maxBytesPerTransaction = bytesPerBlob * blobsPerTransaction - 1 - 1 * fieldElementsPerBlob * blobsPerTransaction;
355
+
356
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/constants/kzg.js
357
+ var versionedHashVersionKzg = 1;
358
+
359
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/errors/blob.js
360
+ class BlobSizeTooLargeError extends BaseError {
361
+ constructor({ maxSize, size: size2 }) {
362
+ super("Blob size is too large.", {
363
+ metaMessages: [`Max: ${maxSize} bytes`, `Given: ${size2} bytes`],
364
+ name: "BlobSizeTooLargeError"
365
+ });
366
+ }
367
+ }
368
+
369
+ class EmptyBlobError extends BaseError {
370
+ constructor() {
371
+ super("Blob data must not be empty.", { name: "EmptyBlobError" });
372
+ }
373
+ }
374
+
375
+ class InvalidVersionedHashSizeError extends BaseError {
376
+ constructor({ hash, size: size2 }) {
377
+ super(`Versioned hash "${hash}" size is invalid.`, {
378
+ metaMessages: ["Expected: 32", `Received: ${size2}`],
379
+ name: "InvalidVersionedHashSizeError"
380
+ });
381
+ }
382
+ }
383
+
384
+ class InvalidVersionedHashVersionError extends BaseError {
385
+ constructor({ hash, version }) {
386
+ super(`Versioned hash "${hash}" version is invalid.`, {
387
+ metaMessages: [
388
+ `Expected: ${versionedHashVersionKzg}`,
389
+ `Received: ${version}`
390
+ ],
391
+ name: "InvalidVersionedHashVersionError"
392
+ });
393
+ }
394
+ }
395
+
396
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/utils/blob/toBlobs.js
397
+ function toBlobs(parameters) {
398
+ const to = parameters.to ?? (typeof parameters.data === "string" ? "hex" : "bytes");
399
+ const data = typeof parameters.data === "string" ? hexToBytes(parameters.data) : parameters.data;
400
+ const size_ = size(data);
401
+ if (!size_)
402
+ throw new EmptyBlobError;
403
+ if (size_ > maxBytesPerTransaction)
404
+ throw new BlobSizeTooLargeError({
405
+ maxSize: maxBytesPerTransaction,
406
+ size: size_
407
+ });
408
+ const blobs = [];
409
+ let active = true;
410
+ let position = 0;
411
+ while (active) {
412
+ const blob = createCursor(new Uint8Array(bytesPerBlob));
413
+ let size2 = 0;
414
+ while (size2 < fieldElementsPerBlob) {
415
+ const bytes = data.slice(position, position + (bytesPerFieldElement - 1));
416
+ blob.pushByte(0);
417
+ blob.pushBytes(bytes);
418
+ if (bytes.length < 31) {
419
+ blob.pushByte(128);
420
+ active = false;
421
+ break;
422
+ }
423
+ size2++;
424
+ position += 31;
425
+ }
426
+ blobs.push(blob);
427
+ }
428
+ return to === "bytes" ? blobs.map((x) => x.bytes) : blobs.map((x) => bytesToHex(x.bytes));
429
+ }
430
+
431
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/utils/blob/toBlobSidecars.js
432
+ function toBlobSidecars(parameters) {
433
+ const { data, kzg, to } = parameters;
434
+ const blobs = parameters.blobs ?? toBlobs({ data, to });
435
+ const commitments = parameters.commitments ?? blobsToCommitments({ blobs, kzg, to });
436
+ const proofs = parameters.proofs ?? blobsToProofs({ blobs, commitments, kzg, to });
437
+ const sidecars = [];
438
+ for (let i = 0;i < blobs.length; i++)
439
+ sidecars.push({
440
+ blob: blobs[i],
441
+ commitment: commitments[i],
442
+ proof: proofs[i]
443
+ });
444
+ return sidecars;
445
+ }
446
+
447
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/utils/transaction/assertTransaction.js
448
+ function assertTransactionEIP7702(transaction) {
449
+ const { authorizationList } = transaction;
450
+ if (authorizationList) {
451
+ for (const authorization of authorizationList) {
452
+ const { chainId } = authorization;
453
+ const address = authorization.address;
454
+ if (!isAddress(address))
455
+ throw new InvalidAddressError({ address });
456
+ if (chainId < 0)
457
+ throw new InvalidChainIdError({ chainId });
458
+ }
459
+ }
460
+ assertTransactionEIP1559(transaction);
461
+ }
462
+ function assertTransactionEIP4844(transaction) {
463
+ const { blobVersionedHashes } = transaction;
464
+ if (blobVersionedHashes) {
465
+ if (blobVersionedHashes.length === 0)
466
+ throw new EmptyBlobError;
467
+ for (const hash of blobVersionedHashes) {
468
+ const size_ = size(hash);
469
+ const version = hexToNumber(slice(hash, 0, 1));
470
+ if (size_ !== 32)
471
+ throw new InvalidVersionedHashSizeError({ hash, size: size_ });
472
+ if (version !== versionedHashVersionKzg)
473
+ throw new InvalidVersionedHashVersionError({
474
+ hash,
475
+ version
476
+ });
477
+ }
478
+ }
479
+ assertTransactionEIP1559(transaction);
480
+ }
481
+ function assertTransactionEIP1559(transaction) {
482
+ const { chainId, maxPriorityFeePerGas, maxFeePerGas, to } = transaction;
483
+ if (chainId <= 0)
484
+ throw new InvalidChainIdError({ chainId });
485
+ if (to && !isAddress(to))
486
+ throw new InvalidAddressError({ address: to });
487
+ if (maxFeePerGas && maxFeePerGas > maxUint256)
488
+ throw new FeeCapTooHighError({ maxFeePerGas });
489
+ if (maxPriorityFeePerGas && maxFeePerGas && maxPriorityFeePerGas > maxFeePerGas)
490
+ throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas });
491
+ }
492
+ function assertTransactionEIP2930(transaction) {
493
+ const { chainId, maxPriorityFeePerGas, gasPrice, maxFeePerGas, to } = transaction;
494
+ if (chainId <= 0)
495
+ throw new InvalidChainIdError({ chainId });
496
+ if (to && !isAddress(to))
497
+ throw new InvalidAddressError({ address: to });
498
+ if (maxPriorityFeePerGas || maxFeePerGas)
499
+ throw new BaseError("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");
500
+ if (gasPrice && gasPrice > maxUint256)
501
+ throw new FeeCapTooHighError({ maxFeePerGas: gasPrice });
502
+ }
503
+ function assertTransactionLegacy(transaction) {
504
+ const { chainId, maxPriorityFeePerGas, gasPrice, maxFeePerGas, to } = transaction;
505
+ if (to && !isAddress(to))
506
+ throw new InvalidAddressError({ address: to });
507
+ if (typeof chainId !== "undefined" && chainId <= 0)
508
+ throw new InvalidChainIdError({ chainId });
509
+ if (maxPriorityFeePerGas || maxFeePerGas)
510
+ throw new BaseError("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");
511
+ if (gasPrice && gasPrice > maxUint256)
512
+ throw new FeeCapTooHighError({ maxFeePerGas: gasPrice });
513
+ }
514
+
515
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/utils/transaction/getTransactionType.js
516
+ function getTransactionType(transaction) {
517
+ if (transaction.type)
518
+ return transaction.type;
519
+ if (typeof transaction.authorizationList !== "undefined")
520
+ return "eip7702";
521
+ if (typeof transaction.blobs !== "undefined" || typeof transaction.blobVersionedHashes !== "undefined" || typeof transaction.maxFeePerBlobGas !== "undefined" || typeof transaction.sidecars !== "undefined")
522
+ return "eip4844";
523
+ if (typeof transaction.maxFeePerGas !== "undefined" || typeof transaction.maxPriorityFeePerGas !== "undefined") {
524
+ return "eip1559";
525
+ }
526
+ if (typeof transaction.gasPrice !== "undefined") {
527
+ if (typeof transaction.accessList !== "undefined")
528
+ return "eip2930";
529
+ return "legacy";
530
+ }
531
+ throw new InvalidSerializableTransactionError({ transaction });
532
+ }
533
+
534
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/utils/transaction/serializeAccessList.js
535
+ function serializeAccessList(accessList) {
536
+ if (!accessList || accessList.length === 0)
537
+ return [];
538
+ const serializedAccessList = [];
539
+ for (let i = 0;i < accessList.length; i++) {
540
+ const { address, storageKeys } = accessList[i];
541
+ for (let j = 0;j < storageKeys.length; j++) {
542
+ if (storageKeys[j].length - 2 !== 64) {
543
+ throw new InvalidStorageKeySizeError({ storageKey: storageKeys[j] });
544
+ }
545
+ }
546
+ if (!isAddress(address, { strict: false })) {
547
+ throw new InvalidAddressError({ address });
548
+ }
549
+ serializedAccessList.push([address, storageKeys]);
550
+ }
551
+ return serializedAccessList;
552
+ }
553
+
554
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/utils/transaction/serializeTransaction.js
555
+ function serializeTransaction(transaction, signature) {
556
+ const type = getTransactionType(transaction);
557
+ if (type === "eip1559")
558
+ return serializeTransactionEIP1559(transaction, signature);
559
+ if (type === "eip2930")
560
+ return serializeTransactionEIP2930(transaction, signature);
561
+ if (type === "eip4844")
562
+ return serializeTransactionEIP4844(transaction, signature);
563
+ if (type === "eip7702")
564
+ return serializeTransactionEIP7702(transaction, signature);
565
+ return serializeTransactionLegacy(transaction, signature);
566
+ }
567
+ function serializeTransactionEIP7702(transaction, signature) {
568
+ const { authorizationList, chainId, gas, nonce, to, value, maxFeePerGas, maxPriorityFeePerGas, accessList, data } = transaction;
569
+ assertTransactionEIP7702(transaction);
570
+ const serializedAccessList = serializeAccessList(accessList);
571
+ const serializedAuthorizationList = serializeAuthorizationList(authorizationList);
572
+ return concatHex([
573
+ "0x04",
574
+ toRlp([
575
+ numberToHex(chainId),
576
+ nonce ? numberToHex(nonce) : "0x",
577
+ maxPriorityFeePerGas ? numberToHex(maxPriorityFeePerGas) : "0x",
578
+ maxFeePerGas ? numberToHex(maxFeePerGas) : "0x",
579
+ gas ? numberToHex(gas) : "0x",
580
+ to ?? "0x",
581
+ value ? numberToHex(value) : "0x",
582
+ data ?? "0x",
583
+ serializedAccessList,
584
+ serializedAuthorizationList,
585
+ ...toYParitySignatureArray(transaction, signature)
586
+ ])
587
+ ]);
588
+ }
589
+ function serializeTransactionEIP4844(transaction, signature) {
590
+ const { chainId, gas, nonce, to, value, maxFeePerBlobGas, maxFeePerGas, maxPriorityFeePerGas, accessList, data } = transaction;
591
+ assertTransactionEIP4844(transaction);
592
+ let blobVersionedHashes = transaction.blobVersionedHashes;
593
+ let sidecars = transaction.sidecars;
594
+ if (transaction.blobs && (typeof blobVersionedHashes === "undefined" || typeof sidecars === "undefined")) {
595
+ const blobs2 = typeof transaction.blobs[0] === "string" ? transaction.blobs : transaction.blobs.map((x) => bytesToHex(x));
596
+ const kzg = transaction.kzg;
597
+ const commitments2 = blobsToCommitments({
598
+ blobs: blobs2,
599
+ kzg
600
+ });
601
+ if (typeof blobVersionedHashes === "undefined")
602
+ blobVersionedHashes = commitmentsToVersionedHashes({
603
+ commitments: commitments2
604
+ });
605
+ if (typeof sidecars === "undefined") {
606
+ const proofs2 = blobsToProofs({ blobs: blobs2, commitments: commitments2, kzg });
607
+ sidecars = toBlobSidecars({ blobs: blobs2, commitments: commitments2, proofs: proofs2 });
608
+ }
609
+ }
610
+ const serializedAccessList = serializeAccessList(accessList);
611
+ const serializedTransaction = [
612
+ numberToHex(chainId),
613
+ nonce ? numberToHex(nonce) : "0x",
614
+ maxPriorityFeePerGas ? numberToHex(maxPriorityFeePerGas) : "0x",
615
+ maxFeePerGas ? numberToHex(maxFeePerGas) : "0x",
616
+ gas ? numberToHex(gas) : "0x",
617
+ to ?? "0x",
618
+ value ? numberToHex(value) : "0x",
619
+ data ?? "0x",
620
+ serializedAccessList,
621
+ maxFeePerBlobGas ? numberToHex(maxFeePerBlobGas) : "0x",
622
+ blobVersionedHashes ?? [],
623
+ ...toYParitySignatureArray(transaction, signature)
624
+ ];
625
+ const blobs = [];
626
+ const commitments = [];
627
+ const proofs = [];
628
+ if (sidecars)
629
+ for (let i = 0;i < sidecars.length; i++) {
630
+ const { blob, commitment, proof } = sidecars[i];
631
+ blobs.push(blob);
632
+ commitments.push(commitment);
633
+ proofs.push(proof);
634
+ }
635
+ return concatHex([
636
+ "0x03",
637
+ sidecars ? toRlp([serializedTransaction, blobs, commitments, proofs]) : toRlp(serializedTransaction)
638
+ ]);
639
+ }
640
+ function serializeTransactionEIP1559(transaction, signature) {
641
+ const { chainId, gas, nonce, to, value, maxFeePerGas, maxPriorityFeePerGas, accessList, data } = transaction;
642
+ assertTransactionEIP1559(transaction);
643
+ const serializedAccessList = serializeAccessList(accessList);
644
+ const serializedTransaction = [
645
+ numberToHex(chainId),
646
+ nonce ? numberToHex(nonce) : "0x",
647
+ maxPriorityFeePerGas ? numberToHex(maxPriorityFeePerGas) : "0x",
648
+ maxFeePerGas ? numberToHex(maxFeePerGas) : "0x",
649
+ gas ? numberToHex(gas) : "0x",
650
+ to ?? "0x",
651
+ value ? numberToHex(value) : "0x",
652
+ data ?? "0x",
653
+ serializedAccessList,
654
+ ...toYParitySignatureArray(transaction, signature)
655
+ ];
656
+ return concatHex([
657
+ "0x02",
658
+ toRlp(serializedTransaction)
659
+ ]);
660
+ }
661
+ function serializeTransactionEIP2930(transaction, signature) {
662
+ const { chainId, gas, data, nonce, to, value, accessList, gasPrice } = transaction;
663
+ assertTransactionEIP2930(transaction);
664
+ const serializedAccessList = serializeAccessList(accessList);
665
+ const serializedTransaction = [
666
+ numberToHex(chainId),
667
+ nonce ? numberToHex(nonce) : "0x",
668
+ gasPrice ? numberToHex(gasPrice) : "0x",
669
+ gas ? numberToHex(gas) : "0x",
670
+ to ?? "0x",
671
+ value ? numberToHex(value) : "0x",
672
+ data ?? "0x",
673
+ serializedAccessList,
674
+ ...toYParitySignatureArray(transaction, signature)
675
+ ];
676
+ return concatHex([
677
+ "0x01",
678
+ toRlp(serializedTransaction)
679
+ ]);
680
+ }
681
+ function serializeTransactionLegacy(transaction, signature) {
682
+ const { chainId = 0, gas, data, nonce, to, value, gasPrice } = transaction;
683
+ assertTransactionLegacy(transaction);
684
+ let serializedTransaction = [
685
+ nonce ? numberToHex(nonce) : "0x",
686
+ gasPrice ? numberToHex(gasPrice) : "0x",
687
+ gas ? numberToHex(gas) : "0x",
688
+ to ?? "0x",
689
+ value ? numberToHex(value) : "0x",
690
+ data ?? "0x"
691
+ ];
692
+ if (signature) {
693
+ const v = (() => {
694
+ if (signature.v >= 35n) {
695
+ const inferredChainId = (signature.v - 35n) / 2n;
696
+ if (inferredChainId > 0)
697
+ return signature.v;
698
+ return 27n + (signature.v === 35n ? 0n : 1n);
699
+ }
700
+ if (chainId > 0)
701
+ return BigInt(chainId * 2) + BigInt(35n + signature.v - 27n);
702
+ const v2 = 27n + (signature.v === 27n ? 0n : 1n);
703
+ if (signature.v !== v2)
704
+ throw new InvalidLegacyVError({ v: signature.v });
705
+ return v2;
706
+ })();
707
+ const r = trim(signature.r);
708
+ const s = trim(signature.s);
709
+ serializedTransaction = [
710
+ ...serializedTransaction,
711
+ numberToHex(v),
712
+ r === "0x00" ? "0x" : r,
713
+ s === "0x00" ? "0x" : s
714
+ ];
715
+ } else if (chainId > 0) {
716
+ serializedTransaction = [
717
+ ...serializedTransaction,
718
+ numberToHex(chainId),
719
+ "0x",
720
+ "0x"
721
+ ];
722
+ }
723
+ return toRlp(serializedTransaction);
724
+ }
725
+ function toYParitySignatureArray(transaction, signature_) {
726
+ const signature = signature_ ?? transaction;
727
+ const { v, yParity } = signature;
728
+ if (typeof signature.r === "undefined")
729
+ return [];
730
+ if (typeof signature.s === "undefined")
731
+ return [];
732
+ if (typeof v === "undefined" && typeof yParity === "undefined")
733
+ return [];
734
+ const r = trim(signature.r);
735
+ const s = trim(signature.s);
736
+ const yParity_ = (() => {
737
+ if (typeof yParity === "number")
738
+ return yParity ? numberToHex(1) : "0x";
739
+ if (v === 0n)
740
+ return "0x";
741
+ if (v === 1n)
742
+ return numberToHex(1);
743
+ return v === 27n ? "0x" : numberToHex(1);
744
+ })();
745
+ return [yParity_, r === "0x00" ? "0x" : r, s === "0x00" ? "0x" : s];
746
+ }
747
+
748
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/accounts/utils/signTransaction.js
749
+ async function signTransaction(parameters) {
750
+ const { privateKey, transaction, serializer = serializeTransaction } = parameters;
751
+ const signableTransaction = (() => {
752
+ if (transaction.type === "eip4844")
753
+ return {
754
+ ...transaction,
755
+ sidecars: false
756
+ };
757
+ return transaction;
758
+ })();
759
+ const signature = await sign({
760
+ hash: keccak256(await serializer(signableTransaction)),
761
+ privateKey
762
+ });
763
+ return await serializer(transaction, signature);
764
+ }
765
+
766
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/errors/typedData.js
767
+ class InvalidDomainError extends BaseError {
768
+ constructor({ domain }) {
769
+ super(`Invalid domain "${stringify(domain)}".`, {
770
+ metaMessages: ["Must be a valid EIP-712 domain."]
771
+ });
772
+ }
773
+ }
774
+
775
+ class InvalidPrimaryTypeError extends BaseError {
776
+ constructor({ primaryType, types }) {
777
+ super(`Invalid primary type \`${primaryType}\` must be one of \`${JSON.stringify(Object.keys(types))}\`.`, {
778
+ docsPath: "/api/glossary/Errors#typeddatainvalidprimarytypeerror",
779
+ metaMessages: ["Check that the primary type is a key in `types`."]
780
+ });
781
+ }
782
+ }
783
+
784
+ class InvalidStructTypeError extends BaseError {
785
+ constructor({ type }) {
786
+ super(`Struct type "${type}" is invalid.`, {
787
+ metaMessages: ["Struct type must not be a Solidity type."],
788
+ name: "InvalidStructTypeError"
789
+ });
790
+ }
791
+ }
792
+
793
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/utils/typedData.js
794
+ function serializeTypedData(parameters) {
795
+ const { domain: domain_, message: message_, primaryType, types } = parameters;
796
+ const normalizeData = (struct, data_) => {
797
+ const data = { ...data_ };
798
+ for (const param of struct) {
799
+ const { name, type } = param;
800
+ if (type === "address")
801
+ data[name] = data[name].toLowerCase();
802
+ }
803
+ return data;
804
+ };
805
+ const domain = (() => {
806
+ if (!types.EIP712Domain)
807
+ return {};
808
+ if (!domain_)
809
+ return {};
810
+ return normalizeData(types.EIP712Domain, domain_);
811
+ })();
812
+ const message = (() => {
813
+ if (primaryType === "EIP712Domain")
814
+ return;
815
+ return normalizeData(types[primaryType], message_);
816
+ })();
817
+ return stringify({ domain, message, primaryType, types });
818
+ }
819
+ function validateTypedData(parameters) {
820
+ const { domain, message, primaryType, types } = parameters;
821
+ const validateData = (struct, data) => {
822
+ for (const param of struct) {
823
+ const { name, type } = param;
824
+ const value = data[name];
825
+ const integerMatch = type.match(integerRegex);
826
+ if (integerMatch && (typeof value === "number" || typeof value === "bigint")) {
827
+ const [_type, base, size_] = integerMatch;
828
+ numberToHex(value, {
829
+ signed: base === "int",
830
+ size: Number.parseInt(size_, 10) / 8
831
+ });
832
+ }
833
+ if (type === "address" && typeof value === "string" && !isAddress(value))
834
+ throw new InvalidAddressError({ address: value });
835
+ const bytesMatch = type.match(bytesRegex);
836
+ if (bytesMatch) {
837
+ const [_type, size_] = bytesMatch;
838
+ if (size_ && size(value) !== Number.parseInt(size_, 10))
839
+ throw new BytesSizeMismatchError({
840
+ expectedSize: Number.parseInt(size_, 10),
841
+ givenSize: size(value)
842
+ });
843
+ }
844
+ const struct2 = types[type];
845
+ if (struct2) {
846
+ validateReference(type);
847
+ validateData(struct2, value);
848
+ }
849
+ }
850
+ };
851
+ if (types.EIP712Domain && domain) {
852
+ if (typeof domain !== "object")
853
+ throw new InvalidDomainError({ domain });
854
+ validateData(types.EIP712Domain, domain);
855
+ }
856
+ if (primaryType !== "EIP712Domain") {
857
+ if (types[primaryType])
858
+ validateData(types[primaryType], message);
859
+ else
860
+ throw new InvalidPrimaryTypeError({ primaryType, types });
861
+ }
862
+ }
863
+ function getTypesForEIP712Domain({ domain }) {
864
+ return [
865
+ typeof domain?.name === "string" && { name: "name", type: "string" },
866
+ domain?.version && { name: "version", type: "string" },
867
+ (typeof domain?.chainId === "number" || typeof domain?.chainId === "bigint") && {
868
+ name: "chainId",
869
+ type: "uint256"
870
+ },
871
+ domain?.verifyingContract && {
872
+ name: "verifyingContract",
873
+ type: "address"
874
+ },
875
+ domain?.salt && { name: "salt", type: "bytes32" }
876
+ ].filter(Boolean);
877
+ }
878
+ function validateReference(type) {
879
+ if (type === "address" || type === "bool" || type === "string" || type.startsWith("bytes") || type.startsWith("uint") || type.startsWith("int"))
880
+ throw new InvalidStructTypeError({ type });
881
+ }
882
+
883
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/utils/signature/hashTypedData.js
884
+ function hashTypedData(parameters) {
885
+ const { domain = {}, message, primaryType } = parameters;
886
+ const types = {
887
+ EIP712Domain: getTypesForEIP712Domain({ domain }),
888
+ ...parameters.types
889
+ };
890
+ validateTypedData({
891
+ domain,
892
+ message,
893
+ primaryType,
894
+ types
895
+ });
896
+ const parts = ["0x1901"];
897
+ if (domain)
898
+ parts.push(hashDomain({
899
+ domain,
900
+ types
901
+ }));
902
+ if (primaryType !== "EIP712Domain")
903
+ parts.push(hashStruct({
904
+ data: message,
905
+ primaryType,
906
+ types
907
+ }));
908
+ return keccak256(concat(parts));
909
+ }
910
+ function hashDomain({ domain, types }) {
911
+ return hashStruct({
912
+ data: domain,
913
+ primaryType: "EIP712Domain",
914
+ types
915
+ });
916
+ }
917
+ function hashStruct({ data, primaryType, types }) {
918
+ const encoded = encodeData({
919
+ data,
920
+ primaryType,
921
+ types
922
+ });
923
+ return keccak256(encoded);
924
+ }
925
+ function encodeData({ data, primaryType, types }) {
926
+ const encodedTypes = [{ type: "bytes32" }];
927
+ const encodedValues = [hashType({ primaryType, types })];
928
+ for (const field of types[primaryType]) {
929
+ const [type, value] = encodeField({
930
+ types,
931
+ name: field.name,
932
+ type: field.type,
933
+ value: data[field.name]
934
+ });
935
+ encodedTypes.push(type);
936
+ encodedValues.push(value);
937
+ }
938
+ return encodeAbiParameters(encodedTypes, encodedValues);
939
+ }
940
+ function hashType({ primaryType, types }) {
941
+ const encodedHashType = toHex(encodeType({ primaryType, types }));
942
+ return keccak256(encodedHashType);
943
+ }
944
+ function encodeType({ primaryType, types }) {
945
+ let result = "";
946
+ const unsortedDeps = findTypeDependencies({ primaryType, types });
947
+ unsortedDeps.delete(primaryType);
948
+ const deps = [primaryType, ...Array.from(unsortedDeps).sort()];
949
+ for (const type of deps) {
950
+ result += `${type}(${types[type].map(({ name, type: t }) => `${t} ${name}`).join(",")})`;
951
+ }
952
+ return result;
953
+ }
954
+ function findTypeDependencies({ primaryType: primaryType_, types }, results = new Set) {
955
+ const match = primaryType_.match(/^\w*/u);
956
+ const primaryType = match?.[0];
957
+ if (results.has(primaryType) || types[primaryType] === undefined) {
958
+ return results;
959
+ }
960
+ results.add(primaryType);
961
+ for (const field of types[primaryType]) {
962
+ findTypeDependencies({ primaryType: field.type, types }, results);
963
+ }
964
+ return results;
965
+ }
966
+ function encodeField({ types, name, type, value }) {
967
+ if (types[type] !== undefined) {
968
+ return [
969
+ { type: "bytes32" },
970
+ keccak256(encodeData({ data: value, primaryType: type, types }))
971
+ ];
972
+ }
973
+ if (type === "bytes")
974
+ return [{ type: "bytes32" }, keccak256(value)];
975
+ if (type === "string")
976
+ return [{ type: "bytes32" }, keccak256(toHex(value))];
977
+ if (type.lastIndexOf("]") === type.length - 1) {
978
+ const parsedType = type.slice(0, type.lastIndexOf("["));
979
+ const typeValuePairs = value.map((item) => encodeField({
980
+ name,
981
+ type: parsedType,
982
+ types,
983
+ value: item
984
+ }));
985
+ return [
986
+ { type: "bytes32" },
987
+ keccak256(encodeAbiParameters(typeValuePairs.map(([t]) => t), typeValuePairs.map(([, v]) => v)))
988
+ ];
989
+ }
990
+ return [{ type }, value];
991
+ }
992
+
993
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/accounts/utils/signTypedData.js
994
+ async function signTypedData(parameters) {
995
+ const { privateKey, ...typedData } = parameters;
996
+ return await sign({
997
+ hash: hashTypedData(typedData),
998
+ privateKey,
999
+ to: "hex"
1000
+ });
1001
+ }
1002
+
1003
+ // ../../node_modules/.bun/viem@2.52.0+e016764623ac6761/node_modules/viem/_esm/accounts/privateKeyToAccount.js
1004
+ function privateKeyToAccount(privateKey, options = {}) {
1005
+ const { nonceManager } = options;
1006
+ const publicKey = toHex(secp256k1.getPublicKey(privateKey.slice(2), false));
1007
+ const address = publicKeyToAddress(publicKey);
1008
+ const account = toAccount({
1009
+ address,
1010
+ nonceManager,
1011
+ async sign({ hash }) {
1012
+ return sign({ hash, privateKey, to: "hex" });
1013
+ },
1014
+ async signAuthorization(authorization) {
1015
+ return signAuthorization({ ...authorization, privateKey });
1016
+ },
1017
+ async signMessage({ message }) {
1018
+ return signMessage({ message, privateKey });
1019
+ },
1020
+ async signTransaction(transaction, { serializer } = {}) {
1021
+ return signTransaction({ privateKey, transaction, serializer });
1022
+ },
1023
+ async signTypedData(typedData) {
1024
+ return signTypedData({ ...typedData, privateKey });
1025
+ }
1026
+ });
1027
+ return {
1028
+ ...account,
1029
+ publicKey,
1030
+ source: "privateKey"
1031
+ };
1032
+ }
1033
+ export { generatePrivateKey, publicKeyToAddress, serializeSignature, toRlp, hashAuthorization, hashMessage, blobsToCommitments, blobsToProofs, sha2563 as sha256, commitmentsToVersionedHashes, toBlobSidecars, getTransactionType, serializeTransaction, serializeTypedData, validateTypedData, getTypesForEIP712Domain, hashTypedData, privateKeyToAccount, DECIMAL, ERC8004_REGISTRY, CAIP19_ERC721 };