| … | … | @@ -1,6 +1,6 @@ |
| 1 | 1 | { |
| 2 | 2 | "name": "atproto-bridge", |
| 3 | "version": "0.9.18", | |
| 3 | "version": "0.9.19", | |
| 4 | 4 | "description": "Stateless keyless atproto MEMBRANE — fronts self-custody hyper-proto-peers to bluesky over HTTP/WS, holds no keys and never signs. Bare-runnable. Deploy root / flat closure over the identity+repo+store+pds packages.", |
| 5 | 5 | "type": "module", |
| 6 | 6 | "main": "index.js", |
| … | … | @@ -15,6 +15,19 @@ const FAVELA_METHODS = new Set([ |
| 15 | 15 | // Is this a stateless lens-export service read we forward to favela-web? |
| 16 | 16 | export function isFavelaMethod (nsid) { return FAVELA_METHODS.has(nsid) } |
| 17 | 17 | |
| 18 | // The membrane's own did:web document, served at GET /.well-known/did.json — this makes did:web:<host> | |
| 19 | // (serverDid) RESOLVABLE. When the lens-export is on (favelaWebUpstream set), it advertises the #bsky_fg | |
| 20 | // BskyFeedGenerator service pointing back at the membrane, so a feed record whose `service` = this did:web | |
| 21 | // resolves here and bsky calls getFeedSkeleton at this host → proxyToFavela → favela-web. Without the | |
| 22 | // feature it is still a valid (empty-service) did doc. Returns null for a non-did:web serverDid. | |
| 23 | export function buildMembraneDidDoc (serverDid, { favelaWebUpstream = null } = {}) { | |
| 24 | if (!serverDid || !/^did:web:/.test(serverDid)) return null | |
| 25 | const host = serverDid.slice('did:web:'.length) | |
| 26 | const doc = { '@context': ['https://www.w3.org/ns/did/v1'], id: serverDid, service: [] } | |
| 27 | if (favelaWebUpstream) doc.service.push({ id: '#bsky_fg', type: 'BskyFeedGenerator', serviceEndpoint: `https://${host}` }) | |
| 28 | return doc | |
| 29 | } | |
| 30 | ||
| 18 | 31 | // Proxy one GET to favela-web. upstream = the gateway base URL (config.favelaWebUpstream, e.g. |
| 19 | 32 | // http://10.22.0.1:4041). doFetch(url,{method,headers}) → { status, contentType, body:Buffer } (the same |
| 20 | 33 | // injected fetch proxyToAppView uses). 501 when unconfigured; 502 on upstream failure. |
| … | … | @@ -11,7 +11,7 @@ import https from 'bare-https' |
| 11 | 11 | import bareWs from 'bare-ws' |
| 12 | 12 | import { tidNow } from 'atproto-store/lib/tid.js' |
| 13 | 13 | import { proxyToAppView, isAppViewMethod } from './appview.js' |
| 14 | import { proxyToFavela, isFavelaMethod } from './favela-proxy.js' | |
| 14 | import { proxyToFavela, isFavelaMethod, buildMembraneDidDoc } from './favela-proxy.js' | |
| 15 | 15 | |
| 16 | 16 | // The caller's bearer token (access/refresh JWT) — passed to the peer, which is the auth authority. |
| 17 | 17 | const bearer = (req) => (req.headers.authorization || '').replace(/^Bearer\s+/i, '') |
| … | … | @@ -147,6 +147,15 @@ export function createPdsServer ({ peers = null, serverDid = null, availableUser |
| 147 | 147 | return res.end(body) |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | // did:web resolution: GET /.well-known/did.json → the membrane's own did doc. With the lens-export on | |
| 151 | // (favelaWebUpstream), it advertises #bsky_fg so a feed record whose service = this did:web resolves | |
| 152 | // here and bsky's getFeedSkeleton lands on proxyToFavela → favela-web. | |
| 153 | if (req.method === 'GET' && url.pathname === '/.well-known/did.json') { | |
| 154 | const doc = buildMembraneDidDoc(serverDid, { favelaWebUpstream }) | |
| 155 | if (!doc) return sendErr(res, 404, 'NotFound', 'no did:web served here') | |
| 156 | return sendJson(res, 200, doc) | |
| 157 | } | |
| 158 | ||
| 150 | 159 | if (req.method === 'GET') { |
| 151 | 160 | switch (nsid) { |
| 152 | 161 | case 'com.atproto.server.describeServer': return sendJson(res, 200, { did: serverDid, availableUserDomains }) |
| … | … | @@ -8,6 +8,7 @@ |
| 8 | 8 | import { createServer } from 'node:http' |
| 9 | 9 | import { WebSocketServer } from 'ws' |
| 10 | 10 | import { proxyToAppView, isAppViewMethod } from './appview.js' |
| 11 | import { buildMembraneDidDoc } from './favela-proxy.js' | |
| 11 | 12 | |
| 12 | 13 | // AppView upstream client (node): global fetch → { status, contentType, body:Buffer }. |
| 13 | 14 | async function doFetch (url, { method, headers, body }) { |
| … | … | @@ -55,7 +56,7 @@ async function readJson (req) { |
| 55 | 56 | |
| 56 | 57 | // The membrane serves ONLY fronted peers. `peers` (PeerRouter) owns the fronted set + live |
| 57 | 58 | // PeerFronts. serverDid/availableUserDomains answer describeServer (there is no local account). |
| 58 | export function createPdsServer ({ peers = null, serverDid = null, availableUserDomains = [] } = {}) { | |
| 59 | export function createPdsServer ({ peers = null, serverDid = null, availableUserDomains = [], favelaWebUpstream = null } = {}) { | |
| 59 | 60 | const resolveHandle = (h) => (peers ? peers.resolveHandle(h) : null) |
| 60 | 61 | const resolveDid = async (idOrHandle) => { |
| 61 | 62 | if (!idOrHandle) return null |
| … | … | @@ -95,6 +96,15 @@ export function createPdsServer ({ peers = null, serverDid = null, availableUser |
| 95 | 96 | return res.end(body) |
| 96 | 97 | } |
| 97 | 98 | |
| 99 | // did:web resolution: GET /.well-known/did.json → the membrane's own did doc. With the lens-export on | |
| 100 | // (favelaWebUpstream), it advertises #bsky_fg so a feed record whose service = this did:web resolves | |
| 101 | // here and bsky's getFeedSkeleton lands on the favela proxy → favela-web. | |
| 102 | if (req.method === 'GET' && url.pathname === '/.well-known/did.json') { | |
| 103 | const doc = buildMembraneDidDoc(serverDid, { favelaWebUpstream }) | |
| 104 | if (!doc) return sendErr(res, 404, 'NotFound', 'no did:web served here') | |
| 105 | return sendJson(res, 200, doc) | |
| 106 | } | |
| 107 | ||
| 98 | 108 | if (req.method === 'GET') { |
| 99 | 109 | switch (nsid) { |
| 100 | 110 | case 'com.atproto.server.describeServer': return sendJson(res, 200, { did: serverDid, availableUserDomains }) |
| … | … | @@ -0,0 +1,37 @@ |
| 1 | // The membrane's did:web document — GET /.well-known/did.json makes did:web:<host> (serverDid) resolvable, | |
| 2 | // and advertises #bsky_fg when the favela lens-export is on so a feed record whose service = this did:web | |
| 3 | // resolves here (getFeedSkeleton → favela-web). Run via brittle-node. | |
| 4 | import test from 'brittle' | |
| 5 | import { buildMembraneDidDoc } from '../lib/favela-proxy.js' | |
| 6 | import { createPdsServer } from '../lib/server.js' | |
| 7 | ||
| 8 | const SERVER_DID = 'did:web:pds.7rnx.net' | |
| 9 | ||
| 10 | test('buildMembraneDidDoc: #bsky_fg present iff the lens-export is on', (t) => { | |
| 11 | const off = buildMembraneDidDoc(SERVER_DID, {}) | |
| 12 | t.is(off.id, SERVER_DID, 'doc id = serverDid') | |
| 13 | t.alike(off.service, [], 'no services when favelaWebUpstream is off') | |
| 14 | ||
| 15 | const on = buildMembraneDidDoc(SERVER_DID, { favelaWebUpstream: 'http://10.22.0.1:4041' }) | |
| 16 | t.is(on.service.length, 1, 'one service when the lens-export is on') | |
| 17 | t.is(on.service[0].id, '#bsky_fg', 'service id = #bsky_fg') | |
| 18 | t.is(on.service[0].type, 'BskyFeedGenerator', 'service type = BskyFeedGenerator') | |
| 19 | t.is(on.service[0].serviceEndpoint, 'https://pds.7rnx.net', 'endpoint = https://<serverDid host>') | |
| 20 | ||
| 21 | t.is(buildMembraneDidDoc('did:plc:notweb', {}), null, 'non-did:web serverDid → null') | |
| 22 | t.is(buildMembraneDidDoc(null, {}), null, 'no serverDid → null') | |
| 23 | }) | |
| 24 | ||
| 25 | test('GET /.well-known/did.json serves the membrane did doc with #bsky_fg (lens-export on)', async (t) => { | |
| 26 | const server = createPdsServer({ peers: null, serverDid: SERVER_DID, availableUserDomains: ['.7rnx.net'], favelaWebUpstream: 'http://10.22.0.1:4041' }) | |
| 27 | await new Promise((r) => server.listen(0, '127.0.0.1', r)) | |
| 28 | t.teardown(() => server.close()) | |
| 29 | const base = `http://127.0.0.1:${server.address().port}` | |
| 30 | ||
| 31 | const res = await fetch(`${base}/.well-known/did.json`) | |
| 32 | t.is(res.status, 200, 'did.json 200s (was MethodNotImplemented before)') | |
| 33 | const doc = await res.json() | |
| 34 | t.is(doc.id, SERVER_DID, 'did doc id = serverDid') | |
| 35 | const fg = (doc.service || []).find((s) => s.id === '#bsky_fg') | |
| 36 | t.ok(fg && fg.type === 'BskyFeedGenerator' && fg.serviceEndpoint === 'https://pds.7rnx.net', 'advertises #bsky_fg → https://pds.7rnx.net (bsky resolves the feed service here)') | |
| 37 | }) |