@noble/curves 1.8.1 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/README.md +305 -433
  2. package/_shortw_utils.d.ts +2 -2
  3. package/_shortw_utils.js +2 -2
  4. package/abstract/bls.d.ts +5 -5
  5. package/abstract/bls.d.ts.map +1 -1
  6. package/abstract/bls.js +15 -16
  7. package/abstract/bls.js.map +1 -1
  8. package/abstract/curve.d.ts +11 -3
  9. package/abstract/curve.d.ts.map +1 -1
  10. package/abstract/curve.js +81 -78
  11. package/abstract/curve.js.map +1 -1
  12. package/abstract/edwards.d.ts +2 -2
  13. package/abstract/edwards.d.ts.map +1 -1
  14. package/abstract/edwards.js +58 -71
  15. package/abstract/edwards.js.map +1 -1
  16. package/abstract/hash-to-curve.d.ts +15 -9
  17. package/abstract/hash-to-curve.d.ts.map +1 -1
  18. package/abstract/hash-to-curve.js +49 -39
  19. package/abstract/hash-to-curve.js.map +1 -1
  20. package/abstract/modular.d.ts +11 -8
  21. package/abstract/modular.d.ts.map +1 -1
  22. package/abstract/modular.js +79 -67
  23. package/abstract/modular.js.map +1 -1
  24. package/abstract/montgomery.d.ts.map +1 -1
  25. package/abstract/montgomery.js +13 -12
  26. package/abstract/montgomery.js.map +1 -1
  27. package/abstract/poseidon.d.ts +40 -3
  28. package/abstract/poseidon.d.ts.map +1 -1
  29. package/abstract/poseidon.js +186 -7
  30. package/abstract/poseidon.js.map +1 -1
  31. package/abstract/tower.d.ts +2 -2
  32. package/abstract/tower.d.ts.map +1 -1
  33. package/abstract/tower.js +16 -17
  34. package/abstract/tower.js.map +1 -1
  35. package/abstract/utils.d.ts +5 -2
  36. package/abstract/utils.d.ts.map +1 -1
  37. package/abstract/utils.js +27 -14
  38. package/abstract/utils.js.map +1 -1
  39. package/abstract/weierstrass.d.ts +21 -9
  40. package/abstract/weierstrass.d.ts.map +1 -1
  41. package/abstract/weierstrass.js +103 -86
  42. package/abstract/weierstrass.js.map +1 -1
  43. package/bls12-381.d.ts +1 -1
  44. package/bls12-381.js +41 -41
  45. package/bls12-381.js.map +1 -1
  46. package/bn254.d.ts +3 -2
  47. package/bn254.d.ts.map +1 -1
  48. package/bn254.js +39 -29
  49. package/bn254.js.map +1 -1
  50. package/ed25519.d.ts +9 -6
  51. package/ed25519.d.ts.map +1 -1
  52. package/ed25519.js +70 -71
  53. package/ed25519.js.map +1 -1
  54. package/ed448.d.ts +7 -6
  55. package/ed448.d.ts.map +1 -1
  56. package/ed448.js +54 -56
  57. package/ed448.js.map +1 -1
  58. package/esm/_shortw_utils.d.ts +2 -2
  59. package/esm/_shortw_utils.js +1 -1
  60. package/esm/abstract/bls.d.ts +5 -5
  61. package/esm/abstract/bls.d.ts.map +1 -1
  62. package/esm/abstract/bls.js +6 -7
  63. package/esm/abstract/bls.js.map +1 -1
  64. package/esm/abstract/curve.d.ts +11 -3
  65. package/esm/abstract/curve.d.ts.map +1 -1
  66. package/esm/abstract/curve.js +77 -74
  67. package/esm/abstract/curve.js.map +1 -1
  68. package/esm/abstract/edwards.d.ts +2 -2
  69. package/esm/abstract/edwards.d.ts.map +1 -1
  70. package/esm/abstract/edwards.js +39 -52
  71. package/esm/abstract/edwards.js.map +1 -1
  72. package/esm/abstract/hash-to-curve.d.ts +15 -9
  73. package/esm/abstract/hash-to-curve.d.ts.map +1 -1
  74. package/esm/abstract/hash-to-curve.js +33 -23
  75. package/esm/abstract/hash-to-curve.js.map +1 -1
  76. package/esm/abstract/modular.d.ts +11 -8
  77. package/esm/abstract/modular.d.ts.map +1 -1
  78. package/esm/abstract/modular.js +71 -59
  79. package/esm/abstract/modular.js.map +1 -1
  80. package/esm/abstract/montgomery.d.ts.map +1 -1
  81. package/esm/abstract/montgomery.js +4 -3
  82. package/esm/abstract/montgomery.js.map +1 -1
  83. package/esm/abstract/poseidon.d.ts +40 -3
  84. package/esm/abstract/poseidon.d.ts.map +1 -1
  85. package/esm/abstract/poseidon.js +180 -5
  86. package/esm/abstract/poseidon.js.map +1 -1
  87. package/esm/abstract/tower.d.ts +2 -2
  88. package/esm/abstract/tower.d.ts.map +1 -1
  89. package/esm/abstract/tower.js +8 -9
  90. package/esm/abstract/tower.js.map +1 -1
  91. package/esm/abstract/utils.d.ts +5 -2
  92. package/esm/abstract/utils.d.ts.map +1 -1
  93. package/esm/abstract/utils.js +26 -13
  94. package/esm/abstract/utils.js.map +1 -1
  95. package/esm/abstract/weierstrass.d.ts +21 -9
  96. package/esm/abstract/weierstrass.d.ts.map +1 -1
  97. package/esm/abstract/weierstrass.js +76 -59
  98. package/esm/abstract/weierstrass.js.map +1 -1
  99. package/esm/bls12-381.d.ts +1 -1
  100. package/esm/bls12-381.js +9 -9
  101. package/esm/bls12-381.js.map +1 -1
  102. package/esm/bn254.d.ts +3 -2
  103. package/esm/bn254.d.ts.map +1 -1
  104. package/esm/bn254.js +17 -7
  105. package/esm/bn254.js.map +1 -1
  106. package/esm/ed25519.d.ts +9 -6
  107. package/esm/ed25519.d.ts.map +1 -1
  108. package/esm/ed25519.js +25 -26
  109. package/esm/ed25519.js.map +1 -1
  110. package/esm/ed448.d.ts +7 -6
  111. package/esm/ed448.d.ts.map +1 -1
  112. package/esm/ed448.js +17 -19
  113. package/esm/ed448.js.map +1 -1
  114. package/esm/jubjub.d.ts +7 -4
  115. package/esm/jubjub.d.ts.map +1 -1
  116. package/esm/jubjub.js +7 -60
  117. package/esm/jubjub.js.map +1 -1
  118. package/esm/misc.d.ts +21 -0
  119. package/esm/misc.d.ts.map +1 -0
  120. package/esm/misc.js +107 -0
  121. package/esm/misc.js.map +1 -0
  122. package/esm/nist.d.ts +29 -0
  123. package/esm/nist.d.ts.map +1 -0
  124. package/esm/nist.js +120 -0
  125. package/esm/nist.js.map +1 -0
  126. package/esm/p256.d.ts +9 -8
  127. package/esm/p256.d.ts.map +1 -1
  128. package/esm/p256.js +6 -43
  129. package/esm/p256.js.map +1 -1
  130. package/esm/p384.d.ts +10 -8
  131. package/esm/p384.d.ts.map +1 -1
  132. package/esm/p384.js +7 -47
  133. package/esm/p384.js.map +1 -1
  134. package/esm/p521.d.ts +6 -6
  135. package/esm/p521.d.ts.map +1 -1
  136. package/esm/p521.js +6 -55
  137. package/esm/p521.js.map +1 -1
  138. package/esm/pasta.d.ts +5 -7
  139. package/esm/pasta.d.ts.map +1 -1
  140. package/esm/pasta.js +5 -33
  141. package/esm/pasta.js.map +1 -1
  142. package/esm/secp256k1.d.ts +15 -10
  143. package/esm/secp256k1.d.ts.map +1 -1
  144. package/esm/secp256k1.js +21 -18
  145. package/esm/secp256k1.js.map +1 -1
  146. package/jubjub.d.ts +7 -4
  147. package/jubjub.d.ts.map +1 -1
  148. package/jubjub.js +8 -63
  149. package/jubjub.js.map +1 -1
  150. package/misc.d.ts +21 -0
  151. package/misc.d.ts.map +1 -0
  152. package/misc.js +112 -0
  153. package/misc.js.map +1 -0
  154. package/nist.d.ts +29 -0
  155. package/nist.d.ts.map +1 -0
  156. package/nist.js +123 -0
  157. package/nist.js.map +1 -0
  158. package/p256.d.ts +9 -8
  159. package/p256.d.ts.map +1 -1
  160. package/p256.js +5 -48
  161. package/p256.js.map +1 -1
  162. package/p384.d.ts +10 -8
  163. package/p384.d.ts.map +1 -1
  164. package/p384.js +6 -52
  165. package/p384.js.map +1 -1
  166. package/p521.d.ts +6 -6
  167. package/p521.d.ts.map +1 -1
  168. package/p521.js +5 -60
  169. package/p521.js.map +1 -1
  170. package/package.json +116 -12
  171. package/pasta.d.ts +5 -7
  172. package/pasta.d.ts.map +1 -1
  173. package/pasta.js +6 -34
  174. package/pasta.js.map +1 -1
  175. package/secp256k1.d.ts +15 -10
  176. package/secp256k1.d.ts.map +1 -1
  177. package/secp256k1.js +60 -57
  178. package/secp256k1.js.map +1 -1
  179. package/src/_shortw_utils.ts +2 -2
  180. package/src/abstract/bls.ts +10 -10
  181. package/src/abstract/curve.ts +89 -80
  182. package/src/abstract/edwards.ts +56 -63
  183. package/src/abstract/hash-to-curve.ts +49 -39
  184. package/src/abstract/modular.ts +68 -59
  185. package/src/abstract/montgomery.ts +4 -3
  186. package/src/abstract/poseidon.ts +208 -13
  187. package/src/abstract/tower.ts +9 -10
  188. package/src/abstract/utils.ts +28 -15
  189. package/src/abstract/weierstrass.ts +105 -87
  190. package/src/bls12-381.ts +10 -10
  191. package/src/bn254.ts +18 -8
  192. package/src/ed25519.ts +31 -28
  193. package/src/ed448.ts +24 -21
  194. package/src/jubjub.ts +8 -63
  195. package/src/misc.ts +123 -0
  196. package/src/nist.ts +154 -0
  197. package/src/p256.ts +6 -49
  198. package/src/p384.ts +8 -53
  199. package/src/p521.ts +6 -70
  200. package/src/pasta.ts +5 -39
  201. package/src/secp256k1.ts +25 -20
