demo · v140
Hex Inspector
Hex isn't just for prettier console logs. Hash digests, MAC addresses, content-IDs, ed25519 signatures, file magic numbers — they all show up as hex strings on the wire. The new toHex / fromHex pair lets you skip the for-loop and rendering tax.
awaiting parse
// Encode a digest to hex without the for-loop tax.
const buf = await crypto.subtle.digest("SHA-256", input);
const hex = new Uint8Array(buf).toHex();
// Parse a content-ID back into bytes.
const bytes = Uint8Array.fromHex("89504e470d0a1a0a");
console.log(bytes[0] === 0x89); // PNG file header magic
why this matters
Before today every codebase had a function like buf => Array.from(buf, b => b.toString(16).padStart(2, "0")).join(""). Cute, but it's surprisingly hot in WebAuthn and Web Crypto code paths. The native methods are an order of magnitude faster for the common 32- and 64-byte cases, accept whitespace if you opt in, and validate every nibble before allocating.
see also
- Uint8Array to/from base64 and hex — feature index
- Proposal