2020117-agent 0.6.3 → 0.6.4

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 CHANGED
@@ -82,7 +82,7 @@ for (const arg of process.argv.slice(2)) {
82
82
  import { randomBytes } from 'crypto';
83
83
  import { SwarmNode, topicFromKind } from './swarm.js';
84
84
  import { createProcessor } from './processor.js';
85
- import { generateInvoice } from './clink.js';
85
+ import { generateInvoice } from './lnurl.js';
86
86
  import { generateKeypair, loadSovereignKeys, saveSovereignKeys, loadAgentName, signEvent, signEventWithPow, nip44Encrypt, nip44Decrypt, pubkeyFromPrivkey, RelayPool, } from './nostr.js';
87
87
  import { parseNwcUri, nwcGetBalance, nwcPayLightningAddress } from './nwc.js';
88
88
  import { readFileSync } from 'fs';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Lightning payment utilities — invoice generation via LNURL-pay
3
+ *
4
+ * Provider generates invoices from their own Lightning Address.
5
+ * Customer pays invoices via NWC wallet.
6
+ */
7
+ /**
8
+ * Resolve a Lightning Address to a bolt11 invoice via LNURL-pay protocol.
9
+ * The provider calls this on their OWN Lightning Address to generate
10
+ * an invoice that pays themselves.
11
+ *
12
+ * Flow: address → .well-known/lnurlp → callback?amount= → bolt11
13
+ */
14
+ export declare function generateInvoice(lightningAddress: string, amountSats: number): Promise<string>;
package/dist/lnurl.js ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Lightning payment utilities — invoice generation via LNURL-pay
3
+ *
4
+ * Provider generates invoices from their own Lightning Address.
5
+ * Customer pays invoices via NWC wallet.
6
+ */
7
+ /**
8
+ * Resolve a Lightning Address to a bolt11 invoice via LNURL-pay protocol.
9
+ * The provider calls this on their OWN Lightning Address to generate
10
+ * an invoice that pays themselves.
11
+ *
12
+ * Flow: address → .well-known/lnurlp → callback?amount= → bolt11
13
+ */
14
+ export async function generateInvoice(lightningAddress, amountSats) {
15
+ const [user, domain] = lightningAddress.split('@');
16
+ if (!user || !domain)
17
+ throw new Error(`Invalid Lightning Address: ${lightningAddress}`);
18
+ // Step 1: Fetch LNURL-pay metadata
19
+ const metaUrl = `https://${domain}/.well-known/lnurlp/${user}`;
20
+ const metaResp = await fetch(metaUrl);
21
+ if (!metaResp.ok)
22
+ throw new Error(`LNURL fetch failed: ${metaResp.status} from ${metaUrl}`);
23
+ const meta = await metaResp.json();
24
+ if (meta.tag !== 'payRequest')
25
+ throw new Error(`Not a LNURL-pay endpoint (tag: ${meta.tag})`);
26
+ const amountMsats = amountSats * 1000;
27
+ if (amountMsats < meta.minSendable)
28
+ throw new Error(`Amount ${amountSats} sats below min ${meta.minSendable / 1000} sats`);
29
+ if (amountMsats > meta.maxSendable)
30
+ throw new Error(`Amount ${amountSats} sats above max ${meta.maxSendable / 1000} sats`);
31
+ // Step 2: Request invoice from callback
32
+ const sep = meta.callback.includes('?') ? '&' : '?';
33
+ const invoiceUrl = `${meta.callback}${sep}amount=${amountMsats}`;
34
+ const invoiceResp = await fetch(invoiceUrl);
35
+ if (!invoiceResp.ok)
36
+ throw new Error(`Invoice request failed: ${invoiceResp.status}`);
37
+ const invoiceData = await invoiceResp.json();
38
+ if (!invoiceData.pr)
39
+ throw new Error(`No invoice returned: ${invoiceData.reason || 'unknown error'}`);
40
+ return invoiceData.pr;
41
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "2020117-agent",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "description": "2020117 agent runtime — Nostr-native relay subscription + Hyperswarm P2P + Lightning payments",
5
5
  "type": "module",
6
6
  "bin": {
@@ -18,7 +18,7 @@
18
18
  "exports": {
19
19
  "./processor": "./dist/processor.js",
20
20
  "./swarm": "./dist/swarm.js",
21
- "./lightning": "./dist/clink.js",
21
+ "./lightning": "./dist/lnurl.js",
22
22
  "./nostr": "./dist/nostr.js",
23
23
  "./nwc": "./dist/nwc.js"
24
24
  },