Grantstamp protocol, version 0.1 (draft)#
Status: working draft, 2026-11-26. This document is licensed under CC BY 4.0. The reference implementation is in this repository (Apache-2.0).
The key words MUST, SHOULD and MAY are to be read as described in RFC 2119 and RFC 8174.
1. Purpose#
Grantstamp lets content owners publish verifiable ownership claims and per-use policies for software, game builds and other files, without publishing the content. It lets automated agents check a file before operating on it. A check answers three questions: who claims this content, how strong the evidence is, and what the owner allows for the intended use.
2. Terms#
- Owner: a principal identified by one or more Ed25519 keys, optionally with verified domains.
- Stamp: an owner's claim over a set of files (a title or release), with a policy.
- Bundle: the digests computed locally for one or more files.
- Agent: a principal that checks content, identified by an Ed25519 key, or anonymous.
- Band: the strength of evidence. One of
exact,high,medium,low,none. - Use: one of
analyze,decompile,modify,port,extract,redistribute,train. - Purpose: one of
interoperability,security-research,preservation,accessibility,education,personal-backup.
3. Bundle format#
{
"format": "grantstamp.bundle/1",
"generator": "grantstamp-py/0.1.0",
"root": "release",
"kind": "file | directory",
"files": [ FileEntry, ... ],
"stats": {"files": 0, "bytes": 0, "skipped": 0, "truncated": 0, "excluded": 0}
}
A FileEntry has these fields:
| Field | Type | Required | Meaning |
|---|---|---|---|
path |
string | yes | path relative to the root; archive members are written archive.zip!/member |
size |
integer | yes | bytes |
kind |
string | yes | pe, elf, macho, xex, dex, wasm, java-class, zip, tar, image, code, text, binary |
sha256 |
string | yes | 64 lowercase hex characters |
chunks, strings, symbols, winnow |
Layer | no | similarity layers |
dhash |
string | no | 16 hex characters |
markers |
[string] | no | stamp IDs found in embedded markers |
manifest_hint |
object | no | {"stamp", "owner"} from a signed sidecar manifest |
truncated |
boolean | no | similarity layers cover only a prefix of the file |
A Layer is {"s": rate, "n": distinct_features, "h": [hex16, ...]}, where h is sorted ascending and contains only hashes whose top s bits are zero.
4. Feature definitions (normative)#
H(domain, data) = the first 8 bytes of SHA-256(domain || 0x00 || data), read as a big-endian uint64 and written as 16 lowercase hex characters.
Chunks (domain dm/chunk/v1)#
T[i]= the first 4 bytes, big-endian, ofSHA-256("dm/buz/v1" || byte(i)), for i in 0..255.P = 0x9E3779B1.- For every position
i ≥ 31:h_i = Σ_{j=0}^{31} T[b_{i−j}] · P^j mod 2^32. - Position
iis a candidate ifh_i >> 20 == 0; the candidate end offset isi + 1. - Walk the candidates in order, starting from
last = 0: - while
p − last > 65536, emit a forced end atlast + 65536; - if
p − last ≥ 2048, emitp. - After the last candidate, force ends every 65536 bytes, then emit the file size.
- Each chunk's feature is
H("dm/chunk/v1", chunk bytes).
Strings and symbols (domain dm/str/v1)#
- Take every maximal run of bytes in 0x20–0x7E with length ≥ 6.
- If the file kind is not
codeortext, also take every maximal run of (0x20–0x7E, 0x00) pairs with at least 6 pairs, keeping the even bytes. - For every ASCII run containing
": match"((?:[^"\\]|\\.){4,})"(non-overlapping, left to right). Split each match's content on\\(?:x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|[0-7]{1,3}|.)and add the pieces. - If the kind is not
code, add the runs themselves. - Normalise each candidate: - replace every whitespace sequence with one space and trim; - reject it if shorter than 6; - truncate to 256 characters; - reject it if it has fewer than 4 ASCII letters; - reject it if 10 × (letters + digits + spaces) < 6 × length.
- Deduplicate. Features matching
^[A-Za-z_][A-Za-z0-9_.:$@]*$form thesymbolslayer; the rest formstrings. Both useH("dm/str/v1", ascii bytes).
The kind code is assigned to text files with these extensions: .c .h .cc .cpp .cxx .hpp .hh .hxx .inl .m .mm .cs .java .kt .kts .scala .go .rs .swift .js .jsx .ts .tsx .mjs .cjs .py .rb .php .lua .gd .hlsl .glsl .shader .cg .vert .frag .comp .asm .s .dart .zig .nim .v .sv .vhd .sql .sh .ps1 .pl .r.
A file is text if its first 64 KiB contain no NUL byte and at least 95% of its first 8 KiB are 0x09, 0x0A, 0x0D, 0x20–0x7E or ≥ 0x80.
Winnow (domain dm/win/v1)#
- Remove
/* … */comments. - Replace string literals with
"S", then remove//…and#…comments. - Tokenise with
[A-Za-z_][A-Za-z0-9_]*|[0-9]+|[^\sA-Za-z0-9_]. - Map identifiers that are not keywords to
Iand numbers toN. - Hash every run of 12 tokens, joined with single spaces.
- Keep the minimum hash of every window of 8 consecutive hashes.
The keyword list is in the reference implementation.
dHash#
Convert the image to greyscale with the Lanczos filter at 9×8. Bit (y·8 + x), read most-significant-first, is 1 if p[y][x] < p[y][x+1].
Markers#
The ASCII string GRANTSTAMP:1:<stamp id> or its UTF-16LE form. A stamp ID is stamp_ followed by 16 characters from 0123456789abcdefghjkmnpqrstvwxyz.
Background removal and sampling#
Implementations SHOULD remove the published background features (background_*_v1.u64) before sampling. A layer exceeding the cap (262,144 when registering, 65,536 when checking) MUST be sampled by increasing s until it fits.
5. Policy#
{
"default": "allow | ask | deny",
"uses": {"analyze": "allow", "decompile": "deny", "modify": "deny", "port": "deny",
"extract": "deny", "redistribute": "deny", "train": "deny"},
"accept_purposes": ["interoperability", "security-research"],
"message": "free text", "contact": "mailto: or URL", "license_url": "URL", "request_url": "URL",
"aipref": "optional IETF aipref expression", "rsl": "optional RSL document URL"
}
To evaluate a use:
1. A valid licence token covering the use (or *) gives allow via license.
2. Otherwise the use's action applies. If that action is not allow and the declared purpose is in accept_purposes, the result is allow via purpose.
3. Registries MUST NOT return a hard deny for a medium match. They MUST return ask via evidence, keeping the owner's action as owner_action.
6. Check#
POST /v1/check with body {"bundle": Bundle, "use": Use, "purpose"?: Purpose, "license_tokens"?: [JWS]}. The response is:
{
"registry": "https://…", "access": "anonymous | registered | trusted | owner",
"verdict": {"band": Band, "decision": "allow | ask | deny | none | no-claim", "stamp": "stamp_…" | null,
"guidance": "plain-language instruction for the agent"},
"matches": [{"band", "stamp": {"id","title","version","status","page"}, "owner": {"id","name","url","verified","verified_domains"},
"policy": Policy, "decision": {"action","via","use",…}, "licenses"?, "confidence"?, "evidence"?}],
"receipt": "compact JWS"
}
Registries SHOULD:
- hide low matches, scores and evidence from anonymous callers;
- rank matches by band, then verified owners, then score, then registration time;
- record a match event and alert owners.
Bands are defined by the registry's published thresholds. The reference thresholds are in docs/04-implementation.md.
7. Authentication#
Signed requests use RFC 9421 HTTP Message Signatures with Ed25519:
- components:
"@method" "@authority" "@path", plus"@query"if a query is present and"content-digest"if a body is present (RFC 9530,sha-256); - parameters:
created,expires(at most 3600 seconds later),keyid= RFC 7638 JWK thumbprint,alg="ed25519",nonce,tag="grantstamp"; - registries MUST reject signatures outside a 300-second skew window and replayed nonces;
Signature-Agent: "<https origin>"MAY be sent, and registries MAY fetch<origin>/.well-known/http-message-signatures-directory(a JWKS) to discover agent keys, as in the IETF Web Bot Auth drafts;- new owners and agents prove possession by signing their registration request with the key they register.
8. Licence tokens#
Compact JWS with header {"alg":"EdDSA","typ":"grantstamp-license+jws","kid":<owner key thumbprint>} and payload {"v":1,"iss":owner_id,"sub":licensee,"stamps":[stamp ids or "*"],"uses":[uses or "*"],"iat","nbf","exp","jti","aud":"grantstamp","note"?}.
Verifiers MUST check:
- the signature against a key registered to iss;
- the time window;
- aud;
- that the stamp is in scope;
- that jti has not been revoked (POST /v1/tokens/revoke).
9. Receipts#
Every check response includes a compact JWS (typ: grantstamp-receipt+jws) signed by the registry key, published at /.well-known/grantstamp and /.well-known/http-message-signatures-directory. The payload is {"iss","iat","qd","use","purpose","band","stamp","decision","via","sub"}, where qd is the SHA-256 of the canonical JSON of the bundle.
10. Manifests#
grantstamp.json at a distribution root contains {"format":"grantstamp.manifest/1","stamp","owner","owner_name","registry","title","version"?,"issued","notice","jws"}. Here jws (typ: grantstamp-manifest+jws) signs all the other fields, and verifiers MUST check that the visible fields equal the signed payload.
11. Transparency log#
Each entry is {"seq","ts","kind","subject","digest","prev","hash"}, where hash = SHA-256(canonical({seq,ts,kind,subject,digest,prev})) and the first prev is 64 zeros. GET /v1/log/head returns {"registry","seq","hash","at","jws"} (typ: grantstamp-loghead+jws). Kinds include owner.created, domain.verified, stamp.registered, stamp.files, stamp.policy, stamp.status, token.revoked, agent.trust, dispute.opened, dispute.resolved and owner.status.
Owner claims (added in release 0.2; optional in protocol 0.1)#
An owner MAY attach a claim to each management request, and clients SHOULD. A claim is a compact JWS (EdDSA, typ: grantstamp-claim+jws, kid = the owner key's thumbprint) whose payload is {"act", …, "iat"}:
act |
Sent with | Other payload fields |
|---|---|---|
register |
POST /v1/stamps |
title, version, policy, files, n, listed |
files |
POST /v1/stamps/{id}/files |
stamp, files, n |
policy |
PUT /v1/stamps/{id}/policy |
stamp, policy |
listing |
PUT /v1/stamps/{id}/listing |
stamp, listed |
withdraw |
POST /v1/stamps/{id}/withdraw |
stamp |
attest |
POST /v1/stamps/{id}/attest |
stamp, title, version, policy, n |
policy is the digest (sha256: + hex of SHA-256 over canonical JSON) of the normalized policy. files is sha256: + hex of SHA-256 over the upload's file SHA-256 values, lower-case, sorted and joined with \n. n is the number of files. A registry MUST reject a claim whose signature fails, whose key is not the owner's, whose fields differ from the request, or whose iat is more than 600 seconds from its clock. A registry MUST store accepted claims unchanged and return them from GET /v1/stamps/{id}/proof, together with the owner's public keys, the owner's domain verification records and the log entries for the stamp.
The response to POST /v1/stamps includes receipt: a JWS signed by the registry (typ: grantstamp-registration+jws) with {"iss","iat","stamp","owner","title","bundle","claim","log":{"seq","hash"}}.
Listing and search (added in release 0.2)#
A stamp is listed unless it is registered with "listed": false. GET /v1/stamps?q=&owner=&before=&limit= returns listed, active stamps, newest first, matching every word of q against the title, version, kind or owner name; a full stamp id as q returns that stamp whether or not it is listed. Unlisted stamps MUST still match checks and MUST still be served at GET /v1/stamps/{id}.
12. Discovery#
GET /.well-known/grantstamp returns the registry descriptor: version, JWKS, vocabularies, limits and endpoints.
Domain verification uses either:
- a DNS TXT record at _grantstamp.<domain> equal to grantstamp-verify=<owner id>:<key id>; or
- https://<domain>/.well-known/grantstamp-verify.txt containing that token.
13. Proof of work#
GET /v1/pow returns {"challenge","bits","expires"}. A client sends Grantstamp-PoW: <challenge>:<n> where SHA-256(challenge ":" n) has at least bits leading zero bits. Each challenge is accepted once.
14. Privacy considerations#
Clients MUST NOT send file content. Registries SHOULD store callers only as keyed hashes, MUST NOT expose fingerprints, and SHOULD offer prefix-based exact lookup (GET /v1/range/{5 hex}).
15. Security considerations#
See docs/threat-model.md. Answers are evidence of similarity plus the owner's claim. They are not determinations of ownership or legality.
16. Mapping to other vocabularies (informative; token names follow drafts current at the time of writing, so check the latest versions)#
| Grantstamp use | IETF aipref (draft) | RSL |
|---|---|---|
| train | train-ai |
ai-train |
| analyze | (AI input; under discussion) | ai-input |
| redistribute | — | licence permits/prohibits |
17. Versioning#
Changing any constant in §4 requires new domain strings (…/v2) and a new bundle format version. Registries SHOULD accept the old and new versions side by side during a migration.
Source of this page on GitHub. Documentation for Grantstamp 0.2, licensed CC BY 4.0.