ethwrapper
Version:
♻️ Utility class to wrap/unwrap ETH on compatible networks
1,705 lines • 451 kB
JavaScript
var wu = Object.defineProperty;
var Au = (r, e, t) => e in r ? wu(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
var p = (r, e, t) => (Au(r, typeof e != "symbol" ? e + "" : e, t), t), ic = (r, e, t) => {
if (!e.has(r))
throw TypeError("Cannot " + t);
};
var f = (r, e, t) => (ic(r, e, "read from private field"), t ? t.call(r) : e.get(r)), y = (r, e, t) => {
if (e.has(r))
throw TypeError("Cannot add the same private member more than once");
e instanceof WeakSet ? e.add(r) : e.set(r, t);
}, x = (r, e, t, n) => (ic(r, e, "write to private field"), n ? n.call(r, t) : e.set(r, t), t), _s = (r, e, t, n) => ({
set _(s) {
x(r, e, s, t);
},
get _() {
return f(r, e, n);
}
}), E = (r, e, t) => (ic(r, e, "access private method"), t);
const uf = "6.0.2";
function Eu(r, e, t) {
const n = e.split("|").map((i) => i.trim());
for (let i = 0; i < n.length; i++)
switch (e) {
case "any":
return;
case "bigint":
case "boolean":
case "number":
case "string":
if (typeof r === e)
return;
}
const s = new Error(`invalid value for type ${e}`);
throw s.code = "INVALID_ARGUMENT", s.argument = `value.${t}`, s.value = r, s;
}
async function ge(r) {
const e = Object.keys(r);
return (await Promise.all(e.map((n) => Promise.resolve(r[n])))).reduce((n, s, i) => (n[e[i]] = s, n), {});
}
function P(r, e, t) {
for (let n in e) {
let s = e[n];
const i = t ? t[n] : null;
i && Eu(s, i, n), Object.defineProperty(r, n, { enumerable: !0, value: s, writable: !1 });
}
}
function vr(r) {
if (r == null)
return "null";
if (Array.isArray(r))
return "[ " + r.map(vr).join(", ") + " ]";
if (r instanceof Uint8Array) {
const e = "0123456789abcdef";
let t = "0x";
for (let n = 0; n < r.length; n++)
t += e[r[n] >> 4], t += e[r[n] & 15];
return t;
}
if (typeof r == "object" && typeof r.toJSON == "function")
return vr(r.toJSON());
switch (typeof r) {
case "boolean":
case "symbol":
return r.toString();
case "bigint":
return BigInt(r).toString();
case "number":
return r.toString();
case "string":
return JSON.stringify(r);
case "object": {
const e = Object.keys(r);
return e.sort(), "{ " + e.map((t) => `${vr(t)}: ${vr(r[t])}`).join(", ") + " }";
}
}
return "[ COULD NOT SERIALIZE ]";
}
function dr(r, e) {
return r && r.code === e;
}
function l0(r) {
return dr(r, "CALL_EXCEPTION");
}
function ve(r, e, t) {
{
const s = [];
if (t) {
if ("message" in t || "code" in t || "name" in t)
throw new Error(`value will overwrite populated values: ${vr(t)}`);
for (const i in t) {
const a = t[i];
s.push(i + "=" + vr(a));
}
}
s.push(`code=${e}`), s.push(`version=${uf}`), s.length && (r += " (" + s.join(", ") + ")");
}
let n;
switch (e) {
case "INVALID_ARGUMENT":
n = new TypeError(r);
break;
case "NUMERIC_FAULT":
case "BUFFER_OVERRUN":
n = new RangeError(r);
break;
default:
n = new Error(r);
}
return P(n, { code: e }), t && P(n, t), n;
}
function m(r, e, t, n) {
if (!r)
throw ve(e, t, n);
}
function h(r, e, t, n) {
m(r, e, "INVALID_ARGUMENT", { argument: t, value: n });
}
function df(r, e, t) {
t == null && (t = ""), t && (t = ": " + t), m(r >= e, "missing arguemnt" + t, "MISSING_ARGUMENT", {
count: r,
expectedCount: e
}), m(r <= e, "too many arguemnts" + t, "UNEXPECTED_ARGUMENT", {
count: r,
expectedCount: e
});
}
const Iu = ["NFD", "NFC", "NFKD", "NFKC"].reduce((r, e) => {
try {
if ("test".normalize(e) !== "test")
throw new Error("bad");
if (e === "NFD") {
const t = String.fromCharCode(233).normalize("NFD"), n = String.fromCharCode(101, 769);
if (t !== n)
throw new Error("broken");
}
r.push(e);
} catch {
}
return r;
}, []);
function xf(r) {
m(Iu.indexOf(r) >= 0, "platform missing String.prototype.normalize", "UNSUPPORTED_OPERATION", {
operation: "String.prototype.normalize",
info: { form: r }
});
}
function Cn(r, e, t) {
if (t == null && (t = ""), r !== e) {
let n = t, s = "new";
t && (n += ".", s += " " + t), m(!1, `private constructor; use ${n}from* methods`, "UNSUPPORTED_OPERATION", {
operation: s
});
}
}
function hf(r, e, t) {
if (r instanceof Uint8Array)
return t ? new Uint8Array(r) : r;
if (typeof r == "string" && r.match(/^0x([0-9a-f][0-9a-f])*$/i)) {
const n = new Uint8Array((r.length - 2) / 2);
let s = 2;
for (let i = 0; i < n.length; i++)
n[i] = parseInt(r.substring(s, s + 2), 16), s += 2;
return n;
}
h(!1, "invalid BytesLike value", e || "value", r);
}
function k(r, e) {
return hf(r, e, !1);
}
function he(r, e) {
return hf(r, e, !0);
}
function q(r, e) {
return !(typeof r != "string" || !r.match(/^0x[0-9A-Fa-f]*$/) || typeof e == "number" && r.length !== 2 + 2 * e || e === !0 && r.length % 2 !== 0);
}
function bf(r) {
return q(r, !0) || r instanceof Uint8Array;
}
const D0 = "0123456789abcdef";
function N(r) {
const e = k(r);
let t = "0x";
for (let n = 0; n < e.length; n++) {
const s = e[n];
t += D0[(s & 240) >> 4] + D0[s & 15];
}
return t;
}
function V(r) {
return "0x" + r.map((e) => N(e).substring(2)).join("");
}
function Mr(r) {
return q(r, !0) ? (r.length - 2) / 2 : k(r).length;
}
function W(r, e, t) {
const n = k(r);
return t != null && t > n.length && m(!1, "cannot slice beyond data bounds", "BUFFER_OVERRUN", {
buffer: n,
length: n.length,
offset: t
}), N(n.slice(e ?? 0, t ?? n.length));
}
function Nu(r, e, t) {
const n = k(r);
m(e >= n.length, "padding exceeds data length", "BUFFER_OVERRUN", {
buffer: new Uint8Array(n),
length: e,
offset: e + 1
});
const s = new Uint8Array(e);
return s.fill(0), t ? s.set(n, e - n.length) : s.set(n, 0), N(s);
}
function pr(r, e) {
return Nu(r, e, !0);
}
const Wa = BigInt(0), at = BigInt(1), Br = 9007199254740991;
function ka(r, e) {
const t = ja(r, "value"), n = BigInt(U(e, "width"));
if (m(t >> n === Wa, "overflow", "NUMERIC_FAULT", {
operation: "fromTwos",
fault: "overflow",
value: r
}), t >> n - at) {
const s = (at << n) - at;
return -((~t & s) + at);
}
return t;
}
function pf(r, e) {
let t = S(r, "value");
const n = BigInt(U(e, "width")), s = at << n - at;
if (t < Wa) {
t = -t, m(t <= s, "too low", "NUMERIC_FAULT", {
operation: "toTwos",
fault: "overflow",
value: r
});
const i = (at << n) - at;
return (~t & i) + at;
} else
m(t < s, "too high", "NUMERIC_FAULT", {
operation: "toTwos",
fault: "overflow",
value: r
});
return t;
}
function Hn(r, e) {
const t = ja(r, "value"), n = BigInt(U(e, "bits"));
return t & (at << n) - at;
}
function S(r, e) {
switch (typeof r) {
case "bigint":
return r;
case "number":
return h(Number.isInteger(r), "underflow", e || "value", r), h(r >= -Br && r <= Br, "overflow", e || "value", r), BigInt(r);
case "string":
try {
if (r === "")
throw new Error("empty string");
return r[0] === "-" && r[1] !== "-" ? -BigInt(r.substring(1)) : BigInt(r);
} catch (t) {
h(!1, `invalid BigNumberish string: ${t.message}`, e || "value", r);
}
}
h(!1, "invalid BigNumberish value", e || "value", r);
}
function ja(r, e) {
const t = S(r, e);
return m(t >= Wa, "unsigned value cannot be negative", "NUMERIC_FAULT", {
fault: "overflow",
operation: "getUint",
value: r
}), t;
}
const M0 = "0123456789abcdef";
function Ji(r) {
if (r instanceof Uint8Array) {
let e = "0x0";
for (const t of r)
e += M0[t >> 4], e += M0[t & 15];
return BigInt(e);
}
return S(r);
}
function U(r, e) {
switch (typeof r) {
case "bigint":
return h(r >= -Br && r <= Br, "overflow", e || "value", r), Number(r);
case "number":
return h(Number.isInteger(r), "underflow", e || "value", r), h(r >= -Br && r <= Br, "overflow", e || "value", r), r;
case "string":
try {
if (r === "")
throw new Error("empty string");
return U(BigInt(r), e);
} catch (t) {
h(!1, `invalid numeric string: ${t.message}`, e || "value", r);
}
}
h(!1, "invalid numeric value", e || "value", r);
}
function Tu(r) {
return U(Ji(r));
}
function Wt(r, e) {
let n = ja(r, "value").toString(16);
if (e == null)
n.length % 2 && (n = "0" + n);
else {
const s = U(e, "width");
for (m(s * 2 >= n.length, `value exceeds width (${s} bits)`, "NUMERIC_FAULT", {
operation: "toBeHex",
fault: "overflow",
value: r
}); n.length < s * 2; )
n = "0" + n;
}
return "0x" + n;
}
function Ce(r) {
const e = ja(r, "value");
if (e === Wa)
return new Uint8Array([]);
let t = e.toString(16);
t.length % 2 && (t = "0" + t);
const n = new Uint8Array(t.length / 2);
for (let s = 0; s < n.length; s++) {
const i = s * 2;
n[s] = parseInt(t.substring(i, i + 2), 16);
}
return n;
}
function Js(r) {
let e = N(bf(r) ? r : Ce(r)).substring(2);
for (; e.substring(0, 1) === "0"; )
e = e.substring(1);
return e === "" && (e = "0"), "0x" + e;
}
const Tc = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
let Xi = null;
function Cu(r) {
if (Xi == null) {
Xi = {};
for (let t = 0; t < Tc.length; t++)
Xi[Tc[t]] = BigInt(t);
}
const e = Xi[r];
return h(e != null, "invalid base58 value", "letter", r), e;
}
const ku = BigInt(0), Cc = BigInt(58);
function gf(r) {
let e = Ji(k(r)), t = "";
for (; e; )
t = Tc[Number(e % Cc)] + t, e /= Cc;
return t;
}
function Pu(r) {
let e = ku;
for (let t = 0; t < r.length; t++)
e *= Cc, e += Cu(r[t]);
return e;
}
function Ou(r) {
r = atob(r);
const e = new Uint8Array(r.length);
for (let t = 0; t < r.length; t++)
e[t] = r.charCodeAt(t);
return k(e);
}
function Ru(r) {
const e = k(r);
let t = "";
for (let n = 0; n < e.length; n++)
t += String.fromCharCode(e[n]);
return btoa(t);
}
var Qr;
class yf {
/**
* Create a new **EventPayload** for %%emitter%% with
* the %%listener%% and for %%filter%%.
*/
constructor(e, t, n) {
/**
* The event filter.
*/
p(this, "filter");
/**
* The **EventEmitterable**.
*/
p(this, "emitter");
y(this, Qr, void 0);
x(this, Qr, t), P(this, { emitter: e, filter: n });
}
/**
* Unregister the triggered listener for future events.
*/
async removeListener() {
f(this, Qr) != null && await this.emitter.off(this.filter, f(this, Qr));
}
}
Qr = new WeakMap();
function Su(r, e, t, n, s) {
h(!1, `invalid codepoint at offset ${e}; ${r}`, "bytes", t);
}
function mf(r, e, t, n, s) {
if (r === "BAD_PREFIX" || r === "UNEXPECTED_CONTINUE") {
let i = 0;
for (let a = e + 1; a < t.length && t[a] >> 6 === 2; a++)
i++;
return i;
}
return r === "OVERRUN" ? t.length - e - 1 : 0;
}
function vu(r, e, t, n, s) {
return r === "OVERLONG" ? (h(typeof s == "number", "invalid bad code point for replacement", "badCodepoint", s), n.push(s), 0) : (n.push(65533), mf(r, e, t));
}
const Bu = Object.freeze({
error: Su,
ignore: mf,
replace: vu
});
function Lu(r, e) {
e == null && (e = Bu.error);
const t = k(r, "bytes"), n = [];
let s = 0;
for (; s < t.length; ) {
const i = t[s++];
if (!(i >> 7)) {
n.push(i);
continue;
}
let a = null, c = null;
if ((i & 224) === 192)
a = 1, c = 127;
else if ((i & 240) === 224)
a = 2, c = 2047;
else if ((i & 248) === 240)
a = 3, c = 65535;
else {
(i & 192) === 128 ? s += e("UNEXPECTED_CONTINUE", s - 1, t, n) : s += e("BAD_PREFIX", s - 1, t, n);
continue;
}
if (s - 1 + a >= t.length) {
s += e("OVERRUN", s - 1, t, n);
continue;
}
let o = i & (1 << 8 - a - 1) - 1;
for (let l = 0; l < a; l++) {
let u = t[s];
if ((u & 192) != 128) {
s += e("MISSING_CONTINUE", s, t, n), o = null;
break;
}
o = o << 6 | u & 63, s++;
}
if (o !== null) {
if (o > 1114111) {
s += e("OUT_OF_RANGE", s - 1 - a, t, n, o);
continue;
}
if (o >= 55296 && o <= 57343) {
s += e("UTF16_SURROGATE", s - 1 - a, t, n, o);
continue;
}
if (o <= c) {
s += e("OVERLONG", s - 1 - a, t, n, o);
continue;
}
n.push(o);
}
}
return n;
}
function Ee(r, e) {
e != null && (xf(e), r = r.normalize(e));
let t = [];
for (let n = 0; n < r.length; n++) {
const s = r.charCodeAt(n);
if (s < 128)
t.push(s);
else if (s < 2048)
t.push(s >> 6 | 192), t.push(s & 63 | 128);
else if ((s & 64512) == 55296) {
n++;
const i = r.charCodeAt(n);
h(n < r.length && (i & 64512) === 56320, "invalid surrogate pair", "str", r);
const a = 65536 + ((s & 1023) << 10) + (i & 1023);
t.push(a >> 18 | 240), t.push(a >> 12 & 63 | 128), t.push(a >> 6 & 63 | 128), t.push(a & 63 | 128);
} else
t.push(s >> 12 | 224), t.push(s >> 6 & 63 | 128), t.push(s & 63 | 128);
}
return new Uint8Array(t);
}
function Uu(r) {
return r.map((e) => e <= 65535 ? String.fromCharCode(e) : (e -= 65536, String.fromCharCode((e >> 10 & 1023) + 55296, (e & 1023) + 56320))).join("");
}
function u0(r, e) {
return Uu(Lu(r, e));
}
async function Fu(r, e) {
const t = r.url.split(":")[0].toLowerCase();
m(t === "http" || t === "https", `unsupported protocol ${t}`, "UNSUPPORTED_OPERATION", {
info: { protocol: t },
operation: "request"
}), m(!r.credentials || r.allowInsecureAuthentication, "insecure authorized connections unsupported", "UNSUPPORTED_OPERATION", {
operation: "request"
});
let n;
if (e) {
const l = new AbortController();
n = l.signal, e.addListener(() => {
l.abort();
});
}
const s = {
method: r.method,
headers: new Headers(Array.from(r)),
body: r.body || void 0,
signal: n
}, i = await fetch(r.url, s), a = {};
i.headers.forEach((l, u) => {
a[u.toLowerCase()] = l;
});
const c = await i.arrayBuffer(), o = c == null ? null : new Uint8Array(c);
return {
statusCode: i.status,
statusMessage: i.statusText,
headers: a,
body: o
};
}
const Du = 12, Mu = 250;
let G0 = Fu;
const Gu = new RegExp("^data:([^;:]*)?(;base64)?,(.*)$", "i"), Hu = new RegExp("^ipfs://(ipfs/)?(.*)$", "i");
let ac = !1;
async function wf(r, e) {
try {
const t = r.match(Gu);
if (!t)
throw new Error("invalid data");
return new En(200, "OK", {
"content-type": t[1] || "text/plain"
}, t[2] ? Ou(t[3]) : Ku(t[3]));
} catch {
return new En(599, "BAD REQUEST (invalid data: URI)", {}, null, new Tn(r));
}
}
function Af(r) {
async function e(t, n) {
try {
const s = t.match(Hu);
if (!s)
throw new Error("invalid link");
return new Tn(`${r}${s[2]}`);
} catch {
return new En(599, "BAD REQUEST (invalid IPFS URI)", {}, null, new Tn(t));
}
}
return e;
}
const qi = {
data: wf,
ipfs: Af("https://gateway.ipfs.io/ipfs/")
}, Ef = /* @__PURE__ */ new WeakMap();
var Kn, cn;
class _u {
constructor(e) {
y(this, Kn, void 0);
y(this, cn, void 0);
x(this, Kn, []), x(this, cn, !1), Ef.set(e, () => {
if (!f(this, cn)) {
x(this, cn, !0);
for (const t of f(this, Kn))
setTimeout(() => {
t();
}, 0);
x(this, Kn, []);
}
});
}
addListener(e) {
m(!f(this, cn), "singal already cancelled", "UNSUPPORTED_OPERATION", {
operation: "fetchCancelSignal.addCancelListener"
}), f(this, Kn).push(e);
}
get cancelled() {
return f(this, cn);
}
checkSignal() {
m(!this.cancelled, "cancelled", "CANCELLED", {});
}
}
Kn = new WeakMap(), cn = new WeakMap();
function ea(r) {
if (r == null)
throw new Error("missing signal; should not happen");
return r.checkSignal(), r;
}
var Jr, Yr, et, St, $r, Wr, re, Oe, vt, zn, Vn, Qn, gt, Bt, Jn, Ys;
const Ga = class {
/**
* Create a new FetchRequest instance with default values.
*
* Once created, each property may be set before issuing a
* ``.send()`` to make teh request.
*/
constructor(e) {
y(this, Jn);
y(this, Jr, void 0);
y(this, Yr, void 0);
y(this, et, void 0);
y(this, St, void 0);
y(this, $r, void 0);
y(this, Wr, void 0);
y(this, re, void 0);
y(this, Oe, void 0);
y(this, vt, void 0);
// Hooks
y(this, zn, void 0);
y(this, Vn, void 0);
y(this, Qn, void 0);
y(this, gt, void 0);
y(this, Bt, void 0);
x(this, Wr, String(e)), x(this, Jr, !1), x(this, Yr, !0), x(this, et, {}), x(this, St, ""), x(this, $r, 3e5), x(this, Bt, {
slotInterval: Mu,
maxAttempts: Du
});
}
/**
* The fetch URI to requrest.
*/
get url() {
return f(this, Wr);
}
set url(e) {
x(this, Wr, String(e));
}
/**
* The fetch body, if any, to send as the request body. //(default: null)//
*
* When setting a body, the intrinsic ``Content-Type`` is automatically
* set and will be used if **not overridden** by setting a custom
* header.
*
* If %%body%% is null, the body is cleared (along with the
* intrinsic ``Content-Type``) and the .
*
* If %%body%% is a string, the intrincis ``Content-Type`` is set to
* ``text/plain``.
*
* If %%body%% is a Uint8Array, the intrincis ``Content-Type`` is set to
* ``application/octet-stream``.
*
* If %%body%% is any other object, the intrincis ``Content-Type`` is
* set to ``application/json``.
*/
get body() {
return f(this, re) == null ? null : new Uint8Array(f(this, re));
}
set body(e) {
if (e == null)
x(this, re, void 0), x(this, Oe, void 0);
else if (typeof e == "string")
x(this, re, Ee(e)), x(this, Oe, "text/plain");
else if (e instanceof Uint8Array)
x(this, re, e), x(this, Oe, "application/octet-stream");
else if (typeof e == "object")
x(this, re, Ee(JSON.stringify(e))), x(this, Oe, "application/json");
else
throw new Error("invalid body");
}
/**
* Returns true if the request has a body.
*/
hasBody() {
return f(this, re) != null;
}
/**
* The HTTP method to use when requesting the URI. If no method
* has been explicitly set, then ``GET`` is used if the body is
* null and ``POST`` otherwise.
*/
get method() {
return f(this, St) ? f(this, St) : this.hasBody() ? "POST" : "GET";
}
set method(e) {
e == null && (e = ""), x(this, St, String(e).toUpperCase());
}
/**
* The headers that will be used when requesting the URI. All
* keys are lower-case.
*
* This object is a copy, so any chnages will **NOT** be reflected
* in the ``FetchRequest``.
*
* To set a header entry, use the ``setHeader`` method.
*/
get headers() {
const e = Object.assign({}, f(this, et));
return f(this, vt) && (e.authorization = `Basic ${Ru(Ee(f(this, vt)))}`), this.allowGzip && (e["accept-encoding"] = "gzip"), e["content-type"] == null && f(this, Oe) && (e["content-type"] = f(this, Oe)), this.body && (e["content-length"] = String(this.body.length)), e;
}
/**
* Get the header for %%key%%, ignoring case.
*/
getHeader(e) {
return this.headers[e.toLowerCase()];
}
/**
* Set the header for %%key%% to %%value%%. All values are coerced
* to a string.
*/
setHeader(e, t) {
f(this, et)[String(e).toLowerCase()] = String(t);
}
/**
* Clear all headers, resetting all intrinsic headers.
*/
clearHeaders() {
x(this, et, {});
}
[Symbol.iterator]() {
const e = this.headers, t = Object.keys(e);
let n = 0;
return {
next: () => {
if (n < t.length) {
const s = t[n++];
return {
value: [s, e[s]],
done: !1
};
}
return { value: void 0, done: !0 };
}
};
}
/**
* The value that will be sent for the ``Authorization`` header.
*
* To set the credentials, use the ``setCredentials`` method.
*/
get credentials() {
return f(this, vt) || null;
}
/**
* Sets an ``Authorization`` for %%username%% with %%password%%.
*/
setCredentials(e, t) {
h(!e.match(/:/), "invalid basic authentication username", "username", "[REDACTED]"), x(this, vt, `${e}:${t}`);
}
/**
* Enable and request gzip-encoded responses. The response will
* automatically be decompressed. //(default: true)//
*/
get allowGzip() {
return f(this, Yr);
}
set allowGzip(e) {
x(this, Yr, !!e);
}
/**
* Allow ``Authentication`` credentials to be sent over insecure
* channels. //(default: false)//
*/
get allowInsecureAuthentication() {
return !!f(this, Jr);
}
set allowInsecureAuthentication(e) {
x(this, Jr, !!e);
}
/**
* The timeout (in milliseconds) to wait for a complere response.
* //(default: 5 minutes)//
*/
get timeout() {
return f(this, $r);
}
set timeout(e) {
h(e >= 0, "timeout must be non-zero", "timeout", e), x(this, $r, e);
}
/**
* This function is called prior to each request, for example
* during a redirection or retry in case of server throttling.
*
* This offers an opportunity to populate headers or update
* content before sending a request.
*/
get preflightFunc() {
return f(this, zn) || null;
}
set preflightFunc(e) {
x(this, zn, e);
}
/**
* This function is called after each response, offering an
* opportunity to provide client-level throttling or updating
* response data.
*
* Any error thrown in this causes the ``send()`` to throw.
*
* To schedule a retry attempt (assuming the maximum retry limit
* has not been reached), use [[response.throwThrottleError]].
*/
get processFunc() {
return f(this, Vn) || null;
}
set processFunc(e) {
x(this, Vn, e);
}
/**
* This function is called on each retry attempt.
*/
get retryFunc() {
return f(this, Qn) || null;
}
set retryFunc(e) {
x(this, Qn, e);
}
toString() {
return `<FetchRequest method=${JSON.stringify(this.method)} url=${JSON.stringify(this.url)} headers=${JSON.stringify(this.headers)} body=${f(this, re) ? N(f(this, re)) : "null"}>`;
}
/**
* Update the throttle parameters used to determine maximum
* attempts and exponential-backoff properties.
*/
setThrottleParams(e) {
e.slotInterval != null && (f(this, Bt).slotInterval = e.slotInterval), e.maxAttempts != null && (f(this, Bt).maxAttempts = e.maxAttempts);
}
/**
* Resolves to the response by sending the request.
*/
send() {
return m(f(this, gt) == null, "request already sent", "UNSUPPORTED_OPERATION", { operation: "fetchRequest.send" }), x(this, gt, new _u(this)), E(this, Jn, Ys).call(this, 0, H0() + this.timeout, 0, this, new En(0, "", {}, null, this));
}
/**
* Cancels the inflight response, causing a ``CANCELLED``
* error to be rejected from the [[send]].
*/
cancel() {
m(f(this, gt) != null, "request has not been sent", "UNSUPPORTED_OPERATION", { operation: "fetchRequest.cancel" });
const e = Ef.get(this);
if (!e)
throw new Error("missing signal; should not happen");
e();
}
/**
* Returns a new [[FetchRequest]] that represents the redirection
* to %%location%%.
*/
redirect(e) {
const t = this.url.split(":")[0].toLowerCase(), n = e.split(":")[0].toLowerCase();
m(this.method === "GET" && (t !== "https" || n !== "http") && e.match(/^https?:/), "unsupported redirect", "UNSUPPORTED_OPERATION", {
operation: `redirect(${this.method} ${JSON.stringify(this.url)} => ${JSON.stringify(e)})`
});
const s = new Ga(e);
return s.method = "GET", s.allowGzip = this.allowGzip, s.timeout = this.timeout, x(s, et, Object.assign({}, f(this, et))), f(this, re) && x(s, re, new Uint8Array(f(this, re))), x(s, Oe, f(this, Oe)), s;
}
/**
* Create a new copy of this request.
*/
clone() {
const e = new Ga(this.url);
return x(e, St, f(this, St)), f(this, re) && x(e, re, f(this, re)), x(e, Oe, f(this, Oe)), x(e, et, Object.assign({}, f(this, et))), x(e, vt, f(this, vt)), this.allowGzip && (e.allowGzip = !0), e.timeout = this.timeout, this.allowInsecureAuthentication && (e.allowInsecureAuthentication = !0), x(e, zn, f(this, zn)), x(e, Vn, f(this, Vn)), x(e, Qn, f(this, Qn)), e;
}
/**
* Locks all static configuration for gateways and FetchGetUrlFunc
* registration.
*/
static lockConfig() {
ac = !0;
}
/**
* Get the current Gateway function for %%scheme%%.
*/
static getGateway(e) {
return qi[e.toLowerCase()] || null;
}
/**
* Use the %%func%% when fetching URIs using %%scheme%%.
*
* This method affects all requests globally.
*
* If [[lockConfig]] has been called, no change is made and this
* throws.
*/
static registerGateway(e, t) {
if (e = e.toLowerCase(), e === "http" || e === "https")
throw new Error(`cannot intercept ${e}; use registerGetUrl`);
if (ac)
throw new Error("gateways locked");
qi[e] = t;
}
/**
* Use %%getUrl%% when fetching URIs over HTTP and HTTPS requests.
*
* This method affects all requests globally.
*
* If [[lockConfig]] has been called, no change is made and this
* throws.
*/
static registerGetUrl(e) {
if (ac)
throw new Error("gateways locked");
G0 = e;
}
/**
* Creates a function that can "fetch" data URIs.
*
* Note that this is automatically done internally to support
* data URIs, so it is not necessary to register it.
*
* This is not generally something that is needed, but may
* be useful in a wrapper to perfom custom data URI functionality.
*/
static createDataGateway() {
return wf;
}
/**
* Creates a function that will fetch IPFS (unvalidated) from
* a custom gateway baseUrl.
*
* The default IPFS gateway used internally is
* ``"https:/\/gateway.ipfs.io/ipfs/"``.
*/
static createIpfsGatewayFunc(e) {
return Af(e);
}
};
let Tn = Ga;
Jr = new WeakMap(), Yr = new WeakMap(), et = new WeakMap(), St = new WeakMap(), $r = new WeakMap(), Wr = new WeakMap(), re = new WeakMap(), Oe = new WeakMap(), vt = new WeakMap(), zn = new WeakMap(), Vn = new WeakMap(), Qn = new WeakMap(), gt = new WeakMap(), Bt = new WeakMap(), Jn = new WeakSet(), Ys = async function(e, t, n, s, i) {
var u, d, b;
if (e >= f(this, Bt).maxAttempts)
return i.makeServerError("exceeded maximum retry limit");
m(H0() <= t, "timeout", "TIMEOUT", {
operation: "request.send",
reason: "timeout",
request: s
}), n > 0 && await zu(n);
let a = this.clone();
const c = (a.url.split(":")[0] || "").toLowerCase();
if (c in qi) {
const g = await qi[c](a.url, ea(f(s, gt)));
if (g instanceof En) {
let A = g;
if (this.processFunc) {
ea(f(s, gt));
try {
A = await this.processFunc(a, A);
} catch (w) {
(w.throttle == null || typeof w.stall != "number") && A.makeServerError("error in post-processing function", w).assertOk();
}
}
return A;
}
a = g;
}
this.preflightFunc && (a = await this.preflightFunc(a));
const o = await G0(a, ea(f(s, gt)));
let l = new En(o.statusCode, o.statusMessage, o.headers, o.body, s);
if (l.statusCode === 301 || l.statusCode === 302) {
try {
const g = l.headers.location || "";
return E(u = a.redirect(g), Jn, Ys).call(u, e + 1, t, 0, s, l);
} catch {
}
return l;
} else if (l.statusCode === 429 && (this.retryFunc == null || await this.retryFunc(a, l, e))) {
const g = l.headers["retry-after"];
let A = f(this, Bt).slotInterval * Math.trunc(Math.random() * Math.pow(2, e));
return typeof g == "string" && g.match(/^[1-9][0-9]*$/) && (A = parseInt(g)), E(d = a.clone(), Jn, Ys).call(d, e + 1, t, A, s, l);
}
if (this.processFunc) {
ea(f(s, gt));
try {
l = await this.processFunc(a, l);
} catch (g) {
(g.throttle == null || typeof g.stall != "number") && l.makeServerError("error in post-processing function", g).assertOk();
let A = f(this, Bt).slotInterval * Math.trunc(Math.random() * Math.pow(2, e));
return g.stall >= 0 && (A = g.stall), E(b = a.clone(), Jn, Ys).call(b, e + 1, t, A, s, l);
}
}
return l;
};
var Ei, Ii, Ni, tt, jr, Yn;
const S0 = class {
constructor(e, t, n, s, i) {
y(this, Ei, void 0);
y(this, Ii, void 0);
y(this, Ni, void 0);
y(this, tt, void 0);
y(this, jr, void 0);
y(this, Yn, void 0);
x(this, Ei, e), x(this, Ii, t), x(this, Ni, Object.keys(n).reduce((a, c) => (a[c.toLowerCase()] = String(n[c]), a), {})), x(this, tt, s == null ? null : new Uint8Array(s)), x(this, jr, i || null), x(this, Yn, { message: "" });
}
toString() {
return `<FetchResponse status=${this.statusCode} body=${f(this, tt) ? N(f(this, tt)) : "null"}>`;
}
/**
* The response status code.
*/
get statusCode() {
return f(this, Ei);
}
/**
* The response status message.
*/
get statusMessage() {
return f(this, Ii);
}
/**
* The response headers. All keys are lower-case.
*/
get headers() {
return Object.assign({}, f(this, Ni));
}
/**
* The response body, or ``null`` if there was no body.
*/
get body() {
return f(this, tt) == null ? null : new Uint8Array(f(this, tt));
}
/**
* The response body as a UTF-8 encoded string, or the empty
* string (i.e. ``""``) if there was no body.
*
* An error is thrown if the body is invalid UTF-8 data.
*/
get bodyText() {
try {
return f(this, tt) == null ? "" : u0(f(this, tt));
} catch {
m(!1, "response body is not valid UTF-8 data", "UNSUPPORTED_OPERATION", {
operation: "bodyText",
info: { response: this }
});
}
}
/**
* The response body, decoded as JSON.
*
* An error is thrown if the body is invalid JSON-encoded data
* or if there was no body.
*/
get bodyJson() {
try {
return JSON.parse(this.bodyText);
} catch {
m(!1, "response body is not valid JSON", "UNSUPPORTED_OPERATION", {
operation: "bodyJson",
info: { response: this }
});
}
}
[Symbol.iterator]() {
const e = this.headers, t = Object.keys(e);
let n = 0;
return {
next: () => {
if (n < t.length) {
const s = t[n++];
return {
value: [s, e[s]],
done: !1
};
}
return { value: void 0, done: !0 };
}
};
}
/**
* Return a Response with matching headers and body, but with
* an error status code (i.e. 599) and %%message%% with an
* optional %%error%%.
*/
makeServerError(e, t) {
let n;
e ? n = `CLIENT ESCALATED SERVER ERROR (${this.statusCode} ${this.statusMessage}; ${e})` : (e = `${this.statusCode} ${this.statusMessage}`, n = `CLIENT ESCALATED SERVER ERROR (${e})`);
const s = new S0(599, n, this.headers, this.body, f(this, jr) || void 0);
return x(s, Yn, { message: e, error: t }), s;
}
/**
* If called within a [request.processFunc](FetchRequest-processFunc)
* call, causes the request to retry as if throttled for %%stall%%
* milliseconds.
*/
throwThrottleError(e, t) {
t == null ? t = -1 : h(Number.isInteger(t) && t >= 0, "invalid stall timeout", "stall", t);
const n = new Error(e || "throttling requests");
throw P(n, { stall: t, throttle: !0 }), n;
}
/**
* Get the header value for %%key%%, ignoring case.
*/
getHeader(e) {
return this.headers[e.toLowerCase()];
}
/**
* Returns true of the response has a body.
*/
hasBody() {
return f(this, tt) != null;
}
/**
* The request made for this response.
*/
get request() {
return f(this, jr);
}
/**
* Returns true if this response was a success statusCode.
*/
ok() {
return f(this, Yn).message === "" && this.statusCode >= 200 && this.statusCode < 300;
}
/**
* Throws a ``SERVER_ERROR`` if this response is not ok.
*/
assertOk() {
if (this.ok())
return;
let { message: e, error: t } = f(this, Yn);
e === "" && (e = `server response ${this.statusCode} ${this.statusMessage}`), m(!1, e, "SERVER_ERROR", {
request: this.request || "unknown request",
response: this,
error: t
});
}
};
let En = S0;
Ei = new WeakMap(), Ii = new WeakMap(), Ni = new WeakMap(), tt = new WeakMap(), jr = new WeakMap(), Yn = new WeakMap();
function H0() {
return new Date().getTime();
}
function Ku(r) {
return Ee(r.replace(/%([0-9a-f][0-9a-f])/gi, (e, t) => String.fromCharCode(parseInt(t, 16))));
}
function zu(r) {
return new Promise((e) => setTimeout(e, r));
}
const Vu = BigInt(-1), Xe = BigInt(0), Lr = BigInt(1), Qu = BigInt(5), Tr = {};
let Gr = "0000";
for (; Gr.length < 80; )
Gr += Gr;
function Fn(r) {
let e = Gr;
for (; e.length < r; )
e += e;
return BigInt("1" + e.substring(0, r));
}
function Ks(r, e, t) {
const n = BigInt(e.width);
if (e.signed) {
const s = Lr << n - Lr;
m(t == null || r >= -s && r < s, "overflow", "NUMERIC_FAULT", {
operation: t,
fault: "overflow",
value: r
}), r > Xe ? r = ka(Hn(r, n), n) : r = -ka(Hn(-r, n), n);
} else {
const s = Lr << n;
m(t == null || r >= 0 && r < s, "overflow", "NUMERIC_FAULT", {
operation: t,
fault: "overflow",
value: r
}), r = (r % s + s) % s & s - Lr;
}
return r;
}
function cc(r) {
typeof r == "number" && (r = `fixed128x${r}`);
let e = !0, t = 128, n = 18;
if (typeof r == "string") {
if (r !== "fixed")
if (r === "ufixed")
e = !1;
else {
const i = r.match(/^(u?)fixed([0-9]+)x([0-9]+)$/);
h(i, "invalid fixed format", "format", r), e = i[1] !== "u", t = parseInt(i[2]), n = parseInt(i[3]);
}
} else if (r) {
const i = r, a = (c, o, l) => i[c] == null ? l : (h(typeof i[c] === o, "invalid fixed format (" + c + " not " + o + ")", "format." + c, i[c]), i[c]);
e = a("signed", "boolean", e), t = a("width", "number", t), n = a("decimals", "number", n);
}
h(t % 8 === 0, "invalid FixedNumber width (not byte aligned)", "format.width", t), h(n <= 80, "invalid FixedNumber decimals (too large)", "format.decimals", n);
const s = (e ? "" : "u") + "fixed" + String(t) + "x" + String(n);
return { signed: e, width: t, decimals: n, name: s };
}
function Ju(r, e) {
let t = "";
r < Xe && (t = "-", r *= Vu);
let n = r.toString();
if (e === 0)
return t + n;
for (; n.length <= e; )
n = Gr + n;
const s = n.length - e;
for (n = n.substring(0, s) + "." + n.substring(s); n[0] === "0" && n[1] !== "."; )
n = n.substring(1);
for (; n[n.length - 1] === "0" && n[n.length - 2] !== "."; )
n = n.substring(0, n.length - 1);
return t + n;
}
var nt, z, pe, Lt, Dn, rt, Ct, Ti, Pc, Ci, Oc, ki, Rc, Pi, Sc;
const rn = class {
// Use this when changing this file to get some typing info,
// but then switch to any to mask the internal type
//constructor(guard: any, value: bigint, format: _FixedFormat) {
/**
* @private
*/
constructor(e, t, n) {
y(this, Lt);
y(this, rt);
y(this, Ti);
y(this, Ci);
y(this, ki);
y(this, Pi);
/**
* The specific fixed-point arithmetic field for this value.
*/
p(this, "format");
y(this, nt, void 0);
// The actual value (accounting for decimals)
y(this, z, void 0);
// A base-10 value to multiple values by to maintain the magnitude
y(this, pe, void 0);
/**
* This is a property so console.log shows a human-meaningful value.
*
* @private
*/
p(this, "_value");
Cn(e, Tr, "FixedNumber"), x(this, z, t), x(this, nt, n);
const s = Ju(t, n.decimals);
P(this, { format: n.name, _value: s }), x(this, pe, Fn(n.decimals));
}
/**
* If true, negative values are permitted, otherwise only
* positive values and zero are allowed.
*/
get signed() {
return f(this, nt).signed;
}
/**
* The number of bits available to store the value.
*/
get width() {
return f(this, nt).width;
}
/**
* The number of decimal places in the fixed-point arithment field.
*/
get decimals() {
return f(this, nt).decimals;
}
/**
* The value as an integer, based on the smallest unit the
* [[decimals]] allow.
*/
get value() {
return f(this, z);
}
/**
* Returns a new [[FixedNumber]] with the result of %%this%% added
* to %%other%%, ignoring overflow.
*/
addUnsafe(e) {
return E(this, Ti, Pc).call(this, e);
}
/**
* Returns a new [[FixedNumber]] with the result of %%this%% added
* to %%other%%. A [[NumericFaultError]] is thrown if overflow
* occurs.
*/
add(e) {
return E(this, Ti, Pc).call(this, e, "add");
}
/**
* Returns a new [[FixedNumber]] with the result of %%other%% subtracted
* from %%this%%, ignoring overflow.
*/
subUnsafe(e) {
return E(this, Ci, Oc).call(this, e);
}
/**
* Returns a new [[FixedNumber]] with the result of %%other%% subtracted
* from %%this%%. A [[NumericFaultError]] is thrown if overflow
* occurs.
*/
sub(e) {
return E(this, Ci, Oc).call(this, e, "sub");
}
/**
* Returns a new [[FixedNumber]] with the result of %%this%% multiplied
* by %%other%%, ignoring overflow and underflow (precision loss).
*/
mulUnsafe(e) {
return E(this, ki, Rc).call(this, e);
}
/**
* Returns a new [[FixedNumber]] with the result of %%this%% multiplied
* by %%other%%. A [[NumericFaultError]] is thrown if overflow
* occurs.
*/
mul(e) {
return E(this, ki, Rc).call(this, e, "mul");
}
/**
* Returns a new [[FixedNumber]] with the result of %%this%% multiplied
* by %%other%%. A [[NumericFaultError]] is thrown if overflow
* occurs or if underflow (precision loss) occurs.
*/
mulSignal(e) {
E(this, Lt, Dn).call(this, e);
const t = f(this, z) * f(e, z);
return m(t % f(this, pe) === Xe, "precision lost during signalling mul", "NUMERIC_FAULT", {
operation: "mulSignal",
fault: "underflow",
value: this
}), E(this, rt, Ct).call(this, t / f(this, pe), "mulSignal");
}
/**
* Returns a new [[FixedNumber]] with the result of %%this%% divided
* by %%other%%, ignoring underflow (precision loss). A
* [[NumericFaultError]] is thrown if overflow occurs.
*/
divUnsafe(e) {
return E(this, Pi, Sc).call(this, e);
}
/**
* Returns a new [[FixedNumber]] with the result of %%this%% divided
* by %%other%%, ignoring underflow (precision loss). A
* [[NumericFaultError]] is thrown if overflow occurs.
*/
div(e) {
return E(this, Pi, Sc).call(this, e, "div");
}
/**
* Returns a new [[FixedNumber]] with the result of %%this%% divided
* by %%other%%. A [[NumericFaultError]] is thrown if underflow
* (precision loss) occurs.
*/
divSignal(e) {
m(f(e, z) !== Xe, "division by zero", "NUMERIC_FAULT", {
operation: "div",
fault: "divide-by-zero",
value: this
}), E(this, Lt, Dn).call(this, e);
const t = f(this, z) * f(this, pe);
return m(t % f(e, z) === Xe, "precision lost during signalling div", "NUMERIC_FAULT", {
operation: "divSignal",
fault: "underflow",
value: this
}), E(this, rt, Ct).call(this, t / f(e, z), "divSignal");
}
/**
* Returns a comparison result between %%this%% and %%other%%.
*
* This is suitable for use in sorting, where ``-1`` implies %%this%%
* is smaller, ``1`` implies %%other%% is larger and ``0`` implies
* both are equal.
*/
cmp(e) {
let t = this.value, n = e.value;
const s = this.decimals - e.decimals;
return s > 0 ? n *= Fn(s) : s < 0 && (t *= Fn(-s)), t < n || t > n ? -1 : 0;
}
/**
* Returns true if %%other%% is equal to %%this%%.
*/
eq(e) {
return this.cmp(e) === 0;
}
/**
* Returns true if %%other%% is less than to %%this%%.
*/
lt(e) {
return this.cmp(e) < 0;
}
/**
* Returns true if %%other%% is less than or equal to %%this%%.
*/
lte(e) {
return this.cmp(e) <= 0;
}
/**
* Returns true if %%other%% is greater than to %%this%%.
*/
gt(e) {
return this.cmp(e) > 0;
}
/**
* Returns true if %%other%% is greater than or equal to %%this%%.
*/
gte(e) {
return this.cmp(e) >= 0;
}
/**
* Returns a new [[FixedNumber]] which is the largest **integer**
* that is less than or equal to %%this%%.
*
* The decimal component of the result will always be ``0``.
*/
floor() {
let e = f(this, z);
return f(this, z) < Xe && (e -= f(this, pe) - Lr), e = f(this, z) / f(this, pe) * f(this, pe), E(this, rt, Ct).call(this, e, "floor");
}
/**
* Returns a new [[FixedNumber]] which is the smallest **integer**
* that is greater than or equal to %%this%%.
*
* The decimal component of the result will always be ``0``.
*/
ceiling() {
let e = f(this, z);
return f(this, z) > Xe && (e += f(this, pe) - Lr), e = f(this, z) / f(this, pe) * f(this, pe), E(this, rt, Ct).call(this, e, "ceiling");
}
/**
* Returns a new [[FixedNumber]] with the decimal component
* rounded up on ties at %%decimals%% places.
*/
round(e) {
if (e == null && (e = 0), e >= this.decimals)
return this;
const t = this.decimals - e, n = Qu * Fn(t - 1);
let s = this.value + n;
const i = Fn(t);
return s = s / i * i, Ks(s, f(this, nt), "round"), new rn(Tr, s, f(this, nt));
}
/**
* Returns true if %%this%% is equal to ``0``.
*/
isZero() {
return f(this, z) === Xe;
}
/**
* Returns true if %%this%% is less than ``0``.
*/
isNegative() {
return f(this, z) < Xe;
}
/**
* Returns the string representation of %%this%%.
*/
toString() {
return this._value;
}
/**
* Returns a float approximation.
*
* Due to IEEE 754 precission (or lack thereof), this function
* can only return an approximation and most values will contain
* rounding errors.
*/
toUnsafeFloat() {
return parseFloat(this.toString());
}
/**
* Return a new [[FixedNumber]] with the same value but has had
* its field set to %%format%%.
*
* This will throw if the value cannot fit into %%format%%.
*/
toFormat(e) {
return rn.fromString(this.toString(), e);
}
/**
* Creates a new [[FixedNumber]] for %%value%% divided by
* %%decimal%% places with %%format%%.
*
* This will throw a [[NumericFaultError]] if %%value%% (once adjusted
* for %%decimals%%) cannot fit in %%format%%, either due to overflow
* or underflow (precision loss).
*/
static fromValue(e, t, n) {
t == null && (t = 0);
const s = cc(n);
let i = S(e, "value");
const a = t - s.decimals;
if (a > 0) {
const c = Fn(a);
m(i % c === Xe, "value loses precision for format", "NUMERIC_FAULT", {
operation: "fromValue",
fault: "underflow",
value: e
}), i /= c;
} else
a < 0 && (i *= Fn(-a));
return Ks(i, s, "fromValue"), new rn(Tr, i, s);
}
/**
* Creates a new [[FixedNumber]] for %%value%% with %%format%%.
*
* This will throw a [[NumericFaultError]] if %%value%% cannot fit
* in %%format%%, either due to overflow or underflow (precision loss).
*/
static fromString(e, t) {
const n = e.match(/^(-?)([0-9]*)\.?([0-9]*)$/);
h(n && n[2].length + n[3].length > 0, "invalid FixedNumber string value", "value", e);
const s = cc(t);
let i = n[2] || "0", a = n[3] || "";
for (; a.length < s.decimals; )
a += Gr;
m(a.substring(s.decimals).match(/^0*$/), "too many decimals for format", "NUMERIC_FAULT", {
operation: "fromString",
fault: "underflow",
value: e
}), a = a.substring(0, s.decimals);
const c = BigInt(n[1] + i + a);
return Ks(c, s, "fromString"), new rn(Tr, c, s);
}
/**
* Creates a new [[FixedNumber]] with the big-endian representation
* %%value%% with %%format%%.
*
* This will throw a [[NumericFaultError]] if %%value%% cannot fit
* in %%format%% due to overflow.
*/
static fromBytes(e, t) {
let n = Ji(k(e, "value"));
const s = cc(t);
return s.signed && (n = ka(n, s.width)), Ks(n, s, "fromBytes"), new rn(Tr, n, s);
}
};
let kc = rn;
nt = new WeakMap(), z = new WeakMap(), pe = new WeakMap(), Lt = new WeakSet(), Dn = function(e) {
h(this.format === e.format, "incompatible format; use fixedNumber.toFormat", "other", e);
}, rt = new WeakSet(), Ct = function(e, t) {
return e = Ks(e, f(this, nt), t), new rn(Tr, e, f(this, nt));
}, Ti = new WeakSet(), Pc = function(e, t) {
return E(this, Lt, Dn).call(this, e), E(this, rt, Ct).call(this, f(this, z) + f(e, z), t);
}, Ci = new WeakSet(), Oc = function(e, t) {
return E(this, Lt, Dn).call(this, e), E(this, rt, Ct).call(this, f(this, z) - f(e, z), t);
}, ki = new WeakSet(), Rc = function(e, t) {
return E(this, Lt, Dn).call(this, e), E(this, rt, Ct).call(this, f(this, z) * f(e, z) / f(this, pe), t);
}, Pi = new WeakSet(), Sc = function(e, t) {
return m(f(e, z) !== Xe, "division by zero", "NUMERIC_FAULT", {
operation: "div",
fault: "divide-by-zero",
value: this
}), E(this, Lt, Dn).call(this, e), E(this, rt, Ct).call(this, f(this, z) * f(this, pe) / f(e, z), t);
};
function Yu(r) {
let e = r.toString(16);
for (; e.length < 2; )
e = "0" + e;
return "0x" + e;
}
function _0(r, e, t) {
let n = 0;
for (let s = 0; s < t; s++)
n = n * 256 + r[e + s];
return n;
}
function K0(r, e, t, n) {
const s = [];
for (; t < e + 1 + n; ) {
const i = If(r, t);
s.push(i.result), t += i.consumed, m(t <= e + 1 + n, "child data too short", "BUFFER_OVERRUN", {
buffer: r,
length: n,
offset: e
});
}
return { consumed: 1 + n, result: s };
}
function If(r, e) {
m(r.length !== 0, "data too short", "BUFFER_OVERRUN", {
buffer: r,
length: 0,
offset: 1
});
const t = (n) => {
m(n <= r.length, "data short segment too short", "BUFFER_OVERRUN", {
buffer: r,
length: r.length,
offset: n
});
};
if (r[e] >= 248) {
const n = r[e] - 247;
t(e + 1 + n);
const s = _0(r, e + 1, n);
return t(e + 1 + n + s), K0(r, e, e + 1 + n, n + s);
} else if (r[e] >= 192) {
const n = r[e] - 192;
return t(e + 1 + n), K0(r, e, e + 1, n);
} else if (r[e] >= 184) {
const n = r[e] - 183;
t(e + 1 + n);
const s = _0(r, e + 1, n);
t(e + 1 + n + s);
const i = N(r.slice(e + 1 + n, e + 1 + n + s));
return { consumed: 1 + n + s, result: i };
} else if (r[e] >= 128) {
const n = r[e] - 128;
t(e + 1 + n);
const s = N(r.slice(e + 1, e + 1 + n));
return { consumed: 1 + n, result: s };
}
return { consumed: 1, result: Yu(r[e]) };
}
function d0(r) {
const e = k(r, "data"), t = If(e, 0);
return h(t.consumed === e.length, "unexpected junk after rlp payload", "data", r), t.result;
}
function z0(r) {
const e = [];
for (; r; )
e.unshift(r & 255), r >>= 8;
return e;
}
function Nf(r) {
if (Array.isArray(r)) {
let n = [];
if (r.forEach(function(i) {
n = n.concat(Nf(i));
}), n.length <= 55)
return n.unshift(192 + n.length), n;
const s = z0(n.length);
return s.unshift(247 + s.length), s.concat(n);
}
const e = Array.prototype.slice.call(k(r, "object"));
if (e.length === 1 && e[0] <= 127)
return e;
if (e.length <= 55)
return e.unshift(128 + e.length), e;
const t = z0(e.length);
return t.unshift(183 + t.length), t.concat(e);
}
const V0 = "0123456789abcdef";
function oi(r) {
let e = "0x";
for (const t of Nf(r))
e += V0[t >> 4], e += V0[t & 15];
return e;
}
const $u = [
"wei",
"kwei",
"mwei",
"gwei",
"szabo",
"finney",
"ether"
];
function Wu(r, e) {
h(typeof r == "string", "value must be a string", "value", r);
let t = 18;
if (typeof e == "string") {
const n = $u.indexOf(e);
h(n >= 0, "invalid unit", "unit", e), t = 3 * n;
} else
e != null && (t = U(e, "unit"));
return kc.fromString(r, { decimals: t }).value;
}
function Q0(r) {
return Wu(r, 18);
}
function ju(r) {
const e = k(r, "randomBytes");
e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128;
const t = N(e);
return [
t.substring(2, 10),
t.substring(10, 14),
t.substring(14, 18),
t.substring(18, 22),
t.substring(22, 34)
].join("-");
}
const me = 32, vc = new Uint8Array(me), Zu = ["then"], ta = {};
function na(r, e) {
const t = new Error(`deferred error during ABI decoding triggered accessing ${r}`);
throw t.error = e, t;
}
var on;
const ai = class extends Array {
/**
* @private
*/
constructor(...t) {
const n = t[0];
let s = t[1], i = (t[2] || []).slice(), a = !0;
n !== ta && (s = t, i = [], a = !1);
super(s.length);
y(this, on, void 0);
s.forEach((o, l) => {
this[l] = o;
});
const c = i.reduce((o, l) => (typeof l == "string" && o.set(l, (o.get(l) || 0) + 1), o), /* @__PURE__ */ new Map());
if (x(this, on, Object.freeze(s.map((o, l) => {
const u = i[l];
return u != null && c.get(u) === 1 ? u : null;
}))), !!a)
return Object.freeze(this), new Proxy(this, {
get: (o, l, u) => {
if (typeof l == "string") {
if (l.match(/^[0-9]+$/)) {
const b = U(l, "%index");
if (b < 0 || b >= this.length)
throw new RangeError("out of result range")