@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.
- package/README.md +267 -421
- package/abstract/bls.d.ts +49 -111
- package/abstract/bls.d.ts.map +1 -1
- package/abstract/bls.js +108 -152
- package/abstract/bls.js.map +1 -1
- package/abstract/curve.d.ts +7 -48
- package/abstract/curve.d.ts.map +1 -1
- package/abstract/curve.js +22 -47
- package/abstract/curve.js.map +1 -1
- package/abstract/edwards.d.ts +17 -68
- package/abstract/edwards.d.ts.map +1 -1
- package/abstract/edwards.js +98 -175
- package/abstract/edwards.js.map +1 -1
- package/abstract/fft.js +14 -27
- package/abstract/fft.js.map +1 -1
- package/abstract/hash-to-curve.d.ts +11 -24
- package/abstract/hash-to-curve.d.ts.map +1 -1
- package/abstract/hash-to-curve.js +30 -35
- package/abstract/hash-to-curve.js.map +1 -1
- package/abstract/modular.d.ts +5 -17
- package/abstract/modular.d.ts.map +1 -1
- package/abstract/modular.js +166 -167
- package/abstract/modular.js.map +1 -1
- package/abstract/montgomery.d.ts +4 -9
- package/abstract/montgomery.d.ts.map +1 -1
- package/abstract/montgomery.js +17 -20
- package/abstract/montgomery.js.map +1 -1
- package/abstract/oprf.d.ts +282 -0
- package/abstract/oprf.d.ts.map +1 -0
- package/abstract/oprf.js +297 -0
- package/abstract/oprf.js.map +1 -0
- package/abstract/poseidon.js +20 -24
- package/abstract/poseidon.js.map +1 -1
- package/abstract/tower.d.ts +9 -7
- package/abstract/tower.d.ts.map +1 -1
- package/abstract/tower.js +600 -364
- package/abstract/tower.js.map +1 -1
- package/abstract/weierstrass.d.ts +12 -145
- package/abstract/weierstrass.d.ts.map +1 -1
- package/abstract/weierstrass.js +153 -377
- package/abstract/weierstrass.js.map +1 -1
- package/bls12-381.d.ts +2 -2
- package/bls12-381.d.ts.map +1 -1
- package/bls12-381.js +174 -216
- package/bls12-381.js.map +1 -1
- package/bn254.d.ts +58 -10
- package/bn254.d.ts.map +1 -1
- package/bn254.js +70 -130
- package/bn254.js.map +1 -1
- package/ed25519.d.ts +12 -31
- package/ed25519.d.ts.map +1 -1
- package/ed25519.js +104 -146
- package/ed25519.js.map +1 -1
- package/ed448.d.ts +14 -33
- package/ed448.d.ts.map +1 -1
- package/ed448.js +105 -132
- package/ed448.js.map +1 -1
- package/index.js +1 -1
- package/misc.d.ts +10 -14
- package/misc.d.ts.map +1 -1
- package/misc.js +51 -60
- package/misc.js.map +1 -1
- package/nist.d.ts +11 -14
- package/nist.d.ts.map +1 -1
- package/nist.js +46 -55
- package/nist.js.map +1 -1
- package/package.json +9 -224
- package/secp256k1.d.ts +7 -23
- package/secp256k1.d.ts.map +1 -1
- package/secp256k1.js +72 -83
- package/secp256k1.js.map +1 -1
- package/src/abstract/bls.ts +197 -344
- package/src/abstract/curve.ts +10 -83
- package/src/abstract/edwards.ts +96 -223
- package/src/abstract/hash-to-curve.ts +32 -45
- package/src/abstract/modular.ts +144 -130
- package/src/abstract/montgomery.ts +21 -22
- package/src/abstract/oprf.ts +600 -0
- package/src/abstract/tower.ts +627 -382
- package/src/abstract/weierstrass.ts +101 -482
- package/src/bls12-381.ts +148 -176
- package/src/bn254.ts +67 -122
- package/src/ed25519.ts +65 -118
- package/src/ed448.ts +63 -113
- package/src/index.ts +1 -1
- package/src/misc.ts +66 -49
- package/src/nist.ts +48 -57
- package/src/secp256k1.ts +56 -88
- package/src/utils.ts +41 -61
- package/src/webcrypto.ts +362 -0
- package/utils.d.ts +28 -19
- package/utils.d.ts.map +1 -1
- package/utils.js +45 -121
- package/utils.js.map +1 -1
- package/webcrypto.d.ts +47 -0
- package/webcrypto.d.ts.map +1 -0
- package/webcrypto.js +231 -0
- package/webcrypto.js.map +1 -0
- package/esm/_shortw_utils.d.ts +0 -19
- package/esm/_shortw_utils.d.ts.map +0 -1
- package/esm/_shortw_utils.js +0 -16
- package/esm/_shortw_utils.js.map +0 -1
- package/esm/abstract/bls.d.ts +0 -190
- package/esm/abstract/bls.d.ts.map +0 -1
- package/esm/abstract/bls.js +0 -408
- package/esm/abstract/bls.js.map +0 -1
- package/esm/abstract/curve.d.ts +0 -231
- package/esm/abstract/curve.d.ts.map +0 -1
- package/esm/abstract/curve.js +0 -465
- package/esm/abstract/curve.js.map +0 -1
- package/esm/abstract/edwards.d.ts +0 -237
- package/esm/abstract/edwards.d.ts.map +0 -1
- package/esm/abstract/edwards.js +0 -632
- package/esm/abstract/edwards.js.map +0 -1
- package/esm/abstract/fft.d.ts +0 -122
- package/esm/abstract/fft.d.ts.map +0 -1
- package/esm/abstract/fft.js +0 -425
- package/esm/abstract/fft.js.map +0 -1
- package/esm/abstract/hash-to-curve.d.ts +0 -102
- package/esm/abstract/hash-to-curve.d.ts.map +0 -1
- package/esm/abstract/hash-to-curve.js +0 -203
- package/esm/abstract/hash-to-curve.js.map +0 -1
- package/esm/abstract/modular.d.ts +0 -171
- package/esm/abstract/modular.d.ts.map +0 -1
- package/esm/abstract/modular.js +0 -530
- package/esm/abstract/modular.js.map +0 -1
- package/esm/abstract/montgomery.d.ts +0 -30
- package/esm/abstract/montgomery.d.ts.map +0 -1
- package/esm/abstract/montgomery.js +0 -157
- package/esm/abstract/montgomery.js.map +0 -1
- package/esm/abstract/poseidon.d.ts +0 -68
- package/esm/abstract/poseidon.d.ts.map +0 -1
- package/esm/abstract/poseidon.js +0 -296
- package/esm/abstract/poseidon.js.map +0 -1
- package/esm/abstract/tower.d.ts +0 -93
- package/esm/abstract/tower.d.ts.map +0 -1
- package/esm/abstract/tower.js +0 -502
- package/esm/abstract/tower.js.map +0 -1
- package/esm/abstract/utils.d.ts +0 -5
- package/esm/abstract/utils.d.ts.map +0 -1
- package/esm/abstract/utils.js +0 -7
- package/esm/abstract/utils.js.map +0 -1
- package/esm/abstract/weierstrass.d.ts +0 -412
- package/esm/abstract/weierstrass.d.ts.map +0 -1
- package/esm/abstract/weierstrass.js +0 -1428
- package/esm/abstract/weierstrass.js.map +0 -1
- package/esm/bls12-381.d.ts +0 -16
- package/esm/bls12-381.d.ts.map +0 -1
- package/esm/bls12-381.js +0 -738
- package/esm/bls12-381.js.map +0 -1
- package/esm/bn254.d.ts +0 -18
- package/esm/bn254.d.ts.map +0 -1
- package/esm/bn254.js +0 -246
- package/esm/bn254.js.map +0 -1
- package/esm/ed25519.d.ts +0 -106
- package/esm/ed25519.d.ts.map +0 -1
- package/esm/ed25519.js +0 -467
- package/esm/ed25519.js.map +0 -1
- package/esm/ed448.d.ts +0 -101
- package/esm/ed448.d.ts.map +0 -1
- package/esm/ed448.js +0 -448
- package/esm/ed448.js.map +0 -1
- package/esm/index.d.ts +0 -2
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js +0 -17
- package/esm/index.js.map +0 -1
- package/esm/jubjub.d.ts +0 -12
- package/esm/jubjub.d.ts.map +0 -1
- package/esm/jubjub.js +0 -12
- package/esm/jubjub.js.map +0 -1
- package/esm/misc.d.ts +0 -19
- package/esm/misc.d.ts.map +0 -1
- package/esm/misc.js +0 -109
- package/esm/misc.js.map +0 -1
- package/esm/nist.d.ts +0 -21
- package/esm/nist.d.ts.map +0 -1
- package/esm/nist.js +0 -132
- package/esm/nist.js.map +0 -1
- package/esm/p256.d.ts +0 -16
- package/esm/p256.d.ts.map +0 -1
- package/esm/p256.js +0 -16
- package/esm/p256.js.map +0 -1
- package/esm/p384.d.ts +0 -16
- package/esm/p384.d.ts.map +0 -1
- package/esm/p384.js +0 -16
- package/esm/p384.js.map +0 -1
- package/esm/p521.d.ts +0 -16
- package/esm/p521.d.ts.map +0 -1
- package/esm/p521.js +0 -16
- package/esm/p521.js.map +0 -1
- package/esm/package.json +0 -4
- package/esm/pasta.d.ts +0 -10
- package/esm/pasta.d.ts.map +0 -1
- package/esm/pasta.js +0 -10
- package/esm/pasta.js.map +0 -1
- package/esm/secp256k1.d.ts +0 -89
- package/esm/secp256k1.d.ts.map +0 -1
- package/esm/secp256k1.js +0 -292
- package/esm/secp256k1.js.map +0 -1
- package/esm/utils.d.ts +0 -110
- package/esm/utils.d.ts.map +0 -1
- package/esm/utils.js +0 -322
- package/esm/utils.js.map +0 -1
- package/src/_shortw_utils.ts +0 -21
- package/src/abstract/utils.ts +0 -7
- package/src/jubjub.ts +0 -12
- package/src/p256.ts +0 -15
- package/src/p384.ts +0 -15
- package/src/p521.ts +0 -15
- package/src/package.json +0 -3
- package/src/pasta.ts +0 -9
package/src/abstract/curve.ts
CHANGED
|
@@ -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
|
|
8
|
-
import { Field, FpInvertBatch,
|
|
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>>
|
|
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:
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
118
|
+
secretKey?: number;
|
|
119
|
+
publicKey?: number;
|
|
120
|
+
publicKeyUncompressed?: number;
|
|
133
121
|
publicKeyHasPrefix?: boolean;
|
|
134
122
|
signature?: number;
|
|
135
123
|
seed?: number;
|
|
136
124
|
}
|
|
137
|
-
|
|
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;
|