@toon-protocol/client-mcp 0.20.2 → 0.20.4

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.
Files changed (29) hide show
  1. package/dist/{chunk-LN2OF264.js → chunk-6GXZ4KRO.js} +257 -1552
  2. package/dist/chunk-6GXZ4KRO.js.map +1 -0
  3. package/dist/{chunk-ZKSFO7M3.js → chunk-F3XAIOGQ.js} +2 -2
  4. package/dist/{chunk-IAOKAQLA.js → chunk-FDUYHYB2.js} +2 -2
  5. package/dist/{chunk-IAOKAQLA.js.map → chunk-FDUYHYB2.js.map} +1 -1
  6. package/dist/chunk-IYPIOSEF.js +3856 -0
  7. package/dist/chunk-IYPIOSEF.js.map +1 -0
  8. package/dist/{chunk-UPIAVE44.js → chunk-JFDVE4IA.js} +544 -4115
  9. package/dist/chunk-JFDVE4IA.js.map +1 -0
  10. package/dist/{chunk-WS3GVRQJ.js → chunk-TGIKIMXO.js} +9 -7
  11. package/dist/{chunk-WS3GVRQJ.js.map → chunk-TGIKIMXO.js.map} +1 -1
  12. package/dist/chunk-V7D5HJBT.js +1363 -0
  13. package/dist/chunk-V7D5HJBT.js.map +1 -0
  14. package/dist/daemon.js +6 -4
  15. package/dist/daemon.js.map +1 -1
  16. package/dist/{ed25519-VBPL32VX.js → ed25519-U6LNJH4K.js} +3 -2
  17. package/dist/index.js +7 -5
  18. package/dist/index.js.map +1 -1
  19. package/dist/mcp.js +6 -4
  20. package/dist/mcp.js.map +1 -1
  21. package/dist/mina-channel-deploy-CO2LMPPB-H2N5FX4G.js +12 -0
  22. package/dist/mina-channel-deploy-CO2LMPPB-H2N5FX4G.js.map +1 -0
  23. package/dist/{node-WPA2UDEH-RCLJ66AU.js → node-WPA2UDEH-HZP3B4FH.js} +3 -3
  24. package/dist/{node-WPA2UDEH-RCLJ66AU.js.map → node-WPA2UDEH-HZP3B4FH.js.map} +1 -1
  25. package/package.json +5 -5
  26. package/dist/chunk-LN2OF264.js.map +0 -1
  27. package/dist/chunk-UPIAVE44.js.map +0 -1
  28. /package/dist/{chunk-ZKSFO7M3.js.map → chunk-F3XAIOGQ.js.map} +0 -0
  29. /package/dist/{ed25519-VBPL32VX.js.map → ed25519-U6LNJH4K.js.map} +0 -0
@@ -927,20 +927,20 @@ function invert(number, modulo) {
927
927
  throw new Error("invert: does not exist");
928
928
  return mod(x, modulo);
929
929
  }
