Skip to content
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

NIP-47 notifications #1164

Merged

Conversation

rolznz
Copy link
Contributor

@rolznz rolznz commented Apr 6, 2024

This allows the wallet service to asynchronously send notifications to connected clients as an alternative to polling.

Example usecases:

  • Realtime balance, invoice status, and transaction list updates

Currently two notification types are defined - payment_received and payment_sent.

This has been implemented in:

There are also some minor copy updates to communicate that NWC is not just for sending payments, but a protocol for connecting apps to lightning wallets.

Currently the notification type is encrypted in the payload, similar to existing responses. The downside is that clients cannot filter notifications - they would get all or none (or would have to be filtered on the wallet service level which is currently outside the spec).

@rolznz rolznz changed the title feat: NIP-47 notifications NIP-47 notifications Apr 6, 2024
@rolznz rolznz force-pushed the feat/nip-47-notifications branch from 15f04cf to 17739eb Compare April 6, 2024 08:07
@vitorpamplona
Copy link
Collaborator

+1. Anything is better than request/response

47.md Outdated Show resolved Hide resolved
47.md Outdated

The info event should be a replaceable event that is published by the **wallet service** on the relay to indicate which commands it supports. The content should be
a plaintext string with the supported commands, space-separated, eg. `pay_invoice get_balance`. Only the `pay_invoice` command is described in this NIP, but other commands might be defined in different NIPs.
If the **wallet service** supports notifications, the info event SHOULD contain a `notifications` tag with the supported notification types space-separated, eg. `payment_received balance_changed`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide an event JSON example, as this isn't very clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example is given: payment_received balance_changed. It's a standard tag as per NIP-01.

However, for a full example I have fetched the info event here from my current NWC wallet (note: there's only payment_received as only one notification type is implemented so far):

{
  "id": "df467db0a9f9ec77ffe6f561811714ccaa2e26051c20f58f33c3d66d6c2b4d1c",
  "pubkey": "c04ccd5c82fc1ea3499b9c6a5c0a7ab627fbe00a0116110d4c750faeaecba1e2",
  "created_at": 1713883677,
  "kind": 13194,
  "tags": [
    [
      "notifications",
      "payment_received"
    ]
  ],
  "content": "pay_invoice pay_keysend get_balance get_info make_invoice lookup_invoice list_transactions multi_pay_invoice multi_pay_keysend sign_message notifications",
  "sig": "31f57b369459b5306a5353aa9e03be7fbde169bc881c3233625605dd12f53548179def16b9fe1137e6465d7e4d5bb27ce81fd6e75908c46b06269f4233c845d8"
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I know. I meant to add it to the spec to make it more obvious and clear for implementors.

Copy link
Contributor

@Kukks Kukks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rolznz
Copy link
Contributor Author

rolznz commented Jun 19, 2024

EDIT: Added a few new things to this PR:

  • add payment_sent notification kind
  • add notifications as an optional field in the get_info command response (because permissions can be set at an app connection level, not just the capabilities at the wallet service level)
  • appendix of example output as Kukks mentioned
  • optional fees_paid on payment command responses

@rolznz rolznz force-pushed the feat/nip-47-notifications branch from aad1941 to 32b9f3f Compare June 21, 2024 10:23
@rolznz rolznz requested a review from Kukks June 21, 2024 10:23
@Kukks
Copy link
Contributor

Kukks commented Jun 25, 2024

EDIT: Added a few new things to this PR:

  • add payment_sent notification kind
  • add notifications as an optional field in the get_info command response (because permissions can be set at an app connection level, not just the capabilities at the wallet service level)
  • appendix of example output as Kukks mentioned
  • optional fees_paid on payment command responses

Kukks/NNostr@7b7aa2e

@frnandu
Copy link

frnandu commented Sep 24, 2024

Yana just added support for these notifications in https://github.com/frnandu/yana/releases/tag/v0.15.0
Can this be merged now?

@rolznz
Copy link
Contributor Author

rolznz commented Oct 2, 2024

@fiatjaf can we merge this?

@frnandu
Copy link

frnandu commented Nov 20, 2024

@vitorpamplona could you merge it?

@vitorpamplona vitorpamplona merged commit 84aeb10 into nostr-protocol:master Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants