@elizaos/plugin-tee 0.1.7-alpha.1 → 0.1.7
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/LICENSE +21 -0
- package/README.md +183 -50
- package/dist/_esm-L4OBJJWB.js +3913 -0
- package/dist/_esm-L4OBJJWB.js.map +1 -0
- package/dist/ccip-MMGH6DXX.js +14 -0
- package/dist/ccip-MMGH6DXX.js.map +1 -0
- package/dist/chunk-4L6P6TY5.js +2556 -0
- package/dist/chunk-4L6P6TY5.js.map +1 -0
- package/dist/chunk-NTU6R7BC.js +4019 -0
- package/dist/chunk-NTU6R7BC.js.map +1 -0
- package/dist/chunk-PR4QN5HX.js +43 -0
- package/dist/chunk-PR4QN5HX.js.map +1 -0
- package/dist/index.js +1253 -2
- package/dist/index.js.map +1 -1
- package/dist/secp256k1-QUTB2QC2.js +14 -0
- package/dist/secp256k1-QUTB2QC2.js.map +1 -0
- package/package.json +40 -26
- package/tsup.config.ts +0 -28
package/dist/index.js
CHANGED
|
@@ -1,3 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
secp256k1
|
|
3
|
+
} from "./chunk-4L6P6TY5.js";
|
|
4
|
+
import {
|
|
5
|
+
BaseError,
|
|
6
|
+
BytesSizeMismatchError,
|
|
7
|
+
FeeCapTooHighError,
|
|
8
|
+
Hash,
|
|
9
|
+
InvalidAddressError,
|
|
10
|
+
InvalidChainIdError,
|
|
11
|
+
InvalidLegacyVError,
|
|
12
|
+
InvalidSerializableTransactionError,
|
|
13
|
+
InvalidStorageKeySizeError,
|
|
14
|
+
TipAboveFeeCapError,
|
|
15
|
+
aexists,
|
|
16
|
+
aoutput,
|
|
17
|
+
bytesRegex,
|
|
18
|
+
bytesToHex,
|
|
19
|
+
checksumAddress,
|
|
20
|
+
concat,
|
|
21
|
+
concatHex,
|
|
22
|
+
createCursor,
|
|
23
|
+
createView,
|
|
24
|
+
encodeAbiParameters,
|
|
25
|
+
hexToBigInt,
|
|
26
|
+
hexToBytes,
|
|
27
|
+
hexToNumber,
|
|
28
|
+
integerRegex,
|
|
29
|
+
isAddress,
|
|
30
|
+
isHex,
|
|
31
|
+
keccak256,
|
|
32
|
+
maxUint256,
|
|
33
|
+
numberToHex,
|
|
34
|
+
rotr,
|
|
35
|
+
size,
|
|
36
|
+
slice,
|
|
37
|
+
stringToHex,
|
|
38
|
+
stringify,
|
|
39
|
+
toBytes,
|
|
40
|
+
toBytes2,
|
|
41
|
+
toHex,
|
|
42
|
+
trim,
|
|
43
|
+
wrapConstructor
|
|
44
|
+
} from "./chunk-NTU6R7BC.js";
|
|
45
|
+
import "./chunk-PR4QN5HX.js";
|
|
46
|
+
|
|
1
47
|
// src/providers/remoteAttestationProvider.ts
|
|
2
48
|
import { TappdClient } from "@phala/dstack-sdk";
|
|
3
49
|
|
|
@@ -88,8 +134,1213 @@ var remoteAttestationProvider = {
|
|
|
88
134
|
import { Keypair } from "@solana/web3.js";
|
|
89
135
|
import crypto from "crypto";
|
|
90
136
|
import { TappdClient as TappdClient2 } from "@phala/dstack-sdk";
|
|
91
|
-
|
|
92
|
-
|
|
137
|
+
|
|
138
|
+
// ../../node_modules/viem/node_modules/@noble/hashes/esm/_md.js
|
|
139
|
+
function setBigUint64(view, byteOffset, value, isLE) {
|
|
140
|
+
if (typeof view.setBigUint64 === "function")
|
|
141
|
+
return view.setBigUint64(byteOffset, value, isLE);
|
|
142
|
+
const _32n = BigInt(32);
|
|
143
|
+
const _u32_max = BigInt(4294967295);
|
|
144
|
+
const wh = Number(value >> _32n & _u32_max);
|
|
145
|
+
const wl = Number(value & _u32_max);
|
|
146
|
+
const h = isLE ? 4 : 0;
|
|
147
|
+
const l = isLE ? 0 : 4;
|
|
148
|
+
view.setUint32(byteOffset + h, wh, isLE);
|
|
149
|
+
view.setUint32(byteOffset + l, wl, isLE);
|
|
150
|
+
}
|
|
151
|
+
var Chi = (a, b, c) => a & b ^ ~a & c;
|
|
152
|
+
var Maj = (a, b, c) => a & b ^ a & c ^ b & c;
|
|
153
|
+
var HashMD = class extends Hash {
|
|
154
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
155
|
+
super();
|
|
156
|
+
this.blockLen = blockLen;
|
|
157
|
+
this.outputLen = outputLen;
|
|
158
|
+
this.padOffset = padOffset;
|
|
159
|
+
this.isLE = isLE;
|
|
160
|
+
this.finished = false;
|
|
161
|
+
this.length = 0;
|
|
162
|
+
this.pos = 0;
|
|
163
|
+
this.destroyed = false;
|
|
164
|
+
this.buffer = new Uint8Array(blockLen);
|
|
165
|
+
this.view = createView(this.buffer);
|
|
166
|
+
}
|
|
167
|
+
update(data) {
|
|
168
|
+
aexists(this);
|
|
169
|
+
const { view, buffer, blockLen } = this;
|
|
170
|
+
data = toBytes(data);
|
|
171
|
+
const len = data.length;
|
|
172
|
+
for (let pos = 0; pos < len; ) {
|
|
173
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
174
|
+
if (take === blockLen) {
|
|
175
|
+
const dataView = createView(data);
|
|
176
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
177
|
+
this.process(dataView, pos);
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
181
|
+
this.pos += take;
|
|
182
|
+
pos += take;
|
|
183
|
+
if (this.pos === blockLen) {
|
|
184
|
+
this.process(view, 0);
|
|
185
|
+
this.pos = 0;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
this.length += data.length;
|
|
189
|
+
this.roundClean();
|
|
190
|
+
return this;
|
|
191
|
+
}
|
|
192
|
+
digestInto(out) {
|
|
193
|
+
aexists(this);
|
|
194
|
+
aoutput(out, this);
|
|
195
|
+
this.finished = true;
|
|
196
|
+
const { buffer, view, blockLen, isLE } = this;
|
|
197
|
+
let { pos } = this;
|
|
198
|
+
buffer[pos++] = 128;
|
|
199
|
+
this.buffer.subarray(pos).fill(0);
|
|
200
|
+
if (this.padOffset > blockLen - pos) {
|
|
201
|
+
this.process(view, 0);
|
|
202
|
+
pos = 0;
|
|
203
|
+
}
|
|
204
|
+
for (let i = pos; i < blockLen; i++)
|
|
205
|
+
buffer[i] = 0;
|
|
206
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
207
|
+
this.process(view, 0);
|
|
208
|
+
const oview = createView(out);
|
|
209
|
+
const len = this.outputLen;
|
|
210
|
+
if (len % 4)
|
|
211
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
212
|
+
const outLen = len / 4;
|
|
213
|
+
const state = this.get();
|
|
214
|
+
if (outLen > state.length)
|
|
215
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
216
|
+
for (let i = 0; i < outLen; i++)
|
|
217
|
+
oview.setUint32(4 * i, state[i], isLE);
|
|
218
|
+
}
|
|
219
|
+
digest() {
|
|
220
|
+
const { buffer, outputLen } = this;
|
|
221
|
+
this.digestInto(buffer);
|
|
222
|
+
const res = buffer.slice(0, outputLen);
|
|
223
|
+
this.destroy();
|
|
224
|
+
return res;
|
|
225
|
+
}
|
|
226
|
+
_cloneInto(to) {
|
|
227
|
+
to || (to = new this.constructor());
|
|
228
|
+
to.set(...this.get());
|
|
229
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
230
|
+
to.length = length;
|
|
231
|
+
to.pos = pos;
|
|
232
|
+
to.finished = finished;
|
|
233
|
+
to.destroyed = destroyed;
|
|
234
|
+
if (length % blockLen)
|
|
235
|
+
to.buffer.set(buffer);
|
|
236
|
+
return to;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
// ../../node_modules/viem/node_modules/@noble/hashes/esm/sha256.js
|
|
241
|
+
var SHA256_K = /* @__PURE__ */ new Uint32Array([
|
|
242
|
+
1116352408,
|
|
243
|
+
1899447441,
|
|
244
|
+
3049323471,
|
|
245
|
+
3921009573,
|
|
246
|
+
961987163,
|
|
247
|
+
1508970993,
|
|
248
|
+
2453635748,
|
|
249
|
+
2870763221,
|
|
250
|
+
3624381080,
|
|
251
|
+
310598401,
|
|
252
|
+
607225278,
|
|
253
|
+
1426881987,
|
|
254
|
+
1925078388,
|
|
255
|
+
2162078206,
|
|
256
|
+
2614888103,
|
|
257
|
+
3248222580,
|
|
258
|
+
3835390401,
|
|
259
|
+
4022224774,
|
|
260
|
+
264347078,
|
|
261
|
+
604807628,
|
|
262
|
+
770255983,
|
|
263
|
+
1249150122,
|
|
264
|
+
1555081692,
|
|
265
|
+
1996064986,
|
|
266
|
+
2554220882,
|
|
267
|
+
2821834349,
|
|
268
|
+
2952996808,
|
|
269
|
+
3210313671,
|
|
270
|
+
3336571891,
|
|
271
|
+
3584528711,
|
|
272
|
+
113926993,
|
|
273
|
+
338241895,
|
|
274
|
+
666307205,
|
|
275
|
+
773529912,
|
|
276
|
+
1294757372,
|
|
277
|
+
1396182291,
|
|
278
|
+
1695183700,
|
|
279
|
+
1986661051,
|
|
280
|
+
2177026350,
|
|
281
|
+
2456956037,
|
|
282
|
+
2730485921,
|
|
283
|
+
2820302411,
|
|
284
|
+
3259730800,
|
|
285
|
+
3345764771,
|
|
286
|
+
3516065817,
|
|
287
|
+
3600352804,
|
|
288
|
+
4094571909,
|
|
289
|
+
275423344,
|
|
290
|
+
430227734,
|
|
291
|
+
506948616,
|
|
292
|
+
659060556,
|
|
293
|
+
883997877,
|
|
294
|
+
958139571,
|
|
295
|
+
1322822218,
|
|
296
|
+
1537002063,
|
|
297
|
+
1747873779,
|
|
298
|
+
1955562222,
|
|
299
|
+
2024104815,
|
|
300
|
+
2227730452,
|
|
301
|
+
2361852424,
|
|
302
|
+
2428436474,
|
|
303
|
+
2756734187,
|
|
304
|
+
3204031479,
|
|
305
|
+
3329325298
|
|
306
|
+
]);
|
|
307
|
+
var SHA256_IV = /* @__PURE__ */ new Uint32Array([
|
|
308
|
+
1779033703,
|
|
309
|
+
3144134277,
|
|
310
|
+
1013904242,
|
|
311
|
+
2773480762,
|
|
312
|
+
1359893119,
|
|
313
|
+
2600822924,
|
|
314
|
+
528734635,
|
|
315
|
+
1541459225
|
|
316
|
+
]);
|
|
317
|
+
var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
318
|
+
var SHA256 = class extends HashMD {
|
|
319
|
+
constructor() {
|
|
320
|
+
super(64, 32, 8, false);
|
|
321
|
+
this.A = SHA256_IV[0] | 0;
|
|
322
|
+
this.B = SHA256_IV[1] | 0;
|
|
323
|
+
this.C = SHA256_IV[2] | 0;
|
|
324
|
+
this.D = SHA256_IV[3] | 0;
|
|
325
|
+
this.E = SHA256_IV[4] | 0;
|
|
326
|
+
this.F = SHA256_IV[5] | 0;
|
|
327
|
+
this.G = SHA256_IV[6] | 0;
|
|
328
|
+
this.H = SHA256_IV[7] | 0;
|
|
329
|
+
}
|
|
330
|
+
get() {
|
|
331
|
+
const { A, B, C, D, E, F, G, H } = this;
|
|
332
|
+
return [A, B, C, D, E, F, G, H];
|
|
333
|
+
}
|
|
334
|
+
// prettier-ignore
|
|
335
|
+
set(A, B, C, D, E, F, G, H) {
|
|
336
|
+
this.A = A | 0;
|
|
337
|
+
this.B = B | 0;
|
|
338
|
+
this.C = C | 0;
|
|
339
|
+
this.D = D | 0;
|
|
340
|
+
this.E = E | 0;
|
|
341
|
+
this.F = F | 0;
|
|
342
|
+
this.G = G | 0;
|
|
343
|
+
this.H = H | 0;
|
|
344
|
+
}
|
|
345
|
+
process(view, offset) {
|
|
346
|
+
for (let i = 0; i < 16; i++, offset += 4)
|
|
347
|
+
SHA256_W[i] = view.getUint32(offset, false);
|
|
348
|
+
for (let i = 16; i < 64; i++) {
|
|
349
|
+
const W15 = SHA256_W[i - 15];
|
|
350
|
+
const W2 = SHA256_W[i - 2];
|
|
351
|
+
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
352
|
+
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
353
|
+
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
354
|
+
}
|
|
355
|
+
let { A, B, C, D, E, F, G, H } = this;
|
|
356
|
+
for (let i = 0; i < 64; i++) {
|
|
357
|
+
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
358
|
+
const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
359
|
+
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
360
|
+
const T2 = sigma0 + Maj(A, B, C) | 0;
|
|
361
|
+
H = G;
|
|
362
|
+
G = F;
|
|
363
|
+
F = E;
|
|
364
|
+
E = D + T1 | 0;
|
|
365
|
+
D = C;
|
|
366
|
+
C = B;
|
|
367
|
+
B = A;
|
|
368
|
+
A = T1 + T2 | 0;
|
|
369
|
+
}
|
|
370
|
+
A = A + this.A | 0;
|
|
371
|
+
B = B + this.B | 0;
|
|
372
|
+
C = C + this.C | 0;
|
|
373
|
+
D = D + this.D | 0;
|
|
374
|
+
E = E + this.E | 0;
|
|
375
|
+
F = F + this.F | 0;
|
|
376
|
+
G = G + this.G | 0;
|
|
377
|
+
H = H + this.H | 0;
|
|
378
|
+
this.set(A, B, C, D, E, F, G, H);
|
|
379
|
+
}
|
|
380
|
+
roundClean() {
|
|
381
|
+
SHA256_W.fill(0);
|
|
382
|
+
}
|
|
383
|
+
destroy() {
|
|
384
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
385
|
+
this.buffer.fill(0);
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
var sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
|
|
389
|
+
|
|
390
|
+
// ../../node_modules/viem/_esm/accounts/toAccount.js
|
|
391
|
+
function toAccount(source) {
|
|
392
|
+
if (typeof source === "string") {
|
|
393
|
+
if (!isAddress(source, { strict: false }))
|
|
394
|
+
throw new InvalidAddressError({ address: source });
|
|
395
|
+
return {
|
|
396
|
+
address: source,
|
|
397
|
+
type: "json-rpc"
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
if (!isAddress(source.address, { strict: false }))
|
|
401
|
+
throw new InvalidAddressError({ address: source.address });
|
|
402
|
+
return {
|
|
403
|
+
address: source.address,
|
|
404
|
+
nonceManager: source.nonceManager,
|
|
405
|
+
sign: source.sign,
|
|
406
|
+
experimental_signAuthorization: source.experimental_signAuthorization,
|
|
407
|
+
signMessage: source.signMessage,
|
|
408
|
+
signTransaction: source.signTransaction,
|
|
409
|
+
signTypedData: source.signTypedData,
|
|
410
|
+
source: "custom",
|
|
411
|
+
type: "local"
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// ../../node_modules/viem/_esm/accounts/utils/publicKeyToAddress.js
|
|
416
|
+
function publicKeyToAddress(publicKey) {
|
|
417
|
+
const address = keccak256(`0x${publicKey.substring(4)}`).substring(26);
|
|
418
|
+
return checksumAddress(`0x${address}`);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// ../../node_modules/viem/_esm/utils/signature/serializeSignature.js
|
|
422
|
+
function serializeSignature({ r, s, to = "hex", v, yParity }) {
|
|
423
|
+
const yParity_ = (() => {
|
|
424
|
+
if (yParity === 0 || yParity === 1)
|
|
425
|
+
return yParity;
|
|
426
|
+
if (v && (v === 27n || v === 28n || v >= 35n))
|
|
427
|
+
return v % 2n === 0n ? 1 : 0;
|
|
428
|
+
throw new Error("Invalid `v` or `yParity` value");
|
|
429
|
+
})();
|
|
430
|
+
const signature = `0x${new secp256k1.Signature(hexToBigInt(r), hexToBigInt(s)).toCompactHex()}${yParity_ === 0 ? "1b" : "1c"}`;
|
|
431
|
+
if (to === "hex")
|
|
432
|
+
return signature;
|
|
433
|
+
return hexToBytes(signature);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// ../../node_modules/viem/_esm/accounts/utils/sign.js
|
|
437
|
+
var extraEntropy = false;
|
|
438
|
+
async function sign({ hash, privateKey, to = "object" }) {
|
|
439
|
+
const { r, s, recovery } = secp256k1.sign(hash.slice(2), privateKey.slice(2), { lowS: true, extraEntropy });
|
|
440
|
+
const signature = {
|
|
441
|
+
r: numberToHex(r, { size: 32 }),
|
|
442
|
+
s: numberToHex(s, { size: 32 }),
|
|
443
|
+
v: recovery ? 28n : 27n,
|
|
444
|
+
yParity: recovery
|
|
445
|
+
};
|
|
446
|
+
return (() => {
|
|
447
|
+
if (to === "bytes" || to === "hex")
|
|
448
|
+
return serializeSignature({ ...signature, to });
|
|
449
|
+
return signature;
|
|
450
|
+
})();
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// ../../node_modules/viem/_esm/utils/encoding/toRlp.js
|
|
454
|
+
function toRlp(bytes, to = "hex") {
|
|
455
|
+
const encodable = getEncodable(bytes);
|
|
456
|
+
const cursor = createCursor(new Uint8Array(encodable.length));
|
|
457
|
+
encodable.encode(cursor);
|
|
458
|
+
if (to === "hex")
|
|
459
|
+
return bytesToHex(cursor.bytes);
|
|
460
|
+
return cursor.bytes;
|
|
461
|
+
}
|
|
462
|
+
function getEncodable(bytes) {
|
|
463
|
+
if (Array.isArray(bytes))
|
|
464
|
+
return getEncodableList(bytes.map((x) => getEncodable(x)));
|
|
465
|
+
return getEncodableBytes(bytes);
|
|
466
|
+
}
|
|
467
|
+
function getEncodableList(list) {
|
|
468
|
+
const bodyLength = list.reduce((acc, x) => acc + x.length, 0);
|
|
469
|
+
const sizeOfBodyLength = getSizeOfLength(bodyLength);
|
|
470
|
+
const length = (() => {
|
|
471
|
+
if (bodyLength <= 55)
|
|
472
|
+
return 1 + bodyLength;
|
|
473
|
+
return 1 + sizeOfBodyLength + bodyLength;
|
|
474
|
+
})();
|
|
475
|
+
return {
|
|
476
|
+
length,
|
|
477
|
+
encode(cursor) {
|
|
478
|
+
if (bodyLength <= 55) {
|
|
479
|
+
cursor.pushByte(192 + bodyLength);
|
|
480
|
+
} else {
|
|
481
|
+
cursor.pushByte(192 + 55 + sizeOfBodyLength);
|
|
482
|
+
if (sizeOfBodyLength === 1)
|
|
483
|
+
cursor.pushUint8(bodyLength);
|
|
484
|
+
else if (sizeOfBodyLength === 2)
|
|
485
|
+
cursor.pushUint16(bodyLength);
|
|
486
|
+
else if (sizeOfBodyLength === 3)
|
|
487
|
+
cursor.pushUint24(bodyLength);
|
|
488
|
+
else
|
|
489
|
+
cursor.pushUint32(bodyLength);
|
|
490
|
+
}
|
|
491
|
+
for (const { encode } of list) {
|
|
492
|
+
encode(cursor);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
function getEncodableBytes(bytesOrHex) {
|
|
498
|
+
const bytes = typeof bytesOrHex === "string" ? hexToBytes(bytesOrHex) : bytesOrHex;
|
|
499
|
+
const sizeOfBytesLength = getSizeOfLength(bytes.length);
|
|
500
|
+
const length = (() => {
|
|
501
|
+
if (bytes.length === 1 && bytes[0] < 128)
|
|
502
|
+
return 1;
|
|
503
|
+
if (bytes.length <= 55)
|
|
504
|
+
return 1 + bytes.length;
|
|
505
|
+
return 1 + sizeOfBytesLength + bytes.length;
|
|
506
|
+
})();
|
|
507
|
+
return {
|
|
508
|
+
length,
|
|
509
|
+
encode(cursor) {
|
|
510
|
+
if (bytes.length === 1 && bytes[0] < 128) {
|
|
511
|
+
cursor.pushBytes(bytes);
|
|
512
|
+
} else if (bytes.length <= 55) {
|
|
513
|
+
cursor.pushByte(128 + bytes.length);
|
|
514
|
+
cursor.pushBytes(bytes);
|
|
515
|
+
} else {
|
|
516
|
+
cursor.pushByte(128 + 55 + sizeOfBytesLength);
|
|
517
|
+
if (sizeOfBytesLength === 1)
|
|
518
|
+
cursor.pushUint8(bytes.length);
|
|
519
|
+
else if (sizeOfBytesLength === 2)
|
|
520
|
+
cursor.pushUint16(bytes.length);
|
|
521
|
+
else if (sizeOfBytesLength === 3)
|
|
522
|
+
cursor.pushUint24(bytes.length);
|
|
523
|
+
else
|
|
524
|
+
cursor.pushUint32(bytes.length);
|
|
525
|
+
cursor.pushBytes(bytes);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
function getSizeOfLength(length) {
|
|
531
|
+
if (length < 2 ** 8)
|
|
532
|
+
return 1;
|
|
533
|
+
if (length < 2 ** 16)
|
|
534
|
+
return 2;
|
|
535
|
+
if (length < 2 ** 24)
|
|
536
|
+
return 3;
|
|
537
|
+
if (length < 2 ** 32)
|
|
538
|
+
return 4;
|
|
539
|
+
throw new BaseError("Length is too large.");
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// ../../node_modules/viem/_esm/experimental/eip7702/utils/hashAuthorization.js
|
|
543
|
+
function hashAuthorization(parameters) {
|
|
544
|
+
const { chainId, contractAddress, nonce, to } = parameters;
|
|
545
|
+
const hash = keccak256(concatHex([
|
|
546
|
+
"0x05",
|
|
547
|
+
toRlp([
|
|
548
|
+
chainId ? numberToHex(chainId) : "0x",
|
|
549
|
+
contractAddress,
|
|
550
|
+
nonce ? numberToHex(nonce) : "0x"
|
|
551
|
+
])
|
|
552
|
+
]));
|
|
553
|
+
if (to === "bytes")
|
|
554
|
+
return hexToBytes(hash);
|
|
555
|
+
return hash;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// ../../node_modules/viem/_esm/accounts/utils/signAuthorization.js
|
|
559
|
+
async function experimental_signAuthorization(parameters) {
|
|
560
|
+
const { contractAddress, chainId, nonce, privateKey, to = "object" } = parameters;
|
|
561
|
+
const signature = await sign({
|
|
562
|
+
hash: hashAuthorization({ contractAddress, chainId, nonce }),
|
|
563
|
+
privateKey,
|
|
564
|
+
to
|
|
565
|
+
});
|
|
566
|
+
if (to === "object")
|
|
567
|
+
return {
|
|
568
|
+
contractAddress,
|
|
569
|
+
chainId,
|
|
570
|
+
nonce,
|
|
571
|
+
...signature
|
|
572
|
+
};
|
|
573
|
+
return signature;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// ../../node_modules/viem/_esm/constants/strings.js
|
|
577
|
+
var presignMessagePrefix = "Ethereum Signed Message:\n";
|
|
578
|
+
|
|
579
|
+
// ../../node_modules/viem/_esm/utils/signature/toPrefixedMessage.js
|
|
580
|
+
function toPrefixedMessage(message_) {
|
|
581
|
+
const message = (() => {
|
|
582
|
+
if (typeof message_ === "string")
|
|
583
|
+
return stringToHex(message_);
|
|
584
|
+
if (typeof message_.raw === "string")
|
|
585
|
+
return message_.raw;
|
|
586
|
+
return bytesToHex(message_.raw);
|
|
587
|
+
})();
|
|
588
|
+
const prefix = stringToHex(`${presignMessagePrefix}${size(message)}`);
|
|
589
|
+
return concat([prefix, message]);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// ../../node_modules/viem/_esm/utils/signature/hashMessage.js
|
|
593
|
+
function hashMessage(message, to_) {
|
|
594
|
+
return keccak256(toPrefixedMessage(message), to_);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// ../../node_modules/viem/_esm/accounts/utils/signMessage.js
|
|
598
|
+
async function signMessage({ message, privateKey }) {
|
|
599
|
+
return await sign({ hash: hashMessage(message), privateKey, to: "hex" });
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// ../../node_modules/viem/_esm/utils/blob/blobsToCommitments.js
|
|
603
|
+
function blobsToCommitments(parameters) {
|
|
604
|
+
const { kzg } = parameters;
|
|
605
|
+
const to = parameters.to ?? (typeof parameters.blobs[0] === "string" ? "hex" : "bytes");
|
|
606
|
+
const blobs = typeof parameters.blobs[0] === "string" ? parameters.blobs.map((x) => hexToBytes(x)) : parameters.blobs;
|
|
607
|
+
const commitments = [];
|
|
608
|
+
for (const blob of blobs)
|
|
609
|
+
commitments.push(Uint8Array.from(kzg.blobToKzgCommitment(blob)));
|
|
610
|
+
return to === "bytes" ? commitments : commitments.map((x) => bytesToHex(x));
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
// ../../node_modules/viem/_esm/utils/blob/blobsToProofs.js
|
|
614
|
+
function blobsToProofs(parameters) {
|
|
615
|
+
const { kzg } = parameters;
|
|
616
|
+
const to = parameters.to ?? (typeof parameters.blobs[0] === "string" ? "hex" : "bytes");
|
|
617
|
+
const blobs = typeof parameters.blobs[0] === "string" ? parameters.blobs.map((x) => hexToBytes(x)) : parameters.blobs;
|
|
618
|
+
const commitments = typeof parameters.commitments[0] === "string" ? parameters.commitments.map((x) => hexToBytes(x)) : parameters.commitments;
|
|
619
|
+
const proofs = [];
|
|
620
|
+
for (let i = 0; i < blobs.length; i++) {
|
|
621
|
+
const blob = blobs[i];
|
|
622
|
+
const commitment = commitments[i];
|
|
623
|
+
proofs.push(Uint8Array.from(kzg.computeBlobKzgProof(blob, commitment)));
|
|
624
|
+
}
|
|
625
|
+
return to === "bytes" ? proofs : proofs.map((x) => bytesToHex(x));
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// ../../node_modules/viem/_esm/utils/hash/sha256.js
|
|
629
|
+
function sha2562(value, to_) {
|
|
630
|
+
const to = to_ || "hex";
|
|
631
|
+
const bytes = sha256(isHex(value, { strict: false }) ? toBytes2(value) : value);
|
|
632
|
+
if (to === "bytes")
|
|
633
|
+
return bytes;
|
|
634
|
+
return toHex(bytes);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
// ../../node_modules/viem/_esm/utils/blob/commitmentToVersionedHash.js
|
|
638
|
+
function commitmentToVersionedHash(parameters) {
|
|
639
|
+
const { commitment, version = 1 } = parameters;
|
|
640
|
+
const to = parameters.to ?? (typeof commitment === "string" ? "hex" : "bytes");
|
|
641
|
+
const versionedHash = sha2562(commitment, "bytes");
|
|
642
|
+
versionedHash.set([version], 0);
|
|
643
|
+
return to === "bytes" ? versionedHash : bytesToHex(versionedHash);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
// ../../node_modules/viem/_esm/utils/blob/commitmentsToVersionedHashes.js
|
|
647
|
+
function commitmentsToVersionedHashes(parameters) {
|
|
648
|
+
const { commitments, version } = parameters;
|
|
649
|
+
const to = parameters.to ?? (typeof commitments[0] === "string" ? "hex" : "bytes");
|
|
650
|
+
const hashes = [];
|
|
651
|
+
for (const commitment of commitments) {
|
|
652
|
+
hashes.push(commitmentToVersionedHash({
|
|
653
|
+
commitment,
|
|
654
|
+
to,
|
|
655
|
+
version
|
|
656
|
+
}));
|
|
657
|
+
}
|
|
658
|
+
return hashes;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// ../../node_modules/viem/_esm/constants/blob.js
|
|
662
|
+
var blobsPerTransaction = 6;
|
|
663
|
+
var bytesPerFieldElement = 32;
|
|
664
|
+
var fieldElementsPerBlob = 4096;
|
|
665
|
+
var bytesPerBlob = bytesPerFieldElement * fieldElementsPerBlob;
|
|
666
|
+
var maxBytesPerTransaction = bytesPerBlob * blobsPerTransaction - // terminator byte (0x80).
|
|
667
|
+
1 - // zero byte (0x00) appended to each field element.
|
|
668
|
+
1 * fieldElementsPerBlob * blobsPerTransaction;
|
|
669
|
+
|
|
670
|
+
// ../../node_modules/viem/_esm/constants/kzg.js
|
|
671
|
+
var versionedHashVersionKzg = 1;
|
|
672
|
+
|
|
673
|
+
// ../../node_modules/viem/_esm/errors/blob.js
|
|
674
|
+
var BlobSizeTooLargeError = class extends BaseError {
|
|
675
|
+
constructor({ maxSize, size: size2 }) {
|
|
676
|
+
super("Blob size is too large.", {
|
|
677
|
+
metaMessages: [`Max: ${maxSize} bytes`, `Given: ${size2} bytes`],
|
|
678
|
+
name: "BlobSizeTooLargeError"
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
var EmptyBlobError = class extends BaseError {
|
|
683
|
+
constructor() {
|
|
684
|
+
super("Blob data must not be empty.", { name: "EmptyBlobError" });
|
|
685
|
+
}
|
|
686
|
+
};
|
|
687
|
+
var InvalidVersionedHashSizeError = class extends BaseError {
|
|
688
|
+
constructor({ hash, size: size2 }) {
|
|
689
|
+
super(`Versioned hash "${hash}" size is invalid.`, {
|
|
690
|
+
metaMessages: ["Expected: 32", `Received: ${size2}`],
|
|
691
|
+
name: "InvalidVersionedHashSizeError"
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
var InvalidVersionedHashVersionError = class extends BaseError {
|
|
696
|
+
constructor({ hash, version }) {
|
|
697
|
+
super(`Versioned hash "${hash}" version is invalid.`, {
|
|
698
|
+
metaMessages: [
|
|
699
|
+
`Expected: ${versionedHashVersionKzg}`,
|
|
700
|
+
`Received: ${version}`
|
|
701
|
+
],
|
|
702
|
+
name: "InvalidVersionedHashVersionError"
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
// ../../node_modules/viem/_esm/utils/blob/toBlobs.js
|
|
708
|
+
function toBlobs(parameters) {
|
|
709
|
+
const to = parameters.to ?? (typeof parameters.data === "string" ? "hex" : "bytes");
|
|
710
|
+
const data = typeof parameters.data === "string" ? hexToBytes(parameters.data) : parameters.data;
|
|
711
|
+
const size_ = size(data);
|
|
712
|
+
if (!size_)
|
|
713
|
+
throw new EmptyBlobError();
|
|
714
|
+
if (size_ > maxBytesPerTransaction)
|
|
715
|
+
throw new BlobSizeTooLargeError({
|
|
716
|
+
maxSize: maxBytesPerTransaction,
|
|
717
|
+
size: size_
|
|
718
|
+
});
|
|
719
|
+
const blobs = [];
|
|
720
|
+
let active = true;
|
|
721
|
+
let position = 0;
|
|
722
|
+
while (active) {
|
|
723
|
+
const blob = createCursor(new Uint8Array(bytesPerBlob));
|
|
724
|
+
let size2 = 0;
|
|
725
|
+
while (size2 < fieldElementsPerBlob) {
|
|
726
|
+
const bytes = data.slice(position, position + (bytesPerFieldElement - 1));
|
|
727
|
+
blob.pushByte(0);
|
|
728
|
+
blob.pushBytes(bytes);
|
|
729
|
+
if (bytes.length < 31) {
|
|
730
|
+
blob.pushByte(128);
|
|
731
|
+
active = false;
|
|
732
|
+
break;
|
|
733
|
+
}
|
|
734
|
+
size2++;
|
|
735
|
+
position += 31;
|
|
736
|
+
}
|
|
737
|
+
blobs.push(blob);
|
|
738
|
+
}
|
|
739
|
+
return to === "bytes" ? blobs.map((x) => x.bytes) : blobs.map((x) => bytesToHex(x.bytes));
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// ../../node_modules/viem/_esm/utils/blob/toBlobSidecars.js
|
|
743
|
+
function toBlobSidecars(parameters) {
|
|
744
|
+
const { data, kzg, to } = parameters;
|
|
745
|
+
const blobs = parameters.blobs ?? toBlobs({ data, to });
|
|
746
|
+
const commitments = parameters.commitments ?? blobsToCommitments({ blobs, kzg, to });
|
|
747
|
+
const proofs = parameters.proofs ?? blobsToProofs({ blobs, commitments, kzg, to });
|
|
748
|
+
const sidecars = [];
|
|
749
|
+
for (let i = 0; i < blobs.length; i++)
|
|
750
|
+
sidecars.push({
|
|
751
|
+
blob: blobs[i],
|
|
752
|
+
commitment: commitments[i],
|
|
753
|
+
proof: proofs[i]
|
|
754
|
+
});
|
|
755
|
+
return sidecars;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// ../../node_modules/viem/_esm/experimental/eip7702/utils/serializeAuthorizationList.js
|
|
759
|
+
function serializeAuthorizationList(authorizationList) {
|
|
760
|
+
if (!authorizationList || authorizationList.length === 0)
|
|
761
|
+
return [];
|
|
762
|
+
const serializedAuthorizationList = [];
|
|
763
|
+
for (const authorization of authorizationList) {
|
|
764
|
+
const { contractAddress, chainId, nonce, ...signature } = authorization;
|
|
765
|
+
serializedAuthorizationList.push([
|
|
766
|
+
chainId ? toHex(chainId) : "0x",
|
|
767
|
+
contractAddress,
|
|
768
|
+
nonce ? toHex(nonce) : "0x",
|
|
769
|
+
...toYParitySignatureArray({}, signature)
|
|
770
|
+
]);
|
|
771
|
+
}
|
|
772
|
+
return serializedAuthorizationList;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
// ../../node_modules/viem/_esm/utils/transaction/assertTransaction.js
|
|
776
|
+
function assertTransactionEIP7702(transaction) {
|
|
777
|
+
const { authorizationList } = transaction;
|
|
778
|
+
if (authorizationList) {
|
|
779
|
+
for (const authorization of authorizationList) {
|
|
780
|
+
const { contractAddress, chainId } = authorization;
|
|
781
|
+
if (!isAddress(contractAddress))
|
|
782
|
+
throw new InvalidAddressError({ address: contractAddress });
|
|
783
|
+
if (chainId < 0)
|
|
784
|
+
throw new InvalidChainIdError({ chainId });
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
assertTransactionEIP1559(transaction);
|
|
788
|
+
}
|
|
789
|
+
function assertTransactionEIP4844(transaction) {
|
|
790
|
+
const { blobVersionedHashes } = transaction;
|
|
791
|
+
if (blobVersionedHashes) {
|
|
792
|
+
if (blobVersionedHashes.length === 0)
|
|
793
|
+
throw new EmptyBlobError();
|
|
794
|
+
for (const hash of blobVersionedHashes) {
|
|
795
|
+
const size_ = size(hash);
|
|
796
|
+
const version = hexToNumber(slice(hash, 0, 1));
|
|
797
|
+
if (size_ !== 32)
|
|
798
|
+
throw new InvalidVersionedHashSizeError({ hash, size: size_ });
|
|
799
|
+
if (version !== versionedHashVersionKzg)
|
|
800
|
+
throw new InvalidVersionedHashVersionError({
|
|
801
|
+
hash,
|
|
802
|
+
version
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
assertTransactionEIP1559(transaction);
|
|
807
|
+
}
|
|
808
|
+
function assertTransactionEIP1559(transaction) {
|
|
809
|
+
const { chainId, maxPriorityFeePerGas, maxFeePerGas, to } = transaction;
|
|
810
|
+
if (chainId <= 0)
|
|
811
|
+
throw new InvalidChainIdError({ chainId });
|
|
812
|
+
if (to && !isAddress(to))
|
|
813
|
+
throw new InvalidAddressError({ address: to });
|
|
814
|
+
if (maxFeePerGas && maxFeePerGas > maxUint256)
|
|
815
|
+
throw new FeeCapTooHighError({ maxFeePerGas });
|
|
816
|
+
if (maxPriorityFeePerGas && maxFeePerGas && maxPriorityFeePerGas > maxFeePerGas)
|
|
817
|
+
throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas });
|
|
818
|
+
}
|
|
819
|
+
function assertTransactionEIP2930(transaction) {
|
|
820
|
+
const { chainId, maxPriorityFeePerGas, gasPrice, maxFeePerGas, to } = transaction;
|
|
821
|
+
if (chainId <= 0)
|
|
822
|
+
throw new InvalidChainIdError({ chainId });
|
|
823
|
+
if (to && !isAddress(to))
|
|
824
|
+
throw new InvalidAddressError({ address: to });
|
|
825
|
+
if (maxPriorityFeePerGas || maxFeePerGas)
|
|
826
|
+
throw new BaseError("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");
|
|
827
|
+
if (gasPrice && gasPrice > maxUint256)
|
|
828
|
+
throw new FeeCapTooHighError({ maxFeePerGas: gasPrice });
|
|
829
|
+
}
|
|
830
|
+
function assertTransactionLegacy(transaction) {
|
|
831
|
+
const { chainId, maxPriorityFeePerGas, gasPrice, maxFeePerGas, to } = transaction;
|
|
832
|
+
if (to && !isAddress(to))
|
|
833
|
+
throw new InvalidAddressError({ address: to });
|
|
834
|
+
if (typeof chainId !== "undefined" && chainId <= 0)
|
|
835
|
+
throw new InvalidChainIdError({ chainId });
|
|
836
|
+
if (maxPriorityFeePerGas || maxFeePerGas)
|
|
837
|
+
throw new BaseError("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");
|
|
838
|
+
if (gasPrice && gasPrice > maxUint256)
|
|
839
|
+
throw new FeeCapTooHighError({ maxFeePerGas: gasPrice });
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
// ../../node_modules/viem/_esm/utils/transaction/getTransactionType.js
|
|
843
|
+
function getTransactionType(transaction) {
|
|
844
|
+
if (transaction.type)
|
|
845
|
+
return transaction.type;
|
|
846
|
+
if (typeof transaction.authorizationList !== "undefined")
|
|
847
|
+
return "eip7702";
|
|
848
|
+
if (typeof transaction.blobs !== "undefined" || typeof transaction.blobVersionedHashes !== "undefined" || typeof transaction.maxFeePerBlobGas !== "undefined" || typeof transaction.sidecars !== "undefined")
|
|
849
|
+
return "eip4844";
|
|
850
|
+
if (typeof transaction.maxFeePerGas !== "undefined" || typeof transaction.maxPriorityFeePerGas !== "undefined") {
|
|
851
|
+
return "eip1559";
|
|
852
|
+
}
|
|
853
|
+
if (typeof transaction.gasPrice !== "undefined") {
|
|
854
|
+
if (typeof transaction.accessList !== "undefined")
|
|
855
|
+
return "eip2930";
|
|
856
|
+
return "legacy";
|
|
857
|
+
}
|
|
858
|
+
throw new InvalidSerializableTransactionError({ transaction });
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
// ../../node_modules/viem/_esm/utils/transaction/serializeAccessList.js
|
|
862
|
+
function serializeAccessList(accessList) {
|
|
863
|
+
if (!accessList || accessList.length === 0)
|
|
864
|
+
return [];
|
|
865
|
+
const serializedAccessList = [];
|
|
866
|
+
for (let i = 0; i < accessList.length; i++) {
|
|
867
|
+
const { address, storageKeys } = accessList[i];
|
|
868
|
+
for (let j = 0; j < storageKeys.length; j++) {
|
|
869
|
+
if (storageKeys[j].length - 2 !== 64) {
|
|
870
|
+
throw new InvalidStorageKeySizeError({ storageKey: storageKeys[j] });
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
if (!isAddress(address, { strict: false })) {
|
|
874
|
+
throw new InvalidAddressError({ address });
|
|
875
|
+
}
|
|
876
|
+
serializedAccessList.push([address, storageKeys]);
|
|
877
|
+
}
|
|
878
|
+
return serializedAccessList;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
// ../../node_modules/viem/_esm/utils/transaction/serializeTransaction.js
|
|
882
|
+
function serializeTransaction(transaction, signature) {
|
|
883
|
+
const type = getTransactionType(transaction);
|
|
884
|
+
if (type === "eip1559")
|
|
885
|
+
return serializeTransactionEIP1559(transaction, signature);
|
|
886
|
+
if (type === "eip2930")
|
|
887
|
+
return serializeTransactionEIP2930(transaction, signature);
|
|
888
|
+
if (type === "eip4844")
|
|
889
|
+
return serializeTransactionEIP4844(transaction, signature);
|
|
890
|
+
if (type === "eip7702")
|
|
891
|
+
return serializeTransactionEIP7702(transaction, signature);
|
|
892
|
+
return serializeTransactionLegacy(transaction, signature);
|
|
893
|
+
}
|
|
894
|
+
function serializeTransactionEIP7702(transaction, signature) {
|
|
895
|
+
const { authorizationList, chainId, gas, nonce, to, value, maxFeePerGas, maxPriorityFeePerGas, accessList, data } = transaction;
|
|
896
|
+
assertTransactionEIP7702(transaction);
|
|
897
|
+
const serializedAccessList = serializeAccessList(accessList);
|
|
898
|
+
const serializedAuthorizationList = serializeAuthorizationList(authorizationList);
|
|
899
|
+
return concatHex([
|
|
900
|
+
"0x04",
|
|
901
|
+
toRlp([
|
|
902
|
+
toHex(chainId),
|
|
903
|
+
nonce ? toHex(nonce) : "0x",
|
|
904
|
+
maxPriorityFeePerGas ? toHex(maxPriorityFeePerGas) : "0x",
|
|
905
|
+
maxFeePerGas ? toHex(maxFeePerGas) : "0x",
|
|
906
|
+
gas ? toHex(gas) : "0x",
|
|
907
|
+
to ?? "0x",
|
|
908
|
+
value ? toHex(value) : "0x",
|
|
909
|
+
data ?? "0x",
|
|
910
|
+
serializedAccessList,
|
|
911
|
+
serializedAuthorizationList,
|
|
912
|
+
...toYParitySignatureArray(transaction, signature)
|
|
913
|
+
])
|
|
914
|
+
]);
|
|
915
|
+
}
|
|
916
|
+
function serializeTransactionEIP4844(transaction, signature) {
|
|
917
|
+
const { chainId, gas, nonce, to, value, maxFeePerBlobGas, maxFeePerGas, maxPriorityFeePerGas, accessList, data } = transaction;
|
|
918
|
+
assertTransactionEIP4844(transaction);
|
|
919
|
+
let blobVersionedHashes = transaction.blobVersionedHashes;
|
|
920
|
+
let sidecars = transaction.sidecars;
|
|
921
|
+
if (transaction.blobs && (typeof blobVersionedHashes === "undefined" || typeof sidecars === "undefined")) {
|
|
922
|
+
const blobs2 = typeof transaction.blobs[0] === "string" ? transaction.blobs : transaction.blobs.map((x) => bytesToHex(x));
|
|
923
|
+
const kzg = transaction.kzg;
|
|
924
|
+
const commitments2 = blobsToCommitments({
|
|
925
|
+
blobs: blobs2,
|
|
926
|
+
kzg
|
|
927
|
+
});
|
|
928
|
+
if (typeof blobVersionedHashes === "undefined")
|
|
929
|
+
blobVersionedHashes = commitmentsToVersionedHashes({
|
|
930
|
+
commitments: commitments2
|
|
931
|
+
});
|
|
932
|
+
if (typeof sidecars === "undefined") {
|
|
933
|
+
const proofs2 = blobsToProofs({ blobs: blobs2, commitments: commitments2, kzg });
|
|
934
|
+
sidecars = toBlobSidecars({ blobs: blobs2, commitments: commitments2, proofs: proofs2 });
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
const serializedAccessList = serializeAccessList(accessList);
|
|
938
|
+
const serializedTransaction = [
|
|
939
|
+
toHex(chainId),
|
|
940
|
+
nonce ? toHex(nonce) : "0x",
|
|
941
|
+
maxPriorityFeePerGas ? toHex(maxPriorityFeePerGas) : "0x",
|
|
942
|
+
maxFeePerGas ? toHex(maxFeePerGas) : "0x",
|
|
943
|
+
gas ? toHex(gas) : "0x",
|
|
944
|
+
to ?? "0x",
|
|
945
|
+
value ? toHex(value) : "0x",
|
|
946
|
+
data ?? "0x",
|
|
947
|
+
serializedAccessList,
|
|
948
|
+
maxFeePerBlobGas ? toHex(maxFeePerBlobGas) : "0x",
|
|
949
|
+
blobVersionedHashes ?? [],
|
|
950
|
+
...toYParitySignatureArray(transaction, signature)
|
|
951
|
+
];
|
|
952
|
+
const blobs = [];
|
|
953
|
+
const commitments = [];
|
|
954
|
+
const proofs = [];
|
|
955
|
+
if (sidecars)
|
|
956
|
+
for (let i = 0; i < sidecars.length; i++) {
|
|
957
|
+
const { blob, commitment, proof } = sidecars[i];
|
|
958
|
+
blobs.push(blob);
|
|
959
|
+
commitments.push(commitment);
|
|
960
|
+
proofs.push(proof);
|
|
961
|
+
}
|
|
962
|
+
return concatHex([
|
|
963
|
+
"0x03",
|
|
964
|
+
sidecars ? (
|
|
965
|
+
// If sidecars are enabled, envelope turns into a "wrapper":
|
|
966
|
+
toRlp([serializedTransaction, blobs, commitments, proofs])
|
|
967
|
+
) : (
|
|
968
|
+
// If sidecars are disabled, standard envelope is used:
|
|
969
|
+
toRlp(serializedTransaction)
|
|
970
|
+
)
|
|
971
|
+
]);
|
|
972
|
+
}
|
|
973
|
+
function serializeTransactionEIP1559(transaction, signature) {
|
|
974
|
+
const { chainId, gas, nonce, to, value, maxFeePerGas, maxPriorityFeePerGas, accessList, data } = transaction;
|
|
975
|
+
assertTransactionEIP1559(transaction);
|
|
976
|
+
const serializedAccessList = serializeAccessList(accessList);
|
|
977
|
+
const serializedTransaction = [
|
|
978
|
+
toHex(chainId),
|
|
979
|
+
nonce ? toHex(nonce) : "0x",
|
|
980
|
+
maxPriorityFeePerGas ? toHex(maxPriorityFeePerGas) : "0x",
|
|
981
|
+
maxFeePerGas ? toHex(maxFeePerGas) : "0x",
|
|
982
|
+
gas ? toHex(gas) : "0x",
|
|
983
|
+
to ?? "0x",
|
|
984
|
+
value ? toHex(value) : "0x",
|
|
985
|
+
data ?? "0x",
|
|
986
|
+
serializedAccessList,
|
|
987
|
+
...toYParitySignatureArray(transaction, signature)
|
|
988
|
+
];
|
|
989
|
+
return concatHex([
|
|
990
|
+
"0x02",
|
|
991
|
+
toRlp(serializedTransaction)
|
|
992
|
+
]);
|
|
993
|
+
}
|
|
994
|
+
function serializeTransactionEIP2930(transaction, signature) {
|
|
995
|
+
const { chainId, gas, data, nonce, to, value, accessList, gasPrice } = transaction;
|
|
996
|
+
assertTransactionEIP2930(transaction);
|
|
997
|
+
const serializedAccessList = serializeAccessList(accessList);
|
|
998
|
+
const serializedTransaction = [
|
|
999
|
+
toHex(chainId),
|
|
1000
|
+
nonce ? toHex(nonce) : "0x",
|
|
1001
|
+
gasPrice ? toHex(gasPrice) : "0x",
|
|
1002
|
+
gas ? toHex(gas) : "0x",
|
|
1003
|
+
to ?? "0x",
|
|
1004
|
+
value ? toHex(value) : "0x",
|
|
1005
|
+
data ?? "0x",
|
|
1006
|
+
serializedAccessList,
|
|
1007
|
+
...toYParitySignatureArray(transaction, signature)
|
|
1008
|
+
];
|
|
1009
|
+
return concatHex([
|
|
1010
|
+
"0x01",
|
|
1011
|
+
toRlp(serializedTransaction)
|
|
1012
|
+
]);
|
|
1013
|
+
}
|
|
1014
|
+
function serializeTransactionLegacy(transaction, signature) {
|
|
1015
|
+
const { chainId = 0, gas, data, nonce, to, value, gasPrice } = transaction;
|
|
1016
|
+
assertTransactionLegacy(transaction);
|
|
1017
|
+
let serializedTransaction = [
|
|
1018
|
+
nonce ? toHex(nonce) : "0x",
|
|
1019
|
+
gasPrice ? toHex(gasPrice) : "0x",
|
|
1020
|
+
gas ? toHex(gas) : "0x",
|
|
1021
|
+
to ?? "0x",
|
|
1022
|
+
value ? toHex(value) : "0x",
|
|
1023
|
+
data ?? "0x"
|
|
1024
|
+
];
|
|
1025
|
+
if (signature) {
|
|
1026
|
+
const v = (() => {
|
|
1027
|
+
if (signature.v >= 35n) {
|
|
1028
|
+
const inferredChainId = (signature.v - 35n) / 2n;
|
|
1029
|
+
if (inferredChainId > 0)
|
|
1030
|
+
return signature.v;
|
|
1031
|
+
return 27n + (signature.v === 35n ? 0n : 1n);
|
|
1032
|
+
}
|
|
1033
|
+
if (chainId > 0)
|
|
1034
|
+
return BigInt(chainId * 2) + BigInt(35n + signature.v - 27n);
|
|
1035
|
+
const v2 = 27n + (signature.v === 27n ? 0n : 1n);
|
|
1036
|
+
if (signature.v !== v2)
|
|
1037
|
+
throw new InvalidLegacyVError({ v: signature.v });
|
|
1038
|
+
return v2;
|
|
1039
|
+
})();
|
|
1040
|
+
const r = trim(signature.r);
|
|
1041
|
+
const s = trim(signature.s);
|
|
1042
|
+
serializedTransaction = [
|
|
1043
|
+
...serializedTransaction,
|
|
1044
|
+
toHex(v),
|
|
1045
|
+
r === "0x00" ? "0x" : r,
|
|
1046
|
+
s === "0x00" ? "0x" : s
|
|
1047
|
+
];
|
|
1048
|
+
} else if (chainId > 0) {
|
|
1049
|
+
serializedTransaction = [
|
|
1050
|
+
...serializedTransaction,
|
|
1051
|
+
toHex(chainId),
|
|
1052
|
+
"0x",
|
|
1053
|
+
"0x"
|
|
1054
|
+
];
|
|
1055
|
+
}
|
|
1056
|
+
return toRlp(serializedTransaction);
|
|
1057
|
+
}
|
|
1058
|
+
function toYParitySignatureArray(transaction, signature_) {
|
|
1059
|
+
const signature = signature_ ?? transaction;
|
|
1060
|
+
const { v, yParity } = signature;
|
|
1061
|
+
if (typeof signature.r === "undefined")
|
|
1062
|
+
return [];
|
|
1063
|
+
if (typeof signature.s === "undefined")
|
|
1064
|
+
return [];
|
|
1065
|
+
if (typeof v === "undefined" && typeof yParity === "undefined")
|
|
1066
|
+
return [];
|
|
1067
|
+
const r = trim(signature.r);
|
|
1068
|
+
const s = trim(signature.s);
|
|
1069
|
+
const yParity_ = (() => {
|
|
1070
|
+
if (typeof yParity === "number")
|
|
1071
|
+
return yParity ? toHex(1) : "0x";
|
|
1072
|
+
if (v === 0n)
|
|
1073
|
+
return "0x";
|
|
1074
|
+
if (v === 1n)
|
|
1075
|
+
return toHex(1);
|
|
1076
|
+
return v === 27n ? "0x" : toHex(1);
|
|
1077
|
+
})();
|
|
1078
|
+
return [yParity_, r === "0x00" ? "0x" : r, s === "0x00" ? "0x" : s];
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
// ../../node_modules/viem/_esm/accounts/utils/signTransaction.js
|
|
1082
|
+
async function signTransaction(parameters) {
|
|
1083
|
+
const { privateKey, transaction, serializer = serializeTransaction } = parameters;
|
|
1084
|
+
const signableTransaction = (() => {
|
|
1085
|
+
if (transaction.type === "eip4844")
|
|
1086
|
+
return {
|
|
1087
|
+
...transaction,
|
|
1088
|
+
sidecars: false
|
|
1089
|
+
};
|
|
1090
|
+
return transaction;
|
|
1091
|
+
})();
|
|
1092
|
+
const signature = await sign({
|
|
1093
|
+
hash: keccak256(serializer(signableTransaction)),
|
|
1094
|
+
privateKey
|
|
1095
|
+
});
|
|
1096
|
+
return serializer(transaction, signature);
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
// ../../node_modules/viem/_esm/errors/typedData.js
|
|
1100
|
+
var InvalidDomainError = class extends BaseError {
|
|
1101
|
+
constructor({ domain }) {
|
|
1102
|
+
super(`Invalid domain "${stringify(domain)}".`, {
|
|
1103
|
+
metaMessages: ["Must be a valid EIP-712 domain."]
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
};
|
|
1107
|
+
var InvalidPrimaryTypeError = class extends BaseError {
|
|
1108
|
+
constructor({ primaryType, types }) {
|
|
1109
|
+
super(`Invalid primary type \`${primaryType}\` must be one of \`${JSON.stringify(Object.keys(types))}\`.`, {
|
|
1110
|
+
docsPath: "/api/glossary/Errors#typeddatainvalidprimarytypeerror",
|
|
1111
|
+
metaMessages: ["Check that the primary type is a key in `types`."]
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
};
|
|
1115
|
+
var InvalidStructTypeError = class extends BaseError {
|
|
1116
|
+
constructor({ type }) {
|
|
1117
|
+
super(`Struct type "${type}" is invalid.`, {
|
|
1118
|
+
metaMessages: ["Struct type must not be a Solidity type."],
|
|
1119
|
+
name: "InvalidStructTypeError"
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
};
|
|
1123
|
+
|
|
1124
|
+
// ../../node_modules/viem/_esm/utils/typedData.js
|
|
1125
|
+
function validateTypedData(parameters) {
|
|
1126
|
+
const { domain, message, primaryType, types } = parameters;
|
|
1127
|
+
const validateData = (struct, data) => {
|
|
1128
|
+
for (const param of struct) {
|
|
1129
|
+
const { name, type } = param;
|
|
1130
|
+
const value = data[name];
|
|
1131
|
+
const integerMatch = type.match(integerRegex);
|
|
1132
|
+
if (integerMatch && (typeof value === "number" || typeof value === "bigint")) {
|
|
1133
|
+
const [_type, base, size_] = integerMatch;
|
|
1134
|
+
numberToHex(value, {
|
|
1135
|
+
signed: base === "int",
|
|
1136
|
+
size: Number.parseInt(size_) / 8
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
if (type === "address" && typeof value === "string" && !isAddress(value))
|
|
1140
|
+
throw new InvalidAddressError({ address: value });
|
|
1141
|
+
const bytesMatch = type.match(bytesRegex);
|
|
1142
|
+
if (bytesMatch) {
|
|
1143
|
+
const [_type, size_] = bytesMatch;
|
|
1144
|
+
if (size_ && size(value) !== Number.parseInt(size_))
|
|
1145
|
+
throw new BytesSizeMismatchError({
|
|
1146
|
+
expectedSize: Number.parseInt(size_),
|
|
1147
|
+
givenSize: size(value)
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
const struct2 = types[type];
|
|
1151
|
+
if (struct2) {
|
|
1152
|
+
validateReference(type);
|
|
1153
|
+
validateData(struct2, value);
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
};
|
|
1157
|
+
if (types.EIP712Domain && domain) {
|
|
1158
|
+
if (typeof domain !== "object")
|
|
1159
|
+
throw new InvalidDomainError({ domain });
|
|
1160
|
+
validateData(types.EIP712Domain, domain);
|
|
1161
|
+
}
|
|
1162
|
+
if (primaryType !== "EIP712Domain") {
|
|
1163
|
+
if (types[primaryType])
|
|
1164
|
+
validateData(types[primaryType], message);
|
|
1165
|
+
else
|
|
1166
|
+
throw new InvalidPrimaryTypeError({ primaryType, types });
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
function getTypesForEIP712Domain({ domain }) {
|
|
1170
|
+
return [
|
|
1171
|
+
typeof domain?.name === "string" && { name: "name", type: "string" },
|
|
1172
|
+
domain?.version && { name: "version", type: "string" },
|
|
1173
|
+
typeof domain?.chainId === "number" && {
|
|
1174
|
+
name: "chainId",
|
|
1175
|
+
type: "uint256"
|
|
1176
|
+
},
|
|
1177
|
+
domain?.verifyingContract && {
|
|
1178
|
+
name: "verifyingContract",
|
|
1179
|
+
type: "address"
|
|
1180
|
+
},
|
|
1181
|
+
domain?.salt && { name: "salt", type: "bytes32" }
|
|
1182
|
+
].filter(Boolean);
|
|
1183
|
+
}
|
|
1184
|
+
function validateReference(type) {
|
|
1185
|
+
if (type === "address" || type === "bool" || type === "string" || type.startsWith("bytes") || type.startsWith("uint") || type.startsWith("int"))
|
|
1186
|
+
throw new InvalidStructTypeError({ type });
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
// ../../node_modules/viem/_esm/utils/signature/hashTypedData.js
|
|
1190
|
+
function hashTypedData(parameters) {
|
|
1191
|
+
const { domain = {}, message, primaryType } = parameters;
|
|
1192
|
+
const types = {
|
|
1193
|
+
EIP712Domain: getTypesForEIP712Domain({ domain }),
|
|
1194
|
+
...parameters.types
|
|
1195
|
+
};
|
|
1196
|
+
validateTypedData({
|
|
1197
|
+
domain,
|
|
1198
|
+
message,
|
|
1199
|
+
primaryType,
|
|
1200
|
+
types
|
|
1201
|
+
});
|
|
1202
|
+
const parts = ["0x1901"];
|
|
1203
|
+
if (domain)
|
|
1204
|
+
parts.push(hashDomain({
|
|
1205
|
+
domain,
|
|
1206
|
+
types
|
|
1207
|
+
}));
|
|
1208
|
+
if (primaryType !== "EIP712Domain")
|
|
1209
|
+
parts.push(hashStruct({
|
|
1210
|
+
data: message,
|
|
1211
|
+
primaryType,
|
|
1212
|
+
types
|
|
1213
|
+
}));
|
|
1214
|
+
return keccak256(concat(parts));
|
|
1215
|
+
}
|
|
1216
|
+
function hashDomain({ domain, types }) {
|
|
1217
|
+
return hashStruct({
|
|
1218
|
+
data: domain,
|
|
1219
|
+
primaryType: "EIP712Domain",
|
|
1220
|
+
types
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
function hashStruct({ data, primaryType, types }) {
|
|
1224
|
+
const encoded = encodeData({
|
|
1225
|
+
data,
|
|
1226
|
+
primaryType,
|
|
1227
|
+
types
|
|
1228
|
+
});
|
|
1229
|
+
return keccak256(encoded);
|
|
1230
|
+
}
|
|
1231
|
+
function encodeData({ data, primaryType, types }) {
|
|
1232
|
+
const encodedTypes = [{ type: "bytes32" }];
|
|
1233
|
+
const encodedValues = [hashType({ primaryType, types })];
|
|
1234
|
+
for (const field of types[primaryType]) {
|
|
1235
|
+
const [type, value] = encodeField({
|
|
1236
|
+
types,
|
|
1237
|
+
name: field.name,
|
|
1238
|
+
type: field.type,
|
|
1239
|
+
value: data[field.name]
|
|
1240
|
+
});
|
|
1241
|
+
encodedTypes.push(type);
|
|
1242
|
+
encodedValues.push(value);
|
|
1243
|
+
}
|
|
1244
|
+
return encodeAbiParameters(encodedTypes, encodedValues);
|
|
1245
|
+
}
|
|
1246
|
+
function hashType({ primaryType, types }) {
|
|
1247
|
+
const encodedHashType = toHex(encodeType({ primaryType, types }));
|
|
1248
|
+
return keccak256(encodedHashType);
|
|
1249
|
+
}
|
|
1250
|
+
function encodeType({ primaryType, types }) {
|
|
1251
|
+
let result = "";
|
|
1252
|
+
const unsortedDeps = findTypeDependencies({ primaryType, types });
|
|
1253
|
+
unsortedDeps.delete(primaryType);
|
|
1254
|
+
const deps = [primaryType, ...Array.from(unsortedDeps).sort()];
|
|
1255
|
+
for (const type of deps) {
|
|
1256
|
+
result += `${type}(${types[type].map(({ name, type: t }) => `${t} ${name}`).join(",")})`;
|
|
1257
|
+
}
|
|
1258
|
+
return result;
|
|
1259
|
+
}
|
|
1260
|
+
function findTypeDependencies({ primaryType: primaryType_, types }, results = /* @__PURE__ */ new Set()) {
|
|
1261
|
+
const match = primaryType_.match(/^\w*/u);
|
|
1262
|
+
const primaryType = match?.[0];
|
|
1263
|
+
if (results.has(primaryType) || types[primaryType] === void 0) {
|
|
1264
|
+
return results;
|
|
1265
|
+
}
|
|
1266
|
+
results.add(primaryType);
|
|
1267
|
+
for (const field of types[primaryType]) {
|
|
1268
|
+
findTypeDependencies({ primaryType: field.type, types }, results);
|
|
1269
|
+
}
|
|
1270
|
+
return results;
|
|
1271
|
+
}
|
|
1272
|
+
function encodeField({ types, name, type, value }) {
|
|
1273
|
+
if (types[type] !== void 0) {
|
|
1274
|
+
return [
|
|
1275
|
+
{ type: "bytes32" },
|
|
1276
|
+
keccak256(encodeData({ data: value, primaryType: type, types }))
|
|
1277
|
+
];
|
|
1278
|
+
}
|
|
1279
|
+
if (type === "bytes") {
|
|
1280
|
+
const prepend = value.length % 2 ? "0" : "";
|
|
1281
|
+
value = `0x${prepend + value.slice(2)}`;
|
|
1282
|
+
return [{ type: "bytes32" }, keccak256(value)];
|
|
1283
|
+
}
|
|
1284
|
+
if (type === "string")
|
|
1285
|
+
return [{ type: "bytes32" }, keccak256(toHex(value))];
|
|
1286
|
+
if (type.lastIndexOf("]") === type.length - 1) {
|
|
1287
|
+
const parsedType = type.slice(0, type.lastIndexOf("["));
|
|
1288
|
+
const typeValuePairs = value.map((item) => encodeField({
|
|
1289
|
+
name,
|
|
1290
|
+
type: parsedType,
|
|
1291
|
+
types,
|
|
1292
|
+
value: item
|
|
1293
|
+
}));
|
|
1294
|
+
return [
|
|
1295
|
+
{ type: "bytes32" },
|
|
1296
|
+
keccak256(encodeAbiParameters(typeValuePairs.map(([t]) => t), typeValuePairs.map(([, v]) => v)))
|
|
1297
|
+
];
|
|
1298
|
+
}
|
|
1299
|
+
return [{ type }, value];
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
// ../../node_modules/viem/_esm/accounts/utils/signTypedData.js
|
|
1303
|
+
async function signTypedData(parameters) {
|
|
1304
|
+
const { privateKey, ...typedData } = parameters;
|
|
1305
|
+
return await sign({
|
|
1306
|
+
hash: hashTypedData(typedData),
|
|
1307
|
+
privateKey,
|
|
1308
|
+
to: "hex"
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
// ../../node_modules/viem/_esm/accounts/privateKeyToAccount.js
|
|
1313
|
+
function privateKeyToAccount(privateKey, options = {}) {
|
|
1314
|
+
const { nonceManager } = options;
|
|
1315
|
+
const publicKey = toHex(secp256k1.getPublicKey(privateKey.slice(2), false));
|
|
1316
|
+
const address = publicKeyToAddress(publicKey);
|
|
1317
|
+
const account = toAccount({
|
|
1318
|
+
address,
|
|
1319
|
+
nonceManager,
|
|
1320
|
+
async sign({ hash }) {
|
|
1321
|
+
return sign({ hash, privateKey, to: "hex" });
|
|
1322
|
+
},
|
|
1323
|
+
async experimental_signAuthorization(authorization) {
|
|
1324
|
+
return experimental_signAuthorization({ ...authorization, privateKey });
|
|
1325
|
+
},
|
|
1326
|
+
async signMessage({ message }) {
|
|
1327
|
+
return signMessage({ message, privateKey });
|
|
1328
|
+
},
|
|
1329
|
+
async signTransaction(transaction, { serializer } = {}) {
|
|
1330
|
+
return signTransaction({ privateKey, transaction, serializer });
|
|
1331
|
+
},
|
|
1332
|
+
async signTypedData(typedData) {
|
|
1333
|
+
return signTypedData({ ...typedData, privateKey });
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1336
|
+
return {
|
|
1337
|
+
...account,
|
|
1338
|
+
publicKey,
|
|
1339
|
+
source: "privateKey"
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
// src/providers/deriveKeyProvider.ts
|
|
93
1344
|
var DeriveKeyProvider = class {
|
|
94
1345
|
client;
|
|
95
1346
|
raProvider;
|