@noble/curves 0.8.3 → 0.9.1

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 (108) hide show
  1. package/README.md +87 -62
  2. package/_shortw_utils.d.ts +2 -1
  3. package/_shortw_utils.d.ts.map +1 -1
  4. package/abstract/bls.d.ts +11 -11
  5. package/abstract/bls.d.ts.map +1 -1
  6. package/abstract/bls.js.map +1 -1
  7. package/abstract/curve.d.ts +5 -3
  8. package/abstract/curve.d.ts.map +1 -1
  9. package/abstract/curve.js +5 -1
  10. package/abstract/curve.js.map +1 -1
  11. package/abstract/edwards.d.ts +6 -1
  12. package/abstract/edwards.d.ts.map +1 -1
  13. package/abstract/edwards.js +8 -9
  14. package/abstract/edwards.js.map +1 -1
  15. package/abstract/hash-to-curve.d.ts +2 -2
  16. package/abstract/hash-to-curve.d.ts.map +1 -1
  17. package/abstract/hash-to-curve.js.map +1 -1
  18. package/abstract/modular.d.ts +24 -12
  19. package/abstract/modular.d.ts.map +1 -1
  20. package/abstract/modular.js +17 -4
  21. package/abstract/modular.js.map +1 -1
  22. package/abstract/poseidon.d.ts +3 -3
  23. package/abstract/poseidon.d.ts.map +1 -1
  24. package/abstract/poseidon.js.map +1 -1
  25. package/abstract/weierstrass.d.ts +29 -5
  26. package/abstract/weierstrass.d.ts.map +1 -1
  27. package/abstract/weierstrass.js +37 -23
  28. package/abstract/weierstrass.js.map +1 -1
  29. package/bls12-381.d.ts +4 -4
  30. package/bls12-381.d.ts.map +1 -1
  31. package/bls12-381.js +109 -106
  32. package/bls12-381.js.map +1 -1
  33. package/bn.js +1 -1
  34. package/bn.js.map +1 -1
  35. package/ed25519.js +2 -2
  36. package/ed25519.js.map +1 -1
  37. package/ed448.d.ts.map +1 -1
  38. package/ed448.js +4 -3
  39. package/ed448.js.map +1 -1
  40. package/esm/abstract/bls.js.map +1 -1
  41. package/esm/abstract/curve.js +5 -1
  42. package/esm/abstract/curve.js.map +1 -1
  43. package/esm/abstract/edwards.js +8 -9
  44. package/esm/abstract/edwards.js.map +1 -1
  45. package/esm/abstract/hash-to-curve.js.map +1 -1
  46. package/esm/abstract/modular.js +15 -2
  47. package/esm/abstract/modular.js.map +1 -1
  48. package/esm/abstract/poseidon.js.map +1 -1
  49. package/esm/abstract/weierstrass.js +37 -23
  50. package/esm/abstract/weierstrass.js.map +1 -1
  51. package/esm/bls12-381.js +109 -106
  52. package/esm/bls12-381.js.map +1 -1
  53. package/esm/bn.js +2 -2
  54. package/esm/bn.js.map +1 -1
  55. package/esm/ed25519.js +2 -2
  56. package/esm/ed25519.js.map +1 -1
  57. package/esm/ed448.js +4 -3
  58. package/esm/ed448.js.map +1 -1
  59. package/esm/jubjub.js +2 -2
  60. package/esm/jubjub.js.map +1 -1
  61. package/esm/p256.js +1 -1
  62. package/esm/p256.js.map +1 -1
  63. package/esm/p384.js +1 -1
  64. package/esm/p384.js.map +1 -1
  65. package/esm/p521.js +1 -1
  66. package/esm/p521.js.map +1 -1
  67. package/esm/pasta.js +2 -2
  68. package/esm/pasta.js.map +1 -1
  69. package/esm/secp256k1.js +2 -2
  70. package/esm/secp256k1.js.map +1 -1
  71. package/jubjub.js +1 -1
  72. package/jubjub.js.map +1 -1
  73. package/p256.d.ts +4 -2
  74. package/p256.d.ts.map +1 -1
  75. package/p256.js +1 -1
  76. package/p256.js.map +1 -1
  77. package/p384.d.ts +4 -2
  78. package/p384.d.ts.map +1 -1
  79. package/p384.js +1 -1
  80. package/p384.js.map +1 -1
  81. package/p521.d.ts +4 -2
  82. package/p521.d.ts.map +1 -1
  83. package/p521.js +1 -1
  84. package/p521.js.map +1 -1
  85. package/package.json +5 -5
  86. package/pasta.js +2 -2
  87. package/pasta.js.map +1 -1
  88. package/secp256k1.d.ts +2 -1
  89. package/secp256k1.d.ts.map +1 -1
  90. package/secp256k1.js +2 -2
  91. package/secp256k1.js.map +1 -1
  92. package/src/abstract/bls.ts +11 -11
  93. package/src/abstract/curve.ts +7 -3
  94. package/src/abstract/edwards.ts +12 -9
  95. package/src/abstract/hash-to-curve.ts +2 -2
  96. package/src/abstract/modular.ts +29 -20
  97. package/src/abstract/poseidon.ts +2 -2
  98. package/src/abstract/weierstrass.ts +45 -27
  99. package/src/bls12-381.ts +199 -114
  100. package/src/bn.ts +2 -2
  101. package/src/ed25519.ts +2 -2
  102. package/src/ed448.ts +4 -3
  103. package/src/jubjub.ts +2 -2
  104. package/src/p256.ts +1 -1
  105. package/src/p384.ts +1 -1
  106. package/src/p521.ts +1 -1
  107. package/src/pasta.ts +2 -2
  108. package/src/secp256k1.ts +3 -4
