diff --git a/README.md b/README.md index fed1651..0fdf319 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,13 @@ This JavaScript SDK for the Alby OAuth2 Wallet API and the Nostr Wallet Connect ## Installing -``` +```bash npm install @getalby/sdk ``` or -``` +```bash yarn add @getalby/sdk ``` @@ -20,21 +20,14 @@ or for use without any build tools: ```html ``` +### NodeJS + **This library relies on a global fetch() function which will work in browsers and node v18.x or newer.** (In older versions you have to use a polyfill.) ## Content @@ -45,13 +38,39 @@ or for use without any build tools: ## Nostr Wallet Connect Documentation -Nostr Wallet Connect is an open protocol enabling applications to interact with bitcoin lightning wallets. It allows users to connect their existing wallets to your application allowing developers to easily integrate bitcoin lightning functionality. +[Nostr Wallet Connect](https://nwc.dev) is an open protocol enabling applications to interact with bitcoin lightning wallets. It allows users to connect their existing wallets to your application allowing developers to easily integrate bitcoin lightning functionality. The Alby JS SDK allows you to easily integrate Nostr Wallet Connect into any JavaScript based application. -The `NostrWebLNProvider` exposes the [WebLN](webln.guide/) interface to execute lightning wallet functionality through Nostr Wallet Connect, such as sending payments, making invoices and getting the node balance. +There are two interfaces you can use to access NWC: + +- The `NWCClient` exposes the [NWC](https://nwc.dev/) interface directly, which is more powerful than the WebLN interface and is recommended if you plan to create an application outside of the web (e.g. native mobile/command line/server backend etc.). You can explore all the examples [here](./examples/nwc/client/). +- The `NostrWebLNProvider` exposes the [WebLN](https://webln.guide/) interface to execute lightning wallet functionality through Nostr Wallet Connect, such as sending payments, making invoices and getting the node balance. You can explore all the examples [here](./examples/nwc/). See also [Bitcoin Connect](https://github.com/getAlby/bitcoin-connect/) if you are developing a frontend web application. + +### NWCClient + +#### Initialization Options + +- `providerName`: name of the provider to load the default options. currently `alby` (default) +- `nostrWalletConnectUrl`: full Nostr Wallet Connect URL as defined by the [spec](https://github.com/getAlby/nips/blob/master/47.md) +- `relayUrl`: URL of the Nostr relay to be used (e.g. wss://nostr-relay.getalby.com) +- `walletPubkey`: pubkey of the Nostr Wallet Connect app +- `secret`: secret key to sign the request event (if not available window.nostr will be used) +- `authorizationUrl`: URL to the NWC interface for the user to and the app connection + +#### Quick start example + +```js +import { nwc } from "@getalby/sdk"; +const nwc = new nwc.NWCClient({ + nostrWalletConnectUrl: loadNWCUrl(), +}); // loadNWCUrl is some function to get the NWC URL from some (encrypted) storage + +// now you can send payments by passing in the invoice in an object +const response = await nwc.payInvoice({ invoice }); +``` -(Note: in the future more WebLN functions will be added to Nostr Wallet Connect) +See [the NWC client examples directory](./examples/nwc/client) for a full list of examples. ### NostrWebLNProvider (aliased as NWC) Options diff --git a/src/NWCClient.ts b/src/NWCClient.ts index 020d0d3..255c964 100644 --- a/src/NWCClient.ts +++ b/src/NWCClient.ts @@ -44,7 +44,7 @@ export type Nip47GetInfoResponse = { block_height: number; block_hash: string; methods: Nip47Method[]; - notifications: Nip47NotificationType[]; + notifications?: Nip47NotificationType[]; }; export type Nip47GetBalanceResponse = {