@noble/curves 1.9.5 → 2.0.0-beta.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 (211) hide show
  1. package/README.md +267 -421
  2. package/abstract/bls.d.ts +49 -111
  3. package/abstract/bls.d.ts.map +1 -1
  4. package/abstract/bls.js +108 -152
  5. package/abstract/bls.js.map +1 -1
  6. package/abstract/curve.d.ts +7 -48
  7. package/abstract/curve.d.ts.map +1 -1
  8. package/abstract/curve.js +22 -47
  9. package/abstract/curve.js.map +1 -1
  10. package/abstract/edwards.d.ts +17 -68
  11. package/abstract/edwards.d.ts.map +1 -1
  12. package/abstract/edwards.js +98 -175
  13. package/abstract/edwards.js.map +1 -1
  14. package/abstract/fft.js +14 -27
  15. package/abstract/fft.js.map +1 -1
  16. package/abstract/hash-to-curve.d.ts +11 -24
  17. package/abstract/hash-to-curve.d.ts.map +1 -1
  18. package/abstract/hash-to-curve.js +30 -35
  19. package/abstract/hash-to-curve.js.map +1 -1
  20. package/abstract/modular.d.ts +5 -17
  21. package/abstract/modular.d.ts.map +1 -1
  22. package/abstract/modular.js +166 -167
  23. package/abstract/modular.js.map +1 -1
  24. package/abstract/montgomery.d.ts +4 -9
  25. package/abstract/montgomery.d.ts.map +1 -1
  26. package/abstract/montgomery.js +17 -20
  27. package/abstract/montgomery.js.map +1 -1
  28. package/abstract/oprf.d.ts +282 -0
  29. package/abstract/oprf.d.ts.map +1 -0
  30. package/abstract/oprf.js +297 -0
  31. package/abstract/oprf.js.map +1 -0
  32. package/abstract/poseidon.js +20 -24
  33. package/abstract/poseidon.js.map +1 -1
  34. package/abstract/tower.d.ts +9 -7
  35. package/abstract/tower.d.ts.map +1 -1
  36. package/abstract/tower.js +600 -364
  37. package/abstract/tower.js.map +1 -1
  38. package/abstract/weierstrass.d.ts +12 -145
  39. package/abstract/weierstrass.d.ts.map +1 -1
  40. package/abstract/weierstrass.js +153 -377
  41. package/abstract/weierstrass.js.map +1 -1
  42. package/bls12-381.d.ts +2 -2
  43. package/bls12-381.d.ts.map +1 -1
  44. package/bls12-381.js +174 -216
  45. package/bls12-381.js.map +1 -1
  46. package/bn254.d.ts +58 -10
  47. package/bn254.d.ts.map +1 -1
  48. package/bn254.js +70 -130
  49. package/bn254.js.map +1 -1
  50. package/ed25519.d.ts +12 -31
  51. package/ed25519.d.ts.map +1 -1
  52. package/ed25519.js +104 -146
  53. package/ed25519.js.map +1 -1
  54. package/ed448.d.ts +14 -33
  55. package/ed448.d.ts.map +1 -1
  56. package/ed448.js +105 -132
  57. package/ed448.js.map +1 -1
  58. package/index.js +1 -1
  59. package/misc.d.ts +10 -14
  60. package/misc.d.ts.map +1 -1
  61. package/misc.js +51 -60
  62. package/misc.js.map +1 -1
  63. package/nist.d.ts +11 -14
  64. package/nist.d.ts.map +1 -1
  65. package/nist.js +46 -55
  66. package/nist.js.map +1 -1
  67. package/package.json +9 -224
  68. package/secp256k1.d.ts +7 -23
  69. package/secp256k1.d.ts.map +1 -1
  70. package/secp256k1.js +72 -83
  71. package/secp256k1.js.map +1 -1
  72. package/src/abstract/bls.ts +197 -344
  73. package/src/abstract/curve.ts +10 -83
  74. package/src/abstract/edwards.ts +96 -223
  75. package/src/abstract/hash-to-curve.ts +32 -45
  76. package/src/abstract/modular.ts +144 -130
  77. package/src/abstract/montgomery.ts +21 -22
  78. package/src/abstract/oprf.ts +600 -0
  79. package/src/abstract/tower.ts +627 -382
  80. package/src/abstract/weierstrass.ts +101 -482
  81. package/src/bls12-381.ts +148 -176
  82. package/src/bn254.ts +67 -122
  83. package/src/ed25519.ts +65 -118
  84. package/src/ed448.ts +63 -113
  85. package/src/index.ts +1 -1
  86. package/src/misc.ts +66 -49
  87. package/src/nist.ts +48 -57
  88. package/src/secp256k1.ts +56 -88
  89. package/src/utils.ts +41 -61
  90. package/src/webcrypto.ts +362 -0
  91. package/utils.d.ts +28 -19
  92. package/utils.d.ts.map +1 -1
  93. package/utils.js +45 -121
  94. package/utils.js.map +1 -1
  95. package/webcrypto.d.ts +47 -0
  96. package/webcrypto.d.ts.map +1 -0
  97. package/webcrypto.js +231 -0
  98. package/webcrypto.js.map +1 -0
  99. package/esm/_shortw_utils.d.ts +0 -19
  100. package/esm/_shortw_utils.d.ts.map +0 -1
  101. package/esm/_shortw_utils.js +0 -16
  102. package/esm/_shortw_utils.js.map +0 -1
  103. package/esm/abstract/bls.d.ts +0 -190
  104. package/esm/abstract/bls.d.ts.map +0 -1
  105. package/esm/abstract/bls.js +0 -408
  106. package/esm/abstract/bls.js.map +0 -1
  107. package/esm/abstract/curve.d.ts +0 -231
  108. package/esm/abstract/curve.d.ts.map +0 -1
  109. package/esm/abstract/curve.js +0 -465
  110. package/esm/abstract/curve.js.map +0 -1
  111. package/esm/abstract/edwards.d.ts +0 -237
  112. package/esm/abstract/edwards.d.ts.map +0 -1
  113. package/esm/abstract/edwards.js +0 -632
  114. package/esm/abstract/edwards.js.map +0 -1
  115. package/esm/abstract/fft.d.ts +0 -122
  116. package/esm/abstract/fft.d.ts.map +0 -1
  117. package/esm/abstract/fft.js +0 -425
  118. package/esm/abstract/fft.js.map +0 -1
  119. package/esm/abstract/hash-to-curve.d.ts +0 -102
  120. package/esm/abstract/hash-to-curve.d.ts.map +0 -1
  121. package/esm/abstract/hash-to-curve.js +0 -203
  122. package/esm/abstract/hash-to-curve.js.map +0 -1
  123. package/esm/abstract/modular.d.ts +0 -171
  124. package/esm/abstract/modular.d.ts.map +0 -1
  125. package/esm/abstract/modular.js +0 -530
  126. package/esm/abstract/modular.js.map +0 -1
  127. package/esm/abstract/montgomery.d.ts +0 -30
  128. package/esm/abstract/montgomery.d.ts.map +0 -1
  129. package/esm/abstract/montgomery.js +0 -157
  130. package/esm/abstract/montgomery.js.map +0 -1
  131. package/esm/abstract/poseidon.d.ts +0 -68
  132. package/esm/abstract/poseidon.d.ts.map +0 -1
  133. package/esm/abstract/poseidon.js +0 -296
  134. package/esm/abstract/poseidon.js.map +0 -1
  135. package/esm/abstract/tower.d.ts +0 -93
  136. package/esm/abstract/tower.d.ts.map +0 -1
  137. package/esm/abstract/tower.js +0 -502
  138. package/esm/abstract/tower.js.map +0 -1
  139. package/esm/abstract/utils.d.ts +0 -5
  140. package/esm/abstract/utils.d.ts.map +0 -1
  141. package/esm/abstract/utils.js +0 -7
  142. package/esm/abstract/utils.js.map +0 -1
  143. package/esm/abstract/weierstrass.d.ts +0 -412
  144. package/esm/abstract/weierstrass.d.ts.map +0 -1
  145. package/esm/abstract/weierstrass.js +0 -1428
  146. package/esm/abstract/weierstrass.js.map +0 -1
  147. package/esm/bls12-381.d.ts +0 -16
  148. package/esm/bls12-381.d.ts.map +0 -1
  149. package/esm/bls12-381.js +0 -738
  150. package/esm/bls12-381.js.map +0 -1
  151. package/esm/bn254.d.ts +0 -18
  152. package/esm/bn254.d.ts.map +0 -1
  153. package/esm/bn254.js +0 -246
  154. package/esm/bn254.js.map +0 -1
  155. package/esm/ed25519.d.ts +0 -106
  156. package/esm/ed25519.d.ts.map +0 -1
  157. package/esm/ed25519.js +0 -467
  158. package/esm/ed25519.js.map +0 -1
  159. package/esm/ed448.d.ts +0 -101
  160. package/esm/ed448.d.ts.map +0 -1
  161. package/esm/ed448.js +0 -448
  162. package/esm/ed448.js.map +0 -1
  163. package/esm/index.d.ts +0 -2
  164. package/esm/index.d.ts.map +0 -1
  165. package/esm/index.js +0 -17
  166. package/esm/index.js.map +0 -1
  167. package/esm/jubjub.d.ts +0 -12
  168. package/esm/jubjub.d.ts.map +0 -1
  169. package/esm/jubjub.js +0 -12
  170. package/esm/jubjub.js.map +0 -1
  171. package/esm/misc.d.ts +0 -19
  172. package/esm/misc.d.ts.map +0 -1
  173. package/esm/misc.js +0 -109
  174. package/esm/misc.js.map +0 -1
  175. package/esm/nist.d.ts +0 -21
  176. package/esm/nist.d.ts.map +0 -1
  177. package/esm/nist.js +0 -132
  178. package/esm/nist.js.map +0 -1
  179. package/esm/p256.d.ts +0 -16
  180. package/esm/p256.d.ts.map +0 -1
  181. package/esm/p256.js +0 -16
  182. package/esm/p256.js.map +0 -1
  183. package/esm/p384.d.ts +0 -16
  184. package/esm/p384.d.ts.map +0 -1
  185. package/esm/p384.js +0 -16
  186. package/esm/p384.js.map +0 -1
  187. package/esm/p521.d.ts +0 -16
  188. package/esm/p521.d.ts.map +0 -1
  189. package/esm/p521.js +0 -16
  190. package/esm/p521.js.map +0 -1
  191. package/esm/package.json +0 -4
  192. package/esm/pasta.d.ts +0 -10
  193. package/esm/pasta.d.ts.map +0 -1
  194. package/esm/pasta.js +0 -10
  195. package/esm/pasta.js.map +0 -1
  196. package/esm/secp256k1.d.ts +0 -89
  197. package/esm/secp256k1.d.ts.map +0 -1
  198. package/esm/secp256k1.js +0 -292
  199. package/esm/secp256k1.js.map +0 -1
  200. package/esm/utils.d.ts +0 -110
  201. package/esm/utils.d.ts.map +0 -1
  202. package/esm/utils.js +0 -322
  203. package/esm/utils.js.map +0 -1
  204. package/src/_shortw_utils.ts +0 -21
  205. package/src/abstract/utils.ts +0 -7
  206. package/src/jubjub.ts +0 -12
  207. package/src/p256.ts +0 -15
  208. package/src/p384.ts +0 -15
  209. package/src/p521.ts +0 -15
  210. package/src/package.json +0 -3
  211. package/src/pasta.ts +0 -9
