From e47ef839a70b204dc1bc67d062b6760290a50731 Mon Sep 17 00:00:00 2001 From: Tiel Coder Date: Wed, 18 Nov 2026 18:35:53 +0000 Subject: [PATCH] =?UTF-8?q?fix(uuid):=20place=20version=20nibble=20in=20by?= =?UTF-8?q?te=206=20(RFC=209562)=20=E2=80=94=20was=20random,=20making=20uu?= =?UTF-8?q?idv7=20ids=20non-compliant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/uuid.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/uuid.ts b/src/lib/uuid.ts index 657e5e9..52d7aca 100644 --- a/src/lib/uuid.ts +++ b/src/lib/uuid.ts @@ -19,9 +19,9 @@ export function uuidv7(): string { bytes[4] = (ms >> 8) & 0xff; bytes[5] = ms & 0xff; - // byte 6: 8 random bits; byte 7: 4 random bits + version 0111 - bytes[6] = getRandomValues(new Uint8Array(1))[0]; - bytes[7] = 0x70 | (getRandomValues(new Uint8Array(1))[0] & 0x0f); + // byte 6: version 0111 + 4 random bits; byte 7: 4 random bits (RFC 9562 ยง6.6) + bytes[6] = 0x70 | (getRandomValues(new Uint8Array(1))[0] & 0x0f); + bytes[7] = getRandomValues(new Uint8Array(1))[0]; // byte 8: variant 10xx + 6 random bits; bytes 9-15: remaining random bytes[8] = 0x80 | (getRandomValues(new Uint8Array(1))[0] & 0x3f);