Skip to content

Commit 07f6ef0

Browse files
Merge pull request #261 from profullstack/codex/w3bs-net
feat: make W3BS Net its own primary registry
2 parents 5f69806 + 573164e commit 07f6ef0

12 files changed

Lines changed: 1749 additions & 551 deletions

‎.env.example‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ W3BS_DATA_DIR=.local/data
1010
# Set a random secret of at least 32 characters to enable publishing/revocation.
1111
# Keep this in your deployment secret manager, never in the repository.
1212
W3BS_PUBLISH_TOKEN=
13+
# Comma-separated W3BS account usernames allowed to operate W3BS Net.
14+
W3BS_NET_OPERATOR_USERNAMES=
15+
# Namespace suffixes routed through this W3BS instance (requires DNS, proxy and TLS).
16+
W3BS_NET_HOSTED_TLDS=whatever,agent,hacker
17+
# Set to off to pause Moshpit backfill and peer delivery in production.
18+
W3BS_NET_SYNC=
1319
# Optional operator-controlled trust store, defaults to fixtures/trust.json.
1420
# Key entries bind Ed25519 public keys to publisher namespaces.
1521
W3BS_TRUST_FILE=

‎docs/deployment.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ The service is deployment-ready source. Production launch requires publishing th
1313
| `DATABASE_URL` | PostgreSQL connection string. On Railway, `${{Postgres.DATABASE_URL}}` from the self-hosted Postgres service |
1414
| `W3BS_DATA_DIR` | Only used without `DATABASE_URL`: SQLite directory for local development |
1515
| `W3BS_PUBLISH_TOKEN` | Random administrative secret, at least 32 characters; absent means read-only |
16+
| `W3BS_NET_OPERATOR_USERNAMES` | Comma-separated W3BS usernames allowed to moderate registrations and manage federation peers |
17+
| `W3BS_NET_HOSTED_TLDS` | Comma-separated namespace suffixes routed through W3BS; DNS wildcard, proxy and TLS must be configured for each |
18+
| `W3BS_NET_SYNC` | Set to `off` to pause the production backfill and federation worker; otherwise it starts with W3BS |
1619
| `W3BS_TRUST_FILE` | Optional path to a mounted operator-managed trust file; otherwise bundled example public keys |
1720
| `RESEND_API_KEY` | Sends account email (signup and sign-in links). w3bs.org is a Resend domain; without it production sends nothing |
1821
| `W3BS_MAIL_FROM` | `W3BS <noreply@w3bs.org>` |
@@ -47,3 +50,5 @@ The service is initially safe to run read-only. Publishing requires explicit adm
4750
## Current operational limits
4851

4952
The server bounds request and response sizes and verifies Host and Origin headers. Platform-level request limiting should be configured for an internet-facing service. No billing, arbitrary tool execution, third-party messages, remote model calls or device control is enabled by this stack.
53+
54+
W3BS Net stores its primary registry in separate `net_*` tables. See `docs/w3bs-net.md` for the public API, OAuth 2.1/CLI operator access and peer setup. A name host uses `<label>.<tld>.w3bs.org`; each opted-in namespace suffix needs its own DNS wildcard, edge proxy host and TLS wildcard certificate.

‎docs/w3bs-net.md‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# W3BS Net
2+
3+
W3BS Net is an independent namespace registry hosted by W3BS. Its PostgreSQL/SQLite tables are separate from Moshpit and its local records have priority during name lookup. Namespace and name requests remain private until an operator approves them. There are no sales, pre-buys, paid reservations or auction states.
4+
5+
The initial open W3BS namespaces are `.agent` and `.whatever`. W3BS reviews every new name request in both namespaces; Moshpit records are backfill and do not reserve or sell W3BS names. The launch seeds `riotcoder.agent` and `cha0spunk.agent` as active operator-created names without assigning ownership. Only the matching W3BS username can request a claim; each claim goes back through moderation.
6+
7+
## Public API
8+
9+
- `GET /api/net/v1/registry?q=...` returns local W3BS names first, then opted-in federation announcements, then the Moshpit backfill. The response labels each record with its source.
10+
- `GET /api/net/v1/resolve/:name` resolves an exact name with the same local-first precedence.
11+
- `GET /api/net/v1/events?since=0&limit=100` reads the append-only public event log. Keep the returned `sequence` as a cursor and request later events with `since`.
12+
- `GET /api/net/v1/instances` and `GET /.well-known/w3bs-net.json` publish this instance, discovered instance announcements and opted-in peers.
13+
- `GET /.well-known/w3bs-net.json` describes the instance and its endpoints.
14+
- `POST /api/net/v1/federation/events` receives public announcements from an opted-in W3BS peer. It requires that peer's inbound bearer token. Imported peer announcements are attributed to their source and never become W3BS-owned registrations.
15+
16+
Local user requests use `POST /api/net/v1/tlds` and `POST /api/net/v1/names`. A signed-in W3BS browser session or a bearer minted for the `w3bs-cli` OAuth client by `w3bs login` is required. A successful request returns `202` and stays private until review.
17+
18+
## Operators and federation
19+
20+
Set `W3BS_NET_OPERATOR_USERNAMES` to a comma-separated list of W3BS usernames. Operators sign in to `/net/operator` with the browser session or use a CLI bearer from the existing W3BS OAuth 2.1 device authorization flow. The operator API controls moderation, peer opt-in, peer removal and backfill.
21+
22+
To connect two W3BS instances, each operator adds the other instance's HTTPS origin and the other instance's inbound token. The console creates a local inbound token once; share it with the remote operator and have them save it as their outbound token. Instances announce themselves and their public event streams. Each instance pulls from its direct peers, records the cursor, and relays new public events to its other opted-in peers. Delivery retries with bounded exponential backoff.
23+
24+
Peer delivery is authenticated with exchanged bearer tokens. Event IDs are SHA-256 integrity hashes, not cryptographic origin signatures, so operators should only connect peers they trust to relay accurate origin attribution.
25+
26+
The production daemon also imports public Moshpit allocation history and names in bounded pages. Moshpit records are stored with `https://pit.moshcode.sh` provenance and do not grant W3BS ownership. The importer reads Moshpit's public APIs; it does not attempt to claim names on behalf of users or mutate the Moshpit registry.
27+
28+
This event feed is a W3BS Net protocol surface inspired by relay and repository federation models. It is not a Nostr NIP-01 relay or an AT Protocol PDS/firehose implementation.
29+
30+
## Domain routing
31+
32+
An active name like `riotcoder.agent` resolves through `riotcoder.agent.w3bs.org`. Configure `W3BS_NET_HOSTED_TLDS` and a DNS wildcard, edge proxy host and TLS certificate for every suffix served here (the launch includes `*.whatever.w3bs.org`, `*.agent.w3bs.org` and `*.hacker.w3bs.org` for Moshpit backfill). If a name has a public HTTPS target, W3BS redirects to it. Otherwise the host serves the W3BS name record. Imported Moshpit names redirect to their source gateway when no local W3BS registration overrides them.

‎public/moshpit-root-ca.crt‎

Lines changed: 0 additions & 11 deletions
This file was deleted.

