@btc-vision/transaction 1.8.7-beta.0 → 1.8.7

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.
Files changed (30) hide show
  1. package/browser/btc-vision-bitcoin.js +364 -364
  2. package/browser/index.js +1022 -903
  3. package/browser/noble-curves.js +1183 -2156
  4. package/browser/src/transaction/builders/TransactionBuilder.d.ts +1 -0
  5. package/browser/src/transaction/offline/OfflineTransactionManager.d.ts +50 -0
  6. package/browser/src/transaction/offline/interfaces/ISerializableState.d.ts +10 -2
  7. package/browser/vendors.js +1395 -1395
  8. package/build/transaction/TransactionFactory.js +1 -1
  9. package/build/transaction/builders/FundingTransaction.js +17 -13
  10. package/build/transaction/builders/TransactionBuilder.d.ts +1 -0
  11. package/build/transaction/builders/TransactionBuilder.js +32 -7
  12. package/build/transaction/offline/OfflineTransactionManager.d.ts +50 -0
  13. package/build/transaction/offline/OfflineTransactionManager.js +142 -1
  14. package/build/transaction/offline/TransactionSerializer.js +9 -0
  15. package/build/transaction/offline/interfaces/ISerializableState.d.ts +10 -2
  16. package/build/transaction/offline/interfaces/ISerializableState.js +3 -2
  17. package/build/transaction/shared/TweakedTransaction.js +27 -5
  18. package/package.json +1 -1
  19. package/src/transaction/TransactionFactory.ts +1 -1
  20. package/src/transaction/builders/FundingTransaction.ts +21 -16
  21. package/src/transaction/builders/TransactionBuilder.ts +46 -10
  22. package/src/transaction/offline/OfflineTransactionManager.ts +191 -1
  23. package/src/transaction/offline/TransactionSerializer.ts +11 -0
  24. package/src/transaction/offline/interfaces/ISerializableState.ts +10 -2
  25. package/src/transaction/shared/TweakedTransaction.ts +33 -5
  26. package/test/add-refund-output.test.ts +96 -11
  27. package/test/csv-multisig-offline-edges.test.ts +293 -0
  28. package/test/csv-multisig-offline.test.ts +202 -0
  29. package/test/transaction-builders.test.ts +69 -3
  30. package/tsconfig.build.tsbuildinfo +1 -1
