# signdocumentsonchain verifier

Checks a signdocumentsonchain certificate **without trusting signdocumentsonchain**. It recomputes everything from
the certificate JSON and only reads public data: a Base transaction. MIT licensed.
The production server uses this same `core.mjs` to build and check proofs.

```sh
# Download: https://signdocumentsonchain.com/verifier/{package.json,core.mjs,key.mjs,verify.mjs}
npm install
node verify.mjs certificate.json                # certificate JSON from the document page
node verify.mjs certificate.json contract.pdf   # also check that this is the file that was signed
node verify.mjs certificate.json --rpc https://your-base-node   # zero trust
node verify.mjs certificate.json --offline      # hashes, proof and signature only
```

Exit code 0 means verified. The verifier prints one line per check: the commitment (SHA-512 of the canonical
manifest), the file (if you pass one), the Merkle proof up to the batch root, the signed statement naming exactly that
root and chain, the ML-DSA-87 signature against our published key, and the Base transaction carrying the root.

## What a certificate proves

1. **The manifest is the certificate.** It names the document (SHA-512 of the file and of each bundled part), every
   signer (name, email, time, IP, signature image hash, identity check), the completion time and a random salt.
   `commitment = SHA-512(canonical manifest)`.
   Canonical = JSON with object keys sorted recursively, no whitespace, keys with undefined values dropped.
2. **The commitment was published on Base** inside a batch. The batch transaction is a 0-value self-send whose
   calldata is `"SDOC"` + version 4 + the 64-byte Merkle root: `0x53444f4304 || root`.

   Merkle tree: `leaf = SHA-512(0x00 || commitment)`, `node = SHA-512(0x01 || min(a, b) || max(a, b))`, compared as
   lowercase hex. A proof is the list of sibling hashes, bottom-up.
3. **We vouched for the batch with a post-quantum signature.** The batch statement
   `{"chainId","sha512Root","signedAt","type":"signdocumentsonchain/anchor-batch","v":2}` (canonical JSON, UTF-8) is
   signed with **ML-DSA-87** (FIPS 204, pure mode, empty context). The key lives in AWS KMS; its public half is in `key.mjs`, at
   <https://signdocumentsonchain.com/api/v1/pq-key>, and in our source. Fingerprint (SHA-512 of the raw 2592-byte key):
   `1b00d88f3c74937d150c6e4b1d28ef1b00a1ae02608762f267229598e510dc86c4338dc2cdf068a652a6c01514d8877edbf677c407934d37292106a719b4b155`.
4. **We signed the certificate itself the moment it was issued.** `certificate.json` has a `signature` block (the
   signed PDF carries the same as the attachment `signdocumentsonchain-signature.json`): the statement
   `{"commitment","issuedAt","kind":"document"|"screening","type":"signdocumentsonchain/certificate","v":1}` signed
   with the same ML-DSA-87 key. It makes the certificate authentic on its own: before its batch is anchored, and
   without any blockchain. Check `certificate-ml-dsa-87`.

### Verified identities

Each verified-identity token (contract `SignOnChainIdentity` v2 on Base) is minted with an ML-DSA-87 attestation,
emitted as `Attested(tokenId, statement, signature)` and served in the token metadata (`attestation`): the statement
`{"chainId","contract","documentCountry","holder","issuedAt","sanctions","type":"signdocumentsonchain/identity","v":1,"verifiedAt"}`
names the holder address, the contract and the chain, with no personal data. Check it with
`verifyIdentityAttestation(statement, signature, publicKey, { holder, contract, chainId })`. A token without a valid
attestation is not one of ours, even if it was minted by our (ECDSA) minter key.

## Why the signature, not the chain (quantum computers)

Hashes (SHA-512) are not meaningfully weakened by quantum computers. Elliptic-curve signatures (ECDSA, BLS) are.
Base transactions and Ethereum's finality rest on those signatures, so a large quantum computer could someday forge
transactions from our wallet. It could not forge the ML-DSA-87 signature. That signature, not the chain, is what makes
a proof authentic: it proves *who* vouched for the batch, the SHA-512 hashes prove *what*, and Base is a public
timestamp witness for *when*, as strong as Base itself.

The proof is built exclusively on the NSA CNSA 2.0 algorithms (ML-DSA-87 for signatures, SHA-512 for hashing; AES-256
for files at rest on our side), following the NSA's post-quantum guidance.

## Files

- `core.mjs`: everything (canonical JSON, SHA-512 Merkle, calldata, ML-DSA-87, Base RPC). Works in browsers too.
- `key.mjs`: our published ML-DSA-87 key, wallets and default RPC endpoints.
- `verify.mjs`: the command line.
