@t2000/mcp 5.17.0 → 5.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.js CHANGED
@@ -2,7 +2,8 @@
2
2
  import { createRequire } from 'module';
3
3
  import url, { fileURLToPath } from 'url';
4
4
  import { dirname, join as join$1, resolve } from 'path';
5
- import crypto2 from 'crypto';
5
+ import * as nc from 'crypto';
6
+ import nc__default from 'crypto';
6
7
  import stream3, { Readable } from 'stream';
7
8
  import util3 from 'util';
8
9
  import http from 'http';
@@ -31,8 +32,8 @@ var __require = /* @__PURE__ */ ((x) => typeof require$1 !== "undefined" ? requi
31
32
  var __esm = (fn, res) => function __init() {
32
33
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
33
34
  };
34
- var __commonJS = (cb, mod3) => function __require3() {
35
- return mod3 || (0, cb[__getOwnPropNames(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports;
35
+ var __commonJS = (cb, mod4) => function __require3() {
36
+ return mod4 || (0, cb[__getOwnPropNames(cb)[0]])((mod4 = { exports: {} }).exports, mod4), mod4.exports;
36
37
  };
37
38
  var __export = (target, all3) => {
38
39
  for (var name in all3)
@@ -46,13 +47,13 @@ var __copyProps = (to, from, except, desc) => {
46
47
  }
47
48
  return to;
48
49
  };
49
- var __toESM = (mod3, isNodeMode, target) => (target = mod3 != null ? __create(__getProtoOf(mod3)) : {}, __copyProps(
50
+ var __toESM = (mod4, isNodeMode, target) => (target = mod4 != null ? __create(__getProtoOf(mod4)) : {}, __copyProps(
50
51
  // If the importer is in node compatibility mode or this is not an ESM
51
52
  // file that has been converted to a CommonJS file using a Babel-
52
53
  // compatible transform (i.e. "__esModule" has not been set), then set
53
54
  // "default" to the CommonJS "module.exports" for node compatibility.
54
- __defProp(target, "default", { value: mod3, enumerable: true }) ,
55
- mod3
55
+ __defProp(target, "default", { value: mod4, enumerable: true }) ,
56
+ mod4
56
57
  ));
57
58
 
58
59
  // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
@@ -11653,7 +11654,7 @@ function dynamicSizeBcsType({ serialize, ...options }) {
11653
11654
  });
11654
11655
  return type;
11655
11656
  }
11656
- function stringLikeBcsType({ toBytes, fromBytes, ...options }) {
11657
+ function stringLikeBcsType({ toBytes: toBytes2, fromBytes, ...options }) {
11657
11658
  return new BcsType({
11658
11659
  ...options,
11659
11660
  read: (reader) => {
@@ -11661,12 +11662,12 @@ function stringLikeBcsType({ toBytes, fromBytes, ...options }) {
11661
11662
  return fromBytes(reader.readBytes(length));
11662
11663
  },
11663
11664
  write: (hex, writer) => {
11664
- const bytes = toBytes(hex);
11665
+ const bytes = toBytes2(hex);
11665
11666
  writer.writeULEB(bytes.length);
11666
11667
  for (let i = 0; i < bytes.length; i++) writer.write8(bytes[i]);
11667
11668
  },
11668
11669
  serialize: (value) => {
11669
- const bytes = toBytes(value);
11670
+ const bytes = toBytes2(value);
11670
11671
  const size = ulebEncode(bytes.length);
11671
11672
  const result = new Uint8Array(size.length + bytes.length);
11672
11673
  result.set(size, 0);
@@ -14884,7 +14885,7 @@ function serializeV1TransactionData(transactionData) {
14884
14885
  };
14885
14886
  if (command.Publish) return {
14886
14887
  kind: "Publish",
14887
- modules: command.Publish.modules.map((mod3) => Array.from(fromBase64(mod3))),
14888
+ modules: command.Publish.modules.map((mod4) => Array.from(fromBase64(mod4))),
14888
14889
  dependencies: command.Publish.dependencies
14889
14890
  };
14890
14891
  if (command.SplitCoins) return {
@@ -14899,7 +14900,7 @@ function serializeV1TransactionData(transactionData) {
14899
14900
  };
14900
14901
  if (command.Upgrade) return {
14901
14902
  kind: "Upgrade",
14902
- modules: command.Upgrade.modules.map((mod3) => Array.from(fromBase64(mod3))),
14903
+ modules: command.Upgrade.modules.map((mod4) => Array.from(fromBase64(mod4))),
14903
14904
  dependencies: command.Upgrade.dependencies,
14904
14905
  packageId: command.Upgrade.package,
14905
14906
  ticket: convertTransactionArgument(command.Upgrade.ticket, inputs)
@@ -14979,10 +14980,10 @@ function transactionDataFromV1(data) {
14979
14980
  sources: transaction.sources.map((arg) => parseV1TransactionArgument(arg))
14980
14981
  } };
14981
14982
  case "MoveCall": {
14982
- const [pkg, mod3, fn] = transaction.target.split("::");
14983
+ const [pkg, mod4, fn] = transaction.target.split("::");
14983
14984
  return { MoveCall: {
14984
14985
  package: pkg,
14985
- module: mod3,
14986
+ module: mod4,
14986
14987
  function: fn,
14987
14988
  typeArguments: transaction.typeArguments,
14988
14989
  arguments: transaction.arguments.map((arg) => parseV1TransactionArgument(arg))
@@ -14990,7 +14991,7 @@ function transactionDataFromV1(data) {
14990
14991
  }
14991
14992
  case "Publish":
14992
14993
  return { Publish: {
14993
- modules: transaction.modules.map((mod3) => toBase64(Uint8Array.from(mod3))),
14994
+ modules: transaction.modules.map((mod4) => toBase64(Uint8Array.from(mod4))),
14994
14995
  dependencies: transaction.dependencies
14995
14996
  } };
14996
14997
  case "SplitCoins":
@@ -15005,7 +15006,7 @@ function transactionDataFromV1(data) {
15005
15006
  } };
15006
15007
  case "Upgrade":
15007
15008
  return { Upgrade: {
15008
- modules: transaction.modules.map((mod3) => toBase64(Uint8Array.from(mod3))),
15009
+ modules: transaction.modules.map((mod4) => toBase64(Uint8Array.from(mod4))),
15009
15010
  dependencies: transaction.dependencies,
15010
15011
  package: transaction.packageId,
15011
15012
  ticket: parseV1TransactionArgument(transaction.ticket)
@@ -15393,7 +15394,7 @@ var init_Commands = __esm({
15393
15394
  init_dist3();
15394
15395
  TransactionCommands = {
15395
15396
  MoveCall(input) {
15396
- const [pkg, mod3 = "", fn = ""] = "target" in input ? input.target.split("::") : [
15397
+ const [pkg, mod4 = "", fn = ""] = "target" in input ? input.target.split("::") : [
15397
15398
  input.package,
15398
15399
  input.module,
15399
15400
  input.function
@@ -15402,7 +15403,7 @@ var init_Commands = __esm({
15402
15403
  $kind: "MoveCall",
15403
15404
  MoveCall: {
15404
15405
  package: pkg,
15405
- module: mod3,
15406
+ module: mod4,
15406
15407
  function: fn,
15407
15408
  typeArguments: input.typeArguments ?? [],
15408
15409
  arguments: input.arguments ?? []
@@ -42406,10 +42407,10 @@ var require_abort = __commonJS({
42406
42407
  "../../node_modules/.pnpm/asynckit@0.4.0/node_modules/asynckit/lib/abort.js"(exports$1, module) {
42407
42408
  module.exports = abort;
42408
42409
  function abort(state) {
42409
- Object.keys(state.jobs).forEach(clean2.bind(state));
42410
+ Object.keys(state.jobs).forEach(clean3.bind(state));
42410
42411
  state.jobs = {};
42411
42412
  }
42412
- function clean2(key) {
42413
+ function clean3(key) {
42413
42414
  if (typeof this.jobs[key] == "function") {
42414
42415
  this.jobs[key]();
42415
42416
  }
@@ -43405,7 +43406,7 @@ var require_form_data = __commonJS({
43405
43406
  var parseUrl2 = __require("url").parse;
43406
43407
  var fs = __require("fs");
43407
43408
  var Stream = __require("stream").Stream;
43408
- var crypto3 = __require("crypto");
43409
+ var crypto4 = __require("crypto");
43409
43410
  var mime = require_mime_types();
43410
43411
  var asynckit = require_asynckit();
43411
43412
  var setToStringTag = require_es_set_tostringtag();
@@ -43611,7 +43612,7 @@ var require_form_data = __commonJS({
43611
43612
  return Buffer.concat([dataBuffer, Buffer.from(this._lastBoundary())]);
43612
43613
  };
43613
43614
  FormData3.prototype._generateBoundary = function() {
43614
- this._boundary = "--------------------------" + crypto3.randomBytes(12).toString("hex");
43615
+ this._boundary = "--------------------------" + crypto4.randomBytes(12).toString("hex");
43615
43616
  };
43616
43617
  FormData3.prototype.getLengthSync = function() {
43617
43618
  var knownLength = this._overheadLength + this._valueLength;
@@ -44032,7 +44033,7 @@ var init_node = __esm({
44032
44033
  let str = "";
44033
44034
  const { length } = alphabet2;
44034
44035
  const randomValues = new Uint32Array(size);
44035
- crypto2.randomFillSync(randomValues);
44036
+ nc__default.randomFillSync(randomValues);
44036
44037
  for (let i = 0; i < size; i++) {
44037
44038
  str += alphabet2[randomValues[i] % length];
44038
44039
  }
@@ -50516,7 +50517,7 @@ function maxOrMin(Ctor, args, n) {
50516
50517
  return x;
50517
50518
  }
50518
50519
  function naturalExponential(x, sd) {
50519
- var denominator, guard, j, pow22, sum2, t, wpr, rep = 0, i = 0, k = 0, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
50520
+ var denominator, guard, j, pow23, sum2, t, wpr, rep = 0, i = 0, k = 0, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
50520
50521
  if (!x.d || !x.d[0] || x.e > 17) {
50521
50522
  return new Ctor(x.d ? !x.d[0] ? 1 : x.s < 0 ? 0 : 1 / 0 : x.s ? x.s < 0 ? 0 : x : 0 / 0);
50522
50523
  }
@@ -50533,19 +50534,19 @@ function naturalExponential(x, sd) {
50533
50534
  }
50534
50535
  guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
50535
50536
  wpr += guard;
50536
- denominator = pow22 = sum2 = new Ctor(1);
50537
+ denominator = pow23 = sum2 = new Ctor(1);
50537
50538
  Ctor.precision = wpr;
50538
50539
  for (; ; ) {
50539
- pow22 = finalise(pow22.times(x), wpr, 1);
50540
+ pow23 = finalise(pow23.times(x), wpr, 1);
50540
50541
  denominator = denominator.times(++i);
50541
- t = sum2.plus(divide(pow22, denominator, wpr, 1));
50542
+ t = sum2.plus(divide(pow23, denominator, wpr, 1));
50542
50543
  if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
50543
50544
  j = k;
50544
50545
  while (j--) sum2 = finalise(sum2.times(sum2), wpr, 1);
50545
50546
  if (sd == null) {
50546
50547
  if (rep < 3 && checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
50547
50548
  Ctor.precision = wpr += 10;
50548
- denominator = pow22 = t = new Ctor(1);
50549
+ denominator = pow23 = t = new Ctor(1);
50549
50550
  i = 0;
50550
50551
  rep++;
50551
50552
  } else {
@@ -51792,12 +51793,12 @@ var init_dist7 = __esm({
51792
51793
  }
51793
51794
  }
51794
51795
  if (mod22 !== 0) {
51795
- var pow22 = 1;
51796
+ var pow23 = 1;
51796
51797
  word = parseBase(number4, i, number4.length, base);
51797
51798
  for (i = 0; i < mod22; i++) {
51798
- pow22 *= base;
51799
+ pow23 *= base;
51799
51800
  }
51800
- this.imuln(pow22);
51801
+ this.imuln(pow23);
51801
51802
  if (this.words[0] + word < 67108864) {
51802
51803
  this.words[0] += word;
51803
51804
  } else {
@@ -53132,7 +53133,7 @@ var init_dist7 = __esm({
53132
53133
  BN7.prototype.isqr = function isqr() {
53133
53134
  return this.imul(this.clone());
53134
53135
  };
53135
- BN7.prototype.pow = function pow22(num) {
53136
+ BN7.prototype.pow = function pow23(num) {
53136
53137
  var w2 = toBitArray(num);
53137
53138
  if (w2.length === 0) return new BN7(1);
53138
53139
  var res = this;
@@ -54126,11 +54127,11 @@ var init_dist7 = __esm({
54126
54127
  };
54127
54128
  Red.prototype.sqrt = function sqrt2(a) {
54128
54129
  if (a.isZero()) return a.clone();
54129
- var mod3 = this.m.andln(3);
54130
- assert3(mod3 % 2 === 1);
54131
- if (mod3 === 3) {
54132
- var pow22 = this.m.add(new BN7(1)).iushrn(2);
54133
- return this.pow(a, pow22);
54130
+ var mod32 = this.m.andln(3);
54131
+ assert3(mod32 % 2 === 1);
54132
+ if (mod32 === 3) {
54133
+ var pow23 = this.m.add(new BN7(1)).iushrn(2);
54134
+ return this.pow(a, pow23);
54134
54135
  }
54135
54136
  var q = this.m.subn(1);
54136
54137
  var s = 0;
@@ -54174,7 +54175,7 @@ var init_dist7 = __esm({
54174
54175
  return this.imod(inv);
54175
54176
  }
54176
54177
  };
54177
- Red.prototype.pow = function pow22(a, num) {
54178
+ Red.prototype.pow = function pow23(a, num) {
54178
54179
  if (num.isZero()) return new BN7(1).toRed(this);
54179
54180
  if (num.cmpn(1) === 0) return a.clone();
54180
54181
  var windowSize = 4;
@@ -58969,8 +58970,8 @@ var require_bn2 = __commonJS({
58969
58970
  limbLen--;
58970
58971
  limbPow = limbPow / base | 0;
58971
58972
  var total = number4.length - start;
58972
- var mod3 = total % limbLen;
58973
- var end = Math.min(total, total - mod3) + start;
58973
+ var mod4 = total % limbLen;
58974
+ var end = Math.min(total, total - mod4) + start;
58974
58975
  var word = 0;
58975
58976
  for (var i = start; i < end; i += limbLen) {
58976
58977
  word = parseBase(number4, i, i + limbLen, base);
@@ -58981,10 +58982,10 @@ var require_bn2 = __commonJS({
58981
58982
  this._iaddn(word);
58982
58983
  }
58983
58984
  }
58984
- if (mod3 !== 0) {
58985
+ if (mod4 !== 0) {
58985
58986
  var pow3 = 1;
58986
58987
  word = parseBase(number4, i, number4.length, base);
58987
- for (i = 0; i < mod3; i++) {
58988
+ for (i = 0; i < mod4; i++) {
58988
58989
  pow3 *= base;
58989
58990
  }
58990
58991
  this.imuln(pow3);
@@ -60624,21 +60625,21 @@ var require_bn2 = __commonJS({
60624
60625
  mod: new BN2(0)
60625
60626
  };
60626
60627
  }
60627
- var div2, mod3, res;
60628
+ var div2, mod4, res;
60628
60629
  if (this.negative !== 0 && num.negative === 0) {
60629
60630
  res = this.neg().divmod(num, mode);
60630
60631
  if (mode !== "mod") {
60631
60632
  div2 = res.div.neg();
60632
60633
  }
60633
60634
  if (mode !== "div") {
60634
- mod3 = res.mod.neg();
60635
- if (positive && mod3.negative !== 0) {
60636
- mod3.iadd(num);
60635
+ mod4 = res.mod.neg();
60636
+ if (positive && mod4.negative !== 0) {
60637
+ mod4.iadd(num);
60637
60638
  }
60638
60639
  }
60639
60640
  return {
60640
60641
  div: div2,
60641
- mod: mod3
60642
+ mod: mod4
60642
60643
  };
60643
60644
  }
60644
60645
  if (this.negative === 0 && num.negative !== 0) {
@@ -60654,14 +60655,14 @@ var require_bn2 = __commonJS({
60654
60655
  if ((this.negative & num.negative) !== 0) {
60655
60656
  res = this.neg().divmod(num.neg(), mode);
60656
60657
  if (mode !== "div") {
60657
- mod3 = res.mod.neg();
60658
- if (positive && mod3.negative !== 0) {
60659
- mod3.isub(num);
60658
+ mod4 = res.mod.neg();
60659
+ if (positive && mod4.negative !== 0) {
60660
+ mod4.isub(num);
60660
60661
  }
60661
60662
  }
60662
60663
  return {
60663
60664
  div: res.div,
60664
- mod: mod3
60665
+ mod: mod4
60665
60666
  };
60666
60667
  }
60667
60668
  if (num.length > this.length || this.cmp(num) < 0) {
@@ -60693,7 +60694,7 @@ var require_bn2 = __commonJS({
60693
60694
  BN2.prototype.div = function div2(num) {
60694
60695
  return this.divmod(num, "div", false).div;
60695
60696
  };
60696
- BN2.prototype.mod = function mod3(num) {
60697
+ BN2.prototype.mod = function mod4(num) {
60697
60698
  return this.divmod(num, "mod", false).mod;
60698
60699
  };
60699
60700
  BN2.prototype.umod = function umod(num) {
@@ -60702,10 +60703,10 @@ var require_bn2 = __commonJS({
60702
60703
  BN2.prototype.divRound = function divRound(num) {
60703
60704
  var dm = this.divmod(num);
60704
60705
  if (dm.mod.isZero()) return dm.div;
60705
- var mod3 = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
60706
+ var mod4 = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
60706
60707
  var half = num.ushrn(1);
60707
60708
  var r2 = num.andln(1);
60708
- var cmp = mod3.cmp(half);
60709
+ var cmp = mod4.cmp(half);
60709
60710
  if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
60710
60711
  return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
60711
60712
  };
@@ -61319,9 +61320,9 @@ var require_bn2 = __commonJS({
61319
61320
  };
61320
61321
  Red.prototype.sqrt = function sqrt2(a) {
61321
61322
  if (a.isZero()) return a.clone();
61322
- var mod3 = this.m.andln(3);
61323
- assert3(mod3 % 2 === 1);
61324
- if (mod3 === 3) {
61323
+ var mod32 = this.m.andln(3);
61324
+ assert3(mod32 % 2 === 1);
61325
+ if (mod32 === 3) {
61325
61326
  var pow3 = this.m.add(new BN2(1)).iushrn(2);
61326
61327
  return this.pow(a, pow3);
61327
61328
  }
@@ -76999,7 +77000,7 @@ function eddsa(Point, cHash, eddsaOpts = {}) {
76999
77000
  });
77000
77001
  const { prehash } = eddsaOpts;
77001
77002
  const { BASE: BASE2, Fp, Fn } = Point;
77002
- const randomBytes2 = eddsaOpts.randomBytes || randomBytes;
77003
+ const randomBytes3 = eddsaOpts.randomBytes || randomBytes;
77003
77004
  const adjustScalarBytes2 = eddsaOpts.adjustScalarBytes || ((bytes) => bytes);
77004
77005
  const domain = eddsaOpts.domain || ((data, ctx, phflag) => {
77005
77006
  abool(phflag, "phflag");
@@ -77081,7 +77082,7 @@ function eddsa(Point, cHash, eddsaOpts = {}) {
77081
77082
  signature: 2 * _size2,
77082
77083
  seed: _size2
77083
77084
  };
77084
- function randomSecretKey(seed = randomBytes2(lengths.seed)) {
77085
+ function randomSecretKey(seed = randomBytes3(lengths.seed)) {
77085
77086
  return abytes(seed, lengths.seed, "seed");
77086
77087
  }
77087
77088
  function isValidSecretKey(key) {
@@ -77649,6 +77650,2310 @@ var Ed25519Keypair = class Ed25519Keypair2 extends Keypair {
77649
77650
  return Ed25519Keypair2.fromSecretKey(key);
77650
77651
  }
77651
77652
  };
77653
+ var crypto3 = nc && typeof nc === "object" && "webcrypto" in nc ? nc.webcrypto : nc && typeof nc === "object" && "randomBytes" in nc ? nc : void 0;
77654
+
77655
+ // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/utils.js
77656
+ function isBytes3(a) {
77657
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
77658
+ }
77659
+ function anumber3(n) {
77660
+ if (!Number.isSafeInteger(n) || n < 0)
77661
+ throw new Error("positive integer expected, got " + n);
77662
+ }
77663
+ function abytes2(b, ...lengths) {
77664
+ if (!isBytes3(b))
77665
+ throw new Error("Uint8Array expected");
77666
+ if (lengths.length > 0 && !lengths.includes(b.length))
77667
+ throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
77668
+ }
77669
+ function ahash2(h) {
77670
+ if (typeof h !== "function" || typeof h.create !== "function")
77671
+ throw new Error("Hash should be wrapped by utils.createHasher");
77672
+ anumber3(h.outputLen);
77673
+ anumber3(h.blockLen);
77674
+ }
77675
+ function aexists2(instance, checkFinished = true) {
77676
+ if (instance.destroyed)
77677
+ throw new Error("Hash instance has been destroyed");
77678
+ if (checkFinished && instance.finished)
77679
+ throw new Error("Hash#digest() has already been called");
77680
+ }
77681
+ function aoutput2(out, instance) {
77682
+ abytes2(out);
77683
+ const min2 = instance.outputLen;
77684
+ if (out.length < min2) {
77685
+ throw new Error("digestInto() expects output buffer of length at least " + min2);
77686
+ }
77687
+ }
77688
+ function clean2(...arrays) {
77689
+ for (let i = 0; i < arrays.length; i++) {
77690
+ arrays[i].fill(0);
77691
+ }
77692
+ }
77693
+ function createView2(arr) {
77694
+ return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
77695
+ }
77696
+ function rotr2(word, shift) {
77697
+ return word << 32 - shift | word >>> shift;
77698
+ }
77699
+ var hasHexBuiltin2 = /* @__PURE__ */ (() => (
77700
+ // @ts-ignore
77701
+ typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
77702
+ ))();
77703
+ var hexes2 = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
77704
+ function bytesToHex2(bytes) {
77705
+ abytes2(bytes);
77706
+ if (hasHexBuiltin2)
77707
+ return bytes.toHex();
77708
+ let hex = "";
77709
+ for (let i = 0; i < bytes.length; i++) {
77710
+ hex += hexes2[bytes[i]];
77711
+ }
77712
+ return hex;
77713
+ }
77714
+ var asciis2 = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
77715
+ function asciiToBase162(ch) {
77716
+ if (ch >= asciis2._0 && ch <= asciis2._9)
77717
+ return ch - asciis2._0;
77718
+ if (ch >= asciis2.A && ch <= asciis2.F)
77719
+ return ch - (asciis2.A - 10);
77720
+ if (ch >= asciis2.a && ch <= asciis2.f)
77721
+ return ch - (asciis2.a - 10);
77722
+ return;
77723
+ }
77724
+ function hexToBytes2(hex) {
77725
+ if (typeof hex !== "string")
77726
+ throw new Error("hex string expected, got " + typeof hex);
77727
+ if (hasHexBuiltin2)
77728
+ return Uint8Array.fromHex(hex);
77729
+ const hl = hex.length;
77730
+ const al = hl / 2;
77731
+ if (hl % 2)
77732
+ throw new Error("hex string expected, got unpadded hex of length " + hl);
77733
+ const array3 = new Uint8Array(al);
77734
+ for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
77735
+ const n1 = asciiToBase162(hex.charCodeAt(hi));
77736
+ const n2 = asciiToBase162(hex.charCodeAt(hi + 1));
77737
+ if (n1 === void 0 || n2 === void 0) {
77738
+ const char = hex[hi] + hex[hi + 1];
77739
+ throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
77740
+ }
77741
+ array3[ai] = n1 * 16 + n2;
77742
+ }
77743
+ return array3;
77744
+ }
77745
+ function utf8ToBytes2(str) {
77746
+ if (typeof str !== "string")
77747
+ throw new Error("string expected");
77748
+ return new Uint8Array(new TextEncoder().encode(str));
77749
+ }
77750
+ function toBytes(data) {
77751
+ if (typeof data === "string")
77752
+ data = utf8ToBytes2(data);
77753
+ abytes2(data);
77754
+ return data;
77755
+ }
77756
+ function concatBytes3(...arrays) {
77757
+ let sum2 = 0;
77758
+ for (let i = 0; i < arrays.length; i++) {
77759
+ const a = arrays[i];
77760
+ abytes2(a);
77761
+ sum2 += a.length;
77762
+ }
77763
+ const res = new Uint8Array(sum2);
77764
+ for (let i = 0, pad = 0; i < arrays.length; i++) {
77765
+ const a = arrays[i];
77766
+ res.set(a, pad);
77767
+ pad += a.length;
77768
+ }
77769
+ return res;
77770
+ }
77771
+ var Hash = class {
77772
+ };
77773
+ function createHasher2(hashCons) {
77774
+ const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
77775
+ const tmp = hashCons();
77776
+ hashC.outputLen = tmp.outputLen;
77777
+ hashC.blockLen = tmp.blockLen;
77778
+ hashC.create = () => hashCons();
77779
+ return hashC;
77780
+ }
77781
+ function randomBytes2(bytesLength = 32) {
77782
+ if (crypto3 && typeof crypto3.getRandomValues === "function") {
77783
+ return crypto3.getRandomValues(new Uint8Array(bytesLength));
77784
+ }
77785
+ if (crypto3 && typeof crypto3.randomBytes === "function") {
77786
+ return Uint8Array.from(crypto3.randomBytes(bytesLength));
77787
+ }
77788
+ throw new Error("crypto.getRandomValues must be defined");
77789
+ }
77790
+
77791
+ // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_md.js
77792
+ function setBigUint64(view, byteOffset, value, isLE2) {
77793
+ if (typeof view.setBigUint64 === "function")
77794
+ return view.setBigUint64(byteOffset, value, isLE2);
77795
+ const _32n2 = BigInt(32);
77796
+ const _u32_max = BigInt(4294967295);
77797
+ const wh = Number(value >> _32n2 & _u32_max);
77798
+ const wl = Number(value & _u32_max);
77799
+ const h = isLE2 ? 4 : 0;
77800
+ const l2 = isLE2 ? 0 : 4;
77801
+ view.setUint32(byteOffset + h, wh, isLE2);
77802
+ view.setUint32(byteOffset + l2, wl, isLE2);
77803
+ }
77804
+ function Chi2(a, b, c) {
77805
+ return a & b ^ ~a & c;
77806
+ }
77807
+ function Maj2(a, b, c) {
77808
+ return a & b ^ a & c ^ b & c;
77809
+ }
77810
+ var HashMD2 = class extends Hash {
77811
+ constructor(blockLen, outputLen, padOffset, isLE2) {
77812
+ super();
77813
+ this.finished = false;
77814
+ this.length = 0;
77815
+ this.pos = 0;
77816
+ this.destroyed = false;
77817
+ this.blockLen = blockLen;
77818
+ this.outputLen = outputLen;
77819
+ this.padOffset = padOffset;
77820
+ this.isLE = isLE2;
77821
+ this.buffer = new Uint8Array(blockLen);
77822
+ this.view = createView2(this.buffer);
77823
+ }
77824
+ update(data) {
77825
+ aexists2(this);
77826
+ data = toBytes(data);
77827
+ abytes2(data);
77828
+ const { view, buffer, blockLen } = this;
77829
+ const len = data.length;
77830
+ for (let pos = 0; pos < len; ) {
77831
+ const take = Math.min(blockLen - this.pos, len - pos);
77832
+ if (take === blockLen) {
77833
+ const dataView = createView2(data);
77834
+ for (; blockLen <= len - pos; pos += blockLen)
77835
+ this.process(dataView, pos);
77836
+ continue;
77837
+ }
77838
+ buffer.set(data.subarray(pos, pos + take), this.pos);
77839
+ this.pos += take;
77840
+ pos += take;
77841
+ if (this.pos === blockLen) {
77842
+ this.process(view, 0);
77843
+ this.pos = 0;
77844
+ }
77845
+ }
77846
+ this.length += data.length;
77847
+ this.roundClean();
77848
+ return this;
77849
+ }
77850
+ digestInto(out) {
77851
+ aexists2(this);
77852
+ aoutput2(out, this);
77853
+ this.finished = true;
77854
+ const { buffer, view, blockLen, isLE: isLE2 } = this;
77855
+ let { pos } = this;
77856
+ buffer[pos++] = 128;
77857
+ clean2(this.buffer.subarray(pos));
77858
+ if (this.padOffset > blockLen - pos) {
77859
+ this.process(view, 0);
77860
+ pos = 0;
77861
+ }
77862
+ for (let i = pos; i < blockLen; i++)
77863
+ buffer[i] = 0;
77864
+ setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE2);
77865
+ this.process(view, 0);
77866
+ const oview = createView2(out);
77867
+ const len = this.outputLen;
77868
+ if (len % 4)
77869
+ throw new Error("_sha2: outputLen should be aligned to 32bit");
77870
+ const outLen = len / 4;
77871
+ const state = this.get();
77872
+ if (outLen > state.length)
77873
+ throw new Error("_sha2: outputLen bigger than state");
77874
+ for (let i = 0; i < outLen; i++)
77875
+ oview.setUint32(4 * i, state[i], isLE2);
77876
+ }
77877
+ digest() {
77878
+ const { buffer, outputLen } = this;
77879
+ this.digestInto(buffer);
77880
+ const res = buffer.slice(0, outputLen);
77881
+ this.destroy();
77882
+ return res;
77883
+ }
77884
+ _cloneInto(to) {
77885
+ to || (to = new this.constructor());
77886
+ to.set(...this.get());
77887
+ const { blockLen, buffer, length, finished, destroyed, pos } = this;
77888
+ to.destroyed = destroyed;
77889
+ to.finished = finished;
77890
+ to.length = length;
77891
+ to.pos = pos;
77892
+ if (length % blockLen)
77893
+ to.buffer.set(buffer);
77894
+ return to;
77895
+ }
77896
+ clone() {
77897
+ return this._cloneInto();
77898
+ }
77899
+ };
77900
+ var SHA256_IV2 = /* @__PURE__ */ Uint32Array.from([
77901
+ 1779033703,
77902
+ 3144134277,
77903
+ 1013904242,
77904
+ 2773480762,
77905
+ 1359893119,
77906
+ 2600822924,
77907
+ 528734635,
77908
+ 1541459225
77909
+ ]);
77910
+
77911
+ // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/sha2.js
77912
+ var SHA256_K = /* @__PURE__ */ Uint32Array.from([
77913
+ 1116352408,
77914
+ 1899447441,
77915
+ 3049323471,
77916
+ 3921009573,
77917
+ 961987163,
77918
+ 1508970993,
77919
+ 2453635748,
77920
+ 2870763221,
77921
+ 3624381080,
77922
+ 310598401,
77923
+ 607225278,
77924
+ 1426881987,
77925
+ 1925078388,
77926
+ 2162078206,
77927
+ 2614888103,
77928
+ 3248222580,
77929
+ 3835390401,
77930
+ 4022224774,
77931
+ 264347078,
77932
+ 604807628,
77933
+ 770255983,
77934
+ 1249150122,
77935
+ 1555081692,
77936
+ 1996064986,
77937
+ 2554220882,
77938
+ 2821834349,
77939
+ 2952996808,
77940
+ 3210313671,
77941
+ 3336571891,
77942
+ 3584528711,
77943
+ 113926993,
77944
+ 338241895,
77945
+ 666307205,
77946
+ 773529912,
77947
+ 1294757372,
77948
+ 1396182291,
77949
+ 1695183700,
77950
+ 1986661051,
77951
+ 2177026350,
77952
+ 2456956037,
77953
+ 2730485921,
77954
+ 2820302411,
77955
+ 3259730800,
77956
+ 3345764771,
77957
+ 3516065817,
77958
+ 3600352804,
77959
+ 4094571909,
77960
+ 275423344,
77961
+ 430227734,
77962
+ 506948616,
77963
+ 659060556,
77964
+ 883997877,
77965
+ 958139571,
77966
+ 1322822218,
77967
+ 1537002063,
77968
+ 1747873779,
77969
+ 1955562222,
77970
+ 2024104815,
77971
+ 2227730452,
77972
+ 2361852424,
77973
+ 2428436474,
77974
+ 2756734187,
77975
+ 3204031479,
77976
+ 3329325298
77977
+ ]);
77978
+ var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
77979
+ var SHA256 = class extends HashMD2 {
77980
+ constructor(outputLen = 32) {
77981
+ super(64, outputLen, 8, false);
77982
+ this.A = SHA256_IV2[0] | 0;
77983
+ this.B = SHA256_IV2[1] | 0;
77984
+ this.C = SHA256_IV2[2] | 0;
77985
+ this.D = SHA256_IV2[3] | 0;
77986
+ this.E = SHA256_IV2[4] | 0;
77987
+ this.F = SHA256_IV2[5] | 0;
77988
+ this.G = SHA256_IV2[6] | 0;
77989
+ this.H = SHA256_IV2[7] | 0;
77990
+ }
77991
+ get() {
77992
+ const { A, B: B2, C: C2, D: D2, E, F: F2, G: G2, H: H2 } = this;
77993
+ return [A, B2, C2, D2, E, F2, G2, H2];
77994
+ }
77995
+ // prettier-ignore
77996
+ set(A, B2, C2, D2, E, F2, G2, H2) {
77997
+ this.A = A | 0;
77998
+ this.B = B2 | 0;
77999
+ this.C = C2 | 0;
78000
+ this.D = D2 | 0;
78001
+ this.E = E | 0;
78002
+ this.F = F2 | 0;
78003
+ this.G = G2 | 0;
78004
+ this.H = H2 | 0;
78005
+ }
78006
+ process(view, offset) {
78007
+ for (let i = 0; i < 16; i++, offset += 4)
78008
+ SHA256_W[i] = view.getUint32(offset, false);
78009
+ for (let i = 16; i < 64; i++) {
78010
+ const W15 = SHA256_W[i - 15];
78011
+ const W2 = SHA256_W[i - 2];
78012
+ const s0 = rotr2(W15, 7) ^ rotr2(W15, 18) ^ W15 >>> 3;
78013
+ const s1 = rotr2(W2, 17) ^ rotr2(W2, 19) ^ W2 >>> 10;
78014
+ SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
78015
+ }
78016
+ let { A, B: B2, C: C2, D: D2, E, F: F2, G: G2, H: H2 } = this;
78017
+ for (let i = 0; i < 64; i++) {
78018
+ const sigma1 = rotr2(E, 6) ^ rotr2(E, 11) ^ rotr2(E, 25);
78019
+ const T1 = H2 + sigma1 + Chi2(E, F2, G2) + SHA256_K[i] + SHA256_W[i] | 0;
78020
+ const sigma0 = rotr2(A, 2) ^ rotr2(A, 13) ^ rotr2(A, 22);
78021
+ const T2 = sigma0 + Maj2(A, B2, C2) | 0;
78022
+ H2 = G2;
78023
+ G2 = F2;
78024
+ F2 = E;
78025
+ E = D2 + T1 | 0;
78026
+ D2 = C2;
78027
+ C2 = B2;
78028
+ B2 = A;
78029
+ A = T1 + T2 | 0;
78030
+ }
78031
+ A = A + this.A | 0;
78032
+ B2 = B2 + this.B | 0;
78033
+ C2 = C2 + this.C | 0;
78034
+ D2 = D2 + this.D | 0;
78035
+ E = E + this.E | 0;
78036
+ F2 = F2 + this.F | 0;
78037
+ G2 = G2 + this.G | 0;
78038
+ H2 = H2 + this.H | 0;
78039
+ this.set(A, B2, C2, D2, E, F2, G2, H2);
78040
+ }
78041
+ roundClean() {
78042
+ clean2(SHA256_W);
78043
+ }
78044
+ destroy() {
78045
+ this.set(0, 0, 0, 0, 0, 0, 0, 0);
78046
+ clean2(this.buffer);
78047
+ }
78048
+ };
78049
+ var sha2562 = /* @__PURE__ */ createHasher2(() => new SHA256());
78050
+
78051
+ // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/hmac.js
78052
+ var HMAC = class extends Hash {
78053
+ constructor(hash, _key) {
78054
+ super();
78055
+ this.finished = false;
78056
+ this.destroyed = false;
78057
+ ahash2(hash);
78058
+ const key = toBytes(_key);
78059
+ this.iHash = hash.create();
78060
+ if (typeof this.iHash.update !== "function")
78061
+ throw new Error("Expected instance of class which extends utils.Hash");
78062
+ this.blockLen = this.iHash.blockLen;
78063
+ this.outputLen = this.iHash.outputLen;
78064
+ const blockLen = this.blockLen;
78065
+ const pad = new Uint8Array(blockLen);
78066
+ pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
78067
+ for (let i = 0; i < pad.length; i++)
78068
+ pad[i] ^= 54;
78069
+ this.iHash.update(pad);
78070
+ this.oHash = hash.create();
78071
+ for (let i = 0; i < pad.length; i++)
78072
+ pad[i] ^= 54 ^ 92;
78073
+ this.oHash.update(pad);
78074
+ clean2(pad);
78075
+ }
78076
+ update(buf) {
78077
+ aexists2(this);
78078
+ this.iHash.update(buf);
78079
+ return this;
78080
+ }
78081
+ digestInto(out) {
78082
+ aexists2(this);
78083
+ abytes2(out, this.outputLen);
78084
+ this.finished = true;
78085
+ this.iHash.digestInto(out);
78086
+ this.oHash.update(out);
78087
+ this.oHash.digestInto(out);
78088
+ this.destroy();
78089
+ }
78090
+ digest() {
78091
+ const out = new Uint8Array(this.oHash.outputLen);
78092
+ this.digestInto(out);
78093
+ return out;
78094
+ }
78095
+ _cloneInto(to) {
78096
+ to || (to = Object.create(Object.getPrototypeOf(this), {}));
78097
+ const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
78098
+ to = to;
78099
+ to.finished = finished;
78100
+ to.destroyed = destroyed;
78101
+ to.blockLen = blockLen;
78102
+ to.outputLen = outputLen;
78103
+ to.oHash = oHash._cloneInto(to.oHash);
78104
+ to.iHash = iHash._cloneInto(to.iHash);
78105
+ return to;
78106
+ }
78107
+ clone() {
78108
+ return this._cloneInto();
78109
+ }
78110
+ destroy() {
78111
+ this.destroyed = true;
78112
+ this.oHash.destroy();
78113
+ this.iHash.destroy();
78114
+ }
78115
+ };
78116
+ var hmac2 = (hash, key, message) => new HMAC(hash, key).update(message).digest();
78117
+ hmac2.create = (hash, key) => new HMAC(hash, key);
78118
+
78119
+ // ../../node_modules/.pnpm/@noble+curves@1.9.7/node_modules/@noble/curves/esm/utils.js
78120
+ var _0n5 = /* @__PURE__ */ BigInt(0);
78121
+ var _1n6 = /* @__PURE__ */ BigInt(1);
78122
+ function _abool2(value, title = "") {
78123
+ if (typeof value !== "boolean") {
78124
+ const prefix = title && `"${title}"`;
78125
+ throw new Error(prefix + "expected boolean, got type=" + typeof value);
78126
+ }
78127
+ return value;
78128
+ }
78129
+ function _abytes2(value, length, title = "") {
78130
+ const bytes = isBytes3(value);
78131
+ const len = value?.length;
78132
+ const needsLen = length !== void 0;
78133
+ if (!bytes || needsLen && len !== length) {
78134
+ const prefix = title && `"${title}" `;
78135
+ const ofLen = needsLen ? ` of length ${length}` : "";
78136
+ const got = bytes ? `length=${len}` : `type=${typeof value}`;
78137
+ throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
78138
+ }
78139
+ return value;
78140
+ }
78141
+ function numberToHexUnpadded(num) {
78142
+ const hex = num.toString(16);
78143
+ return hex.length & 1 ? "0" + hex : hex;
78144
+ }
78145
+ function hexToNumber2(hex) {
78146
+ if (typeof hex !== "string")
78147
+ throw new Error("hex string expected, got " + typeof hex);
78148
+ return hex === "" ? _0n5 : BigInt("0x" + hex);
78149
+ }
78150
+ function bytesToNumberBE2(bytes) {
78151
+ return hexToNumber2(bytesToHex2(bytes));
78152
+ }
78153
+ function bytesToNumberLE2(bytes) {
78154
+ abytes2(bytes);
78155
+ return hexToNumber2(bytesToHex2(Uint8Array.from(bytes).reverse()));
78156
+ }
78157
+ function numberToBytesBE2(n, len) {
78158
+ return hexToBytes2(n.toString(16).padStart(len * 2, "0"));
78159
+ }
78160
+ function numberToBytesLE2(n, len) {
78161
+ return numberToBytesBE2(n, len).reverse();
78162
+ }
78163
+ function ensureBytes(title, hex, expectedLength) {
78164
+ let res;
78165
+ if (typeof hex === "string") {
78166
+ try {
78167
+ res = hexToBytes2(hex);
78168
+ } catch (e) {
78169
+ throw new Error(title + " must be hex string or Uint8Array, cause: " + e);
78170
+ }
78171
+ } else if (isBytes3(hex)) {
78172
+ res = Uint8Array.from(hex);
78173
+ } else {
78174
+ throw new Error(title + " must be hex string or Uint8Array");
78175
+ }
78176
+ res.length;
78177
+ return res;
78178
+ }
78179
+ var isPosBig2 = (n) => typeof n === "bigint" && _0n5 <= n;
78180
+ function inRange2(n, min2, max2) {
78181
+ return isPosBig2(n) && isPosBig2(min2) && isPosBig2(max2) && min2 <= n && n < max2;
78182
+ }
78183
+ function aInRange2(title, n, min2, max2) {
78184
+ if (!inRange2(n, min2, max2))
78185
+ throw new Error("expected valid " + title + ": " + min2 + " <= n < " + max2 + ", got " + n);
78186
+ }
78187
+ function bitLen2(n) {
78188
+ let len;
78189
+ for (len = 0; n > _0n5; n >>= _1n6, len += 1)
78190
+ ;
78191
+ return len;
78192
+ }
78193
+ var bitMask2 = (n) => (_1n6 << BigInt(n)) - _1n6;
78194
+ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
78195
+ if (typeof hashLen !== "number" || hashLen < 2)
78196
+ throw new Error("hashLen must be a number");
78197
+ if (typeof qByteLen !== "number" || qByteLen < 2)
78198
+ throw new Error("qByteLen must be a number");
78199
+ if (typeof hmacFn !== "function")
78200
+ throw new Error("hmacFn must be a function");
78201
+ const u8n = (len) => new Uint8Array(len);
78202
+ const u8of = (byte) => Uint8Array.of(byte);
78203
+ let v = u8n(hashLen);
78204
+ let k = u8n(hashLen);
78205
+ let i = 0;
78206
+ const reset = () => {
78207
+ v.fill(1);
78208
+ k.fill(0);
78209
+ i = 0;
78210
+ };
78211
+ const h = (...b) => hmacFn(k, v, ...b);
78212
+ const reseed = (seed = u8n(0)) => {
78213
+ k = h(u8of(0), seed);
78214
+ v = h();
78215
+ if (seed.length === 0)
78216
+ return;
78217
+ k = h(u8of(1), seed);
78218
+ v = h();
78219
+ };
78220
+ const gen = () => {
78221
+ if (i++ >= 1e3)
78222
+ throw new Error("drbg: tried 1000 values");
78223
+ let len = 0;
78224
+ const out = [];
78225
+ while (len < qByteLen) {
78226
+ v = h();
78227
+ const sl = v.slice();
78228
+ out.push(sl);
78229
+ len += v.length;
78230
+ }
78231
+ return concatBytes3(...out);
78232
+ };
78233
+ const genUntil = (seed, pred) => {
78234
+ reset();
78235
+ reseed(seed);
78236
+ let res = void 0;
78237
+ while (!(res = pred(gen())))
78238
+ reseed();
78239
+ reset();
78240
+ return res;
78241
+ };
78242
+ return genUntil;
78243
+ }
78244
+ function _validateObject(object4, fields, optFields = {}) {
78245
+ if (!object4 || typeof object4 !== "object")
78246
+ throw new Error("expected valid options object");
78247
+ function checkField(fieldName, expectedType, isOpt) {
78248
+ const val = object4[fieldName];
78249
+ if (isOpt && val === void 0)
78250
+ return;
78251
+ const current = typeof val;
78252
+ if (current !== expectedType || val === null)
78253
+ throw new Error(`param "${fieldName}" is invalid: expected ${expectedType}, got ${current}`);
78254
+ }
78255
+ Object.entries(fields).forEach(([k, v]) => checkField(k, v, false));
78256
+ Object.entries(optFields).forEach(([k, v]) => checkField(k, v, true));
78257
+ }
78258
+ function memoized2(fn) {
78259
+ const map2 = /* @__PURE__ */ new WeakMap();
78260
+ return (arg, ...args) => {
78261
+ const val = map2.get(arg);
78262
+ if (val !== void 0)
78263
+ return val;
78264
+ const computed = fn(arg, ...args);
78265
+ map2.set(arg, computed);
78266
+ return computed;
78267
+ };
78268
+ }
78269
+
78270
+ // ../../node_modules/.pnpm/@noble+curves@1.9.7/node_modules/@noble/curves/esm/abstract/modular.js
78271
+ var _0n6 = BigInt(0);
78272
+ var _1n7 = BigInt(1);
78273
+ var _2n4 = /* @__PURE__ */ BigInt(2);
78274
+ var _3n2 = /* @__PURE__ */ BigInt(3);
78275
+ var _4n2 = /* @__PURE__ */ BigInt(4);
78276
+ var _5n3 = /* @__PURE__ */ BigInt(5);
78277
+ var _7n2 = /* @__PURE__ */ BigInt(7);
78278
+ var _8n4 = /* @__PURE__ */ BigInt(8);
78279
+ var _9n2 = /* @__PURE__ */ BigInt(9);
78280
+ var _16n2 = /* @__PURE__ */ BigInt(16);
78281
+ function mod3(a, b) {
78282
+ const result = a % b;
78283
+ return result >= _0n6 ? result : b + result;
78284
+ }
78285
+ function pow22(x, power, modulo) {
78286
+ let res = x;
78287
+ while (power-- > _0n6) {
78288
+ res *= res;
78289
+ res %= modulo;
78290
+ }
78291
+ return res;
78292
+ }
78293
+ function invert2(number4, modulo) {
78294
+ if (number4 === _0n6)
78295
+ throw new Error("invert: expected non-zero number");
78296
+ if (modulo <= _0n6)
78297
+ throw new Error("invert: expected positive modulus, got " + modulo);
78298
+ let a = mod3(number4, modulo);
78299
+ let b = modulo;
78300
+ let x = _0n6, u2 = _1n7;
78301
+ while (a !== _0n6) {
78302
+ const q = b / a;
78303
+ const r = b % a;
78304
+ const m = x - u2 * q;
78305
+ b = a, a = r, x = u2, u2 = m;
78306
+ }
78307
+ const gcd2 = b;
78308
+ if (gcd2 !== _1n7)
78309
+ throw new Error("invert: does not exist");
78310
+ return mod3(x, modulo);
78311
+ }
78312
+ function assertIsSquare2(Fp, root, n) {
78313
+ if (!Fp.eql(Fp.sqr(root), n))
78314
+ throw new Error("Cannot find square root");
78315
+ }
78316
+ function sqrt3mod42(Fp, n) {
78317
+ const p1div4 = (Fp.ORDER + _1n7) / _4n2;
78318
+ const root = Fp.pow(n, p1div4);
78319
+ assertIsSquare2(Fp, root, n);
78320
+ return root;
78321
+ }
78322
+ function sqrt5mod82(Fp, n) {
78323
+ const p5div8 = (Fp.ORDER - _5n3) / _8n4;
78324
+ const n2 = Fp.mul(n, _2n4);
78325
+ const v = Fp.pow(n2, p5div8);
78326
+ const nv = Fp.mul(n, v);
78327
+ const i = Fp.mul(Fp.mul(nv, _2n4), v);
78328
+ const root = Fp.mul(nv, Fp.sub(i, Fp.ONE));
78329
+ assertIsSquare2(Fp, root, n);
78330
+ return root;
78331
+ }
78332
+ function sqrt9mod162(P3) {
78333
+ const Fp_ = Field2(P3);
78334
+ const tn = tonelliShanks2(P3);
78335
+ const c1 = tn(Fp_, Fp_.neg(Fp_.ONE));
78336
+ const c2 = tn(Fp_, c1);
78337
+ const c3 = tn(Fp_, Fp_.neg(c1));
78338
+ const c4 = (P3 + _7n2) / _16n2;
78339
+ return (Fp, n) => {
78340
+ let tv1 = Fp.pow(n, c4);
78341
+ let tv2 = Fp.mul(tv1, c1);
78342
+ const tv3 = Fp.mul(tv1, c2);
78343
+ const tv4 = Fp.mul(tv1, c3);
78344
+ const e1 = Fp.eql(Fp.sqr(tv2), n);
78345
+ const e2 = Fp.eql(Fp.sqr(tv3), n);
78346
+ tv1 = Fp.cmov(tv1, tv2, e1);
78347
+ tv2 = Fp.cmov(tv4, tv3, e2);
78348
+ const e3 = Fp.eql(Fp.sqr(tv2), n);
78349
+ const root = Fp.cmov(tv1, tv2, e3);
78350
+ assertIsSquare2(Fp, root, n);
78351
+ return root;
78352
+ };
78353
+ }
78354
+ function tonelliShanks2(P3) {
78355
+ if (P3 < _3n2)
78356
+ throw new Error("sqrt is not defined for small field");
78357
+ let Q = P3 - _1n7;
78358
+ let S2 = 0;
78359
+ while (Q % _2n4 === _0n6) {
78360
+ Q /= _2n4;
78361
+ S2++;
78362
+ }
78363
+ let Z2 = _2n4;
78364
+ const _Fp = Field2(P3);
78365
+ while (FpLegendre2(_Fp, Z2) === 1) {
78366
+ if (Z2++ > 1e3)
78367
+ throw new Error("Cannot find square root: probably non-prime P");
78368
+ }
78369
+ if (S2 === 1)
78370
+ return sqrt3mod42;
78371
+ let cc = _Fp.pow(Z2, Q);
78372
+ const Q1div2 = (Q + _1n7) / _2n4;
78373
+ return function tonelliSlow(Fp, n) {
78374
+ if (Fp.is0(n))
78375
+ return n;
78376
+ if (FpLegendre2(Fp, n) !== 1)
78377
+ throw new Error("Cannot find square root");
78378
+ let M2 = S2;
78379
+ let c = Fp.mul(Fp.ONE, cc);
78380
+ let t = Fp.pow(n, Q);
78381
+ let R2 = Fp.pow(n, Q1div2);
78382
+ while (!Fp.eql(t, Fp.ONE)) {
78383
+ if (Fp.is0(t))
78384
+ return Fp.ZERO;
78385
+ let i = 1;
78386
+ let t_tmp = Fp.sqr(t);
78387
+ while (!Fp.eql(t_tmp, Fp.ONE)) {
78388
+ i++;
78389
+ t_tmp = Fp.sqr(t_tmp);
78390
+ if (i === M2)
78391
+ throw new Error("Cannot find square root");
78392
+ }
78393
+ const exponent = _1n7 << BigInt(M2 - i - 1);
78394
+ const b = Fp.pow(c, exponent);
78395
+ M2 = i;
78396
+ c = Fp.sqr(b);
78397
+ t = Fp.mul(t, c);
78398
+ R2 = Fp.mul(R2, b);
78399
+ }
78400
+ return R2;
78401
+ };
78402
+ }
78403
+ function FpSqrt2(P3) {
78404
+ if (P3 % _4n2 === _3n2)
78405
+ return sqrt3mod42;
78406
+ if (P3 % _8n4 === _5n3)
78407
+ return sqrt5mod82;
78408
+ if (P3 % _16n2 === _9n2)
78409
+ return sqrt9mod162(P3);
78410
+ return tonelliShanks2(P3);
78411
+ }
78412
+ var FIELD_FIELDS2 = [
78413
+ "create",
78414
+ "isValid",
78415
+ "is0",
78416
+ "neg",
78417
+ "inv",
78418
+ "sqrt",
78419
+ "sqr",
78420
+ "eql",
78421
+ "add",
78422
+ "sub",
78423
+ "mul",
78424
+ "pow",
78425
+ "div",
78426
+ "addN",
78427
+ "subN",
78428
+ "mulN",
78429
+ "sqrN"
78430
+ ];
78431
+ function validateField2(field) {
78432
+ const initial = {
78433
+ ORDER: "bigint",
78434
+ MASK: "bigint",
78435
+ BYTES: "number",
78436
+ BITS: "number"
78437
+ };
78438
+ const opts = FIELD_FIELDS2.reduce((map2, val) => {
78439
+ map2[val] = "function";
78440
+ return map2;
78441
+ }, initial);
78442
+ _validateObject(field, opts);
78443
+ return field;
78444
+ }
78445
+ function FpPow2(Fp, num, power) {
78446
+ if (power < _0n6)
78447
+ throw new Error("invalid exponent, negatives unsupported");
78448
+ if (power === _0n6)
78449
+ return Fp.ONE;
78450
+ if (power === _1n7)
78451
+ return num;
78452
+ let p = Fp.ONE;
78453
+ let d = num;
78454
+ while (power > _0n6) {
78455
+ if (power & _1n7)
78456
+ p = Fp.mul(p, d);
78457
+ d = Fp.sqr(d);
78458
+ power >>= _1n7;
78459
+ }
78460
+ return p;
78461
+ }
78462
+ function FpInvertBatch2(Fp, nums, passZero = false) {
78463
+ const inverted = new Array(nums.length).fill(passZero ? Fp.ZERO : void 0);
78464
+ const multipliedAcc = nums.reduce((acc, num, i) => {
78465
+ if (Fp.is0(num))
78466
+ return acc;
78467
+ inverted[i] = acc;
78468
+ return Fp.mul(acc, num);
78469
+ }, Fp.ONE);
78470
+ const invertedAcc = Fp.inv(multipliedAcc);
78471
+ nums.reduceRight((acc, num, i) => {
78472
+ if (Fp.is0(num))
78473
+ return acc;
78474
+ inverted[i] = Fp.mul(acc, inverted[i]);
78475
+ return Fp.mul(acc, num);
78476
+ }, invertedAcc);
78477
+ return inverted;
78478
+ }
78479
+ function FpLegendre2(Fp, n) {
78480
+ const p1mod2 = (Fp.ORDER - _1n7) / _2n4;
78481
+ const powered = Fp.pow(n, p1mod2);
78482
+ const yes = Fp.eql(powered, Fp.ONE);
78483
+ const zero = Fp.eql(powered, Fp.ZERO);
78484
+ const no = Fp.eql(powered, Fp.neg(Fp.ONE));
78485
+ if (!yes && !zero && !no)
78486
+ throw new Error("invalid Legendre symbol result");
78487
+ return yes ? 1 : zero ? 0 : -1;
78488
+ }
78489
+ function nLength2(n, nBitLength) {
78490
+ if (nBitLength !== void 0)
78491
+ anumber3(nBitLength);
78492
+ const _nBitLength = nBitLength !== void 0 ? nBitLength : n.toString(2).length;
78493
+ const nByteLength = Math.ceil(_nBitLength / 8);
78494
+ return { nBitLength: _nBitLength, nByteLength };
78495
+ }
78496
+ function Field2(ORDER, bitLenOrOpts, isLE2 = false, opts = {}) {
78497
+ if (ORDER <= _0n6)
78498
+ throw new Error("invalid field: expected ORDER > 0, got " + ORDER);
78499
+ let _nbitLength = void 0;
78500
+ let _sqrt = void 0;
78501
+ let modFromBytes = false;
78502
+ let allowedLengths = void 0;
78503
+ if (typeof bitLenOrOpts === "object" && bitLenOrOpts != null) {
78504
+ if (opts.sqrt || isLE2)
78505
+ throw new Error("cannot specify opts in two arguments");
78506
+ const _opts = bitLenOrOpts;
78507
+ if (_opts.BITS)
78508
+ _nbitLength = _opts.BITS;
78509
+ if (_opts.sqrt)
78510
+ _sqrt = _opts.sqrt;
78511
+ if (typeof _opts.isLE === "boolean")
78512
+ isLE2 = _opts.isLE;
78513
+ if (typeof _opts.modFromBytes === "boolean")
78514
+ modFromBytes = _opts.modFromBytes;
78515
+ allowedLengths = _opts.allowedLengths;
78516
+ } else {
78517
+ if (typeof bitLenOrOpts === "number")
78518
+ _nbitLength = bitLenOrOpts;
78519
+ if (opts.sqrt)
78520
+ _sqrt = opts.sqrt;
78521
+ }
78522
+ const { nBitLength: BITS, nByteLength: BYTES } = nLength2(ORDER, _nbitLength);
78523
+ if (BYTES > 2048)
78524
+ throw new Error("invalid field: expected ORDER of <= 2048 bytes");
78525
+ let sqrtP;
78526
+ const f = Object.freeze({
78527
+ ORDER,
78528
+ isLE: isLE2,
78529
+ BITS,
78530
+ BYTES,
78531
+ MASK: bitMask2(BITS),
78532
+ ZERO: _0n6,
78533
+ ONE: _1n7,
78534
+ allowedLengths,
78535
+ create: (num) => mod3(num, ORDER),
78536
+ isValid: (num) => {
78537
+ if (typeof num !== "bigint")
78538
+ throw new Error("invalid field element: expected bigint, got " + typeof num);
78539
+ return _0n6 <= num && num < ORDER;
78540
+ },
78541
+ is0: (num) => num === _0n6,
78542
+ // is valid and invertible
78543
+ isValidNot0: (num) => !f.is0(num) && f.isValid(num),
78544
+ isOdd: (num) => (num & _1n7) === _1n7,
78545
+ neg: (num) => mod3(-num, ORDER),
78546
+ eql: (lhs, rhs) => lhs === rhs,
78547
+ sqr: (num) => mod3(num * num, ORDER),
78548
+ add: (lhs, rhs) => mod3(lhs + rhs, ORDER),
78549
+ sub: (lhs, rhs) => mod3(lhs - rhs, ORDER),
78550
+ mul: (lhs, rhs) => mod3(lhs * rhs, ORDER),
78551
+ pow: (num, power) => FpPow2(f, num, power),
78552
+ div: (lhs, rhs) => mod3(lhs * invert2(rhs, ORDER), ORDER),
78553
+ // Same as above, but doesn't normalize
78554
+ sqrN: (num) => num * num,
78555
+ addN: (lhs, rhs) => lhs + rhs,
78556
+ subN: (lhs, rhs) => lhs - rhs,
78557
+ mulN: (lhs, rhs) => lhs * rhs,
78558
+ inv: (num) => invert2(num, ORDER),
78559
+ sqrt: _sqrt || ((n) => {
78560
+ if (!sqrtP)
78561
+ sqrtP = FpSqrt2(ORDER);
78562
+ return sqrtP(f, n);
78563
+ }),
78564
+ toBytes: (num) => isLE2 ? numberToBytesLE2(num, BYTES) : numberToBytesBE2(num, BYTES),
78565
+ fromBytes: (bytes, skipValidation = true) => {
78566
+ if (allowedLengths) {
78567
+ if (!allowedLengths.includes(bytes.length) || bytes.length > BYTES) {
78568
+ throw new Error("Field.fromBytes: expected " + allowedLengths + " bytes, got " + bytes.length);
78569
+ }
78570
+ const padded = new Uint8Array(BYTES);
78571
+ padded.set(bytes, isLE2 ? 0 : padded.length - bytes.length);
78572
+ bytes = padded;
78573
+ }
78574
+ if (bytes.length !== BYTES)
78575
+ throw new Error("Field.fromBytes: expected " + BYTES + " bytes, got " + bytes.length);
78576
+ let scalar = isLE2 ? bytesToNumberLE2(bytes) : bytesToNumberBE2(bytes);
78577
+ if (modFromBytes)
78578
+ scalar = mod3(scalar, ORDER);
78579
+ if (!skipValidation) {
78580
+ if (!f.isValid(scalar))
78581
+ throw new Error("invalid field element: outside of range 0..ORDER");
78582
+ }
78583
+ return scalar;
78584
+ },
78585
+ // TODO: we don't need it here, move out to separate fn
78586
+ invertBatch: (lst) => FpInvertBatch2(f, lst),
78587
+ // We can't move this out because Fp6, Fp12 implement it
78588
+ // and it's unclear what to return in there.
78589
+ cmov: (a, b, c) => c ? b : a
78590
+ });
78591
+ return Object.freeze(f);
78592
+ }
78593
+ function getFieldBytesLength(fieldOrder) {
78594
+ if (typeof fieldOrder !== "bigint")
78595
+ throw new Error("field order must be bigint");
78596
+ const bitLength = fieldOrder.toString(2).length;
78597
+ return Math.ceil(bitLength / 8);
78598
+ }
78599
+ function getMinHashLength(fieldOrder) {
78600
+ const length = getFieldBytesLength(fieldOrder);
78601
+ return length + Math.ceil(length / 2);
78602
+ }
78603
+ function mapHashToField(key, fieldOrder, isLE2 = false) {
78604
+ const len = key.length;
78605
+ const fieldLen = getFieldBytesLength(fieldOrder);
78606
+ const minLen = getMinHashLength(fieldOrder);
78607
+ if (len < 16 || len < minLen || len > 1024)
78608
+ throw new Error("expected " + minLen + "-1024 bytes of input, got " + len);
78609
+ const num = isLE2 ? bytesToNumberLE2(key) : bytesToNumberBE2(key);
78610
+ const reduced = mod3(num, fieldOrder - _1n7) + _1n7;
78611
+ return isLE2 ? numberToBytesLE2(reduced, fieldLen) : numberToBytesBE2(reduced, fieldLen);
78612
+ }
78613
+
78614
+ // ../../node_modules/.pnpm/@noble+curves@1.9.7/node_modules/@noble/curves/esm/abstract/curve.js
78615
+ var _0n7 = BigInt(0);
78616
+ var _1n8 = BigInt(1);
78617
+ function negateCt2(condition, item) {
78618
+ const neg = item.negate();
78619
+ return condition ? neg : item;
78620
+ }
78621
+ function normalizeZ2(c, points) {
78622
+ const invertedZs = FpInvertBatch2(c.Fp, points.map((p) => p.Z));
78623
+ return points.map((p, i) => c.fromAffine(p.toAffine(invertedZs[i])));
78624
+ }
78625
+ function validateW2(W, bits) {
78626
+ if (!Number.isSafeInteger(W) || W <= 0 || W > bits)
78627
+ throw new Error("invalid window size, expected [1.." + bits + "], got W=" + W);
78628
+ }
78629
+ function calcWOpts2(W, scalarBits) {
78630
+ validateW2(W, scalarBits);
78631
+ const windows = Math.ceil(scalarBits / W) + 1;
78632
+ const windowSize = 2 ** (W - 1);
78633
+ const maxNumber = 2 ** W;
78634
+ const mask = bitMask2(W);
78635
+ const shiftBy = BigInt(W);
78636
+ return { windows, windowSize, mask, maxNumber, shiftBy };
78637
+ }
78638
+ function calcOffsets2(n, window2, wOpts) {
78639
+ const { windowSize, mask, maxNumber, shiftBy } = wOpts;
78640
+ let wbits = Number(n & mask);
78641
+ let nextN = n >> shiftBy;
78642
+ if (wbits > windowSize) {
78643
+ wbits -= maxNumber;
78644
+ nextN += _1n8;
78645
+ }
78646
+ const offsetStart = window2 * windowSize;
78647
+ const offset = offsetStart + Math.abs(wbits) - 1;
78648
+ const isZero = wbits === 0;
78649
+ const isNeg = wbits < 0;
78650
+ const isNegF = window2 % 2 !== 0;
78651
+ const offsetF = offsetStart;
78652
+ return { nextN, offset, isZero, isNeg, isNegF, offsetF };
78653
+ }
78654
+ function validateMSMPoints(points, c) {
78655
+ if (!Array.isArray(points))
78656
+ throw new Error("array expected");
78657
+ points.forEach((p, i) => {
78658
+ if (!(p instanceof c))
78659
+ throw new Error("invalid point at index " + i);
78660
+ });
78661
+ }
78662
+ function validateMSMScalars(scalars, field) {
78663
+ if (!Array.isArray(scalars))
78664
+ throw new Error("array of scalars expected");
78665
+ scalars.forEach((s, i) => {
78666
+ if (!field.isValid(s))
78667
+ throw new Error("invalid scalar at index " + i);
78668
+ });
78669
+ }
78670
+ var pointPrecomputes2 = /* @__PURE__ */ new WeakMap();
78671
+ var pointWindowSizes2 = /* @__PURE__ */ new WeakMap();
78672
+ function getW2(P3) {
78673
+ return pointWindowSizes2.get(P3) || 1;
78674
+ }
78675
+ function assert02(n) {
78676
+ if (n !== _0n7)
78677
+ throw new Error("invalid wNAF");
78678
+ }
78679
+ var wNAF2 = class {
78680
+ // Parametrized with a given Point class (not individual point)
78681
+ constructor(Point, bits) {
78682
+ this.BASE = Point.BASE;
78683
+ this.ZERO = Point.ZERO;
78684
+ this.Fn = Point.Fn;
78685
+ this.bits = bits;
78686
+ }
78687
+ // non-const time multiplication ladder
78688
+ _unsafeLadder(elm, n, p = this.ZERO) {
78689
+ let d = elm;
78690
+ while (n > _0n7) {
78691
+ if (n & _1n8)
78692
+ p = p.add(d);
78693
+ d = d.double();
78694
+ n >>= _1n8;
78695
+ }
78696
+ return p;
78697
+ }
78698
+ /**
78699
+ * Creates a wNAF precomputation window. Used for caching.
78700
+ * Default window size is set by `utils.precompute()` and is equal to 8.
78701
+ * Number of precomputed points depends on the curve size:
78702
+ * 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
78703
+ * - 𝑊 is the window size
78704
+ * - 𝑛 is the bitlength of the curve order.
78705
+ * For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
78706
+ * @param point Point instance
78707
+ * @param W window size
78708
+ * @returns precomputed point tables flattened to a single array
78709
+ */
78710
+ precomputeWindow(point, W) {
78711
+ const { windows, windowSize } = calcWOpts2(W, this.bits);
78712
+ const points = [];
78713
+ let p = point;
78714
+ let base = p;
78715
+ for (let window2 = 0; window2 < windows; window2++) {
78716
+ base = p;
78717
+ points.push(base);
78718
+ for (let i = 1; i < windowSize; i++) {
78719
+ base = base.add(p);
78720
+ points.push(base);
78721
+ }
78722
+ p = base.double();
78723
+ }
78724
+ return points;
78725
+ }
78726
+ /**
78727
+ * Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
78728
+ * More compact implementation:
78729
+ * https://github.com/paulmillr/noble-secp256k1/blob/47cb1669b6e506ad66b35fe7d76132ae97465da2/index.ts#L502-L541
78730
+ * @returns real and fake (for const-time) points
78731
+ */
78732
+ wNAF(W, precomputes, n) {
78733
+ if (!this.Fn.isValid(n))
78734
+ throw new Error("invalid scalar");
78735
+ let p = this.ZERO;
78736
+ let f = this.BASE;
78737
+ const wo = calcWOpts2(W, this.bits);
78738
+ for (let window2 = 0; window2 < wo.windows; window2++) {
78739
+ const { nextN, offset, isZero, isNeg, isNegF, offsetF } = calcOffsets2(n, window2, wo);
78740
+ n = nextN;
78741
+ if (isZero) {
78742
+ f = f.add(negateCt2(isNegF, precomputes[offsetF]));
78743
+ } else {
78744
+ p = p.add(negateCt2(isNeg, precomputes[offset]));
78745
+ }
78746
+ }
78747
+ assert02(n);
78748
+ return { p, f };
78749
+ }
78750
+ /**
78751
+ * Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
78752
+ * @param acc accumulator point to add result of multiplication
78753
+ * @returns point
78754
+ */
78755
+ wNAFUnsafe(W, precomputes, n, acc = this.ZERO) {
78756
+ const wo = calcWOpts2(W, this.bits);
78757
+ for (let window2 = 0; window2 < wo.windows; window2++) {
78758
+ if (n === _0n7)
78759
+ break;
78760
+ const { nextN, offset, isZero, isNeg } = calcOffsets2(n, window2, wo);
78761
+ n = nextN;
78762
+ if (isZero) {
78763
+ continue;
78764
+ } else {
78765
+ const item = precomputes[offset];
78766
+ acc = acc.add(isNeg ? item.negate() : item);
78767
+ }
78768
+ }
78769
+ assert02(n);
78770
+ return acc;
78771
+ }
78772
+ getPrecomputes(W, point, transform3) {
78773
+ let comp = pointPrecomputes2.get(point);
78774
+ if (!comp) {
78775
+ comp = this.precomputeWindow(point, W);
78776
+ if (W !== 1) {
78777
+ if (typeof transform3 === "function")
78778
+ comp = transform3(comp);
78779
+ pointPrecomputes2.set(point, comp);
78780
+ }
78781
+ }
78782
+ return comp;
78783
+ }
78784
+ cached(point, scalar, transform3) {
78785
+ const W = getW2(point);
78786
+ return this.wNAF(W, this.getPrecomputes(W, point, transform3), scalar);
78787
+ }
78788
+ unsafe(point, scalar, transform3, prev) {
78789
+ const W = getW2(point);
78790
+ if (W === 1)
78791
+ return this._unsafeLadder(point, scalar, prev);
78792
+ return this.wNAFUnsafe(W, this.getPrecomputes(W, point, transform3), scalar, prev);
78793
+ }
78794
+ // We calculate precomputes for elliptic curve point multiplication
78795
+ // using windowed method. This specifies window size and
78796
+ // stores precomputed values. Usually only base point would be precomputed.
78797
+ createCache(P3, W) {
78798
+ validateW2(W, this.bits);
78799
+ pointWindowSizes2.set(P3, W);
78800
+ pointPrecomputes2.delete(P3);
78801
+ }
78802
+ hasCache(elm) {
78803
+ return getW2(elm) !== 1;
78804
+ }
78805
+ };
78806
+ function mulEndoUnsafe(Point, point, k1, k2) {
78807
+ let acc = point;
78808
+ let p1 = Point.ZERO;
78809
+ let p2 = Point.ZERO;
78810
+ while (k1 > _0n7 || k2 > _0n7) {
78811
+ if (k1 & _1n8)
78812
+ p1 = p1.add(acc);
78813
+ if (k2 & _1n8)
78814
+ p2 = p2.add(acc);
78815
+ acc = acc.double();
78816
+ k1 >>= _1n8;
78817
+ k2 >>= _1n8;
78818
+ }
78819
+ return { p1, p2 };
78820
+ }
78821
+ function pippenger(c, fieldN, points, scalars) {
78822
+ validateMSMPoints(points, c);
78823
+ validateMSMScalars(scalars, fieldN);
78824
+ const plength = points.length;
78825
+ const slength = scalars.length;
78826
+ if (plength !== slength)
78827
+ throw new Error("arrays of points and scalars must have equal length");
78828
+ const zero = c.ZERO;
78829
+ const wbits = bitLen2(BigInt(plength));
78830
+ let windowSize = 1;
78831
+ if (wbits > 12)
78832
+ windowSize = wbits - 3;
78833
+ else if (wbits > 4)
78834
+ windowSize = wbits - 2;
78835
+ else if (wbits > 0)
78836
+ windowSize = 2;
78837
+ const MASK = bitMask2(windowSize);
78838
+ const buckets = new Array(Number(MASK) + 1).fill(zero);
78839
+ const lastBits = Math.floor((fieldN.BITS - 1) / windowSize) * windowSize;
78840
+ let sum2 = zero;
78841
+ for (let i = lastBits; i >= 0; i -= windowSize) {
78842
+ buckets.fill(zero);
78843
+ for (let j = 0; j < slength; j++) {
78844
+ const scalar = scalars[j];
78845
+ const wbits2 = Number(scalar >> BigInt(i) & MASK);
78846
+ buckets[wbits2] = buckets[wbits2].add(points[j]);
78847
+ }
78848
+ let resI = zero;
78849
+ for (let j = buckets.length - 1, sumI = zero; j > 0; j--) {
78850
+ sumI = sumI.add(buckets[j]);
78851
+ resI = resI.add(sumI);
78852
+ }
78853
+ sum2 = sum2.add(resI);
78854
+ if (i !== 0)
78855
+ for (let j = 0; j < windowSize; j++)
78856
+ sum2 = sum2.double();
78857
+ }
78858
+ return sum2;
78859
+ }
78860
+ function createField2(order, field, isLE2) {
78861
+ if (field) {
78862
+ if (field.ORDER !== order)
78863
+ throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
78864
+ validateField2(field);
78865
+ return field;
78866
+ } else {
78867
+ return Field2(order, { isLE: isLE2 });
78868
+ }
78869
+ }
78870
+ function _createCurveFields(type, CURVE, curveOpts = {}, FpFnLE) {
78871
+ if (FpFnLE === void 0)
78872
+ FpFnLE = type === "edwards";
78873
+ if (!CURVE || typeof CURVE !== "object")
78874
+ throw new Error(`expected valid ${type} CURVE object`);
78875
+ for (const p of ["p", "n", "h"]) {
78876
+ const val = CURVE[p];
78877
+ if (!(typeof val === "bigint" && val > _0n7))
78878
+ throw new Error(`CURVE.${p} must be positive bigint`);
78879
+ }
78880
+ const Fp = createField2(CURVE.p, curveOpts.Fp, FpFnLE);
78881
+ const Fn = createField2(CURVE.n, curveOpts.Fn, FpFnLE);
78882
+ const _b = "b" ;
78883
+ const params = ["Gx", "Gy", "a", _b];
78884
+ for (const p of params) {
78885
+ if (!Fp.isValid(CURVE[p]))
78886
+ throw new Error(`CURVE.${p} must be valid field element of CURVE.Fp`);
78887
+ }
78888
+ CURVE = Object.freeze(Object.assign({}, CURVE));
78889
+ return { CURVE, Fp, Fn };
78890
+ }
78891
+
78892
+ // ../../node_modules/.pnpm/@noble+curves@1.9.7/node_modules/@noble/curves/esm/abstract/weierstrass.js
78893
+ var divNearest = (num, den) => (num + (num >= 0 ? den : -den) / _2n5) / den;
78894
+ function _splitEndoScalar(k, basis, n) {
78895
+ const [[a1, b1], [a2, b2]] = basis;
78896
+ const c1 = divNearest(b2 * k, n);
78897
+ const c2 = divNearest(-b1 * k, n);
78898
+ let k1 = k - c1 * a1 - c2 * a2;
78899
+ let k2 = -c1 * b1 - c2 * b2;
78900
+ const k1neg = k1 < _0n8;
78901
+ const k2neg = k2 < _0n8;
78902
+ if (k1neg)
78903
+ k1 = -k1;
78904
+ if (k2neg)
78905
+ k2 = -k2;
78906
+ const MAX_NUM = bitMask2(Math.ceil(bitLen2(n) / 2)) + _1n9;
78907
+ if (k1 < _0n8 || k1 >= MAX_NUM || k2 < _0n8 || k2 >= MAX_NUM) {
78908
+ throw new Error("splitScalar (endomorphism): failed, k=" + k);
78909
+ }
78910
+ return { k1neg, k1, k2neg, k2 };
78911
+ }
78912
+ function validateSigFormat(format) {
78913
+ if (!["compact", "recovered", "der"].includes(format))
78914
+ throw new Error('Signature format must be "compact", "recovered", or "der"');
78915
+ return format;
78916
+ }
78917
+ function validateSigOpts(opts, def) {
78918
+ const optsn = {};
78919
+ for (let optName of Object.keys(def)) {
78920
+ optsn[optName] = opts[optName] === void 0 ? def[optName] : opts[optName];
78921
+ }
78922
+ _abool2(optsn.lowS, "lowS");
78923
+ _abool2(optsn.prehash, "prehash");
78924
+ if (optsn.format !== void 0)
78925
+ validateSigFormat(optsn.format);
78926
+ return optsn;
78927
+ }
78928
+ var DERErr = class extends Error {
78929
+ constructor(m = "") {
78930
+ super(m);
78931
+ }
78932
+ };
78933
+ var DER = {
78934
+ // asn.1 DER encoding utils
78935
+ Err: DERErr,
78936
+ // Basic building block is TLV (Tag-Length-Value)
78937
+ _tlv: {
78938
+ encode: (tag2, data) => {
78939
+ const { Err: E } = DER;
78940
+ if (tag2 < 0 || tag2 > 256)
78941
+ throw new E("tlv.encode: wrong tag");
78942
+ if (data.length & 1)
78943
+ throw new E("tlv.encode: unpadded data");
78944
+ const dataLen = data.length / 2;
78945
+ const len = numberToHexUnpadded(dataLen);
78946
+ if (len.length / 2 & 128)
78947
+ throw new E("tlv.encode: long form length too big");
78948
+ const lenLen = dataLen > 127 ? numberToHexUnpadded(len.length / 2 | 128) : "";
78949
+ const t = numberToHexUnpadded(tag2);
78950
+ return t + lenLen + len + data;
78951
+ },
78952
+ // v - value, l - left bytes (unparsed)
78953
+ decode(tag2, data) {
78954
+ const { Err: E } = DER;
78955
+ let pos = 0;
78956
+ if (tag2 < 0 || tag2 > 256)
78957
+ throw new E("tlv.encode: wrong tag");
78958
+ if (data.length < 2 || data[pos++] !== tag2)
78959
+ throw new E("tlv.decode: wrong tlv");
78960
+ const first = data[pos++];
78961
+ const isLong = !!(first & 128);
78962
+ let length = 0;
78963
+ if (!isLong)
78964
+ length = first;
78965
+ else {
78966
+ const lenLen = first & 127;
78967
+ if (!lenLen)
78968
+ throw new E("tlv.decode(long): indefinite length not supported");
78969
+ if (lenLen > 4)
78970
+ throw new E("tlv.decode(long): byte length is too big");
78971
+ const lengthBytes = data.subarray(pos, pos + lenLen);
78972
+ if (lengthBytes.length !== lenLen)
78973
+ throw new E("tlv.decode: length bytes not complete");
78974
+ if (lengthBytes[0] === 0)
78975
+ throw new E("tlv.decode(long): zero leftmost byte");
78976
+ for (const b of lengthBytes)
78977
+ length = length << 8 | b;
78978
+ pos += lenLen;
78979
+ if (length < 128)
78980
+ throw new E("tlv.decode(long): not minimal encoding");
78981
+ }
78982
+ const v = data.subarray(pos, pos + length);
78983
+ if (v.length !== length)
78984
+ throw new E("tlv.decode: wrong value length");
78985
+ return { v, l: data.subarray(pos + length) };
78986
+ }
78987
+ },
78988
+ // https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
78989
+ // since we always use positive integers here. It must always be empty:
78990
+ // - add zero byte if exists
78991
+ // - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
78992
+ _int: {
78993
+ encode(num) {
78994
+ const { Err: E } = DER;
78995
+ if (num < _0n8)
78996
+ throw new E("integer: negative integers are not allowed");
78997
+ let hex = numberToHexUnpadded(num);
78998
+ if (Number.parseInt(hex[0], 16) & 8)
78999
+ hex = "00" + hex;
79000
+ if (hex.length & 1)
79001
+ throw new E("unexpected DER parsing assertion: unpadded hex");
79002
+ return hex;
79003
+ },
79004
+ decode(data) {
79005
+ const { Err: E } = DER;
79006
+ if (data[0] & 128)
79007
+ throw new E("invalid signature integer: negative");
79008
+ if (data[0] === 0 && !(data[1] & 128))
79009
+ throw new E("invalid signature integer: unnecessary leading zero");
79010
+ return bytesToNumberBE2(data);
79011
+ }
79012
+ },
79013
+ toSig(hex) {
79014
+ const { Err: E, _int: int2, _tlv: tlv } = DER;
79015
+ const data = ensureBytes("signature", hex);
79016
+ const { v: seqBytes, l: seqLeftBytes } = tlv.decode(48, data);
79017
+ if (seqLeftBytes.length)
79018
+ throw new E("invalid signature: left bytes after parsing");
79019
+ const { v: rBytes, l: rLeftBytes } = tlv.decode(2, seqBytes);
79020
+ const { v: sBytes, l: sLeftBytes } = tlv.decode(2, rLeftBytes);
79021
+ if (sLeftBytes.length)
79022
+ throw new E("invalid signature: left bytes after parsing");
79023
+ return { r: int2.decode(rBytes), s: int2.decode(sBytes) };
79024
+ },
79025
+ hexFromSig(sig) {
79026
+ const { _tlv: tlv, _int: int2 } = DER;
79027
+ const rs = tlv.encode(2, int2.encode(sig.r));
79028
+ const ss = tlv.encode(2, int2.encode(sig.s));
79029
+ const seq = rs + ss;
79030
+ return tlv.encode(48, seq);
79031
+ }
79032
+ };
79033
+ var _0n8 = BigInt(0);
79034
+ var _1n9 = BigInt(1);
79035
+ var _2n5 = BigInt(2);
79036
+ var _3n3 = BigInt(3);
79037
+ var _4n3 = BigInt(4);
79038
+ function _normFnElement(Fn, key) {
79039
+ const { BYTES: expected } = Fn;
79040
+ let num;
79041
+ if (typeof key === "bigint") {
79042
+ num = key;
79043
+ } else {
79044
+ let bytes = ensureBytes("private key", key);
79045
+ try {
79046
+ num = Fn.fromBytes(bytes);
79047
+ } catch (error2) {
79048
+ throw new Error(`invalid private key: expected ui8a of size ${expected}, got ${typeof key}`);
79049
+ }
79050
+ }
79051
+ if (!Fn.isValidNot0(num))
79052
+ throw new Error("invalid private key: out of range [1..N-1]");
79053
+ return num;
79054
+ }
79055
+ function weierstrassN(params, extraOpts = {}) {
79056
+ const validated = _createCurveFields("weierstrass", params, extraOpts);
79057
+ const { Fp, Fn } = validated;
79058
+ let CURVE = validated.CURVE;
79059
+ const { h: cofactor, n: CURVE_ORDER } = CURVE;
79060
+ _validateObject(extraOpts, {}, {
79061
+ allowInfinityPoint: "boolean",
79062
+ clearCofactor: "function",
79063
+ isTorsionFree: "function",
79064
+ fromBytes: "function",
79065
+ toBytes: "function",
79066
+ endo: "object",
79067
+ wrapPrivateKey: "boolean"
79068
+ });
79069
+ const { endo } = extraOpts;
79070
+ if (endo) {
79071
+ if (!Fp.is0(CURVE.a) || typeof endo.beta !== "bigint" || !Array.isArray(endo.basises)) {
79072
+ throw new Error('invalid endo: expected "beta": bigint and "basises": array');
79073
+ }
79074
+ }
79075
+ const lengths = getWLengths(Fp, Fn);
79076
+ function assertCompressionIsSupported() {
79077
+ if (!Fp.isOdd)
79078
+ throw new Error("compression is not supported: Field does not have .isOdd()");
79079
+ }
79080
+ function pointToBytes(_c, point, isCompressed) {
79081
+ const { x, y: y2 } = point.toAffine();
79082
+ const bx = Fp.toBytes(x);
79083
+ _abool2(isCompressed, "isCompressed");
79084
+ if (isCompressed) {
79085
+ assertCompressionIsSupported();
79086
+ const hasEvenY = !Fp.isOdd(y2);
79087
+ return concatBytes3(pprefix(hasEvenY), bx);
79088
+ } else {
79089
+ return concatBytes3(Uint8Array.of(4), bx, Fp.toBytes(y2));
79090
+ }
79091
+ }
79092
+ function pointFromBytes(bytes) {
79093
+ _abytes2(bytes, void 0, "Point");
79094
+ const { publicKey: comp, publicKeyUncompressed: uncomp } = lengths;
79095
+ const length = bytes.length;
79096
+ const head = bytes[0];
79097
+ const tail = bytes.subarray(1);
79098
+ if (length === comp && (head === 2 || head === 3)) {
79099
+ const x = Fp.fromBytes(tail);
79100
+ if (!Fp.isValid(x))
79101
+ throw new Error("bad point: is not on curve, wrong x");
79102
+ const y2 = weierstrassEquation(x);
79103
+ let y3;
79104
+ try {
79105
+ y3 = Fp.sqrt(y2);
79106
+ } catch (sqrtError) {
79107
+ const err = sqrtError instanceof Error ? ": " + sqrtError.message : "";
79108
+ throw new Error("bad point: is not on curve, sqrt error" + err);
79109
+ }
79110
+ assertCompressionIsSupported();
79111
+ const isYOdd = Fp.isOdd(y3);
79112
+ const isHeadOdd = (head & 1) === 1;
79113
+ if (isHeadOdd !== isYOdd)
79114
+ y3 = Fp.neg(y3);
79115
+ return { x, y: y3 };
79116
+ } else if (length === uncomp && head === 4) {
79117
+ const L = Fp.BYTES;
79118
+ const x = Fp.fromBytes(tail.subarray(0, L));
79119
+ const y2 = Fp.fromBytes(tail.subarray(L, L * 2));
79120
+ if (!isValidXY(x, y2))
79121
+ throw new Error("bad point: is not on curve");
79122
+ return { x, y: y2 };
79123
+ } else {
79124
+ throw new Error(`bad point: got length ${length}, expected compressed=${comp} or uncompressed=${uncomp}`);
79125
+ }
79126
+ }
79127
+ const encodePoint = extraOpts.toBytes || pointToBytes;
79128
+ const decodePoint = extraOpts.fromBytes || pointFromBytes;
79129
+ function weierstrassEquation(x) {
79130
+ const x2 = Fp.sqr(x);
79131
+ const x3 = Fp.mul(x2, x);
79132
+ return Fp.add(Fp.add(x3, Fp.mul(x, CURVE.a)), CURVE.b);
79133
+ }
79134
+ function isValidXY(x, y2) {
79135
+ const left = Fp.sqr(y2);
79136
+ const right = weierstrassEquation(x);
79137
+ return Fp.eql(left, right);
79138
+ }
79139
+ if (!isValidXY(CURVE.Gx, CURVE.Gy))
79140
+ throw new Error("bad curve params: generator point");
79141
+ const _4a3 = Fp.mul(Fp.pow(CURVE.a, _3n3), _4n3);
79142
+ const _27b2 = Fp.mul(Fp.sqr(CURVE.b), BigInt(27));
79143
+ if (Fp.is0(Fp.add(_4a3, _27b2)))
79144
+ throw new Error("bad curve params: a or b");
79145
+ function acoord(title, n, banZero = false) {
79146
+ if (!Fp.isValid(n) || banZero && Fp.is0(n))
79147
+ throw new Error(`bad point coordinate ${title}`);
79148
+ return n;
79149
+ }
79150
+ function aprjpoint(other) {
79151
+ if (!(other instanceof Point))
79152
+ throw new Error("ProjectivePoint expected");
79153
+ }
79154
+ function splitEndoScalarN(k) {
79155
+ if (!endo || !endo.basises)
79156
+ throw new Error("no endo");
79157
+ return _splitEndoScalar(k, endo.basises, Fn.ORDER);
79158
+ }
79159
+ const toAffineMemo = memoized2((p, iz) => {
79160
+ const { X, Y, Z: Z2 } = p;
79161
+ if (Fp.eql(Z2, Fp.ONE))
79162
+ return { x: X, y: Y };
79163
+ const is0 = p.is0();
79164
+ if (iz == null)
79165
+ iz = is0 ? Fp.ONE : Fp.inv(Z2);
79166
+ const x = Fp.mul(X, iz);
79167
+ const y2 = Fp.mul(Y, iz);
79168
+ const zz = Fp.mul(Z2, iz);
79169
+ if (is0)
79170
+ return { x: Fp.ZERO, y: Fp.ZERO };
79171
+ if (!Fp.eql(zz, Fp.ONE))
79172
+ throw new Error("invZ was invalid");
79173
+ return { x, y: y2 };
79174
+ });
79175
+ const assertValidMemo = memoized2((p) => {
79176
+ if (p.is0()) {
79177
+ if (extraOpts.allowInfinityPoint && !Fp.is0(p.Y))
79178
+ return;
79179
+ throw new Error("bad point: ZERO");
79180
+ }
79181
+ const { x, y: y2 } = p.toAffine();
79182
+ if (!Fp.isValid(x) || !Fp.isValid(y2))
79183
+ throw new Error("bad point: x or y not field elements");
79184
+ if (!isValidXY(x, y2))
79185
+ throw new Error("bad point: equation left != right");
79186
+ if (!p.isTorsionFree())
79187
+ throw new Error("bad point: not in prime-order subgroup");
79188
+ return true;
79189
+ });
79190
+ function finishEndo(endoBeta, k1p, k2p, k1neg, k2neg) {
79191
+ k2p = new Point(Fp.mul(k2p.X, endoBeta), k2p.Y, k2p.Z);
79192
+ k1p = negateCt2(k1neg, k1p);
79193
+ k2p = negateCt2(k2neg, k2p);
79194
+ return k1p.add(k2p);
79195
+ }
79196
+ class Point {
79197
+ /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
79198
+ constructor(X, Y, Z2) {
79199
+ this.X = acoord("x", X);
79200
+ this.Y = acoord("y", Y, true);
79201
+ this.Z = acoord("z", Z2);
79202
+ Object.freeze(this);
79203
+ }
79204
+ static CURVE() {
79205
+ return CURVE;
79206
+ }
79207
+ /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
79208
+ static fromAffine(p) {
79209
+ const { x, y: y2 } = p || {};
79210
+ if (!p || !Fp.isValid(x) || !Fp.isValid(y2))
79211
+ throw new Error("invalid affine point");
79212
+ if (p instanceof Point)
79213
+ throw new Error("projective point not allowed");
79214
+ if (Fp.is0(x) && Fp.is0(y2))
79215
+ return Point.ZERO;
79216
+ return new Point(x, y2, Fp.ONE);
79217
+ }
79218
+ static fromBytes(bytes) {
79219
+ const P3 = Point.fromAffine(decodePoint(_abytes2(bytes, void 0, "point")));
79220
+ P3.assertValidity();
79221
+ return P3;
79222
+ }
79223
+ static fromHex(hex) {
79224
+ return Point.fromBytes(ensureBytes("pointHex", hex));
79225
+ }
79226
+ get x() {
79227
+ return this.toAffine().x;
79228
+ }
79229
+ get y() {
79230
+ return this.toAffine().y;
79231
+ }
79232
+ /**
79233
+ *
79234
+ * @param windowSize
79235
+ * @param isLazy true will defer table computation until the first multiplication
79236
+ * @returns
79237
+ */
79238
+ precompute(windowSize = 8, isLazy = true) {
79239
+ wnaf.createCache(this, windowSize);
79240
+ if (!isLazy)
79241
+ this.multiply(_3n3);
79242
+ return this;
79243
+ }
79244
+ // TODO: return `this`
79245
+ /** A point on curve is valid if it conforms to equation. */
79246
+ assertValidity() {
79247
+ assertValidMemo(this);
79248
+ }
79249
+ hasEvenY() {
79250
+ const { y: y2 } = this.toAffine();
79251
+ if (!Fp.isOdd)
79252
+ throw new Error("Field doesn't support isOdd");
79253
+ return !Fp.isOdd(y2);
79254
+ }
79255
+ /** Compare one point to another. */
79256
+ equals(other) {
79257
+ aprjpoint(other);
79258
+ const { X: X1, Y: Y1, Z: Z1 } = this;
79259
+ const { X: X2, Y: Y2, Z: Z2 } = other;
79260
+ const U1 = Fp.eql(Fp.mul(X1, Z2), Fp.mul(X2, Z1));
79261
+ const U2 = Fp.eql(Fp.mul(Y1, Z2), Fp.mul(Y2, Z1));
79262
+ return U1 && U2;
79263
+ }
79264
+ /** Flips point to one corresponding to (x, -y) in Affine coordinates. */
79265
+ negate() {
79266
+ return new Point(this.X, Fp.neg(this.Y), this.Z);
79267
+ }
79268
+ // Renes-Costello-Batina exception-free doubling formula.
79269
+ // There is 30% faster Jacobian formula, but it is not complete.
79270
+ // https://eprint.iacr.org/2015/1060, algorithm 3
79271
+ // Cost: 8M + 3S + 3*a + 2*b3 + 15add.
79272
+ double() {
79273
+ const { a, b } = CURVE;
79274
+ const b3 = Fp.mul(b, _3n3);
79275
+ const { X: X1, Y: Y1, Z: Z1 } = this;
79276
+ let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO;
79277
+ let t0 = Fp.mul(X1, X1);
79278
+ let t1 = Fp.mul(Y1, Y1);
79279
+ let t2 = Fp.mul(Z1, Z1);
79280
+ let t3 = Fp.mul(X1, Y1);
79281
+ t3 = Fp.add(t3, t3);
79282
+ Z3 = Fp.mul(X1, Z1);
79283
+ Z3 = Fp.add(Z3, Z3);
79284
+ X3 = Fp.mul(a, Z3);
79285
+ Y3 = Fp.mul(b3, t2);
79286
+ Y3 = Fp.add(X3, Y3);
79287
+ X3 = Fp.sub(t1, Y3);
79288
+ Y3 = Fp.add(t1, Y3);
79289
+ Y3 = Fp.mul(X3, Y3);
79290
+ X3 = Fp.mul(t3, X3);
79291
+ Z3 = Fp.mul(b3, Z3);
79292
+ t2 = Fp.mul(a, t2);
79293
+ t3 = Fp.sub(t0, t2);
79294
+ t3 = Fp.mul(a, t3);
79295
+ t3 = Fp.add(t3, Z3);
79296
+ Z3 = Fp.add(t0, t0);
79297
+ t0 = Fp.add(Z3, t0);
79298
+ t0 = Fp.add(t0, t2);
79299
+ t0 = Fp.mul(t0, t3);
79300
+ Y3 = Fp.add(Y3, t0);
79301
+ t2 = Fp.mul(Y1, Z1);
79302
+ t2 = Fp.add(t2, t2);
79303
+ t0 = Fp.mul(t2, t3);
79304
+ X3 = Fp.sub(X3, t0);
79305
+ Z3 = Fp.mul(t2, t1);
79306
+ Z3 = Fp.add(Z3, Z3);
79307
+ Z3 = Fp.add(Z3, Z3);
79308
+ return new Point(X3, Y3, Z3);
79309
+ }
79310
+ // Renes-Costello-Batina exception-free addition formula.
79311
+ // There is 30% faster Jacobian formula, but it is not complete.
79312
+ // https://eprint.iacr.org/2015/1060, algorithm 1
79313
+ // Cost: 12M + 0S + 3*a + 3*b3 + 23add.
79314
+ add(other) {
79315
+ aprjpoint(other);
79316
+ const { X: X1, Y: Y1, Z: Z1 } = this;
79317
+ const { X: X2, Y: Y2, Z: Z2 } = other;
79318
+ let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO;
79319
+ const a = CURVE.a;
79320
+ const b3 = Fp.mul(CURVE.b, _3n3);
79321
+ let t0 = Fp.mul(X1, X2);
79322
+ let t1 = Fp.mul(Y1, Y2);
79323
+ let t2 = Fp.mul(Z1, Z2);
79324
+ let t3 = Fp.add(X1, Y1);
79325
+ let t4 = Fp.add(X2, Y2);
79326
+ t3 = Fp.mul(t3, t4);
79327
+ t4 = Fp.add(t0, t1);
79328
+ t3 = Fp.sub(t3, t4);
79329
+ t4 = Fp.add(X1, Z1);
79330
+ let t5 = Fp.add(X2, Z2);
79331
+ t4 = Fp.mul(t4, t5);
79332
+ t5 = Fp.add(t0, t2);
79333
+ t4 = Fp.sub(t4, t5);
79334
+ t5 = Fp.add(Y1, Z1);
79335
+ X3 = Fp.add(Y2, Z2);
79336
+ t5 = Fp.mul(t5, X3);
79337
+ X3 = Fp.add(t1, t2);
79338
+ t5 = Fp.sub(t5, X3);
79339
+ Z3 = Fp.mul(a, t4);
79340
+ X3 = Fp.mul(b3, t2);
79341
+ Z3 = Fp.add(X3, Z3);
79342
+ X3 = Fp.sub(t1, Z3);
79343
+ Z3 = Fp.add(t1, Z3);
79344
+ Y3 = Fp.mul(X3, Z3);
79345
+ t1 = Fp.add(t0, t0);
79346
+ t1 = Fp.add(t1, t0);
79347
+ t2 = Fp.mul(a, t2);
79348
+ t4 = Fp.mul(b3, t4);
79349
+ t1 = Fp.add(t1, t2);
79350
+ t2 = Fp.sub(t0, t2);
79351
+ t2 = Fp.mul(a, t2);
79352
+ t4 = Fp.add(t4, t2);
79353
+ t0 = Fp.mul(t1, t4);
79354
+ Y3 = Fp.add(Y3, t0);
79355
+ t0 = Fp.mul(t5, t4);
79356
+ X3 = Fp.mul(t3, X3);
79357
+ X3 = Fp.sub(X3, t0);
79358
+ t0 = Fp.mul(t3, t1);
79359
+ Z3 = Fp.mul(t5, Z3);
79360
+ Z3 = Fp.add(Z3, t0);
79361
+ return new Point(X3, Y3, Z3);
79362
+ }
79363
+ subtract(other) {
79364
+ return this.add(other.negate());
79365
+ }
79366
+ is0() {
79367
+ return this.equals(Point.ZERO);
79368
+ }
79369
+ /**
79370
+ * Constant time multiplication.
79371
+ * Uses wNAF method. Windowed method may be 10% faster,
79372
+ * but takes 2x longer to generate and consumes 2x memory.
79373
+ * Uses precomputes when available.
79374
+ * Uses endomorphism for Koblitz curves.
79375
+ * @param scalar by which the point would be multiplied
79376
+ * @returns New point
79377
+ */
79378
+ multiply(scalar) {
79379
+ const { endo: endo2 } = extraOpts;
79380
+ if (!Fn.isValidNot0(scalar))
79381
+ throw new Error("invalid scalar: out of range");
79382
+ let point, fake;
79383
+ const mul2 = (n) => wnaf.cached(this, n, (p) => normalizeZ2(Point, p));
79384
+ if (endo2) {
79385
+ const { k1neg, k1, k2neg, k2 } = splitEndoScalarN(scalar);
79386
+ const { p: k1p, f: k1f } = mul2(k1);
79387
+ const { p: k2p, f: k2f } = mul2(k2);
79388
+ fake = k1f.add(k2f);
79389
+ point = finishEndo(endo2.beta, k1p, k2p, k1neg, k2neg);
79390
+ } else {
79391
+ const { p, f } = mul2(scalar);
79392
+ point = p;
79393
+ fake = f;
79394
+ }
79395
+ return normalizeZ2(Point, [point, fake])[0];
79396
+ }
79397
+ /**
79398
+ * Non-constant-time multiplication. Uses double-and-add algorithm.
79399
+ * It's faster, but should only be used when you don't care about
79400
+ * an exposed secret key e.g. sig verification, which works over *public* keys.
79401
+ */
79402
+ multiplyUnsafe(sc) {
79403
+ const { endo: endo2 } = extraOpts;
79404
+ const p = this;
79405
+ if (!Fn.isValid(sc))
79406
+ throw new Error("invalid scalar: out of range");
79407
+ if (sc === _0n8 || p.is0())
79408
+ return Point.ZERO;
79409
+ if (sc === _1n9)
79410
+ return p;
79411
+ if (wnaf.hasCache(this))
79412
+ return this.multiply(sc);
79413
+ if (endo2) {
79414
+ const { k1neg, k1, k2neg, k2 } = splitEndoScalarN(sc);
79415
+ const { p1, p2 } = mulEndoUnsafe(Point, p, k1, k2);
79416
+ return finishEndo(endo2.beta, p1, p2, k1neg, k2neg);
79417
+ } else {
79418
+ return wnaf.unsafe(p, sc);
79419
+ }
79420
+ }
79421
+ multiplyAndAddUnsafe(Q, a, b) {
79422
+ const sum2 = this.multiplyUnsafe(a).add(Q.multiplyUnsafe(b));
79423
+ return sum2.is0() ? void 0 : sum2;
79424
+ }
79425
+ /**
79426
+ * Converts Projective point to affine (x, y) coordinates.
79427
+ * @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
79428
+ */
79429
+ toAffine(invertedZ) {
79430
+ return toAffineMemo(this, invertedZ);
79431
+ }
79432
+ /**
79433
+ * Checks whether Point is free of torsion elements (is in prime subgroup).
79434
+ * Always torsion-free for cofactor=1 curves.
79435
+ */
79436
+ isTorsionFree() {
79437
+ const { isTorsionFree } = extraOpts;
79438
+ if (cofactor === _1n9)
79439
+ return true;
79440
+ if (isTorsionFree)
79441
+ return isTorsionFree(Point, this);
79442
+ return wnaf.unsafe(this, CURVE_ORDER).is0();
79443
+ }
79444
+ clearCofactor() {
79445
+ const { clearCofactor } = extraOpts;
79446
+ if (cofactor === _1n9)
79447
+ return this;
79448
+ if (clearCofactor)
79449
+ return clearCofactor(Point, this);
79450
+ return this.multiplyUnsafe(cofactor);
79451
+ }
79452
+ isSmallOrder() {
79453
+ return this.multiplyUnsafe(cofactor).is0();
79454
+ }
79455
+ toBytes(isCompressed = true) {
79456
+ _abool2(isCompressed, "isCompressed");
79457
+ this.assertValidity();
79458
+ return encodePoint(Point, this, isCompressed);
79459
+ }
79460
+ toHex(isCompressed = true) {
79461
+ return bytesToHex2(this.toBytes(isCompressed));
79462
+ }
79463
+ toString() {
79464
+ return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
79465
+ }
79466
+ // TODO: remove
79467
+ get px() {
79468
+ return this.X;
79469
+ }
79470
+ get py() {
79471
+ return this.X;
79472
+ }
79473
+ get pz() {
79474
+ return this.Z;
79475
+ }
79476
+ toRawBytes(isCompressed = true) {
79477
+ return this.toBytes(isCompressed);
79478
+ }
79479
+ _setWindowSize(windowSize) {
79480
+ this.precompute(windowSize);
79481
+ }
79482
+ static normalizeZ(points) {
79483
+ return normalizeZ2(Point, points);
79484
+ }
79485
+ static msm(points, scalars) {
79486
+ return pippenger(Point, Fn, points, scalars);
79487
+ }
79488
+ static fromPrivateKey(privateKey) {
79489
+ return Point.BASE.multiply(_normFnElement(Fn, privateKey));
79490
+ }
79491
+ }
79492
+ Point.BASE = new Point(CURVE.Gx, CURVE.Gy, Fp.ONE);
79493
+ Point.ZERO = new Point(Fp.ZERO, Fp.ONE, Fp.ZERO);
79494
+ Point.Fp = Fp;
79495
+ Point.Fn = Fn;
79496
+ const bits = Fn.BITS;
79497
+ const wnaf = new wNAF2(Point, extraOpts.endo ? Math.ceil(bits / 2) : bits);
79498
+ Point.BASE.precompute(8);
79499
+ return Point;
79500
+ }
79501
+ function pprefix(hasEvenY) {
79502
+ return Uint8Array.of(hasEvenY ? 2 : 3);
79503
+ }
79504
+ function getWLengths(Fp, Fn) {
79505
+ return {
79506
+ secretKey: Fn.BYTES,
79507
+ publicKey: 1 + Fp.BYTES,
79508
+ publicKeyUncompressed: 1 + 2 * Fp.BYTES,
79509
+ publicKeyHasPrefix: true,
79510
+ signature: 2 * Fn.BYTES
79511
+ };
79512
+ }
79513
+ function ecdh(Point, ecdhOpts = {}) {
79514
+ const { Fn } = Point;
79515
+ const randomBytes_ = ecdhOpts.randomBytes || randomBytes2;
79516
+ const lengths = Object.assign(getWLengths(Point.Fp, Fn), { seed: getMinHashLength(Fn.ORDER) });
79517
+ function isValidSecretKey(secretKey) {
79518
+ try {
79519
+ return !!_normFnElement(Fn, secretKey);
79520
+ } catch (error2) {
79521
+ return false;
79522
+ }
79523
+ }
79524
+ function isValidPublicKey(publicKey, isCompressed) {
79525
+ const { publicKey: comp, publicKeyUncompressed } = lengths;
79526
+ try {
79527
+ const l2 = publicKey.length;
79528
+ if (isCompressed === true && l2 !== comp)
79529
+ return false;
79530
+ if (isCompressed === false && l2 !== publicKeyUncompressed)
79531
+ return false;
79532
+ return !!Point.fromBytes(publicKey);
79533
+ } catch (error2) {
79534
+ return false;
79535
+ }
79536
+ }
79537
+ function randomSecretKey(seed = randomBytes_(lengths.seed)) {
79538
+ return mapHashToField(_abytes2(seed, lengths.seed, "seed"), Fn.ORDER);
79539
+ }
79540
+ function getPublicKey(secretKey, isCompressed = true) {
79541
+ return Point.BASE.multiply(_normFnElement(Fn, secretKey)).toBytes(isCompressed);
79542
+ }
79543
+ function keygen(seed) {
79544
+ const secretKey = randomSecretKey(seed);
79545
+ return { secretKey, publicKey: getPublicKey(secretKey) };
79546
+ }
79547
+ function isProbPub(item) {
79548
+ if (typeof item === "bigint")
79549
+ return false;
79550
+ if (item instanceof Point)
79551
+ return true;
79552
+ const { secretKey, publicKey, publicKeyUncompressed } = lengths;
79553
+ if (Fn.allowedLengths || secretKey === publicKey)
79554
+ return void 0;
79555
+ const l2 = ensureBytes("key", item).length;
79556
+ return l2 === publicKey || l2 === publicKeyUncompressed;
79557
+ }
79558
+ function getSharedSecret(secretKeyA, publicKeyB, isCompressed = true) {
79559
+ if (isProbPub(secretKeyA) === true)
79560
+ throw new Error("first arg must be private key");
79561
+ if (isProbPub(publicKeyB) === false)
79562
+ throw new Error("second arg must be public key");
79563
+ const s = _normFnElement(Fn, secretKeyA);
79564
+ const b = Point.fromHex(publicKeyB);
79565
+ return b.multiply(s).toBytes(isCompressed);
79566
+ }
79567
+ const utils = {
79568
+ isValidSecretKey,
79569
+ isValidPublicKey,
79570
+ randomSecretKey,
79571
+ // TODO: remove
79572
+ isValidPrivateKey: isValidSecretKey,
79573
+ randomPrivateKey: randomSecretKey,
79574
+ normPrivateKeyToScalar: (key) => _normFnElement(Fn, key),
79575
+ precompute(windowSize = 8, point = Point.BASE) {
79576
+ return point.precompute(windowSize, false);
79577
+ }
79578
+ };
79579
+ return Object.freeze({ getPublicKey, getSharedSecret, keygen, Point, utils, lengths });
79580
+ }
79581
+ function ecdsa(Point, hash, ecdsaOpts = {}) {
79582
+ ahash2(hash);
79583
+ _validateObject(ecdsaOpts, {}, {
79584
+ hmac: "function",
79585
+ lowS: "boolean",
79586
+ randomBytes: "function",
79587
+ bits2int: "function",
79588
+ bits2int_modN: "function"
79589
+ });
79590
+ const randomBytes3 = ecdsaOpts.randomBytes || randomBytes2;
79591
+ const hmac3 = ecdsaOpts.hmac || ((key, ...msgs) => hmac2(hash, key, concatBytes3(...msgs)));
79592
+ const { Fp, Fn } = Point;
79593
+ const { ORDER: CURVE_ORDER, BITS: fnBits } = Fn;
79594
+ const { keygen, getPublicKey, getSharedSecret, utils, lengths } = ecdh(Point, ecdsaOpts);
79595
+ const defaultSigOpts = {
79596
+ prehash: false,
79597
+ lowS: typeof ecdsaOpts.lowS === "boolean" ? ecdsaOpts.lowS : false,
79598
+ format: void 0,
79599
+ //'compact' as ECDSASigFormat,
79600
+ extraEntropy: false
79601
+ };
79602
+ const defaultSigOpts_format = "compact";
79603
+ function isBiggerThanHalfOrder(number4) {
79604
+ const HALF = CURVE_ORDER >> _1n9;
79605
+ return number4 > HALF;
79606
+ }
79607
+ function validateRS(title, num) {
79608
+ if (!Fn.isValidNot0(num))
79609
+ throw new Error(`invalid signature ${title}: out of range 1..Point.Fn.ORDER`);
79610
+ return num;
79611
+ }
79612
+ function validateSigLength(bytes, format) {
79613
+ validateSigFormat(format);
79614
+ const size = lengths.signature;
79615
+ const sizer = format === "compact" ? size : format === "recovered" ? size + 1 : void 0;
79616
+ return _abytes2(bytes, sizer, `${format} signature`);
79617
+ }
79618
+ class Signature {
79619
+ constructor(r, s, recovery) {
79620
+ this.r = validateRS("r", r);
79621
+ this.s = validateRS("s", s);
79622
+ if (recovery != null)
79623
+ this.recovery = recovery;
79624
+ Object.freeze(this);
79625
+ }
79626
+ static fromBytes(bytes, format = defaultSigOpts_format) {
79627
+ validateSigLength(bytes, format);
79628
+ let recid;
79629
+ if (format === "der") {
79630
+ const { r: r2, s: s2 } = DER.toSig(_abytes2(bytes));
79631
+ return new Signature(r2, s2);
79632
+ }
79633
+ if (format === "recovered") {
79634
+ recid = bytes[0];
79635
+ format = "compact";
79636
+ bytes = bytes.subarray(1);
79637
+ }
79638
+ const L = Fn.BYTES;
79639
+ const r = bytes.subarray(0, L);
79640
+ const s = bytes.subarray(L, L * 2);
79641
+ return new Signature(Fn.fromBytes(r), Fn.fromBytes(s), recid);
79642
+ }
79643
+ static fromHex(hex, format) {
79644
+ return this.fromBytes(hexToBytes2(hex), format);
79645
+ }
79646
+ addRecoveryBit(recovery) {
79647
+ return new Signature(this.r, this.s, recovery);
79648
+ }
79649
+ recoverPublicKey(messageHash) {
79650
+ const FIELD_ORDER = Fp.ORDER;
79651
+ const { r, s, recovery: rec } = this;
79652
+ if (rec == null || ![0, 1, 2, 3].includes(rec))
79653
+ throw new Error("recovery id invalid");
79654
+ const hasCofactor = CURVE_ORDER * _2n5 < FIELD_ORDER;
79655
+ if (hasCofactor && rec > 1)
79656
+ throw new Error("recovery id is ambiguous for h>1 curve");
79657
+ const radj = rec === 2 || rec === 3 ? r + CURVE_ORDER : r;
79658
+ if (!Fp.isValid(radj))
79659
+ throw new Error("recovery id 2 or 3 invalid");
79660
+ const x = Fp.toBytes(radj);
79661
+ const R2 = Point.fromBytes(concatBytes3(pprefix((rec & 1) === 0), x));
79662
+ const ir = Fn.inv(radj);
79663
+ const h = bits2int_modN(ensureBytes("msgHash", messageHash));
79664
+ const u1 = Fn.create(-h * ir);
79665
+ const u2 = Fn.create(s * ir);
79666
+ const Q = Point.BASE.multiplyUnsafe(u1).add(R2.multiplyUnsafe(u2));
79667
+ if (Q.is0())
79668
+ throw new Error("point at infinify");
79669
+ Q.assertValidity();
79670
+ return Q;
79671
+ }
79672
+ // Signatures should be low-s, to prevent malleability.
79673
+ hasHighS() {
79674
+ return isBiggerThanHalfOrder(this.s);
79675
+ }
79676
+ toBytes(format = defaultSigOpts_format) {
79677
+ validateSigFormat(format);
79678
+ if (format === "der")
79679
+ return hexToBytes2(DER.hexFromSig(this));
79680
+ const r = Fn.toBytes(this.r);
79681
+ const s = Fn.toBytes(this.s);
79682
+ if (format === "recovered") {
79683
+ if (this.recovery == null)
79684
+ throw new Error("recovery bit must be present");
79685
+ return concatBytes3(Uint8Array.of(this.recovery), r, s);
79686
+ }
79687
+ return concatBytes3(r, s);
79688
+ }
79689
+ toHex(format) {
79690
+ return bytesToHex2(this.toBytes(format));
79691
+ }
79692
+ // TODO: remove
79693
+ assertValidity() {
79694
+ }
79695
+ static fromCompact(hex) {
79696
+ return Signature.fromBytes(ensureBytes("sig", hex), "compact");
79697
+ }
79698
+ static fromDER(hex) {
79699
+ return Signature.fromBytes(ensureBytes("sig", hex), "der");
79700
+ }
79701
+ normalizeS() {
79702
+ return this.hasHighS() ? new Signature(this.r, Fn.neg(this.s), this.recovery) : this;
79703
+ }
79704
+ toDERRawBytes() {
79705
+ return this.toBytes("der");
79706
+ }
79707
+ toDERHex() {
79708
+ return bytesToHex2(this.toBytes("der"));
79709
+ }
79710
+ toCompactRawBytes() {
79711
+ return this.toBytes("compact");
79712
+ }
79713
+ toCompactHex() {
79714
+ return bytesToHex2(this.toBytes("compact"));
79715
+ }
79716
+ }
79717
+ const bits2int = ecdsaOpts.bits2int || function bits2int_def(bytes) {
79718
+ if (bytes.length > 8192)
79719
+ throw new Error("input is too large");
79720
+ const num = bytesToNumberBE2(bytes);
79721
+ const delta = bytes.length * 8 - fnBits;
79722
+ return delta > 0 ? num >> BigInt(delta) : num;
79723
+ };
79724
+ const bits2int_modN = ecdsaOpts.bits2int_modN || function bits2int_modN_def(bytes) {
79725
+ return Fn.create(bits2int(bytes));
79726
+ };
79727
+ const ORDER_MASK = bitMask2(fnBits);
79728
+ function int2octets(num) {
79729
+ aInRange2("num < 2^" + fnBits, num, _0n8, ORDER_MASK);
79730
+ return Fn.toBytes(num);
79731
+ }
79732
+ function validateMsgAndHash(message, prehash) {
79733
+ _abytes2(message, void 0, "message");
79734
+ return prehash ? _abytes2(hash(message), void 0, "prehashed message") : message;
79735
+ }
79736
+ function prepSig(message, privateKey, opts) {
79737
+ if (["recovered", "canonical"].some((k) => k in opts))
79738
+ throw new Error("sign() legacy options not supported");
79739
+ const { lowS, prehash, extraEntropy } = validateSigOpts(opts, defaultSigOpts);
79740
+ message = validateMsgAndHash(message, prehash);
79741
+ const h1int = bits2int_modN(message);
79742
+ const d = _normFnElement(Fn, privateKey);
79743
+ const seedArgs = [int2octets(d), int2octets(h1int)];
79744
+ if (extraEntropy != null && extraEntropy !== false) {
79745
+ const e = extraEntropy === true ? randomBytes3(lengths.secretKey) : extraEntropy;
79746
+ seedArgs.push(ensureBytes("extraEntropy", e));
79747
+ }
79748
+ const seed = concatBytes3(...seedArgs);
79749
+ const m = h1int;
79750
+ function k2sig(kBytes) {
79751
+ const k = bits2int(kBytes);
79752
+ if (!Fn.isValidNot0(k))
79753
+ return;
79754
+ const ik = Fn.inv(k);
79755
+ const q = Point.BASE.multiply(k).toAffine();
79756
+ const r = Fn.create(q.x);
79757
+ if (r === _0n8)
79758
+ return;
79759
+ const s = Fn.create(ik * Fn.create(m + r * d));
79760
+ if (s === _0n8)
79761
+ return;
79762
+ let recovery = (q.x === r ? 0 : 2) | Number(q.y & _1n9);
79763
+ let normS = s;
79764
+ if (lowS && isBiggerThanHalfOrder(s)) {
79765
+ normS = Fn.neg(s);
79766
+ recovery ^= 1;
79767
+ }
79768
+ return new Signature(r, normS, recovery);
79769
+ }
79770
+ return { seed, k2sig };
79771
+ }
79772
+ function sign2(message, secretKey, opts = {}) {
79773
+ message = ensureBytes("message", message);
79774
+ const { seed, k2sig } = prepSig(message, secretKey, opts);
79775
+ const drbg = createHmacDrbg(hash.outputLen, Fn.BYTES, hmac3);
79776
+ const sig = drbg(seed, k2sig);
79777
+ return sig;
79778
+ }
79779
+ function tryParsingSig(sg) {
79780
+ let sig = void 0;
79781
+ const isHex3 = typeof sg === "string" || isBytes3(sg);
79782
+ const isObj = !isHex3 && sg !== null && typeof sg === "object" && typeof sg.r === "bigint" && typeof sg.s === "bigint";
79783
+ if (!isHex3 && !isObj)
79784
+ throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
79785
+ if (isObj) {
79786
+ sig = new Signature(sg.r, sg.s);
79787
+ } else if (isHex3) {
79788
+ try {
79789
+ sig = Signature.fromBytes(ensureBytes("sig", sg), "der");
79790
+ } catch (derError) {
79791
+ if (!(derError instanceof DER.Err))
79792
+ throw derError;
79793
+ }
79794
+ if (!sig) {
79795
+ try {
79796
+ sig = Signature.fromBytes(ensureBytes("sig", sg), "compact");
79797
+ } catch (error2) {
79798
+ return false;
79799
+ }
79800
+ }
79801
+ }
79802
+ if (!sig)
79803
+ return false;
79804
+ return sig;
79805
+ }
79806
+ function verify(signature, message, publicKey, opts = {}) {
79807
+ const { lowS, prehash, format } = validateSigOpts(opts, defaultSigOpts);
79808
+ publicKey = ensureBytes("publicKey", publicKey);
79809
+ message = validateMsgAndHash(ensureBytes("message", message), prehash);
79810
+ if ("strict" in opts)
79811
+ throw new Error("options.strict was renamed to lowS");
79812
+ const sig = format === void 0 ? tryParsingSig(signature) : Signature.fromBytes(ensureBytes("sig", signature), format);
79813
+ if (sig === false)
79814
+ return false;
79815
+ try {
79816
+ const P3 = Point.fromBytes(publicKey);
79817
+ if (lowS && sig.hasHighS())
79818
+ return false;
79819
+ const { r, s } = sig;
79820
+ const h = bits2int_modN(message);
79821
+ const is2 = Fn.inv(s);
79822
+ const u1 = Fn.create(h * is2);
79823
+ const u2 = Fn.create(r * is2);
79824
+ const R2 = Point.BASE.multiplyUnsafe(u1).add(P3.multiplyUnsafe(u2));
79825
+ if (R2.is0())
79826
+ return false;
79827
+ const v = Fn.create(R2.x);
79828
+ return v === r;
79829
+ } catch (e) {
79830
+ return false;
79831
+ }
79832
+ }
79833
+ function recoverPublicKey(signature, message, opts = {}) {
79834
+ const { prehash } = validateSigOpts(opts, defaultSigOpts);
79835
+ message = validateMsgAndHash(message, prehash);
79836
+ return Signature.fromBytes(signature, "recovered").recoverPublicKey(message).toBytes();
79837
+ }
79838
+ return Object.freeze({
79839
+ keygen,
79840
+ getPublicKey,
79841
+ getSharedSecret,
79842
+ utils,
79843
+ lengths,
79844
+ Point,
79845
+ sign: sign2,
79846
+ verify,
79847
+ recoverPublicKey,
79848
+ Signature,
79849
+ hash
79850
+ });
79851
+ }
79852
+ function _weierstrass_legacy_opts_to_new(c) {
79853
+ const CURVE = {
79854
+ a: c.a,
79855
+ b: c.b,
79856
+ p: c.Fp.ORDER,
79857
+ n: c.n,
79858
+ h: c.h,
79859
+ Gx: c.Gx,
79860
+ Gy: c.Gy
79861
+ };
79862
+ const Fp = c.Fp;
79863
+ let allowedLengths = c.allowedPrivateKeyLengths ? Array.from(new Set(c.allowedPrivateKeyLengths.map((l2) => Math.ceil(l2 / 2)))) : void 0;
79864
+ const Fn = Field2(CURVE.n, {
79865
+ BITS: c.nBitLength,
79866
+ allowedLengths,
79867
+ modFromBytes: c.wrapPrivateKey
79868
+ });
79869
+ const curveOpts = {
79870
+ Fp,
79871
+ Fn,
79872
+ allowInfinityPoint: c.allowInfinityPoint,
79873
+ endo: c.endo,
79874
+ isTorsionFree: c.isTorsionFree,
79875
+ clearCofactor: c.clearCofactor,
79876
+ fromBytes: c.fromBytes,
79877
+ toBytes: c.toBytes
79878
+ };
79879
+ return { CURVE, curveOpts };
79880
+ }
79881
+ function _ecdsa_legacy_opts_to_new(c) {
79882
+ const { CURVE, curveOpts } = _weierstrass_legacy_opts_to_new(c);
79883
+ const ecdsaOpts = {
79884
+ hmac: c.hmac,
79885
+ randomBytes: c.randomBytes,
79886
+ lowS: c.lowS,
79887
+ bits2int: c.bits2int,
79888
+ bits2int_modN: c.bits2int_modN
79889
+ };
79890
+ return { CURVE, curveOpts, hash: c.hash, ecdsaOpts };
79891
+ }
79892
+ function _ecdsa_new_output_to_legacy(c, _ecdsa) {
79893
+ const Point = _ecdsa.Point;
79894
+ return Object.assign({}, _ecdsa, {
79895
+ ProjectivePoint: Point,
79896
+ CURVE: Object.assign({}, c, nLength2(Point.Fn.ORDER, Point.Fn.BITS))
79897
+ });
79898
+ }
79899
+ function weierstrass(c) {
79900
+ const { CURVE, curveOpts, hash, ecdsaOpts } = _ecdsa_legacy_opts_to_new(c);
79901
+ const Point = weierstrassN(CURVE, curveOpts);
79902
+ const signs = ecdsa(Point, hash, ecdsaOpts);
79903
+ return _ecdsa_new_output_to_legacy(c, signs);
79904
+ }
79905
+
79906
+ // ../../node_modules/.pnpm/@noble+curves@1.9.7/node_modules/@noble/curves/esm/_shortw_utils.js
79907
+ function createCurve(curveDef, defHash) {
79908
+ const create = (hash) => weierstrass({ ...curveDef, hash });
79909
+ return { ...create(defHash), create };
79910
+ }
79911
+
79912
+ // ../../node_modules/.pnpm/@noble+curves@1.9.7/node_modules/@noble/curves/esm/secp256k1.js
79913
+ var secp256k1_CURVE = {
79914
+ p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
79915
+ n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
79916
+ h: BigInt(1),
79917
+ a: BigInt(0),
79918
+ b: BigInt(7),
79919
+ Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
79920
+ Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
79921
+ };
79922
+ var secp256k1_ENDO = {
79923
+ beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
79924
+ basises: [
79925
+ [BigInt("0x3086d221a7d46bcde86c90e49284eb15"), -BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],
79926
+ [BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), BigInt("0x3086d221a7d46bcde86c90e49284eb15")]
79927
+ ]
79928
+ };
79929
+ var _2n6 = /* @__PURE__ */ BigInt(2);
79930
+ function sqrtMod(y2) {
79931
+ const P3 = secp256k1_CURVE.p;
79932
+ const _3n4 = BigInt(3), _6n = BigInt(6), _11n = BigInt(11), _22n = BigInt(22);
79933
+ const _23n = BigInt(23), _44n = BigInt(44), _88n = BigInt(88);
79934
+ const b2 = y2 * y2 * y2 % P3;
79935
+ const b3 = b2 * b2 * y2 % P3;
79936
+ const b6 = pow22(b3, _3n4, P3) * b3 % P3;
79937
+ const b9 = pow22(b6, _3n4, P3) * b3 % P3;
79938
+ const b11 = pow22(b9, _2n6, P3) * b2 % P3;
79939
+ const b22 = pow22(b11, _11n, P3) * b11 % P3;
79940
+ const b44 = pow22(b22, _22n, P3) * b22 % P3;
79941
+ const b88 = pow22(b44, _44n, P3) * b44 % P3;
79942
+ const b176 = pow22(b88, _88n, P3) * b88 % P3;
79943
+ const b220 = pow22(b176, _44n, P3) * b44 % P3;
79944
+ const b223 = pow22(b220, _3n4, P3) * b3 % P3;
79945
+ const t1 = pow22(b223, _23n, P3) * b22 % P3;
79946
+ const t2 = pow22(t1, _6n, P3) * b2 % P3;
79947
+ const root = pow22(t2, _2n6, P3);
79948
+ if (!Fpk1.eql(Fpk1.sqr(root), y2))
79949
+ throw new Error("Cannot find square root");
79950
+ return root;
79951
+ }
79952
+ var Fpk1 = Field2(secp256k1_CURVE.p, { sqrt: sqrtMod });
79953
+ var secp256k1 = createCurve({ ...secp256k1_CURVE, Fp: Fpk1, lowS: true, endo: secp256k1_ENDO }, sha2562);
79954
+
79955
+ // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/sha256.js
79956
+ var sha2563 = sha2562;
77652
79957
  var __defProp4 = Object.defineProperty;
77653
79958
  var __getOwnPropNames3 = Object.getOwnPropertyNames;
77654
79959
  var __esm2 = (fn, res) => function __init() {
@@ -79239,10 +81544,10 @@ function recordFromGqlNode(node, address) {
79239
81544
  commandTypes.push("MoveCall");
79240
81545
  const fn = cmd.function;
79241
81546
  const pkg = fn?.module?.package?.address;
79242
- const mod3 = fn?.module?.name;
81547
+ const mod4 = fn?.module?.name;
79243
81548
  const name = fn?.name;
79244
- if (pkg && mod3 && name) {
79245
- moveCallTargets.push(`${pkg}::${mod3}::${name}`);
81549
+ if (pkg && mod4 && name) {
81550
+ moveCallTargets.push(`${pkg}::${mod4}::${name}`);
79246
81551
  }
79247
81552
  } else if (cmd.__typename === "TransferObjectsCommand") {
79248
81553
  commandTypes.push("TransferObjects");
@@ -79467,9 +81772,85 @@ async function listModels(opts) {
79467
81772
  }));
79468
81773
  }
79469
81774
  var RECEIPT_ANCHORED_SUFFIX = "::anchor::ReceiptAnchored";
81775
+ function normalizeClaims(claims) {
81776
+ if (!claims) {
81777
+ return [];
81778
+ }
81779
+ if (Array.isArray(claims)) {
81780
+ return claims.filter((c) => c.name).map((c) => ({
81781
+ name: c.name,
81782
+ status: c.status ?? "unknown",
81783
+ source: c.source
81784
+ }));
81785
+ }
81786
+ return Object.entries(claims).map(([name, v]) => ({
81787
+ name,
81788
+ status: v?.status ?? "unknown",
81789
+ source: v?.source
81790
+ }));
81791
+ }
79470
81792
  function fullnodeUrl(network) {
79471
81793
  return network === "testnet" ? "https://fullnode.testnet.sui.io" : "https://fullnode.mainnet.sui.io";
79472
81794
  }
81795
+ function jcs(value) {
81796
+ if (value === null) {
81797
+ return "null";
81798
+ }
81799
+ if (typeof value === "boolean") {
81800
+ return value ? "true" : "false";
81801
+ }
81802
+ if (typeof value === "number") {
81803
+ if (!Number.isInteger(value)) {
81804
+ throw new Error("JCS: non-integer number");
81805
+ }
81806
+ return String(value);
81807
+ }
81808
+ if (typeof value === "string") {
81809
+ return JSON.stringify(value);
81810
+ }
81811
+ if (Array.isArray(value)) {
81812
+ return `[${value.map(jcs).join(",")}]`;
81813
+ }
81814
+ const keys = Object.keys(value).sort();
81815
+ return `{${keys.map((k) => `${JSON.stringify(k)}:${jcs(value[k])}`).join(",")}}`;
81816
+ }
81817
+ function verifyReceiptSignature(receipt, signingKeyHex) {
81818
+ try {
81819
+ const sig = receipt.signature;
81820
+ if (sig?.algo !== "ecdsa-secp256k1" || !sig.value) {
81821
+ return false;
81822
+ }
81823
+ const canonical = {
81824
+ api_version: receipt.api_version ?? "",
81825
+ receipt_id: receipt.receipt_id ?? "",
81826
+ chat_id: receipt.chat_id ?? null,
81827
+ workload_id: receipt.workload_id ?? "",
81828
+ workload_keyset_digest: receipt.workload_keyset_digest ?? "",
81829
+ endpoint: receipt.endpoint ?? "",
81830
+ method: receipt.method ?? "",
81831
+ served_at: receipt.served_at ?? 0,
81832
+ event_log: receipt.event_log ?? [],
81833
+ signature: { algo: sig.algo, key_id: sig.key_id ?? "" }
81834
+ };
81835
+ const prehash = sha2563(new TextEncoder().encode(jcs(canonical)));
81836
+ const sigBytes = hexToBytes2(sig.value);
81837
+ if (sigBytes.length !== 65) {
81838
+ return false;
81839
+ }
81840
+ let v = sigBytes[64];
81841
+ if (v >= 27 && v <= 30) {
81842
+ v -= 27;
81843
+ }
81844
+ if (v > 3) {
81845
+ return false;
81846
+ }
81847
+ const recovered = secp256k1.Signature.fromCompact(sigBytes.slice(0, 64)).addRecoveryBit(v).recoverPublicKey(prehash).toHex(false);
81848
+ const endorsed = bytesToHex2(hexToBytes2(signingKeyHex.replace(/^0x/, "")));
81849
+ return recovered.toLowerCase() === endorsed.toLowerCase();
81850
+ } catch {
81851
+ return false;
81852
+ }
81853
+ }
79473
81854
  async function verifyReceipt(receiptId, opts = {}) {
79474
81855
  const base = opts.apiBase ?? DEFAULT_API_BASE;
79475
81856
  const network = opts.network ?? "mainnet";
@@ -79501,6 +81882,7 @@ async function verifyReceipt(receiptId, opts = {}) {
79501
81882
  });
79502
81883
  const upstreamEv = receipt.event_log.find((e) => e.type === "upstream.verified");
79503
81884
  const upstreamOk = upstreamEv?.result === "verified";
81885
+ const claims = normalizeClaims(upstreamEv?.claims);
79504
81886
  checks.push({
79505
81887
  name: "Confidential upstream",
79506
81888
  status: upstreamEv ? upstreamOk ? "pass" : "fail" : "skip",
@@ -79563,23 +81945,50 @@ async function verifyReceipt(receiptId, opts = {}) {
79563
81945
  });
79564
81946
  }
79565
81947
  }
81948
+ let signatureForged = false;
81949
+ let sigStatus = "skip";
81950
+ let sigDetail = "no signature on receipt";
81951
+ if (receipt.signature?.value) {
81952
+ try {
81953
+ const model = opts.model ?? "phala/glm-5.2";
81954
+ const res = await fetch(
81955
+ `${base}/aci/attestation?model=${encodeURIComponent(model)}`
81956
+ );
81957
+ const att = res.ok ? await res.json() : null;
81958
+ if (!att?.signingKey) {
81959
+ sigDetail = "could not fetch the attested keyset to check the signature";
81960
+ } else if (att.workloadId && att.workloadId !== workloadId) {
81961
+ sigDetail = `attested keyset is for a different workload \u2014 pass --model for ${workloadId}`;
81962
+ } else {
81963
+ const ok = verifyReceiptSignature(receipt, att.signingKey);
81964
+ sigStatus = ok ? "pass" : "fail";
81965
+ signatureForged = !ok;
81966
+ sigDetail = ok ? `signed by the attested receipt key (${receipt.signature.key_id ?? "key"})` : "signature does NOT recover the attested receipt key \u2014 forged/altered";
81967
+ }
81968
+ } catch {
81969
+ sigDetail = "signature check errored";
81970
+ }
81971
+ }
79566
81972
  checks.push({
79567
81973
  name: "Receipt signature",
79568
- status: "skip",
79569
- detail: receipt.signature ? "present (local recompute via RedPill keyset canonicalization = roadmap)" : "no signature on receipt",
79570
- trust: "roadmap"
81974
+ status: sigStatus,
81975
+ detail: sigDetail,
81976
+ trust: sigStatus === "skip" ? "roadmap" : "trustless"
79571
81977
  });
79572
81978
  return {
79573
81979
  receiptId,
79574
- verified: Boolean(wireHash && workloadId) && anchorVerified,
81980
+ verified: Boolean(wireHash && workloadId) && anchorVerified && !signatureForged,
79575
81981
  anchorVerified,
79576
81982
  checks,
79577
81983
  wireHash,
79578
81984
  workloadId,
79579
81985
  upstream: upstreamEv ? {
79580
81986
  provider: upstreamEv.provider ?? upstreamEv.upstream_name,
81987
+ modelId: upstreamEv.model_id,
79581
81988
  result: upstreamEv.result,
79582
- tcbStatus: upstreamEv.tcb_status
81989
+ tcbStatus: upstreamEv.tcb_status,
81990
+ sessionId: upstreamEv.session_id,
81991
+ claims: claims.length > 0 ? claims : void 0
79583
81992
  } : void 0,
79584
81993
  anchor
79585
81994
  };
@@ -80705,7 +83114,7 @@ CRITICAL: When the user asks to use any external or paid API, names a provider (
80705
83114
  Spending is the user's own USDC and every t2000_pay call is bounded by maxPrice. For larger or multi-step spends, state the estimated cost first and proceed once the user is happy. Use t2000_balance to check funds. The v4 wallet is payments-only; savings / lending live on audric.ai.`;
80706
83115
 
80707
83116
  // src/index.ts
80708
- var PKG_VERSION = "5.17.0" ;
83117
+ var PKG_VERSION = "5.19.0" ;
80709
83118
  console.log = (...args) => console.error("[log]", ...args);
80710
83119
  console.warn = (...args) => console.error("[warn]", ...args);
80711
83120
  async function startMcpServer(opts) {
@@ -80731,6 +83140,7 @@ await startMcpServer();
80731
83140
  (*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
80732
83141
 
80733
83142
  @noble/hashes/utils.js:
83143
+ @noble/hashes/esm/utils.js:
80734
83144
  (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
80735
83145
 
80736
83146
  mime-db/index.js:
@@ -80767,6 +83177,12 @@ mime-types/index.js:
80767
83177
  @noble/curves/abstract/curve.js:
80768
83178
  @noble/curves/abstract/edwards.js:
80769
83179
  @noble/curves/ed25519.js:
83180
+ @noble/curves/esm/utils.js:
83181
+ @noble/curves/esm/abstract/modular.js:
83182
+ @noble/curves/esm/abstract/curve.js:
83183
+ @noble/curves/esm/abstract/weierstrass.js:
83184
+ @noble/curves/esm/_shortw_utils.js:
83185
+ @noble/curves/esm/secp256k1.js:
80770
83186
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
80771
83187
 
80772
83188
  @scure/bip39/index.js: