import { a2 as u, a3 as y, __tla as __tla_0 } from "./App-BLnEEK_h.js";
import { b as l } from "./request-fingerprint-BANtRL63.js";
import "./Logo1am-CaBWyNpM.js";
import "./_virtual_wxt-plugins-CDnz5Vh6.js";
import "./__vite-plugin-wasm-helper-D7K_KhUE.js";
import { __tla as __tla_1 } from "./cardano-e2kMgYtl.js";
let S, T, _, C;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_1;
        } catch  {}
    })()
]).then(async ()=>{
    function c(n) {
        return n.startsWith("0x") || n.startsWith("0X") ? n.slice(2) : n;
    }
    S = function(n) {
        try {
            const a = l.decodeToBytes(n), r = a.prefix.split("_");
            if (r[0] !== "mn" || r[1] !== "addr") return null;
            const i = Array.from(a.bytes).map((e)=>e.toString(16).padStart(2, "0")).join("");
            return i.length === 66 ? i : `00${i}`;
        } catch  {
            return null;
        }
    };
    T = function(n) {
        if (typeof n != "string" || n.length === 0) return [];
        try {
            const a = u.deserialize("signature", "proof", "binding", y(n));
            return Array.from(new Set(a.identifiers().map((r)=>c(String(r))).filter((r)=>r.length > 0)));
        } catch  {
            return [];
        }
    };
    C = async function(n, a) {
        if (!n || a.length === 0) return null;
        for (const r of a){
            const i = c(r);
            if (i) try {
                const e = await fetch(n, {
                    method: "POST",
                    headers: {
                        "Content-Type": "application/json"
                    },
                    signal: AbortSignal.timeout(1e4),
                    body: JSON.stringify({
                        query: `
            query TransactionStatus($transactionId: HexEncoded!) {
              transactions(offset: { identifier: $transactionId }) {
                __typename
                ... on RegularTransaction {
                  hash
                  transactionResult { status }
                }
              }
            }
          `,
                        variables: {
                            transactionId: i
                        }
                    })
                });
                if (!e.ok) continue;
                const s = (await e.json())?.data?.transactions?.find((f)=>f?.__typename === "RegularTransaction"), o = s?.hash, d = s?.transactionResult?.status;
                if (typeof o == "string" && o.length === 64) return {
                    hash: o,
                    status: typeof d == "string" ? d : "SUCCESS"
                };
            } catch  {}
        }
        return null;
    };
    _ = async function(n, a) {
        if (!n || !a) return [];
        try {
            const r = await fetch(n, {
                method: "POST",
                headers: {
                    "Content-Type": "application/json"
                },
                signal: AbortSignal.timeout(1e4),
                body: JSON.stringify({
                    query: `
          query GetPublicActivity($identifier: HexEncoded!) {
            transactions(offset: { identifier: $identifier }) {
              __typename
              ... on RegularTransaction {
                hash
                identifiers
                block { timestamp }
                transactionResult { status }
                contractActions {
                  __typename
                  ... on ContractCall { address entryPoint }
                  ... on ContractDeploy { address }
                  ... on ContractUpdate { address }
                }
              }
            }
          }
        `,
                    variables: {
                        identifier: a
                    }
                })
            });
            if (!r.ok) return [];
            const i = await r.json();
            return (Array.isArray(i?.data?.transactions) ? i.data.transactions : []).filter((t)=>t?.__typename === "RegularTransaction" && Array.isArray(t.contractActions) && t.contractActions.length > 0).map((t)=>{
                const s = t.contractActions[0] ?? {};
                return {
                    hash: t.hash ?? "",
                    status: typeof t.transactionResult?.status == "string" ? t.transactionResult.status : "SUCCESS",
                    createdAt: typeof t.block?.timestamp == "number" ? t.block.timestamp : typeof t.block?.timestamp == "string" ? Number(t.block.timestamp) : Date.now(),
                    identifiers: Array.isArray(t.identifiers) ? t.identifiers.filter((o)=>typeof o == "string").map(c) : [],
                    contractAddress: typeof s.address == "string" ? s.address : void 0,
                    entryPoint: typeof s.entryPoint == "string" ? s.entryPoint : void 0
                };
            }).filter((t)=>t.hash.length === 64).sort((t, s)=>s.createdAt - t.createdAt);
        } catch  {
            return [];
        }
    };
});
export { S as buildMidnightPublicActivityIdentifier, T as extractMidnightTxIdentifiers, _ as fetchMidnightPublicContractInteractions, C as lookupMidnightTxByIdentifiers, __tla };
