chore: use crypto.randomUUID() for generating UUIDv4

This commit is contained in:
Shishkevich D. 2025-03-09 06:09:42 +00:00
parent a45e9de472
commit 64fa0e97a3

View file

@ -126,14 +126,7 @@ class RandomUtil {
} }
static randomUUID() { static randomUUID() {
const template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'; return window.crypto.randomUUID()
return template.replace(/[xy]/g, function (c) {
const randomValues = new Uint8Array(1);
crypto.getRandomValues(randomValues);
let randomValue = randomValues[0] % 16;
let calculatedValue = (c === 'x') ? randomValue : (randomValue & 0x3 | 0x8);
return calculatedValue.toString(16);
});
} }
static randomShadowsocksPassword() { static randomShadowsocksPassword() {