@noble/curves 1.8.0 → 1.8.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 (191) hide show
  1. package/README.md +282 -419
  2. package/_shortw_utils.d.ts +2 -2
  3. package/_shortw_utils.d.ts.map +1 -1
  4. package/_shortw_utils.js +2 -2
  5. package/_shortw_utils.js.map +1 -1
  6. package/abstract/bls.d.ts +5 -5
  7. package/abstract/bls.d.ts.map +1 -1
  8. package/abstract/bls.js +14 -15
  9. package/abstract/bls.js.map +1 -1
  10. package/abstract/curve.d.ts +10 -2
  11. package/abstract/curve.d.ts.map +1 -1
  12. package/abstract/curve.js +81 -78
  13. package/abstract/curve.js.map +1 -1
  14. package/abstract/edwards.d.ts +2 -2
  15. package/abstract/edwards.d.ts.map +1 -1
  16. package/abstract/edwards.js +55 -69
  17. package/abstract/edwards.js.map +1 -1
  18. package/abstract/hash-to-curve.d.ts +5 -4
  19. package/abstract/hash-to-curve.d.ts.map +1 -1
  20. package/abstract/hash-to-curve.js +20 -18
  21. package/abstract/hash-to-curve.js.map +1 -1
  22. package/abstract/modular.d.ts.map +1 -1
  23. package/abstract/modular.js +9 -9
  24. package/abstract/montgomery.js +12 -12
  25. package/abstract/poseidon.d.ts +1 -1
  26. package/abstract/poseidon.d.ts.map +1 -1
  27. package/abstract/poseidon.js +3 -3
  28. package/abstract/poseidon.js.map +1 -1
  29. package/abstract/tower.d.ts +2 -2
  30. package/abstract/tower.js +13 -13
  31. package/abstract/utils.d.ts +4 -2
  32. package/abstract/utils.d.ts.map +1 -1
  33. package/abstract/utils.js +25 -14
  34. package/abstract/utils.js.map +1 -1
  35. package/abstract/weierstrass.d.ts +19 -6
  36. package/abstract/weierstrass.d.ts.map +1 -1
  37. package/abstract/weierstrass.js +97 -80
  38. package/abstract/weierstrass.js.map +1 -1
  39. package/bls12-381.d.ts +1 -1
  40. package/bls12-381.d.ts.map +1 -1
  41. package/bls12-381.js +48 -49
  42. package/bls12-381.js.map +1 -1
  43. package/bn254.d.ts +2 -2
  44. package/bn254.d.ts.map +1 -1
  45. package/bn254.js +29 -30
  46. package/bn254.js.map +1 -1
  47. package/ed25519.d.ts +8 -6
  48. package/ed25519.d.ts.map +1 -1
  49. package/ed25519.js +65 -66
  50. package/ed25519.js.map +1 -1
  51. package/ed448.d.ts +6 -6
  52. package/ed448.d.ts.map +1 -1
  53. package/ed448.js +50 -52
  54. package/ed448.js.map +1 -1
  55. package/esm/_shortw_utils.d.ts +2 -2
  56. package/esm/_shortw_utils.d.ts.map +1 -1
  57. package/esm/_shortw_utils.js +1 -1
  58. package/esm/_shortw_utils.js.map +1 -1
  59. package/esm/abstract/bls.d.ts +5 -5
  60. package/esm/abstract/bls.d.ts.map +1 -1
  61. package/esm/abstract/bls.js +5 -6
  62. package/esm/abstract/bls.js.map +1 -1
  63. package/esm/abstract/curve.d.ts +10 -2
  64. package/esm/abstract/curve.d.ts.map +1 -1
  65. package/esm/abstract/curve.js +77 -74
  66. package/esm/abstract/curve.js.map +1 -1
  67. package/esm/abstract/edwards.d.ts +2 -2
  68. package/esm/abstract/edwards.d.ts.map +1 -1
  69. package/esm/abstract/edwards.js +36 -50
  70. package/esm/abstract/edwards.js.map +1 -1
  71. package/esm/abstract/hash-to-curve.d.ts +5 -4
  72. package/esm/abstract/hash-to-curve.d.ts.map +1 -1
  73. package/esm/abstract/hash-to-curve.js +4 -2
  74. package/esm/abstract/hash-to-curve.js.map +1 -1
  75. package/esm/abstract/modular.d.ts.map +1 -1
  76. package/esm/abstract/modular.js +1 -1
  77. package/esm/abstract/montgomery.js +2 -2
  78. package/esm/abstract/poseidon.d.ts +1 -1
  79. package/esm/abstract/poseidon.d.ts.map +1 -1
  80. package/esm/abstract/poseidon.js +1 -1
  81. package/esm/abstract/poseidon.js.map +1 -1
  82. package/esm/abstract/tower.d.ts +2 -2
  83. package/esm/abstract/tower.js +5 -5
  84. package/esm/abstract/utils.d.ts +4 -2
  85. package/esm/abstract/utils.d.ts.map +1 -1
  86. package/esm/abstract/utils.js +24 -13
  87. package/esm/abstract/utils.js.map +1 -1
  88. package/esm/abstract/weierstrass.d.ts +19 -6
  89. package/esm/abstract/weierstrass.d.ts.map +1 -1
  90. package/esm/abstract/weierstrass.js +77 -60
  91. package/esm/abstract/weierstrass.js.map +1 -1
  92. package/esm/bls12-381.d.ts +1 -1
  93. package/esm/bls12-381.d.ts.map +1 -1
  94. package/esm/bls12-381.js +16 -17
  95. package/esm/bls12-381.js.map +1 -1
  96. package/esm/bn254.d.ts +2 -2
  97. package/esm/bn254.d.ts.map +1 -1
  98. package/esm/bn254.js +7 -8
  99. package/esm/bn254.js.map +1 -1
  100. package/esm/ed25519.d.ts +8 -6
  101. package/esm/ed25519.d.ts.map +1 -1
  102. package/esm/ed25519.js +20 -21
  103. package/esm/ed25519.js.map +1 -1
  104. package/esm/ed448.d.ts +6 -6
  105. package/esm/ed448.d.ts.map +1 -1
  106. package/esm/ed448.js +13 -15
  107. package/esm/ed448.js.map +1 -1
  108. package/esm/index.js +13 -1
  109. package/esm/index.js.map +1 -1
  110. package/esm/jubjub.d.ts +1 -4
  111. package/esm/jubjub.d.ts.map +1 -1
  112. package/esm/jubjub.js +1 -60
  113. package/esm/jubjub.js.map +1 -1
  114. package/esm/misc.d.ts +15 -0
  115. package/esm/misc.d.ts.map +1 -0
  116. package/esm/misc.js +101 -0
  117. package/esm/misc.js.map +1 -0
  118. package/esm/p256.d.ts +8 -5
  119. package/esm/p256.d.ts.map +1 -1
  120. package/esm/p256.js +13 -12
  121. package/esm/p256.js.map +1 -1
  122. package/esm/p384.d.ts +8 -5
  123. package/esm/p384.d.ts.map +1 -1
  124. package/esm/p384.js +14 -15
  125. package/esm/p384.js.map +1 -1
  126. package/esm/p521.d.ts +6 -5
  127. package/esm/p521.d.ts.map +1 -1
  128. package/esm/p521.js +19 -28
  129. package/esm/p521.js.map +1 -1
  130. package/esm/pasta.d.ts +1 -7
  131. package/esm/pasta.d.ts.map +1 -1
  132. package/esm/pasta.js +1 -33
  133. package/esm/pasta.js.map +1 -1
  134. package/esm/secp256k1.d.ts +15 -10
  135. package/esm/secp256k1.d.ts.map +1 -1
  136. package/esm/secp256k1.js +18 -14
  137. package/esm/secp256k1.js.map +1 -1
  138. package/index.js +13 -1
  139. package/index.js.map +1 -1
  140. package/jubjub.d.ts +1 -4
  141. package/jubjub.d.ts.map +1 -1
  142. package/jubjub.js +5 -63
  143. package/jubjub.js.map +1 -1
  144. package/misc.d.ts +15 -0
  145. package/misc.d.ts.map +1 -0
  146. package/misc.js +106 -0
  147. package/misc.js.map +1 -0
  148. package/p256.d.ts +8 -5
  149. package/p256.d.ts.map +1 -1
  150. package/p256.js +19 -18
  151. package/p256.js.map +1 -1
  152. package/p384.d.ts +8 -5
  153. package/p384.d.ts.map +1 -1
  154. package/p384.js +19 -20
  155. package/p384.js.map +1 -1
  156. package/p521.d.ts +6 -5
  157. package/p521.d.ts.map +1 -1
  158. package/p521.js +23 -32
  159. package/p521.js.map +1 -1
  160. package/package.json +21 -16
  161. package/pasta.d.ts +1 -7
  162. package/pasta.d.ts.map +1 -1
  163. package/pasta.js +4 -34
  164. package/pasta.js.map +1 -1
  165. package/secp256k1.d.ts +15 -10
  166. package/secp256k1.d.ts.map +1 -1
  167. package/secp256k1.js +57 -53
  168. package/secp256k1.js.map +1 -1
  169. package/src/_shortw_utils.ts +2 -2
  170. package/src/abstract/bls.ts +14 -12
  171. package/src/abstract/curve.ts +88 -79
  172. package/src/abstract/edwards.ts +52 -59
  173. package/src/abstract/hash-to-curve.ts +7 -5
  174. package/src/abstract/modular.ts +1 -1
  175. package/src/abstract/montgomery.ts +2 -2
  176. package/src/abstract/poseidon.ts +1 -1
  177. package/src/abstract/tower.ts +6 -6
  178. package/src/abstract/utils.ts +26 -15
  179. package/src/abstract/weierstrass.ts +99 -77
  180. package/src/bls12-381.ts +30 -28
  181. package/src/bn254.ts +11 -13
  182. package/src/ed25519.ts +27 -26
  183. package/src/ed448.ts +21 -20
  184. package/src/index.ts +13 -1
  185. package/src/jubjub.ts +5 -63
  186. package/src/misc.ts +117 -0
  187. package/src/p256.ts +13 -12
  188. package/src/p384.ts +18 -15
  189. package/src/p521.ts +27 -32
  190. package/src/pasta.ts +1 -39
  191. package/src/secp256k1.ts +20 -16
