const e=require(`../_virtual/_rolldown/runtime.cjs`);let t=require(`ethers`),n=require(`libsodium-wrappers`);n=e.__toESM(n);var r=()=>n.default.crypto_box_SEALBYTES+n.default.crypto_secretbox_KEYBYTES,i=({nonce:e,sealedKeys:t,ciphertext:n})=>{let i=t.length,a=new Uint8Array(1+e.length+i*r()+n.length),o=0;return a[o]=i,o+=1,a.set(e,o),o+=e.length,t.forEach(e=>{a.set(e,o),o+=e.length}),a.set(n,o),a},a=e=>{let t=n.default.crypto_secretbox_NONCEBYTES,i=r(),a=0,o=e[a];a+=1;let s=e.slice(a,a+t);a+=t;let c=[];for(let t=0;t<o;t+=1)c.push(e.slice(a,a+i)),a+=i;return{nonce:s,sealedKeys:c,ciphertext:e.slice(a)}},o=(e,r)=>{let a=n.default.crypto_secretbox_keygen(),o=n.default.randombytes_buf(n.default.crypto_secretbox_NONCEBYTES),s=n.default.crypto_secretbox_easy(e,o,a);return i({nonce:o,sealedKeys:r.map(e=>n.default.crypto_box_seal(a,t.ethers.getBytes(e))),ciphertext:s})},s=(e,r,i,o)=>{let{nonce:s,sealedKeys:c,ciphertext:l}=a(e),u=n.default.crypto_box_seal_open(c[o],t.ethers.getBytes(i),t.ethers.getBytes(r)),d=n.default.crypto_secretbox_open_easy(l,s,u);return Buffer.from(d)};exports.decryptSealedKeys=s,exports.encryptSealedKeys=o,exports.pack=i,exports.unpack=a;