@0xpolygonid/js-sdk 1.17.1 → 1.17.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2182,19 +2182,19 @@ var PolygonIdSdk = (function (exports) {
2182
2182
  }
2183
2183
  return [Ah, Al];
2184
2184
  }
2185
- const toBig = (h, l) => (BigInt(h >>> 0) << _32n$1) | BigInt(l >>> 0);
2185
+ const toBig$1 = (h, l) => (BigInt(h >>> 0) << _32n$1) | BigInt(l >>> 0);
2186
2186
  // for Shift in [0, 32)
2187
- const shrSH = (h, _l, s) => h >>> s;
2188
- const shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
2187
+ const shrSH$1 = (h, _l, s) => h >>> s;
2188
+ const shrSL$1 = (h, l, s) => (h << (32 - s)) | (l >>> s);
2189
2189
  // Right rotate for Shift in [1, 32)
2190
- const rotrSH = (h, l, s) => (h >>> s) | (l << (32 - s));
2191
- const rotrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
2190
+ const rotrSH$1 = (h, l, s) => (h >>> s) | (l << (32 - s));
2191
+ const rotrSL$1 = (h, l, s) => (h << (32 - s)) | (l >>> s);
2192
2192
  // Right rotate for Shift in (32, 64), NOTE: 32 is special case.
2193
- const rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));
2194
- const rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));
2193
+ const rotrBH$1 = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));
2194
+ const rotrBL$1 = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));
2195
2195
  // Right rotate for shift===32 (just swaps l&h)
2196
- const rotr32H = (_h, l) => l;
2197
- const rotr32L = (h, _l) => h;
2196
+ const rotr32H$1 = (_h, l) => l;
2197
+ const rotr32L$1 = (h, _l) => h;
2198
2198
  // Left rotate for Shift in [1, 32)
2199
2199
  const rotlSH$1 = (h, l, s) => (h << s) | (l >>> (32 - s));
2200
2200
  const rotlSL$1 = (h, l, s) => (l << s) | (h >>> (32 - s));
@@ -2203,30 +2203,30 @@ var PolygonIdSdk = (function (exports) {
2203
2203
  const rotlBL$1 = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));
2204
2204
  // JS uses 32-bit signed integers for bitwise operations which means we cannot
2205
2205
  // simple take carry out of low bit sum by shift, we need to use division.
2206
- function add$1(Ah, Al, Bh, Bl) {
2206
+ function add$2(Ah, Al, Bh, Bl) {
2207
2207
  const l = (Al >>> 0) + (Bl >>> 0);
2208
2208
  return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };
2209
2209
  }
2210
2210
  // Addition with more than 2 elements
2211
- const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
2212
- const add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
2213
- const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
2214
- const add4H = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;
2215
- const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
2216
- const add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;
2211
+ const add3L$1 = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
2212
+ const add3H$1 = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
2213
+ const add4L$1 = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
2214
+ const add4H$1 = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;
2215
+ const add5L$1 = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
2216
+ const add5H$1 = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;
2217
2217
  // prettier-ignore
