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

Support multiple NWC relays #1549

Open
ekzyis opened this issue Nov 6, 2024 · 1 comment · May be fixed by #1590
Open

Support multiple NWC relays #1549

ekzyis opened this issue Nov 6, 2024 · 1 comment · May be fixed by #1590
Labels
difficulty:easy enhancement improvements to existing features wallets

Comments

@ekzyis
Copy link
Member

ekzyis commented Nov 6, 2024

Describe the problem you're trying to solve

Wallets like cashu.me include multiple relays in their NWC connection string. We currently only use the first relay.

Describe the solution you'd like

Parse all relays from NWC connection in parseNwcUrl using url.searchParams.getAll('relay') instead of url.searchParams.get('relay') and use all of them to publish requests and listen for responses.

stacker.news/lib/url.js

Lines 190 to 214 in 4cc3780

export function parseNwcUrl (walletConnectUrl) {
if (!walletConnectUrl) return {}
walletConnectUrl = walletConnectUrl
.replace('nostrwalletconnect://', 'http://')
.replace('nostr+walletconnect://', 'http://') // makes it possible to parse with URL in the different environments (browser/node/...)
// XXX There is a bug in parsing since we use the URL constructor for parsing:
// A wallet pubkey matching /^[0-9a-fA-F]{64}$/ might not be a valid hostname.
// Example: 11111111111 (10 1's) is a valid hostname (gets parsed as IPv4) but 111111111111 (11 1's) is not.
// See https://stackoverflow.com/questions/56804936/how-does-only-numbers-in-url-resolve-to-a-domain
// However, this seems to only get triggered if a wallet pubkey only contains digits so this is pretty improbable.
const url = new URL(walletConnectUrl)
const params = {}
params.walletPubkey = url.host
const secret = url.searchParams.get('secret')
const relayUrl = url.searchParams.get('relay')
if (secret) {
params.secret = secret
}
if (relayUrl) {
params.relayUrl = relayUrl
}
return params
}

Describe alternatives you've considered

No response

Additional context

Logging would become very noisy if we log all events for every relay individually like we do now for the single relay. We should consider to remove all logs inside the nwcCall function if they aren't needed. NWC is the only wallet that uses the logger inside its own functions. So maybe it's indeed not needed and we can simply rely on general wallet logs?

@ekzyis ekzyis added feature new product features that weren't there before enhancement improvements to existing features wallets and removed feature new product features that weren't there before labels Nov 6, 2024
@riccardobl riccardobl linked a pull request Nov 14, 2024 that will close this issue
4 tasks
@riccardobl
Copy link
Member

riccardobl commented Nov 14, 2024

this is the default behavior in ndk, so it should be fixed by #1590

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty:easy enhancement improvements to existing features wallets
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants