• Stars
    star
    462
  • Rank 91,184 (Top 2 %)
  • Language
    JavaScript
  • Created about 5 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

UUID proposal for ECMAScript (Stage 1)

ECMAScript proposal: JavaScript standard library UUID

⚠️⚠️ UPDATE 2021: This proposal is now being pursued at: https://github.com/WICG/uuid ⚠️⚠️

Status: Stage 1

Authors

Synopsis

The JavaScript standard library UUID describes an API for generating character encoded Universally Unique Identifiers (UUID) based on IETF RFC 4122, available for import in JavaScript engines.

Motivation

UUID generation is an extremely common software requirement

The uuid module on npm currently receives some 64,000,000 monthly downloads and is relied on by over 2,600,000 repositories (as of June 2019).

The ubiquitous nature of the uuid module demonstrates that UUID generation is a common requirement for JavaScript software applications, making the functionality a good candidate for the standard library.

Developers "re-inventing the wheel" is potentially harmful

Developers who have not been exposed to RFC 4122 might naturally opt to invent their own approaches to UUID generation, potentially using Math.random() (in TIFU by using Math.random() there's an in-depth discussion of why a Cryptographically-Secure-Pseudo-Random-Number-Generator (CSPRNG) should be used when generating UUIDs).

Introducing a UUID standard library, which dictates that a CSPRNG must be used, helps protect developers from security pitfalls.

Overview

UUID API

The UUID standard library provides an API for generating RFC 4122 identifiers.

The only export of the UUID library that is initially supported is randomUUID(), a method which implements the version 4 "Algorithm for Creating a UUID from Truly Random or Pseudo-Random Numbers", and returns the string representation (as described in RFC-4122).

// We're not yet certain as to how the API will be accessed (whether it's in the global, or a
// future built-in module), and this will be part of the investigative process as we continue
// working on the proposal.
randomUUID(); // "52e6953d-edbe-4953-be2e-65ed3836b2f0"

Math.getRandomValues()

Math.getRandomValues() exposes an identical API to the W3C crypto.getRandomValues() recommendation. With the same guarantees, regarding the quality of randomness:

Implementations should generate cryptographically random values using well-established cryptographic pseudo-random number generators seeded with high-quality entropy, such as from an operating-system entropy source (e.g., "/dev/urandom"). This specification provides no lower-bound on the information theoretic entropy present in cryptographically random values, but implementations should make a best effort to provide as much entropy as practicable.

Math.getRandomValues() will act as the foundation for implementing UUID algorithms, providing a single mockable (see #25) source of randomness.

Out of scope

Algorithms described in RFC 4122 other than version 4 are not initially supported.

Statistics we've collected (see analysis/README.md) indicate that the version 4 algorithm is most widely used:

Algorithm Version Repo Count % Weighted by Watch Count %
v4 4315 77.0% 149802 89.5%
v1 1228 21.9% 16219 9.7%
v5 51 0.9% 1290 0.8%
v3 11 0.2% 116 0.1%

Regarding other UUID versions

While there is utility in other UUID versions, we are advocating starting with a minimal API surface that supports a large percentage of users (the string representation of version 4 UUIDs).

If research and/or user feedback later indicates that additional functionality, such as versions 1, 3, and 5 UUIDs, would add value, this proposal does not preclude these additions.

Use cases

How do folks in the community use RFC 4122 UUIDs?

Creating unique keys for database entries

Generating fake testing data

Writing to temporary files

FAQ

What are the advantages to uuid being in the standard library?

  • The uuid module is relied on by > 2,600,000 repos on GitHub (June 2019). Guaranteeing a secure, consistent, well-maintained UUID implementation provides value to millions of developers.
  • The 12 kb uuid module is downloaded from npm > 62,000,000 times a month (June 2019); making it available in the standard library eventually saves TBs of bandwidth globally. If we continue to address user needs, such as uuid, with the standard library, bandwidth savings add up.

How unique are v4 UUIDs?

If you ignore the challenges involved in random number generation, then v4 UUIDs are unique enough for all but the most stringent use cases. For example, the odds of a collision among 3.3 quadrillion version 4 UUIDs (equivalent to generating a million UUIDs/second for 104 years) is roughly one in a million (p = 0.000001). Source.

That said, the quality of the random number generator is vital to uniqueness. Flawed RNG implementations have led to UUID collisions in real-world systems. It is for this reason that this spec mandates that any random numbers used come from a "cryptographically secure" source, thereby (hopefully) avoiding such issues.

Why call the export randomUUID() and not something like uuidV4()?

As pointed out in the disucssion v4 UUIDs have the maximum amount of entropy possible for a valid UUID as defined in IETF RFC 4122.

UUIDs defined in IETF RFC 4122 are 128 bit numbers that follow a specific byte layout. All of them contain a "version" field comprising 4 bits and a "variant" field comprising 2 bits, meaning that 6 out of 128 bits are reserved for meta information.

Since v4 UUIDs are defined to have all remaining 122 bits set to random values, there cannot be another UUID version that would contain more randomness.

While any name involving v4 requires a rather deep understanding of the intricate meaning of the term "version" in the context of the UUID spec, the term randomUUID() appears to be much more descriptive for v4 UUIDs.

Aren't v1 UUIDs better because they are guaranteed to be unique?

As an oversimplification, v1 UUIDs consist of two parts: A high-precision timestamp and a node id. IETF RFC 4122 contains several requirements that are supposed to ensure that the resulting v1 UUIDs are unique.

  • The timestamp has 100 nanosecond resolution and implementations are required to throw an error or stall on attempts to generate UUIDs at a rate higher than 10M/second on a single node. Realistically that's only enforceable within a single thread/process on a single host. Enforcing this across multiple processes / hosts requires non-trivial architectures that run counter to the main thesis the UUID spec: "One of the main reasons for using UUIDs is that no centralized authority is required to administer them".
  • The mechanism for generating node values preferred by the RFC is to use the host system's IEEE 802 MAC address. This made sense back when the RFC was authored and MAC addresses could reasonably be expected to be unique, but this is arguably no longer the case, not with the proliferation of virtual machines and containers where MAC addresses may not be unique by design.

So in practice, modern implementations will generate a random 48 bit node value each time a process is started leaving a probability of 1 in 248 for collisions in the node part. In the unlikely event of such a collision it would take only 75 milliseconds for a duplicate v1 UUID to appear when generating UUIDs at a rate of 1M/second. So while also unlikely, just like with v4 UUIDs there is no practical guarantee that v1 UUIDs are unique.

Are there privacy concerns related to v1 UUIDs?

If implementations follow the primary recommendations of RFC 4122 then v1 UUIDs would indeed leak the hardware MAC address of the machine where they are being created. As discussed above this would most likely not be the case in modern JavaScript implementations where hardware MAC addresses are either unavailable (browser, serverless functions) or not necessarily unique (containers). However, there are rumors that the presence of the MAC address lead to the arrest of the authors of the Melissa Virus and according to the manual even MySQL 8.0 still uses the hardware MAC address on some operating systems.

In any case the exact creation time of any v1 UUID will be contained within the UUID. This alone can be a privacy or data protection concern for many use cases (e.g. leaking the creation timestamp of a user account) so it's yet another reason to be very careful when choosing to use v1 UUIDs.

How do other languages/libraries deal with UUIDs?

Some other languages/libraries use the term "random" to describe version 4 UUIDs as well (go, Java, C++ Boost).

Apart from that, UUID adoption across other languages/libraries seems to be rather inconsistent:

  • deno added UUID to their standard library, leaving out v3. The code for UUID creation is essentially copied from the uuid npm module, hence method naming follows the vX scheme.
  • Java provides methods for generating v3(UUID.nameUUIDFromBytes()) and v4 (UUID.randomUUID()) UUIDs but not v1 or v5. It would be interesting to investigate further as to why these algorithms were chosen, given that on the one hand time-based UUIDs (v1) appear to have much broader use than name-based (v3/v5) UUIDs and that on the other hand for name-based UUIDs the RFC already recommends v5 over v3.
  • C++ Boost defaults to v5 over v3 for name-based UUIDs but in its implementation anticipates that v5 (which uses SHA-1 for hashing) will be followed up by a newer name-based UUID version which will use a different hashing algorithm ("In anticipation of a new RFC for uuid arriving…").
  • Google's implementation for go has chosen v1 to be the "default" export whose generator method is called NewUUID(), whereas the other exposed methods have names closer to the abstraction we propose: NewRandom() for v4, NewMD5() for v3, NewSHA1() for v5.
  • Python provides methods for generating UUIDs named after the version for all 4 versions (uuid.uuid1(), uuid.uuid3(), uuid.uuid4() and uuid.uuid5()) plus a UUID class to represent UUIDs and transform them into various representations.
  • Rust provides methods for generating UUIDs named after the version for all 4 versions (Uuid::new_v1(), Uuid::new_v3(), Uuid::new_v4() and Uuid::new_v5()) as static members of a Uuid class which is used to represent UUIDs and transform them into various representations.

TODO

  • Identify champion to advance addition (stage-1)
  • Prose outlining the problem or need and general shape of the solution (stage-1)
  • Illustrative examples of usage (stage-1)
  • High-level API (stage-1)
  • Initial spec text (stage-2)
  • Babel plugin (stage-2)
  • Finalize and reviewer sign-off for spec text (stage-3)
  • Test262 acceptance tests (stage-4)
  • tc39/ecma262 pull request with integrated spec text (stage-4)
  • Reviewer sign-off (stage-4)

References

More Repositories

1

proposals

Tracking ECMAScript Proposals
17,177
star
2

ecma262

Status, process, and documents for ECMA-262
HTML
14,437
star
3

proposal-pipeline-operator

A proposal for adding a useful pipe operator to JavaScript.
HTML
7,380
star
4

proposal-pattern-matching

Pattern matching syntax for ECMAScript
HTML
5,341
star
5

proposal-optional-chaining

HTML
4,952
star
6

proposal-type-annotations

ECMAScript proposal for type syntax that is erased - Stage 1
JavaScript
4,090
star
7

proposal-temporal

Provides standard objects and functions for working with dates and times.
HTML
3,135
star
8

proposal-observable

Observables for ECMAScript
JavaScript
3,032
star
9

proposal-signals

A proposal to add signals to JavaScript.
TypeScript
2,668
star
10

proposal-decorators

Decorators for ES6 classes
2,640
star
11

proposal-record-tuple

ECMAScript proposal for the Record and Tuple value types. | Stage 2: it will change!
HTML
2,423
star
12

test262

Official ECMAScript Conformance Test Suite
JavaScript
2,073
star
13

proposal-dynamic-import

import() proposal for JavaScript
HTML
1,859
star
14

proposal-bind-operator

This-Binding Syntax for ECMAScript
1,736
star
15

proposal-class-fields

Orthogonally-informed combination of public and private fields proposals
HTML
1,720
star
16

proposal-async-await

Async/await for ECMAScript
HTML
1,577
star
17

proposal-object-rest-spread

Rest/Spread Properties for ECMAScript
HTML
1,496
star
18

proposal-shadowrealm

ECMAScript Proposal, specs, and reference implementation for Realms
HTML
1,365
star
19

proposal-nullish-coalescing

Nullish coalescing proposal x ?? y
HTML
1,233
star
20

proposal-iterator-helpers

Methods for working with iterators in ECMAScript
HTML
1,220
star
21

proposal-top-level-await

top-level `await` proposal for ECMAScript (stage 4)
HTML
1,082
star
22

proposal-partial-application

Proposal to add partial application to ECMAScript
HTML
1,002
star
23

proposal-do-expressions

Proposal for `do` expressions
HTML
990
star
24

agendas

TC39 meeting agendas
JavaScript
952
star
25

proposal-binary-ast

Binary AST proposal for ECMAScript
945
star
26

proposal-built-in-modules

HTML
886
star
27

proposal-async-iteration

Asynchronous iteration for JavaScript
HTML
854
star
28

proposal-explicit-resource-management

ECMAScript Explicit Resource Management
JavaScript
671
star
29

proposal-operator-overloading

JavaScript
610
star
30

proposal-string-dedent

TC39 Proposal to remove common leading indentation from multiline template strings
HTML
588
star
31

proposal-bigint

Arbitrary precision integers in JavaScript
HTML
560
star
32

proposal-set-methods

Proposal for new Set methods in JS
HTML
557
star
33

proposal-import-attributes

Proposal for syntax to import ES modules with assertions
HTML
538
star
34

ecmascript_simd

SIMD numeric type for EcmaScript
JavaScript
536
star
35

proposal-slice-notation

HTML
515
star
36

proposal-change-array-by-copy

Provides additional methods on Array.prototype and TypedArray.prototype to enable changes on the array by returning a new copy of it with the change.
HTML
509
star
37

ecma402

Status, process, and documents for ECMA 402
HTML
506
star
38

notes

TC39 meeting notes
JavaScript
496
star
39

proposal-class-public-fields

Stage 2 proposal for public class fields in ECMAScript
HTML
489
star
40

proposal-iterator.range

A proposal for ECMAScript to add a built-in Iterator.range()
HTML
464
star
41

proposal-throw-expressions

Proposal for ECMAScript 'throw' expressions
JavaScript
425
star
42

proposal-module-expressions

HTML
424
star
43

proposal-UnambiguousJavaScriptGrammar

413
star
44

proposal-decimal

Built-in decimal datatype in JavaScript
HTML
408
star
45

proposal-array-grouping

A proposal to make grouping of array items easier
HTML
407
star
46

proposal-async-context

Async Context for JavaScript
HTML
406
star
47

proposal-weakrefs

WeakRefs
HTML
404
star
48

proposal-error-cause

TC39 proposal for accumulating errors
HTML
378
star
49

proposal-ecmascript-sharedmem

Shared memory and atomics for ECMAscript
HTML
376
star
50

proposal-cancelable-promises

Former home of the now-withdrawn cancelable promises proposal for JavaScript
Shell
376
star
51

proposal-relative-indexing-method

A TC39 proposal to add an .at() method to all the basic indexable classes (Array, String, TypedArray)
HTML
351
star
52

proposal-first-class-protocols

a proposal to bring protocol-based interfaces to ECMAScript users
350
star
53

proposal-global

ECMAScript Proposal, specs, and reference implementation for `global`
HTML
346
star
54

proposal-private-methods

Private methods and getter/setters for ES6 classes
HTML
344
star
55

proposal-numeric-separator

A proposal to add numeric literal separators in JavaScript.
HTML
327
star
56

proposal-private-fields

A Private Fields Proposal for ECMAScript
HTML
320
star
57

proposal-object-from-entries

TC39 proposal for Object.fromEntries
HTML
317
star
58

proposal-module-declarations

JavaScript Module Declarations
HTML
314
star
59

proposal-promise-allSettled

ECMAScript Proposal, specs, and reference implementation for Promise.allSettled
HTML
314
star
60

tc39.github.io

Get involved in specifying JavaScript
HTML
313
star
61

proposal-regex-escaping

Proposal for investigating RegExp escaping for the ECMAScript standard
JavaScript
309
star
62

proposal-await.ops

Introduce await.all / await.race / await.allSettled / await.any to simplify the usage of Promises
HTML
308
star
63

proposal-logical-assignment

A proposal to combine Logical Operators and Assignment Expressions
HTML
302
star
64

proposal-export-default-from

Proposal to add `export v from "mod";` to ECMAScript.
HTML
297
star
65

proposal-promise-finally

ECMAScript Proposal, specs, and reference implementation for Promise.prototype.finally
HTML
278
star
66

proposal-asset-references

Proposal to ECMAScript to add first-class location references relative to a module
268
star
67

proposal-cancellation

Proposal for a Cancellation API for ECMAScript
HTML
262
star
68

proposal-json-modules

Proposal to import JSON files as modules
HTML
259
star
69

proposal-promise-with-resolvers

HTML
255
star
70

proposal-string-replaceall

ECMAScript proposal: String.prototype.replaceAll
HTML
254
star
71

proposal-export-ns-from

Proposal to add `export * as ns from "mod";` to ECMAScript.
HTML
241
star
72

proposal-ses

Draft proposal for SES (Secure EcmaScript)
HTML
217
star
73

proposal-structs

JavaScript Structs: Fixed Layout Objects
216
star
74

proposal-intl-relative-time

`Intl.RelativeTimeFormat` specification [draft]
HTML
215
star
75

proposal-flatMap

proposal for flatten and flatMap on arrays
HTML
215
star
76

proposal-json-parse-with-source

Proposal for extending JSON.parse to expose input source text.
HTML
204
star
77

ecmarkup

An HTML superset/Markdown subset source format for ECMAScript and related specifications
TypeScript
201
star
78

proposal-promise-any

ECMAScript proposal: Promise.any
HTML
198
star
79

proposal-decorators-previous

Decorators for ECMAScript
HTML
184
star
80

proposal-smart-pipelines

Old archived draft proposal for smart pipelines. Go to the new Hack-pipes proposal at js-choi/proposal-hack-pipes.
HTML
181
star
81

proposal-defer-import-eval

A proposal for introducing a way to defer evaluate of a module
HTML
174
star
82

proposal-array-filtering

A proposal to make filtering arrays easier
HTML
171
star
83

proposal-optional-chaining-assignment

`a?.b = c` proposal
168
star
84

proposal-array-from-async

Draft specification for a proposed Array.fromAsync method in JavaScript.
HTML
167
star
85

proposal-extractors

Extractors for ECMAScript
JavaScript
166
star
86

proposal-upsert

ECMAScript Proposal, specs, and reference implementation for Map.prototype.upsert
HTML
165
star
87

proposal-ptc-syntax

Discussion and specification for an explicit syntactic opt-in for Tail Calls.
HTML
165
star
88

how-we-work

Documentation of how TC39 operates and how to participate
161
star
89

proposal-collection-methods

HTML
160
star
90

proposal-Array.prototype.includes

Spec, tests, reference implementation, and docs for ESnext-track Array.prototype.includes
HTML
157
star
91

proposal-error-stacks

ECMAScript Proposal, specs, and reference implementation for Error.prototype.stack / System.getStack
HTML
156
star
92

proposal-promise-try

ECMAScript Proposal, specs, and reference implementation for Promise.try
HTML
154
star
93

proposal-hashbang

#! for JS
HTML
148
star
94

proposal-resizablearraybuffer

Proposal for resizable array buffers
HTML
145
star
95

proposal-import-meta

import.meta proposal for JavaScript
HTML
145
star
96

proposal-intl-segmenter

Unicode text segmentation for ECMAScript
HTML
145
star
97

proposal-extensions

Extensions proposal for ECMAScript
HTML
143
star
98

proposal-seeded-random

Proposal for an options argument to be added to JS's Math.random() function, and some options to start it with.
HTML
143
star
99

proposal-intl-duration-format

141
star
100

proposal-regexp-unicode-property-escapes

Proposal to add Unicode property escapes `\p{…}` and `\P{…}` to regular expressions in ECMAScript.
HTML
134
star