js-sdk icon indicating copy to clipboard operation
js-sdk copied to clipboard

nwc: uses only a single relay from the connection string

Open f321x opened this issue 7 months ago • 5 comments

NIP-47 says:

The connection URI contains 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.

However the sdk uses only a single relay query param included in the connection string:

https://github.com/getAlby/js-sdk/blob/761d172620335f8dd22d6956f86caf15626d47ab/src/nwc/NWCClient.ts#L88

Using multiple relays encoded in the string (at least 2 or 3 if available) would increase the reliability as the connection wouldn't depend on a single relay anymore that may be down or blocks the current IP (e.g. due to VPN or Tor).

f321x avatar Apr 14 '25 19:04 f321x

Do you know which wallet uses multiple relays currently?

bumi avatar Apr 14 '25 20:04 bumi

Apparently https://github.com/michaelWuensch/BitBanana/issues/122#issuecomment-2803095020 does, however most other clients seem to just pick the first relay from the URI making it quite unreliable from time to time. If you mean the funding source, Electrum uses all configured relays to serve NWC requests when running as NWC server for example.

f321x avatar Apr 15 '25 05:04 f321x

Isn't bitbanana also a client and not a wallet?

bumi avatar Apr 15 '25 09:04 bumi

Correct, BitBanana is a client. Further more I have to add, that I call the connect function from Rust Nostr providing the full nwc connect string including all relays. I just assumed, but haven't checked that the Rust Nostr implementation does it according to specs and is capable of handling more than one relay.

michaelWuensch avatar Apr 15 '25 14:04 michaelWuensch

Yeah I wasn't sure if you were asking for client or funding source examples. In the case of funding source I only know of Electrum using multiple, but haven't looked into others.

f321x avatar Apr 15 '25 14:04 f321x