@prosopo/procaptcha-bundle 2.6.12 → 3.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.
Files changed (117) hide show
  1. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/index.d.ts.map +1 -1
  2. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/index.js +3 -2
  3. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/index.js.map +1 -1
  4. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaComponentProvider.d.ts.map +1 -1
  5. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaComponentProvider.js +4 -0
  6. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaComponentProvider.js.map +1 -1
  7. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaComponentsList.d.ts +1 -1
  8. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaComponentsList.d.ts.map +1 -1
  9. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaRenderer.d.ts.map +1 -1
  10. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaRenderer.js +1 -1
  11. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaRenderer.js.map +1 -1
  12. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/configCreator.d.ts +1 -1
  13. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/configCreator.d.ts.map +1 -1
  14. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/configCreator.js +2 -2
  15. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/configCreator.js.map +1 -1
  16. package/CHANGELOG.md +141 -0
  17. package/dist/bundle/ProcaptchaWidget-BpzncYOb.js +612 -0
  18. package/dist/bundle/ProcaptchaWidget-D961oZ27.js +148 -0
  19. package/dist/bundle/bnChunk-DRlDxTFg.js +1137 -0
  20. package/dist/bundle/{browser-ponyfill-Bctlk3uB.js → browser-ponyfill-CvzSbL_o.js} +31 -30
  21. package/dist/bundle/builder-CQlqPNRd.js +37 -0
  22. package/dist/bundle/captchaComponentProvider-Dw6ydLe3.js +802 -0
  23. package/dist/bundle/{captchaRenderer-BAMErqQN.js → captchaRenderer-CY8KuZK-.js} +22 -22
  24. package/dist/bundle/commonChunk-24zMb_mF.js +189 -0
  25. package/dist/bundle/emotion-element-5486c51c.browser.esm-PRDDgd_k.js +918 -0
  26. package/dist/bundle/{fp.esm-DYWeNGcH.js → fp.esm-BADUiinQ.js} +548 -648
  27. package/dist/bundle/index-BRg_gWPo.js +1328 -0
  28. package/dist/bundle/{index-ByKGlSkE.js → index-BzOMq-ud.js} +2 -2
  29. package/dist/bundle/{index-1qH2dz7u.js → index-DqwVRCwA.js} +166 -199
  30. package/dist/bundle/index.d.ts.map +1 -1
  31. package/dist/bundle/locales/ar/translation.json +4 -3
  32. package/dist/bundle/locales/az/translation.json +4 -3
  33. package/dist/bundle/locales/cs/translation.json +4 -3
  34. package/dist/bundle/locales/de/translation.json +4 -3
  35. package/dist/bundle/locales/el/translation.json +4 -3
  36. package/dist/bundle/locales/en/translation.json +4 -3
  37. package/dist/bundle/locales/es/translation.json +4 -3
  38. package/dist/bundle/locales/fi/translation.json +4 -3
  39. package/dist/bundle/locales/fr/translation.json +4 -3
  40. package/dist/bundle/locales/hi/translation.json +4 -3
  41. package/dist/bundle/locales/hu/translation.json +4 -3
  42. package/dist/bundle/locales/id/translation.json +4 -3
  43. package/dist/bundle/locales/it/translation.json +4 -3
  44. package/dist/bundle/locales/ja/translation.json +4 -3
  45. package/dist/bundle/locales/jv/translation.json +4 -3
  46. package/dist/bundle/locales/ko/translation.json +4 -3
  47. package/dist/bundle/locales/ml/translation.json +4 -3
  48. package/dist/bundle/locales/ms/translation.json +4 -3
  49. package/dist/bundle/locales/nl/translation.json +4 -3
  50. package/dist/bundle/locales/no/translation.json +4 -3
  51. package/dist/bundle/locales/pl/translation.json +4 -3
  52. package/dist/bundle/locales/pt/translation.json +4 -3
  53. package/dist/bundle/locales/{pt-br → pt-BR}/translation.json +4 -3
  54. package/dist/bundle/locales/ro/translation.json +4 -3
  55. package/dist/bundle/locales/ru/translation.json +4 -3
  56. package/dist/bundle/locales/sr/translation.json +4 -3
  57. package/dist/bundle/locales/sv/translation.json +4 -3
  58. package/dist/bundle/locales/th/translation.json +4 -3
  59. package/dist/bundle/locales/tr/translation.json +4 -3
  60. package/dist/bundle/locales/uk/translation.json +4 -3
  61. package/dist/bundle/locales/vi/translation.json +4 -3
  62. package/dist/bundle/locales/{zh-cn → zh-CN}/translation.json +4 -3
  63. package/dist/bundle/nobleChunk-Xl5XLrx3.js +3635 -0
  64. package/dist/bundle/procaptcha.bundle.js +6 -5
  65. package/dist/bundle/util/captcha/captchaComponentProvider.d.ts.map +1 -1
  66. package/dist/bundle/util/captcha/captchaComponentsList.d.ts +1 -1
  67. package/dist/bundle/util/captcha/captchaComponentsList.d.ts.map +1 -1
  68. package/dist/bundle/util/captcha/captchaRenderer.d.ts.map +1 -1
  69. package/dist/bundle/util/configCreator.d.ts +1 -1
  70. package/dist/bundle/util/configCreator.d.ts.map +1 -1
  71. package/dist/bundle/utilChunk-sqstc6C5.js +317 -0
  72. package/dist/bundle/utilCryptoChunk-CIPUtfoO.js +1256 -0
  73. package/dist/bundle/web2Chunk-7Vd8yt2r.js +3711 -0
  74. package/dist/bundle/{hash-CrwduMDb.js → web3Chunk-DrUvbVNW.js} +257 -695
  75. package/dist/bundle/{translations-DEL070wJ.js → zodChunk-wTu9ZHzV.js} +46 -82
  76. package/dist/cjs/index.cjs +8 -2
  77. package/dist/cjs/util/captcha/captchaComponentProvider.cjs +4 -0
  78. package/dist/cjs/util/captcha/captchaRenderer.cjs +2 -1
  79. package/dist/cjs/util/configCreator.cjs +2 -2
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +3 -2
  82. package/dist/index.js.map +1 -1
  83. package/dist/util/captcha/captchaComponentProvider.d.ts +1 -1
  84. package/dist/util/captcha/captchaComponentProvider.d.ts.map +1 -1
  85. package/dist/util/captcha/captchaComponentProvider.js +4 -0
  86. package/dist/util/captcha/captchaComponentProvider.js.map +1 -1
  87. package/dist/util/captcha/captchaComponentsList.d.ts +1 -1
  88. package/dist/util/captcha/captchaComponentsList.d.ts.map +1 -1
  89. package/dist/util/captcha/captchaRenderer.d.ts.map +1 -1
  90. package/dist/util/captcha/captchaRenderer.js +1 -1
  91. package/dist/util/captcha/captchaRenderer.js.map +1 -1
  92. package/dist/util/configCreator.d.ts +1 -1
  93. package/dist/util/configCreator.d.ts.map +1 -1
  94. package/dist/util/configCreator.js +2 -2
  95. package/dist/util/configCreator.js.map +1 -1
  96. package/package.json +21 -14
  97. package/stats.html +1 -1
  98. package/vite.config.ts +47 -4
  99. package/vite.serve.config.ts +2 -0
  100. package/vite.test.config.ts +1 -1
  101. package/webpack.config.cjs +5 -0
  102. package/dist/bundle/ProcaptchaWidget-DPyDGPiI.js +0 -156
  103. package/dist/bundle/ProcaptchaWidget-DoqUlwHS.js +0 -636
  104. package/dist/bundle/_commonjsHelpers-DaMA6jEr.js +0 -8
  105. package/dist/bundle/asU8a-BixKX-w0.js +0 -9
  106. package/dist/bundle/bip39-D7YSihxf.js +0 -260
  107. package/dist/bundle/captchaComponentProvider-BL18T1UE.js +0 -1242
  108. package/dist/bundle/emotion-element-5486c51c.browser.esm-Bjt1gs1F.js +0 -1807
  109. package/dist/bundle/i18nFrontend-DCv3P9jv.js +0 -2273
  110. package/dist/bundle/index-BeN3et18.js +0 -4844
  111. package/dist/bundle/index-BjRdPnnE.js +0 -1198
  112. package/dist/bundle/index-CBquknc2.js +0 -81
  113. package/dist/bundle/index-QVME9Prx.js +0 -32
  114. package/dist/bundle/sha256-CGE_4eEY.js +0 -171
  115. package/dist/bundle/spread-DEmVz7RJ.js +0 -15
  116. package/dist/bundle/toU8a-CPMbkkSw.js +0 -109
  117. package/dist/bundle/useTranslation-BJsfZyOx.js +0 -158
