2020117-agent 0.6.11 → 0.6.12

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 +23 -10
  2. package/package.json +1 -1
package/dist/agent.js CHANGED
@@ -413,17 +413,33 @@ async function handleDvmResult(label, event) {
413
413
  return;
414
414
  // Extract job reference, amount, and provider's Lightning Address
415
415
  const requestId = event.tags.find(t => t[0] === 'e')?.[1];
416
- const amountMsats = Number(event.tags.find(t => t[0] === 'amount')?.[1] || '0');
416
+ const amountTag = event.tags.find(t => t[0] === 'amount');
417
+ const amountMsats = Number(amountTag?.[1] || '0');
417
418
  const amountSats = Math.floor(amountMsats / 1000);
418
- const lightningAddress = event.tags.find(t => t[0] === 'lightning_address')?.[1];
419
+ const bolt11 = amountTag?.[2] || null; // NIP-90: ["amount", "<msats>", "<bolt11>"]
420
+ // Providers may use lud16, lightning_address, or lud06 to declare their payment address
421
+ const lightningAddress = event.tags.find(t => t[0] === 'lud16' || t[0] === 'lightning_address')?.[1];
419
422
  console.log(`[${label}] DVM result from ${event.pubkey.slice(0, 8)}: ${event.content.slice(0, 80)}...`);
420
- // Auto-pay if we have NWC and provider has Lightning Address
423
+ // Auto-pay if we have NWC
421
424
  let paid = false;
422
- if (amountSats > 0 && lightningAddress && state.nwcParsed) {
425
+ if (amountSats > 0 && state.nwcParsed) {
423
426
  try {
424
- const { preimage } = await nwcPayLightningAddress(state.nwcParsed, lightningAddress, amountSats);
425
- console.log(`[${label}] Paid ${amountSats} sats ${lightningAddress} (preimage: ${preimage.slice(0, 16)}...)`);
426
- paid = true;
427
+ if (bolt11) {
428
+ // Preferred: pay bolt11 invoice directly from amount tag
429
+ const { nwcPayInvoice } = await import('./nwc.js');
430
+ const { preimage } = await nwcPayInvoice(state.nwcParsed, bolt11);
431
+ console.log(`[${label}] Paid ${amountSats} sats via bolt11 (preimage: ${preimage.slice(0, 16)}...)`);
432
+ paid = true;
433
+ }
434
+ else if (lightningAddress) {
435
+ // Fallback: pay via Lightning Address (lud16 / lightning_address tag)
436
+ const { preimage } = await nwcPayLightningAddress(state.nwcParsed, lightningAddress, amountSats);
437
+ console.log(`[${label}] Paid ${amountSats} sats → ${lightningAddress} (preimage: ${preimage.slice(0, 16)}...)`);
438
+ paid = true;
439
+ }
440
+ else {
441
+ console.warn(`[${label}] Result requires ${amountSats} sats but provider has no bolt11 or Lightning Address`);
442
+ }
427
443
  }
428
444
  catch (e) {
429
445
  console.error(`[${label}] Payment failed: ${e instanceof Error ? e.message : 'Unknown error'}`);
@@ -432,9 +448,6 @@ async function handleDvmResult(label, event) {
432
448
  else if (amountSats === 0) {
433
449
  paid = true; // free job
434
450
  }
435
- else if (amountSats > 0 && !lightningAddress) {
436
- console.warn(`[${label}] Result requires ${amountSats} sats but provider has no Lightning Address`);
437
- }
438
451
  else if (amountSats > 0 && !state.nwcParsed) {
439
452
  console.warn(`[${label}] Result requires ${amountSats} sats but no NWC wallet configured`);
440
453
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "2020117-agent",
3
- "version": "0.6.11",
3
+ "version": "0.6.12",
4
4
  "description": "2020117 agent runtime — Nostr-native relay subscription + Hyperswarm P2P + Lightning payments",
5
5
  "type": "module",
6
6
  "bin": {