@noble/curves 2.0.1 → 2.2.0
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 +214 -122
- package/abstract/bls.d.ts +299 -16
- package/abstract/bls.d.ts.map +1 -1
- package/abstract/bls.js +82 -22
- package/abstract/bls.js.map +1 -1
- package/abstract/curve.d.ts +274 -27
- package/abstract/curve.d.ts.map +1 -1
- package/abstract/curve.js +177 -23
- package/abstract/curve.js.map +1 -1
- package/abstract/edwards.d.ts +166 -30
- package/abstract/edwards.d.ts.map +1 -1
- package/abstract/edwards.js +221 -86
- package/abstract/edwards.js.map +1 -1
- package/abstract/fft.d.ts +322 -10
- package/abstract/fft.d.ts.map +1 -1
- package/abstract/fft.js +154 -12
- package/abstract/fft.js.map +1 -1
- package/abstract/frost.d.ts +293 -0
- package/abstract/frost.d.ts.map +1 -0
- package/abstract/frost.js +704 -0
- package/abstract/frost.js.map +1 -0
- package/abstract/hash-to-curve.d.ts +173 -24
- package/abstract/hash-to-curve.d.ts.map +1 -1
- package/abstract/hash-to-curve.js +170 -31
- package/abstract/hash-to-curve.js.map +1 -1
- package/abstract/modular.d.ts +429 -37
- package/abstract/modular.d.ts.map +1 -1
- package/abstract/modular.js +414 -119
- package/abstract/modular.js.map +1 -1
- package/abstract/montgomery.d.ts +83 -12
- package/abstract/montgomery.d.ts.map +1 -1
- package/abstract/montgomery.js +32 -7
- package/abstract/montgomery.js.map +1 -1
- package/abstract/oprf.d.ts +164 -91
- package/abstract/oprf.d.ts.map +1 -1
- package/abstract/oprf.js +88 -29
- package/abstract/oprf.js.map +1 -1
- package/abstract/poseidon.d.ts +138 -7
- package/abstract/poseidon.d.ts.map +1 -1
- package/abstract/poseidon.js +178 -15
- package/abstract/poseidon.js.map +1 -1
- package/abstract/tower.d.ts +122 -3
- package/abstract/tower.d.ts.map +1 -1
- package/abstract/tower.js +323 -139
- package/abstract/tower.js.map +1 -1
- package/abstract/weierstrass.d.ts +339 -76
- package/abstract/weierstrass.d.ts.map +1 -1
- package/abstract/weierstrass.js +395 -205
- package/abstract/weierstrass.js.map +1 -1
- package/bls12-381.d.ts +16 -2
- package/bls12-381.d.ts.map +1 -1
- package/bls12-381.js +199 -209
- package/bls12-381.js.map +1 -1
- package/bn254.d.ts +11 -2
- package/bn254.d.ts.map +1 -1
- package/bn254.js +93 -38
- package/bn254.js.map +1 -1
- package/ed25519.d.ts +125 -14
- package/ed25519.d.ts.map +1 -1
- package/ed25519.js +202 -40
- package/ed25519.js.map +1 -1
- package/ed448.d.ts +108 -14
- package/ed448.d.ts.map +1 -1
- package/ed448.js +194 -42
- package/ed448.js.map +1 -1
- package/index.js +7 -1
- package/index.js.map +1 -1
- package/misc.d.ts +106 -7
- package/misc.d.ts.map +1 -1
- package/misc.js +141 -32
- package/misc.js.map +1 -1
- package/nist.d.ts +112 -11
- package/nist.d.ts.map +1 -1
- package/nist.js +139 -17
- package/nist.js.map +1 -1
- package/package.json +11 -6
- package/secp256k1.d.ts +92 -15
- package/secp256k1.d.ts.map +1 -1
- package/secp256k1.js +211 -28
- package/secp256k1.js.map +1 -1
- package/src/abstract/bls.ts +350 -67
- package/src/abstract/curve.ts +327 -44
- package/src/abstract/edwards.ts +367 -143
- package/src/abstract/fft.ts +369 -36
- package/src/abstract/frost.ts +1092 -0
- package/src/abstract/hash-to-curve.ts +255 -56
- package/src/abstract/modular.ts +591 -144
- package/src/abstract/montgomery.ts +114 -30
- package/src/abstract/oprf.ts +383 -194
- package/src/abstract/poseidon.ts +235 -35
- package/src/abstract/tower.ts +428 -159
- package/src/abstract/weierstrass.ts +710 -312
- package/src/bls12-381.ts +239 -236
- package/src/bn254.ts +107 -46
- package/src/ed25519.ts +227 -55
- package/src/ed448.ts +227 -57
- package/src/index.ts +7 -1
- package/src/misc.ts +154 -35
- package/src/nist.ts +143 -20
- package/src/secp256k1.ts +284 -41
- package/src/utils.ts +583 -81
- package/src/webcrypto.ts +302 -73
- package/utils.d.ts +457 -24
- package/utils.d.ts.map +1 -1
- package/utils.js +410 -53
- package/utils.js.map +1 -1
- package/webcrypto.d.ts +167 -25
- package/webcrypto.d.ts.map +1 -1
- package/webcrypto.js +165 -58
- package/webcrypto.js.map +1 -1
package/abstract/curve.d.ts
CHANGED
|
@@ -4,73 +4,212 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
7
|
-
import { type Signer } from '../utils.ts';
|
|
7
|
+
import { type Signer, type TArg, type TRet } from '../utils.ts';
|
|
8
8
|
import { type IField } from './modular.ts';
|
|
9
|
+
/** Affine point coordinates without projective fields. */
|
|
9
10
|
export type AffinePoint<T> = {
|
|
11
|
+
/** Affine x coordinate. */
|
|
10
12
|
x: T;
|
|
13
|
+
/** Affine y coordinate. */
|
|
11
14
|
y: T;
|
|
12
15
|
} & {
|
|
13
16
|
Z?: never;
|
|
14
17
|
};
|
|
15
|
-
/** Base interface for all elliptic
|
|
18
|
+
/** Base interface for all elliptic-curve point instances. */
|
|
16
19
|
export interface CurvePoint<F, P extends CurvePoint<F, P>> {
|
|
17
20
|
/** Affine x coordinate. Different from projective / extended X coordinate. */
|
|
18
21
|
x: F;
|
|
19
22
|
/** Affine y coordinate. Different from projective / extended Y coordinate. */
|
|
20
23
|
y: F;
|
|
24
|
+
/** Projective Z coordinate when the point keeps projective state. */
|
|
21
25
|
Z?: F;
|
|
26
|
+
/**
|
|
27
|
+
* Double the point.
|
|
28
|
+
* @returns Doubled point.
|
|
29
|
+
*/
|
|
22
30
|
double(): P;
|
|
31
|
+
/**
|
|
32
|
+
* Negate the point.
|
|
33
|
+
* @returns Negated point.
|
|
34
|
+
*/
|
|
23
35
|
negate(): P;
|
|
36
|
+
/**
|
|
37
|
+
* Add another point from the same curve.
|
|
38
|
+
* @param other - Point to add.
|
|
39
|
+
* @returns Sum point.
|
|
40
|
+
*/
|
|
24
41
|
add(other: P): P;
|
|
42
|
+
/**
|
|
43
|
+
* Subtract another point from the same curve.
|
|
44
|
+
* @param other - Point to subtract.
|
|
45
|
+
* @returns Difference point.
|
|
46
|
+
*/
|
|
25
47
|
subtract(other: P): P;
|
|
48
|
+
/**
|
|
49
|
+
* Compare two points for equality.
|
|
50
|
+
* @param other - Point to compare.
|
|
51
|
+
* @returns Whether the points are equal.
|
|
52
|
+
*/
|
|
26
53
|
equals(other: P): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Multiply the point by a scalar in constant time.
|
|
56
|
+
* Implementations keep the subgroup-scalar contract strict and may reject
|
|
57
|
+
* `0` instead of returning the identity point.
|
|
58
|
+
* @param scalar - Scalar multiplier.
|
|
59
|
+
* @returns Product point.
|
|
60
|
+
*/
|
|
27
61
|
multiply(scalar: bigint): P;
|
|
62
|
+
/** Assert that the point satisfies the curve equation and subgroup checks. */
|
|
28
63
|
assertValidity(): void;
|
|
64
|
+
/**
|
|
65
|
+
* Map the point into the prime-order subgroup when the curve requires it.
|
|
66
|
+
* @returns Prime-order point.
|
|
67
|
+
*/
|
|
29
68
|
clearCofactor(): P;
|
|
69
|
+
/**
|
|
70
|
+
* Check whether the point is the point at infinity.
|
|
71
|
+
* @returns Whether the point is zero.
|
|
72
|
+
*/
|
|
30
73
|
is0(): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Check whether the point belongs to the prime-order subgroup.
|
|
76
|
+
* @returns Whether the point is torsion-free.
|
|
77
|
+
*/
|
|
31
78
|
isTorsionFree(): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Check whether the point lies in a small torsion subgroup.
|
|
81
|
+
* @returns Whether the point has small order.
|
|
82
|
+
*/
|
|
32
83
|
isSmallOrder(): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Multiply the point by a scalar without constant-time guarantees.
|
|
86
|
+
* Public-scalar callers that need `0` should use this method instead of
|
|
87
|
+
* relying on `multiply(...)` to return the identity point.
|
|
88
|
+
* @param scalar - Scalar multiplier.
|
|
89
|
+
* @returns Product point.
|
|
90
|
+
*/
|
|
33
91
|
multiplyUnsafe(scalar: bigint): P;
|
|
34
92
|
/**
|
|
35
93
|
* Massively speeds up `p.multiply(n)` by using precompute tables (caching). See {@link wNAF}.
|
|
36
|
-
*
|
|
94
|
+
* Cache state lives in internal WeakMaps keyed by point identity, not on the point object.
|
|
95
|
+
* Repeating `precompute(...)` for the same point identity replaces the remembered window size
|
|
96
|
+
* and forces table regeneration for that point.
|
|
97
|
+
* @param windowSize - Precompute window size.
|
|
98
|
+
* @param isLazy - calculate cache now. Default (true) ensures it's deferred to first `multiply()`
|
|
99
|
+
* @returns Same point instance with precompute tables attached.
|
|
37
100
|
*/
|
|
38
101
|
precompute(windowSize?: number, isLazy?: boolean): P;
|
|
39
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* Converts point to 2D xy affine coordinates.
|
|
104
|
+
* @param invertedZ - Optional inverted Z coordinate for batch normalization.
|
|
105
|
+
* @returns Affine x/y coordinates.
|
|
106
|
+
*/
|
|
40
107
|
toAffine(invertedZ?: F): AffinePoint<F>;
|
|
108
|
+
/**
|
|
109
|
+
* Encode the point into the curve's canonical byte form.
|
|
110
|
+
* @returns Encoded point bytes.
|
|
111
|
+
*/
|
|
41
112
|
toBytes(): Uint8Array;
|
|
113
|
+
/**
|
|
114
|
+
* Encode the point into the curve's canonical hex form.
|
|
115
|
+
* @returns Encoded point hex.
|
|
116
|
+
*/
|
|
42
117
|
toHex(): string;
|
|
43
118
|
}
|
|
44
|
-
/** Base interface for
|
|
119
|
+
/** Base interface for elliptic-curve point constructors. */
|
|
45
120
|
export interface CurvePointCons<P extends CurvePoint<any, P>> {
|
|
121
|
+
/**
|
|
122
|
+
* Runtime brand check for points created by this constructor.
|
|
123
|
+
* @param item - Value to test.
|
|
124
|
+
* @returns Whether the value is a point from this constructor.
|
|
125
|
+
*/
|
|
46
126
|
[Symbol.hasInstance]: (item: unknown) => boolean;
|
|
127
|
+
/** Canonical subgroup generator. */
|
|
47
128
|
BASE: P;
|
|
129
|
+
/** Point at infinity. */
|
|
48
130
|
ZERO: P;
|
|
49
131
|
/** Field for basic curve math */
|
|
50
132
|
Fp: IField<P_F<P>>;
|
|
51
133
|
/** Scalar field, for scalars in multiply and others */
|
|
52
134
|
Fn: IField<bigint>;
|
|
53
|
-
/**
|
|
135
|
+
/**
|
|
136
|
+
* Create one point from affine coordinates.
|
|
137
|
+
* Does NOT validate curve, subgroup, or wrapper invariants.
|
|
138
|
+
* Use `.assertValidity()` on adversarial inputs.
|
|
139
|
+
* @param p - Affine point coordinates.
|
|
140
|
+
* @returns Point instance.
|
|
141
|
+
*/
|
|
54
142
|
fromAffine(p: AffinePoint<P_F<P>>): P;
|
|
143
|
+
/**
|
|
144
|
+
* Decode a point from the canonical byte encoding.
|
|
145
|
+
* @param bytes - Encoded point bytes.
|
|
146
|
+
* Implementations MUST treat `bytes` as read-only.
|
|
147
|
+
* @returns Point instance.
|
|
148
|
+
*/
|
|
55
149
|
fromBytes(bytes: Uint8Array): P;
|
|
150
|
+
/**
|
|
151
|
+
* Decode a point from the canonical hex encoding.
|
|
152
|
+
* @param hex - Encoded point hex.
|
|
153
|
+
* @returns Point instance.
|
|
154
|
+
*/
|
|
56
155
|
fromHex(hex: string): P;
|
|
57
156
|
}
|
|
58
|
-
/** Returns
|
|
157
|
+
/** Returns the affine field type for a point instance (`P_F<P> == P.F`). */
|
|
59
158
|
export type P_F<P extends CurvePoint<any, P>> = P extends CurvePoint<infer F, P> ? F : never;
|
|
60
|
-
/** Returns
|
|
159
|
+
/** Returns the affine field type for a point constructor (`PC_F<PC> == PC.P.F`). */
|
|
61
160
|
export type PC_F<PC extends CurvePointCons<CurvePoint<any, any>>> = PC['Fp']['ZERO'];
|
|
62
|
-
/** Returns
|
|
161
|
+
/** Returns the point instance type for a point constructor (`PC_P<PC> == PC.P`). */
|
|
63
162
|
export type PC_P<PC extends CurvePointCons<CurvePoint<any, any>>> = PC['ZERO'];
|
|
163
|
+
/** Wide point-constructor type used when the concrete curve is not important. */
|
|
64
164
|
export type PC_ANY = CurvePointCons<CurvePoint<any, CurvePoint<any, CurvePoint<any, CurvePoint<any, CurvePoint<any, CurvePoint<any, CurvePoint<any, CurvePoint<any, CurvePoint<any, CurvePoint<any, any>>>>>>>>>>>;
|
|
165
|
+
/**
|
|
166
|
+
* Validates the static surface of a point constructor.
|
|
167
|
+
* This is only a cheap sanity check for the constructor hooks and fields consumed by generic
|
|
168
|
+
* factories; it does not certify `BASE`/`ZERO` semantics or prove the curve implementation itself.
|
|
169
|
+
* @param Point - Runtime point constructor.
|
|
170
|
+
* @throws On missing constructor hooks or malformed field metadata. {@link TypeError}
|
|
171
|
+
* @example
|
|
172
|
+
* Check that one point constructor exposes the static hooks generic helpers need.
|
|
173
|
+
*
|
|
174
|
+
* ```ts
|
|
175
|
+
* import { ed25519 } from '@noble/curves/ed25519.js';
|
|
176
|
+
* import { validatePointCons } from '@noble/curves/abstract/curve.js';
|
|
177
|
+
* validatePointCons(ed25519.Point);
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
export declare function validatePointCons<P extends CurvePoint<any, P>>(Point: CurvePointCons<P>): void;
|
|
181
|
+
/** Byte lengths used by one curve implementation. */
|
|
65
182
|
export interface CurveLengths {
|
|
183
|
+
/** Secret-key length in bytes. */
|
|
66
184
|
secretKey?: number;
|
|
185
|
+
/** Compressed public-key length in bytes. */
|
|
67
186
|
publicKey?: number;
|
|
187
|
+
/** Uncompressed public-key length in bytes. */
|
|
68
188
|
publicKeyUncompressed?: number;
|
|
189
|
+
/** Whether public-key encodings include a format prefix byte. */
|
|
69
190
|
publicKeyHasPrefix?: boolean;
|
|
191
|
+
/** Signature length in bytes. */
|
|
70
192
|
signature?: number;
|
|
193
|
+
/** Seed length in bytes when the curve exposes deterministic keygen from seed. */
|
|
71
194
|
seed?: number;
|
|
72
195
|
}
|
|
196
|
+
/** Reorders or otherwise remaps a batch while preserving its element type. */
|
|
73
197
|
export type Mapper<T> = (i: T[]) => T[];
|
|
198
|
+
/**
|
|
199
|
+
* Computes both candidates first, but the final selection still branches on `condition`, so this
|
|
200
|
+
* is not a strict constant-time CMOV primitive.
|
|
201
|
+
* @param condition - Whether to negate the point.
|
|
202
|
+
* @param item - Point-like value.
|
|
203
|
+
* @returns Original or negated value.
|
|
204
|
+
* @example
|
|
205
|
+
* Keep the point or return its negation based on one boolean branch.
|
|
206
|
+
*
|
|
207
|
+
* ```ts
|
|
208
|
+
* import { negateCt } from '@noble/curves/abstract/curve.js';
|
|
209
|
+
* import { p256 } from '@noble/curves/nist.js';
|
|
210
|
+
* const maybeNegated = negateCt(true, p256.Point.BASE);
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
74
213
|
export declare function negateCt<T extends {
|
|
75
214
|
negate: () => T;
|
|
76
215
|
}>(condition: boolean, item: T): T;
|
|
@@ -79,6 +218,18 @@ export declare function negateCt<T extends {
|
|
|
79
218
|
* inversion on all of them. Inversion is very slow operation,
|
|
80
219
|
* so this improves performance massively.
|
|
81
220
|
* Optimization: converts a list of projective points to a list of identical points with Z=1.
|
|
221
|
+
* Input points are left unchanged; the normalized points are returned as fresh instances.
|
|
222
|
+
* @param c - Point constructor.
|
|
223
|
+
* @param points - Projective points.
|
|
224
|
+
* @returns Fresh projective points reconstructed from normalized affine coordinates.
|
|
225
|
+
* @example
|
|
226
|
+
* Batch-normalize projective points with a single shared inversion.
|
|
227
|
+
*
|
|
228
|
+
* ```ts
|
|
229
|
+
* import { normalizeZ } from '@noble/curves/abstract/curve.js';
|
|
230
|
+
* import { p256 } from '@noble/curves/nist.js';
|
|
231
|
+
* const points = normalizeZ(p256.Point, [p256.Point.BASE, p256.Point.BASE.double()]);
|
|
232
|
+
* ```
|
|
82
233
|
*/
|
|
83
234
|
export declare function normalizeZ<P extends CurvePoint<any, P>, PC extends CurvePointCons<P>>(c: PC, points: P[]): P[];
|
|
84
235
|
/**
|
|
@@ -96,8 +247,18 @@ export declare function normalizeZ<P extends CurvePoint<any, P>, PC extends Curv
|
|
|
96
247
|
* - +1 window is neccessary for wNAF
|
|
97
248
|
* - wNAF reduces table size: 2x less memory + 2x faster generation, but 10% slower multiplication
|
|
98
249
|
*
|
|
99
|
-
*
|
|
100
|
-
* This would allow windows to be in different memory locations
|
|
250
|
+
* TODO: research returning a 2d JS array of windows instead of a single window.
|
|
251
|
+
* This would allow windows to be in different memory locations.
|
|
252
|
+
* @param Point - Point constructor.
|
|
253
|
+
* @param bits - Scalar bit length.
|
|
254
|
+
* @example
|
|
255
|
+
* Elliptic curve multiplication of Point by scalar.
|
|
256
|
+
*
|
|
257
|
+
* ```ts
|
|
258
|
+
* import { wNAF } from '@noble/curves/abstract/curve.js';
|
|
259
|
+
* import { p256 } from '@noble/curves/nist.js';
|
|
260
|
+
* const ladder = new wNAF(p256.Point, p256.Point.Fn.BITS);
|
|
261
|
+
* ```
|
|
101
262
|
*/
|
|
102
263
|
export declare class wNAF<PC extends PC_ANY> {
|
|
103
264
|
private readonly BASE;
|
|
@@ -114,8 +275,8 @@ export declare class wNAF<PC extends PC_ANY> {
|
|
|
114
275
|
* - 𝑊 is the window size
|
|
115
276
|
* - 𝑛 is the bitlength of the curve order.
|
|
116
277
|
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
117
|
-
* @param point Point instance
|
|
118
|
-
* @param W window size
|
|
278
|
+
* @param point - Point instance
|
|
279
|
+
* @param W - window size
|
|
119
280
|
* @returns precomputed point tables flattened to a single array
|
|
120
281
|
*/
|
|
121
282
|
private precomputeWindow;
|
|
@@ -127,8 +288,9 @@ export declare class wNAF<PC extends PC_ANY> {
|
|
|
127
288
|
*/
|
|
128
289
|
private wNAF;
|
|
129
290
|
/**
|
|
130
|
-
* Implements
|
|
131
|
-
*
|
|
291
|
+
* Implements unsafe EC multiplication using precomputed tables
|
|
292
|
+
* and w-ary non-adjacent form.
|
|
293
|
+
* @param acc - accumulator point to add result of multiplication
|
|
132
294
|
* @returns point
|
|
133
295
|
*/
|
|
134
296
|
private wNAFUnsafe;
|
|
@@ -144,6 +306,19 @@ export declare class wNAF<PC extends PC_ANY> {
|
|
|
144
306
|
/**
|
|
145
307
|
* Endomorphism-specific multiplication for Koblitz curves.
|
|
146
308
|
* Cost: 128 dbl, 0-256 adds.
|
|
309
|
+
* @param Point - Point constructor.
|
|
310
|
+
* @param point - Input point.
|
|
311
|
+
* @param k1 - First non-negative absolute scalar chunk.
|
|
312
|
+
* @param k2 - Second non-negative absolute scalar chunk.
|
|
313
|
+
* @returns Partial multiplication results.
|
|
314
|
+
* @example
|
|
315
|
+
* Endomorphism-specific multiplication for Koblitz curves.
|
|
316
|
+
*
|
|
317
|
+
* ```ts
|
|
318
|
+
* import { mulEndoUnsafe } from '@noble/curves/abstract/curve.js';
|
|
319
|
+
* import { secp256k1 } from '@noble/curves/secp256k1.js';
|
|
320
|
+
* const parts = mulEndoUnsafe(secp256k1.Point, secp256k1.Point.BASE, 3n, 5n);
|
|
321
|
+
* ```
|
|
147
322
|
*/
|
|
148
323
|
export declare function mulEndoUnsafe<P extends CurvePoint<any, P>, PC extends CurvePointCons<P>>(Point: PC, point: P, k1: bigint, k2: bigint): {
|
|
149
324
|
p1: P;
|
|
@@ -154,42 +329,114 @@ export declare function mulEndoUnsafe<P extends CurvePoint<any, P>, PC extends C
|
|
|
154
329
|
* 30x faster vs naive addition on L=4096, 10x faster than precomputes.
|
|
155
330
|
* For N=254bit, L=1, it does: 1024 ADD + 254 DBL. For L=5: 1536 ADD + 254 DBL.
|
|
156
331
|
* Algorithmically constant-time (for same L), even when 1 point + scalar, or when scalar = 0.
|
|
157
|
-
* @param c Curve Point constructor
|
|
158
|
-
* @param
|
|
159
|
-
* @param
|
|
160
|
-
* @
|
|
332
|
+
* @param c - Curve Point constructor
|
|
333
|
+
* @param points - array of L curve points
|
|
334
|
+
* @param scalars - array of L scalars (aka secret keys / bigints)
|
|
335
|
+
* @returns MSM result point. Empty input is accepted and returns the identity.
|
|
336
|
+
* @throws If the point set, scalar set, or MSM sizing is invalid. {@link Error}
|
|
337
|
+
* @example
|
|
338
|
+
* Pippenger algorithm for multi-scalar multiplication (MSM, Pa + Qb + Rc + ...).
|
|
339
|
+
*
|
|
340
|
+
* ```ts
|
|
341
|
+
* import { pippenger } from '@noble/curves/abstract/curve.js';
|
|
342
|
+
* import { p256 } from '@noble/curves/nist.js';
|
|
343
|
+
* const point = pippenger(p256.Point, [p256.Point.BASE, p256.Point.BASE.double()], [2n, 3n]);
|
|
344
|
+
* ```
|
|
161
345
|
*/
|
|
162
346
|
export declare function pippenger<P extends CurvePoint<any, P>, PC extends CurvePointCons<P>>(c: PC, points: P[], scalars: bigint[]): P;
|
|
163
347
|
/**
|
|
164
348
|
* Precomputed multi-scalar multiplication (MSM, Pa + Qb + Rc + ...).
|
|
165
|
-
* @param c Curve Point constructor
|
|
166
|
-
* @param
|
|
167
|
-
* @param
|
|
168
|
-
* @returns
|
|
349
|
+
* @param c - Curve Point constructor
|
|
350
|
+
* @param points - array of L curve points
|
|
351
|
+
* @param windowSize - Precompute window size.
|
|
352
|
+
* @returns Function which multiplies points with scalars. The closure accepts
|
|
353
|
+
* `scalars.length <= points.length`, and omitted trailing scalars are treated as zero.
|
|
354
|
+
* @throws If the point set or precompute window is invalid. {@link Error}
|
|
355
|
+
* @example
|
|
356
|
+
* Precomputed multi-scalar multiplication (MSM, Pa + Qb + Rc + ...).
|
|
357
|
+
*
|
|
358
|
+
* ```ts
|
|
359
|
+
* import { precomputeMSMUnsafe } from '@noble/curves/abstract/curve.js';
|
|
360
|
+
* import { p256 } from '@noble/curves/nist.js';
|
|
361
|
+
* const msm = precomputeMSMUnsafe(p256.Point, [p256.Point.BASE], 4);
|
|
362
|
+
* const point = msm([3n]);
|
|
363
|
+
* ```
|
|
169
364
|
*/
|
|
170
365
|
export declare function precomputeMSMUnsafe<P extends CurvePoint<any, P>, PC extends CurvePointCons<P>>(c: PC, points: P[], windowSize: number): (scalars: bigint[]) => P;
|
|
366
|
+
/** Minimal curve parameters needed to construct a Weierstrass or Edwards curve. */
|
|
171
367
|
export type ValidCurveParams<T> = {
|
|
368
|
+
/** Base-field modulus. */
|
|
172
369
|
p: bigint;
|
|
370
|
+
/** Prime subgroup order. */
|
|
173
371
|
n: bigint;
|
|
372
|
+
/** Cofactor. */
|
|
174
373
|
h: bigint;
|
|
374
|
+
/** Curve parameter `a`. */
|
|
175
375
|
a: T;
|
|
376
|
+
/** Weierstrass curve parameter `b`. */
|
|
176
377
|
b?: T;
|
|
378
|
+
/** Edwards curve parameter `d`. */
|
|
177
379
|
d?: T;
|
|
380
|
+
/** Generator x coordinate. */
|
|
178
381
|
Gx: T;
|
|
382
|
+
/** Generator y coordinate. */
|
|
179
383
|
Gy: T;
|
|
180
384
|
};
|
|
385
|
+
/** Pair of fields used by curve constructors. */
|
|
181
386
|
export type FpFn<T> = {
|
|
387
|
+
/** Base field used for curve coordinates. */
|
|
182
388
|
Fp: IField<T>;
|
|
389
|
+
/** Scalar field used for secret scalars and subgroup arithmetic. */
|
|
183
390
|
Fn: IField<bigint>;
|
|
184
391
|
};
|
|
185
|
-
/**
|
|
186
|
-
|
|
392
|
+
/**
|
|
393
|
+
* Validates basic CURVE shape and field membership, then creates fields.
|
|
394
|
+
* This does not prove that the generator is on-curve, that subgroup/order data are consistent, or
|
|
395
|
+
* that the curve equation itself is otherwise sane.
|
|
396
|
+
* @param type - Curve family.
|
|
397
|
+
* @param CURVE - Curve parameters.
|
|
398
|
+
* @param curveOpts - Optional field overrides:
|
|
399
|
+
* - `Fp` (optional): Optional base-field override.
|
|
400
|
+
* - `Fn` (optional): Optional scalar-field override.
|
|
401
|
+
* @param FpFnLE - Whether field encoding is little-endian.
|
|
402
|
+
* @returns Frozen curve parameters and fields.
|
|
403
|
+
* @throws If the curve parameters or field overrides are invalid. {@link Error}
|
|
404
|
+
* @example
|
|
405
|
+
* Build curve fields from raw constants before constructing a curve instance.
|
|
406
|
+
*
|
|
407
|
+
* ```ts
|
|
408
|
+
* const curve = createCurveFields('weierstrass', {
|
|
409
|
+
* p: 17n,
|
|
410
|
+
* n: 19n,
|
|
411
|
+
* h: 1n,
|
|
412
|
+
* a: 2n,
|
|
413
|
+
* b: 2n,
|
|
414
|
+
* Gx: 5n,
|
|
415
|
+
* Gy: 1n,
|
|
416
|
+
* });
|
|
417
|
+
* ```
|
|
418
|
+
*/
|
|
419
|
+
export declare function createCurveFields<T>(type: 'weierstrass' | 'edwards', CURVE: ValidCurveParams<T>, curveOpts?: TArg<Partial<FpFn<T>>>, FpFnLE?: boolean): TRet<FpFn<T> & {
|
|
187
420
|
CURVE: ValidCurveParams<T>;
|
|
188
|
-
}
|
|
421
|
+
}>;
|
|
189
422
|
type KeygenFn = (seed?: Uint8Array, isCompressed?: boolean) => {
|
|
190
423
|
secretKey: Uint8Array;
|
|
191
424
|
publicKey: Uint8Array;
|
|
192
425
|
};
|
|
193
|
-
|
|
426
|
+
/**
|
|
427
|
+
* @param randomSecretKey - Secret-key generator.
|
|
428
|
+
* @param getPublicKey - Public-key derivation helper.
|
|
429
|
+
* @returns Keypair generator.
|
|
430
|
+
* @example
|
|
431
|
+
* Build a `keygen()` helper from existing secret-key and public-key primitives.
|
|
432
|
+
*
|
|
433
|
+
* ```ts
|
|
434
|
+
* import { createKeygen } from '@noble/curves/abstract/curve.js';
|
|
435
|
+
* import { p256 } from '@noble/curves/nist.js';
|
|
436
|
+
* const keygen = createKeygen(p256.utils.randomSecretKey, p256.getPublicKey);
|
|
437
|
+
* const pair = keygen();
|
|
438
|
+
* ```
|
|
439
|
+
*/
|
|
440
|
+
export declare function createKeygen(randomSecretKey: Function, getPublicKey: TArg<Signer['getPublicKey']>): TRet<KeygenFn>;
|
|
194
441
|
export {};
|
|
195
442
|
//# sourceMappingURL=curve.d.ts.map
|
package/abstract/curve.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"curve.d.ts","sourceRoot":"","sources":["../src/abstract/curve.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,s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