package/src/bn254.ts CHANGED
@@ -13,6 +13,15 @@ There are huge compatibility issues in the ecosystem:
13
13
  https://github.com/scipr-lab/libff/blob/a44f482e18b8ac04d034c193bd9d7df7817ad73f/libff/algebra/curves/bn128/bn128_init.cpp#L166-L169
14
14
  3. halo2curves bn256 is also incompatible and returns different outputs
15
15
 
16
+ We don't implement Point methods toHex / toRawBytes.
17
+ To work around this limitation, has to initialize points on their own from BigInts.
18
+ Reason it's not implemented is because [there is no standard](https://github.com/privacy-scaling-explorations/halo2curves/issues/109).
19
+ Points of divergence:
20
+
21
+ - Endianness: LE vs BE (byte-swapped)
22
+ - Flags as first hex bits (similar to BLS) vs no-flags
23
+ - Imaginary part last in G2 vs first (c0, c1 vs c1, c0)
24
+
16
25
  The goal of our implementation is to support "Ethereum" variant of the curve,
17
26
  because it at least has specs:
18
27
 
@@ -45,20 +54,20 @@ Ate loop size: 6x+2
45
54
  * @module
46
55
  */
47
56
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
48
- import { sha256 } from '@noble/hashes/sha256';
57
+ import { sha256 } from '@noble/hashes/sha2';
49
58
  import { randomBytes } from '@noble/hashes/utils';