@@ -1,4844 +0,0 @@
1
- var Jo = Object.defineProperty;
2
- var Fo = (t, e, r) => e in t ? Jo(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
- var Jt = (t, e, r) => Fo(t, typeof e != "symbol" ? e + "" : e, r);
4
- import { x as qi, s as ce, d as Qo, f as ts, H as es, n as se, u as Je, i as tr, b as er, e as Qn, t as rs, g as ns, o as is, h as os, r as j } from "./toU8a-CPMbkkSw.js";
5
- import { b as on, B as F, c as ke, d as fe, u as G, R as ss, e as fs, f as we, g as de, j as Vt, i as zt, s as as, k as cs, l as hs, m as ls, n as us, o as ds, p as ws, q as gs, r as ms, v as ps, t as ys, x as xs, y as vs, z as bs, A as Es, C as _s, D as Ms, E as As, F as Bs, G as Ss, H as Is, I as Us, J as ks, K as Ns, L as Rs, M as Ls, N as Os, O as Ts, P as Hs, Q as qs } from "./hash-CrwduMDb.js";
6
- import { g as $s } from "./_commonjsHelpers-DaMA6jEr.js";
7
- import { s as vn } from "./sha256-CGE_4eEY.js";
8
- import { h as Cs, s as Ds, m as Ps, v as Zs, a as ti, p as Vs, b as $i } from "./bip39-D7YSihxf.js";
9
- import { a as Ci } from "./asU8a-BixKX-w0.js";
10
- import { o as bn } from "./spread-DEmVz7RJ.js";
11
- import { n as Re } from "./emotion-element-5486c51c.browser.esm-Bjt1gs1F.js";
12
- const zs = { name: "@polkadot/util", path: import.meta && import.meta.url ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf("/") + 1) : "auto", type: "esm", version: "12.6.2" }, Gs = "POLKADOTJS_DISABLE_ESM_CJS_WARNING";
13
- function Ys(t) {
14
- const e = qi;
15
- return e.__polkadotjs || (e.__polkadotjs = {}), e.__polkadotjs[t] || (e.__polkadotjs[t] = []), e.__polkadotjs[t];
16
- }
17
- function Ws(t, e) {
18
- if (t)
19
- return t;
20
- if (on(e))
21
- try {
22
- return e() || "";
23
- } catch {
24
- return "";
25
- }
26
- return e || "";
27
- }
28
- function Xs({ name: t, path: e, type: r, version: i }, a, o = []) {
29
- var E, M;
30
- if (!t.startsWith("@polkadot"))
31
- throw new Error(`Invalid package descriptor ${t}`);
32
- const l = Ys(t);
33
- l.push({ path: Ws(e, a), type: r, version: i });
34
- const u = l.every((S) => S.version === i), m = ((M = (E = qi.process) == null ? void 0 : E.env) == null ? void 0 : M[Gs]) === "1";
35
- l.length !== 1 && !(m && u) || o.filter((S) => S && S.version !== i);
36
- }
37
- const rr = /* @__PURE__ */ F(0), nr = /* @__PURE__ */ F(1);
38
- Number.MAX_SAFE_INTEGER;
39
- const ei = F(256), ri = F(256 * 256), Ks = F("0x10000000000000000");
40
- function sn(t, { isLe: e = !0, isNegative: r = !1 } = {}) {
41
- e || (t = t.slice().reverse());
42
- const i = t.length;
43
- if (r && i && t[i - 1] & 128) {
44
- switch (i) {
45
- case 0:
46
- return F(0);
47
- case 1:
48
- return F((t[0] ^ 255) * -1 - 1);
49
- case 2:
50
- return F((t[0] + (t[1] << 8) ^ 65535) * -1 - 1);
51
- case 4:
52
- return F((t[0] + (t[1] << 8) + (t[2] << 16) + t[3] * 16777216 ^ 4294967295) * -1 - 1);
53
- }
54
- const o = new DataView(t.buffer, t.byteOffset);
55
- if (i === 8)
56
- return o.getBigInt64(0, !0);
57
- let l = F(0);
58
- const u = i % 2;
59
- for (let m = i - 2; m >= u; m -= 2)
60
- l = l * ri + F(o.getUint16(m, !0) ^ 65535);
61
- return u && (l = l * ei + F(t[0] ^ 255)), l * -nr - nr;
62
- }
63
- switch (i) {
64
- case 0:
65
- return F(0);
66
- case 1:
67
- return F(t[0]);
68
- case 2:
69
- return F(t[0] + (t[1] << 8));
70
- case 4:
71
- return F(t[0] + (t[1] << 8) + (t[2] << 16) + t[3] * 16777216);
72
- }
73
- const a = new DataView(t.buffer, t.byteOffset);
74
- switch (i) {
75
- case 8:
76
- return a.getBigUint64(0, !0);
77
- case 16:
78
- return a.getBigUint64(8, !0) * Ks + a.getBigUint64(0, !0);
79
- default: {
80
- let o = F(0);
81
- const l = i % 2;
82
- for (let u = i - 2; u >= l; u -= 2)
83
- o = o * ri + F(a.getUint16(u, !0));
84
- return l && (o = o * ei + F(t[0])), o;
85
- }
86
- }
87
- }
88
- function js(t, { isLe: e = !1, isNegative: r = !1 } = {}) {
89
- return !t || t === "0x" ? F(0) : sn(ke(t), { isLe: e, isNegative: r });
90
- }
91
- var En = { exports: {} }, Js = En.exports;
92
- (function(t) {
93
- (function(e, r) {
94
- function i(y, n) {
95
- if (!y) throw new Error(n || "Assertion failed");
96
- }
97
- function a(y, n) {
98
- y.super_ = n;
99
- var f = function() {
100
- };
101
- f.prototype = n.prototype, y.prototype = new f(), y.prototype.constructor = y;
102
- }
103
- function o(y, n, f) {
104
- if (o.isBN(y))
105
- return y;
106
- this.negative = 0, this.words = null, this.length = 0, this.red = null, y !== null && ((n === "le" || n === "be") && (f = n, n = 10), this._init(y || 0, n || 10, f || "be"));
107
- }
108
- typeof e == "object" ? e.exports = o : r.BN = o, o.BN = o, o.wordSize = 26;
109
- var l;
110
- try {
111
- typeof window < "u" && typeof window.Buffer < "u" ? l = window.Buffer : l = require("buffer").Buffer;
112
- } catch {
113
- }
114
- o.isBN = function(n) {
115
- return n instanceof o ? !0 : n !== null && typeof n == "object" && n.constructor.wordSize === o.wordSize && Array.isArray(n.words);
116
- }, o.max = function(n, f) {
117
- return n.cmp(f) > 0 ? n : f;
118
- }, o.min = function(n, f) {
119
- return n.cmp(f) < 0 ? n : f;
120
- }, o.prototype._init = function(n, f, c) {
121
- if (typeof n == "number")
122
- return this._initNumber(n, f, c);
123
- if (typeof n == "object")
124
- return this._initArray(n, f, c);
125
- f === "hex" && (f = 16), i(f === (f | 0) && f >= 2 && f <= 36), n = n.toString().replace(/\s+/g, "");
126
- var g = 0;
127
- n[0] === "-" && (g++, this.negative = 1), g < n.length && (f === 16 ? this._parseHex(n, g, c) : (this._parseBase(n, f, g), c === "le" && this._initArray(this.toArray(), f, c)));
128
- }, o.prototype._initNumber = function(n, f, c) {
129
- n < 0 && (this.negative = 1, n = -n), n < 67108864 ? (this.words = [n & 67108863], this.length = 1) : n < 4503599627370496 ? (this.words = [
130
- n & 67108863,
131
- n / 67108864 & 67108863
132
- ], this.length = 2) : (i(n < 9007199254740992), this.words = [
133
- n & 67108863,
134
- n / 67108864 & 67108863,
135
- 1
136
- ], this.length = 3), c === "le" && this._initArray(this.toArray(), f, c);
137
- }, o.prototype._initArray = function(n, f, c) {
138
- if (i(typeof n.length == "number"), n.length <= 0)
139
- return this.words = [0], this.length = 1, this;
140
- this.length = Math.ceil(n.length / 3), this.words = new Array(this.length);
141
- for (var g = 0; g < this.length; g++)
142
- this.words[g] = 0;
143
- var d, w, x = 0;
144
- if (c === "be")
145
- for (g = n.length - 1, d = 0; g >= 0; g -= 3)
146
- w = n[g] | n[g - 1] << 8 | n[g - 2] << 16, this.words[d] |= w << x & 67108863, this.words[d + 1] = w >>> 26 - x & 67108863, x += 24, x >= 26 && (x -= 26, d++);
147
- else if (c === "le")
148
- for (g = 0, d = 0; g < n.length; g += 3)
149
- w = n[g] | n[g + 1] << 8 | n[g + 2] << 16, this.words[d] |= w << x & 67108863, this.words[d + 1] = w >>> 26 - x & 67108863, x += 24, x >= 26 && (x -= 26, d++);
150
- return this._strip();
151
- };
152
- function u(y, n) {
153
- var f = y.charCodeAt(n);
154
- if (f >= 48 && f <= 57)
155
- return f - 48;
156
- if (f >= 65 && f <= 70)
157
- return f - 55;
158
- if (f >= 97 && f <= 102)
159
- return f - 87;
160
- i(!1, "Invalid character in " + y);
161
- }
162
- function m(y, n, f) {
163
- var c = u(y, f);
164
- return f - 1 >= n && (c |= u(y, f - 1) << 4), c;
165
- }
166
- o.prototype._parseHex = function(n, f, c) {
167
- this.length = Math.ceil((n.length - f) / 6), this.words = new Array(this.length);
168
- for (var g = 0; g < this.length; g++)
169
- this.words[g] = 0;
170
- var d = 0, w = 0, x;
171
- if (c === "be")
172
- for (g = n.length - 1; g >= f; g -= 2)
173
- x = m(n, f, g) << d, this.words[w] |= x & 67108863, d >= 18 ? (d -= 18, w += 1, this.words[w] |= x >>> 26) : d += 8;
174
- else {
175
- var h = n.length - f;
176
- for (g = h % 2 === 0 ? f + 1 : f; g < n.length; g += 2)
177
- x = m(n, f, g) << d, this.words[w] |= x & 67108863, d >= 18 ? (d -= 18, w += 1, this.words[w] |= x >>> 26) : d += 8;
178
- }
179
- this._strip();
180
- };
181
- function b(y, n, f, c) {
182
- for (var g = 0, d = 0, w = Math.min(y.length, f), x = n; x < w; x++) {
183
- var h = y.charCodeAt(x) - 48;
184
- g *= c, h >= 49 ? d = h - 49 + 10 : h >= 17 ? d = h - 17 + 10 : d = h, i(h >= 0 && d < c, "Invalid character"), g += d;
185
- }
186
- return g;
187
- }
188
- o.prototype._parseBase = function(n, f, c) {
189
- this.words = [0], this.length = 1;
190
- for (var g = 0, d = 1; d <= 67108863; d *= f)
191
- g++;
192
- g--, d = d / f | 0;
193
- for (var w = n.length - c, x = w % g, h = Math.min(w, w - x) + c, s = 0, p = c; p < h; p += g)
194
- s = b(n, p, p + g, f), this.imuln(d), this.words[0] + s < 67108864 ? this.words[0] += s : this._iaddn(s);
195
- if (x !== 0) {
196
- var k = 1;
197
- for (s = b(n, p, n.length, f), p = 0; p < x; p++)
198
- k *= f;
199
- this.imuln(k), this.words[0] + s < 67108864 ? this.words[0] += s : this._iaddn(s);
200
- }
201
- this._strip();
202
- }, o.prototype.copy = function(n) {
203
- n.words = new Array(this.length);
204
- for (var f = 0; f < this.length; f++)
205
- n.words[f] = this.words[f];
206
- n.length = this.length, n.negative = this.negative, n.red = this.red;
207
- };
208
- function v(y, n) {
209
- y.words = n.words, y.length = n.length, y.negative = n.negative, y.red = n.red;
210
- }
211
- if (o.prototype._move = function(n) {
212
- v(n, this);
213
- }, o.prototype.clone = function() {
214
- var n = new o(null);
215
- return this.copy(n), n;
216
- }, o.prototype._expand = function(n) {
217
- for (; this.length < n; )
218
- this.words[this.length++] = 0;
219
- return this;
220
- }, o.prototype._strip = function() {
221
- for (; this.length > 1 && this.words[this.length - 1] === 0; )
222
- this.length--;
223
- return this._normSign();
224
- }, o.prototype._normSign = function() {
225
- return this.length === 1 && this.words[0] === 0 && (this.negative = 0), this;
226
- }, typeof Symbol < "u" && typeof Symbol.for == "function")
227
- try {
228
- o.prototype[Symbol.for("nodejs.util.inspect.custom")] = E;
229
- } catch {
230
- o.prototype.inspect = E;
231
- }
232
- else
233
- o.prototype.inspect = E;
234
- function E() {
235
- return (this.red ? "<BN-R: " : "<BN: ") + this.toString(16) + ">";
236
- }
237
- var M = [
238
- "",
239
- "0",
240
- "00",
241
- "000",
242
- "0000",
243
- "00000",
244
- "000000",
245
- "0000000",
246
- "00000000",
247
- "000000000",
248
- "0000000000",
249
- "00000000000",
250
- "000000000000",
251
- "0000000000000",
252
- "00000000000000",
253
- "000000000000000",
254
- "0000000000000000",
255
- "00000000000000000",
256
- "000000000000000000",
257
- "0000000000000000000",
258
- "00000000000000000000",
259
- "000000000000000000000",
260
- "0000000000000000000000",
261
- "00000000000000000000000",
262
- "000000000000000000000000",
263
- "0000000000000000000000000"
264
- ], S = [
265
- 0,
266
- 0,
267
- 25,
268
- 16,
269
- 12,
270
- 11,
271
- 10,
272
- 9,
273
- 8,
274
- 8,
275
- 7,
276
- 7,
277
- 7,
278
- 7,
279
- 6,
280
- 6,
281
- 6,
282
- 6,
283
- 6,
284
- 6,
285
- 6,
286
- 5,
287
- 5,
288
- 5,
289
- 5,
290
- 5,
291
- 5,
292
- 5,
293
- 5,
294
- 5,
295
- 5,
296
- 5,
297
- 5,
298
- 5,
299
- 5,
300
- 5,
301
- 5
302
- ], O = [
303
- 0,
304
- 0,
305
- 33554432,
306
- 43046721,
307
- 16777216,
308
- 48828125,
309
- 60466176,
310
- 40353607,
311
- 16777216,
312
- 43046721,
313
- 1e7,
314
- 19487171,
315
- 35831808,
316
- 62748517,
317
- 7529536,
318
- 11390625,
319
- 16777216,
320
- 24137569,
321
- 34012224,
322
- 47045881,
323
- 64e6,
324
- 4084101,
325
- 5153632,
326
- 6436343,
327
- 7962624,
328
- 9765625,
329
- 11881376,
330
- 14348907,
331
- 17210368,
332
- 20511149,
333
- 243e5,
334
- 28629151,
335
- 33554432,
336
- 39135393,
337
- 45435424,
338
- 52521875,
339
- 60466176
340
- ];
341
- o.prototype.toString = function(n, f) {
342
- n = n || 10, f = f | 0 || 1;
343
- var c;
344
- if (n === 16 || n === "hex") {
345
- c = "";
346
- for (var g = 0, d = 0, w = 0; w < this.length; w++) {
347
- var x = this.words[w], h = ((x << g | d) & 16777215).toString(16);
348
- d = x >>> 24 - g & 16777215, g += 2, g >= 26 && (g -= 26, w--), d !== 0 || w !== this.length - 1 ? c = M[6 - h.length] + h + c : c = h + c;
349
- }
350
- for (d !== 0 && (c = d.toString(16) + c); c.length % f !== 0; )
351
- c = "0" + c;
352
- return this.negative !== 0 && (c = "-" + c), c;
353
- }
354
- if (n === (n | 0) && n >= 2 && n <= 36) {
355
- var s = S[n], p = O[n];
356
- c = "";
357
- var k = this.clone();
358
- for (k.negative = 0; !k.isZero(); ) {
359
- var I = k.modrn(p).toString(n);
360
- k = k.idivn(p), k.isZero() ? c = I + c : c = M[s - I.length] + I + c;
361
- }
362
- for (this.isZero() && (c = "0" + c); c.length % f !== 0; )
363
- c = "0" + c;
364
- return this.negative !== 0 && (c = "-" + c), c;
365
- }
366
- i(!1, "Base should be between 2 and 36");
367
- }, o.prototype.toNumber = function() {
368
- var n = this.words[0];
369
- return this.length === 2 ? n += this.words[1] * 67108864 : this.length === 3 && this.words[2] === 1 ? n += 4503599627370496 + this.words[1] * 67108864 : this.length > 2 && i(!1, "Number can only safely store up to 53 bits"), this.negative !== 0 ? -n : n;
370
- }, o.prototype.toJSON = function() {
371
- return this.toString(16, 2);
372
- }, l && (o.prototype.toBuffer = function(n, f) {
373
- return this.toArrayLike(l, n, f);
374
- }), o.prototype.toArray = function(n, f) {
375
- return this.toArrayLike(Array, n, f);
376
- };
377
- var A = function(n, f) {
378
- return n.allocUnsafe ? n.allocUnsafe(f) : new n(f);
379
- };
380
- o.prototype.toArrayLike = function(n, f, c) {
381
- this._strip();
382
- var g = this.byteLength(), d = c || Math.max(1, g);
383
- i(g <= d, "byte array longer than desired length"), i(d > 0, "Requested array length <= 0");
384
- var w = A(n, d), x = f === "le" ? "LE" : "BE";
385
- return this["_toArrayLike" + x](w, g), w;
386
- }, o.prototype._toArrayLikeLE = function(n, f) {
387
- for (var c = 0, g = 0, d = 0, w = 0; d < this.length; d++) {
388
- var x = this.words[d] << w | g;
389
- n[c++] = x & 255, c < n.length && (n[c++] = x >> 8 & 255), c < n.length && (n[c++] = x >> 16 & 255), w === 6 ? (c < n.length && (n[c++] = x >> 24 & 255), g = 0, w = 0) : (g = x >>> 24, w += 2);
390
- }
391
- if (c < n.length)
392
- for (n[c++] = g; c < n.length; )
393
- n[c++] = 0;
394
- }, o.prototype._toArrayLikeBE = function(n, f) {
395
- for (var c = n.length - 1, g = 0, d = 0, w = 0; d < this.length; d++) {
396
- var x = this.words[d] << w | g;
397
- n[c--] = x & 255, c >= 0 && (n[c--] = x >> 8 & 255), c >= 0 && (n[c--] = x >> 16 & 255), w === 6 ? (c >= 0 && (n[c--] = x >> 24 & 255), g = 0, w = 0) : (g = x >>> 24, w += 2);
398
- }
399
- if (c >= 0)
400
- for (n[c--] = g; c >= 0; )
401
- n[c--] = 0;
402
- }, Math.clz32 ? o.prototype._countBits = function(n) {
403
- return 32 - Math.clz32(n);
404
- } : o.prototype._countBits = function(n) {
405
- var f = n, c = 0;
406
- return f >= 4096 && (c += 13, f >>>= 13), f >= 64 && (c += 7, f >>>= 7), f >= 8 && (c += 4, f >>>= 4), f >= 2 && (c += 2, f >>>= 2), c + f;
407
- }, o.prototype._zeroBits = function(n) {
408
- if (n === 0) return 26;
409
- var f = n, c = 0;
410
- return (f & 8191) === 0 && (c += 13, f >>>= 13), (f & 127) === 0 && (c += 7, f >>>= 7), (f & 15) === 0 && (c += 4, f >>>= 4), (f & 3) === 0 && (c += 2, f >>>= 2), (f & 1) === 0 && c++, c;
411
- }, o.prototype.bitLength = function() {
412
- var n = this.words[this.length - 1], f = this._countBits(n);
413
- return (this.length - 1) * 26 + f;
414
- };
415
- function D(y) {
416
- for (var n = new Array(y.bitLength()), f = 0; f < n.length; f++) {
417
- var c = f / 26 | 0, g = f % 26;
418
- n[f] = y.words[c] >>> g & 1;
419
- }
420
- return n;
421
- }
422
- o.prototype.zeroBits = function() {
423
- if (this.isZero()) return 0;
424
- for (var n = 0, f = 0; f < this.length; f++) {
425
- var c = this._zeroBits(this.words[f]);
426
- if (n += c, c !== 26) break;
427
- }
428
- return n;
429
- }, o.prototype.byteLength = function() {
430
- return Math.ceil(this.bitLength() / 8);
431
- }, o.prototype.toTwos = function(n) {
432
- return this.negative !== 0 ? this.abs().inotn(n).iaddn(1) : this.clone();
433
- }, o.prototype.fromTwos = function(n) {
434
- return this.testn(n - 1) ? this.notn(n).iaddn(1).ineg() : this.clone();
435
- }, o.prototype.isNeg = function() {
436
- return this.negative !== 0;
437
- }, o.prototype.neg = function() {
438
- return this.clone().ineg();
439
- }, o.prototype.ineg = function() {
440
- return this.isZero() || (this.negative ^= 1), this;
441
- }, o.prototype.iuor = function(n) {
442
- for (; this.length < n.length; )
443
- this.words[this.length++] = 0;
444
- for (var f = 0; f < n.length; f++)
445
- this.words[f] = this.words[f] | n.words[f];
446
- return this._strip();
447
- }, o.prototype.ior = function(n) {
448
- return i((this.negative | n.negative) === 0), this.iuor(n);
449
- }, o.prototype.or = function(n) {
450
- return this.length > n.length ? this.clone().ior(n) : n.clone().ior(this);
451
- }, o.prototype.uor = function(n) {
452
- return this.length > n.length ? this.clone().iuor(n) : n.clone().iuor(this);
453
- }, o.prototype.iuand = function(n) {
454
- var f;
455
- this.length > n.length ? f = n : f = this;
456
- for (var c = 0; c < f.length; c++)
457
- this.words[c] = this.words[c] & n.words[c];
458
- return this.length = f.length, this._strip();
459
- }, o.prototype.iand = function(n) {
460
- return i((this.negative | n.negative) === 0), this.iuand(n);
461
- }, o.prototype.and = function(n) {
462
- return this.length > n.length ? this.clone().iand(n) : n.clone().iand(this);
463
- }, o.prototype.uand = function(n) {
464
- return this.length > n.length ? this.clone().iuand(n) : n.clone().iuand(this);
465
- }, o.prototype.iuxor = function(n) {
466
- var f, c;
467
- this.length > n.length ? (f = this, c = n) : (f = n, c = this);
468
- for (var g = 0; g < c.length; g++)
469
- this.words[g] = f.words[g] ^ c.words[g];
470
- if (this !== f)
471
- for (; g < f.length; g++)
472
- this.words[g] = f.words[g];
473
- return this.length = f.length, this._strip();
474
- }, o.prototype.ixor = function(n) {
475
- return i((this.negative | n.negative) === 0), this.iuxor(n);
476
- }, o.prototype.xor = function(n) {
477
- return this.length > n.length ? this.clone().ixor(n) : n.clone().ixor(this);
478
- }, o.prototype.uxor = function(n) {
479
- return this.length > n.length ? this.clone().iuxor(n) : n.clone().iuxor(this);
480
- }, o.prototype.inotn = function(n) {
481
- i(typeof n == "number" && n >= 0);
482
- var f = Math.ceil(n / 26) | 0, c = n % 26;
483
- this._expand(f), c > 0 && f--;
484
- for (var g = 0; g < f; g++)
485
- this.words[g] = ~this.words[g] & 67108863;
486
- return c > 0 && (this.words[g] = ~this.words[g] & 67108863 >> 26 - c), this._strip();
487
- }, o.prototype.notn = function(n) {
488
- return this.clone().inotn(n);
489
- }, o.prototype.setn = function(n, f) {
490
- i(typeof n == "number" && n >= 0);
491
- var c = n / 26 | 0, g = n % 26;
492
- return this._expand(c + 1), f ? this.words[c] = this.words[c] | 1 << g : this.words[c] = this.words[c] & ~(1 << g), this._strip();
493
- }, o.prototype.iadd = function(n) {
494
- var f;
495
- if (this.negative !== 0 && n.negative === 0)
496
- return this.negative = 0, f = this.isub(n), this.negative ^= 1, this._normSign();
497
- if (this.negative === 0 && n.negative !== 0)
498
- return n.negative = 0, f = this.isub(n), n.negative = 1, f._normSign();
499
- var c, g;
500
- this.length > n.length ? (c = this, g = n) : (c = n, g = this);
501
- for (var d = 0, w = 0; w < g.length; w++)
502
- f = (c.words[w] | 0) + (g.words[w] | 0) + d, this.words[w] = f & 67108863, d = f >>> 26;
503
- for (; d !== 0 && w < c.length; w++)
504
- f = (c.words[w] | 0) + d, this.words[w] = f & 67108863, d = f >>> 26;
505
- if (this.length = c.length, d !== 0)
506
- this.words[this.length] = d, this.length++;
507
- else if (c !== this)
508
- for (; w < c.length; w++)
509
- this.words[w] = c.words[w];
510
- return this;
511
- }, o.prototype.add = function(n) {
512
- var f;
513
- return n.negative !== 0 && this.negative === 0 ? (n.negative = 0, f = this.sub(n), n.negative ^= 1, f) : n.negative === 0 && this.negative !== 0 ? (this.negative = 0, f = n.sub(this), this.negative = 1, f) : this.length > n.length ? this.clone().iadd(n) : n.clone().iadd(this);
514
- }, o.prototype.isub = function(n) {
515
- if (n.negative !== 0) {
516
- n.negative = 0;
517
- var f = this.iadd(n);
518
- return n.negative = 1, f._normSign();
519
- } else if (this.negative !== 0)
520
- return this.negative = 0, this.iadd(n), this.negative = 1, this._normSign();
521
- var c = this.cmp(n);
522
- if (c === 0)
523
- return this.negative = 0, this.length = 1, this.words[0] = 0, this;
524
- var g, d;
525
- c > 0 ? (g = this, d = n) : (g = n, d = this);
526
- for (var w = 0, x = 0; x < d.length; x++)
527
- f = (g.words[x] | 0) - (d.words[x] | 0) + w, w = f >> 26, this.words[x] = f & 67108863;
528
- for (; w !== 0 && x < g.length; x++)
529
- f = (g.words[x] | 0) + w, w = f >> 26, this.words[x] = f & 67108863;
530
- if (w === 0 && x < g.length && g !== this)
531
- for (; x < g.length; x++)
532
- this.words[x] = g.words[x];
533
- return this.length = Math.max(this.length, x), g !== this && (this.negative = 1), this._strip();
534
- }, o.prototype.sub = function(n) {
535
- return this.clone().isub(n);
536
- };
537
- function V(y, n, f) {
538
- f.negative = n.negative ^ y.negative;
539
- var c = y.length + n.length | 0;
540
- f.length = c, c = c - 1 | 0;
541
- var g = y.words[0] | 0, d = n.words[0] | 0, w = g * d, x = w & 67108863, h = w / 67108864 | 0;
542
- f.words[0] = x;
543
- for (var s = 1; s < c; s++) {
544
- for (var p = h >>> 26, k = h & 67108863, I = Math.min(s, n.length - 1), N = Math.max(0, s - y.length + 1); N <= I; N++) {
545
- var P = s - N | 0;
546
- g = y.words[P] | 0, d = n.words[N] | 0, w = g * d + k, p += w / 67108864 | 0, k = w & 67108863;
547
- }
548
- f.words[s] = k | 0, h = p | 0;
549
- }
550
- return h !== 0 ? f.words[s] = h | 0 : f.length--, f._strip();
551
- }
552
- var Q = function(n, f, c) {
553
- var g = n.words, d = f.words, w = c.words, x = 0, h, s, p, k = g[0] | 0, I = k & 8191, N = k >>> 13, P = g[1] | 0, Z = P & 8191, z = P >>> 13, ft = g[2] | 0, W = ft & 8191, Y = ft >>> 13, Ht = g[3] | 0, K = Ht & 8191, J = Ht >>> 13, Yt = g[4] | 0, et = Yt & 8191, rt = Yt >>> 13, ze = g[5] | 0, nt = ze & 8191, it = ze >>> 13, Cn = g[6] | 0, at = Cn & 8191, ct = Cn >>> 13, Dn = g[7] | 0, ht = Dn & 8191, lt = Dn >>> 13, Pn = g[8] | 0, ut = Pn & 8191, dt = Pn >>> 13, Zn = g[9] | 0, wt = Zn & 8191, gt = Zn >>> 13, Vn = d[0] | 0, mt = Vn & 8191, pt = Vn >>> 13, zn = d[1] | 0, yt = zn & 8191, xt = zn >>> 13, Gn = d[2] | 0, vt = Gn & 8191, bt = Gn >>> 13, Yn = d[3] | 0, Et = Yn & 8191, _t = Yn >>> 13, Wn = d[4] | 0, Mt = Wn & 8191, At = Wn >>> 13, Xn = d[5] | 0, Bt = Xn & 8191, St = Xn >>> 13, Kn = d[6] | 0, It = Kn & 8191, Ut = Kn >>> 13, jn = d[7] | 0, kt = jn & 8191, Nt = jn >>> 13, Jn = d[8] | 0, Rt = Jn & 8191, Lt = Jn >>> 13, Fn = d[9] | 0, Ot = Fn & 8191, Tt = Fn >>> 13;
554
- c.negative = n.negative ^ f.negative, c.length = 19, h = Math.imul(I, mt), s = Math.imul(I, pt), s = s + Math.imul(N, mt) | 0, p = Math.imul(N, pt);
555
- var yr = (x + h | 0) + ((s & 8191) << 13) | 0;
556
- x = (p + (s >>> 13) | 0) + (yr >>> 26) | 0, yr &= 67108863, h = Math.imul(Z, mt), s = Math.imul(Z, pt), s = s + Math.imul(z, mt) | 0, p = Math.imul(z, pt), h = h + Math.imul(I, yt) | 0, s = s + Math.imul(I, xt) | 0, s = s + Math.imul(N, yt) | 0, p = p + Math.imul(N, xt) | 0;
557
- var xr = (x + h | 0) + ((s & 8191) << 13) | 0;
558
- x = (p + (s >>> 13) | 0) + (xr >>> 26) | 0, xr &= 67108863, h = Math.imul(W, mt), s = Math.imul(W, pt), s = s + Math.imul(Y, mt) | 0, p = Math.imul(Y, pt), h = h + Math.imul(Z, yt) | 0, s = s + Math.imul(Z, xt) | 0, s = s + Math.imul(z, yt) | 0, p = p + Math.imul(z, xt) | 0, h = h + Math.imul(I, vt) | 0, s = s + Math.imul(I, bt) | 0, s = s + Math.imul(N, vt) | 0, p = p + Math.imul(N, bt) | 0;
559
- var vr = (x + h | 0) + ((s & 8191) << 13) | 0;
560
- x = (p + (s >>> 13) | 0) + (vr >>> 26) | 0, vr &= 67108863, h = Math.imul(K, mt), s = Math.imul(K, pt), s = s + Math.imul(J, mt) | 0, p = Math.imul(J, pt), h = h + Math.imul(W, yt) | 0, s = s + Math.imul(W, xt) | 0, s = s + Math.imul(Y, yt) | 0, p = p + Math.imul(Y, xt) | 0, h = h + Math.imul(Z, vt) | 0, s = s + Math.imul(Z, bt) | 0, s = s + Math.imul(z, vt) | 0, p = p + Math.imul(z, bt) | 0, h = h + Math.imul(I, Et) | 0, s = s + Math.imul(I, _t) | 0, s = s + Math.imul(N, Et) | 0, p = p + Math.imul(N, _t) | 0;
561
- var br = (x + h | 0) + ((s & 8191) << 13) | 0;
562
- x = (p + (s >>> 13) | 0) + (br >>> 26) | 0, br &= 67108863, h = Math.imul(et, mt), s = Math.imul(et, pt), s = s + Math.imul(rt, mt) | 0, p = Math.imul(rt, pt), h = h + Math.imul(K, yt) | 0, s = s + Math.imul(K, xt) | 0, s = s + Math.imul(J, yt) | 0, p = p + Math.imul(J, xt) | 0, h = h + Math.imul(W, vt) | 0, s = s + Math.imul(W, bt) | 0, s = s + Math.imul(Y, vt) | 0, p = p + Math.imul(Y, bt) | 0, h = h + Math.imul(Z, Et) | 0, s = s + Math.imul(Z, _t) | 0, s = s + Math.imul(z, Et) | 0, p = p + Math.imul(z, _t) | 0, h = h + Math.imul(I, Mt) | 0, s = s + Math.imul(I, At) | 0, s = s + Math.imul(N, Mt) | 0, p = p + Math.imul(N, At) | 0;
563
- var Er = (x + h | 0) + ((s & 8191) << 13) | 0;
564
- x = (p + (s >>> 13) | 0) + (Er >>> 26) | 0, Er &= 67108863, h = Math.imul(nt, mt), s = Math.imul(nt, pt), s = s + Math.imul(it, mt) | 0, p = Math.imul(it, pt), h = h + Math.imul(et, yt) | 0, s = s + Math.imul(et, xt) | 0, s = s + Math.imul(rt, yt) | 0, p = p + Math.imul(rt, xt) | 0, h = h + Math.imul(K, vt) | 0, s = s + Math.imul(K, bt) | 0, s = s + Math.imul(J, vt) | 0, p = p + Math.imul(J, bt) | 0, h = h + Math.imul(W, Et) | 0, s = s + Math.imul(W, _t) | 0, s = s + Math.imul(Y, Et) | 0, p = p + Math.imul(Y, _t) | 0, h = h + Math.imul(Z, Mt) | 0, s = s + Math.imul(Z, At) | 0, s = s + Math.imul(z, Mt) | 0, p = p + Math.imul(z, At) | 0, h = h + Math.imul(I, Bt) | 0, s = s + Math.imul(I, St) | 0, s = s + Math.imul(N, Bt) | 0, p = p + Math.imul(N, St) | 0;
565
- var _r = (x + h | 0) + ((s & 8191) << 13) | 0;
566
- x = (p + (s >>> 13) | 0) + (_r >>> 26) | 0, _r &= 67108863, h = Math.imul(at, mt), s = Math.imul(at, pt), s = s + Math.imul(ct, mt) | 0, p = Math.imul(ct, pt), h = h + Math.imul(nt, yt) | 0, s = s + Math.imul(nt, xt) | 0, s = s + Math.imul(it, yt) | 0, p = p + Math.imul(it, xt) | 0, h = h + Math.imul(et, vt) | 0, s = s + Math.imul(et, bt) | 0, s = s + Math.imul(rt, vt) | 0, p = p + Math.imul(rt, bt) | 0, h = h + Math.imul(K, Et) | 0, s = s + Math.imul(K, _t) | 0, s = s + Math.imul(J, Et) | 0, p = p + Math.imul(J, _t) | 0, h = h + Math.imul(W, Mt) | 0, s = s + Math.imul(W, At) | 0, s = s + Math.imul(Y, Mt) | 0, p = p + Math.imul(Y, At) | 0, h = h + Math.imul(Z, Bt) | 0, s = s + Math.imul(Z, St) | 0, s = s + Math.imul(z, Bt) | 0, p = p + Math.imul(z, St) | 0, h = h + Math.imul(I, It) | 0, s = s + Math.imul(I, Ut) | 0, s = s + Math.imul(N, It) | 0, p = p + Math.imul(N, Ut) | 0;
567
- var Mr = (x + h | 0) + ((s & 8191) << 13) | 0;
568
- x = (p + (s >>> 13) | 0) + (Mr >>> 26) | 0, Mr &= 67108863, h = Math.imul(ht, mt), s = Math.imul(ht, pt), s = s + Math.imul(lt, mt) | 0, p = Math.imul(lt, pt), h = h + Math.imul(at, yt) | 0, s = s + Math.imul(at, xt) | 0, s = s + Math.imul(ct, yt) | 0, p = p + Math.imul(ct, xt) | 0, h = h + Math.imul(nt, vt) | 0, s = s + Math.imul(nt, bt) | 0, s = s + Math.imul(it, vt) | 0, p = p + Math.imul(it, bt) | 0, h = h + Math.imul(et, Et) | 0, s = s + Math.imul(et, _t) | 0, s = s + Math.imul(rt, Et) | 0, p = p + Math.imul(rt, _t) | 0, h = h + Math.imul(K, Mt) | 0, s = s + Math.imul(K, At) | 0, s = s + Math.imul(J, Mt) | 0, p = p + Math.imul(J, At) | 0, h = h + Math.imul(W, Bt) | 0, s = s + Math.imul(W, St) | 0, s = s + Math.imul(Y, Bt) | 0, p = p + Math.imul(Y, St) | 0, h = h + Math.imul(Z, It) | 0, s = s + Math.imul(Z, Ut) | 0, s = s + Math.imul(z, It) | 0, p = p + Math.imul(z, Ut) | 0, h = h + Math.imul(I, kt) | 0, s = s + Math.imul(I, Nt) | 0, s = s + Math.imul(N, kt) | 0, p = p + Math.imul(N, Nt) | 0;
569
- var Ar = (x + h | 0) + ((s & 8191) << 13) | 0;
570
- x = (p + (s >>> 13) | 0) + (Ar >>> 26) | 0, Ar &= 67108863, h = Math.imul(ut, mt), s = Math.imul(ut, pt), s = s + Math.imul(dt, mt) | 0, p = Math.imul(dt, pt), h = h + Math.imul(ht, yt) | 0, s = s + Math.imul(ht, xt) | 0, s = s + Math.imul(lt, yt) | 0, p = p + Math.imul(lt, xt) | 0, h = h + Math.imul(at, vt) | 0, s = s + Math.imul(at, bt) | 0, s = s + Math.imul(ct, vt) | 0, p = p + Math.imul(ct, bt) | 0, h = h + Math.imul(nt, Et) | 0, s = s + Math.imul(nt, _t) | 0, s = s + Math.imul(it, Et) | 0, p = p + Math.imul(it, _t) | 0, h = h + Math.imul(et, Mt) | 0, s = s + Math.imul(et, At) | 0, s = s + Math.imul(rt, Mt) | 0, p = p + Math.imul(rt, At) | 0, h = h + Math.imul(K, Bt) | 0, s = s + Math.imul(K, St) | 0, s = s + Math.imul(J, Bt) | 0, p = p + Math.imul(J, St) | 0, h = h + Math.imul(W, It) | 0, s = s + Math.imul(W, Ut) | 0, s = s + Math.imul(Y, It) | 0, p = p + Math.imul(Y, Ut) | 0, h = h + Math.imul(Z, kt) | 0, s = s + Math.imul(Z, Nt) | 0, s = s + Math.imul(z, kt) | 0, p = p + Math.imul(z, Nt) | 0, h = h + Math.imul(I, Rt) | 0, s = s + Math.imul(I, Lt) | 0, s = s + Math.imul(N, Rt) | 0, p = p + Math.imul(N, Lt) | 0;
571
- var Br = (x + h | 0) + ((s & 8191) << 13) | 0;
572
- x = (p + (s >>> 13) | 0) + (Br >>> 26) | 0, Br &= 67108863, h = Math.imul(wt, mt), s = Math.imul(wt, pt), s = s + Math.imul(gt, mt) | 0, p = Math.imul(gt, pt), h = h + Math.imul(ut, yt) | 0, s = s + Math.imul(ut, xt) | 0, s = s + Math.imul(dt, yt) | 0, p = p + Math.imul(dt, xt) | 0, h = h + Math.imul(ht, vt) | 0, s = s + Math.imul(ht, bt) | 0, s = s + Math.imul(lt, vt) | 0, p = p + Math.imul(lt, bt) | 0, h = h + Math.imul(at, Et) | 0, s = s + Math.imul(at, _t) | 0, s = s + Math.imul(ct, Et) | 0, p = p + Math.imul(ct, _t) | 0, h = h + Math.imul(nt, Mt) | 0, s = s + Math.imul(nt, At) | 0, s = s + Math.imul(it, Mt) | 0, p = p + Math.imul(it, At) | 0, h = h + Math.imul(et, Bt) | 0, s = s + Math.imul(et, St) | 0, s = s + Math.imul(rt, Bt) | 0, p = p + Math.imul(rt, St) | 0, h = h + Math.imul(K, It) | 0, s = s + Math.imul(K, Ut) | 0, s = s + Math.imul(J, It) | 0, p = p + Math.imul(J, Ut) | 0, h = h + Math.imul(W, kt) | 0, s = s + Math.imul(W, Nt) | 0, s = s + Math.imul(Y, kt) | 0, p = p + Math.imul(Y, Nt) | 0, h = h + Math.imul(Z, Rt) | 0, s = s + Math.imul(Z, Lt) | 0, s = s + Math.imul(z, Rt) | 0, p = p + Math.imul(z, Lt) | 0, h = h + Math.imul(I, Ot) | 0, s = s + Math.imul(I, Tt) | 0, s = s + Math.imul(N, Ot) | 0, p = p + Math.imul(N, Tt) | 0;
573
- var Sr = (x + h | 0) + ((s & 8191) << 13) | 0;
574
- x = (p + (s >>> 13) | 0) + (Sr >>> 26) | 0, Sr &= 67108863, h = Math.imul(wt, yt), s = Math.imul(wt, xt), s = s + Math.imul(gt, yt) | 0, p = Math.imul(gt, xt), h = h + Math.imul(ut, vt) | 0, s = s + Math.imul(ut, bt) | 0, s = s + Math.imul(dt, vt) | 0, p = p + Math.imul(dt, bt) | 0, h = h + Math.imul(ht, Et) | 0, s = s + Math.imul(ht, _t) | 0, s = s + Math.imul(lt, Et) | 0, p = p + Math.imul(lt, _t) | 0, h = h + Math.imul(at, Mt) | 0, s = s + Math.imul(at, At) | 0, s = s + Math.imul(ct, Mt) | 0, p = p + Math.imul(ct, At) | 0, h = h + Math.imul(nt, Bt) | 0, s = s + Math.imul(nt, St) | 0, s = s + Math.imul(it, Bt) | 0, p = p + Math.imul(it, St) | 0, h = h + Math.imul(et, It) | 0, s = s + Math.imul(et, Ut) | 0, s = s + Math.imul(rt, It) | 0, p = p + Math.imul(rt, Ut) | 0, h = h + Math.imul(K, kt) | 0, s = s + Math.imul(K, Nt) | 0, s = s + Math.imul(J, kt) | 0, p = p + Math.imul(J, Nt) | 0, h = h + Math.imul(W, Rt) | 0, s = s + Math.imul(W, Lt) | 0, s = s + Math.imul(Y, Rt) | 0, p = p + Math.imul(Y, Lt) | 0, h = h + Math.imul(Z, Ot) | 0, s = s + Math.imul(Z, Tt) | 0, s = s + Math.imul(z, Ot) | 0, p = p + Math.imul(z, Tt) | 0;
575
- var Ir = (x + h | 0) + ((s & 8191) << 13) | 0;
576
- x = (p + (s >>> 13) | 0) + (Ir >>> 26) | 0, Ir &= 67108863, h = Math.imul(wt, vt), s = Math.imul(wt, bt), s = s + Math.imul(gt, vt) | 0, p = Math.imul(gt, bt), h = h + Math.imul(ut, Et) | 0, s = s + Math.imul(ut, _t) | 0, s = s + Math.imul(dt, Et) | 0, p = p + Math.imul(dt, _t) | 0, h = h + Math.imul(ht, Mt) | 0, s = s + Math.imul(ht, At) | 0, s = s + Math.imul(lt, Mt) | 0, p = p + Math.imul(lt, At) | 0, h = h + Math.imul(at, Bt) | 0, s = s + Math.imul(at, St) | 0, s = s + Math.imul(ct, Bt) | 0, p = p + Math.imul(ct, St) | 0, h = h + Math.imul(nt, It) | 0, s = s + Math.imul(nt, Ut) | 0, s = s + Math.imul(it, It) | 0, p = p + Math.imul(it, Ut) | 0, h = h + Math.imul(et, kt) | 0, s = s + Math.imul(et, Nt) | 0, s = s + Math.imul(rt, kt) | 0, p = p + Math.imul(rt, Nt) | 0, h = h + Math.imul(K, Rt) | 0, s = s + Math.imul(K, Lt) | 0, s = s + Math.imul(J, Rt) | 0, p = p + Math.imul(J, Lt) | 0, h = h + Math.imul(W, Ot) | 0, s = s + Math.imul(W, Tt) | 0, s = s + Math.imul(Y, Ot) | 0, p = p + Math.imul(Y, Tt) | 0;
577
- var Ur = (x + h | 0) + ((s & 8191) << 13) | 0;
578
- x = (p + (s >>> 13) | 0) + (Ur >>> 26) | 0, Ur &= 67108863, h = Math.imul(wt, Et), s = Math.imul(wt, _t), s = s + Math.imul(gt, Et) | 0, p = Math.imul(gt, _t), h = h + Math.imul(ut, Mt) | 0, s = s + Math.imul(ut, At) | 0, s = s + Math.imul(dt, Mt) | 0, p = p + Math.imul(dt, At) | 0, h = h + Math.imul(ht, Bt) | 0, s = s + Math.imul(ht, St) | 0, s = s + Math.imul(lt, Bt) | 0, p = p + Math.imul(lt, St) | 0, h = h + Math.imul(at, It) | 0, s = s + Math.imul(at, Ut) | 0, s = s + Math.imul(ct, It) | 0, p = p + Math.imul(ct, Ut) | 0, h = h + Math.imul(nt, kt) | 0, s = s + Math.imul(nt, Nt) | 0, s = s + Math.imul(it, kt) | 0, p = p + Math.imul(it, Nt) | 0, h = h + Math.imul(et, Rt) | 0, s = s + Math.imul(et, Lt) | 0, s = s + Math.imul(rt, Rt) | 0, p = p + Math.imul(rt, Lt) | 0, h = h + Math.imul(K, Ot) | 0, s = s + Math.imul(K, Tt) | 0, s = s + Math.imul(J, Ot) | 0, p = p + Math.imul(J, Tt) | 0;
579
- var kr = (x + h | 0) + ((s & 8191) << 13) | 0;
580
- x = (p + (s >>> 13) | 0) + (kr >>> 26) | 0, kr &= 67108863, h = Math.imul(wt, Mt), s = Math.imul(wt, At), s = s + Math.imul(gt, Mt) | 0, p = Math.imul(gt, At), h = h + Math.imul(ut, Bt) | 0, s = s + Math.imul(ut, St) | 0, s = s + Math.imul(dt, Bt) | 0, p = p + Math.imul(dt, St) | 0, h = h + Math.imul(ht, It) | 0, s = s + Math.imul(ht, Ut) | 0, s = s + Math.imul(lt, It) | 0, p = p + Math.imul(lt, Ut) | 0, h = h + Math.imul(at, kt) | 0, s = s + Math.imul(at, Nt) | 0, s = s + Math.imul(ct, kt) | 0, p = p + Math.imul(ct, Nt) | 0, h = h + Math.imul(nt, Rt) | 0, s = s + Math.imul(nt, Lt) | 0, s = s + Math.imul(it, Rt) | 0, p = p + Math.imul(it, Lt) | 0, h = h + Math.imul(et, Ot) | 0, s = s + Math.imul(et, Tt) | 0, s = s + Math.imul(rt, Ot) | 0, p = p + Math.imul(rt, Tt) | 0;
581
- var Nr = (x + h | 0) + ((s & 8191) << 13) | 0;
582
- x = (p + (s >>> 13) | 0) + (Nr >>> 26) | 0, Nr &= 67108863, h = Math.imul(wt, Bt), s = Math.imul(wt, St), s = s + Math.imul(gt, Bt) | 0, p = Math.imul(gt, St), h = h + Math.imul(ut, It) | 0, s = s + Math.imul(ut, Ut) | 0, s = s + Math.imul(dt, It) | 0, p = p + Math.imul(dt, Ut) | 0, h = h + Math.imul(ht, kt) | 0, s = s + Math.imul(ht, Nt) | 0, s = s + Math.imul(lt, kt) | 0, p = p + Math.imul(lt, Nt) | 0, h = h + Math.imul(at, Rt) | 0, s = s + Math.imul(at, Lt) | 0, s = s + Math.imul(ct, Rt) | 0, p = p + Math.imul(ct, Lt) | 0, h = h + Math.imul(nt, Ot) | 0, s = s + Math.imul(nt, Tt) | 0, s = s + Math.imul(it, Ot) | 0, p = p + Math.imul(it, Tt) | 0;
583
- var Rr = (x + h | 0) + ((s & 8191) << 13) | 0;
584
- x = (p + (s >>> 13) | 0) + (Rr >>> 26) | 0, Rr &= 67108863, h = Math.imul(wt, It), s = Math.imul(wt, Ut), s = s + Math.imul(gt, It) | 0, p = Math.imul(gt, Ut), h = h + Math.imul(ut, kt) | 0, s = s + Math.imul(ut, Nt) | 0, s = s + Math.imul(dt, kt) | 0, p = p + Math.imul(dt, Nt) | 0, h = h + Math.imul(ht, Rt) | 0, s = s + Math.imul(ht, Lt) | 0, s = s + Math.imul(lt, Rt) | 0, p = p + Math.imul(lt, Lt) | 0, h = h + Math.imul(at, Ot) | 0, s = s + Math.imul(at, Tt) | 0, s = s + Math.imul(ct, Ot) | 0, p = p + Math.imul(ct, Tt) | 0;
585
- var Lr = (x + h | 0) + ((s & 8191) << 13) | 0;
586
- x = (p + (s >>> 13) | 0) + (Lr >>> 26) | 0, Lr &= 67108863, h = Math.imul(wt, kt), s = Math.imul(wt, Nt), s = s + Math.imul(gt, kt) | 0, p = Math.imul(gt, Nt), h = h + Math.imul(ut, Rt) | 0, s = s + Math.imul(ut, Lt) | 0, s = s + Math.imul(dt, Rt) | 0, p = p + Math.imul(dt, Lt) | 0, h = h + Math.imul(ht, Ot) | 0, s = s + Math.imul(ht, Tt) | 0, s = s + Math.imul(lt, Ot) | 0, p = p + Math.imul(lt, Tt) | 0;
587
- var Or = (x + h | 0) + ((s & 8191) << 13) | 0;
588
- x = (p + (s >>> 13) | 0) + (Or >>> 26) | 0, Or &= 67108863, h = Math.imul(wt, Rt), s = Math.imul(wt, Lt), s = s + Math.imul(gt, Rt) | 0, p = Math.imul(gt, Lt), h = h + Math.imul(ut, Ot) | 0, s = s + Math.imul(ut, Tt) | 0, s = s + Math.imul(dt, Ot) | 0, p = p + Math.imul(dt, Tt) | 0;
589
- var Tr = (x + h | 0) + ((s & 8191) << 13) | 0;
590
- x = (p + (s >>> 13) | 0) + (Tr >>> 26) | 0, Tr &= 67108863, h = Math.imul(wt, Ot), s = Math.imul(wt, Tt), s = s + Math.imul(gt, Ot) | 0, p = Math.imul(gt, Tt);
591
- var Hr = (x + h | 0) + ((s & 8191) << 13) | 0;
592
- return x = (p + (s >>> 13) | 0) + (Hr >>> 26) | 0, Hr &= 67108863, w[0] = yr, w[1] = xr, w[2] = vr, w[3] = br, w[4] = Er, w[5] = _r, w[6] = Mr, w[7] = Ar, w[8] = Br, w[9] = Sr, w[10] = Ir, w[11] = Ur, w[12] = kr, w[13] = Nr, w[14] = Rr, w[15] = Lr, w[16] = Or, w[17] = Tr, w[18] = Hr, x !== 0 && (w[19] = x, c.length++), c;
593
- };
594
- Math.imul || (Q = V);
595
- function R(y, n, f) {
596
- f.negative = n.negative ^ y.negative, f.length = y.length + n.length;
597
- for (var c = 0, g = 0, d = 0; d < f.length - 1; d++) {
598
- var w = g;
599
- g = 0;
600
- for (var x = c & 67108863, h = Math.min(d, n.length - 1), s = Math.max(0, d - y.length + 1); s <= h; s++) {
601
- var p = d - s, k = y.words[p] | 0, I = n.words[s] | 0, N = k * I, P = N & 67108863;
602
- w = w + (N / 67108864 | 0) | 0, P = P + x | 0, x = P & 67108863, w = w + (P >>> 26) | 0, g += w >>> 26, w &= 67108863;
603
- }
604
- f.words[d] = x, c = w, w = g;
605
- }
606
- return c !== 0 ? f.words[d] = c : f.length--, f._strip();
607
- }
608
- function _(y, n, f) {
609
- return R(y, n, f);
610
- }
611
- o.prototype.mulTo = function(n, f) {
612
- var c, g = this.length + n.length;
613
- return this.length === 10 && n.length === 10 ? c = Q(this, n, f) : g < 63 ? c = V(this, n, f) : g < 1024 ? c = R(this, n, f) : c = _(this, n, f), c;
614
- }, o.prototype.mul = function(n) {
615
- var f = new o(null);
616
- return f.words = new Array(this.length + n.length), this.mulTo(n, f);
617
- }, o.prototype.mulf = function(n) {
618
- var f = new o(null);
619
- return f.words = new Array(this.length + n.length), _(this, n, f);
620
- }, o.prototype.imul = function(n) {
621
- return this.clone().mulTo(n, this);
622
- }, o.prototype.imuln = function(n) {
623
- var f = n < 0;
624
- f && (n = -n), i(typeof n == "number"), i(n < 67108864);
625
- for (var c = 0, g = 0; g < this.length; g++) {
626
- var d = (this.words[g] | 0) * n, w = (d & 67108863) + (c & 67108863);
627
- c >>= 26, c += d / 67108864 | 0, c += w >>> 26, this.words[g] = w & 67108863;
628
- }
629
- return c !== 0 && (this.words[g] = c, this.length++), this.length = n === 0 ? 1 : this.length, f ? this.ineg() : this;
630
- }, o.prototype.muln = function(n) {
631
- return this.clone().imuln(n);
632
- }, o.prototype.sqr = function() {
633
- return this.mul(this);
634
- }, o.prototype.isqr = function() {
635
- return this.imul(this.clone());
636
- }, o.prototype.pow = function(n) {
637
- var f = D(n);
638
- if (f.length === 0) return new o(1);
639
- for (var c = this, g = 0; g < f.length && f[g] === 0; g++, c = c.sqr())
640
- ;
641
- if (++g < f.length)
642
- for (var d = c.sqr(); g < f.length; g++, d = d.sqr())
643
- f[g] !== 0 && (c = c.mul(d));
644
- return c;
645
- }, o.prototype.iushln = function(n) {
646
- i(typeof n == "number" && n >= 0);
647
- var f = n % 26, c = (n - f) / 26, g = 67108863 >>> 26 - f << 26 - f, d;
648
- if (f !== 0) {
649
- var w = 0;
650
- for (d = 0; d < this.length; d++) {
651
- var x = this.words[d] & g, h = (this.words[d] | 0) - x << f;
652
- this.words[d] = h | w, w = x >>> 26 - f;
653
- }
654
- w && (this.words[d] = w, this.length++);
655
- }
656
- if (c !== 0) {
657
- for (d = this.length - 1; d >= 0; d--)
658
- this.words[d + c] = this.words[d];
659
- for (d = 0; d < c; d++)
660
- this.words[d] = 0;
661
- this.length += c;
662
- }
663
- return this._strip();
664
- }, o.prototype.ishln = function(n) {
665
- return i(this.negative === 0), this.iushln(n);
666
- }, o.prototype.iushrn = function(n, f, c) {
667
- i(typeof n == "number" && n >= 0);
668
- var g;
669
- f ? g = (f - f % 26) / 26 : g = 0;
670
- var d = n % 26, w = Math.min((n - d) / 26, this.length), x = 67108863 ^ 67108863 >>> d << d, h = c;
671
- if (g -= w, g = Math.max(0, g), h) {
672
- for (var s = 0; s < w; s++)
673
- h.words[s] = this.words[s];
674
- h.length = w;
675
- }
676
- if (w !== 0) if (this.length > w)
677
- for (this.length -= w, s = 0; s < this.length; s++)
678
- this.words[s] = this.words[s + w];
679
- else
680
- this.words[0] = 0, this.length = 1;
681
- var p = 0;
682
- for (s = this.length - 1; s >= 0 && (p !== 0 || s >= g); s--) {
683
- var k = this.words[s] | 0;
684
- this.words[s] = p << 26 - d | k >>> d, p = k & x;
685
- }
686
- return h && p !== 0 && (h.words[h.length++] = p), this.length === 0 && (this.words[0] = 0, this.length = 1), this._strip();
687
- }, o.prototype.ishrn = function(n, f, c) {
688
- return i(this.negative === 0), this.iushrn(n, f, c);
689
- }, o.prototype.shln = function(n) {
690
- return this.clone().ishln(n);
691
- }, o.prototype.ushln = function(n) {
692
- return this.clone().iushln(n);
693
- }, o.prototype.shrn = function(n) {
694
- return this.clone().ishrn(n);
695
- }, o.prototype.ushrn = function(n) {
696
- return this.clone().iushrn(n);
697
- }, o.prototype.testn = function(n) {
698
- i(typeof n == "number" && n >= 0);
699
- var f = n % 26, c = (n - f) / 26, g = 1 << f;
700
- if (this.length <= c) return !1;
701
- var d = this.words[c];
702
- return !!(d & g);
703
- }, o.prototype.imaskn = function(n) {
704
- i(typeof n == "number" && n >= 0);
705
- var f = n % 26, c = (n - f) / 26;
706
- if (i(this.negative === 0, "imaskn works only with positive numbers"), this.length <= c)
707
- return this;
708
- if (f !== 0 && c++, this.length = Math.min(c, this.length), f !== 0) {
709
- var g = 67108863 ^ 67108863 >>> f << f;
710
- this.words[this.length - 1] &= g;
711
- }
712
- return this._strip();
713
- }, o.prototype.maskn = function(n) {
714
- return this.clone().imaskn(n);
715
- }, o.prototype.iaddn = function(n) {
716
- return i(typeof n == "number"), i(n < 67108864), n < 0 ? this.isubn(-n) : this.negative !== 0 ? this.length === 1 && (this.words[0] | 0) <= n ? (this.words[0] = n - (this.words[0] | 0), this.negative = 0, this) : (this.negative = 0, this.isubn(n), this.negative = 1, this) : this._iaddn(n);
717
- }, o.prototype._iaddn = function(n) {
718
- this.words[0] += n;
719
- for (var f = 0; f < this.length && this.words[f] >= 67108864; f++)
720
- this.words[f] -= 67108864, f === this.length - 1 ? this.words[f + 1] = 1 : this.words[f + 1]++;
721
- return this.length = Math.max(this.length, f + 1), this;
722
- }, o.prototype.isubn = function(n) {
723
- if (i(typeof n == "number"), i(n < 67108864), n < 0) return this.iaddn(-n);
724
- if (this.negative !== 0)
725
- return this.negative = 0, this.iaddn(n), this.negative = 1, this;
726
- if (this.words[0] -= n, this.length === 1 && this.words[0] < 0)
727
- this.words[0] = -this.words[0], this.negative = 1;
728
- else
729
- for (var f = 0; f < this.length && this.words[f] < 0; f++)
730
- this.words[f] += 67108864, this.words[f + 1] -= 1;
731
- return this._strip();
732
- }, o.prototype.addn = function(n) {
733
- return this.clone().iaddn(n);
734
- }, o.prototype.subn = function(n) {
735
- return this.clone().isubn(n);
736
- }, o.prototype.iabs = function() {
737
- return this.negative = 0, this;
738
- }, o.prototype.abs = function() {
739
- return this.clone().iabs();
740
- }, o.prototype._ishlnsubmul = function(n, f, c) {
741
- var g = n.length + c, d;
742
- this._expand(g);
743
- var w, x = 0;
744
- for (d = 0; d < n.length; d++) {
745
- w = (this.words[d + c] | 0) + x;
746
- var h = (n.words[d] | 0) * f;
747
- w -= h & 67108863, x = (w >> 26) - (h / 67108864 | 0), this.words[d + c] = w & 67108863;
748
- }
749
- for (; d < this.length - c; d++)
750
- w = (this.words[d + c] | 0) + x, x = w >> 26, this.words[d + c] = w & 67108863;
751
- if (x === 0) return this._strip();
752
- for (i(x === -1), x = 0, d = 0; d < this.length; d++)
753
- w = -(this.words[d] | 0) + x, x = w >> 26, this.words[d] = w & 67108863;
754
- return this.negative = 1, this._strip();
755
- }, o.prototype._wordDiv = function(n, f) {
756
- var c = this.length - n.length, g = this.clone(), d = n, w = d.words[d.length - 1] | 0, x = this._countBits(w);
757
- c = 26 - x, c !== 0 && (d = d.ushln(c), g.iushln(c), w = d.words[d.length - 1] | 0);
758
- var h = g.length - d.length, s;
759
- if (f !== "mod") {
760
- s = new o(null), s.length = h + 1, s.words = new Array(s.length);
761
- for (var p = 0; p < s.length; p++)
762
- s.words[p] = 0;
763
- }
764
- var k = g.clone()._ishlnsubmul(d, 1, h);
765
- k.negative === 0 && (g = k, s && (s.words[h] = 1));
766
- for (var I = h - 1; I >= 0; I--) {
767
- var N = (g.words[d.length + I] | 0) * 67108864 + (g.words[d.length + I - 1] | 0);
768
- for (N = Math.min(N / w | 0, 67108863), g._ishlnsubmul(d, N, I); g.negative !== 0; )
769
- N--, g.negative = 0, g._ishlnsubmul(d, 1, I), g.isZero() || (g.negative ^= 1);
770
- s && (s.words[I] = N);
771
- }
772
- return s && s._strip(), g._strip(), f !== "div" && c !== 0 && g.iushrn(c), {
773
- div: s || null,
774
- mod: g
775
- };
776
- }, o.prototype.divmod = function(n, f, c) {
777
- if (i(!n.isZero()), this.isZero())
778
- return {
779
- div: new o(0),
780
- mod: new o(0)
781
- };
782
- var g, d, w;
783
- return this.negative !== 0 && n.negative === 0 ? (w = this.neg().divmod(n, f), f !== "mod" && (g = w.div.neg()), f !== "div" && (d = w.mod.neg(), c && d.negative !== 0 && d.iadd(n)), {
784
- div: g,
785
- mod: d
786
- }) : this.negative === 0 && n.negative !== 0 ? (w = this.divmod(n.neg(), f), f !== "mod" && (g = w.div.neg()), {
787
- div: g,
788
- mod: w.mod
789
- }) : (this.negative & n.negative) !== 0 ? (w = this.neg().divmod(n.neg(), f), f !== "div" && (d = w.mod.neg(), c && d.negative !== 0 && d.isub(n)), {
790
- div: w.div,
791
- mod: d
792
- }) : n.length > this.length || this.cmp(n) < 0 ? {
793
- div: new o(0),
794
- mod: this
795
- } : n.length === 1 ? f === "div" ? {
796
- div: this.divn(n.words[0]),
797
- mod: null
798
- } : f === "mod" ? {
799
- div: null,
800
- mod: new o(this.modrn(n.words[0]))
801
- } : {
802
- div: this.divn(n.words[0]),
803
- mod: new o(this.modrn(n.words[0]))
804
- } : this._wordDiv(n, f);
805
- }, o.prototype.div = function(n) {
806
- return this.divmod(n, "div", !1).div;
807
- }, o.prototype.mod = function(n) {
808
- return this.divmod(n, "mod", !1).mod;
809
- }, o.prototype.umod = function(n) {
810
- return this.divmod(n, "mod", !0).mod;
811
- }, o.prototype.divRound = function(n) {
812
- var f = this.divmod(n);
813
- if (f.mod.isZero()) return f.div;
814
- var c = f.div.negative !== 0 ? f.mod.isub(n) : f.mod, g = n.ushrn(1), d = n.andln(1), w = c.cmp(g);
815
- return w < 0 || d === 1 && w === 0 ? f.div : f.div.negative !== 0 ? f.div.isubn(1) : f.div.iaddn(1);
816
- }, o.prototype.modrn = function(n) {
817
- var f = n < 0;
818
- f && (n = -n), i(n <= 67108863);
819
- for (var c = (1 << 26) % n, g = 0, d = this.length - 1; d >= 0; d--)
820
- g = (c * g + (this.words[d] | 0)) % n;
821
- return f ? -g : g;
822
- }, o.prototype.modn = function(n) {
823
- return this.modrn(n);
824
- }, o.prototype.idivn = function(n) {
825
- var f = n < 0;
826
- f && (n = -n), i(n <= 67108863);
827
- for (var c = 0, g = this.length - 1; g >= 0; g--) {
828
- var d = (this.words[g] | 0) + c * 67108864;
829
- this.words[g] = d / n | 0, c = d % n;
830
- }
831
- return this._strip(), f ? this.ineg() : this;
832
- }, o.prototype.divn = function(n) {
833
- return this.clone().idivn(n);
834
- }, o.prototype.egcd = function(n) {
835
- i(n.negative === 0), i(!n.isZero());
836
- var f = this, c = n.clone();
837
- f.negative !== 0 ? f = f.umod(n) : f = f.clone();
838
- for (var g = new o(1), d = new o(0), w = new o(0), x = new o(1), h = 0; f.isEven() && c.isEven(); )
839
- f.iushrn(1), c.iushrn(1), ++h;
840
- for (var s = c.clone(), p = f.clone(); !f.isZero(); ) {
841
- for (var k = 0, I = 1; (f.words[0] & I) === 0 && k < 26; ++k, I <<= 1) ;
842
- if (k > 0)
843
- for (f.iushrn(k); k-- > 0; )
844
- (g.isOdd() || d.isOdd()) && (g.iadd(s), d.isub(p)), g.iushrn(1), d.iushrn(1);
845
- for (var N = 0, P = 1; (c.words[0] & P) === 0 && N < 26; ++N, P <<= 1) ;
846
- if (N > 0)
847
- for (c.iushrn(N); N-- > 0; )
848
- (w.isOdd() || x.isOdd()) && (w.iadd(s), x.isub(p)), w.iushrn(1), x.iushrn(1);
849
- f.cmp(c) >= 0 ? (f.isub(c), g.isub(w), d.isub(x)) : (c.isub(f), w.isub(g), x.isub(d));
850
- }
851
- return {
852
- a: w,
853
- b: x,
854
- gcd: c.iushln(h)
855
- };
856
- }, o.prototype._invmp = function(n) {
857
- i(n.negative === 0), i(!n.isZero());
858
- var f = this, c = n.clone();
859
- f.negative !== 0 ? f = f.umod(n) : f = f.clone();
860
- for (var g = new o(1), d = new o(0), w = c.clone(); f.cmpn(1) > 0 && c.cmpn(1) > 0; ) {
861
- for (var x = 0, h = 1; (f.words[0] & h) === 0 && x < 26; ++x, h <<= 1) ;
862
- if (x > 0)
863
- for (f.iushrn(x); x-- > 0; )
864
- g.isOdd() && g.iadd(w), g.iushrn(1);
865
- for (var s = 0, p = 1; (c.words[0] & p) === 0 && s < 26; ++s, p <<= 1) ;
866
- if (s > 0)
867
- for (c.iushrn(s); s-- > 0; )
868
- d.isOdd() && d.iadd(w), d.iushrn(1);
869
- f.cmp(c) >= 0 ? (f.isub(c), g.isub(d)) : (c.isub(f), d.isub(g));
870
- }
871
- var k;
872
- return f.cmpn(1) === 0 ? k = g : k = d, k.cmpn(0) < 0 && k.iadd(n), k;
873
- }, o.prototype.gcd = function(n) {
874
- if (this.isZero()) return n.abs();
875
- if (n.isZero()) return this.abs();
876
- var f = this.clone(), c = n.clone();
877
- f.negative = 0, c.negative = 0;
878
- for (var g = 0; f.isEven() && c.isEven(); g++)
879
- f.iushrn(1), c.iushrn(1);
880
- do {
881
- for (; f.isEven(); )
882
- f.iushrn(1);
883
- for (; c.isEven(); )
884
- c.iushrn(1);
885
- var d = f.cmp(c);
886
- if (d < 0) {
887
- var w = f;
888
- f = c, c = w;
889
- } else if (d === 0 || c.cmpn(1) === 0)
890
- break;
891
- f.isub(c);
892
- } while (!0);
893
- return c.iushln(g);
894
- }, o.prototype.invm = function(n) {
895
- return this.egcd(n).a.umod(n);
896
- }, o.prototype.isEven = function() {
897
- return (this.words[0] & 1) === 0;
898
- }, o.prototype.isOdd = function() {
899
- return (this.words[0] & 1) === 1;
900
- }, o.prototype.andln = function(n) {
901
- return this.words[0] & n;
902
- }, o.prototype.bincn = function(n) {
903
- i(typeof n == "number");
904
- var f = n % 26, c = (n - f) / 26, g = 1 << f;
905
- if (this.length <= c)
906
- return this._expand(c + 1), this.words[c] |= g, this;
907
- for (var d = g, w = c; d !== 0 && w < this.length; w++) {
908
- var x = this.words[w] | 0;
909
- x += d, d = x >>> 26, x &= 67108863, this.words[w] = x;
910
- }
911
- return d !== 0 && (this.words[w] = d, this.length++), this;
912
- }, o.prototype.isZero = function() {
913
- return this.length === 1 && this.words[0] === 0;
914
- }, o.prototype.cmpn = function(n) {
915
- var f = n < 0;
916
- if (this.negative !== 0 && !f) return -1;
917
- if (this.negative === 0 && f) return 1;
918
- this._strip();
919
- var c;
920
- if (this.length > 1)
921
- c = 1;
922
- else {
923
- f && (n = -n), i(n <= 67108863, "Number is too big");
924
- var g = this.words[0] | 0;
925
- c = g === n ? 0 : g < n ? -1 : 1;
926
- }
927
- return this.negative !== 0 ? -c | 0 : c;
928
- }, o.prototype.cmp = function(n) {
929
- if (this.negative !== 0 && n.negative === 0) return -1;
930
- if (this.negative === 0 && n.negative !== 0) return 1;
931
- var f = this.ucmp(n);
932
- return this.negative !== 0 ? -f | 0 : f;
933
- }, o.prototype.ucmp = function(n) {
934
- if (this.length > n.length) return 1;
935
- if (this.length < n.length) return -1;
936
- for (var f = 0, c = this.length - 1; c >= 0; c--) {
937
- var g = this.words[c] | 0, d = n.words[c] | 0;
938
- if (g !== d) {
939
- g < d ? f = -1 : g > d && (f = 1);
940
- break;
941
- }
942
- }
943
- return f;
944
- }, o.prototype.gtn = function(n) {
945
- return this.cmpn(n) === 1;
946
- }, o.prototype.gt = function(n) {
947
- return this.cmp(n) === 1;
948
- }, o.prototype.gten = function(n) {
949
- return this.cmpn(n) >= 0;
950
- }, o.prototype.gte = function(n) {
951
- return this.cmp(n) >= 0;
952
- }, o.prototype.ltn = function(n) {
953
- return this.cmpn(n) === -1;
954
- }, o.prototype.lt = function(n) {
955
- return this.cmp(n) === -1;
956
- }, o.prototype.lten = function(n) {
957
- return this.cmpn(n) <= 0;
958
- }, o.prototype.lte = function(n) {
959
- return this.cmp(n) <= 0;
960
- }, o.prototype.eqn = function(n) {
961
- return this.cmpn(n) === 0;
962
- }, o.prototype.eq = function(n) {
963
- return this.cmp(n) === 0;
964
- }, o.red = function(n) {
965
- return new U(n);
966
- }, o.prototype.toRed = function(n) {
967
- return i(!this.red, "Already a number in reduction context"), i(this.negative === 0, "red works only with positives"), n.convertTo(this)._forceRed(n);
968
- }, o.prototype.fromRed = function() {
969
- return i(this.red, "fromRed works only with numbers in reduction context"), this.red.convertFrom(this);
970
- }, o.prototype._forceRed = function(n) {
971
- return this.red = n, this;
972
- }, o.prototype.forceRed = function(n) {
973
- return i(!this.red, "Already a number in reduction context"), this._forceRed(n);
974
- }, o.prototype.redAdd = function(n) {
975
- return i(this.red, "redAdd works only with red numbers"), this.red.add(this, n);
976
- }, o.prototype.redIAdd = function(n) {
977
- return i(this.red, "redIAdd works only with red numbers"), this.red.iadd(this, n);
978
- }, o.prototype.redSub = function(n) {
979
- return i(this.red, "redSub works only with red numbers"), this.red.sub(this, n);
980
- }, o.prototype.redISub = function(n) {
981
- return i(this.red, "redISub works only with red numbers"), this.red.isub(this, n);
982
- }, o.prototype.redShl = function(n) {
983
- return i(this.red, "redShl works only with red numbers"), this.red.shl(this, n);
984
- }, o.prototype.redMul = function(n) {
985
- return i(this.red, "redMul works only with red numbers"), this.red._verify2(this, n), this.red.mul(this, n);
986
- }, o.prototype.redIMul = function(n) {
987
- return i(this.red, "redMul works only with red numbers"), this.red._verify2(this, n), this.red.imul(this, n);
988
- }, o.prototype.redSqr = function() {
989
- return i(this.red, "redSqr works only with red numbers"), this.red._verify1(this), this.red.sqr(this);
990
- }, o.prototype.redISqr = function() {
991
- return i(this.red, "redISqr works only with red numbers"), this.red._verify1(this), this.red.isqr(this);
992
- }, o.prototype.redSqrt = function() {
993
- return i(this.red, "redSqrt works only with red numbers"), this.red._verify1(this), this.red.sqrt(this);
994
- }, o.prototype.redInvm = function() {
995
- return i(this.red, "redInvm works only with red numbers"), this.red._verify1(this), this.red.invm(this);
996
- }, o.prototype.redNeg = function() {
997
- return i(this.red, "redNeg works only with red numbers"), this.red._verify1(this), this.red.neg(this);
998
- }, o.prototype.redPow = function(n) {
999
- return i(this.red && !n.red, "redPow(normalNum)"), this.red._verify1(this), this.red.pow(this, n);
1000
- };
1001
- var B = {
1002
- k256: null,
1003
- p224: null,
1004
- p192: null,
1005
- p25519: null
1006
- };
1007
- function L(y, n) {
1008
- this.name = y, this.p = new o(n, 16), this.n = this.p.bitLength(), this.k = new o(1).iushln(this.n).isub(this.p), this.tmp = this._tmp();
1009
- }
1010
- L.prototype._tmp = function() {
1011
- var n = new o(null);
1012
- return n.words = new Array(Math.ceil(this.n / 13)), n;
1013
- }, L.prototype.ireduce = function(n) {
1014
- var f = n, c;
1015
- do
1016
- this.split(f, this.tmp), f = this.imulK(f), f = f.iadd(this.tmp), c = f.bitLength();
1017
- while (c > this.n);
1018
- var g = c < this.n ? -1 : f.ucmp(this.p);
1019
- return g === 0 ? (f.words[0] = 0, f.length = 1) : g > 0 ? f.isub(this.p) : f.strip !== void 0 ? f.strip() : f._strip(), f;
1020
- }, L.prototype.split = function(n, f) {
1021
- n.iushrn(this.n, 0, f);
1022
- }, L.prototype.imulK = function(n) {
1023
- return n.imul(this.k);
1024
- };
1025
- function T() {
1026
- L.call(
1027
- this,
1028
- "k256",
1029
- "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"
1030
- );
1031
- }
1032
- a(T, L), T.prototype.split = function(n, f) {
1033
- for (var c = 4194303, g = Math.min(n.length, 9), d = 0; d < g; d++)
1034
- f.words[d] = n.words[d];
1035
- if (f.length = g, n.length <= 9) {
1036
- n.words[0] = 0, n.length = 1;
1037
- return;
1038
- }
1039
- var w = n.words[9];
1040
- for (f.words[f.length++] = w & c, d = 10; d < n.length; d++) {
1041
- var x = n.words[d] | 0;
1042
- n.words[d - 10] = (x & c) << 4 | w >>> 22, w = x;
1043
- }
1044
- w >>>= 22, n.words[d - 10] = w, w === 0 && n.length > 10 ? n.length -= 10 : n.length -= 9;
1045
- }, T.prototype.imulK = function(n) {
1046
- n.words[n.length] = 0, n.words[n.length + 1] = 0, n.length += 2;
1047
- for (var f = 0, c = 0; c < n.length; c++) {
1048
- var g = n.words[c] | 0;
1049
- f += g * 977, n.words[c] = f & 67108863, f = g * 64 + (f / 67108864 | 0);
1050
- }
1051
- return n.words[n.length - 1] === 0 && (n.length--, n.words[n.length - 1] === 0 && n.length--), n;
1052
- };
1053
- function q() {
1054
- L.call(
1055
- this,
1056
- "p224",
1057
- "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"
1058
- );
1059
- }
1060
- a(q, L);
1061
- function $() {
1062
- L.call(
1063
- this,
1064
- "p192",
1065
- "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"
1066
- );
1067
- }
1068
- a($, L);
1069
- function C() {
1070
- L.call(
1071
- this,
1072
- "25519",
1073
- "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"
1074
- );
1075
- }
1076
- a(C, L), C.prototype.imulK = function(n) {
1077
- for (var f = 0, c = 0; c < n.length; c++) {
1078
- var g = (n.words[c] | 0) * 19 + f, d = g & 67108863;
1079
- g >>>= 26, n.words[c] = d, f = g;
1080
- }
1081
- return f !== 0 && (n.words[n.length++] = f), n;
1082
- }, o._prime = function(n) {
1083
- if (B[n]) return B[n];
1084
- var f;
1085
- if (n === "k256")
1086
- f = new T();
1087
- else if (n === "p224")
1088
- f = new q();
1089
- else if (n === "p192")
1090
- f = new $();
1091
- else if (n === "p25519")
1092
- f = new C();
1093
- else
1094
- throw new Error("Unknown prime " + n);
1095
- return B[n] = f, f;
1096
- };
1097
- function U(y) {
1098
- if (typeof y == "string") {
1099
- var n = o._prime(y);
1100
- this.m = n.p, this.prime = n;
1101
- } else
1102
- i(y.gtn(1), "modulus must be greater than 1"), this.m = y, this.prime = null;
1103
- }
1104
- U.prototype._verify1 = function(n) {
1105
- i(n.negative === 0, "red works only with positives"), i(n.red, "red works only with red numbers");
1106
- }, U.prototype._verify2 = function(n, f) {
1107
- i((n.negative | f.negative) === 0, "red works only with positives"), i(
1108
- n.red && n.red === f.red,
1109
- "red works only with red numbers"
1110
- );
1111
- }, U.prototype.imod = function(n) {
1112
- return this.prime ? this.prime.ireduce(n)._forceRed(this) : (v(n, n.umod(this.m)._forceRed(this)), n);
1113
- }, U.prototype.neg = function(n) {
1114
- return n.isZero() ? n.clone() : this.m.sub(n)._forceRed(this);
1115
- }, U.prototype.add = function(n, f) {
1116
- this._verify2(n, f);
1117
- var c = n.add(f);
1118
- return c.cmp(this.m) >= 0 && c.isub(this.m), c._forceRed(this);
1119
- }, U.prototype.iadd = function(n, f) {
1120
- this._verify2(n, f);
1121
- var c = n.iadd(f);
1122
- return c.cmp(this.m) >= 0 && c.isub(this.m), c;
1123
- }, U.prototype.sub = function(n, f) {
1124
- this._verify2(n, f);
1125
- var c = n.sub(f);
1126
- return c.cmpn(0) < 0 && c.iadd(this.m), c._forceRed(this);
1127
- }, U.prototype.isub = function(n, f) {
1128
- this._verify2(n, f);
1129
- var c = n.isub(f);
1130
- return c.cmpn(0) < 0 && c.iadd(this.m), c;
1131
- }, U.prototype.shl = function(n, f) {
1132
- return this._verify1(n), this.imod(n.ushln(f));
1133
- }, U.prototype.imul = function(n, f) {
1134
- return this._verify2(n, f), this.imod(n.imul(f));
1135
- }, U.prototype.mul = function(n, f) {
1136
- return this._verify2(n, f), this.imod(n.mul(f));
1137
- }, U.prototype.isqr = function(n) {
1138
- return this.imul(n, n.clone());
1139
- }, U.prototype.sqr = function(n) {
1140
- return this.mul(n, n);
1141
- }, U.prototype.sqrt = function(n) {
1142
- if (n.isZero()) return n.clone();
1143
- var f = this.m.andln(3);
1144
- if (i(f % 2 === 1), f === 3) {
1145
- var c = this.m.add(new o(1)).iushrn(2);
1146
- return this.pow(n, c);
1147
- }
1148
- for (var g = this.m.subn(1), d = 0; !g.isZero() && g.andln(1) === 0; )
1149
- d++, g.iushrn(1);
1150
- i(!g.isZero());
1151
- var w = new o(1).toRed(this), x = w.redNeg(), h = this.m.subn(1).iushrn(1), s = this.m.bitLength();
1152
- for (s = new o(2 * s * s).toRed(this); this.pow(s, h).cmp(x) !== 0; )
1153
- s.redIAdd(x);
1154
- for (var p = this.pow(s, g), k = this.pow(n, g.addn(1).iushrn(1)), I = this.pow(n, g), N = d; I.cmp(w) !== 0; ) {
1155
- for (var P = I, Z = 0; P.cmp(w) !== 0; Z++)
1156
- P = P.redSqr();
1157
- i(Z < N);
1158
- var z = this.pow(p, new o(1).iushln(N - Z - 1));
1159
- k = k.redMul(z), p = z.redSqr(), I = I.redMul(p), N = Z;
1160
- }
1161
- return k;
1162
- }, U.prototype.invm = function(n) {
1163
- var f = n._invmp(this.m);
1164
- return f.negative !== 0 ? (f.negative = 0, this.imod(f).redNeg()) : this.imod(f);
1165
- }, U.prototype.pow = function(n, f) {
1166
- if (f.isZero()) return new o(1).toRed(this);
1167
- if (f.cmpn(1) === 0) return n.clone();
1168
- var c = 4, g = new Array(1 << c);
1169
- g[0] = new o(1).toRed(this), g[1] = n;
1170
- for (var d = 2; d < g.length; d++)
1171
- g[d] = this.mul(g[d - 1], n);
1172
- var w = g[0], x = 0, h = 0, s = f.bitLength() % 26;
1173
- for (s === 0 && (s = 26), d = f.length - 1; d >= 0; d--) {
1174
- for (var p = f.words[d], k = s - 1; k >= 0; k--) {
1175
- var I = p >> k & 1;
1176
- if (w !== g[0] && (w = this.sqr(w)), I === 0 && x === 0) {
1177
- h = 0;
1178
- continue;
1179
- }
1180
- x <<= 1, x |= I, h++, !(h !== c && (d !== 0 || k !== 0)) && (w = this.mul(w, g[x]), h = 0, x = 0);
1181
- }
1182
- s = 26;
1183
- }
1184
- return w;
1185
- }, U.prototype.convertTo = function(n) {
1186
- var f = n.umod(this.m);
1187
- return f === n ? f.clone() : f;
1188
- }, U.prototype.convertFrom = function(n) {
1189
- var f = n.clone();
1190
- return f.red = null, f;
1191
- }, o.mont = function(n) {
1192
- return new H(n);
1193
- };
1194
- function H(y) {
1195
- U.call(this, y), this.shift = this.m.bitLength(), this.shift % 26 !== 0 && (this.shift += 26 - this.shift % 26), this.r = new o(1).iushln(this.shift), this.r2 = this.imod(this.r.sqr()), this.rinv = this.r._invmp(this.m), this.minv = this.rinv.mul(this.r).isubn(1).div(this.m), this.minv = this.minv.umod(this.r), this.minv = this.r.sub(this.minv);
1196
- }
1197
- a(H, U), H.prototype.convertTo = function(n) {
1198
- return this.imod(n.ushln(this.shift));
1199
- }, H.prototype.convertFrom = function(n) {
1200
- var f = this.imod(n.mul(this.rinv));
1201
- return f.red = null, f;
1202
- }, H.prototype.imul = function(n, f) {
1203
- if (n.isZero() || f.isZero())
1204
- return n.words[0] = 0, n.length = 1, n;
1205
- var c = n.imul(f), g = c.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m), d = c.isub(g).iushrn(this.shift), w = d;
1206
- return d.cmp(this.m) >= 0 ? w = d.isub(this.m) : d.cmpn(0) < 0 && (w = d.iadd(this.m)), w._forceRed(this);
1207
- }, H.prototype.mul = function(n, f) {
1208
- if (n.isZero() || f.isZero()) return new o(0)._forceRed(this);
1209
- var c = n.mul(f), g = c.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m), d = c.isub(g).iushrn(this.shift), w = d;
1210
- return d.cmp(this.m) >= 0 ? w = d.isub(this.m) : d.cmpn(0) < 0 && (w = d.iadd(this.m)), w._forceRed(this);
1211
- }, H.prototype.invm = function(n) {
1212
- var f = this.imod(n._invmp(this.m).mul(this.r2));
1213
- return f._forceRed(this);
1214
- };
1215
- })(t, Js);
1216
- })(En);
1217
- var Fs = En.exports;
1218
- const X = /* @__PURE__ */ $s(Fs);
1219
- function Di(t) {
1220
- return X.isBN(t);
1221
- }
1222
- function Qs(t) {
1223
- return !!t && typeof t == "object";
1224
- }
1225
- function Pi(...t) {
1226
- return (e) => (Qs(e) || on(e)) && t.every((r) => on(e[r]));
1227
- }
1228
- const Zi = /* @__PURE__ */ Pi("toBigInt"), Vi = /* @__PURE__ */ Pi("toBn");
1229
- function tf(t) {
1230
- return typeof t == "bigint" ? t : t ? fe(t) ? js(t.toString()) : Di(t) ? F(t.toString()) : Zi(t) ? t.toBigInt() : Vi(t) ? F(t.toBn().toString()) : F(t) : F(0);
1231
- }
1232
- function $t(...t) {
1233
- const e = t.length, r = new Array(e);
1234
- let i = 0;
1235
- for (let a = 0; a < e; a++)
1236
- r[a] = G(t[a]), i += r[a].length;
1237
- return He(r, i);
1238
- }
1239
- function He(t, e = 0) {
1240
- const r = t.length;
1241
- let i = 0;
1242
- if (!e)
1243
- for (let o = 0; o < r; o++)
1244
- e += t[o].length;
1245
- const a = new Uint8Array(e);
1246
- for (let o = 0; o < r; o++)
1247
- a.set(t[o], i), i += t[o].length;
1248
- return a;
1249
- }
1250
- function zi(t) {
1251
- const e = t.length | 0;
1252
- for (let r = 0; r < e; r++)
1253
- if (t[r] | 0)
1254
- return !1;
1255
- return !0;
1256
- }
1257
- function jt(t, e) {
1258
- const r = G(t), i = G(e);
1259
- if (r.length === i.length) {
1260
- const a = new DataView(r.buffer, r.byteOffset), o = new DataView(i.buffer, i.byteOffset), l = r.length % 4 | 0, u = r.length - l | 0;
1261
- for (let m = 0; m < u; m += 4)
1262
- if (a.getUint32(m) !== o.getUint32(m))
1263
- return !1;
1264
- for (let m = u, b = r.length; m < b; m++)
1265
- if (r[m] !== i[m])
1266
- return !1;
1267
- return !0;
1268
- }
1269
- return !1;
1270
- }
1271
- function ef(t, e = -1, r = !1) {
1272
- const i = Math.ceil(e / 8);
1273
- if (e === -1 || t.length === i)
1274
- return t;
1275
- if (t.length > i)
1276
- return t.subarray(0, i);
1277
- const a = new Uint8Array(i);
1278
- return a.set(t, r ? 0 : i - t.length), a;
1279
- }
1280
- function qr(t, { isLe: e = !0, isNegative: r = !1 } = {}) {
1281
- e || (t = t.slice().reverse());
1282
- const i = t.length;
1283
- if (r && i && t[i - 1] & 128)
1284
- switch (i) {
1285
- case 0:
1286
- return new X(0);
1287
- case 1:
1288
- return new X((t[0] ^ 255) * -1 - 1);
1289
- case 2:
1290
- return new X((t[0] + (t[1] << 8) ^ 65535) * -1 - 1);
1291
- case 3:
1292
- return new X((t[0] + (t[1] << 8) + (t[2] << 16) ^ 16777215) * -1 - 1);
1293
- case 4:
1294
- return new X((t[0] + (t[1] << 8) + (t[2] << 16) + t[3] * 16777216 ^ 4294967295) * -1 - 1);
1295
- case 5:
1296
- return new X(((t[0] + (t[1] << 8) + (t[2] << 16) + t[3] * 16777216 ^ 4294967295) + (t[4] ^ 255) * 4294967296) * -1 - 1);
1297
- case 6:
1298
- return new X(((t[0] + (t[1] << 8) + (t[2] << 16) + t[3] * 16777216 ^ 4294967295) + (t[4] + (t[5] << 8) ^ 65535) * 4294967296) * -1 - 1);
1299
- default:
1300
- return new X(t, "le").fromTwos(i * 8);
1301
- }
1302
- switch (i) {
1303
- case 0:
1304
- return new X(0);
1305
- case 1:
1306
- return new X(t[0]);
1307
- case 2:
1308
- return new X(t[0] + (t[1] << 8));
1309
- case 3:
1310
- return new X(t[0] + (t[1] << 8) + (t[2] << 16));
1311
- case 4:
1312
- return new X(t[0] + (t[1] << 8) + (t[2] << 16) + t[3] * 16777216);
1313
- case 5:
1314
- return new X(t[0] + (t[1] << 8) + (t[2] << 16) + (t[3] + (t[4] << 8)) * 16777216);
1315
- case 6:
1316
- return new X(t[0] + (t[1] << 8) + (t[2] << 16) + (t[3] + (t[4] << 8) + (t[5] << 16)) * 16777216);
1317
- default:
1318
- return new X(t, "le");
1319
- }
1320
- }
1321
- const $r = /* @__PURE__ */ G(`Ethereum Signed Message:
1322
- `), Le = /* @__PURE__ */ G("<Bytes>"), Oe = /* @__PURE__ */ G("</Bytes>"), rf = Le.length + Oe.length;
1323
- function ir(t, e) {
1324
- return t.length >= rf && jt(t.subarray(0, Le.length), Le) && jt(t.slice(-Oe.length), Oe) || e && t.length >= $r.length && jt(t.subarray(0, $r.length), $r);
1325
- }
1326
- function nf(t) {
1327
- const e = G(t);
1328
- return ir(e, !1) ? e.subarray(Le.length, e.length - Oe.length) : e;
1329
- }
1330
- function of(t) {
1331
- const e = G(t);
1332
- return ir(e, !0) ? e : He([Le, e, Oe]);
1333
- }
1334
- const ni = F(256), sf = F(255);
1335
- function ff(t, e, r) {
1336
- const i = [], a = r && t < rr;
1337
- for (a && (t = (t + nr) * -nr); t !== rr; ) {
1338
- const o = t % ni, l = Number(a ? o ^ sf : o);
1339
- e ? i.push(l) : i.unshift(l), t = (t - o) / ni;
1340
- }
1341
- return Uint8Array.from(i);
1342
- }
1343
- function af(t, { bitLength: e = -1, isLe: r = !0, isNegative: i = !1 } = {}) {
1344
- const a = tf(t);
1345
- if (a === rr)
1346
- return e === -1 ? new Uint8Array(1) : new Uint8Array(Math.ceil((e || 0) / 8));
1347
- const o = ff(a, r, i);
1348
- if (e === -1)
1349
- return o;
1350
- const l = Math.ceil((e || 0) / 8), u = new Uint8Array(l);
1351
- return i && u.fill(255), u.set(o, r ? 0 : l - o.length), u;
1352
- }
1353
- function cf(t) {
1354
- if (!t || t === "0x")
1355
- return "";
1356
- if (ss.test(t))
1357
- return t.substring(2);
1358
- if (fs.test(t))
1359
- return t;
1360
- throw new Error(`Expected hex value to convert, found '${t}'`);
1361
- }
1362
- function hf(t, { isLe: e = !1, isNegative: r = !1 } = {}) {
1363
- if (!t || t === "0x")
1364
- return new X(0);
1365
- const i = cf(t), a = new X(i, 16, e ? "le" : "be");
1366
- return r ? a.fromTwos(i.length * 4) : a;
1367
- }
1368
- const dr = /* @__PURE__ */ new X(1), wr = /* @__PURE__ */ new X(2), ii = /* @__PURE__ */ new X(1e9);
1369
- ii.mul(ii);
1370
- Number.MAX_SAFE_INTEGER;
1371
- function Gi(t) {
1372
- return typeof t == "bigint";
1373
- }
1374
- function Yi(t) {
1375
- return t ? X.isBN(t) ? t : fe(t) ? hf(t.toString()) : Gi(t) ? new X(t.toString()) : Vi(t) ? t.toBn() : Zi(t) ? new X(t.toBigInt().toString()) : new X(t) : new X(0);
1376
- }
1377
- const lf = { bitLength: -1, isLe: !0, isNegative: !1 };
1378
- function Gt(t, { bitLength: e = -1, isLe: r = !0, isNegative: i = !1 } = lf) {
1379
- const a = Yi(t), o = Math.ceil(e === -1 ? a.bitLength() / 8 : (e || 0) / 8);
1380
- if (!t)
1381
- return e === -1 ? new Uint8Array(1) : new Uint8Array(o);
1382
- const l = new Uint8Array(o), u = i ? a.toTwos(o * 8) : a;
1383
- return l.set(u.toArray(r ? "le" : "be", o), 0), l;
1384
- }
1385
- const uf = wr.pow(new X(6)).isub(dr), df = wr.pow(new X(14)).isub(dr), wf = wr.pow(new X(30)).isub(dr), gf = { bitLength: 16 }, mf = { bitLength: 32 };
1386
- function pf(t) {
1387
- const e = Yi(t);
1388
- if (e.lte(uf))
1389
- return new Uint8Array([e.toNumber() << 2]);
1390
- if (e.lte(df))
1391
- return Gt(e.shln(2).iadd(dr), gf);
1392
- if (e.lte(wf))
1393
- return Gt(e.shln(2).iadd(wr), mf);
1394
- const r = Gt(e);
1395
- let i = r.length;
1396
- for (; r[i - 1] === 0; )
1397
- i--;
1398
- if (i < 4)
1399
- throw new Error("Invalid length, previous checks match anything less than 2^30");
1400
- return He([
1401
- // subtract 4 as minimum (also catered for in decoding)
1402
- new Uint8Array([(i - 4 << 2) + 3]),
1403
- r.subarray(0, i)
1404
- ]);
1405
- }
1406
- function _n(t) {
1407
- return He([
1408
- pf(t.length),
1409
- t
1410
- ]);
1411
- }
1412
- function yf(t) {
1413
- return typeof t == "string" || t instanceof String;
1414
- }
1415
- function xf(t) {
1416
- return typeof t == "number";
1417
- }
1418
- const vf = { name: "@polkadot/util-crypto", path: import.meta && import.meta.url ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf("/") + 1) : "auto", type: "esm", version: "12.6.2" };
1419
- function Mn(t) {
1420
- return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
1421
- }
1422
- function bf(t, ...e) {
1423
- if (!Mn(t))
1424
- throw new Error("Uint8Array expected");
1425
- if (e.length > 0 && !e.includes(t.length))
1426
- throw new Error("Uint8Array expected of length " + e + ", got length=" + t.length);
1427
- }
1428
- function Wi(t, e) {
1429
- return Array.isArray(e) ? e.length === 0 ? !0 : t ? e.every((r) => typeof r == "string") : e.every((r) => Number.isSafeInteger(r)) : !1;
1430
- }
1431
- function Te(t, e) {
1432
- if (typeof e != "string")
1433
- throw new Error(`${t}: string expected`);
1434
- return !0;
1435
- }
1436
- function qe(t) {
1437
- if (!Number.isSafeInteger(t))
1438
- throw new Error(`invalid integer: ${t}`);
1439
- }
1440
- function or(t) {
1441
- if (!Array.isArray(t))
1442
- throw new Error("array expected");
1443
- }
1444
- function sr(t, e) {
1445
- if (!Wi(!0, e))
1446
- throw new Error(`${t}: array of strings expected`);
1447
- }
1448
- function Xi(t, e) {
1449
- if (!Wi(!1, e))
1450
- throw new Error(`${t}: array of numbers expected`);
1451
- }
1452
- // @__NO_SIDE_EFFECTS__
1453
- function Ki(...t) {
1454
- const e = (o) => o, r = (o, l) => (u) => o(l(u)), i = t.map((o) => o.encode).reduceRight(r, e), a = t.map((o) => o.decode).reduce(r, e);
1455
- return { encode: i, decode: a };
1456
- }
1457
- // @__NO_SIDE_EFFECTS__
1458
- function ji(t) {
1459
- const e = typeof t == "string" ? t.split("") : t, r = e.length;
1460
- sr("alphabet", e);
1461
- const i = new Map(e.map((a, o) => [a, o]));
1462
- return {
1463
- encode: (a) => (or(a), a.map((o) => {
1464
- if (!Number.isSafeInteger(o) || o < 0 || o >= r)
1465
- throw new Error(`alphabet.encode: digit index outside alphabet "${o}". Allowed: ${t}`);
1466
- return e[o];
1467
- })),
1468
- decode: (a) => (or(a), a.map((o) => {
1469
- Te("alphabet.decode", o);
1470
- const l = i.get(o);
1471
- if (l === void 0)
1472
- throw new Error(`Unknown letter: "${o}". Allowed: ${t}`);
1473
- return l;
1474
- }))
1475
- };
1476
- }
1477
- // @__NO_SIDE_EFFECTS__
1478
- function Ji(t = "") {
1479
- return Te("join", t), {
1480
- encode: (e) => (sr("join.decode", e), e.join(t)),
1481
- decode: (e) => (Te("join.decode", e), e.split(t))
1482
- };
1483
- }
1484
- // @__NO_SIDE_EFFECTS__
1485
- function Ef(t, e = "=") {
1486
- return qe(t), Te("padding", e), {
1487
- encode(r) {
1488
- for (sr("padding.encode", r); r.length * t % 8; )
1489
- r.push(e);
1490
- return r;
1491
- },
1492
- decode(r) {
1493
- sr("padding.decode", r);
1494
- let i = r.length;
1495
- if (i * t % 8)
1496
- throw new Error("padding: invalid, string should have whole number of bytes");
1497
- for (; i > 0 && r[i - 1] === e; i--)
1498
- if ((i - 1) * t % 8 === 0)
1499
- throw new Error("padding: invalid, string has too much padding");
1500
- return r.slice(0, i);
1501
- }
1502
- };
1503
- }
1504
- function oi(t, e, r) {
1505
- if (e < 2)
1506
- throw new Error(`convertRadix: invalid from=${e}, base cannot be less than 2`);
1507
- if (r < 2)
1508
- throw new Error(`convertRadix: invalid to=${r}, base cannot be less than 2`);
1509
- if (or(t), !t.length)
1510
- return [];
1511
- let i = 0;
1512
- const a = [], o = Array.from(t, (u) => {
1513
- if (qe(u), u < 0 || u >= e)
1514
- throw new Error(`invalid integer: ${u}`);
1515
- return u;
1516
- }), l = o.length;
1517
- for (; ; ) {
1518
- let u = 0, m = !0;
1519
- for (let b = i; b < l; b++) {
1520
- const v = o[b], E = e * u, M = E + v;
1521
- if (!Number.isSafeInteger(M) || E / e !== u || M - v !== E)
1522
- throw new Error("convertRadix: carry overflow");
1523
- const S = M / r;
1524
- u = M % r;
1525
- const O = Math.floor(S);
1526
- if (o[b] = O, !Number.isSafeInteger(O) || O * r + u !== M)
1527
- throw new Error("convertRadix: carry overflow");
1528
- if (m)
1529
- O ? m = !1 : i = b;
1530
- else continue;
1531
- }
1532
- if (a.push(u), m)
1533
- break;
1534
- }
1535
- for (let u = 0; u < t.length - 1 && t[u] === 0; u++)
1536
- a.push(0);
1537
- return a.reverse();
1538
- }
1539
- const Fi = (t, e) => e === 0 ? t : Fi(e, t % e), fr = /* @__NO_SIDE_EFFECTS__ */ (t, e) => t + (e - Fi(t, e)), Cr = /* @__PURE__ */ (() => {
1540
- let t = [];
1541
- for (let e = 0; e < 40; e++)
1542
- t.push(2 ** e);
1543
- return t;
1544
- })();
1545
- function si(t, e, r, i) {
1546
- if (or(t), e <= 0 || e > 32)
1547
- throw new Error(`convertRadix2: wrong from=${e}`);
1548
- if (r <= 0 || r > 32)
1549
- throw new Error(`convertRadix2: wrong to=${r}`);
1550
- if (/* @__PURE__ */ fr(e, r) > 32)
1551
- throw new Error(`convertRadix2: carry overflow from=${e} to=${r} carryBits=${/* @__PURE__ */ fr(e, r)}`);
1552
- let a = 0, o = 0;
1553
- const l = Cr[e], u = Cr[r] - 1, m = [];
1554
- for (const b of t) {
1555
- if (qe(b), b >= l)
1556
- throw new Error(`convertRadix2: invalid data word=${b} from=${e}`);
1557
- if (a = a << e | b, o + e > 32)
1558
- throw new Error(`convertRadix2: carry overflow pos=${o} from=${e}`);
1559
- for (o += e; o >= r; o -= r)
1560
- m.push((a >> o - r & u) >>> 0);
1561
- const v = Cr[o];
1562
- if (v === void 0)
1563
- throw new Error("invalid carry");
1564
- a &= v - 1;
1565
- }
1566
- if (a = a << r - o & u, !i && o >= e)
1567
- throw new Error("Excess padding");
1568
- if (!i && a > 0)
1569
- throw new Error(`Non-zero padding: ${a}`);
1570
- return i && o > 0 && m.push(a >>> 0), m;
1571
- }
1572
- // @__NO_SIDE_EFFECTS__
1573
- function _f(t) {
1574
- qe(t);
1575
- const e = 2 ** 8;
1576
- return {
1577
- encode: (r) => {
1578
- if (!Mn(r))
1579
- throw new Error("radix.encode input should be Uint8Array");
1580
- return oi(Array.from(r), e, t);
1581
- },
1582
- decode: (r) => (Xi("radix.decode", r), Uint8Array.from(oi(r, t, e)))
1583
- };
1584
- }
1585
- // @__NO_SIDE_EFFECTS__
1586
- function Mf(t, e = !1) {
1587
- if (qe(t), t <= 0 || t > 32)
1588
- throw new Error("radix2: bits should be in (0..32]");
1589
- if (/* @__PURE__ */ fr(8, t) > 32 || /* @__PURE__ */ fr(t, 8) > 32)
1590
- throw new Error("radix2: carry overflow");
1591
- return {
1592
- encode: (r) => {
1593
- if (!Mn(r))
1594
- throw new Error("radix2.encode input should be Uint8Array");
1595
- return si(Array.from(r), 8, t, !e);
1596
- },
1597
- decode: (r) => (Xi("radix2.decode", r), Uint8Array.from(si(r, t, 8, e)))
1598
- };
1599
- }
1600
- const Af = typeof Uint8Array.from([]).toBase64 == "function" && typeof Uint8Array.fromBase64 == "function", Bf = (t, e) => {
1601
- Te("base64", t);
1602
- const r = /^[A-Za-z0-9=+/]+$/, i = "base64";
1603
- if (t.length > 0 && !r.test(t))
1604
- throw new Error("invalid base64");
1605
- return Uint8Array.fromBase64(t, { alphabet: i, lastChunkHandling: "strict" });
1606
- }, Sf = Af ? {
1607
- encode(t) {
1608
- return bf(t), t.toBase64();
1609
- },
1610
- decode(t) {
1611
- return Bf(t);
1612
- }
1613
- } : /* @__PURE__ */ Ki(/* @__PURE__ */ Mf(6), /* @__PURE__ */ ji("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ Ef(6), /* @__PURE__ */ Ji("")), If = /* @__NO_SIDE_EFFECTS__ */ (t) => /* @__PURE__ */ Ki(/* @__PURE__ */ _f(58), /* @__PURE__ */ ji(t), /* @__PURE__ */ Ji("")), Uf = /* @__PURE__ */ If("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
1614
- function Qi({ coder: t, ipfs: e }, r) {
1615
- return (i, a) => (r(i, a), t.decode(e && a ? i.substring(1) : i));
1616
- }
1617
- function to({ coder: t, ipfs: e }) {
1618
- return (r, i) => {
1619
- const a = t.encode(G(r));
1620
- return e && i ? `${e}${a}` : a;
1621
- };
1622
- }
1623
- function eo({ chars: t, ipfs: e, type: r, withPadding: i }) {
1624
- return (a, o) => {
1625
- if (typeof a != "string")
1626
- throw new Error(`Expected ${r} string input`);
1627
- if (e && o && !a.startsWith(e))
1628
- throw new Error(`Expected ipfs-compatible ${r} to start with '${e}'`);
1629
- for (let l = o ? 1 : 0, u = a.length; l < u; l++)
1630
- if (!t.includes(a[l])) if (i && a[l] === "=") {
1631
- if (l !== u - 1) {
1632
- if (a[l + 1] !== "=") throw new Error(`Invalid ${r} padding sequence "${a[l]}${a[l + 1]}" at index ${l}`);
1633
- }
1634
- } else
1635
- throw new Error(`Invalid ${r} character "${a[l]}" (0x${a.charCodeAt(l).toString(16)}) at index ${l}`);
1636
- return !0;
1637
- };
1638
- }
1639
- const An = {
1640
- chars: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",
1641
- coder: Uf,
1642
- ipfs: "z",
1643
- type: "base58"
1644
- }, kf = /* @__PURE__ */ eo(An), Nf = /* @__PURE__ */ Qi(An, kf), Rf = /* @__PURE__ */ to(An), Lf = ce("SS58PRE");
1645
- function ro(t) {
1646
- return we($t(Lf, t), 512);
1647
- }
1648
- function Of(t) {
1649
- const e = t[0] & 64 ? 2 : 1, r = e === 1 ? t[0] : (t[0] & 63) << 2 | t[1] >> 6 | (t[1] & 63) << 8, i = [34 + e, 35 + e].includes(t.length), a = t.length - (i ? 2 : 1), o = ro(t.subarray(0, a));
1650
- return [(t[0] & 128) === 0 && ![46, 47].includes(t[0]) && (i ? t[t.length - 2] === o[0] && t[t.length - 1] === o[1] : t[t.length - 1] === o[0]), a, e, r];
1651
- }
1652
- const Fe = {
1653
- allowedDecodedLengths: [1, 2, 4, 8, 32, 33],
1654
- // publicKey has prefix + 2 checksum bytes, short only prefix + 1 checksum byte
1655
- allowedEncodedLengths: [3, 4, 6, 10, 35, 36, 37, 38],
1656
- prefix: 42
1657
- };
1658
- function be(t, e, r = -1) {
1659
- if (!t)
1660
- throw new Error("Invalid empty address passed");
1661
- if (de(t) || fe(t))
1662
- return G(t);
1663
- try {
1664
- const i = Nf(t);
1665
- if (!Fe.allowedEncodedLengths.includes(i.length))
1666
- throw new Error("Invalid decoded address length");
1667
- const [a, o, l, u] = Of(i);
1668
- if (!a && !e)
1669
- throw new Error("Invalid decoded address checksum");
1670
- if (r !== -1 && r !== u)
1671
- throw new Error(`Expected ss58Format ${r}, received ${u}`);
1672
- return i.slice(l, o);
1673
- } catch (i) {
1674
- throw new Error(`Decoding ${t}: ${i.message}`);
1675
- }
1676
- }
1677
- const fi = { isLe: !1 }, Dr = { isLe: !0 }, Tf = { bitLength: 32, isLe: !1 }, Pr = { bitLength: 32, isLe: !0 }, Ee = { bitLength: 256, isLe: !1 }, Hf = { bitLength: 256, isLe: !0 }, qf = /^\d+$/, $f = 32;
1678
- class Bn {
1679
- constructor() {
1680
- Jt(this, "__internal__chainCode", new Uint8Array(32));
1681
- Jt(this, "__internal__isHard", !1);
1682
- }
1683
- static from(e) {
1684
- const r = new Bn(), [i, a] = e.startsWith("/") ? [e.substring(1), !0] : [e, !1];
1685
- return r.soft(qf.test(i) ? new X(i, 10) : i), a ? r.harden() : r;
1686
- }
1687
- get chainCode() {
1688
- return this.__internal__chainCode;
1689
- }
1690
- get isHard() {
1691
- return this.__internal__isHard;
1692
- }
1693
- get isSoft() {
1694
- return !this.__internal__isHard;
1695
- }
1696
- hard(e) {
1697
- return this.soft(e).harden();
1698
- }
1699
- harden() {
1700
- return this.__internal__isHard = !0, this;
1701
- }
1702
- soft(e) {
1703
- return xf(e) || Di(e) || Gi(e) ? this.soft(Gt(e, Hf)) : fe(e) ? this.soft(ke(e)) : yf(e) ? this.soft(_n(ce(e))) : e.length > $f ? this.soft(we(e)) : (this.__internal__chainCode.fill(0), this.__internal__chainCode.set(e, 0), this);
1704
- }
1705
- soften() {
1706
- return this.__internal__isHard = !1, this;
1707
- }
1708
- }
1709
- const Cf = /\/(\/?)([^/]+)/g;
1710
- function no(t) {
1711
- const e = t.match(Cf), r = [];
1712
- let i = "";
1713
- if (e) {
1714
- i = e.join("");
1715
- for (const a of e)
1716
- r.push(Bn.from(a.substring(1)));
1717
- }
1718
- if (i !== t)
1719
- throw new Error(`Re-constructed path "${i}" does not match input`);
1720
- return {
1721
- parts: e,
1722
- path: r
1723
- };
1724
- }
1725
- const Df = /^(\w+( \w+)*)((\/\/?[^/]+)*)(\/\/\/(.*))?$/;
1726
- function Pf(t) {
1727
- const e = t.match(Df);
1728
- if (e === null)
1729
- throw new Error("Unable to match provided value to a secret URI");
1730
- const [, r, , i, , , a] = e, { path: o } = no(i);
1731
- return {
1732
- derivePath: i,
1733
- password: a,
1734
- path: o,
1735
- phrase: r
1736
- };
1737
- }
1738
- const Zf = _n(ce("Secp256k1HDKD"));
1739
- function Vf(t, e) {
1740
- if (!de(e) || e.length !== 32)
1741
- throw new Error("Invalid chainCode passed to derive");
1742
- return we($t(Zf, t, e), 256);
1743
- }
1744
- const ge = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
1745
- function zf(t) {
1746
- return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
1747
- }
1748
- function fn(t) {
1749
- if (!Number.isSafeInteger(t) || t < 0)
1750
- throw new Error("positive integer expected, got " + t);
1751
- }
1752
- function $e(t, ...e) {
1753
- if (!zf(t))
1754
- throw new Error("Uint8Array expected");
1755
- if (e.length > 0 && !e.includes(t.length))
1756
- throw new Error("Uint8Array expected of length " + e + ", got length=" + t.length);
1757
- }
1758
- function Gf(t) {
1759
- if (typeof t != "function" || typeof t.create != "function")
1760
- throw new Error("Hash should be wrapped by utils.createHasher");
1761
- fn(t.outputLen), fn(t.blockLen);
1762
- }
1763
- function ar(t, e = !0) {
1764
- if (t.destroyed)
1765
- throw new Error("Hash instance has been destroyed");
1766
- if (e && t.finished)
1767
- throw new Error("Hash#digest() has already been called");
1768
- }
1769
- function Yf(t, e) {
1770
- $e(t);
1771
- const r = e.outputLen;
1772
- if (t.length < r)
1773
- throw new Error("digestInto() expects output buffer of length at least " + r);
1774
- }
1775
- function _e(...t) {
1776
- for (let e = 0; e < t.length; e++)
1777
- t[e].fill(0);
1778
- }
1779
- function Zr(t) {
1780
- return new DataView(t.buffer, t.byteOffset, t.byteLength);
1781
- }
1782
- function Xt(t, e) {
1783
- return t << 32 - e | t >>> e;
1784
- }
1785
- function Wf(t) {
1786
- if (typeof t != "string")
1787
- throw new Error("string expected");
1788
- return new Uint8Array(new TextEncoder().encode(t));
1789
- }
1790
- function Sn(t) {
1791
- return typeof t == "string" && (t = Wf(t)), $e(t), t;
1792
- }
1793
- function Xf(...t) {
1794
- let e = 0;
1795
- for (let i = 0; i < t.length; i++) {
1796
- const a = t[i];
1797
- $e(a), e += a.length;
1798
- }
1799
- const r = new Uint8Array(e);
1800
- for (let i = 0, a = 0; i < t.length; i++) {
1801
- const o = t[i];
1802
- r.set(o, a), a += o.length;
1803
- }
1804
- return r;
1805
- }
1806
- class io {
1807
- }
1808
- function oo(t) {
1809
- const e = (i) => t().update(Sn(i)).digest(), r = t();
1810
- return e.outputLen = r.outputLen, e.blockLen = r.blockLen, e.create = () => t(), e;
1811
- }
1812
- function so(t = 32) {
1813
- if (ge && typeof ge.getRandomValues == "function")
1814
- return ge.getRandomValues(new Uint8Array(t));
1815
- if (ge && typeof ge.randomBytes == "function")
1816
- return Uint8Array.from(ge.randomBytes(t));
1817
- throw new Error("crypto.getRandomValues must be defined");
1818
- }
1819
- function Kf(t, e, r, i) {
1820
- if (typeof t.setBigUint64 == "function")
1821
- return t.setBigUint64(e, r, i);
1822
- const a = BigInt(32), o = BigInt(4294967295), l = Number(r >> a & o), u = Number(r & o), m = i ? 4 : 0, b = i ? 0 : 4;
1823
- t.setUint32(e + m, l, i), t.setUint32(e + b, u, i);
1824
- }
1825
- function jf(t, e, r) {
1826
- return t & e ^ ~t & r;
1827
- }
1828
- function Jf(t, e, r) {
1829
- return t & e ^ t & r ^ e & r;
1830
- }
1831
- class fo extends io {
1832
- constructor(e, r, i, a) {
1833
- super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = e, this.outputLen = r, this.padOffset = i, this.isLE = a, this.buffer = new Uint8Array(e), this.view = Zr(this.buffer);
1834
- }
1835
- update(e) {
1836
- ar(this), e = Sn(e), $e(e);
1837
- const { view: r, buffer: i, blockLen: a } = this, o = e.length;
1838
- for (let l = 0; l < o; ) {
1839
- const u = Math.min(a - this.pos, o - l);
1840
- if (u === a) {
1841
- const m = Zr(e);
1842
- for (; a <= o - l; l += a)
1843
- this.process(m, l);
1844
- continue;
1845
- }
1846
- i.set(e.subarray(l, l + u), this.pos), this.pos += u, l += u, this.pos === a && (this.process(r, 0), this.pos = 0);
1847
- }
1848
- return this.length += e.length, this.roundClean(), this;
1849
- }
1850
- digestInto(e) {
1851
- ar(this), Yf(e, this), this.finished = !0;
1852
- const { buffer: r, view: i, blockLen: a, isLE: o } = this;
1853
- let { pos: l } = this;
1854
- r[l++] = 128, _e(this.buffer.subarray(l)), this.padOffset > a - l && (this.process(i, 0), l = 0);
1855
- for (let E = l; E < a; E++)
1856
- r[E] = 0;
1857
- Kf(i, a - 8, BigInt(this.length * 8), o), this.process(i, 0);
1858
- const u = Zr(e), m = this.outputLen;
1859
- if (m % 4)
1860
- throw new Error("_sha2: outputLen should be aligned to 32bit");
1861
- const b = m / 4, v = this.get();
1862
- if (b > v.length)
1863
- throw new Error("_sha2: outputLen bigger than state");
1864
- for (let E = 0; E < b; E++)
1865
- u.setUint32(4 * E, v[E], o);
1866
- }
1867
- digest() {
1868
- const { buffer: e, outputLen: r } = this;
1869
- this.digestInto(e);
1870
- const i = e.slice(0, r);
1871
- return this.destroy(), i;
1872
- }
1873
- _cloneInto(e) {
1874
- e || (e = new this.constructor()), e.set(...this.get());
1875
- const { blockLen: r, buffer: i, length: a, finished: o, destroyed: l, pos: u } = this;
1876
- return e.destroyed = l, e.finished = o, e.length = a, e.pos = u, a % r && e.buffer.set(i), e;
1877
- }
1878
- clone() {
1879
- return this._cloneInto();
1880
- }
1881
- }
1882
- const re = /* @__PURE__ */ Uint32Array.from([
1883
- 1779033703,
1884
- 3144134277,
1885
- 1013904242,
1886
- 2773480762,
1887
- 1359893119,
1888
- 2600822924,
1889
- 528734635,
1890
- 1541459225
1891
- ]);
1892
- const Dt = /* @__PURE__ */ Uint32Array.from([
1893
- 1779033703,
1894
- 4089235720,
1895
- 3144134277,
1896
- 2227873595,
1897
- 1013904242,
1898
- 4271175723,
1899
- 2773480762,
1900
- 1595750129,
1901
- 1359893119,
1902
- 2917565137,
1903
- 2600822924,
1904
- 725511199,
1905
- 528734635,
1906
- 4215389547,
1907
- 1541459225,
1908
- 327033209
1909
- ]), Ge = /* @__PURE__ */ BigInt(2 ** 32 - 1), ai = /* @__PURE__ */ BigInt(32);
1910
- function Ff(t, e = !1) {
1911
- return e ? { h: Number(t & Ge), l: Number(t >> ai & Ge) } : { h: Number(t >> ai & Ge) | 0, l: Number(t & Ge) | 0 };
1912
- }
1913
- function Qf(t, e = !1) {
1914
- const r = t.length;
1915
- let i = new Uint32Array(r), a = new Uint32Array(r);
1916
- for (let o = 0; o < r; o++) {
1917
- const { h: l, l: u } = Ff(t[o], e);
1918
- [i[o], a[o]] = [l, u];
1919
- }
1920
- return [i, a];
1921
- }
1922
- const ci = (t, e, r) => t >>> r, hi = (t, e, r) => t << 32 - r | e >>> r, me = (t, e, r) => t >>> r | e << 32 - r, pe = (t, e, r) => t << 32 - r | e >>> r, Ye = (t, e, r) => t << 64 - r | e >>> r - 32, We = (t, e, r) => t >>> r - 32 | e << 64 - r;
1923
- function Ft(t, e, r, i) {
1924
- const a = (e >>> 0) + (i >>> 0);
1925
- return { h: t + r + (a / 2 ** 32 | 0) | 0, l: a | 0 };
1926
- }
1927
- const t0 = (t, e, r) => (t >>> 0) + (e >>> 0) + (r >>> 0), e0 = (t, e, r, i) => e + r + i + (t / 2 ** 32 | 0) | 0, r0 = (t, e, r, i) => (t >>> 0) + (e >>> 0) + (r >>> 0) + (i >>> 0), n0 = (t, e, r, i, a) => e + r + i + a + (t / 2 ** 32 | 0) | 0, i0 = (t, e, r, i, a) => (t >>> 0) + (e >>> 0) + (r >>> 0) + (i >>> 0) + (a >>> 0), o0 = (t, e, r, i, a, o) => e + r + i + a + o + (t / 2 ** 32 | 0) | 0, s0 = /* @__PURE__ */ Uint32Array.from([
1928
- 1116352408,
1929
- 1899447441,
1930
- 3049323471,
1931
- 3921009573,
1932
- 961987163,
1933
- 1508970993,
1934
- 2453635748,
1935
- 2870763221,
1936
- 3624381080,
1937
- 310598401,
1938
- 607225278,
1939
- 1426881987,
1940
- 1925078388,
1941
- 2162078206,
1942
- 2614888103,
1943
- 3248222580,
1944
- 3835390401,
1945
- 4022224774,
1946
- 264347078,
1947
- 604807628,
1948
- 770255983,
1949
- 1249150122,
1950
- 1555081692,
1951
- 1996064986,
1952
- 2554220882,
1953
- 2821834349,
1954
- 2952996808,
1955
- 3210313671,
1956
- 3336571891,
1957
- 3584528711,
1958
- 113926993,
1959
- 338241895,
1960
- 666307205,
1961
- 773529912,
1962
- 1294757372,
1963
- 1396182291,
1964
- 1695183700,
1965
- 1986661051,
1966
- 2177026350,
1967
- 2456956037,
1968
- 2730485921,
1969
- 2820302411,
1970
- 3259730800,
1971
- 3345764771,
1972
- 3516065817,
1973
- 3600352804,
1974
- 4094571909,
1975
- 275423344,
1976
- 430227734,
1977
- 506948616,
1978
- 659060556,
1979
- 883997877,
1980
- 958139571,
1981
- 1322822218,
1982
- 1537002063,
1983
- 1747873779,
1984
- 1955562222,
1985
- 2024104815,
1986
- 2227730452,
1987
- 2361852424,
1988
- 2428436474,
1989
- 2756734187,
1990
- 3204031479,
1991
- 3329325298
1992
- ]), ne = /* @__PURE__ */ new Uint32Array(64);
1993
- class f0 extends fo {
1994
- constructor(e = 32) {
1995
- super(64, e, 8, !1), this.A = re[0] | 0, this.B = re[1] | 0, this.C = re[2] | 0, this.D = re[3] | 0, this.E = re[4] | 0, this.F = re[5] | 0, this.G = re[6] | 0, this.H = re[7] | 0;
1996
- }
1997
- get() {
1998
- const { A: e, B: r, C: i, D: a, E: o, F: l, G: u, H: m } = this;
1999
- return [e, r, i, a, o, l, u, m];
2000
- }
2001
- // prettier-ignore
2002
- set(e, r, i, a, o, l, u, m) {
2003
- this.A = e | 0, this.B = r | 0, this.C = i | 0, this.D = a | 0, this.E = o | 0, this.F = l | 0, this.G = u | 0, this.H = m | 0;
2004
- }
2005
- process(e, r) {
2006
- for (let E = 0; E < 16; E++, r += 4)
2007
- ne[E] = e.getUint32(r, !1);
2008
- for (let E = 16; E < 64; E++) {
2009
- const M = ne[E - 15], S = ne[E - 2], O = Xt(M, 7) ^ Xt(M, 18) ^ M >>> 3, A = Xt(S, 17) ^ Xt(S, 19) ^ S >>> 10;
2010
- ne[E] = A + ne[E - 7] + O + ne[E - 16] | 0;
2011
- }
2012
- let { A: i, B: a, C: o, D: l, E: u, F: m, G: b, H: v } = this;
2013
- for (let E = 0; E < 64; E++) {
2014
- const M = Xt(u, 6) ^ Xt(u, 11) ^ Xt(u, 25), S = v + M + jf(u, m, b) + s0[E] + ne[E] | 0, A = (Xt(i, 2) ^ Xt(i, 13) ^ Xt(i, 22)) + Jf(i, a, o) | 0;
2015
- v = b, b = m, m = u, u = l + S | 0, l = o, o = a, a = i, i = S + A | 0;
2016
- }
2017
- i = i + this.A | 0, a = a + this.B | 0, o = o + this.C | 0, l = l + this.D | 0, u = u + this.E | 0, m = m + this.F | 0, b = b + this.G | 0, v = v + this.H | 0, this.set(i, a, o, l, u, m, b, v);
2018
- }
2019
- roundClean() {
2020
- _e(ne);
2021
- }
2022
- destroy() {
2023
- this.set(0, 0, 0, 0, 0, 0, 0, 0), _e(this.buffer);
2024
- }
2025
- }
2026
- const ao = Qf([
2027
- "0x428a2f98d728ae22",
2028
- "0x7137449123ef65cd",
2029
- "0xb5c0fbcfec4d3b2f",
2030
- "0xe9b5dba58189dbbc",
2031
- "0x3956c25bf348b538",
2032
- "0x59f111f1b605d019",
2033
- "0x923f82a4af194f9b",
2034
- "0xab1c5ed5da6d8118",
2035
- "0xd807aa98a3030242",
2036
- "0x12835b0145706fbe",
2037
- "0x243185be4ee4b28c",
2038
- "0x550c7dc3d5ffb4e2",
2039
- "0x72be5d74f27b896f",
2040
- "0x80deb1fe3b1696b1",
2041
- "0x9bdc06a725c71235",
2042
- "0xc19bf174cf692694",
2043
- "0xe49b69c19ef14ad2",
2044
- "0xefbe4786384f25e3",
2045
- "0x0fc19dc68b8cd5b5",
2046
- "0x240ca1cc77ac9c65",
2047
- "0x2de92c6f592b0275",
2048
- "0x4a7484aa6ea6e483",
2049
- "0x5cb0a9dcbd41fbd4",
2050
- "0x76f988da831153b5",
2051
- "0x983e5152ee66dfab",
2052
- "0xa831c66d2db43210",
2053
- "0xb00327c898fb213f",
2054
- "0xbf597fc7beef0ee4",
2055
- "0xc6e00bf33da88fc2",
2056
- "0xd5a79147930aa725",
2057
- "0x06ca6351e003826f",
2058
- "0x142929670a0e6e70",
2059
- "0x27b70a8546d22ffc",
2060
- "0x2e1b21385c26c926",
2061
- "0x4d2c6dfc5ac42aed",
2062
- "0x53380d139d95b3df",
2063
- "0x650a73548baf63de",
2064
- "0x766a0abb3c77b2a8",
2065
- "0x81c2c92e47edaee6",
2066
- "0x92722c851482353b",
2067
- "0xa2bfe8a14cf10364",
2068
- "0xa81a664bbc423001",
2069
- "0xc24b8b70d0f89791",
2070
- "0xc76c51a30654be30",
2071
- "0xd192e819d6ef5218",
2072
- "0xd69906245565a910",
2073
- "0xf40e35855771202a",
2074
- "0x106aa07032bbd1b8",
2075
- "0x19a4c116b8d2d0c8",
2076
- "0x1e376c085141ab53",
2077
- "0x2748774cdf8eeb99",
2078
- "0x34b0bcb5e19b48a8",
2079
- "0x391c0cb3c5c95a63",
2080
- "0x4ed8aa4ae3418acb",
2081
- "0x5b9cca4f7763e373",
2082
- "0x682e6ff3d6b2b8a3",
2083
- "0x748f82ee5defb2fc",
2084
- "0x78a5636f43172f60",
2085
- "0x84c87814a1f0ab72",
2086
- "0x8cc702081a6439ec",
2087
- "0x90befffa23631e28",
2088
- "0xa4506cebde82bde9",
2089
- "0xbef9a3f7b2c67915",
2090
- "0xc67178f2e372532b",
2091
- "0xca273eceea26619c",
2092
- "0xd186b8c721c0c207",
2093
- "0xeada7dd6cde0eb1e",
2094
- "0xf57d4f7fee6ed178",
2095
- "0x06f067aa72176fba",
2096
- "0x0a637dc5a2c898a6",
2097
- "0x113f9804bef90dae",
2098
- "0x1b710b35131c471b",
2099
- "0x28db77f523047d84",
2100
- "0x32caab7b40c72493",
2101
- "0x3c9ebe0a15c9bebc",
2102
- "0x431d67c49c100d4c",
2103
- "0x4cc5d4becb3e42b6",
2104
- "0x597f299cfc657e2a",
2105
- "0x5fcb6fab3ad6faec",
2106
- "0x6c44198c4a475817"
2107
- ].map((t) => BigInt(t))), a0 = ao[0], c0 = ao[1], ie = /* @__PURE__ */ new Uint32Array(80), oe = /* @__PURE__ */ new Uint32Array(80);
2108
- class h0 extends fo {
2109
- constructor(e = 64) {
2110
- super(128, e, 16, !1), this.Ah = Dt[0] | 0, this.Al = Dt[1] | 0, this.Bh = Dt[2] | 0, this.Bl = Dt[3] | 0, this.Ch = Dt[4] | 0, this.Cl = Dt[5] | 0, this.Dh = Dt[6] | 0, this.Dl = Dt[7] | 0, this.Eh = Dt[8] | 0, this.El = Dt[9] | 0, this.Fh = Dt[10] | 0, this.Fl = Dt[11] | 0, this.Gh = Dt[12] | 0, this.Gl = Dt[13] | 0, this.Hh = Dt[14] | 0, this.Hl = Dt[15] | 0;
2111
- }
2112
- // prettier-ignore
2113
- get() {
2114
- const { Ah: e, Al: r, Bh: i, Bl: a, Ch: o, Cl: l, Dh: u, Dl: m, Eh: b, El: v, Fh: E, Fl: M, Gh: S, Gl: O, Hh: A, Hl: D } = this;
2115
- return [e, r, i, a, o, l, u, m, b, v, E, M, S, O, A, D];
2116
- }
2117
- // prettier-ignore
2118
- set(e, r, i, a, o, l, u, m, b, v, E, M, S, O, A, D) {
2119
- this.Ah = e | 0, this.Al = r | 0, this.Bh = i | 0, this.Bl = a | 0, this.Ch = o | 0, this.Cl = l | 0, this.Dh = u | 0, this.Dl = m | 0, this.Eh = b | 0, this.El = v | 0, this.Fh = E | 0, this.Fl = M | 0, this.Gh = S | 0, this.Gl = O | 0, this.Hh = A | 0, this.Hl = D | 0;
2120
- }
2121
- process(e, r) {
2122
- for (let R = 0; R < 16; R++, r += 4)
2123
- ie[R] = e.getUint32(r), oe[R] = e.getUint32(r += 4);
2124
- for (let R = 16; R < 80; R++) {
2125
- const _ = ie[R - 15] | 0, B = oe[R - 15] | 0, L = me(_, B, 1) ^ me(_, B, 8) ^ ci(_, B, 7), T = pe(_, B, 1) ^ pe(_, B, 8) ^ hi(_, B, 7), q = ie[R - 2] | 0, $ = oe[R - 2] | 0, C = me(q, $, 19) ^ Ye(q, $, 61) ^ ci(q, $, 6), U = pe(q, $, 19) ^ We(q, $, 61) ^ hi(q, $, 6), H = r0(T, U, oe[R - 7], oe[R - 16]), y = n0(H, L, C, ie[R - 7], ie[R - 16]);
2126
- ie[R] = y | 0, oe[R] = H | 0;
2127
- }
2128
- let { Ah: i, Al: a, Bh: o, Bl: l, Ch: u, Cl: m, Dh: b, Dl: v, Eh: E, El: M, Fh: S, Fl: O, Gh: A, Gl: D, Hh: V, Hl: Q } = this;
2129
- for (let R = 0; R < 80; R++) {
2130
- const _ = me(E, M, 14) ^ me(E, M, 18) ^ Ye(E, M, 41), B = pe(E, M, 14) ^ pe(E, M, 18) ^ We(E, M, 41), L = E & S ^ ~E & A, T = M & O ^ ~M & D, q = i0(Q, B, T, c0[R], oe[R]), $ = o0(q, V, _, L, a0[R], ie[R]), C = q | 0, U = me(i, a, 28) ^ Ye(i, a, 34) ^ Ye(i, a, 39), H = pe(i, a, 28) ^ We(i, a, 34) ^ We(i, a, 39), y = i & o ^ i & u ^ o & u, n = a & l ^ a & m ^ l & m;
2131
- V = A | 0, Q = D | 0, A = S | 0, D = O | 0, S = E | 0, O = M | 0, { h: E, l: M } = Ft(b | 0, v | 0, $ | 0, C | 0), b = u | 0, v = m | 0, u = o | 0, m = l | 0, o = i | 0, l = a | 0;
2132
- const f = t0(C, H, n);
2133
- i = e0(f, $, U, y), a = f | 0;
2134
- }
2135
- ({ h: i, l: a } = Ft(this.Ah | 0, this.Al | 0, i | 0, a | 0)), { h: o, l } = Ft(this.Bh | 0, this.Bl | 0, o | 0, l | 0), { h: u, l: m } = Ft(this.Ch | 0, this.Cl | 0, u | 0, m | 0), { h: b, l: v } = Ft(this.Dh | 0, this.Dl | 0, b | 0, v | 0), { h: E, l: M } = Ft(this.Eh | 0, this.El | 0, E | 0, M | 0), { h: S, l: O } = Ft(this.Fh | 0, this.Fl | 0, S | 0, O | 0), { h: A, l: D } = Ft(this.Gh | 0, this.Gl | 0, A | 0, D | 0), { h: V, l: Q } = Ft(this.Hh | 0, this.Hl | 0, V | 0, Q | 0), this.set(i, a, o, l, u, m, b, v, E, M, S, O, A, D, V, Q);
2136
- }
2137
- roundClean() {
2138
- _e(ie, oe);
2139
- }
2140
- destroy() {
2141
- _e(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
2142
- }
2143
- }
2144
- const l0 = /* @__PURE__ */ oo(() => new f0()), u0 = /* @__PURE__ */ oo(() => new h0());
2145
- class co extends io {
2146
- constructor(e, r) {
2147
- super(), this.finished = !1, this.destroyed = !1, Gf(e);
2148
- const i = Sn(r);
2149
- if (this.iHash = e.create(), typeof this.iHash.update != "function")
2150
- throw new Error("Expected instance of class which extends utils.Hash");
2151
- this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
2152
- const a = this.blockLen, o = new Uint8Array(a);
2153
- o.set(i.length > a ? e.create().update(i).digest() : i);
2154
- for (let l = 0; l < o.length; l++)
2155
- o[l] ^= 54;
2156
- this.iHash.update(o), this.oHash = e.create();
2157
- for (let l = 0; l < o.length; l++)
2158
- o[l] ^= 106;
2159
- this.oHash.update(o), _e(o);
2160
- }
2161
- update(e) {
2162
- return ar(this), this.iHash.update(e), this;
2163
- }
2164
- digestInto(e) {
2165
- ar(this), $e(e, this.outputLen), this.finished = !0, this.iHash.digestInto(e), this.oHash.update(e), this.oHash.digestInto(e), this.destroy();
2166
- }
2167
- digest() {
2168
- const e = new Uint8Array(this.oHash.outputLen);
2169
- return this.digestInto(e), e;
2170
- }
2171
- _cloneInto(e) {
2172
- e || (e = Object.create(Object.getPrototypeOf(this), {}));
2173
- const { oHash: r, iHash: i, finished: a, destroyed: o, blockLen: l, outputLen: u } = this;
2174
- return e = e, e.finished = a, e.destroyed = o, e.blockLen = l, e.outputLen = u, e.oHash = r._cloneInto(e.oHash), e.iHash = i._cloneInto(e.iHash), e;
2175
- }
2176
- clone() {
2177
- return this._cloneInto();
2178
- }
2179
- destroy() {
2180
- this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
2181
- }
2182
- }
2183
- const ho = (t, e, r) => new co(t, e).update(r).digest();
2184
- ho.create = (t, e) => new co(t, e);
2185
- const In = /* @__PURE__ */ BigInt(0), an = /* @__PURE__ */ BigInt(1);
2186
- function Ce(t) {
2187
- return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
2188
- }
2189
- function Un(t) {
2190
- if (!Ce(t))
2191
- throw new Error("Uint8Array expected");
2192
- }
2193
- function ae(t, e) {
2194
- if (typeof e != "boolean")
2195
- throw new Error(t + " boolean expected, got " + e);
2196
- }
2197
- function Xe(t) {
2198
- const e = t.toString(16);
2199
- return e.length & 1 ? "0" + e : e;
2200
- }
2201
- function lo(t) {
2202
- if (typeof t != "string")
2203
- throw new Error("hex string expected, got " + typeof t);
2204
- return t === "" ? In : BigInt("0x" + t);
2205
- }
2206
- const uo = (
2207
- // @ts-ignore
2208
- typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function"
2209
- ), d0 = /* @__PURE__ */ Array.from({ length: 256 }, (t, e) => e.toString(16).padStart(2, "0"));
2210
- function Me(t) {
2211
- if (Un(t), uo)
2212
- return t.toHex();
2213
- let e = "";
2214
- for (let r = 0; r < t.length; r++)
2215
- e += d0[t[r]];
2216
- return e;
2217
- }
2218
- const Qt = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
2219
- function li(t) {
2220
- if (t >= Qt._0 && t <= Qt._9)
2221
- return t - Qt._0;
2222
- if (t >= Qt.A && t <= Qt.F)
2223
- return t - (Qt.A - 10);
2224
- if (t >= Qt.a && t <= Qt.f)
2225
- return t - (Qt.a - 10);
2226
- }
2227
- function cr(t) {
2228
- if (typeof t != "string")
2229
- throw new Error("hex string expected, got " + typeof t);
2230
- if (uo)
2231
- return Uint8Array.fromHex(t);
2232
- const e = t.length, r = e / 2;
2233
- if (e % 2)
2234
- throw new Error("hex string expected, got unpadded hex of length " + e);
2235
- const i = new Uint8Array(r);
2236
- for (let a = 0, o = 0; a < r; a++, o += 2) {
2237
- const l = li(t.charCodeAt(o)), u = li(t.charCodeAt(o + 1));
2238
- if (l === void 0 || u === void 0) {
2239
- const m = t[o] + t[o + 1];
2240
- throw new Error('hex string expected, got non-hex character "' + m + '" at index ' + o);
2241
- }
2242
- i[a] = l * 16 + u;
2243
- }
2244
- return i;
2245
- }
2246
- function ue(t) {
2247
- return lo(Me(t));
2248
- }
2249
- function Ne(t) {
2250
- return Un(t), lo(Me(Uint8Array.from(t).reverse()));
2251
- }
2252
- function De(t, e) {
2253
- return cr(t.toString(16).padStart(e * 2, "0"));
2254
- }
2255
- function hr(t, e) {
2256
- return De(t, e).reverse();
2257
- }
2258
- function st(t, e, r) {
2259
- let i;
2260
- if (typeof e == "string")
2261
- try {
2262
- i = cr(e);
2263
- } catch (o) {
2264
- throw new Error(t + " must be hex string or Uint8Array, cause: " + o);
2265
- }
2266
- else if (Ce(e))
2267
- i = Uint8Array.from(e);
2268
- else
2269
- throw new Error(t + " must be hex string or Uint8Array");
2270
- const a = i.length;
2271
- if (typeof r == "number" && a !== r)
2272
- throw new Error(t + " of length " + r + " expected, got " + a);
2273
- return i;
2274
- }
2275
- function Ae(...t) {
2276
- let e = 0;
2277
- for (let i = 0; i < t.length; i++) {
2278
- const a = t[i];
2279
- Un(a), e += a.length;
2280
- }
2281
- const r = new Uint8Array(e);
2282
- for (let i = 0, a = 0; i < t.length; i++) {
2283
- const o = t[i];
2284
- r.set(o, a), a += o.length;
2285
- }
2286
- return r;
2287
- }
2288
- const Vr = (t) => typeof t == "bigint" && In <= t;
2289
- function kn(t, e, r) {
2290
- return Vr(t) && Vr(e) && Vr(r) && e <= t && t < r;
2291
- }
2292
- function Wt(t, e, r, i) {
2293
- if (!kn(e, r, i))
2294
- throw new Error("expected valid " + t + ": " + r + " <= n < " + i + ", got " + e);
2295
- }
2296
- function w0(t) {
2297
- let e;
2298
- for (e = 0; t > In; t >>= an, e += 1)
2299
- ;
2300
- return e;
2301
- }
2302
- const gr = (t) => (an << BigInt(t)) - an, zr = (t) => new Uint8Array(t), ui = (t) => Uint8Array.from(t);
2303
- function g0(t, e, r) {
2304
- if (typeof t != "number" || t < 2)
2305
- throw new Error("hashLen must be a number");
2306
- if (typeof e != "number" || e < 2)
2307
- throw new Error("qByteLen must be a number");
2308
- if (typeof r != "function")
2309
- throw new Error("hmacFn must be a function");
2310
- let i = zr(t), a = zr(t), o = 0;
2311
- const l = () => {
2312
- i.fill(1), a.fill(0), o = 0;
2313
- }, u = (...E) => r(a, i, ...E), m = (E = zr(0)) => {
2314
- a = u(ui([0]), E), i = u(), E.length !== 0 && (a = u(ui([1]), E), i = u());
2315
- }, b = () => {
2316
- if (o++ >= 1e3)
2317
- throw new Error("drbg: tried 1000 values");
2318
- let E = 0;
2319
- const M = [];
2320
- for (; E < e; ) {
2321
- i = u();
2322
- const S = i.slice();
2323
- M.push(S), E += i.length;
2324
- }
2325
- return Ae(...M);
2326
- };
2327
- return (E, M) => {
2328
- l(), m(E);
2329
- let S;
2330
- for (; !(S = M(b())); )
2331
- m();
2332
- return l(), S;
2333
- };
2334
- }
2335
- const m0 = {
2336
- bigint: (t) => typeof t == "bigint",
2337
- function: (t) => typeof t == "function",
2338
- boolean: (t) => typeof t == "boolean",
2339
- string: (t) => typeof t == "string",
2340
- stringOrUint8Array: (t) => typeof t == "string" || Ce(t),
2341
- isSafeInteger: (t) => Number.isSafeInteger(t),
2342
- array: (t) => Array.isArray(t),
2343
- field: (t, e) => e.Fp.isValid(t),
2344
- hash: (t) => typeof t == "function" && Number.isSafeInteger(t.outputLen)
2345
- };
2346
- function Pe(t, e, r = {}) {
2347
- const i = (a, o, l) => {
2348
- const u = m0[o];
2349
- if (typeof u != "function")
2350
- throw new Error("invalid validator function");
2351
- const m = t[a];
2352
- if (!(l && m === void 0) && !u(m, t))
2353
- throw new Error("param " + String(a) + " is invalid. Expected " + o + ", got " + m);
2354
- };
2355
- for (const [a, o] of Object.entries(e))
2356
- i(a, o, !1);
2357
- for (const [a, o] of Object.entries(r))
2358
- i(a, o, !0);
2359
- return t;
2360
- }
2361
- function lr(t) {
2362
- const e = /* @__PURE__ */ new WeakMap();
2363
- return (r, ...i) => {
2364
- const a = e.get(r);
2365
- if (a !== void 0)
2366
- return a;
2367
- const o = t(r, ...i);
2368
- return e.set(r, o), o;
2369
- };
2370
- }
2371
- const Zt = BigInt(0), Ct = BigInt(1), le = /* @__PURE__ */ BigInt(2), p0 = /* @__PURE__ */ BigInt(3), wo = /* @__PURE__ */ BigInt(4), go = /* @__PURE__ */ BigInt(5), mo = /* @__PURE__ */ BigInt(8);
2372
- function tt(t, e) {
2373
- const r = t % e;
2374
- return r >= Zt ? r : e + r;
2375
- }
2376
- function ot(t, e, r) {
2377
- let i = t;
2378
- for (; e-- > Zt; )
2379
- i *= i, i %= r;
2380
- return i;
2381
- }
2382
- function cn(t, e) {
2383
- if (t === Zt)
2384
- throw new Error("invert: expected non-zero number");
2385
- if (e <= Zt)
2386
- throw new Error("invert: expected positive modulus, got " + e);
2387
- let r = tt(t, e), i = e, a = Zt, o = Ct;
2388
- for (; r !== Zt; ) {
2389
- const u = i / r, m = i % r, b = a - o * u;
2390
- i = r, r = m, a = o, o = b;
2391
- }
2392
- if (i !== Ct)
2393
- throw new Error("invert: does not exist");
2394
- return tt(a, e);
2395
- }
2396
- function po(t, e) {
2397
- const r = (t.ORDER + Ct) / wo, i = t.pow(e, r);
2398
- if (!t.eql(t.sqr(i), e))
2399
- throw new Error("Cannot find square root");
2400
- return i;
2401
- }
2402
- function y0(t, e) {
2403
- const r = (t.ORDER - go) / mo, i = t.mul(e, le), a = t.pow(i, r), o = t.mul(e, a), l = t.mul(t.mul(o, le), a), u = t.mul(o, t.sub(l, t.ONE));
2404
- if (!t.eql(t.sqr(u), e))
2405
- throw new Error("Cannot find square root");
2406
- return u;
2407
- }
2408
- function x0(t) {
2409
- if (t < BigInt(3))
2410
- throw new Error("sqrt is not defined for small field");
2411
- let e = t - Ct, r = 0;
2412
- for (; e % le === Zt; )
2413
- e /= le, r++;
2414
- let i = le;
2415
- const a = Ze(t);
2416
- for (; di(a, i) === 1; )
2417
- if (i++ > 1e3)
2418
- throw new Error("Cannot find square root: probably non-prime P");
2419
- if (r === 1)
2420
- return po;
2421
- let o = a.pow(i, e);
2422
- const l = (e + Ct) / le;
2423
- return function(m, b) {
2424
- if (m.is0(b))
2425
- return b;
2426
- if (di(m, b) !== 1)
2427
- throw new Error("Cannot find square root");
2428
- let v = r, E = m.mul(m.ONE, o), M = m.pow(b, e), S = m.pow(b, l);
2429
- for (; !m.eql(M, m.ONE); ) {
2430
- if (m.is0(M))
2431
- return m.ZERO;
2432
- let O = 1, A = m.sqr(M);
2433
- for (; !m.eql(A, m.ONE); )
2434
- if (O++, A = m.sqr(A), O === v)
2435
- throw new Error("Cannot find square root");
2436
- const D = Ct << BigInt(v - O - 1), V = m.pow(E, D);
2437
- v = O, E = m.sqr(V), M = m.mul(M, E), S = m.mul(S, V);
2438
- }
2439
- return S;
2440
- };
2441
- }
2442
- function v0(t) {
2443
- return t % wo === p0 ? po : t % mo === go ? y0 : x0(t);
2444
- }
2445
- const b0 = (t, e) => (tt(t, e) & Ct) === Ct, E0 = [
2446
- "create",
2447
- "isValid",
2448
- "is0",
2449
- "neg",
2450
- "inv",
2451
- "sqrt",
2452
- "sqr",
2453
- "eql",
2454
- "add",
2455
- "sub",
2456
- "mul",
2457
- "pow",
2458
- "div",
2459
- "addN",
2460
- "subN",
2461
- "mulN",
2462
- "sqrN"
2463
- ];
2464
- function _0(t) {
2465
- const e = {
2466
- ORDER: "bigint",
2467
- MASK: "bigint",
2468
- BYTES: "isSafeInteger",
2469
- BITS: "isSafeInteger"
2470
- }, r = E0.reduce((i, a) => (i[a] = "function", i), e);
2471
- return Pe(t, r);
2472
- }
2473
- function M0(t, e, r) {
2474
- if (r < Zt)
2475
- throw new Error("invalid exponent, negatives unsupported");
2476
- if (r === Zt)
2477
- return t.ONE;
2478
- if (r === Ct)
2479
- return e;
2480
- let i = t.ONE, a = e;
2481
- for (; r > Zt; )
2482
- r & Ct && (i = t.mul(i, a)), a = t.sqr(a), r >>= Ct;
2483
- return i;
2484
- }
2485
- function Nn(t, e, r = !1) {
2486
- const i = new Array(e.length).fill(r ? t.ZERO : void 0), a = e.reduce((l, u, m) => t.is0(u) ? l : (i[m] = l, t.mul(l, u)), t.ONE), o = t.inv(a);
2487
- return e.reduceRight((l, u, m) => t.is0(u) ? l : (i[m] = t.mul(l, i[m]), t.mul(l, u)), o), i;
2488
- }
2489
- function di(t, e) {
2490
- const r = (t.ORDER - Ct) / le, i = t.pow(e, r), a = t.eql(i, t.ONE), o = t.eql(i, t.ZERO), l = t.eql(i, t.neg(t.ONE));
2491
- if (!a && !o && !l)
2492
- throw new Error("invalid Legendre symbol result");
2493
- return a ? 1 : o ? 0 : -1;
2494
- }
2495
- function yo(t, e) {
2496
- e !== void 0 && fn(e);
2497
- const r = e !== void 0 ? e : t.toString(2).length, i = Math.ceil(r / 8);
2498
- return { nBitLength: r, nByteLength: i };
2499
- }
2500
- function Ze(t, e, r = !1, i = {}) {
2501
- if (t <= Zt)
2502
- throw new Error("invalid field: expected ORDER > 0, got " + t);
2503
- const { nBitLength: a, nByteLength: o } = yo(t, e);
2504
- if (o > 2048)
2505
- throw new Error("invalid field: expected ORDER of <= 2048 bytes");
2506
- let l;
2507
- const u = Object.freeze({
2508
- ORDER: t,
2509
- isLE: r,
2510
- BITS: a,
2511
- BYTES: o,
2512
- MASK: gr(a),
2513
- ZERO: Zt,
2514
- ONE: Ct,
2515
- create: (m) => tt(m, t),
2516
- isValid: (m) => {
2517
- if (typeof m != "bigint")
2518
- throw new Error("invalid field element: expected bigint, got " + typeof m);
2519
- return Zt <= m && m < t;
2520
- },
2521
- is0: (m) => m === Zt,
2522
- isOdd: (m) => (m & Ct) === Ct,
2523
- neg: (m) => tt(-m, t),
2524
- eql: (m, b) => m === b,
2525
- sqr: (m) => tt(m * m, t),
2526
- add: (m, b) => tt(m + b, t),
2527
- sub: (m, b) => tt(m - b, t),
2528
- mul: (m, b) => tt(m * b, t),
2529
- pow: (m, b) => M0(u, m, b),
2530
- div: (m, b) => tt(m * cn(b, t), t),
2531
- // Same as above, but doesn't normalize
2532
- sqrN: (m) => m * m,
2533
- addN: (m, b) => m + b,
2534
- subN: (m, b) => m - b,
2535
- mulN: (m, b) => m * b,
2536
- inv: (m) => cn(m, t),
2537
- sqrt: i.sqrt || ((m) => (l || (l = v0(t)), l(u, m))),
2538
- toBytes: (m) => r ? hr(m, o) : De(m, o),
2539
- fromBytes: (m) => {
2540
- if (m.length !== o)
2541
- throw new Error("Field.fromBytes: expected " + o + " bytes, got " + m.length);
2542
- return r ? Ne(m) : ue(m);
2543
- },
2544
- // TODO: we don't need it here, move out to separate fn
2545
- invertBatch: (m) => Nn(u, m),
2546
- // We can't move this out because Fp6, Fp12 implement it
2547
- // and it's unclear what to return in there.
2548
- cmov: (m, b, v) => v ? b : m
2549
- });
2550
- return Object.freeze(u);
2551
- }
2552
- function xo(t) {
2553
- if (typeof t != "bigint")
2554
- throw new Error("field order must be bigint");
2555
- const e = t.toString(2).length;
2556
- return Math.ceil(e / 8);
2557
- }
2558
- function vo(t) {
2559
- const e = xo(t);
2560
- return e + Math.ceil(e / 2);
2561
- }
2562
- function A0(t, e, r = !1) {
2563
- const i = t.length, a = xo(e), o = vo(e);
2564
- if (i < 16 || i < o || i > 1024)
2565
- throw new Error("expected " + o + "-1024 bytes of input, got " + i);
2566
- const l = r ? Ne(t) : ue(t), u = tt(l, e - Ct) + Ct;
2567
- return r ? hr(u, a) : De(u, a);
2568
- }
2569
- const wi = BigInt(0), hn = BigInt(1);
2570
- function Gr(t, e) {
2571
- const r = e.negate();
2572
- return t ? r : e;
2573
- }
2574
- function bo(t, e) {
2575
- if (!Number.isSafeInteger(t) || t <= 0 || t > e)
2576
- throw new Error("invalid window size, expected [1.." + e + "], got W=" + t);
2577
- }
2578
- function Yr(t, e) {
2579
- bo(t, e);
2580
- const r = Math.ceil(e / t) + 1, i = 2 ** (t - 1), a = 2 ** t, o = gr(t), l = BigInt(t);
2581
- return { windows: r, windowSize: i, mask: o, maxNumber: a, shiftBy: l };
2582
- }
2583
- function gi(t, e, r) {
2584
- const { windowSize: i, mask: a, maxNumber: o, shiftBy: l } = r;
2585
- let u = Number(t & a), m = t >> l;
2586
- u > i && (u -= o, m += hn);
2587
- const b = e * i, v = b + Math.abs(u) - 1, E = u === 0, M = u < 0, S = e % 2 !== 0;
2588
- return { nextN: m, offset: v, isZero: E, isNeg: M, isNegF: S, offsetF: b };
2589
- }
2590
- function B0(t, e) {
2591
- if (!Array.isArray(t))
2592
- throw new Error("array expected");
2593
- t.forEach((r, i) => {
2594
- if (!(r instanceof e))
2595
- throw new Error("invalid point at index " + i);
2596
- });
2597
- }
2598
- function S0(t, e) {
2599
- if (!Array.isArray(t))
2600
- throw new Error("array of scalars expected");
2601
- t.forEach((r, i) => {
2602
- if (!e.isValid(r))
2603
- throw new Error("invalid scalar at index " + i);
2604
- });
2605
- }
2606
- const Wr = /* @__PURE__ */ new WeakMap(), Eo = /* @__PURE__ */ new WeakMap();
2607
- function Xr(t) {
2608
- return Eo.get(t) || 1;
2609
- }
2610
- function _o(t, e) {
2611
- return {
2612
- constTimeNegate: Gr,
2613
- hasPrecomputes(r) {
2614
- return Xr(r) !== 1;
2615
- },
2616
- // non-const time multiplication ladder
2617
- unsafeLadder(r, i, a = t.ZERO) {
2618
- let o = r;
2619
- for (; i > wi; )
2620
- i & hn && (a = a.add(o)), o = o.double(), i >>= hn;
2621
- return a;
2622
- },
2623
- /**
2624
- * Creates a wNAF precomputation window. Used for caching.
2625
- * Default window size is set by `utils.precompute()` and is equal to 8.
2626
- * Number of precomputed points depends on the curve size:
2627
- * 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
2628
- * - 𝑊 is the window size
2629
- * - 𝑛 is the bitlength of the curve order.
2630
- * For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
2631
- * @param elm Point instance
2632
- * @param W window size
2633
- * @returns precomputed point tables flattened to a single array
2634
- */
2635
- precomputeWindow(r, i) {
2636
- const { windows: a, windowSize: o } = Yr(i, e), l = [];
2637
- let u = r, m = u;
2638
- for (let b = 0; b < a; b++) {
2639
- m = u, l.push(m);
2640
- for (let v = 1; v < o; v++)
2641
- m = m.add(u), l.push(m);
2642
- u = m.double();
2643
- }
2644
- return l;
2645
- },
2646
- /**
2647
- * Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
2648
- * @param W window size
2649
- * @param precomputes precomputed tables
2650
- * @param n scalar (we don't check here, but should be less than curve order)
2651
- * @returns real and fake (for const-time) points
2652
- */
2653
- wNAF(r, i, a) {
2654
- let o = t.ZERO, l = t.BASE;
2655
- const u = Yr(r, e);
2656
- for (let m = 0; m < u.windows; m++) {
2657
- const { nextN: b, offset: v, isZero: E, isNeg: M, isNegF: S, offsetF: O } = gi(a, m, u);
2658
- a = b, E ? l = l.add(Gr(S, i[O])) : o = o.add(Gr(M, i[v]));
2659
- }
2660
- return { p: o, f: l };
2661
- },
2662
- /**
2663
- * Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
2664
- * @param W window size
2665
- * @param precomputes precomputed tables
2666
- * @param n scalar (we don't check here, but should be less than curve order)
2667
- * @param acc accumulator point to add result of multiplication
2668
- * @returns point
2669
- */
2670
- wNAFUnsafe(r, i, a, o = t.ZERO) {
2671
- const l = Yr(r, e);
2672
- for (let u = 0; u < l.windows && a !== wi; u++) {
2673
- const { nextN: m, offset: b, isZero: v, isNeg: E } = gi(a, u, l);
2674
- if (a = m, !v) {
2675
- const M = i[b];
2676
- o = o.add(E ? M.negate() : M);
2677
- }
2678
- }
2679
- return o;
2680
- },
2681
- getPrecomputes(r, i, a) {
2682
- let o = Wr.get(i);
2683
- return o || (o = this.precomputeWindow(i, r), r !== 1 && Wr.set(i, a(o))), o;
2684
- },
2685
- wNAFCached(r, i, a) {
2686
- const o = Xr(r);
2687
- return this.wNAF(o, this.getPrecomputes(o, r, a), i);
2688
- },
2689
- wNAFCachedUnsafe(r, i, a, o) {
2690
- const l = Xr(r);
2691
- return l === 1 ? this.unsafeLadder(r, i, o) : this.wNAFUnsafe(l, this.getPrecomputes(l, r, a), i, o);
2692
- },
2693
- // We calculate precomputes for elliptic curve point multiplication
2694
- // using windowed method. This specifies window size and
2695
- // stores precomputed values. Usually only base point would be precomputed.
2696
- setWindowSize(r, i) {
2697
- bo(i, e), Eo.set(r, i), Wr.delete(r);
2698
- }
2699
- };
2700
- }
2701
- function Mo(t, e, r, i) {
2702
- B0(r, t), S0(i, e);
2703
- const a = r.length, o = i.length;
2704
- if (a !== o)
2705
- throw new Error("arrays of points and scalars must have equal length");
2706
- const l = t.ZERO, u = w0(BigInt(a));
2707
- let m = 1;
2708
- u > 12 ? m = u - 3 : u > 4 ? m = u - 2 : u > 0 && (m = 2);
2709
- const b = gr(m), v = new Array(Number(b) + 1).fill(l), E = Math.floor((e.BITS - 1) / m) * m;
2710
- let M = l;
2711
- for (let S = E; S >= 0; S -= m) {
2712
- v.fill(l);
2713
- for (let A = 0; A < o; A++) {
2714
- const D = i[A], V = Number(D >> BigInt(S) & b);
2715
- v[V] = v[V].add(r[A]);
2716
- }
2717
- let O = l;
2718
- for (let A = v.length - 1, D = l; A > 0; A--)
2719
- D = D.add(v[A]), O = O.add(D);
2720
- if (M = M.add(O), S !== 0)
2721
- for (let A = 0; A < m; A++)
2722
- M = M.double();
2723
- }
2724
- return M;
2725
- }
2726
- function Rn(t) {
2727
- return _0(t.Fp), Pe(t, {
2728
- n: "bigint",
2729
- h: "bigint",
2730
- Gx: "field",
2731
- Gy: "field"
2732
- }, {
2733
- nBitLength: "isSafeInteger",
2734
- nByteLength: "isSafeInteger"
2735
- }), Object.freeze({
2736
- ...yo(t.n, t.nBitLength),
2737
- ...t,
2738
- p: t.Fp.ORDER
2739
- });
2740
- }
2741
- function mi(t) {
2742
- t.lowS !== void 0 && ae("lowS", t.lowS), t.prehash !== void 0 && ae("prehash", t.prehash);
2743
- }
2744
- function I0(t) {
2745
- const e = Rn(t);
2746
- Pe(e, {
2747
- a: "field",
2748
- b: "field"
2749
- }, {
2750
- allowInfinityPoint: "boolean",
2751
- allowedPrivateKeyLengths: "array",
2752
- clearCofactor: "function",
2753
- fromBytes: "function",
2754
- isTorsionFree: "function",
2755
- toBytes: "function",
2756
- wrapPrivateKey: "boolean"
2757
- });
2758
- const { endo: r, Fp: i, a } = e;
2759
- if (r) {
2760
- if (!i.eql(a, i.ZERO))
2761
- throw new Error("invalid endo: CURVE.a must be 0");
2762
- if (typeof r != "object" || typeof r.beta != "bigint" || typeof r.splitScalar != "function")
2763
- throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');
2764
- }
2765
- return Object.freeze({ ...e });
2766
- }
2767
- class U0 extends Error {
2768
- constructor(e = "") {
2769
- super(e);
2770
- }
2771
- }
2772
- const te = {
2773
- // asn.1 DER encoding utils
2774
- Err: U0,
2775
- // Basic building block is TLV (Tag-Length-Value)
2776
- _tlv: {
2777
- encode: (t, e) => {
2778
- const { Err: r } = te;
2779
- if (t < 0 || t > 256)
2780
- throw new r("tlv.encode: wrong tag");
2781
- if (e.length & 1)
2782
- throw new r("tlv.encode: unpadded data");
2783
- const i = e.length / 2, a = Xe(i);
2784
- if (a.length / 2 & 128)
2785
- throw new r("tlv.encode: long form length too big");
2786
- const o = i > 127 ? Xe(a.length / 2 | 128) : "";
2787
- return Xe(t) + o + a + e;
2788
- },
2789
- // v - value, l - left bytes (unparsed)
2790
- decode(t, e) {
2791
- const { Err: r } = te;
2792
- let i = 0;
2793
- if (t < 0 || t > 256)
2794
- throw new r("tlv.encode: wrong tag");
2795
- if (e.length < 2 || e[i++] !== t)
2796
- throw new r("tlv.decode: wrong tlv");
2797
- const a = e[i++], o = !!(a & 128);
2798
- let l = 0;
2799
- if (!o)
2800
- l = a;
2801
- else {
2802
- const m = a & 127;
2803
- if (!m)
2804
- throw new r("tlv.decode(long): indefinite length not supported");
2805
- if (m > 4)
2806
- throw new r("tlv.decode(long): byte length is too big");
2807
- const b = e.subarray(i, i + m);
2808
- if (b.length !== m)
2809
- throw new r("tlv.decode: length bytes not complete");
2810
- if (b[0] === 0)
2811
- throw new r("tlv.decode(long): zero leftmost byte");
2812
- for (const v of b)
2813
- l = l << 8 | v;
2814
- if (i += m, l < 128)
2815
- throw new r("tlv.decode(long): not minimal encoding");
2816
- }
2817
- const u = e.subarray(i, i + l);
2818
- if (u.length !== l)
2819
- throw new r("tlv.decode: wrong value length");
2820
- return { v: u, l: e.subarray(i + l) };
2821
- }
2822
- },
2823
- // https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
2824
- // since we always use positive integers here. It must always be empty:
2825
- // - add zero byte if exists
2826
- // - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
2827
- _int: {
2828
- encode(t) {
2829
- const { Err: e } = te;
2830
- if (t < ee)
2831
- throw new e("integer: negative integers are not allowed");
2832
- let r = Xe(t);
2833
- if (Number.parseInt(r[0], 16) & 8 && (r = "00" + r), r.length & 1)
2834
- throw new e("unexpected DER parsing assertion: unpadded hex");
2835
- return r;
2836
- },
2837
- decode(t) {
2838
- const { Err: e } = te;
2839
- if (t[0] & 128)
2840
- throw new e("invalid signature integer: negative");
2841
- if (t[0] === 0 && !(t[1] & 128))
2842
- throw new e("invalid signature integer: unnecessary leading zero");
2843
- return ue(t);
2844
- }
2845
- },
2846
- toSig(t) {
2847
- const { Err: e, _int: r, _tlv: i } = te, a = st("signature", t), { v: o, l } = i.decode(48, a);
2848
- if (l.length)
2849
- throw new e("invalid signature: left bytes after parsing");
2850
- const { v: u, l: m } = i.decode(2, o), { v: b, l: v } = i.decode(2, m);
2851
- if (v.length)
2852
- throw new e("invalid signature: left bytes after parsing");
2853
- return { r: r.decode(u), s: r.decode(b) };
2854
- },
2855
- hexFromSig(t) {
2856
- const { _tlv: e, _int: r } = te, i = e.encode(2, r.encode(t.r)), a = e.encode(2, r.encode(t.s)), o = i + a;
2857
- return e.encode(48, o);
2858
- }
2859
- };
2860
- function Kr(t, e) {
2861
- return Me(De(t, e));
2862
- }
2863
- const ee = BigInt(0), qt = BigInt(1), kc = BigInt(2), jr = BigInt(3), k0 = BigInt(4);
2864
- function N0(t) {
2865
- const e = I0(t), { Fp: r } = e, i = Ze(e.n, e.nBitLength), a = e.toBytes || ((R, _, B) => {
2866
- const L = _.toAffine();
2867
- return Ae(Uint8Array.from([4]), r.toBytes(L.x), r.toBytes(L.y));
2868
- }), o = e.fromBytes || ((R) => {
2869
- const _ = R.subarray(1), B = r.fromBytes(_.subarray(0, r.BYTES)), L = r.fromBytes(_.subarray(r.BYTES, 2 * r.BYTES));
2870
- return { x: B, y: L };
2871
- });
2872
- function l(R) {
2873
- const { a: _, b: B } = e, L = r.sqr(R), T = r.mul(L, R);
2874
- return r.add(r.add(T, r.mul(R, _)), B);
2875
- }
2876
- function u(R, _) {
2877
- const B = r.sqr(_), L = l(R);
2878
- return r.eql(B, L);
2879
- }
2880
- if (!u(e.Gx, e.Gy))
2881
- throw new Error("bad curve params: generator point");
2882
- const m = r.mul(r.pow(e.a, jr), k0), b = r.mul(r.sqr(e.b), BigInt(27));
2883
- if (r.is0(r.add(m, b)))
2884
- throw new Error("bad curve params: a or b");
2885
- function v(R) {
2886
- return kn(R, qt, e.n);
2887
- }
2888
- function E(R) {
2889
- const { allowedPrivateKeyLengths: _, nByteLength: B, wrapPrivateKey: L, n: T } = e;
2890
- if (_ && typeof R != "bigint") {
2891
- if (Ce(R) && (R = Me(R)), typeof R != "string" || !_.includes(R.length))
2892
- throw new Error("invalid private key");
2893
- R = R.padStart(B * 2, "0");
2894
- }
2895
- let q;
2896
- try {
2897
- q = typeof R == "bigint" ? R : ue(st("private key", R, B));
2898
- } catch {
2899
- throw new Error("invalid private key, expected hex or " + B + " bytes, got " + typeof R);
2900
- }
2901
- return L && (q = tt(q, T)), Wt("private key", q, qt, T), q;
2902
- }
2903
- function M(R) {
2904
- if (!(R instanceof A))
2905
- throw new Error("ProjectivePoint expected");
2906
- }
2907
- const S = lr((R, _) => {
2908
- const { px: B, py: L, pz: T } = R;
2909
- if (r.eql(T, r.ONE))
2910
- return { x: B, y: L };
2911
- const q = R.is0();
2912
- _ == null && (_ = q ? r.ONE : r.inv(T));
2913
- const $ = r.mul(B, _), C = r.mul(L, _), U = r.mul(T, _);
2914
- if (q)
2915
- return { x: r.ZERO, y: r.ZERO };
2916
- if (!r.eql(U, r.ONE))
2917
- throw new Error("invZ was invalid");
2918
- return { x: $, y: C };
2919
- }), O = lr((R) => {
2920
- if (R.is0()) {
2921
- if (e.allowInfinityPoint && !r.is0(R.py))
2922
- return;
2923
- throw new Error("bad point: ZERO");
2924
- }
2925
- const { x: _, y: B } = R.toAffine();
2926
- if (!r.isValid(_) || !r.isValid(B))
2927
- throw new Error("bad point: x or y not FE");
2928
- if (!u(_, B))
2929
- throw new Error("bad point: equation left != right");
2930
- if (!R.isTorsionFree())
2931
- throw new Error("bad point: not in prime-order subgroup");
2932
- return !0;
2933
- });
2934
- class A {
2935
- constructor(_, B, L) {
2936
- if (_ == null || !r.isValid(_))
2937
- throw new Error("x required");
2938
- if (B == null || !r.isValid(B) || r.is0(B))
2939
- throw new Error("y required");
2940
- if (L == null || !r.isValid(L))
2941
- throw new Error("z required");
2942
- this.px = _, this.py = B, this.pz = L, Object.freeze(this);
2943
- }
2944
- // Does not validate if the point is on-curve.
2945
- // Use fromHex instead, or call assertValidity() later.
2946
- static fromAffine(_) {
2947
- const { x: B, y: L } = _ || {};
2948
- if (!_ || !r.isValid(B) || !r.isValid(L))
2949
- throw new Error("invalid affine point");
2950
- if (_ instanceof A)
2951
- throw new Error("projective point not allowed");
2952
- const T = (q) => r.eql(q, r.ZERO);
2953
- return T(B) && T(L) ? A.ZERO : new A(B, L, r.ONE);
2954
- }
2955
- get x() {
2956
- return this.toAffine().x;
2957
- }
2958
- get y() {
2959
- return this.toAffine().y;
2960
- }
2961
- /**
2962
- * Takes a bunch of Projective Points but executes only one
2963
- * inversion on all of them. Inversion is very slow operation,
2964
- * so this improves performance massively.
2965
- * Optimization: converts a list of projective points to a list of identical points with Z=1.
2966
- */
2967
- static normalizeZ(_) {
2968
- const B = Nn(r, _.map((L) => L.pz));
2969
- return _.map((L, T) => L.toAffine(B[T])).map(A.fromAffine);
2970
- }
2971
- /**
2972
- * Converts hash string or Uint8Array to Point.
2973
- * @param hex short/long ECDSA hex
2974
- */
2975
- static fromHex(_) {
2976
- const B = A.fromAffine(o(st("pointHex", _)));
2977
- return B.assertValidity(), B;
2978
- }
2979
- // Multiplies generator point by privateKey.
2980
- static fromPrivateKey(_) {
2981
- return A.BASE.multiply(E(_));
2982
- }
2983
- // Multiscalar Multiplication
2984
- static msm(_, B) {
2985
- return Mo(A, i, _, B);
2986
- }
2987
- // "Private method", don't use it directly
2988
- _setWindowSize(_) {
2989
- Q.setWindowSize(this, _);
2990
- }
2991
- // A point on curve is valid if it conforms to equation.
2992
- assertValidity() {
2993
- O(this);
2994
- }
2995
- hasEvenY() {
2996
- const { y: _ } = this.toAffine();
2997
- if (r.isOdd)
2998
- return !r.isOdd(_);
2999
- throw new Error("Field doesn't support isOdd");
3000
- }
3001
- /**
3002
- * Compare one point to another.
3003
- */
3004
- equals(_) {
3005
- M(_);
3006
- const { px: B, py: L, pz: T } = this, { px: q, py: $, pz: C } = _, U = r.eql(r.mul(B, C), r.mul(q, T)), H = r.eql(r.mul(L, C), r.mul($, T));
3007
- return U && H;
3008
- }
3009
- /**
3010
- * Flips point to one corresponding to (x, -y) in Affine coordinates.
3011
- */
3012
- negate() {
3013
- return new A(this.px, r.neg(this.py), this.pz);
3014
- }
3015
- // Renes-Costello-Batina exception-free doubling formula.
3016
- // There is 30% faster Jacobian formula, but it is not complete.
3017
- // https://eprint.iacr.org/2015/1060, algorithm 3
3018
- // Cost: 8M + 3S + 3*a + 2*b3 + 15add.
3019
- double() {
3020
- const { a: _, b: B } = e, L = r.mul(B, jr), { px: T, py: q, pz: $ } = this;
3021
- let C = r.ZERO, U = r.ZERO, H = r.ZERO, y = r.mul(T, T), n = r.mul(q, q), f = r.mul($, $), c = r.mul(T, q);
3022
- return c = r.add(c, c), H = r.mul(T, $), H = r.add(H, H), C = r.mul(_, H), U = r.mul(L, f), U = r.add(C, U), C = r.sub(n, U), U = r.add(n, U), U = r.mul(C, U), C = r.mul(c, C), H = r.mul(L, H), f = r.mul(_, f), c = r.sub(y, f), c = r.mul(_, c), c = r.add(c, H), H = r.add(y, y), y = r.add(H, y), y = r.add(y, f), y = r.mul(y, c), U = r.add(U, y), f = r.mul(q, $), f = r.add(f, f), y = r.mul(f, c), C = r.sub(C, y), H = r.mul(f, n), H = r.add(H, H), H = r.add(H, H), new A(C, U, H);
3023
- }
3024
- // Renes-Costello-Batina exception-free addition formula.
3025
- // There is 30% faster Jacobian formula, but it is not complete.
3026
- // https://eprint.iacr.org/2015/1060, algorithm 1
3027
- // Cost: 12M + 0S + 3*a + 3*b3 + 23add.
3028
- add(_) {
3029
- M(_);
3030
- const { px: B, py: L, pz: T } = this, { px: q, py: $, pz: C } = _;
3031
- let U = r.ZERO, H = r.ZERO, y = r.ZERO;
3032
- const n = e.a, f = r.mul(e.b, jr);
3033
- let c = r.mul(B, q), g = r.mul(L, $), d = r.mul(T, C), w = r.add(B, L), x = r.add(q, $);
3034
- w = r.mul(w, x), x = r.add(c, g), w = r.sub(w, x), x = r.add(B, T);
3035
- let h = r.add(q, C);
3036
- return x = r.mul(x, h), h = r.add(c, d), x = r.sub(x, h), h = r.add(L, T), U = r.add($, C), h = r.mul(h, U), U = r.add(g, d), h = r.sub(h, U), y = r.mul(n, x), U = r.mul(f, d), y = r.add(U, y), U = r.sub(g, y), y = r.add(g, y), H = r.mul(U, y), g = r.add(c, c), g = r.add(g, c), d = r.mul(n, d), x = r.mul(f, x), g = r.add(g, d), d = r.sub(c, d), d = r.mul(n, d), x = r.add(x, d), c = r.mul(g, x), H = r.add(H, c), c = r.mul(h, x), U = r.mul(w, U), U = r.sub(U, c), c = r.mul(w, g), y = r.mul(h, y), y = r.add(y, c), new A(U, H, y);
3037
- }
3038
- subtract(_) {
3039
- return this.add(_.negate());
3040
- }
3041
- is0() {
3042
- return this.equals(A.ZERO);
3043
- }
3044
- wNAF(_) {
3045
- return Q.wNAFCached(this, _, A.normalizeZ);
3046
- }
3047
- /**
3048
- * Non-constant-time multiplication. Uses double-and-add algorithm.
3049
- * It's faster, but should only be used when you don't care about
3050
- * an exposed private key e.g. sig verification, which works over *public* keys.
3051
- */
3052
- multiplyUnsafe(_) {
3053
- const { endo: B, n: L } = e;
3054
- Wt("scalar", _, ee, L);
3055
- const T = A.ZERO;
3056
- if (_ === ee)
3057
- return T;
3058
- if (this.is0() || _ === qt)
3059
- return this;
3060
- if (!B || Q.hasPrecomputes(this))
3061
- return Q.wNAFCachedUnsafe(this, _, A.normalizeZ);
3062
- let { k1neg: q, k1: $, k2neg: C, k2: U } = B.splitScalar(_), H = T, y = T, n = this;
3063
- for (; $ > ee || U > ee; )
3064
- $ & qt && (H = H.add(n)), U & qt && (y = y.add(n)), n = n.double(), $ >>= qt, U >>= qt;
3065
- return q && (H = H.negate()), C && (y = y.negate()), y = new A(r.mul(y.px, B.beta), y.py, y.pz), H.add(y);
3066
- }
3067
- /**
3068
- * Constant time multiplication.
3069
- * Uses wNAF method. Windowed method may be 10% faster,
3070
- * but takes 2x longer to generate and consumes 2x memory.
3071
- * Uses precomputes when available.
3072
- * Uses endomorphism for Koblitz curves.
3073
- * @param scalar by which the point would be multiplied
3074
- * @returns New point
3075
- */
3076
- multiply(_) {
3077
- const { endo: B, n: L } = e;
3078
- Wt("scalar", _, qt, L);
3079
- let T, q;
3080
- if (B) {
3081
- const { k1neg: $, k1: C, k2neg: U, k2: H } = B.splitScalar(_);
3082
- let { p: y, f: n } = this.wNAF(C), { p: f, f: c } = this.wNAF(H);
3083
- y = Q.constTimeNegate($, y), f = Q.constTimeNegate(U, f), f = new A(r.mul(f.px, B.beta), f.py, f.pz), T = y.add(f), q = n.add(c);
3084
- } else {
3085
- const { p: $, f: C } = this.wNAF(_);
3086
- T = $, q = C;
3087
- }
3088
- return A.normalizeZ([T, q])[0];
3089
- }
3090
- /**
3091
- * Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
3092
- * Not using Strauss-Shamir trick: precomputation tables are faster.
3093
- * The trick could be useful if both P and Q are not G (not in our case).
3094
- * @returns non-zero affine point
3095
- */
3096
- multiplyAndAddUnsafe(_, B, L) {
3097
- const T = A.BASE, q = (C, U) => U === ee || U === qt || !C.equals(T) ? C.multiplyUnsafe(U) : C.multiply(U), $ = q(this, B).add(q(_, L));
3098
- return $.is0() ? void 0 : $;
3099
- }
3100
- // Converts Projective point to affine (x, y) coordinates.
3101
- // Can accept precomputed Z^-1 - for example, from invertBatch.
3102
- // (x, y, z) ∋ (x=x/z, y=y/z)
3103
- toAffine(_) {
3104
- return S(this, _);
3105
- }
3106
- isTorsionFree() {
3107
- const { h: _, isTorsionFree: B } = e;
3108
- if (_ === qt)
3109
- return !0;
3110
- if (B)
3111
- return B(A, this);
3112
- throw new Error("isTorsionFree() has not been declared for the elliptic curve");
3113
- }
3114
- clearCofactor() {
3115
- const { h: _, clearCofactor: B } = e;
3116
- return _ === qt ? this : B ? B(A, this) : this.multiplyUnsafe(e.h);
3117
- }
3118
- toRawBytes(_ = !0) {
3119
- return ae("isCompressed", _), this.assertValidity(), a(A, this, _);
3120
- }
3121
- toHex(_ = !0) {
3122
- return ae("isCompressed", _), Me(this.toRawBytes(_));
3123
- }
3124
- }
3125
- A.BASE = new A(e.Gx, e.Gy, r.ONE), A.ZERO = new A(r.ZERO, r.ONE, r.ZERO);
3126
- const { endo: D, nBitLength: V } = e, Q = _o(A, D ? Math.ceil(V / 2) : V);
3127
- return {
3128
- CURVE: e,
3129
- ProjectivePoint: A,
3130
- normPrivateKeyToScalar: E,
3131
- weierstrassEquation: l,
3132
- isWithinCurveOrder: v
3133
- };
3134
- }
3135
- function R0(t) {
3136
- const e = Rn(t);
3137
- return Pe(e, {
3138
- hash: "hash",
3139
- hmac: "function",
3140
- randomBytes: "function"
3141
- }, {
3142
- bits2int: "function",
3143
- bits2int_modN: "function",
3144
- lowS: "boolean"
3145
- }), Object.freeze({ lowS: !0, ...e });
3146
- }
3147
- function L0(t) {
3148
- const e = R0(t), { Fp: r, n: i, nByteLength: a, nBitLength: o } = e, l = r.BYTES + 1, u = 2 * r.BYTES + 1;
3149
- function m(f) {
3150
- return tt(f, i);
3151
- }
3152
- function b(f) {
3153
- return cn(f, i);
3154
- }
3155
- const { ProjectivePoint: v, normPrivateKeyToScalar: E, weierstrassEquation: M, isWithinCurveOrder: S } = N0({
3156
- ...e,
3157
- toBytes(f, c, g) {
3158
- const d = c.toAffine(), w = r.toBytes(d.x), x = Ae;
3159
- return ae("isCompressed", g), g ? x(Uint8Array.from([c.hasEvenY() ? 2 : 3]), w) : x(Uint8Array.from([4]), w, r.toBytes(d.y));
3160
- },
3161
- fromBytes(f) {
3162
- const c = f.length, g = f[0], d = f.subarray(1);
3163
- if (c === l && (g === 2 || g === 3)) {
3164
- const w = ue(d);
3165
- if (!kn(w, qt, r.ORDER))
3166
- throw new Error("Point is not on curve");
3167
- const x = M(w);
3168
- let h;
3169
- try {
3170
- h = r.sqrt(x);
3171
- } catch (k) {
3172
- const I = k instanceof Error ? ": " + k.message : "";
3173
- throw new Error("Point is not on curve" + I);
3174
- }
3175
- const s = (h & qt) === qt;
3176
- return (g & 1) === 1 !== s && (h = r.neg(h)), { x: w, y: h };
3177
- } else if (c === u && g === 4) {
3178
- const w = r.fromBytes(d.subarray(0, r.BYTES)), x = r.fromBytes(d.subarray(r.BYTES, 2 * r.BYTES));
3179
- return { x: w, y: x };
3180
- } else {
3181
- const w = l, x = u;
3182
- throw new Error("invalid Point, expected length of " + w + ", or uncompressed " + x + ", got " + c);
3183
- }
3184
- }
3185
- });
3186
- function O(f) {
3187
- const c = i >> qt;
3188
- return f > c;
3189
- }
3190
- function A(f) {
3191
- return O(f) ? m(-f) : f;
3192
- }
3193
- const D = (f, c, g) => ue(f.slice(c, g));
3194
- class V {
3195
- constructor(c, g, d) {
3196
- Wt("r", c, qt, i), Wt("s", g, qt, i), this.r = c, this.s = g, d != null && (this.recovery = d), Object.freeze(this);
3197
- }
3198
- // pair (bytes of r, bytes of s)
3199
- static fromCompact(c) {
3200
- const g = a;
3201
- return c = st("compactSignature", c, g * 2), new V(D(c, 0, g), D(c, g, 2 * g));
3202
- }
3203
- // DER encoded ECDSA signature
3204
- // https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
3205
- static fromDER(c) {
3206
- const { r: g, s: d } = te.toSig(st("DER", c));
3207
- return new V(g, d);
3208
- }
3209
- /**
3210
- * @todo remove
3211
- * @deprecated
3212
- */
3213
- assertValidity() {
3214
- }
3215
- addRecoveryBit(c) {
3216
- return new V(this.r, this.s, c);
3217
- }
3218
- recoverPublicKey(c) {
3219
- const { r: g, s: d, recovery: w } = this, x = T(st("msgHash", c));
3220
- if (w == null || ![0, 1, 2, 3].includes(w))
3221
- throw new Error("recovery id invalid");
3222
- const h = w === 2 || w === 3 ? g + e.n : g;
3223
- if (h >= r.ORDER)
3224
- throw new Error("recovery id 2 or 3 invalid");
3225
- const s = (w & 1) === 0 ? "02" : "03", p = v.fromHex(s + Kr(h, r.BYTES)), k = b(h), I = m(-x * k), N = m(d * k), P = v.BASE.multiplyAndAddUnsafe(p, I, N);
3226
- if (!P)
3227
- throw new Error("point at infinify");
3228
- return P.assertValidity(), P;
3229
- }
3230
- // Signatures should be low-s, to prevent malleability.
3231
- hasHighS() {
3232
- return O(this.s);
3233
- }
3234
- normalizeS() {
3235
- return this.hasHighS() ? new V(this.r, m(-this.s), this.recovery) : this;
3236
- }
3237
- // DER-encoded
3238
- toDERRawBytes() {
3239
- return cr(this.toDERHex());
3240
- }
3241
- toDERHex() {
3242
- return te.hexFromSig(this);
3243
- }
3244
- // padded bytes of r, then padded bytes of s
3245
- toCompactRawBytes() {
3246
- return cr(this.toCompactHex());
3247
- }
3248
- toCompactHex() {
3249
- const c = a;
3250
- return Kr(this.r, c) + Kr(this.s, c);
3251
- }
3252
- }
3253
- const Q = {
3254
- isValidPrivateKey(f) {
3255
- try {
3256
- return E(f), !0;
3257
- } catch {
3258
- return !1;
3259
- }
3260
- },
3261
- normPrivateKeyToScalar: E,
3262
- /**
3263
- * Produces cryptographically secure private key from random of size
3264
- * (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
3265
- */
3266
- randomPrivateKey: () => {
3267
- const f = vo(e.n);
3268
- return A0(e.randomBytes(f), e.n);
3269
- },
3270
- /**
3271
- * Creates precompute table for an arbitrary EC point. Makes point "cached".
3272
- * Allows to massively speed-up `point.multiply(scalar)`.
3273
- * @returns cached point
3274
- * @example
3275
- * const fast = utils.precompute(8, ProjectivePoint.fromHex(someonesPubKey));
3276
- * fast.multiply(privKey); // much faster ECDH now
3277
- */
3278
- precompute(f = 8, c = v.BASE) {
3279
- return c._setWindowSize(f), c.multiply(BigInt(3)), c;
3280
- }
3281
- };
3282
- function R(f, c = !0) {
3283
- return v.fromPrivateKey(f).toRawBytes(c);
3284
- }
3285
- function _(f) {
3286
- if (typeof f == "bigint")
3287
- return !1;
3288
- if (f instanceof v)
3289
- return !0;
3290
- const g = st("key", f).length, d = r.BYTES, w = d + 1, x = 2 * d + 1;
3291
- if (!(e.allowedPrivateKeyLengths || a === w))
3292
- return g === w || g === x;
3293
- }
3294
- function B(f, c, g = !0) {
3295
- if (_(f) === !0)
3296
- throw new Error("first arg must be private key");
3297
- if (_(c) === !1)
3298
- throw new Error("second arg must be public key");
3299
- return v.fromHex(c).multiply(E(f)).toRawBytes(g);
3300
- }
3301
- const L = e.bits2int || function(f) {
3302
- if (f.length > 8192)
3303
- throw new Error("input is too large");
3304
- const c = ue(f), g = f.length * 8 - o;
3305
- return g > 0 ? c >> BigInt(g) : c;
3306
- }, T = e.bits2int_modN || function(f) {
3307
- return m(L(f));
3308
- }, q = gr(o);
3309
- function $(f) {
3310
- return Wt("num < 2^" + o, f, ee, q), De(f, a);
3311
- }
3312
- function C(f, c, g = U) {
3313
- if (["recovered", "canonical"].some((z) => z in g))
3314
- throw new Error("sign() legacy options not supported");
3315
- const { hash: d, randomBytes: w } = e;
3316
- let { lowS: x, prehash: h, extraEntropy: s } = g;
3317
- x == null && (x = !0), f = st("msgHash", f), mi(g), h && (f = st("prehashed msgHash", d(f)));
3318
- const p = T(f), k = E(c), I = [$(k), $(p)];
3319
- if (s != null && s !== !1) {
3320
- const z = s === !0 ? w(r.BYTES) : s;
3321
- I.push(st("extraEntropy", z));
3322
- }
3323
- const N = Ae(...I), P = p;
3324
- function Z(z) {
3325
- const ft = L(z);
3326
- if (!S(ft))
3327
- return;
3328
- const W = b(ft), Y = v.BASE.multiply(ft).toAffine(), Ht = m(Y.x);
3329
- if (Ht === ee)
3330
- return;
3331
- const K = m(W * m(P + Ht * k));
3332
- if (K === ee)
3333
- return;
3334
- let J = (Y.x === Ht ? 0 : 2) | Number(Y.y & qt), Yt = K;
3335
- return x && O(K) && (Yt = A(K), J ^= 1), new V(Ht, Yt, J);
3336
- }
3337
- return { seed: N, k2sig: Z };
3338
- }
3339
- const U = { lowS: e.lowS, prehash: !1 }, H = { lowS: e.lowS, prehash: !1 };
3340
- function y(f, c, g = U) {
3341
- const { seed: d, k2sig: w } = C(f, c, g), x = e;
3342
- return g0(x.hash.outputLen, x.nByteLength, x.hmac)(d, w);
3343
- }
3344
- v.BASE._setWindowSize(8);
3345
- function n(f, c, g, d = H) {
3346
- var J;
3347
- const w = f;
3348
- c = st("msgHash", c), g = st("publicKey", g);
3349
- const { lowS: x, prehash: h, format: s } = d;
3350
- if (mi(d), "strict" in d)
3351
- throw new Error("options.strict was renamed to lowS");
3352
- if (s !== void 0 && s !== "compact" && s !== "der")
3353
- throw new Error("format must be compact or der");
3354
- const p = typeof w == "string" || Ce(w), k = !p && !s && typeof w == "object" && w !== null && typeof w.r == "bigint" && typeof w.s == "bigint";
3355
- if (!p && !k)
3356
- throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
3357
- let I, N;
3358
- try {
3359
- if (k && (I = new V(w.r, w.s)), p) {
3360
- try {
3361
- s !== "compact" && (I = V.fromDER(w));
3362
- } catch (Yt) {
3363
- if (!(Yt instanceof te.Err))
3364
- throw Yt;
3365
- }
3366
- !I && s !== "der" && (I = V.fromCompact(w));
3367
- }
3368
- N = v.fromHex(g);
3369
- } catch {
3370
- return !1;
3371
- }
3372
- if (!I || x && I.hasHighS())
3373
- return !1;
3374
- h && (c = e.hash(c));
3375
- const { r: P, s: Z } = I, z = T(c), ft = b(Z), W = m(z * ft), Y = m(P * ft), Ht = (J = v.BASE.multiplyAndAddUnsafe(N, W, Y)) == null ? void 0 : J.toAffine();
3376
- return Ht ? m(Ht.x) === P : !1;
3377
- }
3378
- return {
3379
- CURVE: e,
3380
- getPublicKey: R,
3381
- getSharedSecret: B,
3382
- sign: y,
3383
- verify: n,
3384
- ProjectivePoint: v,
3385
- Signature: V,
3386
- utils: Q
3387
- };
3388
- }
3389
- function O0(t) {
3390
- return {
3391
- hash: t,
3392
- hmac: (e, ...r) => ho(t, e, Xf(...r)),
3393
- randomBytes: so
3394
- };
3395
- }
3396
- function T0(t, e) {
3397
- const r = (i) => L0({ ...t, ...O0(i) });
3398
- return { ...r(e), create: r };
3399
- }
3400
- const Ao = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"), pi = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"), H0 = BigInt(0), q0 = BigInt(1), ln = BigInt(2), yi = (t, e) => (t + e / ln) / e;
3401
- function $0(t) {
3402
- const e = Ao, r = BigInt(3), i = BigInt(6), a = BigInt(11), o = BigInt(22), l = BigInt(23), u = BigInt(44), m = BigInt(88), b = t * t * t % e, v = b * b * t % e, E = ot(v, r, e) * v % e, M = ot(E, r, e) * v % e, S = ot(M, ln, e) * b % e, O = ot(S, a, e) * S % e, A = ot(O, o, e) * O % e, D = ot(A, u, e) * A % e, V = ot(D, m, e) * D % e, Q = ot(V, u, e) * A % e, R = ot(Q, r, e) * v % e, _ = ot(R, l, e) * O % e, B = ot(_, i, e) * b % e, L = ot(B, ln, e);
3403
- if (!un.eql(un.sqr(L), t))
3404
- throw new Error("Cannot find square root");
3405
- return L;
3406
- }
3407
- const un = Ze(Ao, void 0, void 0, { sqrt: $0 }), Ve = T0({
3408
- a: H0,
3409
- b: BigInt(7),
3410
- Fp: un,
3411
- n: pi,
3412
- Gx: BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
3413
- Gy: BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),
3414
- h: BigInt(1),
3415
- lowS: !0,
3416
- // Allow only low-S signatures by default in sign() and verify()
3417
- endo: {
3418
- // Endomorphism, see above
3419
- beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
3420
- splitScalar: (t) => {
3421
- const e = pi, r = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), i = -q0 * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), a = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), o = r, l = BigInt("0x100000000000000000000000000000000"), u = yi(o * t, e), m = yi(-i * t, e);
3422
- let b = tt(t - u * r - m * a, e), v = tt(-u * i - m * o, e);
3423
- const E = b > l, M = v > l;
3424
- if (E && (b = e - b), M && (v = e - v), b > l || v > l)
3425
- throw new Error("splitScalar: Endomorphism failed, k=" + t);
3426
- return { k1neg: E, k1: b, k2neg: M, k2: v };
3427
- }
3428
- }
3429
- }, l0);
3430
- function Be(t, e) {
3431
- if (t.length !== 32)
3432
- throw new Error("Expected valid 32-byte private key as a seed");
3433
- if (!Vt || !e && zt()) {
3434
- const r = as(t), i = r.slice(32);
3435
- if (zi(i))
3436
- throw new Error("Invalid publicKey generated from WASM interface");
3437
- return {
3438
- publicKey: i,
3439
- secretKey: r.slice(0, 32)
3440
- };
3441
- }
3442
- return {
3443
- publicKey: Ve.getPublicKey(t, !0),
3444
- secretKey: t
3445
- };
3446
- }
3447
- function Bo(t, e) {
3448
- return (r, { chainCode: i, isHard: a }) => {
3449
- if (!a)
3450
- throw new Error("A soft key was found in the path and is not supported");
3451
- return t(e(r.secretKey.subarray(0, 32), i));
3452
- };
3453
- }
3454
- const xi = /* @__PURE__ */ Bo(Be, Vf), C0 = _n(ce("Ed25519HDKD"));
3455
- function D0(t, e) {
3456
- if (!de(e) || e.length !== 32)
3457
- throw new Error("Invalid chainCode passed to derive");
3458
- return we($t(C0, t, e));
3459
- }
3460
- const Kt = BigInt(0), Pt = BigInt(1), vi = BigInt(2), P0 = BigInt(8), Z0 = { zip215: !0 };
3461
- function V0(t) {
3462
- const e = Rn(t);
3463
- return Pe(t, {
3464
- hash: "function",
3465
- a: "bigint",
3466
- d: "bigint",
3467
- randomBytes: "function"
3468
- }, {
3469
- adjustScalarBytes: "function",
3470
- domain: "function",
3471
- uvRatio: "function",
3472
- mapToCurve: "function"
3473
- }), Object.freeze({ ...e });
3474
- }
3475
- function z0(t) {
3476
- const e = V0(t), { Fp: r, n: i, prehash: a, hash: o, randomBytes: l, nByteLength: u, h: m } = e, b = vi << BigInt(u * 8) - Pt, v = r.create, E = Ze(e.n, e.nBitLength);
3477
- function M(d, w) {
3478
- const x = r.sqr(d), h = r.sqr(w), s = r.add(r.mul(e.a, x), h), p = r.add(r.ONE, r.mul(e.d, r.mul(x, h)));
3479
- return r.eql(s, p);
3480
- }
3481
- if (!M(e.Gx, e.Gy))
3482
- throw new Error("bad curve params: generator point");
3483
- const S = e.uvRatio || ((d, w) => {
3484
- try {
3485
- return { isValid: !0, value: r.sqrt(d * r.inv(w)) };
3486
- } catch {
3487
- return { isValid: !1, value: Kt };
3488
- }
3489
- }), O = e.adjustScalarBytes || ((d) => d), A = e.domain || ((d, w, x) => {
3490
- if (ae("phflag", x), w.length || x)
3491
- throw new Error("Contexts/pre-hash are not supported");
3492
- return d;
3493
- });
3494
- function D(d, w, x = !1) {
3495
- const h = x ? Pt : Kt;
3496
- Wt("coordinate " + d, w, h, b);
3497
- }
3498
- function V(d) {
3499
- if (!(d instanceof _))
3500
- throw new Error("ExtendedPoint expected");
3501
- }
3502
- const Q = lr((d, w) => {
3503
- const { ex: x, ey: h, ez: s } = d, p = d.is0();
3504
- w == null && (w = p ? P0 : r.inv(s));
3505
- const k = v(x * w), I = v(h * w), N = v(s * w);
3506
- if (p)
3507
- return { x: Kt, y: Pt };
3508
- if (N !== Pt)
3509
- throw new Error("invZ was invalid");
3510
- return { x: k, y: I };
3511
- }), R = lr((d) => {
3512
- const { a: w, d: x } = e;
3513
- if (d.is0())
3514
- throw new Error("bad point: ZERO");
3515
- const { ex: h, ey: s, ez: p, et: k } = d, I = v(h * h), N = v(s * s), P = v(p * p), Z = v(P * P), z = v(I * w), ft = v(P * v(z + N)), W = v(Z + v(x * v(I * N)));
3516
- if (ft !== W)
3517
- throw new Error("bad point: equation left != right (1)");
3518
- const Y = v(h * s), Ht = v(p * k);
3519
- if (Y !== Ht)
3520
- throw new Error("bad point: equation left != right (2)");
3521
- return !0;
3522
- });
3523
- class _ {
3524
- constructor(w, x, h, s) {
3525
- D("x", w), D("y", x), D("z", h, !0), D("t", s), this.ex = w, this.ey = x, this.ez = h, this.et = s, Object.freeze(this);
3526
- }
3527
- get x() {
3528
- return this.toAffine().x;
3529
- }
3530
- get y() {
3531
- return this.toAffine().y;
3532
- }
3533
- static fromAffine(w) {
3534
- if (w instanceof _)
3535
- throw new Error("extended point not allowed");
3536
- const { x, y: h } = w || {};
3537
- return D("x", x), D("y", h), new _(x, h, Pt, v(x * h));
3538
- }
3539
- static normalizeZ(w) {
3540
- const x = Nn(r, w.map((h) => h.ez));
3541
- return w.map((h, s) => h.toAffine(x[s])).map(_.fromAffine);
3542
- }
3543
- // Multiscalar Multiplication
3544
- static msm(w, x) {
3545
- return Mo(_, E, w, x);
3546
- }
3547
- // "Private method", don't use it directly
3548
- _setWindowSize(w) {
3549
- T.setWindowSize(this, w);
3550
- }
3551
- // Not required for fromHex(), which always creates valid points.
3552
- // Could be useful for fromAffine().
3553
- assertValidity() {
3554
- R(this);
3555
- }
3556
- // Compare one point to another.
3557
- equals(w) {
3558
- V(w);
3559
- const { ex: x, ey: h, ez: s } = this, { ex: p, ey: k, ez: I } = w, N = v(x * I), P = v(p * s), Z = v(h * I), z = v(k * s);
3560
- return N === P && Z === z;
3561
- }
3562
- is0() {
3563
- return this.equals(_.ZERO);
3564
- }
3565
- negate() {
3566
- return new _(v(-this.ex), this.ey, this.ez, v(-this.et));
3567
- }
3568
- // Fast algo for doubling Extended Point.
3569
- // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#doubling-dbl-2008-hwcd
3570
- // Cost: 4M + 4S + 1*a + 6add + 1*2.
3571
- double() {
3572
- const { a: w } = e, { ex: x, ey: h, ez: s } = this, p = v(x * x), k = v(h * h), I = v(vi * v(s * s)), N = v(w * p), P = x + h, Z = v(v(P * P) - p - k), z = N + k, ft = z - I, W = N - k, Y = v(Z * ft), Ht = v(z * W), K = v(Z * W), J = v(ft * z);
3573
- return new _(Y, Ht, J, K);
3574
- }
3575
- // Fast algo for adding 2 Extended Points.
3576
- // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#addition-add-2008-hwcd
3577
- // Cost: 9M + 1*a + 1*d + 7add.
3578
- add(w) {
3579
- V(w);
3580
- const { a: x, d: h } = e, { ex: s, ey: p, ez: k, et: I } = this, { ex: N, ey: P, ez: Z, et: z } = w, ft = v(s * N), W = v(p * P), Y = v(I * h * z), Ht = v(k * Z), K = v((s + p) * (N + P) - ft - W), J = Ht - Y, Yt = Ht + Y, et = v(W - x * ft), rt = v(K * J), ze = v(Yt * et), nt = v(K * et), it = v(J * Yt);
3581
- return new _(rt, ze, it, nt);
3582
- }
3583
- subtract(w) {
3584
- return this.add(w.negate());
3585
- }
3586
- wNAF(w) {
3587
- return T.wNAFCached(this, w, _.normalizeZ);
3588
- }
3589
- // Constant-time multiplication.
3590
- multiply(w) {
3591
- const x = w;
3592
- Wt("scalar", x, Pt, i);
3593
- const { p: h, f: s } = this.wNAF(x);
3594
- return _.normalizeZ([h, s])[0];
3595
- }
3596
- // Non-constant-time multiplication. Uses double-and-add algorithm.
3597
- // It's faster, but should only be used when you don't care about
3598
- // an exposed private key e.g. sig verification.
3599
- // Does NOT allow scalars higher than CURVE.n.
3600
- // Accepts optional accumulator to merge with multiply (important for sparse scalars)
3601
- multiplyUnsafe(w, x = _.ZERO) {
3602
- const h = w;
3603
- return Wt("scalar", h, Kt, i), h === Kt ? L : this.is0() || h === Pt ? this : T.wNAFCachedUnsafe(this, h, _.normalizeZ, x);
3604
- }
3605
- // Checks if point is of small order.
3606
- // If you add something to small order point, you will have "dirty"
3607
- // point with torsion component.
3608
- // Multiplies point by cofactor and checks if the result is 0.
3609
- isSmallOrder() {
3610
- return this.multiplyUnsafe(m).is0();
3611
- }
3612
- // Multiplies point by curve order and checks if the result is 0.
3613
- // Returns `false` is the point is dirty.
3614
- isTorsionFree() {
3615
- return T.unsafeLadder(this, i).is0();
3616
- }
3617
- // Converts Extended point to default (x, y) coordinates.
3618
- // Can accept precomputed Z^-1 - for example, from invertBatch.
3619
- toAffine(w) {
3620
- return Q(this, w);
3621
- }
3622
- clearCofactor() {
3623
- const { h: w } = e;
3624
- return w === Pt ? this : this.multiplyUnsafe(w);
3625
- }
3626
- // Converts hash string or Uint8Array to Point.
3627
- // Uses algo from RFC8032 5.1.3.
3628
- static fromHex(w, x = !1) {
3629
- const { d: h, a: s } = e, p = r.BYTES;
3630
- w = st("pointHex", w, p), ae("zip215", x);
3631
- const k = w.slice(), I = w[p - 1];
3632
- k[p - 1] = I & -129;
3633
- const N = Ne(k), P = x ? b : r.ORDER;
3634
- Wt("pointHex.y", N, Kt, P);
3635
- const Z = v(N * N), z = v(Z - Pt), ft = v(h * Z - s);
3636
- let { isValid: W, value: Y } = S(z, ft);
3637
- if (!W)
3638
- throw new Error("Point.fromHex: invalid y coordinate");
3639
- const Ht = (Y & Pt) === Pt, K = (I & 128) !== 0;
3640
- if (!x && Y === Kt && K)
3641
- throw new Error("Point.fromHex: x=0 and x_0=1");
3642
- return K !== Ht && (Y = v(-Y)), _.fromAffine({ x: Y, y: N });
3643
- }
3644
- static fromPrivateKey(w) {
3645
- const { scalar: x } = C(w);
3646
- return B.multiply(x);
3647
- }
3648
- toRawBytes() {
3649
- const { x: w, y: x } = this.toAffine(), h = hr(x, r.BYTES);
3650
- return h[h.length - 1] |= w & Pt ? 128 : 0, h;
3651
- }
3652
- toHex() {
3653
- return Me(this.toRawBytes());
3654
- }
3655
- }
3656
- _.BASE = new _(e.Gx, e.Gy, Pt, v(e.Gx * e.Gy)), _.ZERO = new _(Kt, Pt, Pt, Kt);
3657
- const { BASE: B, ZERO: L } = _, T = _o(_, u * 8);
3658
- function q(d) {
3659
- return tt(d, i);
3660
- }
3661
- function $(d) {
3662
- return q(Ne(d));
3663
- }
3664
- function C(d) {
3665
- const w = r.BYTES;
3666
- d = st("private key", d, w);
3667
- const x = st("hashed private key", o(d), 2 * w), h = O(x.slice(0, w)), s = x.slice(w, 2 * w), p = $(h);
3668
- return { head: h, prefix: s, scalar: p };
3669
- }
3670
- function U(d) {
3671
- const { head: w, prefix: x, scalar: h } = C(d), s = B.multiply(h), p = s.toRawBytes();
3672
- return { head: w, prefix: x, scalar: h, point: s, pointBytes: p };
3673
- }
3674
- function H(d) {
3675
- return U(d).pointBytes;
3676
- }
3677
- function y(d = Uint8Array.of(), ...w) {
3678
- const x = Ae(...w);
3679
- return $(o(A(x, st("context", d), !!a)));
3680
- }
3681
- function n(d, w, x = {}) {
3682
- d = st("message", d), a && (d = a(d));
3683
- const { prefix: h, scalar: s, pointBytes: p } = U(w), k = y(x.context, h, d), I = B.multiply(k).toRawBytes(), N = y(x.context, I, p, d), P = q(k + N * s);
3684
- Wt("signature.s", P, Kt, i);
3685
- const Z = Ae(I, hr(P, r.BYTES));
3686
- return st("result", Z, r.BYTES * 2);
3687
- }
3688
- const f = Z0;
3689
- function c(d, w, x, h = f) {
3690
- const { context: s, zip215: p } = h, k = r.BYTES;
3691
- d = st("signature", d, 2 * k), w = st("message", w), x = st("publicKey", x, k), p !== void 0 && ae("zip215", p), a && (w = a(w));
3692
- const I = Ne(d.slice(k, 2 * k));
3693
- let N, P, Z;
3694
- try {
3695
- N = _.fromHex(x, p), P = _.fromHex(d.slice(0, k), p), Z = B.multiplyUnsafe(I);
3696
- } catch {
3697
- return !1;
3698
- }
3699
- if (!p && N.isSmallOrder())
3700
- return !1;
3701
- const z = y(s, P.toRawBytes(), N.toRawBytes(), w);
3702
- return P.add(N.multiplyUnsafe(z)).subtract(Z).clearCofactor().equals(_.ZERO);
3703
- }
3704
- return B._setWindowSize(8), {
3705
- CURVE: e,
3706
- getPublicKey: H,
3707
- sign: n,
3708
- verify: c,
3709
- ExtendedPoint: _,
3710
- utils: {
3711
- getExtendedPublicKey: U,
3712
- /** ed25519 priv keys are uniform 32b. No need to check for modulo bias, like in secp256k1. */
3713
- randomPrivateKey: () => l(r.BYTES),
3714
- /**
3715
- * We're doing scalar multiplication (used in getPublicKey etc) with precomputed BASE_POINT
3716
- * values. This slows down first getPublicKey() by milliseconds (see Speed section),
3717
- * but allows to speed-up subsequent getPublicKey() calls up to 20x.
3718
- * @param windowSize 2, 4, 8, 16
3719
- */
3720
- precompute(d = 8, w = _.BASE) {
3721
- return w._setWindowSize(d), w.multiply(BigInt(3)), w;
3722
- }
3723
- }
3724
- };
3725
- }
3726
- const Nc = BigInt(0), Rc = BigInt(1), Lc = BigInt(2);
3727
- const Ln = BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"), bi = /* @__PURE__ */ BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");
3728
- BigInt(0);
3729
- const G0 = BigInt(1), Ei = BigInt(2), Oc = BigInt(3), Y0 = BigInt(5), W0 = BigInt(8);
3730
- function X0(t) {
3731
- const e = BigInt(10), r = BigInt(20), i = BigInt(40), a = BigInt(80), o = Ln, u = t * t % o * t % o, m = ot(u, Ei, o) * u % o, b = ot(m, G0, o) * t % o, v = ot(b, Y0, o) * b % o, E = ot(v, e, o) * v % o, M = ot(E, r, o) * E % o, S = ot(M, i, o) * M % o, O = ot(S, a, o) * S % o, A = ot(O, a, o) * S % o, D = ot(A, e, o) * v % o;
3732
- return { pow_p_5_8: ot(D, Ei, o) * t % o, b2: u };
3733
- }
3734
- function K0(t) {
3735
- return t[0] &= 248, t[31] &= 127, t[31] |= 64, t;
3736
- }
3737
- function j0(t, e) {
3738
- const r = Ln, i = tt(e * e * e, r), a = tt(i * i * e, r), o = X0(t * a).pow_p_5_8;
3739
- let l = tt(t * i * o, r);
3740
- const u = tt(e * l * l, r), m = l, b = tt(l * bi, r), v = u === t, E = u === tt(-t, r), M = u === tt(-t * bi, r);
3741
- return v && (l = m), (E || M) && (l = b), b0(l, r) && (l = tt(-l, r)), { isValid: v || E, value: l };
3742
- }
3743
- const _i = Ze(Ln, void 0, !0), J0 = {
3744
- // Removing Fp.create() will still work, and is 10% faster on sign
3745
- a: _i.create(BigInt(-1)),
3746
- // d is -121665/121666 a.k.a. Fp.neg(121665 * Fp.inv(121666))
3747
- d: BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),
3748
- // Finite field 2n**255n - 19n
3749
- Fp: _i,
3750
- // Subgroup order 2n**252n + 27742317777372353535851937790883648493n;
3751
- n: BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),
3752
- h: W0,
3753
- Gx: BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),
3754
- Gy: BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),
3755
- hash: u0,
3756
- randomBytes: so,
3757
- adjustScalarBytes: K0,
3758
- // dom2
3759
- // Ratio of u to v. Allows us to combine inversion and square root. Uses algo from RFC8032 5.1.3.
3760
- // Constant-time, u/√v
3761
- uvRatio: j0
3762
- }, On = z0(J0);
3763
- function Tn(t, e) {
3764
- if (!Vt || !e && zt()) {
3765
- const i = cs(t);
3766
- return {
3767
- publicKey: i.slice(32),
3768
- secretKey: i.slice(0, 64)
3769
- };
3770
- }
3771
- const r = On.getPublicKey(t);
3772
- return {
3773
- publicKey: r,
3774
- secretKey: He([t, r])
3775
- };
3776
- }
3777
- function F0(t, { publicKey: e, secretKey: r }, i) {
3778
- if (r) {
3779
- if (!e)
3780
- throw new Error("Expected a valid publicKey");
3781
- } else throw new Error("Expected a valid secretKey");
3782
- const a = G(t), o = r.subarray(0, 32);
3783
- return !Vt || !i && zt() ? hs(e, o, a) : On.sign(a, o);
3784
- }
3785
- function So(t, e, r, i) {
3786
- const a = G(t), o = G(r), l = G(e);
3787
- if (o.length !== 32)
3788
- throw new Error(`Invalid publicKey, received ${o.length}, expected 32`);
3789
- if (l.length !== 64)
3790
- throw new Error(`Invalid signature, received ${l.length} bytes, expected 64`);
3791
- try {
3792
- return !Vt || !i && zt() ? ls(l, a, o) : On.verify(l, a, o);
3793
- } catch {
3794
- return !1;
3795
- }
3796
- }
3797
- const Q0 = /* @__PURE__ */ Bo(Tn, D0), dn = 64, ta = 32, Jr = dn + ta;
3798
- function Io(t) {
3799
- const e = G(t);
3800
- if (e.length !== Jr)
3801
- throw new Error(`Expected keypair with ${Jr} bytes, found ${e.length}`);
3802
- return {
3803
- publicKey: e.slice(dn, Jr),
3804
- secretKey: e.slice(0, dn)
3805
- };
3806
- }
3807
- function ea({ publicKey: t, secretKey: e }) {
3808
- return $t(e, t).slice();
3809
- }
3810
- function Uo(t) {
3811
- return (e, r) => {
3812
- if (!de(r) || r.length !== 32)
3813
- throw new Error("Invalid chainCode passed to derive");
3814
- return Io(t(ea(e), r));
3815
- };
3816
- }
3817
- const ra = /* @__PURE__ */ Uo(us), na = /* @__PURE__ */ Uo(ds);
3818
- function ia(t, { chainCode: e, isSoft: r }) {
3819
- return r ? na(t, e) : ra(t, e);
3820
- }
3821
- const oa = {
3822
- ecdsa: xi,
3823
- ed25519: Q0,
3824
- // FIXME This is Substrate-compatible, not Ethereum-compatible
3825
- ethereum: xi,
3826
- sr25519: ia
3827
- };
3828
- function ko(t, e, r) {
3829
- const i = oa[r];
3830
- let a = t;
3831
- for (const o of e)
3832
- a = i(a, o);
3833
- return a;
3834
- }
3835
- function No(t) {
3836
- const e = G(t);
3837
- if (e.length !== 32)
3838
- throw new Error(`Expected a seed matching 32 bytes, found ${e.length}`);
3839
- return Io(ws(e));
3840
- }
3841
- function sa(t, { publicKey: e, secretKey: r }) {
3842
- if ((e == null ? void 0 : e.length) !== 32)
3843
- throw new Error("Expected a valid publicKey, 32-bytes");
3844
- if ((r == null ? void 0 : r.length) !== 64)
3845
- throw new Error("Expected a valid secretKey, 64-bytes");
3846
- return gs(e, r, G(t));
3847
- }
3848
- function Ro(t, e, r) {
3849
- const i = G(r), a = G(e);
3850
- if (i.length !== 32)
3851
- throw new Error(`Invalid publicKey, received ${i.length} bytes, expected 32`);
3852
- if (a.length !== 64)
3853
- throw new Error(`Invalid signature, received ${a.length} bytes, expected 64`);
3854
- return ms(a, G(t), i);
3855
- }
3856
- const Mi = new Uint8Array();
3857
- function fa(t, { secretKey: e }, r = Mi, i = Mi) {
3858
- if ((e == null ? void 0 : e.length) !== 64)
3859
- throw new Error("Invalid secretKey, expected 64-bytes");
3860
- return ps(e, G(r), G(t), G(i));
3861
- }
3862
- const Ai = new Uint8Array();
3863
- function aa(t, e, r, i = Ai, a = Ai) {
3864
- const o = G(r), l = G(e);
3865
- if (o.length !== 32)
3866
- throw new Error("Invalid publicKey, expected 32-bytes");
3867
- if (l.length !== 96)
3868
- throw new Error("Invalid vrfSign output, expected 96 bytes");
3869
- return ys(o, G(i), G(t), G(a), l);
3870
- }
3871
- function ca(t, e = Fe.prefix) {
3872
- const r = be(t);
3873
- if (e < 0 || e > 16383 || [46, 47].includes(e))
3874
- throw new Error("Out of range ss58Format specified");
3875
- if (!Fe.allowedDecodedLengths.includes(r.length))
3876
- throw new Error(`Expected a valid key to convert, with length ${Fe.allowedDecodedLengths.join(", ")}`);
3877
- const i = $t(e < 64 ? [e] : [
3878
- (e & 252) >> 2 | 64,
3879
- e >> 8 | (e & 3) << 6
3880
- ], r);
3881
- return Rf($t(i, ro(i).subarray(0, [32, 33].includes(r.length) ? 2 : 1)));
3882
- }
3883
- const Lo = [], Oo = [], To = [], ha = /* @__PURE__ */ BigInt(0), Se = /* @__PURE__ */ BigInt(1), la = /* @__PURE__ */ BigInt(2), ua = /* @__PURE__ */ BigInt(7), da = /* @__PURE__ */ BigInt(256), wa = /* @__PURE__ */ BigInt(113);
3884
- for (let t = 0, e = Se, r = 1, i = 0; t < 24; t++) {
3885
- [r, i] = [i, (2 * r + 3 * i) % 5], Lo.push(2 * (5 * i + r)), Oo.push((t + 1) * (t + 2) / 2 % 64);
3886
- let a = ha;
3887
- for (let o = 0; o < 7; o++)
3888
- e = (e << Se ^ (e >> ua) * wa) % da, e & la && (a ^= Se << (Se << /* @__PURE__ */ BigInt(o)) - Se);
3889
- To.push(a);
3890
- }
3891
- const [ga, ma] = /* @__PURE__ */ xs(To, !0), Bi = (t, e, r) => r > 32 ? vs(t, e, r) : bs(t, e, r), Si = (t, e, r) => r > 32 ? Es(t, e, r) : _s(t, e, r);
3892
- function pa(t, e = 24) {
3893
- const r = new Uint32Array(10);
3894
- for (let i = 24 - e; i < 24; i++) {
3895
- for (let l = 0; l < 10; l++)
3896
- r[l] = t[l] ^ t[l + 10] ^ t[l + 20] ^ t[l + 30] ^ t[l + 40];
3897
- for (let l = 0; l < 10; l += 2) {
3898
- const u = (l + 8) % 10, m = (l + 2) % 10, b = r[m], v = r[m + 1], E = Bi(b, v, 1) ^ r[u], M = Si(b, v, 1) ^ r[u + 1];
3899
- for (let S = 0; S < 50; S += 10)
3900
- t[l + S] ^= E, t[l + S + 1] ^= M;
3901
- }
3902
- let a = t[2], o = t[3];
3903
- for (let l = 0; l < 24; l++) {
3904
- const u = Oo[l], m = Bi(a, o, u), b = Si(a, o, u), v = Lo[l];
3905
- a = t[v], o = t[v + 1], t[v] = m, t[v + 1] = b;
3906
- }
3907
- for (let l = 0; l < 50; l += 10) {
3908
- for (let u = 0; u < 10; u++)
3909
- r[u] = t[l + u];
3910
- for (let u = 0; u < 10; u++)
3911
- t[l + u] ^= ~r[(u + 2) % 10] & r[(u + 4) % 10];
3912
- }
3913
- t[0] ^= ga[i], t[1] ^= ma[i];
3914
- }
3915
- r.fill(0);
3916
- }
3917
- class mr extends es {
3918
- // NOTE: we accept arguments in bytes instead of bits here.
3919
- constructor(e, r, i, a = !1, o = 24) {
3920
- if (super(), this.blockLen = e, this.suffix = r, this.outputLen = i, this.enableXOF = a, this.rounds = o, this.pos = 0, this.posOut = 0, this.finished = !1, this.destroyed = !1, se(i), 0 >= this.blockLen || this.blockLen >= 200)
3921
- throw new Error("Sha3 supports only keccak-f1600 function");
3922
- this.state = new Uint8Array(200), this.state32 = Je(this.state);
3923
- }
3924
- keccak() {
3925
- tr || er(this.state32), pa(this.state32, this.rounds), tr || er(this.state32), this.posOut = 0, this.pos = 0;
3926
- }
3927
- update(e) {
3928
- Qn(this);
3929
- const { blockLen: r, state: i } = this;
3930
- e = rs(e);
3931
- const a = e.length;
3932
- for (let o = 0; o < a; ) {
3933
- const l = Math.min(r - this.pos, a - o);
3934
- for (let u = 0; u < l; u++)
3935
- i[this.pos++] ^= e[o++];
3936
- this.pos === r && this.keccak();
3937
- }
3938
- return this;
3939
- }
3940
- finish() {
3941
- if (this.finished)
3942
- return;
3943
- this.finished = !0;
3944
- const { state: e, suffix: r, pos: i, blockLen: a } = this;
3945
- e[i] ^= r, (r & 128) !== 0 && i === a - 1 && this.keccak(), e[a - 1] ^= 128, this.keccak();
3946
- }
3947
- writeInto(e) {
3948
- Qn(this, !1), ns(e), this.finish();
3949
- const r = this.state, { blockLen: i } = this;
3950
- for (let a = 0, o = e.length; a < o; ) {
3951
- this.posOut >= i && this.keccak();
3952
- const l = Math.min(i - this.posOut, o - a);
3953
- e.set(r.subarray(this.posOut, this.posOut + l), a), this.posOut += l, a += l;
3954
- }
3955
- return e;
3956
- }
3957
- xofInto(e) {
3958
- if (!this.enableXOF)
3959
- throw new Error("XOF is not possible for this instance");
3960
- return this.writeInto(e);
3961
- }
3962
- xof(e) {
3963
- return se(e), this.xofInto(new Uint8Array(e));
3964
- }
3965
- digestInto(e) {
3966
- if (is(e, this), this.finished)
3967
- throw new Error("digest() was already called");
3968
- return this.writeInto(e), this.destroy(), e;
3969
- }
3970
- digest() {
3971
- return this.digestInto(new Uint8Array(this.outputLen));
3972
- }
3973
- destroy() {
3974
- this.destroyed = !0, this.state.fill(0);
3975
- }
3976
- _cloneInto(e) {
3977
- const { blockLen: r, suffix: i, outputLen: a, rounds: o, enableXOF: l } = this;
3978
- return e || (e = new mr(r, i, a, l, o)), e.state32.set(this.state32), e.pos = this.pos, e.posOut = this.posOut, e.finished = this.finished, e.rounds = o, e.suffix = i, e.outputLen = a, e.enableXOF = l, e.destroyed = this.destroyed, e;
3979
- }
3980
- }
3981
- const he = (t, e, r) => Qo(() => new mr(e, t, r));
3982
- 224 / 8;
3983
- 256 / 8;
3984
- 384 / 8;
3985
- 512 / 8;
3986
- 224 / 8;
3987
- const ya = /* @__PURE__ */ he(1, 136, 256 / 8);
3988
- 384 / 8;
3989
- const xa = /* @__PURE__ */ he(1, 72, 512 / 8), Ho = (t, e, r) => ts((i = {}) => new mr(e, t, i.dkLen === void 0 ? r : i.dkLen, !0));
3990
- 128 / 8;
3991
- 256 / 8;
3992
- const pr = /* @__PURE__ */ Ms({ 256: Bs, 512: As }, { 256: ya, 512: xa });
3993
- function wn(t, e, r) {
3994
- return t === "keccak" ? pr(e, void 0, r) : we(e, void 0, void 0, r);
3995
- }
3996
- const Hn = {
3997
- chars: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
3998
- coder: Sf,
3999
- type: "base64",
4000
- withPadding: !0
4001
- }, va = /* @__PURE__ */ eo(Hn), ba = /* @__PURE__ */ Qi(Hn, va), Ea = /* @__PURE__ */ to(Hn);
4002
- function qo(t, e) {
4003
- if (![33, 65].includes(t.length))
4004
- throw new Error(`Invalid publicKey provided, received ${t.length} bytes input`);
4005
- return t.length === 33 ? t : !Vt || zt() ? Ss(t) : Ve.ProjectivePoint.fromHex(t).toRawBytes(!0);
4006
- }
4007
- function qn(t, e) {
4008
- if (![33, 65].includes(t.length))
4009
- throw new Error(`Invalid publicKey provided, received ${t.length} bytes input`);
4010
- if (t.length === 65)
4011
- return t.subarray(1);
4012
- if (!Vt || zt())
4013
- return Is(t).subarray(1);
4014
- const { px: r, py: i } = Ve.ProjectivePoint.fromHex(t);
4015
- return $t(Gt(r, Ee), Gt(i, Ee));
4016
- }
4017
- function _a(t, e, r, i = "blake2", a) {
4018
- const o = G(e).subarray(0, 64), l = G(t), u = !Vt || zt() ? Us(l, o, r) : Ve.Signature.fromCompact(o).addRecoveryBit(r).recoverPublicKey(l).toRawBytes();
4019
- if (!u)
4020
- throw new Error("Unable to recover publicKey from signature");
4021
- return i === "keccak" ? qn(u) : qo(u);
4022
- }
4023
- function Ii(t, { secretKey: e }, r = "blake2", i) {
4024
- if ((e == null ? void 0 : e.length) !== 32)
4025
- throw new Error("Expected valid secp256k1 secretKey, 32-bytes");
4026
- const a = wn(r, t, i);
4027
- if (!Vt || zt())
4028
- return ks(a, e);
4029
- const o = Ve.sign(a, e, { lowS: !0 });
4030
- return $t(Gt(o.r, Ee), Gt(o.s, Ee), new Uint8Array([o.recovery || 0]));
4031
- }
4032
- const $o = "ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141".replace(/ /g, ""), Fr = F(`0x${$o}`), Qr = new X($o, "hex");
4033
- function Ma(t, e) {
4034
- let r = sn(e, fi);
4035
- if (r >= Fr)
4036
- throw new Error("Tweak parameter is out of range");
4037
- if (r += sn(t, fi), r >= Fr && (r -= Fr), r === rr)
4038
- throw new Error("Invalid resulting private key");
4039
- return af(r, Ee);
4040
- }
4041
- function Aa(t, e) {
4042
- const r = new X(e);
4043
- if (r.cmp(Qr) >= 0)
4044
- throw new Error("Tweak parameter is out of range");
4045
- if (r.iadd(new X(t)), r.cmp(Qr) >= 0 && r.isub(Qr), r.isZero())
4046
- throw new Error("Invalid resulting private key");
4047
- return Gt(r, Ee);
4048
- }
4049
- function Ba(t, e, r) {
4050
- if (!de(t) || t.length !== 32)
4051
- throw new Error("Expected seckey to be an Uint8Array with length 32");
4052
- if (!de(e) || e.length !== 32)
4053
- throw new Error("Expected tweak to be an Uint8Array with length 32");
4054
- return !Vt || r ? Aa(t, e) : Ma(t, e);
4055
- }
4056
- function Sa(t, e, r, i = "blake2", a) {
4057
- const o = G(e);
4058
- if (o.length !== 65)
4059
- throw new Error(`Expected signature with 65 bytes, ${o.length} found instead`);
4060
- const l = _a(wn(i, t), o, o[64], i), u = wn(i, l, a), m = G(r);
4061
- return jt(l, m) || (i === "keccak" ? jt(u.slice(-20), m.slice(-20)) : jt(u, m));
4062
- }
4063
- function Ia(t) {
4064
- return [33, 65].includes(t.length) && (t = pr(qn(t))), t.slice(-20);
4065
- }
4066
- function Co(t) {
4067
- if (!t)
4068
- return "0x";
4069
- const e = G(t);
4070
- if (![20, 32, 33, 65].includes(e.length))
4071
- throw new Error(`Invalid address or publicKey provided, received ${e.length} bytes input`);
4072
- const r = Re(Ia(e), -1, !1), i = Re(pr(r), -1, !1);
4073
- let a = "";
4074
- for (let o = 0; o < 40; o++)
4075
- a = `${a}${parseInt(i[o], 16) > 7 ? r[o].toUpperCase() : r[o]}`;
4076
- return `0x${a}`;
4077
- }
4078
- const Ua = {
4079
- 256: vn,
4080
- 512: Ds
4081
- }, ka = {
4082
- 256: Rs,
4083
- 512: Ns
4084
- };
4085
- function Do(t, e, r = 256, i) {
4086
- const a = G(t);
4087
- return !Vt || zt() ? ka[r](a, e) : Cs(Ua[r], a, e);
4088
- }
4089
- const $n = 2147483648;
4090
- function Na(t) {
4091
- if (!t.startsWith("m/"))
4092
- return !1;
4093
- const e = t.split("/").slice(1);
4094
- for (const r of e) {
4095
- const i = /^\d+'?$/.test(r) ? parseInt(r.replace(/'$/, ""), 10) : Number.NaN;
4096
- if (isNaN(i) || i >= $n || i < 0)
4097
- return !1;
4098
- }
4099
- return !0;
4100
- }
4101
- const Ra = ce("Bitcoin seed");
4102
- function Po(t, e) {
4103
- return {
4104
- chainCode: e,
4105
- publicKey: Be(t).publicKey,
4106
- secretKey: t
4107
- };
4108
- }
4109
- function Zo(t, e) {
4110
- const r = Gt(e, Tf), i = e >= $n ? $t(new Uint8Array(1), t.secretKey, r) : $t(t.publicKey, r);
4111
- try {
4112
- const a = Do(t.chainCode, i, 512);
4113
- return Po(Ba(t.secretKey, a.slice(0, 32)), a.slice(32));
4114
- } catch {
4115
- return Zo(t, e + 1);
4116
- }
4117
- }
4118
- function La(t, e = "") {
4119
- const r = Do(Ra, t, 512);
4120
- let i = Po(r.slice(0, 32), r.slice(32));
4121
- if (!e || e === "m" || e === "M" || e === "m'" || e === "M'")
4122
- return i;
4123
- if (!Na(e))
4124
- throw new Error("Invalid derivation path");
4125
- const a = e.split("/").slice(1);
4126
- for (const o of a)
4127
- i = Zo(i, parseInt(o, 10) + (o.length > 1 && o.endsWith("'") ? $n : 0));
4128
- return i;
4129
- }
4130
- function Oa(t, e, r) {
4131
- return !Vt || zt() ? Ls(t) : Ps(t, e);
4132
- }
4133
- function Vo(t, e, r) {
4134
- return !Vt || zt() ? Os(t) : Zs(t, e);
4135
- }
4136
- function Ta(t, e = "", r, i = 32) {
4137
- if (Vo(t)) {
4138
- if (![32, 64].includes(i))
4139
- throw new Error(`Invalid seed length ${i}, expected 32 or 64`);
4140
- } else throw new Error("Invalid bip39 mnemonic specified");
4141
- return i === 32 ? !Vt || zt() ? Ts(t, e) : ti(t, e).subarray(0, 32) : ti(t, e);
4142
- }
4143
- function Ha(t, e = "", r, i) {
4144
- if (Vo(t, r)) {
4145
- if (zt())
4146
- return Hs(t, e);
4147
- } else throw new Error("Invalid bip39 mnemonic specified");
4148
- const a = Oa(t, r), o = ce(`mnemonic${e}`);
4149
- return Vs(a, o).password.slice(0, 32);
4150
- }
4151
- function Ke(t, e) {
4152
- return t << e | t >>> 32 - e;
4153
- }
4154
- function ye(t, e) {
4155
- let r = t[e + 3] & 255;
4156
- return r = r << 8 | t[e + 2] & 255, r = r << 8 | t[e + 1] & 255, r << 8 | t[e + 0] & 255;
4157
- }
4158
- function tn(t, e, r) {
4159
- for (let i = 0; i < 4; i++)
4160
- t[e + i] = r & 255, r >>>= 8;
4161
- }
4162
- function qa(t, e, r, i, a) {
4163
- let o = 0;
4164
- for (let l = 0; l < a; l++)
4165
- o |= t[e + l] ^ r[i + l];
4166
- return (1 & o - 1 >>> 8) - 1;
4167
- }
4168
- function gn(t, e, r, i, a) {
4169
- const o = new Uint32Array(16), l = new Uint32Array(16), u = new Uint32Array(16), m = new Uint32Array(4);
4170
- let b, v, E;
4171
- for (b = 0; b < 4; b++)
4172
- l[5 * b] = ye(i, 4 * b), l[1 + b] = ye(r, 4 * b), l[6 + b] = ye(e, 4 * b), l[11 + b] = ye(r, 16 + 4 * b);
4173
- for (b = 0; b < 16; b++)
4174
- u[b] = l[b];
4175
- for (b = 0; b < 20; b++) {
4176
- for (v = 0; v < 4; v++) {
4177
- for (E = 0; E < 4; E++)
4178
- m[E] = l[(5 * v + 4 * E) % 16];
4179
- for (m[1] ^= Ke(m[0] + m[3] | 0, 7), m[2] ^= Ke(m[1] + m[0] | 0, 9), m[3] ^= Ke(m[2] + m[1] | 0, 13), m[0] ^= Ke(m[3] + m[2] | 0, 18), E = 0; E < 4; E++)
4180
- o[4 * v + (v + E) % 4] = m[E];
4181
- }
4182
- for (E = 0; E < 16; E++)
4183
- l[E] = o[E];
4184
- }
4185
- if (a) {
4186
- for (b = 0; b < 16; b++)
4187
- l[b] = l[b] + u[b] | 0;
4188
- for (b = 0; b < 4; b++)
4189
- l[5 * b] = l[5 * b] - ye(i, 4 * b) | 0, l[6 + b] = l[6 + b] - ye(e, 4 * b) | 0;
4190
- for (b = 0; b < 4; b++)
4191
- tn(t, 4 * b, l[5 * b]), tn(t, 16 + 4 * b, l[6 + b]);
4192
- } else
4193
- for (b = 0; b < 16; b++)
4194
- tn(t, 4 * b, l[b] + u[b] | 0);
4195
- }
4196
- const mn = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
4197
- function $a(t, e, r, i, a, o, l) {
4198
- const u = new Uint8Array(16), m = new Uint8Array(64);
4199
- let b, v;
4200
- if (!a)
4201
- return 0;
4202
- for (v = 0; v < 16; v++)
4203
- u[v] = 0;
4204
- for (v = 0; v < 8; v++)
4205
- u[v] = o[v];
4206
- for (; a >= 64; ) {
4207
- for (gn(m, u, l, mn, !1), v = 0; v < 64; v++)
4208
- t[e + v] = (r ? r[i + v] : 0) ^ m[v];
4209
- for (b = 1, v = 8; v < 16; v++)
4210
- b = b + (u[v] & 255) | 0, u[v] = b & 255, b >>>= 8;
4211
- a -= 64, e += 64, r && (i += 64);
4212
- }
4213
- if (a > 0)
4214
- for (gn(m, u, l, mn, !1), v = 0; v < a; v++)
4215
- t[e + v] = (r ? r[i + v] : 0) ^ m[v];
4216
- return 0;
4217
- }
4218
- function pn(t, e, r, i, a, o, l) {
4219
- const u = new Uint8Array(32);
4220
- return gn(u, o, l, mn, !0), $a(t, e, r, i, a, o.subarray(16), u);
4221
- }
4222
- function en(t, e) {
4223
- let r = 0;
4224
- for (let i = 0; i < 17; i++)
4225
- r = r + (t[i] + e[i] | 0) | 0, t[i] = r & 255, r >>>= 8;
4226
- }
4227
- const Ca = new Uint32Array([5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 252]);
4228
- function zo(t, e, r, i, a, o) {
4229
- let l, u, m;
4230
- const b = new Uint32Array(17), v = new Uint32Array(17), E = new Uint32Array(17), M = new Uint32Array(17), S = new Uint32Array(17);
4231
- for (u = 0; u < 17; u++)
4232
- v[u] = E[u] = 0;
4233
- for (u = 0; u < 16; u++)
4234
- v[u] = o[u];
4235
- for (v[3] &= 15, v[4] &= 252, v[7] &= 15, v[8] &= 252, v[11] &= 15, v[12] &= 252, v[15] &= 15; a > 0; ) {
4236
- for (u = 0; u < 17; u++)
4237
- M[u] = 0;
4238
- for (u = 0; u < 16 && u < a; ++u)
4239
- M[u] = r[i + u];
4240
- for (M[u] = 1, i += u, a -= u, en(E, M), l = 0; l < 17; l++)
4241
- for (b[l] = 0, u = 0; u < 17; u++)
4242
- b[l] = b[l] + E[u] * (u <= l ? v[l - u] : 320 * v[l + 17 - u] | 0) | 0 | 0;
4243
- for (l = 0; l < 17; l++)
4244
- E[l] = b[l];
4245
- for (m = 0, u = 0; u < 16; u++)
4246
- m = m + E[u] | 0, E[u] = m & 255, m >>>= 8;
4247
- for (m = m + E[16] | 0, E[16] = m & 3, m = 5 * (m >>> 2) | 0, u = 0; u < 16; u++)
4248
- m = m + E[u] | 0, E[u] = m & 255, m >>>= 8;
4249
- m = m + E[16] | 0, E[16] = m;
4250
- }
4251
- for (u = 0; u < 17; u++)
4252
- S[u] = E[u];
4253
- en(E, Ca);
4254
- const O = -(E[16] >>> 7) | 0;
4255
- for (u = 0; u < 17; u++)
4256
- E[u] ^= O & (S[u] ^ E[u]);
4257
- for (u = 0; u < 16; u++)
4258
- M[u] = o[u + 16];
4259
- for (M[16] = 0, en(E, M), u = 0; u < 16; u++)
4260
- t[e + u] = E[u];
4261
- return 0;
4262
- }
4263
- function Da(t, e, r, i, a, o) {
4264
- const l = new Uint8Array(16);
4265
- return zo(l, 0, r, i, a, o), qa(t, e, l, 0, 16);
4266
- }
4267
- function Pa(t, e, r, i, a) {
4268
- if (r < 32)
4269
- return -1;
4270
- pn(t, 0, e, 0, r, i, a), zo(t, 16, t, 32, r - 32, t);
4271
- for (let o = 0; o < 16; o++)
4272
- t[o] = 0;
4273
- return 0;
4274
- }
4275
- function Za(t, e, r, i, a) {
4276
- const o = new Uint8Array(32);
4277
- if (r < 32 || (pn(o, 0, null, 0, 32, i, a), Da(e, 16, e, 32, r - 32, o) !== 0))
4278
- return -1;
4279
- pn(t, 0, e, 0, r, i, a);
4280
- for (let l = 0; l < 32; l++)
4281
- t[l] = 0;
4282
- return 0;
4283
- }
4284
- const Va = 32, za = 24, yn = 32, xn = 16;
4285
- function Go(t, e) {
4286
- if (t.length !== Va)
4287
- throw new Error("bad key size");
4288
- if (e.length !== za)
4289
- throw new Error("bad nonce size");
4290
- }
4291
- function Yo(...t) {
4292
- for (let e = 0, r = t.length; e < r; e++)
4293
- if (!(t[e] instanceof Uint8Array))
4294
- throw new TypeError("unexpected type, use Uint8Array");
4295
- }
4296
- function Ga(t, e, r) {
4297
- Yo(t, e, r), Go(r, e);
4298
- const i = new Uint8Array(yn + t.length), a = new Uint8Array(i.length);
4299
- for (let o = 0; o < t.length; o++)
4300
- i[o + yn] = t[o];
4301
- return Pa(a, i, i.length, e, r), a.subarray(xn);
4302
- }
4303
- function Ya(t, e, r) {
4304
- Yo(t, e, r), Go(r, e);
4305
- const i = new Uint8Array(xn + t.length), a = new Uint8Array(i.length);
4306
- for (let o = 0; o < t.length; o++)
4307
- i[o + xn] = t[o];
4308
- return i.length < 32 || Za(a, i, i.length, e, r) !== 0 ? null : a.subarray(yn);
4309
- }
4310
- function Wa(t, e, r) {
4311
- return Ya(t, e, r);
4312
- }
4313
- function Xa(t, e, r = Ci(24)) {
4314
- return {
4315
- encrypted: Ga(t, r, e),
4316
- nonce: r
4317
- };
4318
- }
4319
- function Ui(t, e, r, i, a, o) {
4320
- let l = t[e++] ^ r[i++], u = t[e++] ^ r[i++], m = t[e++] ^ r[i++], b = t[e++] ^ r[i++], v = t[e++] ^ r[i++], E = t[e++] ^ r[i++], M = t[e++] ^ r[i++], S = t[e++] ^ r[i++], O = t[e++] ^ r[i++], A = t[e++] ^ r[i++], D = t[e++] ^ r[i++], V = t[e++] ^ r[i++], Q = t[e++] ^ r[i++], R = t[e++] ^ r[i++], _ = t[e++] ^ r[i++], B = t[e++] ^ r[i++], L = l, T = u, q = m, $ = b, C = v, U = E, H = M, y = S, n = O, f = A, c = D, g = V, d = Q, w = R, x = _, h = B;
4321
- for (let s = 0; s < 8; s += 2)
4322
- C ^= j(L + d | 0, 7), n ^= j(C + L | 0, 9), d ^= j(n + C | 0, 13), L ^= j(d + n | 0, 18), f ^= j(U + T | 0, 7), w ^= j(f + U | 0, 9), T ^= j(w + f | 0, 13), U ^= j(T + w | 0, 18), x ^= j(c + H | 0, 7), q ^= j(x + c | 0, 9), H ^= j(q + x | 0, 13), c ^= j(H + q | 0, 18), $ ^= j(h + g | 0, 7), y ^= j($ + h | 0, 9), g ^= j(y + $ | 0, 13), h ^= j(g + y | 0, 18), T ^= j(L + $ | 0, 7), q ^= j(T + L | 0, 9), $ ^= j(q + T | 0, 13), L ^= j($ + q | 0, 18), H ^= j(U + C | 0, 7), y ^= j(H + U | 0, 9), C ^= j(y + H | 0, 13), U ^= j(C + y | 0, 18), g ^= j(c + f | 0, 7), n ^= j(g + c | 0, 9), f ^= j(n + g | 0, 13), c ^= j(f + n | 0, 18), d ^= j(h + x | 0, 7), w ^= j(d + h | 0, 9), x ^= j(w + d | 0, 13), h ^= j(x + w | 0, 18);
4323
- a[o++] = l + L | 0, a[o++] = u + T | 0, a[o++] = m + q | 0, a[o++] = b + $ | 0, a[o++] = v + C | 0, a[o++] = E + U | 0, a[o++] = M + H | 0, a[o++] = S + y | 0, a[o++] = O + n | 0, a[o++] = A + f | 0, a[o++] = D + c | 0, a[o++] = V + g | 0, a[o++] = Q + d | 0, a[o++] = R + w | 0, a[o++] = _ + x | 0, a[o++] = B + h | 0;
4324
- }
4325
- function rn(t, e, r, i, a) {
4326
- let o = i + 0, l = i + 16 * a;
4327
- for (let u = 0; u < 16; u++)
4328
- r[l + u] = t[e + (2 * a - 1) * 16 + u];
4329
- for (let u = 0; u < a; u++, o += 16, e += 16)
4330
- Ui(r, l, t, e, r, o), u > 0 && (l += 16), Ui(r, o, t, e += 16, r, l);
4331
- }
4332
- function Ka(t, e, r) {
4333
- const i = os({
4334
- dkLen: 32,
4335
- asyncTick: 10,
4336
- maxmem: 1073742848
4337
- }, r), { N: a, r: o, p: l, dkLen: u, asyncTick: m, maxmem: b, onProgress: v } = i;
4338
- if (se(a), se(o), se(l), se(u), se(m), se(b), v !== void 0 && typeof v != "function")
4339
- throw new Error("progressCb should be function");
4340
- const E = 128 * o, M = E / 4;
4341
- if (a <= 1 || (a & a - 1) !== 0 || a > 2 ** 32)
4342
- throw new Error("Scrypt: N must be larger than 1, a power of 2, and less than 2^32");
4343
- if (l < 0 || l > (2 ** 32 - 1) * 32 / E)
4344
- throw new Error("Scrypt: p must be a positive integer less than or equal to ((2^32 - 1) * 32) / (128 * r)");
4345
- if (u < 0 || u > (2 ** 32 - 1) * 32)
4346
- throw new Error("Scrypt: dkLen should be positive integer less than or equal to (2^32 - 1) * 32");
4347
- const S = E * (a + l);
4348
- if (S > b)
4349
- throw new Error(`Scrypt: parameters too large, ${S} (128 * r * (N + p)) > ${b} (maxmem)`);
4350
- const O = $i(vn, t, e, { c: 1, dkLen: E * l }), A = Je(O), D = Je(new Uint8Array(E * a)), V = Je(new Uint8Array(E));
4351
- let Q = () => {
4352
- };
4353
- if (v) {
4354
- const R = 2 * a * l, _ = Math.max(Math.floor(R / 1e4), 1);
4355
- let B = 0;
4356
- Q = () => {
4357
- B++, v && (!(B % _) || B === R) && v(B / R);
4358
- };
4359
- }
4360
- return { N: a, r: o, p: l, dkLen: u, blockSize32: M, V: D, B32: A, B: O, tmp: V, blockMixCb: Q, asyncTick: m };
4361
- }
4362
- function ja(t, e, r, i, a) {
4363
- const o = $i(vn, t, r, { c: 1, dkLen: e });
4364
- return r.fill(0), i.fill(0), a.fill(0), o;
4365
- }
4366
- function Ja(t, e, r) {
4367
- const { N: i, r: a, p: o, dkLen: l, blockSize32: u, V: m, B32: b, B: v, tmp: E, blockMixCb: M } = Ka(t, e, r);
4368
- tr || er(b);
4369
- for (let S = 0; S < o; S++) {
4370
- const O = u * S;
4371
- for (let A = 0; A < u; A++)
4372
- m[A] = b[O + A];
4373
- for (let A = 0, D = 0; A < i - 1; A++)
4374
- rn(m, D, m, D += u, a), M();
4375
- rn(m, (i - 1) * u, b, O, a), M();
4376
- for (let A = 0; A < i; A++) {
4377
- const D = b[O + u - 16] % i;
4378
- for (let V = 0; V < u; V++)
4379
- E[V] = b[O + V] ^ m[D * u + V];
4380
- rn(E, 0, b, O, a), M();
4381
- }
4382
- }
4383
- return tr || er(b), ja(t, l, v, m, E);
4384
- }
4385
- const Qe = {
4386
- N: 32768,
4387
- p: 1,
4388
- r: 8
4389
- };
4390
- function Wo(t, e = Ci(), r = Qe, i) {
4391
- const a = G(t);
4392
- return {
4393
- params: r,
4394
- password: !Vt || zt() ? qs(a, e, Math.log2(r.N), r.r, r.p) : Ja(a, e, bn({ dkLen: 64 }, r)),
4395
- salt: e
4396
- };
4397
- }
4398
- function Fa(t) {
4399
- const e = t.subarray(0, 32), r = qr(t.subarray(32, 36), Dr).toNumber(), i = qr(t.subarray(36, 40), Dr).toNumber(), a = qr(t.subarray(40, 44), Dr).toNumber();
4400
- if (r !== Qe.N || i !== Qe.p || a !== Qe.r)
4401
- throw new Error("Invalid injected scrypt params found");
4402
- return { params: { N: r, p: i, r: a }, salt: e };
4403
- }
4404
- function Qa(t, { N: e, p: r, r: i }) {
4405
- return $t(t, Gt(e, Pr), Gt(r, Pr), Gt(i, Pr));
4406
- }
4407
- const Xo = ["scrypt", "xsalsa20-poly1305"], tc = ["none"], ec = "3", ki = 24, rc = 32 + 3 * 4;
4408
- function nc(t, e, r = Xo) {
4409
- if (t) {
4410
- if (r.includes("xsalsa20-poly1305") && !e)
4411
- throw new Error("Password required to decode encrypted data");
4412
- } else throw new Error("No encrypted data available to decode");
4413
- let i = t;
4414
- if (e) {
4415
- let a;
4416
- if (r.includes("scrypt")) {
4417
- const { params: o, salt: l } = Fa(t);
4418
- a = Wo(e, l, o).password, t = t.subarray(rc);
4419
- } else
4420
- a = ce(e);
4421
- i = Wa(t.subarray(ki), t.subarray(0, ki), ef(a, 256, !0));
4422
- }
4423
- if (!i)
4424
- throw new Error("Unable to decode using the supplied passphrase");
4425
- return i;
4426
- }
4427
- function ic(t, e, r) {
4428
- return {
4429
- encoded: Ea(t),
4430
- encoding: {
4431
- content: e,
4432
- type: r ? Xo : tc,
4433
- version: ec
4434
- }
4435
- };
4436
- }
4437
- const Ni = (t) => (e, r, i) => Sa(e, r, i, t), Ko = [
4438
- ["ecdsa", Ni("blake2")],
4439
- ["ethereum", Ni("keccak")]
4440
- ], oc = [
4441
- ["ed25519", So],
4442
- ["sr25519", Ro],
4443
- ...Ko
4444
- ], sc = ["ed25519", "sr25519", "ecdsa"];
4445
- function jo(t, { message: e, publicKey: r, signature: i }, a = oc) {
4446
- return t.isValid = a.some(([o, l]) => {
4447
- try {
4448
- if (l(e, i, r))
4449
- return t.crypto = o, !0;
4450
- } catch {
4451
- }
4452
- return !1;
4453
- }), t;
4454
- }
4455
- function fc(t, { message: e, publicKey: r, signature: i }) {
4456
- if (![0, 1, 2].includes(i[0]))
4457
- throw new Error(`Unknown crypto type, expected signature prefix [0..2], found ${i[0]}`);
4458
- const a = sc[i[0]] || "none";
4459
- t.crypto = a;
4460
- try {
4461
- t.isValid = {
4462
- ecdsa: () => jo(t, { message: e, publicKey: r, signature: i.subarray(1) }, Ko).isValid,
4463
- ed25519: () => So(e, i.subarray(1), r),
4464
- none: () => {
4465
- throw Error("no verify for `none` crypto type");
4466
- },
4467
- sr25519: () => Ro(e, i.subarray(1), r)
4468
- }[a]();
4469
- } catch {
4470
- }
4471
- return t;
4472
- }
4473
- function ac(t) {
4474
- return [0, 1, 2].includes(t[0]) && [65, 66].includes(t.length) ? fc : jo;
4475
- }
4476
- function Ri(t, e, r) {
4477
- const i = G(e);
4478
- if (![64, 65, 66].includes(i.length))
4479
- throw new Error(`Invalid signature length, expected [64..66] bytes, found ${i.length}`);
4480
- const a = be(r), o = { message: G(t), publicKey: a, signature: i }, l = { crypto: "none", isValid: !1, isWrapped: ir(o.message, !0), publicKey: a }, u = ir(o.message, !1), m = ac(i);
4481
- return m(l, o), l.crypto !== "none" || l.isWrapped && !u ? l : (o.message = u ? nf(o.message) : of(o.message), m(l, o));
4482
- }
4483
- const cc = [zs, vf], hc = { name: "@polkadot/keyring", path: import.meta && import.meta.url ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf("/") + 1) : "auto", type: "esm", version: "12.6.2" };
4484
- Xs(hc, null, cc);
4485
- const xe = new Uint8Array([161, 35, 3, 33, 0]), ur = new Uint8Array([48, 83, 2, 1, 1, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32]), lc = 32, Li = 64, uc = 32, Ie = ur.length;
4486
- function dc(t, e, r) {
4487
- const i = Array.isArray(r) || r === void 0 ? r : [r], a = nc(e, t, i), o = a.subarray(0, ur.length);
4488
- if (!jt(o, ur))
4489
- throw new Error("Invalid Pkcs8 header found in body");
4490
- let l = a.subarray(Ie, Ie + Li), u = Ie + Li, m = a.subarray(u, u + xe.length);
4491
- if (!jt(m, xe) && (u = Ie + uc, l = a.subarray(Ie, u), m = a.subarray(u, u + xe.length), !jt(m, xe)))
4492
- throw new Error("Invalid Pkcs8 divider found in body");
4493
- const b = u + xe.length;
4494
- return {
4495
- publicKey: a.subarray(b, b + lc),
4496
- secretKey: l
4497
- };
4498
- }
4499
- function wc({ publicKey: t, secretKey: e }, r) {
4500
- if (!e)
4501
- throw new Error("Expected a valid secretKey to be passed to encode");
4502
- const i = $t(ur, e, xe, t);
4503
- if (!r)
4504
- return i;
4505
- const { params: a, password: o, salt: l } = Wo(r), { encrypted: u, nonce: m } = Xa(i, o.subarray(0, 32));
4506
- return $t(Qa(l, a), m, u);
4507
- }
4508
- function gc(t, { address: e, meta: r }, i, a) {
4509
- return bn(ic(i, ["pkcs8", t], a), {
4510
- address: e,
4511
- meta: r
4512
- });
4513
- }
4514
- const mc = new Uint8Array(), pc = {
4515
- ecdsa: Be,
4516
- ed25519: Tn,
4517
- ethereum: Be,
4518
- sr25519: No
4519
- }, Oi = {
4520
- ecdsa: new Uint8Array([2]),
4521
- ed25519: new Uint8Array([0]),
4522
- ethereum: new Uint8Array([2]),
4523
- sr25519: new Uint8Array([1])
4524
- }, Ti = {
4525
- ecdsa: (t, e) => Ii(t, e, "blake2"),
4526
- ed25519: F0,
4527
- ethereum: (t, e) => Ii(t, e, "keccak"),
4528
- sr25519: sa
4529
- }, je = {
4530
- ecdsa: (t) => t.length > 32 ? we(t) : t,
4531
- ed25519: (t) => t,
4532
- ethereum: (t) => t.length === 20 ? t : pr(qn(t)),
4533
- sr25519: (t) => t
4534
- };
4535
- function Ue(t) {
4536
- return !t || zi(t);
4537
- }
4538
- function Hi(t, e, r) {
4539
- return we($t(e || "", r || "", t));
4540
- }
4541
- function ve({ toSS58: t, type: e }, { publicKey: r, secretKey: i }, a = {}, o = null, l) {
4542
- const u = (v, E) => {
4543
- const M = dc(v, E || o, l);
4544
- if (M.secretKey.length === 64)
4545
- r = M.publicKey, i = M.secretKey;
4546
- else {
4547
- const S = pc[e](M.secretKey);
4548
- r = S.publicKey, i = S.secretKey;
4549
- }
4550
- }, m = (v) => (Ue(i) && o && u(v, o), o = wc({ publicKey: r, secretKey: i }, v), l = void 0, o), b = () => {
4551
- const v = je[e](r);
4552
- return e === "ethereum" ? Co(v) : t(v);
4553
- };
4554
- return {
4555
- get address() {
4556
- return b();
4557
- },
4558
- get addressRaw() {
4559
- const v = je[e](r);
4560
- return e === "ethereum" ? v.slice(-20) : v;
4561
- },
4562
- get isLocked() {
4563
- return Ue(i);
4564
- },
4565
- get meta() {
4566
- return a;
4567
- },
4568
- get publicKey() {
4569
- return r;
4570
- },
4571
- get type() {
4572
- return e;
4573
- },
4574
- // eslint-disable-next-line sort-keys
4575
- decodePkcs8: u,
4576
- derive: (v, E) => {
4577
- if (e === "ethereum")
4578
- throw new Error("Unable to derive on this keypair");
4579
- if (Ue(i))
4580
- throw new Error("Cannot derive on a locked keypair");
4581
- const { path: M } = no(v), S = ko({ publicKey: r, secretKey: i }, M, e);
4582
- return ve({ toSS58: t, type: e }, S, E, null);
4583
- },
4584
- encodePkcs8: (v) => m(v),
4585
- lock: () => {
4586
- i = new Uint8Array();
4587
- },
4588
- setMeta: (v) => {
4589
- a = bn({}, a, v);
4590
- },
4591
- sign: (v, E = {}) => {
4592
- if (Ue(i))
4593
- throw new Error("Cannot sign with a locked key pair");
4594
- return $t(E.withType ? Oi[e] : mc, Ti[e](G(v), { publicKey: r, secretKey: i }));
4595
- },
4596
- toJson: (v) => {
4597
- const E = ["ecdsa", "ethereum"].includes(e) ? r.length === 20 ? Re(r) : Re(qo(r)) : b();
4598
- return gc(e, { address: E, meta: a }, m(v), !!v);
4599
- },
4600
- unlock: (v) => u(v),
4601
- verify: (v, E, M) => Ri(v, E, je[e](G(M))).isValid,
4602
- vrfSign: (v, E, M) => {
4603
- if (Ue(i))
4604
- throw new Error("Cannot sign with a locked key pair");
4605
- if (e === "sr25519")
4606
- return fa(v, { secretKey: i }, E, M);
4607
- const S = Ti[e](G(v), { publicKey: r, secretKey: i });
4608
- return $t(Hi(S, E, M), S);
4609
- },
4610
- vrfVerify: (v, E, M, S, O) => e === "sr25519" ? aa(v, E, r, S, O) : Ri(v, $t(Oi[e], E.subarray(32)), je[e](G(M))).isValid && jt(E.subarray(0, 32), Hi(E.subarray(32), S, O))
4611
- };
4612
- }
4613
- const yc = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
4614
- class xc {
4615
- constructor() {
4616
- Jt(this, "__internal__map", {});
4617
- }
4618
- add(e) {
4619
- return this.__internal__map[be(e.address).toString()] = e, e;
4620
- }
4621
- all() {
4622
- return Object.values(this.__internal__map);
4623
- }
4624
- get(e) {
4625
- const r = this.__internal__map[be(e).toString()];
4626
- if (!r)
4627
- throw new Error(`Unable to retrieve keypair '${de(e) || fe(e) ? Re(G(e)) : e}'`);
4628
- return r;
4629
- }
4630
- remove(e) {
4631
- delete this.__internal__map[be(e).toString()];
4632
- }
4633
- }
4634
- const nn = {
4635
- ecdsa: (t) => Be(t),
4636
- ed25519: (t) => Tn(t),
4637
- ethereum: (t) => Be(t),
4638
- sr25519: (t) => No(t)
4639
- };
4640
- function vc({ publicKey: t }) {
4641
- return t;
4642
- }
4643
- class Tc {
4644
- constructor(e = {}) {
4645
- Jt(this, "__internal__pairs");
4646
- Jt(this, "__internal__type");
4647
- Jt(this, "__internal__ss58");
4648
- Jt(this, "decodeAddress", be);
4649
- /**
4650
- * @name encodeAddress
4651
- * @description Encodes the input into an ss58 representation
4652
- */
4653
- Jt(this, "encodeAddress", (e, r) => this.type === "ethereum" ? Co(e) : ca(e, r ?? this.__internal__ss58));
4654
- if (e.type = e.type || "ed25519", !["ecdsa", "ethereum", "ed25519", "sr25519"].includes(e.type || "undefined"))
4655
- throw new Error(`Expected a keyring type of either 'ed25519', 'sr25519', 'ethereum' or 'ecdsa', found '${e.type || "unknown"}`);
4656
- this.__internal__pairs = new xc(), this.__internal__ss58 = e.ss58Format, this.__internal__type = e.type;
4657
- }
4658
- /**
4659
- * @description retrieve the pairs (alias for getPairs)
4660
- */
4661
- get pairs() {
4662
- return this.getPairs();
4663
- }
4664
- /**
4665
- * @description retrieve the publicKeys (alias for getPublicKeys)
4666
- */
4667
- get publicKeys() {
4668
- return this.getPublicKeys();
4669
- }
4670
- /**
4671
- * @description Returns the type of the keyring, ed25519, sr25519 or ecdsa
4672
- */
4673
- get type() {
4674
- return this.__internal__type;
4675
- }
4676
- /**
4677
- * @name addPair
4678
- * @summary Stores an account, given a keyring pair, as a Key/Value (public key, pair) in Keyring Pair Dictionary
4679
- */
4680
- addPair(e) {
4681
- return this.__internal__pairs.add(e);
4682
- }
4683
- /**
4684
- * @name addFromAddress
4685
- * @summary Stores an account, given an account address, as a Key/Value (public key, pair) in Keyring Pair Dictionary
4686
- * @description Allows user to explicitly provide separate inputs including account address or public key, and optionally
4687
- * the associated account metadata, and the default encoded value as arguments (that may be obtained from the json file
4688
- * of an account backup), and then generates a keyring pair from them that it passes to
4689
- * `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
4690
- */
4691
- addFromAddress(e, r = {}, i = null, a = this.type, o, l) {
4692
- const u = this.decodeAddress(e, o);
4693
- return this.addPair(ve({ toSS58: this.encodeAddress, type: a }, { publicKey: u, secretKey: new Uint8Array() }, r, i, l));
4694
- }
4695
- /**
4696
- * @name addFromJson
4697
- * @summary Stores an account, given JSON data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
4698
- * @description Allows user to provide a json object argument that contains account information (that may be obtained from the json file
4699
- * of an account backup), and then generates a keyring pair from it that it passes to
4700
- * `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
4701
- */
4702
- addFromJson(e, r) {
4703
- return this.addPair(this.createFromJson(e, r));
4704
- }
4705
- /**
4706
- * @name addFromMnemonic
4707
- * @summary Stores an account, given a mnemonic, as a Key/Value (public key, pair) in Keyring Pair Dictionary
4708
- * @description Allows user to provide a mnemonic (seed phrase that is provided when account is originally created)
4709
- * argument and a metadata argument that contains account information (that may be obtained from the json file
4710
- * of an account backup), and then generates a keyring pair from it that it passes to
4711
- * `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
4712
- */
4713
- addFromMnemonic(e, r = {}, i = this.type) {
4714
- return this.addFromUri(e, r, i);
4715
- }
4716
- /**
4717
- * @name addFromPair
4718
- * @summary Stores an account created from an explicit publicKey/secreteKey combination
4719
- */
4720
- addFromPair(e, r = {}, i = this.type) {
4721
- return this.addPair(this.createFromPair(e, r, i));
4722
- }
4723
- /**
4724
- * @name addFromSeed
4725
- * @summary Stores an account, given seed data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
4726
- * @description Stores in a keyring pair dictionary the public key of the pair as a key and the pair as the associated value.
4727
- * Allows user to provide the account seed as an argument, and then generates a keyring pair from it that it passes to
4728
- * `addPair` to store in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
4729
- */
4730
- addFromSeed(e, r = {}, i = this.type) {
4731
- return this.addPair(ve({ toSS58: this.encodeAddress, type: i }, nn[i](e), r, null));
4732
- }
4733
- /**
4734
- * @name addFromUri
4735
- * @summary Creates an account via an suri
4736
- * @description Extracts the phrase, path and password from a SURI format for specifying secret keys `<secret>/<soft-key>//<hard-key>///<password>` (the `///password` may be omitted, and `/<soft-key>` and `//<hard-key>` maybe repeated and mixed). The secret can be a hex string, mnemonic phrase or a string (to be padded)
4737
- */
4738
- addFromUri(e, r = {}, i = this.type) {
4739
- return this.addPair(this.createFromUri(e, r, i));
4740
- }
4741
- /**
4742
- * @name createFromJson
4743
- * @description Creates a pair from a JSON keyfile
4744
- */
4745
- createFromJson({ address: e, encoded: r, encoding: { content: i, type: a, version: o }, meta: l }, u) {
4746
- if (o === "3" && i[0] !== "pkcs8")
4747
- throw new Error(`Unable to decode non-pkcs8 type, [${i.join(",")}] found}`);
4748
- const m = o === "0" || !Array.isArray(i) ? this.type : i[1], b = Array.isArray(a) ? a : [a];
4749
- if (!["ed25519", "sr25519", "ecdsa", "ethereum"].includes(m))
4750
- throw new Error(`Unknown crypto type ${m}`);
4751
- const v = fe(e) ? ke(e) : this.decodeAddress(e, u), E = fe(r) ? ke(r) : ba(r);
4752
- return ve({ toSS58: this.encodeAddress, type: m }, { publicKey: v, secretKey: new Uint8Array() }, l, E, b);
4753
- }
4754
- /**
4755
- * @name createFromPair
4756
- * @summary Creates a pair from an explicit publicKey/secreteKey combination
4757
- */
4758
- createFromPair(e, r = {}, i = this.type) {
4759
- return ve({ toSS58: this.encodeAddress, type: i }, e, r, null);
4760
- }
4761
- /**
4762
- * @name createFromUri
4763
- * @summary Creates a Keypair from an suri
4764
- * @description This creates a pair from the suri, but does not add it to the keyring
4765
- */
4766
- createFromUri(e, r = {}, i = this.type) {
4767
- const a = e.startsWith("//") ? `${yc}${e}` : e, { derivePath: o, password: l, path: u, phrase: m } = Pf(a);
4768
- let b;
4769
- const v = fe(m, 256);
4770
- if (v)
4771
- b = ke(m);
4772
- else {
4773
- const M = m.split(" ");
4774
- if ([12, 15, 18, 21, 24].includes(M.length))
4775
- b = i === "ethereum" ? Ta(m, "", !1, 64) : Ha(m, l);
4776
- else {
4777
- if (m.length > 32)
4778
- throw new Error("specified phrase is not a valid mnemonic and is invalid as a raw seed at > 32 bytes");
4779
- b = ce(m.padEnd(32));
4780
- }
4781
- }
4782
- const E = i === "ethereum" ? v ? nn[i](b) : La(b, o.substring(1)) : ko(nn[i](b), u, i);
4783
- return ve({ toSS58: this.encodeAddress, type: i }, E, r, null);
4784
- }
4785
- /**
4786
- * @name getPair
4787
- * @summary Retrieves an account keyring pair from the Keyring Pair Dictionary, given an account address
4788
- * @description Returns a keyring pair value from the keyring pair dictionary by performing
4789
- * a key lookup using the provided account address or public key (after decoding it).
4790
- */
4791
- getPair(e) {
4792
- return this.__internal__pairs.get(e);
4793
- }
4794
- /**
4795
- * @name getPairs
4796
- * @summary Retrieves all account keyring pairs from the Keyring Pair Dictionary
4797
- * @description Returns an array list of all the keyring pair values that are stored in the keyring pair dictionary.
4798
- */
4799
- getPairs() {
4800
- return this.__internal__pairs.all();
4801
- }
4802
- /**
4803
- * @name getPublicKeys
4804
- * @summary Retrieves Public Keys of all Keyring Pairs stored in the Keyring Pair Dictionary
4805
- * @description Returns an array list of all the public keys associated with each of the keyring pair values that are stored in the keyring pair dictionary.
4806
- */
4807
- getPublicKeys() {
4808
- return this.__internal__pairs.all().map(vc);
4809
- }
4810
- /**
4811
- * @name removePair
4812
- * @description Deletes the provided input address or public key from the stored Keyring Pair Dictionary.
4813
- */
4814
- removePair(e) {
4815
- this.__internal__pairs.remove(e);
4816
- }
4817
- /**
4818
- * @name setSS58Format;
4819
- * @description Sets the ss58 format for the keyring
4820
- */
4821
- setSS58Format(e) {
4822
- this.__internal__ss58 = e;
4823
- }
4824
- /**
4825
- * @name toJson
4826
- * @summary Returns a JSON object associated with the input argument that contains metadata assocated with an account
4827
- * @description Returns a JSON object containing the metadata associated with an account
4828
- * when valid address or public key and when the account passphrase is provided if the account secret
4829
- * is not already unlocked and available in memory. Note that in [Polkadot-JS Apps](https://github.com/polkadot-js/apps) the user
4830
- * may backup their account to a JSON file that contains this information.
4831
- */
4832
- toJson(e, r) {
4833
- return this.__internal__pairs.get(e).toJson(r);
4834
- }
4835
- }
4836
- export {
4837
- yc as DEV_PHRASE,
4838
- Tc as Keyring,
4839
- ve as createPair,
4840
- be as decodeAddress,
4841
- Tc as default,
4842
- ca as encodeAddress,
4843
- hc as packageInfo
4844
- };