Architecture#
Grantstamp has one Python package with four entry points, plus a static website:
flowchart LR
subgraph Owner machine
CLI[grantstamp CLI] --> FP1[fingerprint engine]
end
subgraph User / agent machine
MCP[MCP server grantstamp-mcp] --> FP2[fingerprint engine]
HOOK[Claude Code hook grantstamp-hook] --> FP2
WEB[website check page, in-browser JS] --> FPJ[JS strings + SHA-256]
end
subgraph Registry server
API[FastAPI /v1] --> AUTH[RFC 9421 signatures, rate limits, PoW]
API --> MATCH[matching and bands]
API --> POL[policies, licence tokens]
API --> LOG[transparency log, receipts]
API --> ALERT[alerts and webhooks]
MATCH --> DB[(SQLite or Postgres)]
POL --> DB
LOG --> DB
ALERT --> DB
end
FP1 -- signed stamp registration --> API
FP2 -- digests + use + tokens --> API
FPJ -- digests --> API
ALERT -- Slack / Discord / JSON webhook --> OWNERHOOK[owner's channel]
GHA[GitHub Action: daily witness] -- fetch signed log head --> API
Components#
| Component | Code | Runs where | Talks to |
|---|---|---|---|
| Fingerprint engine | src/grantstamp/fingerprint/ |
wherever content is (owner or user machine) | nothing (offline) |
| Registry API | server/src/grantstamp_server/app.py (AGPL-3.0) |
your server (Render, VPS, Docker) | database, webhooks, DoH for domain checks |
| Matching | grantstamp_server/matching.py |
registry | database |
| Storage | grantstamp_server/db.py, grantstamp_server/store.py |
registry | SQLite (default) or Postgres |
| CLI | src/grantstamp/cli.py |
owner and agent machines | registry |
| MCP server | src/grantstamp/mcp_server.py |
user machine, launched by the AI client over stdio | registry |
| Claude Code hook | src/grantstamp/hook.py |
user machine, launched by Claude Code | registry |
| Website | src/grantstamp/site/ |
GitHub Pages and the registry itself | registry API (CORS) |
Data model#
erDiagram
OWNER ||--o{ KEY : signs-with
OWNER ||--o{ DOMAIN : verifies
OWNER ||--o{ STAMP : registers
STAMP ||--o{ FILE : contains
FILE ||--o{ FEATURE : has
STAMP ||--o{ EVENT : matched-by
OWNER ||--o{ ALERT : receives
STAMP ||--o{ DISPUTE : challenged-by
AGENT ||--o{ KEY : signs-with
LOG_ENTRY }o--|| LOG_ENTRY : chains-to
- 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) and verification time.
- agents: name, URL, trust (registered, trusted or blocked).
- stamps: title, version, kind, policy (JSON), status (active, conflict, suspended or withdrawn), file count and bundle digest.
- files: path, size, kind, SHA-256, per-layer sampling rate and kept count, dHash.
- feats: an inverted index
(layer, h, file_id), with hashes stored as signed 64-bit integers. - events: every match, with the caller as a salted hash. alerts: match, probing, conflict, dispute and domain-shared alerts.
- log: the hash-chained transparency log. revocations: revoked licence-token IDs. disputes.
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 are fine for support, docs and dispute summaries, but never with 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, and the registry verifies the signature, timestamp window, nonce (replay protection) and body digest.
- Every stamp carries its owner's claim. The client also 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. - 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.
Request flow: POST /v1/check#
- Authenticate: anonymous, or a signed agent or owner request (unknown keys can be discovered 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-256s and look up each similarity layer's hashes in the inverted index.
- Suppress features shared by three or more different owners.
- Grade each (query file, registered file) pair, aggregate per stamp, and apply marker and manifest claims.
- 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 (match, probing), then deliver webhooks in the background.
- Return the bands, decisions, guidance text and a receipt signed by the registry.
Scaling path#
| Stage | Change |
|---|---|
| Prototype (now) | 1 instance; SQLite or Postgres; in-memory rate limits. Measured with 3,000 registered files on a 2-CPU machine: 15 ms median check, about 58 checks a second, about 76 KB of database per executable (bench/LOAD.md) |
| Thousands of stamps | Postgres; connection pool; Redis rate limits; 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 |
| Billions of files | Move the feats index to a key-value store (e.g. ScyllaDB or RocksDB), shard by hash prefix; the log becomes a Merkle tree served as static tiles with inclusion proofs |
| Function-level similarity | Add an approximate-nearest-neighbour index (e.g. pgvector or FAISS) for code embeddings |
| Speed | Port the fingerprint core to Rust (same protocol constants) and ship it as a wheel and as WebAssembly for the browser |
Source of this page on GitHub. Documentation for Grantstamp 0.2, licensed CC BY 4.0.