diff options
| author | Adam Soltys <[email protected]> | 2026-08-03 22:07:13 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-08-03 22:07:13 -0700 |
| commit | 1f96f513060d65c3a4e7c7cda100cde4ef8ee2c3 (patch) | |
| tree | 04bb4bae281d9255ca45f9100c6903191b5c7b74 /src/sw-nwc.js | |
| parent | dc8f4b841ff57f4ef74597c2f80b6f90b352db13 (diff) | |
| download | coinosv3-1f96f513060d65c3a4e7c7cda100cde4ef8ee2c3.tar.gz coinosv3-1f96f513060d65c3a4e7c7cda100cde4ef8ee2c3.zip | |
Only people you know get to buzz your phone
A NIP-17 wrap is signed by a throwaway key with the sender sealed under
two layers of nip44, so no server can filter DMs by who sent them. The
notifier now ships the wrap inside the push payload and the service
worker opens it locally: a message from someone you follow arrives with
their name on it, a stranger's is dropped, and your own sent-copy — every
DM is wrapped to the sender too — no longer notifies you about what you
just typed.
That needs the nostr identity key in the worker's IndexedDB, which
dm-inbox.js states plainly: for a seed-derived identity it is a second
copy of a key localStorage's seed already yields, and it exists only to
keep strangers out. A remote signer never hands its key over, so those
wallets store no secret and keep getting unfiltered notifications rather
than silence.
Silence is always the riskier failure here, so the rule leans the other
way whenever it isn't sure: a wrap we can't open notifies, an account
with no contact list published notifies (otherwise a new user's welcome
message would vanish), and anyone you already have a thread with counts
as known whether or not you follow them. The server-side DM cooldown
drops to a second — with the device discarding pushes, a throttle there
would let a discarded one swallow the message behind it.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Wvj4aoeMZwA7VUGdJP9Swi
Diffstat (limited to 'src/sw-nwc.js')
| -rw-r--r-- | src/sw-nwc.js | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/sw-nwc.js b/src/sw-nwc.js index e887963..edf1f5e 100644 --- a/src/sw-nwc.js +++ b/src/sw-nwc.js @@ -6,6 +6,7 @@ import { respondFromBg } from './nwc-respond.js'; import { bgAutoWithdraw } from './bg-autowithdraw.js'; +import { allInboxes, classifyDm, shouldNotifyDm } from './dm-inbox.js'; const NOTIFIER = 'https://nwcpush.coinos.io'; @@ -25,9 +26,22 @@ self.addEventListener('push', (e) => { try { await bgAutoWithdraw({ log: (m) => console.log('[sw-aw]', m) }); } catch (err) { console.warn('[sw-aw] failed:', err && err.message); } } + // A DM arrives wrapped, so only this device can see who sent it. Open it + // here: a message from someone we follow gets their name on it, our own + // sent-copy and a stranger's get nothing at all. Anything we can't open + // — a remote-signer wallet, an oversized wrap — falls through to the + // generic notification rather than being dropped silently. + let dmName = null; + if (data.reason === 'dm' && data.wrap) { + try { + const verdict = await classifyDm(data.wrap, await allInboxes()); + if (!shouldNotifyDm(verdict)) return; + if (verdict && verdict.name) dmName = verdict.name; + } catch (err) { console.warn('[sw-dm] could not classify:', err && err.message); } + } const T = { payment: ['Payment received', data.amountSat ? `+${Number(data.amountSat).toLocaleString()} sats — open coinos to see it.` : 'Open coinos to see it.'], - dm: ['New message', 'You have a new private message.'], + dm: dmName ? [dmName, 'sent you a message.'] : ['New message', 'You have a new private message.'], chat: ['New chat activity', 'There are new messages in your communities.'], }; const [title, body] = T[data.reason] || T.chat; |
