From 60682917ddd7b9d83010ded08fb295b0e02bc8ea Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 14 Feb 2022 17:14:49 +0100 Subject: [PATCH] crypto: expose Web Crypto API on the global scope MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/41938 Refs: https://developer.mozilla.org/en-US/docs/Web/API/crypto_property Refs: https://github.com/nodejs/node/pull/41782 Refs: https://w3c.github.io/webcrypto Reviewed-By: James M Snell Reviewed-By: Michaƫl Zasso Reviewed-By: Filip Skokan --- .eslintrc.js | 4 ++ doc/api/cli.md | 10 ++++ doc/api/crypto.md | 2 + doc/api/globals.md | 52 +++++++++++++++++++ doc/node.1 | 3 ++ lib/.eslintrc.yaml | 8 +++ lib/internal/bootstrap/pre_execution.js | 41 +++++++++++++++ lib/internal/crypto/webcrypto.js | 1 + lib/internal/main/worker_thread.js | 2 + src/node_options.cc | 4 ++ src/node_options.h | 1 + test/common/index.js | 6 +++ .../parallel/test-global-webcrypto-classes.js | 13 +++++ test/parallel/test-global-webcrypto.js | 13 +++++ 14 files changed, 160 insertions(+) create mode 100644 test/parallel/test-global-webcrypto-classes.js create mode 100644 test/parallel/test-global-webcrypto.js diff --git a/.eslintrc.js b/.eslintrc.js index e3872f4b8eeb79..2c7d56266d3977 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -338,5 +338,9 @@ module.exports = { Headers: 'readable', Request: 'readable', Response: 'readable', + crypto: 'readable', + Crypto: 'readable', + CryptoKey: 'readable', + SubtleCrypto: 'readable', }, }; diff --git a/doc/api/cli.md b/doc/api/cli.md index 1bcef4c457ea99..c4602e6c832ae3 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -288,6 +288,14 @@ added: v17.5.0 Enable experimental support for the [Fetch API][]. +### `--experimental-global-webcrypto` + + + +Expose the [Web Crypto API][] on the global scope. + ### `--experimental-import-meta-resolve` + ```cjs let crypto; try { diff --git a/doc/api/globals.md b/doc/api/globals.md index e86885eb749e68..7ca4251d6e46b8 100644 --- a/doc/api/globals.md +++ b/doc/api/globals.md @@ -281,6 +281,43 @@ added: v0.1.100 Used to print to stdout and stderr. See the [`console`][] section. +## `Crypto` + + + +> Stability: 1 - Experimental. Enable this API with the +> [`--experimental-global-webcrypto`][] CLI flag. + +A browser-compatible implementation of {Crypto}. This global is available +only if the Node.js binary was compiled with including support for the +`crypto` module. + +## `crypto` + + + +> Stability: 1 - Experimental. Enable this API with the +> [`--experimental-global-webcrypto`][] CLI flag. + +A browser-compatible implementation of the [Web Crypto API][]. + +## `CryptoKey` + + + +> Stability: 1 - Experimental. Enable this API with the +> [`--experimental-global-webcrypto`][] CLI flag. + +A browser-compatible implementation of {CryptoKey}. This global is available +only if the Node.js binary was compiled with including support for the +`crypto` module. + ## `Event` + +> Stability: 1 - Experimental. Enable this API with the +> [`--experimental-global-webcrypto`][] CLI flag. + +A browser-compatible implementation of {SubtleCrypto}. This global is available +only if the Node.js binary was compiled with including support for the +`crypto` module. + ## `DOMException`