import { networkRegistry as e } from "../../constants/chains.constants.mjs";
import { caseInsensitiveEqual as t } from "./caseInsensitive.utils.mjs";
import { poseidonHash as n } from "../../crypto/poseidon.mjs";
import { convertBytes32ToBigInt as r } from "./bytes32.utils.mjs";
import { Utxo as i } from "../../data-structures/utxo/Utxo.mjs";
import { extractHighestBit as a, takeOffHighestBit as o } from "./bit.operations.mjs";
import { decryptUtxo as s } from "../../data-structures/crypto-keys/encryptDecryptUtxo.mjs";
import { ethers as c } from "ethers";
import { PublicKey as l } from "@solana/web3.js";
import { BorshCoder as u, EventParser as d } from "@coral-xyz/anchor";
//#region libs/shared/common/src/functions/utils/getUtxosFromReceiptSolana.ts
var f = (e) => e instanceof Uint8Array ? e : Array.isArray(e) ? Uint8Array.from(e) : new Uint8Array(e), p = (e, s, f, p) => [...new d(s.programId, new u(s.idl)).parseLogs(e.meta?.logMessages ?? [])].filter(({ name: e }) => t(e, "newCommitment")).filter(({ data: e }) => e.encryptedOutput.length === 0).map((e) => {
	let { onChainData: t } = e.data, [s, u, d, p, m, h, , g] = t.map(r), [, _, v] = t, y = new l([..._.slice(16), ...v.slice(16)]), b = n(u, d), x = a(p) === 1n, S = new i({
		amount: s,
		timeStamp: g.toString(),
		nullifyingKey: f.getShieldedPrivateKey(),
		mintAddress: y.toBase58(),
		erc20TokenAddress: b,
		stealthAddress: c.toBeHex(m),
		isNewStyle: x,
		...x ? { H0: [o(p), h] } : { randomization: p }
	});
	return S.getStealthAddress(), S;
}).filter((e) => t(e.erc20TokenAddress, p)), m = (e, n, r, i) => [...new d(n.programId, new u(n.idl)).parseLogs(e.meta?.logMessages ?? [])].filter(({ name: e }) => t(e, "newCommitment")).filter(({ data: e }) => e.encryptedOutput?.length > 0).map((e) => {
	let { encryptedOutput: t } = e.data, n = f(t);
	try {
		let e = s(n, r);
		return e.getStealthAddress(), e;
	} catch {
		return null;
	}
}).filter((e) => e !== null).filter((e) => t(e.erc20TokenAddress, i)), h = (n, i) => {
	let { contractData: a } = e[n], { hinkalIdl: o, hinkalAddress: s } = a;
	if (!o || !s) throw Error(`Missing Solana Hinkal data for chainId ${n}`);
	return [...new d(new l(s), new u(o)).parseLogs(i.meta?.logMessages ?? [])].filter(({ name: e }) => t(e, "newCommitment")).map(({ data: e }) => {
		try {
			return r(e.commitment).toString();
		} catch {
			return null;
		}
	}).filter((e) => e !== null);
};
//#endregion
export { p as getOnChainUtxosFromReceiptSolana, h as getOutputCommitmentsFromSolanaReceipt, m as getUtxosFromReceiptSolana };
