crypto.subtle methods (which resolve on the
microtask queue) and crypto.bcrypt (which runs off the event loop on a dedicated thread pool).
crypto.randomUUID()
crypto.getRandomValues(typedArray)
crypto.subtle.digest(algorithm, data)
TypeErrors thrown synchronously (before the Promise):
Hashing a stream of chunks
crypto.subtle HMAC (importKey, sign, verify, exportKey)
crypto.subtle supports HMAC keys and constant-time verification across
SHA-1, SHA-256, SHA-384, and SHA-512:
Asymmetric algorithms (RSA, ECDSA, Ed25519), symmetric encryption (encrypt/decrypt), and key generation (generateKey) are not built in. Useffiwith a native library when you need those primitives.
crypto.bcrypt (hash, verify)
Native promise-based bcrypt password hashing running on a dedicated background
worker pool off the event loop. Hashing or verifying passwords will never starve
or stutter HTTP traffic, WebSocket connections, or timer callbacks.
Safety & Constraints
- Passwords ≤ 72 bytes: Per bcrypt design, passwords exceeding 72 bytes are
rejected (
Error: bcrypt: password exceeds 72 bytes). - Bounded worker queue: Backed by a dedicated thread pool (2–4 threads with
256 KiB stacks) and a fixed 16-slot ring queue. If all 16 slots are busy, calls
reject immediately with
Error: crypto.bcrypt: queue fullrather than growing unbounded memory. - Off-event-loop execution: Key derivation and crypt rounds execute strictly on worker threads. CSPRNG salt generation occurs synchronously on dispatch; no allocations occur on the hot path after initialization.
- Main-thread only: Calling
crypto.bcryptinside aWorkerthread throwsTypeError: crypto.bcrypt is not available in workers. - No sync methods:
hashSyncandverifySyncare intentionally not provided to prevent developers from blocking the event loop.
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
crypto.subtlemethods compute synchronously and resolve on the microtask queue — awaiting them 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).crypto.subtlekeys only support"raw"HMAC — for TLS server certificates, see TLS.