@noble/curves 1.9.2 → 1.9.4

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 (179) hide show
  1. package/README.md +186 -206
  2. package/_shortw_utils.d.ts +1 -0
  3. package/_shortw_utils.d.ts.map +1 -1
  4. package/_shortw_utils.js +1 -0
  5. package/_shortw_utils.js.map +1 -1
  6. package/abstract/bls.d.ts +87 -62
  7. package/abstract/bls.d.ts.map +1 -1
  8. package/abstract/bls.js +170 -163
  9. package/abstract/bls.js.map +1 -1
  10. package/abstract/curve.d.ts +109 -23
  11. package/abstract/curve.d.ts.map +1 -1
  12. package/abstract/curve.js +158 -156
  13. package/abstract/curve.js.map +1 -1
  14. package/abstract/edwards.d.ts +126 -70
  15. package/abstract/edwards.d.ts.map +1 -1
  16. package/abstract/edwards.js +212 -62
  17. package/abstract/edwards.js.map +1 -1
  18. package/abstract/hash-to-curve.d.ts +8 -4
  19. package/abstract/hash-to-curve.d.ts.map +1 -1
  20. package/abstract/hash-to-curve.js +23 -11
  21. package/abstract/hash-to-curve.js.map +1 -1
  22. package/abstract/modular.d.ts +8 -3
  23. package/abstract/modular.d.ts.map +1 -1
  24. package/abstract/modular.js +79 -35
  25. package/abstract/modular.js.map +1 -1
  26. package/abstract/montgomery.d.ts +17 -4
  27. package/abstract/montgomery.d.ts.map +1 -1
  28. package/abstract/montgomery.js +19 -3
  29. package/abstract/montgomery.js.map +1 -1
  30. package/abstract/tower.d.ts +3 -3
  31. package/abstract/tower.d.ts.map +1 -1
  32. package/abstract/tower.js.map +1 -1
  33. package/abstract/weierstrass.d.ts +145 -118
  34. package/abstract/weierstrass.d.ts.map +1 -1
  35. package/abstract/weierstrass.js +415 -336
  36. package/abstract/weierstrass.js.map +1 -1
  37. package/bls12-381.d.ts.map +1 -1
  38. package/bls12-381.js +4 -4
  39. package/bls12-381.js.map +1 -1
  40. package/ed25519.d.ts +52 -66
  41. package/ed25519.d.ts.map +1 -1
  42. package/ed25519.js +128 -155
  43. package/ed25519.js.map +1 -1
  44. package/ed448.d.ts +57 -58
  45. package/ed448.d.ts.map +1 -1
  46. package/ed448.js +114 -131
  47. package/ed448.js.map +1 -1
  48. package/esm/_shortw_utils.d.ts +1 -0
  49. package/esm/_shortw_utils.d.ts.map +1 -1
  50. package/esm/_shortw_utils.js +1 -0
  51. package/esm/_shortw_utils.js.map +1 -1
  52. package/esm/abstract/bls.d.ts +87 -62
  53. package/esm/abstract/bls.d.ts.map +1 -1
  54. package/esm/abstract/bls.js +171 -164
  55. package/esm/abstract/bls.js.map +1 -1
  56. package/esm/abstract/curve.d.ts +109 -23
  57. package/esm/abstract/curve.d.ts.map +1 -1
  58. package/esm/abstract/curve.js +156 -155
  59. package/esm/abstract/curve.js.map +1 -1
  60. package/esm/abstract/edwards.d.ts +126 -70
  61. package/esm/abstract/edwards.d.ts.map +1 -1
  62. package/esm/abstract/edwards.js +210 -62
  63. package/esm/abstract/edwards.js.map +1 -1
  64. package/esm/abstract/hash-to-curve.d.ts +8 -4
  65. package/esm/abstract/hash-to-curve.d.ts.map +1 -1
  66. package/esm/abstract/hash-to-curve.js +22 -11
  67. package/esm/abstract/hash-to-curve.js.map +1 -1
  68. package/esm/abstract/modular.d.ts +8 -3
  69. package/esm/abstract/modular.d.ts.map +1 -1
  70. package/esm/abstract/modular.js +79 -35
  71. package/esm/abstract/modular.js.map +1 -1
  72. package/esm/abstract/montgomery.d.ts +17 -4
  73. package/esm/abstract/montgomery.d.ts.map +1 -1
  74. package/esm/abstract/montgomery.js +19 -3
  75. package/esm/abstract/montgomery.js.map +1 -1
  76. package/esm/abstract/tower.d.ts +3 -3
  77. package/esm/abstract/tower.d.ts.map +1 -1
  78. package/esm/abstract/tower.js.map +1 -1
  79. package/esm/abstract/weierstrass.d.ts +145 -118
  80. package/esm/abstract/weierstrass.d.ts.map +1 -1
  81. package/esm/abstract/weierstrass.js +412 -334
  82. package/esm/abstract/weierstrass.js.map +1 -1
  83. package/esm/bls12-381.d.ts.map +1 -1
  84. package/esm/bls12-381.js +4 -4
  85. package/esm/bls12-381.js.map +1 -1
  86. package/esm/ed25519.d.ts +52 -66
  87. package/esm/ed25519.d.ts.map +1 -1
  88. package/esm/ed25519.js +131 -157
  89. package/esm/ed25519.js.map +1 -1
  90. package/esm/ed448.d.ts +57 -58
  91. package/esm/ed448.d.ts.map +1 -1
  92. package/esm/ed448.js +116 -132
  93. package/esm/ed448.js.map +1 -1
  94. package/esm/index.js +7 -9
  95. package/esm/index.js.map +1 -1
  96. package/esm/jubjub.d.ts +3 -3
  97. package/esm/jubjub.d.ts.map +1 -1
  98. package/esm/jubjub.js +3 -3
  99. package/esm/jubjub.js.map +1 -1
  100. package/esm/misc.d.ts +3 -5
  101. package/esm/misc.d.ts.map +1 -1
  102. package/esm/misc.js +0 -3
  103. package/esm/misc.js.map +1 -1
  104. package/esm/nist.d.ts +0 -6
  105. package/esm/nist.d.ts.map +1 -1
  106. package/esm/nist.js +31 -15
  107. package/esm/nist.js.map +1 -1
  108. package/esm/p256.d.ts +4 -0
  109. package/esm/p256.d.ts.map +1 -1
  110. package/esm/p256.js +4 -0
  111. package/esm/p256.js.map +1 -1
  112. package/esm/p384.d.ts +4 -1
  113. package/esm/p384.d.ts.map +1 -1
  114. package/esm/p384.js +4 -1
  115. package/esm/p384.js.map +1 -1
  116. package/esm/p521.d.ts +4 -0
  117. package/esm/p521.d.ts.map +1 -1
  118. package/esm/p521.js +4 -0
  119. package/esm/p521.js.map +1 -1
  120. package/esm/secp256k1.d.ts +32 -15
  121. package/esm/secp256k1.d.ts.map +1 -1
  122. package/esm/secp256k1.js +72 -67
  123. package/esm/secp256k1.js.map +1 -1
  124. package/esm/utils.d.ts +1 -1
  125. package/esm/utils.js +1 -1
  126. package/index.js +7 -9
  127. package/index.js.map +1 -1
  128. package/jubjub.d.ts +3 -3
  129. package/jubjub.d.ts.map +1 -1
  130. package/jubjub.js +3 -3
  131. package/jubjub.js.map +1 -1
  132. package/misc.d.ts +3 -5
  133. package/misc.d.ts.map +1 -1
  134. package/misc.js +0 -3
  135. package/misc.js.map +1 -1
  136. package/nist.d.ts +0 -6
  137. package/nist.d.ts.map +1 -1
  138. package/nist.js +31 -15
  139. package/nist.js.map +1 -1
  140. package/p256.d.ts +4 -0
  141. package/p256.d.ts.map +1 -1
  142. package/p256.js +4 -0
  143. package/p256.js.map +1 -1
  144. package/p384.d.ts +4 -1
  145. package/p384.d.ts.map +1 -1
  146. package/p384.js +4 -1
  147. package/p384.js.map +1 -1
  148. package/p521.d.ts +4 -0
  149. package/p521.d.ts.map +1 -1
  150. package/p521.js +4 -0
  151. package/p521.js.map +1 -1
  152. package/package.json +4 -2
  153. package/secp256k1.d.ts +32 -15
  154. package/secp256k1.d.ts.map +1 -1
  155. package/secp256k1.js +70 -65
  156. package/secp256k1.js.map +1 -1
  157. package/src/_shortw_utils.ts +1 -0
  158. package/src/abstract/bls.ts +319 -257
  159. package/src/abstract/curve.ts +226 -170
  160. package/src/abstract/edwards.ts +352 -139
  161. package/src/abstract/hash-to-curve.ts +33 -16
  162. package/src/abstract/modular.ts +86 -35
  163. package/src/abstract/montgomery.ts +36 -9
  164. package/src/abstract/tower.ts +4 -4
  165. package/src/abstract/weierstrass.ts +570 -476
  166. package/src/bls12-381.ts +28 -20
  167. package/src/ed25519.ts +161 -179
  168. package/src/ed448.ts +150 -156
  169. package/src/index.ts +7 -9
  170. package/src/jubjub.ts +3 -3
  171. package/src/misc.ts +3 -7
  172. package/src/nist.ts +40 -16
  173. package/src/p256.ts +4 -0
  174. package/src/p384.ts +4 -2
  175. package/src/p521.ts +4 -0
  176. package/src/secp256k1.ts +91 -73
  177. package/src/utils.ts +1 -1
  178. package/utils.d.ts +1 -1
  179. package/utils.js +1 -1
