Architecture#
Grantstamp is built so that nobody has to trust a server.
Owners sign their own stamps. The registry puts them in order in a public log and signs it. Witnesses cosign that log. Mirrors copy it. An agent can read from any of them and check every byte.
Who does what#
| Role | Run by | Holds | Trusted for |
|---|---|---|---|
| Owner | Each owner | Their own signing key | Their own claims |
| Registry | The project | All records, private data, the log key | Putting writes in order. A lie is caught by the witnesses. |
| Witnesses | The project today (two GitHub jobs), then others | The last log head they cosigned | Not helping the registry show two histories |
| Mirrors | Anyone | Copies of the log, the public records and the check map | Nothing, except being reachable |
| Agent, or any reader | Everyone | The log's public key and the list of witnesses | Itself |
Three things follow from this.
- The registry cannot forge a stamp. It does not hold the owner's key.
- The registry cannot rewrite history. Witnesses cosign a log only when it extends the one they saw before.
- A mirror cannot change, hide or add anything. Every file it serves must hash up to the signed log. A mirror has one power left: silence.
The full design, with what each party could try and what catches it, is in Mirrors and witnesses.
What runs today#
The design allows many witnesses and mirrors. Today the project runs two of each, and all of them are its own. That is worth saying plainly.
| Part | In the software | On grantstamp.io today |
|---|---|---|
| Registry | One per log, by design | One, at registry.grantstamp.io |
| Witness that cosigns | Any number, with a quorum | Two, both the project's own. github runs in the main repository and is required. second runs in grantstamp/grantstamp-witness and is not. Each cosigns every 5 minutes. |
| Daily witness with Bitcoin timestamps | Yes | Yes, in the main repository |
| Mirror | Any static web host | Two, both the project's own: grantstamp.io/registry/ and grantstamp.github.io/grantstamp-mirror/, each refreshed every 10 minutes |
| Timer | Any | A Cloudflare Worker starts the jobs. GitHub's own scheduler is a backup. |
| Checks answered by mirrors | Experimental, off by default | The registry publishes the check map. Clients use it only with --via-hosts. |
So today the registry's records can be checked by anyone, but every witness and mirror answers to one operator. Two of the project's own witnesses prove no more than one: whoever controls the project's GitHub organisation could make both sign a rewritten history. A witness run by someone else, and required by the quorum, closes that gap. See Run a mirror or a witness.
The software#
One Python package holds the client. A second holds the registry server. The website is static.
| Component | Code | Runs where | Talks to |
|---|---|---|---|
| Fingerprint engine | src/grantstamp/fingerprint/ |
wherever the content is | nothing (offline) |
| CLI | src/grantstamp/cli.py |
owner and agent machines | registry, mirrors |
| MCP server | src/grantstamp/mcp_server.py |
agent's machine, started by the AI client | registry |
| Claude Code hook | src/grantstamp/hook.py |
agent's machine, started by Claude Code | registry |
| Log and proofs | src/grantstamp/tlog.py, note.py |
every machine that verifies | nothing (offline) |
| Mirror | src/grantstamp/mirror.py |
any machine, then any static web host | registry, or another mirror |
| Witness | src/grantstamp/witness.py |
a scheduled job or a small server | registry |
| Registry API | server/src/grantstamp_server/app.py (AGPL-3.0) |
your server (Render, VPS, Docker) | database, webhooks, DNS over HTTPS |
| Matching | grantstamp_server/matching.py |
registry | database |
| Log tree | grantstamp_server/logtree.py |
registry | database, witnesses |
| Check map | grantstamp_server/nodemap.py, nodecheck.py |
registry builds it, clients read it | mirrors |
| Storage | grantstamp_server/db.py, store.py |
registry | SQLite (default) or PostgreSQL |
| Website | src/grantstamp/site/ |
GitHub Pages, and the registry itself | registry API |
A check at the registry#
This is the usual path. POST /v1/check does these steps in order.
- Authenticate. The caller is anonymous, or signs as an agent or an owner. Unknown keys can be found through
Signature-Agent. - Rate-limit by caller class. Anonymous callers can add quota with a proof-of-work header.
- Parse the bundle and drop background features: common runtime strings and chunks.
- Look up exact SHA-256 hashes, and each similarity layer's hashes in the inverted index.
- Suppress features shared by three or more different owners.
- Grade each pair of query file and registered file. Aggregate per stamp. Apply marker and manifest claims.
- Apply the policy. For medium and above, evaluate the owner's policy for the use, purpose and licence tokens. Medium turns deny into ask.
- Record events and raise alerts for matches and probing. Webhooks go out in the background.
- Answer with the bands, decisions, guidance text and a receipt signed by the registry.
A check through a mirror#
This path is experimental and off by default. It lets a mirror answer a check without being trusted, and without learning anything about the file.
- The mirror holds a check map: keyed tokens of every registered feature, sorted in a Merkle tree that the log commits to.
- Only the registry's token service can turn a file's features into tokens. It counts every one against a rate limit.
- A token that is in the map is a match. A token that falls inside a piece of the map without being in it is proven absent. So a mirror cannot hide a match.
- The agent grades the evidence with the registry's own matching code.
A mirror that fails any check, lacks a file or does not answer is skipped. The registry is the last resort.
One limit remains. The token service runs at the registry, so a check through mirrors still needs the registry awake. Auditing a mirror does not: grantstamp audit --from <mirror> works with the registry switched off.
Data model#
- owners: name, contact, URL, status, webhook.
- keys: Ed25519 JWKs by RFC 7638 thumbprint (
kid), each belonging to an owner or an agent. - domains: challenge, method (dns or https), verification time and the date the domain was registered.
- identities: who stands behind an owner, the level at which it was checked, and when.
- agents: name, URL, trust (registered, trusted or blocked).
- stamps: title, version, kind, policy (JSON), status, whether the stamp is exclusive or shared, file count and bundle digest. Status is active, suspended or withdrawn. Stamps from before 0.3 may be in conflict.
- files: path, size, kind, SHA-256, per-layer sampling rate and kept count, dHash, and the verified publisher of a signed executable.
- recipes: fingerprint procedures that owners published.
- feats: an inverted index
(layer, h, file_id), with hashes stored as signed 64-bit integers. - events: every match, with the caller as an id that differs per owner and changes daily. Deleted after 12 months.
- alerts: match, probing, co-owner, policy-proposed, outranked, dispute, notice and lapsed alerts. Deleted after 12 months.
- log: the transparency log. Each entry holds a digest, never the data itself. The same entries form a hash chain (0.3) and the leaves of a Merkle tree (0.4).
- log_cosigs: the witnesses' cosignatures on log heads.
- revocations: revoked licence-token ids.
- disputes: cases, notices and answers.
Security boundaries#
- Content never crosses the network. Only digests do.
- No LLM in the registry path. Matching, policy decisions, signing and storage are deterministic. LLMs may help with support and documentation. They never read or decide cases, and never get access to the fingerprint store or keys.
- Fingerprints are write-only from outside. No endpoint returns them. Exact hashes can be range-queried by prefix, which reveals only that some registered file has that hash.
- Every write is signed. Owners sign with their key. The registry verifies the signature, the timestamp window, the nonce (replay protection) and the body digest.
- Every stamp carries its owner's claim. The client signs a claim over the title, version, policy and file hashes. The registry stores and publishes it. So the registry cannot create or change a stamp on its own, and anyone can check that with
grantstamp audit. - Mirrors hold no names, contacts or fingerprints. They hold the log, the public records of listed stamps, and keyed tokens.
- Outbound requests are SSRF-guarded. Webhooks, domain checks and agent key directories must be https and resolve to public addresses. Dev mode relaxes this.
- Registry key. It signs receipts, log heads and webhooks. It is generated on first start and stored in the database, or provided as
GRANTSTAMP_REGISTRY_KEY(PEM) so it survives database resets.
Scaling path#
| Stage | Change |
|---|---|
| Prototype (now) | 1 registry instance, SQLite or PostgreSQL, in-memory rate limits. The log is a Merkle tree served as static tiles, so reads can already move to mirrors. Measured with 3,000 registered files on a 2-CPU machine: 12 ms median check, about 65 checks a second, about 76 KB of database per executable (bench/LOAD.md). |
| More readers | More mirrors on static hosts and CDNs. The token service on an always-on host, apart from the registry. |
| Thousands of stamps | PostgreSQL, a connection pool, Redis rate limits, a CDN in front of the API |
| Millions of files | Fixed-size sketches per file in place of one index row per feature. Tables partitioned by hash. Batch upload via object storage. Check maps built incrementally. |
| Billions of files | Move the feats index to a key-value store such as ScyllaDB or RocksDB, sharded by hash prefix |
| Function-level similarity | Add an approximate-nearest-neighbour index such as pgvector or FAISS for code embeddings |
| Speed | Port the fingerprint core to Rust with the same protocol constants. Ship it as a wheel, and as WebAssembly for the browser. |
Source of this page on GitHub. Documentation for Grantstamp 0.4, licensed CC BY 4.0.