Skip to content

Commit 2fb1fbc

Browse files
committed
Use platform’s “crypto.randomUUID” method.
Small update to leverage this tool that’s been available since 2022. Previously, we were using “crypto.getRandomValues” which was baseline as of 2015. Note that they _both_ require a “secure context”, so our posture in regards to that should not be changing at all as a result of this swap.
1 parent c06d0f0 commit 2fb1fbc

1 file changed

Lines changed: 1 addition & 5 deletions

File tree

x-test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,15 +413,11 @@ test.todo = function todo(name, fn, timeout) {
413413
}
414414
};
415415

416-
// https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
417416
/**
418417
* @returns {string} A UUID string
419418
*/
420419
function uuid() {
421-
return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, c =>
422-
// eslint-disable-next-line no-bitwise
423-
(+c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +c / 4).toString(16)
424-
);
420+
return crypto.randomUUID();
425421
}
426422

427423
// We need two channels since a messages on a channel are not reflected.

0 commit comments

Comments
 (0)