@0xpolygonid/js-sdk 1.17.1 → 1.17.2

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.
@@ -4,7 +4,7 @@ export { jsIden3Core as core };
4
4
  import { Path, Merklizer, getDocumentLoader } from '@iden3/js-jsonld-merklization';
5
5
  import * as jsJsonldMerklization from '@iden3/js-jsonld-merklization';
6
6
  export { jsJsonldMerklization as jsonLDMerklizer };
7
- import { base58ToBytes as base58ToBytes$2, base58FromBytes, Hex, PrivateKey, PublicKey, Signature as Signature$1, sha256 as sha256$3, poseidon, getRandomBytes, Poseidon } from '@iden3/js-crypto';
7
+ import { base58ToBytes as base58ToBytes$2, base58FromBytes, Hex, PrivateKey, PublicKey, Signature as Signature$1, sha256 as sha256$4, poseidon, getRandomBytes, Poseidon } from '@iden3/js-crypto';
8
8
  import { Hash as Hash$2, Proof, verifyProof, rootFromProof, ZERO_HASH, swapEndianness as swapEndianness$1, Merkletree, InMemoryDB, str2Bytes, LocalStorageDB, IndexedDBStorage, testBit, NodeLeaf, NODE_TYPE_LEAF, hashElems } from '@iden3/js-merkletree';
9
9
  import { groth16 } from 'snarkjs';
10
10
  import { getCurveFromName } from 'ffjavascript';
@@ -2129,19 +2129,19 @@ function split$2(lst, le = false) {
2129
2129
  }
2130
2130
  return [Ah, Al];
2131
2131
  }
2132
- const toBig = (h, l) => (BigInt(h >>> 0) << _32n$1) | BigInt(l >>> 0);
2132
+ const toBig$1 = (h, l) => (BigInt(h >>> 0) << _32n$1) | BigInt(l >>> 0);
2133
2133
  // for Shift in [0, 32)
2134
- const shrSH = (h, _l, s) => h >>> s;
2135
- const shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
2134
+ const shrSH$1 = (h, _l, s) => h >>> s;
2135
+ const shrSL$1 = (h, l, s) => (h << (32 - s)) | (l >>> s);
2136
2136
  // Right rotate for Shift in [1, 32)
2137
- const rotrSH = (h, l, s) => (h >>> s) | (l << (32 - s));
2138
- const rotrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
2137
+ const rotrSH$1 = (h, l, s) => (h >>> s) | (l << (32 - s));
2138
+ const rotrSL$1 = (h, l, s) => (h << (32 - s)) | (l >>> s);
2139
2139
  // Right rotate for Shift in (32, 64), NOTE: 32 is special case.
2140
- const rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));
2141
- const rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));
2140
+ const rotrBH$1 = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));
2141
+ const rotrBL$1 = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));
2142
2142
  // Right rotate for shift===32 (just swaps l&h)
2143
- const rotr32H = (_h, l) => l;
2144
- const rotr32L = (h, _l) => h;
2143
+ const rotr32H$1 = (_h, l) => l;
2144
+ const rotr32L$1 = (h, _l) => h;
2145
2145
  // Left rotate for Shift in [1, 32)
2146
2146
  const rotlSH$1 = (h, l, s) => (h << s) | (l >>> (32 - s));
2147
2147
  const rotlSL$1 = (h, l, s) => (l << s) | (h >>> (32 - s));
@@ -2150,30 +2150,30 @@ const rotlBH$1 = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s));
2150
2150
  const rotlBL$1 = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));
2151
2151
  // JS uses 32-bit signed integers for bitwise operations which means we cannot
2152
2152
  // simple take carry out of low bit sum by shift, we need to use division.
2153
- function add(Ah, Al, Bh, Bl) {
2153
+ function add$1(Ah, Al, Bh, Bl) {
2154
2154
  const l = (Al >>> 0) + (Bl >>> 0);
2155
2155
  return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };
2156
2156
  }
2157
2157
  // Addition with more than 2 elements
2158
- const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
2159
- const add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
2160
- const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
2161
- const add4H = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;
2162
- const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
2163
- const add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;
2158
+ const add3L$1 = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
2159
+ const add3H$1 = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
2160
+ const add4L$1 = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
2161
+ const add4H$1 = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;
2162
+ const add5L$1 = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
2163
+ const add5H$1 = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;
2164
2164
  // prettier-ignore
