@noble/curves 1.4.0 → 1.4.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 (169) hide show
  1. package/README.md +31 -23
  2. package/_shortw_utils.d.ts +16 -16
  3. package/_shortw_utils.d.ts.map +1 -1
  4. package/_shortw_utils.js +2 -3
  5. package/_shortw_utils.js.map +1 -1
  6. package/abstract/bls.d.ts +24 -22
  7. package/abstract/bls.d.ts.map +1 -1
  8. package/abstract/bls.js +1 -2
  9. package/abstract/bls.js.map +1 -1
  10. package/abstract/curve.d.ts.map +1 -1
  11. package/abstract/curve.js +2 -3
  12. package/abstract/curve.js.map +1 -1
  13. package/abstract/edwards.d.ts +12 -12
  14. package/abstract/edwards.d.ts.map +1 -1
  15. package/abstract/edwards.js +12 -5
  16. package/abstract/edwards.js.map +1 -1
  17. package/abstract/hash-to-curve.d.ts +2 -1
  18. package/abstract/hash-to-curve.d.ts.map +1 -1
  19. package/abstract/hash-to-curve.js +16 -6
  20. package/abstract/hash-to-curve.js.map +1 -1
  21. package/abstract/modular.d.ts.map +1 -1
  22. package/abstract/modular.js +20 -20
  23. package/abstract/modular.js.map +1 -1
  24. package/abstract/montgomery.js +1 -2
  25. package/abstract/montgomery.js.map +1 -1
  26. package/abstract/poseidon.d.ts +2 -2
  27. package/abstract/poseidon.d.ts.map +1 -1
  28. package/abstract/poseidon.js +3 -4
  29. package/abstract/poseidon.js.map +1 -1
  30. package/abstract/utils.d.ts +5 -5
  31. package/abstract/utils.js +24 -24
  32. package/abstract/utils.js.map +1 -1
  33. package/abstract/weierstrass.d.ts +17 -17
  34. package/abstract/weierstrass.d.ts.map +1 -1
  35. package/abstract/weierstrass.js +18 -8
  36. package/abstract/weierstrass.js.map +1 -1
  37. package/bls12-381.d.ts +0 -1
  38. package/bls12-381.d.ts.map +1 -1
  39. package/bls12-381.js +41 -39
  40. package/bls12-381.js.map +1 -1
  41. package/bn254.js +1 -1
  42. package/bn254.js.map +1 -1
  43. package/ed25519.d.ts +4 -4
  44. package/ed25519.d.ts.map +1 -1
  45. package/ed25519.js +34 -30
  46. package/ed25519.js.map +1 -1
  47. package/ed448.d.ts +3 -3
  48. package/ed448.d.ts.map +1 -1
  49. package/ed448.js +6 -3
  50. package/ed448.js.map +1 -1
  51. package/esm/_shortw_utils.d.ts +62 -0
  52. package/esm/_shortw_utils.d.ts.map +1 -0
  53. package/esm/_shortw_utils.js.map +1 -1
  54. package/esm/abstract/bls.d.ts +122 -0
  55. package/esm/abstract/bls.d.ts.map +1 -0
  56. package/esm/abstract/bls.js.map +1 -1
  57. package/esm/abstract/curve.d.ts +70 -0
  58. package/esm/abstract/curve.d.ts.map +1 -0
  59. package/esm/abstract/edwards.d.ts +89 -0
  60. package/esm/abstract/edwards.d.ts.map +1 -0
  61. package/esm/abstract/edwards.js +11 -3
  62. package/esm/abstract/edwards.js.map +1 -1
  63. package/esm/abstract/hash-to-curve.d.ts +58 -0
  64. package/esm/abstract/hash-to-curve.d.ts.map +1 -0
  65. package/esm/abstract/hash-to-curve.js +12 -1
  66. package/esm/abstract/hash-to-curve.js.map +1 -1
  67. package/esm/abstract/modular.d.ts +123 -0
  68. package/esm/abstract/modular.d.ts.map +1 -0
  69. package/esm/abstract/modular.js +1 -1
  70. package/esm/abstract/modular.js.map +1 -1
  71. package/esm/abstract/montgomery.d.ts +26 -0
  72. package/esm/abstract/montgomery.d.ts.map +1 -0
  73. package/esm/abstract/poseidon.d.ts +30 -0
  74. package/esm/abstract/poseidon.d.ts.map +1 -0
  75. package/esm/abstract/poseidon.js.map +1 -1
  76. package/esm/abstract/utils.d.ts +94 -0
  77. package/esm/abstract/utils.d.ts.map +1 -0
  78. package/esm/abstract/utils.js +3 -3
  79. package/esm/abstract/utils.js.map +1 -1
  80. package/esm/abstract/weierstrass.d.ts +237 -0
  81. package/esm/abstract/weierstrass.d.ts.map +1 -0
  82. package/esm/abstract/weierstrass.js +13 -3
  83. package/esm/abstract/weierstrass.js.map +1 -1
  84. package/esm/bls12-381.d.ts +67 -0
  85. package/esm/bls12-381.d.ts.map +1 -0
  86. package/esm/bls12-381.js +41 -39
  87. package/esm/bls12-381.js.map +1 -1
  88. package/esm/bn254.d.ts +9 -0
  89. package/esm/bn254.d.ts.map +1 -0
  90. package/esm/bn254.js +1 -1
  91. package/esm/bn254.js.map +1 -1
  92. package/esm/ed25519.d.ts +78 -0
  93. package/esm/ed25519.d.ts.map +1 -0
  94. package/esm/ed25519.js +31 -27
  95. package/esm/ed25519.js.map +1 -1
  96. package/esm/ed448.d.ts +67 -0
  97. package/esm/ed448.d.ts.map +1 -0
  98. package/esm/ed448.js +5 -2
  99. package/esm/ed448.js.map +1 -1
  100. package/esm/index.d.ts +2 -0
  101. package/esm/index.d.ts.map +1 -0
  102. package/esm/index.js +1 -1
  103. package/esm/index.js.map +1 -1
  104. package/esm/jubjub.d.ts +9 -0
  105. package/esm/jubjub.d.ts.map +1 -0
  106. package/esm/jubjub.js +1 -1
  107. package/esm/jubjub.js.map +1 -1
  108. package/esm/p256.d.ts +105 -0
  109. package/esm/p256.d.ts.map +1 -0
  110. package/esm/p256.js +2 -2
  111. package/esm/p256.js.map +1 -1
  112. package/esm/p384.d.ts +105 -0
  113. package/esm/p384.d.ts.map +1 -0
  114. package/esm/p384.js +2 -2
  115. package/esm/p384.js.map +1 -1
  116. package/esm/p521.d.ts +105 -0
  117. package/esm/p521.d.ts.map +1 -0
  118. package/esm/p521.js +2 -2
  119. package/esm/p521.js.map +1 -1
  120. package/esm/pasta.d.ts +5 -0
  121. package/esm/pasta.d.ts.map +1 -0
  122. package/esm/pasta.js +6 -6
  123. package/esm/pasta.js.map +1 -1
  124. package/esm/secp256k1.d.ts +93 -0
  125. package/esm/secp256k1.d.ts.map +1 -0
  126. package/esm/secp256k1.js +3 -3
  127. package/esm/secp256k1.js.map +1 -1
  128. package/index.js +1 -1
  129. package/index.js.map +1 -1
  130. package/jubjub.js +4 -4
  131. package/jubjub.js.map +1 -1
  132. package/p256.d.ts +32 -32
  133. package/p256.d.ts.map +1 -1
  134. package/p256.js +2 -2
  135. package/p256.js.map +1 -1
  136. package/p384.d.ts +32 -32
  137. package/p384.d.ts.map +1 -1
  138. package/p384.js +2 -2
  139. package/p384.js.map +1 -1
  140. package/p521.d.ts +32 -32
  141. package/p521.d.ts.map +1 -1
  142. package/p521.js +2 -2
  143. package/p521.js.map +1 -1
  144. package/package.json +26 -47
  145. package/pasta.js +6 -6
  146. package/pasta.js.map +1 -1
  147. package/secp256k1.d.ts +18 -18
  148. package/secp256k1.d.ts.map +1 -1
  149. package/secp256k1.js +3 -3
  150. package/secp256k1.js.map +1 -1
  151. package/src/_shortw_utils.ts +1 -1
  152. package/src/abstract/bls.ts +31 -25
  153. package/src/abstract/edwards.ts +3 -2
  154. package/src/abstract/hash-to-curve.ts +13 -3
  155. package/src/abstract/modular.ts +2 -2
  156. package/src/abstract/poseidon.ts +1 -1
  157. package/src/abstract/utils.ts +3 -3
  158. package/src/abstract/weierstrass.ts +1 -1
  159. package/src/bls12-381.ts +46 -44
  160. package/src/bn254.ts +1 -1
  161. package/src/ed25519.ts +76 -68
  162. package/src/ed448.ts +3 -3
  163. package/src/index.ts +1 -1
  164. package/src/jubjub.ts +1 -1
  165. package/src/p256.ts +2 -2
  166. package/src/p384.ts +2 -2
  167. package/src/p521.ts +2 -2
  168. package/src/pasta.ts +6 -6
  169. package/src/secp256k1.ts +3 -3
package/src/ed25519.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2
2
  import { sha512 } from '@noble/hashes/sha512';
3
3
  import { concatBytes, randomBytes, utf8ToBytes } from '@noble/hashes/utils';
4
+ import { AffinePoint, Group } from './abstract/curve.js';
4
5
  import { ExtPointType, twistedEdwards } from './abstract/edwards.js';
5
- import { montgomery } from './abstract/montgomery.js';
6
+ import { createHasher, expand_message_xmd, htfBasicOpts } from './abstract/hash-to-curve.js';
6
7
  import { Field, FpSqrtEven, isNegativeLE, mod, pow2 } from './abstract/modular.js';
8
+ import { montgomery } from './abstract/montgomery.js';
7
9
  import {
8
10
  bytesToHex,
9
11
  bytesToNumberLE,
@@ -12,8 +14,6 @@ import {
12
14
  Hex,
13
15
  numberToBytesLE,
14
16
  } from './abstract/utils.js';
15
- import { createHasher, htfBasicOpts, expand_message_xmd } from './abstract/hash-to-curve.js';
16
- import { AffinePoint, Group } from './abstract/curve.js';
17
17
 
18
18
  /**
19
19
  * ed25519 Twisted Edwards curve with following addons:
@@ -26,16 +26,18 @@ const ED25519_P = BigInt(
26
26
  '57896044618658097711785492504343953926634992332820282019728792003956564819949'
27
27
  );
28
28
  // √(-1) aka √(a) aka 2^((p-1)/4)
29
- const ED25519_SQRT_M1 = BigInt(
29
+ const ED25519_SQRT_M1 = /* @__PURE__ */ BigInt(
30
30
  '19681161376707505956807079304988542015446066515923890162744021073123829784752'
31
31
  );
32
32
 
33
33
  // prettier-ignore
34
- const _0n = BigInt(0), _1n = BigInt(1), _2n = BigInt(2), _5n = BigInt(5);
34
+ const _0n = BigInt(0), _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3);
35
35
  // prettier-ignore
