Skip to content

Commit c37a119

Browse files
panvatargos
authored andcommitted
doc: remove last example use of require('crypto').webcrypto
PR-URL: #45819 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Akhil Marsonya <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent bdbb676 commit c37a119

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

doc/api/crypto.md

+4-8
Original file line numberDiff line numberDiff line change
@@ -1930,8 +1930,8 @@ added: v15.0.0
19301930
Example: Converting a `CryptoKey` instance to a `KeyObject`:
19311931

19321932
```mjs
1933-
const { webcrypto, KeyObject } = await import('node:crypto');
1934-
const { subtle } = webcrypto;
1933+
const { KeyObject } = await import('node:crypto');
1934+
const { subtle } = globalThis.crypto;
19351935

19361936
const key = await subtle.generateKey({
19371937
name: 'HMAC',
@@ -1945,12 +1945,8 @@ console.log(keyObject.symmetricKeySize);
19451945
```
19461946

19471947
```cjs
1948-
const {
1949-
webcrypto: {
1950-
subtle,
1951-
},
1952-
KeyObject,
1953-
} = require('node:crypto');
1948+
const { KeyObject } = require('node:crypto');
1949+
const { subtle } = globalThis.crypto;
19541950

19551951
(async function() {
19561952
const key = await subtle.generateKey({

src/crypto/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,12 @@ crypto.randomFill(buf, (err, buf) => {
310310
For the legacy Node.js crypto API, asynchronous single-call
311311
operations use the traditional Node.js callback pattern, as
312312
illustrated in the previous `randomFill()` example. In the
313-
Web Crypto API (accessible via `require('node:crypto').webcrypto`),
313+
Web Crypto API (accessible via `globalThis.crypto`),
314314
all asynchronous single-call operations are Promise-based.
315315

316316
```js
317317
// Example Web Crypto API asynchronous single-call operation
318-
const { subtle } = require('node:crypto').webcrypto;
318+
const { subtle } = globalThis.crypto;
319319

320320
subtle.generateKeys({ name: 'HMAC', length: 256 }, true, ['sign'])
321321
.then((key) => {

0 commit comments

Comments
 (0)