Skip to content

Commit 9e6c9ab

Browse files
authored
Merge pull request #176 from getAlby/fix/nwc-authorization-url-request-methods
fix: allow choosing request methods in authorization url
2 parents 4710871 + 3c4bffb commit 9e6c9ab

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@getalby/sdk",
3-
"version": "3.2.2",
3+
"version": "3.2.3",
44
"description": "The SDK to integrate with Nostr Wallet Connect and the Alby API",
55
"repository": "https://github.com/getAlby/js-sdk.git",
66
"bugs": "https://github.com/getAlby/js-sdk/issues",

src/types.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,14 @@ export type Invoice = {
229229
};
230230
} & Record<string, unknown>;
231231

232-
export type GetNWCAuthorizationUrlOptions = {
232+
/**
233+
* @deprecated please use NWCAuthorizationUrlOptions
234+
*/
235+
export type GetNWCAuthorizationUrlOptions = NWCAuthorizationUrlOptions;
236+
237+
export type NWCAuthorizationUrlOptions = {
233238
name?: string;
239+
requestMethods?: string[];
234240
returnTo?: string;
235241
expiresAt?: Date;
236242
maxAmount?: number;

src/webln/NostrWeblnProvider.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ describe("isValidAmount", () => {
1515
maxAmount: 100,
1616
name: "TestApp",
1717
returnTo: "https://example.com",
18+
requestMethods: ["pay_invoice", "get_balance"],
1819
})
1920
.toString(),
2021
).toEqual(
21-
"https://nwc.getalby.com/apps/new?c=TestApp&pubkey=c5dc47856f533dad6c016b979ee3b21f83f88ae0f0058001b67a4b348339fe94&return_to=https%3A%2F%2Fexample.com&budget_renewal=weekly&expires_at=1689897600&max_amount=100&editable=false",
22+
"https://nwc.getalby.com/apps/new?name=TestApp&pubkey=c5dc47856f533dad6c016b979ee3b21f83f88ae0f0058001b67a4b348339fe94&return_to=https%3A%2F%2Fexample.com&budget_renewal=weekly&expires_at=1689897600&max_amount=100&editable=false&request_methods=pay_invoice+get_balance",
2223
);
2324
});
2425
});

src/webln/NostrWeblnProvider.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
LookupInvoiceResponse,
2626
} from "@webbtc/webln-types";
2727
import { GetInfoResponse } from "@webbtc/webln-types";
28-
import { GetNWCAuthorizationUrlOptions } from "../types";
28+
import { NWCAuthorizationUrlOptions } from "../types";
2929

3030
const NWCs: Record<string, NostrWebLNOptions> = {
3131
alby: {
@@ -439,13 +439,13 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
439439
throw new Error("Method not implemented.");
440440
}
441441

442-
getAuthorizationUrl(options?: GetNWCAuthorizationUrlOptions) {
442+
getAuthorizationUrl(options?: NWCAuthorizationUrlOptions) {
443443
if (!this.options.authorizationUrl) {
444444
throw new Error("Missing authorizationUrl option");
445445
}
446446
const url = new URL(this.options.authorizationUrl);
447447
if (options?.name) {
448-
url.searchParams.set("c", options?.name);
448+
url.searchParams.set("name", options?.name);
449449
}
450450
url.searchParams.set("pubkey", this.publicKey);
451451
if (options?.returnTo) {
@@ -468,10 +468,14 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
468468
url.searchParams.set("editable", options.editable.toString());
469469
}
470470

471+
if (options?.requestMethods) {
472+
url.searchParams.set("request_methods", options.requestMethods.join(" "));
473+
}
474+
471475
return url;
472476
}
473477

474-
initNWC(options: GetNWCAuthorizationUrlOptions = {}) {
478+
initNWC(options: NWCAuthorizationUrlOptions = {}) {
475479
// here we assume an browser context and window/document is available
476480
// we set the location.host as a default name if none is given
477481
if (!options.name) {
@@ -585,13 +589,14 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
585589
const replyTimeoutCheck = setTimeout(replyTimeout, 60000);
586590

587591
sub.on("event", async (event) => {
588-
//console.log(`Received reply event: `, event);
592+
// console.log(`Received reply event: `, event);
589593
clearTimeout(replyTimeoutCheck);
590594
sub.unsub();
591595
const decryptedContent = await this.decrypt(
592596
this.walletPubkey,
593597
event.content,
594598
);
599+
// console.log(`Decrypted content: `, decryptedContent);
595600
let response;
596601
try {
597602
response = JSON.parse(decryptedContent);

0 commit comments

Comments
 (0)