‎public/net-operator.js‎

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
const escape = (value) => String(value ?? '').replace(/[&<>"']/g, (c) => ({
2+
'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;',
3+
}[c]));
4+
5+
const request = async (path, options = {}) => {
6+
const response = await fetch(path, {
7+
...options,
8+
headers: { accept: 'application/json', ...(options.body ? { 'content-type': 'application/json' } : {}), ...options.headers },
9+
});
10+
const data = await response.json().catch(() => ({}));
11+
if (!response.ok) throw new Error(data?.error?.message || data?.error || `Request failed (${response.status})`);
12+
return data;
13+
};
14+
15+
const setStatus = (form, message, isError = false) => {
16+
const status = form.querySelector('[data-status]');
17+
if (!status) return;
18+
status.textContent = message;
19+
status.classList.toggle('net-error', isError);
20+
};
21+
22+
async function refresh() {
23+
const data = await request('/api/net/v1/operator/overview');
24+
const queue = document.querySelector('#net-queue');
25+
const items = [
26+
...data.queue.namespaces.map((item) => ({ kind: 'namespace', subject: `.${item.tld}`, owner: item.owner, date: item.createdAt, details: JSON.stringify(item.policy) })),
27+
...data.queue.names.map((item) => ({ kind: 'name', subject: item.name, owner: item.owner, date: item.createdAt, details: item.target || 'No HTTPS target supplied.' })),
28+
];
29+
queue.innerHTML = items.length ? items.map((item) => `<article><strong>${escape(item.subject)}</strong><p class="net-row-meta">${escape(item.kind)} · account ${escape(item.owner)} · ${escape(item.date)}</p><p>${escape(item.details)}</p><div class="net-actions"><button class="button primary" data-moderate="approve" data-kind="${escape(item.kind)}" data-subject="${escape(item.subject)}">Approve</button><button class="button" data-moderate="reject" data-kind="${escape(item.kind)}" data-subject="${escape(item.subject)}">Reject</button></div></article>`).join('') : '<p class="muted">No registrations are waiting for review.</p>';
30+
31+
const managed = document.querySelector('#net-managed');
32+
const active = [
33+
...data.managed.namespaces.map((item) => ({ kind: 'namespace', subject: `.${item.tld}`, status: item.status, owner: item.owner, edge: data.hostedTlds.includes(item.tld) ? 'DNS/TLS ready' : 'DNS/TLS setup required' })),
34+
...data.managed.names.map((item) => ({ kind: 'name', subject: item.name, status: item.status, owner: item.owner })),
35+
];
36+
managed.innerHTML = active.length ? active.map((item) => `<article><strong>${escape(item.subject)}</strong><p class="net-row-meta">${escape(item.kind)} · ${escape(item.status)} · account ${escape(item.owner || 'operator seeded')}${item.edge ? ` · ${escape(item.edge)}` : ''}</p><div class="net-actions"><button class="button" data-moderate="${item.status === 'suspended' ? 'restore' : 'suspend'}" data-kind="${escape(item.kind)}" data-subject="${escape(item.subject)}">${item.status === 'suspended' ? 'Restore' : 'Suspend'}</button></div></article>`).join('') : '<p class="muted">No local registrations are active yet.</p>';
37+
38+
const peerList = document.querySelector('#net-peers');
39+
const peers = data.peers.map((item) => `<article class="net-row"><div><strong>${escape(item.endpoint)}</strong><p class="net-row-meta">${escape(item.kind)} · ${escape(item.status)} · sent cursor ${escape(item.cursor)} · received cursor ${escape(item.inboundCursor)} · last seen ${escape(item.lastSeenAt || 'never')}</p>${item.lastError ? `<p class="net-row-meta">Last error: ${escape(item.lastError)}</p>` : ''}</div><button class="button" data-remove-peer="${escape(item.id)}">Remove</button></article>`).join('');
40+
peerList.innerHTML = `${peers || '<p class="muted">No remote W3BS peers are opted in yet.</p>'}<article class="net-row"><div><strong>https://pit.moshcode.sh</strong><p class="net-row-meta">Moshpit · public read-only backfill source</p></div></article>`;
41+
42+
const instances = document.querySelector('#net-instances');
43+
instances.innerHTML = data.instances.length
44+
? data.instances.map((item) => `<article class="net-row"><div><strong><a class="inline-link" href="${escape(item.instance)}">${escape(item.instance)}</a></strong><p class="net-row-meta">${item.local ? 'This primary instance' : item.optedIn ? 'Opted-in peer' : 'Announced through federation'} · ${escape(item.protocol || 'announcement pending')}</p></div></article>`).join('')
45+
: '<p class="muted">No W3BS instances have announced yet.</p>';
46+
47+
const backfill = document.querySelector('#net-backfill');
48+
backfill.textContent = data.backfill.length
49+
? data.backfill.map((item) => `${item.source} · ${item.kind}: ${item.count} · updated ${item.importedAt}`).join(' | ')
50+
: 'Backfill has not started yet.';
51+
}
52+
53+
document.addEventListener('click', async (event) => {
54+
const moderate = event.target.closest('[data-moderate]');
55+
if (moderate) {
56+
moderate.disabled = true;
57+
try {
58+
await request('/api/net/v1/operator/moderate', {
59+
method: 'POST',
60+
body: JSON.stringify({ kind: moderate.dataset.kind, subject: moderate.dataset.subject, action: moderate.dataset.moderate }),
61+
});
62+
await refresh();
63+
} catch (error) {
64+
alert(error.message);
65+
moderate.disabled = false;
66+
}
67+
return;
68+
}
69+
70+
const removePeer = event.target.closest('[data-remove-peer]');
71+
if (removePeer) {
72+
removePeer.disabled = true;
73+
try {
74+
await request(`/api/net/v1/operator/peers/${encodeURIComponent(removePeer.dataset.removePeer)}`, { method: 'DELETE' });
75+
await refresh();
76+
} catch (error) {
77+
alert(error.message);
78+
removePeer.disabled = false;
79+
}
80+
}
81+
});
82+
83+
for (const [id, endpoint] of [
84+
['net-tld-form', '/api/net/v1/tlds'],
85+
['net-name-form', '/api/net/v1/names'],
86+
]) {
87+
const form = document.getElementById(id);
88+
form.addEventListener('submit', async (event) => {
89+
event.preventDefault();
90+
const button = form.querySelector('button[type="submit"]');
91+
button.disabled = true;
92+
const fields = new FormData(form);
93+
const payload = id === 'net-tld-form'
94+
? { tld: fields.get('tld'), open: fields.get('open') === '1' }
95+
: { name: fields.get('name'), target: fields.get('target') || null };
96+
try {
97+
const result = await request(endpoint, { method: 'POST', body: JSON.stringify(payload) });
98+
setStatus(form, `${result.name || `.${result.tld}`} submitted for moderation.`);
99+
form.reset();
100+
await refresh();
101+
} catch (error) {
102+
setStatus(form, error.message, true);
103+
} finally {
104+
button.disabled = false;
105+
}
106+
});
107+
}
108+
109+
const peerForm = document.getElementById('net-peer-form');
110+
peerForm.addEventListener('submit', async (event) => {
111+
event.preventDefault();
112+
const button = peerForm.querySelector('button[type="submit"]');
113+
button.disabled = true;
114+
const fields = new FormData(peerForm);
115+
try {
116+
const result = await request('/api/net/v1/operator/peers', {
117+
method: 'POST',
118+
body: JSON.stringify({ endpoint: fields.get('endpoint'), outboundToken: fields.get('outboundToken') }),
119+
});
120+
const secret = document.getElementById('net-peer-secret');
121+
secret.hidden = false;
122+
secret.innerHTML = `<p>Send this one-time inbound token to ${escape(result.endpoint)} and have them configure it as their outbound token:</p><code class="net-code">${escape(result.inboundToken)}</code>`;
123+
setStatus(peerForm, 'Peer opted in; existing W3BS announcements are being backfilled.');
124+
peerForm.reset();
125+
await refresh();
126+
} catch (error) {
127+
setStatus(peerForm, error.message, true);
128+
} finally {
129+
button.disabled = false;
130+
}
131+
});
132+
133+
document.getElementById('net-backfill-now').addEventListener('click', async (event) => {
134+
const button = event.currentTarget;
135+
button.disabled = true;
136+
try {
137+
await request('/api/net/v1/operator/backfill', { method: 'POST', body: '{}' });
138+
document.getElementById('net-backfill').textContent = 'Moshpit backfill is running. It will continue in bounded chunks.';
139+
} catch (error) {
140+
document.getElementById('net-backfill').textContent = error.message;
141+
} finally {
142+
button.disabled = false;
143+
}
144+
});
145+
146+
refresh().catch((error) => {
147+
document.querySelector('#net-queue').textContent = error.message;
148+
document.querySelector('#net-peers').textContent = error.message;
149+
document.querySelector('#net-instances').textContent = error.message;
150+
document.querySelector('#net-backfill').textContent = error.message;
151+
});
152+
setInterval(() => refresh().catch(() => {}), 15_000);

