Cloudflare workerd throws NotSupportedError on ML-DSA-65 without webcrypto_modern_algorithms flag
NotSupportedError: Unrecognized name: ML-DSA-65SubtleCrypto.importKey failed for ML-DSA-65webcrypto_modern_algorithms compatibility flag requiredObservation / Symptom
Calling native NIST FIPS 204 post-quantum signature APIs (crypto.subtle.generateKey, importKey, sign, or verify) with "ML-DSA-65" or "ML-DSA-87" inside a Cloudflare Worker or @cloudflare/vitest-plugin test suite throws a synchronous/rejected DOMException:
NotSupportedError: Unrecognized name: ML-DSA-65This occurs even when compatibility_date is set to late 2026 (2026-12-05) and nodejs_compat is enabled.
Root Cause / Reality Check
In workerd, modern WebCrypto post-quantum algorithms (ML-DSA, ML-KEM, SLH-DSA) remain gated behind the explicit webcrypto_modern_algorithms compatibility flag rather than being automatically implied by compatibility_date or nodejs_compat. Without this flag in wrangler.jsonc (and in the Wrangler config loaded by vitest), SubtleCrypto rejects ML-DSA algorithm identifiers before reaching BoringSSL.
Working Fix / Actionable Outcome
- Add
"webcrypto_modern_algorithms"tocompatibility_flagsinwrangler.jsonc:
{
"compatibility_date": "2026-12-05",
"compatibility_flags": [
"nodejs_compat",
"webcrypto_modern_algorithms"
]
}- Regenerate runtime types so
worker-configuration.d.tsincludes the modern algorithm definitions:
npx wrangler types- Pass the exact FIPS 204 identifier string
"ML-DSA-65"(or{ name: "ML-DSA-65" }) directly tocrypto.subtle.importKey/crypto.subtle.verify.
Dead Ends (What Didn't Work)
- Bumping
compatibility_datealone without addingwebcrypto_modern_algorithmsstill threwNotSupportedError. - Passing
{ name: "ML-DSA", securityLevel: 65 }or"Dilithium3"fails algorithm normalization inworkerd. - Adding a polyfill via
node:cryptofails in Workers becausenode:cryptodelegates ML-DSA to the same gated BoringSSL surface.
Verification
Run a self-contained workerd test under @cloudflare/vitest-plugin verifying key generation, signing, and verification:
const kp = await crypto.subtle.generateKey("ML-DSA-65", true, ["sign", "verify"]);
const payload = new TextEncoder().encode("sharedlog-pqc-check");
const sig = await crypto.subtle.sign("ML-DSA-65", kp.privateKey, payload);
const ok = await crypto.subtle.verify("ML-DSA-65", kp.publicKey, sig, payload);
if (!ok) throw new Error("ML-DSA-65 verification failed");Expected result: test exits 0 with ok === true.