package/ed448.d.ts CHANGED
@@ -1,41 +1,40 @@
1
- import type { AffinePoint, Group } from './abstract/curve.ts';
2
- import { type CurveFn, type ExtPointConstructor, type ExtPointType } from './abstract/edwards.ts';
3
- import { type H2CHasher, type H2CMethod, type htfBasicOpts } from './abstract/hash-to-curve.ts';
4
- import { type CurveFn as XCurveFn } from './abstract/montgomery.ts';
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';
4
+ import { type IField } from './abstract/modular.ts';
5
+ import { type MontgomeryECDH as XCurveFn } from './abstract/montgomery.ts';
5
6
  import { type Hex } from './utils.ts';
6
- export declare const E448: ExtPointConstructor;
7
7
  /**
8
8
  * ed448 EdDSA curve and methods.
9
9
  * @example
10
10
  * import { ed448 } from '@noble/curves/ed448';
11
- * const priv = ed448.utils.randomPrivateKey();
12
- * const pub = ed448.getPublicKey(priv);
13
- * const msg = new TextEncoder().encode('whatsup');
14
- * const sig = ed448.sign(msg, priv);
15
- * ed448.verify(sig, msg, pub);
11
+ * const { secretKey, publicKey } = ed448.keygen();
12
+ * const msg = new TextEncoder().encode('hello');
13
+ * const sig = ed448.sign(msg, secretKey);
14
+ * const isValid = ed448.verify(sig, msg, publicKey);
16
15
  */
