Skip to content

Commit

Permalink
doc: remove last example use of require('crypto').webcrypto
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
panva committed Dec 13, 2022
1 parent 232efb0 commit 0665fa4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
12 changes: 4 additions & 8 deletions doc/api/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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({
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 0665fa4

Please sign in to comment.