UNPKG

@omnisat/lasereyes

Version:

Simplifies wallet interactions across various Bitcoin wallets, making it easy for developers to build dApps with Bitcoin support

1,711 lines (1,710 loc) 2.48 MB
"use client"; import { createContext as RU, useContext as zU, useMemo as Z1, useState as LU, useEffect as jU, useCallback as Xr, useSyncExternalStore as HU } from "react"; import { jsx as j, jsxs as Ot } from "react/jsx-runtime"; var FU = Object.defineProperty, MU = (e, t, r) => t in e ? FU(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, fe = (e, t, r) => MU(e, typeof t != "symbol" ? t + "" : t, r); function DU(e, t) { for (var r = 0; r < t.length; r++) { const n = t[r]; if (typeof n != "string" && !Array.isArray(n)) { for (const o in n) if (o !== "default" && !(o in e)) { const a = Object.getOwnPropertyDescriptor(n, o); a && Object.defineProperty(e, o, a.get ? a : { enumerable: !0, get: () => n[o] }); } } } return Object.freeze(Object.defineProperty(e, Symbol.toStringTag, { value: "Module" })); } let tv = Symbol("clean"), ui = [], Os = 0; const K0 = 4; let rv = (e) => { let t = [], r = { get() { return r.lc || r.listen(() => { })(), r.value; }, lc: 0, listen(n) { return r.lc = t.push(n), () => { for (let a = Os + K0; a < ui.length; ) ui[a] === n ? ui.splice(a, K0) : a += K0; let o = t.indexOf(n); ~o && (t.splice(o, 1), --r.lc || r.off()); }; }, notify(n, o) { let a = !ui.length; for (let i of t) ui.push( i, r.value, n, o ); if (a) { for (Os = 0; Os < ui.length; Os += K0) ui[Os]( ui[Os + 1], ui[Os + 2], ui[Os + 3] ); ui.length = 0; } }, /* It will be called on last listener unsubscribing. We will redefine it in onMount and onStop. */ off() { }, set(n) { let o = r.value; o !== n && (r.value = n, r.notify(o)); }, subscribe(n) { let o = r.listen(n); return n(r.value), o; }, value: e }; return process.env.NODE_ENV !== "production" && (r[tv] = () => { t = [], r.lc = 0, r.off(); }), r; }; const KU = 5, Gl = 6, V0 = 10; let VU = (e, t, r, n) => (e.events = e.events || {}, e.events[r + V0] || (e.events[r + V0] = n((o) => { e.events[r].reduceRight((a, i) => (i(a), a), { shared: {}, ...o }); })), e.events[r] = e.events[r] || [], e.events[r].push(t), () => { let o = e.events[r], a = o.indexOf(t); o.splice(a, 1), o.length || (delete e.events[r], e.events[r + V0](), delete e.events[r + V0]); }), qU = 1e3, GU = (e, t) => VU(e, (r) => { let n = t(r); n && e.events[Gl].push(n); }, KU, (r) => { let n = e.listen; e.listen = (...a) => (!e.lc && !e.active && (e.active = !0, r()), n(...a)); let o = e.off; if (e.events[Gl] = [], e.off = () => { o(), setTimeout(() => { if (e.active && !e.lc) { e.active = !1; for (let a of e.events[Gl]) a(); e.events[Gl] = []; } }, qU); }, process.env.NODE_ENV !== "production") { let a = e[tv]; e[tv] = () => { for (let i of e.events[Gl]) i(); e.events[Gl] = [], e.active = !1, a(); }; } return () => { e.listen = n, e.off = o; }; }), ZU = (e) => { e.listen(() => { }); }; function ai(e, t, r) { let n = /* @__PURE__ */ new Set([...t, void 0]); return e.listen((o, a, i) => { n.has(i) && r(o, a, i); }); } let fk = (e = {}) => { let t = rv(e); return t.setKey = function(r, n) { let o = t.value; typeof n > "u" && r in t.value ? (t.value = { ...t.value }, delete t.value[r], t.notify(o, r)) : t.value[r] !== n && (t.value = { ...t.value, [r]: n }, t.notify(o, r)); }, t; }; const xh = "oyl", hf = "unisat", Au = "xverse", ku = "phantom", Sh = "leather", $c = "magic-eden", _h = "okx", pf = "wizz", xu = "orange", Su = "op_net", gf = "sparrow", Mu = "p2tr", WU = "p2pkh", XU = "p2sh-p2wpkh", nv = "p2wpkh", o3e = "p2psh", YU = "p2wsh", Lp = "p2sh", i3e = { leather: { name: "leather", url: "https://leather.io/install-extension" }, "magic-eden": { name: "magic-eden", url: "https://wallet.magiceden.io/" }, okx: { name: "okx", url: "https://chromewebstore.google.com/detail/okx-wallet/mcohilncbfahbmgdjkbpemcciiolgcge" }, op_net: { name: "op_net", url: "https://opnet.org/" }, orange: { name: "orange", url: "https://www.orangewallet.com/" }, oyl: { name: "oyl", url: "https://www.oyl.io/#get-wallet" }, phantom: { name: "phantom", url: "https://phantom.app/download" }, sparrow: { name: "sparrow", url: "https://sparrowwallet.com/" }, unisat: { name: "unisat", url: "https://unisat.io/download" }, wizz: { name: "wizz", url: "https://wizzwallet.io/#extension" }, xverse: { name: "xverse", url: "https://www.xverse.app/download" } }, E2 = "defaultWallet", Fi = { /** * The message prefix used for signing Bitcoin messages. */ messagePrefix: `Bitcoin Signed Message: `, /** * The Bech32 prefix used for Bitcoin addresses. */ bech32: "bc", /** * The BIP32 key prefixes for Bitcoin. */ bip32: { /** * The public key prefix for BIP32 extended public keys. */ public: 76067358, /** * The private key prefix for BIP32 extended private keys. */ private: 76066276 }, /** * The prefix for Bitcoin public key hashes. */ pubKeyHash: 0, /** * The prefix for Bitcoin script hashes. */ scriptHash: 5, /** * The prefix for Bitcoin Wallet Import Format (WIF) private keys. */ wif: 128 }, JU = { messagePrefix: `Bitcoin Signed Message: `, bech32: "tb", bip32: { public: 70617039, private: 70615956 }, pubKeyHash: 111, scriptHash: 196, wif: 239 }; function QU(e) { if (e.length < 8 || e.length > 72 || e[0] !== 48 || e[1] !== e.length - 2 || e[2] !== 2) return !1; const t = e[3]; if (t === 0 || 5 + t >= e.length || e[4 + t] !== 2) return !1; const r = e[5 + t]; return !(r === 0 || 6 + t + r !== e.length || e[4] & 128 || t > 1 && e[4] === 0 && !(e[5] & 128) || e[t + 6] & 128 || r > 1 && e[t + 6] === 0 && !(e[t + 7] & 128)); } function eR(e) { if (e.length < 8) throw new Error("DER sequence length is too short"); if (e.length > 72) throw new Error("DER sequence length is too long"); if (e[0] !== 48) throw new Error("Expected DER sequence"); if (e[1] !== e.length - 2) throw new Error("DER sequence length is invalid"); if (e[2] !== 2) throw new Error("Expected DER integer"); const t = e[3]; if (t === 0) throw new Error("R length is zero"); if (5 + t >= e.length) throw new Error("R length is too long"); if (e[4 + t] !== 2) throw new Error("Expected DER integer (2)"); const r = e[5 + t]; if (r === 0) throw new Error("S length is zero"); if (6 + t + r !== e.length) throw new Error("S length is invalid"); if (e[4] & 128) throw new Error("R value is negative"); if (t > 1 && e[4] === 0 && !(e[5] & 128)) throw new Error("R value excessively padded"); if (e[t + 6] & 128) throw new Error("S value is negative"); if (r > 1 && e[t + 6] === 0 && !(e[t + 7] & 128)) throw new Error("S value excessively padded"); return { r: e.slice(4, 4 + t), s: e.slice(6 + t) }; } function tR(e, t) { const r = e.length, n = t.length; if (r === 0) throw new Error("R length is zero"); if (n === 0) throw new Error("S length is zero"); if (r > 33) throw new Error("R length is too long"); if (n > 33) throw new Error("S length is too long"); if (e[0] & 128) throw new Error("R value is negative"); if (t[0] & 128) throw new Error("S value is negative"); if (r > 1 && e[0] === 0 && !(e[1] & 128)) throw new Error("R value excessively padded"); if (n > 1 && t[0] === 0 && !(t[1] & 128)) throw new Error("S value excessively padded"); const o = new Uint8Array(6 + r + n); return o[0] = 48, o[1] = o.length - 2, o[2] = 2, o[3] = e.length, o.set(e, 4), o[4 + r] = 2, o[5 + r] = t.length, o.set(t, 6 + r), o; } const Ht = { OP_FALSE: 0, OP_0: 0, OP_PUSHDATA1: 76, OP_PUSHDATA2: 77, OP_PUSHDATA4: 78, OP_1NEGATE: 79, OP_RESERVED: 80, OP_TRUE: 81, OP_1: 81, OP_2: 82, OP_3: 83, OP_4: 84, OP_5: 85, OP_6: 86, OP_7: 87, OP_8: 88, OP_9: 89, OP_10: 90, OP_11: 91, OP_12: 92, OP_13: 93, OP_14: 94, OP_15: 95, OP_16: 96, OP_NOP: 97, OP_VER: 98, OP_IF: 99, OP_NOTIF: 100, OP_VERIF: 101, OP_VERNOTIF: 102, OP_ELSE: 103, OP_ENDIF: 104, OP_VERIFY: 105, OP_RETURN: 106, OP_TOALTSTACK: 107, OP_FROMALTSTACK: 108, OP_2DROP: 109, OP_2DUP: 110, OP_3DUP: 111, OP_2OVER: 112, OP_2ROT: 113, OP_2SWAP: 114, OP_IFDUP: 115, OP_DEPTH: 116, OP_DROP: 117, OP_DUP: 118, OP_NIP: 119, OP_OVER: 120, OP_PICK: 121, OP_ROLL: 122, OP_ROT: 123, OP_SWAP: 124, OP_TUCK: 125, OP_CAT: 126, OP_SUBSTR: 127, OP_LEFT: 128, OP_RIGHT: 129, OP_SIZE: 130, OP_INVERT: 131, OP_AND: 132, OP_OR: 133, OP_XOR: 134, OP_EQUAL: 135, OP_EQUALVERIFY: 136, OP_RESERVED1: 137, OP_RESERVED2: 138, OP_1ADD: 139, OP_1SUB: 140, OP_2MUL: 141, OP_2DIV: 142, OP_NEGATE: 143, OP_ABS: 144, OP_NOT: 145, OP_0NOTEQUAL: 146, OP_ADD: 147, OP_SUB: 148, OP_MUL: 149, OP_DIV: 150, OP_MOD: 151, OP_LSHIFT: 152, OP_RSHIFT: 153, OP_BOOLAND: 154, OP_BOOLOR: 155, OP_NUMEQUAL: 156, OP_NUMEQUALVERIFY: 157, OP_NUMNOTEQUAL: 158, OP_LESSTHAN: 159, OP_GREATERTHAN: 160, OP_LESSTHANOREQUAL: 161, OP_GREATERTHANOREQUAL: 162, OP_MIN: 163, OP_MAX: 164, OP_WITHIN: 165, OP_RIPEMD160: 166, OP_SHA1: 167, OP_SHA256: 168, OP_HASH160: 169, OP_HASH256: 170, OP_CODESEPARATOR: 171, OP_CHECKSIG: 172, OP_CHECKSIGVERIFY: 173, OP_CHECKMULTISIG: 174, OP_CHECKMULTISIGVERIFY: 175, OP_NOP1: 176, OP_NOP2: 177, OP_CHECKLOCKTIMEVERIFY: 177, OP_NOP3: 178, OP_CHECKSEQUENCEVERIFY: 178, OP_NOP4: 179, OP_NOP5: 180, OP_NOP6: 181, OP_NOP7: 182, OP_NOP8: 183, OP_NOP9: 184, OP_NOP10: 185, OP_CHECKSIGADD: 186, OP_PUBKEYHASH: 253, OP_PUBKEY: 254, OP_INVALIDOPCODE: 255 }, dk = {}; for (const e of Object.keys(Ht)) { const t = Ht[e]; dk[t] = e; } const wg = "0123456789abcdefABCDEF", vg = wg.split("").map((e) => e.codePointAt(0)), Eg = Array(256).fill(!0).map((e, t) => { const r = String.fromCodePoint(t), n = wg.indexOf(r); return n < 0 ? void 0 : n < 16 ? n : n - 6; }), hk = new TextEncoder(), pk = new TextDecoder(); function rR(e) { return pk.decode(e); } function nR(e) { return hk.encode(e); } function br(e) { const t = e.reduce((o, a) => o + a.length, 0), r = new Uint8Array(t); let n = 0; for (const o of e) r.set(o, n), n += o.length; return r; } function Ge(e) { const t = e || new Uint8Array(); return t.length > 512 ? iR(t) : oR(t); } function oR(e) { let t = ""; for (let r = 0; r < e.length; ++r) t += wg[Eg[vg[e[r] >> 4]]], t += wg[Eg[vg[e[r] & 15]]]; return t; } function iR(e) { const t = new Uint8Array(e.length * 2); for (let r = 0; r < e.length; ++r) t[r * 2] = vg[e[r] >> 4], t[r * 2 + 1] = vg[e[r] & 15]; return pk.decode(t); } function ks(e) { const t = hk.encode(e || ""), r = new Uint8Array(Math.floor(t.length / 2)); let n; for (n = 0; n < r.length; n++) { const o = Eg[t[n * 2]], a = Eg[t[n * 2 + 1]]; if (o === void 0 || a === void 0) break; r[n] = o << 4 | a; } return n === r.length ? r : r.slice(0, n); } function aR(e) { return btoa(String.fromCharCode(...e)); } function gk(e) { const t = atob(e), r = new Uint8Array(t.length); for (let n = 0; n < t.length; n++) r[n] = t.charCodeAt(n); return r; } function he(e, t) { const r = Math.min(e.length, t.length); for (let n = 0; n < r; ++n) if (e[n] !== t[n]) return e[n] < t[n] ? -1 : 1; return e.length === t.length ? 0 : e.length > t.length ? 1 : -1; } function Eo(e, t, r) { if (t + 1 > e.length) throw new Error("Offset is outside the bounds of Uint8Array"); if (r > 255) throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 255. Received ${r}`); return e[t] = r, t + 1; } function sR(e, t, r, n) { if (t + 2 > e.length) throw new Error("Offset is outside the bounds of Uint8Array"); if (n = n.toUpperCase(), r > 65535) throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 65535. Received ${r}`); return n === "LE" ? (e[t] = r & 255, e[t + 1] = r >> 8 & 255) : (e[t] = r >> 8 & 255, e[t + 1] = r & 255), t + 2; } function jp(e, t, r, n) { if (t + 4 > e.length) throw new Error("Offset is outside the bounds of Uint8Array"); if (n = n.toUpperCase(), r > 4294967295) throw new Error(`The value of "value" is out of range. It must be >= 0 and <= ${4294967295}. Received ${r}`); return n === "LE" ? (e[t] = r & 255, e[t + 1] = r >> 8 & 255, e[t + 2] = r >> 16 & 255, e[t + 3] = r >> 24 & 255) : (e[t] = r >> 24 & 255, e[t + 1] = r >> 16 & 255, e[t + 2] = r >> 8 & 255, e[t + 3] = r & 255), t + 4; } function cR(e, t, r, n) { if (t + 8 > e.length) throw new Error("Offset is outside the bounds of Uint8Array"); if (n = n.toUpperCase(), r > 0xffffffffffffffffn) throw new Error(`The value of "value" is out of range. It must be >= 0 and <= ${0xffffffffffffffffn}. Received ${r}`); return n === "LE" ? (e[t] = Number(r & 0xffn), e[t + 1] = Number(r >> 8n & 0xffn), e[t + 2] = Number(r >> 16n & 0xffn), e[t + 3] = Number(r >> 24n & 0xffn), e[t + 4] = Number(r >> 32n & 0xffn), e[t + 5] = Number(r >> 40n & 0xffn), e[t + 6] = Number(r >> 48n & 0xffn), e[t + 7] = Number(r >> 56n & 0xffn)) : (e[t] = Number(r >> 56n & 0xffn), e[t + 1] = Number(r >> 48n & 0xffn), e[t + 2] = Number(r >> 40n & 0xffn), e[t + 3] = Number(r >> 32n & 0xffn), e[t + 4] = Number(r >> 24n & 0xffn), e[t + 5] = Number(r >> 16n & 0xffn), e[t + 6] = Number(r >> 8n & 0xffn), e[t + 7] = Number(r & 0xffn)), t + 8; } function hs(e, t) { if (t + 1 > e.length) throw new Error("Offset is outside the bounds of Uint8Array"); return e[t]; } function uR(e, t, r) { if (t + 2 > e.length) throw new Error("Offset is outside the bounds of Uint8Array"); if (r = r.toUpperCase(), r === "LE") { let n = 0; return n = (n << 8) + e[t + 1], n = (n << 8) + e[t], n; } else { let n = 0; return n = (n << 8) + e[t], n = (n << 8) + e[t + 1], n; } } function hd(e, t, r) { if (t + 4 > e.length) throw new Error("Offset is outside the bounds of Uint8Array"); if (r = r.toUpperCase(), r === "LE") { let n = 0; return n = (n << 8) + e[t + 3] >>> 0, n = (n << 8) + e[t + 2] >>> 0, n = (n << 8) + e[t + 1] >>> 0, n = (n << 8) + e[t] >>> 0, n; } else { let n = 0; return n = (n << 8) + e[t] >>> 0, n = (n << 8) + e[t + 1] >>> 0, n = (n << 8) + e[t + 2] >>> 0, n = (n << 8) + e[t + 3] >>> 0, n; } } function mk(e, t, r, n) { if (t + 4 > e.length) throw new Error("Offset is outside the bounds of Uint8Array"); if (r > 2147483647 || r < -2147483648) throw new Error(`The value of "value" is out of range. It must be >= -2147483648 and <= 2147483647. Received ${r}`); return n = n.toUpperCase(), n === "LE" ? (e[t] = r & 255, e[t + 1] = r >> 8 & 255, e[t + 2] = r >> 16 & 255, e[t + 3] = r >> 24 & 255) : (e[t] = r >> 24 & 255, e[t + 1] = r >> 16 & 255, e[t + 2] = r >> 8 & 255, e[t + 3] = r & 255), t + 4; } function yk(e, t, r, n) { if (t + 8 > e.length) throw new Error("Offset is outside the bounds of Uint8Array"); if (r > 0x7fffffffffffffffn || r < -0x8000000000000000n) throw new Error(`The value of "value" is out of range. It must be >= ${-0x8000000000000000n} and <= ${0x7fffffffffffffffn}. Received ${r}`); return n = n.toUpperCase(), n === "LE" ? (e[t] = Number(r & 0xffn), e[t + 1] = Number(r >> 8n & 0xffn), e[t + 2] = Number(r >> 16n & 0xffn), e[t + 3] = Number(r >> 24n & 0xffn), e[t + 4] = Number(r >> 32n & 0xffn), e[t + 5] = Number(r >> 40n & 0xffn), e[t + 6] = Number(r >> 48n & 0xffn), e[t + 7] = Number(r >> 56n & 0xffn)) : (e[t] = Number(r >> 56n & 0xffn), e[t + 1] = Number(r >> 48n & 0xffn), e[t + 2] = Number(r >> 40n & 0xffn), e[t + 3] = Number(r >> 32n & 0xffn), e[t + 4] = Number(r >> 24n & 0xffn), e[t + 5] = Number(r >> 16n & 0xffn), e[t + 6] = Number(r >> 8n & 0xffn), e[t + 7] = Number(r & 0xffn)), t + 8; } function lR(e, t, r) { if (t + 4 > e.length) throw new Error("Offset is outside the bounds of Uint8Array"); if (r = r.toUpperCase(), r === "LE") { const n = e[t] + (e[t + 1] << 8) + (e[t + 2] << 16) + (e[t + 3] << 24 >>> 0); return e[t + 3] <= 127 ? n : n - 4294967296; } else { const n = (e[t] << 24 >>> 0) + (e[t + 1] << 16) + (e[t + 2] << 8) + e[t + 3]; return e[t] <= 127 ? n : n - 4294967296; } } function bk(e, t, r) { if (t + 8 > e.length) throw new Error("Offset is outside the bounds of Uint8Array"); r = r.toUpperCase(); let n = 0n; if (r === "LE") return n = (n << 8n) + BigInt(e[t + 7]), n = (n << 8n) + BigInt(e[t + 6]), n = (n << 8n) + BigInt(e[t + 5]), n = (n << 8n) + BigInt(e[t + 4]), n = (n << 8n) + BigInt(e[t + 3]), n = (n << 8n) + BigInt(e[t + 2]), n = (n << 8n) + BigInt(e[t + 1]), n = (n << 8n) + BigInt(e[t]), e[t + 7] <= 127 ? n : n - 0x10000000000000000n; { let o = 0n; return o = (o << 8n) + BigInt(e[t]), o = (o << 8n) + BigInt(e[t + 1]), o = (o << 8n) + BigInt(e[t + 2]), o = (o << 8n) + BigInt(e[t + 3]), o = (o << 8n) + BigInt(e[t + 4]), o = (o << 8n) + BigInt(e[t + 5]), o = (o << 8n) + BigInt(e[t + 6]), o = (o << 8n) + BigInt(e[t + 7]), e[t] <= 127 ? o : o - 0x10000000000000000n; } } function wk(e) { return e < Ht.OP_PUSHDATA1 ? 1 : e <= 255 ? 2 : e <= 65535 ? 3 : 5; } function fR(e, t, r) { const n = wk(t); return n === 1 ? Eo(e, r, t) : n === 2 ? (Eo(e, r, Ht.OP_PUSHDATA1), Eo(e, r + 1, t)) : n === 3 ? (Eo(e, r, Ht.OP_PUSHDATA2), sR(e, r + 1, t, "LE")) : (Eo(e, r, Ht.OP_PUSHDATA4), jp(e, r + 1, t, "LE")), n; } function dR(e, t) { const r = hs(e, t); let n, o; if (r < Ht.OP_PUSHDATA1) n = r, o = 1; else if (r === Ht.OP_PUSHDATA1) { if (t + 2 > e.length) return null; n = hs(e, t + 1), o = 2; } else if (r === Ht.OP_PUSHDATA2) { if (t + 3 > e.length) return null; n = uR(e, t + 1, "LE"), o = 3; } else { if (t + 5 > e.length) return null; if (r !== Ht.OP_PUSHDATA4) throw new Error("Unexpected opcode"); n = hd(e, t + 1, "LE"), o = 5; } return { opcode: r, number: n, size: o }; } function hR(e) { return e > 2147483647 ? 5 : e > 8388607 ? 4 : e > 32767 ? 3 : e > 127 ? 2 : e > 0 ? 1 : 0; } function pR(e) { let t = Math.abs(e); const r = hR(t), n = new Uint8Array(r), o = e < 0; for (let a = 0; a < r; ++a) Eo(n, a, t & 255), t >>= 8; return n[r - 1] & 128 ? Eo(n, r - 1, o ? 128 : 0) : o && (n[r - 1] |= 128), n; } function gR(e) { return { lang: (e == null ? void 0 : e.lang) ?? void 0, message: e == null ? void 0 : e.message, abortEarly: (e == null ? void 0 : e.abortEarly) ?? void 0, abortPipeEarly: (e == null ? void 0 : e.abortPipeEarly) ?? void 0 }; } function mR(e, t) { var r; return (r = void 0) == null ? void 0 : r.get(t); } function Hh(e) { var t, r; const n = typeof e; return n === "string" ? `"${e}"` : n === "number" || n === "bigint" || n === "boolean" ? `${e}` : n === "object" || n === "function" ? (e && ((r = (t = Object.getPrototypeOf(e)) == null ? void 0 : t.constructor) == null ? void 0 : r.name)) ?? "null" : n; } function En(e, t, r, n, o) { const a = o && "input" in o ? o.input : r.value, i = (o == null ? void 0 : o.expected) ?? e.expects ?? null, s = (o == null ? void 0 : o.received) ?? Hh(a), c = { kind: e.kind, type: e.type, input: a, expected: i, received: s, message: `Invalid ${t}: ${i ? `Expected ${i} but r` : "R"}eceived ${s}`, // @ts-expect-error requirement: e.requirement, path: o == null ? void 0 : o.path, issues: o == null ? void 0 : o.issues, lang: n.lang, abortEarly: n.abortEarly, abortPipeEarly: n.abortPipeEarly }, l = e.kind === "schema", u = (o == null ? void 0 : o.message) ?? // @ts-expect-error e.message ?? mR(e.reference, c.lang) ?? (l ? (c.lang, void 0) : null) ?? n.message ?? (c.lang, void 0); u && (c.message = typeof u == "function" ? u(c) : u), l && (r.typed = !1), r.issues ? r.issues.push(c) : r.issues = [c]; } function yR(e, t) { const r = [...new Set(e)]; return r.length > 1 ? `(${r.join(` ${t} `)})` : r[0] ?? "never"; } var bR = class extends Error { /** * Creates a Valibot error with useful information. * * @param issues The error issues. */ constructor(t) { super(t[0].message), fe(this, "issues"), this.name = "ValiError", this.issues = t; } }; function vk(e, t) { return { kind: "validation", type: "every_item", reference: vk, async: !1, expects: null, requirement: e, message: t, _run(r, n) { return r.typed && !r.value.every(this.requirement) && En(this, "item", r, n), r; } }; } function u3(e) { return { kind: "validation", type: "integer", reference: u3, async: !1, expects: null, requirement: Number.isInteger, message: e, _run(t, r) { return t.typed && !this.requirement(t.value) && En(this, "integer", t, r), t; } }; } function Ek(e, t) { return { kind: "validation", type: "length", reference: Ek, async: !1, expects: `${e}`, requirement: e, message: t, _run(r, n) { return r.typed && r.value.length !== this.requirement && En(this, "length", r, n, { received: `${r.value.length}` }), r; } }; } function oy(e, t) { return { kind: "validation", type: "max_value", reference: oy, async: !1, expects: `<=${e instanceof Date ? e.toJSON() : Hh(e)}`, requirement: e, message: t, _run(r, n) { return r.typed && r.value > this.requirement && En(this, "value", r, n, { received: r.value instanceof Date ? r.value.toJSON() : Hh(r.value) }), r; } }; } function iy(e, t) { return { kind: "validation", type: "min_value", reference: iy, async: !1, expects: `>=${e instanceof Date ? e.toJSON() : Hh(e)}`, requirement: e, message: t, _run(r, n) { return r.typed && r.value < this.requirement && En(this, "value", r, n, { received: r.value instanceof Date ? r.value.toJSON() : Hh(r.value) }), r; } }; } function Ak(e, t) { return { kind: "validation", type: "regex", reference: Ak, async: !1, expects: `${e}`, requirement: e, message: t, _run(r, n) { return r.typed && !this.requirement.test(r.value) && En(this, "format", r, n), r; } }; } function l3(e, t, r) { return typeof e.default == "function" ? ( // @ts-expect-error e.default(t, r) ) : ( // @ts-expect-error e.default ); } function ay(e, t) { return !e._run({ typed: !1, value: t }, { abortEarly: !0 }).issues; } function kk() { return { kind: "schema", type: "any", reference: kk, expects: "any", async: !1, _run(e) { return e.typed = !0, e; } }; } function Qn(e, t) { return { kind: "schema", type: "array", reference: Qn, expects: "Array", async: !1, item: e, message: t, _run(r, n) { var o; const a = r.value; if (Array.isArray(a)) { r.typed = !0, r.value = []; for (let i = 0; i < a.length; i++) { const s = a[i], c = this.item._run({ typed: !1, value: s }, n); if (c.issues) { const l = { type: "array", origin: "value", input: a, key: i, value: s }; for (const u of c.issues) u.path ? u.path.unshift(l) : u.path = [l], (o = r.issues) == null || o.push(u); if (r.issues || (r.issues = c.issues), n.abortEarly) { r.typed = !1; break; } } c.typed || (r.typed = !1), r.value.push(c.value); } } else En(this, "type", r, n); return r; } }; } function xk(e) { return { kind: "schema", type: "bigint", reference: xk, expects: "bigint", async: !1, message: e, _run(t, r) { return typeof t.value == "bigint" ? t.typed = !0 : En(this, "type", t, r), t; } }; } function Bi(e, t) { return { kind: "schema", type: "custom", reference: Bi, expects: "unknown", async: !1, check: e, message: t, _run(r, n) { return this.check(r.value) ? r.typed = !0 : En(this, "type", r, n), r; } }; } function sy(e, t) { return { kind: "schema", type: "instance", reference: sy, expects: e.name, async: !1, class: e, message: t, _run(r, n) { return r.value instanceof this.class ? r.typed = !0 : En(this, "type", r, n), r; } }; } function ov(e, ...t) { const r = { kind: "schema", type: "nullable", reference: ov, expects: `(${e.expects} | null)`, async: !1, wrapped: e, _run(n, o) { return n.value === null && ("default" in this && (n.value = l3( this, n, o )), n.value === null) ? (n.typed = !0, n) : this.wrapped._run(n, o); } }; return 0 in t && (r.default = t[0]), r; } function Sk(e, ...t) { const r = { kind: "schema", type: "nullish", reference: Sk, expects: `(${e.expects} | null | undefined)`, async: !1, wrapped: e, _run(n, o) { return (n.value === null || n.value === void 0) && ("default" in this && (n.value = l3( this, n, o )), n.value === null || n.value === void 0) ? (n.typed = !0, n) : this.wrapped._run(n, o); } }; return 0 in t && (r.default = t[0]), r; } function Wn(e) { return { kind: "schema", type: "number", reference: Wn, expects: "number", async: !1, message: e, _run(t, r) { return typeof t.value == "number" && !isNaN(t.value) ? t.typed = !0 : En(this, "type", t, r), t; } }; } function Ur(e, t) { return { kind: "schema", type: "object", reference: Ur, expects: "Object", async: !1, entries: e, message: t, _run(r, n) { var o; const a = r.value; if (a && typeof a == "object") { r.typed = !0, r.value = {}; for (const i in this.entries) { const s = a[i], c = this.entries[i]._run( { typed: !1, value: s }, n ); if (c.issues) { const l = { type: "object", origin: "value", input: a, key: i, value: s }; for (const u of c.issues) u.path ? u.path.unshift(l) : u.path = [l], (o = r.issues) == null || o.push(u); if (r.issues || (r.issues = c.issues), n.abortEarly) { r.typed = !1; break; } } c.typed || (r.typed = !1), (c.value !== void 0 || i in a) && (r.value[i] = c.value); } } else En(this, "type", r, n); return r; } }; } function Ag(e, ...t) { const r = { kind: "schema", type: "optional", reference: Ag, expects: `(${e.expects} | undefined)`, async: !1, wrapped: e, _run(n, o) { return n.value === void 0 && ("default" in this && (n.value = l3( this, n, o )), n.value === void 0) ? (n.typed = !0, n) : this.wrapped._run(n, o); } }; return 0 in t && (r.default = t[0]), r; } function kl(e) { return { kind: "schema", type: "string", reference: kl, expects: "string", async: !1, message: e, _run(t, r) { return typeof t.value == "string" ? t.typed = !0 : En(this, "type", t, r), t; } }; } function fa(e, t) { return { kind: "schema", type: "tuple", reference: fa, expects: "Array", async: !1, items: e, message: t, _run(r, n) { var o; const a = r.value; if (Array.isArray(a)) { r.typed = !0, r.value = []; for (let i = 0; i < this.items.length; i++) { const s = a[i], c = this.items[i]._run( { typed: !1, value: s }, n ); if (c.issues) { const l = { type: "array", origin: "value", input: a, key: i, value: s }; for (const u of c.issues) u.path ? u.path.unshift(l) : u.path = [l], (o = r.issues) == null || o.push(u); if (r.issues || (r.issues = c.issues), n.abortEarly) { r.typed = !1; break; } } c.typed || (r.typed = !1), r.value.push(c.value); } } else En(this, "type", r, n); return r; } }; } function FE(e) { let t; if (e) for (const r of e) t ? t.push(...r.issues) : t = r.issues; return t; } function f3(e, t) { return { kind: "schema", type: "union", reference: f3, expects: yR( e.map((r) => r.expects), "|" ), async: !1, options: e, message: t, _run(r, n) { let o, a, i; for (const s of this.options) { const c = s._run( { typed: !1, value: r.value }, n ); if (c.typed) if (c.issues) a ? a.push(c) : a = [c]; else { o = c; break; } else i ? i.push(c) : i = [c]; } if (o) return o; if (a) { if (a.length === 1) return a[0]; En(this, "type", r, n, { issues: FE(a) }), r.typed = !0; } else { if ((i == null ? void 0 : i.length) === 1) return i[0]; En(this, "type", r, n, { issues: FE(i) }); } return r; } }; } function dr(e, t, r) { const n = e._run( { typed: !1, value: t }, gR(r) ); if (n.issues) throw new bR(n.issues); return n.value; } function Fc(e, t) { const r = {}; for (const n in e.entries) r[n] = Ag(e.entries[n]); return { ...e, entries: r }; } function pd(...e) { return { ...e[0], pipe: e, _run(t, r) { for (const n of e) if (n.kind !== "metadata") { if (t.issues && (n.kind === "schema" || n.kind === "transformation")) { t.typed = !1; break; } (!t.issues || !r.abortEarly && !r.abortPipeEarly) && (t = n._run(t, r)); } return t; } }; } const ME = new Uint8Array(32), DE = ks( "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f" ), qr = (e) => pd(sy(Uint8Array), Ek(e)); function Fh(e, t) { return e.length !== t.length ? !1 : e.every((r, n) => he(r, t[n]) === 0); } function Ai(e) { if (!(e instanceof Uint8Array) || e.length < 33) return !1; const t = e[0], r = e.slice(1, 33); if (he(ME, r) === 0 || he(r, DE) >= 0) return !1; if ((t === 2 || t === 3) && e.length === 33) return !0; const n = e.slice(33); return he(ME, n) === 0 || he(n, DE) >= 0 ? !1 : t === 4 && e.length === 65; } const W1 = 254; function d3(e) { return !e || !("output" in e) || !(e.output instanceof Uint8Array) ? !1 : e.version !== void 0 ? (e.version & W1) === e.version : !0; } function _k(e) { return Array.isArray(e) ? e.length !== 2 ? !1 : e.every((t) => _k(t)) : d3(e); } const wR = qr(32), vR = qr(20), KE = qr(32), Lt = sy(Uint8Array); pd(kl(), Ak(/^([0-9a-f]{2})+$/i)); const ER = pd( Wn(), u3(), iy(0), oy(255) ), Xa = pd( Wn(), u3(), iy(0), oy(4294967295) ), A2 = pd( xk(), iy(0n), oy(0x7fffffffffffffffn) ), VE = (e) => Ur( Object.entries(e).reduce( (t, r) => ({ ...t, [r[0]]: Sk(r[1]) }), {} ) ), qE = new Uint8Array(1); function GE(e) { let t = 0; for (; e[t] === 0; ) ++t; return t === e.length ? qE : (e = e.slice(t), e[0] & 128 ? br([qE, e]) : e); } function ZE(e) { e[0] === 0 && (e = e.slice(1)); const t = new Uint8Array(32), r = Math.max(0, 32 - e.length); return t.set(e, r), t; } function AR(e) { const t = hs(e, e.length - 1); if (!p3(t)) throw new Error("Invalid hashType " + t); const r = eR(e.subarray(0, -1)), n = ZE(r.r), o = ZE(r.s); return { signature: br([n, o]), hashType: t }; } function kR(e, t) { if (dr( Ur({ signature: qr(64), hashType: ER }), { signature: e, hashType: t } ), !p3(t)) throw new Error("Invalid hashType " + t); const r = new Uint8Array(1); Eo(r, 0, t); const n = GE(e.slice(0, 32)), o = GE(e.slice(32, 64)); return br([tR(n, o), r]); } const xR = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, decode: AR, encode: kR }, Symbol.toStringTag, { value: "Module" })), Tk = Ht.OP_RESERVED, Ik = Qn(f3([sy(Uint8Array), Wn()])); function SR(e) { return ay(Wn(), e) && (e === Ht.OP_0 || e >= Ht.OP_1 && e <= Ht.OP_16 || e === Ht.OP_1NEGATE); } function Pk(e) { return ay(Lt, e) || SR(e); } function h3(e) { return ay(pd(kk(), vk(Pk)), e); } function $k(e) { return e.length - e.filter(Pk).length; } function kg(e) { if (e.length === 0) return Ht.OP_0; if (e.length === 1) { if (e[0] >= 1 && e[0] <= 16) return Tk + e[0]; if (e[0] === 129) return Ht.OP_1NEGATE; } } function Ok(e) { return e instanceof Uint8Array; } function _R(e) { return ay(Ik, e); } function xg(e) { return e instanceof Uint8Array; } function eo(e) { if (Ok(e)) return e; dr(Ik, e); const t = e.reduce((o, a) => xg(a) ? a.length === 1 && kg(a) !== void 0 ? o + 1 : o + wk(a.length) + a.length : o + 1, 0), r = new Uint8Array(t); let n = 0; if (e.forEach((o) => { if (xg(o)) { const a = kg(o); if (a !== void 0) { Eo(r, n, a), n += 1; return; } n += fR(r, o.length, n), r.set(o, n), n += o.length; } else Eo(r, n, o), n += 1; }), n !== r.length) throw new Error("Could not decode chunks"); return r; } function pr(e) { if (_R(e)) return e; dr(Lt, e); const t = []; let r = 0; for (; r < e.length; ) { const n = e[r]; if (n > Ht.OP_0 && n <= Ht.OP_PUSHDATA4) { const o = dR(e, r); if (o === null || (r += o.size, r + o.number > e.length)) return null; const a = e.slice(r, r + o.number); r += o.number; const i = kg(a); i !== void 0 ? t.push(i) : t.push(a); } else t.push(n), r += 1; } return t; } function TR(e) { if (Ok(e) && (e = pr(e)), !e) throw new Error("Could not convert invalid chunks to ASM"); return e.map((t) => { if (xg(t)) { const r = kg(t); if (r === void 0) return Ge(t); t = r; } return dk[t]; }).join(" "); } function IR(e) { return e = pr(e), dr(Bi(h3), e), e.map((t) => xg(t) ? t : t === Ht.OP_0 ? new Uint8Array(0) : pR(t - Tk)); } function PR(e) { return Ai(e); } function p3(e) { const t = e & -129; return t > 0 && t < 4; } function ps(e) { return !(e instanceof Uint8Array) || !p3(e[e.length - 1]) ? !1 : QU(e.slice(0, -1)); } const Th = xR; function je(e, t, r) { Object.defineProperty(e, t, { configurable: !0, enumerable: !0, get() { const n = r.call(this); return this[t] = n, n; }, set(n) { Object.defineProperty(this, t, { configurable: !0, enumerable: !0, value: n, writable: !0 }); } }); } function ei(e) { let t; return () => (t !== void 0 || (t = e()), t); } const of = Ht, q0 = of.OP_RESERVED; function cy(e, t) { if (!e.input && !e.output && !(e.pubkeys && e.m !== void 0) && !e.signatures) throw new TypeError("Not enough data"); t = Object.assign({ validate: !0 }, t || {}); function r(s) { return ps(s) || (t.allowIncomplete && s === of.OP_0) !== void 0; } dr( Fc( Ur({ network: Ur({}), m: Wn(), n: Wn(), output: Lt, pubkeys: Qn(Bi(Ai), "Received invalid pubkey"), signatures: Qn( Bi(r), "Expected signature to be of type isAcceptableSignature" ), input: Lt }) ), e ); const n = { network: e.network || Fi }; let o = [], a = !1; function i(s) { a || (a = !0, o = pr(s), n.m = o[0] - q0, n.n = o[o.length - 2] - q0, n.pubkeys = o.slice(1, -2)); } if (je(n, "output", () => { if (e.m && n.n && e.pubkeys) return eo( [].concat( q0 + e.m, e.pubkeys, q0 + n.n, of.OP_CHECKMULTISIG ) ); }), je(n, "m", () => { if (n.output) return i(n.output), n.m; }), je(n, "n", () => { if (n.pubkeys) return n.pubkeys.length; }), je(n, "pubkeys", () => { if (e.output) return i(e.output), n.pubkeys; }), je(n, "signatures", () => { if (e.input) return pr(e.input).slice(1); }), je(n, "input", () => { if (e.signatures) return eo([of.OP_0].concat(e.signatures)); }), je(n, "witness", () => { if (n.input) return []; }), je(n, "name", () => { if (!(!n.m || !n.n)) return `p2ms(${n.m} of ${n.n})`; }), t.validate) { if (e.output) { if (i(e.output), dr(Wn(), o[0], { message: "Output is invalid" }), dr(Wn(), o[o.length - 2], { message: "Output is invalid" }), o[o.length - 1] !== of.OP_CHECKMULTISIG) throw new TypeError("Output is invalid"); if (n.m <= 0 || n.n > 16 || n.m > n.n || n.n !== o.length - 3) throw new TypeError("Output is invalid"); if (!n.pubkeys.every((s) => Ai(s))) throw new TypeError("Output is invalid"); if (e.m !== void 0 && e.m !== n.m) throw new TypeError("m mismatch"); if (e.n !== void 0 && e.n !== n.n) throw new TypeError("n mismatch"); if (e.pubkeys && !Fh(e.pubkeys, n.pubkeys)) throw new TypeError("Pubkeys mismatch"); } if (e.pubkeys) { if (e.n !== void 0 && e.n !== e.pubkeys.length) throw new TypeError("Pubkey count mismatch"); if (n.n = e.pubkeys.length, n.n < n.m) throw new TypeError("Pubkey count cannot be less than m"); } if (e.signatures) { if (e.signatures.length < n.m) throw new TypeError("Not enough signatures provided"); if (e.signatures.length > n.m) throw new TypeError("Too many signatures provided"); } if (e.input) { if (e.input[0] !== of.OP_0) throw new TypeError("Input is invalid"); if (n.signatures.length === 0 || !n.signatures.every(r)) throw new TypeError("Input has invalid signature(s)"); if (e.signatures && !Fh(e.signatures, n.signatures)) throw new TypeError("Signature mismatch"); if (e.m !== void 0 && e.m !== e.signatures.length) throw new TypeError("Signature count mismatch"); } } return Object.assign(n, e); } const WE = Ht; function Nk(e, t) { if (!e.input && !e.output && !e.pubkey && !e.input && !e.signature) throw new TypeError("Not enough data"); t = Object.assign({ validate: !0 }, t || {}), dr( Fc( Ur({ network: Ur({}), output: Lt, pubkey: Bi(Ai, "invalid pubkey"), signature: Bi( ps, "Expected signature to be of type isCanonicalScriptSignature" ), input: Lt }) ), e ); const r = ei(() => pr(e.input)), n = { name: "p2pk", network: e.network || Fi }; if (je(n, "output", () => { if (e.pubkey) return eo([e.pubkey, WE.OP_CHECKSIG]); }), je(n, "pubkey", () => { if (e.output) return e.output.slice(1, -1); }), je(n, "signature", () => { if (e.input) return r()[0]; }), je(n, "input", () => { if (e.signature) return eo([e.signature]); }), je(n, "witness", () => { if (n.input) return []; }), t.validate) { if (e.output) { if (e.output[e.output.length - 1] !== WE.OP_CHECKSIG) throw new TypeError("Output is invalid"); if (!Ai(n.pubkey)) throw new TypeError("Output pubkey is invalid"); if (e.pubkey && he(e.pubkey, n.pubkey) !== 0) throw new TypeError("Pubkey mismatch"); } if (e.signature && e.input && he(e.input, n.input) !== 0) throw new TypeError("Signature mismatch"); if (e.input) { if (r().length !== 1) throw new TypeError("Input is invalid"); if (!ps(n.signature)) throw new TypeError("Input has invalid signature"); } } return Object.assign(n, e); } function XE(e) { if (!Number.isSafeInteger(e) || e < 0) throw new Error(`positive integer expected, not ${e}`); } function $R(e) { return e instanceof Uint8Array || e != null && typeof e == "object" && e.constructor.name === "Uint8Array"; } function uy(e, ...t) { if (!$R(e)) throw new Error("Uint8Array expected"); if (t.length > 0 && !t.includes(e.length)) throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`); } function OR(e) { if (typeof e != "function" || typeof e.create != "function") throw new Error("Hash should be wrapped by utils.wrapConstructor"); XE(e.outputLen), XE(e.blockLen); } function Sg(e, t = !0) { if (e.destroyed) throw new Error("Hash instance has been destroyed"); if (t && e.finished) throw new Error("Hash#digest() has already been called"); } function NR(e, t) { uy(e); const r = t.outputLen; if (e.length < r) throw new Error(`digestInto() expects output buffer of length at least ${r}`); } const Zl = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0; /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */ const k2 = (e) => new DataView(e.buffer, e.byteOffset, e.byteLength), Wi = (e, t) => e << 32 - t | e >>> t, G0 = (e, t) => e << t | e >>> 32 - t >>> 0; new Uint8Array(new Uint32Array([287454020]).buffer)[0]; function BR(e) { if (typeof e != "string") throw new Error(`utf8ToBytes expected string, got ${typeof e}`); return new Uint8Array(new TextEncoder().encode(e)); } function g3(e) { return typeof e == "string" && (e = BR(e)), uy(e), e; } function CR(...e) { let t = 0; for (let n = 0; n < e.length; n++) { const o = e[n]; uy(o), t += o.length; } const r = new Uint8Array(t); for (let n = 0, o = 0; n < e.length; n++) { const a = e[n]; r.set(a, o), o += a.length; } return r; } let Bk = class { // Safe version that clones internal state clone() { return this._cloneInto(); } }; function m3(e) { const t = (n) => e().update(g3(n)).digest(), r = e(); return t.outputLen = r.outputLen, t.blockLen = r.blockLen, t.create = () => e(), t; } function UR(e = 32) { if (Zl && typeof Zl.getRandomValues == "function") return Zl.getRandomValues(new Uint8Array(e)); if (Zl && typeof Zl.randomBytes == "function") return Zl.randomBytes(e); throw new Error("crypto.getRandomValues must be defined"); } function RR(e, t, r, n) { if (typeof e.setBigUint64 == "function") return e.setBigUint64(t, r, n); const o = BigInt(32), a = BigInt(4294967295), i = Number(r >> o & a), s = Number(r & a), c = n ? 4 : 0, l = n ? 0 : 4; e.setUint32(t + c, i, n), e.setUint32(t + l, s, n); } const zR = (e, t, r) => e & t ^ ~e & r, LR = (e, t, r) => e & t ^ e & r ^ t & r; let y3 = class extends Bk { constructor(t, r, n, o) { super(), this.blockLen = t, this.outputLen = r, this.padOffset = n, this.isLE = o, this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.buffer = new Uint8Array(t), this.view = k2(this.buffer); } update(t) { Sg(this); const { view: r, buffer: n, blockLen: o } = this; t = g3(t); const a = t.length; for (let i = 0; i < a; ) { const s = Math.min(o - this.pos, a - i); if (s === o) { const c = k2(t); for (; o <= a - i; i += o) this.process(c, i); continue; } n.set(t.subarray(i, i + s), this.pos), this.pos += s, i += s, this.pos === o && (this.process(r, 0), this.pos = 0); } return this.length += t.length, this.roundClean(), this; } digestInto(t) { Sg(this), NR(t, this), this.finished = !0; const { buffer: r, view: n, blockLen: o, isLE: a } = this; let { pos: i } = this; r[i++] = 128, this.buffer.subarray(i).fill(0), this.padOffset > o - i && (this.process(n, 0), i = 0); for (let f = i; f < o; f++) r[f] = 0; RR(n, o - 8, BigInt(this.length * 8), a), this.process(n, 0); const s = k2(t), c = this.outputLen; if (c % 4) throw new Error("_sha2: outputLen should be aligned to 32bit"); const l = c / 4, u = this.get(); if (l > u.length) throw new Error("_sha2: outputLen bigger than state"); for (let f = 0; f < l; f++) s.setUint32(4 * f, u[f], a); } digest() { const { buffer: t, outputLen: r } = this; this.digestInto(t); const n = t.slice(0, r); return this.destroy(), n; } _cloneInto(t) { t || (t = new this.constructor()), t.set(...this.get()); const { blockLen: r, buffer: n, length: o, finished: a, destroyed: i, pos: s } = this; return t.length = o, t.pos = s, t.finished = a, t.destroyed = i, o % r && t.buffer.set(n), t; } }; const jR = /* @__PURE__ */ new Uint8Array([7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8]), Ck = /* @__PURE__ */ new Uint8Array(new Array(16).fill(0).map((e, t) => t)), HR = /* @__PURE__ */ Ck.map((e) => (9 * e + 5) % 16); let b3 = [Ck], w3 = [HR]; for (let e = 0; e < 4; e++) for (let t of [b3, w3]) t.push(t[e].map((r) => jR[r])); const Uk = /* @__PURE__ */ [ [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8], [12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7], [13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9], [14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6], [15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5] ].map((e) => new Uint8Array(e)), FR = /* @__PURE__ */ b3.map((e, t) => e.map((r) => Uk[t][r])), MR = /* @__PURE__ */ w3.map((e, t) => e.map((r) => Uk[t][r])), DR = /* @__PURE__ */ new Uint32Array([ 0, 1518500249, 1859775393, 2400959708, 2840853838 ]), KR = /* @__PURE__ */ new Uint32Array([ 1352829926, 1548603684, 1836072691, 2053994217, 0 ]); function YE(e, t, r, n) { return e === 0 ? t ^ r ^ n : e === 1 ? t & r | ~t & n : e === 2 ? (t | ~r) ^ n : e === 3 ? t & n | r & ~n : t ^ (r | ~n); } const Z0 = /* @__PURE__ */ new Uint32Array(16); let VR = class extends y3 { constructor() { super(64, 20, 8, !0), this.h0 = 1732584193, this.h1 = -271733879, this.h2 = -1732584194, this.h3 = 271733878, this.h4 = -1009589776; } get() { const { h0: t, h1: r, h2: n, h3: o, h4: a } = this; return [t, r, n, o, a]; } set(t, r, n, o, a) { this.h0 = t | 0, this.h1 = r | 0, this.h2 = n | 0, this.h3 = o | 0, this.h4 = a | 0; } process(t, r) { for (let p = 0; p < 16; p++, r += 4) Z0[p] = t.getUint32(r, !0); let n = this.h0 | 0, o = n, a = this.h1 | 0, i = a, s = this.h2 | 0, c = s, l = this.h3 | 0, u = l, f = this.h4 | 0, h = f; for (let p = 0; p < 5; p++) { const y = 4 - p, m = DR[p], b = KR[p], v = b3[p], A = w3[p], E = FR[p], x = MR[p]; for (let S = 0; S < 16; S++) { const _ = G0(n + YE(p, a, s, l) + Z0[v[S]] + m, E[S]) + f | 0; n = f, f = l, l = G0(s, 10) | 0, s = a, a = _; } for (let S = 0; S < 16; S++) { const _ = G0(o + YE(y, i, c, u) + Z0[A[S]] + b, x[S]) + h | 0; o = h, h = u, u = G0(c, 10) | 0, c = i, i = _; } } this.set(this.h1 + s + u | 0, this.h2 + l + h | 0, this.h3 + f + o | 0, this.h4 + n + i | 0, this.h0 + a + c | 0); } roundClean() { Z0.fill(0); } destroy() { this.destroyed = !0, this.buffer.fill(0), this.set(0, 0, 0, 0, 0); } }; const Rk = /* @__PURE__ */ m3(() => new VR()), qR = /* @__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 ]), Ns = /* @__PURE__ */ new Uint32Array([ 1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225 ]), Bs = /* @__PURE__ */ new Uint32Array(64); let GR = class extends y3 { constructor() { super(64, 32, 8, !1), this.A = Ns[0] | 0, this.B = Ns[1] | 0, this.C = Ns[2] | 0, this.D = Ns[3] | 0, this.E = Ns[4] | 0, this.F = Ns[5] | 0, this.G = Ns[6] | 0, this.H = Ns[7] | 0; } get() { const { A: t, B: r, C: n, D: o, E: a, F: i, G: s, H: c } = this; return [t, r, n, o, a, i, s, c]; } // prettier-ignore set(t, r, n, o, a, i, s, c) { this.A = t | 0, this.B = r | 0, this.C = n | 0, this.D = o | 0, this.E = a | 0, this.F = i | 0, this.G = s | 0, this.H = c | 0; } process(t, r) { for (let f = 0; f < 16; f++, r += 4) Bs[f] = t.getUint32(r, !1); for (let f = 16; f < 64; f++) { const h = Bs[f - 15], p = Bs[f - 2], y = Wi(h, 7) ^ Wi(h, 18) ^ h >>> 3, m = Wi(p, 17) ^ Wi(p, 19) ^ p >>> 10; Bs[f] = m + Bs[f - 7] + y + Bs[f - 16] | 0; } let { A: n, B: o, C: a, D: i, E: s, F: c, G: l, H: u } = this;