Skip to content

Commit 470c284

Browse files
authored
crypto: clarify require("crypto").getRandomValues is Node.js specific
Refs: #41779 Refs: #41760 PR-URL: #41782 Reviewed-By: Matteo Collina <[email protected]>
1 parent e8a972a commit 470c284

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

doc/api/crypto.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -4139,7 +4139,9 @@ added: v17.4.0
41394139
* `typedArray` {Buffer|TypedArray|DataView|ArrayBuffer}
41404140
* Returns: {Buffer|TypedArray|DataView|ArrayBuffer} Returns `typedArray`.
41414141

4142-
A convenient alias for [`crypto.webcrypto.getRandomValues()`][].
4142+
A convenient alias for [`crypto.webcrypto.getRandomValues()`][]. This
4143+
implementation is not compliant with the Web Crypto spec, to write
4144+
web-compatible code use [`crypto.webcrypto.getRandomValues()`][] instead.
41434145

41444146
### `crypto.hkdf(digest, ikm, salt, info, keylen, callback)`
41454147

lib/crypto.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ function getFipsForced() {
252252
return 1;
253253
}
254254

255+
function getRandomValues(array) {
256+
return lazyWebCrypto().crypto.getRandomValues(array);
257+
}
258+
255259
ObjectDefineProperty(constants, 'defaultCipherList', {
256260
value: getOptionValue('--tls-cipher-list')
257261
});
@@ -303,7 +307,7 @@ ObjectDefineProperties(module.exports, {
303307
getRandomValues: {
304308
configurable: false,
305309
enumerable: true,
306-
get() { return lazyWebCrypto().crypto.getRandomValues; },
310+
get: () => getRandomValues,
307311
set: undefined,
308312
},
309313

0 commit comments

Comments
 (0)