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 { getUtxoCircuitH0Coords as r, getUtxoCircuitInRandomization as i } from "../snarkjs/common.snarkjs.mjs";
import { WorkerVariant as a } from "../../webworker/worker.registry.mjs";
import { performTaskWithWorker as o } from "../../webworker/performTaskWithWorker.mjs";
import { generateZkProof as s } from "../snarkjs/generateZkProof.mjs";
import { ZKProofWorkerActionType as c } from "../../webworker/zkProofWorker/zkProofWorker.types.mjs";
//#region libs/shared/common/src/functions/pre-transaction/buildCommitmentValidationData.ts
var l = async (l, u, d, f) => {
	let p = e(l), m = f.map((e) => e.map((e) => e.amount.toString())), h = f.map((e) => e.map((e) => e.timeStamp)), g = f.map((e) => e.map((e) => i(e))), _ = f.map((e) => e.map((e) => e.getConstructableParams())), v = f.map((e) => e.map((e) => e.amount === 0n ? "0" : BigInt(e.getCommitment()).toString())), y = await o({
		type: a.ZKProof,
		payload: {
			type: c.BUILD_IN_NULLIFIERS,
			data: { inputUtxosSerialized: _ }
		}
	}), b = u.getShieldedPrivateKey(), x = u.getSpendingKeyPair().pubSpendingBJJPoint, S = p ? d.map((e) => {
		let { compressedAddress: t } = n(e);
		return BigInt(t).toString();
	}) : d.map((e) => BigInt(e).toString());
	f.forEach((e, n) => {
		e.forEach((e, r) => {
			let i = e.getStealthAddress(), a = e.spendingPublicKey ?? x, o = e.isNewStyle && e.H0 ? t.getStealthAddressNewStyle(e.H0, b, a) : t.getStealthAddress(BigInt(e.randomization), b);
			if (BigInt(i).toString() !== BigInt(o).toString()) throw Error(`Commitment validation stealth mismatch at tokenIdx=${n}, utxoIdx=${r}`);
		});
	});
	let C = {
		nullifyingPrivateKey: b,
		spendingPublicKey: x,
		erc20TokenAddresses: S,
		inAmounts: m,
		inRandomizations: g,
		inH0Ax: f.map((e) => e.map((e) => r(e)[0].toString())),
		inH0Ay: f.map((e) => e.map((e) => r(e)[1].toString())),
		isNewStyle: f.map((e) => e.map((e) => !!e.isNewStyle)),
		inTimeStamps: h,
		inCommitments: v,
		inNullifiers: y
	};
	if (!d.length || !f[0]?.length) return;
	let { zkCallData: w } = await s(l, `commitmentCalculator${d.length}x${f[0].length}`, C, !1);
	if (!Array.isArray(w?.[0]) || !Array.isArray(w?.[1]) || !Array.isArray(w?.[2])) throw Error("Invalid zkCallData shape for commitment validation");
	return {
		tokenAddresses: S,
		inAmounts: m,
		inTimeStamps: h,
		inRandomizations: g,
		inCommitments: v,
		inNullifiers: y,
		proof: {
			a: w[0],
			b: w[1],
			c: w[2]
		}
	};
};
//#endregion
export { l as buildCommitmentValidationData };
