Skip to content

Commit e8dacce

Browse files
bartlomiejuclaude
andcommitted
fix(crypto): support structuredClone for CryptoKey
Uses the cloneable resource registry from denoland#32672 to enable structured cloning of CryptoKey objects. This allows CryptoKeys (including non-extractable ones) to be passed to Workers via postMessage and cloned with structuredClone(). Closes denoland#12734 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1ea5ff0 commit e8dacce

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

ext/crypto/00_crypto.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,29 @@ function constructKey(type, extractable, usages, algorithm, handle) {
438438
key[_algorithm] = algorithm;
439439
key[_handle] = handle;
440440
key[kKeyObject] = WeakMapPrototypeGet(KEY_STORE, handle);
441+
key[core.hostObjectBrand] = () => ({
442+
type: "CryptoKey",
443+
keyType: type,
444+
extractable,
445+
usages,
446+
algorithm,
447+
keyData: WeakMapPrototypeGet(KEY_STORE, handle),
448+
});
441449
return key;
442450
}
443451

452+
core.registerCloneableResource("CryptoKey", (data) => {
453+
const handle = {};
454+
WeakMapPrototypeSet(KEY_STORE, handle, data.keyData);
455+
return constructKey(
456+
data.keyType,
457+
data.extractable,
458+
data.usages,
459+
data.algorithm,
460+
handle,
461+
);
462+
});
463+
444464
// https://w3c.github.io/webcrypto/#concept-usage-intersection
445465
/**
446466
* @param {string[]} a

0 commit comments

Comments
 (0)