@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/ed448.d.ts CHANGED
@@ -1,35 +1,43 @@
1
1
  import type { AffinePoint } from './abstract/curve.ts';
2
- import { PrimeEdwardsPoint, type CurveFn, type EdwardsPoint, type EdwardsPointCons } from './abstract/edwards.ts';
3
- import { type H2CHasher, type H2CHasherBase, type H2CMethod, type htfBasicOpts } from './abstract/hash-to-curve.ts';
2
+ import { PrimeEdwardsPoint, type EdDSA, type EdwardsPoint, type EdwardsPointCons } from './abstract/edwards.ts';
3
+ import { type H2CHasher, type H2CHasherBase } from './abstract/hash-to-curve.ts';
4
4
  import { type IField } from './abstract/modular.ts';
5
- import { type MontgomeryECDH as XCurveFn } from './abstract/montgomery.ts';
6
- import { type Hex } from './utils.ts';
5
+ import { type MontgomeryECDH } from './abstract/montgomery.ts';
6
+ import { type OPRF } from './abstract/oprf.ts';
7
7
  /**
8
8
  * ed448 EdDSA curve and methods.
9
9
  * @example
10
- * import { ed448 } from '@noble/curves/ed448';
10
+ * ```js
11
+ * import { ed448 } from '@noble/curves/ed448.js';
11
12
  * const { secretKey, publicKey } = ed448.keygen();
12
- * const msg = new TextEncoder().encode('hello');
13
+ * // const publicKey = ed448.getPublicKey(secretKey);
14
+ * const msg = new TextEncoder().encode('hello noble');
13
15
  * const sig = ed448.sign(msg, secretKey);
14
16
  * const isValid = ed448.verify(sig, msg, publicKey);
17
+ * ```
15
18
  */
16
- export declare const ed448: CurveFn;
17
- /** Prehashed version of ed448. Accepts already-hashed messages in sign() and verify(). */
18
- export declare const ed448ph: CurveFn;
19
+ export declare const ed448: EdDSA;
20
+ /** Prehashed version of ed448. See {@link ed448} */
21
+ export declare const ed448ph: EdDSA;
19
22
  /**
20
- * E448 curve, defined by NIST.
21
- * E448 != edwards448 used in ed448.
23
+ * E448 (NIST) != edwards448 used in ed448.
22
24
  * E448 is birationally equivalent to edwards448.
23
25
  */
24
26
  export declare const E448: EdwardsPointCons;
25
27
  /**
26
28
  * ECDH using curve448 aka x448.
27
- * x448 has 56-byte keys as per RFC 7748, while
28
- * ed448 has 57-byte keys as per RFC 8032.
29
+ *
30
+ * @example
31
+ * ```js
32
+ * import { x448 } from '@noble/curves/ed448.js';
33
+ * const alice = x448.keygen();
34
+ * const bob = x448.keygen();
35
+ * const shared = x448.getSharedSecret(alice.secretKey, bob.publicKey);
36
+ * ```
29
37
  */
30
- export declare const x448: XCurveFn;
38
+ export declare const x448: MontgomeryECDH;
31
39
  /** Hashing / encoding to ed448 points / field. RFC 9380 methods. */
32
- export declare const ed448_hasher: H2CHasher<bigint>;
40
+ export declare const ed448_hasher: H2CHasher<EdwardsPointCons>;
33
41
  /**
34
42
  * Each ed448/EdwardsPoint has 4 different equivalent points. This can be
35
43
  * a source of bugs for protocols like ring signatures. Decaf was created to solve this.
@@ -46,17 +54,13 @@ declare class _DecafPoint extends PrimeEdwardsPoint<_DecafPoint> {
46
54
  static fromAffine(ap: AffinePoint<bigint>): _DecafPoint;
47
55
  protected assertSame(other: _DecafPoint): void;
48
56
  protected init(ep: EdwardsPoint): _DecafPoint;
49
- /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
50
- static hashToCurve(hex: Hex): _DecafPoint;
51
57
  static fromBytes(bytes: Uint8Array): _DecafPoint;
52
58
  /**
53
59
  * Converts decaf-encoded string to decaf point.
54
60
  * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode-2).
55
61
  * @param hex Decaf-encoded 56 bytes. Not every 56-byte string is valid decaf encoding
56
62
  */
57
- static fromHex(hex: Hex): _DecafPoint;
58
- /** @deprecated use `import { pippenger } from '@noble/curves/abstract/curve.js';` */
59
- static msm(points: _DecafPoint[], scalars: bigint[]): _DecafPoint;
63
+ static fromHex(hex: string): _DecafPoint;
60
64
  /**
61
65
  * Encodes decaf point to Uint8Array.
62
66
  * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-encode-2).
@@ -73,7 +77,9 @@ export declare const decaf448: {
73
77
  Point: typeof _DecafPoint;
74
78
  };
75
79
  /** Hashing to decaf448 points / field. RFC 9380 methods. */
76
- export declare const decaf448_hasher: H2CHasherBase<bigint>;
80
+ export declare const decaf448_hasher: H2CHasherBase<typeof _DecafPoint>;
81
+ /** decaf448 OPRF, defined in RFC 9497. */
82
+ export declare const decaf448_oprf: OPRF;
77
83
  /**
78
84
  * Weird / bogus points, useful for debugging.
79
85
  * Unlike ed25519, there is no ed448 generator point which can produce full T subgroup.
@@ -81,20 +87,5 @@ export declare const decaf448_hasher: H2CHasherBase<bigint>;
81
87
  * (0, 1), (0, -1), (-1, 0), (1, 0).
82
88
  */
