NDKNwc.fromURI always throws 'pubkey not set' in browser #285
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The
URL
constructor in the browser parses URLs differently than in node.With the current implementation of NWC in NDK, I don't see a way to get NWC working in the browser using
NdkNWC.fromURI
. I always getpubkey not set
because NDK usesinstead of
here:
ndk/ndk/src/nwc/index.ts
Lines 94 to 110 in 6b3ea8b
For example, if I use
nostr+walletconnect://
:node:
u.host
✅ |u.pathname
❌browser:
u.host
❌ |u.pathname
❌ (includes//
)If I use
nostr+walletconnect:
:node:
u.host
❌ |u.pathname
✅browser:
u.host
❌ |u.pathname
✅Since in both cases, the browser will set
u.host
to the empty string, the pubkey is never set in the browser. Using||
instead of??
fixes that at least for thenostr+walletconnect:
case.Additional context
Alby replaces the protocol with
http://
to get consistent URL parsing behavior in node and browser for any NWC prefix, see here. I recommend to do the same but I didn't want to change this code more than necessary to get it working using at least one prefix before feedback.Environment
NDK version: v2.10.5
node version: 20.18.0
Brave version: 1.62.165 Chromium: 121.0.6167.184 (Official Build) (64-bit)
Firefox version: 132.0.2 (64-bit)