OverviewFilesCommitsIssuesDocsReleasesPeers

atproto-bridge / pds / test / mk-did-router.js

16 lines · javascript ref:
// Test helper: construct the canonical atproto-did-peer DidPeerRouter EXACTLY as pds-serve.js does
// (owns-swarm + injectable join with the NAT-symmetric opts + rpc for the write path). Signature mirrors
// the retired PeerRouter's `new PeerRouter(swarm, corestore, opts)` so migrated tests only swap the call.
// Extra/unknown opts (e.g. the retired staleStrikeLimit) are harmlessly ignored by DidPeerRouter.
import { DidPeerRouter } from 'atproto-did-peer'
import { discoveryTopic } from 'atproto-identity/lib/discovery.js'

export function mkDidRouter (swarm, corestore, opts = {}) {
  return new DidPeerRouter(corestore, {
    swarm,
    join: (did) => { try { swarm.join(discoveryTopic(did), { server: true, client: true }); if (swarm.flush) swarm.flush().catch(() => {}) } catch {} },
    rpc: true,
    ...opts
  })
}