tc39 / proposal-csprng

Cryptographically Secure Random Number Generation for ECMAScript
BSD 3-Clause "New" or "Revised" License
70 stars 9 forks source link

Errors thrown from getRandomValues in WebCrypto incompatible with current proposal #5

Open rbuckton opened 4 years ago

rbuckton commented 4 years ago

We need to discuss error compatibility with the Web Cryptography API. The WebCrypto definition of getRandomValues specifies the following exceptions are thrown:

  1. If array is not of an integer type (i.e., Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array or Uint8ClampedArray), throw a TypeMismatchError and terminate the algorithm.

  2. If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.

The current proposal uses TypeError instead of TypeMismatchError and RangeError instead of QuotaExceededError, so as not to introduce new Error classes that have only one use in the spec. However, should #2 land this deviation could be considered a web-compat issue.

I am looking for suggestions to address this, either from TC39 members or from those involved with the WebCrypto specification.

Ideally, I would like to avoid redundancy (i.e. TypeMismatchError seems like a redundant form of TypeError), but I also do not want to break existing user code.