package/bls12-381.js CHANGED
@@ -54,12 +54,16 @@ const utils_js_1 = require("./abstract/utils.js");
54
54
  // Types
55
55
  const weierstrass_js_1 = require("./abstract/weierstrass.js");
56
56
  const hash_to_curve_js_1 = require("./abstract/hash-to-curve.js");
57
+ // Be friendly to bad ECMAScript parsers by not using bigint literals
58
+ // prettier-ignore
59
+ const _0n = BigInt(0), _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3), _4n = BigInt(4);
60
+ const _8n = BigInt(8), _16n = BigInt(16);
57
61
  // CURVE FIELDS
58
62
  // Finite field over p.
59
- const Fp = mod.Fp(0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaabn);
63
+ const Fp = mod.Field(BigInt('0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab'));
60
64
  // Finite field over r.
61
65
  // This particular field is not used anywhere in bls12-381, but it is still useful.
62
- const Fr = mod.Fp(0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001n);
66
+ const Fr = mod.Field(BigInt('0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001'));
63
67
  const Fp2Add = ({ c0, c1 }, { c0: r0, c1: r1 }) => ({
64
68
  c0: Fp.add(c0, r0),
65
69
  c1: Fp.add(c1, r1),
@@ -91,8 +95,7 @@ const Fp2Square = ({ c0, c1 }) => {
91
95
  // G² - 1
92
96
  // h2q
93
97
  // NOTE: ORDER was wrong!
94
- const FP2_ORDER = 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaabn **
95
- 2n;
98
+ const FP2_ORDER = BigInt('0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab') ** _2n;
96
99
  const Fp2 = {
97
100
  ORDER: FP2_ORDER,
98
101
  BITS: (0, utils_js_1.bitLen)(FP2_ORDER),
@@ -145,7 +148,7 @@ const Fp2 = {
145
148
  // https://github.com/zkcrypto/bls12_381/blob/080eaa74ec0e394377caa1ba302c8c121df08b07/src/fp2.rs#L250
146
149
  // https://github.com/supranational/blst/blob/aae0c7d70b799ac269ff5edf29d8191dbd357876/src/exp2.c#L1
147
150
  // Inspired by https://github.com/dalek-cryptography/curve25519-dalek/blob/17698df9d4c834204f83a3574143abacb4fc81a5/src/field.rs#L99
148
- const candidateSqrt = Fp2.pow(num, (Fp2.ORDER + 8n) / 16n);
151
+ const candidateSqrt = Fp2.pow(num, (Fp2.ORDER + _8n) / _16n);
149
152
  const check = Fp2.div(Fp2.sqr(candidateSqrt), num); // candidateSqrt.square().div(this);
150
153
  const R = FP2_ROOTS_OF_UNITY;
151
154
  const divisor = [R[0], R[2], R[4], R[6]].find((r) => Fp2.eql(r, check));
@@ -166,10 +169,10 @@ const Fp2 = {
166
169
  // Same as sgn0_fp2 in draft-irtf-cfrg-hash-to-curve-16
167
170
  isOdd: (x) => {
168
171
  const { re: x0, im: x1 } = Fp2.reim(x);
169
- const sign_0 = x0 % 2n;
170
- const zero_0 = x0 === 0n;
171
- const sign_1 = x1 % 2n;
172
- return BigInt(sign_0 || (zero_0 && sign_1)) == 1n;
172
+ const sign_0 = x0 % _2n;
173
+ const zero_0 = x0 === _0n;
174
+ const sign_1 = x1 % _2n;
175
+ return BigInt(sign_0 || (zero_0 && sign_1)) == _1n;
173
176
  },
174
177
  // Bytes util
175
178
  fromBytes(b) {
@@ -190,8 +193,8 @@ const Fp2 = {
190
193
  // multiply by u + 1
191
194
  mulByNonresidue: ({ c0, c1 }) => ({ c0: Fp.sub(c0, c1), c1: Fp.add(c0, c1) }),
192
195
  multiplyByB: ({ c0, c1 }) => {
193
- let t0 = Fp.mul(c0, 4n); // 4 * c0
194
- let t1 = Fp.mul(c1, 4n); // 4 * c1
196
+ let t0 = Fp.mul(c0, _4n); // 4 * c0
197
+ let t1 = Fp.mul(c1, _4n); // 4 * c1
195
198
  // (T0-T1) + (T0+T1)*i
196
199
  return { c0: Fp.sub(t0, t1), c1: Fp.add(t0, t1) };
197
200
  },
@@ -209,30 +212,30 @@ const Fp2 = {
209
212
  // Finite extension field over irreducible polynominal.
210
213
  // Fp(u) / (u² - β) where β = -1
211
214
  const FP2_FROBENIUS_COEFFICIENTS = [
212
- 0x1n,
213
- 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaan,
215
+ BigInt('0x1'),
216
+ BigInt('0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa'),
214
217
  ].map((item) => Fp.create(item));
215
218
  // For Fp2 roots of unity.
216
- const rv1 = 0x6af0e0437ff400b6831e36d6bd17ffe48395dabc2d3435e77f76e17009241c5ee67992f72ec05f4c81084fbede3cc09n;
219
+ const rv1 = BigInt('0x6af0e0437ff400b6831e36d6bd17ffe48395dabc2d3435e77f76e17009241c5ee67992f72ec05f4c81084fbede3cc09');
217
220
  // const ev1 =
218
- // 0x699be3b8c6870965e5bf892ad5d2cc7b0e85a117402dfd83b7f4a947e02d978498255a2aaec0ac627b5afbdf1bf1c90n;
221
+ // BigInt('0x699be3b8c6870965e5bf892ad5d2cc7b0e85a117402dfd83b7f4a947e02d978498255a2aaec0ac627b5afbdf1bf1c90');
219
222
  // const ev2 =
220
- // 0x8157cd83046453f5dd0972b6e3949e4288020b5b8a9cc99ca07e27089a2ce2436d965026adad3ef7baba37f2183e9b5n;
223
+ // BigInt('0x8157cd83046453f5dd0972b6e3949e4288020b5b8a9cc99ca07e27089a2ce2436d965026adad3ef7baba37f2183e9b5');
221
224
  // const ev3 =
222
- // 0xab1c2ffdd6c253ca155231eb3e71ba044fd562f6f72bc5bad5ec46a0b7a3b0247cf08ce6c6317f40edbc653a72dee17n;
225
+ // BigInt('0xab1c2ffdd6c253ca155231eb3e71ba044fd562f6f72bc5bad5ec46a0b7a3b0247cf08ce6c6317f40edbc653a72dee17');
223
226
  // const ev4 =
224
- // 0xaa404866706722864480885d68ad0ccac1967c7544b447873cc37e0181271e006df72162a3d3e0287bf597fbf7f8fc1n;
227
+ // BigInt('0xaa404866706722864480885d68ad0ccac1967c7544b447873cc37e0181271e006df72162a3d3e0287bf597fbf7f8fc1');
225
228
  // Eighth roots of unity, used for computing square roots in Fp2.
226
229
  // To verify or re-calculate:
227
230
  // Array(8).fill(new Fp2([1n, 1n])).map((fp2, k) => fp2.pow(Fp2.ORDER * BigInt(k) / 8n))
228
231
  const FP2_ROOTS_OF_UNITY = [
229
- [1n, 0n],
232
+ [_1n, _0n],
230
233
  [rv1, -rv1],
231
- [0n, 1n],
234
+ [_0n, _1n],
232
235
  [rv1, rv1],
233
- [-1n, 0n],
236
+ [-_1n, _0n],
234
237
  [-rv1, rv1],
235
- [0n, -1n],
238
+ [_0n, -_1n],
236
239
  [-rv1, -rv1],
237
240
  ].map((pair) => Fp2.fromBigTuple(pair));
238
241
  const Fp6Add = ({ c0, c1, c2 }, { c0: r0, c1: r1, c2: r2 }) => ({
@@ -268,8 +271,8 @@ const Fp6Multiply = ({ c0, c1, c2 }, rhs) => {
268
271
  };
269
272
  const Fp6Square = ({ c0, c1, c2 }) => {
270
273
  let t0 = Fp2.sqr(c0); // c0²
271
- let t1 = Fp2.mul(Fp2.mul(c0, c1), 2n); // 2 * c0 * c1
272
- let t3 = Fp2.mul(Fp2.mul(c1, c2), 2n); // 2 * c1 * c2
274
+ let t1 = Fp2.mul(Fp2.mul(c0, c1), _2n); // 2 * c0 * c1
275
+ let t3 = Fp2.mul(Fp2.mul(c1, c2), _2n); // 2 * c1 * c2
273
276
  let t4 = Fp2.sqr(c2); // c2²
274
277
  return {
275
278
  c0: Fp2.add(Fp2.mulByNonresidue(t3), t0),
@@ -379,50 +382,50 @@ const Fp6 = {
379
382
  }),
380
383
  };
381
384
  const FP6_FROBENIUS_COEFFICIENTS_1 = [
382
- [0x1n, 0x0n],
385
+ [BigInt('0x1'), BigInt('0x0')],
383
386
  [
384
- 0x0n,
385
- 0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4897d29650fb85f9b409427eb4f49fffd8bfd00000000aaacn,
387
+ BigInt('0x0'),
388
+ BigInt('0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4897d29650fb85f9b409427eb4f49fffd8bfd00000000aaac'),
386
389
  ],
387
390
  [
388
- 0x00000000000000005f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffen,
389
- 0x0n,
391
+ BigInt('0x00000000000000005f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe'),
392
+ BigInt('0x0'),
390
393
  ],
391
- [0x0n, 0x1n],
394
+ [BigInt('0x0'), BigInt('0x1')],
392
395
  [
393
- 0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4897d29650fb85f9b409427eb4f49fffd8bfd00000000aaacn,
394
- 0x0n,
396
+ BigInt('0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4897d29650fb85f9b409427eb4f49fffd8bfd00000000aaac'),
397
+ BigInt('0x0'),
395
398
  ],
396
399
  [
397
- 0x0n,
398
- 0x00000000000000005f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffen,
400
+ BigInt('0x0'),
401
+ BigInt('0x00000000000000005f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe'),
399
402
  ],
400
403
  ].map((pair) => Fp2.fromBigTuple(pair));
401
404
  const FP6_FROBENIUS_COEFFICIENTS_2 = [
402
- [0x1n, 0x0n],
405
+ [BigInt('0x1'), BigInt('0x0')],
403
406
  [
404
- 0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4897d29650fb85f9b409427eb4f49fffd8bfd00000000aaadn,
405
- 0x0n,
407
+ BigInt('0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4897d29650fb85f9b409427eb4f49fffd8bfd00000000aaad'),
408
+ BigInt('0x0'),
406
409
  ],
407
410
  [
408
- 0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4897d29650fb85f9b409427eb4f49fffd8bfd00000000aaacn,
409
- 0x0n,
411
+ BigInt('0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4897d29650fb85f9b409427eb4f49fffd8bfd00000000aaac'),
412
+ BigInt('0x0'),
410
413
  ],
411
414
  [
412
- 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaan,
413
- 0x0n,
415
+ BigInt('0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa'),
416
+ BigInt('0x0'),
414
417
  ],
415
418
  [
416
- 0x00000000000000005f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffen,
417
- 0x0n,
419
+ BigInt('0x00000000000000005f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe'),
420
+ BigInt('0x0'),
418
421
  ],
419
422
  [
420
- 0x00000000000000005f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffeffffn,
421
- 0x0n,
423
+ BigInt('0x00000000000000005f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffeffff'),
424
+ BigInt('0x0'),
422
425
  ],
423
426
  ].map((pair) => Fp2.fromBigTuple(pair));
424
427
  // The BLS parameter x for BLS12-381
425
- const BLS_X = 0xd201000000010000n;
428
+ const BLS_X = BigInt('0xd201000000010000');
426
429
  const BLS_X_LEN = (0, utils_js_1.bitLen)(BLS_X);
427
430
  const Fp12Add = ({ c0, c1 }, { c0: r0, c1: r1 }) => ({
428
431
  c0: Fp6.add(c0, r0),
@@ -559,14 +562,14 @@ const Fp12 = {
559
562
  let t9 = Fp2.mulByNonresidue(t8); // T8 * (u + 1)
560
563
  return {
561
564
  c0: Fp6.create({
562
- c0: Fp2.add(Fp2.mul(Fp2.sub(t3, c0c0), 2n), t3),
563
- c1: Fp2.add(Fp2.mul(Fp2.sub(t5, c0c1), 2n), t5),
564
- c2: Fp2.add(Fp2.mul(Fp2.sub(t7, c0c2), 2n), t7),
565
+ c0: Fp2.add(Fp2.mul(Fp2.sub(t3, c0c0), _2n), t3),
566
+ c1: Fp2.add(Fp2.mul(Fp2.sub(t5, c0c1), _2n), t5),
567
+ c2: Fp2.add(Fp2.mul(Fp2.sub(t7, c0c2), _2n), t7),
565
568
  }),
566
569
  c1: Fp6.create({
567
- c0: Fp2.add(Fp2.mul(Fp2.add(t9, c1c0), 2n), t9),
568
- c1: Fp2.add(Fp2.mul(Fp2.add(t4, c1c1), 2n), t4),
569
- c2: Fp2.add(Fp2.mul(Fp2.add(t6, c1c2), 2n), t6),
570
+ c0: Fp2.add(Fp2.mul(Fp2.add(t9, c1c0), _2n), t9),
571
+ c1: Fp2.add(Fp2.mul(Fp2.add(t4, c1c1), _2n), t4),
572
+ c2: Fp2.add(Fp2.mul(Fp2.add(t6, c1c2), _2n), t6),
570
573
  }),
571
574
  }; // 2 * (T6 + c1c2) + T6
572
575
  },
@@ -602,50 +605,50 @@ const Fp12 = {
602
605
  },
603
606
  };
604
607
  const FP12_FROBENIUS_COEFFICIENTS = [
605
- [0x1n, 0x0n],
608
+ [BigInt('0x1'), BigInt('0x0')],
606
609
  [
607
- 0x1904d3bf02bb0667c231beb4202c0d1f0fd603fd3cbd5f4f7b2443d784bab9c4f67ea53d63e7813d8d0775ed92235fb8n,
608
- 0x00fc3e2b36c4e03288e9e902231f9fb854a14787b6c7b36fec0c8ec971f63c5f282d5ac14d6c7ec22cf78a126ddc4af3n,
610
+ BigInt('0x1904d3bf02bb0667c231beb4202c0d1f0fd603fd3cbd5f4f7b2443d784bab9c4f67ea53d63e7813d8d0775ed92235fb8'),
611
+ BigInt('0x00fc3e2b36c4e03288e9e902231f9fb854a14787b6c7b36fec0c8ec971f63c5f282d5ac14d6c7ec22cf78a126ddc4af3'),
609
612
  ],
610
613
  [
611
- 0x00000000000000005f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffeffffn,
612
- 0x0n,
614
+ BigInt('0x00000000000000005f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffeffff'),
615
+ BigInt('0x0'),
613
616
  ],
614
617
  [
615
- 0x135203e60180a68ee2e9c448d77a2cd91c3dedd930b1cf60ef396489f61eb45e304466cf3e67fa0af1ee7b04121bdea2n,
616
- 0x06af0e0437ff400b6831e36d6bd17ffe48395dabc2d3435e77f76e17009241c5ee67992f72ec05f4c81084fbede3cc09n,
618
+ BigInt('0x135203e60180a68ee2e9c448d77a2cd91c3dedd930b1cf60ef396489f61eb45e304466cf3e67fa0af1ee7b04121bdea2'),
619
+ BigInt('0x06af0e0437ff400b6831e36d6bd17ffe48395dabc2d3435e77f76e17009241c5ee67992f72ec05f4c81084fbede3cc09'),
617
620
  ],
618
621
  [
619
- 0x00000000000000005f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffen,
620
- 0x0n,
622
+ BigInt('0x00000000000000005f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe'),
623
+ BigInt('0x0'),
621
624
  ],
622
625
  [
623
- 0x144e4211384586c16bd3ad4afa99cc9170df3560e77982d0db45f3536814f0bd5871c1908bd478cd1ee605167ff82995n,
624
- 0x05b2cfd9013a5fd8df47fa6b48b1e045f39816240c0b8fee8beadf4d8e9c0566c63a3e6e257f87329b18fae980078116n,
626
+ BigInt('0x144e4211384586c16bd3ad4afa99cc9170df3560e77982d0db45f3536814f0bd5871c1908bd478cd1ee605167ff82995'),
627
+ BigInt('0x05b2cfd9013a5fd8df47fa6b48b1e045f39816240c0b8fee8beadf4d8e9c0566c63a3e6e257f87329b18fae980078116'),
625
628
  ],
626
629
  [
627
- 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaan,
628
- 0x0n,
630
+ BigInt('0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa'),
631
+ BigInt('0x0'),
629
632
  ],
630
633
  [
631
- 0x00fc3e2b36c4e03288e9e902231f9fb854a14787b6c7b36fec0c8ec971f63c5f282d5ac14d6c7ec22cf78a126ddc4af3n,
632
- 0x1904d3bf02bb0667c231beb4202c0d1f0fd603fd3cbd5f4f7b2443d784bab9c4f67ea53d63e7813d8d0775ed92235fb8n,
634
+ BigInt('0x00fc3e2b36c4e03288e9e902231f9fb854a14787b6c7b36fec0c8ec971f63c5f282d5ac14d6c7ec22cf78a126ddc4af3'),
635
+ BigInt('0x1904d3bf02bb0667c231beb4202c0d1f0fd603fd3cbd5f4f7b2443d784bab9c4f67ea53d63e7813d8d0775ed92235fb8'),
633
636
  ],
634
637
  [
635
- 0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4897d29650fb85f9b409427eb4f49fffd8bfd00000000aaacn,
636
- 0x0n,
638
+ BigInt('0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4897d29650fb85f9b409427eb4f49fffd8bfd00000000aaac'),
639
+ BigInt('0x0'),
637
640
  ],
638
641
  [
639
- 0x06af0e0437ff400b6831e36d6bd17ffe48395dabc2d3435e77f76e17009241c5ee67992f72ec05f4c81084fbede3cc09n,
640
- 0x135203e60180a68ee2e9c448d77a2cd91c3dedd930b1cf60ef396489f61eb45e304466cf3e67fa0af1ee7b04121bdea2n,
642
+ BigInt('0x06af0e0437ff400b6831e36d6bd17ffe48395dabc2d3435e77f76e17009241c5ee67992f72ec05f4c81084fbede3cc09'),
643
+ BigInt('0x135203e60180a68ee2e9c448d77a2cd91c3dedd930b1cf60ef396489f61eb45e304466cf3e67fa0af1ee7b04121bdea2'),
641
644
  ],
642
645
  [
643
- 0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4897d29650fb85f9b409427eb4f49fffd8bfd00000000aaadn,
644
- 0x0n,
646
+ BigInt('0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4897d29650fb85f9b409427eb4f49fffd8bfd00000000aaad'),
647
+ BigInt('0x0'),
645
648
  ],
646
649
  [
647
- 0x05b2cfd9013a5fd8df47fa6b48b1e045f39816240c0b8fee8beadf4d8e9c0566c63a3e6e257f87329b18fae980078116n,
648
- 0x144e4211384586c16bd3ad4afa99cc9170df3560e77982d0db45f3536814f0bd5871c1908bd478cd1ee605167ff82995n,
650
+ BigInt('0x05b2cfd9013a5fd8df47fa6b48b1e045f39816240c0b8fee8beadf4d8e9c0566c63a3e6e257f87329b18fae980078116'),
651
+ BigInt('0x144e4211384586c16bd3ad4afa99cc9170df3560e77982d0db45f3536814f0bd5871c1908bd478cd1ee605167ff82995'),
649
652
  ],
650
653
  ].map((n) => Fp2.fromBigTuple(n));
651
654
  // END OF CURVE FIELDS
@@ -792,14 +795,14 @@ const isogenyMapG1 = (0, hash_to_curve_js_1.isogenyMap)(Fp, [
792
795
  ].map((i) => i.map((j) => BigInt(j))));
793
796
  // SWU Map - Fp2 to G2': y² = x³ + 240i * x + 1012 + 1012i
794
797
  const G2_SWU = (0, weierstrass_js_1.mapToCurveSimpleSWU)(Fp2, {
795
- A: Fp2.create({ c0: Fp.create(0n), c1: Fp.create(240n) }),
798
+ A: Fp2.create({ c0: Fp.create(_0n), c1: Fp.create(240n) }),
796
799
  B: Fp2.create({ c0: Fp.create(1012n), c1: Fp.create(1012n) }),
797
800
  Z: Fp2.create({ c0: Fp.create(-2n), c1: Fp.create(-1n) }), // Z: -(2 + I)
798
801
  });
799
802
  // Optimized SWU Map - Fp to G1
800
803
  const G1_SWU = (0, weierstrass_js_1.mapToCurveSimpleSWU)(Fp, {
801
- A: Fp.create(0x144698a3b8e9433d693a02c96d4982b0ea985383ee66a8d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1dn),
802
- B: Fp.create(0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0n),
804
+ A: Fp.create(BigInt('0x144698a3b8e9433d693a02c96d4982b0ea985383ee66a8d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1d')),
805
+ B: Fp.create(BigInt('0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0')),
803
806
  Z: Fp.create(11n),
804
807
  });
805
808
  // Endomorphisms (for fast cofactor clearing)
@@ -822,7 +825,7 @@ function G2psi(c, P) {
822
825
  }
823
826
  // Ψ²(P) endomorphism
824
827
  // 1 / F2(2)^((p-1)/3) in GF(p²)
825
- const PSI2_C1 = 0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4897d29650fb85f9b409427eb4f49fffd8bfd00000000aaacn;
828
+ const PSI2_C1 = BigInt('0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4897d29650fb85f9b409427eb4f49fffd8bfd00000000aaac');
826
829
  function psi2(x, y) {
827
830
  return [Fp2.mul(x, PSI2_C1), Fp2.neg(y)];
828
831
  }
@@ -895,14 +898,14 @@ exports.bls12_381 = (0, bls_js_1.bls)({
895
898
  G1: {
896
899
  Fp,
897
900
  // cofactor; (z - 1)²/3
898
- h: 0x396c8c005555e1568c00aaab0000aaabn,
901
+ h: BigInt('0x396c8c005555e1568c00aaab0000aaab'),
899
902
  // generator's coordinates
900
903
  // x = 3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507
901
904
  // y = 1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569
902
- Gx: 0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bbn,
903
- Gy: 0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1n,
905
+ Gx: BigInt('0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb'),
906
+ Gy: BigInt('0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1'),
904
907
  a: Fp.ZERO,
905
- b: 4n,
908
+ b: _4n,
906
909
  htfDefaults: { ...htfDefaults, m: 1 },
907
910
  wrapPrivateKey: true,
908
911
  allowInfinityPoint: true,
@@ -912,7 +915,7 @@ exports.bls12_381 = (0, bls_js_1.bls)({
912
915
  // https://eprint.iacr.org/2021/1130.pdf
913
916
  isTorsionFree: (c, point) => {
914
917
  // φ endomorphism
915
- const cubicRootOfUnityModP = 0x5f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffen;
918
+ const cubicRootOfUnityModP = BigInt('0x5f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe');
916
919
  const phi = new c(Fp.mul(point.px, cubicRootOfUnityModP), point.py, point.pz);
917
920
  // todo: unroll
918
921
  const xP = point.multiplyUnsafe(exports.bls12_381.CURVE.x).negate(); // [x]P
@@ -920,7 +923,7 @@ exports.bls12_381 = (0, bls_js_1.bls)({
920
923
  return u2P.equals(phi);
921
924
  // https://eprint.iacr.org/2019/814.pdf
922
925
  // (z² − 1)/3
923
- // const c1 = 0x396c8c005555e1560000000055555555n;
926
+ // const c1 = BigInt('0x396c8c005555e1560000000055555555');
924
927
  // const P = this;
925
928
  // const S = P.sigma();
926
929
  // const Q = S.double();
@@ -946,15 +949,15 @@ exports.bls12_381 = (0, bls_js_1.bls)({
946
949
  const compressedValue = (0, utils_js_1.bytesToNumberBE)(bytes);
947
950
  const bflag = (0, utils_js_1.bitGet)(compressedValue, I_BIT_POS);
948
951
  // Zero
949
- if (bflag === 1n)
950
- return { x: 0n, y: 0n };
952
+ if (bflag === _1n)
953
+ return { x: _0n, y: _0n };
951
954
  const x = Fp.create(compressedValue & Fp.MASK);
952
- const right = Fp.add(Fp.pow(x, 3n), Fp.create(exports.bls12_381.CURVE.G1.b)); // y² = x³ + b
955
+ const right = Fp.add(Fp.pow(x, _3n), Fp.create(exports.bls12_381.CURVE.G1.b)); // y² = x³ + b
953
956
  let y = Fp.sqrt(right);
954
957
  if (!y)
955
958
  throw new Error('Invalid compressed G1 point');
956
959
  const aflag = (0, utils_js_1.bitGet)(compressedValue, C_BIT_POS);
957
- if ((y * 2n) / P !== aflag)
960
+ if ((y * _2n) / P !== aflag)
958
961
  y = Fp.neg(y);
959
962
  return { x: Fp.create(x), y: Fp.create(y) };
960
963
  }
@@ -978,7 +981,7 @@ exports.bls12_381 = (0, bls_js_1.bls)({
978
981
  return COMPRESSED_ZERO.slice();
979
982
  const P = Fp.ORDER;
980
983
  let num;
981
- num = (0, utils_js_1.bitSet)(x, C_BIT_POS, Boolean((y * 2n) / P)); // set aflag
984
+ num = (0, utils_js_1.bitSet)(x, C_BIT_POS, Boolean((y * _2n) / P)); // set aflag
982
985
  num = (0, utils_js_1.bitSet)(num, S_BIT_POS, true);
983
986
  return (0, utils_js_1.numberToBytesBE)(num, Fp.BYTES);
984
987
  }
@@ -1001,21 +1004,21 @@ exports.bls12_381 = (0, bls_js_1.bls)({
1001
1004
  G2: {
1002
1005
  Fp: Fp2,
1003
1006
  // cofactor
1004
- h: 0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5n,
1007
+ h: BigInt('0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5'),
1005
1008
  Gx: Fp2.fromBigTuple([
1006
- 0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8n,
1007
- 0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7en,
1009
+ BigInt('0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8'),
1010
+ BigInt('0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e'),
1008
1011
  ]),
1009
1012
  // y =
1010
1013
  // 927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582,
1011
1014
  // 1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905
1012
1015
  Gy: Fp2.fromBigTuple([
1013
- 0x0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801n,
1014
- 0x0606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79ben,
1016
+ BigInt('0x0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801'),
1017
+ BigInt('0x0606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be'),
1015
1018
  ]),
1016
1019
  a: Fp2.ZERO,
1017
- b: Fp2.fromBigTuple([4n, 4n]),
1018
- hEff: 0xbc69f08f2ee75b3584c6a0ea91b352888e2a8e9145ad7689986ff031508ffe1329c2f178731db956d82bf015d1212b02ec0ec69d7477c1ae954cbc06689f6a359894c0adebbf6b4e8020005aaa95551n,
1020
+ b: Fp2.fromBigTuple([4n, _4n]),
1021
+ hEff: BigInt('0xbc69f08f2ee75b3584c6a0ea91b352888e2a8e9145ad7689986ff031508ffe1329c2f178731db956d82bf015d1212b02ec0ec69d7477c1ae954cbc06689f6a359894c0adebbf6b4e8020005aaa95551'),
1019
1022
  htfDefaults: { ...htfDefaults },
1020
1023
  wrapPrivateKey: true,
1021
1024
  allowInfinityPoint: true,
@@ -1075,9 +1078,9 @@ exports.bls12_381 = (0, bls_js_1.bls)({
1075
1078
  const x_1 = slc(bytes, 0, L);
1076
1079
  const x_0 = slc(bytes, L, 2 * L);
1077
1080
  const x = Fp2.create({ c0: Fp.create(x_0), c1: Fp.create(x_1) });
1078
- const right = Fp2.add(Fp2.pow(x, 3n), b); // y² = x³ + 4 * (u+1) = x³ + b
1081
+ const right = Fp2.add(Fp2.pow(x, _3n), b); // y² = x³ + 4 * (u+1) = x³ + b
1079
1082
  let y = Fp2.sqrt(right);
1080
- const Y_bit = y.c1 === 0n ? (y.c0 * 2n) / P : (y.c1 * 2n) / P ? 1n : 0n;
1083
+ const Y_bit = y.c1 === _0n ? (y.c0 * _2n) / P : (y.c1 * _2n) / P ? _1n : _0n;
1081
1084
  y = bitS > 0 && Y_bit > 0 ? y : Fp2.neg(y);
1082
1085
  return { x, y };
1083
1086
  }
@@ -1103,7 +1106,7 @@ exports.bls12_381 = (0, bls_js_1.bls)({
1103
1106
  const P = Fp.ORDER;
1104
1107
  if (isZero)
1105
1108
  return (0, utils_js_1.concatBytes)(COMPRESSED_ZERO, (0, utils_js_1.numberToBytesBE)(0n, Fp.BYTES));
1106
- const flag = Boolean(y.c1 === 0n ? (y.c0 * 2n) / P : (y.c1 * 2n) / P);
1109
+ const flag = Boolean(y.c1 === _0n ? (y.c0 * _2n) / P : (y.c1 * _2n) / P);
1107
1110
  // set compressed & sign bits (looks like different offsets than for G1/Fp?)
1108
1111
  let x_1 = (0, utils_js_1.bitSet)(x.c1, C_BIT_POS, flag);
1109
1112
  x_1 = (0, utils_js_1.bitSet)(x_1, S_BIT_POS, true);
@@ -1129,12 +1132,12 @@ exports.bls12_381 = (0, bls_js_1.bls)({
1129
1132
  const z2 = (0, utils_js_1.bytesToNumberBE)(hex.slice(half));
1130
1133
  // Indicates the infinity point
1131
1134
  const bflag1 = (0, utils_js_1.bitGet)(z1, I_BIT_POS);
1132
- if (bflag1 === 1n)
1135
+ if (bflag1 === _1n)
1133
1136
  return exports.bls12_381.G2.ProjectivePoint.ZERO;
1134
1137
  const x1 = Fp.create(z1 & Fp.MASK);
1135
1138
  const x2 = Fp.create(z2);
1136
1139
  const x = Fp2.create({ c0: x2, c1: x1 });
1137
- const y2 = Fp2.add(Fp2.pow(x, 3n), exports.bls12_381.CURVE.G2.b); // y² = x³ + 4
1140
+ const y2 = Fp2.add(Fp2.pow(x, _3n), exports.bls12_381.CURVE.G2.b); // y² = x³ + 4
1138
1141
  // The slow part
1139
1142
  let y = Fp2.sqrt(y2);
1140
1143
  if (!y)
@@ -1143,8 +1146,8 @@ exports.bls12_381 = (0, bls_js_1.bls)({
1143
1146
  // If y1 happens to be zero, then use the bit of y0
1144
1147
  const { re: y0, im: y1 } = Fp2.reim(y);
1145
1148
  const aflag1 = (0, utils_js_1.bitGet)(z1, 381);
1146
- const isGreater = y1 > 0n && (y1 * 2n) / P !== aflag1;
1147
- const isZero = y1 === 0n && (y0 * 2n) / P !== aflag1;
1149
+ const isGreater = y1 > _0n && (y1 * _2n) / P !== aflag1;
1150
+ const isZero = y1 === _0n && (y0 * _2n) / P !== aflag1;
1148
1151
  if (isGreater || isZero)
1149
1152
  y = Fp2.neg(y);
1150
1153
  const point = exports.bls12_381.G2.ProjectivePoint.fromAffine({ x, y });
@@ -1159,8 +1162,8 @@ exports.bls12_381 = (0, bls_js_1.bls)({
1159
1162
  const a = point.toAffine();
1160
1163
  const { re: x0, im: x1 } = Fp2.reim(a.x);
1161
1164
  const { re: y0, im: y1 } = Fp2.reim(a.y);
1162
- const tmp = y1 > 0n ? y1 * 2n : y0 * 2n;
1163
- const aflag1 = Boolean((tmp / Fp.ORDER) & 1n);
1165
+ const tmp = y1 > _0n ? y1 * _2n : y0 * _2n;
1166
+ const aflag1 = Boolean((tmp / Fp.ORDER) & _1n);
1164
1167
  const z1 = (0, utils_js_1.bitSet)((0, utils_js_1.bitSet)(x1, 381, aflag1), S_BIT_POS, true);
1165
1168
  const z2 = x0;
1166
1169
  return (0, utils_js_1.concatBytes)((0, utils_js_1.numberToBytesBE)(z1, Fp.BYTES), (0, utils_js_1.numberToBytesBE)(z2, Fp.BYTES));