const e=require(`../../_virtual/_rolldown/runtime.cjs`),t=require(`./serialize.utils.cjs`),n=require(`../../data-structures/http/HttpClient.cjs`);require(`../../data-structures/http/index.cjs`);const r=require(`../snarkjs/constant.cjs`);let i=require(`ethers`),a=require(`libsodium-wrappers`);a=e.__toESM(a);let o=require(`node-forge`);o=e.__toESM(o);var s=async()=>(await n.httpClient.get(`${r.ENCLAVE_URL}/handshake`)).public_key,c=e=>typeof e==`bigint`||typeof e==`number`?e.toString():e,l=e=>o.util.hexToBytes(e.replace(`0x`,``)),u=e=>{let t=structuredClone(e);return Object.entries(t).forEach(([e,n])=>{t[e]=c(n),Array.isArray(n)&&(Array.isArray(n[0])?t[e]=n.map(e=>e.map(c)):t[e]=n.map(c))}),t},d=(e,t)=>{let n=o.util.decode64(e),r=o.asn1.fromDer(o.util.createBuffer(n)),i=o.pki.publicKeyFromAsn1(r),a=o.util.binary.raw.encode(t),s=i.encrypt(a,`RSA-OAEP`,{md:o.md.sha1.create(),mgf1:{md:o.md.sha1.create()}});return o.util.encode64(s)},f=(e,t)=>{let n=a.default.randombytes_buf(a.default.crypto_secretbox_NONCEBYTES),r=a.default.crypto_secretbox_easy(t,n,e),s=l(i.ethers.hexlify(n)+i.ethers.hexlify(r).slice(2));return o.util.encode64(s)},p=(e,t)=>{let n=a.default.randombytes_buf(a.default.crypto_secretbox_KEYBYTES);return{keyCiphertext:d(t,n),inputCiphertext:f(n,e)}},m=(e,n)=>{let r=typeof e==`string`?e:t.safeJsonStringify(u(e));return p(new TextEncoder().encode(r),n)},h=async e=>m(e,await s()),g=async e=>p(e,await s());exports.makeEnclaveHandshakeAndEncryptInput=h,exports.makeEnclaveHandshakeAndEncryptUint8Array=g;