‎public/net-register.js‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const send = async (path, body) => {
2+
const response = await fetch(path, {
3+
method: 'POST',
4+
headers: { accept: 'application/json', 'content-type': 'application/json' },
5+
body: JSON.stringify(body),
6+
});
7+
const data = await response.json().catch(() => ({}));
8+
if (!response.ok) throw new Error(data?.error?.message || `Request failed (${response.status})`);
9+
return data;
10+
};
11+
12+
for (const [id, path] of [
13+
['net-register-tld', '/api/net/v1/tlds'],
14+
['net-register-name', '/api/net/v1/names'],
15+
]) {
16+
const form = document.getElementById(id);
17+
form.addEventListener('submit', async (event) => {
18+
event.preventDefault();
19+
const button = form.querySelector('button[type="submit"]');
20+
const status = form.querySelector('[data-status]');
21+
const fields = new FormData(form);
22+
const body = id === 'net-register-tld'
23+
? { tld: fields.get('tld'), open: fields.get('open') === '1' }
24+
: { name: fields.get('name'), target: fields.get('target') || null };
25+
button.disabled = true;
26+
status.classList.remove('net-error');
27+
try {
28+
const result = await send(path, body);
29+
status.textContent = `${result.name || `.${result.tld}`} is in the moderation queue.`;
30+
form.reset();
31+
} catch (error) {
32+
status.textContent = error.message;
33+
status.classList.add('net-error');
34+
} finally {
35+
button.disabled = false;
36+
}
37+
});
38+
}

