const e=require(`../../constants/chains.constants.cjs`),t=require(`../../functions/web3/etherFunctions.cjs`),n=require(`../../crypto/poseidon.cjs`),r=require(`../crypto-keys/keys.cjs`),i=require(`../../functions/utils/time.utils.cjs`);var a=class a{amount;erc20TokenAddress;mintAddress;timeStamp;nullifyingKey;spendingPublicKey;randomization;H0;stealthAddress;encryptionKey;commitment;nullifier;isBlocked;isNewStyle;constructor({amount:e,erc20TokenAddress:n,mintAddress:a,timeStamp:o,nullifyingKey:s,spendingPublicKey:c,randomization:l,H0:u,stealthAddress:d,encryptionKey:f,commitment:p=void 0,nullifier:m=void 0,isBlocked:h=!1,isNewStyle:g=!1}){this.amount=e,this.erc20TokenAddress=n,this.mintAddress=a,this.timeStamp=o??i.getCurrentTimeInSeconds().toString(),this.nullifyingKey=s,this.spendingPublicKey=c,this.randomization=l??(s?r.UserKeys.findCorrectRandomization(t.randomBigInt(31),s):void 0),this.H0=u??(g&&this.randomization?r.UserKeys.findH0(this.randomization,s):void 0),this.stealthAddress=d,this.encryptionKey=f,this.commitment=p,this.nullifier=m,this.isBlocked=h,this.isNewStyle=g}static createFrom(e,t){return new a({...e.getConstructableParams(),nullifier:void 0,commitment:void 0,...t})}getConstructableParams(){return{amount:this.amount,erc20TokenAddress:this.erc20TokenAddress,mintAddress:this.mintAddress,timeStamp:this.timeStamp,nullifyingKey:this.nullifyingKey,spendingPublicKey:this.spendingPublicKey,randomization:this.randomization,H0:this.H0,stealthAddress:this.stealthAddress,encryptionKey:this.encryptionKey,commitment:this.commitment,nullifier:this.nullifier,isBlocked:this.isBlocked,isNewStyle:this.isNewStyle}}getBasicUtxoParams(){return{amount:this.amount,erc20TokenAddress:this.erc20TokenAddress,mintAddress:this.mintAddress,timeStamp:this.timeStamp,randomization:this.randomization,H0:this.H0,stealthAddress:this.stealthAddress,commitment:this.commitment,nullifier:this.nullifier,isBlocked:this.isBlocked,isNewStyle:this.isNewStyle}}getCommitment(){if(!this.commitment){let e=[this.amount,this.erc20TokenAddress,BigInt(this.getStealthAddress()),this.timeStamp];this.commitment=n.poseidonHash(...e)}return this.commitment}getNullifier(){if(!this.nullifier){if(!this.nullifyingKey)throw Error(`No Nullifiers if private key is not provided`);let e=this.getCommitment(),t=n.poseidonHash(this.nullifyingKey,e);this.nullifier=n.poseidonHash(e,t)}return this.nullifier}getStealthAddress(){if(!this.stealthAddress){if(!this.nullifyingKey)throw Error(`No stealth address in UTXO if private key is not provided`);if(this.isNewStyle){if(!this.H0)throw Error(`No H0 point provided`);this.stealthAddress=r.UserKeys.getStealthAddressNewStyle(this.H0,this.nullifyingKey,this.spendingPublicKey)}else{if(!this.randomization)throw Error(`No randomization provided`);this.stealthAddress=r.UserKeys.getStealthAddress(this.randomization,this.nullifyingKey)}}return this.stealthAddress}getTokenAddress(t){let n=e.isSolanaLike(t)?this.mintAddress:this.erc20TokenAddress;if(!n)throw Error(`No token address provided`);return n}getEncryptionKey(){if(!this.nullifyingKey){if(!this.encryptionKey)throw Error(`No encryption key provided in UTXO`);return this.encryptionKey}return r.UserKeys.getEncryptionKeyPair(this.nullifyingKey).publicKey}};exports.Utxo=a;