Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate proposal for CSPRNG "source of truth" #37

Open
rbuckton opened this issue Dec 5, 2019 · 2 comments
Open

Separate proposal for CSPRNG "source of truth" #37

rbuckton opened this issue Dec 5, 2019 · 2 comments

Comments

@rbuckton
Copy link

rbuckton commented Dec 5, 2019

This was brought up at TC39, with respect to whether random UUIDs should be based on a separate API that would provide a single "source of truth" for generating cryptographically-secure pseudo-random numbers similar to crypto.getRandomValues. This had to do primarily with @erights's concerns about mocking an API.

The main issue with possibly subsuming crypto.getRandomValues from the Web API is the dependence on DOMException-derived errors, and that changing those cases to TypeErrors and RangeErrors could go against "web reality" where people may be filtering exceptions using instanceof.

I put together an outline for a proposal to adopt the semantics of crypto.getRandomValues under a different name, and wanted to spark further discussion here before considering whether to make it a full-blown proposal: https://gist.github.com/rbuckton/0777210dc3086e1a90375354b045a3a7

The idea being to add an ArrayBuffer.fillRandom(view) static method that uses the same semantics as the Web Crypto APIs, except with the errors swapped. I propose making it a method on ArrayBuffer for several reasons:

  • Does not introduce a new global namespace for cryptography, as specifying a crypto global in ECMA-262 could cause complications with how to specify it such that the Web cryptography APIs could be layered on top.
  • Provides a single location for mocking the CSPRNG, vs a method on each TypedArray prototype.
@bcoe
Copy link
Collaborator

bcoe commented Dec 6, 2019

@rbuckton thanks for this great summary.

@rbuckton
Copy link
Author

rbuckton commented Feb 4, 2020

The proposal for this specific feature can now be found here: https://github.com/rbuckton/proposal-arraybuffer-fillrandom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants