import { chainIds as e } from "../../constants/chains.constants.mjs";
import { randomBigInt as t } from "../web3/etherFunctions.mjs";
import { poseidonFunction as n } from "../../crypto/poseidon.mjs";
import { takeOffHighestBit as r } from "../utils/bit.operations.mjs";
import { formatMintAddress as i } from "../utils/solanaMint.utils.mjs";
import { buildOutCommitments as a, calcAmountChanges as ee, calcStealthAddressStructure as o, getUtxoCircuitH0Coords as s, getUtxoCircuitInRandomization as c } from "./common.snarkjs.mjs";
import { encodeToByte32Array as l } from "../pre-transaction/solana.mjs";
import { computeSignedMessageHashSolana as u } from "./signedMessageHash.mjs";
import { generateZkProof as d } from "./generateZkProof.mjs";
import "../pre-transaction/index.mjs";
import "../utils/index.mjs";
import { getDataFromWorkers as f } from "./getMerkleTreeSiblingsAndRootHashes.mjs";
import { getSolanaCalldataHash as p } from "../pre-transaction/getSolanaCalldataHash.mjs";
import "../web3/index.mjs";
import { PublicKey as m } from "@solana/web3.js";
//#region libs/shared/common/src/functions/snarkjs/constructSolanaZkProof.ts
var h = async (h, g, _, te, v, y, b, x, S, C, w, T, E, D = e.solanaLocalnet, O = [], k = [], A = 0n) => {
	let j = new m(C), M = new m(w), N = _.getShieldedPrivateKey(), { pubSpendingBJJPoint: P } = _.getSpendingKeyPair(), F = o(b, N, _.getSpendingKeyPair().pubSpendingBJJPoint), I = t(31), L = n(I), R = n(A), z = te.map((e) => i(e)), B = z.map((e) => e.mintAccountPart1), V = z.map((e) => e.mintAccountPart2), H = p(T, j, M, E, x, S, O, k), U = `${T.tokenNumber}x${T.nullifierAmount}x${T.outputAmount}`, W = ee(v, y), { inCommitmentSiblings: G, inCommitmentSiblingSides: K, rootHashHinkal: q, inNullifiers: J } = await f(D, g, v.map((e) => e.map((e) => e.getConstructableParams()))), Y = a(y), X = r(F.extraRandomization), Z = F.H0, Q = u({
		rootHashHinkal: q,
		mintAccountPart1: B,
		mintAccountPart2: V,
		amountChanges: W,
		outTimeStamp: BigInt(y[0][0].timeStamp),
		inNullifiers: J,
		outCommitments: Y,
		calldataHash: H,
		message: L,
		swapperAccountAdditionalSeed: R,
		outH1Ay: F.H1,
		H0Ax: X,
		H0Ay: Z
	}), { R8: $, S: ne } = _.signEddsa(Q), re = {
		rootHashHinkal: q,
		spendingPublicKey: P,
		eddsaSignature: [
			$[0],
			$[1],
			ne
		],
		signedMessageHash: Q,
		nullifyingPrivateKey: N,
		mintAccountPart1: B,
		mintAccountPart2: V,
		amountChanges: W,
		inAmounts: v.map((e) => e.map((e) => e.amount.toString())),
		inRandomizations: v.map((e) => e.map((e) => c(e))),
		inH0Ax: v.map((e) => e.map((e) => s(e)[0].toString())),
		inH0Ay: v.map((e) => e.map((e) => s(e)[1].toString())),
		isNewStyle: v.map((e) => e.map((e) => !!e.isNewStyle)),
		inTimeStamps: v.map((e) => e.map((e) => e.timeStamp)),
		inNullifiers: J,
		inCommitmentSiblings: G,
		inCommitmentSiblingSides: K,
		outAmounts: y.map((e) => e.map((e) => e.amount.toString())),
		outTimeStamp: BigInt(y[0][0].timeStamp),
		outPublicKeys: y.map((e) => e.map((e) => e.getStealthAddress())),
		outCommitments: Y,
		calldataHash: H,
		messageSeed: I,
		swapperAccountSalt: A,
		H0Ax: X,
		H0Ay: Z
	}, { publicSignals: ie, zkCallData: ae } = await d(D, `mainSolanaCircuit${U}`, re, h), [oe, se, ce] = ae;
	return {
		proofAArr: oe.map(BigInt).map(l).flat(),
		proofBArr: se.flat().map(BigInt).map(l).flat(),
		proofCArr: ce.map(BigInt).map(l).flat(),
		publicInputsArr: ie.map(BigInt).map(l)
	};
};
//#endregion
export { h as constructSolanaZkProof };
