# Post-quantum readiness

> DaloyJS has no encryption or key exchange of its own, so the urgent part of a post-quantum migration is your runtime's TLS. The part the framework owns is token signatures, and `jwk()` and `createJwtVerifier()` verify ML-DSA tokens when you list the algorithm.

OAuth2 role Resource Server

Your API's job. DaloyJS is built for this.

Accepts a token that somebody else issued, verifies its signature and claims, and decides whether this caller may touch this resource. Verifying is not the same as issuing: you always own verification, even when a provider owns the login.

Verifying an ML-DSA token is the same job as verifying an RS256 one. Your identity provider decides when it starts issuing post-quantum tokens; this page is about being able to accept them.

[Auth architecture: where DaloyJS fits in OAuth2 & OpenID Connect](/docs/auth/architecture) explains all three roles and the two deployment shapes we recommend.

## What quantum attacks affect

A large quantum computer breaks today's public-key algorithms: RSA, ECDSA, EdDSA and Diffie-Hellman key exchange. Symmetric cryptography and hash functions are not affected in the same way. That splits the framework into three layers.

**Diagram: Where public-key cryptography appears**

- **TLS key exchange** - Owned by the runtime and the platform, not by DaloyJS - [Node / OpenSSL, Bun, Deno, Workers, your proxy]
- **Token and message signatures** - Owned by DaloyJS. ML-DSA is available for JWTs when listed - [jwk(), createJwtVerifier(), createJwtSigner(), http-signatures]
- **Symmetric keys and hashes** - Not affected. Nothing to migrate - [session() HMAC, webhook HMAC, HS256 tokens, scrypt passwords, cursor signing]

Recorded traffic can be decrypted later, so key exchange is the urgent layer. A signature only has to hold until the token expires.

