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 { getCustomUtxoDecryptor as a } from "../../utils/customEnclaveFunctionsRegister.mjs";
import { ethers as o } from "ethers";
import { PublicKey as s } from "@solana/web3.js";
//#region libs/shared/common/src/functions/web3/events/getInputUtxosEnclave.ts
var c = (e) => {
	if (!e) return;
	let t = o.getBytes(e);
	if (t.length !== 32) return;
	let n = new s(t), r = n.toBase58(), { compressedAddress: a } = i(n);
	return {
		mintBase58: r,
		compressedAddress: a
	};
}, l = async (e, t, n) => {
	let { keyCiphertext: i, inputCiphertext: a } = await r(n);
	return e.getAPI().decryptUtxoEnclaveCall(t, i, a);
}, u = async (r, i, s) => {
	let u = s.getShieldedPrivateKey(), { privateKey: d, publicKey: f } = t.getEncryptionKeyPair(u), p = s.getSpendingKeyPair().pubSpendingBJJPoint, m = o.solidityPacked([
		"uint256",
		"uint256",
		"uint256"
	], [
		f,
		d,
		u
	]), h = o.getBytes(m), g = a(), { utxos: _, lastOutput: v, encryptedOutputs: y } = await (g ? g(i, h) : l(r, i, h));
	return {
		utxos: _.map((t) => {
			let r = t;
			if (e(i)) {
				let e = c(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,
				nullifyingKey: u,
				spendingPublicKey: p,
				isNewStyle: r.isNewStyle,
				H0: r.H0 ? [BigInt(r.H0[0]), BigInt(r.H0[1])] : void 0
			});
		}),
		encryptedOutputs: y,
		lastOutput: v
	};
};
//#endregion
export { u as getInputUtxosEnclave };
