-
Notifications
You must be signed in to change notification settings - Fork 721
Add NIP 9a for push notifications #2194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
c63001a to
2c47af9
Compare
|
How do you distinguish whether a device is online or offline? Is it determined by whether there is a connection to the server? |
|
I'm going to add a |
2c47af9 to
34624f7
Compare
Yes, but on Android you have to use silent push. |
|
What is that |
|
That's the app's dedicated push server, which hold the various keys related to authenticating push notifications. Here's the flow: |
c4d74d0 to
0480065
Compare
|
Just updated the NIP to leave as much up to the client/push server as possible. Now, clients will have to talk directly to push servers to set up device tokens, which reduces the amount of information relays have. Clients can also implement client activity status directly with the push server, solving @sanah9's problem. Push servers can also serve as a central point of control, since they can return a 404 error to indicate the subscription should be deleted. |
|
We should make this a non-hex number just to make it easier on libraries that have a number type on the NIP-11 array of |
|
Relay implementations have to be updated non-trivially anyway to support it, so they might as well convert supported_nips to a string type while they're at it. |
|
Example push notifications for android without requiring a server, or third party service/app install. Just use websockets/connect to relay: Might this change how the NIP is written? |
|
I doubt it, from what I understand mobile platforms are picky about apps using background tasks because there's a necessary trade-off between keeping stuff active and battery life. Plus, this approach is a pain to implement, I was trying it earlier this week, but in capacitor you don't have access to websockets, which means you would have to write an http/websocket proxy, or write native code. It would be good if pokey could be improved to serve as a notifications hub for other nostr apps, but that comes with the UX tradeoff of users having to install another companion app. That's not a bad solution all-in-all though. I've also built anchor.coracle.social, which doesn't work at all because it has to open a separate websocket connection for each subscriber/relay combo to avoid exfiltrating data related to relay access controls. It also only approximates access by using invite codes, which means lots of content will still be inaccessible. Another alternative would be to share a bunker url pointing at the user's signer so that the push server could authenticate on the user's behalf. But this has the same problem with many websocket connections, and opens a blind signing attack vector. This push solution is good because:
The main tradeoffs are:
|
NIP-9a
Nostr Push Notifications
draftoptionalThis NIP defines a way for users to register with relays to facilitate push notifications.
Relays that implement this NIP MUST include
9ain its NIP 11supported_nips, and MUST NOT servekind 30390events to anyone except their author.To register, users may create a
kind 30390event with their notification preferences. This event MUST include the following tags:d- a random stringp- the relay's NIP 11selfpubkeyAll other tags MUST be encrypted and placed in the event's
contentfield:relay- the normalized url of the relay the event was sent tofilter- a nostr filter for matching events (may appear multiple times)callback- a URL indicating a callback url to forward events toIf a relay does not intend to fulfill the subscription, it SHOULD respond with an
OKmessage withfalseas the result and a human-readable message.Because client developers are expected to be running their own push server, any other features such as registration of device tokens, notification cancellation, or client status should be implemented directly between the client and the push server.
When a relay receives a new event, it SHOULD match it against all current registrations and forward the event to authorized users by sending a
POSTrequest to thecallbackURL withContent-Type: application/json. The payload should be as follows:If the
callbackURL responds with anything other than a200status code, the relay SHOULD delete the subscription (optionally taking into account retries, temporary downtime, etc).If a relay receives a request for
kind 30390, it should respond only with the current user's subscription events (based on NIP 42 AUTH). Clients MAY wish to sync subscription events periodically if they wish to ensure they continue receiving push notifications. Clients MAY delete subscription events as specified in NIP 09, or they may delete subscriptions with the push server directly, relying oncallbackerror responses to clean up relay subscriptions.If a relay receives a
kind 30390event not p-tagged to itself, it SHOULD NOT store it. If a relay receives akind 30390event whoserelaytag does not match the relay's own URL, the relay SHOULD discard it. However, special purpose relays MAY choose to implement this behavior on behalf of other relays that do not support this NIP.