@noble/curves 1.9.7 → 2.0.0-beta.2

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 (242) hide show
  1. package/README.md +520 -505
  2. package/abstract/bls.d.ts +58 -120
  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 +18 -54
  7. package/abstract/curve.d.ts.map +1 -1
  8. package/abstract/curve.js +30 -49
  9. package/abstract/curve.js.map +1 -1
  10. package/abstract/edwards.d.ts +18 -77
  11. package/abstract/edwards.d.ts.map +1 -1
  12. package/abstract/edwards.js +68 -144
  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 +35 -47
  17. package/abstract/hash-to-curve.d.ts.map +1 -1
  18. package/abstract/hash-to-curve.js +42 -46
  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 +170 -169
  23. package/abstract/modular.js.map +1 -1
  24. package/abstract/montgomery.d.ts +7 -12
  25. package/abstract/montgomery.d.ts.map +1 -1
  26. package/abstract/montgomery.js +22 -29
  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.d.ts.map +1 -1
  33. package/abstract/poseidon.js +26 -31
  34. package/abstract/poseidon.js.map +1 -1
  35. package/abstract/tower.d.ts.map +1 -1
  36. package/abstract/tower.js +43 -19
  37. package/abstract/tower.js.map +1 -1
  38. package/abstract/weierstrass.d.ts +77 -168
  39. package/abstract/weierstrass.d.ts.map +1 -1
  40. package/abstract/weierstrass.js +184 -389
  41. package/abstract/weierstrass.js.map +1 -1
  42. package/bls12-381.d.ts +5 -11
  43. package/bls12-381.d.ts.map +1 -1
  44. package/bls12-381.js +161 -181
  45. package/bls12-381.js.map +1 -1
  46. package/bn254.d.ts +59 -11
  47. package/bn254.d.ts.map +1 -1
  48. package/bn254.js +69 -97
  49. package/bn254.js.map +1 -1
  50. package/ed25519.d.ts +33 -48
  51. package/ed25519.d.ts.map +1 -1
  52. package/ed25519.js +147 -161
  53. package/ed25519.js.map +1 -1
  54. package/ed448.d.ts +27 -36
  55. package/ed448.d.ts.map +1 -1
  56. package/ed448.js +143 -164
  57. package/ed448.js.map +1 -1
  58. package/index.d.ts +1 -0
  59. package/index.js +20 -4
  60. package/index.js.map +1 -1
  61. package/misc.d.ts +10 -14
  62. package/misc.d.ts.map +1 -1
  63. package/misc.js +53 -62
  64. package/misc.js.map +1 -1
  65. package/nist.d.ts +31 -16
  66. package/nist.d.ts.map +1 -1
  67. package/nist.js +75 -64
  68. package/nist.js.map +1 -1
  69. package/package.json +20 -234
  70. package/secp256k1.d.ts +17 -30
  71. package/secp256k1.d.ts.map +1 -1
  72. package/secp256k1.js +59 -73
  73. package/secp256k1.js.map +1 -1
  74. package/src/abstract/bls.ts +207 -354
  75. package/src/abstract/curve.ts +25 -84
  76. package/src/abstract/edwards.ts +68 -193
  77. package/src/abstract/hash-to-curve.ts +71 -85
  78. package/src/abstract/modular.ts +150 -134
  79. package/src/abstract/montgomery.ts +28 -35
  80. package/src/abstract/oprf.ts +600 -0
  81. package/src/abstract/poseidon.ts +6 -8
  82. package/src/abstract/tower.ts +0 -3
  83. package/src/abstract/weierstrass.ts +203 -525
  84. package/src/bls12-381.ts +133 -139
  85. package/src/bn254.ts +69 -93
  86. package/src/ed25519.ts +106 -133
  87. package/src/ed448.ts +111 -138
  88. package/src/index.ts +19 -3
  89. package/src/misc.ts +68 -51
  90. package/src/nist.ts +77 -70
  91. package/src/secp256k1.ts +46 -81
  92. package/src/utils.ts +67 -137
  93. package/src/webcrypto.ts +403 -0
  94. package/utils.d.ts +31 -38
  95. package/utils.d.ts.map +1 -1
  96. package/utils.js +66 -185
  97. package/utils.js.map +1 -1
  98. package/webcrypto.d.ts +99 -0
  99. package/webcrypto.d.ts.map +1 -0
  100. package/webcrypto.js +256 -0
  101. package/webcrypto.js.map +1 -0
  102. package/_shortw_utils.d.ts +0 -19
  103. package/_shortw_utils.d.ts.map +0 -1
  104. package/_shortw_utils.js +0 -20
  105. package/_shortw_utils.js.map +0 -1
  106. package/abstract/utils.d.ts +0 -78
  107. package/abstract/utils.d.ts.map +0 -1
  108. package/abstract/utils.js +0 -73
  109. package/abstract/utils.js.map +0 -1
  110. package/esm/_shortw_utils.d.ts +0 -19
  111. package/esm/_shortw_utils.d.ts.map +0 -1
  112. package/esm/_shortw_utils.js +0 -16
  113. package/esm/_shortw_utils.js.map +0 -1
  114. package/esm/abstract/bls.d.ts +0 -190
  115. package/esm/abstract/bls.d.ts.map +0 -1
  116. package/esm/abstract/bls.js +0 -408
  117. package/esm/abstract/bls.js.map +0 -1
  118. package/esm/abstract/curve.d.ts +0 -231
  119. package/esm/abstract/curve.d.ts.map +0 -1
  120. package/esm/abstract/curve.js +0 -465
  121. package/esm/abstract/curve.js.map +0 -1
  122. package/esm/abstract/edwards.d.ts +0 -243
  123. package/esm/abstract/edwards.d.ts.map +0 -1
  124. package/esm/abstract/edwards.js +0 -627
  125. package/esm/abstract/edwards.js.map +0 -1
  126. package/esm/abstract/fft.d.ts +0 -122
  127. package/esm/abstract/fft.d.ts.map +0 -1
  128. package/esm/abstract/fft.js +0 -425
  129. package/esm/abstract/fft.js.map +0 -1
  130. package/esm/abstract/hash-to-curve.d.ts +0 -102
  131. package/esm/abstract/hash-to-curve.d.ts.map +0 -1
  132. package/esm/abstract/hash-to-curve.js +0 -203
  133. package/esm/abstract/hash-to-curve.js.map +0 -1
  134. package/esm/abstract/modular.d.ts +0 -171
  135. package/esm/abstract/modular.d.ts.map +0 -1
  136. package/esm/abstract/modular.js +0 -530
  137. package/esm/abstract/modular.js.map +0 -1
  138. package/esm/abstract/montgomery.d.ts +0 -30
  139. package/esm/abstract/montgomery.d.ts.map +0 -1
  140. package/esm/abstract/montgomery.js +0 -157
  141. package/esm/abstract/montgomery.js.map +0 -1
  142. package/esm/abstract/poseidon.d.ts +0 -68
  143. package/esm/abstract/poseidon.d.ts.map +0 -1
  144. package/esm/abstract/poseidon.js +0 -296
  145. package/esm/abstract/poseidon.js.map +0 -1
  146. package/esm/abstract/tower.d.ts +0 -95
  147. package/esm/abstract/tower.d.ts.map +0 -1
  148. package/esm/abstract/tower.js +0 -714
  149. package/esm/abstract/tower.js.map +0 -1
  150. package/esm/abstract/utils.d.ts +0 -78
  151. package/esm/abstract/utils.d.ts.map +0 -1
  152. package/esm/abstract/utils.js +0 -70
  153. package/esm/abstract/utils.js.map +0 -1
  154. package/esm/abstract/weierstrass.d.ts +0 -416
  155. package/esm/abstract/weierstrass.d.ts.map +0 -1
  156. package/esm/abstract/weierstrass.js +0 -1413
  157. package/esm/abstract/weierstrass.js.map +0 -1
  158. package/esm/bls12-381.d.ts +0 -16
  159. package/esm/bls12-381.d.ts.map +0 -1
  160. package/esm/bls12-381.js +0 -705
  161. package/esm/bls12-381.js.map +0 -1
  162. package/esm/bn254.d.ts +0 -18
  163. package/esm/bn254.d.ts.map +0 -1
  164. package/esm/bn254.js +0 -214
  165. package/esm/bn254.js.map +0 -1
  166. package/esm/ed25519.d.ts +0 -106
  167. package/esm/ed25519.d.ts.map +0 -1
  168. package/esm/ed25519.js +0 -467
  169. package/esm/ed25519.js.map +0 -1
  170. package/esm/ed448.d.ts +0 -100
  171. package/esm/ed448.d.ts.map +0 -1
  172. package/esm/ed448.js +0 -459
  173. package/esm/ed448.js.map +0 -1
  174. package/esm/index.d.ts +0 -2
  175. package/esm/index.d.ts.map +0 -1
  176. package/esm/index.js +0 -17
  177. package/esm/index.js.map +0 -1
  178. package/esm/jubjub.d.ts +0 -12
  179. package/esm/jubjub.d.ts.map +0 -1
  180. package/esm/jubjub.js +0 -12
  181. package/esm/jubjub.js.map +0 -1
  182. package/esm/misc.d.ts +0 -19
  183. package/esm/misc.d.ts.map +0 -1
  184. package/esm/misc.js +0 -109
  185. package/esm/misc.js.map +0 -1
  186. package/esm/nist.d.ts +0 -21
  187. package/esm/nist.d.ts.map +0 -1
  188. package/esm/nist.js +0 -132
  189. package/esm/nist.js.map +0 -1
  190. package/esm/p256.d.ts +0 -16
  191. package/esm/p256.d.ts.map +0 -1
  192. package/esm/p256.js +0 -16
  193. package/esm/p256.js.map +0 -1
  194. package/esm/p384.d.ts +0 -16
  195. package/esm/p384.d.ts.map +0 -1
  196. package/esm/p384.js +0 -16
  197. package/esm/p384.js.map +0 -1
  198. package/esm/p521.d.ts +0 -16
  199. package/esm/p521.d.ts.map +0 -1
  200. package/esm/p521.js +0 -16
  201. package/esm/p521.js.map +0 -1
  202. package/esm/package.json +0 -4
  203. package/esm/pasta.d.ts +0 -10
  204. package/esm/pasta.d.ts.map +0 -1
  205. package/esm/pasta.js +0 -10
  206. package/esm/pasta.js.map +0 -1
  207. package/esm/secp256k1.d.ts +0 -89
  208. package/esm/secp256k1.d.ts.map +0 -1
  209. package/esm/secp256k1.js +0 -294
  210. package/esm/secp256k1.js.map +0 -1
  211. package/esm/utils.d.ts +0 -110
  212. package/esm/utils.d.ts.map +0 -1
  213. package/esm/utils.js +0 -322
  214. package/esm/utils.js.map +0 -1
  215. package/jubjub.d.ts +0 -12
  216. package/jubjub.d.ts.map +0 -1
  217. package/jubjub.js +0 -15
  218. package/jubjub.js.map +0 -1
  219. package/p256.d.ts +0 -16
  220. package/p256.d.ts.map +0 -1
  221. package/p256.js +0 -13
  222. package/p256.js.map +0 -1
  223. package/p384.d.ts +0 -16
  224. package/p384.d.ts.map +0 -1
  225. package/p384.js +0 -13
  226. package/p384.js.map +0 -1
  227. package/p521.d.ts +0 -16
  228. package/p521.d.ts.map +0 -1
  229. package/p521.js +0 -13
  230. package/p521.js.map +0 -1
  231. package/pasta.d.ts +0 -10
  232. package/pasta.d.ts.map +0 -1
  233. package/pasta.js +0 -13
  234. package/pasta.js.map +0 -1
  235. package/src/_shortw_utils.ts +0 -21
  236. package/src/abstract/utils.ts +0 -80
  237. package/src/jubjub.ts +0 -12
  238. package/src/p256.ts +0 -15
  239. package/src/p384.ts +0 -15
  240. package/src/p521.ts +0 -15
  241. package/src/package.json +0 -3
  242. package/src/pasta.ts +0 -9