2218
- const u64 = {
2219
- fromBig: fromBig$1, split: split$2, toBig,
2220
- shrSH, shrSL,
2221
- rotrSH, rotrSL, rotrBH, rotrBL,
2222
- rotr32H, rotr32L,
2218
+ const u64$1 = {
2219
+ fromBig: fromBig$1, split: split$2, toBig: toBig$1,
2220
+ shrSH: shrSH$1, shrSL: shrSL$1,
2221
+ rotrSH: rotrSH$1, rotrSL: rotrSL$1, rotrBH: rotrBH$1, rotrBL: rotrBL$1,
2222
+ rotr32H: rotr32H$1, rotr32L: rotr32L$1,
2223
2223
  rotlSH: rotlSH$1, rotlSL: rotlSL$1, rotlBH: rotlBH$1, rotlBL: rotlBL$1,
2224
- add: add$1, add3L, add3H, add4L, add4H, add5H, add5L,
2224
+ add: add$2, add3L: add3L$1, add3H: add3H$1, add4L: add4L$1, add4H: add4H$1, add5H: add5H$1, add5L: add5L$1,
2225
2225
  };
2226
2226
 
2227
2227
  // Round contants (first 32 bits of the fractional parts of the cube roots of the first 80 primes 2..409):
2228
2228
  // prettier-ignore
2229
- const [SHA512_Kh, SHA512_Kl] = /* @__PURE__ */ (() => u64.split([
2229
+ const [SHA512_Kh$1, SHA512_Kl$1] = /* @__PURE__ */ (() => u64$1.split([
2230
2230
  '0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc',
2231
2231
  '0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118',
2232
2232
  '0xd807aa98a3030242', '0x12835b0145706fbe', '0x243185be4ee4b28c', '0x550c7dc3d5ffb4e2',
@@ -2249,9 +2249,9 @@ var PolygonIdSdk = (function (exports) {
2249
2249
  '0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817'
2250
2250
  ].map(n => BigInt(n))))();
2251
2251
  // Temporary buffer, not used to store anything between runs
2252
- const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
2253
- const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
2254
- class SHA512 extends HashMD {
2252
+ const SHA512_W_H$1 = /* @__PURE__ */ new Uint32Array(80);
2253
+ const SHA512_W_L$1 = /* @__PURE__ */ new Uint32Array(80);
2254
+ let SHA512$1 = class SHA512 extends HashMD {
2255
2255
  constructor() {
2256
2256
  super(128, 64, 16, false);
2257
2257
  // We cannot use array here since array allows indexing by variable which means optimizer/compiler cannot use registers.
@@ -2302,43 +2302,43 @@ var PolygonIdSdk = (function (exports) {
2302
2302
  process(view, offset) {
2303
2303
  // Extend the first 16 words into the remaining 64 words w[16..79] of the message schedule array
2304
2304
  for (let i = 0; i < 16; i++, offset += 4) {
2305
- SHA512_W_H[i] = view.getUint32(offset);
2306
- SHA512_W_L[i] = view.getUint32((offset += 4));
2305
+ SHA512_W_H$1[i] = view.getUint32(offset);
2306
+ SHA512_W_L$1[i] = view.getUint32((offset += 4));
2307
2307
  }
2308
2308
  for (let i = 16; i < 80; i++) {
2309
2309
  // s0 := (w[i-15] rightrotate 1) xor (w[i-15] rightrotate 8) xor (w[i-15] rightshift 7)
2310
- const W15h = SHA512_W_H[i - 15] | 0;
2311
- const W15l = SHA512_W_L[i - 15] | 0;
2312
- const s0h = u64.rotrSH(W15h, W15l, 1) ^ u64.rotrSH(W15h, W15l, 8) ^ u64.shrSH(W15h, W15l, 7);
2313
- const s0l = u64.rotrSL(W15h, W15l, 1) ^ u64.rotrSL(W15h, W15l, 8) ^ u64.shrSL(W15h, W15l, 7);
2310
+ const W15h = SHA512_W_H$1[i - 15] | 0;
2311
+ const W15l = SHA512_W_L$1[i - 15] | 0;
2312
+ const s0h = u64$1.rotrSH(W15h, W15l, 1) ^ u64$1.rotrSH(W15h, W15l, 8) ^ u64$1.shrSH(W15h, W15l, 7);
2313
+ const s0l = u64$1.rotrSL(W15h, W15l, 1) ^ u64$1.rotrSL(W15h, W15l, 8) ^ u64$1.shrSL(W15h, W15l, 7);
2314
2314
  // s1 := (w[i-2] rightrotate 19) xor (w[i-2] rightrotate 61) xor (w[i-2] rightshift 6)
2315
- const W2h = SHA512_W_H[i - 2] | 0;
2316
- const W2l = SHA512_W_L[i - 2] | 0;
2317
- const s1h = u64.rotrSH(W2h, W2l, 19) ^ u64.rotrBH(W2h, W2l, 61) ^ u64.shrSH(W2h, W2l, 6);
2318
- const s1l = u64.rotrSL(W2h, W2l, 19) ^ u64.rotrBL(W2h, W2l, 61) ^ u64.shrSL(W2h, W2l, 6);
2315
+ const W2h = SHA512_W_H$1[i - 2] | 0;
2316
+ const W2l = SHA512_W_L$1[i - 2] | 0;
2317
+ const s1h = u64$1.rotrSH(W2h, W2l, 19) ^ u64$1.rotrBH(W2h, W2l, 61) ^ u64$1.shrSH(W2h, W2l, 6);
2318
+ const s1l = u64$1.rotrSL(W2h, W2l, 19) ^ u64$1.rotrBL(W2h, W2l, 61) ^ u64$1.shrSL(W2h, W2l, 6);
2319
2319
  // SHA256_W[i] = s0 + s1 + SHA256_W[i - 7] + SHA256_W[i - 16];
2320
- const SUMl = u64.add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
2321
- const SUMh = u64.add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
2322
- SHA512_W_H[i] = SUMh | 0;
2323
- SHA512_W_L[i] = SUMl | 0;
2320
+ const SUMl = u64$1.add4L(s0l, s1l, SHA512_W_L$1[i - 7], SHA512_W_L$1[i - 16]);
2321
+ const SUMh = u64$1.add4H(SUMl, s0h, s1h, SHA512_W_H$1[i - 7], SHA512_W_H$1[i - 16]);
2322
+ SHA512_W_H$1[i] = SUMh | 0;
2323
+ SHA512_W_L$1[i] = SUMl | 0;
2324
2324
  }
2325
2325
  let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
2326
2326
  // Compression function main loop, 80 rounds
2327
2327
  for (let i = 0; i < 80; i++) {
2328
2328
  // S1 := (e rightrotate 14) xor (e rightrotate 18) xor (e rightrotate 41)
2329
- const sigma1h = u64.rotrSH(Eh, El, 14) ^ u64.rotrSH(Eh, El, 18) ^ u64.rotrBH(Eh, El, 41);
2330
- const sigma1l = u64.rotrSL(Eh, El, 14) ^ u64.rotrSL(Eh, El, 18) ^ u64.rotrBL(Eh, El, 41);
2329
+ const sigma1h = u64$1.rotrSH(Eh, El, 14) ^ u64$1.rotrSH(Eh, El, 18) ^ u64$1.rotrBH(Eh, El, 41);
2330
+ const sigma1l = u64$1.rotrSL(Eh, El, 14) ^ u64$1.rotrSL(Eh, El, 18) ^ u64$1.rotrBL(Eh, El, 41);
2331
2331
  //const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
2332
2332
  const CHIh = (Eh & Fh) ^ (~Eh & Gh);
2333
2333
  const CHIl = (El & Fl) ^ (~El & Gl);
2334
2334
  // T1 = H + sigma1 + Chi(E, F, G) + SHA512_K[i] + SHA512_W[i]
2335
2335
  // prettier-ignore
2336
- const T1ll = u64.add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
2337
- const T1h = u64.add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
2336
+ const T1ll = u64$1.add5L(Hl, sigma1l, CHIl, SHA512_Kl$1[i], SHA512_W_L$1[i]);
2337
+ const T1h = u64$1.add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh$1[i], SHA512_W_H$1[i]);
2338
2338
  const T1l = T1ll | 0;
2339
2339
  // S0 := (a rightrotate 28) xor (a rightrotate 34) xor (a rightrotate 39)
2340
- const sigma0h = u64.rotrSH(Ah, Al, 28) ^ u64.rotrBH(Ah, Al, 34) ^ u64.rotrBH(Ah, Al, 39);
2341
- const sigma0l = u64.rotrSL(Ah, Al, 28) ^ u64.rotrBL(Ah, Al, 34) ^ u64.rotrBL(Ah, Al, 39);
2340
+ const sigma0h = u64$1.rotrSH(Ah, Al, 28) ^ u64$1.rotrBH(Ah, Al, 34) ^ u64$1.rotrBH(Ah, Al, 39);
2341
+ const sigma0l = u64$1.rotrSL(Ah, Al, 28) ^ u64$1.rotrBL(Ah, Al, 34) ^ u64$1.rotrBL(Ah, Al, 39);
2342
2342
  const MAJh = (Ah & Bh) ^ (Ah & Ch) ^ (Bh & Ch);
2343
2343
  const MAJl = (Al & Bl) ^ (Al & Cl) ^ (Bl & Cl);
2344
2344
  Hh = Gh | 0;
@@ -2347,38 +2347,38 @@ var PolygonIdSdk = (function (exports) {
2347
2347
  Gl = Fl | 0;
2348
2348
  Fh = Eh | 0;
2349
2349
  Fl = El | 0;
2350
- ({ h: Eh, l: El } = u64.add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
2350
+ ({ h: Eh, l: El } = u64$1.add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
2351
2351
  Dh = Ch | 0;
2352
2352
  Dl = Cl | 0;
2353
2353
  Ch = Bh | 0;
2354
2354
  Cl = Bl | 0;
2355
2355
  Bh = Ah | 0;
2356
2356
  Bl = Al | 0;
2357
- const All = u64.add3L(T1l, sigma0l, MAJl);
2358
- Ah = u64.add3H(All, T1h, sigma0h, MAJh);
2357
+ const All = u64$1.add3L(T1l, sigma0l, MAJl);
2358
+ Ah = u64$1.add3H(All, T1h, sigma0h, MAJh);
2359
2359
  Al = All | 0;
2360
2360
  }
2361
2361
  // Add the compressed chunk to the current hash value
2362
- ({ h: Ah, l: Al } = u64.add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
2363
- ({ h: Bh, l: Bl } = u64.add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
2364
- ({ h: Ch, l: Cl } = u64.add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
2365
- ({ h: Dh, l: Dl } = u64.add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
2366
- ({ h: Eh, l: El } = u64.add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
2367
- ({ h: Fh, l: Fl } = u64.add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
2368
- ({ h: Gh, l: Gl } = u64.add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
2369
- ({ h: Hh, l: Hl } = u64.add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
2362
+ ({ h: Ah, l: Al } = u64$1.add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
2363
+ ({ h: Bh, l: Bl } = u64$1.add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
2364
+ ({ h: Ch, l: Cl } = u64$1.add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
2365
+ ({ h: Dh, l: Dl } = u64$1.add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
2366
+ ({ h: Eh, l: El } = u64$1.add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
2367
+ ({ h: Fh, l: Fl } = u64$1.add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
2368
+ ({ h: Gh, l: Gl } = u64$1.add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
2369
+ ({ h: Hh, l: Hl } = u64$1.add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
2370
2370
  this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
2371
2371
  }
2372
2372
  roundClean() {
2373
- SHA512_W_H.fill(0);
2374
- SHA512_W_L.fill(0);
2373
+ SHA512_W_H$1.fill(0);
2374
+ SHA512_W_L$1.fill(0);
2375
2375
  }
2376
2376
  destroy() {
2377
2377
  this.buffer.fill(0);
2378
2378
  this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
2379
2379
  }
2380
- }
2381
- const sha512 = /* @__PURE__ */ wrapConstructor$1(() => new SHA512());
2380
+ };
2381
+ const sha512$1 = /* @__PURE__ */ wrapConstructor$1(() => new SHA512$1());
2382
2382
 
2383
2383
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2384
2384
  // 100 lines of code in the file are duplicated from noble-hashes (utils).
@@ -3707,7 +3707,7 @@ var PolygonIdSdk = (function (exports) {
3707
3707
  // Base point (x, y) aka generator point
3708
3708
  Gx: BigInt('15112221349535400772501151409588531511454012693041857206046113283949847762202'),
3709
3709
  Gy: BigInt('46316835694926478169428394003475163141307993866256225615783033603165251855960'),
3710
- hash: sha512,
3710
+ hash: sha512$1,
3711
3711
  randomBytes: randomBytes$1,
3712
3712
  adjustScalarBytes,
3713
3713
  // dom2
@@ -3924,7 +3924,7 @@ var PolygonIdSdk = (function (exports) {
3924
3924
  * SHA2-256 hash function
3925
3925
  * @param message - data that would be hashed
3926
3926
  */
3927
- const sha256$2 = /* @__PURE__ */ wrapConstructor$1(() => new SHA256$1());
3927
+ const sha256$3 = /* @__PURE__ */ wrapConstructor$1(() => new SHA256$1());
3928
3928
 
3929
3929
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
3930
3930
  // Short Weierstrass curve. The formula is: y² = x³ + ax + b
@@ -5027,7 +5027,7 @@ var PolygonIdSdk = (function (exports) {
5027
5027
  return { k1neg, k1, k2neg, k2 };
5028
5028
  },
5029
5029
  },
5030
- }, sha256$2);
5030
+ }, sha256$3);
5031
5031
  // Schnorr signatures are superior to ECDSA from above. Below is Schnorr-specific BIP0340 code.
5032
5032
  // https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
5033
5033
  BigInt(0);
@@ -6306,7 +6306,7 @@ var PolygonIdSdk = (function (exports) {
6306
6306
  Gy: BigInt('0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5'),
6307
6307
  h: BigInt(1),
6308
6308
  lowS: false,
6309
- }, sha256$2);
6309
+ }, sha256$3);
6310
6310
 
6311
6311
  // https://homes.esat.kuleuven.be/~bosselae/ripemd160.html
6312
6312
  // https://homes.esat.kuleuven.be/~bosselae/ripemd160/pdf/AB-9601/AB-9601.pdf
@@ -7084,9 +7084,9 @@ var PolygonIdSdk = (function (exports) {
7084
7084
  return '0'.repeat(size - data.length) + data;
7085
7085
  }
7086
7086
 
7087
- function sha256$1(payload) {
7087
+ function sha256$2(payload) {
7088
7088
  const data = typeof payload === 'string' ? fromString$1(payload) : payload;
7089
- return sha256$2(data);
7089
+ return sha256$3(data);
7090
7090
  }
7091
7091
  const keccak = keccak_256$1;
7092
7092
  function toEthereumAddress(hexPublicKey) {
@@ -7119,7 +7119,7 @@ var PolygonIdSdk = (function (exports) {
7119
7119
 
7120
7120
  return function (data) {
7121
7121
  try {
7122
- const signature = secp256k1$1.sign(sha256$1(data), privateKeyBytes);
7122
+ const signature = secp256k1$1.sign(sha256$2(data), privateKeyBytes);
7123
7123
  return Promise.resolve(toJose({
7124
7124
  r: leftpad(signature.r.toString(16)),
7125
7125
  s: leftpad(signature.s.toString(16)),
@@ -7135,10 +7135,10 @@ var PolygonIdSdk = (function (exports) {
7135
7135
  // Use the same version/prefix byte as the given address.
7136
7136
  const version = bytesToHex$1(base58ToBytes(otherAddress).slice(0, 1));
7137
7137
  const publicKeyBuffer = hexToBytes$1(publicKey);
7138
- const publicKeyHash = ripemd160(sha256$1(publicKeyBuffer));
7138
+ const publicKeyHash = ripemd160(sha256$2(publicKeyBuffer));
7139
7139
  const step1 = version + bytesToHex$1(publicKeyHash);
7140
- const step2 = sha256$1(hexToBytes$1(step1));
7141
- const step3 = sha256$1(step2);
7140
+ const step2 = sha256$2(hexToBytes$1(step1));
7141
+ const step3 = sha256$2(step2);
7142
7142
  const checksum = bytesToHex$1(step3).substring(0, 8);
7143
7143
  const step4 = step1 + checksum;
7144
7144
  return bytesToBase58(hexToBytes$1(step4));
@@ -7146,7 +7146,7 @@ var PolygonIdSdk = (function (exports) {
7146
7146
 
7147
7147
  function publicKeyToAddress(publicKey, prefix) {
7148
7148
  const publicKeyBuffer = secp256k1$1.ProjectivePoint.fromHex(publicKey).toRawBytes();
7149
- const hash = ripemd160(sha256$1(publicKeyBuffer));
7149
+ const hash = ripemd160(sha256$2(publicKeyBuffer));
7150
7150
  const words = bech32.toWords(hash);
7151
7151
  return bech32.encode(prefix, words).replace(prefix, '');
7152
7152
  }
@@ -7211,7 +7211,7 @@ var PolygonIdSdk = (function (exports) {
7211
7211
  };
7212
7212
  }
7213
7213
  function verifyES256(data, signature, authenticators) {
7214
- const hash = sha256$1(data);
7214
+ const hash = sha256$2(data);
7215
7215
  const sig = p256.Signature.fromCompact(toSignatureObject2(signature).compact);
7216
7216
  const fullPublicKeys = authenticators.filter(a => !a.ethereumAddress && !a.blockchainAccountId);
7217
7217
  const signer = fullPublicKeys.find(pk => {
@@ -7228,7 +7228,7 @@ var PolygonIdSdk = (function (exports) {
7228
7228
  return signer;
7229
7229
  }
7230
7230
  function verifyES256K(data, signature, authenticators) {
7231
- const hash = sha256$1(data);
7231
+ const hash = sha256$2(data);
7232
7232
  const signatureNormalized = secp256k1$1.Signature.fromCompact(base64ToBytes(signature)).normalizeS();
7233
7233
  const fullPublicKeys = authenticators.filter(a => {
7234
7234
  return !a.ethereumAddress && !a.blockchainAccountId;
@@ -7269,7 +7269,7 @@ var PolygonIdSdk = (function (exports) {
7269
7269
  });
7270
7270
  }
7271
7271
 
7272
- const hash = sha256$1(data);
7272
+ const hash = sha256$2(data);
7273
7273
 
7274
7274
  const checkSignatureAgainstSigner = sigObj => {
7275
7275
  const signature = secp256k1$1.Signature.fromCompact(sigObj.compact).addRecoveryBit(sigObj.recovery || 0);
@@ -30171,7 +30171,7 @@ var PolygonIdSdk = (function (exports) {
30171
30171
  /**
30172
30172
  * The current version of Ethers.
30173
30173
  */
30174
- const version = "6.8.0";
30174
+ const version = "6.13.1";
30175
30175
 
30176
30176
  /**
30177
30177
  * Property helper functions.
@@ -30277,7 +30277,7 @@ var PolygonIdSdk = (function (exports) {
30277
30277
  * Returns true if the %%error%% matches an error thrown by ethers
30278
30278
  * that matches the error %%code%%.
30279
30279
  *
30280
- * In TypeScript envornoments, this can be used to check that %%error%%
30280
+ * In TypeScript environments, this can be used to check that %%error%%
30281
30281
  * matches an EthersError type, which means the expected properties will
30282
30282
  * be set.
30283
30283
  *
@@ -30303,13 +30303,13 @@ var PolygonIdSdk = (function (exports) {
30303
30303
  }
30304
30304
  /**
30305
30305
  * Returns a new Error configured to the format ethers emits errors, with
30306
- * the %%message%%, [[api:ErrorCode]] %%code%% and additioanl properties
30306
+ * the %%message%%, [[api:ErrorCode]] %%code%% and additional properties
30307
30307
  * for the corresponding EthersError.
30308
30308
  *
30309
30309
  * Each error in ethers includes the version of ethers, a
30310
- * machine-readable [[ErrorCode]], and depneding on %%code%%, additional
30311
- * required properties. The error message will also include the %%meeage%%,
30312
- * ethers version, %%code%% and all aditional properties, serialized.
30310
+ * machine-readable [[ErrorCode]], and depending on %%code%%, additional
30311
+ * required properties. The error message will also include the %%message%%,
30312
+ * ethers version, %%code%% and all additional properties, serialized.
30313
30313
  */
30314
30314
  function makeError(message, code, info) {
30315
30315
  let shortMessage = message;
@@ -30391,7 +30391,7 @@ var PolygonIdSdk = (function (exports) {
30391
30391
  count: count,
30392
30392
  expectedCount: expectedCount
30393
30393
  });
30394
- assert$2(count <= expectedCount, "too many arguemnts" + message, "UNEXPECTED_ARGUMENT", {
30394
+ assert$2(count <= expectedCount, "too many arguments" + message, "UNEXPECTED_ARGUMENT", {
30395
30395
  count: count,
30396
30396
  expectedCount: expectedCount
30397
30397
  });
@@ -30461,7 +30461,7 @@ var PolygonIdSdk = (function (exports) {
30461
30461
  }
30462
30462
  return value;
30463
30463
  }
30464
- if (typeof (value) === "string" && value.match(/^0x([0-9a-f][0-9a-f])*$/i)) {
30464
+ if (typeof (value) === "string" && value.match(/^0x(?:[0-9a-f][0-9a-f])*$/i)) {
30465
30465
  const result = new Uint8Array((value.length - 2) / 2);
30466
30466
  let offset = 2;
30467
30467
  for (let i = 0; i < result.length; i++) {
@@ -30770,7 +30770,7 @@ var PolygonIdSdk = (function (exports) {
30770
30770
  }
30771
30771
  else {
30772
30772
  const width = getNumber(_width, "width");
30773
- assert$2(width * 2 >= result.length, `value exceeds width (${width} bits)`, "NUMERIC_FAULT", {
30773
+ assert$2(width * 2 >= result.length, `value exceeds width (${width} bytes)`, "NUMERIC_FAULT", {
30774
30774
  operation: "toBeHex",
30775
30775
  fault: "overflow",
30776
30776
  value: _value
@@ -30839,12 +30839,20 @@ var PolygonIdSdk = (function (exports) {
30839
30839
  * Encode %%value%% as a Base58-encoded string.
30840
30840
  */
30841
30841
  function encodeBase58(_value) {
30842
- let value = toBigInt(getBytes(_value));
30842
+ const bytes = getBytes(_value);
30843
+ let value = toBigInt(bytes);
30843
30844
  let result = "";
30844
30845
  while (value) {
30845
30846
  result = Alphabet[Number(value % BN_58)] + result;
30846
30847
  value /= BN_58;
30847
30848
  }
30849
+ // Account for leading padding zeros
30850
+ for (let i = 0; i < bytes.length; i++) {
30851
+ if (bytes[i]) {
30852
+ break;
30853
+ }
30854
+ result = Alphabet[0] + result;
30855
+ }
30848
30856
  return result;
30849
30857
  }
30850
30858
 
@@ -31061,6 +31069,7 @@ var PolygonIdSdk = (function (exports) {
31061
31069
  * If %%form%% is specified, the string is normalized.
31062
31070
  */
31063
31071
  function toUtf8Bytes(str, form) {
31072
+ assertArgument(typeof (str) === "string", "invalid string value", "str", str);
31064
31073
  if (form != null) {
31065
31074
  assertNormalize(form);
31066
31075
  str = str.normalize(form);
@@ -31115,9 +31124,9 @@ var PolygonIdSdk = (function (exports) {
31115
31124
  return _toUtf8String(getUtf8CodePoints(bytes, onError));
31116
31125
  }
31117
31126
 
31118
- // @TODO: timeout is completely ignored; start a Promise.any with a reject?
31119
31127
  function createGetUrl(options) {
31120
31128
  async function getUrl(req, _signal) {
31129
+ assert$2(_signal == null || !_signal.cancelled, "request cancelled before sending", "CANCELLED");
31121
31130
  const protocol = req.url.split(":")[0].toLowerCase();
31122
31131
  assert$2(protocol === "http" || protocol === "https", `unsupported protocol ${protocol}`, "UNSUPPORTED_OPERATION", {
31123
31132
  info: { protocol },
@@ -31126,19 +31135,36 @@ var PolygonIdSdk = (function (exports) {
31126
31135
  assert$2(protocol === "https" || !req.credentials || req.allowInsecureAuthentication, "insecure authorized connections unsupported", "UNSUPPORTED_OPERATION", {
31127
31136
  operation: "request"
31128
31137
  });
31129
- let signal = undefined;
31138
+ let error = null;
31139
+ const controller = new AbortController();
31140
+ const timer = setTimeout(() => {
31141
+ error = makeError("request timeout", "TIMEOUT");
31142
+ controller.abort();
31143
+ }, req.timeout);
31130
31144
  if (_signal) {
31131
- const controller = new AbortController();
31132
- signal = controller.signal;
31133
- _signal.addListener(() => { controller.abort(); });
31145
+ _signal.addListener(() => {
31146
+ error = makeError("request cancelled", "CANCELLED");
31147
+ controller.abort();
31148
+ });
31134
31149
  }
31135
31150
  const init = {
31136
31151
  method: req.method,
31137
31152
  headers: new Headers(Array.from(req)),
31138
31153
  body: req.body || undefined,
31139
- signal
31154
+ signal: controller.signal
31140
31155
  };
31141
- const resp = await fetch(req.url, init);
31156
+ let resp;
31157
+ try {
31158
+ resp = await fetch(req.url, init);
31159
+ }
31160
+ catch (_error) {
31161
+ clearTimeout(timer);
31162
+ if (error) {
31163
+ throw error;
31164
+ }
31165
+ throw _error;
31166
+ }
31167
+ clearTimeout(timer);
31142
31168
  const headers = {};
31143
31169
  resp.headers.forEach((value, key) => {
31144
31170
  headers[key.toLowerCase()] = value;
@@ -31156,7 +31182,7 @@ var PolygonIdSdk = (function (exports) {
31156
31182
 
31157
31183
  /**
31158
31184
  * Fetching content from the web is environment-specific, so Ethers
31159
- * provides an abstraction the each environment can implement to provide
31185
+ * provides an abstraction that each environment can implement to provide
31160
31186
  * this service.
31161
31187
  *
31162
31188
  * On [Node.js](link-node), the ``http`` and ``https`` libs are used to
@@ -31164,10 +31190,10 @@ var PolygonIdSdk = (function (exports) {
31164
31190
  * and populate the [[FetchResponse]].
31165
31191
  *
31166
31192
  * In a browser, the [DOM fetch](link-js-fetch) is used, and the resulting
31167
- * ``Promise`` is waited on to retreive the payload.
31193
+ * ``Promise`` is waited on to retrieve the payload.
31168
31194
  *
31169
31195
  * The [[FetchRequest]] is responsible for handling many common situations,
31170
- * such as redirects, server throttling, authentcation, etc.
31196
+ * such as redirects, server throttling, authentication, etc.
31171
31197
  *
31172
31198
  * It also handles common gateways, such as IPFS and data URIs.
31173
31199
  *
@@ -31291,7 +31317,7 @@ var PolygonIdSdk = (function (exports) {
31291
31317
  #throttle;
31292
31318
  #getUrlFunc;
31293
31319
  /**
31294
- * The fetch URI to requrest.
31320
+ * The fetch URL to request.
31295
31321
  */
31296
31322
  get url() { return this.#url; }
31297
31323
  set url(url) {
@@ -31305,15 +31331,15 @@ var PolygonIdSdk = (function (exports) {
31305
31331
  * header.
31306
31332
  *
31307
31333
  * If %%body%% is null, the body is cleared (along with the
31308
- * intrinsic ``Content-Type``) and the .
31334
+ * intrinsic ``Content-Type``).
31309
31335
  *
31310
- * If %%body%% is a string, the intrincis ``Content-Type`` is set to
31336
+ * If %%body%% is a string, the intrinsic ``Content-Type`` is set to
31311
31337
  * ``text/plain``.
31312
31338
  *
31313
- * If %%body%% is a Uint8Array, the intrincis ``Content-Type`` is set to
31339
+ * If %%body%% is a Uint8Array, the intrinsic ``Content-Type`` is set to
31314
31340
  * ``application/octet-stream``.
31315
31341
  *
31316
- * If %%body%% is any other object, the intrincis ``Content-Type`` is
31342
+ * If %%body%% is any other object, the intrinsic ``Content-Type`` is
31317
31343
  * set to ``application/json``.
31318
31344
  */
31319
31345
  get body() {
@@ -31373,7 +31399,7 @@ var PolygonIdSdk = (function (exports) {
31373
31399
  * The headers that will be used when requesting the URI. All
31374
31400
  * keys are lower-case.
31375
31401
  *
31376
- * This object is a copy, so any chnages will **NOT** be reflected
31402
+ * This object is a copy, so any changes will **NOT** be reflected
31377
31403
  * in the ``FetchRequest``.
31378
31404
  *
31379
31405
  * To set a header entry, use the ``setHeader`` method.
@@ -31465,7 +31491,7 @@ var PolygonIdSdk = (function (exports) {
31465
31491
  this.#allowInsecure = !!value;
31466
31492
  }
31467
31493
  /**
31468
- * The timeout (in milliseconds) to wait for a complere response.
31494
+ * The timeout (in milliseconds) to wait for a complete response.
31469
31495
  * //(default: 5 minutes)//
31470
31496
  */
31471
31497
  get timeout() { return this.#timeout; }
@@ -31672,7 +31698,7 @@ var PolygonIdSdk = (function (exports) {
31672
31698
  * to %%location%%.
31673
31699
  */
31674
31700
  redirect(location) {
31675
- // Redirection; for now we only support absolute locataions
31701
+ // Redirection; for now we only support absolute locations
31676
31702
  const current = this.url.split(":")[0].toLowerCase();
31677
31703
  const target = location.split(":")[0].toLowerCase();
31678
31704
  // Don't allow redirecting:
@@ -31724,6 +31750,7 @@ var PolygonIdSdk = (function (exports) {
31724
31750
  clone.#preflight = this.#preflight;
31725
31751
  clone.#process = this.#process;
31726
31752
  clone.#retry = this.#retry;
31753
+ clone.#throttle = Object.assign({}, this.#throttle);
31727
31754
  clone.#getUrlFunc = this.#getUrlFunc;
31728
31755
  return clone;
31729
31756
  }
@@ -31810,7 +31837,7 @@ var PolygonIdSdk = (function (exports) {
31810
31837
  }
31811
31838
  }
31812
31839
  /**
31813
- * The response for a FetchREquest.
31840
+ * The response for a FetchRequest.
31814
31841
  */
31815
31842
  class FetchResponse {
31816
31843
  #statusCode;
@@ -31940,7 +31967,7 @@ var PolygonIdSdk = (function (exports) {
31940
31967
  return this.headers[key.toLowerCase()];
31941
31968
  }
31942
31969
  /**
31943
- * Returns true of the response has a body.
31970
+ * Returns true if the response has a body.
31944
31971
  */
31945
31972
  hasBody() {
31946
31973
  return (this.#body != null);
@@ -31966,8 +31993,23 @@ var PolygonIdSdk = (function (exports) {
31966
31993
  if (message === "") {
31967
31994
  message = `server response ${this.statusCode} ${this.statusMessage}`;
31968
31995
  }
31996
+ let requestUrl = null;
31997
+ if (this.request) {
31998
+ requestUrl = this.request.url;
31999
+ }
32000
+ let responseBody = null;
32001
+ try {
32002
+ if (this.#body) {
32003
+ responseBody = toUtf8String(this.#body);
32004
+ }
32005
+ }
32006
+ catch (e) { }
31969
32007
  assert$2(false, message, "SERVER_ERROR", {
31970
- request: (this.request || "unknown request"), response: this, error
32008
+ request: (this.request || "unknown request"), response: this, error,
32009
+ info: {
32010
+ requestUrl, responseBody,
32011
+ responseStatus: `${this.statusCode} ${this.statusMessage}`
32012
+ }
31971
32013
  });
31972
32014
  }
31973
32015
  }
@@ -32114,11 +32156,38 @@ var PolygonIdSdk = (function (exports) {
32114
32156
  // - `then` is used to detect if an object is a Promise for await
32115
32157
  const passProperties$1 = ["then"];
32116
32158
  const _guard$2 = {};
32159
+ const resultNames = new WeakMap();
32160
+ function getNames(result) {
32161
+ return resultNames.get(result);
32162
+ }
32163
+ function setNames(result, names) {
32164
+ resultNames.set(result, names);
32165
+ }
32117
32166
  function throwError(name, error) {
32118
32167
  const wrapped = new Error(`deferred error during ABI decoding triggered accessing ${name}`);
32119
32168
  wrapped.error = error;
32120
32169
  throw wrapped;
32121
32170
  }
32171
+ function toObject(names, items, deep) {
32172
+ if (names.indexOf(null) >= 0) {
32173
+ return items.map((item, index) => {
32174
+ if (item instanceof Result) {
32175
+ return toObject(getNames(item), item, deep);
32176
+ }
32177
+ return item;
32178
+ });
32179
+ }
32180
+ return names.reduce((accum, name, index) => {
32181
+ let item = items.getValue(name);
32182
+ if (!(name in accum)) {
32183
+ if (deep && item instanceof Result) {
32184
+ item = toObject(getNames(item), item, deep);
32185
+ }
32186
+ accum[name] = item;
32187
+ }
32188
+ return accum;
32189
+ }, {});
32190
+ }
32122
32191
  /**
32123
32192
  * A [[Result]] is a sub-class of Array, which allows accessing any
32124
32193
  * of its values either positionally by its index or, if keys are
@@ -32127,6 +32196,9 @@ var PolygonIdSdk = (function (exports) {
32127
32196
  * @_docloc: api/abi
32128
32197
  */
32129
32198
  class Result extends Array {
32199
+ // No longer used; but cannot be removed as it will remove the
32200
+ // #private field from the .d.ts which may break backwards
32201
+ // compatibility
32130
32202
  #names;
32131
32203
  /**
32132
32204
  * @private
@@ -32159,20 +32231,22 @@ var PolygonIdSdk = (function (exports) {
32159
32231
  return accum;
32160
32232
  }, (new Map()));
32161
32233
  // Remove any key thats not unique
32162
- this.#names = Object.freeze(items.map((item, index) => {
32234
+ setNames(this, Object.freeze(items.map((item, index) => {
32163
32235
  const name = names[index];
32164
32236
  if (name != null && nameCounts.get(name) === 1) {
32165
32237
  return name;
32166
32238
  }
32167
32239
  return null;
32168
- }));
32240
+ })));
32241
+ // Dummy operations to prevent TypeScript from complaining
32242
+ this.#names = [];
32169
32243
  if (!wrap) {
32170
32244
  return;
32171
32245
  }
32172
32246
  // A wrapped Result is immutable
32173
32247
  Object.freeze(this);
32174
32248
  // Proxy indices and names so we can trap deferred errors
32175
- return new Proxy(this, {
32249
+ const proxy = new Proxy(this, {
32176
32250
  get: (target, prop, receiver) => {
32177
32251
  if (typeof (prop) === "string") {
32178
32252
  // Index accessor
@@ -32207,39 +32281,44 @@ var PolygonIdSdk = (function (exports) {
32207
32281
  return Reflect.get(target, prop, receiver);
32208
32282
  }
32209
32283
  });
32284
+ setNames(proxy, getNames(this));
32285
+ return proxy;
32210
32286
  }
32211
32287
  /**
32212
- * Returns the Result as a normal Array.
32288
+ * Returns the Result as a normal Array. If %%deep%%, any children
32289
+ * which are Result objects are also converted to a normal Array.
32213
32290
  *
32214
32291
  * This will throw if there are any outstanding deferred
32215
32292
  * errors.
32216
32293
  */
32217
- toArray() {
32294
+ toArray(deep) {
32218
32295
  const result = [];
32219
32296
  this.forEach((item, index) => {
32220
32297
  if (item instanceof Error) {
32221
32298
  throwError(`index ${index}`, item);
32222
32299
  }
32300
+ if (deep && item instanceof Result) {
32301
+ item = item.toArray(deep);
32302
+ }
32223
32303
  result.push(item);
32224
32304
  });
32225
32305
  return result;
32226
32306
  }
32227
32307
  /**
32228
- * Returns the Result as an Object with each name-value pair.
32308
+ * Returns the Result as an Object with each name-value pair. If
32309
+ * %%deep%%, any children which are Result objects are also
32310
+ * converted to an Object.
32229
32311
  *
32230
32312
  * This will throw if any value is unnamed, or if there are
32231
32313
  * any outstanding deferred errors.
32232
32314
  */
32233
- toObject() {
32234
- return this.#names.reduce((accum, name, index) => {
32235
- assert$2(name != null, "value at index ${ index } unnamed", "UNSUPPORTED_OPERATION", {
32315
+ toObject(deep) {
32316
+ const names = getNames(this);
32317
+ return names.reduce((accum, name, index) => {
32318
+ assert$2(name != null, `value at index ${index} unnamed`, "UNSUPPORTED_OPERATION", {
32236
32319
  operation: "toObject()"
32237
32320
  });
32238
- // Add values for names that don't conflict
32239
- if (!(name in accum)) {
32240
- accum[name] = this.getValue(name);
32241
- }
32242
- return accum;
32321
+ return toObject(names, this, deep);
32243
32322
  }, {});
32244
32323
  }
32245
32324
  /**
@@ -32267,10 +32346,11 @@ var PolygonIdSdk = (function (exports) {
32267
32346
  if (end > this.length) {
32268
32347
  end = this.length;
32269
32348
  }
32349
+ const _names = getNames(this);
32270
32350
  const result = [], names = [];
32271
32351
  for (let i = start; i < end; i++) {
32272
32352
  result.push(this[i]);
32273
- names.push(this.#names[i]);
32353
+ names.push(_names[i]);
32274
32354
  }
32275
32355
  return new Result(_guard$2, result, names);
32276
32356
  }
@@ -32278,6 +32358,7 @@ var PolygonIdSdk = (function (exports) {
32278
32358
  * @_ignore
32279
32359
  */
32280
32360
  filter(callback, thisArg) {
32361
+ const _names = getNames(this);
32281
32362
  const result = [], names = [];
32282
32363
  for (let i = 0; i < this.length; i++) {
32283
32364
  const item = this[i];
@@ -32286,7 +32367,7 @@ var PolygonIdSdk = (function (exports) {
32286
32367
  }
32287
32368
  if (callback.call(thisArg, item, i, this)) {
32288
32369
  result.push(item);
32289
- names.push(this.#names[i]);
32370
+ names.push(_names[i]);
32290
32371
  }
32291
32372
  }
32292
32373
  return new Result(_guard$2, result, names);
@@ -32314,7 +32395,7 @@ var PolygonIdSdk = (function (exports) {
32314
32395
  * accessible by name.
32315
32396
  */
32316
32397
  getValue(name) {
32317
- const index = this.#names.indexOf(name);
32398
+ const index = getNames(this).indexOf(name);
32318
32399
  if (index === -1) {
32319
32400
  return undefined;
32320
32401
  }
@@ -32424,15 +32505,35 @@ var PolygonIdSdk = (function (exports) {
32424
32505
  allowLoose;
32425
32506
  #data;
32426
32507
  #offset;
32427
- constructor(data, allowLoose) {
32508
+ #bytesRead;
32509
+ #parent;
32510
+ #maxInflation;
32511
+ constructor(data, allowLoose, maxInflation) {
32428
32512
  defineProperties(this, { allowLoose: !!allowLoose });
32429
32513
  this.#data = getBytesCopy(data);
32514
+ this.#bytesRead = 0;
32515
+ this.#parent = null;
32516
+ this.#maxInflation = (maxInflation != null) ? maxInflation : 1024;
32430
32517
  this.#offset = 0;
32431
32518
  }
32432
32519
  get data() { return hexlify(this.#data); }
32433
32520
  get dataLength() { return this.#data.length; }
32434
32521
  get consumed() { return this.#offset; }
32435
32522
  get bytes() { return new Uint8Array(this.#data); }
32523
+ #incrementBytesRead(count) {
32524
+ if (this.#parent) {
32525
+ return this.#parent.#incrementBytesRead(count);
32526
+ }
32527
+ this.#bytesRead += count;
32528
+ // Check for excessive inflation (see: #4537)
32529
+ assert$2(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", {
32530
+ buffer: getBytesCopy(this.#data), offset: this.#offset,
32531
+ length: count, info: {
32532
+ bytesRead: this.#bytesRead,
32533
+ dataLength: this.dataLength
32534
+ }
32535
+ });
32536
+ }
32436
32537
  #peekBytes(offset, length, loose) {
32437
32538
  let alignedLength = Math.ceil(length / WordSize) * WordSize;
32438
32539
  if (this.#offset + alignedLength > this.#data.length) {
@@ -32451,11 +32552,14 @@ var PolygonIdSdk = (function (exports) {
32451
32552
  }
32452
32553
  // Create a sub-reader with the same underlying data, but offset
32453
32554
  subReader(offset) {
32454
- return new Reader(this.#data.slice(this.#offset + offset), this.allowLoose);
32555
+ const reader = new Reader(this.#data.slice(this.#offset + offset), this.allowLoose, this.#maxInflation);
32556
+ reader.#parent = this;
32557
+ return reader;
32455
32558
  }
32456
32559
  // Read bytes
32457
32560
  readBytes(length, loose) {
32458
32561
  let bytes = this.#peekBytes(0, length, !!loose);
32562
+ this.#incrementBytesRead(length);
32459
32563
  this.#offset += bytes.length;
32460
32564
  // @TODO: Make sure the length..end bytes are all 0?
32461
32565
  return bytes.slice(0, length);
@@ -32871,7 +32975,7 @@ var PolygonIdSdk = (function (exports) {
32871
32975
  * SHA2-256 hash function
32872
32976
  * @param message - data that would be hashed
32873
32977
  */
32874
- const sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
32978
+ const sha256$1 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
32875
32979
 
32876
32980
  const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
32877
32981
  const _32n = /* @__PURE__ */ BigInt(32);
@@ -32890,12 +32994,225 @@ var PolygonIdSdk = (function (exports) {
32890
32994
  }
32891
32995
  return [Ah, Al];
32892
32996
  }
32997
+ const toBig = (h, l) => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);
32998
+ // for Shift in [0, 32)
32999
+ const shrSH = (h, _l, s) => h >>> s;
33000
+ const shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
33001
+ // Right rotate for Shift in [1, 32)
33002
+ const rotrSH = (h, l, s) => (h >>> s) | (l << (32 - s));
33003
+ const rotrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
33004
+ // Right rotate for Shift in (32, 64), NOTE: 32 is special case.
33005
+ const rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));
33006
+ const rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));
33007
+ // Right rotate for shift===32 (just swaps l&h)
33008
+ const rotr32H = (_h, l) => l;
33009
+ const rotr32L = (h, _l) => h;
32893
33010
  // Left rotate for Shift in [1, 32)
32894
33011
  const rotlSH = (h, l, s) => (h << s) | (l >>> (32 - s));
32895
33012
  const rotlSL = (h, l, s) => (l << s) | (h >>> (32 - s));
32896
33013
  // Left rotate for Shift in (32, 64), NOTE: 32 is special case.
32897
33014
  const rotlBH = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s));
32898
33015
  const rotlBL = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));
33016
+ // JS uses 32-bit signed integers for bitwise operations which means we cannot
33017
+ // simple take carry out of low bit sum by shift, we need to use division.
33018
+ function add$1(Ah, Al, Bh, Bl) {
33019
+ const l = (Al >>> 0) + (Bl >>> 0);
33020
+ return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };
33021
+ }
33022
+ // Addition with more than 2 elements
33023
+ const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
33024
+ const add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
33025
+ const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
33026
+ const add4H = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;
33027
+ const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
33028
+ const add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;
33029
+ // prettier-ignore
33030
+ const u64 = {
33031
+ fromBig, split: split$1, toBig,
33032
+ shrSH, shrSL,
33033
+ rotrSH, rotrSL, rotrBH, rotrBL,
33034
+ rotr32H, rotr32L,
33035
+ rotlSH, rotlSL, rotlBH, rotlBL,
33036
+ add: add$1, add3L, add3H, add4L, add4H, add5H, add5L,
33037
+ };
33038
+
33039
+ // Round contants (first 32 bits of the fractional parts of the cube roots of the first 80 primes 2..409):
33040
+ // prettier-ignore
33041
+ const [SHA512_Kh, SHA512_Kl] = /* @__PURE__ */ (() => u64.split([
33042
+ '0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc',
33043
+ '0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118',
33044
+ '0xd807aa98a3030242', '0x12835b0145706fbe', '0x243185be4ee4b28c', '0x550c7dc3d5ffb4e2',
33045
+ '0x72be5d74f27b896f', '0x80deb1fe3b1696b1', '0x9bdc06a725c71235', '0xc19bf174cf692694',
33046
+ '0xe49b69c19ef14ad2', '0xefbe4786384f25e3', '0x0fc19dc68b8cd5b5', '0x240ca1cc77ac9c65',
33047
+ '0x2de92c6f592b0275', '0x4a7484aa6ea6e483', '0x5cb0a9dcbd41fbd4', '0x76f988da831153b5',
33048
+ '0x983e5152ee66dfab', '0xa831c66d2db43210', '0xb00327c898fb213f', '0xbf597fc7beef0ee4',
33049
+ '0xc6e00bf33da88fc2', '0xd5a79147930aa725', '0x06ca6351e003826f', '0x142929670a0e6e70',
33050
+ '0x27b70a8546d22ffc', '0x2e1b21385c26c926', '0x4d2c6dfc5ac42aed', '0x53380d139d95b3df',
33051
+ '0x650a73548baf63de', '0x766a0abb3c77b2a8', '0x81c2c92e47edaee6', '0x92722c851482353b',
33052
+ '0xa2bfe8a14cf10364', '0xa81a664bbc423001', '0xc24b8b70d0f89791', '0xc76c51a30654be30',
33053
+ '0xd192e819d6ef5218', '0xd69906245565a910', '0xf40e35855771202a', '0x106aa07032bbd1b8',
33054
+ '0x19a4c116b8d2d0c8', '0x1e376c085141ab53', '0x2748774cdf8eeb99', '0x34b0bcb5e19b48a8',
33055
+ '0x391c0cb3c5c95a63', '0x4ed8aa4ae3418acb', '0x5b9cca4f7763e373', '0x682e6ff3d6b2b8a3',
33056
+ '0x748f82ee5defb2fc', '0x78a5636f43172f60', '0x84c87814a1f0ab72', '0x8cc702081a6439ec',
33057
+ '0x90befffa23631e28', '0xa4506cebde82bde9', '0xbef9a3f7b2c67915', '0xc67178f2e372532b',
33058
+ '0xca273eceea26619c', '0xd186b8c721c0c207', '0xeada7dd6cde0eb1e', '0xf57d4f7fee6ed178',
33059
+ '0x06f067aa72176fba', '0x0a637dc5a2c898a6', '0x113f9804bef90dae', '0x1b710b35131c471b',
33060
+ '0x28db77f523047d84', '0x32caab7b40c72493', '0x3c9ebe0a15c9bebc', '0x431d67c49c100d4c',
33061
+ '0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817'
33062
+ ].map(n => BigInt(n))))();
33063
+ // Temporary buffer, not used to store anything between runs
33064
+ const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
33065
+ const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
33066
+ class SHA512 extends SHA2 {
33067
+ constructor() {
33068
+ super(128, 64, 16, false);
33069
+ // We cannot use array here since array allows indexing by variable which means optimizer/compiler cannot use registers.
33070
+ // Also looks cleaner and easier to verify with spec.
33071
+ // Initial state (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
33072
+ // h -- high 32 bits, l -- low 32 bits
33073
+ this.Ah = 0x6a09e667 | 0;
33074
+ this.Al = 0xf3bcc908 | 0;
33075
+ this.Bh = 0xbb67ae85 | 0;
33076
+ this.Bl = 0x84caa73b | 0;
33077
+ this.Ch = 0x3c6ef372 | 0;
33078
+ this.Cl = 0xfe94f82b | 0;
33079
+ this.Dh = 0xa54ff53a | 0;
33080
+ this.Dl = 0x5f1d36f1 | 0;
33081
+ this.Eh = 0x510e527f | 0;
33082
+ this.El = 0xade682d1 | 0;
33083
+ this.Fh = 0x9b05688c | 0;
33084
+ this.Fl = 0x2b3e6c1f | 0;
33085
+ this.Gh = 0x1f83d9ab | 0;
33086
+ this.Gl = 0xfb41bd6b | 0;
33087
+ this.Hh = 0x5be0cd19 | 0;
33088
+ this.Hl = 0x137e2179 | 0;
33089
+ }
33090
+ // prettier-ignore
33091
+ get() {
33092
+ const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
33093
+ return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
33094
+ }
33095
+ // prettier-ignore
33096
+ set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
33097
+ this.Ah = Ah | 0;
33098
+ this.Al = Al | 0;
33099
+ this.Bh = Bh | 0;
33100
+ this.Bl = Bl | 0;
33101
+ this.Ch = Ch | 0;
33102
+ this.Cl = Cl | 0;
33103
+ this.Dh = Dh | 0;
33104
+ this.Dl = Dl | 0;
33105
+ this.Eh = Eh | 0;
33106
+ this.El = El | 0;
33107
+ this.Fh = Fh | 0;
33108
+ this.Fl = Fl | 0;
33109
+ this.Gh = Gh | 0;
33110
+ this.Gl = Gl | 0;
33111
+ this.Hh = Hh | 0;
33112
+ this.Hl = Hl | 0;
33113
+ }
33114
+ process(view, offset) {
33115
+ // Extend the first 16 words into the remaining 64 words w[16..79] of the message schedule array
33116
+ for (let i = 0; i < 16; i++, offset += 4) {
33117
+ SHA512_W_H[i] = view.getUint32(offset);
33118
+ SHA512_W_L[i] = view.getUint32((offset += 4));
33119
+ }
33120
+ for (let i = 16; i < 80; i++) {
33121
+ // s0 := (w[i-15] rightrotate 1) xor (w[i-15] rightrotate 8) xor (w[i-15] rightshift 7)
33122
+ const W15h = SHA512_W_H[i - 15] | 0;
33123
+ const W15l = SHA512_W_L[i - 15] | 0;
33124
+ const s0h = u64.rotrSH(W15h, W15l, 1) ^ u64.rotrSH(W15h, W15l, 8) ^ u64.shrSH(W15h, W15l, 7);
33125
+ const s0l = u64.rotrSL(W15h, W15l, 1) ^ u64.rotrSL(W15h, W15l, 8) ^ u64.shrSL(W15h, W15l, 7);
33126
+ // s1 := (w[i-2] rightrotate 19) xor (w[i-2] rightrotate 61) xor (w[i-2] rightshift 6)
33127
+ const W2h = SHA512_W_H[i - 2] | 0;
33128
+ const W2l = SHA512_W_L[i - 2] | 0;
33129
+ const s1h = u64.rotrSH(W2h, W2l, 19) ^ u64.rotrBH(W2h, W2l, 61) ^ u64.shrSH(W2h, W2l, 6);
33130
+ const s1l = u64.rotrSL(W2h, W2l, 19) ^ u64.rotrBL(W2h, W2l, 61) ^ u64.shrSL(W2h, W2l, 6);
33131
+ // SHA256_W[i] = s0 + s1 + SHA256_W[i - 7] + SHA256_W[i - 16];
33132
+ const SUMl = u64.add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
33133
+ const SUMh = u64.add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
33134
+ SHA512_W_H[i] = SUMh | 0;
33135
+ SHA512_W_L[i] = SUMl | 0;
33136
+ }
33137
+ let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
33138
+ // Compression function main loop, 80 rounds
33139
+ for (let i = 0; i < 80; i++) {
33140
+ // S1 := (e rightrotate 14) xor (e rightrotate 18) xor (e rightrotate 41)
33141
+ const sigma1h = u64.rotrSH(Eh, El, 14) ^ u64.rotrSH(Eh, El, 18) ^ u64.rotrBH(Eh, El, 41);
33142
+ const sigma1l = u64.rotrSL(Eh, El, 14) ^ u64.rotrSL(Eh, El, 18) ^ u64.rotrBL(Eh, El, 41);
33143
+ //const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
33144
+ const CHIh = (Eh & Fh) ^ (~Eh & Gh);
33145
+ const CHIl = (El & Fl) ^ (~El & Gl);
33146
+ // T1 = H + sigma1 + Chi(E, F, G) + SHA512_K[i] + SHA512_W[i]
33147
+ // prettier-ignore
33148
+ const T1ll = u64.add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
33149
+ const T1h = u64.add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
33150
+ const T1l = T1ll | 0;
33151
+ // S0 := (a rightrotate 28) xor (a rightrotate 34) xor (a rightrotate 39)
33152
+ const sigma0h = u64.rotrSH(Ah, Al, 28) ^ u64.rotrBH(Ah, Al, 34) ^ u64.rotrBH(Ah, Al, 39);
33153
+ const sigma0l = u64.rotrSL(Ah, Al, 28) ^ u64.rotrBL(Ah, Al, 34) ^ u64.rotrBL(Ah, Al, 39);
33154
+ const MAJh = (Ah & Bh) ^ (Ah & Ch) ^ (Bh & Ch);
33155
+ const MAJl = (Al & Bl) ^ (Al & Cl) ^ (Bl & Cl);
33156
+ Hh = Gh | 0;
33157
+ Hl = Gl | 0;
33158
+ Gh = Fh | 0;
33159
+ Gl = Fl | 0;
33160
+ Fh = Eh | 0;
33161
+ Fl = El | 0;
33162
+ ({ h: Eh, l: El } = u64.add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
33163
+ Dh = Ch | 0;
33164
+ Dl = Cl | 0;
33165
+ Ch = Bh | 0;
33166
+ Cl = Bl | 0;
33167
+ Bh = Ah | 0;
33168
+ Bl = Al | 0;
33169
+ const All = u64.add3L(T1l, sigma0l, MAJl);
33170
+ Ah = u64.add3H(All, T1h, sigma0h, MAJh);
33171
+ Al = All | 0;
33172
+ }
33173
+ // Add the compressed chunk to the current hash value
33174
+ ({ h: Ah, l: Al } = u64.add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
33175
+ ({ h: Bh, l: Bl } = u64.add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
33176
+ ({ h: Ch, l: Cl } = u64.add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
33177
+ ({ h: Dh, l: Dl } = u64.add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
33178
+ ({ h: Eh, l: El } = u64.add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
33179
+ ({ h: Fh, l: Fl } = u64.add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
33180
+ ({ h: Gh, l: Gl } = u64.add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
33181
+ ({ h: Hh, l: Hl } = u64.add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
33182
+ this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
33183
+ }
33184
+ roundClean() {
33185
+ SHA512_W_H.fill(0);
33186
+ SHA512_W_L.fill(0);
33187
+ }
33188
+ destroy() {
33189
+ this.buffer.fill(0);
33190
+ this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
33191
+ }
33192
+ }
33193
+ const sha512 = /* @__PURE__ */ wrapConstructor(() => new SHA512());
33194
+
33195
+ /* Browser Crypto Shims */
33196
+ function getGlobal() {
33197
+ if (typeof self !== 'undefined') {
33198
+ return self;
33199
+ }
33200
+ if (typeof window !== 'undefined') {
33201
+ return window;
33202
+ }
33203
+ if (typeof global !== 'undefined') {
33204
+ return global;
33205
+ }
33206
+ throw new Error('unable to locate global object');
33207
+ }
33208
+ getGlobal();
33209
+ function createHash(algo) {
33210
+ switch (algo) {
33211
+ case "sha256": return sha256$1.create();
33212
+ case "sha512": return sha512.create();
33213
+ }
33214
+ assertArgument(false, "invalid hashing algorithm name", "algorithm", algo);
33215
+ }
32899
33216
 
32900
33217
  // SHA3 (keccak) is based on a new design: basically, the internal state is bigger than output size.
32901
33218
  // It's called a sponge function.
@@ -33134,6 +33451,43 @@ var PolygonIdSdk = (function (exports) {
33134
33451
  };
33135
33452
  Object.freeze(keccak256);
33136
33453
 
33454
+ const _sha256 = function (data) {
33455
+ return createHash("sha256").update(data).digest();
33456
+ };
33457
+ let __sha256 = _sha256;
33458
+ let locked256 = false;
33459
+ /**
33460
+ * Compute the cryptographic SHA2-256 hash of %%data%%.
33461
+ *
33462
+ * @_docloc: api/crypto:Hash Functions
33463
+ * @returns DataHexstring
33464
+ *
33465
+ * @example:
33466
+ * sha256("0x")
33467
+ * //_result:
33468
+ *
33469
+ * sha256("0x1337")
33470
+ * //_result:
33471
+ *
33472
+ * sha256(new Uint8Array([ 0x13, 0x37 ]))
33473
+ * //_result:
33474
+ *
33475
+ */
33476
+ function sha256(_data) {
33477
+ const data = getBytes(_data, "data");
33478
+ return hexlify(__sha256(data));
33479
+ }
33480
+ sha256._ = _sha256;
33481
+ sha256.lock = function () { locked256 = true; };
33482
+ sha256.register = function (func) {
33483
+ if (locked256) {
33484
+ throw new Error("sha256 is locked");
33485
+ }
33486
+ __sha256 = func;
33487
+ };
33488
+ Object.freeze(sha256);
33489
+ Object.freeze(sha256);
33490
+
33137
33491
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
33138
33492
  // 100 lines of code in the file are duplicated from noble-hashes (utils).
33139
33493
  // This is OK: `abstract` directory does not use noble-hashes.
@@ -34949,7 +35303,7 @@ var PolygonIdSdk = (function (exports) {
34949
35303
  return { k1neg, k1, k2neg, k2 };
34950
35304
  },
34951
35305
  },
34952
- }, sha256);
35306
+ }, sha256$1);
34953
35307
  // Schnorr signatures are superior to ECDSA from above. Below is Schnorr-specific BIP0340 code.
34954
35308
  // https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
34955
35309
  BigInt(0);
@@ -36703,7 +37057,7 @@ var PolygonIdSdk = (function (exports) {
36703
37057
  return keccak256(toUtf8Bytes(value));
36704
37058
  }
36705
37059
 
36706
- // created 2023-09-12T22:05:14.211Z
37060
+ // created 2023-09-25T01:01:55.148Z
36707
37061
  // compressed base64-encoded blob for include-ens data
36708
37062
  // source: https://github.com/adraffy/ens-normalize.js/blob/main/src/make.js
36709
37063
  // see: https://github.com/adraffy/ens-normalize.js#security
@@ -36984,7 +37338,7 @@ var PolygonIdSdk = (function (exports) {
36984
37338
  return c;
36985
37339
  }
36986
37340
 
36987
- // created 2023-09-12T22:05:14.211Z
37341
+ // created 2023-09-25T01:01:55.148Z
36988
37342
  // compressed base64-encoded blob for include-nf data
36989
37343
  // source: https://github.com/adraffy/ens-normalize.js/blob/main/src/make.js
36990
37344
  // see: https://github.com/adraffy/ens-normalize.js#security
@@ -37200,6 +37554,7 @@ var PolygonIdSdk = (function (exports) {
37200
37554
  let r = read_compressed_payload(COMPRESSED$1);
37201
37555
  const read_sorted_array = () => read_sorted(r);
37202
37556
  const read_sorted_set = () => new Set(read_sorted_array());
37557
+ const set_add_many = (set, v) => v.forEach(x => set.add(x));
37203
37558
 
37204
37559
  MAPPED = new Map(read_mapped(r));
37205
37560
  IGNORED = read_sorted_set(); // ignored characters are not valid, so just read raw codepoints
@@ -37222,13 +37577,20 @@ var PolygonIdSdk = (function (exports) {
37222
37577
 
37223
37578
  let chunks = read_sorted_arrays(r);
37224
37579
  let unrestricted = r();
37225
- const read_chunked = () => new Set(read_sorted_array().flatMap(i => chunks[i]).concat(read_sorted_array()));
37580
+ //const read_chunked = () => new Set(read_sorted_array().flatMap(i => chunks[i]).concat(read_sorted_array()));
37581
+ const read_chunked = () => {
37582
+ // 20230921: build set in parts, 2x faster
37583
+ let set = new Set();
37584
+ read_sorted_array().forEach(i => set_add_many(set, chunks[i]));
37585
+ set_add_many(set, read_sorted_array());
37586
+ return set;
37587
+ };
37226
37588
  GROUPS = read_array_while(i => {
37227
37589
  // minifier property mangling seems unsafe
37228
37590
  // so these are manually renamed to single chars
37229
37591
  let N = read_array_while(r).map(x => x+0x60);
37230
37592
  if (N.length) {
37231
- let R = i >= unrestricted; // first arent restricted
37593
+ let R = i >= unrestricted; // unrestricted then restricted
37232
37594
  N[0] -= 32; // capitalize
37233
37595
  N = str_from_cps(N);
37234
37596
  if (R) N=`Restricted[${N}]`;
@@ -37266,6 +37628,7 @@ var PolygonIdSdk = (function (exports) {
37266
37628
  });
37267
37629
 
37268
37630
  // compute confusable-extent complements
37631
+ // usage: WHOLE_MAP.get(cp).M.get(cp) = complement set
37269
37632
  for (let {V, M} of new Set(WHOLE_MAP.values())) {
37270
37633
  // connect all groups that have each whole character
37271
37634
  let recs = [];
@@ -37277,34 +37640,37 @@ var PolygonIdSdk = (function (exports) {
37277
37640
  recs.push(rec);
37278
37641
  }
37279
37642
  rec.V.push(cp);
37280
- gs.forEach(g => rec.G.add(g));
37643
+ set_add_many(rec.G, gs);
37281
37644
  }
37282
37645
  // per character cache groups which are not a member of the extent
37283
- let union = recs.flatMap(x => Array_from(x.G));
37646
+ let union = recs.flatMap(x => Array_from(x.G)); // all of the groups used by this whole
37284
37647
  for (let {G, V} of recs) {
37285
- let complement = new Set(union.filter(g => !G.has(g)));
37648
+ let complement = new Set(union.filter(g => !G.has(g))); // groups not covered by the extent
37286
37649
  for (let cp of V) {
37287
- M.set(cp, complement);
37650
+ M.set(cp, complement); // this is the same reference
37288
37651
  }
37289
37652
  }
37290
37653
  }
37291
37654
 
37292
37655
  // compute valid set
37293
- let union = new Set(); // exists in 1+ groups
37656
+ // 20230924: VALID was union but can be re-used
37657
+ VALID = new Set(); // exists in 1+ groups
37294
37658
  let multi = new Set(); // exists in 2+ groups
37295
- const add_to_union = cp => union.has(cp) ? multi.add(cp) : union.add(cp);
37659
+ const add_to_union = cp => VALID.has(cp) ? multi.add(cp) : VALID.add(cp);
37296
37660
  for (let g of GROUPS) {
37297
37661
  for (let cp of g.P) add_to_union(cp);
37298
37662
  for (let cp of g.Q) add_to_union(cp);
37299
37663
  }
37300
37664
  // dual purpose WHOLE_MAP: return placeholder if unique non-confusable
37301
- for (let cp of union) {
37665
+ for (let cp of VALID) {
37302
37666
  if (!WHOLE_MAP.has(cp) && !multi.has(cp)) {
37303
37667
  WHOLE_MAP.set(cp, UNIQUE_PH);
37304
37668
  }
37305
37669
  }
37306
- VALID = new Set(Array_from(union).concat(Array_from(nfd(union)))); // possibly valid
37307
-
37670
+ // add all decomposed parts
37671
+ // see derive: "Valid is Closed (via Brute-force)"
37672
+ set_add_many(VALID, nfd(VALID));
37673
+
37308
37674
  // decode emoji
37309
37675
  // 20230719: emoji are now fully-expanded to avoid quirk logic
37310
37676
  EMOJI_LIST = read_trie(r).map(v => Emoji.from(v)).sort(compare_arrays);
@@ -37357,7 +37723,7 @@ var PolygonIdSdk = (function (exports) {
37357
37723
 
37358
37724
  function check_label_extension(cps) {
37359
37725
  if (cps.length >= 4 && cps[2] == HYPHEN && cps[3] == HYPHEN) {
37360
- throw new Error(`invalid label extension: "${str_from_cps(cps.slice(0, 4))}"`);
37726
+ throw new Error(`invalid label extension: "${str_from_cps(cps.slice(0, 4))}"`); // this can only be ascii so cant be bidi
37361
37727
  }
37362
37728
  }
37363
37729
  function check_leading_underscore(cps) {
@@ -37391,13 +37757,18 @@ var PolygonIdSdk = (function (exports) {
37391
37757
  // create a safe to print string
37392
37758
  // invisibles are escaped
37393
37759
  // leading cm uses placeholder
37760
+ // if cps exceed max, middle truncate with ellipsis
37394
37761
  // quoter(cp) => string, eg. 3000 => "{3000}"
37395
37762
  // note: in html, you'd call this function then replace [<>&] with entities
37396
- function safe_str_from_cps(cps, quoter = quote_cp) {
37763
+ function safe_str_from_cps(cps, max = Infinity, quoter = quote_cp) {
37397
37764
  //if (Number.isInteger(cps)) cps = [cps];
37398
37765
  //if (!Array.isArray(cps)) throw new TypeError(`expected codepoints`);
37399
37766
  let buf = [];
37400
37767
  if (is_combining_mark(cps[0])) buf.push('◌');
37768
+ if (cps.length > max) {
37769
+ max >>= 1;
37770
+ cps = [...cps.slice(0, max), 0x2026, ...cps.slice(-max)];
37771
+ }
37401
37772
  let prev = 0;
37402
37773
  let n = cps.length;
37403
37774
  for (let i = 0; i < n; i++) {
@@ -37562,7 +37933,7 @@ var PolygonIdSdk = (function (exports) {
37562
37933
  // don't print label again if just a single label
37563
37934
  let msg = error.message;
37564
37935
  // bidi_qq() only necessary if msg is digits
37565
- throw new Error(split.length == 1 ? msg : `Invalid label ${bidi_qq(safe_str_from_cps(input))}: ${msg}`);
37936
+ throw new Error(split.length == 1 ? msg : `Invalid label ${bidi_qq(safe_str_from_cps(input, 63))}: ${msg}`);
37566
37937
  }
37567
37938
  return str_from_cps(output);
37568
37939
  }).join(STOP_CH);
@@ -37816,12 +38187,11 @@ var PolygonIdSdk = (function (exports) {
37816
38187
  * This is used for various parts of ENS name resolution, such
37817
38188
  * as the wildcard resolution.
37818
38189
  */
37819
- function dnsEncode(name) {
38190
+ function dnsEncode(name, _maxLength) {
38191
+ const length = (_maxLength != null) ? _maxLength : 63;
38192
+ assertArgument(length <= 255, "DNS encoded label cannot exceed 255", "length", length);
37820
38193
  return hexlify(concat(ensNameSplit(name).map((comp) => {
37821
- // DNS does not allow components over 63 bytes in length
37822
- if (comp.length > 63) {
37823
- throw new Error("invalid DNS encoded entry; length exceeds 63 bytes");
37824
- }
38194
+ assertArgument(comp.length <= length, `label ${JSON.stringify(name)} exceeds ${length} bytes`, "name", name);
37825
38195
  const bytes = new Uint8Array(comp.length + 1);
37826
38196
  bytes.set(comp, 1);
37827
38197
  bytes[0] = bytes.length - 1;
@@ -37893,6 +38263,15 @@ var PolygonIdSdk = (function (exports) {
37893
38263
  const BN_28 = BigInt(28);
37894
38264
  const BN_35 = BigInt(35);
37895
38265
  const BN_MAX_UINT = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
38266
+ const BLOB_SIZE = 4096 * 32;
38267
+ function getVersionedHash(version, hash) {
38268
+ let versioned = version.toString(16);
38269
+ while (versioned.length < 2) {
38270
+ versioned = "0" + versioned;
38271
+ }
38272
+ versioned += sha256(hash).substring(4);
38273
+ return "0x" + versioned;
38274
+ }
37896
38275
  function handleAddress(value) {
37897
38276
  if (value === "0x") {
37898
38277
  return null;
@@ -37930,6 +38309,13 @@ var PolygonIdSdk = (function (exports) {
37930
38309
  function formatAccessList(value) {
37931
38310
  return accessListify(value).map((set) => [set.address, set.storageKeys]);
37932
38311
  }
38312
+ function formatHashes(value, param) {
38313
+ assertArgument(Array.isArray(value), `invalid ${param}`, "value", value);
38314
+ for (let i = 0; i < value.length; i++) {
38315
+ assertArgument(isHexString(value[i], 32), "invalid ${ param } hash", `value[${i}]`, value[i]);
38316
+ }
38317
+ return value;
38318
+ }
37933
38319
  function _parseLegacy(data) {
37934
38320
  const fields = decodeRlp(data);
37935
38321
  assertArgument(Array.isArray(fields) && (fields.length === 9 || fields.length === 6), "invalid field count for legacy transaction", "data", data);
@@ -37968,18 +38354,18 @@ var PolygonIdSdk = (function (exports) {
37968
38354
  s: zeroPadValue(fields[8], 32),
37969
38355
  v
37970
38356
  });
37971
- tx.hash = keccak256(data);
38357
+ //tx.hash = keccak256(data);
37972
38358
  }
37973
38359
  return tx;
37974
38360
  }
37975
38361
  function _serializeLegacy(tx, sig) {
37976
38362
  const fields = [
37977
- formatNumber(tx.nonce || 0, "nonce"),
38363
+ formatNumber(tx.nonce, "nonce"),
37978
38364
  formatNumber(tx.gasPrice || 0, "gasPrice"),
37979
- formatNumber(tx.gasLimit || 0, "gasLimit"),
37980
- ((tx.to != null) ? getAddress(tx.to) : "0x"),
37981
- formatNumber(tx.value || 0, "value"),
37982
- (tx.data || "0x"),
38365
+ formatNumber(tx.gasLimit, "gasLimit"),
38366
+ (tx.to || "0x"),
38367
+ formatNumber(tx.value, "value"),
38368
+ tx.data,
37983
38369
  ];
37984
38370
  let chainId = BN_0$4;
37985
38371
  if (tx.chainId != BN_0$4) {
@@ -38042,14 +38428,12 @@ var PolygonIdSdk = (function (exports) {
38042
38428
  function _parseEip1559(data) {
38043
38429
  const fields = decodeRlp(getBytes(data).slice(1));
38044
38430
  assertArgument(Array.isArray(fields) && (fields.length === 9 || fields.length === 12), "invalid field count for transaction type: 2", "data", hexlify(data));
38045
- const maxPriorityFeePerGas = handleUint(fields[2], "maxPriorityFeePerGas");
38046
- const maxFeePerGas = handleUint(fields[3], "maxFeePerGas");
38047
38431
  const tx = {
38048
38432
  type: 2,
38049
38433
  chainId: handleUint(fields[0], "chainId"),
38050
38434
  nonce: handleNumber(fields[1], "nonce"),
38051
- maxPriorityFeePerGas: maxPriorityFeePerGas,
38052
- maxFeePerGas: maxFeePerGas,
38435
+ maxPriorityFeePerGas: handleUint(fields[2], "maxPriorityFeePerGas"),
38436
+ maxFeePerGas: handleUint(fields[3], "maxFeePerGas"),
38053
38437
  gasPrice: null,
38054
38438
  gasLimit: handleUint(fields[4], "gasLimit"),
38055
38439
  to: handleAddress(fields[5]),
@@ -38061,21 +38445,21 @@ var PolygonIdSdk = (function (exports) {
38061
38445
  if (fields.length === 9) {
38062
38446
  return tx;
38063
38447
  }
38064
- tx.hash = keccak256(data);
38448
+ //tx.hash = keccak256(data);
38065
38449
  _parseEipSignature(tx, fields.slice(9));
38066
38450
  return tx;
38067
38451
  }
38068
38452
  function _serializeEip1559(tx, sig) {
38069
38453
  const fields = [
38070
- formatNumber(tx.chainId || 0, "chainId"),
38071
- formatNumber(tx.nonce || 0, "nonce"),
38454
+ formatNumber(tx.chainId, "chainId"),
38455
+ formatNumber(tx.nonce, "nonce"),
38072
38456
  formatNumber(tx.maxPriorityFeePerGas || 0, "maxPriorityFeePerGas"),
38073
38457
  formatNumber(tx.maxFeePerGas || 0, "maxFeePerGas"),
38074
- formatNumber(tx.gasLimit || 0, "gasLimit"),
38075
- ((tx.to != null) ? getAddress(tx.to) : "0x"),
38076
- formatNumber(tx.value || 0, "value"),
38077
- (tx.data || "0x"),
38078
- (formatAccessList(tx.accessList || []))
38458
+ formatNumber(tx.gasLimit, "gasLimit"),
38459
+ (tx.to || "0x"),
38460
+ formatNumber(tx.value, "value"),
38461
+ tx.data,
38462
+ formatAccessList(tx.accessList || [])
38079
38463
  ];
38080
38464
  if (sig) {
38081
38465
  fields.push(formatNumber(sig.yParity, "yParity"));
@@ -38102,20 +38486,20 @@ var PolygonIdSdk = (function (exports) {
38102
38486
  if (fields.length === 8) {
38103
38487
  return tx;
38104
38488
  }
38105
- tx.hash = keccak256(data);
38489
+ //tx.hash = keccak256(data);
38106
38490
  _parseEipSignature(tx, fields.slice(8));
38107
38491
  return tx;
38108
38492
  }
38109
38493
  function _serializeEip2930(tx, sig) {
38110
38494
  const fields = [
38111
- formatNumber(tx.chainId || 0, "chainId"),
38112
- formatNumber(tx.nonce || 0, "nonce"),
38495
+ formatNumber(tx.chainId, "chainId"),
38496
+ formatNumber(tx.nonce, "nonce"),
38113
38497
  formatNumber(tx.gasPrice || 0, "gasPrice"),
38114
- formatNumber(tx.gasLimit || 0, "gasLimit"),
38115
- ((tx.to != null) ? getAddress(tx.to) : "0x"),
38116
- formatNumber(tx.value || 0, "value"),
38117
- (tx.data || "0x"),
38118
- (formatAccessList(tx.accessList || []))
38498
+ formatNumber(tx.gasLimit, "gasLimit"),
38499
+ (tx.to || "0x"),
38500
+ formatNumber(tx.value, "value"),
38501
+ tx.data,
38502
+ formatAccessList(tx.accessList || [])
38119
38503
  ];
38120
38504
  if (sig) {
38121
38505
  fields.push(formatNumber(sig.yParity, "recoveryParam"));
@@ -38124,6 +38508,96 @@ var PolygonIdSdk = (function (exports) {
38124
38508
  }
38125
38509
  return concat(["0x01", encodeRlp(fields)]);
38126
38510
  }
38511
+ function _parseEip4844(data) {
38512
+ let fields = decodeRlp(getBytes(data).slice(1));
38513
+ let typeName = "3";
38514
+ let blobs = null;
38515
+ // Parse the network format
38516
+ if (fields.length === 4 && Array.isArray(fields[0])) {
38517
+ typeName = "3 (network format)";
38518
+ const fBlobs = fields[1], fCommits = fields[2], fProofs = fields[3];
38519
+ assertArgument(Array.isArray(fBlobs), "invalid network format: blobs not an array", "fields[1]", fBlobs);
38520
+ assertArgument(Array.isArray(fCommits), "invalid network format: commitments not an array", "fields[2]", fCommits);
38521
+ assertArgument(Array.isArray(fProofs), "invalid network format: proofs not an array", "fields[3]", fProofs);
38522
+ assertArgument(fBlobs.length === fCommits.length, "invalid network format: blobs/commitments length mismatch", "fields", fields);
38523
+ assertArgument(fBlobs.length === fProofs.length, "invalid network format: blobs/proofs length mismatch", "fields", fields);
38524
+ blobs = [];
38525
+ for (let i = 0; i < fields[1].length; i++) {
38526
+ blobs.push({
38527
+ data: fBlobs[i],
38528
+ commitment: fCommits[i],
38529
+ proof: fProofs[i],
38530
+ });
38531
+ }
38532
+ fields = fields[0];
38533
+ }
38534
+ assertArgument(Array.isArray(fields) && (fields.length === 11 || fields.length === 14), `invalid field count for transaction type: ${typeName}`, "data", hexlify(data));
38535
+ const tx = {
38536
+ type: 3,
38537
+ chainId: handleUint(fields[0], "chainId"),
38538
+ nonce: handleNumber(fields[1], "nonce"),
38539
+ maxPriorityFeePerGas: handleUint(fields[2], "maxPriorityFeePerGas"),
38540
+ maxFeePerGas: handleUint(fields[3], "maxFeePerGas"),
38541
+ gasPrice: null,
38542
+ gasLimit: handleUint(fields[4], "gasLimit"),
38543
+ to: handleAddress(fields[5]),
38544
+ value: handleUint(fields[6], "value"),
38545
+ data: hexlify(fields[7]),
38546
+ accessList: handleAccessList(fields[8], "accessList"),
38547
+ maxFeePerBlobGas: handleUint(fields[9], "maxFeePerBlobGas"),
38548
+ blobVersionedHashes: fields[10]
38549
+ };
38550
+ if (blobs) {
38551
+ tx.blobs = blobs;
38552
+ }
38553
+ assertArgument(tx.to != null, `invalid address for transaction type: ${typeName}`, "data", data);
38554
+ assertArgument(Array.isArray(tx.blobVersionedHashes), "invalid blobVersionedHashes: must be an array", "data", data);
38555
+ for (let i = 0; i < tx.blobVersionedHashes.length; i++) {
38556
+ assertArgument(isHexString(tx.blobVersionedHashes[i], 32), `invalid blobVersionedHash at index ${i}: must be length 32`, "data", data);
38557
+ }
38558
+ // Unsigned EIP-4844 Transaction
38559
+ if (fields.length === 11) {
38560
+ return tx;
38561
+ }
38562
+ // @TODO: Do we need to do this? This is only called internally
38563
+ // and used to verify hashes; it might save time to not do this
38564
+ //tx.hash = keccak256(concat([ "0x03", encodeRlp(fields) ]));
38565
+ _parseEipSignature(tx, fields.slice(11));
38566
+ return tx;
38567
+ }
38568
+ function _serializeEip4844(tx, sig, blobs) {
38569
+ const fields = [
38570
+ formatNumber(tx.chainId, "chainId"),
38571
+ formatNumber(tx.nonce, "nonce"),
38572
+ formatNumber(tx.maxPriorityFeePerGas || 0, "maxPriorityFeePerGas"),
38573
+ formatNumber(tx.maxFeePerGas || 0, "maxFeePerGas"),
38574
+ formatNumber(tx.gasLimit, "gasLimit"),
38575
+ (tx.to || ZeroAddress),
38576
+ formatNumber(tx.value, "value"),
38577
+ tx.data,
38578
+ formatAccessList(tx.accessList || []),
38579
+ formatNumber(tx.maxFeePerBlobGas || 0, "maxFeePerBlobGas"),
38580
+ formatHashes(tx.blobVersionedHashes || [], "blobVersionedHashes")
38581
+ ];
38582
+ if (sig) {
38583
+ fields.push(formatNumber(sig.yParity, "yParity"));
38584
+ fields.push(toBeArray(sig.r));
38585
+ fields.push(toBeArray(sig.s));
38586
+ // We have blobs; return the network wrapped format
38587
+ if (blobs) {
38588
+ return concat([
38589
+ "0x03",
38590
+ encodeRlp([
38591
+ fields,
38592
+ blobs.map((b) => b.data),
38593
+ blobs.map((b) => b.commitment),
38594
+ blobs.map((b) => b.proof),
38595
+ ])
38596
+ ]);
38597
+ }
38598
+ }
38599
+ return concat(["0x03", encodeRlp(fields)]);
38600
+ }
38127
38601
  /**
38128
38602
  * A **Transaction** describes an operation to be executed on
38129
38603
  * Ethereum by an Externally Owned Account (EOA). It includes
@@ -38150,6 +38624,10 @@ var PolygonIdSdk = (function (exports) {
38150
38624
  #chainId;
38151
38625
  #sig;
38152
38626
  #accessList;
38627
+ #maxFeePerBlobGas;
38628
+ #blobVersionedHashes;
38629
+ #kzg;
38630
+ #blobs;
38153
38631
  /**
38154
38632
  * The transaction type.
38155
38633
  *
@@ -38176,6 +38654,11 @@ var PolygonIdSdk = (function (exports) {
38176
38654
  case "eip-1559":
38177
38655
  this.#type = 2;
38178
38656
  break;
38657
+ case 3:
38658
+ case "cancun":
38659
+ case "eip-4844":
38660
+ this.#type = 3;
38661
+ break;
38179
38662
  default:
38180
38663
  assertArgument(false, "unsupported transaction type", "type", value);
38181
38664
  }
@@ -38188,6 +38671,7 @@ var PolygonIdSdk = (function (exports) {
38188
38671
  case 0: return "legacy";
38189
38672
  case 1: return "eip-2930";
38190
38673
  case 2: return "eip-1559";
38674
+ case 3: return "eip-4844";
38191
38675
  }
38192
38676
  return null;
38193
38677
  }
@@ -38195,7 +38679,13 @@ var PolygonIdSdk = (function (exports) {
38195
38679
  * The ``to`` address for the transaction or ``null`` if the
38196
38680
  * transaction is an ``init`` transaction.
38197
38681
  */
38198
- get to() { return this.#to; }
38682
+ get to() {
38683
+ const value = this.#to;
38684
+ if (value == null && this.type === 3) {
38685
+ return ZeroAddress;
38686
+ }
38687
+ return value;
38688
+ }
38199
38689
  set to(value) {
38200
38690
  this.#to = (value == null) ? null : getAddress(value);
38201
38691
  }
@@ -38232,7 +38722,7 @@ var PolygonIdSdk = (function (exports) {
38232
38722
  get maxPriorityFeePerGas() {
38233
38723
  const value = this.#maxPriorityFeePerGas;
38234
38724
  if (value == null) {
38235
- if (this.type === 2) {
38725
+ if (this.type === 2 || this.type === 3) {
38236
38726
  return BN_0$4;
38237
38727
  }
38238
38728
  return null;
@@ -38249,7 +38739,7 @@ var PolygonIdSdk = (function (exports) {
38249
38739
  get maxFeePerGas() {
38250
38740
  const value = this.#maxFeePerGas;
38251
38741
  if (value == null) {
38252
- if (this.type === 2) {
38742
+ if (this.type === 2 || this.type === 3) {
38253
38743
  return BN_0$4;
38254
38744
  }
38255
38745
  return null;
@@ -38293,7 +38783,9 @@ var PolygonIdSdk = (function (exports) {
38293
38783
  get accessList() {
38294
38784
  const value = this.#accessList || null;
38295
38785
  if (value == null) {
38296
- if (this.type === 1 || this.type === 2) {
38786
+ if (this.type === 1 || this.type === 2 || this.type === 3) {
38787
+ // @TODO: in v7, this should assign the value or become
38788
+ // a live object itself, otherwise mutation is inconsistent
38297
38789
  return [];
38298
38790
  }
38299
38791
  return null;
@@ -38303,6 +38795,122 @@ var PolygonIdSdk = (function (exports) {
38303
38795
  set accessList(value) {
38304
38796
  this.#accessList = (value == null) ? null : accessListify(value);
38305
38797
  }
38798
+ /**
38799
+ * The max fee per blob gas for Cancun transactions.
38800
+ */
38801
+ get maxFeePerBlobGas() {
38802
+ const value = this.#maxFeePerBlobGas;
38803
+ if (value == null && this.type === 3) {
38804
+ return BN_0$4;
38805
+ }
38806
+ return value;
38807
+ }
38808
+ set maxFeePerBlobGas(value) {
38809
+ this.#maxFeePerBlobGas = (value == null) ? null : getBigInt(value, "maxFeePerBlobGas");
38810
+ }
38811
+ /**
38812
+ * The BLOb versioned hashes for Cancun transactions.
38813
+ */
38814
+ get blobVersionedHashes() {
38815
+ // @TODO: Mutation is inconsistent; if unset, the returned value
38816
+ // cannot mutate the object, if set it can
38817
+ let value = this.#blobVersionedHashes;
38818
+ if (value == null && this.type === 3) {
38819
+ return [];
38820
+ }
38821
+ return value;
38822
+ }
38823
+ set blobVersionedHashes(value) {
38824
+ if (value != null) {
38825
+ assertArgument(Array.isArray(value), "blobVersionedHashes must be an Array", "value", value);
38826
+ value = value.slice();
38827
+ for (let i = 0; i < value.length; i++) {
38828
+ assertArgument(isHexString(value[i], 32), "invalid blobVersionedHash", `value[${i}]`, value[i]);
38829
+ }
38830
+ }
38831
+ this.#blobVersionedHashes = value;
38832
+ }
38833
+ /**
38834
+ * The BLObs for the Transaction, if any.
38835
+ *
38836
+ * If ``blobs`` is non-``null``, then the [[seriailized]]
38837
+ * will return the network formatted sidecar, otherwise it
38838
+ * will return the standard [[link-eip-2718]] payload. The
38839
+ * [[unsignedSerialized]] is unaffected regardless.
38840
+ *
38841
+ * When setting ``blobs``, either fully valid [[Blob]] objects
38842
+ * may be specified (i.e. correctly padded, with correct
38843
+ * committments and proofs) or a raw [[BytesLike]] may
38844
+ * be provided.
38845
+ *
38846
+ * If raw [[BytesLike]] are provided, the [[kzg]] property **must**
38847
+ * be already set. The blob will be correctly padded and the
38848
+ * [[KzgLibrary]] will be used to compute the committment and
38849
+ * proof for the blob.
38850
+ *
38851
+ * A BLOb is a sequence of field elements, each of which must
38852
+ * be within the BLS field modulo, so some additional processing
38853
+ * may be required to encode arbitrary data to ensure each 32 byte
38854
+ * field is within the valid range.
38855
+ *
38856
+ * Setting this automatically populates [[blobVersionedHashes]],
38857
+ * overwriting any existing values. Setting this to ``null``
38858
+ * does **not** remove the [[blobVersionedHashes]], leaving them
38859
+ * present.
38860
+ */
38861
+ get blobs() {
38862
+ if (this.#blobs == null) {
38863
+ return null;
38864
+ }
38865
+ return this.#blobs.map((b) => Object.assign({}, b));
38866
+ }
38867
+ set blobs(_blobs) {
38868
+ if (_blobs == null) {
38869
+ this.#blobs = null;
38870
+ return;
38871
+ }
38872
+ const blobs = [];
38873
+ const versionedHashes = [];
38874
+ for (let i = 0; i < _blobs.length; i++) {
38875
+ const blob = _blobs[i];
38876
+ if (isBytesLike(blob)) {
38877
+ assert$2(this.#kzg, "adding a raw blob requires a KZG library", "UNSUPPORTED_OPERATION", {
38878
+ operation: "set blobs()"
38879
+ });
38880
+ let data = getBytes(blob);
38881
+ assertArgument(data.length <= BLOB_SIZE, "blob is too large", `blobs[${i}]`, blob);
38882
+ // Pad blob if necessary
38883
+ if (data.length !== BLOB_SIZE) {
38884
+ const padded = new Uint8Array(BLOB_SIZE);
38885
+ padded.set(data);
38886
+ data = padded;
38887
+ }
38888
+ const commit = this.#kzg.blobToKzgCommitment(data);
38889
+ const proof = hexlify(this.#kzg.computeBlobKzgProof(data, commit));
38890
+ blobs.push({
38891
+ data: hexlify(data),
38892
+ commitment: hexlify(commit),
38893
+ proof
38894
+ });
38895
+ versionedHashes.push(getVersionedHash(1, commit));
38896
+ }
38897
+ else {
38898
+ const commit = hexlify(blob.commitment);
38899
+ blobs.push({
38900
+ data: hexlify(blob.data),
38901
+ commitment: commit,
38902
+ proof: hexlify(blob.proof)
38903
+ });
38904
+ versionedHashes.push(getVersionedHash(1, commit));
38905
+ }
38906
+ }
38907
+ this.#blobs = blobs;
38908
+ this.#blobVersionedHashes = versionedHashes;
38909
+ }
38910
+ get kzg() { return this.#kzg; }
38911
+ set kzg(kzg) {
38912
+ this.#kzg = kzg;
38913
+ }
38306
38914
  /**
38307
38915
  * Creates a new Transaction with default values.
38308
38916
  */
@@ -38310,15 +38918,19 @@ var PolygonIdSdk = (function (exports) {
38310
38918
  this.#type = null;
38311
38919
  this.#to = null;
38312
38920
  this.#nonce = 0;
38313
- this.#gasLimit = BigInt(0);
38921
+ this.#gasLimit = BN_0$4;
38314
38922
  this.#gasPrice = null;
38315
38923
  this.#maxPriorityFeePerGas = null;
38316
38924
  this.#maxFeePerGas = null;
38317
38925
  this.#data = "0x";
38318
- this.#value = BigInt(0);
38319
- this.#chainId = BigInt(0);
38926
+ this.#value = BN_0$4;
38927
+ this.#chainId = BN_0$4;
38320
38928
  this.#sig = null;
38321
38929
  this.#accessList = null;
38930
+ this.#maxFeePerBlobGas = null;
38931
+ this.#blobVersionedHashes = null;
38932
+ this.#blobs = null;
38933
+ this.#kzg = null;
38322
38934
  }
38323
38935
  /**
38324
38936
  * The transaction hash, if signed. Otherwise, ``null``.
@@ -38327,7 +38939,7 @@ var PolygonIdSdk = (function (exports) {
38327
38939
  if (this.signature == null) {
38328
38940
  return null;
38329
38941
  }
38330
- return keccak256(this.serialized);
38942
+ return keccak256(this.#getSerialized(true, false));
38331
38943
  }
38332
38944
  /**
38333
38945
  * The pre-image hash of this transaction.
@@ -38363,9 +38975,23 @@ var PolygonIdSdk = (function (exports) {
38363
38975
  * transaction are non-null.
38364
38976
  */
38365
38977
  isSigned() {
38366
- //isSigned(): this is SignedTransaction {
38367
38978
  return this.signature != null;
38368
38979
  }
38980
+ #getSerialized(signed, sidecar) {
38981
+ assert$2(!signed || this.signature != null, "cannot serialize unsigned transaction; maybe you meant .unsignedSerialized", "UNSUPPORTED_OPERATION", { operation: ".serialized" });
38982
+ const sig = signed ? this.signature : null;
38983
+ switch (this.inferType()) {
38984
+ case 0:
38985
+ return _serializeLegacy(this, sig);
38986
+ case 1:
38987
+ return _serializeEip2930(this, sig);
38988
+ case 2:
38989
+ return _serializeEip1559(this, sig);
38990
+ case 3:
38991
+ return _serializeEip4844(this, sig, sidecar ? this.blobs : null);
38992
+ }
38993
+ assert$2(false, "unsupported transaction type", "UNSUPPORTED_OPERATION", { operation: ".serialized" });
38994
+ }
38369
38995
  /**
38370
38996
  * The serialized transaction.
38371
38997
  *
@@ -38373,16 +38999,7 @@ var PolygonIdSdk = (function (exports) {
38373
38999
  * use [[unsignedSerialized]].
38374
39000
  */
38375
39001
  get serialized() {
38376
- assert$2(this.signature != null, "cannot serialize unsigned transaction; maybe you meant .unsignedSerialized", "UNSUPPORTED_OPERATION", { operation: ".serialized" });
38377
- switch (this.inferType()) {
38378
- case 0:
38379
- return _serializeLegacy(this, this.signature);
38380
- case 1:
38381
- return _serializeEip2930(this, this.signature);
38382
- case 2:
38383
- return _serializeEip1559(this, this.signature);
38384
- }
38385
- assert$2(false, "unsupported transaction type", "UNSUPPORTED_OPERATION", { operation: ".serialized" });
39002
+ return this.#getSerialized(true, true);
38386
39003
  }
38387
39004
  /**
38388
39005
  * The transaction pre-image.
@@ -38391,22 +39008,20 @@ var PolygonIdSdk = (function (exports) {
38391
39008
  * authorize this transaction.
38392
39009
  */
38393
39010
  get unsignedSerialized() {
38394
- switch (this.inferType()) {
38395
- case 0:
38396
- return _serializeLegacy(this);
38397
- case 1:
38398
- return _serializeEip2930(this);
38399
- case 2:
38400
- return _serializeEip1559(this);
38401
- }
38402
- assert$2(false, "unsupported transaction type", "UNSUPPORTED_OPERATION", { operation: ".unsignedSerialized" });
39011
+ return this.#getSerialized(false, false);
38403
39012
  }
38404
39013
  /**
38405
39014
  * Return the most "likely" type; currently the highest
38406
39015
  * supported transaction type.
38407
39016
  */
38408
39017
  inferType() {
38409
- return (this.inferTypes().pop());
39018
+ const types = this.inferTypes();
39019
+ // Prefer London (EIP-1559) over Cancun (BLOb)
39020
+ if (types.indexOf(2) >= 0) {
39021
+ return 2;
39022
+ }
39023
+ // Return the highest inferred type
39024
+ return (types.pop());
38410
39025
  }
38411
39026
  /**
38412
39027
  * Validates the explicit properties and returns a list of compatible
@@ -38417,6 +39032,7 @@ var PolygonIdSdk = (function (exports) {
38417
39032
  const hasGasPrice = this.gasPrice != null;
38418
39033
  const hasFee = (this.maxFeePerGas != null || this.maxPriorityFeePerGas != null);
38419
39034
  const hasAccessList = (this.accessList != null);
39035
+ const hasBlob = (this.#maxFeePerBlobGas != null || this.#blobVersionedHashes);
38420
39036
  //if (hasGasPrice && hasFee) {
38421
39037
  // throw new Error("transaction cannot have gasPrice and maxFeePerGas");
38422
39038
  //}
@@ -38447,10 +39063,14 @@ var PolygonIdSdk = (function (exports) {
38447
39063
  types.push(1);
38448
39064
  types.push(2);
38449
39065
  }
39066
+ else if (hasBlob && this.to) {
39067
+ types.push(3);
39068
+ }
38450
39069
  else {
38451
39070
  types.push(0);
38452
39071
  types.push(1);
38453
39072
  types.push(2);
39073
+ types.push(3);
38454
39074
  }
38455
39075
  }
38456
39076
  types.sort();
@@ -38486,6 +39106,16 @@ var PolygonIdSdk = (function (exports) {
38486
39106
  isLondon() {
38487
39107
  return (this.type === 2);
38488
39108
  }
39109
+ /**
39110
+ * Returns true if this transaction is an [[link-eip-4844]] BLOB
39111
+ * transaction.
39112
+ *
39113
+ * This provides a Type Guard that the related properties are
39114
+ * non-null.
39115
+ */
39116
+ isCancun() {
39117
+ return (this.type === 3);
39118
+ }
38489
39119
  /**
38490
39120
  * Create a copy of this transaciton.
38491
39121
  */
@@ -38534,6 +39164,7 @@ var PolygonIdSdk = (function (exports) {
38534
39164
  switch (payload[0]) {
38535
39165
  case 1: return Transaction.from(_parseEip2930(payload));
38536
39166
  case 2: return Transaction.from(_parseEip1559(payload));
39167
+ case 3: return Transaction.from(_parseEip4844(payload));
38537
39168
  }
38538
39169
  assert$2(false, "unsupported transaction type", "UNSUPPORTED_OPERATION", { operation: "from" });
38539
39170
  }
@@ -38559,6 +39190,9 @@ var PolygonIdSdk = (function (exports) {
38559
39190
  if (tx.maxFeePerGas != null) {
38560
39191
  result.maxFeePerGas = tx.maxFeePerGas;
38561
39192
  }
39193
+ if (tx.maxFeePerBlobGas != null) {
39194
+ result.maxFeePerBlobGas = tx.maxFeePerBlobGas;
39195
+ }
38562
39196
  if (tx.data != null) {
38563
39197
  result.data = tx.data;
38564
39198
  }
@@ -38574,12 +39208,24 @@ var PolygonIdSdk = (function (exports) {
38574
39208
  if (tx.accessList != null) {
38575
39209
  result.accessList = tx.accessList;
38576
39210
  }
39211
+ // This will get overwritten by blobs, if present
39212
+ if (tx.blobVersionedHashes != null) {
39213
+ result.blobVersionedHashes = tx.blobVersionedHashes;
39214
+ }
39215
+ // Make sure we assign the kzg before assigning blobs, which
39216
+ // require the library in the event raw blob data is provided.
39217
+ if (tx.kzg != null) {
39218
+ result.kzg = tx.kzg;
39219
+ }
39220
+ if (tx.blobs != null) {
39221
+ result.blobs = tx.blobs;
39222
+ }
38577
39223
  if (tx.hash != null) {
38578
- assertArgument(result.isSigned(), "unsigned transaction cannot define hash", "tx", tx);
39224
+ assertArgument(result.isSigned(), "unsigned transaction cannot define '.hash'", "tx", tx);
38579
39225
  assertArgument(result.hash === tx.hash, "hash mismatch", "tx", tx);
38580
39226
  }
38581
39227
  if (tx.from != null) {
38582
- assertArgument(result.isSigned(), "unsigned transaction cannot define from", "tx", tx);
39228
+ assertArgument(result.isSigned(), "unsigned transaction cannot define '.from'", "tx", tx);
38583
39229
  assertArgument(result.from.toLowerCase() === (tx.from || "").toLowerCase(), "from mismatch", "tx", tx);
38584
39230
  }
38585
39231
  return result;
@@ -38646,11 +39292,11 @@ var PolygonIdSdk = (function (exports) {
38646
39292
  function getBaseEncoder(type) {
38647
39293
  // intXX and uintXX
38648
39294
  {
38649
- const match = type.match(/^(u?)int(\d*)$/);
39295
+ const match = type.match(/^(u?)int(\d+)$/);
38650
39296
  if (match) {
38651
39297
  const signed = (match[1] === "");
38652
- const width = parseInt(match[2] || "256");
38653
- assertArgument(width % 8 === 0 && width !== 0 && width <= 256 && (match[2] == null || match[2] === String(width)), "invalid numeric width", "type", type);
39298
+ const width = parseInt(match[2]);
39299
+ assertArgument(width % 8 === 0 && width !== 0 && width <= 256 && match[2] === String(width), "invalid numeric width", "type", type);
38654
39300
  const boundsUpper = mask(BN_MAX_UINT256, signed ? (width - 1) : width);
38655
39301
  const boundsLower = signed ? ((boundsUpper + BN_1) * BN__1) : BN_0$3;
38656
39302
  return function (_value) {
@@ -38692,6 +39338,23 @@ var PolygonIdSdk = (function (exports) {
38692
39338
  function encodeType(name, fields) {
38693
39339
  return `${name}(${fields.map(({ name, type }) => (type + " " + name)).join(",")})`;
38694
39340
  }
39341
+ // foo[][3] => { base: "foo", index: "[][3]", array: {
39342
+ // base: "foo", prefix: "foo[]", count: 3 } }
39343
+ function splitArray(type) {
39344
+ const match = type.match(/^([^\x5b]*)((\x5b\d*\x5d)*)(\x5b(\d*)\x5d)$/);
39345
+ if (match) {
39346
+ return {
39347
+ base: match[1],
39348
+ index: (match[2] + match[4]),
39349
+ array: {
39350
+ base: match[1],
39351
+ prefix: (match[1] + match[2]),
39352
+ count: (match[5] ? parseInt(match[5]) : -1),
39353
+ }
39354
+ };
39355
+ }
39356
+ return { base: type };
39357
+ }
38695
39358
  /**
38696
39359
  * A **TypedDataEncode** prepares and encodes [[link-eip-712]] payloads
38697
39360
  * for signed typed data.
@@ -38726,8 +39389,7 @@ var PolygonIdSdk = (function (exports) {
38726
39389
  * do not violate the [[link-eip-712]] structural constraints as
38727
39390
  * well as computes the [[primaryType]].
38728
39391
  */
38729
- constructor(types) {
38730
- this.#types = JSON.stringify(types);
39392
+ constructor(_types) {
38731
39393
  this.#fullTypes = new Map();
38732
39394
  this.#encoderCache = new Map();
38733
39395
  // Link struct types to their direct child structs
@@ -38736,26 +39398,39 @@ var PolygonIdSdk = (function (exports) {
38736
39398
  const parents = new Map();
38737
39399
  // Link all subtypes within a given struct
38738
39400
  const subtypes = new Map();
38739
- Object.keys(types).forEach((type) => {
39401
+ const types = {};
39402
+ Object.keys(_types).forEach((type) => {
39403
+ types[type] = _types[type].map(({ name, type }) => {
39404
+ // Normalize the base type (unless name conflict)
39405
+ let { base, index } = splitArray(type);
39406
+ if (base === "int" && !_types["int"]) {
39407
+ base = "int256";
39408
+ }
39409
+ if (base === "uint" && !_types["uint"]) {
39410
+ base = "uint256";
39411
+ }
39412
+ return { name, type: (base + (index || "")) };
39413
+ });
38740
39414
  links.set(type, new Set());
38741
39415
  parents.set(type, []);
38742
39416
  subtypes.set(type, new Set());
38743
39417
  });
39418
+ this.#types = JSON.stringify(types);
38744
39419
  for (const name in types) {
38745
39420
  const uniqueNames = new Set();
38746
39421
  for (const field of types[name]) {
38747
39422
  // Check each field has a unique name
38748
- assertArgument(!uniqueNames.has(field.name), `duplicate variable name ${JSON.stringify(field.name)} in ${JSON.stringify(name)}`, "types", types);
39423
+ assertArgument(!uniqueNames.has(field.name), `duplicate variable name ${JSON.stringify(field.name)} in ${JSON.stringify(name)}`, "types", _types);
38749
39424
  uniqueNames.add(field.name);
38750
39425
  // Get the base type (drop any array specifiers)
38751
- const baseType = (field.type.match(/^([^\x5b]*)(\x5b|$)/))[1] || null;
38752
- assertArgument(baseType !== name, `circular type reference to ${JSON.stringify(baseType)}`, "types", types);
39426
+ const baseType = splitArray(field.type).base;
39427
+ assertArgument(baseType !== name, `circular type reference to ${JSON.stringify(baseType)}`, "types", _types);
38753
39428
  // Is this a base encoding type?
38754
39429
  const encoder = getBaseEncoder(baseType);
38755
39430
  if (encoder) {
38756
39431
  continue;
38757
39432
  }
38758
- assertArgument(parents.has(baseType), `unknown type ${JSON.stringify(baseType)}`, "types", types);
39433
+ assertArgument(parents.has(baseType), `unknown type ${JSON.stringify(baseType)}`, "types", _types);
38759
39434
  // Add linkage
38760
39435
  parents.get(baseType).push(name);
38761
39436
  links.get(name).add(baseType);
@@ -38763,12 +39438,12 @@ var PolygonIdSdk = (function (exports) {
38763
39438
  }
38764
39439
  // Deduce the primary type
38765
39440
  const primaryTypes = Array.from(parents.keys()).filter((n) => (parents.get(n).length === 0));
38766
- assertArgument(primaryTypes.length !== 0, "missing primary type", "types", types);
38767
- assertArgument(primaryTypes.length === 1, `ambiguous primary types or unused types: ${primaryTypes.map((t) => (JSON.stringify(t))).join(", ")}`, "types", types);
39441
+ assertArgument(primaryTypes.length !== 0, "missing primary type", "types", _types);
39442
+ assertArgument(primaryTypes.length === 1, `ambiguous primary types or unused types: ${primaryTypes.map((t) => (JSON.stringify(t))).join(", ")}`, "types", _types);
38768
39443
  defineProperties(this, { primaryType: primaryTypes[0] });
38769
39444
  // Check for circular type references
38770
39445
  function checkCircular(type, found) {
38771
- assertArgument(!found.has(type), `circular type reference to ${JSON.stringify(type)}`, "types", types);
39446
+ assertArgument(!found.has(type), `circular type reference to ${JSON.stringify(type)}`, "types", _types);
38772
39447
  found.add(type);
38773
39448
  for (const child of links.get(type)) {
38774
39449
  if (!parents.has(child)) {
@@ -38811,12 +39486,12 @@ var PolygonIdSdk = (function (exports) {
38811
39486
  }
38812
39487
  }
38813
39488
  // Array
38814
- const match = type.match(/^(.*)(\x5b(\d*)\x5d)$/);
38815
- if (match) {
38816
- const subtype = match[1];
39489
+ const array = splitArray(type).array;
39490
+ if (array) {
39491
+ const subtype = array.prefix;
38817
39492
  const subEncoder = this.getEncoder(subtype);
38818
39493
  return (value) => {
38819
- assertArgument(!match[3] || parseInt(match[3]) === value.length, `array length mismatch; expected length ${parseInt(match[3])}`, "value", value);
39494
+ assertArgument(array.count === -1 || array.count === value.length, `array length mismatch; expected length ${array.count}`, "value", value);
38820
39495
  let result = value.map(subEncoder);
38821
39496
  if (this.#fullTypes.has(subtype)) {
38822
39497
  result = result.map(keccak256);
@@ -38886,10 +39561,10 @@ var PolygonIdSdk = (function (exports) {
38886
39561
  }
38887
39562
  }
38888
39563
  // Array
38889
- const match = type.match(/^(.*)(\x5b(\d*)\x5d)$/);
38890
- if (match) {
38891
- assertArgument(!match[3] || parseInt(match[3]) === value.length, `array length mismatch; expected length ${parseInt(match[3])}`, "value", value);
38892
- return value.map((v) => this._visit(match[1], v, callback));
39564
+ const array = splitArray(type).array;
39565
+ if (array) {
39566
+ assertArgument(array.count === -1 || array.count === value.length, `array length mismatch; expected length ${array.count}`, "value", value);
39567
+ return value.map((v) => this._visit(array.prefix, v, callback));
38893
39568
  }
38894
39569
  // Struct
38895
39570
  const fields = this.types[type];
@@ -39028,6 +39703,8 @@ var PolygonIdSdk = (function (exports) {
39028
39703
  domainTypes.push({ name, type: domainFieldTypes[name] });
39029
39704
  });
39030
39705
  const encoder = TypedDataEncoder.from(types);
39706
+ // Get the normalized types
39707
+ types = encoder.types;
39031
39708
  const typesWithDomain = Object.assign({}, types);
39032
39709
  assertArgument(typesWithDomain.EIP712Domain == null, "types must not contain EIP712Domain type", "types.EIP712Domain", types);
39033
39710
  typesWithDomain.EIP712Domain = domainTypes;
@@ -39078,10 +39755,10 @@ var PolygonIdSdk = (function (exports) {
39078
39755
  items.forEach((k) => result.add(k));
39079
39756
  return Object.freeze(result);
39080
39757
  }
39081
- const _kwVisibDeploy = "external public payable";
39758
+ const _kwVisibDeploy = "external public payable override";
39082
39759
  const KwVisibDeploy = setify(_kwVisibDeploy.split(" "));
39083
39760
  // Visibility Keywords
39084
- const _kwVisib = "constant external internal payable private public pure view";
39761
+ const _kwVisib = "constant external internal payable private public pure view override";
39085
39762
  const KwVisib = setify(_kwVisib.split(" "));
39086
39763
  const _kwTypes = "constructor error event fallback function receive struct";
39087
39764
  const KwTypes = setify(_kwTypes.split(" "));
@@ -39135,7 +39812,8 @@ var PolygonIdSdk = (function (exports) {
39135
39812
  // Pops and returns the value of the next token if it is `type`; throws if out of tokens
39136
39813
  popType(type) {
39137
39814
  if (this.peek().type !== type) {
39138
- throw new Error(`expected ${type}; got ${JSON.stringify(this.peek())}`);
39815
+ const top = this.peek();
39816
+ throw new Error(`expected ${type}; got ${top.type} ${JSON.stringify(top.text)}`);
39139
39817
  }
39140
39818
  return this.pop().text;
39141
39819
  }
@@ -39367,7 +40045,7 @@ var PolygonIdSdk = (function (exports) {
39367
40045
  }
39368
40046
  function consumeEoi(tokens) {
39369
40047
  if (tokens.length) {
39370
- throw new Error(`unexpected tokens: ${tokens.toString()}`);
40048
+ throw new Error(`unexpected tokens at offset ${tokens.offset}: ${tokens.toString()}`);
39371
40049
  }
39372
40050
  }
39373
40051
  const regexArrayType = new RegExp(/^(.*)\[([0-9]*)\]$/);
@@ -39515,9 +40193,6 @@ var PolygonIdSdk = (function (exports) {
39515
40193
  }
39516
40194
  else {
39517
40195
  if (this.isTuple()) {
39518
- if (format !== "sighash") {
39519
- result += this.type;
39520
- }
39521
40196
  result += "(" + this.components.map((comp) => comp.format(format)).join((format === "full") ? ", " : ",") + ")";
39522
40197
  }
39523
40198
  else {
@@ -39650,7 +40325,7 @@ var PolygonIdSdk = (function (exports) {
39650
40325
  * Walks the **ParamType** with %%value%%, asynchronously calling
39651
40326
  * %%process%% on each type, destructing the %%value%% recursively.
39652
40327
  *
39653
- * This can be used to resolve ENS naes by walking and resolving each
40328
+ * This can be used to resolve ENS names by walking and resolving each
39654
40329
  * ``"address"`` type.
39655
40330
  */
39656
40331
  async walkAsync(value, process) {
@@ -40059,7 +40734,9 @@ var PolygonIdSdk = (function (exports) {
40059
40734
  });
40060
40735
  }
40061
40736
  const result = [`constructor${joinParams(format, this.inputs)}`];
40062
- result.push((this.payable) ? "payable" : "nonpayable");
40737
+ if (this.payable) {
40738
+ result.push("payable");
40739
+ }
40063
40740
  if (this.gas != null) {
40064
40741
  result.push(`@${this.gas.toString()}`);
40065
40742
  }
@@ -40405,6 +41082,7 @@ var PolygonIdSdk = (function (exports) {
40405
41082
  const paramTypeBytes = new RegExp(/^bytes([0-9]*)$/);
40406
41083
  const paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/);
40407
41084
  let defaultCoder = null;
41085
+ let defaultMaxInflation = 1024;
40408
41086
  function getBuiltinCallException(action, tx, data, abiCoder) {
40409
41087
  let message = "missing revert data";
40410
41088
  let reason = null;
@@ -40541,7 +41219,11 @@ var PolygonIdSdk = (function (exports) {
40541
41219
  decode(types, data, loose) {
40542
41220
  const coders = types.map((type) => this.#getCoder(ParamType.from(type)));
40543
41221
  const coder = new TupleCoder(coders, "_");
40544
- return coder.decode(new Reader(data, loose));
41222
+ return coder.decode(new Reader(data, loose, defaultMaxInflation));
41223
+ }
41224
+ static _setDefaultMaxInflation(value) {
41225
+ assertArgument(typeof (value) === "number" && Number.isInteger(value), "invalid defaultMaxInflation factor", "value", value);
41226
+ defaultMaxInflation = value;
40545
41227
  }
40546
41228
  /**
40547
41229
  * Returns the shared singleton instance of a default [[AbiCoder]].
@@ -40803,7 +41485,7 @@ var PolygonIdSdk = (function (exports) {
40803
41485
  frags.push(Fragment.from(a));
40804
41486
  }
40805
41487
  catch (error) {
40806
- console.log("EE", error);
41488
+ console.log(`[Warning] Invalid Fragment ${JSON.stringify(a)}:`, error.message);
40807
41489
  }
40808
41490
  }
40809
41491
  defineProperties(this, {
@@ -41644,7 +42326,11 @@ var PolygonIdSdk = (function (exports) {
41644
42326
  if (typeof (value) === "string") {
41645
42327
  return new Interface(JSON.parse(value));
41646
42328
  }
41647
- // Maybe an interface from an older version, or from a symlinked copy
42329
+ // An Interface; possibly from another v6 instance
42330
+ if (typeof (value.formatJson) === "function") {
42331
+ return new Interface(value.formatJson());
42332
+ }
42333
+ // A legacy Interface; from an older version
41648
42334
  if (typeof (value.format) === "function") {
41649
42335
  return new Interface(value.format("json"));
41650
42336
  }
@@ -41741,7 +42427,7 @@ var PolygonIdSdk = (function (exports) {
41741
42427
  if (req.data) {
41742
42428
  result.data = hexlify(req.data);
41743
42429
  }
41744
- const bigIntKeys = "chainId,gasLimit,gasPrice,maxFeePerGas,maxPriorityFeePerGas,value".split(/,/);
42430
+ const bigIntKeys = "chainId,gasLimit,gasPrice,maxFeePerBlobGas,maxFeePerGas,maxPriorityFeePerGas,value".split(/,/);
41745
42431
  for (const key of bigIntKeys) {
41746
42432
  if (!(key in req) || req[key] == null) {
41747
42433
  continue;
@@ -41767,6 +42453,20 @@ var PolygonIdSdk = (function (exports) {
41767
42453
  if ("customData" in req) {
41768
42454
  result.customData = req.customData;
41769
42455
  }
42456
+ if ("blobVersionedHashes" in req && req.blobVersionedHashes) {
42457
+ result.blobVersionedHashes = req.blobVersionedHashes.slice();
42458
+ }
42459
+ if ("kzg" in req) {
42460
+ result.kzg = req.kzg;
42461
+ }
42462
+ if ("blobs" in req && req.blobs) {
42463
+ result.blobs = req.blobs.map((b) => {
42464
+ if (isBytesLike(b)) {
42465
+ return hexlify(b);
42466
+ }
42467
+ return Object.assign({}, b);
42468
+ });
42469
+ }
41770
42470
  return result;
41771
42471
  }
41772
42472
  /**
@@ -41800,6 +42500,11 @@ var PolygonIdSdk = (function (exports) {
41800
42500
  * The block hash of the parent block.
41801
42501
  */
41802
42502
  parentHash;
42503
+ /**
42504
+ * The hash tree root of the parent beacon block for the given
42505
+ * execution block. See [[link-eip-4788]].
42506
+ */
42507
+ parentBeaconBlockRoot;
41803
42508
  /**
41804
42509
  * The nonce.
41805
42510
  *
@@ -41825,11 +42530,35 @@ var PolygonIdSdk = (function (exports) {
41825
42530
  * The total gas used in this block.
41826
42531
  */
41827
42532
  gasUsed;
42533
+ /**
42534
+ * The root hash for the global state after applying changes
42535
+ * in this block.
42536
+ */
42537
+ stateRoot;
42538
+ /**
42539
+ * The hash of the transaction receipts trie.
42540
+ */
42541
+ receiptsRoot;
42542
+ /**
42543
+ * The total amount of blob gas consumed by the transactions
42544
+ * within the block. See [[link-eip-4844]].
42545
+ */
42546
+ blobGasUsed;
42547
+ /**
42548
+ * The running total of blob gas consumed in excess of the
42549
+ * target, prior to the block. See [[link-eip-4844]].
42550
+ */
42551
+ excessBlobGas;
41828
42552
  /**
41829
42553
  * The miner coinbase address, wihch receives any subsidies for
41830
42554
  * including this block.
41831
42555
  */
41832
42556
  miner;
42557
+ /**
42558
+ * The latest RANDAO mix of the post beacon state of
42559
+ * the previous block.
42560
+ */
42561
+ prevRandao;
41833
42562
  /**
41834
42563
  * Any extra data the validator wished to include.
41835
42564
  */
@@ -41862,13 +42591,19 @@ var PolygonIdSdk = (function (exports) {
41862
42591
  number: block.number,
41863
42592
  timestamp: block.timestamp,
41864
42593
  parentHash: block.parentHash,
42594
+ parentBeaconBlockRoot: block.parentBeaconBlockRoot,
41865
42595
  nonce: block.nonce,
41866
42596
  difficulty: block.difficulty,
41867
42597
  gasLimit: block.gasLimit,
41868
42598
  gasUsed: block.gasUsed,
42599
+ blobGasUsed: block.blobGasUsed,
42600
+ excessBlobGas: block.excessBlobGas,
41869
42601
  miner: block.miner,
42602
+ prevRandao: getValue(block.prevRandao),
41870
42603
  extraData: block.extraData,
41871
- baseFeePerGas: getValue(block.baseFeePerGas)
42604
+ baseFeePerGas: getValue(block.baseFeePerGas),
42605
+ stateRoot: block.stateRoot,
42606
+ receiptsRoot: block.receiptsRoot,
41872
42607
  });
41873
42608
  }
41874
42609
  /**
@@ -41907,7 +42642,7 @@ var PolygonIdSdk = (function (exports) {
41907
42642
  * Returns a JSON-friendly value.
41908
42643
  */
41909
42644
  toJSON() {
41910
- const { baseFeePerGas, difficulty, extraData, gasLimit, gasUsed, hash, miner, nonce, number, parentHash, timestamp, transactions } = this;
42645
+ const { baseFeePerGas, difficulty, extraData, gasLimit, gasUsed, hash, miner, prevRandao, nonce, number, parentHash, parentBeaconBlockRoot, stateRoot, receiptsRoot, timestamp, transactions } = this;
41911
42646
  return {
41912
42647
  _type: "Block",
41913
42648
  baseFeePerGas: toJson(baseFeePerGas),
@@ -41915,7 +42650,10 @@ var PolygonIdSdk = (function (exports) {
41915
42650
  extraData,
41916
42651
  gasLimit: toJson(gasLimit),
41917
42652
  gasUsed: toJson(gasUsed),
41918
- hash, miner, nonce, number, parentHash, timestamp,
42653
+ blobGasUsed: toJson(this.blobGasUsed),
42654
+ excessBlobGas: toJson(this.excessBlobGas),
42655
+ hash, miner, prevRandao, nonce, number, parentHash, timestamp,
42656
+ parentBeaconBlockRoot, stateRoot, receiptsRoot,
41919
42657
  transactions,
41920
42658
  };
41921
42659
  }
@@ -42173,7 +42911,7 @@ var PolygonIdSdk = (function (exports) {
42173
42911
  */
42174
42912
  provider;
42175
42913
  /**
42176
- * The address the transaction was send to.
42914
+ * The address the transaction was sent to.
42177
42915
  */
42178
42916
  to;
42179
42917
  /**
@@ -42218,6 +42956,10 @@ var PolygonIdSdk = (function (exports) {
42218
42956
  * entire gas limit. After the transaction, the difference is refunded.
42219
42957
  */
42220
42958
  gasUsed;
42959
+ /**
42960
+ * The gas used for BLObs. See [[link-eip-4844]].
42961
+ */
42962
+ blobGasUsed;
42221
42963
  /**
42222
42964
  * The amount of gas used by all transactions within the block for this
42223
42965
  * and all transactions with a lower ``index``.
@@ -42234,6 +42976,10 @@ var PolygonIdSdk = (function (exports) {
42234
42976
  * fee is protocol-enforced.
42235
42977
  */
42236
42978
  gasPrice;
42979
+ /**
42980
+ * The price paid per BLOB in gas. See [[link-eip-4844]].
42981
+ */
42982
+ blobGasPrice;
42237
42983
  /**
42238
42984
  * The [[link-eip-2718]] transaction type.
42239
42985
  */
@@ -42281,7 +43027,9 @@ var PolygonIdSdk = (function (exports) {
42281
43027
  logsBloom: tx.logsBloom,
42282
43028
  gasUsed: tx.gasUsed,
42283
43029
  cumulativeGasUsed: tx.cumulativeGasUsed,
43030
+ blobGasUsed: tx.blobGasUsed,
42284
43031
  gasPrice,
43032
+ blobGasPrice: tx.blobGasPrice,
42285
43033
  type: tx.type,
42286
43034
  //byzantium: tx.byzantium,
42287
43035
  status: tx.status,
@@ -42306,6 +43054,8 @@ var PolygonIdSdk = (function (exports) {
42306
43054
  cumulativeGasUsed: toJson(this.cumulativeGasUsed),
42307
43055
  from,
42308
43056
  gasPrice: toJson(this.gasPrice),
43057
+ blobGasUsed: toJson(this.blobGasUsed),
43058
+ blobGasPrice: toJson(this.blobGasPrice),
42309
43059
  gasUsed: toJson(this.gasUsed),
42310
43060
  hash, index, logs, logsBloom, root, status, to
42311
43061
  };
@@ -42474,6 +43224,10 @@ var PolygonIdSdk = (function (exports) {
42474
43224
  * to charge the sender.
42475
43225
  */
42476
43226
  maxFeePerGas;
43227
+ /**
43228
+ * The [[link-eip-4844]] max fee per BLOb gas.
43229
+ */
43230
+ maxFeePerBlobGas;
42477
43231
  /**
42478
43232
  * The data.
42479
43233
  */
@@ -42496,6 +43250,10 @@ var PolygonIdSdk = (function (exports) {
42496
43250
  * support it, otherwise ``null``.
42497
43251
  */
42498
43252
  accessList;
43253
+ /**
43254
+ * The [[link-eip-4844]] BLOb versioned hashes.
43255
+ */
43256
+ blobVersionedHashes;
42499
43257
  #startBlock;
42500
43258
  /**
42501
43259
  * @_ignore:
@@ -42516,19 +43274,22 @@ var PolygonIdSdk = (function (exports) {
42516
43274
  this.gasPrice = tx.gasPrice;
42517
43275
  this.maxPriorityFeePerGas = (tx.maxPriorityFeePerGas != null) ? tx.maxPriorityFeePerGas : null;
42518
43276
  this.maxFeePerGas = (tx.maxFeePerGas != null) ? tx.maxFeePerGas : null;
43277
+ this.maxFeePerBlobGas = (tx.maxFeePerBlobGas != null) ? tx.maxFeePerBlobGas : null;
42519
43278
  this.chainId = tx.chainId;
42520
43279
  this.signature = tx.signature;
42521
43280
  this.accessList = (tx.accessList != null) ? tx.accessList : null;
43281
+ this.blobVersionedHashes = (tx.blobVersionedHashes != null) ? tx.blobVersionedHashes : null;
42522
43282
  this.#startBlock = -1;
42523
43283
  }
42524
43284
  /**
42525
43285
  * Returns a JSON-compatible representation of this transaction.
42526
43286
  */
42527
43287
  toJSON() {
42528
- const { blockNumber, blockHash, index, hash, type, to, from, nonce, data, signature, accessList } = this;
43288
+ const { blockNumber, blockHash, index, hash, type, to, from, nonce, data, signature, accessList, blobVersionedHashes } = this;
42529
43289
  return {
42530
- _type: "TransactionReceipt",
43290
+ _type: "TransactionResponse",
42531
43291
  accessList, blockNumber, blockHash,
43292
+ blobVersionedHashes,
42532
43293
  chainId: toJson(this.chainId),
42533
43294
  data, from,
42534
43295
  gasLimit: toJson(this.gasLimit),
@@ -42536,6 +43297,7 @@ var PolygonIdSdk = (function (exports) {
42536
43297
  hash,
42537
43298
  maxFeePerGas: toJson(this.maxFeePerGas),
42538
43299
  maxPriorityFeePerGas: toJson(this.maxPriorityFeePerGas),
43300
+ maxFeePerBlobGas: toJson(this.maxFeePerBlobGas),
42539
43301
  nonce, signature, to, index, type,
42540
43302
  value: toJson(this.value),
42541
43303
  };
@@ -42817,6 +43579,13 @@ var PolygonIdSdk = (function (exports) {
42817
43579
  isLondon() {
42818
43580
  return (this.type === 2);
42819
43581
  }
43582
+ /**
43583
+ * Returns true if hte transaction is a Cancun (i.e. ``type == 3``)
43584
+ * transaction. See [[link-eip-4844]].
43585
+ */
43586
+ isCancun() {
43587
+ return (this.type === 3);
43588
+ }
42820
43589
  /**
42821
43590
  * Returns a filter which can be used to listen for orphan events
42822
43591
  * that evict this transaction.
@@ -42976,8 +43745,8 @@ var PolygonIdSdk = (function (exports) {
42976
43745
  * and the transaction has not been mined, otherwise this will
42977
43746
  * wait until enough confirmations have completed.
42978
43747
  */
42979
- async wait(confirms) {
42980
- const receipt = await super.wait(confirms);
43748
+ async wait(confirms, timeout) {
43749
+ const receipt = await super.wait(confirms, timeout);
42981
43750
  if (receipt == null) {
42982
43751
  return null;
42983
43752
  }
@@ -44036,13 +44805,13 @@ var PolygonIdSdk = (function (exports) {
44036
44805
  return false;
44037
44806
  }
44038
44807
  /**
44039
- * Resovles to the encoded %%address%% for %%coinType%%.
44808
+ * Resolves to the encoded %%address%% for %%coinType%%.
44040
44809
  */
44041
44810
  async encodeAddress(coinType, address) {
44042
44811
  throw new Error("unsupported coin");
44043
44812
  }
44044
44813
  /**
44045
- * Resovles to the decoded %%data%% for %%coinType%%.
44814
+ * Resolves to the decoded %%data%% for %%coinType%%.
44046
44815
  */
44047
44816
  async decodeAddress(coinType, data) {
44048
44817
  throw new Error("unsupported coin");
@@ -44122,7 +44891,7 @@ var PolygonIdSdk = (function (exports) {
44122
44891
  info: { funcName }
44123
44892
  });
44124
44893
  params = [
44125
- dnsEncode(this.name),
44894
+ dnsEncode(this.name, 255),
44126
44895
  iface.encodeFunctionData(fragment, params)
44127
44896
  ];
44128
44897
  funcName = "resolve(bytes,bytes)";
@@ -44477,8 +45246,11 @@ var PolygonIdSdk = (function (exports) {
44477
45246
  return format(value);
44478
45247
  });
44479
45248
  }
44480
- function arrayOf(format) {
45249
+ function arrayOf(format, allowNull) {
44481
45250
  return ((array) => {
45251
+ if (allowNull && array == null) {
45252
+ return null;
45253
+ }
44482
45254
  if (!Array.isArray(array)) {
44483
45255
  throw new Error("not an array");
44484
45256
  }
@@ -44553,15 +45325,23 @@ var PolygonIdSdk = (function (exports) {
44553
45325
  const _formatBlock = object({
44554
45326
  hash: allowNull(formatHash),
44555
45327
  parentHash: formatHash,
45328
+ parentBeaconBlockRoot: allowNull(formatHash, null),
44556
45329
  number: getNumber,
44557
45330
  timestamp: getNumber,
44558
45331
  nonce: allowNull(formatData),
44559
45332
  difficulty: getBigInt,
44560
45333
  gasLimit: getBigInt,
44561
45334
  gasUsed: getBigInt,
45335
+ stateRoot: allowNull(formatHash, null),
45336
+ receiptsRoot: allowNull(formatHash, null),
45337
+ blobGasUsed: allowNull(getBigInt, null),
45338
+ excessBlobGas: allowNull(getBigInt, null),
44562
45339
  miner: allowNull(getAddress),
45340
+ prevRandao: allowNull(formatHash, null),
44563
45341
  extraData: formatData,
44564
45342
  baseFeePerGas: allowNull(getBigInt)
45343
+ }, {
45344
+ prevRandao: ["mixHash"]
44565
45345
  });
44566
45346
  function formatBlock(value) {
44567
45347
  const result = _formatBlock(value);
@@ -44596,6 +45376,7 @@ var PolygonIdSdk = (function (exports) {
44596
45376
  index: getNumber,
44597
45377
  root: allowNull(hexlify),
44598
45378
  gasUsed: getBigInt,
45379
+ blobGasUsed: allowNull(getBigInt, null),
44599
45380
  logsBloom: allowNull(formatData),
44600
45381
  blockHash: formatHash,
44601
45382
  hash: formatHash,
@@ -44604,6 +45385,7 @@ var PolygonIdSdk = (function (exports) {
44604
45385
  //confirmations: allowNull(getNumber, null),
44605
45386
  cumulativeGasUsed: getBigInt,
44606
45387
  effectiveGasPrice: allowNull(getBigInt),
45388
+ blobGasPrice: allowNull(getBigInt, null),
44607
45389
  status: allowNull(getNumber),
44608
45390
  type: allowNull(getNumber, 0)
44609
45391
  }, {
@@ -44622,6 +45404,8 @@ var PolygonIdSdk = (function (exports) {
44622
45404
  }
44623
45405
  const result = object({
44624
45406
  hash: formatHash,
45407
+ // Some nodes do not return this, usually test nodes (like Ganache)
45408
+ index: allowNull(getNumber, undefined),
44625
45409
  type: (value) => {
44626
45410
  if (value === "0x" || value == null) {
44627
45411
  return 0;
@@ -44629,15 +45413,16 @@ var PolygonIdSdk = (function (exports) {
44629
45413
  return getNumber(value);
44630
45414
  },
44631
45415
  accessList: allowNull(accessListify, null),
45416
+ blobVersionedHashes: allowNull(arrayOf(formatHash, true), null),
44632
45417
  blockHash: allowNull(formatHash, null),
44633
45418
  blockNumber: allowNull(getNumber, null),
44634
45419
  transactionIndex: allowNull(getNumber, null),
44635
- //confirmations: allowNull(getNumber, null),
44636
45420
  from: getAddress,
44637
45421
  // either (gasPrice) or (maxPriorityFeePerGas + maxFeePerGas) must be set
44638
45422
  gasPrice: allowNull(getBigInt),
44639
45423
  maxPriorityFeePerGas: allowNull(getBigInt),
44640
45424
  maxFeePerGas: allowNull(getBigInt),
45425
+ maxFeePerBlobGas: allowNull(getBigInt, null),
44641
45426
  gasLimit: getBigInt,
44642
45427
  to: allowNull(getAddress, null),
44643
45428
  value: getBigInt,
@@ -44647,7 +45432,8 @@ var PolygonIdSdk = (function (exports) {
44647
45432
  chainId: allowNull(getBigInt, null)
44648
45433
  }, {
44649
45434
  data: ["input"],
44650
- gasLimit: ["gas"]
45435
+ gasLimit: ["gas"],
45436
+ index: ["transactionIndex"]
44651
45437
  })(value);
44652
45438
  // If to and creates are empty, populate the creates from the value
44653
45439
  if (result.to == null && result.creates == null) {
@@ -45173,23 +45959,6 @@ var PolygonIdSdk = (function (exports) {
45173
45959
  }
45174
45960
  });
45175
45961
  }
45176
- // Used by Optimism for a custom priority fee
45177
- function getPriorityFeePlugin(maxPriorityFeePerGas) {
45178
- return new FetchUrlFeeDataNetworkPlugin("data:", async (fetchFeeData, provider, request) => {
45179
- const feeData = await fetchFeeData();
45180
- // This should always fail
45181
- if (feeData.maxFeePerGas == null || feeData.maxPriorityFeePerGas == null) {
45182
- return feeData;
45183
- }
45184
- // Compute the corrected baseFee to recompute the updated values
45185
- const baseFee = feeData.maxFeePerGas - feeData.maxPriorityFeePerGas;
45186
- return {
45187
- gasPrice: feeData.gasPrice,
45188
- maxFeePerGas: (baseFee + maxPriorityFeePerGas),
45189
- maxPriorityFeePerGas
45190
- };
45191
- });
45192
- }
45193
45962
  // See: https://chainlist.org
45194
45963
  let injected = false;
45195
45964
  function injectCommonNetworks() {
@@ -45225,23 +45994,30 @@ var PolygonIdSdk = (function (exports) {
45225
45994
  registerEth("rinkeby", 4, { ensNetwork: 4 });
45226
45995
  registerEth("goerli", 5, { ensNetwork: 5 });
45227
45996
  registerEth("kovan", 42, { ensNetwork: 42 });
45228
- registerEth("sepolia", 11155111, {});
45997
+ registerEth("sepolia", 11155111, { ensNetwork: 11155111 });
45998
+ registerEth("holesky", 17000, { ensNetwork: 17000 });
45229
45999
  registerEth("classic", 61, {});
45230
46000
  registerEth("classicKotti", 6, {});
45231
46001
  registerEth("arbitrum", 42161, {
45232
46002
  ensNetwork: 1,
45233
46003
  });
45234
46004
  registerEth("arbitrum-goerli", 421613, {});
46005
+ registerEth("arbitrum-sepolia", 421614, {});
46006
+ registerEth("base", 8453, { ensNetwork: 1 });
46007
+ registerEth("base-goerli", 84531, {});
46008
+ registerEth("base-sepolia", 84532, {});
45235
46009
  registerEth("bnb", 56, { ensNetwork: 1 });
45236
46010
  registerEth("bnbt", 97, {});
45237
46011
  registerEth("linea", 59144, { ensNetwork: 1 });
45238
46012
  registerEth("linea-goerli", 59140, {});
46013
+ registerEth("linea-sepolia", 59141, {});
45239
46014
  registerEth("matic", 137, {
45240
46015
  ensNetwork: 1,
45241
46016
  plugins: [
45242
46017
  getGasStationPlugin("https:/\/gasstation.polygon.technology/v2")
45243
46018
  ]
45244
46019
  });
46020
+ registerEth("matic-amoy", 80002, {});
45245
46021
  registerEth("matic-mumbai", 80001, {
45246
46022
  altNames: ["maticMumbai", "maticmum"],
45247
46023
  plugins: [
@@ -45250,11 +46026,10 @@ var PolygonIdSdk = (function (exports) {
45250
46026
  });
45251
46027
  registerEth("optimism", 10, {
45252
46028
  ensNetwork: 1,
45253
- plugins: [
45254
- getPriorityFeePlugin(BigInt("1000000"))
45255
- ]
46029
+ plugins: []
45256
46030
  });
45257
46031
  registerEth("optimism-goerli", 420, {});
46032
+ registerEth("optimism-sepolia", 11155420, {});
45258
46033
  registerEth("xdai", 100, { ensNetwork: 1 });
45259
46034
  }
45260
46035
 
@@ -45388,6 +46163,34 @@ var PolygonIdSdk = (function (exports) {
45388
46163
  pause(dropWhilePaused) { this.stop(); }
45389
46164
  resume() { this.start(); }
45390
46165
  }
46166
+ class PollingBlockTagSubscriber extends OnBlockSubscriber {
46167
+ #tag;
46168
+ #lastBlock;
46169
+ constructor(provider, tag) {
46170
+ super(provider);
46171
+ this.#tag = tag;
46172
+ this.#lastBlock = -2;
46173
+ }
46174
+ pause(dropWhilePaused) {
46175
+ if (dropWhilePaused) {
46176
+ this.#lastBlock = -2;
46177
+ }
46178
+ super.pause(dropWhilePaused);
46179
+ }
46180
+ async _poll(blockNumber, provider) {
46181
+ const block = await provider.getBlock(this.#tag);
46182
+ if (block == null) {
46183
+ return;
46184
+ }
46185
+ if (this.#lastBlock === -2) {
46186
+ this.#lastBlock = block.number;
46187
+ }
46188
+ else if (block.number > this.#lastBlock) {
46189
+ provider.emit(this.#tag, block.number);
46190
+ this.#lastBlock = block.number;
46191
+ }
46192
+ }
46193
+ }
45391
46194
  /**
45392
46195
  * @_ignore:
45393
46196
  *
@@ -45586,10 +46389,12 @@ var PolygonIdSdk = (function (exports) {
45586
46389
  if (typeof (_event) === "string") {
45587
46390
  switch (_event) {
45588
46391
  case "block":
45589
- case "pending":
45590
46392
  case "debug":
45591
46393
  case "error":
45592
- case "network": {
46394
+ case "finalized":
46395
+ case "network":
46396
+ case "pending":
46397
+ case "safe": {
45593
46398
  return { type: _event, tag: _event };
45594
46399
  }
45595
46400
  }
@@ -45887,10 +46692,10 @@ var PolygonIdSdk = (function (exports) {
45887
46692
  switch (blockTag) {
45888
46693
  case "earliest":
45889
46694
  return "0x0";
46695
+ case "finalized":
45890
46696
  case "latest":
45891
46697
  case "pending":
45892
46698
  case "safe":
45893
- case "finalized":
45894
46699
  return blockTag;
45895
46700
  }
45896
46701
  if (isHexString(blockTag)) {
@@ -45994,7 +46799,7 @@ var PolygonIdSdk = (function (exports) {
45994
46799
  return resolve(address, fromBlock, toBlock);
45995
46800
  }
45996
46801
  /**
45997
- * Returns or resovles to a transaction for %%request%%, resolving
46802
+ * Returns or resolves to a transaction for %%request%%, resolving
45998
46803
  * any ENS names or [[Addressable]] and returning if already a valid
45999
46804
  * transaction.
46000
46805
  */
@@ -46034,16 +46839,19 @@ var PolygonIdSdk = (function (exports) {
46034
46839
  // No explicit network was set and this is our first time
46035
46840
  if (this.#networkPromise == null) {
46036
46841
  // Detect the current network (shared with all calls)
46037
- const detectNetwork = this._detectNetwork().then((network) => {
46038
- this.emit("network", network, null);
46039
- return network;
46040
- }, (error) => {
46041
- // Reset the networkPromise on failure, so we will try again
46042
- if (this.#networkPromise === detectNetwork) {
46043
- this.#networkPromise = null;
46842
+ const detectNetwork = (async () => {
46843
+ try {
46844
+ const network = await this._detectNetwork();
46845
+ this.emit("network", network, null);
46846
+ return network;
46044
46847
  }
46045
- throw error;
46046
- });
46848
+ catch (error) {
46849
+ if (this.#networkPromise === detectNetwork) {
46850
+ this.#networkPromise = null;
46851
+ }
46852
+ throw error;
46853
+ }
46854
+ })();
46047
46855
  this.#networkPromise = detectNetwork;
46048
46856
  return (await detectNetwork).clone();
46049
46857
  }
@@ -46073,12 +46881,20 @@ var PolygonIdSdk = (function (exports) {
46073
46881
  async getFeeData() {
46074
46882
  const network = await this.getNetwork();
46075
46883
  const getFeeDataFunc = async () => {
46076
- const { _block, gasPrice } = await resolveProperties({
46884
+ const { _block, gasPrice, priorityFee } = await resolveProperties({
46077
46885
  _block: this.#getBlock("latest", false),
46078
46886
  gasPrice: ((async () => {
46079
46887
  try {
46080
- const gasPrice = await this.#perform({ method: "getGasPrice" });
46081
- return getBigInt(gasPrice, "%response");
46888
+ const value = await this.#perform({ method: "getGasPrice" });
46889
+ return getBigInt(value, "%response");
46890
+ }
46891
+ catch (error) { }
46892
+ return null;
46893
+ })()),
46894
+ priorityFee: ((async () => {
46895
+ try {
46896
+ const value = await this.#perform({ method: "getPriorityFee" });
46897
+ return getBigInt(value, "%response");
46082
46898
  }
46083
46899
  catch (error) { }
46084
46900
  return null;
@@ -46089,7 +46905,7 @@ var PolygonIdSdk = (function (exports) {
46089
46905
  // These are the recommended EIP-1559 heuristics for fee data
46090
46906
  const block = this._wrapBlock(_block, network);
46091
46907
  if (block && block.baseFeePerGas) {
46092
- maxPriorityFeePerGas = BigInt("1000000000");
46908
+ maxPriorityFeePerGas = (priorityFee != null) ? priorityFee : BigInt("1000000000");
46093
46909
  maxFeePerGas = (block.baseFeePerGas * BN_2) + maxPriorityFeePerGas;
46094
46910
  }
46095
46911
  return new FeeData(gasPrice, maxFeePerGas, maxPriorityFeePerGas);
@@ -46467,6 +47283,9 @@ var PolygonIdSdk = (function (exports) {
46467
47283
  subscriber.pollingInterval = this.pollingInterval;
46468
47284
  return subscriber;
46469
47285
  }
47286
+ case "safe":
47287
+ case "finalized":
47288
+ return new PollingBlockTagSubscriber(this, sub.type);
46470
47289
  case "event":
46471
47290
  return new PollingEventSubscriber(this, sub.filter);
46472
47291
  case "transaction":
@@ -47017,8 +47836,8 @@ var PolygonIdSdk = (function (exports) {
47017
47836
  });
47018
47837
  }
47019
47838
  }
47020
- else if (pop.type === 2) {
47021
- // Explicitly using EIP-1559
47839
+ else if (pop.type === 2 || pop.type === 3) {
47840
+ // Explicitly using EIP-1559 or EIP-4844
47022
47841
  // Populate missing fee data
47023
47842
  if (pop.maxFeePerGas == null) {
47024
47843
  pop.maxFeePerGas = feeData.maxFeePerGas;
@@ -47148,6 +47967,9 @@ var PolygonIdSdk = (function (exports) {
47148
47967
  if (filterIdPromise) {
47149
47968
  this.#filterIdPromise = null;
47150
47969
  filterIdPromise.then((filterId) => {
47970
+ if (this.#provider.destroyed) {
47971
+ return;
47972
+ }
47151
47973
  this.#provider.send("eth_uninstallFilter", [filterId]);
47152
47974
  });
47153
47975
  }
@@ -47345,12 +48167,45 @@ var PolygonIdSdk = (function (exports) {
47345
48167
  // for it; it should show up very quickly
47346
48168
  return await (new Promise((resolve, reject) => {
47347
48169
  const timeouts = [1000, 100];
48170
+ let invalids = 0;
47348
48171
  const checkTx = async () => {
47349
- // Try getting the transaction
47350
- const tx = await this.provider.getTransaction(hash);
47351
- if (tx != null) {
47352
- resolve(tx.replaceableTransaction(blockNumber));
47353
- return;
48172
+ try {
48173
+ // Try getting the transaction
48174
+ const tx = await this.provider.getTransaction(hash);
48175
+ if (tx != null) {
48176
+ resolve(tx.replaceableTransaction(blockNumber));
48177
+ return;
48178
+ }
48179
+ }
48180
+ catch (error) {
48181
+ // If we were cancelled: stop polling.
48182
+ // If the data is bad: the node returns bad transactions
48183
+ // If the network changed: calling again will also fail
48184
+ // If unsupported: likely destroyed
48185
+ if (isError(error, "CANCELLED") || isError(error, "BAD_DATA") ||
48186
+ isError(error, "NETWORK_ERROR" )) {
48187
+ if (error.info == null) {
48188
+ error.info = {};
48189
+ }
48190
+ error.info.sendTransactionHash = hash;
48191
+ reject(error);
48192
+ return;
48193
+ }
48194
+ // Stop-gap for misbehaving backends; see #4513
48195
+ if (isError(error, "INVALID_ARGUMENT")) {
48196
+ invalids++;
48197
+ if (error.info == null) {
48198
+ error.info = {};
48199
+ }
48200
+ error.info.sendTransactionHash = hash;
48201
+ if (invalids > 10) {
48202
+ reject(error);
48203
+ return;
48204
+ }
48205
+ }
48206
+ // Notify anyone that cares; but we will try again, since
48207
+ // it is likely an intermittent service error
48208
+ this.provider.emit("error", makeError("failed to fetch transation after sending (will try again)", "UNKNOWN_ERROR", { error }));
47354
48209
  }
47355
48210
  // Wait another 4 seconds
47356
48211
  this.provider._setTimeout(() => { checkTx(); }, timeouts.pop() || 4000);
@@ -47423,11 +48278,12 @@ var PolygonIdSdk = (function (exports) {
47423
48278
  #drainTimer;
47424
48279
  #notReady;
47425
48280
  #network;
48281
+ #pendingDetectNetwork;
47426
48282
  #scheduleDrain() {
47427
48283
  if (this.#drainTimer) {
47428
48284
  return;
47429
48285
  }
47430
- // If we aren't using batching, no hard in sending it immeidately
48286
+ // If we aren't using batching, no harm in sending it immediately
47431
48287
  const stallTime = (this._getOption("batchMaxCount") === 1) ? 0 : this._getOption("batchStallTime");
47432
48288
  this.#drainTimer = setTimeout(() => {
47433
48289
  this.#drainTimer = null;
@@ -47498,6 +48354,7 @@ var PolygonIdSdk = (function (exports) {
47498
48354
  this.#payloads = [];
47499
48355
  this.#drainTimer = null;
47500
48356
  this.#network = null;
48357
+ this.#pendingDetectNetwork = null;
47501
48358
  {
47502
48359
  let resolve = null;
47503
48360
  const promise = new Promise((_resolve) => {
@@ -47505,9 +48362,15 @@ var PolygonIdSdk = (function (exports) {
47505
48362
  });
47506
48363
  this.#notReady = { promise, resolve };
47507
48364
  }
47508
- // Make sure any static network is compatbile with the provided netwrok
47509
48365
  const staticNetwork = this._getOption("staticNetwork");
47510
- if (staticNetwork) {
48366
+ if (typeof (staticNetwork) === "boolean") {
48367
+ assertArgument(!staticNetwork || network !== "any", "staticNetwork cannot be used on special network 'any'", "options", options);
48368
+ if (staticNetwork && network != null) {
48369
+ this.#network = Network.from(network);
48370
+ }
48371
+ }
48372
+ else if (staticNetwork) {
48373
+ // Make sure any static network is compatbile with the provided netwrok
47511
48374
  assertArgument(network == null || staticNetwork.matches(network), "staticNetwork MUST match network object", "options", options);
47512
48375
  this.#network = staticNetwork;
47513
48376
  }
@@ -47540,7 +48403,7 @@ var PolygonIdSdk = (function (exports) {
47540
48403
  if (req.method === "call" || req.method === "estimateGas") {
47541
48404
  let tx = req.transaction;
47542
48405
  if (tx && tx.type != null && getBigInt(tx.type)) {
47543
- // If there are no EIP-1559 properties, it might be non-EIP-a559
48406
+ // If there are no EIP-1559 or newer properties, it might be pre-EIP-1559
47544
48407
  if (tx.maxFeePerGas == null && tx.maxPriorityFeePerGas == null) {
47545
48408
  const feeData = await this.getFeeData();
47546
48409
  if (feeData.maxFeePerGas == null && feeData.maxPriorityFeePerGas == null) {
@@ -47568,30 +48431,56 @@ var PolygonIdSdk = (function (exports) {
47568
48431
  async _detectNetwork() {
47569
48432
  const network = this._getOption("staticNetwork");
47570
48433
  if (network) {
47571
- return network;
48434
+ if (network === true) {
48435
+ if (this.#network) {
48436
+ return this.#network;
48437
+ }
48438
+ }
48439
+ else {
48440
+ return network;
48441
+ }
48442
+ }
48443
+ if (this.#pendingDetectNetwork) {
48444
+ return await this.#pendingDetectNetwork;
47572
48445
  }
47573
48446
  // If we are ready, use ``send``, which enabled requests to be batched
47574
48447
  if (this.ready) {
47575
- return Network.from(getBigInt(await this.send("eth_chainId", [])));
48448
+ this.#pendingDetectNetwork = (async () => {
48449
+ try {
48450
+ const result = Network.from(getBigInt(await this.send("eth_chainId", [])));
48451
+ this.#pendingDetectNetwork = null;
48452
+ return result;
48453
+ }
48454
+ catch (error) {
48455
+ this.#pendingDetectNetwork = null;
48456
+ throw error;
48457
+ }
48458
+ })();
48459
+ return await this.#pendingDetectNetwork;
47576
48460
  }
47577
48461
  // We are not ready yet; use the primitive _send
47578
- const payload = {
47579
- id: this.#nextId++, method: "eth_chainId", params: [], jsonrpc: "2.0"
47580
- };
47581
- this.emit("debug", { action: "sendRpcPayload", payload });
47582
- let result;
47583
- try {
47584
- result = (await this._send(payload))[0];
47585
- }
47586
- catch (error) {
47587
- this.emit("debug", { action: "receiveRpcError", error });
47588
- throw error;
47589
- }
47590
- this.emit("debug", { action: "receiveRpcResult", result });
47591
- if ("result" in result) {
47592
- return Network.from(getBigInt(result.result));
47593
- }
47594
- throw this.getRpcError(payload, result);
48462
+ this.#pendingDetectNetwork = (async () => {
48463
+ const payload = {
48464
+ id: this.#nextId++, method: "eth_chainId", params: [], jsonrpc: "2.0"
48465
+ };
48466
+ this.emit("debug", { action: "sendRpcPayload", payload });
48467
+ let result;
48468
+ try {
48469
+ result = (await this._send(payload))[0];
48470
+ this.#pendingDetectNetwork = null;
48471
+ }
48472
+ catch (error) {
48473
+ this.#pendingDetectNetwork = null;
48474
+ this.emit("debug", { action: "receiveRpcError", error });
48475
+ throw error;
48476
+ }
48477
+ this.emit("debug", { action: "receiveRpcResult", result });
48478
+ if ("result" in result) {
48479
+ return Network.from(getBigInt(result.result));
48480
+ }
48481
+ throw this.getRpcError(payload, result);
48482
+ })();
48483
+ return await this.#pendingDetectNetwork;
47595
48484
  }
47596
48485
  /**
47597
48486
  * Sub-classes **MUST** call this. Until [[_start]] has been called, no calls
@@ -47693,6 +48582,14 @@ var PolygonIdSdk = (function (exports) {
47693
48582
  if (tx.accessList) {
47694
48583
  result["accessList"] = accessListify(tx.accessList);
47695
48584
  }
48585
+ if (tx.blobVersionedHashes) {
48586
+ // @TODO: Remove this <any> case once EIP-4844 added to prepared tx
48587
+ result["blobVersionedHashes"] = tx.blobVersionedHashes.map(h => h.toLowerCase());
48588
+ }
48589
+ // @TODO: blobs should probably also be copied over, optionally
48590
+ // accounting for the kzg property to backfill blobVersionedHashes
48591
+ // using the commitment. Or should that be left as an exercise to
48592
+ // the caller?
47696
48593
  return result;
47697
48594
  }
47698
48595
  /**
@@ -47707,6 +48604,8 @@ var PolygonIdSdk = (function (exports) {
47707
48604
  return { method: "eth_blockNumber", args: [] };
47708
48605
  case "getGasPrice":
47709
48606
  return { method: "eth_gasPrice", args: [] };
48607
+ case "getPriorityFee":
48608
+ return { method: "eth_maxPriorityFeePerGas", args: [] };
47710
48609
  case "getBalance":
47711
48610
  return {
47712
48611
  method: "eth_getBalance",
@@ -47957,7 +48856,11 @@ var PolygonIdSdk = (function (exports) {
47957
48856
  #pollingInterval;
47958
48857
  constructor(network, options) {
47959
48858
  super(network, options);
47960
- this.#pollingInterval = 4000;
48859
+ let pollingInterval = this._getOption("pollingInterval");
48860
+ if (pollingInterval == null) {
48861
+ pollingInterval = defaultOptions.pollingInterval;
48862
+ }
48863
+ this.#pollingInterval = pollingInterval;
47961
48864
  }
47962
48865
  _getSubscriber(sub) {
47963
48866
  const subscriber = super._getSubscriber(sub);
@@ -51549,7 +52452,7 @@ var PolygonIdSdk = (function (exports) {
51549
52452
  const chainId = et$2(Z$2.blockchainFromId(idTyped), Z$2.networkIdFromId(idTyped));
51550
52453
  const config = this.networkByChainId(chainId);
51551
52454
  const provider = new JsonRpcProvider(config.url);
51552
- const stateContract = new Contract(config.contractAddress, abi$2, this.provider);
52455
+ const stateContract = new Contract(config.contractAddress, abi$2, provider);
51553
52456
  return { stateContract, provider };
51554
52457
  }
51555
52458
  networkByChainId(chainId) {
@@ -53718,43 +54621,43 @@ var PolygonIdSdk = (function (exports) {
53718
54621
  */
53719
54622
  const PROTOCOL_MESSAGE_TYPE = Object.freeze({
53720
54623
  // AuthorizationV2RequestMessageType defines auth request type of the communication protocol
53721
- AUTHORIZATION_REQUEST_MESSAGE_TYPE: IDEN3_PROTOCOL + 'authorization/1.0/request',
54624
+ AUTHORIZATION_REQUEST_MESSAGE_TYPE: `${IDEN3_PROTOCOL}authorization/1.0/request`,
53722
54625
  // AuthorizationResponseMessageType defines auth response type of the communication protocol
53723
- AUTHORIZATION_RESPONSE_MESSAGE_TYPE: IDEN3_PROTOCOL + 'authorization/1.0/response',
54626
+ AUTHORIZATION_RESPONSE_MESSAGE_TYPE: `${IDEN3_PROTOCOL}authorization/1.0/response`,
53724
54627
  // CredentialIssuanceRequestMessageType accepts request for credential creation
53725
- CREDENTIAL_ISSUANCE_REQUEST_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/1.0/issuance-request',
54628
+ CREDENTIAL_ISSUANCE_REQUEST_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/1.0/issuance-request`,
53726
54629
  // CredentialFetchRequestMessageType is type for request of credential generation
53727
- CREDENTIAL_FETCH_REQUEST_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/1.0/fetch-request',
54630
+ CREDENTIAL_FETCH_REQUEST_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/1.0/fetch-request`,
53728
54631
  // CredentialOfferMessageType is type of message with credential offering
53729
- CREDENTIAL_OFFER_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/1.0/offer',
54632
+ CREDENTIAL_OFFER_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/1.0/offer`,
53730
54633
  // CredentialIssuanceResponseMessageType is type for message with a credential issuance
53731
- CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/1.0/issuance-response',
54634
+ CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/1.0/issuance-response`,
53732
54635
  // CredentialRefreshMessageType is type for message with a credential issuance
53733
- CREDENTIAL_REFRESH_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/1.0/refresh',
54636
+ CREDENTIAL_REFRESH_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/1.0/refresh`,
53734
54637
  // DeviceRegistrationRequestMessageType defines device registration request type of the communication protocol
53735
- DEVICE_REGISTRATION_REQUEST_MESSAGE_TYPE: IDEN3_PROTOCOL + 'devices/1.0/registration',
54638
+ DEVICE_REGISTRATION_REQUEST_MESSAGE_TYPE: `${IDEN3_PROTOCOL}devices/1.0/registration`,
53736
54639
  // MessageFetMessageFetchRequestMessageType defines message fetch request type of the communication protocol.
53737
- MESSAGE_FETCH_REQUEST_MESSAGE_TYPE: IDEN3_PROTOCOL + 'messages/1.0/fetch',
54640
+ MESSAGE_FETCH_REQUEST_MESSAGE_TYPE: `${IDEN3_PROTOCOL}messages/1.0/fetch`,
53738
54641
  // ProofGenerationRequestMessageType is type for request of proof generation
53739
- PROOF_GENERATION_REQUEST_MESSAGE_TYPE: IDEN3_PROTOCOL + 'proofs/1.0/request',
54642
+ PROOF_GENERATION_REQUEST_MESSAGE_TYPE: `${IDEN3_PROTOCOL}proofs/1.0/request`,
53740
54643
  // ProofGenerationResponseMessageType is type for response of proof generation
53741
- PROOF_GENERATION_RESPONSE_MESSAGE_TYPE: IDEN3_PROTOCOL + 'proofs/1.0/response',
54644
+ PROOF_GENERATION_RESPONSE_MESSAGE_TYPE: `${IDEN3_PROTOCOL}proofs/1.0/response`,
53742
54645
  // RevocationStatusRequestMessageType is type for request of revocation status
53743
- REVOCATION_STATUS_REQUEST_MESSAGE_TYPE: IDEN3_PROTOCOL + 'revocation/1.0/request-status',
54646
+ REVOCATION_STATUS_REQUEST_MESSAGE_TYPE: `${IDEN3_PROTOCOL}revocation/1.0/request-status`,
53744
54647
  // RevocationStatusResponseMessageType is type for response with a revocation status
53745
- REVOCATION_STATUS_RESPONSE_MESSAGE_TYPE: IDEN3_PROTOCOL + 'revocation/1.0/status',
54648
+ REVOCATION_STATUS_RESPONSE_MESSAGE_TYPE: `${IDEN3_PROTOCOL}revocation/1.0/status`,
53746
54649
  // ContractInvokeRequestMessageType is type for request of contract invoke request
53747
- CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE: IDEN3_PROTOCOL + 'proofs/1.0/contract-invoke-request',
54650
+ CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE: `${IDEN3_PROTOCOL}proofs/1.0/contract-invoke-request`,
53748
54651
  // CredentialOnchainOfferMessageType is type of message with credential onchain offering
53749
- CREDENTIAL_ONCHAIN_OFFER_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/1.0/onchain-offer',
54652
+ CREDENTIAL_ONCHAIN_OFFER_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/1.0/onchain-offer`,
53750
54653
  // ProposalRequestMessageType is type for proposal-request message
53751
- PROPOSAL_REQUEST_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/0.1/proposal-request',
54654
+ PROPOSAL_REQUEST_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/0.1/proposal-request`,
53752
54655
  // ProposalMessageType is type for proposal message
53753
- PROPOSAL_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/0.1/proposal',
54656
+ PROPOSAL_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/0.1/proposal`,
53754
54657
  // PaymentRequestMessageType is type for payment-request message
53755
- PAYMENT_REQUEST_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/0.1/payment-request',
54658
+ PAYMENT_REQUEST_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/0.1/payment-request`,
53756
54659
  // PaymentMessageType is type for payment message
53757
- PAYMENT_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/0.1/payment'
54660
+ PAYMENT_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/0.1/payment`
53758
54661
  });
53759
54662
  /**
53760
54663
  * Media types for iden3 comm communication protocol
@@ -79391,16 +80294,8 @@ var PolygonIdSdk = (function (exports) {
79391
80294
  await this.updateIdentityState(did, true, newTreeState);
79392
80295
  return txId;
79393
80296
  }
79394
- /** {@inheritdoc IIdentityWallet.addBJJAuthCredential} */
79395
- async addBJJAuthCredential(did, oldTreeState, isOldStateGenesis, ethSigner, opts, prover // it will be needed in case of non ethereum identities
79396
- ) {
79397
- opts.seed = opts.seed ?? V$3(32);
79398
- opts.revocationOpts.nonce =
79399
- opts.revocationOpts.nonce ??
79400
- (isOldStateGenesis
79401
- ? 0
79402
- : opts.revocationOpts.nonce ?? new DataView(V$3(12).buffer).getUint32(0));
79403
- const { authClaim, pubKey } = await this.createAuthCoreClaim(opts.revocationOpts.nonce ?? 0, opts.seed);
80297
+ async getAuthBJJCredential(did, oldTreeState, { nonce, seed, id, type }) {
80298
+ const { authClaim, pubKey } = await this.createAuthCoreClaim(nonce, seed);
79404
80299
  const { hi, hv } = authClaim.hiHv();
79405
80300
  await this._storage.mt.addToMerkleTree(did.string(), exports.MerkleTreeType.Claims, hi, hv);
79406
80301
  // Calculate current state after adding credential to merkle tree
@@ -79410,34 +80305,68 @@ var PolygonIdSdk = (function (exports) {
79410
80305
  oldTreeState.revocationRoot.bigInt(),
79411
80306
  oldTreeState.rootOfRoots.bigInt()
79412
80307
  ]);
79413
- let credential = await this.createAuthBJJCredential(did, pubKey, authClaim, currentState, opts.revocationOpts);
79414
- const txId = await this.transitState(did, oldTreeState, isOldStateGenesis, ethSigner, prover);
79415
- const { receipt, block } = await this._transactionService.getTransactionReceiptAndBlock(txId);
79416
- const credsWithIden3MTPProof = await this.generateIden3SparseMerkleTreeProof(did, [credential], txId, receipt?.blockNumber, block?.timestamp, undefined, {
79417
- revNonce: Number(authClaim.getRevocationNonce()),
79418
- subjectPosition: exports.SubjectPosition.None,
79419
- merklizedRootPosition: exports.MerklizedRootPosition.None,
79420
- updatable: false,
79421
- version: 0,
79422
- merklizeOpts: { documentLoader: cacheLoader() }
80308
+ return this.createAuthBJJCredential(did, pubKey, authClaim, currentState, {
80309
+ id,
80310
+ type
79423
80311
  });
79424
- await this._credentialWallet.saveAll(credsWithIden3MTPProof);
79425
- await this._storage.identity.saveIdentity({
79426
- did: did.string(),
79427
- state: currentState,
79428
- isStatePublished: true,
79429
- isStateGenesis: false
80312
+ }
80313
+ /** {@inheritdoc IIdentityWallet.addBJJAuthCredential} */
80314
+ async addBJJAuthCredential(did, oldTreeState, isOldStateGenesis, ethSigner, opts, prover // it will be needed in case of non ethereum identities
80315
+ ) {
80316
+ opts.seed = opts.seed ?? V$3(32);
80317
+ opts.revocationOpts.nonce =
80318
+ opts.revocationOpts.nonce ??
80319
+ (isOldStateGenesis
80320
+ ? 0
80321
+ : opts.revocationOpts.nonce ?? new DataView(V$3(12).buffer).getUint32(0));
80322
+ const credential = await this.getAuthBJJCredential(did, oldTreeState, {
80323
+ nonce: opts.revocationOpts.nonce,
80324
+ seed: opts.seed,
80325
+ id: opts.revocationOpts.id,
80326
+ type: opts.revocationOpts.type
79430
80327
  });
79431
- const credRefreshed = await this._credentialWallet.findById(credential.id);
79432
- if (!credRefreshed) {
79433
- throw new Error('Credential not found in credential wallet');
80328
+ const addMtpToCredAndPublishRevState = async () => {
80329
+ const { receipt, block } = await this._transactionService.getTransactionReceiptAndBlock(txId);
80330
+ const credsWithIden3MTPProof = await this.generateIden3SparseMerkleTreeProof(did, [credential], txId, receipt?.blockNumber, block?.timestamp, undefined, {
80331
+ revNonce: opts.revocationOpts.nonce ?? 0,
80332
+ subjectPosition: exports.SubjectPosition.None,
80333
+ merklizedRootPosition: exports.MerklizedRootPosition.None,
80334
+ updatable: false,
80335
+ version: 0,
80336
+ merklizeOpts: { documentLoader: cacheLoader() }
80337
+ });
80338
+ await this._credentialWallet.saveAll(credsWithIden3MTPProof);
80339
+ await this.publishRevocationInfoByCredentialStatusType(did, opts.revocationOpts.type, {
80340
+ rhsUrl: opts.revocationOpts.id,
80341
+ onChain: opts.revocationOpts.onChain
80342
+ });
80343
+ return credsWithIden3MTPProof[0];
80344
+ };
80345
+ let txId = '';
80346
+ let attempt = 2;
80347
+ do {
80348
+ try {
80349
+ txId = await this.transitState(did, oldTreeState, isOldStateGenesis, ethSigner, prover);
80350
+ break;
80351
+ }
80352
+ catch (err) {
80353
+ console.warn(`Error while transiting state, retrying state transition, attempt: ${attempt}`, err);
80354
+ }
80355
+ } while (--attempt);
80356
+ if (!txId) {
80357
+ const oldTransitStateInfoJson = JSON.stringify({
80358
+ claimsRoot: oldTreeState.claimsRoot.hex(),
80359
+ revocationRoot: oldTreeState.revocationRoot.hex(),
80360
+ rootOfRoots: oldTreeState.rootOfRoots.hex(),
80361
+ state: oldTreeState.state.hex(),
80362
+ isOldStateGenesis,
80363
+ credentialId: credential.id,
80364
+ did: did.string()
80365
+ }, null, 2);
80366
+ await this._credentialWallet.save(credential);
80367
+ throw new Error(`Error publishing state, info to publish: ${oldTransitStateInfoJson}`);
79434
80368
  }
79435
- credential = credRefreshed;
79436
- await this.publishRevocationInfoByCredentialStatusType(did, opts.revocationOpts.type, {
79437
- rhsUrl: opts.revocationOpts.id,
79438
- onChain: opts.revocationOpts.onChain
79439
- });
79440
- return credential;
80369
+ return addMtpToCredAndPublishRevState();
79441
80370
  }
79442
80371
  }
79443
80372