diff options
Diffstat (limited to 'names/server.js')
| -rw-r--r-- | names/server.js | 28 |
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(); |
