digiid-ts 2.0.3 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2080 +1,1792 @@
1
- var Ve = Object.defineProperty;
2
- var Me = (e, t, r) => t in e ? Ve(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var m = (e, t, r) => Me(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { randomBytes as Ye } from "crypto";
5
- class C extends Error {
6
- constructor(t) {
7
- super(t), this.name = "DigiIDError";
8
- }
9
- }
10
- /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
11
- function Tt(e) {
12
- return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
13
- }
14
- function at(e, t = "") {
15
- if (!Number.isSafeInteger(e) || e < 0) {
16
- const r = t && `"${t}" `;
17
- throw new Error(`${r}expected integer >= 0, got ${e}`);
18
- }
19
- }
20
- function N(e, t, r = "") {
21
- const n = Tt(e), s = e == null ? void 0 : e.length, o = t !== void 0;
22
- if (!n || o && s !== t) {
23
- const i = r && `"${r}" `, c = o ? ` of length ${t}` : "", f = n ? `length=${s}` : `type=${typeof e}`;
24
- throw new Error(i + "expected Uint8Array" + c + ", got " + f);
25
- }
26
- return e;
27
- }
28
- function ue(e) {
29
- if (typeof e != "function" || typeof e.create != "function")
30
- throw new Error("Hash must wrapped by utils.createHasher");
31
- at(e.outputLen), at(e.blockLen);
32
- }
33
- function Bt(e, t = !0) {
34
- if (e.destroyed)
35
- throw new Error("Hash instance has been destroyed");
36
- if (t && e.finished)
37
- throw new Error("Hash#digest() has already been called");
38
- }
39
- function je(e, t) {
40
- N(e, void 0, "digestInto() output");
41
- const r = t.outputLen;
42
- if (e.length < r)
43
- throw new Error('"digestInto() output" expected to be of length >=' + r);
44
- }
45
- function vt(...e) {
46
- for (let t = 0; t < e.length; t++)
47
- e[t].fill(0);
48
- }
49
- function Ot(e) {
50
- return new DataView(e.buffer, e.byteOffset, e.byteLength);
51
- }
52
- function P(e, t) {
53
- return e << 32 - t | e >>> t;
54
- }
55
- const ae = /* @ts-ignore */ typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", Ke = /* @__PURE__ */ Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
56
- function Lt(e) {
57
- if (N(e), ae)
58
- return e.toHex();
59
- let t = "";
60
- for (let r = 0; r < e.length; r++)
61
- t += Ke[e[r]];
62
- return t;
63
- }
64
- const J = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
65
- function Wt(e) {
66
- if (e >= J._0 && e <= J._9)
67
- return e - J._0;
68
- if (e >= J.A && e <= J.F)
69
- return e - (J.A - 10);
70
- if (e >= J.a && e <= J.f)
71
- return e - (J.a - 10);
72
- }
73
- function Rt(e) {
74
- if (typeof e != "string")
75
- throw new Error("hex string expected, got " + typeof e);
76
- if (ae)
77
- return Uint8Array.fromHex(e);
78
- const t = e.length, r = t / 2;
79
- if (t % 2)
80
- throw new Error("hex string expected, got unpadded hex of length " + t);
81
- const n = new Uint8Array(r);
82
- for (let s = 0, o = 0; s < r; s++, o += 2) {
83
- const i = Wt(e.charCodeAt(o)), c = Wt(e.charCodeAt(o + 1));
84
- if (i === void 0 || c === void 0) {
85
- const f = e[o] + e[o + 1];
86
- throw new Error('hex string expected, got non-hex character "' + f + '" at index ' + o);
87
- }
88
- n[s] = i * 16 + c;
89
- }
90
- return n;
91
- }
92
- function it(...e) {
93
- let t = 0;
94
- for (let n = 0; n < e.length; n++) {
95
- const s = e[n];
96
- N(s), t += s.length;
97
- }
98
- const r = new Uint8Array(t);
99
- for (let n = 0, s = 0; n < e.length; n++) {
100
- const o = e[n];
101
- r.set(o, s), s += o.length;
102
- }
103
- return r;
104
- }
105
- function Ge(e, t = {}) {
106
- const r = (s, o) => e(o).update(s).digest(), n = e(void 0);
107
- return r.outputLen = n.outputLen, r.blockLen = n.blockLen, r.create = (s) => e(s), Object.assign(r, t), Object.freeze(r);
108
- }
109
- function le(e = 32) {
110
- const t = typeof globalThis == "object" ? globalThis.crypto : null;
111
- if (typeof (t == null ? void 0 : t.getRandomValues) != "function")
112
- throw new Error("crypto.getRandomValues must be defined");
113
- return t.getRandomValues(new Uint8Array(e));
114
- }
115
- const Xe = (e) => ({
116
- oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, e])
117
- });
118
- function ze(e, t, r) {
119
- return e & t ^ ~e & r;
120
- }
121
- function Fe(e, t, r) {
122
- return e & t ^ e & r ^ t & r;
123
- }
124
- let We = class {
125
- constructor(t, r, n, s) {
126
- m(this, "blockLen");
127
- m(this, "outputLen");
128
- m(this, "padOffset");
129
- m(this, "isLE");
130
- // For partial updates less than block size
131
- m(this, "buffer");
132
- m(this, "view");
133
- m(this, "finished", !1);
134
- m(this, "length", 0);
135
- m(this, "pos", 0);
136
- m(this, "destroyed", !1);
137
- this.blockLen = t, this.outputLen = r, this.padOffset = n, this.isLE = s, this.buffer = new Uint8Array(t), this.view = Ot(this.buffer);
138
- }
139
- update(t) {
140
- Bt(this), N(t);
141
- const { view: r, buffer: n, blockLen: s } = this, o = t.length;
142
- for (let i = 0; i < o; ) {
143
- const c = Math.min(s - this.pos, o - i);
144
- if (c === s) {
145
- const f = Ot(t);
146
- for (; s <= o - i; i += s)
147
- this.process(f, i);
148
- continue;
149
- }
150
- n.set(t.subarray(i, i + c), this.pos), this.pos += c, i += c, this.pos === s && (this.process(r, 0), this.pos = 0);
151
- }
152
- return this.length += t.length, this.roundClean(), this;
153
- }
154
- digestInto(t) {
155
- Bt(this), je(t, this), this.finished = !0;
156
- const { buffer: r, view: n, blockLen: s, isLE: o } = this;
157
- let { pos: i } = this;
158
- r[i++] = 128, vt(this.buffer.subarray(i)), this.padOffset > s - i && (this.process(n, 0), i = 0);
159
- for (let d = i; d < s; d++)
160
- r[d] = 0;
161
- n.setBigUint64(s - 8, BigInt(this.length * 8), o), this.process(n, 0);
162
- const c = Ot(t), f = this.outputLen;
163
- if (f % 4)
164
- throw new Error("_sha2: outputLen must be aligned to 32bit");
165
- const u = f / 4, h = this.get();
166
- if (u > h.length)
167
- throw new Error("_sha2: outputLen bigger than state");
168
- for (let d = 0; d < u; d++)
169
- c.setUint32(4 * d, h[d], o);
170
- }
171
- digest() {
172
- const { buffer: t, outputLen: r } = this;
173
- this.digestInto(t);
174
- const n = t.slice(0, r);
175
- return this.destroy(), n;
176
- }
177
- _cloneInto(t) {
178
- t || (t = new this.constructor()), t.set(...this.get());
179
- const { blockLen: r, buffer: n, length: s, finished: o, destroyed: i, pos: c } = this;
180
- return t.destroyed = i, t.finished = o, t.length = s, t.pos = c, s % r && t.buffer.set(n), t;
181
- }
182
- clone() {
183
- return this._cloneInto();
184
- }
1
+ import { randomBytes as e } from "crypto";
2
+ //#region src/types.ts
3
+ var t = class extends Error {
4
+ constructor(e) {
5
+ super(e), this.name = "DigiIDError";
6
+ }
7
+ };
8
+ //#endregion
9
+ //#region node_modules/@noble/hashes/utils.js
10
+ function n(e) {
11
+ return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in e && e.BYTES_PER_ELEMENT === 1;
12
+ }
13
+ function r(e, t = "") {
14
+ if (typeof e != "number") {
15
+ let n = t && `"${t}" `;
16
+ throw TypeError(`${n}expected number, got ${typeof e}`);
17
+ }
18
+ if (!Number.isSafeInteger(e) || e < 0) {
19
+ let n = t && `"${t}" `;
20
+ throw RangeError(`${n}expected integer >= 0, got ${e}`);
21
+ }
22
+ }
23
+ function i(e, t, r = "") {
24
+ let i = n(e), a = e?.length, o = t !== void 0;
25
+ if (!i || o && a !== t) {
26
+ let n = r && `"${r}" `, s = o ? ` of length ${t}` : "", c = i ? `length=${a}` : `type=${typeof e}`, l = n + "expected Uint8Array" + s + ", got " + c;
27
+ throw i ? RangeError(l) : TypeError(l);
28
+ }
29
+ return e;
30
+ }
31
+ function a(e) {
32
+ if (typeof e != "function" || typeof e.create != "function") throw TypeError("Hash must wrapped by utils.createHasher");
33
+ if (r(e.outputLen), r(e.blockLen), e.outputLen < 1) throw Error("\"outputLen\" must be >= 1");
34
+ if (e.blockLen < 1) throw Error("\"blockLen\" must be >= 1");
35
+ }
36
+ function o(e, t = !0) {
37
+ if (e.destroyed) throw Error("Hash instance has been destroyed");
38
+ if (t && e.finished) throw Error("Hash#digest() has already been called");
39
+ }
40
+ function s(e, t) {
41
+ i(e, void 0, "digestInto() output");
42
+ let n = t.outputLen;
43
+ if (e.length < n) throw RangeError("\"digestInto() output\" expected to be of length >=" + n);
44
+ }
45
+ function c(...e) {
46
+ for (let t = 0; t < e.length; t++) e[t].fill(0);
47
+ }
48
+ function l(e) {
49
+ return new DataView(e.buffer, e.byteOffset, e.byteLength);
50
+ }
51
+ function u(e, t) {
52
+ return e << 32 - t | e >>> t;
53
+ }
54
+ function d(e, t) {
55
+ return e << t | e >>> 32 - t >>> 0;
56
+ }
57
+ var f = typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", p = /* @__PURE__ */ Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
58
+ function m(e) {
59
+ if (i(e), f) return e.toHex();
60
+ let t = "";
61
+ for (let n = 0; n < e.length; n++) t += p[e[n]];
62
+ return t;
63
+ }
64
+ var h = {
65
+ _0: 48,
66
+ _9: 57,
67
+ A: 65,
68
+ F: 70,
69
+ a: 97,
70
+ f: 102
185
71
  };
186
- const et = /* @__PURE__ */ Uint32Array.from([
187
- 1779033703,
188
- 3144134277,
189
- 1013904242,
190
- 2773480762,
191
- 1359893119,
192
- 2600822924,
193
- 528734635,
194
- 1541459225
195
- ]), Pe = /* @__PURE__ */ Uint32Array.from([
196
- 1116352408,
197
- 1899447441,
198
- 3049323471,
199
- 3921009573,
200
- 961987163,
201
- 1508970993,
202
- 2453635748,
203
- 2870763221,
204
- 3624381080,
205
- 310598401,
206
- 607225278,
207
- 1426881987,
208
- 1925078388,
209
- 2162078206,
210
- 2614888103,
211
- 3248222580,
212
- 3835390401,
213
- 4022224774,
214
- 264347078,
215
- 604807628,
216
- 770255983,
217
- 1249150122,
218
- 1555081692,
219
- 1996064986,
220
- 2554220882,
221
- 2821834349,
222
- 2952996808,
223
- 3210313671,
224
- 3336571891,
225
- 3584528711,
226
- 113926993,
227
- 338241895,
228
- 666307205,
229
- 773529912,
230
- 1294757372,
231
- 1396182291,
232
- 1695183700,
233
- 1986661051,
234
- 2177026350,
235
- 2456956037,
236
- 2730485921,
237
- 2820302411,
238
- 3259730800,
239
- 3345764771,
240
- 3516065817,
241
- 3600352804,
242
- 4094571909,
243
- 275423344,
244
- 430227734,
245
- 506948616,
246
- 659060556,
247
- 883997877,
248
- 958139571,
249
- 1322822218,
250
- 1537002063,
251
- 1747873779,
252
- 1955562222,
253
- 2024104815,
254
- 2227730452,
255
- 2361852424,
256
- 2428436474,
257
- 2756734187,
258
- 3204031479,
259
- 3329325298
260
- ]), nt = /* @__PURE__ */ new Uint32Array(64);
261
- class Qe extends We {
262
- constructor(t) {
263
- super(64, t, 8, !1);
264
- }
265
- get() {
266
- const { A: t, B: r, C: n, D: s, E: o, F: i, G: c, H: f } = this;
267
- return [t, r, n, s, o, i, c, f];
268
- }
269
- // prettier-ignore
270
- set(t, r, n, s, o, i, c, f) {
271
- this.A = t | 0, this.B = r | 0, this.C = n | 0, this.D = s | 0, this.E = o | 0, this.F = i | 0, this.G = c | 0, this.H = f | 0;
272
- }
273
- process(t, r) {
274
- for (let d = 0; d < 16; d++, r += 4)
275
- nt[d] = t.getUint32(r, !1);
276
- for (let d = 16; d < 64; d++) {
277
- const x = nt[d - 15], g = nt[d - 2], y = P(x, 7) ^ P(x, 18) ^ x >>> 3, U = P(g, 17) ^ P(g, 19) ^ g >>> 10;
278
- nt[d] = U + nt[d - 7] + y + nt[d - 16] | 0;
279
- }
280
- let { A: n, B: s, C: o, D: i, E: c, F: f, G: u, H: h } = this;
281
- for (let d = 0; d < 64; d++) {
282
- const x = P(c, 6) ^ P(c, 11) ^ P(c, 25), g = h + x + ze(c, f, u) + Pe[d] + nt[d] | 0, U = (P(n, 2) ^ P(n, 13) ^ P(n, 22)) + Fe(n, s, o) | 0;
283
- h = u, u = f, f = c, c = i + g | 0, i = o, o = s, s = n, n = g + U | 0;
284
- }
285
- n = n + this.A | 0, s = s + this.B | 0, o = o + this.C | 0, i = i + this.D | 0, c = c + this.E | 0, f = f + this.F | 0, u = u + this.G | 0, h = h + this.H | 0, this.set(n, s, o, i, c, f, u, h);
286
- }
287
- roundClean() {
288
- vt(nt);
289
- }
290
- destroy() {
291
- this.set(0, 0, 0, 0, 0, 0, 0, 0), vt(this.buffer);
292
- }
293
- }
294
- class Je extends Qe {
295
- constructor() {
296
- super(32);
297
- // We cannot use array here since array allows indexing by variable
298
- // which means optimizer/compiler cannot use registers.
299
- m(this, "A", et[0] | 0);
300
- m(this, "B", et[1] | 0);
301
- m(this, "C", et[2] | 0);
302
- m(this, "D", et[3] | 0);
303
- m(this, "E", et[4] | 0);
304
- m(this, "F", et[5] | 0);
305
- m(this, "G", et[6] | 0);
306
- m(this, "H", et[7] | 0);
307
- }
308
- }
309
- const tn = /* @__PURE__ */ Ge(
310
- () => new Je(),
311
- /* @__PURE__ */ Xe(1)
312
- );
313
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
314
- const Vt = /* @__PURE__ */ BigInt(0), $t = /* @__PURE__ */ BigInt(1);
315
- function At(e, t = "") {
316
- if (typeof e != "boolean") {
317
- const r = t && `"${t}" `;
318
- throw new Error(r + "expected boolean, got type=" + typeof e);
319
- }
320
- return e;
72
+ function g(e) {
73
+ if (e >= h._0 && e <= h._9) return e - h._0;
74
+ if (e >= h.A && e <= h.F) return e - (h.A - 10);
75
+ if (e >= h.a && e <= h.f) return e - (h.a - 10);
76
+ }
77
+ function _(e) {
78
+ if (typeof e != "string") throw TypeError("hex string expected, got " + typeof e);
79
+ if (f) try {
80
+ return Uint8Array.fromHex(e);
81
+ } catch (e) {
82
+ throw e instanceof SyntaxError ? RangeError(e.message) : e;
83
+ }
84
+ let t = e.length, n = t / 2;
85
+ if (t % 2) throw RangeError("hex string expected, got unpadded hex of length " + t);
86
+ let r = new Uint8Array(n);
87
+ for (let t = 0, i = 0; t < n; t++, i += 2) {
88
+ let n = g(e.charCodeAt(i)), a = g(e.charCodeAt(i + 1));
89
+ if (n === void 0 || a === void 0) {
90
+ let t = e[i] + e[i + 1];
91
+ throw RangeError("hex string expected, got non-hex character \"" + t + "\" at index " + i);
92
+ }
93
+ r[t] = n * 16 + a;
94
+ }
95
+ return r;
96
+ }
97
+ function v(...e) {
98
+ let t = 0;
99
+ for (let n = 0; n < e.length; n++) {
100
+ let r = e[n];
101
+ i(r), t += r.length;
102
+ }
103
+ let n = new Uint8Array(t);
104
+ for (let t = 0, r = 0; t < e.length; t++) {
105
+ let i = e[t];
106
+ n.set(i, r), r += i.length;
107
+ }
108
+ return n;
109
+ }
110
+ function y(e, t = {}) {
111
+ let n = (t, n) => e(n).update(t).digest(), r = e(void 0);
112
+ return n.outputLen = r.outputLen, n.blockLen = r.blockLen, n.canXOF = r.canXOF, n.create = (t) => e(t), Object.assign(n, t), Object.freeze(n);
113
+ }
114
+ function b(e = 32) {
115
+ r(e, "bytesLength");
116
+ let t = typeof globalThis == "object" ? globalThis.crypto : null;
117
+ if (typeof t?.getRandomValues != "function") throw Error("crypto.getRandomValues must be defined");
118
+ if (e > 65536) throw RangeError(`"bytesLength" expected <= 65536, got ${e}`);
119
+ return t.getRandomValues(new Uint8Array(e));
120
+ }
121
+ var x = (e) => ({ oid: Uint8Array.from([
122
+ 6,
123
+ 9,
124
+ 96,
125
+ 134,
126
+ 72,
127
+ 1,
128
+ 101,
129
+ 3,
130
+ 4,
131
+ 2,
132
+ e
133
+ ]) });
134
+ //#endregion
135
+ //#region node_modules/@noble/hashes/_md.js
136
+ function S(e, t, n) {
137
+ return e & t ^ ~e & n;
138
+ }
139
+ function C(e, t, n) {
140
+ return e & t ^ e & n ^ t & n;
141
+ }
142
+ var w = class {
143
+ blockLen;
144
+ outputLen;
145
+ canXOF = !1;
146
+ padOffset;
147
+ isLE;
148
+ buffer;
149
+ view;
150
+ finished = !1;
151
+ length = 0;
152
+ pos = 0;
153
+ destroyed = !1;
154
+ constructor(e, t, n, r) {
155
+ this.blockLen = e, this.outputLen = t, this.padOffset = n, this.isLE = r, this.buffer = new Uint8Array(e), this.view = l(this.buffer);
156
+ }
157
+ update(e) {
158
+ o(this), i(e);
159
+ let { view: t, buffer: n, blockLen: r } = this, a = e.length;
160
+ for (let i = 0; i < a;) {
161
+ let o = Math.min(r - this.pos, a - i);
162
+ if (o === r) {
163
+ let t = l(e);
164
+ for (; r <= a - i; i += r) this.process(t, i);
165
+ continue;
166
+ }
167
+ n.set(e.subarray(i, i + o), this.pos), this.pos += o, i += o, this.pos === r && (this.process(t, 0), this.pos = 0);
168
+ }
169
+ return this.length += e.length, this.roundClean(), this;
170
+ }
171
+ digestInto(e) {
172
+ o(this), s(e, this), this.finished = !0;
173
+ let { buffer: t, view: n, blockLen: r, isLE: i } = this, { pos: a } = this;
174
+ t[a++] = 128, c(this.buffer.subarray(a)), this.padOffset > r - a && (this.process(n, 0), a = 0);
175
+ for (let e = a; e < r; e++) t[e] = 0;
176
+ n.setBigUint64(r - 8, BigInt(this.length * 8), i), this.process(n, 0);
177
+ let u = l(e), d = this.outputLen;
178
+ if (d % 4) throw Error("_sha2: outputLen must be aligned to 32bit");
179
+ let f = d / 4, p = this.get();
180
+ if (f > p.length) throw Error("_sha2: outputLen bigger than state");
181
+ for (let e = 0; e < f; e++) u.setUint32(4 * e, p[e], i);
182
+ }
183
+ digest() {
184
+ let { buffer: e, outputLen: t } = this;
185
+ this.digestInto(e);
186
+ let n = e.slice(0, t);
187
+ return this.destroy(), n;
188
+ }
189
+ _cloneInto(e) {
190
+ e ||= new this.constructor(), e.set(...this.get());
191
+ let { blockLen: t, buffer: n, length: r, finished: i, destroyed: a, pos: o } = this;
192
+ return e.destroyed = a, e.finished = i, e.length = r, e.pos = o, r % t && e.buffer.set(n), e;
193
+ }
194
+ clone() {
195
+ return this._cloneInto();
196
+ }
197
+ }, T = /* @__PURE__ */ Uint32Array.from([
198
+ 1779033703,
199
+ 3144134277,
200
+ 1013904242,
201
+ 2773480762,
202
+ 1359893119,
203
+ 2600822924,
204
+ 528734635,
205
+ 1541459225
206
+ ]), E = /* @__PURE__ */ Uint32Array.from([
207
+ 1116352408,
208
+ 1899447441,
209
+ 3049323471,
210
+ 3921009573,
211
+ 961987163,
212
+ 1508970993,
213
+ 2453635748,
214
+ 2870763221,
215
+ 3624381080,
216
+ 310598401,
217
+ 607225278,
218
+ 1426881987,
219
+ 1925078388,
220
+ 2162078206,
221
+ 2614888103,
222
+ 3248222580,
223
+ 3835390401,
224
+ 4022224774,
225
+ 264347078,
226
+ 604807628,
227
+ 770255983,
228
+ 1249150122,
229
+ 1555081692,
230
+ 1996064986,
231
+ 2554220882,
232
+ 2821834349,
233
+ 2952996808,
234
+ 3210313671,
235
+ 3336571891,
236
+ 3584528711,
237
+ 113926993,
238
+ 338241895,
239
+ 666307205,
240
+ 773529912,
241
+ 1294757372,
242
+ 1396182291,
243
+ 1695183700,
244
+ 1986661051,
245
+ 2177026350,
246
+ 2456956037,
247
+ 2730485921,
248
+ 2820302411,
249
+ 3259730800,
250
+ 3345764771,
251
+ 3516065817,
252
+ 3600352804,
253
+ 4094571909,
254
+ 275423344,
255
+ 430227734,
256
+ 506948616,
257
+ 659060556,
258
+ 883997877,
259
+ 958139571,
260
+ 1322822218,
261
+ 1537002063,
262
+ 1747873779,
263
+ 1955562222,
264
+ 2024104815,
265
+ 2227730452,
266
+ 2361852424,
267
+ 2428436474,
268
+ 2756734187,
269
+ 3204031479,
270
+ 3329325298
271
+ ]), D = /* @__PURE__ */ new Uint32Array(64), ee = class extends w {
272
+ constructor(e) {
273
+ super(64, e, 8, !1);
274
+ }
275
+ get() {
276
+ let { A: e, B: t, C: n, D: r, E: i, F: a, G: o, H: s } = this;
277
+ return [
278
+ e,
279
+ t,
280
+ n,
281
+ r,
282
+ i,
283
+ a,
284
+ o,
285
+ s
286
+ ];
287
+ }
288
+ set(e, t, n, r, i, a, o, s) {
289
+ this.A = e | 0, this.B = t | 0, this.C = n | 0, this.D = r | 0, this.E = i | 0, this.F = a | 0, this.G = o | 0, this.H = s | 0;
290
+ }
291
+ process(e, t) {
292
+ for (let n = 0; n < 16; n++, t += 4) D[n] = e.getUint32(t, !1);
293
+ for (let e = 16; e < 64; e++) {
294
+ let t = D[e - 15], n = D[e - 2], r = u(t, 7) ^ u(t, 18) ^ t >>> 3;
295
+ D[e] = (u(n, 17) ^ u(n, 19) ^ n >>> 10) + D[e - 7] + r + D[e - 16] | 0;
296
+ }
297
+ let { A: n, B: r, C: i, D: a, E: o, F: s, G: c, H: l } = this;
298
+ for (let e = 0; e < 64; e++) {
299
+ let t = u(o, 6) ^ u(o, 11) ^ u(o, 25), d = l + t + S(o, s, c) + E[e] + D[e] | 0, f = (u(n, 2) ^ u(n, 13) ^ u(n, 22)) + C(n, r, i) | 0;
300
+ l = c, c = s, s = o, o = a + d | 0, a = i, i = r, r = n, n = d + f | 0;
301
+ }
302
+ n = n + this.A | 0, r = r + this.B | 0, i = i + this.C | 0, a = a + this.D | 0, o = o + this.E | 0, s = s + this.F | 0, c = c + this.G | 0, l = l + this.H | 0, this.set(n, r, i, a, o, s, c, l);
303
+ }
304
+ roundClean() {
305
+ c(D);
306
+ }
307
+ destroy() {
308
+ this.destroyed = !0, this.set(0, 0, 0, 0, 0, 0, 0, 0), c(this.buffer);
309
+ }
310
+ }, te = class extends ee {
311
+ A = T[0] | 0;
312
+ B = T[1] | 0;
313
+ C = T[2] | 0;
314
+ D = T[3] | 0;
315
+ E = T[4] | 0;
316
+ F = T[5] | 0;
317
+ G = T[6] | 0;
318
+ H = T[7] | 0;
319
+ constructor() {
320
+ super(32);
321
+ }
322
+ }, O = /* @__PURE__ */ y(() => new te(), /* @__PURE__ */ x(1)), k = (e, t, n) => i(e, t, n), A = r, ne = m, j = (...e) => v(...e), M = (e) => _(e), re = n, ie = (e) => b(e), N = /* @__PURE__ */ BigInt(0), P = /* @__PURE__ */ BigInt(1);
323
+ function F(e, t = "") {
324
+ if (typeof e != "boolean") {
325
+ let n = t && `"${t}" `;
326
+ throw TypeError(n + "expected boolean, got type=" + typeof e);
327
+ }
328
+ return e;
329
+ }
330
+ function ae(e) {
331
+ if (typeof e == "bigint") {
332
+ if (!R(e)) throw RangeError("positive bigint expected, got " + e);
333
+ } else A(e);
334
+ return e;
335
+ }
336
+ function oe(e, t = "") {
337
+ if (typeof e != "number") {
338
+ let n = t && `"${t}" `;
339
+ throw TypeError(n + "expected number, got type=" + typeof e);
340
+ }
341
+ if (!Number.isSafeInteger(e)) {
342
+ let n = t && `"${t}" `;
343
+ throw RangeError(n + "expected safe integer, got " + e);
344
+ }
345
+ }
346
+ function I(e) {
347
+ let t = ae(e).toString(16);
348
+ return t.length & 1 ? "0" + t : t;
349
+ }
350
+ function se(e) {
351
+ if (typeof e != "string") throw TypeError("hex string expected, got " + typeof e);
352
+ return e === "" ? N : BigInt("0x" + e);
353
+ }
354
+ function L(e) {
355
+ return se(m(e));
356
+ }
357
+ function ce(e) {
358
+ return se(m(de(i(e)).reverse()));
359
+ }
360
+ function le(e, t) {
361
+ if (r(t), t === 0) throw RangeError("zero length");
362
+ e = ae(e);
363
+ let n = e.toString(16);
364
+ if (n.length > t * 2) throw RangeError("number too large");
365
+ return _(n.padStart(t * 2, "0"));
366
+ }
367
+ function ue(e, t) {
368
+ return le(e, t).reverse();
321
369
  }
322
370
  function de(e) {
323
- if (typeof e == "bigint") {
324
- if (!Et(e))
325
- throw new Error("positive bigint expected, got " + e);
326
- } else
327
- at(e);
328
- return e;
329
- }
330
- function pt(e) {
331
- const t = de(e).toString(16);
332
- return t.length & 1 ? "0" + t : t;
333
- }
334
- function he(e) {
335
- if (typeof e != "string")
336
- throw new Error("hex string expected, got " + typeof e);
337
- return e === "" ? Vt : BigInt("0x" + e);
338
- }
339
- function Ut(e) {
340
- return he(Lt(e));
341
- }
342
- function ge(e) {
343
- return he(Lt(en(N(e)).reverse()));
344
- }
345
- function Mt(e, t) {
346
- at(t), e = de(e);
347
- const r = Rt(e.toString(16).padStart(t * 2, "0"));
348
- if (r.length !== t)
349
- throw new Error("number too large");
350
- return r;
371
+ return Uint8Array.from(k(e));
372
+ }
373
+ var R = (e) => typeof e == "bigint" && N <= e;
374
+ function fe(e, t, n) {
375
+ return R(e) && R(t) && R(n) && t <= e && e < n;
376
+ }
377
+ function pe(e, t, n, r) {
378
+ if (!fe(t, n, r)) throw RangeError("expected valid " + e + ": " + n + " <= n < " + r + ", got " + t);
379
+ }
380
+ function me(e) {
381
+ if (e < N) throw Error("expected non-negative bigint, got " + e);
382
+ let t;
383
+ for (t = 0; e > N; e >>= P, t += 1);
384
+ return t;
385
+ }
386
+ var he = (e) => (P << BigInt(e)) - P;
387
+ function ge(e, t, n) {
388
+ if (r(e, "hashLen"), r(t, "qByteLen"), typeof n != "function") throw TypeError("hmacFn must be a function");
389
+ let i = (e) => new Uint8Array(e), a = Uint8Array.of(), o = Uint8Array.of(0), s = Uint8Array.of(1), c = i(e), l = i(e), u = 0, d = () => {
390
+ c.fill(1), l.fill(0), u = 0;
391
+ }, f = (...e) => n(l, j(c, ...e)), p = (e = a) => {
392
+ l = f(o, e), c = f(), e.length !== 0 && (l = f(s, e), c = f());
393
+ }, m = () => {
394
+ if (u++ >= 1e3) throw Error("drbg: tried max amount of iterations");
395
+ let e = 0, n = [];
396
+ for (; e < t;) {
397
+ c = f();
398
+ let t = c.slice();
399
+ n.push(t), e += c.length;
400
+ }
401
+ return j(...n);
402
+ };
403
+ return (e, t) => {
404
+ d(), p(e);
405
+ let n;
406
+ for (; (n = t(m())) === void 0;) p();
407
+ return d(), n;
408
+ };
409
+ }
410
+ function z(e, t = {}, n = {}) {
411
+ if (Object.prototype.toString.call(e) !== "[object Object]") throw TypeError("expected valid options object");
412
+ function r(t, n, r) {
413
+ if (!r && n !== "function" && !Object.hasOwn(e, t)) throw TypeError(`param "${t}" is invalid: expected own property`);
414
+ let i = e[t];
415
+ if (r && i === void 0) return;
416
+ let a = typeof i;
417
+ if (a !== n || i === null) throw TypeError(`param "${t}" is invalid: expected ${n}, got ${a}`);
418
+ }
419
+ let i = (e, t) => Object.entries(e).forEach(([e, n]) => r(e, n, t));
420
+ i(t, !1), i(n, !0);
421
+ }
422
+ //#endregion
423
+ //#region node_modules/@noble/curves/abstract/modular.js
424
+ var B = /* @__PURE__ */ BigInt(0), V = /* @__PURE__ */ BigInt(1), H = /* @__PURE__ */ BigInt(2), _e = /* @__PURE__ */ BigInt(3), ve = /* @__PURE__ */ BigInt(4), ye = /* @__PURE__ */ BigInt(5), be = /* @__PURE__ */ BigInt(7), xe = /* @__PURE__ */ BigInt(8), Se = /* @__PURE__ */ BigInt(9), Ce = /* @__PURE__ */ BigInt(16);
425
+ function U(e, t) {
426
+ if (t <= B) throw Error("mod: expected positive modulus, got " + t);
427
+ let n = e % t;
428
+ return n >= B ? n : t + n;
429
+ }
430
+ function W(e, t, n) {
431
+ if (t < B) throw Error("pow2: expected non-negative exponent, got " + t);
432
+ let r = e;
433
+ for (; t-- > B;) r *= r, r %= n;
434
+ return r;
351
435
  }
352
436
  function we(e, t) {
353
- return Mt(e, t).reverse();
354
- }
355
- function en(e) {
356
- return Uint8Array.from(e);
357
- }
358
- const Et = (e) => typeof e == "bigint" && Vt <= e;
359
- function nn(e, t, r) {
360
- return Et(e) && Et(t) && Et(r) && t <= e && e < r;
361
- }
362
- function rn(e, t, r, n) {
363
- if (!nn(t, r, n))
364
- throw new Error("expected valid " + e + ": " + r + " <= n < " + n + ", got " + t);
365
- }
366
- function sn(e) {
367
- let t;
368
- for (t = 0; e > Vt; e >>= $t, t += 1)
369
- ;
370
- return t;
371
- }
372
- const Yt = (e) => ($t << BigInt(e)) - $t;
373
- function on(e, t, r) {
374
- if (at(e, "hashLen"), at(t, "qByteLen"), typeof r != "function")
375
- throw new Error("hmacFn must be a function");
376
- const n = (I) => new Uint8Array(I), s = Uint8Array.of(), o = Uint8Array.of(0), i = Uint8Array.of(1), c = 1e3;
377
- let f = n(e), u = n(e), h = 0;
378
- const d = () => {
379
- f.fill(1), u.fill(0), h = 0;
380
- }, x = (...I) => r(u, it(f, ...I)), g = (I = s) => {
381
- u = x(o, I), f = x(), I.length !== 0 && (u = x(i, I), f = x());
382
- }, y = () => {
383
- if (h++ >= c)
384
- throw new Error("drbg: tried max amount of iterations");
385
- let I = 0;
386
- const O = [];
387
- for (; I < t; ) {
388
- f = x();
389
- const j = f.slice();
390
- O.push(j), I += f.length;
391
- }
392
- return it(...O);
393
- };
394
- return (I, O) => {
395
- d(), g(I);
396
- let j;
397
- for (; !(j = O(y())); )
398
- g();
399
- return d(), j;
400
- };
401
- }
402
- function jt(e, t = {}, r = {}) {
403
- if (!e || typeof e != "object")
404
- throw new Error("expected valid options object");
405
- function n(o, i, c) {
406
- const f = e[o];
407
- if (c && f === void 0)
408
- return;
409
- const u = typeof f;
410
- if (u !== i || f === null)
411
- throw new Error(`param "${o}" is invalid: expected ${i}, got ${u}`);
412
- }
413
- const s = (o, i) => Object.entries(o).forEach(([c, f]) => n(c, f, i));
414
- s(t, !1), s(r, !0);
415
- }
416
- function Pt(e) {
417
- const t = /* @__PURE__ */ new WeakMap();
418
- return (r, ...n) => {
419
- const s = t.get(r);
420
- if (s !== void 0)
421
- return s;
422
- const o = e(r, ...n);
423
- return t.set(r, o), o;
424
- };
425
- }
426
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
427
- const Y = /* @__PURE__ */ BigInt(0), M = /* @__PURE__ */ BigInt(1), ft = /* @__PURE__ */ BigInt(2), be = /* @__PURE__ */ BigInt(3), pe = /* @__PURE__ */ BigInt(4), ye = /* @__PURE__ */ BigInt(5), cn = /* @__PURE__ */ BigInt(7), xe = /* @__PURE__ */ BigInt(8), fn = /* @__PURE__ */ BigInt(9), me = /* @__PURE__ */ BigInt(16);
428
- function F(e, t) {
429
- const r = e % t;
430
- return r >= Y ? r : t + r;
431
- }
432
- function X(e, t, r) {
433
- let n = e;
434
- for (; t-- > Y; )
435
- n *= n, n %= r;
436
- return n;
437
- }
438
- function Qt(e, t) {
439
- if (e === Y)
440
- throw new Error("invert: expected non-zero number");
441
- if (t <= Y)
442
- throw new Error("invert: expected positive modulus, got " + t);
443
- let r = F(e, t), n = t, s = Y, o = M;
444
- for (; r !== Y; ) {
445
- const c = n / r, f = n % r, u = s - o * c;
446
- n = r, r = f, s = o, o = u;
447
- }
448
- if (n !== M)
449
- throw new Error("invert: does not exist");
450
- return F(s, t);
451
- }
452
- function Kt(e, t, r) {
453
- if (!e.eql(e.sqr(t), r))
454
- throw new Error("Cannot find square root");
437
+ if (e === B) throw Error("invert: expected non-zero number");
438
+ if (t <= B) throw Error("invert: expected positive modulus, got " + t);
439
+ let n = U(e, t), r = t, i = B, a = V, o = V, s = B;
440
+ for (; n !== B;) {
441
+ let e = r / n, t = r - n * e, c = i - o * e, l = a - s * e;
442
+ r = n, n = t, i = o, a = s, o = c, s = l;
443
+ }
444
+ if (r !== V) throw Error("invert: does not exist");
445
+ return U(i, t);
446
+ }
447
+ function Te(e, t, n) {
448
+ let r = e;
449
+ if (!r.eql(r.sqr(t), n)) throw Error("Cannot find square root");
455
450
  }
456
451
  function Ee(e, t) {
457
- const r = (e.ORDER + M) / pe, n = e.pow(t, r);
458
- return Kt(e, n, t), n;
459
- }
460
- function un(e, t) {
461
- const r = (e.ORDER - ye) / xe, n = e.mul(t, ft), s = e.pow(n, r), o = e.mul(t, s), i = e.mul(e.mul(o, ft), s), c = e.mul(o, e.sub(i, e.ONE));
462
- return Kt(e, c, t), c;
463
- }
464
- function an(e) {
465
- const t = St(e), r = Be(e), n = r(t, t.neg(t.ONE)), s = r(t, n), o = r(t, t.neg(n)), i = (e + cn) / me;
466
- return (c, f) => {
467
- let u = c.pow(f, i), h = c.mul(u, n);
468
- const d = c.mul(u, s), x = c.mul(u, o), g = c.eql(c.sqr(h), f), y = c.eql(c.sqr(d), f);
469
- u = c.cmov(u, h, g), h = c.cmov(x, d, y);
470
- const U = c.eql(c.sqr(h), f), I = c.cmov(u, h, U);
471
- return Kt(c, I, f), I;
472
- };
452
+ let n = e, r = (n.ORDER + V) / ve, i = n.pow(t, r);
453
+ return Te(n, i, t), i;
473
454
  }
474
- function Be(e) {
475
- if (e < be)
476
- throw new Error("sqrt is not defined for small field");
477
- let t = e - M, r = 0;
478
- for (; t % ft === Y; )
479
- t /= ft, r++;
480
- let n = ft;
481
- const s = St(e);
482
- for (; Jt(s, n) === 1; )
483
- if (n++ > 1e3)
484
- throw new Error("Cannot find square root: probably non-prime P");
485
- if (r === 1)
486
- return Ee;
487
- let o = s.pow(n, t);
488
- const i = (t + M) / ft;
489
- return function(f, u) {
490
- if (f.is0(u))
491
- return u;
492
- if (Jt(f, u) !== 1)
493
- throw new Error("Cannot find square root");
494
- let h = r, d = f.mul(f.ONE, o), x = f.pow(u, t), g = f.pow(u, i);
495
- for (; !f.eql(x, f.ONE); ) {
496
- if (f.is0(x))
497
- return f.ZERO;
498
- let y = 1, U = f.sqr(x);
499
- for (; !f.eql(U, f.ONE); )
500
- if (y++, U = f.sqr(U), y === h)
501
- throw new Error("Cannot find square root");
502
- const I = M << BigInt(h - y - 1), O = f.pow(d, I);
503
- h = y, d = f.sqr(O), x = f.mul(x, d), g = f.mul(g, O);
504
- }
505
- return g;
506
- };
507
- }
508
- function ln(e) {
509
- return e % pe === be ? Ee : e % xe === ye ? un : e % me === fn ? an(e) : Be(e);
510
- }
511
- const dn = [
512
- "create",
513
- "isValid",
514
- "is0",
515
- "neg",
516
- "inv",
517
- "sqrt",
518
- "sqr",
519
- "eql",
520
- "add",
521
- "sub",
522
- "mul",
523
- "pow",
524
- "div",
525
- "addN",
526
- "subN",
527
- "mulN",
528
- "sqrN"
529
- ];
530
- function hn(e) {
531
- const t = {
532
- ORDER: "bigint",
533
- BYTES: "number",
534
- BITS: "number"
535
- }, r = dn.reduce((n, s) => (n[s] = "function", n), t);
536
- return jt(e, r), e;
537
- }
538
- function gn(e, t, r) {
539
- if (r < Y)
540
- throw new Error("invalid exponent, negatives unsupported");
541
- if (r === Y)
542
- return e.ONE;
543
- if (r === M)
544
- return t;
545
- let n = e.ONE, s = t;
546
- for (; r > Y; )
547
- r & M && (n = e.mul(n, s)), s = e.sqr(s), r >>= M;
548
- return n;
549
- }
550
- function ve(e, t, r = !1) {
551
- const n = new Array(t.length).fill(r ? e.ZERO : void 0), s = t.reduce((i, c, f) => e.is0(c) ? i : (n[f] = i, e.mul(i, c)), e.ONE), o = e.inv(s);
552
- return t.reduceRight((i, c, f) => e.is0(c) ? i : (n[f] = e.mul(i, n[f]), e.mul(i, c)), o), n;
553
- }
554
- function Jt(e, t) {
555
- const r = (e.ORDER - M) / ft, n = e.pow(t, r), s = e.eql(n, e.ONE), o = e.eql(n, e.ZERO), i = e.eql(n, e.neg(e.ONE));
556
- if (!s && !o && !i)
557
- throw new Error("invalid Legendre symbol result");
558
- return s ? 1 : o ? 0 : -1;
559
- }
560
- function wn(e, t) {
561
- t !== void 0 && at(t);
562
- const r = t !== void 0 ? t : e.toString(2).length, n = Math.ceil(r / 8);
563
- return { nBitLength: r, nByteLength: n };
564
- }
565
- class bn {
566
- constructor(t, r = {}) {
567
- m(this, "ORDER");
568
- m(this, "BITS");
569
- m(this, "BYTES");
570
- m(this, "isLE");
571
- m(this, "ZERO", Y);
572
- m(this, "ONE", M);
573
- m(this, "_lengths");
574
- m(this, "_sqrt");
575
- // cached sqrt
576
- m(this, "_mod");
577
- var i;
578
- if (t <= Y)
579
- throw new Error("invalid field: expected ORDER > 0, got " + t);
580
- let n;
581
- this.isLE = !1, r != null && typeof r == "object" && (typeof r.BITS == "number" && (n = r.BITS), typeof r.sqrt == "function" && (this.sqrt = r.sqrt), typeof r.isLE == "boolean" && (this.isLE = r.isLE), r.allowedLengths && (this._lengths = (i = r.allowedLengths) == null ? void 0 : i.slice()), typeof r.modFromBytes == "boolean" && (this._mod = r.modFromBytes));
582
- const { nBitLength: s, nByteLength: o } = wn(t, n);
583
- if (o > 2048)
584
- throw new Error("invalid field: expected ORDER of <= 2048 bytes");
585
- this.ORDER = t, this.BITS = s, this.BYTES = o, this._sqrt = void 0, Object.preventExtensions(this);
586
- }
587
- create(t) {
588
- return F(t, this.ORDER);
589
- }
590
- isValid(t) {
591
- if (typeof t != "bigint")
592
- throw new Error("invalid field element: expected bigint, got " + typeof t);
593
- return Y <= t && t < this.ORDER;
594
- }
595
- is0(t) {
596
- return t === Y;
597
- }
598
- // is valid and invertible
599
- isValidNot0(t) {
600
- return !this.is0(t) && this.isValid(t);
601
- }
602
- isOdd(t) {
603
- return (t & M) === M;
604
- }
605
- neg(t) {
606
- return F(-t, this.ORDER);
607
- }
608
- eql(t, r) {
609
- return t === r;
610
- }
611
- sqr(t) {
612
- return F(t * t, this.ORDER);
613
- }
614
- add(t, r) {
615
- return F(t + r, this.ORDER);
616
- }
617
- sub(t, r) {
618
- return F(t - r, this.ORDER);
619
- }
620
- mul(t, r) {
621
- return F(t * r, this.ORDER);
622
- }
623
- pow(t, r) {
624
- return gn(this, t, r);
625
- }
626
- div(t, r) {
627
- return F(t * Qt(r, this.ORDER), this.ORDER);
628
- }
629
- // Same as above, but doesn't normalize
630
- sqrN(t) {
631
- return t * t;
632
- }
633
- addN(t, r) {
634
- return t + r;
635
- }
636
- subN(t, r) {
637
- return t - r;
638
- }
639
- mulN(t, r) {
640
- return t * r;
641
- }
642
- inv(t) {
643
- return Qt(t, this.ORDER);
644
- }
645
- sqrt(t) {
646
- return this._sqrt || (this._sqrt = ln(this.ORDER)), this._sqrt(this, t);
647
- }
648
- toBytes(t) {
649
- return this.isLE ? we(t, this.BYTES) : Mt(t, this.BYTES);
650
- }
651
- fromBytes(t, r = !1) {
652
- N(t);
653
- const { _lengths: n, BYTES: s, isLE: o, ORDER: i, _mod: c } = this;
654
- if (n) {
655
- if (!n.includes(t.length) || t.length > s)
656
- throw new Error("Field.fromBytes: expected " + n + " bytes, got " + t.length);
657
- const u = new Uint8Array(s);
658
- u.set(t, o ? 0 : u.length - t.length), t = u;
659
- }
660
- if (t.length !== s)
661
- throw new Error("Field.fromBytes: expected " + s + " bytes, got " + t.length);
662
- let f = o ? ge(t) : Ut(t);
663
- if (c && (f = F(f, i)), !r && !this.isValid(f))
664
- throw new Error("invalid field element: outside of range 0..ORDER");
665
- return f;
666
- }
667
- // TODO: we don't need it here, move out to separate fn
668
- invertBatch(t) {
669
- return ve(this, t);
670
- }
671
- // We can't move this out because Fp6, Fp12 implement it
672
- // and it's unclear what to return in there.
673
- cmov(t, r, n) {
674
- return n ? r : t;
675
- }
676
- }
677
- function St(e, t = {}) {
678
- return new bn(e, t);
679
- }
680
- function Re(e) {
681
- if (typeof e != "bigint")
682
- throw new Error("field order must be bigint");
683
- const t = e.toString(2).length;
684
- return Math.ceil(t / 8);
455
+ function De(e, t) {
456
+ let n = e, r = (n.ORDER - ye) / xe, i = n.mul(t, H), a = n.pow(i, r), o = n.mul(t, a), s = n.mul(n.mul(o, H), a), c = n.mul(o, n.sub(s, n.ONE));
457
+ return Te(n, c, t), c;
458
+ }
459
+ function Oe(e) {
460
+ let t = G(e), n = ke(e), r = n(t, t.neg(t.ONE)), i = n(t, r), a = n(t, t.neg(r)), o = (e + be) / Ce;
461
+ return ((e, t) => {
462
+ let n = e, s = n.pow(t, o), c = n.mul(s, r), l = n.mul(s, i), u = n.mul(s, a), d = n.eql(n.sqr(c), t), f = n.eql(n.sqr(l), t);
463
+ s = n.cmov(s, c, d), c = n.cmov(u, l, f);
464
+ let p = n.eql(n.sqr(c), t), m = n.cmov(s, c, p);
465
+ return Te(n, m, t), m;
466
+ });
467
+ }
468
+ function ke(e) {
469
+ if (e < _e) throw Error("sqrt is not defined for small field");
470
+ let t = e - V, n = 0;
471
+ for (; t % H === B;) t /= H, n++;
472
+ let r = H, i = G(e);
473
+ for (; Fe(i, r) === 1;) if (r++ > 1e3) throw Error("Cannot find square root: probably non-prime P");
474
+ if (n === 1) return Ee;
475
+ let a = i.pow(r, t), o = (t + V) / H;
476
+ return function(e, r) {
477
+ let i = e;
478
+ if (i.is0(r)) return r;
479
+ if (Fe(i, r) !== 1) throw Error("Cannot find square root");
480
+ let s = n, c = i.mul(i.ONE, a), l = i.pow(r, t), u = i.pow(r, o);
481
+ for (; !i.eql(l, i.ONE);) {
482
+ if (i.is0(l)) return i.ZERO;
483
+ let e = 1, t = i.sqr(l);
484
+ for (; !i.eql(t, i.ONE);) if (e++, t = i.sqr(t), e === s) throw Error("Cannot find square root");
485
+ let n = V << BigInt(s - e - 1), r = i.pow(c, n);
486
+ s = e, c = i.sqr(r), l = i.mul(l, c), u = i.mul(u, r);
487
+ }
488
+ return u;
489
+ };
685
490
  }
686
491
  function Ae(e) {
687
- const t = Re(e);
688
- return t + Math.ceil(t / 2);
689
- }
690
- function pn(e, t, r = !1) {
691
- N(e);
692
- const n = e.length, s = Re(t), o = Ae(t);
693
- if (n < 16 || n < o || n > 1024)
694
- throw new Error("expected " + o + "-1024 bytes of input, got " + n);
695
- const i = r ? ge(e) : Ut(e), c = F(i, t - M) + M;
696
- return r ? we(c, s) : Mt(c, s);
697
- }
698
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
699
- const dt = /* @__PURE__ */ BigInt(0), ut = /* @__PURE__ */ BigInt(1);
700
- function It(e, t) {
701
- const r = t.negate();
702
- return e ? r : t;
703
- }
704
- function te(e, t) {
705
- const r = ve(e.Fp, t.map((n) => n.Z));
706
- return t.map((n, s) => e.fromAffine(n.toAffine(r[s])));
492
+ return e % ve === _e ? Ee : e % xe === ye ? De : e % Ce === Se ? Oe(e) : ke(e);
493
+ }
494
+ var je = [
495
+ "create",
496
+ "isValid",
497
+ "is0",
498
+ "neg",
499
+ "inv",
500
+ "sqrt",
501
+ "sqr",
502
+ "eql",
503
+ "add",
504
+ "sub",
505
+ "mul",
506
+ "pow",
507
+ "div",
508
+ "addN",
509
+ "subN",
510
+ "mulN",
511
+ "sqrN"
512
+ ];
513
+ function Me(e) {
514
+ if (z(e, je.reduce((e, t) => (e[t] = "function", e), {
515
+ ORDER: "bigint",
516
+ BYTES: "number",
517
+ BITS: "number"
518
+ })), oe(e.BYTES, "BYTES"), oe(e.BITS, "BITS"), e.BYTES < 1 || e.BITS < 1) throw Error("invalid field: expected BYTES/BITS > 0");
519
+ if (e.ORDER <= V) throw Error("invalid field: expected ORDER > 1, got " + e.ORDER);
520
+ return e;
521
+ }
522
+ function Ne(e, t, n) {
523
+ let r = e;
524
+ if (n < B) throw Error("invalid exponent, negatives unsupported");
525
+ if (n === B) return r.ONE;
526
+ if (n === V) return t;
527
+ let i = r.ONE, a = t;
528
+ for (; n > B;) n & V && (i = r.mul(i, a)), a = r.sqr(a), n >>= V;
529
+ return i;
530
+ }
531
+ function Pe(e, t, n = !1) {
532
+ let r = e, i = Array(t.length).fill(n ? r.ZERO : void 0), a = t.reduce((e, t, n) => r.is0(t) ? e : (i[n] = e, r.mul(e, t)), r.ONE), o = r.inv(a);
533
+ return t.reduceRight((e, t, n) => r.is0(t) ? e : (i[n] = r.mul(e, i[n]), r.mul(e, t)), o), i;
534
+ }
535
+ function Fe(e, t) {
536
+ let n = e, r = (n.ORDER - V) / H, i = n.pow(t, r), a = n.eql(i, n.ONE), o = n.eql(i, n.ZERO), s = n.eql(i, n.neg(n.ONE));
537
+ if (!a && !o && !s) throw Error("invalid Legendre symbol result");
538
+ return a ? 1 : o ? 0 : -1;
707
539
  }
708
540
  function Ie(e, t) {
709
- if (!Number.isSafeInteger(e) || e <= 0 || e > t)
710
- throw new Error("invalid window size, expected [1.." + t + "], got W=" + e);
711
- }
712
- function Ht(e, t) {
713
- Ie(e, t);
714
- const r = Math.ceil(t / e) + 1, n = 2 ** (e - 1), s = 2 ** e, o = Yt(e), i = BigInt(e);
715
- return { windows: r, windowSize: n, mask: o, maxNumber: s, shiftBy: i };
716
- }
717
- function ee(e, t, r) {
718
- const { windowSize: n, mask: s, maxNumber: o, shiftBy: i } = r;
719
- let c = Number(e & s), f = e >> i;
720
- c > n && (c -= o, f += ut);
721
- const u = t * n, h = u + Math.abs(c) - 1, d = c === 0, x = c < 0, g = t % 2 !== 0;
722
- return { nextN: f, offset: h, isZero: d, isNeg: x, isNegF: g, offsetF: u };
723
- }
724
- const qt = /* @__PURE__ */ new WeakMap(), Le = /* @__PURE__ */ new WeakMap();
725
- function Nt(e) {
726
- return Le.get(e) || 1;
727
- }
728
- function ne(e) {
729
- if (e !== dt)
730
- throw new Error("invalid wNAF");
731
- }
732
- class yn {
733
- // Parametrized with a given Point class (not individual point)
734
- constructor(t, r) {
735
- m(this, "BASE");
736
- m(this, "ZERO");
737
- m(this, "Fn");
738
- m(this, "bits");
739
- this.BASE = t.BASE, this.ZERO = t.ZERO, this.Fn = t.Fn, this.bits = r;
740
- }
741
- // non-const time multiplication ladder
742
- _unsafeLadder(t, r, n = this.ZERO) {
743
- let s = t;
744
- for (; r > dt; )
745
- r & ut && (n = n.add(s)), s = s.double(), r >>= ut;
746
- return n;
747
- }
748
- /**
749
- * Creates a wNAF precomputation window. Used for caching.
750
- * Default window size is set by `utils.precompute()` and is equal to 8.
751
- * Number of precomputed points depends on the curve size:
752
- * 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
753
- * - 𝑊 is the window size
754
- * - 𝑛 is the bitlength of the curve order.
755
- * For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
756
- * @param point Point instance
757
- * @param W window size
758
- * @returns precomputed point tables flattened to a single array
759
- */
760
- precomputeWindow(t, r) {
761
- const { windows: n, windowSize: s } = Ht(r, this.bits), o = [];
762
- let i = t, c = i;
763
- for (let f = 0; f < n; f++) {
764
- c = i, o.push(c);
765
- for (let u = 1; u < s; u++)
766
- c = c.add(i), o.push(c);
767
- i = c.double();
768
- }
769
- return o;
770
- }
771
- /**
772
- * Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
773
- * More compact implementation:
774
- * https://github.com/paulmillr/noble-secp256k1/blob/47cb1669b6e506ad66b35fe7d76132ae97465da2/index.ts#L502-L541
775
- * @returns real and fake (for const-time) points
776
- */
777
- wNAF(t, r, n) {
778
- if (!this.Fn.isValid(n))
779
- throw new Error("invalid scalar");
780
- let s = this.ZERO, o = this.BASE;
781
- const i = Ht(t, this.bits);
782
- for (let c = 0; c < i.windows; c++) {
783
- const { nextN: f, offset: u, isZero: h, isNeg: d, isNegF: x, offsetF: g } = ee(n, c, i);
784
- n = f, h ? o = o.add(It(x, r[g])) : s = s.add(It(d, r[u]));
785
- }
786
- return ne(n), { p: s, f: o };
787
- }
788
- /**
789
- * Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
790
- * @param acc accumulator point to add result of multiplication
791
- * @returns point
792
- */
793
- wNAFUnsafe(t, r, n, s = this.ZERO) {
794
- const o = Ht(t, this.bits);
795
- for (let i = 0; i < o.windows && n !== dt; i++) {
796
- const { nextN: c, offset: f, isZero: u, isNeg: h } = ee(n, i, o);
797
- if (n = c, !u) {
798
- const d = r[f];
799
- s = s.add(h ? d.negate() : d);
800
- }
801
- }
802
- return ne(n), s;
803
- }
804
- getPrecomputes(t, r, n) {
805
- let s = qt.get(r);
806
- return s || (s = this.precomputeWindow(r, t), t !== 1 && (typeof n == "function" && (s = n(s)), qt.set(r, s))), s;
807
- }
808
- cached(t, r, n) {
809
- const s = Nt(t);
810
- return this.wNAF(s, this.getPrecomputes(s, t, n), r);
811
- }
812
- unsafe(t, r, n, s) {
813
- const o = Nt(t);
814
- return o === 1 ? this._unsafeLadder(t, r, s) : this.wNAFUnsafe(o, this.getPrecomputes(o, t, n), r, s);
815
- }
816
- // We calculate precomputes for elliptic curve point multiplication
817
- // using windowed method. This specifies window size and
818
- // stores precomputed values. Usually only base point would be precomputed.
819
- createCache(t, r) {
820
- Ie(r, this.bits), Le.set(t, r), qt.delete(t);
821
- }
822
- hasCache(t) {
823
- return Nt(t) !== 1;
824
- }
825
- }
826
- function xn(e, t, r, n) {
827
- let s = t, o = e.ZERO, i = e.ZERO;
828
- for (; r > dt || n > dt; )
829
- r & ut && (o = o.add(s)), n & ut && (i = i.add(s)), s = s.double(), r >>= ut, n >>= ut;
830
- return { p1: o, p2: i };
831
- }
832
- function re(e, t, r) {
833
- if (t) {
834
- if (t.ORDER !== e)
835
- throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
836
- return hn(t), t;
837
- } else
838
- return St(e, { isLE: r });
839
- }
840
- function mn(e, t, r = {}, n) {
841
- if (n === void 0 && (n = e === "edwards"), !t || typeof t != "object")
842
- throw new Error(`expected valid ${e} CURVE object`);
843
- for (const f of ["p", "n", "h"]) {
844
- const u = t[f];
845
- if (!(typeof u == "bigint" && u > dt))
846
- throw new Error(`CURVE.${f} must be positive bigint`);
847
- }
848
- const s = re(t.p, r.Fp, n), o = re(t.n, r.Fn, n), c = ["Gx", "Gy", "a", "b"];
849
- for (const f of c)
850
- if (!s.isValid(t[f]))
851
- throw new Error(`CURVE.${f} must be valid field element of CURVE.Fp`);
852
- return t = Object.freeze(Object.assign({}, t)), { CURVE: t, Fp: s, Fn: o };
853
- }
854
- function En(e, t) {
855
- return function(n) {
856
- const s = e(n);
857
- return { secretKey: s, publicKey: t(s) };
858
- };
859
- }
860
- class Ue {
861
- constructor(t, r) {
862
- m(this, "oHash");
863
- m(this, "iHash");
864
- m(this, "blockLen");
865
- m(this, "outputLen");
866
- m(this, "finished", !1);
867
- m(this, "destroyed", !1);
868
- if (ue(t), N(r, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
869
- throw new Error("Expected instance of class which extends utils.Hash");
870
- this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
871
- const n = this.blockLen, s = new Uint8Array(n);
872
- s.set(r.length > n ? t.create().update(r).digest() : r);
873
- for (let o = 0; o < s.length; o++)
874
- s[o] ^= 54;
875
- this.iHash.update(s), this.oHash = t.create();
876
- for (let o = 0; o < s.length; o++)
877
- s[o] ^= 106;
878
- this.oHash.update(s), vt(s);
879
- }
880
- update(t) {
881
- return Bt(this), this.iHash.update(t), this;
882
- }
883
- digestInto(t) {
884
- Bt(this), N(t, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
885
- }
886
- digest() {
887
- const t = new Uint8Array(this.oHash.outputLen);
888
- return this.digestInto(t), t;
889
- }
890
- _cloneInto(t) {
891
- t || (t = Object.create(Object.getPrototypeOf(this), {}));
892
- const { oHash: r, iHash: n, finished: s, destroyed: o, blockLen: i, outputLen: c } = this;
893
- return t = t, t.finished = s, t.destroyed = o, t.blockLen = i, t.outputLen = c, t.oHash = r._cloneInto(t.oHash), t.iHash = n._cloneInto(t.iHash), t;
894
- }
895
- clone() {
896
- return this._cloneInto();
897
- }
898
- destroy() {
899
- this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
900
- }
901
- }
902
- const Se = (e, t, r) => new Ue(e, t).update(r).digest();
903
- Se.create = (e, t) => new Ue(e, t);
904
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
905
- const se = (e, t) => (e + (e >= 0 ? t : -t) / _e) / t;
906
- function Bn(e, t, r) {
907
- const [[n, s], [o, i]] = t, c = se(i * e, r), f = se(-s * e, r);
908
- let u = e - c * n - f * o, h = -c * s - f * i;
909
- const d = u < tt, x = h < tt;
910
- d && (u = -u), x && (h = -h);
911
- const g = Yt(Math.ceil(sn(r) / 2)) + lt;
912
- if (u < tt || u >= g || h < tt || h >= g)
913
- throw new Error("splitScalar (endomorphism): failed, k=" + e);
914
- return { k1neg: d, k1: u, k2neg: x, k2: h };
915
- }
916
- function Zt(e) {
917
- if (!["compact", "recovered", "der"].includes(e))
918
- throw new Error('Signature format must be "compact", "recovered", or "der"');
919
- return e;
920
- }
921
- function kt(e, t) {
922
- const r = {};
923
- for (let n of Object.keys(t))
924
- r[n] = e[n] === void 0 ? t[n] : e[n];
925
- return At(r.lowS, "lowS"), At(r.prehash, "prehash"), r.format !== void 0 && Zt(r.format), r;
926
- }
927
- class vn extends Error {
928
- constructor(t = "") {
929
- super(t);
930
- }
931
- }
932
- const ot = {
933
- // asn.1 DER encoding utils
934
- Err: vn,
935
- // Basic building block is TLV (Tag-Length-Value)
936
- _tlv: {
937
- encode: (e, t) => {
938
- const { Err: r } = ot;
939
- if (e < 0 || e > 256)
940
- throw new r("tlv.encode: wrong tag");
941
- if (t.length & 1)
942
- throw new r("tlv.encode: unpadded data");
943
- const n = t.length / 2, s = pt(n);
944
- if (s.length / 2 & 128)
945
- throw new r("tlv.encode: long form length too big");
946
- const o = n > 127 ? pt(s.length / 2 | 128) : "";
947
- return pt(e) + o + s + t;
948
- },
949
- // v - value, l - left bytes (unparsed)
950
- decode(e, t) {
951
- const { Err: r } = ot;
952
- let n = 0;
953
- if (e < 0 || e > 256)
954
- throw new r("tlv.encode: wrong tag");
955
- if (t.length < 2 || t[n++] !== e)
956
- throw new r("tlv.decode: wrong tlv");
957
- const s = t[n++], o = !!(s & 128);
958
- let i = 0;
959
- if (!o)
960
- i = s;
961
- else {
962
- const f = s & 127;
963
- if (!f)
964
- throw new r("tlv.decode(long): indefinite length not supported");
965
- if (f > 4)
966
- throw new r("tlv.decode(long): byte length is too big");
967
- const u = t.subarray(n, n + f);
968
- if (u.length !== f)
969
- throw new r("tlv.decode: length bytes not complete");
970
- if (u[0] === 0)
971
- throw new r("tlv.decode(long): zero leftmost byte");
972
- for (const h of u)
973
- i = i << 8 | h;
974
- if (n += f, i < 128)
975
- throw new r("tlv.decode(long): not minimal encoding");
976
- }
977
- const c = t.subarray(n, n + i);
978
- if (c.length !== i)
979
- throw new r("tlv.decode: wrong value length");
980
- return { v: c, l: t.subarray(n + i) };
981
- }
982
- },
983
- // https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
984
- // since we always use positive integers here. It must always be empty:
985
- // - add zero byte if exists
986
- // - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
987
- _int: {
988
- encode(e) {
989
- const { Err: t } = ot;
990
- if (e < tt)
991
- throw new t("integer: negative integers are not allowed");
992
- let r = pt(e);
993
- if (Number.parseInt(r[0], 16) & 8 && (r = "00" + r), r.length & 1)
994
- throw new t("unexpected DER parsing assertion: unpadded hex");
995
- return r;
996
- },
997
- decode(e) {
998
- const { Err: t } = ot;
999
- if (e[0] & 128)
1000
- throw new t("invalid signature integer: negative");
1001
- if (e[0] === 0 && !(e[1] & 128))
1002
- throw new t("invalid signature integer: unnecessary leading zero");
1003
- return Ut(e);
1004
- }
1005
- },
1006
- toSig(e) {
1007
- const { Err: t, _int: r, _tlv: n } = ot, s = N(e, void 0, "signature"), { v: o, l: i } = n.decode(48, s);
1008
- if (i.length)
1009
- throw new t("invalid signature: left bytes after parsing");
1010
- const { v: c, l: f } = n.decode(2, o), { v: u, l: h } = n.decode(2, f);
1011
- if (h.length)
1012
- throw new t("invalid signature: left bytes after parsing");
1013
- return { r: r.decode(c), s: r.decode(u) };
1014
- },
1015
- hexFromSig(e) {
1016
- const { _tlv: t, _int: r } = ot, n = t.encode(2, r.encode(e.r)), s = t.encode(2, r.encode(e.s)), o = n + s;
1017
- return t.encode(48, o);
1018
- }
1019
- }, tt = BigInt(0), lt = BigInt(1), _e = BigInt(2), yt = BigInt(3), Rn = BigInt(4);
1020
- function An(e, t = {}) {
1021
- const r = mn("weierstrass", e, t), { Fp: n, Fn: s } = r;
1022
- let o = r.CURVE;
1023
- const { h: i, n: c } = o;
1024
- jt(t, {}, {
1025
- allowInfinityPoint: "boolean",
1026
- clearCofactor: "function",
1027
- isTorsionFree: "function",
1028
- fromBytes: "function",
1029
- toBytes: "function",
1030
- endo: "object"
1031
- });
1032
- const { endo: f } = t;
1033
- if (f && (!n.is0(o.a) || typeof f.beta != "bigint" || !Array.isArray(f.basises)))
1034
- throw new Error('invalid endo: expected "beta": bigint and "basises": array');
1035
- const u = He(n, s);
1036
- function h() {
1037
- if (!n.isOdd)
1038
- throw new Error("compression is not supported: Field does not have .isOdd()");
1039
- }
1040
- function d(S, l, a) {
1041
- const { x: w, y: p } = l.toAffine(), B = n.toBytes(w);
1042
- if (At(a, "isCompressed"), a) {
1043
- h();
1044
- const E = !n.isOdd(p);
1045
- return it(Oe(E), B);
1046
- } else
1047
- return it(Uint8Array.of(4), B, n.toBytes(p));
1048
- }
1049
- function x(S) {
1050
- N(S, void 0, "Point");
1051
- const { publicKey: l, publicKeyUncompressed: a } = u, w = S.length, p = S[0], B = S.subarray(1);
1052
- if (w === l && (p === 2 || p === 3)) {
1053
- const E = n.fromBytes(B);
1054
- if (!n.isValid(E))
1055
- throw new Error("bad point: is not on curve, wrong x");
1056
- const v = U(E);
1057
- let b;
1058
- try {
1059
- b = n.sqrt(v);
1060
- } catch (k) {
1061
- const H = k instanceof Error ? ": " + k.message : "";
1062
- throw new Error("bad point: is not on curve, sqrt error" + H);
1063
- }
1064
- h();
1065
- const R = n.isOdd(b);
1066
- return (p & 1) === 1 !== R && (b = n.neg(b)), { x: E, y: b };
1067
- } else if (w === a && p === 4) {
1068
- const E = n.BYTES, v = n.fromBytes(B.subarray(0, E)), b = n.fromBytes(B.subarray(E, E * 2));
1069
- if (!I(v, b))
1070
- throw new Error("bad point: is not on curve");
1071
- return { x: v, y: b };
1072
- } else
1073
- throw new Error(`bad point: got length ${w}, expected compressed=${l} or uncompressed=${a}`);
1074
- }
1075
- const g = t.toBytes || d, y = t.fromBytes || x;
1076
- function U(S) {
1077
- const l = n.sqr(S), a = n.mul(l, S);
1078
- return n.add(n.add(a, n.mul(S, o.a)), o.b);
1079
- }
1080
- function I(S, l) {
1081
- const a = n.sqr(l), w = U(S);
1082
- return n.eql(a, w);
1083
- }
1084
- if (!I(o.Gx, o.Gy))
1085
- throw new Error("bad curve params: generator point");
1086
- const O = n.mul(n.pow(o.a, yt), Rn), j = n.mul(n.sqr(o.b), BigInt(27));
1087
- if (n.is0(n.add(O, j)))
1088
- throw new Error("bad curve params: a or b");
1089
- function W(S, l, a = !1) {
1090
- if (!n.isValid(l) || a && n.is0(l))
1091
- throw new Error(`bad point coordinate ${S}`);
1092
- return l;
1093
- }
1094
- function Z(S) {
1095
- if (!(S instanceof z))
1096
- throw new Error("Weierstrass Point expected");
1097
- }
1098
- function D(S) {
1099
- if (!f || !f.basises)
1100
- throw new Error("no endo");
1101
- return Bn(S, f.basises, s.ORDER);
1102
- }
1103
- const G = Pt((S, l) => {
1104
- const { X: a, Y: w, Z: p } = S;
1105
- if (n.eql(p, n.ONE))
1106
- return { x: a, y: w };
1107
- const B = S.is0();
1108
- l == null && (l = B ? n.ONE : n.inv(p));
1109
- const E = n.mul(a, l), v = n.mul(w, l), b = n.mul(p, l);
1110
- if (B)
1111
- return { x: n.ZERO, y: n.ZERO };
1112
- if (!n.eql(b, n.ONE))
1113
- throw new Error("invZ was invalid");
1114
- return { x: E, y: v };
1115
- }), _t = Pt((S) => {
1116
- if (S.is0()) {
1117
- if (t.allowInfinityPoint && !n.is0(S.Y))
1118
- return;
1119
- throw new Error("bad point: ZERO");
1120
- }
1121
- const { x: l, y: a } = S.toAffine();
1122
- if (!n.isValid(l) || !n.isValid(a))
1123
- throw new Error("bad point: x or y not field elements");
1124
- if (!I(l, a))
1125
- throw new Error("bad point: equation left != right");
1126
- if (!S.isTorsionFree())
1127
- throw new Error("bad point: not in prime-order subgroup");
1128
- return !0;
1129
- });
1130
- function ht(S, l, a, w, p) {
1131
- return a = new z(n.mul(a.X, S), a.Y, a.Z), l = It(w, l), a = It(p, a), l.add(a);
1132
- }
1133
- const _ = class _ {
1134
- /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
1135
- constructor(l, a, w) {
1136
- m(this, "X");
1137
- m(this, "Y");
1138
- m(this, "Z");
1139
- this.X = W("x", l), this.Y = W("y", a, !0), this.Z = W("z", w), Object.freeze(this);
1140
- }
1141
- static CURVE() {
1142
- return o;
1143
- }
1144
- /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
1145
- static fromAffine(l) {
1146
- const { x: a, y: w } = l || {};
1147
- if (!l || !n.isValid(a) || !n.isValid(w))
1148
- throw new Error("invalid affine point");
1149
- if (l instanceof _)
1150
- throw new Error("projective point not allowed");
1151
- return n.is0(a) && n.is0(w) ? _.ZERO : new _(a, w, n.ONE);
1152
- }
1153
- static fromBytes(l) {
1154
- const a = _.fromAffine(y(N(l, void 0, "point")));
1155
- return a.assertValidity(), a;
1156
- }
1157
- static fromHex(l) {
1158
- return _.fromBytes(Rt(l));
1159
- }
1160
- get x() {
1161
- return this.toAffine().x;
1162
- }
1163
- get y() {
1164
- return this.toAffine().y;
1165
- }
1166
- /**
1167
- *
1168
- * @param windowSize
1169
- * @param isLazy true will defer table computation until the first multiplication
1170
- * @returns
1171
- */
1172
- precompute(l = 8, a = !0) {
1173
- return ct.createCache(this, l), a || this.multiply(yt), this;
1174
- }
1175
- // TODO: return `this`
1176
- /** A point on curve is valid if it conforms to equation. */
1177
- assertValidity() {
1178
- _t(this);
1179
- }
1180
- hasEvenY() {
1181
- const { y: l } = this.toAffine();
1182
- if (!n.isOdd)
1183
- throw new Error("Field doesn't support isOdd");
1184
- return !n.isOdd(l);
1185
- }
1186
- /** Compare one point to another. */
1187
- equals(l) {
1188
- Z(l);
1189
- const { X: a, Y: w, Z: p } = this, { X: B, Y: E, Z: v } = l, b = n.eql(n.mul(a, v), n.mul(B, p)), R = n.eql(n.mul(w, v), n.mul(E, p));
1190
- return b && R;
1191
- }
1192
- /** Flips point to one corresponding to (x, -y) in Affine coordinates. */
1193
- negate() {
1194
- return new _(this.X, n.neg(this.Y), this.Z);
1195
- }
1196
- // Renes-Costello-Batina exception-free doubling formula.
1197
- // There is 30% faster Jacobian formula, but it is not complete.
1198
- // https://eprint.iacr.org/2015/1060, algorithm 3
1199
- // Cost: 8M + 3S + 3*a + 2*b3 + 15add.
1200
- double() {
1201
- const { a: l, b: a } = o, w = n.mul(a, yt), { X: p, Y: B, Z: E } = this;
1202
- let v = n.ZERO, b = n.ZERO, R = n.ZERO, L = n.mul(p, p), k = n.mul(B, B), H = n.mul(E, E), A = n.mul(p, B);
1203
- return A = n.add(A, A), R = n.mul(p, E), R = n.add(R, R), v = n.mul(l, R), b = n.mul(w, H), b = n.add(v, b), v = n.sub(k, b), b = n.add(k, b), b = n.mul(v, b), v = n.mul(A, v), R = n.mul(w, R), H = n.mul(l, H), A = n.sub(L, H), A = n.mul(l, A), A = n.add(A, R), R = n.add(L, L), L = n.add(R, L), L = n.add(L, H), L = n.mul(L, A), b = n.add(b, L), H = n.mul(B, E), H = n.add(H, H), L = n.mul(H, A), v = n.sub(v, L), R = n.mul(H, k), R = n.add(R, R), R = n.add(R, R), new _(v, b, R);
1204
- }
1205
- // Renes-Costello-Batina exception-free addition formula.
1206
- // There is 30% faster Jacobian formula, but it is not complete.
1207
- // https://eprint.iacr.org/2015/1060, algorithm 1
1208
- // Cost: 12M + 0S + 3*a + 3*b3 + 23add.
1209
- add(l) {
1210
- Z(l);
1211
- const { X: a, Y: w, Z: p } = this, { X: B, Y: E, Z: v } = l;
1212
- let b = n.ZERO, R = n.ZERO, L = n.ZERO;
1213
- const k = o.a, H = n.mul(o.b, yt);
1214
- let A = n.mul(a, B), $ = n.mul(w, E), T = n.mul(p, v), K = n.add(a, w), q = n.add(B, E);
1215
- K = n.mul(K, q), q = n.add(A, $), K = n.sub(K, q), q = n.add(a, p);
1216
- let V = n.add(B, v);
1217
- return q = n.mul(q, V), V = n.add(A, T), q = n.sub(q, V), V = n.add(w, p), b = n.add(E, v), V = n.mul(V, b), b = n.add($, T), V = n.sub(V, b), L = n.mul(k, q), b = n.mul(H, T), L = n.add(b, L), b = n.sub($, L), L = n.add($, L), R = n.mul(b, L), $ = n.add(A, A), $ = n.add($, A), T = n.mul(k, T), q = n.mul(H, q), $ = n.add($, T), T = n.sub(A, T), T = n.mul(k, T), q = n.add(q, T), A = n.mul($, q), R = n.add(R, A), A = n.mul(V, q), b = n.mul(K, b), b = n.sub(b, A), A = n.mul(K, $), L = n.mul(V, L), L = n.add(L, A), new _(b, R, L);
1218
- }
1219
- subtract(l) {
1220
- return this.add(l.negate());
1221
- }
1222
- is0() {
1223
- return this.equals(_.ZERO);
1224
- }
1225
- /**
1226
- * Constant time multiplication.
1227
- * Uses wNAF method. Windowed method may be 10% faster,
1228
- * but takes 2x longer to generate and consumes 2x memory.
1229
- * Uses precomputes when available.
1230
- * Uses endomorphism for Koblitz curves.
1231
- * @param scalar by which the point would be multiplied
1232
- * @returns New point
1233
- */
1234
- multiply(l) {
1235
- const { endo: a } = t;
1236
- if (!s.isValidNot0(l))
1237
- throw new Error("invalid scalar: out of range");
1238
- let w, p;
1239
- const B = (E) => ct.cached(this, E, (v) => te(_, v));
1240
- if (a) {
1241
- const { k1neg: E, k1: v, k2neg: b, k2: R } = D(l), { p: L, f: k } = B(v), { p: H, f: A } = B(R);
1242
- p = k.add(A), w = ht(a.beta, L, H, E, b);
1243
- } else {
1244
- const { p: E, f: v } = B(l);
1245
- w = E, p = v;
1246
- }
1247
- return te(_, [w, p])[0];
1248
- }
1249
- /**
1250
- * Non-constant-time multiplication. Uses double-and-add algorithm.
1251
- * It's faster, but should only be used when you don't care about
1252
- * an exposed secret key e.g. sig verification, which works over *public* keys.
1253
- */
1254
- multiplyUnsafe(l) {
1255
- const { endo: a } = t, w = this;
1256
- if (!s.isValid(l))
1257
- throw new Error("invalid scalar: out of range");
1258
- if (l === tt || w.is0())
1259
- return _.ZERO;
1260
- if (l === lt)
1261
- return w;
1262
- if (ct.hasCache(this))
1263
- return this.multiply(l);
1264
- if (a) {
1265
- const { k1neg: p, k1: B, k2neg: E, k2: v } = D(l), { p1: b, p2: R } = xn(_, w, B, v);
1266
- return ht(a.beta, b, R, p, E);
1267
- } else
1268
- return ct.unsafe(w, l);
1269
- }
1270
- /**
1271
- * Converts Projective point to affine (x, y) coordinates.
1272
- * @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
1273
- */
1274
- toAffine(l) {
1275
- return G(this, l);
1276
- }
1277
- /**
1278
- * Checks whether Point is free of torsion elements (is in prime subgroup).
1279
- * Always torsion-free for cofactor=1 curves.
1280
- */
1281
- isTorsionFree() {
1282
- const { isTorsionFree: l } = t;
1283
- return i === lt ? !0 : l ? l(_, this) : ct.unsafe(this, c).is0();
1284
- }
1285
- clearCofactor() {
1286
- const { clearCofactor: l } = t;
1287
- return i === lt ? this : l ? l(_, this) : this.multiplyUnsafe(i);
1288
- }
1289
- isSmallOrder() {
1290
- return this.multiplyUnsafe(i).is0();
1291
- }
1292
- toBytes(l = !0) {
1293
- return At(l, "isCompressed"), this.assertValidity(), g(_, this, l);
1294
- }
1295
- toHex(l = !0) {
1296
- return Lt(this.toBytes(l));
1297
- }
1298
- toString() {
1299
- return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
1300
- }
1301
- };
1302
- // base / generator point
1303
- m(_, "BASE", new _(o.Gx, o.Gy, n.ONE)), // zero / infinity / identity point
1304
- m(_, "ZERO", new _(n.ZERO, n.ONE, n.ZERO)), // 0, 1, 0
1305
- // math field
1306
- m(_, "Fp", n), // scalar field
1307
- m(_, "Fn", s);
1308
- let z = _;
1309
- const bt = s.BITS, ct = new yn(z, t.endo ? Math.ceil(bt / 2) : bt);
1310
- return z.BASE.precompute(8), z;
541
+ if (t !== void 0 && A(t), e <= B) throw Error("invalid n length: expected positive n, got " + e);
542
+ if (t !== void 0 && t < 1) throw Error("invalid n length: expected positive bit length, got " + t);
543
+ let n = me(e);
544
+ if (t !== void 0 && t < n) throw Error(`invalid n length: expected bit length (${n}) >= n.length (${t})`);
545
+ let r = t === void 0 ? n : t;
546
+ return {
547
+ nBitLength: r,
548
+ nByteLength: Math.ceil(r / 8)
549
+ };
550
+ }
551
+ var Le = /* @__PURE__ */ new WeakMap(), Re = class {
552
+ ORDER;
553
+ BITS;
554
+ BYTES;
555
+ isLE;
556
+ ZERO = B;
557
+ ONE = V;
558
+ _lengths;
559
+ _mod;
560
+ constructor(e, t = {}) {
561
+ if (e <= V) throw Error("invalid field: expected ORDER > 1, got " + e);
562
+ let n;
563
+ this.isLE = !1, typeof t == "object" && t && (typeof t.BITS == "number" && (n = t.BITS), typeof t.sqrt == "function" && Object.defineProperty(this, "sqrt", {
564
+ value: t.sqrt,
565
+ enumerable: !0
566
+ }), typeof t.isLE == "boolean" && (this.isLE = t.isLE), t.allowedLengths && (this._lengths = Object.freeze(t.allowedLengths.slice())), typeof t.modFromBytes == "boolean" && (this._mod = t.modFromBytes));
567
+ let { nBitLength: r, nByteLength: i } = Ie(e, n);
568
+ if (i > 2048) throw Error("invalid field: expected ORDER of <= 2048 bytes");
569
+ this.ORDER = e, this.BITS = r, this.BYTES = i, Object.freeze(this);
570
+ }
571
+ create(e) {
572
+ return U(e, this.ORDER);
573
+ }
574
+ isValid(e) {
575
+ if (typeof e != "bigint") throw TypeError("invalid field element: expected bigint, got " + typeof e);
576
+ return B <= e && e < this.ORDER;
577
+ }
578
+ is0(e) {
579
+ return e === B;
580
+ }
581
+ isValidNot0(e) {
582
+ return !this.is0(e) && this.isValid(e);
583
+ }
584
+ isOdd(e) {
585
+ return (e & V) === V;
586
+ }
587
+ neg(e) {
588
+ return U(-e, this.ORDER);
589
+ }
590
+ eql(e, t) {
591
+ return e === t;
592
+ }
593
+ sqr(e) {
594
+ return U(e * e, this.ORDER);
595
+ }
596
+ add(e, t) {
597
+ return U(e + t, this.ORDER);
598
+ }
599
+ sub(e, t) {
600
+ return U(e - t, this.ORDER);
601
+ }
602
+ mul(e, t) {
603
+ return U(e * t, this.ORDER);
604
+ }
605
+ pow(e, t) {
606
+ return Ne(this, e, t);
607
+ }
608
+ div(e, t) {
609
+ return U(e * we(t, this.ORDER), this.ORDER);
610
+ }
611
+ sqrN(e) {
612
+ return e * e;
613
+ }
614
+ addN(e, t) {
615
+ return e + t;
616
+ }
617
+ subN(e, t) {
618
+ return e - t;
619
+ }
620
+ mulN(e, t) {
621
+ return e * t;
622
+ }
623
+ inv(e) {
624
+ return we(e, this.ORDER);
625
+ }
626
+ sqrt(e) {
627
+ let t = Le.get(this);
628
+ return t || Le.set(this, t = Ae(this.ORDER)), t(this, e);
629
+ }
630
+ toBytes(e) {
631
+ return this.isLE ? ue(e, this.BYTES) : le(e, this.BYTES);
632
+ }
633
+ fromBytes(e, t = !1) {
634
+ k(e);
635
+ let { _lengths: n, BYTES: r, isLE: i, ORDER: a, _mod: o } = this;
636
+ if (n) {
637
+ if (e.length < 1 || !n.includes(e.length) || e.length > r) throw Error("Field.fromBytes: expected " + n + " bytes, got " + e.length);
638
+ let t = new Uint8Array(r);
639
+ t.set(e, i ? 0 : t.length - e.length), e = t;
640
+ }
641
+ if (e.length !== r) throw Error("Field.fromBytes: expected " + r + " bytes, got " + e.length);
642
+ let s = i ? ce(e) : L(e);
643
+ if (o && (s = U(s, a)), !t && !this.isValid(s)) throw Error("invalid field element: outside of range 0..ORDER");
644
+ return s;
645
+ }
646
+ invertBatch(e) {
647
+ return Pe(this, e);
648
+ }
649
+ cmov(e, t, n) {
650
+ return F(n, "condition"), n ? t : e;
651
+ }
652
+ };
653
+ Object.freeze(Re.prototype);
654
+ function G(e, t = {}) {
655
+ return new Re(e, t);
1311
656
  }
1312
- function Oe(e) {
1313
- return Uint8Array.of(e ? 2 : 3);
657
+ function ze(e) {
658
+ if (typeof e != "bigint") throw Error("field order must be bigint");
659
+ if (e <= V) throw Error("field order must be greater than 1");
660
+ let t = me(e - V);
661
+ return Math.ceil(t / 8);
662
+ }
663
+ function Be(e) {
664
+ let t = ze(e);
665
+ return t + Math.ceil(t / 2);
666
+ }
667
+ function Ve(e, t, n = !1) {
668
+ k(e);
669
+ let r = e.length, i = ze(t), a = Math.max(Be(t), 16);
670
+ if (r < a || r > 1024) throw Error("expected " + a + "-1024 bytes of input, got " + r);
671
+ let o = U(n ? ce(e) : L(e), t - V) + V;
672
+ return n ? ue(o, i) : le(o, i);
673
+ }
674
+ //#endregion
675
+ //#region node_modules/@noble/curves/abstract/curve.js
676
+ var K = /* @__PURE__ */ BigInt(0), q = /* @__PURE__ */ BigInt(1);
677
+ function J(e, t) {
678
+ let n = t.negate();
679
+ return e ? n : t;
1314
680
  }
1315
681
  function He(e, t) {
1316
- return {
1317
- secretKey: t.BYTES,
1318
- publicKey: 1 + e.BYTES,
1319
- publicKeyUncompressed: 1 + 2 * e.BYTES,
1320
- publicKeyHasPrefix: !0,
1321
- signature: 2 * t.BYTES
1322
- };
1323
- }
1324
- function In(e, t = {}) {
1325
- const { Fn: r } = e, n = t.randomBytes || le, s = Object.assign(He(e.Fp, r), { seed: Ae(r.ORDER) });
1326
- function o(g) {
1327
- try {
1328
- const y = r.fromBytes(g);
1329
- return r.isValidNot0(y);
1330
- } catch {
1331
- return !1;
1332
- }
1333
- }
1334
- function i(g, y) {
1335
- const { publicKey: U, publicKeyUncompressed: I } = s;
1336
- try {
1337
- const O = g.length;
1338
- return y === !0 && O !== U || y === !1 && O !== I ? !1 : !!e.fromBytes(g);
1339
- } catch {
1340
- return !1;
1341
- }
1342
- }
1343
- function c(g = n(s.seed)) {
1344
- return pn(N(g, s.seed, "seed"), r.ORDER);
1345
- }
1346
- function f(g, y = !0) {
1347
- return e.BASE.multiply(r.fromBytes(g)).toBytes(y);
1348
- }
1349
- function u(g) {
1350
- const { secretKey: y, publicKey: U, publicKeyUncompressed: I } = s;
1351
- if (!Tt(g) || "_lengths" in r && r._lengths || y === U)
1352
- return;
1353
- const O = N(g, void 0, "key").length;
1354
- return O === U || O === I;
1355
- }
1356
- function h(g, y, U = !0) {
1357
- if (u(g) === !0)
1358
- throw new Error("first arg must be private key");
1359
- if (u(y) === !1)
1360
- throw new Error("second arg must be public key");
1361
- const I = r.fromBytes(g);
1362
- return e.fromBytes(y).multiply(I).toBytes(U);
1363
- }
1364
- const d = {
1365
- isValidSecretKey: o,
1366
- isValidPublicKey: i,
1367
- randomSecretKey: c
1368
- }, x = En(c, f);
1369
- return Object.freeze({ getPublicKey: f, getSharedSecret: h, keygen: x, Point: e, utils: d, lengths: s });
1370
- }
1371
- function Ln(e, t, r = {}) {
1372
- ue(t), jt(r, {}, {
1373
- hmac: "function",
1374
- lowS: "boolean",
1375
- randomBytes: "function",
1376
- bits2int: "function",
1377
- bits2int_modN: "function"
1378
- }), r = Object.assign({}, r);
1379
- const n = r.randomBytes || le, s = r.hmac || ((l, a) => Se(t, l, a)), { Fp: o, Fn: i } = e, { ORDER: c, BITS: f } = i, { keygen: u, getPublicKey: h, getSharedSecret: d, utils: x, lengths: g } = In(e, r), y = {
1380
- prehash: !0,
1381
- lowS: typeof r.lowS == "boolean" ? r.lowS : !0,
1382
- format: "compact",
1383
- extraEntropy: !1
1384
- }, U = c * _e < o.ORDER;
1385
- function I(l) {
1386
- const a = c >> lt;
1387
- return l > a;
1388
- }
1389
- function O(l, a) {
1390
- if (!i.isValidNot0(a))
1391
- throw new Error(`invalid signature ${l}: out of range 1..Point.Fn.ORDER`);
1392
- return a;
1393
- }
1394
- function j() {
1395
- if (U)
1396
- throw new Error('"recovered" sig type is not supported for cofactor >2 curves');
1397
- }
1398
- function W(l, a) {
1399
- Zt(a);
1400
- const w = g.signature, p = a === "compact" ? w : a === "recovered" ? w + 1 : void 0;
1401
- return N(l, p);
1402
- }
1403
- class Z {
1404
- constructor(a, w, p) {
1405
- m(this, "r");
1406
- m(this, "s");
1407
- m(this, "recovery");
1408
- if (this.r = O("r", a), this.s = O("s", w), p != null) {
1409
- if (j(), ![0, 1, 2, 3].includes(p))
1410
- throw new Error("invalid recovery id");
1411
- this.recovery = p;
1412
- }
1413
- Object.freeze(this);
1414
- }
1415
- static fromBytes(a, w = y.format) {
1416
- W(a, w);
1417
- let p;
1418
- if (w === "der") {
1419
- const { r: b, s: R } = ot.toSig(N(a));
1420
- return new Z(b, R);
1421
- }
1422
- w === "recovered" && (p = a[0], w = "compact", a = a.subarray(1));
1423
- const B = g.signature / 2, E = a.subarray(0, B), v = a.subarray(B, B * 2);
1424
- return new Z(i.fromBytes(E), i.fromBytes(v), p);
1425
- }
1426
- static fromHex(a, w) {
1427
- return this.fromBytes(Rt(a), w);
1428
- }
1429
- assertRecovery() {
1430
- const { recovery: a } = this;
1431
- if (a == null)
1432
- throw new Error("invalid recovery id: must be present");
1433
- return a;
1434
- }
1435
- addRecoveryBit(a) {
1436
- return new Z(this.r, this.s, a);
1437
- }
1438
- recoverPublicKey(a) {
1439
- const { r: w, s: p } = this, B = this.assertRecovery(), E = B === 2 || B === 3 ? w + c : w;
1440
- if (!o.isValid(E))
1441
- throw new Error("invalid recovery id: sig.r+curve.n != R.x");
1442
- const v = o.toBytes(E), b = e.fromBytes(it(Oe((B & 1) === 0), v)), R = i.inv(E), L = G(N(a, void 0, "msgHash")), k = i.create(-L * R), H = i.create(p * R), A = e.BASE.multiplyUnsafe(k).add(b.multiplyUnsafe(H));
1443
- if (A.is0())
1444
- throw new Error("invalid recovery: point at infinify");
1445
- return A.assertValidity(), A;
1446
- }
1447
- // Signatures should be low-s, to prevent malleability.
1448
- hasHighS() {
1449
- return I(this.s);
1450
- }
1451
- toBytes(a = y.format) {
1452
- if (Zt(a), a === "der")
1453
- return Rt(ot.hexFromSig(this));
1454
- const { r: w, s: p } = this, B = i.toBytes(w), E = i.toBytes(p);
1455
- return a === "recovered" ? (j(), it(Uint8Array.of(this.assertRecovery()), B, E)) : it(B, E);
1456
- }
1457
- toHex(a) {
1458
- return Lt(this.toBytes(a));
1459
- }
1460
- }
1461
- const D = r.bits2int || function(a) {
1462
- if (a.length > 8192)
1463
- throw new Error("input is too large");
1464
- const w = Ut(a), p = a.length * 8 - f;
1465
- return p > 0 ? w >> BigInt(p) : w;
1466
- }, G = r.bits2int_modN || function(a) {
1467
- return i.create(D(a));
1468
- }, _t = Yt(f);
1469
- function ht(l) {
1470
- return rn("num < 2^" + f, l, tt, _t), i.toBytes(l);
1471
- }
1472
- function z(l, a) {
1473
- return N(l, void 0, "message"), a ? N(t(l), void 0, "prehashed message") : l;
1474
- }
1475
- function bt(l, a, w) {
1476
- const { lowS: p, prehash: B, extraEntropy: E } = kt(w, y);
1477
- l = z(l, B);
1478
- const v = G(l), b = i.fromBytes(a);
1479
- if (!i.isValidNot0(b))
1480
- throw new Error("invalid private key");
1481
- const R = [ht(b), ht(v)];
1482
- if (E != null && E !== !1) {
1483
- const A = E === !0 ? n(g.secretKey) : E;
1484
- R.push(N(A, void 0, "extraEntropy"));
1485
- }
1486
- const L = it(...R), k = v;
1487
- function H(A) {
1488
- const $ = D(A);
1489
- if (!i.isValidNot0($))
1490
- return;
1491
- const T = i.inv($), K = e.BASE.multiply($).toAffine(), q = i.create(K.x);
1492
- if (q === tt)
1493
- return;
1494
- const V = i.create(T * i.create(k + q * b));
1495
- if (V === tt)
1496
- return;
1497
- let zt = (K.x === q ? 0 : 2) | Number(K.y & lt), Ft = V;
1498
- return p && I(V) && (Ft = i.neg(V), zt ^= 1), new Z(q, Ft, U ? void 0 : zt);
1499
- }
1500
- return { seed: L, k2sig: H };
1501
- }
1502
- function ct(l, a, w = {}) {
1503
- const { seed: p, k2sig: B } = bt(l, a, w);
1504
- return on(t.outputLen, i.BYTES, s)(p, B).toBytes(w.format);
1505
- }
1506
- function _(l, a, w, p = {}) {
1507
- const { lowS: B, prehash: E, format: v } = kt(p, y);
1508
- if (w = N(w, void 0, "publicKey"), a = z(a, E), !Tt(l)) {
1509
- const b = l instanceof Z ? ", use sig.toBytes()" : "";
1510
- throw new Error("verify expects Uint8Array signature" + b);
1511
- }
1512
- W(l, v);
1513
- try {
1514
- const b = Z.fromBytes(l, v), R = e.fromBytes(w);
1515
- if (B && b.hasHighS())
1516
- return !1;
1517
- const { r: L, s: k } = b, H = G(a), A = i.inv(k), $ = i.create(H * A), T = i.create(L * A), K = e.BASE.multiplyUnsafe($).add(R.multiplyUnsafe(T));
1518
- return K.is0() ? !1 : i.create(K.x) === L;
1519
- } catch {
1520
- return !1;
1521
- }
1522
- }
1523
- function S(l, a, w = {}) {
1524
- const { prehash: p } = kt(w, y);
1525
- return a = z(a, p), Z.fromBytes(l, "recovered").recoverPublicKey(a).toBytes();
1526
- }
1527
- return Object.freeze({
1528
- keygen: u,
1529
- getPublicKey: h,
1530
- getSharedSecret: d,
1531
- utils: x,
1532
- lengths: g,
1533
- Point: e,
1534
- sign: ct,
1535
- verify: _,
1536
- recoverPublicKey: S,
1537
- Signature: Z,
1538
- hash: t
1539
- });
1540
- }
1541
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1542
- const Gt = {
1543
- p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
1544
- n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
1545
- h: BigInt(1),
1546
- a: BigInt(0),
1547
- b: BigInt(7),
1548
- Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
1549
- Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
1550
- }, Un = {
1551
- beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
1552
- basises: [
1553
- [BigInt("0x3086d221a7d46bcde86c90e49284eb15"), -BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],
1554
- [BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), BigInt("0x3086d221a7d46bcde86c90e49284eb15")]
1555
- ]
1556
- }, oe = /* @__PURE__ */ BigInt(2);
1557
- function Sn(e) {
1558
- const t = Gt.p, r = BigInt(3), n = BigInt(6), s = BigInt(11), o = BigInt(22), i = BigInt(23), c = BigInt(44), f = BigInt(88), u = e * e * e % t, h = u * u * e % t, d = X(h, r, t) * h % t, x = X(d, r, t) * h % t, g = X(x, oe, t) * u % t, y = X(g, s, t) * g % t, U = X(y, o, t) * y % t, I = X(U, c, t) * U % t, O = X(I, f, t) * I % t, j = X(O, c, t) * U % t, W = X(j, r, t) * h % t, Z = X(W, i, t) * y % t, D = X(Z, n, t) * u % t, G = X(D, oe, t);
1559
- if (!Ct.eql(Ct.sqr(G), e))
1560
- throw new Error("Cannot find square root");
1561
- return G;
1562
- }
1563
- const Ct = St(Gt.p, { sqrt: Sn }), _n = /* @__PURE__ */ An(Gt, {
1564
- Fp: Ct,
1565
- endo: Un
1566
- }), On = /* @__PURE__ */ Ln(_n, tn);
1567
- /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1568
- function Hn(e) {
1569
- return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
1570
- }
1571
- function Xt(e, ...t) {
1572
- if (!Hn(e))
1573
- throw new Error("Uint8Array expected");
1574
- if (t.length > 0 && !t.includes(e.length))
1575
- throw new Error("Uint8Array expected of length " + t + ", got length=" + e.length);
1576
- }
1577
- function ie(e, t = !0) {
1578
- if (e.destroyed)
1579
- throw new Error("Hash instance has been destroyed");
1580
- if (t && e.finished)
1581
- throw new Error("Hash#digest() has already been called");
1582
- }
1583
- function qn(e, t) {
1584
- Xt(e);
1585
- const r = t.outputLen;
1586
- if (e.length < r)
1587
- throw new Error("digestInto() expects output buffer of length at least " + r);
1588
- }
1589
- function gt(...e) {
1590
- for (let t = 0; t < e.length; t++)
1591
- e[t].fill(0);
1592
- }
1593
- function Dt(e) {
1594
- return new DataView(e.buffer, e.byteOffset, e.byteLength);
1595
- }
1596
- function Q(e, t) {
1597
- return e << 32 - t | e >>> t;
1598
- }
1599
- function xt(e, t) {
1600
- return e << t | e >>> 32 - t >>> 0;
1601
- }
1602
- function Nn(e) {
1603
- if (typeof e != "string")
1604
- throw new Error("string expected");
1605
- return new Uint8Array(new TextEncoder().encode(e));
1606
- }
1607
- function qe(e) {
1608
- return typeof e == "string" && (e = Nn(e)), Xt(e), e;
1609
- }
1610
- class kn {
1611
- }
1612
- function Ne(e) {
1613
- const t = (n) => e().update(qe(n)).digest(), r = e();
1614
- return t.outputLen = r.outputLen, t.blockLen = r.blockLen, t.create = () => e(), t;
1615
- }
1616
- function Dn(e, t, r, n) {
1617
- if (typeof e.setBigUint64 == "function")
1618
- return e.setBigUint64(t, r, n);
1619
- const s = BigInt(32), o = BigInt(4294967295), i = Number(r >> s & o), c = Number(r & o), f = n ? 4 : 0, u = n ? 0 : 4;
1620
- e.setUint32(t + f, i, n), e.setUint32(t + u, c, n);
1621
- }
1622
- function $n(e, t, r) {
1623
- return e & t ^ ~e & r;
1624
- }
1625
- function Zn(e, t, r) {
1626
- return e & t ^ e & r ^ t & r;
1627
- }
1628
- class ke extends kn {
1629
- constructor(t, r, n, s) {
1630
- super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = t, this.outputLen = r, this.padOffset = n, this.isLE = s, this.buffer = new Uint8Array(t), this.view = Dt(this.buffer);
1631
- }
1632
- update(t) {
1633
- ie(this), t = qe(t), Xt(t);
1634
- const { view: r, buffer: n, blockLen: s } = this, o = t.length;
1635
- for (let i = 0; i < o; ) {
1636
- const c = Math.min(s - this.pos, o - i);
1637
- if (c === s) {
1638
- const f = Dt(t);
1639
- for (; s <= o - i; i += s)
1640
- this.process(f, i);
1641
- continue;
1642
- }
1643
- n.set(t.subarray(i, i + c), this.pos), this.pos += c, i += c, this.pos === s && (this.process(r, 0), this.pos = 0);
1644
- }
1645
- return this.length += t.length, this.roundClean(), this;
1646
- }
1647
- digestInto(t) {
1648
- ie(this), qn(t, this), this.finished = !0;
1649
- const { buffer: r, view: n, blockLen: s, isLE: o } = this;
1650
- let { pos: i } = this;
1651
- r[i++] = 128, gt(this.buffer.subarray(i)), this.padOffset > s - i && (this.process(n, 0), i = 0);
1652
- for (let d = i; d < s; d++)
1653
- r[d] = 0;
1654
- Dn(n, s - 8, BigInt(this.length * 8), o), this.process(n, 0);
1655
- const c = Dt(t), f = this.outputLen;
1656
- if (f % 4)
1657
- throw new Error("_sha2: outputLen should be aligned to 32bit");
1658
- const u = f / 4, h = this.get();
1659
- if (u > h.length)
1660
- throw new Error("_sha2: outputLen bigger than state");
1661
- for (let d = 0; d < u; d++)
1662
- c.setUint32(4 * d, h[d], o);
1663
- }
1664
- digest() {
1665
- const { buffer: t, outputLen: r } = this;
1666
- this.digestInto(t);
1667
- const n = t.slice(0, r);
1668
- return this.destroy(), n;
1669
- }
1670
- _cloneInto(t) {
1671
- t || (t = new this.constructor()), t.set(...this.get());
1672
- const { blockLen: r, buffer: n, length: s, finished: o, destroyed: i, pos: c } = this;
1673
- return t.destroyed = i, t.finished = o, t.length = s, t.pos = c, s % r && t.buffer.set(n), t;
1674
- }
1675
- clone() {
1676
- return this._cloneInto();
1677
- }
1678
- }
1679
- const rt = /* @__PURE__ */ Uint32Array.from([
1680
- 1779033703,
1681
- 3144134277,
1682
- 1013904242,
1683
- 2773480762,
1684
- 1359893119,
1685
- 2600822924,
1686
- 528734635,
1687
- 1541459225
1688
- ]), Cn = /* @__PURE__ */ Uint8Array.from([
1689
- 7,
1690
- 4,
1691
- 13,
1692
- 1,
1693
- 10,
1694
- 6,
1695
- 15,
1696
- 3,
1697
- 12,
1698
- 0,
1699
- 9,
1700
- 5,
1701
- 2,
1702
- 14,
1703
- 11,
1704
- 8
1705
- ]), De = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), Tn = De.map((e) => (9 * e + 5) % 16), $e = /* @__PURE__ */ (() => {
1706
- const r = [[De], [Tn]];
1707
- for (let n = 0; n < 4; n++)
1708
- for (let s of r)
1709
- s.push(s[n].map((o) => Cn[o]));
1710
- return r;
1711
- })(), Ze = $e[0], Ce = $e[1], Te = /* @__PURE__ */ [
1712
- [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
1713
- [12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
1714
- [13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
1715
- [14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
1716
- [15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
1717
- ].map((e) => Uint8Array.from(e)), Vn = /* @__PURE__ */ Ze.map((e, t) => e.map((r) => Te[t][r])), Mn = /* @__PURE__ */ Ce.map((e, t) => e.map((r) => Te[t][r])), Yn = /* @__PURE__ */ Uint32Array.from([
1718
- 0,
1719
- 1518500249,
1720
- 1859775393,
1721
- 2400959708,
1722
- 2840853838
1723
- ]), jn = /* @__PURE__ */ Uint32Array.from([
1724
- 1352829926,
1725
- 1548603684,
1726
- 1836072691,
1727
- 2053994217,
1728
- 0
1729
- ]);
1730
- function ce(e, t, r, n) {
1731
- return e === 0 ? t ^ r ^ n : e === 1 ? t & r | ~t & n : e === 2 ? (t | ~r) ^ n : e === 3 ? t & n | r & ~n : t ^ (r | ~n);
1732
- }
1733
- const mt = /* @__PURE__ */ new Uint32Array(16);
1734
- class Kn extends ke {
1735
- constructor() {
1736
- super(64, 20, 8, !0), this.h0 = 1732584193, this.h1 = -271733879, this.h2 = -1732584194, this.h3 = 271733878, this.h4 = -1009589776;
1737
- }
1738
- get() {
1739
- const { h0: t, h1: r, h2: n, h3: s, h4: o } = this;
1740
- return [t, r, n, s, o];
1741
- }
1742
- set(t, r, n, s, o) {
1743
- this.h0 = t | 0, this.h1 = r | 0, this.h2 = n | 0, this.h3 = s | 0, this.h4 = o | 0;
1744
- }
1745
- process(t, r) {
1746
- for (let g = 0; g < 16; g++, r += 4)
1747
- mt[g] = t.getUint32(r, !0);
1748
- let n = this.h0 | 0, s = n, o = this.h1 | 0, i = o, c = this.h2 | 0, f = c, u = this.h3 | 0, h = u, d = this.h4 | 0, x = d;
1749
- for (let g = 0; g < 5; g++) {
1750
- const y = 4 - g, U = Yn[g], I = jn[g], O = Ze[g], j = Ce[g], W = Vn[g], Z = Mn[g];
1751
- for (let D = 0; D < 16; D++) {
1752
- const G = xt(n + ce(g, o, c, u) + mt[O[D]] + U, W[D]) + d | 0;
1753
- n = d, d = u, u = xt(c, 10) | 0, c = o, o = G;
1754
- }
1755
- for (let D = 0; D < 16; D++) {
1756
- const G = xt(s + ce(y, i, f, h) + mt[j[D]] + I, Z[D]) + x | 0;
1757
- s = x, x = h, h = xt(f, 10) | 0, f = i, i = G;
1758
- }
1759
- }
1760
- this.set(this.h1 + c + h | 0, this.h2 + u + x | 0, this.h3 + d + s | 0, this.h4 + n + i | 0, this.h0 + o + f | 0);
1761
- }
1762
- roundClean() {
1763
- gt(mt);
1764
- }
1765
- destroy() {
1766
- this.destroyed = !0, gt(this.buffer), this.set(0, 0, 0, 0, 0);
1767
- }
1768
- }
1769
- const Gn = /* @__PURE__ */ Ne(() => new Kn()), Xn = Gn, zn = /* @__PURE__ */ Uint32Array.from([
1770
- 1116352408,
1771
- 1899447441,
1772
- 3049323471,
1773
- 3921009573,
1774
- 961987163,
1775
- 1508970993,
1776
- 2453635748,
1777
- 2870763221,
1778
- 3624381080,
1779
- 310598401,
1780
- 607225278,
1781
- 1426881987,
1782
- 1925078388,
1783
- 2162078206,
1784
- 2614888103,
1785
- 3248222580,
1786
- 3835390401,
1787
- 4022224774,
1788
- 264347078,
1789
- 604807628,
1790
- 770255983,
1791
- 1249150122,
1792
- 1555081692,
1793
- 1996064986,
1794
- 2554220882,
1795
- 2821834349,
1796
- 2952996808,
1797
- 3210313671,
1798
- 3336571891,
1799
- 3584528711,
1800
- 113926993,
1801
- 338241895,
1802
- 666307205,
1803
- 773529912,
1804
- 1294757372,
1805
- 1396182291,
1806
- 1695183700,
1807
- 1986661051,
1808
- 2177026350,
1809
- 2456956037,
1810
- 2730485921,
1811
- 2820302411,
1812
- 3259730800,
1813
- 3345764771,
1814
- 3516065817,
1815
- 3600352804,
1816
- 4094571909,
1817
- 275423344,
1818
- 430227734,
1819
- 506948616,
1820
- 659060556,
1821
- 883997877,
1822
- 958139571,
1823
- 1322822218,
1824
- 1537002063,
1825
- 1747873779,
1826
- 1955562222,
1827
- 2024104815,
1828
- 2227730452,
1829
- 2361852424,
1830
- 2428436474,
1831
- 2756734187,
1832
- 3204031479,
1833
- 3329325298
1834
- ]), st = /* @__PURE__ */ new Uint32Array(64);
1835
- class Fn extends ke {
1836
- constructor(t = 32) {
1837
- super(64, t, 8, !1), this.A = rt[0] | 0, this.B = rt[1] | 0, this.C = rt[2] | 0, this.D = rt[3] | 0, this.E = rt[4] | 0, this.F = rt[5] | 0, this.G = rt[6] | 0, this.H = rt[7] | 0;
1838
- }
1839
- get() {
1840
- const { A: t, B: r, C: n, D: s, E: o, F: i, G: c, H: f } = this;
1841
- return [t, r, n, s, o, i, c, f];
1842
- }
1843
- // prettier-ignore
1844
- set(t, r, n, s, o, i, c, f) {
1845
- this.A = t | 0, this.B = r | 0, this.C = n | 0, this.D = s | 0, this.E = o | 0, this.F = i | 0, this.G = c | 0, this.H = f | 0;
1846
- }
1847
- process(t, r) {
1848
- for (let d = 0; d < 16; d++, r += 4)
1849
- st[d] = t.getUint32(r, !1);
1850
- for (let d = 16; d < 64; d++) {
1851
- const x = st[d - 15], g = st[d - 2], y = Q(x, 7) ^ Q(x, 18) ^ x >>> 3, U = Q(g, 17) ^ Q(g, 19) ^ g >>> 10;
1852
- st[d] = U + st[d - 7] + y + st[d - 16] | 0;
1853
- }
1854
- let { A: n, B: s, C: o, D: i, E: c, F: f, G: u, H: h } = this;
1855
- for (let d = 0; d < 64; d++) {
1856
- const x = Q(c, 6) ^ Q(c, 11) ^ Q(c, 25), g = h + x + $n(c, f, u) + zn[d] + st[d] | 0, U = (Q(n, 2) ^ Q(n, 13) ^ Q(n, 22)) + Zn(n, s, o) | 0;
1857
- h = u, u = f, f = c, c = i + g | 0, i = o, o = s, s = n, n = g + U | 0;
1858
- }
1859
- n = n + this.A | 0, s = s + this.B | 0, o = o + this.C | 0, i = i + this.D | 0, c = c + this.E | 0, f = f + this.F | 0, u = u + this.G | 0, h = h + this.H | 0, this.set(n, s, o, i, c, f, u, h);
1860
- }
1861
- roundClean() {
1862
- gt(st);
1863
- }
1864
- destroy() {
1865
- this.set(0, 0, 0, 0, 0, 0, 0, 0), gt(this.buffer);
1866
- }
1867
- }
1868
- const Wn = /* @__PURE__ */ Ne(() => new Fn()), wt = Wn, Pn = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
1869
- function Qn(e) {
1870
- const t = [0];
1871
- for (let r = 0; r < e.length; r++) {
1872
- const n = e[r];
1873
- if (!n) continue;
1874
- const s = Pn.indexOf(n);
1875
- if (s === -1) throw new Error("Invalid base58 character");
1876
- for (let i = 0; i < t.length; i++)
1877
- t[i] *= 58;
1878
- t[0] += s;
1879
- let o = 0;
1880
- for (let i = 0; i < t.length; i++) {
1881
- const c = t[i];
1882
- t[i] = c + o, o = t[i] >> 8, t[i] &= 255;
1883
- }
1884
- for (; o > 0; )
1885
- t.push(o & 255), o >>= 8;
1886
- }
1887
- for (let r = 0; r < e.length && e[r] === "1"; r++)
1888
- t.push(0);
1889
- return new Uint8Array(t.reverse());
1890
- }
1891
- function Jn(e) {
1892
- const t = "qpzry9x8gf2tvdw0s3jn54khce6mua7l", n = e.toLowerCase().split("1");
1893
- if (n.length !== 2) return null;
1894
- const s = n[0], o = n[1];
1895
- if (!s || !o || s !== "dgb") return null;
1896
- const i = [];
1897
- for (const h of o) {
1898
- const d = t.indexOf(h);
1899
- if (d === -1) return null;
1900
- i.push(d);
1901
- }
1902
- const c = i.slice(0, -6);
1903
- if (c.length < 1) return null;
1904
- const f = c[0];
1905
- if (f === void 0) return null;
1906
- const u = tr(c.slice(1), 5, 8);
1907
- return u ? { version: f, program: new Uint8Array(u) } : null;
1908
- }
1909
- function tr(e, t, r, n) {
1910
- let s = 0, o = 0;
1911
- const i = [], c = (1 << r) - 1;
1912
- for (const f of e) {
1913
- if (f < 0 || f >> t !== 0) return null;
1914
- for (s = s << t | f, o += t; o >= r; )
1915
- o -= r, i.push(s >> o & c);
1916
- }
1917
- return o >= t || s << r - o & c ? null : i;
1918
- }
1919
- function er(e, t) {
1920
- const r = new TextEncoder().encode(t), n = new TextEncoder().encode(e), s = [];
1921
- let o = n.length;
1922
- if (o < 253)
1923
- s.push(o);
1924
- else if (o <= 65535)
1925
- s.push(253, o & 255, o >> 8 & 255);
1926
- else if (o <= 4294967295)
1927
- s.push(
1928
- 254,
1929
- o & 255,
1930
- o >> 8 & 255,
1931
- o >> 16 & 255,
1932
- o >> 24 & 255
1933
- );
1934
- else
1935
- throw new Error("Message too long");
1936
- const i = new Uint8Array(s), c = r.length + i.length + n.length, f = new Uint8Array(c);
1937
- let u = 0;
1938
- return f.set(r, u), u += r.length, f.set(i, u), u += i.length, f.set(n, u), wt(wt(f));
1939
- }
1940
- function nr(e, t) {
1941
- if (t.length !== 65)
1942
- throw new Error("Invalid signature length");
1943
- if (t[0] === void 0) throw new Error("Invalid signature");
1944
- const n = t.slice(1, 33), s = t.slice(33, 65), o = [];
1945
- for (let i = 0; i < 4; i++)
1946
- try {
1947
- const f = new On.Signature(
1948
- BigInt("0x" + Array.from(n).map((d) => d.toString(16).padStart(2, "0")).join("")),
1949
- BigInt("0x" + Array.from(s).map((d) => d.toString(16).padStart(2, "0")).join(""))
1950
- ).addRecoveryBit(i).recoverPublicKey(e), u = f.toBytes(!0), h = f.toBytes(!1);
1951
- o.push(u), o.push(h);
1952
- } catch {
1953
- continue;
1954
- }
1955
- if (o.length === 0)
1956
- throw new Error("Failed to recover any public keys");
1957
- return o;
1958
- }
1959
- function fe(e) {
1960
- return Xn(wt(e));
1961
- }
1962
- function rr(e, t) {
1963
- if (e.startsWith("D") || e.startsWith("S"))
1964
- try {
1965
- const r = Qn(e);
1966
- if (r.length < 25) return !1;
1967
- const n = r.slice(0, -4), s = r.slice(-4), i = wt(wt(n)).slice(0, 4);
1968
- if (!s.every((u, h) => u === i[h]))
1969
- return !1;
1970
- const c = n.slice(1), f = fe(t);
1971
- return c.every((u, h) => u === f[h]);
1972
- } catch {
1973
- return !1;
1974
- }
1975
- if (e.toLowerCase().startsWith("dgb1"))
1976
- try {
1977
- const r = Jn(e);
1978
- if (!r) return !1;
1979
- const { version: n, program: s } = r;
1980
- if (n === 0) {
1981
- let o = t;
1982
- if (t.length === 65) {
1983
- const c = t[64] % 2 === 0;
1984
- o = new Uint8Array(33), o[0] = c ? 2 : 3, o.set(t.slice(1, 33), 1);
1985
- }
1986
- const i = fe(o);
1987
- return s.every((c, f) => c === i[f]);
1988
- }
1989
- return !1;
1990
- } catch {
1991
- return !1;
1992
- }
1993
- return !1;
1994
- }
1995
- async function sr(e, t, r) {
1996
- const n = `DigiByte Signed Message:
1997
- `;
1998
- try {
1999
- const s = Uint8Array.from(atob(r), (c) => c.charCodeAt(0));
2000
- if (s.length !== 65)
2001
- throw new Error("Invalid signature length");
2002
- const o = er(e, n), i = nr(o, s);
2003
- for (const c of i)
2004
- if (rr(t, c))
2005
- return !0;
2006
- return !1;
2007
- } catch (s) {
2008
- const o = s instanceof Error ? s.message : String(s);
2009
- throw new C(`Signature verification failed: ${o}`);
2010
- }
2011
- }
2012
- function or(e = 16) {
2013
- return Ye(e).toString("hex");
2014
- }
2015
- function ur(e) {
2016
- if (!e.callbackUrl)
2017
- throw new C("Callback URL is required.");
2018
- let t;
2019
- try {
2020
- t = new URL(e.callbackUrl);
2021
- } catch (i) {
2022
- throw new C(`Invalid callback URL: ${i.message}`);
2023
- }
2024
- const r = t.host + t.pathname, n = e.nonce || or(), s = e.unsecure ? "1" : "0";
2025
- if (e.unsecure && t.protocol !== "http:")
2026
- throw new C("Unsecure flag is true, but callback URL does not use http protocol.");
2027
- if (!e.unsecure && t.protocol !== "https:")
2028
- throw new C("Callback URL must use https protocol unless unsecure flag is set to true.");
2029
- return `digiid://${r}?x=${n}&u=${s}`;
2030
- }
2031
- async function ar(e, t) {
2032
- const { address: r, uri: n, signature: s } = e, { expectedCallbackUrl: o, expectedNonce: i } = t;
2033
- if (!r || !n || !s)
2034
- throw new C("Missing required callback data: address, uri, or signature.");
2035
- let c;
2036
- try {
2037
- const y = n.replace(/^digiid:/, "http:");
2038
- c = new URL(y);
2039
- } catch (y) {
2040
- throw new C(`Invalid URI received in callback: ${y.message}`);
2041
- }
2042
- const f = c.searchParams.get("x"), u = c.searchParams.get("u"), h = c.host + c.pathname;
2043
- if (f === null || u === null)
2044
- throw new C("URI missing nonce (x) or unsecure (u) parameter.");
2045
- let d;
2046
- try {
2047
- d = typeof o == "string" ? new URL(o) : o;
2048
- } catch (y) {
2049
- throw new C(`Invalid expectedCallbackUrl provided: ${y.message}`);
2050
- }
2051
- const x = d.host + d.pathname;
2052
- if (h !== x)
2053
- throw new C(`Callback URL mismatch: URI contained "${h}", expected "${x}"`);
2054
- const g = d.protocol;
2055
- if (u === "1" && g !== "http:")
2056
- throw new C("URI indicates unsecure (u=1), but expectedCallbackUrl is not http.");
2057
- if (u === "0" && g !== "https:")
2058
- throw new C("URI indicates secure (u=0), but expectedCallbackUrl is not https.");
2059
- if (i && f !== i)
2060
- throw new C(`Nonce mismatch: URI contained "${f}", expected "${i}". Possible replay attack.`);
2061
- try {
2062
- if (!await sr(n, r, s))
2063
- throw new C("Invalid signature.");
2064
- } catch (y) {
2065
- throw y instanceof C ? y : new C(`Unexpected error during signature verification: ${y.message}`);
2066
- }
2067
- return {
2068
- isValid: !0,
2069
- address: r,
2070
- nonce: f
2071
- // Return the nonce from the URI
2072
- };
2073
- }
2074
- export {
2075
- C as DigiIDError,
2076
- sr as _internalVerifySignature,
2077
- ur as generateDigiIDUri,
2078
- ar as verifyDigiIDCallback
682
+ let n = Pe(e.Fp, t.map((e) => e.Z));
683
+ return t.map((t, r) => e.fromAffine(t.toAffine(n[r])));
684
+ }
685
+ function Ue(e, t) {
686
+ if (!Number.isSafeInteger(e) || e <= 0 || e > t) throw Error("invalid window size, expected [1.." + t + "], got W=" + e);
687
+ }
688
+ function We(e, t) {
689
+ Ue(e, t);
690
+ let n = Math.ceil(t / e) + 1, r = 2 ** (e - 1), i = 2 ** e;
691
+ return {
692
+ windows: n,
693
+ windowSize: r,
694
+ mask: he(e),
695
+ maxNumber: i,
696
+ shiftBy: BigInt(e)
697
+ };
698
+ }
699
+ function Ge(e, t, n) {
700
+ let { windowSize: r, mask: i, maxNumber: a, shiftBy: o } = n, s = Number(e & i), c = e >> o;
701
+ s > r && (s -= a, c += q);
702
+ let l = t * r, u = l + Math.abs(s) - 1, d = s === 0, f = s < 0, p = t % 2 != 0;
703
+ return {
704
+ nextN: c,
705
+ offset: u,
706
+ isZero: d,
707
+ isNeg: f,
708
+ isNegF: p,
709
+ offsetF: l
710
+ };
711
+ }
712
+ var Ke = /* @__PURE__ */ new WeakMap(), qe = /* @__PURE__ */ new WeakMap();
713
+ function Je(e) {
714
+ return qe.get(e) || 1;
715
+ }
716
+ function Ye(e) {
717
+ if (e !== K) throw Error("invalid wNAF");
718
+ }
719
+ var Xe = class {
720
+ BASE;
721
+ ZERO;
722
+ Fn;
723
+ bits;
724
+ constructor(e, t) {
725
+ this.BASE = e.BASE, this.ZERO = e.ZERO, this.Fn = e.Fn, this.bits = t;
726
+ }
727
+ _unsafeLadder(e, t, n = this.ZERO) {
728
+ let r = e;
729
+ for (; t > K;) t & q && (n = n.add(r)), r = r.double(), t >>= q;
730
+ return n;
731
+ }
732
+ precomputeWindow(e, t) {
733
+ let { windows: n, windowSize: r } = We(t, this.bits), i = [], a = e, o = a;
734
+ for (let e = 0; e < n; e++) {
735
+ o = a, i.push(o);
736
+ for (let e = 1; e < r; e++) o = o.add(a), i.push(o);
737
+ a = o.double();
738
+ }
739
+ return i;
740
+ }
741
+ wNAF(e, t, n) {
742
+ if (!this.Fn.isValid(n)) throw Error("invalid scalar");
743
+ let r = this.ZERO, i = this.BASE, a = We(e, this.bits);
744
+ for (let e = 0; e < a.windows; e++) {
745
+ let { nextN: o, offset: s, isZero: c, isNeg: l, isNegF: u, offsetF: d } = Ge(n, e, a);
746
+ n = o, c ? i = i.add(J(u, t[d])) : r = r.add(J(l, t[s]));
747
+ }
748
+ return Ye(n), {
749
+ p: r,
750
+ f: i
751
+ };
752
+ }
753
+ wNAFUnsafe(e, t, n, r = this.ZERO) {
754
+ let i = We(e, this.bits);
755
+ for (let e = 0; e < i.windows && n !== K; e++) {
756
+ let { nextN: a, offset: o, isZero: s, isNeg: c } = Ge(n, e, i);
757
+ if (n = a, !s) {
758
+ let e = t[o];
759
+ r = r.add(c ? e.negate() : e);
760
+ }
761
+ }
762
+ return Ye(n), r;
763
+ }
764
+ getPrecomputes(e, t, n) {
765
+ let r = Ke.get(t);
766
+ return r || (r = this.precomputeWindow(t, e), e !== 1 && (typeof n == "function" && (r = n(r)), Ke.set(t, r))), r;
767
+ }
768
+ cached(e, t, n) {
769
+ let r = Je(e);
770
+ return this.wNAF(r, this.getPrecomputes(r, e, n), t);
771
+ }
772
+ unsafe(e, t, n, r) {
773
+ let i = Je(e);
774
+ return i === 1 ? this._unsafeLadder(e, t, r) : this.wNAFUnsafe(i, this.getPrecomputes(i, e, n), t, r);
775
+ }
776
+ createCache(e, t) {
777
+ Ue(t, this.bits), qe.set(e, t), Ke.delete(e);
778
+ }
779
+ hasCache(e) {
780
+ return Je(e) !== 1;
781
+ }
2079
782
  };
2080
- //# sourceMappingURL=digiid-ts.es.js.map
783
+ function Ze(e, t, n, r) {
784
+ let i = t, a = e.ZERO, o = e.ZERO;
785
+ for (; n > K || r > K;) n & q && (a = a.add(i)), r & q && (o = o.add(i)), i = i.double(), n >>= q, r >>= q;
786
+ return {
787
+ p1: a,
788
+ p2: o
789
+ };
790
+ }
791
+ function Qe(e, t, n) {
792
+ if (t) {
793
+ if (t.ORDER !== e) throw Error("Field.ORDER must match order: Fp == p, Fn == n");
794
+ return Me(t), t;
795
+ } else return G(e, { isLE: n });
796
+ }
797
+ function $e(e, t, n = {}, r) {
798
+ if (r === void 0 && (r = e === "edwards"), !t || typeof t != "object") throw Error(`expected valid ${e} CURVE object`);
799
+ for (let e of [
800
+ "p",
801
+ "n",
802
+ "h"
803
+ ]) {
804
+ let n = t[e];
805
+ if (!(typeof n == "bigint" && n > K)) throw Error(`CURVE.${e} must be positive bigint`);
806
+ }
807
+ let i = Qe(t.p, n.Fp, r), a = Qe(t.n, n.Fn, r), o = [
808
+ "Gx",
809
+ "Gy",
810
+ "a",
811
+ e === "weierstrass" ? "b" : "d"
812
+ ];
813
+ for (let e of o) if (!i.isValid(t[e])) throw Error(`CURVE.${e} must be valid field element of CURVE.Fp`);
814
+ return t = Object.freeze(Object.assign({}, t)), {
815
+ CURVE: t,
816
+ Fp: i,
817
+ Fn: a
818
+ };
819
+ }
820
+ function et(e, t) {
821
+ return function(n) {
822
+ let r = e(n);
823
+ return {
824
+ secretKey: r,
825
+ publicKey: t(r)
826
+ };
827
+ };
828
+ }
829
+ //#endregion
830
+ //#region node_modules/@noble/hashes/hmac.js
831
+ var tt = class {
832
+ oHash;
833
+ iHash;
834
+ blockLen;
835
+ outputLen;
836
+ canXOF = !1;
837
+ finished = !1;
838
+ destroyed = !1;
839
+ constructor(e, t) {
840
+ if (a(e), i(t, void 0, "key"), this.iHash = e.create(), typeof this.iHash.update != "function") throw Error("Expected instance of class which extends utils.Hash");
841
+ this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
842
+ let n = this.blockLen, r = new Uint8Array(n);
843
+ r.set(t.length > n ? e.create().update(t).digest() : t);
844
+ for (let e = 0; e < r.length; e++) r[e] ^= 54;
845
+ this.iHash.update(r), this.oHash = e.create();
846
+ for (let e = 0; e < r.length; e++) r[e] ^= 106;
847
+ this.oHash.update(r), c(r);
848
+ }
849
+ update(e) {
850
+ return o(this), this.iHash.update(e), this;
851
+ }
852
+ digestInto(e) {
853
+ o(this), s(e, this), this.finished = !0;
854
+ let t = e.subarray(0, this.outputLen);
855
+ this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
856
+ }
857
+ digest() {
858
+ let e = new Uint8Array(this.oHash.outputLen);
859
+ return this.digestInto(e), e;
860
+ }
861
+ _cloneInto(e) {
862
+ e ||= Object.create(Object.getPrototypeOf(this), {});
863
+ let { oHash: t, iHash: n, finished: r, destroyed: i, blockLen: a, outputLen: o } = this;
864
+ return e = e, e.finished = r, e.destroyed = i, e.blockLen = a, e.outputLen = o, e.oHash = t._cloneInto(e.oHash), e.iHash = n._cloneInto(e.iHash), e;
865
+ }
866
+ clone() {
867
+ return this._cloneInto();
868
+ }
869
+ destroy() {
870
+ this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
871
+ }
872
+ }, nt = /* @__PURE__ */ (() => {
873
+ let e = ((e, t, n) => new tt(e, t).update(n).digest());
874
+ return e.create = (e, t) => new tt(e, t), e;
875
+ })(), rt = (e, t) => (e + (e >= 0 ? t : -t) / st) / t;
876
+ function it(e, t, n) {
877
+ pe("scalar", e, X, n);
878
+ let [[r, i], [a, o]] = t, s = rt(o * e, n), c = rt(-i * e, n), l = e - s * r - c * a, u = -s * i - c * o, d = l < X, f = u < X;
879
+ d && (l = -l), f && (u = -u);
880
+ let p = he(Math.ceil(me(n) / 2)) + Z;
881
+ if (l < X || l >= p || u < X || u >= p) throw Error("splitScalar (endomorphism): failed for k");
882
+ return {
883
+ k1neg: d,
884
+ k1: l,
885
+ k2neg: f,
886
+ k2: u
887
+ };
888
+ }
889
+ function at(e) {
890
+ if (![
891
+ "compact",
892
+ "recovered",
893
+ "der"
894
+ ].includes(e)) throw Error("Signature format must be \"compact\", \"recovered\", or \"der\"");
895
+ return e;
896
+ }
897
+ function ot(e, t) {
898
+ z(e);
899
+ let n = {};
900
+ for (let r of Object.keys(t)) n[r] = e[r] === void 0 ? t[r] : e[r];
901
+ return F(n.lowS, "lowS"), F(n.prehash, "prehash"), n.format !== void 0 && at(n.format), n;
902
+ }
903
+ var Y = {
904
+ Err: class extends Error {
905
+ constructor(e = "") {
906
+ super(e);
907
+ }
908
+ },
909
+ _tlv: {
910
+ encode: (e, t) => {
911
+ let { Err: n } = Y;
912
+ if (oe(e, "tag"), e < 0 || e > 255) throw new n("tlv.encode: wrong tag");
913
+ if (typeof t != "string") throw TypeError("\"data\" expected string, got type=" + typeof t);
914
+ if (t.length & 1) throw new n("tlv.encode: unpadded data");
915
+ let r = t.length / 2, i = I(r);
916
+ if (i.length / 2 & 128) throw new n("tlv.encode: long form length too big");
917
+ let a = r > 127 ? I(i.length / 2 | 128) : "";
918
+ return I(e) + a + i + t;
919
+ },
920
+ decode(e, t) {
921
+ let { Err: n } = Y;
922
+ t = k(t, void 0, "DER data");
923
+ let r = 0;
924
+ if (e < 0 || e > 255) throw new n("tlv.encode: wrong tag");
925
+ if (t.length < 2 || t[r++] !== e) throw new n("tlv.decode: wrong tlv");
926
+ let i = t[r++], a = !!(i & 128), o = 0;
927
+ if (!a) o = i;
928
+ else {
929
+ let e = i & 127;
930
+ if (!e) throw new n("tlv.decode(long): indefinite length not supported");
931
+ if (e > 4) throw new n("tlv.decode(long): byte length is too big");
932
+ let a = t.subarray(r, r + e);
933
+ if (a.length !== e) throw new n("tlv.decode: length bytes not complete");
934
+ if (a[0] === 0) throw new n("tlv.decode(long): zero leftmost byte");
935
+ for (let e of a) o = o << 8 | e;
936
+ if (r += e, o < 128) throw new n("tlv.decode(long): not minimal encoding");
937
+ }
938
+ let s = t.subarray(r, r + o);
939
+ if (s.length !== o) throw new n("tlv.decode: wrong value length");
940
+ return {
941
+ v: s,
942
+ l: t.subarray(r + o)
943
+ };
944
+ }
945
+ },
946
+ _int: {
947
+ encode(e) {
948
+ let { Err: t } = Y;
949
+ if (ae(e), e < X) throw new t("integer: negative integers are not allowed");
950
+ let n = I(e);
951
+ if (Number.parseInt(n[0], 16) & 8 && (n = "00" + n), n.length & 1) throw new t("unexpected DER parsing assertion: unpadded hex");
952
+ return n;
953
+ },
954
+ decode(e) {
955
+ let { Err: t } = Y;
956
+ if (e.length < 1) throw new t("invalid signature integer: empty");
957
+ if (e[0] & 128) throw new t("invalid signature integer: negative");
958
+ if (e.length > 1 && e[0] === 0 && !(e[1] & 128)) throw new t("invalid signature integer: unnecessary leading zero");
959
+ return L(e);
960
+ }
961
+ },
962
+ toSig(e) {
963
+ let { Err: t, _int: n, _tlv: r } = Y, i = k(e, void 0, "signature"), { v: a, l: o } = r.decode(48, i);
964
+ if (o.length) throw new t("invalid signature: left bytes after parsing");
965
+ let { v: s, l: c } = r.decode(2, a), { v: l, l: u } = r.decode(2, c);
966
+ if (u.length) throw new t("invalid signature: left bytes after parsing");
967
+ return {
968
+ r: n.decode(s),
969
+ s: n.decode(l)
970
+ };
971
+ },
972
+ hexFromSig(e) {
973
+ let { _tlv: t, _int: n } = Y, r = t.encode(2, n.encode(e.r)) + t.encode(2, n.encode(e.s));
974
+ return t.encode(48, r);
975
+ }
976
+ };
977
+ Object.freeze(Y._tlv), Object.freeze(Y._int), Object.freeze(Y);
978
+ var X = /* @__PURE__ */ BigInt(0), Z = /* @__PURE__ */ BigInt(1), st = /* @__PURE__ */ BigInt(2), Q = /* @__PURE__ */ BigInt(3), ct = /* @__PURE__ */ BigInt(4);
979
+ function lt(e, t = {}) {
980
+ let n = $e("weierstrass", e, t), r = n.Fp, i = n.Fn, a = n.CURVE, { h: o, n: s } = a;
981
+ z(t, {}, {
982
+ allowInfinityPoint: "boolean",
983
+ clearCofactor: "function",
984
+ isTorsionFree: "function",
985
+ fromBytes: "function",
986
+ toBytes: "function",
987
+ endo: "object"
988
+ });
989
+ let { endo: c, allowInfinityPoint: l } = t;
990
+ if (c && (!r.is0(a.a) || typeof c.beta != "bigint" || !Array.isArray(c.basises))) throw Error("invalid endo: expected \"beta\": bigint and \"basises\": array");
991
+ let u = dt(r, i);
992
+ function d() {
993
+ if (!r.isOdd) throw Error("compression is not supported: Field does not have .isOdd()");
994
+ }
995
+ function f(e, t, n) {
996
+ if (l && t.is0()) return Uint8Array.of(0);
997
+ let { x: i, y: a } = t.toAffine(), o = r.toBytes(i);
998
+ return F(n, "isCompressed"), n ? (d(), j(ut(!r.isOdd(a)), o)) : j(Uint8Array.of(4), o, r.toBytes(a));
999
+ }
1000
+ function p(e) {
1001
+ k(e, void 0, "Point");
1002
+ let { publicKey: t, publicKeyUncompressed: n } = u, i = e.length, a = e[0], o = e.subarray(1);
1003
+ if (l && i === 1 && a === 0) return {
1004
+ x: r.ZERO,
1005
+ y: r.ZERO
1006
+ };
1007
+ if (i === t && (a === 2 || a === 3)) {
1008
+ let e = r.fromBytes(o);
1009
+ if (!r.isValid(e)) throw Error("bad point: is not on curve, wrong x");
1010
+ let t = g(e), n;
1011
+ try {
1012
+ n = r.sqrt(t);
1013
+ } catch (e) {
1014
+ let t = e instanceof Error ? ": " + e.message : "";
1015
+ throw Error("bad point: is not on curve, sqrt error" + t);
1016
+ }
1017
+ d();
1018
+ let i = r.isOdd(n);
1019
+ return (a & 1) == 1 !== i && (n = r.neg(n)), {
1020
+ x: e,
1021
+ y: n
1022
+ };
1023
+ } else if (i === n && a === 4) {
1024
+ let e = r.BYTES, t = r.fromBytes(o.subarray(0, e)), n = r.fromBytes(o.subarray(e, e * 2));
1025
+ if (!_(t, n)) throw Error("bad point: is not on curve");
1026
+ return {
1027
+ x: t,
1028
+ y: n
1029
+ };
1030
+ } else throw Error(`bad point: got length ${i}, expected compressed=${t} or uncompressed=${n}`);
1031
+ }
1032
+ let m = t.toBytes === void 0 ? f : t.toBytes, h = t.fromBytes === void 0 ? p : t.fromBytes;
1033
+ function g(e) {
1034
+ let t = r.sqr(e), n = r.mul(t, e);
1035
+ return r.add(r.add(n, r.mul(e, a.a)), a.b);
1036
+ }
1037
+ function _(e, t) {
1038
+ let n = r.sqr(t), i = g(e);
1039
+ return r.eql(n, i);
1040
+ }
1041
+ if (!_(a.Gx, a.Gy)) throw Error("bad curve params: generator point");
1042
+ let v = r.mul(r.pow(a.a, Q), ct), y = r.mul(r.sqr(a.b), BigInt(27));
1043
+ if (r.is0(r.add(v, y))) throw Error("bad curve params: a or b");
1044
+ function b(e, t, n = !1) {
1045
+ if (!r.isValid(t) || n && r.is0(t)) throw Error(`bad point coordinate ${e}`);
1046
+ return t;
1047
+ }
1048
+ function x(e) {
1049
+ if (!(e instanceof w)) throw Error("Weierstrass Point expected");
1050
+ }
1051
+ function S(e) {
1052
+ if (!c || !c.basises) throw Error("no endo");
1053
+ return it(e, c.basises, i.ORDER);
1054
+ }
1055
+ function C(e, t, n, i, a) {
1056
+ return n = new w(r.mul(n.X, e), n.Y, n.Z), t = J(i, t), n = J(a, n), t.add(n);
1057
+ }
1058
+ class w {
1059
+ static BASE = new w(a.Gx, a.Gy, r.ONE);
1060
+ static ZERO = new w(r.ZERO, r.ONE, r.ZERO);
1061
+ static Fp = r;
1062
+ static Fn = i;
1063
+ X;
1064
+ Y;
1065
+ Z;
1066
+ constructor(e, t, n) {
1067
+ this.X = b("x", e), this.Y = b("y", t, !0), this.Z = b("z", n), Object.freeze(this);
1068
+ }
1069
+ static CURVE() {
1070
+ return a;
1071
+ }
1072
+ static fromAffine(e) {
1073
+ let { x: t, y: n } = e || {};
1074
+ if (!e || !r.isValid(t) || !r.isValid(n)) throw Error("invalid affine point");
1075
+ if (e instanceof w) throw Error("projective point not allowed");
1076
+ return r.is0(t) && r.is0(n) ? w.ZERO : new w(t, n, r.ONE);
1077
+ }
1078
+ static fromBytes(e) {
1079
+ let t = w.fromAffine(h(k(e, void 0, "point")));
1080
+ return t.assertValidity(), t;
1081
+ }
1082
+ static fromHex(e) {
1083
+ return w.fromBytes(M(e));
1084
+ }
1085
+ get x() {
1086
+ return this.toAffine().x;
1087
+ }
1088
+ get y() {
1089
+ return this.toAffine().y;
1090
+ }
1091
+ precompute(e = 8, t = !0) {
1092
+ return E.createCache(this, e), t || this.multiply(Q), this;
1093
+ }
1094
+ assertValidity() {
1095
+ let e = this;
1096
+ if (e.is0()) {
1097
+ if (t.allowInfinityPoint && r.is0(e.X) && r.eql(e.Y, r.ONE) && r.is0(e.Z)) return;
1098
+ throw Error("bad point: ZERO");
1099
+ }
1100
+ let { x: n, y: i } = e.toAffine();
1101
+ if (!r.isValid(n) || !r.isValid(i)) throw Error("bad point: x or y not field elements");
1102
+ if (!_(n, i)) throw Error("bad point: equation left != right");
1103
+ if (!e.isTorsionFree()) throw Error("bad point: not in prime-order subgroup");
1104
+ }
1105
+ hasEvenY() {
1106
+ let { y: e } = this.toAffine();
1107
+ if (!r.isOdd) throw Error("Field doesn't support isOdd");
1108
+ return !r.isOdd(e);
1109
+ }
1110
+ equals(e) {
1111
+ x(e);
1112
+ let { X: t, Y: n, Z: i } = this, { X: a, Y: o, Z: s } = e, c = r.eql(r.mul(t, s), r.mul(a, i)), l = r.eql(r.mul(n, s), r.mul(o, i));
1113
+ return c && l;
1114
+ }
1115
+ negate() {
1116
+ return new w(this.X, r.neg(this.Y), this.Z);
1117
+ }
1118
+ double() {
1119
+ let { a: e, b: t } = a, n = r.mul(t, Q), { X: i, Y: o, Z: s } = this, c = r.ZERO, l = r.ZERO, u = r.ZERO, d = r.mul(i, i), f = r.mul(o, o), p = r.mul(s, s), m = r.mul(i, o);
1120
+ return m = r.add(m, m), u = r.mul(i, s), u = r.add(u, u), c = r.mul(e, u), l = r.mul(n, p), l = r.add(c, l), c = r.sub(f, l), l = r.add(f, l), l = r.mul(c, l), c = r.mul(m, c), u = r.mul(n, u), p = r.mul(e, p), m = r.sub(d, p), m = r.mul(e, m), m = r.add(m, u), u = r.add(d, d), d = r.add(u, d), d = r.add(d, p), d = r.mul(d, m), l = r.add(l, d), p = r.mul(o, s), p = r.add(p, p), d = r.mul(p, m), c = r.sub(c, d), u = r.mul(p, f), u = r.add(u, u), u = r.add(u, u), new w(c, l, u);
1121
+ }
1122
+ add(e) {
1123
+ x(e);
1124
+ let { X: t, Y: n, Z: i } = this, { X: o, Y: s, Z: c } = e, l = r.ZERO, u = r.ZERO, d = r.ZERO, f = a.a, p = r.mul(a.b, Q), m = r.mul(t, o), h = r.mul(n, s), g = r.mul(i, c), _ = r.add(t, n), v = r.add(o, s);
1125
+ _ = r.mul(_, v), v = r.add(m, h), _ = r.sub(_, v), v = r.add(t, i);
1126
+ let y = r.add(o, c);
1127
+ return v = r.mul(v, y), y = r.add(m, g), v = r.sub(v, y), y = r.add(n, i), l = r.add(s, c), y = r.mul(y, l), l = r.add(h, g), y = r.sub(y, l), d = r.mul(f, v), l = r.mul(p, g), d = r.add(l, d), l = r.sub(h, d), d = r.add(h, d), u = r.mul(l, d), h = r.add(m, m), h = r.add(h, m), g = r.mul(f, g), v = r.mul(p, v), h = r.add(h, g), g = r.sub(m, g), g = r.mul(f, g), v = r.add(v, g), m = r.mul(h, v), u = r.add(u, m), m = r.mul(y, v), l = r.mul(_, l), l = r.sub(l, m), m = r.mul(_, h), d = r.mul(y, d), d = r.add(d, m), new w(l, u, d);
1128
+ }
1129
+ subtract(e) {
1130
+ return x(e), this.add(e.negate());
1131
+ }
1132
+ is0() {
1133
+ return this.equals(w.ZERO);
1134
+ }
1135
+ multiply(e) {
1136
+ let { endo: n } = t;
1137
+ if (!i.isValidNot0(e)) throw RangeError("invalid scalar: out of range");
1138
+ let r, a, o = (e) => E.cached(this, e, (e) => He(w, e));
1139
+ if (n) {
1140
+ let { k1neg: t, k1: i, k2neg: s, k2: c } = S(e), { p: l, f: u } = o(i), { p: d, f } = o(c);
1141
+ a = u.add(f), r = C(n.beta, l, d, t, s);
1142
+ } else {
1143
+ let { p: t, f: n } = o(e);
1144
+ r = t, a = n;
1145
+ }
1146
+ return He(w, [r, a])[0];
1147
+ }
1148
+ multiplyUnsafe(e) {
1149
+ let { endo: n } = t, r = this, a = e;
1150
+ if (!i.isValid(a)) throw RangeError("invalid scalar: out of range");
1151
+ if (a === X || r.is0()) return w.ZERO;
1152
+ if (a === Z) return r;
1153
+ if (E.hasCache(this)) return this.multiply(a);
1154
+ if (n) {
1155
+ let { k1neg: e, k1: t, k2neg: i, k2: o } = S(a), { p1: s, p2: c } = Ze(w, r, t, o);
1156
+ return C(n.beta, s, c, e, i);
1157
+ } else return E.unsafe(r, a);
1158
+ }
1159
+ toAffine(e) {
1160
+ let t = this, n = e, { X: i, Y: a, Z: o } = t;
1161
+ if (r.eql(o, r.ONE)) return {
1162
+ x: i,
1163
+ y: a
1164
+ };
1165
+ let s = t.is0();
1166
+ n ??= s ? r.ONE : r.inv(o);
1167
+ let c = r.mul(i, n), l = r.mul(a, n), u = r.mul(o, n);
1168
+ if (s) return {
1169
+ x: r.ZERO,
1170
+ y: r.ZERO
1171
+ };
1172
+ if (!r.eql(u, r.ONE)) throw Error("invZ was invalid");
1173
+ return {
1174
+ x: c,
1175
+ y: l
1176
+ };
1177
+ }
1178
+ isTorsionFree() {
1179
+ let { isTorsionFree: e } = t;
1180
+ return o === Z ? !0 : e ? e(w, this) : E.unsafe(this, s).is0();
1181
+ }
1182
+ clearCofactor() {
1183
+ let { clearCofactor: e } = t;
1184
+ return o === Z ? this : e ? e(w, this) : this.multiplyUnsafe(o);
1185
+ }
1186
+ isSmallOrder() {
1187
+ return o === Z ? this.is0() : this.clearCofactor().is0();
1188
+ }
1189
+ toBytes(e = !0) {
1190
+ return F(e, "isCompressed"), this.assertValidity(), m(w, this, e);
1191
+ }
1192
+ toHex(e = !0) {
1193
+ return ne(this.toBytes(e));
1194
+ }
1195
+ toString() {
1196
+ return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
1197
+ }
1198
+ }
1199
+ let T = i.BITS, E = new Xe(w, t.endo ? Math.ceil(T / 2) : T);
1200
+ return T >= 8 && w.BASE.precompute(8), Object.freeze(w.prototype), Object.freeze(w), w;
1201
+ }
1202
+ function ut(e) {
1203
+ return Uint8Array.of(e ? 2 : 3);
1204
+ }
1205
+ function dt(e, t) {
1206
+ return {
1207
+ secretKey: t.BYTES,
1208
+ publicKey: 1 + e.BYTES,
1209
+ publicKeyUncompressed: 1 + 2 * e.BYTES,
1210
+ publicKeyHasPrefix: !0,
1211
+ signature: 2 * t.BYTES
1212
+ };
1213
+ }
1214
+ function ft(e, t = {}) {
1215
+ let { Fn: n } = e, r = t.randomBytes === void 0 ? ie : t.randomBytes, i = Object.assign(dt(e.Fp, n), { seed: Math.max(Be(n.ORDER), 16) });
1216
+ function a(e) {
1217
+ try {
1218
+ let t = n.fromBytes(e);
1219
+ return n.isValidNot0(t);
1220
+ } catch {
1221
+ return !1;
1222
+ }
1223
+ }
1224
+ function o(t, n) {
1225
+ let { publicKey: r, publicKeyUncompressed: a } = i;
1226
+ try {
1227
+ let i = t.length;
1228
+ return n === !0 && i !== r || n === !1 && i !== a ? !1 : !!e.fromBytes(t);
1229
+ } catch {
1230
+ return !1;
1231
+ }
1232
+ }
1233
+ function s(e) {
1234
+ return e = e === void 0 ? r(i.seed) : e, Ve(k(e, i.seed, "seed"), n.ORDER);
1235
+ }
1236
+ function c(t, r = !0) {
1237
+ return e.BASE.multiply(n.fromBytes(t)).toBytes(r);
1238
+ }
1239
+ function l(e) {
1240
+ let { secretKey: t, publicKey: r, publicKeyUncompressed: a } = i, o = n._lengths;
1241
+ if (!re(e)) return;
1242
+ let s = k(e, void 0, "key").length, c = s === r || s === a, l = s === t || !!o?.includes(s);
1243
+ if (!(c && l)) return c;
1244
+ }
1245
+ function u(t, r, i = !0) {
1246
+ if (l(t) === !0) throw Error("first arg must be private key");
1247
+ if (l(r) === !1) throw Error("second arg must be public key");
1248
+ let a = n.fromBytes(t);
1249
+ return e.fromBytes(r).multiply(a).toBytes(i);
1250
+ }
1251
+ let d = {
1252
+ isValidSecretKey: a,
1253
+ isValidPublicKey: o,
1254
+ randomSecretKey: s
1255
+ }, f = et(s, c);
1256
+ return Object.freeze(d), Object.freeze(i), Object.freeze({
1257
+ getPublicKey: c,
1258
+ getSharedSecret: u,
1259
+ keygen: f,
1260
+ Point: e,
1261
+ utils: d,
1262
+ lengths: i
1263
+ });
1264
+ }
1265
+ function pt(e, t, n = {}) {
1266
+ let r = t;
1267
+ a(r), z(n, {}, {
1268
+ hmac: "function",
1269
+ lowS: "boolean",
1270
+ randomBytes: "function",
1271
+ bits2int: "function",
1272
+ bits2int_modN: "function"
1273
+ }), n = Object.assign({}, n);
1274
+ let i = n.randomBytes === void 0 ? ie : n.randomBytes, o = n.hmac === void 0 ? (e, t) => nt(r, e, t) : n.hmac, { Fp: s, Fn: c } = e, { ORDER: l, BITS: u } = c, { keygen: d, getPublicKey: f, getSharedSecret: p, utils: m, lengths: h } = ft(e, n), g = {
1275
+ prehash: !0,
1276
+ lowS: typeof n.lowS == "boolean" ? n.lowS : !0,
1277
+ format: "compact",
1278
+ extraEntropy: !1
1279
+ }, _ = l * st + Z < s.ORDER;
1280
+ function v(e) {
1281
+ return e > l >> Z;
1282
+ }
1283
+ function y(e, t) {
1284
+ if (!c.isValidNot0(t)) throw Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);
1285
+ return t;
1286
+ }
1287
+ function b() {
1288
+ if (_) throw Error("\"recovered\" sig type is not supported for cofactor >2 curves");
1289
+ }
1290
+ function x(e, t) {
1291
+ at(t);
1292
+ let n = h.signature;
1293
+ return k(e, t === "compact" ? n : t === "recovered" ? n + 1 : void 0);
1294
+ }
1295
+ class S {
1296
+ r;
1297
+ s;
1298
+ recovery;
1299
+ constructor(e, t, n) {
1300
+ if (this.r = y("r", e), this.s = y("s", t), n != null) {
1301
+ if (b(), ![
1302
+ 0,
1303
+ 1,
1304
+ 2,
1305
+ 3
1306
+ ].includes(n)) throw Error("invalid recovery id");
1307
+ this.recovery = n;
1308
+ }
1309
+ Object.freeze(this);
1310
+ }
1311
+ static fromBytes(e, t = g.format) {
1312
+ x(e, t);
1313
+ let n;
1314
+ if (t === "der") {
1315
+ let { r: t, s: n } = Y.toSig(k(e));
1316
+ return new S(t, n);
1317
+ }
1318
+ t === "recovered" && (n = e[0], t = "compact", e = e.subarray(1));
1319
+ let r = h.signature / 2, i = e.subarray(0, r), a = e.subarray(r, r * 2);
1320
+ return new S(c.fromBytes(i), c.fromBytes(a), n);
1321
+ }
1322
+ static fromHex(e, t) {
1323
+ return this.fromBytes(M(e), t);
1324
+ }
1325
+ assertRecovery() {
1326
+ let { recovery: e } = this;
1327
+ if (e == null) throw Error("invalid recovery id: must be present");
1328
+ return e;
1329
+ }
1330
+ addRecoveryBit(e) {
1331
+ return new S(this.r, this.s, e);
1332
+ }
1333
+ recoverPublicKey(t) {
1334
+ let { r: n, s: r } = this, i = this.assertRecovery(), a = i === 2 || i === 3 ? n + l : n;
1335
+ if (!s.isValid(a)) throw Error("invalid recovery id: sig.r+curve.n != R.x");
1336
+ let o = s.toBytes(a), u = e.fromBytes(j(ut((i & 1) == 0), o)), d = c.inv(a), f = w(k(t, void 0, "msgHash")), p = c.create(-f * d), m = c.create(r * d), h = e.BASE.multiplyUnsafe(p).add(u.multiplyUnsafe(m));
1337
+ if (h.is0()) throw Error("invalid recovery: point at infinify");
1338
+ return h.assertValidity(), h;
1339
+ }
1340
+ hasHighS() {
1341
+ return v(this.s);
1342
+ }
1343
+ toBytes(e = g.format) {
1344
+ if (at(e), e === "der") return M(Y.hexFromSig(this));
1345
+ let { r: t, s: n } = this, r = c.toBytes(t), i = c.toBytes(n);
1346
+ return e === "recovered" ? (b(), j(Uint8Array.of(this.assertRecovery()), r, i)) : j(r, i);
1347
+ }
1348
+ toHex(e) {
1349
+ return ne(this.toBytes(e));
1350
+ }
1351
+ }
1352
+ Object.freeze(S.prototype), Object.freeze(S);
1353
+ let C = n.bits2int === void 0 ? function(e) {
1354
+ if (e.length > 8192) throw Error("input is too large");
1355
+ let t = L(e), n = e.length * 8 - u;
1356
+ return n > 0 ? t >> BigInt(n) : t;
1357
+ } : n.bits2int, w = n.bits2int_modN === void 0 ? function(e) {
1358
+ return c.create(C(e));
1359
+ } : n.bits2int_modN, T = he(u);
1360
+ function E(e) {
1361
+ return pe("num < 2^" + u, e, X, T), c.toBytes(e);
1362
+ }
1363
+ function D(e, t) {
1364
+ return k(e, void 0, "message"), t ? k(r(e), void 0, "prehashed message") : e;
1365
+ }
1366
+ function ee(t, n, r) {
1367
+ let { lowS: a, prehash: o, extraEntropy: s } = ot(r, g);
1368
+ t = D(t, o);
1369
+ let l = w(t), u = c.fromBytes(n);
1370
+ if (!c.isValidNot0(u)) throw Error("invalid private key");
1371
+ let d = [E(u), E(l)];
1372
+ if (s != null && s !== !1) {
1373
+ let e = s === !0 ? i(h.secretKey) : s;
1374
+ d.push(k(e, void 0, "extraEntropy"));
1375
+ }
1376
+ let f = j(...d), p = l;
1377
+ function m(t) {
1378
+ let n = C(t);
1379
+ if (!c.isValidNot0(n)) return;
1380
+ let r = c.inv(n), i = e.BASE.multiply(n).toAffine(), o = c.create(i.x);
1381
+ if (o === X) return;
1382
+ let s = c.create(r * c.create(p + o * u));
1383
+ if (s === X) return;
1384
+ let l = (i.x === o ? 0 : 2) | Number(i.y & Z), d = s;
1385
+ return a && v(s) && (d = c.neg(s), l ^= 1), new S(o, d, _ ? void 0 : l);
1386
+ }
1387
+ return {
1388
+ seed: f,
1389
+ k2sig: m
1390
+ };
1391
+ }
1392
+ function te(e, t, n = {}) {
1393
+ let { seed: i, k2sig: a } = ee(e, t, n);
1394
+ return ge(r.outputLen, c.BYTES, o)(i, a).toBytes(n.format);
1395
+ }
1396
+ function O(t, n, r, i = {}) {
1397
+ let { lowS: a, prehash: o, format: s } = ot(i, g);
1398
+ if (r = k(r, void 0, "publicKey"), n = D(n, o), !re(t)) {
1399
+ let e = t instanceof S ? ", use sig.toBytes()" : "";
1400
+ throw Error("verify expects Uint8Array signature" + e);
1401
+ }
1402
+ x(t, s);
1403
+ try {
1404
+ let i = S.fromBytes(t, s), o = e.fromBytes(r);
1405
+ if (a && i.hasHighS()) return !1;
1406
+ let { r: l, s: u } = i, d = w(n), f = c.inv(u), p = c.create(d * f), m = c.create(l * f), h = e.BASE.multiplyUnsafe(p).add(o.multiplyUnsafe(m));
1407
+ return h.is0() ? !1 : c.create(h.x) === l;
1408
+ } catch {
1409
+ return !1;
1410
+ }
1411
+ }
1412
+ function A(e, t, n = {}) {
1413
+ let { prehash: r } = ot(n, g);
1414
+ return t = D(t, r), S.fromBytes(e, "recovered").recoverPublicKey(t).toBytes();
1415
+ }
1416
+ return Object.freeze({
1417
+ keygen: d,
1418
+ getPublicKey: f,
1419
+ getSharedSecret: p,
1420
+ utils: m,
1421
+ lengths: h,
1422
+ Point: e,
1423
+ sign: te,
1424
+ verify: O,
1425
+ recoverPublicKey: A,
1426
+ Signature: S,
1427
+ hash: r
1428
+ });
1429
+ }
1430
+ //#endregion
1431
+ //#region node_modules/@noble/curves/secp256k1.js
1432
+ var mt = {
1433
+ p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
1434
+ n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
1435
+ h: BigInt(1),
1436
+ a: BigInt(0),
1437
+ b: BigInt(7),
1438
+ Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
1439
+ Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
1440
+ }, ht = {
1441
+ beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
1442
+ basises: [[BigInt("0x3086d221a7d46bcde86c90e49284eb15"), -BigInt("0xe4437ed6010e88286f547fa90abfe4c3")], [BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]
1443
+ }, gt = /* @__PURE__ */ BigInt(2);
1444
+ function _t(e) {
1445
+ let t = mt.p, n = BigInt(3), r = BigInt(6), i = BigInt(11), a = BigInt(22), o = BigInt(23), s = BigInt(44), c = BigInt(88), l = e * e * e % t, u = l * l * e % t, d = W(W(W(u, n, t) * u % t, n, t) * u % t, gt, t) * l % t, f = W(d, i, t) * d % t, p = W(f, a, t) * f % t, m = W(p, s, t) * p % t, h = W(W(W(W(W(W(m, c, t) * m % t, s, t) * p % t, n, t) * u % t, o, t) * f % t, r, t) * l % t, gt, t);
1446
+ if (!vt.eql(vt.sqr(h), e)) throw Error("Cannot find square root");
1447
+ return h;
1448
+ }
1449
+ var vt = G(mt.p, { sqrt: _t }), yt = /* @__PURE__ */ pt(/* @__PURE__ */ lt(mt, {
1450
+ Fp: vt,
1451
+ endo: ht
1452
+ }), O), bt = /* @__PURE__ */ Uint8Array.from([
1453
+ 7,
1454
+ 4,
1455
+ 13,
1456
+ 1,
1457
+ 10,
1458
+ 6,
1459
+ 15,
1460
+ 3,
1461
+ 12,
1462
+ 0,
1463
+ 9,
1464
+ 5,
1465
+ 2,
1466
+ 14,
1467
+ 11,
1468
+ 8
1469
+ ]), xt = /* @__PURE__ */ Uint8Array.from(Array(16).fill(0).map((e, t) => t)), St = /* @__PURE__ */ xt.map((e) => (9 * e + 5) % 16), Ct = /* @__PURE__ */ (() => {
1470
+ let e = [[xt], [St]];
1471
+ for (let t = 0; t < 4; t++) for (let n of e) n.push(n[t].map((e) => bt[e]));
1472
+ return e;
1473
+ })(), wt = Ct[0], Tt = Ct[1], Et = /* @__PURE__ */ [
1474
+ [
1475
+ 11,
1476
+ 14,
1477
+ 15,
1478
+ 12,
1479
+ 5,
1480
+ 8,
1481
+ 7,
1482
+ 9,
1483
+ 11,
1484
+ 13,
1485
+ 14,
1486
+ 15,
1487
+ 6,
1488
+ 7,
1489
+ 9,
1490
+ 8
1491
+ ],
1492
+ [
1493
+ 12,
1494
+ 13,
1495
+ 11,
1496
+ 15,
1497
+ 6,
1498
+ 9,
1499
+ 9,
1500
+ 7,
1501
+ 12,
1502
+ 15,
1503
+ 11,
1504
+ 13,
1505
+ 7,
1506
+ 8,
1507
+ 7,
1508
+ 7
1509
+ ],
1510
+ [
1511
+ 13,
1512
+ 15,
1513
+ 14,
1514
+ 11,
1515
+ 7,
1516
+ 7,
1517
+ 6,
1518
+ 8,
1519
+ 13,
1520
+ 14,
1521
+ 13,
1522
+ 12,
1523
+ 5,
1524
+ 5,
1525
+ 6,
1526
+ 9
1527
+ ],
1528
+ [
1529
+ 14,
1530
+ 11,
1531
+ 12,
1532
+ 14,
1533
+ 8,
1534
+ 6,
1535
+ 5,
1536
+ 5,
1537
+ 15,
1538
+ 12,
1539
+ 15,
1540
+ 14,
1541
+ 9,
1542
+ 9,
1543
+ 8,
1544
+ 6
1545
+ ],
1546
+ [
1547
+ 15,
1548
+ 12,
1549
+ 13,
1550
+ 13,
1551
+ 9,
1552
+ 5,
1553
+ 8,
1554
+ 6,
1555
+ 14,
1556
+ 11,
1557
+ 12,
1558
+ 11,
1559
+ 8,
1560
+ 6,
1561
+ 5,
1562
+ 5
1563
+ ]
1564
+ ].map((e) => Uint8Array.from(e)), Dt = /* @__PURE__ */ wt.map((e, t) => e.map((e) => Et[t][e])), Ot = /* @__PURE__ */ Tt.map((e, t) => e.map((e) => Et[t][e])), kt = /* @__PURE__ */ Uint32Array.from([
1565
+ 0,
1566
+ 1518500249,
1567
+ 1859775393,
1568
+ 2400959708,
1569
+ 2840853838
1570
+ ]), At = /* @__PURE__ */ Uint32Array.from([
1571
+ 1352829926,
1572
+ 1548603684,
1573
+ 1836072691,
1574
+ 2053994217,
1575
+ 0
1576
+ ]);
1577
+ function jt(e, t, n, r) {
1578
+ return e === 0 ? t ^ n ^ r : e === 1 ? t & n | ~t & r : e === 2 ? (t | ~n) ^ r : e === 3 ? t & r | n & ~r : t ^ (n | ~r);
1579
+ }
1580
+ var $ = /* @__PURE__ */ new Uint32Array(16), Mt = class extends w {
1581
+ h0 = 1732584193;
1582
+ h1 = -271733879;
1583
+ h2 = -1732584194;
1584
+ h3 = 271733878;
1585
+ h4 = -1009589776;
1586
+ constructor() {
1587
+ super(64, 20, 8, !0);
1588
+ }
1589
+ get() {
1590
+ let { h0: e, h1: t, h2: n, h3: r, h4: i } = this;
1591
+ return [
1592
+ e,
1593
+ t,
1594
+ n,
1595
+ r,
1596
+ i
1597
+ ];
1598
+ }
1599
+ set(e, t, n, r, i) {
1600
+ this.h0 = e | 0, this.h1 = t | 0, this.h2 = n | 0, this.h3 = r | 0, this.h4 = i | 0;
1601
+ }
1602
+ process(e, t) {
1603
+ for (let n = 0; n < 16; n++, t += 4) $[n] = e.getUint32(t, !0);
1604
+ let n = this.h0 | 0, r = n, i = this.h1 | 0, a = i, o = this.h2 | 0, s = o, c = this.h3 | 0, l = c, u = this.h4 | 0, f = u;
1605
+ for (let e = 0; e < 5; e++) {
1606
+ let t = 4 - e, p = kt[e], m = At[e], h = wt[e], g = Tt[e], _ = Dt[e], v = Ot[e];
1607
+ for (let t = 0; t < 16; t++) {
1608
+ let r = d(n + jt(e, i, o, c) + $[h[t]] + p, _[t]) + u | 0;
1609
+ n = u, u = c, c = d(o, 10) | 0, o = i, i = r;
1610
+ }
1611
+ for (let e = 0; e < 16; e++) {
1612
+ let n = d(r + jt(t, a, s, l) + $[g[e]] + m, v[e]) + f | 0;
1613
+ r = f, f = l, l = d(s, 10) | 0, s = a, a = n;
1614
+ }
1615
+ }
1616
+ this.set(this.h1 + o + l | 0, this.h2 + c + f | 0, this.h3 + u + r | 0, this.h4 + n + a | 0, this.h0 + i + s | 0);
1617
+ }
1618
+ roundClean() {
1619
+ c($);
1620
+ }
1621
+ destroy() {
1622
+ this.destroyed = !0, c(this.buffer), this.set(0, 0, 0, 0, 0);
1623
+ }
1624
+ }, Nt = /* @__PURE__ */ y(() => new Mt()), Pt = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
1625
+ function Ft(e) {
1626
+ let t = [0];
1627
+ for (let n = 0; n < e.length; n++) {
1628
+ let r = e[n];
1629
+ if (!r) continue;
1630
+ let i = Pt.indexOf(r);
1631
+ if (i === -1) throw Error("Invalid base58 character");
1632
+ for (let e = 0; e < t.length; e++) t[e] *= 58;
1633
+ t[0] += i;
1634
+ let a = 0;
1635
+ for (let e = 0; e < t.length; e++) t[e] = t[e] + a, a = t[e] >> 8, t[e] &= 255;
1636
+ for (; a > 0;) t.push(a & 255), a >>= 8;
1637
+ }
1638
+ for (let n = 0; n < e.length && e[n] === "1"; n++) t.push(0);
1639
+ return new Uint8Array(t.reverse());
1640
+ }
1641
+ function It(e) {
1642
+ let t = e.toLowerCase().split("1");
1643
+ if (t.length !== 2) return null;
1644
+ let n = t[0], r = t[1];
1645
+ if (!n || !r || n !== "dgb") return null;
1646
+ let i = [];
1647
+ for (let e of r) {
1648
+ let t = "qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(e);
1649
+ if (t === -1) return null;
1650
+ i.push(t);
1651
+ }
1652
+ let a = i.slice(0, -6);
1653
+ if (a.length < 1) return null;
1654
+ let o = a[0];
1655
+ if (o === void 0) return null;
1656
+ let s = Lt(a.slice(1), 5, 8, !1);
1657
+ return s ? {
1658
+ version: o,
1659
+ program: new Uint8Array(s)
1660
+ } : null;
1661
+ }
1662
+ function Lt(e, t, n, r) {
1663
+ let i = 0, a = 0, o = [], s = (1 << n) - 1;
1664
+ for (let r of e) {
1665
+ if (r < 0 || r >> t !== 0) return null;
1666
+ for (i = i << t | r, a += t; a >= n;) a -= n, o.push(i >> a & s);
1667
+ }
1668
+ if (r) a > 0 && o.push(i << n - a & s);
1669
+ else if (a >= t || i << n - a & s) return null;
1670
+ return o;
1671
+ }
1672
+ function Rt(e, t) {
1673
+ let n = new TextEncoder().encode(t), r = new TextEncoder().encode(e), i = [], a = r.length;
1674
+ if (a < 253) i.push(a);
1675
+ else if (a <= 65535) i.push(253, a & 255, a >> 8 & 255);
1676
+ else if (a <= 4294967295) i.push(254, a & 255, a >> 8 & 255, a >> 16 & 255, a >> 24 & 255);
1677
+ else throw Error("Message too long");
1678
+ let o = new Uint8Array(i), s = n.length + o.length + r.length, c = new Uint8Array(s), l = 0;
1679
+ return c.set(n, l), l += n.length, c.set(o, l), l += o.length, c.set(r, l), O(O(c));
1680
+ }
1681
+ function zt(e, t) {
1682
+ if (t.length !== 65) throw Error("Invalid signature length");
1683
+ if (t[0] === void 0) throw Error("Invalid signature");
1684
+ let n = t.slice(1, 33), r = t.slice(33, 65), i = [];
1685
+ for (let t = 0; t < 4; t++) try {
1686
+ let a = new yt.Signature(BigInt("0x" + Array.from(n).map((e) => e.toString(16).padStart(2, "0")).join("")), BigInt("0x" + Array.from(r).map((e) => e.toString(16).padStart(2, "0")).join(""))).addRecoveryBit(t).recoverPublicKey(e), o = a.toBytes(!0), s = a.toBytes(!1);
1687
+ i.push(o), i.push(s);
1688
+ } catch {
1689
+ continue;
1690
+ }
1691
+ if (i.length === 0) throw Error("Failed to recover any public keys");
1692
+ return i;
1693
+ }
1694
+ function Bt(e) {
1695
+ return Nt(O(e));
1696
+ }
1697
+ function Vt(e, t) {
1698
+ if (e.startsWith("D") || e.startsWith("S")) try {
1699
+ let n = Ft(e);
1700
+ if (n.length < 25) return !1;
1701
+ let r = n.slice(0, -4), i = n.slice(-4), a = O(O(r)).slice(0, 4);
1702
+ if (!i.every((e, t) => e === a[t])) return !1;
1703
+ let o = r.slice(1), s = Bt(t);
1704
+ return o.every((e, t) => e === s[t]);
1705
+ } catch {
1706
+ return !1;
1707
+ }
1708
+ if (e.toLowerCase().startsWith("dgb1")) try {
1709
+ let n = It(e);
1710
+ if (!n) return !1;
1711
+ let { version: r, program: i } = n;
1712
+ if (r === 0) {
1713
+ let e = t;
1714
+ if (t.length === 65) {
1715
+ let n = t[64] % 2 == 0;
1716
+ e = new Uint8Array(33), e[0] = n ? 2 : 3, e.set(t.slice(1, 33), 1);
1717
+ }
1718
+ let n = Bt(e);
1719
+ return i.every((e, t) => e === n[t]);
1720
+ }
1721
+ return !1;
1722
+ } catch {
1723
+ return !1;
1724
+ }
1725
+ return !1;
1726
+ }
1727
+ async function Ht(e, n, r) {
1728
+ try {
1729
+ let t = Uint8Array.from(globalThis.atob(r), (e) => e.charCodeAt(0));
1730
+ if (t.length !== 65) throw Error("Invalid signature length");
1731
+ let i = zt(Rt(e, "DigiByte Signed Message:\n"), t);
1732
+ for (let e of i) if (Vt(n, e)) return !0;
1733
+ return !1;
1734
+ } catch (e) {
1735
+ throw new t(`Signature verification failed: ${e instanceof Error ? e.message : String(e)}`);
1736
+ }
1737
+ }
1738
+ function Ut(t = 16) {
1739
+ return e(t).toString("hex");
1740
+ }
1741
+ function Wt(e) {
1742
+ if (!e.callbackUrl) throw new t("Callback URL is required.");
1743
+ let n;
1744
+ try {
1745
+ n = new URL(e.callbackUrl);
1746
+ } catch (e) {
1747
+ throw new t(`Invalid callback URL: ${e.message}`);
1748
+ }
1749
+ let r = n.host + n.pathname, i = e.nonce || Ut(), a = e.unsecure ? "1" : "0";
1750
+ if (e.unsecure && n.protocol !== "http:") throw new t("Unsecure flag is true, but callback URL does not use http protocol.");
1751
+ if (!e.unsecure && n.protocol !== "https:") throw new t("Callback URL must use https protocol unless unsecure flag is set to true.");
1752
+ return `digiid://${r}?x=${i}&u=${a}`;
1753
+ }
1754
+ async function Gt(e, n) {
1755
+ let { address: r, uri: i, signature: a } = e, { expectedCallbackUrl: o, expectedNonce: s } = n;
1756
+ if (!r || !i || !a) throw new t("Missing required callback data: address, uri, or signature.");
1757
+ let c;
1758
+ try {
1759
+ let e = i.replace(/^digiid:/, "http:");
1760
+ c = new URL(e);
1761
+ } catch (e) {
1762
+ throw new t(`Invalid URI received in callback: ${e.message}`);
1763
+ }
1764
+ let l = c.searchParams.get("x"), u = c.searchParams.get("u"), d = c.host + c.pathname;
1765
+ if (l === null || u === null) throw new t("URI missing nonce (x) or unsecure (u) parameter.");
1766
+ let f;
1767
+ try {
1768
+ f = typeof o == "string" ? new URL(o) : o;
1769
+ } catch (e) {
1770
+ throw new t(`Invalid expectedCallbackUrl provided: ${e.message}`);
1771
+ }
1772
+ let p = f.host + f.pathname;
1773
+ if (d !== p) throw new t(`Callback URL mismatch: URI contained "${d}", expected "${p}"`);
1774
+ let m = f.protocol;
1775
+ if (u === "1" && m !== "http:") throw new t("URI indicates unsecure (u=1), but expectedCallbackUrl is not http.");
1776
+ if (u === "0" && m !== "https:") throw new t("URI indicates secure (u=0), but expectedCallbackUrl is not https.");
1777
+ if (s && l !== s) throw new t(`Nonce mismatch: URI contained "${l}", expected "${s}". Possible replay attack.`);
1778
+ try {
1779
+ if (!await Ht(i, r, a)) throw new t("Invalid signature.");
1780
+ } catch (e) {
1781
+ throw e instanceof t ? e : new t(`Unexpected error during signature verification: ${e.message}`);
1782
+ }
1783
+ return {
1784
+ isValid: !0,
1785
+ address: r,
1786
+ nonce: l
1787
+ };
1788
+ }
1789
+ //#endregion
1790
+ export { t as DigiIDError, Ht as _internalVerifySignature, Wt as generateDigiIDUri, Gt as verifyDigiIDCallback };
1791
+
1792
+ //# sourceMappingURL=digiid-ts.es.js.map