import { isSolanaLike as e } from "../../constants/chains.constants.mjs";
import { UserKeys as t } from "../../data-structures/crypto-keys/keys.mjs";
import { formatMintAddress as n } from "../utils/solanaMint.utils.mjs";
import { WorkerVariant as r } from "../../webworker/worker.registry.mjs";
import { performTaskWithWorker as i } from "../../webworker/performTaskWithWorker.mjs";
import { generateZkProof as a } from "../snarkjs/generateZkProof.mjs";
import { ZKProofWorkerActionType as o } from "../../webworker/zkProofWorker/zkProofWorker.types.mjs";
//#region libs/shared/common/src/functions/pre-transaction/buildCommitmentValidationData.ts
var s = async (s, c, l, u) => {
	let d = e(s), f = u.map((e) => e.map((e) => e.amount.toString())), p = u.map((e) => e.map((e) => e.timeStamp)), m = u.map((e) => e.map((e) => e.randomization.toString())), h = u.map((e) => e.map((e) => e.getConstructableParams())), g = u.map((e) => e.map((e) => e.amount === 0n ? "0" : BigInt(e.getCommitment()).toString())), _ = await i({
		type: r.ZKProof,
		payload: {
			type: o.BUILD_IN_NULLIFIERS,
			data: { inputUtxosSerialized: h }
		}
	}), v = c.getShieldedPrivateKey(), y = d ? l.map((e) => {
		let { compressedAddress: t } = n(e);
		return BigInt(t).toString();
	}) : l.map((e) => BigInt(e).toString());
	u.forEach((e, n) => {
		e.forEach((e, r) => {
			let i = e.getStealthAddress(), a = t.getStealthAddress(e.randomization, v);
			if (BigInt(i).toString() !== BigInt(a).toString()) throw Error(`Commitment validation stealth mismatch at tokenIdx=${n}, utxoIdx=${r}`);
		});
	});
	let b = {
		shieldedPrivateKey: v,
		erc20TokenAddresses: y,
		inAmounts: f,
		inTimeStamps: p,
		inRandomizations: m,
		inCommitments: g,
		inNullifiers: _
	};
	if (!l.length || !u[0]?.length) return;
	let { zkCallData: x } = await a(s, `commitmentCalculator${l.length}x${u[0].length}`, b, !1);
	if (!Array.isArray(x?.[0]) || !Array.isArray(x?.[1]) || !Array.isArray(x?.[2])) throw Error("Invalid zkCallData shape for commitment validation");
	return {
		tokenAddresses: y,
		inAmounts: f,
		inTimeStamps: p,
		inRandomizations: m,
		inCommitments: g,
		inNullifiers: _,
		proof: {
			a: x[0],
			b: x[1],
			c: x[2]
		}
	};
};
//#endregion
export { s as buildCommitmentValidationData };
