DEV Community

Minute Notary
Minute Notary

Posted on Fully Autonomous

Verifying a sealed PDF in the browser: SHA-256, ECDSA P-256, RFC 3161 and a hash chain

A PDF arrives with a seal on it. How does the person holding it check that seal without trusting the sender, and without uploading the document anywhere?

We needed an answer for the PDFs our office seals, so we wrote one down as a spec and built an open-source verifier around it: sealed-pdf-verify. It runs as a library (Node 20+ and browsers), a CLI, and a single HTML file that works from file:// with no network requests. This post walks through the five checks it makes, the one place WebCrypto was not enough, and what a "genuine" result does not prove.

What the holder receives

Two files: the PDF, and a small proof JSON next to it. Trimmed:

{
  "schemaVersion": 1,
  "sealId": "…",
  "documentHash": "<64 hex: SHA-256 of the exact PDF bytes>",
  "algorithm": "OCI_ECDSA_P256_SHA256",
  "signature": "<base64 DER ECDSA signature>",
  "publicKeyPem": "-----BEGIN PUBLIC KEY-----…",
  "tsaToken": "<base64 DER RFC 3161 TimeStampToken, or null>",
  "ledger": { "seq": 123, "previousEntryHash": "<64 hex>", "entryHash": "<64 hex>" },
  "sealedAt": "2026-11-04T15:04:05.000Z"
}
Enter fullscreen mode Exit fullscreen mode

Everything the verifier needs is in those two files. The full format is in the specification, written so anyone can build their own checker without reading our code.

Check 1: the bytes

const digest = new Uint8Array(await crypto.subtle.digest('SHA-256', pdfBytes));
Enter fullscreen mode Exit fullscreen mode

The digest must equal documentHash, compared in constant time. This is a seal on bytes, not on how the page looks: open the PDF in an editor, save it, and the check fails, even if you changed nothing visible. That is the point.

Check 2: the signature, and why WebCrypto wasn't enough

The issuer signs the 32-byte digest with ECDSA P-256 in a cloud KMS. The digest is the ECDSA message; it is not hashed a second time.

crypto.subtle.verify can't express that. It always hashes whatever you pass in, and it only accepts the raw 64-byte r || s encoding, while the KMS returns DER. If you have the PDF, passing the whole file to WebCrypto works out to the same math. But the verifier also has a proof-only mode where it holds the digest and not the file, and there WebCrypto would hash the digest again.

So the signature goes through @noble/curves in prehashed mode:

import { p256 } from '@noble/curves/nist.js';

// `compact` is r || s, converted from DER after a strict parse
// (minimal lengths and integers, no trailing bytes).
const ok = p256.verify(compact, digest, publicKeyPoint, {
  prehash: false, // the digest is the message
  lowS: false,    // high-S is valid ECDSA: accept it on purpose
  format: 'compact',
});
Enter fullscreen mode Exit fullscreen mode

Two details that were easy to get wrong:

  • Do not enforce low-S. Low-S is a malleability rule some blockchains add on top of ECDSA, not part of ECDSA verification, and a signer that does not normalise S produces perfectly valid high-S signatures.
  • Reject r or s outside [1, n-1].

Check 3: is it the issuer's key?

A valid signature only proves that someone holding some private key signed these bytes. Anyone can generate a key pair and write a proof that passes the math. So the verifier computes a fingerprint, the SHA-256 of the key's SubjectPublicKeyInfo DER:

openssl ec -pubin -in key.pem -outform DER | openssl dgst -sha256
Enter fullscreen mode Exit fullscreen mode

It then compares that fingerprint with a trust list you fill in yourself. The result has three states:

  • pinned: the key is on your list.
  • rejected: the key is not on your list, and the whole verdict becomes "altered".
  • unpinned: you gave no list. The verifier says so plainly, instead of pretending the math settles it.

The issuer's fingerprint is published in two places, so you can compare one against the other: trust/issuers.json in the repo, and the issuer's own check page at https://minutenotary.ca/verify (we are Minute Notary, an Ontario notary office; the PDFs we seal are the ones this tool was built for).

Check 4: the RFC 3161 timestamp

The issuer's own clock proves nothing about time. A timestamp authority (TSA) does: it signs a token over the same digest. The verifier checks the token in two layers:

  • Imprint (required). TSTInfo.messageImprint must be SHA-256 and must equal the document digest. That binds the token to this document. genTime becomes the trusted time.
  • Trust (on by default). Exactly one SignerInfo. SHA-2 digest only (SHA-1 is refused before anything else is looked at). RSA or ECDSA signature over the signed attributes. A signer certificate whose extended key usage is critical and contains only id-kp-timeStamping. Validity at genTime. A chain to a root the verifier trusts. Two roots are bundled (DigiCert Trusted Root G4 and FreeTSA), and callers can add their own.

ASN.1 and CMS parsing goes through PKI.js and the @peculiar/asn1-* packages. The tests include a real FreeTSA token plus a synthetic TSA generated in the suite, so chain validation is exercised fully offline.

One honest limit: offline means no CRL and no OCSP. A TSA certificate revoked after the fact still verifies as trusted. The docs say so, and the threat model lists it next to the other things a "genuine" result does not cover.

Check 5: the ledger entry

Every seal also gets an entry in an append-only hash chain:

const line = `${seq}\n${documentHash}\n${previousEntryHash}\n${sealedAt}`;
const entryHash = hex(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(line)));
Enter fullscreen mode Exit fullscreen mode

The verifier recomputes that hash and compares it with the proof. A single entry only proves local consistency; it cannot show that the issuer never forked the chain. Two things go further:

  • An evidence ZIP carries a segment of the chain, and the verifier walks it link by link.
  • The issuer's online check compares against the published chain.

The verdict

overall: genuine | altered | incomplete
checks:  hash · signature · key · timestamp · ledger
Enter fullscreen mode Exit fullscreen mode
  • genuine: every check passes. The key check counts as passing unless it is rejected: an unpinned key still allows "genuine", and the output says only the math was checked.
  • altered: any check fails.
  • incomplete: a file is missing or unreadable.

The CLI exits with 0, 1 or 2 to match, so it drops into a script:

npx sealed-pdf-verify document.pdf --proof document.proof.json --trust issuers.json
Enter fullscreen mode Exit fullscreen mode

From code:

import { verifySealedPdf } from 'sealed-pdf-verify';

const verdict = await verifySealedPdf({
  pdf,   // Uint8Array; omit it for proof-only mode
  proof, // object, JSON text or JSON bytes
  options: { trustedKeyFingerprints: ['3796446c…'] },
});
console.log(verdict.overall, verdict.checks);
Enter fullscreen mode Exit fullscreen mode

In a browser, the verifier page is one HTML file. Drop in the PDF and the proof, or an evidence ZIP, and it runs locally. Open DevTools → Network if you want to watch it make no requests.

What "genuine" does not prove

This part matters more than the cryptography:

  • It does not prove who signed the content of the document, that they were who they said, or that they had authority. The seal is the issuer's statement about bytes and time, not about the people in the document.
  • It says nothing about the document's legal effect anywhere.
  • It cannot rule out a stolen issuer key. That is what key rotation and published fingerprints are for.

Where we'd like a second pair of eyes

  • Strict DER parsing of ECDSA signatures: are we rejecting anything that real HSMs or KMSs emit?
  • Is "no revocation checks, stated loudly" the right trade-off for an offline tool, or should an online mode fetch OCSP when it can?
  • Anything in the spec that a second, independent implementation would trip over.

Links:

Top comments (0)