@noble/curves 1.9.2 → 1.9.3

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 +124 -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 +142 -116
  34. package/abstract/weierstrass.d.ts.map +1 -1
  35. package/abstract/weierstrass.js +414 -335
  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 +124 -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 +142 -116
  80. package/esm/abstract/weierstrass.d.ts.map +1 -1
  81. package/esm/abstract/weierstrass.js +411 -333
  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 +350 -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 +567 -474
  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/esm/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
@@ -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,KAAK,OAAO,EAGZ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I7C,kFAAkF;IAClF,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,WAAW;IAIzC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW;IA8BhD;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,WAAW;IAIrC,qFAAqF;IACrF,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,WAAW;IAIjE;;;OAGG;IACH,OAAO,IAAI,UAAU;IAoBrB;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO;IASnC,GAAG,IAAI,OAAO;CAGf;AAED,uCAAuC;AACvC,eAAO,MAAM,UAAU,EAAE,OAAO,WAAyB,CAAC;AAC1D,eAAO,MAAM,QAAQ,EAAE;IACrB,KAAK,EAAE,OAAO,WAAW,CAAC;CACF,CAAC;AAE3B,4DAA4D;AAC5D,eAAO,MAAM,eAAe,EAAE,aAAa,CAAC,MAAM,CAQjD,CAAC;AAUF,KAAK,SAAS,GAAG,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,KAAK,WAAW,CAAC;AAEzE,+EAA+E;AAC/E,eAAO,MAAM,WAAW,EAAE,SAAS,CAAC,MAAM,CAAsD,CAAC;AACjG,+EAA+E;AAC/E,eAAO,MAAM,aAAa,EAAE,SAAS,CAAC,MAAM,CACb,CAAC;AAChC,kFAAkF;AAClF,eAAO,MAAM,cAAc,EAAE,SACgB,CAAC;AAC9C,kFAAkF;AAClF,eAAO,MAAM,gBAAgB,EAAE,SACc,CAAC;AAE9C;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,EAK1C,CAAC"}
package/esm/ed448.js CHANGED
@@ -10,11 +10,12 @@
10
10
  import { shake256 } from '@noble/hashes/sha3.js';
11
11
  import { abytes, concatBytes, utf8ToBytes, createHasher as wrapConstructor, } from '@noble/hashes/utils.js';
12
12
  import { pippenger } from "./abstract/curve.js";
13
- import { edwards, twistedEdwards, } from "./abstract/edwards.js";
14
- import { createHasher, expand_message_xof, } from "./abstract/hash-to-curve.js";
13
+ import { edwards, PrimeEdwardsPoint, twistedEdwards, } from "./abstract/edwards.js";
14
+ import { _DST_scalar, createHasher, expand_message_xof, } from "./abstract/hash-to-curve.js";
15
15
  import { Field, FpInvertBatch, isNegativeLE, mod, pow2 } from "./abstract/modular.js";
16
16
  import { montgomery } from "./abstract/montgomery.js";
17
- import { bytesToHex, bytesToNumberLE, ensureBytes, equalBytes, numberToBytesLE, } from "./utils.js";
17
+ import { bytesToNumberLE, ensureBytes, equalBytes, numberToBytesLE } from "./utils.js";
18
+ // edwards448 curve
18
19
  // a = 1n
19
20
  // d = Fp.neg(39081n)
20
21
  // Finite field 2n**448n - 2n**224n - 1n
@@ -29,9 +30,7 @@ const ed448_CURVE = {
29
30
  Gx: BigInt('0x4f1970c66bed0ded221d15a622bf36da9e146570470f1767ea6de324a3d3a46412ae1af72ab66511433b80e18b00938e2626a82bc70cc05e'),
30
31
  Gy: BigInt('0x693f46716eb6bc248876203756c9c7624bea73736ca3984087789c1e05a0c2d73ad3ff1ce67c39c4fdbd132c4ed7c8ad9808795bf230fa14'),
31
32
  };
32
- // E448 != Edwards448 used in ed448
33
- // E448 is defined by NIST
34
- // It's birationally equivalent to edwards448
33
+ // E448 NIST curve is identical to edwards448, except for:
35
34
  // d = 39082/39081