83
89
  export declare const ED448_TORSION_SUBGROUP: string[];
84
- type DcfHasher = (msg: Uint8Array, options: htfBasicOpts) => _DecafPoint;
85
- /** @deprecated use `decaf448.Point` */
86
- export declare const DecafPoint: typeof _DecafPoint;
87
- /** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
88
- export declare const hashToCurve: H2CMethod<bigint>;
89
- /** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
90
- export declare const encodeToCurve: H2CMethod<bigint>;
91
- /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
92
- export declare const hashToDecaf448: DcfHasher;
93
- /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
94
- export declare const hash_to_decaf448: DcfHasher;
95
- /** @deprecated use `ed448.utils.toMontgomery` */
96
- export declare function edwardsToMontgomeryPub(edwardsPub: string | Uint8Array): Uint8Array;
97
- /** @deprecated use `ed448.utils.toMontgomery` */
98
- export declare const edwardsToMontgomery: typeof edwardsToMontgomeryPub;
99
90
  export {};
100
91
  //# sourceMappingURL=ed448.d.ts.map
package/ed448.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ed448.d.ts","sourceRoot":"","sources":["src/ed448.ts"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"ed448.d.ts","sourceRoot":"","sources":["src/ed448.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAGL,iBAAiB,EACjB,KAAK,KAAK,EAGV,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAKL,KAAK,SAAS,EACd,KAAK,aAAa,EACnB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAiD,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACnG,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAc,KAAK,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAoI3D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,KAAK,EAAE,KAA+B,CAAC;AAGpD,oDAAoD;AACpD,eAAO,MAAM,OAAO,EAAE,KAAqD,CAAC;AAC5E;;;GAGG;AACH,eAAO,MAAM,IAAI,EAAE,gBAAsD,CAAC;AAE1E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,IAAI,EAAE,cAYf,CAAC;AA+EL,oEAAoE;AACpE,eAAO,MAAM,YAAY,EAAE,SAAS,CAAC,gBAAgB,CAS9C,CAAC;AAkDR;;;;;;GAMG;AACH,cAAM,WAAY,SAAQ,iBAAiB,CAAC,WAAW,CAAC;IAGtD,MAAM,CAAC,IAAI,EAAE,WAAW,CAC0D;IAElF,MAAM,CAAC,IAAI,EAAE,WAAW,CACsC;IAE9D,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,CACS;IAElC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,CACS;gBAEtB,EAAE,EAAE,YAAY;IAI5B,MAAM,CAAC,UAAU,CAAC,EAAE,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,WAAW;IAIvD,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAI9C,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,YAAY,GAAG,WAAW;IAI7C,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW;IA6BhD;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW;IAIxC;;;OAGG;IACH,OAAO,IAAI,UAAU;IAerB;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO;IAQnC,GAAG,IAAI,OAAO;CAGf;AAED,eAAO,MAAM,QAAQ,EAAE;IACrB,KAAK,EAAE,OAAO,WAAW,CAAC;CACF,CAAC;AAE3B,4DAA4D;AAC5D,eAAO,MAAM,eAAe,EAAE,aAAa,CAAC,OAAO,WAAW,CAmC7D,CAAC;AAEF,0CAA0C;AAC1C,eAAO,MAAM,aAAa,EAAE,IAOrB,CAAC;AAER;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,EAK1C,CAAC"}
package/ed448.js CHANGED
@@ -1,7 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.edwardsToMontgomery = exports.hash_to_decaf448 = exports.hashToDecaf448 = exports.encodeToCurve = exports.hashToCurve = exports.DecafPoint = exports.ED448_TORSION_SUBGROUP = exports.decaf448_hasher = exports.decaf448 = exports.ed448_hasher = exports.x448 = exports.E448 = exports.ed448ph = exports.ed448 = void 0;
4
- exports.edwardsToMontgomeryPub = edwardsToMontgomeryPub;
5
1
  /**
6
2
  * Edwards448 (not Ed448-Goldilocks) curve with following addons:
7
3
  * - X448 ECDH
@@ -11,61 +7,62 @@ exports.edwardsToMontgomeryPub = edwardsToMontgomeryPub;
11
7
  * @module
12
8
  */
13
9
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
14
- const sha3_js_1 = require("@noble/hashes/sha3.js");
15
- const utils_js_1 = require("@noble/hashes/utils.js");
16
- const curve_ts_1 = require("./abstract/curve.js");
17
- const edwards_ts_1 = require("./abstract/edwards.js");
18
- const hash_to_curve_ts_1 = require("./abstract/hash-to-curve.js");
19
- const modular_ts_1 = require("./abstract/modular.js");
20
- const montgomery_ts_1 = require("./abstract/montgomery.js");
21
- const utils_ts_1 = require("./utils.js");
10
+ import { shake256 } from '@noble/hashes/sha3.js';
11
+ import { concatBytes, hexToBytes, createHasher as wrapConstructor } from '@noble/hashes/utils.js';
12
+ import { eddsa, edwards, PrimeEdwardsPoint, } from "./abstract/edwards.js";
13
+ import { _DST_scalar, createHasher, expand_message_xof, } from "./abstract/hash-to-curve.js";
14
+ import { Field, FpInvertBatch, isNegativeLE, mod, pow2 } from "./abstract/modular.js";
15
+ import { montgomery } from "./abstract/montgomery.js";
16
+ import { createORPF } from "./abstract/oprf.js";
17
+ import { abytes, asciiToBytes, bytesToNumberLE, equalBytes } from "./utils.js";
22
18
  // edwards448 curve
