openclaw-overlay-plugin 0.8.15 → 0.8.17

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 (191) hide show
  1. package/dist/index.js +3037 -328
  2. package/dist/index.js.map +7 -0
  3. package/dist/src/cli.js +3820 -11
  4. package/dist/src/cli.js.map +7 -0
  5. package/index.ts +32 -27
  6. package/openclaw.plugin.json +1 -1
  7. package/package.json +8 -6
  8. package/src/scripts/messaging/handlers.ts +1 -1
  9. package/src/scripts/overlay/advertisement.ts +1 -1
  10. package/src/scripts/overlay/registration.ts +1 -1
  11. package/src/scripts/overlay/services.ts +1 -1
  12. package/src/scripts/overlay/transaction.ts +1 -1
  13. package/src/scripts/payment/build.ts +1 -1
  14. package/src/scripts/payment/commands.ts +1 -1
  15. package/src/scripts/wallet/balance.ts +1 -1
  16. package/src/scripts/wallet/setup.ts +1 -1
  17. package/src/scripts/x-verification/commands.ts +5 -0
  18. package/src/test/identity-consistency.test.ts +1 -1
  19. package/src/test/wallet.test.ts +1 -2
  20. package/dist/index.d.ts +0 -9
  21. package/dist/src/cli-main.d.ts +0 -7
  22. package/dist/src/cli-main.js +0 -202
  23. package/dist/src/cli.d.ts +0 -8
  24. package/dist/src/compatibility.test.d.ts +0 -4
  25. package/dist/src/compatibility.test.js +0 -41
  26. package/dist/src/core/config.d.ts +0 -11
  27. package/dist/src/core/config.js +0 -15
  28. package/dist/src/core/index.d.ts +0 -25
  29. package/dist/src/core/index.js +0 -26
  30. package/dist/src/core/payment.d.ts +0 -16
  31. package/dist/src/core/payment.js +0 -94
  32. package/dist/src/core/types.d.ts +0 -94
  33. package/dist/src/core/types.js +0 -4
  34. package/dist/src/core/verify.d.ts +0 -28
  35. package/dist/src/core/verify.js +0 -104
  36. package/dist/src/core/wallet.d.ts +0 -105
  37. package/dist/src/core/wallet.js +0 -256
  38. package/dist/src/scripts/baemail/commands.d.ts +0 -35
  39. package/dist/src/scripts/baemail/commands.js +0 -282
  40. package/dist/src/scripts/baemail/handler.d.ts +0 -36
  41. package/dist/src/scripts/baemail/handler.js +0 -284
  42. package/dist/src/scripts/baemail/index.d.ts +0 -5
  43. package/dist/src/scripts/baemail/index.js +0 -5
  44. package/dist/src/scripts/config.d.ts +0 -52
  45. package/dist/src/scripts/config.js +0 -75
  46. package/dist/src/scripts/index.d.ts +0 -7
  47. package/dist/src/scripts/index.js +0 -7
  48. package/dist/src/scripts/messaging/connect.d.ts +0 -8
  49. package/dist/src/scripts/messaging/connect.js +0 -168
  50. package/dist/src/scripts/messaging/handlers.d.ts +0 -21
  51. package/dist/src/scripts/messaging/handlers.js +0 -334
  52. package/dist/src/scripts/messaging/inbox.d.ts +0 -11
  53. package/dist/src/scripts/messaging/inbox.js +0 -51
  54. package/dist/src/scripts/messaging/index.d.ts +0 -8
  55. package/dist/src/scripts/messaging/index.js +0 -8
  56. package/dist/src/scripts/messaging/poll.d.ts +0 -7
  57. package/dist/src/scripts/messaging/poll.js +0 -52
  58. package/dist/src/scripts/messaging/send.d.ts +0 -7
  59. package/dist/src/scripts/messaging/send.js +0 -43
  60. package/dist/src/scripts/output.d.ts +0 -13
  61. package/dist/src/scripts/output.js +0 -28
  62. package/dist/src/scripts/overlay/advertisement.d.ts +0 -16
  63. package/dist/src/scripts/overlay/advertisement.js +0 -122
  64. package/dist/src/scripts/overlay/discover.d.ts +0 -7
  65. package/dist/src/scripts/overlay/discover.js +0 -74
  66. package/dist/src/scripts/overlay/index.d.ts +0 -7
  67. package/dist/src/scripts/overlay/index.js +0 -7
  68. package/dist/src/scripts/overlay/registration.d.ts +0 -19
  69. package/dist/src/scripts/overlay/registration.js +0 -176
  70. package/dist/src/scripts/overlay/services.d.ts +0 -29
  71. package/dist/src/scripts/overlay/services.js +0 -167
  72. package/dist/src/scripts/overlay/transaction.d.ts +0 -42
  73. package/dist/src/scripts/overlay/transaction.js +0 -103
  74. package/dist/src/scripts/payment/build.d.ts +0 -24
  75. package/dist/src/scripts/payment/build.js +0 -54
  76. package/dist/src/scripts/payment/commands.d.ts +0 -15
  77. package/dist/src/scripts/payment/commands.js +0 -73
  78. package/dist/src/scripts/payment/index.d.ts +0 -6
  79. package/dist/src/scripts/payment/index.js +0 -6
  80. package/dist/src/scripts/payment/types.d.ts +0 -56
  81. package/dist/src/scripts/payment/types.js +0 -4
  82. package/dist/src/scripts/services/index.d.ts +0 -6
  83. package/dist/src/scripts/services/index.js +0 -6
  84. package/dist/src/scripts/services/queue.d.ts +0 -11
  85. package/dist/src/scripts/services/queue.js +0 -28
  86. package/dist/src/scripts/services/request.d.ts +0 -7
  87. package/dist/src/scripts/services/request.js +0 -82
  88. package/dist/src/scripts/services/respond.d.ts +0 -11
  89. package/dist/src/scripts/services/respond.js +0 -132
  90. package/dist/src/scripts/types.d.ts +0 -107
  91. package/dist/src/scripts/types.js +0 -4
  92. package/dist/src/scripts/utils/index.d.ts +0 -6
  93. package/dist/src/scripts/utils/index.js +0 -6
  94. package/dist/src/scripts/utils/merkle.d.ts +0 -12
  95. package/dist/src/scripts/utils/merkle.js +0 -47
  96. package/dist/src/scripts/utils/storage.d.ts +0 -66
  97. package/dist/src/scripts/utils/storage.js +0 -211
  98. package/dist/src/scripts/utils/woc.d.ts +0 -26
  99. package/dist/src/scripts/utils/woc.js +0 -91
  100. package/dist/src/scripts/wallet/balance.d.ts +0 -22
  101. package/dist/src/scripts/wallet/balance.js +0 -240
  102. package/dist/src/scripts/wallet/identity.d.ts +0 -71
  103. package/dist/src/scripts/wallet/identity.js +0 -152
  104. package/dist/src/scripts/wallet/index.d.ts +0 -6
  105. package/dist/src/scripts/wallet/index.js +0 -6
  106. package/dist/src/scripts/wallet/setup.d.ts +0 -19
  107. package/dist/src/scripts/wallet/setup.js +0 -119
  108. package/dist/src/scripts/x-verification/commands.d.ts +0 -27
  109. package/dist/src/scripts/x-verification/commands.js +0 -222
  110. package/dist/src/scripts/x-verification/index.d.ts +0 -4
  111. package/dist/src/scripts/x-verification/index.js +0 -4
  112. package/dist/src/services/built-in/api-proxy/index.d.ts +0 -6
  113. package/dist/src/services/built-in/api-proxy/index.js +0 -23
  114. package/dist/src/services/built-in/code-develop/index.d.ts +0 -6
  115. package/dist/src/services/built-in/code-develop/index.js +0 -23
  116. package/dist/src/services/built-in/code-review/index.d.ts +0 -10
  117. package/dist/src/services/built-in/code-review/index.js +0 -51
  118. package/dist/src/services/built-in/image-analysis/index.d.ts +0 -6
  119. package/dist/src/services/built-in/image-analysis/index.js +0 -33
  120. package/dist/src/services/built-in/memory-store/index.d.ts +0 -6
  121. package/dist/src/services/built-in/memory-store/index.js +0 -22
  122. package/dist/src/services/built-in/roulette/index.d.ts +0 -6
  123. package/dist/src/services/built-in/roulette/index.js +0 -27
  124. package/dist/src/services/built-in/summarize/index.d.ts +0 -6
  125. package/dist/src/services/built-in/summarize/index.js +0 -21
  126. package/dist/src/services/built-in/tell-joke/handler.d.ts +0 -7
  127. package/dist/src/services/built-in/tell-joke/handler.js +0 -122
  128. package/dist/src/services/built-in/tell-joke/index.d.ts +0 -9
  129. package/dist/src/services/built-in/tell-joke/index.js +0 -31
  130. package/dist/src/services/built-in/translate/index.d.ts +0 -6
  131. package/dist/src/services/built-in/translate/index.js +0 -21
  132. package/dist/src/services/built-in/web-research/index.d.ts +0 -9
  133. package/dist/src/services/built-in/web-research/index.js +0 -51
  134. package/dist/src/services/index.d.ts +0 -13
  135. package/dist/src/services/index.js +0 -14
  136. package/dist/src/services/loader.d.ts +0 -77
  137. package/dist/src/services/loader.js +0 -292
  138. package/dist/src/services/manager.d.ts +0 -86
  139. package/dist/src/services/manager.js +0 -255
  140. package/dist/src/services/registry.d.ts +0 -98
  141. package/dist/src/services/registry.js +0 -204
  142. package/dist/src/services/types.d.ts +0 -230
  143. package/dist/src/services/types.js +0 -30
  144. package/dist/src/test/cli.test.d.ts +0 -7
  145. package/dist/src/test/cli.test.js +0 -330
  146. package/dist/src/test/comprehensive-overlay.test.d.ts +0 -13
  147. package/dist/src/test/comprehensive-overlay.test.js +0 -593
  148. package/dist/src/test/identity-consistency.test.d.ts +0 -6
  149. package/dist/src/test/identity-consistency.test.js +0 -60
  150. package/dist/src/test/key-derivation.test.d.ts +0 -12
  151. package/dist/src/test/key-derivation.test.js +0 -86
  152. package/dist/src/test/network-address.test.d.ts +0 -9
  153. package/dist/src/test/network-address.test.js +0 -37
  154. package/dist/src/test/overlay-submit.test.d.ts +0 -10
  155. package/dist/src/test/overlay-submit.test.js +0 -460
  156. package/dist/src/test/request-response-flow.test.d.ts +0 -5
  157. package/dist/src/test/request-response-flow.test.js +0 -210
  158. package/dist/src/test/service-system.test.d.ts +0 -5
  159. package/dist/src/test/service-system.test.js +0 -190
  160. package/dist/src/test/taskflow.test.d.ts +0 -7
  161. package/dist/src/test/taskflow.test.js +0 -82
  162. package/dist/src/test/utils/server-logic.d.ts +0 -98
  163. package/dist/src/test/utils/server-logic.js +0 -286
  164. package/dist/src/test/wallet.test.d.ts +0 -7
  165. package/dist/src/test/wallet.test.js +0 -146
  166. package/src/core/README.md +0 -246
  167. package/src/core/config.d.ts +0 -12
  168. package/src/core/config.d.ts.map +0 -1
  169. package/src/core/config.js +0 -14
  170. package/src/core/config.js.map +0 -1
  171. package/src/core/config.ts +0 -22
  172. package/src/core/index.ts +0 -42
  173. package/src/core/payment.d.ts +0 -17
  174. package/src/core/payment.d.ts.map +0 -1
  175. package/src/core/payment.js +0 -95
  176. package/src/core/payment.js.map +0 -1
  177. package/src/core/payment.ts +0 -111
  178. package/src/core/types.d.ts +0 -95
  179. package/src/core/types.d.ts.map +0 -1
  180. package/src/core/types.js +0 -5
  181. package/src/core/types.js.map +0 -1
  182. package/src/core/types.ts +0 -102
  183. package/src/core/verify.d.ts +0 -29
  184. package/src/core/verify.d.ts.map +0 -1
  185. package/src/core/verify.js +0 -105
  186. package/src/core/verify.js.map +0 -1
  187. package/src/core/verify.ts +0 -119
  188. package/src/core/wallet.d.ts +0 -100
  189. package/src/core/wallet.d.ts.map +0 -1
  190. package/src/core/wallet.js.map +0 -1
  191. package/src/core/wallet.ts +0 -323
