UNPKG

@vitejs/plugin-rsc

Version:
24 lines (22 loc) 1.19 kB
import { once } from "./dist-DEF94lDJ.js"; import { arrayToStream, concatArrayStream, decryptBuffer, encryptBuffer, fromBase64 } from "./encryption-utils-BDwwcMVT.js"; import { createFromReadableStream, renderToReadableStream } from "./rsc-DHfL29FT.js"; import encryptionKeySource from "virtual:vite-rsc/encryption-key"; //#region src/utils/encryption-runtime.ts async function encryptActionBoundArgs(originalValue) { const serialized = renderToReadableStream(originalValue); const serializedBuffer = await concatArrayStream(serialized); return encryptBuffer(serializedBuffer, await getEncryptionKey()); } async function decryptActionBoundArgs(encrypted) { const serializedBuffer = await decryptBuffer(await encrypted, await getEncryptionKey()); const serialized = arrayToStream(new Uint8Array(serializedBuffer)); return createFromReadableStream(serialized); } const getEncryptionKey = /* @__PURE__ */ once(async () => { const resolved = await encryptionKeySource(); const key = await crypto.subtle.importKey("raw", fromBase64(resolved), { name: "AES-GCM" }, true, ["encrypt", "decrypt"]); return key; }); //#endregion export { decryptActionBoundArgs, encryptActionBoundArgs };