import { chainIds as e, isTronLike as t } from "../../constants/chains.constants.mjs";
import { defaultSignatureData as n, zeroAddress as r } from "../../constants/protocol.constants.mjs";
import { defaultHinkalLogicArgs as ee } from "../../types/hinkal.types.mjs";
import { randomBigInt as te } from "../web3/etherFunctions.mjs";
import { Utxo as ne } from "../../data-structures/utxo/Utxo.mjs";
import { Logger as re } from "../../error-handling/logger.mjs";
import { buildOutCommitments as ie, calcAmountChanges as i, calcEncryptedOutputs as a, calcPublicSignalCount as o, calcStealthAddressStructure as s, createCallDataHash as ae, getSlippageValues as c } from "./common.snarkjs.mjs";
import { generateCircomData as oe } from "./generateCircomData.mjs";
import { generateZkProof as se } from "./generateZkProof.mjs";
import { generateFeeStructure as ce } from "../utils/fees.utils.mjs";
import { createHinkalHelperFromData as l, hinkalCheckTokenRegistry as u, hinkalCheckTronTokenRegistry as le } from "../../data-structures/Hinkal/hinkalCheckTokenRegistry.mjs";
import { getDataFromWorkers as d } from "./getMerkleTreeSiblingsAndRootHashes.mjs";
//#region libs/shared/common/src/functions/snarkjs/constructGeneralZkProof.ts
var f = async (f, p, m, h, g, _, v, y, b, x, S = r, C = e.localhost, w = m.map(() => !1), T = m.map(() => 0n), E = void 0, D = !1, O, k = void 0, A, j = n, M) => {
	let N = i(m, h), P = m.map((e) => e[0].erc20TokenAddress), F = a(h), I = g.getShieldedPrivateKey(), L = ne.findCorrectRandomization(te(31), I), R = t(C) ? await le(P, i(m, h, !0), C) : await u(A ?? l(C), P, i(m, h, !0)), z = t(C) ? D || R : D, { inCommitmentSiblings: B, inCommitmentSiblingSides: V, accessTokenSiblings: H, accessTokenSiblingSides: U, rootHashHinkal: W, rootHashAccessToken: G, inNullifiers: K } = await d(C, f, p, g, m.map((e) => e.map((e) => e.getConstructableParams())), z, R), q = ie(h), J = {
		rootHashHinkal: W,
		shieldedPrivateKey: I,
		erc20TokenAddresses: P,
		inAmounts: m.map((e) => e.map((e) => e.amount.toString())),
		inTimeStamps: m.map((e) => e.map((e) => e.timeStamp)),
		inRandomizations: m.map((e) => e.map((e) => e.randomization)),
		inNullifiers: K,
		inCommitmentSiblings: B,
		inCommitmentSiblingSides: V,
		outAmounts: h.map((e) => e.map((e) => e.amount.toString())),
		outTimeStamp: BigInt(h[0][0].timeStamp),
		outPublicKeys: h.map((e) => e.map((e) => e.getStealthAddress())),
		extraRandomization: L,
		amountChanges: N,
		outCommitments: q,
		rootHashAccessToken: G,
		accessTokenSiblings: H,
		accessTokenSiblingSides: U,
		calldataHash: 0n
	}, Y = m.map((e) => e[0].tokenId ?? 0), X = Y.reduce((e, t) => e + t, 0) > 0 ? Y.length : 0;
	X > 0 && (J.tokenIds = Y);
	let Z = o(_, J.erc20TokenAddresses, J.amountChanges, J.inNullifiers, J.outCommitments, X), Q = ee(N.length, g);
	J.interactionAddress = Q.interactionAddress, J.externalApprovalAddresses = Q.useApprovalUtxoData?.map(({ externalApprovalAddresses: e }) => e), k ||= ce(T, m.map((e) => e[0].erc20TokenAddress));
	let $ = i(m, h, !0);
	O ||= c($), re.log({ publicSignalCount: Z }), J.calldataHash = ae(Z, S, y, v, b, F, T, E, O, w, Q, k, j, M);
	let { zkCallData: ue } = await se(C, _, J, x), de = s(L, I);
	return {
		zkCallData: ue,
		circomData: oe(q, K, W, G, $, P, h, F, Z, v, y, b, S, J.calldataHash, Y, de, w, E, void 0, Q, O, k, j, M),
		dimData: {
			tokenNumber: m.length,
			nullifierAmount: m[0].length,
			outputAmount: h[0].length
		},
		encryptedOutputs: F
	};
};
//#endregion
export { f as constructZkProof };
