Skip to content

Commit

Permalink
Merge pull request #235 from getAlby/feat/parse-nwc-url-lud16
Browse files Browse the repository at this point in the history
Feat: parse nwc url lud16
  • Loading branch information
rolznz authored Sep 1, 2024
2 parents 1621456 + b49255d commit 915f269
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/webln/NWCClient.test.ts → src/NWCClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import "websocket-polyfill";
import { NWCClient } from "../NWCClient";
import { NWCClient } from "./NWCClient";

// this has no funds on it, I think ;-)
const exampleNwcUrl =
"nostr+walletconnect://69effe7b49a6dd5cf525bd0905917a5005ffe480b58eeb8e861418cf3ae760d9?relay=wss://relay.getalby.com/v1&secret=e839faf78693765b3833027fefa5a305c78f6965d0a5d2e47a3fcb25aa7cc45b";
"nostr+walletconnect://69effe7b49a6dd5cf525bd0905917a5005ffe480b58eeb8e861418cf3ae760d9?relay=wss://relay.getalby.com/v1&secret=e839faf78693765b3833027fefa5a305c78f6965d0a5d2e47a3fcb25aa7cc45b&[email protected]";

describe("parseWalletConnectUrl", () => {
test("standard protocol", () => {
Expand All @@ -15,6 +15,7 @@ describe("parseWalletConnectUrl", () => {
"e839faf78693765b3833027fefa5a305c78f6965d0a5d2e47a3fcb25aa7cc45b",
);
expect(parsed.relayUrl).toBe("wss://relay.getalby.com/v1");
expect(parsed.lud16).toBe("[email protected]");
});
test("protocol without double slash", () => {
const parsed = NWCClient.parseWalletConnectUrl(
Expand Down
5 changes: 5 additions & 0 deletions src/NWCClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export interface NWCOptions {
relayUrl: string;
walletPubkey: string;
secret?: string;
lud16?: string;
}

export class Nip47Error extends Error {
Expand Down Expand Up @@ -227,6 +228,10 @@ export class NWCClient {
if (secret) {
options.secret = secret;
}
const lud16 = url.searchParams.get("lud16");
if (lud16) {
options.lud16 = lud16;
}
return options;
}

Expand Down

0 comments on commit 915f269

Please sign in to comment.