thunder-bridge 1.4.1 → 1.5.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/dist/qr.cjs ADDED
@@ -0,0 +1,262 @@
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 MSAT_PER_BTC = 1e11;
115
+ var HRP_MULTIPLIER_MSAT = {
116
+ m: MSAT_PER_BTC / 1e3,
117
+ u: MSAT_PER_BTC / 1e6,
118
+ n: MSAT_PER_BTC / 1e9,
119
+ p: MSAT_PER_BTC / 1e12
120
+ };
121
+
122
+ // ../core/lnurl.ts
123
+ var BECH32_CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
124
+ var BECH32_GENERATOR = [996825010, 642813549, 513874426, 1027748829, 705979059];
125
+ var CHECKSUM_SLOTS = [0, 1, 2, 3, 4, 5];
126
+ var LNURL_HRP = "lnurl";
127
+ function toLnurl(endpoint) {
128
+ const scheme = parsedScheme(endpoint);
129
+ if (scheme !== "https:" && scheme !== "http:") {
130
+ throw new Error(`${endpoint} is not an http or https URL`);
131
+ }
132
+ const words = toWords(new TextEncoder().encode(endpoint));
133
+ const data = [...words, ...checksumWords(LNURL_HRP, words)];
134
+ return `${LNURL_HRP}1${data.map((word) => BECH32_CHARSET[word]).join("")}`.toUpperCase();
135
+ }
136
+ function parsedScheme(endpoint) {
137
+ try {
138
+ return new URL(endpoint).protocol;
139
+ } catch {
140
+ return null;
141
+ }
142
+ }
143
+ function toWords(bytes) {
144
+ const words = [];
145
+ let accumulator = 0;
146
+ let bits = 0;
147
+ for (const byte of bytes) {
148
+ accumulator = accumulator << 8 | byte;
149
+ bits += 8;
150
+ while (bits >= 5) {
151
+ bits -= 5;
152
+ words.push(accumulator >> bits & 31);
153
+ }
154
+ }
155
+ if (bits > 0) {
156
+ words.push(accumulator << 5 - bits & 31);
157
+ }
158
+ return words;
159
+ }
160
+ function checksumWords(hrp, words) {
161
+ const expanded = [...hrp].map((char) => char.charCodeAt(0));
162
+ const values = [
163
+ ...expanded.map((code) => code >> 5),
164
+ 0,
165
+ ...expanded.map((code) => code & 31),
166
+ ...words,
167
+ ...CHECKSUM_SLOTS.map(() => 0)
168
+ ];
169
+ const polymod = bech32Polymod(values) ^ 1;
170
+ return CHECKSUM_SLOTS.map((slot) => polymod >> 5 * (5 - slot) & 31);
171
+ }
172
+ function bech32Polymod(values) {
173
+ let checksum = 1;
174
+ for (const value of values) {
175
+ const top = checksum >> 25;
176
+ checksum = (checksum & 33554431) << 5 ^ value;
177
+ for (let bit = 0; bit < 5; bit++) {
178
+ if (top >> bit & 1) {
179
+ checksum ^= BECH32_GENERATOR[bit];
180
+ }
181
+ }
182
+ }
183
+ return checksum;
184
+ }
185
+
186
+ // src/qr.ts
187
+ var import_uqr = require("uqr");
188
+ var SAFE_COLOR = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$|^rgba?\([\d.,%/\s]+\)$|^[a-z]+$/i;
189
+ function toLightningUri(destination) {
190
+ const scanned = isLnAddress(destination) ? destination : destination.toUpperCase();
191
+ return `LIGHTNING:${scanned}`;
192
+ }
193
+ function invoiceToSvg(destination, options) {
194
+ return svgOf(toLightningUri(destination), options);
195
+ }
196
+ function invoiceToDataUrl(destination, options) {
197
+ return asDataUrl(invoiceToSvg(destination, options));
198
+ }
199
+ function lnurlEndpointToSvg(endpoint, options) {
200
+ return svgOf(toLnurl(endpoint), options);
201
+ }
202
+ function lnurlEndpointToDataUrl(endpoint, options) {
203
+ return asDataUrl(lnurlEndpointToSvg(endpoint, options));
204
+ }
205
+ function spdToSvg(spd, options) {
206
+ return svgOf(spd, options);
207
+ }
208
+ function spdToDataUrl(spd, options) {
209
+ return asDataUrl(spdToSvg(spd, options));
210
+ }
211
+ function qrToSvg(payload, options) {
212
+ return svgOf(payload, options);
213
+ }
214
+ function qrToDataUrl(payload, options) {
215
+ return asDataUrl(qrToSvg(payload, options));
216
+ }
217
+ function svgOf(scanned, options) {
218
+ const size = options?.size ?? 256;
219
+ const color = options?.color ?? "#000";
220
+ if (!SAFE_COLOR.test(color)) {
221
+ throw new Error(`Invalid color: ${color}`);
222
+ }
223
+ return renderSvg(scanned, size, color);
224
+ }
225
+ function asDataUrl(svg) {
226
+ return `data:image/svg+xml,${encodeURIComponent(svg)}`;
227
+ }
228
+ function isLnAddress(destination) {
229
+ const at = destination.indexOf("@");
230
+ return at > 0 && destination.slice(at + 1).includes(".");
231
+ }
232
+ function renderSvg(content, size, color) {
233
+ const { data } = (0, import_uqr.encode)(content);
234
+ const modules = data.length;
235
+ const cellSize = size / modules;
236
+ let path = "";
237
+ for (let y = 0; y < modules; y++) {
238
+ for (let x = 0; x < modules; x++) {
239
+ if (data[y][x]) {
240
+ path += `M${x * cellSize},${y * cellSize}h${cellSize}v${cellSize}h-${cellSize}z`;
241
+ }
242
+ }
243
+ }
244
+ return [
245
+ `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}" width="${size}" height="${size}">`,
246
+ `<rect width="100%" height="100%" fill="white"/>`,
247
+ `<path d="${path}" fill="${color}"/>`,
248
+ `</svg>`
249
+ ].join("");
250
+ }
251
+ // Annotate the CommonJS export names for ESM import in node:
252
+ 0 && (module.exports = {
253
+ invoiceToDataUrl,
254
+ invoiceToSvg,
255
+ lnurlEndpointToDataUrl,
256
+ lnurlEndpointToSvg,
257
+ qrToDataUrl,
258
+ qrToSvg,
259
+ spdToDataUrl,
260
+ spdToSvg,
261
+ toLnurl
262
+ });
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,227 @@
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 MSAT_PER_BTC = 1e11;
81
+ var HRP_MULTIPLIER_MSAT = {
82
+ m: MSAT_PER_BTC / 1e3,
83
+ u: MSAT_PER_BTC / 1e6,
84
+ n: MSAT_PER_BTC / 1e9,
85
+ p: MSAT_PER_BTC / 1e12
86
+ };
87
+
88
+ // ../core/lnurl.ts
89
+ var BECH32_CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
90
+ var BECH32_GENERATOR = [996825010, 642813549, 513874426, 1027748829, 705979059];
91
+ var CHECKSUM_SLOTS = [0, 1, 2, 3, 4, 5];
92
+ var LNURL_HRP = "lnurl";
93
+ function toLnurl(endpoint) {
94
+ const scheme = parsedScheme(endpoint);
95
+ if (scheme !== "https:" && scheme !== "http:") {
96
+ throw new Error(`${endpoint} is not an http or https URL`);
97
+ }
98
+ const words = toWords(new TextEncoder().encode(endpoint));
99
+ const data = [...words, ...checksumWords(LNURL_HRP, words)];
100
+ return `${LNURL_HRP}1${data.map((word) => BECH32_CHARSET[word]).join("")}`.toUpperCase();
101
+ }
102
+ function parsedScheme(endpoint) {
103
+ try {
104
+ return new URL(endpoint).protocol;
105
+ } catch {
106
+ return null;
107
+ }
108
+ }
109
+ function toWords(bytes) {
110
+ const words = [];
111
+ let accumulator = 0;
112
+ let bits = 0;
113
+ for (const byte of bytes) {
114
+ accumulator = accumulator << 8 | byte;
115
+ bits += 8;
116
+ while (bits >= 5) {
117
+ bits -= 5;
118
+ words.push(accumulator >> bits & 31);
119
+ }
120
+ }
121
+ if (bits > 0) {
122
+ words.push(accumulator << 5 - bits & 31);
123
+ }
124
+ return words;
125
+ }
126
+ function checksumWords(hrp, words) {
127
+ const expanded = [...hrp].map((char) => char.charCodeAt(0));
128
+ const values = [
129
+ ...expanded.map((code) => code >> 5),
130
+ 0,
131
+ ...expanded.map((code) => code & 31),
132
+ ...words,
133
+ ...CHECKSUM_SLOTS.map(() => 0)
134
+ ];
135
+ const polymod = bech32Polymod(values) ^ 1;
136
+ return CHECKSUM_SLOTS.map((slot) => polymod >> 5 * (5 - slot) & 31);
137
+ }
138
+ function bech32Polymod(values) {
139
+ let checksum = 1;
140
+ for (const value of values) {
141
+ const top = checksum >> 25;
142
+ checksum = (checksum & 33554431) << 5 ^ value;
143
+ for (let bit = 0; bit < 5; bit++) {
144
+ if (top >> bit & 1) {
145
+ checksum ^= BECH32_GENERATOR[bit];
146
+ }
147
+ }
148
+ }
149
+ return checksum;
150
+ }
151
+
152
+ // src/qr.ts
153
+ import { encode } from "uqr";
154
+ var SAFE_COLOR = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$|^rgba?\([\d.,%/\s]+\)$|^[a-z]+$/i;
155
+ function toLightningUri(destination) {
156
+ const scanned = isLnAddress(destination) ? destination : destination.toUpperCase();
157
+ return `LIGHTNING:${scanned}`;
158
+ }
159
+ function invoiceToSvg(destination, options) {
160
+ return svgOf(toLightningUri(destination), options);
161
+ }
162
+ function invoiceToDataUrl(destination, options) {
163
+ return asDataUrl(invoiceToSvg(destination, options));
164
+ }
165
+ function lnurlEndpointToSvg(endpoint, options) {
166
+ return svgOf(toLnurl(endpoint), options);
167
+ }
168
+ function lnurlEndpointToDataUrl(endpoint, options) {
169
+ return asDataUrl(lnurlEndpointToSvg(endpoint, options));
170
+ }
171
+ function spdToSvg(spd, options) {
172
+ return svgOf(spd, options);
173
+ }
174
+ function spdToDataUrl(spd, options) {
175
+ return asDataUrl(spdToSvg(spd, options));
176
+ }
177
+ function qrToSvg(payload, options) {
178
+ return svgOf(payload, options);
179
+ }
180
+ function qrToDataUrl(payload, options) {
181
+ return asDataUrl(qrToSvg(payload, options));
182
+ }
183
+ function svgOf(scanned, options) {
184
+ const size = options?.size ?? 256;
185
+ const color = options?.color ?? "#000";
186
+ if (!SAFE_COLOR.test(color)) {
187
+ throw new Error(`Invalid color: ${color}`);
188
+ }
189
+ return renderSvg(scanned, size, color);
190
+ }
191
+ function asDataUrl(svg) {
192
+ return `data:image/svg+xml,${encodeURIComponent(svg)}`;
193
+ }
194
+ function isLnAddress(destination) {
195
+ const at = destination.indexOf("@");
196
+ return at > 0 && destination.slice(at + 1).includes(".");
197
+ }
198
+ function renderSvg(content, size, color) {
199
+ const { data } = encode(content);
200
+ const modules = data.length;
201
+ const cellSize = size / modules;
202
+ let path = "";
203
+ for (let y = 0; y < modules; y++) {
204
+ for (let x = 0; x < modules; x++) {
205
+ if (data[y][x]) {
206
+ path += `M${x * cellSize},${y * cellSize}h${cellSize}v${cellSize}h-${cellSize}z`;
207
+ }
208
+ }
209
+ }
210
+ return [
211
+ `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}" width="${size}" height="${size}">`,
212
+ `<rect width="100%" height="100%" fill="white"/>`,
213
+ `<path d="${path}" fill="${color}"/>`,
214
+ `</svg>`
215
+ ].join("");
216
+ }
217
+ export {
218
+ invoiceToDataUrl,
219
+ invoiceToSvg,
220
+ lnurlEndpointToDataUrl,
221
+ lnurlEndpointToSvg,
222
+ qrToDataUrl,
223
+ qrToSvg,
224
+ spdToDataUrl,
225
+ spdToSvg,
226
+ toLnurl
227
+ };