@oottoo-core/oottoo-ui 0.0.4 → 0.0.6

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