package/src/ed25519.ts CHANGED
@@ -7,14 +7,17 @@
7
7
  */
8
8
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
9
9
  import { sha512 } from '@noble/hashes/sha2.js';
10
- import { abytes, concatBytes, utf8ToBytes } from '@noble/hashes/utils.js';
11
- import { pippenger, type AffinePoint } from './abstract/curve.ts';
10
+ import { abytes, concatBytes, hexToBytes } from '@noble/hashes/utils.js';
11
+ import { type AffinePoint } from './abstract/curve.ts';
12
12
  import {
13
+ eddsa,
14
+ edwards,
13
15
  PrimeEdwardsPoint,
14
- twistedEdwards,
15
- type CurveFn,
16
+ type EdDSA,
17
+ type EdDSAOpts,
16
18
  type EdwardsOpts,
17
19
  type EdwardsPoint,
20
+ type EdwardsPointCons,
18
21
  } from './abstract/edwards.ts';
19
22
  import {
20
23
  _DST_scalar,
@@ -22,11 +25,9 @@ import {
22
25
  expand_message_xmd,
23
26
  type H2CHasher,
24
27
  type H2CHasherBase,
25
- type H2CMethod,
26
28
  type htfBasicOpts,
27
29
  } from './abstract/hash-to-curve.ts';
28
30
  import {
29
- Field,
30
31
  FpInvertBatch,
31
32
  FpSqrtEven,
32
33
  isNegativeLE,
@@ -34,24 +35,23 @@ import {
34
35
  pow2,
35
36
  type IField,
36
37
  } from './abstract/modular.ts';
37
- import { montgomery, type MontgomeryECDH as XCurveFn } from './abstract/montgomery.ts';
38
- import { bytesToNumberLE, ensureBytes, equalBytes, numberToBytesLE, type Hex } from './utils.ts';
38
+ import { montgomery, type MontgomeryECDH } from './abstract/montgomery.ts';
39
+ import { createORPF, type OPRF } from './abstract/oprf.ts';
40
+ import { asciiToBytes, bytesToNumberLE, equalBytes } from './utils.ts';
39
41
 
40
42
  // prettier-ignore
41
- const _0n = BigInt(0), _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3);
43
+ const _0n = /* @__PURE__ */ BigInt(0), _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3);
42
44
  // prettier-ignore
