# Verifying an Aigistry record (rules 2.0 and 2.1)

Every record page at `https://<host>/r/<record_hash>` has a twin at `.../r/<record_hash>.json`:

    {"signed":<exact signed text>,"record_hash":"<hex>","signature":"<hex>","signature_algorithm":"Ed25519","public_key_id":"<id>"}

## The three checks
1. **Take the signed text as raw bytes.** It is everything between `{"signed":` and `,"record_hash":`. Do not parse and re-print it; any change of spacing or key order changes the hash.
2. **Hash.** The SHA-256 of those bytes (UTF-8), written as 64 lowercase hex characters, must equal `record_hash`.
3. **Signature.** `signature` (128 hex characters) must be a valid Ed25519 signature, made over the ASCII text of the 64-character hash, under the public key listed at `/public-key.json` whose `key_id` equals `public_key_id`.

If all three pass, Aigistry signed exactly that text. Nothing else is claimed: the signature does not say the statement is true.

## What the signed text contains
A JSON object with these fields, in this order: `format` ("2.0", or "2.1" when the record has an author), `type` ("record" or "removal"), `external_id`, `organization`, `kind` ("commercial"; early test records may say "government"), `jurisdiction`, `domain`, `agency`, `author` (only in format 2.1), `title`, `body`, `source_url`, `attachments` (a list of `{name, size, sha256}`), `published_at`, `received_at`, `revision`, `supersedes`. `supersedes` is the record hash of the previous revision, or null for the first. `domain` is the domain the publishing organization proved it controls; the page says "Published by the organization that controls <domain>." `author` is who wrote or posted the statement, as the publisher stated it; Aigistry does not check it. A record without an author is signed as format 2.0 with no `author` key; a record with an author is signed as format 2.1 with `author` right after `agency`. Verifiers hash the signed text exactly as stored and never rebuild it, so both formats verify with the same three checks.

## Tools
- `verify.py` (Python 3, `pip install cryptography`): `python3 verify.py record.json --keys public-key.json`
- `verify.php` (PHP with sodium): `php verify.php record.json --keys public-key.json`
- In the browser: `/verify/`
- Both programs fetch `/public-key.json` by default. Pass `--key <64 hex characters>` to supply a key yourself.

## Test vectors
`vectors/valid.json` must verify; `vectors/tampered-text.json` and `vectors/tampered-signature.json` must not. They were signed with a test key, in `vectors/KEY.txt`, not a production key.

## Erased records
If a publisher permanently deletes a publication, its text is erased and the page shows a notice. The signed text no longer exists, so verification is no longer possible for that record. This is by design.
