If your team builds on Cloudflare, pdf-pqs-worker gives you a ready-to-deploy Worker that handles both domain discovery and PDF signing in one project while keeping signing strictly private:
- Public discovery endpoint. Serves your policy document at
https://pdfpqs.<domain>/.well-known/pdfpqs.json, along with any issuer certificates and CRLs hosted on that same subdomain. - Private signing service. Exposes a
PdfPqsSignerRPC entrypoint so your other Workers can sign PDFs over an internal Cloudflare service binding. Signing is never exposed over public HTTP.
Before you start
- Obtain an ML-DSA-65 or ML-DSA-87 certificate. ML-DSA-44 is not allowed by PDF-PQS.
- Create an AWS KMS signing key. Provision an asymmetric key with key spec
ML_DSA_65and key usageSIGN_VERIFY. Create a dedicated IAM user or credential scoped tokms:Signon that single key only. - Route
pdfpqs.<domain>to the Worker. Attach it as a Custom Domain on your Cloudflare zone, or point aCNAMEfrom your DNS zone to a provider running the Worker.
Configuration and code examples
Install
Clone the Worker project, install dependencies, and run the built-in test suite:
git clone https://github.com/pdf-pqs/pdf-pqs-worker
cd pdf-pqs-worker
pnpm install
pnpm testConfigure the policy document
Define your policy document inside wrangler.jsonc. The domain field controls which hostname the Worker accepts: it only responds to requests for pdfpqs.<domain>.
{
"name": "pdf-pqs-worker",
"main": "src/index.ts",
"compatibility_flags": ["nodejs_compat"],
"workers_dev": false,
"preview_urls": false,
"assets": { "directory": "./public", "binding": "ASSETS", "run_worker_first": true },
"routes": [{ "pattern": "pdfpqs.example.com", "custom_domain": true }],
"vars": {
"PDFPQS_DOCUMENT": {
"version": 1,
"domain": "example.com",
"pqcRequiredFrom": "2026-12-01T00:00:00Z",
"issuers": [
{
"certificate": "https://pdfpqs.example.com/certs/client-example.der",
"crl": "https://pdfpqs.example.com/crl/client-example.crl"
}
]
},
"SIGNER_BACKEND": "kms",
"AWS_REGION": "ca-central-1",
"KMS_KEY_ID": "alias/your-ml-dsa-key"
}
}Any certificate or CRL URL pointing to pdfpqs.<domain> (like public/certs/client-example.der and public/crl/client-example.crl above) is served automatically from ./public. All other paths are blocked.
Set the secrets
Store your signing certificate, intermediate chain, and scoped AWS credentials as Wrangler secrets so they are never committed to source control:
wrangler secret put SIGNER_CERT # PEM certificate matching your KMS key
wrangler secret put SIGNER_CHAIN # Intermediate PEM certificates (omit the root CA)
wrangler secret put AWS_ACCESS_KEY_ID # IAM user with kms:Sign on this key only
wrangler secret put AWS_SECRET_ACCESS_KEYVerify the policy route locally
Start the Worker with wrangler dev and check that it serves the policy document with the expected JSON and security headers:
curl -i -H 'Host: pdfpqs.example.com' http://127.0.0.1:8787/.well-known/pdfpqs.jsonHTTP/1.1 200 OK
Content-Type: application/json
Access-Control-Allow-Origin: *
Cache-Control: public, max-age=3600
X-Content-Type-Options: nosniffRequests for any other Host header return 421 Misdirected Request, and unrecognized paths return 404.
Call the signer from another Worker
To sign PDFs from your application Worker, add a Cloudflare service binding targeting the PdfPqsSigner entrypoint. Because this entrypoint is not exposed over HTTP, only Workers in your account with an explicit binding can invoke it:
{
"services": [
{ "binding": "PDFPQS", "service": "pdf-pqs-worker", "entrypoint": "PdfPqsSigner" }
]
}import type { PdfPqsSigner } from '../pdf-pqs-worker/src/index.ts'
interface Env {
PDFPQS: Service<PdfPqsSigner>
}
export default {
async fetch(request, env) {
// Authorize the caller first. The binding signs any PDF that it receives.
const pdf = new Uint8Array(await request.arrayBuffer())
const signed = await env.PDFPQS.sign(pdf, { place: 'b' })
return new Response(signed, { headers: { 'Content-Type': 'application/pdf' } })
},
} satisfies ExportedHandler<Env>Calling sign(pdf, { place }) signs the bytes [0, L) (where L is the length of the input PDF) and returns the signed PDF bytes. Passing place: 'a' also requires configuring your classical host key and certificate (HOST_KEY, HOST_CERT). You can also call publicDocument() to retrieve the configured policy JSON directly.
Verify the signed PDF
Check the signed file with the pdfpqs CLI:
pdfpqs verify signed.pdf --json --trust root.pem \
--certs issuing.pem client-example.pem \
--crl root.crl issuing.crl client-example.crl{
"result": "valid",
"signatures": [
{
"place": "B",
"L": 1044,
"codes": ["W_NO_TIMESTAMP"],
"signer": "CN=Example Document Signer,O=Example Org,C=CA",
"attachment": "pdfpqs-1.p7s"
}
],
"fileCodes": []
}Because the Worker does not attach an RFC 3161 timestamp, W_NO_TIMESTAMP is expected in the output.
What the Worker does when signing
Each time another Worker calls env.PDFPQS.sign(pdf, options), the signer runs five safeguards before returning the signed bytes:
- Validates the input PDF to ensure it ends cleanly at a revision boundary, and refuses any document locked with a DocMDP level-1 certification.
- Builds and sorts the signed attributes over
[0, L)in canonical DER order. - Calls AWS KMS to sign using
MessageType: "RAW"andSigningAlgorithm: "ML_DSA_SHAKE_256"(pure ML-DSA with an empty context string). - Self-verifies the signature against the signer certificate’s public key before writing it into the PDF.
- Appends the payload in Place A or Place B as a new incremental update after byte
L.
Because Cloudflare’s workerd runtime does not include native ML-DSA in WebCrypto or node:crypto, the Worker performs its self-verification in pure JavaScript using @noble/post-quantum. For local development and automated tests, you can also configure a local key secret instead of KMS.
After signing a test file, verify the output with the CLI or inspect it with OpenSSL.