diff options
Diffstat (limited to 'names/server.js')
| -rw-r--r-- | names/server.js | 32 |
1 files changed, 32 insertions, 0 deletions
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(); |