package/src/pasta.ts CHANGED
@@ -1,39 +1 @@
1
- /**
2
- * Pasta curves. See [Spec](https://o1-labs.github.io/proof-systems/specs/pasta.html).
3
- * @module
4
- */
5
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
6
- import { sha256 } from '@noble/hashes/sha256';
7
- import { getHash } from './_shortw_utils.js';
8
- import { Field, mod } from './abstract/modular.js';
9
- import { CurveFn, weierstrass } from './abstract/weierstrass.js';
10
-
11
- export const p: bigint = BigInt(
12
- '0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001'
13
- );
14
- export const q: bigint = BigInt(
15
- '0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001'
16
- );
17
-
18
- /** https://neuromancer.sk/std/other/Pallas */
19
- export const pallas: CurveFn = weierstrass({
20
- a: BigInt(0),
21
- b: BigInt(5),
22
- Fp: Field(p),
23
- n: q,
24
- Gx: mod(BigInt(-1), p),
25
- Gy: BigInt(2),
26
- h: BigInt(1),
27
- ...getHash(sha256),
28
- });
29
- /** https://neuromancer.sk/std/other/Vesta */
30
- export const vesta: CurveFn = weierstrass({
31
- a: BigInt(0),
32
- b: BigInt(5),
33
- Fp: Field(q),
34
- n: p,
35
- Gx: mod(BigInt(-1), q),
36
- Gy: BigInt(2),
37
- h: BigInt(1),
38
- ...getHash(sha256),
39
- });
1
+ export { pallas, vesta } from './misc.ts';
package/src/secp256k1.ts CHANGED
@@ -11,21 +11,21 @@
11
11
  * @module
