starknet 5.9.0 → 5.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,8 +9,8 @@ var starknet = (() => {
9
9
  var __esm = (fn, res) => function __init() {
10
10
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
11
  };
12
- var __commonJS = (cb, mod2) => function __require() {
13
- return mod2 || (0, cb[__getOwnPropNames(cb)[0]])((mod2 = { exports: {} }).exports, mod2), mod2.exports;
12
+ var __commonJS = (cb, mod3) => function __require() {
13
+ return mod3 || (0, cb[__getOwnPropNames(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports;
14
14
  };
15
15
  var __export = (target, all) => {
16
16
  for (var name in all)
@@ -24,11 +24,11 @@ var starknet = (() => {
24
24
  }
25
25
  return to;
26
26
  };
27
- var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
28
- isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
29
- mod2
27
+ var __toESM = (mod3, isNodeMode, target) => (target = mod3 != null ? __create(__getProtoOf(mod3)) : {}, __copyProps(
28
+ isNodeMode || !mod3 || !mod3.__esModule ? __defProp(target, "default", { value: mod3, enumerable: true }) : target,
29
+ mod3
30
30
  ));
31
- var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
31
+ var __toCommonJS = (mod3) => __copyProps(__defProp({}, "__esModule", { value: true }), mod3);
32
32
 
33
33
  // node_modules/whatwg-fetch/fetch.js
34
34
  var fetch_exports = {};
@@ -760,7 +760,7 @@ var starknet = (() => {
760
760
  verify: () => verify
761
761
  });
762
762
 
763
- // node_modules/@noble/hashes/esm/_assert.js
763
+ // node_modules/micro-starknet/node_modules/@noble/hashes/esm/_assert.js
764
764
  function number(n) {
765
765
  if (!Number.isSafeInteger(n) || n < 0)
766
766
  throw new Error(`Wrong positive integer: ${n}`);
@@ -804,7 +804,7 @@ var starknet = (() => {
804
804
  };
805
805
  var assert_default = assert2;
806
806
 
807
- // node_modules/@noble/hashes/esm/_u64.js
807
+ // node_modules/micro-starknet/node_modules/@noble/hashes/esm/_u64.js
808
808
  var U32_MASK64 = BigInt(2 ** 32 - 1);
809
809
  var _32n = BigInt(32);
810
810
  function fromBig(n, le = false) {
@@ -870,10 +870,10 @@ var starknet = (() => {
870
870
  };
871
871
  var u64_default = u64;
872
872
 
873
- // node_modules/@noble/hashes/esm/crypto.js
873
+ // node_modules/micro-starknet/node_modules/@noble/hashes/esm/crypto.js
874
874
  var crypto = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
875
875
 
876
- // node_modules/@noble/hashes/esm/utils.js
876
+ // node_modules/micro-starknet/node_modules/@noble/hashes/esm/utils.js
877
877
  var u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
878
878
  var createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
879
879
  var rotr = (word, shift) => word << 32 - shift | word >>> shift;
@@ -936,7 +936,7 @@ var starknet = (() => {
936
936
  throw new Error("crypto.getRandomValues must be defined");
937
937
  }
938
938
 
939
- // node_modules/@noble/hashes/esm/sha3.js
939
+ // node_modules/micro-starknet/node_modules/@noble/hashes/esm/sha3.js
940
940
  var [SHA3_PI, SHA3_ROTL, _SHA3_IOTA] = [[], [], []];
941
941
  var _0n = BigInt(0);
942
942
  var _1n = BigInt(1);
@@ -1115,7 +1115,7 @@ var starknet = (() => {
1115
1115
  var shake128 = genShake(31, 168, 128 / 8);
1116
1116
  var shake256 = genShake(31, 136, 256 / 8);
1117
1117
 
1118
- // node_modules/@noble/hashes/esm/_sha2.js
1118
+ // node_modules/micro-starknet/node_modules/@noble/hashes/esm/_sha2.js
1119
1119
  function setBigUint64(view, byteOffset, value, isLE2) {
1120
1120
  if (typeof view.setBigUint64 === "function")
1121
1121
  return view.setBigUint64(byteOffset, value, isLE2);
@@ -1215,7 +1215,7 @@ var starknet = (() => {
1215
1215
  }
1216
1216
  };
1217
1217
 
1218
- // node_modules/@noble/hashes/esm/sha256.js
1218
+ // node_modules/micro-starknet/node_modules/@noble/hashes/esm/sha256.js
1219
1219
  var Chi = (a, b, c) => a & b ^ ~a & c;
1220
1220
  var Maj = (a, b, c) => a & b ^ a & c ^ b & c;
1221
1221
  var SHA256_K = new Uint32Array([
@@ -1381,7 +1381,7 @@ var starknet = (() => {
1381
1381
  var sha256 = wrapConstructor(() => new SHA256());
1382
1382
  var sha224 = wrapConstructor(() => new SHA224());
1383
1383
 
1384
- // node_modules/@noble/curves/esm/abstract/utils.js
1384
+ // node_modules/micro-starknet/node_modules/@noble/curves/esm/abstract/utils.js
1385
1385
  var utils_exports = {};
1386
1386
  __export(utils_exports, {
1387
1387
  bitGet: () => bitGet,
@@ -1499,11 +1499,11 @@ var starknet = (() => {
1499
1499
  }
1500
1500
  function bitLen(n) {
1501
1501
  let len;
1502
- for (len = 0; n > 0n; n >>= _1n2, len += 1)
1502
+ for (len = 0; n > _0n2; n >>= _1n2, len += 1)
1503
1503
  ;
1504
1504
  return len;
1505
1505
  }
1506
- var bitGet = (n, pos) => n >> BigInt(pos) & 1n;
1506
+ var bitGet = (n, pos) => n >> BigInt(pos) & _1n2;
1507
1507
  var bitSet = (n, pos, value) => n | (value ? _1n2 : _0n2) << BigInt(pos);
1508
1508
  var bitMask = (n) => (_2n2 << BigInt(n - 1)) - _1n2;
1509
1509
  var u8n = (data) => new Uint8Array(data);
@@ -1585,7 +1585,7 @@ var starknet = (() => {
1585
1585
  return object;
1586
1586
  }
1587
1587
 
1588
- // node_modules/@noble/curves/esm/abstract/modular.js
1588
+ // node_modules/micro-starknet/node_modules/@noble/curves/esm/abstract/modular.js
1589
1589
  var _0n3 = BigInt(0);
1590
1590
  var _1n3 = BigInt(1);
1591
1591
  var _2n3 = BigInt(2);
@@ -1641,34 +1641,34 @@ var starknet = (() => {
1641
1641
  ;
1642
1642
  if (S === 1) {
1643
1643
  const p1div4 = (P + _1n3) / _4n;
1644
- return function tonelliFast(Fp2, n) {
1645
- const root = Fp2.pow(n, p1div4);
1646
- if (!Fp2.eql(Fp2.sqr(root), n))
1644
+ return function tonelliFast(Fp, n) {
1645
+ const root = Fp.pow(n, p1div4);
1646
+ if (!Fp.eql(Fp.sqr(root), n))
1647
1647
  throw new Error("Cannot find square root");
1648
1648
  return root;
1649
1649
  };
1650
1650
  }
1651
1651
  const Q1div2 = (Q + _1n3) / _2n3;
1652
- return function tonelliSlow(Fp2, n) {
1653
- if (Fp2.pow(n, legendreC) === Fp2.neg(Fp2.ONE))
1652
+ return function tonelliSlow(Fp, n) {
1653
+ if (Fp.pow(n, legendreC) === Fp.neg(Fp.ONE))
1654
1654
  throw new Error("Cannot find square root");
1655
1655
  let r = S;
1656
- let g = Fp2.pow(Fp2.mul(Fp2.ONE, Z), Q);
1657
- let x = Fp2.pow(n, Q1div2);
1658
- let b = Fp2.pow(n, Q);
1659
- while (!Fp2.eql(b, Fp2.ONE)) {
1660
- if (Fp2.eql(b, Fp2.ZERO))
1661
- return Fp2.ZERO;
1656
+ let g = Fp.pow(Fp.mul(Fp.ONE, Z), Q);
1657
+ let x = Fp.pow(n, Q1div2);
1658
+ let b = Fp.pow(n, Q);
1659
+ while (!Fp.eql(b, Fp.ONE)) {
1660
+ if (Fp.eql(b, Fp.ZERO))
1661
+ return Fp.ZERO;
1662
1662
  let m = 1;
1663
- for (let t2 = Fp2.sqr(b); m < r; m++) {
1664
- if (Fp2.eql(t2, Fp2.ONE))
1663
+ for (let t2 = Fp.sqr(b); m < r; m++) {
1664
+ if (Fp.eql(t2, Fp.ONE))
1665
1665
  break;
1666
- t2 = Fp2.sqr(t2);
1666
+ t2 = Fp.sqr(t2);
1667
1667
  }
1668
- const ge = Fp2.pow(g, _1n3 << BigInt(r - m - 1));
1669
- g = Fp2.sqr(ge);
1670
- x = Fp2.mul(x, ge);
1671
- b = Fp2.mul(b, g);
1668
+ const ge = Fp.pow(g, _1n3 << BigInt(r - m - 1));
1669
+ g = Fp.sqr(ge);
1670
+ x = Fp.mul(x, ge);
1671
+ b = Fp.mul(b, g);
1672
1672
  r = m;
1673
1673
  }
1674
1674
  return x;
@@ -1677,22 +1677,22 @@ var starknet = (() => {
1677
1677
  function FpSqrt(P) {
1678
1678
  if (P % _4n === _3n) {
1679
1679
  const p1div4 = (P + _1n3) / _4n;
1680
- return function sqrt3mod4(Fp2, n) {
1681
- const root = Fp2.pow(n, p1div4);
1682
- if (!Fp2.eql(Fp2.sqr(root), n))
1680
+ return function sqrt3mod4(Fp, n) {
1681
+ const root = Fp.pow(n, p1div4);
1682
+ if (!Fp.eql(Fp.sqr(root), n))
1683
1683
  throw new Error("Cannot find square root");
1684
1684
  return root;
1685
1685
  };
1686
1686
  }
1687
1687
  if (P % _8n === _5n) {
1688
1688
  const c1 = (P - _5n) / _8n;
1689
- return function sqrt5mod8(Fp2, n) {
1690
- const n2 = Fp2.mul(n, _2n3);
1691
- const v = Fp2.pow(n2, c1);
1692
- const nv = Fp2.mul(n, v);
1693
- const i = Fp2.mul(Fp2.mul(nv, _2n3), v);
1694
- const root = Fp2.mul(nv, Fp2.sub(i, Fp2.ONE));
1695
- if (!Fp2.eql(Fp2.sqr(root), n))
1689
+ return function sqrt5mod8(Fp, n) {
1690
+ const n2 = Fp.mul(n, _2n3);
1691
+ const v = Fp.pow(n2, c1);
1692
+ const nv = Fp.mul(n, v);
1693
+ const i = Fp.mul(Fp.mul(nv, _2n3), v);
1694
+ const root = Fp.mul(nv, Fp.sub(i, Fp.ONE));
1695
+ if (!Fp.eql(Fp.sqr(root), n))
1696
1696
  throw new Error("Cannot find square root");
1697
1697
  return root;
1698
1698
  };
@@ -1746,7 +1746,7 @@ var starknet = (() => {
1746
1746
  if (power & _1n3)
1747
1747
  p = f.mul(p, d);
1748
1748
  d = f.sqr(d);
1749
- power >>= 1n;
1749
+ power >>= _1n3;
1750
1750
  }
1751
1751
  return p;
1752
1752
  }
@@ -1772,10 +1772,10 @@ var starknet = (() => {
1772
1772
  const nByteLength = Math.ceil(_nBitLength / 8);
1773
1773
  return { nBitLength: _nBitLength, nByteLength };
1774
1774
  }
1775
- function Fp(ORDER, bitLen2, isLE2 = false, redef = {}) {
1775
+ function Field(ORDER, bitLen3, isLE2 = false, redef = {}) {
1776
1776
  if (ORDER <= _0n3)
1777
1777
  throw new Error(`Expected Fp ORDER > 0, got ${ORDER}`);
1778
- const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, bitLen2);
1778
+ const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, bitLen3);
1779
1779
  if (BYTES > 2048)
1780
1780
  throw new Error("Field lengths over 2048 bytes are not supported");
1781
1781
  const sqrtP = FpSqrt(ORDER);
@@ -1829,16 +1829,10 @@ var starknet = (() => {
1829
1829
  return mod(num, groupOrder - _1n3) + _1n3;
1830
1830
  }
1831
1831
 
1832
- // node_modules/@noble/curves/esm/abstract/poseidon.js
1833
- var poseidon_exports = {};
1834
- __export(poseidon_exports, {
1835
- poseidon: () => poseidon,
1836
- splitConstants: () => splitConstants,
1837
- validateOpts: () => validateOpts
1838
- });
1832
+ // node_modules/micro-starknet/node_modules/@noble/curves/esm/abstract/poseidon.js
1839
1833
  function validateOpts(opts) {
1840
- const { Fp: Fp2 } = opts;
1841
- validateField(Fp2);
1834
+ const { Fp } = opts;
1835
+ validateField(Fp);
1842
1836
  for (const i of ["t", "roundsFull", "roundsPartial"]) {
1843
1837
  if (typeof opts[i] !== "number" || !Number.isSafeInteger(opts[i]))
1844
1838
  throw new Error(`Poseidon: invalid param ${i}=${opts[i]} (${typeof opts[i]})`);
@@ -1851,11 +1845,11 @@ var starknet = (() => {
1851
1845
  if (typeof sboxPower !== "number" || !Number.isSafeInteger(sboxPower))
1852
1846
  throw new Error(`Poseidon wrong sboxPower=${sboxPower}`);
1853
1847
  const _sboxPower = BigInt(sboxPower);
1854
- let sboxFn = (n) => FpPow(Fp2, n, _sboxPower);
1848
+ let sboxFn = (n) => FpPow(Fp, n, _sboxPower);
1855
1849
  if (sboxPower === 3)
1856
- sboxFn = (n) => Fp2.mul(Fp2.sqrN(n), n);
1850
+ sboxFn = (n) => Fp.mul(Fp.sqrN(n), n);
1857
1851
  else if (sboxPower === 5)
1858
- sboxFn = (n) => Fp2.mul(Fp2.sqrN(Fp2.sqrN(n)), n);
1852
+ sboxFn = (n) => Fp.mul(Fp.sqrN(Fp.sqrN(n)), n);
1859
1853
  if (opts.roundsFull % 2 !== 0)
1860
1854
  throw new Error(`Poseidon roundsFull is not even: ${opts.roundsFull}`);
1861
1855
  const rounds = opts.roundsFull + opts.roundsPartial;
@@ -1865,9 +1859,9 @@ var starknet = (() => {
1865
1859
  if (!Array.isArray(rc) || rc.length !== opts.t)
1866
1860
  throw new Error(`Poseidon wrong round constants: ${rc}`);
1867
1861
  return rc.map((i) => {
1868
- if (typeof i !== "bigint" || !Fp2.isValid(i))
1862
+ if (typeof i !== "bigint" || !Fp.isValid(i))
1869
1863
  throw new Error(`Poseidon wrong round constant=${i}`);
1870
- return Fp2.create(i);
1864
+ return Fp.create(i);
1871
1865
  });
1872
1866
  });
1873
1867
  if (!Array.isArray(opts.mds) || opts.mds.length !== opts.t)
@@ -1878,38 +1872,22 @@ var starknet = (() => {
1878
1872
  return mdsRow.map((i) => {
1879
1873
  if (typeof i !== "bigint")
1880
1874
  throw new Error(`Poseidon MDS matrix value=${i}`);
1881
- return Fp2.create(i);
1875
+ return Fp.create(i);
1882
1876
  });
1883
1877
  });
1884
1878
  return Object.freeze({ ...opts, rounds, sboxFn, roundConstants, mds });
1885
1879
  }
1886
- function splitConstants(rc, t) {
1887
- if (typeof t !== "number")
1888
- throw new Error("poseidonSplitConstants: wrong t");
1889
- if (!Array.isArray(rc) || rc.length % t)
1890
- throw new Error("poseidonSplitConstants: wrong rc");
1891
- const res = [];
1892
- let tmp = [];
1893
- for (let i = 0; i < rc.length; i++) {
1894
- tmp.push(rc[i]);
1895
- if (tmp.length === t) {
1896
- res.push(tmp);
1897
- tmp = [];
1898
- }
1899
- }
1900
- return res;
1901
- }
1902
1880
  function poseidon(opts) {
1903
- const { t, Fp: Fp2, rounds, sboxFn, reversePartialPowIdx } = validateOpts(opts);
1881
+ const { t, Fp, rounds, sboxFn, reversePartialPowIdx } = validateOpts(opts);
1904
1882
  const halfRoundsFull = Math.floor(opts.roundsFull / 2);
1905
1883
  const partialIdx = reversePartialPowIdx ? t - 1 : 0;
1906
1884
  const poseidonRound = (values, isFull, idx) => {
1907
- values = values.map((i, j) => Fp2.add(i, opts.roundConstants[idx][j]));
1885
+ values = values.map((i, j) => Fp.add(i, opts.roundConstants[idx][j]));
1908
1886
  if (isFull)
1909
1887
  values = values.map((i) => sboxFn(i));
1910
1888
  else
1911
1889
  values[partialIdx] = sboxFn(values[partialIdx]);
1912
- values = opts.mds.map((i) => i.reduce((acc, i2, j) => Fp2.add(acc, Fp2.mulN(i2, values[j])), Fp2.ZERO));
1890
+ values = opts.mds.map((i) => i.reduce((acc, i2, j) => Fp.add(acc, Fp.mulN(i2, values[j])), Fp.ZERO));
1913
1891
  return values;
1914
1892
  };
1915
1893
  const poseidonHash2 = function poseidonHash3(values) {
@@ -1918,7 +1896,7 @@ var starknet = (() => {
1918
1896
  values = values.map((i) => {
1919
1897
  if (typeof i !== "bigint")
1920
1898
  throw new Error(`Poseidon: wrong value=${i} (${typeof i})`);
1921
- return Fp2.create(i);
1899
+ return Fp.create(i);
1922
1900
  });
1923
1901
  let round = 0;
1924
1902
  for (let i = 0; i < halfRoundsFull; i++)
@@ -1935,16 +1913,7 @@ var starknet = (() => {
1935
1913
  return poseidonHash2;
1936
1914
  }
1937
1915
 
1938
- // node_modules/@noble/curves/esm/abstract/weierstrass.js
1939
- var weierstrass_exports = {};
1940
- __export(weierstrass_exports, {
1941
- SWUFpSqrtRatio: () => SWUFpSqrtRatio,
1942
- mapToCurveSimpleSWU: () => mapToCurveSimpleSWU,
1943
- weierstrass: () => weierstrass,
1944
- weierstrassPoints: () => weierstrassPoints
1945
- });
1946
-
1947
- // node_modules/@noble/curves/esm/abstract/curve.js
1916
+ // node_modules/micro-starknet/node_modules/@noble/curves/esm/abstract/curve.js
1948
1917
  var _0n4 = BigInt(0);
1949
1918
  var _1n4 = BigInt(1);
1950
1919
  function wNAF(c, bits) {
@@ -2037,27 +2006,31 @@ var starknet = (() => {
2037
2006
  nBitLength: "isSafeInteger",
2038
2007
  nByteLength: "isSafeInteger"
2039
2008
  });
2040
- return Object.freeze({ ...nLength(curve2.n, curve2.nBitLength), ...curve2 });
2009
+ return Object.freeze({
2010
+ ...nLength(curve2.n, curve2.nBitLength),
2011
+ ...curve2,
2012
+ ...{ p: curve2.Fp.ORDER }
2013
+ });
2041
2014
  }
2042
2015
 
2043
- // node_modules/@noble/curves/esm/abstract/weierstrass.js
2016
+ // node_modules/micro-starknet/node_modules/@noble/curves/esm/abstract/weierstrass.js
2044
2017
  function validatePointOpts(curve2) {
2045
2018
  const opts = validateBasic(curve2);
2046
2019
  validateObject(opts, {
2047
2020
  a: "field",
2048
- b: "field",
2049
- fromBytes: "function",
2050
- toBytes: "function"
2021
+ b: "field"
2051
2022
  }, {
2052
2023
  allowedPrivateKeyLengths: "array",
2053
2024
  wrapPrivateKey: "boolean",
2054
2025
  isTorsionFree: "function",
2055
2026
  clearCofactor: "function",
2056
- allowInfinityPoint: "boolean"
2027
+ allowInfinityPoint: "boolean",
2028
+ fromBytes: "function",
2029
+ toBytes: "function"
2057
2030
  });
2058
- const { endo, Fp: Fp2, a } = opts;
2031
+ const { endo, Fp, a } = opts;
2059
2032
  if (endo) {
2060
- if (!Fp2.eql(a, Fp2.ZERO)) {
2033
+ if (!Fp.eql(a, Fp.ZERO)) {
2061
2034
  throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");
2062
2035
  }
2063
2036
  if (typeof endo !== "object" || typeof endo.beta !== "bigint" || typeof endo.splitScalar !== "function") {
@@ -2081,8 +2054,10 @@ var starknet = (() => {
2081
2054
  const res = data.subarray(2, len + 2);
2082
2055
  if (!len || res.length !== len)
2083
2056
  throw new E("Invalid signature integer: wrong length");
2084
- if (res[0] === 0 && res[1] <= 127)
2085
- throw new E("Invalid signature integer: trailing length");
2057
+ if (res[0] & 128)
2058
+ throw new E("Invalid signature integer: negative");
2059
+ if (res[0] === 0 && !(res[1] & 128))
2060
+ throw new E("Invalid signature integer: unnecessary leading zero");
2086
2061
  return { d: b2n(res), l: data.subarray(len + 2) };
2087
2062
  },
2088
2063
  toSig(hex) {
@@ -2102,7 +2077,7 @@ var starknet = (() => {
2102
2077
  return { r, s };
2103
2078
  },
2104
2079
  hexFromSig(sig) {
2105
- const slice = (s2) => Number.parseInt(s2[0], 16) >= 8 ? "00" + s2 : s2;
2080
+ const slice = (s2) => Number.parseInt(s2[0], 16) & 8 ? "00" + s2 : s2;
2106
2081
  const h = (num) => {
2107
2082
  const hex = num.toString(16);
2108
2083
  return hex.length & 1 ? `0${hex}` : hex;
@@ -2118,15 +2093,30 @@ var starknet = (() => {
2118
2093
  };
2119
2094
  var _0n5 = BigInt(0);
2120
2095
  var _1n5 = BigInt(1);
2096
+ var _2n4 = BigInt(2);
2097
+ var _3n2 = BigInt(3);
2098
+ var _4n2 = BigInt(4);
2121
2099
  function weierstrassPoints(opts) {
2122
2100
  const CURVE2 = validatePointOpts(opts);
2123
- const { Fp: Fp2 } = CURVE2;
2101
+ const { Fp } = CURVE2;
2102
+ const toBytes2 = CURVE2.toBytes || ((c, point, isCompressed) => {
2103
+ const a = point.toAffine();
2104
+ return concatBytes2(Uint8Array.from([4]), Fp.toBytes(a.x), Fp.toBytes(a.y));
2105
+ });
2106
+ const fromBytes = CURVE2.fromBytes || ((bytes2) => {
2107
+ const tail = bytes2.subarray(1);
2108
+ const x = Fp.fromBytes(tail.subarray(0, Fp.BYTES));
2109
+ const y = Fp.fromBytes(tail.subarray(Fp.BYTES, 2 * Fp.BYTES));
2110
+ return { x, y };
2111
+ });
2124
2112
  function weierstrassEquation(x) {
2125
2113
  const { a, b } = CURVE2;
2126
- const x2 = Fp2.sqr(x);
2127
- const x3 = Fp2.mul(x2, x);
2128
- return Fp2.add(Fp2.add(x3, Fp2.mul(x, a)), b);
2114
+ const x2 = Fp.sqr(x);
2115
+ const x3 = Fp.mul(x2, x);
2116
+ return Fp.add(Fp.add(x3, Fp.mul(x, a)), b);
2129
2117
  }
2118
+ if (!Fp.eql(Fp.sqr(CURVE2.Gy), weierstrassEquation(CURVE2.Gx)))
2119
+ throw new Error("bad generator point: equation left != right");
2130
2120
  function isWithinCurveOrder(num) {
2131
2121
  return typeof num === "bigint" && _0n5 < num && num < CURVE2.n;
2132
2122
  }
@@ -2164,23 +2154,23 @@ var starknet = (() => {
2164
2154
  this.px = px;
2165
2155
  this.py = py;
2166
2156
  this.pz = pz;
2167
- if (px == null || !Fp2.isValid(px))
2157
+ if (px == null || !Fp.isValid(px))
2168
2158
  throw new Error("x required");
2169
- if (py == null || !Fp2.isValid(py))
2159
+ if (py == null || !Fp.isValid(py))
2170
2160
  throw new Error("y required");
2171
- if (pz == null || !Fp2.isValid(pz))
2161
+ if (pz == null || !Fp.isValid(pz))
2172
2162
  throw new Error("z required");
2173
2163
  }
2174
2164
  static fromAffine(p) {
2175
2165
  const { x, y } = p || {};
2176
- if (!p || !Fp2.isValid(x) || !Fp2.isValid(y))
2166
+ if (!p || !Fp.isValid(x) || !Fp.isValid(y))
2177
2167
  throw new Error("invalid affine point");
2178
2168
  if (p instanceof Point)
2179
2169
  throw new Error("projective point not allowed");
2180
- const is0 = (i) => Fp2.eql(i, Fp2.ZERO);
2170
+ const is0 = (i) => Fp.eql(i, Fp.ZERO);
2181
2171
  if (is0(x) && is0(y))
2182
2172
  return Point.ZERO;
2183
- return new Point(x, y, Fp2.ONE);
2173
+ return new Point(x, y, Fp.ONE);
2184
2174
  }
2185
2175
  get x() {
2186
2176
  return this.toAffine().x;
@@ -2189,11 +2179,11 @@ var starknet = (() => {
2189
2179
  return this.toAffine().y;
2190
2180
  }
2191
2181
  static normalizeZ(points) {
2192
- const toInv = Fp2.invertBatch(points.map((p) => p.pz));
2182
+ const toInv = Fp.invertBatch(points.map((p) => p.pz));
2193
2183
  return points.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
2194
2184
  }
2195
2185
  static fromHex(hex) {
2196
- const P = Point.fromAffine(CURVE2.fromBytes(ensureBytes("pointHex", hex)));
2186
+ const P = Point.fromAffine(fromBytes(ensureBytes("pointHex", hex)));
2197
2187
  P.assertValidity();
2198
2188
  return P;
2199
2189
  }
@@ -2211,117 +2201,117 @@ var starknet = (() => {
2211
2201
  throw new Error("bad point: ZERO");
2212
2202
  }
2213
2203
  const { x, y } = this.toAffine();
2214
- if (!Fp2.isValid(x) || !Fp2.isValid(y))
2204
+ if (!Fp.isValid(x) || !Fp.isValid(y))
2215
2205
  throw new Error("bad point: x or y not FE");
2216
- const left = Fp2.sqr(y);
2206
+ const left = Fp.sqr(y);
2217
2207
  const right = weierstrassEquation(x);
2218
- if (!Fp2.eql(left, right))
2208
+ if (!Fp.eql(left, right))
2219
2209
  throw new Error("bad point: equation left != right");
2220
2210
  if (!this.isTorsionFree())
2221
2211
  throw new Error("bad point: not in prime-order subgroup");
2222
2212
  }
2223
2213
  hasEvenY() {
2224
2214
  const { y } = this.toAffine();
2225
- if (Fp2.isOdd)
2226
- return !Fp2.isOdd(y);
2215
+ if (Fp.isOdd)
2216
+ return !Fp.isOdd(y);
2227
2217
  throw new Error("Field doesn't support isOdd");
2228
2218
  }
2229
2219
  equals(other) {
2230
2220
  assertPrjPoint(other);
2231
2221
  const { px: X1, py: Y1, pz: Z1 } = this;
2232
2222
  const { px: X2, py: Y2, pz: Z2 } = other;
2233
- const U1 = Fp2.eql(Fp2.mul(X1, Z2), Fp2.mul(X2, Z1));
2234
- const U2 = Fp2.eql(Fp2.mul(Y1, Z2), Fp2.mul(Y2, Z1));
2223
+ const U1 = Fp.eql(Fp.mul(X1, Z2), Fp.mul(X2, Z1));
2224
+ const U2 = Fp.eql(Fp.mul(Y1, Z2), Fp.mul(Y2, Z1));
2235
2225
  return U1 && U2;
2236
2226
  }
2237
2227
  negate() {
2238
- return new Point(this.px, Fp2.neg(this.py), this.pz);
2228
+ return new Point(this.px, Fp.neg(this.py), this.pz);
2239
2229
  }
2240
2230
  double() {
2241
2231
  const { a, b } = CURVE2;
2242
- const b3 = Fp2.mul(b, 3n);
2232
+ const b3 = Fp.mul(b, _3n2);
2243
2233
  const { px: X1, py: Y1, pz: Z1 } = this;
2244
- let X3 = Fp2.ZERO, Y3 = Fp2.ZERO, Z3 = Fp2.ZERO;
2245
- let t0 = Fp2.mul(X1, X1);
2246
- let t1 = Fp2.mul(Y1, Y1);
2247
- let t2 = Fp2.mul(Z1, Z1);
2248
- let t3 = Fp2.mul(X1, Y1);
2249
- t3 = Fp2.add(t3, t3);
2250
- Z3 = Fp2.mul(X1, Z1);
2251
- Z3 = Fp2.add(Z3, Z3);
2252
- X3 = Fp2.mul(a, Z3);
2253
- Y3 = Fp2.mul(b3, t2);
2254
- Y3 = Fp2.add(X3, Y3);
2255
- X3 = Fp2.sub(t1, Y3);
2256
- Y3 = Fp2.add(t1, Y3);
2257
- Y3 = Fp2.mul(X3, Y3);
2258
- X3 = Fp2.mul(t3, X3);
2259
- Z3 = Fp2.mul(b3, Z3);
2260
- t2 = Fp2.mul(a, t2);
2261
- t3 = Fp2.sub(t0, t2);
2262
- t3 = Fp2.mul(a, t3);
2263
- t3 = Fp2.add(t3, Z3);
2264
- Z3 = Fp2.add(t0, t0);
2265
- t0 = Fp2.add(Z3, t0);
2266
- t0 = Fp2.add(t0, t2);
2267
- t0 = Fp2.mul(t0, t3);
2268
- Y3 = Fp2.add(Y3, t0);
2269
- t2 = Fp2.mul(Y1, Z1);
2270
- t2 = Fp2.add(t2, t2);
2271
- t0 = Fp2.mul(t2, t3);
2272
- X3 = Fp2.sub(X3, t0);
2273
- Z3 = Fp2.mul(t2, t1);
2274
- Z3 = Fp2.add(Z3, Z3);
2275
- Z3 = Fp2.add(Z3, Z3);
2234
+ let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO;
2235
+ let t0 = Fp.mul(X1, X1);
2236
+ let t1 = Fp.mul(Y1, Y1);
2237
+ let t2 = Fp.mul(Z1, Z1);
2238
+ let t3 = Fp.mul(X1, Y1);
2239
+ t3 = Fp.add(t3, t3);
2240
+ Z3 = Fp.mul(X1, Z1);
2241
+ Z3 = Fp.add(Z3, Z3);
2242
+ X3 = Fp.mul(a, Z3);
2243
+ Y3 = Fp.mul(b3, t2);
2244
+ Y3 = Fp.add(X3, Y3);
2245
+ X3 = Fp.sub(t1, Y3);
2246
+ Y3 = Fp.add(t1, Y3);
2247
+ Y3 = Fp.mul(X3, Y3);
2248
+ X3 = Fp.mul(t3, X3);
2249
+ Z3 = Fp.mul(b3, Z3);
2250
+ t2 = Fp.mul(a, t2);
2251
+ t3 = Fp.sub(t0, t2);
2252
+ t3 = Fp.mul(a, t3);
2253
+ t3 = Fp.add(t3, Z3);
2254
+ Z3 = Fp.add(t0, t0);
2255
+ t0 = Fp.add(Z3, t0);
2256
+ t0 = Fp.add(t0, t2);
2257
+ t0 = Fp.mul(t0, t3);
2258
+ Y3 = Fp.add(Y3, t0);
2259
+ t2 = Fp.mul(Y1, Z1);
2260
+ t2 = Fp.add(t2, t2);
2261
+ t0 = Fp.mul(t2, t3);
2262
+ X3 = Fp.sub(X3, t0);
2263
+ Z3 = Fp.mul(t2, t1);
2264
+ Z3 = Fp.add(Z3, Z3);
2265
+ Z3 = Fp.add(Z3, Z3);
2276
2266
  return new Point(X3, Y3, Z3);
2277
2267
  }
2278
2268
  add(other) {
2279
2269
  assertPrjPoint(other);
2280
2270
  const { px: X1, py: Y1, pz: Z1 } = this;
2281
2271
  const { px: X2, py: Y2, pz: Z2 } = other;
2282
- let X3 = Fp2.ZERO, Y3 = Fp2.ZERO, Z3 = Fp2.ZERO;
2272
+ let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO;
2283
2273
  const a = CURVE2.a;
2284
- const b3 = Fp2.mul(CURVE2.b, 3n);
2285
- let t0 = Fp2.mul(X1, X2);
2286
- let t1 = Fp2.mul(Y1, Y2);
2287
- let t2 = Fp2.mul(Z1, Z2);
2288
- let t3 = Fp2.add(X1, Y1);
2289
- let t4 = Fp2.add(X2, Y2);
2290
- t3 = Fp2.mul(t3, t4);
2291
- t4 = Fp2.add(t0, t1);
2292
- t3 = Fp2.sub(t3, t4);
2293
- t4 = Fp2.add(X1, Z1);
2294
- let t5 = Fp2.add(X2, Z2);
2295
- t4 = Fp2.mul(t4, t5);
2296
- t5 = Fp2.add(t0, t2);
2297
- t4 = Fp2.sub(t4, t5);
2298
- t5 = Fp2.add(Y1, Z1);
2299
- X3 = Fp2.add(Y2, Z2);
2300
- t5 = Fp2.mul(t5, X3);
2301
- X3 = Fp2.add(t1, t2);
2302
- t5 = Fp2.sub(t5, X3);
2303
- Z3 = Fp2.mul(a, t4);
2304
- X3 = Fp2.mul(b3, t2);
2305
- Z3 = Fp2.add(X3, Z3);
2306
- X3 = Fp2.sub(t1, Z3);
2307
- Z3 = Fp2.add(t1, Z3);
2308
- Y3 = Fp2.mul(X3, Z3);
2309
- t1 = Fp2.add(t0, t0);
2310
- t1 = Fp2.add(t1, t0);
2311
- t2 = Fp2.mul(a, t2);
2312
- t4 = Fp2.mul(b3, t4);
2313
- t1 = Fp2.add(t1, t2);
2314
- t2 = Fp2.sub(t0, t2);
2315
- t2 = Fp2.mul(a, t2);
2316
- t4 = Fp2.add(t4, t2);
2317
- t0 = Fp2.mul(t1, t4);
2318
- Y3 = Fp2.add(Y3, t0);
2319
- t0 = Fp2.mul(t5, t4);
2320
- X3 = Fp2.mul(t3, X3);
2321
- X3 = Fp2.sub(X3, t0);
2322
- t0 = Fp2.mul(t3, t1);
2323
- Z3 = Fp2.mul(t5, Z3);
2324
- Z3 = Fp2.add(Z3, t0);
2274
+ const b3 = Fp.mul(CURVE2.b, _3n2);
2275
+ let t0 = Fp.mul(X1, X2);
2276
+ let t1 = Fp.mul(Y1, Y2);
2277
+ let t2 = Fp.mul(Z1, Z2);
2278
+ let t3 = Fp.add(X1, Y1);
2279
+ let t4 = Fp.add(X2, Y2);
2280
+ t3 = Fp.mul(t3, t4);
2281
+ t4 = Fp.add(t0, t1);
2282
+ t3 = Fp.sub(t3, t4);
2283
+ t4 = Fp.add(X1, Z1);
2284
+ let t5 = Fp.add(X2, Z2);
2285
+ t4 = Fp.mul(t4, t5);
2286
+ t5 = Fp.add(t0, t2);
2287
+ t4 = Fp.sub(t4, t5);
2288
+ t5 = Fp.add(Y1, Z1);
2289
+ X3 = Fp.add(Y2, Z2);
2290
+ t5 = Fp.mul(t5, X3);
2291
+ X3 = Fp.add(t1, t2);
2292
+ t5 = Fp.sub(t5, X3);
2293
+ Z3 = Fp.mul(a, t4);
2294
+ X3 = Fp.mul(b3, t2);
2295
+ Z3 = Fp.add(X3, Z3);
2296
+ X3 = Fp.sub(t1, Z3);
2297
+ Z3 = Fp.add(t1, Z3);
2298
+ Y3 = Fp.mul(X3, Z3);
2299
+ t1 = Fp.add(t0, t0);
2300
+ t1 = Fp.add(t1, t0);
2301
+ t2 = Fp.mul(a, t2);
2302
+ t4 = Fp.mul(b3, t4);
2303
+ t1 = Fp.add(t1, t2);
2304
+ t2 = Fp.sub(t0, t2);
2305
+ t2 = Fp.mul(a, t2);
2306
+ t4 = Fp.add(t4, t2);
2307
+ t0 = Fp.mul(t1, t4);
2308
+ Y3 = Fp.add(Y3, t0);
2309
+ t0 = Fp.mul(t5, t4);
2310
+ X3 = Fp.mul(t3, X3);
2311
+ X3 = Fp.sub(X3, t0);
2312
+ t0 = Fp.mul(t3, t1);
2313
+ Z3 = Fp.mul(t5, Z3);
2314
+ Z3 = Fp.add(Z3, t0);
2325
2315
  return new Point(X3, Y3, Z3);
2326
2316
  }
2327
2317
  subtract(other) {
@@ -2332,7 +2322,7 @@ var starknet = (() => {
2332
2322
  }
2333
2323
  wNAF(n) {
2334
2324
  return wnaf.wNAFCached(this, pointPrecomputes, n, (comp) => {
2335
- const toInv = Fp2.invertBatch(comp.map((p) => p.pz));
2325
+ const toInv = Fp.invertBatch(comp.map((p) => p.pz));
2336
2326
  return comp.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
2337
2327
  });
2338
2328
  }
@@ -2363,7 +2353,7 @@ var starknet = (() => {
2363
2353
  k1p = k1p.negate();
2364
2354
  if (k2neg)
2365
2355
  k2p = k2p.negate();
2366
- k2p = new Point(Fp2.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
2356
+ k2p = new Point(Fp.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
2367
2357
  return k1p.add(k2p);
2368
2358
  }
2369
2359
  multiply(scalar) {
@@ -2377,7 +2367,7 @@ var starknet = (() => {
2377
2367
  let { p: k2p, f: f2p } = this.wNAF(k2);
2378
2368
  k1p = wnaf.constTimeNegate(k1neg, k1p);
2379
2369
  k2p = wnaf.constTimeNegate(k2neg, k2p);
2380
- k2p = new Point(Fp2.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
2370
+ k2p = new Point(Fp.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
2381
2371
  point = k1p.add(k2p);
2382
2372
  fake = f1p.add(f2p);
2383
2373
  } else {
@@ -2397,13 +2387,13 @@ var starknet = (() => {
2397
2387
  const { px: x, py: y, pz: z } = this;
2398
2388
  const is0 = this.is0();
2399
2389
  if (iz == null)
2400
- iz = is0 ? Fp2.ONE : Fp2.inv(z);
2401
- const ax = Fp2.mul(x, iz);
2402
- const ay = Fp2.mul(y, iz);
2403
- const zz = Fp2.mul(z, iz);
2390
+ iz = is0 ? Fp.ONE : Fp.inv(z);
2391
+ const ax = Fp.mul(x, iz);
2392
+ const ay = Fp.mul(y, iz);
2393
+ const zz = Fp.mul(z, iz);
2404
2394
  if (is0)
2405
- return { x: Fp2.ZERO, y: Fp2.ZERO };
2406
- if (!Fp2.eql(zz, Fp2.ONE))
2395
+ return { x: Fp.ZERO, y: Fp.ZERO };
2396
+ if (!Fp.eql(zz, Fp.ONE))
2407
2397
  throw new Error("invZ was invalid");
2408
2398
  return { x: ax, y: ay };
2409
2399
  }
@@ -2425,17 +2415,18 @@ var starknet = (() => {
2425
2415
  }
2426
2416
  toRawBytes(isCompressed = true) {
2427
2417
  this.assertValidity();
2428
- return CURVE2.toBytes(Point, this, isCompressed);
2418
+ return toBytes2(Point, this, isCompressed);
2429
2419
  }
2430
2420
  toHex(isCompressed = true) {
2431
2421
  return bytesToHex(this.toRawBytes(isCompressed));
2432
2422
  }
2433
2423
  }
2434
- Point.BASE = new Point(CURVE2.Gx, CURVE2.Gy, Fp2.ONE);
2435
- Point.ZERO = new Point(Fp2.ZERO, Fp2.ONE, Fp2.ZERO);
2424
+ Point.BASE = new Point(CURVE2.Gx, CURVE2.Gy, Fp.ONE);
2425
+ Point.ZERO = new Point(Fp.ZERO, Fp.ONE, Fp.ZERO);
2436
2426
  const _bits = CURVE2.nBitLength;
2437
2427
  const wnaf = wNAF(Point, CURVE2.endo ? Math.ceil(_bits / 2) : _bits);
2438
2428
  return {
2429
+ CURVE: CURVE2,
2439
2430
  ProjectivePoint: Point,
2440
2431
  normPrivateKeyToScalar,
2441
2432
  weierstrassEquation,
@@ -2457,12 +2448,11 @@ var starknet = (() => {
2457
2448
  }
2458
2449
  function weierstrass(curveDef) {
2459
2450
  const CURVE2 = validateOpts2(curveDef);
2460
- const CURVE_ORDER2 = CURVE2.n;
2461
- const Fp2 = CURVE2.Fp;
2462
- const compressedLen = Fp2.BYTES + 1;
2463
- const uncompressedLen = 2 * Fp2.BYTES + 1;
2451
+ const { Fp, n: CURVE_ORDER2 } = CURVE2;
2452
+ const compressedLen = Fp.BYTES + 1;
2453
+ const uncompressedLen = 2 * Fp.BYTES + 1;
2464
2454
  function isValidFieldElement(num) {
2465
- return _0n5 < num && num < Fp2.ORDER;
2455
+ return _0n5 < num && num < Fp.ORDER;
2466
2456
  }
2467
2457
  function modN(a) {
2468
2458
  return mod(a, CURVE_ORDER2);
@@ -2474,12 +2464,12 @@ var starknet = (() => {
2474
2464
  ...CURVE2,
2475
2465
  toBytes(c, point, isCompressed) {
2476
2466
  const a = point.toAffine();
2477
- const x = Fp2.toBytes(a.x);
2467
+ const x = Fp.toBytes(a.x);
2478
2468
  const cat = concatBytes2;
2479
2469
  if (isCompressed) {
2480
2470
  return cat(Uint8Array.from([point.hasEvenY() ? 2 : 3]), x);
2481
2471
  } else {
2482
- return cat(Uint8Array.from([4]), x, Fp2.toBytes(a.y));
2472
+ return cat(Uint8Array.from([4]), x, Fp.toBytes(a.y));
2483
2473
  }
2484
2474
  },
2485
2475
  fromBytes(bytes2) {
@@ -2491,15 +2481,15 @@ var starknet = (() => {
2491
2481
  if (!isValidFieldElement(x))
2492
2482
  throw new Error("Point is not on curve");
2493
2483
  const y2 = weierstrassEquation(x);
2494
- let y = Fp2.sqrt(y2);
2484
+ let y = Fp.sqrt(y2);
2495
2485
  const isYOdd = (y & _1n5) === _1n5;
2496
2486
  const isHeadOdd = (head & 1) === 1;
2497
2487
  if (isHeadOdd !== isYOdd)
2498
- y = Fp2.neg(y);
2488
+ y = Fp.neg(y);
2499
2489
  return { x, y };
2500
2490
  } else if (len === uncompressedLen && head === 4) {
2501
- const x = Fp2.fromBytes(tail.subarray(0, Fp2.BYTES));
2502
- const y = Fp2.fromBytes(tail.subarray(Fp2.BYTES, 2 * Fp2.BYTES));
2491
+ const x = Fp.fromBytes(tail.subarray(0, Fp.BYTES));
2492
+ const y = Fp.fromBytes(tail.subarray(Fp.BYTES, 2 * Fp.BYTES));
2503
2493
  return { x, y };
2504
2494
  } else {
2505
2495
  throw new Error(`Point of length ${len} was invalid. Expected ${compressedLen} compressed bytes or ${uncompressedLen} uncompressed bytes`);
@@ -2546,7 +2536,7 @@ var starknet = (() => {
2546
2536
  if (rec == null || ![0, 1, 2, 3].includes(rec))
2547
2537
  throw new Error("recovery id invalid");
2548
2538
  const radj = rec === 2 || rec === 3 ? r + CURVE2.n : r;
2549
- if (radj >= Fp2.ORDER)
2539
+ if (radj >= Fp.ORDER)
2550
2540
  throw new Error("recovery id 2 or 3 invalid");
2551
2541
  const prefix = (rec & 1) === 0 ? "02" : "03";
2552
2542
  const R = Point.fromHex(prefix + numToNByteStr(radj));
@@ -2589,7 +2579,7 @@ var starknet = (() => {
2589
2579
  },
2590
2580
  normPrivateKeyToScalar,
2591
2581
  randomPrivateKey: () => {
2592
- const rand = CURVE2.randomBytes(Fp2.BYTES + 8);
2582
+ const rand = CURVE2.randomBytes(Fp.BYTES + 8);
2593
2583
  const num = hashToPrivateScalar(rand, CURVE_ORDER2);
2594
2584
  return numberToBytesBE(num, CURVE2.nByteLength);
2595
2585
  },
@@ -2652,8 +2642,8 @@ var starknet = (() => {
2652
2642
  const d = normPrivateKeyToScalar(privateKey);
2653
2643
  const seedArgs = [int2octets(d), int2octets(h1int)];
2654
2644
  if (ent != null) {
2655
- const e = ent === true ? randomBytes2(Fp2.BYTES) : ent;
2656
- seedArgs.push(ensureBytes("extraEntropy", e, Fp2.BYTES));
2645
+ const e = ent === true ? randomBytes2(Fp.BYTES) : ent;
2646
+ seedArgs.push(ensureBytes("extraEntropy", e, Fp.BYTES));
2657
2647
  }
2658
2648
  const seed = concatBytes2(...seedArgs);
2659
2649
  const m = h1int;
@@ -2744,104 +2734,8 @@ var starknet = (() => {
2744
2734
  utils: utils2
2745
2735
  };
2746
2736
  }
2747
- function SWUFpSqrtRatio(Fp2, Z) {
2748
- const q = Fp2.ORDER;
2749
- let l = 0n;
2750
- for (let o = q - 1n; o % 2n === 0n; o /= 2n)
2751
- l += 1n;
2752
- const c1 = l;
2753
- const c2 = (q - 1n) / 2n ** c1;
2754
- const c3 = (c2 - 1n) / 2n;
2755
- const c4 = 2n ** c1 - 1n;
2756
- const c5 = 2n ** (c1 - 1n);
2757
- const c6 = Fp2.pow(Z, c2);
2758
- const c7 = Fp2.pow(Z, (c2 + 1n) / 2n);
2759
- let sqrtRatio = (u, v) => {
2760
- let tv1 = c6;
2761
- let tv2 = Fp2.pow(v, c4);
2762
- let tv3 = Fp2.sqr(tv2);
2763
- tv3 = Fp2.mul(tv3, v);
2764
- let tv5 = Fp2.mul(u, tv3);
2765
- tv5 = Fp2.pow(tv5, c3);
2766
- tv5 = Fp2.mul(tv5, tv2);
2767
- tv2 = Fp2.mul(tv5, v);
2768
- tv3 = Fp2.mul(tv5, u);
2769
- let tv4 = Fp2.mul(tv3, tv2);
2770
- tv5 = Fp2.pow(tv4, c5);
2771
- let isQR = Fp2.eql(tv5, Fp2.ONE);
2772
- tv2 = Fp2.mul(tv3, c7);
2773
- tv5 = Fp2.mul(tv4, tv1);
2774
- tv3 = Fp2.cmov(tv2, tv3, isQR);
2775
- tv4 = Fp2.cmov(tv5, tv4, isQR);
2776
- for (let i = c1; i > 1; i--) {
2777
- let tv52 = 2n ** (i - 2n);
2778
- let tvv5 = Fp2.pow(tv4, tv52);
2779
- const e1 = Fp2.eql(tvv5, Fp2.ONE);
2780
- tv2 = Fp2.mul(tv3, tv1);
2781
- tv1 = Fp2.mul(tv1, tv1);
2782
- tvv5 = Fp2.mul(tv4, tv1);
2783
- tv3 = Fp2.cmov(tv2, tv3, e1);
2784
- tv4 = Fp2.cmov(tvv5, tv4, e1);
2785
- }
2786
- return { isValid: isQR, value: tv3 };
2787
- };
2788
- if (Fp2.ORDER % 4n === 3n) {
2789
- const c12 = (Fp2.ORDER - 3n) / 4n;
2790
- const c22 = Fp2.sqrt(Fp2.neg(Z));
2791
- sqrtRatio = (u, v) => {
2792
- let tv1 = Fp2.sqr(v);
2793
- const tv2 = Fp2.mul(u, v);
2794
- tv1 = Fp2.mul(tv1, tv2);
2795
- let y1 = Fp2.pow(tv1, c12);
2796
- y1 = Fp2.mul(y1, tv2);
2797
- const y2 = Fp2.mul(y1, c22);
2798
- const tv3 = Fp2.mul(Fp2.sqr(y1), v);
2799
- const isQR = Fp2.eql(tv3, u);
2800
- let y = Fp2.cmov(y2, y1, isQR);
2801
- return { isValid: isQR, value: y };
2802
- };
2803
- }
2804
- return sqrtRatio;
2805
- }
2806
- function mapToCurveSimpleSWU(Fp2, opts) {
2807
- validateField(Fp2);
2808
- if (!Fp2.isValid(opts.A) || !Fp2.isValid(opts.B) || !Fp2.isValid(opts.Z))
2809
- throw new Error("mapToCurveSimpleSWU: invalid opts");
2810
- const sqrtRatio = SWUFpSqrtRatio(Fp2, opts.Z);
2811
- if (!Fp2.isOdd)
2812
- throw new Error("Fp.isOdd is not implemented!");
2813
- return (u) => {
2814
- let tv1, tv2, tv3, tv4, tv5, tv6, x, y;
2815
- tv1 = Fp2.sqr(u);
2816
- tv1 = Fp2.mul(tv1, opts.Z);
2817
- tv2 = Fp2.sqr(tv1);
2818
- tv2 = Fp2.add(tv2, tv1);
2819
- tv3 = Fp2.add(tv2, Fp2.ONE);
2820
- tv3 = Fp2.mul(tv3, opts.B);
2821
- tv4 = Fp2.cmov(opts.Z, Fp2.neg(tv2), !Fp2.eql(tv2, Fp2.ZERO));
2822
- tv4 = Fp2.mul(tv4, opts.A);
2823
- tv2 = Fp2.sqr(tv3);
2824
- tv6 = Fp2.sqr(tv4);
2825
- tv5 = Fp2.mul(tv6, opts.A);
2826
- tv2 = Fp2.add(tv2, tv5);
2827
- tv2 = Fp2.mul(tv2, tv3);
2828
- tv6 = Fp2.mul(tv6, tv4);
2829
- tv5 = Fp2.mul(tv6, opts.B);
2830
- tv2 = Fp2.add(tv2, tv5);
2831
- x = Fp2.mul(tv1, tv3);
2832
- const { isValid, value } = sqrtRatio(tv2, tv6);
2833
- y = Fp2.mul(tv1, u);
2834
- y = Fp2.mul(y, value);
2835
- x = Fp2.cmov(x, tv3, isValid);
2836
- y = Fp2.cmov(y, value, isValid);
2837
- const e1 = Fp2.isOdd(u) === Fp2.isOdd(y);
2838
- y = Fp2.cmov(Fp2.neg(y), y, e1);
2839
- x = Fp2.div(x, tv4);
2840
- return { x, y };
2841
- };
2842
- }
2843
2737
 
2844
- // node_modules/@noble/hashes/esm/hmac.js
2738
+ // node_modules/micro-starknet/node_modules/@noble/hashes/esm/hmac.js
2845
2739
  var HMAC = class extends Hash {
2846
2740
  constructor(hash2, _key) {
2847
2741
  super();
@@ -2906,7 +2800,7 @@ var starknet = (() => {
2906
2800
  var hmac = (hash2, key, message) => new HMAC(hash2, key).update(message).digest();
2907
2801
  hmac.create = (hash2, key) => new HMAC(hash2, key);
2908
2802
 
2909
- // node_modules/@noble/curves/esm/_shortw_utils.js
2803
+ // node_modules/micro-starknet/node_modules/@noble/curves/esm/_shortw_utils.js
2910
2804
  function getHash(hash2) {
2911
2805
  return {
2912
2806
  hash: hash2,
@@ -2936,7 +2830,7 @@ var starknet = (() => {
2936
2830
  var curve = weierstrass({
2937
2831
  a: BigInt(1),
2938
2832
  b: BigInt("3141592653589793238462643383279502884197169399375105820974944592307816406665"),
2939
- Fp: Fp(BigInt("0x800000000000011000000000000000000000000000000000000000000000001")),
2833
+ Fp: Field(BigInt("0x800000000000011000000000000000000000000000000000000000000000001")),
2940
2834
  n: CURVE_ORDER,
2941
2835
  nBitLength,
2942
2836
  Gx: BigInt("874739451078007766457464989774322083649278607533249481151382481072868806602"),
@@ -3080,22 +2974,22 @@ var starknet = (() => {
3080
2974
  var MASK_250 = bitMask(250);
3081
2975
  var keccak = (data) => bytesToNumberBE(keccak_256(data)) & MASK_250;
3082
2976
  var sha256Num = (data) => bytesToNumberBE(sha256(data));
3083
- var Fp253 = Fp(BigInt("14474011154664525231415395255581126252639794253786371766033694892385558855681"));
3084
- var Fp251 = Fp(BigInt("3618502788666131213697322783095070105623107215331596699973092056135872020481"));
3085
- function poseidonRoundConstant(Fp2, name, idx) {
3086
- const val = Fp2.fromBytes(sha256(utf8ToBytes(`${name}${idx}`)));
3087
- return Fp2.create(val);
2977
+ var Fp253 = Field(BigInt("14474011154664525231415395255581126252639794253786371766033694892385558855681"));
2978
+ var Fp251 = Field(BigInt("3618502788666131213697322783095070105623107215331596699973092056135872020481"));
2979
+ function poseidonRoundConstant(Fp, name, idx) {
2980
+ const val = Fp.fromBytes(sha256(utf8ToBytes(`${name}${idx}`)));
2981
+ return Fp.create(val);
3088
2982
  }
3089
- function _poseidonMDS(Fp2, name, m, attempt = 0) {
2983
+ function _poseidonMDS(Fp, name, m, attempt = 0) {
3090
2984
  const x_values = [];
3091
2985
  const y_values = [];
3092
2986
  for (let i = 0; i < m; i++) {
3093
- x_values.push(poseidonRoundConstant(Fp2, `${name}x`, attempt * m + i));
3094
- y_values.push(poseidonRoundConstant(Fp2, `${name}y`, attempt * m + i));
2987
+ x_values.push(poseidonRoundConstant(Fp, `${name}x`, attempt * m + i));
2988
+ y_values.push(poseidonRoundConstant(Fp, `${name}y`, attempt * m + i));
3095
2989
  }
3096
2990
  if ((/* @__PURE__ */ new Set([...x_values, ...y_values])).size !== 2 * m)
3097
2991
  throw new Error("X and Y values are not distinct");
3098
- return x_values.map((x) => y_values.map((y) => Fp2.inv(Fp2.sub(x, y))));
2992
+ return x_values.map((x) => y_values.map((y) => Fp.inv(Fp.sub(x, y))));
3099
2993
  }
3100
2994
  var MDS_SMALL = [
3101
2995
  [3, 1, 1],
@@ -5347,7 +5241,7 @@ var starknet = (() => {
5347
5241
  getDecimalString: () => getDecimalString,
5348
5242
  getHexString: () => getHexString,
5349
5243
  getHexStringArray: () => getHexStringArray,
5350
- hexToBytes: () => hexToBytes2,
5244
+ hexToBytes: () => hexToBytes3,
5351
5245
  hexToDecimalString: () => hexToDecimalString,
5352
5246
  isBigInt: () => isBigInt,
5353
5247
  isHex: () => isHex,
@@ -5357,6 +5251,212 @@ var starknet = (() => {
5357
5251
  toHex: () => toHex,
5358
5252
  toHexString: () => toHexString
5359
5253
  });
5254
+
5255
+ // node_modules/@noble/curves/esm/abstract/utils.js
5256
+ var utils_exports2 = {};
5257
+ __export(utils_exports2, {
5258
+ bitGet: () => bitGet2,
5259
+ bitLen: () => bitLen2,
5260
+ bitMask: () => bitMask2,
5261
+ bitSet: () => bitSet2,
5262
+ bytesToHex: () => bytesToHex2,
5263
+ bytesToNumberBE: () => bytesToNumberBE2,
5264
+ bytesToNumberLE: () => bytesToNumberLE2,
5265
+ concatBytes: () => concatBytes3,
5266
+ createHmacDrbg: () => createHmacDrbg2,
5267
+ ensureBytes: () => ensureBytes3,
5268
+ equalBytes: () => equalBytes2,
5269
+ hexToBytes: () => hexToBytes2,
5270
+ hexToNumber: () => hexToNumber2,
5271
+ numberToBytesBE: () => numberToBytesBE2,
5272
+ numberToBytesLE: () => numberToBytesLE2,
5273
+ numberToHexUnpadded: () => numberToHexUnpadded2,
5274
+ numberToVarBytesBE: () => numberToVarBytesBE2,
5275
+ utf8ToBytes: () => utf8ToBytes3,
5276
+ validateObject: () => validateObject2
5277
+ });
5278
+ var _0n6 = BigInt(0);
5279
+ var _1n6 = BigInt(1);
5280
+ var _2n5 = BigInt(2);
5281
+ var u8a2 = (a) => a instanceof Uint8Array;
5282
+ var hexes3 = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, "0"));
5283
+ function bytesToHex2(bytes2) {
5284
+ if (!u8a2(bytes2))
5285
+ throw new Error("Uint8Array expected");
5286
+ let hex = "";
5287
+ for (let i = 0; i < bytes2.length; i++) {
5288
+ hex += hexes3[bytes2[i]];
5289
+ }
5290
+ return hex;
5291
+ }
5292
+ function numberToHexUnpadded2(num) {
5293
+ const hex = num.toString(16);
5294
+ return hex.length & 1 ? `0${hex}` : hex;
5295
+ }
5296
+ function hexToNumber2(hex) {
5297
+ if (typeof hex !== "string")
5298
+ throw new Error("hex string expected, got " + typeof hex);
5299
+ return BigInt(hex === "" ? "0" : `0x${hex}`);
5300
+ }
5301
+ function hexToBytes2(hex) {
5302
+ if (typeof hex !== "string")
5303
+ throw new Error("hex string expected, got " + typeof hex);
5304
+ if (hex.length % 2)
5305
+ throw new Error("hex string is invalid: unpadded " + hex.length);
5306
+ const array = new Uint8Array(hex.length / 2);
5307
+ for (let i = 0; i < array.length; i++) {
5308
+ const j = i * 2;
5309
+ const hexByte = hex.slice(j, j + 2);
5310
+ const byte = Number.parseInt(hexByte, 16);
5311
+ if (Number.isNaN(byte) || byte < 0)
5312
+ throw new Error("invalid byte sequence");
5313
+ array[i] = byte;
5314
+ }
5315
+ return array;
5316
+ }
5317
+ function bytesToNumberBE2(bytes2) {
5318
+ return hexToNumber2(bytesToHex2(bytes2));
5319
+ }
5320
+ function bytesToNumberLE2(bytes2) {
5321
+ if (!u8a2(bytes2))
5322
+ throw new Error("Uint8Array expected");
5323
+ return hexToNumber2(bytesToHex2(Uint8Array.from(bytes2).reverse()));
5324
+ }
5325
+ var numberToBytesBE2 = (n, len) => hexToBytes2(n.toString(16).padStart(len * 2, "0"));
5326
+ var numberToBytesLE2 = (n, len) => numberToBytesBE2(n, len).reverse();
5327
+ var numberToVarBytesBE2 = (n) => hexToBytes2(numberToHexUnpadded2(n));
5328
+ function ensureBytes3(title, hex, expectedLength) {
5329
+ let res;
5330
+ if (typeof hex === "string") {
5331
+ try {
5332
+ res = hexToBytes2(hex);
5333
+ } catch (e) {
5334
+ throw new Error(`${title} must be valid hex string, got "${hex}". Cause: ${e}`);
5335
+ }
5336
+ } else if (u8a2(hex)) {
5337
+ res = Uint8Array.from(hex);
5338
+ } else {
5339
+ throw new Error(`${title} must be hex string or Uint8Array`);
5340
+ }
5341
+ const len = res.length;
5342
+ if (typeof expectedLength === "number" && len !== expectedLength)
5343
+ throw new Error(`${title} expected ${expectedLength} bytes, got ${len}`);
5344
+ return res;
5345
+ }
5346
+ function concatBytes3(...arrs) {
5347
+ const r = new Uint8Array(arrs.reduce((sum, a) => sum + a.length, 0));
5348
+ let pad = 0;
5349
+ arrs.forEach((a) => {
5350
+ if (!u8a2(a))
5351
+ throw new Error("Uint8Array expected");
5352
+ r.set(a, pad);
5353
+ pad += a.length;
5354
+ });
5355
+ return r;
5356
+ }
5357
+ function equalBytes2(b1, b2) {
5358
+ if (b1.length !== b2.length)
5359
+ return false;
5360
+ for (let i = 0; i < b1.length; i++)
5361
+ if (b1[i] !== b2[i])
5362
+ return false;
5363
+ return true;
5364
+ }
5365
+ function utf8ToBytes3(str) {
5366
+ if (typeof str !== "string") {
5367
+ throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
5368
+ }
5369
+ return new TextEncoder().encode(str);
5370
+ }
5371
+ function bitLen2(n) {
5372
+ let len;
5373
+ for (len = 0; n > 0n; n >>= _1n6, len += 1)
5374
+ ;
5375
+ return len;
5376
+ }
5377
+ var bitGet2 = (n, pos) => n >> BigInt(pos) & 1n;
5378
+ var bitSet2 = (n, pos, value) => n | (value ? _1n6 : _0n6) << BigInt(pos);
5379
+ var bitMask2 = (n) => (_2n5 << BigInt(n - 1)) - _1n6;
5380
+ var u8n2 = (data) => new Uint8Array(data);
5381
+ var u8fr2 = (arr) => Uint8Array.from(arr);
5382
+ function createHmacDrbg2(hashLen, qByteLen, hmacFn) {
5383
+ if (typeof hashLen !== "number" || hashLen < 2)
5384
+ throw new Error("hashLen must be a number");
5385
+ if (typeof qByteLen !== "number" || qByteLen < 2)
5386
+ throw new Error("qByteLen must be a number");
5387
+ if (typeof hmacFn !== "function")
5388
+ throw new Error("hmacFn must be a function");
5389
+ let v = u8n2(hashLen);
5390
+ let k = u8n2(hashLen);
5391
+ let i = 0;
5392
+ const reset = () => {
5393
+ v.fill(1);
5394
+ k.fill(0);
5395
+ i = 0;
5396
+ };
5397
+ const h = (...b) => hmacFn(k, v, ...b);
5398
+ const reseed = (seed = u8n2()) => {
5399
+ k = h(u8fr2([0]), seed);
5400
+ v = h();
5401
+ if (seed.length === 0)
5402
+ return;
5403
+ k = h(u8fr2([1]), seed);
5404
+ v = h();
5405
+ };
5406
+ const gen2 = () => {
5407
+ if (i++ >= 1e3)
5408
+ throw new Error("drbg: tried 1000 values");
5409
+ let len = 0;
5410
+ const out = [];
5411
+ while (len < qByteLen) {
5412
+ v = h();
5413
+ const sl = v.slice();
5414
+ out.push(sl);
5415
+ len += v.length;
5416
+ }
5417
+ return concatBytes3(...out);
5418
+ };
5419
+ const genUntil = (seed, pred) => {
5420
+ reset();
5421
+ reseed(seed);
5422
+ let res = void 0;
5423
+ while (!(res = pred(gen2())))
5424
+ reseed();
5425
+ reset();
5426
+ return res;
5427
+ };
5428
+ return genUntil;
5429
+ }
5430
+ var validatorFns2 = {
5431
+ bigint: (val) => typeof val === "bigint",
5432
+ function: (val) => typeof val === "function",
5433
+ boolean: (val) => typeof val === "boolean",
5434
+ string: (val) => typeof val === "string",
5435
+ isSafeInteger: (val) => Number.isSafeInteger(val),
5436
+ array: (val) => Array.isArray(val),
5437
+ field: (val, object) => object.Fp.isValid(val),
5438
+ hash: (val) => typeof val === "function" && Number.isSafeInteger(val.outputLen)
5439
+ };
5440
+ function validateObject2(object, validators, optValidators = {}) {
5441
+ const checkField = (fieldName, type, isOptional) => {
5442
+ const checkVal = validatorFns2[type];
5443
+ if (typeof checkVal !== "function")
5444
+ throw new Error(`Invalid validator "${type}", expected function`);
5445
+ const val = object[fieldName];
5446
+ if (isOptional && val === void 0)
5447
+ return;
5448
+ if (!checkVal(val, object)) {
5449
+ throw new Error(`Invalid param ${String(fieldName)}=${val} (${typeof val}), expected ${type}`);
5450
+ }
5451
+ };
5452
+ for (const [fieldName, type] of Object.entries(validators))
5453
+ checkField(fieldName, type, false);
5454
+ for (const [fieldName, type] of Object.entries(optValidators))
5455
+ checkField(fieldName, type, true);
5456
+ return object;
5457
+ }
5458
+
5459
+ // src/utils/num.ts
5360
5460
  function isHex(hex) {
5361
5461
  return /^0x[0-9a-f]*$/i.test(hex);
5362
5462
  }
@@ -5413,14 +5513,14 @@ var starknet = (() => {
5413
5513
  return value.map((el) => getHexString(el));
5414
5514
  }
5415
5515
  var toCairoBool = (value) => (+value).toString();
5416
- function hexToBytes2(value) {
5516
+ function hexToBytes3(value) {
5417
5517
  if (!isHex(value))
5418
5518
  throw new Error(`${value} need to be a hex-string`);
5419
5519
  let adaptedValue = removeHexPrefix(value);
5420
5520
  if (adaptedValue.length % 2 !== 0) {
5421
5521
  adaptedValue = `0${adaptedValue}`;
5422
5522
  }
5423
- return hexToBytes(adaptedValue);
5523
+ return hexToBytes2(adaptedValue);
5424
5524
  }
5425
5525
 
5426
5526
  // src/utils/shortString.ts
@@ -5569,35 +5669,1038 @@ var starknet = (() => {
5569
5669
  weierstrass: () => weierstrass_exports
5570
5670
  });
5571
5671
 
5572
- // src/utils/json.ts
5573
- var json_exports = {};
5574
- __export(json_exports, {
5575
- parse: () => parse2,
5576
- parseAlwaysAsBig: () => parseAlwaysAsBig,
5577
- stringify: () => stringify2,
5578
- stringifyAlwaysAsBig: () => stringifyAlwaysAsBig
5672
+ // node_modules/@noble/curves/esm/abstract/weierstrass.js
5673
+ var weierstrass_exports = {};
5674
+ __export(weierstrass_exports, {
5675
+ SWUFpSqrtRatio: () => SWUFpSqrtRatio,
5676
+ mapToCurveSimpleSWU: () => mapToCurveSimpleSWU,
5677
+ weierstrass: () => weierstrass2,
5678
+ weierstrassPoints: () => weierstrassPoints2
5579
5679
  });
5580
5680
 
5581
- // node_modules/lossless-json/lib/esm/utils.js
5582
- function isInteger(value) {
5583
- return INTEGER_REGEX.test(value);
5584
- }
5585
- var INTEGER_REGEX = /^-?[0-9]+$/;
5586
- function isNumber(value) {
5587
- return NUMBER_REGEX.test(value);
5681
+ // node_modules/@noble/curves/esm/abstract/modular.js
5682
+ var _0n7 = BigInt(0);
5683
+ var _1n7 = BigInt(1);
5684
+ var _2n6 = BigInt(2);
5685
+ var _3n3 = BigInt(3);
5686
+ var _4n3 = BigInt(4);
5687
+ var _5n2 = BigInt(5);
5688
+ var _8n2 = BigInt(8);
5689
+ var _9n2 = BigInt(9);
5690
+ var _16n2 = BigInt(16);
5691
+ function mod2(a, b) {
5692
+ const result = a % b;
5693
+ return result >= _0n7 ? result : b + result;
5588
5694
  }
5589
- var NUMBER_REGEX = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
5590
- function isSafeNumber(value, config) {
5591
- var num = parseFloat(value);
5592
- var str = String(num);
5593
- var v = extractSignificantDigits(value);
5594
- var s = extractSignificantDigits(str);
5595
- if (v === s) {
5596
- return true;
5695
+ function invert2(number3, modulo) {
5696
+ if (number3 === _0n7 || modulo <= _0n7) {
5697
+ throw new Error(`invert: expected positive integers, got n=${number3} mod=${modulo}`);
5597
5698
  }
5598
- if ((config === null || config === void 0 ? void 0 : config.approx) === true) {
5599
- var requiredDigits = 14;
5600
- if (!isInteger(value) && s.length >= requiredDigits && v.startsWith(s.substring(0, requiredDigits))) {
5699
+ let a = mod2(number3, modulo);
5700
+ let b = modulo;
5701
+ let x = _0n7, y = _1n7, u = _1n7, v = _0n7;
5702
+ while (a !== _0n7) {
5703
+ const q = b / a;
5704
+ const r = b % a;
5705
+ const m = x - u * q;
5706
+ const n = y - v * q;
5707
+ b = a, a = r, x = u, y = v, u = m, v = n;
5708
+ }
5709
+ const gcd = b;
5710
+ if (gcd !== _1n7)
5711
+ throw new Error("invert: does not exist");
5712
+ return mod2(x, modulo);
5713
+ }
5714
+ var FIELD_FIELDS2 = [
5715
+ "create",
5716
+ "isValid",
5717
+ "is0",
5718
+ "neg",
5719
+ "inv",
5720
+ "sqrt",
5721
+ "sqr",
5722
+ "eql",
5723
+ "add",
5724
+ "sub",
5725
+ "mul",
5726
+ "pow",
5727
+ "div",
5728
+ "addN",
5729
+ "subN",
5730
+ "mulN",
5731
+ "sqrN"
5732
+ ];
5733
+ function validateField2(field) {
5734
+ const initial = {
5735
+ ORDER: "bigint",
5736
+ MASK: "bigint",
5737
+ BYTES: "isSafeInteger",
5738
+ BITS: "isSafeInteger"
5739
+ };
5740
+ const opts = FIELD_FIELDS2.reduce((map, val) => {
5741
+ map[val] = "function";
5742
+ return map;
5743
+ }, initial);
5744
+ return validateObject2(field, opts);
5745
+ }
5746
+ function FpPow2(f, num, power) {
5747
+ if (power < _0n7)
5748
+ throw new Error("Expected power > 0");
5749
+ if (power === _0n7)
5750
+ return f.ONE;
5751
+ if (power === _1n7)
5752
+ return num;
5753
+ let p = f.ONE;
5754
+ let d = num;
5755
+ while (power > _0n7) {
5756
+ if (power & _1n7)
5757
+ p = f.mul(p, d);
5758
+ d = f.sqr(d);
5759
+ power >>= 1n;
5760
+ }
5761
+ return p;
5762
+ }
5763
+ function nLength2(n, nBitLength2) {
5764
+ const _nBitLength = nBitLength2 !== void 0 ? nBitLength2 : n.toString(2).length;
5765
+ const nByteLength = Math.ceil(_nBitLength / 8);
5766
+ return { nBitLength: _nBitLength, nByteLength };
5767
+ }
5768
+ function hashToPrivateScalar2(hash2, groupOrder, isLE2 = false) {
5769
+ hash2 = ensureBytes3("privateHash", hash2);
5770
+ const hashLen = hash2.length;
5771
+ const minLen = nLength2(groupOrder).nByteLength + 8;
5772
+ if (minLen < 24 || hashLen < minLen || hashLen > 1024)
5773
+ throw new Error(`hashToPrivateScalar: expected ${minLen}-1024 bytes of input, got ${hashLen}`);
5774
+ const num = isLE2 ? bytesToNumberLE2(hash2) : bytesToNumberBE2(hash2);
5775
+ return mod2(num, groupOrder - _1n7) + _1n7;
5776
+ }
5777
+
5778
+ // node_modules/@noble/curves/esm/abstract/curve.js
5779
+ var _0n8 = BigInt(0);
5780
+ var _1n8 = BigInt(1);
5781
+ function wNAF2(c, bits) {
5782
+ const constTimeNegate = (condition, item) => {
5783
+ const neg = item.negate();
5784
+ return condition ? neg : item;
5785
+ };
5786
+ const opts = (W) => {
5787
+ const windows = Math.ceil(bits / W) + 1;
5788
+ const windowSize = 2 ** (W - 1);
5789
+ return { windows, windowSize };
5790
+ };
5791
+ return {
5792
+ constTimeNegate,
5793
+ unsafeLadder(elm, n) {
5794
+ let p = c.ZERO;
5795
+ let d = elm;
5796
+ while (n > _0n8) {
5797
+ if (n & _1n8)
5798
+ p = p.add(d);
5799
+ d = d.double();
5800
+ n >>= _1n8;
5801
+ }
5802
+ return p;
5803
+ },
5804
+ precomputeWindow(elm, W) {
5805
+ const { windows, windowSize } = opts(W);
5806
+ const points = [];
5807
+ let p = elm;
5808
+ let base = p;
5809
+ for (let window2 = 0; window2 < windows; window2++) {
5810
+ base = p;
5811
+ points.push(base);
5812
+ for (let i = 1; i < windowSize; i++) {
5813
+ base = base.add(p);
5814
+ points.push(base);
5815
+ }
5816
+ p = base.double();
5817
+ }
5818
+ return points;
5819
+ },
5820
+ wNAF(W, precomputes, n) {
5821
+ const { windows, windowSize } = opts(W);
5822
+ let p = c.ZERO;
5823
+ let f = c.BASE;
5824
+ const mask = BigInt(2 ** W - 1);
5825
+ const maxNumber = 2 ** W;
5826
+ const shiftBy = BigInt(W);
5827
+ for (let window2 = 0; window2 < windows; window2++) {
5828
+ const offset = window2 * windowSize;
5829
+ let wbits = Number(n & mask);
5830
+ n >>= shiftBy;
5831
+ if (wbits > windowSize) {
5832
+ wbits -= maxNumber;
5833
+ n += _1n8;
5834
+ }
5835
+ const offset1 = offset;
5836
+ const offset2 = offset + Math.abs(wbits) - 1;
5837
+ const cond1 = window2 % 2 !== 0;
5838
+ const cond2 = wbits < 0;
5839
+ if (wbits === 0) {
5840
+ f = f.add(constTimeNegate(cond1, precomputes[offset1]));
5841
+ } else {
5842
+ p = p.add(constTimeNegate(cond2, precomputes[offset2]));
5843
+ }
5844
+ }
5845
+ return { p, f };
5846
+ },
5847
+ wNAFCached(P, precomputesMap, n, transform) {
5848
+ const W = P._WINDOW_SIZE || 1;
5849
+ let comp = precomputesMap.get(P);
5850
+ if (!comp) {
5851
+ comp = this.precomputeWindow(P, W);
5852
+ if (W !== 1) {
5853
+ precomputesMap.set(P, transform(comp));
5854
+ }
5855
+ }
5856
+ return this.wNAF(W, comp, n);
5857
+ }
5858
+ };
5859
+ }
5860
+ function validateBasic2(curve2) {
5861
+ validateField2(curve2.Fp);
5862
+ validateObject2(curve2, {
5863
+ n: "bigint",
5864
+ h: "bigint",
5865
+ Gx: "field",
5866
+ Gy: "field"
5867
+ }, {
5868
+ nBitLength: "isSafeInteger",
5869
+ nByteLength: "isSafeInteger"
5870
+ });
5871
+ return Object.freeze({ ...nLength2(curve2.n, curve2.nBitLength), ...curve2 });
5872
+ }
5873
+
5874
+ // node_modules/@noble/curves/esm/abstract/weierstrass.js
5875
+ function validatePointOpts2(curve2) {
5876
+ const opts = validateBasic2(curve2);
5877
+ validateObject2(opts, {
5878
+ a: "field",
5879
+ b: "field",
5880
+ fromBytes: "function",
5881
+ toBytes: "function"
5882
+ }, {
5883
+ allowedPrivateKeyLengths: "array",
5884
+ wrapPrivateKey: "boolean",
5885
+ isTorsionFree: "function",
5886
+ clearCofactor: "function",
5887
+ allowInfinityPoint: "boolean"
5888
+ });
5889
+ const { endo, Fp, a } = opts;
5890
+ if (endo) {
5891
+ if (!Fp.eql(a, Fp.ZERO)) {
5892
+ throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");
5893
+ }
5894
+ if (typeof endo !== "object" || typeof endo.beta !== "bigint" || typeof endo.splitScalar !== "function") {
5895
+ throw new Error("Expected endomorphism with beta: bigint and splitScalar: function");
5896
+ }
5897
+ }
5898
+ return Object.freeze({ ...opts });
5899
+ }
5900
+ var { bytesToNumberBE: b2n2, hexToBytes: h2b2 } = utils_exports2;
5901
+ var DER2 = {
5902
+ Err: class DERErr2 extends Error {
5903
+ constructor(m = "") {
5904
+ super(m);
5905
+ }
5906
+ },
5907
+ _parseInt(data) {
5908
+ const { Err: E } = DER2;
5909
+ if (data.length < 2 || data[0] !== 2)
5910
+ throw new E("Invalid signature integer tag");
5911
+ const len = data[1];
5912
+ const res = data.subarray(2, len + 2);
5913
+ if (!len || res.length !== len)
5914
+ throw new E("Invalid signature integer: wrong length");
5915
+ if (res[0] === 0 && res[1] <= 127)
5916
+ throw new E("Invalid signature integer: trailing length");
5917
+ return { d: b2n2(res), l: data.subarray(len + 2) };
5918
+ },
5919
+ toSig(hex) {
5920
+ const { Err: E } = DER2;
5921
+ const data = typeof hex === "string" ? h2b2(hex) : hex;
5922
+ if (!(data instanceof Uint8Array))
5923
+ throw new Error("ui8a expected");
5924
+ let l = data.length;
5925
+ if (l < 2 || data[0] != 48)
5926
+ throw new E("Invalid signature tag");
5927
+ if (data[1] !== l - 2)
5928
+ throw new E("Invalid signature: incorrect length");
5929
+ const { d: r, l: sBytes } = DER2._parseInt(data.subarray(2));
5930
+ const { d: s, l: rBytesLeft } = DER2._parseInt(sBytes);
5931
+ if (rBytesLeft.length)
5932
+ throw new E("Invalid signature: left bytes after parsing");
5933
+ return { r, s };
5934
+ },
5935
+ hexFromSig(sig) {
5936
+ const slice = (s2) => Number.parseInt(s2[0], 16) >= 8 ? "00" + s2 : s2;
5937
+ const h = (num) => {
5938
+ const hex = num.toString(16);
5939
+ return hex.length & 1 ? `0${hex}` : hex;
5940
+ };
5941
+ const s = slice(h(sig.s));
5942
+ const r = slice(h(sig.r));
5943
+ const shl = s.length / 2;
5944
+ const rhl = r.length / 2;
5945
+ const sl = h(shl);
5946
+ const rl = h(rhl);
5947
+ return `30${h(rhl + shl + 4)}02${rl}${r}02${sl}${s}`;
5948
+ }
5949
+ };
5950
+ var _0n9 = BigInt(0);
5951
+ var _1n9 = BigInt(1);
5952
+ function weierstrassPoints2(opts) {
5953
+ const CURVE2 = validatePointOpts2(opts);
5954
+ const { Fp } = CURVE2;
5955
+ function weierstrassEquation(x) {
5956
+ const { a, b } = CURVE2;
5957
+ const x2 = Fp.sqr(x);
5958
+ const x3 = Fp.mul(x2, x);
5959
+ return Fp.add(Fp.add(x3, Fp.mul(x, a)), b);
5960
+ }
5961
+ function isWithinCurveOrder(num) {
5962
+ return typeof num === "bigint" && _0n9 < num && num < CURVE2.n;
5963
+ }
5964
+ function assertGE(num) {
5965
+ if (!isWithinCurveOrder(num))
5966
+ throw new Error("Expected valid bigint: 0 < bigint < curve.n");
5967
+ }
5968
+ function normPrivateKeyToScalar(key) {
5969
+ const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n } = CURVE2;
5970
+ if (lengths && typeof key !== "bigint") {
5971
+ if (key instanceof Uint8Array)
5972
+ key = bytesToHex2(key);
5973
+ if (typeof key !== "string" || !lengths.includes(key.length))
5974
+ throw new Error("Invalid key");
5975
+ key = key.padStart(nByteLength * 2, "0");
5976
+ }
5977
+ let num;
5978
+ try {
5979
+ num = typeof key === "bigint" ? key : bytesToNumberBE2(ensureBytes3("private key", key, nByteLength));
5980
+ } catch (error) {
5981
+ throw new Error(`private key must be ${nByteLength} bytes, hex or bigint, not ${typeof key}`);
5982
+ }
5983
+ if (wrapPrivateKey)
5984
+ num = mod2(num, n);
5985
+ assertGE(num);
5986
+ return num;
5987
+ }
5988
+ const pointPrecomputes = /* @__PURE__ */ new Map();
5989
+ function assertPrjPoint(other) {
5990
+ if (!(other instanceof Point))
5991
+ throw new Error("ProjectivePoint expected");
5992
+ }
5993
+ class Point {
5994
+ constructor(px, py, pz) {
5995
+ this.px = px;
5996
+ this.py = py;
5997
+ this.pz = pz;
5998
+ if (px == null || !Fp.isValid(px))
5999
+ throw new Error("x required");
6000
+ if (py == null || !Fp.isValid(py))
6001
+ throw new Error("y required");
6002
+ if (pz == null || !Fp.isValid(pz))
6003
+ throw new Error("z required");
6004
+ }
6005
+ static fromAffine(p) {
6006
+ const { x, y } = p || {};
6007
+ if (!p || !Fp.isValid(x) || !Fp.isValid(y))
6008
+ throw new Error("invalid affine point");
6009
+ if (p instanceof Point)
6010
+ throw new Error("projective point not allowed");
6011
+ const is0 = (i) => Fp.eql(i, Fp.ZERO);
6012
+ if (is0(x) && is0(y))
6013
+ return Point.ZERO;
6014
+ return new Point(x, y, Fp.ONE);
6015
+ }
6016
+ get x() {
6017
+ return this.toAffine().x;
6018
+ }
6019
+ get y() {
6020
+ return this.toAffine().y;
6021
+ }
6022
+ static normalizeZ(points) {
6023
+ const toInv = Fp.invertBatch(points.map((p) => p.pz));
6024
+ return points.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
6025
+ }
6026
+ static fromHex(hex) {
6027
+ const P = Point.fromAffine(CURVE2.fromBytes(ensureBytes3("pointHex", hex)));
6028
+ P.assertValidity();
6029
+ return P;
6030
+ }
6031
+ static fromPrivateKey(privateKey) {
6032
+ return Point.BASE.multiply(normPrivateKeyToScalar(privateKey));
6033
+ }
6034
+ _setWindowSize(windowSize) {
6035
+ this._WINDOW_SIZE = windowSize;
6036
+ pointPrecomputes.delete(this);
6037
+ }
6038
+ assertValidity() {
6039
+ if (this.is0()) {
6040
+ if (CURVE2.allowInfinityPoint)
6041
+ return;
6042
+ throw new Error("bad point: ZERO");
6043
+ }
6044
+ const { x, y } = this.toAffine();
6045
+ if (!Fp.isValid(x) || !Fp.isValid(y))
6046
+ throw new Error("bad point: x or y not FE");
6047
+ const left = Fp.sqr(y);
6048
+ const right = weierstrassEquation(x);
6049
+ if (!Fp.eql(left, right))
6050
+ throw new Error("bad point: equation left != right");
6051
+ if (!this.isTorsionFree())
6052
+ throw new Error("bad point: not in prime-order subgroup");
6053
+ }
6054
+ hasEvenY() {
6055
+ const { y } = this.toAffine();
6056
+ if (Fp.isOdd)
6057
+ return !Fp.isOdd(y);
6058
+ throw new Error("Field doesn't support isOdd");
6059
+ }
6060
+ equals(other) {
6061
+ assertPrjPoint(other);
6062
+ const { px: X1, py: Y1, pz: Z1 } = this;
6063
+ const { px: X2, py: Y2, pz: Z2 } = other;
6064
+ const U1 = Fp.eql(Fp.mul(X1, Z2), Fp.mul(X2, Z1));
6065
+ const U2 = Fp.eql(Fp.mul(Y1, Z2), Fp.mul(Y2, Z1));
6066
+ return U1 && U2;
6067
+ }
6068
+ negate() {
6069
+ return new Point(this.px, Fp.neg(this.py), this.pz);
6070
+ }
6071
+ double() {
6072
+ const { a, b } = CURVE2;
6073
+ const b3 = Fp.mul(b, 3n);
6074
+ const { px: X1, py: Y1, pz: Z1 } = this;
6075
+ let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO;
6076
+ let t0 = Fp.mul(X1, X1);
6077
+ let t1 = Fp.mul(Y1, Y1);
6078
+ let t2 = Fp.mul(Z1, Z1);
6079
+ let t3 = Fp.mul(X1, Y1);
6080
+ t3 = Fp.add(t3, t3);
6081
+ Z3 = Fp.mul(X1, Z1);
6082
+ Z3 = Fp.add(Z3, Z3);
6083
+ X3 = Fp.mul(a, Z3);
6084
+ Y3 = Fp.mul(b3, t2);
6085
+ Y3 = Fp.add(X3, Y3);
6086
+ X3 = Fp.sub(t1, Y3);
6087
+ Y3 = Fp.add(t1, Y3);
6088
+ Y3 = Fp.mul(X3, Y3);
6089
+ X3 = Fp.mul(t3, X3);
6090
+ Z3 = Fp.mul(b3, Z3);
6091
+ t2 = Fp.mul(a, t2);
6092
+ t3 = Fp.sub(t0, t2);
6093
+ t3 = Fp.mul(a, t3);
6094
+ t3 = Fp.add(t3, Z3);
6095
+ Z3 = Fp.add(t0, t0);
6096
+ t0 = Fp.add(Z3, t0);
6097
+ t0 = Fp.add(t0, t2);
6098
+ t0 = Fp.mul(t0, t3);
6099
+ Y3 = Fp.add(Y3, t0);
6100
+ t2 = Fp.mul(Y1, Z1);
6101
+ t2 = Fp.add(t2, t2);
6102
+ t0 = Fp.mul(t2, t3);
6103
+ X3 = Fp.sub(X3, t0);
6104
+ Z3 = Fp.mul(t2, t1);
6105
+ Z3 = Fp.add(Z3, Z3);
6106
+ Z3 = Fp.add(Z3, Z3);
6107
+ return new Point(X3, Y3, Z3);
6108
+ }
6109
+ add(other) {
6110
+ assertPrjPoint(other);
6111
+ const { px: X1, py: Y1, pz: Z1 } = this;
6112
+ const { px: X2, py: Y2, pz: Z2 } = other;
6113
+ let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO;
6114
+ const a = CURVE2.a;
6115
+ const b3 = Fp.mul(CURVE2.b, 3n);
6116
+ let t0 = Fp.mul(X1, X2);
6117
+ let t1 = Fp.mul(Y1, Y2);
6118
+ let t2 = Fp.mul(Z1, Z2);
6119
+ let t3 = Fp.add(X1, Y1);
6120
+ let t4 = Fp.add(X2, Y2);
6121
+ t3 = Fp.mul(t3, t4);
6122
+ t4 = Fp.add(t0, t1);
6123
+ t3 = Fp.sub(t3, t4);
6124
+ t4 = Fp.add(X1, Z1);
6125
+ let t5 = Fp.add(X2, Z2);
6126
+ t4 = Fp.mul(t4, t5);
6127
+ t5 = Fp.add(t0, t2);
6128
+ t4 = Fp.sub(t4, t5);
6129
+ t5 = Fp.add(Y1, Z1);
6130
+ X3 = Fp.add(Y2, Z2);
6131
+ t5 = Fp.mul(t5, X3);
6132
+ X3 = Fp.add(t1, t2);
6133
+ t5 = Fp.sub(t5, X3);
6134
+ Z3 = Fp.mul(a, t4);
6135
+ X3 = Fp.mul(b3, t2);
6136
+ Z3 = Fp.add(X3, Z3);
6137
+ X3 = Fp.sub(t1, Z3);
6138
+ Z3 = Fp.add(t1, Z3);
6139
+ Y3 = Fp.mul(X3, Z3);
6140
+ t1 = Fp.add(t0, t0);
6141
+ t1 = Fp.add(t1, t0);
6142
+ t2 = Fp.mul(a, t2);
6143
+ t4 = Fp.mul(b3, t4);
6144
+ t1 = Fp.add(t1, t2);
6145
+ t2 = Fp.sub(t0, t2);
6146
+ t2 = Fp.mul(a, t2);
6147
+ t4 = Fp.add(t4, t2);
6148
+ t0 = Fp.mul(t1, t4);
6149
+ Y3 = Fp.add(Y3, t0);
6150
+ t0 = Fp.mul(t5, t4);
6151
+ X3 = Fp.mul(t3, X3);
6152
+ X3 = Fp.sub(X3, t0);
6153
+ t0 = Fp.mul(t3, t1);
6154
+ Z3 = Fp.mul(t5, Z3);
6155
+ Z3 = Fp.add(Z3, t0);
6156
+ return new Point(X3, Y3, Z3);
6157
+ }
6158
+ subtract(other) {
6159
+ return this.add(other.negate());
6160
+ }
6161
+ is0() {
6162
+ return this.equals(Point.ZERO);
6163
+ }
6164
+ wNAF(n) {
6165
+ return wnaf.wNAFCached(this, pointPrecomputes, n, (comp) => {
6166
+ const toInv = Fp.invertBatch(comp.map((p) => p.pz));
6167
+ return comp.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
6168
+ });
6169
+ }
6170
+ multiplyUnsafe(n) {
6171
+ const I = Point.ZERO;
6172
+ if (n === _0n9)
6173
+ return I;
6174
+ assertGE(n);
6175
+ if (n === _1n9)
6176
+ return this;
6177
+ const { endo } = CURVE2;
6178
+ if (!endo)
6179
+ return wnaf.unsafeLadder(this, n);
6180
+ let { k1neg, k1, k2neg, k2 } = endo.splitScalar(n);
6181
+ let k1p = I;
6182
+ let k2p = I;
6183
+ let d = this;
6184
+ while (k1 > _0n9 || k2 > _0n9) {
6185
+ if (k1 & _1n9)
6186
+ k1p = k1p.add(d);
6187
+ if (k2 & _1n9)
6188
+ k2p = k2p.add(d);
6189
+ d = d.double();
6190
+ k1 >>= _1n9;
6191
+ k2 >>= _1n9;
6192
+ }
6193
+ if (k1neg)
6194
+ k1p = k1p.negate();
6195
+ if (k2neg)
6196
+ k2p = k2p.negate();
6197
+ k2p = new Point(Fp.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
6198
+ return k1p.add(k2p);
6199
+ }
6200
+ multiply(scalar) {
6201
+ assertGE(scalar);
6202
+ let n = scalar;
6203
+ let point, fake;
6204
+ const { endo } = CURVE2;
6205
+ if (endo) {
6206
+ const { k1neg, k1, k2neg, k2 } = endo.splitScalar(n);
6207
+ let { p: k1p, f: f1p } = this.wNAF(k1);
6208
+ let { p: k2p, f: f2p } = this.wNAF(k2);
6209
+ k1p = wnaf.constTimeNegate(k1neg, k1p);
6210
+ k2p = wnaf.constTimeNegate(k2neg, k2p);
6211
+ k2p = new Point(Fp.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
6212
+ point = k1p.add(k2p);
6213
+ fake = f1p.add(f2p);
6214
+ } else {
6215
+ const { p, f } = this.wNAF(n);
6216
+ point = p;
6217
+ fake = f;
6218
+ }
6219
+ return Point.normalizeZ([point, fake])[0];
6220
+ }
6221
+ multiplyAndAddUnsafe(Q, a, b) {
6222
+ const G = Point.BASE;
6223
+ const mul = (P, a2) => a2 === _0n9 || a2 === _1n9 || !P.equals(G) ? P.multiplyUnsafe(a2) : P.multiply(a2);
6224
+ const sum = mul(this, a).add(mul(Q, b));
6225
+ return sum.is0() ? void 0 : sum;
6226
+ }
6227
+ toAffine(iz) {
6228
+ const { px: x, py: y, pz: z } = this;
6229
+ const is0 = this.is0();
6230
+ if (iz == null)
6231
+ iz = is0 ? Fp.ONE : Fp.inv(z);
6232
+ const ax = Fp.mul(x, iz);
6233
+ const ay = Fp.mul(y, iz);
6234
+ const zz = Fp.mul(z, iz);
6235
+ if (is0)
6236
+ return { x: Fp.ZERO, y: Fp.ZERO };
6237
+ if (!Fp.eql(zz, Fp.ONE))
6238
+ throw new Error("invZ was invalid");
6239
+ return { x: ax, y: ay };
6240
+ }
6241
+ isTorsionFree() {
6242
+ const { h: cofactor, isTorsionFree } = CURVE2;
6243
+ if (cofactor === _1n9)
6244
+ return true;
6245
+ if (isTorsionFree)
6246
+ return isTorsionFree(Point, this);
6247
+ throw new Error("isTorsionFree() has not been declared for the elliptic curve");
6248
+ }
6249
+ clearCofactor() {
6250
+ const { h: cofactor, clearCofactor } = CURVE2;
6251
+ if (cofactor === _1n9)
6252
+ return this;
6253
+ if (clearCofactor)
6254
+ return clearCofactor(Point, this);
6255
+ return this.multiplyUnsafe(CURVE2.h);
6256
+ }
6257
+ toRawBytes(isCompressed = true) {
6258
+ this.assertValidity();
6259
+ return CURVE2.toBytes(Point, this, isCompressed);
6260
+ }
6261
+ toHex(isCompressed = true) {
6262
+ return bytesToHex2(this.toRawBytes(isCompressed));
6263
+ }
6264
+ }
6265
+ Point.BASE = new Point(CURVE2.Gx, CURVE2.Gy, Fp.ONE);
6266
+ Point.ZERO = new Point(Fp.ZERO, Fp.ONE, Fp.ZERO);
6267
+ const _bits = CURVE2.nBitLength;
6268
+ const wnaf = wNAF2(Point, CURVE2.endo ? Math.ceil(_bits / 2) : _bits);
6269
+ return {
6270
+ ProjectivePoint: Point,
6271
+ normPrivateKeyToScalar,
6272
+ weierstrassEquation,
6273
+ isWithinCurveOrder
6274
+ };
6275
+ }
6276
+ function validateOpts3(curve2) {
6277
+ const opts = validateBasic2(curve2);
6278
+ validateObject2(opts, {
6279
+ hash: "hash",
6280
+ hmac: "function",
6281
+ randomBytes: "function"
6282
+ }, {
6283
+ bits2int: "function",
6284
+ bits2int_modN: "function",
6285
+ lowS: "boolean"
6286
+ });
6287
+ return Object.freeze({ lowS: true, ...opts });
6288
+ }
6289
+ function weierstrass2(curveDef) {
6290
+ const CURVE2 = validateOpts3(curveDef);
6291
+ const CURVE_ORDER2 = CURVE2.n;
6292
+ const Fp = CURVE2.Fp;
6293
+ const compressedLen = Fp.BYTES + 1;
6294
+ const uncompressedLen = 2 * Fp.BYTES + 1;
6295
+ function isValidFieldElement(num) {
6296
+ return _0n9 < num && num < Fp.ORDER;
6297
+ }
6298
+ function modN(a) {
6299
+ return mod2(a, CURVE_ORDER2);
6300
+ }
6301
+ function invN(a) {
6302
+ return invert2(a, CURVE_ORDER2);
6303
+ }
6304
+ const { ProjectivePoint: Point, normPrivateKeyToScalar, weierstrassEquation, isWithinCurveOrder } = weierstrassPoints2({
6305
+ ...CURVE2,
6306
+ toBytes(c, point, isCompressed) {
6307
+ const a = point.toAffine();
6308
+ const x = Fp.toBytes(a.x);
6309
+ const cat = concatBytes3;
6310
+ if (isCompressed) {
6311
+ return cat(Uint8Array.from([point.hasEvenY() ? 2 : 3]), x);
6312
+ } else {
6313
+ return cat(Uint8Array.from([4]), x, Fp.toBytes(a.y));
6314
+ }
6315
+ },
6316
+ fromBytes(bytes2) {
6317
+ const len = bytes2.length;
6318
+ const head = bytes2[0];
6319
+ const tail = bytes2.subarray(1);
6320
+ if (len === compressedLen && (head === 2 || head === 3)) {
6321
+ const x = bytesToNumberBE2(tail);
6322
+ if (!isValidFieldElement(x))
6323
+ throw new Error("Point is not on curve");
6324
+ const y2 = weierstrassEquation(x);
6325
+ let y = Fp.sqrt(y2);
6326
+ const isYOdd = (y & _1n9) === _1n9;
6327
+ const isHeadOdd = (head & 1) === 1;
6328
+ if (isHeadOdd !== isYOdd)
6329
+ y = Fp.neg(y);
6330
+ return { x, y };
6331
+ } else if (len === uncompressedLen && head === 4) {
6332
+ const x = Fp.fromBytes(tail.subarray(0, Fp.BYTES));
6333
+ const y = Fp.fromBytes(tail.subarray(Fp.BYTES, 2 * Fp.BYTES));
6334
+ return { x, y };
6335
+ } else {
6336
+ throw new Error(`Point of length ${len} was invalid. Expected ${compressedLen} compressed bytes or ${uncompressedLen} uncompressed bytes`);
6337
+ }
6338
+ }
6339
+ });
6340
+ const numToNByteStr = (num) => bytesToHex2(numberToBytesBE2(num, CURVE2.nByteLength));
6341
+ function isBiggerThanHalfOrder(number3) {
6342
+ const HALF = CURVE_ORDER2 >> _1n9;
6343
+ return number3 > HALF;
6344
+ }
6345
+ function normalizeS(s) {
6346
+ return isBiggerThanHalfOrder(s) ? modN(-s) : s;
6347
+ }
6348
+ const slcNum = (b, from, to) => bytesToNumberBE2(b.slice(from, to));
6349
+ class Signature3 {
6350
+ constructor(r, s, recovery) {
6351
+ this.r = r;
6352
+ this.s = s;
6353
+ this.recovery = recovery;
6354
+ this.assertValidity();
6355
+ }
6356
+ static fromCompact(hex) {
6357
+ const l = CURVE2.nByteLength;
6358
+ hex = ensureBytes3("compactSignature", hex, l * 2);
6359
+ return new Signature3(slcNum(hex, 0, l), slcNum(hex, l, 2 * l));
6360
+ }
6361
+ static fromDER(hex) {
6362
+ const { r, s } = DER2.toSig(ensureBytes3("DER", hex));
6363
+ return new Signature3(r, s);
6364
+ }
6365
+ assertValidity() {
6366
+ if (!isWithinCurveOrder(this.r))
6367
+ throw new Error("r must be 0 < r < CURVE.n");
6368
+ if (!isWithinCurveOrder(this.s))
6369
+ throw new Error("s must be 0 < s < CURVE.n");
6370
+ }
6371
+ addRecoveryBit(recovery) {
6372
+ return new Signature3(this.r, this.s, recovery);
6373
+ }
6374
+ recoverPublicKey(msgHash) {
6375
+ const { r, s, recovery: rec } = this;
6376
+ const h = bits2int_modN(ensureBytes3("msgHash", msgHash));
6377
+ if (rec == null || ![0, 1, 2, 3].includes(rec))
6378
+ throw new Error("recovery id invalid");
6379
+ const radj = rec === 2 || rec === 3 ? r + CURVE2.n : r;
6380
+ if (radj >= Fp.ORDER)
6381
+ throw new Error("recovery id 2 or 3 invalid");
6382
+ const prefix = (rec & 1) === 0 ? "02" : "03";
6383
+ const R = Point.fromHex(prefix + numToNByteStr(radj));
6384
+ const ir = invN(radj);
6385
+ const u1 = modN(-h * ir);
6386
+ const u2 = modN(s * ir);
6387
+ const Q = Point.BASE.multiplyAndAddUnsafe(R, u1, u2);
6388
+ if (!Q)
6389
+ throw new Error("point at infinify");
6390
+ Q.assertValidity();
6391
+ return Q;
6392
+ }
6393
+ hasHighS() {
6394
+ return isBiggerThanHalfOrder(this.s);
6395
+ }
6396
+ normalizeS() {
6397
+ return this.hasHighS() ? new Signature3(this.r, modN(-this.s), this.recovery) : this;
6398
+ }
6399
+ toDERRawBytes() {
6400
+ return hexToBytes2(this.toDERHex());
6401
+ }
6402
+ toDERHex() {
6403
+ return DER2.hexFromSig({ r: this.r, s: this.s });
6404
+ }
6405
+ toCompactRawBytes() {
6406
+ return hexToBytes2(this.toCompactHex());
6407
+ }
6408
+ toCompactHex() {
6409
+ return numToNByteStr(this.r) + numToNByteStr(this.s);
6410
+ }
6411
+ }
6412
+ const utils2 = {
6413
+ isValidPrivateKey(privateKey) {
6414
+ try {
6415
+ normPrivateKeyToScalar(privateKey);
6416
+ return true;
6417
+ } catch (error) {
6418
+ return false;
6419
+ }
6420
+ },
6421
+ normPrivateKeyToScalar,
6422
+ randomPrivateKey: () => {
6423
+ const rand = CURVE2.randomBytes(Fp.BYTES + 8);
6424
+ const num = hashToPrivateScalar2(rand, CURVE_ORDER2);
6425
+ return numberToBytesBE2(num, CURVE2.nByteLength);
6426
+ },
6427
+ precompute(windowSize = 8, point = Point.BASE) {
6428
+ point._setWindowSize(windowSize);
6429
+ point.multiply(BigInt(3));
6430
+ return point;
6431
+ }
6432
+ };
6433
+ function getPublicKey2(privateKey, isCompressed = true) {
6434
+ return Point.fromPrivateKey(privateKey).toRawBytes(isCompressed);
6435
+ }
6436
+ function isProbPub(item) {
6437
+ const arr = item instanceof Uint8Array;
6438
+ const str = typeof item === "string";
6439
+ const len = (arr || str) && item.length;
6440
+ if (arr)
6441
+ return len === compressedLen || len === uncompressedLen;
6442
+ if (str)
6443
+ return len === 2 * compressedLen || len === 2 * uncompressedLen;
6444
+ if (item instanceof Point)
6445
+ return true;
6446
+ return false;
6447
+ }
6448
+ function getSharedSecret2(privateA, publicB, isCompressed = true) {
6449
+ if (isProbPub(privateA))
6450
+ throw new Error("first arg must be private key");
6451
+ if (!isProbPub(publicB))
6452
+ throw new Error("second arg must be public key");
6453
+ const b = Point.fromHex(publicB);
6454
+ return b.multiply(normPrivateKeyToScalar(privateA)).toRawBytes(isCompressed);
6455
+ }
6456
+ const bits2int2 = CURVE2.bits2int || function(bytes2) {
6457
+ const num = bytesToNumberBE2(bytes2);
6458
+ const delta = bytes2.length * 8 - CURVE2.nBitLength;
6459
+ return delta > 0 ? num >> BigInt(delta) : num;
6460
+ };
6461
+ const bits2int_modN = CURVE2.bits2int_modN || function(bytes2) {
6462
+ return modN(bits2int2(bytes2));
6463
+ };
6464
+ const ORDER_MASK = bitMask2(CURVE2.nBitLength);
6465
+ function int2octets(num) {
6466
+ if (typeof num !== "bigint")
6467
+ throw new Error("bigint expected");
6468
+ if (!(_0n9 <= num && num < ORDER_MASK))
6469
+ throw new Error(`bigint expected < 2^${CURVE2.nBitLength}`);
6470
+ return numberToBytesBE2(num, CURVE2.nByteLength);
6471
+ }
6472
+ function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
6473
+ if (["recovered", "canonical"].some((k) => k in opts))
6474
+ throw new Error("sign() legacy options not supported");
6475
+ const { hash: hash2, randomBytes: randomBytes2 } = CURVE2;
6476
+ let { lowS, prehash, extraEntropy: ent } = opts;
6477
+ if (lowS == null)
6478
+ lowS = true;
6479
+ msgHash = ensureBytes3("msgHash", msgHash);
6480
+ if (prehash)
6481
+ msgHash = ensureBytes3("prehashed msgHash", hash2(msgHash));
6482
+ const h1int = bits2int_modN(msgHash);
6483
+ const d = normPrivateKeyToScalar(privateKey);
6484
+ const seedArgs = [int2octets(d), int2octets(h1int)];
6485
+ if (ent != null) {
6486
+ const e = ent === true ? randomBytes2(Fp.BYTES) : ent;
6487
+ seedArgs.push(ensureBytes3("extraEntropy", e, Fp.BYTES));
6488
+ }
6489
+ const seed = concatBytes3(...seedArgs);
6490
+ const m = h1int;
6491
+ function k2sig(kBytes) {
6492
+ const k = bits2int2(kBytes);
6493
+ if (!isWithinCurveOrder(k))
6494
+ return;
6495
+ const ik = invN(k);
6496
+ const q = Point.BASE.multiply(k).toAffine();
6497
+ const r = modN(q.x);
6498
+ if (r === _0n9)
6499
+ return;
6500
+ const s = modN(ik * modN(m + r * d));
6501
+ if (s === _0n9)
6502
+ return;
6503
+ let recovery = (q.x === r ? 0 : 2) | Number(q.y & _1n9);
6504
+ let normS = s;
6505
+ if (lowS && isBiggerThanHalfOrder(s)) {
6506
+ normS = normalizeS(s);
6507
+ recovery ^= 1;
6508
+ }
6509
+ return new Signature3(r, normS, recovery);
6510
+ }
6511
+ return { seed, k2sig };
6512
+ }
6513
+ const defaultSigOpts = { lowS: CURVE2.lowS, prehash: false };
6514
+ const defaultVerOpts = { lowS: CURVE2.lowS, prehash: false };
6515
+ function sign2(msgHash, privKey, opts = defaultSigOpts) {
6516
+ const { seed, k2sig } = prepSig(msgHash, privKey, opts);
6517
+ const drbg = createHmacDrbg2(CURVE2.hash.outputLen, CURVE2.nByteLength, CURVE2.hmac);
6518
+ return drbg(seed, k2sig);
6519
+ }
6520
+ Point.BASE._setWindowSize(8);
6521
+ function verify2(signature, msgHash, publicKey, opts = defaultVerOpts) {
6522
+ var _a;
6523
+ const sg = signature;
6524
+ msgHash = ensureBytes3("msgHash", msgHash);
6525
+ publicKey = ensureBytes3("publicKey", publicKey);
6526
+ if ("strict" in opts)
6527
+ throw new Error("options.strict was renamed to lowS");
6528
+ const { lowS, prehash } = opts;
6529
+ let _sig = void 0;
6530
+ let P;
6531
+ try {
6532
+ if (typeof sg === "string" || sg instanceof Uint8Array) {
6533
+ try {
6534
+ _sig = Signature3.fromDER(sg);
6535
+ } catch (derError) {
6536
+ if (!(derError instanceof DER2.Err))
6537
+ throw derError;
6538
+ _sig = Signature3.fromCompact(sg);
6539
+ }
6540
+ } else if (typeof sg === "object" && typeof sg.r === "bigint" && typeof sg.s === "bigint") {
6541
+ const { r: r2, s: s2 } = sg;
6542
+ _sig = new Signature3(r2, s2);
6543
+ } else {
6544
+ throw new Error("PARSE");
6545
+ }
6546
+ P = Point.fromHex(publicKey);
6547
+ } catch (error) {
6548
+ if (error.message === "PARSE")
6549
+ throw new Error(`signature must be Signature instance, Uint8Array or hex string`);
6550
+ return false;
6551
+ }
6552
+ if (lowS && _sig.hasHighS())
6553
+ return false;
6554
+ if (prehash)
6555
+ msgHash = CURVE2.hash(msgHash);
6556
+ const { r, s } = _sig;
6557
+ const h = bits2int_modN(msgHash);
6558
+ const is = invN(s);
6559
+ const u1 = modN(h * is);
6560
+ const u2 = modN(r * is);
6561
+ const R = (_a = Point.BASE.multiplyAndAddUnsafe(P, u1, u2)) == null ? void 0 : _a.toAffine();
6562
+ if (!R)
6563
+ return false;
6564
+ const v = modN(R.x);
6565
+ return v === r;
6566
+ }
6567
+ return {
6568
+ CURVE: CURVE2,
6569
+ getPublicKey: getPublicKey2,
6570
+ getSharedSecret: getSharedSecret2,
6571
+ sign: sign2,
6572
+ verify: verify2,
6573
+ ProjectivePoint: Point,
6574
+ Signature: Signature3,
6575
+ utils: utils2
6576
+ };
6577
+ }
6578
+ function SWUFpSqrtRatio(Fp, Z) {
6579
+ const q = Fp.ORDER;
6580
+ let l = 0n;
6581
+ for (let o = q - 1n; o % 2n === 0n; o /= 2n)
6582
+ l += 1n;
6583
+ const c1 = l;
6584
+ const c2 = (q - 1n) / 2n ** c1;
6585
+ const c3 = (c2 - 1n) / 2n;
6586
+ const c4 = 2n ** c1 - 1n;
6587
+ const c5 = 2n ** (c1 - 1n);
6588
+ const c6 = Fp.pow(Z, c2);
6589
+ const c7 = Fp.pow(Z, (c2 + 1n) / 2n);
6590
+ let sqrtRatio = (u, v) => {
6591
+ let tv1 = c6;
6592
+ let tv2 = Fp.pow(v, c4);
6593
+ let tv3 = Fp.sqr(tv2);
6594
+ tv3 = Fp.mul(tv3, v);
6595
+ let tv5 = Fp.mul(u, tv3);
6596
+ tv5 = Fp.pow(tv5, c3);
6597
+ tv5 = Fp.mul(tv5, tv2);
6598
+ tv2 = Fp.mul(tv5, v);
6599
+ tv3 = Fp.mul(tv5, u);
6600
+ let tv4 = Fp.mul(tv3, tv2);
6601
+ tv5 = Fp.pow(tv4, c5);
6602
+ let isQR = Fp.eql(tv5, Fp.ONE);
6603
+ tv2 = Fp.mul(tv3, c7);
6604
+ tv5 = Fp.mul(tv4, tv1);
6605
+ tv3 = Fp.cmov(tv2, tv3, isQR);
6606
+ tv4 = Fp.cmov(tv5, tv4, isQR);
6607
+ for (let i = c1; i > 1; i--) {
6608
+ let tv52 = 2n ** (i - 2n);
6609
+ let tvv5 = Fp.pow(tv4, tv52);
6610
+ const e1 = Fp.eql(tvv5, Fp.ONE);
6611
+ tv2 = Fp.mul(tv3, tv1);
6612
+ tv1 = Fp.mul(tv1, tv1);
6613
+ tvv5 = Fp.mul(tv4, tv1);
6614
+ tv3 = Fp.cmov(tv2, tv3, e1);
6615
+ tv4 = Fp.cmov(tvv5, tv4, e1);
6616
+ }
6617
+ return { isValid: isQR, value: tv3 };
6618
+ };
6619
+ if (Fp.ORDER % 4n === 3n) {
6620
+ const c12 = (Fp.ORDER - 3n) / 4n;
6621
+ const c22 = Fp.sqrt(Fp.neg(Z));
6622
+ sqrtRatio = (u, v) => {
6623
+ let tv1 = Fp.sqr(v);
6624
+ const tv2 = Fp.mul(u, v);
6625
+ tv1 = Fp.mul(tv1, tv2);
6626
+ let y1 = Fp.pow(tv1, c12);
6627
+ y1 = Fp.mul(y1, tv2);
6628
+ const y2 = Fp.mul(y1, c22);
6629
+ const tv3 = Fp.mul(Fp.sqr(y1), v);
6630
+ const isQR = Fp.eql(tv3, u);
6631
+ let y = Fp.cmov(y2, y1, isQR);
6632
+ return { isValid: isQR, value: y };
6633
+ };
6634
+ }
6635
+ return sqrtRatio;
6636
+ }
6637
+ function mapToCurveSimpleSWU(Fp, opts) {
6638
+ validateField2(Fp);
6639
+ if (!Fp.isValid(opts.A) || !Fp.isValid(opts.B) || !Fp.isValid(opts.Z))
6640
+ throw new Error("mapToCurveSimpleSWU: invalid opts");
6641
+ const sqrtRatio = SWUFpSqrtRatio(Fp, opts.Z);
6642
+ if (!Fp.isOdd)
6643
+ throw new Error("Fp.isOdd is not implemented!");
6644
+ return (u) => {
6645
+ let tv1, tv2, tv3, tv4, tv5, tv6, x, y;
6646
+ tv1 = Fp.sqr(u);
6647
+ tv1 = Fp.mul(tv1, opts.Z);
6648
+ tv2 = Fp.sqr(tv1);
6649
+ tv2 = Fp.add(tv2, tv1);
6650
+ tv3 = Fp.add(tv2, Fp.ONE);
6651
+ tv3 = Fp.mul(tv3, opts.B);
6652
+ tv4 = Fp.cmov(opts.Z, Fp.neg(tv2), !Fp.eql(tv2, Fp.ZERO));
6653
+ tv4 = Fp.mul(tv4, opts.A);
6654
+ tv2 = Fp.sqr(tv3);
6655
+ tv6 = Fp.sqr(tv4);
6656
+ tv5 = Fp.mul(tv6, opts.A);
6657
+ tv2 = Fp.add(tv2, tv5);
6658
+ tv2 = Fp.mul(tv2, tv3);
6659
+ tv6 = Fp.mul(tv6, tv4);
6660
+ tv5 = Fp.mul(tv6, opts.B);
6661
+ tv2 = Fp.add(tv2, tv5);
6662
+ x = Fp.mul(tv1, tv3);
6663
+ const { isValid, value } = sqrtRatio(tv2, tv6);
6664
+ y = Fp.mul(tv1, u);
6665
+ y = Fp.mul(y, value);
6666
+ x = Fp.cmov(x, tv3, isValid);
6667
+ y = Fp.cmov(y, value, isValid);
6668
+ const e1 = Fp.isOdd(u) === Fp.isOdd(y);
6669
+ y = Fp.cmov(Fp.neg(y), y, e1);
6670
+ x = Fp.div(x, tv4);
6671
+ return { x, y };
6672
+ };
6673
+ }
6674
+
6675
+ // src/utils/json.ts
6676
+ var json_exports = {};
6677
+ __export(json_exports, {
6678
+ parse: () => parse2,
6679
+ parseAlwaysAsBig: () => parseAlwaysAsBig,
6680
+ stringify: () => stringify2,
6681
+ stringifyAlwaysAsBig: () => stringifyAlwaysAsBig
6682
+ });
6683
+
6684
+ // node_modules/lossless-json/lib/esm/utils.js
6685
+ function isInteger(value) {
6686
+ return INTEGER_REGEX.test(value);
6687
+ }
6688
+ var INTEGER_REGEX = /^-?[0-9]+$/;
6689
+ function isNumber(value) {
6690
+ return NUMBER_REGEX.test(value);
6691
+ }
6692
+ var NUMBER_REGEX = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
6693
+ function isSafeNumber(value, config) {
6694
+ var num = parseFloat(value);
6695
+ var str = String(num);
6696
+ var v = extractSignificantDigits(value);
6697
+ var s = extractSignificantDigits(str);
6698
+ if (v === s) {
6699
+ return true;
6700
+ }
6701
+ if ((config === null || config === void 0 ? void 0 : config.approx) === true) {
6702
+ var requiredDigits = 14;
6703
+ if (!isInteger(value) && s.length >= requiredDigits && v.startsWith(s.substring(0, requiredDigits))) {
5601
6704
  return true;
5602
6705
  }
5603
6706
  }
@@ -6236,6 +7339,112 @@ var starknet = (() => {
6236
7339
  var stringify2 = (...p) => stringify(...p);
6237
7340
  var stringifyAlwaysAsBig = stringify2;
6238
7341
 
7342
+ // node_modules/@noble/curves/esm/abstract/poseidon.js
7343
+ var poseidon_exports = {};
7344
+ __export(poseidon_exports, {
7345
+ poseidon: () => poseidon2,
7346
+ splitConstants: () => splitConstants,
7347
+ validateOpts: () => validateOpts4
7348
+ });
7349
+ function validateOpts4(opts) {
7350
+ const { Fp } = opts;
7351
+ validateField2(Fp);
7352
+ for (const i of ["t", "roundsFull", "roundsPartial"]) {
7353
+ if (typeof opts[i] !== "number" || !Number.isSafeInteger(opts[i]))
7354
+ throw new Error(`Poseidon: invalid param ${i}=${opts[i]} (${typeof opts[i]})`);
7355
+ }
7356
+ if (opts.reversePartialPowIdx !== void 0 && typeof opts.reversePartialPowIdx !== "boolean")
7357
+ throw new Error(`Poseidon: invalid param reversePartialPowIdx=${opts.reversePartialPowIdx}`);
7358
+ let sboxPower = opts.sboxPower;
7359
+ if (sboxPower === void 0)
7360
+ sboxPower = 5;
7361
+ if (typeof sboxPower !== "number" || !Number.isSafeInteger(sboxPower))
7362
+ throw new Error(`Poseidon wrong sboxPower=${sboxPower}`);
7363
+ const _sboxPower = BigInt(sboxPower);
7364
+ let sboxFn = (n) => FpPow2(Fp, n, _sboxPower);
7365
+ if (sboxPower === 3)
7366
+ sboxFn = (n) => Fp.mul(Fp.sqrN(n), n);
7367
+ else if (sboxPower === 5)
7368
+ sboxFn = (n) => Fp.mul(Fp.sqrN(Fp.sqrN(n)), n);
7369
+ if (opts.roundsFull % 2 !== 0)
7370
+ throw new Error(`Poseidon roundsFull is not even: ${opts.roundsFull}`);
7371
+ const rounds = opts.roundsFull + opts.roundsPartial;
7372
+ if (!Array.isArray(opts.roundConstants) || opts.roundConstants.length !== rounds)
7373
+ throw new Error("Poseidon: wrong round constants");
7374
+ const roundConstants = opts.roundConstants.map((rc) => {
7375
+ if (!Array.isArray(rc) || rc.length !== opts.t)
7376
+ throw new Error(`Poseidon wrong round constants: ${rc}`);
7377
+ return rc.map((i) => {
7378
+ if (typeof i !== "bigint" || !Fp.isValid(i))
7379
+ throw new Error(`Poseidon wrong round constant=${i}`);
7380
+ return Fp.create(i);
7381
+ });
7382
+ });
7383
+ if (!Array.isArray(opts.mds) || opts.mds.length !== opts.t)
7384
+ throw new Error("Poseidon: wrong MDS matrix");
7385
+ const mds = opts.mds.map((mdsRow) => {
7386
+ if (!Array.isArray(mdsRow) || mdsRow.length !== opts.t)
7387
+ throw new Error(`Poseidon MDS matrix row: ${mdsRow}`);
7388
+ return mdsRow.map((i) => {
7389
+ if (typeof i !== "bigint")
7390
+ throw new Error(`Poseidon MDS matrix value=${i}`);
7391
+ return Fp.create(i);
7392
+ });
7393
+ });
7394
+ return Object.freeze({ ...opts, rounds, sboxFn, roundConstants, mds });
7395
+ }
7396
+ function splitConstants(rc, t) {
7397
+ if (typeof t !== "number")
7398
+ throw new Error("poseidonSplitConstants: wrong t");
7399
+ if (!Array.isArray(rc) || rc.length % t)
7400
+ throw new Error("poseidonSplitConstants: wrong rc");
7401
+ const res = [];
7402
+ let tmp = [];
7403
+ for (let i = 0; i < rc.length; i++) {
7404
+ tmp.push(rc[i]);
7405
+ if (tmp.length === t) {
7406
+ res.push(tmp);
7407
+ tmp = [];
7408
+ }
7409
+ }
7410
+ return res;
7411
+ }
7412
+ function poseidon2(opts) {
7413
+ const { t, Fp, rounds, sboxFn, reversePartialPowIdx } = validateOpts4(opts);
7414
+ const halfRoundsFull = Math.floor(opts.roundsFull / 2);
7415
+ const partialIdx = reversePartialPowIdx ? t - 1 : 0;
7416
+ const poseidonRound = (values, isFull, idx) => {
7417
+ values = values.map((i, j) => Fp.add(i, opts.roundConstants[idx][j]));
7418
+ if (isFull)
7419
+ values = values.map((i) => sboxFn(i));
7420
+ else
7421
+ values[partialIdx] = sboxFn(values[partialIdx]);
7422
+ values = opts.mds.map((i) => i.reduce((acc, i2, j) => Fp.add(acc, Fp.mulN(i2, values[j])), Fp.ZERO));
7423
+ return values;
7424
+ };
7425
+ const poseidonHash2 = function poseidonHash3(values) {
7426
+ if (!Array.isArray(values) || values.length !== t)
7427
+ throw new Error(`Poseidon: wrong values (expected array of bigints with length ${t})`);
7428
+ values = values.map((i) => {
7429
+ if (typeof i !== "bigint")
7430
+ throw new Error(`Poseidon: wrong value=${i} (${typeof i})`);
7431
+ return Fp.create(i);
7432
+ });
7433
+ let round = 0;
7434
+ for (let i = 0; i < halfRoundsFull; i++)
7435
+ values = poseidonRound(values, true, round++);
7436
+ for (let i = 0; i < opts.roundsPartial; i++)
7437
+ values = poseidonRound(values, false, round++);
7438
+ for (let i = 0; i < halfRoundsFull; i++)
7439
+ values = poseidonRound(values, true, round++);
7440
+ if (round !== rounds)
7441
+ throw new Error(`Poseidon: wrong number of rounds: last round=${round}, total=${rounds}`);
7442
+ return values;
7443
+ };
7444
+ poseidonHash2.roundConstants = opts.roundConstants;
7445
+ return poseidonHash2;
7446
+ }
7447
+
6239
7448
  // src/utils/hash.ts
6240
7449
  var transactionVersion = 1n;
6241
7450
  var transactionVersion_2 = 2n;
@@ -6243,7 +7452,7 @@ var starknet = (() => {
6243
7452
  function keccakBn(value) {
6244
7453
  const hexWithoutPrefix = removeHexPrefix(toHex(BigInt(value)));
6245
7454
  const evenHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
6246
- return addHexPrefix(keccak(hexToBytes2(addHexPrefix(evenHex))).toString(16));
7455
+ return addHexPrefix(keccak(hexToBytes3(addHexPrefix(evenHex))).toString(16));
6247
7456
  }
6248
7457
  function keccakHex(value) {
6249
7458
  return addHexPrefix(keccak(utf8ToArray(value)).toString(16));
@@ -6657,6 +7866,12 @@ var starknet = (() => {
6657
7866
  }, result);
6658
7867
  case (isTypeStruct(type, structs) || isTypeTuple(type)):
6659
7868
  return parseCalldataValue(value, type, structs);
7869
+ case isTypeUint256(type):
7870
+ if (typeof value === "object") {
7871
+ return [felt(value.low), felt(value.high)];
7872
+ }
7873
+ const el_uint256 = uint256(value);
7874
+ return [felt(el_uint256.low), felt(el_uint256.high)];
6660
7875
  default:
6661
7876
  return parseBaseTypes(type, value);
6662
7877
  }
@@ -6744,10 +7959,10 @@ var starknet = (() => {
6744
7959
  );
6745
7960
  }
6746
7961
  assert(
6747
- typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
6748
- `Validate: arg ${input.name} of cairo type ${input.type} should be type (String, Number or BigInt)`
7962
+ typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint" || typeof parameter === "object" && "low" in parameter && "high" in parameter,
7963
+ `Validate: arg ${input.name} of cairo ZORG type ${input.type} should be type (String, Number or BigInt)`
6749
7964
  );
6750
- const param = toBigInt(parameter);
7965
+ const param = typeof parameter === "object" ? uint256ToBN(parameter) : toBigInt(parameter);
6751
7966
  switch (input.type) {
6752
7967
  case "core::integer::u8" /* u8 */:
6753
7968
  assert(
@@ -13580,7 +14795,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
13580
14795
  function getChecksumAddress(address) {
13581
14796
  const chars = removeHexPrefix(validateAndParseAddress(address)).toLowerCase().split("");
13582
14797
  const hex = removeHexPrefix(keccakBn(address));
13583
- const hashed = hexToBytes(hex.padStart(64, "0"));
14798
+ const hashed = hexToBytes2(hex.padStart(64, "0"));
13584
14799
  for (let i = 0; i < chars.length; i += 2) {
13585
14800
  if (hashed[i >> 1] >> 4 >= 8) {
13586
14801
  chars[i] = chars[i].toUpperCase();