@volr/react 0.1.62 → 0.1.64
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/index.cjs +97 -1811
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +97 -1811
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -4580,7 +4580,7 @@ var init_hmac = __esm({
|
|
|
4580
4580
|
}
|
|
4581
4581
|
});
|
|
4582
4582
|
|
|
4583
|
-
// ../node_modules
|
|
4583
|
+
// ../node_modules/@noble/curves/esm/abstract/utils.js
|
|
4584
4584
|
function isBytes2(a) {
|
|
4585
4585
|
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
4586
4586
|
}
|
|
@@ -4784,7 +4784,7 @@ function memoized(fn) {
|
|
|
4784
4784
|
}
|
|
4785
4785
|
var _0n2, _1n2, hasHexBuiltin, hexes2, asciis, isPosBig, bitMask, u8n, u8fr, validatorFns;
|
|
4786
4786
|
var init_utils4 = __esm({
|
|
4787
|
-
"../node_modules
|
|
4787
|
+
"../node_modules/@noble/curves/esm/abstract/utils.js"() {
|
|
4788
4788
|
_0n2 = /* @__PURE__ */ BigInt(0);
|
|
4789
4789
|
_1n2 = /* @__PURE__ */ BigInt(1);
|
|
4790
4790
|
hasHexBuiltin = // @ts-ignore
|
|
@@ -4809,7 +4809,7 @@ var init_utils4 = __esm({
|
|
|
4809
4809
|
}
|
|
4810
4810
|
});
|
|
4811
4811
|
|
|
4812
|
-
// ../node_modules
|
|
4812
|
+
// ../node_modules/@noble/curves/esm/abstract/modular.js
|
|
4813
4813
|
function mod(a, b) {
|
|
4814
4814
|
const result = a % b;
|
|
4815
4815
|
return result >= _0n3 ? result : b + result;
|
|
@@ -4979,10 +4979,10 @@ function nLength(n, nBitLength) {
|
|
|
4979
4979
|
const nByteLength = Math.ceil(_nBitLength / 8);
|
|
4980
4980
|
return { nBitLength: _nBitLength, nByteLength };
|
|
4981
4981
|
}
|
|
4982
|
-
function Field(ORDER,
|
|
4982
|
+
function Field(ORDER, bitLen2, isLE2 = false, redef = {}) {
|
|
4983
4983
|
if (ORDER <= _0n3)
|
|
4984
4984
|
throw new Error("invalid field: expected ORDER > 0, got " + ORDER);
|
|
4985
|
-
const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER,
|
|
4985
|
+
const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, bitLen2);
|
|
4986
4986
|
if (BYTES > 2048)
|
|
4987
4987
|
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
4988
4988
|
let sqrtP;
|
|
@@ -5057,7 +5057,7 @@ function mapHashToField(key, fieldOrder, isLE2 = false) {
|
|
|
5057
5057
|
}
|
|
5058
5058
|
var _0n3, _1n3, _2n2, _3n, _4n, _5n, _8n, FIELD_FIELDS;
|
|
5059
5059
|
var init_modular = __esm({
|
|
5060
|
-
"../node_modules
|
|
5060
|
+
"../node_modules/@noble/curves/esm/abstract/modular.js"() {
|
|
5061
5061
|
init_utils2();
|
|
5062
5062
|
init_utils4();
|
|
5063
5063
|
_0n3 = BigInt(0);
|
|
@@ -5089,7 +5089,7 @@ var init_modular = __esm({
|
|
|
5089
5089
|
}
|
|
5090
5090
|
});
|
|
5091
5091
|
|
|
5092
|
-
// ../node_modules
|
|
5092
|
+
// ../node_modules/@noble/curves/esm/abstract/curve.js
|
|
5093
5093
|
function constTimeNegate(condition, item) {
|
|
5094
5094
|
const neg = item.negate();
|
|
5095
5095
|
return condition ? neg : item;
|
|
@@ -5320,7 +5320,7 @@ function validateBasic(curve) {
|
|
|
5320
5320
|
}
|
|
5321
5321
|
var _0n4, _1n4, pointPrecomputes, pointWindowSizes;
|
|
5322
5322
|
var init_curve = __esm({
|
|
5323
|
-
"../node_modules
|
|
5323
|
+
"../node_modules/@noble/curves/esm/abstract/curve.js"() {
|
|
5324
5324
|
init_modular();
|
|
5325
5325
|
init_utils4();
|
|
5326
5326
|
_0n4 = BigInt(0);
|
|
@@ -5330,7 +5330,7 @@ var init_curve = __esm({
|
|
|
5330
5330
|
}
|
|
5331
5331
|
});
|
|
5332
5332
|
|
|
5333
|
-
// ../node_modules
|
|
5333
|
+
// ../node_modules/@noble/curves/esm/abstract/weierstrass.js
|
|
5334
5334
|
function validateSigVerOpts(opts) {
|
|
5335
5335
|
if (opts.lowS !== void 0)
|
|
5336
5336
|
abool("lowS", opts.lowS);
|
|
@@ -6207,7 +6207,7 @@ function mapToCurveSimpleSWU(Fp, opts) {
|
|
|
6207
6207
|
}
|
|
6208
6208
|
var DERErr, DER, _0n5, _1n5, _2n3, _3n2, _4n2;
|
|
6209
6209
|
var init_weierstrass = __esm({
|
|
6210
|
-
"../node_modules
|
|
6210
|
+
"../node_modules/@noble/curves/esm/abstract/weierstrass.js"() {
|
|
6211
6211
|
init_curve();
|
|
6212
6212
|
init_modular();
|
|
6213
6213
|
init_utils4();
|
|
@@ -6324,7 +6324,7 @@ var init_weierstrass = __esm({
|
|
|
6324
6324
|
}
|
|
6325
6325
|
});
|
|
6326
6326
|
|
|
6327
|
-
// ../node_modules
|
|
6327
|
+
// ../node_modules/@noble/curves/esm/_shortw_utils.js
|
|
6328
6328
|
function getHash(hash3) {
|
|
6329
6329
|
return {
|
|
6330
6330
|
hash: hash3,
|
|
@@ -6337,14 +6337,14 @@ function createCurve(curveDef, defHash) {
|
|
|
6337
6337
|
return { ...create2(defHash), create: create2 };
|
|
6338
6338
|
}
|
|
6339
6339
|
var init_shortw_utils = __esm({
|
|
6340
|
-
"../node_modules
|
|
6340
|
+
"../node_modules/@noble/curves/esm/_shortw_utils.js"() {
|
|
6341
6341
|
init_hmac();
|
|
6342
6342
|
init_utils2();
|
|
6343
6343
|
init_weierstrass();
|
|
6344
6344
|
}
|
|
6345
6345
|
});
|
|
6346
6346
|
|
|
6347
|
-
// ../node_modules
|
|
6347
|
+
// ../node_modules/@noble/curves/esm/abstract/hash-to-curve.js
|
|
6348
6348
|
function i2osp(value, length) {
|
|
6349
6349
|
anum(value);
|
|
6350
6350
|
anum(length);
|
|
@@ -6492,14 +6492,14 @@ function createHasher2(Point2, mapToCurve, defaults) {
|
|
|
6492
6492
|
}
|
|
6493
6493
|
var os2ip;
|
|
6494
6494
|
var init_hash_to_curve = __esm({
|
|
6495
|
-
"../node_modules
|
|
6495
|
+
"../node_modules/@noble/curves/esm/abstract/hash-to-curve.js"() {
|
|
6496
6496
|
init_modular();
|
|
6497
6497
|
init_utils4();
|
|
6498
6498
|
os2ip = bytesToNumberBE;
|
|
6499
6499
|
}
|
|
6500
6500
|
});
|
|
6501
6501
|
|
|
6502
|
-
// ../node_modules
|
|
6502
|
+
// ../node_modules/@noble/curves/esm/secp256k1.js
|
|
6503
6503
|
var secp256k1_exports = {};
|
|
6504
6504
|
__export(secp256k1_exports, {
|
|
6505
6505
|
encodeToCurve: () => encodeToCurve,
|
|
@@ -6510,19 +6510,19 @@ __export(secp256k1_exports, {
|
|
|
6510
6510
|
});
|
|
6511
6511
|
function sqrtMod(y) {
|
|
6512
6512
|
const P = secp256k1P;
|
|
6513
|
-
const
|
|
6513
|
+
const _3n3 = BigInt(3), _6n = BigInt(6), _11n = BigInt(11), _22n = BigInt(22);
|
|
6514
6514
|
const _23n = BigInt(23), _44n = BigInt(44), _88n = BigInt(88);
|
|
6515
6515
|
const b2 = y * y * y % P;
|
|
6516
6516
|
const b3 = b2 * b2 * y % P;
|
|
6517
|
-
const b6 = pow2(b3,
|
|
6518
|
-
const b9 = pow2(b6,
|
|
6517
|
+
const b6 = pow2(b3, _3n3, P) * b3 % P;
|
|
6518
|
+
const b9 = pow2(b6, _3n3, P) * b3 % P;
|
|
6519
6519
|
const b11 = pow2(b9, _2n4, P) * b2 % P;
|
|
6520
6520
|
const b22 = pow2(b11, _11n, P) * b11 % P;
|
|
6521
6521
|
const b44 = pow2(b22, _22n, P) * b22 % P;
|
|
6522
6522
|
const b88 = pow2(b44, _44n, P) * b44 % P;
|
|
6523
6523
|
const b176 = pow2(b88, _88n, P) * b88 % P;
|
|
6524
6524
|
const b220 = pow2(b176, _44n, P) * b44 % P;
|
|
6525
|
-
const b223 = pow2(b220,
|
|
6525
|
+
const b223 = pow2(b220, _3n3, P) * b3 % P;
|
|
6526
6526
|
const t1 = pow2(b223, _23n, P) * b22 % P;
|
|
6527
6527
|
const t2 = pow2(t1, _6n, P) * b2 % P;
|
|
6528
6528
|
const root = pow2(t2, _2n4, P);
|
|
@@ -6603,7 +6603,7 @@ function schnorrVerify(signature, message, publicKey) {
|
|
|
6603
6603
|
}
|
|
6604
6604
|
var secp256k1P, secp256k1N, _0n6, _1n6, _2n4, divNearest, Fpk1, secp256k1, TAGGED_HASH_PREFIXES, pointToBytes, numTo32b, modP, modN, Point, GmulAdd, num, schnorr, isoMap, mapSWU, secp256k1_hasher, hashToCurve, encodeToCurve;
|
|
6605
6605
|
var init_secp256k1 = __esm({
|
|
6606
|
-
"../node_modules
|
|
6606
|
+
"../node_modules/@noble/curves/esm/secp256k1.js"() {
|
|
6607
6607
|
init_sha2();
|
|
6608
6608
|
init_utils2();
|
|
6609
6609
|
init_shortw_utils();
|
|
@@ -7202,230 +7202,6 @@ var init_decodeFunctionResult = __esm({
|
|
|
7202
7202
|
}
|
|
7203
7203
|
});
|
|
7204
7204
|
|
|
7205
|
-
// ../node_modules/ox/node_modules/@noble/curves/esm/abstract/utils.js
|
|
7206
|
-
function isBytes3(a) {
|
|
7207
|
-
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
7208
|
-
}
|
|
7209
|
-
function abytes3(item) {
|
|
7210
|
-
if (!isBytes3(item))
|
|
7211
|
-
throw new Error("Uint8Array expected");
|
|
7212
|
-
}
|
|
7213
|
-
function abool2(title, value) {
|
|
7214
|
-
if (typeof value !== "boolean")
|
|
7215
|
-
throw new Error(title + " boolean expected, got " + value);
|
|
7216
|
-
}
|
|
7217
|
-
function numberToHexUnpadded2(num2) {
|
|
7218
|
-
const hex = num2.toString(16);
|
|
7219
|
-
return hex.length & 1 ? "0" + hex : hex;
|
|
7220
|
-
}
|
|
7221
|
-
function hexToNumber3(hex) {
|
|
7222
|
-
if (typeof hex !== "string")
|
|
7223
|
-
throw new Error("hex string expected, got " + typeof hex);
|
|
7224
|
-
return hex === "" ? _0n7 : BigInt("0x" + hex);
|
|
7225
|
-
}
|
|
7226
|
-
function bytesToHex3(bytes) {
|
|
7227
|
-
abytes3(bytes);
|
|
7228
|
-
if (hasHexBuiltin2)
|
|
7229
|
-
return bytes.toHex();
|
|
7230
|
-
let hex = "";
|
|
7231
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
7232
|
-
hex += hexes3[bytes[i]];
|
|
7233
|
-
}
|
|
7234
|
-
return hex;
|
|
7235
|
-
}
|
|
7236
|
-
function asciiToBase162(ch) {
|
|
7237
|
-
if (ch >= asciis2._0 && ch <= asciis2._9)
|
|
7238
|
-
return ch - asciis2._0;
|
|
7239
|
-
if (ch >= asciis2.A && ch <= asciis2.F)
|
|
7240
|
-
return ch - (asciis2.A - 10);
|
|
7241
|
-
if (ch >= asciis2.a && ch <= asciis2.f)
|
|
7242
|
-
return ch - (asciis2.a - 10);
|
|
7243
|
-
return;
|
|
7244
|
-
}
|
|
7245
|
-
function hexToBytes3(hex) {
|
|
7246
|
-
if (typeof hex !== "string")
|
|
7247
|
-
throw new Error("hex string expected, got " + typeof hex);
|
|
7248
|
-
if (hasHexBuiltin2)
|
|
7249
|
-
return Uint8Array.fromHex(hex);
|
|
7250
|
-
const hl = hex.length;
|
|
7251
|
-
const al = hl / 2;
|
|
7252
|
-
if (hl % 2)
|
|
7253
|
-
throw new Error("hex string expected, got unpadded hex of length " + hl);
|
|
7254
|
-
const array = new Uint8Array(al);
|
|
7255
|
-
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
7256
|
-
const n1 = asciiToBase162(hex.charCodeAt(hi));
|
|
7257
|
-
const n2 = asciiToBase162(hex.charCodeAt(hi + 1));
|
|
7258
|
-
if (n1 === void 0 || n2 === void 0) {
|
|
7259
|
-
const char = hex[hi] + hex[hi + 1];
|
|
7260
|
-
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
7261
|
-
}
|
|
7262
|
-
array[ai] = n1 * 16 + n2;
|
|
7263
|
-
}
|
|
7264
|
-
return array;
|
|
7265
|
-
}
|
|
7266
|
-
function bytesToNumberBE2(bytes) {
|
|
7267
|
-
return hexToNumber3(bytesToHex3(bytes));
|
|
7268
|
-
}
|
|
7269
|
-
function bytesToNumberLE2(bytes) {
|
|
7270
|
-
abytes3(bytes);
|
|
7271
|
-
return hexToNumber3(bytesToHex3(Uint8Array.from(bytes).reverse()));
|
|
7272
|
-
}
|
|
7273
|
-
function numberToBytesBE2(n, len) {
|
|
7274
|
-
return hexToBytes3(n.toString(16).padStart(len * 2, "0"));
|
|
7275
|
-
}
|
|
7276
|
-
function numberToBytesLE2(n, len) {
|
|
7277
|
-
return numberToBytesBE2(n, len).reverse();
|
|
7278
|
-
}
|
|
7279
|
-
function ensureBytes2(title, hex, expectedLength) {
|
|
7280
|
-
let res;
|
|
7281
|
-
if (typeof hex === "string") {
|
|
7282
|
-
try {
|
|
7283
|
-
res = hexToBytes3(hex);
|
|
7284
|
-
} catch (e) {
|
|
7285
|
-
throw new Error(title + " must be hex string or Uint8Array, cause: " + e);
|
|
7286
|
-
}
|
|
7287
|
-
} else if (isBytes3(hex)) {
|
|
7288
|
-
res = Uint8Array.from(hex);
|
|
7289
|
-
} else {
|
|
7290
|
-
throw new Error(title + " must be hex string or Uint8Array");
|
|
7291
|
-
}
|
|
7292
|
-
const len = res.length;
|
|
7293
|
-
if (typeof expectedLength === "number" && len !== expectedLength)
|
|
7294
|
-
throw new Error(title + " of length " + expectedLength + " expected, got " + len);
|
|
7295
|
-
return res;
|
|
7296
|
-
}
|
|
7297
|
-
function concatBytes4(...arrays) {
|
|
7298
|
-
let sum = 0;
|
|
7299
|
-
for (let i = 0; i < arrays.length; i++) {
|
|
7300
|
-
const a = arrays[i];
|
|
7301
|
-
abytes3(a);
|
|
7302
|
-
sum += a.length;
|
|
7303
|
-
}
|
|
7304
|
-
const res = new Uint8Array(sum);
|
|
7305
|
-
for (let i = 0, pad4 = 0; i < arrays.length; i++) {
|
|
7306
|
-
const a = arrays[i];
|
|
7307
|
-
res.set(a, pad4);
|
|
7308
|
-
pad4 += a.length;
|
|
7309
|
-
}
|
|
7310
|
-
return res;
|
|
7311
|
-
}
|
|
7312
|
-
function inRange2(n, min, max) {
|
|
7313
|
-
return isPosBig2(n) && isPosBig2(min) && isPosBig2(max) && min <= n && n < max;
|
|
7314
|
-
}
|
|
7315
|
-
function aInRange2(title, n, min, max) {
|
|
7316
|
-
if (!inRange2(n, min, max))
|
|
7317
|
-
throw new Error("expected valid " + title + ": " + min + " <= n < " + max + ", got " + n);
|
|
7318
|
-
}
|
|
7319
|
-
function bitLen2(n) {
|
|
7320
|
-
let len;
|
|
7321
|
-
for (len = 0; n > _0n7; n >>= _1n7, len += 1)
|
|
7322
|
-
;
|
|
7323
|
-
return len;
|
|
7324
|
-
}
|
|
7325
|
-
function createHmacDrbg2(hashLen, qByteLen, hmacFn) {
|
|
7326
|
-
if (typeof hashLen !== "number" || hashLen < 2)
|
|
7327
|
-
throw new Error("hashLen must be a number");
|
|
7328
|
-
if (typeof qByteLen !== "number" || qByteLen < 2)
|
|
7329
|
-
throw new Error("qByteLen must be a number");
|
|
7330
|
-
if (typeof hmacFn !== "function")
|
|
7331
|
-
throw new Error("hmacFn must be a function");
|
|
7332
|
-
let v = u8n2(hashLen);
|
|
7333
|
-
let k = u8n2(hashLen);
|
|
7334
|
-
let i = 0;
|
|
7335
|
-
const reset = () => {
|
|
7336
|
-
v.fill(1);
|
|
7337
|
-
k.fill(0);
|
|
7338
|
-
i = 0;
|
|
7339
|
-
};
|
|
7340
|
-
const h = (...b) => hmacFn(k, v, ...b);
|
|
7341
|
-
const reseed = (seed = u8n2(0)) => {
|
|
7342
|
-
k = h(u8fr2([0]), seed);
|
|
7343
|
-
v = h();
|
|
7344
|
-
if (seed.length === 0)
|
|
7345
|
-
return;
|
|
7346
|
-
k = h(u8fr2([1]), seed);
|
|
7347
|
-
v = h();
|
|
7348
|
-
};
|
|
7349
|
-
const gen2 = () => {
|
|
7350
|
-
if (i++ >= 1e3)
|
|
7351
|
-
throw new Error("drbg: tried 1000 values");
|
|
7352
|
-
let len = 0;
|
|
7353
|
-
const out = [];
|
|
7354
|
-
while (len < qByteLen) {
|
|
7355
|
-
v = h();
|
|
7356
|
-
const sl = v.slice();
|
|
7357
|
-
out.push(sl);
|
|
7358
|
-
len += v.length;
|
|
7359
|
-
}
|
|
7360
|
-
return concatBytes4(...out);
|
|
7361
|
-
};
|
|
7362
|
-
const genUntil = (seed, pred) => {
|
|
7363
|
-
reset();
|
|
7364
|
-
reseed(seed);
|
|
7365
|
-
let res = void 0;
|
|
7366
|
-
while (!(res = pred(gen2())))
|
|
7367
|
-
reseed();
|
|
7368
|
-
reset();
|
|
7369
|
-
return res;
|
|
7370
|
-
};
|
|
7371
|
-
return genUntil;
|
|
7372
|
-
}
|
|
7373
|
-
function validateObject2(object, validators, optValidators = {}) {
|
|
7374
|
-
const checkField = (fieldName, type, isOptional) => {
|
|
7375
|
-
const checkVal = validatorFns2[type];
|
|
7376
|
-
if (typeof checkVal !== "function")
|
|
7377
|
-
throw new Error("invalid validator function");
|
|
7378
|
-
const val = object[fieldName];
|
|
7379
|
-
if (isOptional && val === void 0)
|
|
7380
|
-
return;
|
|
7381
|
-
if (!checkVal(val, object)) {
|
|
7382
|
-
throw new Error("param " + String(fieldName) + " is invalid. Expected " + type + ", got " + val);
|
|
7383
|
-
}
|
|
7384
|
-
};
|
|
7385
|
-
for (const [fieldName, type] of Object.entries(validators))
|
|
7386
|
-
checkField(fieldName, type, false);
|
|
7387
|
-
for (const [fieldName, type] of Object.entries(optValidators))
|
|
7388
|
-
checkField(fieldName, type, true);
|
|
7389
|
-
return object;
|
|
7390
|
-
}
|
|
7391
|
-
function memoized2(fn) {
|
|
7392
|
-
const map = /* @__PURE__ */ new WeakMap();
|
|
7393
|
-
return (arg, ...args) => {
|
|
7394
|
-
const val = map.get(arg);
|
|
7395
|
-
if (val !== void 0)
|
|
7396
|
-
return val;
|
|
7397
|
-
const computed = fn(arg, ...args);
|
|
7398
|
-
map.set(arg, computed);
|
|
7399
|
-
return computed;
|
|
7400
|
-
};
|
|
7401
|
-
}
|
|
7402
|
-
var _0n7, _1n7, hasHexBuiltin2, hexes3, asciis2, isPosBig2, bitMask2, u8n2, u8fr2, validatorFns2;
|
|
7403
|
-
var init_utils5 = __esm({
|
|
7404
|
-
"../node_modules/ox/node_modules/@noble/curves/esm/abstract/utils.js"() {
|
|
7405
|
-
_0n7 = /* @__PURE__ */ BigInt(0);
|
|
7406
|
-
_1n7 = /* @__PURE__ */ BigInt(1);
|
|
7407
|
-
hasHexBuiltin2 = // @ts-ignore
|
|
7408
|
-
typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function";
|
|
7409
|
-
hexes3 = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
7410
|
-
asciis2 = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
7411
|
-
isPosBig2 = (n) => typeof n === "bigint" && _0n7 <= n;
|
|
7412
|
-
bitMask2 = (n) => (_1n7 << BigInt(n)) - _1n7;
|
|
7413
|
-
u8n2 = (len) => new Uint8Array(len);
|
|
7414
|
-
u8fr2 = (arr) => Uint8Array.from(arr);
|
|
7415
|
-
validatorFns2 = {
|
|
7416
|
-
bigint: (val) => typeof val === "bigint",
|
|
7417
|
-
function: (val) => typeof val === "function",
|
|
7418
|
-
boolean: (val) => typeof val === "boolean",
|
|
7419
|
-
string: (val) => typeof val === "string",
|
|
7420
|
-
stringOrUint8Array: (val) => typeof val === "string" || isBytes3(val),
|
|
7421
|
-
isSafeInteger: (val) => Number.isSafeInteger(val),
|
|
7422
|
-
array: (val) => Array.isArray(val),
|
|
7423
|
-
field: (val, object) => object.Fp.isValid(val),
|
|
7424
|
-
hash: (val) => typeof val === "function" && Number.isSafeInteger(val.outputLen)
|
|
7425
|
-
};
|
|
7426
|
-
}
|
|
7427
|
-
});
|
|
7428
|
-
|
|
7429
7205
|
// ../node_modules/ox/_esm/core/version.js
|
|
7430
7206
|
var version3;
|
|
7431
7207
|
var init_version3 = __esm({
|
|
@@ -7892,7 +7668,7 @@ function fromBoolean(value, options = {}) {
|
|
|
7892
7668
|
function fromBytes(value, options = {}) {
|
|
7893
7669
|
let string = "";
|
|
7894
7670
|
for (let i = 0; i < value.length; i++)
|
|
7895
|
-
string +=
|
|
7671
|
+
string += hexes3[value[i]];
|
|
7896
7672
|
const hex = `0x${string}`;
|
|
7897
7673
|
if (typeof options.size === "number") {
|
|
7898
7674
|
assertSize3(hex, options.size);
|
|
@@ -7981,14 +7757,14 @@ function validate2(value, options = {}) {
|
|
|
7981
7757
|
return false;
|
|
7982
7758
|
}
|
|
7983
7759
|
}
|
|
7984
|
-
var encoder4,
|
|
7760
|
+
var encoder4, hexes3, IntegerOutOfRangeError2, InvalidHexTypeError, InvalidHexValueError, SizeOverflowError3, SliceOffsetOutOfBoundsError3, SizeExceedsPaddingSizeError3;
|
|
7985
7761
|
var init_Hex = __esm({
|
|
7986
7762
|
"../node_modules/ox/_esm/core/Hex.js"() {
|
|
7987
7763
|
init_Errors();
|
|
7988
7764
|
init_hex();
|
|
7989
7765
|
init_Json();
|
|
7990
7766
|
encoder4 = /* @__PURE__ */ new TextEncoder();
|
|
7991
|
-
|
|
7767
|
+
hexes3 = /* @__PURE__ */ Array.from({ length: 256 }, (_v, i) => i.toString(16).padStart(2, "0"));
|
|
7992
7768
|
IntegerOutOfRangeError2 = class extends BaseError3 {
|
|
7993
7769
|
constructor({ max, min, signed, size: size5, value }) {
|
|
7994
7770
|
super(`Number \`${value}\` is not in safe${size5 ? ` ${size5 * 8}-bit` : ""}${signed ? " signed" : " unsigned"} integer range ${max ? `(\`${min}\` to \`${max}\`)` : `(above \`${min}\`)`}`);
|
|
@@ -10693,20 +10469,20 @@ init_fromHex();
|
|
|
10693
10469
|
init_toHex();
|
|
10694
10470
|
async function recoverPublicKey({ hash: hash3, signature }) {
|
|
10695
10471
|
const hashHex = isHex(hash3) ? hash3 : toHex(hash3);
|
|
10696
|
-
const { secp256k1:
|
|
10472
|
+
const { secp256k1: secp256k12 } = await Promise.resolve().then(() => (init_secp256k1(), secp256k1_exports));
|
|
10697
10473
|
const signature_ = (() => {
|
|
10698
10474
|
if (typeof signature === "object" && "r" in signature && "s" in signature) {
|
|
10699
10475
|
const { r, s, v, yParity } = signature;
|
|
10700
10476
|
const yParityOrV2 = Number(yParity ?? v);
|
|
10701
10477
|
const recoveryBit2 = toRecoveryBit(yParityOrV2);
|
|
10702
|
-
return new
|
|
10478
|
+
return new secp256k12.Signature(hexToBigInt(r), hexToBigInt(s)).addRecoveryBit(recoveryBit2);
|
|
10703
10479
|
}
|
|
10704
10480
|
const signatureHex = isHex(signature) ? signature : toHex(signature);
|
|
10705
10481
|
if (size(signatureHex) !== 65)
|
|
10706
10482
|
throw new Error("invalid signature length");
|
|
10707
10483
|
const yParityOrV = hexToNumber(`0x${signatureHex.slice(130)}`);
|
|
10708
10484
|
const recoveryBit = toRecoveryBit(yParityOrV);
|
|
10709
|
-
return
|
|
10485
|
+
return secp256k12.Signature.fromCompact(signatureHex.substring(2, 130)).addRecoveryBit(recoveryBit);
|
|
10710
10486
|
})();
|
|
10711
10487
|
const publicKey = signature_.recoverPublicKey(hashHex.substring(2)).toHex(false);
|
|
10712
10488
|
return `0x${publicKey}`;
|
|
@@ -15800,1564 +15576,79 @@ function getSizeOfLength2(length) {
|
|
|
15800
15576
|
throw new BaseError3("Length is too large.");
|
|
15801
15577
|
}
|
|
15802
15578
|
|
|
15803
|
-
// ../node_modules/ox/
|
|
15804
|
-
|
|
15805
|
-
|
|
15806
|
-
|
|
15807
|
-
|
|
15808
|
-
|
|
15809
|
-
|
|
15810
|
-
|
|
15811
|
-
|
|
15812
|
-
|
|
15813
|
-
|
|
15814
|
-
|
|
15815
|
-
|
|
15816
|
-
|
|
15817
|
-
|
|
15818
|
-
|
|
15819
|
-
|
|
15820
|
-
|
|
15821
|
-
const result = a % b;
|
|
15822
|
-
return result >= _0n8 ? result : b + result;
|
|
15579
|
+
// ../node_modules/ox/_esm/core/Signature.js
|
|
15580
|
+
init_Errors();
|
|
15581
|
+
init_Hex();
|
|
15582
|
+
init_Json();
|
|
15583
|
+
function assert5(signature, options = {}) {
|
|
15584
|
+
const { recovered } = options;
|
|
15585
|
+
if (typeof signature.r === "undefined")
|
|
15586
|
+
throw new MissingPropertiesError({ signature });
|
|
15587
|
+
if (typeof signature.s === "undefined")
|
|
15588
|
+
throw new MissingPropertiesError({ signature });
|
|
15589
|
+
if (recovered && typeof signature.yParity === "undefined")
|
|
15590
|
+
throw new MissingPropertiesError({ signature });
|
|
15591
|
+
if (signature.r < 0n || signature.r > maxUint2562)
|
|
15592
|
+
throw new InvalidRError({ value: signature.r });
|
|
15593
|
+
if (signature.s < 0n || signature.s > maxUint2562)
|
|
15594
|
+
throw new InvalidSError({ value: signature.s });
|
|
15595
|
+
if (typeof signature.yParity === "number" && signature.yParity !== 0 && signature.yParity !== 1)
|
|
15596
|
+
throw new InvalidYParityError({ value: signature.yParity });
|
|
15823
15597
|
}
|
|
15824
|
-
function
|
|
15825
|
-
|
|
15826
|
-
while (power-- > _0n8) {
|
|
15827
|
-
res *= res;
|
|
15828
|
-
res %= modulo;
|
|
15829
|
-
}
|
|
15830
|
-
return res;
|
|
15598
|
+
function fromBytes3(signature) {
|
|
15599
|
+
return fromHex4(fromBytes(signature));
|
|
15831
15600
|
}
|
|
15832
|
-
function
|
|
15833
|
-
if (
|
|
15834
|
-
throw new
|
|
15835
|
-
|
|
15836
|
-
|
|
15837
|
-
|
|
15838
|
-
|
|
15839
|
-
|
|
15840
|
-
|
|
15841
|
-
|
|
15842
|
-
|
|
15843
|
-
|
|
15844
|
-
|
|
15845
|
-
|
|
15846
|
-
|
|
15847
|
-
if (
|
|
15848
|
-
|
|
15849
|
-
|
|
15601
|
+
function fromHex4(signature) {
|
|
15602
|
+
if (signature.length !== 130 && signature.length !== 132)
|
|
15603
|
+
throw new InvalidSerializedSizeError2({ signature });
|
|
15604
|
+
const r = BigInt(slice3(signature, 0, 32));
|
|
15605
|
+
const s = BigInt(slice3(signature, 32, 64));
|
|
15606
|
+
const yParity = (() => {
|
|
15607
|
+
const yParity2 = Number(`0x${signature.slice(130)}`);
|
|
15608
|
+
if (Number.isNaN(yParity2))
|
|
15609
|
+
return void 0;
|
|
15610
|
+
try {
|
|
15611
|
+
return vToYParity(yParity2);
|
|
15612
|
+
} catch {
|
|
15613
|
+
throw new InvalidYParityError({ value: yParity2 });
|
|
15614
|
+
}
|
|
15615
|
+
})();
|
|
15616
|
+
if (typeof yParity === "undefined")
|
|
15617
|
+
return {
|
|
15618
|
+
r,
|
|
15619
|
+
s
|
|
15620
|
+
};
|
|
15621
|
+
return {
|
|
15622
|
+
r,
|
|
15623
|
+
s,
|
|
15624
|
+
yParity
|
|
15625
|
+
};
|
|
15850
15626
|
}
|
|
15851
|
-
function
|
|
15852
|
-
|
|
15853
|
-
|
|
15854
|
-
if (
|
|
15855
|
-
|
|
15856
|
-
return
|
|
15627
|
+
function extract2(value) {
|
|
15628
|
+
if (typeof value.r === "undefined")
|
|
15629
|
+
return void 0;
|
|
15630
|
+
if (typeof value.s === "undefined")
|
|
15631
|
+
return void 0;
|
|
15632
|
+
return from7(value);
|
|
15857
15633
|
}
|
|
15858
|
-
function
|
|
15859
|
-
const
|
|
15860
|
-
|
|
15861
|
-
|
|
15862
|
-
|
|
15863
|
-
|
|
15864
|
-
|
|
15865
|
-
|
|
15866
|
-
|
|
15867
|
-
|
|
15868
|
-
|
|
15869
|
-
|
|
15870
|
-
|
|
15871
|
-
|
|
15872
|
-
|
|
15873
|
-
|
|
15874
|
-
|
|
15875
|
-
|
|
15876
|
-
S++;
|
|
15877
|
-
}
|
|
15878
|
-
let Z = _2n5;
|
|
15879
|
-
const _Fp = Field2(P);
|
|
15880
|
-
while (FpLegendre2(_Fp, Z) === 1) {
|
|
15881
|
-
if (Z++ > 1e3)
|
|
15882
|
-
throw new Error("Cannot find square root: probably non-prime P");
|
|
15883
|
-
}
|
|
15884
|
-
if (S === 1)
|
|
15885
|
-
return sqrt3mod42;
|
|
15886
|
-
let cc = _Fp.pow(Z, Q);
|
|
15887
|
-
const Q1div2 = (Q + _1n8) / _2n5;
|
|
15888
|
-
return function tonelliSlow(Fp, n) {
|
|
15889
|
-
if (Fp.is0(n))
|
|
15890
|
-
return n;
|
|
15891
|
-
if (FpLegendre2(Fp, n) !== 1)
|
|
15892
|
-
throw new Error("Cannot find square root");
|
|
15893
|
-
let M = S;
|
|
15894
|
-
let c = Fp.mul(Fp.ONE, cc);
|
|
15895
|
-
let t = Fp.pow(n, Q);
|
|
15896
|
-
let R = Fp.pow(n, Q1div2);
|
|
15897
|
-
while (!Fp.eql(t, Fp.ONE)) {
|
|
15898
|
-
if (Fp.is0(t))
|
|
15899
|
-
return Fp.ZERO;
|
|
15900
|
-
let i = 1;
|
|
15901
|
-
let t_tmp = Fp.sqr(t);
|
|
15902
|
-
while (!Fp.eql(t_tmp, Fp.ONE)) {
|
|
15903
|
-
i++;
|
|
15904
|
-
t_tmp = Fp.sqr(t_tmp);
|
|
15905
|
-
if (i === M)
|
|
15906
|
-
throw new Error("Cannot find square root");
|
|
15907
|
-
}
|
|
15908
|
-
const exponent = _1n8 << BigInt(M - i - 1);
|
|
15909
|
-
const b = Fp.pow(c, exponent);
|
|
15910
|
-
M = i;
|
|
15911
|
-
c = Fp.sqr(b);
|
|
15912
|
-
t = Fp.mul(t, c);
|
|
15913
|
-
R = Fp.mul(R, b);
|
|
15914
|
-
}
|
|
15915
|
-
return R;
|
|
15916
|
-
};
|
|
15917
|
-
}
|
|
15918
|
-
function FpSqrt2(P) {
|
|
15919
|
-
if (P % _4n3 === _3n3)
|
|
15920
|
-
return sqrt3mod42;
|
|
15921
|
-
if (P % _8n2 === _5n2)
|
|
15922
|
-
return sqrt5mod82;
|
|
15923
|
-
return tonelliShanks2(P);
|
|
15924
|
-
}
|
|
15925
|
-
var FIELD_FIELDS2 = [
|
|
15926
|
-
"create",
|
|
15927
|
-
"isValid",
|
|
15928
|
-
"is0",
|
|
15929
|
-
"neg",
|
|
15930
|
-
"inv",
|
|
15931
|
-
"sqrt",
|
|
15932
|
-
"sqr",
|
|
15933
|
-
"eql",
|
|
15934
|
-
"add",
|
|
15935
|
-
"sub",
|
|
15936
|
-
"mul",
|
|
15937
|
-
"pow",
|
|
15938
|
-
"div",
|
|
15939
|
-
"addN",
|
|
15940
|
-
"subN",
|
|
15941
|
-
"mulN",
|
|
15942
|
-
"sqrN"
|
|
15943
|
-
];
|
|
15944
|
-
function validateField2(field) {
|
|
15945
|
-
const initial = {
|
|
15946
|
-
ORDER: "bigint",
|
|
15947
|
-
MASK: "bigint",
|
|
15948
|
-
BYTES: "isSafeInteger",
|
|
15949
|
-
BITS: "isSafeInteger"
|
|
15950
|
-
};
|
|
15951
|
-
const opts = FIELD_FIELDS2.reduce((map, val) => {
|
|
15952
|
-
map[val] = "function";
|
|
15953
|
-
return map;
|
|
15954
|
-
}, initial);
|
|
15955
|
-
return validateObject2(field, opts);
|
|
15956
|
-
}
|
|
15957
|
-
function FpPow2(Fp, num2, power) {
|
|
15958
|
-
if (power < _0n8)
|
|
15959
|
-
throw new Error("invalid exponent, negatives unsupported");
|
|
15960
|
-
if (power === _0n8)
|
|
15961
|
-
return Fp.ONE;
|
|
15962
|
-
if (power === _1n8)
|
|
15963
|
-
return num2;
|
|
15964
|
-
let p = Fp.ONE;
|
|
15965
|
-
let d = num2;
|
|
15966
|
-
while (power > _0n8) {
|
|
15967
|
-
if (power & _1n8)
|
|
15968
|
-
p = Fp.mul(p, d);
|
|
15969
|
-
d = Fp.sqr(d);
|
|
15970
|
-
power >>= _1n8;
|
|
15971
|
-
}
|
|
15972
|
-
return p;
|
|
15973
|
-
}
|
|
15974
|
-
function FpInvertBatch2(Fp, nums, passZero = false) {
|
|
15975
|
-
const inverted = new Array(nums.length).fill(passZero ? Fp.ZERO : void 0);
|
|
15976
|
-
const multipliedAcc = nums.reduce((acc, num2, i) => {
|
|
15977
|
-
if (Fp.is0(num2))
|
|
15978
|
-
return acc;
|
|
15979
|
-
inverted[i] = acc;
|
|
15980
|
-
return Fp.mul(acc, num2);
|
|
15981
|
-
}, Fp.ONE);
|
|
15982
|
-
const invertedAcc = Fp.inv(multipliedAcc);
|
|
15983
|
-
nums.reduceRight((acc, num2, i) => {
|
|
15984
|
-
if (Fp.is0(num2))
|
|
15985
|
-
return acc;
|
|
15986
|
-
inverted[i] = Fp.mul(acc, inverted[i]);
|
|
15987
|
-
return Fp.mul(acc, num2);
|
|
15988
|
-
}, invertedAcc);
|
|
15989
|
-
return inverted;
|
|
15990
|
-
}
|
|
15991
|
-
function FpLegendre2(Fp, n) {
|
|
15992
|
-
const p1mod2 = (Fp.ORDER - _1n8) / _2n5;
|
|
15993
|
-
const powered = Fp.pow(n, p1mod2);
|
|
15994
|
-
const yes = Fp.eql(powered, Fp.ONE);
|
|
15995
|
-
const zero = Fp.eql(powered, Fp.ZERO);
|
|
15996
|
-
const no = Fp.eql(powered, Fp.neg(Fp.ONE));
|
|
15997
|
-
if (!yes && !zero && !no)
|
|
15998
|
-
throw new Error("invalid Legendre symbol result");
|
|
15999
|
-
return yes ? 1 : zero ? 0 : -1;
|
|
16000
|
-
}
|
|
16001
|
-
function nLength2(n, nBitLength) {
|
|
16002
|
-
if (nBitLength !== void 0)
|
|
16003
|
-
anumber(nBitLength);
|
|
16004
|
-
const _nBitLength = nBitLength !== void 0 ? nBitLength : n.toString(2).length;
|
|
16005
|
-
const nByteLength = Math.ceil(_nBitLength / 8);
|
|
16006
|
-
return { nBitLength: _nBitLength, nByteLength };
|
|
16007
|
-
}
|
|
16008
|
-
function Field2(ORDER, bitLen3, isLE2 = false, redef = {}) {
|
|
16009
|
-
if (ORDER <= _0n8)
|
|
16010
|
-
throw new Error("invalid field: expected ORDER > 0, got " + ORDER);
|
|
16011
|
-
const { nBitLength: BITS, nByteLength: BYTES } = nLength2(ORDER, bitLen3);
|
|
16012
|
-
if (BYTES > 2048)
|
|
16013
|
-
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
16014
|
-
let sqrtP;
|
|
16015
|
-
const f = Object.freeze({
|
|
16016
|
-
ORDER,
|
|
16017
|
-
isLE: isLE2,
|
|
16018
|
-
BITS,
|
|
16019
|
-
BYTES,
|
|
16020
|
-
MASK: bitMask2(BITS),
|
|
16021
|
-
ZERO: _0n8,
|
|
16022
|
-
ONE: _1n8,
|
|
16023
|
-
create: (num2) => mod2(num2, ORDER),
|
|
16024
|
-
isValid: (num2) => {
|
|
16025
|
-
if (typeof num2 !== "bigint")
|
|
16026
|
-
throw new Error("invalid field element: expected bigint, got " + typeof num2);
|
|
16027
|
-
return _0n8 <= num2 && num2 < ORDER;
|
|
16028
|
-
},
|
|
16029
|
-
is0: (num2) => num2 === _0n8,
|
|
16030
|
-
isOdd: (num2) => (num2 & _1n8) === _1n8,
|
|
16031
|
-
neg: (num2) => mod2(-num2, ORDER),
|
|
16032
|
-
eql: (lhs, rhs) => lhs === rhs,
|
|
16033
|
-
sqr: (num2) => mod2(num2 * num2, ORDER),
|
|
16034
|
-
add: (lhs, rhs) => mod2(lhs + rhs, ORDER),
|
|
16035
|
-
sub: (lhs, rhs) => mod2(lhs - rhs, ORDER),
|
|
16036
|
-
mul: (lhs, rhs) => mod2(lhs * rhs, ORDER),
|
|
16037
|
-
pow: (num2, power) => FpPow2(f, num2, power),
|
|
16038
|
-
div: (lhs, rhs) => mod2(lhs * invert2(rhs, ORDER), ORDER),
|
|
16039
|
-
// Same as above, but doesn't normalize
|
|
16040
|
-
sqrN: (num2) => num2 * num2,
|
|
16041
|
-
addN: (lhs, rhs) => lhs + rhs,
|
|
16042
|
-
subN: (lhs, rhs) => lhs - rhs,
|
|
16043
|
-
mulN: (lhs, rhs) => lhs * rhs,
|
|
16044
|
-
inv: (num2) => invert2(num2, ORDER),
|
|
16045
|
-
sqrt: redef.sqrt || ((n) => {
|
|
16046
|
-
if (!sqrtP)
|
|
16047
|
-
sqrtP = FpSqrt2(ORDER);
|
|
16048
|
-
return sqrtP(f, n);
|
|
16049
|
-
}),
|
|
16050
|
-
toBytes: (num2) => isLE2 ? numberToBytesLE2(num2, BYTES) : numberToBytesBE2(num2, BYTES),
|
|
16051
|
-
fromBytes: (bytes) => {
|
|
16052
|
-
if (bytes.length !== BYTES)
|
|
16053
|
-
throw new Error("Field.fromBytes: expected " + BYTES + " bytes, got " + bytes.length);
|
|
16054
|
-
return isLE2 ? bytesToNumberLE2(bytes) : bytesToNumberBE2(bytes);
|
|
16055
|
-
},
|
|
16056
|
-
// TODO: we don't need it here, move out to separate fn
|
|
16057
|
-
invertBatch: (lst) => FpInvertBatch2(f, lst),
|
|
16058
|
-
// We can't move this out because Fp6, Fp12 implement it
|
|
16059
|
-
// and it's unclear what to return in there.
|
|
16060
|
-
cmov: (a, b, c) => c ? b : a
|
|
16061
|
-
});
|
|
16062
|
-
return Object.freeze(f);
|
|
16063
|
-
}
|
|
16064
|
-
function getFieldBytesLength2(fieldOrder) {
|
|
16065
|
-
if (typeof fieldOrder !== "bigint")
|
|
16066
|
-
throw new Error("field order must be bigint");
|
|
16067
|
-
const bitLength = fieldOrder.toString(2).length;
|
|
16068
|
-
return Math.ceil(bitLength / 8);
|
|
16069
|
-
}
|
|
16070
|
-
function getMinHashLength2(fieldOrder) {
|
|
16071
|
-
const length = getFieldBytesLength2(fieldOrder);
|
|
16072
|
-
return length + Math.ceil(length / 2);
|
|
16073
|
-
}
|
|
16074
|
-
function mapHashToField2(key, fieldOrder, isLE2 = false) {
|
|
16075
|
-
const len = key.length;
|
|
16076
|
-
const fieldLen = getFieldBytesLength2(fieldOrder);
|
|
16077
|
-
const minLen = getMinHashLength2(fieldOrder);
|
|
16078
|
-
if (len < 16 || len < minLen || len > 1024)
|
|
16079
|
-
throw new Error("expected " + minLen + "-1024 bytes of input, got " + len);
|
|
16080
|
-
const num2 = isLE2 ? bytesToNumberLE2(key) : bytesToNumberBE2(key);
|
|
16081
|
-
const reduced = mod2(num2, fieldOrder - _1n8) + _1n8;
|
|
16082
|
-
return isLE2 ? numberToBytesLE2(reduced, fieldLen) : numberToBytesBE2(reduced, fieldLen);
|
|
16083
|
-
}
|
|
16084
|
-
|
|
16085
|
-
// ../node_modules/ox/node_modules/@noble/curves/esm/abstract/curve.js
|
|
16086
|
-
init_utils5();
|
|
16087
|
-
var _0n9 = BigInt(0);
|
|
16088
|
-
var _1n9 = BigInt(1);
|
|
16089
|
-
function constTimeNegate2(condition, item) {
|
|
16090
|
-
const neg = item.negate();
|
|
16091
|
-
return condition ? neg : item;
|
|
16092
|
-
}
|
|
16093
|
-
function validateW2(W, bits) {
|
|
16094
|
-
if (!Number.isSafeInteger(W) || W <= 0 || W > bits)
|
|
16095
|
-
throw new Error("invalid window size, expected [1.." + bits + "], got W=" + W);
|
|
16096
|
-
}
|
|
16097
|
-
function calcWOpts2(W, scalarBits) {
|
|
16098
|
-
validateW2(W, scalarBits);
|
|
16099
|
-
const windows = Math.ceil(scalarBits / W) + 1;
|
|
16100
|
-
const windowSize = 2 ** (W - 1);
|
|
16101
|
-
const maxNumber = 2 ** W;
|
|
16102
|
-
const mask = bitMask2(W);
|
|
16103
|
-
const shiftBy = BigInt(W);
|
|
16104
|
-
return { windows, windowSize, mask, maxNumber, shiftBy };
|
|
16105
|
-
}
|
|
16106
|
-
function calcOffsets2(n, window2, wOpts) {
|
|
16107
|
-
const { windowSize, mask, maxNumber, shiftBy } = wOpts;
|
|
16108
|
-
let wbits = Number(n & mask);
|
|
16109
|
-
let nextN = n >> shiftBy;
|
|
16110
|
-
if (wbits > windowSize) {
|
|
16111
|
-
wbits -= maxNumber;
|
|
16112
|
-
nextN += _1n9;
|
|
16113
|
-
}
|
|
16114
|
-
const offsetStart = window2 * windowSize;
|
|
16115
|
-
const offset = offsetStart + Math.abs(wbits) - 1;
|
|
16116
|
-
const isZero = wbits === 0;
|
|
16117
|
-
const isNeg = wbits < 0;
|
|
16118
|
-
const isNegF = window2 % 2 !== 0;
|
|
16119
|
-
const offsetF = offsetStart;
|
|
16120
|
-
return { nextN, offset, isZero, isNeg, isNegF, offsetF };
|
|
16121
|
-
}
|
|
16122
|
-
function validateMSMPoints2(points, c) {
|
|
16123
|
-
if (!Array.isArray(points))
|
|
16124
|
-
throw new Error("array expected");
|
|
16125
|
-
points.forEach((p, i) => {
|
|
16126
|
-
if (!(p instanceof c))
|
|
16127
|
-
throw new Error("invalid point at index " + i);
|
|
16128
|
-
});
|
|
16129
|
-
}
|
|
16130
|
-
function validateMSMScalars2(scalars, field) {
|
|
16131
|
-
if (!Array.isArray(scalars))
|
|
16132
|
-
throw new Error("array of scalars expected");
|
|
16133
|
-
scalars.forEach((s, i) => {
|
|
16134
|
-
if (!field.isValid(s))
|
|
16135
|
-
throw new Error("invalid scalar at index " + i);
|
|
16136
|
-
});
|
|
16137
|
-
}
|
|
16138
|
-
var pointPrecomputes2 = /* @__PURE__ */ new WeakMap();
|
|
16139
|
-
var pointWindowSizes2 = /* @__PURE__ */ new WeakMap();
|
|
16140
|
-
function getW2(P) {
|
|
16141
|
-
return pointWindowSizes2.get(P) || 1;
|
|
16142
|
-
}
|
|
16143
|
-
function wNAF2(c, bits) {
|
|
16144
|
-
return {
|
|
16145
|
-
constTimeNegate: constTimeNegate2,
|
|
16146
|
-
hasPrecomputes(elm) {
|
|
16147
|
-
return getW2(elm) !== 1;
|
|
16148
|
-
},
|
|
16149
|
-
// non-const time multiplication ladder
|
|
16150
|
-
unsafeLadder(elm, n, p = c.ZERO) {
|
|
16151
|
-
let d = elm;
|
|
16152
|
-
while (n > _0n9) {
|
|
16153
|
-
if (n & _1n9)
|
|
16154
|
-
p = p.add(d);
|
|
16155
|
-
d = d.double();
|
|
16156
|
-
n >>= _1n9;
|
|
16157
|
-
}
|
|
16158
|
-
return p;
|
|
16159
|
-
},
|
|
16160
|
-
/**
|
|
16161
|
-
* Creates a wNAF precomputation window. Used for caching.
|
|
16162
|
-
* Default window size is set by `utils.precompute()` and is equal to 8.
|
|
16163
|
-
* Number of precomputed points depends on the curve size:
|
|
16164
|
-
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
|
16165
|
-
* - 𝑊 is the window size
|
|
16166
|
-
* - 𝑛 is the bitlength of the curve order.
|
|
16167
|
-
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
16168
|
-
* @param elm Point instance
|
|
16169
|
-
* @param W window size
|
|
16170
|
-
* @returns precomputed point tables flattened to a single array
|
|
16171
|
-
*/
|
|
16172
|
-
precomputeWindow(elm, W) {
|
|
16173
|
-
const { windows, windowSize } = calcWOpts2(W, bits);
|
|
16174
|
-
const points = [];
|
|
16175
|
-
let p = elm;
|
|
16176
|
-
let base = p;
|
|
16177
|
-
for (let window2 = 0; window2 < windows; window2++) {
|
|
16178
|
-
base = p;
|
|
16179
|
-
points.push(base);
|
|
16180
|
-
for (let i = 1; i < windowSize; i++) {
|
|
16181
|
-
base = base.add(p);
|
|
16182
|
-
points.push(base);
|
|
16183
|
-
}
|
|
16184
|
-
p = base.double();
|
|
16185
|
-
}
|
|
16186
|
-
return points;
|
|
16187
|
-
},
|
|
16188
|
-
/**
|
|
16189
|
-
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
16190
|
-
* @param W window size
|
|
16191
|
-
* @param precomputes precomputed tables
|
|
16192
|
-
* @param n scalar (we don't check here, but should be less than curve order)
|
|
16193
|
-
* @returns real and fake (for const-time) points
|
|
16194
|
-
*/
|
|
16195
|
-
wNAF(W, precomputes, n) {
|
|
16196
|
-
let p = c.ZERO;
|
|
16197
|
-
let f = c.BASE;
|
|
16198
|
-
const wo = calcWOpts2(W, bits);
|
|
16199
|
-
for (let window2 = 0; window2 < wo.windows; window2++) {
|
|
16200
|
-
const { nextN, offset, isZero, isNeg, isNegF, offsetF } = calcOffsets2(n, window2, wo);
|
|
16201
|
-
n = nextN;
|
|
16202
|
-
if (isZero) {
|
|
16203
|
-
f = f.add(constTimeNegate2(isNegF, precomputes[offsetF]));
|
|
16204
|
-
} else {
|
|
16205
|
-
p = p.add(constTimeNegate2(isNeg, precomputes[offset]));
|
|
16206
|
-
}
|
|
16207
|
-
}
|
|
16208
|
-
return { p, f };
|
|
16209
|
-
},
|
|
16210
|
-
/**
|
|
16211
|
-
* Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
|
|
16212
|
-
* @param W window size
|
|
16213
|
-
* @param precomputes precomputed tables
|
|
16214
|
-
* @param n scalar (we don't check here, but should be less than curve order)
|
|
16215
|
-
* @param acc accumulator point to add result of multiplication
|
|
16216
|
-
* @returns point
|
|
16217
|
-
*/
|
|
16218
|
-
wNAFUnsafe(W, precomputes, n, acc = c.ZERO) {
|
|
16219
|
-
const wo = calcWOpts2(W, bits);
|
|
16220
|
-
for (let window2 = 0; window2 < wo.windows; window2++) {
|
|
16221
|
-
if (n === _0n9)
|
|
16222
|
-
break;
|
|
16223
|
-
const { nextN, offset, isZero, isNeg } = calcOffsets2(n, window2, wo);
|
|
16224
|
-
n = nextN;
|
|
16225
|
-
if (isZero) {
|
|
16226
|
-
continue;
|
|
16227
|
-
} else {
|
|
16228
|
-
const item = precomputes[offset];
|
|
16229
|
-
acc = acc.add(isNeg ? item.negate() : item);
|
|
16230
|
-
}
|
|
16231
|
-
}
|
|
16232
|
-
return acc;
|
|
16233
|
-
},
|
|
16234
|
-
getPrecomputes(W, P, transform) {
|
|
16235
|
-
let comp = pointPrecomputes2.get(P);
|
|
16236
|
-
if (!comp) {
|
|
16237
|
-
comp = this.precomputeWindow(P, W);
|
|
16238
|
-
if (W !== 1)
|
|
16239
|
-
pointPrecomputes2.set(P, transform(comp));
|
|
16240
|
-
}
|
|
16241
|
-
return comp;
|
|
16242
|
-
},
|
|
16243
|
-
wNAFCached(P, n, transform) {
|
|
16244
|
-
const W = getW2(P);
|
|
16245
|
-
return this.wNAF(W, this.getPrecomputes(W, P, transform), n);
|
|
16246
|
-
},
|
|
16247
|
-
wNAFCachedUnsafe(P, n, transform, prev) {
|
|
16248
|
-
const W = getW2(P);
|
|
16249
|
-
if (W === 1)
|
|
16250
|
-
return this.unsafeLadder(P, n, prev);
|
|
16251
|
-
return this.wNAFUnsafe(W, this.getPrecomputes(W, P, transform), n, prev);
|
|
16252
|
-
},
|
|
16253
|
-
// We calculate precomputes for elliptic curve point multiplication
|
|
16254
|
-
// using windowed method. This specifies window size and
|
|
16255
|
-
// stores precomputed values. Usually only base point would be precomputed.
|
|
16256
|
-
setWindowSize(P, W) {
|
|
16257
|
-
validateW2(W, bits);
|
|
16258
|
-
pointWindowSizes2.set(P, W);
|
|
16259
|
-
pointPrecomputes2.delete(P);
|
|
16260
|
-
}
|
|
16261
|
-
};
|
|
16262
|
-
}
|
|
16263
|
-
function pippenger2(c, fieldN, points, scalars) {
|
|
16264
|
-
validateMSMPoints2(points, c);
|
|
16265
|
-
validateMSMScalars2(scalars, fieldN);
|
|
16266
|
-
const plength = points.length;
|
|
16267
|
-
const slength = scalars.length;
|
|
16268
|
-
if (plength !== slength)
|
|
16269
|
-
throw new Error("arrays of points and scalars must have equal length");
|
|
16270
|
-
const zero = c.ZERO;
|
|
16271
|
-
const wbits = bitLen2(BigInt(plength));
|
|
16272
|
-
let windowSize = 1;
|
|
16273
|
-
if (wbits > 12)
|
|
16274
|
-
windowSize = wbits - 3;
|
|
16275
|
-
else if (wbits > 4)
|
|
16276
|
-
windowSize = wbits - 2;
|
|
16277
|
-
else if (wbits > 0)
|
|
16278
|
-
windowSize = 2;
|
|
16279
|
-
const MASK = bitMask2(windowSize);
|
|
16280
|
-
const buckets = new Array(Number(MASK) + 1).fill(zero);
|
|
16281
|
-
const lastBits = Math.floor((fieldN.BITS - 1) / windowSize) * windowSize;
|
|
16282
|
-
let sum = zero;
|
|
16283
|
-
for (let i = lastBits; i >= 0; i -= windowSize) {
|
|
16284
|
-
buckets.fill(zero);
|
|
16285
|
-
for (let j = 0; j < slength; j++) {
|
|
16286
|
-
const scalar = scalars[j];
|
|
16287
|
-
const wbits2 = Number(scalar >> BigInt(i) & MASK);
|
|
16288
|
-
buckets[wbits2] = buckets[wbits2].add(points[j]);
|
|
16289
|
-
}
|
|
16290
|
-
let resI = zero;
|
|
16291
|
-
for (let j = buckets.length - 1, sumI = zero; j > 0; j--) {
|
|
16292
|
-
sumI = sumI.add(buckets[j]);
|
|
16293
|
-
resI = resI.add(sumI);
|
|
16294
|
-
}
|
|
16295
|
-
sum = sum.add(resI);
|
|
16296
|
-
if (i !== 0)
|
|
16297
|
-
for (let j = 0; j < windowSize; j++)
|
|
16298
|
-
sum = sum.double();
|
|
16299
|
-
}
|
|
16300
|
-
return sum;
|
|
16301
|
-
}
|
|
16302
|
-
function validateBasic2(curve) {
|
|
16303
|
-
validateField2(curve.Fp);
|
|
16304
|
-
validateObject2(curve, {
|
|
16305
|
-
n: "bigint",
|
|
16306
|
-
h: "bigint",
|
|
16307
|
-
Gx: "field",
|
|
16308
|
-
Gy: "field"
|
|
16309
|
-
}, {
|
|
16310
|
-
nBitLength: "isSafeInteger",
|
|
16311
|
-
nByteLength: "isSafeInteger"
|
|
16312
|
-
});
|
|
16313
|
-
return Object.freeze({
|
|
16314
|
-
...nLength2(curve.n, curve.nBitLength),
|
|
16315
|
-
...curve,
|
|
16316
|
-
...{ p: curve.Fp.ORDER }
|
|
16317
|
-
});
|
|
16318
|
-
}
|
|
16319
|
-
|
|
16320
|
-
// ../node_modules/ox/node_modules/@noble/curves/esm/abstract/weierstrass.js
|
|
16321
|
-
init_utils5();
|
|
16322
|
-
function validateSigVerOpts2(opts) {
|
|
16323
|
-
if (opts.lowS !== void 0)
|
|
16324
|
-
abool2("lowS", opts.lowS);
|
|
16325
|
-
if (opts.prehash !== void 0)
|
|
16326
|
-
abool2("prehash", opts.prehash);
|
|
16327
|
-
}
|
|
16328
|
-
function validatePointOpts2(curve) {
|
|
16329
|
-
const opts = validateBasic2(curve);
|
|
16330
|
-
validateObject2(opts, {
|
|
16331
|
-
a: "field",
|
|
16332
|
-
b: "field"
|
|
16333
|
-
}, {
|
|
16334
|
-
allowInfinityPoint: "boolean",
|
|
16335
|
-
allowedPrivateKeyLengths: "array",
|
|
16336
|
-
clearCofactor: "function",
|
|
16337
|
-
fromBytes: "function",
|
|
16338
|
-
isTorsionFree: "function",
|
|
16339
|
-
toBytes: "function",
|
|
16340
|
-
wrapPrivateKey: "boolean"
|
|
16341
|
-
});
|
|
16342
|
-
const { endo, Fp, a } = opts;
|
|
16343
|
-
if (endo) {
|
|
16344
|
-
if (!Fp.eql(a, Fp.ZERO)) {
|
|
16345
|
-
throw new Error("invalid endo: CURVE.a must be 0");
|
|
16346
|
-
}
|
|
16347
|
-
if (typeof endo !== "object" || typeof endo.beta !== "bigint" || typeof endo.splitScalar !== "function") {
|
|
16348
|
-
throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');
|
|
16349
|
-
}
|
|
16350
|
-
}
|
|
16351
|
-
return Object.freeze({ ...opts });
|
|
16352
|
-
}
|
|
16353
|
-
var DERErr2 = class extends Error {
|
|
16354
|
-
constructor(m = "") {
|
|
16355
|
-
super(m);
|
|
16356
|
-
}
|
|
16357
|
-
};
|
|
16358
|
-
var DER2 = {
|
|
16359
|
-
// asn.1 DER encoding utils
|
|
16360
|
-
Err: DERErr2,
|
|
16361
|
-
// Basic building block is TLV (Tag-Length-Value)
|
|
16362
|
-
_tlv: {
|
|
16363
|
-
encode: (tag, data) => {
|
|
16364
|
-
const { Err: E } = DER2;
|
|
16365
|
-
if (tag < 0 || tag > 256)
|
|
16366
|
-
throw new E("tlv.encode: wrong tag");
|
|
16367
|
-
if (data.length & 1)
|
|
16368
|
-
throw new E("tlv.encode: unpadded data");
|
|
16369
|
-
const dataLen = data.length / 2;
|
|
16370
|
-
const len = numberToHexUnpadded2(dataLen);
|
|
16371
|
-
if (len.length / 2 & 128)
|
|
16372
|
-
throw new E("tlv.encode: long form length too big");
|
|
16373
|
-
const lenLen = dataLen > 127 ? numberToHexUnpadded2(len.length / 2 | 128) : "";
|
|
16374
|
-
const t = numberToHexUnpadded2(tag);
|
|
16375
|
-
return t + lenLen + len + data;
|
|
16376
|
-
},
|
|
16377
|
-
// v - value, l - left bytes (unparsed)
|
|
16378
|
-
decode(tag, data) {
|
|
16379
|
-
const { Err: E } = DER2;
|
|
16380
|
-
let pos = 0;
|
|
16381
|
-
if (tag < 0 || tag > 256)
|
|
16382
|
-
throw new E("tlv.encode: wrong tag");
|
|
16383
|
-
if (data.length < 2 || data[pos++] !== tag)
|
|
16384
|
-
throw new E("tlv.decode: wrong tlv");
|
|
16385
|
-
const first = data[pos++];
|
|
16386
|
-
const isLong = !!(first & 128);
|
|
16387
|
-
let length = 0;
|
|
16388
|
-
if (!isLong)
|
|
16389
|
-
length = first;
|
|
16390
|
-
else {
|
|
16391
|
-
const lenLen = first & 127;
|
|
16392
|
-
if (!lenLen)
|
|
16393
|
-
throw new E("tlv.decode(long): indefinite length not supported");
|
|
16394
|
-
if (lenLen > 4)
|
|
16395
|
-
throw new E("tlv.decode(long): byte length is too big");
|
|
16396
|
-
const lengthBytes = data.subarray(pos, pos + lenLen);
|
|
16397
|
-
if (lengthBytes.length !== lenLen)
|
|
16398
|
-
throw new E("tlv.decode: length bytes not complete");
|
|
16399
|
-
if (lengthBytes[0] === 0)
|
|
16400
|
-
throw new E("tlv.decode(long): zero leftmost byte");
|
|
16401
|
-
for (const b of lengthBytes)
|
|
16402
|
-
length = length << 8 | b;
|
|
16403
|
-
pos += lenLen;
|
|
16404
|
-
if (length < 128)
|
|
16405
|
-
throw new E("tlv.decode(long): not minimal encoding");
|
|
16406
|
-
}
|
|
16407
|
-
const v = data.subarray(pos, pos + length);
|
|
16408
|
-
if (v.length !== length)
|
|
16409
|
-
throw new E("tlv.decode: wrong value length");
|
|
16410
|
-
return { v, l: data.subarray(pos + length) };
|
|
16411
|
-
}
|
|
16412
|
-
},
|
|
16413
|
-
// https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
|
|
16414
|
-
// since we always use positive integers here. It must always be empty:
|
|
16415
|
-
// - add zero byte if exists
|
|
16416
|
-
// - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
|
|
16417
|
-
_int: {
|
|
16418
|
-
encode(num2) {
|
|
16419
|
-
const { Err: E } = DER2;
|
|
16420
|
-
if (num2 < _0n10)
|
|
16421
|
-
throw new E("integer: negative integers are not allowed");
|
|
16422
|
-
let hex = numberToHexUnpadded2(num2);
|
|
16423
|
-
if (Number.parseInt(hex[0], 16) & 8)
|
|
16424
|
-
hex = "00" + hex;
|
|
16425
|
-
if (hex.length & 1)
|
|
16426
|
-
throw new E("unexpected DER parsing assertion: unpadded hex");
|
|
16427
|
-
return hex;
|
|
16428
|
-
},
|
|
16429
|
-
decode(data) {
|
|
16430
|
-
const { Err: E } = DER2;
|
|
16431
|
-
if (data[0] & 128)
|
|
16432
|
-
throw new E("invalid signature integer: negative");
|
|
16433
|
-
if (data[0] === 0 && !(data[1] & 128))
|
|
16434
|
-
throw new E("invalid signature integer: unnecessary leading zero");
|
|
16435
|
-
return bytesToNumberBE2(data);
|
|
16436
|
-
}
|
|
16437
|
-
},
|
|
16438
|
-
toSig(hex) {
|
|
16439
|
-
const { Err: E, _int: int, _tlv: tlv } = DER2;
|
|
16440
|
-
const data = ensureBytes2("signature", hex);
|
|
16441
|
-
const { v: seqBytes, l: seqLeftBytes } = tlv.decode(48, data);
|
|
16442
|
-
if (seqLeftBytes.length)
|
|
16443
|
-
throw new E("invalid signature: left bytes after parsing");
|
|
16444
|
-
const { v: rBytes, l: rLeftBytes } = tlv.decode(2, seqBytes);
|
|
16445
|
-
const { v: sBytes, l: sLeftBytes } = tlv.decode(2, rLeftBytes);
|
|
16446
|
-
if (sLeftBytes.length)
|
|
16447
|
-
throw new E("invalid signature: left bytes after parsing");
|
|
16448
|
-
return { r: int.decode(rBytes), s: int.decode(sBytes) };
|
|
16449
|
-
},
|
|
16450
|
-
hexFromSig(sig) {
|
|
16451
|
-
const { _tlv: tlv, _int: int } = DER2;
|
|
16452
|
-
const rs = tlv.encode(2, int.encode(sig.r));
|
|
16453
|
-
const ss = tlv.encode(2, int.encode(sig.s));
|
|
16454
|
-
const seq = rs + ss;
|
|
16455
|
-
return tlv.encode(48, seq);
|
|
16456
|
-
}
|
|
16457
|
-
};
|
|
16458
|
-
function numToSizedHex2(num2, size5) {
|
|
16459
|
-
return bytesToHex3(numberToBytesBE2(num2, size5));
|
|
16460
|
-
}
|
|
16461
|
-
var _0n10 = BigInt(0);
|
|
16462
|
-
var _1n10 = BigInt(1);
|
|
16463
|
-
BigInt(2);
|
|
16464
|
-
var _3n4 = BigInt(3);
|
|
16465
|
-
var _4n4 = BigInt(4);
|
|
16466
|
-
function weierstrassPoints2(opts) {
|
|
16467
|
-
const CURVE = validatePointOpts2(opts);
|
|
16468
|
-
const { Fp } = CURVE;
|
|
16469
|
-
const Fn = Field2(CURVE.n, CURVE.nBitLength);
|
|
16470
|
-
const toBytes4 = CURVE.toBytes || ((_c, point, _isCompressed) => {
|
|
16471
|
-
const a = point.toAffine();
|
|
16472
|
-
return concatBytes4(Uint8Array.from([4]), Fp.toBytes(a.x), Fp.toBytes(a.y));
|
|
16473
|
-
});
|
|
16474
|
-
const fromBytes4 = CURVE.fromBytes || ((bytes) => {
|
|
16475
|
-
const tail = bytes.subarray(1);
|
|
16476
|
-
const x = Fp.fromBytes(tail.subarray(0, Fp.BYTES));
|
|
16477
|
-
const y = Fp.fromBytes(tail.subarray(Fp.BYTES, 2 * Fp.BYTES));
|
|
16478
|
-
return { x, y };
|
|
16479
|
-
});
|
|
16480
|
-
function weierstrassEquation(x) {
|
|
16481
|
-
const { a, b } = CURVE;
|
|
16482
|
-
const x2 = Fp.sqr(x);
|
|
16483
|
-
const x3 = Fp.mul(x2, x);
|
|
16484
|
-
return Fp.add(Fp.add(x3, Fp.mul(x, a)), b);
|
|
16485
|
-
}
|
|
16486
|
-
function isValidXY(x, y) {
|
|
16487
|
-
const left = Fp.sqr(y);
|
|
16488
|
-
const right = weierstrassEquation(x);
|
|
16489
|
-
return Fp.eql(left, right);
|
|
16490
|
-
}
|
|
16491
|
-
if (!isValidXY(CURVE.Gx, CURVE.Gy))
|
|
16492
|
-
throw new Error("bad curve params: generator point");
|
|
16493
|
-
const _4a3 = Fp.mul(Fp.pow(CURVE.a, _3n4), _4n4);
|
|
16494
|
-
const _27b2 = Fp.mul(Fp.sqr(CURVE.b), BigInt(27));
|
|
16495
|
-
if (Fp.is0(Fp.add(_4a3, _27b2)))
|
|
16496
|
-
throw new Error("bad curve params: a or b");
|
|
16497
|
-
function isWithinCurveOrder(num2) {
|
|
16498
|
-
return inRange2(num2, _1n10, CURVE.n);
|
|
16499
|
-
}
|
|
16500
|
-
function normPrivateKeyToScalar(key) {
|
|
16501
|
-
const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n: N } = CURVE;
|
|
16502
|
-
if (lengths && typeof key !== "bigint") {
|
|
16503
|
-
if (isBytes3(key))
|
|
16504
|
-
key = bytesToHex3(key);
|
|
16505
|
-
if (typeof key !== "string" || !lengths.includes(key.length))
|
|
16506
|
-
throw new Error("invalid private key");
|
|
16507
|
-
key = key.padStart(nByteLength * 2, "0");
|
|
16508
|
-
}
|
|
16509
|
-
let num2;
|
|
16510
|
-
try {
|
|
16511
|
-
num2 = typeof key === "bigint" ? key : bytesToNumberBE2(ensureBytes2("private key", key, nByteLength));
|
|
16512
|
-
} catch (error) {
|
|
16513
|
-
throw new Error("invalid private key, expected hex or " + nByteLength + " bytes, got " + typeof key);
|
|
16514
|
-
}
|
|
16515
|
-
if (wrapPrivateKey)
|
|
16516
|
-
num2 = mod2(num2, N);
|
|
16517
|
-
aInRange2("private key", num2, _1n10, N);
|
|
16518
|
-
return num2;
|
|
16519
|
-
}
|
|
16520
|
-
function aprjpoint(other) {
|
|
16521
|
-
if (!(other instanceof Point2))
|
|
16522
|
-
throw new Error("ProjectivePoint expected");
|
|
16523
|
-
}
|
|
16524
|
-
const toAffineMemo = memoized2((p, iz) => {
|
|
16525
|
-
const { px: x, py: y, pz: z } = p;
|
|
16526
|
-
if (Fp.eql(z, Fp.ONE))
|
|
16527
|
-
return { x, y };
|
|
16528
|
-
const is0 = p.is0();
|
|
16529
|
-
if (iz == null)
|
|
16530
|
-
iz = is0 ? Fp.ONE : Fp.inv(z);
|
|
16531
|
-
const ax = Fp.mul(x, iz);
|
|
16532
|
-
const ay = Fp.mul(y, iz);
|
|
16533
|
-
const zz = Fp.mul(z, iz);
|
|
16534
|
-
if (is0)
|
|
16535
|
-
return { x: Fp.ZERO, y: Fp.ZERO };
|
|
16536
|
-
if (!Fp.eql(zz, Fp.ONE))
|
|
16537
|
-
throw new Error("invZ was invalid");
|
|
16538
|
-
return { x: ax, y: ay };
|
|
16539
|
-
});
|
|
16540
|
-
const assertValidMemo = memoized2((p) => {
|
|
16541
|
-
if (p.is0()) {
|
|
16542
|
-
if (CURVE.allowInfinityPoint && !Fp.is0(p.py))
|
|
16543
|
-
return;
|
|
16544
|
-
throw new Error("bad point: ZERO");
|
|
16545
|
-
}
|
|
16546
|
-
const { x, y } = p.toAffine();
|
|
16547
|
-
if (!Fp.isValid(x) || !Fp.isValid(y))
|
|
16548
|
-
throw new Error("bad point: x or y not FE");
|
|
16549
|
-
if (!isValidXY(x, y))
|
|
16550
|
-
throw new Error("bad point: equation left != right");
|
|
16551
|
-
if (!p.isTorsionFree())
|
|
16552
|
-
throw new Error("bad point: not in prime-order subgroup");
|
|
16553
|
-
return true;
|
|
16554
|
-
});
|
|
16555
|
-
class Point2 {
|
|
16556
|
-
constructor(px, py, pz) {
|
|
16557
|
-
if (px == null || !Fp.isValid(px))
|
|
16558
|
-
throw new Error("x required");
|
|
16559
|
-
if (py == null || !Fp.isValid(py) || Fp.is0(py))
|
|
16560
|
-
throw new Error("y required");
|
|
16561
|
-
if (pz == null || !Fp.isValid(pz))
|
|
16562
|
-
throw new Error("z required");
|
|
16563
|
-
this.px = px;
|
|
16564
|
-
this.py = py;
|
|
16565
|
-
this.pz = pz;
|
|
16566
|
-
Object.freeze(this);
|
|
16567
|
-
}
|
|
16568
|
-
// Does not validate if the point is on-curve.
|
|
16569
|
-
// Use fromHex instead, or call assertValidity() later.
|
|
16570
|
-
static fromAffine(p) {
|
|
16571
|
-
const { x, y } = p || {};
|
|
16572
|
-
if (!p || !Fp.isValid(x) || !Fp.isValid(y))
|
|
16573
|
-
throw new Error("invalid affine point");
|
|
16574
|
-
if (p instanceof Point2)
|
|
16575
|
-
throw new Error("projective point not allowed");
|
|
16576
|
-
const is0 = (i) => Fp.eql(i, Fp.ZERO);
|
|
16577
|
-
if (is0(x) && is0(y))
|
|
16578
|
-
return Point2.ZERO;
|
|
16579
|
-
return new Point2(x, y, Fp.ONE);
|
|
16580
|
-
}
|
|
16581
|
-
get x() {
|
|
16582
|
-
return this.toAffine().x;
|
|
16583
|
-
}
|
|
16584
|
-
get y() {
|
|
16585
|
-
return this.toAffine().y;
|
|
16586
|
-
}
|
|
16587
|
-
/**
|
|
16588
|
-
* Takes a bunch of Projective Points but executes only one
|
|
16589
|
-
* inversion on all of them. Inversion is very slow operation,
|
|
16590
|
-
* so this improves performance massively.
|
|
16591
|
-
* Optimization: converts a list of projective points to a list of identical points with Z=1.
|
|
16592
|
-
*/
|
|
16593
|
-
static normalizeZ(points) {
|
|
16594
|
-
const toInv = FpInvertBatch2(Fp, points.map((p) => p.pz));
|
|
16595
|
-
return points.map((p, i) => p.toAffine(toInv[i])).map(Point2.fromAffine);
|
|
16596
|
-
}
|
|
16597
|
-
/**
|
|
16598
|
-
* Converts hash string or Uint8Array to Point.
|
|
16599
|
-
* @param hex short/long ECDSA hex
|
|
16600
|
-
*/
|
|
16601
|
-
static fromHex(hex) {
|
|
16602
|
-
const P = Point2.fromAffine(fromBytes4(ensureBytes2("pointHex", hex)));
|
|
16603
|
-
P.assertValidity();
|
|
16604
|
-
return P;
|
|
16605
|
-
}
|
|
16606
|
-
// Multiplies generator point by privateKey.
|
|
16607
|
-
static fromPrivateKey(privateKey) {
|
|
16608
|
-
return Point2.BASE.multiply(normPrivateKeyToScalar(privateKey));
|
|
16609
|
-
}
|
|
16610
|
-
// Multiscalar Multiplication
|
|
16611
|
-
static msm(points, scalars) {
|
|
16612
|
-
return pippenger2(Point2, Fn, points, scalars);
|
|
16613
|
-
}
|
|
16614
|
-
// "Private method", don't use it directly
|
|
16615
|
-
_setWindowSize(windowSize) {
|
|
16616
|
-
wnaf.setWindowSize(this, windowSize);
|
|
16617
|
-
}
|
|
16618
|
-
// A point on curve is valid if it conforms to equation.
|
|
16619
|
-
assertValidity() {
|
|
16620
|
-
assertValidMemo(this);
|
|
16621
|
-
}
|
|
16622
|
-
hasEvenY() {
|
|
16623
|
-
const { y } = this.toAffine();
|
|
16624
|
-
if (Fp.isOdd)
|
|
16625
|
-
return !Fp.isOdd(y);
|
|
16626
|
-
throw new Error("Field doesn't support isOdd");
|
|
16627
|
-
}
|
|
16628
|
-
/**
|
|
16629
|
-
* Compare one point to another.
|
|
16630
|
-
*/
|
|
16631
|
-
equals(other) {
|
|
16632
|
-
aprjpoint(other);
|
|
16633
|
-
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
16634
|
-
const { px: X2, py: Y2, pz: Z2 } = other;
|
|
16635
|
-
const U1 = Fp.eql(Fp.mul(X1, Z2), Fp.mul(X2, Z1));
|
|
16636
|
-
const U2 = Fp.eql(Fp.mul(Y1, Z2), Fp.mul(Y2, Z1));
|
|
16637
|
-
return U1 && U2;
|
|
16638
|
-
}
|
|
16639
|
-
/**
|
|
16640
|
-
* Flips point to one corresponding to (x, -y) in Affine coordinates.
|
|
16641
|
-
*/
|
|
16642
|
-
negate() {
|
|
16643
|
-
return new Point2(this.px, Fp.neg(this.py), this.pz);
|
|
16644
|
-
}
|
|
16645
|
-
// Renes-Costello-Batina exception-free doubling formula.
|
|
16646
|
-
// There is 30% faster Jacobian formula, but it is not complete.
|
|
16647
|
-
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
16648
|
-
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
16649
|
-
double() {
|
|
16650
|
-
const { a, b } = CURVE;
|
|
16651
|
-
const b3 = Fp.mul(b, _3n4);
|
|
16652
|
-
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
16653
|
-
let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO;
|
|
16654
|
-
let t0 = Fp.mul(X1, X1);
|
|
16655
|
-
let t1 = Fp.mul(Y1, Y1);
|
|
16656
|
-
let t2 = Fp.mul(Z1, Z1);
|
|
16657
|
-
let t3 = Fp.mul(X1, Y1);
|
|
16658
|
-
t3 = Fp.add(t3, t3);
|
|
16659
|
-
Z3 = Fp.mul(X1, Z1);
|
|
16660
|
-
Z3 = Fp.add(Z3, Z3);
|
|
16661
|
-
X3 = Fp.mul(a, Z3);
|
|
16662
|
-
Y3 = Fp.mul(b3, t2);
|
|
16663
|
-
Y3 = Fp.add(X3, Y3);
|
|
16664
|
-
X3 = Fp.sub(t1, Y3);
|
|
16665
|
-
Y3 = Fp.add(t1, Y3);
|
|
16666
|
-
Y3 = Fp.mul(X3, Y3);
|
|
16667
|
-
X3 = Fp.mul(t3, X3);
|
|
16668
|
-
Z3 = Fp.mul(b3, Z3);
|
|
16669
|
-
t2 = Fp.mul(a, t2);
|
|
16670
|
-
t3 = Fp.sub(t0, t2);
|
|
16671
|
-
t3 = Fp.mul(a, t3);
|
|
16672
|
-
t3 = Fp.add(t3, Z3);
|
|
16673
|
-
Z3 = Fp.add(t0, t0);
|
|
16674
|
-
t0 = Fp.add(Z3, t0);
|
|
16675
|
-
t0 = Fp.add(t0, t2);
|
|
16676
|
-
t0 = Fp.mul(t0, t3);
|
|
16677
|
-
Y3 = Fp.add(Y3, t0);
|
|
16678
|
-
t2 = Fp.mul(Y1, Z1);
|
|
16679
|
-
t2 = Fp.add(t2, t2);
|
|
16680
|
-
t0 = Fp.mul(t2, t3);
|
|
16681
|
-
X3 = Fp.sub(X3, t0);
|
|
16682
|
-
Z3 = Fp.mul(t2, t1);
|
|
16683
|
-
Z3 = Fp.add(Z3, Z3);
|
|
16684
|
-
Z3 = Fp.add(Z3, Z3);
|
|
16685
|
-
return new Point2(X3, Y3, Z3);
|
|
16686
|
-
}
|
|
16687
|
-
// Renes-Costello-Batina exception-free addition formula.
|
|
16688
|
-
// There is 30% faster Jacobian formula, but it is not complete.
|
|
16689
|
-
// https://eprint.iacr.org/2015/1060, algorithm 1
|
|
16690
|
-
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
16691
|
-
add(other) {
|
|
16692
|
-
aprjpoint(other);
|
|
16693
|
-
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
16694
|
-
const { px: X2, py: Y2, pz: Z2 } = other;
|
|
16695
|
-
let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO;
|
|
16696
|
-
const a = CURVE.a;
|
|
16697
|
-
const b3 = Fp.mul(CURVE.b, _3n4);
|
|
16698
|
-
let t0 = Fp.mul(X1, X2);
|
|
16699
|
-
let t1 = Fp.mul(Y1, Y2);
|
|
16700
|
-
let t2 = Fp.mul(Z1, Z2);
|
|
16701
|
-
let t3 = Fp.add(X1, Y1);
|
|
16702
|
-
let t4 = Fp.add(X2, Y2);
|
|
16703
|
-
t3 = Fp.mul(t3, t4);
|
|
16704
|
-
t4 = Fp.add(t0, t1);
|
|
16705
|
-
t3 = Fp.sub(t3, t4);
|
|
16706
|
-
t4 = Fp.add(X1, Z1);
|
|
16707
|
-
let t5 = Fp.add(X2, Z2);
|
|
16708
|
-
t4 = Fp.mul(t4, t5);
|
|
16709
|
-
t5 = Fp.add(t0, t2);
|
|
16710
|
-
t4 = Fp.sub(t4, t5);
|
|
16711
|
-
t5 = Fp.add(Y1, Z1);
|
|
16712
|
-
X3 = Fp.add(Y2, Z2);
|
|
16713
|
-
t5 = Fp.mul(t5, X3);
|
|
16714
|
-
X3 = Fp.add(t1, t2);
|
|
16715
|
-
t5 = Fp.sub(t5, X3);
|
|
16716
|
-
Z3 = Fp.mul(a, t4);
|
|
16717
|
-
X3 = Fp.mul(b3, t2);
|
|
16718
|
-
Z3 = Fp.add(X3, Z3);
|
|
16719
|
-
X3 = Fp.sub(t1, Z3);
|
|
16720
|
-
Z3 = Fp.add(t1, Z3);
|
|
16721
|
-
Y3 = Fp.mul(X3, Z3);
|
|
16722
|
-
t1 = Fp.add(t0, t0);
|
|
16723
|
-
t1 = Fp.add(t1, t0);
|
|
16724
|
-
t2 = Fp.mul(a, t2);
|
|
16725
|
-
t4 = Fp.mul(b3, t4);
|
|
16726
|
-
t1 = Fp.add(t1, t2);
|
|
16727
|
-
t2 = Fp.sub(t0, t2);
|
|
16728
|
-
t2 = Fp.mul(a, t2);
|
|
16729
|
-
t4 = Fp.add(t4, t2);
|
|
16730
|
-
t0 = Fp.mul(t1, t4);
|
|
16731
|
-
Y3 = Fp.add(Y3, t0);
|
|
16732
|
-
t0 = Fp.mul(t5, t4);
|
|
16733
|
-
X3 = Fp.mul(t3, X3);
|
|
16734
|
-
X3 = Fp.sub(X3, t0);
|
|
16735
|
-
t0 = Fp.mul(t3, t1);
|
|
16736
|
-
Z3 = Fp.mul(t5, Z3);
|
|
16737
|
-
Z3 = Fp.add(Z3, t0);
|
|
16738
|
-
return new Point2(X3, Y3, Z3);
|
|
16739
|
-
}
|
|
16740
|
-
subtract(other) {
|
|
16741
|
-
return this.add(other.negate());
|
|
16742
|
-
}
|
|
16743
|
-
is0() {
|
|
16744
|
-
return this.equals(Point2.ZERO);
|
|
16745
|
-
}
|
|
16746
|
-
wNAF(n) {
|
|
16747
|
-
return wnaf.wNAFCached(this, n, Point2.normalizeZ);
|
|
16748
|
-
}
|
|
16749
|
-
/**
|
|
16750
|
-
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
16751
|
-
* It's faster, but should only be used when you don't care about
|
|
16752
|
-
* an exposed private key e.g. sig verification, which works over *public* keys.
|
|
16753
|
-
*/
|
|
16754
|
-
multiplyUnsafe(sc) {
|
|
16755
|
-
const { endo: endo2, n: N } = CURVE;
|
|
16756
|
-
aInRange2("scalar", sc, _0n10, N);
|
|
16757
|
-
const I = Point2.ZERO;
|
|
16758
|
-
if (sc === _0n10)
|
|
16759
|
-
return I;
|
|
16760
|
-
if (this.is0() || sc === _1n10)
|
|
16761
|
-
return this;
|
|
16762
|
-
if (!endo2 || wnaf.hasPrecomputes(this))
|
|
16763
|
-
return wnaf.wNAFCachedUnsafe(this, sc, Point2.normalizeZ);
|
|
16764
|
-
let { k1neg, k1, k2neg, k2 } = endo2.splitScalar(sc);
|
|
16765
|
-
let k1p = I;
|
|
16766
|
-
let k2p = I;
|
|
16767
|
-
let d = this;
|
|
16768
|
-
while (k1 > _0n10 || k2 > _0n10) {
|
|
16769
|
-
if (k1 & _1n10)
|
|
16770
|
-
k1p = k1p.add(d);
|
|
16771
|
-
if (k2 & _1n10)
|
|
16772
|
-
k2p = k2p.add(d);
|
|
16773
|
-
d = d.double();
|
|
16774
|
-
k1 >>= _1n10;
|
|
16775
|
-
k2 >>= _1n10;
|
|
16776
|
-
}
|
|
16777
|
-
if (k1neg)
|
|
16778
|
-
k1p = k1p.negate();
|
|
16779
|
-
if (k2neg)
|
|
16780
|
-
k2p = k2p.negate();
|
|
16781
|
-
k2p = new Point2(Fp.mul(k2p.px, endo2.beta), k2p.py, k2p.pz);
|
|
16782
|
-
return k1p.add(k2p);
|
|
16783
|
-
}
|
|
16784
|
-
/**
|
|
16785
|
-
* Constant time multiplication.
|
|
16786
|
-
* Uses wNAF method. Windowed method may be 10% faster,
|
|
16787
|
-
* but takes 2x longer to generate and consumes 2x memory.
|
|
16788
|
-
* Uses precomputes when available.
|
|
16789
|
-
* Uses endomorphism for Koblitz curves.
|
|
16790
|
-
* @param scalar by which the point would be multiplied
|
|
16791
|
-
* @returns New point
|
|
16792
|
-
*/
|
|
16793
|
-
multiply(scalar) {
|
|
16794
|
-
const { endo: endo2, n: N } = CURVE;
|
|
16795
|
-
aInRange2("scalar", scalar, _1n10, N);
|
|
16796
|
-
let point, fake;
|
|
16797
|
-
if (endo2) {
|
|
16798
|
-
const { k1neg, k1, k2neg, k2 } = endo2.splitScalar(scalar);
|
|
16799
|
-
let { p: k1p, f: f1p } = this.wNAF(k1);
|
|
16800
|
-
let { p: k2p, f: f2p } = this.wNAF(k2);
|
|
16801
|
-
k1p = wnaf.constTimeNegate(k1neg, k1p);
|
|
16802
|
-
k2p = wnaf.constTimeNegate(k2neg, k2p);
|
|
16803
|
-
k2p = new Point2(Fp.mul(k2p.px, endo2.beta), k2p.py, k2p.pz);
|
|
16804
|
-
point = k1p.add(k2p);
|
|
16805
|
-
fake = f1p.add(f2p);
|
|
16806
|
-
} else {
|
|
16807
|
-
const { p, f } = this.wNAF(scalar);
|
|
16808
|
-
point = p;
|
|
16809
|
-
fake = f;
|
|
16810
|
-
}
|
|
16811
|
-
return Point2.normalizeZ([point, fake])[0];
|
|
16812
|
-
}
|
|
16813
|
-
/**
|
|
16814
|
-
* Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
|
|
16815
|
-
* Not using Strauss-Shamir trick: precomputation tables are faster.
|
|
16816
|
-
* The trick could be useful if both P and Q are not G (not in our case).
|
|
16817
|
-
* @returns non-zero affine point
|
|
16818
|
-
*/
|
|
16819
|
-
multiplyAndAddUnsafe(Q, a, b) {
|
|
16820
|
-
const G = Point2.BASE;
|
|
16821
|
-
const mul = (P, a2) => a2 === _0n10 || a2 === _1n10 || !P.equals(G) ? P.multiplyUnsafe(a2) : P.multiply(a2);
|
|
16822
|
-
const sum = mul(this, a).add(mul(Q, b));
|
|
16823
|
-
return sum.is0() ? void 0 : sum;
|
|
16824
|
-
}
|
|
16825
|
-
// Converts Projective point to affine (x, y) coordinates.
|
|
16826
|
-
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
16827
|
-
// (x, y, z) ∋ (x=x/z, y=y/z)
|
|
16828
|
-
toAffine(iz) {
|
|
16829
|
-
return toAffineMemo(this, iz);
|
|
16830
|
-
}
|
|
16831
|
-
isTorsionFree() {
|
|
16832
|
-
const { h: cofactor, isTorsionFree } = CURVE;
|
|
16833
|
-
if (cofactor === _1n10)
|
|
16834
|
-
return true;
|
|
16835
|
-
if (isTorsionFree)
|
|
16836
|
-
return isTorsionFree(Point2, this);
|
|
16837
|
-
throw new Error("isTorsionFree() has not been declared for the elliptic curve");
|
|
16838
|
-
}
|
|
16839
|
-
clearCofactor() {
|
|
16840
|
-
const { h: cofactor, clearCofactor } = CURVE;
|
|
16841
|
-
if (cofactor === _1n10)
|
|
16842
|
-
return this;
|
|
16843
|
-
if (clearCofactor)
|
|
16844
|
-
return clearCofactor(Point2, this);
|
|
16845
|
-
return this.multiplyUnsafe(CURVE.h);
|
|
16846
|
-
}
|
|
16847
|
-
toRawBytes(isCompressed = true) {
|
|
16848
|
-
abool2("isCompressed", isCompressed);
|
|
16849
|
-
this.assertValidity();
|
|
16850
|
-
return toBytes4(Point2, this, isCompressed);
|
|
16851
|
-
}
|
|
16852
|
-
toHex(isCompressed = true) {
|
|
16853
|
-
abool2("isCompressed", isCompressed);
|
|
16854
|
-
return bytesToHex3(this.toRawBytes(isCompressed));
|
|
16855
|
-
}
|
|
16856
|
-
}
|
|
16857
|
-
Point2.BASE = new Point2(CURVE.Gx, CURVE.Gy, Fp.ONE);
|
|
16858
|
-
Point2.ZERO = new Point2(Fp.ZERO, Fp.ONE, Fp.ZERO);
|
|
16859
|
-
const { endo, nBitLength } = CURVE;
|
|
16860
|
-
const wnaf = wNAF2(Point2, endo ? Math.ceil(nBitLength / 2) : nBitLength);
|
|
16861
|
-
return {
|
|
16862
|
-
CURVE,
|
|
16863
|
-
ProjectivePoint: Point2,
|
|
16864
|
-
normPrivateKeyToScalar,
|
|
16865
|
-
weierstrassEquation,
|
|
16866
|
-
isWithinCurveOrder
|
|
16867
|
-
};
|
|
16868
|
-
}
|
|
16869
|
-
function validateOpts2(curve) {
|
|
16870
|
-
const opts = validateBasic2(curve);
|
|
16871
|
-
validateObject2(opts, {
|
|
16872
|
-
hash: "hash",
|
|
16873
|
-
hmac: "function",
|
|
16874
|
-
randomBytes: "function"
|
|
16875
|
-
}, {
|
|
16876
|
-
bits2int: "function",
|
|
16877
|
-
bits2int_modN: "function",
|
|
16878
|
-
lowS: "boolean"
|
|
16879
|
-
});
|
|
16880
|
-
return Object.freeze({ lowS: true, ...opts });
|
|
16881
|
-
}
|
|
16882
|
-
function weierstrass2(curveDef) {
|
|
16883
|
-
const CURVE = validateOpts2(curveDef);
|
|
16884
|
-
const { Fp, n: CURVE_ORDER, nByteLength, nBitLength } = CURVE;
|
|
16885
|
-
const compressedLen = Fp.BYTES + 1;
|
|
16886
|
-
const uncompressedLen = 2 * Fp.BYTES + 1;
|
|
16887
|
-
function modN2(a) {
|
|
16888
|
-
return mod2(a, CURVE_ORDER);
|
|
16889
|
-
}
|
|
16890
|
-
function invN(a) {
|
|
16891
|
-
return invert2(a, CURVE_ORDER);
|
|
16892
|
-
}
|
|
16893
|
-
const { ProjectivePoint: Point2, normPrivateKeyToScalar, weierstrassEquation, isWithinCurveOrder } = weierstrassPoints2({
|
|
16894
|
-
...CURVE,
|
|
16895
|
-
toBytes(_c, point, isCompressed) {
|
|
16896
|
-
const a = point.toAffine();
|
|
16897
|
-
const x = Fp.toBytes(a.x);
|
|
16898
|
-
const cat = concatBytes4;
|
|
16899
|
-
abool2("isCompressed", isCompressed);
|
|
16900
|
-
if (isCompressed) {
|
|
16901
|
-
return cat(Uint8Array.from([point.hasEvenY() ? 2 : 3]), x);
|
|
16902
|
-
} else {
|
|
16903
|
-
return cat(Uint8Array.from([4]), x, Fp.toBytes(a.y));
|
|
16904
|
-
}
|
|
16905
|
-
},
|
|
16906
|
-
fromBytes(bytes) {
|
|
16907
|
-
const len = bytes.length;
|
|
16908
|
-
const head = bytes[0];
|
|
16909
|
-
const tail = bytes.subarray(1);
|
|
16910
|
-
if (len === compressedLen && (head === 2 || head === 3)) {
|
|
16911
|
-
const x = bytesToNumberBE2(tail);
|
|
16912
|
-
if (!inRange2(x, _1n10, Fp.ORDER))
|
|
16913
|
-
throw new Error("Point is not on curve");
|
|
16914
|
-
const y2 = weierstrassEquation(x);
|
|
16915
|
-
let y;
|
|
16916
|
-
try {
|
|
16917
|
-
y = Fp.sqrt(y2);
|
|
16918
|
-
} catch (sqrtError) {
|
|
16919
|
-
const suffix = sqrtError instanceof Error ? ": " + sqrtError.message : "";
|
|
16920
|
-
throw new Error("Point is not on curve" + suffix);
|
|
16921
|
-
}
|
|
16922
|
-
const isYOdd = (y & _1n10) === _1n10;
|
|
16923
|
-
const isHeadOdd = (head & 1) === 1;
|
|
16924
|
-
if (isHeadOdd !== isYOdd)
|
|
16925
|
-
y = Fp.neg(y);
|
|
16926
|
-
return { x, y };
|
|
16927
|
-
} else if (len === uncompressedLen && head === 4) {
|
|
16928
|
-
const x = Fp.fromBytes(tail.subarray(0, Fp.BYTES));
|
|
16929
|
-
const y = Fp.fromBytes(tail.subarray(Fp.BYTES, 2 * Fp.BYTES));
|
|
16930
|
-
return { x, y };
|
|
16931
|
-
} else {
|
|
16932
|
-
const cl = compressedLen;
|
|
16933
|
-
const ul = uncompressedLen;
|
|
16934
|
-
throw new Error("invalid Point, expected length of " + cl + ", or uncompressed " + ul + ", got " + len);
|
|
16935
|
-
}
|
|
16936
|
-
}
|
|
16937
|
-
});
|
|
16938
|
-
function isBiggerThanHalfOrder(number) {
|
|
16939
|
-
const HALF = CURVE_ORDER >> _1n10;
|
|
16940
|
-
return number > HALF;
|
|
16941
|
-
}
|
|
16942
|
-
function normalizeS(s) {
|
|
16943
|
-
return isBiggerThanHalfOrder(s) ? modN2(-s) : s;
|
|
16944
|
-
}
|
|
16945
|
-
const slcNum = (b, from14, to) => bytesToNumberBE2(b.slice(from14, to));
|
|
16946
|
-
class Signature {
|
|
16947
|
-
constructor(r, s, recovery) {
|
|
16948
|
-
aInRange2("r", r, _1n10, CURVE_ORDER);
|
|
16949
|
-
aInRange2("s", s, _1n10, CURVE_ORDER);
|
|
16950
|
-
this.r = r;
|
|
16951
|
-
this.s = s;
|
|
16952
|
-
if (recovery != null)
|
|
16953
|
-
this.recovery = recovery;
|
|
16954
|
-
Object.freeze(this);
|
|
16955
|
-
}
|
|
16956
|
-
// pair (bytes of r, bytes of s)
|
|
16957
|
-
static fromCompact(hex) {
|
|
16958
|
-
const l = nByteLength;
|
|
16959
|
-
hex = ensureBytes2("compactSignature", hex, l * 2);
|
|
16960
|
-
return new Signature(slcNum(hex, 0, l), slcNum(hex, l, 2 * l));
|
|
16961
|
-
}
|
|
16962
|
-
// DER encoded ECDSA signature
|
|
16963
|
-
// https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
|
|
16964
|
-
static fromDER(hex) {
|
|
16965
|
-
const { r, s } = DER2.toSig(ensureBytes2("DER", hex));
|
|
16966
|
-
return new Signature(r, s);
|
|
16967
|
-
}
|
|
16968
|
-
/**
|
|
16969
|
-
* @todo remove
|
|
16970
|
-
* @deprecated
|
|
16971
|
-
*/
|
|
16972
|
-
assertValidity() {
|
|
16973
|
-
}
|
|
16974
|
-
addRecoveryBit(recovery) {
|
|
16975
|
-
return new Signature(this.r, this.s, recovery);
|
|
16976
|
-
}
|
|
16977
|
-
recoverPublicKey(msgHash) {
|
|
16978
|
-
const { r, s, recovery: rec } = this;
|
|
16979
|
-
const h = bits2int_modN(ensureBytes2("msgHash", msgHash));
|
|
16980
|
-
if (rec == null || ![0, 1, 2, 3].includes(rec))
|
|
16981
|
-
throw new Error("recovery id invalid");
|
|
16982
|
-
const radj = rec === 2 || rec === 3 ? r + CURVE.n : r;
|
|
16983
|
-
if (radj >= Fp.ORDER)
|
|
16984
|
-
throw new Error("recovery id 2 or 3 invalid");
|
|
16985
|
-
const prefix = (rec & 1) === 0 ? "02" : "03";
|
|
16986
|
-
const R = Point2.fromHex(prefix + numToSizedHex2(radj, Fp.BYTES));
|
|
16987
|
-
const ir = invN(radj);
|
|
16988
|
-
const u1 = modN2(-h * ir);
|
|
16989
|
-
const u2 = modN2(s * ir);
|
|
16990
|
-
const Q = Point2.BASE.multiplyAndAddUnsafe(R, u1, u2);
|
|
16991
|
-
if (!Q)
|
|
16992
|
-
throw new Error("point at infinify");
|
|
16993
|
-
Q.assertValidity();
|
|
16994
|
-
return Q;
|
|
16995
|
-
}
|
|
16996
|
-
// Signatures should be low-s, to prevent malleability.
|
|
16997
|
-
hasHighS() {
|
|
16998
|
-
return isBiggerThanHalfOrder(this.s);
|
|
16999
|
-
}
|
|
17000
|
-
normalizeS() {
|
|
17001
|
-
return this.hasHighS() ? new Signature(this.r, modN2(-this.s), this.recovery) : this;
|
|
17002
|
-
}
|
|
17003
|
-
// DER-encoded
|
|
17004
|
-
toDERRawBytes() {
|
|
17005
|
-
return hexToBytes3(this.toDERHex());
|
|
17006
|
-
}
|
|
17007
|
-
toDERHex() {
|
|
17008
|
-
return DER2.hexFromSig(this);
|
|
17009
|
-
}
|
|
17010
|
-
// padded bytes of r, then padded bytes of s
|
|
17011
|
-
toCompactRawBytes() {
|
|
17012
|
-
return hexToBytes3(this.toCompactHex());
|
|
17013
|
-
}
|
|
17014
|
-
toCompactHex() {
|
|
17015
|
-
const l = nByteLength;
|
|
17016
|
-
return numToSizedHex2(this.r, l) + numToSizedHex2(this.s, l);
|
|
17017
|
-
}
|
|
17018
|
-
}
|
|
17019
|
-
const utils = {
|
|
17020
|
-
isValidPrivateKey(privateKey) {
|
|
17021
|
-
try {
|
|
17022
|
-
normPrivateKeyToScalar(privateKey);
|
|
17023
|
-
return true;
|
|
17024
|
-
} catch (error) {
|
|
17025
|
-
return false;
|
|
17026
|
-
}
|
|
17027
|
-
},
|
|
17028
|
-
normPrivateKeyToScalar,
|
|
17029
|
-
/**
|
|
17030
|
-
* Produces cryptographically secure private key from random of size
|
|
17031
|
-
* (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
|
|
17032
|
-
*/
|
|
17033
|
-
randomPrivateKey: () => {
|
|
17034
|
-
const length = getMinHashLength2(CURVE.n);
|
|
17035
|
-
return mapHashToField2(CURVE.randomBytes(length), CURVE.n);
|
|
17036
|
-
},
|
|
17037
|
-
/**
|
|
17038
|
-
* Creates precompute table for an arbitrary EC point. Makes point "cached".
|
|
17039
|
-
* Allows to massively speed-up `point.multiply(scalar)`.
|
|
17040
|
-
* @returns cached point
|
|
17041
|
-
* @example
|
|
17042
|
-
* const fast = utils.precompute(8, ProjectivePoint.fromHex(someonesPubKey));
|
|
17043
|
-
* fast.multiply(privKey); // much faster ECDH now
|
|
17044
|
-
*/
|
|
17045
|
-
precompute(windowSize = 8, point = Point2.BASE) {
|
|
17046
|
-
point._setWindowSize(windowSize);
|
|
17047
|
-
point.multiply(BigInt(3));
|
|
17048
|
-
return point;
|
|
17049
|
-
}
|
|
17050
|
-
};
|
|
17051
|
-
function getPublicKey(privateKey, isCompressed = true) {
|
|
17052
|
-
return Point2.fromPrivateKey(privateKey).toRawBytes(isCompressed);
|
|
17053
|
-
}
|
|
17054
|
-
function isProbPub(item) {
|
|
17055
|
-
if (typeof item === "bigint")
|
|
17056
|
-
return false;
|
|
17057
|
-
if (item instanceof Point2)
|
|
17058
|
-
return true;
|
|
17059
|
-
const arr = ensureBytes2("key", item);
|
|
17060
|
-
const len = arr.length;
|
|
17061
|
-
const fpl = Fp.BYTES;
|
|
17062
|
-
const compLen = fpl + 1;
|
|
17063
|
-
const uncompLen = 2 * fpl + 1;
|
|
17064
|
-
if (CURVE.allowedPrivateKeyLengths || nByteLength === compLen) {
|
|
17065
|
-
return void 0;
|
|
17066
|
-
} else {
|
|
17067
|
-
return len === compLen || len === uncompLen;
|
|
17068
|
-
}
|
|
17069
|
-
}
|
|
17070
|
-
function getSharedSecret(privateA, publicB, isCompressed = true) {
|
|
17071
|
-
if (isProbPub(privateA) === true)
|
|
17072
|
-
throw new Error("first arg must be private key");
|
|
17073
|
-
if (isProbPub(publicB) === false)
|
|
17074
|
-
throw new Error("second arg must be public key");
|
|
17075
|
-
const b = Point2.fromHex(publicB);
|
|
17076
|
-
return b.multiply(normPrivateKeyToScalar(privateA)).toRawBytes(isCompressed);
|
|
17077
|
-
}
|
|
17078
|
-
const bits2int = CURVE.bits2int || function(bytes) {
|
|
17079
|
-
if (bytes.length > 8192)
|
|
17080
|
-
throw new Error("input is too large");
|
|
17081
|
-
const num2 = bytesToNumberBE2(bytes);
|
|
17082
|
-
const delta = bytes.length * 8 - nBitLength;
|
|
17083
|
-
return delta > 0 ? num2 >> BigInt(delta) : num2;
|
|
17084
|
-
};
|
|
17085
|
-
const bits2int_modN = CURVE.bits2int_modN || function(bytes) {
|
|
17086
|
-
return modN2(bits2int(bytes));
|
|
17087
|
-
};
|
|
17088
|
-
const ORDER_MASK = bitMask2(nBitLength);
|
|
17089
|
-
function int2octets(num2) {
|
|
17090
|
-
aInRange2("num < 2^" + nBitLength, num2, _0n10, ORDER_MASK);
|
|
17091
|
-
return numberToBytesBE2(num2, nByteLength);
|
|
17092
|
-
}
|
|
17093
|
-
function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
|
|
17094
|
-
if (["recovered", "canonical"].some((k) => k in opts))
|
|
17095
|
-
throw new Error("sign() legacy options not supported");
|
|
17096
|
-
const { hash: hash3, randomBytes: randomBytes2 } = CURVE;
|
|
17097
|
-
let { lowS, prehash, extraEntropy: ent } = opts;
|
|
17098
|
-
if (lowS == null)
|
|
17099
|
-
lowS = true;
|
|
17100
|
-
msgHash = ensureBytes2("msgHash", msgHash);
|
|
17101
|
-
validateSigVerOpts2(opts);
|
|
17102
|
-
if (prehash)
|
|
17103
|
-
msgHash = ensureBytes2("prehashed msgHash", hash3(msgHash));
|
|
17104
|
-
const h1int = bits2int_modN(msgHash);
|
|
17105
|
-
const d = normPrivateKeyToScalar(privateKey);
|
|
17106
|
-
const seedArgs = [int2octets(d), int2octets(h1int)];
|
|
17107
|
-
if (ent != null && ent !== false) {
|
|
17108
|
-
const e = ent === true ? randomBytes2(Fp.BYTES) : ent;
|
|
17109
|
-
seedArgs.push(ensureBytes2("extraEntropy", e));
|
|
17110
|
-
}
|
|
17111
|
-
const seed = concatBytes4(...seedArgs);
|
|
17112
|
-
const m = h1int;
|
|
17113
|
-
function k2sig(kBytes) {
|
|
17114
|
-
const k = bits2int(kBytes);
|
|
17115
|
-
if (!isWithinCurveOrder(k))
|
|
17116
|
-
return;
|
|
17117
|
-
const ik = invN(k);
|
|
17118
|
-
const q = Point2.BASE.multiply(k).toAffine();
|
|
17119
|
-
const r = modN2(q.x);
|
|
17120
|
-
if (r === _0n10)
|
|
17121
|
-
return;
|
|
17122
|
-
const s = modN2(ik * modN2(m + r * d));
|
|
17123
|
-
if (s === _0n10)
|
|
17124
|
-
return;
|
|
17125
|
-
let recovery = (q.x === r ? 0 : 2) | Number(q.y & _1n10);
|
|
17126
|
-
let normS = s;
|
|
17127
|
-
if (lowS && isBiggerThanHalfOrder(s)) {
|
|
17128
|
-
normS = normalizeS(s);
|
|
17129
|
-
recovery ^= 1;
|
|
17130
|
-
}
|
|
17131
|
-
return new Signature(r, normS, recovery);
|
|
17132
|
-
}
|
|
17133
|
-
return { seed, k2sig };
|
|
17134
|
-
}
|
|
17135
|
-
const defaultSigOpts = { lowS: CURVE.lowS, prehash: false };
|
|
17136
|
-
const defaultVerOpts = { lowS: CURVE.lowS, prehash: false };
|
|
17137
|
-
function sign(msgHash, privKey, opts = defaultSigOpts) {
|
|
17138
|
-
const { seed, k2sig } = prepSig(msgHash, privKey, opts);
|
|
17139
|
-
const C = CURVE;
|
|
17140
|
-
const drbg = createHmacDrbg2(C.hash.outputLen, C.nByteLength, C.hmac);
|
|
17141
|
-
return drbg(seed, k2sig);
|
|
17142
|
-
}
|
|
17143
|
-
Point2.BASE._setWindowSize(8);
|
|
17144
|
-
function verify(signature, msgHash, publicKey, opts = defaultVerOpts) {
|
|
17145
|
-
const sg = signature;
|
|
17146
|
-
msgHash = ensureBytes2("msgHash", msgHash);
|
|
17147
|
-
publicKey = ensureBytes2("publicKey", publicKey);
|
|
17148
|
-
const { lowS, prehash, format } = opts;
|
|
17149
|
-
validateSigVerOpts2(opts);
|
|
17150
|
-
if ("strict" in opts)
|
|
17151
|
-
throw new Error("options.strict was renamed to lowS");
|
|
17152
|
-
if (format !== void 0 && format !== "compact" && format !== "der")
|
|
17153
|
-
throw new Error("format must be compact or der");
|
|
17154
|
-
const isHex2 = typeof sg === "string" || isBytes3(sg);
|
|
17155
|
-
const isObj = !isHex2 && !format && typeof sg === "object" && sg !== null && typeof sg.r === "bigint" && typeof sg.s === "bigint";
|
|
17156
|
-
if (!isHex2 && !isObj)
|
|
17157
|
-
throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
|
|
17158
|
-
let _sig = void 0;
|
|
17159
|
-
let P;
|
|
17160
|
-
try {
|
|
17161
|
-
if (isObj)
|
|
17162
|
-
_sig = new Signature(sg.r, sg.s);
|
|
17163
|
-
if (isHex2) {
|
|
17164
|
-
try {
|
|
17165
|
-
if (format !== "compact")
|
|
17166
|
-
_sig = Signature.fromDER(sg);
|
|
17167
|
-
} catch (derError) {
|
|
17168
|
-
if (!(derError instanceof DER2.Err))
|
|
17169
|
-
throw derError;
|
|
17170
|
-
}
|
|
17171
|
-
if (!_sig && format !== "der")
|
|
17172
|
-
_sig = Signature.fromCompact(sg);
|
|
17173
|
-
}
|
|
17174
|
-
P = Point2.fromHex(publicKey);
|
|
17175
|
-
} catch (error) {
|
|
17176
|
-
return false;
|
|
17177
|
-
}
|
|
17178
|
-
if (!_sig)
|
|
17179
|
-
return false;
|
|
17180
|
-
if (lowS && _sig.hasHighS())
|
|
17181
|
-
return false;
|
|
17182
|
-
if (prehash)
|
|
17183
|
-
msgHash = CURVE.hash(msgHash);
|
|
17184
|
-
const { r, s } = _sig;
|
|
17185
|
-
const h = bits2int_modN(msgHash);
|
|
17186
|
-
const is = invN(s);
|
|
17187
|
-
const u1 = modN2(h * is);
|
|
17188
|
-
const u2 = modN2(r * is);
|
|
17189
|
-
const R = Point2.BASE.multiplyAndAddUnsafe(P, u1, u2)?.toAffine();
|
|
17190
|
-
if (!R)
|
|
17191
|
-
return false;
|
|
17192
|
-
const v = modN2(R.x);
|
|
17193
|
-
return v === r;
|
|
17194
|
-
}
|
|
17195
|
-
return {
|
|
17196
|
-
CURVE,
|
|
17197
|
-
getPublicKey,
|
|
17198
|
-
getSharedSecret,
|
|
17199
|
-
sign,
|
|
17200
|
-
verify,
|
|
17201
|
-
ProjectivePoint: Point2,
|
|
17202
|
-
Signature,
|
|
17203
|
-
utils
|
|
17204
|
-
};
|
|
17205
|
-
}
|
|
17206
|
-
|
|
17207
|
-
// ../node_modules/ox/node_modules/@noble/curves/esm/_shortw_utils.js
|
|
17208
|
-
function getHash2(hash3) {
|
|
17209
|
-
return {
|
|
17210
|
-
hash: hash3,
|
|
17211
|
-
hmac: (key, ...msgs) => hmac(hash3, key, concatBytes(...msgs)),
|
|
17212
|
-
randomBytes
|
|
17213
|
-
};
|
|
17214
|
-
}
|
|
17215
|
-
function createCurve2(curveDef, defHash) {
|
|
17216
|
-
const create2 = (hash3) => weierstrass2({ ...curveDef, ...getHash2(hash3) });
|
|
17217
|
-
return { ...create2(defHash), create: create2 };
|
|
17218
|
-
}
|
|
17219
|
-
|
|
17220
|
-
// ../node_modules/ox/node_modules/@noble/curves/esm/secp256k1.js
|
|
17221
|
-
var secp256k1P2 = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f");
|
|
17222
|
-
var secp256k1N2 = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
|
|
17223
|
-
var _0n11 = BigInt(0);
|
|
17224
|
-
var _1n11 = BigInt(1);
|
|
17225
|
-
var _2n7 = BigInt(2);
|
|
17226
|
-
var divNearest2 = (a, b) => (a + b / _2n7) / b;
|
|
17227
|
-
function sqrtMod2(y) {
|
|
17228
|
-
const P = secp256k1P2;
|
|
17229
|
-
const _3n5 = BigInt(3), _6n = BigInt(6), _11n = BigInt(11), _22n = BigInt(22);
|
|
17230
|
-
const _23n = BigInt(23), _44n = BigInt(44), _88n = BigInt(88);
|
|
17231
|
-
const b2 = y * y * y % P;
|
|
17232
|
-
const b3 = b2 * b2 * y % P;
|
|
17233
|
-
const b6 = pow22(b3, _3n5, P) * b3 % P;
|
|
17234
|
-
const b9 = pow22(b6, _3n5, P) * b3 % P;
|
|
17235
|
-
const b11 = pow22(b9, _2n7, P) * b2 % P;
|
|
17236
|
-
const b22 = pow22(b11, _11n, P) * b11 % P;
|
|
17237
|
-
const b44 = pow22(b22, _22n, P) * b22 % P;
|
|
17238
|
-
const b88 = pow22(b44, _44n, P) * b44 % P;
|
|
17239
|
-
const b176 = pow22(b88, _88n, P) * b88 % P;
|
|
17240
|
-
const b220 = pow22(b176, _44n, P) * b44 % P;
|
|
17241
|
-
const b223 = pow22(b220, _3n5, P) * b3 % P;
|
|
17242
|
-
const t1 = pow22(b223, _23n, P) * b22 % P;
|
|
17243
|
-
const t2 = pow22(t1, _6n, P) * b2 % P;
|
|
17244
|
-
const root = pow22(t2, _2n7, P);
|
|
17245
|
-
if (!Fpk12.eql(Fpk12.sqr(root), y))
|
|
17246
|
-
throw new Error("Cannot find square root");
|
|
17247
|
-
return root;
|
|
17248
|
-
}
|
|
17249
|
-
var Fpk12 = Field2(secp256k1P2, void 0, void 0, { sqrt: sqrtMod2 });
|
|
17250
|
-
var secp256k12 = createCurve2({
|
|
17251
|
-
a: _0n11,
|
|
17252
|
-
b: BigInt(7),
|
|
17253
|
-
Fp: Fpk12,
|
|
17254
|
-
n: secp256k1N2,
|
|
17255
|
-
Gx: BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
|
|
17256
|
-
Gy: BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),
|
|
17257
|
-
h: BigInt(1),
|
|
17258
|
-
lowS: true,
|
|
17259
|
-
// Allow only low-S signatures by default in sign() and verify()
|
|
17260
|
-
endo: {
|
|
17261
|
-
// Endomorphism, see above
|
|
17262
|
-
beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
|
|
17263
|
-
splitScalar: (k) => {
|
|
17264
|
-
const n = secp256k1N2;
|
|
17265
|
-
const a1 = BigInt("0x3086d221a7d46bcde86c90e49284eb15");
|
|
17266
|
-
const b1 = -_1n11 * BigInt("0xe4437ed6010e88286f547fa90abfe4c3");
|
|
17267
|
-
const a2 = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8");
|
|
17268
|
-
const b2 = a1;
|
|
17269
|
-
const POW_2_128 = BigInt("0x100000000000000000000000000000000");
|
|
17270
|
-
const c1 = divNearest2(b2 * k, n);
|
|
17271
|
-
const c2 = divNearest2(-b1 * k, n);
|
|
17272
|
-
let k1 = mod2(k - c1 * a1 - c2 * a2, n);
|
|
17273
|
-
let k2 = mod2(-c1 * b1 - c2 * b2, n);
|
|
17274
|
-
const k1neg = k1 > POW_2_128;
|
|
17275
|
-
const k2neg = k2 > POW_2_128;
|
|
17276
|
-
if (k1neg)
|
|
17277
|
-
k1 = n - k1;
|
|
17278
|
-
if (k2neg)
|
|
17279
|
-
k2 = n - k2;
|
|
17280
|
-
if (k1 > POW_2_128 || k2 > POW_2_128) {
|
|
17281
|
-
throw new Error("splitScalar: Endomorphism failed, k=" + k);
|
|
17282
|
-
}
|
|
17283
|
-
return { k1neg, k1, k2neg, k2 };
|
|
17284
|
-
}
|
|
17285
|
-
}
|
|
17286
|
-
}, sha256);
|
|
17287
|
-
|
|
17288
|
-
// ../node_modules/ox/_esm/core/Signature.js
|
|
17289
|
-
init_Errors();
|
|
17290
|
-
init_Hex();
|
|
17291
|
-
init_Json();
|
|
17292
|
-
function assert5(signature, options = {}) {
|
|
17293
|
-
const { recovered } = options;
|
|
17294
|
-
if (typeof signature.r === "undefined")
|
|
17295
|
-
throw new MissingPropertiesError({ signature });
|
|
17296
|
-
if (typeof signature.s === "undefined")
|
|
17297
|
-
throw new MissingPropertiesError({ signature });
|
|
17298
|
-
if (recovered && typeof signature.yParity === "undefined")
|
|
17299
|
-
throw new MissingPropertiesError({ signature });
|
|
17300
|
-
if (signature.r < 0n || signature.r > maxUint2562)
|
|
17301
|
-
throw new InvalidRError({ value: signature.r });
|
|
17302
|
-
if (signature.s < 0n || signature.s > maxUint2562)
|
|
17303
|
-
throw new InvalidSError({ value: signature.s });
|
|
17304
|
-
if (typeof signature.yParity === "number" && signature.yParity !== 0 && signature.yParity !== 1)
|
|
17305
|
-
throw new InvalidYParityError({ value: signature.yParity });
|
|
17306
|
-
}
|
|
17307
|
-
function fromBytes3(signature) {
|
|
17308
|
-
return fromHex4(fromBytes(signature));
|
|
17309
|
-
}
|
|
17310
|
-
function fromHex4(signature) {
|
|
17311
|
-
if (signature.length !== 130 && signature.length !== 132)
|
|
17312
|
-
throw new InvalidSerializedSizeError2({ signature });
|
|
17313
|
-
const r = BigInt(slice3(signature, 0, 32));
|
|
17314
|
-
const s = BigInt(slice3(signature, 32, 64));
|
|
17315
|
-
const yParity = (() => {
|
|
17316
|
-
const yParity2 = Number(`0x${signature.slice(130)}`);
|
|
17317
|
-
if (Number.isNaN(yParity2))
|
|
17318
|
-
return void 0;
|
|
17319
|
-
try {
|
|
17320
|
-
return vToYParity(yParity2);
|
|
17321
|
-
} catch {
|
|
17322
|
-
throw new InvalidYParityError({ value: yParity2 });
|
|
17323
|
-
}
|
|
17324
|
-
})();
|
|
17325
|
-
if (typeof yParity === "undefined")
|
|
17326
|
-
return {
|
|
17327
|
-
r,
|
|
17328
|
-
s
|
|
17329
|
-
};
|
|
17330
|
-
return {
|
|
17331
|
-
r,
|
|
17332
|
-
s,
|
|
17333
|
-
yParity
|
|
17334
|
-
};
|
|
17335
|
-
}
|
|
17336
|
-
function extract2(value) {
|
|
17337
|
-
if (typeof value.r === "undefined")
|
|
17338
|
-
return void 0;
|
|
17339
|
-
if (typeof value.s === "undefined")
|
|
17340
|
-
return void 0;
|
|
17341
|
-
return from7(value);
|
|
17342
|
-
}
|
|
17343
|
-
function from7(signature) {
|
|
17344
|
-
const signature_ = (() => {
|
|
17345
|
-
if (typeof signature === "string")
|
|
17346
|
-
return fromHex4(signature);
|
|
17347
|
-
if (signature instanceof Uint8Array)
|
|
17348
|
-
return fromBytes3(signature);
|
|
17349
|
-
if (typeof signature.r === "string")
|
|
17350
|
-
return fromRpc2(signature);
|
|
17351
|
-
if (signature.v)
|
|
17352
|
-
return fromLegacy(signature);
|
|
17353
|
-
return {
|
|
17354
|
-
r: signature.r,
|
|
17355
|
-
s: signature.s,
|
|
17356
|
-
...typeof signature.yParity !== "undefined" ? { yParity: signature.yParity } : {}
|
|
17357
|
-
};
|
|
17358
|
-
})();
|
|
17359
|
-
assert5(signature_);
|
|
17360
|
-
return signature_;
|
|
15634
|
+
function from7(signature) {
|
|
15635
|
+
const signature_ = (() => {
|
|
15636
|
+
if (typeof signature === "string")
|
|
15637
|
+
return fromHex4(signature);
|
|
15638
|
+
if (signature instanceof Uint8Array)
|
|
15639
|
+
return fromBytes3(signature);
|
|
15640
|
+
if (typeof signature.r === "string")
|
|
15641
|
+
return fromRpc2(signature);
|
|
15642
|
+
if (signature.v)
|
|
15643
|
+
return fromLegacy(signature);
|
|
15644
|
+
return {
|
|
15645
|
+
r: signature.r,
|
|
15646
|
+
s: signature.s,
|
|
15647
|
+
...typeof signature.yParity !== "undefined" ? { yParity: signature.yParity } : {}
|
|
15648
|
+
};
|
|
15649
|
+
})();
|
|
15650
|
+
assert5(signature_);
|
|
15651
|
+
return signature_;
|
|
17361
15652
|
}
|
|
17362
15653
|
function fromLegacy(signature) {
|
|
17363
15654
|
return {
|
|
@@ -17514,6 +15805,7 @@ init_Errors();
|
|
|
17514
15805
|
init_Hex();
|
|
17515
15806
|
|
|
17516
15807
|
// ../node_modules/ox/_esm/core/Secp256k1.js
|
|
15808
|
+
init_secp256k1();
|
|
17517
15809
|
init_Hex();
|
|
17518
15810
|
function recoverAddress2(options) {
|
|
17519
15811
|
return fromPublicKey(recoverPublicKey2(options));
|
|
@@ -17521,7 +15813,7 @@ function recoverAddress2(options) {
|
|
|
17521
15813
|
function recoverPublicKey2(options) {
|
|
17522
15814
|
const { payload, signature } = options;
|
|
17523
15815
|
const { r, s, yParity } = signature;
|
|
17524
|
-
const signature_ = new
|
|
15816
|
+
const signature_ = new secp256k1.Signature(BigInt(r), BigInt(s)).addRecoveryBit(yParity);
|
|
17525
15817
|
const point = signature_.recoverPublicKey(from2(payload).substring(2));
|
|
17526
15818
|
return from3(point);
|
|
17527
15819
|
}
|
|
@@ -21223,12 +19515,6 @@ async function debugTransactionFailure(publicClient, failingWallet, workingWalle
|
|
|
21223
19515
|
@noble/hashes/esm/utils.js:
|
|
21224
19516
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
21225
19517
|
|
|
21226
|
-
@noble/curves/esm/abstract/utils.js:
|
|
21227
|
-
@noble/curves/esm/abstract/modular.js:
|
|
21228
|
-
@noble/curves/esm/abstract/curve.js:
|
|
21229
|
-
@noble/curves/esm/abstract/weierstrass.js:
|
|
21230
|
-
@noble/curves/esm/_shortw_utils.js:
|
|
21231
|
-
@noble/curves/esm/secp256k1.js:
|
|
21232
19518
|
@noble/curves/esm/abstract/utils.js:
|
|
21233
19519
|
@noble/curves/esm/abstract/modular.js:
|
|
21234
19520
|
@noble/curves/esm/abstract/curve.js:
|