genlayer 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -7715,7 +7715,7 @@ var version3;
7715
7715
  var init_version2 = __esm({
7716
7716
  "node_modules/viem/_esm/errors/version.js"() {
7717
7717
  "use strict";
7718
- version3 = "2.30.5";
7718
+ version3 = "2.31.7";
7719
7719
  }
7720
7720
  });
7721
7721
 
@@ -8564,6 +8564,46 @@ function byteSwap32(arr) {
8564
8564
  }
8565
8565
  return arr;
8566
8566
  }
8567
+ function bytesToHex2(bytes) {
8568
+ abytes(bytes);
8569
+ if (hasHexBuiltin)
8570
+ return bytes.toHex();
8571
+ let hex = "";
8572
+ for (let i2 = 0; i2 < bytes.length; i2++) {
8573
+ hex += hexes2[bytes[i2]];
8574
+ }
8575
+ return hex;
8576
+ }
8577
+ function asciiToBase16(ch) {
8578
+ if (ch >= asciis._0 && ch <= asciis._9)
8579
+ return ch - asciis._0;
8580
+ if (ch >= asciis.A && ch <= asciis.F)
8581
+ return ch - (asciis.A - 10);
8582
+ if (ch >= asciis.a && ch <= asciis.f)
8583
+ return ch - (asciis.a - 10);
8584
+ return;
8585
+ }
8586
+ function hexToBytes2(hex) {
8587
+ if (typeof hex !== "string")
8588
+ throw new Error("hex string expected, got " + typeof hex);
8589
+ if (hasHexBuiltin)
8590
+ return Uint8Array.fromHex(hex);
8591
+ const hl = hex.length;
8592
+ const al = hl / 2;
8593
+ if (hl % 2)
8594
+ throw new Error("hex string expected, got unpadded hex of length " + hl);
8595
+ const array = new Uint8Array(al);
8596
+ for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
8597
+ const n1 = asciiToBase16(hex.charCodeAt(hi));
8598
+ const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
8599
+ if (n1 === void 0 || n2 === void 0) {
8600
+ const char = hex[hi] + hex[hi + 1];
8601
+ throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
8602
+ }
8603
+ array[ai] = n1 * 16 + n2;
8604
+ }
8605
+ return array;
8606
+ }
8567
8607
  function utf8ToBytes(str) {
8568
8608
  if (typeof str !== "string")
8569
8609
  throw new Error("string expected");
@@ -8607,13 +8647,19 @@ function randomBytes(bytesLength = 32) {
8607
8647
  }
8608
8648
  throw new Error("crypto.getRandomValues must be defined");
8609
8649
  }
8610
- var isLE, swap32IfBE, Hash;
8650
+ var isLE, swap32IfBE, hasHexBuiltin, hexes2, asciis, Hash;
8611
8651
  var init_utils2 = __esm({
8612
8652
  "node_modules/viem/node_modules/@noble/hashes/esm/utils.js"() {
8613
8653
  "use strict";
8614
8654
  init_cryptoNode();
8615
8655
  isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
8616
8656
  swap32IfBE = isLE ? (u) => u : byteSwap32;
8657
+ hasHexBuiltin = /* @__PURE__ */ (() => (
8658
+ // @ts-ignore
8659
+ typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
8660
+ ))();
8661
+ hexes2 = /* @__PURE__ */ Array.from({ length: 256 }, (_, i2) => i2.toString(16).padStart(2, "0"));
8662
+ asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
8617
8663
  Hash = class {
8618
8664
  };
8619
8665
  }
@@ -11480,14 +11526,7 @@ var init_hmac = __esm({
11480
11526
  }
11481
11527
  });
11482
11528
 
11483
- // node_modules/viem/node_modules/@noble/curves/esm/abstract/utils.js
11484
- function isBytes2(a) {
11485
- return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
11486
- }
11487
- function abytes2(item) {
11488
- if (!isBytes2(item))
11489
- throw new Error("Uint8Array expected");
11490
- }
11529
+ // node_modules/viem/node_modules/@noble/curves/esm/utils.js
11491
11530
  function abool(title, value) {
11492
11531
  if (typeof value !== "boolean")
11493
11532
  throw new Error(title + " boolean expected, got " + value);
@@ -11501,51 +11540,11 @@ function hexToNumber2(hex) {
11501
11540
  throw new Error("hex string expected, got " + typeof hex);
11502
11541
  return hex === "" ? _0n2 : BigInt("0x" + hex);
11503
11542
  }
11504
- function bytesToHex2(bytes) {
11505
- abytes2(bytes);
11506
- if (hasHexBuiltin)
11507
- return bytes.toHex();
11508
- let hex = "";
11509
- for (let i2 = 0; i2 < bytes.length; i2++) {
11510
- hex += hexes2[bytes[i2]];
11511
- }
11512
- return hex;
11513
- }
11514
- function asciiToBase16(ch) {
11515
- if (ch >= asciis._0 && ch <= asciis._9)
11516
- return ch - asciis._0;
11517
- if (ch >= asciis.A && ch <= asciis.F)
11518
- return ch - (asciis.A - 10);
11519
- if (ch >= asciis.a && ch <= asciis.f)
11520
- return ch - (asciis.a - 10);
11521
- return;
11522
- }
11523
- function hexToBytes2(hex) {
11524
- if (typeof hex !== "string")
11525
- throw new Error("hex string expected, got " + typeof hex);
11526
- if (hasHexBuiltin)
11527
- return Uint8Array.fromHex(hex);
11528
- const hl = hex.length;
11529
- const al = hl / 2;
11530
- if (hl % 2)
11531
- throw new Error("hex string expected, got unpadded hex of length " + hl);
11532
- const array = new Uint8Array(al);
11533
- for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
11534
- const n1 = asciiToBase16(hex.charCodeAt(hi));
11535
- const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
11536
- if (n1 === void 0 || n2 === void 0) {
11537
- const char = hex[hi] + hex[hi + 1];
11538
- throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
11539
- }
11540
- array[ai] = n1 * 16 + n2;
11541
- }
11542
- return array;
11543
- }
11544
11543
  function bytesToNumberBE(bytes) {
11545
11544
  return hexToNumber2(bytesToHex2(bytes));
11546
11545
  }
11547
11546
  function bytesToNumberLE(bytes) {
11548
- abytes2(bytes);
11547
+ abytes(bytes);
11549
11548
  return hexToNumber2(bytesToHex2(Uint8Array.from(bytes).reverse()));
11550
11549
  }
11551
11550
  function numberToBytesBE(n, len) {
@@ -11562,7 +11561,7 @@ function ensureBytes(title, hex, expectedLength) {
11562
11561
  } catch (e2) {
11563
11562
  throw new Error(title + " must be hex string or Uint8Array, cause: " + e2);
11564
11563
  }
11565
- } else if (isBytes2(hex)) {
11564
+ } else if (isBytes(hex)) {
11566
11565
  res = Uint8Array.from(hex);
11567
11566
  } else {
11568
11567
  throw new Error(title + " must be hex string or Uint8Array");
@@ -11572,26 +11571,6 @@ function ensureBytes(title, hex, expectedLength) {
11572
11571
  throw new Error(title + " of length " + expectedLength + " expected, got " + len);
11573
11572
  return res;
11574
11573
  }
11575
- function concatBytes3(...arrays) {
11576
- let sum = 0;
11577
- for (let i2 = 0; i2 < arrays.length; i2++) {
11578
- const a = arrays[i2];
11579
- abytes2(a);
11580
- sum += a.length;
11581
- }
11582
- const res = new Uint8Array(sum);
11583
- for (let i2 = 0, pad4 = 0; i2 < arrays.length; i2++) {
11584
- const a = arrays[i2];
11585
- res.set(a, pad4);
11586
- pad4 += a.length;
11587
- }
11588
- return res;
11589
- }
11590
- function utf8ToBytes2(str) {
11591
- if (typeof str !== "string")
11592
- throw new Error("string expected");
11593
- return new Uint8Array(new TextEncoder().encode(str));
11594
- }
11595
11574
  function inRange(n, min, max) {
11596
11575
  return isPosBig(n) && isPosBig(min) && isPosBig(max) && min <= n && n < max;
11597
11576
  }
@@ -11612,6 +11591,8 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
11612
11591
  throw new Error("qByteLen must be a number");
11613
11592
  if (typeof hmacFn !== "function")
11614
11593
  throw new Error("hmacFn must be a function");
11594
+ const u8n = (len) => new Uint8Array(len);
11595
+ const u8of = (byte) => Uint8Array.of(byte);
11615
11596
  let v = u8n(hashLen);
11616
11597
  let k = u8n(hashLen);
11617
11598
  let i2 = 0;
@@ -11622,11 +11603,11 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
11622
11603
  };
11623
11604
  const h2 = (...b) => hmacFn(k, v, ...b);
11624
11605
  const reseed = (seed = u8n(0)) => {
11625
- k = h2(u8fr([0]), seed);
11606
+ k = h2(u8of(0), seed);
11626
11607
  v = h2();
11627
11608
  if (seed.length === 0)
11628
11609
  return;
11629
- k = h2(u8fr([1]), seed);
11610
+ k = h2(u8of(1), seed);
11630
11611
  v = h2();
11631
11612
  };
11632
11613
  const gen3 = () => {
@@ -11640,7 +11621,7 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
11640
11621
  out.push(sl);
11641
11622
  len += v.length;
11642
11623
  }
11643
- return concatBytes3(...out);
11624
+ return concatBytes(...out);
11644
11625
  };
11645
11626
  const genUntil = (seed, pred) => {
11646
11627
  reset();
@@ -11653,23 +11634,22 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
11653
11634
  };
11654
11635
  return genUntil;
11655
11636
  }
