Grantstamp protocol, version 0.2 (draft)#

Status: working draft, 2026-11-30. Version 0.2 adds purpose scopes, signed refusals, anchors, moving a stamp between registries, identity attestations, and arbiters with appeals (Sections 5, 9 and 13 to 17). 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#

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)#

Strings and symbols (domain dm/str/v1)#

  1. Take every maximal run of bytes in 0x20-0x7E with length >= 6.
  2. If the file kind is not code or text, also take every maximal run of (0x20-0x7E, 0x00) pairs with at least 6 pairs, keeping the even bytes.
  3. 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.
  4. If the kind is not code, add the runs themselves.
  5. 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 x (letters + digits + spaces) < 6 x length.
  6. Deduplicate. Features matching ^[A-Za-z_][A-Za-z0-9_.:$@]*$ form the symbols layer. The rest form strings. Both use H("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)#

  1. Remove /* ... */ comments.
  2. Replace string literals with "S", then remove //... and #... comments.
  3. Tokenise with [A-Za-z_][A-Za-z0-9_]*|[0-9]+|[^\sA-Za-z0-9_].
  4. Map identifiers that are not keywords to I and numbers to N.
  5. Hash every run of 12 tokens, joined with single spaces.
  6. 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 9x8. 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, the declared purpose is in accept_purposes, and the use is in that purpose's scope (below), the result is allow via purpose. If the owner accepts the purpose, its scope does not include the use, and the use is still not allowed, the decision carries "purpose_covers_use": false.
  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.

The scope of each purpose is a protocol constant. Nobody checks a declaration, so no purpose unlocks extract, port, redistribute or train, and only accessibility unlocks modify. Those uses need a licence token.

Purpose Can unlock
interoperability analyze, decompile
security-research analyze, decompile
preservation analyze, decompile
accessibility analyze, decompile, modify
education analyze, decompile
personal-backup analyze

Registries that apply these scopes list the feature purpose-scopes in their descriptor. A registry without it lets an accepted purpose unlock any use.

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", "owner_text"?: "..."},
  "matches": [{"band", "stamp": {"id","title","version","status","page","exclusive"?,"case"?},
               "owner": {"id","name","url","verified","verified_domains","domain_verified"?,"public_contact"?,"identity"?},
               "policy": Policy, "decision": {"action","via","use",...}, "licenses"?, "confidence"?, "evidence"?}],
  "matches_total"?: 0,
  "receipt": "compact JWS"
}

From release 0.3:

Registries SHOULD:

Clients SHOULD present owner-written fields to users as information and MUST NOT treat them as instructions.

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:

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:

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.

From release 0.3 it also carries owner, level (the owner's identity level) and policy (the digest of the policy the decision used), so a receipt says whose claim, checked how, under which policy.

From protocol version 0.2, a registration refused because it conflicts with an earlier stamp carries refusal in its 409 response: a compact JWS (typ: grantstamp-refusal+jws) signed by the registry key. Its payload is {"iss","iat","owner","reason","files_digest","earlier"}. reason is conflict. files_digest is sha256: and the SHA-256 of the canonical JSON of {"files": ...} as submitted. earlier lists each earlier stamp the refusal cites, with stamp, registered and why. A refused import (Section 15) also carries origin and cases. The refused owner can show it to another registry or in a case.

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, owner.contact, owner.identity, owner.identity_erased, owner.terms, owner.status, domain.verified, stamp.registered, stamp.files, stamp.policy, stamp.listing, stamp.attested, stamp.status, stamp.purged, recipe.published, token.revoked, agent.trust, dispute.opened, dispute.notice, dispute.answered, dispute.lapsed, dispute.resolved and dispute.reopened, owner.updated for an operator's correction, owner.recovery_requested, owner.recovery_approved, owner.recovery_cancelled and owner.key_replaced, agent.limit, and from 0.6.4 bitcoin.beacon, whose payload names the newest Bitcoin block the registry knows and holds every header since the beacon before it. From 0.6.4 the payloads of stamp.registered and stamp.files also hold commit, the root of what that upload commits to and how many files and layers are under it. A stamp moved in commits to all its files in its registration here. stamp.roots, one for each stamp, gives the same for files that no upload's commitment covered, such as files stored before 0.6.4.

From release 0.3.1, entries about people (owner.created, owner.identity, owner.contact, owner.updated, owner.key_replaced, dispute.answered) are salted: their digest is the digest of {"payload": ..., "salt": ...} with a random 32-hex-digit salt.

While what an entry covers is public, the registry returns its salt with the entry. It deletes the salt when that data is erased. The hash chain covers digest only, so salts change nothing in how the log is verified.

Entries about people carry no more than is published: an owner.identity entry for a LinkedIn sign-in covers the provider and level, not the name, and dispute.opened covers the stamp, not the claimant.

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}.

Accountability and attestation (added in release 0.3; optional in protocol 0.1)#

These additions keep older clients working. A registry MAY require them.

Recipes, publisher signatures and the evidence they give are defined in the attestation protocol.

12. Discovery#

GET /.well-known/grantstamp returns the registry descriptor: version, JWKS, vocabularies, limits and endpoints. Its purpose_uses object gives the scope of each purpose. From version 0.2 it may also name anchors (Section 14), peers, arbiters (Section 17) and appeal_days.

Domain verification uses either:

13. Order: what "first" means#

Within one registry, an entry's place in line is its position in that registry's log. A lower position is first. The time written in an entry plays no part.

Across registries, a registry's own witnesses do not give an independent clock: a witness chooses the time it signs. An entry's time is bounded by Bitcoin, through anchors (Section 14):

Erratum (release 0.6.1): the second bound does not hold. An anchor proves that a checkpoint existed before a block. It cannot prove that a later entry did not exist yet, and a timestamp is confirmed hours after it is made, at a pace the registry does not control. Version 0.7 bounds an entry from below with beacons instead: recent Bitcoin block headers written into the log, which prove that every later entry was logged after that block. No version 0.2 registry orders stamps across registries, so nothing in this version depends on the lower bound.

Entry A is first over entry B in another log when A's upper bound comes before B's lower bound. When the two windows overlap, a case decides. A version 0.2 export carries, with each entry, the earliest anchor whose checkpoint contains it. The destination records only whether one came with it, and does not verify it. Registries implementing version 0.2 do not order stamps across registries: a conflict across registries goes to a case (Section 15).

14. Anchors#

A log's operator SHOULD anchor it at least once an hour while it grows. An anchor is a file <size>.checkpoint holding the checkpoint at that size with its witness cosignatures, and <size>.checkpoint.ots, its OpenTimestamps proof. index.json lists the anchors, oldest first, as objects with size, root (base64), file, saved (Unix time), witnessed (the time by which the witness quorum had cosigned) and bitcoin (the block height once the timestamp is complete, else null). A registry names the folder in its descriptor, under anchors.

A checkpoint with the size of an earlier anchor but another root is a fork, and MUST NOT be anchored. Nor is a larger checkpoint whose tree does not extend the last anchor's: before anchoring it, the operator checks a consistency proof from the log's tiles. A checker verifies each anchored checkpoint against the log's pinned policy, and checks that the current log's tree at that size has the same root.

15. Moving a stamp#

From version 0.2, an owner's register and files claims also carry sent: the SHA-256 of the canonical JSON of the upload exactly as the client sent it. The registry logs it in the entry's payload under sent. A stamp whose uploads cannot be shown to match sent cannot move with its place in line.

