Metadata-Version: 2.5
Name: grantstamp
Version: 0.1.2
Summary: Open ownership registry and check protocol for AI agents: owners publish fingerprints and policies, agents check before they touch a file.
Project-URL: Homepage, https://grantstamp.io
Project-URL: Documentation, https://github.com/grantstamp/grantstamp/tree/main/docs
Project-URL: Source, https://github.com/grantstamp/grantstamp
Project-URL: Issues, https://github.com/grantstamp/grantstamp/issues
Author: Grantstamp contributors
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Keywords: ai-agents,copyright,fingerprinting,licensing,mcp,ownership,provenance,registry
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.10
Requires-Dist: cryptography>=42
Requires-Dist: httpx>=0.27
Requires-Dist: mcp>=1.2
Requires-Dist: numpy>=1.24
Provides-Extra: all
Requires-Dist: pillow>=10; extra == 'all'
Provides-Extra: dev
Requires-Dist: pillow>=10; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Provides-Extra: images
Requires-Dist: pillow>=10; extra == 'images'
Provides-Extra: mcp
Description-Content-Type: text/markdown

# Grantstamp

**Agents ask first.** Grantstamp™ is an open ownership registry and check protocol for AI agents. Owners publish fingerprints and a policy for their software and game builds, but never the files themselves. Before an agent decompiles, ports, modifies or redistributes a file, it checks the registry. It gets back who owns the file, what the owner allows for that exact use, a confidence band and a signed receipt.

<!-- mcp-name: io.github.grantstamp/grantstamp -->

> Status: prototype 0.1. This version works end to end and is tested and benchmarked, but it is not production-hardened yet, and interfaces may change before 1.0.

## Why

AI coding agents now compress weeks of reverse-engineering and porting work into hours. Owners have no machine-readable way to tell those agents "this is mine, and this is what I allow." Today's safeguards are blunt rules: they cannot tell a pirate from the owner's own contractor. Grantstamp gives agents precise, owner-supplied data. It flags copies and unblocks licensees, and it alerts the owner within seconds. Read [docs/01-problem.md](docs/01-problem.md).

## How it works

```mermaid
sequenceDiagram
    participant O as Owner (CLI, local)
    participant R as Grantstamp registry
    participant A as AI agent (MCP / hook / API)
    O->>O: fingerprint build locally (hashes only)
    O->>R: register stamp: fingerprints + policy (signed)
    A->>A: fingerprint the user's file locally
    A->>R: POST /v1/check {digests, use: "port", licence tokens?}
    R-->>A: owner, policy decision, band, guidance, signed receipt
    R-->>O: alert (match / probing / conflict) via webhook
```

Every file gets a **layered identity**. No single fingerprint survives everything, so Grantstamp combines several:

| Layer | What it survives |
| --- | --- |
| `sha256` | nothing; exact copies only, zero false positives |
| `chunks`, content-defined chunking | patches, edits, embedding in a bigger file |
| `strings`, printable strings and code literals | recompiling, other compilers, stripping, porting, decompiling |
| `symbols`, identifier-like strings | weak evidence on its own, so stricter thresholds |
| `winnow`, normalised code k-grams | reformatting and renaming in source code |
| `dhash`, perceptual image hash | re-encoding and resizing of textures and art |
| `markers`, embedded notice or signed `grantstamp.json` | anything that keeps strings; also visible to agents reading the file |

Matches are graded **exact > high > medium > low**. Only high and exact can produce a hard *deny*. A medium-confidence match turns the owner's *deny* into *ask*.

## Quick start

```bash
pip install grantstamp           # client, CLI, MCP server, agent hook (Apache-2.0)
pip install grantstamp-server    # only to run a registry (AGPL-3.0)
python examples/demo.py          # the whole story, locally, in ~10 seconds (needs both)
```

### Owners

