hunt-mint-swap
Version:
A React component library for swapping MINT / HUNT buildings
1,331 lines • 2.44 MB
JavaScript
var lb = Object.defineProperty;
var ub = (et, tt, rt) => tt in et ? lb(et, tt, { enumerable: !0, configurable: !0, writable: !0, value: rt }) : et[tt] = rt;
var Nr = (et, tt, rt) => ub(et, typeof tt != "symbol" ? tt + "" : tt, rt);
import React, { useEffect, forwardRef, createElement, useMemo, useState, useRef } from "react";
import { ConnectButton, useConnectModal } from "@rainbow-me/rainbowkit";
import { useReadContract, useSimulateContract, useWriteContract, useWaitForTransactionReceipt, useBalance, useAccount, useSignTypedData, useWalletClient, useSendTransaction, useDisconnect, usePublicClient, useSwitchChain } from "wagmi";
import { erc20Abi, isAddress as isAddress$1, createWalletClient, custom, createPublicClient, fallback, http, formatUnits as formatUnits$1, keccak256 as keccak256$1, maxUint256 as maxUint256$1, stringToHex as stringToHex$1, hexToBytes as hexToBytes$2, getAddress, parseUnits, numberToHex as numberToHex$1, size as size$1, concat as concat$4 } from "viem";
import { createPortal } from "react-dom";
import { twMerge } from "tailwind-merge";
import { Sheet } from "react-modal-sheet";
import toast, { Toaster } from "react-hot-toast";
var commonjsGlobal = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
function getDefaultExportFromCjs(et) {
return et && et.__esModule && Object.prototype.hasOwnProperty.call(et, "default") ? et.default : et;
}
function getAugmentedNamespace(et) {
if (Object.prototype.hasOwnProperty.call(et, "__esModule")) return et;
var tt = et.default;
if (typeof tt == "function") {
var rt = function nt() {
return this instanceof nt ? Reflect.construct(tt, arguments, this.constructor) : tt.apply(this, arguments);
};
rt.prototype = tt.prototype;
} else rt = {};
return Object.defineProperty(rt, "__esModule", { value: !0 }), Object.keys(et).forEach(function(nt) {
var it = Object.getOwnPropertyDescriptor(et, nt);
Object.defineProperty(rt, nt, it.get ? it : {
enumerable: !0,
get: function() {
return et[nt];
}
});
}), rt;
}
var jsxRuntime = { exports: {} }, reactJsxRuntime_production = {};
/**
* @license React
* react-jsx-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var hasRequiredReactJsxRuntime_production;
function requireReactJsxRuntime_production() {
if (hasRequiredReactJsxRuntime_production) return reactJsxRuntime_production;
hasRequiredReactJsxRuntime_production = 1;
var et = Symbol.for("react.transitional.element"), tt = Symbol.for("react.fragment");
function rt(nt, it, st) {
var ot = null;
if (st !== void 0 && (ot = "" + st), it.key !== void 0 && (ot = "" + it.key), "key" in it) {
st = {};
for (var lt in it)
lt !== "key" && (st[lt] = it[lt]);
} else st = it;
return it = st.ref, {
$$typeof: et,
type: nt,
key: ot,
ref: it !== void 0 ? it : null,
props: st
};
}
return reactJsxRuntime_production.Fragment = tt, reactJsxRuntime_production.jsx = rt, reactJsxRuntime_production.jsxs = rt, reactJsxRuntime_production;
}
var reactJsxRuntime_development = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var hasRequiredReactJsxRuntime_development;
function requireReactJsxRuntime_development() {
return hasRequiredReactJsxRuntime_development || (hasRequiredReactJsxRuntime_development = 1, process.env.NODE_ENV !== "production" && function() {
function et(nr) {
if (nr == null) return null;
if (typeof nr == "function")
return nr.$$typeof === Ht ? null : nr.displayName || nr.name || null;
if (typeof nr == "string") return nr;
switch (nr) {
case Et:
return "Fragment";
case Ct:
return "Profiler";
case gt:
return "StrictMode";
case Dt:
return "Suspense";
case St:
return "SuspenseList";
case Pt:
return "Activity";
}
if (typeof nr == "object")
switch (typeof nr.tag == "number" && console.error(
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
), nr.$$typeof) {
case wt:
return "Portal";
case kt:
return (nr.displayName || "Context") + ".Provider";
case Bt:
return (nr._context.displayName || "Context") + ".Consumer";
case vt:
var Qt = nr.render;
return nr = nr.displayName, nr || (nr = Qt.displayName || Qt.name || "", nr = nr !== "" ? "ForwardRef(" + nr + ")" : "ForwardRef"), nr;
case Nt:
return Qt = nr.displayName || null, Qt !== null ? Qt : et(nr.type) || "Memo";
case Ot:
Qt = nr._payload, nr = nr._init;
try {
return et(nr(Qt));
} catch {
}
}
return null;
}
function tt(nr) {
return "" + nr;
}
function rt(nr) {
try {
tt(nr);
var Qt = !1;
} catch {
Qt = !0;
}
if (Qt) {
Qt = console;
var fr = Qt.error, Er = typeof Symbol == "function" && Symbol.toStringTag && nr[Symbol.toStringTag] || nr.constructor.name || "Object";
return fr.call(
Qt,
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
Er
), tt(nr);
}
}
function nt(nr) {
if (nr === Et) return "<>";
if (typeof nr == "object" && nr !== null && nr.$$typeof === Ot)
return "<...>";
try {
var Qt = et(nr);
return Qt ? "<" + Qt + ">" : "<...>";
} catch {
return "<...>";
}
}
function it() {
var nr = Lt.A;
return nr === null ? null : nr.getOwner();
}
function st() {
return Error("react-stack-top-frame");
}
function ot(nr) {
if (Vt.call(nr, "key")) {
var Qt = Object.getOwnPropertyDescriptor(nr, "key").get;
if (Qt && Qt.isReactWarning) return !1;
}
return nr.key !== void 0;
}
function lt(nr, Qt) {
function fr() {
Gt || (Gt = !0, console.error(
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
Qt
));
}
fr.isReactWarning = !0, Object.defineProperty(nr, "key", {
get: fr,
configurable: !0
});
}
function dt() {
var nr = et(this.type);
return Xt[nr] || (Xt[nr] = !0, console.error(
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
)), nr = this.props.ref, nr !== void 0 ? nr : null;
}
function pt(nr, Qt, fr, Er, tr, Pr, rr, pr) {
return fr = Pr.ref, nr = {
$$typeof: xt,
type: nr,
key: Qt,
props: Pr,
_owner: tr
}, (fr !== void 0 ? fr : null) !== null ? Object.defineProperty(nr, "ref", {
enumerable: !1,
get: dt
}) : Object.defineProperty(nr, "ref", { enumerable: !1, value: null }), nr._store = {}, Object.defineProperty(nr._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: 0
}), Object.defineProperty(nr, "_debugInfo", {
configurable: !1,
enumerable: !1,
writable: !0,
value: null
}), Object.defineProperty(nr, "_debugStack", {
configurable: !1,
enumerable: !1,
writable: !0,
value: rr
}), Object.defineProperty(nr, "_debugTask", {
configurable: !1,
enumerable: !1,
writable: !0,
value: pr
}), Object.freeze && (Object.freeze(nr.props), Object.freeze(nr)), nr;
}
function ht(nr, Qt, fr, Er, tr, Pr, rr, pr) {
var mr = Qt.children;
if (mr !== void 0)
if (Er)
if (ir(mr)) {
for (Er = 0; Er < mr.length; Er++)
yt(mr[Er]);
Object.freeze && Object.freeze(mr);
} else
console.error(
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
);
else yt(mr);
if (Vt.call(Qt, "key")) {
mr = et(nr);
var Rr = Object.keys(Qt).filter(function(Wt) {
return Wt !== "key";
});
Er = 0 < Rr.length ? "{key: someKey, " + Rr.join(": ..., ") + ": ...}" : "{key: someKey}", Dr[mr + Er] || (Rr = 0 < Rr.length ? "{" + Rr.join(": ..., ") + ": ...}" : "{}", console.error(
`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,
Er,
mr,
Rr,
mr
), Dr[mr + Er] = !0);
}
if (mr = null, fr !== void 0 && (rt(fr), mr = "" + fr), ot(Qt) && (rt(Qt.key), mr = "" + Qt.key), "key" in Qt) {
fr = {};
for (var Ur in Qt)
Ur !== "key" && (fr[Ur] = Qt[Ur]);
} else fr = Qt;
return mr && lt(
fr,
typeof nr == "function" ? nr.displayName || nr.name || "Unknown" : nr
), pt(
nr,
mr,
Pr,
tr,
it(),
fr,
rr,
pr
);
}
function yt(nr) {
typeof nr == "object" && nr !== null && nr.$$typeof === xt && nr._store && (nr._store.validated = 1);
}
var mt = React, xt = Symbol.for("react.transitional.element"), wt = Symbol.for("react.portal"), Et = Symbol.for("react.fragment"), gt = Symbol.for("react.strict_mode"), Ct = Symbol.for("react.profiler"), Bt = Symbol.for("react.consumer"), kt = Symbol.for("react.context"), vt = Symbol.for("react.forward_ref"), Dt = Symbol.for("react.suspense"), St = Symbol.for("react.suspense_list"), Nt = Symbol.for("react.memo"), Ot = Symbol.for("react.lazy"), Pt = Symbol.for("react.activity"), Ht = Symbol.for("react.client.reference"), Lt = mt.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, Vt = Object.prototype.hasOwnProperty, ir = Array.isArray, Jt = console.createTask ? console.createTask : function() {
return null;
};
mt = {
"react-stack-bottom-frame": function(nr) {
return nr();
}
};
var Gt, Xt = {}, wr = mt["react-stack-bottom-frame"].bind(
mt,
st
)(), dr = Jt(nt(st)), Dr = {};
reactJsxRuntime_development.Fragment = Et, reactJsxRuntime_development.jsx = function(nr, Qt, fr, Er, tr) {
var Pr = 1e4 > Lt.recentlyCreatedOwnerStacks++;
return ht(
nr,
Qt,
fr,
!1,
Er,
tr,
Pr ? Error("react-stack-top-frame") : wr,
Pr ? Jt(nt(nr)) : dr
);
}, reactJsxRuntime_development.jsxs = function(nr, Qt, fr, Er, tr) {
var Pr = 1e4 > Lt.recentlyCreatedOwnerStacks++;
return ht(
nr,
Qt,
fr,
!0,
Er,
tr,
Pr ? Error("react-stack-top-frame") : wr,
Pr ? Jt(nt(nr)) : dr
);
};
}()), reactJsxRuntime_development;
}
var hasRequiredJsxRuntime;
function requireJsxRuntime() {
return hasRequiredJsxRuntime || (hasRequiredJsxRuntime = 1, process.env.NODE_ENV === "production" ? jsxRuntime.exports = requireReactJsxRuntime_production() : jsxRuntime.exports = requireReactJsxRuntime_development()), jsxRuntime.exports;
}
var jsxRuntimeExports = requireJsxRuntime();
function defineChain(et) {
return {
formatters: void 0,
fees: void 0,
serializers: void 0,
...et
};
}
const abey = /* @__PURE__ */ defineChain({
id: 179,
name: "ABEY Mainnet",
nativeCurrency: { name: "ABEY", symbol: "ABEY", decimals: 18 },
rpcUrls: {
default: {
http: ["https://rpc.abeychain.com"]
}
},
blockExplorers: {
default: {
name: "Abey Scan",
url: "https://abeyscan.com"
}
},
testnet: !1
}), version$3 = "2.29.4";
let errorConfig = {
getDocsUrl: ({ docsBaseUrl: et, docsPath: tt = "", docsSlug: rt }) => tt ? `${et ?? "https://viem.sh"}${tt}${rt ? `#${rt}` : ""}` : void 0,
version: `viem@${version$3}`
}, BaseError$1 = class ql extends Error {
constructor(tt, rt = {}) {
var lt;
const nt = (() => {
var dt;
return rt.cause instanceof ql ? rt.cause.details : (dt = rt.cause) != null && dt.message ? rt.cause.message : rt.details;
})(), it = rt.cause instanceof ql && rt.cause.docsPath || rt.docsPath, st = (lt = errorConfig.getDocsUrl) == null ? void 0 : lt.call(errorConfig, { ...rt, docsPath: it }), ot = [
tt || "An error occurred.",
"",
...rt.metaMessages ? [...rt.metaMessages, ""] : [],
...st ? [`Docs: ${st}`] : [],
...nt ? [`Details: ${nt}`] : [],
...errorConfig.version ? [`Version: ${errorConfig.version}`] : []
].join(`
`);
super(ot, rt.cause ? { cause: rt.cause } : void 0), Object.defineProperty(this, "details", {
enumerable: !0,
configurable: !0,
writable: !0,
value: void 0
}), Object.defineProperty(this, "docsPath", {
enumerable: !0,
configurable: !0,
writable: !0,
value: void 0
}), Object.defineProperty(this, "metaMessages", {
enumerable: !0,
configurable: !0,
writable: !0,
value: void 0
}), Object.defineProperty(this, "shortMessage", {
enumerable: !0,
configurable: !0,
writable: !0,
value: void 0
}), Object.defineProperty(this, "version", {
enumerable: !0,
configurable: !0,
writable: !0,
value: void 0
}), Object.defineProperty(this, "name", {
enumerable: !0,
configurable: !0,
writable: !0,
value: "BaseError"
}), this.details = nt, this.docsPath = it, this.metaMessages = rt.metaMessages, this.name = rt.name ?? this.name, this.shortMessage = tt, this.version = version$3;
}
walk(tt) {
return walk$1(this, tt);
}
};
function walk$1(et, tt) {
return tt != null && tt(et) ? et : et && typeof et == "object" && "cause" in et && et.cause !== void 0 ? walk$1(et.cause, tt) : tt ? null : et;
}
class IntegerOutOfRangeError extends BaseError$1 {
constructor({ max: tt, min: rt, signed: nt, size: it, value: st }) {
super(`Number "${st}" is not in safe ${it ? `${it * 8}-bit ${nt ? "signed" : "unsigned"} ` : ""}integer range ${tt ? `(${rt} to ${tt})` : `(above ${rt})`}`, { name: "IntegerOutOfRangeError" });
}
}
class SizeOverflowError extends BaseError$1 {
constructor({ givenSize: tt, maxSize: rt }) {
super(`Size cannot exceed ${rt} bytes. Given size: ${tt} bytes.`, { name: "SizeOverflowError" });
}
}
function isHex(et, { strict: tt = !0 } = {}) {
return !et || typeof et != "string" ? !1 : tt ? /^0x[0-9a-fA-F]*$/.test(et) : et.startsWith("0x");
}
function size(et) {
return isHex(et, { strict: !1 }) ? Math.ceil((et.length - 2) / 2) : et.length;
}
function trim(et, { dir: tt = "left" } = {}) {
let rt = typeof et == "string" ? et.replace("0x", "") : et, nt = 0;
for (let it = 0; it < rt.length - 1 && rt[tt === "left" ? it : rt.length - it - 1].toString() === "0"; it++)
nt++;
return rt = tt === "left" ? rt.slice(nt) : rt.slice(0, rt.length - nt), typeof et == "string" ? (rt.length === 1 && tt === "right" && (rt = `${rt}0`), `0x${rt.length % 2 === 1 ? `0${rt}` : rt}`) : rt;
}
class SliceOffsetOutOfBoundsError extends BaseError$1 {
constructor({ offset: tt, position: rt, size: nt }) {
super(`Slice ${rt === "start" ? "starting" : "ending"} at offset "${tt}" is out-of-bounds (size: ${nt}).`, { name: "SliceOffsetOutOfBoundsError" });
}
}
class SizeExceedsPaddingSizeError extends BaseError$1 {
constructor({ size: tt, targetSize: rt, type: nt }) {
super(`${nt.charAt(0).toUpperCase()}${nt.slice(1).toLowerCase()} size (${tt}) exceeds padding size (${rt}).`, { name: "SizeExceedsPaddingSizeError" });
}
}
function pad(et, { dir: tt, size: rt = 32 } = {}) {
return typeof et == "string" ? padHex(et, { dir: tt, size: rt }) : padBytes(et, { dir: tt, size: rt });
}
function padHex(et, { dir: tt, size: rt = 32 } = {}) {
if (rt === null)
return et;
const nt = et.replace("0x", "");
if (nt.length > rt * 2)
throw new SizeExceedsPaddingSizeError({
size: Math.ceil(nt.length / 2),
targetSize: rt,
type: "hex"
});
return `0x${nt[tt === "right" ? "padEnd" : "padStart"](rt * 2, "0")}`;
}
function padBytes(et, { dir: tt, size: rt = 32 } = {}) {
if (rt === null)
return et;
if (et.length > rt)
throw new SizeExceedsPaddingSizeError({
size: et.length,
targetSize: rt,
type: "bytes"
});
const nt = new Uint8Array(rt);
for (let it = 0; it < rt; it++) {
const st = tt === "right";
nt[st ? it : rt - it - 1] = et[st ? it : et.length - it - 1];
}
return nt;
}
const hexes$1 = /* @__PURE__ */ Array.from({ length: 256 }, (et, tt) => tt.toString(16).padStart(2, "0"));
function toHex$1(et, tt = {}) {
return typeof et == "number" || typeof et == "bigint" ? numberToHex(et, tt) : typeof et == "string" ? stringToHex(et, tt) : typeof et == "boolean" ? boolToHex(et, tt) : bytesToHex$1(et, tt);
}
function boolToHex(et, tt = {}) {
const rt = `0x${Number(et)}`;
return typeof tt.size == "number" ? (assertSize(rt, { size: tt.size }), pad(rt, { size: tt.size })) : rt;
}
function bytesToHex$1(et, tt = {}) {
let rt = "";
for (let it = 0; it < et.length; it++)
rt += hexes$1[et[it]];
const nt = `0x${rt}`;
return typeof tt.size == "number" ? (assertSize(nt, { size: tt.size }), pad(nt, { dir: "right", size: tt.size })) : nt;
}
function numberToHex(et, tt = {}) {
const { signed: rt, size: nt } = tt, it = BigInt(et);
let st;
nt ? rt ? st = (1n << BigInt(nt) * 8n - 1n) - 1n : st = 2n ** (BigInt(nt) * 8n) - 1n : typeof et == "number" && (st = BigInt(Number.MAX_SAFE_INTEGER));
const ot = typeof st == "bigint" && rt ? -st - 1n : 0;
if (st && it > st || it < ot) {
const dt = typeof et == "bigint" ? "n" : "";
throw new IntegerOutOfRangeError({
max: st ? `${st}${dt}` : void 0,
min: `${ot}${dt}`,
signed: rt,
size: nt,
value: `${et}${dt}`
});
}
const lt = `0x${(rt && it < 0 ? (1n << BigInt(nt * 8)) + BigInt(it) : it).toString(16)}`;
return nt ? pad(lt, { size: nt }) : lt;
}
const encoder$1 = /* @__PURE__ */ new TextEncoder();
function stringToHex(et, tt = {}) {
const rt = encoder$1.encode(et);
return bytesToHex$1(rt, tt);
}
const encoder = /* @__PURE__ */ new TextEncoder();
function toBytes$2(et, tt = {}) {
return typeof et == "number" || typeof et == "bigint" ? numberToBytes(et, tt) : typeof et == "boolean" ? boolToBytes(et, tt) : isHex(et) ? hexToBytes$1(et, tt) : stringToBytes(et, tt);
}
function boolToBytes(et, tt = {}) {
const rt = new Uint8Array(1);
return rt[0] = Number(et), typeof tt.size == "number" ? (assertSize(rt, { size: tt.size }), pad(rt, { size: tt.size })) : rt;
}
const charCodeMap = {
zero: 48,
nine: 57,
A: 65,
F: 70,
a: 97,
f: 102
};
function charCodeToBase16(et) {
if (et >= charCodeMap.zero && et <= charCodeMap.nine)
return et - charCodeMap.zero;
if (et >= charCodeMap.A && et <= charCodeMap.F)
return et - (charCodeMap.A - 10);
if (et >= charCodeMap.a && et <= charCodeMap.f)
return et - (charCodeMap.a - 10);
}
function hexToBytes$1(et, tt = {}) {
let rt = et;
tt.size && (assertSize(rt, { size: tt.size }), rt = pad(rt, { dir: "right", size: tt.size }));
let nt = rt.slice(2);
nt.length % 2 && (nt = `0${nt}`);
const it = nt.length / 2, st = new Uint8Array(it);
for (let ot = 0, lt = 0; ot < it; ot++) {
const dt = charCodeToBase16(nt.charCodeAt(lt++)), pt = charCodeToBase16(nt.charCodeAt(lt++));
if (dt === void 0 || pt === void 0)
throw new BaseError$1(`Invalid byte sequence ("${nt[lt - 2]}${nt[lt - 1]}" in "${nt}").`);
st[ot] = dt * 16 + pt;
}
return st;
}
function numberToBytes(et, tt) {
const rt = numberToHex(et, tt);
return hexToBytes$1(rt);
}
function stringToBytes(et, tt = {}) {
const rt = encoder.encode(et);
return typeof tt.size == "number" ? (assertSize(rt, { size: tt.size }), pad(rt, { dir: "right", size: tt.size })) : rt;
}
function assertSize(et, { size: tt }) {
if (size(et) > tt)
throw new SizeOverflowError({
givenSize: size(et),
maxSize: tt
});
}
function hexToBigInt(et, tt = {}) {
const { signed: rt } = tt;
tt.size && assertSize(et, { size: tt.size });
const nt = BigInt(et);
if (!rt)
return nt;
const it = (et.length - 2) / 2, st = (1n << BigInt(it) * 8n - 1n) - 1n;
return nt <= st ? nt : nt - BigInt(`0x${"f".padStart(it * 2, "f")}`) - 1n;
}
function hexToNumber$1(et, tt = {}) {
return Number(hexToBigInt(et, tt));
}
function defineFormatter(et, tt) {
return ({ exclude: rt, format: nt }) => ({
exclude: rt,
format: (it) => {
const st = tt(it);
if (rt)
for (const ot of rt)
delete st[ot];
return {
...st,
...nt(it)
};
},
type: et
});
}
const transactionType = {
"0x0": "legacy",
"0x1": "eip2930",
"0x2": "eip1559",
"0x3": "eip4844",
"0x4": "eip7702"
};
function formatTransaction(et) {
const tt = {
...et,
blockHash: et.blockHash ? et.blockHash : null,
blockNumber: et.blockNumber ? BigInt(et.blockNumber) : null,
chainId: et.chainId ? hexToNumber$1(et.chainId) : void 0,
gas: et.gas ? BigInt(et.gas) : void 0,
gasPrice: et.gasPrice ? BigInt(et.gasPrice) : void 0,
maxFeePerBlobGas: et.maxFeePerBlobGas ? BigInt(et.maxFeePerBlobGas) : void 0,
maxFeePerGas: et.maxFeePerGas ? BigInt(et.maxFeePerGas) : void 0,
maxPriorityFeePerGas: et.maxPriorityFeePerGas ? BigInt(et.maxPriorityFeePerGas) : void 0,
nonce: et.nonce ? hexToNumber$1(et.nonce) : void 0,
to: et.to ? et.to : null,
transactionIndex: et.transactionIndex ? Number(et.transactionIndex) : null,
type: et.type ? transactionType[et.type] : void 0,
typeHex: et.type ? et.type : void 0,
value: et.value ? BigInt(et.value) : void 0,
v: et.v ? BigInt(et.v) : void 0
};
return et.authorizationList && (tt.authorizationList = formatAuthorizationList$1(et.authorizationList)), tt.yParity = (() => {
if (et.yParity)
return Number(et.yParity);
if (typeof tt.v == "bigint") {
if (tt.v === 0n || tt.v === 27n)
return 0;
if (tt.v === 1n || tt.v === 28n)
return 1;
if (tt.v >= 35n)
return tt.v % 2n === 0n ? 1 : 0;
}
})(), tt.type === "legacy" && (delete tt.accessList, delete tt.maxFeePerBlobGas, delete tt.maxFeePerGas, delete tt.maxPriorityFeePerGas, delete tt.yParity), tt.type === "eip2930" && (delete tt.maxFeePerBlobGas, delete tt.maxFeePerGas, delete tt.maxPriorityFeePerGas), tt.type === "eip1559" && delete tt.maxFeePerBlobGas, tt;
}
const defineTransaction = /* @__PURE__ */ defineFormatter("transaction", formatTransaction);
function formatAuthorizationList$1(et) {
return et.map((tt) => ({
address: tt.address,
chainId: Number(tt.chainId),
nonce: Number(tt.nonce),
r: tt.r,
s: tt.s,
yParity: Number(tt.yParity)
}));
}
function formatBlock(et) {
const tt = (et.transactions ?? []).map((rt) => typeof rt == "string" ? rt : formatTransaction(rt));
return {
...et,
baseFeePerGas: et.baseFeePerGas ? BigInt(et.baseFeePerGas) : null,
blobGasUsed: et.blobGasUsed ? BigInt(et.blobGasUsed) : void 0,
difficulty: et.difficulty ? BigInt(et.difficulty) : void 0,
excessBlobGas: et.excessBlobGas ? BigInt(et.excessBlobGas) : void 0,
gasLimit: et.gasLimit ? BigInt(et.gasLimit) : void 0,
gasUsed: et.gasUsed ? BigInt(et.gasUsed) : void 0,
hash: et.hash ? et.hash : null,
logsBloom: et.logsBloom ? et.logsBloom : null,
nonce: et.nonce ? et.nonce : null,
number: et.number ? BigInt(et.number) : null,
size: et.size ? BigInt(et.size) : void 0,
timestamp: et.timestamp ? BigInt(et.timestamp) : void 0,
transactions: tt,
totalDifficulty: et.totalDifficulty ? BigInt(et.totalDifficulty) : null
};
}
const defineBlock = /* @__PURE__ */ defineFormatter("block", formatBlock);
function formatLog(et, { args: tt, eventName: rt } = {}) {
return {
...et,
blockHash: et.blockHash ? et.blockHash : null,
blockNumber: et.blockNumber ? BigInt(et.blockNumber) : null,
logIndex: et.logIndex ? Number(et.logIndex) : null,
transactionHash: et.transactionHash ? et.transactionHash : null,
transactionIndex: et.transactionIndex ? Number(et.transactionIndex) : null,
...rt ? { args: tt, eventName: rt } : {}
};
}
const receiptStatuses = {
"0x0": "reverted",
"0x1": "success"
};
function formatTransactionReceipt(et) {
const tt = {
...et,
blockNumber: et.blockNumber ? BigInt(et.blockNumber) : null,
contractAddress: et.contractAddress ? et.contractAddress : null,
cumulativeGasUsed: et.cumulativeGasUsed ? BigInt(et.cumulativeGasUsed) : null,
effectiveGasPrice: et.effectiveGasPrice ? BigInt(et.effectiveGasPrice) : null,
gasUsed: et.gasUsed ? BigInt(et.gasUsed) : null,
logs: et.logs ? et.logs.map((rt) => formatLog(rt)) : null,
to: et.to ? et.to : null,
transactionIndex: et.transactionIndex ? hexToNumber$1(et.transactionIndex) : null,
status: et.status ? receiptStatuses[et.status] : null,
type: et.type ? transactionType[et.type] || et.type : null
};
return et.blobGasPrice && (tt.blobGasPrice = BigInt(et.blobGasPrice)), et.blobGasUsed && (tt.blobGasUsed = BigInt(et.blobGasUsed)), tt;
}
const defineTransactionReceipt = /* @__PURE__ */ defineFormatter("transactionReceipt", formatTransactionReceipt), rpcTransactionType = {
legacy: "0x0",
eip2930: "0x1",
eip1559: "0x2",
eip4844: "0x3",
eip7702: "0x4"
};
function formatTransactionRequest(et) {
const tt = {};
return typeof et.authorizationList < "u" && (tt.authorizationList = formatAuthorizationList(et.authorizationList)), typeof et.accessList < "u" && (tt.accessList = et.accessList), typeof et.blobVersionedHashes < "u" && (tt.blobVersionedHashes = et.blobVersionedHashes), typeof et.blobs < "u" && (typeof et.blobs[0] != "string" ? tt.blobs = et.blobs.map((rt) => bytesToHex$1(rt)) : tt.blobs = et.blobs), typeof et.data < "u" && (tt.data = et.data), typeof et.from < "u" && (tt.from = et.from), typeof et.gas < "u" && (tt.gas = numberToHex(et.gas)), typeof et.gasPrice < "u" && (tt.gasPrice = numberToHex(et.gasPrice)), typeof et.maxFeePerBlobGas < "u" && (tt.maxFeePerBlobGas = numberToHex(et.maxFeePerBlobGas)), typeof et.maxFeePerGas < "u" && (tt.maxFeePerGas = numberToHex(et.maxFeePerGas)), typeof et.maxPriorityFeePerGas < "u" && (tt.maxPriorityFeePerGas = numberToHex(et.maxPriorityFeePerGas)), typeof et.nonce < "u" && (tt.nonce = numberToHex(et.nonce)), typeof et.to < "u" && (tt.to = et.to), typeof et.type < "u" && (tt.type = rpcTransactionType[et.type]), typeof et.value < "u" && (tt.value = numberToHex(et.value)), tt;
}
const defineTransactionRequest = /* @__PURE__ */ defineFormatter("transactionRequest", formatTransactionRequest);
function formatAuthorizationList(et) {
return et.map((tt) => ({
address: tt.address,
r: tt.r ? numberToHex(BigInt(tt.r)) : tt.r,
s: tt.s ? numberToHex(BigInt(tt.s)) : tt.s,
chainId: numberToHex(tt.chainId),
nonce: numberToHex(tt.nonce),
...typeof tt.yParity < "u" ? { yParity: numberToHex(tt.yParity) } : {},
...typeof tt.v < "u" && typeof tt.yParity > "u" ? { v: numberToHex(tt.v) } : {}
}));
}
const maxUint16 = 2n ** 16n - 1n, maxUint256 = 2n ** 256n - 1n, gasPerPubdataDefault = 50000n, maxBytecodeSize = maxUint16 * 32n, formatters$2 = {
block: /* @__PURE__ */ defineBlock({
format(et) {
var rt;
const tt = (rt = et.transactions) == null ? void 0 : rt.map((nt) => {
var st;
if (typeof nt == "string")
return nt;
const it = (st = formatters$2.transaction) == null ? void 0 : st.format(nt);
return it.typeHex === "0x71" ? it.type = "eip712" : it.typeHex === "0xff" && (it.type = "priority"), it;
});
return {
l1BatchNumber: et.l1BatchNumber ? hexToBigInt(et.l1BatchNumber) : null,
l1BatchTimestamp: et.l1BatchTimestamp ? hexToBigInt(et.l1BatchTimestamp) : null,
transactions: tt
};
}
}),
transaction: /* @__PURE__ */ defineTransaction({
format(et) {
const tt = {};
return et.type === "0x71" ? tt.type = "eip712" : et.type === "0xff" && (tt.type = "priority"), {
...tt,
l1BatchNumber: et.l1BatchNumber ? hexToBigInt(et.l1BatchNumber) : null,
l1BatchTxIndex: et.l1BatchTxIndex ? hexToBigInt(et.l1BatchTxIndex) : null
};
}
}),
transactionReceipt: /* @__PURE__ */ defineTransactionReceipt({
format(et) {
return {
l1BatchNumber: et.l1BatchNumber ? hexToBigInt(et.l1BatchNumber) : null,
l1BatchTxIndex: et.l1BatchTxIndex ? hexToBigInt(et.l1BatchTxIndex) : null,
logs: et.logs.map((tt) => ({
...formatLog(tt),
l1BatchNumber: tt.l1BatchNumber ? hexToBigInt(tt.l1BatchNumber) : null,
transactionLogIndex: hexToNumber$1(tt.transactionLogIndex),
logType: tt.logType
})),
l2ToL1Logs: et.l2ToL1Logs.map((tt) => ({
blockNumber: hexToBigInt(tt.blockHash),
blockHash: tt.blockHash,
l1BatchNumber: tt.l1BatchNumber ? hexToBigInt(tt.l1BatchNumber) : null,
transactionIndex: hexToBigInt(tt.transactionIndex),
shardId: hexToBigInt(tt.shardId),
isService: tt.isService,
sender: tt.sender,
key: tt.key,
value: tt.value,
transactionHash: tt.transactionHash,
logIndex: hexToBigInt(tt.logIndex)
}))
};
}
}),
transactionRequest: /* @__PURE__ */ defineTransactionRequest({
exclude: [
"customSignature",
"factoryDeps",
"gasPerPubdata",
"paymaster",
"paymasterInput"
],
format(et) {
return et.gasPerPubdata || et.paymaster && et.paymasterInput || et.factoryDeps || et.customSignature ? {
eip712Meta: {
...et.gasPerPubdata ? { gasPerPubdata: toHex$1(et.gasPerPubdata) } : { gasPerPubdata: toHex$1(gasPerPubdataDefault) },
...et.paymaster && et.paymasterInput ? {
paymasterParams: {
paymaster: et.paymaster,
paymasterInput: Array.from(hexToBytes$1(et.paymasterInput))
}
} : {},
...et.factoryDeps ? {
factoryDeps: et.factoryDeps.map((tt) => Array.from(hexToBytes$1(tt)))
} : {},
...et.customSignature ? {
customSignature: Array.from(hexToBytes$1(et.customSignature))
} : {}
},
type: "0x71"
} : {};
}
})
};
function concat$3(et) {
return typeof et[0] == "string" ? concatHex(et) : concatBytes$2(et);
}
function concatBytes$2(et) {
let tt = 0;
for (const it of et)
tt += it.length;
const rt = new Uint8Array(tt);
let nt = 0;
for (const it of et)
rt.set(it, nt), nt += it.length;
return rt;
}
function concatHex(et) {
return `0x${et.reduce((tt, rt) => tt + rt.replace("0x", ""), "")}`;
}
class NegativeOffsetError extends BaseError$1 {
constructor({ offset: tt }) {
super(`Offset \`${tt}\` cannot be negative.`, {
name: "NegativeOffsetError"
});
}
}
class PositionOutOfBoundsError extends BaseError$1 {
constructor({ length: tt, position: rt }) {
super(`Position \`${rt}\` is out of bounds (\`0 < position < ${tt}\`).`, { name: "PositionOutOfBoundsError" });
}
}
class RecursiveReadLimitExceededError extends BaseError$1 {
constructor({ count: tt, limit: rt }) {
super(`Recursive read limit of \`${rt}\` exceeded (recursive read count: \`${tt}\`).`, { name: "RecursiveReadLimitExceededError" });
}
}
const staticCursor = {
bytes: new Uint8Array(),
dataView: new DataView(new ArrayBuffer(0)),
position: 0,
positionReadCount: /* @__PURE__ */ new Map(),
recursiveReadCount: 0,
recursiveReadLimit: Number.POSITIVE_INFINITY,
assertReadLimit() {
if (this.recursiveReadCount >= this.recursiveReadLimit)
throw new RecursiveReadLimitExceededError({
count: this.recursiveReadCount + 1,
limit: this.recursiveReadLimit
});
},
assertPosition(et) {
if (et < 0 || et > this.bytes.length - 1)
throw new PositionOutOfBoundsError({
length: this.bytes.length,
position: et
});
},
decrementPosition(et) {
if (et < 0)
throw new NegativeOffsetError({ offset: et });
const tt = this.position - et;
this.assertPosition(tt), this.position = tt;
},
getReadCount(et) {
return this.positionReadCount.get(et || this.position) || 0;
},
incrementPosition(et) {
if (et < 0)
throw new NegativeOffsetError({ offset: et });
const tt = this.position + et;
this.assertPosition(tt), this.position = tt;
},
inspectByte(et) {
const tt = et ?? this.position;
return this.assertPosition(tt), this.bytes[tt];
},
inspectBytes(et, tt) {
const rt = tt ?? this.position;
return this.assertPosition(rt + et - 1), this.bytes.subarray(rt, rt + et);
},
inspectUint8(et) {
const tt = et ?? this.position;
return this.assertPosition(tt), this.bytes[tt];
},
inspectUint16(et) {
const tt = et ?? this.position;
return this.assertPosition(tt + 1), this.dataView.getUint16(tt);
},
inspectUint24(et) {
const tt = et ?? this.position;
return this.assertPosition(tt + 2), (this.dataView.getUint16(tt) << 8) + this.dataView.getUint8(tt + 2);
},
inspectUint32(et) {
const tt = et ?? this.position;
return this.assertPosition(tt + 3), this.dataView.getUint32(tt);
},
pushByte(et) {
this.assertPosition(this.position), this.bytes[this.position] = et, this.position++;
},
pushBytes(et) {
this.assertPosition(this.position + et.length - 1), this.bytes.set(et, this.position), this.position += et.length;
},
pushUint8(et) {
this.assertPosition(this.position), this.bytes[this.position] = et, this.position++;
},
pushUint16(et) {
this.assertPosition(this.position + 1), this.dataView.setUint16(this.position, et), this.position += 2;
},
pushUint24(et) {
this.assertPosition(this.position + 2), this.dataView.setUint16(this.position, et >> 8), this.dataView.setUint8(this.position + 2, et & 255), this.position += 3;
},
pushUint32(et) {
this.assertPosition(this.position + 3), this.dataView.setUint32(this.position, et), this.position += 4;
},
readByte() {
this.assertReadLimit(), this._touch();
const et = this.inspectByte();
return this.position++, et;
},
readBytes(et, tt) {
this.assertReadLimit(), this._touch();
const rt = this.inspectBytes(et);
return this.position += tt ?? et, rt;
},
readUint8() {
this.assertReadLimit(), this._touch();
const et = this.inspectUint8();
return this.position += 1, et;
},
readUint16() {
this.assertReadLimit(), this._touch();
const et = this.inspectUint16();
return this.position += 2, et;
},
readUint24() {
this.assertReadLimit(), this._touch();
const et = this.inspectUint24();
return this.position += 3, et;
},
readUint32() {
this.assertReadLimit(), this._touch();
const et = this.inspectUint32();
return this.position += 4, et;
},
get remaining() {
return this.bytes.length - this.position;
},
setPosition(et) {
const tt = this.position;
return this.assertPosition(et), this.position = et, () => this.position = tt;
},
_touch() {
if (this.recursiveReadLimit === Number.POSITIVE_INFINITY)
return;
const et = this.getReadCount();
this.positionReadCount.set(this.position, et + 1), et > 0 && this.recursiveReadCount++;
}
};
function createCursor(et, { recursiveReadLimit: tt = 8192 } = {}) {
const rt = Object.create(staticCursor);
return rt.bytes = et, rt.dataView = new DataView(et.buffer, et.byteOffset, et.byteLength), rt.positionReadCount = /* @__PURE__ */ new Map(), rt.recursiveReadLimit = tt, rt;
}
function toRlp(et, tt = "hex") {
const rt = getEncodable(et), nt = createCursor(new Uint8Array(rt.length));
return rt.encode(nt), tt === "hex" ? bytesToHex$1(nt.bytes) : nt.bytes;
}
function getEncodable(et) {
return Array.isArray(et) ? getEncodableList(et.map((tt) => getEncodable(tt))) : getEncodableBytes(et);
}
function getEncodableList(et) {
const tt = et.reduce((it, st) => it + st.length, 0), rt = getSizeOfLength(tt);
return {
length: tt <= 55 ? 1 + tt : 1 + rt + tt,
encode(it) {
tt <= 55 ? it.pushByte(192 + tt) : (it.pushByte(247 + rt), rt === 1 ? it.pushUint8(tt) : rt === 2 ? it.pushUint16(tt) : rt === 3 ? it.pushUint24(tt) : it.pushUint32(tt));
for (const { encode: st } of et)
st(it);
}
};
}
function getEncodableBytes(et) {
const tt = typeof et == "string" ? hexToBytes$1(et) : et, rt = getSizeOfLength(tt.length);
return {
length: tt.length === 1 && tt[0] < 128 ? 1 : tt.length <= 55 ? 1 + tt.length : 1 + rt + tt.length,
encode(it) {
tt.length === 1 && tt[0] < 128 ? it.pushBytes(tt) : tt.length <= 55 ? (it.pushByte(128 + tt.length), it.pushBytes(tt)) : (it.pushByte(183 + rt), rt === 1 ? it.pushUint8(tt.length) : rt === 2 ? it.pushUint16(tt.length) : rt === 3 ? it.pushUint24(tt.length) : it.pushUint32(tt.length), it.pushBytes(tt));
}
};
}
function getSizeOfLength(et) {
if (et < 2 ** 8)
return 1;
if (et < 2 ** 16)
return 2;
if (et < 2 ** 24)
return 3;
if (et < 2 ** 32)
return 4;
throw new BaseError$1("Length is too large.");
}
const etherUnits = {
gwei: 9,
wei: 18
}, gweiUnits = {
ether: -9,
wei: 9
};
function formatUnits(et, tt) {
let rt = et.toString();
const nt = rt.startsWith("-");
nt && (rt = rt.slice(1)), rt = rt.padStart(tt, "0");
let [it, st] = [
rt.slice(0, rt.length - tt),
rt.slice(rt.length - tt)
];
return st = st.replace(/(0+)$/, ""), `${nt ? "-" : ""}${it || "0"}${st ? `.${st}` : ""}`;
}
function formatEther(et, tt = "wei") {
return formatUnits(et, etherUnits[tt]);
}
function formatGwei(et, tt = "wei") {
return formatUnits(et, gweiUnits[tt]);
}
function prettyPrint(et) {
const tt = Object.entries(et).map(([nt, it]) => it === void 0 || it === !1 ? null : [nt, it]).filter(Boolean), rt = tt.reduce((nt, [it]) => Math.max(nt, it.length), 0);
return tt.map(([nt, it]) => ` ${`${nt}:`.padEnd(rt + 1)} ${it}`).join(`
`);
}
class FeeConflictError extends BaseError$1 {
constructor() {
super([
"Cannot specify both a `gasPrice` and a `maxFeePerGas`/`maxPriorityFeePerGas`.",
"Use `maxFeePerGas`/`maxPriorityFeePerGas` for EIP-1559 compatible networks, and `gasPrice` for others."
].join(`
`), { name: "FeeConflictError" });
}
}
class InvalidLegacyVError extends BaseError$1 {
constructor({ v: tt }) {
super(`Invalid \`v\` value "${tt}". Expected 27 or 28.`, {
name: "InvalidLegacyVError"
});
}
}
class InvalidSerializableTransactionError extends BaseError$1 {
constructor({ transaction: tt }) {
super("Cannot infer a transaction type from provided transaction.", {
metaMessages: [
"Provided Transaction:",
"{",
prettyPrint(tt),
"}",
"",
"To infer the type, either provide:",
"- a `type` to the Transaction, or",
"- an EIP-1559 Transaction with `maxFeePerGas`, or",
"- an EIP-2930 Transaction with `gasPrice` & `accessList`, or",
"- an EIP-4844 Transaction with `blobs`, `blobVersionedHashes`, `sidecars`, or",
"- an EIP-7702 Transaction with `authorizationList`, or",
"- a Legacy Transaction with `gasPrice`"
],
name: "InvalidSerializableTransactionError"
});
}
}
class InvalidStorageKeySizeError extends BaseError$1 {
constructor({ storageKey: tt }) {
super(`Size for storage key "${tt}" is invalid. Expected 32 bytes. Got ${Math.floor((tt.length - 2) / 2)} bytes.`, { name: "InvalidStorageKeySizeError" });
}
}
function serializeAuthorizationList(et) {
if (!et || et.length === 0)
return [];
const tt = [];
for (const rt of et) {
const { chainId: nt, nonce: it, ...st } = rt, ot = rt.address;
tt.push([
nt ? toHex$1(nt) : "0x",
ot,
it ? toHex$1(it) : "0x",
...toYParitySignatureArray({}, st)
]);
}
return tt;
}
function blobsToCommitments(et) {
const { kzg: tt } = et, rt = et.to ?? (typeof et.blobs[0] == "string" ? "hex" : "bytes"), nt = typeof et.blobs[0] == "string" ? et.blobs.map((st) => hexToBytes$1(st)) : et.blobs, it = [];
for (const st of nt)
it.push(Uint8Array.from(tt.blobToKzgCommitment(st)));
return rt === "bytes" ? it : it.map((st) => bytesToHex$1(st));
}
function blobsToProofs(et) {
const { kzg: tt } = et, rt = et.to ?? (typeof et.blobs[0] == "string" ? "hex" : "bytes"), nt = typeof et.blobs[0] == "string" ? et.blobs.map((ot) => hexToBytes$1(ot)) : et.blobs, it = typeof et.commitments[0] == "string" ? et.commitments.map((ot) => hexToBytes$1(ot)) : et.commitments, st = [];
for (let ot = 0; ot < nt.length; ot++) {
const lt = nt[ot], dt = it[ot];
st.push(Uint8Array.from(tt.computeBlobKzgProof(lt, dt)));
}
return rt === "bytes" ? st : st.map((ot) => bytesToHex$1(ot));
}
function anumber(et) {
if (!Number.isSafeInteger(et) || et < 0)
throw new Error("positive integer expected, got " + et);
}
function isBytes$3(et) {
return et instanceof Uint8Array || ArrayBuffer.isView(et) && et.constructor.name === "Uint8Array";
}
function abytes$1(et, ...tt) {
if (!isBytes$3(et))
throw new Error("Uint8Array expected");
if (tt.length > 0 && !tt.includes(et.length))
throw new Error("Uint8Array expected of length " + tt + ", got length=" + et.length);
}
function ahash(et) {
if (typeof et != "function" || typeof et.create != "function")
throw new Error("Hash should be wrapped by utils.wrapConstructor");
anumber(et.outputLen), anumber(et.blockLen);
}
function aexists(et, tt = !0) {
if (et.destroyed)
throw new Error("Hash instance has been destroyed");
if (tt && et.finished)
throw new Error("Hash#digest() has already been called");
}
function aoutput(et, tt) {
abytes$1(et);
const rt = tt.outputLen;
if (et.length < rt)
throw new Error("digestInto() expects output buffer of length at least " + rt);
}
const crypto$1 = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
function u32(et) {
return new Uint32Array(et.buffer, et.byteOffset, Math.floor(et.byteLength / 4));
}
function createView(et) {
return new DataView(et.buffer, et.byteOffset, et.byteLength);
}
function rotr(et, tt) {
return et << 32 - tt | et >>> tt;
}
const isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
function byteSwap(et) {
return et << 24 & 4278190080 | et << 8 & 16711680 | et >>> 8 & 65280 | et >>> 24 & 255;
}
function byteSwap32(et) {
for (let tt = 0; tt < et.length; tt++)
et[tt] = byteSwap(et[tt]);
}
typeof Uint8Array.from([]).toHex == "function" && Uint8Array.fromHex;
function utf8ToBytes$1(et) {
if (typeof et != "string")
throw new Error("utf8ToBytes expected string, got " + typeof et);
return new Uint8Array(new TextEncoder().encode(et));
}
function toBytes$1(et) {
return typeof et == "string" && (et = utf8ToBytes$1(et)), abytes$1(et), et;
}
function concatBytes$1(...et) {
let tt = 0;
for (let nt = 0; nt < et.length; nt++) {
const it = et[nt];
abytes$1(it), tt += it.length;
}
const rt = new Uint8Array(tt);
for (let nt = 0, it = 0; nt < et.length; nt++) {
const st = et[nt];
rt.set(st, it), it += st.length;
}
return rt;
}
class Hash {
// Safe version that clones internal state
clone() {
return this._cloneInto();
}
}
function wrapConstructor(et) {
const tt = (nt) => et().update(toBytes$1(nt)).digest(), rt = et();
return tt.outputLen = rt.outputLen, tt.blockLen = rt.blockLen, tt.create = () => et(), tt;
}
function randomBytes(et = 32) {
if (crypto$1 && typeof crypto$1.getRandomValues == "function")
return crypto$1.getRandomValues(new Uint8Array(et));
if (crypto$1 && typeof crypto$1.randomBytes == "function")
return Uint8Array.from(crypto$1.randomBytes(et));
throw new Error("crypto.getRandomValues must be defined");
}
function setBigUint64(et, tt, rt, nt) {
if (typeof et.setBigUint64 == "function")
return et.setBigUint64(tt, rt, nt);
const it = BigInt(32), st = BigInt(4294967295), ot = Number(rt >> it & st), lt = Number(rt & st), dt = nt ? 4 : 0, pt = nt ? 0 : 4;
et.setUint32(tt + dt, ot, nt), et.setUint32(tt + pt, lt, nt);
}
function Chi(et, tt, rt) {
return et & tt ^ ~et & rt;
}
function Maj(et, tt, rt) {
return et & tt ^ et & rt ^ tt & rt;
}
class HashMD extends Hash {
constructor(tt, rt, nt, it) {
super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = tt, this.outputLen = rt, this.padOffset = nt, this.isLE = it, this.buffer = new Uint8Array(tt), this.view = createView(this.buffer);
}
update(tt) {
aexists(this);
const { view: rt, buffer: nt, blockLen: it } = this;
tt = toBytes$1(tt);
const st = tt.length;
for (let ot = 0; ot < st; ) {
const lt = Math.min(it - this.pos, st - ot);
if (lt === it) {
const dt = createView(tt);
for (; it <= st - ot; ot += it)
this.process(dt, ot);
continue;
}
nt.set(tt.subarray(ot, ot + lt), this.pos), this.pos += lt, ot += lt, this.pos === it && (this.process(rt, 0), this.pos = 0);
}
return this.length += tt.length, this.roundClean(), this;
}
digestInto(tt) {
aexists(this), aoutput(tt, this), this.finished = !0;
const { buffer: rt, view: nt, blockLen: it, isLE: st } = this;
let { pos: ot } = this;
rt[ot++] = 128, this.buffer.subarray(ot).fill(0), this.padOffset > it - ot && (this.process(nt, 0), ot = 0);
for (let yt = ot; yt < it; yt++)
rt[yt] = 0;
setBigUint64(nt, it - 8, BigInt(this.length * 8), st), this.process(nt, 0);
const lt = createView(tt), dt = this.outputLen;
if (dt % 4)
throw new Error("_sha2: outputLen should be aligned to 32bit");
const pt = dt / 4, ht = this.get();
if (pt > ht.length)
throw new Error("_sha2: outputLen bigger than state");
for (let yt = 0; yt < pt; yt++)
lt.setUint32(4 * yt, ht[yt], st);
}
digest() {
const { buffer: tt, outputLen: rt } = this;
this.digestInto(tt);
const nt = tt.slice(0, rt);
return this.destroy(), nt;
}
_cloneInto(tt) {
tt || (tt = new this.constructor()), tt.set(...this.get());
const { blockLen: rt, buffer: nt, length: it, finished: st, destroyed: ot, pos: lt } = this;
return tt.length = it, tt.pos = lt, tt.finished = st, tt.destroyed = ot, it % rt && tt.buffer.set(nt), tt;
}
}
const SHA256_K = /* @__PURE__ */ new Uint32Array([
1116352408,
1899447441,
3049323471,
3921009573,
961987163,
1508970993,
2453635748,
2870763221,
3624381080,
310598401,
607225278,
1426881987,
1925078388,
2162078206,
2614888103,
3248222580,
3835390401,
4022224774,
264347078,
604807628,
770255983,
1249150122,
1555081692,
1996064986,
2554220882,
2821834349,
2952996808,
3210313671,
3336571891,
3584528711,
113926993,
338241895,
666307205,
773529912,
1294757372,
1396182291,
1695183700,
1986661051,
2177026350,
2456956037,
2730485921,
2820302411,
3259730800,
3345764771,
3516065817,
3600352804,
4094571909,
275423344,
430227734,
506948616,
659060556,
883997877,
958139571,
1322822218,
1537002063,
1747873779,
1955562222,
2024104815,
2227730452,
2361852424,
2428436474,
2756734187,
3204031479,
3329325298
]), SHA256_IV = /* @__PURE__ */ new Uint32Array([
1779033703,
3144134277,
1013904242,
2773480762,
1359893119,
2600822924,
528734635,
1541459225
]), SHA256_W = /* @__PURE__ */ new Uint32Array(64);
class SHA256 extends HashMD {
constructor(tt = 32) {
super(64, tt, 8, !1), this.A = SHA256_IV[0] | 0, this.B = SHA256_IV[1] | 0, this.C = SHA256_IV[2] | 0, this.D = SHA256_IV[3] | 0, this.E = SHA256_IV[4] | 0, this.F = SHA256_IV[5] | 0, this.G = SHA256_IV[6] | 0, this.H = SHA256_IV[7] | 0;
}
get() {
const { A: tt, B: rt, C: nt, D: it, E: st, F: ot, G: lt, H: dt } = this;
return [tt, rt, nt, it, st, ot, lt, dt];
}
// prettier-ignore
set(tt, rt, nt, it, st, ot, lt, dt) {
this.A = tt | 0, this.B = rt | 0, this.C = nt | 0, this.D = it | 0, this.E = st | 0, this.F = ot | 0, this.G = lt | 0, this.H = dt | 0;
}
process(tt, rt) {
for (let yt = 0; yt < 16; yt++, rt += 4)
SHA256_W[yt] = tt.getUint32(rt, !1);
for (let yt = 16; yt < 64; yt++) {
const mt = SHA256_W[yt - 15], xt = SHA256_W[yt - 2], wt = rotr(mt, 7) ^ rotr(mt, 18) ^ mt >>> 3, Et = rotr(xt, 17) ^ rotr(xt, 19) ^ xt >>> 10;
SHA256_W[yt] = Et + SHA256_W[yt - 7] + wt + SHA256_W[yt - 16] | 0;
}
let { A: nt, B: it, C: st, D: ot, E: lt, F: dt, G: pt, H: ht } = this;
for (let yt = 0; yt < 64; yt++) {
const mt = rotr(lt, 6) ^ rotr(lt, 11