@smallwebco/tinypivot-vue 1.0.64 → 1.0.65

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