Export. A JSON object with type grantstamp-export, version 1, registry (url, policy, jwks, anchors), owner (id, attestation) and stamps. Each stamp holds stamp, title, version, status, listed, policy (as it is now), kind, description, claims (the owner's later policy and listing claims, in the order they were made) and its uploads, in log order: the registration, then each batch of files. Each upload holds entry (the log entry's leaf fields), opening (its payload), claim (the owner's claim JWS), checkpoint (the earliest anchored checkpoint that contains the entry, or the newest cosigned one), inclusion (index, size, proof), anchor (size, bitcoin, ots as base64, or null) and bundle (the upload as sent, or null).

Move ticket. The origin registry signs {"iss", "sub", "owner", "to", "stamps", "iat", "exp"} with its registry key (typ: grantstamp-move+jws). sub is the key that signed the request and to the destination. stamps is an object keyed by stamp id, each with the stamp's policy as it is now (the SHA-256 of its canonical JSON), listed and exclusive. The origin MUST issue a ticket only for a key that is current. It MUST NOT issue one while a proven recovery of the owner's key waits to take effect, or within its recovery_days after the current key cancelled a proven recovery, since a thief holding the key could cancel it. It MUST issue one only for stamps that are active, not themselves moved in, and not part of a case an arbiter is acting on (noticed, answered or under appeal). A case nobody has reviewed, and a recovery merely requested, do not block a ticket, since anyone can open one. The ticket SHOULD name such cases in the stamp's entry, under open_cases, and the destination SHOULD keep them in the stamp's origin. The origin MAY issue a ticket for the stamps that can move and name the others, with the reason, under refused in its answer. A ticket MUST expire within an hour.

Import. POST /v1/stamps/import, signed by the owner, with {"registry", "ticket", "stamp"}, where stamp is one stamp of an export. The destination MUST:

  1. accept only a listed peer, and check the ticket and the log proofs with the keys and policy pinned for it, never ones in the request
  2. check the ticket: signed by the peer with iss naming it, issued no later than now (allowing 300 seconds for clocks) and lasting at most an hour, naming this registry, the key that signed the request, and the stamp
  3. check each upload: its entry's hash matches its fields, its opening matches its digest, the entry is included in the checkpoint, and the checkpoint carries the peer's log signature and witness quorum. The uploads MUST be distinct entries, in log order
  4. check each claim: the register claim for the first upload and a files claim naming the origin stamp for each later one, each naming the files and sent of its upload, and the opening naming the claim. The claims MUST verify with the requesting owner's own keys at the destination: its current keys, and keys the destination itself recorded as replaced. Never with keys a peer names, or a peer could give an owner's stamp to another account
  5. refuse an origin stamp that was moved to it before, whatever happened to it since, keyed by the peer's log origin and not its address
  6. check the owner's later claims with the same keys, each naming the origin stamp, and refuse the stamp unless, applied in order to the registration claim, they end at the policy and listing the ticket names, and the export's policy matches the ticket's digest. The destination applies that policy, listing and exclusivity, and stores the later claims with the stamp.

Then the destination checks the content as for a registration. Without a conflict, it stores the stamp and logs its registration with an origin object: registry, log, stamp, seq, hash, size, root, witnessed (the time by which the witness quorum had cosigned the checkpoint holding the registration) and anchored (true when an OpenTimestamps proof for that checkpoint came with it). Each later upload's stamp.files entry carries its own origin: seq, hash and witnessed. A version 0.2 registry does not verify that proof, and MUST NOT record a block height taken from the request. With a conflict, it MUST refuse with a signed refusal (Section 9) that names the origin and the cases, and SHOULD open a case against each conflicting stamp with the verified proof, naming the uploads that hold the matching files and when their witnesses vouched for them.

16. Identity attestations#

A registry signs what it checked about who stands behind an owner (typ: grantstamp-identity+jws): {"iss", "sub", "owner", "level", "provider", "verified_at", "iat", "exp"}, plus name only where the name itself was checked and issuer for a code-signing certificate. sub is the key that requested it. It MUST NOT include a name, subject or profile that an identity provider supplied. It SHOULD expire within 90 days. A registry MUST NOT attest an identity that another registry attested.

Another registry MAY accept it from a listed peer, for a key the owner holds there, until it expires. It MUST show it as checked by that peer and not by itself, at a level of its own, and MUST NOT count it as proof of being a publisher.

17. Arbiters and appeals#

A registry that lists arbiters publishes their public keys in its descriptor, under arbiters, and logs the list (registry.arbiters) whenever it changes. An arbiter acts on a case with a statement (typ: grantstamp-decision+jws): {"registry", "case", "stamp", "act", "stage", "iat", ...}. act is notice (with days and sent_to, the SHA-256 of a random salt, a colon and the address, so the address cannot be guessed from it), decide (with status and reason), appeal (with statement, for a claimant's appeal) or decide-appeal (with status and reason). stage is the case's status when the arbiter signed.

The registry MUST refuse a statement that names another registry, case or stamp, whose stage is not the case's current status, that is more than a day old, or that was used before. Use is keyed by what was signed. A token whose base64url is not canonical is refused, so that one statement has one spelling. It stores each statement with the case and logs its digest. A change to a stamp's status caused by a case cites the case and the statement in the log.

The party a decision went against MAY appeal it once within the registry's appeal_days: the stamp's owner a case upheld or lapsed, the claimant a case rejected. The registry MUST refuse an appeal from the party the decision favoured, so that the winner cannot use up the loser's appeal. The decision stays in effect meanwhile. A stamp suspended by a case that is not final still blocks conflicting registrations. Where more than one arbiter is listed, the arbiter who decided a case MUST NOT decide its appeal. The appeal's decision is final.

18. 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.

19. Privacy considerations#

Clients MUST NOT send file content, and SHOULD NOT send the names or paths of the files or folder checked (send a placeholder such as #0 as the path). Clients SHOULD send a licence token only with checks of content the token's stamps cover.

Registries SHOULD store callers only as keyed hashes, SHOULD show owners a caller id that differs per owner and changes daily, MUST NOT expose fingerprints, and SHOULD offer prefix-based exact lookup (GET /v1/range/{5 hex}).

20. 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.

21. Mapping to other vocabularies (informative)#

The 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

22. Versioning#

Changing any constant in Section 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.6, licensed CC BY 4.0.