const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../types/hinkal.types.cjs`),r=require(`../web3/etherFunctions.cjs`),i=require(`../../data-structures/utxo/Utxo.cjs`),a=require(`../../error-handling/logger.cjs`),o=require(`./common.snarkjs.cjs`),s=require(`./generateCircomData.cjs`),c=require(`./generateZkProof.cjs`),l=require(`../utils/fees.utils.cjs`),u=require(`../../data-structures/Hinkal/hinkalCheckTokenRegistry.cjs`),d=require(`./getMerkleTreeSiblingsAndRootHashes.cjs`);var f=async(f,p,m,h,g,_,v,y,b,x,S=t.zeroAddress,C=e.chainIds.localhost,w=m.map(()=>!1),T=m.map(()=>0n),E=void 0,D=!1,O,k=void 0,A,j=t.defaultSignatureData,M)=>{let N=o.calcAmountChanges(m,h),P=m.map(e=>e[0].erc20TokenAddress),F=o.calcEncryptedOutputs(h),I=g.getShieldedPrivateKey(),L=i.Utxo.findCorrectRandomization(r.randomBigInt(31),I),R=e.isTronLike(C)?await u.hinkalCheckTronTokenRegistry(P,o.calcAmountChanges(m,h,!0),C):await u.hinkalCheckTokenRegistry(A??u.createHinkalHelperFromData(C),P,o.calcAmountChanges(m,h,!0)),z=e.isTronLike(C)?D||R:D,{inCommitmentSiblings:B,inCommitmentSiblingSides:V,accessTokenSiblings:H,accessTokenSiblingSides:U,rootHashHinkal:W,rootHashAccessToken:G,inNullifiers:K}=await d.getDataFromWorkers(C,f,p,g,m.map(e=>e.map(e=>e.getConstructableParams())),z,R),q=o.buildOutCommitments(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.calcPublicSignalCount(_,J.erc20TokenAddresses,J.amountChanges,J.inNullifiers,J.outCommitments,X),Q=n.defaultHinkalLogicArgs(N.length,g);J.interactionAddress=Q.interactionAddress,J.externalApprovalAddresses=Q.useApprovalUtxoData?.map(({externalApprovalAddresses:e})=>e),k||=l.generateFeeStructure(T,m.map(e=>e[0].erc20TokenAddress));let $=o.calcAmountChanges(m,h,!0);O||=o.getSlippageValues($),a.Logger.log({publicSignalCount:Z}),J.calldataHash=o.createCallDataHash(Z,S,y,v,b,F,T,E,O,w,Q,k,j,M);let{zkCallData:ee}=await c.generateZkProof(C,_,J,x),te=o.calcStealthAddressStructure(L,I);return{zkCallData:ee,circomData:s.generateCircomData(q,K,W,G,$,P,h,F,Z,v,y,b,S,J.calldataHash,Y,te,w,E,void 0,Q,O,k,j,M),dimData:{tokenNumber:m.length,nullifierAmount:m[0].length,outputAmount:h[0].length},encryptedOutputs:F}};exports.constructZkProof=f;