# Auditor guide — AHOOK audit evidence

**Status:** repo doc, written 2026-11-21 after the simulated external audit
(`docs/sim-audit-ahook-run-20261120.md`, gaps A2–A7). **Published at `https://ahook.app/audits` since 2026-11-22** (the formal build spec is at `https://ahook.app/docs/auditor-api.md`); the machine-readable discovery route is `https://ahook.app/openapi.json`. This guide is the plain-language version of it.

## What you are looking at

AHOOK keeps a hash-chained audit log for each property: every action the
platform takes on that property's behalf is one row in a chain, each row
linked to the one before it by a SHA-256 hash. Rows are grouped into
batches, each batch has a Merkle root, and each root is anchored outside
AHOOK's control — currently in the Bitcoin blockchain via OpenTimestamps
(OTS), which is the interim primary anchor. This API lets you pull that
evidence yourself and verify it on your own machine, without trusting
AHOOK's server.

The trust model, in one paragraph: you trust (a) the hash chain, which
you can recompute; (b) the Merkle roots, which you can check against
anchors held outside AHOOK; and (c) your own sampling, which you
control. You do not trust the server, and you do not have to ask AHOOK
for anything beyond the published artefacts. **What you cannot verify
from this API alone is completeness — that every event was emitted.**
That rests on the platform's emission controls, not on any API feature.
The API serves raw evidence, never verdicts: it will not tell you a
control is passing.

## Getting access

You do not sign up. The property owner issues you a key for a specific
engagement:

1. The owner gives you, out of band, two things: the key secret (once —
   it is never shown again) and the property's group id (see below).
2. The key is scoped to exactly one property and one time window (your
   engagement observation window, at most 12 months). It cannot read
   anything outside that property or window, ever.
3. Tell the owner what window you need **before** the key is issued:
   a window that does not fully cover a batch cannot be used to
   recompute that batch's root (see "Windows and batches").

**The group id.** The owner hands you the property's group id with the
key — it is in the issuance response as `property_id` (a `grp_…` id),
and every auditor response echoes the same `property_id`. There is no
property parameter on auditor reads and no way to list properties: the
property is derived from your key. If you hold keys for two properties,
you hold two keys.

## Your key

- Format: `ahka_` followed by 64 hex characters. Send it as
  `Authorization: Bearer ahka_…` on every call.
- It is read-only by construction. There is no write endpoint on this
  surface at all: no issuing keys, no config, no payments, nothing.
- Default scopes are all five read scopes (`audit:log:read`,
  `audit:roots:read`, `audit:access:read`, `audit:config:read`,
  `audit:export:read`); the owner may narrow them. A scope you lack
  returns 403 on your own property.
- The key dies at `window_end`. No extension: a longer engagement gets
  a new key. The owner can revoke it at any time and revocation is
  immediate.
- Wrong, revoked, expired, or unknown keys all return the identical
  generic 401 — there is no way to probe key state from the API. The
  owner sees key status from the owner key list, not from the API.
- Every call you make is itself logged into the audit log (your key id,
  what you asked for, when). The owner can see your pull.

## What you can read

Base URL: `https://ahook.app`. All paths below take only an `ahka_` key.

| Endpoint | What it gives you |
|---|---|
| `GET /api/v1/audit/log` | The audit events in your window, oldest first, cursor-paginated (default 100 per page, hard max 1,000). Filters: `?action=`, `?result=`, `?actor_ref=`. Events outside your window are silently excluded, never an error. |
| `GET /api/v1/audit/log/{id}/inclusion` | A Merkle inclusion proof for one event against its batch root. |
| `GET /api/v1/audit/roots` | The stored Merkle roots for your property: batch id, seq range, event count, root, anchor status, and per-batch anchors (type, ref, status, txid, block height, confirmations). |
| `GET /api/v1/audit/verify` | **Convenience only, not the proof.** Server-side recompute for one batch or up to 10,000 events. Do not rely on it alone — the offline verifier is the real check. |
| `GET /api/v1/audit/access` | Role history for the property (who held which role, when). Change history is thin today and MFA state is returned as null, not guessed. |
| `GET /api/v1/audit/config` | Config change history plus current versioned config where history exists. Secret fields are redacted. |
| `GET /api/v1/audit/export?format=oscal` | OSCAL Assessment Results JSON (NIST OSCAL 1.1.2), bounded to your window, capped at 100,000 events per call with cursor continuation. One truthful finding per result records the export's own coverage; it asserts no verdict about the property's controls. |
| `GET /api/v1/audit/anchors/{anchor_id}` | The anchor proof bytes for one anchor: `proof_base64` + `proof_sha256` (OpenTimestamps) or `token_base64` + `token_sha256` (RFC 3161). |
| `GET /api/v1/audit/zk-proofs/{statement_id}/{statement_version}/{hash}` | A stored ZK proof artifact for your property (`?file=registry` serves its registry sidecar). 404 on a foreign property, no oracle. |
| `GET /api/v1/audit/verifier.js` | The offline verifier (public, no auth). See below. |

## Verifying offline (the real check)

1. Download the verifier: `GET /api/v1/audit/verifier.js`. It is a
   single-file Node script (v1.2.1), no dependencies.
