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