2020117-agent 0.2.2 → 0.2.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/dist/api.d.ts CHANGED
@@ -90,3 +90,13 @@ export declare function updateProfile(fields: {
90
90
  about?: string;
91
91
  lightning_address?: string;
92
92
  }): Promise<boolean>;
93
+ export interface ProxyDebitResult {
94
+ ok: boolean;
95
+ preimage?: string;
96
+ error?: string;
97
+ }
98
+ export declare function proxyDebit(opts: {
99
+ ndebit: string;
100
+ lightningAddress: string;
101
+ amountSats: number;
102
+ }): Promise<ProxyDebitResult | null>;
package/dist/api.js CHANGED
@@ -275,3 +275,10 @@ export async function updateProfile(fields) {
275
275
  const result = await apiPut('/api/me', fields);
276
276
  return result !== null;
277
277
  }
278
+ export async function proxyDebit(opts) {
279
+ return apiPost('/api/dvm/proxy-debit', {
280
+ ndebit: opts.ndebit,
281
+ lightning_address: opts.lightningAddress,
282
+ amount_sats: opts.amountSats,
283
+ });
284
+ }
package/dist/clink.d.ts CHANGED
@@ -33,6 +33,11 @@ export declare function generateInvoice(lightningAddress: string, amountSats: nu
33
33
  /**
34
34
  * Full payment cycle: generate invoice from provider's Lightning Address,
35
35
  * then debit customer's wallet via CLINK.
36
+ *
37
+ * Priority: platform proxy (if API key available) → direct debit (if agent key initialized).
38
+ * Proxy uses the platform's pre-authorized CLINK identity, so providers don't need
39
+ * individual DebitAccess on customer wallets. Direct debit works for power users
40
+ * who pre-authorize each other's keys.
36
41
  */
37
42
  export declare function collectPayment(opts: {
38
43
  ndebit: string;
package/dist/clink.js CHANGED
@@ -5,6 +5,7 @@
5
5
  * Invoice generation via LNURL-pay from provider's own Lightning Address.
6
6
  */
7
7
  import { ClinkSDK, decodeBech32, generateSecretKey, getPublicKey, newNdebitPaymentRequest } from '@shocknet/clink-sdk';
8
+ import { hasApiKey, proxyDebit } from './api.js';
8
9
  // --- Agent identity ---
9
10
  let agentKey = null;
10
11
  let agentPubkey = null;
@@ -76,8 +77,27 @@ export async function generateInvoice(lightningAddress, amountSats) {
76
77
  /**
77
78
  * Full payment cycle: generate invoice from provider's Lightning Address,
78
79
  * then debit customer's wallet via CLINK.
80
+ *
81
+ * Priority: platform proxy (if API key available) → direct debit (if agent key initialized).
82
+ * Proxy uses the platform's pre-authorized CLINK identity, so providers don't need
83
+ * individual DebitAccess on customer wallets. Direct debit works for power users
84
+ * who pre-authorize each other's keys.
79
85
  */
80
86
  export async function collectPayment(opts) {
87
+ // Try platform proxy first (provider doesn't need DebitAccess)
88
+ if (hasApiKey()) {
89
+ console.log(`[clink] Proxy debit: ${opts.amountSats} sats → ${opts.lightningAddress}`);
90
+ const result = await proxyDebit({
91
+ ndebit: opts.ndebit,
92
+ lightningAddress: opts.lightningAddress,
93
+ amountSats: opts.amountSats,
94
+ });
95
+ if (result) {
96
+ return { ok: result.ok, preimage: result.preimage, error: result.error };
97
+ }
98
+ console.warn('[clink] Proxy debit unavailable, trying direct...');
99
+ }
100
+ // Fallback: direct debit (requires provider's CLINK key to be authorized)
81
101
  const bolt11 = await generateInvoice(opts.lightningAddress, opts.amountSats);
82
102
  return debitCustomer({
83
103
  ndebit: opts.ndebit,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "2020117-agent",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "2020117 agent runtime — API polling + Hyperswarm P2P + CLINK Lightning payments",
5
5
  "type": "module",
6
6
  "bin": {