// Verify the LIVE peer PUSHES the corrected announce (atproto/did-announce/v1) — no get-coords.
// node scripts/capture-announce.mjs did:plc:...
import Hyperswarm from 'hyperswarm'
import Protomux from 'protomux'
import c from 'compact-encoding'
import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { openCorestore } from 'atproto-store/lib/corestore.js'
import { discoveryTopic } from 'atproto-identity/lib/discovery.js'
const did = process.argv[2]
if (!did) { console.log('usage: node capture-announce.mjs <did>'); process.exit(1) }
const dir = mkdtempSync(join(tmpdir(), 'ca-'))
const store = openCorestore(dir)
const swarm = new Hyperswarm()
const done = new Promise((res, rej) => {
const to = setTimeout(() => rej(new Error('no announce (peer offline or not on 0.3.20+)')), 25000)
swarm.on('connection', (conn) => {
try { store.replicate(conn) } catch {}
const chan = Protomux.from(conn).createChannel({ protocol: 'atproto/did-announce/v1' })
if (!chan) return
chan.addMessage({ encoding: c.json, onmessage: (a) => { if (a && a.did === did) { clearTimeout(to); res(a) } } })
chan.open()
})
})
swarm.join(discoveryTopic(did), { server: true, client: true })
await swarm.flush()
try { const a = await done; console.log('ANNOUNCE ' + JSON.stringify(a)) } catch (e) { console.log('FAIL ' + e.message) }
await swarm.destroy(); await store.close(); rmSync(dir, { recursive: true, force: true }); process.exit(0)