43
45
  const _5n = BigInt(5), _8n = BigInt(8);
44
46
 
45
- // 2n**255n-19n
47
+ // P = 2n**255n - 19n
46
48
  const ed25519_CURVE_p = BigInt(
47
49
  '0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed'
48
50
  );
49
-
50
- // P = 2n**255n - 19n
51
51
  // N = 2n**252n + 27742317777372353535851937790883648493n
52
52
  // a = Fp.create(BigInt(-1))
53
53
  // d = -121665/121666 a.k.a. Fp.neg(121665 * Fp.inv(121666))
54
- const ed25519_CURVE: EdwardsOpts = {
54
+ const ed25519_CURVE: EdwardsOpts = /* @__PURE__ */ (() => ({
55
55
  p: ed25519_CURVE_p,
56
56
  n: BigInt('0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed'),
57
57
  h: _8n,
@@ -59,7 +59,7 @@ const ed25519_CURVE: EdwardsOpts = {
59
59
  d: BigInt('0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3'),
60
60
  Gx: BigInt('0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a'),
61
61
  Gy: BigInt('0x6666666666666666666666666666666666666666666666666666666666666658'),
62
- };
62
+ }))();
63
63
 
64
64
  function ed25519_pow_2_252_3(x: bigint) {
65
65
  // prettier-ignore
@@ -117,19 +117,24 @@ function uvRatio(u: bigint, v: bigint): { isValid: boolean; value: bigint } {
117
117
  return { isValid: useRoot1 || useRoot2, value: x };
118
118
  }
119
119
 
120
- const Fp = /* @__PURE__ */ (() => Field(ed25519_CURVE.p, { isLE: true }))();
121
- const Fn = /* @__PURE__ */ (() => Field(ed25519_CURVE.n, { isLE: true }))();
122
-
123
- const ed25519Defaults = /* @__PURE__ */ (() => ({
124
- ...ed25519_CURVE,
125
- Fp,
126
- hash: sha512,
127
- adjustScalarBytes,
128
- // dom2
129
- // Ratio of u to v. Allows us to combine inversion and square root. Uses algo from RFC8032 5.1.3.
130
- // Constant-time, u/√v
131
- uvRatio,
132
- }))();
120
+ const ed25519_Point = /* @__PURE__ */ edwards(ed25519_CURVE, { uvRatio });
121
+ const Fp = /* @__PURE__ */ (() => ed25519_Point.Fp)();
122
+ const Fn = /* @__PURE__ */ (() => ed25519_Point.Fn)();
123
+
124
+ const ed25519_eddsa_opts = { adjustScalarBytes };
125
+ function ed25519_domain(data: Uint8Array, ctx: Uint8Array, phflag: boolean) {
126
+ if (ctx.length > 255) throw new Error('Context is too big');
127
+ return concatBytes(
128
+ asciiToBytes('SigEd25519 no Ed25519 collisions'),
129
+ new Uint8Array([phflag ? 1 : 0, ctx.length]),
130
+ ctx,
131
+ data
132
+ );
133
+ }
134
+
135
+ function _ed(opts: EdDSAOpts) {
136
+ return eddsa(ed25519_Point, sha512, Object.assign({}, ed25519_eddsa_opts, opts));
137
+ }
133
138
 
134
139
  /**
135
140
  * ed25519 curve with EdDSA signatures.
@@ -141,33 +146,11 @@ const ed25519Defaults = /* @__PURE__ */ (() => ({
141
146
  * ed25519.verify(sig, msg, pub); // Default mode: follows ZIP215
142
147
  * ed25519.verify(sig, msg, pub, { zip215: false }); // RFC8032 / FIPS 186-5
143
148
  */
144
- export const ed25519: CurveFn = /* @__PURE__ */ (() => twistedEdwards(ed25519Defaults))();
145
-
146
- function ed25519_domain(data: Uint8Array, ctx: Uint8Array, phflag: boolean) {
147
- if (ctx.length > 255) throw new Error('Context is too big');
148
- return concatBytes(
149
- utf8ToBytes('SigEd25519 no Ed25519 collisions'),
150
- new Uint8Array([phflag ? 1 : 0, ctx.length]),
151
- ctx,
152
- data
153
- );
154
- }
155
-
149
+ export const ed25519: EdDSA = /* @__PURE__ */ _ed({});
156
150
  /** Context of ed25519. Uses context for domain separation. */
157
- export const ed25519ctx: CurveFn = /* @__PURE__ */ (() =>
158
- twistedEdwards({
159
- ...ed25519Defaults,
160
- domain: ed25519_domain,
161
- }))();
162
-
151
+ export const ed25519ctx: EdDSA = /* @__PURE__ */ _ed({ domain: ed25519_domain });
163
152
  /** Prehashed version of ed25519. Accepts already-hashed messages in sign() and verify(). */
164
- export const ed25519ph: CurveFn = /* @__PURE__ */ (() =>
165
- twistedEdwards(
166
- Object.assign({}, ed25519Defaults, {
167
- domain: ed25519_domain,
168
- prehash: sha512,
169
- })
170
- ))();
153
+ export const ed25519ph: EdDSA = /* @__PURE__ */ _ed({ domain: ed25519_domain, prehash: sha512 });
171
154
 
172
155
  /**
173
156
  * ECDH using curve25519 aka x25519.
@@ -179,8 +162,8 @@ export const ed25519ph: CurveFn = /* @__PURE__ */ (() =>
179
162
  * x25519.getPublicKey(priv) === x25519.scalarMultBase(priv);
180
163
  * x25519.getPublicKey(x25519.utils.randomSecretKey());
181
164
  */
182
- export const x25519: XCurveFn = /* @__PURE__ */ (() => {
183
- const P = ed25519.CURVE.Fp.ORDER;
165
+ export const x25519: MontgomeryECDH = /* @__PURE__ */ (() => {
166
+ const P = ed25519_CURVE_p;
184
167
  return montgomery({
185
168
  P,
186
169
  type: 'x25519',
@@ -196,14 +179,13 @@ export const x25519: XCurveFn = /* @__PURE__ */ (() => {
196
179
  // Hash To Curve Elligator2 Map (NOTE: different from ristretto255 elligator)
197
180
  // NOTE: very important part is usage of FpSqrtEven for ELL2_C1_EDWARDS, since
198
181
  // SageMath returns different root first and everything falls apart
199
-
200
- const ELL2_C1 = /* @__PURE__ */ (() => (Fp.ORDER + _3n) / _8n)(); // 1. c1 = (q + 3) / 8 # Integer arithmetic
182
+ const ELL2_C1 = /* @__PURE__ */ (() => (ed25519_CURVE_p + _3n) / _8n)(); // 1. c1 = (q + 3) / 8 # Integer arithmetic
201
183
  const ELL2_C2 = /* @__PURE__ */ (() => Fp.pow(_2n, ELL2_C1))(); // 2. c2 = 2^c1
202
184
  const ELL2_C3 = /* @__PURE__ */ (() => Fp.sqrt(Fp.neg(Fp.ONE)))(); // 3. c3 = sqrt(-1)
203
185
 
204
186
  // prettier-ignore
205
187
  function map_to_curve_elligator2_curve25519(u: bigint) {
206
- const ELL2_C4 = (Fp.ORDER - _5n) / _8n; // 4. c4 = (q - 5) / 8 # Integer arithmetic
188
+ const ELL2_C4 = (ed25519_CURVE_p - _5n) / _8n; // 4. c4 = (q - 5) / 8 # Integer arithmetic
207
189
  const ELL2_J = BigInt(486662);
208
190
 
209
191
  let tv1 = Fp.sqr(u); // 1. tv1 = u^2
@@ -267,14 +249,14 @@ function map_to_curve_elligator2_edwards25519(u: bigint) {
267
249
  }
268
250
 
269
251
  /** Hashing to ed25519 points / field. RFC 9380 methods. */
270
- export const ed25519_hasher: H2CHasher<bigint> = /* @__PURE__ */ (() =>
252
+ export const ed25519_hasher: H2CHasher<EdwardsPointCons> = /* @__PURE__ */ (() =>
271
253
  createHasher(
272
- ed25519.Point,
254
+ ed25519_Point,
273
255
  (scalars: bigint[]) => map_to_curve_elligator2_edwards25519(scalars[0]),
274
256
  {
275
257
  DST: 'edwards25519_XMD:SHA-512_ELL2_RO_',
276
258
  encodeDST: 'edwards25519_XMD:SHA-512_ELL2_NU_',
277
- p: Fp.ORDER,
259
+ p: ed25519_CURVE_p,
278
260
  m: 1,
279
261
  k: 128,
280
262
  expand: 'xmd',
@@ -306,8 +288,7 @@ const invertSqrt = (number: bigint) => uvRatio(_1n, number);
306
288
  const MAX_255B = /* @__PURE__ */ BigInt(
307
289
  '0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
308
290
  );
309
- const bytes255ToNumberLE = (bytes: Uint8Array) =>
310
- ed25519.Point.Fp.create(bytesToNumberLE(bytes) & MAX_255B);
291
+ const bytes255ToNumberLE = (bytes: Uint8Array) => Fp.create(bytesToNumberLE(bytes) & MAX_255B);
311
292
 
312
293
  type ExtendedPoint = EdwardsPoint;
313
294
 
@@ -318,7 +299,7 @@ type ExtendedPoint = EdwardsPoint;
318
299
  */
319
300
  function calcElligatorRistrettoMap(r0: bigint): ExtendedPoint {
320
301
  const { d } = ed25519_CURVE;
321
- const P = Fp.ORDER;
302
+ const P = ed25519_CURVE_p;
322
303
  const mod = (n: bigint) => Fp.create(n);
323
304
  const r = mod(SQRT_M1 * r0 * r0); // 1
324
305
  const Ns = mod((r + _1n) * ONE_MINUS_D_SQ); // 2
@@ -335,7 +316,7 @@ function calcElligatorRistrettoMap(r0: bigint): ExtendedPoint {
335
316
  const W1 = mod(Nt * SQRT_AD_MINUS_ONE); // 11
336
317
  const W2 = mod(_1n - s2); // 12
337
318
  const W3 = mod(_1n + s2); // 13
338
- return new ed25519.Point(mod(W0 * W3), mod(W2 * W1), mod(W1 * W3), mod(W0 * W2));
319
+ return new ed25519_Point(mod(W0 * W3), mod(W2 * W1), mod(W1 * W3), mod(W0 * W2));
339
320
  }
340
321
 
341
322
  function ristretto255_map(bytes: Uint8Array): _RistrettoPoint {
@@ -361,10 +342,10 @@ class _RistrettoPoint extends PrimeEdwardsPoint<_RistrettoPoint> {
361
342
  // because typescript strips comments, which makes bundlers disable tree-shaking.
362
343
  // prettier-ignore
363
344
  static BASE: _RistrettoPoint =
364
- /* @__PURE__ */ (() => new _RistrettoPoint(ed25519.Point.BASE))();
345
+ /* @__PURE__ */ (() => new _RistrettoPoint(ed25519_Point.BASE))();
365
346
  // prettier-ignore
366
347
  static ZERO: _RistrettoPoint =
367
- /* @__PURE__ */ (() => new _RistrettoPoint(ed25519.Point.ZERO))();
348
+ /* @__PURE__ */ (() => new _RistrettoPoint(ed25519_Point.ZERO))();
368
349
  // prettier-ignore
369
350
  static Fp: IField<bigint> =
370
351
  /* @__PURE__ */ (() => Fp)();
@@ -377,7 +358,7 @@ class _RistrettoPoint extends PrimeEdwardsPoint<_RistrettoPoint> {
377
358
  }
378
359
 
379
360
  static fromAffine(ap: AffinePoint<bigint>): _RistrettoPoint {
380
- return new _RistrettoPoint(ed25519.Point.fromAffine(ap));
361
+ return new _RistrettoPoint(ed25519_Point.fromAffine(ap));
381
362
  }
382
363
 
383
364
  protected assertSame(other: _RistrettoPoint): void {
@@ -388,11 +369,6 @@ class _RistrettoPoint extends PrimeEdwardsPoint<_RistrettoPoint> {
388
369
  return new _RistrettoPoint(ep);
389
370
  }
390
371
 
391
- /** @deprecated use `import { ristretto255_hasher } from '@noble/curves/ed25519.js';` */
392
- static hashToCurve(hex: Hex): _RistrettoPoint {
393
- return ristretto255_map(ensureBytes('ristrettoHash', hex, 64));
394
- }
395
-
396
372
  static fromBytes(bytes: Uint8Array): _RistrettoPoint {
397
373
  abytes(bytes, 32);
398
374
  const { a, d } = ed25519_CURVE;
@@ -401,7 +377,7 @@ class _RistrettoPoint extends PrimeEdwardsPoint<_RistrettoPoint> {
401
377
  const s = bytes255ToNumberLE(bytes);
402
378
  // 1. Check that s_bytes is the canonical encoding of a field element, or else abort.
403
379
  // 3. Check that s is non-negative, or else abort
404
- if (!equalBytes(numberToBytesLE(s, 32), bytes) || isNegativeLE(s, P))
380
+ if (!equalBytes(Fp.toBytes(s), bytes) || isNegativeLE(s, P))
405
381
  throw new Error('invalid ristretto255 encoding 1');
406
382
  const s2 = mod(s * s);
407
383
  const u1 = mod(_1n + a * s2); // 4 (a is -1)
@@ -418,7 +394,7 @@ class _RistrettoPoint extends PrimeEdwardsPoint<_RistrettoPoint> {
418
394
  const t = mod(x * y); // 12
419
395
  if (!isValid || isNegativeLE(t, P) || y === _0n)
420
396
  throw new Error('invalid ristretto255 encoding 2');
421
- return new _RistrettoPoint(new ed25519.Point(x, y, _1n, t));
397
+ return new _RistrettoPoint(new ed25519_Point(x, y, _1n, t));
422
398
  }
423
399
 
424
400
  /**
@@ -426,12 +402,8 @@ class _RistrettoPoint extends PrimeEdwardsPoint<_RistrettoPoint> {
426
402
  * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode).
427
403
  * @param hex Ristretto-encoded 32 bytes. Not every 32-byte string is valid ristretto encoding
428
404
  */
429
- static fromHex(hex: Hex): _RistrettoPoint {
430
- return _RistrettoPoint.fromBytes(ensureBytes('ristrettoHex', hex, 32));
431
- }
432
-
433
- static msm(points: _RistrettoPoint[], scalars: bigint[]): _RistrettoPoint {
434
- return pippenger(_RistrettoPoint, ed25519.Point.Fn, points, scalars);
405
+ static fromHex(hex: string): _RistrettoPoint {
406
+ return _RistrettoPoint.fromBytes(hexToBytes(hex));
435
407
  }
436
408
 
437
409
  /**
@@ -463,7 +435,7 @@ class _RistrettoPoint extends PrimeEdwardsPoint<_RistrettoPoint> {
463
435
  if (isNegativeLE(X * zInv, P)) Y = mod(-Y); // 9
464
436
  let s = mod((Z - Y) * D); // 10 (check footer's note, no sqrt(-a))
465
437
  if (isNegativeLE(s, P)) s = mod(-s);
466
- return numberToBytesLE(s, 32); // 11
438
+ return Fp.toBytes(s); // 11
467
439
  }
468
440
 
469
441
  /**
@@ -491,24 +463,26 @@ export const ristretto255: {
491
463
  } = { Point: _RistrettoPoint };
492
464
 
493
465
  /** Hashing to ristretto255 points / field. RFC 9380 methods. */
494
- export const ristretto255_hasher: H2CHasherBase<bigint> = {
466
+ export const ristretto255_hasher: H2CHasherBase<_RistrettoPoint> = {
495
467
  hashToCurve(msg: Uint8Array, options?: htfBasicOpts): _RistrettoPoint {
496
468
  const DST = options?.DST || 'ristretto255_XMD:SHA-512_R255MAP_RO_';
497
- return ristretto255_map(expand_message_xmd(msg, DST, 64, sha512));
469
+ const xmd = expand_message_xmd(msg, DST, 64, sha512);
470
+ return ristretto255_map(xmd);
498
471
  },
499
472
  hashToScalar(msg: Uint8Array, options: htfBasicOpts = { DST: _DST_scalar }) {
500
473
  const xmd = expand_message_xmd(msg, options.DST, 64, sha512);
501
- return ristretto255.Point.Fn.create(bytesToNumberLE(xmd));
474
+ return Fn.create(bytesToNumberLE(xmd));
502
475
  },
503
476
  };
504
477
 
505
- // export const ristretto255_oprf: OPRF = createORPF({
506
- // name: 'ristretto255-SHA512',
507
- // Point: RistrettoPoint,
508
- // hash: sha512,
509
- // hashToGroup: ristretto255_hasher.hashToCurve,
510
- // hashToScalar: ristretto255_hasher.hashToScalar,
511
- // });
478
+ export const ristretto255_oprf: OPRF = /* @__PURE__ */ (() =>
479
+ createORPF({
480
+ name: 'ristretto255-SHA512',
481
+ Point: _RistrettoPoint,
482
+ hash: sha512,
483
+ hashToGroup: ristretto255_hasher.hashToCurve,
484
+ hashToScalar: ristretto255_hasher.hashToScalar,
485
+ }))();
512
486
 
513
487
  /**
514
488
  * Weird / bogus points, useful for debugging.
@@ -526,30 +500,3 @@ export const ED25519_TORSION_SUBGROUP: string[] = [
526
500
  '0000000000000000000000000000000000000000000000000000000000000000',
527
501
  'c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa',
528
502
  ];
529
-
530
- /** @deprecated use `ed25519.utils.toMontgomery` */
531
- export function edwardsToMontgomeryPub(edwardsPub: Hex): Uint8Array {
532
- return ed25519.utils.toMontgomery(ensureBytes('pub', edwardsPub));
533
- }
534
- /** @deprecated use `ed25519.utils.toMontgomery` */
535
- export const edwardsToMontgomery: typeof edwardsToMontgomeryPub = edwardsToMontgomeryPub;
536
-
537
- /** @deprecated use `ed25519.utils.toMontgomeryPriv` */
538
- export function edwardsToMontgomeryPriv(edwardsPriv: Uint8Array): Uint8Array {
539
- return ed25519.utils.toMontgomeryPriv(ensureBytes('pub', edwardsPriv));
540
- }
541
-
542
- /** @deprecated use `ristretto255.Point` */
543
- export const RistrettoPoint: typeof _RistrettoPoint = _RistrettoPoint;
544
- /** @deprecated use `import { ed25519_hasher } from '@noble/curves/ed25519.js';` */
545
- export const hashToCurve: H2CMethod<bigint> = /* @__PURE__ */ (() => ed25519_hasher.hashToCurve)();
546
- /** @deprecated use `import { ed25519_hasher } from '@noble/curves/ed25519.js';` */
547
- export const encodeToCurve: H2CMethod<bigint> = /* @__PURE__ */ (() =>
548
- ed25519_hasher.encodeToCurve)();
549
- type RistHasher = (msg: Uint8Array, options: htfBasicOpts) => _RistrettoPoint;
550
- /** @deprecated use `import { ristretto255_hasher } from '@noble/curves/ed25519.js';` */
551
- export const hashToRistretto255: RistHasher = /* @__PURE__ */ (() =>
552
- ristretto255_hasher.hashToCurve as RistHasher)();
553
- /** @deprecated use `import { ristretto255_hasher } from '@noble/curves/ed25519.js';` */
554
- export const hash_to_ristretto255: RistHasher = /* @__PURE__ */ (() =>
555
- ristretto255_hasher.hashToCurve as RistHasher)();