50
- import { getHash } from './_shortw_utils.js';
59
+ import { getHash } from './_shortw_utils.ts';
51
60
  import {
52
61
  bls,
53
62
  type CurveFn as BLSCurveFn,
54
63
  type PostPrecomputeFn,
55
64
  type PostPrecomputePointAddFn,
56
- } from './abstract/bls.js';
57
- import { Field } from './abstract/modular.js';
58
- import type { Fp, Fp12, Fp2, Fp6 } from './abstract/tower.js';
59
- import { psiFrobenius, tower12 } from './abstract/tower.js';
60
- import { bitGet, bitLen, notImplemented } from './abstract/utils.js';
61
- import { type CurveFn, weierstrass } from './abstract/weierstrass.js';
65
+ } from './abstract/bls.ts';
66
+ import { Field } from './abstract/modular.ts';
67
+ import type { Fp, Fp12, Fp2, Fp6 } from './abstract/tower.ts';
68
+ import { psiFrobenius, tower12 } from './abstract/tower.ts';
69
+ import { bitGet, bitLen, notImplemented } from './abstract/utils.ts';
70
+ import { type CurveFn, weierstrass } from './abstract/weierstrass.ts';
62
71
  // prettier-ignore
63
72
  const _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3);
64
73
  const _6n = BigInt(6);
