diff --git a/nip47.test.ts b/nip47.test.ts index fc8fac1..2aecc67 100644 --- a/nip47.test.ts +++ b/nip47.test.ts @@ -5,6 +5,16 @@ import { decrypt } from './nip04.ts' import { NWCWalletRequest } from './kinds.ts' describe('parseConnectionString', () => { + test('returns pubkey, relay, and secret if connection string has double slash', () => { + const connectionString = + 'nostr+walletconnect://b889ff5b1513b641e2a139f661a661364979c5beee91842f8f0ef42ab558e9d4?relay=wss%3A%2F%2Frelay.damus.io&secret=71a8c14c1407c113601079c4302dab36460f0ccd0ad506f1f2dc73b5100e4f3c' + const { pubkey, relay, secret } = parseConnectionString(connectionString) + + expect(pubkey).toBe('b889ff5b1513b641e2a139f661a661364979c5beee91842f8f0ef42ab558e9d4') + expect(relay).toBe('wss://relay.damus.io') + expect(secret).toBe('71a8c14c1407c113601079c4302dab36460f0ccd0ad506f1f2dc73b5100e4f3c') + }) + test('returns pubkey, relay, and secret if connection string is valid', () => { const connectionString = 'nostr+walletconnect:b889ff5b1513b641e2a139f661a661364979c5beee91842f8f0ef42ab558e9d4?relay=wss%3A%2F%2Frelay.damus.io&secret=71a8c14c1407c113601079c4302dab36460f0ccd0ad506f1f2dc73b5100e4f3c' diff --git a/nip47.ts b/nip47.ts index 55f7892..c5fe461 100644 --- a/nip47.ts +++ b/nip47.ts @@ -9,8 +9,8 @@ interface NWCConnection { } export function parseConnectionString(connectionString: string): NWCConnection { - const { pathname, searchParams } = new URL(connectionString) - const pubkey = pathname + const { host, pathname, searchParams } = new URL(connectionString) + const pubkey = pathname || host const relay = searchParams.get('relay') const secret = searchParams.get('secret')