From 05c9362b14d31ca65995fa8104518f989ff6406e Mon Sep 17 00:00:00 2001 From: James M Snell Date: Mon, 29 Mar 2021 13:16:00 -0700 Subject: [PATCH 1/2] crypto: expose subtle and getRandomValues from crypto In the browser, the `crypto` global exposes `subtle` and `getRandomValues` as properties. In the Node.js impl, those require an additional indirection via `crypto.webcrypto.*`. This commit exposes aliases to promote cross-environment isomorphism. Note: In the browser, the `CryptoKey` object is also exposed as a global. I decided not to do that here because it requires a larger change to the internal `node_crypto` binding because of the need to register external references. That can be done in a separate PR but it's a much lower priority. Signed-off-by: James M Snell --- doc/api/crypto.md | 21 +++++++++++++++++++++ lib/crypto.js | 12 ++++++++++++ test/parallel/test-webcrypto.js | 16 ++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 test/parallel/test-webcrypto.js diff --git a/doc/api/crypto.md b/doc/api/crypto.md index 0918d599c287fc..03564234aefbc5 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -3836,6 +3836,18 @@ const { console.log(getHashes()); // ['DSA', 'DSA-SHA', 'DSA-SHA1', ...] ``` +### `crypto.getRandomValues(typedArray)` + + +* `typedArray` {Buffer|TypedArray|DataView|ArrayBuffer} +* Returns: {Buffer|TypedArray|DataView|ArrayBuffer} Returns `typedArray`. + +Alias for `crypto.webcrypto.getRandomValues(typedArray)` + +See [`webcrypto.getRandomValues()`][] for details. + ### `crypto.hkdf(digest, key, salt, info, keylen, callback)` + +Alias for [`webcrypto.subtle`][]. + ### `crypto.timingSafeEqual(a, b)` -> Stability: 1 - Experimental +> Stability: 2 - Stable Node.js provides an implementation of the standard [Web Crypto API][].