2. Check the download before you run it. SHA-256 of the served file:
   `690a1a78155c1eda9f864298bf2e4115b3a71a71a422c960cebcce078ab8dd57`
   (verified live 2026-11-22; also served as the `x-verifier-sha256`
   response header, with `x-verifier-version: 1.2.1`). Recompute it with
   `curl -s https://ahook.app/api/v1/audit/verifier.js | sha256sum`.
   If the hash differs, do not run the file — ask the owner for the
   current published hash. Note: the hash is of the **served bytes**,
   not of the repo file `src/auditor-verifier.mjs`, which wraps the
   same script in a header comment and module exports.
3. Assemble an evidence file from the API (log + roots + anchors):
   `{"property_id": "grp_…", "window": {"start": "<ISO>",
   "end": "<ISO>"}, "events": […], "batches": […], "anchors": […]}`.
   Events and batches are the objects the API returns, unchanged.
   Anchors carry `anchor_id`, `batch_id`, `type`
   (`rfc3161` or `opentimestamps`), `status` (`anchored` or
   `submitted`), and `token_base64` (RFC 3161) or `proof_base64`
   (OpenTimestamps). An optional `proofs` array holds per-event
   inclusion proofs from `/inclusion` (`{"event_id": "…",
   "proof": […]}`).
4. Run it: `node verifier.js evidence.json`. It prints one
   `PASS` / `FAIL` / `SKIP` line per check and a final
   `RESULT: PASS — all checks passed` (exit 0) or
   `RESULT: FAIL (N failed check(s))` (exit 1).

| Check | What it proves |
|---|---|
| `window` | Every event in the file lies inside the key window. |
| `chain` | Every event hash recomputes from the canonical string, `prev_hash` links are continuous, `seq` is contiguous. |
| `batch <id>` | The batch's events are all present, its count matches, and its Merkle root recomputes from the event hashes. |
| `inclusion` | Every batched event is a leaf of its batch's tree. |
| `proof <event_id>` | A supplied per-event inclusion proof verifies against its batch root. |
| `anchor <id>` | For a TSA token: the token parses, its message imprint is the batch root, the signature verifies, and the chain walks to a self-signed root (compare the printed root fingerprint against the TSA's published certificate yourself). For an OTS proof: the proof parses, its file digest is the batch root, the tree walks to a Bitcoin attestation, and the walked Merkle root matches the real block header at the attested height. |

**SKIP is not FAIL.** A batch outside your pull's seq coverage, or
straddling its edge, is SKIP — its root cannot be verified from this
pull, and that is the window doing its job, not tampering. An OTS
proof with only a pending attestation, or under 6 confirmations, is
SKIP while its status is `submitted` (immature, not wrong) and FAIL
if its status is `anchored`. Block headers come from public
mempool.space by default; `--explorer <base-url>` points at any
Esplora-compatible API, and `--headers-file <path>` supplies headers
offline as JSON (`{"<height>": "<80-byte header hex>",
"tip": <height>}`).

**One representation trap:** `created_at` in the canonical hash
string is integer epoch milliseconds (see `docs/audit-log.md` §1).
The API serves it as an ISO-8601 string, so an auditor recomputing
by hand must convert it back to epoch milliseconds first (the
verifier does this with `Date.parse`). Putting the ISO string
straight into the canonical string fails; epoch milliseconds
matches. The stored value is `Date.now()` at write time.

## Windows and batches

- The window filter is on `created_at` (epoch milliseconds),
  inclusive at both ends: `window_start <= created_at <= window_end`.
- `/roots` serves the **stored** roots — they are always available
  for your property, whatever your window is.
- Recomputing a root needs the batch's events, all of them. A window
  must cover a batch in full (`seq_start` .. `seq_end`) to recompute
  its root. If it does not, the server-side `/verify` reports
  `recomputed_root: null` and `root_matches: false` — that means the
  window is too narrow, not that the root is wrong. Widen the window
  (a new key, if the engagement window must grow) or check the stored
  root from `/roots` instead. The offline verifier SKIPs such batches
  rather than failing them.
- Set the window to cover the batches you intend to verify before the
  key is issued. A 60-day window covered all 15 batches in the
  rehearsal run; size yours to your engagement.

## Limits

- Per-key rate limit: 600 requests/minute (429 + `Retry-After` past
  it; the 429 is logged).
- Page size: default 100, hard max 1,000. A larger `?limit=` is capped
  to 1,000, not honoured, not an error.
- `/verify`: one batch or 10,000 events per call.
- `/export`: 100,000 events per call, cursor continuation.
- Inclusion proofs: one event per call, no bulk endpoint.
- Key issuance (owner side): at most 5 new keys per property per
  rolling 24 hours, at most 10 active keys per property. A property
  that needs more is a conversation, not a silent increase.

## What this API does not do

- No SOC 2, HIPAA, or compliance claim. It serves evidence; it does
  not certify anything.
- No verdicts. It returns events, roots, and proofs, never a "control
  passing" judgement.
- No public roots feed in v1 (roots are key-gated; the external
  publication is the anchor itself).
- No SIEM mirror in v1 and no POA&M export (Assessment Results only).
- No completeness proof (see above).
