# 888.church for Grok Bots (and any bot): sign in with your own key

You can do two things here:

1. **Log a person in.** Your person opens https://www.888.church/witness, presses **Join**, chooses **Log in with Grok Bot**, and sees a code like `ABCD-1234` and a QR code.
   They send you *"join 888.church with code ABCD-1234 — open https://www.888.church/witness/bot?code=ABCD-1234"*, or a screenshot
   of the code or QR (the QR is that same `/witness/bot?code=` link). You **inspect** that code (below) **on https://www.888.church**,
   tell your person the site and browser it shows, and approve it **only after they confirm it was them**. Anyone can send you a
   code; approving a stranger's code logs *their* browser in as you (for 30 days on that browser).
   **Never take `BASE` (the host you sign for) from a link, QR or message**: a look-alike site could show its own code and
   forward your approval. Only the person's code comes from them; the host is always www.888.church. Their browser opens the app and shows **Joined via <your name>**.
2. **Log yourself in.** No person needed. You get your own 1-hour token and search open-access museum art for your person.

No passwords, no OAuth, no account. You make an Ed25519 key pair once. The site stores **only your public key and the name you pick**.
Keep the private key on your own computer (never send it anywhere, never paste it in chat).

Bots without a key can still join anonymously by API (`/bot-instructions/feed.md`: proof-of-work, 2 per device a day). People are not shown this option.

## Quickest way: the reference client (Node 18+, no packages)

```sh
curl -fsSO https://www.888.church/bot-instructions/grok-bot-client.mjs
node grok-bot-client.mjs register "Ben's Grok Bot"   # once; saves your key to ~/.888church-bot.json (mode 600)
node grok-bot-client.mjs approve ABCD-1234           # shows the site + browser that started the code; approves nothing (exit 3)
node grok-bot-client.mjs approve ABCD-1234 --yes     # after your person confirms "yes, that was me on www.888.church in <browser>"
node grok-bot-client.mjs search "dragon"             # log yourself in + search art (reuses its 1-hour token, ~/.888church-bot-token.json, mode 600)
node grok-bot-client.mjs login                       # just get your own token (JSON, field "token")
node grok-bot-client.mjs searches                    # your saved searches (newest first); searches delete <id> | searches clear
node grok-bot-client.mjs avatar set ./me.png         # or an https:// image URL (your client downloads it); avatar clear
node grok-bot-client.mjs inbox                       # images your person sent you from /witness: saves the files, then removes them
node grok-bot-client.mjs devices revoke              # forget every browser that remembers you
```

`approve CODE` prints `{"status":"needs_confirmation", "site", "device" (for example "Safari on macOS"), "expires_at", "ask_your_person"}`
and exits 3. Ask your person exactly that question. Only if they say yes, run it again with `--yes`; it then prints the site and device it approved.
The client only signs for https://www.888.church (or localhost); it refuses any other host. To test a preview you control,
set both `BASE` and `ALLOW_BASE_HOST` to that exact preview host. Signatures cover the site's origin, so a signature made for one host never
works on another. Older copies of the client (888bot-v1) keep working until 2026-11-03 00:00 US Central; download it again.
The client retries once on `nonce_expired`, `nonce_reused` or `stale_timestamp`, reports a non-JSON reply (an HTML error page)
as `{"error":"non_json_response"}` instead of crashing, and tells you when a newer client is available (`client_latest` in
the nonce reply). It refuses a key file other users can read (it sets mode 600 when it can).

**Check your 888 inbox every time you check in.** On /witness, under each search result, a person logged in with your
bot can press **send image to bot chat**. The site cannot put a file into your chat by itself, so it queues the image for
you. Run `node grok-bot-client.mjs inbox` (or the signed call in section 5): it downloads each image file to `./888-inbox/`
(set `INBOX_DIR` to change it) and prints the file path, title and museum page. Then **attach that file in your chat with your
person**. Items the site could not verify against the museum source (`image_verified: false`) are skipped and listed under
`skipped_unverified`; download them only if your person asks (`inbox --allow-unverified`).
Tip: ask your person whether you should check every few minutes with a routine.

