@getalby/lightning-tools 6.0.0 → 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 +10 -1
- package/dist/cjs/fiat.cjs +21 -0
- package/dist/cjs/fiat.cjs.map +1 -1
- package/dist/cjs/index.cjs +21 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/fiat.js +21 -1
- package/dist/esm/fiat.js.map +1 -1
- package/dist/esm/index.js +21 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/lightning-tools.umd.js +1 -1
- package/dist/lightning-tools.umd.js.map +1 -1
- package/dist/types/fiat.d.ts +9 -1
- package/dist/types/index.d.ts +9 -2
- package/package.json +1 -1
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
|
|
@@ -242,6 +246,10 @@ const { paymentHash, satoshi, description, createdDate, expiryDate } = invoice;
|
|
|
242
246
|
|
|
243
247
|
Helpers to convert sats values to fiat and fiat values to sats.
|
|
244
248
|
|
|
249
|
+
##### getFiatCurrencies(): Promise<FiatCurrency[]>
|
|
250
|
+
|
|
251
|
+
Returns the list of available fiat currencies sorted by priority
|
|
252
|
+
|
|
245
253
|
##### getFiatValue(satoshi: number, currency: string): number
|
|
246
254
|
|
|
247
255
|
Returns the fiat value for a specified currency of a satoshi amount
|
|
@@ -257,6 +265,7 @@ Like `getFiatValue` but returns a formatted string for a given locale using Java
|
|
|
257
265
|
#### Examples
|
|
258
266
|
|
|
259
267
|
```js
|
|
268
|
+
await fiat.getFiatCurrencies();
|
|
260
269
|
await fiat.getFiatValue({ satoshi: 2100, currency: "eur" });
|
|
261
270
|
await fiat.getSatoshiValue({ amount: 100, currency: "eur" }); // for 1 EUR
|
|
262
271
|
await fiat.getFormattedFiatValue({
|
package/dist/cjs/fiat.cjs
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const numSatsInBtc = 100000000;
|
|
4
|
+
const getFiatCurrencies = async () => {
|
|
5
|
+
const url = "https://getalby.com/api/rates";
|
|
6
|
+
const response = await fetch(url);
|
|
7
|
+
if (!response.ok) {
|
|
8
|
+
throw new Error(`Failed to fetch currencies: ${response.status} ${response.statusText}`);
|
|
9
|
+
}
|
|
10
|
+
const data = await response.json();
|
|
11
|
+
const mappedCurrencies = Object.entries(data)
|
|
12
|
+
.filter(([code]) => code.toUpperCase() !== "BTC")
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
.map(([code, details]) => ({
|
|
15
|
+
code: code.toUpperCase(),
|
|
16
|
+
name: details.name,
|
|
17
|
+
priority: details.priority,
|
|
18
|
+
symbol: details.symbol,
|
|
19
|
+
}))
|
|
20
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
21
|
+
.sort((a, b) => a.priority - b.priority);
|
|
22
|
+
return mappedCurrencies;
|
|
23
|
+
};
|
|
4
24
|
const getFiatBtcRate = async (currency) => {
|
|
5
25
|
const url = "https://getalby.com/api/rates/" + currency.toLowerCase() + ".json";
|
|
6
26
|
const response = await fetch(url);
|
|
@@ -30,6 +50,7 @@ const getFormattedFiatValue = async ({ satoshi, currency, locale, }) => {
|
|
|
30
50
|
};
|
|
31
51
|
|
|
32
52
|
exports.getFiatBtcRate = getFiatBtcRate;
|
|
53
|
+
exports.getFiatCurrencies = getFiatCurrencies;
|
|
33
54
|
exports.getFiatValue = getFiatValue;
|
|
34
55
|
exports.getFormattedFiatValue = getFormattedFiatValue;
|
|
35
56
|
exports.getSatoshiValue = getSatoshiValue;
|
package/dist/cjs/fiat.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fiat.cjs","sources":["../../src/fiat/fiat.ts"],"sourcesContent":["const numSatsInBtc = 100_000_000;\n\nexport const getFiatBtcRate = async (currency: string): Promise<number> => {\n const url =\n \"https://getalby.com/api/rates/\" + currency.toLowerCase() + \".json\";\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch rate: ${response.status} ${response.statusText}`,\n );\n }\n\n const data = await response.json();\n\n return data.rate_float / numSatsInBtc;\n};\n\nexport const getFiatValue = async ({\n satoshi,\n currency,\n}: {\n satoshi: number | string;\n currency: string;\n}) => {\n const rate = await getFiatBtcRate(currency);\n\n return Number(satoshi) * rate;\n};\n\nexport const getSatoshiValue = async ({\n amount,\n currency,\n}: {\n amount: number | string;\n currency: string;\n}) => {\n const rate = await getFiatBtcRate(currency);\n\n return Math.floor(Number(amount) / rate);\n};\n\nexport const getFormattedFiatValue = async ({\n satoshi,\n currency,\n locale,\n}: {\n satoshi: number | string;\n currency: string;\n locale: string;\n}) => {\n if (!locale) {\n locale = \"en\";\n }\n const fiatValue = await getFiatValue({ satoshi, currency });\n return fiatValue.toLocaleString(locale, {\n style: \"currency\",\n currency,\n });\n};\n"],"names":[],"mappings":";;AAAA,MAAM,YAAY,GAAG,SAAW;
|
|
1
|
+
{"version":3,"file":"fiat.cjs","sources":["../../src/fiat/fiat.ts"],"sourcesContent":["const numSatsInBtc = 100_000_000;\n\nexport interface FiatCurrency {\n code: string;\n name: string;\n symbol: string;\n priority: number;\n}\n\nexport const getFiatCurrencies = async (): Promise<FiatCurrency[]> => {\n const url = \"https://getalby.com/api/rates\";\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch currencies: ${response.status} ${response.statusText}`,\n );\n }\n\n const data = await response.json();\n const mappedCurrencies: FiatCurrency[] = Object.entries(data)\n .filter(([code]) => code.toUpperCase() !== \"BTC\")\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .map(([code, details]: any) => ({\n code: code.toUpperCase(),\n name: details.name,\n priority: details.priority,\n symbol: details.symbol,\n }))\n .sort((a, b) => a.name.localeCompare(b.name))\n .sort((a, b) => a.priority - b.priority) as FiatCurrency[];\n\n return mappedCurrencies;\n};\n\nexport const getFiatBtcRate = async (currency: string): Promise<number> => {\n const url =\n \"https://getalby.com/api/rates/\" + currency.toLowerCase() + \".json\";\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch rate: ${response.status} ${response.statusText}`,\n );\n }\n\n const data = await response.json();\n\n return data.rate_float / numSatsInBtc;\n};\n\nexport const getFiatValue = async ({\n satoshi,\n currency,\n}: {\n satoshi: number | string;\n currency: string;\n}) => {\n const rate = await getFiatBtcRate(currency);\n\n return Number(satoshi) * rate;\n};\n\nexport const getSatoshiValue = async ({\n amount,\n currency,\n}: {\n amount: number | string;\n currency: string;\n}) => {\n const rate = await getFiatBtcRate(currency);\n\n return Math.floor(Number(amount) / rate);\n};\n\nexport const getFormattedFiatValue = async ({\n satoshi,\n currency,\n locale,\n}: {\n satoshi: number | string;\n currency: string;\n locale: string;\n}) => {\n if (!locale) {\n locale = \"en\";\n }\n const fiatValue = await getFiatValue({ satoshi, currency });\n return fiatValue.toLocaleString(locale, {\n style: \"currency\",\n currency,\n });\n};\n"],"names":[],"mappings":";;AAAA,MAAM,YAAY,GAAG,SAAW;AASzB,MAAM,iBAAiB,GAAG,YAAoC;IACnE,MAAM,GAAG,GAAG,+BAA+B;AAC3C,IAAA,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC;AAEjC,IAAA,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;AAChB,QAAA,MAAM,IAAI,KAAK,CACb,CAAA,4BAAA,EAA+B,QAAQ,CAAC,MAAM,CAAA,CAAA,EA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AAEO,MAAM,YAAY,GAAG,OAAO,EACjC,OAAO,EACP,QAAQ,GAIT,KAAI;AACH,IAAA,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,QAAQ,CAAC;AAE3C,IAAA,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI;AAC/B;AAEO,MAAM,eAAe,GAAG,OAAO,EACpC,MAAM,EACN,QAAQ,GAIT,KAAI;AACH,IAAA,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,QAAQ,CAAC;IAE3C,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;AAC1C;AAEO,MAAM,qBAAqB,GAAG,OAAO,EAC1C,OAAO,EACP,QAAQ,EACR,MAAM,GAKP,KAAI;IACH,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,GAAG,IAAI;IACf;IACA,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AAC3D,IAAA,OAAO,SAAS,CAAC,cAAc,CAAC,MAAM,EAAE;AACtC,QAAA,KAAK,EAAE,UAAU;QACjB,QAAQ;AACT,KAAA,CAAC;AACJ;;;;;;;;"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1742,6 +1742,26 @@ const fetchWithL402 = async (url, fetchArgs, options) => {
|
|
|
1742
1742
|
};
|
|
1743
1743
|
|
|
1744
1744
|
const numSatsInBtc = 100000000;
|
|
1745
|
+
const getFiatCurrencies = async () => {
|
|
1746
|
+
const url = "https://getalby.com/api/rates";
|
|
1747
|
+
const response = await fetch(url);
|
|
1748
|
+
if (!response.ok) {
|
|
1749
|
+
throw new Error(`Failed to fetch currencies: ${response.status} ${response.statusText}`);
|
|
1750
|
+
}
|
|
1751
|
+
const data = await response.json();
|
|
1752
|
+
const mappedCurrencies = Object.entries(data)
|
|
1753
|
+
.filter(([code]) => code.toUpperCase() !== "BTC")
|
|
1754
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1755
|
+
.map(([code, details]) => ({
|
|
1756
|
+
code: code.toUpperCase(),
|
|
1757
|
+
name: details.name,
|
|
1758
|
+
priority: details.priority,
|
|
1759
|
+
symbol: details.symbol,
|
|
1760
|
+
}))
|
|
1761
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
1762
|
+
.sort((a, b) => a.priority - b.priority);
|
|
1763
|
+
return mappedCurrencies;
|
|
1764
|
+
};
|
|
1745
1765
|
const getFiatBtcRate = async (currency) => {
|
|
1746
1766
|
const url = "https://getalby.com/api/rates/" + currency.toLowerCase() + ".json";
|
|
1747
1767
|
const response = await fetch(url);
|
|
@@ -1782,6 +1802,7 @@ exports.fromHexString = fromHexString;
|
|
|
1782
1802
|
exports.generateZapEvent = generateZapEvent;
|
|
1783
1803
|
exports.getEventHash = getEventHash;
|
|
1784
1804
|
exports.getFiatBtcRate = getFiatBtcRate;
|
|
1805
|
+
exports.getFiatCurrencies = getFiatCurrencies;
|
|
1785
1806
|
exports.getFiatValue = getFiatValue;
|
|
1786
1807
|
exports.getFormattedFiatValue = getFormattedFiatValue;
|
|
1787
1808
|
exports.getSatoshiValue = getSatoshiValue;
|