@@ -1,119 +1,115 @@
1
- import { n as Dt, r as Bn } from "./rolldown-runtime.js";
2
- function Sn(t) {
1
+ import { n as dt, r as Ze } from "./rolldown-runtime.js";
2
+ function Ce(t) {
3
3
  return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in t && t.BYTES_PER_ELEMENT === 1;
4
4
  }
5
- function Pt(t, n = "") {
5
+ function Et(t, e = "") {
6
6
  if (typeof t != "number") {
7
- const e = n && `"${n}" `;
8
- throw new TypeError(`${e}expected number, got ${typeof t}`);
7
+ const r = e && `"${e}" `;
8
+ throw new TypeError(`${r}expected number, got ${typeof t}`);
9
9
  }
10
10
  if (!Number.isSafeInteger(t) || t < 0) {
11
- const e = n && `"${n}" `;
12
- throw new RangeError(`${e}expected integer >= 0, got ${t}`);
11
+ const r = e && `"${e}" `;
12
+ throw new RangeError(`${r}expected integer >= 0, got ${t}`);
13
13
  }
14
14
  }
15
- function zt(t, n, e = "") {
16
- const r = Sn(t), o = t?.length, i = n !== void 0;
17
- if (!r || i && o !== n) {
18
- const a = e && `"${e}" `, f = i ? ` of length ${n}` : "", l = r ? `length=${o}` : `type=${typeof t}`, g = a + "expected Uint8Array" + f + ", got " + l;
19
- throw r ? new RangeError(g) : new TypeError(g);
15
+ function mt(t, e, r = "") {
16
+ const n = Ce(t), o = t?.length, i = e !== void 0;
17
+ if (!n || i && o !== e) {
18
+ const c = r && `"${r}" `, s = i ? ` of length ${e}` : "", a = n ? `length=${o}` : `type=${typeof t}`, u = c + "expected Uint8Array" + s + ", got " + a;
19
+ throw n ? new RangeError(u) : new TypeError(u);
20
20
  }
21
21
  return t;
22
22
  }
23
- function An(t) {
23
+ function ke(t) {
24
24
  if (typeof t != "function" || typeof t.create != "function") throw new TypeError("Hash must wrapped by utils.createHasher");
25
- if (Pt(t.outputLen), Pt(t.blockLen), t.outputLen < 1) throw new Error('"outputLen" must be >= 1');
25
+ if (Et(t.outputLen), Et(t.blockLen), t.outputLen < 1) throw new Error('"outputLen" must be >= 1');
26
26
  if (t.blockLen < 1) throw new Error('"blockLen" must be >= 1');
27
27
  }
28
- function de(t, n = !0) {
28
+ function Dt(t, e = !0) {
29
29
  if (t.destroyed) throw new Error("Hash instance has been destroyed");
30
- if (n && t.finished) throw new Error("Hash#digest() has already been called");
30
+ if (e && t.finished) throw new Error("Hash#digest() has already been called");
31
31
  }
32
- function Rn(t, n) {
33
- zt(t, void 0, "digestInto() output");
34
- const e = n.outputLen;
35
- if (t.length < e) throw new RangeError('"digestInto() output" expected to be of length >=' + e);
32
+ function je(t, e) {
33
+ mt(t, void 0, "digestInto() output");
34
+ const r = e.outputLen;
35
+ if (t.length < r) throw new RangeError('"digestInto() output" expected to be of length >=' + r);
36
36
  }
37
- function Kt(...t) {
38
- for (let n = 0; n < t.length; n++) t[n].fill(0);
37
+ function Bt(...t) {
38
+ for (let e = 0; e < t.length; e++) t[e].fill(0);
39
39
  }
40
- function Be(t) {
40
+ function Vt(t) {
41
41
  return new DataView(t.buffer, t.byteOffset, t.byteLength);
42
42
  }
43
- function vt(t, n) {
44
- return t << 32 - n | t >>> n;
43
+ function nt(t, e) {
44
+ return t << 32 - e | t >>> e;
45
45
  }
46
- function Ho(t, n) {
47
- return t << n | t >>> 32 - n >>> 0;
46
+ function vr(t, e) {
47
+ return t << e | t >>> 32 - e >>> 0;
48
48
  }
49
- function Ke(t) {
50
- if (zt(t), Xe) return t.toHex();
51
- let n = "";
52
- for (let e = 0; e < t.length; e++) n += On[t[e]];
53
- return n;
49
+ function le(t) {
50
+ if (mt(t), he) return t.toHex();
51
+ let e = "";
52
+ for (let r = 0; r < t.length; r++) e += Ye[t[r]];
53
+ return e;
54
54
  }
55
- function sn(t) {
56
- if (t >= xt._0 && t <= xt._9) return t - xt._0;
57
- if (t >= xt.A && t <= xt.F) return t - (xt.A - 10);
58
- if (t >= xt.a && t <= xt.f) return t - (xt.a - 10);
55
+ function Ae(t) {
56
+ if (t >= rt._0 && t <= rt._9) return t - rt._0;
57
+ if (t >= rt.A && t <= rt.F) return t - (rt.A - 10);
58
+ if (t >= rt.a && t <= rt.f) return t - (rt.a - 10);
59
59
  }
60
- function _n(t) {
60
+ function Ve(t) {
61
61
  if (typeof t != "string") throw new TypeError("hex string expected, got " + typeof t);
62
- if (Xe) try {
62
+ if (he) try {
63
63
  return Uint8Array.fromHex(t);
64
64
  } catch (o) {
65
65
  throw o instanceof SyntaxError ? new RangeError(o.message) : o;
66
66
  }
67
- const n = t.length, e = n / 2;
68
- if (n % 2) throw new RangeError("hex string expected, got unpadded hex of length " + n);
69
- const r = new Uint8Array(e);
70
- for (let o = 0, i = 0; o < e; o++, i += 2) {
71
- const a = sn(t.charCodeAt(i)), f = sn(t.charCodeAt(i + 1));
72
- if (a === void 0 || f === void 0) {
73
- const l = t[i] + t[i + 1];
74
- throw new RangeError('hex string expected, got non-hex character "' + l + '" at index ' + i);
67
+ const e = t.length, r = e / 2;
68
+ if (e % 2) throw new RangeError("hex string expected, got unpadded hex of length " + e);
69
+ const n = new Uint8Array(r);
70
+ for (let o = 0, i = 0; o < r; o++, i += 2) {
71
+ const c = Ae(t.charCodeAt(i)), s = Ae(t.charCodeAt(i + 1));
72
+ if (c === void 0 || s === void 0) {
73
+ const a = t[i] + t[i + 1];
74
+ throw new RangeError('hex string expected, got non-hex character "' + a + '" at index ' + i);
75
75
  }
76
- r[o] = a * 16 + f;
76
+ n[o] = c * 16 + s;
77
77
  }
78
- return r;
79
- }
80
- function Nt(t) {
81
- if (typeof t != "string") throw new TypeError("string expected");
82
- return new Uint8Array(new TextEncoder().encode(t));
78
+ return n;
83
79
  }
84
- function br(...t) {
85
- let n = 0;
86
- for (let r = 0; r < t.length; r++) {
87
- const o = t[r];
88
- zt(o), n += o.length;
80
+ function In(...t) {
81
+ let e = 0;
82
+ for (let n = 0; n < t.length; n++) {
83
+ const o = t[n];
84
+ mt(o), e += o.length;
89
85
  }
90
- const e = new Uint8Array(n);
91
- for (let r = 0, o = 0; r < t.length; r++) {
92
- const i = t[r];
93
- e.set(i, o), o += i.length;
86
+ const r = new Uint8Array(e);
87
+ for (let n = 0, o = 0; n < t.length; n++) {
88
+ const i = t[n];
89
+ r.set(i, o), o += i.length;
94
90
  }
95
- return e;
91
+ return r;
96
92
  }
97
- function Yt(t, n = {}) {
98
- const e = (o, i) => t(i).update(o).digest(), r = t(void 0);
99
- return e.outputLen = r.outputLen, e.blockLen = r.blockLen, e.canXOF = r.canXOF, e.create = (o) => t(o), Object.assign(e, n), Object.freeze(e);
93
+ function xt(t, e = {}) {
94
+ const r = (o, i) => t(i).update(o).digest(), n = t(void 0);
95
+ return r.outputLen = n.outputLen, r.blockLen = n.blockLen, r.canXOF = n.canXOF, r.create = (o) => t(o), Object.assign(r, e), Object.freeze(r);
100
96
  }
101
- function yr(t = 32) {
102
- Pt(t, "bytesLength");
103
- const n = typeof globalThis == "object" ? globalThis.crypto : null;
104
- if (typeof n?.getRandomValues != "function") throw new Error("crypto.getRandomValues must be defined");
97
+ function Fn(t = 32) {
98
+ Et(t, "bytesLength");
99
+ const e = typeof globalThis == "object" ? globalThis.crypto : null;
100
+ if (typeof e?.getRandomValues != "function") throw new Error("crypto.getRandomValues must be defined");
105
101
  if (t > 65536) throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);
106
- return n.getRandomValues(new Uint8Array(t));
102
+ return e.getRandomValues(new Uint8Array(t));
107
103
  }
108
- var pr, Xe, On, xt, Lt, Qt = Dt((() => {
109
- pr = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68, Xe = typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", On = /* @__PURE__ */ Array.from({ length: 256 }, (t, n) => n.toString(16).padStart(2, "0")), xt = {
104
+ var he, Ye, rt, gt, It = dt((() => {
105
+ he = typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", Ye = /* @__PURE__ */ Array.from({ length: 256 }, (t, e) => e.toString(16).padStart(2, "0")), rt = {
110
106
  _0: 48,
111
107
  _9: 57,
112
108
  A: 65,
113
109
  F: 70,
114
110
  a: 97,
115
111
  f: 102
116
- }, Lt = (t) => ({ oid: Uint8Array.from([
112
+ }, gt = (t) => ({ oid: Uint8Array.from([
117
113
  6,
118
114
  9,
119
115
  96,
@@ -126,11 +122,11 @@ var pr, Xe, On, xt, Lt, Qt = Dt((() => {
126
122
  2,
127
123
  t
128
124
  ]) });
129
- })), To = /* @__PURE__ */ Bn({
130
- _HMAC: () => le,
131
- hmac: () => We
132
- }), le, We, Er = Dt((() => {
133
- Qt(), le = class {
125
+ })), xr = /* @__PURE__ */ Ze({
126
+ _HMAC: () => Ut,
127
+ hmac: () => de
128
+ }), Ut, de, Ln = dt((() => {
129
+ It(), Ut = class {
134
130
  oHash;
135
131
  iHash;
136
132
  blockLen;
@@ -138,23 +134,23 @@ var pr, Xe, On, xt, Lt, Qt = Dt((() => {
138
134
  canXOF = !1;
139
135
  finished = !1;
140
136
  destroyed = !1;
141
- constructor(t, n) {
142
- if (An(t), zt(n, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function") throw new Error("Expected instance of class which extends utils.Hash");
137
+ constructor(t, e) {
138
+ if (ke(t), mt(e, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function") throw new Error("Expected instance of class which extends utils.Hash");
143
139
  this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
144
- const e = this.blockLen, r = new Uint8Array(e);
145
- r.set(n.length > e ? t.create().update(n).digest() : n);
146
- for (let o = 0; o < r.length; o++) r[o] ^= 54;
147
- this.iHash.update(r), this.oHash = t.create();
148
- for (let o = 0; o < r.length; o++) r[o] ^= 106;
149
- this.oHash.update(r), Kt(r);
140
+ const r = this.blockLen, n = new Uint8Array(r);
141
+ n.set(e.length > r ? t.create().update(e).digest() : e);
142
+ for (let o = 0; o < n.length; o++) n[o] ^= 54;
143
+ this.iHash.update(n), this.oHash = t.create();
144
+ for (let o = 0; o < n.length; o++) n[o] ^= 106;
145
+ this.oHash.update(n), Bt(n);
150
146
  }
151
147
  update(t) {
152
- return de(this), this.iHash.update(t), this;
148
+ return Dt(this), this.iHash.update(t), this;
153
149
  }
154
150
  digestInto(t) {
155
- de(this), Rn(t, this), this.finished = !0;
156
- const n = t.subarray(0, this.outputLen);
157
- this.iHash.digestInto(n), this.oHash.update(n), this.oHash.digestInto(n), this.destroy();
151
+ Dt(this), je(t, this), this.finished = !0;
152
+ const e = t.subarray(0, this.outputLen);
153
+ this.iHash.digestInto(e), this.oHash.update(e), this.oHash.digestInto(e), this.destroy();
158
154
  }
159
155
  digest() {
160
156
  const t = new Uint8Array(this.oHash.outputLen);
@@ -162,8 +158,8 @@ var pr, Xe, On, xt, Lt, Qt = Dt((() => {
162
158
  }
163
159
  _cloneInto(t) {
164
160
  t ||= Object.create(Object.getPrototypeOf(this), {});
165
- const { oHash: n, iHash: e, finished: r, destroyed: o, blockLen: i, outputLen: a } = this;
166
- return t = t, t.finished = r, t.destroyed = o, t.blockLen = i, t.outputLen = a, t.oHash = n._cloneInto(t.oHash), t.iHash = e._cloneInto(t.iHash), t;
161
+ const { oHash: e, iHash: r, finished: n, destroyed: o, blockLen: i, outputLen: c } = this;
162
+ return t = t, t.finished = n, t.destroyed = o, t.blockLen = i, t.outputLen = c, t.oHash = e._cloneInto(t.oHash), t.iHash = r._cloneInto(t.iHash), t;
167
163
  }
168
164
  clone() {
169
165
  return this._cloneInto();
@@ -171,19 +167,19 @@ var pr, Xe, On, xt, Lt, Qt = Dt((() => {
171
167
  destroy() {
172
168
  this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
173
169
  }
174
- }, We = /* @__PURE__ */ (() => {
175
- const t = ((n, e, r) => new le(n, e).update(r).digest());
176
- return t.create = (n, e) => new le(n, e), t;
170
+ }, de = /* @__PURE__ */ (() => {
171
+ const t = ((e, r, n) => new Ut(e, r).update(n).digest());
172
+ return t.create = (e, r) => new Ut(e, r), t;
177
173
  })();
178
174
  }));
179
- function vr(t, n, e) {
180
- return t & n ^ ~t & e;
175
+ function Nn(t, e, r) {
176
+ return t & e ^ ~t & r;
181
177
  }
182
- function xr(t, n, e) {
183
- return t & n ^ t & e ^ n & e;
178
+ function Tn(t, e, r) {
179
+ return t & e ^ t & r ^ e & r;
184
180
  }
185
- var Fe, Ht, Tt, lt, ut, Br = Dt((() => {
186
- Qt(), Fe = class {
181
+ var Wt, at, ut, M, G, Un = dt((() => {
182
+ It(), Wt = class {
187
183
  blockLen;
188
184
  outputLen;
189
185
  canXOF = !1;
@@ -195,51 +191,51 @@ var Fe, Ht, Tt, lt, ut, Br = Dt((() => {
195
191
  length = 0;
196
192
  pos = 0;
197
193
  destroyed = !1;
198
- constructor(t, n, e, r) {
199
- this.blockLen = t, this.outputLen = n, this.padOffset = e, this.isLE = r, this.buffer = new Uint8Array(t), this.view = Be(this.buffer);
194
+ constructor(t, e, r, n) {
195
+ this.blockLen = t, this.outputLen = e, this.padOffset = r, this.isLE = n, this.buffer = new Uint8Array(t), this.view = Vt(this.buffer);
200
196
  }
201
197
  update(t) {
202
- de(this), zt(t);
203
- const { view: n, buffer: e, blockLen: r } = this, o = t.length;
198
+ Dt(this), mt(t);
199
+ const { view: e, buffer: r, blockLen: n } = this, o = t.length;
204
200
  for (let i = 0; i < o; ) {
205
- const a = Math.min(r - this.pos, o - i);
206
- if (a === r) {
207
- const f = Be(t);
208
- for (; r <= o - i; i += r) this.process(f, i);
201
+ const c = Math.min(n - this.pos, o - i);
202
+ if (c === n) {
203
+ const s = Vt(t);
204
+ for (; n <= o - i; i += n) this.process(s, i);
209
205
  continue;
210
206
  }
211
- e.set(t.subarray(i, i + a), this.pos), this.pos += a, i += a, this.pos === r && (this.process(n, 0), this.pos = 0);
207
+ r.set(t.subarray(i, i + c), this.pos), this.pos += c, i += c, this.pos === n && (this.process(e, 0), this.pos = 0);
212
208
  }
213
209
  return this.length += t.length, this.roundClean(), this;
214
210
  }
215
211
  digestInto(t) {
216
- de(this), Rn(t, this), this.finished = !0;
217
- const { buffer: n, view: e, blockLen: r, isLE: o } = this;
212
+ Dt(this), je(t, this), this.finished = !0;
213
+ const { buffer: e, view: r, blockLen: n, isLE: o } = this;
218
214
  let { pos: i } = this;
219
- n[i++] = 128, Kt(this.buffer.subarray(i)), this.padOffset > r - i && (this.process(e, 0), i = 0);
220
- for (let s = i; s < r; s++) n[s] = 0;
221
- e.setBigUint64(r - 8, BigInt(this.length * 8), o), this.process(e, 0);
222
- const a = Be(t), f = this.outputLen;
223
- if (f % 4) throw new Error("_sha2: outputLen must be aligned to 32bit");
224
- const l = f / 4, g = this.get();
225
- if (l > g.length) throw new Error("_sha2: outputLen bigger than state");
226
- for (let s = 0; s < l; s++) a.setUint32(4 * s, g[s], o);
215
+ e[i++] = 128, Bt(this.buffer.subarray(i)), this.padOffset > n - i && (this.process(r, 0), i = 0);
216
+ for (let f = i; f < n; f++) e[f] = 0;
217
+ r.setBigUint64(n - 8, BigInt(this.length * 8), o), this.process(r, 0);
218
+ const c = Vt(t), s = this.outputLen;
219
+ if (s % 4) throw new Error("_sha2: outputLen must be aligned to 32bit");
220
+ const a = s / 4, u = this.get();
221
+ if (a > u.length) throw new Error("_sha2: outputLen bigger than state");
222
+ for (let f = 0; f < a; f++) c.setUint32(4 * f, u[f], o);
227
223
  }
228
224
  digest() {
229
- const { buffer: t, outputLen: n } = this;
225
+ const { buffer: t, outputLen: e } = this;
230
226
  this.digestInto(t);
231
- const e = t.slice(0, n);
232
- return this.destroy(), e;
227
+ const r = t.slice(0, e);
228
+ return this.destroy(), r;
233
229
  }
234
230
  _cloneInto(t) {
235
231
  t ||= new this.constructor(), t.set(...this.get());
236
- const { blockLen: n, buffer: e, length: r, finished: o, destroyed: i, pos: a } = this;
237
- return t.destroyed = i, t.finished = o, t.length = r, t.pos = a, r % n && t.buffer.set(e), t;
232
+ const { blockLen: e, buffer: r, length: n, finished: o, destroyed: i, pos: c } = this;
233
+ return t.destroyed = i, t.finished = o, t.length = n, t.pos = c, n % e && t.buffer.set(r), t;
238
234
  }
239
235
  clone() {
240
236
  return this._cloneInto();
241
237
  }
242
- }, Ht = /* @__PURE__ */ Uint32Array.from([
238
+ }, at = /* @__PURE__ */ Uint32Array.from([
243
239
  1779033703,
244
240
  3144134277,
245
241
  1013904242,
@@ -248,7 +244,7 @@ var Fe, Ht, Tt, lt, ut, Br = Dt((() => {
248
244
  2600822924,
249
245
  528734635,
250
246
  1541459225
251
- ]), Tt = /* @__PURE__ */ Uint32Array.from([
247
+ ]), ut = /* @__PURE__ */ Uint32Array.from([
252
248
  3238371032,
253
249
  914150663,
254
250
  812702999,
@@ -257,7 +253,7 @@ var Fe, Ht, Tt, lt, ut, Br = Dt((() => {
257
253
  1750603025,
258
254
  1694076839,
259
255
  3204075428
260
- ]), lt = /* @__PURE__ */ Uint32Array.from([
256
+ ]), M = /* @__PURE__ */ Uint32Array.from([
261
257
  3418070365,
262
258
  3238371032,
263
259
  1654270250,
@@ -274,7 +270,7 @@ var Fe, Ht, Tt, lt, ut, Br = Dt((() => {
274
270
  1694076839,
275
271
  1203062813,
276
272
  3204075428
277
- ]), ut = /* @__PURE__ */ Uint32Array.from([
273
+ ]), G = /* @__PURE__ */ Uint32Array.from([
278
274
  1779033703,
279
275
  4089235720,
280
276
  3144134277,
@@ -293,48 +289,48 @@ var Fe, Ht, Tt, lt, ut, Br = Dt((() => {
293
289
  327033209
294
290
  ]);
295
291
  }));
296
- function Sr(t, n = !1) {
297
- return n ? {
298
- h: Number(t & ee),
299
- l: Number(t >> Ie & ee)
292
+ function $n(t, e = !1) {
293
+ return e ? {
294
+ h: Number(t & St),
295
+ l: Number(t >> Qt & St)
300
296
  } : {
301
- h: Number(t >> Ie & ee) | 0,
302
- l: Number(t & ee) | 0
297
+ h: Number(t >> Qt & St) | 0,
298
+ l: Number(t & St) | 0
303
299
  };
304
300
  }
305
- function Ar(t, n = !1) {
306
- const e = t.length;
307
- let r = new Uint32Array(e), o = new Uint32Array(e);
308
- for (let i = 0; i < e; i++) {
309
- const { h: a, l: f } = Sr(t[i], n);
310
- [r[i], o[i]] = [a, f];
301
+ function Dn(t, e = !1) {
302
+ const r = t.length;
303
+ let n = new Uint32Array(r), o = new Uint32Array(r);
304
+ for (let i = 0; i < r; i++) {
305
+ const { h: c, l: s } = $n(t[i], e);
306
+ [n[i], o[i]] = [c, s];
311
307
  }
312
- return [r, o];
308
+ return [n, o];
313
309
  }
314
- function At(t, n, e, r) {
315
- const o = (n >>> 0) + (r >>> 0);
310
+ function it(t, e, r, n) {
311
+ const o = (e >>> 0) + (n >>> 0);
316
312
  return {
317
- h: t + e + (o / 2 ** 32 | 0) | 0,
313
+ h: t + r + (o / 2 ** 32 | 0) | 0,
318
314
  l: o | 0
319
315
  };
320
316
  }
321
- var ee, Ie, Ne, je, Ut, qt, ne, re, Hn, Tn, Fn, In, Nn, jn, Rr = Dt((() => {
322
- ee = /* @__PURE__ */ BigInt(2 ** 32 - 1), Ie = /* @__PURE__ */ BigInt(32), Ne = (t, n, e) => t >>> e, je = (t, n, e) => t << 32 - e | n >>> e, Ut = (t, n, e) => t >>> e | n << 32 - e, qt = (t, n, e) => t << 32 - e | n >>> e, ne = (t, n, e) => t << 64 - e | n >>> e - 32, re = (t, n, e) => t >>> e - 32 | n << 64 - e, Hn = (t, n, e) => (t >>> 0) + (n >>> 0) + (e >>> 0), Tn = (t, n, e, r) => n + e + r + (t / 2 ** 32 | 0) | 0, Fn = (t, n, e, r) => (t >>> 0) + (n >>> 0) + (e >>> 0) + (r >>> 0), In = (t, n, e, r, o) => n + e + r + o + (t / 2 ** 32 | 0) | 0, Nn = (t, n, e, r, o) => (t >>> 0) + (n >>> 0) + (e >>> 0) + (r >>> 0) + (o >>> 0), jn = (t, n, e, r, o, i) => n + e + r + o + i + (t / 2 ** 32 | 0) | 0;
323
- })), Fo = /* @__PURE__ */ Bn({
324
- _SHA224: () => Le,
325
- _SHA256: () => De,
326
- _SHA384: () => qe,
327
- _SHA512: () => Ue,
328
- _SHA512_224: () => Ce,
329
- _SHA512_256: () => ke,
330
- sha224: () => Dn,
331
- sha256: () => jt,
332
- sha384: () => Un,
333
- sha512: () => Ln,
334
- sha512_224: () => Cn,
335
- sha512_256: () => qn
336
- }), cn, Rt, Se, De, Le, Ae, fn, an, _t, Ot, te, Ue, qe, ft, at, Ce, ke, jt, Dn, Ln, Un, qn, Cn, _r = Dt((() => {
337
- Br(), Rr(), Qt(), cn = /* @__PURE__ */ Uint32Array.from([
317
+ var St, Qt, Jt, Pt, bt, wt, _t, Ht, ze, Me, Ge, Ke, Xe, We, qn = dt((() => {
318
+ St = /* @__PURE__ */ BigInt(2 ** 32 - 1), Qt = /* @__PURE__ */ BigInt(32), Jt = (t, e, r) => t >>> r, Pt = (t, e, r) => t << 32 - r | e >>> r, bt = (t, e, r) => t >>> r | e << 32 - r, wt = (t, e, r) => t << 32 - r | e >>> r, _t = (t, e, r) => t << 64 - r | e >>> r - 32, Ht = (t, e, r) => t >>> r - 32 | e << 64 - r, ze = (t, e, r) => (t >>> 0) + (e >>> 0) + (r >>> 0), Me = (t, e, r, n) => e + r + n + (t / 2 ** 32 | 0) | 0, Ge = (t, e, r, n) => (t >>> 0) + (e >>> 0) + (r >>> 0) + (n >>> 0), Ke = (t, e, r, n, o) => e + r + n + o + (t / 2 ** 32 | 0) | 0, Xe = (t, e, r, n, o) => (t >>> 0) + (e >>> 0) + (r >>> 0) + (n >>> 0) + (o >>> 0), We = (t, e, r, n, o, i) => e + r + n + o + i + (t / 2 ** 32 | 0) | 0;
319
+ })), Br = /* @__PURE__ */ Ze({
320
+ _SHA224: () => ee,
321
+ _SHA256: () => te,
322
+ _SHA384: () => re,
323
+ _SHA512: () => ne,
324
+ _SHA512_224: () => oe,
325
+ _SHA512_256: () => ie,
326
+ sha224: () => Qe,
327
+ sha256: () => ge,
328
+ sha384: () => Pe,
329
+ sha512: () => Je,
330
+ sha512_224: () => en,
331
+ sha512_256: () => tn
332
+ }), Re, st, Yt, te, ee, zt, Se, _e, ct, ft, Rt, ne, re, Y, z, oe, ie, ge, Qe, Je, Pe, tn, en, Zn = dt((() => {
333
+ Un(), qn(), It(), Re = /* @__PURE__ */ Uint32Array.from([
338
334
  1116352408,
339
335
  1899447441,
340
336
  3049323471,
@@ -399,70 +395,70 @@ var ee, Ie, Ne, je, Ut, qt, ne, re, Hn, Tn, Fn, In, Nn, jn, Rr = Dt((() => {
399
395
  2756734187,
400
396
  3204031479,
401
397
  3329325298
402
- ]), Rt = /* @__PURE__ */ new Uint32Array(64), Se = class extends Fe {
398
+ ]), st = /* @__PURE__ */ new Uint32Array(64), Yt = class extends Wt {
403
399
  constructor(t) {
404
400
  super(64, t, 8, !1);
405
401
  }
406
402
  get() {
407
- const { A: t, B: n, C: e, D: r, E: o, F: i, G: a, H: f } = this;
403
+ const { A: t, B: e, C: r, D: n, E: o, F: i, G: c, H: s } = this;
408
404
  return [
409
405
  t,
410
- n,
411
406
  e,
412
407
  r,
408
+ n,
413
409
  o,
414
410
  i,
415
- a,
416
- f
411
+ c,
412
+ s
417
413
  ];
418
414
  }
419
- set(t, n, e, r, o, i, a, f) {
420
- this.A = t | 0, this.B = n | 0, this.C = e | 0, this.D = r | 0, this.E = o | 0, this.F = i | 0, this.G = a | 0, this.H = f | 0;
415
+ set(t, e, r, n, o, i, c, s) {
416
+ this.A = t | 0, this.B = e | 0, this.C = r | 0, this.D = n | 0, this.E = o | 0, this.F = i | 0, this.G = c | 0, this.H = s | 0;
421
417
  }
422
- process(t, n) {
423
- for (let s = 0; s < 16; s++, n += 4) Rt[s] = t.getUint32(n, !1);
424
- for (let s = 16; s < 64; s++) {
425
- const u = Rt[s - 15], d = Rt[s - 2], h = vt(u, 7) ^ vt(u, 18) ^ u >>> 3;
426
- Rt[s] = (vt(d, 17) ^ vt(d, 19) ^ d >>> 10) + Rt[s - 7] + h + Rt[s - 16] | 0;
418
+ process(t, e) {
419
+ for (let f = 0; f < 16; f++, e += 4) st[f] = t.getUint32(e, !1);
420
+ for (let f = 16; f < 64; f++) {
421
+ const g = st[f - 15], m = st[f - 2], w = nt(g, 7) ^ nt(g, 18) ^ g >>> 3;
422
+ st[f] = (nt(m, 17) ^ nt(m, 19) ^ m >>> 10) + st[f - 7] + w + st[f - 16] | 0;
427
423
  }
428
- let { A: e, B: r, C: o, D: i, E: a, F: f, G: l, H: g } = this;
429
- for (let s = 0; s < 64; s++) {
430
- const u = vt(a, 6) ^ vt(a, 11) ^ vt(a, 25), d = g + u + vr(a, f, l) + cn[s] + Rt[s] | 0, h = (vt(e, 2) ^ vt(e, 13) ^ vt(e, 22)) + xr(e, r, o) | 0;
431
- g = l, l = f, f = a, a = i + d | 0, i = o, o = r, r = e, e = d + h | 0;
424
+ let { A: r, B: n, C: o, D: i, E: c, F: s, G: a, H: u } = this;
425
+ for (let f = 0; f < 64; f++) {
426
+ const g = nt(c, 6) ^ nt(c, 11) ^ nt(c, 25), m = u + g + Nn(c, s, a) + Re[f] + st[f] | 0, w = (nt(r, 2) ^ nt(r, 13) ^ nt(r, 22)) + Tn(r, n, o) | 0;
427
+ u = a, a = s, s = c, c = i + m | 0, i = o, o = n, n = r, r = m + w | 0;
432
428
  }
433
- e = e + this.A | 0, r = r + this.B | 0, o = o + this.C | 0, i = i + this.D | 0, a = a + this.E | 0, f = f + this.F | 0, l = l + this.G | 0, g = g + this.H | 0, this.set(e, r, o, i, a, f, l, g);
429
+ r = r + this.A | 0, n = n + this.B | 0, o = o + this.C | 0, i = i + this.D | 0, c = c + this.E | 0, s = s + this.F | 0, a = a + this.G | 0, u = u + this.H | 0, this.set(r, n, o, i, c, s, a, u);
434
430
  }
435
431
  roundClean() {
436
- Kt(Rt);
432
+ Bt(st);
437
433
  }
438
434
  destroy() {
439
- this.destroyed = !0, this.set(0, 0, 0, 0, 0, 0, 0, 0), Kt(this.buffer);
440
- }
441
- }, De = class extends Se {
442
- A = Ht[0] | 0;
443
- B = Ht[1] | 0;
444
- C = Ht[2] | 0;
445
- D = Ht[3] | 0;
446
- E = Ht[4] | 0;
447
- F = Ht[5] | 0;
448
- G = Ht[6] | 0;
449
- H = Ht[7] | 0;
435
+ this.destroyed = !0, this.set(0, 0, 0, 0, 0, 0, 0, 0), Bt(this.buffer);
436
+ }
437
+ }, te = class extends Yt {
438
+ A = at[0] | 0;
439
+ B = at[1] | 0;
440
+ C = at[2] | 0;
441
+ D = at[3] | 0;
442
+ E = at[4] | 0;
443
+ F = at[5] | 0;
444
+ G = at[6] | 0;
445
+ H = at[7] | 0;
450
446
  constructor() {
451
447
  super(32);
452
448
  }
453
- }, Le = class extends Se {
454
- A = Tt[0] | 0;
455
- B = Tt[1] | 0;
456
- C = Tt[2] | 0;
457
- D = Tt[3] | 0;
458
- E = Tt[4] | 0;
459
- F = Tt[5] | 0;
460
- G = Tt[6] | 0;
461
- H = Tt[7] | 0;
449
+ }, ee = class extends Yt {
450
+ A = ut[0] | 0;
451
+ B = ut[1] | 0;
452
+ C = ut[2] | 0;
453
+ D = ut[3] | 0;
454
+ E = ut[4] | 0;
455
+ F = ut[5] | 0;
456
+ G = ut[6] | 0;
457
+ H = ut[7] | 0;
462
458
  constructor() {
463
459
  super(28);
464
460
  }
465
- }, Ae = Ar([
461
+ }, zt = Dn([
466
462
  "0x428a2f98d728ae22",
467
463
  "0x7137449123ef65cd",
468
464
  "0xb5c0fbcfec4d3b2f",
@@ -543,97 +539,97 @@ var ee, Ie, Ne, je, Ut, qt, ne, re, Hn, Tn, Fn, In, Nn, jn, Rr = Dt((() => {
543
539
  "0x597f299cfc657e2a",
544
540
  "0x5fcb6fab3ad6faec",
545
541
  "0x6c44198c4a475817"
546
- ].map((t) => BigInt(t))), fn = Ae[0], an = Ae[1], _t = /* @__PURE__ */ new Uint32Array(80), Ot = /* @__PURE__ */ new Uint32Array(80), te = class extends Fe {
542
+ ].map((t) => BigInt(t))), Se = zt[0], _e = zt[1], ct = /* @__PURE__ */ new Uint32Array(80), ft = /* @__PURE__ */ new Uint32Array(80), Rt = class extends Wt {
547
543
  constructor(t) {
548
544
  super(128, t, 16, !1);
549
545
  }
550
546
  get() {
551
- const { Ah: t, Al: n, Bh: e, Bl: r, Ch: o, Cl: i, Dh: a, Dl: f, Eh: l, El: g, Fh: s, Fl: u, Gh: d, Gl: h, Hh: w, Hl: b } = this;
547
+ const { Ah: t, Al: e, Bh: r, Bl: n, Ch: o, Cl: i, Dh: c, Dl: s, Eh: a, El: u, Fh: f, Fl: g, Gh: m, Gl: w, Hh: A, Hl: _ } = this;
552
548
  return [
553
549
  t,
554
- n,
555
550
  e,
556
551
  r,
552
+ n,
557
553
  o,
558
554
  i,
555
+ c,
556
+ s,
559
557
  a,
558
+ u,
560
559
  f,
561
- l,
562
560
  g,
563
- s,
564
- u,
565
- d,
566
- h,
561
+ m,
567
562
  w,
568
- b
563
+ A,
564
+ _
569
565
  ];
570
566
  }
571
- set(t, n, e, r, o, i, a, f, l, g, s, u, d, h, w, b) {
572
- this.Ah = t | 0, this.Al = n | 0, this.Bh = e | 0, this.Bl = r | 0, this.Ch = o | 0, this.Cl = i | 0, this.Dh = a | 0, this.Dl = f | 0, this.Eh = l | 0, this.El = g | 0, this.Fh = s | 0, this.Fl = u | 0, this.Gh = d | 0, this.Gl = h | 0, this.Hh = w | 0, this.Hl = b | 0;
567
+ set(t, e, r, n, o, i, c, s, a, u, f, g, m, w, A, _) {
568
+ this.Ah = t | 0, this.Al = e | 0, this.Bh = r | 0, this.Bl = n | 0, this.Ch = o | 0, this.Cl = i | 0, this.Dh = c | 0, this.Dl = s | 0, this.Eh = a | 0, this.El = u | 0, this.Fh = f | 0, this.Fl = g | 0, this.Gh = m | 0, this.Gl = w | 0, this.Hh = A | 0, this.Hl = _ | 0;
573
569
  }
574
- process(t, n) {
575
- for (let B = 0; B < 16; B++, n += 4)
576
- _t[B] = t.getUint32(n), Ot[B] = t.getUint32(n += 4);
577
- for (let B = 16; B < 80; B++) {
578
- const C = _t[B - 15] | 0, O = Ot[B - 15] | 0, F = Ut(C, O, 1) ^ Ut(C, O, 8) ^ Ne(C, O, 7), z = qt(C, O, 1) ^ qt(C, O, 8) ^ je(C, O, 7), W = _t[B - 2] | 0, N = Ot[B - 2] | 0, V = Ut(W, N, 19) ^ ne(W, N, 61) ^ Ne(W, N, 6), K = qt(W, N, 19) ^ re(W, N, 61) ^ je(W, N, 6), M = Fn(z, K, Ot[B - 7], Ot[B - 16]);
579
- _t[B] = In(M, F, V, _t[B - 7], _t[B - 16]) | 0, Ot[B] = M | 0;
570
+ process(t, e) {
571
+ for (let x = 0; x < 16; x++, e += 4)
572
+ ct[x] = t.getUint32(e), ft[x] = t.getUint32(e += 4);
573
+ for (let x = 16; x < 80; x++) {
574
+ const q = ct[x - 15] | 0, Z = ft[x - 15] | 0, T = bt(q, Z, 1) ^ bt(q, Z, 8) ^ Jt(q, Z, 7), Q = wt(q, Z, 1) ^ wt(q, Z, 8) ^ Pt(q, Z, 7), $ = ct[x - 2] | 0, R = ft[x - 2] | 0, C = bt($, R, 19) ^ _t($, R, 61) ^ Jt($, R, 6), X = wt($, R, 19) ^ Ht($, R, 61) ^ Pt($, R, 6), F = Ge(Q, X, ft[x - 7], ft[x - 16]);
575
+ ct[x] = Ke(F, T, C, ct[x - 7], ct[x - 16]) | 0, ft[x] = F | 0;
580
576
  }
581
- let { Ah: e, Al: r, Bh: o, Bl: i, Ch: a, Cl: f, Dh: l, Dl: g, Eh: s, El: u, Fh: d, Fl: h, Gh: w, Gl: b, Hh: E, Hl: T } = this;
582
- for (let B = 0; B < 80; B++) {
583
- const C = Ut(s, u, 14) ^ Ut(s, u, 18) ^ ne(s, u, 41), O = qt(s, u, 14) ^ qt(s, u, 18) ^ re(s, u, 41), F = s & d ^ ~s & w, z = u & h ^ ~u & b, W = Nn(T, O, z, an[B], Ot[B]), N = jn(W, E, C, F, fn[B], _t[B]), V = W | 0, K = Ut(e, r, 28) ^ ne(e, r, 34) ^ ne(e, r, 39), M = qt(e, r, 28) ^ re(e, r, 34) ^ re(e, r, 39), v = e & o ^ e & a ^ o & a, H = r & i ^ r & f ^ i & f;
584
- E = w | 0, T = b | 0, w = d | 0, b = h | 0, d = s | 0, h = u | 0, { h: s, l: u } = At(l | 0, g | 0, N | 0, V | 0), l = a | 0, g = f | 0, a = o | 0, f = i | 0, o = e | 0, i = r | 0;
585
- const U = Hn(V, M, H);
586
- e = Tn(U, N, K, v), r = U | 0;
577
+ let { Ah: r, Al: n, Bh: o, Bl: i, Ch: c, Cl: s, Dh: a, Dl: u, Eh: f, El: g, Fh: m, Fl: w, Gh: A, Gl: _, Hh: H, Hl: O } = this;
578
+ for (let x = 0; x < 80; x++) {
579
+ const q = bt(f, g, 14) ^ bt(f, g, 18) ^ _t(f, g, 41), Z = wt(f, g, 14) ^ wt(f, g, 18) ^ Ht(f, g, 41), T = f & m ^ ~f & A, Q = g & w ^ ~g & _, $ = Xe(O, Z, Q, _e[x], ft[x]), R = We($, H, q, T, Se[x], ct[x]), C = $ | 0, X = bt(r, n, 28) ^ _t(r, n, 34) ^ _t(r, n, 39), F = wt(r, n, 28) ^ Ht(r, n, 34) ^ Ht(r, n, 39), h = r & o ^ r & c ^ o & c, y = n & i ^ n & s ^ i & s;
580
+ H = A | 0, O = _ | 0, A = m | 0, _ = w | 0, m = f | 0, w = g | 0, { h: f, l: g } = it(a | 0, u | 0, R | 0, C | 0), a = c | 0, u = s | 0, c = o | 0, s = i | 0, o = r | 0, i = n | 0;
581
+ const B = ze(C, F, y);
582
+ r = Me(B, R, X, h), n = B | 0;
587
583
  }
588
- ({ h: e, l: r } = At(this.Ah | 0, this.Al | 0, e | 0, r | 0)), { h: o, l: i } = At(this.Bh | 0, this.Bl | 0, o | 0, i | 0), { h: a, l: f } = At(this.Ch | 0, this.Cl | 0, a | 0, f | 0), { h: l, l: g } = At(this.Dh | 0, this.Dl | 0, l | 0, g | 0), { h: s, l: u } = At(this.Eh | 0, this.El | 0, s | 0, u | 0), { h: d, l: h } = At(this.Fh | 0, this.Fl | 0, d | 0, h | 0), { h: w, l: b } = At(this.Gh | 0, this.Gl | 0, w | 0, b | 0), { h: E, l: T } = At(this.Hh | 0, this.Hl | 0, E | 0, T | 0), this.set(e, r, o, i, a, f, l, g, s, u, d, h, w, b, E, T);
584
+ ({ h: r, l: n } = it(this.Ah | 0, this.Al | 0, r | 0, n | 0)), { h: o, l: i } = it(this.Bh | 0, this.Bl | 0, o | 0, i | 0), { h: c, l: s } = it(this.Ch | 0, this.Cl | 0, c | 0, s | 0), { h: a, l: u } = it(this.Dh | 0, this.Dl | 0, a | 0, u | 0), { h: f, l: g } = it(this.Eh | 0, this.El | 0, f | 0, g | 0), { h: m, l: w } = it(this.Fh | 0, this.Fl | 0, m | 0, w | 0), { h: A, l: _ } = it(this.Gh | 0, this.Gl | 0, A | 0, _ | 0), { h: H, l: O } = it(this.Hh | 0, this.Hl | 0, H | 0, O | 0), this.set(r, n, o, i, c, s, a, u, f, g, m, w, A, _, H, O);
589
585
  }
590
586
  roundClean() {
591
- Kt(_t, Ot);
587
+ Bt(ct, ft);
592
588
  }
593
589
  destroy() {
594
- this.destroyed = !0, Kt(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
595
- }
596
- }, Ue = class extends te {
597
- Ah = ut[0] | 0;
598
- Al = ut[1] | 0;
599
- Bh = ut[2] | 0;
600
- Bl = ut[3] | 0;
601
- Ch = ut[4] | 0;
602
- Cl = ut[5] | 0;
603
- Dh = ut[6] | 0;
604
- Dl = ut[7] | 0;
605
- Eh = ut[8] | 0;
606
- El = ut[9] | 0;
607
- Fh = ut[10] | 0;
608
- Fl = ut[11] | 0;
609
- Gh = ut[12] | 0;
610
- Gl = ut[13] | 0;
611
- Hh = ut[14] | 0;
612
- Hl = ut[15] | 0;
590
+ this.destroyed = !0, Bt(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
591
+ }
592
+ }, ne = class extends Rt {
593
+ Ah = G[0] | 0;
594
+ Al = G[1] | 0;
595
+ Bh = G[2] | 0;
596
+ Bl = G[3] | 0;
597
+ Ch = G[4] | 0;
598
+ Cl = G[5] | 0;
599
+ Dh = G[6] | 0;
600
+ Dl = G[7] | 0;
601
+ Eh = G[8] | 0;
602
+ El = G[9] | 0;
603
+ Fh = G[10] | 0;
604
+ Fl = G[11] | 0;
605
+ Gh = G[12] | 0;
606
+ Gl = G[13] | 0;
607
+ Hh = G[14] | 0;
608
+ Hl = G[15] | 0;
613
609
  constructor() {
614
610
  super(64);
615
611
  }
616
- }, qe = class extends te {
617
- Ah = lt[0] | 0;
618
- Al = lt[1] | 0;
619
- Bh = lt[2] | 0;
620
- Bl = lt[3] | 0;
621
- Ch = lt[4] | 0;
622
- Cl = lt[5] | 0;
623
- Dh = lt[6] | 0;
624
- Dl = lt[7] | 0;
625
- Eh = lt[8] | 0;
626
- El = lt[9] | 0;
627
- Fh = lt[10] | 0;
628
- Fl = lt[11] | 0;
629
- Gh = lt[12] | 0;
630
- Gl = lt[13] | 0;
631
- Hh = lt[14] | 0;
632
- Hl = lt[15] | 0;
612
+ }, re = class extends Rt {
613
+ Ah = M[0] | 0;
614
+ Al = M[1] | 0;
615
+ Bh = M[2] | 0;
616
+ Bl = M[3] | 0;
617
+ Ch = M[4] | 0;
618
+ Cl = M[5] | 0;
619
+ Dh = M[6] | 0;
620
+ Dl = M[7] | 0;
621
+ Eh = M[8] | 0;
622
+ El = M[9] | 0;
623
+ Fh = M[10] | 0;
624
+ Fl = M[11] | 0;
625
+ Gh = M[12] | 0;
626
+ Gl = M[13] | 0;
627
+ Hh = M[14] | 0;
628
+ Hl = M[15] | 0;
633
629
  constructor() {
634
630
  super(48);
635
631
  }
636
- }, ft = /* @__PURE__ */ Uint32Array.from([
632
+ }, Y = /* @__PURE__ */ Uint32Array.from([
637
633
  2352822216,
638
634
  424955298,
639
635
  1944164710,
@@ -650,7 +646,7 @@ var ee, Ie, Ne, je, Ut, qt, ne, re, Hn, Tn, Fn, In, Nn, jn, Rr = Dt((() => {
650
646
  1780299464,
651
647
  286451373,
652
648
  2446758561
653
- ]), at = /* @__PURE__ */ Uint32Array.from([
649
+ ]), z = /* @__PURE__ */ Uint32Array.from([
654
650
  573645204,
655
651
  4230739756,
656
652
  2673172387,
@@ -667,111 +663,111 @@ var ee, Ie, Ne, je, Ut, qt, ne, re, Hn, Tn, Fn, In, Nn, jn, Rr = Dt((() => {
667
663
  746961066,
668
664
  246885852,
669
665
  2177182882
670
- ]), Ce = class extends te {
671
- Ah = ft[0] | 0;
672
- Al = ft[1] | 0;
673
- Bh = ft[2] | 0;
674
- Bl = ft[3] | 0;
675
- Ch = ft[4] | 0;
676
- Cl = ft[5] | 0;
677
- Dh = ft[6] | 0;
678
- Dl = ft[7] | 0;
679
- Eh = ft[8] | 0;
680
- El = ft[9] | 0;
681
- Fh = ft[10] | 0;
682
- Fl = ft[11] | 0;
683
- Gh = ft[12] | 0;
684
- Gl = ft[13] | 0;
685
- Hh = ft[14] | 0;
686
- Hl = ft[15] | 0;
666
+ ]), oe = class extends Rt {
667
+ Ah = Y[0] | 0;
668
+ Al = Y[1] | 0;
669
+ Bh = Y[2] | 0;
670
+ Bl = Y[3] | 0;
671
+ Ch = Y[4] | 0;
672
+ Cl = Y[5] | 0;
673
+ Dh = Y[6] | 0;
674
+ Dl = Y[7] | 0;
675
+ Eh = Y[8] | 0;
676
+ El = Y[9] | 0;
677
+ Fh = Y[10] | 0;
678
+ Fl = Y[11] | 0;
679
+ Gh = Y[12] | 0;
680
+ Gl = Y[13] | 0;
681
+ Hh = Y[14] | 0;
682
+ Hl = Y[15] | 0;
687
683
  constructor() {
688
684
  super(28);
689
685
  }
690
- }, ke = class extends te {
691
- Ah = at[0] | 0;
692
- Al = at[1] | 0;
693
- Bh = at[2] | 0;
694
- Bl = at[3] | 0;
695
- Ch = at[4] | 0;
696
- Cl = at[5] | 0;
697
- Dh = at[6] | 0;
698
- Dl = at[7] | 0;
699
- Eh = at[8] | 0;
700
- El = at[9] | 0;
701
- Fh = at[10] | 0;
702
- Fl = at[11] | 0;
703
- Gh = at[12] | 0;
704
- Gl = at[13] | 0;
705
- Hh = at[14] | 0;
706
- Hl = at[15] | 0;
686
+ }, ie = class extends Rt {
687
+ Ah = z[0] | 0;
688
+ Al = z[1] | 0;
689
+ Bh = z[2] | 0;
690
+ Bl = z[3] | 0;
691
+ Ch = z[4] | 0;
692
+ Cl = z[5] | 0;
693
+ Dh = z[6] | 0;
694
+ Dl = z[7] | 0;
695
+ Eh = z[8] | 0;
696
+ El = z[9] | 0;
697
+ Fh = z[10] | 0;
698
+ Fl = z[11] | 0;
699
+ Gh = z[12] | 0;
700
+ Gl = z[13] | 0;
701
+ Hh = z[14] | 0;
702
+ Hl = z[15] | 0;
707
703
  constructor() {
708
704
  super(32);
709
705
  }
710
- }, jt = /* @__PURE__ */ Yt(() => new De(), /* @__PURE__ */ Lt(1)), Dn = /* @__PURE__ */ Yt(() => new Le(), /* @__PURE__ */ Lt(4)), Ln = /* @__PURE__ */ Yt(() => new Ue(), /* @__PURE__ */ Lt(3)), Un = /* @__PURE__ */ Yt(() => new qe(), /* @__PURE__ */ Lt(2)), qn = /* @__PURE__ */ Yt(() => new ke(), /* @__PURE__ */ Lt(6)), Cn = /* @__PURE__ */ Yt(() => new Ce(), /* @__PURE__ */ Lt(5));
706
+ }, ge = /* @__PURE__ */ xt(() => new te(), /* @__PURE__ */ gt(1)), Qe = /* @__PURE__ */ xt(() => new ee(), /* @__PURE__ */ gt(4)), Je = /* @__PURE__ */ xt(() => new ne(), /* @__PURE__ */ gt(3)), Pe = /* @__PURE__ */ xt(() => new re(), /* @__PURE__ */ gt(2)), tn = /* @__PURE__ */ xt(() => new ie(), /* @__PURE__ */ gt(6)), en = /* @__PURE__ */ xt(() => new oe(), /* @__PURE__ */ gt(5));
711
707
  }));
712
- function Or(t) {
708
+ function Cn(t) {
713
709
  return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
714
710
  }
715
- function Io(t, n = "") {
711
+ function Ar(t, e = "") {
716
712
  if (!Number.isSafeInteger(t) || t < 0) {
717
- const e = n && `"${n}" `;
718
- throw new Error(`${e}expected integer >= 0, got ${t}`);
713
+ const r = e && `"${e}" `;
714
+ throw new Error(`${r}expected integer >= 0, got ${t}`);
719
715
  }
720
716
  }
721
- function kn(t, n, e = "") {
722
- const r = Or(t), o = t?.length, i = n !== void 0;
723
- if (!r || i && o !== n) {
724
- const a = e && `"${e}" `, f = i ? ` of length ${n}` : "", l = r ? `length=${o}` : `type=${typeof t}`;
725
- throw new Error(a + "expected Uint8Array" + f + ", got " + l);
717
+ function nn(t, e, r = "") {
718
+ const n = Cn(t), o = t?.length, i = e !== void 0;
719
+ if (!n || i && o !== e) {
720
+ const c = r && `"${r}" `, s = i ? ` of length ${e}` : "", a = n ? `length=${o}` : `type=${typeof t}`;
721
+ throw new Error(c + "expected Uint8Array" + s + ", got " + a);
726
722
  }
727
723
  return t;
728
724
  }
729
- function No(t, n = !0) {
725
+ function Rr(t, e = !0) {
730
726
  if (t.destroyed) throw new Error("Hash instance has been destroyed");
731
- if (n && t.finished) throw new Error("Hash#digest() has already been called");
727
+ if (e && t.finished) throw new Error("Hash#digest() has already been called");
732
728
  }
733
- function jo(t, n) {
734
- kn(t, void 0, "digestInto() output");
735
- const e = n.outputLen;
736
- if (t.length < e) throw new Error('"digestInto() output" expected to be of length >=' + e);
729
+ function Sr(t, e) {
730
+ nn(t, void 0, "digestInto() output");
731
+ const r = e.outputLen;
732
+ if (t.length < r) throw new Error('"digestInto() output" expected to be of length >=' + r);
737
733
  }
738
- function Do(t) {
734
+ function _r(t) {
739
735
  return new Uint32Array(t.buffer, t.byteOffset, Math.floor(t.byteLength / 4));
740
736
  }
741
- function Lo(...t) {
742
- for (let n = 0; n < t.length; n++) t[n].fill(0);
737
+ function Hr(...t) {
738
+ for (let e = 0; e < t.length; e++) t[e].fill(0);
743
739
  }
744
- function Hr(t) {
740
+ function kn(t) {
745
741
  return t << 24 & 4278190080 | t << 8 & 16711680 | t >>> 8 & 65280 | t >>> 24 & 255;
746
742
  }
747
- function Tr(t) {
748
- for (let n = 0; n < t.length; n++) t[n] = Hr(t[n]);
743
+ function jn(t) {
744
+ for (let e = 0; e < t.length; e++) t[e] = kn(t[e]);
749
745
  return t;
750
746
  }
751
- function Uo(...t) {
752
- let n = 0;
753
- for (let r = 0; r < t.length; r++) {
754
- const o = t[r];
755
- kn(o), n += o.length;
747
+ function Or(...t) {
748
+ let e = 0;
749
+ for (let n = 0; n < t.length; n++) {
750
+ const o = t[n];
751
+ nn(o), e += o.length;
756
752
  }
757
- const e = new Uint8Array(n);
758
- for (let r = 0, o = 0; r < t.length; r++) {
759
- const i = t[r];
760
- e.set(i, o), o += i.length;
753
+ const r = new Uint8Array(e);
754
+ for (let n = 0, o = 0; n < t.length; n++) {
755
+ const i = t[n];
756
+ r.set(i, o), o += i.length;
761
757
  }
762
- return e;
758
+ return r;
763
759
  }
764
- function qo(t, n = {}) {
765
- const e = (o, i) => t(i).update(o).digest(), r = t(void 0);
766
- return e.outputLen = r.outputLen, e.blockLen = r.blockLen, e.create = (o) => t(o), Object.assign(e, n), Object.freeze(e);
760
+ function Ir(t, e = {}) {
761
+ const r = (o, i) => t(i).update(o).digest(), n = t(void 0);
762
+ return r.outputLen = n.outputLen, r.blockLen = n.blockLen, r.create = (o) => t(o), Object.assign(r, e), Object.freeze(r);
767
763
  }
768
- function Co(t = 32) {
769
- const n = typeof globalThis == "object" ? globalThis.crypto : null;
770
- if (typeof n?.getRandomValues != "function") throw new Error("crypto.getRandomValues must be defined");
771
- return n.getRandomValues(new Uint8Array(t));
764
+ function Fr(t = 32) {
765
+ const e = typeof globalThis == "object" ? globalThis.crypto : null;
766
+ if (typeof e?.getRandomValues != "function") throw new Error("crypto.getRandomValues must be defined");
767
+ return e.getRandomValues(new Uint8Array(t));
772
768
  }
773
- var ln, Fr, Ir, Nr, jr = Dt((() => {
774
- ln = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68, Fr = ln ? (t) => t : Tr, Ir = typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", Nr = (t) => ({ oid: Uint8Array.from([
769
+ var He, Vn, Yn, zn = dt((() => {
770
+ He = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68, Vn = He ? (t) => t : jn, Yn = (t) => ({ oid: Uint8Array.from([
775
771
  6,
776
772
  9,
777
773
  96,
@@ -785,258 +781,250 @@ var ln, Fr, Ir, Nr, jr = Dt((() => {
785
781
  t
786
782
  ]) });
787
783
  }));
788
- function ko(t, n = "") {
784
+ function Lr(t, e = "") {
789
785
  if (typeof t != "boolean") {
790
- const e = n && `"${n}" `;
791
- throw new Error(e + "expected boolean, got type=" + typeof t);
786
+ const r = e && `"${e}" `;
787
+ throw new Error(r + "expected boolean, got type=" + typeof t);
792
788
  }
793
789
  return t;
794
790
  }
795
- var $o = Dt((() => {
796
- jr();
791
+ var Nr = dt((() => {
792
+ zn();
797
793
  }));
798
- function Qe(t) {
794
+ function be(t) {
799
795
  if (!Number.isSafeInteger(t) || t < 0 || t > 4294967295) throw new Error("wrong u32 integer:" + t);
800
796
  return t;
801
797
  }
802
- function $n(t) {
803
- return Qe(t), (t & t - 1) === 0 && t !== 0;
798
+ function rn(t) {
799
+ return be(t), (t & t - 1) === 0 && t !== 0;
804
800
  }
805
- function Dr(t, n) {
806
- Qe(t);
807
- let e = 0;
808
- for (let r = 0; r < n; r++, t >>>= 1) e = e << 1 | t & 1;
809
- return e;
801
+ function Mn(t, e) {
802
+ be(t);
803
+ let r = 0;
804
+ for (let n = 0; n < e; n++, t >>>= 1) r = r << 1 | t & 1;
805
+ return r;
810
806
  }
811
- function Zn(t) {
812
- return Qe(t), 31 - Math.clz32(t);
807
+ function on(t) {
808
+ return be(t), 31 - Math.clz32(t);
813
809
  }
814
- function un(t) {
815
- const n = t.length;
816
- if (n < 2 || !$n(n)) throw new Error("n must be a power of 2 and greater than 1. Got " + n);
817
- const e = Zn(n);
818
- for (let r = 0; r < n; r++) {
819
- const o = Dr(r, e);
820
- if (r < o) {
821
- const i = t[r];
822
- t[r] = t[o], t[o] = i;
810
+ function Oe(t) {
811
+ const e = t.length;
812
+ if (e < 2 || !rn(e)) throw new Error("n must be a power of 2 and greater than 1. Got " + e);
813
+ const r = on(e);
814
+ for (let n = 0; n < e; n++) {
815
+ const o = Mn(n, r);
816
+ if (n < o) {
817
+ const i = t[n];
818
+ t[n] = t[o], t[o] = i;
823
819
  }
824
820
  }
825
821
  return t;
826
822
  }
827
- var Lr, Zo = Dt((() => {
828
- Lr = (t, n) => {
829
- const { N: e, roots: r, dit: o, invertButterflies: i = !1, skipStages: a = 0, brp: f = !0 } = n, l = Zn(e);
830
- if (!$n(e)) throw new Error("FFT: Polynomial size should be power of two");
831
- const g = o !== i;
832
- return (s) => {
833
- if (s.length !== e) throw new Error("FFT: wrong Polynomial length");
834
- o && f && un(s);
835
- for (let u = 0, d = 1; u < l - a; u++) {
836
- const h = o ? u + 1 + a : l - u, w = 1 << h, b = w >> 1, E = e >> h;
837
- for (let T = 0; T < e; T += w) for (let B = 0, C = d++; B < b; B++) {
838
- const O = i ? o ? e - C : C : B * E, F = T + B, z = T + B + b, W = r[O], N = s[z], V = s[F];
839
- if (g) {
840
- const K = t.mul(N, W);
841
- s[F] = t.add(V, K), s[z] = t.sub(V, K);
842
- } else i ? (s[F] = t.add(N, V), s[z] = t.mul(t.sub(N, V), W)) : (s[F] = t.add(V, N), s[z] = t.mul(t.sub(V, N), W));
823
+ var Gn, Tr = dt((() => {
824
+ Gn = (t, e) => {
825
+ const { N: r, roots: n, dit: o, invertButterflies: i = !1, skipStages: c = 0, brp: s = !0 } = e, a = on(r);
826
+ if (!rn(r)) throw new Error("FFT: Polynomial size should be power of two");
827
+ const u = o !== i;
828
+ return (f) => {
829
+ if (f.length !== r) throw new Error("FFT: wrong Polynomial length");
830
+ o && s && Oe(f);
831
+ for (let g = 0, m = 1; g < a - c; g++) {
832
+ const w = o ? g + 1 + c : a - g, A = 1 << w, _ = A >> 1, H = r >> w;
833
+ for (let O = 0; O < r; O += A) for (let x = 0, q = m++; x < _; x++) {
834
+ const Z = i ? o ? r - q : q : x * H, T = O + x, Q = O + x + _, $ = n[Z], R = f[Q], C = f[T];
835
+ if (u) {
836
+ const X = t.mul(R, $);
837
+ f[T] = t.add(C, X), f[Q] = t.sub(C, X);
838
+ } else i ? (f[T] = t.add(R, C), f[Q] = t.mul(t.sub(R, C), $)) : (f[T] = t.add(C, R), f[Q] = t.mul(t.sub(C, R), $));
843
839
  }
844
840
  }
845
- return !o && f && un(s), s;
841
+ return !o && s && Oe(f), f;
846
842
  };
847
843
  };
848
844
  }));
849
- _r();
850
- Qt();
851
- var st = (t, n, e) => zt(t, n, e), Vn = Pt, Ct = Ke, Q = (...t) => br(...t), he = (t) => _n(t), oe = Sn, wt = (t) => yr(t), me = /* @__PURE__ */ BigInt(0), $e = /* @__PURE__ */ BigInt(1);
852
- function ie(t, n = "") {
845
+ Zn();
846
+ It();
847
+ var W = (t, e, r) => mt(t, e, r), sn = Et, cn = le, lt = (...t) => In(...t), se = (t) => Ve(t), fn = Ce, an = (t) => Fn(t), qt = /* @__PURE__ */ BigInt(0), ce = /* @__PURE__ */ BigInt(1);
848
+ function Ot(t, e = "") {
853
849
  if (typeof t != "boolean") {
854
- const e = n && `"${n}" `;
855
- throw new TypeError(e + "expected boolean, got type=" + typeof t);
850
+ const r = e && `"${e}" `;
851
+ throw new TypeError(r + "expected boolean, got type=" + typeof t);
856
852
  }
857
853
  return t;
858
854
  }
859
- function Je(t) {
855
+ function we(t) {
860
856
  if (typeof t == "bigint") {
861
- if (!ue(t)) throw new RangeError("positive bigint expected, got " + t);
862
- } else Vn(t);
857
+ if (!$t(t)) throw new RangeError("positive bigint expected, got " + t);
858
+ } else sn(t);
863
859
  return t;
864
860
  }
865
- function Ft(t, n = "") {
861
+ function fe(t, e = "") {
866
862
  if (typeof t != "number") {
867
- const e = n && `"${n}" `;
868
- throw new TypeError(e + "expected number, got type=" + typeof t);
863
+ const r = e && `"${e}" `;
864
+ throw new TypeError(r + "expected number, got type=" + typeof t);
869
865
  }
870
866
  if (!Number.isSafeInteger(t)) {
871
- const e = n && `"${n}" `;
872
- throw new RangeError(e + "expected safe integer, got " + t);
867
+ const r = e && `"${e}" `;
868
+ throw new RangeError(r + "expected safe integer, got " + t);
873
869
  }
874
870
  }
875
- function ce(t) {
876
- const n = Je(t).toString(16);
877
- return n.length & 1 ? "0" + n : n;
871
+ function Nt(t) {
872
+ const e = we(t).toString(16);
873
+ return e.length & 1 ? "0" + e : e;
878
874
  }
879
- function Pn(t) {
875
+ function un(t) {
880
876
  if (typeof t != "string") throw new TypeError("hex string expected, got " + typeof t);
881
- return t === "" ? me : BigInt("0x" + t);
882
- }
883
- function St(t) {
884
- return Pn(Ke(t));
877
+ return t === "" ? qt : BigInt("0x" + t);
885
878
  }
886
- function ge(t) {
887
- return Pn(Ke(Ze(zt(t)).reverse()));
879
+ function Ct(t) {
880
+ return un(le(t));
888
881
  }
889
- function tn(t, n) {
890
- if (Pt(n), n === 0) throw new RangeError("zero length");
891
- t = Je(t);
892
- const e = t.toString(16);
893
- if (e.length > n * 2) throw new RangeError("number too large");
894
- return _n(e.padStart(n * 2, "0"));
882
+ function ln(t) {
883
+ return un(le(Kn(mt(t)).reverse()));
895
884
  }
896
- function zn(t, n) {
897
- return tn(t, n).reverse();
885
+ function pe(t, e) {
886
+ if (Et(e), e === 0) throw new RangeError("zero length");
887
+ t = we(t);
888
+ const r = t.toString(16);
889
+ if (r.length > e * 2) throw new RangeError("number too large");
890
+ return Ve(r.padStart(e * 2, "0"));
898
891
  }
899
- function Ze(t) {
900
- return Uint8Array.from(st(t));
892
+ function hn(t, e) {
893
+ return pe(t, e).reverse();
901
894
  }
902
- function be(t) {
903
- if (typeof t != "string") throw new TypeError("ascii string expected, got " + typeof t);
904
- return Uint8Array.from(t, (n, e) => {
905
- const r = n.charCodeAt(0);
906
- if (n.length !== 1 || r > 127) throw new RangeError(`string contains non-ASCII character "${t[e]}" with code ${r} at position ${e}`);
907
- return r;
908
- });
895
+ function Kn(t) {
896
+ return Uint8Array.from(W(t));
909
897
  }
910
- var ue = (t) => typeof t == "bigint" && me <= t;
911
- function Ur(t, n, e) {
912
- return ue(t) && ue(n) && ue(e) && n <= t && t < e;
898
+ var $t = (t) => typeof t == "bigint" && qt <= t;
899
+ function Xn(t, e, r) {
900
+ return $t(t) && $t(e) && $t(r) && e <= t && t < r;
913
901
  }
914
- function Mn(t, n, e, r) {
915
- if (!Ur(n, e, r)) throw new RangeError("expected valid " + t + ": " + e + " <= n < " + r + ", got " + n);
902
+ function dn(t, e, r, n) {
903
+ if (!Xn(e, r, n)) throw new RangeError("expected valid " + t + ": " + r + " <= n < " + n + ", got " + e);
916
904
  }
917
905
  function ye(t) {
918
- if (t < me) throw new Error("expected non-negative bigint, got " + t);
919
- let n;
920
- for (n = 0; t > me; t >>= $e, n += 1) ;
921
- return n;
906
+ if (t < qt) throw new Error("expected non-negative bigint, got " + t);
907
+ let e;
908
+ for (e = 0; t > qt; t >>= ce, e += 1) ;
909
+ return e;
922
910
  }
923
- var pe = (t) => ($e << BigInt(t)) - $e;
924
- function qr(t, n, e) {
925
- if (Pt(t, "hashLen"), Pt(n, "qByteLen"), typeof e != "function") throw new TypeError("hmacFn must be a function");
926
- const r = (E) => new Uint8Array(E), o = Uint8Array.of(), i = Uint8Array.of(0), a = Uint8Array.of(1), f = 1e3;
927
- let l = r(t), g = r(t), s = 0;
928
- const u = () => {
929
- l.fill(1), g.fill(0), s = 0;
930
- }, d = (...E) => e(g, Q(l, ...E)), h = (E = o) => {
931
- g = d(i, E), l = d(), E.length !== 0 && (g = d(a, E), l = d());
932
- }, w = () => {
933
- if (s++ >= f) throw new Error("drbg: tried max amount of iterations");
934
- let E = 0;
935
- const T = [];
936
- for (; E < n; ) {
937
- l = d();
938
- const B = l.slice();
939
- T.push(B), E += l.length;
940
- }
941
- return Q(...T);
911
+ var Ee = (t) => (ce << BigInt(t)) - ce;
912
+ function Wn(t, e, r) {
913
+ if (Et(t, "hashLen"), Et(e, "qByteLen"), typeof r != "function") throw new TypeError("hmacFn must be a function");
914
+ const n = (H) => new Uint8Array(H), o = Uint8Array.of(), i = Uint8Array.of(0), c = Uint8Array.of(1), s = 1e3;
915
+ let a = n(t), u = n(t), f = 0;
916
+ const g = () => {
917
+ a.fill(1), u.fill(0), f = 0;
918
+ }, m = (...H) => r(u, lt(a, ...H)), w = (H = o) => {
919
+ u = m(i, H), a = m(), H.length !== 0 && (u = m(c, H), a = m());
920
+ }, A = () => {
921
+ if (f++ >= s) throw new Error("drbg: tried max amount of iterations");
922
+ let H = 0;
923
+ const O = [];
924
+ for (; H < e; ) {
925
+ a = m();
926
+ const x = a.slice();
927
+ O.push(x), H += a.length;
928
+ }
929
+ return lt(...O);
942
930
  };
943
- return (E, T) => {
944
- u(), h(E);
945
- let B;
946
- for (; (B = T(w())) === void 0; ) h();
947
- return u(), B;
931
+ return (H, O) => {
932
+ g(), w(H);
933
+ let x;
934
+ for (; (x = O(A())) === void 0; ) w();
935
+ return g(), x;
948
936
  };
949
937
  }
950
- function Mt(t, n = {}, e = {}) {
938
+ function kt(t, e = {}, r = {}) {
951
939
  if (Object.prototype.toString.call(t) !== "[object Object]") throw new TypeError("expected valid options object");
952
- function r(i, a, f) {
953
- if (!f && a !== "function" && !Object.hasOwn(t, i)) throw new TypeError(`param "${i}" is invalid: expected own property`);
954
- const l = t[i];
955
- if (f && l === void 0) return;
956
- const g = typeof l;
957
- if (g !== a || l === null) throw new TypeError(`param "${i}" is invalid: expected ${a}, got ${g}`);
958
- }
959
- const o = (i, a) => Object.entries(i).forEach(([f, l]) => r(f, l, a));
960
- o(n, !1), o(e, !0);
961
- }
962
- var dt = /* @__PURE__ */ BigInt(0), ot = /* @__PURE__ */ BigInt(1), $t = /* @__PURE__ */ BigInt(2), Gn = /* @__PURE__ */ BigInt(3), Yn = /* @__PURE__ */ BigInt(4), Kn = /* @__PURE__ */ BigInt(5), Cr = /* @__PURE__ */ BigInt(7), Xn = /* @__PURE__ */ BigInt(8), kr = /* @__PURE__ */ BigInt(9), Wn = /* @__PURE__ */ BigInt(16);
963
- function bt(t, n) {
964
- if (n <= dt) throw new Error("mod: expected positive modulus, got " + n);
965
- const e = t % n;
966
- return e >= dt ? e : n + e;
967
- }
968
- function gt(t, n, e) {
969
- if (n < dt) throw new Error("pow2: expected non-negative exponent, got " + n);
970
- let r = t;
971
- for (; n-- > dt; )
972
- r *= r, r %= e;
973
- return r;
940
+ function n(i, c, s) {
941
+ if (!s && c !== "function" && !Object.hasOwn(t, i)) throw new TypeError(`param "${i}" is invalid: expected own property`);
942
+ const a = t[i];
943
+ if (s && a === void 0) return;
944
+ const u = typeof a;
945
+ if (u !== c || a === null) throw new TypeError(`param "${i}" is invalid: expected ${c}, got ${u}`);
946
+ }
947
+ const o = (i, c) => Object.entries(i).forEach(([s, a]) => n(s, a, c));
948
+ o(e, !1), o(r, !0);
949
+ }
950
+ var K = /* @__PURE__ */ BigInt(0), D = /* @__PURE__ */ BigInt(1), pt = /* @__PURE__ */ BigInt(2), gn = /* @__PURE__ */ BigInt(3), bn = /* @__PURE__ */ BigInt(4), wn = /* @__PURE__ */ BigInt(5), Qn = /* @__PURE__ */ BigInt(7), pn = /* @__PURE__ */ BigInt(8), Jn = /* @__PURE__ */ BigInt(9), yn = /* @__PURE__ */ BigInt(16);
951
+ function tt(t, e) {
952
+ if (e <= K) throw new Error("mod: expected positive modulus, got " + e);
953
+ const r = t % e;
954
+ return r >= K ? r : e + r;
955
+ }
956
+ function P(t, e, r) {
957
+ if (e < K) throw new Error("pow2: expected non-negative exponent, got " + e);
958
+ let n = t;
959
+ for (; e-- > K; )
960
+ n *= n, n %= r;
961
+ return n;
974
962
  }
975
- function dn(t, n) {
976
- if (t === dt) throw new Error("invert: expected non-zero number");
977
- if (n <= dt) throw new Error("invert: expected positive modulus, got " + n);
978
- let e = bt(t, n), r = n, o = dt, i = ot, a = ot, f = dt;
979
- for (; e !== dt; ) {
980
- const l = r / e, g = r - e * l, s = o - a * l, u = i - f * l;
981
- r = e, e = g, o = a, i = f, a = s, f = u;
982
- }
983
- if (r !== ot) throw new Error("invert: does not exist");
984
- return bt(o, n);
985
- }
986
- function en(t, n, e) {
987
- const r = t;
988
- if (!r.eql(r.sqr(n), e)) throw new Error("Cannot find square root");
989
- }
990
- function Qn(t, n) {
991
- const e = t, r = (e.ORDER + ot) / Yn, o = e.pow(n, r);
992
- return en(e, o, n), o;
993
- }
994
- function $r(t, n) {
995
- const e = t, r = (e.ORDER - Kn) / Xn, o = e.mul(n, $t), i = e.pow(o, r), a = e.mul(n, i), f = e.mul(e.mul(a, $t), i), l = e.mul(a, e.sub(f, e.ONE));
996
- return en(e, l, n), l;
997
- }
998
- function Zr(t) {
999
- const n = ve(t), e = Jn(t), r = e(n, n.neg(n.ONE)), o = e(n, r), i = e(n, n.neg(r)), a = (t + Cr) / Wn;
1000
- return ((f, l) => {
1001
- const g = f;
1002
- let s = g.pow(l, a), u = g.mul(s, r);
1003
- const d = g.mul(s, o), h = g.mul(s, i), w = g.eql(g.sqr(u), l), b = g.eql(g.sqr(d), l);
1004
- s = g.cmov(s, u, w), u = g.cmov(h, d, b);
1005
- const E = g.eql(g.sqr(u), l), T = g.cmov(s, u, E);
1006
- return en(g, T, l), T;
963
+ function Ie(t, e) {
964
+ if (t === K) throw new Error("invert: expected non-zero number");
965
+ if (e <= K) throw new Error("invert: expected positive modulus, got " + e);
966
+ let r = tt(t, e), n = e, o = K, i = D, c = D, s = K;
967
+ for (; r !== K; ) {
968
+ const a = n / r, u = n - r * a, f = o - c * a, g = i - s * a;
969
+ n = r, r = u, o = c, i = s, c = f, s = g;
970
+ }
971
+ if (n !== D) throw new Error("invert: does not exist");
972
+ return tt(o, e);
973
+ }
974
+ function me(t, e, r) {
975
+ const n = t;
976
+ if (!n.eql(n.sqr(e), r)) throw new Error("Cannot find square root");
977
+ }
978
+ function En(t, e) {
979
+ const r = t, n = (r.ORDER + D) / bn, o = r.pow(e, n);
980
+ return me(r, o, e), o;
981
+ }
982
+ function Pn(t, e) {
983
+ const r = t, n = (r.ORDER - wn) / pn, o = r.mul(e, pt), i = r.pow(o, n), c = r.mul(e, i), s = r.mul(r.mul(c, pt), i), a = r.mul(c, r.sub(s, r.ONE));
984
+ return me(r, a, e), a;
985
+ }
986
+ function tr(t) {
987
+ const e = jt(t), r = mn(t), n = r(e, e.neg(e.ONE)), o = r(e, n), i = r(e, e.neg(n)), c = (t + Qn) / yn;
988
+ return ((s, a) => {
989
+ const u = s;
990
+ let f = u.pow(a, c), g = u.mul(f, n);
991
+ const m = u.mul(f, o), w = u.mul(f, i), A = u.eql(u.sqr(g), a), _ = u.eql(u.sqr(m), a);
992
+ f = u.cmov(f, g, A), g = u.cmov(w, m, _);
993
+ const H = u.eql(u.sqr(g), a), O = u.cmov(f, g, H);
994
+ return me(u, O, a), O;
1007
995
  });
1008
996
  }
1009
- function Jn(t) {
1010
- if (t < Gn) throw new Error("sqrt is not defined for small field");
1011
- let n = t - ot, e = 0;
1012
- for (; n % $t === dt; )
1013
- n /= $t, e++;
1014
- let r = $t;
1015
- const o = ve(t);
1016
- for (; Ve(o, r) === 1; ) if (r++ > 1e3) throw new Error("Cannot find square root: probably non-prime P");
1017
- if (e === 1) return Qn;
1018
- let i = o.pow(r, n);
1019
- const a = (n + ot) / $t;
1020
- return function(l, g) {
1021
- const s = l;
1022
- if (s.is0(g)) return g;
1023
- if (Ve(s, g) !== 1) throw new Error("Cannot find square root");
1024
- let u = e, d = s.mul(s.ONE, i), h = s.pow(g, n), w = s.pow(g, a);
1025
- for (; !s.eql(h, s.ONE); ) {
1026
- if (s.is0(h)) return s.ZERO;
1027
- let b = 1, E = s.sqr(h);
1028
- for (; !s.eql(E, s.ONE); )
1029
- if (b++, E = s.sqr(E), b === u) throw new Error("Cannot find square root");
1030
- const T = ot << BigInt(u - b - 1), B = s.pow(d, T);
1031
- u = b, d = s.sqr(B), h = s.mul(h, d), w = s.mul(w, B);
1032
- }
1033
- return w;
997
+ function mn(t) {
998
+ if (t < gn) throw new Error("sqrt is not defined for small field");
999
+ let e = t - D, r = 0;
1000
+ for (; e % pt === K; )
1001
+ e /= pt, r++;
1002
+ let n = pt;
1003
+ const o = jt(t);
1004
+ for (; Fe(o, n) === 1; ) if (n++ > 1e3) throw new Error("Cannot find square root: probably non-prime P");
1005
+ if (r === 1) return En;
1006
+ let i = o.pow(n, e);
1007
+ const c = (e + D) / pt;
1008
+ return function(a, u) {
1009
+ const f = a;
1010
+ if (f.is0(u)) return u;
1011
+ if (Fe(f, u) !== 1) throw new Error("Cannot find square root");
1012
+ let g = r, m = f.mul(f.ONE, i), w = f.pow(u, e), A = f.pow(u, c);
1013
+ for (; !f.eql(w, f.ONE); ) {
1014
+ if (f.is0(w)) return f.ZERO;
1015
+ let _ = 1, H = f.sqr(w);
1016
+ for (; !f.eql(H, f.ONE); )
1017
+ if (_++, H = f.sqr(H), _ === g) throw new Error("Cannot find square root");
1018
+ const O = D << BigInt(g - _ - 1), x = f.pow(m, O);
1019
+ g = _, m = f.sqr(x), w = f.mul(w, m), A = f.mul(A, x);
1020
+ }
1021
+ return A;
1034
1022
  };
1035
1023
  }
1036
- function Vr(t) {
1037
- return t % Yn === Gn ? Qn : t % Xn === Kn ? $r : t % Wn === kr ? Zr(t) : Jn(t);
1024
+ function er(t) {
1025
+ return t % bn === gn ? En : t % pn === wn ? Pn : t % yn === Jn ? tr(t) : mn(t);
1038
1026
  }
1039
- var Pr = [
1027
+ var nr = [
1040
1028
  "create",
1041
1029
  "isValid",
1042
1030
  "is0",
@@ -1055,1088 +1043,347 @@ var Pr = [
1055
1043
  "mulN",
1056
1044
  "sqrN"
1057
1045
  ];
1058
- function se(t) {
1059
- if (Mt(t, Pr.reduce((n, e) => (n[e] = "function", n), {
1046
+ function rr(t) {
1047
+ if (kt(t, nr.reduce((e, r) => (e[r] = "function", e), {
1060
1048
  ORDER: "bigint",
1061
1049
  BYTES: "number",
1062
1050
  BITS: "number"
1063
- })), Ft(t.BYTES, "BYTES"), Ft(t.BITS, "BITS"), t.BYTES < 1 || t.BITS < 1) throw new Error("invalid field: expected BYTES/BITS > 0");
1064
- if (t.ORDER <= ot) throw new Error("invalid field: expected ORDER > 1, got " + t.ORDER);
1051
+ })), fe(t.BYTES, "BYTES"), fe(t.BITS, "BITS"), t.BYTES < 1 || t.BITS < 1) throw new Error("invalid field: expected BYTES/BITS > 0");
1052
+ if (t.ORDER <= D) throw new Error("invalid field: expected ORDER > 1, got " + t.ORDER);
1065
1053
  return t;
1066
1054
  }
1067
- function zr(t, n, e) {
1068
- const r = t;
1069
- if (e < dt) throw new Error("invalid exponent, negatives unsupported");
1070
- if (e === dt) return r.ONE;
1071
- if (e === ot) return n;
1072
- let o = r.ONE, i = n;
1073
- for (; e > dt; )
1074
- e & ot && (o = r.mul(o, i)), i = r.sqr(i), e >>= ot;
1055
+ function or(t, e, r) {
1056
+ const n = t;
1057
+ if (r < K) throw new Error("invalid exponent, negatives unsupported");
1058
+ if (r === K) return n.ONE;
1059
+ if (r === D) return e;
1060
+ let o = n.ONE, i = e;
1061
+ for (; r > K; )
1062
+ r & D && (o = n.mul(o, i)), i = n.sqr(i), r >>= D;
1075
1063
  return o;
1076
1064
  }
1077
- function Ee(t, n, e = !1) {
1078
- const r = t, o = new Array(n.length).fill(e ? r.ZERO : void 0), i = n.reduce((f, l, g) => r.is0(l) ? f : (o[g] = f, r.mul(f, l)), r.ONE), a = r.inv(i);
1079
- return n.reduceRight((f, l, g) => r.is0(l) ? f : (o[g] = r.mul(f, o[g]), r.mul(f, l)), a), o;
1080
- }
1081
- function Ve(t, n) {
1082
- const e = t, r = (e.ORDER - ot) / $t, o = e.pow(n, r), i = e.eql(o, e.ONE), a = e.eql(o, e.ZERO), f = e.eql(o, e.neg(e.ONE));
1083
- if (!i && !a && !f) throw new Error("invalid Legendre symbol result");
1084
- return i ? 1 : a ? 0 : -1;
1085
- }
1086
- function hn(t, n) {
1087
- return Ve(t, n) !== -1;
1088
- }
1089
- function Mr(t, n) {
1090
- if (n !== void 0 && Vn(n), t <= dt) throw new Error("invalid n length: expected positive n, got " + t);
1091
- if (n !== void 0 && n < 1) throw new Error("invalid n length: expected positive bit length, got " + n);
1092
- const e = ye(t);
1093
- if (n !== void 0 && n < e) throw new Error(`invalid n length: expected bit length (${e}) >= n.length (${n})`);
1094
- const r = n !== void 0 ? n : e;
1065
+ function vn(t, e, r = !1) {
1066
+ const n = t, o = new Array(e.length).fill(r ? n.ZERO : void 0), i = e.reduce((s, a, u) => n.is0(a) ? s : (o[u] = s, n.mul(s, a)), n.ONE), c = n.inv(i);
1067
+ return e.reduceRight((s, a, u) => n.is0(a) ? s : (o[u] = n.mul(s, o[u]), n.mul(s, a)), c), o;
1068
+ }
1069
+ function Fe(t, e) {
1070
+ const r = t, n = (r.ORDER - D) / pt, o = r.pow(e, n), i = r.eql(o, r.ONE), c = r.eql(o, r.ZERO), s = r.eql(o, r.neg(r.ONE));
1071
+ if (!i && !c && !s) throw new Error("invalid Legendre symbol result");
1072
+ return i ? 1 : c ? 0 : -1;
1073
+ }
1074
+ function ir(t, e) {
1075
+ if (e !== void 0 && sn(e), t <= K) throw new Error("invalid n length: expected positive n, got " + t);
1076
+ if (e !== void 0 && e < 1) throw new Error("invalid n length: expected positive bit length, got " + e);
1077
+ const r = ye(t);
1078
+ if (e !== void 0 && e < r) throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${e})`);
1079
+ const n = e !== void 0 ? e : r;
1095
1080
  return {
1096
- nBitLength: r,
1097
- nByteLength: Math.ceil(r / 8)
1081
+ nBitLength: n,
1082
+ nByteLength: Math.ceil(n / 8)
1098
1083
  };
1099
1084
  }
1100
- var mn = /* @__PURE__ */ new WeakMap(), tr = class {
1085
+ var Le = /* @__PURE__ */ new WeakMap(), xn = class {
1101
1086
  ORDER;
1102
1087
  BITS;
1103
1088
  BYTES;
1104
1089
  isLE;
1105
- ZERO = dt;
1106
- ONE = ot;
1090
+ ZERO = K;
1091
+ ONE = D;
1107
1092
  _lengths;
1108
1093
  _mod;
1109
- constructor(t, n = {}) {
1110
- if (t <= ot) throw new Error("invalid field: expected ORDER > 1, got " + t);
1111
- let e;
1112
- this.isLE = !1, n != null && typeof n == "object" && (typeof n.BITS == "number" && (e = n.BITS), typeof n.sqrt == "function" && Object.defineProperty(this, "sqrt", {
1113
- value: n.sqrt,
1094
+ constructor(t, e = {}) {
1095
+ if (t <= D) throw new Error("invalid field: expected ORDER > 1, got " + t);
1096
+ let r;
1097
+ this.isLE = !1, e != null && typeof e == "object" && (typeof e.BITS == "number" && (r = e.BITS), typeof e.sqrt == "function" && Object.defineProperty(this, "sqrt", {
1098
+ value: e.sqrt,
1114
1099
  enumerable: !0
1115
- }), typeof n.isLE == "boolean" && (this.isLE = n.isLE), n.allowedLengths && (this._lengths = Object.freeze(n.allowedLengths.slice())), typeof n.modFromBytes == "boolean" && (this._mod = n.modFromBytes));
1116
- const { nBitLength: r, nByteLength: o } = Mr(t, e);
1100
+ }), typeof e.isLE == "boolean" && (this.isLE = e.isLE), e.allowedLengths && (this._lengths = Object.freeze(e.allowedLengths.slice())), typeof e.modFromBytes == "boolean" && (this._mod = e.modFromBytes));
1101
+ const { nBitLength: n, nByteLength: o } = ir(t, r);
1117
1102
  if (o > 2048) throw new Error("invalid field: expected ORDER of <= 2048 bytes");
1118
- this.ORDER = t, this.BITS = r, this.BYTES = o, Object.freeze(this);
1103
+ this.ORDER = t, this.BITS = n, this.BYTES = o, Object.freeze(this);
1119
1104
  }
1120
1105
  create(t) {
1121
- return bt(t, this.ORDER);
1106
+ return tt(t, this.ORDER);
1122
1107
  }
1123
1108
  isValid(t) {
1124
1109
  if (typeof t != "bigint") throw new TypeError("invalid field element: expected bigint, got " + typeof t);
1125
- return dt <= t && t < this.ORDER;
1110
+ return K <= t && t < this.ORDER;
1126
1111
  }
1127
1112
  is0(t) {
1128
- return t === dt;
1113
+ return t === K;
1129
1114
  }
1130
1115
  isValidNot0(t) {
1131
1116
  return !this.is0(t) && this.isValid(t);
1132
1117
  }
1133
1118
  isOdd(t) {
1134
- return (t & ot) === ot;
1119
+ return (t & D) === D;
1135
1120
  }
1136
1121
  neg(t) {
1137
- return bt(-t, this.ORDER);
1122
+ return tt(-t, this.ORDER);
1138
1123
  }
1139
- eql(t, n) {
1140
- return t === n;
1124
+ eql(t, e) {
1125
+ return t === e;
1141
1126
  }
1142
1127
  sqr(t) {
1143
- return bt(t * t, this.ORDER);
1128
+ return tt(t * t, this.ORDER);
1144
1129
  }
1145
- add(t, n) {
1146
- return bt(t + n, this.ORDER);
1130
+ add(t, e) {
1131
+ return tt(t + e, this.ORDER);
1147
1132
  }
1148
- sub(t, n) {
1149
- return bt(t - n, this.ORDER);
1133
+ sub(t, e) {
1134
+ return tt(t - e, this.ORDER);
1150
1135
  }
1151
- mul(t, n) {
1152
- return bt(t * n, this.ORDER);
1136
+ mul(t, e) {
1137
+ return tt(t * e, this.ORDER);
1153
1138
  }
1154
- pow(t, n) {
1155
- return zr(this, t, n);
1139
+ pow(t, e) {
1140
+ return or(this, t, e);
1156
1141
  }
1157
- div(t, n) {
1158
- return bt(t * dn(n, this.ORDER), this.ORDER);
1142
+ div(t, e) {
1143
+ return tt(t * Ie(e, this.ORDER), this.ORDER);
1159
1144
  }
1160
1145
  sqrN(t) {
1161
1146
  return t * t;
1162
1147
  }
1163
- addN(t, n) {
1164
- return t + n;
1148
+ addN(t, e) {
1149
+ return t + e;
1165
1150
  }
1166
- subN(t, n) {
1167
- return t - n;
1151
+ subN(t, e) {
1152
+ return t - e;
1168
1153
  }
1169
- mulN(t, n) {
1170
- return t * n;
1154
+ mulN(t, e) {
1155
+ return t * e;
1171
1156
  }
1172
1157
  inv(t) {
1173
- return dn(t, this.ORDER);
1158
+ return Ie(t, this.ORDER);
1174
1159
  }
1175
1160
  sqrt(t) {
1176
- let n = mn.get(this);
1177
- return n || mn.set(this, n = Vr(this.ORDER)), n(this, t);
1161
+ let e = Le.get(this);
1162
+ return e || Le.set(this, e = er(this.ORDER)), e(this, t);
1178
1163
  }
1179
1164
  toBytes(t) {
1180
- return this.isLE ? zn(t, this.BYTES) : tn(t, this.BYTES);
1181
- }
1182
- fromBytes(t, n = !1) {
1183
- st(t);
1184
- const { _lengths: e, BYTES: r, isLE: o, ORDER: i, _mod: a } = this;
1185
- if (e) {
1186
- if (t.length < 1 || !e.includes(t.length) || t.length > r) throw new Error("Field.fromBytes: expected " + e + " bytes, got " + t.length);
1187
- const l = new Uint8Array(r);
1188
- l.set(t, o ? 0 : l.length - t.length), t = l;
1189
- }
1190
- if (t.length !== r) throw new Error("Field.fromBytes: expected " + r + " bytes, got " + t.length);
1191
- let f = o ? ge(t) : St(t);
1192
- if (a && (f = bt(f, i)), !n && !this.isValid(f))
1165
+ return this.isLE ? hn(t, this.BYTES) : pe(t, this.BYTES);
1166
+ }
1167
+ fromBytes(t, e = !1) {
1168
+ W(t);
1169
+ const { _lengths: r, BYTES: n, isLE: o, ORDER: i, _mod: c } = this;
1170
+ if (r) {
1171
+ if (t.length < 1 || !r.includes(t.length) || t.length > n) throw new Error("Field.fromBytes: expected " + r + " bytes, got " + t.length);
1172
+ const a = new Uint8Array(n);
1173
+ a.set(t, o ? 0 : a.length - t.length), t = a;
1174
+ }
1175
+ if (t.length !== n) throw new Error("Field.fromBytes: expected " + n + " bytes, got " + t.length);
1176
+ let s = o ? ln(t) : Ct(t);
1177
+ if (c && (s = tt(s, i)), !e && !this.isValid(s))
1193
1178
  throw new Error("invalid field element: outside of range 0..ORDER");
1194
- return f;
1179
+ return s;
1195
1180
  }
1196
1181
  invertBatch(t) {
1197
- return Ee(this, t);
1182
+ return vn(this, t);
1198
1183
  }
1199
- cmov(t, n, e) {
1200
- return ie(e, "condition"), e ? n : t;
1184
+ cmov(t, e, r) {
1185
+ return Ot(r, "condition"), r ? e : t;
1201
1186
  }
1202
1187
  };
1203
- Object.freeze(tr.prototype);
1204
- function ve(t, n = {}) {
1205
- return new tr(t, n);
1188
+ Object.freeze(xn.prototype);
1189
+ function jt(t, e = {}) {
1190
+ return new xn(t, e);
1206
1191
  }
1207
- function er(t) {
1192
+ function Bn(t) {
1208
1193
  if (typeof t != "bigint") throw new Error("field order must be bigint");
1209
- if (t <= ot) throw new Error("field order must be greater than 1");
1210
- const n = ye(t - ot);
1211
- return Math.ceil(n / 8);
1212
- }
1213
- function nn(t) {
1214
- const n = er(t);
1215
- return n + Math.ceil(n / 2);
1216
- }
1217
- function nr(t, n, e = !1) {
1218
- st(t);
1219
- const r = t.length, o = er(n), i = Math.max(nn(n), 16);
1220
- if (r < i || r > 1024) throw new Error("expected " + i + "-1024 bytes of input, got " + r);
1221
- const a = bt(e ? ge(t) : St(t), n - ot) + ot;
1222
- return e ? zn(a, o) : tn(a, o);
1223
- }
1224
- var Wt = /* @__PURE__ */ BigInt(0), Zt = /* @__PURE__ */ BigInt(1);
1225
- function Gr(t) {
1226
- const n = t;
1227
- if (typeof n != "function") throw new TypeError("Point must be a constructor");
1228
- Mt({
1229
- Fp: n.Fp,
1230
- Fn: n.Fn,
1231
- fromAffine: n.fromAffine,
1232
- fromBytes: n.fromBytes,
1233
- fromHex: n.fromHex
1234
- }, {
1235
- Fp: "object",
1236
- Fn: "object",
1237
- fromAffine: "function",
1238
- fromBytes: "function",
1239
- fromHex: "function"
1240
- }), se(n.Fp), se(n.Fn);
1241
- }
1242
- function we(t, n) {
1243
- const e = n.negate();
1244
- return t ? e : n;
1245
- }
1246
- function gn(t, n) {
1247
- const e = Ee(t.Fp, n.map((r) => r.Z));
1248
- return n.map((r, o) => t.fromAffine(r.toAffine(e[o])));
1249
- }
1250
- function rr(t, n) {
1251
- if (!Number.isSafeInteger(t) || t <= 0 || t > n) throw new Error("invalid window size, expected [1.." + n + "], got W=" + t);
1194
+ if (t <= D) throw new Error("field order must be greater than 1");
1195
+ const e = ye(t - D);
1196
+ return Math.ceil(e / 8);
1252
1197
  }
1253
- function Re(t, n) {
1254
- rr(t, n);
1255
- const e = Math.ceil(n / t) + 1, r = 2 ** (t - 1), o = 2 ** t;
1198
+ function An(t) {
1199
+ const e = Bn(t);
1200
+ return e + Math.ceil(e / 2);
1201
+ }
1202
+ function sr(t, e, r = !1) {
1203
+ W(t);
1204
+ const n = t.length, o = Bn(e), i = Math.max(An(e), 16);
1205
+ if (n < i || n > 1024) throw new Error("expected " + i + "-1024 bytes of input, got " + n);
1206
+ const c = tt(r ? ln(t) : Ct(t), e - D) + D;
1207
+ return r ? hn(c, o) : pe(c, o);
1208
+ }
1209
+ var At = /* @__PURE__ */ BigInt(0), yt = /* @__PURE__ */ BigInt(1);
1210
+ function Zt(t, e) {
1211
+ const r = e.negate();
1212
+ return t ? r : e;
1213
+ }
1214
+ function Ne(t, e) {
1215
+ const r = vn(t.Fp, e.map((n) => n.Z));
1216
+ return e.map((n, o) => t.fromAffine(n.toAffine(r[o])));
1217
+ }
1218
+ function Rn(t, e) {
1219
+ if (!Number.isSafeInteger(t) || t <= 0 || t > e) throw new Error("invalid window size, expected [1.." + e + "], got W=" + t);
1220
+ }
1221
+ function Mt(t, e) {
1222
+ Rn(t, e);
1223
+ const r = Math.ceil(e / t) + 1, n = 2 ** (t - 1), o = 2 ** t;
1256
1224
  return {
1257
- windows: e,
1258
- windowSize: r,
1259
- mask: pe(t),
1225
+ windows: r,
1226
+ windowSize: n,
1227
+ mask: Ee(t),
1260
1228
  maxNumber: o,
1261
1229
  shiftBy: BigInt(t)
1262
1230
  };
1263
1231
  }
1264
- function wn(t, n, e) {
1265
- const { windowSize: r, mask: o, maxNumber: i, shiftBy: a } = e;
1266
- let f = Number(t & o), l = t >> a;
1267
- f > r && (f -= i, l += Zt);
1268
- const g = n * r, s = g + Math.abs(f) - 1, u = f === 0, d = f < 0, h = n % 2 !== 0;
1232
+ function Te(t, e, r) {
1233
+ const { windowSize: n, mask: o, maxNumber: i, shiftBy: c } = r;
1234
+ let s = Number(t & o), a = t >> c;
1235
+ s > n && (s -= i, a += yt);
1236
+ const u = e * n, f = u + Math.abs(s) - 1, g = s === 0, m = s < 0, w = e % 2 !== 0;
1269
1237
  return {
1270
- nextN: l,
1271
- offset: s,
1272
- isZero: u,
1273
- isNeg: d,
1274
- isNegF: h,
1275
- offsetF: g
1238
+ nextN: a,
1239
+ offset: f,
1240
+ isZero: g,
1241
+ isNeg: m,
1242
+ isNegF: w,
1243
+ offsetF: u
1276
1244
  };
1277
1245
  }
1278
- function Yr(t, n) {
1279
- if (!Array.isArray(t)) throw new Error("array expected");
1280
- t.forEach((e, r) => {
1281
- if (!(e instanceof n)) throw new Error("invalid point at index " + r);
1282
- });
1246
+ var Gt = /* @__PURE__ */ new WeakMap(), Sn = /* @__PURE__ */ new WeakMap();
1247
+ function Kt(t) {
1248
+ return Sn.get(t) || 1;
1283
1249
  }
1284
- function Kr(t, n) {
1285
- if (!Array.isArray(t)) throw new Error("array of scalars expected");
1286
- t.forEach((e, r) => {
1287
- if (!n.isValid(e)) throw new Error("invalid scalar at index " + r);
1288
- });
1250
+ function Ue(t) {
1251
+ if (t !== At) throw new Error("invalid wNAF");
1289
1252
  }
1290
- var _e = /* @__PURE__ */ new WeakMap(), or = /* @__PURE__ */ new WeakMap();
1291
- function Oe(t) {
1292
- return or.get(t) || 1;
1293
- }
1294
- function bn(t) {
1295
- if (t !== Wt) throw new Error("invalid wNAF");
1296
- }
1297
- var Xr = class {
1253
+ var cr = class {
1298
1254
  BASE;
1299
1255
  ZERO;
1300
1256
  Fn;
1301
1257
  bits;
1302
- constructor(t, n) {
1303
- this.BASE = t.BASE, this.ZERO = t.ZERO, this.Fn = t.Fn, this.bits = n;
1304
- }
1305
- _unsafeLadder(t, n, e = this.ZERO) {
1306
- let r = t;
1307
- for (; n > Wt; )
1308
- n & Zt && (e = e.add(r)), r = r.double(), n >>= Zt;
1309
- return e;
1310
- }
1311
- precomputeWindow(t, n) {
1312
- const { windows: e, windowSize: r } = Re(n, this.bits), o = [];
1313
- let i = t, a = i;
1314
- for (let f = 0; f < e; f++) {
1315
- a = i, o.push(a);
1316
- for (let l = 1; l < r; l++)
1317
- a = a.add(i), o.push(a);
1318
- i = a.double();
1258
+ constructor(t, e) {
1259
+ this.BASE = t.BASE, this.ZERO = t.ZERO, this.Fn = t.Fn, this.bits = e;
1260
+ }
1261
+ _unsafeLadder(t, e, r = this.ZERO) {
1262
+ let n = t;
1263
+ for (; e > At; )
1264
+ e & yt && (r = r.add(n)), n = n.double(), e >>= yt;
1265
+ return r;
1266
+ }
1267
+ precomputeWindow(t, e) {
1268
+ const { windows: r, windowSize: n } = Mt(e, this.bits), o = [];
1269
+ let i = t, c = i;
1270
+ for (let s = 0; s < r; s++) {
1271
+ c = i, o.push(c);
1272
+ for (let a = 1; a < n; a++)
1273
+ c = c.add(i), o.push(c);
1274
+ i = c.double();
1319
1275
  }
1320
1276
  return o;
1321
1277
  }
1322
- wNAF(t, n, e) {
1323
- if (!this.Fn.isValid(e)) throw new Error("invalid scalar");
1324
- let r = this.ZERO, o = this.BASE;
1325
- const i = Re(t, this.bits);
1326
- for (let a = 0; a < i.windows; a++) {
1327
- const { nextN: f, offset: l, isZero: g, isNeg: s, isNegF: u, offsetF: d } = wn(e, a, i);
1328
- e = f, g ? o = o.add(we(u, n[d])) : r = r.add(we(s, n[l]));
1278
+ wNAF(t, e, r) {
1279
+ if (!this.Fn.isValid(r)) throw new Error("invalid scalar");
1280
+ let n = this.ZERO, o = this.BASE;
1281
+ const i = Mt(t, this.bits);
1282
+ for (let c = 0; c < i.windows; c++) {
1283
+ const { nextN: s, offset: a, isZero: u, isNeg: f, isNegF: g, offsetF: m } = Te(r, c, i);
1284
+ r = s, u ? o = o.add(Zt(g, e[m])) : n = n.add(Zt(f, e[a]));
1329
1285
  }
1330
- return bn(e), {
1331
- p: r,
1286
+ return Ue(r), {
1287
+ p: n,
1332
1288
  f: o
1333
1289
  };
1334
1290
  }
1335
- wNAFUnsafe(t, n, e, r = this.ZERO) {
1336
- const o = Re(t, this.bits);
1337
- for (let i = 0; i < o.windows && e !== Wt; i++) {
1338
- const { nextN: a, offset: f, isZero: l, isNeg: g } = wn(e, i, o);
1339
- if (e = a, !l) {
1340
- const s = n[f];
1341
- r = r.add(g ? s.negate() : s);
1291
+ wNAFUnsafe(t, e, r, n = this.ZERO) {
1292
+ const o = Mt(t, this.bits);
1293
+ for (let i = 0; i < o.windows && r !== At; i++) {
1294
+ const { nextN: c, offset: s, isZero: a, isNeg: u } = Te(r, i, o);
1295
+ if (r = c, !a) {
1296
+ const f = e[s];
1297
+ n = n.add(u ? f.negate() : f);
1342
1298
  }
1343
1299
  }
1344
- return bn(e), r;
1300
+ return Ue(r), n;
1345
1301
  }
1346
- getPrecomputes(t, n, e) {
1347
- let r = _e.get(n);
1348
- return r || (r = this.precomputeWindow(n, t), t !== 1 && (typeof e == "function" && (r = e(r)), _e.set(n, r))), r;
1302
+ getPrecomputes(t, e, r) {
1303
+ let n = Gt.get(e);
1304
+ return n || (n = this.precomputeWindow(e, t), t !== 1 && (typeof r == "function" && (n = r(n)), Gt.set(e, n))), n;
1349
1305
  }
1350
- cached(t, n, e) {
1351
- const r = Oe(t);
1352
- return this.wNAF(r, this.getPrecomputes(r, t, e), n);
1306
+ cached(t, e, r) {
1307
+ const n = Kt(t);
1308
+ return this.wNAF(n, this.getPrecomputes(n, t, r), e);
1353
1309
  }
1354
- unsafe(t, n, e, r) {
1355
- const o = Oe(t);
1356
- return o === 1 ? this._unsafeLadder(t, n, r) : this.wNAFUnsafe(o, this.getPrecomputes(o, t, e), n, r);
1310
+ unsafe(t, e, r, n) {
1311
+ const o = Kt(t);
1312
+ return o === 1 ? this._unsafeLadder(t, e, n) : this.wNAFUnsafe(o, this.getPrecomputes(o, t, r), e, n);
1357
1313
  }
1358
- createCache(t, n) {
1359
- rr(n, this.bits), or.set(t, n), _e.delete(t);
1314
+ createCache(t, e) {
1315
+ Rn(e, this.bits), Sn.set(t, e), Gt.delete(t);
1360
1316
  }
1361
1317
  hasCache(t) {
1362
- return Oe(t) !== 1;
1318
+ return Kt(t) !== 1;
1363
1319
  }
1364
1320
  };
1365
- function Wr(t, n, e, r) {
1366
- let o = n, i = t.ZERO, a = t.ZERO;
1367
- for (; e > Wt || r > Wt; )
1368
- e & Zt && (i = i.add(o)), r & Zt && (a = a.add(o)), o = o.double(), e >>= Zt, r >>= Zt;
1321
+ function fr(t, e, r, n) {
1322
+ let o = e, i = t.ZERO, c = t.ZERO;
1323
+ for (; r > At || n > At; )
1324
+ r & yt && (i = i.add(o)), n & yt && (c = c.add(o)), o = o.double(), r >>= yt, n >>= yt;
1369
1325
  return {
1370
1326
  p1: i,
1371
- p2: a
1327
+ p2: c
1372
1328
  };
1373
1329
  }
1374
- function Qr(t, n, e) {
1375
- const r = t.Fn;
1376
- Yr(n, t), Kr(e, r);
1377
- const o = n.length, i = e.length;
1378
- if (o !== i) throw new Error("arrays of points and scalars must have equal length");
1379
- const a = t.ZERO, f = ye(BigInt(o));
1380
- let l = 1;
1381
- f > 12 ? l = f - 3 : f > 4 ? l = f - 2 : f > 0 && (l = 2);
1382
- const g = pe(l), s = new Array(Number(g) + 1).fill(a), u = Math.floor((r.BITS - 1) / l) * l;
1383
- let d = a;
1384
- for (let h = u; h >= 0; h -= l) {
1385
- s.fill(a);
1386
- for (let b = 0; b < i; b++) {
1387
- const E = e[b], T = Number(E >> BigInt(h) & g);
1388
- s[T] = s[T].add(n[b]);
1389
- }
1390
- let w = a;
1391
- for (let b = s.length - 1, E = a; b > 0; b--)
1392
- E = E.add(s[b]), w = w.add(E);
1393
- if (d = d.add(w), h !== 0) for (let b = 0; b < l; b++) d = d.double();
1394
- }
1395
- return d;
1396
- }
1397
- function yn(t, n, e) {
1398
- if (n) {
1399
- if (n.ORDER !== t) throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
1400
- return se(n), n;
1401
- } else return ve(t, { isLE: e });
1402
- }
1403
- function Jr(t, n, e = {}, r) {
1404
- if (r === void 0 && (r = t === "edwards"), !n || typeof n != "object") throw new Error(`expected valid ${t} CURVE object`);
1405
- for (const f of [
1330
+ function $e(t, e, r) {
1331
+ if (e) {
1332
+ if (e.ORDER !== t) throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
1333
+ return rr(e), e;
1334
+ } else return jt(t, { isLE: r });
1335
+ }
1336
+ function ar(t, e, r = {}, n) {
1337
+ if (n === void 0 && (n = t === "edwards"), !e || typeof e != "object") throw new Error(`expected valid ${t} CURVE object`);
1338
+ for (const s of [
1406
1339
  "p",
1407
1340
  "n",
1408
1341
  "h"
1409
1342
  ]) {
1410
- const l = n[f];
1411
- if (!(typeof l == "bigint" && l > Wt)) throw new Error(`CURVE.${f} must be positive bigint`);
1343
+ const a = e[s];
1344
+ if (!(typeof a == "bigint" && a > At)) throw new Error(`CURVE.${s} must be positive bigint`);
1412
1345
  }
1413
- const o = yn(n.p, e.Fp, r), i = yn(n.n, e.Fn, r), a = [
1346
+ const o = $e(e.p, r.Fp, n), i = $e(e.n, r.Fn, n), c = [
1414
1347
  "Gx",
1415
1348
  "Gy",
1416
1349
  "a",
1417
1350
  t === "weierstrass" ? "b" : "d"
1418
1351
  ];
1419
- for (const f of a) if (!o.isValid(n[f])) throw new Error(`CURVE.${f} must be valid field element of CURVE.Fp`);
1420
- return n = Object.freeze(Object.assign({}, n)), {
1421
- CURVE: n,
1352
+ for (const s of c) if (!o.isValid(e[s])) throw new Error(`CURVE.${s} must be valid field element of CURVE.Fp`);
1353
+ return e = Object.freeze(Object.assign({}, e)), {
1354
+ CURVE: e,
1422
1355
  Fp: o,
1423
1356
  Fn: i
1424
1357
  };
1425
1358
  }
1426
- function to(t, n) {
1427
- return function(r) {
1428
- const o = t(r);
1359
+ function ur(t, e) {
1360
+ return function(n) {
1361
+ const o = t(n);
1429
1362
  return {
1430
1363
  secretKey: o,
1431
- publicKey: n(o)
1432
- };
1433
- };
1434
- }
1435
- function ir(t) {
1436
- if (!Number.isSafeInteger(t) || t < 0 || t > 4294967295) throw new Error("wrong u32 integer:" + t);
1437
- return t;
1438
- }
1439
- function eo(t) {
1440
- if (ir(t), t <= 1) return 1;
1441
- if (t > 2147483648) throw new Error("nextPowerOfTwo overflow: result does not fit u32");
1442
- return 1 << Pe(t - 1) + 1 >>> 0;
1443
- }
1444
- function Pe(t) {
1445
- return ir(t), 31 - Math.clz32(t);
1446
- }
1447
- function no(t, n, e, r, o) {
1448
- const i = t, a = e || ((s, u) => new Array(s).fill(u ?? i.ZERO)), f = (s) => {
1449
- if (Array.isArray(s)) return !0;
1450
- if (!ArrayBuffer.isView(s)) return !1;
1451
- const u = s;
1452
- return typeof u.length == "number" && typeof u.slice == "function" && typeof u[Symbol.iterator] == "function";
1453
- }, l = (...s) => {
1454
- if (!s.length) return 0;
1455
- for (const d of s) if (!f(d)) throw new Error("poly: not polynomial: " + d);
1456
- const u = s[0].length;
1457
- for (let d = 1; d < s.length; d++) if (s[d].length !== u) throw new Error(`poly: mismatched lengths ${u} vs ${s[d].length}`);
1458
- if (o !== void 0 && u !== o) throw new Error(`poly: expected fixed length ${o}, got ${u}`);
1459
- return u;
1460
- };
1461
- function g(s, u, d = !1) {
1462
- const h = Pe(u), w = d ? n.brp(h) : n.roots(h);
1463
- for (let b = 0; b < u; b++) if (i.eql(s, w[b])) return b;
1464
- return -1;
1465
- }
1466
- return {
1467
- roots: n,
1468
- create: a,
1469
- length: o,
1470
- extend: (s, u) => {
1471
- l(s);
1472
- const d = a(u, i.ZERO);
1473
- for (let h = 0; h < Math.min(s.length, u); h++) d[h] = s[h];
1474
- return d;
1475
- },
1476
- degree: (s) => {
1477
- l(s);
1478
- for (let u = s.length - 1; u >= 0; u--) if (!i.is0(s[u])) return u;
1479
- return -1;
1480
- },
1481
- add: (s, u) => {
1482
- const d = l(s, u), h = a(d);
1483
- for (let w = 0; w < d; w++) h[w] = i.add(s[w], u[w]);
1484
- return h;
1485
- },
1486
- sub: (s, u) => {
1487
- const d = l(s, u), h = a(d);
1488
- for (let w = 0; w < d; w++) h[w] = i.sub(s[w], u[w]);
1489
- return h;
1490
- },
1491
- dot: (s, u) => {
1492
- const d = l(s, u), h = a(d);
1493
- for (let w = 0; w < d; w++) h[w] = i.mul(s[w], u[w]);
1494
- return h;
1495
- },
1496
- mul: (s, u) => {
1497
- if (f(u)) {
1498
- const d = l(s, u);
1499
- if (r) {
1500
- const h = r.direct(s, !1, !0), w = r.direct(u, !1, !0);
1501
- for (let b = 0; b < h.length; b++) h[b] = i.mul(h[b], w[b]);
1502
- return r.inverse(h, !0, !1);
1503
- } else {
1504
- const h = a(d);
1505
- for (let w = 0; w < d; w++) for (let b = 0; b < d; b++) {
1506
- const E = (w + b) % d;
1507
- h[E] = i.add(h[E], i.mul(s[w], u[b]));
1508
- }
1509
- return h;
1510
- }
1511
- } else {
1512
- const d = a(l(s));
1513
- for (let h = 0; h < d.length; h++) d[h] = i.mul(s[h], u);
1514
- return d;
1515
- }
1516
- },
1517
- convolve(s, u) {
1518
- const d = eo(s.length + u.length - 1);
1519
- return this.mul(this.extend(s, d), this.extend(u, d));
1520
- },
1521
- shift(s, u) {
1522
- const d = a(l(s));
1523
- d[0] = s[0];
1524
- for (let h = 1, w = i.ONE; h < s.length; h++)
1525
- w = i.mul(w, u), d[h] = i.mul(s[h], w);
1526
- return d;
1527
- },
1528
- clone: (s) => {
1529
- l(s);
1530
- const u = a(s.length);
1531
- for (let d = 0; d < s.length; d++) u[d] = s[d];
1532
- return u;
1533
- },
1534
- eval: (s, u) => {
1535
- l(s, u);
1536
- let d = i.ZERO;
1537
- for (let h = 0; h < s.length; h++) d = i.add(d, i.mul(s[h], u[h]));
1538
- return d;
1539
- },
1540
- monomial: {
1541
- basis: (s, u) => {
1542
- const d = a(u);
1543
- let h = i.ONE;
1544
- for (let w = 0; w < u; w++)
1545
- d[w] = h, h = i.mul(h, s);
1546
- return d;
1547
- },
1548
- eval: (s, u) => {
1549
- l(s);
1550
- let d = i.ZERO;
1551
- for (let h = s.length - 1; h >= 0; h--) d = i.add(i.mul(d, u), s[h]);
1552
- return d;
1553
- }
1554
- },
1555
- lagrange: {
1556
- basis: (s, u, d = !1, h) => {
1557
- const w = Pe(u), b = h || (d ? n.brp(w) : n.roots(w)), E = a(u), T = g(s, u, d);
1558
- if (T !== -1)
1559
- return E[T] = i.ONE, E;
1560
- const B = i.pow(s, BigInt(u)), C = i.mul(i.sub(B, i.ONE), i.inv(BigInt(u))), O = a(u);
1561
- for (let z = 0; z < u; z++) O[z] = i.sub(s, b[z]);
1562
- const F = i.invertBatch(O);
1563
- for (let z = 0; z < u; z++) E[z] = i.mul(C, i.mul(b[z], F[z]));
1564
- return E;
1565
- },
1566
- eval(s, u, d = !1) {
1567
- l(s);
1568
- const h = g(u, s.length, d);
1569
- if (h !== -1) return s[h];
1570
- const w = this.basis(u, s.length, d);
1571
- let b = i.ZERO;
1572
- for (let E = 0; E < s.length; E++) i.is0(s[E]) || (b = i.add(b, i.mul(s[E], w[E])));
1573
- return b;
1574
- }
1575
- },
1576
- vanishing(s) {
1577
- l(s);
1578
- const u = a(s.length + 1, i.ZERO);
1579
- u[0] = i.ONE;
1580
- for (const d of s) {
1581
- const h = i.neg(d);
1582
- for (let w = u.length - 1; w > 0; w--) u[w] = i.add(i.mul(u[w], h), u[w - 1]);
1583
- u[0] = i.mul(u[0], h);
1584
- }
1585
- return u;
1586
- }
1587
- };
1588
- }
1589
- var ro = St;
1590
- function kt(t, n) {
1591
- if (Ft(t), Ft(n), n < 0 || n > 4) throw new Error("invalid I2OSP length: " + n);
1592
- if (t < 0 || t > 2 ** (8 * n) - 1) throw new Error("invalid I2OSP input: " + t);
1593
- const e = Array.from({ length: n }).fill(0);
1594
- for (let r = n - 1; r >= 0; r--)
1595
- e[r] = t & 255, t >>>= 8;
1596
- return new Uint8Array(e);
1597
- }
1598
- function oo(t, n) {
1599
- const e = new Uint8Array(t.length);
1600
- for (let r = 0; r < t.length; r++) e[r] = t[r] ^ n[r];
1601
- return e;
1602
- }
1603
- function sr(t) {
1604
- if (!oe(t) && typeof t != "string") throw new Error("DST must be Uint8Array or ascii string");
1605
- const n = typeof t == "string" ? be(t) : t;
1606
- if (n.length === 0) throw new Error("DST must be non-empty");
1607
- return n;
1608
- }
1609
- function io(t, n, e, r) {
1610
- st(t), Ft(e), n = sr(n), n.length > 255 && (n = r(Q(be("H2C-OVERSIZE-DST-"), n)));
1611
- const { outputLen: o, blockLen: i } = r, a = Math.ceil(e / o);
1612
- if (e > 65535 || a > 255) throw new Error("expand_message_xmd: invalid lenInBytes");
1613
- const f = Q(n, kt(n.length, 1)), l = new Uint8Array(i), g = kt(e, 2), s = new Array(a), u = r(Q(l, t, g, kt(0, 1), f));
1614
- s[0] = r(Q(u, kt(1, 1), f));
1615
- for (let d = 1; d < a; d++) s[d] = r(Q(oo(u, s[d - 1]), kt(d + 1, 1), f));
1616
- return Q(...s).slice(0, e);
1617
- }
1618
- function so(t, n, e, r, o) {
1619
- if (st(t), Ft(e), n = sr(n), n.length > 255) {
1620
- const i = Math.ceil(2 * r / 8);
1621
- n = o.create({ dkLen: i }).update(be("H2C-OVERSIZE-DST-")).update(n).digest();
1622
- }
1623
- if (e > 65535 || n.length > 255) throw new Error("expand_message_xof: invalid lenInBytes");
1624
- return o.create({ dkLen: e }).update(t).update(kt(e, 2)).update(n).update(kt(n.length, 1)).digest();
1625
- }
1626
- function He(t, n, e) {
1627
- Mt(e, {
1628
- p: "bigint",
1629
- m: "number",
1630
- k: "number",
1631
- hash: "function"
1632
- });
1633
- const { p: r, k: o, m: i, hash: a, expand: f, DST: l } = e;
1634
- if (Ft(a.outputLen, "valid hash"), st(t), Ft(n), n < 1) throw new Error("hash_to_field: expected count >= 1");
1635
- if (i < 1) throw new Error("hash_to_field: expected m >= 1");
1636
- const g = r.toString(2).length, s = Math.ceil((g + o) / 8), u = n * i * s;
1637
- let d;
1638
- if (f === "xmd") d = io(t, l, u, a);
1639
- else if (f === "xof") d = so(t, l, u, o, a);
1640
- else if (f === "_internal_pass") d = t;
1641
- else throw new Error('expand must be "xmd" or "xof"');
1642
- const h = new Array(n);
1643
- for (let w = 0; w < n; w++) {
1644
- const b = new Array(i);
1645
- for (let E = 0; E < i; E++) {
1646
- const T = s * (E + w * i);
1647
- b[E] = bt(ro(d.subarray(T, T + s)), r);
1648
- }
1649
- h[w] = b;
1650
- }
1651
- return h;
1652
- }
1653
- function co(t, n) {
1654
- const e = n.map((r) => Array.from(r).reverse());
1655
- return (r, o) => {
1656
- const [i, a, f, l] = e.map((u) => u.reduce((d, h) => t.add(t.mul(d, r), h))), [g, s] = Ee(t, [a, l], !0);
1657
- return r = t.mul(i, g), o = t.mul(o, t.mul(f, s)), {
1658
- x: r,
1659
- y: o
1364
+ publicKey: e(o)
1660
1365
  };
1661
1366
  };
1662
1367
  }
1663
- var fo = "HashToScalar-";
1664
- function ao(t, n, e) {
1665
- if (typeof n != "function") throw new Error("mapToCurve() must be defined");
1666
- const r = (f) => Object.freeze({
1667
- ...f,
1668
- DST: oe(f.DST) ? Ze(f.DST) : f.DST,
1669
- ...f.encodeDST === void 0 ? {} : { encodeDST: oe(f.encodeDST) ? Ze(f.encodeDST) : f.encodeDST }
1670
- }), o = r(e);
1671
- function i(f) {
1672
- return t.fromAffine(n(f));
1673
- }
1674
- function a(f) {
1675
- const l = f.clearCofactor();
1676
- return l.equals(t.ZERO) ? t.ZERO : (l.assertValidity(), l);
1677
- }
1678
- return Object.freeze({
1679
- get defaults() {
1680
- return r(o);
1681
- },
1682
- Point: t,
1683
- hashToCurve(f, l) {
1684
- const g = He(f, 2, Object.assign({}, o, l)), s = i(g[0]), u = i(g[1]);
1685
- return a(s.add(u));
1686
- },
1687
- encodeToCurve(f, l) {
1688
- const g = o.encodeDST ? { DST: o.encodeDST } : {};
1689
- return a(i(He(f, 1, Object.assign({}, o, g, l))[0]));
1690
- },
1691
- mapToCurve(f) {
1692
- if (o.m === 1) {
1693
- if (typeof f != "bigint") throw new Error("expected bigint (m=1)");
1694
- return a(i([f]));
1695
- }
1696
- if (!Array.isArray(f)) throw new Error("expected array of bigints");
1697
- for (const l of f) if (typeof l != "bigint") throw new Error("expected array of bigints");
1698
- return a(i(f));
1699
- },
1700
- hashToScalar(f, l) {
1701
- const g = t.Fn.ORDER;
1702
- return He(f, 1, Object.assign({}, o, {
1703
- p: g,
1704
- m: 1,
1705
- DST: fo
1706
- }, l))[0][0];
1707
- }
1708
- });
1709
- }
1710
- Qt();
1711
- var fe = (t) => {
1712
- if (!Number.isSafeInteger(t.min) || !Number.isSafeInteger(t.max)) throw new Error("Wrong signers info: min=" + t.min + " max=" + t.max);
1713
- if (t.min < 2 || t.max < 2 || t.min > t.max) throw new Error("Wrong signers info: min=" + t.min + " max=" + t.max);
1714
- }, pn = (t, n) => {
1715
- if (n < t.min || n > t.max) throw new Error("Wrong number of commitments=" + n);
1716
- }, ae = class extends Error {
1717
- cheaters;
1718
- constructor(t, n) {
1719
- super(t), this.cheaters = n;
1720
- }
1721
- };
1722
- function cr(t) {
1723
- Mt(t, {
1724
- name: "string",
1725
- hash: "function"
1726
- }, {
1727
- hashToScalar: "function",
1728
- validatePoint: "function",
1729
- parsePublicKey: "function",
1730
- adjustScalar: "function",
1731
- adjustPoint: "function",
1732
- challenge: "function",
1733
- adjustNonces: "function",
1734
- adjustSecret: "function",
1735
- adjustPublic: "function",
1736
- adjustGroupCommitmentShare: "function",
1737
- adjustDKG: "function"
1738
- }), Gr(t.Point);
1739
- const { Point: n } = t, e = t.Fn === void 0 ? n.Fn : t.Fn, r = t.hash, o = t.hashToScalar === void 0 ? (c, m = { DST: new Uint8Array() }) => {
1740
- const y = r(Q(m.DST, c));
1741
- return e.create(e.isLE ? ge(y) : St(y));
1742
- } : t.hashToScalar, i = Nt(t.H1 !== void 0 ? t.H1 : t.name + "rho"), a = Nt(t.H2 !== void 0 ? t.H2 : t.name + "chal"), f = Nt(t.H3 !== void 0 ? t.H3 : t.name + "nonce"), l = Nt(t.H4 !== void 0 ? t.H4 : t.name + "msg"), g = Nt(t.H5 !== void 0 ? t.H5 : t.name + "com"), s = Nt(t.HDKG !== void 0 ? t.HDKG : t.name + "dkg"), u = Nt(t.HID !== void 0 ? t.HID : t.name + "id"), d = (c) => o(c, { DST: i }), h = (c) => o(c, { DST: a }), w = (c) => o(c, { DST: f }), b = (c) => r(Q(l, c)), E = (c) => r(Q(g, c)), T = (c) => o(c, { DST: s }), B = (c) => o(c, { DST: u }), C = (c = wt) => {
1743
- const m = nr(c(nn(e.ORDER)), e.ORDER, e.isLE);
1744
- return e.isLE ? ge(m) : St(m);
1745
- }, O = (c) => c.toBytes(), F = (c) => {
1746
- const m = n.fromBytes(c);
1747
- return t.validatePoint && t.validatePoint(m), m;
1748
- }, z = (c, m) => ({
1749
- identifier: c,
1750
- hiding: O(n.BASE.multiply(e.fromBytes(m.hiding))),
1751
- binding: O(n.BASE.multiply(e.fromBytes(m.binding)))
1752
- }), W = t.adjustPoint === void 0 ? (c) => c : t.adjustPoint, N = (c) => {
1753
- if (!e.isValid(c) || e.is0(c)) throw new Error("Invalid identifier " + c);
1754
- return c;
1755
- }, V = (c) => Ct(e.toBytes(N(c))), K = (c) => {
1756
- const m = N(e.fromBytes(he(c)));
1757
- if (V(m) !== c) throw new Error("expected canonical identifier hex");
1758
- return m;
1759
- }, M = {
1760
- encode: (c, m) => {
1761
- let y = Q(O(c), e.toBytes(m));
1762
- return t.adjustTx && (y = t.adjustTx.encode(y)), y;
1763
- },
1764
- decode: (c) => (t.adjustTx && (c = t.adjustTx.decode(c)), {
1765
- R: F(c.subarray(0, -e.BYTES)),
1766
- z: e.fromBytes(c.subarray(-e.BYTES))
1767
- })
1768
- }, v = (c = wt) => {
1769
- let m = C(c);
1770
- t.adjustScalar && (m = t.adjustScalar(m));
1771
- let y = n.BASE.multiply(m);
1772
- return {
1773
- scalar: m,
1774
- point: y
1775
- };
1776
- }, H = "roots are unavailable in FROST polynomial mode", U = no(e, {
1777
- info: {
1778
- G: e.ZERO,
1779
- oddFactor: e.ZERO,
1780
- powerOfTwo: 0
1781
- },
1782
- roots() {
1783
- throw new Error(H);
1784
- },
1785
- brp() {
1786
- throw new Error(H);
1787
- },
1788
- inverse() {
1789
- throw new Error(H);
1790
- },
1791
- omega() {
1792
- throw new Error(H);
1793
- },
1794
- clear() {
1795
- }
1796
- }), S = (c, m) => Qr(n, c, m), p = (c, m) => {
1797
- if (!m.length) throw new Error("empty coefficients");
1798
- return U.monomial.eval(m, c);
1799
- }, R = (c, m) => {
1800
- const y = "invalid parameters";
1801
- if (!c.some((L) => e.eql(L, m))) throw new Error(y);
1802
- const x = new Set(c);
1803
- if (x.size !== c.length) throw new Error(y);
1804
- if (!x.has(m)) throw new Error(y);
1805
- let A = e.ONE, j = e.ONE;
1806
- for (const L of c)
1807
- e.eql(L, m) || (A = e.mul(A, L), j = e.mul(j, e.sub(L, m)));
1808
- return e.div(A, j);
1809
- }, I = (c, m) => S(m, U.monomial.basis(c, m.length)), _ = (c, m, y, x = wt) => {
1810
- fe(c);
1811
- const A = m === void 0 ? C(x) : e.fromBytes(m);
1812
- if (!y) {
1813
- y = [];
1814
- for (let L = 0; L < c.min - 1; L++) y.push(C(x));
1815
- }
1816
- if (y.length !== c.min - 1) throw new Error("wrong coefficients length");
1817
- const j = [A, ...y];
1818
- return {
1819
- coefficients: j,
1820
- commitment: j.map((L) => n.BASE.multiply(L)),
1821
- secret: A
1822
- };
1823
- }, D = {
1824
- challenge: (c, m, y) => T(Q(e.toBytes(c), O(m), O(y))),
1825
- compute(c, m, y, x = wt) {
1826
- if (m.length < 1) throw new Error("coefficients should have at least one element");
1827
- const { point: A, scalar: j } = v(x), L = y[0], P = this.challenge(c, L, A), k = e.add(j, e.mul(m[0], P));
1828
- return M.encode(A, k);
1829
- },
1830
- validate(c, m, y) {
1831
- if (m.length < 1) throw new Error("commitment should have at least one element");
1832
- const { R: x, z: A } = M.decode(y), j = F(m[0]), L = this.challenge(c, j, x);
1833
- if (!x.equals(n.BASE.multiply(A).subtract(j.multiply(L)))) throw new Error("invalid proof of knowledge");
1834
- }
1835
- }, q = {
1836
- challenge: (c, m, y) => t.challenge ? t.challenge(c, m, y) : h(Q(O(c), O(m), y)),
1837
- sign(c, m, y = wt) {
1838
- const { point: x, scalar: A } = v(y), j = n.BASE.multiply(m), L = this.challenge(x, j, c);
1839
- return [x, e.add(A, e.mul(L, m))];
1840
- },
1841
- verify(c, m, y, x) {
1842
- t.adjustPoint && (x = t.adjustPoint(x)), t.adjustPoint && (m = t.adjustPoint(m));
1843
- const A = this.challenge(m, x, c), j = n.BASE.multiply(y), L = x.multiply(A);
1844
- let P = j.subtract(L).subtract(m);
1845
- return P.clearCofactor && (P = P.clearCofactor()), n.ZERO.equals(P);
1846
- }
1847
- }, X = (c, m, y) => {
1848
- if (!n.BASE.multiply(y).equals(I(c, m))) throw new Error("invalid secret share");
1849
- }, Y = {
1850
- fromNumber(c) {
1851
- if (!Number.isSafeInteger(c)) throw new Error("expected safe interger");
1852
- return V(BigInt(c));
1853
- },
1854
- derive(c) {
1855
- if (typeof c != "string") throw new Error("wrong identifier string: " + c);
1856
- return V(B(Nt(c)));
1857
- }
1858
- }, Z = (c, m = wt) => w(Q(m(32), e.toBytes(c))), nt = (c, m, y) => {
1859
- const x = m.map((tt) => [
1860
- tt.identifier,
1861
- K(tt.identifier),
1862
- F(tt.hiding),
1863
- F(tt.binding)
1864
- ]);
1865
- x.sort((tt, ht) => tt[1] < ht[1] ? -1 : tt[1] > ht[1] ? 1 : 0);
1866
- const A = [];
1867
- for (const [tt, ht, $, et] of x) A.push(e.toBytes(ht), O($), O(et));
1868
- const j = E(Q(...A)), L = Q(O(c), b(y), j), P = {};
1869
- for (const [tt, ht] of x) P[tt] = d(Q(L, e.toBytes(ht)));
1870
- const k = [], G = [];
1871
- for (const [tt, ht, $, et] of x) {
1872
- if (n.ZERO.equals($) || n.ZERO.equals(et)) throw new Error("infinity commitment");
1873
- k.push($, et), G.push(e.ONE, P[tt]);
1874
- }
1875
- const mt = S(k, G);
1876
- return {
1877
- identifiers: x.map((tt) => tt[1]),
1878
- groupCommitment: mt,
1879
- bindingFactors: P
1880
- };
1881
- }, rt = (c, m, y, x) => {
1882
- const A = W(F(c)), j = K(x), { identifiers: L, groupCommitment: P, bindingFactors: k } = nt(A, m, y), G = k[x];
1883
- return {
1884
- lambda: R(L, j),
1885
- challenge: q.challenge(P, A, y),
1886
- bindingFactor: G,
1887
- groupCommitment: P
1888
- };
1889
- };
1890
- Object.freeze(Y);
1891
- const it = {
1892
- Identifier: Y,
1893
- DKG: Object.freeze({
1894
- round1: (c, m, y, x = wt) => {
1895
- fe(m);
1896
- const A = K(c), { coefficients: j, commitment: L } = _(m, y, void 0, x), P = D.compute(A, j, L, x), k = L.map(O);
1897
- return {
1898
- public: {
1899
- identifier: V(A),
1900
- commitment: k,
1901
- proofOfKnowledge: P
1902
- },
1903
- secret: {
1904
- identifier: A,
1905
- coefficients: j,
1906
- commitment: L.map(O),
1907
- signers: {
1908
- min: m.min,
1909
- max: m.max
1910
- },
1911
- step: 1
1912
- }
1913
- };
1914
- },
1915
- round2: (c, m) => {
1916
- if (m.length !== c.signers.max - 1) throw new Error("wrong number of round1 packages");
1917
- if (!c.coefficients || c.step === 3) throw new Error("round3 package used in round2");
1918
- const y = {};
1919
- for (const x of m) {
1920
- if (x.commitment.length !== c.signers.min) throw new Error("wrong number of commitments");
1921
- const A = K(x.identifier);
1922
- if (A === c.identifier) throw new Error("duplicate id=" + V(A));
1923
- D.validate(A, x.commitment, x.proofOfKnowledge);
1924
- for (const L of x.commitment) F(L);
1925
- if (y[x.identifier]) throw new Error("Duplicate id=" + A);
1926
- const j = e.toBytes(p(A, c.coefficients));
1927
- y[x.identifier] = {
1928
- identifier: V(c.identifier),
1929
- signingShare: j
1930
- };
1931
- }
1932
- return c.step = 2, y;
1933
- },
1934
- round3: (c, m, y) => {
1935
- if (m.length !== c.signers.max - 1) throw new Error("wrong length of round1 packages");
1936
- if (!c.coefficients || c.step !== 2) throw new Error("round2 package used in round3");
1937
- if (y.length !== m.length) throw new Error("wrong length of round2 packages");
1938
- const x = {};
1939
- for (const $ of m) {
1940
- if (!$.identifier || !$.commitment) throw new Error("wrong round1 share");
1941
- x[$.identifier] = { ...$ };
1942
- }
1943
- for (const $ of y) {
1944
- if (!$.identifier || !$.signingShare) throw new Error("wrong round2 share");
1945
- if (!x[$.identifier]) throw new Error("round1 share for " + $.identifier + " is missing");
1946
- x[$.identifier].signingShare = $.signingShare;
1947
- }
1948
- if (Object.keys(x).length !== m.length) throw new Error("mismatch identifiers between rounds");
1949
- let A = e.ZERO;
1950
- if (c.commitment.length !== c.signers.min) throw new Error("wrong commitments length");
1951
- const j = c.commitment.map(F), L = p(c.identifier, c.coefficients);
1952
- X(c.identifier, j, L);
1953
- const P = j.map(O), k = { [V(c.identifier)]: P };
1954
- for (const $ in x) {
1955
- const et = x[$];
1956
- if (!et.signingShare || !et.commitment) throw new Error("mismatch identifiers");
1957
- const pt = K($), Gt = e.fromBytes(et.signingShare), xe = et.commitment.map(F);
1958
- X(c.identifier, xe, Gt), A = e.add(A, Gt);
1959
- const Jt = V(pt);
1960
- if (k[Jt]) throw new Error("duplicated id=" + Jt);
1961
- k[Jt] = et.commitment;
1962
- }
1963
- A = e.add(A, L);
1964
- const G = new Array(c.signers.min).fill(n.ZERO);
1965
- for (const $ in k) {
1966
- const et = k[$];
1967
- if (et.length !== c.signers.min) throw new Error("wrong commitments length");
1968
- for (let pt = 0; pt < et.length; pt++) G[pt] = G[pt].add(F(et[pt]));
1969
- }
1970
- const mt = G.map(O), tt = {};
1971
- for (const $ in k) tt[$] = O(I(K($), G));
1972
- let ht = {
1973
- public: {
1974
- signers: {
1975
- min: c.signers.min,
1976
- max: c.signers.max
1977
- },
1978
- commitments: mt,
1979
- verifyingShares: Object.fromEntries(Object.entries(tt).map(([$, et]) => [$, et.slice()]))
1980
- },
1981
- secret: {
1982
- identifier: V(c.identifier),
1983
- signingShare: e.toBytes(A)
1984
- }
1985
- };
1986
- t.adjustDKG && (ht = t.adjustDKG(ht));
1987
- for (let $ = 0; $ < c.coefficients.length; $++) c.coefficients[$] -= c.coefficients[$];
1988
- return delete c.coefficients, c.step = 3, ht;
1989
- },
1990
- clean(c) {
1991
- if (c.identifier -= c.identifier, c.coefficients) for (let m = 0; m < c.coefficients.length; m++) c.coefficients[m] -= c.coefficients[m];
1992
- c.step = 3;
1993
- }
1994
- }),
1995
- trustedDealer(c, m, y, x = wt) {
1996
- if (fe(c), m === void 0) {
1997
- m = [];
1998
- for (let G = 1; G <= c.max; G++) m.push(Y.fromNumber(G));
1999
- } else if (!Array.isArray(m) || m.length !== c.max) throw new Error("identifiers should be array of " + c.max);
2000
- const A = {};
2001
- for (const G of m) {
2002
- const mt = K(G);
2003
- if (G in A) throw new Error("duplicated id=" + G);
2004
- A[G] = mt;
2005
- }
2006
- const j = _(c, y, void 0, x), L = j.commitment.map(O), P = {}, k = {};
2007
- for (const G of m) {
2008
- const mt = p(A[G], j.coefficients);
2009
- k[G] = O(n.BASE.multiply(mt)), P[G] = {
2010
- identifier: G,
2011
- signingShare: e.toBytes(mt)
2012
- };
2013
- }
2014
- return {
2015
- public: {
2016
- signers: {
2017
- min: c.min,
2018
- max: c.max
2019
- },
2020
- commitments: L,
2021
- verifyingShares: k
2022
- },
2023
- secretShares: P
2024
- };
2025
- },
2026
- validateSecret(c, m) {
2027
- X(K(c.identifier), m.commitments.map(F), e.fromBytes(c.signingShare));
2028
- },
2029
- commit(c, m = wt) {
2030
- const y = e.fromBytes(c.signingShare), x = Z(y, m), A = Z(y, m), j = {
2031
- hiding: e.toBytes(x),
2032
- binding: e.toBytes(A)
2033
- };
2034
- return {
2035
- nonces: j,
2036
- commitments: z(c.identifier, j)
2037
- };
2038
- },
2039
- signShare(c, m, y, x, A) {
2040
- pn(m.signers, x.length);
2041
- const j = e.fromBytes(y.hiding), L = e.fromBytes(y.binding);
2042
- if (e.is0(j) || e.is0(L)) throw new Error("signing nonces already used");
2043
- const P = {
2044
- identifier: c.identifier,
2045
- hiding: O(n.BASE.multiply(j)),
2046
- binding: O(n.BASE.multiply(L))
2047
- }, k = x.find((wr) => wr.identifier === c.identifier);
2048
- if (!k) throw new Error("missing signer commitment");
2049
- if (Ct(k.hiding) !== Ct(P.hiding) || Ct(k.binding) !== Ct(P.binding)) throw new Error("incorrect signer commitment");
2050
- t.adjustSecret && (c = t.adjustSecret(c, m)), t.adjustPublic && (m = t.adjustPublic(m));
2051
- const G = e.fromBytes(c.signingShare), { lambda: mt, challenge: tt, bindingFactor: ht, groupCommitment: $ } = rt(m.commitments[0], x, A, c.identifier), et = t.adjustNonces ? t.adjustNonces($, y) : y, pt = t.adjustNonces ? e.fromBytes(et.hiding) : j, Gt = t.adjustNonces ? e.fromBytes(et.binding) : L, xe = e.mul(e.mul(mt, G), tt), Jt = e.mul(Gt, ht), gr = e.toBytes(e.add(e.add(pt, Jt), xe));
2052
- return y.hiding.fill(0), y.binding.fill(0), gr;
2053
- },
2054
- verifyShare(c, m, y, x, A) {
2055
- t.adjustPublic && (c = t.adjustPublic(c));
2056
- const j = m.find((Gt) => Gt.identifier === x);
2057
- if (!j) throw new Error("cannot find identifier commitment");
2058
- const L = F(c.verifyingShares[x]), P = F(j.hiding), k = F(j.binding), { lambda: G, challenge: mt, bindingFactor: tt, groupCommitment: ht } = rt(c.commitments[0], m, y, x);
2059
- let $ = P.add(k.multiply(tt));
2060
- t.adjustGroupCommitmentShare && ($ = t.adjustGroupCommitmentShare(ht, $));
2061
- const et = n.BASE.multiply(e.fromBytes(A)), pt = $.add(L.multiply(e.mul(mt, G)));
2062
- return et.equals(pt);
2063
- },
2064
- aggregate(c, m, y, x) {
2065
- t.adjustPublic && (c = t.adjustPublic(c));
2066
- try {
2067
- pn(c.signers, m.length);
2068
- } catch {
2069
- throw new ae("aggregation failed", []);
2070
- }
2071
- const A = m.map((k) => k.identifier);
2072
- if (A.length !== Object.keys(x).length) throw new ae("aggregation failed", []);
2073
- for (const k of A) if (!(k in x) || !(k in c.verifyingShares)) throw new ae("aggregation failed", []);
2074
- const j = F(c.commitments[0]), { groupCommitment: L } = nt(j, m, y);
2075
- let P = e.ZERO;
2076
- for (const k of A) P = e.add(P, e.fromBytes(x[k]));
2077
- if (!q.verify(y, L, P, j)) {
2078
- const k = [];
2079
- for (const G of A) this.verifyShare(c, m, y, G, x[G]) || k.push(G);
2080
- throw new ae("aggregation failed", k);
2081
- }
2082
- return M.encode(L, P);
2083
- },
2084
- sign(c, m) {
2085
- let y = e.fromBytes(m);
2086
- t.adjustScalar && (y = t.adjustScalar(y));
2087
- const [x, A] = q.sign(c, y);
2088
- return M.encode(x, A);
2089
- },
2090
- verify(c, m, y) {
2091
- const x = t.parsePublicKey ? t.parsePublicKey(y) : F(y), { R: A, z: j } = M.decode(c);
2092
- return q.verify(m, A, j, x);
2093
- },
2094
- combineSecret(c, m) {
2095
- if (fe(m), !Array.isArray(c) || c.length < m.min) throw new Error("wrong secret shares array");
2096
- const y = [], x = {};
2097
- for (const L of c) {
2098
- const P = K(L.identifier), k = V(P);
2099
- if (x[k]) throw new Error("duplicated id=" + k);
2100
- x[k] = !0, y.push([P, e.fromBytes(L.signingShare)]);
2101
- }
2102
- const A = y.map(([L]) => L);
2103
- let j = e.ZERO;
2104
- for (const [L, P] of y) j = e.add(j, e.mul(P, R(A, L)));
2105
- return e.toBytes(j);
2106
- },
2107
- utils: Object.freeze({
2108
- Fn: e,
2109
- randomScalar: (c = wt) => e.toBytes(v(c).scalar),
2110
- generateSecretPolynomial: (c, m, y, x) => {
2111
- const A = _(c, m, y, x);
2112
- return {
2113
- ...A,
2114
- commitment: A.commitment.map(O)
2115
- };
2116
- }
2117
- })
2118
- };
2119
- return Object.freeze(it);
2120
- }
2121
- Er();
2122
- Qt();
2123
- var En = (t, n) => (t + (t >= 0 ? n : -n) / Bt) / n;
2124
- function lo(t, n, e) {
2125
- Mn("scalar", t, yt, e);
2126
- const [[r, o], [i, a]] = n, f = En(a * t, e), l = En(-o * t, e);
2127
- let g = t - f * r - l * i, s = -f * o - l * a;
2128
- const u = g < yt, d = s < yt;
2129
- u && (g = -g), d && (s = -s);
2130
- const h = pe(Math.ceil(ye(e) / 2)) + ct;
2131
- if (g < yt || g >= h || s < yt || s >= h) throw new Error("splitScalar (endomorphism): failed for k");
1368
+ Ln();
1369
+ It();
1370
+ var De = (t, e) => (t + (t >= 0 ? e : -e) / _n) / e;
1371
+ function lr(t, e, r) {
1372
+ dn("scalar", t, ot, r);
1373
+ const [[n, o], [i, c]] = e, s = De(c * t, r), a = De(-o * t, r);
1374
+ let u = t - s * n - a * i, f = -s * o - a * c;
1375
+ const g = u < ot, m = f < ot;
1376
+ g && (u = -u), m && (f = -f);
1377
+ const w = Ee(Math.ceil(ye(r) / 2)) + ht;
1378
+ if (u < ot || u >= w || f < ot || f >= w) throw new Error("splitScalar (endomorphism): failed for k");
2132
1379
  return {
2133
- k1neg: u,
2134
- k1: g,
2135
- k2neg: d,
2136
- k2: s
1380
+ k1neg: g,
1381
+ k1: u,
1382
+ k2neg: m,
1383
+ k2: f
2137
1384
  };
2138
1385
  }
2139
- function ze(t) {
1386
+ function ae(t) {
2140
1387
  if (![
2141
1388
  "compact",
2142
1389
  "recovered",
@@ -2144,96 +1391,96 @@ function ze(t) {
2144
1391
  ].includes(t)) throw new Error('Signature format must be "compact", "recovered", or "der"');
2145
1392
  return t;
2146
1393
  }
2147
- function Te(t, n) {
2148
- Mt(t);
2149
- const e = {};
2150
- for (let r of Object.keys(n)) e[r] = t[r] === void 0 ? n[r] : t[r];
2151
- return ie(e.lowS, "lowS"), ie(e.prehash, "prehash"), e.format !== void 0 && ze(e.format), e;
1394
+ function Xt(t, e) {
1395
+ kt(t);
1396
+ const r = {};
1397
+ for (let n of Object.keys(e)) r[n] = t[n] === void 0 ? e[n] : t[n];
1398
+ return Ot(r.lowS, "lowS"), Ot(r.prehash, "prehash"), r.format !== void 0 && ae(r.format), r;
2152
1399
  }
2153
- var uo = class extends Error {
1400
+ var hr = class extends Error {
2154
1401
  constructor(t = "") {
2155
1402
  super(t);
2156
1403
  }
2157
- }, Et = {
2158
- Err: uo,
1404
+ }, et = {
1405
+ Err: hr,
2159
1406
  _tlv: {
2160
- encode: (t, n) => {
2161
- const { Err: e } = Et;
2162
- if (Ft(t, "tag"), t < 0 || t > 255) throw new e("tlv.encode: wrong tag");
2163
- if (typeof n != "string") throw new TypeError('"data" expected string, got type=' + typeof n);
2164
- if (n.length & 1) throw new e("tlv.encode: unpadded data");
2165
- const r = n.length / 2, o = ce(r);
2166
- if (o.length / 2 & 128) throw new e("tlv.encode: long form length too big");
2167
- const i = r > 127 ? ce(o.length / 2 | 128) : "";
2168
- return ce(t) + i + o + n;
1407
+ encode: (t, e) => {
1408
+ const { Err: r } = et;
1409
+ if (fe(t, "tag"), t < 0 || t > 255) throw new r("tlv.encode: wrong tag");
1410
+ if (typeof e != "string") throw new TypeError('"data" expected string, got type=' + typeof e);
1411
+ if (e.length & 1) throw new r("tlv.encode: unpadded data");
1412
+ const n = e.length / 2, o = Nt(n);
1413
+ if (o.length / 2 & 128) throw new r("tlv.encode: long form length too big");
1414
+ const i = n > 127 ? Nt(o.length / 2 | 128) : "";
1415
+ return Nt(t) + i + o + e;
2169
1416
  },
2170
- decode(t, n) {
2171
- const { Err: e } = Et;
2172
- n = st(n, void 0, "DER data");
2173
- let r = 0;
2174
- if (t < 0 || t > 255) throw new e("tlv.encode: wrong tag");
2175
- if (n.length < 2 || n[r++] !== t) throw new e("tlv.decode: wrong tlv");
2176
- const o = n[r++], i = !!(o & 128);
2177
- let a = 0;
2178
- if (!i) a = o;
1417
+ decode(t, e) {
1418
+ const { Err: r } = et;
1419
+ e = W(e, void 0, "DER data");
1420
+ let n = 0;
1421
+ if (t < 0 || t > 255) throw new r("tlv.encode: wrong tag");
1422
+ if (e.length < 2 || e[n++] !== t) throw new r("tlv.decode: wrong tlv");
1423
+ const o = e[n++], i = !!(o & 128);
1424
+ let c = 0;
1425
+ if (!i) c = o;
2179
1426
  else {
2180
- const l = o & 127;
2181
- if (!l) throw new e("tlv.decode(long): indefinite length not supported");
2182
- if (l > 4) throw new e("tlv.decode(long): byte length is too big");
2183
- const g = n.subarray(r, r + l);
2184
- if (g.length !== l) throw new e("tlv.decode: length bytes not complete");
2185
- if (g[0] === 0) throw new e("tlv.decode(long): zero leftmost byte");
2186
- for (const s of g) a = a << 8 | s;
2187
- if (r += l, a < 128) throw new e("tlv.decode(long): not minimal encoding");
1427
+ const a = o & 127;
1428
+ if (!a) throw new r("tlv.decode(long): indefinite length not supported");
1429
+ if (a > 4) throw new r("tlv.decode(long): byte length is too big");
1430
+ const u = e.subarray(n, n + a);
1431
+ if (u.length !== a) throw new r("tlv.decode: length bytes not complete");
1432
+ if (u[0] === 0) throw new r("tlv.decode(long): zero leftmost byte");
1433
+ for (const f of u) c = c << 8 | f;
1434
+ if (n += a, c < 128) throw new r("tlv.decode(long): not minimal encoding");
2188
1435
  }
2189
- const f = n.subarray(r, r + a);
2190
- if (f.length !== a) throw new e("tlv.decode: wrong value length");
1436
+ const s = e.subarray(n, n + c);
1437
+ if (s.length !== c) throw new r("tlv.decode: wrong value length");
2191
1438
  return {
2192
- v: f,
2193
- l: n.subarray(r + a)
1439
+ v: s,
1440
+ l: e.subarray(n + c)
2194
1441
  };
2195
1442
  }
2196
1443
  },
2197
1444
  _int: {
2198
1445
  encode(t) {
2199
- const { Err: n } = Et;
2200
- if (Je(t), t < yt) throw new n("integer: negative integers are not allowed");
2201
- let e = ce(t);
2202
- if (Number.parseInt(e[0], 16) & 8 && (e = "00" + e), e.length & 1) throw new n("unexpected DER parsing assertion: unpadded hex");
2203
- return e;
1446
+ const { Err: e } = et;
1447
+ if (we(t), t < ot) throw new e("integer: negative integers are not allowed");
1448
+ let r = Nt(t);
1449
+ if (Number.parseInt(r[0], 16) & 8 && (r = "00" + r), r.length & 1) throw new e("unexpected DER parsing assertion: unpadded hex");
1450
+ return r;
2204
1451
  },
2205
1452
  decode(t) {
2206
- const { Err: n } = Et;
2207
- if (t.length < 1) throw new n("invalid signature integer: empty");
2208
- if (t[0] & 128) throw new n("invalid signature integer: negative");
2209
- if (t.length > 1 && t[0] === 0 && !(t[1] & 128)) throw new n("invalid signature integer: unnecessary leading zero");
2210
- return St(t);
1453
+ const { Err: e } = et;
1454
+ if (t.length < 1) throw new e("invalid signature integer: empty");
1455
+ if (t[0] & 128) throw new e("invalid signature integer: negative");
1456
+ if (t.length > 1 && t[0] === 0 && !(t[1] & 128)) throw new e("invalid signature integer: unnecessary leading zero");
1457
+ return Ct(t);
2211
1458
  }
2212
1459
  },
2213
1460
  toSig(t) {
2214
- const { Err: n, _int: e, _tlv: r } = Et, o = st(t, void 0, "signature"), { v: i, l: a } = r.decode(48, o);
2215
- if (a.length) throw new n("invalid signature: left bytes after parsing");
2216
- const { v: f, l } = r.decode(2, i), { v: g, l: s } = r.decode(2, l);
2217
- if (s.length) throw new n("invalid signature: left bytes after parsing");
1461
+ const { Err: e, _int: r, _tlv: n } = et, o = W(t, void 0, "signature"), { v: i, l: c } = n.decode(48, o);
1462
+ if (c.length) throw new e("invalid signature: left bytes after parsing");
1463
+ const { v: s, l: a } = n.decode(2, i), { v: u, l: f } = n.decode(2, a);
1464
+ if (f.length) throw new e("invalid signature: left bytes after parsing");
2218
1465
  return {
2219
- r: e.decode(f),
2220
- s: e.decode(g)
1466
+ r: r.decode(s),
1467
+ s: r.decode(u)
2221
1468
  };
2222
1469
  },
2223
1470
  hexFromSig(t) {
2224
- const { _tlv: n, _int: e } = Et, r = n.encode(2, e.encode(t.r)) + n.encode(2, e.encode(t.s));
2225
- return n.encode(48, r);
1471
+ const { _tlv: e, _int: r } = et, n = e.encode(2, r.encode(t.r)) + e.encode(2, r.encode(t.s));
1472
+ return e.encode(48, n);
2226
1473
  }
2227
1474
  };
2228
- Object.freeze(Et._tlv);
2229
- Object.freeze(Et._int);
2230
- Object.freeze(Et);
2231
- var yt = /* @__PURE__ */ BigInt(0), ct = /* @__PURE__ */ BigInt(1), Bt = /* @__PURE__ */ BigInt(2), Xt = /* @__PURE__ */ BigInt(3), Me = /* @__PURE__ */ BigInt(4);
2232
- function ho(t, n = {}) {
2233
- const e = Jr("weierstrass", t, n), r = e.Fp, o = e.Fn;
2234
- let i = e.CURVE;
2235
- const { h: a, n: f } = i;
2236
- Mt(n, {}, {
1475
+ Object.freeze(et._tlv);
1476
+ Object.freeze(et._int);
1477
+ Object.freeze(et);
1478
+ var ot = /* @__PURE__ */ BigInt(0), ht = /* @__PURE__ */ BigInt(1), _n = /* @__PURE__ */ BigInt(2), Tt = /* @__PURE__ */ BigInt(3), dr = /* @__PURE__ */ BigInt(4);
1479
+ function gr(t, e = {}) {
1480
+ const r = ar("weierstrass", t, e), n = r.Fp, o = r.Fn;
1481
+ let i = r.CURVE;
1482
+ const { h: c, n: s } = i;
1483
+ kt(e, {}, {
2237
1484
  allowInfinityPoint: "boolean",
2238
1485
  clearCofactor: "function",
2239
1486
  isTorsionFree: "function",
@@ -2241,103 +1488,103 @@ function ho(t, n = {}) {
2241
1488
  toBytes: "function",
2242
1489
  endo: "object"
2243
1490
  });
2244
- const { endo: l, allowInfinityPoint: g } = n;
2245
- if (l && (!r.is0(i.a) || typeof l.beta != "bigint" || !Array.isArray(l.basises)))
1491
+ const { endo: a, allowInfinityPoint: u } = e;
1492
+ if (a && (!n.is0(i.a) || typeof a.beta != "bigint" || !Array.isArray(a.basises)))
2246
1493
  throw new Error('invalid endo: expected "beta": bigint and "basises": array');
2247
- const s = ar(r, o);
2248
- function u() {
2249
- if (!r.isOdd) throw new Error("compression is not supported: Field does not have .isOdd()");
2250
- }
2251
- function d(M, v, H) {
2252
- if (g && v.is0()) return Uint8Array.of(0);
2253
- const { x: U, y: S } = v.toAffine(), p = r.toBytes(U);
2254
- return ie(H, "isCompressed"), H ? (u(), Q(fr(!r.isOdd(S)), p)) : Q(Uint8Array.of(4), p, r.toBytes(S));
2255
- }
2256
- function h(M) {
2257
- st(M, void 0, "Point");
2258
- const { publicKey: v, publicKeyUncompressed: H } = s, U = M.length, S = M[0], p = M.subarray(1);
2259
- if (g && U === 1 && S === 0) return {
2260
- x: r.ZERO,
2261
- y: r.ZERO
1494
+ const f = On(n, o);
1495
+ function g() {
1496
+ if (!n.isOdd) throw new Error("compression is not supported: Field does not have .isOdd()");
1497
+ }
1498
+ function m(F, h, y) {
1499
+ if (u && h.is0()) return Uint8Array.of(0);
1500
+ const { x: B, y: d } = h.toAffine(), l = n.toBytes(B);
1501
+ return Ot(y, "isCompressed"), y ? (g(), lt(Hn(!n.isOdd(d)), l)) : lt(Uint8Array.of(4), l, n.toBytes(d));
1502
+ }
1503
+ function w(F) {
1504
+ W(F, void 0, "Point");
1505
+ const { publicKey: h, publicKeyUncompressed: y } = f, B = F.length, d = F[0], l = F.subarray(1);
1506
+ if (u && B === 1 && d === 0) return {
1507
+ x: n.ZERO,
1508
+ y: n.ZERO
2262
1509
  };
2263
- if (U === v && (S === 2 || S === 3)) {
2264
- const R = r.fromBytes(p);
2265
- if (!r.isValid(R)) throw new Error("bad point: is not on curve, wrong x");
2266
- const I = E(R);
2267
- let _;
1510
+ if (B === h && (d === 2 || d === 3)) {
1511
+ const b = n.fromBytes(l);
1512
+ if (!n.isValid(b)) throw new Error("bad point: is not on curve, wrong x");
1513
+ const E = H(b);
1514
+ let p;
2268
1515
  try {
2269
- _ = r.sqrt(I);
2270
- } catch (q) {
2271
- const X = q instanceof Error ? ": " + q.message : "";
2272
- throw new Error("bad point: is not on curve, sqrt error" + X);
1516
+ p = n.sqrt(E);
1517
+ } catch (S) {
1518
+ const N = S instanceof Error ? ": " + S.message : "";
1519
+ throw new Error("bad point: is not on curve, sqrt error" + N);
2273
1520
  }
2274
- u();
2275
- const D = r.isOdd(_);
2276
- return (S & 1) === 1 !== D && (_ = r.neg(_)), {
2277
- x: R,
2278
- y: _
1521
+ g();
1522
+ const v = n.isOdd(p);
1523
+ return (d & 1) === 1 !== v && (p = n.neg(p)), {
1524
+ x: b,
1525
+ y: p
2279
1526
  };
2280
- } else if (U === H && S === 4) {
2281
- const R = r.BYTES, I = r.fromBytes(p.subarray(0, R)), _ = r.fromBytes(p.subarray(R, R * 2));
2282
- if (!T(I, _)) throw new Error("bad point: is not on curve");
1527
+ } else if (B === y && d === 4) {
1528
+ const b = n.BYTES, E = n.fromBytes(l.subarray(0, b)), p = n.fromBytes(l.subarray(b, b * 2));
1529
+ if (!O(E, p)) throw new Error("bad point: is not on curve");
2283
1530
  return {
2284
- x: I,
2285
- y: _
1531
+ x: E,
1532
+ y: p
2286
1533
  };
2287
- } else throw new Error(`bad point: got length ${U}, expected compressed=${v} or uncompressed=${H}`);
2288
- }
2289
- const w = n.toBytes === void 0 ? d : n.toBytes, b = n.fromBytes === void 0 ? h : n.fromBytes;
2290
- function E(M) {
2291
- const v = r.sqr(M), H = r.mul(v, M);
2292
- return r.add(r.add(H, r.mul(M, i.a)), i.b);
2293
- }
2294
- function T(M, v) {
2295
- const H = r.sqr(v), U = E(M);
2296
- return r.eql(H, U);
2297
- }
2298
- if (!T(i.Gx, i.Gy)) throw new Error("bad curve params: generator point");
2299
- const B = r.mul(r.pow(i.a, Xt), Me), C = r.mul(r.sqr(i.b), BigInt(27));
2300
- if (r.is0(r.add(B, C))) throw new Error("bad curve params: a or b");
2301
- function O(M, v, H = !1) {
2302
- if (!r.isValid(v) || H && r.is0(v)) throw new Error(`bad point coordinate ${M}`);
2303
- return v;
2304
- }
2305
- function F(M) {
2306
- if (!(M instanceof N)) throw new Error("Weierstrass Point expected");
2307
- }
2308
- function z(M) {
2309
- if (!l || !l.basises) throw new Error("no endo");
2310
- return lo(M, l.basises, o.ORDER);
2311
- }
2312
- function W(M, v, H, U, S) {
2313
- return H = new N(r.mul(H.X, M), H.Y, H.Z), v = we(U, v), H = we(S, H), v.add(H);
2314
- }
2315
- class N {
2316
- static BASE = new N(i.Gx, i.Gy, r.ONE);
2317
- static ZERO = new N(r.ZERO, r.ONE, r.ZERO);
2318
- static Fp = r;
1534
+ } else throw new Error(`bad point: got length ${B}, expected compressed=${h} or uncompressed=${y}`);
1535
+ }
1536
+ const A = e.toBytes === void 0 ? m : e.toBytes, _ = e.fromBytes === void 0 ? w : e.fromBytes;
1537
+ function H(F) {
1538
+ const h = n.sqr(F), y = n.mul(h, F);
1539
+ return n.add(n.add(y, n.mul(F, i.a)), i.b);
1540
+ }
1541
+ function O(F, h) {
1542
+ const y = n.sqr(h), B = H(F);
1543
+ return n.eql(y, B);
1544
+ }
1545
+ if (!O(i.Gx, i.Gy)) throw new Error("bad curve params: generator point");
1546
+ const x = n.mul(n.pow(i.a, Tt), dr), q = n.mul(n.sqr(i.b), BigInt(27));
1547
+ if (n.is0(n.add(x, q))) throw new Error("bad curve params: a or b");
1548
+ function Z(F, h, y = !1) {
1549
+ if (!n.isValid(h) || y && n.is0(h)) throw new Error(`bad point coordinate ${F}`);
1550
+ return h;
1551
+ }
1552
+ function T(F) {
1553
+ if (!(F instanceof R)) throw new Error("Weierstrass Point expected");
1554
+ }
1555
+ function Q(F) {
1556
+ if (!a || !a.basises) throw new Error("no endo");
1557
+ return lr(F, a.basises, o.ORDER);
1558
+ }
1559
+ function $(F, h, y, B, d) {
1560
+ return y = new R(n.mul(y.X, F), y.Y, y.Z), h = Zt(B, h), y = Zt(d, y), h.add(y);
1561
+ }
1562
+ class R {
1563
+ static BASE = new R(i.Gx, i.Gy, n.ONE);
1564
+ static ZERO = new R(n.ZERO, n.ONE, n.ZERO);
1565
+ static Fp = n;
2319
1566
  static Fn = o;
2320
1567
  X;
2321
1568
  Y;
2322
1569
  Z;
2323
- constructor(v, H, U) {
2324
- this.X = O("x", v), this.Y = O("y", H, !0), this.Z = O("z", U), Object.freeze(this);
1570
+ constructor(h, y, B) {
1571
+ this.X = Z("x", h), this.Y = Z("y", y, !0), this.Z = Z("z", B), Object.freeze(this);
2325
1572
  }
2326
1573
  static CURVE() {
2327
1574
  return i;
2328
1575
  }
2329
- static fromAffine(v) {
2330
- const { x: H, y: U } = v || {};
2331
- if (!v || !r.isValid(H) || !r.isValid(U)) throw new Error("invalid affine point");
2332
- if (v instanceof N) throw new Error("projective point not allowed");
2333
- return r.is0(H) && r.is0(U) ? N.ZERO : new N(H, U, r.ONE);
1576
+ static fromAffine(h) {
1577
+ const { x: y, y: B } = h || {};
1578
+ if (!h || !n.isValid(y) || !n.isValid(B)) throw new Error("invalid affine point");
1579
+ if (h instanceof R) throw new Error("projective point not allowed");
1580
+ return n.is0(y) && n.is0(B) ? R.ZERO : new R(y, B, n.ONE);
2334
1581
  }
2335
- static fromBytes(v) {
2336
- const H = N.fromAffine(b(st(v, void 0, "point")));
2337
- return H.assertValidity(), H;
1582
+ static fromBytes(h) {
1583
+ const y = R.fromAffine(_(W(h, void 0, "point")));
1584
+ return y.assertValidity(), y;
2338
1585
  }
2339
- static fromHex(v) {
2340
- return N.fromBytes(he(v));
1586
+ static fromHex(h) {
1587
+ return R.fromBytes(se(h));
2341
1588
  }
2342
1589
  get x() {
2343
1590
  return this.toAffine().x;
@@ -2345,420 +1592,354 @@ function ho(t, n = {}) {
2345
1592
  get y() {
2346
1593
  return this.toAffine().y;
2347
1594
  }
2348
- precompute(v = 8, H = !0) {
2349
- return K.createCache(this, v), H || this.multiply(Xt), this;
1595
+ precompute(h = 8, y = !0) {
1596
+ return X.createCache(this, h), y || this.multiply(Tt), this;
2350
1597
  }
2351
1598
  assertValidity() {
2352
- const v = this;
2353
- if (v.is0()) {
2354
- if (n.allowInfinityPoint && r.is0(v.X) && r.eql(v.Y, r.ONE) && r.is0(v.Z)) return;
1599
+ const h = this;
1600
+ if (h.is0()) {
1601
+ if (e.allowInfinityPoint && n.is0(h.X) && n.eql(h.Y, n.ONE) && n.is0(h.Z)) return;
2355
1602
  throw new Error("bad point: ZERO");
2356
1603
  }
2357
- const { x: H, y: U } = v.toAffine();
2358
- if (!r.isValid(H) || !r.isValid(U)) throw new Error("bad point: x or y not field elements");
2359
- if (!T(H, U)) throw new Error("bad point: equation left != right");
2360
- if (!v.isTorsionFree()) throw new Error("bad point: not in prime-order subgroup");
1604
+ const { x: y, y: B } = h.toAffine();
1605
+ if (!n.isValid(y) || !n.isValid(B)) throw new Error("bad point: x or y not field elements");
1606
+ if (!O(y, B)) throw new Error("bad point: equation left != right");
1607
+ if (!h.isTorsionFree()) throw new Error("bad point: not in prime-order subgroup");
2361
1608
  }
2362
1609
  hasEvenY() {
2363
- const { y: v } = this.toAffine();
2364
- if (!r.isOdd) throw new Error("Field doesn't support isOdd");
2365
- return !r.isOdd(v);
1610
+ const { y: h } = this.toAffine();
1611
+ if (!n.isOdd) throw new Error("Field doesn't support isOdd");
1612
+ return !n.isOdd(h);
2366
1613
  }
2367
- equals(v) {
2368
- F(v);
2369
- const { X: H, Y: U, Z: S } = this, { X: p, Y: R, Z: I } = v, _ = r.eql(r.mul(H, I), r.mul(p, S)), D = r.eql(r.mul(U, I), r.mul(R, S));
2370
- return _ && D;
1614
+ equals(h) {
1615
+ T(h);
1616
+ const { X: y, Y: B, Z: d } = this, { X: l, Y: b, Z: E } = h, p = n.eql(n.mul(y, E), n.mul(l, d)), v = n.eql(n.mul(B, E), n.mul(b, d));
1617
+ return p && v;
2371
1618
  }
2372
1619
  negate() {
2373
- return new N(this.X, r.neg(this.Y), this.Z);
1620
+ return new R(this.X, n.neg(this.Y), this.Z);
2374
1621
  }
2375
1622
  double() {
2376
- const { a: v, b: H } = i, U = r.mul(H, Xt), { X: S, Y: p, Z: R } = this;
2377
- let I = r.ZERO, _ = r.ZERO, D = r.ZERO, q = r.mul(S, S), X = r.mul(p, p), Y = r.mul(R, R), Z = r.mul(S, p);
2378
- return Z = r.add(Z, Z), D = r.mul(S, R), D = r.add(D, D), I = r.mul(v, D), _ = r.mul(U, Y), _ = r.add(I, _), I = r.sub(X, _), _ = r.add(X, _), _ = r.mul(I, _), I = r.mul(Z, I), D = r.mul(U, D), Y = r.mul(v, Y), Z = r.sub(q, Y), Z = r.mul(v, Z), Z = r.add(Z, D), D = r.add(q, q), q = r.add(D, q), q = r.add(q, Y), q = r.mul(q, Z), _ = r.add(_, q), Y = r.mul(p, R), Y = r.add(Y, Y), q = r.mul(Y, Z), I = r.sub(I, q), D = r.mul(Y, X), D = r.add(D, D), D = r.add(D, D), new N(I, _, D);
2379
- }
2380
- add(v) {
2381
- F(v);
2382
- const { X: H, Y: U, Z: S } = this, { X: p, Y: R, Z: I } = v;
2383
- let _ = r.ZERO, D = r.ZERO, q = r.ZERO;
2384
- const X = i.a, Y = r.mul(i.b, Xt);
2385
- let Z = r.mul(H, p), nt = r.mul(U, R), rt = r.mul(S, I), it = r.add(H, U), c = r.add(p, R);
2386
- it = r.mul(it, c), c = r.add(Z, nt), it = r.sub(it, c), c = r.add(H, S);
2387
- let m = r.add(p, I);
2388
- return c = r.mul(c, m), m = r.add(Z, rt), c = r.sub(c, m), m = r.add(U, S), _ = r.add(R, I), m = r.mul(m, _), _ = r.add(nt, rt), m = r.sub(m, _), q = r.mul(X, c), _ = r.mul(Y, rt), q = r.add(_, q), _ = r.sub(nt, q), q = r.add(nt, q), D = r.mul(_, q), nt = r.add(Z, Z), nt = r.add(nt, Z), rt = r.mul(X, rt), c = r.mul(Y, c), nt = r.add(nt, rt), rt = r.sub(Z, rt), rt = r.mul(X, rt), c = r.add(c, rt), Z = r.mul(nt, c), D = r.add(D, Z), Z = r.mul(m, c), _ = r.mul(it, _), _ = r.sub(_, Z), Z = r.mul(it, nt), q = r.mul(m, q), q = r.add(q, Z), new N(_, D, q);
2389
- }
2390
- subtract(v) {
2391
- return F(v), this.add(v.negate());
1623
+ const { a: h, b: y } = i, B = n.mul(y, Tt), { X: d, Y: l, Z: b } = this;
1624
+ let E = n.ZERO, p = n.ZERO, v = n.ZERO, S = n.mul(d, d), N = n.mul(l, l), L = n.mul(b, b), I = n.mul(d, l);
1625
+ return I = n.add(I, I), v = n.mul(d, b), v = n.add(v, v), E = n.mul(h, v), p = n.mul(B, L), p = n.add(E, p), E = n.sub(N, p), p = n.add(N, p), p = n.mul(E, p), E = n.mul(I, E), v = n.mul(B, v), L = n.mul(h, L), I = n.sub(S, L), I = n.mul(h, I), I = n.add(I, v), v = n.add(S, S), S = n.add(v, S), S = n.add(S, L), S = n.mul(S, I), p = n.add(p, S), L = n.mul(l, b), L = n.add(L, L), S = n.mul(L, I), E = n.sub(E, S), v = n.mul(L, N), v = n.add(v, v), v = n.add(v, v), new R(E, p, v);
1626
+ }
1627
+ add(h) {
1628
+ T(h);
1629
+ const { X: y, Y: B, Z: d } = this, { X: l, Y: b, Z: E } = h;
1630
+ let p = n.ZERO, v = n.ZERO, S = n.ZERO;
1631
+ const N = i.a, L = n.mul(i.b, Tt);
1632
+ let I = n.mul(y, l), k = n.mul(B, b), j = n.mul(d, E), V = n.add(y, B), U = n.add(l, b);
1633
+ V = n.mul(V, U), U = n.add(I, k), V = n.sub(V, U), U = n.add(y, d);
1634
+ let J = n.add(l, E);
1635
+ return U = n.mul(U, J), J = n.add(I, j), U = n.sub(U, J), J = n.add(B, d), p = n.add(b, E), J = n.mul(J, p), p = n.add(k, j), J = n.sub(J, p), S = n.mul(N, U), p = n.mul(L, j), S = n.add(p, S), p = n.sub(k, S), S = n.add(k, S), v = n.mul(p, S), k = n.add(I, I), k = n.add(k, I), j = n.mul(N, j), U = n.mul(L, U), k = n.add(k, j), j = n.sub(I, j), j = n.mul(N, j), U = n.add(U, j), I = n.mul(k, U), v = n.add(v, I), I = n.mul(J, U), p = n.mul(V, p), p = n.sub(p, I), I = n.mul(V, k), S = n.mul(J, S), S = n.add(S, I), new R(p, v, S);
1636
+ }
1637
+ subtract(h) {
1638
+ return T(h), this.add(h.negate());
2392
1639
  }
2393
1640
  is0() {
2394
- return this.equals(N.ZERO);
2395
- }
2396
- multiply(v) {
2397
- const { endo: H } = n;
2398
- if (!o.isValidNot0(v)) throw new RangeError("invalid scalar: out of range");
2399
- let U, S;
2400
- const p = (R) => K.cached(this, R, (I) => gn(N, I));
2401
- if (H) {
2402
- const { k1neg: R, k1: I, k2neg: _, k2: D } = z(v), { p: q, f: X } = p(I), { p: Y, f: Z } = p(D);
2403
- S = X.add(Z), U = W(H.beta, q, Y, R, _);
1641
+ return this.equals(R.ZERO);
1642
+ }
1643
+ multiply(h) {
1644
+ const { endo: y } = e;
1645
+ if (!o.isValidNot0(h)) throw new RangeError("invalid scalar: out of range");
1646
+ let B, d;
1647
+ const l = (b) => X.cached(this, b, (E) => Ne(R, E));
1648
+ if (y) {
1649
+ const { k1neg: b, k1: E, k2neg: p, k2: v } = Q(h), { p: S, f: N } = l(E), { p: L, f: I } = l(v);
1650
+ d = N.add(I), B = $(y.beta, S, L, b, p);
2404
1651
  } else {
2405
- const { p: R, f: I } = p(v);
2406
- U = R, S = I;
1652
+ const { p: b, f: E } = l(h);
1653
+ B = b, d = E;
2407
1654
  }
2408
- return gn(N, [U, S])[0];
2409
- }
2410
- multiplyUnsafe(v) {
2411
- const { endo: H } = n, U = this, S = v;
2412
- if (!o.isValid(S)) throw new RangeError("invalid scalar: out of range");
2413
- if (S === yt || U.is0()) return N.ZERO;
2414
- if (S === ct) return U;
2415
- if (K.hasCache(this)) return this.multiply(S);
2416
- if (H) {
2417
- const { k1neg: p, k1: R, k2neg: I, k2: _ } = z(S), { p1: D, p2: q } = Wr(N, U, R, _);
2418
- return W(H.beta, D, q, p, I);
2419
- } else return K.unsafe(U, S);
2420
- }
2421
- toAffine(v) {
2422
- const H = this;
2423
- let U = v;
2424
- const { X: S, Y: p, Z: R } = H;
2425
- if (r.eql(R, r.ONE)) return {
2426
- x: S,
2427
- y: p
1655
+ return Ne(R, [B, d])[0];
1656
+ }
1657
+ multiplyUnsafe(h) {
1658
+ const { endo: y } = e, B = this, d = h;
1659
+ if (!o.isValid(d)) throw new RangeError("invalid scalar: out of range");
1660
+ if (d === ot || B.is0()) return R.ZERO;
1661
+ if (d === ht) return B;
1662
+ if (X.hasCache(this)) return this.multiply(d);
1663
+ if (y) {
1664
+ const { k1neg: l, k1: b, k2neg: E, k2: p } = Q(d), { p1: v, p2: S } = fr(R, B, b, p);
1665
+ return $(y.beta, v, S, l, E);
1666
+ } else return X.unsafe(B, d);
1667
+ }
1668
+ toAffine(h) {
1669
+ const y = this;
1670
+ let B = h;
1671
+ const { X: d, Y: l, Z: b } = y;
1672
+ if (n.eql(b, n.ONE)) return {
1673
+ x: d,
1674
+ y: l
2428
1675
  };
2429
- const I = H.is0();
2430
- U == null && (U = I ? r.ONE : r.inv(R));
2431
- const _ = r.mul(S, U), D = r.mul(p, U), q = r.mul(R, U);
2432
- if (I) return {
2433
- x: r.ZERO,
2434
- y: r.ZERO
1676
+ const E = y.is0();
1677
+ B == null && (B = E ? n.ONE : n.inv(b));
1678
+ const p = n.mul(d, B), v = n.mul(l, B), S = n.mul(b, B);
1679
+ if (E) return {
1680
+ x: n.ZERO,
1681
+ y: n.ZERO
2435
1682
  };
2436
- if (!r.eql(q, r.ONE)) throw new Error("invZ was invalid");
1683
+ if (!n.eql(S, n.ONE)) throw new Error("invZ was invalid");
2437
1684
  return {
2438
- x: _,
2439
- y: D
1685
+ x: p,
1686
+ y: v
2440
1687
  };
2441
1688
  }
2442
1689
  isTorsionFree() {
2443
- const { isTorsionFree: v } = n;
2444
- return a === ct ? !0 : v ? v(N, this) : K.unsafe(this, f).is0();
1690
+ const { isTorsionFree: h } = e;
1691
+ return c === ht ? !0 : h ? h(R, this) : X.unsafe(this, s).is0();
2445
1692
  }
2446
1693
  clearCofactor() {
2447
- const { clearCofactor: v } = n;
2448
- return a === ct ? this : v ? v(N, this) : this.multiplyUnsafe(a);
1694
+ const { clearCofactor: h } = e;
1695
+ return c === ht ? this : h ? h(R, this) : this.multiplyUnsafe(c);
2449
1696
  }
2450
1697
  isSmallOrder() {
2451
- return a === ct ? this.is0() : this.clearCofactor().is0();
1698
+ return c === ht ? this.is0() : this.clearCofactor().is0();
2452
1699
  }
2453
- toBytes(v = !0) {
2454
- return ie(v, "isCompressed"), this.assertValidity(), w(N, this, v);
1700
+ toBytes(h = !0) {
1701
+ return Ot(h, "isCompressed"), this.assertValidity(), A(R, this, h);
2455
1702
  }
2456
- toHex(v = !0) {
2457
- return Ct(this.toBytes(v));
1703
+ toHex(h = !0) {
1704
+ return cn(this.toBytes(h));
2458
1705
  }
2459
1706
  toString() {
2460
1707
  return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
2461
1708
  }
2462
1709
  }
2463
- const V = o.BITS, K = new Xr(N, n.endo ? Math.ceil(V / 2) : V);
2464
- return V >= 8 && N.BASE.precompute(8), Object.freeze(N.prototype), Object.freeze(N), N;
1710
+ const C = o.BITS, X = new cr(R, e.endo ? Math.ceil(C / 2) : C);
1711
+ return C >= 8 && R.BASE.precompute(8), Object.freeze(R.prototype), Object.freeze(R), R;
2465
1712
  }
2466
- function fr(t) {
1713
+ function Hn(t) {
2467
1714
  return Uint8Array.of(t ? 2 : 3);
2468
1715
  }
2469
- function mo(t, n) {
2470
- const e = se(t), r = e.ORDER;
2471
- let o = yt;
2472
- for (let b = r - ct; b % Bt === yt; b /= Bt) o += ct;
2473
- const i = o, a = Bt << i - ct - ct, f = a * Bt, l = (r - ct) / f, g = (l - ct) / Bt, s = f - ct, u = a, d = e.pow(n, l), h = e.pow(n, (l + ct) / Bt);
2474
- let w = (b, E) => {
2475
- let T = d, B = e.pow(E, s), C = e.sqr(B);
2476
- C = e.mul(C, E);
2477
- let O = e.mul(b, C);
2478
- O = e.pow(O, g), O = e.mul(O, B), B = e.mul(O, E), C = e.mul(O, b);
2479
- let F = e.mul(C, B);
2480
- O = e.pow(F, u);
2481
- let z = e.eql(O, e.ONE);
2482
- B = e.mul(C, h), O = e.mul(F, T), C = e.cmov(B, C, z), F = e.cmov(O, F, z);
2483
- for (let W = i; W > ct; W--) {
2484
- let N = W - Bt;
2485
- N = Bt << N - ct;
2486
- let V = e.pow(F, N);
2487
- const K = e.eql(V, e.ONE);
2488
- B = e.mul(C, T), T = e.mul(T, T), V = e.mul(F, T), C = e.cmov(B, C, K), F = e.cmov(V, F, K);
2489
- }
2490
- return {
2491
- isValid: !e.is0(E) && (z || e.is0(b)),
2492
- value: C
2493
- };
2494
- };
2495
- if (e.ORDER % Me === Xt) {
2496
- const b = (e.ORDER - Xt) / Me, E = e.sqrt(e.neg(n));
2497
- w = (T, B) => {
2498
- let C = e.sqr(B);
2499
- const O = e.mul(T, B);
2500
- C = e.mul(C, O);
2501
- let F = e.pow(C, b);
2502
- F = e.mul(F, O);
2503
- const z = e.mul(F, E), W = e.mul(e.sqr(F), B), N = e.eql(W, T);
2504
- let V = e.cmov(z, F, N);
2505
- return {
2506
- isValid: !e.is0(B) && N,
2507
- value: V
2508
- };
2509
- };
2510
- }
2511
- return w;
2512
- }
2513
- function go(t, n) {
2514
- const e = se(t), { A: r, B: o, Z: i } = n;
2515
- if (!e.isValidNot0(r) || !e.isValidNot0(o) || !e.isValid(i)) throw new Error("mapToCurveSimpleSWU: invalid opts");
2516
- if (e.eql(i, e.neg(e.ONE)) || hn(e, i)) throw new Error("mapToCurveSimpleSWU: invalid opts");
2517
- const a = e.mul(o, e.inv(e.mul(i, r)));
2518
- if (!hn(e, e.add(e.add(e.mul(e.sqr(a), a), e.mul(r, a)), o))) throw new Error("mapToCurveSimpleSWU: invalid opts");
2519
- const f = mo(e, i);
2520
- if (!e.isOdd) throw new Error("Field does not have .isOdd()");
2521
- return (l) => {
2522
- let g, s, u, d, h, w, b, E;
2523
- g = e.sqr(l), g = e.mul(g, i), s = e.sqr(g), s = e.add(s, g), u = e.add(s, e.ONE), u = e.mul(u, o), d = e.cmov(i, e.neg(s), !e.eql(s, e.ZERO)), d = e.mul(d, r), s = e.sqr(u), w = e.sqr(d), h = e.mul(w, r), s = e.add(s, h), s = e.mul(s, u), w = e.mul(w, d), h = e.mul(w, o), s = e.add(s, h), b = e.mul(g, u);
2524
- const { isValid: T, value: B } = f(s, w);
2525
- E = e.mul(g, l), E = e.mul(E, B), b = e.cmov(b, u, T), E = e.cmov(E, B, T);
2526
- const C = e.isOdd(l) === e.isOdd(E);
2527
- E = e.cmov(e.neg(E), E, C);
2528
- const O = Ee(e, [d], !0)[0];
2529
- return b = e.mul(b, O), {
2530
- x: b,
2531
- y: E
2532
- };
2533
- };
2534
- }
2535
- function ar(t, n) {
1716
+ function On(t, e) {
2536
1717
  return {
2537
- secretKey: n.BYTES,
1718
+ secretKey: e.BYTES,
2538
1719
  publicKey: 1 + t.BYTES,
2539
1720
  publicKeyUncompressed: 1 + 2 * t.BYTES,
2540
1721
  publicKeyHasPrefix: !0,
2541
- signature: 2 * n.BYTES
1722
+ signature: 2 * e.BYTES
2542
1723
  };
2543
1724
  }
2544
- function wo(t, n = {}) {
2545
- const { Fn: e } = t, r = n.randomBytes === void 0 ? wt : n.randomBytes, o = Object.assign(ar(t.Fp, e), { seed: Math.max(nn(e.ORDER), 16) });
2546
- function i(h) {
1725
+ function br(t, e = {}) {
1726
+ const { Fn: r } = t, n = e.randomBytes === void 0 ? an : e.randomBytes, o = Object.assign(On(t.Fp, r), { seed: Math.max(An(r.ORDER), 16) });
1727
+ function i(w) {
2547
1728
  try {
2548
- const w = e.fromBytes(h);
2549
- return e.isValidNot0(w);
1729
+ const A = r.fromBytes(w);
1730
+ return r.isValidNot0(A);
2550
1731
  } catch {
2551
1732
  return !1;
2552
1733
  }
2553
1734
  }
2554
- function a(h, w) {
2555
- const { publicKey: b, publicKeyUncompressed: E } = o;
1735
+ function c(w, A) {
1736
+ const { publicKey: _, publicKeyUncompressed: H } = o;
2556
1737
  try {
2557
- const T = h.length;
2558
- return w === !0 && T !== b || w === !1 && T !== E ? !1 : !!t.fromBytes(h);
1738
+ const O = w.length;
1739
+ return A === !0 && O !== _ || A === !1 && O !== H ? !1 : !!t.fromBytes(w);
2559
1740
  } catch {
2560
1741
  return !1;
2561
1742
  }
2562
1743
  }
2563
- function f(h) {
2564
- return h = h === void 0 ? r(o.seed) : h, nr(st(h, o.seed, "seed"), e.ORDER);
1744
+ function s(w) {
1745
+ return w = w === void 0 ? n(o.seed) : w, sr(W(w, o.seed, "seed"), r.ORDER);
2565
1746
  }
2566
- function l(h, w = !0) {
2567
- return t.BASE.multiply(e.fromBytes(h)).toBytes(w);
1747
+ function a(w, A = !0) {
1748
+ return t.BASE.multiply(r.fromBytes(w)).toBytes(A);
2568
1749
  }
2569
- function g(h) {
2570
- const { secretKey: w, publicKey: b, publicKeyUncompressed: E } = o, T = e._lengths;
2571
- if (!oe(h)) return;
2572
- const B = st(h, void 0, "key").length, C = B === b || B === E, O = B === w || !!T?.includes(B);
2573
- if (!(C && O))
2574
- return C;
1750
+ function u(w) {
1751
+ const { secretKey: A, publicKey: _, publicKeyUncompressed: H } = o, O = r._lengths;
1752
+ if (!fn(w)) return;
1753
+ const x = W(w, void 0, "key").length, q = x === _ || x === H, Z = x === A || !!O?.includes(x);
1754
+ if (!(q && Z))
1755
+ return q;
2575
1756
  }
2576
- function s(h, w, b = !0) {
2577
- if (g(h) === !0) throw new Error("first arg must be private key");
2578
- if (g(w) === !1) throw new Error("second arg must be public key");
2579
- const E = e.fromBytes(h);
2580
- return t.fromBytes(w).multiply(E).toBytes(b);
1757
+ function f(w, A, _ = !0) {
1758
+ if (u(w) === !0) throw new Error("first arg must be private key");
1759
+ if (u(A) === !1) throw new Error("second arg must be public key");
1760
+ const H = r.fromBytes(w);
1761
+ return t.fromBytes(A).multiply(H).toBytes(_);
2581
1762
  }
2582
- const u = {
1763
+ const g = {
2583
1764
  isValidSecretKey: i,
2584
- isValidPublicKey: a,
2585
- randomSecretKey: f
2586
- }, d = to(f, l);
2587
- return Object.freeze(u), Object.freeze(o), Object.freeze({
2588
- getPublicKey: l,
2589
- getSharedSecret: s,
2590
- keygen: d,
1765
+ isValidPublicKey: c,
1766
+ randomSecretKey: s
1767
+ }, m = ur(s, a);
1768
+ return Object.freeze(g), Object.freeze(o), Object.freeze({
1769
+ getPublicKey: a,
1770
+ getSharedSecret: f,
1771
+ keygen: m,
2591
1772
  Point: t,
2592
- utils: u,
1773
+ utils: g,
2593
1774
  lengths: o
2594
1775
  });
2595
1776
  }
2596
- function bo(t, n, e = {}) {
2597
- const r = n;
2598
- An(r), Mt(e, {}, {
1777
+ function wr(t, e, r = {}) {
1778
+ const n = e;
1779
+ ke(n), kt(r, {}, {
2599
1780
  hmac: "function",
2600
1781
  lowS: "boolean",
2601
1782
  randomBytes: "function",
2602
1783
  bits2int: "function",
2603
1784
  bits2int_modN: "function"
2604
- }), e = Object.assign({}, e);
2605
- const o = e.randomBytes === void 0 ? wt : e.randomBytes, i = e.hmac === void 0 ? (S, p) => We(r, S, p) : e.hmac, { Fp: a, Fn: f } = t, { ORDER: l, BITS: g } = f, { keygen: s, getPublicKey: u, getSharedSecret: d, utils: h, lengths: w } = wo(t, e), b = {
1785
+ }), r = Object.assign({}, r);
1786
+ const o = r.randomBytes === void 0 ? an : r.randomBytes, i = r.hmac === void 0 ? (d, l) => de(n, d, l) : r.hmac, { Fp: c, Fn: s } = t, { ORDER: a, BITS: u } = s, { keygen: f, getPublicKey: g, getSharedSecret: m, utils: w, lengths: A } = br(t, r), _ = {
2606
1787
  prehash: !0,
2607
- lowS: typeof e.lowS == "boolean" ? e.lowS : !0,
1788
+ lowS: typeof r.lowS == "boolean" ? r.lowS : !0,
2608
1789
  format: "compact",
2609
1790
  extraEntropy: !1
2610
- }, E = l * Bt + ct < a.ORDER;
2611
- function T(S) {
2612
- return S > l >> ct;
1791
+ }, H = a * _n + ht < c.ORDER;
1792
+ function O(d) {
1793
+ return d > a >> ht;
2613
1794
  }
2614
- function B(S, p) {
2615
- if (!f.isValidNot0(p)) throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);
2616
- return p;
1795
+ function x(d, l) {
1796
+ if (!s.isValidNot0(l)) throw new Error(`invalid signature ${d}: out of range 1..Point.Fn.ORDER`);
1797
+ return l;
2617
1798
  }
2618
- function C() {
2619
- if (E) throw new Error('"recovered" sig type is not supported for cofactor >2 curves');
1799
+ function q() {
1800
+ if (H) throw new Error('"recovered" sig type is not supported for cofactor >2 curves');
2620
1801
  }
2621
- function O(S, p) {
2622
- ze(p);
2623
- const R = w.signature;
2624
- return st(S, p === "compact" ? R : p === "recovered" ? R + 1 : void 0);
1802
+ function Z(d, l) {
1803
+ ae(l);
1804
+ const b = A.signature;
1805
+ return W(d, l === "compact" ? b : l === "recovered" ? b + 1 : void 0);
2625
1806
  }
2626
- class F {
1807
+ class T {
2627
1808
  r;
2628
1809
  s;
2629
1810
  recovery;
2630
- constructor(p, R, I) {
2631
- if (this.r = B("r", p), this.s = B("s", R), I != null) {
2632
- if (C(), ![
1811
+ constructor(l, b, E) {
1812
+ if (this.r = x("r", l), this.s = x("s", b), E != null) {
1813
+ if (q(), ![
2633
1814
  0,
2634
1815
  1,
2635
1816
  2,
2636
1817
  3
2637
- ].includes(I)) throw new Error("invalid recovery id");
2638
- this.recovery = I;
1818
+ ].includes(E)) throw new Error("invalid recovery id");
1819
+ this.recovery = E;
2639
1820
  }
2640
1821
  Object.freeze(this);
2641
1822
  }
2642
- static fromBytes(p, R = b.format) {
2643
- O(p, R);
2644
- let I;
2645
- if (R === "der") {
2646
- const { r: X, s: Y } = Et.toSig(st(p));
2647
- return new F(X, Y);
1823
+ static fromBytes(l, b = _.format) {
1824
+ Z(l, b);
1825
+ let E;
1826
+ if (b === "der") {
1827
+ const { r: N, s: L } = et.toSig(W(l));
1828
+ return new T(N, L);
2648
1829
  }
2649
- R === "recovered" && (I = p[0], R = "compact", p = p.subarray(1));
2650
- const _ = w.signature / 2, D = p.subarray(0, _), q = p.subarray(_, _ * 2);
2651
- return new F(f.fromBytes(D), f.fromBytes(q), I);
1830
+ b === "recovered" && (E = l[0], b = "compact", l = l.subarray(1));
1831
+ const p = A.signature / 2, v = l.subarray(0, p), S = l.subarray(p, p * 2);
1832
+ return new T(s.fromBytes(v), s.fromBytes(S), E);
2652
1833
  }
2653
- static fromHex(p, R) {
2654
- return this.fromBytes(he(p), R);
1834
+ static fromHex(l, b) {
1835
+ return this.fromBytes(se(l), b);
2655
1836
  }
2656
1837
  assertRecovery() {
2657
- const { recovery: p } = this;
2658
- if (p == null) throw new Error("invalid recovery id: must be present");
2659
- return p;
1838
+ const { recovery: l } = this;
1839
+ if (l == null) throw new Error("invalid recovery id: must be present");
1840
+ return l;
2660
1841
  }
2661
- addRecoveryBit(p) {
2662
- return new F(this.r, this.s, p);
1842
+ addRecoveryBit(l) {
1843
+ return new T(this.r, this.s, l);
2663
1844
  }
2664
- recoverPublicKey(p) {
2665
- const { r: R, s: I } = this, _ = this.assertRecovery(), D = _ === 2 || _ === 3 ? R + l : R;
2666
- if (!a.isValid(D)) throw new Error("invalid recovery id: sig.r+curve.n != R.x");
2667
- const q = a.toBytes(D), X = t.fromBytes(Q(fr((_ & 1) === 0), q)), Y = f.inv(D), Z = W(st(p, void 0, "msgHash")), nt = f.create(-Z * Y), rt = f.create(I * Y), it = t.BASE.multiplyUnsafe(nt).add(X.multiplyUnsafe(rt));
2668
- if (it.is0()) throw new Error("invalid recovery: point at infinify");
2669
- return it.assertValidity(), it;
1845
+ recoverPublicKey(l) {
1846
+ const { r: b, s: E } = this, p = this.assertRecovery(), v = p === 2 || p === 3 ? b + a : b;
1847
+ if (!c.isValid(v)) throw new Error("invalid recovery id: sig.r+curve.n != R.x");
1848
+ const S = c.toBytes(v), N = t.fromBytes(lt(Hn((p & 1) === 0), S)), L = s.inv(v), I = $(W(l, void 0, "msgHash")), k = s.create(-I * L), j = s.create(E * L), V = t.BASE.multiplyUnsafe(k).add(N.multiplyUnsafe(j));
1849
+ if (V.is0()) throw new Error("invalid recovery: point at infinify");
1850
+ return V.assertValidity(), V;
2670
1851
  }
2671
1852
  hasHighS() {
2672
- return T(this.s);
2673
- }
2674
- toBytes(p = b.format) {
2675
- if (ze(p), p === "der") return he(Et.hexFromSig(this));
2676
- const { r: R, s: I } = this, _ = f.toBytes(R), D = f.toBytes(I);
2677
- return p === "recovered" ? (C(), Q(Uint8Array.of(this.assertRecovery()), _, D)) : Q(_, D);
2678
- }
2679
- toHex(p) {
2680
- return Ct(this.toBytes(p));
2681
- }
2682
- }
2683
- Object.freeze(F.prototype), Object.freeze(F);
2684
- const z = e.bits2int === void 0 ? function(p) {
2685
- if (p.length > 8192) throw new Error("input is too large");
2686
- const R = St(p), I = p.length * 8 - g;
2687
- return I > 0 ? R >> BigInt(I) : R;
2688
- } : e.bits2int, W = e.bits2int_modN === void 0 ? function(p) {
2689
- return f.create(z(p));
2690
- } : e.bits2int_modN, N = pe(g);
2691
- function V(S) {
2692
- return Mn("num < 2^" + g, S, yt, N), f.toBytes(S);
2693
- }
2694
- function K(S, p) {
2695
- return st(S, void 0, "message"), p ? st(r(S), void 0, "prehashed message") : S;
2696
- }
2697
- function M(S, p, R) {
2698
- const { lowS: I, prehash: _, extraEntropy: D } = Te(R, b);
2699
- S = K(S, _);
2700
- const q = W(S), X = f.fromBytes(p);
2701
- if (!f.isValidNot0(X)) throw new Error("invalid private key");
2702
- const Y = [V(X), V(q)];
2703
- if (D != null && D !== !1) {
2704
- const it = D === !0 ? o(w.secretKey) : D;
2705
- Y.push(st(it, void 0, "extraEntropy"));
2706
- }
2707
- const Z = Q(...Y), nt = q;
2708
- function rt(it) {
2709
- const c = z(it);
2710
- if (!f.isValidNot0(c)) return;
2711
- const m = f.inv(c), y = t.BASE.multiply(c).toAffine(), x = f.create(y.x);
2712
- if (x === yt) return;
2713
- const A = f.create(m * f.create(nt + x * X));
2714
- if (A === yt) return;
2715
- let j = (y.x === x ? 0 : 2) | Number(y.y & ct), L = A;
2716
- return I && T(A) && (L = f.neg(A), j ^= 1), new F(x, L, E ? void 0 : j);
1853
+ return O(this.s);
1854
+ }
1855
+ toBytes(l = _.format) {
1856
+ if (ae(l), l === "der") return se(et.hexFromSig(this));
1857
+ const { r: b, s: E } = this, p = s.toBytes(b), v = s.toBytes(E);
1858
+ return l === "recovered" ? (q(), lt(Uint8Array.of(this.assertRecovery()), p, v)) : lt(p, v);
1859
+ }
1860
+ toHex(l) {
1861
+ return cn(this.toBytes(l));
1862
+ }
1863
+ }
1864
+ Object.freeze(T.prototype), Object.freeze(T);
1865
+ const Q = r.bits2int === void 0 ? function(l) {
1866
+ if (l.length > 8192) throw new Error("input is too large");
1867
+ const b = Ct(l), E = l.length * 8 - u;
1868
+ return E > 0 ? b >> BigInt(E) : b;
1869
+ } : r.bits2int, $ = r.bits2int_modN === void 0 ? function(l) {
1870
+ return s.create(Q(l));
1871
+ } : r.bits2int_modN, R = Ee(u);
1872
+ function C(d) {
1873
+ return dn("num < 2^" + u, d, ot, R), s.toBytes(d);
1874
+ }
1875
+ function X(d, l) {
1876
+ return W(d, void 0, "message"), l ? W(n(d), void 0, "prehashed message") : d;
1877
+ }
1878
+ function F(d, l, b) {
1879
+ const { lowS: E, prehash: p, extraEntropy: v } = Xt(b, _);
1880
+ d = X(d, p);
1881
+ const S = $(d), N = s.fromBytes(l);
1882
+ if (!s.isValidNot0(N)) throw new Error("invalid private key");
1883
+ const L = [C(N), C(S)];
1884
+ if (v != null && v !== !1) {
1885
+ const V = v === !0 ? o(A.secretKey) : v;
1886
+ L.push(W(V, void 0, "extraEntropy"));
1887
+ }
1888
+ const I = lt(...L), k = S;
1889
+ function j(V) {
1890
+ const U = Q(V);
1891
+ if (!s.isValidNot0(U)) return;
1892
+ const J = s.inv(U), vt = t.BASE.multiply(U).toAffine(), Ft = s.create(vt.x);
1893
+ if (Ft === ot) return;
1894
+ const Lt = s.create(J * s.create(k + Ft * N));
1895
+ if (Lt === ot) return;
1896
+ let xe = (vt.x === Ft ? 0 : 2) | Number(vt.y & ht), Be = Lt;
1897
+ return E && O(Lt) && (Be = s.neg(Lt), xe ^= 1), new T(Ft, Be, H ? void 0 : xe);
2717
1898
  }
2718
1899
  return {
2719
- seed: Z,
2720
- k2sig: rt
1900
+ seed: I,
1901
+ k2sig: j
2721
1902
  };
2722
1903
  }
2723
- function v(S, p, R = {}) {
2724
- const { seed: I, k2sig: _ } = M(S, p, R);
2725
- return qr(r.outputLen, f.BYTES, i)(I, _).toBytes(R.format);
1904
+ function h(d, l, b = {}) {
1905
+ const { seed: E, k2sig: p } = F(d, l, b);
1906
+ return Wn(n.outputLen, s.BYTES, i)(E, p).toBytes(b.format);
2726
1907
  }
2727
- function H(S, p, R, I = {}) {
2728
- const { lowS: _, prehash: D, format: q } = Te(I, b);
2729
- if (R = st(R, void 0, "publicKey"), p = K(p, D), !oe(S)) {
2730
- const X = S instanceof F ? ", use sig.toBytes()" : "";
2731
- throw new Error("verify expects Uint8Array signature" + X);
1908
+ function y(d, l, b, E = {}) {
1909
+ const { lowS: p, prehash: v, format: S } = Xt(E, _);
1910
+ if (b = W(b, void 0, "publicKey"), l = X(l, v), !fn(d)) {
1911
+ const N = d instanceof T ? ", use sig.toBytes()" : "";
1912
+ throw new Error("verify expects Uint8Array signature" + N);
2732
1913
  }
2733
- O(S, q);
1914
+ Z(d, S);
2734
1915
  try {
2735
- const X = F.fromBytes(S, q), Y = t.fromBytes(R);
2736
- if (_ && X.hasHighS()) return !1;
2737
- const { r: Z, s: nt } = X, rt = W(p), it = f.inv(nt), c = f.create(rt * it), m = f.create(Z * it), y = t.BASE.multiplyUnsafe(c).add(Y.multiplyUnsafe(m));
2738
- return y.is0() ? !1 : f.create(y.x) === Z;
1916
+ const N = T.fromBytes(d, S), L = t.fromBytes(b);
1917
+ if (p && N.hasHighS()) return !1;
1918
+ const { r: I, s: k } = N, j = $(l), V = s.inv(k), U = s.create(j * V), J = s.create(I * V), vt = t.BASE.multiplyUnsafe(U).add(L.multiplyUnsafe(J));
1919
+ return vt.is0() ? !1 : s.create(vt.x) === I;
2739
1920
  } catch {
2740
1921
  return !1;
2741
1922
  }
2742
1923
  }
2743
- function U(S, p, R = {}) {
2744
- const { prehash: I } = Te(R, b);
2745
- return p = K(p, I), F.fromBytes(S, "recovered").recoverPublicKey(p).toBytes();
1924
+ function B(d, l, b = {}) {
1925
+ const { prehash: E } = Xt(b, _);
1926
+ return l = X(l, E), T.fromBytes(d, "recovered").recoverPublicKey(l).toBytes();
2746
1927
  }
2747
1928
  return Object.freeze({
2748
- keygen: s,
2749
- getPublicKey: u,
2750
- getSharedSecret: d,
2751
- utils: h,
2752
- lengths: w,
1929
+ keygen: f,
1930
+ getPublicKey: g,
1931
+ getSharedSecret: m,
1932
+ utils: w,
1933
+ lengths: A,
2753
1934
  Point: t,
2754
- sign: v,
2755
- verify: H,
2756
- recoverPublicKey: U,
2757
- Signature: F,
2758
- hash: r
1935
+ sign: h,
1936
+ verify: y,
1937
+ recoverPublicKey: B,
1938
+ Signature: T,
1939
+ hash: n
2759
1940
  });
2760
1941
  }
2761
- var rn = {
1942
+ var ve = {
2762
1943
  p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
2763
1944
  n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
2764
1945
  h: BigInt(1),
@@ -2766,209 +1947,55 @@ var rn = {
2766
1947
  b: BigInt(7),
2767
1948
  Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
2768
1949
  Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
2769
- }, yo = {
1950
+ }, pr = {
2770
1951
  beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
2771
1952
  basises: [[BigInt("0x3086d221a7d46bcde86c90e49284eb15"), -BigInt("0xe4437ed6010e88286f547fa90abfe4c3")], [BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]
2772
- }, lr = /* @__PURE__ */ BigInt(0), Ge = /* @__PURE__ */ BigInt(2);
2773
- function po(t) {
2774
- const n = rn.p, e = BigInt(3), r = BigInt(6), o = BigInt(11), i = BigInt(22), a = BigInt(23), f = BigInt(44), l = BigInt(88), g = t * t * t % n, s = g * g * t % n, u = gt(gt(gt(s, e, n) * s % n, e, n) * s % n, Ge, n) * g % n, d = gt(u, o, n) * u % n, h = gt(d, i, n) * d % n, w = gt(h, f, n) * h % n, b = gt(gt(gt(gt(gt(gt(w, l, n) * w % n, f, n) * h % n, e, n) * s % n, a, n) * d % n, r, n) * g % n, Ge, n);
2775
- if (!It.eql(It.sqr(b), t)) throw new Error("Cannot find square root");
2776
- return b;
2777
- }
2778
- var It = ve(rn.p, { sqrt: po }), J = /* @__PURE__ */ ho(rn, {
2779
- Fp: It,
2780
- endo: yo
2781
- }), Vo = /* @__PURE__ */ bo(J, jt), vn = {};
2782
- function ur(t, ...n) {
2783
- let e = vn[t];
2784
- if (e === void 0) {
2785
- const r = jt(be(t));
2786
- e = Q(r, r), vn[t] = e;
2787
- }
2788
- return jt(Q(e, ...n));
2789
- }
2790
- var Ye = (t) => t.toBytes(!0).slice(1), Vt = (t) => t % Ge === lr;
2791
- function Eo(t) {
2792
- const n = It;
2793
- if (!n.isValidNot0(t)) throw new Error("invalid x: Fail if x ≥ p");
2794
- const e = n.create(t * t), r = n.create(e * t + BigInt(7));
2795
- let o = n.sqrt(r);
2796
- Vt(o) || (o = n.neg(o));
2797
- const i = J.fromAffine({
2798
- x: t,
2799
- y: o
2800
- });
2801
- return i.assertValidity(), i;
2802
- }
2803
- var vo = St;
2804
- function xo(...t) {
2805
- return J.Fn.create(vo(ur("BIP0340/challenge", ...t)));
2806
- }
2807
- var Bo = co(It, [
2808
- [
2809
- "0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7",
2810
- "0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581",
2811
- "0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262",
2812
- "0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"
2813
- ],
2814
- [
2815
- "0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b",
2816
- "0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14",
2817
- "0x0000000000000000000000000000000000000000000000000000000000000001"
2818
- ],
2819
- [
2820
- "0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c",
2821
- "0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3",
2822
- "0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931",
2823
- "0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"
2824
- ],
2825
- [
2826
- "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b",
2827
- "0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573",
2828
- "0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f",
2829
- "0x0000000000000000000000000000000000000000000000000000000000000001"
2830
- ]
2831
- ].map((t) => t.map((n) => BigInt(n)))), xn, So = () => xn || (xn = go(It, {
2832
- A: BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),
2833
- B: BigInt("1771"),
2834
- Z: It.create(BigInt("-11"))
2835
- })), dr = ao(J, (t) => {
2836
- const { x: n, y: e } = So()(It.create(t[0]));
2837
- return Bo(n, e);
2838
- }, {
2839
- DST: "secp256k1_XMD:SHA-256_SSWU_RO_",
2840
- encodeDST: "secp256k1_XMD:SHA-256_SSWU_NU_",
2841
- p: It.ORDER,
2842
- m: 1,
2843
- k: 128,
2844
- expand: "xmd",
2845
- hash: jt
2846
- }), Po = cr({
2847
- name: "FROST-secp256k1-SHA256-v1",
2848
- Point: J,
2849
- hashToScalar: dr.hashToScalar,
2850
- hash: jt
2851
- });
2852
- function hr(t, n) {
2853
- if (n === void 0) return lr;
2854
- const e = St(ur("TapTweak", Ye(t), n));
2855
- if (!J.Fn.isValid(e)) throw new Error("invalid TapTweak hash");
2856
- return e;
2857
- }
2858
- function on(t) {
2859
- return Vt(J.fromBytes(t.commitments[0]).y) ? t : {
2860
- signers: {
2861
- min: t.signers.min,
2862
- max: t.signers.max
2863
- },
2864
- commitments: t.commitments.map((n) => J.fromBytes(n).negate().toBytes()),
2865
- verifyingShares: Object.fromEntries(Object.entries(t.verifyingShares).map(([n, e]) => [n, J.fromBytes(e).negate().toBytes()]))
2866
- };
2867
- }
2868
- function mr(t, n) {
2869
- if (Vt(J.fromBytes(n.commitments[0]).y)) return t;
2870
- const e = J.Fn;
2871
- return {
2872
- ...t,
2873
- signingShare: e.toBytes(e.neg(e.fromBytes(t.signingShare)))
2874
- };
2875
- }
2876
- function Ao(t, n) {
2877
- if (Vt(t.y)) return n;
2878
- const e = J.Fn;
2879
- return {
2880
- binding: e.toBytes(e.neg(e.fromBytes(n.binding))),
2881
- hiding: e.toBytes(e.neg(e.fromBytes(n.hiding)))
2882
- };
2883
- }
2884
- function Ro(t, n, e) {
2885
- const r = J.Fn, o = mr(t, n), i = on(n), a = hr(J.fromBytes(i.commitments[0]), e), f = r.toBytes(r.add(r.fromBytes(o.signingShare), a));
2886
- return {
2887
- identifier: o.identifier,
2888
- signingShare: f
2889
- };
2890
- }
2891
- function _o(t, n) {
2892
- const e = on(t), r = hr(J.fromBytes(e.commitments[0]), n), o = J.BASE.multiply(r), i = e.commitments.map((f, l) => (l === 0 ? J.fromBytes(f).add(o) : J.fromBytes(f)).toBytes()), a = {};
2893
- for (const f in e.verifyingShares) a[f] = J.fromBytes(e.verifyingShares[f]).add(o).toBytes();
2894
- return {
2895
- signers: {
2896
- min: e.signers.min,
2897
- max: e.signers.max
2898
- },
2899
- commitments: i,
2900
- verifyingShares: a
2901
- };
2902
- }
2903
- var zo = cr({
2904
- name: "FROST-secp256k1-SHA256-TR-v1",
2905
- Point: J,
2906
- hashToScalar: dr.hashToScalar,
2907
- hash: jt,
2908
- parsePublicKey(t) {
2909
- if (t.length === 32) return Eo(St(t));
2910
- if (t.length === 33) return J.fromBytes(t);
2911
- throw new Error(`expected x-only or compressed public key, got length=${t.length}`);
2912
- },
2913
- adjustScalar(t) {
2914
- return Vt(J.BASE.multiply(t).y) ? t : J.Fn.neg(t);
2915
- },
2916
- adjustPoint: (t) => Vt(t.y) ? t : t.negate(),
2917
- challenge(t, n, e) {
2918
- return xo(Ye(t), Ye(n), e);
2919
- },
2920
- adjustNonces: Ao,
2921
- adjustGroupCommitmentShare: (t, n) => Vt(t.y) ? n : n.negate(),
2922
- adjustPublic: on,
2923
- adjustSecret: mr,
2924
- adjustTx: {
2925
- encode: (t) => t.subarray(1),
2926
- decode: (t) => Q(Uint8Array.of(2), t)
2927
- },
2928
- adjustDKG: (t) => {
2929
- const n = new Uint8Array(0);
2930
- return {
2931
- public: _o(t.public, n),
2932
- secret: Ro(t.secret, t.public, n)
2933
- };
2934
- }
2935
- });
1953
+ }, qe = /* @__PURE__ */ BigInt(2);
1954
+ function yr(t) {
1955
+ const e = ve.p, r = BigInt(3), n = BigInt(6), o = BigInt(11), i = BigInt(22), c = BigInt(23), s = BigInt(44), a = BigInt(88), u = t * t * t % e, f = u * u * t % e, g = P(P(P(f, r, e) * f % e, r, e) * f % e, qe, e) * u % e, m = P(g, o, e) * g % e, w = P(m, i, e) * m % e, A = P(w, s, e) * w % e, _ = P(P(P(P(P(P(A, a, e) * A % e, s, e) * w % e, r, e) * f % e, c, e) * m % e, n, e) * u % e, qe, e);
1956
+ if (!ue.eql(ue.sqr(_), t)) throw new Error("Cannot find square root");
1957
+ return _;
1958
+ }
1959
+ var ue = jt(ve.p, { sqrt: yr }), Er = /* @__PURE__ */ gr(ve, {
1960
+ Fp: ue,
1961
+ endo: pr
1962
+ }), Ur = /* @__PURE__ */ wr(Er, ge);
2936
1963
  export {
2937
- xr as A,
2938
- Do as C,
2939
- Ln as D,
2940
- Fo as E,
2941
- Yt as F,
2942
- Qt as I,
2943
- Ho as L,
2944
- To as M,
2945
- Er as N,
2946
- vr as O,
2947
- Kt as P,
2948
- Fr as S,
2949
- jt as T,
2950
- qo as _,
2951
- wt as a,
2952
- Nr as b,
2953
- Dr as c,
2954
- kn as d,
2955
- No as f,
2956
- Uo as g,
2957
- Lo as h,
2958
- Q as i,
2959
- Br as j,
2960
- Fe as k,
2961
- ko as l,
2962
- jo as m,
2963
- bt as n,
2964
- Lr as o,
2965
- Io as p,
2966
- St as r,
2967
- Zo as s,
2968
- Vo as t,
2969
- $o as u,
2970
- jr as v,
2971
- _r as w,
2972
- Co as x,
2973
- Or as y
1964
+ Tn as A,
1965
+ _r as C,
1966
+ Je as D,
1967
+ Br as E,
1968
+ xt as F,
1969
+ It as I,
1970
+ vr as L,
1971
+ xr as M,
1972
+ Ln as N,
1973
+ Nn as O,
1974
+ Bt as P,
1975
+ Vn as S,
1976
+ ge as T,
1977
+ Ir as _,
1978
+ an as a,
1979
+ Yn as b,
1980
+ Mn as c,
1981
+ nn as d,
1982
+ Rr as f,
1983
+ Or as g,
1984
+ Hr as h,
1985
+ lt as i,
1986
+ Un as j,
1987
+ Wt as k,
1988
+ Lr as l,
1989
+ Sr as m,
1990
+ tt as n,
1991
+ Gn as o,
1992
+ Ar as p,
1993
+ Ct as r,
1994
+ Tr as s,
1995
+ Ur as t,
1996
+ Nr as u,
1997
+ zn as v,
1998
+ Zn as w,
1999
+ Fr as x,
2000
+ Cn as y
2974
2001
  };