36
- const _10n = BigInt(10), _20n = BigInt(20), _40n = BigInt(40), _80n = BigInt(80);
36
+ const _5n = BigInt(5), _8n = BigInt(8);
37
37
 
38
38
  function ed25519_pow_2_252_3(x: bigint) {
39
+ // prettier-ignore
40
+ const _10n = BigInt(10), _20n = BigInt(20), _40n = BigInt(40), _80n = BigInt(80);
39
41
  const P = ED25519_P;
40
42
  const x2 = (x * x) % P;
41
43
  const b2 = (x2 * x) % P; // x^3, 11
@@ -96,34 +98,35 @@ export const ED25519_TORSION_SUBGROUP = [
96
98
  'c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa',
97
99
  ];
98
100
 
99
- const Fp = Field(ED25519_P, undefined, true);
100
-
101
- const ed25519Defaults = {
102
- // Param: a
103
- a: BigInt(-1), // Fp.create(-1) is proper; our way still works and is faster
104
- // d is equal to -121665/121666 over finite field.
105
- // Negative number is P - number, and division is invert(number, P)
106
- d: BigInt('37095705934669439343138083508754565189542113879843219016388785533085940283555'),
107
- // Finite field 𝔽p over which we'll do calculations; 2n**255n - 19n
108
- Fp,
109
- // Subgroup order: how many points curve has
110
- // 2n**252n + 27742317777372353535851937790883648493n;
111
- n: BigInt('7237005577332262213973186563042994240857116359379907606001950938285454250989'),
112
- // Cofactor
113
- h: BigInt(8),
114
- // Base point (x, y) aka generator point
115
- Gx: BigInt('15112221349535400772501151409588531511454012693041857206046113283949847762202'),
116
- Gy: BigInt('46316835694926478169428394003475163141307993866256225615783033603165251855960'),
117
- hash: sha512,
118
- randomBytes,
119
- adjustScalarBytes,
120
- // dom2
121
- // Ratio of u to v. Allows us to combine inversion and square root. Uses algo from RFC8032 5.1.3.
122
- // Constant-time, u/√v
123
- uvRatio,
124
- } as const;
125
-
126
- export const ed25519 = /* @__PURE__ */ twistedEdwards(ed25519Defaults);
101
+ const Fp = /* @__PURE__ */ (() => Field(ED25519_P, undefined, true))();
102
+
103
+ const ed25519Defaults = /* @__PURE__ */ (() =>
104
+ ({
105
+ // Param: a
106
+ a: BigInt(-1), // Fp.create(-1) is proper; our way still works and is faster
107
+ // d is equal to -121665/121666 over finite field.
108
+ // Negative number is P - number, and division is invert(number, P)
109
+ d: BigInt('37095705934669439343138083508754565189542113879843219016388785533085940283555'),
110
+ // Finite field 𝔽p over which we'll do calculations; 2n**255n - 19n
111
+ Fp,
112
+ // Subgroup order: how many points curve has
113
+ // 2n**252n + 27742317777372353535851937790883648493n;
114
+ n: BigInt('7237005577332262213973186563042994240857116359379907606001950938285454250989'),
115
+ // Cofactor
116
+ h: _8n,
117
+ // Base point (x, y) aka generator point
118
+ Gx: BigInt('15112221349535400772501151409588531511454012693041857206046113283949847762202'),
119
+ Gy: BigInt('46316835694926478169428394003475163141307993866256225615783033603165251855960'),
120
+ hash: sha512,
121
+ randomBytes,
122
+ adjustScalarBytes,
123
+ // dom2
124
+ // Ratio of u to v. Allows us to combine inversion and square root. Uses algo from RFC8032 5.1.3.
125
+ // Constant-time, u/√v
126
+ uvRatio,
127
+ }) as const)();
128
+
129
+ export const ed25519 = /* @__PURE__ */ (() => twistedEdwards(ed25519Defaults))();
127
130
 
128
131
  function ed25519_domain(data: Uint8Array, ctx: Uint8Array, phflag: boolean) {
129
132
  if (ctx.length > 255) throw new Error('Context is too big');
@@ -135,15 +138,18 @@ function ed25519_domain(data: Uint8Array, ctx: Uint8Array, phflag: boolean) {
135
138
  );
136
139
  }
137
140
 
138
- export const ed25519ctx = /* @__PURE__ */ twistedEdwards({
139
- ...ed25519Defaults,
140
- domain: ed25519_domain,
141
- });
142
- export const ed25519ph = /* @__PURE__ */ twistedEdwards({
143
- ...ed25519Defaults,
144
- domain: ed25519_domain,
145
- prehash: sha512,
146
- });
141
+ export const ed25519ctx = /* @__PURE__ */ (() =>
142
+ twistedEdwards({
143
+ ...ed25519Defaults,
144
+ domain: ed25519_domain,
145
+ }))();
146
+ export const ed25519ph = /* @__PURE__ */ (() =>
147
+ twistedEdwards(
148
+ Object.assign({}, ed25519Defaults, {
149
+ domain: ed25519_domain,
150
+ prehash: sha512,
151
+ })
152
+ ))();
147
153
 
148
154
  export const x25519 = /* @__PURE__ */ (() =>
149
155
  montgomery({
@@ -156,7 +162,7 @@ export const x25519 = /* @__PURE__ */ (() =>
156
162
  const P = ED25519_P;
157
163
  // x^(p-2) aka x^(2^255-21)
158
164
  const { pow_p_5_8, b2 } = ed25519_pow_2_252_3(x);
159
- return mod(pow2(pow_p_5_8, BigInt(3), P) * b2, P);
165
+ return mod(pow2(pow_p_5_8, _3n, P) * b2, P);
160
166
  },
161
167
  adjustScalarBytes,
162
168
  randomBytes,
@@ -194,49 +200,49 @@ export function edwardsToMontgomeryPriv(edwardsPriv: Uint8Array): Uint8Array {
194
200
  // NOTE: very important part is usage of FpSqrtEven for ELL2_C1_EDWARDS, since
195
201
  // SageMath returns different root first and everything falls apart
196
202
 
197
- const ELL2_C1 = (Fp.ORDER + BigInt(3)) / BigInt(8); // 1. c1 = (q + 3) / 8 # Integer arithmetic
198
-
199
- const ELL2_C2 = Fp.pow(_2n, ELL2_C1); // 2. c2 = 2^c1
200
- const ELL2_C3 = Fp.sqrt(Fp.neg(Fp.ONE)); // 3. c3 = sqrt(-1)
201
- const ELL2_C4 = (Fp.ORDER - BigInt(5)) / BigInt(8); // 4. c4 = (q - 5) / 8 # Integer arithmetic
202
- const ELL2_J = BigInt(486662);
203
+ const ELL2_C1 = /* @__PURE__ */ (() => (Fp.ORDER + _3n) / _8n)(); // 1. c1 = (q + 3) / 8 # Integer arithmetic
204
+ const ELL2_C2 = /* @__PURE__ */ (() => Fp.pow(_2n, ELL2_C1))(); // 2. c2 = 2^c1
205
+ const ELL2_C3 = /* @__PURE__ */ (() => Fp.sqrt(Fp.neg(Fp.ONE)))(); // 3. c3 = sqrt(-1)
203
206
 
204
207
  // prettier-ignore
205
208
  function map_to_curve_elligator2_curve25519(u: bigint) {
206
- let tv1 = Fp.sqr(u); // 1. tv1 = u^2
209
+ const ELL2_C4 = (Fp.ORDER - _5n) / _8n; // 4. c4 = (q - 5) / 8 # Integer arithmetic
210
+ const ELL2_J = BigInt(486662);
211
+
212
+ let tv1 = Fp.sqr(u); // 1. tv1 = u^2
207
213
  tv1 = Fp.mul(tv1, _2n); // 2. tv1 = 2 * tv1
208
214
  let xd = Fp.add(tv1, Fp.ONE); // 3. xd = tv1 + 1 # Nonzero: -1 is square (mod p), tv1 is not
209
- let x1n = Fp.neg(ELL2_J); // 4. x1n = -J # x1 = x1n / xd = -J / (1 + 2 * u^2)
210
- let tv2 = Fp.sqr(xd); // 5. tv2 = xd^2
215
+ let x1n = Fp.neg(ELL2_J); // 4. x1n = -J # x1 = x1n / xd = -J / (1 + 2 * u^2)
216
+ let tv2 = Fp.sqr(xd); // 5. tv2 = xd^2
211
217
  let gxd = Fp.mul(tv2, xd); // 6. gxd = tv2 * xd # gxd = xd^3
212
- let gx1 = Fp.mul(tv1, ELL2_J); // 7. gx1 = J * tv1 # x1n + J * xd
218
+ let gx1 = Fp.mul(tv1, ELL2_J);// 7. gx1 = J * tv1 # x1n + J * xd
213
219
  gx1 = Fp.mul(gx1, x1n); // 8. gx1 = gx1 * x1n # x1n^2 + J * x1n * xd
214
220
  gx1 = Fp.add(gx1, tv2); // 9. gx1 = gx1 + tv2 # x1n^2 + J * x1n * xd + xd^2
215
221
  gx1 = Fp.mul(gx1, x1n); // 10. gx1 = gx1 * x1n # x1n^3 + J * x1n^2 * xd + x1n * xd^2
216
- let tv3 = Fp.sqr(gxd); // 11. tv3 = gxd^2
217
- tv2 = Fp.sqr(tv3); // 12. tv2 = tv3^2 # gxd^4
222
+ let tv3 = Fp.sqr(gxd); // 11. tv3 = gxd^2
223
+ tv2 = Fp.sqr(tv3); // 12. tv2 = tv3^2 # gxd^4
218
224
  tv3 = Fp.mul(tv3, gxd); // 13. tv3 = tv3 * gxd # gxd^3
219
225
  tv3 = Fp.mul(tv3, gx1); // 14. tv3 = tv3 * gx1 # gx1 * gxd^3
220
226
  tv2 = Fp.mul(tv2, tv3); // 15. tv2 = tv2 * tv3 # gx1 * gxd^7
221
227
  let y11 = Fp.pow(tv2, ELL2_C4); // 16. y11 = tv2^c4 # (gx1 * gxd^7)^((p - 5) / 8)
222
228
  y11 = Fp.mul(y11, tv3); // 17. y11 = y11 * tv3 # gx1*gxd^3*(gx1*gxd^7)^((p-5)/8)
223
229
  let y12 = Fp.mul(y11, ELL2_C3); // 18. y12 = y11 * c3
224
- tv2 = Fp.sqr(y11); // 19. tv2 = y11^2
230
+ tv2 = Fp.sqr(y11); // 19. tv2 = y11^2
225
231
  tv2 = Fp.mul(tv2, gxd); // 20. tv2 = tv2 * gxd
226
- let e1 = Fp.eql(tv2, gx1); // 21. e1 = tv2 == gx1
232
+ let e1 = Fp.eql(tv2, gx1); // 21. e1 = tv2 == gx1
227
233
  let y1 = Fp.cmov(y12, y11, e1); // 22. y1 = CMOV(y12, y11, e1) # If g(x1) is square, this is its sqrt
228
234
  let x2n = Fp.mul(x1n, tv1); // 23. x2n = x1n * tv1 # x2 = x2n / xd = 2 * u^2 * x1n / xd
229
235
  let y21 = Fp.mul(y11, u); // 24. y21 = y11 * u
230
236
  y21 = Fp.mul(y21, ELL2_C2); // 25. y21 = y21 * c2
231
237
  let y22 = Fp.mul(y21, ELL2_C3); // 26. y22 = y21 * c3
232
238
  let gx2 = Fp.mul(gx1, tv1); // 27. gx2 = gx1 * tv1 # g(x2) = gx2 / gxd = 2 * u^2 * g(x1)
233
- tv2 = Fp.sqr(y21); // 28. tv2 = y21^2
239
+ tv2 = Fp.sqr(y21); // 28. tv2 = y21^2
234
240
  tv2 = Fp.mul(tv2, gxd); // 29. tv2 = tv2 * gxd
235
- let e2 = Fp.eql(tv2, gx2); // 30. e2 = tv2 == gx2
241
+ let e2 = Fp.eql(tv2, gx2); // 30. e2 = tv2 == gx2
236
242
  let y2 = Fp.cmov(y22, y21, e2); // 31. y2 = CMOV(y22, y21, e2) # If g(x2) is square, this is its sqrt
237
- tv2 = Fp.sqr(y1); // 32. tv2 = y1^2
243
+ tv2 = Fp.sqr(y1); // 32. tv2 = y1^2
238
244
  tv2 = Fp.mul(tv2, gxd); // 33. tv2 = tv2 * gxd
239
- let e3 = Fp.eql(tv2, gx1); // 34. e3 = tv2 == gx1
245
+ let e3 = Fp.eql(tv2, gx1); // 34. e3 = tv2 == gx1
240
246
  let xn = Fp.cmov(x2n, x1n, e3); // 35. xn = CMOV(x2n, x1n, e3) # If e3, x = x1, else x = x2
241
247
  let y = Fp.cmov(y2, y1, e3); // 36. y = CMOV(y2, y1, e3) # If e3, y = y1, else y = y2
242
248
  let e4 = Fp.isOdd(y); // 37. e4 = sgn0(y) == 1 # Fix sign of y
@@ -244,7 +250,7 @@ function map_to_curve_elligator2_curve25519(u: bigint) {
244
250
  return { xMn: xn, xMd: xd, yMn: y, yMd: _1n }; // 39. return (xn, xd, y, 1)
245
251
  }
246
252
 
247
- const ELL2_C1_EDWARDS = FpSqrtEven(Fp, Fp.neg(BigInt(486664))); // sgn0(c1) MUST equal 0
253
+ const ELL2_C1_EDWARDS = /* @__PURE__ */ (() => FpSqrtEven(Fp, Fp.neg(BigInt(486664))))(); // sgn0(c1) MUST equal 0
248
254
  function map_to_curve_elligator2_edwards25519(u: bigint) {
249
255
  const { xMn, xMd, yMn, yMd } = map_to_curve_elligator2_curve25519(u); // 1. (xMn, xMd, yMn, yMd) =
250
256
  // map_to_curve_elligator2_curve25519(u)
@@ -288,25 +294,27 @@ function assertRstPoint(other: unknown) {
288
294
  // √(-1) aka √(a) aka 2^((p-1)/4)
289
295
  const SQRT_M1 = ED25519_SQRT_M1;
290
296
  // √(ad - 1)
291
- const SQRT_AD_MINUS_ONE = BigInt(
297
+ const SQRT_AD_MINUS_ONE = /* @__PURE__ */ BigInt(
292
298
  '25063068953384623474111414158702152701244531502492656460079210482610430750235'
293
299
  );
294
300
  // 1 / √(a-d)
295
- const INVSQRT_A_MINUS_D = BigInt(
301
+ const INVSQRT_A_MINUS_D = /* @__PURE__ */ BigInt(
296
302
  '54469307008909316920995813868745141605393597292927456921205312896311721017578'
297
303
  );
298
304
  // 1-d²
299
- const ONE_MINUS_D_SQ = BigInt(
305
+ const ONE_MINUS_D_SQ = /* @__PURE__ */ BigInt(
300
306
  '1159843021668779879193775521855586647937357759715417654439879720876111806838'
301
307
  );
302
308
  // (d-1)²
303
- const D_MINUS_ONE_SQ = BigInt(
309
+ const D_MINUS_ONE_SQ = /* @__PURE__ */ BigInt(
304
310
  '40440834346308536858101042469323190826248399146238708352240133220865137265952'
305
311
  );
306
312
  // Calculates 1/√(number)
307
313
  const invertSqrt = (number: bigint) => uvRatio(_1n, number);
308
314
 
309
- const MAX_255B = BigInt('0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
315
+ const MAX_255B = /* @__PURE__ */ BigInt(
316
+ '0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
317
+ );
310
318
  const bytes255ToNumberLE = (bytes: Uint8Array) =>
311
319
  ed25519.CURVE.Fp.create(bytesToNumberLE(bytes) & MAX_255B);
312
320
 
package/src/ed448.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2
2
  import { shake256 } from '@noble/hashes/sha3';
3
3
  import { concatBytes, randomBytes, utf8ToBytes, wrapConstructor } from '@noble/hashes/utils';
4
+ import { AffinePoint, Group } from './abstract/curve.js';
4
5
  import { ExtPointType, twistedEdwards } from './abstract/edwards.js';
5
- import { mod, pow2, Field, isNegativeLE } from './abstract/modular.js';
6
+ import { createHasher, expand_message_xof, htfBasicOpts } from './abstract/hash-to-curve.js';
7
+ import { Field, isNegativeLE, mod, pow2 } from './abstract/modular.js';
6
8
  import { montgomery } from './abstract/montgomery.js';
7
- import { createHasher, htfBasicOpts, expand_message_xof } from './abstract/hash-to-curve.js';
8
9
  import {
9
10
  bytesToHex,
10
11
  bytesToNumberLE,
@@ -13,7 +14,6 @@ import {
13
14
  Hex,
14
15
  numberToBytesLE,
15
16
  } from './abstract/utils.js';
16
- import { AffinePoint, Group } from './abstract/curve.js';
17
17
 
18
18
  /**
19
19
  * Edwards448 (not Ed448-Goldilocks) curve with following addons:
package/src/index.ts CHANGED
@@ -1 +1 @@
1
- throw new Error('Incorrect usage. Import submodules instead');
1
+ throw new Error('root module cannot be imported: import submodules instead. Check out README');
package/src/jubjub.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2
+ import { blake2s } from '@noble/hashes/blake2s';
2
3
  import { sha512 } from '@noble/hashes/sha512';
3
4
  import { concatBytes, randomBytes, utf8ToBytes } from '@noble/hashes/utils';
4
5
  import { twistedEdwards } from './abstract/edwards.js';
5
- import { blake2s } from '@noble/hashes/blake2s';
6
6
  import { Field } from './abstract/modular.js';
7
7
 
8
8
  /**
package/src/p256.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2
- import { createCurve } from './_shortw_utils.js';
3
2
  import { sha256 } from '@noble/hashes/sha256';
3
+ import { createCurve } from './_shortw_utils.js';
4
+ import { createHasher } from './abstract/hash-to-curve.js';
4
5
  import { Field } from './abstract/modular.js';
5
6
  import { mapToCurveSimpleSWU } from './abstract/weierstrass.js';
6
- import { createHasher } from './abstract/hash-to-curve.js';
7
7
 
8
8
  // NIST secp256r1 aka p256
9
9
  // https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-256
package/src/p384.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2
- import { createCurve } from './_shortw_utils.js';
3
2
  import { sha384 } from '@noble/hashes/sha512';
3
+ import { createCurve } from './_shortw_utils.js';
4
+ import { createHasher } from './abstract/hash-to-curve.js';
4
5
  import { Field } from './abstract/modular.js';
5
6
  import { mapToCurveSimpleSWU } from './abstract/weierstrass.js';
6
- import { createHasher } from './abstract/hash-to-curve.js';
7
7
 
8
8
  // NIST secp384r1 aka p384
9
9
  // https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-384
package/src/p521.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2
- import { createCurve } from './_shortw_utils.js';
3
2
  import { sha512 } from '@noble/hashes/sha512';
3
+ import { createCurve } from './_shortw_utils.js';
4
+ import { createHasher } from './abstract/hash-to-curve.js';
4
5
  import { Field } from './abstract/modular.js';
5
6
  import { mapToCurveSimpleSWU } from './abstract/weierstrass.js';
6
- import { createHasher } from './abstract/hash-to-curve.js';
7
7
 
8
8
  // NIST secp521r1 aka p521
9
9
  // Note that it's 521, which differs from 512 of its hash function.
package/src/pasta.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2
2
  import { sha256 } from '@noble/hashes/sha256';
3
- import { weierstrass } from './abstract/weierstrass.js';
4
3
  import { getHash } from './_shortw_utils.js';
5
- import * as mod from './abstract/modular.js';
4
+ import { Field, mod } from './abstract/modular.js';
5
+ import { weierstrass } from './abstract/weierstrass.js';
6
6
 
7
7
  export const p = BigInt('0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001');
8
8
  export const q = BigInt('0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001');
@@ -11,9 +11,9 @@ export const q = BigInt('0x40000000000000000000000000000000224698fc0994a8dd8c46e
11
11
  export const pallas = weierstrass({
12
12
  a: BigInt(0),
13
13
  b: BigInt(5),
14
- Fp: mod.Field(p),
14
+ Fp: Field(p),
15
15
  n: q,
16
- Gx: mod.mod(BigInt(-1), p),
16
+ Gx: mod(BigInt(-1), p),
17
17
  Gy: BigInt(2),
18
18
  h: BigInt(1),
19
19
  ...getHash(sha256),
@@ -22,9 +22,9 @@ export const pallas = weierstrass({
22
22
  export const vesta = weierstrass({
23
23
  a: BigInt(0),
24
24
  b: BigInt(5),
25
- Fp: mod.Field(q),
25
+ Fp: Field(q),
26
26
  n: p,
27
- Gx: mod.mod(BigInt(-1), q),
27
+ Gx: mod(BigInt(-1), q),
28
28
  Gy: BigInt(2),
29
29
  h: BigInt(1),
30
30
  ...getHash(sha256),
package/src/secp256k1.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2
2
  import { sha256 } from '@noble/hashes/sha256';
3
3
  import { randomBytes } from '@noble/hashes/utils';
4
+ import { createCurve } from './_shortw_utils.js';
5
+ import { createHasher, isogenyMap } from './abstract/hash-to-curve.js';
4
6
  import { Field, mod, pow2 } from './abstract/modular.js';
5
- import { ProjPointType as PointType, mapToCurveSimpleSWU } from './abstract/weierstrass.js';
6
7
  import type { Hex, PrivKey } from './abstract/utils.js';
7
8
  import { bytesToNumberBE, concatBytes, ensureBytes, numberToBytesBE } from './abstract/utils.js';
8
- import { createHasher, isogenyMap } from './abstract/hash-to-curve.js';
9
- import { createCurve } from './_shortw_utils.js';
9
+ import { ProjPointType as PointType, mapToCurveSimpleSWU } from './abstract/weierstrass.js';
10
10
 
11
11
  const secp256k1P = BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f');
12
12
  const secp256k1N = BigInt('0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141');