| Area | What DaloyJS uses | Affected | What to do |
| --- | --- | --- | --- |
| TLS | Whatever the runtime negotiates | Yes, and it is urgent | Keep the runtime current and [check the key exchange](#tls) |
| `jwk()`, `createJwtVerifier()` | RS, PS, ES, EdDSA, and ML-DSA when listed | Yes, later | [List an ML-DSA algorithm](#ml-dsa) once your issuer publishes such keys |
| `http-signatures` | Ed25519, ECDSA, RSA, HMAC | Yes, later | Nothing yet. That module has no post-quantum algorithm |
| `session()`, cursors, webhooks | HMAC-SHA-256 | No | Nothing |
| `passwordHash()` | scrypt | No | Nothing |
| `clientCertAuth()` | The certificate your CA issued | Decided by your CA | Follow your CA's migration |

## TLS is the urgent part

DaloyJS does not configure TLS groups. The Node adapter, `fetchGuard()` and plain `fetch()` all use the runtime's defaults, so the fix for recorded-traffic attacks is a runtime that offers the hybrid group `X25519MLKEM768` and a peer that accepts it.

Check what your deployment negotiates instead of trusting a version number:

```ts title="scripts/check-tls.ts"
import tls from "node:tls";

const host = "api.example.com";
const socket = tls.connect({ host, port: 443, servername: host }, () => {
  console.log(socket.getProtocol(), socket.getEphemeralKeyInfo());
  // TLSv1.3 { type: 'TLSGroup', name: 'X25519MLKEM768' }
  socket.end();
});
```

If the name is `X25519` or a `P-256` curve, one side does not offer the hybrid group. Update the runtime first: DaloyJS supports every Node 24 release, but an older 24 patch release may not offer the hybrid group by default. Then check the proxy or load balancer in front of the app, because it terminates TLS for your clients.

> [!NOTE]
> The same applies to outbound calls. `fetchGuard()` blocks SSRF targets; it does not change which TLS group the runtime offers to the services you call.

## ML-DSA tokens

ML-DSA is the NIST post-quantum signature standard (FIPS 204). [RFC 9964](https://www.rfc-editor.org/rfc/rfc9964) registers it for JWTs as `ML-DSA-44`, `ML-DSA-65` and `ML-DSA-87`, with keys published as `kty: "AKP"` JSON Web Keys.

Nothing accepts these algorithms by default. A verifier takes them only when its allowlist names them, the same rule as every other algorithm:

```ts title="src/build-app.ts"
import { App, jwk } from "@daloyjs/core";

app.use(jwk({
  jwks: "https://login.example.com/.well-known/jwks.json",
  algorithms: ["ES256", "ML-DSA-65"],
  issuer: "https://login.example.com/",
  audience: "books-api",
}));
```

Listing both lets the issuer move at its own pace: classical tokens keep verifying, and ML-DSA tokens verify as soon as the JWKS carries an ML-DSA key. Remove the classical algorithm once the issuer has stopped signing with it.

With a key you hold yourself, pass the public JWK or a `CryptoKey`:

```ts title="src/verify.ts"
import { createJwtVerifier, type AkpJsonWebKey } from "@daloyjs/core";

const publicKey: AkpJsonWebKey = {
  kty: "AKP",
  alg: "ML-DSA-65",
  pub: process.env.TOKEN_PUBLIC_KEY!, // base64url of the raw ML-DSA public key
};

const verifier = createJwtVerifier({
  algorithms: ["ML-DSA-65"],
  key: publicKey,
  issuer: "https://tokens.internal.example/",
  audience: "books-api",
});
```

### Runtime support

ML-DSA runs through WebCrypto, so `@daloyjs/core` still has no runtime dependency. The runtime must implement it. Check before you list the algorithm:

```ts
const supported = (SubtleCrypto as { supports?: (op: string, alg: string) => boolean })
  .supports?.("verify", "ML-DSA-65") ?? false;
```

On a runtime without ML-DSA the verifier rejects the token with `unsupported_alg`, and `jwk()` answers `401`. It never falls back to another algorithm.

### What the verifier checks

- The token's `alg` must be in the allowlist. `ML-DSA-65` in the list does not accept `ML-DSA-44` or `ML-DSA-87`.
- The JWK must be `kty: "AKP"` and its `alg` must equal the token's algorithm. RFC 9964 makes `alg` mandatory on these keys, and the `AKP` key type is shared with other algorithms, so this is what ties a key to ML-DSA and to one parameter set.
- `pub` must have the exact length for the parameter set, so a key relabelled as a different set is refused before it is used.
- A verification key must not carry `priv`. A JWKS that publishes a private seed is rejected instead of quietly used.
- `HS*` next to a JWK source is still refused at construction, and `alg: "none"` is still refused everywhere.

| Code | Meaning |
| --- | --- |
| `alg_not_allowed` | The token's algorithm is not in the allowlist |
| `key_algorithm_mismatch` | The key's `alg` is missing or names a different algorithm |
| `invalid_key` | Not an `AKP` key, wrong `pub` length, a `priv` on a verification key, or the runtime refused it |
| `unsupported_alg` | The runtime's WebCrypto has no ML-DSA |
| `invalid_signature` | The signature does not verify |

### Token size

ML-DSA signatures are large. Plan for it before you switch.

| Algorithm | Public key | Signature | Signature in a token |
| --- | --- | --- | --- |
| `ES256` | 65 bytes | 64 bytes | 86 characters |
| `ML-DSA-44` | 1,312 bytes | 2,420 bytes | 3,227 characters |
| `ML-DSA-65` | 1,952 bytes | 3,309 bytes | 4,412 characters |
| `ML-DSA-87` | 2,592 bytes | 4,627 bytes | 6,170 characters |

- **Cookies:** browsers cap a cookie near 4 KB, so an ML-DSA token does not fit in one. Send it in the `Authorization` header, or keep a [session](/docs/security/session) cookie and hold the token server-side.
- **Header limits:** the Node adapter accepts 16 KiB of headers by default (`maxHeaderBytes`), which fits every parameter set. Many proxies cap a single header line at 8 KB; an `ML-DSA-87` token with large claims gets close to that.
- **JWKS size:** `jwk()` caps a fetched key set at 1 MiB, which is room for hundreds of ML-DSA keys.

### Signing

`createJwtSigner()` accepts the same three algorithms, with a `CryptoKey` or an `AkpJsonWebKey` whose `priv` is the 32-byte seed. Minting tokens is authorization-server work, so the boundary described in the [security API reference](/docs/api-reference/security) applies here too.

## A migration order that works

1. ### Fix TLS first

  Update the runtime, run the check above against production, and confirm the proxy in front of the app offers the hybrid group.
2. ### List where you verify public-key signatures

  Search for `jwk(` and `createJwtVerifier(` and note each issuer.
3. ### Add the ML-DSA algorithm next to the classical one

  Do this when an issuer announces post-quantum keys, after checking that the runtime supports ML-DSA.
4. ### Check sizes on the path the token takes

  Cookies, proxy header limits, and any gateway that logs or stores tokens.
5. ### Remove the classical algorithm

  Take it out of the allowlist once the issuer has stopped signing with it.

## Related

- [JWT and authentication safeguards](/docs/security/auth-slice) for `jwk()` in full.
- [Security API reference](/docs/api-reference/security) for `JwtAlgorithm`, `AkpJsonWebKey` and the signer boundary.
- [FIPS 204](https://csrc.nist.gov/pubs/fips/204/final), the ML-DSA standard, and [RFC 9964](https://www.rfc-editor.org/rfc/rfc9964), its JOSE registration.

---

Source: https://daloyjs.dev/docs/security/post-quantum