@settlemint/sdk-cli 2.3.14-prfdf11875 → 2.4.0-main005a9b57

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/cli.js CHANGED
@@ -5149,7 +5149,7 @@ var require_sha2 = __commonJS((exports) => {
5149
5149
  exports.sha512_224 = (0, utils_ts_1.createHasher)(() => new SHA512_224);
5150
5150
  });
5151
5151
 
5152
- // ../../node_modules/@noble/curves/abstract/utils.js
5152
+ // ../../node_modules/eciesjs/node_modules/@noble/curves/abstract/utils.js
5153
5153
  var require_utils5 = __commonJS((exports) => {
5154
5154
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
5155
5155
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -5423,7 +5423,7 @@ var require_utils5 = __commonJS((exports) => {
5423
5423
  }
5424
5424
  });
5425
5425
 
5426
- // ../../node_modules/@noble/curves/abstract/modular.js
5426
+ // ../../node_modules/eciesjs/node_modules/@noble/curves/abstract/modular.js
5427
5427
  var require_modular = __commonJS((exports) => {
5428
5428
  Object.defineProperty(exports, "__esModule", { value: true });
5429
5429
  exports.isNegativeLE = undefined;
@@ -5753,7 +5753,7 @@ var require_modular = __commonJS((exports) => {
5753
5753
  }
5754
5754
  });
5755
5755
 
5756
- // ../../node_modules/@noble/curves/abstract/curve.js
5756
+ // ../../node_modules/eciesjs/node_modules/@noble/curves/abstract/curve.js
5757
5757
  var require_curve = __commonJS((exports) => {
5758
5758
  Object.defineProperty(exports, "__esModule", { value: true });
5759
5759
  exports.wNAF = wNAF;
@@ -6002,7 +6002,7 @@ var require_curve = __commonJS((exports) => {
6002
6002
  }
6003
6003
  });
6004
6004
 
6005
- // ../../node_modules/@noble/curves/abstract/edwards.js
6005
+ // ../../node_modules/eciesjs/node_modules/@noble/curves/abstract/edwards.js
6006
6006
  var require_edwards = __commonJS((exports) => {
6007
6007
  Object.defineProperty(exports, "__esModule", { value: true });
6008
6008
  exports.twistedEdwards = twistedEdwards;
@@ -6361,7 +6361,7 @@ var require_edwards = __commonJS((exports) => {
6361
6361
  }
6362
6362
  });
6363
6363
 
6364
- // ../../node_modules/@noble/curves/abstract/hash-to-curve.js
6364
+ // ../../node_modules/eciesjs/node_modules/@noble/curves/abstract/hash-to-curve.js
6365
6365
  var require_hash_to_curve = __commonJS((exports) => {
6366
6366
  Object.defineProperty(exports, "__esModule", { value: true });
6367
6367
  exports.expand_message_xmd = expand_message_xmd;
@@ -6514,7 +6514,7 @@ var require_hash_to_curve = __commonJS((exports) => {
6514
6514
  }
6515
6515
  });
6516
6516
 
6517
- // ../../node_modules/@noble/curves/abstract/montgomery.js
6517
+ // ../../node_modules/eciesjs/node_modules/@noble/curves/abstract/montgomery.js
6518
6518
  var require_montgomery = __commonJS((exports) => {
6519
6519
  Object.defineProperty(exports, "__esModule", { value: true });
6520
6520
  exports.montgomery = montgomery;
@@ -6621,7 +6621,7 @@ var require_montgomery = __commonJS((exports) => {
6621
6621
  }
6622
6622
  });
6623
6623
 
6624
- // ../../node_modules/@noble/curves/ed25519.js
6624
+ // ../../node_modules/eciesjs/node_modules/@noble/curves/ed25519.js
6625
6625
  var require_ed25519 = __commonJS((exports) => {
6626
6626
  Object.defineProperty(exports, "__esModule", { value: true });
6627
6627
  exports.hash_to_ristretto255 = exports.hashToRistretto255 = exports.RistrettoPoint = exports.encodeToCurve = exports.hashToCurve = exports.ed25519_hasher = exports.edwardsToMontgomery = exports.x25519 = exports.ed25519ph = exports.ed25519ctx = exports.ed25519 = exports.ED25519_TORSION_SUBGROUP = undefined;
@@ -7061,7 +7061,7 @@ var require_hmac = __commonJS((exports) => {
7061
7061
  exports.hmac.create = (hash, key) => new HMAC(hash, key);
7062
7062
  });
7063
7063
 
7064
- // ../../node_modules/@noble/curves/abstract/weierstrass.js
7064
+ // ../../node_modules/eciesjs/node_modules/@noble/curves/abstract/weierstrass.js
7065
7065
  var require_weierstrass = __commonJS((exports) => {
7066
7066
  Object.defineProperty(exports, "__esModule", { value: true });
7067
7067
  exports.DER = exports.DERErr = undefined;
@@ -7980,7 +7980,7 @@ var require_weierstrass = __commonJS((exports) => {
7980
7980
  }
7981
7981
  });
7982
7982
 
7983
- // ../../node_modules/@noble/curves/_shortw_utils.js
7983
+ // ../../node_modules/eciesjs/node_modules/@noble/curves/_shortw_utils.js
7984
7984
  var require__shortw_utils = __commonJS((exports) => {
7985
7985
  Object.defineProperty(exports, "__esModule", { value: true });
7986
7986
  exports.getHash = getHash;
@@ -8002,7 +8002,7 @@ var require__shortw_utils = __commonJS((exports) => {
8002
8002
  }
8003
8003
  });
8004
8004
 
8005
- // ../../node_modules/@noble/curves/secp256k1.js
8005
+ // ../../node_modules/eciesjs/node_modules/@noble/curves/secp256k1.js
8006
8006
  var require_secp256k1 = __commonJS((exports) => {
8007
8007
  Object.defineProperty(exports, "__esModule", { value: true });
8008
8008
  exports.encodeToCurve = exports.hashToCurve = exports.secp256k1_hasher = exports.schnorr = exports.secp256k1 = undefined;
@@ -48857,7 +48857,7 @@ var require_typescript = __commonJS((exports, module) => {
48857
48857
  tryGetPropertyNameOfBindingOrAssignmentElement: () => tryGetPropertyNameOfBindingOrAssignmentElement,
48858
48858
  tryGetSourceMappingURL: () => tryGetSourceMappingURL,
48859
48859
  tryGetTextOfPropertyName: () => tryGetTextOfPropertyName,
48860
- tryParseJson: () => tryParseJson4,
48860
+ tryParseJson: () => tryParseJson5,
48861
48861
  tryParsePattern: () => tryParsePattern,
48862
48862
  tryParsePatterns: () => tryParsePatterns,
48863
48863
  tryParseRawSourceMap: () => tryParseRawSourceMap,
@@ -66862,7 +66862,7 @@ ${lanes.join(`
66862
66862
  function readJson(path7, host) {
66863
66863
  return readJsonOrUndefined(path7, host) || {};
66864
66864
  }
66865
- function tryParseJson4(text) {
66865
+ function tryParseJson5(text) {
66866
66866
  try {
66867
66867
  return JSON.parse(text);
66868
66868
  } catch {
@@ -92927,7 +92927,7 @@ ${lanes.join(`
92927
92927
  if (isMissingPackageJsonInfo(cachedPackageJson) || !host.fileExists(packageJsonPath)) {
92928
92928
  return;
92929
92929
  }
92930
- const packageJsonContent = (cachedPackageJson == null ? undefined : cachedPackageJson.contents.packageJsonContent) || tryParseJson4(host.readFile(packageJsonPath));
92930
+ const packageJsonContent = (cachedPackageJson == null ? undefined : cachedPackageJson.contents.packageJsonContent) || tryParseJson5(host.readFile(packageJsonPath));
92931
92931
  const imports = packageJsonContent == null ? undefined : packageJsonContent.imports;
92932
92932
  if (!imports) {
92933
92933
  return;
@@ -93013,7 +93013,7 @@ ${lanes.join(`
93013
93013
  let maybeBlockedByTypesVersions = false;
93014
93014
  const cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) == null ? undefined : _a.call(host)) == null ? undefined : _b.getPackageJsonInfo(packageJsonPath);
93015
93015
  if (isPackageJsonInfo(cachedPackageJson) || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) {
93016
- const packageJsonContent = (cachedPackageJson == null ? undefined : cachedPackageJson.contents.packageJsonContent) || tryParseJson4(host.readFile(packageJsonPath));
93016
+ const packageJsonContent = (cachedPackageJson == null ? undefined : cachedPackageJson.contents.packageJsonContent) || tryParseJson5(host.readFile(packageJsonPath));
93017
93017
  const importMode = overrideMode || getDefaultResolutionModeForFile(importingSourceFile, host, options);
93018
93018
  if (getResolvePackageJsonExports(options)) {
93019
93019
  const nodeModulesDirectoryName2 = packageRootPath.substring(parts.topLevelPackageNameIndex + 1);
@@ -166185,7 +166185,7 @@ ${lanes.join(`
166185
166185
  }
166186
166186
  const dependencyKeys = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
166187
166187
  const stringContent = host.readFile(fileName) || "";
166188
- const content = tryParseJson4(stringContent);
166188
+ const content = tryParseJson5(stringContent);
166189
166189
  const info = {};
166190
166190
  if (content) {
166191
166191
  for (const key2 of dependencyKeys) {
@@ -204120,7 +204120,7 @@ ${options.prefix}` : `
204120
204120
  tryGetPropertyNameOfBindingOrAssignmentElement: () => tryGetPropertyNameOfBindingOrAssignmentElement,
204121
204121
  tryGetSourceMappingURL: () => tryGetSourceMappingURL,
204122
204122
  tryGetTextOfPropertyName: () => tryGetTextOfPropertyName,
204123
- tryParseJson: () => tryParseJson4,
204123
+ tryParseJson: () => tryParseJson5,
204124
204124
  tryParsePattern: () => tryParsePattern,
204125
204125
  tryParsePatterns: () => tryParsePatterns,
204126
204126
  tryParseRawSourceMap: () => tryParseRawSourceMap,
@@ -231623,7 +231623,7 @@ function size(value4) {
231623
231623
  var init_size = () => {};
231624
231624
 
231625
231625
  // ../../node_modules/viem/_esm/errors/version.js
231626
- var version5 = "2.31.0";
231626
+ var version5 = "2.31.2";
231627
231627
 
231628
231628
  // ../../node_modules/viem/_esm/errors/base.js
231629
231629
  function walk(err, fn) {
@@ -232421,6 +232421,46 @@ function byteSwap32(arr) {
232421
232421
  }
232422
232422
  return arr;
232423
232423
  }
232424
+ function bytesToHex2(bytes) {
232425
+ abytes(bytes);
232426
+ if (hasHexBuiltin)
232427
+ return bytes.toHex();
232428
+ let hex = "";
232429
+ for (let i6 = 0;i6 < bytes.length; i6++) {
232430
+ hex += hexes2[bytes[i6]];
232431
+ }
232432
+ return hex;
232433
+ }
232434
+ function asciiToBase16(ch) {
232435
+ if (ch >= asciis._0 && ch <= asciis._9)
232436
+ return ch - asciis._0;
232437
+ if (ch >= asciis.A && ch <= asciis.F)
232438
+ return ch - (asciis.A - 10);
232439
+ if (ch >= asciis.a && ch <= asciis.f)
232440
+ return ch - (asciis.a - 10);
232441
+ return;
232442
+ }
232443
+ function hexToBytes2(hex) {
232444
+ if (typeof hex !== "string")
232445
+ throw new Error("hex string expected, got " + typeof hex);
232446
+ if (hasHexBuiltin)
232447
+ return Uint8Array.fromHex(hex);
232448
+ const hl = hex.length;
232449
+ const al = hl / 2;
232450
+ if (hl % 2)
232451
+ throw new Error("hex string expected, got unpadded hex of length " + hl);
232452
+ const array4 = new Uint8Array(al);
232453
+ for (let ai = 0, hi = 0;ai < al; ai++, hi += 2) {
232454
+ const n1 = asciiToBase16(hex.charCodeAt(hi));
232455
+ const n22 = asciiToBase16(hex.charCodeAt(hi + 1));
232456
+ if (n1 === undefined || n22 === undefined) {
232457
+ const char = hex[hi] + hex[hi + 1];
232458
+ throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
232459
+ }
232460
+ array4[ai] = n1 * 16 + n22;
232461
+ }
232462
+ return array4;
232463
+ }
232424
232464
  function utf8ToBytes(str) {
232425
232465
  if (typeof str !== "string")
232426
232466
  throw new Error("string expected");
@@ -232467,12 +232507,15 @@ function randomBytes(bytesLength = 32) {
232467
232507
  }
232468
232508
  throw new Error("crypto.getRandomValues must be defined");
232469
232509
  }
232470
- var isLE, swap32IfBE;
232510
+ var isLE, swap32IfBE, hasHexBuiltin, hexes2, asciis;
232471
232511
  var init_utils2 = __esm(() => {
232472
232512
  init_cryptoNode();
232473
232513
  /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
232474
232514
  isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
232475
232515
  swap32IfBE = isLE ? (u6) => u6 : byteSwap32;
232516
+ hasHexBuiltin = /* @__PURE__ */ (() => typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function")();
232517
+ hexes2 = /* @__PURE__ */ Array.from({ length: 256 }, (_5, i6) => i6.toString(16).padStart(2, "0"));
232518
+ asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
232476
232519
  });
232477
232520
 
232478
232521
  // ../../node_modules/@noble/hashes/esm/sha3.js
@@ -235138,14 +235181,7 @@ var init_hmac = __esm(() => {
235138
235181
  hmac.create = (hash2, key2) => new HMAC(hash2, key2);
235139
235182
  });
235140
235183
 
235141
- // ../../node_modules/@noble/curves/esm/abstract/utils.js
235142
- function isBytes2(a7) {
235143
- return a7 instanceof Uint8Array || ArrayBuffer.isView(a7) && a7.constructor.name === "Uint8Array";
235144
- }
235145
- function abytes2(item) {
235146
- if (!isBytes2(item))
235147
- throw new Error("Uint8Array expected");
235148
- }
235184
+ // ../../node_modules/@noble/curves/esm/utils.js
235149
235185
  function abool(title, value4) {
235150
235186
  if (typeof value4 !== "boolean")
235151
235187
  throw new Error(title + " boolean expected, got " + value4);
@@ -235159,51 +235195,11 @@ function hexToNumber2(hex) {
235159
235195
  throw new Error("hex string expected, got " + typeof hex);
235160
235196
  return hex === "" ? _0n2 : BigInt("0x" + hex);
235161
235197
  }
235162
- function bytesToHex2(bytes) {
235163
- abytes2(bytes);
235164
- if (hasHexBuiltin)
235165
- return bytes.toHex();
235166
- let hex = "";
235167
- for (let i6 = 0;i6 < bytes.length; i6++) {
235168
- hex += hexes2[bytes[i6]];
235169
- }
235170
- return hex;
235171
- }
235172
- function asciiToBase16(ch) {
235173
- if (ch >= asciis._0 && ch <= asciis._9)
235174
- return ch - asciis._0;
235175
- if (ch >= asciis.A && ch <= asciis.F)
235176
- return ch - (asciis.A - 10);
235177
- if (ch >= asciis.a && ch <= asciis.f)
235178
- return ch - (asciis.a - 10);
235179
- return;
235180
- }
235181
- function hexToBytes2(hex) {
235182
- if (typeof hex !== "string")
235183
- throw new Error("hex string expected, got " + typeof hex);
235184
- if (hasHexBuiltin)
235185
- return Uint8Array.fromHex(hex);
235186
- const hl = hex.length;
235187
- const al = hl / 2;
235188
- if (hl % 2)
235189
- throw new Error("hex string expected, got unpadded hex of length " + hl);
235190
- const array4 = new Uint8Array(al);
235191
- for (let ai = 0, hi = 0;ai < al; ai++, hi += 2) {
235192
- const n1 = asciiToBase16(hex.charCodeAt(hi));
235193
- const n22 = asciiToBase16(hex.charCodeAt(hi + 1));
235194
- if (n1 === undefined || n22 === undefined) {
235195
- const char = hex[hi] + hex[hi + 1];
235196
- throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
235197
- }
235198
- array4[ai] = n1 * 16 + n22;
235199
- }
235200
- return array4;
235201
- }
235202
235198
  function bytesToNumberBE(bytes) {
235203
235199
  return hexToNumber2(bytesToHex2(bytes));
235204
235200
  }
235205
235201
  function bytesToNumberLE(bytes) {
235206
- abytes2(bytes);
235202
+ abytes(bytes);
235207
235203
  return hexToNumber2(bytesToHex2(Uint8Array.from(bytes).reverse()));
235208
235204
  }
235209
235205
  function numberToBytesBE(n6, len) {
@@ -235220,7 +235216,7 @@ function ensureBytes(title, hex, expectedLength) {
235220
235216
  } catch (e10) {
235221
235217
  throw new Error(title + " must be hex string or Uint8Array, cause: " + e10);
235222
235218
  }
235223
- } else if (isBytes2(hex)) {
235219
+ } else if (isBytes(hex)) {
235224
235220
  res = Uint8Array.from(hex);
235225
235221
  } else {
235226
235222
  throw new Error(title + " must be hex string or Uint8Array");
@@ -235230,26 +235226,6 @@ function ensureBytes(title, hex, expectedLength) {
235230
235226
  throw new Error(title + " of length " + expectedLength + " expected, got " + len);
235231
235227
  return res;
235232
235228
  }
235233
- function concatBytes3(...arrays) {
235234
- let sum = 0;
235235
- for (let i6 = 0;i6 < arrays.length; i6++) {
235236
- const a7 = arrays[i6];
235237
- abytes2(a7);
235238
- sum += a7.length;
235239
- }
235240
- const res = new Uint8Array(sum);
235241
- for (let i6 = 0, pad2 = 0;i6 < arrays.length; i6++) {
235242
- const a7 = arrays[i6];
235243
- res.set(a7, pad2);
235244
- pad2 += a7.length;
235245
- }
235246
- return res;
235247
- }
235248
- function utf8ToBytes2(str) {
235249
- if (typeof str !== "string")
235250
- throw new Error("string expected");
235251
- return new Uint8Array(new TextEncoder().encode(str));
235252
- }
235253
235229
  function inRange(n6, min, max) {
235254
235230
  return isPosBig(n6) && isPosBig(min) && isPosBig(max) && min <= n6 && n6 < max;
235255
235231
  }
@@ -235270,6 +235246,8 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
235270
235246
  throw new Error("qByteLen must be a number");
235271
235247
  if (typeof hmacFn !== "function")
235272
235248
  throw new Error("hmacFn must be a function");
235249
+ const u8n = (len) => new Uint8Array(len);
235250
+ const u8of = (byte) => Uint8Array.of(byte);
235273
235251
  let v6 = u8n(hashLen);
235274
235252
  let k5 = u8n(hashLen);
235275
235253
  let i6 = 0;
@@ -235280,11 +235258,11 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
235280
235258
  };
235281
235259
  const h8 = (...b4) => hmacFn(k5, v6, ...b4);
235282
235260
  const reseed = (seed = u8n(0)) => {
235283
- k5 = h8(u8fr([0]), seed);
235261
+ k5 = h8(u8of(0), seed);
235284
235262
  v6 = h8();
235285
235263
  if (seed.length === 0)
235286
235264
  return;
235287
- k5 = h8(u8fr([1]), seed);
235265
+ k5 = h8(u8of(1), seed);
235288
235266
  v6 = h8();
235289
235267
  };
235290
235268
  const gen2 = () => {
@@ -235298,7 +235276,7 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
235298
235276
  out.push(sl);
235299
235277
  len += v6.length;
235300
235278
  }
235301
- return concatBytes3(...out);
235279
+ return concatBytes(...out);
235302
235280
  };
235303
235281
  const genUntil = (seed, pred) => {
235304
235282
  reset2();
@@ -235311,23 +235289,22 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
235311
235289
  };
235312
235290
  return genUntil;
235313
235291
  }
235314
- function validateObject(object4, validators, optValidators = {}) {
235315
- const checkField = (fieldName, type4, isOptional) => {
235316
- const checkVal = validatorFns[type4];
235317
- if (typeof checkVal !== "function")
235318
- throw new Error("invalid validator function");
235292
+ function isHash(val) {
235293
+ return typeof val === "function" && Number.isSafeInteger(val.outputLen);
235294
+ }
235295
+ function _validateObject(object4, fields, optFields = {}) {
235296
+ if (!object4 || typeof object4 !== "object")
235297
+ throw new Error("expected valid options object");
235298
+ function checkField(fieldName, expectedType, isOpt) {
235319
235299
  const val = object4[fieldName];
235320
- if (isOptional && val === undefined)
235300
+ if (isOpt && val === undefined)
235321
235301
  return;
235322
- if (!checkVal(val, object4)) {
235323
- throw new Error("param " + String(fieldName) + " is invalid. Expected " + type4 + ", got " + val);
235324
- }
235325
- };
235326
- for (const [fieldName, type4] of Object.entries(validators))
235327
- checkField(fieldName, type4, false);
235328
- for (const [fieldName, type4] of Object.entries(optValidators))
235329
- checkField(fieldName, type4, true);
235330
- return object4;
235302
+ const current = typeof val;
235303
+ if (current !== expectedType || val === null)
235304
+ throw new Error(`param "${fieldName}" is invalid: expected ${expectedType}, got ${current}`);
235305
+ }
235306
+ Object.entries(fields).forEach(([k5, v6]) => checkField(k5, v6, false));
235307
+ Object.entries(optFields).forEach(([k5, v6]) => checkField(k5, v6, true));
235331
235308
  }
235332
235309
  function memoized(fn) {
235333
235310
  const map6 = new WeakMap;
@@ -235340,25 +235317,13 @@ function memoized(fn) {
235340
235317
  return computed;
235341
235318
  };
235342
235319
  }
235343
- var _0n2, _1n2, hasHexBuiltin, hexes2, asciis, isPosBig = (n6) => typeof n6 === "bigint" && _0n2 <= n6, bitMask = (n6) => (_1n2 << BigInt(n6)) - _1n2, u8n = (len) => new Uint8Array(len), u8fr = (arr) => Uint8Array.from(arr), validatorFns;
235320
+ var _0n2, _1n2, isPosBig = (n6) => typeof n6 === "bigint" && _0n2 <= n6, bitMask = (n6) => (_1n2 << BigInt(n6)) - _1n2;
235344
235321
  var init_utils3 = __esm(() => {
235322
+ init_utils2();
235323
+ init_utils2();
235345
235324
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
235346
235325
  _0n2 = /* @__PURE__ */ BigInt(0);
235347
235326
  _1n2 = /* @__PURE__ */ BigInt(1);
235348
- hasHexBuiltin = typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function";
235349
- hexes2 = /* @__PURE__ */ Array.from({ length: 256 }, (_5, i6) => i6.toString(16).padStart(2, "0"));
235350
- asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
235351
- validatorFns = {
235352
- bigint: (val) => typeof val === "bigint",
235353
- function: (val) => typeof val === "function",
235354
- boolean: (val) => typeof val === "boolean",
235355
- string: (val) => typeof val === "string",
235356
- stringOrUint8Array: (val) => typeof val === "string" || isBytes2(val),
235357
- isSafeInteger: (val) => Number.isSafeInteger(val),
235358
- array: (val) => Array.isArray(val),
235359
- field: (val, object4) => object4.Fp.isValid(val),
235360
- hash: (val) => typeof val === "function" && Number.isSafeInteger(val.outputLen)
235361
- };
235362
235327
  });
235363
235328
 
235364
235329
  // ../../node_modules/@noble/curves/esm/abstract/modular.js
@@ -235472,14 +235437,15 @@ function validateField(field2) {
235472
235437
  const initial = {
235473
235438
  ORDER: "bigint",
235474
235439
  MASK: "bigint",
235475
- BYTES: "isSafeInteger",
235476
- BITS: "isSafeInteger"
235440
+ BYTES: "number",
235441
+ BITS: "number"
235477
235442
  };
235478
235443
  const opts = FIELD_FIELDS.reduce((map6, val) => {
235479
235444
  map6[val] = "function";
235480
235445
  return map6;
235481
235446
  }, initial);
235482
- return validateObject(field2, opts);
235447
+ _validateObject(field2, opts);
235448
+ return field2;
235483
235449
  }
235484
235450
  function FpPow(Fp, num, power) {
235485
235451
  if (power < _0n3)
@@ -235532,10 +235498,28 @@ function nLength(n6, nBitLength) {
235532
235498
  const nByteLength = Math.ceil(_nBitLength / 8);
235533
235499
  return { nBitLength: _nBitLength, nByteLength };
235534
235500
  }
235535
- function Field(ORDER, bitLen2, isLE2 = false, redef = {}) {
235501
+ function Field(ORDER, bitLenOrOpts, isLE2 = false, opts = {}) {
235536
235502
  if (ORDER <= _0n3)
235537
235503
  throw new Error("invalid field: expected ORDER > 0, got " + ORDER);
235538
- const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, bitLen2);
235504
+ let _nbitLength = undefined;
235505
+ let _sqrt = undefined;
235506
+ if (typeof bitLenOrOpts === "object" && bitLenOrOpts != null) {
235507
+ if (opts.sqrt || isLE2)
235508
+ throw new Error("cannot specify opts in two arguments");
235509
+ const _opts = bitLenOrOpts;
235510
+ if (_opts.BITS)
235511
+ _nbitLength = _opts.BITS;
235512
+ if (_opts.sqrt)
235513
+ _sqrt = _opts.sqrt;
235514
+ if (typeof _opts.isLE === "boolean")
235515
+ isLE2 = _opts.isLE;
235516
+ } else {
235517
+ if (typeof bitLenOrOpts === "number")
235518
+ _nbitLength = bitLenOrOpts;
235519
+ if (opts.sqrt)
235520
+ _sqrt = opts.sqrt;
235521
+ }
235522
+ const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, _nbitLength);
235539
235523
  if (BYTES > 2048)
235540
235524
  throw new Error("invalid field: expected ORDER of <= 2048 bytes");
235541
235525
  let sqrtP;
@@ -235554,6 +235538,7 @@ function Field(ORDER, bitLen2, isLE2 = false, redef = {}) {
235554
235538
  return _0n3 <= num && num < ORDER;
235555
235539
  },
235556
235540
  is0: (num) => num === _0n3,
235541
+ isValidNot0: (num) => !f5.is0(num) && f5.isValid(num),
235557
235542
  isOdd: (num) => (num & _1n3) === _1n3,
235558
235543
  neg: (num) => mod(-num, ORDER),
235559
235544
  eql: (lhs, rhs) => lhs === rhs,
@@ -235568,7 +235553,7 @@ function Field(ORDER, bitLen2, isLE2 = false, redef = {}) {
235568
235553
  subN: (lhs, rhs) => lhs - rhs,
235569
235554
  mulN: (lhs, rhs) => lhs * rhs,
235570
235555
  inv: (num) => invert(num, ORDER),
235571
- sqrt: redef.sqrt || ((n6) => {
235556
+ sqrt: _sqrt || ((n6) => {
235572
235557
  if (!sqrtP)
235573
235558
  sqrtP = FpSqrt(ORDER);
235574
235559
  return sqrtP(f5, n6);
@@ -235606,7 +235591,6 @@ function mapHashToField(key2, fieldOrder, isLE2 = false) {
235606
235591
  }
235607
235592
  var _0n3, _1n3, _2n2, _3n, _4n, _5n, _8n, FIELD_FIELDS;
235608
235593
  var init_modular = __esm(() => {
235609
- init_utils2();
235610
235594
  init_utils3();
235611
235595
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
235612
235596
  _0n3 = BigInt(0);
@@ -235638,10 +235622,16 @@ var init_modular = __esm(() => {
235638
235622
  });
235639
235623
 
235640
235624
  // ../../node_modules/@noble/curves/esm/abstract/curve.js
235641
- function constTimeNegate(condition, item) {
235625
+ function negateCt(condition, item) {
235642
235626
  const neg = item.negate();
235643
235627
  return condition ? neg : item;
235644
235628
  }
235629
+ function normalizeZ(c3, property, points) {
235630
+ const getz = property === "pz" ? (p5) => p5.pz : (p5) => p5.ez;
235631
+ const toInv = FpInvertBatch(c3.Fp, points.map(getz));
235632
+ const affined = points.map((p5, i6) => p5.toAffine(toInv[i6]));
235633
+ return affined.map(c3.fromAffine);
235634
+ }
235645
235635
  function validateW(W5, bits) {
235646
235636
  if (!Number.isSafeInteger(W5) || W5 <= 0 || W5 > bits)
235647
235637
  throw new Error("invalid window size, expected [1.." + bits + "], got W=" + W5);
@@ -235690,9 +235680,13 @@ function validateMSMScalars(scalars, field2) {
235690
235680
  function getW(P5) {
235691
235681
  return pointWindowSizes.get(P5) || 1;
235692
235682
  }
235683
+ function assert0(n6) {
235684
+ if (n6 !== _0n4)
235685
+ throw new Error("invalid wNAF");
235686
+ }
235693
235687
  function wNAF(c3, bits) {
235694
235688
  return {
235695
- constTimeNegate,
235689
+ constTimeNegate: negateCt,
235696
235690
  hasPrecomputes(elm) {
235697
235691
  return getW(elm) !== 1;
235698
235692
  },
@@ -235730,11 +235724,12 @@ function wNAF(c3, bits) {
235730
235724
  const { nextN, offset, isZero, isNeg, isNegF, offsetF } = calcOffsets(n6, window2, wo);
235731
235725
  n6 = nextN;
235732
235726
  if (isZero) {
235733
- f5 = f5.add(constTimeNegate(isNegF, precomputes[offsetF]));
235727
+ f5 = f5.add(negateCt(isNegF, precomputes[offsetF]));
235734
235728
  } else {
235735
- p5 = p5.add(constTimeNegate(isNeg, precomputes[offset]));
235729
+ p5 = p5.add(negateCt(isNeg, precomputes[offset]));
235736
235730
  }
235737
235731
  }
235732
+ assert0(n6);
235738
235733
  return { p: p5, f: f5 };
235739
235734
  },
235740
235735
  wNAFUnsafe(W5, precomputes, n6, acc = c3.ZERO) {
@@ -235751,14 +235746,18 @@ function wNAF(c3, bits) {
235751
235746
  acc = acc.add(isNeg ? item.negate() : item);
235752
235747
  }
235753
235748
  }
235749
+ assert0(n6);
235754
235750
  return acc;
235755
235751
  },
235756
235752
  getPrecomputes(W5, P5, transform5) {
235757
235753
  let comp = pointPrecomputes.get(P5);
235758
235754
  if (!comp) {
235759
235755
  comp = this.precomputeWindow(P5, W5);
235760
- if (W5 !== 1)
235761
- pointPrecomputes.set(P5, transform5(comp));
235756
+ if (W5 !== 1) {
235757
+ if (typeof transform5 === "function")
235758
+ comp = transform5(comp);
235759
+ pointPrecomputes.set(P5, comp);
235760
+ }
235762
235761
  }
235763
235762
  return comp;
235764
235763
  },
@@ -235779,6 +235778,21 @@ function wNAF(c3, bits) {
235779
235778
  }
235780
235779
  };
235781
235780
  }
235781
+ function mulEndoUnsafe(c3, point, k1, k22) {
235782
+ let acc = point;
235783
+ let p1 = c3.ZERO;
235784
+ let p22 = c3.ZERO;
235785
+ while (k1 > _0n4 || k22 > _0n4) {
235786
+ if (k1 & _1n4)
235787
+ p1 = p1.add(acc);
235788
+ if (k22 & _1n4)
235789
+ p22 = p22.add(acc);
235790
+ acc = acc.double();
235791
+ k1 >>= _1n4;
235792
+ k22 >>= _1n4;
235793
+ }
235794
+ return { p1, p2: p22 };
235795
+ }
235782
235796
  function pippenger(c3, fieldN, points, scalars) {
235783
235797
  validateMSMPoints(points, c3);
235784
235798
  validateMSMScalars(scalars, fieldN);
@@ -235818,27 +235832,38 @@ function pippenger(c3, fieldN, points, scalars) {
235818
235832
  }
235819
235833
  return sum;
235820
235834
  }
235821
- function validateBasic(curve) {
235822
- validateField(curve.Fp);
235823
- validateObject(curve, {
235824
- n: "bigint",
235825
- h: "bigint",
235826
- Gx: "field",
235827
- Gy: "field"
235828
- }, {
235829
- nBitLength: "isSafeInteger",
235830
- nByteLength: "isSafeInteger"
235831
- });
235832
- return Object.freeze({
235833
- ...nLength(curve.n, curve.nBitLength),
235834
- ...curve,
235835
- ...{ p: curve.Fp.ORDER }
235836
- });
235835
+ function createField(order, field2) {
235836
+ if (field2) {
235837
+ if (field2.ORDER !== order)
235838
+ throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
235839
+ validateField(field2);
235840
+ return field2;
235841
+ } else {
235842
+ return Field(order);
235843
+ }
235844
+ }
235845
+ function _createCurveFields(type4, CURVE, curveOpts = {}) {
235846
+ if (!CURVE || typeof CURVE !== "object")
235847
+ throw new Error(`expected valid ${type4} CURVE object`);
235848
+ for (const p5 of ["p", "n", "h"]) {
235849
+ const val = CURVE[p5];
235850
+ if (!(typeof val === "bigint" && val > _0n4))
235851
+ throw new Error(`CURVE.${p5} must be positive bigint`);
235852
+ }
235853
+ const Fp = createField(CURVE.p, curveOpts.Fp);
235854
+ const Fn = createField(CURVE.n, curveOpts.Fn);
235855
+ const _b = type4 === "weierstrass" ? "b" : "d";
235856
+ const params = ["Gx", "Gy", "a", _b];
235857
+ for (const p5 of params) {
235858
+ if (!Fp.isValid(CURVE[p5]))
235859
+ throw new Error(`CURVE.${p5} must be valid field element of CURVE.Fp`);
235860
+ }
235861
+ return { Fp, Fn };
235837
235862
  }
235838
235863
  var _0n4, _1n4, pointPrecomputes, pointWindowSizes;
235839
235864
  var init_curve = __esm(() => {
235840
- init_modular();
235841
235865
  init_utils3();
235866
+ init_modular();
235842
235867
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
235843
235868
  _0n4 = BigInt(0);
235844
235869
  _1n4 = BigInt(1);
@@ -235853,54 +235878,116 @@ function validateSigVerOpts(opts) {
235853
235878
  if (opts.prehash !== undefined)
235854
235879
  abool("prehash", opts.prehash);
235855
235880
  }
235856
- function validatePointOpts(curve) {
235857
- const opts = validateBasic(curve);
235858
- validateObject(opts, {
235859
- a: "field",
235860
- b: "field"
235861
- }, {
235881
+ function _legacyHelperEquat(Fp, a7, b4) {
235882
+ function weierstrassEquation(x6) {
235883
+ const x22 = Fp.sqr(x6);
235884
+ const x32 = Fp.mul(x22, x6);
235885
+ return Fp.add(Fp.add(x32, Fp.mul(x6, a7)), b4);
235886
+ }
235887
+ return weierstrassEquation;
235888
+ }
235889
+ function _legacyHelperNormPriv(Fn, allowedPrivateKeyLengths, wrapPrivateKey) {
235890
+ const { BYTES: expected } = Fn;
235891
+ function normPrivateKeyToScalar(key2) {
235892
+ let num;
235893
+ if (typeof key2 === "bigint") {
235894
+ num = key2;
235895
+ } else {
235896
+ let bytes = ensureBytes("private key", key2);
235897
+ if (allowedPrivateKeyLengths) {
235898
+ if (!allowedPrivateKeyLengths.includes(bytes.length * 2))
235899
+ throw new Error("invalid private key");
235900
+ const padded = new Uint8Array(expected);
235901
+ padded.set(bytes, padded.length - bytes.length);
235902
+ bytes = padded;
235903
+ }
235904
+ try {
235905
+ num = Fn.fromBytes(bytes);
235906
+ } catch (error44) {
235907
+ throw new Error(`invalid private key: expected ui8a of size ${expected}, got ${typeof key2}`);
235908
+ }
235909
+ }
235910
+ if (wrapPrivateKey)
235911
+ num = Fn.create(num);
235912
+ if (!Fn.isValidNot0(num))
235913
+ throw new Error("invalid private key: out of range [1..N-1]");
235914
+ return num;
235915
+ }
235916
+ return normPrivateKeyToScalar;
235917
+ }
235918
+ function weierstrassN(CURVE, curveOpts = {}) {
235919
+ const { Fp, Fn } = _createCurveFields("weierstrass", CURVE, curveOpts);
235920
+ const { h: cofactor, n: CURVE_ORDER } = CURVE;
235921
+ _validateObject(curveOpts, {}, {
235862
235922
  allowInfinityPoint: "boolean",
235863
- allowedPrivateKeyLengths: "array",
235864
235923
  clearCofactor: "function",
235865
- fromBytes: "function",
235866
235924
  isTorsionFree: "function",
235925
+ fromBytes: "function",
235867
235926
  toBytes: "function",
235927
+ endo: "object",
235868
235928
  wrapPrivateKey: "boolean"
235869
235929
  });
235870
- const { endo, Fp, a: a7 } = opts;
235930
+ const { endo } = curveOpts;
235871
235931
  if (endo) {
235872
- if (!Fp.eql(a7, Fp.ZERO)) {
235873
- throw new Error("invalid endo: CURVE.a must be 0");
235874
- }
235875
- if (typeof endo !== "object" || typeof endo.beta !== "bigint" || typeof endo.splitScalar !== "function") {
235932
+ if (!Fp.is0(CURVE.a) || typeof endo.beta !== "bigint" || typeof endo.splitScalar !== "function") {
235876
235933
  throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');
235877
235934
  }
235878
235935
  }
235879
- return Object.freeze({ ...opts });
235880
- }
235881
- function numToSizedHex(num, size2) {
235882
- return bytesToHex2(numberToBytesBE(num, size2));
235883
- }
235884
- function weierstrassPoints(opts) {
235885
- const CURVE = validatePointOpts(opts);
235886
- const { Fp } = CURVE;
235887
- const Fn = Field(CURVE.n, CURVE.nBitLength);
235888
- const toBytes3 = CURVE.toBytes || ((_c, point, _isCompressed) => {
235889
- const a7 = point.toAffine();
235890
- return concatBytes3(Uint8Array.from([4]), Fp.toBytes(a7.x), Fp.toBytes(a7.y));
235891
- });
235892
- const fromBytes = CURVE.fromBytes || ((bytes) => {
235936
+ function assertCompressionIsSupported() {
235937
+ if (!Fp.isOdd)
235938
+ throw new Error("compression is not supported: Field does not have .isOdd()");
235939
+ }
235940
+ function pointToBytes(_c, point, isCompressed) {
235941
+ const { x: x6, y: y4 } = point.toAffine();
235942
+ const bx = Fp.toBytes(x6);
235943
+ abool("isCompressed", isCompressed);
235944
+ if (isCompressed) {
235945
+ assertCompressionIsSupported();
235946
+ const hasEvenY = !Fp.isOdd(y4);
235947
+ return concatBytes(pprefix(hasEvenY), bx);
235948
+ } else {
235949
+ return concatBytes(Uint8Array.of(4), bx, Fp.toBytes(y4));
235950
+ }
235951
+ }
235952
+ function pointFromBytes(bytes) {
235953
+ abytes(bytes);
235954
+ const L5 = Fp.BYTES;
235955
+ const LC = L5 + 1;
235956
+ const LU = 2 * L5 + 1;
235957
+ const length = bytes.length;
235958
+ const head = bytes[0];
235893
235959
  const tail = bytes.subarray(1);
235894
- const x6 = Fp.fromBytes(tail.subarray(0, Fp.BYTES));
235895
- const y4 = Fp.fromBytes(tail.subarray(Fp.BYTES, 2 * Fp.BYTES));
235896
- return { x: x6, y: y4 };
235897
- });
235898
- function weierstrassEquation(x6) {
235899
- const { a: a7, b: b4 } = CURVE;
235900
- const x22 = Fp.sqr(x6);
235901
- const x32 = Fp.mul(x22, x6);
235902
- return Fp.add(Fp.add(x32, Fp.mul(x6, a7)), b4);
235960
+ if (length === LC && (head === 2 || head === 3)) {
235961
+ const x6 = Fp.fromBytes(tail);
235962
+ if (!Fp.isValid(x6))
235963
+ throw new Error("bad point: is not on curve, wrong x");
235964
+ const y22 = weierstrassEquation(x6);
235965
+ let y4;
235966
+ try {
235967
+ y4 = Fp.sqrt(y22);
235968
+ } catch (sqrtError) {
235969
+ const err = sqrtError instanceof Error ? ": " + sqrtError.message : "";
235970
+ throw new Error("bad point: is not on curve, sqrt error" + err);
235971
+ }
235972
+ assertCompressionIsSupported();
235973
+ const isYOdd = Fp.isOdd(y4);
235974
+ const isHeadOdd = (head & 1) === 1;
235975
+ if (isHeadOdd !== isYOdd)
235976
+ y4 = Fp.neg(y4);
235977
+ return { x: x6, y: y4 };
235978
+ } else if (length === LU && head === 4) {
235979
+ const x6 = Fp.fromBytes(tail.subarray(L5 * 0, L5 * 1));
235980
+ const y4 = Fp.fromBytes(tail.subarray(L5 * 1, L5 * 2));
235981
+ if (!isValidXY(x6, y4))
235982
+ throw new Error("bad point: is not on curve");
235983
+ return { x: x6, y: y4 };
235984
+ } else {
235985
+ throw new Error(`bad point: got length ${length}, expected compressed=${LC} or uncompressed=${LU}`);
235986
+ }
235903
235987
  }
235988
+ const toBytes3 = curveOpts.toBytes || pointToBytes;
235989
+ const fromBytes = curveOpts.fromBytes || pointFromBytes;
235990
+ const weierstrassEquation = _legacyHelperEquat(Fp, CURVE.a, CURVE.b);
235904
235991
  function isValidXY(x6, y4) {
235905
235992
  const left = Fp.sqr(y4);
235906
235993
  const right = weierstrassEquation(x6);
@@ -235912,28 +235999,10 @@ function weierstrassPoints(opts) {
235912
235999
  const _27b2 = Fp.mul(Fp.sqr(CURVE.b), BigInt(27));
235913
236000
  if (Fp.is0(Fp.add(_4a3, _27b2)))
235914
236001
  throw new Error("bad curve params: a or b");
235915
- function isWithinCurveOrder(num) {
235916
- return inRange(num, _1n5, CURVE.n);
235917
- }
235918
- function normPrivateKeyToScalar(key2) {
235919
- const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n: N6 } = CURVE;
235920
- if (lengths && typeof key2 !== "bigint") {
235921
- if (isBytes2(key2))
235922
- key2 = bytesToHex2(key2);
235923
- if (typeof key2 !== "string" || !lengths.includes(key2.length))
235924
- throw new Error("invalid private key");
235925
- key2 = key2.padStart(nByteLength * 2, "0");
235926
- }
235927
- let num;
235928
- try {
235929
- num = typeof key2 === "bigint" ? key2 : bytesToNumberBE(ensureBytes("private key", key2, nByteLength));
235930
- } catch (error44) {
235931
- throw new Error("invalid private key, expected hex or " + nByteLength + " bytes, got " + typeof key2);
235932
- }
235933
- if (wrapPrivateKey)
235934
- num = mod(num, N6);
235935
- aInRange("private key", num, _1n5, N6);
235936
- return num;
236002
+ function acoord(title, n6, banZero = false) {
236003
+ if (!Fp.isValid(n6) || banZero && Fp.is0(n6))
236004
+ throw new Error(`bad point coordinate ${title}`);
236005
+ return n6;
235937
236006
  }
235938
236007
  function aprjpoint(other) {
235939
236008
  if (!(other instanceof Point))
@@ -235957,31 +236026,31 @@ function weierstrassPoints(opts) {
235957
236026
  });
235958
236027
  const assertValidMemo = memoized((p5) => {
235959
236028
  if (p5.is0()) {
235960
- if (CURVE.allowInfinityPoint && !Fp.is0(p5.py))
236029
+ if (curveOpts.allowInfinityPoint && !Fp.is0(p5.py))
235961
236030
  return;
235962
236031
  throw new Error("bad point: ZERO");
235963
236032
  }
235964
236033
  const { x: x6, y: y4 } = p5.toAffine();
235965
236034
  if (!Fp.isValid(x6) || !Fp.isValid(y4))
235966
- throw new Error("bad point: x or y not FE");
236035
+ throw new Error("bad point: x or y not field elements");
235967
236036
  if (!isValidXY(x6, y4))
235968
236037
  throw new Error("bad point: equation left != right");
235969
236038
  if (!p5.isTorsionFree())
235970
236039
  throw new Error("bad point: not in prime-order subgroup");
235971
236040
  return true;
235972
236041
  });
236042
+ function finishEndo(endoBeta, k1p, k2p, k1neg, k2neg) {
236043
+ k2p = new Point(Fp.mul(k2p.px, endoBeta), k2p.py, k2p.pz);
236044
+ k1p = negateCt(k1neg, k1p);
236045
+ k2p = negateCt(k2neg, k2p);
236046
+ return k1p.add(k2p);
236047
+ }
235973
236048
 
235974
236049
  class Point {
235975
236050
  constructor(px, py, pz) {
235976
- if (px == null || !Fp.isValid(px))
235977
- throw new Error("x required");
235978
- if (py == null || !Fp.isValid(py) || Fp.is0(py))
235979
- throw new Error("y required");
235980
- if (pz == null || !Fp.isValid(pz))
235981
- throw new Error("z required");
235982
- this.px = px;
235983
- this.py = py;
235984
- this.pz = pz;
236051
+ this.px = acoord("x", px);
236052
+ this.py = acoord("y", py, true);
236053
+ this.pz = acoord("z", pz);
235985
236054
  Object.freeze(this);
235986
236055
  }
235987
236056
  static fromAffine(p5) {
@@ -235990,8 +236059,7 @@ function weierstrassPoints(opts) {
235990
236059
  throw new Error("invalid affine point");
235991
236060
  if (p5 instanceof Point)
235992
236061
  throw new Error("projective point not allowed");
235993
- const is0 = (i6) => Fp.eql(i6, Fp.ZERO);
235994
- if (is0(x6) && is0(y4))
236062
+ if (Fp.is0(x6) && Fp.is0(y4))
235995
236063
  return Point.ZERO;
235996
236064
  return new Point(x6, y4, Fp.ONE);
235997
236065
  }
@@ -236002,8 +236070,11 @@ function weierstrassPoints(opts) {
236002
236070
  return this.toAffine().y;
236003
236071
  }
236004
236072
  static normalizeZ(points) {
236005
- const toInv = FpInvertBatch(Fp, points.map((p5) => p5.pz));
236006
- return points.map((p5, i6) => p5.toAffine(toInv[i6])).map(Point.fromAffine);
236073
+ return normalizeZ(Point, "pz", points);
236074
+ }
236075
+ static fromBytes(bytes) {
236076
+ abytes(bytes);
236077
+ return Point.fromHex(bytes);
236007
236078
  }
236008
236079
  static fromHex(hex) {
236009
236080
  const P5 = Point.fromAffine(fromBytes(ensureBytes("pointHex", hex)));
@@ -236011,22 +236082,29 @@ function weierstrassPoints(opts) {
236011
236082
  return P5;
236012
236083
  }
236013
236084
  static fromPrivateKey(privateKey) {
236085
+ const normPrivateKeyToScalar = _legacyHelperNormPriv(Fn, curveOpts.allowedPrivateKeyLengths, curveOpts.wrapPrivateKey);
236014
236086
  return Point.BASE.multiply(normPrivateKeyToScalar(privateKey));
236015
236087
  }
236016
236088
  static msm(points, scalars) {
236017
236089
  return pippenger(Point, Fn, points, scalars);
236018
236090
  }
236019
- _setWindowSize(windowSize) {
236091
+ precompute(windowSize = 8, isLazy = true) {
236020
236092
  wnaf.setWindowSize(this, windowSize);
236093
+ if (!isLazy)
236094
+ this.multiply(_3n2);
236095
+ return this;
236096
+ }
236097
+ _setWindowSize(windowSize) {
236098
+ this.precompute(windowSize);
236021
236099
  }
236022
236100
  assertValidity() {
236023
236101
  assertValidMemo(this);
236024
236102
  }
236025
236103
  hasEvenY() {
236026
236104
  const { y: y4 } = this.toAffine();
236027
- if (Fp.isOdd)
236028
- return !Fp.isOdd(y4);
236029
- throw new Error("Field doesn't support isOdd");
236105
+ if (!Fp.isOdd)
236106
+ throw new Error("Field doesn't support isOdd");
236107
+ return !Fp.isOdd(y4);
236030
236108
  }
236031
236109
  equals(other) {
236032
236110
  aprjpoint(other);
@@ -236132,188 +236210,121 @@ function weierstrassPoints(opts) {
236132
236210
  is0() {
236133
236211
  return this.equals(Point.ZERO);
236134
236212
  }
236135
- wNAF(n6) {
236136
- return wnaf.wNAFCached(this, n6, Point.normalizeZ);
236137
- }
236138
- multiplyUnsafe(sc) {
236139
- const { endo: endo2, n: N6 } = CURVE;
236140
- aInRange("scalar", sc, _0n5, N6);
236141
- const I6 = Point.ZERO;
236142
- if (sc === _0n5)
236143
- return I6;
236144
- if (this.is0() || sc === _1n5)
236145
- return this;
236146
- if (!endo2 || wnaf.hasPrecomputes(this))
236147
- return wnaf.wNAFCachedUnsafe(this, sc, Point.normalizeZ);
236148
- let { k1neg, k1, k2neg, k2: k22 } = endo2.splitScalar(sc);
236149
- let k1p = I6;
236150
- let k2p = I6;
236151
- let d6 = this;
236152
- while (k1 > _0n5 || k22 > _0n5) {
236153
- if (k1 & _1n5)
236154
- k1p = k1p.add(d6);
236155
- if (k22 & _1n5)
236156
- k2p = k2p.add(d6);
236157
- d6 = d6.double();
236158
- k1 >>= _1n5;
236159
- k22 >>= _1n5;
236160
- }
236161
- if (k1neg)
236162
- k1p = k1p.negate();
236163
- if (k2neg)
236164
- k2p = k2p.negate();
236165
- k2p = new Point(Fp.mul(k2p.px, endo2.beta), k2p.py, k2p.pz);
236166
- return k1p.add(k2p);
236167
- }
236168
236213
  multiply(scalar) {
236169
- const { endo: endo2, n: N6 } = CURVE;
236170
- aInRange("scalar", scalar, _1n5, N6);
236214
+ const { endo: endo2 } = curveOpts;
236215
+ if (!Fn.isValidNot0(scalar))
236216
+ throw new Error("invalid scalar: out of range");
236171
236217
  let point, fake;
236218
+ const mul = (n6) => wnaf.wNAFCached(this, n6, Point.normalizeZ);
236172
236219
  if (endo2) {
236173
236220
  const { k1neg, k1, k2neg, k2: k22 } = endo2.splitScalar(scalar);
236174
- let { p: k1p, f: f1p } = this.wNAF(k1);
236175
- let { p: k2p, f: f2p } = this.wNAF(k22);
236176
- k1p = wnaf.constTimeNegate(k1neg, k1p);
236177
- k2p = wnaf.constTimeNegate(k2neg, k2p);
236178
- k2p = new Point(Fp.mul(k2p.px, endo2.beta), k2p.py, k2p.pz);
236179
- point = k1p.add(k2p);
236180
- fake = f1p.add(f2p);
236221
+ const { p: k1p, f: k1f } = mul(k1);
236222
+ const { p: k2p, f: k2f } = mul(k22);
236223
+ fake = k1f.add(k2f);
236224
+ point = finishEndo(endo2.beta, k1p, k2p, k1neg, k2neg);
236181
236225
  } else {
236182
- const { p: p5, f: f5 } = this.wNAF(scalar);
236226
+ const { p: p5, f: f5 } = mul(scalar);
236183
236227
  point = p5;
236184
236228
  fake = f5;
236185
236229
  }
236186
236230
  return Point.normalizeZ([point, fake])[0];
236187
236231
  }
236232
+ multiplyUnsafe(sc) {
236233
+ const { endo: endo2 } = curveOpts;
236234
+ const p5 = this;
236235
+ if (!Fn.isValid(sc))
236236
+ throw new Error("invalid scalar: out of range");
236237
+ if (sc === _0n5 || p5.is0())
236238
+ return Point.ZERO;
236239
+ if (sc === _1n5)
236240
+ return p5;
236241
+ if (wnaf.hasPrecomputes(this))
236242
+ return this.multiply(sc);
236243
+ if (endo2) {
236244
+ const { k1neg, k1, k2neg, k2: k22 } = endo2.splitScalar(sc);
236245
+ const { p1, p2: p22 } = mulEndoUnsafe(Point, p5, k1, k22);
236246
+ return finishEndo(endo2.beta, p1, p22, k1neg, k2neg);
236247
+ } else {
236248
+ return wnaf.wNAFCachedUnsafe(p5, sc);
236249
+ }
236250
+ }
236188
236251
  multiplyAndAddUnsafe(Q4, a7, b4) {
236189
- const G4 = Point.BASE;
236190
- const mul = (P5, a8) => a8 === _0n5 || a8 === _1n5 || !P5.equals(G4) ? P5.multiplyUnsafe(a8) : P5.multiply(a8);
236191
- const sum = mul(this, a7).add(mul(Q4, b4));
236252
+ const sum = this.multiplyUnsafe(a7).add(Q4.multiplyUnsafe(b4));
236192
236253
  return sum.is0() ? undefined : sum;
236193
236254
  }
236194
- toAffine(iz) {
236195
- return toAffineMemo(this, iz);
236255
+ toAffine(invertedZ) {
236256
+ return toAffineMemo(this, invertedZ);
236196
236257
  }
236197
236258
  isTorsionFree() {
236198
- const { h: cofactor, isTorsionFree } = CURVE;
236259
+ const { isTorsionFree } = curveOpts;
236199
236260
  if (cofactor === _1n5)
236200
236261
  return true;
236201
236262
  if (isTorsionFree)
236202
236263
  return isTorsionFree(Point, this);
236203
- throw new Error("isTorsionFree() has not been declared for the elliptic curve");
236264
+ return wnaf.wNAFCachedUnsafe(this, CURVE_ORDER).is0();
236204
236265
  }
236205
236266
  clearCofactor() {
236206
- const { h: cofactor, clearCofactor } = CURVE;
236267
+ const { clearCofactor } = curveOpts;
236207
236268
  if (cofactor === _1n5)
236208
236269
  return this;
236209
236270
  if (clearCofactor)
236210
236271
  return clearCofactor(Point, this);
236211
- return this.multiplyUnsafe(CURVE.h);
236272
+ return this.multiplyUnsafe(cofactor);
236212
236273
  }
236213
- toRawBytes(isCompressed = true) {
236274
+ toBytes(isCompressed = true) {
236214
236275
  abool("isCompressed", isCompressed);
236215
236276
  this.assertValidity();
236216
236277
  return toBytes3(Point, this, isCompressed);
236217
236278
  }
236279
+ toRawBytes(isCompressed = true) {
236280
+ return this.toBytes(isCompressed);
236281
+ }
236218
236282
  toHex(isCompressed = true) {
236219
- abool("isCompressed", isCompressed);
236220
- return bytesToHex2(this.toRawBytes(isCompressed));
236283
+ return bytesToHex2(this.toBytes(isCompressed));
236284
+ }
236285
+ toString() {
236286
+ return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
236221
236287
  }
236222
236288
  }
236223
236289
  Point.BASE = new Point(CURVE.Gx, CURVE.Gy, Fp.ONE);
236224
236290
  Point.ZERO = new Point(Fp.ZERO, Fp.ONE, Fp.ZERO);
236225
- const { endo, nBitLength } = CURVE;
236226
- const wnaf = wNAF(Point, endo ? Math.ceil(nBitLength / 2) : nBitLength);
236227
- return {
236228
- CURVE,
236229
- ProjectivePoint: Point,
236230
- normPrivateKeyToScalar,
236231
- weierstrassEquation,
236232
- isWithinCurveOrder
236233
- };
236291
+ Point.Fp = Fp;
236292
+ Point.Fn = Fn;
236293
+ const bits = Fn.BITS;
236294
+ const wnaf = wNAF(Point, curveOpts.endo ? Math.ceil(bits / 2) : bits);
236295
+ return Point;
236296
+ }
236297
+ function pprefix(hasEvenY) {
236298
+ return Uint8Array.of(hasEvenY ? 2 : 3);
236234
236299
  }
236235
- function validateOpts(curve) {
236236
- const opts = validateBasic(curve);
236237
- validateObject(opts, {
236238
- hash: "hash",
236300
+ function ecdsa(Point, ecdsaOpts, curveOpts = {}) {
236301
+ _validateObject(ecdsaOpts, { hash: "function" }, {
236239
236302
  hmac: "function",
236240
- randomBytes: "function"
236241
- }, {
236303
+ lowS: "boolean",
236304
+ randomBytes: "function",
236242
236305
  bits2int: "function",
236243
- bits2int_modN: "function",
236244
- lowS: "boolean"
236245
- });
236246
- return Object.freeze({ lowS: true, ...opts });
236247
- }
236248
- function weierstrass(curveDef) {
236249
- const CURVE = validateOpts(curveDef);
236250
- const { Fp, n: CURVE_ORDER, nByteLength, nBitLength } = CURVE;
236251
- const compressedLen = Fp.BYTES + 1;
236252
- const uncompressedLen = 2 * Fp.BYTES + 1;
236253
- function modN(a7) {
236254
- return mod(a7, CURVE_ORDER);
236255
- }
236256
- function invN(a7) {
236257
- return invert(a7, CURVE_ORDER);
236258
- }
236259
- const { ProjectivePoint: Point, normPrivateKeyToScalar, weierstrassEquation, isWithinCurveOrder } = weierstrassPoints({
236260
- ...CURVE,
236261
- toBytes(_c, point, isCompressed) {
236262
- const a7 = point.toAffine();
236263
- const x6 = Fp.toBytes(a7.x);
236264
- const cat = concatBytes3;
236265
- abool("isCompressed", isCompressed);
236266
- if (isCompressed) {
236267
- return cat(Uint8Array.from([point.hasEvenY() ? 2 : 3]), x6);
236268
- } else {
236269
- return cat(Uint8Array.from([4]), x6, Fp.toBytes(a7.y));
236270
- }
236271
- },
236272
- fromBytes(bytes) {
236273
- const len = bytes.length;
236274
- const head = bytes[0];
236275
- const tail = bytes.subarray(1);
236276
- if (len === compressedLen && (head === 2 || head === 3)) {
236277
- const x6 = bytesToNumberBE(tail);
236278
- if (!inRange(x6, _1n5, Fp.ORDER))
236279
- throw new Error("Point is not on curve");
236280
- const y22 = weierstrassEquation(x6);
236281
- let y4;
236282
- try {
236283
- y4 = Fp.sqrt(y22);
236284
- } catch (sqrtError) {
236285
- const suffix = sqrtError instanceof Error ? ": " + sqrtError.message : "";
236286
- throw new Error("Point is not on curve" + suffix);
236287
- }
236288
- const isYOdd = (y4 & _1n5) === _1n5;
236289
- const isHeadOdd = (head & 1) === 1;
236290
- if (isHeadOdd !== isYOdd)
236291
- y4 = Fp.neg(y4);
236292
- return { x: x6, y: y4 };
236293
- } else if (len === uncompressedLen && head === 4) {
236294
- const x6 = Fp.fromBytes(tail.subarray(0, Fp.BYTES));
236295
- const y4 = Fp.fromBytes(tail.subarray(Fp.BYTES, 2 * Fp.BYTES));
236296
- return { x: x6, y: y4 };
236297
- } else {
236298
- const cl = compressedLen;
236299
- const ul = uncompressedLen;
236300
- throw new Error("invalid Point, expected length of " + cl + ", or uncompressed " + ul + ", got " + len);
236301
- }
236302
- }
236306
+ bits2int_modN: "function"
236303
236307
  });
236308
+ const randomBytes_ = ecdsaOpts.randomBytes || randomBytes;
236309
+ const hmac_ = ecdsaOpts.hmac || ((key2, ...msgs) => hmac(ecdsaOpts.hash, key2, concatBytes(...msgs)));
236310
+ const { Fp, Fn } = Point;
236311
+ const { ORDER: CURVE_ORDER, BITS: fnBits } = Fn;
236304
236312
  function isBiggerThanHalfOrder(number6) {
236305
236313
  const HALF = CURVE_ORDER >> _1n5;
236306
236314
  return number6 > HALF;
236307
236315
  }
236308
236316
  function normalizeS(s7) {
236309
- return isBiggerThanHalfOrder(s7) ? modN(-s7) : s7;
236317
+ return isBiggerThanHalfOrder(s7) ? Fn.neg(s7) : s7;
236318
+ }
236319
+ function aValidRS(title, num) {
236320
+ if (!Fn.isValidNot0(num))
236321
+ throw new Error(`invalid signature ${title}: out of range 1..CURVE.n`);
236310
236322
  }
236311
- const slcNum = (b4, from, to) => bytesToNumberBE(b4.slice(from, to));
236312
236323
 
236313
236324
  class Signature {
236314
236325
  constructor(r6, s7, recovery) {
236315
- aInRange("r", r6, _1n5, CURVE_ORDER);
236316
- aInRange("s", s7, _1n5, CURVE_ORDER);
236326
+ aValidRS("r", r6);
236327
+ aValidRS("s", s7);
236317
236328
  this.r = r6;
236318
236329
  this.s = s7;
236319
236330
  if (recovery != null)
@@ -236321,9 +236332,9 @@ function weierstrass(curveDef) {
236321
236332
  Object.freeze(this);
236322
236333
  }
236323
236334
  static fromCompact(hex) {
236324
- const l3 = nByteLength;
236325
- hex = ensureBytes("compactSignature", hex, l3 * 2);
236326
- return new Signature(slcNum(hex, 0, l3), slcNum(hex, l3, 2 * l3));
236335
+ const L5 = Fn.BYTES;
236336
+ const b4 = ensureBytes("compactSignature", hex, L5 * 2);
236337
+ return new Signature(Fn.fromBytes(b4.subarray(0, L5)), Fn.fromBytes(b4.subarray(L5, L5 * 2)));
236327
236338
  }
236328
236339
  static fromDER(hex) {
236329
236340
  const { r: r6, s: s7 } = DER.toSig(ensureBytes("DER", hex));
@@ -236334,20 +236345,24 @@ function weierstrass(curveDef) {
236334
236345
  return new Signature(this.r, this.s, recovery);
236335
236346
  }
236336
236347
  recoverPublicKey(msgHash) {
236348
+ const FIELD_ORDER = Fp.ORDER;
236337
236349
  const { r: r6, s: s7, recovery: rec } = this;
236338
- const h8 = bits2int_modN(ensureBytes("msgHash", msgHash));
236339
236350
  if (rec == null || ![0, 1, 2, 3].includes(rec))
236340
236351
  throw new Error("recovery id invalid");
236341
- const radj = rec === 2 || rec === 3 ? r6 + CURVE.n : r6;
236342
- if (radj >= Fp.ORDER)
236352
+ const hasCofactor = CURVE_ORDER * _2n3 < FIELD_ORDER;
236353
+ if (hasCofactor && rec > 1)
236354
+ throw new Error("recovery id is ambiguous for h>1 curve");
236355
+ const radj = rec === 2 || rec === 3 ? r6 + CURVE_ORDER : r6;
236356
+ if (!Fp.isValid(radj))
236343
236357
  throw new Error("recovery id 2 or 3 invalid");
236344
- const prefix = (rec & 1) === 0 ? "02" : "03";
236345
- const R7 = Point.fromHex(prefix + numToSizedHex(radj, Fp.BYTES));
236346
- const ir2 = invN(radj);
236347
- const u1 = modN(-h8 * ir2);
236348
- const u22 = modN(s7 * ir2);
236349
- const Q4 = Point.BASE.multiplyAndAddUnsafe(R7, u1, u22);
236350
- if (!Q4)
236358
+ const x6 = Fp.toBytes(radj);
236359
+ const R7 = Point.fromHex(concatBytes(pprefix((rec & 1) === 0), x6));
236360
+ const ir2 = Fn.inv(radj);
236361
+ const h8 = bits2int_modN(ensureBytes("msgHash", msgHash));
236362
+ const u1 = Fn.create(-h8 * ir2);
236363
+ const u22 = Fn.create(s7 * ir2);
236364
+ const Q4 = Point.BASE.multiplyUnsafe(u1).add(R7.multiplyUnsafe(u22));
236365
+ if (Q4.is0())
236351
236366
  throw new Error("point at infinify");
236352
236367
  Q4.assertValidity();
236353
236368
  return Q4;
@@ -236356,22 +236371,29 @@ function weierstrass(curveDef) {
236356
236371
  return isBiggerThanHalfOrder(this.s);
236357
236372
  }
236358
236373
  normalizeS() {
236359
- return this.hasHighS() ? new Signature(this.r, modN(-this.s), this.recovery) : this;
236374
+ return this.hasHighS() ? new Signature(this.r, Fn.neg(this.s), this.recovery) : this;
236375
+ }
236376
+ toBytes(format2) {
236377
+ if (format2 === "compact")
236378
+ return concatBytes(Fn.toBytes(this.r), Fn.toBytes(this.s));
236379
+ if (format2 === "der")
236380
+ return hexToBytes2(DER.hexFromSig(this));
236381
+ throw new Error("invalid format");
236360
236382
  }
236361
236383
  toDERRawBytes() {
236362
- return hexToBytes2(this.toDERHex());
236384
+ return this.toBytes("der");
236363
236385
  }
236364
236386
  toDERHex() {
236365
- return DER.hexFromSig(this);
236387
+ return bytesToHex2(this.toBytes("der"));
236366
236388
  }
236367
236389
  toCompactRawBytes() {
236368
- return hexToBytes2(this.toCompactHex());
236390
+ return this.toBytes("compact");
236369
236391
  }
236370
236392
  toCompactHex() {
236371
- const l3 = nByteLength;
236372
- return numToSizedHex(this.r, l3) + numToSizedHex(this.s, l3);
236393
+ return bytesToHex2(this.toBytes("compact"));
236373
236394
  }
236374
236395
  }
236396
+ const normPrivateKeyToScalar = _legacyHelperNormPriv(Fn, curveOpts.allowedPrivateKeyLengths, curveOpts.wrapPrivateKey);
236375
236397
  const utils = {
236376
236398
  isValidPrivateKey(privateKey) {
236377
236399
  try {
@@ -236383,17 +236405,15 @@ function weierstrass(curveDef) {
236383
236405
  },
236384
236406
  normPrivateKeyToScalar,
236385
236407
  randomPrivateKey: () => {
236386
- const length = getMinHashLength(CURVE.n);
236387
- return mapHashToField(CURVE.randomBytes(length), CURVE.n);
236408
+ const n6 = CURVE_ORDER;
236409
+ return mapHashToField(randomBytes_(getMinHashLength(n6)), n6);
236388
236410
  },
236389
236411
  precompute(windowSize = 8, point = Point.BASE) {
236390
- point._setWindowSize(windowSize);
236391
- point.multiply(BigInt(3));
236392
- return point;
236412
+ return point.precompute(windowSize, false);
236393
236413
  }
236394
236414
  };
236395
236415
  function getPublicKey(privateKey, isCompressed = true) {
236396
- return Point.fromPrivateKey(privateKey).toRawBytes(isCompressed);
236416
+ return Point.fromPrivateKey(privateKey).toBytes(isCompressed);
236397
236417
  }
236398
236418
  function isProbPub(item) {
236399
236419
  if (typeof item === "bigint")
@@ -236401,14 +236421,14 @@ function weierstrass(curveDef) {
236401
236421
  if (item instanceof Point)
236402
236422
  return true;
236403
236423
  const arr = ensureBytes("key", item);
236404
- const len = arr.length;
236405
- const fpl = Fp.BYTES;
236406
- const compLen = fpl + 1;
236407
- const uncompLen = 2 * fpl + 1;
236408
- if (CURVE.allowedPrivateKeyLengths || nByteLength === compLen) {
236424
+ const length = arr.length;
236425
+ const L5 = Fp.BYTES;
236426
+ const LC = L5 + 1;
236427
+ const LU = 2 * L5 + 1;
236428
+ if (curveOpts.allowedPrivateKeyLengths || Fn.BYTES === LC) {
236409
236429
  return;
236410
236430
  } else {
236411
- return len === compLen || len === uncompLen;
236431
+ return length === LC || length === LU;
236412
236432
  }
236413
236433
  }
236414
236434
  function getSharedSecret(privateA, publicB, isCompressed = true) {
@@ -236417,27 +236437,27 @@ function weierstrass(curveDef) {
236417
236437
  if (isProbPub(publicB) === false)
236418
236438
  throw new Error("second arg must be public key");
236419
236439
  const b4 = Point.fromHex(publicB);
236420
- return b4.multiply(normPrivateKeyToScalar(privateA)).toRawBytes(isCompressed);
236440
+ return b4.multiply(normPrivateKeyToScalar(privateA)).toBytes(isCompressed);
236421
236441
  }
236422
- const bits2int = CURVE.bits2int || function(bytes) {
236442
+ const bits2int = ecdsaOpts.bits2int || function(bytes) {
236423
236443
  if (bytes.length > 8192)
236424
236444
  throw new Error("input is too large");
236425
236445
  const num = bytesToNumberBE(bytes);
236426
- const delta = bytes.length * 8 - nBitLength;
236446
+ const delta = bytes.length * 8 - fnBits;
236427
236447
  return delta > 0 ? num >> BigInt(delta) : num;
236428
236448
  };
236429
- const bits2int_modN = CURVE.bits2int_modN || function(bytes) {
236430
- return modN(bits2int(bytes));
236449
+ const bits2int_modN = ecdsaOpts.bits2int_modN || function(bytes) {
236450
+ return Fn.create(bits2int(bytes));
236431
236451
  };
236432
- const ORDER_MASK = bitMask(nBitLength);
236452
+ const ORDER_MASK = bitMask(fnBits);
236433
236453
  function int2octets(num) {
236434
- aInRange("num < 2^" + nBitLength, num, _0n5, ORDER_MASK);
236435
- return numberToBytesBE(num, nByteLength);
236454
+ aInRange("num < 2^" + fnBits, num, _0n5, ORDER_MASK);
236455
+ return Fn.toBytes(num);
236436
236456
  }
236437
236457
  function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
236438
236458
  if (["recovered", "canonical"].some((k5) => (k5 in opts)))
236439
236459
  throw new Error("sign() legacy options not supported");
236440
- const { hash: hash2, randomBytes: randomBytes2 } = CURVE;
236460
+ const { hash: hash2 } = ecdsaOpts;
236441
236461
  let { lowS, prehash, extraEntropy: ent } = opts;
236442
236462
  if (lowS == null)
236443
236463
  lowS = true;
@@ -236449,21 +236469,21 @@ function weierstrass(curveDef) {
236449
236469
  const d6 = normPrivateKeyToScalar(privateKey);
236450
236470
  const seedArgs = [int2octets(d6), int2octets(h1int)];
236451
236471
  if (ent != null && ent !== false) {
236452
- const e10 = ent === true ? randomBytes2(Fp.BYTES) : ent;
236472
+ const e10 = ent === true ? randomBytes_(Fp.BYTES) : ent;
236453
236473
  seedArgs.push(ensureBytes("extraEntropy", e10));
236454
236474
  }
236455
- const seed = concatBytes3(...seedArgs);
236475
+ const seed = concatBytes(...seedArgs);
236456
236476
  const m7 = h1int;
236457
236477
  function k2sig(kBytes) {
236458
236478
  const k5 = bits2int(kBytes);
236459
- if (!isWithinCurveOrder(k5))
236479
+ if (!Fn.isValidNot0(k5))
236460
236480
  return;
236461
- const ik = invN(k5);
236481
+ const ik = Fn.inv(k5);
236462
236482
  const q6 = Point.BASE.multiply(k5).toAffine();
236463
- const r6 = modN(q6.x);
236483
+ const r6 = Fn.create(q6.x);
236464
236484
  if (r6 === _0n5)
236465
236485
  return;
236466
- const s7 = modN(ik * modN(m7 + r6 * d6));
236486
+ const s7 = Fn.create(ik * Fn.create(m7 + r6 * d6));
236467
236487
  if (s7 === _0n5)
236468
236488
  return;
236469
236489
  let recovery = (q6.x === r6 ? 0 : 2) | Number(q6.y & _1n5);
@@ -236476,34 +236496,38 @@ function weierstrass(curveDef) {
236476
236496
  }
236477
236497
  return { seed, k2sig };
236478
236498
  }
236479
- const defaultSigOpts = { lowS: CURVE.lowS, prehash: false };
236480
- const defaultVerOpts = { lowS: CURVE.lowS, prehash: false };
236499
+ const defaultSigOpts = { lowS: ecdsaOpts.lowS, prehash: false };
236500
+ const defaultVerOpts = { lowS: ecdsaOpts.lowS, prehash: false };
236481
236501
  function sign(msgHash, privKey, opts = defaultSigOpts) {
236482
236502
  const { seed, k2sig } = prepSig(msgHash, privKey, opts);
236483
- const C4 = CURVE;
236484
- const drbg = createHmacDrbg(C4.hash.outputLen, C4.nByteLength, C4.hmac);
236503
+ const drbg = createHmacDrbg(ecdsaOpts.hash.outputLen, Fn.BYTES, hmac_);
236485
236504
  return drbg(seed, k2sig);
236486
236505
  }
236487
- Point.BASE._setWindowSize(8);
236506
+ Point.BASE.precompute(8);
236488
236507
  function verify(signature, msgHash, publicKey, opts = defaultVerOpts) {
236489
236508
  const sg = signature;
236490
236509
  msgHash = ensureBytes("msgHash", msgHash);
236491
236510
  publicKey = ensureBytes("publicKey", publicKey);
236492
- const { lowS, prehash, format: format2 } = opts;
236493
236511
  validateSigVerOpts(opts);
236512
+ const { lowS, prehash, format: format2 } = opts;
236494
236513
  if ("strict" in opts)
236495
236514
  throw new Error("options.strict was renamed to lowS");
236496
- if (format2 !== undefined && format2 !== "compact" && format2 !== "der")
236497
- throw new Error("format must be compact or der");
236498
- const isHex2 = typeof sg === "string" || isBytes2(sg);
236515
+ if (format2 !== undefined && !["compact", "der", "js"].includes(format2))
236516
+ throw new Error('format must be "compact", "der" or "js"');
236517
+ const isHex2 = typeof sg === "string" || isBytes(sg);
236499
236518
  const isObj = !isHex2 && !format2 && typeof sg === "object" && sg !== null && typeof sg.r === "bigint" && typeof sg.s === "bigint";
236500
236519
  if (!isHex2 && !isObj)
236501
236520
  throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
236502
236521
  let _sig = undefined;
236503
236522
  let P5;
236504
236523
  try {
236505
- if (isObj)
236506
- _sig = new Signature(sg.r, sg.s);
236524
+ if (isObj) {
236525
+ if (format2 === undefined || format2 === "js") {
236526
+ _sig = new Signature(sg.r, sg.s);
236527
+ } else {
236528
+ throw new Error("invalid format");
236529
+ }
236530
+ }
236507
236531
  if (isHex2) {
236508
236532
  try {
236509
236533
  if (format2 !== "compact")
@@ -236524,28 +236548,77 @@ function weierstrass(curveDef) {
236524
236548
  if (lowS && _sig.hasHighS())
236525
236549
  return false;
236526
236550
  if (prehash)
236527
- msgHash = CURVE.hash(msgHash);
236551
+ msgHash = ecdsaOpts.hash(msgHash);
236528
236552
  const { r: r6, s: s7 } = _sig;
236529
236553
  const h8 = bits2int_modN(msgHash);
236530
- const is = invN(s7);
236531
- const u1 = modN(h8 * is);
236532
- const u22 = modN(r6 * is);
236533
- const R7 = Point.BASE.multiplyAndAddUnsafe(P5, u1, u22)?.toAffine();
236534
- if (!R7)
236554
+ const is = Fn.inv(s7);
236555
+ const u1 = Fn.create(h8 * is);
236556
+ const u22 = Fn.create(r6 * is);
236557
+ const R7 = Point.BASE.multiplyUnsafe(u1).add(P5.multiplyUnsafe(u22));
236558
+ if (R7.is0())
236535
236559
  return false;
236536
- const v6 = modN(R7.x);
236560
+ const v6 = Fn.create(R7.x);
236537
236561
  return v6 === r6;
236538
236562
  }
236539
- return {
236540
- CURVE,
236563
+ return Object.freeze({
236541
236564
  getPublicKey,
236542
236565
  getSharedSecret,
236543
236566
  sign,
236544
236567
  verify,
236545
- ProjectivePoint: Point,
236546
- Signature,
236547
- utils
236548
- };
236568
+ utils,
236569
+ Point,
236570
+ Signature
236571
+ });
236572
+ }
236573
+ function _weierstrass_legacy_opts_to_new(c3) {
236574
+ const CURVE = {
236575
+ a: c3.a,
236576
+ b: c3.b,
236577
+ p: c3.Fp.ORDER,
236578
+ n: c3.n,
236579
+ h: c3.h,
236580
+ Gx: c3.Gx,
236581
+ Gy: c3.Gy
236582
+ };
236583
+ const Fp = c3.Fp;
236584
+ const Fn = Field(CURVE.n, c3.nBitLength);
236585
+ const curveOpts = {
236586
+ Fp,
236587
+ Fn,
236588
+ allowedPrivateKeyLengths: c3.allowedPrivateKeyLengths,
236589
+ allowInfinityPoint: c3.allowInfinityPoint,
236590
+ endo: c3.endo,
236591
+ wrapPrivateKey: c3.wrapPrivateKey,
236592
+ isTorsionFree: c3.isTorsionFree,
236593
+ clearCofactor: c3.clearCofactor,
236594
+ fromBytes: c3.fromBytes,
236595
+ toBytes: c3.toBytes
236596
+ };
236597
+ return { CURVE, curveOpts };
236598
+ }
236599
+ function _ecdsa_legacy_opts_to_new(c3) {
236600
+ const { CURVE, curveOpts } = _weierstrass_legacy_opts_to_new(c3);
236601
+ const ecdsaOpts = {
236602
+ hash: c3.hash,
236603
+ hmac: c3.hmac,
236604
+ randomBytes: c3.randomBytes,
236605
+ lowS: c3.lowS,
236606
+ bits2int: c3.bits2int,
236607
+ bits2int_modN: c3.bits2int_modN
236608
+ };
236609
+ return { CURVE, curveOpts, ecdsaOpts };
236610
+ }
236611
+ function _ecdsa_new_output_to_legacy(c3, ecdsa2) {
236612
+ return Object.assign({}, ecdsa2, {
236613
+ ProjectivePoint: ecdsa2.Point,
236614
+ CURVE: c3
236615
+ });
236616
+ }
236617
+ function weierstrass(c3) {
236618
+ const { CURVE, curveOpts, ecdsaOpts } = _ecdsa_legacy_opts_to_new(c3);
236619
+ const Point = weierstrassN(CURVE, curveOpts);
236620
+ const signs = ecdsa(Point, ecdsaOpts, curveOpts);
236621
+ return _ecdsa_new_output_to_legacy(c3, signs);
236549
236622
  }
236550
236623
  function SWUFpSqrtRatio(Fp, Z4) {
236551
236624
  const q6 = Fp.ORDER;
@@ -236611,28 +236684,29 @@ function SWUFpSqrtRatio(Fp, Z4) {
236611
236684
  }
236612
236685
  function mapToCurveSimpleSWU(Fp, opts) {
236613
236686
  validateField(Fp);
236614
- if (!Fp.isValid(opts.A) || !Fp.isValid(opts.B) || !Fp.isValid(opts.Z))
236687
+ const { A: A5, B: B4, Z: Z4 } = opts;
236688
+ if (!Fp.isValid(A5) || !Fp.isValid(B4) || !Fp.isValid(Z4))
236615
236689
  throw new Error("mapToCurveSimpleSWU: invalid opts");
236616
- const sqrtRatio = SWUFpSqrtRatio(Fp, opts.Z);
236690
+ const sqrtRatio = SWUFpSqrtRatio(Fp, Z4);
236617
236691
  if (!Fp.isOdd)
236618
- throw new Error("Fp.isOdd is not implemented!");
236692
+ throw new Error("Field does not have .isOdd()");
236619
236693
  return (u6) => {
236620
236694
  let tv1, tv2, tv3, tv4, tv5, tv6, x6, y4;
236621
236695
  tv1 = Fp.sqr(u6);
236622
- tv1 = Fp.mul(tv1, opts.Z);
236696
+ tv1 = Fp.mul(tv1, Z4);
236623
236697
  tv2 = Fp.sqr(tv1);
236624
236698
  tv2 = Fp.add(tv2, tv1);
236625
236699
  tv3 = Fp.add(tv2, Fp.ONE);
236626
- tv3 = Fp.mul(tv3, opts.B);
236627
- tv4 = Fp.cmov(opts.Z, Fp.neg(tv2), !Fp.eql(tv2, Fp.ZERO));
236628
- tv4 = Fp.mul(tv4, opts.A);
236700
+ tv3 = Fp.mul(tv3, B4);
236701
+ tv4 = Fp.cmov(Z4, Fp.neg(tv2), !Fp.eql(tv2, Fp.ZERO));
236702
+ tv4 = Fp.mul(tv4, A5);
236629
236703
  tv2 = Fp.sqr(tv3);
236630
236704
  tv6 = Fp.sqr(tv4);
236631
- tv5 = Fp.mul(tv6, opts.A);
236705
+ tv5 = Fp.mul(tv6, A5);
236632
236706
  tv2 = Fp.add(tv2, tv5);
236633
236707
  tv2 = Fp.mul(tv2, tv3);
236634
236708
  tv6 = Fp.mul(tv6, tv4);
236635
- tv5 = Fp.mul(tv6, opts.B);
236709
+ tv5 = Fp.mul(tv6, B4);
236636
236710
  tv2 = Fp.add(tv2, tv5);
236637
236711
  x6 = Fp.mul(tv1, tv3);
236638
236712
  const { isValid, value: value4 } = sqrtRatio(tv2, tv6);
@@ -236649,9 +236723,10 @@ function mapToCurveSimpleSWU(Fp, opts) {
236649
236723
  }
236650
236724
  var DERErr, DER, _0n5, _1n5, _2n3, _3n2, _4n2;
236651
236725
  var init_weierstrass = __esm(() => {
236726
+ init_hmac();
236727
+ init_utils3();
236652
236728
  init_curve();
236653
236729
  init_modular();
236654
- init_utils3();
236655
236730
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
236656
236731
  DERErr = class DERErr extends Error {
236657
236732
  constructor(m7 = "") {
@@ -236759,20 +236834,11 @@ var init_weierstrass = __esm(() => {
236759
236834
  });
236760
236835
 
236761
236836
  // ../../node_modules/@noble/curves/esm/_shortw_utils.js
236762
- function getHash(hash2) {
236763
- return {
236764
- hash: hash2,
236765
- hmac: (key2, ...msgs) => hmac(hash2, key2, concatBytes(...msgs)),
236766
- randomBytes
236767
- };
236768
- }
236769
236837
  function createCurve(curveDef, defHash) {
236770
- const create2 = (hash2) => weierstrass({ ...curveDef, ...getHash(hash2) });
236838
+ const create2 = (hash2) => weierstrass({ ...curveDef, hash: hash2 });
236771
236839
  return { ...create2(defHash), create: create2 };
236772
236840
  }
236773
236841
  var init__shortw_utils = __esm(() => {
236774
- init_hmac();
236775
- init_utils2();
236776
236842
  init_weierstrass();
236777
236843
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
236778
236844
  });
@@ -236802,52 +236868,55 @@ function anum(item) {
236802
236868
  throw new Error("number expected");
236803
236869
  }
236804
236870
  function expand_message_xmd(msg, DST, lenInBytes, H4) {
236805
- abytes2(msg);
236806
- abytes2(DST);
236871
+ abytes(msg);
236872
+ abytes(DST);
236807
236873
  anum(lenInBytes);
236808
236874
  if (DST.length > 255)
236809
- DST = H4(concatBytes3(utf8ToBytes2("H2C-OVERSIZE-DST-"), DST));
236875
+ DST = H4(concatBytes(utf8ToBytes("H2C-OVERSIZE-DST-"), DST));
236810
236876
  const { outputLen: b_in_bytes, blockLen: r_in_bytes } = H4;
236811
236877
  const ell = Math.ceil(lenInBytes / b_in_bytes);
236812
236878
  if (lenInBytes > 65535 || ell > 255)
236813
236879
  throw new Error("expand_message_xmd: invalid lenInBytes");
236814
- const DST_prime = concatBytes3(DST, i2osp(DST.length, 1));
236880
+ const DST_prime = concatBytes(DST, i2osp(DST.length, 1));
236815
236881
  const Z_pad = i2osp(0, r_in_bytes);
236816
236882
  const l_i_b_str = i2osp(lenInBytes, 2);
236817
236883
  const b4 = new Array(ell);
236818
- const b_0 = H4(concatBytes3(Z_pad, msg, l_i_b_str, i2osp(0, 1), DST_prime));
236819
- b4[0] = H4(concatBytes3(b_0, i2osp(1, 1), DST_prime));
236884
+ const b_0 = H4(concatBytes(Z_pad, msg, l_i_b_str, i2osp(0, 1), DST_prime));
236885
+ b4[0] = H4(concatBytes(b_0, i2osp(1, 1), DST_prime));
236820
236886
  for (let i6 = 1;i6 <= ell; i6++) {
236821
236887
  const args = [strxor(b_0, b4[i6 - 1]), i2osp(i6 + 1, 1), DST_prime];
236822
- b4[i6] = H4(concatBytes3(...args));
236888
+ b4[i6] = H4(concatBytes(...args));
236823
236889
  }
236824
- const pseudo_random_bytes = concatBytes3(...b4);
236890
+ const pseudo_random_bytes = concatBytes(...b4);
236825
236891
  return pseudo_random_bytes.slice(0, lenInBytes);
236826
236892
  }
236827
236893
  function expand_message_xof(msg, DST, lenInBytes, k5, H4) {
236828
- abytes2(msg);
236829
- abytes2(DST);
236894
+ abytes(msg);
236895
+ abytes(DST);
236830
236896
  anum(lenInBytes);
236831
236897
  if (DST.length > 255) {
236832
236898
  const dkLen = Math.ceil(2 * k5 / 8);
236833
- DST = H4.create({ dkLen }).update(utf8ToBytes2("H2C-OVERSIZE-DST-")).update(DST).digest();
236899
+ DST = H4.create({ dkLen }).update(utf8ToBytes("H2C-OVERSIZE-DST-")).update(DST).digest();
236834
236900
  }
236835
236901
  if (lenInBytes > 65535 || DST.length > 255)
236836
236902
  throw new Error("expand_message_xof: invalid lenInBytes");
236837
236903
  return H4.create({ dkLen: lenInBytes }).update(msg).update(i2osp(lenInBytes, 2)).update(DST).update(i2osp(DST.length, 1)).digest();
236838
236904
  }
236839
236905
  function hash_to_field(msg, count, options) {
236840
- validateObject(options, {
236841
- DST: "stringOrUint8Array",
236906
+ _validateObject(options, {
236842
236907
  p: "bigint",
236843
- m: "isSafeInteger",
236844
- k: "isSafeInteger",
236845
- hash: "hash"
236908
+ m: "number",
236909
+ k: "number",
236910
+ hash: "function"
236846
236911
  });
236847
236912
  const { p: p5, k: k5, m: m7, hash: hash2, expand, DST: _DST } = options;
236848
- abytes2(msg);
236913
+ if (!isBytes(_DST) && typeof _DST !== "string")
236914
+ throw new Error("DST must be string or uint8array");
236915
+ if (!isHash(options.hash))
236916
+ throw new Error("expected valid hash");
236917
+ abytes(msg);
236849
236918
  anum(count);
236850
- const DST = typeof _DST === "string" ? utf8ToBytes2(_DST) : _DST;
236919
+ const DST = typeof _DST === "string" ? utf8ToBytes(_DST) : _DST;
236851
236920
  const log2p = p5.toString(2).length;
236852
236921
  const L5 = Math.ceil((log2p + k5) / 8);
236853
236922
  const len_in_bytes = count * m7 * L5;
@@ -236899,13 +236968,17 @@ function createHasher2(Point, mapToCurve, defaults4) {
236899
236968
  return {
236900
236969
  defaults: defaults4,
236901
236970
  hashToCurve(msg, options) {
236902
- const u6 = hash_to_field(msg, 2, { ...defaults4, DST: defaults4.DST, ...options });
236971
+ const dst = defaults4.DST ? defaults4.DST : {};
236972
+ const opts = Object.assign({}, defaults4, dst, options);
236973
+ const u6 = hash_to_field(msg, 2, opts);
236903
236974
  const u0 = map6(u6[0]);
236904
236975
  const u1 = map6(u6[1]);
236905
236976
  return clear(u0.add(u1));
236906
236977
  },
236907
236978
  encodeToCurve(msg, options) {
236908
- const u6 = hash_to_field(msg, 1, { ...defaults4, DST: defaults4.encodeDST, ...options });
236979
+ const dst = defaults4.encodeDST ? defaults4.encodeDST : {};
236980
+ const opts = Object.assign({}, defaults4, dst, options);
236981
+ const u6 = hash_to_field(msg, 1, opts);
236909
236982
  return clear(map6(u6[0]));
236910
236983
  },
236911
236984
  mapToCurve(scalars) {
@@ -236920,8 +236993,8 @@ function createHasher2(Point, mapToCurve, defaults4) {
236920
236993
  }
236921
236994
  var os2ip;
236922
236995
  var init_hash_to_curve = __esm(() => {
236923
- init_modular();
236924
236996
  init_utils3();
236997
+ init_modular();
236925
236998
  os2ip = bytesToNumberBE;
236926
236999
  });
236927
237000
 
@@ -236935,7 +237008,7 @@ __export(exports_secp256k1, {
236935
237008
  encodeToCurve: () => encodeToCurve
236936
237009
  });
236937
237010
  function sqrtMod(y4) {
236938
- const P5 = secp256k1P;
237011
+ const P5 = secp256k1_CURVE.p;
236939
237012
  const _3n3 = BigInt(3), _6n = BigInt(6), _11n = BigInt(11), _22n = BigInt(22);
236940
237013
  const _23n = BigInt(23), _44n = BigInt(44), _88n = BigInt(88);
236941
237014
  const b22 = y4 * y4 * y4 % P5;
@@ -236960,25 +237033,25 @@ function taggedHash(tag, ...messages) {
236960
237033
  let tagP = TAGGED_HASH_PREFIXES[tag];
236961
237034
  if (tagP === undefined) {
236962
237035
  const tagH = sha256(Uint8Array.from(tag, (c3) => c3.charCodeAt(0)));
236963
- tagP = concatBytes3(tagH, tagH);
237036
+ tagP = concatBytes(tagH, tagH);
236964
237037
  TAGGED_HASH_PREFIXES[tag] = tagP;
236965
237038
  }
236966
- return sha256(concatBytes3(tagP, ...messages));
237039
+ return sha256(concatBytes(tagP, ...messages));
236967
237040
  }
236968
237041
  function schnorrGetExtPubKey(priv) {
236969
237042
  let d_ = secp256k1.utils.normPrivateKeyToScalar(priv);
236970
237043
  let p5 = Point.fromPrivateKey(d_);
236971
- const scalar = p5.hasEvenY() ? d_ : modN(-d_);
237044
+ const scalar = hasEven(p5.y) ? d_ : modN(-d_);
236972
237045
  return { scalar, bytes: pointToBytes(p5) };
236973
237046
  }
236974
237047
  function lift_x(x6) {
236975
- aInRange("x", x6, _1n6, secp256k1P);
237048
+ aInRange("x", x6, _1n6, secp256k1_CURVE.p);
236976
237049
  const xx = modP(x6 * x6);
236977
237050
  const c3 = modP(xx * x6 + BigInt(7));
236978
237051
  let y4 = sqrtMod(c3);
236979
- if (y4 % _2n4 !== _0n6)
237052
+ if (!hasEven(y4))
236980
237053
  y4 = modP(-y4);
236981
- const p5 = new Point(x6, y4, _1n6);
237054
+ const p5 = Point.fromAffine({ x: x6, y: y4 });
236982
237055
  p5.assertValidity();
236983
237056
  return p5;
236984
237057
  }
@@ -237013,49 +237086,52 @@ function schnorrVerify(signature, message, publicKey) {
237013
237086
  try {
237014
237087
  const P5 = lift_x(num(pub));
237015
237088
  const r6 = num(sig.subarray(0, 32));
237016
- if (!inRange(r6, _1n6, secp256k1P))
237089
+ if (!inRange(r6, _1n6, secp256k1_CURVE.p))
237017
237090
  return false;
237018
237091
  const s7 = num(sig.subarray(32, 64));
237019
- if (!inRange(s7, _1n6, secp256k1N))
237092
+ if (!inRange(s7, _1n6, secp256k1_CURVE.n))
237020
237093
  return false;
237021
237094
  const e10 = challenge(numTo32b(r6), pointToBytes(P5), m7);
237022
- const R7 = GmulAdd(P5, s7, modN(-e10));
237023
- if (!R7 || !R7.hasEvenY() || R7.toAffine().x !== r6)
237095
+ const R7 = Point.BASE.multiplyUnsafe(s7).add(P5.multiplyUnsafe(modN(-e10)));
237096
+ const { x: x6, y: y4 } = R7.toAffine();
237097
+ if (R7.is0() || !hasEven(y4) || x6 !== r6)
237024
237098
  return false;
237025
237099
  return true;
237026
237100
  } catch (error44) {
237027
237101
  return false;
237028
237102
  }
237029
237103
  }
237030
- var secp256k1P, secp256k1N, _0n6, _1n6, _2n4, divNearest = (a7, b4) => (a7 + b4 / _2n4) / b4, Fpk1, secp256k1, TAGGED_HASH_PREFIXES, pointToBytes = (point) => point.toRawBytes(true).slice(1), numTo32b = (n6) => numberToBytesBE(n6, 32), modP = (x6) => mod(x6, secp256k1P), modN = (x6) => mod(x6, secp256k1N), Point, GmulAdd = (Q4, a7, b4) => Point.BASE.multiplyAndAddUnsafe(Q4, a7, b4), num, schnorr, isoMap, mapSWU, secp256k1_hasher, hashToCurve, encodeToCurve;
237104
+ var secp256k1_CURVE, _0n6, _1n6, _2n4, divNearest = (a7, b4) => (a7 + b4 / _2n4) / b4, Fpk1, secp256k1, TAGGED_HASH_PREFIXES, pointToBytes = (point) => point.toBytes(true).slice(1), numTo32b = (n6) => numberToBytesBE(n6, 32), modP = (x6) => mod(x6, secp256k1_CURVE.p), modN = (x6) => mod(x6, secp256k1_CURVE.n), Point, hasEven = (y4) => y4 % _2n4 === _0n6, num, schnorr, isoMap, mapSWU, secp256k1_hasher, hashToCurve, encodeToCurve;
237031
237105
  var init_secp256k1 = __esm(() => {
237032
237106
  init_sha2();
237033
237107
  init_utils2();
237034
237108
  init__shortw_utils();
237035
237109
  init_hash_to_curve();
237036
237110
  init_modular();
237037
- init_utils3();
237038
237111
  init_weierstrass();
237112
+ init_utils3();
237039
237113
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
237040
- secp256k1P = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f");
237041
- secp256k1N = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
237114
+ secp256k1_CURVE = {
237115
+ p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
237116
+ n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
237117
+ h: BigInt(1),
237118
+ a: BigInt(0),
237119
+ b: BigInt(7),
237120
+ Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
237121
+ Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
237122
+ };
237042
237123
  _0n6 = BigInt(0);
237043
237124
  _1n6 = BigInt(1);
237044
237125
  _2n4 = BigInt(2);
237045
- Fpk1 = Field(secp256k1P, undefined, undefined, { sqrt: sqrtMod });
237126
+ Fpk1 = Field(secp256k1_CURVE.p, undefined, undefined, { sqrt: sqrtMod });
237046
237127
  secp256k1 = createCurve({
237047
- a: _0n6,
237048
- b: BigInt(7),
237128
+ ...secp256k1_CURVE,
237049
237129
  Fp: Fpk1,
237050
- n: secp256k1N,
237051
- Gx: BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
237052
- Gy: BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),
237053
- h: BigInt(1),
237054
237130
  lowS: true,
237055
237131
  endo: {
237056
237132
  beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
237057
237133
  splitScalar: (k5) => {
237058
- const n6 = secp256k1N;
237134
+ const n6 = secp256k1_CURVE.n;
237059
237135
  const a1 = BigInt("0x3086d221a7d46bcde86c90e49284eb15");
237060
237136
  const b1 = -_1n6 * BigInt("0xe4437ed6010e88286f547fa90abfe4c3");
237061
237137
  const a22 = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8");
@@ -237079,7 +237155,7 @@ var init_secp256k1 = __esm(() => {
237079
237155
  }
237080
237156
  }, sha256);
237081
237157
  TAGGED_HASH_PREFIXES = {};
237082
- Point = /* @__PURE__ */ (() => secp256k1.ProjectivePoint)();
237158
+ Point = /* @__PURE__ */ (() => secp256k1.Point)();
237083
237159
  num = bytesToNumberBE;
237084
237160
  schnorr = /* @__PURE__ */ (() => ({
237085
237161
  getPublicKey: schnorrGetPublicKey,
@@ -237125,7 +237201,7 @@ var init_secp256k1 = __esm(() => {
237125
237201
  B: BigInt("1771"),
237126
237202
  Z: Fpk1.create(BigInt("-11"))
237127
237203
  }))();
237128
- secp256k1_hasher = /* @__PURE__ */ (() => createHasher2(secp256k1.ProjectivePoint, (scalars) => {
237204
+ secp256k1_hasher = /* @__PURE__ */ (() => createHasher2(secp256k1.Point, (scalars) => {
237129
237205
  const { x: x6, y: y4 } = mapSWU(Fpk1.create(scalars[0]));
237130
237206
  return isoMap(x6, y4);
237131
237207
  }, {
@@ -263764,7 +263840,7 @@ function pruneCurrentEnv(currentEnv, env2) {
263764
263840
  var package_default = {
263765
263841
  name: "@settlemint/sdk-cli",
263766
263842
  description: "Command-line interface for SettleMint SDK, providing development tools and project management capabilities",
263767
- version: "2.3.14-prfdf11875",
263843
+ version: "2.4.0-main005a9b57",
263768
263844
  type: "module",
263769
263845
  private: false,
263770
263846
  license: "FSL-1.1-MIT",
@@ -263813,9 +263889,10 @@ var package_default = {
263813
263889
  "@inquirer/input": "4.1.12",
263814
263890
  "@inquirer/password": "4.0.15",
263815
263891
  "@inquirer/select": "4.2.3",
263816
- "@settlemint/sdk-js": "2.3.14-prfdf11875",
263817
- "@settlemint/sdk-utils": "2.3.14-prfdf11875",
263818
- "@types/node": "24.0.0",
263892
+ "@settlemint/sdk-js": "2.4.0-main005a9b57",
263893
+ "@settlemint/sdk-utils": "2.4.0-main005a9b57",
263894
+ "@settlemint/sdk-viem": "2.4.0-main005a9b57",
263895
+ "@types/node": "24.0.1",
263819
263896
  "@types/semver": "7.7.0",
263820
263897
  "@types/which": "3.0.4",
263821
263898
  "get-tsconfig": "4.10.1",
@@ -263823,13 +263900,13 @@ var package_default = {
263823
263900
  "is-in-ci": "1.0.0",
263824
263901
  semver: "7.7.2",
263825
263902
  slugify: "1.6.6",
263826
- viem: "2.31.0",
263903
+ viem: "2.31.2",
263827
263904
  which: "5.0.0",
263828
263905
  yaml: "2.8.0",
263829
263906
  yoctocolors: "2.1.1"
263830
263907
  },
263831
263908
  peerDependencies: {
263832
- hardhat: "2.24.2"
263909
+ hardhat: "2.24.3"
263833
263910
  },
263834
263911
  peerDependenciesMeta: {
263835
263912
  hardhat: {
@@ -295792,6 +295869,17 @@ async function exists3(path$1) {
295792
295869
  return false;
295793
295870
  }
295794
295871
  }
295872
+ function tryParseJson3(value2, defaultValue = null) {
295873
+ try {
295874
+ const parsed = JSON.parse(value2);
295875
+ if (parsed === undefined || parsed === null) {
295876
+ return defaultValue;
295877
+ }
295878
+ return parsed;
295879
+ } catch (err) {
295880
+ return defaultValue;
295881
+ }
295882
+ }
295795
295883
  var require_balanced_match4 = __commonJS4({ "../../node_modules/balanced-match/index.js"(exports, module) {
295796
295884
  module.exports = balanced$1;
295797
295885
  function balanced$1(a3, b, str) {
@@ -301270,9 +301358,45 @@ var glob3 = Object.assign(glob_3, {
301270
301358
  unescape: unescape4
301271
301359
  });
301272
301360
  glob3.glob = glob3;
301361
+ async function findMonoRepoRoot2(startDir) {
301362
+ const lockFilePath = await findUp([
301363
+ "package-lock.json",
301364
+ "yarn.lock",
301365
+ "pnpm-lock.yaml",
301366
+ "bun.lockb",
301367
+ "bun.lock"
301368
+ ], { cwd: startDir });
301369
+ if (lockFilePath) {
301370
+ const packageJsonPath = join3(dirname3(lockFilePath), "package.json");
301371
+ const hasWorkSpaces = await packageJsonHasWorkspaces2(packageJsonPath);
301372
+ return hasWorkSpaces ? dirname3(lockFilePath) : null;
301373
+ }
301374
+ let currentDir = startDir;
301375
+ while (currentDir !== "/") {
301376
+ const packageJsonPath = join3(currentDir, "package.json");
301377
+ if (await packageJsonHasWorkspaces2(packageJsonPath)) {
301378
+ return currentDir;
301379
+ }
301380
+ const parentDir = dirname3(currentDir);
301381
+ if (parentDir === currentDir) {
301382
+ break;
301383
+ }
301384
+ currentDir = parentDir;
301385
+ }
301386
+ return null;
301387
+ }
301388
+ async function packageJsonHasWorkspaces2(packageJsonPath) {
301389
+ if (await exists3(packageJsonPath)) {
301390
+ const packageJson = tryParseJson3(await readFile3(packageJsonPath, "utf-8"));
301391
+ if (packageJson?.workspaces && Array.isArray(packageJson?.workspaces) && packageJson?.workspaces.length > 0) {
301392
+ return true;
301393
+ }
301394
+ }
301395
+ return false;
301396
+ }
301273
301397
 
301274
301398
  // ../utils/dist/json.js
301275
- function tryParseJson3(value2, defaultValue = null) {
301399
+ function tryParseJson4(value2, defaultValue = null) {
301276
301400
  try {
301277
301401
  const parsed = JSON.parse(value2);
301278
301402
  if (parsed === undefined || parsed === null) {
@@ -301291,7 +301415,7 @@ function extractJsonObject(value2) {
301291
301415
  if (!result) {
301292
301416
  return null;
301293
301417
  }
301294
- return tryParseJson3(result[0]);
301418
+ return tryParseJson4(result[0]);
301295
301419
  }
301296
301420
 
301297
301421
  // src/utils/config.ts
@@ -301306,7 +301430,7 @@ async function readConfig() {
301306
301430
  await ensureConfigDir();
301307
301431
  try {
301308
301432
  const content = await readFile4(CONFIG_FILE, "utf-8");
301309
- return tryParseJson3(content, { instances: {} });
301433
+ return tryParseJson4(content, { instances: {} });
301310
301434
  } catch (error41) {
301311
301435
  return { instances: {} };
301312
301436
  }
@@ -304887,8 +305011,11 @@ function observe(observerId, callbacks, fn) {
304887
305011
  if (!listeners2.some((cb) => cb.id === callbackId))
304888
305012
  return;
304889
305013
  const cleanup2 = cleanupCache.get(observerId);
304890
- if (listeners2.length === 1 && cleanup2)
304891
- cleanup2();
305014
+ if (listeners2.length === 1 && cleanup2) {
305015
+ const p5 = cleanup2();
305016
+ if (p5 instanceof Promise)
305017
+ p5.catch(() => {});
305018
+ }
304892
305019
  unsubscribe();
304893
305020
  };
304894
305021
  const listeners = getListeners();
@@ -307067,7 +307194,7 @@ async function simulateBlocks(client, parameters) {
307067
307194
  return;
307068
307195
  return getContractError(error45, {
307069
307196
  abi: abi2 ?? [],
307070
- address: to,
307197
+ address: to ?? "0x",
307071
307198
  args,
307072
307199
  functionName: functionName ?? "<unknown>"
307073
307200
  });
@@ -308009,14 +308136,6 @@ async function simulateCalls(client, parameters) {
308009
308136
  });
308010
308137
  return accessList.map(({ address, storageKeys }) => storageKeys.length > 0 ? address : null);
308011
308138
  })).then((x6) => x6.flat().filter(Boolean)) : [];
308012
- const resultsStateOverrides = stateOverrides?.map((override) => {
308013
- if (override.address === account?.address)
308014
- return {
308015
- ...override,
308016
- nonce: 0
308017
- };
308018
- return override;
308019
- });
308020
308139
  const blocks = await simulateBlocks(client, {
308021
308140
  blockNumber,
308022
308141
  blockTag,
@@ -308046,12 +308165,11 @@ async function simulateCalls(client, parameters) {
308046
308165
  }
308047
308166
  ] : [],
308048
308167
  {
308049
- calls: [...calls, {}].map((call2, index2) => ({
308168
+ calls: [...calls, {}].map((call2) => ({
308050
308169
  ...call2,
308051
- from: account?.address,
308052
- nonce: index2
308170
+ from: account?.address
308053
308171
  })),
308054
- stateOverrides: resultsStateOverrides
308172
+ stateOverrides
308055
308173
  },
308056
308174
  ...traceAssetChanges ? [
308057
308175
  {
@@ -308590,7 +308708,7 @@ function watchBlocks(client, { blockTag = "latest", emitMissed = false, emitOnBe
308590
308708
  if (!active)
308591
308709
  return;
308592
308710
  const block = await getAction(client, getBlock, "getBlock")({
308593
- blockNumber: data.blockNumber,
308711
+ blockNumber: data.result?.number,
308594
308712
  includeTransactions
308595
308713
  }).catch(() => {});
308596
308714
  if (!active)
@@ -329313,9 +329431,9 @@ function hardhatTestCommand() {
329313
329431
  });
329314
329432
  }
329315
329433
 
329316
- // src/utils/subgraph/setup.ts
329317
- import { rm as rm4 } from "node:fs/promises";
329318
- var import_semver = __toESM(require_semver2(), 1);
329434
+ // src/commands/smart-contract-set/subgraph/add.ts
329435
+ import { copyFile, mkdir as mkdir7, readFile as readFile10, unlink as unlink2, writeFile as writeFile9 } from "node:fs/promises";
329436
+ import { basename as basename5, dirname as dirname8, isAbsolute as isAbsolute2, join as join11, relative as relative4 } from "node:path";
329319
329437
 
329320
329438
  // src/utils/subgraph/subgraph-config.ts
329321
329439
  import { readFile as readFile9, writeFile as writeFile8 } from "node:fs/promises";
@@ -329347,7 +329465,7 @@ var updateSubgraphYamlConfig = async (config5, cwd2 = process.cwd()) => {
329347
329465
  var getSubgraphConfig = async (path7 = process.cwd()) => {
329348
329466
  try {
329349
329467
  const configContents = await readFile9(join10(path7, CONFIG_FILE_PATH));
329350
- const currentConfig = tryParseJson3(configContents.toString());
329468
+ const currentConfig = tryParseJson4(configContents.toString());
329351
329469
  return currentConfig;
329352
329470
  } catch (err) {
329353
329471
  const error45 = err;
@@ -329356,7 +329474,102 @@ var getSubgraphConfig = async (path7 = process.cwd()) => {
329356
329474
  }
329357
329475
  };
329358
329476
 
329477
+ // src/commands/smart-contract-set/subgraph/add.ts
329478
+ var DEFAULT_ADDRESS = "0x0000000000000000000000000000000000000000";
329479
+ function subgraphAddCommand() {
329480
+ return new Command("add").description("Add a contract to the subgraph").usage(createExamples([
329481
+ {
329482
+ description: "Add a contract to the subgraph",
329483
+ command: "scs subgraph add --abi=./abis/bond.json --contract-name=bond"
329484
+ }
329485
+ ])).requiredOption("--abi <abi>", "Path to the contract ABI.").requiredOption("--contract-name <contract-name>", "Name of the contract.").option("--address <contract-address>", `Address of the contract (defaults to ${DEFAULT_ADDRESS}).`).option("--start-block <start-block>", "Start block of the contract (defaults to 0).").option("--network <network>", "Network name (defaults to settlemint).").action(async ({ abi: abi2, contractName, address, startBlock, network }) => {
329486
+ intro(`Adding subgraph config for contract ${contractName}`);
329487
+ const abiPath = isAbsolute2(abi2) ? abi2 : join11(process.cwd(), abi2);
329488
+ if (!await exists3(abiPath)) {
329489
+ throw new Error("ABI file not found");
329490
+ }
329491
+ await validateIfRequiredPackagesAreInstalled(["@graphprotocol/graph-cli"]);
329492
+ if (await isGenerated()) {
329493
+ throw new Error("This command does not support automatically generated subgraph configs");
329494
+ }
329495
+ const { command, args } = await getPackageManagerExecutable();
329496
+ const subgraphYamlFile = await getSubgraphYamlFile();
329497
+ const abiName = basename5(abiPath);
329498
+ const subgraphYamlDir = dirname8(subgraphYamlFile);
329499
+ await mkdir7(join11(subgraphYamlDir, "abis"), { recursive: true });
329500
+ const localAbiPath = join11(subgraphYamlDir, "abis", abiName);
329501
+ await copyFile(abiPath, localAbiPath);
329502
+ try {
329503
+ const root = await projectRoot3();
329504
+ await fixPackageJson(root);
329505
+ const monoRepoRoot = await findMonoRepoRoot2(root);
329506
+ if (monoRepoRoot) {
329507
+ await fixPackageJson(monoRepoRoot, false);
329508
+ }
329509
+ await executeCommand(command, [
329510
+ ...args,
329511
+ "graph",
329512
+ "add",
329513
+ "--abi",
329514
+ abi2,
329515
+ "--contract-name",
329516
+ contractName,
329517
+ "--start-block",
329518
+ startBlock ?? "0",
329519
+ address ?? DEFAULT_ADDRESS,
329520
+ subgraphYamlFile
329521
+ ]);
329522
+ const subgraphYamlConfig = await getSubgraphYamlConfig();
329523
+ if (subgraphYamlConfig) {
329524
+ const updatedDataSources = subgraphYamlConfig?.dataSources.map((dataSource) => {
329525
+ if (dataSource.name === contractName) {
329526
+ dataSource.network = network ?? "settlemint";
329527
+ dataSource.mapping.abis = [
329528
+ {
329529
+ name: contractName,
329530
+ file: relative4(subgraphYamlDir, abiPath)
329531
+ }
329532
+ ];
329533
+ }
329534
+ return dataSource;
329535
+ });
329536
+ await updateSubgraphYamlConfig({
329537
+ ...subgraphYamlConfig,
329538
+ dataSources: updatedDataSources
329539
+ });
329540
+ }
329541
+ } finally {
329542
+ await unlink2(localAbiPath);
329543
+ }
329544
+ outro(`Subgraph config for contract ${contractName} added successfully`);
329545
+ });
329546
+ }
329547
+ async function fixPackageJson(packageJsonDir, requiresCodegenScript = true) {
329548
+ const packageJsonPath = join11(packageJsonDir, "package.json");
329549
+ if (!await exists3(packageJsonPath)) {
329550
+ return;
329551
+ }
329552
+ let hasPackageJsonChanged = false;
329553
+ const subgraphPackageJson = await readFile10(packageJsonPath);
329554
+ const subgraphPackageJsonData = JSON.parse(subgraphPackageJson.toString());
329555
+ if (subgraphPackageJsonData.packageManager?.includes("bun")) {
329556
+ note("Removing package manager from package.json (bun is not an official package manager)");
329557
+ delete subgraphPackageJsonData.packageManager;
329558
+ hasPackageJsonChanged = true;
329559
+ }
329560
+ if (requiresCodegenScript && !subgraphPackageJsonData.scripts?.codegen) {
329561
+ note("Adding codegen script to package.json");
329562
+ subgraphPackageJsonData.scripts.codegen = "settlemint scs subgraph codegen";
329563
+ hasPackageJsonChanged = true;
329564
+ }
329565
+ if (hasPackageJsonChanged) {
329566
+ await writeFile9(packageJsonPath, JSON.stringify(subgraphPackageJsonData, null, 2));
329567
+ }
329568
+ }
329569
+
329359
329570
  // src/utils/subgraph/setup.ts
329571
+ import { rm as rm4 } from "node:fs/promises";
329572
+ var import_semver = __toESM(require_semver2(), 1);
329360
329573
  var SETTLEMINT_NETWORK = "settlemint";
329361
329574
  async function subgraphSetup({ network }) {
329362
329575
  const generated = await isGenerated();
@@ -329746,6 +329959,7 @@ function smartContractSetCommand() {
329746
329959
  hardhat.addCommand(hardhatScriptCommand());
329747
329960
  hardhat.addCommand(hardhatTestCommand());
329748
329961
  const subgraph = new Command("subgraph").alias("sg").enablePositionalOptions().description("Commands for managing TheGraph subgraphs for smart contract indexing");
329962
+ subgraph.addCommand(subgraphAddCommand());
329749
329963
  subgraph.addCommand(subgraphBuildCommand());
329750
329964
  subgraph.addCommand(subgraphCodegenCommand());
329751
329965
  subgraph.addCommand(subgraphDeployCommand());
@@ -329875,4 +330089,4 @@ async function sdkCliCommand(argv = process.argv) {
329875
330089
  // src/cli.ts
329876
330090
  sdkCliCommand();
329877
330091
 
329878
- //# debugId=4DCFE5EBE8F6591364756E2164756E21
330092
+ //# debugId=54A153F5116DB2FB64756E2164756E21