thunder-bridge 1.4.2 → 2.1.1
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 +145 -133
- package/dist/bank-CEIuNhV_.d.cts +896 -0
- package/dist/bank-M8flcMks.d.ts +896 -0
- package/dist/bank.cjs +338 -0
- package/dist/bank.d.cts +46 -0
- package/dist/bank.d.ts +46 -0
- package/dist/bank.js +310 -0
- package/dist/errors-DriqW-lp.d.cts +126 -0
- package/dist/errors-ZEUT-MhO.d.ts +126 -0
- package/dist/index.cjs +2108 -1235
- package/dist/index.d.cts +13 -505
- package/dist/index.d.ts +13 -505
- package/dist/index.js +2088 -1193
- package/dist/{server.cjs → nwc.cjs} +376 -720
- package/dist/nwc.d.cts +122 -0
- package/dist/nwc.d.ts +122 -0
- package/dist/{server.js → nwc.js} +368 -695
- package/dist/price.cjs +240 -0
- package/dist/price.d.cts +17 -0
- package/dist/price.d.ts +17 -0
- package/dist/price.js +205 -0
- package/dist/qr-CF-YeXU1.d.cts +55 -0
- package/dist/qr-CF-YeXU1.d.ts +55 -0
- package/dist/qr.cjs +259 -0
- package/dist/qr.d.cts +1 -0
- package/dist/qr.d.ts +1 -0
- package/dist/qr.js +224 -0
- package/dist/types-DYZ9EkmJ.d.cts +261 -0
- package/dist/types-DYZ9EkmJ.d.ts +261 -0
- package/openapi.yaml +29 -39
- package/package.json +48 -9
- package/dist/rail-CqUfuYXJ.d.cts +0 -615
- package/dist/rail-CqUfuYXJ.d.ts +0 -615
- package/dist/server.d.cts +0 -145
- package/dist/server.d.ts +0 -145
package/dist/qr.cjs
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/entry/qr.ts
|
|
21
|
+
var qr_exports = {};
|
|
22
|
+
__export(qr_exports, {
|
|
23
|
+
invoiceToDataUrl: () => invoiceToDataUrl,
|
|
24
|
+
invoiceToSvg: () => invoiceToSvg,
|
|
25
|
+
lnurlEndpointToDataUrl: () => lnurlEndpointToDataUrl,
|
|
26
|
+
lnurlEndpointToSvg: () => lnurlEndpointToSvg,
|
|
27
|
+
qrToDataUrl: () => qrToDataUrl,
|
|
28
|
+
qrToSvg: () => qrToSvg,
|
|
29
|
+
spdToDataUrl: () => spdToDataUrl,
|
|
30
|
+
spdToSvg: () => spdToSvg,
|
|
31
|
+
toLnurl: () => toLnurl
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(qr_exports);
|
|
34
|
+
|
|
35
|
+
// ../core/sha256.ts
|
|
36
|
+
var ROUND_CONSTANTS = new Uint32Array([
|
|
37
|
+
1116352408,
|
|
38
|
+
1899447441,
|
|
39
|
+
3049323471,
|
|
40
|
+
3921009573,
|
|
41
|
+
961987163,
|
|
42
|
+
1508970993,
|
|
43
|
+
2453635748,
|
|
44
|
+
2870763221,
|
|
45
|
+
3624381080,
|
|
46
|
+
310598401,
|
|
47
|
+
607225278,
|
|
48
|
+
1426881987,
|
|
49
|
+
1925078388,
|
|
50
|
+
2162078206,
|
|
51
|
+
2614888103,
|
|
52
|
+
3248222580,
|
|
53
|
+
3835390401,
|
|
54
|
+
4022224774,
|
|
55
|
+
264347078,
|
|
56
|
+
604807628,
|
|
57
|
+
770255983,
|
|
58
|
+
1249150122,
|
|
59
|
+
1555081692,
|
|
60
|
+
1996064986,
|
|
61
|
+
2554220882,
|
|
62
|
+
2821834349,
|
|
63
|
+
2952996808,
|
|
64
|
+
3210313671,
|
|
65
|
+
3336571891,
|
|
66
|
+
3584528711,
|
|
67
|
+
113926993,
|
|
68
|
+
338241895,
|
|
69
|
+
666307205,
|
|
70
|
+
773529912,
|
|
71
|
+
1294757372,
|
|
72
|
+
1396182291,
|
|
73
|
+
1695183700,
|
|
74
|
+
1986661051,
|
|
75
|
+
2177026350,
|
|
76
|
+
2456956037,
|
|
77
|
+
2730485921,
|
|
78
|
+
2820302411,
|
|
79
|
+
3259730800,
|
|
80
|
+
3345764771,
|
|
81
|
+
3516065817,
|
|
82
|
+
3600352804,
|
|
83
|
+
4094571909,
|
|
84
|
+
275423344,
|
|
85
|
+
430227734,
|
|
86
|
+
506948616,
|
|
87
|
+
659060556,
|
|
88
|
+
883997877,
|
|
89
|
+
958139571,
|
|
90
|
+
1322822218,
|
|
91
|
+
1537002063,
|
|
92
|
+
1747873779,
|
|
93
|
+
1955562222,
|
|
94
|
+
2024104815,
|
|
95
|
+
2227730452,
|
|
96
|
+
2361852424,
|
|
97
|
+
2428436474,
|
|
98
|
+
2756734187,
|
|
99
|
+
3204031479,
|
|
100
|
+
3329325298
|
|
101
|
+
]);
|
|
102
|
+
var INITIAL_STATE = new Uint32Array([
|
|
103
|
+
1779033703,
|
|
104
|
+
3144134277,
|
|
105
|
+
1013904242,
|
|
106
|
+
2773480762,
|
|
107
|
+
1359893119,
|
|
108
|
+
2600822924,
|
|
109
|
+
528734635,
|
|
110
|
+
1541459225
|
|
111
|
+
]);
|
|
112
|
+
|
|
113
|
+
// ../core/bolt11.ts
|
|
114
|
+
var BECH32_CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
|
115
|
+
var BECH32_GENERATOR = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
116
|
+
var MSAT_PER_BTC = 1e11;
|
|
117
|
+
var HRP_MULTIPLIER_MSAT = {
|
|
118
|
+
m: MSAT_PER_BTC / 1e3,
|
|
119
|
+
u: MSAT_PER_BTC / 1e6,
|
|
120
|
+
n: MSAT_PER_BTC / 1e9,
|
|
121
|
+
p: MSAT_PER_BTC / 1e12
|
|
122
|
+
};
|
|
123
|
+
function expandedHrp(hrp) {
|
|
124
|
+
const codes = [...hrp].map((char) => char.charCodeAt(0));
|
|
125
|
+
return [...codes.map((code) => code >> 5), 0, ...codes.map((code) => code & 31)];
|
|
126
|
+
}
|
|
127
|
+
function bech32Polymod(values) {
|
|
128
|
+
let checksum = 1;
|
|
129
|
+
for (const value of values) {
|
|
130
|
+
const top = checksum >> 25;
|
|
131
|
+
checksum = (checksum & 33554431) << 5 ^ value;
|
|
132
|
+
for (let bit = 0; bit < 5; bit++) {
|
|
133
|
+
if (top >> bit & 1) {
|
|
134
|
+
checksum ^= BECH32_GENERATOR[bit];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return checksum;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// ../core/lnurl.ts
|
|
142
|
+
var CHECKSUM_SLOTS = [0, 1, 2, 3, 4, 5];
|
|
143
|
+
var LNURL_HRP = "lnurl";
|
|
144
|
+
function toLnurl(endpoint) {
|
|
145
|
+
const scheme = parsedScheme(endpoint);
|
|
146
|
+
if (scheme !== "https:" && scheme !== "http:") {
|
|
147
|
+
throw new Error(`${endpoint} is not an http or https URL`);
|
|
148
|
+
}
|
|
149
|
+
const words = toWords(new TextEncoder().encode(endpoint));
|
|
150
|
+
const data = [...words, ...checksumWords(LNURL_HRP, words)];
|
|
151
|
+
return `${LNURL_HRP}1${data.map((word) => BECH32_CHARSET[word]).join("")}`.toUpperCase();
|
|
152
|
+
}
|
|
153
|
+
function parsedScheme(endpoint) {
|
|
154
|
+
try {
|
|
155
|
+
return new URL(endpoint).protocol;
|
|
156
|
+
} catch {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function toWords(bytes) {
|
|
161
|
+
const words = [];
|
|
162
|
+
let accumulator = 0;
|
|
163
|
+
let bits = 0;
|
|
164
|
+
for (const byte of bytes) {
|
|
165
|
+
accumulator = accumulator << 8 | byte;
|
|
166
|
+
bits += 8;
|
|
167
|
+
while (bits >= 5) {
|
|
168
|
+
bits -= 5;
|
|
169
|
+
words.push(accumulator >> bits & 31);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (bits > 0) {
|
|
173
|
+
words.push(accumulator << 5 - bits & 31);
|
|
174
|
+
}
|
|
175
|
+
return words;
|
|
176
|
+
}
|
|
177
|
+
function checksumWords(hrp, words) {
|
|
178
|
+
const values = [...expandedHrp(hrp), ...words, ...CHECKSUM_SLOTS.map(() => 0)];
|
|
179
|
+
const polymod = bech32Polymod(values) ^ 1;
|
|
180
|
+
return CHECKSUM_SLOTS.map((slot) => polymod >> 5 * (5 - slot) & 31);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// src/qr.ts
|
|
184
|
+
var import_uqr = require("uqr");
|
|
185
|
+
var SAFE_COLOR = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$|^rgba?\([\d.,%/\s]+\)$|^[a-z]+$/i;
|
|
186
|
+
function toLightningUri(destination) {
|
|
187
|
+
const scanned = isLnAddress(destination) ? destination : destination.toUpperCase();
|
|
188
|
+
return `LIGHTNING:${scanned}`;
|
|
189
|
+
}
|
|
190
|
+
function invoiceToSvg(destination, options) {
|
|
191
|
+
return svgOf(toLightningUri(destination), options);
|
|
192
|
+
}
|
|
193
|
+
function invoiceToDataUrl(destination, options) {
|
|
194
|
+
return asDataUrl(invoiceToSvg(destination, options));
|
|
195
|
+
}
|
|
196
|
+
function lnurlEndpointToSvg(endpoint, options) {
|
|
197
|
+
return svgOf(toLnurl(endpoint), options);
|
|
198
|
+
}
|
|
199
|
+
function lnurlEndpointToDataUrl(endpoint, options) {
|
|
200
|
+
return asDataUrl(lnurlEndpointToSvg(endpoint, options));
|
|
201
|
+
}
|
|
202
|
+
function spdToSvg(spd, options) {
|
|
203
|
+
return svgOf(spd, options);
|
|
204
|
+
}
|
|
205
|
+
function spdToDataUrl(spd, options) {
|
|
206
|
+
return asDataUrl(spdToSvg(spd, options));
|
|
207
|
+
}
|
|
208
|
+
function qrToSvg(payload, options) {
|
|
209
|
+
return svgOf(payload, options);
|
|
210
|
+
}
|
|
211
|
+
function qrToDataUrl(payload, options) {
|
|
212
|
+
return asDataUrl(qrToSvg(payload, options));
|
|
213
|
+
}
|
|
214
|
+
function svgOf(scanned, options) {
|
|
215
|
+
const size = options?.size ?? 256;
|
|
216
|
+
const color = options?.color ?? "#000";
|
|
217
|
+
if (!SAFE_COLOR.test(color)) {
|
|
218
|
+
throw new Error(`Invalid color: ${color}`);
|
|
219
|
+
}
|
|
220
|
+
return renderSvg(scanned, size, color);
|
|
221
|
+
}
|
|
222
|
+
function asDataUrl(svg) {
|
|
223
|
+
return `data:image/svg+xml,${encodeURIComponent(svg)}`;
|
|
224
|
+
}
|
|
225
|
+
function isLnAddress(destination) {
|
|
226
|
+
const at = destination.indexOf("@");
|
|
227
|
+
return at > 0 && destination.slice(at + 1).includes(".");
|
|
228
|
+
}
|
|
229
|
+
function renderSvg(content, size, color) {
|
|
230
|
+
const { data } = (0, import_uqr.encode)(content);
|
|
231
|
+
const modules = data.length;
|
|
232
|
+
const cellSize = size / modules;
|
|
233
|
+
let path = "";
|
|
234
|
+
for (let y = 0; y < modules; y++) {
|
|
235
|
+
for (let x = 0; x < modules; x++) {
|
|
236
|
+
if (data[y][x]) {
|
|
237
|
+
path += `M${x * cellSize},${y * cellSize}h${cellSize}v${cellSize}h-${cellSize}z`;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return [
|
|
242
|
+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}" width="${size}" height="${size}">`,
|
|
243
|
+
`<rect width="100%" height="100%" fill="white"/>`,
|
|
244
|
+
`<path d="${path}" fill="${color}"/>`,
|
|
245
|
+
`</svg>`
|
|
246
|
+
].join("");
|
|
247
|
+
}
|
|
248
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
249
|
+
0 && (module.exports = {
|
|
250
|
+
invoiceToDataUrl,
|
|
251
|
+
invoiceToSvg,
|
|
252
|
+
lnurlEndpointToDataUrl,
|
|
253
|
+
lnurlEndpointToSvg,
|
|
254
|
+
qrToDataUrl,
|
|
255
|
+
qrToSvg,
|
|
256
|
+
spdToDataUrl,
|
|
257
|
+
spdToSvg,
|
|
258
|
+
toLnurl
|
|
259
|
+
});
|
package/dist/qr.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Q as QrOptions, i as invoiceToDataUrl, a as invoiceToSvg, l as lnurlEndpointToDataUrl, b as lnurlEndpointToSvg, q as qrToDataUrl, c as qrToSvg, s as spdToDataUrl, d as spdToSvg, t as toLnurl } from './qr-CF-YeXU1.cjs';
|
package/dist/qr.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Q as QrOptions, i as invoiceToDataUrl, a as invoiceToSvg, l as lnurlEndpointToDataUrl, b as lnurlEndpointToSvg, q as qrToDataUrl, c as qrToSvg, s as spdToDataUrl, d as spdToSvg, t as toLnurl } from './qr-CF-YeXU1.js';
|
package/dist/qr.js
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// ../core/sha256.ts
|
|
2
|
+
var ROUND_CONSTANTS = new Uint32Array([
|
|
3
|
+
1116352408,
|
|
4
|
+
1899447441,
|
|
5
|
+
3049323471,
|
|
6
|
+
3921009573,
|
|
7
|
+
961987163,
|
|
8
|
+
1508970993,
|
|
9
|
+
2453635748,
|
|
10
|
+
2870763221,
|
|
11
|
+
3624381080,
|
|
12
|
+
310598401,
|
|
13
|
+
607225278,
|
|
14
|
+
1426881987,
|
|
15
|
+
1925078388,
|
|
16
|
+
2162078206,
|
|
17
|
+
2614888103,
|
|
18
|
+
3248222580,
|
|
19
|
+
3835390401,
|
|
20
|
+
4022224774,
|
|
21
|
+
264347078,
|
|
22
|
+
604807628,
|
|
23
|
+
770255983,
|
|
24
|
+
1249150122,
|
|
25
|
+
1555081692,
|
|
26
|
+
1996064986,
|
|
27
|
+
2554220882,
|
|
28
|
+
2821834349,
|
|
29
|
+
2952996808,
|
|
30
|
+
3210313671,
|
|
31
|
+
3336571891,
|
|
32
|
+
3584528711,
|
|
33
|
+
113926993,
|
|
34
|
+
338241895,
|
|
35
|
+
666307205,
|
|
36
|
+
773529912,
|
|
37
|
+
1294757372,
|
|
38
|
+
1396182291,
|
|
39
|
+
1695183700,
|
|
40
|
+
1986661051,
|
|
41
|
+
2177026350,
|
|
42
|
+
2456956037,
|
|
43
|
+
2730485921,
|
|
44
|
+
2820302411,
|
|
45
|
+
3259730800,
|
|
46
|
+
3345764771,
|
|
47
|
+
3516065817,
|
|
48
|
+
3600352804,
|
|
49
|
+
4094571909,
|
|
50
|
+
275423344,
|
|
51
|
+
430227734,
|
|
52
|
+
506948616,
|
|
53
|
+
659060556,
|
|
54
|
+
883997877,
|
|
55
|
+
958139571,
|
|
56
|
+
1322822218,
|
|
57
|
+
1537002063,
|
|
58
|
+
1747873779,
|
|
59
|
+
1955562222,
|
|
60
|
+
2024104815,
|
|
61
|
+
2227730452,
|
|
62
|
+
2361852424,
|
|
63
|
+
2428436474,
|
|
64
|
+
2756734187,
|
|
65
|
+
3204031479,
|
|
66
|
+
3329325298
|
|
67
|
+
]);
|
|
68
|
+
var INITIAL_STATE = new Uint32Array([
|
|
69
|
+
1779033703,
|
|
70
|
+
3144134277,
|
|
71
|
+
1013904242,
|
|
72
|
+
2773480762,
|
|
73
|
+
1359893119,
|
|
74
|
+
2600822924,
|
|
75
|
+
528734635,
|
|
76
|
+
1541459225
|
|
77
|
+
]);
|
|
78
|
+
|
|
79
|
+
// ../core/bolt11.ts
|
|
80
|
+
var BECH32_CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
|
81
|
+
var BECH32_GENERATOR = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
82
|
+
var MSAT_PER_BTC = 1e11;
|
|
83
|
+
var HRP_MULTIPLIER_MSAT = {
|
|
84
|
+
m: MSAT_PER_BTC / 1e3,
|
|
85
|
+
u: MSAT_PER_BTC / 1e6,
|
|
86
|
+
n: MSAT_PER_BTC / 1e9,
|
|
87
|
+
p: MSAT_PER_BTC / 1e12
|
|
88
|
+
};
|
|
89
|
+
function expandedHrp(hrp) {
|
|
90
|
+
const codes = [...hrp].map((char) => char.charCodeAt(0));
|
|
91
|
+
return [...codes.map((code) => code >> 5), 0, ...codes.map((code) => code & 31)];
|
|
92
|
+
}
|
|
93
|
+
function bech32Polymod(values) {
|
|
94
|
+
let checksum = 1;
|
|
95
|
+
for (const value of values) {
|
|
96
|
+
const top = checksum >> 25;
|
|
97
|
+
checksum = (checksum & 33554431) << 5 ^ value;
|
|
98
|
+
for (let bit = 0; bit < 5; bit++) {
|
|
99
|
+
if (top >> bit & 1) {
|
|
100
|
+
checksum ^= BECH32_GENERATOR[bit];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return checksum;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ../core/lnurl.ts
|
|
108
|
+
var CHECKSUM_SLOTS = [0, 1, 2, 3, 4, 5];
|
|
109
|
+
var LNURL_HRP = "lnurl";
|
|
110
|
+
function toLnurl(endpoint) {
|
|
111
|
+
const scheme = parsedScheme(endpoint);
|
|
112
|
+
if (scheme !== "https:" && scheme !== "http:") {
|
|
113
|
+
throw new Error(`${endpoint} is not an http or https URL`);
|
|
114
|
+
}
|
|
115
|
+
const words = toWords(new TextEncoder().encode(endpoint));
|
|
116
|
+
const data = [...words, ...checksumWords(LNURL_HRP, words)];
|
|
117
|
+
return `${LNURL_HRP}1${data.map((word) => BECH32_CHARSET[word]).join("")}`.toUpperCase();
|
|
118
|
+
}
|
|
119
|
+
function parsedScheme(endpoint) {
|
|
120
|
+
try {
|
|
121
|
+
return new URL(endpoint).protocol;
|
|
122
|
+
} catch {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function toWords(bytes) {
|
|
127
|
+
const words = [];
|
|
128
|
+
let accumulator = 0;
|
|
129
|
+
let bits = 0;
|
|
130
|
+
for (const byte of bytes) {
|
|
131
|
+
accumulator = accumulator << 8 | byte;
|
|
132
|
+
bits += 8;
|
|
133
|
+
while (bits >= 5) {
|
|
134
|
+
bits -= 5;
|
|
135
|
+
words.push(accumulator >> bits & 31);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (bits > 0) {
|
|
139
|
+
words.push(accumulator << 5 - bits & 31);
|
|
140
|
+
}
|
|
141
|
+
return words;
|
|
142
|
+
}
|
|
143
|
+
function checksumWords(hrp, words) {
|
|
144
|
+
const values = [...expandedHrp(hrp), ...words, ...CHECKSUM_SLOTS.map(() => 0)];
|
|
145
|
+
const polymod = bech32Polymod(values) ^ 1;
|
|
146
|
+
return CHECKSUM_SLOTS.map((slot) => polymod >> 5 * (5 - slot) & 31);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/qr.ts
|
|
150
|
+
import { encode } from "uqr";
|
|
151
|
+
var SAFE_COLOR = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$|^rgba?\([\d.,%/\s]+\)$|^[a-z]+$/i;
|
|
152
|
+
function toLightningUri(destination) {
|
|
153
|
+
const scanned = isLnAddress(destination) ? destination : destination.toUpperCase();
|
|
154
|
+
return `LIGHTNING:${scanned}`;
|
|
155
|
+
}
|
|
156
|
+
function invoiceToSvg(destination, options) {
|
|
157
|
+
return svgOf(toLightningUri(destination), options);
|
|
158
|
+
}
|
|
159
|
+
function invoiceToDataUrl(destination, options) {
|
|
160
|
+
return asDataUrl(invoiceToSvg(destination, options));
|
|
161
|
+
}
|
|
162
|
+
function lnurlEndpointToSvg(endpoint, options) {
|
|
163
|
+
return svgOf(toLnurl(endpoint), options);
|
|
164
|
+
}
|
|
165
|
+
function lnurlEndpointToDataUrl(endpoint, options) {
|
|
166
|
+
return asDataUrl(lnurlEndpointToSvg(endpoint, options));
|
|
167
|
+
}
|
|
168
|
+
function spdToSvg(spd, options) {
|
|
169
|
+
return svgOf(spd, options);
|
|
170
|
+
}
|
|
171
|
+
function spdToDataUrl(spd, options) {
|
|
172
|
+
return asDataUrl(spdToSvg(spd, options));
|
|
173
|
+
}
|
|
174
|
+
function qrToSvg(payload, options) {
|
|
175
|
+
return svgOf(payload, options);
|
|
176
|
+
}
|
|
177
|
+
function qrToDataUrl(payload, options) {
|
|
178
|
+
return asDataUrl(qrToSvg(payload, options));
|
|
179
|
+
}
|
|
180
|
+
function svgOf(scanned, options) {
|
|
181
|
+
const size = options?.size ?? 256;
|
|
182
|
+
const color = options?.color ?? "#000";
|
|
183
|
+
if (!SAFE_COLOR.test(color)) {
|
|
184
|
+
throw new Error(`Invalid color: ${color}`);
|
|
185
|
+
}
|
|
186
|
+
return renderSvg(scanned, size, color);
|
|
187
|
+
}
|
|
188
|
+
function asDataUrl(svg) {
|
|
189
|
+
return `data:image/svg+xml,${encodeURIComponent(svg)}`;
|
|
190
|
+
}
|
|
191
|
+
function isLnAddress(destination) {
|
|
192
|
+
const at = destination.indexOf("@");
|
|
193
|
+
return at > 0 && destination.slice(at + 1).includes(".");
|
|
194
|
+
}
|
|
195
|
+
function renderSvg(content, size, color) {
|
|
196
|
+
const { data } = encode(content);
|
|
197
|
+
const modules = data.length;
|
|
198
|
+
const cellSize = size / modules;
|
|
199
|
+
let path = "";
|
|
200
|
+
for (let y = 0; y < modules; y++) {
|
|
201
|
+
for (let x = 0; x < modules; x++) {
|
|
202
|
+
if (data[y][x]) {
|
|
203
|
+
path += `M${x * cellSize},${y * cellSize}h${cellSize}v${cellSize}h-${cellSize}z`;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return [
|
|
208
|
+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}" width="${size}" height="${size}">`,
|
|
209
|
+
`<rect width="100%" height="100%" fill="white"/>`,
|
|
210
|
+
`<path d="${path}" fill="${color}"/>`,
|
|
211
|
+
`</svg>`
|
|
212
|
+
].join("");
|
|
213
|
+
}
|
|
214
|
+
export {
|
|
215
|
+
invoiceToDataUrl,
|
|
216
|
+
invoiceToSvg,
|
|
217
|
+
lnurlEndpointToDataUrl,
|
|
218
|
+
lnurlEndpointToSvg,
|
|
219
|
+
qrToDataUrl,
|
|
220
|
+
qrToSvg,
|
|
221
|
+
spdToDataUrl,
|
|
222
|
+
spdToSvg,
|
|
223
|
+
toLnurl
|
|
224
|
+
};
|