11656
- function validateObject(object, validators, optValidators = {}) {
11657
- const checkField = (fieldName, type, isOptional) => {
11658
- const checkVal = validatorFns[type];
11659
- if (typeof checkVal !== "function")
11660
- throw new Error("invalid validator function");
11637
+ function isHash(val) {
11638
+ return typeof val === "function" && Number.isSafeInteger(val.outputLen);
11639
+ }
11640
+ function _validateObject(object, fields, optFields = {}) {
11641
+ if (!object || typeof object !== "object")
11642
+ throw new Error("expected valid options object");
11643
+ function checkField(fieldName, expectedType, isOpt) {
11661
11644
  const val = object[fieldName];
11662
- if (isOptional && val === void 0)
11645
+ if (isOpt && val === void 0)
11663
11646
  return;
11664
- if (!checkVal(val, object)) {
11665
- throw new Error("param " + String(fieldName) + " is invalid. Expected " + type + ", got " + val);
11666
- }
11667
- };
11668
- for (const [fieldName, type] of Object.entries(validators))
11669
- checkField(fieldName, type, false);
11670
- for (const [fieldName, type] of Object.entries(optValidators))
11671
- checkField(fieldName, type, true);
11672
- return object;
11647
+ const current = typeof val;
11648
+ if (current !== expectedType || val === null)
11649
+ throw new Error(`param "${fieldName}" is invalid: expected ${expectedType}, got ${current}`);
11650
+ }
11651
+ Object.entries(fields).forEach(([k, v]) => checkField(k, v, false));
11652
+ Object.entries(optFields).forEach(([k, v]) => checkField(k, v, true));
11673
11653
  }
11674
11654
  function memoized(fn) {
11675
11655
  const map = /* @__PURE__ */ new WeakMap();
@@ -11682,31 +11662,16 @@ function memoized(fn) {
11682
11662
  return computed;
11683
11663
  };
11684
11664
  }
11685
- var _0n2, _1n2, hasHexBuiltin, hexes2, asciis, isPosBig, bitMask, u8n, u8fr, validatorFns;
11665
+ var _0n2, _1n2, isPosBig, bitMask;
11686
11666
  var init_utils4 = __esm({
11687
- "node_modules/viem/node_modules/@noble/curves/esm/abstract/utils.js"() {
11667
+ "node_modules/viem/node_modules/@noble/curves/esm/utils.js"() {
11688
11668
  "use strict";
11669
+ init_utils2();
11670
+ init_utils2();
11689
11671
  _0n2 = /* @__PURE__ */ BigInt(0);
11690
11672
  _1n2 = /* @__PURE__ */ BigInt(1);
11691
- hasHexBuiltin = // @ts-ignore
11692
- typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function";
11693
- hexes2 = /* @__PURE__ */ Array.from({ length: 256 }, (_, i2) => i2.toString(16).padStart(2, "0"));
11694
- asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
11695
11673
  isPosBig = (n) => typeof n === "bigint" && _0n2 <= n;
11696
11674
  bitMask = (n) => (_1n2 << BigInt(n)) - _1n2;
11697
- u8n = (len) => new Uint8Array(len);
11698
- u8fr = (arr) => Uint8Array.from(arr);
11699
- validatorFns = {
11700
- bigint: (val) => typeof val === "bigint",
11701
- function: (val) => typeof val === "function",
11702
- boolean: (val) => typeof val === "boolean",
11703
- string: (val) => typeof val === "string",
11704
- stringOrUint8Array: (val) => typeof val === "string" || isBytes2(val),
11705
- isSafeInteger: (val) => Number.isSafeInteger(val),
11706
- array: (val) => Array.isArray(val),
11707
- field: (val, object) => object.Fp.isValid(val),
11708
- hash: (val) => typeof val === "function" && Number.isSafeInteger(val.outputLen)
11709
- };
11710
11675
  }
11711
11676
  });
11712
11677
 
@@ -11821,14 +11786,15 @@ function validateField(field) {
11821
11786
  const initial = {
11822
11787
  ORDER: "bigint",
11823
11788
  MASK: "bigint",
11824
- BYTES: "isSafeInteger",
11825
- BITS: "isSafeInteger"
11789
+ BYTES: "number",
11790
+ BITS: "number"
11826
11791
  };
11827
11792
  const opts = FIELD_FIELDS.reduce((map, val) => {
11828
11793
  map[val] = "function";
11829
11794
  return map;
11830
11795
  }, initial);
11831
- return validateObject(field, opts);
11796
+ _validateObject(field, opts);
11797
+ return field;
11832
11798
  }
11833
11799
  function FpPow(Fp, num2, power) {
11834
11800
  if (power < _0n3)
@@ -11881,10 +11847,28 @@ function nLength(n, nBitLength) {
11881
11847
  const nByteLength = Math.ceil(_nBitLength / 8);
11882
11848
  return { nBitLength: _nBitLength, nByteLength };
11883
11849
  }
11884
- function Field(ORDER, bitLen2, isLE3 = false, redef = {}) {
11850
+ function Field(ORDER, bitLenOrOpts, isLE3 = false, opts = {}) {
11885
11851
  if (ORDER <= _0n3)
11886
11852
  throw new Error("invalid field: expected ORDER > 0, got " + ORDER);
11887
- const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, bitLen2);
11853
+ let _nbitLength = void 0;
11854
+ let _sqrt = void 0;
11855
+ if (typeof bitLenOrOpts === "object" && bitLenOrOpts != null) {
11856
+ if (opts.sqrt || isLE3)
11857
+ throw new Error("cannot specify opts in two arguments");
11858
+ const _opts = bitLenOrOpts;
11859
+ if (_opts.BITS)
11860
+ _nbitLength = _opts.BITS;
11861
+ if (_opts.sqrt)
11862
+ _sqrt = _opts.sqrt;
11863
+ if (typeof _opts.isLE === "boolean")
11864
+ isLE3 = _opts.isLE;
11865
+ } else {
11866
+ if (typeof bitLenOrOpts === "number")
11867
+ _nbitLength = bitLenOrOpts;
11868
+ if (opts.sqrt)
11869
+ _sqrt = opts.sqrt;
11870
+ }
11871
+ const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, _nbitLength);
11888
11872
  if (BYTES > 2048)
11889
11873
  throw new Error("invalid field: expected ORDER of <= 2048 bytes");
11890
11874
  let sqrtP;
@@ -11903,6 +11887,8 @@ function Field(ORDER, bitLen2, isLE3 = false, redef = {}) {
11903
11887
  return _0n3 <= num2 && num2 < ORDER;
11904
11888
  },
11905
11889
  is0: (num2) => num2 === _0n3,
11890
+ // is valid and invertible
11891
+ isValidNot0: (num2) => !f3.is0(num2) && f3.isValid(num2),
11906
11892
  isOdd: (num2) => (num2 & _1n3) === _1n3,
11907
11893
  neg: (num2) => mod(-num2, ORDER),
11908
11894
  eql: (lhs, rhs) => lhs === rhs,
@@ -11918,7 +11904,7 @@ function Field(ORDER, bitLen2, isLE3 = false, redef = {}) {
11918
11904
  subN: (lhs, rhs) => lhs - rhs,
11919
11905
  mulN: (lhs, rhs) => lhs * rhs,
11920
11906
  inv: (num2) => invert(num2, ORDER),
11921
- sqrt: redef.sqrt || ((n) => {
11907
+ sqrt: _sqrt || ((n) => {
11922
11908
  if (!sqrtP)
11923
11909
  sqrtP = FpSqrt(ORDER);
11924
11910
  return sqrtP(f3, n);
@@ -11961,7 +11947,6 @@ var _0n3, _1n3, _2n2, _3n, _4n, _5n, _8n, FIELD_FIELDS;
11961
11947
  var init_modular = __esm({
11962
11948
  "node_modules/viem/node_modules/@noble/curves/esm/abstract/modular.js"() {
11963
11949
  "use strict";
11964
- init_utils2();
11965
11950
  init_utils4();
11966
11951
  _0n3 = BigInt(0);
11967
11952
  _1n3 = BigInt(1);
@@ -11993,10 +11978,16 @@ var init_modular = __esm({
11993
11978
  });
11994
11979
 
11995
11980
  // node_modules/viem/node_modules/@noble/curves/esm/abstract/curve.js
11996
- function constTimeNegate(condition, item) {
11981
+ function negateCt(condition, item) {
11997
11982
  const neg = item.negate();
11998
11983
  return condition ? neg : item;
11999
11984
  }
11985
+ function normalizeZ(c, property, points) {
11986
+ const getz = property === "pz" ? (p) => p.pz : (p) => p.ez;
11987
+ const toInv = FpInvertBatch(c.Fp, points.map(getz));
11988
+ const affined = points.map((p, i2) => p.toAffine(toInv[i2]));
11989
+ return affined.map(c.fromAffine);
11990
+ }
12000
11991
  function validateW(W, bits) {
12001
11992
  if (!Number.isSafeInteger(W) || W <= 0 || W > bits)
12002
11993
  throw new Error("invalid window size, expected [1.." + bits + "], got W=" + W);
@@ -12045,9 +12036,13 @@ function validateMSMScalars(scalars, field) {
12045
12036
  function getW(P) {
12046
12037
  return pointWindowSizes.get(P) || 1;
12047
12038
  }
12039
+ function assert0(n) {
12040
+ if (n !== _0n4)
12041
+ throw new Error("invalid wNAF");
12042
+ }
12048
12043
  function wNAF(c, bits) {
12049
12044
  return {
12050
- constTimeNegate,
12045
+ constTimeNegate: negateCt,
12051
12046
  hasPrecomputes(elm) {
12052
12047
  return getW(elm) !== 1;
12053
12048
  },
@@ -12105,11 +12100,12 @@ function wNAF(c, bits) {
12105
12100
  const { nextN, offset, isZero, isNeg, isNegF, offsetF } = calcOffsets(n, window2, wo);
12106
12101
  n = nextN;
12107
12102
  if (isZero) {
12108
- f3 = f3.add(constTimeNegate(isNegF, precomputes[offsetF]));
12103
+ f3 = f3.add(negateCt(isNegF, precomputes[offsetF]));
12109
12104
  } else {
12110
- p = p.add(constTimeNegate(isNeg, precomputes[offset]));
12105
+ p = p.add(negateCt(isNeg, precomputes[offset]));
12111
12106
  }
12112
12107
  }
12108
+ assert0(n);
12113
12109
  return { p, f: f3 };
12114
12110
  },
12115
12111
  /**
@@ -12134,14 +12130,18 @@ function wNAF(c, bits) {
12134
12130
  acc = acc.add(isNeg ? item.negate() : item);
12135
12131
  }
12136
12132
  }
12133
+ assert0(n);
12137
12134
  return acc;
12138
12135
  },
12139
12136
  getPrecomputes(W, P, transform) {
12140
12137
  let comp = pointPrecomputes.get(P);
12141
12138
  if (!comp) {
12142
12139
  comp = this.precomputeWindow(P, W);
12143
- if (W !== 1)
12144
- pointPrecomputes.set(P, transform(comp));
12140
+ if (W !== 1) {
12141
+ if (typeof transform === "function")
12142
+ comp = transform(comp);
12143
+ pointPrecomputes.set(P, comp);
12144
+ }
12145
12145
  }
12146
12146
  return comp;
12147
12147
  },
@@ -12165,6 +12165,21 @@ function wNAF(c, bits) {
12165
12165
  }
12166
12166
  };
12167
12167
  }
12168
+ function mulEndoUnsafe(c, point, k1, k2) {
12169
+ let acc = point;
12170
+ let p1 = c.ZERO;
12171
+ let p2 = c.ZERO;
12172
+ while (k1 > _0n4 || k2 > _0n4) {
12173
+ if (k1 & _1n4)
12174
+ p1 = p1.add(acc);
12175
+ if (k2 & _1n4)
12176
+ p2 = p2.add(acc);
12177
+ acc = acc.double();
12178
+ k1 >>= _1n4;
12179
+ k2 >>= _1n4;
12180
+ }
12181
+ return { p1, p2 };
12182
+ }
12168
12183
  function pippenger(c, fieldN, points, scalars) {
12169
12184
  validateMSMPoints(points, c);
12170
12185
  validateMSMScalars(scalars, fieldN);
@@ -12204,29 +12219,40 @@ function pippenger(c, fieldN, points, scalars) {
12204
12219
  }
12205
12220
  return sum;
12206
12221
  }
12207
- function validateBasic(curve) {
12208
- validateField(curve.Fp);
12209
- validateObject(curve, {
12210
- n: "bigint",
12211
- h: "bigint",
12212
- Gx: "field",
12213
- Gy: "field"
12214
- }, {
12215
- nBitLength: "isSafeInteger",
12216
- nByteLength: "isSafeInteger"
12217
- });
12218
- return Object.freeze({
12219
- ...nLength(curve.n, curve.nBitLength),
12220
- ...curve,
12221
- ...{ p: curve.Fp.ORDER }
12222
- });
12222
+ function createField(order, field) {
12223
+ if (field) {
12224
+ if (field.ORDER !== order)
12225
+ throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
12226
+ validateField(field);
12227
+ return field;
12228
+ } else {
12229
+ return Field(order);
12230
+ }
12231
+ }
12232
+ function _createCurveFields(type, CURVE, curveOpts = {}) {
12233
+ if (!CURVE || typeof CURVE !== "object")
12234
+ throw new Error(`expected valid ${type} CURVE object`);
12235
+ for (const p of ["p", "n", "h"]) {
12236
+ const val = CURVE[p];
12237
+ if (!(typeof val === "bigint" && val > _0n4))
12238
+ throw new Error(`CURVE.${p} must be positive bigint`);
12239
+ }
12240
+ const Fp = createField(CURVE.p, curveOpts.Fp);
12241
+ const Fn = createField(CURVE.n, curveOpts.Fn);
12242
+ const _b = type === "weierstrass" ? "b" : "d";
12243
+ const params = ["Gx", "Gy", "a", _b];
12244
+ for (const p of params) {
12245
+ if (!Fp.isValid(CURVE[p]))
12246
+ throw new Error(`CURVE.${p} must be valid field element of CURVE.Fp`);
12247
+ }
12248
+ return { Fp, Fn };
12223
12249
  }
12224
12250
  var _0n4, _1n4, pointPrecomputes, pointWindowSizes;
12225
12251
  var init_curve = __esm({
12226
12252
  "node_modules/viem/node_modules/@noble/curves/esm/abstract/curve.js"() {
12227
12253
  "use strict";
12228
- init_modular();
12229
12254
  init_utils4();
12255
+ init_modular();
12230
12256
  _0n4 = BigInt(0);
12231
12257
  _1n4 = BigInt(1);
12232
12258
  pointPrecomputes = /* @__PURE__ */ new WeakMap();
@@ -12241,54 +12267,116 @@ function validateSigVerOpts(opts) {
12241
12267
  if (opts.prehash !== void 0)
12242
12268
  abool("prehash", opts.prehash);
12243
12269
  }
12244
- function validatePointOpts(curve) {
12245
- const opts = validateBasic(curve);
12246
- validateObject(opts, {
12247
- a: "field",
12248
- b: "field"
12249
- }, {
12270
+ function _legacyHelperEquat(Fp, a, b) {
12271
+ function weierstrassEquation(x2) {
12272
+ const x22 = Fp.sqr(x2);
12273
+ const x3 = Fp.mul(x22, x2);
12274
+ return Fp.add(Fp.add(x3, Fp.mul(x2, a)), b);
12275
+ }
12276
+ return weierstrassEquation;
12277
+ }
12278
+ function _legacyHelperNormPriv(Fn, allowedPrivateKeyLengths, wrapPrivateKey) {
12279
+ const { BYTES: expected } = Fn;
12280
+ function normPrivateKeyToScalar(key) {
12281
+ let num2;
12282
+ if (typeof key === "bigint") {
12283
+ num2 = key;
12284
+ } else {
12285
+ let bytes = ensureBytes("private key", key);
12286
+ if (allowedPrivateKeyLengths) {
12287
+ if (!allowedPrivateKeyLengths.includes(bytes.length * 2))
12288
+ throw new Error("invalid private key");
12289
+ const padded = new Uint8Array(expected);
12290
+ padded.set(bytes, padded.length - bytes.length);
12291
+ bytes = padded;
12292
+ }
12293
+ try {
12294
+ num2 = Fn.fromBytes(bytes);
12295
+ } catch (error) {
12296
+ throw new Error(`invalid private key: expected ui8a of size ${expected}, got ${typeof key}`);
12297
+ }
12298
+ }
12299
+ if (wrapPrivateKey)
12300
+ num2 = Fn.create(num2);
12301
+ if (!Fn.isValidNot0(num2))
12302
+ throw new Error("invalid private key: out of range [1..N-1]");
12303
+ return num2;
12304
+ }
12305
+ return normPrivateKeyToScalar;
12306
+ }
12307
+ function weierstrassN(CURVE, curveOpts = {}) {
12308
+ const { Fp, Fn } = _createCurveFields("weierstrass", CURVE, curveOpts);
12309
+ const { h: cofactor, n: CURVE_ORDER } = CURVE;
12310
+ _validateObject(curveOpts, {}, {
12250
12311
  allowInfinityPoint: "boolean",
12251
- allowedPrivateKeyLengths: "array",
12252
12312
  clearCofactor: "function",
12253
- fromBytes: "function",
12254
12313
  isTorsionFree: "function",
12314
+ fromBytes: "function",
12255
12315
  toBytes: "function",
12316
+ endo: "object",
12256
12317
  wrapPrivateKey: "boolean"
12257
12318
  });
12258
- const { endo, Fp, a } = opts;
12319
+ const { endo } = curveOpts;
12259
12320
  if (endo) {
12260
- if (!Fp.eql(a, Fp.ZERO)) {
12261
- throw new Error("invalid endo: CURVE.a must be 0");
12262
- }
12263
- if (typeof endo !== "object" || typeof endo.beta !== "bigint" || typeof endo.splitScalar !== "function") {
12321
+ if (!Fp.is0(CURVE.a) || typeof endo.beta !== "bigint" || typeof endo.splitScalar !== "function") {
12264
12322
  throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');
12265
12323
  }
12266
12324
  }
12267
- return Object.freeze({ ...opts });
12268
- }
12269
- function numToSizedHex(num2, size5) {
12270
- return bytesToHex2(numberToBytesBE(num2, size5));
12271
- }
12272
- function weierstrassPoints(opts) {
12273
- const CURVE = validatePointOpts(opts);
12274
- const { Fp } = CURVE;
12275
- const Fn = Field(CURVE.n, CURVE.nBitLength);
12276
- const toBytes4 = CURVE.toBytes || ((_c, point, _isCompressed) => {
12277
- const a = point.toAffine();
12278
- return concatBytes3(Uint8Array.from([4]), Fp.toBytes(a.x), Fp.toBytes(a.y));
12279
- });
12280
- const fromBytes2 = CURVE.fromBytes || ((bytes) => {
12325
+ function assertCompressionIsSupported() {
12326
+ if (!Fp.isOdd)
12327
+ throw new Error("compression is not supported: Field does not have .isOdd()");
12328
+ }
12329
+ function pointToBytes2(_c, point, isCompressed) {
12330
+ const { x: x2, y } = point.toAffine();
12331
+ const bx = Fp.toBytes(x2);
12332
+ abool("isCompressed", isCompressed);
12333
+ if (isCompressed) {
12334
+ assertCompressionIsSupported();
12335
+ const hasEvenY = !Fp.isOdd(y);
12336
+ return concatBytes(pprefix(hasEvenY), bx);
12337
+ } else {
12338
+ return concatBytes(Uint8Array.of(4), bx, Fp.toBytes(y));
12339
+ }
12340
+ }
12341
+ function pointFromBytes(bytes) {
12342
+ abytes(bytes);
12343
+ const L = Fp.BYTES;
12344
+ const LC = L + 1;
12345
+ const LU = 2 * L + 1;
12346
+ const length = bytes.length;
12347
+ const head = bytes[0];
12281
12348
  const tail = bytes.subarray(1);
12282
- const x2 = Fp.fromBytes(tail.subarray(0, Fp.BYTES));
12283
- const y = Fp.fromBytes(tail.subarray(Fp.BYTES, 2 * Fp.BYTES));
12284
- return { x: x2, y };
12285
- });
12286
- function weierstrassEquation(x2) {
12287
- const { a, b } = CURVE;
12288
- const x22 = Fp.sqr(x2);
12289
- const x3 = Fp.mul(x22, x2);
12290
- return Fp.add(Fp.add(x3, Fp.mul(x2, a)), b);
12349
+ if (length === LC && (head === 2 || head === 3)) {
12350
+ const x2 = Fp.fromBytes(tail);
12351
+ if (!Fp.isValid(x2))
12352
+ throw new Error("bad point: is not on curve, wrong x");
12353
+ const y2 = weierstrassEquation(x2);
12354
+ let y;
12355
+ try {
12356
+ y = Fp.sqrt(y2);
12357
+ } catch (sqrtError) {
12358
+ const err = sqrtError instanceof Error ? ": " + sqrtError.message : "";
12359
+ throw new Error("bad point: is not on curve, sqrt error" + err);
12360
+ }
12361
+ assertCompressionIsSupported();
12362
+ const isYOdd = Fp.isOdd(y);
12363
+ const isHeadOdd = (head & 1) === 1;
12364
+ if (isHeadOdd !== isYOdd)
12365
+ y = Fp.neg(y);
12366
+ return { x: x2, y };
12367
+ } else if (length === LU && head === 4) {
12368
+ const x2 = Fp.fromBytes(tail.subarray(L * 0, L * 1));
12369
+ const y = Fp.fromBytes(tail.subarray(L * 1, L * 2));
12370
+ if (!isValidXY(x2, y))
12371
+ throw new Error("bad point: is not on curve");
12372
+ return { x: x2, y };
12373
+ } else {
12374
+ throw new Error(`bad point: got length ${length}, expected compressed=${LC} or uncompressed=${LU}`);
12375
+ }
12291
12376
  }
12377
+ const toBytes4 = curveOpts.toBytes || pointToBytes2;
12378
+ const fromBytes2 = curveOpts.fromBytes || pointFromBytes;
12379
+ const weierstrassEquation = _legacyHelperEquat(Fp, CURVE.a, CURVE.b);
12292
12380
  function isValidXY(x2, y) {
12293
12381
  const left = Fp.sqr(y);
12294
12382
  const right = weierstrassEquation(x2);
@@ -12300,28 +12388,10 @@ function weierstrassPoints(opts) {
12300
12388
  const _27b2 = Fp.mul(Fp.sqr(CURVE.b), BigInt(27));
12301
12389
  if (Fp.is0(Fp.add(_4a3, _27b2)))
12302
12390
  throw new Error("bad curve params: a or b");
12303
- function isWithinCurveOrder(num2) {
12304
- return inRange(num2, _1n5, CURVE.n);
12305
- }
12306
- function normPrivateKeyToScalar(key) {
12307
- const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n: N } = CURVE;
12308
- if (lengths && typeof key !== "bigint") {
12309
- if (isBytes2(key))
12310
- key = bytesToHex2(key);
12311
- if (typeof key !== "string" || !lengths.includes(key.length))
12312
- throw new Error("invalid private key");
12313
- key = key.padStart(nByteLength * 2, "0");
12314
- }
12315
- let num2;
12316
- try {
12317
- num2 = typeof key === "bigint" ? key : bytesToNumberBE(ensureBytes("private key", key, nByteLength));
12318
- } catch (error) {
12319
- throw new Error("invalid private key, expected hex or " + nByteLength + " bytes, got " + typeof key);
12320
- }
12321
- if (wrapPrivateKey)
12322
- num2 = mod(num2, N);
12323
- aInRange("private key", num2, _1n5, N);
12324
- return num2;
12391
+ function acoord(title, n, banZero = false) {
12392
+ if (!Fp.isValid(n) || banZero && Fp.is0(n))
12393
+ throw new Error(`bad point coordinate ${title}`);
12394
+ return n;
12325
12395
  }
12326
12396
  function aprjpoint(other) {
12327
12397
  if (!(other instanceof Point2))
@@ -12345,42 +12415,41 @@ function weierstrassPoints(opts) {
12345
12415
  });
12346
12416
  const assertValidMemo = memoized((p) => {
12347
12417
  if (p.is0()) {
12348
- if (CURVE.allowInfinityPoint && !Fp.is0(p.py))
12418
+ if (curveOpts.allowInfinityPoint && !Fp.is0(p.py))
12349
12419
  return;
12350
12420
  throw new Error("bad point: ZERO");
12351
12421
  }
12352
12422
  const { x: x2, y } = p.toAffine();
12353
12423
  if (!Fp.isValid(x2) || !Fp.isValid(y))
12354
- throw new Error("bad point: x or y not FE");
12424
+ throw new Error("bad point: x or y not field elements");
12355
12425
  if (!isValidXY(x2, y))
12356
12426
  throw new Error("bad point: equation left != right");
12357
12427
  if (!p.isTorsionFree())
12358
12428
  throw new Error("bad point: not in prime-order subgroup");
12359
12429
  return true;
12360
12430
  });
12431
+ function finishEndo(endoBeta, k1p, k2p, k1neg, k2neg) {
12432
+ k2p = new Point2(Fp.mul(k2p.px, endoBeta), k2p.py, k2p.pz);
12433
+ k1p = negateCt(k1neg, k1p);
12434
+ k2p = negateCt(k2neg, k2p);
12435
+ return k1p.add(k2p);
12436
+ }
12361
12437
  class Point2 {
12438
+ /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
12362
12439
  constructor(px, py, pz) {
12363
- if (px == null || !Fp.isValid(px))
12364
- throw new Error("x required");
12365
- if (py == null || !Fp.isValid(py) || Fp.is0(py))
12366
- throw new Error("y required");
12367
- if (pz == null || !Fp.isValid(pz))
12368
- throw new Error("z required");
12369
- this.px = px;
12370
- this.py = py;
12371
- this.pz = pz;
12440
+ this.px = acoord("x", px);
12441
+ this.py = acoord("y", py, true);
12442
+ this.pz = acoord("z", pz);
12372
12443
  Object.freeze(this);
12373
12444
  }
12374
- // Does not validate if the point is on-curve.
12375
- // Use fromHex instead, or call assertValidity() later.
12445
+ /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
12376
12446
  static fromAffine(p) {
12377
12447
  const { x: x2, y } = p || {};
12378
12448
  if (!p || !Fp.isValid(x2) || !Fp.isValid(y))
12379
12449
  throw new Error("invalid affine point");
12380
12450
  if (p instanceof Point2)
12381
12451
  throw new Error("projective point not allowed");
12382
- const is0 = (i2) => Fp.eql(i2, Fp.ZERO);
12383
- if (is0(x2) && is0(y))
12452
+ if (Fp.is0(x2) && Fp.is0(y))
12384
12453
  return Point2.ZERO;
12385
12454
  return new Point2(x2, y, Fp.ONE);
12386
12455
  }
@@ -12390,50 +12459,56 @@ function weierstrassPoints(opts) {
12390
12459
  get y() {
12391
12460
  return this.toAffine().y;
12392
12461
  }
12393
- /**
12394
- * Takes a bunch of Projective Points but executes only one
12395
- * inversion on all of them. Inversion is very slow operation,
12396
- * so this improves performance massively.
12397
- * Optimization: converts a list of projective points to a list of identical points with Z=1.
12398
- */
12399
12462
  static normalizeZ(points) {
12400
- const toInv = FpInvertBatch(Fp, points.map((p) => p.pz));
12401
- return points.map((p, i2) => p.toAffine(toInv[i2])).map(Point2.fromAffine);
12463
+ return normalizeZ(Point2, "pz", points);
12402
12464
  }
12403
- /**
12404
- * Converts hash string or Uint8Array to Point.
12405
- * @param hex short/long ECDSA hex
12406
- */
12465
+ static fromBytes(bytes) {
12466
+ abytes(bytes);
12467
+ return Point2.fromHex(bytes);
12468
+ }
12469
+ /** Converts hash string or Uint8Array to Point. */
12407
12470
  static fromHex(hex) {
12408
12471
  const P = Point2.fromAffine(fromBytes2(ensureBytes("pointHex", hex)));
12409
12472
  P.assertValidity();
12410
12473
  return P;
12411
12474
  }
12412
- // Multiplies generator point by privateKey.
12475
+ /** Multiplies generator point by privateKey. */
12413
12476
  static fromPrivateKey(privateKey) {
12477
+ const normPrivateKeyToScalar = _legacyHelperNormPriv(Fn, curveOpts.allowedPrivateKeyLengths, curveOpts.wrapPrivateKey);
12414
12478
  return Point2.BASE.multiply(normPrivateKeyToScalar(privateKey));
12415
12479
  }
12416
- // Multiscalar Multiplication
12480
+ /** Multiscalar Multiplication */
12417
12481
  static msm(points, scalars) {
12418
12482
  return pippenger(Point2, Fn, points, scalars);
12419
12483
  }
12420
- // "Private method", don't use it directly
12421
- _setWindowSize(windowSize) {
12484
+ /**
12485
+ *
12486
+ * @param windowSize
12487
+ * @param isLazy true will defer table computation until the first multiplication
12488
+ * @returns
12489
+ */
12490
+ precompute(windowSize = 8, isLazy = true) {
12422
12491
  wnaf.setWindowSize(this, windowSize);
12492
+ if (!isLazy)
12493
+ this.multiply(_3n2);
12494
+ return this;
12495
+ }
12496
+ /** "Private method", don't use it directly */
12497
+ _setWindowSize(windowSize) {
12498
+ this.precompute(windowSize);
12423
12499
  }
12424
- // A point on curve is valid if it conforms to equation.
12500
+ // TODO: return `this`
12501
+ /** A point on curve is valid if it conforms to equation. */
12425
12502
  assertValidity() {
12426
12503
  assertValidMemo(this);
12427
12504
  }
12428
12505
  hasEvenY() {
12429
12506
  const { y } = this.toAffine();
12430
- if (Fp.isOdd)
12431
- return !Fp.isOdd(y);
12432
- throw new Error("Field doesn't support isOdd");
12507
+ if (!Fp.isOdd)
12508
+ throw new Error("Field doesn't support isOdd");
12509
+ return !Fp.isOdd(y);
12433
12510
  }
12434
- /**
12435
- * Compare one point to another.
12436
- */
12511
+ /** Compare one point to another. */
12437
12512
  equals(other) {
12438
12513
  aprjpoint(other);
12439
12514
  const { px: X1, py: Y1, pz: Z1 } = this;
@@ -12442,9 +12517,7 @@ function weierstrassPoints(opts) {
12442
12517
  const U2 = Fp.eql(Fp.mul(Y1, Z2), Fp.mul(Y2, Z1));
12443
12518
  return U1 && U2;
12444
12519
  }
12445
- /**
12446
- * Flips point to one corresponding to (x, -y) in Affine coordinates.
12447
- */
12520
+ /** Flips point to one corresponding to (x, -y) in Affine coordinates. */
12448
12521
  negate() {
12449
12522
  return new Point2(this.px, Fp.neg(this.py), this.pz);
12450
12523
  }
@@ -12549,44 +12622,6 @@ function weierstrassPoints(opts) {
12549
12622
  is0() {
12550
12623
  return this.equals(Point2.ZERO);
12551
12624
  }
12552
- wNAF(n) {
12553
- return wnaf.wNAFCached(this, n, Point2.normalizeZ);
12554
- }
12555
- /**
12556
- * Non-constant-time multiplication. Uses double-and-add algorithm.
12557
- * It's faster, but should only be used when you don't care about
12558
- * an exposed private key e.g. sig verification, which works over *public* keys.
12559
- */
12560
- multiplyUnsafe(sc) {
12561
- const { endo: endo2, n: N } = CURVE;
12562
- aInRange("scalar", sc, _0n5, N);
12563
- const I = Point2.ZERO;
12564
- if (sc === _0n5)
12565
- return I;
12566
- if (this.is0() || sc === _1n5)
12567
- return this;
12568
- if (!endo2 || wnaf.hasPrecomputes(this))
12569
- return wnaf.wNAFCachedUnsafe(this, sc, Point2.normalizeZ);
12570
- let { k1neg, k1, k2neg, k2 } = endo2.splitScalar(sc);
12571
- let k1p = I;
12572
- let k2p = I;
12573
- let d = this;
12574
- while (k1 > _0n5 || k2 > _0n5) {
12575
- if (k1 & _1n5)
12576
- k1p = k1p.add(d);
12577
- if (k2 & _1n5)
12578
- k2p = k2p.add(d);
12579
- d = d.double();
12580
- k1 >>= _1n5;
12581
- k2 >>= _1n5;
12582
- }
12583
- if (k1neg)
12584
- k1p = k1p.negate();
12585
- if (k2neg)
12586
- k2p = k2p.negate();
12587
- k2p = new Point2(Fp.mul(k2p.px, endo2.beta), k2p.py, k2p.pz);
12588
- return k1p.add(k2p);
12589
- }
12590
12625
  /**
12591
12626
  * Constant time multiplication.
12592
12627
  * Uses wNAF method. Windowed method may be 10% faster,
@@ -12597,162 +12632,133 @@ function weierstrassPoints(opts) {
12597
12632
  * @returns New point
12598
12633
  */
12599
12634
  multiply(scalar) {
12600
- const { endo: endo2, n: N } = CURVE;
12601
- aInRange("scalar", scalar, _1n5, N);
12635
+ const { endo: endo2 } = curveOpts;
12636
+ if (!Fn.isValidNot0(scalar))
12637
+ throw new Error("invalid scalar: out of range");
12602
12638
  let point, fake;
12639
+ const mul = (n) => wnaf.wNAFCached(this, n, Point2.normalizeZ);
12603
12640
  if (endo2) {
12604
12641
  const { k1neg, k1, k2neg, k2 } = endo2.splitScalar(scalar);
12605
- let { p: k1p, f: f1p } = this.wNAF(k1);
12606
- let { p: k2p, f: f2p } = this.wNAF(k2);
12607
- k1p = wnaf.constTimeNegate(k1neg, k1p);
12608
- k2p = wnaf.constTimeNegate(k2neg, k2p);
12609
- k2p = new Point2(Fp.mul(k2p.px, endo2.beta), k2p.py, k2p.pz);
12610
- point = k1p.add(k2p);
12611
- fake = f1p.add(f2p);
12642
+ const { p: k1p, f: k1f } = mul(k1);
12643
+ const { p: k2p, f: k2f } = mul(k2);
12644
+ fake = k1f.add(k2f);
12645
+ point = finishEndo(endo2.beta, k1p, k2p, k1neg, k2neg);
12612
12646
  } else {
12613
- const { p, f: f3 } = this.wNAF(scalar);
12647
+ const { p, f: f3 } = mul(scalar);
12614
12648
  point = p;
12615
12649
  fake = f3;
12616
12650
  }
12617
12651
  return Point2.normalizeZ([point, fake])[0];
12618
12652
  }
12619
12653
  /**
12620
- * Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
12621
- * Not using Strauss-Shamir trick: precomputation tables are faster.
12622
- * The trick could be useful if both P and Q are not G (not in our case).
12623
- * @returns non-zero affine point
12654
+ * Non-constant-time multiplication. Uses double-and-add algorithm.
12655
+ * It's faster, but should only be used when you don't care about
12656
+ * an exposed private key e.g. sig verification, which works over *public* keys.
12624
12657
  */
12658
+ multiplyUnsafe(sc) {
12659
+ const { endo: endo2 } = curveOpts;
12660
+ const p = this;
12661
+ if (!Fn.isValid(sc))
12662
+ throw new Error("invalid scalar: out of range");
12663
+ if (sc === _0n5 || p.is0())
12664
+ return Point2.ZERO;
12665
+ if (sc === _1n5)
12666
+ return p;
12667
+ if (wnaf.hasPrecomputes(this))
12668
+ return this.multiply(sc);
12669
+ if (endo2) {
12670
+ const { k1neg, k1, k2neg, k2 } = endo2.splitScalar(sc);
12671
+ const { p1, p2 } = mulEndoUnsafe(Point2, p, k1, k2);
12672
+ return finishEndo(endo2.beta, p1, p2, k1neg, k2neg);
12673
+ } else {
12674
+ return wnaf.wNAFCachedUnsafe(p, sc);
12675
+ }
12676
+ }
12625
12677
  multiplyAndAddUnsafe(Q, a, b) {
12626
- const G = Point2.BASE;
12627
- const mul = (P, a2) => a2 === _0n5 || a2 === _1n5 || !P.equals(G) ? P.multiplyUnsafe(a2) : P.multiply(a2);
12628
- const sum = mul(this, a).add(mul(Q, b));
12678
+ const sum = this.multiplyUnsafe(a).add(Q.multiplyUnsafe(b));
12629
12679
  return sum.is0() ? void 0 : sum;
12630
12680
  }
12631
- // Converts Projective point to affine (x, y) coordinates.
12632
- // Can accept precomputed Z^-1 - for example, from invertBatch.
12633
- // (x, y, z) (x=x/z, y=y/z)
12634
- toAffine(iz) {
12635
- return toAffineMemo(this, iz);
12681
+ /**
12682
+ * Converts Projective point to affine (x, y) coordinates.
12683
+ * @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
12684
+ */
12685
+ toAffine(invertedZ) {
12686
+ return toAffineMemo(this, invertedZ);
12636
12687
  }
12688
+ /**
12689
+ * Checks whether Point is free of torsion elements (is in prime subgroup).
12690
+ * Always torsion-free for cofactor=1 curves.
12691
+ */
12637
12692
  isTorsionFree() {
12638
- const { h: cofactor, isTorsionFree } = CURVE;
12693
+ const { isTorsionFree } = curveOpts;
12639
12694
  if (cofactor === _1n5)
12640
12695
  return true;
12641
12696
  if (isTorsionFree)
12642
12697
  return isTorsionFree(Point2, this);
12643
- throw new Error("isTorsionFree() has not been declared for the elliptic curve");
12698
+ return wnaf.wNAFCachedUnsafe(this, CURVE_ORDER).is0();
12644
12699
  }
12645
12700
  clearCofactor() {
12646
- const { h: cofactor, clearCofactor } = CURVE;
12701
+ const { clearCofactor } = curveOpts;
12647
12702
  if (cofactor === _1n5)
12648
12703
  return this;
12649
12704
  if (clearCofactor)
12650
12705
  return clearCofactor(Point2, this);
12651
- return this.multiplyUnsafe(CURVE.h);
12706
+ return this.multiplyUnsafe(cofactor);
12652
12707
  }
12653
- toRawBytes(isCompressed = true) {
12708
+ toBytes(isCompressed = true) {
12654
12709
  abool("isCompressed", isCompressed);
12655
12710
  this.assertValidity();
12656
12711
  return toBytes4(Point2, this, isCompressed);
12657
12712
  }
12713
+ /** @deprecated use `toBytes` */
12714
+ toRawBytes(isCompressed = true) {
12715
+ return this.toBytes(isCompressed);
12716
+ }
12658
12717
  toHex(isCompressed = true) {
12659
- abool("isCompressed", isCompressed);
12660
- return bytesToHex2(this.toRawBytes(isCompressed));
12718
+ return bytesToHex2(this.toBytes(isCompressed));
12719
+ }
12720
+ toString() {
12721
+ return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
12661
12722
  }
12662
12723
  }
12663
12724
  Point2.BASE = new Point2(CURVE.Gx, CURVE.Gy, Fp.ONE);
12664
12725
  Point2.ZERO = new Point2(Fp.ZERO, Fp.ONE, Fp.ZERO);
12665
- const { endo, nBitLength } = CURVE;
12666
- const wnaf = wNAF(Point2, endo ? Math.ceil(nBitLength / 2) : nBitLength);
12667
- return {
12668
- CURVE,
12669
- ProjectivePoint: Point2,
12670
- normPrivateKeyToScalar,
12671
- weierstrassEquation,
12672
- isWithinCurveOrder
12673
- };
12726
+ Point2.Fp = Fp;
12727
+ Point2.Fn = Fn;
12728
+ const bits = Fn.BITS;
12729
+ const wnaf = wNAF(Point2, curveOpts.endo ? Math.ceil(bits / 2) : bits);
12730
+ return Point2;
12731
+ }
12732
+ function pprefix(hasEvenY) {
12733
+ return Uint8Array.of(hasEvenY ? 2 : 3);
12674
12734
  }
12675
- function validateOpts(curve) {
12676
- const opts = validateBasic(curve);
12677
- validateObject(opts, {
12678
- hash: "hash",
12735
+ function ecdsa(Point2, ecdsaOpts, curveOpts = {}) {
12736
+ _validateObject(ecdsaOpts, { hash: "function" }, {
12679
12737
  hmac: "function",
12680
- randomBytes: "function"
12681
- }, {
12738
+ lowS: "boolean",
12739
+ randomBytes: "function",
12682
12740
  bits2int: "function",
12683
- bits2int_modN: "function",
12684
- lowS: "boolean"
12685
- });
12686
- return Object.freeze({ lowS: true, ...opts });
12687
- }
12688
- function weierstrass(curveDef) {
12689
- const CURVE = validateOpts(curveDef);
12690
- const { Fp, n: CURVE_ORDER, nByteLength, nBitLength } = CURVE;
12691
- const compressedLen = Fp.BYTES + 1;
12692
- const uncompressedLen = 2 * Fp.BYTES + 1;
12693
- function modN2(a) {
12694
- return mod(a, CURVE_ORDER);
12695
- }
12696
- function invN(a) {
12697
- return invert(a, CURVE_ORDER);
12698
- }
12699
- const { ProjectivePoint: Point2, normPrivateKeyToScalar, weierstrassEquation, isWithinCurveOrder } = weierstrassPoints({
12700
- ...CURVE,
12701
- toBytes(_c, point, isCompressed) {
12702
- const a = point.toAffine();
12703
- const x2 = Fp.toBytes(a.x);
12704
- const cat = concatBytes3;
12705
- abool("isCompressed", isCompressed);
12706
- if (isCompressed) {
12707
- return cat(Uint8Array.from([point.hasEvenY() ? 2 : 3]), x2);
12708
- } else {
12709
- return cat(Uint8Array.from([4]), x2, Fp.toBytes(a.y));
12710
- }
12711
- },
12712
- fromBytes(bytes) {
12713
- const len = bytes.length;
12714
- const head = bytes[0];
12715
- const tail = bytes.subarray(1);
12716
- if (len === compressedLen && (head === 2 || head === 3)) {
12717
- const x2 = bytesToNumberBE(tail);
12718
- if (!inRange(x2, _1n5, Fp.ORDER))
12719
- throw new Error("Point is not on curve");
12720
- const y2 = weierstrassEquation(x2);
12721
- let y;
12722
- try {
12723
- y = Fp.sqrt(y2);
12724
- } catch (sqrtError) {
12725
- const suffix = sqrtError instanceof Error ? ": " + sqrtError.message : "";
12726
- throw new Error("Point is not on curve" + suffix);
12727
- }
12728
- const isYOdd = (y & _1n5) === _1n5;
12729
- const isHeadOdd = (head & 1) === 1;
12730
- if (isHeadOdd !== isYOdd)
12731
- y = Fp.neg(y);
12732
- return { x: x2, y };
12733
- } else if (len === uncompressedLen && head === 4) {
12734
- const x2 = Fp.fromBytes(tail.subarray(0, Fp.BYTES));
12735
- const y = Fp.fromBytes(tail.subarray(Fp.BYTES, 2 * Fp.BYTES));
12736
- return { x: x2, y };
12737
- } else {
12738
- const cl = compressedLen;
12739
- const ul = uncompressedLen;
12740
- throw new Error("invalid Point, expected length of " + cl + ", or uncompressed " + ul + ", got " + len);
12741
- }
12742
- }
12741
+ bits2int_modN: "function"
12743
12742
  });
12743
+ const randomBytes_ = ecdsaOpts.randomBytes || randomBytes;
12744
+ const hmac_ = ecdsaOpts.hmac || ((key, ...msgs) => hmac(ecdsaOpts.hash, key, concatBytes(...msgs)));
12745
+ const { Fp, Fn } = Point2;
12746
+ const { ORDER: CURVE_ORDER, BITS: fnBits } = Fn;
12744
12747
  function isBiggerThanHalfOrder(number) {
12745
12748
  const HALF = CURVE_ORDER >> _1n5;
12746
12749
  return number > HALF;
12747
12750
  }
12748
12751
  function normalizeS(s2) {
12749
- return isBiggerThanHalfOrder(s2) ? modN2(-s2) : s2;
12752
+ return isBiggerThanHalfOrder(s2) ? Fn.neg(s2) : s2;
12753
+ }
12754
+ function aValidRS(title, num2) {
12755
+ if (!Fn.isValidNot0(num2))
12756
+ throw new Error(`invalid signature ${title}: out of range 1..CURVE.n`);
12750
12757
  }
12751
- const slcNum = (b, from5, to) => bytesToNumberBE(b.slice(from5, to));
12752
12758
  class Signature {
12753
12759
  constructor(r2, s2, recovery) {
12754
- aInRange("r", r2, _1n5, CURVE_ORDER);
12755
- aInRange("s", s2, _1n5, CURVE_ORDER);
12760
+ aValidRS("r", r2);
12761
+ aValidRS("s", s2);
12756
12762
  this.r = r2;
12757
12763
  this.s = s2;
12758
12764
  if (recovery != null)
@@ -12761,9 +12767,9 @@ function weierstrass(curveDef) {
12761
12767
  }
12762
12768
  // pair (bytes of r, bytes of s)
12763
12769
  static fromCompact(hex) {
12764
- const l = nByteLength;
12765
- hex = ensureBytes("compactSignature", hex, l * 2);
12766
- return new Signature(slcNum(hex, 0, l), slcNum(hex, l, 2 * l));
12770
+ const L = Fn.BYTES;
12771
+ const b = ensureBytes("compactSignature", hex, L * 2);
12772
+ return new Signature(Fn.fromBytes(b.subarray(0, L)), Fn.fromBytes(b.subarray(L, L * 2)));
12767
12773
  }
12768
12774
  // DER encoded ECDSA signature
12769
12775
  // https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
@@ -12780,21 +12786,26 @@ function weierstrass(curveDef) {
12780
12786
  addRecoveryBit(recovery) {
12781
12787
  return new Signature(this.r, this.s, recovery);
12782
12788
  }
12789
+ // ProjPointType<bigint>
12783
12790
  recoverPublicKey(msgHash) {
12791
+ const FIELD_ORDER = Fp.ORDER;
12784
12792
  const { r: r2, s: s2, recovery: rec } = this;
12785
- const h2 = bits2int_modN(ensureBytes("msgHash", msgHash));
12786
12793
  if (rec == null || ![0, 1, 2, 3].includes(rec))
12787
12794
  throw new Error("recovery id invalid");
12788
- const radj = rec === 2 || rec === 3 ? r2 + CURVE.n : r2;
12789
- if (radj >= Fp.ORDER)
12795
+ const hasCofactor = CURVE_ORDER * _2n3 < FIELD_ORDER;
12796
+ if (hasCofactor && rec > 1)
12797
+ throw new Error("recovery id is ambiguous for h>1 curve");
12798
+ const radj = rec === 2 || rec === 3 ? r2 + CURVE_ORDER : r2;
12799
+ if (!Fp.isValid(radj))
12790
12800
  throw new Error("recovery id 2 or 3 invalid");
12791
- const prefix = (rec & 1) === 0 ? "02" : "03";
12792
- const R = Point2.fromHex(prefix + numToSizedHex(radj, Fp.BYTES));
12793
- const ir = invN(radj);
12794
- const u1 = modN2(-h2 * ir);
12795
- const u2 = modN2(s2 * ir);
12796
- const Q = Point2.BASE.multiplyAndAddUnsafe(R, u1, u2);
12797
- if (!Q)
12801
+ const x2 = Fp.toBytes(radj);
12802
+ const R = Point2.fromHex(concatBytes(pprefix((rec & 1) === 0), x2));
12803
+ const ir = Fn.inv(radj);
12804
+ const h2 = bits2int_modN(ensureBytes("msgHash", msgHash));
12805
+ const u1 = Fn.create(-h2 * ir);
12806
+ const u2 = Fn.create(s2 * ir);
12807
+ const Q = Point2.BASE.multiplyUnsafe(u1).add(R.multiplyUnsafe(u2));
12808
+ if (Q.is0())
12798
12809
  throw new Error("point at infinify");
12799
12810
  Q.assertValidity();
12800
12811
  return Q;
@@ -12804,24 +12815,31 @@ function weierstrass(curveDef) {
12804
12815
  return isBiggerThanHalfOrder(this.s);
12805
12816
  }
12806
12817
  normalizeS() {
12807
- return this.hasHighS() ? new Signature(this.r, modN2(-this.s), this.recovery) : this;
12818
+ return this.hasHighS() ? new Signature(this.r, Fn.neg(this.s), this.recovery) : this;
12819
+ }
12820
+ toBytes(format) {
12821
+ if (format === "compact")
12822
+ return concatBytes(Fn.toBytes(this.r), Fn.toBytes(this.s));
12823
+ if (format === "der")
12824
+ return hexToBytes2(DER.hexFromSig(this));
12825
+ throw new Error("invalid format");
12808
12826
  }
12809
12827
  // DER-encoded
12810
12828
  toDERRawBytes() {
12811
- return hexToBytes2(this.toDERHex());
12829
+ return this.toBytes("der");
12812
12830
  }
12813
12831
  toDERHex() {
12814
- return DER.hexFromSig(this);
12832
+ return bytesToHex2(this.toBytes("der"));
12815
12833
  }
12816
12834
  // padded bytes of r, then padded bytes of s
12817
12835
  toCompactRawBytes() {
12818
- return hexToBytes2(this.toCompactHex());
12836
+ return this.toBytes("compact");
12819
12837
  }
12820
12838
  toCompactHex() {
12821
- const l = nByteLength;
12822
- return numToSizedHex(this.r, l) + numToSizedHex(this.s, l);
12839
+ return bytesToHex2(this.toBytes("compact"));
12823
12840
  }
12824
12841
  }
12842
+ const normPrivateKeyToScalar = _legacyHelperNormPriv(Fn, curveOpts.allowedPrivateKeyLengths, curveOpts.wrapPrivateKey);
12825
12843
  const utils = {
12826
12844
  isValidPrivateKey(privateKey) {
12827
12845
  try {
@@ -12837,25 +12855,15 @@ function weierstrass(curveDef) {
12837
12855
  * (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
12838
12856
  */
12839
12857
  randomPrivateKey: () => {
12840
- const length = getMinHashLength(CURVE.n);
12841
- return mapHashToField(CURVE.randomBytes(length), CURVE.n);
12858
+ const n = CURVE_ORDER;
12859
+ return mapHashToField(randomBytes_(getMinHashLength(n)), n);
12842
12860
  },
12843
- /**
12844
- * Creates precompute table for an arbitrary EC point. Makes point "cached".
12845
- * Allows to massively speed-up `point.multiply(scalar)`.
12846
- * @returns cached point
12847
- * @example
12848
- * const fast = utils.precompute(8, ProjectivePoint.fromHex(someonesPubKey));
12849
- * fast.multiply(privKey); // much faster ECDH now
12850
- */
12851
12861
  precompute(windowSize = 8, point = Point2.BASE) {
12852
- point._setWindowSize(windowSize);
12853
- point.multiply(BigInt(3));
12854
- return point;
12862
+ return point.precompute(windowSize, false);
12855
12863
  }
12856
12864
  };
12857
12865
  function getPublicKey(privateKey, isCompressed = true) {
12858
- return Point2.fromPrivateKey(privateKey).toRawBytes(isCompressed);
12866
+ return Point2.fromPrivateKey(privateKey).toBytes(isCompressed);
12859
12867
  }
12860
12868
  function isProbPub(item) {
12861
12869
  if (typeof item === "bigint")
@@ -12863,14 +12871,14 @@ function weierstrass(curveDef) {
12863
12871
  if (item instanceof Point2)
12864
12872
  return true;
12865
12873
  const arr = ensureBytes("key", item);
12866
- const len = arr.length;
12867
- const fpl = Fp.BYTES;
12868
- const compLen = fpl + 1;
12869
- const uncompLen = 2 * fpl + 1;
12870
- if (CURVE.allowedPrivateKeyLengths || nByteLength === compLen) {
12874
+ const length = arr.length;
12875
+ const L = Fp.BYTES;
12876
+ const LC = L + 1;
12877
+ const LU = 2 * L + 1;
12878
+ if (curveOpts.allowedPrivateKeyLengths || Fn.BYTES === LC) {
12871
12879
  return void 0;
12872
12880
  } else {
12873
- return len === compLen || len === uncompLen;
12881
+ return length === LC || length === LU;
12874
12882
  }
12875
12883
  }
12876
12884
  function getSharedSecret(privateA, publicB, isCompressed = true) {
@@ -12879,27 +12887,27 @@ function weierstrass(curveDef) {
12879
12887
  if (isProbPub(publicB) === false)
12880
12888
  throw new Error("second arg must be public key");
12881
12889
  const b = Point2.fromHex(publicB);
12882
- return b.multiply(normPrivateKeyToScalar(privateA)).toRawBytes(isCompressed);
12890
+ return b.multiply(normPrivateKeyToScalar(privateA)).toBytes(isCompressed);
12883
12891
  }
12884
- const bits2int = CURVE.bits2int || function(bytes) {
12892
+ const bits2int = ecdsaOpts.bits2int || function(bytes) {
12885
12893
  if (bytes.length > 8192)
12886
12894
  throw new Error("input is too large");
12887
12895
  const num2 = bytesToNumberBE(bytes);
12888
- const delta = bytes.length * 8 - nBitLength;
12896
+ const delta = bytes.length * 8 - fnBits;
12889
12897
  return delta > 0 ? num2 >> BigInt(delta) : num2;
12890
12898
  };
12891
- const bits2int_modN = CURVE.bits2int_modN || function(bytes) {
12892
- return modN2(bits2int(bytes));
12899
+ const bits2int_modN = ecdsaOpts.bits2int_modN || function(bytes) {
12900
+ return Fn.create(bits2int(bytes));
12893
12901
  };
12894
- const ORDER_MASK = bitMask(nBitLength);
12902
+ const ORDER_MASK = bitMask(fnBits);
12895
12903
  function int2octets(num2) {
12896
- aInRange("num < 2^" + nBitLength, num2, _0n5, ORDER_MASK);
12897
- return numberToBytesBE(num2, nByteLength);
12904
+ aInRange("num < 2^" + fnBits, num2, _0n5, ORDER_MASK);
12905
+ return Fn.toBytes(num2);
12898
12906
  }
12899
12907
  function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
12900
12908
  if (["recovered", "canonical"].some((k) => k in opts))
12901
12909
  throw new Error("sign() legacy options not supported");
12902
- const { hash: hash2, randomBytes: randomBytes2 } = CURVE;
12910
+ const { hash: hash2 } = ecdsaOpts;
12903
12911
  let { lowS, prehash, extraEntropy: ent } = opts;
12904
12912
  if (lowS == null)
12905
12913
  lowS = true;
@@ -12911,21 +12919,21 @@ function weierstrass(curveDef) {
12911
12919
  const d = normPrivateKeyToScalar(privateKey);
12912
12920
  const seedArgs = [int2octets(d), int2octets(h1int)];
12913
12921
  if (ent != null && ent !== false) {
12914
- const e2 = ent === true ? randomBytes2(Fp.BYTES) : ent;
12922
+ const e2 = ent === true ? randomBytes_(Fp.BYTES) : ent;
12915
12923
  seedArgs.push(ensureBytes("extraEntropy", e2));
12916
12924
  }
12917
- const seed = concatBytes3(...seedArgs);
12925
+ const seed = concatBytes(...seedArgs);
12918
12926
  const m2 = h1int;
12919
12927
  function k2sig(kBytes) {
12920
12928
  const k = bits2int(kBytes);
12921
- if (!isWithinCurveOrder(k))
12929
+ if (!Fn.isValidNot0(k))
12922
12930
  return;
12923
- const ik = invN(k);
12931
+ const ik = Fn.inv(k);
12924
12932
  const q = Point2.BASE.multiply(k).toAffine();
12925
- const r2 = modN2(q.x);
12933
+ const r2 = Fn.create(q.x);
12926
12934
  if (r2 === _0n5)
12927
12935
  return;
12928
- const s2 = modN2(ik * modN2(m2 + r2 * d));
12936
+ const s2 = Fn.create(ik * Fn.create(m2 + r2 * d));
12929
12937
  if (s2 === _0n5)
12930
12938
  return;
12931
12939
  let recovery = (q.x === r2 ? 0 : 2) | Number(q.y & _1n5);
@@ -12938,34 +12946,38 @@ function weierstrass(curveDef) {
12938
12946
  }
12939
12947
  return { seed, k2sig };
12940
12948
  }
12941
- const defaultSigOpts = { lowS: CURVE.lowS, prehash: false };
12942
- const defaultVerOpts = { lowS: CURVE.lowS, prehash: false };
12949
+ const defaultSigOpts = { lowS: ecdsaOpts.lowS, prehash: false };
12950
+ const defaultVerOpts = { lowS: ecdsaOpts.lowS, prehash: false };
12943
12951
  function sign2(msgHash, privKey, opts = defaultSigOpts) {
12944
12952
  const { seed, k2sig } = prepSig(msgHash, privKey, opts);
12945
- const C = CURVE;
12946
- const drbg = createHmacDrbg(C.hash.outputLen, C.nByteLength, C.hmac);
12953
+ const drbg = createHmacDrbg(ecdsaOpts.hash.outputLen, Fn.BYTES, hmac_);
12947
12954
  return drbg(seed, k2sig);
12948
12955
  }
12949
- Point2.BASE._setWindowSize(8);
12956
+ Point2.BASE.precompute(8);
12950
12957
  function verify(signature, msgHash, publicKey, opts = defaultVerOpts) {
12951
12958
  const sg = signature;
12952
12959
  msgHash = ensureBytes("msgHash", msgHash);
12953
12960
  publicKey = ensureBytes("publicKey", publicKey);
12954
- const { lowS, prehash, format } = opts;
12955
12961
  validateSigVerOpts(opts);
12962
+ const { lowS, prehash, format } = opts;
12956
12963
  if ("strict" in opts)
12957
12964
  throw new Error("options.strict was renamed to lowS");
12958
- if (format !== void 0 && format !== "compact" && format !== "der")
12959
- throw new Error("format must be compact or der");
12960
- const isHex2 = typeof sg === "string" || isBytes2(sg);
12965
+ if (format !== void 0 && !["compact", "der", "js"].includes(format))
12966
+ throw new Error('format must be "compact", "der" or "js"');
12967
+ const isHex2 = typeof sg === "string" || isBytes(sg);
12961
12968
  const isObj = !isHex2 && !format && typeof sg === "object" && sg !== null && typeof sg.r === "bigint" && typeof sg.s === "bigint";
12962
12969
  if (!isHex2 && !isObj)
12963
12970
  throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
12964
12971
  let _sig = void 0;
12965
12972
  let P;
12966
12973
  try {
12967
- if (isObj)
12968
- _sig = new Signature(sg.r, sg.s);
12974
+ if (isObj) {
12975
+ if (format === void 0 || format === "js") {
12976
+ _sig = new Signature(sg.r, sg.s);
12977
+ } else {
12978
+ throw new Error("invalid format");
12979
+ }
12980
+ }
12969
12981
  if (isHex2) {
12970
12982
  try {
12971
12983
  if (format !== "compact")
@@ -12986,28 +12998,77 @@ function weierstrass(curveDef) {
12986
12998
  if (lowS && _sig.hasHighS())
12987
12999
  return false;
12988
13000
  if (prehash)
12989
- msgHash = CURVE.hash(msgHash);
13001
+ msgHash = ecdsaOpts.hash(msgHash);
12990
13002
  const { r: r2, s: s2 } = _sig;
12991
13003
  const h2 = bits2int_modN(msgHash);
12992
- const is = invN(s2);
12993
- const u1 = modN2(h2 * is);
12994
- const u2 = modN2(r2 * is);
12995
- const R = Point2.BASE.multiplyAndAddUnsafe(P, u1, u2)?.toAffine();
12996
- if (!R)
13004
+ const is = Fn.inv(s2);
13005
+ const u1 = Fn.create(h2 * is);
13006
+ const u2 = Fn.create(r2 * is);
13007
+ const R = Point2.BASE.multiplyUnsafe(u1).add(P.multiplyUnsafe(u2));
13008
+ if (R.is0())
12997
13009
  return false;
12998
- const v = modN2(R.x);
13010
+ const v = Fn.create(R.x);
12999
13011
  return v === r2;
13000
13012
  }
13001
- return {
13002
- CURVE,
13013
+ return Object.freeze({
13003
13014
  getPublicKey,
13004
13015
  getSharedSecret,
13005
13016
  sign: sign2,
13006
13017
  verify,
13007
- ProjectivePoint: Point2,
13008
- Signature,
13009
- utils
13018
+ utils,
13019
+ Point: Point2,
13020
+ Signature
13021
+ });
13022
+ }
13023
+ function _weierstrass_legacy_opts_to_new(c) {
13024
+ const CURVE = {
13025
+ a: c.a,
13026
+ b: c.b,
13027
+ p: c.Fp.ORDER,
13028
+ n: c.n,
13029
+ h: c.h,
13030
+ Gx: c.Gx,
13031
+ Gy: c.Gy
13032
+ };
13033
+ const Fp = c.Fp;
13034
+ const Fn = Field(CURVE.n, c.nBitLength);
13035
+ const curveOpts = {
13036
+ Fp,
13037
+ Fn,
13038
+ allowedPrivateKeyLengths: c.allowedPrivateKeyLengths,
13039
+ allowInfinityPoint: c.allowInfinityPoint,
13040
+ endo: c.endo,
13041
+ wrapPrivateKey: c.wrapPrivateKey,
13042
+ isTorsionFree: c.isTorsionFree,
13043
+ clearCofactor: c.clearCofactor,
13044
+ fromBytes: c.fromBytes,
13045
+ toBytes: c.toBytes
13010
13046
  };
13047
+ return { CURVE, curveOpts };
13048
+ }
13049
+ function _ecdsa_legacy_opts_to_new(c) {
13050
+ const { CURVE, curveOpts } = _weierstrass_legacy_opts_to_new(c);
13051
+ const ecdsaOpts = {
13052
+ hash: c.hash,
13053
+ hmac: c.hmac,
13054
+ randomBytes: c.randomBytes,
13055
+ lowS: c.lowS,
13056
+ bits2int: c.bits2int,
13057
+ bits2int_modN: c.bits2int_modN
13058
+ };
13059
+ return { CURVE, curveOpts, ecdsaOpts };
13060
+ }
13061
+ function _ecdsa_new_output_to_legacy(c, ecdsa2) {
13062
+ return Object.assign({}, ecdsa2, {
13063
+ ProjectivePoint: ecdsa2.Point,
13064
+ CURVE: c
13065
+ });
13066
+ }
13067
+ function weierstrass(c) {
13068
+ const { CURVE, curveOpts, ecdsaOpts } = _ecdsa_legacy_opts_to_new(c);
13069
+ const Point2 = weierstrassN(CURVE, curveOpts);
13070
+ const signs = ecdsa(Point2, ecdsaOpts, curveOpts);
13071
+ return _ecdsa_new_output_to_legacy(c, signs);
13011
13072
  }
13012
13073
  function SWUFpSqrtRatio(Fp, Z2) {
13013
13074
  const q = Fp.ORDER;
@@ -13073,28 +13134,29 @@ function SWUFpSqrtRatio(Fp, Z2) {
13073
13134
  }
13074
13135
  function mapToCurveSimpleSWU(Fp, opts) {
13075
13136
  validateField(Fp);
13076
- if (!Fp.isValid(opts.A) || !Fp.isValid(opts.B) || !Fp.isValid(opts.Z))
13137
+ const { A: A2, B, Z: Z2 } = opts;
13138
+ if (!Fp.isValid(A2) || !Fp.isValid(B) || !Fp.isValid(Z2))
13077
13139
  throw new Error("mapToCurveSimpleSWU: invalid opts");
13078
- const sqrtRatio = SWUFpSqrtRatio(Fp, opts.Z);
13140
+ const sqrtRatio = SWUFpSqrtRatio(Fp, Z2);
13079
13141
  if (!Fp.isOdd)
13080
- throw new Error("Fp.isOdd is not implemented!");
13142
+ throw new Error("Field does not have .isOdd()");
13081
13143
  return (u) => {
13082
13144
  let tv1, tv2, tv3, tv4, tv5, tv6, x2, y;
13083
13145
  tv1 = Fp.sqr(u);
13084
- tv1 = Fp.mul(tv1, opts.Z);
13146
+ tv1 = Fp.mul(tv1, Z2);
13085
13147
  tv2 = Fp.sqr(tv1);
13086
13148
  tv2 = Fp.add(tv2, tv1);
13087
13149
  tv3 = Fp.add(tv2, Fp.ONE);
13088
- tv3 = Fp.mul(tv3, opts.B);
13089
- tv4 = Fp.cmov(opts.Z, Fp.neg(tv2), !Fp.eql(tv2, Fp.ZERO));
13090
- tv4 = Fp.mul(tv4, opts.A);
13150
+ tv3 = Fp.mul(tv3, B);
13151
+ tv4 = Fp.cmov(Z2, Fp.neg(tv2), !Fp.eql(tv2, Fp.ZERO));
13152
+ tv4 = Fp.mul(tv4, A2);
13091
13153
  tv2 = Fp.sqr(tv3);
13092
13154
  tv6 = Fp.sqr(tv4);
13093
- tv5 = Fp.mul(tv6, opts.A);
13155
+ tv5 = Fp.mul(tv6, A2);
13094
13156
  tv2 = Fp.add(tv2, tv5);
13095
13157
  tv2 = Fp.mul(tv2, tv3);
13096
13158
  tv6 = Fp.mul(tv6, tv4);
13097
- tv5 = Fp.mul(tv6, opts.B);
13159
+ tv5 = Fp.mul(tv6, B);
13098
13160
  tv2 = Fp.add(tv2, tv5);
13099
13161
  x2 = Fp.mul(tv1, tv3);
13100
13162
  const { isValid, value } = sqrtRatio(tv2, tv6);
@@ -13113,9 +13175,10 @@ var DERErr, DER, _0n5, _1n5, _2n3, _3n2, _4n2;
13113
13175
  var init_weierstrass = __esm({
13114
13176
  "node_modules/viem/node_modules/@noble/curves/esm/abstract/weierstrass.js"() {
13115
13177
  "use strict";
13178
+ init_hmac();
13179
+ init_utils4();
13116
13180
  init_curve();
13117
13181
  init_modular();
13118
- init_utils4();
13119
13182
  DERErr = class extends Error {
13120
13183
  constructor(m2 = "") {
13121
13184
  super(m2);
@@ -13230,22 +13293,13 @@ var init_weierstrass = __esm({
13230
13293
  });
13231
13294
 
13232
13295
  // node_modules/viem/node_modules/@noble/curves/esm/_shortw_utils.js
13233
- function getHash(hash2) {
13234
- return {
13235
- hash: hash2,
13236
- hmac: (key, ...msgs) => hmac(hash2, key, concatBytes(...msgs)),
13237
- randomBytes
13238
- };
13239
- }
13240
13296
  function createCurve(curveDef, defHash) {
13241
- const create = (hash2) => weierstrass({ ...curveDef, ...getHash(hash2) });
13297
+ const create = (hash2) => weierstrass({ ...curveDef, hash: hash2 });
13242
13298
  return { ...create(defHash), create };
13243
13299
  }
13244
13300
  var init_shortw_utils = __esm({
13245
13301
  "node_modules/viem/node_modules/@noble/curves/esm/_shortw_utils.js"() {
13246
13302
  "use strict";
13247
- init_hmac();
13248
- init_utils2();
13249
13303
  init_weierstrass();
13250
13304
  }
13251
13305
  });
@@ -13275,52 +13329,55 @@ function anum(item) {
13275
13329
  throw new Error("number expected");
13276
13330
  }
13277
13331
  function expand_message_xmd(msg, DST, lenInBytes, H) {
13278
- abytes2(msg);
13279
- abytes2(DST);
13332
+ abytes(msg);
13333
+ abytes(DST);
13280
13334
  anum(lenInBytes);
13281
13335
  if (DST.length > 255)
13282
- DST = H(concatBytes3(utf8ToBytes2("H2C-OVERSIZE-DST-"), DST));
13336
+ DST = H(concatBytes(utf8ToBytes("H2C-OVERSIZE-DST-"), DST));
13283
13337
  const { outputLen: b_in_bytes, blockLen: r_in_bytes } = H;
13284
13338
  const ell = Math.ceil(lenInBytes / b_in_bytes);
13285
13339
  if (lenInBytes > 65535 || ell > 255)
13286
13340
  throw new Error("expand_message_xmd: invalid lenInBytes");
13287
- const DST_prime = concatBytes3(DST, i2osp(DST.length, 1));
13341
+ const DST_prime = concatBytes(DST, i2osp(DST.length, 1));
13288
13342
  const Z_pad = i2osp(0, r_in_bytes);
13289
13343
  const l_i_b_str = i2osp(lenInBytes, 2);
13290
13344
  const b = new Array(ell);
13291
- const b_0 = H(concatBytes3(Z_pad, msg, l_i_b_str, i2osp(0, 1), DST_prime));
13292
- b[0] = H(concatBytes3(b_0, i2osp(1, 1), DST_prime));
13345
+ const b_0 = H(concatBytes(Z_pad, msg, l_i_b_str, i2osp(0, 1), DST_prime));
13346
+ b[0] = H(concatBytes(b_0, i2osp(1, 1), DST_prime));
13293
13347
  for (let i2 = 1; i2 <= ell; i2++) {
13294
13348
  const args = [strxor(b_0, b[i2 - 1]), i2osp(i2 + 1, 1), DST_prime];
13295
- b[i2] = H(concatBytes3(...args));
13349
+ b[i2] = H(concatBytes(...args));
13296
13350
  }
13297
- const pseudo_random_bytes = concatBytes3(...b);
13351
+ const pseudo_random_bytes = concatBytes(...b);
13298
13352
  return pseudo_random_bytes.slice(0, lenInBytes);
13299
13353
  }
13300
13354
  function expand_message_xof(msg, DST, lenInBytes, k, H) {
13301
- abytes2(msg);
13302
- abytes2(DST);
13355
+ abytes(msg);
13356
+ abytes(DST);
13303
13357
  anum(lenInBytes);
13304
13358
  if (DST.length > 255) {
13305
13359
  const dkLen = Math.ceil(2 * k / 8);
13306
- DST = H.create({ dkLen }).update(utf8ToBytes2("H2C-OVERSIZE-DST-")).update(DST).digest();
13360
+ DST = H.create({ dkLen }).update(utf8ToBytes("H2C-OVERSIZE-DST-")).update(DST).digest();
13307
13361
  }
13308
13362
  if (lenInBytes > 65535 || DST.length > 255)
13309
13363
  throw new Error("expand_message_xof: invalid lenInBytes");
13310
13364
  return H.create({ dkLen: lenInBytes }).update(msg).update(i2osp(lenInBytes, 2)).update(DST).update(i2osp(DST.length, 1)).digest();
13311
13365
  }
13312
13366
  function hash_to_field(msg, count, options) {
13313
- validateObject(options, {
13314
- DST: "stringOrUint8Array",
13367
+ _validateObject(options, {
13315
13368
  p: "bigint",
13316
- m: "isSafeInteger",
13317
- k: "isSafeInteger",
13318
- hash: "hash"
13369
+ m: "number",
13370
+ k: "number",
13371
+ hash: "function"
13319
13372
  });
13320
13373
  const { p, k, m: m2, hash: hash2, expand, DST: _DST } = options;
13321
- abytes2(msg);
13374
+ if (!isBytes(_DST) && typeof _DST !== "string")
13375
+ throw new Error("DST must be string or uint8array");
13376
+ if (!isHash(options.hash))
13377
+ throw new Error("expected valid hash");
13378
+ abytes(msg);
13322
13379
  anum(count);
13323
- const DST = typeof _DST === "string" ? utf8ToBytes2(_DST) : _DST;
13380
+ const DST = typeof _DST === "string" ? utf8ToBytes(_DST) : _DST;
13324
13381
  const log2p = p.toString(2).length;
13325
13382
  const L = Math.ceil((log2p + k) / 8);
13326
13383
  const len_in_bytes = count * m2 * L;
@@ -13371,21 +13428,21 @@ function createHasher2(Point2, mapToCurve, defaults) {
13371
13428
  }
13372
13429
  return {
13373
13430
  defaults,
13374
- // Encodes byte string to elliptic curve.
13375
- // hash_to_curve from https://www.rfc-editor.org/rfc/rfc9380#section-3
13376
13431
  hashToCurve(msg, options) {
13377
- const u = hash_to_field(msg, 2, { ...defaults, DST: defaults.DST, ...options });
13432
+ const dst = defaults.DST ? defaults.DST : {};
13433
+ const opts = Object.assign({}, defaults, dst, options);
13434
+ const u = hash_to_field(msg, 2, opts);
13378
13435
  const u0 = map(u[0]);
13379
13436
  const u1 = map(u[1]);
13380
13437
  return clear(u0.add(u1));
13381
13438
  },
13382
- // Encodes byte string to elliptic curve.
13383
- // encode_to_curve from https://www.rfc-editor.org/rfc/rfc9380#section-3
13384
13439
  encodeToCurve(msg, options) {
13385
- const u = hash_to_field(msg, 1, { ...defaults, DST: defaults.encodeDST, ...options });
13440
+ const dst = defaults.encodeDST ? defaults.encodeDST : {};
13441
+ const opts = Object.assign({}, defaults, dst, options);
13442
+ const u = hash_to_field(msg, 1, opts);
13386
13443
  return clear(map(u[0]));
13387
13444
  },
13388
- // Same as encodeToCurve, but without hash
13445
+ /** See {@link H2CHasher} */
13389
13446
  mapToCurve(scalars) {
13390
13447
  if (!Array.isArray(scalars))
13391
13448
  throw new Error("expected array of bigints");
@@ -13400,8 +13457,8 @@ var os2ip;
13400
13457
  var init_hash_to_curve = __esm({
13401
13458
  "node_modules/viem/node_modules/@noble/curves/esm/abstract/hash-to-curve.js"() {
13402
13459
  "use strict";
13403
- init_modular();
13404
13460
  init_utils4();
13461
+ init_modular();
13405
13462
  os2ip = bytesToNumberBE;
13406
13463
  }
13407
13464
  });
@@ -13416,7 +13473,7 @@ __export(secp256k1_exports, {
13416
13473
  secp256k1_hasher: () => secp256k1_hasher
13417
13474
  });
13418
13475
  function sqrtMod(y) {
13419
- const P = secp256k1P;
13476
+ const P = secp256k1_CURVE.p;
13420
13477
  const _3n3 = BigInt(3), _6n = BigInt(6), _11n = BigInt(11), _22n = BigInt(22);
13421
13478
  const _23n = BigInt(23), _44n = BigInt(44), _88n = BigInt(88);
13422
13479
  const b2 = y * y * y % P;
@@ -13441,25 +13498,25 @@ function taggedHash(tag, ...messages) {
13441
13498
  let tagP = TAGGED_HASH_PREFIXES[tag];
13442
13499
  if (tagP === void 0) {
13443
13500
  const tagH = sha256(Uint8Array.from(tag, (c) => c.charCodeAt(0)));
13444
- tagP = concatBytes3(tagH, tagH);
13501
+ tagP = concatBytes(tagH, tagH);
13445
13502
  TAGGED_HASH_PREFIXES[tag] = tagP;
13446
13503
  }
13447
- return sha256(concatBytes3(tagP, ...messages));
13504
+ return sha256(concatBytes(tagP, ...messages));
13448
13505
  }
13449
13506
  function schnorrGetExtPubKey(priv) {
13450
13507
  let d_ = secp256k1.utils.normPrivateKeyToScalar(priv);
13451
13508
  let p = Point.fromPrivateKey(d_);
13452
- const scalar = p.hasEvenY() ? d_ : modN(-d_);
13509
+ const scalar = hasEven(p.y) ? d_ : modN(-d_);
13453
13510
  return { scalar, bytes: pointToBytes(p) };
13454
13511
  }
13455
13512
  function lift_x(x2) {
13456
- aInRange("x", x2, _1n6, secp256k1P);
13513
+ aInRange("x", x2, _1n6, secp256k1_CURVE.p);
13457
13514
  const xx = modP(x2 * x2);
13458
13515
  const c = modP(xx * x2 + BigInt(7));
13459
13516
  let y = sqrtMod(c);
13460
- if (y % _2n4 !== _0n6)
13517
+ if (!hasEven(y))
13461
13518
  y = modP(-y);
13462
- const p = new Point(x2, y, _1n6);
13519
+ const p = Point.fromAffine({ x: x2, y });
13463
13520
  p.assertValidity();
13464
13521
  return p;
13465
13522
  }
@@ -13494,21 +13551,22 @@ function schnorrVerify(signature, message, publicKey) {
13494
13551
  try {
13495
13552
  const P = lift_x(num(pub));
13496
13553
  const r2 = num(sig.subarray(0, 32));
13497
- if (!inRange(r2, _1n6, secp256k1P))
13554
+ if (!inRange(r2, _1n6, secp256k1_CURVE.p))
13498
13555
  return false;
13499
13556
  const s2 = num(sig.subarray(32, 64));
13500
- if (!inRange(s2, _1n6, secp256k1N))
13557
+ if (!inRange(s2, _1n6, secp256k1_CURVE.n))
13501
13558
  return false;
13502
13559
  const e2 = challenge(numTo32b(r2), pointToBytes(P), m2);
13503
- const R = GmulAdd(P, s2, modN(-e2));
13504
- if (!R || !R.hasEvenY() || R.toAffine().x !== r2)
13560
+ const R = Point.BASE.multiplyUnsafe(s2).add(P.multiplyUnsafe(modN(-e2)));
13561
+ const { x: x2, y } = R.toAffine();
13562
+ if (R.is0() || !hasEven(y) || x2 !== r2)
13505
13563
  return false;
13506
13564
  return true;
13507
13565
  } catch (error) {
13508
13566
  return false;
13509
13567
  }
13510
13568
  }
13511
- var secp256k1P, secp256k1N, _0n6, _1n6, _2n4, divNearest, Fpk1, secp256k1, TAGGED_HASH_PREFIXES, pointToBytes, numTo32b, modP, modN, Point, GmulAdd, num, schnorr, isoMap, mapSWU, secp256k1_hasher, hashToCurve, encodeToCurve;
13569
+ var secp256k1_CURVE, _0n6, _1n6, _2n4, divNearest, Fpk1, secp256k1, TAGGED_HASH_PREFIXES, pointToBytes, numTo32b, modP, modN, Point, hasEven, num, schnorr, isoMap, mapSWU, secp256k1_hasher, hashToCurve, encodeToCurve;
13512
13570
  var init_secp256k1 = __esm({
13513
13571
  "node_modules/viem/node_modules/@noble/curves/esm/secp256k1.js"() {
13514
13572
  "use strict";
@@ -13517,30 +13575,32 @@ var init_secp256k1 = __esm({
13517
13575
  init_shortw_utils();
13518
13576
  init_hash_to_curve();
13519
13577
  init_modular();
13520
- init_utils4();
13521
13578
  init_weierstrass();
13522
- secp256k1P = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f");
13523
- secp256k1N = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
13579
+ init_utils4();
13580
+ secp256k1_CURVE = {
13581
+ p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
13582
+ n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
13583
+ h: BigInt(1),
13584
+ a: BigInt(0),
13585
+ b: BigInt(7),
13586
+ Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
13587
+ Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
13588
+ };
13524
13589
  _0n6 = BigInt(0);
13525
13590
  _1n6 = BigInt(1);
13526
13591
  _2n4 = BigInt(2);
13527
13592
  divNearest = (a, b) => (a + b / _2n4) / b;
13528
- Fpk1 = Field(secp256k1P, void 0, void 0, { sqrt: sqrtMod });
13593
+ Fpk1 = Field(secp256k1_CURVE.p, void 0, void 0, { sqrt: sqrtMod });
13529
13594
  secp256k1 = createCurve({
13530
- a: _0n6,
13531
- b: BigInt(7),
13595
+ ...secp256k1_CURVE,
13532
13596
  Fp: Fpk1,
13533
- n: secp256k1N,
13534
- Gx: BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
13535
- Gy: BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),
13536
- h: BigInt(1),
13537
13597
  lowS: true,
13538
13598
  // Allow only low-S signatures by default in sign() and verify()
13539
13599
  endo: {
13540
13600
  // Endomorphism, see above
13541
13601
  beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
13542
13602
  splitScalar: (k) => {
13543
- const n = secp256k1N;
13603
+ const n = secp256k1_CURVE.n;
13544
13604
  const a1 = BigInt("0x3086d221a7d46bcde86c90e49284eb15");
13545
13605
  const b1 = -_1n6 * BigInt("0xe4437ed6010e88286f547fa90abfe4c3");
13546
13606
  const a2 = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8");
@@ -13564,12 +13624,12 @@ var init_secp256k1 = __esm({
13564
13624
  }
13565
13625
  }, sha256);
13566
13626
  TAGGED_HASH_PREFIXES = {};
13567
- pointToBytes = (point) => point.toRawBytes(true).slice(1);
13627
+ pointToBytes = (point) => point.toBytes(true).slice(1);
13568
13628
  numTo32b = (n) => numberToBytesBE(n, 32);
13569
- modP = (x2) => mod(x2, secp256k1P);
13570
- modN = (x2) => mod(x2, secp256k1N);
13571
- Point = /* @__PURE__ */ (() => secp256k1.ProjectivePoint)();
13572
- GmulAdd = (Q, a, b) => Point.BASE.multiplyAndAddUnsafe(Q, a, b);
13629
+ modP = (x2) => mod(x2, secp256k1_CURVE.p);
13630
+ modN = (x2) => mod(x2, secp256k1_CURVE.n);
13631
+ Point = /* @__PURE__ */ (() => secp256k1.Point)();
13632
+ hasEven = (y) => y % _2n4 === _0n6;
13573
13633
  num = bytesToNumberBE;
13574
13634
  schnorr = /* @__PURE__ */ (() => ({
13575
13635
  getPublicKey: schnorrGetPublicKey,
@@ -13621,7 +13681,7 @@ var init_secp256k1 = __esm({
13621
13681
  B: BigInt("1771"),
13622
13682
  Z: Fpk1.create(BigInt("-11"))
13623
13683
  }))();
13624
- secp256k1_hasher = /* @__PURE__ */ (() => createHasher2(secp256k1.ProjectivePoint, (scalars) => {
13684
+ secp256k1_hasher = /* @__PURE__ */ (() => createHasher2(secp256k1.Point, (scalars) => {
13625
13685
  const { x: x2, y } = mapSWU(Fpk1.create(scalars[0]));
13626
13686
  return isoMap(x2, y);
13627
13687
  }, {
@@ -14212,6 +14272,80 @@ var init_decodeFunctionResult = __esm({
14212
14272
  }
14213
14273
  });
14214
14274
 
14275
+ // node_modules/ox/node_modules/@noble/hashes/esm/utils.js
14276
+ function isBytes2(a) {
14277
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
14278
+ }
14279
+ function anumber2(n) {
14280
+ if (!Number.isSafeInteger(n) || n < 0)
14281
+ throw new Error("positive integer expected, got " + n);
14282
+ }
14283
+ function abytes2(b, ...lengths) {
14284
+ if (!isBytes2(b))
14285
+ throw new Error("Uint8Array expected");
14286
+ if (lengths.length > 0 && !lengths.includes(b.length))
14287
+ throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
14288
+ }
14289
+ function aexists2(instance, checkFinished = true) {
14290
+ if (instance.destroyed)
14291
+ throw new Error("Hash instance has been destroyed");
14292
+ if (checkFinished && instance.finished)
14293
+ throw new Error("Hash#digest() has already been called");
14294
+ }
14295
+ function aoutput2(out, instance) {
14296
+ abytes2(out);
14297
+ const min = instance.outputLen;
14298
+ if (out.length < min) {
14299
+ throw new Error("digestInto() expects output buffer of length at least " + min);
14300
+ }
14301
+ }
14302
+ function u322(arr) {
14303
+ return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
14304
+ }
14305
+ function clean2(...arrays) {
14306
+ for (let i2 = 0; i2 < arrays.length; i2++) {
14307
+ arrays[i2].fill(0);
14308
+ }
14309
+ }
14310
+ function byteSwap2(word) {
14311
+ return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
14312
+ }
14313
+ function byteSwap322(arr) {
14314
+ for (let i2 = 0; i2 < arr.length; i2++) {
14315
+ arr[i2] = byteSwap2(arr[i2]);
14316
+ }
14317
+ return arr;
14318
+ }
14319
+ function utf8ToBytes2(str) {
14320
+ if (typeof str !== "string")
14321
+ throw new Error("string expected");
14322
+ return new Uint8Array(new TextEncoder().encode(str));
14323
+ }
14324
+ function toBytes3(data) {
14325
+ if (typeof data === "string")
14326
+ data = utf8ToBytes2(data);
14327
+ abytes2(data);
14328
+ return data;
14329
+ }
14330
+ function createHasher3(hashCons) {
14331
+ const hashC = (msg) => hashCons().update(toBytes3(msg)).digest();
14332
+ const tmp = hashCons();
14333
+ hashC.outputLen = tmp.outputLen;
14334
+ hashC.blockLen = tmp.blockLen;
14335
+ hashC.create = () => hashCons();
14336
+ return hashC;
14337
+ }
14338
+ var isLE2, swap32IfBE2, Hash2;
14339
+ var init_utils5 = __esm({
14340
+ "node_modules/ox/node_modules/@noble/hashes/esm/utils.js"() {
14341
+ "use strict";
14342
+ isLE2 = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
14343
+ swap32IfBE2 = isLE2 ? (u) => u : byteSwap322;
14344
+ Hash2 = class {
14345
+ };
14346
+ }
14347
+ });
14348
+
14215
14349
  // node_modules/ox/_esm/core/version.js
14216
14350
  var version4;
14217
14351
  var init_version3 = __esm({
@@ -15421,7 +15555,7 @@ async function localBatchGatewayRequest(parameters) {
15421
15555
  const responses = [];
15422
15556
  await Promise.all(queries.map(async (query, i2) => {
15423
15557
  try {
15424
- responses[i2] = await ccipRequest2(query);
15558
+ responses[i2] = query.urls.includes(localBatchGatewayUrl) ? await localBatchGatewayRequest({ data: query.data, ccipRequest: ccipRequest2 }) : await ccipRequest2(query);
15425
15559
  failures[i2] = false;
15426
15560
  } catch (err) {
15427
15561
  failures[i2] = true;
@@ -15597,7 +15731,7 @@ var init_ccip2 = __esm({
15597
15731
 
15598
15732
  // node_modules/viem/_esm/actions/public/call.js
15599
15733
  async function call(client, args) {
15600
- const { account: account_ = client.account, authorizationList, batch = Boolean(client.batch?.multicall), blockNumber, blockTag = "pending", accessList, blobs, blockOverrides, code, data: data_, factory, factoryData, gas, gasPrice, maxFeePerBlobGas, maxFeePerGas, maxPriorityFeePerGas, nonce, to, value, stateOverride, ...rest } = args;
15734
+ const { account: account_ = client.account, authorizationList, batch = Boolean(client.batch?.multicall), blockNumber, blockTag = "latest", accessList, blobs, blockOverrides, code, data: data_, factory, factoryData, gas, gasPrice, maxFeePerBlobGas, maxFeePerGas, maxPriorityFeePerGas, nonce, to, value, stateOverride, ...rest } = args;
15601
15735
  const account = account_ ? parseAccount(account_) : void 0;
15602
15736
  if (code && (factory || factoryData))
15603
15737
  throw new BaseError2("Cannot provide both `code` & `factory`/`factoryData` as parameters.");
@@ -15706,7 +15840,7 @@ function shouldPerformMulticall({ request }) {
15706
15840
  }
15707
15841
  async function scheduleMulticall(client, args) {
15708
15842
  const { batchSize = 1024, wait: wait2 = 0 } = typeof client.batch?.multicall === "object" ? client.batch.multicall : {};
15709
- const { blockNumber, blockTag = "pending", data, multicallAddress: multicallAddress_, to } = args;
15843
+ const { blockNumber, blockTag = "latest", data, multicallAddress: multicallAddress_, to } = args;
15710
15844
  let multicallAddress = multicallAddress_;
15711
15845
  if (!multicallAddress) {
15712
15846
  if (!client.chain)
@@ -15896,8 +16030,8 @@ var require_re = __commonJS({
15896
16030
  createToken("NONNUMERICIDENTIFIER", `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`);
15897
16031
  createToken("MAINVERSION", `(${src[t2.NUMERICIDENTIFIER]})\\.(${src[t2.NUMERICIDENTIFIER]})\\.(${src[t2.NUMERICIDENTIFIER]})`);
15898
16032
  createToken("MAINVERSIONLOOSE", `(${src[t2.NUMERICIDENTIFIERLOOSE]})\\.(${src[t2.NUMERICIDENTIFIERLOOSE]})\\.(${src[t2.NUMERICIDENTIFIERLOOSE]})`);
15899
- createToken("PRERELEASEIDENTIFIER", `(?:${src[t2.NUMERICIDENTIFIER]}|${src[t2.NONNUMERICIDENTIFIER]})`);
15900
- createToken("PRERELEASEIDENTIFIERLOOSE", `(?:${src[t2.NUMERICIDENTIFIERLOOSE]}|${src[t2.NONNUMERICIDENTIFIER]})`);
16033
+ createToken("PRERELEASEIDENTIFIER", `(?:${src[t2.NONNUMERICIDENTIFIER]}|${src[t2.NUMERICIDENTIFIER]})`);
16034
+ createToken("PRERELEASEIDENTIFIERLOOSE", `(?:${src[t2.NONNUMERICIDENTIFIER]}|${src[t2.NUMERICIDENTIFIERLOOSE]})`);
15901
16035
  createToken("PRERELEASE", `(?:-(${src[t2.PRERELEASEIDENTIFIER]}(?:\\.${src[t2.PRERELEASEIDENTIFIER]})*))`);
15902
16036
  createToken("PRERELEASELOOSE", `(?:-?(${src[t2.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${src[t2.PRERELEASEIDENTIFIERLOOSE]})*))`);
15903
16037
  createToken("BUILDIDENTIFIER", `${LETTERDASHNUMBER}+`);
@@ -15987,7 +16121,7 @@ var require_semver = __commonJS({
15987
16121
  "use strict";
15988
16122
  var debug = require_debug();
15989
16123
  var { MAX_LENGTH, MAX_SAFE_INTEGER } = require_constants();
15990
- var { safeRe: re, safeSrc: src, t: t2 } = require_re();
16124
+ var { safeRe: re, t: t2 } = require_re();
15991
16125
  var parseOptions = require_parse_options();
15992
16126
  var { compareIdentifiers } = require_identifiers();
15993
16127
  var SemVer = class _SemVer {
@@ -16132,8 +16266,7 @@ var require_semver = __commonJS({
16132
16266
  throw new Error("invalid increment argument: identifier is empty");
16133
16267
  }
16134
16268
  if (identifier) {
16135
- const r2 = new RegExp(`^${this.options.loose ? src[t2.PRERELEASELOOSE] : src[t2.PRERELEASE]}$`);
16136
- const match = `-${identifier}`.match(r2);
16269
+ const match = `-${identifier}`.match(this.options.loose ? re[t2.PRERELEASELOOSE] : re[t2.PRERELEASE]);
16137
16270
  if (!match || match[1] !== identifier) {
16138
16271
  throw new Error(`invalid identifier: ${identifier}`);
16139
16272
  }
@@ -17723,7 +17856,7 @@ var require_semver2 = __commonJS({
17723
17856
  import { program } from "commander";
17724
17857
 
17725
17858
  // package.json
17726
- var version = "0.22.0";
17859
+ var version = "0.23.0";
17727
17860
  var package_default = {
17728
17861
  name: "genlayer",
17729
17862
  version,
@@ -17770,7 +17903,7 @@ var package_default = {
17770
17903
  "@types/uuid": "^10.0.0",
17771
17904
  "@typescript-eslint/eslint-plugin": "^8.0.0",
17772
17905
  "@typescript-eslint/parser": "^8.0.0",
17773
- "@vitest/coverage-v8": "^2.1.4",
17906
+ "@vitest/coverage-v8": "^3.0.0",
17774
17907
  "cross-env": "^7.0.3",
17775
17908
  esbuild: ">=0.25.0",
17776
17909
  eslint: "^9.0.0",
@@ -17785,9 +17918,9 @@ var package_default = {
17785
17918
  },
17786
17919
  dependencies: {
17787
17920
  chalk: "^5.4.1",
17788
- commander: "^13.1.0",
17921
+ commander: "^14.0.0",
17789
17922
  dockerode: "^4.0.2",
17790
- dotenv: "^16.4.5",
17923
+ dotenv: "^17.0.0",
17791
17924
  ethers: "^6.13.4",
17792
17925
  "fs-extra": "^11.3.0",
17793
17926
  "genlayer-js": "^0.11.0",
@@ -17798,7 +17931,7 @@ var package_default = {
17798
17931
  "update-check": "^1.5.4",
17799
17932
  uuid: "^11.0.0",
17800
17933
  viem: "^2.21.54",
17801
- vitest: "^2.1.4"
17934
+ vitest: "^3.0.0"
17802
17935
  },
17803
17936
  overrides: {
17804
17937
  vite: {
@@ -21690,7 +21823,7 @@ async function estimateGas(client, args) {
21690
21823
  const { block: block2, request: request2, rpcStateOverride: rpcStateOverride2 } = parameters;
21691
21824
  return client.request({
21692
21825
  method: "eth_estimateGas",
21693
- params: rpcStateOverride2 ? [request2, block2 ?? "pending", rpcStateOverride2] : block2 ? [request2, block2] : [request2]
21826
+ params: rpcStateOverride2 ? [request2, block2 ?? "latest", rpcStateOverride2] : block2 ? [request2, block2] : [request2]
21694
21827
  });
21695
21828
  };
21696
21829
  var estimateGas_rpc = estimateGas_rpc2;
@@ -21819,26 +21952,25 @@ function decodeEventLog(parameters) {
21819
21952
  const [signature, ...argTopics] = topics;
21820
21953
  if (!signature)
21821
21954
  throw new AbiEventSignatureEmptyTopicsError({ docsPath: docsPath3 });
21822
- const abiItem = (() => {
21823
- if (abi2.length === 1)
21824
- return abi2[0];
21825
- return abi2.find((x2) => x2.type === "event" && signature === toEventSelector(formatAbiItem2(x2)));
21826
- })();
21955
+ const abiItem = abi2.find((x2) => x2.type === "event" && signature === toEventSelector(formatAbiItem2(x2)));
21827
21956
  if (!(abiItem && "name" in abiItem) || abiItem.type !== "event")
21828
21957
  throw new AbiEventSignatureNotFoundError(signature, { docsPath: docsPath3 });
21829
21958
  const { name, inputs } = abiItem;
21830
21959
  const isUnnamed = inputs?.some((x2) => !("name" in x2 && x2.name));
21831
- let args = isUnnamed ? [] : {};
21832
- const indexedInputs = inputs.filter((x2) => "indexed" in x2 && x2.indexed);
21960
+ const args = isUnnamed ? [] : {};
21961
+ const indexedInputs = inputs.map((x2, i2) => [x2, i2]).filter(([x2]) => "indexed" in x2 && x2.indexed);
21833
21962
  for (let i2 = 0; i2 < indexedInputs.length; i2++) {
21834
- const param = indexedInputs[i2];
21963
+ const [param, argIndex] = indexedInputs[i2];
21835
21964
  const topic = argTopics[i2];
21836
21965
  if (!topic)
21837
21966
  throw new DecodeLogTopicsMismatch({
21838
21967
  abiItem,
21839
21968
  param
21840
21969
  });
21841
- args[isUnnamed ? i2 : param.name || i2] = decodeTopic({ param, value: topic });
21970
+ args[isUnnamed ? argIndex : param.name || argIndex] = decodeTopic({
21971
+ param,
21972
+ value: topic
21973
+ });
21842
21974
  }
21843
21975
  const nonIndexedInputs = inputs.filter((x2) => !("indexed" in x2 && x2.indexed));
21844
21976
  if (nonIndexedInputs.length > 0) {
@@ -21847,12 +21979,11 @@ function decodeEventLog(parameters) {
21847
21979
  const decodedData = decodeAbiParameters(nonIndexedInputs, data);
21848
21980
  if (decodedData) {
21849
21981
  if (isUnnamed)
21850
- args = [...args, ...decodedData];
21851
- else {
21852
- for (let i2 = 0; i2 < nonIndexedInputs.length; i2++) {
21982
+ for (let i2 = 0; i2 < inputs.length; i2++)
21983
+ args[i2] = args[i2] ?? decodedData.shift();
21984
+ else
21985
+ for (let i2 = 0; i2 < nonIndexedInputs.length; i2++)
21853
21986
  args[nonIndexedInputs[i2].name] = decodedData[i2];
21854
- }
21855
- }
21856
21987
  }
21857
21988
  } catch (err) {
21858
21989
  if (strict) {
@@ -22152,8 +22283,12 @@ function observe(observerId, callbacks, fn) {
22152
22283
  if (!listeners2.some((cb) => cb.id === callbackId))
22153
22284
  return;
22154
22285
  const cleanup2 = cleanupCache.get(observerId);
22155
- if (listeners2.length === 1 && cleanup2)
22156
- cleanup2();
22286
+ if (listeners2.length === 1 && cleanup2) {
22287
+ const p = cleanup2();
22288
+ if (p instanceof Promise)
22289
+ p.catch(() => {
22290
+ });
22291
+ }
22157
22292
  unsubscribe();
22158
22293
  };
22159
22294
  const listeners = getListeners();
@@ -22296,9 +22431,9 @@ function watchContractEvent(client, parameters) {
22296
22431
  return poll_;
22297
22432
  if (typeof fromBlock === "bigint")
22298
22433
  return true;
22299
- if (client.transport.type === "webSocket")
22434
+ if (client.transport.type === "webSocket" || client.transport.type === "ipc")
22300
22435
  return false;
22301
- if (client.transport.type === "fallback" && client.transport.transports[0].config.type === "webSocket")
22436
+ if (client.transport.type === "fallback" && (client.transport.transports[0].config.type === "webSocket" || client.transport.transports[0].config.type === "ipc"))
22302
22437
  return false;
22303
22438
  return true;
22304
22439
  })();
@@ -22401,7 +22536,7 @@ function watchContractEvent(client, parameters) {
22401
22536
  try {
22402
22537
  const transport = (() => {
22403
22538
  if (client.transport.type === "fallback") {
22404
- const transport2 = client.transport.transports.find((transport3) => transport3.config.type === "webSocket");
22539
+ const transport2 = client.transport.transports.find((transport3) => transport3.config.type === "webSocket" || transport3.config.type === "ipc");
22405
22540
  if (!transport2)
22406
22541
  return client.transport;
22407
22542
  return transport2.value;
@@ -22757,10 +22892,6 @@ var fallbackTransactionErrorMagicIdentifier = numberToHex(0, {
22757
22892
  });
22758
22893
  async function sendCalls(client, parameters) {
22759
22894
  const { account: account_ = client.account, capabilities, chain = client.chain, experimental_fallback, experimental_fallbackDelay = 32, forceAtomic = false, id, version: version5 = "2.0.0" } = parameters;
22760
- if (typeof account_ === "undefined")
22761
- throw new AccountNotFoundError({
22762
- docsPath: "/docs/actions/wallet/sendCalls"
22763
- });
22764
22895
  const account = account_ ? parseAccount(account_) : null;
22765
22896
  const calls = parameters.calls.map((call_) => {
22766
22897
  const call2 = call_;
@@ -22770,7 +22901,7 @@ async function sendCalls(client, parameters) {
22770
22901
  args: call2.args
22771
22902
  }) : call2.data;
22772
22903
  return {
22773
- data,
22904
+ data: call2.dataSuffix && data ? concat([data, call2.dataSuffix]) : data,
22774
22905
  to: call2.to,
22775
22906
  value: call2.value ? numberToHex(call2.value) : void 0
22776
22907
  };
@@ -22795,7 +22926,7 @@ async function sendCalls(client, parameters) {
22795
22926
  return response;
22796
22927
  } catch (err) {
22797
22928
  const error = err;
22798
- if (experimental_fallback && (error.name === "MethodNotFoundRpcError" || error.name === "MethodNotSupportedRpcError" || error.details.toLowerCase().includes("does not exist / is not available") || error.details.toLowerCase().includes("missing or invalid. request()") || error.details.toLowerCase().includes("did not match any variant of untagged enum"))) {
22929
+ if (experimental_fallback && (error.name === "MethodNotFoundRpcError" || error.name === "MethodNotSupportedRpcError" || error.name === "UnknownRpcError" || error.details.toLowerCase().includes("does not exist / is not available") || error.details.toLowerCase().includes("missing or invalid. request()") || error.details.toLowerCase().includes("did not match any variant of untagged enum") || error.details.toLowerCase().includes("account upgraded to unsupported contract") || error.details.toLowerCase().includes("eip-7702 not supported") || error.details.toLowerCase().includes("unsupported wc_ method"))) {
22799
22930
  if (capabilities) {
22800
22931
  const hasNonOptionalCapability = Object.values(capabilities).some((capability) => !capability.optional);
22801
22932
  if (hasNonOptionalCapability) {
@@ -22974,8 +23105,11 @@ function uid(length = 11) {
22974
23105
 
22975
23106
  // node_modules/viem/_esm/clients/createClient.js
22976
23107
  function createClient(parameters) {
22977
- const { batch, cacheTime = parameters.pollingInterval ?? 4e3, ccipRead, key = "base", name = "Base Client", pollingInterval = 4e3, type = "base" } = parameters;
22978
- const chain = parameters.chain;
23108
+ const { batch, chain, ccipRead, key = "base", name = "Base Client", type = "base" } = parameters;
23109
+ const blockTime = chain?.blockTime ?? 12e3;
23110
+ const defaultPollingInterval = Math.min(Math.max(Math.floor(blockTime / 2), 500), 4e3);
23111
+ const pollingInterval = parameters.pollingInterval ?? defaultPollingInterval;
23112
+ const cacheTime = parameters.cacheTime ?? pollingInterval;
22979
23113
  const account = parameters.account ? parseAccount(parameters.account) : void 0;
22980
23114
  const { config, request, value } = parameters.transport({
22981
23115
  chain,
@@ -24464,13 +24598,13 @@ function serializeTransactionEIP7702(transaction, signature) {
24464
24598
  return concatHex([
24465
24599
  "0x04",
24466
24600
  toRlp([
24467
- toHex(chainId),
24468
- nonce ? toHex(nonce) : "0x",
24469
- maxPriorityFeePerGas ? toHex(maxPriorityFeePerGas) : "0x",
24470
- maxFeePerGas ? toHex(maxFeePerGas) : "0x",
24471
- gas ? toHex(gas) : "0x",
24601
+ numberToHex(chainId),
24602
+ nonce ? numberToHex(nonce) : "0x",
24603
+ maxPriorityFeePerGas ? numberToHex(maxPriorityFeePerGas) : "0x",
24604
+ maxFeePerGas ? numberToHex(maxFeePerGas) : "0x",
24605
+ gas ? numberToHex(gas) : "0x",
24472
24606
  to ?? "0x",
24473
- value ? toHex(value) : "0x",
24607
+ value ? numberToHex(value) : "0x",
24474
24608
  data ?? "0x",
24475
24609
  serializedAccessList,
24476
24610
  serializedAuthorizationList,
@@ -24501,16 +24635,16 @@ function serializeTransactionEIP4844(transaction, signature) {
24501
24635
  }
24502
24636
  const serializedAccessList = serializeAccessList(accessList);
24503
24637
  const serializedTransaction = [
24504
- toHex(chainId),
24505
- nonce ? toHex(nonce) : "0x",
24506
- maxPriorityFeePerGas ? toHex(maxPriorityFeePerGas) : "0x",
24507
- maxFeePerGas ? toHex(maxFeePerGas) : "0x",
24508
- gas ? toHex(gas) : "0x",
24638
+ numberToHex(chainId),
24639
+ nonce ? numberToHex(nonce) : "0x",
24640
+ maxPriorityFeePerGas ? numberToHex(maxPriorityFeePerGas) : "0x",
24641
+ maxFeePerGas ? numberToHex(maxFeePerGas) : "0x",
24642
+ gas ? numberToHex(gas) : "0x",
24509
24643
  to ?? "0x",
24510
- value ? toHex(value) : "0x",
24644
+ value ? numberToHex(value) : "0x",
24511
24645
  data ?? "0x",
24512
24646
  serializedAccessList,
24513
- maxFeePerBlobGas ? toHex(maxFeePerBlobGas) : "0x",
24647
+ maxFeePerBlobGas ? numberToHex(maxFeePerBlobGas) : "0x",
24514
24648
  blobVersionedHashes ?? [],
24515
24649
  ...toYParitySignatureArray(transaction, signature)
24516
24650
  ];
@@ -24540,13 +24674,13 @@ function serializeTransactionEIP1559(transaction, signature) {
24540
24674
  assertTransactionEIP1559(transaction);
24541
24675
  const serializedAccessList = serializeAccessList(accessList);
24542
24676
  const serializedTransaction = [
24543
- toHex(chainId),
24544
- nonce ? toHex(nonce) : "0x",
24545
- maxPriorityFeePerGas ? toHex(maxPriorityFeePerGas) : "0x",
24546
- maxFeePerGas ? toHex(maxFeePerGas) : "0x",
24547
- gas ? toHex(gas) : "0x",
24677
+ numberToHex(chainId),
24678
+ nonce ? numberToHex(nonce) : "0x",
24679
+ maxPriorityFeePerGas ? numberToHex(maxPriorityFeePerGas) : "0x",
24680
+ maxFeePerGas ? numberToHex(maxFeePerGas) : "0x",
24681
+ gas ? numberToHex(gas) : "0x",
24548
24682
  to ?? "0x",
24549
- value ? toHex(value) : "0x",
24683
+ value ? numberToHex(value) : "0x",
24550
24684
  data ?? "0x",
24551
24685
  serializedAccessList,
24552
24686
  ...toYParitySignatureArray(transaction, signature)
@@ -24561,12 +24695,12 @@ function serializeTransactionEIP2930(transaction, signature) {
24561
24695
  assertTransactionEIP2930(transaction);
24562
24696
  const serializedAccessList = serializeAccessList(accessList);
24563
24697
  const serializedTransaction = [
24564
- toHex(chainId),
24565
- nonce ? toHex(nonce) : "0x",
24566
- gasPrice ? toHex(gasPrice) : "0x",
24567
- gas ? toHex(gas) : "0x",
24698
+ numberToHex(chainId),
24699
+ nonce ? numberToHex(nonce) : "0x",
24700
+ gasPrice ? numberToHex(gasPrice) : "0x",
24701
+ gas ? numberToHex(gas) : "0x",
24568
24702
  to ?? "0x",
24569
- value ? toHex(value) : "0x",
24703
+ value ? numberToHex(value) : "0x",
24570
24704
  data ?? "0x",
24571
24705
  serializedAccessList,
24572
24706
  ...toYParitySignatureArray(transaction, signature)
@@ -24580,11 +24714,11 @@ function serializeTransactionLegacy(transaction, signature) {
24580
24714
  const { chainId = 0, gas, data, nonce, to, value, gasPrice } = transaction;
24581
24715
  assertTransactionLegacy(transaction);
24582
24716
  let serializedTransaction = [
24583
- nonce ? toHex(nonce) : "0x",
24584
- gasPrice ? toHex(gasPrice) : "0x",
24585
- gas ? toHex(gas) : "0x",
24717
+ nonce ? numberToHex(nonce) : "0x",
24718
+ gasPrice ? numberToHex(gasPrice) : "0x",
24719
+ gas ? numberToHex(gas) : "0x",
24586
24720
  to ?? "0x",
24587
- value ? toHex(value) : "0x",
24721
+ value ? numberToHex(value) : "0x",
24588
24722
  data ?? "0x"
24589
24723
  ];
24590
24724
  if (signature) {
@@ -24606,14 +24740,14 @@ function serializeTransactionLegacy(transaction, signature) {
24606
24740
  const s2 = trim(signature.s);
24607
24741
  serializedTransaction = [
24608
24742
  ...serializedTransaction,
24609
- toHex(v),
24743
+ numberToHex(v),
24610
24744
  r2 === "0x00" ? "0x" : r2,
24611
24745
  s2 === "0x00" ? "0x" : s2
24612
24746
  ];
24613
24747
  } else if (chainId > 0) {
24614
24748
  serializedTransaction = [
24615
24749
  ...serializedTransaction,
24616
- toHex(chainId),
24750
+ numberToHex(chainId),
24617
24751
  "0x",
24618
24752
  "0x"
24619
24753
  ];
@@ -24633,12 +24767,12 @@ function toYParitySignatureArray(transaction, signature_) {
24633
24767
  const s2 = trim(signature.s);
24634
24768
  const yParity_ = (() => {
24635
24769
  if (typeof yParity === "number")
24636
- return yParity ? toHex(1) : "0x";
24770
+ return yParity ? numberToHex(1) : "0x";
24637
24771
  if (v === 0n)
24638
24772
  return "0x";
24639
24773
  if (v === 1n)
24640
- return toHex(1);
24641
- return v === 27n ? "0x" : toHex(1);
24774
+ return numberToHex(1);
24775
+ return v === 27n ? "0x" : numberToHex(1);
24642
24776
  })();
24643
24777
  return [yParity_, r2 === "0x00" ? "0x" : r2, s2 === "0x00" ? "0x" : s2];
24644
24778
  }
@@ -25009,13 +25143,14 @@ init_contract();
25009
25143
  init_node();
25010
25144
  init_decodeFunctionResult();
25011
25145
  init_encodeFunctionData();
25146
+ init_concat();
25012
25147
  init_toHex();
25013
25148
  init_getNodeError();
25014
25149
  init_transactionRequest();
25015
25150
  init_stateOverride2();
25016
25151
  init_assertRequest();
25017
25152
  async function simulateBlocks(client, parameters) {
25018
- const { blockNumber, blockTag = "pending", blocks, returnFullTransactions, traceTransfers, validation } = parameters;
25153
+ const { blockNumber, blockTag = "latest", blocks, returnFullTransactions, traceTransfers, validation } = parameters;
25019
25154
  try {
25020
25155
  const blockStateCalls = [];
25021
25156
  for (const block2 of blocks) {
@@ -25023,9 +25158,10 @@ async function simulateBlocks(client, parameters) {
25023
25158
  const calls = block2.calls.map((call_) => {
25024
25159
  const call2 = call_;
25025
25160
  const account = call2.account ? parseAccount(call2.account) : void 0;
25161
+ const data = call2.abi ? encodeFunctionData(call2) : call2.data;
25026
25162
  const request = {
25027
25163
  ...call2,
25028
- data: call2.abi ? encodeFunctionData(call2) : call2.data,
25164
+ data: call2.dataSuffix ? concat([data || "0x", call2.dataSuffix]) : data,
25029
25165
  from: call2.from ?? account?.address
25030
25166
  };
25031
25167
  assertRequest(request);
@@ -25072,7 +25208,7 @@ async function simulateBlocks(client, parameters) {
25072
25208
  return void 0;
25073
25209
  return getContractError(error2, {
25074
25210
  abi: abi2 ?? [],
25075
- address: to,
25211
+ address: to ?? "0x",
25076
25212
  args,
25077
25213
  functionName: functionName ?? "<unknown>"
25078
25214
  });
@@ -25103,74 +25239,6 @@ async function simulateBlocks(client, parameters) {
25103
25239
  init_exports();
25104
25240
  init_Errors();
25105
25241
 
25106
- // node_modules/ox/node_modules/@noble/hashes/esm/utils.js
25107
- function isBytes3(a) {
25108
- return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
25109
- }
25110
- function anumber2(n) {
25111
- if (!Number.isSafeInteger(n) || n < 0)
25112
- throw new Error("positive integer expected, got " + n);
25113
- }
25114
- function abytes3(b, ...lengths) {
25115
- if (!isBytes3(b))
25116
- throw new Error("Uint8Array expected");
25117
- if (lengths.length > 0 && !lengths.includes(b.length))
25118
- throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
25119
- }
25120
- function aexists2(instance, checkFinished = true) {
25121
- if (instance.destroyed)
25122
- throw new Error("Hash instance has been destroyed");
25123
- if (checkFinished && instance.finished)
25124
- throw new Error("Hash#digest() has already been called");
25125
- }
25126
- function aoutput2(out, instance) {
25127
- abytes3(out);
25128
- const min = instance.outputLen;
25129
- if (out.length < min) {
25130
- throw new Error("digestInto() expects output buffer of length at least " + min);
25131
- }
25132
- }
25133
- function u322(arr) {
25134
- return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
25135
- }
25136
- function clean2(...arrays) {
25137
- for (let i2 = 0; i2 < arrays.length; i2++) {
25138
- arrays[i2].fill(0);
25139
- }
25140
- }
25141
- var isLE2 = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
25142
- function byteSwap2(word) {
25143
- return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
25144
- }
25145
- function byteSwap322(arr) {
25146
- for (let i2 = 0; i2 < arr.length; i2++) {
25147
- arr[i2] = byteSwap2(arr[i2]);
25148
- }
25149
- return arr;
25150
- }
25151
- var swap32IfBE2 = isLE2 ? (u) => u : byteSwap322;
25152
- function utf8ToBytes3(str) {
25153
- if (typeof str !== "string")
25154
- throw new Error("string expected");
25155
- return new Uint8Array(new TextEncoder().encode(str));
25156
- }
25157
- function toBytes3(data) {
25158
- if (typeof data === "string")
25159
- data = utf8ToBytes3(data);
25160
- abytes3(data);
25161
- return data;
25162
- }
25163
- var Hash2 = class {
25164
- };
25165
- function createHasher3(hashCons) {
25166
- const hashC = (msg) => hashCons().update(toBytes3(msg)).digest();
25167
- const tmp = hashCons();
25168
- hashC.outputLen = tmp.outputLen;
25169
- hashC.blockLen = tmp.blockLen;
25170
- hashC.create = () => hashCons();
25171
- return hashC;
25172
- }
25173
-
25174
25242
  // node_modules/ox/node_modules/@noble/hashes/esm/_u64.js
25175
25243
  var U32_MASK642 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
25176
25244
  var _32n2 = /* @__PURE__ */ BigInt(32);
@@ -25195,6 +25263,7 @@ var rotlBH2 = (h2, l, s2) => l << s2 - 32 | h2 >>> 64 - s2;
25195
25263
  var rotlBL2 = (h2, l, s2) => h2 << s2 - 32 | l >>> 64 - s2;
25196
25264
 
25197
25265
  // node_modules/ox/node_modules/@noble/hashes/esm/sha3.js
25266
+ init_utils5();
25198
25267
  var _0n7 = BigInt(0);
25199
25268
  var _1n7 = BigInt(1);
25200
25269
  var _2n5 = BigInt(2);
@@ -25294,7 +25363,7 @@ var Keccak2 = class _Keccak extends Hash2 {
25294
25363
  update(data) {
25295
25364
  aexists2(this);
25296
25365
  data = toBytes3(data);
25297
- abytes3(data);
25366
+ abytes2(data);
25298
25367
  const { blockLen, state } = this;
25299
25368
  const len = data.length;
25300
25369
  for (let pos = 0; pos < len; ) {
@@ -25319,7 +25388,7 @@ var Keccak2 = class _Keccak extends Hash2 {
25319
25388
  }
25320
25389
  writeInto(out) {
25321
25390
  aexists2(this, false);
25322
- abytes3(out);
25391
+ abytes2(out);
25323
25392
  this.finish();
25324
25393
  const bufferOut = this.state;
25325
25394
  const { blockLen } = this;
@@ -26285,14 +26354,6 @@ async function simulateCalls(client, parameters) {
26285
26354
  });
26286
26355
  return accessList.map(({ address, storageKeys }) => storageKeys.length > 0 ? address : null);
26287
26356
  })).then((x2) => x2.flat().filter(Boolean)) : [];
26288
- const resultsStateOverrides = stateOverrides?.map((override) => {
26289
- if (override.address === account?.address)
26290
- return {
26291
- ...override,
26292
- nonce: 0
26293
- };
26294
- return override;
26295
- });
26296
26357
  const blocks = await simulateBlocks(client, {
26297
26358
  blockNumber,
26298
26359
  blockTag,
@@ -26324,12 +26385,11 @@ async function simulateCalls(client, parameters) {
26324
26385
  }
26325
26386
  ] : [],
26326
26387
  {
26327
- calls: [...calls, {}].map((call2, index2) => ({
26388
+ calls: [...calls, {}].map((call2) => ({
26328
26389
  ...call2,
26329
- from: account?.address,
26330
- nonce: index2
26390
+ from: account?.address
26331
26391
  })),
26332
- stateOverrides: resultsStateOverrides
26392
+ stateOverrides
26333
26393
  },
26334
26394
  ...traceAssetChanges ? [
26335
26395
  // ETH post balances
@@ -26589,9 +26649,9 @@ function watchBlockNumber(client, { emitOnBegin = false, emitMissed = false, onB
26589
26649
  const enablePolling = (() => {
26590
26650
  if (typeof poll_ !== "undefined")
26591
26651
  return poll_;
26592
- if (client.transport.type === "webSocket")
26652
+ if (client.transport.type === "webSocket" || client.transport.type === "ipc")
26593
26653
  return false;
26594
- if (client.transport.type === "fallback" && client.transport.transports[0].config.type === "webSocket")
26654
+ if (client.transport.type === "fallback" && (client.transport.transports[0].config.type === "webSocket" || client.transport.transports[0].config.type === "ipc"))
26595
26655
  return false;
26596
26656
  return true;
26597
26657
  })();
@@ -26643,7 +26703,7 @@ function watchBlockNumber(client, { emitOnBegin = false, emitMissed = false, onB
26643
26703
  try {
26644
26704
  const transport = (() => {
26645
26705
  if (client.transport.type === "fallback") {
26646
- const transport2 = client.transport.transports.find((transport3) => transport3.config.type === "webSocket");
26706
+ const transport2 = client.transport.transports.find((transport3) => transport3.config.type === "webSocket" || transport3.config.type === "ipc");
26647
26707
  if (!transport2)
26648
26708
  return client.transport;
26649
26709
  return transport2.value;
@@ -26799,9 +26859,9 @@ function watchBlocks(client, { blockTag = "latest", emitMissed = false, emitOnBe
26799
26859
  const enablePolling = (() => {
26800
26860
  if (typeof poll_ !== "undefined")
26801
26861
  return poll_;
26802
- if (client.transport.type === "webSocket")
26862
+ if (client.transport.type === "webSocket" || client.transport.type === "ipc")
26803
26863
  return false;
26804
- if (client.transport.type === "fallback" && client.transport.transports[0].config.type === "webSocket")
26864
+ if (client.transport.type === "fallback" && (client.transport.transports[0].config.type === "webSocket" || client.transport.transports[0].config.type === "ipc"))
26805
26865
  return false;
26806
26866
  return true;
26807
26867
  })();
@@ -26876,7 +26936,7 @@ function watchBlocks(client, { blockTag = "latest", emitMissed = false, emitOnBe
26876
26936
  }
26877
26937
  const transport = (() => {
26878
26938
  if (client.transport.type === "fallback") {
26879
- const transport2 = client.transport.transports.find((transport3) => transport3.config.type === "webSocket");
26939
+ const transport2 = client.transport.transports.find((transport3) => transport3.config.type === "webSocket" || transport3.config.type === "ipc");
26880
26940
  if (!transport2)
26881
26941
  return client.transport;
26882
26942
  return transport2.value;
@@ -26889,7 +26949,7 @@ function watchBlocks(client, { blockTag = "latest", emitMissed = false, emitOnBe
26889
26949
  if (!active)
26890
26950
  return;
26891
26951
  const block = await getAction(client, getBlock, "getBlock")({
26892
- blockNumber: data.blockNumber,
26952
+ blockNumber: data.result?.number,
26893
26953
  includeTransactions
26894
26954
  }).catch(() => {
26895
26955
  });
@@ -26925,9 +26985,9 @@ function watchEvent(client, { address, args, batch = true, event, events, fromBl
26925
26985
  return poll_;
26926
26986
  if (typeof fromBlock === "bigint")
26927
26987
  return true;
26928
- if (client.transport.type === "webSocket")
26988
+ if (client.transport.type === "webSocket" || client.transport.type === "ipc")
26929
26989
  return false;
26930
- if (client.transport.type === "fallback" && client.transport.transports[0].config.type === "webSocket")
26990
+ if (client.transport.type === "fallback" && (client.transport.transports[0].config.type === "webSocket" || client.transport.transports[0].config.type === "ipc"))
26931
26991
  return false;
26932
26992
  return true;
26933
26993
  })();
@@ -27015,7 +27075,7 @@ function watchEvent(client, { address, args, batch = true, event, events, fromBl
27015
27075
  try {
27016
27076
  const transport = (() => {
27017
27077
  if (client.transport.type === "fallback") {
27018
- const transport2 = client.transport.transports.find((transport3) => transport3.config.type === "webSocket");
27078
+ const transport2 = client.transport.transports.find((transport3) => transport3.config.type === "webSocket" || transport3.config.type === "ipc");
27019
27079
  if (!transport2)
27020
27080
  return client.transport;
27021
27081
  return transport2.value;
@@ -27084,7 +27144,7 @@ function watchEvent(client, { address, args, batch = true, event, events, fromBl
27084
27144
  // node_modules/viem/_esm/actions/public/watchPendingTransactions.js
27085
27145
  init_stringify();
27086
27146
  function watchPendingTransactions(client, { batch = true, onError, onTransactions, poll: poll_, pollingInterval = client.pollingInterval }) {
27087
- const enablePolling = typeof poll_ !== "undefined" ? poll_ : client.transport.type !== "webSocket";
27147
+ const enablePolling = typeof poll_ !== "undefined" ? poll_ : client.transport.type !== "webSocket" && client.transport.type !== "ipc";
27088
27148
  const pollPendingTransactions = () => {
27089
27149
  const observerId = stringify([
27090
27150
  "watchPendingTransactions",
@@ -27595,7 +27655,7 @@ init_encodeFunctionData();
27595
27655
  init_toHex();
27596
27656
  init_fromHex();
27597
27657
 
27598
- // node_modules/genlayer-js/dist/chunk-565IJBV4.js
27658
+ // node_modules/genlayer-js/dist/chunk-GEN4SJ6K.js
27599
27659
  var chains_exports = {};
27600
27660
  __export2(chains_exports, {
27601
27661
  localnet: () => localnet,
@@ -35622,7 +35682,7 @@ var studionet = defineChain({
35622
35682
  var TESTNET_JSON_RPC_URL = " http://34.32.169.58:9151";
35623
35683
  var EXPLORER_URL2 = "https://explorer-asimov.genlayer.com/";
35624
35684
  var CONSENSUS_MAIN_CONTRACT3 = {
35625
- address: "0x174782d5819dD26F3d6967c995EE43db7DB824F8",
35685
+ address: "0xe30293d600fF9B2C865d91307826F28006A458f4",
35626
35686
  abi: [
35627
35687
  {
35628
35688
  inputs: [],
@@ -36086,25 +36146,6 @@ var CONSENSUS_MAIN_CONTRACT3 = {
36086
36146
  name: "TransactionActivated",
36087
36147
  type: "event"
36088
36148
  },
36089
- {
36090
- anonymous: false,
36091
- inputs: [
36092
- {
36093
- indexed: true,
36094
- internalType: "uint256",
36095
- name: "batchId",
36096
- type: "uint256"
36097
- },
36098
- {
36099
- indexed: false,
36100
- internalType: "address[]",
36101
- name: "validators",
36102
- type: "address[]"
36103
- }
36104
- ],
36105
- name: "TransactionActivatedValidators",
36106
- type: "event"
36107
- },
36108
36149
  {
36109
36150
  anonymous: false,
36110
36151
  inputs: [
@@ -36383,19 +36424,6 @@ var CONSENSUS_MAIN_CONTRACT3 = {
36383
36424
  stateMutability: "view",
36384
36425
  type: "function"
36385
36426
  },
36386
- {
36387
- inputs: [],
36388
- name: "EVENTS_BATCH_SIZE",
36389
- outputs: [
36390
- {
36391
- internalType: "uint256",
36392
- name: "",
36393
- type: "uint256"
36394
- }
36395
- ],
36396
- stateMutability: "view",
36397
- type: "function"
36398
- },
36399
36427
  {
36400
36428
  inputs: [],
36401
36429
  name: "acceptOwnership",
@@ -36496,11 +36524,6 @@ var CONSENSUS_MAIN_CONTRACT3 = {
36496
36524
  internalType: "bytes32",
36497
36525
  name: "_commitHash",
36498
36526
  type: "bytes32"
36499
- },
36500
- {
36501
- internalType: "uint256",
36502
- name: "_validatorIndex",
36503
- type: "uint256"
36504
36527
  }
36505
36528
  ],
36506
36529
  name: "commitVote",
@@ -36913,11 +36936,6 @@ var CONSENSUS_MAIN_CONTRACT3 = {
36913
36936
  internalType: "uint256",
36914
36937
  name: "_nonce",
36915
36938
  type: "uint256"
36916
- },
36917
- {
36918
- internalType: "uint256",
36919
- name: "_validatorIndex",
36920
- type: "uint256"
36921
36939
  }
36922
36940
  ],
36923
36941
  name: "revealVote",
@@ -37053,7 +37071,7 @@ var CONSENSUS_MAIN_CONTRACT3 = {
37053
37071
  bytecode: ""
37054
37072
  };
37055
37073
  var CONSENSUS_DATA_CONTRACT3 = {
37056
- address: "0x88B0F18613Db92Bf970FfE264E02496e20a74D16",
37074
+ address: "0x2a50afD9d3E0ACC824aC4850d7B4c5561aB5D27a",
37057
37075
  abi: [
37058
37076
  {
37059
37077
  inputs: [],
@@ -38601,6 +38619,16 @@ var CONSENSUS_DATA_CONTRACT3 = {
38601
38619
  internalType: "address",
38602
38620
  name: "ghostAddress",
38603
38621
  type: "address"
38622
+ },
38623
+ {
38624
+ internalType: "uint256",
38625
+ name: "numOfMessagesIssuedOnAcceptance",
38626
+ type: "uint256"
38627
+ },
38628
+ {
38629
+ internalType: "uint256",
38630
+ name: "numOfMessagesIssuedOnFinalization",
38631
+ type: "uint256"
38604
38632
  }
38605
38633
  ],
38606
38634
  stateMutability: "view",
@@ -39008,6 +39036,26 @@ var CONSENSUS_DATA_CONTRACT3 = {
39008
39036
  internalType: "struct ITransactions.RoundData[]",
39009
39037
  name: "roundData",
39010
39038
  type: "tuple[]"
39039
+ },
39040
+ {
39041
+ internalType: "uint256",
39042
+ name: "numOfMessagesIssuedOnAcceptance",
39043
+ type: "uint256"
39044
+ },
39045
+ {
39046
+ internalType: "uint256",
39047
+ name: "numOfMessagesIssuedOnFinalization",
39048
+ type: "uint256"
39049
+ },
39050
+ {
39051
+ internalType: "address",
39052
+ name: "txOrigin",
39053
+ type: "address"
39054
+ },
39055
+ {
39056
+ internalType: "uint256",
39057
+ name: "initialRotations",
39058
+ type: "uint256"
39011
39059
  }
39012
39060
  ],
39013
39061
  internalType: "struct ITransactions.Transaction",
@@ -41163,7 +41211,7 @@ import updateCheck from "update-check";
41163
41211
  import { fileURLToPath as fileURLToPath2 } from "url";
41164
41212
 
41165
41213
  // src/lib/clients/system.ts
41166
- import util from "node:util";
41214
+ import util2 from "node:util";
41167
41215
  import { exec } from "child_process";
41168
41216
 
41169
41217
  // node_modules/open/index.js
@@ -41171,6 +41219,7 @@ import process14 from "node:process";
41171
41219
  import { Buffer as Buffer4 } from "node:buffer";
41172
41220
  import path2 from "node:path";
41173
41221
  import { fileURLToPath } from "node:url";
41222
+ import util from "node:util";
41174
41223
  import childProcess from "node:child_process";
41175
41224
  import fs6, { constants as fsConstants } from "node:fs/promises";
41176
41225
 
@@ -41360,6 +41409,7 @@ async function defaultBrowser2() {
41360
41409
  }
41361
41410
 
41362
41411
  // node_modules/open/index.js
41412
+ var execFile5 = util.promisify(childProcess.execFile);
41363
41413
  var __dirname = path2.dirname(fileURLToPath(import.meta.url));
41364
41414
  var localXdgOpenPath = path2.join(__dirname, "xdg-open");
41365
41415
  var { platform, arch } = process14;
@@ -41390,6 +41440,34 @@ var getWslDrivesMountPoint = /* @__PURE__ */ (() => {
41390
41440
  return mountPoint;
41391
41441
  };
41392
41442
  })();
41443
+ var getPowershellPathFromWsl = async () => {
41444
+ const mountPoint = await getWslDrivesMountPoint();
41445
+ return `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`;
41446
+ };
41447
+ async function getWindowsDefaultBrowserFromWsl() {
41448
+ const powershellPath = await getPowershellPathFromWsl();
41449
+ const rawCommand = '(Get-ItemProperty -Path "HKCU:\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice").ProgId';
41450
+ const encodedCommand = Buffer4.from(rawCommand, "utf16le").toString("base64");
41451
+ const { stdout } = await execFile5(
41452
+ powershellPath,
41453
+ [
41454
+ "-NoProfile",
41455
+ "-NonInteractive",
41456
+ "-ExecutionPolicy",
41457
+ "Bypass",
41458
+ "-EncodedCommand",
41459
+ encodedCommand
41460
+ ],
41461
+ { encoding: "utf8" }
41462
+ );
41463
+ const progId = stdout.trim();
41464
+ const browserMap = {
41465
+ ChromeHTML: "com.google.chrome",
41466
+ MSEdgeHTM: "com.microsoft.edge",
41467
+ FirefoxURL: "org.mozilla.firefox"
41468
+ };
41469
+ return browserMap[progId] ? { id: browserMap[progId] } : {};
41470
+ }
41393
41471
  var pTryEach = async (array, mapper) => {
41394
41472
  let latestError;
41395
41473
  for (const item of array) {
@@ -41442,7 +41520,7 @@ var baseOpen = async (options) => {
41442
41520
  firefox: "--private-window",
41443
41521
  edge: "--inPrivate"
41444
41522
  };
41445
- const browser = await defaultBrowser2();
41523
+ const browser = is_wsl_default ? await getWindowsDefaultBrowserFromWsl() : await defaultBrowser2();
41446
41524
  if (browser.id in ids) {
41447
41525
  const browserName = ids[browser.id];
41448
41526
  if (app === "browserPrivate") {
@@ -41476,8 +41554,7 @@ var baseOpen = async (options) => {
41476
41554
  cliArguments.push("-a", app);
41477
41555
  }
41478
41556
  } else if (platform === "win32" || is_wsl_default && !isInsideContainer() && !app) {
41479
- const mountPoint = await getWslDrivesMountPoint();
41480
- command = is_wsl_default ? `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe` : `${process14.env.SYSTEMROOT || process14.env.windir || "C:\\Windows"}\\System32\\WindowsPowerShell\\v1.0\\powershell`;
41557
+ command = is_wsl_default ? await getPowershellPathFromWsl() : `${process14.env.SYSTEMROOT || process14.env.windir || "C:\\Windows"}\\System32\\WindowsPowerShell\\v1.0\\powershell`;
41481
41558
  cliArguments.push(
41482
41559
  "-NoProfile",
41483
41560
  "-NonInteractive",
@@ -41619,7 +41696,7 @@ var MissingRequirementError = class extends Error {
41619
41696
  // src/lib/clients/system.ts
41620
41697
  async function checkCommand(command, toolName) {
41621
41698
  try {
41622
- await util.promisify(exec)(command);
41699
+ await util2.promisify(exec)(command);
41623
41700
  } catch (error) {
41624
41701
  if (error.stderr) {
41625
41702
  throw new MissingRequirementError(toolName);
@@ -41630,7 +41707,7 @@ async function executeCommand(cmdsByPlatform, toolName) {
41630
41707
  const runningPlatform = getPlatform();
41631
41708
  const command = cmdsByPlatform[runningPlatform];
41632
41709
  try {
41633
- return await util.promisify(exec)(command);
41710
+ return await util2.promisify(exec)(command);
41634
41711
  } catch (error) {
41635
41712
  throw new Error(`Error executing ${toolName || command}: ${error.message}.`);
41636
41713
  }
@@ -41647,7 +41724,7 @@ function openUrl(url) {
41647
41724
  }
41648
41725
  async function getVersion2(toolName) {
41649
41726
  try {
41650
- const toolResponse = await util.promisify(exec)(`${toolName} --version`);
41727
+ const toolResponse = await util2.promisify(exec)(`${toolName} --version`);
41651
41728
  if (toolResponse.stderr) {
41652
41729
  throw new Error(toolResponse.stderr);
41653
41730
  }
@@ -42832,6 +42909,51 @@ function initializeNetworkCommands(program2) {
42832
42909
  return program2;
42833
42910
  }
42834
42911
 
42912
+ // src/commands/transactions/receipt.ts
42913
+ var ReceiptAction = class extends BaseAction {
42914
+ constructor() {
42915
+ super();
42916
+ }
42917
+ validateTransactionStatus(status) {
42918
+ const upperStatus = status.toUpperCase();
42919
+ if (!(upperStatus in TransactionStatus)) {
42920
+ const validStatuses = Object.values(TransactionStatus);
42921
+ this.failSpinner(
42922
+ "Invalid transaction status",
42923
+ `Invalid status: ${status}. Valid values are: ${validStatuses.join(", ")}`
42924
+ );
42925
+ return;
42926
+ }
42927
+ return TransactionStatus[upperStatus];
42928
+ }
42929
+ async receipt({
42930
+ txId,
42931
+ status = TransactionStatus.FINALIZED,
42932
+ retries,
42933
+ interval,
42934
+ rpc
42935
+ }) {
42936
+ const client = await this.getClient(rpc);
42937
+ await client.initializeConsensusSmartContract();
42938
+ this.startSpinner(`Waiting for transaction receipt ${txId} (status: ${status})...`);
42939
+ try {
42940
+ let validatedStatus = this.validateTransactionStatus(status);
42941
+ if (!validatedStatus) {
42942
+ return;
42943
+ }
42944
+ const result = await client.waitForTransactionReceipt({
42945
+ hash: txId,
42946
+ status: validatedStatus,
42947
+ retries,
42948
+ interval
42949
+ });
42950
+ this.succeedSpinner("Transaction receipt retrieved successfully", result);
42951
+ } catch (error) {
42952
+ this.failSpinner("Error retrieving transaction receipt", error);
42953
+ }
42954
+ }
42955
+ };
42956
+
42835
42957
  // src/commands/transactions/appeal.ts
42836
42958
  var AppealAction = class extends BaseAction {
42837
42959
  constructor() {
@@ -42861,7 +42983,16 @@ var AppealAction = class extends BaseAction {
42861
42983
  };
42862
42984
 
42863
42985
  // src/commands/transactions/index.ts
42986
+ function parseIntOption(value, fallback2) {
42987
+ const parsed = parseInt(value, 10);
42988
+ return isNaN(parsed) ? fallback2 : parsed;
42989
+ }
42864
42990
  function initializeTransactionsCommands(program2) {
42991
+ const validStatuses = Object.values(TransactionStatus).join(", ");
42992
+ program2.command("receipt <txId>").description("Get transaction receipt by hash").option("--status <status>", `Transaction status to wait for (${validStatuses})`, TransactionStatus.FINALIZED).option("--retries <retries>", "Number of retries", (value) => parseIntOption(value, 100), 100).option("--interval <interval>", "Interval between retries in milliseconds", (value) => parseIntOption(value, 5e3), 5e3).option("--rpc <rpcUrl>", "RPC URL for the network").action(async (txId, options) => {
42993
+ const receiptAction = new ReceiptAction();
42994
+ await receiptAction.receipt({ txId, ...options });
42995
+ });
42865
42996
  program2.command("appeal <txId>").description("Appeal a transaction by its hash").option("--rpc <rpcUrl>", "RPC URL for the network").action(async (txId, options) => {
42866
42997
  const appealAction = new AppealAction();
42867
42998
  await appealAction.appeal({ txId, ...options });
@@ -42907,27 +43038,15 @@ formdata-polyfill/esm.min.js:
42907
43038
  node-domexception/index.js:
42908
43039
  (*! node-domexception. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> *)
42909
43040
 
43041
+ @noble/hashes/esm/utils.js:
42910
43042
  @noble/hashes/esm/utils.js:
42911
43043
  (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
42912
43044
 
42913
- @noble/curves/esm/abstract/utils.js:
42914
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
42915
-
43045
+ @noble/curves/esm/utils.js:
42916
43046
  @noble/curves/esm/abstract/modular.js:
42917
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
42918
-
42919
43047
  @noble/curves/esm/abstract/curve.js:
42920
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
42921
-
42922
43048
  @noble/curves/esm/abstract/weierstrass.js:
42923
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
42924
-
42925
43049
  @noble/curves/esm/_shortw_utils.js:
42926
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
42927
-
42928
43050
  @noble/curves/esm/secp256k1.js:
42929
43051
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
42930
-
42931
- @noble/hashes/esm/utils.js:
42932
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
42933
43052
  */