NIP-9a: Nostr Relay Push
NIP-9a
Nostr Relay Push
draft optional
This NIP defines a way for users to ask relays to push events to other servers.
To register a push subscription, users may create a kind 30390 event. This event defines the following tags:
d- a random stringrelay- a nostr relay URL to monitor (may appear multiple times)filter- a nostr filter for matching events (may appear multiple times)ignore- an nostr filter for ignoring matched events (optional, may appear multiple times)callback- a URL indicating a callback url to forward events toinclude_event- if included, relays MUST agree to include the completeeventdata in the push payload or reject the subscriptionignore_self- if included, relays SHOULD NOT push events received over a connection authenticated as the subscription author with [NIP 42](nostr:naddr1qvzqqqrcvypzq2eeknl7v2fnm7tsuxfkds3vrcyjl9fls070a465urcy6k3mgk0eqqrxu6ts956ryv4r3t9)
If a relay does not intend to fulfill the subscription, it SHOULD respond with an OK message with false as the result and a human-readable message.
Before accepting a subscription, relays MUST verify the callback by sending it a GET request with a random challenge query parameter appended. Relays MUST reject the subscription unless the response has a 2xx status code and a body that is exactly the challenge value.
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 POST request to the callback URL with Content-Type: application/json. The payload should be as follows:
{
id: string // The event's id
relay: string // The normalized url of the relay where the event was received
event?: Event // The event itself, if the subscription specifies `include_event`
}If the callback URL responds with a 404 status code, the relay SHOULD delete the subscription.
Miscellaneous recommendations
- Relays MAY delete subscriptions at their discretion (e.g. due to expiration, inactivity, callback
500errors, etc). - Clients MAY delete subscription events as specified in [NIP 09](nostr:naddr1qvzqqqrcvypzq2eeknl7v2fnm7tsuxfkds3vrcyjl9fls070a465urcy6k3mgk0eqqrxu6ts95crjpl6tec).
- Clients SHOULD re-sync subscription events periodically to ensure they continue receiving push notifications.
- If a relay receives a
kind 30390event whoserelaytag does not match the relay's own URL, the relay SHOULD discard it. - Relays that implement this NIP MUST include
9ain its [NIP 11](nostr:naddr1qqrxu6ts95cnzq3q9vumfllx9yeal9cwrymxcgkpuzf0j5lc8l876a2wpuzdtga5t8usxpqqqpuxzgedygu)supported_nips. - Relays MUST serve
kind 30390events only to their author. - Clients MUST NOT send
kind 30390events to relays that do not advertise support for this NIP.
Example: Push Notifications
This NIP may be used to facilitate push notifications sent over FCM, APN, VAPID, or other types of server. To do so, a client developer can register device tokens with their own server, returning a callback to the client. The client can then construct kind 30390 events signed by the user containing the callback to relays they want to get notifications from:
{
kind: 30390,
pubkey: "<user pubkey>",
content: "",
tags: [
["d", "<subscription id>"],
["relay", "wss://relay.example.com/"],
["filter", "{\"kinds\": [1], \"#p\": [\"<user pubkey>\"]}"],
["ignore", "{\"#t\": [\"footstr\"]}"],
["callback", "https://my-callback.example.com/<subscription-id>"]
],
}When the subscription is no longer needed, clients can delete subscription events or cancel the subscription with the push server directly, relying on the server to return a 404 to relays sending events.