‎public/style.css‎

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,6 +2644,114 @@ footer.pfs-footer p {
26442644
.net-policy {
26452645
margin-top: 38px;
26462646
}
2647+
.net-intro {
2648+
max-width: 850px;
2649+
}
2650+
.net-meta,
2651+
.net-row-meta {
2652+
color: var(--muted);
2653+
font-size: 13px;
2654+
}
2655+
.net-list {
2656+
display: grid;
2657+
gap: 14px;
2658+
margin: 24px 0;
2659+
}
2660+
.net-row {
2661+
display: flex;
2662+
justify-content: space-between;
2663+
align-items: center;
2664+
gap: 20px;
2665+
padding: 18px 20px;
2666+
border: 1px solid var(--line);
2667+
border-radius: 7px;
2668+
}
2669+
.net-row h3 {
2670+
margin-bottom: 6px;
2671+
font-size: 20px;
2672+
}
2673+
.net-row p {
2674+
margin: 0;
2675+
overflow-wrap: anywhere;
2676+
}
2677+
.net-block {
2678+
margin: 28px 0;
2679+
padding: 24px;
2680+
border: 1px solid var(--line);
2681+
border-radius: 7px;
2682+
}
2683+
.net-block h2 {
2684+
margin: 0 0 12px;
2685+
}
2686+
.net-console {
2687+
display: grid;
2688+
gap: 24px;
2689+
}
2690+
.net-console form {
2691+
display: grid;
2692+
gap: 10px;
2693+
max-width: 680px;
2694+
margin-top: 20px;
2695+
}
2696+
.net-console input:not([type='checkbox']),
2697+
.net-console select,
2698+
.net-console textarea {
2699+
width: 100%;
2700+
padding: 11px;
2701+
border: 1px solid var(--line);
2702+
border-radius: 5px;
2703+
background: var(--paper);
2704+
color: var(--ink);
2705+
}
2706+
.net-console label {
2707+
font-weight: 600;
2708+
}
2709+
.net-console small,
2710+
.net-help {
2711+
color: var(--muted);
2712+
line-height: 1.6;
2713+
}
2714+
.net-queue {
2715+
display: grid;
2716+
gap: 12px;
2717+
margin-top: 16px;
2718+
}
2719+
.net-queue article {
2720+
padding: 16px;
2721+
border: 1px solid var(--line);
2722+
border-radius: 7px;
2723+
}
2724+
.net-actions {
2725+
display: flex;
2726+
flex-wrap: wrap;
2727+
gap: 8px;
2728+
margin-top: 12px;
2729+
}
2730+
.net-code {
2731+
display: block;
2732+
margin-top: 8px;
2733+
padding: 12px;
2734+
border: 1px solid var(--line);
2735+
border-radius: 5px;
2736+
word-break: break-all;
2737+
}
2738+
.net-search-results {
2739+
margin: 24px 0;
2740+
}
2741+
.net-search-results h2 {
2742+
margin-bottom: 10px;
2743+
}
2744+
.net-no-sales {
2745+
border-left: 3px solid var(--orange);
2746+
padding-left: 16px;
2747+
}
2748+
.net-status {
2749+
min-height: 1.5em;
2750+
color: var(--muted);
2751+
}
2752+
.net-error {
2753+
color: var(--orange);
2754+
}
26472755
@media (max-width: 760px) {
26482756
.net-result-grid,
26492757
.net-name-grid {
@@ -2652,4 +2760,11 @@ footer.pfs-footer p {
26522760
.net-moshpit-card {
26532761
padding: 18px;
26542762
}
2763+
.net-row {
2764+
align-items: flex-start;
2765+
flex-direction: column;
2766+
}
2767+
.net-block {
2768+
padding: 18px;
2769+
}
26552770
}

0 commit comments

Comments
 (0)