import { httpClient as e } from "../../data-structures/http/HttpClient.mjs";
import { convertBytes32ToBigInt as t } from "../utils/bytes32.utils.mjs";
import { deserializeCircomData as n } from "./common.snarkjs.mjs";
import { getVKFile as r } from "./getZKFiles.mjs";
import { convertSolanaPublicSignals as i } from "../pre-transaction/solana-public-signals.mjs";
import { ethers as a } from "ethers";
import * as o from "snarkjs";
//#region libs/shared/common/src/functions/snarkjs/verifyCommitmentValidationData.ts
var s = (e) => e.flat().map((e) => BigInt(e).toString()), c = (e, t) => {
	let n = t.inNullifiers[0]?.length ?? 0;
	return r(`commitmentCalculator${t.tokenAddresses.length}x${n}`, e);
}, l = async (t, n) => {
	let r = c(t, n);
	return e.get(r);
}, u = (e) => ({
	pi_a: [...e.a],
	pi_b: [[e.b[0][1], e.b[0][0]], [e.b[1][1], e.b[1][0]]],
	pi_c: [...e.c],
	protocol: "groth16"
}), d = (e) => {
	let t = e.tokenAddresses.map((e) => a.getBigInt(e).toString()), n = s(e.inCommitments), r = s(e.inNullifiers);
	return [
		...t,
		...n,
		...r
	];
}, f = async (e, t, n) => {
	if (s(t.inNullifiers).join(",") !== n.join(",")) throw Error("commitmentValidationData.inNullifiers mismatch with request input");
	let r = await l(e, t), i = d(t), a = u(t.proof);
	if (!await o.groth16.verify(r, i, a)) throw Error("Invalid commitment validation proof");
}, p = async (e) => {
	let t = e.commitmentValidationData;
	if (!t) return;
	let r = s(n(e.circomData).inputNullifiers);
	await f(e.chainId, t, r);
}, m = async (e) => {
	let n = e.commitmentValidationData;
	if (!n) return;
	let r = i(e.args.publicInputsArr, e.args.dimensions).inNullifiers.flat().map((e) => t(e).toString());
	await f(e.chainId, n, r);
};
//#endregion
export { p as verifyCommitmentValidationData, m as verifyCommitmentValidationDataSolana };
