aboutsummaryrefslogtreecommitdiffstats
path: root/names/server.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-11-15 21:30:02 -0700
committerAdam Soltys <[email protected]>2026-11-15 21:30:02 -0700
commit4b222a2043ff2abc0edffe553700d5f1fe9519f7 (patch)
tree89ca531b3ce85480f2b09d065b3f319aeba6c9e9 /names/server.js
parent4aa5606408f7188a7edda5c010793f9d7d1dc076 (diff)
downloadcoinosv3-server-4b222a2043ff2abc0edffe553700d5f1fe9519f7.tar.gz
coinosv3-server-4b222a2043ff2abc0edffe553700d5f1fe9519f7.zip
BIP-353 records move to our own DNS: Knot on cs, served from ovh2. "just learned cloudflare may have a quota on how many names we can register on dns so is that going to foil our plans to give everyone a bip353 payment address?" … "yeah build it on cs don't worry about the fallback just get it working with our knot dns" (Adam, 2026-11-16). coinos.io's Cloudflare zone (Pro) was at 3,038 of its 3,500 records with one TXT per name and about 35 names claimed a day. user._bitcoin-payment.coinos.io and user._bitcoin-payment.staging.coinos.io get delegated (NS + DS in Cloudflare) to Knot DNS, so there's no record quota. The `dns` compose service on cs is the hidden primary: it signs both zones (ECDSA P-256, NSEC3 without iterations, the KSK fixed because its DS sits in Cloudflare) and listens on cs's Tailscale address only, because the house router forwards nothing to cs. ovh2 runs the public secondary (dns/secondary.conf, dns1.coinos.io), notified and transferred over Tailscale with a TSIG key, so names keep resolving while cs is down. The registrar sends RFC 2136 UPDATEs signed with TSIG hmac-sha256 over TCP (names/dns-update.js) for domains with `knot` in its config. It replaces a name's TXT RRset whole, removes it on release and on account deletion (forgetAccount now hands back the name), and deletes a name's leftover Cloudflare record as it rewrites it. names/dns-migrate.js does the one-shot moves: backfill, check, cf-cleanup. dns/README.md is the runbook. Tested against Knot 3.4.11: updates land signed, a 700-byte URI spans several TXT strings, a wrong key gets NOTAUTH and an out-of-zone name gets NOTZONE. bun test names/ passes (21, with the new dns-update tests)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VMan6SwkivduFDDkMmnXjZ
Diffstat (limited to 'names/server.js')
-rw-r--r--names/server.js28
1 files changed, 25 insertions, 3 deletions
diff --git a/names/server.js b/names/server.js
index 92e6fd8..34aae77 100644
--- a/names/server.js
+++ b/names/server.js
@@ -28,6 +28,7 @@ import { mnemonicToSeedSync } from '@scure/bip39';
import { lnBackend } from '../bridge/ln.js';
import { ArkManager } from '../coinosv3/src/ark/manager.js';
import { fetchPreview } from './preview.js';
+import { dnsUpdate } from './dns-update.js';
import { translate, translateDeepl, languages } from './translate.js';
import { decodeAddress, arkIdFromServerPubkey } from '../coinosv3/src/ark/proto.js';
import { decodeNoffer } from '../coinosv3/src/noffer.js';
@@ -87,7 +88,20 @@ const cfHeaders = {
};
const recordName = (name, domain) => `${name}.user._bitcoin-payment.${domain}`;
+// A domain with `knot` in its config keeps its BIP-353 records on our own
+// DNS server (dns/: Knot on cs, signed, served from ovh2), the subtree
+// user._bitcoin-payment.<domain> delegated there — Cloudflare's per-zone
+// record quota (3,500 on Pro) can't hold one record per name. Records are
+// replaced whole (recordId 'knot'); a Cloudflare record a name still has
+// from before is removed as it's rewritten.
+const KNOT_ID = 'knot';
+async function knotWrite(name, domain, uri, existingId) {
+ await dnsUpdate(DOMAINS[domain].knot, [{ name: recordName(name, domain), value: uri }], TTL);
+ if (existingId && existingId !== KNOT_ID) await cfDeleteRecord(domain, existingId).catch((e) => log(`old cloudflare record ${existingId} stayed: ${e.message}`));
+ return KNOT_ID;
+}
async function cfWrite(name, domain, uri, existingId) {
+ if (DOMAINS[domain]?.knot) return knotWrite(name, domain, uri, existingId);
// A domain whose config says dns: false gets no BIP-353 records: its names
// are LNURL and NIP-05 only. paff.club: every browser's tipping wallet
// claims a name there, the zone hit Cloudflare's record quota ("Record quota
@@ -113,8 +127,16 @@ async function cfWrite(name, domain, uri, existingId) {
if (!j.success) throw new Error('dns write failed: ' + JSON.stringify(j.errors).slice(0, 200));
return j.result.id;
}
-async function cfDelete(domain, recordId) {
+async function cfDelete(domain, recordId, name) {
if (!recordId) return; // a name on a domain without records (dns: false)
+ if (DOMAINS[domain]?.knot) {
+ if (name) await dnsUpdate(DOMAINS[domain].knot, [{ name: recordName(name, domain), value: null }], TTL);
+ if (recordId !== KNOT_ID) await cfDeleteRecord(domain, recordId).catch(() => {});
+ return;
+ }
+ return cfDeleteRecord(domain, recordId);
+}
+async function cfDeleteRecord(domain, recordId) {
const zoneId = DOMAINS[domain]?.zoneId;
if (!zoneId) throw new Error('unknown domain');
const r = await fetch(`${CF}/zones/${zoneId}/dns_records/${recordId}`, {
@@ -2288,7 +2310,7 @@ Bun.serve({
if (hold.any) return json({ error: 'funds', pendingSat: hold.pendingSat, withdrawSat: hold.withdrawSat, paying: hold.paying }, 409);
const out = forgetAccount(state, acct);
persist();
- for (const d of out.dns) await cfDelete(d.domain, d.recordId).catch((e) => log(`account delete: dns record ${d.recordId} stayed: ${e.message}`));
+ for (const d of out.dns) await cfDelete(d.domain, d.recordId, d.name).catch((e) => log(`account delete: dns record ${d.recordId} stayed: ${e.message}`));
if (ln) for (const id of out.offers) await ln.call('disableoffer', { offer_id: id }).catch(() => {});
// their devices' push registrations and scheduled posts, at the notifier
if (CFG.push && CFG.push.url) {
@@ -2316,7 +2338,7 @@ Bun.serve({
const existing = state.names[key];
if (!existing) return json({ error: 'unknown name' }, 404);
if (existing.pubkey !== auth.pubkey && existing.manager !== auth.pubkey) return json({ error: 'not your name' }, 403);
- await cfDelete(domain, existing.recordId).catch(() => {});
+ await cfDelete(domain, existing.recordId, name).catch(() => {});
if (existing.offerId && ln) await ln.call('disableoffer', { offer_id: existing.offerId }).catch(() => {});
delete state.names[key];
persist();