@@ -1,103 +0,0 @@
1
- /**
2
- * Overlay transaction building utilities.
3
- *
4
- * Follows the openclaw-overlay server API:
5
- * - Submit: POST /submit with binary BEEF and X-Topics header
6
- * - OP_RETURN format: OP_FALSE OP_RETURN <"clawdbot-overlay-v1"> <JSON>
7
- */
8
- import { NETWORK, OVERLAY_URL, PROTOCOL_ID, WALLET_DIR } from '../config.js';
9
- import { Utils, PushDrop, Transaction } from '@bsv/sdk';
10
- import { BSVAgentWallet } from '../../core/wallet.js';
11
- /**
12
- * Build an PushDrop locking script with JSON payload using SDK's Script class.
13
- *
14
- * @param payload - The data to embed in the OP_RETURN
15
- * @returns A proper Script object that the SDK can serialize
16
- */
17
- export async function buildPushDropScript(wallet, payload) {
18
- const jsonBytes = Utils.toArray(JSON.stringify(payload), 'utf8');
19
- const fields = [jsonBytes];
20
- const token = new PushDrop(wallet._setup.wallet);
21
- const script = await token.lock(fields, [0, PROTOCOL_ID], '1', 'self', true, true);
22
- return script.toHex();
23
- }
24
- /**
25
- * Build and submit an overlay transaction.
26
- * @param payload - JSON data to store in OP_RETURN
27
- * @param topic - Topic manager for submission
28
- * @returns Transaction result with txid and funding info
29
- */
30
- export async function buildRealOverlayTransaction(payload, topic) {
31
- const wallet = await BSVAgentWallet.load({ network: NETWORK, storageDir: WALLET_DIR });
32
- const lockingScript = await buildPushDropScript(wallet, payload);
33
- const response = await wallet._setup.wallet.createAction({
34
- description: 'topic manager submission',
35
- outputs: [
36
- {
37
- lockingScript,
38
- satoshis: 1,
39
- outputDescription: 'overlay',
40
- basket: topic, // basket is the topic manager
41
- }
42
- ],
43
- options: {
44
- acceptDelayedBroadcast: false,
45
- }
46
- });
47
- // --- Submit to overlay ---
48
- // Use binary BEEF with X-Topics header (matches openclaw-overlay server API)
49
- const submitResp = await fetch(`${OVERLAY_URL}/submit`, {
50
- method: 'POST',
51
- headers: {
52
- 'Content-Type': 'application/octet-stream',
53
- 'X-Topics': JSON.stringify([topic]),
54
- },
55
- body: new Uint8Array(response.tx),
56
- });
57
- if (!submitResp.ok) {
58
- const errText = await submitResp.text();
59
- throw new Error(`Overlay submission failed: ${submitResp.status} — ${errText}`);
60
- }
61
- const wocNet = NETWORK === 'mainnet' ? '' : 'test.';
62
- return {
63
- txid: response.txid,
64
- funded: 'stored-beef',
65
- explorer: `https://${wocNet}whatsonchain.com/tx/${response.txid}`,
66
- };
67
- }
68
- /**
69
- * Lookup data from an overlay lookup service.
70
- */
71
- export async function lookupOverlay(service, query) {
72
- const resp = await fetch(`${OVERLAY_URL}/lookup`, {
73
- method: 'POST',
74
- headers: { 'Content-Type': 'application/json' },
75
- body: JSON.stringify({ service, query }),
76
- });
77
- if (!resp.ok) {
78
- const errText = await resp.text();
79
- throw new Error(`Lookup failed: ${resp.status} — ${errText}`);
80
- }
81
- return resp.json();
82
- }
83
- /**
84
- * Parse an overlay output from BEEF data.
85
- *
86
- * Handles both formats:
87
- * - OP_FALSE OP_RETURN <protocol> <json> (standard)
88
- * - OP_RETURN <protocol> <json> (legacy)
89
- */
90
- export async function parseOverlayOutput(beefData, outputIndex) {
91
- try {
92
- const tx = Transaction.fromBEEF(beefData);
93
- const txid = tx.id('hex');
94
- const output = tx.outputs[outputIndex];
95
- if (!output)
96
- return { data: null, txid: null };
97
- const { fields } = PushDrop.decode(output.lockingScript);
98
- return { data: JSON.parse(Utils.toUTF8(fields[0])), txid };
99
- }
100
- catch {
101
- return { data: null, txid: null };
102
- }
103
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * Payment building using a2a-bsv wallet.createPayment().
3
- *
4
- * This replaces the old buildDirectPayment() which used plain P2PKH scripts
5
- * and manual UTXO management. The new implementation:
6
- * - Uses proper BRC-29 locking scripts via wallet.createPayment()
7
- * - Relies on wallet's createAction() for UTXO management
8
- * - Uses noSend: true (recipient broadcasts via acceptPayment())
9
- */
10
- import type { PaymentResult } from './types.js';
11
- /**
12
- * Build a BRC-29 payment using the a2a-bsv wallet.
13
- *
14
- * This creates a payment transaction using proper BRC-29 locking scripts.
15
- * The transaction uses noSend: true, meaning:
16
- * - The sender does NOT broadcast the transaction
17
- * - The recipient broadcasts it when they call acceptPayment()
18
- *
19
- * @param recipientPubKey - Recipient's compressed public key (66 hex chars, 02/03 prefix)
20
- * @param sats - Amount to send in satoshis
21
- * @param desc - Optional description for the payment
22
- * @returns PaymentResult with BEEF and derivation metadata for the recipient
23
- */
24
- export declare function buildDirectPayment(recipientPubKey: string, sats: number, desc?: string): Promise<PaymentResult>;
@@ -1,54 +0,0 @@
1
- /**
2
- * Payment building using a2a-bsv wallet.createPayment().
3
- *
4
- * This replaces the old buildDirectPayment() which used plain P2PKH scripts
5
- * and manual UTXO management. The new implementation:
6
- * - Uses proper BRC-29 locking scripts via wallet.createPayment()
7
- * - Relies on wallet's createAction() for UTXO management
8
- * - Uses noSend: true (recipient broadcasts via acceptPayment())
9
- */
10
- import { NETWORK, WALLET_DIR } from '../config.js';
11
- import { BSVAgentWallet } from '../../core/index.js';
12
- async function getBSVAgentWallet() {
13
- return BSVAgentWallet;
14
- }
15
- /**
16
- * Build a BRC-29 payment using the a2a-bsv wallet.
17
- *
18
- * This creates a payment transaction using proper BRC-29 locking scripts.
19
- * The transaction uses noSend: true, meaning:
20
- * - The sender does NOT broadcast the transaction
21
- * - The recipient broadcasts it when they call acceptPayment()
22
- *
23
- * @param recipientPubKey - Recipient's compressed public key (66 hex chars, 02/03 prefix)
24
- * @param sats - Amount to send in satoshis
25
- * @param desc - Optional description for the payment
26
- * @returns PaymentResult with BEEF and derivation metadata for the recipient
27
- */
28
- export async function buildDirectPayment(recipientPubKey, sats, desc) {
29
- // Validate recipient pubkey format
30
- if (!/^0[23][0-9a-fA-F]{64}$/.test(recipientPubKey)) {
31
- throw new Error('Recipient must be a compressed public key (66 hex chars starting with 02 or 03)');
32
- }
33
- const BSVAgentWallet = await getBSVAgentWallet();
34
- const wallet = await BSVAgentWallet.load({ network: NETWORK, storageDir: WALLET_DIR });
35
- try {
36
- const result = await wallet.createPayment({
37
- to: recipientPubKey,
38
- satoshis: sats,
39
- description: desc || 'agent payment',
40
- });
41
- // Return format compatible with existing code
42
- return {
43
- beef: result.beef,
44
- txid: result.txid,
45
- satoshis: result.satoshis,
46
- derivationPrefix: result.derivationPrefix,
47
- derivationSuffix: result.derivationSuffix,
48
- senderIdentityKey: result.senderIdentityKey,
49
- };
50
- }
51
- finally {
52
- await wallet.destroy();
53
- }
54
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * Payment CLI commands: pay, verify, accept.
3
- */
4
- /**
5
- * Pay command: send satoshis to another agent.
6
- */
7
- export declare function cmdPay(pubkey: string | undefined, satoshis: string | undefined, description?: string): Promise<any>;
8
- /**
9
- * Verify command: verify an incoming payment BEEF.
10
- */
11
- export declare function cmdVerify(beefBase64: string | undefined): Promise<any>;
12
- /**
13
- * Accept command: accept and internalize a payment.
14
- */
15
- export declare function cmdAccept(beef: string | undefined, derivationPrefix: string | undefined, derivationSuffix: string | undefined, senderIdentityKey: string | undefined, description?: string): Promise<any>;
@@ -1,73 +0,0 @@
1
- /**
2
- * Payment CLI commands: pay, verify, accept.
3
- */
4
- import { NETWORK, WALLET_DIR } from '../config.js';
5
- import { ok, fail } from '../output.js';
6
- import { buildDirectPayment } from './build.js';
7
- import { BSVAgentWallet } from '../../core/index.js';
8
- async function getBSVAgentWallet() {
9
- return BSVAgentWallet;
10
- }
11
- /**
12
- * Pay command: send satoshis to another agent.
13
- */
14
- export async function cmdPay(pubkey, satoshis, description) {
15
- if (!pubkey || !satoshis) {
16
- return fail('Usage: pay <pubkey> <satoshis> [description]');
17
- }
18
- const sats = parseInt(satoshis, 10);
19
- if (isNaN(sats) || sats <= 0) {
20
- return fail('satoshis must be a positive integer');
21
- }
22
- try {
23
- const payment = await buildDirectPayment(pubkey, sats, description || 'agent payment');
24
- return ok(payment);
25
- }
26
- catch (err) {
27
- return fail(err instanceof Error ? err.message : String(err));
28
- }
29
- }
30
- /**
31
- * Verify command: verify an incoming payment BEEF.
32
- */
33
- export async function cmdVerify(beefBase64) {
34
- if (!beefBase64) {
35
- return fail('Usage: verify <beef_base64>');
36
- }
37
- const BSVAgentWallet = await getBSVAgentWallet();
38
- const wallet = await BSVAgentWallet.load({ network: NETWORK, storageDir: WALLET_DIR });
39
- try {
40
- const result = wallet.verifyPayment({ beef: beefBase64 });
41
- await wallet.destroy();
42
- return ok(result);
43
- }
44
- catch (err) {
45
- await wallet.destroy();
46
- return fail(err instanceof Error ? err.message : String(err));
47
- }
48
- }
49
- /**
50
- * Accept command: accept and internalize a payment.
51
- */
52
- export async function cmdAccept(beef, derivationPrefix, derivationSuffix, senderIdentityKey, description) {
53
- if (!beef || !derivationPrefix || !derivationSuffix || !senderIdentityKey) {
54
- return fail('Usage: accept <beef> <prefix> <suffix> <senderKey> [description]');
55
- }
56
- const BSVAgentWallet = await getBSVAgentWallet();
57
- const wallet = await BSVAgentWallet.load({ network: NETWORK, storageDir: WALLET_DIR });
58
- try {
59
- const receipt = await wallet.acceptPayment({
60
- beef,
61
- derivationPrefix,
62
- derivationSuffix,
63
- senderIdentityKey,
64
- description: description || undefined,
65
- });
66
- await wallet.destroy();
67
- return ok(receipt);
68
- }
69
- catch (err) {
70
- await wallet.destroy();
71
- return fail(err instanceof Error ? err.message : String(err));
72
- }
73
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * Payment module exports.
3
- */
4
- export * from './types.js';
5
- export * from './build.js';
6
- export * from './commands.js';
@@ -1,6 +0,0 @@
1
- /**
2
- * Payment module exports.
3
- */
4
- export * from './types.js';
5
- export * from './build.js';
6
- export * from './commands.js';
@@ -1,56 +0,0 @@
1
- /**
2
- * Payment-specific type definitions.
3
- */
4
- export interface PaymentResult {
5
- /** Base64-encoded Atomic BEEF transaction data */
6
- beef: string;
7
- /** Transaction ID (hex) */
8
- txid: string;
9
- /** Amount paid in satoshis */
10
- satoshis: number;
11
- /** BRC-29 derivation prefix (base64) - needed by recipient */
12
- derivationPrefix: string;
13
- /** BRC-29 derivation suffix (base64) - needed by recipient */
14
- derivationSuffix: string;
15
- /** Sender's identity key (compressed hex) - needed by recipient */
16
- senderIdentityKey: string;
17
- }
18
- export interface PaymentParams {
19
- /** Recipient's compressed public key (hex, 66 chars starting with 02/03) */
20
- to: string;
21
- /** Amount to pay in satoshis */
22
- satoshis: number;
23
- /** Optional human-readable description */
24
- description?: string;
25
- }
26
- export interface VerifyParams {
27
- /** Base64-encoded BEEF */
28
- beef: string;
29
- /** Expected amount (optional) */
30
- expectedAmount?: number;
31
- /** Expected sender identity key (optional) */
32
- expectedSender?: string;
33
- }
34
- export interface VerifyResult {
35
- valid: boolean;
36
- txid: string;
37
- outputCount: number;
38
- errors: string[];
39
- }
40
- export interface AcceptParams {
41
- /** Base64-encoded Atomic BEEF */
42
- beef: string;
43
- /** Output index (default: 0) */
44
- vout?: number;
45
- /** BRC-29 derivation prefix from PaymentResult */
46
- derivationPrefix: string;
47
- /** BRC-29 derivation suffix from PaymentResult */
48
- derivationSuffix: string;
49
- /** Sender's identity key from PaymentResult */
50
- senderIdentityKey: string;
51
- /** Optional description */
52
- description?: string;
53
- }
54
- export interface AcceptResult {
55
- accepted: boolean;
56
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * Payment-specific type definitions.
3
- */
4
- export {};
@@ -1,6 +0,0 @@
1
- /**
2
- * Services module exports.
3
- */
4
- export * from './request.js';
5
- export * from './respond.js';
6
- export * from './queue.js';
@@ -1,6 +0,0 @@
1
- /**
2
- * Services module exports.
3
- */
4
- export * from './request.js';
5
- export * from './respond.js';
6
- export * from './queue.js';
@@ -1,11 +0,0 @@
1
- /**
2
- * Service queue commands.
3
- */
4
- /**
5
- * Service queue command: list pending service requests.
6
- */
7
- export declare function cmdServiceQueue(): Promise<any>;
8
- /**
9
- * Research queue command: list pending research requests.
10
- */
11
- export declare function cmdResearchQueue(): Promise<any>;
@@ -1,28 +0,0 @@
1
- /**
2
- * Service queue commands.
3
- */
4
- import fs from 'node:fs';
5
- import { PATHS } from '../config.js';
6
- import { ok } from '../output.js';
7
- import { readJsonl } from '../utils/storage.js';
8
- /**
9
- * Service queue command: list pending service requests.
10
- */
11
- export async function cmdServiceQueue() {
12
- if (!fs.existsSync(PATHS.serviceQueue)) {
13
- return ok({ pending: [], count: 0 });
14
- }
15
- const entries = readJsonl(PATHS.serviceQueue);
16
- const pending = entries.filter(e => e.status === 'pending');
17
- return ok({ pending, count: pending.length, total: entries.length });
18
- }
19
- /**
20
- * Research queue command: list pending research requests.
21
- */
22
- export async function cmdResearchQueue() {
23
- if (!fs.existsSync(PATHS.researchQueue)) {
24
- return ok({ pending: [] });
25
- }
26
- const entries = readJsonl(PATHS.researchQueue);
27
- return ok({ pending: entries, count: entries.length });
28
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Service request command.
3
- */
4
- /**
5
- * Request service command: send a service request with optional payment.
6
- */
7
- export declare function cmdRequestService(targetKey: string | undefined, serviceId: string | undefined, satsStr?: string, inputJsonStr?: string): Promise<any>;
@@ -1,82 +0,0 @@
1
- /**
2
- * Service request command.
3
- */
4
- import { OVERLAY_URL } from '../config.js';
5
- import { ok, fail } from '../output.js';
6
- import { loadIdentity, signRelayMessage } from '../wallet/identity.js';
7
- import { buildDirectPayment } from '../payment/build.js';
8
- /**
9
- * Request service command: send a service request with optional payment.
10
- */
11
- export async function cmdRequestService(targetKey, serviceId, satsStr, inputJsonStr) {
12
- if (!targetKey || !serviceId) {
13
- return fail('Usage: request-service <identityKey> <serviceId> [sats] [inputJson]');
14
- }
15
- if (!/^0[23][0-9a-fA-F]{64}$/.test(targetKey)) {
16
- return fail('Target must be a compressed public key (66 hex chars, 02/03 prefix)');
17
- }
18
- const { identityKey, privKey } = await loadIdentity();
19
- const sats = parseInt(satsStr || '5', 10);
20
- // Parse optional input JSON
21
- let inputData = null;
22
- if (inputJsonStr) {
23
- try {
24
- inputData = JSON.parse(inputJsonStr);
25
- }
26
- catch {
27
- return fail('inputJson must be valid JSON');
28
- }
29
- }
30
- // Build the service request payload
31
- let paymentData = null;
32
- if (sats > 0) {
33
- try {
34
- const payment = await buildDirectPayment(targetKey, sats, `service-request: ${serviceId}`);
35
- paymentData = {
36
- beef: payment.beef,
37
- txid: payment.txid,
38
- satoshis: payment.satoshis,
39
- derivationPrefix: payment.derivationPrefix,
40
- derivationSuffix: payment.derivationSuffix,
41
- senderIdentityKey: payment.senderIdentityKey,
42
- };
43
- }
44
- catch (err) {
45
- // Payment failed — send request without payment
46
- paymentData = { error: String(err.message || err) };
47
- }
48
- }
49
- const requestPayload = {
50
- serviceId,
51
- ...(inputData ? { input: inputData } : {}),
52
- payment: paymentData,
53
- requestedAt: new Date().toISOString(),
54
- };
55
- const signature = await signRelayMessage(privKey, targetKey, 'service-request', requestPayload);
56
- const resp = await fetch(`${OVERLAY_URL}/relay/send`, {
57
- method: 'POST',
58
- headers: { 'Content-Type': 'application/json' },
59
- body: JSON.stringify({
60
- from: identityKey,
61
- to: targetKey,
62
- type: 'service-request',
63
- payload: requestPayload,
64
- signature,
65
- }),
66
- });
67
- if (!resp.ok) {
68
- const body = await resp.text();
69
- return fail(`Relay send failed (${resp.status}): ${body}`);
70
- }
71
- const result = await resp.json();
72
- return ok({
73
- sent: true,
74
- requestId: result.id,
75
- to: targetKey,
76
- serviceId,
77
- paymentIncluded: paymentData && !paymentData.error,
78
- paymentTxid: paymentData?.txid || null,
79
- satoshis: paymentData?.satoshis || 0,
80
- note: 'Poll for service-response to get the result',
81
- });
82
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * Service response commands.
3
- */
4
- /**
5
- * Respond to a service request.
6
- */
7
- export declare function cmdRespondService(requestId: string | undefined, recipientKey: string | undefined, serviceId: string | undefined, resultJson: string | undefined): Promise<any>;
8
- /**
9
- * Respond to a research request with results.
10
- */
11
- export declare function cmdResearchRespond(resultJsonPath: string | undefined): Promise<any>;
@@ -1,132 +0,0 @@
1
- /**
2
- * Service response commands.
3
- */
4
- import fs from 'node:fs';
5
- import { OVERLAY_URL, PATHS } from '../config.js';
6
- import { ok, fail } from '../output.js';
7
- import { loadIdentity, signRelayMessage } from '../wallet/identity.js';
8
- import { updateServiceQueueStatus } from '../utils/storage.js';
9
- /**
10
- * Respond to a service request.
11
- */
12
- export async function cmdRespondService(requestId, recipientKey, serviceId, resultJson) {
13
- if (!requestId || !recipientKey || !serviceId || !resultJson) {
14
- return fail('Usage: respond-service <requestId> <recipientKey> <serviceId> <resultJson>');
15
- }
16
- let result;
17
- try {
18
- result = JSON.parse(resultJson);
19
- }
20
- catch {
21
- return fail('resultJson must be valid JSON');
22
- }
23
- const { identityKey, privKey } = await loadIdentity();
24
- // Check if already processed before sending response (idempotency)
25
- if (fs.existsSync(PATHS.serviceQueue)) {
26
- const lines = fs.readFileSync(PATHS.serviceQueue, 'utf-8').trim().split('\n').filter(Boolean);
27
- const finalStatuses = ['fulfilled', 'rejected', 'delivery_failed', 'failed', 'error'];
28
- for (const line of lines) {
29
- try {
30
- const entry = JSON.parse(line);
31
- if (entry.requestId === requestId && finalStatuses.includes(entry.status)) {
32
- return ok({
33
- sent: false,
34
- requestId,
35
- serviceId,
36
- to: recipientKey,
37
- message: `Request already processed with status: ${entry.status}`,
38
- alreadyProcessed: true,
39
- previousStatus: entry.status
40
- });
41
- }
42
- }
43
- catch { }
44
- }
45
- }
46
- const responsePayload = {
47
- requestId,
48
- serviceId,
49
- status: 'fulfilled',
50
- result,
51
- };
52
- const sig = await signRelayMessage(privKey, recipientKey, 'service-response', responsePayload);
53
- const resp = await fetch(`${OVERLAY_URL}/relay/send`, {
54
- method: 'POST',
55
- headers: { 'Content-Type': 'application/json' },
56
- body: JSON.stringify({
57
- from: identityKey,
58
- to: recipientKey,
59
- type: 'service-response',
60
- payload: responsePayload,
61
- signature: sig,
62
- }),
63
- });
64
- if (!resp.ok) {
65
- // Mark as failed in queue using atomic update
66
- updateServiceQueueStatus(requestId, 'failed', {
67
- failedAt: Date.now(),
68
- error: `Relay send failed: ${resp.status}`
69
- });
70
- return fail(`Relay send failed: ${resp.status}`);
71
- }
72
- // Mark as fulfilled in queue using atomic update
73
- updateServiceQueueStatus(requestId, 'fulfilled', {
74
- fulfilledAt: Date.now()
75
- });
76
- return ok({ sent: true, requestId, serviceId, to: recipientKey });
77
- }
78
- /**
79
- * Respond to a research request with results.
80
- */
81
- export async function cmdResearchRespond(resultJsonPath) {
82
- if (!resultJsonPath)
83
- return fail('Usage: research-respond <resultJsonFile>');
84
- if (!fs.existsSync(resultJsonPath))
85
- return fail(`File not found: ${resultJsonPath}`);
86
- const result = JSON.parse(fs.readFileSync(resultJsonPath, 'utf-8'));
87
- const { requestId, from: recipientKey, query, research } = result;
88
- if (!requestId || !recipientKey || !research) {
89
- return fail('Result JSON must have: requestId, from, query, research');
90
- }
91
- const { identityKey, privKey } = await loadIdentity();
92
- const responsePayload = {
93
- requestId,
94
- serviceId: 'web-research',
95
- status: 'fulfilled',
96
- result: research,
97
- paymentAccepted: true,
98
- paymentTxid: result.paymentTxid || null,
99
- satoshisReceived: result.satoshisReceived || 0,
100
- walletAccepted: result.walletAccepted ?? true,
101
- };
102
- const sig = await signRelayMessage(privKey, recipientKey, 'service-response', responsePayload);
103
- const sendResp = await fetch(`${OVERLAY_URL}/relay/send`, {
104
- method: 'POST',
105
- headers: { 'Content-Type': 'application/json' },
106
- body: JSON.stringify({
107
- from: identityKey,
108
- to: recipientKey,
109
- type: 'service-response',
110
- payload: responsePayload,
111
- signature: sig,
112
- }),
113
- });
114
- if (!sendResp.ok) {
115
- return fail(`Failed to send response: ${await sendResp.text()}`);
116
- }
117
- const sendResult = await sendResp.json();
118
- // Remove from queue
119
- if (fs.existsSync(PATHS.researchQueue)) {
120
- const lines = fs.readFileSync(PATHS.researchQueue, 'utf-8').trim().split('\n').filter(Boolean);
121
- const remaining = lines.filter((l) => {
122
- try {
123
- return JSON.parse(l).requestId !== requestId;
124
- }
125
- catch {
126
- return true;
127
- }
128
- });
129
- fs.writeFileSync(PATHS.researchQueue, remaining.length ? remaining.join('\n') + '\n' : '');
130
- }
131
- return ok({ responded: true, requestId, to: recipientKey, query, pushed: sendResult.pushed });
132
- }