17
16
  export declare const ed448: CurveFn;
17
+ /** Prehashed version of ed448. Accepts already-hashed messages in sign() and verify(). */
18
18
  export declare const ed448ph: CurveFn;
19
+ /**
20
+ * E448 curve, defined by NIST.
21
+ * E448 != edwards448 used in ed448.
22
+ * E448 is birationally equivalent to edwards448.
23
+ */
24
+ export declare const E448: EdwardsPointCons;
19
25
  /**
20
26
  * ECDH using curve448 aka x448.
21
27
  * x448 has 56-byte keys as per RFC 7748, while
22
28
  * ed448 has 57-byte keys as per RFC 8032.
23
29
  */
24
30
  export declare const x448: XCurveFn;
25
- /**
26
- * Converts edwards448 public key to x448 public key. Uses formula:
27
- * * `(u, v) = ((y-1)/(y+1), sqrt(156324)*u/x)`
28
- * * `(x, y) = (sqrt(156324)*u/v, (1+u)/(1-u))`
29
- * @example
30
- * const aPub = ed448.getPublicKey(utils.randomPrivateKey());
31
- * x448.getSharedSecret(edwardsToMontgomery(aPub), edwardsToMontgomery(someonesPub))
32
- */
31
+ /** @deprecated use `ed448.utils.toMontgomery` */
33
32
  export declare function edwardsToMontgomeryPub(edwardsPub: string | Uint8Array): Uint8Array;
33
+ /** @deprecated use `ed448.utils.toMontgomery` */
34
34
  export declare const edwardsToMontgomery: typeof edwardsToMontgomeryPub;
35
+ /** Hashing / encoding to ed448 points / field. RFC 9380 methods. */
35
36
  export declare const ed448_hasher: H2CHasher<bigint>;
36
- export declare const hashToCurve: H2CMethod<bigint>;
37
- export declare const encodeToCurve: H2CMethod<bigint>;
38
- type ExtendedPoint = ExtPointType;
37
+ type ExtendedPoint = EdwardsPoint;
39
38
  /**
40
39
  * Each ed448/ExtendedPoint has 4 different equivalent points. This can be
41
40
  * a source of bugs for protocols like ring signatures. Decaf was created to solve this.
@@ -43,60 +42,60 @@ type ExtendedPoint = ExtPointType;
43
42
  * but it should work in its own namespace: do not combine those two.
44
43
  * See [RFC9496](https://www.rfc-editor.org/rfc/rfc9496).
45
44
  */
