Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions doc/api/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -3836,6 +3836,18 @@ const {
console.log(getHashes()); // ['DSA', 'DSA-SHA', 'DSA-SHA1', ...]
```

### `crypto.getRandomValues(typedArray)`
<!-- YAML
added: REPLACEME
-->

* `typedArray` {Buffer|TypedArray|DataView|ArrayBuffer}
* Returns: {Buffer|TypedArray|DataView|ArrayBuffer} Returns `typedArray`.

Alias for `crypto.webcrypto.getRandomValues(typedArray)`

See [`webcrypto.getRandomValues()`][] for details.

### `crypto.hkdf(digest, key, salt, info, keylen, callback)`
<!-- YAML
added: v15.0.0
Expand Down Expand Up @@ -5002,6 +5014,13 @@ additional properties can be passed:

If the `callback` function is provided this function uses libuv's threadpool.

### `crypto.subtle`
<!-- YAML
added: REPLACEME
-->

Alias for [`webcrypto.subtle`][].

### `crypto.timingSafeEqual(a, b)`
<!-- YAML
added: v6.6.0
Expand Down Expand Up @@ -5724,6 +5743,8 @@ See the [list of SSL OP Flags][] for details.
[`util.promisify()`]: util.md#util_util_promisify_original
[`verify.update()`]: #crypto_verify_update_data_inputencoding
[`verify.verify()`]: #crypto_verify_verify_object_signature_signatureencoding
[`webcrypto.getRandomValues()`]: webcrypto.md#webcrypto_crypto_getrandomvalues_typedarray
[`webcrypto.subtle`]: webcrypto.md#webcrypto_crypto_subtle
[certificate object]: tls.md#tls_certificate_object
[encoding]: buffer.md#buffer_buffers_and_character_encodings
[initialization vector]: https://en.wikipedia.org/wiki/Initialization_vector
Expand Down
2 changes: 1 addition & 1 deletion doc/api/webcrypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- introduced_in=v15.0.0 -->

> Stability: 1 - Experimental
> Stability: 2 - Stable

Node.js provides an implementation of the standard [Web Crypto API][].

Expand Down
12 changes: 12 additions & 0 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,18 @@ ObjectDefineProperties(module.exports, {
get() { return lazyRequire('internal/crypto/webcrypto'); }
},

subtle: {
configurable: true,
enumerable: false,
get() { return this.webcrypto.subtle; },
},

getRandomValues: {
configurable: true,
enumerable: false,
get() { return this.webcrypto.getRandomValues; },
},

// Aliases for randomBytes are deprecated.
// The ecosystem needs those to exist for backwards compatibility.
prng: {
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-webcrypto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

const common = require('../common');

if (!common.hasCrypto)
common.skip('missing crypto');

const { strictEqual } = require('assert');
const {
webcrypto,
subtle,
getRandomValues,
} = require('crypto');

strictEqual(subtle, webcrypto.subtle);
strictEqual(getRandomValues, webcrypto.getRandomValues);