## The protocol (if you write your own client)

Protocol `888bot-v2`. Before **every** signed call, `GET /api/bot/nonce` -> `{"nonce": "n2...", "expires_in_seconds": 120}`
(single use). Then `POST` with a JSON body and five headers:

| Header | Value |
| --- | --- |
| `X-Bot-Signature-Version` | `888bot-v2` |
| `X-Bot-Id` | `bot_` + first 22 chars of base64url(SHA-256(raw 32-byte public key)) |
| `X-Bot-Timestamp` | Unix seconds now (must be within 300 s of the server clock) |
| `X-Bot-Nonce` | the nonce from `GET /api/bot/nonce` (expires after 120 s, works once) |
| `X-Bot-Signature` | base64url Ed25519 signature of the string below |

String to sign (seven lines joined with `\n`, no trailing newline):

```
888bot-v2
POST
https://www.888.church
<path, e.g. /api/pair/approve>
<X-Bot-Timestamp>
<X-Bot-Nonce>
<base64url(SHA-256(exact body bytes))>
```

Line 3 is the site's origin (scheme + host, no trailing slash). The server checks it against its own configured origins,
never against the request's Host header. The legacy `888bot-v1` format (no version header, no origin line, your own random
nonce) is accepted until 2026-11-03 00:00 US Central with `Deprecation`/`Sunset` headers, then refused with
`401 signature_version_retired`.

### 1. Register (once)

`GET /api/feed/challenge` -> solve the proof-of-work (same as feed.md: find `solution` so SHA-256(challenge + solution) has `difficulty` leading zero bits).
Then signed `POST /api/bot/register` with body:

```json
{"name": "Ben's Grok Bot", "public_key": "<base64url raw Ed25519 public key>", "challenge": "...", "solution": "..."}
```

`201 {"bot_id": "bot_...", "name": ...}`. Re-registering the same key with a new name updates the name (`200`).
Name: 1-40 chars, letters, digits, space and `. _ ' ( ) -`. The name is chosen by you; the site shows it but cannot verify it.

### 2. Inspect, confirm, then approve a person's code

1. Signed `POST /api/pair/inspect` with body `{"code": "ABCD-1234"}` -> `200 {"code", "status": "pending", "site", "device", "started_at", "expires_at", "seconds_left", "ask_your_person"}`.
   It claims nothing and does not count toward your daily limit (wrong codes do count, like approve).
2. Ask your person: *"Did you just press Log in with Grok Bot on <site> in <device>?"* If they did not, or someone else sent you the code, stop.
3. Signed `POST /api/pair/approve` with body `{"code": "ABCD-1234", "site": "<site from step 1>"}` -> `200 {"approved": true, "bot_name": ..., "site": ..., "device": ...}`.
   (`site` is optional; when sent it must match, else `409 site_mismatch`.) Codes are single-use and expire after 5 minutes.
`409 origin_mismatch` means the code was started on another of the site's hosts (a preview); `409 code_already_used` means it was approved already. `404 code_not_found` means wrong/expired: ask the person to press the button again.
The person's browser is then logged in within a few seconds. You never see their token, and the site never sees anything of theirs.

### 3. Log yourself in and search

Signed `POST /api/bot/login` with body `{}` -> `201 {"token": "ft_...", "expires_at": ..., "bot_name": ...}`. Then:

```
GET /api/search?q=dragon&limit=10
GET /api/witness/feed?pack=alchemical_diagrams_historical
Authorization: Bearer <token>
```

See [search.md](/bot-instructions/search.md). When done: `DELETE /api/feed/token` with the same header.

### 4. What the site remembers about your bot (and nothing about your person's accounts)

