# The schemas

This directory holds the JSON Schemas for everything ForgetMe and ForgetProof put on the wire: nine
schemas for the ForgetMe v1 contract with valid and invalid fixtures, two for the older 0.2 provider
surface, and the Poppy 1.0 kit's schemas vendored unmodified. This page says what each schema
describes and how to validate a document against it with ajv or with Python's `jsonschema`.

Status: served under [`/schemas/`](https://forget.stellarminds.ai/schemas/) on the demo site; not yet
packaged on PyPI or npm.

A **receipt** is one holder's signed statement about one erasure; a **holder** is one store of one
party. The **index** is the document a server answers at its ForgetMe endpoint, with its name and
keys. The [glossary](../docs/GLOSSARY.md) has the rest; the [wire contract](../docs/extension.md) says
where each document is used.

## The ForgetMe v1 schemas

Under `forget-me/v1/`, one schema per shape of the contract:

| Schema | Describes |
| --- | --- |
| `common.schema.json` | The shared definitions the others reference: references, operation ids, the six outcome words, the approval offer. |
| `discovery.schema.json` | The `stellarminds.ai/forget-me` fragment a Company merges into its `poppy.json`. |
| `index.schema.json` | The index at `GET {endpoint}`: issuer, keys, routes, scopes, limits, `approval`, `identity`. |
| `preview-request.schema.json` | The body of `POST {endpoint}/preview`. |
| `preview.schema.json` | A `Preview`: item, holders, exceptions, exact terms. |
| `submit-request.schema.json` | The body of `POST {endpoint}/submit`: terms, approvals, idempotency key. |
| `operation.schema.json` | An `Operation`: state, terms, outcome per holder, log. |
| `evidence.schema.json` | An `Evidence` document: one portable receipt per holder, plus observations. |
| `receipt.schema.json` | A portable receipt, `forget-me-receipt/1`: counts, timestamps, vocabulary words, the Ed25519 `public_key` and `signature`. |
| `error.schema.json` | Every non-2xx answer: `error`, `error_description` and the fields some codes add. |

## The fixtures

`forget-me/v1/fixtures/<shape>/valid/` holds documents each schema must accept and
`…/invalid/` documents it must refuse; `fixtures/poppy/` holds the operation and approval documents the
reference Company exchanges over Poppy. The receipt fixtures are real, signed receipts for four of the
six outcome words.
`fixtures/content-rules/` holds receipts that pass the schema and must still be refused: one tampered
after signing, one whose coverage names a host path. A schema checks shape, never truth.

## The 0.2 schemas

At the root, for the [0.2 provider surface](../docs/provider-surface.md):

| Schema | Describes |
| --- | --- |
| `receipt.schema.json` | An engine receipt, `forgetproof-receipt/0.1` or `/0.2`: before and after scan counts, actions, canary results, copies, file hashes, and the Ed25519 `public_key` and `signature`. 0.2 adds `issuer`, `subject_values` and `copies`, requires every scan field, and allows no extra top-level keys. |
| `well-known.schema.json` | The document a hosted provider serves at `GET /.well-known/forgetproof.json`: its receipt-signing key and rotated predecessors under `keys`, the stores a forget request covers, the `forget`, `status` and `receipts` endpoints, and its capabilities. The schema carries an example. |

## The Poppy kit

`poppy-1.0-kit/` is the Personal Agent Protocol's Company kit schemas, copied unchanged; its
[README](poppy-1.0-kit/README.md) says where from and under which licence. The reference Company's
`poppy.json`, OAuth metadata, Session JWTs and operations are checked against them in the tests.

## Validate with ajv

Any stack with Node 18 or later. Fetch the schema and its shared definitions, then the document:

```sh
v1=https://forget.stellarminds.ai/schemas/forget-me/v1
curl -sO $v1/common.schema.json -O $v1/index.schema.json
curl -s https://company.forget.stellarminds.ai/forget-me/v1 > index.json
npx --yes -p ajv-cli@5 -p ajv-formats@3 ajv validate -c ajv-formats --spec=draft2020 --strict=false \
  -s index.schema.json -r common.schema.json -d index.json
```

The last command prints `index.json valid`. An invalid document prints `index.json invalid` and the
failing path. Every v1 schema takes `-r common.schema.json`. `-c ajv-formats` supplies the `date-time`
and `uri-template` format checks; without it ajv ignores `format` and warns.

A 0.2 engine receipt, with the signed fixtures in the verify package as examples:

```sh
npx --yes ajv-cli@5 validate -c ajv-formats --spec=draft2020 \
  -s schemas/receipt.schema.json -d "packages/forgetproof-verify/test/fixtures/*.json"
```

It prints one `valid` line per fixture.

## Validate in Python

`jsonschema` 4.18 or later:

```python
import json, httpx
from jsonschema import Draft202012Validator
from referencing import Registry, Resource

v1 = "https://forget.stellarminds.ai/schemas/forget-me/v1/"
common = httpx.get(v1 + "common.schema.json").json()
schema = httpx.get(v1 + "index.schema.json").json()
registry = Registry().with_resource(common["$id"], Resource.from_contents(common))
validator = Draft202012Validator(schema, registry=registry, format_checker=Draft202012Validator.FORMAT_CHECKER)
validator.validate(httpx.get("https://company.forget.stellarminds.ai/forget-me/v1").json())
print("valid")
```

It prints `valid`; an invalid document raises `ValidationError` naming the failing path.

## Limits

- A schema checks shape, never truth. The signature is checked by `forgetproof verify` or by
  [`forgetproof-verify`](../packages/forgetproof-verify/README.md), which also checks the key against
  the issuer's published keys.
- The signature over a receipt is Ed25519 over the canonical JSON of the receipt without its
  `signature` key: keys sorted by code point, no whitespace, non-ASCII raw, UTF-8. The key fingerprint
  shown to people is the first 32 hex characters of SHA-256 over the raw 32-byte public key.

## Next steps

- [ForgetMe v1, the wire contract](../docs/extension.md): where each shape is used, section by section.
- [Quickstart: a Company that serves ForgetMe](../docs/quickstart-company.md): validate your own index and receipts as you build.
- [forgetproof-verify](../packages/forgetproof-verify/README.md): the checks a schema cannot make.
