save-forever-mcp 0.1.0 → 0.3.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/dist/{ccip-X5HB77FX.js → ccip-CNDQCMQK.js} +2 -2
- package/dist/chunk-JACDA5LQ.js +383 -0
- package/dist/{chunk-MDUN2K7E.js → chunk-JKB3QFBD.js} +309 -319
- package/dist/{chunk-IS73UAH3.js → chunk-TGY4KIJJ.js} +209 -2085
- package/dist/{secp256k1-YU6BFYUO.js → secp256k1-GO3WM2N3.js} +2 -2
- package/dist/server.js +3115 -14566
- package/package.json +29 -29
- package/dist/chunk-5DKVHEO2.js +0 -138
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { createHasher, anumber, rotr, clean, Hash, ahash, toBytes, aexists, abytes, randomBytes, concatBytes, createView, aoutput } from './chunk-
|
|
2
|
+
import { bytesToNumberLE, bytesToNumberBE, numberToBytesLE, numberToBytesBE, bitMask, validateObject, concatBytes2, memoized, aInRange, ensureBytes, hexToBytes, isBytes, createHmacDrbg, abool, bytesToHex, inRange, numberToHexUnpadded, bitLen, createHasher, anumber, rotr, clean, rotrSH, shrSH, rotrSL, shrSL, rotrBH, rotrBL, add4L, add4H, add5L, add5H, add, add3L, add3H, Hash, ahash, toBytes, aexists, abytes, randomBytes, concatBytes, createView, aoutput, abytes2, utf8ToBytes2, split } from './chunk-JACDA5LQ.js';
|
|
3
3
|
|
|
4
4
|
// node_modules/@noble/hashes/esm/_md.js
|
|
5
5
|
function setBigUint64(view, byteOffset, value, isLE) {
|
|
@@ -120,6 +120,24 @@ var SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
|
120
120
|
528734635,
|
|
121
121
|
1541459225
|
|
122
122
|
]);
|
|
123
|
+
var SHA512_IV = /* @__PURE__ */ Uint32Array.from([
|
|
124
|
+
1779033703,
|
|
125
|
+
4089235720,
|
|
126
|
+
3144134277,
|
|
127
|
+
2227873595,
|
|
128
|
+
1013904242,
|
|
129
|
+
4271175723,
|
|
130
|
+
2773480762,
|
|
131
|
+
1595750129,
|
|
132
|
+
1359893119,
|
|
133
|
+
2917565137,
|
|
134
|
+
2600822924,
|
|
135
|
+
725511199,
|
|
136
|
+
528734635,
|
|
137
|
+
4215389547,
|
|
138
|
+
1541459225,
|
|
139
|
+
327033209
|
|
140
|
+
]);
|
|
123
141
|
|
|
124
142
|
// node_modules/@noble/hashes/esm/sha2.js
|
|
125
143
|
var SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
@@ -259,7 +277,205 @@ var SHA256 = class extends HashMD {
|
|
|
259
277
|
clean(this.buffer);
|
|
260
278
|
}
|
|
261
279
|
};
|
|
280
|
+
var K512 = /* @__PURE__ */ (() => split([
|
|
281
|
+
"0x428a2f98d728ae22",
|
|
282
|
+
"0x7137449123ef65cd",
|
|
283
|
+
"0xb5c0fbcfec4d3b2f",
|
|
284
|
+
"0xe9b5dba58189dbbc",
|
|
285
|
+
"0x3956c25bf348b538",
|
|
286
|
+
"0x59f111f1b605d019",
|
|
287
|
+
"0x923f82a4af194f9b",
|
|
288
|
+
"0xab1c5ed5da6d8118",
|
|
289
|
+
"0xd807aa98a3030242",
|
|
290
|
+
"0x12835b0145706fbe",
|
|
291
|
+
"0x243185be4ee4b28c",
|
|
292
|
+
"0x550c7dc3d5ffb4e2",
|
|
293
|
+
"0x72be5d74f27b896f",
|
|
294
|
+
"0x80deb1fe3b1696b1",
|
|
295
|
+
"0x9bdc06a725c71235",
|
|
296
|
+
"0xc19bf174cf692694",
|
|
297
|
+
"0xe49b69c19ef14ad2",
|
|
298
|
+
"0xefbe4786384f25e3",
|
|
299
|
+
"0x0fc19dc68b8cd5b5",
|
|
300
|
+
"0x240ca1cc77ac9c65",
|
|
301
|
+
"0x2de92c6f592b0275",
|
|
302
|
+
"0x4a7484aa6ea6e483",
|
|
303
|
+
"0x5cb0a9dcbd41fbd4",
|
|
304
|
+
"0x76f988da831153b5",
|
|
305
|
+
"0x983e5152ee66dfab",
|
|
306
|
+
"0xa831c66d2db43210",
|
|
307
|
+
"0xb00327c898fb213f",
|
|
308
|
+
"0xbf597fc7beef0ee4",
|
|
309
|
+
"0xc6e00bf33da88fc2",
|
|
310
|
+
"0xd5a79147930aa725",
|
|
311
|
+
"0x06ca6351e003826f",
|
|
312
|
+
"0x142929670a0e6e70",
|
|
313
|
+
"0x27b70a8546d22ffc",
|
|
314
|
+
"0x2e1b21385c26c926",
|
|
315
|
+
"0x4d2c6dfc5ac42aed",
|
|
316
|
+
"0x53380d139d95b3df",
|
|
317
|
+
"0x650a73548baf63de",
|
|
318
|
+
"0x766a0abb3c77b2a8",
|
|
319
|
+
"0x81c2c92e47edaee6",
|
|
320
|
+
"0x92722c851482353b",
|
|
321
|
+
"0xa2bfe8a14cf10364",
|
|
322
|
+
"0xa81a664bbc423001",
|
|
323
|
+
"0xc24b8b70d0f89791",
|
|
324
|
+
"0xc76c51a30654be30",
|
|
325
|
+
"0xd192e819d6ef5218",
|
|
326
|
+
"0xd69906245565a910",
|
|
327
|
+
"0xf40e35855771202a",
|
|
328
|
+
"0x106aa07032bbd1b8",
|
|
329
|
+
"0x19a4c116b8d2d0c8",
|
|
330
|
+
"0x1e376c085141ab53",
|
|
331
|
+
"0x2748774cdf8eeb99",
|
|
332
|
+
"0x34b0bcb5e19b48a8",
|
|
333
|
+
"0x391c0cb3c5c95a63",
|
|
334
|
+
"0x4ed8aa4ae3418acb",
|
|
335
|
+
"0x5b9cca4f7763e373",
|
|
336
|
+
"0x682e6ff3d6b2b8a3",
|
|
337
|
+
"0x748f82ee5defb2fc",
|
|
338
|
+
"0x78a5636f43172f60",
|
|
339
|
+
"0x84c87814a1f0ab72",
|
|
340
|
+
"0x8cc702081a6439ec",
|
|
341
|
+
"0x90befffa23631e28",
|
|
342
|
+
"0xa4506cebde82bde9",
|
|
343
|
+
"0xbef9a3f7b2c67915",
|
|
344
|
+
"0xc67178f2e372532b",
|
|
345
|
+
"0xca273eceea26619c",
|
|
346
|
+
"0xd186b8c721c0c207",
|
|
347
|
+
"0xeada7dd6cde0eb1e",
|
|
348
|
+
"0xf57d4f7fee6ed178",
|
|
349
|
+
"0x06f067aa72176fba",
|
|
350
|
+
"0x0a637dc5a2c898a6",
|
|
351
|
+
"0x113f9804bef90dae",
|
|
352
|
+
"0x1b710b35131c471b",
|
|
353
|
+
"0x28db77f523047d84",
|
|
354
|
+
"0x32caab7b40c72493",
|
|
355
|
+
"0x3c9ebe0a15c9bebc",
|
|
356
|
+
"0x431d67c49c100d4c",
|
|
357
|
+
"0x4cc5d4becb3e42b6",
|
|
358
|
+
"0x597f299cfc657e2a",
|
|
359
|
+
"0x5fcb6fab3ad6faec",
|
|
360
|
+
"0x6c44198c4a475817"
|
|
361
|
+
].map((n) => BigInt(n))))();
|
|
362
|
+
var SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
|
|
363
|
+
var SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
|
|
364
|
+
var SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
365
|
+
var SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
366
|
+
var SHA512 = class extends HashMD {
|
|
367
|
+
constructor(outputLen = 64) {
|
|
368
|
+
super(128, outputLen, 16, false);
|
|
369
|
+
this.Ah = SHA512_IV[0] | 0;
|
|
370
|
+
this.Al = SHA512_IV[1] | 0;
|
|
371
|
+
this.Bh = SHA512_IV[2] | 0;
|
|
372
|
+
this.Bl = SHA512_IV[3] | 0;
|
|
373
|
+
this.Ch = SHA512_IV[4] | 0;
|
|
374
|
+
this.Cl = SHA512_IV[5] | 0;
|
|
375
|
+
this.Dh = SHA512_IV[6] | 0;
|
|
376
|
+
this.Dl = SHA512_IV[7] | 0;
|
|
377
|
+
this.Eh = SHA512_IV[8] | 0;
|
|
378
|
+
this.El = SHA512_IV[9] | 0;
|
|
379
|
+
this.Fh = SHA512_IV[10] | 0;
|
|
380
|
+
this.Fl = SHA512_IV[11] | 0;
|
|
381
|
+
this.Gh = SHA512_IV[12] | 0;
|
|
382
|
+
this.Gl = SHA512_IV[13] | 0;
|
|
383
|
+
this.Hh = SHA512_IV[14] | 0;
|
|
384
|
+
this.Hl = SHA512_IV[15] | 0;
|
|
385
|
+
}
|
|
386
|
+
// prettier-ignore
|
|
387
|
+
get() {
|
|
388
|
+
const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
389
|
+
return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
|
|
390
|
+
}
|
|
391
|
+
// prettier-ignore
|
|
392
|
+
set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
|
|
393
|
+
this.Ah = Ah | 0;
|
|
394
|
+
this.Al = Al | 0;
|
|
395
|
+
this.Bh = Bh | 0;
|
|
396
|
+
this.Bl = Bl | 0;
|
|
397
|
+
this.Ch = Ch | 0;
|
|
398
|
+
this.Cl = Cl | 0;
|
|
399
|
+
this.Dh = Dh | 0;
|
|
400
|
+
this.Dl = Dl | 0;
|
|
401
|
+
this.Eh = Eh | 0;
|
|
402
|
+
this.El = El | 0;
|
|
403
|
+
this.Fh = Fh | 0;
|
|
404
|
+
this.Fl = Fl | 0;
|
|
405
|
+
this.Gh = Gh | 0;
|
|
406
|
+
this.Gl = Gl | 0;
|
|
407
|
+
this.Hh = Hh | 0;
|
|
408
|
+
this.Hl = Hl | 0;
|
|
409
|
+
}
|
|
410
|
+
process(view, offset) {
|
|
411
|
+
for (let i = 0; i < 16; i++, offset += 4) {
|
|
412
|
+
SHA512_W_H[i] = view.getUint32(offset);
|
|
413
|
+
SHA512_W_L[i] = view.getUint32(offset += 4);
|
|
414
|
+
}
|
|
415
|
+
for (let i = 16; i < 80; i++) {
|
|
416
|
+
const W15h = SHA512_W_H[i - 15] | 0;
|
|
417
|
+
const W15l = SHA512_W_L[i - 15] | 0;
|
|
418
|
+
const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
|
|
419
|
+
const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
|
|
420
|
+
const W2h = SHA512_W_H[i - 2] | 0;
|
|
421
|
+
const W2l = SHA512_W_L[i - 2] | 0;
|
|
422
|
+
const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
|
|
423
|
+
const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
|
|
424
|
+
const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
|
|
425
|
+
const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
|
|
426
|
+
SHA512_W_H[i] = SUMh | 0;
|
|
427
|
+
SHA512_W_L[i] = SUMl | 0;
|
|
428
|
+
}
|
|
429
|
+
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
430
|
+
for (let i = 0; i < 80; i++) {
|
|
431
|
+
const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
|
|
432
|
+
const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
|
|
433
|
+
const CHIh = Eh & Fh ^ ~Eh & Gh;
|
|
434
|
+
const CHIl = El & Fl ^ ~El & Gl;
|
|
435
|
+
const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
|
|
436
|
+
const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
|
|
437
|
+
const T1l = T1ll | 0;
|
|
438
|
+
const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
|
|
439
|
+
const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
|
|
440
|
+
const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
|
|
441
|
+
const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
|
|
442
|
+
Hh = Gh | 0;
|
|
443
|
+
Hl = Gl | 0;
|
|
444
|
+
Gh = Fh | 0;
|
|
445
|
+
Gl = Fl | 0;
|
|
446
|
+
Fh = Eh | 0;
|
|
447
|
+
Fl = El | 0;
|
|
448
|
+
({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
449
|
+
Dh = Ch | 0;
|
|
450
|
+
Dl = Cl | 0;
|
|
451
|
+
Ch = Bh | 0;
|
|
452
|
+
Cl = Bl | 0;
|
|
453
|
+
Bh = Ah | 0;
|
|
454
|
+
Bl = Al | 0;
|
|
455
|
+
const All = add3L(T1l, sigma0l, MAJl);
|
|
456
|
+
Ah = add3H(All, T1h, sigma0h, MAJh);
|
|
457
|
+
Al = All | 0;
|
|
458
|
+
}
|
|
459
|
+
({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
460
|
+
({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
|
461
|
+
({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
462
|
+
({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
463
|
+
({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
464
|
+
({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
465
|
+
({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
466
|
+
({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
467
|
+
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
468
|
+
}
|
|
469
|
+
roundClean() {
|
|
470
|
+
clean(SHA512_W_H, SHA512_W_L);
|
|
471
|
+
}
|
|
472
|
+
destroy() {
|
|
473
|
+
clean(this.buffer);
|
|
474
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
475
|
+
}
|
|
476
|
+
};
|
|
262
477
|
var sha256 = /* @__PURE__ */ createHasher(() => new SHA256());
|
|
478
|
+
var sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
|
|
263
479
|
|
|
264
480
|
// node_modules/@noble/hashes/esm/hmac.js
|
|
265
481
|
var HMAC = class extends Hash {
|
|
@@ -329,235 +545,9 @@ var HMAC = class extends Hash {
|
|
|
329
545
|
var hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
|
|
330
546
|
hmac.create = (hash, key) => new HMAC(hash, key);
|
|
331
547
|
|
|
332
|
-
// node_modules
|
|
333
|
-
var _0n =
|
|
334
|
-
var _1n =
|
|
335
|
-
function isBytes(a) {
|
|
336
|
-
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
337
|
-
}
|
|
338
|
-
function abytes2(item) {
|
|
339
|
-
if (!isBytes(item))
|
|
340
|
-
throw new Error("Uint8Array expected");
|
|
341
|
-
}
|
|
342
|
-
function abool(title, value) {
|
|
343
|
-
if (typeof value !== "boolean")
|
|
344
|
-
throw new Error(title + " boolean expected, got " + value);
|
|
345
|
-
}
|
|
346
|
-
function numberToHexUnpadded(num2) {
|
|
347
|
-
const hex = num2.toString(16);
|
|
348
|
-
return hex.length & 1 ? "0" + hex : hex;
|
|
349
|
-
}
|
|
350
|
-
function hexToNumber(hex) {
|
|
351
|
-
if (typeof hex !== "string")
|
|
352
|
-
throw new Error("hex string expected, got " + typeof hex);
|
|
353
|
-
return hex === "" ? _0n : BigInt("0x" + hex);
|
|
354
|
-
}
|
|
355
|
-
var hasHexBuiltin = (
|
|
356
|
-
// @ts-ignore
|
|
357
|
-
typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
|
|
358
|
-
);
|
|
359
|
-
var hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
360
|
-
function bytesToHex(bytes) {
|
|
361
|
-
abytes2(bytes);
|
|
362
|
-
if (hasHexBuiltin)
|
|
363
|
-
return bytes.toHex();
|
|
364
|
-
let hex = "";
|
|
365
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
366
|
-
hex += hexes[bytes[i]];
|
|
367
|
-
}
|
|
368
|
-
return hex;
|
|
369
|
-
}
|
|
370
|
-
var asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
371
|
-
function asciiToBase16(ch) {
|
|
372
|
-
if (ch >= asciis._0 && ch <= asciis._9)
|
|
373
|
-
return ch - asciis._0;
|
|
374
|
-
if (ch >= asciis.A && ch <= asciis.F)
|
|
375
|
-
return ch - (asciis.A - 10);
|
|
376
|
-
if (ch >= asciis.a && ch <= asciis.f)
|
|
377
|
-
return ch - (asciis.a - 10);
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
|
-
function hexToBytes(hex) {
|
|
381
|
-
if (typeof hex !== "string")
|
|
382
|
-
throw new Error("hex string expected, got " + typeof hex);
|
|
383
|
-
if (hasHexBuiltin)
|
|
384
|
-
return Uint8Array.fromHex(hex);
|
|
385
|
-
const hl = hex.length;
|
|
386
|
-
const al = hl / 2;
|
|
387
|
-
if (hl % 2)
|
|
388
|
-
throw new Error("hex string expected, got unpadded hex of length " + hl);
|
|
389
|
-
const array = new Uint8Array(al);
|
|
390
|
-
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
391
|
-
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
392
|
-
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
393
|
-
if (n1 === void 0 || n2 === void 0) {
|
|
394
|
-
const char = hex[hi] + hex[hi + 1];
|
|
395
|
-
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
396
|
-
}
|
|
397
|
-
array[ai] = n1 * 16 + n2;
|
|
398
|
-
}
|
|
399
|
-
return array;
|
|
400
|
-
}
|
|
401
|
-
function bytesToNumberBE(bytes) {
|
|
402
|
-
return hexToNumber(bytesToHex(bytes));
|
|
403
|
-
}
|
|
404
|
-
function bytesToNumberLE(bytes) {
|
|
405
|
-
abytes2(bytes);
|
|
406
|
-
return hexToNumber(bytesToHex(Uint8Array.from(bytes).reverse()));
|
|
407
|
-
}
|
|
408
|
-
function numberToBytesBE(n, len) {
|
|
409
|
-
return hexToBytes(n.toString(16).padStart(len * 2, "0"));
|
|
410
|
-
}
|
|
411
|
-
function numberToBytesLE(n, len) {
|
|
412
|
-
return numberToBytesBE(n, len).reverse();
|
|
413
|
-
}
|
|
414
|
-
function ensureBytes(title, hex, expectedLength) {
|
|
415
|
-
let res;
|
|
416
|
-
if (typeof hex === "string") {
|
|
417
|
-
try {
|
|
418
|
-
res = hexToBytes(hex);
|
|
419
|
-
} catch (e) {
|
|
420
|
-
throw new Error(title + " must be hex string or Uint8Array, cause: " + e);
|
|
421
|
-
}
|
|
422
|
-
} else if (isBytes(hex)) {
|
|
423
|
-
res = Uint8Array.from(hex);
|
|
424
|
-
} else {
|
|
425
|
-
throw new Error(title + " must be hex string or Uint8Array");
|
|
426
|
-
}
|
|
427
|
-
const len = res.length;
|
|
428
|
-
if (typeof expectedLength === "number" && len !== expectedLength)
|
|
429
|
-
throw new Error(title + " of length " + expectedLength + " expected, got " + len);
|
|
430
|
-
return res;
|
|
431
|
-
}
|
|
432
|
-
function concatBytes2(...arrays) {
|
|
433
|
-
let sum = 0;
|
|
434
|
-
for (let i = 0; i < arrays.length; i++) {
|
|
435
|
-
const a = arrays[i];
|
|
436
|
-
abytes2(a);
|
|
437
|
-
sum += a.length;
|
|
438
|
-
}
|
|
439
|
-
const res = new Uint8Array(sum);
|
|
440
|
-
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
441
|
-
const a = arrays[i];
|
|
442
|
-
res.set(a, pad);
|
|
443
|
-
pad += a.length;
|
|
444
|
-
}
|
|
445
|
-
return res;
|
|
446
|
-
}
|
|
447
|
-
function utf8ToBytes(str) {
|
|
448
|
-
if (typeof str !== "string")
|
|
449
|
-
throw new Error("string expected");
|
|
450
|
-
return new Uint8Array(new TextEncoder().encode(str));
|
|
451
|
-
}
|
|
452
|
-
var isPosBig = (n) => typeof n === "bigint" && _0n <= n;
|
|
453
|
-
function inRange(n, min, max) {
|
|
454
|
-
return isPosBig(n) && isPosBig(min) && isPosBig(max) && min <= n && n < max;
|
|
455
|
-
}
|
|
456
|
-
function aInRange(title, n, min, max) {
|
|
457
|
-
if (!inRange(n, min, max))
|
|
458
|
-
throw new Error("expected valid " + title + ": " + min + " <= n < " + max + ", got " + n);
|
|
459
|
-
}
|
|
460
|
-
function bitLen(n) {
|
|
461
|
-
let len;
|
|
462
|
-
for (len = 0; n > _0n; n >>= _1n, len += 1)
|
|
463
|
-
;
|
|
464
|
-
return len;
|
|
465
|
-
}
|
|
466
|
-
var bitMask = (n) => (_1n << BigInt(n)) - _1n;
|
|
467
|
-
var u8n = (len) => new Uint8Array(len);
|
|
468
|
-
var u8fr = (arr) => Uint8Array.from(arr);
|
|
469
|
-
function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
470
|
-
if (typeof hashLen !== "number" || hashLen < 2)
|
|
471
|
-
throw new Error("hashLen must be a number");
|
|
472
|
-
if (typeof qByteLen !== "number" || qByteLen < 2)
|
|
473
|
-
throw new Error("qByteLen must be a number");
|
|
474
|
-
if (typeof hmacFn !== "function")
|
|
475
|
-
throw new Error("hmacFn must be a function");
|
|
476
|
-
let v = u8n(hashLen);
|
|
477
|
-
let k = u8n(hashLen);
|
|
478
|
-
let i = 0;
|
|
479
|
-
const reset = () => {
|
|
480
|
-
v.fill(1);
|
|
481
|
-
k.fill(0);
|
|
482
|
-
i = 0;
|
|
483
|
-
};
|
|
484
|
-
const h = (...b) => hmacFn(k, v, ...b);
|
|
485
|
-
const reseed = (seed = u8n(0)) => {
|
|
486
|
-
k = h(u8fr([0]), seed);
|
|
487
|
-
v = h();
|
|
488
|
-
if (seed.length === 0)
|
|
489
|
-
return;
|
|
490
|
-
k = h(u8fr([1]), seed);
|
|
491
|
-
v = h();
|
|
492
|
-
};
|
|
493
|
-
const gen = () => {
|
|
494
|
-
if (i++ >= 1e3)
|
|
495
|
-
throw new Error("drbg: tried 1000 values");
|
|
496
|
-
let len = 0;
|
|
497
|
-
const out = [];
|
|
498
|
-
while (len < qByteLen) {
|
|
499
|
-
v = h();
|
|
500
|
-
const sl = v.slice();
|
|
501
|
-
out.push(sl);
|
|
502
|
-
len += v.length;
|
|
503
|
-
}
|
|
504
|
-
return concatBytes2(...out);
|
|
505
|
-
};
|
|
506
|
-
const genUntil = (seed, pred) => {
|
|
507
|
-
reset();
|
|
508
|
-
reseed(seed);
|
|
509
|
-
let res = void 0;
|
|
510
|
-
while (!(res = pred(gen())))
|
|
511
|
-
reseed();
|
|
512
|
-
reset();
|
|
513
|
-
return res;
|
|
514
|
-
};
|
|
515
|
-
return genUntil;
|
|
516
|
-
}
|
|
517
|
-
var validatorFns = {
|
|
518
|
-
bigint: (val) => typeof val === "bigint",
|
|
519
|
-
function: (val) => typeof val === "function",
|
|
520
|
-
boolean: (val) => typeof val === "boolean",
|
|
521
|
-
string: (val) => typeof val === "string",
|
|
522
|
-
stringOrUint8Array: (val) => typeof val === "string" || isBytes(val),
|
|
523
|
-
isSafeInteger: (val) => Number.isSafeInteger(val),
|
|
524
|
-
array: (val) => Array.isArray(val),
|
|
525
|
-
field: (val, object) => object.Fp.isValid(val),
|
|
526
|
-
hash: (val) => typeof val === "function" && Number.isSafeInteger(val.outputLen)
|
|
527
|
-
};
|
|
528
|
-
function validateObject(object, validators, optValidators = {}) {
|
|
529
|
-
const checkField = (fieldName, type, isOptional) => {
|
|
530
|
-
const checkVal = validatorFns[type];
|
|
531
|
-
if (typeof checkVal !== "function")
|
|
532
|
-
throw new Error("invalid validator function");
|
|
533
|
-
const val = object[fieldName];
|
|
534
|
-
if (isOptional && val === void 0)
|
|
535
|
-
return;
|
|
536
|
-
if (!checkVal(val, object)) {
|
|
537
|
-
throw new Error("param " + String(fieldName) + " is invalid. Expected " + type + ", got " + val);
|
|
538
|
-
}
|
|
539
|
-
};
|
|
540
|
-
for (const [fieldName, type] of Object.entries(validators))
|
|
541
|
-
checkField(fieldName, type, false);
|
|
542
|
-
for (const [fieldName, type] of Object.entries(optValidators))
|
|
543
|
-
checkField(fieldName, type, true);
|
|
544
|
-
return object;
|
|
545
|
-
}
|
|
546
|
-
function memoized(fn) {
|
|
547
|
-
const map = /* @__PURE__ */ new WeakMap();
|
|
548
|
-
return (arg, ...args) => {
|
|
549
|
-
const val = map.get(arg);
|
|
550
|
-
if (val !== void 0)
|
|
551
|
-
return val;
|
|
552
|
-
const computed = fn(arg, ...args);
|
|
553
|
-
map.set(arg, computed);
|
|
554
|
-
return computed;
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
// node_modules/viem/node_modules/@noble/curves/esm/abstract/modular.js
|
|
559
|
-
var _0n2 = BigInt(0);
|
|
560
|
-
var _1n2 = BigInt(1);
|
|
548
|
+
// node_modules/@noble/curves/esm/abstract/modular.js
|
|
549
|
+
var _0n = BigInt(0);
|
|
550
|
+
var _1n = BigInt(1);
|
|
561
551
|
var _2n = /* @__PURE__ */ BigInt(2);
|
|
562
552
|
var _3n = /* @__PURE__ */ BigInt(3);
|
|
563
553
|
var _4n = /* @__PURE__ */ BigInt(4);
|
|
@@ -565,37 +555,37 @@ var _5n = /* @__PURE__ */ BigInt(5);
|
|
|
565
555
|
var _8n = /* @__PURE__ */ BigInt(8);
|
|
566
556
|
function mod(a, b) {
|
|
567
557
|
const result = a % b;
|
|
568
|
-
return result >=
|
|
558
|
+
return result >= _0n ? result : b + result;
|
|
569
559
|
}
|
|
570
560
|
function pow2(x, power, modulo) {
|
|
571
561
|
let res = x;
|
|
572
|
-
while (power-- >
|
|
562
|
+
while (power-- > _0n) {
|
|
573
563
|
res *= res;
|
|
574
564
|
res %= modulo;
|
|
575
565
|
}
|
|
576
566
|
return res;
|
|
577
567
|
}
|
|
578
568
|
function invert(number, modulo) {
|
|
579
|
-
if (number ===
|
|
569
|
+
if (number === _0n)
|
|
580
570
|
throw new Error("invert: expected non-zero number");
|
|
581
|
-
if (modulo <=
|
|
571
|
+
if (modulo <= _0n)
|
|
582
572
|
throw new Error("invert: expected positive modulus, got " + modulo);
|
|
583
573
|
let a = mod(number, modulo);
|
|
584
574
|
let b = modulo;
|
|
585
|
-
let x =
|
|
586
|
-
while (a !==
|
|
575
|
+
let x = _0n, u = _1n;
|
|
576
|
+
while (a !== _0n) {
|
|
587
577
|
const q = b / a;
|
|
588
578
|
const r = b % a;
|
|
589
579
|
const m = x - u * q;
|
|
590
580
|
b = a, a = r, x = u, u = m;
|
|
591
581
|
}
|
|
592
582
|
const gcd = b;
|
|
593
|
-
if (gcd !==
|
|
583
|
+
if (gcd !== _1n)
|
|
594
584
|
throw new Error("invert: does not exist");
|
|
595
585
|
return mod(x, modulo);
|
|
596
586
|
}
|
|
597
587
|
function sqrt3mod4(Fp, n) {
|
|
598
|
-
const p1div4 = (Fp.ORDER +
|
|
588
|
+
const p1div4 = (Fp.ORDER + _1n) / _4n;
|
|
599
589
|
const root = Fp.pow(n, p1div4);
|
|
600
590
|
if (!Fp.eql(Fp.sqr(root), n))
|
|
601
591
|
throw new Error("Cannot find square root");
|
|
@@ -615,9 +605,9 @@ function sqrt5mod8(Fp, n) {
|
|
|
615
605
|
function tonelliShanks(P) {
|
|
616
606
|
if (P < BigInt(3))
|
|
617
607
|
throw new Error("sqrt is not defined for small field");
|
|
618
|
-
let Q = P -
|
|
608
|
+
let Q = P - _1n;
|
|
619
609
|
let S = 0;
|
|
620
|
-
while (Q % _2n ===
|
|
610
|
+
while (Q % _2n === _0n) {
|
|
621
611
|
Q /= _2n;
|
|
622
612
|
S++;
|
|
623
613
|
}
|
|
@@ -630,7 +620,7 @@ function tonelliShanks(P) {
|
|
|
630
620
|
if (S === 1)
|
|
631
621
|
return sqrt3mod4;
|
|
632
622
|
let cc = _Fp.pow(Z, Q);
|
|
633
|
-
const Q1div2 = (Q +
|
|
623
|
+
const Q1div2 = (Q + _1n) / _2n;
|
|
634
624
|
return function tonelliSlow(Fp, n) {
|
|
635
625
|
if (Fp.is0(n))
|
|
636
626
|
return n;
|
|
@@ -651,7 +641,7 @@ function tonelliShanks(P) {
|
|
|
651
641
|
if (i === M)
|
|
652
642
|
throw new Error("Cannot find square root");
|
|
653
643
|
}
|
|
654
|
-
const exponent =
|
|
644
|
+
const exponent = _1n << BigInt(M - i - 1);
|
|
655
645
|
const b = Fp.pow(c, exponent);
|
|
656
646
|
M = i;
|
|
657
647
|
c = Fp.sqr(b);
|
|
@@ -668,6 +658,7 @@ function FpSqrt(P) {
|
|
|
668
658
|
return sqrt5mod8;
|
|
669
659
|
return tonelliShanks(P);
|
|
670
660
|
}
|
|
661
|
+
var isNegativeLE = (num2, modulo) => (mod(num2, modulo) & _1n) === _1n;
|
|
671
662
|
var FIELD_FIELDS = [
|
|
672
663
|
"create",
|
|
673
664
|
"isValid",
|
|
@@ -701,19 +692,19 @@ function validateField(field) {
|
|
|
701
692
|
return validateObject(field, opts);
|
|
702
693
|
}
|
|
703
694
|
function FpPow(Fp, num2, power) {
|
|
704
|
-
if (power <
|
|
695
|
+
if (power < _0n)
|
|
705
696
|
throw new Error("invalid exponent, negatives unsupported");
|
|
706
|
-
if (power ===
|
|
697
|
+
if (power === _0n)
|
|
707
698
|
return Fp.ONE;
|
|
708
|
-
if (power ===
|
|
699
|
+
if (power === _1n)
|
|
709
700
|
return num2;
|
|
710
701
|
let p = Fp.ONE;
|
|
711
702
|
let d = num2;
|
|
712
|
-
while (power >
|
|
713
|
-
if (power &
|
|
703
|
+
while (power > _0n) {
|
|
704
|
+
if (power & _1n)
|
|
714
705
|
p = Fp.mul(p, d);
|
|
715
706
|
d = Fp.sqr(d);
|
|
716
|
-
power >>=
|
|
707
|
+
power >>= _1n;
|
|
717
708
|
}
|
|
718
709
|
return p;
|
|
719
710
|
}
|
|
@@ -735,7 +726,7 @@ function FpInvertBatch(Fp, nums, passZero = false) {
|
|
|
735
726
|
return inverted;
|
|
736
727
|
}
|
|
737
728
|
function FpLegendre(Fp, n) {
|
|
738
|
-
const p1mod2 = (Fp.ORDER -
|
|
729
|
+
const p1mod2 = (Fp.ORDER - _1n) / _2n;
|
|
739
730
|
const powered = Fp.pow(n, p1mod2);
|
|
740
731
|
const yes = Fp.eql(powered, Fp.ONE);
|
|
741
732
|
const zero = Fp.eql(powered, Fp.ZERO);
|
|
@@ -752,7 +743,7 @@ function nLength(n, nBitLength) {
|
|
|
752
743
|
return { nBitLength: _nBitLength, nByteLength };
|
|
753
744
|
}
|
|
754
745
|
function Field(ORDER, bitLen2, isLE = false, redef = {}) {
|
|
755
|
-
if (ORDER <=
|
|
746
|
+
if (ORDER <= _0n)
|
|
756
747
|
throw new Error("invalid field: expected ORDER > 0, got " + ORDER);
|
|
757
748
|
const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, bitLen2);
|
|
758
749
|
if (BYTES > 2048)
|
|
@@ -764,16 +755,16 @@ function Field(ORDER, bitLen2, isLE = false, redef = {}) {
|
|
|
764
755
|
BITS,
|
|
765
756
|
BYTES,
|
|
766
757
|
MASK: bitMask(BITS),
|
|
767
|
-
ZERO:
|
|
768
|
-
ONE:
|
|
758
|
+
ZERO: _0n,
|
|
759
|
+
ONE: _1n,
|
|
769
760
|
create: (num2) => mod(num2, ORDER),
|
|
770
761
|
isValid: (num2) => {
|
|
771
762
|
if (typeof num2 !== "bigint")
|
|
772
763
|
throw new Error("invalid field element: expected bigint, got " + typeof num2);
|
|
773
|
-
return
|
|
764
|
+
return _0n <= num2 && num2 < ORDER;
|
|
774
765
|
},
|
|
775
|
-
is0: (num2) => num2 ===
|
|
776
|
-
isOdd: (num2) => (num2 &
|
|
766
|
+
is0: (num2) => num2 === _0n,
|
|
767
|
+
isOdd: (num2) => (num2 & _1n) === _1n,
|
|
777
768
|
neg: (num2) => mod(-num2, ORDER),
|
|
778
769
|
eql: (lhs, rhs) => lhs === rhs,
|
|
779
770
|
sqr: (num2) => mod(num2 * num2, ORDER),
|
|
@@ -824,13 +815,13 @@ function mapHashToField(key, fieldOrder, isLE = false) {
|
|
|
824
815
|
if (len < 16 || len < minLen || len > 1024)
|
|
825
816
|
throw new Error("expected " + minLen + "-1024 bytes of input, got " + len);
|
|
826
817
|
const num2 = isLE ? bytesToNumberLE(key) : bytesToNumberBE(key);
|
|
827
|
-
const reduced = mod(num2, fieldOrder -
|
|
818
|
+
const reduced = mod(num2, fieldOrder - _1n) + _1n;
|
|
828
819
|
return isLE ? numberToBytesLE(reduced, fieldLen) : numberToBytesBE(reduced, fieldLen);
|
|
829
820
|
}
|
|
830
821
|
|
|
831
|
-
// node_modules
|
|
832
|
-
var
|
|
833
|
-
var
|
|
822
|
+
// node_modules/@noble/curves/esm/abstract/curve.js
|
|
823
|
+
var _0n2 = BigInt(0);
|
|
824
|
+
var _1n2 = BigInt(1);
|
|
834
825
|
function constTimeNegate(condition, item) {
|
|
835
826
|
const neg = item.negate();
|
|
836
827
|
return condition ? neg : item;
|
|
@@ -854,7 +845,7 @@ function calcOffsets(n, window, wOpts) {
|
|
|
854
845
|
let nextN = n >> shiftBy;
|
|
855
846
|
if (wbits > windowSize) {
|
|
856
847
|
wbits -= maxNumber;
|
|
857
|
-
nextN +=
|
|
848
|
+
nextN += _1n2;
|
|
858
849
|
}
|
|
859
850
|
const offsetStart = window * windowSize;
|
|
860
851
|
const offset = offsetStart + Math.abs(wbits) - 1;
|
|
@@ -894,11 +885,11 @@ function wNAF(c, bits) {
|
|
|
894
885
|
// non-const time multiplication ladder
|
|
895
886
|
unsafeLadder(elm, n, p = c.ZERO) {
|
|
896
887
|
let d = elm;
|
|
897
|
-
while (n >
|
|
898
|
-
if (n &
|
|
888
|
+
while (n > _0n2) {
|
|
889
|
+
if (n & _1n2)
|
|
899
890
|
p = p.add(d);
|
|
900
891
|
d = d.double();
|
|
901
|
-
n >>=
|
|
892
|
+
n >>= _1n2;
|
|
902
893
|
}
|
|
903
894
|
return p;
|
|
904
895
|
},
|
|
@@ -963,7 +954,7 @@ function wNAF(c, bits) {
|
|
|
963
954
|
wNAFUnsafe(W, precomputes, n, acc = c.ZERO) {
|
|
964
955
|
const wo = calcWOpts(W, bits);
|
|
965
956
|
for (let window = 0; window < wo.windows; window++) {
|
|
966
|
-
if (n ===
|
|
957
|
+
if (n === _0n2)
|
|
967
958
|
break;
|
|
968
959
|
const { nextN, offset, isZero, isNeg } = calcOffsets(n, window, wo);
|
|
969
960
|
n = nextN;
|
|
@@ -1062,7 +1053,7 @@ function validateBasic(curve) {
|
|
|
1062
1053
|
});
|
|
1063
1054
|
}
|
|
1064
1055
|
|
|
1065
|
-
// node_modules
|
|
1056
|
+
// node_modules/@noble/curves/esm/abstract/weierstrass.js
|
|
1066
1057
|
function validateSigVerOpts(opts) {
|
|
1067
1058
|
if (opts.lowS !== void 0)
|
|
1068
1059
|
abool("lowS", opts.lowS);
|
|
@@ -1161,7 +1152,7 @@ var DER = {
|
|
|
1161
1152
|
_int: {
|
|
1162
1153
|
encode(num2) {
|
|
1163
1154
|
const { Err: E } = DER;
|
|
1164
|
-
if (num2 <
|
|
1155
|
+
if (num2 < _0n3)
|
|
1165
1156
|
throw new E("integer: negative integers are not allowed");
|
|
1166
1157
|
let hex = numberToHexUnpadded(num2);
|
|
1167
1158
|
if (Number.parseInt(hex[0], 16) & 8)
|
|
@@ -1202,8 +1193,8 @@ var DER = {
|
|
|
1202
1193
|
function numToSizedHex(num2, size) {
|
|
1203
1194
|
return bytesToHex(numberToBytesBE(num2, size));
|
|
1204
1195
|
}
|
|
1205
|
-
var
|
|
1206
|
-
var
|
|
1196
|
+
var _0n3 = BigInt(0);
|
|
1197
|
+
var _1n3 = BigInt(1);
|
|
1207
1198
|
var _2n2 = BigInt(2);
|
|
1208
1199
|
var _3n2 = BigInt(3);
|
|
1209
1200
|
var _4n2 = BigInt(4);
|
|
@@ -1239,7 +1230,7 @@ function weierstrassPoints(opts) {
|
|
|
1239
1230
|
if (Fp.is0(Fp.add(_4a3, _27b2)))
|
|
1240
1231
|
throw new Error("bad curve params: a or b");
|
|
1241
1232
|
function isWithinCurveOrder(num2) {
|
|
1242
|
-
return inRange(num2,
|
|
1233
|
+
return inRange(num2, _1n3, CURVE.n);
|
|
1243
1234
|
}
|
|
1244
1235
|
function normPrivateKeyToScalar(key) {
|
|
1245
1236
|
const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n: N } = CURVE;
|
|
@@ -1258,7 +1249,7 @@ function weierstrassPoints(opts) {
|
|
|
1258
1249
|
}
|
|
1259
1250
|
if (wrapPrivateKey)
|
|
1260
1251
|
num2 = mod(num2, N);
|
|
1261
|
-
aInRange("private key", num2,
|
|
1252
|
+
aInRange("private key", num2, _1n3, N);
|
|
1262
1253
|
return num2;
|
|
1263
1254
|
}
|
|
1264
1255
|
function aprjpoint(other) {
|
|
@@ -1497,11 +1488,11 @@ function weierstrassPoints(opts) {
|
|
|
1497
1488
|
*/
|
|
1498
1489
|
multiplyUnsafe(sc) {
|
|
1499
1490
|
const { endo: endo2, n: N } = CURVE;
|
|
1500
|
-
aInRange("scalar", sc,
|
|
1491
|
+
aInRange("scalar", sc, _0n3, N);
|
|
1501
1492
|
const I = Point2.ZERO;
|
|
1502
|
-
if (sc ===
|
|
1493
|
+
if (sc === _0n3)
|
|
1503
1494
|
return I;
|
|
1504
|
-
if (this.is0() || sc ===
|
|
1495
|
+
if (this.is0() || sc === _1n3)
|
|
1505
1496
|
return this;
|
|
1506
1497
|
if (!endo2 || wnaf.hasPrecomputes(this))
|
|
1507
1498
|
return wnaf.wNAFCachedUnsafe(this, sc, Point2.normalizeZ);
|
|
@@ -1509,14 +1500,14 @@ function weierstrassPoints(opts) {
|
|
|
1509
1500
|
let k1p = I;
|
|
1510
1501
|
let k2p = I;
|
|
1511
1502
|
let d = this;
|
|
1512
|
-
while (k1 >
|
|
1513
|
-
if (k1 &
|
|
1503
|
+
while (k1 > _0n3 || k2 > _0n3) {
|
|
1504
|
+
if (k1 & _1n3)
|
|
1514
1505
|
k1p = k1p.add(d);
|
|
1515
|
-
if (k2 &
|
|
1506
|
+
if (k2 & _1n3)
|
|
1516
1507
|
k2p = k2p.add(d);
|
|
1517
1508
|
d = d.double();
|
|
1518
|
-
k1 >>=
|
|
1519
|
-
k2 >>=
|
|
1509
|
+
k1 >>= _1n3;
|
|
1510
|
+
k2 >>= _1n3;
|
|
1520
1511
|
}
|
|
1521
1512
|
if (k1neg)
|
|
1522
1513
|
k1p = k1p.negate();
|
|
@@ -1536,7 +1527,7 @@ function weierstrassPoints(opts) {
|
|
|
1536
1527
|
*/
|
|
1537
1528
|
multiply(scalar) {
|
|
1538
1529
|
const { endo: endo2, n: N } = CURVE;
|
|
1539
|
-
aInRange("scalar", scalar,
|
|
1530
|
+
aInRange("scalar", scalar, _1n3, N);
|
|
1540
1531
|
let point, fake;
|
|
1541
1532
|
if (endo2) {
|
|
1542
1533
|
const { k1neg, k1, k2neg, k2 } = endo2.splitScalar(scalar);
|
|
@@ -1562,7 +1553,7 @@ function weierstrassPoints(opts) {
|
|
|
1562
1553
|
*/
|
|
1563
1554
|
multiplyAndAddUnsafe(Q, a, b) {
|
|
1564
1555
|
const G = Point2.BASE;
|
|
1565
|
-
const mul = (P, a2) => a2 ===
|
|
1556
|
+
const mul = (P, a2) => a2 === _0n3 || a2 === _1n3 || !P.equals(G) ? P.multiplyUnsafe(a2) : P.multiply(a2);
|
|
1566
1557
|
const sum = mul(this, a).add(mul(Q, b));
|
|
1567
1558
|
return sum.is0() ? void 0 : sum;
|
|
1568
1559
|
}
|
|
@@ -1574,7 +1565,7 @@ function weierstrassPoints(opts) {
|
|
|
1574
1565
|
}
|
|
1575
1566
|
isTorsionFree() {
|
|
1576
1567
|
const { h: cofactor, isTorsionFree } = CURVE;
|
|
1577
|
-
if (cofactor ===
|
|
1568
|
+
if (cofactor === _1n3)
|
|
1578
1569
|
return true;
|
|
1579
1570
|
if (isTorsionFree)
|
|
1580
1571
|
return isTorsionFree(Point2, this);
|
|
@@ -1582,7 +1573,7 @@ function weierstrassPoints(opts) {
|
|
|
1582
1573
|
}
|
|
1583
1574
|
clearCofactor() {
|
|
1584
1575
|
const { h: cofactor, clearCofactor } = CURVE;
|
|
1585
|
-
if (cofactor ===
|
|
1576
|
+
if (cofactor === _1n3)
|
|
1586
1577
|
return this;
|
|
1587
1578
|
if (clearCofactor)
|
|
1588
1579
|
return clearCofactor(Point2, this);
|
|
@@ -1653,7 +1644,7 @@ function weierstrass(curveDef) {
|
|
|
1653
1644
|
const tail = bytes.subarray(1);
|
|
1654
1645
|
if (len === compressedLen && (head === 2 || head === 3)) {
|
|
1655
1646
|
const x = bytesToNumberBE(tail);
|
|
1656
|
-
if (!inRange(x,
|
|
1647
|
+
if (!inRange(x, _1n3, Fp.ORDER))
|
|
1657
1648
|
throw new Error("Point is not on curve");
|
|
1658
1649
|
const y2 = weierstrassEquation(x);
|
|
1659
1650
|
let y;
|
|
@@ -1663,7 +1654,7 @@ function weierstrass(curveDef) {
|
|
|
1663
1654
|
const suffix = sqrtError instanceof Error ? ": " + sqrtError.message : "";
|
|
1664
1655
|
throw new Error("Point is not on curve" + suffix);
|
|
1665
1656
|
}
|
|
1666
|
-
const isYOdd = (y &
|
|
1657
|
+
const isYOdd = (y & _1n3) === _1n3;
|
|
1667
1658
|
const isHeadOdd = (head & 1) === 1;
|
|
1668
1659
|
if (isHeadOdd !== isYOdd)
|
|
1669
1660
|
y = Fp.neg(y);
|
|
@@ -1680,7 +1671,7 @@ function weierstrass(curveDef) {
|
|
|
1680
1671
|
}
|
|
1681
1672
|
});
|
|
1682
1673
|
function isBiggerThanHalfOrder(number) {
|
|
1683
|
-
const HALF = CURVE_ORDER >>
|
|
1674
|
+
const HALF = CURVE_ORDER >> _1n3;
|
|
1684
1675
|
return number > HALF;
|
|
1685
1676
|
}
|
|
1686
1677
|
function normalizeS(s) {
|
|
@@ -1689,8 +1680,8 @@ function weierstrass(curveDef) {
|
|
|
1689
1680
|
const slcNum = (b, from, to) => bytesToNumberBE(b.slice(from, to));
|
|
1690
1681
|
class Signature {
|
|
1691
1682
|
constructor(r, s, recovery) {
|
|
1692
|
-
aInRange("r", r,
|
|
1693
|
-
aInRange("s", s,
|
|
1683
|
+
aInRange("r", r, _1n3, CURVE_ORDER);
|
|
1684
|
+
aInRange("s", s, _1n3, CURVE_ORDER);
|
|
1694
1685
|
this.r = r;
|
|
1695
1686
|
this.s = s;
|
|
1696
1687
|
if (recovery != null)
|
|
@@ -1831,7 +1822,7 @@ function weierstrass(curveDef) {
|
|
|
1831
1822
|
};
|
|
1832
1823
|
const ORDER_MASK = bitMask(nBitLength);
|
|
1833
1824
|
function int2octets(num2) {
|
|
1834
|
-
aInRange("num < 2^" + nBitLength, num2,
|
|
1825
|
+
aInRange("num < 2^" + nBitLength, num2, _0n3, ORDER_MASK);
|
|
1835
1826
|
return numberToBytesBE(num2, nByteLength);
|
|
1836
1827
|
}
|
|
1837
1828
|
function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
|
|
@@ -1861,12 +1852,12 @@ function weierstrass(curveDef) {
|
|
|
1861
1852
|
const ik = invN(k);
|
|
1862
1853
|
const q = Point2.BASE.multiply(k).toAffine();
|
|
1863
1854
|
const r = modN2(q.x);
|
|
1864
|
-
if (r ===
|
|
1855
|
+
if (r === _0n3)
|
|
1865
1856
|
return;
|
|
1866
1857
|
const s = modN2(ik * modN2(m + r * d));
|
|
1867
|
-
if (s ===
|
|
1858
|
+
if (s === _0n3)
|
|
1868
1859
|
return;
|
|
1869
|
-
let recovery = (q.x === r ? 0 : 2) | Number(q.y &
|
|
1860
|
+
let recovery = (q.x === r ? 0 : 2) | Number(q.y & _1n3);
|
|
1870
1861
|
let normS = s;
|
|
1871
1862
|
if (lowS && isBiggerThanHalfOrder(s)) {
|
|
1872
1863
|
normS = normalizeS(s);
|
|
@@ -1949,18 +1940,18 @@ function weierstrass(curveDef) {
|
|
|
1949
1940
|
}
|
|
1950
1941
|
function SWUFpSqrtRatio(Fp, Z) {
|
|
1951
1942
|
const q = Fp.ORDER;
|
|
1952
|
-
let l =
|
|
1953
|
-
for (let o = q -
|
|
1954
|
-
l +=
|
|
1943
|
+
let l = _0n3;
|
|
1944
|
+
for (let o = q - _1n3; o % _2n2 === _0n3; o /= _2n2)
|
|
1945
|
+
l += _1n3;
|
|
1955
1946
|
const c1 = l;
|
|
1956
|
-
const _2n_pow_c1_1 = _2n2 << c1 -
|
|
1947
|
+
const _2n_pow_c1_1 = _2n2 << c1 - _1n3 - _1n3;
|
|
1957
1948
|
const _2n_pow_c1 = _2n_pow_c1_1 * _2n2;
|
|
1958
|
-
const c2 = (q -
|
|
1959
|
-
const c3 = (c2 -
|
|
1960
|
-
const c4 = _2n_pow_c1 -
|
|
1949
|
+
const c2 = (q - _1n3) / _2n_pow_c1;
|
|
1950
|
+
const c3 = (c2 - _1n3) / _2n2;
|
|
1951
|
+
const c4 = _2n_pow_c1 - _1n3;
|
|
1961
1952
|
const c5 = _2n_pow_c1_1;
|
|
1962
1953
|
const c6 = Fp.pow(Z, c2);
|
|
1963
|
-
const c7 = Fp.pow(Z, (c2 +
|
|
1954
|
+
const c7 = Fp.pow(Z, (c2 + _1n3) / _2n2);
|
|
1964
1955
|
let sqrtRatio = (u, v) => {
|
|
1965
1956
|
let tv1 = c6;
|
|
1966
1957
|
let tv2 = Fp.pow(v, c4);
|
|
@@ -1978,9 +1969,9 @@ function SWUFpSqrtRatio(Fp, Z) {
|
|
|
1978
1969
|
tv5 = Fp.mul(tv4, tv1);
|
|
1979
1970
|
tv3 = Fp.cmov(tv2, tv3, isQR);
|
|
1980
1971
|
tv4 = Fp.cmov(tv5, tv4, isQR);
|
|
1981
|
-
for (let i = c1; i >
|
|
1972
|
+
for (let i = c1; i > _1n3; i--) {
|
|
1982
1973
|
let tv52 = i - _2n2;
|
|
1983
|
-
tv52 = _2n2 << tv52 -
|
|
1974
|
+
tv52 = _2n2 << tv52 - _1n3;
|
|
1984
1975
|
let tvv5 = Fp.pow(tv4, tv52);
|
|
1985
1976
|
const e1 = Fp.eql(tvv5, Fp.ONE);
|
|
1986
1977
|
tv2 = Fp.mul(tv3, tv1);
|
|
@@ -2048,7 +2039,7 @@ function mapToCurveSimpleSWU(Fp, opts) {
|
|
|
2048
2039
|
};
|
|
2049
2040
|
}
|
|
2050
2041
|
|
|
2051
|
-
// node_modules
|
|
2042
|
+
// node_modules/@noble/curves/esm/_shortw_utils.js
|
|
2052
2043
|
function getHash(hash) {
|
|
2053
2044
|
return {
|
|
2054
2045
|
hash,
|
|
@@ -2061,7 +2052,7 @@ function createCurve(curveDef, defHash) {
|
|
|
2061
2052
|
return { ...create(defHash), create };
|
|
2062
2053
|
}
|
|
2063
2054
|
|
|
2064
|
-
// node_modules
|
|
2055
|
+
// node_modules/@noble/curves/esm/abstract/hash-to-curve.js
|
|
2065
2056
|
var os2ip = bytesToNumberBE;
|
|
2066
2057
|
function i2osp(value, length) {
|
|
2067
2058
|
anum(value);
|
|
@@ -2091,7 +2082,7 @@ function expand_message_xmd(msg, DST, lenInBytes, H) {
|
|
|
2091
2082
|
abytes2(DST);
|
|
2092
2083
|
anum(lenInBytes);
|
|
2093
2084
|
if (DST.length > 255)
|
|
2094
|
-
DST = H(concatBytes2(
|
|
2085
|
+
DST = H(concatBytes2(utf8ToBytes2("H2C-OVERSIZE-DST-"), DST));
|
|
2095
2086
|
const { outputLen: b_in_bytes, blockLen: r_in_bytes } = H;
|
|
2096
2087
|
const ell = Math.ceil(lenInBytes / b_in_bytes);
|
|
2097
2088
|
if (lenInBytes > 65535 || ell > 255)
|
|
@@ -2115,7 +2106,7 @@ function expand_message_xof(msg, DST, lenInBytes, k, H) {
|
|
|
2115
2106
|
anum(lenInBytes);
|
|
2116
2107
|
if (DST.length > 255) {
|
|
2117
2108
|
const dkLen = Math.ceil(2 * k / 8);
|
|
2118
|
-
DST = H.create({ dkLen }).update(
|
|
2109
|
+
DST = H.create({ dkLen }).update(utf8ToBytes2("H2C-OVERSIZE-DST-")).update(DST).digest();
|
|
2119
2110
|
}
|
|
2120
2111
|
if (lenInBytes > 65535 || DST.length > 255)
|
|
2121
2112
|
throw new Error("expand_message_xof: invalid lenInBytes");
|
|
@@ -2132,7 +2123,7 @@ function hash_to_field(msg, count, options) {
|
|
|
2132
2123
|
const { p, k, m, hash, expand, DST: _DST } = options;
|
|
2133
2124
|
abytes2(msg);
|
|
2134
2125
|
anum(count);
|
|
2135
|
-
const DST = typeof _DST === "string" ?
|
|
2126
|
+
const DST = typeof _DST === "string" ? utf8ToBytes2(_DST) : _DST;
|
|
2136
2127
|
const log2p = p.toString(2).length;
|
|
2137
2128
|
const L = Math.ceil((log2p + k) / 8);
|
|
2138
2129
|
const len_in_bytes = count * m * L;
|
|
@@ -2209,11 +2200,11 @@ function createHasher2(Point2, mapToCurve, defaults) {
|
|
|
2209
2200
|
};
|
|
2210
2201
|
}
|
|
2211
2202
|
|
|
2212
|
-
// node_modules
|
|
2203
|
+
// node_modules/@noble/curves/esm/secp256k1.js
|
|
2213
2204
|
var secp256k1P = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f");
|
|
2214
2205
|
var secp256k1N = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
|
|
2215
|
-
var
|
|
2216
|
-
var
|
|
2206
|
+
var _0n4 = BigInt(0);
|
|
2207
|
+
var _1n4 = BigInt(1);
|
|
2217
2208
|
var _2n3 = BigInt(2);
|
|
2218
2209
|
var divNearest = (a, b) => (a + b / _2n3) / b;
|
|
2219
2210
|
function sqrtMod(y) {
|
|
@@ -2240,7 +2231,7 @@ function sqrtMod(y) {
|
|
|
2240
2231
|
}
|
|
2241
2232
|
var Fpk1 = Field(secp256k1P, void 0, void 0, { sqrt: sqrtMod });
|
|
2242
2233
|
var secp256k1 = createCurve({
|
|
2243
|
-
a:
|
|
2234
|
+
a: _0n4,
|
|
2244
2235
|
b: BigInt(7),
|
|
2245
2236
|
Fp: Fpk1,
|
|
2246
2237
|
n: secp256k1N,
|
|
@@ -2255,7 +2246,7 @@ var secp256k1 = createCurve({
|
|
|
2255
2246
|
splitScalar: (k) => {
|
|
2256
2247
|
const n = secp256k1N;
|
|
2257
2248
|
const a1 = BigInt("0x3086d221a7d46bcde86c90e49284eb15");
|
|
2258
|
-
const b1 = -
|
|
2249
|
+
const b1 = -_1n4 * BigInt("0xe4437ed6010e88286f547fa90abfe4c3");
|
|
2259
2250
|
const a2 = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8");
|
|
2260
2251
|
const b2 = a1;
|
|
2261
2252
|
const POW_2_128 = BigInt("0x100000000000000000000000000000000");
|
|
@@ -2299,13 +2290,13 @@ function schnorrGetExtPubKey(priv) {
|
|
|
2299
2290
|
return { scalar, bytes: pointToBytes(p) };
|
|
2300
2291
|
}
|
|
2301
2292
|
function lift_x(x) {
|
|
2302
|
-
aInRange("x", x,
|
|
2293
|
+
aInRange("x", x, _1n4, secp256k1P);
|
|
2303
2294
|
const xx = modP(x * x);
|
|
2304
2295
|
const c = modP(xx * x + BigInt(7));
|
|
2305
2296
|
let y = sqrtMod(c);
|
|
2306
|
-
if (y % _2n3 !==
|
|
2297
|
+
if (y % _2n3 !== _0n4)
|
|
2307
2298
|
y = modP(-y);
|
|
2308
|
-
const p = new Point(x, y,
|
|
2299
|
+
const p = new Point(x, y, _1n4);
|
|
2309
2300
|
p.assertValidity();
|
|
2310
2301
|
return p;
|
|
2311
2302
|
}
|
|
@@ -2323,7 +2314,7 @@ function schnorrSign(message, privateKey, auxRand = randomBytes(32)) {
|
|
|
2323
2314
|
const t = numTo32b(d ^ num(taggedHash("BIP0340/aux", a)));
|
|
2324
2315
|
const rand = taggedHash("BIP0340/nonce", t, px, m);
|
|
2325
2316
|
const k_ = modN(num(rand));
|
|
2326
|
-
if (k_ ===
|
|
2317
|
+
if (k_ === _0n4)
|
|
2327
2318
|
throw new Error("sign failed: k is zero");
|
|
2328
2319
|
const { bytes: rx, scalar: k } = schnorrGetExtPubKey(k_);
|
|
2329
2320
|
const e = challenge(rx, px, m);
|
|
@@ -2341,10 +2332,10 @@ function schnorrVerify(signature, message, publicKey) {
|
|
|
2341
2332
|
try {
|
|
2342
2333
|
const P = lift_x(num(pub));
|
|
2343
2334
|
const r = num(sig.subarray(0, 32));
|
|
2344
|
-
if (!inRange(r,
|
|
2335
|
+
if (!inRange(r, _1n4, secp256k1P))
|
|
2345
2336
|
return false;
|
|
2346
2337
|
const s = num(sig.subarray(32, 64));
|
|
2347
|
-
if (!inRange(s,
|
|
2338
|
+
if (!inRange(s, _1n4, secp256k1N))
|
|
2348
2339
|
return false;
|
|
2349
2340
|
const e = challenge(numTo32b(r), pointToBytes(P), m);
|
|
2350
2341
|
const R = GmulAdd(P, s, modN(-e));
|
|
@@ -2421,7 +2412,6 @@ var hashToCurve = /* @__PURE__ */ (() => secp256k1_hasher.hashToCurve)();
|
|
|
2421
2412
|
var encodeToCurve = /* @__PURE__ */ (() => secp256k1_hasher.encodeToCurve)();
|
|
2422
2413
|
/*! Bundled license information:
|
|
2423
2414
|
|
|
2424
|
-
@noble/curves/esm/abstract/utils.js:
|
|
2425
2415
|
@noble/curves/esm/abstract/modular.js:
|
|
2426
2416
|
@noble/curves/esm/abstract/curve.js:
|
|
2427
2417
|
@noble/curves/esm/abstract/weierstrass.js:
|
|
@@ -2430,4 +2420,4 @@ var encodeToCurve = /* @__PURE__ */ (() => secp256k1_hasher.encodeToCurve)();
|
|
|
2430
2420
|
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
2431
2421
|
*/
|
|
2432
2422
|
|
|
2433
|
-
export { encodeToCurve, hashToCurve, hmac, schnorr, secp256k1, secp256k1_hasher, sha256 };
|
|
2423
|
+
export { Field, FpInvertBatch, encodeToCurve, hashToCurve, hmac, isNegativeLE, mod, pippenger, pow2, schnorr, secp256k1, secp256k1_hasher, sha256, sha512, validateBasic, wNAF };
|