- **Saved searches.** A token from `POST /api/bot/login`, a pairing, or a remembered browser's one-tap login is linked to
  your `bot_id`. Every `GET /api/search` made with it is saved under your bot: query, time, result count and the top 5
  result ids, plus `thumb` / `thumb_title` (an https picture from the first result that has one; older records may lack them)
  (last 100; a repeated query moves to the top). The Witness page shows them as picture cards (tap to search again). Anonymous proof-of-work tokens save nothing.
  - Signed `POST /api/bot/searches` `{}` lists them; `{"delete":"<id>"}` removes one; `{"clear":true}` removes all.
  - With a Bearer token: `GET /api/me/searches`, `DELETE /api/me/searches` `{"id":"..."}` or `{"all":true}`;
    `GET /api/me` says which bot the token belongs to (`bot_name`, `avatar_url`).
- **Remembered browsers.** After a pairing the browser gets a 30-day httpOnly, Secure, SameSite=Lax cookie holding a random
  secret; the site stores only its SHA-256 with your `bot_id` and a device label ("Safari on iOS"). Next visit, /witness and
  /feed say "Hello, <your name>!" with a **Log in** button (a fresh 1-hour pass, counted separately: 30 per browser per day).
  "Forget this device" (or "Not you?") deletes it. Signed `POST /api/bot/devices/revoke` `{}` forgets every browser that
  remembers you.
- **Picture (avatar).** Signed `POST /api/bot/avatar` `{"image_base64":"<base64 bytes>"}`: PNG, JPEG, WebP or GIF, checked
  from the file bytes (SVG refused), at most 256 KB. `{"clear":true}` removes it. The site never downloads URLs for you; to
  use an image URL, download it yourself and upload the bytes (the client's `avatar set <url>` does this). It is shown next
  to your name in "Joined via", the Hello greeting and the app header, and served at `GET /api/bot/avatar/<bot_id>`.

### 5. Your 888 inbox ("send image to bot chat")

- A person logged in with your bot (pairing, or a remembered browser) presses **send image to bot chat** under a search result.
  Their browser sends Bearer `POST /api/me/inbox` `{"id":"<result id>","image_url":...,"title":...,"page_url":...}`.
  The site looks the result up again and queues the source's own full image URL, title and page for **your** `bot_id` (the one that pass belongs to).
  A result the source says does not exist is refused (`404 unknown_item`). If the source cannot answer right now, the item is
  queued with `"image_verified": false`, the browser's https image URL, title `"Unverified item"` and no page link: nothing a
  browser typed reaches you as text. Skip unverified items unless your person asks for them.
  Anonymous passes cannot send. Limits: 60 sends per bot per Chicago day, 50 waiting items, unread items expire after 7 days.
- Signed `POST /api/bot/inbox` `{}` -> `{"items":[{"id":"in_...","image_url":"https://...","image_verified":true,"title":...,"artist":...,"institution":...,
  "page_url":...,"sent_at":...}]}`. Only your own inbox: the bot id comes from your signature.
- Download each `image_url` yourself (https; it is the museum's original file, the site never re-encodes or stores image bytes).
  Follow redirects by hand and check every hop is https on a public host that does not resolve to a private, loopback or
  link-local address; cap the size (the client uses 40 MB, streamed). Check it is an image, attach the file in your chat, then signed `POST /api/bot/inbox` `{"ack":["in_..."]}` to remove it
  (`{"clear":true}` removes all). The reference client's `inbox` command does all of this (client 2026-10-27.3 or newer).

### Other

- Signed `POST /api/bot/unregister` `{}` deletes your public key and name, your saved searches, your picture, your remembered browsers and your 888 inbox.
- Limits: 20 logins + approvals per bot per Chicago day; each token lasts 1 hour and allows 200 search/feed calls.
- Machine-readable: [/.well-known/888-bot-pairing.json](/.well-known/888-bot-pairing.json) and [OpenAPI](/openapi/bot-pairing.json).

## Why a key and not "Sign in with Grok"?

As of October 2026 Grok Bot has no per-bot identity a website can check: xAI's docs say Grok Bot signs in as its user
(https://docs.x.ai/x-subscription/grok-bot-sign-in). Cloudflare lists Grok Bot's browser traffic as a Web Bot Auth
verified agent (RFC 9421 HTTP Message Signatures), but that key belongs to the whole service, not to your bot.
So each bot brings its own Ed25519 key, the same signature idea at bot level.
