@danidoble/webserial
Version:
WebSerial API wrapper
1,282 lines • 207 kB
JavaScript
import { K as Ye, a as ti, i as K, b as Zt, w as Yt } from "./kernel-Dk_J4ThU.js";
import { h as te } from "./webserial-core-BjytHor1.js";
var ei = "0123456789abcdefghijklmnopqrstuvwxyz";
function H(n) {
return ei.charAt(n);
}
function ii(n, t) {
return n & t;
}
function pt(n, t) {
return n | t;
}
function ee(n, t) {
return n ^ t;
}
function ie(n, t) {
return n & ~t;
}
function ni(n) {
if (n == 0)
return -1;
var t = 0;
return (n & 65535) == 0 && (n >>= 16, t += 16), (n & 255) == 0 && (n >>= 8, t += 8), (n & 15) == 0 && (n >>= 4, t += 4), (n & 3) == 0 && (n >>= 2, t += 2), (n & 1) == 0 && ++t, t;
}
function ri(n) {
for (var t = 0; n != 0; )
n &= n - 1, ++t;
return t;
}
var tt = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", Se = "=";
function Et(n) {
var t, e, i = "";
for (t = 0; t + 3 <= n.length; t += 3)
e = parseInt(n.substring(t, t + 3), 16), i += tt.charAt(e >> 6) + tt.charAt(e & 63);
for (t + 1 == n.length ? (e = parseInt(n.substring(t, t + 1), 16), i += tt.charAt(e << 2)) : t + 2 == n.length && (e = parseInt(n.substring(t, t + 2), 16), i += tt.charAt(e >> 2) + tt.charAt((e & 3) << 4)); (i.length & 3) > 0; )
i += Se;
return i;
}
function ne(n) {
var t = "", e, i = 0, r = 0;
for (e = 0; e < n.length && n.charAt(e) != Se; ++e) {
var s = tt.indexOf(n.charAt(e));
s < 0 || (i == 0 ? (t += H(s >> 2), r = s & 3, i = 1) : i == 1 ? (t += H(r << 2 | s >> 4), r = s & 15, i = 2) : i == 2 ? (t += H(r), t += H(s >> 2), r = s & 3, i = 3) : (t += H(r << 2 | s >> 4), t += H(s & 15), i = 0));
}
return i == 1 && (t += H(r << 2)), t;
}
var Z, si = {
decode: function(n) {
var t;
if (Z === void 0) {
var e = "0123456789ABCDEF", i = ` \f
\r \u2028\u2029`;
for (Z = {}, t = 0; t < 16; ++t)
Z[e.charAt(t)] = t;
for (e = e.toLowerCase(), t = 10; t < 16; ++t)
Z[e.charAt(t)] = t;
for (t = 0; t < i.length; ++t)
Z[i.charAt(t)] = -1;
}
var r = [], s = 0, a = 0;
for (t = 0; t < n.length; ++t) {
var o = n.charAt(t);
if (o == "=")
break;
if (o = Z[o], o != -1) {
if (o === void 0)
throw new Error("Illegal character at offset " + t);
s |= o, ++a >= 2 ? (r[r.length] = s, s = 0, a = 0) : s <<= 4;
}
}
if (a)
throw new Error("Hex encoding incomplete: 4 bits missing");
return r;
}
}, G, Ft = {
decode: function(n) {
var t;
if (G === void 0) {
var e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", i = `= \f
\r \u2028\u2029`;
for (G = /* @__PURE__ */ Object.create(null), t = 0; t < 64; ++t)
G[e.charAt(t)] = t;
for (G["-"] = 62, G._ = 63, t = 0; t < i.length; ++t)
G[i.charAt(t)] = -1;
}
var r = [], s = 0, a = 0;
for (t = 0; t < n.length; ++t) {
var o = n.charAt(t);
if (o == "=")
break;
if (o = G[o], o != -1) {
if (o === void 0)
throw new Error("Illegal character at offset " + t);
s |= o, ++a >= 4 ? (r[r.length] = s >> 16, r[r.length] = s >> 8 & 255, r[r.length] = s & 255, s = 0, a = 0) : s <<= 6;
}
}
switch (a) {
case 1:
throw new Error("Base64 encoding incomplete: at least 2 bits missing");
case 2:
r[r.length] = s >> 10;
break;
case 3:
r[r.length] = s >> 16, r[r.length] = s >> 8 & 255;
break;
}
return r;
},
re: /-----BEGIN [^-]+-----([A-Za-z0-9+\/=\s]+)-----END [^-]+-----|begin-base64[^\n]+\n([A-Za-z0-9+\/=\s]+)====/,
unarmor: function(n) {
var t = Ft.re.exec(n);
if (t)
if (t[1])
n = t[1];
else if (t[2])
n = t[2];
else
throw new Error("RegExp out of sync");
return Ft.decode(n);
}
}, Y = 1e13, at = (
/** @class */
function() {
function n(t) {
this.buf = [+t || 0];
}
return n.prototype.mulAdd = function(t, e) {
var i = this.buf, r = i.length, s, a;
for (s = 0; s < r; ++s)
a = i[s] * t + e, a < Y ? e = 0 : (e = 0 | a / Y, a -= e * Y), i[s] = a;
e > 0 && (i[s] = e);
}, n.prototype.sub = function(t) {
var e = this.buf, i = e.length, r, s;
for (r = 0; r < i; ++r)
s = e[r] - t, s < 0 ? (s += Y, t = 1) : t = 0, e[r] = s;
for (; e[e.length - 1] === 0; )
e.pop();
}, n.prototype.toString = function(t) {
if ((t || 10) != 10)
throw new Error("only base 10 is supported");
for (var e = this.buf, i = e[e.length - 1].toString(), r = e.length - 2; r >= 0; --r)
i += (Y + e[r]).toString().substring(1);
return i;
}, n.prototype.valueOf = function() {
for (var t = this.buf, e = 0, i = t.length - 1; i >= 0; --i)
e = e * Y + t[i];
return e;
}, n.prototype.simplify = function() {
var t = this.buf;
return t.length == 1 ? t[0] : this;
}, n;
}()
), Te = "…", ai = /^(\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/, oi = /^(\d\d\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;
function et(n, t) {
return n.length > t && (n = n.substring(0, t) + Te), n;
}
var Nt = (
/** @class */
function() {
function n(t, e) {
this.hexDigits = "0123456789ABCDEF", t instanceof n ? (this.enc = t.enc, this.pos = t.pos) : (this.enc = t, this.pos = e);
}
return n.prototype.get = function(t) {
if (t === void 0 && (t = this.pos++), t >= this.enc.length)
throw new Error("Requesting byte offset ".concat(t, " on a stream of length ").concat(this.enc.length));
return typeof this.enc == "string" ? this.enc.charCodeAt(t) : this.enc[t];
}, n.prototype.hexByte = function(t) {
return this.hexDigits.charAt(t >> 4 & 15) + this.hexDigits.charAt(t & 15);
}, n.prototype.hexDump = function(t, e, i) {
for (var r = "", s = t; s < e; ++s)
if (r += this.hexByte(this.get(s)), i !== !0)
switch (s & 15) {
case 7:
r += " ";
break;
case 15:
r += `
`;
break;
default:
r += " ";
}
return r;
}, n.prototype.isASCII = function(t, e) {
for (var i = t; i < e; ++i) {
var r = this.get(i);
if (r < 32 || r > 176)
return !1;
}
return !0;
}, n.prototype.parseStringISO = function(t, e) {
for (var i = "", r = t; r < e; ++r)
i += String.fromCharCode(this.get(r));
return i;
}, n.prototype.parseStringUTF = function(t, e) {
for (var i = "", r = t; r < e; ) {
var s = this.get(r++);
s < 128 ? i += String.fromCharCode(s) : s > 191 && s < 224 ? i += String.fromCharCode((s & 31) << 6 | this.get(r++) & 63) : i += String.fromCharCode((s & 15) << 12 | (this.get(r++) & 63) << 6 | this.get(r++) & 63);
}
return i;
}, n.prototype.parseStringBMP = function(t, e) {
for (var i = "", r, s, a = t; a < e; )
r = this.get(a++), s = this.get(a++), i += String.fromCharCode(r << 8 | s);
return i;
}, n.prototype.parseTime = function(t, e, i) {
var r = this.parseStringISO(t, e), s = (i ? ai : oi).exec(r);
return s ? (i && (s[1] = +s[1], s[1] += +s[1] < 70 ? 2e3 : 1900), r = s[1] + "-" + s[2] + "-" + s[3] + " " + s[4], s[5] && (r += ":" + s[5], s[6] && (r += ":" + s[6], s[7] && (r += "." + s[7]))), s[8] && (r += " UTC", s[8] != "Z" && (r += s[8], s[9] && (r += ":" + s[9]))), r) : "Unrecognized time: " + r;
}, n.prototype.parseInteger = function(t, e) {
for (var i = this.get(t), r = i > 127, s = r ? 255 : 0, a, o = ""; i == s && ++t < e; )
i = this.get(t);
if (a = e - t, a === 0)
return r ? -1 : 0;
if (a > 4) {
for (o = i, a <<= 3; ((+o ^ s) & 128) == 0; )
o = +o << 1, --a;
o = "(" + a + ` bit)
`;
}
r && (i = i - 256);
for (var c = new at(i), h = t + 1; h < e; ++h)
c.mulAdd(256, this.get(h));
return o + c.toString();
}, n.prototype.parseBitString = function(t, e, i) {
for (var r = this.get(t), s = (e - t - 1 << 3) - r, a = "(" + s + ` bit)
`, o = "", c = t + 1; c < e; ++c) {
for (var h = this.get(c), u = c == e - 1 ? r : 0, f = 7; f >= u; --f)
o += h >> f & 1 ? "1" : "0";
if (o.length > i)
return a + et(o, i);
}
return a + o;
}, n.prototype.parseOctetString = function(t, e, i) {
if (this.isASCII(t, e))
return et(this.parseStringISO(t, e), i);
var r = e - t, s = "(" + r + ` byte)
`;
i /= 2, r > i && (e = t + i);
for (var a = t; a < e; ++a)
s += this.hexByte(this.get(a));
return r > i && (s += Te), s;
}, n.prototype.parseOID = function(t, e, i) {
for (var r = "", s = new at(), a = 0, o = t; o < e; ++o) {
var c = this.get(o);
if (s.mulAdd(128, c & 127), a += 7, !(c & 128)) {
if (r === "")
if (s = s.simplify(), s instanceof at)
s.sub(80), r = "2." + s.toString();
else {
var h = s < 80 ? s < 40 ? 0 : 1 : 2;
r = h + "." + (s - h * 40);
}
else
r += "." + s.toString();
if (r.length > i)
return et(r, i);
s = new at(), a = 0;
}
}
return a > 0 && (r += ".incomplete"), r;
}, n;
}()
), ci = (
/** @class */
function() {
function n(t, e, i, r, s) {
if (!(r instanceof re))
throw new Error("Invalid tag value.");
this.stream = t, this.header = e, this.length = i, this.tag = r, this.sub = s;
}
return n.prototype.typeName = function() {
switch (this.tag.tagClass) {
case 0:
switch (this.tag.tagNumber) {
case 0:
return "EOC";
case 1:
return "BOOLEAN";
case 2:
return "INTEGER";
case 3:
return "BIT_STRING";
case 4:
return "OCTET_STRING";
case 5:
return "NULL";
case 6:
return "OBJECT_IDENTIFIER";
case 7:
return "ObjectDescriptor";
case 8:
return "EXTERNAL";
case 9:
return "REAL";
case 10:
return "ENUMERATED";
case 11:
return "EMBEDDED_PDV";
case 12:
return "UTF8String";
case 16:
return "SEQUENCE";
case 17:
return "SET";
case 18:
return "NumericString";
case 19:
return "PrintableString";
// ASCII subset
case 20:
return "TeletexString";
// aka T61String
case 21:
return "VideotexString";
case 22:
return "IA5String";
// ASCII
case 23:
return "UTCTime";
case 24:
return "GeneralizedTime";
case 25:
return "GraphicString";
case 26:
return "VisibleString";
// ASCII subset
case 27:
return "GeneralString";
case 28:
return "UniversalString";
case 30:
return "BMPString";
}
return "Universal_" + this.tag.tagNumber.toString();
case 1:
return "Application_" + this.tag.tagNumber.toString();
case 2:
return "[" + this.tag.tagNumber.toString() + "]";
// Context
case 3:
return "Private_" + this.tag.tagNumber.toString();
}
}, n.prototype.content = function(t) {
if (this.tag === void 0)
return null;
t === void 0 && (t = 1 / 0);
var e = this.posContent(), i = Math.abs(this.length);
if (!this.tag.isUniversal())
return this.sub !== null ? "(" + this.sub.length + " elem)" : this.stream.parseOctetString(e, e + i, t);
switch (this.tag.tagNumber) {
case 1:
return this.stream.get(e) === 0 ? "false" : "true";
case 2:
return this.stream.parseInteger(e, e + i);
case 3:
return this.sub ? "(" + this.sub.length + " elem)" : this.stream.parseBitString(e, e + i, t);
case 4:
return this.sub ? "(" + this.sub.length + " elem)" : this.stream.parseOctetString(e, e + i, t);
// case 0x05: // NULL
case 6:
return this.stream.parseOID(e, e + i, t);
// case 0x07: // ObjectDescriptor
// case 0x08: // EXTERNAL
// case 0x09: // REAL
// case 0x0A: // ENUMERATED
// case 0x0B: // EMBEDDED_PDV
case 16:
// SEQUENCE
case 17:
return this.sub !== null ? "(" + this.sub.length + " elem)" : "(no elem)";
case 12:
return et(this.stream.parseStringUTF(e, e + i), t);
case 18:
// NumericString
case 19:
// PrintableString
case 20:
// TeletexString
case 21:
// VideotexString
case 22:
// IA5String
// case 0x19: // GraphicString
case 26:
return et(this.stream.parseStringISO(e, e + i), t);
case 30:
return et(this.stream.parseStringBMP(e, e + i), t);
case 23:
// UTCTime
case 24:
return this.stream.parseTime(e, e + i, this.tag.tagNumber == 23);
}
return null;
}, n.prototype.toString = function() {
return this.typeName() + "@" + this.stream.pos + "[header:" + this.header + ",length:" + this.length + ",sub:" + (this.sub === null ? "null" : this.sub.length) + "]";
}, n.prototype.toPrettyString = function(t) {
t === void 0 && (t = "");
var e = t + this.typeName() + " @" + this.stream.pos;
if (this.length >= 0 && (e += "+"), e += this.length, this.tag.tagConstructed ? e += " (constructed)" : this.tag.isUniversal() && (this.tag.tagNumber == 3 || this.tag.tagNumber == 4) && this.sub !== null && (e += " (encapsulates)"), e += `
`, this.sub !== null) {
t += " ";
for (var i = 0, r = this.sub.length; i < r; ++i)
e += this.sub[i].toPrettyString(t);
}
return e;
}, n.prototype.posStart = function() {
return this.stream.pos;
}, n.prototype.posContent = function() {
return this.stream.pos + this.header;
}, n.prototype.posEnd = function() {
return this.stream.pos + this.header + Math.abs(this.length);
}, n.prototype.toHexString = function() {
return this.stream.hexDump(this.posStart(), this.posEnd(), !0);
}, n.decodeLength = function(t) {
var e = t.get(), i = e & 127;
if (i == e)
return i;
if (i > 6)
throw new Error("Length over 48 bits not supported at position " + (t.pos - 1));
if (i === 0)
return null;
e = 0;
for (var r = 0; r < i; ++r)
e = e * 256 + t.get();
return e;
}, n.prototype.getHexStringValue = function() {
var t = this.toHexString(), e = this.header * 2, i = this.length * 2;
return t.substr(e, i);
}, n.decode = function(t) {
var e;
t instanceof Nt ? e = t : e = new Nt(t, 0);
var i = new Nt(e), r = new re(e), s = n.decodeLength(e), a = e.pos, o = a - i.pos, c = null, h = function() {
var f = [];
if (s !== null) {
for (var _ = a + s; e.pos < _; )
f[f.length] = n.decode(e);
if (e.pos != _)
throw new Error("Content size is not correct for container starting at offset " + a);
} else
try {
for (; ; ) {
var y = n.decode(e);
if (y.tag.isEOC())
break;
f[f.length] = y;
}
s = a - e.pos;
} catch (d) {
throw new Error("Exception while decoding undefined length content: " + d);
}
return f;
};
if (r.tagConstructed)
c = h();
else if (r.isUniversal() && (r.tagNumber == 3 || r.tagNumber == 4))
try {
if (r.tagNumber == 3 && e.get() != 0)
throw new Error("BIT STRINGs with unused bits cannot encapsulate.");
c = h();
for (var u = 0; u < c.length; ++u)
if (c[u].tag.isEOC())
throw new Error("EOC is not supposed to be actual content.");
} catch {
c = null;
}
if (c === null) {
if (s === null)
throw new Error("We can't skip over an invalid tag with undefined length at offset " + a);
e.pos = a + Math.abs(s);
}
return new n(i, o, s, r, c);
}, n;
}()
), re = (
/** @class */
function() {
function n(t) {
var e = t.get();
if (this.tagClass = e >> 6, this.tagConstructed = (e & 32) !== 0, this.tagNumber = e & 31, this.tagNumber == 31) {
var i = new at();
do
e = t.get(), i.mulAdd(128, e & 127);
while (e & 128);
this.tagNumber = i.simplify();
}
}
return n.prototype.isUniversal = function() {
return this.tagClass === 0;
}, n.prototype.isEOC = function() {
return this.tagClass === 0 && this.tagNumber === 0;
}, n;
}()
), z, ui = 244837814094590, se = (ui & 16777215) == 15715070, D = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997], hi = (1 << 26) / D[D.length - 1], v = (
/** @class */
function() {
function n(t, e, i) {
t != null && (typeof t == "number" ? this.fromNumber(t, e, i) : e == null && typeof t != "string" ? this.fromString(t, 256) : this.fromString(t, e));
}
return n.prototype.toString = function(t) {
if (this.s < 0)
return "-" + this.negate().toString(t);
var e;
if (t == 16)
e = 4;
else if (t == 8)
e = 3;
else if (t == 2)
e = 1;
else if (t == 32)
e = 5;
else if (t == 4)
e = 2;
else
return this.toRadix(t);
var i = (1 << e) - 1, r, s = !1, a = "", o = this.t, c = this.DB - o * this.DB % e;
if (o-- > 0)
for (c < this.DB && (r = this[o] >> c) > 0 && (s = !0, a = H(r)); o >= 0; )
c < e ? (r = (this[o] & (1 << c) - 1) << e - c, r |= this[--o] >> (c += this.DB - e)) : (r = this[o] >> (c -= e) & i, c <= 0 && (c += this.DB, --o)), r > 0 && (s = !0), s && (a += H(r));
return s ? a : "0";
}, n.prototype.negate = function() {
var t = w();
return n.ZERO.subTo(this, t), t;
}, n.prototype.abs = function() {
return this.s < 0 ? this.negate() : this;
}, n.prototype.compareTo = function(t) {
var e = this.s - t.s;
if (e != 0)
return e;
var i = this.t;
if (e = i - t.t, e != 0)
return this.s < 0 ? -e : e;
for (; --i >= 0; )
if ((e = this[i] - t[i]) != 0)
return e;
return 0;
}, n.prototype.bitLength = function() {
return this.t <= 0 ? 0 : this.DB * (this.t - 1) + dt(this[this.t - 1] ^ this.s & this.DM);
}, n.prototype.mod = function(t) {
var e = w();
return this.abs().divRemTo(t, null, e), this.s < 0 && e.compareTo(n.ZERO) > 0 && t.subTo(e, e), e;
}, n.prototype.modPowInt = function(t, e) {
var i;
return t < 256 || e.isEven() ? i = new ae(e) : i = new oe(e), this.exp(t, i);
}, n.prototype.clone = function() {
var t = w();
return this.copyTo(t), t;
}, n.prototype.intValue = function() {
if (this.s < 0) {
if (this.t == 1)
return this[0] - this.DV;
if (this.t == 0)
return -1;
} else {
if (this.t == 1)
return this[0];
if (this.t == 0)
return 0;
}
return (this[1] & (1 << 32 - this.DB) - 1) << this.DB | this[0];
}, n.prototype.byteValue = function() {
return this.t == 0 ? this.s : this[0] << 24 >> 24;
}, n.prototype.shortValue = function() {
return this.t == 0 ? this.s : this[0] << 16 >> 16;
}, n.prototype.signum = function() {
return this.s < 0 ? -1 : this.t <= 0 || this.t == 1 && this[0] <= 0 ? 0 : 1;
}, n.prototype.toByteArray = function() {
var t = this.t, e = [];
e[0] = this.s;
var i = this.DB - t * this.DB % 8, r, s = 0;
if (t-- > 0)
for (i < this.DB && (r = this[t] >> i) != (this.s & this.DM) >> i && (e[s++] = r | this.s << this.DB - i); t >= 0; )
i < 8 ? (r = (this[t] & (1 << i) - 1) << 8 - i, r |= this[--t] >> (i += this.DB - 8)) : (r = this[t] >> (i -= 8) & 255, i <= 0 && (i += this.DB, --t)), (r & 128) != 0 && (r |= -256), s == 0 && (this.s & 128) != (r & 128) && ++s, (s > 0 || r != this.s) && (e[s++] = r);
return e;
}, n.prototype.equals = function(t) {
return this.compareTo(t) == 0;
}, n.prototype.min = function(t) {
return this.compareTo(t) < 0 ? this : t;
}, n.prototype.max = function(t) {
return this.compareTo(t) > 0 ? this : t;
}, n.prototype.and = function(t) {
var e = w();
return this.bitwiseTo(t, ii, e), e;
}, n.prototype.or = function(t) {
var e = w();
return this.bitwiseTo(t, pt, e), e;
}, n.prototype.xor = function(t) {
var e = w();
return this.bitwiseTo(t, ee, e), e;
}, n.prototype.andNot = function(t) {
var e = w();
return this.bitwiseTo(t, ie, e), e;
}, n.prototype.not = function() {
for (var t = w(), e = 0; e < this.t; ++e)
t[e] = this.DM & ~this[e];
return t.t = this.t, t.s = ~this.s, t;
}, n.prototype.shiftLeft = function(t) {
var e = w();
return t < 0 ? this.rShiftTo(-t, e) : this.lShiftTo(t, e), e;
}, n.prototype.shiftRight = function(t) {
var e = w();
return t < 0 ? this.lShiftTo(-t, e) : this.rShiftTo(t, e), e;
}, n.prototype.getLowestSetBit = function() {
for (var t = 0; t < this.t; ++t)
if (this[t] != 0)
return t * this.DB + ni(this[t]);
return this.s < 0 ? this.t * this.DB : -1;
}, n.prototype.bitCount = function() {
for (var t = 0, e = this.s & this.DM, i = 0; i < this.t; ++i)
t += ri(this[i] ^ e);
return t;
}, n.prototype.testBit = function(t) {
var e = Math.floor(t / this.DB);
return e >= this.t ? this.s != 0 : (this[e] & 1 << t % this.DB) != 0;
}, n.prototype.setBit = function(t) {
return this.changeBit(t, pt);
}, n.prototype.clearBit = function(t) {
return this.changeBit(t, ie);
}, n.prototype.flipBit = function(t) {
return this.changeBit(t, ee);
}, n.prototype.add = function(t) {
var e = w();
return this.addTo(t, e), e;
}, n.prototype.subtract = function(t) {
var e = w();
return this.subTo(t, e), e;
}, n.prototype.multiply = function(t) {
var e = w();
return this.multiplyTo(t, e), e;
}, n.prototype.divide = function(t) {
var e = w();
return this.divRemTo(t, e, null), e;
}, n.prototype.remainder = function(t) {
var e = w();
return this.divRemTo(t, null, e), e;
}, n.prototype.divideAndRemainder = function(t) {
var e = w(), i = w();
return this.divRemTo(t, e, i), [e, i];
}, n.prototype.modPow = function(t, e) {
var i = t.bitLength(), r, s = W(1), a;
if (i <= 0)
return s;
i < 18 ? r = 1 : i < 48 ? r = 3 : i < 144 ? r = 4 : i < 768 ? r = 5 : r = 6, i < 8 ? a = new ae(e) : e.isEven() ? a = new fi(e) : a = new oe(e);
var o = [], c = 3, h = r - 1, u = (1 << r) - 1;
if (o[1] = a.convert(this), r > 1) {
var f = w();
for (a.sqrTo(o[1], f); c <= u; )
o[c] = w(), a.mulTo(f, o[c - 2], o[c]), c += 2;
}
var _ = t.t - 1, y, d = !0, m = w(), g;
for (i = dt(t[_]) - 1; _ >= 0; ) {
for (i >= h ? y = t[_] >> i - h & u : (y = (t[_] & (1 << i + 1) - 1) << h - i, _ > 0 && (y |= t[_ - 1] >> this.DB + i - h)), c = r; (y & 1) == 0; )
y >>= 1, --c;
if ((i -= c) < 0 && (i += this.DB, --_), d)
o[y].copyTo(s), d = !1;
else {
for (; c > 1; )
a.sqrTo(s, m), a.sqrTo(m, s), c -= 2;
c > 0 ? a.sqrTo(s, m) : (g = s, s = m, m = g), a.mulTo(m, o[y], s);
}
for (; _ >= 0 && (t[_] & 1 << i) == 0; )
a.sqrTo(s, m), g = s, s = m, m = g, --i < 0 && (i = this.DB - 1, --_);
}
return a.revert(s);
}, n.prototype.modInverse = function(t) {
var e = t.isEven();
if (this.isEven() && e || t.signum() == 0)
return n.ZERO;
for (var i = t.clone(), r = this.clone(), s = W(1), a = W(0), o = W(0), c = W(1); i.signum() != 0; ) {
for (; i.isEven(); )
i.rShiftTo(1, i), e ? ((!s.isEven() || !a.isEven()) && (s.addTo(this, s), a.subTo(t, a)), s.rShiftTo(1, s)) : a.isEven() || a.subTo(t, a), a.rShiftTo(1, a);
for (; r.isEven(); )
r.rShiftTo(1, r), e ? ((!o.isEven() || !c.isEven()) && (o.addTo(this, o), c.subTo(t, c)), o.rShiftTo(1, o)) : c.isEven() || c.subTo(t, c), c.rShiftTo(1, c);
i.compareTo(r) >= 0 ? (i.subTo(r, i), e && s.subTo(o, s), a.subTo(c, a)) : (r.subTo(i, r), e && o.subTo(s, o), c.subTo(a, c));
}
if (r.compareTo(n.ONE) != 0)
return n.ZERO;
if (c.compareTo(t) >= 0)
return c.subtract(t);
if (c.signum() < 0)
c.addTo(t, c);
else
return c;
return c.signum() < 0 ? c.add(t) : c;
}, n.prototype.pow = function(t) {
return this.exp(t, new li());
}, n.prototype.gcd = function(t) {
var e = this.s < 0 ? this.negate() : this.clone(), i = t.s < 0 ? t.negate() : t.clone();
if (e.compareTo(i) < 0) {
var r = e;
e = i, i = r;
}
var s = e.getLowestSetBit(), a = i.getLowestSetBit();
if (a < 0)
return e;
for (s < a && (a = s), a > 0 && (e.rShiftTo(a, e), i.rShiftTo(a, i)); e.signum() > 0; )
(s = e.getLowestSetBit()) > 0 && e.rShiftTo(s, e), (s = i.getLowestSetBit()) > 0 && i.rShiftTo(s, i), e.compareTo(i) >= 0 ? (e.subTo(i, e), e.rShiftTo(1, e)) : (i.subTo(e, i), i.rShiftTo(1, i));
return a > 0 && i.lShiftTo(a, i), i;
}, n.prototype.isProbablePrime = function(t) {
var e, i = this.abs();
if (i.t == 1 && i[0] <= D[D.length - 1]) {
for (e = 0; e < D.length; ++e)
if (i[0] == D[e])
return !0;
return !1;
}
if (i.isEven())
return !1;
for (e = 1; e < D.length; ) {
for (var r = D[e], s = e + 1; s < D.length && r < hi; )
r *= D[s++];
for (r = i.modInt(r); e < s; )
if (r % D[e++] == 0)
return !1;
}
return i.millerRabin(t);
}, n.prototype.copyTo = function(t) {
for (var e = this.t - 1; e >= 0; --e)
t[e] = this[e];
t.t = this.t, t.s = this.s;
}, n.prototype.fromInt = function(t) {
this.t = 1, this.s = t < 0 ? -1 : 0, t > 0 ? this[0] = t : t < -1 ? this[0] = t + this.DV : this.t = 0;
}, n.prototype.fromString = function(t, e) {
var i;
if (e == 16)
i = 4;
else if (e == 8)
i = 3;
else if (e == 256)
i = 8;
else if (e == 2)
i = 1;
else if (e == 32)
i = 5;
else if (e == 4)
i = 2;
else {
this.fromRadix(t, e);
return;
}
this.t = 0, this.s = 0;
for (var r = t.length, s = !1, a = 0; --r >= 0; ) {
var o = i == 8 ? +t[r] & 255 : ue(t, r);
if (o < 0) {
t.charAt(r) == "-" && (s = !0);
continue;
}
s = !1, a == 0 ? this[this.t++] = o : a + i > this.DB ? (this[this.t - 1] |= (o & (1 << this.DB - a) - 1) << a, this[this.t++] = o >> this.DB - a) : this[this.t - 1] |= o << a, a += i, a >= this.DB && (a -= this.DB);
}
i == 8 && (+t[0] & 128) != 0 && (this.s = -1, a > 0 && (this[this.t - 1] |= (1 << this.DB - a) - 1 << a)), this.clamp(), s && n.ZERO.subTo(this, this);
}, n.prototype.clamp = function() {
for (var t = this.s & this.DM; this.t > 0 && this[this.t - 1] == t; )
--this.t;
}, n.prototype.dlShiftTo = function(t, e) {
var i;
for (i = this.t - 1; i >= 0; --i)
e[i + t] = this[i];
for (i = t - 1; i >= 0; --i)
e[i] = 0;
e.t = this.t + t, e.s = this.s;
}, n.prototype.drShiftTo = function(t, e) {
for (var i = t; i < this.t; ++i)
e[i - t] = this[i];
e.t = Math.max(this.t - t, 0), e.s = this.s;
}, n.prototype.lShiftTo = function(t, e) {
for (var i = t % this.DB, r = this.DB - i, s = (1 << r) - 1, a = Math.floor(t / this.DB), o = this.s << i & this.DM, c = this.t - 1; c >= 0; --c)
e[c + a + 1] = this[c] >> r | o, o = (this[c] & s) << i;
for (var c = a - 1; c >= 0; --c)
e[c] = 0;
e[a] = o, e.t = this.t + a + 1, e.s = this.s, e.clamp();
}, n.prototype.rShiftTo = function(t, e) {
e.s = this.s;
var i = Math.floor(t / this.DB);
if (i >= this.t) {
e.t = 0;
return;
}
var r = t % this.DB, s = this.DB - r, a = (1 << r) - 1;
e[0] = this[i] >> r;
for (var o = i + 1; o < this.t; ++o)
e[o - i - 1] |= (this[o] & a) << s, e[o - i] = this[o] >> r;
r > 0 && (e[this.t - i - 1] |= (this.s & a) << s), e.t = this.t - i, e.clamp();
}, n.prototype.subTo = function(t, e) {
for (var i = 0, r = 0, s = Math.min(t.t, this.t); i < s; )
r += this[i] - t[i], e[i++] = r & this.DM, r >>= this.DB;
if (t.t < this.t) {
for (r -= t.s; i < this.t; )
r += this[i], e[i++] = r & this.DM, r >>= this.DB;
r += this.s;
} else {
for (r += this.s; i < t.t; )
r -= t[i], e[i++] = r & this.DM, r >>= this.DB;
r -= t.s;
}
e.s = r < 0 ? -1 : 0, r < -1 ? e[i++] = this.DV + r : r > 0 && (e[i++] = r), e.t = i, e.clamp();
}, n.prototype.multiplyTo = function(t, e) {
var i = this.abs(), r = t.abs(), s = i.t;
for (e.t = s + r.t; --s >= 0; )
e[s] = 0;
for (s = 0; s < r.t; ++s)
e[s + i.t] = i.am(0, r[s], e, s, 0, i.t);
e.s = 0, e.clamp(), this.s != t.s && n.ZERO.subTo(e, e);
}, n.prototype.squareTo = function(t) {
for (var e = this.abs(), i = t.t = 2 * e.t; --i >= 0; )
t[i] = 0;
for (i = 0; i < e.t - 1; ++i) {
var r = e.am(i, e[i], t, 2 * i, 0, 1);
(t[i + e.t] += e.am(i + 1, 2 * e[i], t, 2 * i + 1, r, e.t - i - 1)) >= e.DV && (t[i + e.t] -= e.DV, t[i + e.t + 1] = 1);
}
t.t > 0 && (t[t.t - 1] += e.am(i, e[i], t, 2 * i, 0, 1)), t.s = 0, t.clamp();
}, n.prototype.divRemTo = function(t, e, i) {
var r = t.abs();
if (!(r.t <= 0)) {
var s = this.abs();
if (s.t < r.t) {
e?.fromInt(0), i != null && this.copyTo(i);
return;
}
i == null && (i = w());
var a = w(), o = this.s, c = t.s, h = this.DB - dt(r[r.t - 1]);
h > 0 ? (r.lShiftTo(h, a), s.lShiftTo(h, i)) : (r.copyTo(a), s.copyTo(i));
var u = a.t, f = a[u - 1];
if (f != 0) {
var _ = f * (1 << this.F1) + (u > 1 ? a[u - 2] >> this.F2 : 0), y = this.FV / _, d = (1 << this.F1) / _, m = 1 << this.F2, g = i.t, S = g - u, E = e ?? w();
for (a.dlShiftTo(S, E), i.compareTo(E) >= 0 && (i[i.t++] = 1, i.subTo(E, i)), n.ONE.dlShiftTo(u, E), E.subTo(a, a); a.t < u; )
a[a.t++] = 0;
for (; --S >= 0; ) {
var C = i[--g] == f ? this.DM : Math.floor(i[g] * y + (i[g - 1] + m) * d);
if ((i[g] += a.am(0, C, i, S, 0, u)) < C)
for (a.dlShiftTo(S, E), i.subTo(E, i); i[g] < --C; )
i.subTo(E, i);
}
e != null && (i.drShiftTo(u, e), o != c && n.ZERO.subTo(e, e)), i.t = u, i.clamp(), h > 0 && i.rShiftTo(h, i), o < 0 && n.ZERO.subTo(i, i);
}
}
}, n.prototype.invDigit = function() {
if (this.t < 1)
return 0;
var t = this[0];
if ((t & 1) == 0)
return 0;
var e = t & 3;
return e = e * (2 - (t & 15) * e) & 15, e = e * (2 - (t & 255) * e) & 255, e = e * (2 - ((t & 65535) * e & 65535)) & 65535, e = e * (2 - t * e % this.DV) % this.DV, e > 0 ? this.DV - e : -e;
}, n.prototype.isEven = function() {
return (this.t > 0 ? this[0] & 1 : this.s) == 0;
}, n.prototype.exp = function(t, e) {
if (t > 4294967295 || t < 1)
return n.ONE;
var i = w(), r = w(), s = e.convert(this), a = dt(t) - 1;
for (s.copyTo(i); --a >= 0; )
if (e.sqrTo(i, r), (t & 1 << a) > 0)
e.mulTo(r, s, i);
else {
var o = i;
i = r, r = o;
}
return e.revert(i);
}, n.prototype.chunkSize = function(t) {
return Math.floor(Math.LN2 * this.DB / Math.log(t));
}, n.prototype.toRadix = function(t) {
if (t == null && (t = 10), this.signum() == 0 || t < 2 || t > 36)
return "0";
var e = this.chunkSize(t), i = Math.pow(t, e), r = W(i), s = w(), a = w(), o = "";
for (this.divRemTo(r, s, a); s.signum() > 0; )
o = (i + a.intValue()).toString(t).substr(1) + o, s.divRemTo(r, s, a);
return a.intValue().toString(t) + o;
}, n.prototype.fromRadix = function(t, e) {
this.fromInt(0), e == null && (e = 10);
for (var i = this.chunkSize(e), r = Math.pow(e, i), s = !1, a = 0, o = 0, c = 0; c < t.length; ++c) {
var h = ue(t, c);
if (h < 0) {
t.charAt(c) == "-" && this.signum() == 0 && (s = !0);
continue;
}
o = e * o + h, ++a >= i && (this.dMultiply(r), this.dAddOffset(o, 0), a = 0, o = 0);
}
a > 0 && (this.dMultiply(Math.pow(e, a)), this.dAddOffset(o, 0)), s && n.ZERO.subTo(this, this);
}, n.prototype.fromNumber = function(t, e, i) {
if (typeof e == "number")
if (t < 2)
this.fromInt(1);
else
for (this.fromNumber(t, i), this.testBit(t - 1) || this.bitwiseTo(n.ONE.shiftLeft(t - 1), pt, this), this.isEven() && this.dAddOffset(1, 0); !this.isProbablePrime(e); )
this.dAddOffset(2, 0), this.bitLength() > t && this.subTo(n.ONE.shiftLeft(t - 1), this);
else {
var r = [], s = t & 7;
r.length = (t >> 3) + 1, e.nextBytes(r), s > 0 ? r[0] &= (1 << s) - 1 : r[0] = 0, this.fromString(r, 256);
}
}, n.prototype.bitwiseTo = function(t, e, i) {
var r, s, a = Math.min(t.t, this.t);
for (r = 0; r < a; ++r)
i[r] = e(this[r], t[r]);
if (t.t < this.t) {
for (s = t.s & this.DM, r = a; r < this.t; ++r)
i[r] = e(this[r], s);
i.t = this.t;
} else {
for (s = this.s & this.DM, r = a; r < t.t; ++r)
i[r] = e(s, t[r]);
i.t = t.t;
}
i.s = e(this.s, t.s), i.clamp();
}, n.prototype.changeBit = function(t, e) {
var i = n.ONE.shiftLeft(t);
return this.bitwiseTo(i, e, i), i;
}, n.prototype.addTo = function(t, e) {
for (var i = 0, r = 0, s = Math.min(t.t, this.t); i < s; )
r += this[i] + t[i], e[i++] = r & this.DM, r >>= this.DB;
if (t.t < this.t) {
for (r += t.s; i < this.t; )
r += this[i], e[i++] = r & this.DM, r >>= this.DB;
r += this.s;
} else {
for (r += this.s; i < t.t; )
r += t[i], e[i++] = r & this.DM, r >>= this.DB;
r += t.s;
}
e.s = r < 0 ? -1 : 0, r > 0 ? e[i++] = r : r < -1 && (e[i++] = this.DV + r), e.t = i, e.clamp();
}, n.prototype.dMultiply = function(t) {
this[this.t] = this.am(0, t - 1, this, 0, 0, this.t), ++this.t, this.clamp();
}, n.prototype.dAddOffset = function(t, e) {
if (t != 0) {
for (; this.t <= e; )
this[this.t++] = 0;
for (this[e] += t; this[e] >= this.DV; )
this[e] -= this.DV, ++e >= this.t && (this[this.t++] = 0), ++this[e];
}
}, n.prototype.multiplyLowerTo = function(t, e, i) {
var r = Math.min(this.t + t.t, e);
for (i.s = 0, i.t = r; r > 0; )
i[--r] = 0;
for (var s = i.t - this.t; r < s; ++r)
i[r + this.t] = this.am(0, t[r], i, r, 0, this.t);
for (var s = Math.min(t.t, e); r < s; ++r)
this.am(0, t[r], i, r, 0, e - r);
i.clamp();
}, n.prototype.multiplyUpperTo = function(t, e, i) {
--e;
var r = i.t = this.t + t.t - e;
for (i.s = 0; --r >= 0; )
i[r] = 0;
for (r = Math.max(e - this.t, 0); r < t.t; ++r)
i[this.t + r - e] = this.am(e - r, t[r], i, 0, 0, this.t + r - e);
i.clamp(), i.drShiftTo(1, i);
}, n.prototype.modInt = function(t) {
if (t <= 0)
return 0;
var e = this.DV % t, i = this.s < 0 ? t - 1 : 0;
if (this.t > 0)
if (e == 0)
i = this[0] % t;
else
for (var r = this.t - 1; r >= 0; --r)
i = (e * i + this[r]) % t;
return i;
}, n.prototype.millerRabin = function(t) {
var e = this.subtract(n.ONE), i = e.getLowestSetBit();
if (i <= 0)
return !1;
var r = e.shiftRight(i);
t = t + 1 >> 1, t > D.length && (t = D.length);
for (var s = w(), a = 0; a < t; ++a) {
s.fromInt(D[Math.floor(Math.random() * D.length)]);
var o = s.modPow(r, this);
if (o.compareTo(n.ONE) != 0 && o.compareTo(e) != 0) {
for (var c = 1; c++ < i && o.compareTo(e) != 0; )
if (o = o.modPowInt(2, this), o.compareTo(n.ONE) == 0)
return !1;
if (o.compareTo(e) != 0)
return !1;
}
}
return !0;
}, n.prototype.square = function() {
var t = w();
return this.squareTo(t), t;
}, n.prototype.gcda = function(t, e) {
var i = this.s < 0 ? this.negate() : this.clone(), r = t.s < 0 ? t.negate() : t.clone();
if (i.compareTo(r) < 0) {
var s = i;
i = r, r = s;
}
var a = i.getLowestSetBit(), o = r.getLowestSetBit();
if (o < 0) {
e(i);
return;
}
a < o && (o = a), o > 0 && (i.rShiftTo(o, i), r.rShiftTo(o, r));
var c = function() {
(a = i.getLowestSetBit()) > 0 && i.rShiftTo(a, i), (a = r.getLowestSetBit()) > 0 && r.rShiftTo(a, r), i.compareTo(r) >= 0 ? (i.subTo(r, i), i.rShiftTo(1, i)) : (r.subTo(i, r), r.rShiftTo(1, r)), i.signum() > 0 ? setTimeout(c, 0) : (o > 0 && r.lShiftTo(o, r), setTimeout(function() {
e(r);
}, 0));
};
setTimeout(c, 10);
}, n.prototype.fromNumberAsync = function(t, e, i, r) {
if (typeof e == "number")
if (t < 2)
this.fromInt(1);
else {
this.fromNumber(t, i), this.testBit(t - 1) || this.bitwiseTo(n.ONE.shiftLeft(t - 1), pt, this), this.isEven() && this.dAddOffset(1, 0);
var s = this, a = function() {
s.dAddOffset(2, 0), s.bitLength() > t && s.subTo(n.ONE.shiftLeft(t - 1), s), s.isProbablePrime(e) ? setTimeout(function() {
r();
}, 0) : setTimeout(a, 0);
};
setTimeout(a, 0);
}
else {
var o = [], c = t & 7;
o.length = (t >> 3) + 1, e.nextBytes(o), c > 0 ? o[0] &= (1 << c) - 1 : o[0] = 0, this.fromString(o, 256);
}
}, n;
}()
), li = (
/** @class */
function() {
function n() {
}
return n.prototype.convert = function(t) {
return t;
}, n.prototype.revert = function(t) {
return t;
}, n.prototype.mulTo = function(t, e, i) {
t.multiplyTo(e, i);
}, n.prototype.sqrTo = function(t, e) {
t.squareTo(e);
}, n;
}()
), ae = (
/** @class */
function() {
function n(t) {
this.m = t;
}
return n.prototype.convert = function(t) {
return t.s < 0 || t.compareTo(this.m) >= 0 ? t.mod(this.m) : t;
}, n.prototype.revert = function(t) {
return t;
}, n.prototype.reduce = function(t) {
t.divRemTo(this.m, null, t);
}, n.prototype.mulTo = function(t, e, i) {
t.multiplyTo(e, i), this.reduce(i);
}, n.prototype.sqrTo = function(t, e) {
t.squareTo(e), this.reduce(e);
}, n;
}()
), oe = (
/** @class */
function() {
function n(t) {
this.m = t, this.mp = t.invDigit(), this.mpl = this.mp & 32767, this.mph = this.mp >> 15, this.um = (1 << t.DB - 15) - 1, this.mt2 = 2 * t.t;
}
return n.prototype.convert = function(t) {
var e = w();
return t.abs().dlShiftTo(this.m.t, e), e.divRemTo(this.m, null, e), t.s < 0 && e.compareTo(v.ZERO) > 0 && this.m.subTo(e, e), e;
}, n.prototype.revert = function(t) {
var e = w();
return t.copyTo(e), this.reduce(e), e;
}, n.prototype.reduce = function(t) {
for (; t.t <= this.mt2; )
t[t.t++] = 0;
for (var e = 0; e < this.m.t; ++e) {
var i = t[e] & 32767, r = i * this.mpl + ((i * this.mph + (t[e] >> 15) * this.mpl & this.um) << 15) & t.DM;
for (i = e + this.m.t, t[i] += this.m.am(0, r, t, e, 0, this.m.t); t[i] >= t.DV; )
t[i] -= t.DV, t[++i]++;
}
t.clamp(), t.drShiftTo(this.m.t, t), t.compareTo(this.m) >= 0 && t.subTo(this.m, t);
}, n.prototype.mulTo = function(t, e, i) {
t.multiplyTo(e, i), this.reduce(i);
}, n.prototype.sqrTo = function(t, e) {
t.squareTo(e), this.reduce(e);
}, n;
}()
), fi = (
/** @class */
function() {
function n(t) {
this.m = t, this.r2 = w(), this.q3 = w(), v.ONE.dlShiftTo(2 * t.t, this.r2), this.mu = this.r2.divide(t);
}
return n.prototype.convert = function(t) {
if (t.s < 0 || t.t > 2 * this.m.t)
return t.mod(this.m);
if (t.compareTo(this.m) < 0)
return t;
var e = w();
return t.copyTo(e), this.reduce(e), e;
}, n.prototype.revert = function(t) {
return t;
}, n.prototype.reduce = function(t) {
for (t.drShiftTo(this.m.t - 1, this.r2), t.t > this.m.t + 1 && (t.t = this.m.t + 1, t.clamp()), this.mu.multiplyUpperTo(this.r2, this.m.t + 1, this.q3), this.m.multiplyLowerTo(this.q3, this.m.t + 1, this.r2); t.compareTo(this.r2) < 0; )
t.dAddOffset(1, this.m.t + 1);
for (t.subTo(this.r2, t); t.compareTo(this.m) >= 0; )
t.subTo(this.m, t);
}, n.prototype.mulTo = function(t, e, i) {
t.multiplyTo(e, i), this.reduce(i);
}, n.prototype.sqrTo = function(t, e) {
t.squareTo(e), this.reduce(e);
}, n;
}()
);
function w() {
return new v(null);
}
function A(n, t) {
return new v(n, t);
}
var ce = typeof navigator < "u";
ce && se && navigator.appName == "Microsoft Internet Explorer" ? (v.prototype.am = function(t, e, i, r, s, a) {
for (var o = e & 32767, c = e >> 15; --a >= 0; ) {
var h = this[t] & 32767, u = this[t++] >> 15, f = c * h + u * o;
h = o * h + ((f & 32767) << 15) + i[r] + (s & 1073741823), s = (h >>> 30) + (f >>> 15) + c * u + (s >>> 30), i[r++] = h & 1073741823;
}
return s;
}, z = 30) : ce && se && navigator.appName != "Netscape" ? (v.prototype.am = function(t, e, i, r, s, a) {
for (; --a >= 0; ) {
var o = e * this[t++] + i[r] + s;
s = Math.floor(o / 67108864), i[r++] = o & 67108863;
}
return s;
}, z = 26) : (v.prototype.am = function(t, e, i, r, s, a) {
for (var o = e & 16383, c = e >> 14; --a >= 0; ) {
var h = this[t] & 16383, u = this[t++] >> 14, f = c * h + u * o;
h = o * h + ((f & 16383) << 14) + i[r] + s, s = (h >> 28) + (f >> 14) + c * u, i[r++] = h & 268435455;
}
return s;
}, z = 28);
v.prototype.DB = z;
v.prototype.DM = (1 << z) - 1;
v.prototype.DV = 1 << z;
var Gt = 52;
v.prototype.FV = Math.pow(2, Gt);
v.prototype.F1 = Gt - z;
v.prototype.F2 = 2 * z - Gt;
var Ct = [], it, U;
it = 48;
for (U = 0; U <= 9; ++U)
Ct[it++] = U;
it = 97;
for (U = 10; U < 36; ++U)
Ct[it++] = U;
it = 65;
for (U = 10; U < 36; ++U)
Ct[it++] = U;
function ue(n, t) {
var e = Ct[n.charCodeAt(t)];
return e ?? -1;
}
function W(n) {
var t = w();
return t.fromInt(n), t;
}
function dt(n) {
var t = 1, e;
return (e = n >>> 16) != 0 && (n = e, t += 16), (e = n >> 8) != 0 && (n = e, t += 8), (e = n >> 4) != 0 && (n = e, t += 4), (e = n >> 2) != 0 && (n = e, t += 2), (e = n >> 1) != 0 && (n = e, t += 1), t;
}
v.ZERO = W(0);
v.ONE = W(1);
var pi = (
/** @class */
function() {
function n() {
this.i = 0, this.j = 0, this.S = [];
}
return n.prototype.init = function(t) {
var e, i, r;
for (e = 0; e < 256; ++e)
this.S[e] = e;
for (i = 0, e = 0; e < 256; ++e)
i = i + this.S[e] + t[e % t.length] & 255, r = this.S[e], this.S[e] = this.S[i], this.S[i] = r;
this.i = 0, this.j = 0;
}, n.prototype.next = function() {
var t;
return this.i = this.i + 1 & 255, this.j = this.j + this.S[this.i] & 255, t = this.S[this.i], this.S[this.i] = this.S[this.j], this.S[this.j] = t, this.S[t + this.S[this.i] & 255];
}, n;
}()
);
function di() {
return new pi();
}
var Ce = 256, _t, X = null, M;
if (X == null) {
X = [], M = 0;
var gt = void 0;
if (typeof window < "u" && window.crypto && window.crypto.getRandomValues) {
var Vt = new Uint32Array(256);
for (window.crypto.getRandomValues(Vt), gt = 0; gt < Vt.length; ++gt)
X[M++] = Vt[gt] & 255;
}
var mt = 0, yt = function(n) {
if (mt = mt || 0, mt >= 256 || M >= Ce) {
window.removeEventListener ? window.removeEventListener("mousemove", yt, !1) : window.detachEvent && window.detachEvent("onmousemove", yt);
return;
}
try {
var t = n.x + n.y;
X[M++] = t & 255, mt += 1;
} catch {
}
};
typeof window < "u" && (window.addEventListener ? window.addEventListener("mousemove", yt, !1) : window.attachEvent && window.attachEvent("onmousemove", yt));
}
function _i() {
if (_t == null) {
for (_t = di(); M < Ce; ) {
var n = Math.floor(65536 * Math.random());
X[M++] = n & 255;
}
for (_t.init(X), M = 0; M < X.length; ++M)
X[M] = 0;
M = 0;
}
return _t.next();
}
var jt = (
/** @class */
function() {
function n() {
}
return n.prototype.nextBytes = function(t) {
for (var e = 0; e < t.length; ++e)
t[e] = _i();
}, n;
}()
);
function gi(n, t) {
if (t < n.length + 22)
return console.error("Message too long for RSA"), null;
for (var e = t - n.length - 6, i = "", r = 0; r < e; r += 2)
i += "ff";
var s = "0001" + i + "00" + n;
return A(s, 16);
}
function mi(n, t) {
if (t < n.length + 11)
return console.error("Message too long for RSA"), null;
for (var e = [], i = n.length - 1; i >= 0 && t > 0; ) {
var r = n.charCodeAt(i--);
r < 128 ? e[--t] = r : r > 127 && r < 2048 ? (e[--t] = r & 63 | 128, e[--t] = r >> 6 | 192) : (e[--t] = r & 63 | 128, e[--t] = r >> 6 & 63 | 128, e[--t] = r >> 12 | 224);
}
e[--t] = 0;
for (var s = new jt(), a = []; t > 2; ) {
for (a[0] = 0; a[0] == 0; )
s.nextBytes(a);
e[--t] = a[0];
}
return e[--t] = 2, e[--t] = 0, new v(e);
}
var yi = (
/** @class */
function() {
function n() {
this.n = null, this.e = 0, this.d = null, this.p = null, this.q = null, this.dmp1 = null, this.dmq1 = null, this.coeff = null;
}
return n.prototype.doPublic = function(t) {
return t.modPowInt(this.e, this.n);
}, n.prototype.doPrivate = function(t) {
if (this.p == null || this.q == null)
return t.modPow(this.d, this.n);
for (var e = t.mod(this.p).modPow(this.dmp1, this.p), i = t.mod(this.q).modPow(this.dmq1, this.q); e.compareTo(i) < 0; )
e = e.add(this.p);
return e.subtract(i).multiply(this.coeff).mod(this.p).multiply(this.q).add(i);
}, n.prototype.setPublic = function(t, e) {
t != null && e != null && t.length > 0 && e.length > 0 ? (this.n = A(t, 16), this.e = parseInt(e, 16)) : console.error("Invalid RSA public key");
}, n.prototype.encrypt = function(t) {
var e = this.n.bitLength() + 7 >> 3, i = mi(t, e);
if (i == null)
return null;
var r = this.doPublic(i);
if (r == null)
return null;
for (var s = r.toString(16), a = s.length, o = 0; o < e * 2 - a; o++)
s = "0" + s;
return s;
}, n.prototype.setPrivate = function(t, e, i) {
t != null && e != null && t.length > 0 && e.length > 0 ? (this.n = A(t, 16), this.e = parseInt(e, 16), this.d = A(i, 16)) : console.error("Invalid RSA private key");
}, n.prototype.setPrivateEx = function(t, e, i, r, s, a, o, c) {
t != null && e != null && t.length > 0 && e.length > 0 ? (this.n = A(t, 16), this.e = parseInt(e, 16), this.d = A(i, 16), this.p = A(r, 16), this.q = A(s, 16), this.dmp1 = A(a, 16), this.dmq1 = A(o, 16), this.coeff = A(c, 16)) : console.error("Invalid RSA private key");
}, n.prototype.generate = function(t, e) {
var i = new jt(), r = t >> 1;
this.e = parseInt(e, 16);
for (var s = new v(e, 16); ; ) {
for (; this.p = new v(t - r, 1, i), !(this.p.subtract(v.ONE).gcd(s).compareTo(v.ONE) == 0 && this.p.isProbablePrime(10)); )
;
for (; this.q = new v(r, 1, i), !(this.q.subtract(v.