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

Can the NNoster client code use an ongoing wss connection to a nostr relay in an event loop? #63

Open
johnheenan opened this issue Sep 17, 2024 · 2 comments

Comments

@johnheenan
Copy link
Contributor

johnheenan commented Sep 17, 2024

NIP47 is implmented by the nostr plugin.

NIP47 specifes an implementation must provide a connection URI for nostr clients to use at https://github.com/nostr-protocol/nips/blob/master/47.md#theory-of-operation

I assume the conection URI is then used to build a call to the function below through a nostr relay event:

public ILightningClient? Create(string connectionString, Network network, out string? error)

I cannot find a way to determine the connection URI.

From https://github.com/nostr-protocol/nips/blob/master/47.md#nostr-wallet-connect-uri

Nostr Wallet Connect URI

client discovers wallet service by scanning a QR code, handling a deeplink or pasting in a URI.

The wallet service generates this connection URI with protocol nostr+walletconnect:// and base path it's hex-encoded pubkey with the following query string parameters:

  • relay Required. URL of the relay where the wallet service is connected and will be listening for events. May be more than one.
  • secret Required. 32-byte randomly generated hex encoded string. The client MUST use this to sign events and encrypt payloads when communicating with the wallet service.
    • Authorization does not require passing keys back and forth.
    • The user can have different keys for different applications. Keys can be revoked and created at will and have arbitrary constraints (eg. budgets).
    • The key is harder to leak since it is not shown to the user and backed up.
    • It improves privacy because the user's main key would not be linked to their payments.
  • lud16 Recommended. A lightning address that clients can use to automatically setup the lud16 field on the user's profile if they have none configured.

The client should then store this connection and use it when the user wants to perform actions like paying an invoice. Due to this NIP using ephemeral events, it is recommended to pick relays that do not close connections on inactivity to not drop events.

Example connection string

nostr+walletconnect://b889ff5b1513b641e2a139f661a661364979c5beee91842f8f0ef42ab558e9d4?relay=wss%3A%2F%2Frelay.damus.io&secret=71a8c14c1407c113601079c4302dab36460f0ccd0ad506f1f2dc73b5100e4f3c
@johnheenan johnheenan changed the title No GET request to the connection URI for NIP47 of Nostr plugin? No QR code, deeplink or URI to the connection URI for NIP47 of Nostr plugin? Sep 17, 2024
@johnheenan
Copy link
Contributor Author

Here is the answer:
https://github.com/Kukks/NNostr/blob/78753daa9c0a81adebab1b50ebea923de654036a/NNostr.Client/Protocols/NIP67.cs#L110

return (NIP47.CreateUri(e.GetPublicKey(), key,relay, lud16:payload.Lud16), payload);

NIP67 is the name @Kukks has given to code to construct the Network Wallet Connect URI. He has assigned NIP67 one nostr event kind so far: 33194.

The static function below in the same file is used for unit tests:
https://github.com/Kukks/NNostr/blob/78753daa9c0a81adebab1b50ebea923de654036a/NNostr.Client/Protocols/NIP67.cs#L40

What does this mean in practice?

I guess Kukks want an extension to NIP47 to include the wallet service can also be discovered by nostr, not just QR code, deeplink or pasting a URI.

https://github.com/Kukks/NNostr/blob/master/README.md#relay shows how to add in a nostr relay to BTCPay with the NIP67 extension.

So nostr clients that want to use NWC with BTCPay will need to generate a custom event and probably include the BTCPay server as a relay to ensure the event does not get ignored.

@johnheenan johnheenan changed the title No QR code, deeplink or URI to the connection URI for NIP47 of Nostr plugin? Can the NNoster client code use an ongoing wss connection to a nostr relay in an event loop? Sep 24, 2024
@johnheenan
Copy link
Contributor Author

johnheenan commented Sep 24, 2024

I have changed the title again to reflect comments made at #57 (comment)

Using NNoster client code, can btcpay plugins function as nostr clients through a low resource event loop waiting for events from nostr server?

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

No branches or pull requests

1 participant