930
- function assertIsSquare(Fp2, root, n) {
931
- const F = Fp2;
930
+ function assertIsSquare(Fp, root, n) {
931
+ const F = Fp;
932
932
  if (!F.eql(F.sqr(root), n))
933
933
  throw new Error("Cannot find square root");
934
934
  }
935
- function sqrt3mod4(Fp2, n) {
936
- const F = Fp2;
935
+ function sqrt3mod4(Fp, n) {
936
+ const F = Fp;
937
937
  const p1div4 = (F.ORDER + _1n2) / _4n;
938
938
  const root = F.pow(n, p1div4);
939
939
  assertIsSquare(F, root, n);
940
940
  return root;
941
941
  }
942
- function sqrt5mod8(Fp2, n) {
943
- const F = Fp2;
942
+ function sqrt5mod8(Fp, n) {
943
+ const F = Fp;
944
944
  const p5div8 = (F.ORDER - _5n) / _8n;
945
945
  const n2 = F.mul(n, _2n);
946
946
  const v = F.pow(n2, p5div8);
@@ -957,8 +957,8 @@ function sqrt9mod16(P) {
957
957
  const c2 = tn(Fp_, c1);
958
958
  const c3 = tn(Fp_, Fp_.neg(c1));
959
959
  const c4 = (P + _7n) / _16n;
960
- return ((Fp2, n) => {
961
- const F = Fp2;
960
+ return ((Fp, n) => {
961
+ const F = Fp;
962
962
  let tv1 = F.pow(n, c4);
963
963
  let tv2 = F.mul(tv1, c1);
964
964
  const tv3 = F.mul(tv1, c2);
@@ -992,8 +992,8 @@ function tonelliShanks(P) {
992
992
  return sqrt3mod4;
993
993
  let cc = _Fp.pow(Z, Q);
994
994
  const Q1div2 = (Q + _1n2) / _2n;
995
- return function tonelliSlow(Fp2, n) {
996
- const F = Fp2;
995
+ return function tonelliSlow(Fp, n) {
996
+ const F = Fp;
997
997
  if (F.is0(n))
998
998
  return n;
999
999
  if (FpLegendre(F, n) !== 1)
@@ -1071,8 +1071,8 @@ function validateField(field) {
1071
1071
  throw new Error("invalid field: expected ORDER > 1, got " + field.ORDER);
1072
1072
  return field;
1073
1073
  }
1074
- function FpPow(Fp2, num, power) {
1075
- const F = Fp2;
1074
+ function FpPow(Fp, num, power) {
1075
+ const F = Fp;
1076
1076
  if (power < _0n2)
1077
1077
  throw new Error("invalid exponent, negatives unsupported");
1078
1078
  if (power === _0n2)
@@ -1089,8 +1089,8 @@ function FpPow(Fp2, num, power) {
1089
1089
  }
1090
1090
  return p;
1091
1091
  }
1092
- function FpInvertBatch(Fp2, nums, passZero = false) {
1093
- const F = Fp2;
1092
+ function FpInvertBatch(Fp, nums, passZero = false) {
1093
+ const F = Fp;
1094
1094
  const inverted = new Array(nums.length).fill(passZero ? F.ZERO : void 0);
1095
1095
  const multipliedAcc = nums.reduce((acc, num, i) => {
1096
1096
  if (F.is0(num))
@@ -1107,8 +1107,8 @@ function FpInvertBatch(Fp2, nums, passZero = false) {
1107
1107
  }, invertedAcc);
1108
1108
  return inverted;
1109
1109
  }
1110
- function FpLegendre(Fp2, n) {
1111
- const F = Fp2;
1110
+ function FpLegendre(Fp, n) {
1111
+ const F = Fp;
1112
1112
  const p1mod2 = (F.ORDER - _1n2) / _2n;
1113
1113
  const powered = F.pow(n, p1mod2);
1114
1114
  const yes = F.eql(powered, F.ONE);
@@ -1271,8 +1271,8 @@ Object.freeze(_Field.prototype);
1271
1271
  function Field(ORDER, opts = {}) {
1272
1272
  return new _Field(ORDER, opts);
1273
1273
  }
1274
- function FpSqrtEven(Fp2, elm) {
1275
- const F = Fp2;
1274
+ function FpSqrtEven(Fp, elm) {
1275
+ const F = Fp;
1276
1276
  if (!F.isOdd)
1277
1277
  throw new Error("Field doesn't have isOdd");
1278
1278
  const root = F.sqrt(elm);
@@ -1594,16 +1594,16 @@ function createCurveFields(type, CURVE, curveOpts = {}, FpFnLE) {
1594
1594
  if (!(typeof val === "bigint" && val > _0n3))
1595
1595
  throw new Error(`CURVE.${p} must be positive bigint`);
1596
1596
  }
1597
- const Fp2 = createField(CURVE.p, curveOpts.Fp, FpFnLE);
1598
- const Fn2 = createField(CURVE.n, curveOpts.Fn, FpFnLE);
1597
+ const Fp = createField(CURVE.p, curveOpts.Fp, FpFnLE);
1598
+ const Fn = createField(CURVE.n, curveOpts.Fn, FpFnLE);
1599
1599
  const _b = type === "weierstrass" ? "b" : "d";
1600
1600
  const params = ["Gx", "Gy", "a", _b];
1601
1601
  for (const p of params) {
1602
- if (!Fp2.isValid(CURVE[p]))
1602
+ if (!Fp.isValid(CURVE[p]))
1603
1603
  throw new Error(`CURVE.${p} must be valid field element of CURVE.Fp`);
1604
1604
  }
1605
1605
  CURVE = Object.freeze(Object.assign({}, CURVE));
1606
- return { CURVE, Fp: Fp2, Fn: Fn2 };
1606
+ return { CURVE, Fp, Fn };
1607
1607
  }
1608
1608
  function createKeygen(randomSecretKey, getPublicKey) {
1609
1609
  return function keygen(seed) {
@@ -1612,525 +1612,173 @@ function createKeygen(randomSecretKey, getPublicKey) {
1612
1612
  };
1613
1613
  }
1614
1614
 
1615
- // ../../node_modules/.pnpm/@noble+curves@2.2.0/node_modules/@noble/curves/abstract/edwards.js
1616
- var _0n4 = /* @__PURE__ */ BigInt(0);
1617
- var _1n4 = /* @__PURE__ */ BigInt(1);
1618
- var _2n2 = /* @__PURE__ */ BigInt(2);
1619
- var _8n2 = /* @__PURE__ */ BigInt(8);
1620
- function isEdValidXY(Fp2, CURVE, x, y) {
1621
- const x2 = Fp2.sqr(x);
1622
- const y2 = Fp2.sqr(y);
1623
- const left = Fp2.add(Fp2.mul(CURVE.a, x2), y2);
1624
- const right = Fp2.add(Fp2.ONE, Fp2.mul(CURVE.d, Fp2.mul(x2, y2)));
1625
- return Fp2.eql(left, right);
1626
- }
1627
- function edwards(params, extraOpts = {}) {
1628
- const opts = extraOpts;
1629
- const validated = createCurveFields("edwards", params, opts, opts.FpFnLE);
1630
- const { Fp: Fp2, Fn: Fn2 } = validated;
1631
- let CURVE = validated.CURVE;
1632
- const { h: cofactor } = CURVE;
1633
- validateObject(opts, {}, { uvRatio: "function" });
1634
- const MASK = _2n2 << BigInt(Fn2.BYTES * 8) - _1n4;
1635
- const modP = (n) => Fp2.create(n);
1636
- const uvRatio2 = opts.uvRatio === void 0 ? (u, v) => {
1637
- try {
1638
- return { isValid: true, value: Fp2.sqrt(Fp2.div(u, v)) };
1639
- } catch (e) {
1640
- return { isValid: false, value: _0n4 };
1641
- }
1642
- } : opts.uvRatio;
1643
- if (!isEdValidXY(Fp2, CURVE, CURVE.Gx, CURVE.Gy))
1644
- throw new Error("bad curve params: generator point");
1645
- function acoord(title, n, banZero = false) {
1646
- const min = banZero ? _1n4 : _0n4;
1647
- aInRange("coordinate " + title, n, min, MASK);
1648
- return n;
1649
- }
1650
- function aedpoint(other) {
1651
- if (!(other instanceof Point))
1652
- throw new Error("EdwardsPoint expected");
1653
- }
1654
- class Point {
1655
- // base / generator point
1656
- static BASE = new Point(CURVE.Gx, CURVE.Gy, _1n4, modP(CURVE.Gx * CURVE.Gy));
1657
- // zero / infinity / identity point
1658
- static ZERO = new Point(_0n4, _1n4, _1n4, _0n4);
1659
- // 0, 1, 1, 0
1660
- // math field
1661
- static Fp = Fp2;
1662
- // scalar field
1663
- static Fn = Fn2;
1664
- X;
1665
- Y;
1666
- Z;
1667
- T;
1668
- constructor(X, Y, Z, T) {
1669
- this.X = acoord("x", X);
1670
- this.Y = acoord("y", Y);
1671
- this.Z = acoord("z", Z, true);
1672
- this.T = acoord("t", T);
1673
- Object.freeze(this);
1674
- }
1675
- static CURVE() {
1676
- return CURVE;
1677
- }
1678
- /**
1679
- * Create one extended Edwards point from affine coordinates.
1680
- * Does NOT validate that the point is on-curve or torsion-free.
1681
- * Use `.assertValidity()` on adversarial inputs.
1682
- */
1683
- static fromAffine(p) {
1684
- if (p instanceof Point)
1685
- throw new Error("extended point not allowed");
1686
- const { x, y } = p || {};
1687
- acoord("x", x);
1688
- acoord("y", y);
1689
- return new Point(x, y, _1n4, modP(x * y));
1690
- }
1691
- // Uses algo from RFC8032 5.1.3.
1692
- static fromBytes(bytes, zip215 = false) {
1693
- const len = Fp2.BYTES;
1694
- const { a, d } = CURVE;
1695
- bytes = copyBytes(abytes2(bytes, len, "point"));
1696
- abool(zip215, "zip215");
1697
- const normed = copyBytes(bytes);
1698
- const lastByte = bytes[len - 1];
1699
- normed[len - 1] = lastByte & ~128;
1700
- const y = bytesToNumberLE(normed);
1701
- const max = zip215 ? MASK : Fp2.ORDER;
1702
- aInRange("point.y", y, _0n4, max);
1703
- const y2 = modP(y * y);
1704
- const u = modP(y2 - _1n4);
1705
- const v = modP(d * y2 - a);
1706
- let { isValid, value: x } = uvRatio2(u, v);
1707
- if (!isValid)
1708
- throw new Error("bad point: invalid y coordinate");
1709
- const isXOdd = (x & _1n4) === _1n4;
1710
- const isLastByteOdd = (lastByte & 128) !== 0;
1711
- if (!zip215 && x === _0n4 && isLastByteOdd)
1712
- throw new Error("bad point: x=0 and x_0=1");
1713
- if (isLastByteOdd !== isXOdd)
1714
- x = modP(-x);
1715
- return Point.fromAffine({ x, y });
1716
- }
1717
- static fromHex(hex, zip215 = false) {
1718
- return Point.fromBytes(hexToBytes2(hex), zip215);
1719
- }
1720
- get x() {
1721
- return this.toAffine().x;
1722
- }
1723
- get y() {
1724
- return this.toAffine().y;
1725
- }
1726
- precompute(windowSize = 8, isLazy = true) {
1727
- wnaf.createCache(this, windowSize);
1728
- if (!isLazy)
1729
- this.multiply(_2n2);
1730
- return this;
1731
- }
1732
- // Useful in fromAffine() - not for fromBytes(), which always created valid points.
1733
- assertValidity() {
1734
- const p = this;
1735
- const { a, d } = CURVE;
1736
- if (p.is0())
1737
- throw new Error("bad point: ZERO");
1738
- const { X, Y, Z, T } = p;
1739
- const X2 = modP(X * X);
1740
- const Y2 = modP(Y * Y);
1741
- const Z2 = modP(Z * Z);
1742
- const Z4 = modP(Z2 * Z2);
1743
- const aX2 = modP(X2 * a);
1744
- const left = modP(Z2 * modP(aX2 + Y2));
1745
- const right = modP(Z4 + modP(d * modP(X2 * Y2)));
1746
- if (left !== right)
1747
- throw new Error("bad point: equation left != right (1)");
1748
- const XY = modP(X * Y);
1749
- const ZT = modP(Z * T);
1750
- if (XY !== ZT)
1751
- throw new Error("bad point: equation left != right (2)");
1752
- }
1753
- // Compare one point to another.
1754
- equals(other) {
1755
- aedpoint(other);
1756
- const { X: X1, Y: Y1, Z: Z1 } = this;
1757
- const { X: X2, Y: Y2, Z: Z2 } = other;
1758
- const X1Z2 = modP(X1 * Z2);
1759
- const X2Z1 = modP(X2 * Z1);
1760
- const Y1Z2 = modP(Y1 * Z2);
1761
- const Y2Z1 = modP(Y2 * Z1);
1762
- return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
1763
- }
1764
- is0() {
1765
- return this.equals(Point.ZERO);
1766
- }
1767
- negate() {
1768
- return new Point(modP(-this.X), this.Y, this.Z, modP(-this.T));
1769
- }
1770
- // Fast algo for doubling Extended Point.
1771
- // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#doubling-dbl-2008-hwcd
1772
- // Cost: 4M + 4S + 1*a + 6add + 1*2.
1773
- double() {
1774
- const { a } = CURVE;
1775
- const { X: X1, Y: Y1, Z: Z1 } = this;
1776
- const A = modP(X1 * X1);
1777
- const B = modP(Y1 * Y1);
1778
- const C = modP(_2n2 * modP(Z1 * Z1));
1779
- const D = modP(a * A);
1780
- const x1y1 = X1 + Y1;
1781
- const E = modP(modP(x1y1 * x1y1) - A - B);
1782
- const G = D + B;
1783
- const F = G - C;
1784
- const H = D - B;
1785
- const X3 = modP(E * F);
1786
- const Y3 = modP(G * H);
1787
- const T3 = modP(E * H);
1788
- const Z3 = modP(F * G);
1789
- return new Point(X3, Y3, Z3, T3);
1790
- }
1791
- // Fast algo for adding 2 Extended Points.
1792
- // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#addition-add-2008-hwcd
1793
- // Cost: 9M + 1*a + 1*d + 7add.
1794
- add(other) {
1795
- aedpoint(other);
1796
- const { a, d } = CURVE;
1797
- const { X: X1, Y: Y1, Z: Z1, T: T1 } = this;
1798
- const { X: X2, Y: Y2, Z: Z2, T: T2 } = other;
1799
- const A = modP(X1 * X2);
1800
- const B = modP(Y1 * Y2);
1801
- const C = modP(T1 * d * T2);
1802
- const D = modP(Z1 * Z2);
1803
- const E = modP((X1 + Y1) * (X2 + Y2) - A - B);
1804
- const F = D - C;
1805
- const G = D + C;
1806
- const H = modP(B - a * A);
1807
- const X3 = modP(E * F);
1808
- const Y3 = modP(G * H);
1809
- const T3 = modP(E * H);
1810
- const Z3 = modP(F * G);
1811
- return new Point(X3, Y3, Z3, T3);
1812
- }
1813
- subtract(other) {
1814
- aedpoint(other);
1815
- return this.add(other.negate());
1816
- }
1817
- // Constant-time multiplication.
1818
- multiply(scalar) {
1819
- if (!Fn2.isValidNot0(scalar))
1820
- throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");
1821
- const { p, f } = wnaf.cached(this, scalar, (p2) => normalizeZ(Point, p2));
1822
- return normalizeZ(Point, [p, f])[0];
1823
- }
1824
- // Non-constant-time multiplication. Uses double-and-add algorithm.
1825
- // It's faster, but should only be used when you don't care about
1826
- // an exposed private key e.g. sig verification.
1827
- // Keeps the same subgroup-scalar contract: 0 is allowed for public-scalar callers, but
1828
- // n and larger values are rejected instead of being reduced mod n to the identity point.
1829
- multiplyUnsafe(scalar) {
1830
- if (!Fn2.isValid(scalar))
1831
- throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");
1832
- if (scalar === _0n4)
1833
- return Point.ZERO;
1834
- if (this.is0() || scalar === _1n4)
1835
- return this;
1836
- return wnaf.unsafe(this, scalar, (p) => normalizeZ(Point, p));
1837
- }
1838
- // Checks if point is of small order.
1839
- // If you add something to small order point, you will have "dirty"
1840
- // point with torsion component.
1841
- // Clears cofactor and checks if the result is 0.
1842
- isSmallOrder() {
1843
- return this.clearCofactor().is0();
1844
- }
1845
- // Multiplies point by curve order and checks if the result is 0.
1846
- // Returns `false` is the point is dirty.
1847
- isTorsionFree() {
1848
- return wnaf.unsafe(this, CURVE.n).is0();
1849
- }
1850
- // Converts Extended point to default (x, y) coordinates.
1851
- // Can accept precomputed Z^-1 - for example, from invertBatch.
1852
- toAffine(invertedZ) {
1853
- const p = this;
1854
- let iz = invertedZ;
1855
- const { X, Y, Z } = p;
1856
- const is0 = p.is0();
1857
- if (iz == null)
1858
- iz = is0 ? _8n2 : Fp2.inv(Z);
1859
- const x = modP(X * iz);
1860
- const y = modP(Y * iz);
1861
- const zz = Fp2.mul(Z, iz);
1862
- if (is0)
1863
- return { x: _0n4, y: _1n4 };
1864
- if (zz !== _1n4)
1865
- throw new Error("invZ was invalid");
1866
- return { x, y };
1867
- }
1868
- clearCofactor() {
1869
- if (cofactor === _1n4)
1870
- return this;
1871
- return this.multiplyUnsafe(cofactor);
1872
- }
1873
- toBytes() {
1874
- const { x, y } = this.toAffine();
1875
- const bytes = Fp2.toBytes(y);
1876
- bytes[bytes.length - 1] |= x & _1n4 ? 128 : 0;
1877
- return bytes;
1878
- }
1879
- toHex() {
1880
- return bytesToHex2(this.toBytes());
1881
- }
1882
- toString() {
1883
- return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
1884
- }
1885
- }
1886
- const wnaf = new wNAF(Point, Fn2.BITS);
1887
- if (Fn2.BITS >= 8)
1888
- Point.BASE.precompute(8);
1889
- Object.freeze(Point.prototype);
1890
- Object.freeze(Point);
1891
- return Point;
1892
- }
1893
- var PrimeEdwardsPoint = class {
1894
- static BASE;
1895
- static ZERO;
1896
- static Fp;
1897
- static Fn;
1898
- ep;
1899
- /**
1900
- * Wrap one internal Edwards representative directly.
1901
- * This is not a canonical encoding boundary: alternate Edwards
1902
- * representatives may still describe the same abstract wrapper element.
1903
- */
1904
- constructor(ep) {
1905
- this.ep = ep;
1906
- }
1907
- // Static methods that must be implemented by subclasses
1908
- static fromBytes(_bytes) {
1909
- notImplemented();
1910
- }
1911
- static fromHex(_hex) {
1912
- notImplemented();
1913
- }
1914
- get x() {
1915
- return this.toAffine().x;
1916
- }
1917
- get y() {
1918
- return this.toAffine().y;
1919
- }
1920
- // Common implementations
1921
- clearCofactor() {
1922
- return this;
1923
- }
1924
- assertValidity() {
1925
- this.ep.assertValidity();
1926
- }
1927
- /**
1928
- * Return affine coordinates of the current internal Edwards representative.
1929
- * This is a convenience helper, not a canonical Ristretto/Decaf encoding.
1930
- * Equal abstract elements may expose different `x` / `y`; use
1931
- * `toBytes()` / `fromBytes()` for canonical roundtrips.
1932
- */
1933
- toAffine(invertedZ) {
1934
- return this.ep.toAffine(invertedZ);
1935
- }
1936
- toHex() {
1937
- return bytesToHex2(this.toBytes());
1938
- }
1939
- toString() {
1940
- return this.toHex();
1941
- }
1942
- isTorsionFree() {
1943
- return true;
1944
- }
1945
- isSmallOrder() {
1946
- return false;
1947
- }
1948
- add(other) {
1949
- this.assertSame(other);
1950
- return this.init(this.ep.add(other.ep));
1951
- }
1952
- subtract(other) {
1953
- this.assertSame(other);
1954
- return this.init(this.ep.subtract(other.ep));
1955
- }
1956
- multiply(scalar) {
1957
- return this.init(this.ep.multiply(scalar));
1958
- }
1959
- multiplyUnsafe(scalar) {
1960
- return this.init(this.ep.multiplyUnsafe(scalar));
1615
+ // ../../node_modules/.pnpm/@noble+curves@2.2.0/node_modules/@noble/curves/abstract/hash-to-curve.js
1616
+ var os2ip = bytesToNumberBE;
1617
+ function i2osp(value, length) {
1618
+ asafenumber(value);
1619
+ asafenumber(length);
1620
+ if (length < 0 || length > 4)
1621
+ throw new Error("invalid I2OSP length: " + length);
1622
+ if (value < 0 || value > 2 ** (8 * length) - 1)
1623
+ throw new Error("invalid I2OSP input: " + value);
1624
+ const res = Array.from({ length }).fill(0);
1625
+ for (let i = length - 1; i >= 0; i--) {
1626
+ res[i] = value & 255;
1627
+ value >>>= 8;
1961
1628
  }
1962
- double() {
1963
- return this.init(this.ep.double());
1629
+ return new Uint8Array(res);
1630
+ }
1631
+ function strxor(a, b) {
1632
+ const arr = new Uint8Array(a.length);
1633
+ for (let i = 0; i < a.length; i++) {
1634
+ arr[i] = a[i] ^ b[i];
1964
1635
  }
1965
- negate() {
1966
- return this.init(this.ep.negate());
1636
+ return arr;
1637
+ }
1638
+ function normDST(DST) {
1639
+ if (!isBytes2(DST) && typeof DST !== "string")
1640
+ throw new Error("DST must be Uint8Array or ascii string");
1641
+ const dst = typeof DST === "string" ? asciiToBytes(DST) : DST;
1642
+ if (dst.length === 0)
1643
+ throw new Error("DST must be non-empty");
1644
+ return dst;
1645
+ }
1646
+ function expand_message_xmd(msg, DST, lenInBytes, H) {
1647
+ abytes2(msg);
1648
+ asafenumber(lenInBytes);
1649
+ DST = normDST(DST);
1650
+ if (DST.length > 255)
1651
+ DST = H(concatBytes2(asciiToBytes("H2C-OVERSIZE-DST-"), DST));
1652
+ const { outputLen: b_in_bytes, blockLen: r_in_bytes } = H;
1653
+ const ell = Math.ceil(lenInBytes / b_in_bytes);
1654
+ if (lenInBytes > 65535 || ell > 255)
1655
+ throw new Error("expand_message_xmd: invalid lenInBytes");
1656
+ const DST_prime = concatBytes2(DST, i2osp(DST.length, 1));
1657
+ const Z_pad = new Uint8Array(r_in_bytes);
1658
+ const l_i_b_str = i2osp(lenInBytes, 2);
1659
+ const b = new Array(ell);
1660
+ const b_0 = H(concatBytes2(Z_pad, msg, l_i_b_str, i2osp(0, 1), DST_prime));
1661
+ b[0] = H(concatBytes2(b_0, i2osp(1, 1), DST_prime));
1662
+ for (let i = 1; i < ell; i++) {
1663
+ const args = [strxor(b_0, b[i - 1]), i2osp(i + 1, 1), DST_prime];
1664
+ b[i] = H(concatBytes2(...args));
1967
1665
  }
1968
- precompute(windowSize, isLazy) {
1969
- this.ep.precompute(windowSize, isLazy);
1970
- return this;
1666
+ const pseudo_random_bytes = concatBytes2(...b);
1667
+ return pseudo_random_bytes.slice(0, lenInBytes);
1668
+ }
1669
+ function expand_message_xof(msg, DST, lenInBytes, k, H) {
1670
+ abytes2(msg);
1671
+ asafenumber(lenInBytes);
1672
+ DST = normDST(DST);
1673
+ if (DST.length > 255) {
1674
+ const dkLen = Math.ceil(2 * k / 8);
1675
+ DST = H.create({ dkLen }).update(asciiToBytes("H2C-OVERSIZE-DST-")).update(DST).digest();
1971
1676
  }
1972
- };
1973
- function eddsa(Point, cHash, eddsaOpts = {}) {
1974
- if (typeof cHash !== "function")
1975
- throw new Error('"hash" function param is required');
1976
- const hash = cHash;
1977
- const opts = eddsaOpts;
1978
- validateObject(opts, {}, {
1979
- adjustScalarBytes: "function",
1980
- randomBytes: "function",
1981
- domain: "function",
1982
- prehash: "function",
1983
- zip215: "boolean",
1984
- mapToCurve: "function"
1677
+ if (lenInBytes > 65535 || DST.length > 255)
1678
+ throw new Error("expand_message_xof: invalid lenInBytes");
1679
+ return H.create({ dkLen: lenInBytes }).update(msg).update(i2osp(lenInBytes, 2)).update(DST).update(i2osp(DST.length, 1)).digest();
1680
+ }
1681
+ function hash_to_field(msg, count, options) {
1682
+ validateObject(options, {
1683
+ p: "bigint",
1684
+ m: "number",
1685
+ k: "number",
1686
+ hash: "function"
1985
1687
  });
1986
- const { prehash } = opts;
1987
- const { BASE, Fp: Fp2, Fn: Fn2 } = Point;
1988
- const outputLen = hash.outputLen;
1989
- const expectedLen = 2 * Fp2.BYTES;
1990
- if (outputLen !== void 0) {
1991
- asafenumber(outputLen, "hash.outputLen");
1992
- if (outputLen !== expectedLen)
1993
- throw new Error(`hash.outputLen must be ${expectedLen}, got ${outputLen}`);
1994
- }
1995
- const randomBytes3 = opts.randomBytes === void 0 ? randomBytes2 : opts.randomBytes;
1996
- const adjustScalarBytes2 = opts.adjustScalarBytes === void 0 ? (bytes) => bytes : opts.adjustScalarBytes;
1997
- const domain = opts.domain === void 0 ? (data, ctx, phflag) => {
1998
- abool(phflag, "phflag");
1999
- if (ctx.length || phflag)
2000
- throw new Error("Contexts/pre-hash are not supported");
2001
- return data;
2002
- } : opts.domain;
2003
- function modN_LE(hash2) {
2004
- return Fn2.create(bytesToNumberLE(hash2));
2005
- }
2006
- function getPrivateScalar(key) {
2007
- const len = lengths.secretKey;
2008
- abytes2(key, lengths.secretKey, "secretKey");
2009
- const hashed = abytes2(hash(key), 2 * len, "hashedSecretKey");
2010
- const head = adjustScalarBytes2(hashed.slice(0, len));
2011
- const prefix = hashed.slice(len, 2 * len);
2012
- const scalar = modN_LE(head);
2013
- return { head, prefix, scalar };
2014
- }
2015
- function getExtendedPublicKey(secretKey) {
2016
- const { head, prefix, scalar } = getPrivateScalar(secretKey);
2017
- const point = BASE.multiply(scalar);
2018
- const pointBytes = point.toBytes();
2019
- return { head, prefix, scalar, point, pointBytes };
2020
- }
2021
- function getPublicKey(secretKey) {
2022
- return getExtendedPublicKey(secretKey).pointBytes;
2023
- }
2024
- function hashDomainToScalar(context = Uint8Array.of(), ...msgs) {
2025
- const msg = concatBytes2(...msgs);
2026
- return modN_LE(hash(domain(msg, abytes2(context, void 0, "context"), !!prehash)));
2027
- }
2028
- function sign(msg, secretKey, options = {}) {
2029
- msg = abytes2(msg, void 0, "message");
2030
- if (prehash)
2031
- msg = prehash(msg);
2032
- const { prefix, scalar, pointBytes } = getExtendedPublicKey(secretKey);
2033
- const r = hashDomainToScalar(options.context, prefix, msg);
2034
- const R = BASE.multiply(r).toBytes();
2035
- const k = hashDomainToScalar(options.context, R, pointBytes, msg);
2036
- const s = Fn2.create(r + k * scalar);
2037
- if (!Fn2.isValid(s))
2038
- throw new Error("sign failed: invalid s");
2039
- const rs = concatBytes2(R, Fn2.toBytes(s));
2040
- return abytes2(rs, lengths.signature, "result");
2041
- }
2042
- const verifyOpts = {
2043
- zip215: opts.zip215
2044
- };
2045
- function verify(sig, msg, publicKey, options = verifyOpts) {
2046
- const { context } = options;
2047
- const zip215 = options.zip215 === void 0 ? !!verifyOpts.zip215 : options.zip215;
2048
- const len = lengths.signature;
2049
- sig = abytes2(sig, len, "signature");
2050
- msg = abytes2(msg, void 0, "message");
2051
- publicKey = abytes2(publicKey, lengths.publicKey, "publicKey");
2052
- if (zip215 !== void 0)
2053
- abool(zip215, "zip215");
2054
- if (prehash)
2055
- msg = prehash(msg);
2056
- const mid = len / 2;
2057
- const r = sig.subarray(0, mid);
2058
- const s = bytesToNumberLE(sig.subarray(mid, len));
2059
- let A, R, SB;
2060
- try {
2061
- A = Point.fromBytes(publicKey, zip215);
2062
- R = Point.fromBytes(r, zip215);
2063
- SB = BASE.multiplyUnsafe(s);
2064
- } catch (error) {
2065
- return false;
1688
+ const { p, k, m, hash, expand, DST } = options;
1689
+ asafenumber(hash.outputLen, "valid hash");
1690
+ abytes2(msg);
1691
+ asafenumber(count);
1692
+ if (count < 1)
1693
+ throw new Error("hash_to_field: expected count >= 1");
1694
+ if (m < 1)
1695
+ throw new Error("hash_to_field: expected m >= 1");
1696
+ const log2p = p.toString(2).length;
1697
+ const L = Math.ceil((log2p + k) / 8);
1698
+ const len_in_bytes = count * m * L;
1699
+ let prb;
1700
+ if (expand === "xmd") {
1701
+ prb = expand_message_xmd(msg, DST, len_in_bytes, hash);
1702
+ } else if (expand === "xof") {
1703
+ prb = expand_message_xof(msg, DST, len_in_bytes, k, hash);
1704
+ } else if (expand === "_internal_pass") {
1705
+ prb = msg;
1706
+ } else {
1707
+ throw new Error('expand must be "xmd" or "xof"');
1708
+ }
1709
+ const u = new Array(count);
1710
+ for (let i = 0; i < count; i++) {
1711
+ const e = new Array(m);
1712
+ for (let j = 0; j < m; j++) {
1713
+ const elm_offset = L * (j + i * m);
1714
+ const tv = prb.subarray(elm_offset, elm_offset + L);
1715
+ e[j] = mod(os2ip(tv), p);
2066
1716
  }
2067
- if (!zip215 && A.isSmallOrder())
2068
- return false;
2069
- const k = hashDomainToScalar(context, r, publicKey, msg);
2070
- const RkA = R.add(A.multiplyUnsafe(k));
2071
- return RkA.subtract(SB).clearCofactor().is0();
2072
- }
2073
- const _size = Fp2.BYTES;
2074
- const lengths = {
2075
- secretKey: _size,
2076
- publicKey: _size,
2077
- signature: 2 * _size,
2078
- seed: _size
2079
- };
2080
- function randomSecretKey(seed) {
2081
- seed = seed === void 0 ? randomBytes3(lengths.seed) : seed;
2082
- return abytes2(seed, lengths.seed, "seed");
1717
+ u[i] = e;
2083
1718
  }
2084
- function isValidSecretKey(key) {
2085
- return isBytes2(key) && key.length === lengths.secretKey;
1719
+ return u;
1720
+ }
1721
+ var _DST_scalar = "HashToScalar-";
1722
+ function createHasher2(Point, mapToCurve, defaults) {
1723
+ if (typeof mapToCurve !== "function")
1724
+ throw new Error("mapToCurve() must be defined");
1725
+ const snapshot = (src) => Object.freeze({
1726
+ ...src,
1727
+ DST: isBytes2(src.DST) ? copyBytes(src.DST) : src.DST,
1728
+ ...src.encodeDST === void 0 ? {} : { encodeDST: isBytes2(src.encodeDST) ? copyBytes(src.encodeDST) : src.encodeDST }
1729
+ });
1730
+ const safeDefaults = snapshot(defaults);
1731
+ function map(num) {
1732
+ return Point.fromAffine(mapToCurve(num));
2086
1733
  }
2087
- function isValidPublicKey(key, zip215) {
2088
- try {
2089
- return !!Point.fromBytes(key, zip215 === void 0 ? verifyOpts.zip215 : zip215);
2090
- } catch (error) {
2091
- return false;
2092
- }
1734
+ function clear(initial) {
1735
+ const P = initial.clearCofactor();
1736
+ if (P.equals(Point.ZERO))
1737
+ return Point.ZERO;
1738
+ P.assertValidity();
1739
+ return P;
2093
1740
  }
2094
- const utils = {
2095
- getExtendedPublicKey,
2096
- randomSecretKey,
2097
- isValidSecretKey,
2098
- isValidPublicKey,
2099
- /**
2100
- * Converts ed public key to x public key. Uses formula:
2101
- * - ed25519:
2102
- * - `(u, v) = ((1+y)/(1-y), sqrt(-486664)*u/x)`
2103
- * - `(x, y) = (sqrt(-486664)*u/v, (u-1)/(u+1))`
2104
- * - ed448:
2105
- * - `(u, v) = ((y-1)/(y+1), sqrt(156324)*u/x)`
2106
- * - `(x, y) = (sqrt(156324)*u/v, (1+u)/(1-u))`
2107
- */
2108
- toMontgomery(publicKey) {
2109
- const { y } = Point.fromBytes(publicKey);
2110
- const size = lengths.publicKey;
2111
- const is25519 = size === 32;
2112
- if (!is25519 && size !== 57)
2113
- throw new Error("only defined for 25519 and 448");
2114
- const u = is25519 ? Fp2.div(_1n4 + y, _1n4 - y) : Fp2.div(y - _1n4, y + _1n4);
2115
- return Fp2.toBytes(u);
2116
- },
2117
- toMontgomerySecret(secretKey) {
2118
- const size = lengths.secretKey;
2119
- abytes2(secretKey, size);
2120
- const hashed = hash(secretKey.subarray(0, size));
2121
- return adjustScalarBytes2(hashed).subarray(0, size);
2122
- }
2123
- };
2124
- Object.freeze(lengths);
2125
- Object.freeze(utils);
2126
1741
  return Object.freeze({
2127
- keygen: createKeygen(randomSecretKey, getPublicKey),
2128
- getPublicKey,
2129
- sign,
2130
- verify,
2131
- utils,
1742
+ get defaults() {
1743
+ return snapshot(safeDefaults);
1744
+ },
2132
1745
  Point,
2133
- lengths
1746
+ hashToCurve(msg, options) {
1747
+ const opts = Object.assign({}, safeDefaults, options);
1748
+ const u = hash_to_field(msg, 2, opts);
1749
+ const u0 = map(u[0]);
1750
+ const u1 = map(u[1]);
1751
+ return clear(u0.add(u1));
1752
+ },
1753
+ encodeToCurve(msg, options) {
1754
+ const optsDst = safeDefaults.encodeDST ? { DST: safeDefaults.encodeDST } : {};
1755
+ const opts = Object.assign({}, safeDefaults, optsDst, options);
1756
+ const u = hash_to_field(msg, 1, opts);
1757
+ const u0 = map(u[0]);
1758
+ return clear(u0);
1759
+ },
1760
+ /** See {@link H2CHasher} */
1761
+ mapToCurve(scalars) {
1762
+ if (safeDefaults.m === 1) {
1763
+ if (typeof scalars !== "bigint")
1764
+ throw new Error("expected bigint (m=1)");
1765
+ return clear(map([scalars]));
1766
+ }
1767
+ if (!Array.isArray(scalars))
1768
+ throw new Error("expected array of bigints");
1769
+ for (const i of scalars)
1770
+ if (typeof i !== "bigint")
1771
+ throw new Error("expected array of bigints");
1772
+ return clear(map(scalars));
1773
+ },
1774
+ // hash_to_scalar can produce 0: https://www.rfc-editor.org/errata/eid8393
1775
+ // RFC 9380, draft-irtf-cfrg-bbs-signatures-08. Default scalar DST is the shared generic
1776
+ // `HashToScalar-` prefix above unless the caller overrides it per invocation.
1777
+ hashToScalar(msg, options) {
1778
+ const N = Point.Fn.ORDER;
1779
+ const opts = Object.assign({}, safeDefaults, { p: N, m: 1, DST: _DST_scalar }, options);
1780
+ return hash_to_field(msg, 1, opts)[0][0];
1781
+ }
2134
1782
  });
2135
1783
  }
2136
1784
 
@@ -2343,176 +1991,6 @@ function poly(field, roots, create, fft, length) {
2343
1991
  };
2344
1992
  }
2345
1993
 
2346
- // ../../node_modules/.pnpm/@noble+curves@2.2.0/node_modules/@noble/curves/abstract/hash-to-curve.js
2347
- var os2ip = bytesToNumberBE;
2348
- function i2osp(value, length) {
2349
- asafenumber(value);
2350
- asafenumber(length);
2351
- if (length < 0 || length > 4)
2352
- throw new Error("invalid I2OSP length: " + length);
2353
- if (value < 0 || value > 2 ** (8 * length) - 1)
2354
- throw new Error("invalid I2OSP input: " + value);
2355
- const res = Array.from({ length }).fill(0);
2356
- for (let i = length - 1; i >= 0; i--) {
2357
- res[i] = value & 255;
2358
- value >>>= 8;
2359
- }
2360
- return new Uint8Array(res);
2361
- }
2362
- function strxor(a, b) {
2363
- const arr = new Uint8Array(a.length);
2364
- for (let i = 0; i < a.length; i++) {
2365
- arr[i] = a[i] ^ b[i];
2366
- }
2367
- return arr;
2368
- }
2369
- function normDST(DST) {
2370
- if (!isBytes2(DST) && typeof DST !== "string")
2371
- throw new Error("DST must be Uint8Array or ascii string");
2372
- const dst = typeof DST === "string" ? asciiToBytes(DST) : DST;
2373
- if (dst.length === 0)
2374
- throw new Error("DST must be non-empty");
2375
- return dst;
2376
- }
2377
- function expand_message_xmd(msg, DST, lenInBytes, H) {
2378
- abytes2(msg);
2379
- asafenumber(lenInBytes);
2380
- DST = normDST(DST);
2381
- if (DST.length > 255)
2382
- DST = H(concatBytes2(asciiToBytes("H2C-OVERSIZE-DST-"), DST));
2383
- const { outputLen: b_in_bytes, blockLen: r_in_bytes } = H;
2384
- const ell = Math.ceil(lenInBytes / b_in_bytes);
2385
- if (lenInBytes > 65535 || ell > 255)
2386
- throw new Error("expand_message_xmd: invalid lenInBytes");
2387
- const DST_prime = concatBytes2(DST, i2osp(DST.length, 1));
2388
- const Z_pad = new Uint8Array(r_in_bytes);
2389
- const l_i_b_str = i2osp(lenInBytes, 2);
2390
- const b = new Array(ell);
2391
- const b_0 = H(concatBytes2(Z_pad, msg, l_i_b_str, i2osp(0, 1), DST_prime));
2392
- b[0] = H(concatBytes2(b_0, i2osp(1, 1), DST_prime));
2393
- for (let i = 1; i < ell; i++) {
2394
- const args = [strxor(b_0, b[i - 1]), i2osp(i + 1, 1), DST_prime];
2395
- b[i] = H(concatBytes2(...args));
2396
- }
2397
- const pseudo_random_bytes = concatBytes2(...b);
2398
- return pseudo_random_bytes.slice(0, lenInBytes);
2399
- }
2400
- function expand_message_xof(msg, DST, lenInBytes, k, H) {
2401
- abytes2(msg);
2402
- asafenumber(lenInBytes);
2403
- DST = normDST(DST);
2404
- if (DST.length > 255) {
2405
- const dkLen = Math.ceil(2 * k / 8);
2406
- DST = H.create({ dkLen }).update(asciiToBytes("H2C-OVERSIZE-DST-")).update(DST).digest();
2407
- }
2408
- if (lenInBytes > 65535 || DST.length > 255)
2409
- throw new Error("expand_message_xof: invalid lenInBytes");
2410
- return H.create({ dkLen: lenInBytes }).update(msg).update(i2osp(lenInBytes, 2)).update(DST).update(i2osp(DST.length, 1)).digest();
2411
- }
2412
- function hash_to_field(msg, count, options) {
2413
- validateObject(options, {
2414
- p: "bigint",
2415
- m: "number",
2416
- k: "number",
2417
- hash: "function"
2418
- });
2419
- const { p, k, m, hash, expand, DST } = options;
2420
- asafenumber(hash.outputLen, "valid hash");
2421
- abytes2(msg);
2422
- asafenumber(count);
2423
- if (count < 1)
2424
- throw new Error("hash_to_field: expected count >= 1");
2425
- if (m < 1)
2426
- throw new Error("hash_to_field: expected m >= 1");
2427
- const log2p = p.toString(2).length;
2428
- const L = Math.ceil((log2p + k) / 8);
2429
- const len_in_bytes = count * m * L;
2430
- let prb;
2431
- if (expand === "xmd") {
2432
- prb = expand_message_xmd(msg, DST, len_in_bytes, hash);
2433
- } else if (expand === "xof") {
2434
- prb = expand_message_xof(msg, DST, len_in_bytes, k, hash);
2435
- } else if (expand === "_internal_pass") {
2436
- prb = msg;
2437
- } else {
2438
- throw new Error('expand must be "xmd" or "xof"');
2439
- }
2440
- const u = new Array(count);
2441
- for (let i = 0; i < count; i++) {
2442
- const e = new Array(m);
2443
- for (let j = 0; j < m; j++) {
2444
- const elm_offset = L * (j + i * m);
2445
- const tv = prb.subarray(elm_offset, elm_offset + L);
2446
- e[j] = mod(os2ip(tv), p);
2447
- }
2448
- u[i] = e;
2449
- }
2450
- return u;
2451
- }
2452
- var _DST_scalar = "HashToScalar-";
2453
- function createHasher2(Point, mapToCurve, defaults) {
2454
- if (typeof mapToCurve !== "function")
2455
- throw new Error("mapToCurve() must be defined");
2456
- const snapshot = (src) => Object.freeze({
2457
- ...src,
2458
- DST: isBytes2(src.DST) ? copyBytes(src.DST) : src.DST,
2459
- ...src.encodeDST === void 0 ? {} : { encodeDST: isBytes2(src.encodeDST) ? copyBytes(src.encodeDST) : src.encodeDST }
2460
- });
2461
- const safeDefaults = snapshot(defaults);
2462
- function map(num) {
2463
- return Point.fromAffine(mapToCurve(num));
2464
- }
2465
- function clear(initial) {
2466
- const P = initial.clearCofactor();
2467
- if (P.equals(Point.ZERO))
2468
- return Point.ZERO;
2469
- P.assertValidity();
2470
- return P;
2471
- }
2472
- return Object.freeze({
2473
- get defaults() {
2474
- return snapshot(safeDefaults);
2475
- },
2476
- Point,
2477
- hashToCurve(msg, options) {
2478
- const opts = Object.assign({}, safeDefaults, options);
2479
- const u = hash_to_field(msg, 2, opts);
2480
- const u0 = map(u[0]);
2481
- const u1 = map(u[1]);
2482
- return clear(u0.add(u1));
2483
- },
2484
- encodeToCurve(msg, options) {
2485
- const optsDst = safeDefaults.encodeDST ? { DST: safeDefaults.encodeDST } : {};
2486
- const opts = Object.assign({}, safeDefaults, optsDst, options);
2487
- const u = hash_to_field(msg, 1, opts);
2488
- const u0 = map(u[0]);
2489
- return clear(u0);
2490
- },
2491
- /** See {@link H2CHasher} */
2492
- mapToCurve(scalars) {
2493
- if (safeDefaults.m === 1) {
2494
- if (typeof scalars !== "bigint")
2495
- throw new Error("expected bigint (m=1)");
2496
- return clear(map([scalars]));
2497
- }
2498
- if (!Array.isArray(scalars))
2499
- throw new Error("expected array of bigints");
2500
- for (const i of scalars)
2501
- if (typeof i !== "bigint")
2502
- throw new Error("expected array of bigints");
2503
- return clear(map(scalars));
2504
- },
2505
- // hash_to_scalar can produce 0: https://www.rfc-editor.org/errata/eid8393
2506
- // RFC 9380, draft-irtf-cfrg-bbs-signatures-08. Default scalar DST is the shared generic
2507
- // `HashToScalar-` prefix above unless the caller overrides it per invocation.
2508
- hashToScalar(msg, options) {
2509
- const N = Point.Fn.ORDER;
2510
- const opts = Object.assign({}, safeDefaults, { p: N, m: 1, DST: _DST_scalar }, options);
2511
- return hash_to_field(msg, 1, opts)[0][0];
2512
- }
2513
- });
2514
- }
2515
-
2516
1994
  // ../../node_modules/.pnpm/@noble+curves@2.2.0/node_modules/@noble/curves/abstract/frost.js
2517
1995
  var validateSigners = (signers) => {
2518
1996
  if (!Number.isSafeInteger(signers.min) || !Number.isSafeInteger(signers.max))
@@ -2551,11 +2029,11 @@ function createFROST(opts) {
2551
2029
  });
2552
2030
  validatePointCons(opts.Point);
2553
2031
  const { Point } = opts;
2554
- const Fn2 = opts.Fn === void 0 ? Point.Fn : opts.Fn;
2032
+ const Fn = opts.Fn === void 0 ? Point.Fn : opts.Fn;
2555
2033
  const hashBytes = opts.hash;
2556
2034
  const hashToScalar = opts.hashToScalar === void 0 ? (msg, opts2 = { DST: new Uint8Array() }) => {
2557
2035
  const t = hashBytes(concatBytes2(opts2.DST, msg));
2558
- return Fn2.create(Fn2.isLE ? bytesToNumberLE(t) : bytesToNumberBE(t));
2036
+ return Fn.create(Fn.isLE ? bytesToNumberLE(t) : bytesToNumberBE(t));
2559
2037
  } : opts.hashToScalar;
2560
2038
  const H1Prefix = utf8ToBytes(opts.H1 !== void 0 ? opts.H1 : opts.name + "rho");
2561
2039
  const H2Prefix = utf8ToBytes(opts.H2 !== void 0 ? opts.H2 : opts.name + "chal");
@@ -2572,8 +2050,8 @@ function createFROST(opts) {
2572
2050
  const HDKG = (msg) => hashToScalar(msg, { DST: HDKGPrefix });
2573
2051
  const HID = (msg) => hashToScalar(msg, { DST: HIDPrefix });
2574
2052
  const randomScalar = (rng = randomBytes2) => {
2575
- const t = mapHashToField(rng(getMinHashLength(Fn2.ORDER)), Fn2.ORDER, Fn2.isLE);
2576
- return Fn2.isLE ? bytesToNumberLE(t) : bytesToNumberBE(t);
2053
+ const t = mapHashToField(rng(getMinHashLength(Fn.ORDER)), Fn.ORDER, Fn.isLE);
2054
+ return Fn.isLE ? bytesToNumberLE(t) : bytesToNumberBE(t);
2577
2055
  };
2578
2056
  const serializePoint = (p) => p.toBytes();
2579
2057
  const parsePoint = (bytes) => {
@@ -2584,18 +2062,18 @@ function createFROST(opts) {
2584
2062
  };
2585
2063
  const nonceCommitments = (identifier, nonces) => ({
2586
2064
  identifier,
2587
- hiding: serializePoint(Point.BASE.multiply(Fn2.fromBytes(nonces.hiding))),
2588
- binding: serializePoint(Point.BASE.multiply(Fn2.fromBytes(nonces.binding)))
2065
+ hiding: serializePoint(Point.BASE.multiply(Fn.fromBytes(nonces.hiding))),
2066
+ binding: serializePoint(Point.BASE.multiply(Fn.fromBytes(nonces.binding)))
2589
2067
  });
2590
2068
  const adjustPoint = opts.adjustPoint === void 0 ? (n) => n : opts.adjustPoint;
2591
2069
  const validateIdentifier = (n) => {
2592
- if (!Fn2.isValid(n) || Fn2.is0(n))
2070
+ if (!Fn.isValid(n) || Fn.is0(n))
2593
2071
  throw new Error("Invalid identifier " + n);
2594
2072
  return n;
2595
2073
  };
2596
- const serializeIdentifier = (id) => bytesToHex2(Fn2.toBytes(validateIdentifier(id)));
2074
+ const serializeIdentifier = (id) => bytesToHex2(Fn.toBytes(validateIdentifier(id)));
2597
2075
  const parseIdentifier = (id) => {
2598
- const n = validateIdentifier(Fn2.fromBytes(hexToBytes2(id)));
2076
+ const n = validateIdentifier(Fn.fromBytes(hexToBytes2(id)));
2599
2077
  if (serializeIdentifier(n) !== id)
2600
2078
  throw new Error("expected canonical identifier hex");
2601
2079
  return n;
@@ -2604,7 +2082,7 @@ function createFROST(opts) {
2604
2082
  // RFC 9591 Appendix A encodes signatures canonically as
2605
2083
  // SerializeElement(R) || SerializeScalar(z).
2606
2084
  encode: (R, z) => {
2607
- let res = concatBytes2(serializePoint(R), Fn2.toBytes(z));
2085
+ let res = concatBytes2(serializePoint(R), Fn.toBytes(z));
2608
2086
  if (opts.adjustTx)
2609
2087
  res = opts.adjustTx.encode(res);
2610
2088
  return res;
@@ -2612,8 +2090,8 @@ function createFROST(opts) {
2612
2090
  decode: (sig) => {
2613
2091
  if (opts.adjustTx)
2614
2092
  sig = opts.adjustTx.decode(sig);
2615
- const R = parsePoint(sig.subarray(0, -Fn2.BYTES));
2616
- const z = Fn2.fromBytes(sig.subarray(-Fn2.BYTES));
2093
+ const R = parsePoint(sig.subarray(0, -Fn.BYTES));
2094
+ const z = Fn.fromBytes(sig.subarray(-Fn.BYTES));
2617
2095
  return { R, z };
2618
2096
  }
2619
2097
  };
@@ -2626,7 +2104,7 @@ function createFROST(opts) {
2626
2104
  };
2627
2105
  const nrErr = "roots are unavailable in FROST polynomial mode";
2628
2106
  const noRoots = {
2629
- info: { G: Fn2.ZERO, oddFactor: Fn2.ZERO, powerOfTwo: 0 },
2107
+ info: { G: Fn.ZERO, oddFactor: Fn.ZERO, powerOfTwo: 0 },
2630
2108
  roots() {
2631
2109
  throw new Error(nrErr);
2632
2110
  },
@@ -2642,7 +2120,7 @@ function createFROST(opts) {
2642
2120
  clear() {
2643
2121
  }
2644
2122
  };
2645
- const Poly = poly(Fn2, noRoots);
2123
+ const Poly = poly(Fn, noRoots);
2646
2124
  const msm = (points, scalars) => pippenger(Point, points, scalars);
2647
2125
  const polynomialEvaluate = (x, coeffs) => {
2648
2126
  if (!coeffs.length)
@@ -2651,22 +2129,22 @@ function createFROST(opts) {
2651
2129
  };
2652
2130
  const deriveInterpolatingValue = (L, xi) => {
2653
2131
  const err = "invalid parameters";
2654
- if (!L.some((x) => Fn2.eql(x, xi)))
2132
+ if (!L.some((x) => Fn.eql(x, xi)))
2655
2133
  throw new Error(err);
2656
2134
  const Lset = new Set(L);
2657
2135
  if (Lset.size !== L.length)
2658
2136
  throw new Error(err);
2659
2137
  if (!Lset.has(xi))
2660
2138
  throw new Error(err);
2661
- let num = Fn2.ONE;
2662
- let den = Fn2.ONE;
2139
+ let num = Fn.ONE;
2140
+ let den = Fn.ONE;
2663
2141
  for (const x of L) {
2664
- if (Fn2.eql(x, xi))
2142
+ if (Fn.eql(x, xi))
2665
2143
  continue;
2666
- num = Fn2.mul(num, x);
2667
- den = Fn2.mul(den, Fn2.sub(x, xi));
2144
+ num = Fn.mul(num, x);
2145
+ den = Fn.mul(den, Fn.sub(x, xi));
2668
2146
  }
2669
- return Fn2.div(num, den);
2147
+ return Fn.div(num, den);
2670
2148
  };
2671
2149
  const evalutateVSS = (identifier, commitment) => {
2672
2150
  const monomial = Poly.monomial.basis(identifier, commitment.length);
@@ -2674,7 +2152,7 @@ function createFROST(opts) {
2674
2152
  };
2675
2153
  const generateSecretPolynomial = (signers, secret, coeffs, rng = randomBytes2) => {
2676
2154
  validateSigners(signers);
2677
- const secretScalar = secret === void 0 ? randomScalar(rng) : Fn2.fromBytes(secret);
2155
+ const secretScalar = secret === void 0 ? randomScalar(rng) : Fn.fromBytes(secret);
2678
2156
  if (!coeffs) {
2679
2157
  coeffs = [];
2680
2158
  for (let i = 0; i < signers.min - 1; i++)
@@ -2687,14 +2165,14 @@ function createFROST(opts) {
2687
2165
  return { coefficients, commitment, secret: secretScalar };
2688
2166
  };
2689
2167
  const ProofOfKnowledge = {
2690
- challenge: (id, verKey, R) => HDKG(concatBytes2(Fn2.toBytes(id), serializePoint(verKey), serializePoint(R))),
2168
+ challenge: (id, verKey, R) => HDKG(concatBytes2(Fn.toBytes(id), serializePoint(verKey), serializePoint(R))),
2691
2169
  compute(id, coefficents, commitments, rng = randomBytes2) {
2692
2170
  if (coefficents.length < 1)
2693
2171
  throw new Error("coefficients should have at least one element");
2694
2172
  const { point: R, scalar: k } = genPointScalarPair(rng);
2695
2173
  const verKey = commitments[0];
2696
2174
  const c = this.challenge(id, verKey, R);
2697
- const mu = Fn2.add(k, Fn2.mul(coefficents[0], c));
2175
+ const mu = Fn.add(k, Fn.mul(coefficents[0], c));
2698
2176
  return Signature.encode(R, mu);
2699
2177
  },
2700
2178
  validate(id, commitment, proof) {
@@ -2717,7 +2195,7 @@ function createFROST(opts) {
2717
2195
  const { point: R, scalar: r } = genPointScalarPair(rng);
2718
2196
  const PK = Point.BASE.multiply(sk);
2719
2197
  const c = this.challenge(R, PK, msg);
2720
- const z = Fn2.add(r, Fn2.mul(c, sk));
2198
+ const z = Fn.add(r, Fn.mul(c, sk));
2721
2199
  return [R, z];
2722
2200
  },
2723
2201
  verify(msg, R, z, PK) {
@@ -2752,7 +2230,7 @@ function createFROST(opts) {
2752
2230
  return serializeIdentifier(HID(utf8ToBytes(s)));
2753
2231
  }
2754
2232
  };
2755
- const generateNonce = (secret, rng = randomBytes2) => H3(concatBytes2(rng(32), Fn2.toBytes(secret)));
2233
+ const generateNonce = (secret, rng = randomBytes2) => H3(concatBytes2(rng(32), Fn.toBytes(secret)));
2756
2234
  const getGroupCommitment = (GPK, commitmentList, msg) => {
2757
2235
  const CL = commitmentList.map((i) => [
2758
2236
  i.identifier,
@@ -2763,12 +2241,12 @@ function createFROST(opts) {
2763
2241
  CL.sort((a, b) => a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0);
2764
2242
  const Cbytes = [];
2765
2243
  for (const [_, id, hC, bC] of CL)
2766
- Cbytes.push(Fn2.toBytes(id), serializePoint(hC), serializePoint(bC));
2244
+ Cbytes.push(Fn.toBytes(id), serializePoint(hC), serializePoint(bC));
2767
2245
  const encodedCommitmentHash = H5(concatBytes2(...Cbytes));
2768
2246
  const rhoPrefix = concatBytes2(serializePoint(GPK), H4(msg), encodedCommitmentHash);
2769
2247
  const bindingFactors = {};
2770
2248
  for (const [i, id] of CL) {
2771
- bindingFactors[i] = H1(concatBytes2(rhoPrefix, Fn2.toBytes(id)));
2249
+ bindingFactors[i] = H1(concatBytes2(rhoPrefix, Fn.toBytes(id)));
2772
2250
  }
2773
2251
  const points = [];
2774
2252
  const scalars = [];
@@ -2776,7 +2254,7 @@ function createFROST(opts) {
2776
2254
  if (Point.ZERO.equals(hC) || Point.ZERO.equals(bC))
2777
2255
  throw new Error("infinity commitment");
2778
2256
  points.push(hC, bC);
2779
- scalars.push(Fn2.ONE, bindingFactors[i]);
2257
+ scalars.push(Fn.ONE, bindingFactors[i]);
2780
2258
  }
2781
2259
  const groupCommitment = msm(points, scalars);
2782
2260
  const identifiers = CL.map((i) => i[1]);
@@ -2836,7 +2314,7 @@ function createFROST(opts) {
2836
2314
  parsePoint(c);
2837
2315
  if (res[p.identifier])
2838
2316
  throw new Error("Duplicate id=" + id);
2839
- const signingShare = Fn2.toBytes(polynomialEvaluate(id, secret.coefficients));
2317
+ const signingShare = Fn.toBytes(polynomialEvaluate(id, secret.coefficients));
2840
2318
  res[p.identifier] = {
2841
2319
  identifier: serializeIdentifier(secret.identifier),
2842
2320
  signingShare
@@ -2867,7 +2345,7 @@ function createFROST(opts) {
2867
2345
  }
2868
2346
  if (Object.keys(merged).length !== round1.length)
2869
2347
  throw new Error("mismatch identifiers between rounds");
2870
- let signingShare = Fn2.ZERO;
2348
+ let signingShare = Fn.ZERO;
2871
2349
  if (secret.commitment.length !== secret.signers.min)
2872
2350
  throw new Error("wrong commitments length");
2873
2351
  const localCommitment = secret.commitment.map(parsePoint);
@@ -2882,16 +2360,16 @@ function createFROST(opts) {
2882
2360
  if (!v.signingShare || !v.commitment)
2883
2361
  throw new Error("mismatch identifiers");
2884
2362
  const id = parseIdentifier(k);
2885
- const signingSharePart = Fn2.fromBytes(v.signingShare);
2363
+ const signingSharePart = Fn.fromBytes(v.signingShare);
2886
2364
  const commitment = v.commitment.map(parsePoint);
2887
2365
  validateSecretShare(secret.identifier, commitment, signingSharePart);
2888
- signingShare = Fn2.add(signingShare, signingSharePart);
2366
+ signingShare = Fn.add(signingShare, signingSharePart);
2889
2367
  const idSer = serializeIdentifier(id);
2890
2368
  if (commitments[idSer])
2891
2369
  throw new Error("duplicated id=" + idSer);
2892
2370
  commitments[idSer] = v.commitment;
2893
2371
  }
2894
- signingShare = Fn2.add(signingShare, localShare);
2372
+ signingShare = Fn.add(signingShare, localShare);
2895
2373
  const mergedCommitment = new Array(secret.signers.min).fill(Point.ZERO);
2896
2374
  for (const k in commitments) {
2897
2375
  const v = commitments[k];
@@ -2912,7 +2390,7 @@ function createFROST(opts) {
2912
2390
  },
2913
2391
  secret: {
2914
2392
  identifier: serializeIdentifier(secret.identifier),
2915
- signingShare: Fn2.toBytes(signingShare)
2393
+ signingShare: Fn.toBytes(signingShare)
2916
2394
  }
2917
2395
  };
2918
2396
  if (opts.adjustDKG)
@@ -2960,7 +2438,7 @@ function createFROST(opts) {
2960
2438
  verifyingShares[id] = serializePoint(Point.BASE.multiply(signingShare));
2961
2439
  secretShares[id] = {
2962
2440
  identifier: id,
2963
- signingShare: Fn2.toBytes(signingShare)
2441
+ signingShare: Fn.toBytes(signingShare)
2964
2442
  };
2965
2443
  }
2966
2444
  return {
@@ -2976,7 +2454,7 @@ function createFROST(opts) {
2976
2454
  validateSecret(secret, pub) {
2977
2455
  const id = parseIdentifier(secret.identifier);
2978
2456
  const commitment = pub.commitments.map(parsePoint);
2979
- const signingShare = Fn2.fromBytes(secret.signingShare);
2457
+ const signingShare = Fn.fromBytes(secret.signingShare);
2980
2458
  validateSecretShare(id, commitment, signingShare);
2981
2459
  },
2982
2460
  // Actual signing
@@ -2987,19 +2465,19 @@ function createFROST(opts) {
2987
2465
  // round1 for signing.
2988
2466
  // But then each participant needs to remember generated shares
2989
2467
  commit(secret, rng = randomBytes2) {
2990
- const secretScalar = Fn2.fromBytes(secret.signingShare);
2468
+ const secretScalar = Fn.fromBytes(secret.signingShare);
2991
2469
  const hiding = generateNonce(secretScalar, rng);
2992
2470
  const binding = generateNonce(secretScalar, rng);
2993
- const nonces = { hiding: Fn2.toBytes(hiding), binding: Fn2.toBytes(binding) };
2471
+ const nonces = { hiding: Fn.toBytes(hiding), binding: Fn.toBytes(binding) };
2994
2472
  return { nonces, commitments: nonceCommitments(secret.identifier, nonces) };
2995
2473
  },
2996
2474
  // Round2: sign. Each participant creates a signature share from the secret
2997
2475
  // and the selected nonce commitments.
2998
2476
  signShare(secret, pub, nonces, commitmentList, msg) {
2999
2477
  validateCommitmentsNum(pub.signers, commitmentList.length);
3000
- const hidingNonce0 = Fn2.fromBytes(nonces.hiding);
3001
- const bindingNonce0 = Fn2.fromBytes(nonces.binding);
3002
- if (Fn2.is0(hidingNonce0) || Fn2.is0(bindingNonce0))
2478
+ const hidingNonce0 = Fn.fromBytes(nonces.hiding);
2479
+ const bindingNonce0 = Fn.fromBytes(nonces.binding);
2480
+ if (Fn.is0(hidingNonce0) || Fn.is0(bindingNonce0))
3003
2481
  throw new Error("signing nonces already used");
3004
2482
  const expectedCommitment = {
3005
2483
  identifier: secret.identifier,
@@ -3015,14 +2493,14 @@ function createFROST(opts) {
3015
2493
  secret = opts.adjustSecret(secret, pub);
3016
2494
  if (opts.adjustPublic)
3017
2495
  pub = opts.adjustPublic(pub);
3018
- const SK = Fn2.fromBytes(secret.signingShare);
2496
+ const SK = Fn.fromBytes(secret.signingShare);
3019
2497
  const { lambda, challenge, bindingFactor, groupCommitment } = prepareShare(pub.commitments[0], commitmentList, msg, secret.identifier);
3020
2498
  const N = opts.adjustNonces ? opts.adjustNonces(groupCommitment, nonces) : nonces;
3021
- const hidingNonce = opts.adjustNonces ? Fn2.fromBytes(N.hiding) : hidingNonce0;
3022
- const bindingNonce = opts.adjustNonces ? Fn2.fromBytes(N.binding) : bindingNonce0;
3023
- const t = Fn2.mul(Fn2.mul(lambda, SK), challenge);
3024
- const t2 = Fn2.mul(bindingNonce, bindingFactor);
3025
- const r = Fn2.toBytes(Fn2.add(Fn2.add(hidingNonce, t2), t));
2499
+ const hidingNonce = opts.adjustNonces ? Fn.fromBytes(N.hiding) : hidingNonce0;
2500
+ const bindingNonce = opts.adjustNonces ? Fn.fromBytes(N.binding) : bindingNonce0;
2501
+ const t = Fn.mul(Fn.mul(lambda, SK), challenge);
2502
+ const t2 = Fn.mul(bindingNonce, bindingFactor);
2503
+ const r = Fn.toBytes(Fn.add(Fn.add(hidingNonce, t2), t));
3026
2504
  nonces.hiding.fill(0);
3027
2505
  nonces.binding.fill(0);
3028
2506
  return r;
@@ -3041,8 +2519,8 @@ function createFROST(opts) {
3041
2519
  let commShare = hidingNonceCommitment.add(bindingNonceCommitment.multiply(bindingFactor));
3042
2520
  if (opts.adjustGroupCommitmentShare)
3043
2521
  commShare = opts.adjustGroupCommitmentShare(groupCommitment, commShare);
3044
- const l = Point.BASE.multiply(Fn2.fromBytes(sigShare));
3045
- const r = commShare.add(PK.multiply(Fn2.mul(challenge, lambda)));
2522
+ const l = Point.BASE.multiply(Fn.fromBytes(sigShare));
2523
+ const r = commShare.add(PK.multiply(Fn.mul(challenge, lambda)));
3046
2524
  return l.equals(r);
3047
2525
  },
3048
2526
  // Aggregate multiple signature shares into groupSignature
@@ -3063,9 +2541,9 @@ function createFROST(opts) {
3063
2541
  }
3064
2542
  const GPK = parsePoint(pub.commitments[0]);
3065
2543
  const { groupCommitment } = getGroupCommitment(GPK, commitmentList, msg);
3066
- let z = Fn2.ZERO;
2544
+ let z = Fn.ZERO;
3067
2545
  for (const id of ids)
3068
- z = Fn2.add(z, Fn2.fromBytes(sigShares[id]));
2546
+ z = Fn.add(z, Fn.fromBytes(sigShares[id]));
3069
2547
  if (!Basic.verify(msg, groupCommitment, z, GPK)) {
3070
2548
  const cheaters = [];
3071
2549
  for (const id of ids) {
@@ -3078,7 +2556,7 @@ function createFROST(opts) {
3078
2556
  },
3079
2557
  // Basic sign/verify using single key
3080
2558
  sign(msg, secretKey) {
3081
- let sk = Fn2.fromBytes(secretKey);
2559
+ let sk = Fn.fromBytes(secretKey);
3082
2560
  if (opts.adjustScalar)
3083
2561
  sk = opts.adjustScalar(sk);
3084
2562
  const [R, z] = Basic.sign(msg, sk);
@@ -3102,21 +2580,21 @@ function createFROST(opts) {
3102
2580
  if (seen[id])
3103
2581
  throw new Error("duplicated id=" + id);
3104
2582
  seen[id] = true;
3105
- points.push([idNum, Fn2.fromBytes(s.signingShare)]);
2583
+ points.push([idNum, Fn.fromBytes(s.signingShare)]);
3106
2584
  }
3107
2585
  const xCoords = points.map(([x]) => x);
3108
- let res = Fn2.ZERO;
2586
+ let res = Fn.ZERO;
3109
2587
  for (const [x, y] of points)
3110
- res = Fn2.add(res, Fn2.mul(y, deriveInterpolatingValue(xCoords, x)));
3111
- return Fn2.toBytes(res);
2588
+ res = Fn.add(res, Fn.mul(y, deriveInterpolatingValue(xCoords, x)));
2589
+ return Fn.toBytes(res);
3112
2590
  },
3113
2591
  // Utils
3114
2592
  utils: Object.freeze({
3115
- Fn: Fn2,
2593
+ Fn,
3116
2594
  // NOTE: we re-export it here because it may be different from Point.Fn (ed448 is fun!)
3117
2595
  // Test RNG overrides still go through noble's non-zero scalar derivation; this is not a raw
3118
2596
  // "bytes become scalar" escape hatch.
3119
- randomScalar: (rng = randomBytes2) => Fn2.toBytes(genPointScalarPair(rng).scalar),
2597
+ randomScalar: (rng = randomBytes2) => Fn.toBytes(genPointScalarPair(rng).scalar),
3120
2598
  generateSecretPolynomial: (signers, secret, coeffs, rng) => {
3121
2599
  const res = generateSecretPolynomial(signers, secret, coeffs, rng);
3122
2600
  return { ...res, commitment: res.commitment.map(serializePoint) };
@@ -3126,781 +2604,6 @@ function createFROST(opts) {
3126
2604
  return Object.freeze(frost);
3127
2605
  }
3128
2606
 
3129
- // ../../node_modules/.pnpm/@noble+curves@2.2.0/node_modules/@noble/curves/abstract/montgomery.js
3130
- var _0n5 = BigInt(0);
3131
- var _1n5 = BigInt(1);
3132
- var _2n3 = BigInt(2);
3133
- function validateOpts(curve) {
3134
- validateObject(curve, {
3135
- P: "bigint",
3136
- type: "string",
3137
- adjustScalarBytes: "function",
3138
- powPminus2: "function"
3139
- }, {
3140
- randomBytes: "function"
3141
- });
3142
- return Object.freeze({ ...curve });
3143
- }
3144
- function montgomery(curveDef) {
3145
- const CURVE = validateOpts(curveDef);
3146
- const { P, type, adjustScalarBytes: adjustScalarBytes2, powPminus2, randomBytes: rand } = CURVE;
3147
- const is25519 = type === "x25519";
3148
- if (!is25519 && type !== "x448")
3149
- throw new Error("invalid type");
3150
- const randomBytes_ = rand === void 0 ? randomBytes2 : rand;
3151
- const montgomeryBits = is25519 ? 255 : 448;
3152
- const fieldLen = is25519 ? 32 : 56;
3153
- const Gu = is25519 ? BigInt(9) : BigInt(5);
3154
- const a24 = is25519 ? BigInt(121665) : BigInt(39081);
3155
- const minScalar = is25519 ? _2n3 ** BigInt(254) : _2n3 ** BigInt(447);
3156
- const maxAdded = is25519 ? BigInt(8) * _2n3 ** BigInt(251) - _1n5 : BigInt(4) * _2n3 ** BigInt(445) - _1n5;
3157
- const maxScalar = minScalar + maxAdded + _1n5;
3158
- const modP = (n) => mod(n, P);
3159
- const GuBytes = encodeU(Gu);
3160
- function encodeU(u) {
3161
- return numberToBytesLE(modP(u), fieldLen);
3162
- }
3163
- function decodeU(u) {
3164
- const _u = copyBytes(abytes2(u, fieldLen, "uCoordinate"));
3165
- if (is25519)
3166
- _u[31] &= 127;
3167
- return modP(bytesToNumberLE(_u));
3168
- }
3169
- function decodeScalar(scalar) {
3170
- return bytesToNumberLE(adjustScalarBytes2(copyBytes(abytes2(scalar, fieldLen, "scalar"))));
3171
- }
3172
- function scalarMult(scalar, u) {
3173
- const pu = montgomeryLadder(decodeU(u), decodeScalar(scalar));
3174
- if (pu === _0n5)
3175
- throw new Error("invalid private or public key received");
3176
- return encodeU(pu);
3177
- }
3178
- function scalarMultBase(scalar) {
3179
- return scalarMult(scalar, GuBytes);
3180
- }
3181
- const getPublicKey = scalarMultBase;
3182
- const getSharedSecret = scalarMult;
3183
- function cswap(swap, x_2, x_3) {
3184
- const dummy = modP(swap * (x_2 - x_3));
3185
- x_2 = modP(x_2 - dummy);
3186
- x_3 = modP(x_3 + dummy);
3187
- return { x_2, x_3 };
3188
- }
3189
- function montgomeryLadder(u, scalar) {
3190
- aInRange("u", u, _0n5, P);
3191
- aInRange("scalar", scalar, minScalar, maxScalar);
3192
- const k = scalar;
3193
- const x_1 = u;
3194
- let x_2 = _1n5;
3195
- let z_2 = _0n5;
3196
- let x_3 = u;
3197
- let z_3 = _1n5;
3198
- let swap = _0n5;
3199
- for (let t = BigInt(montgomeryBits - 1); t >= _0n5; t--) {
3200
- const k_t = k >> t & _1n5;
3201
- swap ^= k_t;
3202
- ({ x_2, x_3 } = cswap(swap, x_2, x_3));
3203
- ({ x_2: z_2, x_3: z_3 } = cswap(swap, z_2, z_3));
3204
- swap = k_t;
3205
- const A = x_2 + z_2;
3206
- const AA = modP(A * A);
3207
- const B = x_2 - z_2;
3208
- const BB = modP(B * B);
3209
- const E = AA - BB;
3210
- const C = x_3 + z_3;
3211
- const D = x_3 - z_3;
3212
- const DA = modP(D * A);
3213
- const CB = modP(C * B);
3214
- const dacb = DA + CB;
3215
- const da_cb = DA - CB;
3216
- x_3 = modP(dacb * dacb);
3217
- z_3 = modP(x_1 * modP(da_cb * da_cb));
3218
- x_2 = modP(AA * BB);
3219
- z_2 = modP(E * (AA + modP(a24 * E)));
3220
- }
3221
- ({ x_2, x_3 } = cswap(swap, x_2, x_3));
3222
- ({ x_2: z_2, x_3: z_3 } = cswap(swap, z_2, z_3));
3223
- const z2 = powPminus2(z_2);
3224
- return modP(x_2 * z2);
3225
- }
3226
- const lengths = {
3227
- secretKey: fieldLen,
3228
- publicKey: fieldLen,
3229
- seed: fieldLen
3230
- };
3231
- const randomSecretKey = (seed) => {
3232
- seed = seed === void 0 ? randomBytes_(fieldLen) : seed;
3233
- abytes2(seed, lengths.seed, "seed");
3234
- return seed;
3235
- };
3236
- const utils = { randomSecretKey };
3237
- Object.freeze(lengths);
3238
- Object.freeze(utils);
3239
- return Object.freeze({
3240
- keygen: createKeygen(randomSecretKey, getPublicKey),
3241
- getSharedSecret,
3242
- getPublicKey,
3243
- scalarMult,
3244
- scalarMultBase,
3245
- utils,
3246
- GuBytes: GuBytes.slice(),
3247
- lengths
3248
- });
3249
- }
3250
-
3251
- // ../../node_modules/.pnpm/@noble+curves@2.2.0/node_modules/@noble/curves/abstract/oprf.js
3252
- var _DST_scalarBytes = /* @__PURE__ */ asciiToBytes(_DST_scalar);
3253
- function createOPRF(opts) {
3254
- validateObject(opts, {
3255
- name: "string",
3256
- hash: "function",
3257
- hashToScalar: "function",
3258
- hashToGroup: "function"
3259
- });
3260
- validatePointCons(opts.Point);
3261
- const { name, Point, hash } = opts;
3262
- const { Fn: Fn2 } = Point;
3263
- const hashToGroup = (msg, ctx) => opts.hashToGroup(msg, {
3264
- DST: concatBytes2(asciiToBytes("HashToGroup-"), ctx)
3265
- });
3266
- const hashToScalarPrefixed = (msg, ctx) => opts.hashToScalar(msg, { DST: concatBytes2(_DST_scalarBytes, ctx) });
3267
- const randomScalar = (rng = randomBytes2) => {
3268
- const t = mapHashToField(rng(getMinHashLength(Fn2.ORDER)), Fn2.ORDER, Fn2.isLE);
3269
- return Fn2.isLE ? bytesToNumberLE(t) : bytesToNumberBE(t);
3270
- };
3271
- const msm = (points, scalars) => pippenger(Point, points, scalars);
3272
- const getCtx = (mode) => concatBytes2(asciiToBytes("OPRFV1-"), new Uint8Array([mode]), asciiToBytes("-" + name));
3273
- const ctxOPRF = getCtx(0);
3274
- const ctxVOPRF = getCtx(1);
3275
- const ctxPOPRF = getCtx(2);
3276
- function encode(...args) {
3277
- const res2 = [];
3278
- for (const a of args) {
3279
- if (typeof a === "number")
3280
- res2.push(numberToBytesBE(a, 2));
3281
- else if (typeof a === "string")
3282
- res2.push(asciiToBytes(a));
3283
- else {
3284
- abytes2(a);
3285
- res2.push(numberToBytesBE(a.length, 2), a);
3286
- }
3287
- }
3288
- return concatBytes2(...res2);
3289
- }
3290
- const inputBytes = (title, bytes) => {
3291
- abytes2(bytes, void 0, title);
3292
- if (bytes.length > 65535)
3293
- throw new Error(`"${title}" expected Uint8Array of length <= 65535, got length=${bytes.length}`);
3294
- return bytes;
3295
- };
3296
- const hashInput = (...bytes) => hash(encode(...bytes, "Finalize"));
3297
- function getTranscripts(B, C, D, ctx) {
3298
- const Bm = B.toBytes();
3299
- const seed = hash(encode(Bm, concatBytes2(asciiToBytes("Seed-"), ctx)));
3300
- const res2 = [];
3301
- for (let i = 0; i < C.length; i++) {
3302
- const Ci = C[i].toBytes();
3303
- const Di = D[i].toBytes();
3304
- const di = hashToScalarPrefixed(encode(seed, i, Ci, Di, "Composite"), ctx);
3305
- res2.push(di);
3306
- }
3307
- return res2;
3308
- }
3309
- function computeComposites(B, C, D, ctx) {
3310
- const T = getTranscripts(B, C, D, ctx);
3311
- const M = msm(C, T);
3312
- const Z = msm(D, T);
3313
- return { M, Z };
3314
- }
3315
- function computeCompositesFast(k, B, C, D, ctx) {
3316
- const T = getTranscripts(B, C, D, ctx);
3317
- const M = msm(C, T);
3318
- const Z = M.multiply(k);
3319
- return { M, Z };
3320
- }
3321
- function challengeTranscript(B, M, Z, t2, t3, ctx) {
3322
- const [Bm, a0, a1, a2, a3] = [B, M, Z, t2, t3].map((i) => i.toBytes());
3323
- return hashToScalarPrefixed(encode(Bm, a0, a1, a2, a3, "Challenge"), ctx);
3324
- }
3325
- function generateProof(ctx, k, B, C, D, rng) {
3326
- const { M, Z } = computeCompositesFast(k, B, C, D, ctx);
3327
- const r = randomScalar(rng);
3328
- const t2 = Point.BASE.multiply(r);
3329
- const t3 = M.multiply(r);
3330
- const c = challengeTranscript(B, M, Z, t2, t3, ctx);
3331
- const s = Fn2.sub(r, Fn2.mul(c, k));
3332
- return concatBytes2(...[c, s].map((i) => Fn2.toBytes(i)));
3333
- }
3334
- function verifyProof(ctx, B, C, D, proof) {
3335
- abytes2(proof, 2 * Fn2.BYTES);
3336
- const { M, Z } = computeComposites(B, C, D, ctx);
3337
- const [c, s] = [proof.subarray(0, Fn2.BYTES), proof.subarray(Fn2.BYTES)].map((f) => Fn2.fromBytes(f));
3338
- const t2 = Point.BASE.multiply(s).add(B.multiply(c));
3339
- const t3 = M.multiply(s).add(Z.multiply(c));
3340
- const expectedC = challengeTranscript(B, M, Z, t2, t3, ctx);
3341
- if (!Fn2.eql(c, expectedC))
3342
- throw new Error("proof verification failed");
3343
- }
3344
- function generateKeyPair() {
3345
- const skS = randomScalar();
3346
- const pkS = Point.BASE.multiply(skS);
3347
- return { secretKey: Fn2.toBytes(skS), publicKey: pkS.toBytes() };
3348
- }
3349
- function deriveKeyPair(ctx, seed, info) {
3350
- abytes2(seed, 32, "seed");
3351
- info = inputBytes("keyInfo", info);
3352
- const dst = concatBytes2(asciiToBytes("DeriveKeyPair"), ctx);
3353
- const msg = concatBytes2(seed, encode(info), Uint8Array.of(0));
3354
- for (let counter = 0; counter <= 255; counter++) {
3355
- msg[msg.length - 1] = counter;
3356
- const skS = opts.hashToScalar(msg, { DST: dst });
3357
- if (Fn2.is0(skS))
3358
- continue;
3359
- return {
3360
- secretKey: Fn2.toBytes(skS),
3361
- publicKey: Point.BASE.multiply(skS).toBytes()
3362
- };
3363
- }
3364
- throw new Error("Cannot derive key");
3365
- }
3366
- const wirePoint = (label, bytes) => {
3367
- const point = Point.fromBytes(bytes);
3368
- if (point.equals(Point.ZERO))
3369
- throw new Error(label + " point at infinity");
3370
- return point;
3371
- };
3372
- function blind(ctx, input, rng = randomBytes2) {
3373
- input = inputBytes("input", input);
3374
- const blind2 = randomScalar(rng);
3375
- const inputPoint = hashToGroup(input, ctx);
3376
- if (inputPoint.equals(Point.ZERO))
3377
- throw new Error("Input point at infinity");
3378
- const blinded = inputPoint.multiply(blind2);
3379
- return { blind: Fn2.toBytes(blind2), blinded: blinded.toBytes() };
3380
- }
3381
- function evaluate(ctx, secretKey, input) {
3382
- input = inputBytes("input", input);
3383
- const skS = Fn2.fromBytes(secretKey);
3384
- const inputPoint = hashToGroup(input, ctx);
3385
- if (inputPoint.equals(Point.ZERO))
3386
- throw new Error("Input point at infinity");
3387
- const unblinded = inputPoint.multiply(skS).toBytes();
3388
- return hashInput(input, unblinded);
3389
- }
3390
- const oprf = Object.freeze({
3391
- generateKeyPair,
3392
- deriveKeyPair: (seed, keyInfo) => deriveKeyPair(ctxOPRF, seed, keyInfo),
3393
- blind: (input, rng = randomBytes2) => blind(ctxOPRF, input, rng),
3394
- blindEvaluate(secretKey, blindedPoint) {
3395
- const skS = Fn2.fromBytes(secretKey);
3396
- const elm = wirePoint("blinded", blindedPoint);
3397
- return elm.multiply(skS).toBytes();
3398
- },
3399
- finalize(input, blindBytes, evaluatedBytes) {
3400
- input = inputBytes("input", input);
3401
- const blind2 = Fn2.fromBytes(blindBytes);
3402
- const evalPoint = wirePoint("evaluated", evaluatedBytes);
3403
- const unblinded = evalPoint.multiply(Fn2.inv(blind2)).toBytes();
3404
- return hashInput(input, unblinded);
3405
- },
3406
- evaluate: (secretKey, input) => evaluate(ctxOPRF, secretKey, input)
3407
- });
3408
- const voprf = Object.freeze({
3409
- generateKeyPair,
3410
- deriveKeyPair: (seed, keyInfo) => deriveKeyPair(ctxVOPRF, seed, keyInfo),
3411
- blind: (input, rng = randomBytes2) => blind(ctxVOPRF, input, rng),
3412
- blindEvaluateBatch(secretKey, publicKey, blinded, rng = randomBytes2) {
3413
- if (!Array.isArray(blinded))
3414
- throw new Error("expected array");
3415
- const skS = Fn2.fromBytes(secretKey);
3416
- const pkS = wirePoint("public key", publicKey);
3417
- const blindedPoints = blinded.map((i) => wirePoint("blinded", i));
3418
- const evaluated = blindedPoints.map((i) => i.multiply(skS));
3419
- const proof = generateProof(ctxVOPRF, skS, pkS, blindedPoints, evaluated, rng);
3420
- return { evaluated: evaluated.map((i) => i.toBytes()), proof };
3421
- },
3422
- blindEvaluate(secretKey, publicKey, blinded, rng = randomBytes2) {
3423
- const res2 = this.blindEvaluateBatch(secretKey, publicKey, [blinded], rng);
3424
- return { evaluated: res2.evaluated[0], proof: res2.proof };
3425
- },
3426
- finalizeBatch(items, publicKey, proof) {
3427
- if (!Array.isArray(items))
3428
- throw new Error("expected array");
3429
- const pkS = wirePoint("public key", publicKey);
3430
- const blindedPoints = items.map((i) => wirePoint("blinded", i.blinded));
3431
- const evalPoints = items.map((i) => wirePoint("evaluated", i.evaluated));
3432
- verifyProof(ctxVOPRF, pkS, blindedPoints, evalPoints, proof);
3433
- return items.map((i) => oprf.finalize(i.input, i.blind, i.evaluated));
3434
- },
3435
- finalize(input, blind2, evaluated, blinded, publicKey, proof) {
3436
- return this.finalizeBatch([{ input, blind: blind2, evaluated, blinded }], publicKey, proof)[0];
3437
- },
3438
- evaluate: (secretKey, input) => evaluate(ctxVOPRF, secretKey, input)
3439
- });
3440
- const poprf = (info) => {
3441
- info = inputBytes("info", info);
3442
- const m = hashToScalarPrefixed(encode("Info", info), ctxPOPRF);
3443
- const T = Point.BASE.multiply(m);
3444
- return Object.freeze({
3445
- generateKeyPair,
3446
- deriveKeyPair: (seed, keyInfo) => deriveKeyPair(ctxPOPRF, seed, keyInfo),
3447
- blind(input, publicKey, rng = randomBytes2) {
3448
- input = inputBytes("input", input);
3449
- const pkS = wirePoint("public key", publicKey);
3450
- const tweakedKey = T.add(pkS);
3451
- if (tweakedKey.equals(Point.ZERO))
3452
- throw new Error("tweakedKey point at infinity");
3453
- const blind2 = randomScalar(rng);
3454
- const inputPoint = hashToGroup(input, ctxPOPRF);
3455
- if (inputPoint.equals(Point.ZERO))
3456
- throw new Error("Input point at infinity");
3457
- const blindedPoint = inputPoint.multiply(blind2);
3458
- return {
3459
- blind: Fn2.toBytes(blind2),
3460
- blinded: blindedPoint.toBytes(),
3461
- tweakedKey: tweakedKey.toBytes()
3462
- };
3463
- },
3464
- blindEvaluateBatch(secretKey, blinded, rng = randomBytes2) {
3465
- if (!Array.isArray(blinded))
3466
- throw new Error("expected array");
3467
- const skS = Fn2.fromBytes(secretKey);
3468
- const t = Fn2.add(skS, m);
3469
- const invT = Fn2.inv(t);
3470
- const blindedPoints = blinded.map((i) => wirePoint("blinded", i));
3471
- const evalPoints = blindedPoints.map((i) => i.multiply(invT));
3472
- const tweakedKey = Point.BASE.multiply(t);
3473
- const proof = generateProof(ctxPOPRF, t, tweakedKey, evalPoints, blindedPoints, rng);
3474
- return { evaluated: evalPoints.map((i) => i.toBytes()), proof };
3475
- },
3476
- blindEvaluate(secretKey, blinded, rng = randomBytes2) {
3477
- const res2 = this.blindEvaluateBatch(secretKey, [blinded], rng);
3478
- return { evaluated: res2.evaluated[0], proof: res2.proof };
3479
- },
3480
- finalizeBatch(items, proof, tweakedKey) {
3481
- if (!Array.isArray(items))
3482
- throw new Error("expected array");
3483
- const inputs = items.map((i) => inputBytes("input", i.input));
3484
- const evalPoints = items.map((i) => wirePoint("evaluated", i.evaluated));
3485
- verifyProof(ctxPOPRF, wirePoint("tweakedKey", tweakedKey), evalPoints, items.map((i) => wirePoint("blinded", i.blinded)), proof);
3486
- return items.map((i, j) => {
3487
- const blind2 = Fn2.fromBytes(i.blind);
3488
- const point = evalPoints[j].multiply(Fn2.inv(blind2)).toBytes();
3489
- return hashInput(inputs[j], info, point);
3490
- });
3491
- },
3492
- finalize(input, blind2, evaluated, blinded, proof, tweakedKey) {
3493
- return this.finalizeBatch([{ input, blind: blind2, evaluated, blinded }], proof, tweakedKey)[0];
3494
- },
3495
- evaluate(secretKey, input) {
3496
- input = inputBytes("input", input);
3497
- const skS = Fn2.fromBytes(secretKey);
3498
- const inputPoint = hashToGroup(input, ctxPOPRF);
3499
- if (inputPoint.equals(Point.ZERO))
3500
- throw new Error("Input point at infinity");
3501
- const t = Fn2.add(skS, m);
3502
- const invT = Fn2.inv(t);
3503
- const unblinded = inputPoint.multiply(invT).toBytes();
3504
- return hashInput(input, info, unblinded);
3505
- }
3506
- });
3507
- };
3508
- const res = { name, oprf, voprf, poprf, __tests: Object.freeze({ Fn: Fn2 }) };
3509
- return Object.freeze(res);
3510
- }
3511
-
3512
- // ../../node_modules/.pnpm/@noble+curves@2.2.0/node_modules/@noble/curves/ed25519.js
3513
- var _0n6 = /* @__PURE__ */ BigInt(0);
3514
- var _1n6 = /* @__PURE__ */ BigInt(1);
3515
- var _2n4 = /* @__PURE__ */ BigInt(2);
3516
- var _3n2 = /* @__PURE__ */ BigInt(3);
3517
- var _5n2 = /* @__PURE__ */ BigInt(5);
3518
- var _8n3 = /* @__PURE__ */ BigInt(8);
3519
- var ed25519_CURVE_p = /* @__PURE__ */ BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed");
3520
- var ed25519_CURVE = /* @__PURE__ */ (() => ({
3521
- p: ed25519_CURVE_p,
3522
- n: BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),
3523
- h: _8n3,
3524
- a: BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),
3525
- d: BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),
3526
- Gx: BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),
3527
- Gy: BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")
3528
- }))();
3529
- function ed25519_pow_2_252_3(x) {
3530
- const _10n = BigInt(10), _20n = BigInt(20), _40n = BigInt(40), _80n = BigInt(80);
3531
- const P = ed25519_CURVE_p;
3532
- const x2 = x * x % P;
3533
- const b2 = x2 * x % P;
3534
- const b4 = pow2(b2, _2n4, P) * b2 % P;
3535
- const b5 = pow2(b4, _1n6, P) * x % P;
3536
- const b10 = pow2(b5, _5n2, P) * b5 % P;
3537
- const b20 = pow2(b10, _10n, P) * b10 % P;
3538
- const b40 = pow2(b20, _20n, P) * b20 % P;
3539
- const b80 = pow2(b40, _40n, P) * b40 % P;
3540
- const b160 = pow2(b80, _80n, P) * b80 % P;
3541
- const b240 = pow2(b160, _80n, P) * b80 % P;
3542
- const b250 = pow2(b240, _10n, P) * b10 % P;
3543
- const pow_p_5_8 = pow2(b250, _2n4, P) * x % P;
3544
- return { pow_p_5_8, b2 };
3545
- }
3546
- function adjustScalarBytes(bytes) {
3547
- bytes[0] &= 248;
3548
- bytes[31] &= 127;
3549
- bytes[31] |= 64;
3550
- return bytes;
3551
- }
3552
- var ED25519_SQRT_M1 = /* @__PURE__ */ BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");
3553
- function uvRatio(u, v) {
3554
- const P = ed25519_CURVE_p;
3555
- const v3 = mod(v * v * v, P);
3556
- const v7 = mod(v3 * v3 * v, P);
3557
- const pow = ed25519_pow_2_252_3(u * v7).pow_p_5_8;
3558
- let x = mod(u * v3 * pow, P);
3559
- const vx2 = mod(v * x * x, P);
3560
- const root1 = x;
3561
- const root2 = mod(x * ED25519_SQRT_M1, P);
3562
- const useRoot1 = vx2 === u;
3563
- const useRoot2 = vx2 === mod(-u, P);
3564
- const noRoot = vx2 === mod(-u * ED25519_SQRT_M1, P);
3565
- if (useRoot1)
3566
- x = root1;
3567
- if (useRoot2 || noRoot)
3568
- x = root2;
3569
- if (isNegativeLE(x, P))
3570
- x = mod(-x, P);
3571
- return { isValid: useRoot1 || useRoot2, value: x };
3572
- }
3573
- var ed25519_Point = /* @__PURE__ */ edwards(ed25519_CURVE, { uvRatio });
3574
- var Fp = /* @__PURE__ */ (() => ed25519_Point.Fp)();
3575
- var Fn = /* @__PURE__ */ (() => ed25519_Point.Fn)();
3576
- function ed25519_domain(data, ctx, phflag) {
3577
- if (ctx.length > 255)
3578
- throw new Error("Context is too big");
3579
- return concatBytes(asciiToBytes("SigEd25519 no Ed25519 collisions"), new Uint8Array([phflag ? 1 : 0, ctx.length]), ctx, data);
3580
- }
3581
- function ed(opts) {
3582
- return eddsa(ed25519_Point, sha512, Object.assign({ adjustScalarBytes, zip215: true }, opts));
3583
- }
3584
- var ed25519 = /* @__PURE__ */ ed({});
3585
- var ed25519ctx = /* @__PURE__ */ ed({ domain: ed25519_domain });
3586
- var ed25519ph = /* @__PURE__ */ ed({ domain: ed25519_domain, prehash: sha512 });
3587
- var ed25519_FROST = /* @__PURE__ */ (() => createFROST({
3588
- name: "FROST-ED25519-SHA512-v1",
3589
- Point: ed25519_Point,
3590
- validatePoint: (p) => {
3591
- p.assertValidity();
3592
- if (!p.isTorsionFree())
3593
- throw new Error("bad point: not torsion-free");
3594
- },
3595
- hash: sha512,
3596
- // RFC 9591 keeps H2 undecorated here for RFC 8032 compatibility. In createFROST(),
3597
- // `H2: ''` becomes an empty DST prefix; the built-in hashToScalar fallback treats
3598
- // that the same as omitted DST, even though custom hooks can still observe the empty bag.
3599
- H2: ""
3600
- }))();
3601
- var x25519 = /* @__PURE__ */ (() => {
3602
- const P = ed25519_CURVE_p;
3603
- return montgomery({
3604
- P,
3605
- type: "x25519",
3606
- powPminus2: (x) => {
3607
- const { pow_p_5_8, b2 } = ed25519_pow_2_252_3(x);
3608
- return mod(pow2(pow_p_5_8, _3n2, P) * b2, P);
3609
- },
3610
- adjustScalarBytes
3611
- });
3612
- })();
3613
- var ELL2_C1 = /* @__PURE__ */ (() => (ed25519_CURVE_p + _3n2) / _8n3)();
3614
- var ELL2_C2 = /* @__PURE__ */ (() => Fp.pow(_2n4, ELL2_C1))();
3615
- var ELL2_C3 = /* @__PURE__ */ (() => Fp.sqrt(Fp.neg(Fp.ONE)))();
3616
- function _map_to_curve_elligator2_curve25519(u) {
3617
- const ELL2_C4 = (ed25519_CURVE_p - _5n2) / _8n3;
3618
- const ELL2_J = BigInt(486662);
3619
- let tv1 = Fp.sqr(u);
3620
- tv1 = Fp.mul(tv1, _2n4);
3621
- let xd = Fp.add(tv1, Fp.ONE);
3622
- let x1n = Fp.neg(ELL2_J);
3623
- let tv2 = Fp.sqr(xd);
3624
- let gxd = Fp.mul(tv2, xd);
3625
- let gx1 = Fp.mul(tv1, ELL2_J);
3626
- gx1 = Fp.mul(gx1, x1n);
3627
- gx1 = Fp.add(gx1, tv2);
3628
- gx1 = Fp.mul(gx1, x1n);
3629
- let tv3 = Fp.sqr(gxd);
3630
- tv2 = Fp.sqr(tv3);
3631
- tv3 = Fp.mul(tv3, gxd);
3632
- tv3 = Fp.mul(tv3, gx1);
3633
- tv2 = Fp.mul(tv2, tv3);
3634
- let y11 = Fp.pow(tv2, ELL2_C4);
3635
- y11 = Fp.mul(y11, tv3);
3636
- let y12 = Fp.mul(y11, ELL2_C3);
3637
- tv2 = Fp.sqr(y11);
3638
- tv2 = Fp.mul(tv2, gxd);
3639
- let e1 = Fp.eql(tv2, gx1);
3640
- let y1 = Fp.cmov(y12, y11, e1);
3641
- let x2n = Fp.mul(x1n, tv1);
3642
- let y21 = Fp.mul(y11, u);
3643
- y21 = Fp.mul(y21, ELL2_C2);
3644
- let y22 = Fp.mul(y21, ELL2_C3);
3645
- let gx2 = Fp.mul(gx1, tv1);
3646
- tv2 = Fp.sqr(y21);
3647
- tv2 = Fp.mul(tv2, gxd);
3648
- let e2 = Fp.eql(tv2, gx2);
3649
- let y2 = Fp.cmov(y22, y21, e2);
3650
- tv2 = Fp.sqr(y1);
3651
- tv2 = Fp.mul(tv2, gxd);
3652
- let e3 = Fp.eql(tv2, gx1);
3653
- let xn = Fp.cmov(x2n, x1n, e3);
3654
- let y = Fp.cmov(y2, y1, e3);
3655
- let e4 = Fp.isOdd(y);
3656
- y = Fp.cmov(y, Fp.neg(y), e3 !== e4);
3657
- return { xMn: xn, xMd: xd, yMn: y, yMd: _1n6 };
3658
- }
3659
- var ELL2_C1_EDWARDS = /* @__PURE__ */ (() => FpSqrtEven(Fp, Fp.neg(BigInt(486664))))();
3660
- function map_to_curve_elligator2_edwards25519(u) {
3661
- const { xMn, xMd, yMn, yMd } = _map_to_curve_elligator2_curve25519(u);
3662
- let xn = Fp.mul(xMn, yMd);
3663
- xn = Fp.mul(xn, ELL2_C1_EDWARDS);
3664
- let xd = Fp.mul(xMd, yMn);
3665
- let yn = Fp.sub(xMn, xMd);
3666
- let yd = Fp.add(xMn, xMd);
3667
- let tv1 = Fp.mul(xd, yd);
3668
- let e = Fp.eql(tv1, Fp.ZERO);
3669
- xn = Fp.cmov(xn, Fp.ZERO, e);
3670
- xd = Fp.cmov(xd, Fp.ONE, e);
3671
- yn = Fp.cmov(yn, Fp.ONE, e);
3672
- yd = Fp.cmov(yd, Fp.ONE, e);
3673
- const [xd_inv, yd_inv] = FpInvertBatch(Fp, [xd, yd], true);
3674
- return { x: Fp.mul(xn, xd_inv), y: Fp.mul(yn, yd_inv) };
3675
- }
3676
- var ed25519_hasher = /* @__PURE__ */ (() => createHasher2(ed25519_Point, (scalars) => map_to_curve_elligator2_edwards25519(scalars[0]), {
3677
- DST: "edwards25519_XMD:SHA-512_ELL2_RO_",
3678
- encodeDST: "edwards25519_XMD:SHA-512_ELL2_NU_",
3679
- p: ed25519_CURVE_p,
3680
- m: 1,
3681
- k: 128,
3682
- expand: "xmd",
3683
- hash: sha512
3684
- }))();
3685
- var SQRT_M1 = ED25519_SQRT_M1;
3686
- var SQRT_AD_MINUS_ONE = /* @__PURE__ */ BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235");
3687
- var INVSQRT_A_MINUS_D = /* @__PURE__ */ BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578");
3688
- var ONE_MINUS_D_SQ = /* @__PURE__ */ BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838");
3689
- var D_MINUS_ONE_SQ = /* @__PURE__ */ BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");
3690
- var invertSqrt = (number) => uvRatio(_1n6, number);
3691
- var MAX_255B = /* @__PURE__ */ BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
3692
- var bytes255ToNumberLE = (bytes) => Fp.create(bytesToNumberLE(bytes) & MAX_255B);
3693
- function calcElligatorRistrettoMap(r0) {
3694
- const { d } = ed25519_CURVE;
3695
- const P = ed25519_CURVE_p;
3696
- const mod2 = (n) => Fp.create(n);
3697
- const r = mod2(SQRT_M1 * r0 * r0);
3698
- const Ns = mod2((r + _1n6) * ONE_MINUS_D_SQ);
3699
- let c = BigInt(-1);
3700
- const D = mod2((c - d * r) * mod2(r + d));
3701
- let { isValid: Ns_D_is_sq, value: s } = uvRatio(Ns, D);
3702
- let s_ = mod2(s * r0);
3703
- if (!isNegativeLE(s_, P))
3704
- s_ = mod2(-s_);
3705
- if (!Ns_D_is_sq)
3706
- s = s_;
3707
- if (!Ns_D_is_sq)
3708
- c = r;
3709
- const Nt = mod2(c * (r - _1n6) * D_MINUS_ONE_SQ - D);
3710
- const s2 = s * s;
3711
- const W0 = mod2((s + s) * D);
3712
- const W1 = mod2(Nt * SQRT_AD_MINUS_ONE);
3713
- const W2 = mod2(_1n6 - s2);
3714
- const W3 = mod2(_1n6 + s2);
3715
- return new ed25519_Point(mod2(W0 * W3), mod2(W2 * W1), mod2(W1 * W3), mod2(W0 * W2));
3716
- }
3717
- var _RistrettoPoint = class __RistrettoPoint extends PrimeEdwardsPoint {
3718
- // Do NOT change syntax: the following gymnastics is done,
3719
- // because typescript strips comments, which makes bundlers disable tree-shaking.
3720
- // prettier-ignore
3721
- static BASE = /* @__PURE__ */ (() => new __RistrettoPoint(ed25519_Point.BASE))();
3722
- // prettier-ignore
3723
- static ZERO = /* @__PURE__ */ (() => new __RistrettoPoint(ed25519_Point.ZERO))();
3724
- // prettier-ignore
3725
- static Fp = /* @__PURE__ */ (() => Fp)();
3726
- // prettier-ignore
3727
- static Fn = /* @__PURE__ */ (() => Fn)();
3728
- constructor(ep) {
3729
- super(ep);
3730
- }
3731
- /**
3732
- * Create one Ristretto255 point from affine Edwards coordinates.
3733
- * This wraps the internal Edwards representative directly and is not a
3734
- * canonical ristretto255 decoding path.
3735
- * Use `toBytes()` / `fromBytes()` if canonical ristretto255 bytes matter.
3736
- */
3737
- static fromAffine(ap) {
3738
- return new __RistrettoPoint(ed25519_Point.fromAffine(ap));
3739
- }
3740
- assertSame(other) {
3741
- if (!(other instanceof __RistrettoPoint))
3742
- throw new Error("RistrettoPoint expected");
3743
- }
3744
- init(ep) {
3745
- return new __RistrettoPoint(ep);
3746
- }
3747
- static fromBytes(bytes) {
3748
- abytes(bytes, 32);
3749
- const { a, d } = ed25519_CURVE;
3750
- const P = ed25519_CURVE_p;
3751
- const mod2 = (n) => Fp.create(n);
3752
- const s = bytes255ToNumberLE(bytes);
3753
- if (!equalBytes(Fp.toBytes(s), bytes) || isNegativeLE(s, P))
3754
- throw new Error("invalid ristretto255 encoding 1");
3755
- const s2 = mod2(s * s);
3756
- const u1 = mod2(_1n6 + a * s2);
3757
- const u2 = mod2(_1n6 - a * s2);
3758
- const u1_2 = mod2(u1 * u1);
3759
- const u2_2 = mod2(u2 * u2);
3760
- const v = mod2(a * d * u1_2 - u2_2);
3761
- const { isValid, value: I } = invertSqrt(mod2(v * u2_2));
3762
- const Dx = mod2(I * u2);
3763
- const Dy = mod2(I * Dx * v);
3764
- let x = mod2((s + s) * Dx);
3765
- if (isNegativeLE(x, P))
3766
- x = mod2(-x);
3767
- const y = mod2(u1 * Dy);
3768
- const t = mod2(x * y);
3769
- if (!isValid || isNegativeLE(t, P) || y === _0n6)
3770
- throw new Error("invalid ristretto255 encoding 2");
3771
- return new __RistrettoPoint(new ed25519_Point(x, y, _1n6, t));
3772
- }
3773
- /**
3774
- * Converts ristretto-encoded string to ristretto point.
3775
- * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode).
3776
- * @param hex - Ristretto-encoded 32 bytes. Not every 32-byte string is valid ristretto encoding
3777
- */
3778
- static fromHex(hex) {
3779
- return __RistrettoPoint.fromBytes(hexToBytes(hex));
3780
- }
3781
- /**
3782
- * Encodes ristretto point to Uint8Array.
3783
- * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-encode).
3784
- */
3785
- toBytes() {
3786
- let { X, Y, Z, T } = this.ep;
3787
- const P = ed25519_CURVE_p;
3788
- const mod2 = (n) => Fp.create(n);
3789
- const u1 = mod2(mod2(Z + Y) * mod2(Z - Y));
3790
- const u2 = mod2(X * Y);
3791
- const u2sq = mod2(u2 * u2);
3792
- const { value: invsqrt } = invertSqrt(mod2(u1 * u2sq));
3793
- const D1 = mod2(invsqrt * u1);
3794
- const D2 = mod2(invsqrt * u2);
3795
- const zInv = mod2(D1 * D2 * T);
3796
- let D;
3797
- if (isNegativeLE(T * zInv, P)) {
3798
- let _x = mod2(Y * SQRT_M1);
3799
- let _y = mod2(X * SQRT_M1);
3800
- X = _x;
3801
- Y = _y;
3802
- D = mod2(D1 * INVSQRT_A_MINUS_D);
3803
- } else {
3804
- D = D2;
3805
- }
3806
- if (isNegativeLE(X * zInv, P))
3807
- Y = mod2(-Y);
3808
- let s = mod2((Z - Y) * D);
3809
- if (isNegativeLE(s, P))
3810
- s = mod2(-s);
3811
- return Fp.toBytes(s);
3812
- }
3813
- /**
3814
- * Compares two Ristretto points.
3815
- * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-equals).
3816
- */
3817
- equals(other) {
3818
- this.assertSame(other);
3819
- const { X: X1, Y: Y1 } = this.ep;
3820
- const { X: X2, Y: Y2 } = other.ep;
3821
- const mod2 = (n) => Fp.create(n);
3822
- const one = mod2(X1 * Y2) === mod2(Y1 * X2);
3823
- const two = mod2(Y1 * Y2) === mod2(X1 * X2);
3824
- return one || two;
3825
- }
3826
- is0() {
3827
- return this.equals(__RistrettoPoint.ZERO);
3828
- }
3829
- };
3830
- Object.freeze(_RistrettoPoint.BASE);
3831
- Object.freeze(_RistrettoPoint.ZERO);
3832
- Object.freeze(_RistrettoPoint.prototype);
3833
- Object.freeze(_RistrettoPoint);
3834
- var ristretto255 = /* @__PURE__ */ Object.freeze({ Point: _RistrettoPoint });
3835
- var ristretto255_hasher = Object.freeze({
3836
- Point: _RistrettoPoint,
3837
- /**
3838
- * Spec: https://www.rfc-editor.org/rfc/rfc9380.html#name-hashing-to-ristretto255. Caveats:
3839
- * * There are no test vectors
3840
- * * encodeToCurve / mapToCurve is undefined
3841
- * * mapToCurve would be `calcElligatorRistrettoMap(scalars[0])`, not ristretto255_map!
3842
- * * hashToScalar is undefined too, so we just use OPRF implementation
3843
- * * We cannot re-use 'createHasher', because ristretto255_map is different algorithm/RFC
3844
- (os2ip -> bytes255ToNumberLE)
3845
- * * mapToCurve == calcElligatorRistrettoMap, hashToCurve == ristretto255_map
3846
- * * hashToScalar is undefined in RFC9380 for ristretto, so we use the OPRF
3847
- version here. Using `bytes255ToNumblerLE` will create a different result
3848
- if we use `bytes255ToNumberLE` as os2ip
3849
- * * current version is closest to spec.
3850
- */
3851
- hashToCurve(msg, options) {
3852
- const DST = options?.DST === void 0 ? "ristretto255_XMD:SHA-512_R255MAP_RO_" : options.DST;
3853
- const xmd = expand_message_xmd(msg, DST, 64, sha512);
3854
- return ristretto255_hasher.deriveToCurve(xmd);
3855
- },
3856
- hashToScalar(msg, options = { DST: _DST_scalar }) {
3857
- const xmd = expand_message_xmd(msg, options.DST, 64, sha512);
3858
- return Fn.create(bytesToNumberLE(xmd));
3859
- },
3860
- /**
3861
- * HashToCurve-like construction based on RFC 9496 (Element Derivation).
3862
- * Converts 64 uniform random bytes into a curve point.
3863
- *
3864
- * WARNING: This represents an older hash-to-curve construction from before
3865
- * RFC 9380 was finalized.
3866
- * It was later reused as a component in the newer
3867
- * `hash_to_ristretto255` function defined in RFC 9380.
3868
- */
3869
- deriveToCurve(bytes) {
3870
- abytes(bytes, 64);
3871
- const r1 = bytes255ToNumberLE(bytes.subarray(0, 32));
3872
- const R1 = calcElligatorRistrettoMap(r1);
3873
- const r2 = bytes255ToNumberLE(bytes.subarray(32, 64));
3874
- const R2 = calcElligatorRistrettoMap(r2);
3875
- return new _RistrettoPoint(R1.add(R2));
3876
- }
3877
- });
3878
- var ristretto255_oprf = /* @__PURE__ */ (() => createOPRF({
3879
- name: "ristretto255-SHA512",
3880
- Point: _RistrettoPoint,
3881
- hash: sha512,
3882
- hashToGroup: ristretto255_hasher.hashToCurve,
3883
- hashToScalar: ristretto255_hasher.hashToScalar
3884
- }))();
3885
- var ristretto255_FROST = /* @__PURE__ */ (() => createFROST({
3886
- name: "FROST-RISTRETTO255-SHA512-v1",
3887
- Point: _RistrettoPoint,
3888
- validatePoint: (p) => {
3889
- p.assertValidity();
3890
- },
3891
- hash: sha512
3892
- }))();
3893
- var ED25519_TORSION_SUBGROUP = /* @__PURE__ */ Object.freeze([
3894
- "0100000000000000000000000000000000000000000000000000000000000000",
3895
- "c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a",
3896
- "0000000000000000000000000000000000000000000000000000000000000080",
3897
- "26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05",
3898
- "ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f",
3899
- "26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85",
3900
- "0000000000000000000000000000000000000000000000000000000000000000",
3901
- "c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa"
3902
- ]);
3903
-
3904
2607
  export {
3905
2608
  split,
3906
2609
  rotlSH,
@@ -3917,12 +2620,14 @@ export {
3917
2620
  swap32IfBE,
3918
2621
  bytesToHex,
3919
2622
  hexToBytes,
2623
+ concatBytes,
3920
2624
  createHasher,
3921
2625
  randomBytes,
3922
2626
  sha256,
2627
+ sha512,
3923
2628
  abytes2,
3924
2629
  bytesToHex2,
3925
- concatBytes2 as concatBytes,
2630
+ concatBytes2,
3926
2631
  hexToBytes2,
3927
2632
  isBytes2 as isBytes,
3928
2633
  randomBytes2,
@@ -3931,44 +2636,44 @@ export {
3931
2636
  asafenumber,
3932
2637
  numberToHexUnpadded,
3933
2638
  bytesToNumberBE,
2639
+ bytesToNumberLE,
2640
+ numberToBytesBE,
2641
+ numberToBytesLE,
2642
+ equalBytes,
2643
+ copyBytes,
3934
2644
  asciiToBytes,
3935
2645
  aInRange,
3936
2646
  bitLen,
3937
2647
  bitMask,
3938
2648
  createHmacDrbg,
3939
2649
  validateObject,
2650
+ notImplemented,
2651
+ mod,
3940
2652
  pow2,
2653
+ isNegativeLE,
2654
+ FpInvertBatch,
3941
2655
  Field,
2656
+ FpSqrtEven,
3942
2657
  getMinHashLength,
3943
2658
  mapHashToField,
2659
+ validatePointCons,
3944
2660
  negateCt,
3945
2661
  normalizeZ,
3946
2662
  wNAF,
3947
2663
  mulEndoUnsafe,
2664
+ pippenger,
3948
2665
  createCurveFields,
3949
2666
  createKeygen,
3950
- ed25519,
3951
- ed25519ctx,
3952
- ed25519ph,
3953
- ed25519_FROST,
3954
- x25519,
3955
- _map_to_curve_elligator2_curve25519,
3956
- ed25519_hasher,
3957
- ristretto255,
3958
- ristretto255_hasher,
3959
- ristretto255_oprf,
3960
- ristretto255_FROST,
3961
- ED25519_TORSION_SUBGROUP
2667
+ expand_message_xmd,
2668
+ _DST_scalar,
2669
+ createHasher2,
2670
+ createFROST
3962
2671
  };
3963
2672
  /*! Bundled license information:
3964
2673
 
3965
2674
  @noble/curves/utils.js:
3966
2675
  @noble/curves/abstract/modular.js:
3967
2676
  @noble/curves/abstract/curve.js:
3968
- @noble/curves/abstract/edwards.js:
3969
- @noble/curves/abstract/montgomery.js:
3970
- @noble/curves/abstract/oprf.js:
3971
- @noble/curves/ed25519.js:
3972
2677
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
3973
2678
  */
3974
- //# sourceMappingURL=chunk-LN2OF264.js.map
2679
+ //# sourceMappingURL=chunk-6GXZ4KRO.js.map