From ec1d6b8c6da0f9e4e169f4e8f95b88133207b741 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 5 Sep 2026 21:38:09 -0700 Subject: Payment push notifications are scoped to their network, so a mainnet payment stops opening the staging PWA. The same seed derives the same nostr pubkey on mainnet and staging, so both PWAs registered push under one pubkey and the notifier — matching only by pubkey — fanned every mainnet payment out to the staging subscription too; tapping it opened staging.coinos.io. Now the client stamps its network on the push registration (pushWatch net: getNetwork()), the registrar declares its own network on the /notify call (CFG.forwarder.network), and nwcpush delivers a payment only to registrations whose net matches — with a rollout-safe fallback: a device that hasn't re-registered yet (net=null) still gets the push, and a caller that omits net still reaches everyone, so nobody goes dark mid-deploy. Deployed names + nwcpush on cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01MGzU12QrAA4G6BYGzGVdXz --- nwcpush/server.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'nwcpush/server.js') diff --git a/nwcpush/server.js b/nwcpush/server.js index 7efebb1..61cab60 100644 --- a/nwcpush/server.js +++ b/nwcpush/server.js @@ -331,9 +331,18 @@ const server = Bun.serve({ if (!CFG.notifyToken || body?.token !== CFG.notifyToken) return json({ error: 'forbidden' }, 403); const pk = body?.pubkey; if (!/^[0-9a-f]{64}$/.test(pk || '')) return json({ error: 'pubkey required' }, 400); + // Network scoping: the same pubkey exists on mainnet and staging, so a + // payment goes only to devices on its own network. A device that hasn't + // re-registered since this shipped has net=null and still gets it (so + // no one goes dark mid-rollout); once both sides send a net, mismatches + // are filtered. A caller that omits net pushes to everyone (legacy). + const wantNet = typeof body.net === 'string' ? body.net : null; let n = 0; for (const [id, r] of Object.entries(notifyRegs)) { - if ((r.ptags || []).includes(pk)) { pushNotify(id, r, 'payment', { amountSat: Number(body.amountSat) || undefined }).catch(() => {}); n++; } + if (!(r.ptags || []).includes(pk)) continue; + if (wantNet && r.net && r.net !== wantNet) continue; + pushNotify(id, r, 'payment', { amountSat: Number(body.amountSat) || undefined }).catch(() => {}); + n++; } return json({ ok: true, devices: n }); } @@ -367,6 +376,10 @@ const server = Bun.serve({ ptags: hex(body.notify.ptags, 8), authors: hex(body.notify.authors, 64), reasons, + // the network this device is on: the same seed yields the same + // pubkey on mainnet and staging, so a payment push is delivered + // only to devices on the payment's network (see /notify) + net: typeof body.notify.net === 'string' ? body.notify.net.slice(0, 16) : null, }; persist(); resubscribeNotify(); -- cgit v1.2.3