Skip to content

Commit 8e1531c

Browse files
committed
crypto: update randomUUIDv7() to construct UUID string directly from bytes
1 parent 65936c9 commit 8e1531c

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

lib/internal/crypto/random.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,28 @@ function randomUUIDv7() {
443443
uuidV7Buffer[6] = (uuidV7Buffer[6] & 0x0f) | 0x70;
444444

445445
uuidV7Buffer[8] = (uuidV7Buffer[8] & 0x3f) | 0x80;
446-
447-
const result = serializeUUID(uuidV7Buffer);
448-
return result;
446+
447+
const kHexBytes = getHexBytes();
448+
return kHexBytes[uuidV7Buffer[0]] +
449+
kHexBytes[uuidV7Buffer[1]] +
450+
kHexBytes[uuidV7Buffer[2]] +
451+
kHexBytes[uuidV7Buffer[3]] +
452+
'-' +
453+
kHexBytes[uuidV7Buffer[4]] +
454+
kHexBytes[uuidV7Buffer[5]] +
455+
'-' +
456+
kHexBytes[uuidV7Buffer[6]] +
457+
kHexBytes[uuidV7Buffer[7]] +
458+
'-' +
459+
kHexBytes[uuidV7Buffer[8]] +
460+
kHexBytes[uuidV7Buffer[9]] +
461+
'-' +
462+
kHexBytes[uuidV7Buffer[10]] +
463+
kHexBytes[uuidV7Buffer[11]] +
464+
kHexBytes[uuidV7Buffer[12]] +
465+
kHexBytes[uuidV7Buffer[13]] +
466+
kHexBytes[uuidV7Buffer[14]] +
467+
kHexBytes[uuidV7Buffer[15]];
449468
}
450469

451470
function createRandomPrimeJob(type, size, options) {

0 commit comments

Comments
 (0)