Copyright © 2021 the Contributors to the uuid Specification, published by the Web Platform Incubator Community Group under the W3C Community Contributor License Agreement (CLA). A human-readable summary is available.
This specification describes an API for generating character encoded
Universally Unique Identifiers (UUID) based on [RFC4122], available
as a method on the Crypto
interface.
This specification was published by the Web Platform Incubator Community Group. It is not a W3C Standard nor is it on the W3C Standards Track. Please note that under the W3C Community Contributor License Agreement (CLA) there is a limited opt-out and other conditions apply. Learn more about W3C Community and Business Groups.
This is a work in progress.
GitHub Issues are preferred for discussion of this specification.
Provide a straightforward and secure mechanism for generating UUIDs that addresses developers' common needs (identifiers for generated pages, identifiers for sessions, identifiers for generated HTML elements, database keys, etc.), while minimizing the amount of domain knowledge a developer requires to discover and use the feature.
To generate a UUID, simply call Crypto
's randomUUID
()
method:
const filename = `${crypto.randomUUID()}.txt`;
// do something with filename.
Crypto
interface
WebIDL[Exposed=(Window,Worker)]
partial interface Crypto {
[SecureContext] DOMString randomUUID
();
};
randomUUID()
method
The randomUUID()
method steps are to return the result of
generating a random UUID.
To generate a random UUID:
0b0100
.
0b10
.
Return the concatenation of «
"-"
,
"-"
,
"-"
,
"-"
,
».
For the steps described in the algorithm to generate a random UUID,
the hexadecimal representation of a byte value is the
two-character string created by expressing value in hexadecimal using
ASCII lower hex digits, left-padded with "0"
to reach two
ASCII lower hex digits.
This section is non-normative.
randomUUID
()
is invoked before the underlying system is
seeded with enough entropy it may result in colliding UUIDs (due to
cycles in the PRNG). Authors of applications that use
randomUUID
need to be aware of these risks.
This section is non-normative.
randomUUID
is
not likely to make users more susceptible to fingerprinting than they
are through existing cryptography methods. See also, WebCrypto Privacy Considerations.
randomUUID
as user ID
randomUUID
is useful for generating user
IDs, but does not directly give any ability to generate global
identifiers.
As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.
Referenced in: