import { isSolanaLike as e } from "../../../constants/chains.constants.mjs";
import { UserKeys as t } from "../../../data-structures/crypto-keys/keys.mjs";
import { Utxo as n } from "../../../data-structures/utxo/Utxo.mjs";
import { makeEnclaveHandshakeAndEncryptUint8Array as r } from "../../utils/encryptInputForEnclave.mjs";
import { formatMintAddress as i } from "../../utils/solanaMint.utils.mjs";
import { ethers as a } from "ethers";
import { PublicKey as o } from "@solana/web3.js";
//#region libs/shared/common/src/functions/web3/events/getInputUtxosEnclave.ts
var s = (e) => {
	if (!e) return;
	let t = a.getBytes(e);
	if (t.length !== 32) return;
	let n = new o(t), r = n.toBase58(), { compressedAddress: s } = i(n);
	return {
		mintBase58: r,
		compressedAddress: s
	};
}, c = async (i, o, c) => {
	let l = c.getShieldedPrivateKey(), { privateKey: u, publicKey: d } = t.getEncryptionKeyPair(l), f = a.solidityPacked([
		"uint256",
		"uint256",
		"uint256"
	], [
		d,
		u,
		l
	]), { keyCiphertext: p, inputCiphertext: m } = await r(a.getBytes(f)), { utxos: h, lastOutput: g, encryptedOutputs: _ } = await i.getAPI().decryptUtxoEnclaveCall(o, p, m);
	return {
		utxos: h.map((t) => {
			let r = t;
			if (e(o)) {
				let e = s(t.mintAddress);
				if (!e) throw Error("Invalid mint address");
				r = {
					...r,
					erc20TokenAddress: e.compressedAddress,
					mintAddress: e.mintBase58
				};
			}
			return new n({
				...r,
				amount: BigInt(r.amount),
				randomization: r.randomization ? BigInt(r.randomization) : void 0,
				shieldedPrivateKey: l
			});
		}),
		encryptedOutputs: _,
		lastOutput: g
	};
};
//#endregion
export { c as getInputUtxosEnclave };