```bash
grantstamp keygen                                   # your identity: ~/.grantstamp/owner.key
grantstamp owner create --name "Starfall Studio" --url https://starfall.example
grantstamp owner domain starfall.example            # prints a DNS TXT record / .well-known file
grantstamp owner verify starfall.example
grantstamp register ./build --title "Starfall Courier" --version 0.9.4 \
    --preset standard --contact legal@starfall.example --manifest
grantstamp marker stamp_… --lang cpp                 # notice to compile into the next build
grantstamp owner webhook https://hooks.slack.com/services/… --format slack
grantstamp token issue --stamp stamp_… --to "PortCo" --uses port,modify --days 90
grantstamp alerts
```

### AI agents and tools

- **MCP server** (Claude Desktop, Claude Code, Cursor, VS Code): run `pip install grantstamp`, then point your client at the `grantstamp-mcp` command. See [integrations/](integrations/).
- **Claude Code hook**: `grantstamp-hook` runs before Read, Edit and Bash on binaries and game files. It denies, asks or allows based on the owner's policy. See [integrations/claude-code](integrations/claude-code/README.md).
- **HTTP API**: `POST /v1/check`. Sign requests with RFC 9421 HTTP Message Signatures (Web Bot Auth compatible) for higher limits. See [spec/grantstamp-protocol-v0.1.md](spec/grantstamp-protocol-v0.1.md).
- **Command line**: `grantstamp check path/to/file --use port --exit-code`.
- **Browser**: the website's check page fingerprints a file in the browser; the file never leaves it.

### Run a registry

```bash
pip install "grantstamp-server[postgres]"
grantstamp serve --host 0.0.0.0 --port 8000 --db sqlite:///grantstamp.db --public-url https://registry.example
# or: docker compose up -d   (Caddy + HTTPS), or render.yaml + a free Neon Postgres: docs/05-integrations.md
```

## Benchmark (prototype scale)

The full results are in [bench/RESULTS.md](bench/RESULTS.md), reproducible with `python bench/run_bench.py`.

- **Detection.** A toy game was recompiled with gcc and clang at -O0 to -O3 with LTO, stripped, byte-patched, given half-rewritten strings, ported as a folder, or turned into synthetic decompiler output. Every variant matched **high** or **exact**.
- **Cross-matches.** 400 Linux system executables were checked against 60 others registered under 60 owners. There were **0 medium-or-higher matches across different source packages**. All 21 medium or high matches were programs from the same source package, which really do share code.

## Documentation

| | |
| --- | --- |
| [01 Problem](docs/01-problem.md) | What happened, why speed matters, where safeguards fail |
| [02 Solutions](docs/02-solutions.md) | Each original idea, what breaks, the fix that holds |
| [03 Architecture](docs/03-architecture.md) | Components, data flow, security boundaries |
| [04 Implementation](docs/04-implementation.md) | Algorithms, scoring, API and CLI reference |
| [05 Integrations](docs/05-integrations.md) | Every account and service needed, step by step |
| [Threat model](docs/threat-model.md) · [Spec](spec/grantstamp-protocol-v0.1.md) | Attacks and mitigations; the protocol |

## What Grantstamp is not

It is not DRM and not a court. It does not stop leaks, make anything uncrackable or decide what is legal. It puts the owner's signed claim and policy in front of a cooperating agent at the moment it is about to act, and tells the owner fast.

## Citing

Each release is archived on Zenodo with a DOI and in Software Heritage. Citation details are in [CITATION.cff](CITATION.cff); GitHub's "Cite this repository" button uses it.

## License

The client library, CLI, MCP server, agent hook and website are Apache-2.0 ([LICENSE](LICENSE)). The registry server in [server/](server/) (`grantstamp-server`) is AGPL-3.0-only ([server/LICENSE](server/LICENSE)): anyone who runs a modified copy for others must publish their changes. Agents and tools that only check the registry need only the Apache-2.0 client. The protocol specification is CC BY 4.0.

Copyright 2026 The Grantstamp Authors. "Grantstamp" and the Grantstamp seal are trademarks of the project owner; neither licence grants trademark rights. See [TRADEMARK.md](TRADEMARK.md).
