2020117-agent 0.6.6 → 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.
Files changed (2) hide show
  1. package/dist/agent.js +16 -6
  2. 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)
@@ -827,11 +827,21 @@ function markSeen(eventId) {
827
827
  }
828
828
  return true;
829
829
  }
830
- /** 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. */
831
832
  async function sendBillingTick(node, session, amount, label) {
832
833
  const tickId = randomBytes(4).toString('hex');
833
834
  try {
834
- const bolt11 = await generateInvoice(LIGHTNING_ADDRESS, amount);
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
+ }
835
845
  node.send(session.socket, {
836
846
  type: 'session_tick',
837
847
  id: tickId,
@@ -872,8 +882,8 @@ async function startSwarmListener(label) {
872
882
  if (msg.type === 'session_start') {
873
883
  const processorUrl = process.env.PROCESSOR || '';
874
884
  const proxyMode = processorUrl.startsWith('http://') || processorUrl.startsWith('https://');
875
- if (!proxyMode && !LIGHTNING_ADDRESS) {
876
- node.send(socket, { type: 'error', id: msg.id, message: 'Provider Lightning Address not configured' });
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)' });
877
887
  return;
878
888
  }
879
889
  const paymentMethod = 'invoice';
@@ -911,7 +921,7 @@ async function startSwarmListener(label) {
911
921
  pubkey: state.sovereignKeys?.pubkey,
912
922
  });
913
923
  if (proxyMode) {
914
- if (billingAmount <= 0 || !LIGHTNING_ADDRESS) {
924
+ if (billingAmount <= 0 || (!LIGHTNING_ADDRESS && !state.nwcParsed)) {
915
925
  // Free proxy — open TCP pipe immediately
916
926
  startTcpProxy(session, node, processorUrl, label);
917
927
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "2020117-agent",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "description": "2020117 agent runtime — Nostr-native relay subscription + Hyperswarm P2P + Lightning payments",
5
5
  "type": "module",
6
6
  "bin": {