@@ -239,6 +248,7 @@ export const bn254: BLSCurveFn = bls({
239
248
  * bn254 weierstrass curve with ECDSA.
240
249
  * This is very rare and probably not used anywhere.
241
250
  * Instead, you should use G1 / G2, defined above.
251
+ * @deprecated
242
252
  */
243
253
  export const bn254_weierstrass: CurveFn = weierstrass({
244
254
  a: BigInt(0),
package/src/ed25519.ts CHANGED
@@ -6,18 +6,19 @@
6
6
  * @module
7
7
  */
8
8
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
9
- import { sha512 } from '@noble/hashes/sha512';
9
+ import { sha512 } from '@noble/hashes/sha2';
10
10
  import { concatBytes, randomBytes, utf8ToBytes } from '@noble/hashes/utils';
11
- import { type AffinePoint, type Group, pippenger } from './abstract/curve.js';
12
- import { type CurveFn, type ExtPointType, twistedEdwards } from './abstract/edwards.js';
11
+ import { type AffinePoint, type Group, pippenger } from './abstract/curve.ts';
12
+ import { type CurveFn, type ExtPointType, twistedEdwards } from './abstract/edwards.ts';
13
13
  import {
14
14
  createHasher,
15
15
  expand_message_xmd,
16
+ type Hasher,
16
17
  type htfBasicOpts,
17
18
  type HTFMethod,
18
- } from './abstract/hash-to-curve.js';
19
- import { Field, FpSqrtEven, isNegativeLE, mod, pow2 } from './abstract/modular.js';
20
- import { montgomery, type CurveFn as XCurveFn } from './abstract/montgomery.js';
19
+ } from './abstract/hash-to-curve.ts';
20
+ import { Field, FpInvertBatch, FpSqrtEven, isNegativeLE, mod, pow2 } from './abstract/modular.ts';
21
+ import { montgomery, type CurveFn as XCurveFn } from './abstract/montgomery.ts';
21
22
  import {
22
23
  bytesToHex,
23
24
  bytesToNumberLE,
@@ -25,12 +26,14 @@ import {
25
26
  equalBytes,
26
27
  type Hex,
27
28
  numberToBytesLE,
28
- } from './abstract/utils.js';
29
+ } from './abstract/utils.ts';
29
30
 
31
+ // 2n**255n - 19n
30
32
  const ED25519_P = BigInt(
31
33
  '57896044618658097711785492504343953926634992332820282019728792003956564819949'
32
34
  );
33
35
  // √(-1) aka √(a) aka 2^((p-1)/4)
36
+ // Fp.sqrt(Fp.neg(1))
34
37
  const ED25519_SQRT_M1 = /* @__PURE__ */ BigInt(
35
38
  '19681161376707505956807079304988542015446066515923890162744021073123829784752'
36
39
  );
@@ -91,7 +94,7 @@ function uvRatio(u: bigint, v: bigint): { isValid: boolean; value: bigint } {
91
94
  return { isValid: useRoot1 || useRoot2, value: x };
92
95
  }
93
96
 
94
- // Just in case
97
+ /** Weird / bogus points, useful for debugging. */
95
98
  export const ED25519_TORSION_SUBGROUP: string[] = [
96
99
  '0100000000000000000000000000000000000000000000000000000000000000',
97
100
  'c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a',
@@ -107,19 +110,15 @@ const Fp = /* @__PURE__ */ (() => Field(ED25519_P, undefined, true))();
107
110
 
108
111
  const ed25519Defaults = /* @__PURE__ */ (() =>
109
112
  ({
110
- // Param: a
111
- a: BigInt(-1), // Fp.create(-1) is proper; our way still works and is faster
112
- // d is equal to -121665/121666 over finite field.
113
- // Negative number is P - number, and division is invert(number, P)
113
+ // Removing Fp.create() will still work, and is 10% faster on sign
114
+ a: Fp.create(BigInt(-1)),
115
+ // d is -121665/121666 a.k.a. Fp.neg(121665 * Fp.inv(121666))
114
116
  d: BigInt('37095705934669439343138083508754565189542113879843219016388785533085940283555'),
115
- // Finite field 𝔽p over which we'll do calculations; 2n**255n - 19n
117
+ // Finite field 2n**255n - 19n
116
118
  Fp,
117
- // Subgroup order: how many points curve has
118
- // 2n**252n + 27742317777372353535851937790883648493n;
119
+ // Subgroup order 2n**252n + 27742317777372353535851937790883648493n;
119
120
  n: BigInt('7237005577332262213973186563042994240857116359379907606001950938285454250989'),
120
- // Cofactor
121
121
  h: _8n,
122
- // Base point (x, y) aka generator point
123
122
  Gx: BigInt('15112221349535400772501151409588531511454012693041857206046113283949847762202'),
124
123
  Gy: BigInt('46316835694926478169428394003475163141307993866256225615783033603165251855960'),
125
124
  hash: sha512,
@@ -291,12 +290,11 @@ function map_to_curve_elligator2_edwards25519(u: bigint) {
291
290
  xd = Fp.cmov(xd, Fp.ONE, e); // 10. xd = CMOV(xd, 1, e)
292
291
  yn = Fp.cmov(yn, Fp.ONE, e); // 11. yn = CMOV(yn, 1, e)
293
292
  yd = Fp.cmov(yd, Fp.ONE, e); // 12. yd = CMOV(yd, 1, e)
294
-
295
- const inv = Fp.invertBatch([xd, yd]); // batch division
296
- return { x: Fp.mul(xn, inv[0]), y: Fp.mul(yn, inv[1]) }; // 13. return (xn, xd, yn, yd)
293
+ const [xd_inv, yd_inv] = FpInvertBatch(Fp, [xd, yd], true); // batch division
294
+ return { x: Fp.mul(xn, xd_inv), y: Fp.mul(yn, yd_inv) }; // 13. return (xn, xd, yn, yd)
297
295
  }
298
296
 
299
- const htf = /* @__PURE__ */ (() =>
297
+ export const ed25519_hasher: Hasher<bigint> = /* @__PURE__ */ (() =>
300
298
  createHasher(
301
299
  ed25519.ExtendedPoint,
302
300
  (scalars: bigint[]) => map_to_curve_elligator2_edwards25519(scalars[0]),
@@ -310,10 +308,11 @@ const htf = /* @__PURE__ */ (() =>
310
308
  hash: sha512,
311
309
  }
312
310
  ))();
313
- export const hashToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.hashToCurve)();
314
- export const encodeToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.encodeToCurve)();
311
+ export const hashToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => ed25519_hasher.hashToCurve)();
312
+ export const encodeToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() =>
313
+ ed25519_hasher.encodeToCurve)();
315
314
 
316
- function assertRstPoint(other: unknown) {
315
+ function aristp(other: unknown) {
317
316
  if (!(other instanceof RistPoint)) throw new Error('RistrettoPoint expected');
318
317
  }
319
318
 
@@ -380,9 +379,12 @@ function calcElligatorRistrettoMap(r0: bigint): ExtendedPoint {
380
379
  class RistPoint implements Group<RistPoint> {
381
380
  static BASE: RistPoint;
382
381
  static ZERO: RistPoint;
382
+ private readonly ep: ExtendedPoint;
383
383
  // Private property to discourage combining ExtendedPoint + RistrettoPoint
384
384
  // Always use Ristretto encoding/decoding instead.
385
- constructor(private readonly ep: ExtendedPoint) {}
385
+ constructor(ep: ExtendedPoint) {
386
+ this.ep = ep;
387
+ }
386
388
 
387
389
  static fromAffine(ap: AffinePoint<bigint>): RistPoint {
388
390
  return new RistPoint(ed25519.ExtendedPoint.fromAffine(ap));
@@ -483,7 +485,7 @@ class RistPoint implements Group<RistPoint> {
483
485
 
484
486
  // Compare one point to another.
485
487
  equals(other: RistPoint): boolean {
486
- assertRstPoint(other);
488
+ aristp(other);
487
489
  const { ex: X1, ey: Y1 } = this.ep;
488
490
  const { ex: X2, ey: Y2 } = other.ep;
489
491
  const mod = ed25519.CURVE.Fp.create;
@@ -494,12 +496,12 @@ class RistPoint implements Group<RistPoint> {
494
496
  }
495
497
 
496
498
  add(other: RistPoint): RistPoint {
497
- assertRstPoint(other);
499
+ aristp(other);
498
500
  return new RistPoint(this.ep.add(other.ep));
499
501
  }
500
502
 
501
503
  subtract(other: RistPoint): RistPoint {
502
- assertRstPoint(other);
504
+ aristp(other);
503
505
  return new RistPoint(this.ep.subtract(other.ep));
504
506
  }
505
507
 
@@ -533,5 +535,6 @@ export const hashToRistretto255 = (msg: Uint8Array, options: htfBasicOpts): Rist
533
535
  const P = RistPoint.hashToCurve(uniform_bytes);
534
536
  return P;
535
537
  };
538
+ /** @deprecated */
536
539
  export const hash_to_ristretto255: (msg: Uint8Array, options: htfBasicOpts) => RistPoint =
537
540
  hashToRistretto255; // legacy
package/src/ed448.ts CHANGED
@@ -9,17 +9,18 @@
9
9
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
10
10
  import { shake256 } from '@noble/hashes/sha3';
11
11
  import { concatBytes, randomBytes, utf8ToBytes, wrapConstructor } from '@noble/hashes/utils';
12
- import type { AffinePoint, Group } from './abstract/curve.js';
13
- import { pippenger } from './abstract/curve.js';
14
- import { type CurveFn, type ExtPointType, twistedEdwards } from './abstract/edwards.js';
12
+ import type { AffinePoint, Group } from './abstract/curve.ts';
13
+ import { pippenger } from './abstract/curve.ts';
14
+ import { type CurveFn, type ExtPointType, twistedEdwards } from './abstract/edwards.ts';
15
15
  import {
16
16
  createHasher,
17
17
  expand_message_xof,
18
+ type Hasher,
18
19
  type htfBasicOpts,
19
20
  type HTFMethod,
20
- } from './abstract/hash-to-curve.js';
21
- import { Field, isNegativeLE, mod, pow2 } from './abstract/modular.js';
22
- import { montgomery, type CurveFn as XCurveFn } from './abstract/montgomery.js';
21
+ } from './abstract/hash-to-curve.ts';
22
+ import { Field, FpInvertBatch, isNegativeLE, mod, pow2 } from './abstract/modular.ts';
23
+ import { montgomery, type CurveFn as XCurveFn } from './abstract/montgomery.ts';
23
24
  import {
24
25
  bytesToHex,
25
26
  bytesToNumberLE,
@@ -27,7 +28,7 @@ import {
27
28
  equalBytes,
28
29
  type Hex,
29
30
  numberToBytesLE,
30
- } from './abstract/utils.js';
31
+ } from './abstract/utils.ts';
31
32
 
32
33
  const shake256_114 = wrapConstructor(() => shake256.create({ dkLen: 114 }));
33
34
  const shake256_64 = wrapConstructor(() => shake256.create({ dkLen: 64 }));
@@ -98,22 +99,20 @@ const Fp = Field(ed448P, 456, true);
98
99
  const ED448_DEF = {
99
100
  // Param: a
100
101
  a: BigInt(1),
101
- // -39081. Negative number is P - number
102
+ // -39081 a.k.a. Fp.neg(39081)
102
103
  d: BigInt(
103
104
  '726838724295606890549323807888004534353641360687318060281490199180612328166730772686396383698676545930088884461843637361053498018326358'
104
105
  ),
105
- // Finite field 𝔽p over which we'll do calculations; 2n**448n - 2n**224n - 1n
106
+ // Finite field 2n**448n - 2n**224n - 1n
106
107
  Fp,
107
- // Subgroup order: how many points curve has;
108
+ // Subgroup order
108
109
  // 2n**446n - 13818066809895115352007386748515426880336692474882178609894547503885n
109
110
  n: BigInt(
110
111
  '181709681073901722637330951972001133588410340171829515070372549795146003961539585716195755291692375963310293709091662304773755859649779'
111
112
  ),
112
113
  // RFC 7748 has 56-byte keys, RFC 8032 has 57-byte keys
113
114
  nBitLength: 456,
114
- // Cofactor
115
115
  h: BigInt(4),
116
- // Base point (x, y) aka generator point
117
116
  Gx: BigInt(
118
117
  '224580040295924300187604334099896036246789641632564134246125461686950415467406032909029192869357953282578032075146446173674602635247710'
119
118
  ),
@@ -265,11 +264,11 @@ function map_to_curve_elligator2_edwards448(u: bigint) {
265
264
  yEn = Fp.cmov(yEn, Fp.ONE, e); // 36. yEn = CMOV(yEn, 1, e)
266
265
  yEd = Fp.cmov(yEd, Fp.ONE, e); // 37. yEd = CMOV(yEd, 1, e)
267
266
 
268
- const inv = Fp.invertBatch([xEd, yEd]); // batch division
267
+ const inv = FpInvertBatch(Fp, [xEd, yEd], true); // batch division
269
268
  return { x: Fp.mul(xEn, inv[0]), y: Fp.mul(yEn, inv[1]) }; // 38. return (xEn, xEd, yEn, yEd)
270
269
  }
271
270
 
272
- const htf = /* @__PURE__ */ (() =>
271
+ export const ed448_hasher: Hasher<bigint> = /* @__PURE__ */ (() =>
273
272
  createHasher(
274
273
  ed448.ExtendedPoint,
275
274
  (scalars: bigint[]) => map_to_curve_elligator2_edwards448(scalars[0]),
@@ -283,10 +282,11 @@ const htf = /* @__PURE__ */ (() =>
283
282
  hash: shake256,
284
283
  }
285
284
  ))();
286
- export const hashToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.hashToCurve)();
287
- export const encodeToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.encodeToCurve)();
285
+ export const hashToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => ed448_hasher.hashToCurve)();
286
+ export const encodeToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() =>
287
+ ed448_hasher.encodeToCurve)();
288
288
 
289
- function assertDcfPoint(other: unknown) {
289
+ function adecafp(other: unknown) {
290
290
  if (!(other instanceof DcfPoint)) throw new Error('DecafPoint expected');
291
291
  }
292
292
 
@@ -354,9 +354,12 @@ function calcElligatorDecafMap(r0: bigint): ExtendedPoint {
354
354
  class DcfPoint implements Group<DcfPoint> {
355
355
  static BASE: DcfPoint;
356
356
  static ZERO: DcfPoint;
357
+ private readonly ep: ExtendedPoint;
357
358
  // Private property to discourage combining ExtendedPoint + DecafPoint
358
359
  // Always use Decaf encoding/decoding instead.
359
- constructor(private readonly ep: ExtendedPoint) {}
360
+ constructor(ep: ExtendedPoint) {
361
+ this.ep = ep;
362
+ }
360
363
 
361
364
  static fromAffine(ap: AffinePoint<bigint>): DcfPoint {
362
365
  return new DcfPoint(ed448.ExtendedPoint.fromAffine(ap));
@@ -453,7 +456,7 @@ class DcfPoint implements Group<DcfPoint> {
453
456
  // Compare one point to another.
454
457
  // https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-ristretto255-decaf448-07#name-equals-2
455
458
  equals(other: DcfPoint): boolean {
456
- assertDcfPoint(other);
459
+ adecafp(other);
457
460
  const { ex: X1, ey: Y1 } = this.ep;
458
461
  const { ex: X2, ey: Y2 } = other.ep;
459
462
  const mod = ed448.CURVE.Fp.create;
@@ -462,12 +465,12 @@ class DcfPoint implements Group<DcfPoint> {
462
465
  }
463
466
 
464
467
  add(other: DcfPoint): DcfPoint {
465
- assertDcfPoint(other);
468
+ adecafp(other);
466
469
  return new DcfPoint(this.ep.add(other.ep));
467
470
  }
468
471
 
469
472
  subtract(other: DcfPoint): DcfPoint {
470
- assertDcfPoint(other);
473
+ adecafp(other);
471
474
  return new DcfPoint(this.ep.subtract(other.ep));
472
475
  }
473
476
 
package/src/jubjub.ts CHANGED
@@ -1,63 +1,8 @@
1
- /**
2
- * jubjub Twisted Edwards curve.
3
- * https://neuromancer.sk/std/other/JubJub
4
- * jubjub does not use EdDSA, so `hash`/sha512 params are passed because interface expects them.
5
- * @module
6
- */
7
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
8
- import { blake2s } from '@noble/hashes/blake2s';
9
- import { sha512 } from '@noble/hashes/sha512';
10
- import { concatBytes, randomBytes, utf8ToBytes } from '@noble/hashes/utils';
11
- import { type CurveFn, type ExtPointType, twistedEdwards } from './abstract/edwards.js';
12
- import { Field } from './abstract/modular.js';
13
-
14
- export const jubjub: CurveFn = /* @__PURE__ */ twistedEdwards({
15
- // Params: a, d
16
- a: BigInt('0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000000'),
17
- d: BigInt('0x2a9318e74bfa2b48f5fd9207e6bd7fd4292d7f6d37579d2601065fd6d6343eb1'),
18
- // Finite field 𝔽p over which we'll do calculations
19
- // Same value as bls12-381 Fr (not Fp)
20
- Fp: Field(BigInt('0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001')),
21
- // Subgroup order: how many points curve has
22
- n: BigInt('0xe7db4ea6533afa906673b0101343b00a6682093ccc81082d0970e5ed6f72cb7'),
23
- // Cofactor
24
- h: BigInt(8),
25
- // Base point (x, y) aka generator point
26
- Gx: BigInt('0x11dafe5d23e1218086a365b99fbf3d3be72f6afd7d1f72623e6b071492d1122b'),
27
- Gy: BigInt('0x1d523cf1ddab1a1793132e78c866c0c33e26ba5cc220fed7cc3f870e59d292aa'),
28
- hash: sha512,
29
- randomBytes,
30
- } as const);
31
-
32
- const GH_FIRST_BLOCK = utf8ToBytes(
33
- '096b36a5804bfacef1691e173c366a47ff5ba84a44f26ddd7e8d9f79d5b42df0'
34
- );
35
-
36
- // Returns point at JubJub curve which is prime order and not zero
37
- export function groupHash(tag: Uint8Array, personalization: Uint8Array): ExtPointType {
38
- const h = blake2s.create({ personalization, dkLen: 32 });
39
- h.update(GH_FIRST_BLOCK);
40
- h.update(tag);
41
- // NOTE: returns ExtendedPoint, in case it will be multiplied later
42
- let p = jubjub.ExtendedPoint.fromHex(h.digest());
43
- // NOTE: cannot replace with isSmallOrder, returns Point*8
44
- p = p.multiply(jubjub.CURVE.h);
45
- if (p.equals(jubjub.ExtendedPoint.ZERO)) throw new Error('Point has small order');
46
- return p;
47
- }
48
-
49
- // No secret data is leaked here at all.
50
- // It operates over public data:
51
- // const G_SPEND = jubjub.findGroupHash(new Uint8Array(), utf8ToBytes('Item_G_'));
52
- export function findGroupHash(m: Uint8Array, personalization: Uint8Array): ExtPointType {
53
- const tag = concatBytes(m, new Uint8Array([0]));
54
- const hashes = [];
55
- for (let i = 0; i < 256; i++) {
56
- tag[tag.length - 1] = i;
57
- try {
58
- hashes.push(groupHash(tag, personalization));
59
- } catch (e) {}
60
- }
61
- if (!hashes.length) throw new Error('findGroupHash tag overflow');
62
- return hashes[0];
63
- }
1
+ import { jubjub_findGroupHash, jubjub_groupHash, jubjub as jubjubn } from './misc.ts';
2
+
3
+ /** @deprecated Use `@noble/curves/misc` module directly. */
4
+ export const jubjub: typeof jubjubn = jubjubn;
5
+ /** @deprecated Use `@noble/curves/misc` module directly. */
6
+ export const findGroupHash: typeof jubjub_findGroupHash = jubjub_findGroupHash;
7
+ /** @deprecated Use `@noble/curves/misc` module directly. */
8
+ export const groupHash: typeof jubjub_groupHash = jubjub_groupHash;
package/src/misc.ts ADDED
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Miscellaneous, rarely used curves.
3
+ * jubjub, babyjubjub, pallas, vesta.
4
+ * @module
5
+ */
6
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
7
+ import { blake256 } from '@noble/hashes/blake1';
8
+ import { blake2s } from '@noble/hashes/blake2';
9
+ import { sha256, sha512 } from '@noble/hashes/sha2';
10
+ import { concatBytes, randomBytes, utf8ToBytes } from '@noble/hashes/utils';
11
+ import { getHash } from './_shortw_utils.ts';
12
+ import { type CurveFn, type ExtPointType, twistedEdwards } from './abstract/edwards.ts';
13
+ import { Field, mod } from './abstract/modular.ts';
14
+ import { type CurveFn as WCurveFn, weierstrass } from './abstract/weierstrass.ts';
15
+
16
+ // Jubjub curves have 𝔽p over scalar fields of other curves. They are friendly to ZK proofs.
17
+ // jubjub Fp = bls n. babyjubjub Fp = bn254 n.
18
+ // verify manually, check bls12-381.ts and bn254.ts.
19
+ // https://neuromancer.sk/std/other/JubJub
20
+
21
+ const bls12_381_Fr = Field(
22
+ BigInt('0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001')
23
+ );
24
+ const bn254_Fr = Field(
25
+ BigInt('21888242871839275222246405745257275088548364400416034343698204186575808495617')
26
+ );
27
+
28
+ /** Curve over scalar field of bls12-381. jubjub Fp = bls n */
29
+ export const jubjub: CurveFn = /* @__PURE__ */ twistedEdwards({
30
+ a: BigInt('0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000000'),
31
+ d: BigInt('0x2a9318e74bfa2b48f5fd9207e6bd7fd4292d7f6d37579d2601065fd6d6343eb1'),
32
+ Fp: bls12_381_Fr,
33
+ n: BigInt('0xe7db4ea6533afa906673b0101343b00a6682093ccc81082d0970e5ed6f72cb7'),
34
+ h: BigInt(8),
35
+ Gx: BigInt('0x11dafe5d23e1218086a365b99fbf3d3be72f6afd7d1f72623e6b071492d1122b'),
36
+ Gy: BigInt('0x1d523cf1ddab1a1793132e78c866c0c33e26ba5cc220fed7cc3f870e59d292aa'),
37
+ hash: sha512,
38
+ randomBytes,
39
+ } as const);
40
+
41
+ /** Curve over scalar field of bn254. babyjubjub Fp = bn254 n */
42
+ export const babyjubjub: CurveFn = /* @__PURE__ */ twistedEdwards({
43
+ a: BigInt(168700),
44
+ d: BigInt(168696),
45
+ Fp: bn254_Fr,
46
+ n: BigInt('21888242871839275222246405745257275088614511777268538073601725287587578984328'),
47
+ h: BigInt(8),
48
+ Gx: BigInt('995203441582195749578291179787384436505546430278305826713579947235728471134'),
49
+ Gy: BigInt('5472060717959818805561601436314318772137091100104008585924551046643952123905'),
50
+ hash: blake256,
51
+ randomBytes,
52
+ } as const);
53
+
54
+ const jubjub_gh_first_block = utf8ToBytes(
55
+ '096b36a5804bfacef1691e173c366a47ff5ba84a44f26ddd7e8d9f79d5b42df0'
56
+ );
57
+
58
+ // Returns point at JubJub curve which is prime order and not zero
59
+ export function jubjub_groupHash(tag: Uint8Array, personalization: Uint8Array): ExtPointType {
60
+ const h = blake2s.create({ personalization, dkLen: 32 });
61
+ h.update(jubjub_gh_first_block);
62
+ h.update(tag);
63
+ // NOTE: returns ExtendedPoint, in case it will be multiplied later
64
+ let p = jubjub.ExtendedPoint.fromHex(h.digest());
65
+ // NOTE: cannot replace with isSmallOrder, returns Point*8
66
+ p = p.multiply(jubjub.CURVE.h);
67
+ if (p.equals(jubjub.ExtendedPoint.ZERO)) throw new Error('Point has small order');
68
+ return p;
69
+ }
70
+
71
+ // No secret data is leaked here at all.
72
+ // It operates over public data:
73
+ // const G_SPEND = jubjub.findGroupHash(Uint8Array.of(), utf8ToBytes('Item_G_'));
74
+ export function jubjub_findGroupHash(m: Uint8Array, personalization: Uint8Array): ExtPointType {
75
+ const tag = concatBytes(m, new Uint8Array([0]));
76
+ const hashes = [];
77
+ for (let i = 0; i < 256; i++) {
78
+ tag[tag.length - 1] = i;
79
+ try {
80
+ hashes.push(jubjub_groupHash(tag, personalization));
81
+ } catch (e) {}
82
+ }
83
+ if (!hashes.length) throw new Error('findGroupHash tag overflow');
84
+ return hashes[0];
85
+ }
86
+
87
+ // Pasta curves. See [Spec](https://o1-labs.github.io/proof-systems/specs/pasta.html).
88
+
89
+ export const pasta_p: bigint = BigInt(
90
+ '0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001'
91
+ );
92
+ export const pasta_q: bigint = BigInt(
93
+ '0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001'
94
+ );
95
+
96
+ /**
97
+ * https://neuromancer.sk/std/other/Pallas
98
+ * @deprecated
99
+ */
100
+ export const pallas: WCurveFn = weierstrass({
101
+ a: BigInt(0),
102
+ b: BigInt(5),
103
+ Fp: Field(pasta_p),
104
+ n: pasta_q,
105
+ Gx: mod(BigInt(-1), pasta_p),
106
+ Gy: BigInt(2),
107
+ h: BigInt(1),
108
+ ...getHash(sha256),
109
+ });
110
+ /**
111
+ * https://neuromancer.sk/std/other/Vesta
112
+ * @deprecated
113
+ */
114
+ export const vesta: WCurveFn = weierstrass({
115
+ a: BigInt(0),
116
+ b: BigInt(5),
117
+ Fp: Field(pasta_q),
118
+ n: pasta_p,
119
+ Gx: mod(BigInt(-1), pasta_q),
120
+ Gy: BigInt(2),
121
+ h: BigInt(1),
122
+ ...getHash(sha256),
123
+ });
package/src/nist.ts ADDED
@@ -0,0 +1,154 @@
1
+ /**
2
+ * Internal module for NIST P256, P384, P521 curves.
3
+ * Do not use for now.
4
+ * @module
5
+ */
6
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
7
+ import { sha256, sha384, sha512 } from '@noble/hashes/sha2';
8
+ import { createCurve, type CurveFnWithCreate } from './_shortw_utils.ts';
9
+ import { createHasher, type Hasher } from './abstract/hash-to-curve.ts';
10
+ import { Field } from './abstract/modular.ts';
11
+ import { mapToCurveSimpleSWU } from './abstract/weierstrass.ts';
12
+
13
+ const Fp256 = Field(BigInt('0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff'));
14
+ const p256_a = Fp256.create(BigInt('-3'));
15
+ const p256_b = BigInt('0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b');
16
+
17
+ /**
18
+ * secp256r1 curve, ECDSA and ECDH methods.
19
+ * Field: `2n**224n * (2n**32n-1n) + 2n**192n + 2n**96n-1n`
20
+ */
21
+ // prettier-ignore
22
+ export const p256: CurveFnWithCreate = createCurve({
23
+ a: p256_a,
24
+ b: p256_b,
25
+ Fp: Fp256,
26
+ n: BigInt('0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551'),
27
+ Gx: BigInt('0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296'),
28
+ Gy: BigInt('0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5'),
29
+ h: BigInt(1),
30
+ lowS: false
31
+ } as const, sha256);
32
+ /** Alias to p256. */
33
+ export const secp256r1: CurveFnWithCreate = p256;
34
+
35
+ const p256_mapSWU = /* @__PURE__ */ (() =>
36
+ mapToCurveSimpleSWU(Fp256, {
37
+ A: p256_a,
38
+ B: p256_b,
39
+ Z: Fp256.create(BigInt('-10')),
40
+ }))();
41
+
42
+ /** Hashing / encoding to p256 points / field. RFC 9380 methods. */
43
+ export const p256_hasher: Hasher<bigint> = /* @__PURE__ */ (() =>
44
+ createHasher(secp256r1.ProjectivePoint, (scalars: bigint[]) => p256_mapSWU(scalars[0]), {
45
+ DST: 'P256_XMD:SHA-256_SSWU_RO_',
46
+ encodeDST: 'P256_XMD:SHA-256_SSWU_NU_',
47
+ p: Fp256.ORDER,
48
+ m: 1,
49
+ k: 128,
50
+ expand: 'xmd',
51
+ hash: sha256,
52
+ }))();
53
+
54
+ // Field over which we'll do calculations.
55
+ const Fp384 = Field(
56
+ BigInt(
57
+ '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff'
58
+ )
59
+ );
60
+ const p384_a = Fp384.create(BigInt('-3'));
61
+ // prettier-ignore
62
+ const p384_b = BigInt('0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef');
63
+
64
+ /**
65
+ * secp384r1 curve, ECDSA and ECDH methods.
66
+ * Field: `2n**384n - 2n**128n - 2n**96n + 2n**32n - 1n`.
67
+ * */
68
+ // prettier-ignore
69
+ export const p384: CurveFnWithCreate = createCurve({
70
+ a: p384_a,
71
+ b: p384_b,
72
+ Fp: Fp384,
73
+ n: BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973'),
74
+ Gx: BigInt('0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7'),
75
+ Gy: BigInt('0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f'),
76
+ h: BigInt(1),
77
+ lowS: false
78
+ } as const, sha384);
79
+ /** Alias to p384. */
80
+ export const secp384r1: CurveFnWithCreate = p384;
81
+
82
+ const p384_mapSWU = /* @__PURE__ */ (() =>
83
+ mapToCurveSimpleSWU(Fp384, {
84
+ A: p384_a,
85
+ B: p384_b,
86
+ Z: Fp384.create(BigInt('-12')),
87
+ }))();
88
+
89
+ /** Hashing / encoding to p384 points / field. RFC 9380 methods. */
90
+ export const p384_hasher: Hasher<bigint> = /* @__PURE__ */ (() =>
91
+ createHasher(secp384r1.ProjectivePoint, (scalars: bigint[]) => p384_mapSWU(scalars[0]), {
92
+ DST: 'P384_XMD:SHA-384_SSWU_RO_',
93
+ encodeDST: 'P384_XMD:SHA-384_SSWU_NU_',
94
+ p: Fp384.ORDER,
95
+ m: 1,
96
+ k: 192,
97
+ expand: 'xmd',
98
+ hash: sha384,
99
+ }))();
100
+
101
+ // Field over which we'll do calculations.
102
+ const Fp521 = Field(
103
+ BigInt(
104
+ '0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
105
+ )
106
+ );
107
+
108
+ const p521_a = Fp521.create(BigInt('-3'));
109
+ const p521_b = BigInt(
110
+ '0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00'
111
+ );
112
+
113
+ /**
114
+ * NIST secp521r1 aka p521 curve, ECDSA and ECDH methods.
115
+ * Field: `2n**521n - 1n`.
116
+ */
117
+ // prettier-ignore
118
+ export const p521: CurveFnWithCreate = createCurve({
119
+ a: p521_a,
120
+ b: p521_b,
121
+ Fp: Fp521,
122
+ n: BigInt(
123
+ '0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409'
124
+ ),
125
+ Gx: BigInt(
126
+ '0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66'
127
+ ),
128
+ Gy: BigInt(
129
+ '0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650'
130
+ ),
131
+ h: BigInt(1),
132
+ lowS: false,
133
+ allowedPrivateKeyLengths: [130, 131, 132] // P521 keys are variable-length. Normalize to 132b
134
+ } as const, sha512);
135
+ export const secp521r1: CurveFnWithCreate = p521;
136
+
137
+ const p521_mapSWU = /* @__PURE__ */ (() =>
138
+ mapToCurveSimpleSWU(Fp521, {
139
+ A: p521_a,
140
+ B: p521_b,
141
+ Z: Fp521.create(BigInt('-4')),
142
+ }))();
143
+
144
+ /** Hashing / encoding to p521 points / field. RFC 9380 methods. */
145
+ export const p521_hasher: Hasher<bigint> = /* @__PURE__ */ (() =>
146
+ createHasher(secp521r1.ProjectivePoint, (scalars: bigint[]) => p521_mapSWU(scalars[0]), {
147
+ DST: 'P521_XMD:SHA-512_SSWU_RO_',
148
+ encodeDST: 'P521_XMD:SHA-512_SSWU_NU_',
149
+ p: Fp521.ORDER,
150
+ m: 1,
151
+ k: 256,
152
+ expand: 'xmd',
153
+ hash: sha512,
154
+ }))();