@autogames/sdk 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +732 -0
  2. package/dist/PhArrowCircleDown-Db_5u1DC.js +73 -0
  3. package/dist/PhArrowClockwise-D5uNEUen.js +73 -0
  4. package/dist/PhArrowDown-CKkl0Ow8.js +73 -0
  5. package/dist/PhArrowLeft-5Y_-c8ih.js +73 -0
  6. package/dist/PhArrowRight-BAENQRa7.js +73 -0
  7. package/dist/PhArrowSquareOut-DlfAcw2e.js +73 -0
  8. package/dist/PhArrowUp-8KZkS1Bo.js +73 -0
  9. package/dist/PhArrowUpRight-DU3GSwzb.js +73 -0
  10. package/dist/PhArrowsClockwise-CShJ-Teu.js +73 -0
  11. package/dist/PhArrowsDownUp-BL_LzwqW.js +73 -0
  12. package/dist/PhArrowsLeftRight-B8vh7AsL.js +73 -0
  13. package/dist/PhBank-CP_QveNf.js +73 -0
  14. package/dist/PhBrowser-CCSpUQte.js +73 -0
  15. package/dist/PhCaretDown-C4u7yn0j.js +73 -0
  16. package/dist/PhCaretLeft-BSbx9BBc.js +73 -0
  17. package/dist/PhCaretRight-B1CumbxI.js +73 -0
  18. package/dist/PhCaretUp-CqiATiNS.js +73 -0
  19. package/dist/PhCheck-DNkwyplN.js +73 -0
  20. package/dist/PhCircleHalf-D4fgYYPo.js +73 -0
  21. package/dist/PhClock-DkIJeKoF.js +73 -0
  22. package/dist/PhCompass-CwVX0Z1y.js +73 -0
  23. package/dist/PhCopy-C0BiDhpw.js +73 -0
  24. package/dist/PhCreditCard-Bv5P9lrI.js +73 -0
  25. package/dist/PhCurrencyDollar-BCl4tAtz.js +73 -0
  26. package/dist/PhDesktop-DREPgw1q.js +73 -0
  27. package/dist/PhDeviceMobile-CM6lQlUa.js +73 -0
  28. package/dist/PhDotsThree-dmgI5Eht.js +73 -0
  29. package/dist/PhEnvelope-D7EatbfP.js +73 -0
  30. package/dist/PhFunnelSimple-Bs-Zsz_A.js +73 -0
  31. package/dist/PhGlobe-Azwq0DDw.js +73 -0
  32. package/dist/PhIdentificationCard-BZpHUHrg.js +73 -0
  33. package/dist/PhImage-CuSFzxM3.js +73 -0
  34. package/dist/PhInfo-B4SBturW.js +73 -0
  35. package/dist/PhLightbulb-79sWB45x.js +73 -0
  36. package/dist/PhMagnifyingGlass-CojwRGSu.js +73 -0
  37. package/dist/PhPaperPlaneRight-C3krm3eP.js +73 -0
  38. package/dist/PhPlus-DDYz48cV.js +73 -0
  39. package/dist/PhPower-CZWV02MF.js +73 -0
  40. package/dist/PhPuzzlePiece-fazdHBSU.js +73 -0
  41. package/dist/PhQrCode-BbBdb_ct.js +73 -0
  42. package/dist/PhQuestion-B6cc25Dw.js +73 -0
  43. package/dist/PhQuestionMark-TmZ4Sxa8.js +73 -0
  44. package/dist/PhSealCheck-CdKeNk5K.js +73 -0
  45. package/dist/PhSignOut-BBNQiKWI.js +73 -0
  46. package/dist/PhSpinner-BwqRA0He.js +73 -0
  47. package/dist/PhTrash-CXtQYiKu.js +73 -0
  48. package/dist/PhUser-DVV5XCqw.js +73 -0
  49. package/dist/PhVault-B73IPDB0.js +73 -0
  50. package/dist/PhWarning-BEhs8fc4.js +73 -0
  51. package/dist/PhWarningCircle-BA0Qvc1c.js +73 -0
  52. package/dist/PhX-CifUIiFs.js +73 -0
  53. package/dist/autogames-sdk.esm.js +5 -0
  54. package/dist/autogames-sdk.js +5247 -0
  55. package/dist/basic-R2aK52rX.js +4875 -0
  56. package/dist/bridge-mount-Bhf05oeO.js +89817 -0
  57. package/dist/ccip-Bg_nydEz.js +145 -0
  58. package/dist/ccip-CjgrAp_t.js +147 -0
  59. package/dist/core-CnCeDQAm.js +17712 -0
  60. package/dist/features-BrlR4_0m.js +268 -0
  61. package/dist/index-C9RsDt_J.js +8044 -0
  62. package/dist/index-Chq42DrS.js +2010 -0
  63. package/dist/index-HQNbtrlg.js +341 -0
  64. package/dist/index-zA8BVXWW.js +264 -0
  65. package/dist/main-oRLGGL0R.js +2284 -0
  66. package/dist/main.d.ts +342 -0
  67. package/dist/parseSignature-DFDCc7FD.js +131 -0
  68. package/dist/property-DkPmFHg2.js +587 -0
  69. package/dist/secp256k1-UpZfvHa8.js +1347 -0
  70. package/dist/stats-confirm.html +4949 -0
  71. package/dist/w3m-modal-ClvdQLsb.js +2822 -0
  72. package/package.json +48 -0
