From f8c9efa8d1fab36ded9fa525c0ed56cd16ae5345 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 10 Nov 2026 15:09:20 -0700 Subject: names: delete my account. "someone's asking for a way to delete their v3 account. we allowed that in v2. i guess we'd want to free up the name once the deletion is done and remove any records we have on them on the server" (Adam, 2026-11-10). POST /account/delete, NIP-98 signed: the signer's account is its key, the names it owns or manages, and those names' other key (a login identity's name is kept by its wallet's key). Everything filed under them goes: the names (DNS record, node offer), custom offers, POS tokens and sales, hats and hat invoices, the welcome mark, Lightning receipts, migration grants (which would otherwise keep the name reserved for the key that left), queued webhooks, closed and never-funded withdraw links. Then the notifier is told (POST /forget with the shared notify token): the devices registered to be told about those keys lose their registrations, NWC wakes included, and the keys' scheduled posts are dropped. Money is never deleted: while sats are queued, parked or in flight to them, or an open withdraw link of theirs still holds some, the answer is 409 "funds" with the amounts; { check: true } asks without doing. Kept: what stops a payment being made twice (delivered, withdrawPaid, inflight) and the unpaid-invoice map, which ages out in a week. names/forget.js + forget.test.js; run against both real services on throwaway state Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01VMan6V74NSFWZtNtgCfokN --- names/server.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'names/server.js') diff --git a/names/server.js b/names/server.js index 6336e2b..4d497c5 100644 --- a/names/server.js +++ b/names/server.js @@ -36,6 +36,7 @@ import { decodeOffer } from '../coinosv3/src/bolt12.js'; import { registrationIdentity } from './ownership.js'; import { openStore } from './store.js'; import { withdrawService } from './withdraw.js'; +import { accountOf, accountBlockers, forgetAccount } from './forget.js'; const CFG = JSON.parse(readFileSync(process.env.NAMES_CONFIG || join(import.meta.dir, 'config.json'), 'utf8')); @@ -2240,6 +2241,37 @@ Bun.serve({ return json({ ok: true, webhook: { url: rawUrl, secret: secret || null } }); } + // Delete my account: the signer's names are freed and every record filed + // under them or their keys goes (names/forget.js). Refused while sats are + // still on their way to them or held in a withdraw link of theirs. + // { check: true } only reports what would happen. + if (url.pathname === '/account/delete' && req.method === 'POST') { + if (!rateOk(ip)) return json({ error: 'rate limited' }, 429); + const bodyText = await req.text(); + const a = await checkNip98(req, url, bodyText); + if (a.error) return json({ error: a.error }, 401); + let body = {}; + if (bodyText) { try { body = JSON.parse(bodyText); } catch { return json({ error: 'bad body' }, 400); } } + const acct = accountOf(state, a.pubkey); + const hold = accountBlockers(state, acct); + if (body.check) return json({ names: acct.names, pendingSat: hold.pendingSat, withdrawSat: hold.withdrawSat, paying: hold.paying, blocked: hold.any }); + 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}`)); + 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) { + await fetch(`${CFG.push.url}/forget`, { + method: 'POST', headers: { 'content-type': 'application/json' }, + body: JSON.stringify({ token: CFG.push.token, pubkeys: [...acct.keys] }), + signal: AbortSignal.timeout(5000), + }).catch((e) => log(`account delete: notifier not told: ${e.message}`)); + } + log(`account deleted: ${acct.names.join(', ') || '(no name)'} ${JSON.stringify(out.removed)}`); + return json({ ok: true, names: acct.names }); + } + if (url.pathname === '/register' && req.method === 'DELETE') { if (!rateOk(ip)) return json({ error: 'rate limited' }, 429); const bodyText = await req.text(); -- cgit v1.2.3