OverviewFilesCommitsIssuesDocsReleasesPeers

atproto-bridge / pds / lib / did-doc.js

16 lines · javascript ref:
// The membrane's own did:web document, served at GET /.well-known/did.json — it makes did:web:<host>
// (serverDid) RESOLVABLE. When a feed generator is served here (the gateway's lens registered
// app.bsky.feed.getFeedSkeleton as an XRPC extension), it advertises #bsky_fg pointing back at this host,
// so a feed record whose `did` is this did:web resolves here. Without one it is still a valid
// (empty-service) did doc. Returns null for a non-did:web serverDid.
//
// (Until 0.9.55 this lived in favela-proxy.js and keyed on a favela-web upstream URL; the lens is now a
// role of the same process, so the honest condition is "is a feed skeleton actually served here".)
export function buildMembraneDidDoc (serverDid, { feedGenerator = false } = {}) {
  if (!serverDid || !/^did:web:/.test(serverDid)) return null
  const host = serverDid.slice('did:web:'.length)
  const doc = { '@context': ['https://www.w3.org/ns/did/v1'], id: serverDid, service: [] }
  if (feedGenerator) doc.service.push({ id: '#bsky_fg', type: 'BskyFeedGenerator', serviceEndpoint: `https://${host}` })
  return doc
}