36
35
  // Gx = 3/2
37
36
  const E448_CURVE = Object.assign({}, ed448_CURVE, {
@@ -39,7 +38,6 @@ const E448_CURVE = Object.assign({}, ed448_CURVE, {
39
38
  Gx: BigInt('0x79a70b2b70400553ae7c9df416c792c61128751ac92969240c25a07d728bdc93e21f7787ed6972249de732f38496cd11698713093e9c04fc'),
40
39
  Gy: BigInt('0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff80000000000000000000000000000000000000000000000000000001'),
41
40
  });
42
- export const E448 = edwards(E448_CURVE);
43
41
  const shake256_114 = /* @__PURE__ */ wrapConstructor(() => shake256.create({ dkLen: 114 }));
44
42
  const shake256_64 = /* @__PURE__ */ wrapConstructor(() => shake256.create({ dkLen: 64 }));
45
43
  // prettier-ignore
@@ -97,13 +95,15 @@ function uvRatio(u, v) {
97
95
  return { isValid: mod(x2 * v, P) === u, value: x };
98
96
  }
99
97
  // Finite field 2n**448n - 2n**224n - 1n
100
- const Fp = /* @__PURE__ */ (() => Field(ed448_CURVE.p, 456, true))();
98
+ const Fp = /* @__PURE__ */ (() => Field(ed448_CURVE.p, { BITS: 456, isLE: true }))();
101
99
  // RFC 7748 has 56-byte keys, RFC 8032 has 57-byte keys
100
+ const Fn = /* @__PURE__ */ (() => Field(ed448_CURVE.n, { BITS: 448, isLE: true }))();
101
+ // const Fn456 = /* @__PURE__ */ (() => Field(ed448_CURVE.n, { BITS: 456, isLE: true }))();
102
102
  // SHAKE256(dom4(phflag,context)||x, 114)
103
103
  const ED448_DEF = /* @__PURE__ */ (() => ({
104
104
  ...ed448_CURVE,
105
105
  Fp,
106
- nBitLength: 456,
106
+ Fn,
107
107
  hash: shake256_114,
108
108
  adjustScalarBytes,
109
109
  // dom4
@@ -118,18 +118,24 @@ const ED448_DEF = /* @__PURE__ */ (() => ({
118
118
  * ed448 EdDSA curve and methods.
119
119
  * @example
120
120
  * import { ed448 } from '@noble/curves/ed448';
121
- * const priv = ed448.utils.randomPrivateKey();
122
- * const pub = ed448.getPublicKey(priv);
123
- * const msg = new TextEncoder().encode('whatsup');
124
- * const sig = ed448.sign(msg, priv);
125
- * ed448.verify(sig, msg, pub);
121
+ * const { secretKey, publicKey } = ed448.keygen();
122
+ * const msg = new TextEncoder().encode('hello');
123
+ * const sig = ed448.sign(msg, secretKey);
124
+ * const isValid = ed448.verify(sig, msg, publicKey);
126
125
  */
127
126
  export const ed448 = twistedEdwards(ED448_DEF);
128
- // NOTE: there is no ed448ctx, since ed448 supports ctx by default
127
+ // There is no ed448ctx, since ed448 supports ctx by default
128
+ /** Prehashed version of ed448. Accepts already-hashed messages in sign() and verify(). */
129
129
  export const ed448ph = /* @__PURE__ */ (() => twistedEdwards({
130
130
  ...ED448_DEF,
131
131
  prehash: shake256_64,
132
132
  }))();
133
+ /**
134
+ * E448 curve, defined by NIST.
135
+ * E448 != edwards448 used in ed448.
136
+ * E448 is birationally equivalent to edwards448.
137
+ */
138
+ export const E448 = edwards(E448_CURVE);
133
139
  /**
134
140
  * ECDH using curve448 aka x448.
135
141
  * x448 has 56-byte keys as per RFC 7748, while
@@ -148,22 +154,12 @@ export const x448 = /* @__PURE__ */ (() => {
148
154
  adjustScalarBytes,
149
155
  });
150
156
  })();
151
- /**
152
- * Converts edwards448 public key to x448 public key. Uses formula:
153
- * * `(u, v) = ((y-1)/(y+1), sqrt(156324)*u/x)`
154
- * * `(x, y) = (sqrt(156324)*u/v, (1+u)/(1-u))`
155
- * @example
156
- * const aPub = ed448.getPublicKey(utils.randomPrivateKey());
157
- * x448.getSharedSecret(edwardsToMontgomery(aPub), edwardsToMontgomery(someonesPub))
158
- */
157
+ /** @deprecated use `ed448.utils.toMontgomery` */
159
158
  export function edwardsToMontgomeryPub(edwardsPub) {
160
- const bpub = ensureBytes('pub', edwardsPub);
161
- const { y } = ed448.Point.fromHex(bpub);
162
- const _1n = BigInt(1);
163
- return Fp.toBytes(Fp.create((y - _1n) * Fp.inv(y + _1n)));
159
+ return ed448.utils.toMontgomery(ensureBytes('pub', edwardsPub));
164
160
  }
165
- export const edwardsToMontgomery = edwardsToMontgomeryPub; // deprecated
166
- // TODO: add edwardsToMontgomeryPriv, similar to ed25519 version
161
+ /** @deprecated use `ed448.utils.toMontgomery` */
162
+ export const edwardsToMontgomery = edwardsToMontgomeryPub;
167
163
  // Hash To Curve Elligator2 Map
168
164
  const ELL2_C1 = /* @__PURE__ */ (() => (Fp.ORDER - BigInt(3)) / BigInt(4))(); // 1. c1 = (q - 3) / 4 # Integer arithmetic
169
165
  const ELL2_J = /* @__PURE__ */ BigInt(156326);
@@ -237,6 +233,7 @@ function map_to_curve_elligator2_edwards448(u) {
237
233
  const inv = FpInvertBatch(Fp, [xEd, yEd], true); // batch division
238
234
  return { x: Fp.mul(xEn, inv[0]), y: Fp.mul(yEn, inv[1]) }; // 38. return (xEn, xEd, yEn, yEd)
239
235
  }
236
+ /** Hashing / encoding to ed448 points / field. RFC 9380 methods. */
240
237
  export const ed448_hasher = /* @__PURE__ */ (() => createHasher(ed448.Point, (scalars) => map_to_curve_elligator2_edwards448(scalars[0]), {
241
238
  DST: 'edwards448_XOF:SHAKE256_ELL2_RO_',
242
239
  encodeDST: 'edwards448_XOF:SHAKE256_ELL2_NU_',
@@ -246,12 +243,6 @@ export const ed448_hasher = /* @__PURE__ */ (() => createHasher(ed448.Point, (sc
246
243
  expand: 'xof',
247
244
  hash: shake256,
248
245
  }))();
249
- export const hashToCurve = /* @__PURE__ */ (() => ed448_hasher.hashToCurve)();
250
- export const encodeToCurve = /* @__PURE__ */ (() => ed448_hasher.encodeToCurve)();
251
- function adecafp(other) {
252
- if (!(other instanceof DcfPoint))
253
- throw new Error('DecafPoint expected');
254
- }
255
246
  // 1-d
256
247
  const ONE_MINUS_D = /* @__PURE__ */ BigInt('39082');
257
248
  // 1-2d
@@ -294,6 +285,14 @@ function calcElligatorDecafMap(r0) {
294
285
  const W3 = mod(v_prime * s * (r - _1n) * ONE_MINUS_TWO_D + sgn); // 11
295
286
  return new ed448.Point(mod(W0 * W3), mod(W2 * W1), mod(W1 * W3), mod(W0 * W2));
296
287
  }
288
+ function decaf448_map(bytes) {
289
+ abytes(bytes, 112);
290
+ const r1 = bytes448ToNumberLE(bytes.slice(0, 56));
291
+ const R1 = calcElligatorDecafMap(r1);
292
+ const r2 = bytes448ToNumberLE(bytes.slice(56, 112));
293
+ const R2 = calcElligatorDecafMap(r2);
294
+ return new _DecafPoint(R1.add(R2));
295
+ }
297
296
  /**
298
297
  * Each ed448/ExtendedPoint has 4 different equivalent points. This can be
299
298
  * a source of bugs for protocols like ring signatures. Decaf was created to solve this.
@@ -301,51 +300,34 @@ function calcElligatorDecafMap(r0) {
301
300
  * but it should work in its own namespace: do not combine those two.
302
301
  * See [RFC9496](https://www.rfc-editor.org/rfc/rfc9496).
303
302
  */
304
- class DcfPoint {
305
- // Private property to discourage combining ExtendedPoint + DecafPoint
306
- // Always use Decaf encoding/decoding instead.
303
+ class _DecafPoint extends PrimeEdwardsPoint {
307
304
  constructor(ep) {
308
- this.ep = ep;
305
+ super(ep);
309
306
  }
310
307
  static fromAffine(ap) {
311
- return new DcfPoint(ed448.Point.fromAffine(ap));
308
+ return new _DecafPoint(ed448.Point.fromAffine(ap));
312
309
  }
313
- /**
314
- * Takes uniform output of 112-byte hash function like shake256 and converts it to `DecafPoint`.
315
- * The hash-to-group operation applies Elligator twice and adds the results.
316
- * **Note:** this is one-way map, there is no conversion from point to hash.
317
- * Described in [RFC9380](https://www.rfc-editor.org/rfc/rfc9380#appendix-C)
318
- * and [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-element-derivation-2).
319
- * @param hex 112-byte output of a hash function
320
- */
310
+ assertSame(other) {
311
+ if (!(other instanceof _DecafPoint))
312
+ throw new Error('DecafPoint expected');
313
+ }
314
+ init(ep) {
315
+ return new _DecafPoint(ep);
316
+ }
317
+ /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
321
318
  static hashToCurve(hex) {
322
- hex = ensureBytes('decafHash', hex, 112);
323
- const r1 = bytes448ToNumberLE(hex.slice(0, 56));
324
- const R1 = calcElligatorDecafMap(r1);
325
- const r2 = bytes448ToNumberLE(hex.slice(56, 112));
326
- const R2 = calcElligatorDecafMap(r2);
327
- return new DcfPoint(R1.add(R2));
319
+ return decaf448_map(ensureBytes('decafHash', hex, 112));
328
320
  }
329
321
  static fromBytes(bytes) {
330
- abytes(bytes);
331
- return this.fromHex(bytes);
332
- }
333
- /**
334
- * Converts decaf-encoded string to decaf point.
335
- * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode-2).
336
- * @param hex Decaf-encoded 56 bytes. Not every 56-byte string is valid decaf encoding
337
- */
338
- static fromHex(hex) {
339
- hex = ensureBytes('decafHex', hex, 56);
322
+ abytes(bytes, 56);
340
323
  const { d } = ed448.CURVE;
341
324
  const P = Fp.ORDER;
342
325
  const mod = Fp.create;
343
- const emsg = 'DecafPoint.fromHex: the hex is not valid encoding of DecafPoint';
344
- const s = bytes448ToNumberLE(hex);
326
+ const s = bytes448ToNumberLE(bytes);
345
327
  // 1. Check that s_bytes is the canonical encoding of a field element, or else abort.
346
328
  // 2. Check that s is non-negative, or else abort
347
- if (!equalBytes(numberToBytesLE(s, 56), hex) || isNegativeLE(s, P))
348
- throw new Error(emsg);
329
+ if (!equalBytes(numberToBytesLE(s, 56), bytes) || isNegativeLE(s, P))
330
+ throw new Error('invalid decaf448 encoding 1');
349
331
  const s2 = mod(s * s); // 1
350
332
  const u1 = mod(_1n + s2); // 2
351
333
  const u1sq = mod(u1 * u1);
@@ -358,99 +340,101 @@ class DcfPoint {
358
340
  const y = mod((_1n - s2) * invsqrt * u1); // 7
359
341
  const t = mod(x * y); // 8
360
342
  if (!isValid)
361
- throw new Error(emsg);
362
- return new DcfPoint(new ed448.Point(x, y, _1n, t));
343
+ throw new Error('invalid decaf448 encoding 2');
344
+ return new _DecafPoint(new ed448.Point(x, y, _1n, t));
345
+ }
346
+ /**
347
+ * Converts decaf-encoded string to decaf point.
348
+ * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode-2).
349
+ * @param hex Decaf-encoded 56 bytes. Not every 56-byte string is valid decaf encoding
350
+ */
351
+ static fromHex(hex) {
352
+ return _DecafPoint.fromBytes(ensureBytes('decafHex', hex, 56));
363
353
  }
354
+ /** @deprecated use `import { pippenger } from '@noble/curves/abstract/curve.js';` */
364
355
  static msm(points, scalars) {
365
- const Fn = Field(ed448.CURVE.n, ed448.CURVE.nBitLength);
366
- return pippenger(DcfPoint, Fn, points, scalars);
356
+ return pippenger(_DecafPoint, Fn, points, scalars);
367
357
  }
368
358
  /**
369
359
  * Encodes decaf point to Uint8Array.
370
360
  * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-encode-2).
371
361
  */
372
362
  toBytes() {
373
- let { ex: x, ey: _y, ez: z, et: t } = this.ep;
363
+ const { X, Z, T } = this.ep;
374
364
  const P = Fp.ORDER;
375
365
  const mod = Fp.create;
376
- const u1 = mod(mod(x + t) * mod(x - t)); // 1
377
- const x2 = mod(x * x);
366
+ const u1 = mod(mod(X + T) * mod(X - T)); // 1
367
+ const x2 = mod(X * X);
378
368
  const { value: invsqrt } = invertSqrt(mod(u1 * ONE_MINUS_D * x2)); // 2
379
369
  let ratio = mod(invsqrt * u1 * SQRT_MINUS_D); // 3
380
370
  if (isNegativeLE(ratio, P))
381
371
  ratio = mod(-ratio);
382
- const u2 = mod(INVSQRT_MINUS_D * ratio * z - t); // 4
383
- let s = mod(ONE_MINUS_D * invsqrt * x * u2); // 5
372
+ const u2 = mod(INVSQRT_MINUS_D * ratio * Z - T); // 4
373
+ let s = mod(ONE_MINUS_D * invsqrt * X * u2); // 5
384
374
  if (isNegativeLE(s, P))
385
375
  s = mod(-s);
386
376
  return numberToBytesLE(s, 56);
387
377
  }
388
- /** @deprecated use `toBytes` */
389
- toRawBytes() {
390
- return this.toBytes();
391
- }
392
- toHex() {
393
- return bytesToHex(this.toBytes());
394
- }
395
- toString() {
396
- return this.toHex();
397
- }
398
378
  /**
399
379
  * Compare one point to another.
400
380
  * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-equals-2).
401
381
  */
402
382
  equals(other) {
403
- adecafp(other);
404
- const { ex: X1, ey: Y1 } = this.ep;
405
- const { ex: X2, ey: Y2 } = other.ep;
383
+ this.assertSame(other);
384
+ const { X: X1, Y: Y1 } = this.ep;
385
+ const { X: X2, Y: Y2 } = other.ep;
406
386
  const mod = Fp.create;
407
387
  // (x1 * y2 == y1 * x2)
408
388
  return mod(X1 * Y2) === mod(Y1 * X2);
409
389
  }
410
- add(other) {
411
- adecafp(other);
412
- return new DcfPoint(this.ep.add(other.ep));
413
- }
414
- subtract(other) {
415
- adecafp(other);
416
- return new DcfPoint(this.ep.subtract(other.ep));
417
- }
418
- multiply(scalar) {
419
- return new DcfPoint(this.ep.multiply(scalar));
420
- }
421
- multiplyUnsafe(scalar) {
422
- return new DcfPoint(this.ep.multiplyUnsafe(scalar));
423
- }
424
- double() {
425
- return new DcfPoint(this.ep.double());
426
- }
427
- negate() {
428
- return new DcfPoint(this.ep.negate());
390
+ is0() {
391
+ return this.equals(_DecafPoint.ZERO);
429
392
  }
430
393
  }
394
+ // The following gymnastics is done because typescript strips comments otherwise
395
+ // prettier-ignore
396
+ _DecafPoint.BASE =
397
+ /* @__PURE__ */ (() => new _DecafPoint(ed448.Point.BASE).multiplyUnsafe(_2n))();
398
+ // prettier-ignore
399
+ _DecafPoint.ZERO =
400
+ /* @__PURE__ */ (() => new _DecafPoint(ed448.Point.ZERO))();
401
+ // prettier-ignore
402
+ _DecafPoint.Fp =
403
+ /* @__PURE__ */ Fp;
404
+ // prettier-ignore
405
+ _DecafPoint.Fn =
406
+ /* @__PURE__ */ Fn;
407
+ /** @deprecated use `decaf448.Point` */
408
+ export const DecafPoint = _DecafPoint;
409
+ export const decaf448 = { Point: _DecafPoint };
410
+ /** Hashing to decaf448 points / field. RFC 9380 methods. */
411
+ export const decaf448_hasher = {
412
+ hashToCurve(msg, options) {
413
+ const DST = options?.DST || 'decaf448_XOF:SHAKE256_D448MAP_RO_';
414
+ return decaf448_map(expand_message_xof(msg, DST, 112, 224, shake256));
415
+ },
416
+ hashToScalar(msg, options = { DST: _DST_scalar }) {
417
+ return Fn.create(bytesToNumberLE(expand_message_xof(msg, options.DST, 64, 256, shake256)));
418
+ },
419
+ };
420
+ /** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
421
+ export const hashToCurve = /* @__PURE__ */ (() => ed448_hasher.hashToCurve)();
422
+ /** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
423
+ export const encodeToCurve = /* @__PURE__ */ (() => ed448_hasher.encodeToCurve)();
424
+ /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
425
+ export const hashToDecaf448 = /* @__PURE__ */ (() => decaf448_hasher.hashToCurve)();
426
+ /** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
427
+ export const hash_to_decaf448 = /* @__PURE__ */ (() => decaf448_hasher.hashToCurve)();
431
428
  /**
432
- * Wrapper over Edwards Point for decaf448 from
433
- * [RFC9496](https://www.rfc-editor.org/rfc/rfc9496).
434
- */
435
- export const DecafPoint = /* @__PURE__ */ (() => {
436
- // decaf448 base point is ed448 base x 2
437
- // https://github.com/dalek-cryptography/curve25519-dalek/blob/59837c6ecff02b77b9d5ff84dbc239d0cf33ef90/vendor/ristretto.sage#L699
438
- if (!DcfPoint.BASE)
439
- DcfPoint.BASE = new DcfPoint(ed448.Point.BASE).multiply(_2n);
440
- if (!DcfPoint.ZERO)
441
- DcfPoint.ZERO = new DcfPoint(ed448.Point.ZERO);
442
- return DcfPoint;
443
- })();
444
- /**
445
- * hash-to-curve for decaf448.
446
- * Described in [RFC9380](https://www.rfc-editor.org/rfc/rfc9380#appendix-C).
429
+ * Weird / bogus points, useful for debugging.
430
+ * Unlike ed25519, there is no ed448 generator point which can produce full T subgroup.
431
+ * Instead, there is a Klein four-group, which spans over 2 independent 2-torsion points:
432
+ * (0, 1), (0, -1), (-1, 0), (1, 0).
447
433
  */
448
- export const hashToDecaf448 = (msg, options) => {
449
- const d = options.DST;
450
- const DST = typeof d === 'string' ? utf8ToBytes(d) : d;
451
- const uniform_bytes = expand_message_xof(msg, DST, 112, 224, shake256);
452
- const P = DcfPoint.hashToCurve(uniform_bytes);
453
- return P;
454
- };
455
- export const hash_to_decaf448 = hashToDecaf448; // legacy
434
+ export const ED448_TORSION_SUBGROUP = [
435
+ '010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
436
+ 'fefffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffff00',
437
+ '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
438
+ '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080',
439
+ ];
456
440
  //# sourceMappingURL=ed448.js.map