denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
98.17k stars 5.4k forks source link

Cannot use structuredClone on CryptoKey #12734

Open irbull opened 3 years ago

irbull commented 3 years ago

I am trying to create a WebWorker, and pass a CryptoKey to it. The idea is that the Web Worker should not be able to extract the key, so I generate the key with extractable === false. However, trying to pass a clone of a CryptoKey fails.

According to the MDN, this should be possible.

CryptoKey objects can be stored using the structured clone algorithm, meaning that you can store and retrieve them using standard web storage APIs. The specification expects that most developers will use the IndexedDB API to store CryptoKey objects.

Here is a small snippet that demonstrates the problem. After calling structuredClone an empty object is returned.

const result = await crypto.subtle.generateKey(
  { name: 'AES-CBC', length: 256 },
  false,
  ['encrypt', 'decrypt'],
);

console.log(result);
console.log(structuredClone(result));
lucacasonato commented 3 years ago

Blocked on https://github.com/denoland/deno/issues/12067