@noble/curves 1.9.5 → 2.0.0-beta.1

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 (211) hide show
  1. package/README.md +267 -421
  2. package/abstract/bls.d.ts +49 -111
  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 +7 -48
  7. package/abstract/curve.d.ts.map +1 -1
  8. package/abstract/curve.js +22 -47
  9. package/abstract/curve.js.map +1 -1
  10. package/abstract/edwards.d.ts +17 -68
  11. package/abstract/edwards.d.ts.map +1 -1
  12. package/abstract/edwards.js +98 -175
  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 +11 -24
  17. package/abstract/hash-to-curve.d.ts.map +1 -1
  18. package/abstract/hash-to-curve.js +30 -35
  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 +166 -167
  23. package/abstract/modular.js.map +1 -1
  24. package/abstract/montgomery.d.ts +4 -9
  25. package/abstract/montgomery.d.ts.map +1 -1
  26. package/abstract/montgomery.js +17 -20
  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.js +20 -24
  33. package/abstract/poseidon.js.map +1 -1
  34. package/abstract/tower.d.ts +9 -7
  35. package/abstract/tower.d.ts.map +1 -1
  36. package/abstract/tower.js +600 -364
  37. package/abstract/tower.js.map +1 -1
  38. package/abstract/weierstrass.d.ts +12 -145
  39. package/abstract/weierstrass.d.ts.map +1 -1
  40. package/abstract/weierstrass.js +153 -377
  41. package/abstract/weierstrass.js.map +1 -1
  42. package/bls12-381.d.ts +2 -2
  43. package/bls12-381.d.ts.map +1 -1
  44. package/bls12-381.js +174 -216
  45. package/bls12-381.js.map +1 -1
  46. package/bn254.d.ts +58 -10
  47. package/bn254.d.ts.map +1 -1
  48. package/bn254.js +70 -130
  49. package/bn254.js.map +1 -1
  50. package/ed25519.d.ts +12 -31
  51. package/ed25519.d.ts.map +1 -1
  52. package/ed25519.js +104 -146
  53. package/ed25519.js.map +1 -1
  54. package/ed448.d.ts +14 -33
  55. package/ed448.d.ts.map +1 -1
  56. package/ed448.js +105 -132
  57. package/ed448.js.map +1 -1
  58. package/index.js +1 -1
  59. package/misc.d.ts +10 -14
  60. package/misc.d.ts.map +1 -1
  61. package/misc.js +51 -60
  62. package/misc.js.map +1 -1
  63. package/nist.d.ts +11 -14
  64. package/nist.d.ts.map +1 -1
  65. package/nist.js +46 -55
  66. package/nist.js.map +1 -1
  67. package/package.json +9 -224
  68. package/secp256k1.d.ts +7 -23
  69. package/secp256k1.d.ts.map +1 -1
  70. package/secp256k1.js +72 -83
  71. package/secp256k1.js.map +1 -1
  72. package/src/abstract/bls.ts +197 -344
  73. package/src/abstract/curve.ts +10 -83
  74. package/src/abstract/edwards.ts +96 -223
  75. package/src/abstract/hash-to-curve.ts +32 -45
  76. package/src/abstract/modular.ts +144 -130
  77. package/src/abstract/montgomery.ts +21 -22
  78. package/src/abstract/oprf.ts +600 -0
  79. package/src/abstract/tower.ts +627 -382
  80. package/src/abstract/weierstrass.ts +101 -482
  81. package/src/bls12-381.ts +148 -176
  82. package/src/bn254.ts +67 -122
  83. package/src/ed25519.ts +65 -118
  84. package/src/ed448.ts +63 -113
  85. package/src/index.ts +1 -1
  86. package/src/misc.ts +66 -49
  87. package/src/nist.ts +48 -57
  88. package/src/secp256k1.ts +56 -88
  89. package/src/utils.ts +41 -61
  90. package/src/webcrypto.ts +362 -0
  91. package/utils.d.ts +28 -19
  92. package/utils.d.ts.map +1 -1
  93. package/utils.js +45 -121
  94. package/utils.js.map +1 -1
  95. package/webcrypto.d.ts +47 -0
  96. package/webcrypto.d.ts.map +1 -0
  97. package/webcrypto.js +231 -0
  98. package/webcrypto.js.map +1 -0
  99. package/esm/_shortw_utils.d.ts +0 -19
  100. package/esm/_shortw_utils.d.ts.map +0 -1
  101. package/esm/_shortw_utils.js +0 -16
  102. package/esm/_shortw_utils.js.map +0 -1
  103. package/esm/abstract/bls.d.ts +0 -190
  104. package/esm/abstract/bls.d.ts.map +0 -1
  105. package/esm/abstract/bls.js +0 -408
  106. package/esm/abstract/bls.js.map +0 -1
  107. package/esm/abstract/curve.d.ts +0 -231
  108. package/esm/abstract/curve.d.ts.map +0 -1
  109. package/esm/abstract/curve.js +0 -465
  110. package/esm/abstract/curve.js.map +0 -1
  111. package/esm/abstract/edwards.d.ts +0 -237
  112. package/esm/abstract/edwards.d.ts.map +0 -1
  113. package/esm/abstract/edwards.js +0 -632
  114. package/esm/abstract/edwards.js.map +0 -1
  115. package/esm/abstract/fft.d.ts +0 -122
  116. package/esm/abstract/fft.d.ts.map +0 -1
  117. package/esm/abstract/fft.js +0 -425
  118. package/esm/abstract/fft.js.map +0 -1
  119. package/esm/abstract/hash-to-curve.d.ts +0 -102
  120. package/esm/abstract/hash-to-curve.d.ts.map +0 -1
  121. package/esm/abstract/hash-to-curve.js +0 -203
  122. package/esm/abstract/hash-to-curve.js.map +0 -1
  123. package/esm/abstract/modular.d.ts +0 -171
  124. package/esm/abstract/modular.d.ts.map +0 -1
  125. package/esm/abstract/modular.js +0 -530
  126. package/esm/abstract/modular.js.map +0 -1
  127. package/esm/abstract/montgomery.d.ts +0 -30
  128. package/esm/abstract/montgomery.d.ts.map +0 -1
  129. package/esm/abstract/montgomery.js +0 -157
  130. package/esm/abstract/montgomery.js.map +0 -1
  131. package/esm/abstract/poseidon.d.ts +0 -68
  132. package/esm/abstract/poseidon.d.ts.map +0 -1
  133. package/esm/abstract/poseidon.js +0 -296
  134. package/esm/abstract/poseidon.js.map +0 -1
  135. package/esm/abstract/tower.d.ts +0 -93
  136. package/esm/abstract/tower.d.ts.map +0 -1
  137. package/esm/abstract/tower.js +0 -502
  138. package/esm/abstract/tower.js.map +0 -1
  139. package/esm/abstract/utils.d.ts +0 -5
  140. package/esm/abstract/utils.d.ts.map +0 -1
  141. package/esm/abstract/utils.js +0 -7
  142. package/esm/abstract/utils.js.map +0 -1
  143. package/esm/abstract/weierstrass.d.ts +0 -412
  144. package/esm/abstract/weierstrass.d.ts.map +0 -1
  145. package/esm/abstract/weierstrass.js +0 -1428
  146. package/esm/abstract/weierstrass.js.map +0 -1
  147. package/esm/bls12-381.d.ts +0 -16
  148. package/esm/bls12-381.d.ts.map +0 -1
  149. package/esm/bls12-381.js +0 -738
  150. package/esm/bls12-381.js.map +0 -1
  151. package/esm/bn254.d.ts +0 -18
  152. package/esm/bn254.d.ts.map +0 -1
  153. package/esm/bn254.js +0 -246
  154. package/esm/bn254.js.map +0 -1
  155. package/esm/ed25519.d.ts +0 -106
  156. package/esm/ed25519.d.ts.map +0 -1
  157. package/esm/ed25519.js +0 -467
  158. package/esm/ed25519.js.map +0 -1
  159. package/esm/ed448.d.ts +0 -101
  160. package/esm/ed448.d.ts.map +0 -1
  161. package/esm/ed448.js +0 -448
  162. package/esm/ed448.js.map +0 -1
  163. package/esm/index.d.ts +0 -2
  164. package/esm/index.d.ts.map +0 -1
  165. package/esm/index.js +0 -17
  166. package/esm/index.js.map +0 -1
  167. package/esm/jubjub.d.ts +0 -12
  168. package/esm/jubjub.d.ts.map +0 -1
  169. package/esm/jubjub.js +0 -12
  170. package/esm/jubjub.js.map +0 -1
  171. package/esm/misc.d.ts +0 -19
  172. package/esm/misc.d.ts.map +0 -1
  173. package/esm/misc.js +0 -109
  174. package/esm/misc.js.map +0 -1
  175. package/esm/nist.d.ts +0 -21
  176. package/esm/nist.d.ts.map +0 -1
  177. package/esm/nist.js +0 -132
  178. package/esm/nist.js.map +0 -1
  179. package/esm/p256.d.ts +0 -16
  180. package/esm/p256.d.ts.map +0 -1
  181. package/esm/p256.js +0 -16
  182. package/esm/p256.js.map +0 -1
  183. package/esm/p384.d.ts +0 -16
  184. package/esm/p384.d.ts.map +0 -1
  185. package/esm/p384.js +0 -16
  186. package/esm/p384.js.map +0 -1
  187. package/esm/p521.d.ts +0 -16
  188. package/esm/p521.d.ts.map +0 -1
  189. package/esm/p521.js +0 -16
  190. package/esm/p521.js.map +0 -1
  191. package/esm/package.json +0 -4
  192. package/esm/pasta.d.ts +0 -10
  193. package/esm/pasta.d.ts.map +0 -1
  194. package/esm/pasta.js +0 -10
  195. package/esm/pasta.js.map +0 -1
  196. package/esm/secp256k1.d.ts +0 -89
  197. package/esm/secp256k1.d.ts.map +0 -1
  198. package/esm/secp256k1.js +0 -292
  199. package/esm/secp256k1.js.map +0 -1
  200. package/esm/utils.d.ts +0 -110
  201. package/esm/utils.d.ts.map +0 -1
  202. package/esm/utils.js +0 -322
  203. package/esm/utils.js.map +0 -1
  204. package/src/_shortw_utils.ts +0 -21
  205. package/src/abstract/utils.ts +0 -7
  206. package/src/jubjub.ts +0 -12
  207. package/src/p256.ts +0 -15
  208. package/src/p384.ts +0 -15
  209. package/src/p521.ts +0 -15
  210. package/src/package.json +0 -3
  211. package/src/pasta.ts +0 -9
