@noble/curves 2.0.0 → 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 +89 -24
- 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 +327 -10
- package/abstract/fft.d.ts.map +1 -1
- package/abstract/fft.js +155 -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 +135 -14
- package/ed25519.d.ts.map +1 -1
- package/ed25519.js +207 -41
- 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 +34 -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 +356 -69
- package/src/abstract/curve.ts +327 -44
- package/src/abstract/edwards.ts +367 -143
- package/src/abstract/fft.ts +371 -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 +234 -56
- 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/utils.js
CHANGED
|
@@ -3,66 +3,299 @@
|
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
5
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
6
|
-
import { abytes as abytes_, anumber, bytesToHex as bytesToHex_, concatBytes as concatBytes_, hexToBytes as hexToBytes_, } from '@noble/hashes/utils.js';
|
|
7
|
-
|
|
6
|
+
import { abytes as abytes_, anumber as anumber_, bytesToHex as bytesToHex_, concatBytes as concatBytes_, hexToBytes as hexToBytes_, isBytes as isBytes_, randomBytes as randomBytes_, } from '@noble/hashes/utils.js';
|
|
7
|
+
/**
|
|
8
|
+
* Validates that a value is a byte array.
|
|
9
|
+
* @param value - Value to validate.
|
|
10
|
+
* @param length - Optional exact byte length.
|
|
11
|
+
* @param title - Optional field name.
|
|
12
|
+
* @returns Original byte array.
|
|
13
|
+
* @example
|
|
14
|
+
* Reject non-byte input before passing data into curve code.
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* abytes(new Uint8Array(1));
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export const abytes = (value, length, title) => abytes_(value, length, title);
|
|
21
|
+
/**
|
|
22
|
+
* Validates that a value is a non-negative safe integer.
|
|
23
|
+
* @param n - Value to validate.
|
|
24
|
+
* @param title - Optional field name.
|
|
25
|
+
* @example
|
|
26
|
+
* Validate a numeric length before allocating buffers.
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* anumber(1);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export const anumber = anumber_;
|
|
33
|
+
/**
|
|
34
|
+
* Encodes bytes as lowercase hex.
|
|
35
|
+
* @param bytes - Bytes to encode.
|
|
36
|
+
* @returns Lowercase hex string.
|
|
37
|
+
* @example
|
|
38
|
+
* Serialize bytes as hex for logging or fixtures.
|
|
39
|
+
*
|
|
40
|
+
* ```ts
|
|
41
|
+
* bytesToHex(Uint8Array.of(1, 2, 3));
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export const bytesToHex = bytesToHex_;
|
|
45
|
+
/**
|
|
46
|
+
* Concatenates byte arrays.
|
|
47
|
+
* @param arrays - Byte arrays to join.
|
|
48
|
+
* @returns Concatenated bytes.
|
|
49
|
+
* @example
|
|
50
|
+
* Join domain-separated chunks into one buffer.
|
|
51
|
+
*
|
|
52
|
+
* ```ts
|
|
53
|
+
* concatBytes(Uint8Array.of(1), Uint8Array.of(2));
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export const concatBytes = (...arrays) => concatBytes_(...arrays);
|
|
57
|
+
/**
|
|
58
|
+
* Decodes lowercase or uppercase hex into bytes.
|
|
59
|
+
* @param hex - Hex string to decode.
|
|
60
|
+
* @returns Decoded bytes.
|
|
61
|
+
* @example
|
|
62
|
+
* Parse fixture hex into bytes before hashing.
|
|
63
|
+
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* hexToBytes('0102');
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export const hexToBytes = (hex) => hexToBytes_(hex);
|
|
69
|
+
/**
|
|
70
|
+
* Checks whether a value is a Uint8Array.
|
|
71
|
+
* @param a - Value to inspect.
|
|
72
|
+
* @returns `true` when `a` is a Uint8Array.
|
|
73
|
+
* @example
|
|
74
|
+
* Branch on byte input before decoding it.
|
|
75
|
+
*
|
|
76
|
+
* ```ts
|
|
77
|
+
* isBytes(new Uint8Array(1));
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export const isBytes = isBytes_;
|
|
81
|
+
/**
|
|
82
|
+
* Reads random bytes from the platform CSPRNG.
|
|
83
|
+
* @param bytesLength - Number of random bytes to read.
|
|
84
|
+
* @returns Fresh random bytes.
|
|
85
|
+
* @example
|
|
86
|
+
* Generate a random seed for a keypair.
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* randomBytes(2);
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export const randomBytes = (bytesLength) => randomBytes_(bytesLength);
|
|
8
93
|
const _0n = /* @__PURE__ */ BigInt(0);
|
|
9
94
|
const _1n = /* @__PURE__ */ BigInt(1);
|
|
95
|
+
/**
|
|
96
|
+
* Validates that a flag is boolean.
|
|
97
|
+
* @param value - Value to validate.
|
|
98
|
+
* @param title - Optional field name.
|
|
99
|
+
* @returns Original value.
|
|
100
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
101
|
+
* @example
|
|
102
|
+
* Reject non-boolean option flags early.
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* abool(true);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
10
108
|
export function abool(value, title = '') {
|
|
11
109
|
if (typeof value !== 'boolean') {
|
|
12
110
|
const prefix = title && `"${title}" `;
|
|
13
|
-
throw new
|
|
111
|
+
throw new TypeError(prefix + 'expected boolean, got type=' + typeof value);
|
|
14
112
|
}
|
|
15
113
|
return value;
|
|
16
114
|
}
|
|
17
|
-
|
|
18
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Validates that a value is a non-negative bigint or safe integer.
|
|
117
|
+
* @param n - Value to validate.
|
|
118
|
+
* @returns The same validated value.
|
|
119
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
120
|
+
* @example
|
|
121
|
+
* Validate one integer-like value before serializing it.
|
|
122
|
+
*
|
|
123
|
+
* ```ts
|
|
124
|
+
* abignumber(1n);
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export function abignumber(n) {
|
|
19
128
|
if (typeof n === 'bigint') {
|
|
20
129
|
if (!isPosBig(n))
|
|
21
|
-
throw new
|
|
130
|
+
throw new RangeError('positive bigint expected, got ' + n);
|
|
22
131
|
}
|
|
23
132
|
else
|
|
24
133
|
anumber(n);
|
|
25
134
|
return n;
|
|
26
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Validates that a value is a safe integer.
|
|
138
|
+
* @param value - Integer to validate.
|
|
139
|
+
* @param title - Optional field name.
|
|
140
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
141
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
142
|
+
* @example
|
|
143
|
+
* Validate a window size before scalar arithmetic uses it.
|
|
144
|
+
*
|
|
145
|
+
* ```ts
|
|
146
|
+
* asafenumber(1);
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
27
149
|
export function asafenumber(value, title = '') {
|
|
150
|
+
if (typeof value !== 'number') {
|
|
151
|
+
const prefix = title && `"${title}" `;
|
|
152
|
+
throw new TypeError(prefix + 'expected number, got type=' + typeof value);
|
|
153
|
+
}
|
|
28
154
|
if (!Number.isSafeInteger(value)) {
|
|
29
155
|
const prefix = title && `"${title}" `;
|
|
30
|
-
throw new
|
|
156
|
+
throw new RangeError(prefix + 'expected safe integer, got ' + value);
|
|
31
157
|
}
|
|
32
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Encodes a bigint into even-length big-endian hex.
|
|
161
|
+
* The historical "unpadded" name only means "no fixed-width field padding"; odd-length hex still
|
|
162
|
+
* gets one leading zero nibble so the result always represents whole bytes.
|
|
163
|
+
* @param num - Number to encode.
|
|
164
|
+
* @returns Big-endian hex string.
|
|
165
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
166
|
+
* @example
|
|
167
|
+
* Encode a scalar into hex without a `0x` prefix.
|
|
168
|
+
*
|
|
169
|
+
* ```ts
|
|
170
|
+
* numberToHexUnpadded(255n);
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
33
173
|
export function numberToHexUnpadded(num) {
|
|
34
174
|
const hex = abignumber(num).toString(16);
|
|
35
175
|
return hex.length & 1 ? '0' + hex : hex;
|
|
36
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Parses a big-endian hex string into bigint.
|
|
179
|
+
* Accepts odd-length hex through the native `BigInt('0x' + hex)` parser and currently surfaces the
|
|
180
|
+
* same native `SyntaxError` for malformed hex instead of wrapping it in a library-specific error.
|
|
181
|
+
* @param hex - Hex string without `0x`.
|
|
182
|
+
* @returns Parsed bigint value.
|
|
183
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
184
|
+
* @example
|
|
185
|
+
* Parse a scalar from fixture hex.
|
|
186
|
+
*
|
|
187
|
+
* ```ts
|
|
188
|
+
* hexToNumber('ff');
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
37
191
|
export function hexToNumber(hex) {
|
|
38
192
|
if (typeof hex !== 'string')
|
|
39
|
-
throw new
|
|
193
|
+
throw new TypeError('hex string expected, got ' + typeof hex);
|
|
40
194
|
return hex === '' ? _0n : BigInt('0x' + hex); // Big Endian
|
|
41
195
|
}
|
|
42
196
|
// BE: Big Endian, LE: Little Endian
|
|
197
|
+
/**
|
|
198
|
+
* Parses big-endian bytes into bigint.
|
|
199
|
+
* @param bytes - Bytes in big-endian order.
|
|
200
|
+
* @returns Parsed bigint value.
|
|
201
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
202
|
+
* @example
|
|
203
|
+
* Read a scalar encoded in network byte order.
|
|
204
|
+
*
|
|
205
|
+
* ```ts
|
|
206
|
+
* bytesToNumberBE(Uint8Array.of(1, 0));
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
43
209
|
export function bytesToNumberBE(bytes) {
|
|
44
210
|
return hexToNumber(bytesToHex_(bytes));
|
|
45
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Parses little-endian bytes into bigint.
|
|
214
|
+
* @param bytes - Bytes in little-endian order.
|
|
215
|
+
* @returns Parsed bigint value.
|
|
216
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
217
|
+
* @example
|
|
218
|
+
* Read a scalar encoded in little-endian form.
|
|
219
|
+
*
|
|
220
|
+
* ```ts
|
|
221
|
+
* bytesToNumberLE(Uint8Array.of(1, 0));
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
46
224
|
export function bytesToNumberLE(bytes) {
|
|
47
225
|
return hexToNumber(bytesToHex_(copyBytes(abytes_(bytes)).reverse()));
|
|
48
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Encodes a bigint into fixed-length big-endian bytes.
|
|
229
|
+
* @param n - Number to encode.
|
|
230
|
+
* @param len - Output length in bytes. Must be greater than zero.
|
|
231
|
+
* @returns Big-endian byte array.
|
|
232
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
233
|
+
* @example
|
|
234
|
+
* Serialize a scalar into a 32-byte field element.
|
|
235
|
+
*
|
|
236
|
+
* ```ts
|
|
237
|
+
* numberToBytesBE(255n, 2);
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
49
240
|
export function numberToBytesBE(n, len) {
|
|
50
|
-
|
|
241
|
+
anumber_(len);
|
|
242
|
+
if (len === 0)
|
|
243
|
+
throw new RangeError('zero length');
|
|
51
244
|
n = abignumber(n);
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
245
|
+
const hex = n.toString(16);
|
|
246
|
+
// Detect overflow before hex parsing so oversized values don't leak the shared odd-hex error.
|
|
247
|
+
if (hex.length > len * 2)
|
|
248
|
+
throw new RangeError('number too large');
|
|
249
|
+
return hexToBytes_(hex.padStart(len * 2, '0'));
|
|
56
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Encodes a bigint into fixed-length little-endian bytes.
|
|
253
|
+
* @param n - Number to encode.
|
|
254
|
+
* @param len - Output length in bytes.
|
|
255
|
+
* @returns Little-endian byte array.
|
|
256
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
257
|
+
* @example
|
|
258
|
+
* Serialize a scalar for little-endian protocols.
|
|
259
|
+
*
|
|
260
|
+
* ```ts
|
|
261
|
+
* numberToBytesLE(255n, 2);
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
57
264
|
export function numberToBytesLE(n, len) {
|
|
58
265
|
return numberToBytesBE(n, len).reverse();
|
|
59
266
|
}
|
|
60
267
|
// Unpadded, rarely used
|
|
268
|
+
/**
|
|
269
|
+
* Encodes a bigint into variable-length big-endian bytes.
|
|
270
|
+
* @param n - Number to encode.
|
|
271
|
+
* @returns Variable-length big-endian bytes.
|
|
272
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
273
|
+
* @example
|
|
274
|
+
* Serialize a bigint without fixed-width padding.
|
|
275
|
+
*
|
|
276
|
+
* ```ts
|
|
277
|
+
* numberToVarBytesBE(255n);
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
61
280
|
export function numberToVarBytesBE(n) {
|
|
62
281
|
return hexToBytes_(numberToHexUnpadded(abignumber(n)));
|
|
63
282
|
}
|
|
64
283
|
// Compares 2 u8a-s in kinda constant time
|
|
284
|
+
/**
|
|
285
|
+
* Compares two byte arrays in constant-ish time.
|
|
286
|
+
* @param a - Left byte array.
|
|
287
|
+
* @param b - Right byte array.
|
|
288
|
+
* @returns `true` when bytes match.
|
|
289
|
+
* @example
|
|
290
|
+
* Compare two encoded points without early exit.
|
|
291
|
+
*
|
|
292
|
+
* ```ts
|
|
293
|
+
* equalBytes(Uint8Array.of(1), Uint8Array.of(1));
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
65
296
|
export function equalBytes(a, b) {
|
|
297
|
+
a = abytes(a);
|
|
298
|
+
b = abytes(b);
|
|
66
299
|
if (a.length !== b.length)
|
|
67
300
|
return false;
|
|
68
301
|
let diff = 0;
|
|
@@ -73,33 +306,78 @@ export function equalBytes(a, b) {
|
|
|
73
306
|
/**
|
|
74
307
|
* Copies Uint8Array. We can't use u8a.slice(), because u8a can be Buffer,
|
|
75
308
|
* and Buffer#slice creates mutable copy. Never use Buffers!
|
|
309
|
+
* @param bytes - Bytes to copy.
|
|
310
|
+
* @returns Detached copy.
|
|
311
|
+
* @example
|
|
312
|
+
* Make an isolated copy before mutating serialized bytes.
|
|
313
|
+
*
|
|
314
|
+
* ```ts
|
|
315
|
+
* copyBytes(Uint8Array.of(1, 2, 3));
|
|
316
|
+
* ```
|
|
76
317
|
*/
|
|
77
318
|
export function copyBytes(bytes) {
|
|
78
|
-
|
|
319
|
+
// `Uint8Array.from(...)` would also accept arrays / other typed arrays. Keep this helper strict
|
|
320
|
+
// because callers use it at byte-validation boundaries before mutating the detached copy.
|
|
321
|
+
return Uint8Array.from(abytes(bytes));
|
|
79
322
|
}
|
|
80
323
|
/**
|
|
81
324
|
* Decodes 7-bit ASCII string to Uint8Array, throws on non-ascii symbols
|
|
82
325
|
* Should be safe to use for things expected to be ASCII.
|
|
83
326
|
* Returns exact same result as `TextEncoder` for ASCII or throws.
|
|
327
|
+
* @param ascii - ASCII input text.
|
|
328
|
+
* @returns Encoded bytes.
|
|
329
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
330
|
+
* @example
|
|
331
|
+
* Encode an ASCII domain-separation tag.
|
|
332
|
+
*
|
|
333
|
+
* ```ts
|
|
334
|
+
* asciiToBytes('ABC');
|
|
335
|
+
* ```
|
|
84
336
|
*/
|
|
85
337
|
export function asciiToBytes(ascii) {
|
|
338
|
+
if (typeof ascii !== 'string')
|
|
339
|
+
throw new TypeError('ascii string expected, got ' + typeof ascii);
|
|
86
340
|
return Uint8Array.from(ascii, (c, i) => {
|
|
87
341
|
const charCode = c.charCodeAt(0);
|
|
88
342
|
if (c.length !== 1 || charCode > 127) {
|
|
89
|
-
throw new
|
|
343
|
+
throw new RangeError(`string contains non-ASCII character "${ascii[i]}" with code ${charCode} at position ${i}`);
|
|
90
344
|
}
|
|
91
345
|
return charCode;
|
|
92
346
|
});
|
|
93
347
|
}
|
|
94
|
-
//
|
|
348
|
+
// Historical name: this accepts non-negative bigints, including zero.
|
|
95
349
|
const isPosBig = (n) => typeof n === 'bigint' && _0n <= n;
|
|
350
|
+
/**
|
|
351
|
+
* Checks whether a bigint lies inside a half-open range.
|
|
352
|
+
* @param n - Candidate value.
|
|
353
|
+
* @param min - Inclusive lower bound.
|
|
354
|
+
* @param max - Exclusive upper bound.
|
|
355
|
+
* @returns `true` when the value is inside the range.
|
|
356
|
+
* @example
|
|
357
|
+
* Check whether a candidate scalar fits the field order.
|
|
358
|
+
*
|
|
359
|
+
* ```ts
|
|
360
|
+
* inRange(2n, 1n, 3n);
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
96
363
|
export function inRange(n, min, max) {
|
|
97
364
|
return isPosBig(n) && isPosBig(min) && isPosBig(max) && min <= n && n < max;
|
|
98
365
|
}
|
|
99
366
|
/**
|
|
100
|
-
* Asserts min <= n < max
|
|
367
|
+
* Asserts `min <= n < max`. NOTE: upper bound is exclusive.
|
|
368
|
+
* @param title - Value label for error messages.
|
|
369
|
+
* @param n - Candidate value.
|
|
370
|
+
* @param min - Inclusive lower bound.
|
|
371
|
+
* @param max - Exclusive upper bound.
|
|
372
|
+
* Wrong-type inputs are not separated from out-of-range values here: they still flow through the
|
|
373
|
+
* shared `RangeError` path because this is only a throwing wrapper around `inRange(...)`.
|
|
374
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
101
375
|
* @example
|
|
102
|
-
*
|
|
376
|
+
* Assert that a bigint stays within one half-open range.
|
|
377
|
+
*
|
|
378
|
+
* ```ts
|
|
379
|
+
* aInRange('x', 2n, 1n, 256n);
|
|
380
|
+
* ```
|
|
103
381
|
*/
|
|
104
382
|
export function aInRange(title, n, min, max) {
|
|
105
383
|
// Why min <= n < max and not a (min < n < max) OR b (min <= n <= max)?
|
|
@@ -108,15 +386,28 @@ export function aInRange(title, n, min, max) {
|
|
|
108
386
|
// - b would commonly require subtraction: `inRange('x', x, 0n, P - 1n)`
|
|
109
387
|
// - our way is the cleanest: `inRange('x', x, 0n, P)
|
|
110
388
|
if (!inRange(n, min, max))
|
|
111
|
-
throw new
|
|
389
|
+
throw new RangeError('expected valid ' + title + ': ' + min + ' <= n < ' + max + ', got ' + n);
|
|
112
390
|
}
|
|
113
391
|
// Bit operations
|
|
114
392
|
/**
|
|
115
393
|
* Calculates amount of bits in a bigint.
|
|
116
394
|
* Same as `n.toString(2).length`
|
|
117
395
|
* TODO: merge with nLength in modular
|
|
396
|
+
* @param n - Value to inspect.
|
|
397
|
+
* @returns Bit length.
|
|
398
|
+
* @throws If the value is negative. {@link Error}
|
|
399
|
+
* @example
|
|
400
|
+
* Measure the bit length of a scalar before serialization.
|
|
401
|
+
*
|
|
402
|
+
* ```ts
|
|
403
|
+
* bitLen(8n);
|
|
404
|
+
* ```
|
|
118
405
|
*/
|
|
119
406
|
export function bitLen(n) {
|
|
407
|
+
// Size callers in this repo only use non-negative orders / scalars, so negative inputs are a
|
|
408
|
+
// contract bug and must not silently collapse to zero bits.
|
|
409
|
+
if (n < _0n)
|
|
410
|
+
throw new Error('expected non-negative bigint, got ' + n);
|
|
120
411
|
let len;
|
|
121
412
|
for (len = 0; n > _0n; n >>= _1n, len += 1)
|
|
122
413
|
;
|
|
@@ -126,48 +417,99 @@ export function bitLen(n) {
|
|
|
126
417
|
* Gets single bit at position.
|
|
127
418
|
* NOTE: first bit position is 0 (same as arrays)
|
|
128
419
|
* Same as `!!+Array.from(n.toString(2)).reverse()[pos]`
|
|
420
|
+
* @param n - Source value.
|
|
421
|
+
* @param pos - Bit position. Negative positions are passed through to raw
|
|
422
|
+
* bigint shift semantics; because the mask is built as `1n << pos`,
|
|
423
|
+
* they currently collapse to `0n` and make the helper a no-op.
|
|
424
|
+
* @returns Bit as bigint.
|
|
425
|
+
* @example
|
|
426
|
+
* Gets single bit at position.
|
|
427
|
+
*
|
|
428
|
+
* ```ts
|
|
429
|
+
* bitGet(5n, 0);
|
|
430
|
+
* ```
|
|
129
431
|
*/
|
|
130
432
|
export function bitGet(n, pos) {
|
|
131
433
|
return (n >> BigInt(pos)) & _1n;
|
|
132
434
|
}
|
|
133
435
|
/**
|
|
134
436
|
* Sets single bit at position.
|
|
437
|
+
* @param n - Source value.
|
|
438
|
+
* @param pos - Bit position. Negative positions are passed through to raw bigint shift semantics,
|
|
439
|
+
* so they currently behave like left shifts.
|
|
440
|
+
* @param value - Whether the bit should be set.
|
|
441
|
+
* @returns Updated bigint.
|
|
442
|
+
* @example
|
|
443
|
+
* Sets single bit at position.
|
|
444
|
+
*
|
|
445
|
+
* ```ts
|
|
446
|
+
* bitSet(0n, 1, true);
|
|
447
|
+
* ```
|
|
135
448
|
*/
|
|
136
449
|
export function bitSet(n, pos, value) {
|
|
137
|
-
|
|
450
|
+
const mask = _1n << BigInt(pos);
|
|
451
|
+
// Clearing needs AND-not here; OR with zero leaves an already-set bit untouched.
|
|
452
|
+
return value ? n | mask : n & ~mask;
|
|
138
453
|
}
|
|
139
454
|
/**
|
|
140
455
|
* Calculate mask for N bits. Not using ** operator with bigints because of old engines.
|
|
141
456
|
* Same as BigInt(`0b${Array(i).fill('1').join('')}`)
|
|
457
|
+
* @param n - Number of bits. Negative widths are currently passed through to raw bigint shift
|
|
458
|
+
* semantics and therefore produce `-1n`.
|
|
459
|
+
* @returns Bitmask value.
|
|
460
|
+
* @example
|
|
461
|
+
* Calculate mask for N bits.
|
|
462
|
+
*
|
|
463
|
+
* ```ts
|
|
464
|
+
* bitMask(4);
|
|
465
|
+
* ```
|
|
142
466
|
*/
|
|
143
467
|
export const bitMask = (n) => (_1n << BigInt(n)) - _1n;
|
|
144
468
|
/**
|
|
145
469
|
* Minimal HMAC-DRBG from NIST 800-90 for RFC6979 sigs.
|
|
146
|
-
* @
|
|
470
|
+
* @param hashLen - Hash output size in bytes. Callers are expected to pass a positive length; `0`
|
|
471
|
+
* is not rejected here and would make the internal generate loop non-progressing.
|
|
472
|
+
* @param qByteLen - Requested output size in bytes. Callers are expected to pass a positive length.
|
|
473
|
+
* @param hmacFn - HMAC implementation.
|
|
474
|
+
* @returns Function that will call DRBG until the predicate returns anything
|
|
475
|
+
* other than `undefined`.
|
|
476
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
147
477
|
* @example
|
|
148
|
-
*
|
|
149
|
-
*
|
|
478
|
+
* Build a deterministic nonce generator for RFC6979-style signing.
|
|
479
|
+
*
|
|
480
|
+
* ```ts
|
|
481
|
+
* import { createHmacDrbg } from '@noble/curves/utils.js';
|
|
482
|
+
* import { hmac } from '@noble/hashes/hmac.js';
|
|
483
|
+
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
484
|
+
* const drbg = createHmacDrbg(32, 32, (key, msg) => hmac(sha256, key, msg));
|
|
485
|
+
* const seed = new Uint8Array(32);
|
|
486
|
+
* drbg(seed, (bytes) => bytes);
|
|
487
|
+
* ```
|
|
150
488
|
*/
|
|
151
489
|
export function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
152
|
-
|
|
153
|
-
|
|
490
|
+
anumber_(hashLen, 'hashLen');
|
|
491
|
+
anumber_(qByteLen, 'qByteLen');
|
|
154
492
|
if (typeof hmacFn !== 'function')
|
|
155
|
-
throw new
|
|
156
|
-
|
|
493
|
+
throw new TypeError('hmacFn must be a function');
|
|
494
|
+
// creates Uint8Array
|
|
495
|
+
const u8n = (len) => new Uint8Array(len);
|
|
157
496
|
const NULL = Uint8Array.of();
|
|
158
497
|
const byte0 = Uint8Array.of(0x00);
|
|
159
498
|
const byte1 = Uint8Array.of(0x01);
|
|
160
499
|
const _maxDrbgIters = 1000;
|
|
161
|
-
// Step B, Step C: set hashLen to 8*ceil(hlen/8)
|
|
162
|
-
|
|
163
|
-
let
|
|
500
|
+
// Step B, Step C: set hashLen to 8*ceil(hlen/8).
|
|
501
|
+
// Minimal non-full-spec HMAC-DRBG from NIST 800-90 for RFC6979 signatures.
|
|
502
|
+
let v = u8n(hashLen);
|
|
503
|
+
// Steps B and C of RFC6979 3.2.
|
|
504
|
+
let k = u8n(hashLen);
|
|
164
505
|
let i = 0; // Iterations counter, will throw when over 1000
|
|
165
506
|
const reset = () => {
|
|
166
507
|
v.fill(1);
|
|
167
508
|
k.fill(0);
|
|
168
509
|
i = 0;
|
|
169
510
|
};
|
|
170
|
-
|
|
511
|
+
// hmac(k)(v, ...values)
|
|
512
|
+
const h = (...msgs) => hmacFn(k, concatBytes(v, ...msgs));
|
|
171
513
|
const reseed = (seed = NULL) => {
|
|
172
514
|
// HMAC-DRBG reseed() function. Steps D-G
|
|
173
515
|
k = h(byte0, seed); // k = hmac(k || v || 0x00 || seed)
|
|
@@ -189,53 +531,68 @@ export function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
|
189
531
|
out.push(sl);
|
|
190
532
|
len += v.length;
|
|
191
533
|
}
|
|
192
|
-
return
|
|
534
|
+
return concatBytes(...out);
|
|
193
535
|
};
|
|
194
536
|
const genUntil = (seed, pred) => {
|
|
195
537
|
reset();
|
|
196
538
|
reseed(seed); // Steps D-G
|
|
197
|
-
let res = undefined; // Step H: grind until
|
|
198
|
-
|
|
539
|
+
let res = undefined; // Step H: grind until the predicate accepts a candidate.
|
|
540
|
+
// Falsy values like 0 are valid outputs.
|
|
541
|
+
while ((res = pred(gen())) === undefined)
|
|
199
542
|
reseed();
|
|
200
543
|
reset();
|
|
201
544
|
return res;
|
|
202
545
|
};
|
|
203
546
|
return genUntil;
|
|
204
547
|
}
|
|
548
|
+
/**
|
|
549
|
+
* Validates declared required and optional field types on a plain object.
|
|
550
|
+
* Extra keys are intentionally ignored because many callers validate only the subset they use from
|
|
551
|
+
* richer option bags or runtime objects.
|
|
552
|
+
* @param object - Object to validate.
|
|
553
|
+
* @param fields - Required field types.
|
|
554
|
+
* @param optFields - Optional field types.
|
|
555
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
556
|
+
* @example
|
|
557
|
+
* Check user options before building a curve helper.
|
|
558
|
+
*
|
|
559
|
+
* ```ts
|
|
560
|
+
* validateObject({ flag: true }, { flag: 'boolean' });
|
|
561
|
+
* ```
|
|
562
|
+
*/
|
|
205
563
|
export function validateObject(object, fields = {}, optFields = {}) {
|
|
206
|
-
if (
|
|
207
|
-
throw new
|
|
564
|
+
if (Object.prototype.toString.call(object) !== '[object Object]')
|
|
565
|
+
throw new TypeError('expected valid options object');
|
|
208
566
|
function checkField(fieldName, expectedType, isOpt) {
|
|
567
|
+
// Config/data fields must be explicit own properties, but runtime objects such as Field
|
|
568
|
+
// instances intentionally satisfy required method slots via their shared prototype.
|
|
569
|
+
if (!isOpt && expectedType !== 'function' && !Object.hasOwn(object, fieldName))
|
|
570
|
+
throw new TypeError(`param "${fieldName}" is invalid: expected own property`);
|
|
209
571
|
const val = object[fieldName];
|
|
210
572
|
if (isOpt && val === undefined)
|
|
211
573
|
return;
|
|
212
574
|
const current = typeof val;
|
|
213
575
|
if (current !== expectedType || val === null)
|
|
214
|
-
throw new
|
|
576
|
+
throw new TypeError(`param "${fieldName}" is invalid: expected ${expectedType}, got ${current}`);
|
|
215
577
|
}
|
|
216
578
|
const iter = (f, isOpt) => Object.entries(f).forEach(([k, v]) => checkField(k, v, isOpt));
|
|
217
579
|
iter(fields, false);
|
|
218
580
|
iter(optFields, true);
|
|
219
581
|
}
|
|
220
582
|
/**
|
|
221
|
-
*
|
|
583
|
+
* Throws not implemented error.
|
|
584
|
+
* @returns Never returns.
|
|
585
|
+
* @throws If the unfinished code path is reached. {@link Error}
|
|
586
|
+
* @example
|
|
587
|
+
* Surface the placeholder error from an unfinished code path.
|
|
588
|
+
*
|
|
589
|
+
* ```ts
|
|
590
|
+
* try {
|
|
591
|
+
* notImplemented();
|
|
592
|
+
* } catch {}
|
|
593
|
+
* ```
|
|
222
594
|
*/
|
|
223
595
|
export const notImplemented = () => {
|
|
224
596
|
throw new Error('not implemented');
|
|
225
597
|
};
|
|
226
|
-
/**
|
|
227
|
-
* Memoizes (caches) computation result.
|
|
228
|
-
* Uses WeakMap: the value is going auto-cleaned by GC after last reference is removed.
|
|
229
|
-
*/
|
|
230
|
-
export function memoized(fn) {
|
|
231
|
-
const map = new WeakMap();
|
|
232
|
-
return (arg, ...args) => {
|
|
233
|
-
const val = map.get(arg);
|
|
234
|
-
if (val !== undefined)
|
|
235
|
-
return val;
|
|
236
|
-
const computed = fn(arg, ...args);
|
|
237
|
-
map.set(arg, computed);
|
|
238
|
-
return computed;
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
598
|
//# sourceMappingURL=utils.js.map
|
package/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,sEAAsE;AACtE,OAAO,EACL,MAAM,IAAI,OAAO,EACjB,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,sEAAsE;AACtE,OAAO,EACL,MAAM,IAAI,OAAO,EACjB,OAAO,IAAI,QAAQ,EACnB,UAAU,IAAI,WAAW,EACzB,WAAW,IAAI,YAAY,EAC3B,UAAU,IAAI,WAAW,EACzB,OAAO,IAAI,QAAQ,EACnB,WAAW,IAAI,YAAY,GAC5B,MAAM,wBAAwB,CAAC;AA0GhC;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAA6B,KAAQ,EAAE,MAAe,EAAE,KAAc,EAAK,EAAE,CACjG,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAM,CAAC;AACrC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,OAAO,GAAoB,QAAQ,CAAC;AACjD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,UAAU,GAAuB,WAAW,CAAC;AAC1D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAG,MAA0B,EAAoB,EAAE,CAC7E,YAAY,CAAC,GAAG,MAAM,CAAqB,CAAC;AAC9C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAW,EAAoB,EAAE,CAAC,WAAW,CAAC,GAAG,CAAqB,CAAC;AAClG;;;;;;;;;;GAUG;AACH,MAAM,CAA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