Add randomUUIDv7() method (RFC 9562) - #562
Open
gianluca-pettenon wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add randomUUIDv7() method (RFC 9562)
Addresses #561.
What
Adds
Crypto.randomUUIDv7(), generating [RFC 9562](https://www.rfc-editor.org/rfc/rfc9562) version 7 UUIDs, alongside the existingrandomUUID()(v4).Why
Unlike v4 UUIDs, v7 UUIDs embed a millisecond-precision timestamp in their most significant bits, which makes them sortable by creation time when compared as byte sequences or as their lowercase hex string form. This is useful as:
RFC 9562 (2024) formalized v7 specifically to address the fingerprinting concerns that blocked earlier timestamp-based UUID versions (v1) from being added to this API — see the discussion in WICG/uuid#25 and WICG/uuid#36. v7 does not embed a MAC address, and millisecond resolution alone does not provide a practically exploitable fingerprinting/tracking side channel beyond what other web-exposed timers already do.
Precedent
cryptomodule already implements this: crypto: implement randomUUIDv7() nodejs/node#62553 (fixes Add support for generating UUIDv7s nodejs/node#62529)uuidv7module: feat(uuid): stabilize uuidv7 module denoland/std#6897node:cryptosuite to Node v26.3.0: node:crypto: sync the crypto suite to Node v26.3.0 and fix surfaced gaps oven-sh/bun#32623uuidnpm package (64M+ downloads/month) has shippeduuidv7()since v9.1Three independent JS runtimes now agree on the
randomUUIDv7()naming and shape, which is a meaningfully stronger signal than a single-implementation precedent.What this PR does NOT do
randomUUID()itself — per prior discussion in Supporting future UUID formats WICG/uuid#36, overloadingrandomUUID()with a version parameter was considered undesirable, since older implementations would silently ignore it. This PR instead adds a separate, distinctly-named method, matching the precedent set by Node.js.Open questions for reviewers
randomUUIDv7()the right name/shape, or should this berandomUUID({version: 7})despite the earlier objection?Performance.now()resolution)?localBiblioentry (RFC4122 didn't need one, but 9562 is newer)?Opened as a starting point for discussion — happy to iterate based on feedback before/instead of merging as-is.