@@ -4,8 +4,8 @@
4
4
  * @module
5
5
  */
6
6
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
7
- import { bitLen, bitMask, validateObject } from '../utils.ts';
8
- import { Field, FpInvertBatch, nLength, validateField, type IField } from './modular.ts';
7
+ import { bitLen, bitMask } from '../utils.ts';
8
+ import { Field, FpInvertBatch, validateField, type IField } from './modular.ts';
9
9
 
10
10
  const _0n = BigInt(0);
11
11
  const _1n = BigInt(1);
@@ -15,18 +15,6 @@ export type AffinePoint<T> = {
15
15
  y: T;
16
16
  } & { Z?: never };
17
17
 
18
- // This was initialy do this way to re-use montgomery ladder in field (add->mul,double->sqr), but
19
- // that didn't happen and there is probably not much reason to have separate Group like this?
20
- export interface Group<T extends Group<T>> {
21
- double(): T;
22
- negate(): T;
23
- add(other: T): T;
24
- subtract(other: T): T;
25
- equals(other: T): boolean;
26
- multiply(scalar: bigint): T;
27
- toAffine?(invertedZ?: any): AffinePoint<any>;
28
- }
29
-
30
18
  // We can't "abstract out" coordinates (X, Y, Z; and T in Edwards): argument names of constructor
