lightning-agent 0.3.1 → 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/README.md +4 -2
- package/lib/auth.js +12 -0
- package/lib/stream.js +15 -8
- package/lib/wallet.js +7 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# ⚡ lightning-agent
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Settle this transaction without a platform.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
You can't transact without a payment rail. lightning-agent is the rail — payments, auth, escrow, and streaming micropayments over [Nostr Wallet Connect (NWC)](https://nwc.dev). No browser, no UI, no bank accounts, no Stripe. Connect to any NWC-compatible wallet (Alby Hub, Mutiny, etc.) and two agents can exchange value directly.
|
|
6
|
+
|
|
7
|
+
Part of the constraint chain: [agent-discovery](https://github.com/jeletor/agent-discovery) (find) → [ai-wot](https://github.com/jeletor/ai-wot) (verify) → **lightning-agent** (pay) → [lightning-toll](https://github.com/jeletor/lightning-toll) (gate).
|
|
6
8
|
|
|
7
9
|
## Install
|
|
8
10
|
|
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
|
|
|
@@ -265,12 +265,14 @@ class NWCWallet {
|
|
|
265
265
|
* @param {number} [opts.timeoutMs] - Request timeout
|
|
266
266
|
*/
|
|
267
267
|
async createInvoice(opts = {}) {
|
|
268
|
-
|
|
268
|
+
// Accept both amountSats and amount for convenience
|
|
269
|
+
const sats = opts.amountSats || opts.amount;
|
|
270
|
+
if (!sats || sats <= 0) {
|
|
269
271
|
throw new Error('amountSats is required and must be positive');
|
|
270
272
|
}
|
|
271
273
|
|
|
272
274
|
const params = {
|
|
273
|
-
amount:
|
|
275
|
+
amount: sats * 1000, // NWC uses millisats
|
|
274
276
|
};
|
|
275
277
|
if (opts.description) params.description = opts.description;
|
|
276
278
|
if (opts.expiry) params.expiry = opts.expiry;
|