@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.
Files changed (54) hide show
  1. package/README.md +25 -18
  2. package/dist/cjs/bolt11.cjs +1250 -0
  3. package/dist/cjs/bolt11.cjs.map +1 -0
  4. package/dist/cjs/fiat.cjs +57 -0
  5. package/dist/cjs/fiat.cjs.map +1 -0
  6. package/dist/cjs/index.cjs +1818 -0
  7. package/dist/cjs/index.cjs.map +1 -0
  8. package/dist/cjs/l402.cjs +89 -0
  9. package/dist/cjs/l402.cjs.map +1 -0
  10. package/dist/cjs/lnurl.cjs +1674 -0
  11. package/dist/cjs/lnurl.cjs.map +1 -0
  12. package/dist/cjs/podcasting2.cjs +32 -0
  13. package/dist/cjs/podcasting2.cjs.map +1 -0
  14. package/dist/esm/bolt11.js +1246 -0
  15. package/dist/esm/bolt11.js.map +1 -0
  16. package/dist/esm/fiat.js +51 -0
  17. package/dist/esm/fiat.js.map +1 -0
  18. package/dist/esm/index.js +1792 -0
  19. package/dist/esm/index.js.map +1 -0
  20. package/dist/esm/l402.js +84 -0
  21. package/dist/esm/l402.js.map +1 -0
  22. package/dist/esm/lnurl.js +1661 -0
  23. package/dist/esm/lnurl.js.map +1 -0
  24. package/dist/esm/podcasting2.js +30 -0
  25. package/dist/esm/podcasting2.js.map +1 -0
  26. package/dist/lightning-tools.umd.js +5 -0
  27. package/dist/lightning-tools.umd.js.map +1 -0
  28. package/dist/types/bolt11.d.ts +46 -0
  29. package/dist/types/fiat.d.ts +24 -0
  30. package/dist/types/index.d.ts +284 -0
  31. package/dist/types/l402.d.ts +27 -0
  32. package/dist/types/lnurl.d.ts +211 -0
  33. package/dist/{podcasting2/types.d.ts → types/podcasting2.d.ts} +11 -4
  34. package/package.json +51 -17
  35. package/dist/bolt11/Invoice.d.ts +0 -19
  36. package/dist/bolt11/index.d.ts +0 -3
  37. package/dist/bolt11/types.d.ts +0 -14
  38. package/dist/bolt11/utils.d.ts +0 -10
  39. package/dist/fiat/fiat.d.ts +0 -14
  40. package/dist/fiat/index.d.ts +0 -1
  41. package/dist/index.cjs +0 -1
  42. package/dist/index.d.ts +0 -7
  43. package/dist/index.modern.js +0 -1
  44. package/dist/index.module.js +0 -1
  45. package/dist/index.umd.js +0 -1
  46. package/dist/l402/index.d.ts +0 -2
  47. package/dist/l402/l402.d.ts +0 -6
  48. package/dist/l402/utils.d.ts +0 -12
  49. package/dist/lnurl/LightningAddress.d.ts +0 -44
  50. package/dist/lnurl/index.d.ts +0 -3
  51. package/dist/lnurl/types.d.ts +0 -104
  52. package/dist/lnurl/utils.d.ts +0 -14
  53. package/dist/podcasting2/boostagrams.d.ts +0 -2
  54. 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
- ## 🚀 Quick Start
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 convenenice method:
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
- const { Invoice } = require("alby-tools");
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 { webln } from "@getalby/sdk";
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 webln.NostrWebLNProvider({
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 { l402 } from "@getalby/lightning-tools";
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 l402.fetchWithL402(
225
+ await fetchWithL402(
223
226
  "https://lsat-weather-api.getalby.repl.co/kigali",
224
227
  {},
225
- { store: new l402.storage.NoStorage() },
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
- const { Invoice } = require("alby-tools");
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({