const e=require(`../../constants/vite.constants.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../utils/amounts.utils.cjs`),r=require(`../../webworker/worker.registry.cjs`),i=require(`../../webworker/performTaskWithWorker.cjs`),a=require(`../../webworker/zkProofWorker/zkProofWorker.types.cjs`),o=require(`./fetchMerkleTreeSiblings.cjs`),s=require(`./fetchOnChainRootHashes.cjs`);var c=async(t,n)=>{let o=t.getRootHash();if(o===void 0)throw Error(`Root hash not available from hinkal merkle tree`);let s;return s=(e.isNode,await i.performTaskWithWorker({type:r.WorkerVariant.ZKProof,payload:{type:a.ZKProofWorkerActionType.CALC_COMMITMENTS_SIBLING_AND_SIDES,data:{inputUtxosSerialized:n,merkleTreeSerialized:t.toJSON()}}})),{inCommitmentSiblings:s.inCommitmentSiblings,inCommitmentSiblingSides:s.inCommitmentSiblingSides,rootHashHinkal:o}},l=async(e,t)=>{let r=await o.fetchMerkleTreeSiblings(e,t);return{inCommitmentSiblings:r.inCommitmentSiblings,inCommitmentSiblingSides:r.inCommitmentSiblingSides,rootHashHinkal:n.toBigInt(r.rootHashHinkal)}},u=async(e,t)=>{if(!t)return!1;try{let n=t.getRootHash();if(n===void 0)return!1;let{hinkalRootHash:r}=await s.fetchOnChainRootHashes(e);return n===r}catch{return!1}},d=async(e,n,r)=>await u(e,r)||t.isLocalNetwork(e)?c(r,n):l(e,n),f=async(t,n,o)=>{if(e.isNode){let{inCommitmentSiblings:e,inCommitmentSiblingSides:s,rootHashHinkal:c}=await d(t,o,n);return{inCommitmentSiblings:e,inCommitmentSiblingSides:s,rootHashHinkal:c,inNullifiers:await i.performTaskWithWorker({type:r.WorkerVariant.ZKProof,payload:{type:a.ZKProofWorkerActionType.BUILD_IN_NULLIFIERS,data:{inputUtxosSerialized:o}}})}}else{let[{inCommitmentSiblings:e,inCommitmentSiblingSides:s,rootHashHinkal:c},l]=await Promise.all([d(t,o,n),i.performTaskWithWorker({type:r.WorkerVariant.ZKProof,payload:{type:a.ZKProofWorkerActionType.BUILD_IN_NULLIFIERS,data:{inputUtxosSerialized:o}}})]);return{inCommitmentSiblings:e,inCommitmentSiblingSides:s,rootHashHinkal:c,inNullifiers:l}}};exports.getDataFromWorkers=f;