From f3ed546ae81b37678b271f398efc777d1123961c Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 11 Feb 2022 19:10:16 +0100 Subject: [PATCH 1/7] crypto: expose Web Crypto API on the global scope --- .eslintrc.js | 1 + doc/api/cli.md | 10 ++++++++++ doc/api/crypto.md | 12 +++++++----- doc/api/globals.md | 13 +++++++++++++ doc/node.1 | 3 +++ lib/.eslintrc.yaml | 2 ++ lib/internal/bootstrap/pre_execution.js | 13 +++++++++++++ lib/internal/main/worker_thread.js | 2 ++ src/node_options.cc | 4 ++++ src/node_options.h | 1 + test/common/index.js | 3 +++ test/parallel/test-global-webcrypto.js | 11 +++++++++++ 12 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 test/parallel/test-global-webcrypto.js diff --git a/.eslintrc.js b/.eslintrc.js index da17fd47acd4b9..d9ec6f709de542 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -340,5 +340,6 @@ module.exports = { Headers: 'readable', Request: 'readable', Response: 'readable', + crypto: 'readable', }, }; diff --git a/doc/api/cli.md b/doc/api/cli.md index 10500f130a6b28..a551a3fff9cec6 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` + +> Stability: 1 - Experimental. Enable this API with the +> [`--experimental-global-webcrypto`][] CLI flag. + +A browser-compatible implementation of the [Web Crypto API][]. + ## `Event` + +> 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 {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` + ```cjs -{ - let crypto; - try { - crypto = require('crypto'); - } catch (err) { - console.log('crypto support is disabled!'); - } +let crypto; +try { + crypto = require('crypto'); +} catch (err) { + console.log('crypto support is disabled!'); } ```