package/src/ed448.ts CHANGED
@@ -8,14 +8,14 @@
8
8
  */
9
9
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
10
10
  import { shake256 } from '@noble/hashes/sha3.js';
11
- import { abytes, concatBytes, createHasher as wrapConstructor } from '@noble/hashes/utils.js';
11
+ import { concatBytes, hexToBytes, createHasher as wrapConstructor } from '@noble/hashes/utils.js';
12
12
  import type { AffinePoint } from './abstract/curve.ts';
13
- import { pippenger } from './abstract/curve.ts';
14
13
  import {
14
+ eddsa,
15
15
  edwards,
16
16
  PrimeEdwardsPoint,
17
- twistedEdwards,
18
- type CurveFn,
17
+ type EdDSA,
18
+ type EdDSAOpts,
19
19
  type EdwardsOpts,
20
20
  type EdwardsPoint,
21
21
  type EdwardsPointCons,
@@ -24,14 +24,14 @@ import {
24
24
  _DST_scalar,
25
25
  createHasher,
26
26
  expand_message_xof,
27
+ type H2CDSTOpts,
27
28
  type H2CHasher,
28
29
  type H2CHasherBase,
29
- type H2CMethod,
30
- type htfBasicOpts,
31
30
  } from './abstract/hash-to-curve.ts';
32
31
  import { Field, FpInvertBatch, isNegativeLE, mod, pow2, type IField } from './abstract/modular.ts';
33
- import { montgomery, type MontgomeryECDH as XCurveFn } from './abstract/montgomery.ts';
34
- import { asciiToBytes, bytesToNumberLE, ensureBytes, equalBytes, type Hex } from './utils.ts';
32
+ import { montgomery, type MontgomeryECDH } from './abstract/montgomery.ts';
33
+ import { createORPF, type OPRF } from './abstract/oprf.ts';
34
+ import { abytes, asciiToBytes, bytesToNumberLE, equalBytes } from './utils.ts';
35
35
 
36
36
  // edwards448 curve
37
37
  // a = 1n
@@ -39,10 +39,11 @@ import { asciiToBytes, bytesToNumberLE, ensureBytes, equalBytes, type Hex } from
39
39
  // Finite field 2n**448n - 2n**224n - 1n
40
40
  // Subgroup order
41
41
  // 2n**446n - 13818066809895115352007386748515426880336692474882178609894547503885n
42
- const ed448_CURVE: EdwardsOpts = {
43
- p: BigInt(
44
- '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
45
- ),
42
+ const ed448_CURVE_p = BigInt(
43
+ '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
44
+ );
45
+ const ed448_CURVE: EdwardsOpts = /* @__PURE__ */ (() => ({
46
+ p: ed448_CURVE_p,
46
47
  n: BigInt(
47
48
  '0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffff7cca23e9c44edb49aed63690216cc2728dc58f552378c292ab5844f3'
48
49
  ),
@@ -57,28 +58,29 @@ const ed448_CURVE: EdwardsOpts = {
57
58
  Gy: BigInt(
58
59
  '0x693f46716eb6bc248876203756c9c7624bea73736ca3984087789c1e05a0c2d73ad3ff1ce67c39c4fdbd132c4ed7c8ad9808795bf230fa14'
59
60
  ),
60
- };
61
+ }))();
61
62
 
62
63
  // E448 NIST curve is identical to edwards448, except for:
63
64
  // d = 39082/39081
64
65
  // Gx = 3/2
65
- const E448_CURVE: EdwardsOpts = Object.assign({}, ed448_CURVE, {
66
- d: BigInt(
67
- '0xd78b4bdc7f0daf19f24f38c29373a2ccad46157242a50f37809b1da3412a12e79ccc9c81264cfe9ad080997058fb61c4243cc32dbaa156b9'
68
- ),
69
- Gx: BigInt(
70
- '0x79a70b2b70400553ae7c9df416c792c61128751ac92969240c25a07d728bdc93e21f7787ed6972249de732f38496cd11698713093e9c04fc'
71
- ),
72
- Gy: BigInt(
73
- '0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff80000000000000000000000000000000000000000000000000000001'
74
- ),
75
- });
66
+ const E448_CURVE: EdwardsOpts = /* @__PURE__ */ (() =>
67
+ Object.assign({}, ed448_CURVE, {
68
+ d: BigInt(
69
+ '0xd78b4bdc7f0daf19f24f38c29373a2ccad46157242a50f37809b1da3412a12e79ccc9c81264cfe9ad080997058fb61c4243cc32dbaa156b9'
70
+ ),
71
+ Gx: BigInt(
72
+ '0x79a70b2b70400553ae7c9df416c792c61128751ac92969240c25a07d728bdc93e21f7787ed6972249de732f38496cd11698713093e9c04fc'
73
+ ),
74
+ Gy: BigInt(
75
+ '0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff80000000000000000000000000000000000000000000000000000001'
76
+ ),
77
+ }))();
76
78
 
77
79
  const shake256_114 = /* @__PURE__ */ wrapConstructor(() => shake256.create({ dkLen: 114 }));
78
80
  const shake256_64 = /* @__PURE__ */ wrapConstructor(() => shake256.create({ dkLen: 64 }));
79
81
 
80
82
  // prettier-ignore
81
- const _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3), _4n = BigInt(4), _11n = BigInt(11);
83
+ const _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3), _4n = /* @__PURE__ */ BigInt(4), _11n = BigInt(11);
82
84
  // prettier-ignore
83
85
  const _22n = BigInt(22), _44n = BigInt(44), _88n = BigInt(88), _223n = BigInt(223);
84
86
 
@@ -86,7 +88,7 @@ const _22n = BigInt(22), _44n = BigInt(44), _88n = BigInt(88), _223n = BigInt(22
86
88
  // Used for efficient square root calculation.
87
89
  // ((P-3)/4).toString(2) would produce bits [223x 1, 0, 222x 1]
88
90
  function ed448_pow_Pminus3div4(x: bigint): bigint {
89
- const P = ed448_CURVE.p;
91
+ const P = ed448_CURVE_p;
90
92
  const b2 = (x * x * x) % P;
91
93
  const b3 = (b2 * b2 * x) % P;
92
94
  const b6 = (pow2(b3, _3n, P) * b3) % P;
@@ -115,7 +117,7 @@ function adjustScalarBytes(bytes: Uint8Array): Uint8Array {
115
117
  // Constant-time ratio of u to v. Allows to combine inversion and square root u/√v.
116
118
  // Uses algo from RFC8032 5.1.3.
117
119
  function uvRatio(u: bigint, v: bigint): { isValid: boolean; value: bigint } {
118
- const P = ed448_CURVE.p;
120
+ const P = ed448_CURVE_p;
119
121
  // https://www.rfc-editor.org/rfc/rfc8032#section-5.2.3
120
122
  // To compute the square root of (u/v), the first step is to compute the
121
123
  // candidate root x = (u/v)^((p+1)/4). This can be done using the
@@ -138,10 +140,10 @@ function uvRatio(u: bigint, v: bigint): { isValid: boolean; value: bigint } {
138
140
  // The value fits in 448 bits, but we use 456-bit (57-byte) elements because of bitflags.
139
141
  // - ed25519 fits in 255 bits, allowing using last 1 byte for specifying bit flag of point negation.
140
142
  // - ed448 fits in 448 bits. We can't use last 1 byte: we can only use a bit 224 in the middle.
141
- const Fp = /* @__PURE__ */ (() => Field(ed448_CURVE.p, { BITS: 456, isLE: true }))();
143
+ const Fp = /* @__PURE__ */ (() => Field(ed448_CURVE_p, { BITS: 456, isLE: true }))();
142
144
  const Fn = /* @__PURE__ */ (() => Field(ed448_CURVE.n, { BITS: 456, isLE: true }))();
143
145
  // decaf448 uses 448-bit (56-byte) keys
144
- const Fp448 = /* @__PURE__ */ (() => Field(ed448_CURVE.p, { BITS: 448, isLE: true }))();
146
+ const Fp448 = /* @__PURE__ */ (() => Field(ed448_CURVE_p, { BITS: 448, isLE: true }))();
145
147
  const Fn448 = /* @__PURE__ */ (() => Field(ed448_CURVE.n, { BITS: 448, isLE: true }))();
146
148
 
147
149
  // SHAKE256(dom4(phflag,context)||x, 114)
@@ -154,53 +156,48 @@ function dom4(data: Uint8Array, ctx: Uint8Array, phflag: boolean) {
154
156
  data
155
157
  );
156
158
  }
157
- // const ed448_eddsa_opts = { adjustScalarBytes, domain: dom4 };
158
- // const ed448_Point = edwards(ed448_CURVE, { Fp, Fn, uvRatio });
159
-
160
- const ED448_DEF = /* @__PURE__ */ (() => ({
161
- ...ed448_CURVE,
162
- Fp,
163
- Fn,
164
- nBitLength: Fn.BITS,
165
- hash: shake256_114,
166
- adjustScalarBytes,
167
- domain: dom4,
168
- uvRatio,
169
- }))();
159
+ const ed448_Point = /* @__PURE__ */ edwards(ed448_CURVE, { Fp, Fn, uvRatio });
160
+
161
+ function ed4(opts: EdDSAOpts) {
162
+ return eddsa(ed448_Point, shake256_114, Object.assign({ adjustScalarBytes, domain: dom4 }, opts));
163
+ }
170
164
 
171
165
  /**
172
166
  * ed448 EdDSA curve and methods.
173
167
  * @example
174
- * import { ed448 } from '@noble/curves/ed448';
168
+ * ```js
169
+ * import { ed448 } from '@noble/curves/ed448.js';
175
170
  * const { secretKey, publicKey } = ed448.keygen();
176
- * const msg = new TextEncoder().encode('hello');
171
+ * // const publicKey = ed448.getPublicKey(secretKey);
172
+ * const msg = new TextEncoder().encode('hello noble');
177
173
  * const sig = ed448.sign(msg, secretKey);
178
174
  * const isValid = ed448.verify(sig, msg, publicKey);
175
+ * ```
179
176
  */
180
- export const ed448: CurveFn = twistedEdwards(ED448_DEF);
177
+ export const ed448: EdDSA = /* @__PURE__ */ ed4({});
181
178
 
182
179
  // There is no ed448ctx, since ed448 supports ctx by default
183
- /** Prehashed version of ed448. Accepts already-hashed messages in sign() and verify(). */
184
- export const ed448ph: CurveFn = /* @__PURE__ */ (() =>
185
- twistedEdwards({
186
- ...ED448_DEF,
187
- prehash: shake256_64,
188
- }))();
189
-
180
+ /** Prehashed version of ed448. See {@link ed448} */
181
+ export const ed448ph: EdDSA = /* @__PURE__ */ ed4({ prehash: shake256_64 });
190
182
  /**
191
- * E448 curve, defined by NIST.
192
- * E448 != edwards448 used in ed448.
183
+ * E448 (NIST) != edwards448 used in ed448.
193
184
  * E448 is birationally equivalent to edwards448.
194
185
  */
195
- export const E448: EdwardsPointCons = edwards(E448_CURVE);
186
+ export const E448: EdwardsPointCons = /* @__PURE__ */ edwards(E448_CURVE);
196
187
 
197
188
  /**
198
189
  * ECDH using curve448 aka x448.
199
- * x448 has 56-byte keys as per RFC 7748, while
200
- * ed448 has 57-byte keys as per RFC 8032.
190
+ *
191
+ * @example
192
+ * ```js
193
+ * import { x448 } from '@noble/curves/ed448.js';
194
+ * const alice = x448.keygen();
195
+ * const bob = x448.keygen();
196
+ * const shared = x448.getSharedSecret(alice.secretKey, bob.publicKey);
197
+ * ```
201
198
  */
202
- export const x448: XCurveFn = /* @__PURE__ */ (() => {
203
- const P = ed448_CURVE.p;
199
+ export const x448: MontgomeryECDH = /* @__PURE__ */ (() => {
200
+ const P = ed448_CURVE_p;
204
201
  return montgomery({
205
202
  P,
206
203
  type: 'x448',
@@ -214,7 +211,7 @@ export const x448: XCurveFn = /* @__PURE__ */ (() => {
214
211
  })();
215
212
 
216
213
  // Hash To Curve Elligator2 Map
217
- const ELL2_C1 = /* @__PURE__ */ (() => (Fp.ORDER - BigInt(3)) / BigInt(4))(); // 1. c1 = (q - 3) / 4 # Integer arithmetic
214
+ const ELL2_C1 = /* @__PURE__ */ (() => (ed448_CURVE_p - BigInt(3)) / BigInt(4))(); // 1. c1 = (q - 3) / 4 # Integer arithmetic
218
215
  const ELL2_J = /* @__PURE__ */ BigInt(156326);
219
216
 
220
217
  function map_to_curve_elligator2_curve448(u: bigint) {
@@ -291,11 +288,11 @@ function map_to_curve_elligator2_edwards448(u: bigint) {
291
288
  }
292
289
 
293
290
  /** Hashing / encoding to ed448 points / field. RFC 9380 methods. */
294
- export const ed448_hasher: H2CHasher<bigint> = /* @__PURE__ */ (() =>
295
- createHasher(ed448.Point, (scalars: bigint[]) => map_to_curve_elligator2_edwards448(scalars[0]), {
291
+ export const ed448_hasher: H2CHasher<EdwardsPointCons> = /* @__PURE__ */ (() =>
292
+ createHasher(ed448_Point, (scalars: bigint[]) => map_to_curve_elligator2_edwards448(scalars[0]), {
296
293
  DST: 'edwards448_XOF:SHAKE256_ELL2_RO_',
297
294
  encodeDST: 'edwards448_XOF:SHAKE256_ELL2_NU_',
298
- p: Fp.ORDER,
295
+ p: ed448_CURVE_p,
299
296
  m: 1,
300
297
  k: 224,
301
298
  expand: 'xof',
@@ -323,9 +320,8 @@ const invertSqrt = (number: bigint) => uvRatio(_1n, number);
323
320
  * and [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-element-derivation-2).
324
321
  */
325
322
  function calcElligatorDecafMap(r0: bigint): EdwardsPoint {
326
- const { d } = ed448_CURVE;
327
- const P = Fp.ORDER;
328
- const mod = (n: bigint) => Fp.create(n);
323
+ const { d, p: P } = ed448_CURVE;
324
+ const mod = (n: bigint) => Fp448.create(n);
329
325
 
330
326
  const r = mod(-(r0 * r0)); // 1
331
327
  const u0 = mod(d * (r - _1n)); // 2
@@ -348,20 +344,7 @@ function calcElligatorDecafMap(r0: bigint): EdwardsPoint {
348
344
  const W1 = mod(s2 + _1n); // 9
349
345
  const W2 = mod(s2 - _1n); // 10
350
346
  const W3 = mod(v_prime * s * (r - _1n) * ONE_MINUS_TWO_D + sgn); // 11
351
- return new ed448.Point(mod(W0 * W3), mod(W2 * W1), mod(W1 * W3), mod(W0 * W2));
352
- }
353
-
354
- function decaf448_map(bytes: Uint8Array): _DecafPoint {
355
- abytes(bytes, 112);
356
- const skipValidation = true;
357
- // Note: Similar to the field element decoding described in
358
- // [RFC7748], and unlike the field element decoding described in
359
- // Section 5.3.1, non-canonical values are accepted.
360
- const r1 = Fp448.create(Fp448.fromBytes(bytes.subarray(0, 56), skipValidation));
361
- const R1 = calcElligatorDecafMap(r1);
362
- const r2 = Fp448.create(Fp448.fromBytes(bytes.subarray(56, 112), skipValidation));
363
- const R2 = calcElligatorDecafMap(r2);
364
- return new _DecafPoint(R1.add(R2));
347
+ return new ed448_Point(mod(W0 * W3), mod(W2 * W1), mod(W1 * W3), mod(W0 * W2));
365
348
  }
366
349
 
367
350
  /**
@@ -375,10 +358,10 @@ class _DecafPoint extends PrimeEdwardsPoint<_DecafPoint> {
375
358
  // The following gymnastics is done because typescript strips comments otherwise
376
359
  // prettier-ignore
377
360
  static BASE: _DecafPoint =
378
- /* @__PURE__ */ (() => new _DecafPoint(ed448.Point.BASE).multiplyUnsafe(_2n))();
361
+ /* @__PURE__ */ (() => new _DecafPoint(ed448_Point.BASE).multiplyUnsafe(_2n))();
379
362
  // prettier-ignore
380
363
  static ZERO: _DecafPoint =
381
- /* @__PURE__ */ (() => new _DecafPoint(ed448.Point.ZERO))();
364
+ /* @__PURE__ */ (() => new _DecafPoint(ed448_Point.ZERO))();
382
365
  // prettier-ignore
383
366
  static Fp: IField<bigint> =
384
367
  /* @__PURE__ */ (() => Fp448)();
@@ -391,7 +374,7 @@ class _DecafPoint extends PrimeEdwardsPoint<_DecafPoint> {
391
374
  }
392
375
 
393
376
  static fromAffine(ap: AffinePoint<bigint>): _DecafPoint {
394
- return new _DecafPoint(ed448.Point.fromAffine(ap));
377
+ return new _DecafPoint(ed448_Point.fromAffine(ap));
395
378
  }
396
379
 
397
380
  protected assertSame(other: _DecafPoint): void {
@@ -402,21 +385,14 @@ class _DecafPoint extends PrimeEdwardsPoint<_DecafPoint> {
402
385
  return new _DecafPoint(ep);
403
386
  }
404
387
 
405
- /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
406
- static hashToCurve(hex: Hex): _DecafPoint {
407
- return decaf448_map(ensureBytes('decafHash', hex, 112));
408
- }
409
-
410
388
  static fromBytes(bytes: Uint8Array): _DecafPoint {
411
389
  abytes(bytes, 56);
412
- const { d } = ed448_CURVE;
413
- const P = Fp.ORDER;
390
+ const { d, p: P } = ed448_CURVE;
414
391
  const mod = (n: bigint) => Fp448.create(n);
415
392
  const s = Fp448.fromBytes(bytes);
416
393
 
417
394
  // 1. Check that s_bytes is the canonical encoding of a field element, or else abort.
418
395
  // 2. Check that s is non-negative, or else abort
419
-
420
396
  if (!equalBytes(Fn448.toBytes(s), bytes) || isNegativeLE(s, P))
421
397
  throw new Error('invalid decaf448 encoding 1');
422
398
 
@@ -435,7 +411,7 @@ class _DecafPoint extends PrimeEdwardsPoint<_DecafPoint> {
435
411
  const t = mod(x * y); // 8
436
412
 
437
413
  if (!isValid) throw new Error('invalid decaf448 encoding 2');
438
- return new _DecafPoint(new ed448.Point(x, y, _1n, t));
414
+ return new _DecafPoint(new ed448_Point(x, y, _1n, t));
439
415
  }
440
416
 
441
417
  /**
@@ -443,13 +419,8 @@ class _DecafPoint extends PrimeEdwardsPoint<_DecafPoint> {
443
419
  * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode-2).
444
420
  * @param hex Decaf-encoded 56 bytes. Not every 56-byte string is valid decaf encoding
445
421
  */
446
- static fromHex(hex: Hex): _DecafPoint {
447
- return _DecafPoint.fromBytes(ensureBytes('decafHex', hex, 56));
448
- }
449
-
450
- /** @deprecated use `import { pippenger } from '@noble/curves/abstract/curve.js';` */
451
- static msm(points: _DecafPoint[], scalars: bigint[]): _DecafPoint {
452
- return pippenger(_DecafPoint, Fn, points, scalars);
422
+ static fromHex(hex: string): _DecafPoint {
423
+ return _DecafPoint.fromBytes(hexToBytes(hex));
453
424
  }
454
425
 
455
426
  /**
@@ -458,8 +429,8 @@ class _DecafPoint extends PrimeEdwardsPoint<_DecafPoint> {
458
429
  */
459
430
  toBytes(): Uint8Array {
460
431
  const { X, Z, T } = this.ep;
461
- const P = Fp.ORDER;
462
- const mod = (n: bigint) => Fp.create(n);
432
+ const P = ed448_CURVE.p;
433
+ const mod = (n: bigint) => Fp448.create(n);
463
434
  const u1 = mod(mod(X + T) * mod(X - T)); // 1
464
435
  const x2 = mod(X * X);
465
436
  const { value: invsqrt } = invertSqrt(mod(u1 * ONE_MINUS_D * x2)); // 2
@@ -480,7 +451,7 @@ class _DecafPoint extends PrimeEdwardsPoint<_DecafPoint> {
480
451
  const { X: X1, Y: Y1 } = this.ep;
481
452
  const { X: X2, Y: Y2 } = other.ep;
482
453
  // (x1 * y2 == y1 * x2)
483
- return Fp.create(X1 * Y2) === Fp.create(Y1 * X2);
454
+ return Fp448.create(X1 * Y2) === Fp448.create(Y1 * X2);
484
455
  }
485
456
 
486
457
  is0(): boolean {
@@ -493,28 +464,52 @@ export const decaf448: {
493
464
  } = { Point: _DecafPoint };
494
465
 
495
466
  /** Hashing to decaf448 points / field. RFC 9380 methods. */
496
- export const decaf448_hasher: H2CHasherBase<bigint> = {
497
- hashToCurve(msg: Uint8Array, options?: htfBasicOpts): _DecafPoint {
467
+ export const decaf448_hasher: H2CHasherBase<typeof _DecafPoint> = {
468
+ Point: _DecafPoint,
469
+ hashToCurve(msg: Uint8Array, options?: H2CDSTOpts): _DecafPoint {
498
470
  const DST = options?.DST || 'decaf448_XOF:SHAKE256_D448MAP_RO_';
499
- return decaf448_map(expand_message_xof(msg, DST, 112, 224, shake256));
471
+ return decaf448_hasher.deriveToCurve!(expand_message_xof(msg, DST, 112, 224, shake256));
500
472
  },
501
- // Warning: has big modulo bias of 2^-64.
502
- // RFC is invalid. RFC says "use 64-byte xof", while for 2^-112 bias
503
- // it must use 84-byte xof (56+56/2), not 64.
504
- hashToScalar(msg: Uint8Array, options: htfBasicOpts = { DST: _DST_scalar }) {
473
+ /**
474
+ * Warning: has big modulo bias of 2^-64.
475
+ * RFC is invalid. RFC says "use 64-byte xof", while for 2^-112 bias
476
+ * it must use 84-byte xof (56+56/2), not 64.
477
+ */
478
+ hashToScalar(msg: Uint8Array, options: H2CDSTOpts = { DST: _DST_scalar }): bigint {
505
479
  // Can't use `Fn448.fromBytes()`. 64-byte input => 56-byte field element
506
480
  const xof = expand_message_xof(msg, options.DST, 64, 256, shake256);
507
481
  return Fn448.create(bytesToNumberLE(xof));
508
482
  },
483
+ /**
484
+ * HashToCurve-like construction based on RFC 9496 (Element Derivation).
485
+ * Converts 112 uniform random bytes into a curve point.
486
+ *
487
+ * WARNING: This represents an older hash-to-curve construction, preceding the finalization of RFC 9380.
488
+ * It was later reused as a component in the newer `hash_to_ristretto255` function defined in RFC 9380.
489
+ */
490
+ deriveToCurve(bytes: Uint8Array): _DecafPoint {
491
+ abytes(bytes, 112);
492
+ const skipValidation = true;
493
+ // Note: Similar to the field element decoding described in
494
+ // [RFC7748], and unlike the field element decoding described in
495
+ // Section 5.3.1, non-canonical values are accepted.
496
+ const r1 = Fp448.create(Fp448.fromBytes(bytes.subarray(0, 56), skipValidation));
497
+ const R1 = calcElligatorDecafMap(r1);
498
+ const r2 = Fp448.create(Fp448.fromBytes(bytes.subarray(56, 112), skipValidation));
499
+ const R2 = calcElligatorDecafMap(r2);
500
+ return new _DecafPoint(R1.add(R2));
501
+ },
509
502
  };
510
503
 
511
- // export const decaf448_oprf: OPRF = createORPF({
512
- // name: 'decaf448-SHAKE256',
513
- // Point: DecafPoint,
514
- // hash: (msg: Uint8Array) => shake256(msg, { dkLen: 64 }),
515
- // hashToGroup: decaf448_hasher.hashToCurve,
516
- // hashToScalar: decaf448_hasher.hashToScalar,
517
- // });
504
+ /** decaf448 OPRF, defined in RFC 9497. */
505
+ export const decaf448_oprf: OPRF = /* @__PURE__ */ (() =>
506
+ createORPF({
507
+ name: 'decaf448-SHAKE256',
508
+ Point: _DecafPoint,
509
+ hash: (msg: Uint8Array) => shake256(msg, { dkLen: 64 }),
510
+ hashToGroup: decaf448_hasher.hashToCurve,
511
+ hashToScalar: decaf448_hasher.hashToScalar,
512
+ }))();
518
513
 
519
514
  /**
520
515
  * Weird / bogus points, useful for debugging.
@@ -528,25 +523,3 @@ export const ED448_TORSION_SUBGROUP: string[] = [
528
523
  '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
529
524
  '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080',
530
525
  ];
531
-
532
- type DcfHasher = (msg: Uint8Array, options: htfBasicOpts) => _DecafPoint;
533
-
534
- /** @deprecated use `decaf448.Point` */
535
- export const DecafPoint: typeof _DecafPoint = _DecafPoint;
536
- /** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
537
- export const hashToCurve: H2CMethod<bigint> = /* @__PURE__ */ (() => ed448_hasher.hashToCurve)();
538
- /** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
539
- export const encodeToCurve: H2CMethod<bigint> = /* @__PURE__ */ (() =>
540
- ed448_hasher.encodeToCurve)();
541
- /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
542
- export const hashToDecaf448: DcfHasher = /* @__PURE__ */ (() =>
543
- decaf448_hasher.hashToCurve as DcfHasher)();
544
- /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
545
- export const hash_to_decaf448: DcfHasher = /* @__PURE__ */ (() =>
546
- decaf448_hasher.hashToCurve as DcfHasher)();
547
- /** @deprecated use `ed448.utils.toMontgomery` */
548
- export function edwardsToMontgomeryPub(edwardsPub: string | Uint8Array): Uint8Array {
549
- return ed448.utils.toMontgomery(ensureBytes('pub', edwardsPub));
550
- }
551
- /** @deprecated use `ed448.utils.toMontgomery` */
552
- export const edwardsToMontgomery: typeof edwardsToMontgomeryPub = edwardsToMontgomeryPub;
package/src/index.ts CHANGED
@@ -4,12 +4,28 @@
4
4
  * @example
5
5
  ```js
6
6
  import { secp256k1, schnorr } from '@noble/curves/secp256k1.js';
7
- import { ed25519, ed25519ph, ed25519ctx, x25519, RistrettoPoint } from '@noble/curves/ed25519.js';
8
- import { ed448, ed448ph, ed448ctx, x448 } from '@noble/curves/ed448.js';
7
+ import { ed25519, ed25519ph, ed25519ctx, x25519, ristretto255 } from '@noble/curves/ed25519.js';
8
+ import { ed448, ed448ph, x448, decaf448 } from '@noble/curves/ed448.js';
9
9
  import { p256, p384, p521 } from '@noble/curves/nist.js';
10
10
  import { bls12_381 } from '@noble/curves/bls12-381.js';
11
11
  import { bn254 } from '@noble/curves/bn254.js';
12
- import { bytesToHex, hexToBytes, concatBytes, utf8ToBytes } from '@noble/curves/abstract/utils.js';
12
+ import { jubjub, babyjubjub, brainpoolP256r1, brainpoolP384r1, brainpoolP512r1 } from '@noble/curves/misc.js';
13
+ import * as webcrypto from '@noble/curves/webcrypto.js';
14
+
15
+ // hash-to-curve
16
+ import { secp256k1_hasher } from '@noble/curves/secp256k1.js';
17
+ import { p256_hasher, p384_hasher, p521_hasher } from '@noble/curves/nist.js';
18
+ import { ristretto255_hasher } from '@noble/curves/ed25519.js';
19
+ import { decaf448_hasher } from '@noble/curves/ed448.js';
20
+
21
+ // OPRFs
22
+ import { p256_oprf, p384_oprf, p521_oprf } from '@noble/curves/nist.js';
23
+ import { ristretto255_oprf } from '@noble/curves/ed25519.js';
24
+ import { decaf448_oprf } from '@noble/curves/ed448.js';
25
+
26
+ // utils
27
+ import { bytesToHex, hexToBytes, concatBytes } from '@noble/curves/abstract/utils.js';
28
+ import { Field } from '@noble/curves/abstract/modular.js';
13
29
  ```
14
30
  */
15
31
  throw new Error('root module cannot be imported: import submodules instead. Check out README');
package/src/misc.ts CHANGED
@@ -6,18 +6,19 @@
6
6
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
7
7
  import { blake256 } from '@noble/hashes/blake1.js';
8
8
  import { blake2s } from '@noble/hashes/blake2.js';
9
- import { sha256, sha512 } from '@noble/hashes/sha2.js';
10
- import { concatBytes, utf8ToBytes } from '@noble/hashes/utils.js';
9
+ import { sha256, sha384, sha512 } from '@noble/hashes/sha2.js';
10
+ import { concatBytes } from '@noble/hashes/utils.js';
11
11
  import {
12
- twistedEdwards,
13
- type CurveFn,
12
+ eddsa,
13
+ edwards,
14
+ type EdDSA,
14
15
  type EdwardsOpts,
15
16
  type EdwardsPoint,
16
17
  } from './abstract/edwards.ts';
17
- import { Field, mod } from './abstract/modular.ts';
18
- import { weierstrass, type CurveFn as WCurveFn } from './abstract/weierstrass.ts';
18
+ import { ecdsa, weierstrass, type ECDSA, type WeierstrassOpts } from './abstract/weierstrass.ts';
19
19
  import { bls12_381_Fr } from './bls12-381.ts';
20
20
  import { bn254_Fr } from './bn254.ts';
21
+ import { asciiToBytes } from './utils.ts';
21
22
 
22
23
  // Jubjub curves have 𝔽p over scalar fields of other curves. They are friendly to ZK proofs.
23
24
  // jubjub Fp = bls n. babyjubjub Fp = bn254 n.
@@ -32,11 +33,7 @@ const jubjub_CURVE: EdwardsOpts = {
32
33
  Gy: BigInt('0x1d523cf1ddab1a1793132e78c866c0c33e26ba5cc220fed7cc3f870e59d292aa'),
33
34
  };
34
35
  /** Curve over scalar field of bls12-381. jubjub Fp = bls n */
35
- export const jubjub: CurveFn = /* @__PURE__ */ twistedEdwards({
36
- ...jubjub_CURVE,
37
- Fp: bls12_381_Fr,
38
- hash: sha512,
39
- });
36
+ export const jubjub: EdDSA = /* @__PURE__ */ eddsa(edwards(jubjub_CURVE), sha512);
40
37
 
41
38
  const babyjubjub_CURVE: EdwardsOpts = {
42
39
  p: bn254_Fr.ORDER,
@@ -48,13 +45,9 @@ const babyjubjub_CURVE: EdwardsOpts = {
48
45
  Gy: BigInt('0xc19139cb84c680a6e14116da06056174a0cfa121e6e5c2450f87d64fc000001'),
49
46
  };
50
47
  /** Curve over scalar field of bn254. babyjubjub Fp = bn254 n */
51
- export const babyjubjub: CurveFn = /* @__PURE__ */ twistedEdwards({
52
- ...babyjubjub_CURVE,
53
- Fp: bn254_Fr,
54
- hash: blake256,
55
- });
48
+ export const babyjubjub: EdDSA = /* @__PURE__ */ eddsa(edwards(babyjubjub_CURVE), blake256);
56
49
 
57
- const jubjub_gh_first_block = utf8ToBytes(
50
+ const jubjub_gh_first_block = asciiToBytes(
58
51
  '096b36a5804bfacef1691e173c366a47ff5ba84a44f26ddd7e8d9f79d5b42df0'
59
52
  );
60
53
 
@@ -63,7 +56,7 @@ export function jubjub_groupHash(tag: Uint8Array, personalization: Uint8Array):
63
56
  const h = blake2s.create({ personalization, dkLen: 32 });
64
57
  h.update(jubjub_gh_first_block);
65
58
  h.update(tag);
66
- // NOTE: returns ExtendedPoint, in case it will be multiplied later
59
+ // NOTE: returns EdwardsPoint, in case it will be multiplied later
67
60
  let p = jubjub.Point.fromBytes(h.digest());
68
61
  // NOTE: cannot replace with isSmallOrder, returns Point*8
69
62
  p = p.multiply(jubjub_CURVE.h);
@@ -73,7 +66,7 @@ export function jubjub_groupHash(tag: Uint8Array, personalization: Uint8Array):
73
66
 
74
67
  // No secret data is leaked here at all.
75
68
  // It operates over public data:
76
- // const G_SPEND = jubjub.findGroupHash(Uint8Array.of(), utf8ToBytes('Item_G_'));
69
+ // const G_SPEND = jubjub.findGroupHash(Uint8Array.of(), asciiToBytes('Item_G_'));
77
70
  export function jubjub_findGroupHash(m: Uint8Array, personalization: Uint8Array): EdwardsPoint {
78
71
  const tag = concatBytes(m, Uint8Array.of(0));
79
72
  const hashes = [];
@@ -87,38 +80,62 @@ export function jubjub_findGroupHash(m: Uint8Array, personalization: Uint8Array)
87
80
  return hashes[0];
88
81
  }
89
82
 
90
- // Pasta curves. See [Spec](https://o1-labs.github.io/proof-systems/specs/pasta.html).
91
-
92
- export const pasta_p: bigint = BigInt(
93
- '0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001'
94
- );
95
- export const pasta_q: bigint = BigInt(
96
- '0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001'
97
- );
83
+ const brainpoolP256r1_CURVE: WeierstrassOpts<bigint> = {
84
+ p: BigInt('0xa9fb57dba1eea9bc3e660a909d838d726e3bf623d52620282013481d1f6e5377'),
85
+ a: BigInt('0x7d5a0975fc2c3057eef67530417affe7fb8055c126dc5c6ce94a4b44f330b5d9'),
86
+ b: BigInt('0x26dc5c6ce94a4b44f330b5d9bbd77cbf958416295cf7e1ce6bccdc18ff8c07b6'),
87
+ n: BigInt('0xa9fb57dba1eea9bc3e660a909d838d718c397aa3b561a6f7901e0e82974856a7'),
88
+ Gx: BigInt('0x8bd2aeb9cb7e57cb2c4b482ffc81b7afb9de27e1e3bd23c23a4453bd9ace3262'),
89
+ Gy: BigInt('0x547ef835c3dac4fd97f8461a14611dc9c27745132ded8e545c1d54c72f046997'),
90
+ h: BigInt(1),
91
+ };
92
+ /** Brainpool P256r1 with sha256, from RFC 5639. */
93
+ export const brainpoolP256r1: ECDSA = ecdsa(weierstrass(brainpoolP256r1_CURVE), sha256);
98
94
 
99
- /**
100
- * @deprecated
101
- */
102
- export const pallas: WCurveFn = weierstrass({
103
- a: BigInt(0),
104
- b: BigInt(5),
105
- Fp: Field(pasta_p),
106
- n: pasta_q,
107
- Gx: mod(BigInt(-1), pasta_p),
108
- Gy: BigInt(2),
95
+ const brainpoolP384r1_CURVE: WeierstrassOpts<bigint> = {
96
+ p: BigInt(
97
+ '0x8cb91e82a3386d280f5d6f7e50e641df152f7109ed5456b412b1da197fb71123acd3a729901d1a71874700133107ec53'
98
+ ),
99
+ a: BigInt(
100
+ '0x7bc382c63d8c150c3c72080ace05afa0c2bea28e4fb22787139165efba91f90f8aa5814a503ad4eb04a8c7dd22ce2826'
101
+ ),
102
+ b: BigInt(
103
+ '0x04a8c7dd22ce28268b39b55416f0447c2fb77de107dcd2a62e880ea53eeb62d57cb4390295dbc9943ab78696fa504c11'
104
+ ),
105
+ n: BigInt(
106
+ '0x8cb91e82a3386d280f5d6f7e50e641df152f7109ed5456b31f166e6cac0425a7cf3ab6af6b7fc3103b883202e9046565'
107
+ ),
108
+ Gx: BigInt(
109
+ '0x1d1c64f068cf45ffa2a63a81b7c13f6b8847a3e77ef14fe3db7fcafe0cbd10e8e826e03436d646aaef87b2e247d4af1e'
110
+ ),
111
+ Gy: BigInt(
112
+ '0x8abe1d7520f9c2a45cb1eb8e95cfd55262b70b29feec5864e19c054ff99129280e4646217791811142820341263c5315'
113
+ ),
109
114
  h: BigInt(1),
110
- hash: sha256,
111
- });
112
- /**
113
- * @deprecated
114
- */
115
- export const vesta: WCurveFn = weierstrass({
116
- a: BigInt(0),
117
- b: BigInt(5),
118
- Fp: Field(pasta_q),
119
- n: pasta_p,
120
- Gx: mod(BigInt(-1), pasta_q),
121
- Gy: BigInt(2),
115
+ };
116
+ /** Brainpool P384r1 with sha384, from RFC 5639. */
117
+ export const brainpoolP384r1: ECDSA = ecdsa(weierstrass(brainpoolP384r1_CURVE), sha384);
118
+
119
+ const brainpoolP512r1_CURVE: WeierstrassOpts<bigint> = {
120
+ p: BigInt(
121
+ '0xaadd9db8dbe9c48b3fd4e6ae33c9fc07cb308db3b3c9d20ed6639cca703308717d4d9b009bc66842aecda12ae6a380e62881ff2f2d82c68528aa6056583a48f3'
122
+ ),
123
+ a: BigInt(
124
+ '0x7830a3318b603b89e2327145ac234cc594cbdd8d3df91610a83441caea9863bc2ded5d5aa8253aa10a2ef1c98b9ac8b57f1117a72bf2c7b9e7c1ac4d77fc94ca'
125
+ ),
126
+ b: BigInt(
127
+ '0x3df91610a83441caea9863bc2ded5d5aa8253aa10a2ef1c98b9ac8b57f1117a72bf2c7b9e7c1ac4d77fc94cadc083e67984050b75ebae5dd2809bd638016f723'
128
+ ),
129
+ n: BigInt(
130
+ '0xaadd9db8dbe9c48b3fd4e6ae33c9fc07cb308db3b3c9d20ed6639cca70330870553e5c414ca92619418661197fac10471db1d381085ddaddb58796829ca90069'
131
+ ),
132
+ Gx: BigInt(
133
+ '0x81aee4bdd82ed9645a21322e9c4c6a9385ed9f70b5d916c1b43b62eef4d0098eff3b1f78e2d0d48d50d1687b93b97d5f7c6d5047406a5e688b352209bcb9f822'
134
+ ),
135
+ Gy: BigInt(
136
+ '0x7dde385d566332ecc0eabfa9cf7822fdf209f70024a57b1aa000c55b881f8111b2dcde494a5f485e5bca4bd88a2763aed1ca2b2fa8f0540678cd1e0f3ad80892'
137
+ ),
122
138
  h: BigInt(1),
123
- hash: sha256,
124
- });
139
+ };
140
+ /** Brainpool P521r1 with sha512, from RFC 5639. */
141
+ export const brainpoolP512r1: ECDSA = ecdsa(weierstrass(brainpoolP512r1_CURVE), sha512);