OverviewFilesCommitsIssuesDocsReleasesPeers

atproto-identity / lib / discovery.js

19 lines · javascript ref:
// DID-derived P2P discovery (the "sneaky P2P" binding, Option 2).
//
// The rendezvous topic for a DID is DERIVED, not written anywhere: the DID document stays
// 100% vanilla atproto (only atproto_pds -> the bridge), so bsky/HTTP never sees a P2P side.
// A self-custody peer announces on discoveryTopic(did); a bridge, given the DID, derives the
// SAME topic, connects, and AUTHENTICATES the peer on connect (the peer's served repo must
// sign against the DID's key — a squatter on the public topic can't forge that). So the lookup
// is deterministic + unauthenticated; trust is established at the connection, not the address.

import crypto from 'hypercore-crypto'

const NS = 'hyper-proto-peer/discovery/v1:'

// did (string) -> 32-byte Hyperswarm topic. Deterministic; anyone with the DID can compute it.
export function discoveryTopic (did) {
  if (!did || typeof did !== 'string') throw new Error('discoveryTopic: did (string) required')
  return crypto.data(new TextEncoder().encode(NS + did))
}