@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/fft.d.ts
CHANGED
|
@@ -3,67 +3,231 @@
|
|
|
3
3
|
* API may change at any time. The code has not been audited. Feature requests are welcome.
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
+
import type { TArg } from '../utils.ts';
|
|
6
7
|
import type { IField } from './modular.ts';
|
|
8
|
+
/** Array-like coefficient storage that can be mutated in place. */
|
|
7
9
|
export interface MutableArrayLike<T> {
|
|
10
|
+
/** Element access by numeric index. */
|
|
8
11
|
[index: number]: T;
|
|
12
|
+
/** Current amount of stored coefficients. */
|
|
9
13
|
length: number;
|
|
14
|
+
/**
|
|
15
|
+
* Return a sliced copy using the same storage shape.
|
|
16
|
+
* @param start - Inclusive start index.
|
|
17
|
+
* @param end - Exclusive end index.
|
|
18
|
+
* @returns Sliced copy.
|
|
19
|
+
*/
|
|
10
20
|
slice(start?: number, end?: number): this;
|
|
21
|
+
/**
|
|
22
|
+
* Iterate over stored coefficients in order.
|
|
23
|
+
* @returns Coefficient iterator.
|
|
24
|
+
*/
|
|
11
25
|
[Symbol.iterator](): Iterator<T>;
|
|
12
26
|
}
|
|
13
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Concrete polynomial containers accepted by the high-level `poly(...)` helpers.
|
|
29
|
+
* Lower-level FFT helpers can work with structural `MutableArrayLike`, but `poly(...)`
|
|
30
|
+
* intentionally keeps runtime dispatch on plain arrays and typed-array views.
|
|
31
|
+
*/
|
|
32
|
+
export type PolyStorage<T> = T[] | (MutableArrayLike<T> & ArrayBufferView);
|
|
33
|
+
/**
|
|
34
|
+
* Checks if integer is in form of `1 << X`.
|
|
35
|
+
* @param x - Integer to inspect.
|
|
36
|
+
* @returns `true` when the value is a power of two.
|
|
37
|
+
* @throws If `x` is not a valid unsigned 32-bit integer. {@link Error}
|
|
38
|
+
* @example
|
|
39
|
+
* Validate that an FFT size is a power of two.
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* isPowerOfTwo(8);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
14
45
|
export declare function isPowerOfTwo(x: number): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* @param n - Input value.
|
|
48
|
+
* @returns Next power of two within the u32/array-length domain.
|
|
49
|
+
* @throws If `n` is not a valid unsigned 32-bit integer. {@link Error}
|
|
50
|
+
* @example
|
|
51
|
+
* Round an integer up to the FFT size it needs.
|
|
52
|
+
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* nextPowerOfTwo(9);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
15
57
|
export declare function nextPowerOfTwo(n: number): number;
|
|
58
|
+
/**
|
|
59
|
+
* @param n - Value to reverse.
|
|
60
|
+
* @param bits - Number of bits to use.
|
|
61
|
+
* @returns Bit-reversed integer.
|
|
62
|
+
* @throws If `n` is not a valid unsigned 32-bit integer. {@link Error}
|
|
63
|
+
* @example
|
|
64
|
+
* Reverse the low `bits` bits of one index.
|
|
65
|
+
*
|
|
66
|
+
* ```ts
|
|
67
|
+
* reverseBits(3, 3);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
16
70
|
export declare function reverseBits(n: number, bits: number): number;
|
|
17
|
-
/**
|
|
71
|
+
/**
|
|
72
|
+
* Similar to `bitLen(x)-1` but much faster for small integers, like indices.
|
|
73
|
+
* @param n - Input value.
|
|
74
|
+
* @returns Base-2 logarithm. For `n = 0`, the current implementation returns `-1`.
|
|
75
|
+
* @throws If `n` is not a valid unsigned 32-bit integer. {@link Error}
|
|
76
|
+
* @example
|
|
77
|
+
* Compute the radix-2 stage count for one transform size.
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* log2(8);
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
18
83
|
export declare function log2(n: number): number;
|
|
19
84
|
/**
|
|
20
85
|
* Moves lowest bit to highest position, which at first step splits
|
|
21
86
|
* array on even and odd indices, then it applied again to each part,
|
|
22
87
|
* which is core of fft
|
|
88
|
+
* @param values - Mutable coefficient array.
|
|
89
|
+
* @returns Mutated input array.
|
|
90
|
+
* @throws If the array length is not a positive power of two. {@link Error}
|
|
91
|
+
* @example
|
|
92
|
+
* Reorder coefficients into bit-reversed order in place.
|
|
93
|
+
*
|
|
94
|
+
* ```ts
|
|
95
|
+
* const values = Uint8Array.from([0, 1, 2, 3]);
|
|
96
|
+
* bitReversalInplace(values);
|
|
97
|
+
* ```
|
|
23
98
|
*/
|
|
24
99
|
export declare function bitReversalInplace<T extends MutableArrayLike<any>>(values: T): T;
|
|
100
|
+
/**
|
|
101
|
+
* @param values - Input values.
|
|
102
|
+
* @returns Reordered copy.
|
|
103
|
+
* @throws If the array length is not a positive power of two. {@link Error}
|
|
104
|
+
* @example
|
|
105
|
+
* Return a reordered copy instead of mutating the input in place.
|
|
106
|
+
*
|
|
107
|
+
* ```ts
|
|
108
|
+
* const reordered = bitReversalPermutation([0, 1, 2, 3]);
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
25
111
|
export declare function bitReversalPermutation<T>(values: T[]): T[];
|
|
112
|
+
/** Cached roots-of-unity tables derived from one finite field. */
|
|
26
113
|
export type RootsOfUnity = {
|
|
114
|
+
/** Generator and 2-adicity metadata for the cached field. */
|
|
27
115
|
info: {
|
|
28
116
|
G: bigint;
|
|
29
117
|
oddFactor: bigint;
|
|
30
118
|
powerOfTwo: number;
|
|
31
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* Return the natural-order roots of unity for one radix-2 size.
|
|
122
|
+
* @param bits - Transform size as `log2(N)`.
|
|
123
|
+
* @returns Natural-order roots for that size.
|
|
124
|
+
*/
|
|
32
125
|
roots: (bits: number) => bigint[];
|
|
126
|
+
/**
|
|
127
|
+
* Return the bit-reversal permutation of the roots for one radix-2 size.
|
|
128
|
+
* @param bits - Transform size as `log2(N)`.
|
|
129
|
+
* @returns Bit-reversed roots.
|
|
130
|
+
*/
|
|
33
131
|
brp(bits: number): bigint[];
|
|
132
|
+
/**
|
|
133
|
+
* Return the inverse roots of unity for one radix-2 size.
|
|
134
|
+
* @param bits - Transform size as `log2(N)`.
|
|
135
|
+
* @returns Inverse roots.
|
|
136
|
+
*/
|
|
34
137
|
inverse(bits: number): bigint[];
|
|
138
|
+
/**
|
|
139
|
+
* Return one primitive root used by a radix-2 stage.
|
|
140
|
+
* @param bits - Transform size as `log2(N)`.
|
|
141
|
+
* @returns Primitive root for that stage.
|
|
142
|
+
*/
|
|
35
143
|
omega: (bits: number) => bigint;
|
|
144
|
+
/**
|
|
145
|
+
* Drop all cached root tables.
|
|
146
|
+
* @returns Nothing.
|
|
147
|
+
*/
|
|
36
148
|
clear: () => void;
|
|
37
149
|
};
|
|
38
|
-
/**
|
|
39
|
-
|
|
150
|
+
/**
|
|
151
|
+
* We limit roots up to 2**31, which is a lot: 2-billion polynomimal should be rare.
|
|
152
|
+
* @param field - Field implementation.
|
|
153
|
+
* @param generator - Optional generator override.
|
|
154
|
+
* @returns Roots-of-unity cache.
|
|
155
|
+
* @example
|
|
156
|
+
* Cache roots once, then ask for the omega table of one FFT size.
|
|
157
|
+
*
|
|
158
|
+
* ```ts
|
|
159
|
+
* import { rootsOfUnity } from '@noble/curves/abstract/fft.js';
|
|
160
|
+
* import { Field } from '@noble/curves/abstract/modular.js';
|
|
161
|
+
* const roots = rootsOfUnity(Field(17n));
|
|
162
|
+
* const omega = roots.omega(4);
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export declare function rootsOfUnity(field: TArg<IField<bigint>>, generator?: bigint): RootsOfUnity;
|
|
166
|
+
/** Polynomial coefficient container used by the FFT helpers. */
|
|
40
167
|
export type Polynomial<T> = MutableArrayLike<T>;
|
|
41
168
|
/**
|
|
169
|
+
* Arithmetic operations used by the generic FFT implementation.
|
|
170
|
+
*
|
|
42
171
|
* Maps great to Field<bigint>, but not to Group (EC points):
|
|
43
172
|
* - inv from scalar field
|
|
44
173
|
* - we need multiplyUnsafe here, instead of multiply for speed
|
|
45
174
|
* - multiplyUnsafe is safe in the context: we do mul(rootsOfUnity), which are public and sparse
|
|
46
175
|
*/
|
|
47
176
|
export type FFTOpts<T, R> = {
|
|
177
|
+
/**
|
|
178
|
+
* Add two coefficients.
|
|
179
|
+
* @param a - Left coefficient.
|
|
180
|
+
* @param b - Right coefficient.
|
|
181
|
+
* @returns Sum coefficient.
|
|
182
|
+
*/
|
|
48
183
|
add: (a: T, b: T) => T;
|
|
184
|
+
/**
|
|
185
|
+
* Subtract two coefficients.
|
|
186
|
+
* @param a - Left coefficient.
|
|
187
|
+
* @param b - Right coefficient.
|
|
188
|
+
* @returns Difference coefficient.
|
|
189
|
+
*/
|
|
49
190
|
sub: (a: T, b: T) => T;
|
|
191
|
+
/**
|
|
192
|
+
* Multiply one coefficient by a scalar/root factor.
|
|
193
|
+
* @param a - Coefficient value.
|
|
194
|
+
* @param scalar - Scalar/root factor.
|
|
195
|
+
* @returns Scaled coefficient.
|
|
196
|
+
*/
|
|
50
197
|
mul: (a: T, scalar: R) => T;
|
|
198
|
+
/**
|
|
199
|
+
* Invert one scalar/root factor.
|
|
200
|
+
* @param a - Scalar/root factor.
|
|
201
|
+
* @returns Inverse factor.
|
|
202
|
+
*/
|
|
51
203
|
inv: (a: R) => R;
|
|
52
204
|
};
|
|
205
|
+
/** Configuration for one low-level FFT loop. */
|
|
53
206
|
export type FFTCoreOpts<R> = {
|
|
207
|
+
/** Transform size. Must be a power of two. */
|
|
54
208
|
N: number;
|
|
209
|
+
/** Stage roots for the selected transform size. */
|
|
55
210
|
roots: Polynomial<R>;
|
|
211
|
+
/** Whether to run the DIT variant instead of DIF. */
|
|
56
212
|
dit: boolean;
|
|
213
|
+
/** Whether to invert butterfly placement for decode-oriented layouts. */
|
|
57
214
|
invertButterflies?: boolean;
|
|
215
|
+
/** Number of initial stages to skip. */
|
|
58
216
|
skipStages?: number;
|
|
217
|
+
/** Whether to apply bit-reversal permutation at the boundary. */
|
|
59
218
|
brp?: boolean;
|
|
60
219
|
};
|
|
220
|
+
/**
|
|
221
|
+
* Callable low-level FFT loop over one polynomial storage shape.
|
|
222
|
+
* @param values - Polynomial coefficients to transform in place.
|
|
223
|
+
* @returns The mutated input polynomial.
|
|
224
|
+
*/
|
|
61
225
|
export type FFTCoreLoop<T> = <P extends Polynomial<T>>(values: P) => P;
|
|
62
226
|
/**
|
|
63
227
|
* Constructs different flavors of FFT. radix2 implementation of low level mutating API. Flavors:
|
|
64
228
|
*
|
|
65
|
-
* - DIT (Decimation-in-Time): Bottom-Up (leaves
|
|
66
|
-
* - DIF (Decimation-in-Frequency): Top-Down (root
|
|
229
|
+
* - DIT (Decimation-in-Time): Bottom-Up (leaves to root), Cool-Turkey
|
|
230
|
+
* - DIF (Decimation-in-Frequency): Top-Down (root to leaves), Gentleman-Sande
|
|
67
231
|
*
|
|
68
232
|
* DIT takes brp input, returns natural output.
|
|
69
233
|
* DIF takes natural input, returns brp output.
|
|
@@ -74,40 +238,171 @@ export type FFTCoreLoop<T> = <P extends Polynomial<T>>(values: P) => P;
|
|
|
74
238
|
*
|
|
75
239
|
* Cyclic NTT: Rq = Zq[x]/(x^n-1). butterfly_DIT+loop_DIT OR butterfly_DIF+loop_DIT, roots are omega
|
|
76
240
|
* Negacyclic NTT: Rq = Zq[x]/(x^n+1). butterfly_DIT+loop_DIF, at least for mlkem / mldsa
|
|
241
|
+
* @param F - Field operations.
|
|
242
|
+
* @param coreOpts - FFT configuration:
|
|
243
|
+
* - `N`: Transform size. Must be a power of two.
|
|
244
|
+
* - `roots`: Stage roots for the selected transform size.
|
|
245
|
+
* - `dit`: Whether to run the DIT variant instead of DIF.
|
|
246
|
+
* - `invertButterflies` (optional): Whether to invert butterfly placement.
|
|
247
|
+
* - `skipStages` (optional): Number of initial stages to skip.
|
|
248
|
+
* - `brp` (optional): Whether to apply bit-reversal permutation at the boundary.
|
|
249
|
+
* @returns Low-level FFT loop.
|
|
250
|
+
* @throws If the FFT options or cached roots are invalid for the requested size. {@link Error}
|
|
251
|
+
* @example
|
|
252
|
+
* Constructs different flavors of FFT.
|
|
253
|
+
*
|
|
254
|
+
* ```ts
|
|
255
|
+
* import { FFTCore, rootsOfUnity } from '@noble/curves/abstract/fft.js';
|
|
256
|
+
* import { Field } from '@noble/curves/abstract/modular.js';
|
|
257
|
+
* const Fp = Field(17n);
|
|
258
|
+
* const roots = rootsOfUnity(Fp).roots(2);
|
|
259
|
+
* const loop = FFTCore(Fp, { N: 4, roots, dit: true });
|
|
260
|
+
* const values = loop([1n, 2n, 3n, 4n]);
|
|
261
|
+
* ```
|
|
77
262
|
*/
|
|
78
263
|
export declare const FFTCore: <T, R>(F: FFTOpts<T, R>, coreOpts: FFTCoreOpts<R>) => FFTCoreLoop<T>;
|
|
264
|
+
/** Forward and inverse FFT helpers for one coefficient domain. */
|
|
79
265
|
export type FFTMethods<T> = {
|
|
266
|
+
/**
|
|
267
|
+
* Apply the forward transform.
|
|
268
|
+
* @param values - Polynomial coefficients to transform.
|
|
269
|
+
* @param brpInput - Whether the input is already bit-reversed.
|
|
270
|
+
* @param brpOutput - Whether to keep the output bit-reversed.
|
|
271
|
+
* @returns Transformed copy.
|
|
272
|
+
*/
|
|
80
273
|
direct<P extends Polynomial<T>>(values: P, brpInput?: boolean, brpOutput?: boolean): P;
|
|
274
|
+
/**
|
|
275
|
+
* Apply the inverse transform.
|
|
276
|
+
* @param values - Polynomial coefficients to transform.
|
|
277
|
+
* @param brpInput - Whether the input is already bit-reversed.
|
|
278
|
+
* @param brpOutput - Whether to keep the output bit-reversed.
|
|
279
|
+
* @returns Inverse-transformed copy.
|
|
280
|
+
*/
|
|
81
281
|
inverse<P extends Polynomial<T>>(values: P, brpInput?: boolean, brpOutput?: boolean): P;
|
|
82
282
|
};
|
|
83
283
|
/**
|
|
84
284
|
* NTT aka FFT over finite field (NOT over complex numbers).
|
|
85
285
|
* Naming mirrors other libraries.
|
|
286
|
+
* @param roots - Roots-of-unity cache.
|
|
287
|
+
* @param opts - Field operations. See {@link FFTOpts}.
|
|
288
|
+
* @returns Forward and inverse FFT helpers.
|
|
289
|
+
* @example
|
|
290
|
+
* NTT aka FFT over finite field (NOT over complex numbers).
|
|
291
|
+
*
|
|
292
|
+
* ```ts
|
|
293
|
+
* import { FFT, rootsOfUnity } from '@noble/curves/abstract/fft.js';
|
|
294
|
+
* import { Field } from '@noble/curves/abstract/modular.js';
|
|
295
|
+
* const Fp = Field(17n);
|
|
296
|
+
* const fft = FFT(rootsOfUnity(Fp), Fp);
|
|
297
|
+
* const values = fft.direct([1n, 2n, 3n, 4n]);
|
|
298
|
+
* ```
|
|
86
299
|
*/
|
|
87
300
|
export declare function FFT<T>(roots: RootsOfUnity, opts: FFTOpts<T, bigint>): FFTMethods<T>;
|
|
88
|
-
|
|
89
|
-
|
|
301
|
+
/**
|
|
302
|
+
* Factory that allocates one polynomial storage container.
|
|
303
|
+
* Callers must ensure `_create(len)` returns field-zero-filled storage when `elm` is omitted,
|
|
304
|
+
* because the quadratic `mul()` / `convolve()` paths and the Kronecker-δ shortcut in
|
|
305
|
+
* `lagrange.basis()` rely on that default instead of always passing `field.ZERO` explicitly.
|
|
306
|
+
* @param len - Requested amount of coefficients.
|
|
307
|
+
* @param elm - Optional fill value.
|
|
308
|
+
* @returns Newly allocated polynomial container.
|
|
309
|
+
*/
|
|
310
|
+
export type CreatePolyFn<P extends PolyStorage<T>, T> = (len: number, elm?: T) => P;
|
|
311
|
+
/** High-level polynomial helpers layered on top of FFT and field arithmetic. */
|
|
312
|
+
export type PolyFn<P extends PolyStorage<T>, T> = {
|
|
313
|
+
/** Roots-of-unity cache used by the helper namespace. */
|
|
90
314
|
roots: RootsOfUnity;
|
|
315
|
+
/** Factory used to allocate new polynomial containers. */
|
|
91
316
|
create: CreatePolyFn<P, T>;
|
|
317
|
+
/** Optional enforced polynomial length. */
|
|
92
318
|
length?: number;
|
|
319
|
+
/**
|
|
320
|
+
* Compute the polynomial degree.
|
|
321
|
+
* @param a - Polynomial coefficients.
|
|
322
|
+
* @returns Polynomial degree.
|
|
323
|
+
*/
|
|
93
324
|
degree: (a: P) => number;
|
|
325
|
+
/**
|
|
326
|
+
* Extend or truncate one polynomial to a requested length.
|
|
327
|
+
* @param a - Polynomial coefficients.
|
|
328
|
+
* @param len - Target length.
|
|
329
|
+
* @returns Resized polynomial.
|
|
330
|
+
*/
|
|
94
331
|
extend: (a: P, len: number) => P;
|
|
332
|
+
/**
|
|
333
|
+
* Add two polynomials coefficient-wise.
|
|
334
|
+
* @param a - Left polynomial.
|
|
335
|
+
* @param b - Right polynomial.
|
|
336
|
+
* @returns Sum polynomial.
|
|
337
|
+
*/
|
|
95
338
|
add: (a: P, b: P) => P;
|
|
339
|
+
/**
|
|
340
|
+
* Subtract two polynomials coefficient-wise.
|
|
341
|
+
* @param a - Left polynomial.
|
|
342
|
+
* @param b - Right polynomial.
|
|
343
|
+
* @returns Difference polynomial.
|
|
344
|
+
*/
|
|
96
345
|
sub: (a: P, b: P) => P;
|
|
346
|
+
/**
|
|
347
|
+
* Multiply by another polynomial or by one scalar.
|
|
348
|
+
* @param a - Left polynomial.
|
|
349
|
+
* @param b - Right polynomial or scalar.
|
|
350
|
+
* @returns Product polynomial.
|
|
351
|
+
*/
|
|
97
352
|
mul: (a: P, b: P | T) => P;
|
|
353
|
+
/**
|
|
354
|
+
* Multiply coefficients point-wise.
|
|
355
|
+
* @param a - Left polynomial.
|
|
356
|
+
* @param b - Right polynomial.
|
|
357
|
+
* @returns Point-wise product polynomial.
|
|
358
|
+
*/
|
|
98
359
|
dot: (a: P, b: P) => P;
|
|
360
|
+
/**
|
|
361
|
+
* Multiply two polynomials with convolution.
|
|
362
|
+
* @param a - Left polynomial.
|
|
363
|
+
* @param b - Right polynomial.
|
|
364
|
+
* @returns Convolution product.
|
|
365
|
+
*/
|
|
99
366
|
convolve: (a: P, b: P) => P;
|
|
367
|
+
/**
|
|
368
|
+
* Apply a point-wise coefficient shift by powers of one factor.
|
|
369
|
+
* @param p - Polynomial coefficients.
|
|
370
|
+
* @param factor - Shift factor.
|
|
371
|
+
* @returns Shifted polynomial.
|
|
372
|
+
*/
|
|
100
373
|
shift: (p: P, factor: bigint) => P;
|
|
374
|
+
/**
|
|
375
|
+
* Clone one polynomial container.
|
|
376
|
+
* @param a - Polynomial coefficients.
|
|
377
|
+
* @returns Cloned polynomial.
|
|
378
|
+
*/
|
|
101
379
|
clone: (a: P) => P;
|
|
380
|
+
/**
|
|
381
|
+
* Evaluate one polynomial on a basis vector.
|
|
382
|
+
* @param a - Polynomial coefficients.
|
|
383
|
+
* @param basis - Basis vector.
|
|
384
|
+
* @returns Evaluated field element.
|
|
385
|
+
*/
|
|
102
386
|
eval: (a: P, basis: P) => T;
|
|
387
|
+
/** Helpers for monomial-basis polynomials. */
|
|
103
388
|
monomial: {
|
|
389
|
+
/** Build the monomial basis vector for one evaluation point. */
|
|
104
390
|
basis: (x: T, n: number) => P;
|
|
391
|
+
/** Evaluate a polynomial in the monomial basis. */
|
|
105
392
|
eval: (a: P, x: T) => T;
|
|
106
393
|
};
|
|
394
|
+
/** Helpers for Lagrange-basis polynomials. */
|
|
107
395
|
lagrange: {
|
|
396
|
+
/** Build the Lagrange basis vector for one evaluation point. */
|
|
108
397
|
basis: (x: T, n: number, brp?: boolean) => P;
|
|
398
|
+
/** Evaluate a polynomial in the Lagrange basis. */
|
|
109
399
|
eval: (a: P, x: T, brp?: boolean) => T;
|
|
110
400
|
};
|
|
401
|
+
/**
|
|
402
|
+
* Build the vanishing polynomial for a root set.
|
|
403
|
+
* @param roots - Root set.
|
|
404
|
+
* @returns Vanishing polynomial.
|
|
405
|
+
*/
|
|
111
406
|
vanishing: (roots: P) => P;
|
|
112
407
|
};
|
|
113
408
|
/**
|
|
@@ -121,7 +416,24 @@ export type PolyFn<P extends Polynomial<T>, T> = {
|
|
|
121
416
|
* - **Monominal** is Polynomial where `basis[i](x) == x**i` (powers)
|
|
122
417
|
* - **Array size** is domain size
|
|
123
418
|
* - **Lattice** is matrix (Polynomial of Polynomials)
|
|
419
|
+
* @param field - Field implementation.
|
|
420
|
+
* @param roots - Roots-of-unity cache.
|
|
421
|
+
* @param create - Optional polynomial factory. Runtime input validation accepts only plain `Array`
|
|
422
|
+
* and typed-array polynomial containers; arbitrary structural wrappers are intentionally rejected.
|
|
423
|
+
* @param fft - Optional FFT implementation.
|
|
424
|
+
* @param length - Optional fixed polynomial length.
|
|
425
|
+
* @returns Polynomial helper namespace.
|
|
426
|
+
* @example
|
|
427
|
+
* Build polynomial helpers, then convolve two coefficient arrays.
|
|
428
|
+
*
|
|
429
|
+
* ```ts
|
|
430
|
+
* import { poly, rootsOfUnity } from '@noble/curves/abstract/fft.js';
|
|
431
|
+
* import { Field } from '@noble/curves/abstract/modular.js';
|
|
432
|
+
* const Fp = Field(17n);
|
|
433
|
+
* const poly17 = poly(Fp, rootsOfUnity(Fp));
|
|
434
|
+
* const product = poly17.convolve([1n, 2n], [3n, 4n]);
|
|
435
|
+
* ```
|
|
124
436
|
*/
|
|
125
|
-
export declare function poly<T>(field: IField<T
|
|
126
|
-
export declare function poly<T, P extends
|
|
437
|
+
export declare function poly<T>(field: TArg<IField<T>>, roots: RootsOfUnity, create?: undefined, fft?: FFTMethods<T>, length?: number): PolyFn<T[], T>;
|
|
438
|
+
export declare function poly<T, P extends PolyStorage<T>>(field: TArg<IField<T>>, roots: RootsOfUnity, create: CreatePolyFn<P, T>, fft?: FFTMethods<T>, length?: number): PolyFn<P, T>;
|
|
127
439
|
//# sourceMappingURL=fft.d.ts.map
|
package/abstract/fft.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fft.d.ts","sourceRoot":"","sources":["../src/abstract/fft.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,W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