@cedros/login-react 0.0.38 → 0.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/dist/{AuthenticationSettings-pR8sUc8u.js → AuthenticationSettings-BF_7Ea6Z.js} +1 -1
  2. package/dist/{AuthenticationSettings-pR8sUc8u.js.map → AuthenticationSettings-BF_7Ea6Z.js.map} +1 -1
  3. package/dist/{AuthenticationSettings-CaNdnqL2.cjs → AuthenticationSettings-BMDrCVSf.cjs} +1 -1
  4. package/dist/{AuthenticationSettings-CaNdnqL2.cjs.map → AuthenticationSettings-BMDrCVSf.cjs.map} +1 -1
  5. package/dist/{AuthenticationSettings-BWfMzQ30.js → AuthenticationSettings-DUXpyiJ5.js} +21 -21
  6. package/dist/{AuthenticationSettings-BWfMzQ30.js.map → AuthenticationSettings-DUXpyiJ5.js.map} +1 -1
  7. package/dist/{AuthenticationSettings-REAsemKP.cjs → AuthenticationSettings-Dk1LX0CK.cjs} +1 -1
  8. package/dist/{AuthenticationSettings-REAsemKP.cjs.map → AuthenticationSettings-Dk1LX0CK.cjs.map} +1 -1
  9. package/dist/{AutosaveStatus-DNK2vjyX.cjs → AutosaveStatus-BKsCIvPj.cjs} +1 -1
  10. package/dist/AutosaveStatus-BKsCIvPj.cjs.map +1 -0
  11. package/dist/{AutosaveStatus-Bgts5i6l.js → AutosaveStatus-CSZsp6w7.js} +190 -166
  12. package/dist/AutosaveStatus-CSZsp6w7.js.map +1 -0
  13. package/dist/{CreditSystemSettings-CLKgkXHi.js → CreditSystemSettings-Buu7Y-7I.js} +1 -1
  14. package/dist/{CreditSystemSettings-CLKgkXHi.js.map → CreditSystemSettings-Buu7Y-7I.js.map} +1 -1
  15. package/dist/{CreditSystemSettings-OHes0bEe.cjs → CreditSystemSettings-C2HkyMXy.cjs} +1 -1
  16. package/dist/{CreditSystemSettings-OHes0bEe.cjs.map → CreditSystemSettings-C2HkyMXy.cjs.map} +1 -1
  17. package/dist/{CreditSystemSettings-BP-DMr-u.cjs → CreditSystemSettings-CLImarX-.cjs} +1 -1
  18. package/dist/{CreditSystemSettings-BP-DMr-u.cjs.map → CreditSystemSettings-CLImarX-.cjs.map} +1 -1
  19. package/dist/{CreditSystemSettings-DBo-z1ti.js → CreditSystemSettings-Cj21_Ug8.js} +1 -1
  20. package/dist/{CreditSystemSettings-DBo-z1ti.js.map → CreditSystemSettings-Cj21_Ug8.js.map} +1 -1
  21. package/dist/EmailRegisterForm-CNjYrqU6.cjs +1 -0
  22. package/dist/EmailRegisterForm-CNjYrqU6.cjs.map +1 -0
  23. package/dist/EmailRegisterForm-D2VaJouj.js +750 -0
  24. package/dist/EmailRegisterForm-D2VaJouj.js.map +1 -0
  25. package/dist/{EmailSettings-lrl43m3p.cjs → EmailSettings-9sdEAONl.cjs} +1 -1
  26. package/dist/{EmailSettings-lrl43m3p.cjs.map → EmailSettings-9sdEAONl.cjs.map} +1 -1
  27. package/dist/{EmailSettings-JKyF5uqz.js → EmailSettings-CmxxnrA9.js} +1 -1
  28. package/dist/{EmailSettings-JKyF5uqz.js.map → EmailSettings-CmxxnrA9.js.map} +1 -1
  29. package/dist/{EmailSettings-j1TW9Nph.js → EmailSettings-DRfOF0Sf.js} +1 -1
  30. package/dist/{EmailSettings-j1TW9Nph.js.map → EmailSettings-DRfOF0Sf.js.map} +1 -1
  31. package/dist/{EmailSettings-kqzTquHb.cjs → EmailSettings-eLlzzI5D.cjs} +1 -1
  32. package/dist/{EmailSettings-kqzTquHb.cjs.map → EmailSettings-eLlzzI5D.cjs.map} +1 -1
  33. package/dist/{EmbeddedWalletSettings-tg6BTW4F.cjs → EmbeddedWalletSettings-BuLN_Uqc.cjs} +1 -1
  34. package/dist/{EmbeddedWalletSettings-tg6BTW4F.cjs.map → EmbeddedWalletSettings-BuLN_Uqc.cjs.map} +1 -1
  35. package/dist/{EmbeddedWalletSettings-_45K-0PV.js → EmbeddedWalletSettings-CHkkCjyR.js} +1 -1
  36. package/dist/{EmbeddedWalletSettings-_45K-0PV.js.map → EmbeddedWalletSettings-CHkkCjyR.js.map} +1 -1
  37. package/dist/EmbeddedWalletSettings-DGq-kXbw.cjs +1 -0
  38. package/dist/EmbeddedWalletSettings-DGq-kXbw.cjs.map +1 -0
  39. package/dist/{EmbeddedWalletSettings-Bln1PHH4.js → EmbeddedWalletSettings-M-D5N0eY.js} +5 -5
  40. package/dist/EmbeddedWalletSettings-M-D5N0eY.js.map +1 -0
  41. package/dist/{ServerSettings-DBc7opXq.cjs → ServerSettings-CMmH5pZv.cjs} +1 -1
  42. package/dist/{ServerSettings-DBc7opXq.cjs.map → ServerSettings-CMmH5pZv.cjs.map} +1 -1
  43. package/dist/{ServerSettings-BGI3YP_z.js → ServerSettings-DQemMrNv.js} +1 -1
  44. package/dist/{ServerSettings-BGI3YP_z.js.map → ServerSettings-DQemMrNv.js.map} +1 -1
  45. package/dist/{ServerSettings-etuaUiXh.cjs → ServerSettings-DfimU7ay.cjs} +1 -1
  46. package/dist/{ServerSettings-etuaUiXh.cjs.map → ServerSettings-DfimU7ay.cjs.map} +1 -1
  47. package/dist/{ServerSettings-D2sqqBMZ.js → ServerSettings-qxi8aZO7.js} +1 -1
  48. package/dist/{ServerSettings-D2sqqBMZ.js.map → ServerSettings-qxi8aZO7.js.map} +1 -1
  49. package/dist/{WebhookSettings-CD8gptC3.cjs → WebhookSettings-0sgWRI3U.cjs} +1 -1
  50. package/dist/{WebhookSettings-CD8gptC3.cjs.map → WebhookSettings-0sgWRI3U.cjs.map} +1 -1
  51. package/dist/{WebhookSettings-CHe_D4Bd.js → WebhookSettings-8QAqvkkO.js} +1 -1
  52. package/dist/{WebhookSettings-CHe_D4Bd.js.map → WebhookSettings-8QAqvkkO.js.map} +1 -1
  53. package/dist/{WebhookSettings-BHgVRCin.cjs → WebhookSettings-B6Y3Tnjv.cjs} +1 -1
  54. package/dist/{WebhookSettings-BHgVRCin.cjs.map → WebhookSettings-B6Y3Tnjv.cjs.map} +1 -1
  55. package/dist/{WebhookSettings-B0_D5YIz.js → WebhookSettings-B8hAwhZ2.js} +1 -1
  56. package/dist/{WebhookSettings-B0_D5YIz.js.map → WebhookSettings-B8hAwhZ2.js.map} +1 -1
  57. package/dist/admin-only.cjs +1 -1
  58. package/dist/admin-only.js +1 -1
  59. package/dist/email-only.cjs +1 -1
  60. package/dist/email-only.d.ts +2 -2
  61. package/dist/email-only.js +2 -2
  62. package/dist/google-only.cjs +1 -1
  63. package/dist/google-only.d.ts +2 -2
  64. package/dist/google-only.js +1 -1
  65. package/dist/index.cjs +13 -13
  66. package/dist/index.cjs.map +1 -1
  67. package/dist/index.d.ts +34 -9
  68. package/dist/index.js +7884 -5957
  69. package/dist/index.js.map +1 -1
  70. package/dist/{plugin-DTP_0JDr.cjs → plugin-CUxpAjL-.cjs} +1 -1
  71. package/dist/{plugin-DTP_0JDr.cjs.map → plugin-CUxpAjL-.cjs.map} +1 -1
  72. package/dist/{plugin-DD07LDez.js → plugin-C_NDZ2-D.js} +5 -5
  73. package/dist/{plugin-DD07LDez.js.map → plugin-C_NDZ2-D.js.map} +1 -1
  74. package/dist/solana-only.cjs +1 -1
  75. package/dist/solana-only.d.ts +2 -2
  76. package/dist/solana-only.js +1 -1
  77. package/dist/{useAuth-CWBApIWg.js → useAuth-C-Vw-ggy.js} +743 -803
  78. package/dist/useAuth-C-Vw-ggy.js.map +1 -0
  79. package/dist/useAuth-U5CYsHEU.cjs +1 -0
  80. package/dist/useAuth-U5CYsHEU.cjs.map +1 -0
  81. package/package.json +4 -1
  82. package/dist/AutosaveStatus-Bgts5i6l.js.map +0 -1
  83. package/dist/AutosaveStatus-DNK2vjyX.cjs.map +0 -1
  84. package/dist/EmailRegisterForm-BiisUR7P.js +0 -773
  85. package/dist/EmailRegisterForm-BiisUR7P.js.map +0 -1
  86. package/dist/EmailRegisterForm-CBzHZxvg.cjs +0 -1
  87. package/dist/EmailRegisterForm-CBzHZxvg.cjs.map +0 -1
  88. package/dist/EmbeddedWalletSettings-1ERxP6--.cjs +0 -1
  89. package/dist/EmbeddedWalletSettings-1ERxP6--.cjs.map +0 -1
  90. package/dist/EmbeddedWalletSettings-Bln1PHH4.js.map +0 -1
  91. package/dist/shamir-BNuiZ2ry.cjs +0 -1
  92. package/dist/shamir-BNuiZ2ry.cjs.map +0 -1
  93. package/dist/shamir-BbDh58Zo.js +0 -1940
  94. package/dist/shamir-BbDh58Zo.js.map +0 -1
  95. package/dist/silentWalletEnroll-B6a-fPgB.cjs +0 -1
  96. package/dist/silentWalletEnroll-B6a-fPgB.cjs.map +0 -1
  97. package/dist/silentWalletEnroll-KHso2-HB.js +0 -41
  98. package/dist/silentWalletEnroll-KHso2-HB.js.map +0 -1
  99. package/dist/useAuth-CWBApIWg.js.map +0 -1
  100. package/dist/useAuth-GzGopI4v.cjs +0 -1
  101. package/dist/useAuth-GzGopI4v.cjs.map +0 -1