23
19
  // a = 1n
24
20
  // d = Fp.neg(39081n)
25
21
  // Finite field 2n**448n - 2n**224n - 1n
26
22
  // Subgroup order
27
23
  // 2n**446n - 13818066809895115352007386748515426880336692474882178609894547503885n
28
- const ed448_CURVE = {
29
- p: BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffff'),
24
+ const ed448_CURVE_p = BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
25
+ const ed448_CURVE = /* @__PURE__ */ (() => ({
26
+ p: ed448_CURVE_p,
30
27
  n: BigInt('0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffff7cca23e9c44edb49aed63690216cc2728dc58f552378c292ab5844f3'),
31
28
  h: BigInt(4),
32
29
  a: BigInt(1),
33
30
  d: BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffff6756'),
34
31
  Gx: BigInt('0x4f1970c66bed0ded221d15a622bf36da9e146570470f1767ea6de324a3d3a46412ae1af72ab66511433b80e18b00938e2626a82bc70cc05e'),
35
32
  Gy: BigInt('0x693f46716eb6bc248876203756c9c7624bea73736ca3984087789c1e05a0c2d73ad3ff1ce67c39c4fdbd132c4ed7c8ad9808795bf230fa14'),
36
- };
33
+ }))();
37
34
  // E448 NIST curve is identical to edwards448, except for:
38
35
  // d = 39082/39081
39
36
  // Gx = 3/2
40
- const E448_CURVE = Object.assign({}, ed448_CURVE, {
37
+ const E448_CURVE = /* @__PURE__ */ (() => Object.assign({}, ed448_CURVE, {
41
38
  d: BigInt('0xd78b4bdc7f0daf19f24f38c29373a2ccad46157242a50f37809b1da3412a12e79ccc9c81264cfe9ad080997058fb61c4243cc32dbaa156b9'),
42
39
  Gx: BigInt('0x79a70b2b70400553ae7c9df416c792c61128751ac92969240c25a07d728bdc93e21f7787ed6972249de732f38496cd11698713093e9c04fc'),
43
40
  Gy: BigInt('0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff80000000000000000000000000000000000000000000000000000001'),
44
- });
45
- const shake256_114 = /* @__PURE__ */ (0, utils_js_1.createHasher)(() => sha3_js_1.shake256.create({ dkLen: 114 }));
46
- const shake256_64 = /* @__PURE__ */ (0, utils_js_1.createHasher)(() => sha3_js_1.shake256.create({ dkLen: 64 }));
41
+ }))();
42
+ const shake256_114 = /* @__PURE__ */ wrapConstructor(() => shake256.create({ dkLen: 114 }));
43
+ const shake256_64 = /* @__PURE__ */ wrapConstructor(() => shake256.create({ dkLen: 64 }));
47
44
  // prettier-ignore
48
- const _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3), _4n = BigInt(4), _11n = BigInt(11);
45
+ const _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3), _4n = /* @__PURE__ */ BigInt(4), _11n = BigInt(11);
49
46
  // prettier-ignore
50
47
  const _22n = BigInt(22), _44n = BigInt(44), _88n = BigInt(88), _223n = BigInt(223);
51
48
  // powPminus3div4 calculates z = x^k mod p, where k = (p-3)/4.
52
49
  // Used for efficient square root calculation.
53
50
  // ((P-3)/4).toString(2) would produce bits [223x 1, 0, 222x 1]
54
51
  function ed448_pow_Pminus3div4(x) {
55
- const P = ed448_CURVE.p;
52
+ const P = ed448_CURVE_p;
56
53
  const b2 = (x * x * x) % P;
57
54
  const b3 = (b2 * b2 * x) % P;
58
- const b6 = ((0, modular_ts_1.pow2)(b3, _3n, P) * b3) % P;
59
- const b9 = ((0, modular_ts_1.pow2)(b6, _3n, P) * b3) % P;
60
- const b11 = ((0, modular_ts_1.pow2)(b9, _2n, P) * b2) % P;
61
- const b22 = ((0, modular_ts_1.pow2)(b11, _11n, P) * b11) % P;
62
- const b44 = ((0, modular_ts_1.pow2)(b22, _22n, P) * b22) % P;
63
- const b88 = ((0, modular_ts_1.pow2)(b44, _44n, P) * b44) % P;
64
- const b176 = ((0, modular_ts_1.pow2)(b88, _88n, P) * b88) % P;
65
- const b220 = ((0, modular_ts_1.pow2)(b176, _44n, P) * b44) % P;
66
- const b222 = ((0, modular_ts_1.pow2)(b220, _2n, P) * b2) % P;
67
- const b223 = ((0, modular_ts_1.pow2)(b222, _1n, P) * x) % P;
68
- return ((0, modular_ts_1.pow2)(b223, _223n, P) * b222) % P;
55
+ const b6 = (pow2(b3, _3n, P) * b3) % P;
56
+ const b9 = (pow2(b6, _3n, P) * b3) % P;
57
+ const b11 = (pow2(b9, _2n, P) * b2) % P;
58
+ const b22 = (pow2(b11, _11n, P) * b11) % P;
59
+ const b44 = (pow2(b22, _22n, P) * b22) % P;
60
+ const b88 = (pow2(b44, _44n, P) * b44) % P;
61
+ const b176 = (pow2(b88, _88n, P) * b88) % P;
62
+ const b220 = (pow2(b176, _44n, P) * b44) % P;
63
+ const b222 = (pow2(b220, _2n, P) * b2) % P;
64
+ const b223 = (pow2(b222, _1n, P) * x) % P;
65
+ return (pow2(b223, _223n, P) * b222) % P;
69
66
  }
