@latticexyz/world-module-erc20 2.2.22-fdb727e847024560315c10ebf32c1f924755ffe9 → 2.2.22
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/dist/{_esm-H47RQ4ED.js → _esm-4QBXERIC.js} +136 -131
- package/dist/_esm-4QBXERIC.js.map +1 -0
- package/dist/{ccip-VIBPEQNI.js → ccip-POWS7KFG.js} +3 -3
- package/dist/{chunk-XE443CMG.js → chunk-5LBWQX65.js} +732 -341
- package/dist/chunk-5LBWQX65.js.map +1 -0
- package/dist/chunk-Y6LDJZ7L.js +408 -0
- package/dist/chunk-Y6LDJZ7L.js.map +1 -0
- package/dist/internal.js +2 -2
- package/dist/{secp256k1-QT34R5PW.js → secp256k1-QCGY4Z6Q.js} +405 -624
- package/dist/secp256k1-QCGY4Z6Q.js.map +1 -0
- package/package.json +8 -8
- package/dist/_esm-H47RQ4ED.js.map +0 -1
- package/dist/chunk-M5FHJZR5.js +0 -139
- package/dist/chunk-M5FHJZR5.js.map +0 -1
- package/dist/chunk-XE443CMG.js.map +0 -1
- package/dist/secp256k1-QT34R5PW.js.map +0 -1
- /package/dist/{ccip-VIBPEQNI.js.map → ccip-POWS7KFG.js.map} +0 -0
|
@@ -1,21 +1,41 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Hash,
|
|
3
|
+
aInRange,
|
|
4
|
+
abool,
|
|
3
5
|
abytes,
|
|
6
|
+
abytes2,
|
|
4
7
|
aexists,
|
|
5
8
|
ahash,
|
|
9
|
+
anumber,
|
|
6
10
|
aoutput,
|
|
11
|
+
bitLen,
|
|
12
|
+
bitMask,
|
|
13
|
+
bytesToHex,
|
|
14
|
+
bytesToNumberBE,
|
|
15
|
+
bytesToNumberLE,
|
|
16
|
+
clean,
|
|
7
17
|
concatBytes,
|
|
18
|
+
concatBytes2,
|
|
19
|
+
createHasher,
|
|
20
|
+
createHmacDrbg,
|
|
8
21
|
createView,
|
|
22
|
+
ensureBytes,
|
|
23
|
+
hexToBytes,
|
|
24
|
+
inRange,
|
|
25
|
+
isBytes,
|
|
26
|
+
memoized,
|
|
27
|
+
numberToBytesBE,
|
|
28
|
+
numberToBytesLE,
|
|
29
|
+
numberToHexUnpadded,
|
|
9
30
|
randomBytes,
|
|
10
31
|
rotr,
|
|
11
32
|
toBytes,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} from "./chunk-PR4QN5HX.js";
|
|
33
|
+
utf8ToBytes,
|
|
34
|
+
validateObject
|
|
35
|
+
} from "./chunk-Y6LDJZ7L.js";
|
|
36
|
+
import "./chunk-PR4QN5HX.js";
|
|
17
37
|
|
|
18
|
-
// ../../node_modules/.pnpm/@noble+hashes@1.
|
|
38
|
+
// ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_md.js
|
|
19
39
|
function setBigUint64(view, byteOffset, value, isLE) {
|
|
20
40
|
if (typeof view.setBigUint64 === "function")
|
|
21
41
|
return view.setBigUint64(byteOffset, value, isLE);
|
|
@@ -37,21 +57,22 @@ function Maj(a, b, c) {
|
|
|
37
57
|
var HashMD = class extends Hash {
|
|
38
58
|
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
39
59
|
super();
|
|
40
|
-
this.blockLen = blockLen;
|
|
41
|
-
this.outputLen = outputLen;
|
|
42
|
-
this.padOffset = padOffset;
|
|
43
|
-
this.isLE = isLE;
|
|
44
60
|
this.finished = false;
|
|
45
61
|
this.length = 0;
|
|
46
62
|
this.pos = 0;
|
|
47
63
|
this.destroyed = false;
|
|
64
|
+
this.blockLen = blockLen;
|
|
65
|
+
this.outputLen = outputLen;
|
|
66
|
+
this.padOffset = padOffset;
|
|
67
|
+
this.isLE = isLE;
|
|
48
68
|
this.buffer = new Uint8Array(blockLen);
|
|
49
69
|
this.view = createView(this.buffer);
|
|
50
70
|
}
|
|
51
71
|
update(data) {
|
|
52
72
|
aexists(this);
|
|
53
|
-
const { view, buffer, blockLen } = this;
|
|
54
73
|
data = toBytes(data);
|
|
74
|
+
abytes(data);
|
|
75
|
+
const { view, buffer, blockLen } = this;
|
|
55
76
|
const len = data.length;
|
|
56
77
|
for (let pos = 0; pos < len; ) {
|
|
57
78
|
const take = Math.min(blockLen - this.pos, len - pos);
|
|
@@ -80,7 +101,7 @@ var HashMD = class extends Hash {
|
|
|
80
101
|
const { buffer, view, blockLen, isLE } = this;
|
|
81
102
|
let { pos } = this;
|
|
82
103
|
buffer[pos++] = 128;
|
|
83
|
-
this.buffer.subarray(pos)
|
|
104
|
+
clean(this.buffer.subarray(pos));
|
|
84
105
|
if (this.padOffset > blockLen - pos) {
|
|
85
106
|
this.process(view, 0);
|
|
86
107
|
pos = 0;
|
|
@@ -111,18 +132,31 @@ var HashMD = class extends Hash {
|
|
|
111
132
|
to || (to = new this.constructor());
|
|
112
133
|
to.set(...this.get());
|
|
113
134
|
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
135
|
+
to.destroyed = destroyed;
|
|
136
|
+
to.finished = finished;
|
|
114
137
|
to.length = length;
|
|
115
138
|
to.pos = pos;
|
|
116
|
-
to.finished = finished;
|
|
117
|
-
to.destroyed = destroyed;
|
|
118
139
|
if (length % blockLen)
|
|
119
140
|
to.buffer.set(buffer);
|
|
120
141
|
return to;
|
|
121
142
|
}
|
|
143
|
+
clone() {
|
|
144
|
+
return this._cloneInto();
|
|
145
|
+
}
|
|
122
146
|
};
|
|
147
|
+
var SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
148
|
+
1779033703,
|
|
149
|
+
3144134277,
|
|
150
|
+
1013904242,
|
|
151
|
+
2773480762,
|
|
152
|
+
1359893119,
|
|
153
|
+
2600822924,
|
|
154
|
+
528734635,
|
|
155
|
+
1541459225
|
|
156
|
+
]);
|
|
123
157
|
|
|
124
|
-
// ../../node_modules/.pnpm/@noble+hashes@1.
|
|
125
|
-
var SHA256_K = /* @__PURE__ */
|
|
158
|
+
// ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/sha2.js
|
|
159
|
+
var SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
126
160
|
1116352408,
|
|
127
161
|
1899447441,
|
|
128
162
|
3049323471,
|
|
@@ -188,20 +222,10 @@ var SHA256_K = /* @__PURE__ */ new Uint32Array([
|
|
|
188
222
|
3204031479,
|
|
189
223
|
3329325298
|
|
190
224
|
]);
|
|
191
|
-
var SHA256_IV = /* @__PURE__ */ new Uint32Array([
|
|
192
|
-
1779033703,
|
|
193
|
-
3144134277,
|
|
194
|
-
1013904242,
|
|
195
|
-
2773480762,
|
|
196
|
-
1359893119,
|
|
197
|
-
2600822924,
|
|
198
|
-
528734635,
|
|
199
|
-
1541459225
|
|
200
|
-
]);
|
|
201
225
|
var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
202
226
|
var SHA256 = class extends HashMD {
|
|
203
|
-
constructor() {
|
|
204
|
-
super(64,
|
|
227
|
+
constructor(outputLen = 32) {
|
|
228
|
+
super(64, outputLen, 8, false);
|
|
205
229
|
this.A = SHA256_IV[0] | 0;
|
|
206
230
|
this.B = SHA256_IV[1] | 0;
|
|
207
231
|
this.C = SHA256_IV[2] | 0;
|
|
@@ -262,16 +286,16 @@ var SHA256 = class extends HashMD {
|
|
|
262
286
|
this.set(A, B, C, D, E, F, G, H);
|
|
263
287
|
}
|
|
264
288
|
roundClean() {
|
|
265
|
-
SHA256_W
|
|
289
|
+
clean(SHA256_W);
|
|
266
290
|
}
|
|
267
291
|
destroy() {
|
|
268
292
|
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
269
|
-
this.buffer
|
|
293
|
+
clean(this.buffer);
|
|
270
294
|
}
|
|
271
295
|
};
|
|
272
|
-
var sha256 = /* @__PURE__ */
|
|
296
|
+
var sha256 = /* @__PURE__ */ createHasher(() => new SHA256());
|
|
273
297
|
|
|
274
|
-
// ../../node_modules/.pnpm/@noble+hashes@1.
|
|
298
|
+
// ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/hmac.js
|
|
275
299
|
var HMAC = class extends Hash {
|
|
276
300
|
constructor(hash, _key) {
|
|
277
301
|
super();
|
|
@@ -294,7 +318,7 @@ var HMAC = class extends Hash {
|
|
|
294
318
|
for (let i = 0; i < pad.length; i++)
|
|
295
319
|
pad[i] ^= 54 ^ 92;
|
|
296
320
|
this.oHash.update(pad);
|
|
297
|
-
pad
|
|
321
|
+
clean(pad);
|
|
298
322
|
}
|
|
299
323
|
update(buf) {
|
|
300
324
|
aexists(this);
|
|
@@ -327,6 +351,9 @@ var HMAC = class extends Hash {
|
|
|
327
351
|
to.iHash = iHash._cloneInto(to.iHash);
|
|
328
352
|
return to;
|
|
329
353
|
}
|
|
354
|
+
clone() {
|
|
355
|
+
return this._cloneInto();
|
|
356
|
+
}
|
|
330
357
|
destroy() {
|
|
331
358
|
this.destroyed = true;
|
|
332
359
|
this.oHash.destroy();
|
|
@@ -336,321 +363,35 @@ var HMAC = class extends Hash {
|
|
|
336
363
|
var hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
|
|
337
364
|
hmac.create = (hash, key) => new HMAC(hash, key);
|
|
338
365
|
|
|
339
|
-
// ../../node_modules/.pnpm/@noble+curves@1.
|
|
340
|
-
var
|
|
341
|
-
|
|
342
|
-
aInRange: () => aInRange,
|
|
343
|
-
abool: () => abool,
|
|
344
|
-
abytes: () => abytes2,
|
|
345
|
-
bitGet: () => bitGet,
|
|
346
|
-
bitLen: () => bitLen,
|
|
347
|
-
bitMask: () => bitMask,
|
|
348
|
-
bitSet: () => bitSet,
|
|
349
|
-
bytesToHex: () => bytesToHex,
|
|
350
|
-
bytesToNumberBE: () => bytesToNumberBE,
|
|
351
|
-
bytesToNumberLE: () => bytesToNumberLE,
|
|
352
|
-
concatBytes: () => concatBytes2,
|
|
353
|
-
createHmacDrbg: () => createHmacDrbg,
|
|
354
|
-
ensureBytes: () => ensureBytes,
|
|
355
|
-
equalBytes: () => equalBytes,
|
|
356
|
-
hexToBytes: () => hexToBytes,
|
|
357
|
-
hexToNumber: () => hexToNumber,
|
|
358
|
-
inRange: () => inRange,
|
|
359
|
-
isBytes: () => isBytes,
|
|
360
|
-
memoized: () => memoized,
|
|
361
|
-
notImplemented: () => notImplemented,
|
|
362
|
-
numberToBytesBE: () => numberToBytesBE,
|
|
363
|
-
numberToBytesLE: () => numberToBytesLE,
|
|
364
|
-
numberToHexUnpadded: () => numberToHexUnpadded,
|
|
365
|
-
numberToVarBytesBE: () => numberToVarBytesBE,
|
|
366
|
-
utf8ToBytes: () => utf8ToBytes,
|
|
367
|
-
validateObject: () => validateObject
|
|
368
|
-
});
|
|
369
|
-
var _0n = /* @__PURE__ */ BigInt(0);
|
|
370
|
-
var _1n = /* @__PURE__ */ BigInt(1);
|
|
366
|
+
// ../../node_modules/.pnpm/@noble+curves@1.9.1/node_modules/@noble/curves/esm/abstract/modular.js
|
|
367
|
+
var _0n = BigInt(0);
|
|
368
|
+
var _1n = BigInt(1);
|
|
371
369
|
var _2n = /* @__PURE__ */ BigInt(2);
|
|
372
|
-
function isBytes(a) {
|
|
373
|
-
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
374
|
-
}
|
|
375
|
-
function abytes2(item) {
|
|
376
|
-
if (!isBytes(item))
|
|
377
|
-
throw new Error("Uint8Array expected");
|
|
378
|
-
}
|
|
379
|
-
function abool(title, value) {
|
|
380
|
-
if (typeof value !== "boolean")
|
|
381
|
-
throw new Error(title + " boolean expected, got " + value);
|
|
382
|
-
}
|
|
383
|
-
var hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
384
|
-
function bytesToHex(bytes) {
|
|
385
|
-
abytes2(bytes);
|
|
386
|
-
let hex = "";
|
|
387
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
388
|
-
hex += hexes[bytes[i]];
|
|
389
|
-
}
|
|
390
|
-
return hex;
|
|
391
|
-
}
|
|
392
|
-
function numberToHexUnpadded(num2) {
|
|
393
|
-
const hex = num2.toString(16);
|
|
394
|
-
return hex.length & 1 ? "0" + hex : hex;
|
|
395
|
-
}
|
|
396
|
-
function hexToNumber(hex) {
|
|
397
|
-
if (typeof hex !== "string")
|
|
398
|
-
throw new Error("hex string expected, got " + typeof hex);
|
|
399
|
-
return hex === "" ? _0n : BigInt("0x" + hex);
|
|
400
|
-
}
|
|
401
|
-
var asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
402
|
-
function asciiToBase16(ch) {
|
|
403
|
-
if (ch >= asciis._0 && ch <= asciis._9)
|
|
404
|
-
return ch - asciis._0;
|
|
405
|
-
if (ch >= asciis.A && ch <= asciis.F)
|
|
406
|
-
return ch - (asciis.A - 10);
|
|
407
|
-
if (ch >= asciis.a && ch <= asciis.f)
|
|
408
|
-
return ch - (asciis.a - 10);
|
|
409
|
-
return;
|
|
410
|
-
}
|
|
411
|
-
function hexToBytes(hex) {
|
|
412
|
-
if (typeof hex !== "string")
|
|
413
|
-
throw new Error("hex string expected, got " + typeof hex);
|
|
414
|
-
const hl = hex.length;
|
|
415
|
-
const al = hl / 2;
|
|
416
|
-
if (hl % 2)
|
|
417
|
-
throw new Error("hex string expected, got unpadded hex of length " + hl);
|
|
418
|
-
const array = new Uint8Array(al);
|
|
419
|
-
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
420
|
-
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
421
|
-
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
422
|
-
if (n1 === void 0 || n2 === void 0) {
|
|
423
|
-
const char = hex[hi] + hex[hi + 1];
|
|
424
|
-
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
425
|
-
}
|
|
426
|
-
array[ai] = n1 * 16 + n2;
|
|
427
|
-
}
|
|
428
|
-
return array;
|
|
429
|
-
}
|
|
430
|
-
function bytesToNumberBE(bytes) {
|
|
431
|
-
return hexToNumber(bytesToHex(bytes));
|
|
432
|
-
}
|
|
433
|
-
function bytesToNumberLE(bytes) {
|
|
434
|
-
abytes2(bytes);
|
|
435
|
-
return hexToNumber(bytesToHex(Uint8Array.from(bytes).reverse()));
|
|
436
|
-
}
|
|
437
|
-
function numberToBytesBE(n, len) {
|
|
438
|
-
return hexToBytes(n.toString(16).padStart(len * 2, "0"));
|
|
439
|
-
}
|
|
440
|
-
function numberToBytesLE(n, len) {
|
|
441
|
-
return numberToBytesBE(n, len).reverse();
|
|
442
|
-
}
|
|
443
|
-
function numberToVarBytesBE(n) {
|
|
444
|
-
return hexToBytes(numberToHexUnpadded(n));
|
|
445
|
-
}
|
|
446
|
-
function ensureBytes(title, hex, expectedLength) {
|
|
447
|
-
let res;
|
|
448
|
-
if (typeof hex === "string") {
|
|
449
|
-
try {
|
|
450
|
-
res = hexToBytes(hex);
|
|
451
|
-
} catch (e) {
|
|
452
|
-
throw new Error(title + " must be hex string or Uint8Array, cause: " + e);
|
|
453
|
-
}
|
|
454
|
-
} else if (isBytes(hex)) {
|
|
455
|
-
res = Uint8Array.from(hex);
|
|
456
|
-
} else {
|
|
457
|
-
throw new Error(title + " must be hex string or Uint8Array");
|
|
458
|
-
}
|
|
459
|
-
const len = res.length;
|
|
460
|
-
if (typeof expectedLength === "number" && len !== expectedLength)
|
|
461
|
-
throw new Error(title + " of length " + expectedLength + " expected, got " + len);
|
|
462
|
-
return res;
|
|
463
|
-
}
|
|
464
|
-
function concatBytes2(...arrays) {
|
|
465
|
-
let sum = 0;
|
|
466
|
-
for (let i = 0; i < arrays.length; i++) {
|
|
467
|
-
const a = arrays[i];
|
|
468
|
-
abytes2(a);
|
|
469
|
-
sum += a.length;
|
|
470
|
-
}
|
|
471
|
-
const res = new Uint8Array(sum);
|
|
472
|
-
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
473
|
-
const a = arrays[i];
|
|
474
|
-
res.set(a, pad);
|
|
475
|
-
pad += a.length;
|
|
476
|
-
}
|
|
477
|
-
return res;
|
|
478
|
-
}
|
|
479
|
-
function equalBytes(a, b) {
|
|
480
|
-
if (a.length !== b.length)
|
|
481
|
-
return false;
|
|
482
|
-
let diff = 0;
|
|
483
|
-
for (let i = 0; i < a.length; i++)
|
|
484
|
-
diff |= a[i] ^ b[i];
|
|
485
|
-
return diff === 0;
|
|
486
|
-
}
|
|
487
|
-
function utf8ToBytes(str) {
|
|
488
|
-
if (typeof str !== "string")
|
|
489
|
-
throw new Error("string expected");
|
|
490
|
-
return new Uint8Array(new TextEncoder().encode(str));
|
|
491
|
-
}
|
|
492
|
-
var isPosBig = (n) => typeof n === "bigint" && _0n <= n;
|
|
493
|
-
function inRange(n, min, max) {
|
|
494
|
-
return isPosBig(n) && isPosBig(min) && isPosBig(max) && min <= n && n < max;
|
|
495
|
-
}
|
|
496
|
-
function aInRange(title, n, min, max) {
|
|
497
|
-
if (!inRange(n, min, max))
|
|
498
|
-
throw new Error("expected valid " + title + ": " + min + " <= n < " + max + ", got " + n);
|
|
499
|
-
}
|
|
500
|
-
function bitLen(n) {
|
|
501
|
-
let len;
|
|
502
|
-
for (len = 0; n > _0n; n >>= _1n, len += 1)
|
|
503
|
-
;
|
|
504
|
-
return len;
|
|
505
|
-
}
|
|
506
|
-
function bitGet(n, pos) {
|
|
507
|
-
return n >> BigInt(pos) & _1n;
|
|
508
|
-
}
|
|
509
|
-
function bitSet(n, pos, value) {
|
|
510
|
-
return n | (value ? _1n : _0n) << BigInt(pos);
|
|
511
|
-
}
|
|
512
|
-
var bitMask = (n) => (_2n << BigInt(n - 1)) - _1n;
|
|
513
|
-
var u8n = (data) => new Uint8Array(data);
|
|
514
|
-
var u8fr = (arr) => Uint8Array.from(arr);
|
|
515
|
-
function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
516
|
-
if (typeof hashLen !== "number" || hashLen < 2)
|
|
517
|
-
throw new Error("hashLen must be a number");
|
|
518
|
-
if (typeof qByteLen !== "number" || qByteLen < 2)
|
|
519
|
-
throw new Error("qByteLen must be a number");
|
|
520
|
-
if (typeof hmacFn !== "function")
|
|
521
|
-
throw new Error("hmacFn must be a function");
|
|
522
|
-
let v = u8n(hashLen);
|
|
523
|
-
let k = u8n(hashLen);
|
|
524
|
-
let i = 0;
|
|
525
|
-
const reset = () => {
|
|
526
|
-
v.fill(1);
|
|
527
|
-
k.fill(0);
|
|
528
|
-
i = 0;
|
|
529
|
-
};
|
|
530
|
-
const h = (...b) => hmacFn(k, v, ...b);
|
|
531
|
-
const reseed = (seed = u8n()) => {
|
|
532
|
-
k = h(u8fr([0]), seed);
|
|
533
|
-
v = h();
|
|
534
|
-
if (seed.length === 0)
|
|
535
|
-
return;
|
|
536
|
-
k = h(u8fr([1]), seed);
|
|
537
|
-
v = h();
|
|
538
|
-
};
|
|
539
|
-
const gen = () => {
|
|
540
|
-
if (i++ >= 1e3)
|
|
541
|
-
throw new Error("drbg: tried 1000 values");
|
|
542
|
-
let len = 0;
|
|
543
|
-
const out = [];
|
|
544
|
-
while (len < qByteLen) {
|
|
545
|
-
v = h();
|
|
546
|
-
const sl = v.slice();
|
|
547
|
-
out.push(sl);
|
|
548
|
-
len += v.length;
|
|
549
|
-
}
|
|
550
|
-
return concatBytes2(...out);
|
|
551
|
-
};
|
|
552
|
-
const genUntil = (seed, pred) => {
|
|
553
|
-
reset();
|
|
554
|
-
reseed(seed);
|
|
555
|
-
let res = void 0;
|
|
556
|
-
while (!(res = pred(gen())))
|
|
557
|
-
reseed();
|
|
558
|
-
reset();
|
|
559
|
-
return res;
|
|
560
|
-
};
|
|
561
|
-
return genUntil;
|
|
562
|
-
}
|
|
563
|
-
var validatorFns = {
|
|
564
|
-
bigint: (val) => typeof val === "bigint",
|
|
565
|
-
function: (val) => typeof val === "function",
|
|
566
|
-
boolean: (val) => typeof val === "boolean",
|
|
567
|
-
string: (val) => typeof val === "string",
|
|
568
|
-
stringOrUint8Array: (val) => typeof val === "string" || isBytes(val),
|
|
569
|
-
isSafeInteger: (val) => Number.isSafeInteger(val),
|
|
570
|
-
array: (val) => Array.isArray(val),
|
|
571
|
-
field: (val, object) => object.Fp.isValid(val),
|
|
572
|
-
hash: (val) => typeof val === "function" && Number.isSafeInteger(val.outputLen)
|
|
573
|
-
};
|
|
574
|
-
function validateObject(object, validators, optValidators = {}) {
|
|
575
|
-
const checkField = (fieldName, type, isOptional) => {
|
|
576
|
-
const checkVal = validatorFns[type];
|
|
577
|
-
if (typeof checkVal !== "function")
|
|
578
|
-
throw new Error("invalid validator function");
|
|
579
|
-
const val = object[fieldName];
|
|
580
|
-
if (isOptional && val === void 0)
|
|
581
|
-
return;
|
|
582
|
-
if (!checkVal(val, object)) {
|
|
583
|
-
throw new Error("param " + String(fieldName) + " is invalid. Expected " + type + ", got " + val);
|
|
584
|
-
}
|
|
585
|
-
};
|
|
586
|
-
for (const [fieldName, type] of Object.entries(validators))
|
|
587
|
-
checkField(fieldName, type, false);
|
|
588
|
-
for (const [fieldName, type] of Object.entries(optValidators))
|
|
589
|
-
checkField(fieldName, type, true);
|
|
590
|
-
return object;
|
|
591
|
-
}
|
|
592
|
-
var notImplemented = () => {
|
|
593
|
-
throw new Error("not implemented");
|
|
594
|
-
};
|
|
595
|
-
function memoized(fn) {
|
|
596
|
-
const map = /* @__PURE__ */ new WeakMap();
|
|
597
|
-
return (arg, ...args) => {
|
|
598
|
-
const val = map.get(arg);
|
|
599
|
-
if (val !== void 0)
|
|
600
|
-
return val;
|
|
601
|
-
const computed = fn(arg, ...args);
|
|
602
|
-
map.set(arg, computed);
|
|
603
|
-
return computed;
|
|
604
|
-
};
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
// ../../node_modules/.pnpm/@noble+curves@1.8.1/node_modules/@noble/curves/esm/abstract/modular.js
|
|
608
|
-
var _0n2 = BigInt(0);
|
|
609
|
-
var _1n2 = BigInt(1);
|
|
610
|
-
var _2n2 = /* @__PURE__ */ BigInt(2);
|
|
611
370
|
var _3n = /* @__PURE__ */ BigInt(3);
|
|
612
371
|
var _4n = /* @__PURE__ */ BigInt(4);
|
|
613
372
|
var _5n = /* @__PURE__ */ BigInt(5);
|
|
614
373
|
var _8n = /* @__PURE__ */ BigInt(8);
|
|
615
|
-
var _9n = /* @__PURE__ */ BigInt(9);
|
|
616
|
-
var _16n = /* @__PURE__ */ BigInt(16);
|
|
617
374
|
function mod(a, b) {
|
|
618
375
|
const result = a % b;
|
|
619
|
-
return result >=
|
|
620
|
-
}
|
|
621
|
-
function pow(num2, power, modulo) {
|
|
622
|
-
if (power < _0n2)
|
|
623
|
-
throw new Error("invalid exponent, negatives unsupported");
|
|
624
|
-
if (modulo <= _0n2)
|
|
625
|
-
throw new Error("invalid modulus");
|
|
626
|
-
if (modulo === _1n2)
|
|
627
|
-
return _0n2;
|
|
628
|
-
let res = _1n2;
|
|
629
|
-
while (power > _0n2) {
|
|
630
|
-
if (power & _1n2)
|
|
631
|
-
res = res * num2 % modulo;
|
|
632
|
-
num2 = num2 * num2 % modulo;
|
|
633
|
-
power >>= _1n2;
|
|
634
|
-
}
|
|
635
|
-
return res;
|
|
376
|
+
return result >= _0n ? result : b + result;
|
|
636
377
|
}
|
|
637
378
|
function pow2(x, power, modulo) {
|
|
638
379
|
let res = x;
|
|
639
|
-
while (power-- >
|
|
380
|
+
while (power-- > _0n) {
|
|
640
381
|
res *= res;
|
|
641
382
|
res %= modulo;
|
|
642
383
|
}
|
|
643
384
|
return res;
|
|
644
385
|
}
|
|
645
386
|
function invert(number, modulo) {
|
|
646
|
-
if (number ===
|
|
387
|
+
if (number === _0n)
|
|
647
388
|
throw new Error("invert: expected non-zero number");
|
|
648
|
-
if (modulo <=
|
|
389
|
+
if (modulo <= _0n)
|
|
649
390
|
throw new Error("invert: expected positive modulus, got " + modulo);
|
|
650
391
|
let a = mod(number, modulo);
|
|
651
392
|
let b = modulo;
|
|
652
|
-
let x =
|
|
653
|
-
while (a !==
|
|
393
|
+
let x = _0n, y = _1n, u = _1n, v = _0n;
|
|
394
|
+
while (a !== _0n) {
|
|
654
395
|
const q = b / a;
|
|
655
396
|
const r = b % a;
|
|
656
397
|
const m = x - u * q;
|
|
@@ -658,79 +399,82 @@ function invert(number, modulo) {
|
|
|
658
399
|
b = a, a = r, x = u, y = v, u = m, v = n;
|
|
659
400
|
}
|
|
660
401
|
const gcd = b;
|
|
661
|
-
if (gcd !==
|
|
402
|
+
if (gcd !== _1n)
|
|
662
403
|
throw new Error("invert: does not exist");
|
|
663
404
|
return mod(x, modulo);
|
|
664
405
|
}
|
|
406
|
+
function sqrt3mod4(Fp, n) {
|
|
407
|
+
const p1div4 = (Fp.ORDER + _1n) / _4n;
|
|
408
|
+
const root = Fp.pow(n, p1div4);
|
|
409
|
+
if (!Fp.eql(Fp.sqr(root), n))
|
|
410
|
+
throw new Error("Cannot find square root");
|
|
411
|
+
return root;
|
|
412
|
+
}
|
|
413
|
+
function sqrt5mod8(Fp, n) {
|
|
414
|
+
const p5div8 = (Fp.ORDER - _5n) / _8n;
|
|
415
|
+
const n2 = Fp.mul(n, _2n);
|
|
416
|
+
const v = Fp.pow(n2, p5div8);
|
|
417
|
+
const nv = Fp.mul(n, v);
|
|
418
|
+
const i = Fp.mul(Fp.mul(nv, _2n), v);
|
|
419
|
+
const root = Fp.mul(nv, Fp.sub(i, Fp.ONE));
|
|
420
|
+
if (!Fp.eql(Fp.sqr(root), n))
|
|
421
|
+
throw new Error("Cannot find square root");
|
|
422
|
+
return root;
|
|
423
|
+
}
|
|
665
424
|
function tonelliShanks(P) {
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
425
|
+
if (P < BigInt(3))
|
|
426
|
+
throw new Error("sqrt is not defined for small field");
|
|
427
|
+
let Q = P - _1n;
|
|
428
|
+
let S = 0;
|
|
429
|
+
while (Q % _2n === _0n) {
|
|
430
|
+
Q /= _2n;
|
|
431
|
+
S++;
|
|
673
432
|
}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
throw new Error("Cannot find square root");
|
|
680
|
-
return root;
|
|
681
|
-
};
|
|
433
|
+
let Z = _2n;
|
|
434
|
+
const _Fp = Field(P);
|
|
435
|
+
while (FpLegendre(_Fp, Z) === 1) {
|
|
436
|
+
if (Z++ > 1e3)
|
|
437
|
+
throw new Error("Cannot find square root: probably non-prime P");
|
|
682
438
|
}
|
|
683
|
-
|
|
439
|
+
if (S === 1)
|
|
440
|
+
return sqrt3mod4;
|
|
441
|
+
let cc = _Fp.pow(Z, Q);
|
|
442
|
+
const Q1div2 = (Q + _1n) / _2n;
|
|
684
443
|
return function tonelliSlow(Fp, n) {
|
|
685
|
-
if (Fp.
|
|
444
|
+
if (Fp.is0(n))
|
|
445
|
+
return n;
|
|
446
|
+
if (FpLegendre(Fp, n) !== 1)
|
|
686
447
|
throw new Error("Cannot find square root");
|
|
687
|
-
let
|
|
688
|
-
let
|
|
689
|
-
let
|
|
690
|
-
let
|
|
691
|
-
while (!Fp.eql(
|
|
692
|
-
if (Fp.
|
|
448
|
+
let M = S;
|
|
449
|
+
let c = Fp.mul(Fp.ONE, cc);
|
|
450
|
+
let t = Fp.pow(n, Q);
|
|
451
|
+
let R = Fp.pow(n, Q1div2);
|
|
452
|
+
while (!Fp.eql(t, Fp.ONE)) {
|
|
453
|
+
if (Fp.is0(t))
|
|
693
454
|
return Fp.ZERO;
|
|
694
|
-
let
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
455
|
+
let i = 1;
|
|
456
|
+
let t_tmp = Fp.sqr(t);
|
|
457
|
+
while (!Fp.eql(t_tmp, Fp.ONE)) {
|
|
458
|
+
i++;
|
|
459
|
+
t_tmp = Fp.sqr(t_tmp);
|
|
460
|
+
if (i === M)
|
|
461
|
+
throw new Error("Cannot find square root");
|
|
699
462
|
}
|
|
700
|
-
const
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
463
|
+
const exponent = _1n << BigInt(M - i - 1);
|
|
464
|
+
const b = Fp.pow(c, exponent);
|
|
465
|
+
M = i;
|
|
466
|
+
c = Fp.sqr(b);
|
|
467
|
+
t = Fp.mul(t, c);
|
|
468
|
+
R = Fp.mul(R, b);
|
|
469
|
+
}
|
|
470
|
+
return R;
|
|
707
471
|
};
|
|
708
472
|
}
|
|
709
473
|
function FpSqrt(P) {
|
|
710
|
-
if (P % _4n === _3n)
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
if (!Fp.eql(Fp.sqr(root), n))
|
|
715
|
-
throw new Error("Cannot find square root");
|
|
716
|
-
return root;
|
|
717
|
-
};
|
|
718
|
-
}
|
|
719
|
-
if (P % _8n === _5n) {
|
|
720
|
-
const c1 = (P - _5n) / _8n;
|
|
721
|
-
return function sqrt5mod8(Fp, n) {
|
|
722
|
-
const n2 = Fp.mul(n, _2n2);
|
|
723
|
-
const v = Fp.pow(n2, c1);
|
|
724
|
-
const nv = Fp.mul(n, v);
|
|
725
|
-
const i = Fp.mul(Fp.mul(nv, _2n2), v);
|
|
726
|
-
const root = Fp.mul(nv, Fp.sub(i, Fp.ONE));
|
|
727
|
-
if (!Fp.eql(Fp.sqr(root), n))
|
|
728
|
-
throw new Error("Cannot find square root");
|
|
729
|
-
return root;
|
|
730
|
-
};
|
|
731
|
-
}
|
|
732
|
-
if (P % _16n === _9n) {
|
|
733
|
-
}
|
|
474
|
+
if (P % _4n === _3n)
|
|
475
|
+
return sqrt3mod4;
|
|
476
|
+
if (P % _8n === _5n)
|
|
477
|
+
return sqrt5mod8;
|
|
734
478
|
return tonelliShanks(P);
|
|
735
479
|
}
|
|
736
480
|
var FIELD_FIELDS = [
|
|
@@ -765,47 +509,59 @@ function validateField(field) {
|
|
|
765
509
|
}, initial);
|
|
766
510
|
return validateObject(field, opts);
|
|
767
511
|
}
|
|
768
|
-
function FpPow(
|
|
769
|
-
if (power <
|
|
512
|
+
function FpPow(Fp, num2, power) {
|
|
513
|
+
if (power < _0n)
|
|
770
514
|
throw new Error("invalid exponent, negatives unsupported");
|
|
771
|
-
if (power ===
|
|
772
|
-
return
|
|
773
|
-
if (power ===
|
|
515
|
+
if (power === _0n)
|
|
516
|
+
return Fp.ONE;
|
|
517
|
+
if (power === _1n)
|
|
774
518
|
return num2;
|
|
775
|
-
let p =
|
|
519
|
+
let p = Fp.ONE;
|
|
776
520
|
let d = num2;
|
|
777
|
-
while (power >
|
|
778
|
-
if (power &
|
|
779
|
-
p =
|
|
780
|
-
d =
|
|
781
|
-
power >>=
|
|
521
|
+
while (power > _0n) {
|
|
522
|
+
if (power & _1n)
|
|
523
|
+
p = Fp.mul(p, d);
|
|
524
|
+
d = Fp.sqr(d);
|
|
525
|
+
power >>= _1n;
|
|
782
526
|
}
|
|
783
527
|
return p;
|
|
784
528
|
}
|
|
785
|
-
function FpInvertBatch(
|
|
786
|
-
const
|
|
787
|
-
const
|
|
788
|
-
if (
|
|
529
|
+
function FpInvertBatch(Fp, nums, passZero = false) {
|
|
530
|
+
const inverted = new Array(nums.length).fill(passZero ? Fp.ZERO : void 0);
|
|
531
|
+
const multipliedAcc = nums.reduce((acc, num2, i) => {
|
|
532
|
+
if (Fp.is0(num2))
|
|
789
533
|
return acc;
|
|
790
|
-
|
|
791
|
-
return
|
|
792
|
-
},
|
|
793
|
-
const
|
|
534
|
+
inverted[i] = acc;
|
|
535
|
+
return Fp.mul(acc, num2);
|
|
536
|
+
}, Fp.ONE);
|
|
537
|
+
const invertedAcc = Fp.inv(multipliedAcc);
|
|
794
538
|
nums.reduceRight((acc, num2, i) => {
|
|
795
|
-
if (
|
|
539
|
+
if (Fp.is0(num2))
|
|
796
540
|
return acc;
|
|
797
|
-
|
|
798
|
-
return
|
|
799
|
-
},
|
|
800
|
-
return
|
|
541
|
+
inverted[i] = Fp.mul(acc, inverted[i]);
|
|
542
|
+
return Fp.mul(acc, num2);
|
|
543
|
+
}, invertedAcc);
|
|
544
|
+
return inverted;
|
|
545
|
+
}
|
|
546
|
+
function FpLegendre(Fp, n) {
|
|
547
|
+
const p1mod2 = (Fp.ORDER - _1n) / _2n;
|
|
548
|
+
const powered = Fp.pow(n, p1mod2);
|
|
549
|
+
const yes = Fp.eql(powered, Fp.ONE);
|
|
550
|
+
const zero = Fp.eql(powered, Fp.ZERO);
|
|
551
|
+
const no = Fp.eql(powered, Fp.neg(Fp.ONE));
|
|
552
|
+
if (!yes && !zero && !no)
|
|
553
|
+
throw new Error("invalid Legendre symbol result");
|
|
554
|
+
return yes ? 1 : zero ? 0 : -1;
|
|
801
555
|
}
|
|
802
556
|
function nLength(n, nBitLength) {
|
|
557
|
+
if (nBitLength !== void 0)
|
|
558
|
+
anumber(nBitLength);
|
|
803
559
|
const _nBitLength = nBitLength !== void 0 ? nBitLength : n.toString(2).length;
|
|
804
560
|
const nByteLength = Math.ceil(_nBitLength / 8);
|
|
805
561
|
return { nBitLength: _nBitLength, nByteLength };
|
|
806
562
|
}
|
|
807
563
|
function Field(ORDER, bitLen2, isLE = false, redef = {}) {
|
|
808
|
-
if (ORDER <=
|
|
564
|
+
if (ORDER <= _0n)
|
|
809
565
|
throw new Error("invalid field: expected ORDER > 0, got " + ORDER);
|
|
810
566
|
const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, bitLen2);
|
|
811
567
|
if (BYTES > 2048)
|
|
@@ -817,16 +573,16 @@ function Field(ORDER, bitLen2, isLE = false, redef = {}) {
|
|
|
817
573
|
BITS,
|
|
818
574
|
BYTES,
|
|
819
575
|
MASK: bitMask(BITS),
|
|
820
|
-
ZERO:
|
|
821
|
-
ONE:
|
|
576
|
+
ZERO: _0n,
|
|
577
|
+
ONE: _1n,
|
|
822
578
|
create: (num2) => mod(num2, ORDER),
|
|
823
579
|
isValid: (num2) => {
|
|
824
580
|
if (typeof num2 !== "bigint")
|
|
825
581
|
throw new Error("invalid field element: expected bigint, got " + typeof num2);
|
|
826
|
-
return
|
|
582
|
+
return _0n <= num2 && num2 < ORDER;
|
|
827
583
|
},
|
|
828
|
-
is0: (num2) => num2 ===
|
|
829
|
-
isOdd: (num2) => (num2 &
|
|
584
|
+
is0: (num2) => num2 === _0n,
|
|
585
|
+
isOdd: (num2) => (num2 & _1n) === _1n,
|
|
830
586
|
neg: (num2) => mod(-num2, ORDER),
|
|
831
587
|
eql: (lhs, rhs) => lhs === rhs,
|
|
832
588
|
sqr: (num2) => mod(num2 * num2, ORDER),
|
|
@@ -846,16 +602,17 @@ function Field(ORDER, bitLen2, isLE = false, redef = {}) {
|
|
|
846
602
|
sqrtP = FpSqrt(ORDER);
|
|
847
603
|
return sqrtP(f, n);
|
|
848
604
|
}),
|
|
849
|
-
invertBatch: (lst) => FpInvertBatch(f, lst),
|
|
850
|
-
// TODO: do we really need constant cmov?
|
|
851
|
-
// We don't have const-time bigints anyway, so probably will be not very useful
|
|
852
|
-
cmov: (a, b, c) => c ? b : a,
|
|
853
605
|
toBytes: (num2) => isLE ? numberToBytesLE(num2, BYTES) : numberToBytesBE(num2, BYTES),
|
|
854
606
|
fromBytes: (bytes) => {
|
|
855
607
|
if (bytes.length !== BYTES)
|
|
856
608
|
throw new Error("Field.fromBytes: expected " + BYTES + " bytes, got " + bytes.length);
|
|
857
609
|
return isLE ? bytesToNumberLE(bytes) : bytesToNumberBE(bytes);
|
|
858
|
-
}
|
|
610
|
+
},
|
|
611
|
+
// TODO: we don't need it here, move out to separate fn
|
|
612
|
+
invertBatch: (lst) => FpInvertBatch(f, lst),
|
|
613
|
+
// We can't move this out because Fp6, Fp12 implement it
|
|
614
|
+
// and it's unclear what to return in there.
|
|
615
|
+
cmov: (a, b, c) => c ? b : a
|
|
859
616
|
});
|
|
860
617
|
return Object.freeze(f);
|
|
861
618
|
}
|
|
@@ -876,13 +633,13 @@ function mapHashToField(key, fieldOrder, isLE = false) {
|
|
|
876
633
|
if (len < 16 || len < minLen || len > 1024)
|
|
877
634
|
throw new Error("expected " + minLen + "-1024 bytes of input, got " + len);
|
|
878
635
|
const num2 = isLE ? bytesToNumberLE(key) : bytesToNumberBE(key);
|
|
879
|
-
const reduced = mod(num2, fieldOrder -
|
|
636
|
+
const reduced = mod(num2, fieldOrder - _1n) + _1n;
|
|
880
637
|
return isLE ? numberToBytesLE(reduced, fieldLen) : numberToBytesBE(reduced, fieldLen);
|
|
881
638
|
}
|
|
882
639
|
|
|
883
|
-
// ../../node_modules/.pnpm/@noble+curves@1.
|
|
884
|
-
var
|
|
885
|
-
var
|
|
640
|
+
// ../../node_modules/.pnpm/@noble+curves@1.9.1/node_modules/@noble/curves/esm/abstract/curve.js
|
|
641
|
+
var _0n2 = BigInt(0);
|
|
642
|
+
var _1n2 = BigInt(1);
|
|
886
643
|
function constTimeNegate(condition, item) {
|
|
887
644
|
const neg = item.negate();
|
|
888
645
|
return condition ? neg : item;
|
|
@@ -891,11 +648,30 @@ function validateW(W, bits) {
|
|
|
891
648
|
if (!Number.isSafeInteger(W) || W <= 0 || W > bits)
|
|
892
649
|
throw new Error("invalid window size, expected [1.." + bits + "], got W=" + W);
|
|
893
650
|
}
|
|
894
|
-
function calcWOpts(W,
|
|
895
|
-
validateW(W,
|
|
896
|
-
const windows = Math.ceil(
|
|
651
|
+
function calcWOpts(W, scalarBits) {
|
|
652
|
+
validateW(W, scalarBits);
|
|
653
|
+
const windows = Math.ceil(scalarBits / W) + 1;
|
|
897
654
|
const windowSize = 2 ** (W - 1);
|
|
898
|
-
|
|
655
|
+
const maxNumber = 2 ** W;
|
|
656
|
+
const mask = bitMask(W);
|
|
657
|
+
const shiftBy = BigInt(W);
|
|
658
|
+
return { windows, windowSize, mask, maxNumber, shiftBy };
|
|
659
|
+
}
|
|
660
|
+
function calcOffsets(n, window, wOpts) {
|
|
661
|
+
const { windowSize, mask, maxNumber, shiftBy } = wOpts;
|
|
662
|
+
let wbits = Number(n & mask);
|
|
663
|
+
let nextN = n >> shiftBy;
|
|
664
|
+
if (wbits > windowSize) {
|
|
665
|
+
wbits -= maxNumber;
|
|
666
|
+
nextN += _1n2;
|
|
667
|
+
}
|
|
668
|
+
const offsetStart = window * windowSize;
|
|
669
|
+
const offset = offsetStart + Math.abs(wbits) - 1;
|
|
670
|
+
const isZero = wbits === 0;
|
|
671
|
+
const isNeg = wbits < 0;
|
|
672
|
+
const isNegF = window % 2 !== 0;
|
|
673
|
+
const offsetF = offsetStart;
|
|
674
|
+
return { nextN, offset, isZero, isNeg, isNegF, offsetF };
|
|
899
675
|
}
|
|
900
676
|
function validateMSMPoints(points, c) {
|
|
901
677
|
if (!Array.isArray(points))
|
|
@@ -927,11 +703,11 @@ function wNAF(c, bits) {
|
|
|
927
703
|
// non-const time multiplication ladder
|
|
928
704
|
unsafeLadder(elm, n, p = c.ZERO) {
|
|
929
705
|
let d = elm;
|
|
930
|
-
while (n >
|
|
931
|
-
if (n &
|
|
706
|
+
while (n > _0n2) {
|
|
707
|
+
if (n & _1n2)
|
|
932
708
|
p = p.add(d);
|
|
933
709
|
d = d.double();
|
|
934
|
-
n >>=
|
|
710
|
+
n >>= _1n2;
|
|
935
711
|
}
|
|
936
712
|
return p;
|
|
937
713
|
},
|
|
@@ -971,28 +747,16 @@ function wNAF(c, bits) {
|
|
|
971
747
|
* @returns real and fake (for const-time) points
|
|
972
748
|
*/
|
|
973
749
|
wNAF(W, precomputes, n) {
|
|
974
|
-
const { windows, windowSize } = calcWOpts(W, bits);
|
|
975
750
|
let p = c.ZERO;
|
|
976
751
|
let f = c.BASE;
|
|
977
|
-
const
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
n >>= shiftBy;
|
|
984
|
-
if (wbits > windowSize) {
|
|
985
|
-
wbits -= maxNumber;
|
|
986
|
-
n += _1n3;
|
|
987
|
-
}
|
|
988
|
-
const offset1 = offset;
|
|
989
|
-
const offset2 = offset + Math.abs(wbits) - 1;
|
|
990
|
-
const cond1 = window % 2 !== 0;
|
|
991
|
-
const cond2 = wbits < 0;
|
|
992
|
-
if (wbits === 0) {
|
|
993
|
-
f = f.add(constTimeNegate(cond1, precomputes[offset1]));
|
|
752
|
+
const wo = calcWOpts(W, bits);
|
|
753
|
+
for (let window = 0; window < wo.windows; window++) {
|
|
754
|
+
const { nextN, offset, isZero, isNeg, isNegF, offsetF } = calcOffsets(n, window, wo);
|
|
755
|
+
n = nextN;
|
|
756
|
+
if (isZero) {
|
|
757
|
+
f = f.add(constTimeNegate(isNegF, precomputes[offsetF]));
|
|
994
758
|
} else {
|
|
995
|
-
p = p.add(constTimeNegate(
|
|
759
|
+
p = p.add(constTimeNegate(isNeg, precomputes[offset]));
|
|
996
760
|
}
|
|
997
761
|
}
|
|
998
762
|
return { p, f };
|
|
@@ -1006,26 +770,18 @@ function wNAF(c, bits) {
|
|
|
1006
770
|
* @returns point
|
|
1007
771
|
*/
|
|
1008
772
|
wNAFUnsafe(W, precomputes, n, acc = c.ZERO) {
|
|
1009
|
-
const
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
const shiftBy = BigInt(W);
|
|
1013
|
-
for (let window = 0; window < windows; window++) {
|
|
1014
|
-
const offset = window * windowSize;
|
|
1015
|
-
if (n === _0n3)
|
|
773
|
+
const wo = calcWOpts(W, bits);
|
|
774
|
+
for (let window = 0; window < wo.windows; window++) {
|
|
775
|
+
if (n === _0n2)
|
|
1016
776
|
break;
|
|
1017
|
-
|
|
1018
|
-
n
|
|
1019
|
-
if (
|
|
1020
|
-
wbits -= maxNumber;
|
|
1021
|
-
n += _1n3;
|
|
1022
|
-
}
|
|
1023
|
-
if (wbits === 0)
|
|
777
|
+
const { nextN, offset, isZero, isNeg } = calcOffsets(n, window, wo);
|
|
778
|
+
n = nextN;
|
|
779
|
+
if (isZero) {
|
|
1024
780
|
continue;
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
781
|
+
} else {
|
|
782
|
+
const item = precomputes[offset];
|
|
783
|
+
acc = acc.add(isNeg ? item.negate() : item);
|
|
784
|
+
}
|
|
1029
785
|
}
|
|
1030
786
|
return acc;
|
|
1031
787
|
},
|
|
@@ -1061,20 +817,28 @@ function wNAF(c, bits) {
|
|
|
1061
817
|
function pippenger(c, fieldN, points, scalars) {
|
|
1062
818
|
validateMSMPoints(points, c);
|
|
1063
819
|
validateMSMScalars(scalars, fieldN);
|
|
1064
|
-
|
|
820
|
+
const plength = points.length;
|
|
821
|
+
const slength = scalars.length;
|
|
822
|
+
if (plength !== slength)
|
|
1065
823
|
throw new Error("arrays of points and scalars must have equal length");
|
|
1066
824
|
const zero = c.ZERO;
|
|
1067
|
-
const wbits = bitLen(BigInt(
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
825
|
+
const wbits = bitLen(BigInt(plength));
|
|
826
|
+
let windowSize = 1;
|
|
827
|
+
if (wbits > 12)
|
|
828
|
+
windowSize = wbits - 3;
|
|
829
|
+
else if (wbits > 4)
|
|
830
|
+
windowSize = wbits - 2;
|
|
831
|
+
else if (wbits > 0)
|
|
832
|
+
windowSize = 2;
|
|
833
|
+
const MASK = bitMask(windowSize);
|
|
834
|
+
const buckets = new Array(Number(MASK) + 1).fill(zero);
|
|
1071
835
|
const lastBits = Math.floor((fieldN.BITS - 1) / windowSize) * windowSize;
|
|
1072
836
|
let sum = zero;
|
|
1073
837
|
for (let i = lastBits; i >= 0; i -= windowSize) {
|
|
1074
838
|
buckets.fill(zero);
|
|
1075
|
-
for (let j = 0; j <
|
|
839
|
+
for (let j = 0; j < slength; j++) {
|
|
1076
840
|
const scalar = scalars[j];
|
|
1077
|
-
const wbits2 = Number(scalar >> BigInt(i) &
|
|
841
|
+
const wbits2 = Number(scalar >> BigInt(i) & MASK);
|
|
1078
842
|
buckets[wbits2] = buckets[wbits2].add(points[j]);
|
|
1079
843
|
}
|
|
1080
844
|
let resI = zero;
|
|
@@ -1107,7 +871,7 @@ function validateBasic(curve) {
|
|
|
1107
871
|
});
|
|
1108
872
|
}
|
|
1109
873
|
|
|
1110
|
-
// ../../node_modules/.pnpm/@noble+curves@1.
|
|
874
|
+
// ../../node_modules/.pnpm/@noble+curves@1.9.1/node_modules/@noble/curves/esm/abstract/weierstrass.js
|
|
1111
875
|
function validateSigVerOpts(opts) {
|
|
1112
876
|
if (opts.lowS !== void 0)
|
|
1113
877
|
abool("lowS", opts.lowS);
|
|
@@ -1120,26 +884,25 @@ function validatePointOpts(curve) {
|
|
|
1120
884
|
a: "field",
|
|
1121
885
|
b: "field"
|
|
1122
886
|
}, {
|
|
887
|
+
allowInfinityPoint: "boolean",
|
|
1123
888
|
allowedPrivateKeyLengths: "array",
|
|
1124
|
-
wrapPrivateKey: "boolean",
|
|
1125
|
-
isTorsionFree: "function",
|
|
1126
889
|
clearCofactor: "function",
|
|
1127
|
-
allowInfinityPoint: "boolean",
|
|
1128
890
|
fromBytes: "function",
|
|
1129
|
-
|
|
891
|
+
isTorsionFree: "function",
|
|
892
|
+
toBytes: "function",
|
|
893
|
+
wrapPrivateKey: "boolean"
|
|
1130
894
|
});
|
|
1131
895
|
const { endo, Fp, a } = opts;
|
|
1132
896
|
if (endo) {
|
|
1133
897
|
if (!Fp.eql(a, Fp.ZERO)) {
|
|
1134
|
-
throw new Error("invalid
|
|
898
|
+
throw new Error("invalid endo: CURVE.a must be 0");
|
|
1135
899
|
}
|
|
1136
900
|
if (typeof endo !== "object" || typeof endo.beta !== "bigint" || typeof endo.splitScalar !== "function") {
|
|
1137
|
-
throw new Error(
|
|
901
|
+
throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');
|
|
1138
902
|
}
|
|
1139
903
|
}
|
|
1140
904
|
return Object.freeze({ ...opts });
|
|
1141
905
|
}
|
|
1142
|
-
var { bytesToNumberBE: b2n, hexToBytes: h2b } = utils_exports;
|
|
1143
906
|
var DERErr = class extends Error {
|
|
1144
907
|
constructor(m = "") {
|
|
1145
908
|
super(m);
|
|
@@ -1207,7 +970,7 @@ var DER = {
|
|
|
1207
970
|
_int: {
|
|
1208
971
|
encode(num2) {
|
|
1209
972
|
const { Err: E } = DER;
|
|
1210
|
-
if (num2 <
|
|
973
|
+
if (num2 < _0n3)
|
|
1211
974
|
throw new E("integer: negative integers are not allowed");
|
|
1212
975
|
let hex = numberToHexUnpadded(num2);
|
|
1213
976
|
if (Number.parseInt(hex[0], 16) & 8)
|
|
@@ -1222,13 +985,12 @@ var DER = {
|
|
|
1222
985
|
throw new E("invalid signature integer: negative");
|
|
1223
986
|
if (data[0] === 0 && !(data[1] & 128))
|
|
1224
987
|
throw new E("invalid signature integer: unnecessary leading zero");
|
|
1225
|
-
return
|
|
988
|
+
return bytesToNumberBE(data);
|
|
1226
989
|
}
|
|
1227
990
|
},
|
|
1228
991
|
toSig(hex) {
|
|
1229
992
|
const { Err: E, _int: int, _tlv: tlv } = DER;
|
|
1230
|
-
const data =
|
|
1231
|
-
abytes2(data);
|
|
993
|
+
const data = ensureBytes("signature", hex);
|
|
1232
994
|
const { v: seqBytes, l: seqLeftBytes } = tlv.decode(48, data);
|
|
1233
995
|
if (seqLeftBytes.length)
|
|
1234
996
|
throw new E("invalid signature: left bytes after parsing");
|
|
@@ -1246,9 +1008,12 @@ var DER = {
|
|
|
1246
1008
|
return tlv.encode(48, seq);
|
|
1247
1009
|
}
|
|
1248
1010
|
};
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1011
|
+
function numToSizedHex(num2, size) {
|
|
1012
|
+
return bytesToHex(numberToBytesBE(num2, size));
|
|
1013
|
+
}
|
|
1014
|
+
var _0n3 = BigInt(0);
|
|
1015
|
+
var _1n3 = BigInt(1);
|
|
1016
|
+
var _2n2 = BigInt(2);
|
|
1252
1017
|
var _3n2 = BigInt(3);
|
|
1253
1018
|
var _4n2 = BigInt(4);
|
|
1254
1019
|
function weierstrassPoints(opts) {
|
|
@@ -1271,10 +1036,19 @@ function weierstrassPoints(opts) {
|
|
|
1271
1036
|
const x3 = Fp.mul(x2, x);
|
|
1272
1037
|
return Fp.add(Fp.add(x3, Fp.mul(x, a)), b);
|
|
1273
1038
|
}
|
|
1274
|
-
|
|
1275
|
-
|
|
1039
|
+
function isValidXY(x, y) {
|
|
1040
|
+
const left = Fp.sqr(y);
|
|
1041
|
+
const right = weierstrassEquation(x);
|
|
1042
|
+
return Fp.eql(left, right);
|
|
1043
|
+
}
|
|
1044
|
+
if (!isValidXY(CURVE.Gx, CURVE.Gy))
|
|
1045
|
+
throw new Error("bad curve params: generator point");
|
|
1046
|
+
const _4a3 = Fp.mul(Fp.pow(CURVE.a, _3n2), _4n2);
|
|
1047
|
+
const _27b2 = Fp.mul(Fp.sqr(CURVE.b), BigInt(27));
|
|
1048
|
+
if (Fp.is0(Fp.add(_4a3, _27b2)))
|
|
1049
|
+
throw new Error("bad curve params: a or b");
|
|
1276
1050
|
function isWithinCurveOrder(num2) {
|
|
1277
|
-
return inRange(num2,
|
|
1051
|
+
return inRange(num2, _1n3, CURVE.n);
|
|
1278
1052
|
}
|
|
1279
1053
|
function normPrivateKeyToScalar(key) {
|
|
1280
1054
|
const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n: N } = CURVE;
|
|
@@ -1293,10 +1067,10 @@ function weierstrassPoints(opts) {
|
|
|
1293
1067
|
}
|
|
1294
1068
|
if (wrapPrivateKey)
|
|
1295
1069
|
num2 = mod(num2, N);
|
|
1296
|
-
aInRange("private key", num2,
|
|
1070
|
+
aInRange("private key", num2, _1n3, N);
|
|
1297
1071
|
return num2;
|
|
1298
1072
|
}
|
|
1299
|
-
function
|
|
1073
|
+
function aprjpoint(other) {
|
|
1300
1074
|
if (!(other instanceof Point2))
|
|
1301
1075
|
throw new Error("ProjectivePoint expected");
|
|
1302
1076
|
}
|
|
@@ -1325,9 +1099,7 @@ function weierstrassPoints(opts) {
|
|
|
1325
1099
|
const { x, y } = p.toAffine();
|
|
1326
1100
|
if (!Fp.isValid(x) || !Fp.isValid(y))
|
|
1327
1101
|
throw new Error("bad point: x or y not FE");
|
|
1328
|
-
|
|
1329
|
-
const right = weierstrassEquation(x);
|
|
1330
|
-
if (!Fp.eql(left, right))
|
|
1102
|
+
if (!isValidXY(x, y))
|
|
1331
1103
|
throw new Error("bad point: equation left != right");
|
|
1332
1104
|
if (!p.isTorsionFree())
|
|
1333
1105
|
throw new Error("bad point: not in prime-order subgroup");
|
|
@@ -1335,15 +1107,15 @@ function weierstrassPoints(opts) {
|
|
|
1335
1107
|
});
|
|
1336
1108
|
class Point2 {
|
|
1337
1109
|
constructor(px, py, pz) {
|
|
1338
|
-
this.px = px;
|
|
1339
|
-
this.py = py;
|
|
1340
|
-
this.pz = pz;
|
|
1341
1110
|
if (px == null || !Fp.isValid(px))
|
|
1342
1111
|
throw new Error("x required");
|
|
1343
|
-
if (py == null || !Fp.isValid(py))
|
|
1112
|
+
if (py == null || !Fp.isValid(py) || Fp.is0(py))
|
|
1344
1113
|
throw new Error("y required");
|
|
1345
1114
|
if (pz == null || !Fp.isValid(pz))
|
|
1346
1115
|
throw new Error("z required");
|
|
1116
|
+
this.px = px;
|
|
1117
|
+
this.py = py;
|
|
1118
|
+
this.pz = pz;
|
|
1347
1119
|
Object.freeze(this);
|
|
1348
1120
|
}
|
|
1349
1121
|
// Does not validate if the point is on-curve.
|
|
@@ -1372,7 +1144,7 @@ function weierstrassPoints(opts) {
|
|
|
1372
1144
|
* Optimization: converts a list of projective points to a list of identical points with Z=1.
|
|
1373
1145
|
*/
|
|
1374
1146
|
static normalizeZ(points) {
|
|
1375
|
-
const toInv = Fp
|
|
1147
|
+
const toInv = FpInvertBatch(Fp, points.map((p) => p.pz));
|
|
1376
1148
|
return points.map((p, i) => p.toAffine(toInv[i])).map(Point2.fromAffine);
|
|
1377
1149
|
}
|
|
1378
1150
|
/**
|
|
@@ -1410,7 +1182,7 @@ function weierstrassPoints(opts) {
|
|
|
1410
1182
|
* Compare one point to another.
|
|
1411
1183
|
*/
|
|
1412
1184
|
equals(other) {
|
|
1413
|
-
|
|
1185
|
+
aprjpoint(other);
|
|
1414
1186
|
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
1415
1187
|
const { px: X2, py: Y2, pz: Z2 } = other;
|
|
1416
1188
|
const U1 = Fp.eql(Fp.mul(X1, Z2), Fp.mul(X2, Z1));
|
|
@@ -1470,7 +1242,7 @@ function weierstrassPoints(opts) {
|
|
|
1470
1242
|
// https://eprint.iacr.org/2015/1060, algorithm 1
|
|
1471
1243
|
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
1472
1244
|
add(other) {
|
|
1473
|
-
|
|
1245
|
+
aprjpoint(other);
|
|
1474
1246
|
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
1475
1247
|
const { px: X2, py: Y2, pz: Z2 } = other;
|
|
1476
1248
|
let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO;
|
|
@@ -1533,33 +1305,33 @@ function weierstrassPoints(opts) {
|
|
|
1533
1305
|
* an exposed private key e.g. sig verification, which works over *public* keys.
|
|
1534
1306
|
*/
|
|
1535
1307
|
multiplyUnsafe(sc) {
|
|
1536
|
-
const { endo, n: N } = CURVE;
|
|
1537
|
-
aInRange("scalar", sc,
|
|
1308
|
+
const { endo: endo2, n: N } = CURVE;
|
|
1309
|
+
aInRange("scalar", sc, _0n3, N);
|
|
1538
1310
|
const I = Point2.ZERO;
|
|
1539
|
-
if (sc ===
|
|
1311
|
+
if (sc === _0n3)
|
|
1540
1312
|
return I;
|
|
1541
|
-
if (this.is0() || sc ===
|
|
1313
|
+
if (this.is0() || sc === _1n3)
|
|
1542
1314
|
return this;
|
|
1543
|
-
if (!
|
|
1315
|
+
if (!endo2 || wnaf.hasPrecomputes(this))
|
|
1544
1316
|
return wnaf.wNAFCachedUnsafe(this, sc, Point2.normalizeZ);
|
|
1545
|
-
let { k1neg, k1, k2neg, k2 } =
|
|
1317
|
+
let { k1neg, k1, k2neg, k2 } = endo2.splitScalar(sc);
|
|
1546
1318
|
let k1p = I;
|
|
1547
1319
|
let k2p = I;
|
|
1548
1320
|
let d = this;
|
|
1549
|
-
while (k1 >
|
|
1550
|
-
if (k1 &
|
|
1321
|
+
while (k1 > _0n3 || k2 > _0n3) {
|
|
1322
|
+
if (k1 & _1n3)
|
|
1551
1323
|
k1p = k1p.add(d);
|
|
1552
|
-
if (k2 &
|
|
1324
|
+
if (k2 & _1n3)
|
|
1553
1325
|
k2p = k2p.add(d);
|
|
1554
1326
|
d = d.double();
|
|
1555
|
-
k1 >>=
|
|
1556
|
-
k2 >>=
|
|
1327
|
+
k1 >>= _1n3;
|
|
1328
|
+
k2 >>= _1n3;
|
|
1557
1329
|
}
|
|
1558
1330
|
if (k1neg)
|
|
1559
1331
|
k1p = k1p.negate();
|
|
1560
1332
|
if (k2neg)
|
|
1561
1333
|
k2p = k2p.negate();
|
|
1562
|
-
k2p = new Point2(Fp.mul(k2p.px,
|
|
1334
|
+
k2p = new Point2(Fp.mul(k2p.px, endo2.beta), k2p.py, k2p.pz);
|
|
1563
1335
|
return k1p.add(k2p);
|
|
1564
1336
|
}
|
|
1565
1337
|
/**
|
|
@@ -1572,16 +1344,16 @@ function weierstrassPoints(opts) {
|
|
|
1572
1344
|
* @returns New point
|
|
1573
1345
|
*/
|
|
1574
1346
|
multiply(scalar) {
|
|
1575
|
-
const { endo, n: N } = CURVE;
|
|
1576
|
-
aInRange("scalar", scalar,
|
|
1347
|
+
const { endo: endo2, n: N } = CURVE;
|
|
1348
|
+
aInRange("scalar", scalar, _1n3, N);
|
|
1577
1349
|
let point, fake;
|
|
1578
|
-
if (
|
|
1579
|
-
const { k1neg, k1, k2neg, k2 } =
|
|
1350
|
+
if (endo2) {
|
|
1351
|
+
const { k1neg, k1, k2neg, k2 } = endo2.splitScalar(scalar);
|
|
1580
1352
|
let { p: k1p, f: f1p } = this.wNAF(k1);
|
|
1581
1353
|
let { p: k2p, f: f2p } = this.wNAF(k2);
|
|
1582
1354
|
k1p = wnaf.constTimeNegate(k1neg, k1p);
|
|
1583
1355
|
k2p = wnaf.constTimeNegate(k2neg, k2p);
|
|
1584
|
-
k2p = new Point2(Fp.mul(k2p.px,
|
|
1356
|
+
k2p = new Point2(Fp.mul(k2p.px, endo2.beta), k2p.py, k2p.pz);
|
|
1585
1357
|
point = k1p.add(k2p);
|
|
1586
1358
|
fake = f1p.add(f2p);
|
|
1587
1359
|
} else {
|
|
@@ -1599,7 +1371,7 @@ function weierstrassPoints(opts) {
|
|
|
1599
1371
|
*/
|
|
1600
1372
|
multiplyAndAddUnsafe(Q, a, b) {
|
|
1601
1373
|
const G = Point2.BASE;
|
|
1602
|
-
const mul = (P, a2) => a2 ===
|
|
1374
|
+
const mul = (P, a2) => a2 === _0n3 || a2 === _1n3 || !P.equals(G) ? P.multiplyUnsafe(a2) : P.multiply(a2);
|
|
1603
1375
|
const sum = mul(this, a).add(mul(Q, b));
|
|
1604
1376
|
return sum.is0() ? void 0 : sum;
|
|
1605
1377
|
}
|
|
@@ -1611,7 +1383,7 @@ function weierstrassPoints(opts) {
|
|
|
1611
1383
|
}
|
|
1612
1384
|
isTorsionFree() {
|
|
1613
1385
|
const { h: cofactor, isTorsionFree } = CURVE;
|
|
1614
|
-
if (cofactor ===
|
|
1386
|
+
if (cofactor === _1n3)
|
|
1615
1387
|
return true;
|
|
1616
1388
|
if (isTorsionFree)
|
|
1617
1389
|
return isTorsionFree(Point2, this);
|
|
@@ -1619,7 +1391,7 @@ function weierstrassPoints(opts) {
|
|
|
1619
1391
|
}
|
|
1620
1392
|
clearCofactor() {
|
|
1621
1393
|
const { h: cofactor, clearCofactor } = CURVE;
|
|
1622
|
-
if (cofactor ===
|
|
1394
|
+
if (cofactor === _1n3)
|
|
1623
1395
|
return this;
|
|
1624
1396
|
if (clearCofactor)
|
|
1625
1397
|
return clearCofactor(Point2, this);
|
|
@@ -1637,8 +1409,8 @@ function weierstrassPoints(opts) {
|
|
|
1637
1409
|
}
|
|
1638
1410
|
Point2.BASE = new Point2(CURVE.Gx, CURVE.Gy, Fp.ONE);
|
|
1639
1411
|
Point2.ZERO = new Point2(Fp.ZERO, Fp.ONE, Fp.ZERO);
|
|
1640
|
-
const
|
|
1641
|
-
const wnaf = wNAF(Point2,
|
|
1412
|
+
const { endo, nBitLength } = CURVE;
|
|
1413
|
+
const wnaf = wNAF(Point2, endo ? Math.ceil(nBitLength / 2) : nBitLength);
|
|
1642
1414
|
return {
|
|
1643
1415
|
CURVE,
|
|
1644
1416
|
ProjectivePoint: Point2,
|
|
@@ -1662,7 +1434,7 @@ function validateOpts(curve) {
|
|
|
1662
1434
|
}
|
|
1663
1435
|
function weierstrass(curveDef) {
|
|
1664
1436
|
const CURVE = validateOpts(curveDef);
|
|
1665
|
-
const { Fp, n: CURVE_ORDER } = CURVE;
|
|
1437
|
+
const { Fp, n: CURVE_ORDER, nByteLength, nBitLength } = CURVE;
|
|
1666
1438
|
const compressedLen = Fp.BYTES + 1;
|
|
1667
1439
|
const uncompressedLen = 2 * Fp.BYTES + 1;
|
|
1668
1440
|
function modN2(a) {
|
|
@@ -1690,7 +1462,7 @@ function weierstrass(curveDef) {
|
|
|
1690
1462
|
const tail = bytes.subarray(1);
|
|
1691
1463
|
if (len === compressedLen && (head === 2 || head === 3)) {
|
|
1692
1464
|
const x = bytesToNumberBE(tail);
|
|
1693
|
-
if (!inRange(x,
|
|
1465
|
+
if (!inRange(x, _1n3, Fp.ORDER))
|
|
1694
1466
|
throw new Error("Point is not on curve");
|
|
1695
1467
|
const y2 = weierstrassEquation(x);
|
|
1696
1468
|
let y;
|
|
@@ -1700,7 +1472,7 @@ function weierstrass(curveDef) {
|
|
|
1700
1472
|
const suffix = sqrtError instanceof Error ? ": " + sqrtError.message : "";
|
|
1701
1473
|
throw new Error("Point is not on curve" + suffix);
|
|
1702
1474
|
}
|
|
1703
|
-
const isYOdd = (y &
|
|
1475
|
+
const isYOdd = (y & _1n3) === _1n3;
|
|
1704
1476
|
const isHeadOdd = (head & 1) === 1;
|
|
1705
1477
|
if (isHeadOdd !== isYOdd)
|
|
1706
1478
|
y = Fp.neg(y);
|
|
@@ -1716,9 +1488,8 @@ function weierstrass(curveDef) {
|
|
|
1716
1488
|
}
|
|
1717
1489
|
}
|
|
1718
1490
|
});
|
|
1719
|
-
const numToNByteStr = (num2) => bytesToHex(numberToBytesBE(num2, CURVE.nByteLength));
|
|
1720
1491
|
function isBiggerThanHalfOrder(number) {
|
|
1721
|
-
const HALF = CURVE_ORDER >>
|
|
1492
|
+
const HALF = CURVE_ORDER >> _1n3;
|
|
1722
1493
|
return number > HALF;
|
|
1723
1494
|
}
|
|
1724
1495
|
function normalizeS(s) {
|
|
@@ -1727,14 +1498,17 @@ function weierstrass(curveDef) {
|
|
|
1727
1498
|
const slcNum = (b, from, to) => bytesToNumberBE(b.slice(from, to));
|
|
1728
1499
|
class Signature {
|
|
1729
1500
|
constructor(r, s, recovery) {
|
|
1501
|
+
aInRange("r", r, _1n3, CURVE_ORDER);
|
|
1502
|
+
aInRange("s", s, _1n3, CURVE_ORDER);
|
|
1730
1503
|
this.r = r;
|
|
1731
1504
|
this.s = s;
|
|
1732
|
-
|
|
1733
|
-
|
|
1505
|
+
if (recovery != null)
|
|
1506
|
+
this.recovery = recovery;
|
|
1507
|
+
Object.freeze(this);
|
|
1734
1508
|
}
|
|
1735
1509
|
// pair (bytes of r, bytes of s)
|
|
1736
1510
|
static fromCompact(hex) {
|
|
1737
|
-
const l =
|
|
1511
|
+
const l = nByteLength;
|
|
1738
1512
|
hex = ensureBytes("compactSignature", hex, l * 2);
|
|
1739
1513
|
return new Signature(slcNum(hex, 0, l), slcNum(hex, l, 2 * l));
|
|
1740
1514
|
}
|
|
@@ -1744,9 +1518,11 @@ function weierstrass(curveDef) {
|
|
|
1744
1518
|
const { r, s } = DER.toSig(ensureBytes("DER", hex));
|
|
1745
1519
|
return new Signature(r, s);
|
|
1746
1520
|
}
|
|
1521
|
+
/**
|
|
1522
|
+
* @todo remove
|
|
1523
|
+
* @deprecated
|
|
1524
|
+
*/
|
|
1747
1525
|
assertValidity() {
|
|
1748
|
-
aInRange("r", this.r, _1n4, CURVE_ORDER);
|
|
1749
|
-
aInRange("s", this.s, _1n4, CURVE_ORDER);
|
|
1750
1526
|
}
|
|
1751
1527
|
addRecoveryBit(recovery) {
|
|
1752
1528
|
return new Signature(this.r, this.s, recovery);
|
|
@@ -1760,7 +1536,7 @@ function weierstrass(curveDef) {
|
|
|
1760
1536
|
if (radj >= Fp.ORDER)
|
|
1761
1537
|
throw new Error("recovery id 2 or 3 invalid");
|
|
1762
1538
|
const prefix = (rec & 1) === 0 ? "02" : "03";
|
|
1763
|
-
const R = Point2.fromHex(prefix +
|
|
1539
|
+
const R = Point2.fromHex(prefix + numToSizedHex(radj, Fp.BYTES));
|
|
1764
1540
|
const ir = invN(radj);
|
|
1765
1541
|
const u1 = modN2(-h * ir);
|
|
1766
1542
|
const u2 = modN2(s * ir);
|
|
@@ -1782,14 +1558,15 @@ function weierstrass(curveDef) {
|
|
|
1782
1558
|
return hexToBytes(this.toDERHex());
|
|
1783
1559
|
}
|
|
1784
1560
|
toDERHex() {
|
|
1785
|
-
return DER.hexFromSig(
|
|
1561
|
+
return DER.hexFromSig(this);
|
|
1786
1562
|
}
|
|
1787
1563
|
// padded bytes of r, then padded bytes of s
|
|
1788
1564
|
toCompactRawBytes() {
|
|
1789
1565
|
return hexToBytes(this.toCompactHex());
|
|
1790
1566
|
}
|
|
1791
1567
|
toCompactHex() {
|
|
1792
|
-
|
|
1568
|
+
const l = nByteLength;
|
|
1569
|
+
return numToSizedHex(this.r, l) + numToSizedHex(this.s, l);
|
|
1793
1570
|
}
|
|
1794
1571
|
}
|
|
1795
1572
|
const utils = {
|
|
@@ -1828,21 +1605,25 @@ function weierstrass(curveDef) {
|
|
|
1828
1605
|
return Point2.fromPrivateKey(privateKey).toRawBytes(isCompressed);
|
|
1829
1606
|
}
|
|
1830
1607
|
function isProbPub(item) {
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
const len = (arr || str) && item.length;
|
|
1834
|
-
if (arr)
|
|
1835
|
-
return len === compressedLen || len === uncompressedLen;
|
|
1836
|
-
if (str)
|
|
1837
|
-
return len === 2 * compressedLen || len === 2 * uncompressedLen;
|
|
1608
|
+
if (typeof item === "bigint")
|
|
1609
|
+
return false;
|
|
1838
1610
|
if (item instanceof Point2)
|
|
1839
1611
|
return true;
|
|
1840
|
-
|
|
1612
|
+
const arr = ensureBytes("key", item);
|
|
1613
|
+
const len = arr.length;
|
|
1614
|
+
const fpl = Fp.BYTES;
|
|
1615
|
+
const compLen = fpl + 1;
|
|
1616
|
+
const uncompLen = 2 * fpl + 1;
|
|
1617
|
+
if (CURVE.allowedPrivateKeyLengths || nByteLength === compLen) {
|
|
1618
|
+
return void 0;
|
|
1619
|
+
} else {
|
|
1620
|
+
return len === compLen || len === uncompLen;
|
|
1621
|
+
}
|
|
1841
1622
|
}
|
|
1842
1623
|
function getSharedSecret(privateA, publicB, isCompressed = true) {
|
|
1843
|
-
if (isProbPub(privateA))
|
|
1624
|
+
if (isProbPub(privateA) === true)
|
|
1844
1625
|
throw new Error("first arg must be private key");
|
|
1845
|
-
if (
|
|
1626
|
+
if (isProbPub(publicB) === false)
|
|
1846
1627
|
throw new Error("second arg must be public key");
|
|
1847
1628
|
const b = Point2.fromHex(publicB);
|
|
1848
1629
|
return b.multiply(normPrivateKeyToScalar(privateA)).toRawBytes(isCompressed);
|
|
@@ -1851,16 +1632,16 @@ function weierstrass(curveDef) {
|
|
|
1851
1632
|
if (bytes.length > 8192)
|
|
1852
1633
|
throw new Error("input is too large");
|
|
1853
1634
|
const num2 = bytesToNumberBE(bytes);
|
|
1854
|
-
const delta = bytes.length * 8 -
|
|
1635
|
+
const delta = bytes.length * 8 - nBitLength;
|
|
1855
1636
|
return delta > 0 ? num2 >> BigInt(delta) : num2;
|
|
1856
1637
|
};
|
|
1857
1638
|
const bits2int_modN = CURVE.bits2int_modN || function(bytes) {
|
|
1858
1639
|
return modN2(bits2int(bytes));
|
|
1859
1640
|
};
|
|
1860
|
-
const ORDER_MASK = bitMask(
|
|
1641
|
+
const ORDER_MASK = bitMask(nBitLength);
|
|
1861
1642
|
function int2octets(num2) {
|
|
1862
|
-
aInRange("num < 2^" +
|
|
1863
|
-
return numberToBytesBE(num2,
|
|
1643
|
+
aInRange("num < 2^" + nBitLength, num2, _0n3, ORDER_MASK);
|
|
1644
|
+
return numberToBytesBE(num2, nByteLength);
|
|
1864
1645
|
}
|
|
1865
1646
|
function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
|
|
1866
1647
|
if (["recovered", "canonical"].some((k) => k in opts))
|
|
@@ -1889,12 +1670,12 @@ function weierstrass(curveDef) {
|
|
|
1889
1670
|
const ik = invN(k);
|
|
1890
1671
|
const q = Point2.BASE.multiply(k).toAffine();
|
|
1891
1672
|
const r = modN2(q.x);
|
|
1892
|
-
if (r ===
|
|
1673
|
+
if (r === _0n3)
|
|
1893
1674
|
return;
|
|
1894
1675
|
const s = modN2(ik * modN2(m + r * d));
|
|
1895
|
-
if (s ===
|
|
1676
|
+
if (s === _0n3)
|
|
1896
1677
|
return;
|
|
1897
|
-
let recovery = (q.x === r ? 0 : 2) | Number(q.y &
|
|
1678
|
+
let recovery = (q.x === r ? 0 : 2) | Number(q.y & _1n3);
|
|
1898
1679
|
let normS = s;
|
|
1899
1680
|
if (lowS && isBiggerThanHalfOrder(s)) {
|
|
1900
1681
|
normS = normalizeS(s);
|
|
@@ -1977,18 +1758,18 @@ function weierstrass(curveDef) {
|
|
|
1977
1758
|
}
|
|
1978
1759
|
function SWUFpSqrtRatio(Fp, Z) {
|
|
1979
1760
|
const q = Fp.ORDER;
|
|
1980
|
-
let l =
|
|
1981
|
-
for (let o = q -
|
|
1982
|
-
l +=
|
|
1761
|
+
let l = _0n3;
|
|
1762
|
+
for (let o = q - _1n3; o % _2n2 === _0n3; o /= _2n2)
|
|
1763
|
+
l += _1n3;
|
|
1983
1764
|
const c1 = l;
|
|
1984
|
-
const _2n_pow_c1_1 =
|
|
1985
|
-
const _2n_pow_c1 = _2n_pow_c1_1 *
|
|
1986
|
-
const c2 = (q -
|
|
1987
|
-
const c3 = (c2 -
|
|
1988
|
-
const c4 = _2n_pow_c1 -
|
|
1765
|
+
const _2n_pow_c1_1 = _2n2 << c1 - _1n3 - _1n3;
|
|
1766
|
+
const _2n_pow_c1 = _2n_pow_c1_1 * _2n2;
|
|
1767
|
+
const c2 = (q - _1n3) / _2n_pow_c1;
|
|
1768
|
+
const c3 = (c2 - _1n3) / _2n2;
|
|
1769
|
+
const c4 = _2n_pow_c1 - _1n3;
|
|
1989
1770
|
const c5 = _2n_pow_c1_1;
|
|
1990
1771
|
const c6 = Fp.pow(Z, c2);
|
|
1991
|
-
const c7 = Fp.pow(Z, (c2 +
|
|
1772
|
+
const c7 = Fp.pow(Z, (c2 + _1n3) / _2n2);
|
|
1992
1773
|
let sqrtRatio = (u, v) => {
|
|
1993
1774
|
let tv1 = c6;
|
|
1994
1775
|
let tv2 = Fp.pow(v, c4);
|
|
@@ -2006,9 +1787,9 @@ function SWUFpSqrtRatio(Fp, Z) {
|
|
|
2006
1787
|
tv5 = Fp.mul(tv4, tv1);
|
|
2007
1788
|
tv3 = Fp.cmov(tv2, tv3, isQR);
|
|
2008
1789
|
tv4 = Fp.cmov(tv5, tv4, isQR);
|
|
2009
|
-
for (let i = c1; i >
|
|
2010
|
-
let tv52 = i -
|
|
2011
|
-
tv52 =
|
|
1790
|
+
for (let i = c1; i > _1n3; i--) {
|
|
1791
|
+
let tv52 = i - _2n2;
|
|
1792
|
+
tv52 = _2n2 << tv52 - _1n3;
|
|
2012
1793
|
let tvv5 = Fp.pow(tv4, tv52);
|
|
2013
1794
|
const e1 = Fp.eql(tvv5, Fp.ONE);
|
|
2014
1795
|
tv2 = Fp.mul(tv3, tv1);
|
|
@@ -2070,12 +1851,13 @@ function mapToCurveSimpleSWU(Fp, opts) {
|
|
|
2070
1851
|
y = Fp.cmov(y, value, isValid);
|
|
2071
1852
|
const e1 = Fp.isOdd(u) === Fp.isOdd(y);
|
|
2072
1853
|
y = Fp.cmov(Fp.neg(y), y, e1);
|
|
2073
|
-
|
|
1854
|
+
const tv4_inv = FpInvertBatch(Fp, [tv4], true)[0];
|
|
1855
|
+
x = Fp.mul(x, tv4_inv);
|
|
2074
1856
|
return { x, y };
|
|
2075
1857
|
};
|
|
2076
1858
|
}
|
|
2077
1859
|
|
|
2078
|
-
// ../../node_modules/.pnpm/@noble+curves@1.
|
|
1860
|
+
// ../../node_modules/.pnpm/@noble+curves@1.9.1/node_modules/@noble/curves/esm/_shortw_utils.js
|
|
2079
1861
|
function getHash(hash) {
|
|
2080
1862
|
return {
|
|
2081
1863
|
hash,
|
|
@@ -2088,7 +1870,7 @@ function createCurve(curveDef, defHash) {
|
|
|
2088
1870
|
return { ...create(defHash), create };
|
|
2089
1871
|
}
|
|
2090
1872
|
|
|
2091
|
-
// ../../node_modules/.pnpm/@noble+curves@1.
|
|
1873
|
+
// ../../node_modules/.pnpm/@noble+curves@1.9.1/node_modules/@noble/curves/esm/abstract/hash-to-curve.js
|
|
2092
1874
|
var os2ip = bytesToNumberBE;
|
|
2093
1875
|
function i2osp(value, length) {
|
|
2094
1876
|
anum(value);
|
|
@@ -2186,56 +1968,63 @@ function hash_to_field(msg, count, options) {
|
|
|
2186
1968
|
return u;
|
|
2187
1969
|
}
|
|
2188
1970
|
function isogenyMap(field, map) {
|
|
2189
|
-
const
|
|
1971
|
+
const coeff = map.map((i) => Array.from(i).reverse());
|
|
2190
1972
|
return (x, y) => {
|
|
2191
|
-
const [
|
|
2192
|
-
|
|
2193
|
-
|
|
1973
|
+
const [xn, xd, yn, yd] = coeff.map((val) => val.reduce((acc, i) => field.add(field.mul(acc, x), i)));
|
|
1974
|
+
const [xd_inv, yd_inv] = FpInvertBatch(field, [xd, yd], true);
|
|
1975
|
+
x = field.mul(xn, xd_inv);
|
|
1976
|
+
y = field.mul(y, field.mul(yn, yd_inv));
|
|
2194
1977
|
return { x, y };
|
|
2195
1978
|
};
|
|
2196
1979
|
}
|
|
2197
|
-
function
|
|
1980
|
+
function createHasher2(Point2, mapToCurve, defaults) {
|
|
2198
1981
|
if (typeof mapToCurve !== "function")
|
|
2199
1982
|
throw new Error("mapToCurve() must be defined");
|
|
1983
|
+
function map(num2) {
|
|
1984
|
+
return Point2.fromAffine(mapToCurve(num2));
|
|
1985
|
+
}
|
|
1986
|
+
function clear(initial) {
|
|
1987
|
+
const P = initial.clearCofactor();
|
|
1988
|
+
if (P.equals(Point2.ZERO))
|
|
1989
|
+
return Point2.ZERO;
|
|
1990
|
+
P.assertValidity();
|
|
1991
|
+
return P;
|
|
1992
|
+
}
|
|
2200
1993
|
return {
|
|
1994
|
+
defaults,
|
|
2201
1995
|
// Encodes byte string to elliptic curve.
|
|
2202
1996
|
// hash_to_curve from https://www.rfc-editor.org/rfc/rfc9380#section-3
|
|
2203
1997
|
hashToCurve(msg, options) {
|
|
2204
|
-
const u = hash_to_field(msg, 2, { ...
|
|
2205
|
-
const u0 =
|
|
2206
|
-
const u1 =
|
|
2207
|
-
|
|
2208
|
-
P.assertValidity();
|
|
2209
|
-
return P;
|
|
1998
|
+
const u = hash_to_field(msg, 2, { ...defaults, DST: defaults.DST, ...options });
|
|
1999
|
+
const u0 = map(u[0]);
|
|
2000
|
+
const u1 = map(u[1]);
|
|
2001
|
+
return clear(u0.add(u1));
|
|
2210
2002
|
},
|
|
2211
2003
|
// Encodes byte string to elliptic curve.
|
|
2212
2004
|
// encode_to_curve from https://www.rfc-editor.org/rfc/rfc9380#section-3
|
|
2213
2005
|
encodeToCurve(msg, options) {
|
|
2214
|
-
const u = hash_to_field(msg, 1, { ...
|
|
2215
|
-
|
|
2216
|
-
P.assertValidity();
|
|
2217
|
-
return P;
|
|
2006
|
+
const u = hash_to_field(msg, 1, { ...defaults, DST: defaults.encodeDST, ...options });
|
|
2007
|
+
return clear(map(u[0]));
|
|
2218
2008
|
},
|
|
2219
2009
|
// Same as encodeToCurve, but without hash
|
|
2220
2010
|
mapToCurve(scalars) {
|
|
2221
2011
|
if (!Array.isArray(scalars))
|
|
2222
|
-
throw new Error("
|
|
2012
|
+
throw new Error("expected array of bigints");
|
|
2223
2013
|
for (const i of scalars)
|
|
2224
2014
|
if (typeof i !== "bigint")
|
|
2225
|
-
throw new Error("
|
|
2226
|
-
|
|
2227
|
-
P.assertValidity();
|
|
2228
|
-
return P;
|
|
2015
|
+
throw new Error("expected array of bigints");
|
|
2016
|
+
return clear(map(scalars));
|
|
2229
2017
|
}
|
|
2230
2018
|
};
|
|
2231
2019
|
}
|
|
2232
2020
|
|
|
2233
|
-
// ../../node_modules/.pnpm/@noble+curves@1.
|
|
2021
|
+
// ../../node_modules/.pnpm/@noble+curves@1.9.1/node_modules/@noble/curves/esm/secp256k1.js
|
|
2234
2022
|
var secp256k1P = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f");
|
|
2235
2023
|
var secp256k1N = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
|
|
2236
|
-
var
|
|
2237
|
-
var
|
|
2238
|
-
var
|
|
2024
|
+
var _0n4 = BigInt(0);
|
|
2025
|
+
var _1n4 = BigInt(1);
|
|
2026
|
+
var _2n3 = BigInt(2);
|
|
2027
|
+
var divNearest = (a, b) => (a + b / _2n3) / b;
|
|
2239
2028
|
function sqrtMod(y) {
|
|
2240
2029
|
const P = secp256k1P;
|
|
2241
2030
|
const _3n3 = BigInt(3), _6n = BigInt(6), _11n = BigInt(11), _22n = BigInt(22);
|
|
@@ -2244,7 +2033,7 @@ function sqrtMod(y) {
|
|
|
2244
2033
|
const b3 = b2 * b2 * y % P;
|
|
2245
2034
|
const b6 = pow2(b3, _3n3, P) * b3 % P;
|
|
2246
2035
|
const b9 = pow2(b6, _3n3, P) * b3 % P;
|
|
2247
|
-
const b11 = pow2(b9,
|
|
2036
|
+
const b11 = pow2(b9, _2n3, P) * b2 % P;
|
|
2248
2037
|
const b22 = pow2(b11, _11n, P) * b11 % P;
|
|
2249
2038
|
const b44 = pow2(b22, _22n, P) * b22 % P;
|
|
2250
2039
|
const b88 = pow2(b44, _44n, P) * b44 % P;
|
|
@@ -2253,25 +2042,20 @@ function sqrtMod(y) {
|
|
|
2253
2042
|
const b223 = pow2(b220, _3n3, P) * b3 % P;
|
|
2254
2043
|
const t1 = pow2(b223, _23n, P) * b22 % P;
|
|
2255
2044
|
const t2 = pow2(t1, _6n, P) * b2 % P;
|
|
2256
|
-
const root = pow2(t2,
|
|
2045
|
+
const root = pow2(t2, _2n3, P);
|
|
2257
2046
|
if (!Fpk1.eql(Fpk1.sqr(root), y))
|
|
2258
2047
|
throw new Error("Cannot find square root");
|
|
2259
2048
|
return root;
|
|
2260
2049
|
}
|
|
2261
2050
|
var Fpk1 = Field(secp256k1P, void 0, void 0, { sqrt: sqrtMod });
|
|
2262
2051
|
var secp256k1 = createCurve({
|
|
2263
|
-
a:
|
|
2264
|
-
// equation params: a, b
|
|
2052
|
+
a: _0n4,
|
|
2265
2053
|
b: BigInt(7),
|
|
2266
2054
|
Fp: Fpk1,
|
|
2267
|
-
// Field's prime: 2n**256n - 2n**32n - 2n**9n - 2n**8n - 2n**7n - 2n**6n - 2n**4n - 1n
|
|
2268
2055
|
n: secp256k1N,
|
|
2269
|
-
// Curve order, total count of valid points in the field
|
|
2270
|
-
// Base point (x, y) aka generator point
|
|
2271
2056
|
Gx: BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
|
|
2272
2057
|
Gy: BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),
|
|
2273
2058
|
h: BigInt(1),
|
|
2274
|
-
// Cofactor
|
|
2275
2059
|
lowS: true,
|
|
2276
2060
|
// Allow only low-S signatures by default in sign() and verify()
|
|
2277
2061
|
endo: {
|
|
@@ -2280,7 +2064,7 @@ var secp256k1 = createCurve({
|
|
|
2280
2064
|
splitScalar: (k) => {
|
|
2281
2065
|
const n = secp256k1N;
|
|
2282
2066
|
const a1 = BigInt("0x3086d221a7d46bcde86c90e49284eb15");
|
|
2283
|
-
const b1 = -
|
|
2067
|
+
const b1 = -_1n4 * BigInt("0xe4437ed6010e88286f547fa90abfe4c3");
|
|
2284
2068
|
const a2 = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8");
|
|
2285
2069
|
const b2 = a1;
|
|
2286
2070
|
const POW_2_128 = BigInt("0x100000000000000000000000000000000");
|
|
@@ -2301,7 +2085,6 @@ var secp256k1 = createCurve({
|
|
|
2301
2085
|
}
|
|
2302
2086
|
}
|
|
2303
2087
|
}, sha256);
|
|
2304
|
-
var _0n5 = BigInt(0);
|
|
2305
2088
|
var TAGGED_HASH_PREFIXES = {};
|
|
2306
2089
|
function taggedHash(tag, ...messages) {
|
|
2307
2090
|
let tagP = TAGGED_HASH_PREFIXES[tag];
|
|
@@ -2316,7 +2099,7 @@ var pointToBytes = (point) => point.toRawBytes(true).slice(1);
|
|
|
2316
2099
|
var numTo32b = (n) => numberToBytesBE(n, 32);
|
|
2317
2100
|
var modP = (x) => mod(x, secp256k1P);
|
|
2318
2101
|
var modN = (x) => mod(x, secp256k1N);
|
|
2319
|
-
var Point = secp256k1.ProjectivePoint;
|
|
2102
|
+
var Point = /* @__PURE__ */ (() => secp256k1.ProjectivePoint)();
|
|
2320
2103
|
var GmulAdd = (Q, a, b) => Point.BASE.multiplyAndAddUnsafe(Q, a, b);
|
|
2321
2104
|
function schnorrGetExtPubKey(priv) {
|
|
2322
2105
|
let d_ = secp256k1.utils.normPrivateKeyToScalar(priv);
|
|
@@ -2325,13 +2108,13 @@ function schnorrGetExtPubKey(priv) {
|
|
|
2325
2108
|
return { scalar, bytes: pointToBytes(p) };
|
|
2326
2109
|
}
|
|
2327
2110
|
function lift_x(x) {
|
|
2328
|
-
aInRange("x", x,
|
|
2111
|
+
aInRange("x", x, _1n4, secp256k1P);
|
|
2329
2112
|
const xx = modP(x * x);
|
|
2330
2113
|
const c = modP(xx * x + BigInt(7));
|
|
2331
2114
|
let y = sqrtMod(c);
|
|
2332
|
-
if (y %
|
|
2115
|
+
if (y % _2n3 !== _0n4)
|
|
2333
2116
|
y = modP(-y);
|
|
2334
|
-
const p = new Point(x, y,
|
|
2117
|
+
const p = new Point(x, y, _1n4);
|
|
2335
2118
|
p.assertValidity();
|
|
2336
2119
|
return p;
|
|
2337
2120
|
}
|
|
@@ -2349,7 +2132,7 @@ function schnorrSign(message, privateKey, auxRand = randomBytes(32)) {
|
|
|
2349
2132
|
const t = numTo32b(d ^ num(taggedHash("BIP0340/aux", a)));
|
|
2350
2133
|
const rand = taggedHash("BIP0340/nonce", t, px, m);
|
|
2351
2134
|
const k_ = modN(num(rand));
|
|
2352
|
-
if (k_ ===
|
|
2135
|
+
if (k_ === _0n4)
|
|
2353
2136
|
throw new Error("sign failed: k is zero");
|
|
2354
2137
|
const { bytes: rx, scalar: k } = schnorrGetExtPubKey(k_);
|
|
2355
2138
|
const e = challenge(rx, px, m);
|
|
@@ -2367,10 +2150,10 @@ function schnorrVerify(signature, message, publicKey) {
|
|
|
2367
2150
|
try {
|
|
2368
2151
|
const P = lift_x(num(pub));
|
|
2369
2152
|
const r = num(sig.subarray(0, 32));
|
|
2370
|
-
if (!inRange(r,
|
|
2153
|
+
if (!inRange(r, _1n4, secp256k1P))
|
|
2371
2154
|
return false;
|
|
2372
2155
|
const s = num(sig.subarray(32, 64));
|
|
2373
|
-
if (!inRange(s,
|
|
2156
|
+
if (!inRange(s, _1n4, secp256k1N))
|
|
2374
2157
|
return false;
|
|
2375
2158
|
const e = challenge(numTo32b(r), pointToBytes(P), m);
|
|
2376
2159
|
const R = GmulAdd(P, s, modN(-e));
|
|
@@ -2431,7 +2214,7 @@ var mapSWU = /* @__PURE__ */ (() => mapToCurveSimpleSWU(Fpk1, {
|
|
|
2431
2214
|
B: BigInt("1771"),
|
|
2432
2215
|
Z: Fpk1.create(BigInt("-11"))
|
|
2433
2216
|
}))();
|
|
2434
|
-
var
|
|
2217
|
+
var secp256k1_hasher = /* @__PURE__ */ (() => createHasher2(secp256k1.ProjectivePoint, (scalars) => {
|
|
2435
2218
|
const { x, y } = mapSWU(Fpk1.create(scalars[0]));
|
|
2436
2219
|
return isoMap(x, y);
|
|
2437
2220
|
}, {
|
|
@@ -2443,19 +2226,17 @@ var htf = /* @__PURE__ */ (() => createHasher(secp256k1.ProjectivePoint, (scalar
|
|
|
2443
2226
|
expand: "xmd",
|
|
2444
2227
|
hash: sha256
|
|
2445
2228
|
}))();
|
|
2446
|
-
var hashToCurve = /* @__PURE__ */ (() =>
|
|
2447
|
-
var encodeToCurve = /* @__PURE__ */ (() =>
|
|
2229
|
+
var hashToCurve = /* @__PURE__ */ (() => secp256k1_hasher.hashToCurve)();
|
|
2230
|
+
var encodeToCurve = /* @__PURE__ */ (() => secp256k1_hasher.encodeToCurve)();
|
|
2448
2231
|
export {
|
|
2449
2232
|
encodeToCurve,
|
|
2450
2233
|
hashToCurve,
|
|
2451
2234
|
schnorr,
|
|
2452
|
-
secp256k1
|
|
2235
|
+
secp256k1,
|
|
2236
|
+
secp256k1_hasher
|
|
2453
2237
|
};
|
|
2454
2238
|
/*! Bundled license information:
|
|
2455
2239
|
|
|
2456
|
-
@noble/curves/esm/abstract/utils.js:
|
|
2457
|
-
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
2458
|
-
|
|
2459
2240
|
@noble/curves/esm/abstract/modular.js:
|
|
2460
2241
|
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
2461
2242
|
|
|
@@ -2471,4 +2252,4 @@ export {
|
|
|
2471
2252
|
@noble/curves/esm/secp256k1.js:
|
|
2472
2253
|
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
2473
2254
|
*/
|
|
2474
|
-
//# sourceMappingURL=secp256k1-
|
|
2255
|
+
//# sourceMappingURL=secp256k1-QCGY4Z6Q.js.map
|