require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../crypto/ecdh.cjs`),t=require(`../../crypto/ecdh-sealed-keys.cjs`),n=require(`./keys.cjs`),r=require(`../utxo/Utxo.cjs`);let i=require(`ethers`),a=require(`@solana/web3.js`);var o=e=>e.startsWith(`0x`)?e:`0x${e}`,s=54912,c=2,l=e=>Uint8Array.from([Math.floor(e/256),e%256]),u=e=>e[0]*256+e[1],d=e=>{let n=[Buffer.from(i.ethers.toBeHex(e.amount)),Buffer.from(o(e.erc20TokenAddress)),Buffer.from(i.ethers.toBeHex(e.randomization??0n)),Buffer.from(o(e.getStealthAddress())),Buffer.from(i.ethers.toBeHex(BigInt(e.timeStamp))),Buffer.from(i.ethers.toBeHex(e.isNewStyle?1n:0n)),Buffer.from(i.ethers.toBeHex(e.H0?.[0]??0n)),Buffer.from(i.ethers.toBeHex(e.H0?.[1]??0n))];if(e.mintAddress){let t=new a.PublicKey(e.mintAddress),r=i.ethers.hexlify(t.toBytes());n.push(Buffer.from(r))}let r=t.encryptSealedKeys(Buffer.concat(n),[e.getEncryptionKey()]);return Buffer.concat([Buffer.from(l(s)),Buffer.from(r)])},f=(r,i)=>{let{privateKey:o,publicKey:l}=n.UserKeys.getEncryptionKeyPair(i.getShieldedPrivateKey()),d=u(r)===s?t.decryptSealedKeys(r.slice(c),o,l,0):e.decryptBoxSeal(r,o,l),f=Buffer.from(d).toString(`utf-8`).split(`0x`).filter(e=>e.length!==0),p=e=>BigInt(`0x${e}`),m=e=>`0x${e}`,h=f.length>=8,g=h&&p(f[5])===1n,_=h?8:6,v=f[_]?m(f[_]):void 0,y=v?new a.PublicKey(Buffer.from(v.slice(2),`hex`)).toString():void 0;return{amount:p(f[0]),erc20TokenAddress:m(f[1]),randomization:p(f[2]),stealthAddress:m(f[3]),nullifyingKey:i.getShieldedPrivateKey(),timeStamp:p(f[4]).toString(),isNewStyle:g,...g?{H0:[p(f[6]),p(f[7])]}:{},mintAddress:y}},p=(e,t)=>new r.Utxo(f(e,t));exports.decryptUtxo=p,exports.decryptUtxoConstructorArgs=f,exports.encryptUtxo=d;