46
- declare class DcfPoint implements Group<DcfPoint> {
47
- static BASE: DcfPoint;
48
- static ZERO: DcfPoint;
49
- private readonly ep;
45
+ declare class _DecafPoint extends PrimeEdwardsPoint<_DecafPoint> {
46
+ static BASE: _DecafPoint;
47
+ static ZERO: _DecafPoint;
48
+ static Fp: IField<bigint>;
49
+ static Fn: IField<bigint>;
50
50
  constructor(ep: ExtendedPoint);
51
- static fromAffine(ap: AffinePoint<bigint>): DcfPoint;
52
- /**
53
- * Takes uniform output of 112-byte hash function like shake256 and converts it to `DecafPoint`.
54
- * The hash-to-group operation applies Elligator twice and adds the results.
55
- * **Note:** this is one-way map, there is no conversion from point to hash.
56
- * Described in [RFC9380](https://www.rfc-editor.org/rfc/rfc9380#appendix-C)
57
- * and [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-element-derivation-2).
58
- * @param hex 112-byte output of a hash function
59
- */
60
- static hashToCurve(hex: Hex): DcfPoint;
61
- static fromBytes(bytes: Uint8Array): DcfPoint;
51
+ static fromAffine(ap: AffinePoint<bigint>): _DecafPoint;
52
+ protected assertSame(other: _DecafPoint): void;
53
+ protected init(ep: EdwardsPoint): _DecafPoint;
54
+ /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
55
+ static hashToCurve(hex: Hex): _DecafPoint;
56
+ static fromBytes(bytes: Uint8Array): _DecafPoint;
62
57
  /**
63
58
  * Converts decaf-encoded string to decaf point.
64
59
  * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode-2).
65
60
  * @param hex Decaf-encoded 56 bytes. Not every 56-byte string is valid decaf encoding
66
61
  */
67
- static fromHex(hex: Hex): DcfPoint;
68
- static msm(points: DcfPoint[], scalars: bigint[]): DcfPoint;
62
+ static fromHex(hex: Hex): _DecafPoint;
63
+ /** @deprecated use `import { pippenger } from '@noble/curves/abstract/curve.js';` */
64
+ static msm(points: _DecafPoint[], scalars: bigint[]): _DecafPoint;
69
65
  /**
70
66
  * Encodes decaf point to Uint8Array.
71
67
  * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-encode-2).
72
68
  */
73
69
  toBytes(): Uint8Array;
74
- /** @deprecated use `toBytes` */
75
- toRawBytes(): Uint8Array;
76
- toHex(): string;
77
- toString(): string;
78
70
  /**
79
71
  * Compare one point to another.
80
72
  * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-equals-2).
81
73
  */
82
- equals(other: DcfPoint): boolean;
83
- add(other: DcfPoint): DcfPoint;
84
- subtract(other: DcfPoint): DcfPoint;
85
- multiply(scalar: bigint): DcfPoint;
86
- multiplyUnsafe(scalar: bigint): DcfPoint;
87
- double(): DcfPoint;
88
- negate(): DcfPoint;
74
+ equals(other: _DecafPoint): boolean;
75
+ is0(): boolean;
89
76
  }
77
+ /** @deprecated use `decaf448.Point` */
78
+ export declare const DecafPoint: typeof _DecafPoint;
79
+ export declare const decaf448: {
80
+ Point: typeof _DecafPoint;
81
+ };
82
+ /** Hashing to decaf448 points / field. RFC 9380 methods. */
83
+ export declare const decaf448_hasher: H2CHasherBase<bigint>;
84
+ type DcfHasher = (msg: Uint8Array, options: htfBasicOpts) => _DecafPoint;
85
+ /** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
86
+ export declare const hashToCurve: H2CMethod<bigint>;
87
+ /** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
88
+ export declare const encodeToCurve: H2CMethod<bigint>;
89
+ /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
90
+ export declare const hashToDecaf448: DcfHasher;
91
+ /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
92
+ export declare const hash_to_decaf448: DcfHasher;
90
93
  /**
91
- * Wrapper over Edwards Point for decaf448 from
92
- * [RFC9496](https://www.rfc-editor.org/rfc/rfc9496).
93
- */
94
- export declare const DecafPoint: typeof DcfPoint;
95
- /**
96
- * hash-to-curve for decaf448.
97
- * Described in [RFC9380](https://www.rfc-editor.org/rfc/rfc9380#appendix-C).
94
+ * Weird / bogus points, useful for debugging.
95
+ * Unlike ed25519, there is no ed448 generator point which can produce full T subgroup.
96
+ * Instead, there is a Klein four-group, which spans over 2 independent 2-torsion points:
97
+ * (0, 1), (0, -1), (-1, 0), (1, 0).
98
98
  */
99
- export declare const hashToDecaf448: (msg: Uint8Array, options: htfBasicOpts) => DcfPoint;
100
- export declare const hash_to_decaf448: typeof hashToDecaf448;
99
+ export declare const ED448_TORSION_SUBGROUP: string[];
101
100
  export {};
102
101
  //# 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":"AAgBA,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE9D,OAAO,EACL,K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Decaf448 = exports.DecafPoint = exports.encodeToCurve = exports.hashToCurve = exports.ed448_hasher = exports.edwardsToMontgomery = exports.x448 = exports.ed448ph = exports.ed448 = exports.E448 = void 0;
3
+ exports.ED448_TORSION_SUBGROUP = exports.hash_to_decaf448 = exports.hashToDecaf448 = exports.encodeToCurve = exports.hashToCurve = exports.decaf448_hasher = exports.decaf448 = exports.DecafPoint = exports.ed448_hasher = exports.edwardsToMontgomery = exports.x448 = exports.E448 = exports.ed448ph = exports.ed448 = void 0;
4
4
  exports.edwardsToMontgomeryPub = edwardsToMontgomeryPub;
5
5
  /**
6
6
  * Edwards448 (not Ed448-Goldilocks) curve with following addons:
@@ -19,6 +19,7 @@ const hash_to_curve_ts_1 = require("./abstract/hash-to-curve.js");
19
19
  const modular_ts_1 = require("./abstract/modular.js");
20
20
  const montgomery_ts_1 = require("./abstract/montgomery.js");
21
21
  const utils_ts_1 = require("./utils.js");
22
+ // edwards448 curve
22
23
  // a = 1n
23
24
  // d = Fp.neg(39081n)
24
25
  // Finite field 2n**448n - 2n**224n - 1n
@@ -33,9 +34,7 @@ const ed448_CURVE = {
33
34
  Gx: BigInt('0x4f1970c66bed0ded221d15a622bf36da9e146570470f1767ea6de324a3d3a46412ae1af72ab66511433b80e18b00938e2626a82bc70cc05e'),
34
35
  Gy: BigInt('0x693f46716eb6bc248876203756c9c7624bea73736ca3984087789c1e05a0c2d73ad3ff1ce67c39c4fdbd132c4ed7c8ad9808795bf230fa14'),
35
36
  };
36
- // E448 != Edwards448 used in ed448
37
- // E448 is defined by NIST
38
- // It's birationally equivalent to edwards448
37
+ // E448 NIST curve is identical to edwards448, except for:
39
38
  // d = 39082/39081
40
39
  // Gx = 3/2
41
40
  const E448_CURVE = Object.assign({}, ed448_CURVE, {
@@ -43,7 +42,6 @@ const E448_CURVE = Object.assign({}, ed448_CURVE, {
43
42
  Gx: BigInt('0x79a70b2b70400553ae7c9df416c792c61128751ac92969240c25a07d728bdc93e21f7787ed6972249de732f38496cd11698713093e9c04fc'),
44
43
  Gy: BigInt('0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff80000000000000000000000000000000000000000000000000000001'),
45
44
  });
46
- exports.E448 = (0, edwards_ts_1.edwards)(E448_CURVE);
47
45
  const shake256_114 = /* @__PURE__ */ (0, utils_js_1.createHasher)(() => sha3_js_1.shake256.create({ dkLen: 114 }));
48
46
  const shake256_64 = /* @__PURE__ */ (0, utils_js_1.createHasher)(() => sha3_js_1.shake256.create({ dkLen: 64 }));
49
47
  // prettier-ignore
@@ -101,13 +99,15 @@ function uvRatio(u, v) {
101
99
  return { isValid: (0, modular_ts_1.mod)(x2 * v, P) === u, value: x };
102
100
  }
103
101
  // Finite field 2n**448n - 2n**224n - 1n
104
- const Fp = /* @__PURE__ */ (() => (0, modular_ts_1.Field)(ed448_CURVE.p, 456, true))();
102
+ const Fp = /* @__PURE__ */ (() => (0, modular_ts_1.Field)(ed448_CURVE.p, { BITS: 456, isLE: true }))();
105
103
  // RFC 7748 has 56-byte keys, RFC 8032 has 57-byte keys
104
+ const Fn = /* @__PURE__ */ (() => (0, modular_ts_1.Field)(ed448_CURVE.n, { BITS: 448, isLE: true }))();
105
+ // const Fn456 = /* @__PURE__ */ (() => Field(ed448_CURVE.n, { BITS: 456, isLE: true }))();
106
106
  // SHAKE256(dom4(phflag,context)||x, 114)
107
107
  const ED448_DEF = /* @__PURE__ */ (() => ({
108
108
  ...ed448_CURVE,
109
109
  Fp,
110
- nBitLength: 456,
110
+ Fn,
111
111
  hash: shake256_114,
112
112
  adjustScalarBytes,
113
113
  // dom4
@@ -122,18 +122,24 @@ const ED448_DEF = /* @__PURE__ */ (() => ({
122
122
  * ed448 EdDSA curve and methods.
123
123
  * @example
124
124
  * import { ed448 } from '@noble/curves/ed448';
125
- * const priv = ed448.utils.randomPrivateKey();
126
- * const pub = ed448.getPublicKey(priv);
127
- * const msg = new TextEncoder().encode('whatsup');
128
- * const sig = ed448.sign(msg, priv);
129
- * ed448.verify(sig, msg, pub);
125
+ * const { secretKey, publicKey } = ed448.keygen();
126
+ * const msg = new TextEncoder().encode('hello');
127
+ * const sig = ed448.sign(msg, secretKey);
128
+ * const isValid = ed448.verify(sig, msg, publicKey);
130
129
  */
131
130
  exports.ed448 = (0, edwards_ts_1.twistedEdwards)(ED448_DEF);
132
- // NOTE: there is no ed448ctx, since ed448 supports ctx by default
131
+ // There is no ed448ctx, since ed448 supports ctx by default
132
+ /** Prehashed version of ed448. Accepts already-hashed messages in sign() and verify(). */
133
133
  exports.ed448ph = (() => (0, edwards_ts_1.twistedEdwards)({
134
134
  ...ED448_DEF,
135
135
  prehash: shake256_64,
136
136
  }))();
137
+ /**
138
+ * E448 curve, defined by NIST.
139
+ * E448 != edwards448 used in ed448.
140
+ * E448 is birationally equivalent to edwards448.
141
+ */
142
+ exports.E448 = (0, edwards_ts_1.edwards)(E448_CURVE);
137
143
  /**
138
144
  * ECDH using curve448 aka x448.
139
145
  * x448 has 56-byte keys as per RFC 7748, while
@@ -152,22 +158,12 @@ exports.x448 = (() => {
152
158
  adjustScalarBytes,
153
159
  });
154
160
  })();
155
- /**
156
- * Converts edwards448 public key to x448 public key. Uses formula:
157
- * * `(u, v) = ((y-1)/(y+1), sqrt(156324)*u/x)`
158
- * * `(x, y) = (sqrt(156324)*u/v, (1+u)/(1-u))`
159
- * @example
160
- * const aPub = ed448.getPublicKey(utils.randomPrivateKey());
161
- * x448.getSharedSecret(edwardsToMontgomery(aPub), edwardsToMontgomery(someonesPub))
162
- */
161
+ /** @deprecated use `ed448.utils.toMontgomery` */
163
162
  function edwardsToMontgomeryPub(edwardsPub) {
164
- const bpub = (0, utils_ts_1.ensureBytes)('pub', edwardsPub);
165
- const { y } = exports.ed448.Point.fromHex(bpub);
166
- const _1n = BigInt(1);
167
- return Fp.toBytes(Fp.create((y - _1n) * Fp.inv(y + _1n)));
163
+ return exports.ed448.utils.toMontgomery((0, utils_ts_1.ensureBytes)('pub', edwardsPub));
168
164
  }
169
- exports.edwardsToMontgomery = edwardsToMontgomeryPub; // deprecated
170
- // TODO: add edwardsToMontgomeryPriv, similar to ed25519 version
165
+ /** @deprecated use `ed448.utils.toMontgomery` */
166
+ exports.edwardsToMontgomery = edwardsToMontgomeryPub;
171
167
  // Hash To Curve Elligator2 Map
172
168
  const ELL2_C1 = /* @__PURE__ */ (() => (Fp.ORDER - BigInt(3)) / BigInt(4))(); // 1. c1 = (q - 3) / 4 # Integer arithmetic
173
169
  const ELL2_J = /* @__PURE__ */ BigInt(156326);
@@ -241,6 +237,7 @@ function map_to_curve_elligator2_edwards448(u) {
241
237
  const inv = (0, modular_ts_1.FpInvertBatch)(Fp, [xEd, yEd], true); // batch division
242
238
  return { x: Fp.mul(xEn, inv[0]), y: Fp.mul(yEn, inv[1]) }; // 38. return (xEn, xEd, yEn, yEd)
243
239
  }
240
+ /** Hashing / encoding to ed448 points / field. RFC 9380 methods. */
244
241
  exports.ed448_hasher = (() => (0, hash_to_curve_ts_1.createHasher)(exports.ed448.Point, (scalars) => map_to_curve_elligator2_edwards448(scalars[0]), {
245
242
  DST: 'edwards448_XOF:SHAKE256_ELL2_RO_',
246
243
  encodeDST: 'edwards448_XOF:SHAKE256_ELL2_NU_',
@@ -250,12 +247,6 @@ exports.ed448_hasher = (() => (0, hash_to_curve_ts_1.createHasher)(exports.ed448
250
247
  expand: 'xof',
251
248
  hash: sha3_js_1.shake256,
252
249
  }))();
253
- exports.hashToCurve = (() => exports.ed448_hasher.hashToCurve)();
254
- exports.encodeToCurve = (() => exports.ed448_hasher.encodeToCurve)();
255
- function adecafp(other) {
256
- if (!(other instanceof DcfPoint))
257
- throw new Error('DecafPoint expected');
258
- }
259
250
  // 1-d
260
251
  const ONE_MINUS_D = /* @__PURE__ */ BigInt('39082');
261
252
  // 1-2d
@@ -298,6 +289,14 @@ function calcElligatorDecafMap(r0) {
298
289
  const W3 = mod(v_prime * s * (r - _1n) * ONE_MINUS_TWO_D + sgn); // 11
299
290
  return new exports.ed448.Point(mod(W0 * W3), mod(W2 * W1), mod(W1 * W3), mod(W0 * W2));
300
291
  }
292
+ function decaf448_map(bytes) {
293
+ (0, utils_js_1.abytes)(bytes, 112);
294
+ const r1 = bytes448ToNumberLE(bytes.slice(0, 56));
295
+ const R1 = calcElligatorDecafMap(r1);
296
+ const r2 = bytes448ToNumberLE(bytes.slice(56, 112));
297
+ const R2 = calcElligatorDecafMap(r2);
298
+ return new _DecafPoint(R1.add(R2));
299
+ }
301
300
  /**
302
301
  * Each ed448/ExtendedPoint has 4 different equivalent points. This can be
303
302
  * a source of bugs for protocols like ring signatures. Decaf was created to solve this.
@@ -305,51 +304,34 @@ function calcElligatorDecafMap(r0) {
305
304
  * but it should work in its own namespace: do not combine those two.
306
305
  * See [RFC9496](https://www.rfc-editor.org/rfc/rfc9496).
307
306
  */
308
- class DcfPoint {
309
- // Private property to discourage combining ExtendedPoint + DecafPoint
310
- // Always use Decaf encoding/decoding instead.
307
+ class _DecafPoint extends edwards_ts_1.PrimeEdwardsPoint {
311
308
  constructor(ep) {
312
- this.ep = ep;
309
+ super(ep);
313
310
  }
314
311
  static fromAffine(ap) {
315
- return new DcfPoint(exports.ed448.Point.fromAffine(ap));
312
+ return new _DecafPoint(exports.ed448.Point.fromAffine(ap));
316
313
  }
317
- /**
318
- * Takes uniform output of 112-byte hash function like shake256 and converts it to `DecafPoint`.
319
- * The hash-to-group operation applies Elligator twice and adds the results.
320
- * **Note:** this is one-way map, there is no conversion from point to hash.
321
- * Described in [RFC9380](https://www.rfc-editor.org/rfc/rfc9380#appendix-C)
322
- * and [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-element-derivation-2).
323
- * @param hex 112-byte output of a hash function
324
- */
314
+ assertSame(other) {
315
+ if (!(other instanceof _DecafPoint))
316
+ throw new Error('DecafPoint expected');
317
+ }
318
+ init(ep) {
319
+ return new _DecafPoint(ep);
320
+ }
321
+ /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
325
322
  static hashToCurve(hex) {
326
- hex = (0, utils_ts_1.ensureBytes)('decafHash', hex, 112);
327
- const r1 = bytes448ToNumberLE(hex.slice(0, 56));
328
- const R1 = calcElligatorDecafMap(r1);
329
- const r2 = bytes448ToNumberLE(hex.slice(56, 112));
330
- const R2 = calcElligatorDecafMap(r2);
331
- return new DcfPoint(R1.add(R2));
323
+ return decaf448_map((0, utils_ts_1.ensureBytes)('decafHash', hex, 112));
332
324
  }
333
325
  static fromBytes(bytes) {
334
- (0, utils_js_1.abytes)(bytes);
335
- return this.fromHex(bytes);
336
- }
337
- /**
338
- * Converts decaf-encoded string to decaf point.
339
- * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode-2).
340
- * @param hex Decaf-encoded 56 bytes. Not every 56-byte string is valid decaf encoding
341
- */
342
- static fromHex(hex) {
343
- hex = (0, utils_ts_1.ensureBytes)('decafHex', hex, 56);
326
+ (0, utils_js_1.abytes)(bytes, 56);
344
327
  const { d } = exports.ed448.CURVE;
345
328
  const P = Fp.ORDER;
346
329
  const mod = Fp.create;
347
- const emsg = 'DecafPoint.fromHex: the hex is not valid encoding of DecafPoint';
348
- const s = bytes448ToNumberLE(hex);
330
+ const s = bytes448ToNumberLE(bytes);
349
331
  // 1. Check that s_bytes is the canonical encoding of a field element, or else abort.
350
332
  // 2. Check that s is non-negative, or else abort
351
- if (!(0, utils_ts_1.equalBytes)((0, utils_ts_1.numberToBytesLE)(s, 56), hex) || (0, modular_ts_1.isNegativeLE)(s, P))
352
- throw new Error(emsg);
333
+ if (!(0, utils_ts_1.equalBytes)((0, utils_ts_1.numberToBytesLE)(s, 56), bytes) || (0, modular_ts_1.isNegativeLE)(s, P))
334
+ throw new Error('invalid decaf448 encoding 1');
353
335
  const s2 = mod(s * s); // 1
354
336
  const u1 = mod(_1n + s2); // 2
355
337
  const u1sq = mod(u1 * u1);
@@ -362,100 +344,101 @@ class DcfPoint {
362
344
  const y = mod((_1n - s2) * invsqrt * u1); // 7
363
345
  const t = mod(x * y); // 8
364
346
  if (!isValid)
365
- throw new Error(emsg);
366
- return new DcfPoint(new exports.ed448.Point(x, y, _1n, t));
347
+ throw new Error('invalid decaf448 encoding 2');
348
+ return new _DecafPoint(new exports.ed448.Point(x, y, _1n, t));
349
+ }
350
+ /**
351
+ * Converts decaf-encoded string to decaf point.
352
+ * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode-2).
353
+ * @param hex Decaf-encoded 56 bytes. Not every 56-byte string is valid decaf encoding
354
+ */
355
+ static fromHex(hex) {
356
+ return _DecafPoint.fromBytes((0, utils_ts_1.ensureBytes)('decafHex', hex, 56));
367
357
  }
358
+ /** @deprecated use `import { pippenger } from '@noble/curves/abstract/curve.js';` */
368
359
  static msm(points, scalars) {
369
- const Fn = (0, modular_ts_1.Field)(exports.ed448.CURVE.n, exports.ed448.CURVE.nBitLength);
370
- return (0, curve_ts_1.pippenger)(DcfPoint, Fn, points, scalars);
360
+ return (0, curve_ts_1.pippenger)(_DecafPoint, Fn, points, scalars);
371
361
  }
372
362
  /**
373
363
  * Encodes decaf point to Uint8Array.
374
364
  * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-encode-2).
375
365
  */
376
366
  toBytes() {
377
- let { ex: x, ey: _y, ez: z, et: t } = this.ep;
367
+ const { X, Z, T } = this.ep;
378
368
  const P = Fp.ORDER;
379
369
  const mod = Fp.create;
380
- const u1 = mod(mod(x + t) * mod(x - t)); // 1
381
- const x2 = mod(x * x);
370
+ const u1 = mod(mod(X + T) * mod(X - T)); // 1
371
+ const x2 = mod(X * X);
382
372
  const { value: invsqrt } = invertSqrt(mod(u1 * ONE_MINUS_D * x2)); // 2
383
373
  let ratio = mod(invsqrt * u1 * SQRT_MINUS_D); // 3
384
374
  if ((0, modular_ts_1.isNegativeLE)(ratio, P))
385
375
  ratio = mod(-ratio);
386
- const u2 = mod(INVSQRT_MINUS_D * ratio * z - t); // 4
387
- let s = mod(ONE_MINUS_D * invsqrt * x * u2); // 5
376
+ const u2 = mod(INVSQRT_MINUS_D * ratio * Z - T); // 4
377
+ let s = mod(ONE_MINUS_D * invsqrt * X * u2); // 5
388
378
  if ((0, modular_ts_1.isNegativeLE)(s, P))
389
379
  s = mod(-s);
390
380
  return (0, utils_ts_1.numberToBytesLE)(s, 56);
391
381
  }
392
- /** @deprecated use `toBytes` */
393
- toRawBytes() {
394
- return this.toBytes();
395
- }
396
- toHex() {
397
- return (0, utils_ts_1.bytesToHex)(this.toBytes());
398
- }
399
- toString() {
400
- return this.toHex();
401
- }
402
382
  /**
403
383
  * Compare one point to another.
404
384
  * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-equals-2).
405
385
  */
406
386
  equals(other) {
407
- adecafp(other);
408
- const { ex: X1, ey: Y1 } = this.ep;
409
- const { ex: X2, ey: Y2 } = other.ep;
387
+ this.assertSame(other);
388
+ const { X: X1, Y: Y1 } = this.ep;
389
+ const { X: X2, Y: Y2 } = other.ep;
410
390
  const mod = Fp.create;
411
391
  // (x1 * y2 == y1 * x2)
412
392
  return mod(X1 * Y2) === mod(Y1 * X2);
413
393
  }
414
- add(other) {
415
- adecafp(other);
416
- return new DcfPoint(this.ep.add(other.ep));
417
- }
418
- subtract(other) {
419
- adecafp(other);
420
- return new DcfPoint(this.ep.subtract(other.ep));
421
- }
422
- multiply(scalar) {
423
- return new DcfPoint(this.ep.multiply(scalar));
424
- }
425
- multiplyUnsafe(scalar) {
426
- return new DcfPoint(this.ep.multiplyUnsafe(scalar));
427
- }
428
- double() {
429
- return new DcfPoint(this.ep.double());
430
- }
431
- negate() {
432
- return new DcfPoint(this.ep.negate());
394
+ is0() {
395
+ return this.equals(_DecafPoint.ZERO);
433
396
  }
434
397
  }
398
+ // The following gymnastics is done because typescript strips comments otherwise
399
+ // prettier-ignore
400
+ _DecafPoint.BASE =
401
+ /* @__PURE__ */ (() => new _DecafPoint(exports.ed448.Point.BASE).multiplyUnsafe(_2n))();
402
+ // prettier-ignore
403
+ _DecafPoint.ZERO =
404
+ /* @__PURE__ */ (() => new _DecafPoint(exports.ed448.Point.ZERO))();
405
+ // prettier-ignore
406
+ _DecafPoint.Fp =
407
+ /* @__PURE__ */ Fp;
408
+ // prettier-ignore
409
+ _DecafPoint.Fn =
410
+ /* @__PURE__ */ Fn;
411
+ /** @deprecated use `decaf448.Point` */
412
+ exports.DecafPoint = _DecafPoint;
413
+ exports.decaf448 = { Point: _DecafPoint };
414
+ /** Hashing to decaf448 points / field. RFC 9380 methods. */
415
+ exports.decaf448_hasher = {
416
+ hashToCurve(msg, options) {
417
+ const DST = options?.DST || 'decaf448_XOF:SHAKE256_D448MAP_RO_';
418
+ return decaf448_map((0, hash_to_curve_ts_1.expand_message_xof)(msg, DST, 112, 224, sha3_js_1.shake256));
419
+ },
420
+ hashToScalar(msg, options = { DST: hash_to_curve_ts_1._DST_scalar }) {
421
+ return Fn.create((0, utils_ts_1.bytesToNumberLE)((0, hash_to_curve_ts_1.expand_message_xof)(msg, options.DST, 64, 256, sha3_js_1.shake256)));
422
+ },
423
+ };
424
+ /** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
425
+ exports.hashToCurve = (() => exports.ed448_hasher.hashToCurve)();
426
+ /** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
427
+ exports.encodeToCurve = (() => exports.ed448_hasher.encodeToCurve)();
428
+ /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
429
+ exports.hashToDecaf448 = (() => exports.decaf448_hasher.hashToCurve)();
430
+ /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
431
+ exports.hash_to_decaf448 = (() => exports.decaf448_hasher.hashToCurve)();
435
432
  /**
436
- * Wrapper over Edwards Point for decaf448 from
437
- * [RFC9496](https://www.rfc-editor.org/rfc/rfc9496).
438
- */
439
- exports.DecafPoint = (() => {
440
- // decaf448 base point is ed448 base x 2
441
- // https://github.com/dalek-cryptography/curve25519-dalek/blob/59837c6ecff02b77b9d5ff84dbc239d0cf33ef90/vendor/ristretto.sage#L699
442
- if (!DcfPoint.BASE)
443
- DcfPoint.BASE = new DcfPoint(exports.ed448.Point.BASE).multiply(_2n);
444
- if (!DcfPoint.ZERO)
445
- DcfPoint.ZERO = new DcfPoint(exports.ed448.Point.ZERO);
446
- return DcfPoint;
447
- })();
448
- /**
449
- * hash-to-curve for decaf448.
450
- * Described in [RFC9380](https://www.rfc-editor.org/rfc/rfc9380#appendix-C).
433
+ * Weird / bogus points, useful for debugging.
434
+ * Unlike ed25519, there is no ed448 generator point which can produce full T subgroup.
435
+ * Instead, there is a Klein four-group, which spans over 2 independent 2-torsion points:
436
+ * (0, 1), (0, -1), (-1, 0), (1, 0).
451
437
  */
452
- const hashToDecaf448 = (msg, options) => {
453
- const d = options.DST;
454
- const DST = typeof d === 'string' ? (0, utils_js_1.utf8ToBytes)(d) : d;
455
- const uniform_bytes = (0, hash_to_curve_ts_1.expand_message_xof)(msg, DST, 112, 224, sha3_js_1.shake256);
456
- const P = DcfPoint.hashToCurve(uniform_bytes);
457
- return P;
458
- };
459
- exports.hashToDecaf448 = hashToDecaf448;
460
- exports.hash_to_decaf448 = exports.hashToDecaf448; // legacy
438
+ exports.ED448_TORSION_SUBGROUP = [
439
+ '010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
440
+ 'fefffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffff00',
441
+ '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
442
+ '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080',
443
+ ];
461
444
  //# sourceMappingURL=ed448.js.map