31
19
  // are not accessible. See Typescript gh-56093, gh-41594.
32
20
  //
@@ -36,7 +24,7 @@ export interface Group<T extends Group<T>> {
36
24
  // but we lose all constrains on methods.
37
25
 
38
26
  /** Base interface for all elliptic curve Points. */
39
- export interface CurvePoint<F, P extends CurvePoint<F, P>> extends Group<P> {
27
+ export interface CurvePoint<F, P extends CurvePoint<F, P>> {
40
28
  /** Affine x coordinate. Different from projective / extended X coordinate. */
41
29
  x: F;
42
30
  /** Affine y coordinate. Different from projective / extended Y coordinate. */
@@ -77,7 +65,7 @@ export interface CurvePointCons<P extends CurvePoint<any, P>> {
77
65
  /** Creates point from x, y. Does NOT validate if the point is valid. Use `.assertValidity()`. */
78
66
  fromAffine(p: AffinePoint<P_F<P>>): P;
79
67
  fromBytes(bytes: Uint8Array): P;
80
- fromHex(hex: Uint8Array | string): P;
68
+ fromHex(hex: string): P;
81
69
  }
82
70
 
83
71
  // Type inference helpers: PC - PointConstructor, P - Point, Fp - Field element
@@ -127,23 +115,14 @@ export type PC_ANY = CurvePointCons<
127
115
  >;
128
116
 
129
117
  export interface CurveLengths {
130
- secret?: number;
131
- public?: number;
132
- publicUncompressed?: number;
118
+ secretKey?: number;
119
+ publicKey?: number;
120
+ publicKeyUncompressed?: number;
133
121
  publicKeyHasPrefix?: boolean;
134
122
  signature?: number;
135
123
  seed?: number;
136
124
  }
137
- export type GroupConstructor<T> = {
138
- BASE: T;
139
- ZERO: T;
140
- };
141
- /** @deprecated */
142
- export type ExtendedGroupConstructor<T> = GroupConstructor<T> & {
143
- Fp: IField<any>;
144
- Fn: IField<bigint>;
145
- fromAffine(ap: AffinePoint<any>): T;
146
- };
125
+
147
126
  export type Mapper<T> = (i: T[]) => T[];
148
127
 
149
128
  export function negateCt<T extends { negate: () => T }>(condition: boolean, item: T): T {
@@ -464,7 +443,6 @@ export function mulEndoUnsafe<P extends CurvePoint<any, P>, PC extends CurvePoin
464
443
  */
465
444
  export function pippenger<P extends CurvePoint<any, P>, PC extends CurvePointCons<P>>(
466
445
  c: PC,
467
- fieldN: IField<bigint>,
468
446
  points: P[],
469
447
  scalars: bigint[]
470
448
  ): P {
@@ -474,6 +452,7 @@ export function pippenger<P extends CurvePoint<any, P>, PC extends CurvePointCon
474
452
  // - https://eprint.iacr.org/2024/750.pdf
475
453
  // - https://tches.iacr.org/index.php/TCHES/article/view/10287
476
454
  // 0 is accepted in scalars
455
+ const fieldN = c.Fn;
477
456
  validateMSMPoints(points, c);
478
457
  validateMSMScalars(scalars, fieldN);
479
458
  const plength = points.length;
@@ -517,7 +496,6 @@ export function pippenger<P extends CurvePoint<any, P>, PC extends CurvePointCon
517
496
  */
518
497
  export function precomputeMSMUnsafe<P extends CurvePoint<any, P>, PC extends CurvePointCons<P>>(
519
498
  c: PC,
520
- fieldN: IField<bigint>,
521
499
  points: P[],
522
500
  windowSize: number
523
501
  ): (scalars: bigint[]) => P {
@@ -556,6 +534,7 @@ export function precomputeMSMUnsafe<P extends CurvePoint<any, P>, PC extends Cur
556
534
  * - Optimal for ~256 scalars
557
535
  * - Less efficient for 4096+ scalars (Pippenger preferred)
558
536
  */
537
+ const fieldN = c.Fn;
559
538
  validateW(windowSize, fieldN.BITS);
560
539
  validateMSMPoints(points, c);
561
540
  const zero = c.ZERO;
@@ -590,58 +569,6 @@ export function precomputeMSMUnsafe<P extends CurvePoint<any, P>, PC extends Cur
590
569
  };
591
570
  }
592
571
 
593
- // TODO: remove
594
- /**
595
- * Generic BasicCurve interface: works even for polynomial fields (BLS): P, n, h would be ok.
596
- * Though generator can be different (Fp2 / Fp6 for BLS).
597
- */
598
- export type BasicCurve<T> = {
599
- Fp: IField<T>; // Field over which we'll do calculations (Fp)
600
- n: bigint; // Curve order, total count of valid points in the field
601
- nBitLength?: number; // bit length of curve order
602
- nByteLength?: number; // byte length of curve order
603
- h: bigint; // cofactor. we can assign default=1, but users will just ignore it w/o validation
604
- hEff?: bigint; // Number to multiply to clear cofactor
605
- Gx: T; // base point X coordinate
606
- Gy: T; // base point Y coordinate
607
- allowInfinityPoint?: boolean; // bls12-381 requires it. ZERO point is valid, but invalid pubkey
608
- };
609
-
610
- // TODO: remove
611
- /** @deprecated */
612
- export function validateBasic<FP, T>(
613
- curve: BasicCurve<FP> & T
614
- ): Readonly<
615
- {
616
- readonly nBitLength: number;
617
- readonly nByteLength: number;
618
- } & BasicCurve<FP> &
619
- T & {
620
- p: bigint;
621
- }
622
- > {
623
- validateField(curve.Fp);
624
- validateObject(
625
- curve,
626
- {
627
- n: 'bigint',
628
- h: 'bigint',
629
- Gx: 'field',
630
- Gy: 'field',
631
- },
632
- {
633
- nBitLength: 'isSafeInteger',
634
- nByteLength: 'isSafeInteger',
635
- }
636
- );
637
- // Set defaults
638
- return Object.freeze({
639
- ...nLength(curve.n, curve.nBitLength),
640
- ...curve,
641
- ...{ p: curve.Fp.ORDER },
642
- } as const);
643
- }
644
-
645
572
  export type ValidCurveParams<T> = {
646
573
  p: bigint;
647
574
  n: bigint;