// The PLC directory both sides register their accounts' DIDs with: a DID's // document, and the operations that made it (spec/atproto/did-plc.md). import { isDeepStrictEqual } from 'node:util' import { plcUrl, ref } from './processes.mjs' import { differ } from './report.mjs' const get = async (path) => { const r = await fetch(`${plcUrl}/${path}`) return { status: r.status, body: await r.json().catch(() => null) } } /// The DID document the directory serves for `did`. export const plcDocument = (did) => get(did) /// The operations the directory holds for `did`, oldest first. export const plcLog = (did) => get(`${did}/log`) /// What fails a check held to both sides. The reference is held to it too, /// which checks the check: its failure is the harness's to fix. export const fail = (side, what, request, want, got) => differ(`the ${side.name}'s ${what}`, request, want, got, side === ref ? 'the reference fails the check it is held to' : undefined) /// A `didDoc` answered for `did` on `side` must be the one the directory /// serves. export async function checkDidDoc(side, did, didDoc, what, request) { const doc = await plcDocument(did) if (doc.status !== 200) return fail(side, what, request, `the DID registered with the PLC directory`, doc) if (!isDeepStrictEqual(didDoc, doc.body)) await fail(side, what, request, { didDoc: doc.body }, { didDoc }) }