@getalby/lightning-tools 5.2.1 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -18
- package/dist/cjs/bolt11.cjs +1250 -0
- package/dist/cjs/bolt11.cjs.map +1 -0
- package/dist/cjs/fiat.cjs +57 -0
- package/dist/cjs/fiat.cjs.map +1 -0
- package/dist/cjs/index.cjs +1818 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/l402.cjs +89 -0
- package/dist/cjs/l402.cjs.map +1 -0
- package/dist/cjs/lnurl.cjs +1674 -0
- package/dist/cjs/lnurl.cjs.map +1 -0
- package/dist/cjs/podcasting2.cjs +32 -0
- package/dist/cjs/podcasting2.cjs.map +1 -0
- package/dist/esm/bolt11.js +1246 -0
- package/dist/esm/bolt11.js.map +1 -0
- package/dist/esm/fiat.js +51 -0
- package/dist/esm/fiat.js.map +1 -0
- package/dist/esm/index.js +1792 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/l402.js +84 -0
- package/dist/esm/l402.js.map +1 -0
- package/dist/esm/lnurl.js +1661 -0
- package/dist/esm/lnurl.js.map +1 -0
- package/dist/esm/podcasting2.js +30 -0
- package/dist/esm/podcasting2.js.map +1 -0
- package/dist/lightning-tools.umd.js +5 -0
- package/dist/lightning-tools.umd.js.map +1 -0
- package/dist/types/bolt11.d.ts +46 -0
- package/dist/types/fiat.d.ts +24 -0
- package/dist/types/index.d.ts +284 -0
- package/dist/types/l402.d.ts +27 -0
- package/dist/types/lnurl.d.ts +211 -0
- package/dist/{podcasting2/types.d.ts → types/podcasting2.d.ts} +11 -4
- package/package.json +51 -17
- package/dist/bolt11/Invoice.d.ts +0 -19
- package/dist/bolt11/index.d.ts +0 -3
- package/dist/bolt11/types.d.ts +0 -14
- package/dist/bolt11/utils.d.ts +0 -10
- package/dist/fiat/fiat.d.ts +0 -14
- package/dist/fiat/index.d.ts +0 -1
- package/dist/index.cjs +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.modern.js +0 -1
- package/dist/index.module.js +0 -1
- package/dist/index.umd.js +0 -1
- package/dist/l402/index.d.ts +0 -2
- package/dist/l402/l402.d.ts +0 -6
- package/dist/l402/utils.d.ts +0 -12
- package/dist/lnurl/LightningAddress.d.ts +0 -44
- package/dist/lnurl/index.d.ts +0 -3
- package/dist/lnurl/types.d.ts +0 -104
- package/dist/lnurl/utils.d.ts +0 -14
- package/dist/podcasting2/boostagrams.d.ts +0 -2
- package/dist/podcasting2/index.d.ts +0 -2
package/README.md
CHANGED
|
@@ -6,7 +6,11 @@
|
|
|
6
6
|
|
|
7
7
|
An npm package that provides useful and common tools and helpers to build lightning web applications.
|
|
8
8
|
|
|
9
|
-
## 🚀
|
|
9
|
+
## 🤖 🚀 ⚡ For Developers using Agents / LLMs / Vibe Coding
|
|
10
|
+
|
|
11
|
+
Skip the rest of this README and use the [Alby Bitcoin Payments Agent Skill](https://github.com/getAlby/alby-agent-skill) instead. It will handle the rest!
|
|
12
|
+
|
|
13
|
+
## Manual Installation
|
|
10
14
|
|
|
11
15
|
```
|
|
12
16
|
npm install @getalby/lightning-tools
|
|
@@ -44,7 +48,7 @@ or for use without any build tools:
|
|
|
44
48
|
The `LightningAddress` class provides helpers to work with lightning addresses
|
|
45
49
|
|
|
46
50
|
```js
|
|
47
|
-
import { LightningAddress } from "@getalby/lightning-tools";
|
|
51
|
+
import { LightningAddress } from "@getalby/lightning-tools/lnurl";
|
|
48
52
|
|
|
49
53
|
const ln = new LightningAddress("hello@getalby.com");
|
|
50
54
|
|
|
@@ -60,7 +64,7 @@ console.log(ln.keysendData);
|
|
|
60
64
|
#### Get an invoice:
|
|
61
65
|
|
|
62
66
|
```js
|
|
63
|
-
import { LightningAddress } from "@getalby/lightning-tools";
|
|
67
|
+
import { LightningAddress } from "@getalby/lightning-tools/lnurl";
|
|
64
68
|
|
|
65
69
|
const ln = new LightningAddress("hello@getalby.com");
|
|
66
70
|
|
|
@@ -76,7 +80,7 @@ console.log(invoice.paymentHash); // print the payment hash
|
|
|
76
80
|
#### Verify a payment
|
|
77
81
|
|
|
78
82
|
```js
|
|
79
|
-
import { LightningAddress } from "@getalby/lightning-tools";
|
|
83
|
+
import { LightningAddress } from "@getalby/lightning-tools/lnurl";
|
|
80
84
|
const ln = new LightningAddress("hello@getalby.com");
|
|
81
85
|
await ln.fetch();
|
|
82
86
|
|
|
@@ -96,14 +100,14 @@ if (paid) {
|
|
|
96
100
|
console.log("paid");
|
|
97
101
|
}
|
|
98
102
|
|
|
99
|
-
// or use the
|
|
103
|
+
// or use the convenient method:
|
|
100
104
|
await invoice.isPaid();
|
|
101
105
|
```
|
|
102
106
|
|
|
103
107
|
It is also possible to manually initialize the `Invoice`
|
|
104
108
|
|
|
105
109
|
```js
|
|
106
|
-
|
|
110
|
+
import { Invoice } from "@getalby/lightning-tools/bolt11";
|
|
107
111
|
|
|
108
112
|
const invoice = new Invoice({ pr: pr, preimage: preimage });
|
|
109
113
|
await invoice.isPaid();
|
|
@@ -114,7 +118,7 @@ await invoice.isPaid();
|
|
|
114
118
|
You can also attach additional metadata information like app name, version, name of the podcast which is boosted etc. to the keysend payment.
|
|
115
119
|
|
|
116
120
|
```js
|
|
117
|
-
import { LightningAddress } from "@getalby/lightning-tools";
|
|
121
|
+
import { LightningAddress } from "@getalby/lightning-tools/lnurl";
|
|
118
122
|
const ln = new LightningAddress("hello@getalby.com");
|
|
119
123
|
await ln.fetch();
|
|
120
124
|
|
|
@@ -141,7 +145,7 @@ Nostr is a simple, open protocol that enables truly censorship-resistant and glo
|
|
|
141
145
|
This librarys provides helpers to create [zaps](https://github.com/nostr-protocol/nips/blob/master/57.md).
|
|
142
146
|
|
|
143
147
|
```js
|
|
144
|
-
import { LightningAddress } from "@getalby/lightning-tools";
|
|
148
|
+
import { LightningAddress } from "@getalby/lightning-tools/lnurl";
|
|
145
149
|
const ln = new LightningAddress("hello@getalby.com");
|
|
146
150
|
await ln.fetch();
|
|
147
151
|
|
|
@@ -182,7 +186,7 @@ This library includes a `fetchWithL402` function to consume L402 protected resou
|
|
|
182
186
|
##### Examples
|
|
183
187
|
|
|
184
188
|
```js
|
|
185
|
-
import { fetchWithL402 } from "@getalby/lightning-tools";
|
|
189
|
+
import { fetchWithL402 } from "@getalby/lightning-tools/l402";
|
|
186
190
|
|
|
187
191
|
// this will fetch the resource and pay the invoice with window.webln.
|
|
188
192
|
// the tokens/preimage data will be stored in the browser's localStorage and used for any following request
|
|
@@ -196,11 +200,11 @@ await fetchWithL402(
|
|
|
196
200
|
```
|
|
197
201
|
|
|
198
202
|
```js
|
|
199
|
-
import { fetchWithL402 } from "@getalby/lightning-tools";
|
|
200
|
-
import {
|
|
203
|
+
import { fetchWithL402 } from "@getalby/lightning-tools/l402";
|
|
204
|
+
import { NostrWebLNProvider } from "@getalby/sdk";
|
|
201
205
|
|
|
202
206
|
// use a NWC WebLN provide to do the payments
|
|
203
|
-
const nwc = new
|
|
207
|
+
const nwc = new NostrWebLNProvider({
|
|
204
208
|
nostrWalletConnectUrl: loadNWCUrl(),
|
|
205
209
|
});
|
|
206
210
|
|
|
@@ -215,14 +219,13 @@ await fetchWithL402(
|
|
|
215
219
|
```
|
|
216
220
|
|
|
217
221
|
```js
|
|
218
|
-
import {
|
|
219
|
-
import { fiat } from "@getalby/lightning-tools";
|
|
222
|
+
import { fetchWithL402, NoStorage } from "@getalby/lightning-tools/l402";
|
|
220
223
|
|
|
221
224
|
// do not store the tokens
|
|
222
|
-
await
|
|
225
|
+
await fetchWithL402(
|
|
223
226
|
"https://lsat-weather-api.getalby.repl.co/kigali",
|
|
224
227
|
{},
|
|
225
|
-
{ store: new
|
|
228
|
+
{ store: new NoStorage() },
|
|
226
229
|
);
|
|
227
230
|
```
|
|
228
231
|
|
|
@@ -231,10 +234,9 @@ await l402.fetchWithL402(
|
|
|
231
234
|
You can initialize an `Invoice` to decode a payment request.
|
|
232
235
|
|
|
233
236
|
```js
|
|
234
|
-
|
|
237
|
+
import { Invoice } from "@getalby/lightning-tools/bolt11";
|
|
235
238
|
|
|
236
239
|
const invoice = new Invoice({ pr });
|
|
237
|
-
|
|
238
240
|
const { paymentHash, satoshi, description, createdDate, expiryDate } = invoice;
|
|
239
241
|
```
|
|
240
242
|
|
|
@@ -244,6 +246,10 @@ const { paymentHash, satoshi, description, createdDate, expiryDate } = invoice;
|
|
|
244
246
|
|
|
245
247
|
Helpers to convert sats values to fiat and fiat values to sats.
|
|
246
248
|
|
|
249
|
+
##### getFiatCurrencies(): Promise<FiatCurrency[]>
|
|
250
|
+
|
|
251
|
+
Returns the list of available fiat currencies sorted by priority
|
|
252
|
+
|
|
247
253
|
##### getFiatValue(satoshi: number, currency: string): number
|
|
248
254
|
|
|
249
255
|
Returns the fiat value for a specified currency of a satoshi amount
|
|
@@ -259,6 +265,7 @@ Like `getFiatValue` but returns a formatted string for a given locale using Java
|
|
|
259
265
|
#### Examples
|
|
260
266
|
|
|
261
267
|
```js
|
|
268
|
+
await fiat.getFiatCurrencies();
|
|
262
269
|
await fiat.getFiatValue({ satoshi: 2100, currency: "eur" });
|
|
263
270
|
await fiat.getSatoshiValue({ amount: 100, currency: "eur" }); // for 1 EUR
|
|
264
271
|
await fiat.getFormattedFiatValue({
|