Skip to content

Commit 9073603

Browse files
committed
crypto: implement webcrypto.randomUUID
Refs: https://wicg.github.io/uuid/ Refs: https://www.chromestatus.com/feature/5689159362543616 PR-URL: #39648 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent 58316e2 commit 9073603

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

doc/api/webcrypto.md

+11
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,16 @@ filled with random values, and a reference to `typedArray` is returned.
361361

362362
An error will be thrown if the given `typedArray` is larger than 65,536 bytes.
363363

364+
### `crypto.randomUUID()`
365+
<!-- YAML
366+
added: REPLACEME
367+
-->
368+
369+
* Returns: {string}
370+
371+
Generates a random [RFC 4122][] Version 4 UUID. The UUID is generated using a
372+
cryptographic pseudorandom number generator.
373+
364374
## Class: `CryptoKey`
365375
<!-- YAML
366376
added: v15.0.0
@@ -1771,4 +1781,5 @@ added: v15.0.0
17711781

17721782
[JSON Web Key]: https://tools.ietf.org/html/rfc7517
17731783
[Key usages]: #webcrypto_cryptokey_usages
1784+
[RFC 4122]: https://www.rfc-editor.org/rfc/rfc4122.txt
17741785
[Web Crypto API]: https://www.w3.org/TR/WebCryptoAPI/

lib/crypto.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ ObjectDefineProperties(module.exports, {
284284
webcrypto: {
285285
configurable: false,
286286
enumerable: true,
287-
get() { return lazyRequire('internal/crypto/webcrypto'); }
287+
get() { return lazyRequire('internal/crypto/webcrypto').crypto; }
288288
},
289289

290290
// Aliases for randomBytes are deprecated.

lib/internal/crypto/webcrypto.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ const {
6464

6565
const {
6666
getRandomValues,
67+
randomUUID: _randomUUID,
6768
} = require('internal/crypto/random');
6869

70+
const randomUUID = () => _randomUUID();
71+
6972
async function generateKey(
7073
algorithm,
7174
extractable,
@@ -705,6 +708,12 @@ ObjectDefineProperties(
705708
writable: true,
706709
value: getRandomValues,
707710
},
711+
randomUUID: {
712+
enumerable: true,
713+
configurable: true,
714+
writable: true,
715+
value: randomUUID,
716+
},
708717
CryptoKey: {
709718
enumerable: true,
710719
configurable: true,
@@ -795,4 +804,8 @@ ObjectDefineProperties(
795804
}
796805
});
797806

798-
module.exports = crypto;
807+
module.exports = {
808+
Crypto,
809+
SubtleCrypto,
810+
crypto,
811+
};

0 commit comments

Comments
 (0)