crypto
Random values, digests, and base64. Everything is synchronous except
subtle.digest, which returns a Promise (resolved immediately).
crypto.randomUUID()
Use it for request ids, session ids, and primary keys:
crypto.getRandomValues(typedArray)
Non-typed arguments throw:
crypto.subtle.digest(algorithm, data)
Errors are TypeErrors thrown synchronously (before the Promise):
Hashing a stream of chunks
There is no
SubtleCrypto.sign,verify,encrypt,decrypt,generateKey, orimportKey. For signatures and key exchange, useffiwith a native library.
btoa / atob (globals)
btoa deviates from the spec in your favour: non-Latin-1 input does
not throw — it encodes the UTF-8 bytes, and atob decodes them
straight back, so Unicode round-trips with no workaround:
atob does throw on malformed input:
Not provided
Gotchas
subtle.digestcomputes synchronously and resolves on the microtask queue — awaiting it does not free the loop for I/O.getRandomValuesisUint8Array-only-ish: any TypedArray works, plain arrays/strings throw.btoa/atobdon't throw on non-Latin-1 — both sides go through UTF-8, so Unicode round-trips (unlike browsers).- No
cryptokeys, no TLS material access — see TLS for server certificates.