12
12
  */
13
13
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
14
- import { sha256 } from '@noble/hashes/sha256';
14
+ import { sha256 } from '@noble/hashes/sha2';
15
15
  import { randomBytes } from '@noble/hashes/utils';
16
- import { createCurve, CurveFnWithCreate } from './_shortw_utils.js';
17
- import { createHasher, HTFMethod, isogenyMap } from './abstract/hash-to-curve.js';
18
- import { Field, mod, pow2 } from './abstract/modular.js';
19
- import type { Hex, PrivKey } from './abstract/utils.js';
16
+ import { createCurve, type CurveFnWithCreate } from './_shortw_utils.ts';
17
+ import { createHasher, type HTFMethod, isogenyMap } from './abstract/hash-to-curve.ts';
18
+ import { Field, mod, pow2 } from './abstract/modular.ts';
19
+ import type { Hex, PrivKey } from './abstract/utils.ts';
20
20
  import {
21
- inRange,
22
21
  aInRange,
23
22
  bytesToNumberBE,
24
23
  concatBytes,
25
24
  ensureBytes,
25
+ inRange,
26
26
  numberToBytesBE,
27
- } from './abstract/utils.js';
28
- import { ProjPointType as PointType, mapToCurveSimpleSWU } from './abstract/weierstrass.js';
27
+ } from './abstract/utils.ts';
28
+ import { mapToCurveSimpleSWU, type ProjPointType as PointType } from './abstract/weierstrass.ts';
29
29
 
30
30
  const secp256k1P = BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f');
31
31
  const secp256k1N = BigInt('0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141');
@@ -64,24 +64,26 @@ function sqrtMod(y: bigint): bigint {
64
64
  const Fpk1 = Field(secp256k1P, undefined, undefined, { sqrt: sqrtMod });
65
65
 
66
66
  /**
67
- * secp256k1 short weierstrass curve and ECDSA signatures over it.
67
+ * secp256k1 curve, ECDSA and ECDH methods.
68
+ *
69
+ * Field: `2n**256n - 2n**32n - 2n**9n - 2n**8n - 2n**7n - 2n**6n - 2n**4n - 1n`
68
70
  *
69
71
  * @example
72
+ * ```js
70
73
  * import { secp256k1 } from '@noble/curves/secp256k1';
71
- *
72
74
  * const priv = secp256k1.utils.randomPrivateKey();
73
75
  * const pub = secp256k1.getPublicKey(priv);
74
76
  * const msg = new Uint8Array(32).fill(1); // message hash (not message) in ecdsa
75
77
  * const sig = secp256k1.sign(msg, priv); // `{prehash: true}` option is available
76
78
  * const isValid = secp256k1.verify(sig, msg, pub) === true;
79
+ * ```
77
80
  */
78
81
  export const secp256k1: CurveFnWithCreate = createCurve(
79
82
  {
80
- a: BigInt(0), // equation params: a, b
83
+ a: BigInt(0),
81
84
  b: BigInt(7),
82
- Fp: Fpk1, // Field's prime: 2n**256n - 2n**32n - 2n**9n - 2n**8n - 2n**7n - 2n**6n - 2n**4n - 1n
83
- n: secp256k1N, // Curve order, total count of valid points in the field
84
- // Base point (x, y) aka generator point
85
+ Fp: Fpk1,
86
+ n: secp256k1N,
85
87
  Gx: BigInt('55066263022277343669578718895168534326250603453777594175500187360389116729240'),
86
88
  Gy: BigInt('32670510020758816978083085130507043184471273380659243275938904335757337482424'),
87
89
  h: BigInt(1), // Cofactor
@@ -242,12 +244,14 @@ export type SecpSchnorr = {
242
244
  * Schnorr signatures over secp256k1.
243
245
  * https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
244
246
  * @example
247
+ * ```js
245
248
  * import { schnorr } from '@noble/curves/secp256k1';
246
249
  * const priv = schnorr.utils.randomPrivateKey();
247
250
  * const pub = schnorr.getPublicKey(priv);
248
251
  * const msg = new TextEncoder().encode('hello');
249
252
  * const sig = schnorr.sign(msg, priv);
250
253
  * const isValid = schnorr.verify(sig, msg, pub);
254
+ * ```
251
255
  */
252
256
  export const schnorr: SecpSchnorr = /* @__PURE__ */ (() => ({
253
257
  getPublicKey: schnorrGetPublicKey,
@@ -321,8 +325,8 @@ const htf = /* @__PURE__ */ (() =>
321
325
  }
322
326
  ))();
323
327
 
324
- /** secp256k1 hash-to-curve from [RFC 9380](https://www.rfc-editor.org/rfc/rfc9380). */
328
+ /** secp256k1 hash-to-curve from RFC 9380. */
325
329
  export const hashToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.hashToCurve)();
326
330
 
327
- /** secp256k1 encode-to-curve from [RFC 9380](https://www.rfc-editor.org/rfc/rfc9380). */
331
+ /** secp256k1 encode-to-curve from RFC 9380. */
328
332
  export const encodeToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.encodeToCurve)();