ANProto over ATProto -- using Bluesky PDSes to store ANProto messages and blobs
1# Work Order: ANProto Messages on Bluesky PDS
2
3## Scope
4- Store ANProto-signed messages (and blobs) in a Bluesky PDS using the existing Node OAuth backend. APDS remains frontend-only.
5- Use custom collections `com.anproto.message.v1` (messages) and optional `com.anproto.blob` if we need standalone blob records.
6
7## First Steps
8- Lexicons: `com.anproto.message.v1` has `anmsg` (full ANProto message), optional `anblob`, `anhash` (base64 ANProto hash), and `blobhash` (hash of the attached blob). PDS rkey uses a base64url form of `anhash` (replace `+`→`-`, `/`→`_`, strip `=`) to satisfy record-key rules. IDs must match the collection names exactly. `com.anproto.blob` is optional if blobs stay in `anblob`.
9- OAuth/scopes: Keep Node OAuth flow; request repo read/write + blob upload (`atproto` for now). Continue storing DID in cookies and tokens server-side.
10- Signing/validation: Frontend APDS signs messages; send backend `{anmsg, blob?, blobMime?}`. Backend recomputes `anhash` via ANProto, converts to base64url rkey, and rejects mismatches.
11- Persistence: Upload blobs via `com.atproto.repo.uploadBlob`; create `com.anproto.message.v1` records with rkey = base64url(anhash), storing `anmsg`, `anhash`, optional `anblob`, and optional `blobhash`.
12- Retrieval/indexing: Add backend endpoints to fetch by rkey/anhash/DID; optional local index (DB) for search/filter; fallback to repo reads by rkey.
13- Safety: Enforce size limits on content/blobs, rate-limit publish, reject tampered/duplicate/invalid signatures, log verification failures.
14
15## Client UI (Frontend)
16- Auth status: “Connect Bluesky” button; show connected DID/handle; disable publish until connected.
17- Key management: Display ANProto pubkey; controls to generate/import/export (avoid leaking private key in production).
18- Composer: Text area for content, optional “previous” hash, blob uploader, live display of computed hash/signature.
19- Publish flow: “Sign & Save to Bluesky” runs APDS sign then POSTs to backend; show progress/errors.
20- Viewer: Fetch by hash, display content, author pubkey, timestamp, previous chain, blob previews; simple search/filter if backend index exists.
21- Notifications: Inline status/toasts for auth, signing, upload, and save failures.