2020117-agent 0.6.5 → 0.6.7
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/agent.js +21 -16
- package/package.json +1 -1
package/dist/agent.js
CHANGED
|
@@ -85,7 +85,7 @@ import { SwarmNode, topicFromKind } from './swarm.js';
|
|
|
85
85
|
import { createProcessor } from './processor.js';
|
|
86
86
|
import { generateInvoice } from './lnurl.js';
|
|
87
87
|
import { generateKeypair, loadSovereignKeys, saveSovereignKeys, loadAgentName, signEvent, signEventWithPow, nip44Encrypt, nip44Decrypt, pubkeyFromPrivkey, RelayPool, } from './nostr.js';
|
|
88
|
-
import { parseNwcUri, nwcGetBalance, nwcPayLightningAddress } from './nwc.js';
|
|
88
|
+
import { parseNwcUri, nwcGetBalance, nwcPayLightningAddress, nwcMakeInvoice } from './nwc.js';
|
|
89
89
|
import { readFileSync } from 'fs';
|
|
90
90
|
import WebSocket from 'ws';
|
|
91
91
|
// Polyfill global WebSocket for Node.js < 22 (needed by ws tunnel)
|
|
@@ -258,10 +258,11 @@ async function setupNostr(label) {
|
|
|
258
258
|
// 7. Subscribe to NIP-XX prompts (Kind 25802)
|
|
259
259
|
subscribeNipXX(label);
|
|
260
260
|
// 8. Subscribe to DVM requests (Kind 5xxx)
|
|
261
|
-
// P2P-only:
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
261
|
+
// P2P-only: skip relay subscription entirely — only serve P2P customers
|
|
262
|
+
if (!P2P_ONLY) {
|
|
263
|
+
subscribeDvmRequests(label);
|
|
264
|
+
subscribeDvmResults(label);
|
|
265
|
+
}
|
|
265
266
|
// 9. Start heartbeat (Kind 30333 to relay)
|
|
266
267
|
const pricing = {};
|
|
267
268
|
const priceSats = SATS_PER_CHUNK * CHUNKS_PER_PAYMENT;
|
|
@@ -552,12 +553,6 @@ async function handleDvmRequest(label, event) {
|
|
|
552
553
|
// Skip own events
|
|
553
554
|
if (event.pubkey === state.sovereignKeys.pubkey)
|
|
554
555
|
return;
|
|
555
|
-
// P2P-only mode: only handle direct requests (p tag pointing to us)
|
|
556
|
-
if (P2P_ONLY) {
|
|
557
|
-
const isDirected = event.tags.some(t => t[0] === 'p' && t[1] === state.sovereignKeys.pubkey);
|
|
558
|
-
if (!isDirected)
|
|
559
|
-
return;
|
|
560
|
-
}
|
|
561
556
|
// Dedup: skip already-seen events
|
|
562
557
|
if (!markSeen(event.id))
|
|
563
558
|
return;
|
|
@@ -832,11 +827,21 @@ function markSeen(eventId) {
|
|
|
832
827
|
}
|
|
833
828
|
return true;
|
|
834
829
|
}
|
|
835
|
-
/** Send a billing tick to the customer — generate Lightning invoice
|
|
830
|
+
/** Send a billing tick to the customer — generate Lightning invoice.
|
|
831
|
+
* Prefers NWC make_invoice (if nwc_uri configured), falls back to LNURL-pay. */
|
|
836
832
|
async function sendBillingTick(node, session, amount, label) {
|
|
837
833
|
const tickId = randomBytes(4).toString('hex');
|
|
838
834
|
try {
|
|
839
|
-
|
|
835
|
+
let bolt11;
|
|
836
|
+
if (state.nwcParsed) {
|
|
837
|
+
// NWC make_invoice: wallet generates invoice directly — no lightning address needed
|
|
838
|
+
const result = await nwcMakeInvoice(state.nwcParsed, amount * 1000, `2020117 session ${session.sessionId}`);
|
|
839
|
+
bolt11 = result.bolt11;
|
|
840
|
+
}
|
|
841
|
+
else {
|
|
842
|
+
// Fallback: LNURL-pay via lightning address
|
|
843
|
+
bolt11 = await generateInvoice(LIGHTNING_ADDRESS, amount);
|
|
844
|
+
}
|
|
840
845
|
node.send(session.socket, {
|
|
841
846
|
type: 'session_tick',
|
|
842
847
|
id: tickId,
|
|
@@ -877,8 +882,8 @@ async function startSwarmListener(label) {
|
|
|
877
882
|
if (msg.type === 'session_start') {
|
|
878
883
|
const processorUrl = process.env.PROCESSOR || '';
|
|
879
884
|
const proxyMode = processorUrl.startsWith('http://') || processorUrl.startsWith('https://');
|
|
880
|
-
if (!proxyMode && !LIGHTNING_ADDRESS) {
|
|
881
|
-
node.send(socket, { type: 'error', id: msg.id, message: 'Provider
|
|
885
|
+
if (!proxyMode && !LIGHTNING_ADDRESS && !state.nwcParsed) {
|
|
886
|
+
node.send(socket, { type: 'error', id: msg.id, message: 'Provider payment not configured (need --lightning-address or --nwc)' });
|
|
882
887
|
return;
|
|
883
888
|
}
|
|
884
889
|
const paymentMethod = 'invoice';
|
|
@@ -916,7 +921,7 @@ async function startSwarmListener(label) {
|
|
|
916
921
|
pubkey: state.sovereignKeys?.pubkey,
|
|
917
922
|
});
|
|
918
923
|
if (proxyMode) {
|
|
919
|
-
if (billingAmount <= 0 || !LIGHTNING_ADDRESS) {
|
|
924
|
+
if (billingAmount <= 0 || (!LIGHTNING_ADDRESS && !state.nwcParsed)) {
|
|
920
925
|
// Free proxy — open TCP pipe immediately
|
|
921
926
|
startTcpProxy(session, node, processorUrl, label);
|
|
922
927
|
}
|