From 0665fa4009e2aa26adb95c27a363cc7ff0686d41 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Sun, 11 Dec 2022 19:02:21 +0100 Subject: [PATCH] doc: remove last example use of require('crypto').webcrypto MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/45819 Reviewed-By: Tobias Nießen Reviewed-By: Luigi Pinca Reviewed-By: Antoine du Hamel Reviewed-By: Akhil Marsonya Reviewed-By: Benjamin Gruenbaum --- doc/api/crypto.md | 12 ++++-------- src/crypto/README.md | 4 ++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/doc/api/crypto.md b/doc/api/crypto.md index 2e03ffb9a5e39a..614c18d4887d65 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -1930,8 +1930,8 @@ added: v15.0.0 Example: Converting a `CryptoKey` instance to a `KeyObject`: ```mjs -const { webcrypto, KeyObject } = await import('node:crypto'); -const { subtle } = webcrypto; +const { KeyObject } = await import('node:crypto'); +const { subtle } = globalThis.crypto; const key = await subtle.generateKey({ name: 'HMAC', @@ -1945,12 +1945,8 @@ console.log(keyObject.symmetricKeySize); ``` ```cjs -const { - webcrypto: { - subtle, - }, - KeyObject, -} = require('node:crypto'); +const { KeyObject } = require('node:crypto'); +const { subtle } = globalThis.crypto; (async function() { const key = await subtle.generateKey({ diff --git a/src/crypto/README.md b/src/crypto/README.md index c58f3cb118089f..ceefda03976ba9 100644 --- a/src/crypto/README.md +++ b/src/crypto/README.md @@ -310,12 +310,12 @@ crypto.randomFill(buf, (err, buf) => { For the legacy Node.js crypto API, asynchronous single-call operations use the traditional Node.js callback pattern, as illustrated in the previous `randomFill()` example. In the -Web Crypto API (accessible via `require('node:crypto').webcrypto`), +Web Crypto API (accessible via `globalThis.crypto`), all asynchronous single-call operations are Promise-based. ```js // Example Web Crypto API asynchronous single-call operation -const { subtle } = require('node:crypto').webcrypto; +const { subtle } = globalThis.crypto; subtle.generateKeys({ name: 'HMAC', length: 256 }, true, ['sign']) .then((key) => {