Skip to content

Commit 288f627

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

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
@@ -4104,7 +4104,9 @@ added: v17.4.0
41044104
* `typedArray` {Buffer|TypedArray|DataView|ArrayBuffer}
41054105
* Returns: {Buffer|TypedArray|DataView|ArrayBuffer} Returns `typedArray`.
41064106

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

41094111
### `crypto.hkdf(digest, ikm, salt, info, keylen, callback)`
41104112

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)