const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../constants/protocol.constants.cjs`),r=require(`../../functions/utils/caseInsensitive.utils.cjs`),i=require(`../../error-handling/error-codes.constants.cjs`),a=require(`../crypto-keys/keys.cjs`),o=require(`../../functions/utils/time.utils.cjs`),s=require(`../utxo/Utxo.cjs`),c=require(`../../functions/utils/tron.utils.cjs`),l=require(`../../functions/utils/token-check.utils.cjs`),u=require(`../../functions/pre-transaction/outputUtxoProcessing.cjs`),d=require(`../../functions/pre-transaction/getFeeStructure.cjs`),f=require(`../../functions/pre-transaction/buildCommitmentValidationData.cjs`);require(`../../functions/pre-transaction/index.cjs`);const p=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),m=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`);var h=async(h,g,_,v,y)=>{let b=l.validateAndGetChainId([g]),x=t.isTronLike(b),S=g.erc20TokenAddress,C=c.addressToHexFormat(await h.getEthereumAddressByChain(b));if(!r.caseInsensitiveEqual(S,_.erc20TokenAddress))throw Error(`Off-chain UTXO token mismatch`);let w=y?new a.UserKeys(y):new a.UserKeys(_.nullifyingKey,_.nullifyingKey);if(!_.nullifyingKey&&!y)throw Error(`Claimable UTXO nullifyingKey is missing`);let T=w.getShieldedPrivateKey();if(_.nullifyingKey&&_.nullifyingKey!==T)throw Error(`Claimable UTXO key mismatch`);let E=h.getRecipientInfo(),D=s.Utxo.createFrom(_,{nullifyingKey:T}),O=new s.Utxo({amount:0n,erc20TokenAddress:D.erc20TokenAddress,mintAddress:D.mintAddress,nullifyingKey:T,...D.isNewStyle?{spendingPublicKey:w.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}:{isNewStyle:!1}}),k=[S],A=v??await d.getFeeStructure(b,S,[S],e.ExternalActionId.Transact);if(!r.caseInsensitiveEqual(A.feeToken,S))throw Error(`Claim fee token mismatch: fee must be paid from claimed UTXO token`);let j=A.variableRate>0n?A.variableRate:n.HINKAL_PRIVATE_SEND_VARIABLE_RATE;if(D.amount<=A.flatFee)throw Error(i.transactionErrorCodes.INSUFFICIENT_FUNDS_TO_TRANSACT);let M=D.amount-A.flatFee,N=M*j/10000n,P=M-N;if(P<=0n)throw Error(i.transactionErrorCodes.RECIPIENT_AMOUNT_INVALID);let F={feeToken:A.feeToken,flatFee:A.flatFee+N,variableRate:0n},I=[-D.amount],L=await h.getRandomRelay(b,!0);if(!L)throw Error(i.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let R={externalActionId:0n,externalAddress:L??C,externalActionMetadata:`0x00`},z=[[D,O]],B=[],V=o.getCurrentTimeInSeconds().toString(),{outputUtxos:H}=u.outputUtxoProcessing(w,z[0],I[0],V,!0,E,P);B.push(H);let[{zkCallData:U,circomData:W,dimData:G},K]=await Promise.all([p.constructZkProof(h.merkleTreeHinkalByChain[b],z,B,w,R.externalActionId,R.externalAddress,R.externalActionMetadata,h.generateProofRemotely,F,L,b),f.buildCommitmentValidationData(b,w,k,z)]);return m.transactCallRelayer(b,U,G,W,K,void 0,void 0,void 0,await c.reorderZkCallData(x,U,G,W))};exports.hinkalClaimUtxo=h;