@@ -0,0 +1,1347 @@
1
+ import { db as nt, dc as qt, dd as ht, de as ue, df as D, dg as ae, dh as le, di as Ct, dj as de, dk as he } from "./bridge-mount-Bhf05oeO.js";
2
+ const Nt = /* @__PURE__ */ BigInt(0), xt = /* @__PURE__ */ BigInt(1);
3
+ function wt(e, n = "") {
4
+ if (typeof e != "boolean") {
5
+ const r = n && `"${n}"`;
6
+ throw new Error(r + "expected boolean, got type=" + typeof e);
7
+ }
8
+ return e;
9
+ }
10
+ function W(e, n, r = "") {
11
+ const t = qt(e), o = e?.length, i = n !== void 0;
12
+ if (!t || i && o !== n) {
13
+ const s = r && `"${r}" `, l = i ? ` of length ${n}` : "", a = t ? `length=${o}` : `type=${typeof e}`;
14
+ throw new Error(s + "expected Uint8Array" + l + ", got " + a);
15
+ }
16
+ return e;
17
+ }
18
+ function lt(e) {
19
+ const n = e.toString(16);
20
+ return n.length & 1 ? "0" + n : n;
21
+ }
22
+ function kt(e) {
23
+ if (typeof e != "string")
24
+ throw new Error("hex string expected, got " + typeof e);
25
+ return e === "" ? Nt : BigInt("0x" + e);
26
+ }
27
+ function mt(e) {
28
+ return kt(nt(e));
29
+ }
30
+ function zt(e) {
31
+ return ue(e), kt(nt(Uint8Array.from(e).reverse()));
32
+ }
33
+ function Rt(e, n) {
34
+ return ht(e.toString(16).padStart(n * 2, "0"));
35
+ }
36
+ function Ht(e, n) {
37
+ return Rt(e, n).reverse();
38
+ }
39
+ function L(e, n, r) {
40
+ let t;
41
+ if (typeof n == "string")
42
+ try {
43
+ t = ht(n);
44
+ } catch (o) {
45
+ throw new Error(e + " must be hex string or Uint8Array, cause: " + o);
46
+ }
47
+ else if (qt(n))
48
+ t = Uint8Array.from(n);
49
+ else
50
+ throw new Error(e + " must be hex string or Uint8Array");
51
+ return t.length, t;
52
+ }
53
+ const yt = (e) => typeof e == "bigint" && Nt <= e;
54
+ function we(e, n, r) {
55
+ return yt(e) && yt(n) && yt(r) && n <= e && e < r;
56
+ }
57
+ function ge(e, n, r, t) {
58
+ if (!we(n, r, t))
59
+ throw new Error("expected valid " + e + ": " + r + " <= n < " + t + ", got " + n);
60
+ }
61
+ function Xt(e) {
62
+ let n;
63
+ for (n = 0; e > Nt; e >>= xt, n += 1)
64
+ ;
65
+ return n;
66
+ }
67
+ const st = (e) => (xt << BigInt(e)) - xt;
68
+ function me(e, n, r) {
69
+ if (typeof e != "number" || e < 2)
70
+ throw new Error("hashLen must be a number");
71
+ if (typeof n != "number" || n < 2)
72
+ throw new Error("qByteLen must be a number");
73
+ if (typeof r != "function")
74
+ throw new Error("hmacFn must be a function");
75
+ const t = (h) => new Uint8Array(h), o = (h) => Uint8Array.of(h);
76
+ let i = t(e), s = t(e), l = 0;
77
+ const a = () => {
78
+ i.fill(1), s.fill(0), l = 0;
79
+ }, w = (...h) => r(s, i, ...h), y = (h = t(0)) => {
80
+ s = w(o(0), h), i = w(), h.length !== 0 && (s = w(o(1), h), i = w());
81
+ }, I = () => {
82
+ if (l++ >= 1e3)
83
+ throw new Error("drbg: tried 1000 values");
84
+ let h = 0;
85
+ const E = [];
86
+ for (; h < n; ) {
87
+ i = w();
88
+ const x = i.slice();
89
+ E.push(x), h += i.length;
90
+ }
91
+ return D(...E);
92
+ };
93
+ return (h, E) => {
94
+ a(), y(h);
95
+ let x;
96
+ for (; !(x = E(I())); )
97
+ y();
98
+ return a(), x;
99
+ };
100
+ }
101
+ function Ot(e, n, r = {}) {
102
+ if (!e || typeof e != "object")
103
+ throw new Error("expected valid options object");
104
+ function t(o, i, s) {
105
+ const l = e[o];
106
+ if (s && l === void 0)
107
+ return;
108
+ const a = typeof l;
109
+ if (a !== i || l === null)
110
+ throw new Error(`param "${o}" is invalid: expected ${i}, got ${a}`);
111
+ }
112
+ Object.entries(n).forEach(([o, i]) => t(o, i, !1)), Object.entries(r).forEach(([o, i]) => t(o, i, !0));
113
+ }
114
+ function Tt(e) {
115
+ const n = /* @__PURE__ */ new WeakMap();
116
+ return (r, ...t) => {
117
+ const o = n.get(r);
118
+ if (o !== void 0)
119
+ return o;
120
+ const i = e(r, ...t);
121
+ return n.set(r, i), i;
122
+ };
123
+ }
124
+ const M = BigInt(0), j = BigInt(1), Q = /* @__PURE__ */ BigInt(2), Dt = /* @__PURE__ */ BigInt(3), Gt = /* @__PURE__ */ BigInt(4), Ft = /* @__PURE__ */ BigInt(5), ye = /* @__PURE__ */ BigInt(7), Wt = /* @__PURE__ */ BigInt(8), be = /* @__PURE__ */ BigInt(9), Qt = /* @__PURE__ */ BigInt(16);
125
+ function k(e, n) {
126
+ const r = e % n;
127
+ return r >= M ? r : n + r;
128
+ }
129
+ function C(e, n, r) {
130
+ let t = e;
131
+ for (; n-- > M; )
132
+ t *= t, t %= r;
133
+ return t;
134
+ }
135
+ function Vt(e, n) {
136
+ if (e === M)
137
+ throw new Error("invert: expected non-zero number");
138
+ if (n <= M)
139
+ throw new Error("invert: expected positive modulus, got " + n);
140
+ let r = k(e, n), t = n, o = M, i = j;
141
+ for (; r !== M; ) {
142
+ const l = t / r, a = t % r, w = o - i * l;
143
+ t = r, r = a, o = i, i = w;
144
+ }
145
+ if (t !== j)
146
+ throw new Error("invert: does not exist");
147
+ return k(o, n);
148
+ }
149
+ function At(e, n, r) {
150
+ if (!e.eql(e.sqr(n), r))
151
+ throw new Error("Cannot find square root");
152
+ }
153
+ function Pt(e, n) {
154
+ const r = (e.ORDER + j) / Gt, t = e.pow(n, r);
155
+ return At(e, t, n), t;
156
+ }
157
+ function Ee(e, n) {
158
+ const r = (e.ORDER - Ft) / Wt, t = e.mul(n, Q), o = e.pow(t, r), i = e.mul(n, o), s = e.mul(e.mul(i, Q), o), l = e.mul(i, e.sub(s, e.ONE));
159
+ return At(e, l, n), l;
160
+ }
161
+ function pe(e) {
162
+ const n = ct(e), r = Jt(e), t = r(n, n.neg(n.ONE)), o = r(n, t), i = r(n, n.neg(t)), s = (e + ye) / Qt;
163
+ return (l, a) => {
164
+ let w = l.pow(a, s), y = l.mul(w, t);
165
+ const I = l.mul(w, o), f = l.mul(w, i), h = l.eql(l.sqr(y), a), E = l.eql(l.sqr(I), a);
166
+ w = l.cmov(w, y, h), y = l.cmov(f, I, E);
167
+ const x = l.eql(l.sqr(y), a), O = l.cmov(w, y, x);
168
+ return At(l, O, a), O;
169
+ };
170
+ }
171
+ function Jt(e) {
172
+ if (e < Dt)
173
+ throw new Error("sqrt is not defined for small field");
174
+ let n = e - j, r = 0;
175
+ for (; n % Q === M; )
176
+ n /= Q, r++;
177
+ let t = Q;
178
+ const o = ct(e);
179
+ for (; $t(o, t) === 1; )
180
+ if (t++ > 1e3)
181
+ throw new Error("Cannot find square root: probably non-prime P");
182
+ if (r === 1)
183
+ return Pt;
184
+ let i = o.pow(t, n);
185
+ const s = (n + j) / Q;
186
+ return function(a, w) {
187
+ if (a.is0(w))
188
+ return w;
189
+ if ($t(a, w) !== 1)
190
+ throw new Error("Cannot find square root");
191
+ let y = r, I = a.mul(a.ONE, i), f = a.pow(w, n), h = a.pow(w, s);
192
+ for (; !a.eql(f, a.ONE); ) {
193
+ if (a.is0(f))
194
+ return a.ZERO;
195
+ let E = 1, x = a.sqr(f);
196
+ for (; !a.eql(x, a.ONE); )
197
+ if (E++, x = a.sqr(x), E === y)
198
+ throw new Error("Cannot find square root");
199
+ const O = j << BigInt(y - E - 1), U = a.pow(I, O);
200
+ y = E, I = a.sqr(U), f = a.mul(f, I), h = a.mul(h, U);
201
+ }
202
+ return h;
203
+ };
204
+ }
205
+ function Be(e) {
206
+ return e % Gt === Dt ? Pt : e % Wt === Ft ? Ee : e % Qt === be ? pe(e) : Jt(e);
207
+ }
208
+ const ve = [
209
+ "create",
210
+ "isValid",
211
+ "is0",
212
+ "neg",
213
+ "inv",
214
+ "sqrt",
215
+ "sqr",
216
+ "eql",
217
+ "add",
218
+ "sub",
219
+ "mul",
220
+ "pow",
221
+ "div",
222
+ "addN",
223
+ "subN",
224
+ "mulN",
225
+ "sqrN"
226
+ ];
227
+ function xe(e) {
228
+ const n = {
229
+ ORDER: "bigint",
230
+ MASK: "bigint",
231
+ BYTES: "number",
232
+ BITS: "number"
233
+ }, r = ve.reduce((t, o) => (t[o] = "function", t), n);
234
+ return Ot(e, r), e;
235
+ }
236
+ function Se(e, n, r) {
237
+ if (r < M)
238
+ throw new Error("invalid exponent, negatives unsupported");
239
+ if (r === M)
240
+ return e.ONE;
241
+ if (r === j)
242
+ return n;
243
+ let t = e.ONE, o = n;
244
+ for (; r > M; )
245
+ r & j && (t = e.mul(t, o)), o = e.sqr(o), r >>= j;
246
+ return t;
247
+ }
248
+ function te(e, n, r = !1) {
249
+ const t = new Array(n.length).fill(r ? e.ZERO : void 0), o = n.reduce((s, l, a) => e.is0(l) ? s : (t[a] = s, e.mul(s, l)), e.ONE), i = e.inv(o);
250
+ return n.reduceRight((s, l, a) => e.is0(l) ? s : (t[a] = e.mul(s, t[a]), e.mul(s, l)), i), t;
251
+ }
252
+ function $t(e, n) {
253
+ const r = (e.ORDER - j) / Q, t = e.pow(n, r), o = e.eql(t, e.ONE), i = e.eql(t, e.ZERO), s = e.eql(t, e.neg(e.ONE));
254
+ if (!o && !i && !s)
255
+ throw new Error("invalid Legendre symbol result");
256
+ return o ? 1 : i ? 0 : -1;
257
+ }
258
+ function ee(e, n) {
259
+ n !== void 0 && ae(n);
260
+ const r = n !== void 0 ? n : e.toString(2).length, t = Math.ceil(r / 8);
261
+ return { nBitLength: r, nByteLength: t };
262
+ }
263
+ function ct(e, n, r = !1, t = {}) {
264
+ if (e <= M)
265
+ throw new Error("invalid field: expected ORDER > 0, got " + e);
266
+ let o, i, s = !1, l;
267
+ if (typeof n == "object" && n != null) {
268
+ if (t.sqrt || r)
269
+ throw new Error("cannot specify opts in two arguments");
270
+ const f = n;
271
+ f.BITS && (o = f.BITS), f.sqrt && (i = f.sqrt), typeof f.isLE == "boolean" && (r = f.isLE), typeof f.modFromBytes == "boolean" && (s = f.modFromBytes), l = f.allowedLengths;
272
+ } else
273
+ typeof n == "number" && (o = n), t.sqrt && (i = t.sqrt);
274
+ const { nBitLength: a, nByteLength: w } = ee(e, o);
275
+ if (w > 2048)
276
+ throw new Error("invalid field: expected ORDER of <= 2048 bytes");
277
+ let y;
278
+ const I = Object.freeze({
279
+ ORDER: e,
280
+ isLE: r,
281
+ BITS: a,
282
+ BYTES: w,
283
+ MASK: st(a),
284
+ ZERO: M,
285
+ ONE: j,
286
+ allowedLengths: l,
287
+ create: (f) => k(f, e),
288
+ isValid: (f) => {
289
+ if (typeof f != "bigint")
290
+ throw new Error("invalid field element: expected bigint, got " + typeof f);
291
+ return M <= f && f < e;
292
+ },
293
+ is0: (f) => f === M,
294
+ // is valid and invertible
295
+ isValidNot0: (f) => !I.is0(f) && I.isValid(f),
296
+ isOdd: (f) => (f & j) === j,
297
+ neg: (f) => k(-f, e),
298
+ eql: (f, h) => f === h,
299
+ sqr: (f) => k(f * f, e),
300
+ add: (f, h) => k(f + h, e),
301
+ sub: (f, h) => k(f - h, e),
302
+ mul: (f, h) => k(f * h, e),
303
+ pow: (f, h) => Se(I, f, h),
304
+ div: (f, h) => k(f * Vt(h, e), e),
305
+ // Same as above, but doesn't normalize
306
+ sqrN: (f) => f * f,
307
+ addN: (f, h) => f + h,
308
+ subN: (f, h) => f - h,
309
+ mulN: (f, h) => f * h,
310
+ inv: (f) => Vt(f, e),
311
+ sqrt: i || ((f) => (y || (y = Be(e)), y(I, f))),
312
+ toBytes: (f) => r ? Ht(f, w) : Rt(f, w),
313
+ fromBytes: (f, h = !0) => {
314
+ if (l) {
315
+ if (!l.includes(f.length) || f.length > w)
316
+ throw new Error("Field.fromBytes: expected " + l + " bytes, got " + f.length);
317
+ const x = new Uint8Array(w);
318
+ x.set(f, r ? 0 : x.length - f.length), f = x;
319
+ }
320
+ if (f.length !== w)
321
+ throw new Error("Field.fromBytes: expected " + w + " bytes, got " + f.length);
322
+ let E = r ? zt(f) : mt(f);
323
+ if (s && (E = k(E, e)), !h && !I.isValid(E))
324
+ throw new Error("invalid field element: outside of range 0..ORDER");
325
+ return E;
326
+ },
327
+ // TODO: we don't need it here, move out to separate fn
328
+ invertBatch: (f) => te(I, f),
329
+ // We can't move this out because Fp6, Fp12 implement it
330
+ // and it's unclear what to return in there.
331
+ cmov: (f, h, E) => E ? h : f
332
+ });
333
+ return Object.freeze(I);
334
+ }
335
+ function ne(e) {
336
+ if (typeof e != "bigint")
337
+ throw new Error("field order must be bigint");
338
+ const n = e.toString(2).length;
339
+ return Math.ceil(n / 8);
340
+ }
341
+ function re(e) {
342
+ const n = ne(e);
343
+ return n + Math.ceil(n / 2);
344
+ }
345
+ function Ie(e, n, r = !1) {
346
+ const t = e.length, o = ne(n), i = re(n);
347
+ if (t < 16 || t < i || t > 1024)
348
+ throw new Error("expected " + i + "-1024 bytes of input, got " + t);
349
+ const s = r ? zt(e) : mt(e), l = k(s, n - j) + j;
350
+ return r ? Ht(l, o) : Rt(l, o);
351
+ }
352
+ const ot = BigInt(0), P = BigInt(1);
353
+ function gt(e, n) {
354
+ const r = n.negate();
355
+ return e ? r : n;
356
+ }
357
+ function bt(e, n) {
358
+ const r = te(e.Fp, n.map((t) => t.Z));
359
+ return n.map((t, o) => e.fromAffine(t.toAffine(r[o])));
360
+ }
361
+ function oe(e, n) {
362
+ if (!Number.isSafeInteger(e) || e <= 0 || e > n)
363
+ throw new Error("invalid window size, expected [1.." + n + "], got W=" + e);
364
+ }
365
+ function Et(e, n) {
366
+ oe(e, n);
367
+ const r = Math.ceil(n / e) + 1, t = 2 ** (e - 1), o = 2 ** e, i = st(e), s = BigInt(e);
368
+ return { windows: r, windowSize: t, mask: i, maxNumber: o, shiftBy: s };
369
+ }
370
+ function Yt(e, n, r) {
371
+ const { windowSize: t, mask: o, maxNumber: i, shiftBy: s } = r;
372
+ let l = Number(e & o), a = e >> s;
373
+ l > t && (l -= i, a += P);
374
+ const w = n * t, y = w + Math.abs(l) - 1, I = l === 0, f = l < 0, h = n % 2 !== 0;
375
+ return { nextN: a, offset: y, isZero: I, isNeg: f, isNegF: h, offsetF: w };
376
+ }
377
+ function qe(e, n) {
378
+ if (!Array.isArray(e))
379
+ throw new Error("array expected");
380
+ e.forEach((r, t) => {
381
+ if (!(r instanceof n))
382
+ throw new Error("invalid point at index " + t);
383
+ });
384
+ }
385
+ function Ne(e, n) {
386
+ if (!Array.isArray(e))
387
+ throw new Error("array of scalars expected");
388
+ e.forEach((r, t) => {
389
+ if (!n.isValid(r))
390
+ throw new Error("invalid scalar at index " + t);
391
+ });
392
+ }
393
+ const pt = /* @__PURE__ */ new WeakMap(), ie = /* @__PURE__ */ new WeakMap();
394
+ function Bt(e) {
395
+ return ie.get(e) || 1;
396
+ }
397
+ function jt(e) {
398
+ if (e !== ot)
399
+ throw new Error("invalid wNAF");
400
+ }
401
+ class Re {
402
+ // Parametrized with a given Point class (not individual point)
403
+ constructor(n, r) {
404
+ this.BASE = n.BASE, this.ZERO = n.ZERO, this.Fn = n.Fn, this.bits = r;
405
+ }
406
+ // non-const time multiplication ladder
407
+ _unsafeLadder(n, r, t = this.ZERO) {
408
+ let o = n;
409
+ for (; r > ot; )
410
+ r & P && (t = t.add(o)), o = o.double(), r >>= P;
411
+ return t;
412
+ }
413
+ /**
414
+ * Creates a wNAF precomputation window. Used for caching.
415
+ * Default window size is set by `utils.precompute()` and is equal to 8.
416
+ * Number of precomputed points depends on the curve size:
417
+ * 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
418
+ * - 𝑊 is the window size
419
+ * - 𝑛 is the bitlength of the curve order.
420
+ * For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
421
+ * @param point Point instance
422
+ * @param W window size
423
+ * @returns precomputed point tables flattened to a single array
424
+ */
425
+ precomputeWindow(n, r) {
426
+ const { windows: t, windowSize: o } = Et(r, this.bits), i = [];
427
+ let s = n, l = s;
428
+ for (let a = 0; a < t; a++) {
429
+ l = s, i.push(l);
430
+ for (let w = 1; w < o; w++)
431
+ l = l.add(s), i.push(l);
432
+ s = l.double();
433
+ }
434
+ return i;
435
+ }
436
+ /**
437
+ * Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
438
+ * More compact implementation:
439
+ * https://github.com/paulmillr/noble-secp256k1/blob/47cb1669b6e506ad66b35fe7d76132ae97465da2/index.ts#L502-L541
440
+ * @returns real and fake (for const-time) points
441
+ */
442
+ wNAF(n, r, t) {
443
+ if (!this.Fn.isValid(t))
444
+ throw new Error("invalid scalar");
445
+ let o = this.ZERO, i = this.BASE;
446
+ const s = Et(n, this.bits);
447
+ for (let l = 0; l < s.windows; l++) {
448
+ const { nextN: a, offset: w, isZero: y, isNeg: I, isNegF: f, offsetF: h } = Yt(t, l, s);
449
+ t = a, y ? i = i.add(gt(f, r[h])) : o = o.add(gt(I, r[w]));
450
+ }
451
+ return jt(t), { p: o, f: i };
452
+ }
453
+ /**
454
+ * Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
455
+ * @param acc accumulator point to add result of multiplication
456
+ * @returns point
457
+ */
458
+ wNAFUnsafe(n, r, t, o = this.ZERO) {
459
+ const i = Et(n, this.bits);
460
+ for (let s = 0; s < i.windows && t !== ot; s++) {
461
+ const { nextN: l, offset: a, isZero: w, isNeg: y } = Yt(t, s, i);
462
+ if (t = l, !w) {
463
+ const I = r[a];
464
+ o = o.add(y ? I.negate() : I);
465
+ }
466
+ }
467
+ return jt(t), o;
468
+ }
469
+ getPrecomputes(n, r, t) {
470
+ let o = pt.get(r);
471
+ return o || (o = this.precomputeWindow(r, n), n !== 1 && (typeof t == "function" && (o = t(o)), pt.set(r, o))), o;
472
+ }
473
+ cached(n, r, t) {
474
+ const o = Bt(n);
475
+ return this.wNAF(o, this.getPrecomputes(o, n, t), r);
476
+ }
477
+ unsafe(n, r, t, o) {
478
+ const i = Bt(n);
479
+ return i === 1 ? this._unsafeLadder(n, r, o) : this.wNAFUnsafe(i, this.getPrecomputes(i, n, t), r, o);
480
+ }
481
+ // We calculate precomputes for elliptic curve point multiplication
482
+ // using windowed method. This specifies window size and
483
+ // stores precomputed values. Usually only base point would be precomputed.
484
+ createCache(n, r) {
485
+ oe(r, this.bits), ie.set(n, r), pt.delete(n);
486
+ }
487
+ hasCache(n) {
488
+ return Bt(n) !== 1;
489
+ }
490
+ }
491
+ function Oe(e, n, r, t) {
492
+ let o = n, i = e.ZERO, s = e.ZERO;
493
+ for (; r > ot || t > ot; )
494
+ r & P && (i = i.add(o)), t & P && (s = s.add(o)), o = o.double(), r >>= P, t >>= P;
495
+ return { p1: i, p2: s };
496
+ }
497
+ function Ae(e, n, r, t) {
498
+ qe(r, e), Ne(t, n);
499
+ const o = r.length, i = t.length;
500
+ if (o !== i)
501
+ throw new Error("arrays of points and scalars must have equal length");
502
+ const s = e.ZERO, l = Xt(BigInt(o));
503
+ let a = 1;
504
+ l > 12 ? a = l - 3 : l > 4 ? a = l - 2 : l > 0 && (a = 2);
505
+ const w = st(a), y = new Array(Number(w) + 1).fill(s), I = Math.floor((n.BITS - 1) / a) * a;
506
+ let f = s;
507
+ for (let h = I; h >= 0; h -= a) {
508
+ y.fill(s);
509
+ for (let x = 0; x < i; x++) {
510
+ const O = t[x], U = Number(O >> BigInt(h) & w);
511
+ y[U] = y[U].add(r[x]);
512
+ }
513
+ let E = s;
514
+ for (let x = y.length - 1, O = s; x > 0; x--)
515
+ O = O.add(y[x]), E = E.add(O);
516
+ if (f = f.add(E), h !== 0)
517
+ for (let x = 0; x < a; x++)
518
+ f = f.double();
519
+ }
520
+ return f;
521
+ }
522
+ function Kt(e, n, r) {
523
+ if (n) {
524
+ if (n.ORDER !== e)
525
+ throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
526
+ return xe(n), n;
527
+ } else
528
+ return ct(e, { isLE: r });
529
+ }
530
+ function _e(e, n, r = {}, t) {
531
+ if (t === void 0 && (t = e === "edwards"), !n || typeof n != "object")
532
+ throw new Error(`expected valid ${e} CURVE object`);
533
+ for (const a of ["p", "n", "h"]) {
534
+ const w = n[a];
535
+ if (!(typeof w == "bigint" && w > ot))
536
+ throw new Error(`CURVE.${a} must be positive bigint`);
537
+ }
538
+ const o = Kt(n.p, r.Fp, t), i = Kt(n.n, r.Fn, t), l = ["Gx", "Gy", "a", "b"];
539
+ for (const a of l)
540
+ if (!o.isValid(n[a]))
541
+ throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);
542
+ return n = Object.freeze(Object.assign({}, n)), { CURVE: n, Fp: o, Fn: i };
543
+ }
544
+ const Lt = (e, n) => (e + (e >= 0 ? n : -n) / se) / n;
545
+ function Ze(e, n, r) {
546
+ const [[t, o], [i, s]] = n, l = Lt(s * e, r), a = Lt(-o * e, r);
547
+ let w = e - l * t - a * i, y = -l * o - a * s;
548
+ const I = w < H, f = y < H;
549
+ I && (w = -w), f && (y = -y);
550
+ const h = st(Math.ceil(Xt(r) / 2)) + rt;
551
+ if (w < H || w >= h || y < H || y >= h)
552
+ throw new Error("splitScalar (endomorphism): failed, k=" + e);
553
+ return { k1neg: I, k1: w, k2neg: f, k2: y };
554
+ }
555
+ function St(e) {
556
+ if (!["compact", "recovered", "der"].includes(e))
557
+ throw new Error('Signature format must be "compact", "recovered", or "der"');
558
+ return e;
559
+ }
560
+ function vt(e, n) {
561
+ const r = {};
562
+ for (let t of Object.keys(n))
563
+ r[t] = e[t] === void 0 ? n[t] : e[t];
564
+ return wt(r.lowS, "lowS"), wt(r.prehash, "prehash"), r.format !== void 0 && St(r.format), r;
565
+ }
566
+ class Ue extends Error {
567
+ constructor(n = "") {
568
+ super(n);
569
+ }
570
+ }
571
+ const z = {
572
+ // asn.1 DER encoding utils
573
+ Err: Ue,
574
+ // Basic building block is TLV (Tag-Length-Value)
575
+ _tlv: {
576
+ encode: (e, n) => {
577
+ const { Err: r } = z;
578
+ if (e < 0 || e > 256)
579
+ throw new r("tlv.encode: wrong tag");
580
+ if (n.length & 1)
581
+ throw new r("tlv.encode: unpadded data");
582
+ const t = n.length / 2, o = lt(t);
583
+ if (o.length / 2 & 128)
584
+ throw new r("tlv.encode: long form length too big");
585
+ const i = t > 127 ? lt(o.length / 2 | 128) : "";
586
+ return lt(e) + i + o + n;
587
+ },
588
+ // v - value, l - left bytes (unparsed)
589
+ decode(e, n) {
590
+ const { Err: r } = z;
591
+ let t = 0;
592
+ if (e < 0 || e > 256)
593
+ throw new r("tlv.encode: wrong tag");
594
+ if (n.length < 2 || n[t++] !== e)
595
+ throw new r("tlv.decode: wrong tlv");
596
+ const o = n[t++], i = !!(o & 128);
597
+ let s = 0;
598
+ if (!i)
599
+ s = o;
600
+ else {
601
+ const a = o & 127;
602
+ if (!a)
603
+ throw new r("tlv.decode(long): indefinite length not supported");
604
+ if (a > 4)
605
+ throw new r("tlv.decode(long): byte length is too big");
606
+ const w = n.subarray(t, t + a);
607
+ if (w.length !== a)
608
+ throw new r("tlv.decode: length bytes not complete");
609
+ if (w[0] === 0)
610
+ throw new r("tlv.decode(long): zero leftmost byte");
611
+ for (const y of w)
612
+ s = s << 8 | y;
613
+ if (t += a, s < 128)
614
+ throw new r("tlv.decode(long): not minimal encoding");
615
+ }
616
+ const l = n.subarray(t, t + s);
617
+ if (l.length !== s)
618
+ throw new r("tlv.decode: wrong value length");
619
+ return { v: l, l: n.subarray(t + s) };
620
+ }
621
+ },
622
+ // https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
623
+ // since we always use positive integers here. It must always be empty:
624
+ // - add zero byte if exists
625
+ // - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
626
+ _int: {
627
+ encode(e) {
628
+ const { Err: n } = z;
629
+ if (e < H)
630
+ throw new n("integer: negative integers are not allowed");
631
+ let r = lt(e);
632
+ if (Number.parseInt(r[0], 16) & 8 && (r = "00" + r), r.length & 1)
633
+ throw new n("unexpected DER parsing assertion: unpadded hex");
634
+ return r;
635
+ },
636
+ decode(e) {
637
+ const { Err: n } = z;
638
+ if (e[0] & 128)
639
+ throw new n("invalid signature integer: negative");
640
+ if (e[0] === 0 && !(e[1] & 128))
641
+ throw new n("invalid signature integer: unnecessary leading zero");
642
+ return mt(e);
643
+ }
644
+ },
645
+ toSig(e) {
646
+ const { Err: n, _int: r, _tlv: t } = z, o = L("signature", e), { v: i, l: s } = t.decode(48, o);
647
+ if (s.length)
648
+ throw new n("invalid signature: left bytes after parsing");
649
+ const { v: l, l: a } = t.decode(2, i), { v: w, l: y } = t.decode(2, a);
650
+ if (y.length)
651
+ throw new n("invalid signature: left bytes after parsing");
652
+ return { r: r.decode(l), s: r.decode(w) };
653
+ },
654
+ hexFromSig(e) {
655
+ const { _tlv: n, _int: r } = z, t = n.encode(2, r.encode(e.r)), o = n.encode(2, r.encode(e.s)), i = t + o;
656
+ return n.encode(48, i);
657
+ }
658
+ }, H = BigInt(0), rt = BigInt(1), se = BigInt(2), dt = BigInt(3), Te = BigInt(4);
659
+ function et(e, n) {
660
+ const { BYTES: r } = e;
661
+ let t;
662
+ if (typeof n == "bigint")
663
+ t = n;
664
+ else {
665
+ let o = L("private key", n);
666
+ try {
667
+ t = e.fromBytes(o);
668
+ } catch {
669
+ throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof n}`);
670
+ }
671
+ }
672
+ if (!e.isValidNot0(t))
673
+ throw new Error("invalid private key: out of range [1..N-1]");
674
+ return t;
675
+ }
676
+ function Ve(e, n = {}) {
677
+ const r = _e("weierstrass", e, n), { Fp: t, Fn: o } = r;
678
+ let i = r.CURVE;
679
+ const { h: s, n: l } = i;
680
+ Ot(n, {}, {
681
+ allowInfinityPoint: "boolean",
682
+ clearCofactor: "function",
683
+ isTorsionFree: "function",
684
+ fromBytes: "function",
685
+ toBytes: "function",
686
+ endo: "object",
687
+ wrapPrivateKey: "boolean"
688
+ });
689
+ const { endo: a } = n;
690
+ if (a && (!t.is0(i.a) || typeof a.beta != "bigint" || !Array.isArray(a.basises)))
691
+ throw new Error('invalid endo: expected "beta": bigint and "basises": array');
692
+ const w = fe(t, o);
693
+ function y() {
694
+ if (!t.isOdd)
695
+ throw new Error("compression is not supported: Field does not have .isOdd()");
696
+ }
697
+ function I(R, d, u) {
698
+ const { x: c, y: g } = d.toAffine(), m = t.toBytes(c);
699
+ if (wt(u, "isCompressed"), u) {
700
+ y();
701
+ const B = !t.isOdd(g);
702
+ return D(ce(B), m);
703
+ } else
704
+ return D(Uint8Array.of(4), m, t.toBytes(g));
705
+ }
706
+ function f(R) {
707
+ W(R, void 0, "Point");
708
+ const { publicKey: d, publicKeyUncompressed: u } = w, c = R.length, g = R[0], m = R.subarray(1);
709
+ if (c === d && (g === 2 || g === 3)) {
710
+ const B = t.fromBytes(m);
711
+ if (!t.isValid(B))
712
+ throw new Error("bad point: is not on curve, wrong x");
713
+ const p = x(B);
714
+ let b;
715
+ try {
716
+ b = t.sqrt(p);
717
+ } catch (V) {
718
+ const A = V instanceof Error ? ": " + V.message : "";
719
+ throw new Error("bad point: is not on curve, sqrt error" + A);
720
+ }
721
+ y();
722
+ const v = t.isOdd(b);
723
+ return (g & 1) === 1 !== v && (b = t.neg(b)), { x: B, y: b };
724
+ } else if (c === u && g === 4) {
725
+ const B = t.BYTES, p = t.fromBytes(m.subarray(0, B)), b = t.fromBytes(m.subarray(B, B * 2));
726
+ if (!O(p, b))
727
+ throw new Error("bad point: is not on curve");
728
+ return { x: p, y: b };
729
+ } else
730
+ throw new Error(`bad point: got length ${c}, expected compressed=${d} or uncompressed=${u}`);
731
+ }
732
+ const h = n.toBytes || I, E = n.fromBytes || f;
733
+ function x(R) {
734
+ const d = t.sqr(R), u = t.mul(d, R);
735
+ return t.add(t.add(u, t.mul(R, i.a)), i.b);
736
+ }
737
+ function O(R, d) {
738
+ const u = t.sqr(d), c = x(R);
739
+ return t.eql(u, c);
740
+ }
741
+ if (!O(i.Gx, i.Gy))
742
+ throw new Error("bad curve params: generator point");
743
+ const U = t.mul(t.pow(i.a, dt), Te), it = t.mul(t.sqr(i.b), BigInt(27));
744
+ if (t.is0(t.add(U, it)))
745
+ throw new Error("bad curve params: a or b");
746
+ function T(R, d, u = !1) {
747
+ if (!t.isValid(d) || u && t.is0(d))
748
+ throw new Error(`bad point coordinate ${R}`);
749
+ return d;
750
+ }
751
+ function G(R) {
752
+ if (!(R instanceof q))
753
+ throw new Error("ProjectivePoint expected");
754
+ }
755
+ function X(R) {
756
+ if (!a || !a.basises)
757
+ throw new Error("no endo");
758
+ return Ze(R, a.basises, o.ORDER);
759
+ }
760
+ const J = Tt((R, d) => {
761
+ const { X: u, Y: c, Z: g } = R;
762
+ if (t.eql(g, t.ONE))
763
+ return { x: u, y: c };
764
+ const m = R.is0();
765
+ d == null && (d = m ? t.ONE : t.inv(g));
766
+ const B = t.mul(u, d), p = t.mul(c, d), b = t.mul(g, d);
767
+ if (m)
768
+ return { x: t.ZERO, y: t.ZERO };
769
+ if (!t.eql(b, t.ONE))
770
+ throw new Error("invZ was invalid");
771
+ return { x: B, y: p };
772
+ }), ft = Tt((R) => {
773
+ if (R.is0()) {
774
+ if (n.allowInfinityPoint && !t.is0(R.Y))
775
+ return;
776
+ throw new Error("bad point: ZERO");
777
+ }
778
+ const { x: d, y: u } = R.toAffine();
779
+ if (!t.isValid(d) || !t.isValid(u))
780
+ throw new Error("bad point: x or y not field elements");
781
+ if (!O(d, u))
782
+ throw new Error("bad point: equation left != right");
783
+ if (!R.isTorsionFree())
784
+ throw new Error("bad point: not in prime-order subgroup");
785
+ return !0;
786
+ });
787
+ function tt(R, d, u, c, g) {
788
+ return u = new q(t.mul(u.X, R), u.Y, u.Z), d = gt(c, d), u = gt(g, u), d.add(u);
789
+ }
790
+ class q {
791
+ /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
792
+ constructor(d, u, c) {
793
+ this.X = T("x", d), this.Y = T("y", u, !0), this.Z = T("z", c), Object.freeze(this);
794
+ }
795
+ static CURVE() {
796
+ return i;
797
+ }
798
+ /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
799
+ static fromAffine(d) {
800
+ const { x: u, y: c } = d || {};
801
+ if (!d || !t.isValid(u) || !t.isValid(c))
802
+ throw new Error("invalid affine point");
803
+ if (d instanceof q)
804
+ throw new Error("projective point not allowed");
805
+ return t.is0(u) && t.is0(c) ? q.ZERO : new q(u, c, t.ONE);
806
+ }
807
+ static fromBytes(d) {
808
+ const u = q.fromAffine(E(W(d, void 0, "point")));
809
+ return u.assertValidity(), u;
810
+ }
811
+ static fromHex(d) {
812
+ return q.fromBytes(L("pointHex", d));
813
+ }
814
+ get x() {
815
+ return this.toAffine().x;
816
+ }
817
+ get y() {
818
+ return this.toAffine().y;
819
+ }
820
+ /**
821
+ *
822
+ * @param windowSize
823
+ * @param isLazy true will defer table computation until the first multiplication
824
+ * @returns
825
+ */
826
+ precompute(d = 8, u = !0) {
827
+ return F.createCache(this, d), u || this.multiply(dt), this;
828
+ }
829
+ // TODO: return `this`
830
+ /** A point on curve is valid if it conforms to equation. */
831
+ assertValidity() {
832
+ ft(this);
833
+ }
834
+ hasEvenY() {
835
+ const { y: d } = this.toAffine();
836
+ if (!t.isOdd)
837
+ throw new Error("Field doesn't support isOdd");
838
+ return !t.isOdd(d);
839
+ }
840
+ /** Compare one point to another. */
841
+ equals(d) {
842
+ G(d);
843
+ const { X: u, Y: c, Z: g } = this, { X: m, Y: B, Z: p } = d, b = t.eql(t.mul(u, p), t.mul(m, g)), v = t.eql(t.mul(c, p), t.mul(B, g));
844
+ return b && v;
845
+ }
846
+ /** Flips point to one corresponding to (x, -y) in Affine coordinates. */
847
+ negate() {
848
+ return new q(this.X, t.neg(this.Y), this.Z);
849
+ }
850
+ // Renes-Costello-Batina exception-free doubling formula.
851
+ // There is 30% faster Jacobian formula, but it is not complete.
852
+ // https://eprint.iacr.org/2015/1060, algorithm 3
853
+ // Cost: 8M + 3S + 3*a + 2*b3 + 15add.
854
+ double() {
855
+ const { a: d, b: u } = i, c = t.mul(u, dt), { X: g, Y: m, Z: B } = this;
856
+ let p = t.ZERO, b = t.ZERO, v = t.ZERO, S = t.mul(g, g), V = t.mul(m, m), A = t.mul(B, B), N = t.mul(g, m);
857
+ return N = t.add(N, N), v = t.mul(g, B), v = t.add(v, v), p = t.mul(d, v), b = t.mul(c, A), b = t.add(p, b), p = t.sub(V, b), b = t.add(V, b), b = t.mul(p, b), p = t.mul(N, p), v = t.mul(c, v), A = t.mul(d, A), N = t.sub(S, A), N = t.mul(d, N), N = t.add(N, v), v = t.add(S, S), S = t.add(v, S), S = t.add(S, A), S = t.mul(S, N), b = t.add(b, S), A = t.mul(m, B), A = t.add(A, A), S = t.mul(A, N), p = t.sub(p, S), v = t.mul(A, V), v = t.add(v, v), v = t.add(v, v), new q(p, b, v);
858
+ }
859
+ // Renes-Costello-Batina exception-free addition formula.
860
+ // There is 30% faster Jacobian formula, but it is not complete.
861
+ // https://eprint.iacr.org/2015/1060, algorithm 1
862
+ // Cost: 12M + 0S + 3*a + 3*b3 + 23add.
863
+ add(d) {
864
+ G(d);
865
+ const { X: u, Y: c, Z: g } = this, { X: m, Y: B, Z: p } = d;
866
+ let b = t.ZERO, v = t.ZERO, S = t.ZERO;
867
+ const V = i.a, A = t.mul(i.b, dt);
868
+ let N = t.mul(u, m), _ = t.mul(c, B), $ = t.mul(g, p), K = t.add(u, c), Z = t.add(m, B);
869
+ K = t.mul(K, Z), Z = t.add(N, _), K = t.sub(K, Z), Z = t.add(u, g);
870
+ let Y = t.add(m, p);
871
+ return Z = t.mul(Z, Y), Y = t.add(N, $), Z = t.sub(Z, Y), Y = t.add(c, g), b = t.add(B, p), Y = t.mul(Y, b), b = t.add(_, $), Y = t.sub(Y, b), S = t.mul(V, Z), b = t.mul(A, $), S = t.add(b, S), b = t.sub(_, S), S = t.add(_, S), v = t.mul(b, S), _ = t.add(N, N), _ = t.add(_, N), $ = t.mul(V, $), Z = t.mul(A, Z), _ = t.add(_, $), $ = t.sub(N, $), $ = t.mul(V, $), Z = t.add(Z, $), N = t.mul(_, Z), v = t.add(v, N), N = t.mul(Y, Z), b = t.mul(K, b), b = t.sub(b, N), N = t.mul(K, _), S = t.mul(Y, S), S = t.add(S, N), new q(b, v, S);
872
+ }
873
+ subtract(d) {
874
+ return this.add(d.negate());
875
+ }
876
+ is0() {
877
+ return this.equals(q.ZERO);
878
+ }
879
+ /**
880
+ * Constant time multiplication.
881
+ * Uses wNAF method. Windowed method may be 10% faster,
882
+ * but takes 2x longer to generate and consumes 2x memory.
883
+ * Uses precomputes when available.
884
+ * Uses endomorphism for Koblitz curves.
885
+ * @param scalar by which the point would be multiplied
886
+ * @returns New point
887
+ */
888
+ multiply(d) {
889
+ const { endo: u } = n;
890
+ if (!o.isValidNot0(d))
891
+ throw new Error("invalid scalar: out of range");
892
+ let c, g;
893
+ const m = (B) => F.cached(this, B, (p) => bt(q, p));
894
+ if (u) {
895
+ const { k1neg: B, k1: p, k2neg: b, k2: v } = X(d), { p: S, f: V } = m(p), { p: A, f: N } = m(v);
896
+ g = V.add(N), c = tt(u.beta, S, A, B, b);
897
+ } else {
898
+ const { p: B, f: p } = m(d);
899
+ c = B, g = p;
900
+ }
901
+ return bt(q, [c, g])[0];
902
+ }
903
+ /**
904
+ * Non-constant-time multiplication. Uses double-and-add algorithm.
905
+ * It's faster, but should only be used when you don't care about
906
+ * an exposed secret key e.g. sig verification, which works over *public* keys.
907
+ */
908
+ multiplyUnsafe(d) {
909
+ const { endo: u } = n, c = this;
910
+ if (!o.isValid(d))
911
+ throw new Error("invalid scalar: out of range");
912
+ if (d === H || c.is0())
913
+ return q.ZERO;
914
+ if (d === rt)
915
+ return c;
916
+ if (F.hasCache(this))
917
+ return this.multiply(d);
918
+ if (u) {
919
+ const { k1neg: g, k1: m, k2neg: B, k2: p } = X(d), { p1: b, p2: v } = Oe(q, c, m, p);
920
+ return tt(u.beta, b, v, g, B);
921
+ } else
922
+ return F.unsafe(c, d);
923
+ }
924
+ multiplyAndAddUnsafe(d, u, c) {
925
+ const g = this.multiplyUnsafe(u).add(d.multiplyUnsafe(c));
926
+ return g.is0() ? void 0 : g;
927
+ }
928
+ /**
929
+ * Converts Projective point to affine (x, y) coordinates.
930
+ * @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
931
+ */
932
+ toAffine(d) {
933
+ return J(this, d);
934
+ }
935
+ /**
936
+ * Checks whether Point is free of torsion elements (is in prime subgroup).
937
+ * Always torsion-free for cofactor=1 curves.
938
+ */
939
+ isTorsionFree() {
940
+ const { isTorsionFree: d } = n;
941
+ return s === rt ? !0 : d ? d(q, this) : F.unsafe(this, l).is0();
942
+ }
943
+ clearCofactor() {
944
+ const { clearCofactor: d } = n;
945
+ return s === rt ? this : d ? d(q, this) : this.multiplyUnsafe(s);
946
+ }
947
+ isSmallOrder() {
948
+ return this.multiplyUnsafe(s).is0();
949
+ }
950
+ toBytes(d = !0) {
951
+ return wt(d, "isCompressed"), this.assertValidity(), h(q, this, d);
952
+ }
953
+ toHex(d = !0) {
954
+ return nt(this.toBytes(d));
955
+ }
956
+ toString() {
957
+ return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
958
+ }
959
+ // TODO: remove
960
+ get px() {
961
+ return this.X;
962
+ }
963
+ get py() {
964
+ return this.X;
965
+ }
966
+ get pz() {
967
+ return this.Z;
968
+ }
969
+ toRawBytes(d = !0) {
970
+ return this.toBytes(d);
971
+ }
972
+ _setWindowSize(d) {
973
+ this.precompute(d);
974
+ }
975
+ static normalizeZ(d) {
976
+ return bt(q, d);
977
+ }
978
+ static msm(d, u) {
979
+ return Ae(q, o, d, u);
980
+ }
981
+ static fromPrivateKey(d) {
982
+ return q.BASE.multiply(et(o, d));
983
+ }
984
+ }
985
+ q.BASE = new q(i.Gx, i.Gy, t.ONE), q.ZERO = new q(t.ZERO, t.ONE, t.ZERO), q.Fp = t, q.Fn = o;
986
+ const ut = o.BITS, F = new Re(q, n.endo ? Math.ceil(ut / 2) : ut);
987
+ return q.BASE.precompute(8), q;
988
+ }
989
+ function ce(e) {
990
+ return Uint8Array.of(e ? 2 : 3);
991
+ }
992
+ function fe(e, n) {
993
+ return {
994
+ secretKey: n.BYTES,
995
+ publicKey: 1 + e.BYTES,
996
+ publicKeyUncompressed: 1 + 2 * e.BYTES,
997
+ publicKeyHasPrefix: !0,
998
+ signature: 2 * n.BYTES
999
+ };
1000
+ }
1001
+ function $e(e, n = {}) {
1002
+ const { Fn: r } = e, t = n.randomBytes || Ct, o = Object.assign(fe(e.Fp, r), { seed: re(r.ORDER) });
1003
+ function i(h) {
1004
+ try {
1005
+ return !!et(r, h);
1006
+ } catch {
1007
+ return !1;
1008
+ }
1009
+ }
1010
+ function s(h, E) {
1011
+ const { publicKey: x, publicKeyUncompressed: O } = o;
1012
+ try {
1013
+ const U = h.length;
1014
+ return E === !0 && U !== x || E === !1 && U !== O ? !1 : !!e.fromBytes(h);
1015
+ } catch {
1016
+ return !1;
1017
+ }
1018
+ }
1019
+ function l(h = t(o.seed)) {
1020
+ return Ie(W(h, o.seed, "seed"), r.ORDER);
1021
+ }
1022
+ function a(h, E = !0) {
1023
+ return e.BASE.multiply(et(r, h)).toBytes(E);
1024
+ }
1025
+ function w(h) {
1026
+ const E = l(h);
1027
+ return { secretKey: E, publicKey: a(E) };
1028
+ }
1029
+ function y(h) {
1030
+ if (typeof h == "bigint")
1031
+ return !1;
1032
+ if (h instanceof e)
1033
+ return !0;
1034
+ const { secretKey: E, publicKey: x, publicKeyUncompressed: O } = o;
1035
+ if (r.allowedLengths || E === x)
1036
+ return;
1037
+ const U = L("key", h).length;
1038
+ return U === x || U === O;
1039
+ }
1040
+ function I(h, E, x = !0) {
1041
+ if (y(h) === !0)
1042
+ throw new Error("first arg must be private key");
1043
+ if (y(E) === !1)
1044
+ throw new Error("second arg must be public key");
1045
+ const O = et(r, h);
1046
+ return e.fromHex(E).multiply(O).toBytes(x);
1047
+ }
1048
+ return Object.freeze({ getPublicKey: a, getSharedSecret: I, keygen: w, Point: e, utils: {
1049
+ isValidSecretKey: i,
1050
+ isValidPublicKey: s,
1051
+ randomSecretKey: l,
1052
+ // TODO: remove
1053
+ isValidPrivateKey: i,
1054
+ randomPrivateKey: l,
1055
+ normPrivateKeyToScalar: (h) => et(r, h),
1056
+ precompute(h = 8, E = e.BASE) {
1057
+ return E.precompute(h, !1);
1058
+ }
1059
+ }, lengths: o });
1060
+ }
1061
+ function Ye(e, n, r = {}) {
1062
+ le(n), Ot(r, {}, {
1063
+ hmac: "function",
1064
+ lowS: "boolean",
1065
+ randomBytes: "function",
1066
+ bits2int: "function",
1067
+ bits2int_modN: "function"
1068
+ });
1069
+ const t = r.randomBytes || Ct, o = r.hmac || ((u, ...c) => de(n, u, D(...c))), { Fp: i, Fn: s } = e, { ORDER: l, BITS: a } = s, { keygen: w, getPublicKey: y, getSharedSecret: I, utils: f, lengths: h } = $e(e, r), E = {
1070
+ prehash: !1,
1071
+ lowS: typeof r.lowS == "boolean" ? r.lowS : !1,
1072
+ format: void 0,
1073
+ //'compact' as ECDSASigFormat,
1074
+ extraEntropy: !1
1075
+ }, x = "compact";
1076
+ function O(u) {
1077
+ const c = l >> rt;
1078
+ return u > c;
1079
+ }
1080
+ function U(u, c) {
1081
+ if (!s.isValidNot0(c))
1082
+ throw new Error(`invalid signature ${u}: out of range 1..Point.Fn.ORDER`);
1083
+ return c;
1084
+ }
1085
+ function it(u, c) {
1086
+ St(c);
1087
+ const g = h.signature, m = c === "compact" ? g : c === "recovered" ? g + 1 : void 0;
1088
+ return W(u, m, `${c} signature`);
1089
+ }
1090
+ class T {
1091
+ constructor(c, g, m) {
1092
+ this.r = U("r", c), this.s = U("s", g), m != null && (this.recovery = m), Object.freeze(this);
1093
+ }
1094
+ static fromBytes(c, g = x) {
1095
+ it(c, g);
1096
+ let m;
1097
+ if (g === "der") {
1098
+ const { r: v, s: S } = z.toSig(W(c));
1099
+ return new T(v, S);
1100
+ }
1101
+ g === "recovered" && (m = c[0], g = "compact", c = c.subarray(1));
1102
+ const B = s.BYTES, p = c.subarray(0, B), b = c.subarray(B, B * 2);
1103
+ return new T(s.fromBytes(p), s.fromBytes(b), m);
1104
+ }
1105
+ static fromHex(c, g) {
1106
+ return this.fromBytes(ht(c), g);
1107
+ }
1108
+ addRecoveryBit(c) {
1109
+ return new T(this.r, this.s, c);
1110
+ }
1111
+ recoverPublicKey(c) {
1112
+ const g = i.ORDER, { r: m, s: B, recovery: p } = this;
1113
+ if (p == null || ![0, 1, 2, 3].includes(p))
1114
+ throw new Error("recovery id invalid");
1115
+ if (l * se < g && p > 1)
1116
+ throw new Error("recovery id is ambiguous for h>1 curve");
1117
+ const v = p === 2 || p === 3 ? m + l : m;
1118
+ if (!i.isValid(v))
1119
+ throw new Error("recovery id 2 or 3 invalid");
1120
+ const S = i.toBytes(v), V = e.fromBytes(D(ce((p & 1) === 0), S)), A = s.inv(v), N = X(L("msgHash", c)), _ = s.create(-N * A), $ = s.create(B * A), K = e.BASE.multiplyUnsafe(_).add(V.multiplyUnsafe($));
1121
+ if (K.is0())
1122
+ throw new Error("point at infinify");
1123
+ return K.assertValidity(), K;
1124
+ }
1125
+ // Signatures should be low-s, to prevent malleability.
1126
+ hasHighS() {
1127
+ return O(this.s);
1128
+ }
1129
+ toBytes(c = x) {
1130
+ if (St(c), c === "der")
1131
+ return ht(z.hexFromSig(this));
1132
+ const g = s.toBytes(this.r), m = s.toBytes(this.s);
1133
+ if (c === "recovered") {
1134
+ if (this.recovery == null)
1135
+ throw new Error("recovery bit must be present");
1136
+ return D(Uint8Array.of(this.recovery), g, m);
1137
+ }
1138
+ return D(g, m);
1139
+ }
1140
+ toHex(c) {
1141
+ return nt(this.toBytes(c));
1142
+ }
1143
+ // TODO: remove
1144
+ assertValidity() {
1145
+ }
1146
+ static fromCompact(c) {
1147
+ return T.fromBytes(L("sig", c), "compact");
1148
+ }
1149
+ static fromDER(c) {
1150
+ return T.fromBytes(L("sig", c), "der");
1151
+ }
1152
+ normalizeS() {
1153
+ return this.hasHighS() ? new T(this.r, s.neg(this.s), this.recovery) : this;
1154
+ }
1155
+ toDERRawBytes() {
1156
+ return this.toBytes("der");
1157
+ }
1158
+ toDERHex() {
1159
+ return nt(this.toBytes("der"));
1160
+ }
1161
+ toCompactRawBytes() {
1162
+ return this.toBytes("compact");
1163
+ }
1164
+ toCompactHex() {
1165
+ return nt(this.toBytes("compact"));
1166
+ }
1167
+ }
1168
+ const G = r.bits2int || function(c) {
1169
+ if (c.length > 8192)
1170
+ throw new Error("input is too large");
1171
+ const g = mt(c), m = c.length * 8 - a;
1172
+ return m > 0 ? g >> BigInt(m) : g;
1173
+ }, X = r.bits2int_modN || function(c) {
1174
+ return s.create(G(c));
1175
+ }, J = st(a);
1176
+ function ft(u) {
1177
+ return ge("num < 2^" + a, u, H, J), s.toBytes(u);
1178
+ }
1179
+ function tt(u, c) {
1180
+ return W(u, void 0, "message"), c ? W(n(u), void 0, "prehashed message") : u;
1181
+ }
1182
+ function q(u, c, g) {
1183
+ if (["recovered", "canonical"].some((_) => _ in g))
1184
+ throw new Error("sign() legacy options not supported");
1185
+ const { lowS: m, prehash: B, extraEntropy: p } = vt(g, E);
1186
+ u = tt(u, B);
1187
+ const b = X(u), v = et(s, c), S = [ft(v), ft(b)];
1188
+ if (p != null && p !== !1) {
1189
+ const _ = p === !0 ? t(h.secretKey) : p;
1190
+ S.push(L("extraEntropy", _));
1191
+ }
1192
+ const V = D(...S), A = b;
1193
+ function N(_) {
1194
+ const $ = G(_);
1195
+ if (!s.isValidNot0($))
1196
+ return;
1197
+ const K = s.inv($), Z = e.BASE.multiply($).toAffine(), Y = s.create(Z.x);
1198
+ if (Y === H)
1199
+ return;
1200
+ const at = s.create(K * s.create(A + Y * v));
1201
+ if (at === H)
1202
+ return;
1203
+ let Zt = (Z.x === Y ? 0 : 2) | Number(Z.y & rt), Ut = at;
1204
+ return m && O(at) && (Ut = s.neg(at), Zt ^= 1), new T(Y, Ut, Zt);
1205
+ }
1206
+ return { seed: V, k2sig: N };
1207
+ }
1208
+ function ut(u, c, g = {}) {
1209
+ u = L("message", u);
1210
+ const { seed: m, k2sig: B } = q(u, c, g);
1211
+ return me(n.outputLen, s.BYTES, o)(m, B);
1212
+ }
1213
+ function F(u) {
1214
+ let c;
1215
+ const g = typeof u == "string" || qt(u), m = !g && u !== null && typeof u == "object" && typeof u.r == "bigint" && typeof u.s == "bigint";
1216
+ if (!g && !m)
1217
+ throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
1218
+ if (m)
1219
+ c = new T(u.r, u.s);
1220
+ else if (g) {
1221
+ try {
1222
+ c = T.fromBytes(L("sig", u), "der");
1223
+ } catch (B) {
1224
+ if (!(B instanceof z.Err))
1225
+ throw B;
1226
+ }
1227
+ if (!c)
1228
+ try {
1229
+ c = T.fromBytes(L("sig", u), "compact");
1230
+ } catch {
1231
+ return !1;
1232
+ }
1233
+ }
1234
+ return c || !1;
1235
+ }
1236
+ function R(u, c, g, m = {}) {
1237
+ const { lowS: B, prehash: p, format: b } = vt(m, E);
1238
+ if (g = L("publicKey", g), c = tt(L("message", c), p), "strict" in m)
1239
+ throw new Error("options.strict was renamed to lowS");
1240
+ const v = b === void 0 ? F(u) : T.fromBytes(L("sig", u), b);
1241
+ if (v === !1)
1242
+ return !1;
1243
+ try {
1244
+ const S = e.fromBytes(g);
1245
+ if (B && v.hasHighS())
1246
+ return !1;
1247
+ const { r: V, s: A } = v, N = X(c), _ = s.inv(A), $ = s.create(N * _), K = s.create(V * _), Z = e.BASE.multiplyUnsafe($).add(S.multiplyUnsafe(K));
1248
+ return Z.is0() ? !1 : s.create(Z.x) === V;
1249
+ } catch {
1250
+ return !1;
1251
+ }
1252
+ }
1253
+ function d(u, c, g = {}) {
1254
+ const { prehash: m } = vt(g, E);
1255
+ return c = tt(c, m), T.fromBytes(u, "recovered").recoverPublicKey(c).toBytes();
1256
+ }
1257
+ return Object.freeze({
1258
+ keygen: w,
1259
+ getPublicKey: y,
1260
+ getSharedSecret: I,
1261
+ utils: f,
1262
+ lengths: h,
1263
+ Point: e,
1264
+ sign: ut,
1265
+ verify: R,
1266
+ recoverPublicKey: d,
1267
+ Signature: T,
1268
+ hash: n
1269
+ });
1270
+ }
1271
+ function je(e) {
1272
+ const n = {
1273
+ a: e.a,
1274
+ b: e.b,
1275
+ p: e.Fp.ORDER,
1276
+ n: e.n,
1277
+ h: e.h,
1278
+ Gx: e.Gx,
1279
+ Gy: e.Gy
1280
+ }, r = e.Fp;
1281
+ let t = e.allowedPrivateKeyLengths ? Array.from(new Set(e.allowedPrivateKeyLengths.map((s) => Math.ceil(s / 2)))) : void 0;
1282
+ const o = ct(n.n, {
1283
+ BITS: e.nBitLength,
1284
+ allowedLengths: t,
1285
+ modFromBytes: e.wrapPrivateKey
1286
+ }), i = {
1287
+ Fp: r,
1288
+ Fn: o,
1289
+ allowInfinityPoint: e.allowInfinityPoint,
1290
+ endo: e.endo,
1291
+ isTorsionFree: e.isTorsionFree,
1292
+ clearCofactor: e.clearCofactor,
1293
+ fromBytes: e.fromBytes,
1294
+ toBytes: e.toBytes
1295
+ };
1296
+ return { CURVE: n, curveOpts: i };
1297
+ }
1298
+ function Ke(e) {
1299
+ const { CURVE: n, curveOpts: r } = je(e), t = {
1300
+ hmac: e.hmac,
1301
+ randomBytes: e.randomBytes,
1302
+ lowS: e.lowS,
1303
+ bits2int: e.bits2int,
1304
+ bits2int_modN: e.bits2int_modN
1305
+ };
1306
+ return { CURVE: n, curveOpts: r, hash: e.hash, ecdsaOpts: t };
1307
+ }
1308
+ function Le(e, n) {
1309
+ const r = n.Point;
1310
+ return Object.assign({}, n, {
1311
+ ProjectivePoint: r,
1312
+ CURVE: Object.assign({}, e, ee(r.Fn.ORDER, r.Fn.BITS))
1313
+ });
1314
+ }
1315
+ function Me(e) {
1316
+ const { CURVE: n, curveOpts: r, hash: t, ecdsaOpts: o } = Ke(e), i = Ve(n, r), s = Ye(i, t, o);
1317
+ return Le(e, s);
1318
+ }
1319
+ function Ce(e, n) {
1320
+ const r = (t) => Me({ ...e, hash: t });
1321
+ return { ...r(n), create: r };
1322
+ }
1323
+ const _t = {
1324
+ p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
1325
+ n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
1326
+ h: BigInt(1),
1327
+ a: BigInt(0),
1328
+ b: BigInt(7),
1329
+ Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
1330
+ Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
1331
+ }, ke = {
1332
+ beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
1333
+ basises: [
1334
+ [BigInt("0x3086d221a7d46bcde86c90e49284eb15"), -BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],
1335
+ [BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), BigInt("0x3086d221a7d46bcde86c90e49284eb15")]
1336
+ ]
1337
+ }, Mt = /* @__PURE__ */ BigInt(2);
1338
+ function ze(e) {
1339
+ const n = _t.p, r = BigInt(3), t = BigInt(6), o = BigInt(11), i = BigInt(22), s = BigInt(23), l = BigInt(44), a = BigInt(88), w = e * e * e % n, y = w * w * e % n, I = C(y, r, n) * y % n, f = C(I, r, n) * y % n, h = C(f, Mt, n) * w % n, E = C(h, o, n) * h % n, x = C(E, i, n) * E % n, O = C(x, l, n) * x % n, U = C(O, a, n) * O % n, it = C(U, l, n) * x % n, T = C(it, r, n) * y % n, G = C(T, s, n) * E % n, X = C(G, t, n) * w % n, J = C(X, Mt, n);
1340
+ if (!It.eql(It.sqr(J), e))
1341
+ throw new Error("Cannot find square root");
1342
+ return J;
1343
+ }
1344
+ const It = ct(_t.p, { sqrt: ze }), Xe = Ce({ ..._t, Fp: It, lowS: !0, endo: ke }, he);
1345
+ export {
1346
+ Xe as secp256k1
1347
+ };