2165
- const u64 = {
2166
- fromBig: fromBig$1, split: split$2, toBig,
2167
- shrSH, shrSL,
2168
- rotrSH, rotrSL, rotrBH, rotrBL,
2169
- rotr32H, rotr32L,
2165
+ const u64$1 = {
2166
+ fromBig: fromBig$1, split: split$2, toBig: toBig$1,
2167
+ shrSH: shrSH$1, shrSL: shrSL$1,
2168
+ rotrSH: rotrSH$1, rotrSL: rotrSL$1, rotrBH: rotrBH$1, rotrBL: rotrBL$1,
2169
+ rotr32H: rotr32H$1, rotr32L: rotr32L$1,
2170
2170
  rotlSH: rotlSH$1, rotlSL: rotlSL$1, rotlBH: rotlBH$1, rotlBL: rotlBL$1,
2171
- add, add3L, add3H, add4L, add4H, add5H, add5L,
2171
+ add: add$1, add3L: add3L$1, add3H: add3H$1, add4L: add4L$1, add4H: add4H$1, add5H: add5H$1, add5L: add5L$1,
2172
2172
  };
2173
2173
 
2174
2174
  // Round contants (first 32 bits of the fractional parts of the cube roots of the first 80 primes 2..409):
2175
2175
  // prettier-ignore
2176
- const [SHA512_Kh, SHA512_Kl] = /* @__PURE__ */ (() => u64.split([
2176
+ const [SHA512_Kh$1, SHA512_Kl$1] = /* @__PURE__ */ (() => u64$1.split([
2177
2177
  '0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc',
2178
2178
  '0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118',
2179
2179
  '0xd807aa98a3030242', '0x12835b0145706fbe', '0x243185be4ee4b28c', '0x550c7dc3d5ffb4e2',
@@ -2196,9 +2196,9 @@ const [SHA512_Kh, SHA512_Kl] = /* @__PURE__ */ (() => u64.split([
2196
2196
  '0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817'
2197
2197
  ].map(n => BigInt(n))))();
2198
2198
  // Temporary buffer, not used to store anything between runs
2199
- const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
2200
- const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
2201
- class SHA512 extends HashMD {
2199
+ const SHA512_W_H$1 = /* @__PURE__ */ new Uint32Array(80);
2200
+ const SHA512_W_L$1 = /* @__PURE__ */ new Uint32Array(80);
2201
+ let SHA512$1 = class SHA512 extends HashMD {
2202
2202
  constructor() {
2203
2203
  super(128, 64, 16, false);
2204
2204
  // We cannot use array here since array allows indexing by variable which means optimizer/compiler cannot use registers.
@@ -2249,43 +2249,43 @@ class SHA512 extends HashMD {
2249
2249
  process(view, offset) {
2250
2250
  // Extend the first 16 words into the remaining 64 words w[16..79] of the message schedule array
2251
2251
  for (let i = 0; i < 16; i++, offset += 4) {
2252
- SHA512_W_H[i] = view.getUint32(offset);
2253
- SHA512_W_L[i] = view.getUint32((offset += 4));
2252
+ SHA512_W_H$1[i] = view.getUint32(offset);
2253
+ SHA512_W_L$1[i] = view.getUint32((offset += 4));
2254
2254
  }
2255
2255
  for (let i = 16; i < 80; i++) {
2256
2256
  // s0 := (w[i-15] rightrotate 1) xor (w[i-15] rightrotate 8) xor (w[i-15] rightshift 7)
2257
- const W15h = SHA512_W_H[i - 15] | 0;
2258
- const W15l = SHA512_W_L[i - 15] | 0;
2259
- const s0h = u64.rotrSH(W15h, W15l, 1) ^ u64.rotrSH(W15h, W15l, 8) ^ u64.shrSH(W15h, W15l, 7);
2260
- const s0l = u64.rotrSL(W15h, W15l, 1) ^ u64.rotrSL(W15h, W15l, 8) ^ u64.shrSL(W15h, W15l, 7);
2257
+ const W15h = SHA512_W_H$1[i - 15] | 0;
2258
+ const W15l = SHA512_W_L$1[i - 15] | 0;
2259
+ const s0h = u64$1.rotrSH(W15h, W15l, 1) ^ u64$1.rotrSH(W15h, W15l, 8) ^ u64$1.shrSH(W15h, W15l, 7);
2260
+ const s0l = u64$1.rotrSL(W15h, W15l, 1) ^ u64$1.rotrSL(W15h, W15l, 8) ^ u64$1.shrSL(W15h, W15l, 7);
2261
2261
  // s1 := (w[i-2] rightrotate 19) xor (w[i-2] rightrotate 61) xor (w[i-2] rightshift 6)
2262
- const W2h = SHA512_W_H[i - 2] | 0;
2263
- const W2l = SHA512_W_L[i - 2] | 0;
2264
- const s1h = u64.rotrSH(W2h, W2l, 19) ^ u64.rotrBH(W2h, W2l, 61) ^ u64.shrSH(W2h, W2l, 6);
2265
- const s1l = u64.rotrSL(W2h, W2l, 19) ^ u64.rotrBL(W2h, W2l, 61) ^ u64.shrSL(W2h, W2l, 6);
2262
+ const W2h = SHA512_W_H$1[i - 2] | 0;
2263
+ const W2l = SHA512_W_L$1[i - 2] | 0;
2264
+ const s1h = u64$1.rotrSH(W2h, W2l, 19) ^ u64$1.rotrBH(W2h, W2l, 61) ^ u64$1.shrSH(W2h, W2l, 6);
2265
+ const s1l = u64$1.rotrSL(W2h, W2l, 19) ^ u64$1.rotrBL(W2h, W2l, 61) ^ u64$1.shrSL(W2h, W2l, 6);
2266
2266
  // SHA256_W[i] = s0 + s1 + SHA256_W[i - 7] + SHA256_W[i - 16];
2267
- const SUMl = u64.add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
2268
- const SUMh = u64.add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
2269
- SHA512_W_H[i] = SUMh | 0;
2270
- SHA512_W_L[i] = SUMl | 0;
2267
+ const SUMl = u64$1.add4L(s0l, s1l, SHA512_W_L$1[i - 7], SHA512_W_L$1[i - 16]);
2268
+ const SUMh = u64$1.add4H(SUMl, s0h, s1h, SHA512_W_H$1[i - 7], SHA512_W_H$1[i - 16]);
2269
+ SHA512_W_H$1[i] = SUMh | 0;
2270
+ SHA512_W_L$1[i] = SUMl | 0;
2271
2271
  }
2272
2272
  let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
2273
2273
  // Compression function main loop, 80 rounds
2274
2274
  for (let i = 0; i < 80; i++) {
2275
2275
  // S1 := (e rightrotate 14) xor (e rightrotate 18) xor (e rightrotate 41)
2276
- const sigma1h = u64.rotrSH(Eh, El, 14) ^ u64.rotrSH(Eh, El, 18) ^ u64.rotrBH(Eh, El, 41);
2277
- const sigma1l = u64.rotrSL(Eh, El, 14) ^ u64.rotrSL(Eh, El, 18) ^ u64.rotrBL(Eh, El, 41);
2276
+ const sigma1h = u64$1.rotrSH(Eh, El, 14) ^ u64$1.rotrSH(Eh, El, 18) ^ u64$1.rotrBH(Eh, El, 41);
2277
+ const sigma1l = u64$1.rotrSL(Eh, El, 14) ^ u64$1.rotrSL(Eh, El, 18) ^ u64$1.rotrBL(Eh, El, 41);
2278
2278
  //const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
2279
2279
  const CHIh = (Eh & Fh) ^ (~Eh & Gh);
2280
2280
  const CHIl = (El & Fl) ^ (~El & Gl);
2281
2281
  // T1 = H + sigma1 + Chi(E, F, G) + SHA512_K[i] + SHA512_W[i]
2282
2282
  // prettier-ignore
2283
- const T1ll = u64.add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
2284
- const T1h = u64.add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
2283
+ const T1ll = u64$1.add5L(Hl, sigma1l, CHIl, SHA512_Kl$1[i], SHA512_W_L$1[i]);
2284
+ const T1h = u64$1.add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh$1[i], SHA512_W_H$1[i]);
2285
2285
  const T1l = T1ll | 0;
2286
2286
  // S0 := (a rightrotate 28) xor (a rightrotate 34) xor (a rightrotate 39)
2287
- const sigma0h = u64.rotrSH(Ah, Al, 28) ^ u64.rotrBH(Ah, Al, 34) ^ u64.rotrBH(Ah, Al, 39);
2288
- const sigma0l = u64.rotrSL(Ah, Al, 28) ^ u64.rotrBL(Ah, Al, 34) ^ u64.rotrBL(Ah, Al, 39);
2287
+ const sigma0h = u64$1.rotrSH(Ah, Al, 28) ^ u64$1.rotrBH(Ah, Al, 34) ^ u64$1.rotrBH(Ah, Al, 39);
2288
+ const sigma0l = u64$1.rotrSL(Ah, Al, 28) ^ u64$1.rotrBL(Ah, Al, 34) ^ u64$1.rotrBL(Ah, Al, 39);
2289
2289
  const MAJh = (Ah & Bh) ^ (Ah & Ch) ^ (Bh & Ch);
2290
2290
  const MAJl = (Al & Bl) ^ (Al & Cl) ^ (Bl & Cl);
2291
2291
  Hh = Gh | 0;
@@ -2294,38 +2294,38 @@ class SHA512 extends HashMD {
2294
2294
  Gl = Fl | 0;
2295
2295
  Fh = Eh | 0;
2296
2296
  Fl = El | 0;
2297
- ({ h: Eh, l: El } = u64.add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
2297
+ ({ h: Eh, l: El } = u64$1.add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
2298
2298
  Dh = Ch | 0;
2299
2299
  Dl = Cl | 0;
2300
2300
  Ch = Bh | 0;
2301
2301
  Cl = Bl | 0;
2302
2302
  Bh = Ah | 0;
2303
2303
  Bl = Al | 0;
2304
- const All = u64.add3L(T1l, sigma0l, MAJl);
2305
- Ah = u64.add3H(All, T1h, sigma0h, MAJh);
2304
+ const All = u64$1.add3L(T1l, sigma0l, MAJl);
2305
+ Ah = u64$1.add3H(All, T1h, sigma0h, MAJh);
2306
2306
  Al = All | 0;
2307
2307
  }
2308
2308
  // Add the compressed chunk to the current hash value
2309
- ({ h: Ah, l: Al } = u64.add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
2310
- ({ h: Bh, l: Bl } = u64.add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
2311
- ({ h: Ch, l: Cl } = u64.add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
2312
- ({ h: Dh, l: Dl } = u64.add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
2313
- ({ h: Eh, l: El } = u64.add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
2314
- ({ h: Fh, l: Fl } = u64.add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
2315
- ({ h: Gh, l: Gl } = u64.add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
2316
- ({ h: Hh, l: Hl } = u64.add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
2309
+ ({ h: Ah, l: Al } = u64$1.add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
2310
+ ({ h: Bh, l: Bl } = u64$1.add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
2311
+ ({ h: Ch, l: Cl } = u64$1.add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
2312
+ ({ h: Dh, l: Dl } = u64$1.add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
2313
+ ({ h: Eh, l: El } = u64$1.add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
2314
+ ({ h: Fh, l: Fl } = u64$1.add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
2315
+ ({ h: Gh, l: Gl } = u64$1.add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
2316
+ ({ h: Hh, l: Hl } = u64$1.add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
2317
2317
  this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
2318
2318
  }
2319
2319
  roundClean() {
2320
- SHA512_W_H.fill(0);
2321
- SHA512_W_L.fill(0);
2320
+ SHA512_W_H$1.fill(0);
2321
+ SHA512_W_L$1.fill(0);
2322
2322
  }
2323
2323
  destroy() {
2324
2324
  this.buffer.fill(0);
2325
2325
  this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
2326
2326
  }
2327
- }
2328
- const sha512 = /* @__PURE__ */ wrapConstructor$1(() => new SHA512());
2327
+ };
2328
+ const sha512$1 = /* @__PURE__ */ wrapConstructor$1(() => new SHA512$1());
2329
2329
 
2330
2330
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2331
2331
  // 100 lines of code in the file are duplicated from noble-hashes (utils).
@@ -3654,7 +3654,7 @@ const ed25519Defaults = {
3654
3654
  // Base point (x, y) aka generator point
3655
3655
  Gx: BigInt('15112221349535400772501151409588531511454012693041857206046113283949847762202'),
3656
3656
  Gy: BigInt('46316835694926478169428394003475163141307993866256225615783033603165251855960'),
3657
- hash: sha512,
3657
+ hash: sha512$1,
3658
3658
  randomBytes: randomBytes$1,
3659
3659
  adjustScalarBytes,
3660
3660
  // dom2
@@ -3871,7 +3871,7 @@ let SHA256$1 = class SHA256 extends HashMD {
3871
3871
  * SHA2-256 hash function
3872
3872
  * @param message - data that would be hashed
3873
3873
  */
3874
- const sha256$2 = /* @__PURE__ */ wrapConstructor$1(() => new SHA256$1());
3874
+ const sha256$3 = /* @__PURE__ */ wrapConstructor$1(() => new SHA256$1());
3875
3875
 
3876
3876
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
3877
3877
  // Short Weierstrass curve. The formula is: y² = x³ + ax + b
@@ -4974,7 +4974,7 @@ const secp256k1$1 = createCurve$1({
4974
4974
  return { k1neg, k1, k2neg, k2 };
4975
4975
  },
4976
4976
  },
4977
- }, sha256$2);
4977
+ }, sha256$3);
4978
4978
  // Schnorr signatures are superior to ECDSA from above. Below is Schnorr-specific BIP0340 code.
4979
4979
  // https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
4980
4980
  BigInt(0);
@@ -6253,7 +6253,7 @@ const p256 = createCurve$1({
6253
6253
  Gy: BigInt('0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5'),
6254
6254
  h: BigInt(1),
6255
6255
  lowS: false,
6256
- }, sha256$2);
6256
+ }, sha256$3);
6257
6257
 
6258
6258
  // https://homes.esat.kuleuven.be/~bosselae/ripemd160.html
6259
6259
  // https://homes.esat.kuleuven.be/~bosselae/ripemd160/pdf/AB-9601/AB-9601.pdf
@@ -7031,9 +7031,9 @@ function leftpad(data, size = 64) {
7031
7031
  return '0'.repeat(size - data.length) + data;
7032
7032
  }
7033
7033
 
7034
- function sha256$1(payload) {
7034
+ function sha256$2(payload) {
7035
7035
  const data = typeof payload === 'string' ? fromString(payload) : payload;
7036
- return sha256$2(data);
7036
+ return sha256$3(data);
7037
7037
  }
7038
7038
  const keccak = keccak_256$1;
7039
7039
  function toEthereumAddress(hexPublicKey) {
@@ -7066,7 +7066,7 @@ function ES256KSigner(privateKey, recoverable = false) {
7066
7066
 
7067
7067
  return function (data) {
7068
7068
  try {
7069
- const signature = secp256k1$1.sign(sha256$1(data), privateKeyBytes);
7069
+ const signature = secp256k1$1.sign(sha256$2(data), privateKeyBytes);
7070
7070
  return Promise.resolve(toJose({
7071
7071
  r: leftpad(signature.r.toString(16)),
7072
7072
  s: leftpad(signature.s.toString(16)),
@@ -7082,10 +7082,10 @@ function publicKeyToAddress$1(publicKey, otherAddress) {
7082
7082
  // Use the same version/prefix byte as the given address.
7083
7083
  const version = bytesToHex$1(base58ToBytes(otherAddress).slice(0, 1));
7084
7084
  const publicKeyBuffer = hexToBytes$1(publicKey);
7085
- const publicKeyHash = ripemd160(sha256$1(publicKeyBuffer));
7085
+ const publicKeyHash = ripemd160(sha256$2(publicKeyBuffer));
7086
7086
  const step1 = version + bytesToHex$1(publicKeyHash);
7087
- const step2 = sha256$1(hexToBytes$1(step1));
7088
- const step3 = sha256$1(step2);
7087
+ const step2 = sha256$2(hexToBytes$1(step1));
7088
+ const step3 = sha256$2(step2);
7089
7089
  const checksum = bytesToHex$1(step3).substring(0, 8);
7090
7090
  const step4 = step1 + checksum;
7091
7091
  return bytesToBase58(hexToBytes$1(step4));
@@ -7093,7 +7093,7 @@ function publicKeyToAddress$1(publicKey, otherAddress) {
7093
7093
 
7094
7094
  function publicKeyToAddress(publicKey, prefix) {
7095
7095
  const publicKeyBuffer = secp256k1$1.ProjectivePoint.fromHex(publicKey).toRawBytes();
7096
- const hash = ripemd160(sha256$1(publicKeyBuffer));
7096
+ const hash = ripemd160(sha256$2(publicKeyBuffer));
7097
7097
  const words = bech32.toWords(hash);
7098
7098
  return bech32.encode(prefix, words).replace(prefix, '');
7099
7099
  }
@@ -7158,7 +7158,7 @@ function toSignatureObject2(signature, recoverable = false) {
7158
7158
  };
7159
7159
  }
7160
7160
  function verifyES256(data, signature, authenticators) {
7161
- const hash = sha256$1(data);
7161
+ const hash = sha256$2(data);
7162
7162
  const sig = p256.Signature.fromCompact(toSignatureObject2(signature).compact);
7163
7163
  const fullPublicKeys = authenticators.filter(a => !a.ethereumAddress && !a.blockchainAccountId);
7164
7164
  const signer = fullPublicKeys.find(pk => {
@@ -7175,7 +7175,7 @@ function verifyES256(data, signature, authenticators) {
7175
7175
  return signer;
7176
7176
  }
7177
7177
  function verifyES256K(data, signature, authenticators) {
7178
- const hash = sha256$1(data);
7178
+ const hash = sha256$2(data);
7179
7179
  const signatureNormalized = secp256k1$1.Signature.fromCompact(base64ToBytes(signature)).normalizeS();
7180
7180
  const fullPublicKeys = authenticators.filter(a => {
7181
7181
  return !a.ethereumAddress && !a.blockchainAccountId;
@@ -7216,7 +7216,7 @@ function verifyRecoverableES256K(data, signature, authenticators) {
7216
7216
  });
7217
7217
  }
7218
7218
 
7219
- const hash = sha256$1(data);
7219
+ const hash = sha256$2(data);
7220
7220
 
7221
7221
  const checkSignatureAgainstSigner = sigObj => {
7222
7222
  const signature = secp256k1$1.Signature.fromCompact(sigObj.compact).addRecoveryBit(sigObj.recovery || 0);
@@ -7407,7 +7407,7 @@ class Sec256k1Provider {
7407
7407
  */
7408
7408
  async verify(message, signatureHex, keyId) {
7409
7409
  const publicKeyHex = await this.publicKey(keyId);
7410
- return secp256k1$1.verify(signatureHex, sha256$3(message), publicKeyHex);
7410
+ return secp256k1$1.verify(signatureHex, sha256$4(message), publicKeyHex);
7411
7411
  }
7412
7412
  async privateKey(keyId) {
7413
7413
  return this._keyStore.get({ alias: keyId.id });
@@ -30032,7 +30032,7 @@ const cacheLoader = (opts) => {
30032
30032
  /**
30033
30033
  * The current version of Ethers.
30034
30034
  */
30035
- const version = "6.8.0";
30035
+ const version = "6.13.1";
30036
30036
 
30037
30037
  /**
30038
30038
  * Property helper functions.
@@ -30138,7 +30138,7 @@ function stringify(value) {
30138
30138
  * Returns true if the %%error%% matches an error thrown by ethers
30139
30139
  * that matches the error %%code%%.
30140
30140
  *
30141
- * In TypeScript envornoments, this can be used to check that %%error%%
30141
+ * In TypeScript environments, this can be used to check that %%error%%
30142
30142
  * matches an EthersError type, which means the expected properties will
30143
30143
  * be set.
30144
30144
  *
@@ -30164,13 +30164,13 @@ function isCallException(error) {
30164
30164
  }
30165
30165
  /**
30166
30166
  * Returns a new Error configured to the format ethers emits errors, with
30167
- * the %%message%%, [[api:ErrorCode]] %%code%% and additioanl properties
30167
+ * the %%message%%, [[api:ErrorCode]] %%code%% and additional properties
30168
30168
  * for the corresponding EthersError.
30169
30169
  *
30170
30170
  * Each error in ethers includes the version of ethers, a
30171
- * machine-readable [[ErrorCode]], and depneding on %%code%%, additional
30172
- * required properties. The error message will also include the %%meeage%%,
30173
- * ethers version, %%code%% and all aditional properties, serialized.
30171
+ * machine-readable [[ErrorCode]], and depending on %%code%%, additional
30172
+ * required properties. The error message will also include the %%message%%,
30173
+ * ethers version, %%code%% and all additional properties, serialized.
30174
30174
  */
30175
30175
  function makeError(message, code, info) {
30176
30176
  let shortMessage = message;
@@ -30252,7 +30252,7 @@ function assertArgumentCount(count, expectedCount, message) {
30252
30252
  count: count,
30253
30253
  expectedCount: expectedCount
30254
30254
  });
30255
- assert(count <= expectedCount, "too many arguemnts" + message, "UNEXPECTED_ARGUMENT", {
30255
+ assert(count <= expectedCount, "too many arguments" + message, "UNEXPECTED_ARGUMENT", {
30256
30256
  count: count,
30257
30257
  expectedCount: expectedCount
30258
30258
  });
@@ -30322,7 +30322,7 @@ function _getBytes(value, name, copy) {
30322
30322
  }
30323
30323
  return value;
30324
30324
  }
30325
- if (typeof (value) === "string" && value.match(/^0x([0-9a-f][0-9a-f])*$/i)) {
30325
+ if (typeof (value) === "string" && value.match(/^0x(?:[0-9a-f][0-9a-f])*$/i)) {
30326
30326
  const result = new Uint8Array((value.length - 2) / 2);
30327
30327
  let offset = 2;
30328
30328
  for (let i = 0; i < result.length; i++) {
@@ -30631,7 +30631,7 @@ function toBeHex(_value, _width) {
30631
30631
  }
30632
30632
  else {
30633
30633
  const width = getNumber(_width, "width");
30634
- assert(width * 2 >= result.length, `value exceeds width (${width} bits)`, "NUMERIC_FAULT", {
30634
+ assert(width * 2 >= result.length, `value exceeds width (${width} bytes)`, "NUMERIC_FAULT", {
30635
30635
  operation: "toBeHex",
30636
30636
  fault: "overflow",
30637
30637
  value: _value
@@ -30700,12 +30700,20 @@ const BN_58 = BigInt(58);
30700
30700
  * Encode %%value%% as a Base58-encoded string.
30701
30701
  */
30702
30702
  function encodeBase58(_value) {
30703
- let value = toBigInt(getBytes(_value));
30703
+ const bytes = getBytes(_value);
30704
+ let value = toBigInt(bytes);
30704
30705
  let result = "";
30705
30706
  while (value) {
30706
30707
  result = Alphabet[Number(value % BN_58)] + result;
30707
30708
  value /= BN_58;
30708
30709
  }
30710
+ // Account for leading padding zeros
30711
+ for (let i = 0; i < bytes.length; i++) {
30712
+ if (bytes[i]) {
30713
+ break;
30714
+ }
30715
+ result = Alphabet[0] + result;
30716
+ }
30709
30717
  return result;
30710
30718
  }
30711
30719
 
@@ -30922,6 +30930,7 @@ function getUtf8CodePoints(_bytes, onError) {
30922
30930
  * If %%form%% is specified, the string is normalized.
30923
30931
  */
30924
30932
  function toUtf8Bytes(str, form) {
30933
+ assertArgument(typeof (str) === "string", "invalid string value", "str", str);
30925
30934
  if (form != null) {
30926
30935
  assertNormalize(form);
30927
30936
  str = str.normalize(form);
@@ -30976,9 +30985,9 @@ function toUtf8String(bytes, onError) {
30976
30985
  return _toUtf8String(getUtf8CodePoints(bytes, onError));
30977
30986
  }
30978
30987
 
30979
- // @TODO: timeout is completely ignored; start a Promise.any with a reject?
30980
30988
  function createGetUrl(options) {
30981
30989
  async function getUrl(req, _signal) {
30990
+ assert(_signal == null || !_signal.cancelled, "request cancelled before sending", "CANCELLED");
30982
30991
  const protocol = req.url.split(":")[0].toLowerCase();
30983
30992
  assert(protocol === "http" || protocol === "https", `unsupported protocol ${protocol}`, "UNSUPPORTED_OPERATION", {
30984
30993
  info: { protocol },
@@ -30987,19 +30996,36 @@ function createGetUrl(options) {
30987
30996
  assert(protocol === "https" || !req.credentials || req.allowInsecureAuthentication, "insecure authorized connections unsupported", "UNSUPPORTED_OPERATION", {
30988
30997
  operation: "request"
30989
30998
  });
30990
- let signal = undefined;
30999
+ let error = null;
31000
+ const controller = new AbortController();
31001
+ const timer = setTimeout(() => {
31002
+ error = makeError("request timeout", "TIMEOUT");
31003
+ controller.abort();
31004
+ }, req.timeout);
30991
31005
  if (_signal) {
30992
- const controller = new AbortController();
30993
- signal = controller.signal;
30994
- _signal.addListener(() => { controller.abort(); });
31006
+ _signal.addListener(() => {
31007
+ error = makeError("request cancelled", "CANCELLED");
31008
+ controller.abort();
31009
+ });
30995
31010
  }
30996
31011
  const init = {
30997
31012
  method: req.method,
30998
31013
  headers: new Headers(Array.from(req)),
30999
31014
  body: req.body || undefined,
31000
- signal
31015
+ signal: controller.signal
31001
31016
  };
31002
- const resp = await fetch(req.url, init);
31017
+ let resp;
31018
+ try {
31019
+ resp = await fetch(req.url, init);
31020
+ }
31021
+ catch (_error) {
31022
+ clearTimeout(timer);
31023
+ if (error) {
31024
+ throw error;
31025
+ }
31026
+ throw _error;
31027
+ }
31028
+ clearTimeout(timer);
31003
31029
  const headers = {};
31004
31030
  resp.headers.forEach((value, key) => {
31005
31031
  headers[key.toLowerCase()] = value;
@@ -31017,7 +31043,7 @@ function createGetUrl(options) {
31017
31043
 
31018
31044
  /**
31019
31045
  * Fetching content from the web is environment-specific, so Ethers
31020
- * provides an abstraction the each environment can implement to provide
31046
+ * provides an abstraction that each environment can implement to provide
31021
31047
  * this service.
31022
31048
  *
31023
31049
  * On [Node.js](link-node), the ``http`` and ``https`` libs are used to
@@ -31025,10 +31051,10 @@ function createGetUrl(options) {
31025
31051
  * and populate the [[FetchResponse]].
31026
31052
  *
31027
31053
  * In a browser, the [DOM fetch](link-js-fetch) is used, and the resulting
31028
- * ``Promise`` is waited on to retreive the payload.
31054
+ * ``Promise`` is waited on to retrieve the payload.
31029
31055
  *
31030
31056
  * The [[FetchRequest]] is responsible for handling many common situations,
31031
- * such as redirects, server throttling, authentcation, etc.
31057
+ * such as redirects, server throttling, authentication, etc.
31032
31058
  *
31033
31059
  * It also handles common gateways, such as IPFS and data URIs.
31034
31060
  *
@@ -31152,7 +31178,7 @@ class FetchRequest {
31152
31178
  #throttle;
31153
31179
  #getUrlFunc;
31154
31180
  /**
31155
- * The fetch URI to requrest.
31181
+ * The fetch URL to request.
31156
31182
  */
31157
31183
  get url() { return this.#url; }
31158
31184
  set url(url) {
@@ -31166,15 +31192,15 @@ class FetchRequest {
31166
31192
  * header.
31167
31193
  *
31168
31194
  * If %%body%% is null, the body is cleared (along with the
31169
- * intrinsic ``Content-Type``) and the .
31195
+ * intrinsic ``Content-Type``).
31170
31196
  *
31171
- * If %%body%% is a string, the intrincis ``Content-Type`` is set to
31197
+ * If %%body%% is a string, the intrinsic ``Content-Type`` is set to
31172
31198
  * ``text/plain``.
31173
31199
  *
31174
- * If %%body%% is a Uint8Array, the intrincis ``Content-Type`` is set to
31200
+ * If %%body%% is a Uint8Array, the intrinsic ``Content-Type`` is set to
31175
31201
  * ``application/octet-stream``.
31176
31202
  *
31177
- * If %%body%% is any other object, the intrincis ``Content-Type`` is
31203
+ * If %%body%% is any other object, the intrinsic ``Content-Type`` is
31178
31204
  * set to ``application/json``.
31179
31205
  */
31180
31206
  get body() {
@@ -31234,7 +31260,7 @@ class FetchRequest {
31234
31260
  * The headers that will be used when requesting the URI. All
31235
31261
  * keys are lower-case.
31236
31262
  *
31237
- * This object is a copy, so any chnages will **NOT** be reflected
31263
+ * This object is a copy, so any changes will **NOT** be reflected
31238
31264
  * in the ``FetchRequest``.
31239
31265
  *
31240
31266
  * To set a header entry, use the ``setHeader`` method.
@@ -31326,7 +31352,7 @@ class FetchRequest {
31326
31352
  this.#allowInsecure = !!value;
31327
31353
  }
31328
31354
  /**
31329
- * The timeout (in milliseconds) to wait for a complere response.
31355
+ * The timeout (in milliseconds) to wait for a complete response.
31330
31356
  * //(default: 5 minutes)//
31331
31357
  */
31332
31358
  get timeout() { return this.#timeout; }
@@ -31533,7 +31559,7 @@ class FetchRequest {
31533
31559
  * to %%location%%.
31534
31560
  */
31535
31561
  redirect(location) {
31536
- // Redirection; for now we only support absolute locataions
31562
+ // Redirection; for now we only support absolute locations
31537
31563
  const current = this.url.split(":")[0].toLowerCase();
31538
31564
  const target = location.split(":")[0].toLowerCase();
31539
31565
  // Don't allow redirecting:
@@ -31585,6 +31611,7 @@ class FetchRequest {
31585
31611
  clone.#preflight = this.#preflight;
31586
31612
  clone.#process = this.#process;
31587
31613
  clone.#retry = this.#retry;
31614
+ clone.#throttle = Object.assign({}, this.#throttle);
31588
31615
  clone.#getUrlFunc = this.#getUrlFunc;
31589
31616
  return clone;
31590
31617
  }
@@ -31671,7 +31698,7 @@ class FetchRequest {
31671
31698
  }
31672
31699
  }
31673
31700
  /**
31674
- * The response for a FetchREquest.
31701
+ * The response for a FetchRequest.
31675
31702
  */
31676
31703
  class FetchResponse {
31677
31704
  #statusCode;
@@ -31801,7 +31828,7 @@ class FetchResponse {
31801
31828
  return this.headers[key.toLowerCase()];
31802
31829
  }
31803
31830
  /**
31804
- * Returns true of the response has a body.
31831
+ * Returns true if the response has a body.
31805
31832
  */
31806
31833
  hasBody() {
31807
31834
  return (this.#body != null);
@@ -31827,8 +31854,23 @@ class FetchResponse {
31827
31854
  if (message === "") {
31828
31855
  message = `server response ${this.statusCode} ${this.statusMessage}`;
31829
31856
  }
31857
+ let requestUrl = null;
31858
+ if (this.request) {
31859
+ requestUrl = this.request.url;
31860
+ }
31861
+ let responseBody = null;
31862
+ try {
31863
+ if (this.#body) {
31864
+ responseBody = toUtf8String(this.#body);
31865
+ }
31866
+ }
31867
+ catch (e) { }
31830
31868
  assert(false, message, "SERVER_ERROR", {
31831
- request: (this.request || "unknown request"), response: this, error
31869
+ request: (this.request || "unknown request"), response: this, error,
31870
+ info: {
31871
+ requestUrl, responseBody,
31872
+ responseStatus: `${this.statusCode} ${this.statusMessage}`
31873
+ }
31832
31874
  });
31833
31875
  }
31834
31876
  }
@@ -31975,11 +32017,38 @@ const Padding = new Uint8Array(WordSize);
31975
32017
  // - `then` is used to detect if an object is a Promise for await
31976
32018
  const passProperties$1 = ["then"];
31977
32019
  const _guard$2 = {};
32020
+ const resultNames = new WeakMap();
32021
+ function getNames(result) {
32022
+ return resultNames.get(result);
32023
+ }
32024
+ function setNames(result, names) {
32025
+ resultNames.set(result, names);
32026
+ }
31978
32027
  function throwError(name, error) {
31979
32028
  const wrapped = new Error(`deferred error during ABI decoding triggered accessing ${name}`);
31980
32029
  wrapped.error = error;
31981
32030
  throw wrapped;
31982
32031
  }
32032
+ function toObject(names, items, deep) {
32033
+ if (names.indexOf(null) >= 0) {
32034
+ return items.map((item, index) => {
32035
+ if (item instanceof Result) {
32036
+ return toObject(getNames(item), item, deep);
32037
+ }
32038
+ return item;
32039
+ });
32040
+ }
32041
+ return names.reduce((accum, name, index) => {
32042
+ let item = items.getValue(name);
32043
+ if (!(name in accum)) {
32044
+ if (deep && item instanceof Result) {
32045
+ item = toObject(getNames(item), item, deep);
32046
+ }
32047
+ accum[name] = item;
32048
+ }
32049
+ return accum;
32050
+ }, {});
32051
+ }
31983
32052
  /**
31984
32053
  * A [[Result]] is a sub-class of Array, which allows accessing any
31985
32054
  * of its values either positionally by its index or, if keys are
@@ -31988,6 +32057,9 @@ function throwError(name, error) {
31988
32057
  * @_docloc: api/abi
31989
32058
  */
31990
32059
  class Result extends Array {
32060
+ // No longer used; but cannot be removed as it will remove the
32061
+ // #private field from the .d.ts which may break backwards
32062
+ // compatibility
31991
32063
  #names;
31992
32064
  /**
31993
32065
  * @private
@@ -32020,20 +32092,22 @@ class Result extends Array {
32020
32092
  return accum;
32021
32093
  }, (new Map()));
32022
32094
  // Remove any key thats not unique
32023
- this.#names = Object.freeze(items.map((item, index) => {
32095
+ setNames(this, Object.freeze(items.map((item, index) => {
32024
32096
  const name = names[index];
32025
32097
  if (name != null && nameCounts.get(name) === 1) {
32026
32098
  return name;
32027
32099
  }
32028
32100
  return null;
32029
- }));
32101
+ })));
32102
+ // Dummy operations to prevent TypeScript from complaining
32103
+ this.#names = [];
32030
32104
  if (!wrap) {
32031
32105
  return;
32032
32106
  }
32033
32107
  // A wrapped Result is immutable
32034
32108
  Object.freeze(this);
32035
32109
  // Proxy indices and names so we can trap deferred errors
32036
- return new Proxy(this, {
32110
+ const proxy = new Proxy(this, {
32037
32111
  get: (target, prop, receiver) => {
32038
32112
  if (typeof (prop) === "string") {
32039
32113
  // Index accessor
@@ -32068,39 +32142,44 @@ class Result extends Array {
32068
32142
  return Reflect.get(target, prop, receiver);
32069
32143
  }
32070
32144
  });
32145
+ setNames(proxy, getNames(this));
32146
+ return proxy;
32071
32147
  }
32072
32148
  /**
32073
- * Returns the Result as a normal Array.
32149
+ * Returns the Result as a normal Array. If %%deep%%, any children
32150
+ * which are Result objects are also converted to a normal Array.
32074
32151
  *
32075
32152
  * This will throw if there are any outstanding deferred
32076
32153
  * errors.
32077
32154
  */
32078
- toArray() {
32155
+ toArray(deep) {
32079
32156
  const result = [];
32080
32157
  this.forEach((item, index) => {
32081
32158
  if (item instanceof Error) {
32082
32159
  throwError(`index ${index}`, item);
32083
32160
  }
32161
+ if (deep && item instanceof Result) {
32162
+ item = item.toArray(deep);
32163
+ }
32084
32164
  result.push(item);
32085
32165
  });
32086
32166
  return result;
32087
32167
  }
32088
32168
  /**
32089
- * Returns the Result as an Object with each name-value pair.
32169
+ * Returns the Result as an Object with each name-value pair. If
32170
+ * %%deep%%, any children which are Result objects are also
32171
+ * converted to an Object.
32090
32172
  *
32091
32173
  * This will throw if any value is unnamed, or if there are
32092
32174
  * any outstanding deferred errors.
32093
32175
  */
32094
- toObject() {
32095
- return this.#names.reduce((accum, name, index) => {
32096
- assert(name != null, "value at index ${ index } unnamed", "UNSUPPORTED_OPERATION", {
32176
+ toObject(deep) {
32177
+ const names = getNames(this);
32178
+ return names.reduce((accum, name, index) => {
32179
+ assert(name != null, `value at index ${index} unnamed`, "UNSUPPORTED_OPERATION", {
32097
32180
  operation: "toObject()"
32098
32181
  });
32099
- // Add values for names that don't conflict
32100
- if (!(name in accum)) {
32101
- accum[name] = this.getValue(name);
32102
- }
32103
- return accum;
32182
+ return toObject(names, this, deep);
32104
32183
  }, {});
32105
32184
  }
32106
32185
  /**
@@ -32128,10 +32207,11 @@ class Result extends Array {
32128
32207
  if (end > this.length) {
32129
32208
  end = this.length;
32130
32209
  }
32210
+ const _names = getNames(this);
32131
32211
  const result = [], names = [];
32132
32212
  for (let i = start; i < end; i++) {
32133
32213
  result.push(this[i]);
32134
- names.push(this.#names[i]);
32214
+ names.push(_names[i]);
32135
32215
  }
32136
32216
  return new Result(_guard$2, result, names);
32137
32217
  }
@@ -32139,6 +32219,7 @@ class Result extends Array {
32139
32219
  * @_ignore
32140
32220
  */
32141
32221
  filter(callback, thisArg) {
32222
+ const _names = getNames(this);
32142
32223
  const result = [], names = [];
32143
32224
  for (let i = 0; i < this.length; i++) {
32144
32225
  const item = this[i];
@@ -32147,7 +32228,7 @@ class Result extends Array {
32147
32228
  }
32148
32229
  if (callback.call(thisArg, item, i, this)) {
32149
32230
  result.push(item);
32150
- names.push(this.#names[i]);
32231
+ names.push(_names[i]);
32151
32232
  }
32152
32233
  }
32153
32234
  return new Result(_guard$2, result, names);
@@ -32175,7 +32256,7 @@ class Result extends Array {
32175
32256
  * accessible by name.
32176
32257
  */
32177
32258
  getValue(name) {
32178
- const index = this.#names.indexOf(name);
32259
+ const index = getNames(this).indexOf(name);
32179
32260
  if (index === -1) {
32180
32261
  return undefined;
32181
32262
  }
@@ -32285,15 +32366,35 @@ class Reader {
32285
32366
  allowLoose;
32286
32367
  #data;
32287
32368
  #offset;
32288
- constructor(data, allowLoose) {
32369
+ #bytesRead;
32370
+ #parent;
32371
+ #maxInflation;
32372
+ constructor(data, allowLoose, maxInflation) {
32289
32373
  defineProperties(this, { allowLoose: !!allowLoose });
32290
32374
  this.#data = getBytesCopy(data);
32375
+ this.#bytesRead = 0;
32376
+ this.#parent = null;
32377
+ this.#maxInflation = (maxInflation != null) ? maxInflation : 1024;
32291
32378
  this.#offset = 0;
32292
32379
  }
32293
32380
  get data() { return hexlify(this.#data); }
32294
32381
  get dataLength() { return this.#data.length; }
32295
32382
  get consumed() { return this.#offset; }
32296
32383
  get bytes() { return new Uint8Array(this.#data); }
32384
+ #incrementBytesRead(count) {
32385
+ if (this.#parent) {
32386
+ return this.#parent.#incrementBytesRead(count);
32387
+ }
32388
+ this.#bytesRead += count;
32389
+ // Check for excessive inflation (see: #4537)
32390
+ assert(this.#maxInflation < 1 || this.#bytesRead <= this.#maxInflation * this.dataLength, `compressed ABI data exceeds inflation ratio of ${this.#maxInflation} ( see: https:/\/github.com/ethers-io/ethers.js/issues/4537 )`, "BUFFER_OVERRUN", {
32391
+ buffer: getBytesCopy(this.#data), offset: this.#offset,
32392
+ length: count, info: {
32393
+ bytesRead: this.#bytesRead,
32394
+ dataLength: this.dataLength
32395
+ }
32396
+ });
32397
+ }
32297
32398
  #peekBytes(offset, length, loose) {
32298
32399
  let alignedLength = Math.ceil(length / WordSize) * WordSize;
32299
32400
  if (this.#offset + alignedLength > this.#data.length) {
@@ -32312,11 +32413,14 @@ class Reader {
32312
32413
  }
32313
32414
  // Create a sub-reader with the same underlying data, but offset
32314
32415
  subReader(offset) {
32315
- return new Reader(this.#data.slice(this.#offset + offset), this.allowLoose);
32416
+ const reader = new Reader(this.#data.slice(this.#offset + offset), this.allowLoose, this.#maxInflation);
32417
+ reader.#parent = this;
32418
+ return reader;
32316
32419
  }
32317
32420
  // Read bytes
32318
32421
  readBytes(length, loose) {
32319
32422
  let bytes = this.#peekBytes(0, length, !!loose);
32423
+ this.#incrementBytesRead(length);
32320
32424
  this.#offset += bytes.length;
32321
32425
  // @TODO: Make sure the length..end bytes are all 0?
32322
32426
  return bytes.slice(0, length);
@@ -32732,7 +32836,7 @@ class SHA256 extends SHA2 {
32732
32836
  * SHA2-256 hash function
32733
32837
  * @param message - data that would be hashed
32734
32838
  */
32735
- const sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
32839
+ const sha256$1 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
32736
32840
 
32737
32841
  const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
32738
32842
  const _32n = /* @__PURE__ */ BigInt(32);
@@ -32751,12 +32855,225 @@ function split$1(lst, le = false) {
32751
32855
  }
32752
32856
  return [Ah, Al];
32753
32857
  }
32858
+ const toBig = (h, l) => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);
32859
+ // for Shift in [0, 32)
32860
+ const shrSH = (h, _l, s) => h >>> s;
32861
+ const shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
32862
+ // Right rotate for Shift in [1, 32)
32863
+ const rotrSH = (h, l, s) => (h >>> s) | (l << (32 - s));
32864
+ const rotrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
32865
+ // Right rotate for Shift in (32, 64), NOTE: 32 is special case.
32866
+ const rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));
32867
+ const rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));
32868
+ // Right rotate for shift===32 (just swaps l&h)
32869
+ const rotr32H = (_h, l) => l;
32870
+ const rotr32L = (h, _l) => h;
32754
32871
  // Left rotate for Shift in [1, 32)
32755
32872
  const rotlSH = (h, l, s) => (h << s) | (l >>> (32 - s));
32756
32873
  const rotlSL = (h, l, s) => (l << s) | (h >>> (32 - s));
32757
32874
  // Left rotate for Shift in (32, 64), NOTE: 32 is special case.
32758
32875
  const rotlBH = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s));
32759
32876
  const rotlBL = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));
32877
+ // JS uses 32-bit signed integers for bitwise operations which means we cannot
32878
+ // simple take carry out of low bit sum by shift, we need to use division.
32879
+ function add(Ah, Al, Bh, Bl) {
32880
+ const l = (Al >>> 0) + (Bl >>> 0);
32881
+ return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };
32882
+ }
32883
+ // Addition with more than 2 elements
32884
+ const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
32885
+ const add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
32886
+ const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
32887
+ const add4H = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;
32888
+ const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
32889
+ const add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;
32890
+ // prettier-ignore
32891
+ const u64 = {
32892
+ fromBig, split: split$1, toBig,
32893
+ shrSH, shrSL,
32894
+ rotrSH, rotrSL, rotrBH, rotrBL,
32895
+ rotr32H, rotr32L,
32896
+ rotlSH, rotlSL, rotlBH, rotlBL,
32897
+ add, add3L, add3H, add4L, add4H, add5H, add5L,
32898
+ };
32899
+
32900
+ // Round contants (first 32 bits of the fractional parts of the cube roots of the first 80 primes 2..409):
32901
+ // prettier-ignore
32902
+ const [SHA512_Kh, SHA512_Kl] = /* @__PURE__ */ (() => u64.split([
32903
+ '0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc',
32904
+ '0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118',
32905
+ '0xd807aa98a3030242', '0x12835b0145706fbe', '0x243185be4ee4b28c', '0x550c7dc3d5ffb4e2',
32906
+ '0x72be5d74f27b896f', '0x80deb1fe3b1696b1', '0x9bdc06a725c71235', '0xc19bf174cf692694',
32907
+ '0xe49b69c19ef14ad2', '0xefbe4786384f25e3', '0x0fc19dc68b8cd5b5', '0x240ca1cc77ac9c65',
32908
+ '0x2de92c6f592b0275', '0x4a7484aa6ea6e483', '0x5cb0a9dcbd41fbd4', '0x76f988da831153b5',
32909
+ '0x983e5152ee66dfab', '0xa831c66d2db43210', '0xb00327c898fb213f', '0xbf597fc7beef0ee4',
32910
+ '0xc6e00bf33da88fc2', '0xd5a79147930aa725', '0x06ca6351e003826f', '0x142929670a0e6e70',
32911
+ '0x27b70a8546d22ffc', '0x2e1b21385c26c926', '0x4d2c6dfc5ac42aed', '0x53380d139d95b3df',
32912
+ '0x650a73548baf63de', '0x766a0abb3c77b2a8', '0x81c2c92e47edaee6', '0x92722c851482353b',
32913
+ '0xa2bfe8a14cf10364', '0xa81a664bbc423001', '0xc24b8b70d0f89791', '0xc76c51a30654be30',
32914
+ '0xd192e819d6ef5218', '0xd69906245565a910', '0xf40e35855771202a', '0x106aa07032bbd1b8',
32915
+ '0x19a4c116b8d2d0c8', '0x1e376c085141ab53', '0x2748774cdf8eeb99', '0x34b0bcb5e19b48a8',
32916
+ '0x391c0cb3c5c95a63', '0x4ed8aa4ae3418acb', '0x5b9cca4f7763e373', '0x682e6ff3d6b2b8a3',
32917
+ '0x748f82ee5defb2fc', '0x78a5636f43172f60', '0x84c87814a1f0ab72', '0x8cc702081a6439ec',
32918
+ '0x90befffa23631e28', '0xa4506cebde82bde9', '0xbef9a3f7b2c67915', '0xc67178f2e372532b',
32919
+ '0xca273eceea26619c', '0xd186b8c721c0c207', '0xeada7dd6cde0eb1e', '0xf57d4f7fee6ed178',
32920
+ '0x06f067aa72176fba', '0x0a637dc5a2c898a6', '0x113f9804bef90dae', '0x1b710b35131c471b',
32921
+ '0x28db77f523047d84', '0x32caab7b40c72493', '0x3c9ebe0a15c9bebc', '0x431d67c49c100d4c',
32922
+ '0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817'
32923
+ ].map(n => BigInt(n))))();
32924
+ // Temporary buffer, not used to store anything between runs
32925
+ const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
32926
+ const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
32927
+ class SHA512 extends SHA2 {
32928
+ constructor() {
32929
+ super(128, 64, 16, false);
32930
+ // We cannot use array here since array allows indexing by variable which means optimizer/compiler cannot use registers.
32931
+ // Also looks cleaner and easier to verify with spec.
32932
+ // Initial state (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
32933
+ // h -- high 32 bits, l -- low 32 bits
32934
+ this.Ah = 0x6a09e667 | 0;
32935
+ this.Al = 0xf3bcc908 | 0;
32936
+ this.Bh = 0xbb67ae85 | 0;
32937
+ this.Bl = 0x84caa73b | 0;
32938
+ this.Ch = 0x3c6ef372 | 0;
32939
+ this.Cl = 0xfe94f82b | 0;
32940
+ this.Dh = 0xa54ff53a | 0;
32941
+ this.Dl = 0x5f1d36f1 | 0;
32942
+ this.Eh = 0x510e527f | 0;
32943
+ this.El = 0xade682d1 | 0;
32944
+ this.Fh = 0x9b05688c | 0;
32945
+ this.Fl = 0x2b3e6c1f | 0;
32946
+ this.Gh = 0x1f83d9ab | 0;
32947
+ this.Gl = 0xfb41bd6b | 0;
32948
+ this.Hh = 0x5be0cd19 | 0;
32949
+ this.Hl = 0x137e2179 | 0;
32950
+ }
32951
+ // prettier-ignore
32952
+ get() {
32953
+ const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
32954
+ return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
32955
+ }
32956
+ // prettier-ignore
32957
+ set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
32958
+ this.Ah = Ah | 0;
32959
+ this.Al = Al | 0;
32960
+ this.Bh = Bh | 0;
32961
+ this.Bl = Bl | 0;
32962
+ this.Ch = Ch | 0;
32963
+ this.Cl = Cl | 0;
32964
+ this.Dh = Dh | 0;
32965
+ this.Dl = Dl | 0;
32966
+ this.Eh = Eh | 0;
32967
+ this.El = El | 0;
32968
+ this.Fh = Fh | 0;
32969
+ this.Fl = Fl | 0;
32970
+ this.Gh = Gh | 0;
32971
+ this.Gl = Gl | 0;
32972
+ this.Hh = Hh | 0;
32973
+ this.Hl = Hl | 0;
32974
+ }
32975
+ process(view, offset) {
32976
+ // Extend the first 16 words into the remaining 64 words w[16..79] of the message schedule array
32977
+ for (let i = 0; i < 16; i++, offset += 4) {
32978
+ SHA512_W_H[i] = view.getUint32(offset);
32979
+ SHA512_W_L[i] = view.getUint32((offset += 4));
32980
+ }
32981
+ for (let i = 16; i < 80; i++) {
32982
+ // s0 := (w[i-15] rightrotate 1) xor (w[i-15] rightrotate 8) xor (w[i-15] rightshift 7)
32983
+ const W15h = SHA512_W_H[i - 15] | 0;
32984
+ const W15l = SHA512_W_L[i - 15] | 0;
32985
+ const s0h = u64.rotrSH(W15h, W15l, 1) ^ u64.rotrSH(W15h, W15l, 8) ^ u64.shrSH(W15h, W15l, 7);
32986
+ const s0l = u64.rotrSL(W15h, W15l, 1) ^ u64.rotrSL(W15h, W15l, 8) ^ u64.shrSL(W15h, W15l, 7);
32987
+ // s1 := (w[i-2] rightrotate 19) xor (w[i-2] rightrotate 61) xor (w[i-2] rightshift 6)
32988
+ const W2h = SHA512_W_H[i - 2] | 0;
32989
+ const W2l = SHA512_W_L[i - 2] | 0;
32990
+ const s1h = u64.rotrSH(W2h, W2l, 19) ^ u64.rotrBH(W2h, W2l, 61) ^ u64.shrSH(W2h, W2l, 6);
32991
+ const s1l = u64.rotrSL(W2h, W2l, 19) ^ u64.rotrBL(W2h, W2l, 61) ^ u64.shrSL(W2h, W2l, 6);
32992
+ // SHA256_W[i] = s0 + s1 + SHA256_W[i - 7] + SHA256_W[i - 16];
32993
+ const SUMl = u64.add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
32994
+ const SUMh = u64.add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
32995
+ SHA512_W_H[i] = SUMh | 0;
32996
+ SHA512_W_L[i] = SUMl | 0;
32997
+ }
32998
+ let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
32999
+ // Compression function main loop, 80 rounds
33000
+ for (let i = 0; i < 80; i++) {
33001
+ // S1 := (e rightrotate 14) xor (e rightrotate 18) xor (e rightrotate 41)
33002
+ const sigma1h = u64.rotrSH(Eh, El, 14) ^ u64.rotrSH(Eh, El, 18) ^ u64.rotrBH(Eh, El, 41);
33003
+ const sigma1l = u64.rotrSL(Eh, El, 14) ^ u64.rotrSL(Eh, El, 18) ^ u64.rotrBL(Eh, El, 41);
33004
+ //const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
33005
+ const CHIh = (Eh & Fh) ^ (~Eh & Gh);
33006
+ const CHIl = (El & Fl) ^ (~El & Gl);
33007
+ // T1 = H + sigma1 + Chi(E, F, G) + SHA512_K[i] + SHA512_W[i]
33008
+ // prettier-ignore
33009
+ const T1ll = u64.add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
33010
+ const T1h = u64.add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
33011
+ const T1l = T1ll | 0;
33012
+ // S0 := (a rightrotate 28) xor (a rightrotate 34) xor (a rightrotate 39)
33013
+ const sigma0h = u64.rotrSH(Ah, Al, 28) ^ u64.rotrBH(Ah, Al, 34) ^ u64.rotrBH(Ah, Al, 39);
33014
+ const sigma0l = u64.rotrSL(Ah, Al, 28) ^ u64.rotrBL(Ah, Al, 34) ^ u64.rotrBL(Ah, Al, 39);
33015
+ const MAJh = (Ah & Bh) ^ (Ah & Ch) ^ (Bh & Ch);
33016
+ const MAJl = (Al & Bl) ^ (Al & Cl) ^ (Bl & Cl);
33017
+ Hh = Gh | 0;
33018
+ Hl = Gl | 0;
33019
+ Gh = Fh | 0;
33020
+ Gl = Fl | 0;
33021
+ Fh = Eh | 0;
33022
+ Fl = El | 0;
33023
+ ({ h: Eh, l: El } = u64.add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
33024
+ Dh = Ch | 0;
33025
+ Dl = Cl | 0;
33026
+ Ch = Bh | 0;
33027
+ Cl = Bl | 0;
33028
+ Bh = Ah | 0;
33029
+ Bl = Al | 0;
33030
+ const All = u64.add3L(T1l, sigma0l, MAJl);
33031
+ Ah = u64.add3H(All, T1h, sigma0h, MAJh);
33032
+ Al = All | 0;
33033
+ }
33034
+ // Add the compressed chunk to the current hash value
33035
+ ({ h: Ah, l: Al } = u64.add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
33036
+ ({ h: Bh, l: Bl } = u64.add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
33037
+ ({ h: Ch, l: Cl } = u64.add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
33038
+ ({ h: Dh, l: Dl } = u64.add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
33039
+ ({ h: Eh, l: El } = u64.add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
33040
+ ({ h: Fh, l: Fl } = u64.add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
33041
+ ({ h: Gh, l: Gl } = u64.add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
33042
+ ({ h: Hh, l: Hl } = u64.add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
33043
+ this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
33044
+ }
33045
+ roundClean() {
33046
+ SHA512_W_H.fill(0);
33047
+ SHA512_W_L.fill(0);
33048
+ }
33049
+ destroy() {
33050
+ this.buffer.fill(0);
33051
+ this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
33052
+ }
33053
+ }
33054
+ const sha512 = /* @__PURE__ */ wrapConstructor(() => new SHA512());
33055
+
33056
+ /* Browser Crypto Shims */
33057
+ function getGlobal() {
33058
+ if (typeof self !== 'undefined') {
33059
+ return self;
33060
+ }
33061
+ if (typeof window !== 'undefined') {
33062
+ return window;
33063
+ }
33064
+ if (typeof global !== 'undefined') {
33065
+ return global;
33066
+ }
33067
+ throw new Error('unable to locate global object');
33068
+ }
33069
+ getGlobal();
33070
+ function createHash(algo) {
33071
+ switch (algo) {
33072
+ case "sha256": return sha256$1.create();
33073
+ case "sha512": return sha512.create();
33074
+ }
33075
+ assertArgument(false, "invalid hashing algorithm name", "algorithm", algo);
33076
+ }
32760
33077
 
32761
33078
  // SHA3 (keccak) is based on a new design: basically, the internal state is bigger than output size.
32762
33079
  // It's called a sponge function.
@@ -32995,6 +33312,43 @@ keccak256.register = function (func) {
32995
33312
  };
32996
33313
  Object.freeze(keccak256);
32997
33314
 
33315
+ const _sha256 = function (data) {
33316
+ return createHash("sha256").update(data).digest();
33317
+ };
33318
+ let __sha256 = _sha256;
33319
+ let locked256 = false;
33320
+ /**
33321
+ * Compute the cryptographic SHA2-256 hash of %%data%%.
33322
+ *
33323
+ * @_docloc: api/crypto:Hash Functions
33324
+ * @returns DataHexstring
33325
+ *
33326
+ * @example:
33327
+ * sha256("0x")
33328
+ * //_result:
33329
+ *
33330
+ * sha256("0x1337")
33331
+ * //_result:
33332
+ *
33333
+ * sha256(new Uint8Array([ 0x13, 0x37 ]))
33334
+ * //_result:
33335
+ *
33336
+ */
33337
+ function sha256(_data) {
33338
+ const data = getBytes(_data, "data");
33339
+ return hexlify(__sha256(data));
33340
+ }
33341
+ sha256._ = _sha256;
33342
+ sha256.lock = function () { locked256 = true; };
33343
+ sha256.register = function (func) {
33344
+ if (locked256) {
33345
+ throw new Error("sha256 is locked");
33346
+ }
33347
+ __sha256 = func;
33348
+ };
33349
+ Object.freeze(sha256);
33350
+ Object.freeze(sha256);
33351
+
32998
33352
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
32999
33353
  // 100 lines of code in the file are duplicated from noble-hashes (utils).
33000
33354
  // This is OK: `abstract` directory does not use noble-hashes.
@@ -34810,7 +35164,7 @@ const secp256k1 = createCurve({
34810
35164
  return { k1neg, k1, k2neg, k2 };
34811
35165
  },
34812
35166
  },
34813
- }, sha256);
35167
+ }, sha256$1);
34814
35168
  // Schnorr signatures are superior to ECDSA from above. Below is Schnorr-specific BIP0340 code.
34815
35169
  // https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
34816
35170
  BigInt(0);
@@ -36564,7 +36918,7 @@ function id(value) {
36564
36918
  return keccak256(toUtf8Bytes(value));
36565
36919
  }
36566
36920
 
36567
- // created 2023-09-12T22:05:14.211Z
36921
+ // created 2023-09-25T01:01:55.148Z
36568
36922
  // compressed base64-encoded blob for include-ens data
36569
36923
  // source: https://github.com/adraffy/ens-normalize.js/blob/main/src/make.js
36570
36924
  // see: https://github.com/adraffy/ens-normalize.js#security
@@ -36845,7 +37199,7 @@ function compare_arrays(a, b) {
36845
37199
  return c;
36846
37200
  }
36847
37201
 
36848
- // created 2023-09-12T22:05:14.211Z
37202
+ // created 2023-09-25T01:01:55.148Z
36849
37203
  // compressed base64-encoded blob for include-nf data
36850
37204
  // source: https://github.com/adraffy/ens-normalize.js/blob/main/src/make.js
36851
37205
  // see: https://github.com/adraffy/ens-normalize.js#security
@@ -37061,6 +37415,7 @@ function init() {
37061
37415
  let r = read_compressed_payload(COMPRESSED$1);
37062
37416
  const read_sorted_array = () => read_sorted(r);
37063
37417
  const read_sorted_set = () => new Set(read_sorted_array());
37418
+ const set_add_many = (set, v) => v.forEach(x => set.add(x));
37064
37419
 
37065
37420
  MAPPED = new Map(read_mapped(r));
37066
37421
  IGNORED = read_sorted_set(); // ignored characters are not valid, so just read raw codepoints
@@ -37083,13 +37438,20 @@ function init() {
37083
37438
 
37084
37439
  let chunks = read_sorted_arrays(r);
37085
37440
  let unrestricted = r();
37086
- const read_chunked = () => new Set(read_sorted_array().flatMap(i => chunks[i]).concat(read_sorted_array()));
37441
+ //const read_chunked = () => new Set(read_sorted_array().flatMap(i => chunks[i]).concat(read_sorted_array()));
37442
+ const read_chunked = () => {
37443
+ // 20230921: build set in parts, 2x faster
37444
+ let set = new Set();
37445
+ read_sorted_array().forEach(i => set_add_many(set, chunks[i]));
37446
+ set_add_many(set, read_sorted_array());
37447
+ return set;
37448
+ };
37087
37449
  GROUPS = read_array_while(i => {
37088
37450
  // minifier property mangling seems unsafe
37089
37451
  // so these are manually renamed to single chars
37090
37452
  let N = read_array_while(r).map(x => x+0x60);
37091
37453
  if (N.length) {
37092
- let R = i >= unrestricted; // first arent restricted
37454
+ let R = i >= unrestricted; // unrestricted then restricted
37093
37455
  N[0] -= 32; // capitalize
37094
37456
  N = str_from_cps(N);
37095
37457
  if (R) N=`Restricted[${N}]`;
@@ -37127,6 +37489,7 @@ function init() {
37127
37489
  });
37128
37490
 
37129
37491
  // compute confusable-extent complements
37492
+ // usage: WHOLE_MAP.get(cp).M.get(cp) = complement set
37130
37493
  for (let {V, M} of new Set(WHOLE_MAP.values())) {
37131
37494
  // connect all groups that have each whole character
37132
37495
  let recs = [];
@@ -37138,34 +37501,37 @@ function init() {
37138
37501
  recs.push(rec);
37139
37502
  }
37140
37503
  rec.V.push(cp);
37141
- gs.forEach(g => rec.G.add(g));
37504
+ set_add_many(rec.G, gs);
37142
37505
  }
37143
37506
  // per character cache groups which are not a member of the extent
37144
- let union = recs.flatMap(x => Array_from(x.G));
37507
+ let union = recs.flatMap(x => Array_from(x.G)); // all of the groups used by this whole
37145
37508
  for (let {G, V} of recs) {
37146
- let complement = new Set(union.filter(g => !G.has(g)));
37509
+ let complement = new Set(union.filter(g => !G.has(g))); // groups not covered by the extent
37147
37510
  for (let cp of V) {
37148
- M.set(cp, complement);
37511
+ M.set(cp, complement); // this is the same reference
37149
37512
  }
37150
37513
  }
37151
37514
  }
37152
37515
 
37153
37516
  // compute valid set
37154
- let union = new Set(); // exists in 1+ groups
37517
+ // 20230924: VALID was union but can be re-used
37518
+ VALID = new Set(); // exists in 1+ groups
37155
37519
  let multi = new Set(); // exists in 2+ groups
37156
- const add_to_union = cp => union.has(cp) ? multi.add(cp) : union.add(cp);
37520
+ const add_to_union = cp => VALID.has(cp) ? multi.add(cp) : VALID.add(cp);
37157
37521
  for (let g of GROUPS) {
37158
37522
  for (let cp of g.P) add_to_union(cp);
37159
37523
  for (let cp of g.Q) add_to_union(cp);
37160
37524
  }
37161
37525
  // dual purpose WHOLE_MAP: return placeholder if unique non-confusable
37162
- for (let cp of union) {
37526
+ for (let cp of VALID) {
37163
37527
  if (!WHOLE_MAP.has(cp) && !multi.has(cp)) {
37164
37528
  WHOLE_MAP.set(cp, UNIQUE_PH);
37165
37529
  }
37166
37530
  }
37167
- VALID = new Set(Array_from(union).concat(Array_from(nfd(union)))); // possibly valid
37168
-
37531
+ // add all decomposed parts
37532
+ // see derive: "Valid is Closed (via Brute-force)"
37533
+ set_add_many(VALID, nfd(VALID));
37534
+
37169
37535
  // decode emoji
37170
37536
  // 20230719: emoji are now fully-expanded to avoid quirk logic
37171
37537
  EMOJI_LIST = read_trie(r).map(v => Emoji.from(v)).sort(compare_arrays);
@@ -37218,7 +37584,7 @@ function bidi_qq(s) {
37218
37584
 
37219
37585
  function check_label_extension(cps) {
37220
37586
  if (cps.length >= 4 && cps[2] == HYPHEN && cps[3] == HYPHEN) {
37221
- throw new Error(`invalid label extension: "${str_from_cps(cps.slice(0, 4))}"`);
37587
+ throw new Error(`invalid label extension: "${str_from_cps(cps.slice(0, 4))}"`); // this can only be ascii so cant be bidi
37222
37588
  }
37223
37589
  }
37224
37590
  function check_leading_underscore(cps) {
@@ -37252,13 +37618,18 @@ function check_fenced(cps) {
37252
37618
  // create a safe to print string
37253
37619
  // invisibles are escaped
37254
37620
  // leading cm uses placeholder
37621
+ // if cps exceed max, middle truncate with ellipsis
37255
37622
  // quoter(cp) => string, eg. 3000 => "{3000}"
37256
37623
  // note: in html, you'd call this function then replace [<>&] with entities
37257
- function safe_str_from_cps(cps, quoter = quote_cp) {
37624
+ function safe_str_from_cps(cps, max = Infinity, quoter = quote_cp) {
37258
37625
  //if (Number.isInteger(cps)) cps = [cps];
37259
37626
  //if (!Array.isArray(cps)) throw new TypeError(`expected codepoints`);
37260
37627
  let buf = [];
37261
37628
  if (is_combining_mark(cps[0])) buf.push('◌');
37629
+ if (cps.length > max) {
37630
+ max >>= 1;
37631
+ cps = [...cps.slice(0, max), 0x2026, ...cps.slice(-max)];
37632
+ }
37262
37633
  let prev = 0;
37263
37634
  let n = cps.length;
37264
37635
  for (let i = 0; i < n; i++) {
@@ -37423,7 +37794,7 @@ function flatten(split) {
37423
37794
  // don't print label again if just a single label
37424
37795
  let msg = error.message;
37425
37796
  // bidi_qq() only necessary if msg is digits
37426
- throw new Error(split.length == 1 ? msg : `Invalid label ${bidi_qq(safe_str_from_cps(input))}: ${msg}`);
37797
+ throw new Error(split.length == 1 ? msg : `Invalid label ${bidi_qq(safe_str_from_cps(input, 63))}: ${msg}`);
37427
37798
  }
37428
37799
  return str_from_cps(output);
37429
37800
  }).join(STOP_CH);
@@ -37677,12 +38048,11 @@ function namehash(name) {
37677
38048
  * This is used for various parts of ENS name resolution, such
37678
38049
  * as the wildcard resolution.
37679
38050
  */
37680
- function dnsEncode(name) {
38051
+ function dnsEncode(name, _maxLength) {
38052
+ const length = (_maxLength != null) ? _maxLength : 63;
38053
+ assertArgument(length <= 255, "DNS encoded label cannot exceed 255", "length", length);
37681
38054
  return hexlify(concat(ensNameSplit(name).map((comp) => {
37682
- // DNS does not allow components over 63 bytes in length
37683
- if (comp.length > 63) {
37684
- throw new Error("invalid DNS encoded entry; length exceeds 63 bytes");
37685
- }
38055
+ assertArgument(comp.length <= length, `label ${JSON.stringify(name)} exceeds ${length} bytes`, "name", name);
37686
38056
  const bytes = new Uint8Array(comp.length + 1);
37687
38057
  bytes.set(comp, 1);
37688
38058
  bytes[0] = bytes.length - 1;
@@ -37754,6 +38124,15 @@ const BN_27 = BigInt(27);
37754
38124
  const BN_28 = BigInt(28);
37755
38125
  const BN_35 = BigInt(35);
37756
38126
  const BN_MAX_UINT = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
38127
+ const BLOB_SIZE = 4096 * 32;
38128
+ function getVersionedHash(version, hash) {
38129
+ let versioned = version.toString(16);
38130
+ while (versioned.length < 2) {
38131
+ versioned = "0" + versioned;
38132
+ }
38133
+ versioned += sha256(hash).substring(4);
38134
+ return "0x" + versioned;
38135
+ }
37757
38136
  function handleAddress(value) {
37758
38137
  if (value === "0x") {
37759
38138
  return null;
@@ -37791,6 +38170,13 @@ function formatNumber(_value, name) {
37791
38170
  function formatAccessList(value) {
37792
38171
  return accessListify(value).map((set) => [set.address, set.storageKeys]);
37793
38172
  }
38173
+ function formatHashes(value, param) {
38174
+ assertArgument(Array.isArray(value), `invalid ${param}`, "value", value);
38175
+ for (let i = 0; i < value.length; i++) {
38176
+ assertArgument(isHexString(value[i], 32), "invalid ${ param } hash", `value[${i}]`, value[i]);
38177
+ }
38178
+ return value;
38179
+ }
37794
38180
  function _parseLegacy(data) {
37795
38181
  const fields = decodeRlp(data);
37796
38182
  assertArgument(Array.isArray(fields) && (fields.length === 9 || fields.length === 6), "invalid field count for legacy transaction", "data", data);
@@ -37829,18 +38215,18 @@ function _parseLegacy(data) {
37829
38215
  s: zeroPadValue(fields[8], 32),
37830
38216
  v
37831
38217
  });
37832
- tx.hash = keccak256(data);
38218
+ //tx.hash = keccak256(data);
37833
38219
  }
37834
38220
  return tx;
37835
38221
  }
37836
38222
  function _serializeLegacy(tx, sig) {
37837
38223
  const fields = [
37838
- formatNumber(tx.nonce || 0, "nonce"),
38224
+ formatNumber(tx.nonce, "nonce"),
37839
38225
  formatNumber(tx.gasPrice || 0, "gasPrice"),
37840
- formatNumber(tx.gasLimit || 0, "gasLimit"),
37841
- ((tx.to != null) ? getAddress(tx.to) : "0x"),
37842
- formatNumber(tx.value || 0, "value"),
37843
- (tx.data || "0x"),
38226
+ formatNumber(tx.gasLimit, "gasLimit"),
38227
+ (tx.to || "0x"),
38228
+ formatNumber(tx.value, "value"),
38229
+ tx.data,
37844
38230
  ];
37845
38231
  let chainId = BN_0$4;
37846
38232
  if (tx.chainId != BN_0$4) {
@@ -37903,14 +38289,12 @@ function _parseEipSignature(tx, fields) {
37903
38289
  function _parseEip1559(data) {
37904
38290
  const fields = decodeRlp(getBytes(data).slice(1));
37905
38291
  assertArgument(Array.isArray(fields) && (fields.length === 9 || fields.length === 12), "invalid field count for transaction type: 2", "data", hexlify(data));
37906
- const maxPriorityFeePerGas = handleUint(fields[2], "maxPriorityFeePerGas");
37907
- const maxFeePerGas = handleUint(fields[3], "maxFeePerGas");
37908
38292
  const tx = {
37909
38293
  type: 2,
37910
38294
  chainId: handleUint(fields[0], "chainId"),
37911
38295
  nonce: handleNumber(fields[1], "nonce"),
37912
- maxPriorityFeePerGas: maxPriorityFeePerGas,
37913
- maxFeePerGas: maxFeePerGas,
38296
+ maxPriorityFeePerGas: handleUint(fields[2], "maxPriorityFeePerGas"),
38297
+ maxFeePerGas: handleUint(fields[3], "maxFeePerGas"),
37914
38298
  gasPrice: null,
37915
38299
  gasLimit: handleUint(fields[4], "gasLimit"),
37916
38300
  to: handleAddress(fields[5]),
@@ -37922,21 +38306,21 @@ function _parseEip1559(data) {
37922
38306
  if (fields.length === 9) {
37923
38307
  return tx;
37924
38308
  }
37925
- tx.hash = keccak256(data);
38309
+ //tx.hash = keccak256(data);
37926
38310
  _parseEipSignature(tx, fields.slice(9));
37927
38311
  return tx;
37928
38312
  }
37929
38313
  function _serializeEip1559(tx, sig) {
37930
38314
  const fields = [
37931
- formatNumber(tx.chainId || 0, "chainId"),
37932
- formatNumber(tx.nonce || 0, "nonce"),
38315
+ formatNumber(tx.chainId, "chainId"),
38316
+ formatNumber(tx.nonce, "nonce"),
37933
38317
  formatNumber(tx.maxPriorityFeePerGas || 0, "maxPriorityFeePerGas"),
37934
38318
  formatNumber(tx.maxFeePerGas || 0, "maxFeePerGas"),
37935
- formatNumber(tx.gasLimit || 0, "gasLimit"),
37936
- ((tx.to != null) ? getAddress(tx.to) : "0x"),
37937
- formatNumber(tx.value || 0, "value"),
37938
- (tx.data || "0x"),
37939
- (formatAccessList(tx.accessList || []))
38319
+ formatNumber(tx.gasLimit, "gasLimit"),
38320
+ (tx.to || "0x"),
38321
+ formatNumber(tx.value, "value"),
38322
+ tx.data,
38323
+ formatAccessList(tx.accessList || [])
37940
38324
  ];
37941
38325
  if (sig) {
37942
38326
  fields.push(formatNumber(sig.yParity, "yParity"));
@@ -37963,20 +38347,20 @@ function _parseEip2930(data) {
37963
38347
  if (fields.length === 8) {
37964
38348
  return tx;
37965
38349
  }
37966
- tx.hash = keccak256(data);
38350
+ //tx.hash = keccak256(data);
37967
38351
  _parseEipSignature(tx, fields.slice(8));
37968
38352
  return tx;
37969
38353
  }
37970
38354
  function _serializeEip2930(tx, sig) {
37971
38355
  const fields = [
37972
- formatNumber(tx.chainId || 0, "chainId"),
37973
- formatNumber(tx.nonce || 0, "nonce"),
38356
+ formatNumber(tx.chainId, "chainId"),
38357
+ formatNumber(tx.nonce, "nonce"),
37974
38358
  formatNumber(tx.gasPrice || 0, "gasPrice"),
37975
- formatNumber(tx.gasLimit || 0, "gasLimit"),
37976
- ((tx.to != null) ? getAddress(tx.to) : "0x"),
37977
- formatNumber(tx.value || 0, "value"),
37978
- (tx.data || "0x"),
37979
- (formatAccessList(tx.accessList || []))
38359
+ formatNumber(tx.gasLimit, "gasLimit"),
38360
+ (tx.to || "0x"),
38361
+ formatNumber(tx.value, "value"),
38362
+ tx.data,
38363
+ formatAccessList(tx.accessList || [])
37980
38364
  ];
37981
38365
  if (sig) {
37982
38366
  fields.push(formatNumber(sig.yParity, "recoveryParam"));
@@ -37985,6 +38369,96 @@ function _serializeEip2930(tx, sig) {
37985
38369
  }
37986
38370
  return concat(["0x01", encodeRlp(fields)]);
37987
38371
  }
38372
+ function _parseEip4844(data) {
38373
+ let fields = decodeRlp(getBytes(data).slice(1));
38374
+ let typeName = "3";
38375
+ let blobs = null;
38376
+ // Parse the network format
38377
+ if (fields.length === 4 && Array.isArray(fields[0])) {
38378
+ typeName = "3 (network format)";
38379
+ const fBlobs = fields[1], fCommits = fields[2], fProofs = fields[3];
38380
+ assertArgument(Array.isArray(fBlobs), "invalid network format: blobs not an array", "fields[1]", fBlobs);
38381
+ assertArgument(Array.isArray(fCommits), "invalid network format: commitments not an array", "fields[2]", fCommits);
38382
+ assertArgument(Array.isArray(fProofs), "invalid network format: proofs not an array", "fields[3]", fProofs);
38383
+ assertArgument(fBlobs.length === fCommits.length, "invalid network format: blobs/commitments length mismatch", "fields", fields);
38384
+ assertArgument(fBlobs.length === fProofs.length, "invalid network format: blobs/proofs length mismatch", "fields", fields);
38385
+ blobs = [];
38386
+ for (let i = 0; i < fields[1].length; i++) {
38387
+ blobs.push({
38388
+ data: fBlobs[i],
38389
+ commitment: fCommits[i],
38390
+ proof: fProofs[i],
38391
+ });
38392
+ }
38393
+ fields = fields[0];
38394
+ }
38395
+ assertArgument(Array.isArray(fields) && (fields.length === 11 || fields.length === 14), `invalid field count for transaction type: ${typeName}`, "data", hexlify(data));
38396
+ const tx = {
38397
+ type: 3,
38398
+ chainId: handleUint(fields[0], "chainId"),
38399
+ nonce: handleNumber(fields[1], "nonce"),
38400
+ maxPriorityFeePerGas: handleUint(fields[2], "maxPriorityFeePerGas"),
38401
+ maxFeePerGas: handleUint(fields[3], "maxFeePerGas"),
38402
+ gasPrice: null,
38403
+ gasLimit: handleUint(fields[4], "gasLimit"),
38404
+ to: handleAddress(fields[5]),
38405
+ value: handleUint(fields[6], "value"),
38406
+ data: hexlify(fields[7]),
38407
+ accessList: handleAccessList(fields[8], "accessList"),
38408
+ maxFeePerBlobGas: handleUint(fields[9], "maxFeePerBlobGas"),
38409
+ blobVersionedHashes: fields[10]
38410
+ };
38411
+ if (blobs) {
38412
+ tx.blobs = blobs;
38413
+ }
38414
+ assertArgument(tx.to != null, `invalid address for transaction type: ${typeName}`, "data", data);
38415
+ assertArgument(Array.isArray(tx.blobVersionedHashes), "invalid blobVersionedHashes: must be an array", "data", data);
38416
+ for (let i = 0; i < tx.blobVersionedHashes.length; i++) {
38417
+ assertArgument(isHexString(tx.blobVersionedHashes[i], 32), `invalid blobVersionedHash at index ${i}: must be length 32`, "data", data);
38418
+ }
38419
+ // Unsigned EIP-4844 Transaction
38420
+ if (fields.length === 11) {
38421
+ return tx;
38422
+ }
38423
+ // @TODO: Do we need to do this? This is only called internally
38424
+ // and used to verify hashes; it might save time to not do this
38425
+ //tx.hash = keccak256(concat([ "0x03", encodeRlp(fields) ]));
38426
+ _parseEipSignature(tx, fields.slice(11));
38427
+ return tx;
38428
+ }
38429
+ function _serializeEip4844(tx, sig, blobs) {
38430
+ const fields = [
38431
+ formatNumber(tx.chainId, "chainId"),
38432
+ formatNumber(tx.nonce, "nonce"),
38433
+ formatNumber(tx.maxPriorityFeePerGas || 0, "maxPriorityFeePerGas"),
38434
+ formatNumber(tx.maxFeePerGas || 0, "maxFeePerGas"),
38435
+ formatNumber(tx.gasLimit, "gasLimit"),
38436
+ (tx.to || ZeroAddress),
38437
+ formatNumber(tx.value, "value"),
38438
+ tx.data,
38439
+ formatAccessList(tx.accessList || []),
38440
+ formatNumber(tx.maxFeePerBlobGas || 0, "maxFeePerBlobGas"),
38441
+ formatHashes(tx.blobVersionedHashes || [], "blobVersionedHashes")
38442
+ ];
38443
+ if (sig) {
38444
+ fields.push(formatNumber(sig.yParity, "yParity"));
38445
+ fields.push(toBeArray(sig.r));
38446
+ fields.push(toBeArray(sig.s));
38447
+ // We have blobs; return the network wrapped format
38448
+ if (blobs) {
38449
+ return concat([
38450
+ "0x03",
38451
+ encodeRlp([
38452
+ fields,
38453
+ blobs.map((b) => b.data),
38454
+ blobs.map((b) => b.commitment),
38455
+ blobs.map((b) => b.proof),
38456
+ ])
38457
+ ]);
38458
+ }
38459
+ }
38460
+ return concat(["0x03", encodeRlp(fields)]);
38461
+ }
37988
38462
  /**
37989
38463
  * A **Transaction** describes an operation to be executed on
37990
38464
  * Ethereum by an Externally Owned Account (EOA). It includes
@@ -38011,6 +38485,10 @@ class Transaction {
38011
38485
  #chainId;
38012
38486
  #sig;
38013
38487
  #accessList;
38488
+ #maxFeePerBlobGas;
38489
+ #blobVersionedHashes;
38490
+ #kzg;
38491
+ #blobs;
38014
38492
  /**
38015
38493
  * The transaction type.
38016
38494
  *
@@ -38037,6 +38515,11 @@ class Transaction {
38037
38515
  case "eip-1559":
38038
38516
  this.#type = 2;
38039
38517
  break;
38518
+ case 3:
38519
+ case "cancun":
38520
+ case "eip-4844":
38521
+ this.#type = 3;
38522
+ break;
38040
38523
  default:
38041
38524
  assertArgument(false, "unsupported transaction type", "type", value);
38042
38525
  }
@@ -38049,6 +38532,7 @@ class Transaction {
38049
38532
  case 0: return "legacy";
38050
38533
  case 1: return "eip-2930";
38051
38534
  case 2: return "eip-1559";
38535
+ case 3: return "eip-4844";
38052
38536
  }
38053
38537
  return null;
38054
38538
  }
@@ -38056,7 +38540,13 @@ class Transaction {
38056
38540
  * The ``to`` address for the transaction or ``null`` if the
38057
38541
  * transaction is an ``init`` transaction.
38058
38542
  */
38059
- get to() { return this.#to; }
38543
+ get to() {
38544
+ const value = this.#to;
38545
+ if (value == null && this.type === 3) {
38546
+ return ZeroAddress;
38547
+ }
38548
+ return value;
38549
+ }
38060
38550
  set to(value) {
38061
38551
  this.#to = (value == null) ? null : getAddress(value);
38062
38552
  }
@@ -38093,7 +38583,7 @@ class Transaction {
38093
38583
  get maxPriorityFeePerGas() {
38094
38584
  const value = this.#maxPriorityFeePerGas;
38095
38585
  if (value == null) {
38096
- if (this.type === 2) {
38586
+ if (this.type === 2 || this.type === 3) {
38097
38587
  return BN_0$4;
38098
38588
  }
38099
38589
  return null;
@@ -38110,7 +38600,7 @@ class Transaction {
38110
38600
  get maxFeePerGas() {
38111
38601
  const value = this.#maxFeePerGas;
38112
38602
  if (value == null) {
38113
- if (this.type === 2) {
38603
+ if (this.type === 2 || this.type === 3) {
38114
38604
  return BN_0$4;
38115
38605
  }
38116
38606
  return null;
@@ -38154,7 +38644,9 @@ class Transaction {
38154
38644
  get accessList() {
38155
38645
  const value = this.#accessList || null;
38156
38646
  if (value == null) {
38157
- if (this.type === 1 || this.type === 2) {
38647
+ if (this.type === 1 || this.type === 2 || this.type === 3) {
38648
+ // @TODO: in v7, this should assign the value or become
38649
+ // a live object itself, otherwise mutation is inconsistent
38158
38650
  return [];
38159
38651
  }
38160
38652
  return null;
@@ -38164,6 +38656,122 @@ class Transaction {
38164
38656
  set accessList(value) {
38165
38657
  this.#accessList = (value == null) ? null : accessListify(value);
38166
38658
  }
38659
+ /**
38660
+ * The max fee per blob gas for Cancun transactions.
38661
+ */
38662
+ get maxFeePerBlobGas() {
38663
+ const value = this.#maxFeePerBlobGas;
38664
+ if (value == null && this.type === 3) {
38665
+ return BN_0$4;
38666
+ }
38667
+ return value;
38668
+ }
38669
+ set maxFeePerBlobGas(value) {
38670
+ this.#maxFeePerBlobGas = (value == null) ? null : getBigInt(value, "maxFeePerBlobGas");
38671
+ }
38672
+ /**
38673
+ * The BLOb versioned hashes for Cancun transactions.
38674
+ */
38675
+ get blobVersionedHashes() {
38676
+ // @TODO: Mutation is inconsistent; if unset, the returned value
38677
+ // cannot mutate the object, if set it can
38678
+ let value = this.#blobVersionedHashes;
38679
+ if (value == null && this.type === 3) {
38680
+ return [];
38681
+ }
38682
+ return value;
38683
+ }
38684
+ set blobVersionedHashes(value) {
38685
+ if (value != null) {
38686
+ assertArgument(Array.isArray(value), "blobVersionedHashes must be an Array", "value", value);
38687
+ value = value.slice();
38688
+ for (let i = 0; i < value.length; i++) {
38689
+ assertArgument(isHexString(value[i], 32), "invalid blobVersionedHash", `value[${i}]`, value[i]);
38690
+ }
38691
+ }
38692
+ this.#blobVersionedHashes = value;
38693
+ }
38694
+ /**
38695
+ * The BLObs for the Transaction, if any.
38696
+ *
38697
+ * If ``blobs`` is non-``null``, then the [[seriailized]]
38698
+ * will return the network formatted sidecar, otherwise it
38699
+ * will return the standard [[link-eip-2718]] payload. The
38700
+ * [[unsignedSerialized]] is unaffected regardless.
38701
+ *
38702
+ * When setting ``blobs``, either fully valid [[Blob]] objects
38703
+ * may be specified (i.e. correctly padded, with correct
38704
+ * committments and proofs) or a raw [[BytesLike]] may
38705
+ * be provided.
38706
+ *
38707
+ * If raw [[BytesLike]] are provided, the [[kzg]] property **must**
38708
+ * be already set. The blob will be correctly padded and the
38709
+ * [[KzgLibrary]] will be used to compute the committment and
38710
+ * proof for the blob.
38711
+ *
38712
+ * A BLOb is a sequence of field elements, each of which must
38713
+ * be within the BLS field modulo, so some additional processing
38714
+ * may be required to encode arbitrary data to ensure each 32 byte
38715
+ * field is within the valid range.
38716
+ *
38717
+ * Setting this automatically populates [[blobVersionedHashes]],
38718
+ * overwriting any existing values. Setting this to ``null``
38719
+ * does **not** remove the [[blobVersionedHashes]], leaving them
38720
+ * present.
38721
+ */
38722
+ get blobs() {
38723
+ if (this.#blobs == null) {
38724
+ return null;
38725
+ }
38726
+ return this.#blobs.map((b) => Object.assign({}, b));
38727
+ }
38728
+ set blobs(_blobs) {
38729
+ if (_blobs == null) {
38730
+ this.#blobs = null;
38731
+ return;
38732
+ }
38733
+ const blobs = [];
38734
+ const versionedHashes = [];
38735
+ for (let i = 0; i < _blobs.length; i++) {
38736
+ const blob = _blobs[i];
38737
+ if (isBytesLike(blob)) {
38738
+ assert(this.#kzg, "adding a raw blob requires a KZG library", "UNSUPPORTED_OPERATION", {
38739
+ operation: "set blobs()"
38740
+ });
38741
+ let data = getBytes(blob);
38742
+ assertArgument(data.length <= BLOB_SIZE, "blob is too large", `blobs[${i}]`, blob);
38743
+ // Pad blob if necessary
38744
+ if (data.length !== BLOB_SIZE) {
38745
+ const padded = new Uint8Array(BLOB_SIZE);
38746
+ padded.set(data);
38747
+ data = padded;
38748
+ }
38749
+ const commit = this.#kzg.blobToKzgCommitment(data);
38750
+ const proof = hexlify(this.#kzg.computeBlobKzgProof(data, commit));
38751
+ blobs.push({
38752
+ data: hexlify(data),
38753
+ commitment: hexlify(commit),
38754
+ proof
38755
+ });
38756
+ versionedHashes.push(getVersionedHash(1, commit));
38757
+ }
38758
+ else {
38759
+ const commit = hexlify(blob.commitment);
38760
+ blobs.push({
38761
+ data: hexlify(blob.data),
38762
+ commitment: commit,
38763
+ proof: hexlify(blob.proof)
38764
+ });
38765
+ versionedHashes.push(getVersionedHash(1, commit));
38766
+ }
38767
+ }
38768
+ this.#blobs = blobs;
38769
+ this.#blobVersionedHashes = versionedHashes;
38770
+ }
38771
+ get kzg() { return this.#kzg; }
38772
+ set kzg(kzg) {
38773
+ this.#kzg = kzg;
38774
+ }
38167
38775
  /**
38168
38776
  * Creates a new Transaction with default values.
38169
38777
  */
@@ -38171,15 +38779,19 @@ class Transaction {
38171
38779
  this.#type = null;
38172
38780
  this.#to = null;
38173
38781
  this.#nonce = 0;
38174
- this.#gasLimit = BigInt(0);
38782
+ this.#gasLimit = BN_0$4;
38175
38783
  this.#gasPrice = null;
38176
38784
  this.#maxPriorityFeePerGas = null;
38177
38785
  this.#maxFeePerGas = null;
38178
38786
  this.#data = "0x";
38179
- this.#value = BigInt(0);
38180
- this.#chainId = BigInt(0);
38787
+ this.#value = BN_0$4;
38788
+ this.#chainId = BN_0$4;
38181
38789
  this.#sig = null;
38182
38790
  this.#accessList = null;
38791
+ this.#maxFeePerBlobGas = null;
38792
+ this.#blobVersionedHashes = null;
38793
+ this.#blobs = null;
38794
+ this.#kzg = null;
38183
38795
  }
38184
38796
  /**
38185
38797
  * The transaction hash, if signed. Otherwise, ``null``.
@@ -38188,7 +38800,7 @@ class Transaction {
38188
38800
  if (this.signature == null) {
38189
38801
  return null;
38190
38802
  }
38191
- return keccak256(this.serialized);
38803
+ return keccak256(this.#getSerialized(true, false));
38192
38804
  }
38193
38805
  /**
38194
38806
  * The pre-image hash of this transaction.
@@ -38224,9 +38836,23 @@ class Transaction {
38224
38836
  * transaction are non-null.
38225
38837
  */
38226
38838
  isSigned() {
38227
- //isSigned(): this is SignedTransaction {
38228
38839
  return this.signature != null;
38229
38840
  }
38841
+ #getSerialized(signed, sidecar) {
38842
+ assert(!signed || this.signature != null, "cannot serialize unsigned transaction; maybe you meant .unsignedSerialized", "UNSUPPORTED_OPERATION", { operation: ".serialized" });
38843
+ const sig = signed ? this.signature : null;
38844
+ switch (this.inferType()) {
38845
+ case 0:
38846
+ return _serializeLegacy(this, sig);
38847
+ case 1:
38848
+ return _serializeEip2930(this, sig);
38849
+ case 2:
38850
+ return _serializeEip1559(this, sig);
38851
+ case 3:
38852
+ return _serializeEip4844(this, sig, sidecar ? this.blobs : null);
38853
+ }
38854
+ assert(false, "unsupported transaction type", "UNSUPPORTED_OPERATION", { operation: ".serialized" });
38855
+ }
38230
38856
  /**
38231
38857
  * The serialized transaction.
38232
38858
  *
@@ -38234,16 +38860,7 @@ class Transaction {
38234
38860
  * use [[unsignedSerialized]].
38235
38861
  */
38236
38862
  get serialized() {
38237
- assert(this.signature != null, "cannot serialize unsigned transaction; maybe you meant .unsignedSerialized", "UNSUPPORTED_OPERATION", { operation: ".serialized" });
38238
- switch (this.inferType()) {
38239
- case 0:
38240
- return _serializeLegacy(this, this.signature);
38241
- case 1:
38242
- return _serializeEip2930(this, this.signature);
38243
- case 2:
38244
- return _serializeEip1559(this, this.signature);
38245
- }
38246
- assert(false, "unsupported transaction type", "UNSUPPORTED_OPERATION", { operation: ".serialized" });
38863
+ return this.#getSerialized(true, true);
38247
38864
  }
38248
38865
  /**
38249
38866
  * The transaction pre-image.
@@ -38252,22 +38869,20 @@ class Transaction {
38252
38869
  * authorize this transaction.
38253
38870
  */
38254
38871
  get unsignedSerialized() {
38255
- switch (this.inferType()) {
38256
- case 0:
38257
- return _serializeLegacy(this);
38258
- case 1:
38259
- return _serializeEip2930(this);
38260
- case 2:
38261
- return _serializeEip1559(this);
38262
- }
38263
- assert(false, "unsupported transaction type", "UNSUPPORTED_OPERATION", { operation: ".unsignedSerialized" });
38872
+ return this.#getSerialized(false, false);
38264
38873
  }
38265
38874
  /**
38266
38875
  * Return the most "likely" type; currently the highest
38267
38876
  * supported transaction type.
38268
38877
  */
38269
38878
  inferType() {
38270
- return (this.inferTypes().pop());
38879
+ const types = this.inferTypes();
38880
+ // Prefer London (EIP-1559) over Cancun (BLOb)
38881
+ if (types.indexOf(2) >= 0) {
38882
+ return 2;
38883
+ }
38884
+ // Return the highest inferred type
38885
+ return (types.pop());
38271
38886
  }
38272
38887
  /**
38273
38888
  * Validates the explicit properties and returns a list of compatible
@@ -38278,6 +38893,7 @@ class Transaction {
38278
38893
  const hasGasPrice = this.gasPrice != null;
38279
38894
  const hasFee = (this.maxFeePerGas != null || this.maxPriorityFeePerGas != null);
38280
38895
  const hasAccessList = (this.accessList != null);
38896
+ const hasBlob = (this.#maxFeePerBlobGas != null || this.#blobVersionedHashes);
38281
38897
  //if (hasGasPrice && hasFee) {
38282
38898
  // throw new Error("transaction cannot have gasPrice and maxFeePerGas");
38283
38899
  //}
@@ -38308,10 +38924,14 @@ class Transaction {
38308
38924
  types.push(1);
38309
38925
  types.push(2);
38310
38926
  }
38927
+ else if (hasBlob && this.to) {
38928
+ types.push(3);
38929
+ }
38311
38930
  else {
38312
38931
  types.push(0);
38313
38932
  types.push(1);
38314
38933
  types.push(2);
38934
+ types.push(3);
38315
38935
  }
38316
38936
  }
38317
38937
  types.sort();
@@ -38347,6 +38967,16 @@ class Transaction {
38347
38967
  isLondon() {
38348
38968
  return (this.type === 2);
38349
38969
  }
38970
+ /**
38971
+ * Returns true if this transaction is an [[link-eip-4844]] BLOB
38972
+ * transaction.
38973
+ *
38974
+ * This provides a Type Guard that the related properties are
38975
+ * non-null.
38976
+ */
38977
+ isCancun() {
38978
+ return (this.type === 3);
38979
+ }
38350
38980
  /**
38351
38981
  * Create a copy of this transaciton.
38352
38982
  */
@@ -38395,6 +39025,7 @@ class Transaction {
38395
39025
  switch (payload[0]) {
38396
39026
  case 1: return Transaction.from(_parseEip2930(payload));
38397
39027
  case 2: return Transaction.from(_parseEip1559(payload));
39028
+ case 3: return Transaction.from(_parseEip4844(payload));
38398
39029
  }
38399
39030
  assert(false, "unsupported transaction type", "UNSUPPORTED_OPERATION", { operation: "from" });
38400
39031
  }
@@ -38420,6 +39051,9 @@ class Transaction {
38420
39051
  if (tx.maxFeePerGas != null) {
38421
39052
  result.maxFeePerGas = tx.maxFeePerGas;
38422
39053
  }
39054
+ if (tx.maxFeePerBlobGas != null) {
39055
+ result.maxFeePerBlobGas = tx.maxFeePerBlobGas;
39056
+ }
38423
39057
  if (tx.data != null) {
38424
39058
  result.data = tx.data;
38425
39059
  }
@@ -38435,12 +39069,24 @@ class Transaction {
38435
39069
  if (tx.accessList != null) {
38436
39070
  result.accessList = tx.accessList;
38437
39071
  }
39072
+ // This will get overwritten by blobs, if present
39073
+ if (tx.blobVersionedHashes != null) {
39074
+ result.blobVersionedHashes = tx.blobVersionedHashes;
39075
+ }
39076
+ // Make sure we assign the kzg before assigning blobs, which
39077
+ // require the library in the event raw blob data is provided.
39078
+ if (tx.kzg != null) {
39079
+ result.kzg = tx.kzg;
39080
+ }
39081
+ if (tx.blobs != null) {
39082
+ result.blobs = tx.blobs;
39083
+ }
38438
39084
  if (tx.hash != null) {
38439
- assertArgument(result.isSigned(), "unsigned transaction cannot define hash", "tx", tx);
39085
+ assertArgument(result.isSigned(), "unsigned transaction cannot define '.hash'", "tx", tx);
38440
39086
  assertArgument(result.hash === tx.hash, "hash mismatch", "tx", tx);
38441
39087
  }
38442
39088
  if (tx.from != null) {
38443
- assertArgument(result.isSigned(), "unsigned transaction cannot define from", "tx", tx);
39089
+ assertArgument(result.isSigned(), "unsigned transaction cannot define '.from'", "tx", tx);
38444
39090
  assertArgument(result.from.toLowerCase() === (tx.from || "").toLowerCase(), "from mismatch", "tx", tx);
38445
39091
  }
38446
39092
  return result;
@@ -38507,11 +39153,11 @@ const domainChecks = {
38507
39153
  function getBaseEncoder(type) {
38508
39154
  // intXX and uintXX
38509
39155
  {
38510
- const match = type.match(/^(u?)int(\d*)$/);
39156
+ const match = type.match(/^(u?)int(\d+)$/);
38511
39157
  if (match) {
38512
39158
  const signed = (match[1] === "");
38513
- const width = parseInt(match[2] || "256");
38514
- assertArgument(width % 8 === 0 && width !== 0 && width <= 256 && (match[2] == null || match[2] === String(width)), "invalid numeric width", "type", type);
39159
+ const width = parseInt(match[2]);
39160
+ assertArgument(width % 8 === 0 && width !== 0 && width <= 256 && match[2] === String(width), "invalid numeric width", "type", type);
38515
39161
  const boundsUpper = mask(BN_MAX_UINT256, signed ? (width - 1) : width);
38516
39162
  const boundsLower = signed ? ((boundsUpper + BN_1) * BN__1) : BN_0$3;
38517
39163
  return function (_value) {
@@ -38553,6 +39199,23 @@ function getBaseEncoder(type) {
38553
39199
  function encodeType(name, fields) {
38554
39200
  return `${name}(${fields.map(({ name, type }) => (type + " " + name)).join(",")})`;
38555
39201
  }
39202
+ // foo[][3] => { base: "foo", index: "[][3]", array: {
39203
+ // base: "foo", prefix: "foo[]", count: 3 } }
39204
+ function splitArray(type) {
39205
+ const match = type.match(/^([^\x5b]*)((\x5b\d*\x5d)*)(\x5b(\d*)\x5d)$/);
39206
+ if (match) {
39207
+ return {
39208
+ base: match[1],
39209
+ index: (match[2] + match[4]),
39210
+ array: {
39211
+ base: match[1],
39212
+ prefix: (match[1] + match[2]),
39213
+ count: (match[5] ? parseInt(match[5]) : -1),
39214
+ }
39215
+ };
39216
+ }
39217
+ return { base: type };
39218
+ }
38556
39219
  /**
38557
39220
  * A **TypedDataEncode** prepares and encodes [[link-eip-712]] payloads
38558
39221
  * for signed typed data.
@@ -38587,8 +39250,7 @@ class TypedDataEncoder {
38587
39250
  * do not violate the [[link-eip-712]] structural constraints as
38588
39251
  * well as computes the [[primaryType]].
38589
39252
  */
38590
- constructor(types) {
38591
- this.#types = JSON.stringify(types);
39253
+ constructor(_types) {
38592
39254
  this.#fullTypes = new Map();
38593
39255
  this.#encoderCache = new Map();
38594
39256
  // Link struct types to their direct child structs
@@ -38597,26 +39259,39 @@ class TypedDataEncoder {
38597
39259
  const parents = new Map();
38598
39260
  // Link all subtypes within a given struct
38599
39261
  const subtypes = new Map();
38600
- Object.keys(types).forEach((type) => {
39262
+ const types = {};
39263
+ Object.keys(_types).forEach((type) => {
39264
+ types[type] = _types[type].map(({ name, type }) => {
39265
+ // Normalize the base type (unless name conflict)
39266
+ let { base, index } = splitArray(type);
39267
+ if (base === "int" && !_types["int"]) {
39268
+ base = "int256";
39269
+ }
39270
+ if (base === "uint" && !_types["uint"]) {
39271
+ base = "uint256";
39272
+ }
39273
+ return { name, type: (base + (index || "")) };
39274
+ });
38601
39275
  links.set(type, new Set());
38602
39276
  parents.set(type, []);
38603
39277
  subtypes.set(type, new Set());
38604
39278
  });
39279
+ this.#types = JSON.stringify(types);
38605
39280
  for (const name in types) {
38606
39281
  const uniqueNames = new Set();
38607
39282
  for (const field of types[name]) {
38608
39283
  // Check each field has a unique name
38609
- assertArgument(!uniqueNames.has(field.name), `duplicate variable name ${JSON.stringify(field.name)} in ${JSON.stringify(name)}`, "types", types);
39284
+ assertArgument(!uniqueNames.has(field.name), `duplicate variable name ${JSON.stringify(field.name)} in ${JSON.stringify(name)}`, "types", _types);
38610
39285
  uniqueNames.add(field.name);
38611
39286
  // Get the base type (drop any array specifiers)
38612
- const baseType = (field.type.match(/^([^\x5b]*)(\x5b|$)/))[1] || null;
38613
- assertArgument(baseType !== name, `circular type reference to ${JSON.stringify(baseType)}`, "types", types);
39287
+ const baseType = splitArray(field.type).base;
39288
+ assertArgument(baseType !== name, `circular type reference to ${JSON.stringify(baseType)}`, "types", _types);
38614
39289
  // Is this a base encoding type?
38615
39290
  const encoder = getBaseEncoder(baseType);
38616
39291
  if (encoder) {
38617
39292
  continue;
38618
39293
  }
38619
- assertArgument(parents.has(baseType), `unknown type ${JSON.stringify(baseType)}`, "types", types);
39294
+ assertArgument(parents.has(baseType), `unknown type ${JSON.stringify(baseType)}`, "types", _types);
38620
39295
  // Add linkage
38621
39296
  parents.get(baseType).push(name);
38622
39297
  links.get(name).add(baseType);
@@ -38624,12 +39299,12 @@ class TypedDataEncoder {
38624
39299
  }
38625
39300
  // Deduce the primary type
38626
39301
  const primaryTypes = Array.from(parents.keys()).filter((n) => (parents.get(n).length === 0));
38627
- assertArgument(primaryTypes.length !== 0, "missing primary type", "types", types);
38628
- assertArgument(primaryTypes.length === 1, `ambiguous primary types or unused types: ${primaryTypes.map((t) => (JSON.stringify(t))).join(", ")}`, "types", types);
39302
+ assertArgument(primaryTypes.length !== 0, "missing primary type", "types", _types);
39303
+ assertArgument(primaryTypes.length === 1, `ambiguous primary types or unused types: ${primaryTypes.map((t) => (JSON.stringify(t))).join(", ")}`, "types", _types);
38629
39304
  defineProperties(this, { primaryType: primaryTypes[0] });
38630
39305
  // Check for circular type references
38631
39306
  function checkCircular(type, found) {
38632
- assertArgument(!found.has(type), `circular type reference to ${JSON.stringify(type)}`, "types", types);
39307
+ assertArgument(!found.has(type), `circular type reference to ${JSON.stringify(type)}`, "types", _types);
38633
39308
  found.add(type);
38634
39309
  for (const child of links.get(type)) {
38635
39310
  if (!parents.has(child)) {
@@ -38672,12 +39347,12 @@ class TypedDataEncoder {
38672
39347
  }
38673
39348
  }
38674
39349
  // Array
38675
- const match = type.match(/^(.*)(\x5b(\d*)\x5d)$/);
38676
- if (match) {
38677
- const subtype = match[1];
39350
+ const array = splitArray(type).array;
39351
+ if (array) {
39352
+ const subtype = array.prefix;
38678
39353
  const subEncoder = this.getEncoder(subtype);
38679
39354
  return (value) => {
38680
- assertArgument(!match[3] || parseInt(match[3]) === value.length, `array length mismatch; expected length ${parseInt(match[3])}`, "value", value);
39355
+ assertArgument(array.count === -1 || array.count === value.length, `array length mismatch; expected length ${array.count}`, "value", value);
38681
39356
  let result = value.map(subEncoder);
38682
39357
  if (this.#fullTypes.has(subtype)) {
38683
39358
  result = result.map(keccak256);
@@ -38747,10 +39422,10 @@ class TypedDataEncoder {
38747
39422
  }
38748
39423
  }
38749
39424
  // Array
38750
- const match = type.match(/^(.*)(\x5b(\d*)\x5d)$/);
38751
- if (match) {
38752
- assertArgument(!match[3] || parseInt(match[3]) === value.length, `array length mismatch; expected length ${parseInt(match[3])}`, "value", value);
38753
- return value.map((v) => this._visit(match[1], v, callback));
39425
+ const array = splitArray(type).array;
39426
+ if (array) {
39427
+ assertArgument(array.count === -1 || array.count === value.length, `array length mismatch; expected length ${array.count}`, "value", value);
39428
+ return value.map((v) => this._visit(array.prefix, v, callback));
38754
39429
  }
38755
39430
  // Struct
38756
39431
  const fields = this.types[type];
@@ -38889,6 +39564,8 @@ class TypedDataEncoder {
38889
39564
  domainTypes.push({ name, type: domainFieldTypes[name] });
38890
39565
  });
38891
39566
  const encoder = TypedDataEncoder.from(types);
39567
+ // Get the normalized types
39568
+ types = encoder.types;
38892
39569
  const typesWithDomain = Object.assign({}, types);
38893
39570
  assertArgument(typesWithDomain.EIP712Domain == null, "types must not contain EIP712Domain type", "types.EIP712Domain", types);
38894
39571
  typesWithDomain.EIP712Domain = domainTypes;
@@ -38939,10 +39616,10 @@ function setify(items) {
38939
39616
  items.forEach((k) => result.add(k));
38940
39617
  return Object.freeze(result);
38941
39618
  }
38942
- const _kwVisibDeploy = "external public payable";
39619
+ const _kwVisibDeploy = "external public payable override";
38943
39620
  const KwVisibDeploy = setify(_kwVisibDeploy.split(" "));
38944
39621
  // Visibility Keywords
38945
- const _kwVisib = "constant external internal payable private public pure view";
39622
+ const _kwVisib = "constant external internal payable private public pure view override";
38946
39623
  const KwVisib = setify(_kwVisib.split(" "));
38947
39624
  const _kwTypes = "constructor error event fallback function receive struct";
38948
39625
  const KwTypes = setify(_kwTypes.split(" "));
@@ -38996,7 +39673,8 @@ class TokenString {
38996
39673
  // Pops and returns the value of the next token if it is `type`; throws if out of tokens
38997
39674
  popType(type) {
38998
39675
  if (this.peek().type !== type) {
38999
- throw new Error(`expected ${type}; got ${JSON.stringify(this.peek())}`);
39676
+ const top = this.peek();
39677
+ throw new Error(`expected ${type}; got ${top.type} ${JSON.stringify(top.text)}`);
39000
39678
  }
39001
39679
  return this.pop().text;
39002
39680
  }
@@ -39228,7 +39906,7 @@ function consumeGas(tokens) {
39228
39906
  }
39229
39907
  function consumeEoi(tokens) {
39230
39908
  if (tokens.length) {
39231
- throw new Error(`unexpected tokens: ${tokens.toString()}`);
39909
+ throw new Error(`unexpected tokens at offset ${tokens.offset}: ${tokens.toString()}`);
39232
39910
  }
39233
39911
  }
39234
39912
  const regexArrayType = new RegExp(/^(.*)\[([0-9]*)\]$/);
@@ -39376,9 +40054,6 @@ class ParamType {
39376
40054
  }
39377
40055
  else {
39378
40056
  if (this.isTuple()) {
39379
- if (format !== "sighash") {
39380
- result += this.type;
39381
- }
39382
40057
  result += "(" + this.components.map((comp) => comp.format(format)).join((format === "full") ? ", " : ",") + ")";
39383
40058
  }
39384
40059
  else {
@@ -39511,7 +40186,7 @@ class ParamType {
39511
40186
  * Walks the **ParamType** with %%value%%, asynchronously calling
39512
40187
  * %%process%% on each type, destructing the %%value%% recursively.
39513
40188
  *
39514
- * This can be used to resolve ENS naes by walking and resolving each
40189
+ * This can be used to resolve ENS names by walking and resolving each
39515
40190
  * ``"address"`` type.
39516
40191
  */
39517
40192
  async walkAsync(value, process) {
@@ -39920,7 +40595,9 @@ class ConstructorFragment extends Fragment {
39920
40595
  });
39921
40596
  }
39922
40597
  const result = [`constructor${joinParams(format, this.inputs)}`];
39923
- result.push((this.payable) ? "payable" : "nonpayable");
40598
+ if (this.payable) {
40599
+ result.push("payable");
40600
+ }
39924
40601
  if (this.gas != null) {
39925
40602
  result.push(`@${this.gas.toString()}`);
39926
40603
  }
@@ -40266,6 +40943,7 @@ PanicReasons$1.set(0x51, "UNINITIALIZED_FUNCTION_CALL");
40266
40943
  const paramTypeBytes = new RegExp(/^bytes([0-9]*)$/);
40267
40944
  const paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/);
40268
40945
  let defaultCoder = null;
40946
+ let defaultMaxInflation = 1024;
40269
40947
  function getBuiltinCallException(action, tx, data, abiCoder) {
40270
40948
  let message = "missing revert data";
40271
40949
  let reason = null;
@@ -40402,7 +41080,11 @@ class AbiCoder {
40402
41080
  decode(types, data, loose) {
40403
41081
  const coders = types.map((type) => this.#getCoder(ParamType.from(type)));
40404
41082
  const coder = new TupleCoder(coders, "_");
40405
- return coder.decode(new Reader(data, loose));
41083
+ return coder.decode(new Reader(data, loose, defaultMaxInflation));
41084
+ }
41085
+ static _setDefaultMaxInflation(value) {
41086
+ assertArgument(typeof (value) === "number" && Number.isInteger(value), "invalid defaultMaxInflation factor", "value", value);
41087
+ defaultMaxInflation = value;
40406
41088
  }
40407
41089
  /**
40408
41090
  * Returns the shared singleton instance of a default [[AbiCoder]].
@@ -40664,7 +41346,7 @@ class Interface {
40664
41346
  frags.push(Fragment.from(a));
40665
41347
  }
40666
41348
  catch (error) {
40667
- console.log("EE", error);
41349
+ console.log(`[Warning] Invalid Fragment ${JSON.stringify(a)}:`, error.message);
40668
41350
  }
40669
41351
  }
40670
41352
  defineProperties(this, {
@@ -41505,7 +42187,11 @@ getSelector(fragment: ErrorFragment | FunctionFragment): string {
41505
42187
  if (typeof (value) === "string") {
41506
42188
  return new Interface(JSON.parse(value));
41507
42189
  }
41508
- // Maybe an interface from an older version, or from a symlinked copy
42190
+ // An Interface; possibly from another v6 instance
42191
+ if (typeof (value.formatJson) === "function") {
42192
+ return new Interface(value.formatJson());
42193
+ }
42194
+ // A legacy Interface; from an older version
41509
42195
  if (typeof (value.format) === "function") {
41510
42196
  return new Interface(value.format("json"));
41511
42197
  }
@@ -41602,7 +42288,7 @@ function copyRequest(req) {
41602
42288
  if (req.data) {
41603
42289
  result.data = hexlify(req.data);
41604
42290
  }
41605
- const bigIntKeys = "chainId,gasLimit,gasPrice,maxFeePerGas,maxPriorityFeePerGas,value".split(/,/);
42291
+ const bigIntKeys = "chainId,gasLimit,gasPrice,maxFeePerBlobGas,maxFeePerGas,maxPriorityFeePerGas,value".split(/,/);
41606
42292
  for (const key of bigIntKeys) {
41607
42293
  if (!(key in req) || req[key] == null) {
41608
42294
  continue;
@@ -41628,6 +42314,20 @@ function copyRequest(req) {
41628
42314
  if ("customData" in req) {
41629
42315
  result.customData = req.customData;
41630
42316
  }
42317
+ if ("blobVersionedHashes" in req && req.blobVersionedHashes) {
42318
+ result.blobVersionedHashes = req.blobVersionedHashes.slice();
42319
+ }
42320
+ if ("kzg" in req) {
42321
+ result.kzg = req.kzg;
42322
+ }
42323
+ if ("blobs" in req && req.blobs) {
42324
+ result.blobs = req.blobs.map((b) => {
42325
+ if (isBytesLike(b)) {
42326
+ return hexlify(b);
42327
+ }
42328
+ return Object.assign({}, b);
42329
+ });
42330
+ }
41631
42331
  return result;
41632
42332
  }
41633
42333
  /**
@@ -41661,6 +42361,11 @@ class Block {
41661
42361
  * The block hash of the parent block.
41662
42362
  */
41663
42363
  parentHash;
42364
+ /**
42365
+ * The hash tree root of the parent beacon block for the given
42366
+ * execution block. See [[link-eip-4788]].
42367
+ */
42368
+ parentBeaconBlockRoot;
41664
42369
  /**
41665
42370
  * The nonce.
41666
42371
  *
@@ -41686,11 +42391,35 @@ class Block {
41686
42391
  * The total gas used in this block.
41687
42392
  */
41688
42393
  gasUsed;
42394
+ /**
42395
+ * The root hash for the global state after applying changes
42396
+ * in this block.
42397
+ */
42398
+ stateRoot;
42399
+ /**
42400
+ * The hash of the transaction receipts trie.
42401
+ */
42402
+ receiptsRoot;
42403
+ /**
42404
+ * The total amount of blob gas consumed by the transactions
42405
+ * within the block. See [[link-eip-4844]].
42406
+ */
42407
+ blobGasUsed;
42408
+ /**
42409
+ * The running total of blob gas consumed in excess of the
42410
+ * target, prior to the block. See [[link-eip-4844]].
42411
+ */
42412
+ excessBlobGas;
41689
42413
  /**
41690
42414
  * The miner coinbase address, wihch receives any subsidies for
41691
42415
  * including this block.
41692
42416
  */
41693
42417
  miner;
42418
+ /**
42419
+ * The latest RANDAO mix of the post beacon state of
42420
+ * the previous block.
42421
+ */
42422
+ prevRandao;
41694
42423
  /**
41695
42424
  * Any extra data the validator wished to include.
41696
42425
  */
@@ -41723,13 +42452,19 @@ class Block {
41723
42452
  number: block.number,
41724
42453
  timestamp: block.timestamp,
41725
42454
  parentHash: block.parentHash,
42455
+ parentBeaconBlockRoot: block.parentBeaconBlockRoot,
41726
42456
  nonce: block.nonce,
41727
42457
  difficulty: block.difficulty,
41728
42458
  gasLimit: block.gasLimit,
41729
42459
  gasUsed: block.gasUsed,
42460
+ blobGasUsed: block.blobGasUsed,
42461
+ excessBlobGas: block.excessBlobGas,
41730
42462
  miner: block.miner,
42463
+ prevRandao: getValue(block.prevRandao),
41731
42464
  extraData: block.extraData,
41732
- baseFeePerGas: getValue(block.baseFeePerGas)
42465
+ baseFeePerGas: getValue(block.baseFeePerGas),
42466
+ stateRoot: block.stateRoot,
42467
+ receiptsRoot: block.receiptsRoot,
41733
42468
  });
41734
42469
  }
41735
42470
  /**
@@ -41768,7 +42503,7 @@ class Block {
41768
42503
  * Returns a JSON-friendly value.
41769
42504
  */
41770
42505
  toJSON() {
41771
- const { baseFeePerGas, difficulty, extraData, gasLimit, gasUsed, hash, miner, nonce, number, parentHash, timestamp, transactions } = this;
42506
+ const { baseFeePerGas, difficulty, extraData, gasLimit, gasUsed, hash, miner, prevRandao, nonce, number, parentHash, parentBeaconBlockRoot, stateRoot, receiptsRoot, timestamp, transactions } = this;
41772
42507
  return {
41773
42508
  _type: "Block",
41774
42509
  baseFeePerGas: toJson(baseFeePerGas),
@@ -41776,7 +42511,10 @@ class Block {
41776
42511
  extraData,
41777
42512
  gasLimit: toJson(gasLimit),
41778
42513
  gasUsed: toJson(gasUsed),
41779
- hash, miner, nonce, number, parentHash, timestamp,
42514
+ blobGasUsed: toJson(this.blobGasUsed),
42515
+ excessBlobGas: toJson(this.excessBlobGas),
42516
+ hash, miner, prevRandao, nonce, number, parentHash, timestamp,
42517
+ parentBeaconBlockRoot, stateRoot, receiptsRoot,
41780
42518
  transactions,
41781
42519
  };
41782
42520
  }
@@ -42034,7 +42772,7 @@ class TransactionReceipt {
42034
42772
  */
42035
42773
  provider;
42036
42774
  /**
42037
- * The address the transaction was send to.
42775
+ * The address the transaction was sent to.
42038
42776
  */
42039
42777
  to;
42040
42778
  /**
@@ -42079,6 +42817,10 @@ class TransactionReceipt {
42079
42817
  * entire gas limit. After the transaction, the difference is refunded.
42080
42818
  */
42081
42819
  gasUsed;
42820
+ /**
42821
+ * The gas used for BLObs. See [[link-eip-4844]].
42822
+ */
42823
+ blobGasUsed;
42082
42824
  /**
42083
42825
  * The amount of gas used by all transactions within the block for this
42084
42826
  * and all transactions with a lower ``index``.
@@ -42095,6 +42837,10 @@ class TransactionReceipt {
42095
42837
  * fee is protocol-enforced.
42096
42838
  */
42097
42839
  gasPrice;
42840
+ /**
42841
+ * The price paid per BLOB in gas. See [[link-eip-4844]].
42842
+ */
42843
+ blobGasPrice;
42098
42844
  /**
42099
42845
  * The [[link-eip-2718]] transaction type.
42100
42846
  */
@@ -42142,7 +42888,9 @@ class TransactionReceipt {
42142
42888
  logsBloom: tx.logsBloom,
42143
42889
  gasUsed: tx.gasUsed,
42144
42890
  cumulativeGasUsed: tx.cumulativeGasUsed,
42891
+ blobGasUsed: tx.blobGasUsed,
42145
42892
  gasPrice,
42893
+ blobGasPrice: tx.blobGasPrice,
42146
42894
  type: tx.type,
42147
42895
  //byzantium: tx.byzantium,
42148
42896
  status: tx.status,
@@ -42167,6 +42915,8 @@ class TransactionReceipt {
42167
42915
  cumulativeGasUsed: toJson(this.cumulativeGasUsed),
42168
42916
  from,
42169
42917
  gasPrice: toJson(this.gasPrice),
42918
+ blobGasUsed: toJson(this.blobGasUsed),
42919
+ blobGasPrice: toJson(this.blobGasPrice),
42170
42920
  gasUsed: toJson(this.gasUsed),
42171
42921
  hash, index, logs, logsBloom, root, status, to
42172
42922
  };
@@ -42335,6 +43085,10 @@ class TransactionResponse {
42335
43085
  * to charge the sender.
42336
43086
  */
42337
43087
  maxFeePerGas;
43088
+ /**
43089
+ * The [[link-eip-4844]] max fee per BLOb gas.
43090
+ */
43091
+ maxFeePerBlobGas;
42338
43092
  /**
42339
43093
  * The data.
42340
43094
  */
@@ -42357,6 +43111,10 @@ class TransactionResponse {
42357
43111
  * support it, otherwise ``null``.
42358
43112
  */
42359
43113
  accessList;
43114
+ /**
43115
+ * The [[link-eip-4844]] BLOb versioned hashes.
43116
+ */
43117
+ blobVersionedHashes;
42360
43118
  #startBlock;
42361
43119
  /**
42362
43120
  * @_ignore:
@@ -42377,19 +43135,22 @@ class TransactionResponse {
42377
43135
  this.gasPrice = tx.gasPrice;
42378
43136
  this.maxPriorityFeePerGas = (tx.maxPriorityFeePerGas != null) ? tx.maxPriorityFeePerGas : null;
42379
43137
  this.maxFeePerGas = (tx.maxFeePerGas != null) ? tx.maxFeePerGas : null;
43138
+ this.maxFeePerBlobGas = (tx.maxFeePerBlobGas != null) ? tx.maxFeePerBlobGas : null;
42380
43139
  this.chainId = tx.chainId;
42381
43140
  this.signature = tx.signature;
42382
43141
  this.accessList = (tx.accessList != null) ? tx.accessList : null;
43142
+ this.blobVersionedHashes = (tx.blobVersionedHashes != null) ? tx.blobVersionedHashes : null;
42383
43143
  this.#startBlock = -1;
42384
43144
  }
42385
43145
  /**
42386
43146
  * Returns a JSON-compatible representation of this transaction.
42387
43147
  */
42388
43148
  toJSON() {
42389
- const { blockNumber, blockHash, index, hash, type, to, from, nonce, data, signature, accessList } = this;
43149
+ const { blockNumber, blockHash, index, hash, type, to, from, nonce, data, signature, accessList, blobVersionedHashes } = this;
42390
43150
  return {
42391
- _type: "TransactionReceipt",
43151
+ _type: "TransactionResponse",
42392
43152
  accessList, blockNumber, blockHash,
43153
+ blobVersionedHashes,
42393
43154
  chainId: toJson(this.chainId),
42394
43155
  data, from,
42395
43156
  gasLimit: toJson(this.gasLimit),
@@ -42397,6 +43158,7 @@ class TransactionResponse {
42397
43158
  hash,
42398
43159
  maxFeePerGas: toJson(this.maxFeePerGas),
42399
43160
  maxPriorityFeePerGas: toJson(this.maxPriorityFeePerGas),
43161
+ maxFeePerBlobGas: toJson(this.maxFeePerBlobGas),
42400
43162
  nonce, signature, to, index, type,
42401
43163
  value: toJson(this.value),
42402
43164
  };
@@ -42678,6 +43440,13 @@ class TransactionResponse {
42678
43440
  isLondon() {
42679
43441
  return (this.type === 2);
42680
43442
  }
43443
+ /**
43444
+ * Returns true if hte transaction is a Cancun (i.e. ``type == 3``)
43445
+ * transaction. See [[link-eip-4844]].
43446
+ */
43447
+ isCancun() {
43448
+ return (this.type === 3);
43449
+ }
42681
43450
  /**
42682
43451
  * Returns a filter which can be used to listen for orphan events
42683
43452
  * that evict this transaction.
@@ -42837,8 +43606,8 @@ class ContractTransactionResponse extends TransactionResponse {
42837
43606
  * and the transaction has not been mined, otherwise this will
42838
43607
  * wait until enough confirmations have completed.
42839
43608
  */
42840
- async wait(confirms) {
42841
- const receipt = await super.wait(confirms);
43609
+ async wait(confirms, timeout) {
43610
+ const receipt = await super.wait(confirms, timeout);
42842
43611
  if (receipt == null) {
42843
43612
  return null;
42844
43613
  }
@@ -43897,13 +44666,13 @@ class MulticoinProviderPlugin {
43897
44666
  return false;
43898
44667
  }
43899
44668
  /**
43900
- * Resovles to the encoded %%address%% for %%coinType%%.
44669
+ * Resolves to the encoded %%address%% for %%coinType%%.
43901
44670
  */
43902
44671
  async encodeAddress(coinType, address) {
43903
44672
  throw new Error("unsupported coin");
43904
44673
  }
43905
44674
  /**
43906
- * Resovles to the decoded %%data%% for %%coinType%%.
44675
+ * Resolves to the decoded %%data%% for %%coinType%%.
43907
44676
  */
43908
44677
  async decodeAddress(coinType, data) {
43909
44678
  throw new Error("unsupported coin");
@@ -43983,7 +44752,7 @@ class EnsResolver {
43983
44752
  info: { funcName }
43984
44753
  });
43985
44754
  params = [
43986
- dnsEncode(this.name),
44755
+ dnsEncode(this.name, 255),
43987
44756
  iface.encodeFunctionData(fragment, params)
43988
44757
  ];
43989
44758
  funcName = "resolve(bytes,bytes)";
@@ -44338,8 +45107,11 @@ function allowNull(format, nullValue) {
44338
45107
  return format(value);
44339
45108
  });
44340
45109
  }
44341
- function arrayOf(format) {
45110
+ function arrayOf(format, allowNull) {
44342
45111
  return ((array) => {
45112
+ if (allowNull && array == null) {
45113
+ return null;
45114
+ }
44343
45115
  if (!Array.isArray(array)) {
44344
45116
  throw new Error("not an array");
44345
45117
  }
@@ -44414,15 +45186,23 @@ function formatLog(value) {
44414
45186
  const _formatBlock = object({
44415
45187
  hash: allowNull(formatHash),
44416
45188
  parentHash: formatHash,
45189
+ parentBeaconBlockRoot: allowNull(formatHash, null),
44417
45190
  number: getNumber,
44418
45191
  timestamp: getNumber,
44419
45192
  nonce: allowNull(formatData),
44420
45193
  difficulty: getBigInt,
44421
45194
  gasLimit: getBigInt,
44422
45195
  gasUsed: getBigInt,
45196
+ stateRoot: allowNull(formatHash, null),
45197
+ receiptsRoot: allowNull(formatHash, null),
45198
+ blobGasUsed: allowNull(getBigInt, null),
45199
+ excessBlobGas: allowNull(getBigInt, null),
44423
45200
  miner: allowNull(getAddress),
45201
+ prevRandao: allowNull(formatHash, null),
44424
45202
  extraData: formatData,
44425
45203
  baseFeePerGas: allowNull(getBigInt)
45204
+ }, {
45205
+ prevRandao: ["mixHash"]
44426
45206
  });
44427
45207
  function formatBlock(value) {
44428
45208
  const result = _formatBlock(value);
@@ -44457,6 +45237,7 @@ const _formatTransactionReceipt = object({
44457
45237
  index: getNumber,
44458
45238
  root: allowNull(hexlify),
44459
45239
  gasUsed: getBigInt,
45240
+ blobGasUsed: allowNull(getBigInt, null),
44460
45241
  logsBloom: allowNull(formatData),
44461
45242
  blockHash: formatHash,
44462
45243
  hash: formatHash,
@@ -44465,6 +45246,7 @@ const _formatTransactionReceipt = object({
44465
45246
  //confirmations: allowNull(getNumber, null),
44466
45247
  cumulativeGasUsed: getBigInt,
44467
45248
  effectiveGasPrice: allowNull(getBigInt),
45249
+ blobGasPrice: allowNull(getBigInt, null),
44468
45250
  status: allowNull(getNumber),
44469
45251
  type: allowNull(getNumber, 0)
44470
45252
  }, {
@@ -44483,6 +45265,8 @@ function formatTransactionResponse(value) {
44483
45265
  }
44484
45266
  const result = object({
44485
45267
  hash: formatHash,
45268
+ // Some nodes do not return this, usually test nodes (like Ganache)
45269
+ index: allowNull(getNumber, undefined),
44486
45270
  type: (value) => {
44487
45271
  if (value === "0x" || value == null) {
44488
45272
  return 0;
@@ -44490,15 +45274,16 @@ function formatTransactionResponse(value) {
44490
45274
  return getNumber(value);
44491
45275
  },
44492
45276
  accessList: allowNull(accessListify, null),
45277
+ blobVersionedHashes: allowNull(arrayOf(formatHash, true), null),
44493
45278
  blockHash: allowNull(formatHash, null),
44494
45279
  blockNumber: allowNull(getNumber, null),
44495
45280
  transactionIndex: allowNull(getNumber, null),
44496
- //confirmations: allowNull(getNumber, null),
44497
45281
  from: getAddress,
44498
45282
  // either (gasPrice) or (maxPriorityFeePerGas + maxFeePerGas) must be set
44499
45283
  gasPrice: allowNull(getBigInt),
44500
45284
  maxPriorityFeePerGas: allowNull(getBigInt),
44501
45285
  maxFeePerGas: allowNull(getBigInt),
45286
+ maxFeePerBlobGas: allowNull(getBigInt, null),
44502
45287
  gasLimit: getBigInt,
44503
45288
  to: allowNull(getAddress, null),
44504
45289
  value: getBigInt,
@@ -44508,7 +45293,8 @@ function formatTransactionResponse(value) {
44508
45293
  chainId: allowNull(getBigInt, null)
44509
45294
  }, {
44510
45295
  data: ["input"],
44511
- gasLimit: ["gas"]
45296
+ gasLimit: ["gas"],
45297
+ index: ["transactionIndex"]
44512
45298
  })(value);
44513
45299
  // If to and creates are empty, populate the creates from the value
44514
45300
  if (result.to == null && result.creates == null) {
@@ -45034,23 +45820,6 @@ function getGasStationPlugin(url) {
45034
45820
  }
45035
45821
  });
45036
45822
  }
45037
- // Used by Optimism for a custom priority fee
45038
- function getPriorityFeePlugin(maxPriorityFeePerGas) {
45039
- return new FetchUrlFeeDataNetworkPlugin("data:", async (fetchFeeData, provider, request) => {
45040
- const feeData = await fetchFeeData();
45041
- // This should always fail
45042
- if (feeData.maxFeePerGas == null || feeData.maxPriorityFeePerGas == null) {
45043
- return feeData;
45044
- }
45045
- // Compute the corrected baseFee to recompute the updated values
45046
- const baseFee = feeData.maxFeePerGas - feeData.maxPriorityFeePerGas;
45047
- return {
45048
- gasPrice: feeData.gasPrice,
45049
- maxFeePerGas: (baseFee + maxPriorityFeePerGas),
45050
- maxPriorityFeePerGas
45051
- };
45052
- });
45053
- }
45054
45823
  // See: https://chainlist.org
45055
45824
  let injected = false;
45056
45825
  function injectCommonNetworks() {
@@ -45086,23 +45855,30 @@ function injectCommonNetworks() {
45086
45855
  registerEth("rinkeby", 4, { ensNetwork: 4 });
45087
45856
  registerEth("goerli", 5, { ensNetwork: 5 });
45088
45857
  registerEth("kovan", 42, { ensNetwork: 42 });
45089
- registerEth("sepolia", 11155111, {});
45858
+ registerEth("sepolia", 11155111, { ensNetwork: 11155111 });
45859
+ registerEth("holesky", 17000, { ensNetwork: 17000 });
45090
45860
  registerEth("classic", 61, {});
45091
45861
  registerEth("classicKotti", 6, {});
45092
45862
  registerEth("arbitrum", 42161, {
45093
45863
  ensNetwork: 1,
45094
45864
  });
45095
45865
  registerEth("arbitrum-goerli", 421613, {});
45866
+ registerEth("arbitrum-sepolia", 421614, {});
45867
+ registerEth("base", 8453, { ensNetwork: 1 });
45868
+ registerEth("base-goerli", 84531, {});
45869
+ registerEth("base-sepolia", 84532, {});
45096
45870
  registerEth("bnb", 56, { ensNetwork: 1 });
45097
45871
  registerEth("bnbt", 97, {});
45098
45872
  registerEth("linea", 59144, { ensNetwork: 1 });
45099
45873
  registerEth("linea-goerli", 59140, {});
45874
+ registerEth("linea-sepolia", 59141, {});
45100
45875
  registerEth("matic", 137, {
45101
45876
  ensNetwork: 1,
45102
45877
  plugins: [
45103
45878
  getGasStationPlugin("https:/\/gasstation.polygon.technology/v2")
45104
45879
  ]
45105
45880
  });
45881
+ registerEth("matic-amoy", 80002, {});
45106
45882
  registerEth("matic-mumbai", 80001, {
45107
45883
  altNames: ["maticMumbai", "maticmum"],
45108
45884
  plugins: [
@@ -45111,11 +45887,10 @@ function injectCommonNetworks() {
45111
45887
  });
45112
45888
  registerEth("optimism", 10, {
45113
45889
  ensNetwork: 1,
45114
- plugins: [
45115
- getPriorityFeePlugin(BigInt("1000000"))
45116
- ]
45890
+ plugins: []
45117
45891
  });
45118
45892
  registerEth("optimism-goerli", 420, {});
45893
+ registerEth("optimism-sepolia", 11155420, {});
45119
45894
  registerEth("xdai", 100, { ensNetwork: 1 });
45120
45895
  }
45121
45896
 
@@ -45249,6 +46024,34 @@ class OnBlockSubscriber {
45249
46024
  pause(dropWhilePaused) { this.stop(); }
45250
46025
  resume() { this.start(); }
45251
46026
  }
46027
+ class PollingBlockTagSubscriber extends OnBlockSubscriber {
46028
+ #tag;
46029
+ #lastBlock;
46030
+ constructor(provider, tag) {
46031
+ super(provider);
46032
+ this.#tag = tag;
46033
+ this.#lastBlock = -2;
46034
+ }
46035
+ pause(dropWhilePaused) {
46036
+ if (dropWhilePaused) {
46037
+ this.#lastBlock = -2;
46038
+ }
46039
+ super.pause(dropWhilePaused);
46040
+ }
46041
+ async _poll(blockNumber, provider) {
46042
+ const block = await provider.getBlock(this.#tag);
46043
+ if (block == null) {
46044
+ return;
46045
+ }
46046
+ if (this.#lastBlock === -2) {
46047
+ this.#lastBlock = block.number;
46048
+ }
46049
+ else if (block.number > this.#lastBlock) {
46050
+ provider.emit(this.#tag, block.number);
46051
+ this.#lastBlock = block.number;
46052
+ }
46053
+ }
46054
+ }
45252
46055
  /**
45253
46056
  * @_ignore:
45254
46057
  *
@@ -45447,10 +46250,12 @@ async function getSubscription(_event, provider) {
45447
46250
  if (typeof (_event) === "string") {
45448
46251
  switch (_event) {
45449
46252
  case "block":
45450
- case "pending":
45451
46253
  case "debug":
45452
46254
  case "error":
45453
- case "network": {
46255
+ case "finalized":
46256
+ case "network":
46257
+ case "pending":
46258
+ case "safe": {
45454
46259
  return { type: _event, tag: _event };
45455
46260
  }
45456
46261
  }
@@ -45748,10 +46553,10 @@ class AbstractProvider {
45748
46553
  switch (blockTag) {
45749
46554
  case "earliest":
45750
46555
  return "0x0";
46556
+ case "finalized":
45751
46557
  case "latest":
45752
46558
  case "pending":
45753
46559
  case "safe":
45754
- case "finalized":
45755
46560
  return blockTag;
45756
46561
  }
45757
46562
  if (isHexString(blockTag)) {
@@ -45855,7 +46660,7 @@ class AbstractProvider {
45855
46660
  return resolve(address, fromBlock, toBlock);
45856
46661
  }
45857
46662
  /**
45858
- * Returns or resovles to a transaction for %%request%%, resolving
46663
+ * Returns or resolves to a transaction for %%request%%, resolving
45859
46664
  * any ENS names or [[Addressable]] and returning if already a valid
45860
46665
  * transaction.
45861
46666
  */
@@ -45895,16 +46700,19 @@ class AbstractProvider {
45895
46700
  // No explicit network was set and this is our first time
45896
46701
  if (this.#networkPromise == null) {
45897
46702
  // Detect the current network (shared with all calls)
45898
- const detectNetwork = this._detectNetwork().then((network) => {
45899
- this.emit("network", network, null);
45900
- return network;
45901
- }, (error) => {
45902
- // Reset the networkPromise on failure, so we will try again
45903
- if (this.#networkPromise === detectNetwork) {
45904
- this.#networkPromise = null;
46703
+ const detectNetwork = (async () => {
46704
+ try {
46705
+ const network = await this._detectNetwork();
46706
+ this.emit("network", network, null);
46707
+ return network;
45905
46708
  }
45906
- throw error;
45907
- });
46709
+ catch (error) {
46710
+ if (this.#networkPromise === detectNetwork) {
46711
+ this.#networkPromise = null;
46712
+ }
46713
+ throw error;
46714
+ }
46715
+ })();
45908
46716
  this.#networkPromise = detectNetwork;
45909
46717
  return (await detectNetwork).clone();
45910
46718
  }
@@ -45934,12 +46742,20 @@ class AbstractProvider {
45934
46742
  async getFeeData() {
45935
46743
  const network = await this.getNetwork();
45936
46744
  const getFeeDataFunc = async () => {
45937
- const { _block, gasPrice } = await resolveProperties({
46745
+ const { _block, gasPrice, priorityFee } = await resolveProperties({
45938
46746
  _block: this.#getBlock("latest", false),
45939
46747
  gasPrice: ((async () => {
45940
46748
  try {
45941
- const gasPrice = await this.#perform({ method: "getGasPrice" });
45942
- return getBigInt(gasPrice, "%response");
46749
+ const value = await this.#perform({ method: "getGasPrice" });
46750
+ return getBigInt(value, "%response");
46751
+ }
46752
+ catch (error) { }
46753
+ return null;
46754
+ })()),
46755
+ priorityFee: ((async () => {
46756
+ try {
46757
+ const value = await this.#perform({ method: "getPriorityFee" });
46758
+ return getBigInt(value, "%response");
45943
46759
  }
45944
46760
  catch (error) { }
45945
46761
  return null;
@@ -45950,7 +46766,7 @@ class AbstractProvider {
45950
46766
  // These are the recommended EIP-1559 heuristics for fee data
45951
46767
  const block = this._wrapBlock(_block, network);
45952
46768
  if (block && block.baseFeePerGas) {
45953
- maxPriorityFeePerGas = BigInt("1000000000");
46769
+ maxPriorityFeePerGas = (priorityFee != null) ? priorityFee : BigInt("1000000000");
45954
46770
  maxFeePerGas = (block.baseFeePerGas * BN_2) + maxPriorityFeePerGas;
45955
46771
  }
45956
46772
  return new FeeData(gasPrice, maxFeePerGas, maxPriorityFeePerGas);
@@ -46328,6 +47144,9 @@ class AbstractProvider {
46328
47144
  subscriber.pollingInterval = this.pollingInterval;
46329
47145
  return subscriber;
46330
47146
  }
47147
+ case "safe":
47148
+ case "finalized":
47149
+ return new PollingBlockTagSubscriber(this, sub.type);
46331
47150
  case "event":
46332
47151
  return new PollingEventSubscriber(this, sub.filter);
46333
47152
  case "transaction":
@@ -46878,8 +47697,8 @@ class AbstractSigner {
46878
47697
  });
46879
47698
  }
46880
47699
  }
46881
- else if (pop.type === 2) {
46882
- // Explicitly using EIP-1559
47700
+ else if (pop.type === 2 || pop.type === 3) {
47701
+ // Explicitly using EIP-1559 or EIP-4844
46883
47702
  // Populate missing fee data
46884
47703
  if (pop.maxFeePerGas == null) {
46885
47704
  pop.maxFeePerGas = feeData.maxFeePerGas;
@@ -47009,6 +47828,9 @@ class FilterIdSubscriber {
47009
47828
  if (filterIdPromise) {
47010
47829
  this.#filterIdPromise = null;
47011
47830
  filterIdPromise.then((filterId) => {
47831
+ if (this.#provider.destroyed) {
47832
+ return;
47833
+ }
47012
47834
  this.#provider.send("eth_uninstallFilter", [filterId]);
47013
47835
  });
47014
47836
  }
@@ -47206,12 +48028,45 @@ class JsonRpcSigner extends AbstractSigner {
47206
48028
  // for it; it should show up very quickly
47207
48029
  return await (new Promise((resolve, reject) => {
47208
48030
  const timeouts = [1000, 100];
48031
+ let invalids = 0;
47209
48032
  const checkTx = async () => {
47210
- // Try getting the transaction
47211
- const tx = await this.provider.getTransaction(hash);
47212
- if (tx != null) {
47213
- resolve(tx.replaceableTransaction(blockNumber));
47214
- return;
48033
+ try {
48034
+ // Try getting the transaction
48035
+ const tx = await this.provider.getTransaction(hash);
48036
+ if (tx != null) {
48037
+ resolve(tx.replaceableTransaction(blockNumber));
48038
+ return;
48039
+ }
48040
+ }
48041
+ catch (error) {
48042
+ // If we were cancelled: stop polling.
48043
+ // If the data is bad: the node returns bad transactions
48044
+ // If the network changed: calling again will also fail
48045
+ // If unsupported: likely destroyed
48046
+ if (isError(error, "CANCELLED") || isError(error, "BAD_DATA") ||
48047
+ isError(error, "NETWORK_ERROR" )) {
48048
+ if (error.info == null) {
48049
+ error.info = {};
48050
+ }
48051
+ error.info.sendTransactionHash = hash;
48052
+ reject(error);
48053
+ return;
48054
+ }
48055
+ // Stop-gap for misbehaving backends; see #4513
48056
+ if (isError(error, "INVALID_ARGUMENT")) {
48057
+ invalids++;
48058
+ if (error.info == null) {
48059
+ error.info = {};
48060
+ }
48061
+ error.info.sendTransactionHash = hash;
48062
+ if (invalids > 10) {
48063
+ reject(error);
48064
+ return;
48065
+ }
48066
+ }
48067
+ // Notify anyone that cares; but we will try again, since
48068
+ // it is likely an intermittent service error
48069
+ this.provider.emit("error", makeError("failed to fetch transation after sending (will try again)", "UNKNOWN_ERROR", { error }));
47215
48070
  }
47216
48071
  // Wait another 4 seconds
47217
48072
  this.provider._setTimeout(() => { checkTx(); }, timeouts.pop() || 4000);
@@ -47284,11 +48139,12 @@ class JsonRpcApiProvider extends AbstractProvider {
47284
48139
  #drainTimer;
47285
48140
  #notReady;
47286
48141
  #network;
48142
+ #pendingDetectNetwork;
47287
48143
  #scheduleDrain() {
47288
48144
  if (this.#drainTimer) {
47289
48145
  return;
47290
48146
  }
47291
- // If we aren't using batching, no hard in sending it immeidately
48147
+ // If we aren't using batching, no harm in sending it immediately
47292
48148
  const stallTime = (this._getOption("batchMaxCount") === 1) ? 0 : this._getOption("batchStallTime");
47293
48149
  this.#drainTimer = setTimeout(() => {
47294
48150
  this.#drainTimer = null;
@@ -47359,6 +48215,7 @@ class JsonRpcApiProvider extends AbstractProvider {
47359
48215
  this.#payloads = [];
47360
48216
  this.#drainTimer = null;
47361
48217
  this.#network = null;
48218
+ this.#pendingDetectNetwork = null;
47362
48219
  {
47363
48220
  let resolve = null;
47364
48221
  const promise = new Promise((_resolve) => {
@@ -47366,9 +48223,15 @@ class JsonRpcApiProvider extends AbstractProvider {
47366
48223
  });
47367
48224
  this.#notReady = { promise, resolve };
47368
48225
  }
47369
- // Make sure any static network is compatbile with the provided netwrok
47370
48226
  const staticNetwork = this._getOption("staticNetwork");
47371
- if (staticNetwork) {
48227
+ if (typeof (staticNetwork) === "boolean") {
48228
+ assertArgument(!staticNetwork || network !== "any", "staticNetwork cannot be used on special network 'any'", "options", options);
48229
+ if (staticNetwork && network != null) {
48230
+ this.#network = Network.from(network);
48231
+ }
48232
+ }
48233
+ else if (staticNetwork) {
48234
+ // Make sure any static network is compatbile with the provided netwrok
47372
48235
  assertArgument(network == null || staticNetwork.matches(network), "staticNetwork MUST match network object", "options", options);
47373
48236
  this.#network = staticNetwork;
47374
48237
  }
@@ -47401,7 +48264,7 @@ class JsonRpcApiProvider extends AbstractProvider {
47401
48264
  if (req.method === "call" || req.method === "estimateGas") {
47402
48265
  let tx = req.transaction;
47403
48266
  if (tx && tx.type != null && getBigInt(tx.type)) {
47404
- // If there are no EIP-1559 properties, it might be non-EIP-a559
48267
+ // If there are no EIP-1559 or newer properties, it might be pre-EIP-1559
47405
48268
  if (tx.maxFeePerGas == null && tx.maxPriorityFeePerGas == null) {
47406
48269
  const feeData = await this.getFeeData();
47407
48270
  if (feeData.maxFeePerGas == null && feeData.maxPriorityFeePerGas == null) {
@@ -47429,30 +48292,56 @@ class JsonRpcApiProvider extends AbstractProvider {
47429
48292
  async _detectNetwork() {
47430
48293
  const network = this._getOption("staticNetwork");
47431
48294
  if (network) {
47432
- return network;
48295
+ if (network === true) {
48296
+ if (this.#network) {
48297
+ return this.#network;
48298
+ }
48299
+ }
48300
+ else {
48301
+ return network;
48302
+ }
48303
+ }
48304
+ if (this.#pendingDetectNetwork) {
48305
+ return await this.#pendingDetectNetwork;
47433
48306
  }
47434
48307
  // If we are ready, use ``send``, which enabled requests to be batched
47435
48308
  if (this.ready) {
47436
- return Network.from(getBigInt(await this.send("eth_chainId", [])));
48309
+ this.#pendingDetectNetwork = (async () => {
48310
+ try {
48311
+ const result = Network.from(getBigInt(await this.send("eth_chainId", [])));
48312
+ this.#pendingDetectNetwork = null;
48313
+ return result;
48314
+ }
48315
+ catch (error) {
48316
+ this.#pendingDetectNetwork = null;
48317
+ throw error;
48318
+ }
48319
+ })();
48320
+ return await this.#pendingDetectNetwork;
47437
48321
  }
47438
48322
  // We are not ready yet; use the primitive _send
47439
- const payload = {
47440
- id: this.#nextId++, method: "eth_chainId", params: [], jsonrpc: "2.0"
47441
- };
47442
- this.emit("debug", { action: "sendRpcPayload", payload });
47443
- let result;
47444
- try {
47445
- result = (await this._send(payload))[0];
47446
- }
47447
- catch (error) {
47448
- this.emit("debug", { action: "receiveRpcError", error });
47449
- throw error;
47450
- }
47451
- this.emit("debug", { action: "receiveRpcResult", result });
47452
- if ("result" in result) {
47453
- return Network.from(getBigInt(result.result));
47454
- }
47455
- throw this.getRpcError(payload, result);
48323
+ this.#pendingDetectNetwork = (async () => {
48324
+ const payload = {
48325
+ id: this.#nextId++, method: "eth_chainId", params: [], jsonrpc: "2.0"
48326
+ };
48327
+ this.emit("debug", { action: "sendRpcPayload", payload });
48328
+ let result;
48329
+ try {
48330
+ result = (await this._send(payload))[0];
48331
+ this.#pendingDetectNetwork = null;
48332
+ }
48333
+ catch (error) {
48334
+ this.#pendingDetectNetwork = null;
48335
+ this.emit("debug", { action: "receiveRpcError", error });
48336
+ throw error;
48337
+ }
48338
+ this.emit("debug", { action: "receiveRpcResult", result });
48339
+ if ("result" in result) {
48340
+ return Network.from(getBigInt(result.result));
48341
+ }
48342
+ throw this.getRpcError(payload, result);
48343
+ })();
48344
+ return await this.#pendingDetectNetwork;
47456
48345
  }
47457
48346
  /**
47458
48347
  * Sub-classes **MUST** call this. Until [[_start]] has been called, no calls
@@ -47554,6 +48443,14 @@ class JsonRpcApiProvider extends AbstractProvider {
47554
48443
  if (tx.accessList) {
47555
48444
  result["accessList"] = accessListify(tx.accessList);
47556
48445
  }
48446
+ if (tx.blobVersionedHashes) {
48447
+ // @TODO: Remove this <any> case once EIP-4844 added to prepared tx
48448
+ result["blobVersionedHashes"] = tx.blobVersionedHashes.map(h => h.toLowerCase());
48449
+ }
48450
+ // @TODO: blobs should probably also be copied over, optionally
48451
+ // accounting for the kzg property to backfill blobVersionedHashes
48452
+ // using the commitment. Or should that be left as an exercise to
48453
+ // the caller?
47557
48454
  return result;
47558
48455
  }
47559
48456
  /**
@@ -47568,6 +48465,8 @@ class JsonRpcApiProvider extends AbstractProvider {
47568
48465
  return { method: "eth_blockNumber", args: [] };
47569
48466
  case "getGasPrice":
47570
48467
  return { method: "eth_gasPrice", args: [] };
48468
+ case "getPriorityFee":
48469
+ return { method: "eth_maxPriorityFeePerGas", args: [] };
47571
48470
  case "getBalance":
47572
48471
  return {
47573
48472
  method: "eth_getBalance",
@@ -47818,7 +48717,11 @@ class JsonRpcApiPollingProvider extends JsonRpcApiProvider {
47818
48717
  #pollingInterval;
47819
48718
  constructor(network, options) {
47820
48719
  super(network, options);
47821
- this.#pollingInterval = 4000;
48720
+ let pollingInterval = this._getOption("pollingInterval");
48721
+ if (pollingInterval == null) {
48722
+ pollingInterval = defaultOptions.pollingInterval;
48723
+ }
48724
+ this.#pollingInterval = pollingInterval;
47822
48725
  }
47823
48726
  _getSubscriber(sub) {
47824
48727
  const subscriber = super._getSubscriber(sub);
@@ -51410,7 +52313,7 @@ class EthStateStorage {
51410
52313
  const chainId = getChainId(DID.blockchainFromId(idTyped), DID.networkIdFromId(idTyped));
51411
52314
  const config = this.networkByChainId(chainId);
51412
52315
  const provider = new JsonRpcProvider(config.url);
51413
- const stateContract = new Contract(config.contractAddress, abi$2, this.provider);
52316
+ const stateContract = new Contract(config.contractAddress, abi$2, provider);
51414
52317
  return { stateContract, provider };
51415
52318
  }
51416
52319
  networkByChainId(chainId) {
@@ -57933,7 +58836,7 @@ class IdentityWallet {
57933
58836
  * {@inheritDoc IIdentityWallet.createIdentity}
57934
58837
  */
57935
58838
  async createIdentity(opts) {
57936
- const tmpIdentifier = opts.seed ? v5(Hex.encode(sha256$3(opts.seed)), nil) : v4();
58839
+ const tmpIdentifier = opts.seed ? v5(Hex.encode(sha256$4(opts.seed)), nil) : v4();
57937
58840
  opts.seed = opts.seed ?? getRandomBytes(32);
57938
58841
  await this._storage.mt.createIdentityMerkleTrees(tmpIdentifier);
57939
58842
  const revNonce = opts.revocationOpts.nonce ?? 0;
@@ -58483,16 +59386,8 @@ class IdentityWallet {
58483
59386
  await this.updateIdentityState(did, true, newTreeState);
58484
59387
  return txId;
58485
59388
  }
58486
- /** {@inheritdoc IIdentityWallet.addBJJAuthCredential} */
58487
- async addBJJAuthCredential(did, oldTreeState, isOldStateGenesis, ethSigner, opts, prover // it will be needed in case of non ethereum identities
58488
- ) {
58489
- opts.seed = opts.seed ?? getRandomBytes(32);
58490
- opts.revocationOpts.nonce =
58491
- opts.revocationOpts.nonce ??
58492
- (isOldStateGenesis
58493
- ? 0
58494
- : opts.revocationOpts.nonce ?? new DataView(getRandomBytes(12).buffer).getUint32(0));
58495
- const { authClaim, pubKey } = await this.createAuthCoreClaim(opts.revocationOpts.nonce ?? 0, opts.seed);
59389
+ async getAuthBJJCredential(did, oldTreeState, { nonce, seed, id, type }) {
59390
+ const { authClaim, pubKey } = await this.createAuthCoreClaim(nonce, seed);
58496
59391
  const { hi, hv } = authClaim.hiHv();
58497
59392
  await this._storage.mt.addToMerkleTree(did.string(), MerkleTreeType.Claims, hi, hv);
58498
59393
  // Calculate current state after adding credential to merkle tree
@@ -58502,34 +59397,68 @@ class IdentityWallet {
58502
59397
  oldTreeState.revocationRoot.bigInt(),
58503
59398
  oldTreeState.rootOfRoots.bigInt()
58504
59399
  ]);
58505
- let credential = await this.createAuthBJJCredential(did, pubKey, authClaim, currentState, opts.revocationOpts);
58506
- const txId = await this.transitState(did, oldTreeState, isOldStateGenesis, ethSigner, prover);
58507
- const { receipt, block } = await this._transactionService.getTransactionReceiptAndBlock(txId);
58508
- const credsWithIden3MTPProof = await this.generateIden3SparseMerkleTreeProof(did, [credential], txId, receipt?.blockNumber, block?.timestamp, undefined, {
58509
- revNonce: Number(authClaim.getRevocationNonce()),
58510
- subjectPosition: SubjectPosition.None,
58511
- merklizedRootPosition: MerklizedRootPosition.None,
58512
- updatable: false,
58513
- version: 0,
58514
- merklizeOpts: { documentLoader: cacheLoader() }
59400
+ return this.createAuthBJJCredential(did, pubKey, authClaim, currentState, {
59401
+ id,
59402
+ type
58515
59403
  });
58516
- await this._credentialWallet.saveAll(credsWithIden3MTPProof);
58517
- await this._storage.identity.saveIdentity({
58518
- did: did.string(),
58519
- state: currentState,
58520
- isStatePublished: true,
58521
- isStateGenesis: false
59404
+ }
59405
+ /** {@inheritdoc IIdentityWallet.addBJJAuthCredential} */
59406
+ async addBJJAuthCredential(did, oldTreeState, isOldStateGenesis, ethSigner, opts, prover // it will be needed in case of non ethereum identities
59407
+ ) {
59408
+ opts.seed = opts.seed ?? getRandomBytes(32);
59409
+ opts.revocationOpts.nonce =
59410
+ opts.revocationOpts.nonce ??
59411
+ (isOldStateGenesis
59412
+ ? 0
59413
+ : opts.revocationOpts.nonce ?? new DataView(getRandomBytes(12).buffer).getUint32(0));
59414
+ const credential = await this.getAuthBJJCredential(did, oldTreeState, {
59415
+ nonce: opts.revocationOpts.nonce,
59416
+ seed: opts.seed,
59417
+ id: opts.revocationOpts.id,
59418
+ type: opts.revocationOpts.type
58522
59419
  });
58523
- const credRefreshed = await this._credentialWallet.findById(credential.id);
58524
- if (!credRefreshed) {
58525
- throw new Error('Credential not found in credential wallet');
59420
+ const addMtpToCredAndPublishRevState = async () => {
59421
+ const { receipt, block } = await this._transactionService.getTransactionReceiptAndBlock(txId);
59422
+ const credsWithIden3MTPProof = await this.generateIden3SparseMerkleTreeProof(did, [credential], txId, receipt?.blockNumber, block?.timestamp, undefined, {
59423
+ revNonce: opts.revocationOpts.nonce ?? 0,
59424
+ subjectPosition: SubjectPosition.None,
59425
+ merklizedRootPosition: MerklizedRootPosition.None,
59426
+ updatable: false,
59427
+ version: 0,
59428
+ merklizeOpts: { documentLoader: cacheLoader() }
59429
+ });
59430
+ await this._credentialWallet.saveAll(credsWithIden3MTPProof);
59431
+ await this.publishRevocationInfoByCredentialStatusType(did, opts.revocationOpts.type, {
59432
+ rhsUrl: opts.revocationOpts.id,
59433
+ onChain: opts.revocationOpts.onChain
59434
+ });
59435
+ return credsWithIden3MTPProof[0];
59436
+ };
59437
+ let txId = '';
59438
+ let attempt = 2;
59439
+ do {
59440
+ try {
59441
+ txId = await this.transitState(did, oldTreeState, isOldStateGenesis, ethSigner, prover);
59442
+ break;
59443
+ }
59444
+ catch (err) {
59445
+ console.warn(`Error while transiting state, retrying state transition, attempt: ${attempt}`, err);
59446
+ }
59447
+ } while (--attempt);
59448
+ if (!txId) {
59449
+ const oldTransitStateInfoJson = JSON.stringify({
59450
+ claimsRoot: oldTreeState.claimsRoot.hex(),
59451
+ revocationRoot: oldTreeState.revocationRoot.hex(),
59452
+ rootOfRoots: oldTreeState.rootOfRoots.hex(),
59453
+ state: oldTreeState.state.hex(),
59454
+ isOldStateGenesis,
59455
+ credentialId: credential.id,
59456
+ did: did.string()
59457
+ }, null, 2);
59458
+ await this._credentialWallet.save(credential);
59459
+ throw new Error(`Error publishing state, info to publish: ${oldTransitStateInfoJson}`);
58526
59460
  }
58527
- credential = credRefreshed;
58528
- await this.publishRevocationInfoByCredentialStatusType(did, opts.revocationOpts.type, {
58529
- rhsUrl: opts.revocationOpts.id,
58530
- onChain: opts.revocationOpts.onChain
58531
- });
58532
- return credential;
59461
+ return addMtpToCredAndPublishRevState();
58533
59462
  }
58534
59463
  }
58535
59464