From 74df445116e1405d50d8ca5a2ac18e1843e0863e Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Tue, 6 Feb 2024 16:27:11 +0700 Subject: [PATCH] chore: make NostrWeblnProvider NWC client public, deprecate client methods on NostrWeblnProvider --- package.json | 2 +- src/client.ts | 2 +- src/types.ts | 4 +- src/webln/NostrWeblnProvider.ts | 116 ++++++++++++++++++++++++-------- 4 files changed, 92 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index 5426139..dad9575 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@getalby/sdk", - "version": "3.2.3", + "version": "3.3.0", "description": "The SDK to integrate with Nostr Wallet Connect and the Alby API", "repository": "https://github.com/getAlby/js-sdk.git", "bugs": "https://github.com/getAlby/js-sdk/issues", diff --git a/src/client.ts b/src/client.ts index c58c4f8..ead7729 100644 --- a/src/client.ts +++ b/src/client.ts @@ -240,7 +240,7 @@ export class Client { } /** - * @deprecated please use sendBoostagramToAlbyAccount. Deprecated since v2.7.0. Will be removed in v3.0.0. + * @deprecated please use sendBoostagramToAlbyAccount. Deprecated since v2.7.0. Will be removed in v4.0.0. */ sendToAlbyAccount( args: SendBoostagramToAlbyRequestParams, diff --git a/src/types.ts b/src/types.ts index ea32871..dff06d1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -133,7 +133,7 @@ export type SendBoostagramToAlbyRequestParams = { }; /** - * @deprecated please use SendBoostagramToAlbyRequestParams + * @deprecated please use SendBoostagramToAlbyRequestParams. Deprecated since v3.2.3. Will be removed in v4.0.0. */ export type SendToAlbyRequestParams = SendBoostagramToAlbyRequestParams; @@ -230,7 +230,7 @@ export type Invoice = { } & Record; /** - * @deprecated please use NWCAuthorizationUrlOptions + * @deprecated please use NWCAuthorizationUrlOptions. Deprecated since v3.2.3. Will be removed in v4.0.0. */ export type GetNWCAuthorizationUrlOptions = NWCAuthorizationUrlOptions; diff --git a/src/webln/NostrWeblnProvider.ts b/src/webln/NostrWeblnProvider.ts index 5ba5d82..0cdf7a0 100644 --- a/src/webln/NostrWeblnProvider.ts +++ b/src/webln/NostrWeblnProvider.ts @@ -75,24 +75,42 @@ const nip47ToWeblnRequestMap: Record = { }; export class NostrWebLNProvider implements WebLNProvider, Nip07Provider { - private readonly _client: NWCClient; private _enabled = false; + readonly client: NWCClient; readonly subscribers: Record void>; + /** + * @deprecated please use client.relay. Deprecated since v3.2.3. Will be removed in v4.0.0. + */ get relay(): Relay { - return this._client.relay; + console.warn("relay is deprecated. Please use client.relay instead."); + return this.client.relay; } + /** + * @deprecated please use client.relayUrl. Deprecated since v3.2.3. Will be removed in v4.0.0. + */ get relayUrl(): string { - return this._client.relayUrl; + console.warn("relayUrl is deprecated. Please use client.relayUrl instead."); + return this.client.relayUrl; } + /** + * @deprecated please use client.walletPubkey. Deprecated since v3.2.3. Will be removed in v4.0.0. + */ get walletPubkey(): string { - return this._client.walletPubkey; + console.warn( + "walletPubkey is deprecated. Please use client.walletPubkey instead.", + ); + return this.client.walletPubkey; } get options(): NostrWebLNOptions { - return this._client.options; + return this.client.options; } + /** + * @deprecated please use client.secret. Deprecated since v3.2.3. Will be removed in v4.0.0. + */ get secret(): string | undefined { - return this._client.secret; + console.warn("secret is deprecated. Please use client.secret instead."); + return this.client.secret; } static withNewSecret( @@ -104,7 +122,7 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider { } constructor(options?: NewNWCClientOptions) { - this._client = new NWCClient(options); + this.client = new NWCClient(options); this.subscribers = {}; } @@ -121,31 +139,55 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider { } getNostrWalletConnectUrl(includeSecret = true) { - return this._client.getNostrWalletConnectUrl(includeSecret); + return this.client.getNostrWalletConnectUrl(includeSecret); } + /** + * @deprecated please use client.nostrWalletConnectUrl. Deprecated since v3.2.3. Will be removed in v4.0.0. + */ get nostrWalletConnectUrl() { - return this._client.nostrWalletConnectUrl; + console.warn( + "nostrWalletConnectUrl is deprecated. Please use client.nostrWalletConnectUrl instead.", + ); + return this.client.nostrWalletConnectUrl; } + /** + * @deprecated please use client.connected. Deprecated since v3.2.3. Will be removed in v4.0.0. + */ get connected() { - return this._client.connected; + console.warn( + "connected is deprecated. Please use client.connected instead.", + ); + return this.client.connected; } + /** + * @deprecated please use getPublicKey(). Deprecated since v3.2.3. Will be removed in v4.0.0. + */ get publicKey() { - return this._client.publicKey; + console.warn( + "publicKey is deprecated. Please use client.publicKey instead.", + ); + return this.client.publicKey; } getPublicKey(): Promise { - return this._client.getPublicKey(); + return this.client.getPublicKey(); } signEvent(event: UnsignedEvent): Promise { - return this._client.signEvent(event); + return this.client.signEvent(event); } + /** + * @deprecated please use client.getEventHash. Deprecated since v3.2.3. Will be removed in v4.0.0. + */ getEventHash(event: Event) { - return this._client.getEventHash(event); + console.warn( + "getEventHash is deprecated. Please use client.getEventHash instead.", + ); + return this.client.getEventHash(event); } async enable() { @@ -153,23 +195,41 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider { } close() { - return this._client.close(); + return this.client.close(); } + /** + * @deprecated please use client.encrypt. Deprecated since v3.2.3. Will be removed in v4.0.0. + */ async encrypt(pubkey: string, content: string) { - return this._client.encrypt(pubkey, content); + console.warn("encrypt is deprecated. Please use client.encrypt instead."); + return this.client.encrypt(pubkey, content); } + /** + * @deprecated please use client.decrypt. Deprecated since v3.2.3. Will be removed in v4.0.0. + */ async decrypt(pubkey: string, content: string) { - return this._client.decrypt(pubkey, content); + console.warn("decrypt is deprecated. Please use client.decrypt instead."); + return this.client.decrypt(pubkey, content); } + /** + * @deprecated please use client.getAuthorizationUrl. Deprecated since v3.2.3. Will be removed in v4.0.0. + */ getAuthorizationUrl(options?: NWCAuthorizationUrlOptions) { - return this._client.getAuthorizationUrl(options); + console.warn( + "getAuthorizationUrl is deprecated. Please use client.getAuthorizationUrl instead.", + ); + return this.client.getAuthorizationUrl(options); } + /** + * @deprecated please use client.initNWC. Deprecated since v3.2.3. Will be removed in v4.0.0. + */ initNWC(options: NWCAuthorizationUrlOptions = {}) { - return this._client.initNWC(options); + console.warn("initNWC is deprecated. Please use client.initNWC instead."); + return this.client.initNWC(options); } async getInfo(): Promise { @@ -179,7 +239,7 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider { const version = "Alby JS SDK"; try { - const nip47Result = await this._client.getInfo(); + const nip47Result = await this.client.getInfo(); const result = { methods: nip47Result.methods.map( @@ -210,7 +270,7 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider { async getBalance(): Promise { await this.checkEnabled(); - const nip47Result = await this._client.getBalance(); + const nip47Result = await this.client.getBalance(); const result = { // NWC uses msats - convert to sats for webln @@ -224,7 +284,7 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider { async sendPayment(invoice: string): Promise { await this.checkEnabled(); - const nip47Result = await this._client.payInvoice({ invoice }); + const nip47Result = await this.client.payInvoice({ invoice }); const result = { preimage: nip47Result.preimage }; this.notify("sendPayment", result); @@ -235,7 +295,7 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider { async keysend(args: KeysendArgs): Promise { await this.checkEnabled(); - const nip47Result = await this._client.payKeysend( + const nip47Result = await this.client.payKeysend( mapKeysendToNip47Keysend(args), ); @@ -258,7 +318,7 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider { throw new Error("No amount specified"); } - const nip47Result = await this._client.makeInvoice({ + const nip47Result = await this.client.makeInvoice({ amount: amount * 1000, // NIP-47 uses msat description: requestInvoiceArgs?.defaultMemo, // TODO: support additional fields below @@ -276,7 +336,7 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider { async lookupInvoice(args: LookupInvoiceArgs): Promise { await this.checkEnabled(); - const nip47Result = await this._client.lookupInvoice({ + const nip47Result = await this.client.lookupInvoice({ invoice: args.paymentRequest, payment_hash: args.paymentHash, }); @@ -297,7 +357,7 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider { ): Promise { await this.checkEnabled(); - const nip47Result = await this._client.listTransactions(args); + const nip47Result = await this.client.listTransactions(args); const result = { transactions: nip47Result.transactions.map( @@ -316,7 +376,7 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider { ): Promise { await this.checkEnabled(); - const nip47Result = await this._client.multiPayInvoice({ + const nip47Result = await this.client.multiPayInvoice({ invoices: paymentRequests.map((paymentRequest, index) => ({ invoice: paymentRequest, id: index.toString(), @@ -347,7 +407,7 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider { async multiKeysend(keysends: KeysendArgs[]): Promise { await this.checkEnabled(); - const nip47Result = await this._client.multiPayKeysend({ + const nip47Result = await this.client.multiPayKeysend({ keysends: keysends.map((keysend, index) => ({ ...mapKeysendToNip47Keysend(keysend), id: index.toString(),