70
67
  function adjustScalarBytes(bytes) {
71
68
  // Section 5: Likewise, for X448, set the two least significant bits of the first byte to 0,
@@ -79,93 +76,90 @@ function adjustScalarBytes(bytes) {
79
76
  // Constant-time ratio of u to v. Allows to combine inversion and square root u/√v.
80
77
  // Uses algo from RFC8032 5.1.3.
81
78
  function uvRatio(u, v) {
82
- const P = ed448_CURVE.p;
79
+ const P = ed448_CURVE_p;
83
80
  // https://www.rfc-editor.org/rfc/rfc8032#section-5.2.3
84
81
  // To compute the square root of (u/v), the first step is to compute the
85
82
  // candidate root x = (u/v)^((p+1)/4). This can be done using the
86
83
  // following trick, to use a single modular powering for both the
87
84
  // inversion of v and the square root:
88
85
  // x = (u/v)^((p+1)/4) = u³v(u⁵v³)^((p-3)/4) (mod p)
89
- const u2v = (0, modular_ts_1.mod)(u * u * v, P); // u²v
90
- const u3v = (0, modular_ts_1.mod)(u2v * u, P); // u³v
91
- const u5v3 = (0, modular_ts_1.mod)(u3v * u2v * v, P); // u⁵v³
86
+ const u2v = mod(u * u * v, P); // u²v
87
+ const u3v = mod(u2v * u, P); // u³v
88
+ const u5v3 = mod(u3v * u2v * v, P); // u⁵v³
92
89
  const root = ed448_pow_Pminus3div4(u5v3);
93
- const x = (0, modular_ts_1.mod)(u3v * root, P);
90
+ const x = mod(u3v * root, P);
94
91
  // Verify that root is exists
95
- const x2 = (0, modular_ts_1.mod)(x * x, P); // x²
92
+ const x2 = mod(x * x, P); // x²
96
93
  // If vx² = u, the recovered x-coordinate is x. Otherwise, no
97
94
  // square root exists, and the decoding fails.
98
- return { isValid: (0, modular_ts_1.mod)(x2 * v, P) === u, value: x };
95
+ return { isValid: mod(x2 * v, P) === u, value: x };
99
96
  }
100
97
  // Finite field 2n**448n - 2n**224n - 1n
101
98
  // The value fits in 448 bits, but we use 456-bit (57-byte) elements because of bitflags.
102
99
  // - ed25519 fits in 255 bits, allowing using last 1 byte for specifying bit flag of point negation.
103
100
  // - ed448 fits in 448 bits. We can't use last 1 byte: we can only use a bit 224 in the middle.
104
- const Fp = /* @__PURE__ */ (() => (0, modular_ts_1.Field)(ed448_CURVE.p, { BITS: 456, isLE: true }))();
105
- const Fn = /* @__PURE__ */ (() => (0, modular_ts_1.Field)(ed448_CURVE.n, { BITS: 456, isLE: true }))();
101
+ const Fp = /* @__PURE__ */ (() => Field(ed448_CURVE_p, { BITS: 456, isLE: true }))();
102
+ const Fn = /* @__PURE__ */ (() => Field(ed448_CURVE.n, { BITS: 456, isLE: true }))();
106
103
  // decaf448 uses 448-bit (56-byte) keys
107
- const Fp448 = /* @__PURE__ */ (() => (0, modular_ts_1.Field)(ed448_CURVE.p, { BITS: 448, isLE: true }))();
108
- const Fn448 = /* @__PURE__ */ (() => (0, modular_ts_1.Field)(ed448_CURVE.n, { BITS: 448, isLE: true }))();
104
+ const Fp448 = /* @__PURE__ */ (() => Field(ed448_CURVE_p, { BITS: 448, isLE: true }))();
105
+ const Fn448 = /* @__PURE__ */ (() => Field(ed448_CURVE.n, { BITS: 448, isLE: true }))();
109
106
  // SHAKE256(dom4(phflag,context)||x, 114)
110
107
  function dom4(data, ctx, phflag) {
111
108
  if (ctx.length > 255)
112
109
  throw new Error('context must be smaller than 255, got: ' + ctx.length);
113
- return (0, utils_js_1.concatBytes)((0, utils_ts_1.asciiToBytes)('SigEd448'), new Uint8Array([phflag ? 1 : 0, ctx.length]), ctx, data);
110
+ return concatBytes(asciiToBytes('SigEd448'), new Uint8Array([phflag ? 1 : 0, ctx.length]), ctx, data);
111
+ }
112
+ const ed448_Point = /* @__PURE__ */ edwards(ed448_CURVE, { Fp, Fn, uvRatio });
113
+ function ed4(opts) {
114
+ return eddsa(ed448_Point, shake256_114, Object.assign({ adjustScalarBytes, domain: dom4 }, opts));
114
115
  }
115
- // const ed448_eddsa_opts = { adjustScalarBytes, domain: dom4 };
116
- // const ed448_Point = edwards(ed448_CURVE, { Fp, Fn, uvRatio });
117
- const ED448_DEF = /* @__PURE__ */ (() => ({
118
- ...ed448_CURVE,
119
- Fp,
120
- Fn,
121
- nBitLength: Fn.BITS,
122
- hash: shake256_114,
123
- adjustScalarBytes,
124
- domain: dom4,
125
- uvRatio,
126
- }))();
127
116
  /**
128
117
  * ed448 EdDSA curve and methods.
129
118
  * @example
130
- * import { ed448 } from '@noble/curves/ed448';
119
+ * ```js
120
+ * import { ed448 } from '@noble/curves/ed448.js';
131
121
  * const { secretKey, publicKey } = ed448.keygen();
132
- * const msg = new TextEncoder().encode('hello');
122
+ * // const publicKey = ed448.getPublicKey(secretKey);
123
+ * const msg = new TextEncoder().encode('hello noble');
133
124
  * const sig = ed448.sign(msg, secretKey);
134
125
  * const isValid = ed448.verify(sig, msg, publicKey);
126
+ * ```
135
127
  */
136
- exports.ed448 = (0, edwards_ts_1.twistedEdwards)(ED448_DEF);
128
+ export const ed448 = /* @__PURE__ */ ed4({});
137
129
  // There is no ed448ctx, since ed448 supports ctx by default
138
- /** Prehashed version of ed448. Accepts already-hashed messages in sign() and verify(). */
139
- exports.ed448ph = (() => (0, edwards_ts_1.twistedEdwards)({
140
- ...ED448_DEF,
141
- prehash: shake256_64,
142
- }))();
130
+ /** Prehashed version of ed448. See {@link ed448} */
131
+ export const ed448ph = /* @__PURE__ */ ed4({ prehash: shake256_64 });
143
132
  /**
144
- * E448 curve, defined by NIST.
145
- * E448 != edwards448 used in ed448.
133
+ * E448 (NIST) != edwards448 used in ed448.
146
134
  * E448 is birationally equivalent to edwards448.
147
135
  */
148
- exports.E448 = (0, edwards_ts_1.edwards)(E448_CURVE);
136
+ export const E448 = /* @__PURE__ */ edwards(E448_CURVE);
149
137
  /**
150
138
  * ECDH using curve448 aka x448.
151
- * x448 has 56-byte keys as per RFC 7748, while
152
- * ed448 has 57-byte keys as per RFC 8032.
139
+ *
140
+ * @example
141
+ * ```js
142
+ * import { x448 } from '@noble/curves/ed448.js';
143
+ * const alice = x448.keygen();
144
+ * const bob = x448.keygen();
145
+ * const shared = x448.getSharedSecret(alice.secretKey, bob.publicKey);
146
+ * ```
153
147
  */
154
- exports.x448 = (() => {
155
- const P = ed448_CURVE.p;
156
- return (0, montgomery_ts_1.montgomery)({
148
+ export const x448 = /* @__PURE__ */ (() => {
149
+ const P = ed448_CURVE_p;
150
+ return montgomery({
157
151
  P,
158
152
  type: 'x448',
159
153
  powPminus2: (x) => {
160
154
  const Pminus3div4 = ed448_pow_Pminus3div4(x);
161
- const Pminus3 = (0, modular_ts_1.pow2)(Pminus3div4, _2n, P);
162
- return (0, modular_ts_1.mod)(Pminus3 * x, P); // Pminus3 * x = Pminus2
155
+ const Pminus3 = pow2(Pminus3div4, _2n, P);
156
+ return mod(Pminus3 * x, P); // Pminus3 * x = Pminus2
163
157
  },
164
158
  adjustScalarBytes,
165
159
  });
166
160
  })();
167
161
  // Hash To Curve Elligator2 Map
168
- const ELL2_C1 = /* @__PURE__ */ (() => (Fp.ORDER - BigInt(3)) / BigInt(4))(); // 1. c1 = (q - 3) / 4 # Integer arithmetic
162
+ const ELL2_C1 = /* @__PURE__ */ (() => (ed448_CURVE_p - BigInt(3)) / BigInt(4))(); // 1. c1 = (q - 3) / 4 # Integer arithmetic
169
163
  const ELL2_J = /* @__PURE__ */ BigInt(156326);
170
164
  function map_to_curve_elligator2_curve448(u) {
171
165
  let tv1 = Fp.sqr(u); // 1. tv1 = u^2
@@ -234,18 +228,18 @@ function map_to_curve_elligator2_edwards448(u) {
234
228
  xEd = Fp.cmov(xEd, Fp.ONE, e); // 35. xEd = CMOV(xEd, 1, e)
235
229
  yEn = Fp.cmov(yEn, Fp.ONE, e); // 36. yEn = CMOV(yEn, 1, e)
236
230
  yEd = Fp.cmov(yEd, Fp.ONE, e); // 37. yEd = CMOV(yEd, 1, e)
237
- const inv = (0, modular_ts_1.FpInvertBatch)(Fp, [xEd, yEd], true); // batch division
231
+ const inv = FpInvertBatch(Fp, [xEd, yEd], true); // batch division
238
232
  return { x: Fp.mul(xEn, inv[0]), y: Fp.mul(yEn, inv[1]) }; // 38. return (xEn, xEd, yEn, yEd)
239
233
  }
240
234
  /** Hashing / encoding to ed448 points / field. RFC 9380 methods. */
241
- exports.ed448_hasher = (() => (0, hash_to_curve_ts_1.createHasher)(exports.ed448.Point, (scalars) => map_to_curve_elligator2_edwards448(scalars[0]), {
235
+ export const ed448_hasher = /* @__PURE__ */ (() => createHasher(ed448_Point, (scalars) => map_to_curve_elligator2_edwards448(scalars[0]), {
242
236
  DST: 'edwards448_XOF:SHAKE256_ELL2_RO_',
243
237
  encodeDST: 'edwards448_XOF:SHAKE256_ELL2_NU_',
244
- p: Fp.ORDER,
238
+ p: ed448_CURVE_p,
245
239
  m: 1,
246
240
  k: 224,
247
241
  expand: 'xof',
248
- hash: sha3_js_1.shake256,
242
+ hash: shake256,
249
243
  }))();
250
244
  // 1-d
251
245
  const ONE_MINUS_D = /* @__PURE__ */ BigInt('39082');
@@ -263,9 +257,8 @@ const invertSqrt = (number) => uvRatio(_1n, number);
263
257
  * and [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-element-derivation-2).
264
258
  */
265
259
  function calcElligatorDecafMap(r0) {
266
- const { d } = ed448_CURVE;
267
- const P = Fp.ORDER;
268
- const mod = (n) => Fp.create(n);
260
+ const { d, p: P } = ed448_CURVE;
261
+ const mod = (n) => Fp448.create(n);
269
262
  const r = mod(-(r0 * r0)); // 1
270
263
  const u0 = mod(d * (r - _1n)); // 2
271
264
  const u1 = mod((u0 + _1n) * (u0 - r)); // 3
@@ -278,26 +271,14 @@ function calcElligatorDecafMap(r0) {
278
271
  sgn = mod(-_1n);
279
272
  const s = mod(v_prime * (r + _1n)); // 7
280
273
  let s_abs = s;
281
- if ((0, modular_ts_1.isNegativeLE)(s, P))
274
+ if (isNegativeLE(s, P))
282
275
  s_abs = mod(-s);
283
276
  const s2 = s * s;
284
277
  const W0 = mod(s_abs * _2n); // 8
285
278
  const W1 = mod(s2 + _1n); // 9
286
279
  const W2 = mod(s2 - _1n); // 10
287
280
  const W3 = mod(v_prime * s * (r - _1n) * ONE_MINUS_TWO_D + sgn); // 11
288
- return new exports.ed448.Point(mod(W0 * W3), mod(W2 * W1), mod(W1 * W3), mod(W0 * W2));
289
- }
290
- function decaf448_map(bytes) {
291
- (0, utils_js_1.abytes)(bytes, 112);
292
- const skipValidation = true;
293
- // Note: Similar to the field element decoding described in
294
- // [RFC7748], and unlike the field element decoding described in
295
- // Section 5.3.1, non-canonical values are accepted.
296
- const r1 = Fp448.create(Fp448.fromBytes(bytes.subarray(0, 56), skipValidation));
297
- const R1 = calcElligatorDecafMap(r1);
298
- const r2 = Fp448.create(Fp448.fromBytes(bytes.subarray(56, 112), skipValidation));
299
- const R2 = calcElligatorDecafMap(r2);
300
- return new _DecafPoint(R1.add(R2));
281
+ return new ed448_Point(mod(W0 * W3), mod(W2 * W1), mod(W1 * W3), mod(W0 * W2));
301
282
  }
302
283
  /**
303
284
  * Each ed448/EdwardsPoint has 4 different equivalent points. This can be
@@ -306,12 +287,25 @@ function decaf448_map(bytes) {
306
287
  * but it should work in its own namespace: do not combine those two.
307
288
  * See [RFC9496](https://www.rfc-editor.org/rfc/rfc9496).
308
289
  */
309
- class _DecafPoint extends edwards_ts_1.PrimeEdwardsPoint {
290
+ class _DecafPoint extends PrimeEdwardsPoint {
291
+ // The following gymnastics is done because typescript strips comments otherwise
292
+ // prettier-ignore
293
+ static BASE =
294
+ /* @__PURE__ */ (() => new _DecafPoint(ed448_Point.BASE).multiplyUnsafe(_2n))();
295
+ // prettier-ignore
296
+ static ZERO =
297
+ /* @__PURE__ */ (() => new _DecafPoint(ed448_Point.ZERO))();
298
+ // prettier-ignore
299
+ static Fp =
300
+ /* @__PURE__ */ (() => Fp448)();
301
+ // prettier-ignore
302
+ static Fn =
303
+ /* @__PURE__ */ (() => Fn448)();
310
304
  constructor(ep) {
311
305
  super(ep);
312
306
  }
313
307
  static fromAffine(ap) {
314
- return new _DecafPoint(exports.ed448.Point.fromAffine(ap));
308
+ return new _DecafPoint(ed448_Point.fromAffine(ap));
315
309
  }
316
310
  assertSame(other) {
317
311
  if (!(other instanceof _DecafPoint))
@@ -320,19 +314,14 @@ class _DecafPoint extends edwards_ts_1.PrimeEdwardsPoint {
320
314
  init(ep) {
321
315
  return new _DecafPoint(ep);
322
316
  }
323
- /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
324
- static hashToCurve(hex) {
325
- return decaf448_map((0, utils_ts_1.ensureBytes)('decafHash', hex, 112));
326
- }
327
317
  static fromBytes(bytes) {
328
- (0, utils_js_1.abytes)(bytes, 56);
329
- const { d } = ed448_CURVE;
330
- const P = Fp.ORDER;
318
+ abytes(bytes, 56);
319
+ const { d, p: P } = ed448_CURVE;
331
320
  const mod = (n) => Fp448.create(n);
332
321
  const s = Fp448.fromBytes(bytes);
333
322
  // 1. Check that s_bytes is the canonical encoding of a field element, or else abort.
334
323
  // 2. Check that s is non-negative, or else abort
335
- if (!(0, utils_ts_1.equalBytes)(Fn448.toBytes(s), bytes) || (0, modular_ts_1.isNegativeLE)(s, P))
324
+ if (!equalBytes(Fn448.toBytes(s), bytes) || isNegativeLE(s, P))
336
325
  throw new Error('invalid decaf448 encoding 1');
337
326
  const s2 = mod(s * s); // 1
338
327
  const u1 = mod(_1n + s2); // 2
@@ -340,14 +329,14 @@ class _DecafPoint extends edwards_ts_1.PrimeEdwardsPoint {
340
329
  const u2 = mod(u1sq - _4n * d * s2); // 3
341
330
  const { isValid, value: invsqrt } = invertSqrt(mod(u2 * u1sq)); // 4
342
331
  let u3 = mod((s + s) * invsqrt * u1 * SQRT_MINUS_D); // 5
343
- if ((0, modular_ts_1.isNegativeLE)(u3, P))
332
+ if (isNegativeLE(u3, P))
344
333
  u3 = mod(-u3);
345
334
  const x = mod(u3 * invsqrt * u2 * INVSQRT_MINUS_D); // 6
346
335
  const y = mod((_1n - s2) * invsqrt * u1); // 7
347
336
  const t = mod(x * y); // 8
348
337
  if (!isValid)
349
338
  throw new Error('invalid decaf448 encoding 2');
350
- return new _DecafPoint(new exports.ed448.Point(x, y, _1n, t));
339
+ return new _DecafPoint(new ed448_Point(x, y, _1n, t));
351
340
  }
352
341
  /**
353
342
  * Converts decaf-encoded string to decaf point.
@@ -355,11 +344,7 @@ class _DecafPoint extends edwards_ts_1.PrimeEdwardsPoint {
355
344
  * @param hex Decaf-encoded 56 bytes. Not every 56-byte string is valid decaf encoding
356
345
  */
357
346
  static fromHex(hex) {
358
- return _DecafPoint.fromBytes((0, utils_ts_1.ensureBytes)('decafHex', hex, 56));
359
- }
360
- /** @deprecated use `import { pippenger } from '@noble/curves/abstract/curve.js';` */
361
- static msm(points, scalars) {
362
- return (0, curve_ts_1.pippenger)(_DecafPoint, Fn, points, scalars);
347
+ return _DecafPoint.fromBytes(hexToBytes(hex));
363
348
  }
364
349
  /**
365
350
  * Encodes decaf point to Uint8Array.
@@ -367,17 +352,17 @@ class _DecafPoint extends edwards_ts_1.PrimeEdwardsPoint {
367
352
  */
368
353
  toBytes() {
369
354
  const { X, Z, T } = this.ep;
370
- const P = Fp.ORDER;
371
- const mod = (n) => Fp.create(n);
355
+ const P = ed448_CURVE.p;
356
+ const mod = (n) => Fp448.create(n);
372
357
  const u1 = mod(mod(X + T) * mod(X - T)); // 1
373
358
  const x2 = mod(X * X);
374
359
  const { value: invsqrt } = invertSqrt(mod(u1 * ONE_MINUS_D * x2)); // 2
375
360
  let ratio = mod(invsqrt * u1 * SQRT_MINUS_D); // 3
376
- if ((0, modular_ts_1.isNegativeLE)(ratio, P))
361
+ if (isNegativeLE(ratio, P))
377
362
  ratio = mod(-ratio);
378
363
  const u2 = mod(INVSQRT_MINUS_D * ratio * Z - T); // 4
379
364
  let s = mod(ONE_MINUS_D * invsqrt * X * u2); // 5
380
- if ((0, modular_ts_1.isNegativeLE)(s, P))
365
+ if (isNegativeLE(s, P))
381
366
  s = mod(-s);
382
367
  return Fn448.toBytes(s);
383
368
  }
@@ -390,74 +375,68 @@ class _DecafPoint extends edwards_ts_1.PrimeEdwardsPoint {
390
375
  const { X: X1, Y: Y1 } = this.ep;
391
376
  const { X: X2, Y: Y2 } = other.ep;
392
377
  // (x1 * y2 == y1 * x2)
393
- return Fp.create(X1 * Y2) === Fp.create(Y1 * X2);
378
+ return Fp448.create(X1 * Y2) === Fp448.create(Y1 * X2);
394
379
  }
395
380
  is0() {
396
381
  return this.equals(_DecafPoint.ZERO);
397
382
  }
398
383
  }
399
- // The following gymnastics is done because typescript strips comments otherwise
400
- // prettier-ignore
401
- _DecafPoint.BASE =
402
- /* @__PURE__ */ (() => new _DecafPoint(exports.ed448.Point.BASE).multiplyUnsafe(_2n))();
403
- // prettier-ignore
404
- _DecafPoint.ZERO =
405
- /* @__PURE__ */ (() => new _DecafPoint(exports.ed448.Point.ZERO))();
406
- // prettier-ignore
407
- _DecafPoint.Fp =
408
- /* @__PURE__ */ (() => Fp448)();
409
- // prettier-ignore
410
- _DecafPoint.Fn =
411
- /* @__PURE__ */ (() => Fn448)();
412
- exports.decaf448 = { Point: _DecafPoint };
384
+ export const decaf448 = { Point: _DecafPoint };
413
385
  /** Hashing to decaf448 points / field. RFC 9380 methods. */
414
- exports.decaf448_hasher = {
386
+ export const decaf448_hasher = {
387
+ Point: _DecafPoint,
415
388
  hashToCurve(msg, options) {
416
389
  const DST = options?.DST || 'decaf448_XOF:SHAKE256_D448MAP_RO_';
417
- return decaf448_map((0, hash_to_curve_ts_1.expand_message_xof)(msg, DST, 112, 224, sha3_js_1.shake256));
390
+ return decaf448_hasher.deriveToCurve(expand_message_xof(msg, DST, 112, 224, shake256));
418
391
  },
419
- // Warning: has big modulo bias of 2^-64.
420
- // RFC is invalid. RFC says "use 64-byte xof", while for 2^-112 bias
421
- // it must use 84-byte xof (56+56/2), not 64.
422
- hashToScalar(msg, options = { DST: hash_to_curve_ts_1._DST_scalar }) {
392
+ /**
393
+ * Warning: has big modulo bias of 2^-64.
394
+ * RFC is invalid. RFC says "use 64-byte xof", while for 2^-112 bias
395
+ * it must use 84-byte xof (56+56/2), not 64.
396
+ */
397
+ hashToScalar(msg, options = { DST: _DST_scalar }) {
423
398
  // Can't use `Fn448.fromBytes()`. 64-byte input => 56-byte field element
424
- const xof = (0, hash_to_curve_ts_1.expand_message_xof)(msg, options.DST, 64, 256, sha3_js_1.shake256);
425
- return Fn448.create((0, utils_ts_1.bytesToNumberLE)(xof));
399
+ const xof = expand_message_xof(msg, options.DST, 64, 256, shake256);
400
+ return Fn448.create(bytesToNumberLE(xof));
401
+ },
402
+ /**
403
+ * HashToCurve-like construction based on RFC 9496 (Element Derivation).
404
+ * Converts 112 uniform random bytes into a curve point.
405
+ *
406
+ * WARNING: This represents an older hash-to-curve construction, preceding the finalization of RFC 9380.
407
+ * It was later reused as a component in the newer `hash_to_ristretto255` function defined in RFC 9380.
408
+ */
409
+ deriveToCurve(bytes) {
410
+ abytes(bytes, 112);
411
+ const skipValidation = true;
412
+ // Note: Similar to the field element decoding described in
413
+ // [RFC7748], and unlike the field element decoding described in
414
+ // Section 5.3.1, non-canonical values are accepted.
415
+ const r1 = Fp448.create(Fp448.fromBytes(bytes.subarray(0, 56), skipValidation));
416
+ const R1 = calcElligatorDecafMap(r1);
417
+ const r2 = Fp448.create(Fp448.fromBytes(bytes.subarray(56, 112), skipValidation));
418
+ const R2 = calcElligatorDecafMap(r2);
419
+ return new _DecafPoint(R1.add(R2));
426
420
  },
427
421
  };
428
- // export const decaf448_oprf: OPRF = createORPF({
429
- // name: 'decaf448-SHAKE256',
430
- // Point: DecafPoint,
431
- // hash: (msg: Uint8Array) => shake256(msg, { dkLen: 64 }),
432
- // hashToGroup: decaf448_hasher.hashToCurve,
433
- // hashToScalar: decaf448_hasher.hashToScalar,
434
- // });
422
+ /** decaf448 OPRF, defined in RFC 9497. */
423
+ export const decaf448_oprf = /* @__PURE__ */ (() => createORPF({
424
+ name: 'decaf448-SHAKE256',
425
+ Point: _DecafPoint,
426
+ hash: (msg) => shake256(msg, { dkLen: 64 }),
427
+ hashToGroup: decaf448_hasher.hashToCurve,
428
+ hashToScalar: decaf448_hasher.hashToScalar,
429
+ }))();
435
430
  /**
436
431
  * Weird / bogus points, useful for debugging.
437
432
  * Unlike ed25519, there is no ed448 generator point which can produce full T subgroup.
438
433
  * Instead, there is a Klein four-group, which spans over 2 independent 2-torsion points:
439
434
  * (0, 1), (0, -1), (-1, 0), (1, 0).
440
435
  */
441
- exports.ED448_TORSION_SUBGROUP = [
436
+ export const ED448_TORSION_SUBGROUP = [
442
437
  '010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
443
438
  'fefffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffff00',
444
439
  '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
445
440
  '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080',
446
441
  ];
447
- /** @deprecated use `decaf448.Point` */
448
- exports.DecafPoint = _DecafPoint;
449
- /** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
450
- exports.hashToCurve = (() => exports.ed448_hasher.hashToCurve)();
451
- /** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
452
- exports.encodeToCurve = (() => exports.ed448_hasher.encodeToCurve)();
453
- /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
454
- exports.hashToDecaf448 = (() => exports.decaf448_hasher.hashToCurve)();
455
- /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
456
- exports.hash_to_decaf448 = (() => exports.decaf448_hasher.hashToCurve)();
457
- /** @deprecated use `ed448.utils.toMontgomery` */
458
- function edwardsToMontgomeryPub(edwardsPub) {
459
- return exports.ed448.utils.toMontgomery((0, utils_ts_1.ensureBytes)('pub', edwardsPub));
460
- }
461
- /** @deprecated use `ed448.utils.toMontgomery` */
462
- exports.edwardsToMontgomery = edwardsToMontgomeryPub;
463
442
  //# sourceMappingURL=ed448.js.map