lightning-agent 0.3.2 → 0.3.3
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/lib/auth.js +12 -0
- package/lib/stream.js +15 -8
- package/lib/wallet.js +3 -3
- package/package.json +1 -1
package/lib/auth.js
CHANGED
|
@@ -169,6 +169,18 @@ function createAuthServer(opts = {}) {
|
|
|
169
169
|
* // Send sig + key back to the auth server
|
|
170
170
|
*/
|
|
171
171
|
function signAuth(k1, privateKey) {
|
|
172
|
+
// Validate k1 is a 64-character hex string (32 bytes)
|
|
173
|
+
if (typeof k1 !== 'string' || !/^[0-9a-f]{64}$/i.test(k1)) {
|
|
174
|
+
throw new Error('k1 must be a 64-character hex string');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Validate privateKey is valid hex when provided as string
|
|
178
|
+
if (typeof privateKey === 'string') {
|
|
179
|
+
if (!/^[0-9a-f]+$/i.test(privateKey) || privateKey.length === 0) {
|
|
180
|
+
throw new Error('privateKey must be a valid hex string');
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
172
184
|
const privBuf = typeof privateKey === 'string'
|
|
173
185
|
? Buffer.from(privateKey, 'hex')
|
|
174
186
|
: Buffer.from(privateKey);
|
package/lib/stream.js
CHANGED
|
@@ -415,14 +415,21 @@ function createStreamClient(wallet, opts = {}) {
|
|
|
415
415
|
|
|
416
416
|
// POST preimage back to provider
|
|
417
417
|
if (sessionId && payResult.preimage) {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
418
|
+
try {
|
|
419
|
+
const proofRes = await fetch(url, {
|
|
420
|
+
method: 'POST',
|
|
421
|
+
headers: { 'Content-Type': 'application/json' },
|
|
422
|
+
body: JSON.stringify({
|
|
423
|
+
sessionId,
|
|
424
|
+
preimage: payResult.preimage
|
|
425
|
+
})
|
|
426
|
+
});
|
|
427
|
+
if (!proofRes.ok) {
|
|
428
|
+
console.error('Preimage POST failed:', proofRes.status);
|
|
429
|
+
}
|
|
430
|
+
} catch (postErr) {
|
|
431
|
+
console.error('Preimage POST error:', postErr.message);
|
|
432
|
+
}
|
|
426
433
|
}
|
|
427
434
|
} catch (err) {
|
|
428
435
|
// Payment failed — stream will pause
|
package/lib/wallet.js
CHANGED
|
@@ -90,9 +90,9 @@ function decodeBolt11(invoice) {
|
|
|
90
90
|
amountSats,
|
|
91
91
|
description,
|
|
92
92
|
paymentHash,
|
|
93
|
-
network: hrp.startsWith('
|
|
94
|
-
hrp.startsWith('
|
|
95
|
-
hrp.startsWith('
|
|
93
|
+
network: hrp.startsWith('lntbs') ? 'signet' :
|
|
94
|
+
hrp.startsWith('lntb') ? 'testnet' :
|
|
95
|
+
hrp.startsWith('lnbcrt') ? 'regtest' : 'mainnet'
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
98
|
|