diff --git a/lib/internal/crypto/keys.js b/lib/internal/crypto/keys.js index 4303dc44fe60d7..2f9b34361335b3 100644 --- a/lib/internal/crypto/keys.js +++ b/lib/internal/crypto/keys.js @@ -54,7 +54,7 @@ const { } = require('internal/util/types'); const { - JSTransferable, + makeTransferable, kClone, kDeserialize, } = require('internal/worker/js_transferable'); @@ -627,14 +627,12 @@ function isKeyObject(obj) { } // Our implementation of CryptoKey is a simple wrapper around a KeyObject -// that adapts it to the standard interface. This implementation also -// extends the JSTransferable class, allowing the CryptoKey to be cloned -// to Workers. +// that adapts it to the standard interface. // TODO(@jasnell): Embedder environments like electron may have issues // here similar to other things like URL. A chromium provided CryptoKey // will not be recognized as a Node.js CryptoKey, and vice versa. It // would be fantastic if we could find a way of making those interop. -class CryptoKey extends JSTransferable { +class CryptoKey { constructor() { throw new ERR_ILLEGAL_CONSTRUCTOR(); } @@ -671,6 +669,29 @@ class CryptoKey extends JSTransferable { get usages() { return ArrayFrom(this[kKeyUsages]); } +} + +// All internal code must use new InternalCryptoKey to create +// CryptoKey instances. The CryptoKey class is exposed to end +// user code but is not permitted to be constructed directly. +// Using makeTransferable also allows the CryptoKey to be +// cloned to Workers. +class InternalCryptoKey { + constructor( + keyObject, + algorithm, + keyUsages, + extractable) { + // Using symbol properties here currently instead of private + // properties because (for now) the performance penalty of + // private fields is still too high. + this[kKeyObject] = keyObject; + this[kAlgorithm] = algorithm; + this[kExtractable] = extractable; + this[kKeyUsages] = keyUsages; + + return makeTransferable(this); + } [kClone]() { const keyObject = this[kKeyObject]; @@ -697,26 +718,6 @@ class CryptoKey extends JSTransferable { } } -// All internal code must use new InternalCryptoKey to create -// CryptoKey instances. The CryptoKey class is exposed to end -// user code but is not permitted to be constructed directly. -class InternalCryptoKey extends JSTransferable { - constructor( - keyObject, - algorithm, - keyUsages, - extractable) { - super(); - // Using symbol properties here currently instead of private - // properties because (for now) the performance penalty of - // private fields is still too high. - this[kKeyObject] = keyObject; - this[kAlgorithm] = algorithm; - this[kExtractable] = extractable; - this[kKeyUsages] = keyUsages; - } -} - InternalCryptoKey.prototype.constructor = CryptoKey; ObjectSetPrototypeOf(InternalCryptoKey.prototype, CryptoKey.prototype); diff --git a/test/wpt/status/WebCryptoAPI.json b/test/wpt/status/WebCryptoAPI.json index 7e61cb4b5a47d8..c3198262a74a88 100644 --- a/test/wpt/status/WebCryptoAPI.json +++ b/test/wpt/status/WebCryptoAPI.json @@ -11,7 +11,6 @@ "Crypto interface: existence and properties of interface object", "Crypto interface: calling getRandomValues(ArrayBufferView) on crypto with too few arguments must throw TypeError", "CryptoKey interface: existence and properties of interface object", - "CryptoKey interface: existence and properties of interface prototype object", "CryptoKey interface: attribute type", "CryptoKey interface: attribute extractable", "CryptoKey interface: attribute algorithm",