const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../crypto/poseidon.cjs`),r=require(`../../functions/web3/etherFunctions.cjs`),i=require(`../crypto-keys/keys.cjs`),a=require(`../../functions/utils/time.utils.cjs`);var o=class o{amount;erc20TokenAddress;mintAddress;timeStamp;tokenId;shieldedPrivateKey;randomization;stealthAddress;encryptionKey;commitment;nullifier;isBlocked;constructor({amount:e,erc20TokenAddress:t,mintAddress:n,timeStamp:i,tokenId:s,shieldedPrivateKey:c,randomization:l,stealthAddress:u,encryptionKey:d,commitment:f=void 0,nullifier:p=void 0,isBlocked:m=!1}){this.amount=e,this.erc20TokenAddress=t,this.mintAddress=n,this.timeStamp=i??a.getCurrentTimeInSeconds().toString(),this.tokenId=s??0,this.shieldedPrivateKey=c,this.randomization=l??o.findCorrectRandomization(r.randomBigInt(31),c),this.stealthAddress=u,this.encryptionKey=d,this.commitment=f,this.nullifier=p,this.isBlocked=m}static createFrom(e,t){return new o({...e.getConstructableParams(),nullifier:void 0,commitment:void 0,...t})}getConstructableParams(){return{amount:this.amount,erc20TokenAddress:this.erc20TokenAddress,mintAddress:this.mintAddress,timeStamp:this.timeStamp,shieldedPrivateKey:this.shieldedPrivateKey,randomization:this.randomization,stealthAddress:this.stealthAddress,encryptionKey:this.encryptionKey,tokenId:this.tokenId,commitment:this.commitment,nullifier:this.nullifier,isBlocked:this.isBlocked}}getBasicUtxoParams(){return{amount:this.amount,erc20TokenAddress:this.erc20TokenAddress,mintAddress:this.mintAddress,timeStamp:this.timeStamp,randomization:this.randomization,stealthAddress:this.stealthAddress,tokenId:this.tokenId,commitment:this.commitment,nullifier:this.nullifier,isBlocked:this.isBlocked}}getCommitment(){if(!this.commitment){let e=[this.amount,this.erc20TokenAddress,BigInt(this.getStealthAddress()),this.timeStamp];this.tokenId>0&&e.push(this.tokenId.toString()),this.commitment=n.poseidonHash(...e)}return this.commitment}getNullifier(){if(!this.nullifier){if(!this.shieldedPrivateKey)throw Error(`No Nullifiers if private key is not provided`);let e=n.poseidonHash(this.shieldedPrivateKey,this.getCommitment());this.nullifier=n.poseidonHash(this.commitment,e)}return this.nullifier}getStealthAddress(){if(!this.stealthAddress){if(!this.shieldedPrivateKey)throw Error(`No stealth address in UTXO if private key is not provided`);let e=i.UserKeys.getStealthAddress(this.randomization,this.shieldedPrivateKey);this.stealthAddress=e}return this.stealthAddress}getEncryptionKey(){if(!this.shieldedPrivateKey){if(!this.encryptionKey)throw Error(`No encryption key provided in UTXO`);return this.encryptionKey}return i.UserKeys.getEncryptionKeyPair(this.shieldedPrivateKey).publicKey}static findCorrectRandomization(e,n){if(!n)throw Error(`No Private Shielded Key Provided`);let r=BigInt(n)%t.CIRCOM_P,i,a,o=0n;do i=e*10n**o%t.CIRCOM_P,a=i*r%t.CIRCOM_P,o+=1n;while(a>=2n**253n||i>=2n**253n);return i}getTokenAddress(t){let n=e.isSolanaLike(t)?this.mintAddress:this.erc20TokenAddress;if(!n)throw Error(`No token address provided`);return n}};exports.Utxo=o;