diff --git a/spec/Overview.html b/spec/Overview.html index d568caa..a3c07f0 100644 --- a/spec/Overview.html +++ b/spec/Overview.html @@ -818,6 +818,7 @@

Crypto interface

[SecureContext] readonly attribute SubtleCrypto subtle; ArrayBufferView getRandomValues(ArrayBufferView array); [SecureContext] DOMString randomUUID(); + [SecureContext] DOMString randomUUIDv7(); }; @@ -977,6 +978,109 @@

The randomUUID method

[= ASCII lower hex digits =].

+
+

The randomUUIDv7 method

+

+ The randomUUIDv7 + method generates a new version 7 UUID + and returns its namespace specific string representation + as described in section 4 of [[RFC9562]]. + Unlike {{Crypto/randomUUID}}, a version 7 UUID embeds a millisecond-precision + timestamp in its most significant bits, so that UUIDs [= generate a random UUIDv7 | + generated =] later sort after ones generated earlier when compared as unsigned + byte sequences or as their [= hexadecimal representation | lowercase hexadecimal =] + string form. To generate a random UUIDv7: +

+
    +
  1. + Let |bytes| be a [= byte sequence =] of length 16. +
  2. +
  3. + Fill |bytes| with cryptographically secure random bytes. +
  4. +
  5. +

    + Let |timestamp| be the number of milliseconds since the [= Unix epoch =], + as an unsigned 48-bit integer. +

    +
    + Implementations should not expose sub-millisecond timing information via + |timestamp|, and should not increase the precision of the clock used here + beyond what is already exposed to the document via other means (e.g. + {{Performance/now()}}), in order to avoid introducing a new + higher-resolution timing side channel. +
    +
  6. +
  7. + Set |bytes|[0] through |bytes|[5] to the big-endian byte representation of + |timestamp|. +
  8. +
  9. + Set the 4 most significant bits of |bytes|[6], which represent the + UUID version, to `0111`. +
  10. +
  11. + Set the 2 most significant bits of |bytes|[8], which represent the + UUID variant, to `10`. +
  12. +
  13. +

    + Return the [= string/concatenate | string concatenation =] of « +

    +
      +
    1. + [= hexadecimal representation =] of |bytes|[0], [= hexadecimal + representation =] of |bytes|[1], [= hexadecimal representation =] of + |bytes|[2], [= hexadecimal representation =] of |bytes|[3], +
    2. +
    3. + "`-`", +
    4. +
    5. + [= hexadecimal representation =] of |bytes|[4], [= hexadecimal + representation =] of |bytes|[5], +
    6. +
    7. + "`-`", +
    8. +
    9. + [= hexadecimal representation =] of |bytes|[6], [= hexadecimal + representation =] of |bytes|[7], +
    10. +
    11. + "`-`", +
    12. +
    13. + [= hexadecimal representation =] of |bytes|[8], [= hexadecimal + representation =] of |bytes|[9], +
    14. +
    15. + "`-`", +
    16. +
    17. + [= hexadecimal representation =] of |bytes|[10], [= hexadecimal + representation =] of |bytes|[11], [= hexadecimal representation =] of + |bytes|[12], [= hexadecimal representation =] of |bytes|[13], + [= hexadecimal representation =] of |bytes|[14], [= hexadecimal + representation =] of |bytes|[15] +
    18. +
    +

    + ». +

    +
  14. +
+
+

+ This algorithm does not specify a mechanism for guaranteeing that UUIDs + generated within the same millisecond sort in call order (a property some + server-side [[RFC9562]] implementations refer to as strict monotonicity). + Implementations and specifications wishing to add that guarantee are invited + to open an issue for discussion, since it requires per-realm state that is + not otherwise needed by this method. +

+
+

Attributes

@@ -15770,6 +15874,12 @@

Generate unique name for download

const filename = `${crypto.randomUUID()}.txt`;
+
+

Generate sortable primary key for IndexedDB

+
+            const id = crypto.randomUUIDv7();
+          
+