@@ -1,1940 +0,0 @@
1
- import { D as Be, v as ve, d as Se, e as ee, f as ht, h as Ae } from "./useAuth-CWBApIWg.js";
2
- let P = null, Re = 0;
3
- const et = /* @__PURE__ */ new Map();
4
- function Ie() {
5
- return typeof Worker > "u" ? null : (P || (P = new Worker(new URL(
6
- /* @vite-ignore */
7
- "" + new URL("assets/argon2Worker-Bi5TuQvD.js", import.meta.url).href,
8
- import.meta.url
9
- ), {
10
- type: "module"
11
- }), P.onmessage = (e) => {
12
- const { id: t, key: n, error: o } = e.data, r = et.get(t);
13
- if (r) {
14
- if (et.delete(t), o) {
15
- r.reject(new Error(o));
16
- return;
17
- }
18
- if (!n) {
19
- r.reject(new Error("Argon2 worker returned no key"));
20
- return;
21
- }
22
- r.resolve(n);
23
- }
24
- }, P.onerror = (e) => {
25
- const t = e instanceof ErrorEvent ? e.error : new Error("Argon2 worker error");
26
- for (const n of et.values())
27
- n.reject(t instanceof Error ? t : new Error(String(t)));
28
- et.clear(), P?.terminate(), P = null;
29
- }), P);
30
- }
31
- async function sr(e, t, n = Be) {
32
- ve(n);
33
- const o = Ie();
34
- return o ? new Promise((r, s) => {
35
- const c = Re++;
36
- et.set(c, { resolve: r, reject: s });
37
- const u = {
38
- id: c,
39
- password: e,
40
- salt: t,
41
- params: n
42
- };
43
- o.postMessage(u);
44
- }) : Se(e, t, n);
45
- }
46
- function _e(e) {
47
- return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
48
- }
49
- function Ne(e) {
50
- if (Object.prototype.hasOwnProperty.call(e, "__esModule")) return e;
51
- var t = e.default;
52
- if (typeof t == "function") {
53
- var n = function o() {
54
- var r = !1;
55
- try {
56
- r = this instanceof o;
57
- } catch {
58
- }
59
- return r ? Reflect.construct(t, arguments, this.constructor) : t.apply(this, arguments);
60
- };
61
- n.prototype = t.prototype;
62
- } else n = {};
63
- return Object.defineProperty(n, "__esModule", { value: !0 }), Object.keys(e).forEach(function(o) {
64
- var r = Object.getOwnPropertyDescriptor(e, o);
65
- Object.defineProperty(n, o, r.get ? r : {
66
- enumerable: !0,
67
- get: function() {
68
- return e[o];
69
- }
70
- });
71
- }), n;
72
- }
73
- var it = { exports: {} };
74
- const Oe = globalThis.crypto, Te = globalThis.crypto, Ce = globalThis.crypto.subtle, Le = globalThis.crypto.getRandomValues.bind(globalThis.crypto), He = globalThis.crypto.randomUUID.bind(globalThis.crypto), Ue = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
75
- __proto__: null,
76
- default: Oe,
77
- getRandomValues: Le,
78
- randomUUID: He,
79
- subtle: Ce,
80
- webcrypto: Te
81
- }, Symbol.toStringTag, { value: "Module" })), De = /* @__PURE__ */ Ne(Ue);
82
- var qe = it.exports, Ut;
83
- function Me() {
84
- return Ut || (Ut = 1, (function(e, t) {
85
- (function(n, o) {
86
- e.exports = o(De);
87
- })(qe, function(n) {
88
- var o, r, s, c, u;
89
- function i() {
90
- o = {
91
- bits: 8,
92
- // default number of bits
93
- radix: 16,
94
- // work with HEX by default
95
- minBits: 3,
96
- maxBits: 20,
97
- // this permits 1,048,575 shares, though going this high is NOT recommended in JS!
98
- bytesPerChar: 2,
99
- maxBytesPerChar: 6,
100
- // Math.pow(256,7) > Math.pow(2,53)
101
- // Primitive polynomials (in decimal form) for Galois Fields GF(2^n), for 2 <= n <= 30
102
- // The index of each term in the array corresponds to the n for that polynomial
103
- // i.e. to get the polynomial for n=16, use primitivePolynomials[16]
104
- primitivePolynomials: [
105
- null,
106
- null,
107
- 1,
108
- 3,
109
- 3,
110
- 5,
111
- 3,
112
- 3,
113
- 29,
114
- 17,
115
- 9,
116
- 5,
117
- 83,
118
- 27,
119
- 43,
120
- 3,
121
- 45,
122
- 9,
123
- 39,
124
- 39,
125
- 9,
126
- 5,
127
- 3,
128
- 33,
129
- 27,
130
- 9,
131
- 71,
132
- 39,
133
- 9,
134
- 5,
135
- 83
136
- ]
137
- }, r = {}, s = new Array(1024).join("0"), c = !0, u = [
138
- "nodeCryptoRandomBytes",
139
- "browserCryptoGetRandomValues",
140
- "testRandom"
141
- ];
142
- }
143
- function x() {
144
- return !!(r && r.rng && typeof r.rng == "function");
145
- }
146
- function m(a, h) {
147
- var f;
148
- if (h === 0 || h === 1)
149
- return a;
150
- if (h && h > 1024)
151
- throw new Error(
152
- "Padding must be multiples of no larger than 1024 bits."
153
- );
154
- return h = h || r.bits, a && (f = a.length % h), f ? (s + a).slice(
155
- -(h - f + a.length)
156
- ) : a;
157
- }
158
- function w(a) {
159
- var h = "", f, l;
160
- for (l = a.length - 1; l >= 0; l--) {
161
- if (f = parseInt(a[l], 16), isNaN(f))
162
- throw new Error("Invalid hex character.");
163
- h = m(f.toString(2), 4) + h;
164
- }
165
- return h;
166
- }
167
- function v(a) {
168
- var h = "", f, l;
169
- for (a = m(a, 4), l = a.length; l >= 4; l -= 4) {
170
- if (f = parseInt(a.slice(l - 4, l), 2), isNaN(f))
171
- throw new Error("Invalid binary character.");
172
- h = f.toString(16) + h;
173
- }
174
- return h;
175
- }
176
- function I() {
177
- return !!(n && typeof n == "object" && (typeof n.getRandomValues == "function" || typeof n.getRandomValues == "object") && (typeof Uint32Array == "function" || typeof Uint32Array == "object"));
178
- }
179
- function S() {
180
- return typeof n == "object" && typeof n.randomBytes == "function";
181
- }
182
- function O(a) {
183
- function h(b, g, y, B) {
184
- var R = 0, C, L = "", q;
185
- for (g && (C = g.length - 1); R < C || L.length < b; )
186
- q = Math.abs(parseInt(g[R], y)), L = L + m(q.toString(2), B), R++;
187
- return L = L.substr(-b), (L.match(/0/g) || []).length === L.length ? null : L;
188
- }
189
- function f(b) {
190
- var g, y, B, R, C = null;
191
- for (B = 16, R = 4, y = Math.ceil(b / 8); C === null; )
192
- g = n.randomBytes(y), C = h(b, g.toString("hex"), B, R);
193
- return C;
194
- }
195
- function l(b) {
196
- var g, y, B, R = null;
197
- for (y = 10, B = 32, g = Math.ceil(b / 32); R === null; )
198
- R = h(
199
- b,
200
- n.getRandomValues(new Uint32Array(g)),
201
- y,
202
- B
203
- );
204
- return R;
205
- }
206
- function d(b) {
207
- var g, y, B, R, C, L = null;
208
- R = 10, C = 32, y = Math.ceil(b / 32), B = 123456789, g = new Uint32Array(y);
209
- for (var q = 0; q < g.length; q++)
210
- g[q] = B;
211
- for (; L === null; )
212
- L = h(b, g, R, C);
213
- return L;
214
- }
215
- if (a && a === "testRandom")
216
- return r.typeCSPRNG = a, d;
217
- if (a && a === "nodeCryptoRandomBytes")
218
- return r.typeCSPRNG = a, f;
219
- if (a && a === "browserCryptoGetRandomValues")
220
- return r.typeCSPRNG = a, l;
221
- if (S())
222
- return r.typeCSPRNG = "nodeCryptoRandomBytes", f;
223
- if (I())
224
- return r.typeCSPRNG = "browserCryptoGetRandomValues", l;
225
- }
226
- function _(a, h) {
227
- var f = [], l;
228
- for (h && (a = m(a, h)), l = a.length; l > r.bits; l -= r.bits)
229
- f.push(parseInt(a.slice(l - r.bits, l), 2));
230
- return f.push(parseInt(a.slice(0, l), 2)), f;
231
- }
232
- function E(a, h) {
233
- var f = r.logs[a], l = 0, d;
234
- for (d = h.length - 1; d >= 0; d--)
235
- l !== 0 ? l = r.exps[(f + r.logs[l]) % r.maxShares] ^ h[d] : l = h[d];
236
- return l;
237
- }
238
- function A(a, h, f) {
239
- var l = 0, d, b, g, y;
240
- for (g = 0, d = h.length; g < d; g++)
241
- if (f[g]) {
242
- for (b = r.logs[f[g]], y = 0; y < d; y++)
243
- if (g !== y) {
244
- if (a === h[y]) {
245
- b = -1;
246
- break;
247
- }
248
- b = (b + r.logs[a ^ h[y]] - r.logs[h[g] ^ h[y]] + r.maxShares) % r.maxShares;
249
- }
250
- l = b === -1 ? l : l ^ r.exps[b];
251
- }
252
- return l;
253
- }
254
- function p(a, h, f) {
255
- var l = [], d = [a], b, g;
256
- for (b = 1; b < f; b++)
257
- d[b] = parseInt(r.rng(r.bits), 2);
258
- for (b = 1, g = h + 1; b < g; b++)
259
- l[b - 1] = {
260
- x: b,
261
- y: E(b, d)
262
- };
263
- return l;
264
- }
265
- function N(a, h, f) {
266
- var l, d, b, g, y;
267
- if (h = parseInt(h, r.radix), a = parseInt(a, 10) || r.bits, l = a.toString(36).toUpperCase(), b = Math.pow(2, a) - 1, g = b.toString(r.radix).length, d = m(h.toString(r.radix), g), typeof h != "number" || h % 1 !== 0 || h < 1 || h > b)
268
- throw new Error(
269
- "Share id must be an integer between 1 and " + b + ", inclusive."
270
- );
271
- return y = l + d + f, y;
272
- }
273
- var T = {
274
- init: function(a, h) {
275
- var f = [], l = [], d = 1, b, g;
276
- if (i(), a && (typeof a != "number" || a % 1 !== 0 || a < o.minBits || a > o.maxBits))
277
- throw new Error(
278
- "Number of bits must be an integer between " + o.minBits + " and " + o.maxBits + ", inclusive."
279
- );
280
- if (h && u.indexOf(h) === -1)
281
- throw new Error("Invalid RNG type argument : '" + h + "'");
282
- for (r.radix = o.radix, r.bits = a || o.bits, r.size = Math.pow(2, r.bits), r.maxShares = r.size - 1, b = o.primitivePolynomials[r.bits], g = 0; g < r.size; g++)
283
- l[g] = d, f[d] = g, d = d << 1, d >= r.size && (d = d ^ b, d = d & r.maxShares);
284
- if (r.logs = f, r.exps = l, h && this.setRNG(h), x() || this.setRNG(), !x() || !r.bits || !r.size || !r.maxShares || !r.logs || !r.exps || r.logs.length !== r.size || r.exps.length !== r.size)
285
- throw new Error("Initialization failed.");
286
- },
287
- // Evaluates the Lagrange interpolation polynomial at x=`at` for
288
- // individual config.bits-length segments of each share in the `shares`
289
- // Array. Each share is expressed in base `inputRadix`. The output
290
- // is expressed in base `outputRadix'.
291
- combine: function(a, h) {
292
- var f, l, d, b, g = "", y, B, R, C = [], L = [];
293
- for (h = h || 0, f = 0, d = a.length; f < d; f++) {
294
- if (B = this.extractShareComponents(a[f]), y === void 0)
295
- y = B.bits;
296
- else if (B.bits !== y)
297
- throw new Error(
298
- "Mismatched shares: Different bit settings."
299
- );
300
- if (r.bits !== y && this.init(y), C.indexOf(B.id) === -1)
301
- for (C.push(B.id), R = _(w(B.data)), l = 0, b = R.length; l < b; l++)
302
- L[l] = L[l] || [], L[l][C.length - 1] = R[l];
303
- }
304
- for (f = 0, d = L.length; f < d; f++)
305
- g = m(A(h, C, L[f]).toString(2)) + g;
306
- return v(
307
- h >= 1 ? g : g.slice(g.indexOf("1") + 1)
308
- );
309
- },
310
- getConfig: function() {
311
- var a = {};
312
- return a.radix = r.radix, a.bits = r.bits, a.maxShares = r.maxShares, a.hasCSPRNG = x(), a.typeCSPRNG = r.typeCSPRNG, a;
313
- },
314
- // Given a public share, extract the bits (Integer), share ID (Integer), and share data (Hex)
315
- // and return an Object containing those components.
316
- extractShareComponents: function(a) {
317
- var h, f, l, d, b = {}, g, y;
318
- if (h = parseInt(a.substr(0, 1), 36), h && (typeof h != "number" || h % 1 !== 0 || h < o.minBits || h > o.maxBits))
319
- throw new Error(
320
- "Invalid share : Number of bits must be an integer between " + o.minBits + " and " + o.maxBits + ", inclusive."
321
- );
322
- if (d = Math.pow(2, h) - 1, l = (Math.pow(2, h) - 1).toString(r.radix).length, g = "^([a-kA-K3-9]{1})([a-fA-F0-9]{" + l + "})([a-fA-F0-9]+)$", y = new RegExp(g).exec(a), y && (f = parseInt(y[2], r.radix)), typeof f != "number" || f % 1 !== 0 || f < 1 || f > d)
323
- throw new Error(
324
- "Invalid share : Share id must be an integer between 1 and " + r.maxShares + ", inclusive."
325
- );
326
- if (y && y[3])
327
- return b.bits = h, b.id = f, b.data = y[3], b;
328
- throw new Error("The share data provided is invalid : " + a);
329
- },
330
- // Set the PRNG to use. If no RNG function is supplied, pick a default using getRNG()
331
- setRNG: function(a) {
332
- var h = "Random number generator is invalid ", f = " Supply an CSPRNG of the form function(bits){} that returns a string containing 'bits' number of random 1's and 0's.";
333
- if (a && typeof a == "string" && u.indexOf(a) === -1)
334
- throw new Error("Invalid RNG type argument : '" + a + "'");
335
- if (a || (a = O()), a && typeof a == "string" && (a = O(a)), c) {
336
- if (a && typeof a != "function")
337
- throw new Error(h + "(Not a function)." + f);
338
- if (a && typeof a(r.bits) != "string")
339
- throw new Error(
340
- h + "(Output is not a string)." + f
341
- );
342
- if (a && !parseInt(a(r.bits), 2))
343
- throw new Error(
344
- h + "(Binary string output not parseable to an Integer)." + f
345
- );
346
- if (a && a(r.bits).length > r.bits)
347
- throw new Error(
348
- h + "(Output length is greater than config.bits)." + f
349
- );
350
- if (a && a(r.bits).length < r.bits)
351
- throw new Error(
352
- h + "(Output length is less than config.bits)." + f
353
- );
354
- }
355
- return r.rng = a, !0;
356
- },
357
- // Converts a given UTF16 character string to the HEX representation.
358
- // Each character of the input string is represented by
359
- // `bytesPerChar` bytes in the output string which defaults to 2.
360
- str2hex: function(a, h) {
361
- var f, l, d = "", b, g, y, B;
362
- if (typeof a != "string")
363
- throw new Error("Input must be a character string.");
364
- if (h || (h = o.bytesPerChar), typeof h != "number" || h < 1 || h > o.maxBytesPerChar || h % 1 !== 0)
365
- throw new Error(
366
- "Bytes per character must be an integer between 1 and " + o.maxBytesPerChar + ", inclusive."
367
- );
368
- for (f = 2 * h, l = Math.pow(16, f) - 1, y = 0, B = a.length; y < B; y++) {
369
- if (g = a[y].charCodeAt(), isNaN(g))
370
- throw new Error("Invalid character: " + a[y]);
371
- if (g > l)
372
- throw b = Math.ceil(Math.log(g + 1) / Math.log(256)), new Error(
373
- "Invalid character code (" + g + "). Maximum allowable is 256^bytes-1 (" + l + "). To convert this character, use at least " + b + " bytes."
374
- );
375
- d = m(g.toString(16), f) + d;
376
- }
377
- return d;
378
- },
379
- // Converts a given HEX number string to a UTF16 character string.
380
- hex2str: function(a, h) {
381
- var f, l = "", d, b;
382
- if (typeof a != "string")
383
- throw new Error("Input must be a hexadecimal string.");
384
- if (h = h || o.bytesPerChar, typeof h != "number" || h % 1 !== 0 || h < 1 || h > o.maxBytesPerChar)
385
- throw new Error(
386
- "Bytes per character must be an integer between 1 and " + o.maxBytesPerChar + ", inclusive."
387
- );
388
- for (f = 2 * h, a = m(a, f), d = 0, b = a.length; d < b; d += f)
389
- l = String.fromCharCode(
390
- parseInt(a.slice(d, d + f), 16)
391
- ) + l;
392
- return l;
393
- },
394
- // Generates a random bits-length number string using the PRNG
395
- random: function(a) {
396
- if (typeof a != "number" || a % 1 !== 0 || a < 2 || a > 65536)
397
- throw new Error(
398
- "Number of bits must be an Integer between 1 and 65536."
399
- );
400
- return v(r.rng(a));
401
- },
402
- // Divides a `secret` number String str expressed in radix `inputRadix` (optional, default 16)
403
- // into `numShares` shares, each expressed in radix `outputRadix` (optional, default to `inputRadix`),
404
- // requiring `threshold` number of shares to reconstruct the secret.
405
- // Optionally, zero-pads the secret to a length that is a multiple of padLength before sharing.
406
- share: function(a, h, f, l) {
407
- var d, b, g = new Array(h), y = new Array(h), B, R, C;
408
- if (l = l || 128, typeof a != "string")
409
- throw new Error("Secret must be a string.");
410
- if (typeof h != "number" || h % 1 !== 0 || h < 2)
411
- throw new Error(
412
- "Number of shares must be an integer between 2 and 2^bits-1 (" + r.maxShares + "), inclusive."
413
- );
414
- if (h > r.maxShares)
415
- throw d = Math.ceil(Math.log(h + 1) / Math.LN2), new Error(
416
- "Number of shares must be an integer between 2 and 2^bits-1 (" + r.maxShares + "), inclusive. To create " + h + " shares, use at least " + d + " bits."
417
- );
418
- if (typeof f != "number" || f % 1 !== 0 || f < 2)
419
- throw new Error(
420
- "Threshold number of shares must be an integer between 2 and 2^bits-1 (" + r.maxShares + "), inclusive."
421
- );
422
- if (f > r.maxShares)
423
- throw d = Math.ceil(Math.log(f + 1) / Math.LN2), new Error(
424
- "Threshold number of shares must be an integer between 2 and 2^bits-1 (" + r.maxShares + "), inclusive. To use a threshold of " + f + ", use at least " + d + " bits."
425
- );
426
- if (f > h)
427
- throw new Error(
428
- "Threshold number of shares was " + f + " but must be less than or equal to the " + h + " shares specified as the total to generate."
429
- );
430
- if (typeof l != "number" || l % 1 !== 0 || l < 0 || l > 1024)
431
- throw new Error(
432
- "Zero-pad length must be an integer between 0 and 1024 inclusive."
433
- );
434
- for (a = "1" + w(a), a = _(a, l), B = 0, C = a.length; B < C; B++)
435
- for (b = p(a[B], h, f), R = 0; R < h; R++)
436
- g[R] = g[R] || b[R].x.toString(r.radix), y[R] = m(b[R].y.toString(2)) + (y[R] || "");
437
- for (B = 0; B < h; B++)
438
- g[B] = N(
439
- r.bits,
440
- g[B],
441
- v(y[B])
442
- );
443
- return g;
444
- },
445
- // Generate a new share with id `id` (a number between 1 and 2^bits-1)
446
- // `id` can be a Number or a String in the default radix (16)
447
- newShare: function(a, h) {
448
- var f, l;
449
- if (a && typeof a == "string" && (a = parseInt(a, r.radix)), l = a.toString(r.radix), a && l && h && h[0])
450
- return f = this.extractShareComponents(h[0]), N(
451
- f.bits,
452
- l,
453
- this.combine(h, a)
454
- );
455
- throw new Error(
456
- "Invalid 'id' or 'shares' Array argument to newShare()."
457
- );
458
- },
459
- /* test-code */
460
- // export private functions so they can be unit tested directly.
461
- _reset: i,
462
- _padLeft: m,
463
- _hex2bin: w,
464
- _bin2hex: v,
465
- _hasCryptoGetRandomValues: I,
466
- _hasCryptoRandomBytes: S,
467
- _getRNG: O,
468
- _isSetRNG: x,
469
- _splitNumStringToIntArray: _,
470
- _horner: E,
471
- _lagrange: A,
472
- _getShares: p,
473
- _constructPublicShareString: N
474
- /* end-test-code */
475
- };
476
- return T.init(), T;
477
- });
478
- })(it)), it.exports;
479
- }
480
- var Ge = Me();
481
- const ne = /* @__PURE__ */ _e(Ge);
482
- function re(e) {
483
- return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
484
- }
485
- function Rt(e, t = "") {
486
- if (!Number.isSafeInteger(e) || e < 0) {
487
- const n = t && `"${t}" `;
488
- throw new Error(`${n}expected integer >= 0, got ${e}`);
489
- }
490
- }
491
- function D(e, t, n = "") {
492
- const o = re(e), r = e?.length, s = t !== void 0;
493
- if (!o || s && r !== t) {
494
- const c = n && `"${n}" `, u = s ? ` of length ${t}` : "", i = o ? `length=${r}` : `type=${typeof e}`;
495
- throw new Error(c + "expected Uint8Array" + u + ", got " + i);
496
- }
497
- return e;
498
- }
499
- function Dt(e, t = !0) {
500
- if (e.destroyed)
501
- throw new Error("Hash instance has been destroyed");
502
- if (t && e.finished)
503
- throw new Error("Hash#digest() has already been called");
504
- }
505
- function $e(e, t) {
506
- D(e, void 0, "digestInto() output");
507
- const n = t.outputLen;
508
- if (e.length < n)
509
- throw new Error('"digestInto() output" expected to be of length >=' + n);
510
- }
511
- function mt(...e) {
512
- for (let t = 0; t < e.length; t++)
513
- e[t].fill(0);
514
- }
515
- function lt(e) {
516
- return new DataView(e.buffer, e.byteOffset, e.byteLength);
517
- }
518
- const oe = /* @ts-ignore */ typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", Ze = /* @__PURE__ */ Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
519
- function It(e) {
520
- if (D(e), oe)
521
- return e.toHex();
522
- let t = "";
523
- for (let n = 0; n < e.length; n++)
524
- t += Ze[e[n]];
525
- return t;
526
- }
527
- const V = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
528
- function qt(e) {
529
- if (e >= V._0 && e <= V._9)
530
- return e - V._0;
531
- if (e >= V.A && e <= V.F)
532
- return e - (V.A - 10);
533
- if (e >= V.a && e <= V.f)
534
- return e - (V.a - 10);
535
- }
536
- function se(e) {
537
- if (typeof e != "string")
538
- throw new Error("hex string expected, got " + typeof e);
539
- if (oe)
540
- return Uint8Array.fromHex(e);
541
- const t = e.length, n = t / 2;
542
- if (t % 2)
543
- throw new Error("hex string expected, got unpadded hex of length " + t);
544
- const o = new Uint8Array(n);
545
- for (let r = 0, s = 0; r < n; r++, s += 2) {
546
- const c = qt(e.charCodeAt(s)), u = qt(e.charCodeAt(s + 1));
547
- if (c === void 0 || u === void 0) {
548
- const i = e[s] + e[s + 1];
549
- throw new Error('hex string expected, got non-hex character "' + i + '" at index ' + s);
550
- }
551
- o[r] = c * 16 + u;
552
- }
553
- return o;
554
- }
555
- function Mt(...e) {
556
- let t = 0;
557
- for (let o = 0; o < e.length; o++) {
558
- const r = e[o];
559
- D(r), t += r.length;
560
- }
561
- const n = new Uint8Array(t);
562
- for (let o = 0, r = 0; o < e.length; o++) {
563
- const s = e[o];
564
- n.set(s, r), r += s.length;
565
- }
566
- return n;
567
- }
568
- function je(e, t = {}) {
569
- const n = (r, s) => e(s).update(r).digest(), o = e(void 0);
570
- return n.outputLen = o.outputLen, n.blockLen = o.blockLen, n.create = (r) => e(r), Object.assign(n, t), Object.freeze(n);
571
- }
572
- function Ve(e = 32) {
573
- const t = typeof globalThis == "object" ? globalThis.crypto : null;
574
- if (typeof t?.getRandomValues != "function")
575
- throw new Error("crypto.getRandomValues must be defined");
576
- return t.getRandomValues(new Uint8Array(e));
577
- }
578
- const ke = (e) => ({
579
- oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, e])
580
- });
581
- let Ke = class {
582
- blockLen;
583
- outputLen;
584
- padOffset;
585
- isLE;
586
- // For partial updates less than block size
587
- buffer;
588
- view;
589
- finished = !1;
590
- length = 0;
591
- pos = 0;
592
- destroyed = !1;
593
- constructor(t, n, o, r) {
594
- this.blockLen = t, this.outputLen = n, this.padOffset = o, this.isLE = r, this.buffer = new Uint8Array(t), this.view = lt(this.buffer);
595
- }
596
- update(t) {
597
- Dt(this), D(t);
598
- const { view: n, buffer: o, blockLen: r } = this, s = t.length;
599
- for (let c = 0; c < s; ) {
600
- const u = Math.min(r - this.pos, s - c);
601
- if (u === r) {
602
- const i = lt(t);
603
- for (; r <= s - c; c += r)
604
- this.process(i, c);
605
- continue;
606
- }
607
- o.set(t.subarray(c, c + u), this.pos), this.pos += u, c += u, this.pos === r && (this.process(n, 0), this.pos = 0);
608
- }
609
- return this.length += t.length, this.roundClean(), this;
610
- }
611
- digestInto(t) {
612
- Dt(this), $e(t, this), this.finished = !0;
613
- const { buffer: n, view: o, blockLen: r, isLE: s } = this;
614
- let { pos: c } = this;
615
- n[c++] = 128, mt(this.buffer.subarray(c)), this.padOffset > r - c && (this.process(o, 0), c = 0);
616
- for (let w = c; w < r; w++)
617
- n[w] = 0;
618
- o.setBigUint64(r - 8, BigInt(this.length * 8), s), this.process(o, 0);
619
- const u = lt(t), i = this.outputLen;
620
- if (i % 4)
621
- throw new Error("_sha2: outputLen must be aligned to 32bit");
622
- const x = i / 4, m = this.get();
623
- if (x > m.length)
624
- throw new Error("_sha2: outputLen bigger than state");
625
- for (let w = 0; w < x; w++)
626
- u.setUint32(4 * w, m[w], s);
627
- }
628
- digest() {
629
- const { buffer: t, outputLen: n } = this;
630
- this.digestInto(t);
631
- const o = t.slice(0, n);
632
- return this.destroy(), o;
633
- }
634
- _cloneInto(t) {
635
- t ||= new this.constructor(), t.set(...this.get());
636
- const { blockLen: n, buffer: o, length: r, finished: s, destroyed: c, pos: u } = this;
637
- return t.destroyed = c, t.finished = s, t.length = r, t.pos = u, r % n && t.buffer.set(o), t;
638
- }
639
- clone() {
640
- return this._cloneInto();
641
- }
642
- };
643
- const M = /* @__PURE__ */ Uint32Array.from([
644
- 1779033703,
645
- 4089235720,
646
- 3144134277,
647
- 2227873595,
648
- 1013904242,
649
- 4271175723,
650
- 2773480762,
651
- 1595750129,
652
- 1359893119,
653
- 2917565137,
654
- 2600822924,
655
- 725511199,
656
- 528734635,
657
- 4215389547,
658
- 1541459225,
659
- 327033209
660
- ]), rt = /* @__PURE__ */ BigInt(2 ** 32 - 1), Gt = /* @__PURE__ */ BigInt(32);
661
- function Ye(e, t = !1) {
662
- return t ? { h: Number(e & rt), l: Number(e >> Gt & rt) } : { h: Number(e >> Gt & rt) | 0, l: Number(e & rt) | 0 };
663
- }
664
- function ze(e, t = !1) {
665
- const n = e.length;
666
- let o = new Uint32Array(n), r = new Uint32Array(n);
667
- for (let s = 0; s < n; s++) {
668
- const { h: c, l: u } = Ye(e[s], t);
669
- [o[s], r[s]] = [c, u];
670
- }
671
- return [o, r];
672
- }
673
- const $t = (e, t, n) => e >>> n, Zt = (e, t, n) => e << 32 - n | t >>> n, J = (e, t, n) => e >>> n | t << 32 - n, tt = (e, t, n) => e << 32 - n | t >>> n, ot = (e, t, n) => e << 64 - n | t >>> n - 32, st = (e, t, n) => e >>> n - 32 | t << 64 - n;
674
- function k(e, t, n, o) {
675
- const r = (t >>> 0) + (o >>> 0);
676
- return { h: e + n + (r / 2 ** 32 | 0) | 0, l: r | 0 };
677
- }
678
- const Xe = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), We = (e, t, n, o) => t + n + o + (e / 2 ** 32 | 0) | 0, Pe = (e, t, n, o) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (o >>> 0), Fe = (e, t, n, o, r) => t + n + o + r + (e / 2 ** 32 | 0) | 0, Qe = (e, t, n, o, r) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (o >>> 0) + (r >>> 0), Je = (e, t, n, o, r, s) => t + n + o + r + s + (e / 2 ** 32 | 0) | 0, ie = ze([
679
- "0x428a2f98d728ae22",
680
- "0x7137449123ef65cd",
681
- "0xb5c0fbcfec4d3b2f",
682
- "0xe9b5dba58189dbbc",
683
- "0x3956c25bf348b538",
684
- "0x59f111f1b605d019",
685
- "0x923f82a4af194f9b",
686
- "0xab1c5ed5da6d8118",
687
- "0xd807aa98a3030242",
688
- "0x12835b0145706fbe",
689
- "0x243185be4ee4b28c",
690
- "0x550c7dc3d5ffb4e2",
691
- "0x72be5d74f27b896f",
692
- "0x80deb1fe3b1696b1",
693
- "0x9bdc06a725c71235",
694
- "0xc19bf174cf692694",
695
- "0xe49b69c19ef14ad2",
696
- "0xefbe4786384f25e3",
697
- "0x0fc19dc68b8cd5b5",
698
- "0x240ca1cc77ac9c65",
699
- "0x2de92c6f592b0275",
700
- "0x4a7484aa6ea6e483",
701
- "0x5cb0a9dcbd41fbd4",
702
- "0x76f988da831153b5",
703
- "0x983e5152ee66dfab",
704
- "0xa831c66d2db43210",
705
- "0xb00327c898fb213f",
706
- "0xbf597fc7beef0ee4",
707
- "0xc6e00bf33da88fc2",
708
- "0xd5a79147930aa725",
709
- "0x06ca6351e003826f",
710
- "0x142929670a0e6e70",
711
- "0x27b70a8546d22ffc",
712
- "0x2e1b21385c26c926",
713
- "0x4d2c6dfc5ac42aed",
714
- "0x53380d139d95b3df",
715
- "0x650a73548baf63de",
716
- "0x766a0abb3c77b2a8",
717
- "0x81c2c92e47edaee6",
718
- "0x92722c851482353b",
719
- "0xa2bfe8a14cf10364",
720
- "0xa81a664bbc423001",
721
- "0xc24b8b70d0f89791",
722
- "0xc76c51a30654be30",
723
- "0xd192e819d6ef5218",
724
- "0xd69906245565a910",
725
- "0xf40e35855771202a",
726
- "0x106aa07032bbd1b8",
727
- "0x19a4c116b8d2d0c8",
728
- "0x1e376c085141ab53",
729
- "0x2748774cdf8eeb99",
730
- "0x34b0bcb5e19b48a8",
731
- "0x391c0cb3c5c95a63",
732
- "0x4ed8aa4ae3418acb",
733
- "0x5b9cca4f7763e373",
734
- "0x682e6ff3d6b2b8a3",
735
- "0x748f82ee5defb2fc",
736
- "0x78a5636f43172f60",
737
- "0x84c87814a1f0ab72",
738
- "0x8cc702081a6439ec",
739
- "0x90befffa23631e28",
740
- "0xa4506cebde82bde9",
741
- "0xbef9a3f7b2c67915",
742
- "0xc67178f2e372532b",
743
- "0xca273eceea26619c",
744
- "0xd186b8c721c0c207",
745
- "0xeada7dd6cde0eb1e",
746
- "0xf57d4f7fee6ed178",
747
- "0x06f067aa72176fba",
748
- "0x0a637dc5a2c898a6",
749
- "0x113f9804bef90dae",
750
- "0x1b710b35131c471b",
751
- "0x28db77f523047d84",
752
- "0x32caab7b40c72493",
753
- "0x3c9ebe0a15c9bebc",
754
- "0x431d67c49c100d4c",
755
- "0x4cc5d4becb3e42b6",
756
- "0x597f299cfc657e2a",
757
- "0x5fcb6fab3ad6faec",
758
- "0x6c44198c4a475817"
759
- ].map((e) => BigInt(e))), tn = ie[0], en = ie[1], K = /* @__PURE__ */ new Uint32Array(80), Y = /* @__PURE__ */ new Uint32Array(80);
760
- class nn extends Ke {
761
- constructor(t) {
762
- super(128, t, 16, !1);
763
- }
764
- // prettier-ignore
765
- get() {
766
- const { Ah: t, Al: n, Bh: o, Bl: r, Ch: s, Cl: c, Dh: u, Dl: i, Eh: x, El: m, Fh: w, Fl: v, Gh: I, Gl: S, Hh: O, Hl: _ } = this;
767
- return [t, n, o, r, s, c, u, i, x, m, w, v, I, S, O, _];
768
- }
769
- // prettier-ignore
770
- set(t, n, o, r, s, c, u, i, x, m, w, v, I, S, O, _) {
771
- this.Ah = t | 0, this.Al = n | 0, this.Bh = o | 0, this.Bl = r | 0, this.Ch = s | 0, this.Cl = c | 0, this.Dh = u | 0, this.Dl = i | 0, this.Eh = x | 0, this.El = m | 0, this.Fh = w | 0, this.Fl = v | 0, this.Gh = I | 0, this.Gl = S | 0, this.Hh = O | 0, this.Hl = _ | 0;
772
- }
773
- process(t, n) {
774
- for (let p = 0; p < 16; p++, n += 4)
775
- K[p] = t.getUint32(n), Y[p] = t.getUint32(n += 4);
776
- for (let p = 16; p < 80; p++) {
777
- const N = K[p - 15] | 0, T = Y[p - 15] | 0, a = J(N, T, 1) ^ J(N, T, 8) ^ $t(N, T, 7), h = tt(N, T, 1) ^ tt(N, T, 8) ^ Zt(N, T, 7), f = K[p - 2] | 0, l = Y[p - 2] | 0, d = J(f, l, 19) ^ ot(f, l, 61) ^ $t(f, l, 6), b = tt(f, l, 19) ^ st(f, l, 61) ^ Zt(f, l, 6), g = Pe(h, b, Y[p - 7], Y[p - 16]), y = Fe(g, a, d, K[p - 7], K[p - 16]);
778
- K[p] = y | 0, Y[p] = g | 0;
779
- }
780
- let { Ah: o, Al: r, Bh: s, Bl: c, Ch: u, Cl: i, Dh: x, Dl: m, Eh: w, El: v, Fh: I, Fl: S, Gh: O, Gl: _, Hh: E, Hl: A } = this;
781
- for (let p = 0; p < 80; p++) {
782
- const N = J(w, v, 14) ^ J(w, v, 18) ^ ot(w, v, 41), T = tt(w, v, 14) ^ tt(w, v, 18) ^ st(w, v, 41), a = w & I ^ ~w & O, h = v & S ^ ~v & _, f = Qe(A, T, h, en[p], Y[p]), l = Je(f, E, N, a, tn[p], K[p]), d = f | 0, b = J(o, r, 28) ^ ot(o, r, 34) ^ ot(o, r, 39), g = tt(o, r, 28) ^ st(o, r, 34) ^ st(o, r, 39), y = o & s ^ o & u ^ s & u, B = r & c ^ r & i ^ c & i;
783
- E = O | 0, A = _ | 0, O = I | 0, _ = S | 0, I = w | 0, S = v | 0, { h: w, l: v } = k(x | 0, m | 0, l | 0, d | 0), x = u | 0, m = i | 0, u = s | 0, i = c | 0, s = o | 0, c = r | 0;
784
- const R = Xe(d, g, B);
785
- o = We(R, l, b, y), r = R | 0;
786
- }
787
- ({ h: o, l: r } = k(this.Ah | 0, this.Al | 0, o | 0, r | 0)), { h: s, l: c } = k(this.Bh | 0, this.Bl | 0, s | 0, c | 0), { h: u, l: i } = k(this.Ch | 0, this.Cl | 0, u | 0, i | 0), { h: x, l: m } = k(this.Dh | 0, this.Dl | 0, x | 0, m | 0), { h: w, l: v } = k(this.Eh | 0, this.El | 0, w | 0, v | 0), { h: I, l: S } = k(this.Fh | 0, this.Fl | 0, I | 0, S | 0), { h: O, l: _ } = k(this.Gh | 0, this.Gl | 0, O | 0, _ | 0), { h: E, l: A } = k(this.Hh | 0, this.Hl | 0, E | 0, A | 0), this.set(o, r, s, c, u, i, x, m, w, v, I, S, O, _, E, A);
788
- }
789
- roundClean() {
790
- mt(K, Y);
791
- }
792
- destroy() {
793
- mt(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
794
- }
795
- }
796
- class rn extends nn {
797
- Ah = M[0] | 0;
798
- Al = M[1] | 0;
799
- Bh = M[2] | 0;
800
- Bl = M[3] | 0;
801
- Ch = M[4] | 0;
802
- Cl = M[5] | 0;
803
- Dh = M[6] | 0;
804
- Dl = M[7] | 0;
805
- Eh = M[8] | 0;
806
- El = M[9] | 0;
807
- Fh = M[10] | 0;
808
- Fl = M[11] | 0;
809
- Gh = M[12] | 0;
810
- Gl = M[13] | 0;
811
- Hh = M[14] | 0;
812
- Hl = M[15] | 0;
813
- constructor() {
814
- super(64);
815
- }
816
- }
817
- const on = /* @__PURE__ */ je(
818
- () => new rn(),
819
- /* @__PURE__ */ ke(3)
820
- );
821
- const ce = /* @__PURE__ */ BigInt(0), jt = /* @__PURE__ */ BigInt(1);
822
- function Et(e, t = "") {
823
- if (typeof e != "boolean") {
824
- const n = t && `"${t}" `;
825
- throw new Error(n + "expected boolean, got type=" + typeof e);
826
- }
827
- return e;
828
- }
829
- function sn(e) {
830
- if (typeof e == "bigint") {
831
- if (!ct(e))
832
- throw new Error("positive bigint expected, got " + e);
833
- } else
834
- Rt(e);
835
- return e;
836
- }
837
- function fe(e) {
838
- if (typeof e != "string")
839
- throw new Error("hex string expected, got " + typeof e);
840
- return e === "" ? ce : BigInt("0x" + e);
841
- }
842
- function cn(e) {
843
- return fe(It(e));
844
- }
845
- function ft(e) {
846
- return fe(It(Bt(D(e)).reverse()));
847
- }
848
- function ae(e, t) {
849
- Rt(t), e = sn(e);
850
- const n = se(e.toString(16).padStart(t * 2, "0"));
851
- if (n.length !== t)
852
- throw new Error("number too large");
853
- return n;
854
- }
855
- function fn(e, t) {
856
- return ae(e, t).reverse();
857
- }
858
- function Bt(e) {
859
- return Uint8Array.from(e);
860
- }
861
- const ct = (e) => typeof e == "bigint" && ce <= e;
862
- function an(e, t, n) {
863
- return ct(e) && ct(t) && ct(n) && t <= e && e < n;
864
- }
865
- function Vt(e, t, n, o) {
866
- if (!an(t, n, o))
867
- throw new Error("expected valid " + e + ": " + n + " <= n < " + o + ", got " + t);
868
- }
869
- const un = (e) => (jt << BigInt(e)) - jt;
870
- function _t(e, t = {}, n = {}) {
871
- if (!e || typeof e != "object")
872
- throw new Error("expected valid options object");
873
- function o(s, c, u) {
874
- const i = e[s];
875
- if (u && i === void 0)
876
- return;
877
- const x = typeof i;
878
- if (x !== c || i === null)
879
- throw new Error(`param "${s}" is invalid: expected ${c}, got ${x}`);
880
- }
881
- const r = (s, c) => Object.entries(s).forEach(([u, i]) => o(u, i, c));
882
- r(t, !1), r(n, !0);
883
- }
884
- function kt(e) {
885
- const t = /* @__PURE__ */ new WeakMap();
886
- return (n, ...o) => {
887
- const r = t.get(n);
888
- if (r !== void 0)
889
- return r;
890
- const s = e(n, ...o);
891
- return t.set(n, s), s;
892
- };
893
- }
894
- const $ = /* @__PURE__ */ BigInt(0), G = /* @__PURE__ */ BigInt(1), F = /* @__PURE__ */ BigInt(2), ue = /* @__PURE__ */ BigInt(3), he = /* @__PURE__ */ BigInt(4), le = /* @__PURE__ */ BigInt(5), hn = /* @__PURE__ */ BigInt(7), de = /* @__PURE__ */ BigInt(8), ln = /* @__PURE__ */ BigInt(9), be = /* @__PURE__ */ BigInt(16);
895
- function H(e, t) {
896
- const n = e % t;
897
- return n >= $ ? n : t + n;
898
- }
899
- function Z(e, t, n) {
900
- let o = e;
901
- for (; t-- > $; )
902
- o *= o, o %= n;
903
- return o;
904
- }
905
- function Kt(e, t) {
906
- if (e === $)
907
- throw new Error("invert: expected non-zero number");
908
- if (t <= $)
909
- throw new Error("invert: expected positive modulus, got " + t);
910
- let n = H(e, t), o = t, r = $, s = G;
911
- for (; n !== $; ) {
912
- const u = o / n, i = o % n, x = r - s * u;
913
- o = n, n = i, r = s, s = x;
914
- }
915
- if (o !== G)
916
- throw new Error("invert: does not exist");
917
- return H(r, t);
918
- }
919
- function Nt(e, t, n) {
920
- if (!e.eql(e.sqr(t), n))
921
- throw new Error("Cannot find square root");
922
- }
923
- function ge(e, t) {
924
- const n = (e.ORDER + G) / he, o = e.pow(t, n);
925
- return Nt(e, o, t), o;
926
- }
927
- function dn(e, t) {
928
- const n = (e.ORDER - le) / de, o = e.mul(t, F), r = e.pow(o, n), s = e.mul(t, r), c = e.mul(e.mul(s, F), r), u = e.mul(s, e.sub(c, e.ONE));
929
- return Nt(e, u, t), u;
930
- }
931
- function bn(e) {
932
- const t = Ot(e), n = we(e), o = n(t, t.neg(t.ONE)), r = n(t, o), s = n(t, t.neg(o)), c = (e + hn) / be;
933
- return (u, i) => {
934
- let x = u.pow(i, c), m = u.mul(x, o);
935
- const w = u.mul(x, r), v = u.mul(x, s), I = u.eql(u.sqr(m), i), S = u.eql(u.sqr(w), i);
936
- x = u.cmov(x, m, I), m = u.cmov(v, w, S);
937
- const O = u.eql(u.sqr(m), i), _ = u.cmov(x, m, O);
938
- return Nt(u, _, i), _;
939
- };
940
- }
941
- function we(e) {
942
- if (e < ue)
943
- throw new Error("sqrt is not defined for small field");
944
- let t = e - G, n = 0;
945
- for (; t % F === $; )
946
- t /= F, n++;
947
- let o = F;
948
- const r = Ot(e);
949
- for (; Yt(r, o) === 1; )
950
- if (o++ > 1e3)
951
- throw new Error("Cannot find square root: probably non-prime P");
952
- if (n === 1)
953
- return ge;
954
- let s = r.pow(o, t);
955
- const c = (t + G) / F;
956
- return function(i, x) {
957
- if (i.is0(x))
958
- return x;
959
- if (Yt(i, x) !== 1)
960
- throw new Error("Cannot find square root");
961
- let m = n, w = i.mul(i.ONE, s), v = i.pow(x, t), I = i.pow(x, c);
962
- for (; !i.eql(v, i.ONE); ) {
963
- if (i.is0(v))
964
- return i.ZERO;
965
- let S = 1, O = i.sqr(v);
966
- for (; !i.eql(O, i.ONE); )
967
- if (S++, O = i.sqr(O), S === m)
968
- throw new Error("Cannot find square root");
969
- const _ = G << BigInt(m - S - 1), E = i.pow(w, _);
970
- m = S, w = i.sqr(E), v = i.mul(v, w), I = i.mul(I, E);
971
- }
972
- return I;
973
- };
974
- }
975
- function gn(e) {
976
- return e % he === ue ? ge : e % de === le ? dn : e % be === ln ? bn(e) : we(e);
977
- }
978
- const wn = (e, t) => (H(e, t) & G) === G, xn = [
979
- "create",
980
- "isValid",
981
- "is0",
982
- "neg",
983
- "inv",
984
- "sqrt",
985
- "sqr",
986
- "eql",
987
- "add",
988
- "sub",
989
- "mul",
990
- "pow",
991
- "div",
992
- "addN",
993
- "subN",
994
- "mulN",
995
- "sqrN"
996
- ];
997
- function pn(e) {
998
- const t = {
999
- ORDER: "bigint",
1000
- BYTES: "number",
1001
- BITS: "number"
1002
- }, n = xn.reduce((o, r) => (o[r] = "function", o), t);
1003
- return _t(e, n), e;
1004
- }
1005
- function yn(e, t, n) {
1006
- if (n < $)
1007
- throw new Error("invalid exponent, negatives unsupported");
1008
- if (n === $)
1009
- return e.ONE;
1010
- if (n === G)
1011
- return t;
1012
- let o = e.ONE, r = t;
1013
- for (; n > $; )
1014
- n & G && (o = e.mul(o, r)), r = e.sqr(r), n >>= G;
1015
- return o;
1016
- }
1017
- function xe(e, t, n = !1) {
1018
- const o = new Array(t.length).fill(n ? e.ZERO : void 0), r = t.reduce((c, u, i) => e.is0(u) ? c : (o[i] = c, e.mul(c, u)), e.ONE), s = e.inv(r);
1019
- return t.reduceRight((c, u, i) => e.is0(u) ? c : (o[i] = e.mul(c, o[i]), e.mul(c, u)), s), o;
1020
- }
1021
- function Yt(e, t) {
1022
- const n = (e.ORDER - G) / F, o = e.pow(t, n), r = e.eql(o, e.ONE), s = e.eql(o, e.ZERO), c = e.eql(o, e.neg(e.ONE));
1023
- if (!r && !s && !c)
1024
- throw new Error("invalid Legendre symbol result");
1025
- return r ? 1 : s ? 0 : -1;
1026
- }
1027
- function mn(e, t) {
1028
- t !== void 0 && Rt(t);
1029
- const n = t !== void 0 ? t : e.toString(2).length, o = Math.ceil(n / 8);
1030
- return { nBitLength: n, nByteLength: o };
1031
- }
1032
- class En {
1033
- ORDER;
1034
- BITS;
1035
- BYTES;
1036
- isLE;
1037
- ZERO = $;
1038
- ONE = G;
1039
- _lengths;
1040
- _sqrt;
1041
- // cached sqrt
1042
- _mod;
1043
- constructor(t, n = {}) {
1044
- if (t <= $)
1045
- throw new Error("invalid field: expected ORDER > 0, got " + t);
1046
- let o;
1047
- this.isLE = !1, n != null && typeof n == "object" && (typeof n.BITS == "number" && (o = n.BITS), typeof n.sqrt == "function" && (this.sqrt = n.sqrt), typeof n.isLE == "boolean" && (this.isLE = n.isLE), n.allowedLengths && (this._lengths = n.allowedLengths?.slice()), typeof n.modFromBytes == "boolean" && (this._mod = n.modFromBytes));
1048
- const { nBitLength: r, nByteLength: s } = mn(t, o);
1049
- if (s > 2048)
1050
- throw new Error("invalid field: expected ORDER of <= 2048 bytes");
1051
- this.ORDER = t, this.BITS = r, this.BYTES = s, this._sqrt = void 0, Object.preventExtensions(this);
1052
- }
1053
- create(t) {
1054
- return H(t, this.ORDER);
1055
- }
1056
- isValid(t) {
1057
- if (typeof t != "bigint")
1058
- throw new Error("invalid field element: expected bigint, got " + typeof t);
1059
- return $ <= t && t < this.ORDER;
1060
- }
1061
- is0(t) {
1062
- return t === $;
1063
- }
1064
- // is valid and invertible
1065
- isValidNot0(t) {
1066
- return !this.is0(t) && this.isValid(t);
1067
- }
1068
- isOdd(t) {
1069
- return (t & G) === G;
1070
- }
1071
- neg(t) {
1072
- return H(-t, this.ORDER);
1073
- }
1074
- eql(t, n) {
1075
- return t === n;
1076
- }
1077
- sqr(t) {
1078
- return H(t * t, this.ORDER);
1079
- }
1080
- add(t, n) {
1081
- return H(t + n, this.ORDER);
1082
- }
1083
- sub(t, n) {
1084
- return H(t - n, this.ORDER);
1085
- }
1086
- mul(t, n) {
1087
- return H(t * n, this.ORDER);
1088
- }
1089
- pow(t, n) {
1090
- return yn(this, t, n);
1091
- }
1092
- div(t, n) {
1093
- return H(t * Kt(n, this.ORDER), this.ORDER);
1094
- }
1095
- // Same as above, but doesn't normalize
1096
- sqrN(t) {
1097
- return t * t;
1098
- }
1099
- addN(t, n) {
1100
- return t + n;
1101
- }
1102
- subN(t, n) {
1103
- return t - n;
1104
- }
1105
- mulN(t, n) {
1106
- return t * n;
1107
- }
1108
- inv(t) {
1109
- return Kt(t, this.ORDER);
1110
- }
1111
- sqrt(t) {
1112
- return this._sqrt || (this._sqrt = gn(this.ORDER)), this._sqrt(this, t);
1113
- }
1114
- toBytes(t) {
1115
- return this.isLE ? fn(t, this.BYTES) : ae(t, this.BYTES);
1116
- }
1117
- fromBytes(t, n = !1) {
1118
- D(t);
1119
- const { _lengths: o, BYTES: r, isLE: s, ORDER: c, _mod: u } = this;
1120
- if (o) {
1121
- if (!o.includes(t.length) || t.length > r)
1122
- throw new Error("Field.fromBytes: expected " + o + " bytes, got " + t.length);
1123
- const x = new Uint8Array(r);
1124
- x.set(t, s ? 0 : x.length - t.length), t = x;
1125
- }
1126
- if (t.length !== r)
1127
- throw new Error("Field.fromBytes: expected " + r + " bytes, got " + t.length);
1128
- let i = s ? ft(t) : cn(t);
1129
- if (u && (i = H(i, c)), !n && !this.isValid(i))
1130
- throw new Error("invalid field element: outside of range 0..ORDER");
1131
- return i;
1132
- }
1133
- // TODO: we don't need it here, move out to separate fn
1134
- invertBatch(t) {
1135
- return xe(this, t);
1136
- }
1137
- // We can't move this out because Fp6, Fp12 implement it
1138
- // and it's unclear what to return in there.
1139
- cmov(t, n, o) {
1140
- return o ? n : t;
1141
- }
1142
- }
1143
- function Ot(e, t = {}) {
1144
- return new En(e, t);
1145
- }
1146
- const at = /* @__PURE__ */ BigInt(0), vt = /* @__PURE__ */ BigInt(1);
1147
- function zt(e, t) {
1148
- const n = t.negate();
1149
- return e ? n : t;
1150
- }
1151
- function dt(e, t) {
1152
- const n = xe(e.Fp, t.map((o) => o.Z));
1153
- return t.map((o, r) => e.fromAffine(o.toAffine(n[r])));
1154
- }
1155
- function pe(e, t) {
1156
- if (!Number.isSafeInteger(e) || e <= 0 || e > t)
1157
- throw new Error("invalid window size, expected [1.." + t + "], got W=" + e);
1158
- }
1159
- function bt(e, t) {
1160
- pe(e, t);
1161
- const n = Math.ceil(t / e) + 1, o = 2 ** (e - 1), r = 2 ** e, s = un(e), c = BigInt(e);
1162
- return { windows: n, windowSize: o, mask: s, maxNumber: r, shiftBy: c };
1163
- }
1164
- function Xt(e, t, n) {
1165
- const { windowSize: o, mask: r, maxNumber: s, shiftBy: c } = n;
1166
- let u = Number(e & r), i = e >> c;
1167
- u > o && (u -= s, i += vt);
1168
- const x = t * o, m = x + Math.abs(u) - 1, w = u === 0, v = u < 0, I = t % 2 !== 0;
1169
- return { nextN: i, offset: m, isZero: w, isNeg: v, isNegF: I, offsetF: x };
1170
- }
1171
- const gt = /* @__PURE__ */ new WeakMap(), ye = /* @__PURE__ */ new WeakMap();
1172
- function wt(e) {
1173
- return ye.get(e) || 1;
1174
- }
1175
- function Wt(e) {
1176
- if (e !== at)
1177
- throw new Error("invalid wNAF");
1178
- }
1179
- class Bn {
1180
- BASE;
1181
- ZERO;
1182
- Fn;
1183
- bits;
1184
- // Parametrized with a given Point class (not individual point)
1185
- constructor(t, n) {
1186
- this.BASE = t.BASE, this.ZERO = t.ZERO, this.Fn = t.Fn, this.bits = n;
1187
- }
1188
- // non-const time multiplication ladder
1189
- _unsafeLadder(t, n, o = this.ZERO) {
1190
- let r = t;
1191
- for (; n > at; )
1192
- n & vt && (o = o.add(r)), r = r.double(), n >>= vt;
1193
- return o;
1194
- }
1195
- /**
1196
- * Creates a wNAF precomputation window. Used for caching.
1197
- * Default window size is set by `utils.precompute()` and is equal to 8.
1198
- * Number of precomputed points depends on the curve size:
1199
- * 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
1200
- * - 𝑊 is the window size
1201
- * - 𝑛 is the bitlength of the curve order.
1202
- * For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
1203
- * @param point Point instance
1204
- * @param W window size
1205
- * @returns precomputed point tables flattened to a single array
1206
- */
1207
- precomputeWindow(t, n) {
1208
- const { windows: o, windowSize: r } = bt(n, this.bits), s = [];
1209
- let c = t, u = c;
1210
- for (let i = 0; i < o; i++) {
1211
- u = c, s.push(u);
1212
- for (let x = 1; x < r; x++)
1213
- u = u.add(c), s.push(u);
1214
- c = u.double();
1215
- }
1216
- return s;
1217
- }
1218
- /**
1219
- * Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
1220
- * More compact implementation:
1221
- * https://github.com/paulmillr/noble-secp256k1/blob/47cb1669b6e506ad66b35fe7d76132ae97465da2/index.ts#L502-L541
1222
- * @returns real and fake (for const-time) points
1223
- */
1224
- wNAF(t, n, o) {
1225
- if (!this.Fn.isValid(o))
1226
- throw new Error("invalid scalar");
1227
- let r = this.ZERO, s = this.BASE;
1228
- const c = bt(t, this.bits);
1229
- for (let u = 0; u < c.windows; u++) {
1230
- const { nextN: i, offset: x, isZero: m, isNeg: w, isNegF: v, offsetF: I } = Xt(o, u, c);
1231
- o = i, m ? s = s.add(zt(v, n[I])) : r = r.add(zt(w, n[x]));
1232
- }
1233
- return Wt(o), { p: r, f: s };
1234
- }
1235
- /**
1236
- * Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
1237
- * @param acc accumulator point to add result of multiplication
1238
- * @returns point
1239
- */
1240
- wNAFUnsafe(t, n, o, r = this.ZERO) {
1241
- const s = bt(t, this.bits);
1242
- for (let c = 0; c < s.windows && o !== at; c++) {
1243
- const { nextN: u, offset: i, isZero: x, isNeg: m } = Xt(o, c, s);
1244
- if (o = u, !x) {
1245
- const w = n[i];
1246
- r = r.add(m ? w.negate() : w);
1247
- }
1248
- }
1249
- return Wt(o), r;
1250
- }
1251
- getPrecomputes(t, n, o) {
1252
- let r = gt.get(n);
1253
- return r || (r = this.precomputeWindow(n, t), t !== 1 && (typeof o == "function" && (r = o(r)), gt.set(n, r))), r;
1254
- }
1255
- cached(t, n, o) {
1256
- const r = wt(t);
1257
- return this.wNAF(r, this.getPrecomputes(r, t, o), n);
1258
- }
1259
- unsafe(t, n, o, r) {
1260
- const s = wt(t);
1261
- return s === 1 ? this._unsafeLadder(t, n, r) : this.wNAFUnsafe(s, this.getPrecomputes(s, t, o), n, r);
1262
- }
1263
- // We calculate precomputes for elliptic curve point multiplication
1264
- // using windowed method. This specifies window size and
1265
- // stores precomputed values. Usually only base point would be precomputed.
1266
- createCache(t, n) {
1267
- pe(n, this.bits), ye.set(t, n), gt.delete(t);
1268
- }
1269
- hasCache(t) {
1270
- return wt(t) !== 1;
1271
- }
1272
- }
1273
- function Pt(e, t, n) {
1274
- if (t) {
1275
- if (t.ORDER !== e)
1276
- throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
1277
- return pn(t), t;
1278
- } else
1279
- return Ot(e, { isLE: n });
1280
- }
1281
- function vn(e, t, n = {}, o) {
1282
- if (o === void 0 && (o = e === "edwards"), !t || typeof t != "object")
1283
- throw new Error(`expected valid ${e} CURVE object`);
1284
- for (const i of ["p", "n", "h"]) {
1285
- const x = t[i];
1286
- if (!(typeof x == "bigint" && x > at))
1287
- throw new Error(`CURVE.${i} must be positive bigint`);
1288
- }
1289
- const r = Pt(t.p, n.Fp, o), s = Pt(t.n, n.Fn, o), u = ["Gx", "Gy", "a", "d"];
1290
- for (const i of u)
1291
- if (!r.isValid(t[i]))
1292
- throw new Error(`CURVE.${i} must be valid field element of CURVE.Fp`);
1293
- return t = Object.freeze(Object.assign({}, t)), { CURVE: t, Fp: r, Fn: s };
1294
- }
1295
- function Sn(e, t) {
1296
- return function(o) {
1297
- const r = e(o);
1298
- return { secretKey: r, publicKey: t(r) };
1299
- };
1300
- }
1301
- const z = BigInt(0), U = BigInt(1), xt = BigInt(2), An = BigInt(8);
1302
- function Rn(e, t, n, o) {
1303
- const r = e.sqr(n), s = e.sqr(o), c = e.add(e.mul(t.a, r), s), u = e.add(e.ONE, e.mul(t.d, e.mul(r, s)));
1304
- return e.eql(c, u);
1305
- }
1306
- function In(e, t = {}) {
1307
- const n = vn("edwards", e, t, t.FpFnLE), { Fp: o, Fn: r } = n;
1308
- let s = n.CURVE;
1309
- const { h: c } = s;
1310
- _t(t, {}, { uvRatio: "function" });
1311
- const u = xt << BigInt(r.BYTES * 8) - U, i = (_) => o.create(_), x = t.uvRatio || ((_, E) => {
1312
- try {
1313
- return { isValid: !0, value: o.sqrt(o.div(_, E)) };
1314
- } catch {
1315
- return { isValid: !1, value: z };
1316
- }
1317
- });
1318
- if (!Rn(o, s, s.Gx, s.Gy))
1319
- throw new Error("bad curve params: generator point");
1320
- function m(_, E, A = !1) {
1321
- const p = A ? U : z;
1322
- return Vt("coordinate " + _, E, p, u), E;
1323
- }
1324
- function w(_) {
1325
- if (!(_ instanceof S))
1326
- throw new Error("EdwardsPoint expected");
1327
- }
1328
- const v = kt((_, E) => {
1329
- const { X: A, Y: p, Z: N } = _, T = _.is0();
1330
- E == null && (E = T ? An : o.inv(N));
1331
- const a = i(A * E), h = i(p * E), f = o.mul(N, E);
1332
- if (T)
1333
- return { x: z, y: U };
1334
- if (f !== U)
1335
- throw new Error("invZ was invalid");
1336
- return { x: a, y: h };
1337
- }), I = kt((_) => {
1338
- const { a: E, d: A } = s;
1339
- if (_.is0())
1340
- throw new Error("bad point: ZERO");
1341
- const { X: p, Y: N, Z: T, T: a } = _, h = i(p * p), f = i(N * N), l = i(T * T), d = i(l * l), b = i(h * E), g = i(l * i(b + f)), y = i(d + i(A * i(h * f)));
1342
- if (g !== y)
1343
- throw new Error("bad point: equation left != right (1)");
1344
- const B = i(p * N), R = i(T * a);
1345
- if (B !== R)
1346
- throw new Error("bad point: equation left != right (2)");
1347
- return !0;
1348
- });
1349
- class S {
1350
- // base / generator point
1351
- static BASE = new S(s.Gx, s.Gy, U, i(s.Gx * s.Gy));
1352
- // zero / infinity / identity point
1353
- static ZERO = new S(z, U, U, z);
1354
- // 0, 1, 1, 0
1355
- // math field
1356
- static Fp = o;
1357
- // scalar field
1358
- static Fn = r;
1359
- X;
1360
- Y;
1361
- Z;
1362
- T;
1363
- constructor(E, A, p, N) {
1364
- this.X = m("x", E), this.Y = m("y", A), this.Z = m("z", p, !0), this.T = m("t", N), Object.freeze(this);
1365
- }
1366
- static CURVE() {
1367
- return s;
1368
- }
1369
- static fromAffine(E) {
1370
- if (E instanceof S)
1371
- throw new Error("extended point not allowed");
1372
- const { x: A, y: p } = E || {};
1373
- return m("x", A), m("y", p), new S(A, p, U, i(A * p));
1374
- }
1375
- // Uses algo from RFC8032 5.1.3.
1376
- static fromBytes(E, A = !1) {
1377
- const p = o.BYTES, { a: N, d: T } = s;
1378
- E = Bt(D(E, p, "point")), Et(A, "zip215");
1379
- const a = Bt(E), h = E[p - 1];
1380
- a[p - 1] = h & -129;
1381
- const f = ft(a), l = A ? u : o.ORDER;
1382
- Vt("point.y", f, z, l);
1383
- const d = i(f * f), b = i(d - U), g = i(T * d - N);
1384
- let { isValid: y, value: B } = x(b, g);
1385
- if (!y)
1386
- throw new Error("bad point: invalid y coordinate");
1387
- const R = (B & U) === U, C = (h & 128) !== 0;
1388
- if (!A && B === z && C)
1389
- throw new Error("bad point: x=0 and x_0=1");
1390
- return C !== R && (B = i(-B)), S.fromAffine({ x: B, y: f });
1391
- }
1392
- static fromHex(E, A = !1) {
1393
- return S.fromBytes(se(E), A);
1394
- }
1395
- get x() {
1396
- return this.toAffine().x;
1397
- }
1398
- get y() {
1399
- return this.toAffine().y;
1400
- }
1401
- precompute(E = 8, A = !0) {
1402
- return O.createCache(this, E), A || this.multiply(xt), this;
1403
- }
1404
- // Useful in fromAffine() - not for fromBytes(), which always created valid points.
1405
- assertValidity() {
1406
- I(this);
1407
- }
1408
- // Compare one point to another.
1409
- equals(E) {
1410
- w(E);
1411
- const { X: A, Y: p, Z: N } = this, { X: T, Y: a, Z: h } = E, f = i(A * h), l = i(T * N), d = i(p * h), b = i(a * N);
1412
- return f === l && d === b;
1413
- }
1414
- is0() {
1415
- return this.equals(S.ZERO);
1416
- }
1417
- negate() {
1418
- return new S(i(-this.X), this.Y, this.Z, i(-this.T));
1419
- }
1420
- // Fast algo for doubling Extended Point.
1421
- // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#doubling-dbl-2008-hwcd
1422
- // Cost: 4M + 4S + 1*a + 6add + 1*2.
1423
- double() {
1424
- const { a: E } = s, { X: A, Y: p, Z: N } = this, T = i(A * A), a = i(p * p), h = i(xt * i(N * N)), f = i(E * T), l = A + p, d = i(i(l * l) - T - a), b = f + a, g = b - h, y = f - a, B = i(d * g), R = i(b * y), C = i(d * y), L = i(g * b);
1425
- return new S(B, R, L, C);
1426
- }
1427
- // Fast algo for adding 2 Extended Points.
1428
- // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#addition-add-2008-hwcd
1429
- // Cost: 9M + 1*a + 1*d + 7add.
1430
- add(E) {
1431
- w(E);
1432
- const { a: A, d: p } = s, { X: N, Y: T, Z: a, T: h } = this, { X: f, Y: l, Z: d, T: b } = E, g = i(N * f), y = i(T * l), B = i(h * p * b), R = i(a * d), C = i((N + T) * (f + l) - g - y), L = R - B, q = R + B, Q = i(y - A * g), nt = i(C * L), ut = i(q * Q), Lt = i(C * Q), Ht = i(L * q);
1433
- return new S(nt, ut, Ht, Lt);
1434
- }
1435
- subtract(E) {
1436
- return this.add(E.negate());
1437
- }
1438
- // Constant-time multiplication.
1439
- multiply(E) {
1440
- if (!r.isValidNot0(E))
1441
- throw new Error("invalid scalar: expected 1 <= sc < curve.n");
1442
- const { p: A, f: p } = O.cached(this, E, (N) => dt(S, N));
1443
- return dt(S, [A, p])[0];
1444
- }
1445
- // Non-constant-time multiplication. Uses double-and-add algorithm.
1446
- // It's faster, but should only be used when you don't care about
1447
- // an exposed private key e.g. sig verification.
1448
- // Does NOT allow scalars higher than CURVE.n.
1449
- // Accepts optional accumulator to merge with multiply (important for sparse scalars)
1450
- multiplyUnsafe(E, A = S.ZERO) {
1451
- if (!r.isValid(E))
1452
- throw new Error("invalid scalar: expected 0 <= sc < curve.n");
1453
- return E === z ? S.ZERO : this.is0() || E === U ? this : O.unsafe(this, E, (p) => dt(S, p), A);
1454
- }
1455
- // Checks if point is of small order.
1456
- // If you add something to small order point, you will have "dirty"
1457
- // point with torsion component.
1458
- // Multiplies point by cofactor and checks if the result is 0.
1459
- isSmallOrder() {
1460
- return this.multiplyUnsafe(c).is0();
1461
- }
1462
- // Multiplies point by curve order and checks if the result is 0.
1463
- // Returns `false` is the point is dirty.
1464
- isTorsionFree() {
1465
- return O.unsafe(this, s.n).is0();
1466
- }
1467
- // Converts Extended point to default (x, y) coordinates.
1468
- // Can accept precomputed Z^-1 - for example, from invertBatch.
1469
- toAffine(E) {
1470
- return v(this, E);
1471
- }
1472
- clearCofactor() {
1473
- return c === U ? this : this.multiplyUnsafe(c);
1474
- }
1475
- toBytes() {
1476
- const { x: E, y: A } = this.toAffine(), p = o.toBytes(A);
1477
- return p[p.length - 1] |= E & U ? 128 : 0, p;
1478
- }
1479
- toHex() {
1480
- return It(this.toBytes());
1481
- }
1482
- toString() {
1483
- return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
1484
- }
1485
- }
1486
- const O = new Bn(S, r.BITS);
1487
- return S.BASE.precompute(8), S;
1488
- }
1489
- function _n(e, t, n = {}) {
1490
- if (typeof t != "function")
1491
- throw new Error('"hash" function param is required');
1492
- _t(n, {}, {
1493
- adjustScalarBytes: "function",
1494
- randomBytes: "function",
1495
- domain: "function",
1496
- prehash: "function",
1497
- mapToCurve: "function"
1498
- });
1499
- const { prehash: o } = n, { BASE: r, Fp: s, Fn: c } = e, u = n.randomBytes || Ve, i = n.adjustScalarBytes || ((f) => f), x = n.domain || ((f, l, d) => {
1500
- if (Et(d, "phflag"), l.length || d)
1501
- throw new Error("Contexts/pre-hash are not supported");
1502
- return f;
1503
- });
1504
- function m(f) {
1505
- return c.create(ft(f));
1506
- }
1507
- function w(f) {
1508
- const l = p.secretKey;
1509
- D(f, p.secretKey, "secretKey");
1510
- const d = D(t(f), 2 * l, "hashedSecretKey"), b = i(d.slice(0, l)), g = d.slice(l, 2 * l), y = m(b);
1511
- return { head: b, prefix: g, scalar: y };
1512
- }
1513
- function v(f) {
1514
- const { head: l, prefix: d, scalar: b } = w(f), g = r.multiply(b), y = g.toBytes();
1515
- return { head: l, prefix: d, scalar: b, point: g, pointBytes: y };
1516
- }
1517
- function I(f) {
1518
- return v(f).pointBytes;
1519
- }
1520
- function S(f = Uint8Array.of(), ...l) {
1521
- const d = Mt(...l);
1522
- return m(t(x(d, D(f, void 0, "context"), !!o)));
1523
- }
1524
- function O(f, l, d = {}) {
1525
- f = D(f, void 0, "message"), o && (f = o(f));
1526
- const { prefix: b, scalar: g, pointBytes: y } = v(l), B = S(d.context, b, f), R = r.multiply(B).toBytes(), C = S(d.context, R, y, f), L = c.create(B + C * g);
1527
- if (!c.isValid(L))
1528
- throw new Error("sign failed: invalid s");
1529
- const q = Mt(R, c.toBytes(L));
1530
- return D(q, p.signature, "result");
1531
- }
1532
- const _ = { zip215: !0 };
1533
- function E(f, l, d, b = _) {
1534
- const { context: g, zip215: y } = b, B = p.signature;
1535
- f = D(f, B, "signature"), l = D(l, void 0, "message"), d = D(d, p.publicKey, "publicKey"), y !== void 0 && Et(y, "zip215"), o && (l = o(l));
1536
- const R = B / 2, C = f.subarray(0, R), L = ft(f.subarray(R, B));
1537
- let q, Q, nt;
1538
- try {
1539
- q = e.fromBytes(d, y), Q = e.fromBytes(C, y), nt = r.multiplyUnsafe(L);
1540
- } catch {
1541
- return !1;
1542
- }
1543
- if (!y && q.isSmallOrder())
1544
- return !1;
1545
- const ut = S(g, Q.toBytes(), q.toBytes(), l);
1546
- return Q.add(q.multiplyUnsafe(ut)).subtract(nt).clearCofactor().is0();
1547
- }
1548
- const A = s.BYTES, p = {
1549
- secretKey: A,
1550
- publicKey: A,
1551
- signature: 2 * A,
1552
- seed: A
1553
- };
1554
- function N(f = u(p.seed)) {
1555
- return D(f, p.seed, "seed");
1556
- }
1557
- function T(f) {
1558
- return re(f) && f.length === c.BYTES;
1559
- }
1560
- function a(f, l) {
1561
- try {
1562
- return !!e.fromBytes(f, l);
1563
- } catch {
1564
- return !1;
1565
- }
1566
- }
1567
- const h = {
1568
- getExtendedPublicKey: v,
1569
- randomSecretKey: N,
1570
- isValidSecretKey: T,
1571
- isValidPublicKey: a,
1572
- /**
1573
- * Converts ed public key to x public key. Uses formula:
1574
- * - ed25519:
1575
- * - `(u, v) = ((1+y)/(1-y), sqrt(-486664)*u/x)`
1576
- * - `(x, y) = (sqrt(-486664)*u/v, (u-1)/(u+1))`
1577
- * - ed448:
1578
- * - `(u, v) = ((y-1)/(y+1), sqrt(156324)*u/x)`
1579
- * - `(x, y) = (sqrt(156324)*u/v, (1+u)/(1-u))`
1580
- */
1581
- toMontgomery(f) {
1582
- const { y: l } = e.fromBytes(f), d = p.publicKey, b = d === 32;
1583
- if (!b && d !== 57)
1584
- throw new Error("only defined for 25519 and 448");
1585
- const g = b ? s.div(U + l, U - l) : s.div(l - U, l + U);
1586
- return s.toBytes(g);
1587
- },
1588
- toMontgomerySecret(f) {
1589
- const l = p.secretKey;
1590
- D(f, l);
1591
- const d = t(f.subarray(0, l));
1592
- return i(d).subarray(0, l);
1593
- }
1594
- };
1595
- return Object.freeze({
1596
- keygen: Sn(N, I),
1597
- getPublicKey: I,
1598
- sign: O,
1599
- verify: E,
1600
- utils: h,
1601
- Point: e,
1602
- lengths: p
1603
- });
1604
- }
1605
- const Nn = BigInt(1), Ft = BigInt(2), On = BigInt(5), Tn = BigInt(8), Tt = BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"), Cn = {
1606
- p: Tt,
1607
- n: BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),
1608
- h: Tn,
1609
- a: BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),
1610
- d: BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),
1611
- Gx: BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),
1612
- Gy: BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")
1613
- };
1614
- function Ln(e) {
1615
- const t = BigInt(10), n = BigInt(20), o = BigInt(40), r = BigInt(80), s = Tt, u = e * e % s * e % s, i = Z(u, Ft, s) * u % s, x = Z(i, Nn, s) * e % s, m = Z(x, On, s) * x % s, w = Z(m, t, s) * m % s, v = Z(w, n, s) * w % s, I = Z(v, o, s) * v % s, S = Z(I, r, s) * I % s, O = Z(S, r, s) * I % s, _ = Z(O, t, s) * m % s;
1616
- return { pow_p_5_8: Z(_, Ft, s) * e % s, b2: u };
1617
- }
1618
- function Hn(e) {
1619
- return e[0] &= 248, e[31] &= 127, e[31] |= 64, e;
1620
- }
1621
- const Qt = /* @__PURE__ */ BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");
1622
- function Un(e, t) {
1623
- const n = Tt, o = H(t * t * t, n), r = H(o * o * t, n), s = Ln(e * r).pow_p_5_8;
1624
- let c = H(e * o * s, n);
1625
- const u = H(t * c * c, n), i = c, x = H(c * Qt, n), m = u === e, w = u === H(-e, n), v = u === H(-e * Qt, n);
1626
- return m && (c = i), (w || v) && (c = x), wn(c, n) && (c = H(-c, n)), { isValid: m || w, value: c };
1627
- }
1628
- const Dn = /* @__PURE__ */ In(Cn, { uvRatio: Un });
1629
- function qn(e) {
1630
- return _n(Dn, on, Object.assign({ adjustScalarBytes: Hn }, e));
1631
- }
1632
- const Mn = /* @__PURE__ */ qn({});
1633
- function Gn(e) {
1634
- return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
1635
- }
1636
- function Ct(e, ...t) {
1637
- if (!Gn(e))
1638
- throw new Error("Uint8Array expected");
1639
- if (t.length > 0 && !t.includes(e.length))
1640
- throw new Error("Uint8Array expected of length " + t + ", got length=" + e.length);
1641
- }
1642
- function Jt(e, t = !0) {
1643
- if (e.destroyed)
1644
- throw new Error("Hash instance has been destroyed");
1645
- if (t && e.finished)
1646
- throw new Error("Hash#digest() has already been called");
1647
- }
1648
- function $n(e, t) {
1649
- Ct(e);
1650
- const n = t.outputLen;
1651
- if (e.length < n)
1652
- throw new Error("digestInto() expects output buffer of length at least " + n);
1653
- }
1654
- function St(...e) {
1655
- for (let t = 0; t < e.length; t++)
1656
- e[t].fill(0);
1657
- }
1658
- function pt(e) {
1659
- return new DataView(e.buffer, e.byteOffset, e.byteLength);
1660
- }
1661
- function j(e, t) {
1662
- return e << 32 - t | e >>> t;
1663
- }
1664
- function Zn(e) {
1665
- if (typeof e != "string")
1666
- throw new Error("string expected");
1667
- return new Uint8Array(new TextEncoder().encode(e));
1668
- }
1669
- function me(e) {
1670
- return typeof e == "string" && (e = Zn(e)), Ct(e), e;
1671
- }
1672
- class jn {
1673
- }
1674
- function Vn(e) {
1675
- const t = (o) => e().update(me(o)).digest(), n = e();
1676
- return t.outputLen = n.outputLen, t.blockLen = n.blockLen, t.create = () => e(), t;
1677
- }
1678
- function kn(e, t, n, o) {
1679
- if (typeof e.setBigUint64 == "function")
1680
- return e.setBigUint64(t, n, o);
1681
- const r = BigInt(32), s = BigInt(4294967295), c = Number(n >> r & s), u = Number(n & s), i = o ? 4 : 0, x = o ? 0 : 4;
1682
- e.setUint32(t + i, c, o), e.setUint32(t + x, u, o);
1683
- }
1684
- function Kn(e, t, n) {
1685
- return e & t ^ ~e & n;
1686
- }
1687
- function Yn(e, t, n) {
1688
- return e & t ^ e & n ^ t & n;
1689
- }
1690
- class zn extends jn {
1691
- constructor(t, n, o, r) {
1692
- super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = t, this.outputLen = n, this.padOffset = o, this.isLE = r, this.buffer = new Uint8Array(t), this.view = pt(this.buffer);
1693
- }
1694
- update(t) {
1695
- Jt(this), t = me(t), Ct(t);
1696
- const { view: n, buffer: o, blockLen: r } = this, s = t.length;
1697
- for (let c = 0; c < s; ) {
1698
- const u = Math.min(r - this.pos, s - c);
1699
- if (u === r) {
1700
- const i = pt(t);
1701
- for (; r <= s - c; c += r)
1702
- this.process(i, c);
1703
- continue;
1704
- }
1705
- o.set(t.subarray(c, c + u), this.pos), this.pos += u, c += u, this.pos === r && (this.process(n, 0), this.pos = 0);
1706
- }
1707
- return this.length += t.length, this.roundClean(), this;
1708
- }
1709
- digestInto(t) {
1710
- Jt(this), $n(t, this), this.finished = !0;
1711
- const { buffer: n, view: o, blockLen: r, isLE: s } = this;
1712
- let { pos: c } = this;
1713
- n[c++] = 128, St(this.buffer.subarray(c)), this.padOffset > r - c && (this.process(o, 0), c = 0);
1714
- for (let w = c; w < r; w++)
1715
- n[w] = 0;
1716
- kn(o, r - 8, BigInt(this.length * 8), s), this.process(o, 0);
1717
- const u = pt(t), i = this.outputLen;
1718
- if (i % 4)
1719
- throw new Error("_sha2: outputLen should be aligned to 32bit");
1720
- const x = i / 4, m = this.get();
1721
- if (x > m.length)
1722
- throw new Error("_sha2: outputLen bigger than state");
1723
- for (let w = 0; w < x; w++)
1724
- u.setUint32(4 * w, m[w], s);
1725
- }
1726
- digest() {
1727
- const { buffer: t, outputLen: n } = this;
1728
- this.digestInto(t);
1729
- const o = t.slice(0, n);
1730
- return this.destroy(), o;
1731
- }
1732
- _cloneInto(t) {
1733
- t || (t = new this.constructor()), t.set(...this.get());
1734
- const { blockLen: n, buffer: o, length: r, finished: s, destroyed: c, pos: u } = this;
1735
- return t.destroyed = c, t.finished = s, t.length = r, t.pos = u, r % n && t.buffer.set(o), t;
1736
- }
1737
- clone() {
1738
- return this._cloneInto();
1739
- }
1740
- }
1741
- const X = /* @__PURE__ */ Uint32Array.from([
1742
- 1779033703,
1743
- 3144134277,
1744
- 1013904242,
1745
- 2773480762,
1746
- 1359893119,
1747
- 2600822924,
1748
- 528734635,
1749
- 1541459225
1750
- ]), Xn = /* @__PURE__ */ Uint32Array.from([
1751
- 1116352408,
1752
- 1899447441,
1753
- 3049323471,
1754
- 3921009573,
1755
- 961987163,
1756
- 1508970993,
1757
- 2453635748,
1758
- 2870763221,
1759
- 3624381080,
1760
- 310598401,
1761
- 607225278,
1762
- 1426881987,
1763
- 1925078388,
1764
- 2162078206,
1765
- 2614888103,
1766
- 3248222580,
1767
- 3835390401,
1768
- 4022224774,
1769
- 264347078,
1770
- 604807628,
1771
- 770255983,
1772
- 1249150122,
1773
- 1555081692,
1774
- 1996064986,
1775
- 2554220882,
1776
- 2821834349,
1777
- 2952996808,
1778
- 3210313671,
1779
- 3336571891,
1780
- 3584528711,
1781
- 113926993,
1782
- 338241895,
1783
- 666307205,
1784
- 773529912,
1785
- 1294757372,
1786
- 1396182291,
1787
- 1695183700,
1788
- 1986661051,
1789
- 2177026350,
1790
- 2456956037,
1791
- 2730485921,
1792
- 2820302411,
1793
- 3259730800,
1794
- 3345764771,
1795
- 3516065817,
1796
- 3600352804,
1797
- 4094571909,
1798
- 275423344,
1799
- 430227734,
1800
- 506948616,
1801
- 659060556,
1802
- 883997877,
1803
- 958139571,
1804
- 1322822218,
1805
- 1537002063,
1806
- 1747873779,
1807
- 1955562222,
1808
- 2024104815,
1809
- 2227730452,
1810
- 2361852424,
1811
- 2428436474,
1812
- 2756734187,
1813
- 3204031479,
1814
- 3329325298
1815
- ]), W = /* @__PURE__ */ new Uint32Array(64);
1816
- class Wn extends zn {
1817
- constructor(t = 32) {
1818
- super(64, t, 8, !1), this.A = X[0] | 0, this.B = X[1] | 0, this.C = X[2] | 0, this.D = X[3] | 0, this.E = X[4] | 0, this.F = X[5] | 0, this.G = X[6] | 0, this.H = X[7] | 0;
1819
- }
1820
- get() {
1821
- const { A: t, B: n, C: o, D: r, E: s, F: c, G: u, H: i } = this;
1822
- return [t, n, o, r, s, c, u, i];
1823
- }
1824
- // prettier-ignore
1825
- set(t, n, o, r, s, c, u, i) {
1826
- this.A = t | 0, this.B = n | 0, this.C = o | 0, this.D = r | 0, this.E = s | 0, this.F = c | 0, this.G = u | 0, this.H = i | 0;
1827
- }
1828
- process(t, n) {
1829
- for (let w = 0; w < 16; w++, n += 4)
1830
- W[w] = t.getUint32(n, !1);
1831
- for (let w = 16; w < 64; w++) {
1832
- const v = W[w - 15], I = W[w - 2], S = j(v, 7) ^ j(v, 18) ^ v >>> 3, O = j(I, 17) ^ j(I, 19) ^ I >>> 10;
1833
- W[w] = O + W[w - 7] + S + W[w - 16] | 0;
1834
- }
1835
- let { A: o, B: r, C: s, D: c, E: u, F: i, G: x, H: m } = this;
1836
- for (let w = 0; w < 64; w++) {
1837
- const v = j(u, 6) ^ j(u, 11) ^ j(u, 25), I = m + v + Kn(u, i, x) + Xn[w] + W[w] | 0, O = (j(o, 2) ^ j(o, 13) ^ j(o, 22)) + Yn(o, r, s) | 0;
1838
- m = x, x = i, i = u, u = c + I | 0, c = s, s = r, r = o, o = I + O | 0;
1839
- }
1840
- o = o + this.A | 0, r = r + this.B | 0, s = s + this.C | 0, c = c + this.D | 0, u = u + this.E | 0, i = i + this.F | 0, x = x + this.G | 0, m = m + this.H | 0, this.set(o, r, s, c, u, i, x, m);
1841
- }
1842
- roundClean() {
1843
- St(W);
1844
- }
1845
- destroy() {
1846
- this.set(0, 0, 0, 0, 0, 0, 0, 0), St(this.buffer);
1847
- }
1848
- }
1849
- const Pn = /* @__PURE__ */ Vn(() => new Wn()), Fn = Pn, Qn = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
1850
- function Jn(e) {
1851
- if (e.length !== 16)
1852
- throw new Error(`Invalid seed length: expected 16, got ${e.length}`);
1853
- const t = Fn(e), n = Mn.getPublicKey(t), o = new Uint8Array(64);
1854
- return o.set(t, 0), o.set(n, 32), ee(t), { publicKey: n, secretKey: o };
1855
- }
1856
- function cr(e) {
1857
- const t = Jn(e), n = t.publicKey;
1858
- return ee(t.secretKey), n;
1859
- }
1860
- function fr(e) {
1861
- if (e.length !== 32)
1862
- throw new Error(`Invalid public key length: expected 32, got ${e.length}`);
1863
- return tr(e);
1864
- }
1865
- function tr(e) {
1866
- let t = 0;
1867
- for (let r = 0; r < e.length && e[r] === 0; r++)
1868
- t++;
1869
- let n = 0n;
1870
- for (let r = 0; r < e.length; r++)
1871
- n = n * 256n + BigInt(e[r]);
1872
- let o = "";
1873
- for (; n > 0n; ) {
1874
- const r = Number(n % 58n);
1875
- o = Qn[r] + o, n = n / 58n;
1876
- }
1877
- return "1".repeat(t) + o;
1878
- }
1879
- const er = 2, nr = 3;
1880
- function ar(e) {
1881
- if (e.length !== 16)
1882
- throw new Error(`Invalid seed length: expected 16, got ${e.length}`);
1883
- const t = At(e), n = ne.share(t, nr, er);
1884
- if (n.length !== 3)
1885
- throw new Error(`Unexpected share count: ${n.length}`);
1886
- const o = yt(n[0]), r = yt(n[1]), s = yt(n[2]);
1887
- return {
1888
- shareA: ht(o),
1889
- shareB: ht(r),
1890
- shareC: ht(s)
1891
- };
1892
- }
1893
- function ur(e, t, n) {
1894
- const o = te(e), r = te(t);
1895
- try {
1896
- const s = ne.combine([o, r]), c = Ee(s);
1897
- if (c.length !== 16)
1898
- throw new Error(`Reconstructed seed has wrong length: ${c.length}`);
1899
- return Ae(c);
1900
- } catch (s) {
1901
- throw s instanceof Error && s.message.startsWith("Reconstructed seed") || s instanceof Error && s.message.startsWith("Invalid expectedPublicKey") || s instanceof Error && s.message.startsWith("Reconstructed seed does not match") ? s : new Error("Failed to reconstruct seed from shares");
1902
- }
1903
- }
1904
- function At(e) {
1905
- return Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
1906
- }
1907
- function Ee(e) {
1908
- if (!/^[0-9a-fA-F]*$/.test(e))
1909
- throw new Error("Invalid hex string: contains non-hex characters");
1910
- if (e.length % 2 !== 0)
1911
- throw new Error(`Invalid hex string: length ${e.length} is odd (must be even)`);
1912
- const t = new Uint8Array(e.length / 2);
1913
- for (let n = 0; n < t.length; n++)
1914
- t[n] = parseInt(e.substr(n * 2, 2), 16);
1915
- return t;
1916
- }
1917
- function yt(e) {
1918
- const t = e.length % 2 !== 0, n = t ? "0" + e : e, o = Ee(n), r = new Uint8Array(1 + o.length);
1919
- return r[0] = t ? 1 : 0, r.set(o, 1), r;
1920
- }
1921
- function te(e) {
1922
- const t = e[0];
1923
- if (t === 0 || t === 1) {
1924
- const o = t === 1, r = e.subarray(1), s = At(r), c = o ? s.substring(1) : s;
1925
- if (/^[0-9a-f]/.test(c))
1926
- return c;
1927
- }
1928
- const n = At(e);
1929
- return n.startsWith("0") && !n.startsWith("00") ? n.substring(1) : n;
1930
- }
1931
- export {
1932
- sr as a,
1933
- Ct as b,
1934
- Pn as c,
1935
- ur as d,
1936
- _e as e,
1937
- cr as g,
1938
- fr as p,
1939
- ar as s
1940
- };