openclaw-overlay-plugin 0.8.15 → 0.8.16

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 (189) hide show
  1. package/dist/index.js +6705 -326
  2. package/dist/index.js.map +7 -0
  3. package/dist/src/cli.js +7498 -11
  4. package/dist/src/cli.js.map +7 -0
  5. package/openclaw.plugin.json +1 -1
  6. package/package.json +6 -6
  7. package/src/scripts/messaging/handlers.ts +1 -1
  8. package/src/scripts/overlay/advertisement.ts +1 -1
  9. package/src/scripts/overlay/registration.ts +1 -1
  10. package/src/scripts/overlay/services.ts +1 -1
  11. package/src/scripts/overlay/transaction.ts +1 -1
  12. package/src/scripts/payment/build.ts +1 -1
  13. package/src/scripts/payment/commands.ts +1 -1
  14. package/src/scripts/wallet/balance.ts +1 -1
  15. package/src/scripts/wallet/setup.ts +1 -1
  16. package/src/test/identity-consistency.test.ts +1 -1
  17. package/src/test/wallet.test.ts +1 -2
  18. package/dist/index.d.ts +0 -9
  19. package/dist/src/cli-main.d.ts +0 -7
  20. package/dist/src/cli-main.js +0 -202
  21. package/dist/src/cli.d.ts +0 -8
  22. package/dist/src/compatibility.test.d.ts +0 -4
  23. package/dist/src/compatibility.test.js +0 -41
  24. package/dist/src/core/config.d.ts +0 -11
  25. package/dist/src/core/config.js +0 -15
  26. package/dist/src/core/index.d.ts +0 -25
  27. package/dist/src/core/index.js +0 -26
  28. package/dist/src/core/payment.d.ts +0 -16
  29. package/dist/src/core/payment.js +0 -94
  30. package/dist/src/core/types.d.ts +0 -94
  31. package/dist/src/core/types.js +0 -4
  32. package/dist/src/core/verify.d.ts +0 -28
  33. package/dist/src/core/verify.js +0 -104
  34. package/dist/src/core/wallet.d.ts +0 -105
  35. package/dist/src/core/wallet.js +0 -256
  36. package/dist/src/scripts/baemail/commands.d.ts +0 -35
  37. package/dist/src/scripts/baemail/commands.js +0 -282
  38. package/dist/src/scripts/baemail/handler.d.ts +0 -36
  39. package/dist/src/scripts/baemail/handler.js +0 -284
  40. package/dist/src/scripts/baemail/index.d.ts +0 -5
  41. package/dist/src/scripts/baemail/index.js +0 -5
  42. package/dist/src/scripts/config.d.ts +0 -52
  43. package/dist/src/scripts/config.js +0 -75
  44. package/dist/src/scripts/index.d.ts +0 -7
  45. package/dist/src/scripts/index.js +0 -7
  46. package/dist/src/scripts/messaging/connect.d.ts +0 -8
  47. package/dist/src/scripts/messaging/connect.js +0 -168
  48. package/dist/src/scripts/messaging/handlers.d.ts +0 -21
  49. package/dist/src/scripts/messaging/handlers.js +0 -334
  50. package/dist/src/scripts/messaging/inbox.d.ts +0 -11
  51. package/dist/src/scripts/messaging/inbox.js +0 -51
  52. package/dist/src/scripts/messaging/index.d.ts +0 -8
  53. package/dist/src/scripts/messaging/index.js +0 -8
  54. package/dist/src/scripts/messaging/poll.d.ts +0 -7
  55. package/dist/src/scripts/messaging/poll.js +0 -52
  56. package/dist/src/scripts/messaging/send.d.ts +0 -7
  57. package/dist/src/scripts/messaging/send.js +0 -43
  58. package/dist/src/scripts/output.d.ts +0 -13
  59. package/dist/src/scripts/output.js +0 -28
  60. package/dist/src/scripts/overlay/advertisement.d.ts +0 -16
  61. package/dist/src/scripts/overlay/advertisement.js +0 -122
  62. package/dist/src/scripts/overlay/discover.d.ts +0 -7
  63. package/dist/src/scripts/overlay/discover.js +0 -74
  64. package/dist/src/scripts/overlay/index.d.ts +0 -7
  65. package/dist/src/scripts/overlay/index.js +0 -7
  66. package/dist/src/scripts/overlay/registration.d.ts +0 -19
  67. package/dist/src/scripts/overlay/registration.js +0 -176
  68. package/dist/src/scripts/overlay/services.d.ts +0 -29
  69. package/dist/src/scripts/overlay/services.js +0 -167
  70. package/dist/src/scripts/overlay/transaction.d.ts +0 -42
  71. package/dist/src/scripts/overlay/transaction.js +0 -103
  72. package/dist/src/scripts/payment/build.d.ts +0 -24
  73. package/dist/src/scripts/payment/build.js +0 -54
  74. package/dist/src/scripts/payment/commands.d.ts +0 -15
  75. package/dist/src/scripts/payment/commands.js +0 -73
  76. package/dist/src/scripts/payment/index.d.ts +0 -6
  77. package/dist/src/scripts/payment/index.js +0 -6
  78. package/dist/src/scripts/payment/types.d.ts +0 -56
  79. package/dist/src/scripts/payment/types.js +0 -4
  80. package/dist/src/scripts/services/index.d.ts +0 -6
  81. package/dist/src/scripts/services/index.js +0 -6
  82. package/dist/src/scripts/services/queue.d.ts +0 -11
  83. package/dist/src/scripts/services/queue.js +0 -28
  84. package/dist/src/scripts/services/request.d.ts +0 -7
  85. package/dist/src/scripts/services/request.js +0 -82
  86. package/dist/src/scripts/services/respond.d.ts +0 -11
  87. package/dist/src/scripts/services/respond.js +0 -132
  88. package/dist/src/scripts/types.d.ts +0 -107
  89. package/dist/src/scripts/types.js +0 -4
  90. package/dist/src/scripts/utils/index.d.ts +0 -6
  91. package/dist/src/scripts/utils/index.js +0 -6
  92. package/dist/src/scripts/utils/merkle.d.ts +0 -12
  93. package/dist/src/scripts/utils/merkle.js +0 -47
  94. package/dist/src/scripts/utils/storage.d.ts +0 -66
  95. package/dist/src/scripts/utils/storage.js +0 -211
  96. package/dist/src/scripts/utils/woc.d.ts +0 -26
  97. package/dist/src/scripts/utils/woc.js +0 -91
  98. package/dist/src/scripts/wallet/balance.d.ts +0 -22
  99. package/dist/src/scripts/wallet/balance.js +0 -240
  100. package/dist/src/scripts/wallet/identity.d.ts +0 -71
  101. package/dist/src/scripts/wallet/identity.js +0 -152
  102. package/dist/src/scripts/wallet/index.d.ts +0 -6
  103. package/dist/src/scripts/wallet/index.js +0 -6
  104. package/dist/src/scripts/wallet/setup.d.ts +0 -19
  105. package/dist/src/scripts/wallet/setup.js +0 -119
  106. package/dist/src/scripts/x-verification/commands.d.ts +0 -27
  107. package/dist/src/scripts/x-verification/commands.js +0 -222
  108. package/dist/src/scripts/x-verification/index.d.ts +0 -4
  109. package/dist/src/scripts/x-verification/index.js +0 -4
  110. package/dist/src/services/built-in/api-proxy/index.d.ts +0 -6
  111. package/dist/src/services/built-in/api-proxy/index.js +0 -23
  112. package/dist/src/services/built-in/code-develop/index.d.ts +0 -6
  113. package/dist/src/services/built-in/code-develop/index.js +0 -23
  114. package/dist/src/services/built-in/code-review/index.d.ts +0 -10
  115. package/dist/src/services/built-in/code-review/index.js +0 -51
  116. package/dist/src/services/built-in/image-analysis/index.d.ts +0 -6
  117. package/dist/src/services/built-in/image-analysis/index.js +0 -33
  118. package/dist/src/services/built-in/memory-store/index.d.ts +0 -6
  119. package/dist/src/services/built-in/memory-store/index.js +0 -22
  120. package/dist/src/services/built-in/roulette/index.d.ts +0 -6
  121. package/dist/src/services/built-in/roulette/index.js +0 -27
  122. package/dist/src/services/built-in/summarize/index.d.ts +0 -6
  123. package/dist/src/services/built-in/summarize/index.js +0 -21
  124. package/dist/src/services/built-in/tell-joke/handler.d.ts +0 -7
  125. package/dist/src/services/built-in/tell-joke/handler.js +0 -122
  126. package/dist/src/services/built-in/tell-joke/index.d.ts +0 -9
  127. package/dist/src/services/built-in/tell-joke/index.js +0 -31
  128. package/dist/src/services/built-in/translate/index.d.ts +0 -6
  129. package/dist/src/services/built-in/translate/index.js +0 -21
  130. package/dist/src/services/built-in/web-research/index.d.ts +0 -9
  131. package/dist/src/services/built-in/web-research/index.js +0 -51
  132. package/dist/src/services/index.d.ts +0 -13
  133. package/dist/src/services/index.js +0 -14
  134. package/dist/src/services/loader.d.ts +0 -77
  135. package/dist/src/services/loader.js +0 -292
  136. package/dist/src/services/manager.d.ts +0 -86
  137. package/dist/src/services/manager.js +0 -255
  138. package/dist/src/services/registry.d.ts +0 -98
  139. package/dist/src/services/registry.js +0 -204
  140. package/dist/src/services/types.d.ts +0 -230
  141. package/dist/src/services/types.js +0 -30
  142. package/dist/src/test/cli.test.d.ts +0 -7
  143. package/dist/src/test/cli.test.js +0 -330
  144. package/dist/src/test/comprehensive-overlay.test.d.ts +0 -13
  145. package/dist/src/test/comprehensive-overlay.test.js +0 -593
  146. package/dist/src/test/identity-consistency.test.d.ts +0 -6
  147. package/dist/src/test/identity-consistency.test.js +0 -60
  148. package/dist/src/test/key-derivation.test.d.ts +0 -12
  149. package/dist/src/test/key-derivation.test.js +0 -86
  150. package/dist/src/test/network-address.test.d.ts +0 -9
  151. package/dist/src/test/network-address.test.js +0 -37
  152. package/dist/src/test/overlay-submit.test.d.ts +0 -10
  153. package/dist/src/test/overlay-submit.test.js +0 -460
  154. package/dist/src/test/request-response-flow.test.d.ts +0 -5
  155. package/dist/src/test/request-response-flow.test.js +0 -210
  156. package/dist/src/test/service-system.test.d.ts +0 -5
  157. package/dist/src/test/service-system.test.js +0 -190
  158. package/dist/src/test/taskflow.test.d.ts +0 -7
  159. package/dist/src/test/taskflow.test.js +0 -82
  160. package/dist/src/test/utils/server-logic.d.ts +0 -98
  161. package/dist/src/test/utils/server-logic.js +0 -286
  162. package/dist/src/test/wallet.test.d.ts +0 -7
  163. package/dist/src/test/wallet.test.js +0 -146
  164. package/src/core/README.md +0 -246
  165. package/src/core/config.d.ts +0 -12
  166. package/src/core/config.d.ts.map +0 -1
  167. package/src/core/config.js +0 -14
  168. package/src/core/config.js.map +0 -1
  169. package/src/core/config.ts +0 -22
  170. package/src/core/index.ts +0 -42
  171. package/src/core/payment.d.ts +0 -17
  172. package/src/core/payment.d.ts.map +0 -1
  173. package/src/core/payment.js +0 -95
  174. package/src/core/payment.js.map +0 -1
  175. package/src/core/payment.ts +0 -111
  176. package/src/core/types.d.ts +0 -95
  177. package/src/core/types.d.ts.map +0 -1
  178. package/src/core/types.js +0 -5
  179. package/src/core/types.js.map +0 -1
  180. package/src/core/types.ts +0 -102
  181. package/src/core/verify.d.ts +0 -29
  182. package/src/core/verify.d.ts.map +0 -1
  183. package/src/core/verify.js +0 -105
  184. package/src/core/verify.js.map +0 -1
  185. package/src/core/verify.ts +0 -119
  186. package/src/core/wallet.d.ts +0 -100
  187. package/src/core/wallet.d.ts.map +0 -1
  188. package/src/core/wallet.js.map +0 -1
  189. package/src/core/wallet.ts +0 -323
@@ -1,51 +0,0 @@
1
- /**
2
- * Inbox and ack commands.
3
- */
4
- import { OVERLAY_URL } from '../config.js';
5
- import { ok, fail } from '../output.js';
6
- import { loadIdentity, verifyRelaySignature } from '../wallet/identity.js';
7
- /**
8
- * Inbox command: fetch pending messages.
9
- */
10
- export async function cmdInbox(args) {
11
- const { identityKey } = await loadIdentity();
12
- let since = '';
13
- for (let i = 0; i < args.length; i++) {
14
- if (args[i] === '--since' && args[i + 1])
15
- since = `&since=${args[++i]}`;
16
- }
17
- const resp = await fetch(`${OVERLAY_URL}/relay/inbox?identity=${identityKey}${since}`);
18
- if (!resp.ok) {
19
- const body = await resp.text();
20
- return fail(`Relay inbox failed (${resp.status}): ${body}`);
21
- }
22
- const result = await resp.json();
23
- // Verify signatures on received messages
24
- const messages = await Promise.all(result.messages.map(async (msg) => ({
25
- ...msg,
26
- signatureValid: msg.signature
27
- ? (await verifyRelaySignature(msg.from, msg.to, msg.type, msg.payload, msg.signature)).valid
28
- : null,
29
- })));
30
- return ok({ messages, count: messages.length, identityKey });
31
- }
32
- /**
33
- * Ack command: acknowledge processed messages.
34
- */
35
- export async function cmdAck(messageIds) {
36
- if (!messageIds || messageIds.length === 0) {
37
- return fail('Usage: ack <messageId> [messageId2 ...]');
38
- }
39
- const { identityKey } = await loadIdentity();
40
- const resp = await fetch(`${OVERLAY_URL}/relay/ack`, {
41
- method: 'POST',
42
- headers: { 'Content-Type': 'application/json' },
43
- body: JSON.stringify({ identity: identityKey, messageIds }),
44
- });
45
- if (!resp.ok) {
46
- const body = await resp.text();
47
- return fail(`Relay ack failed (${resp.status}): ${body}`);
48
- }
49
- const result = await resp.json();
50
- return ok({ acked: result.acked, messageIds });
51
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Messaging module exports.
3
- */
4
- export * from './send.js';
5
- export * from './inbox.js';
6
- export * from './handlers.js';
7
- export * from './poll.js';
8
- export * from './connect.js';
@@ -1,8 +0,0 @@
1
- /**
2
- * Messaging module exports.
3
- */
4
- export * from './send.js';
5
- export * from './inbox.js';
6
- export * from './handlers.js';
7
- export * from './poll.js';
8
- export * from './connect.js';
@@ -1,7 +0,0 @@
1
- /**
2
- * Poll command: fetch and process all pending messages.
3
- */
4
- /**
5
- * Poll command: fetch all pending messages and process them.
6
- */
7
- export declare function cmdPoll(): Promise<any>;
@@ -1,52 +0,0 @@
1
- /**
2
- * Poll command: fetch and process all pending messages.
3
- */
4
- import { OVERLAY_URL } from '../config.js';
5
- import { ok, fail } from '../output.js';
6
- import { loadIdentity } from '../wallet/identity.js';
7
- import { processMessage } from './handlers.js';
8
- /**
9
- * Poll command: fetch all pending messages and process them.
10
- */
11
- export async function cmdPoll() {
12
- const { identityKey, privKey } = await loadIdentity();
13
- // Fetch inbox
14
- const inboxResp = await fetch(`${OVERLAY_URL}/relay/inbox?identity=${identityKey}`);
15
- if (!inboxResp.ok) {
16
- const body = await inboxResp.text();
17
- return fail(`Relay inbox failed (${inboxResp.status}): ${body}`);
18
- }
19
- const inbox = await inboxResp.json();
20
- if (inbox.count === 0) {
21
- return ok({ processed: 0, messages: [], summary: 'No pending messages.' });
22
- }
23
- const processed = [];
24
- const ackedIds = [];
25
- const unhandled = [];
26
- for (const msg of inbox.messages) {
27
- const result = await processMessage(msg, identityKey, privKey);
28
- if (result.ack) {
29
- ackedIds.push(result.id);
30
- processed.push(result);
31
- }
32
- else {
33
- unhandled.push(result);
34
- }
35
- }
36
- // ACK processed messages
37
- if (ackedIds.length > 0) {
38
- await fetch(`${OVERLAY_URL}/relay/ack`, {
39
- method: 'POST',
40
- headers: { 'Content-Type': 'application/json' },
41
- body: JSON.stringify({ identity: identityKey, messageIds: ackedIds }),
42
- });
43
- }
44
- return ok({
45
- processed: processed.length,
46
- unhandled: unhandled.length,
47
- total: inbox.count,
48
- messages: processed,
49
- unhandledMessages: unhandled,
50
- ackedIds,
51
- });
52
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Send relay message command.
3
- */
4
- /**
5
- * Send command: send a typed message to another agent.
6
- */
7
- export declare function cmdSend(targetKey: string | undefined, type: string | undefined, payloadStr: string | undefined): Promise<any>;
@@ -1,43 +0,0 @@
1
- /**
2
- * Send relay message 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
- /**
8
- * Send command: send a typed message to another agent.
9
- */
10
- export async function cmdSend(targetKey, type, payloadStr) {
11
- if (!targetKey || !type || !payloadStr) {
12
- return fail('Usage: send <identityKey> <type> <json_payload>');
13
- }
14
- if (!/^0[23][0-9a-fA-F]{64}$/.test(targetKey)) {
15
- return fail('Target must be a compressed public key (66 hex chars, 02/03 prefix)');
16
- }
17
- let payload;
18
- try {
19
- payload = JSON.parse(payloadStr);
20
- }
21
- catch {
22
- return fail('payload must be valid JSON');
23
- }
24
- const { identityKey, privKey } = await loadIdentity();
25
- const signature = await signRelayMessage(privKey, targetKey, type, payload);
26
- const resp = await fetch(`${OVERLAY_URL}/relay/send`, {
27
- method: 'POST',
28
- headers: { 'Content-Type': 'application/json' },
29
- body: JSON.stringify({
30
- from: identityKey,
31
- to: targetKey,
32
- type,
33
- payload,
34
- signature,
35
- }),
36
- });
37
- if (!resp.ok) {
38
- const body = await resp.text();
39
- return fail(`Relay send failed (${resp.status}): ${body}`);
40
- }
41
- const result = await resp.json();
42
- return ok({ sent: true, messageId: result.id, to: targetKey, type, signed: true });
43
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * JSON output helpers for CLI commands.
3
- * All CLI output follows the { success, data/error } wrapper format.
4
- */
5
- export declare function setNoExit(value: boolean): void;
6
- /**
7
- * Output a successful result and exit (unless noExit is set).
8
- */
9
- export declare function ok<T>(data: T): any;
10
- /**
11
- * Output an error and exit (unless noExit is set).
12
- */
13
- export declare function fail(error: string | Error): any;
@@ -1,28 +0,0 @@
1
- /**
2
- * JSON output helpers for CLI commands.
3
- * All CLI output follows the { success, data/error } wrapper format.
4
- */
5
- // Global flag to prevent exit when used as a library
6
- let noExitFlag = false;
7
- export function setNoExit(value) {
8
- noExitFlag = value;
9
- }
10
- /**
11
- * Output a successful result and exit (unless noExit is set).
12
- */
13
- export function ok(data) {
14
- if (noExitFlag)
15
- return { success: true, data };
16
- console.log(JSON.stringify({ success: true, data }));
17
- process.exit(0);
18
- }
19
- /**
20
- * Output an error and exit (unless noExit is set).
21
- */
22
- export function fail(error) {
23
- const message = error instanceof Error ? error.message : String(error);
24
- if (noExitFlag)
25
- return { success: false, error: message };
26
- console.log(JSON.stringify({ success: false, error: message }));
27
- process.exit(1);
28
- }
@@ -1,16 +0,0 @@
1
- /**
2
- * SHIP and SLAP advertisement commands.
3
- *
4
- * SHIP: Service Health & Information Protocol (tm_ship)
5
- * SLAP: Service Level Agreement Protocol (tm_slap)
6
- */
7
- /**
8
- * Advertise a SHIP record.
9
- * Announce that you host a specific Topic Manager (tm_).
10
- */
11
- export declare function cmdAdvertiseSHIP(domain?: string, topic?: string): Promise<any>;
12
- /**
13
- * Advertise a SLAP record.
14
- * Announce that you host a specific Lookup Service (ls_).
15
- */
16
- export declare function cmdAdvertiseSLAP(domain?: string, service?: string): Promise<any>;
@@ -1,122 +0,0 @@
1
- /**
2
- * SHIP and SLAP advertisement commands.
3
- *
4
- * SHIP: Service Health & Information Protocol (tm_ship)
5
- * SLAP: Service Level Agreement Protocol (tm_slap)
6
- */
7
- import { PushDrop, Utils } from '@bsv/sdk';
8
- import { NETWORK, WALLET_DIR, TOPICS, DEFAULT_SLAP_TRACKERS } from '../config.js';
9
- import { BSVAgentWallet } from '../../core/wallet.js';
10
- import { ok, fail } from '../output.js';
11
- /**
12
- * Advertise a SHIP record.
13
- * Announce that you host a specific Topic Manager (tm_).
14
- */
15
- export async function cmdAdvertiseSHIP(domain, topic) {
16
- if (!domain || !topic) {
17
- return fail('Usage: advertise-ship <domain> <topic>');
18
- }
19
- if (!topic.startsWith('tm_')) {
20
- return fail('Topic must start with "tm_"');
21
- }
22
- try {
23
- const wallet = await BSVAgentWallet.load({ network: NETWORK, storageDir: WALLET_DIR });
24
- const token = new PushDrop(wallet._setup.wallet);
25
- // SHIP format: Payload is the domain hosting the topic
26
- const fields = [Utils.toArray(domain, 'utf8')];
27
- // Context is [0, topic] to identify the topic manager being advertised
28
- const lockingScript = (await token.lock(fields, [0, topic], '1', 'self', true, true)).toHex();
29
- const response = await wallet._setup.wallet.createAction({
30
- description: `advertise SHIP for ${topic}`,
31
- outputs: [{
32
- lockingScript,
33
- satoshis: 1,
34
- outputDescription: 'SHIP advertisement',
35
- basket: TOPICS.SHIP
36
- }]
37
- });
38
- // Broadcast to primary overlay and SLAP trackers
39
- const trackers = [
40
- ...DEFAULT_SLAP_TRACKERS[NETWORK]
41
- ];
42
- const results = await broadcastToTrackers(response.tx, [TOPICS.SHIP, topic], trackers);
43
- return ok({
44
- advertised: 'SHIP',
45
- topic,
46
- domain,
47
- txid: response.txid,
48
- broadcasts: results
49
- });
50
- }
51
- catch (err) {
52
- return fail(`SHIP advertisement failed: ${err.message}`);
53
- }
54
- }
55
- /**
56
- * Advertise a SLAP record.
57
- * Announce that you host a specific Lookup Service (ls_).
58
- */
59
- export async function cmdAdvertiseSLAP(domain, service) {
60
- if (!domain || !service) {
61
- return fail('Usage: advertise-slap <domain> <service>');
62
- }
63
- if (!service.startsWith('ls_')) {
64
- return fail('Service must start with "ls_"');
65
- }
66
- try {
67
- const wallet = await BSVAgentWallet.load({ network: NETWORK, storageDir: WALLET_DIR });
68
- const token = new PushDrop(wallet._setup.wallet);
69
- // SLAP format: Payload is the domain hosting the lookup service
70
- const fields = [Utils.toArray(domain, 'utf8')];
71
- // Context is [0, service] to identify the lookup service being advertised
72
- const lockingScript = (await token.lock(fields, [0, service], '1', 'self', true, true)).toHex();
73
- const response = await wallet._setup.wallet.createAction({
74
- description: `advertise SLAP for ${service}`,
75
- outputs: [{
76
- lockingScript,
77
- satoshis: 1,
78
- outputDescription: 'SLAP advertisement',
79
- basket: TOPICS.SLAP
80
- }]
81
- });
82
- // Broadcast to primary overlay and SLAP trackers
83
- const trackers = [
84
- ...DEFAULT_SLAP_TRACKERS[NETWORK]
85
- ];
86
- const results = await broadcastToTrackers(response.tx, [TOPICS.SLAP, service], trackers);
87
- return ok({
88
- advertised: 'SLAP',
89
- service,
90
- domain,
91
- txid: response.txid,
92
- broadcasts: results
93
- });
94
- }
95
- catch (err) {
96
- return fail(`SLAP advertisement failed: ${err.message}`);
97
- }
98
- }
99
- /**
100
- * Helper to broadcast BEEF to multiple trackers/overlays.
101
- */
102
- async function broadcastToTrackers(tx, topics, trackers) {
103
- const results = {};
104
- const body = new Uint8Array(tx);
105
- for (const url of trackers) {
106
- try {
107
- const resp = await fetch(`${url.replace(/\/$/, '')}/submit`, {
108
- method: 'POST',
109
- headers: {
110
- 'Content-Type': 'application/octet-stream',
111
- 'X-Topics': JSON.stringify(topics)
112
- },
113
- body
114
- });
115
- results[url] = resp.ok ? 'success' : `error: ${resp.status}`;
116
- }
117
- catch (err) {
118
- results[url] = `failed: ${err.message}`;
119
- }
120
- }
121
- return results;
122
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Overlay discovery commands.
3
- */
4
- /**
5
- * Discover command: query the overlay for agents and services.
6
- */
7
- export declare function cmdDiscover(args: string[]): Promise<any>;
@@ -1,74 +0,0 @@
1
- /**
2
- * Overlay discovery commands.
3
- */
4
- import { OVERLAY_URL, LOOKUP_SERVICES } from '../config.js';
5
- import { ok } from '../output.js';
6
- import { lookupOverlay, parseOverlayOutput } from './transaction.js';
7
- /**
8
- * Discover command: query the overlay for agents and services.
9
- */
10
- export async function cmdDiscover(args) {
11
- // Parse flags
12
- let serviceFilter = null;
13
- let agentFilter = null;
14
- for (let i = 0; i < args.length; i++) {
15
- if (args[i] === '--service' && args[i + 1])
16
- serviceFilter = args[++i];
17
- else if (args[i] === '--agent' && args[i + 1])
18
- agentFilter = args[++i];
19
- }
20
- const results = { agents: [], services: [] };
21
- // Query agents
22
- if (!serviceFilter) {
23
- try {
24
- const agentQuery = agentFilter ? { name: agentFilter } : { type: 'list' };
25
- const agentResult = await lookupOverlay(LOOKUP_SERVICES.AGENTS, agentQuery);
26
- if (agentResult.outputs) {
27
- for (const output of agentResult.outputs) {
28
- try {
29
- const { data, txid } = await parseOverlayOutput(output.beef, output.outputIndex);
30
- if (data?.type === 'identity') {
31
- // Handle both 'name' and 'agentName' for backward compatibility
32
- const name = data.name || data.agentName || 'Unknown Agent';
33
- results.agents.push({ ...data, name, txid });
34
- }
35
- }
36
- catch { /* ignore */ }
37
- }
38
- }
39
- }
40
- catch (err) {
41
- results.agentError = String(err);
42
- }
43
- }
44
- // Query services
45
- if (!agentFilter) {
46
- try {
47
- const serviceQuery = serviceFilter ? { serviceType: serviceFilter } : {};
48
- const serviceResult = await lookupOverlay(LOOKUP_SERVICES.SERVICES, serviceQuery);
49
- if (serviceResult.outputs) {
50
- for (const output of serviceResult.outputs) {
51
- try {
52
- const { data, txid } = await parseOverlayOutput(output.beef, output.outputIndex);
53
- if (data?.type === 'service') {
54
- results.services.push({ ...data, txid });
55
- }
56
- }
57
- catch { /* ignore */ }
58
- }
59
- }
60
- }
61
- catch (err) {
62
- results.serviceError = String(err);
63
- }
64
- }
65
- return ok({
66
- overlayUrl: OVERLAY_URL,
67
- agentCount: results.agents.length,
68
- serviceCount: results.services.length,
69
- agents: results.agents,
70
- services: results.services,
71
- ...(results.agentError && { agentError: results.agentError }),
72
- ...(results.serviceError && { serviceError: results.serviceError }),
73
- });
74
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Overlay module exports.
3
- */
4
- export * from './transaction.js';
5
- export * from './registration.js';
6
- export * from './services.js';
7
- export * from './discover.js';
@@ -1,7 +0,0 @@
1
- /**
2
- * Overlay module exports.
3
- */
4
- export * from './transaction.js';
5
- export * from './registration.js';
6
- export * from './services.js';
7
- export * from './discover.js';
@@ -1,19 +0,0 @@
1
- /**
2
- * Overlay registration commands: register, unregister.
3
- *
4
- * Registration creates an identity record on the overlay network with:
5
- * - identityKey: compressed public key (66 hex chars)
6
- * - name: agent display name
7
- * - description: what the agent does
8
- * - channels: contact methods (e.g., { overlay: "https://..." })
9
- * - capabilities: what the agent can do (e.g., ["services", "jokes"])
10
- * - timestamp: ISO 8601 registration time
11
- */
12
- /**
13
- * Register command: register this agent on the overlay network.
14
- */
15
- export declare function cmdRegister(): Promise<any>;
16
- /**
17
- * Unregister command: submit revocation tx to remove agent from overlay network.
18
- */
19
- export declare function cmdUnregister(): Promise<any>;
@@ -1,176 +0,0 @@
1
- /**
2
- * Overlay registration commands: register, unregister.
3
- *
4
- * Registration creates an identity record on the overlay network with:
5
- * - identityKey: compressed public key (66 hex chars)
6
- * - name: agent display name
7
- * - description: what the agent does
8
- * - channels: contact methods (e.g., { overlay: "https://..." })
9
- * - capabilities: what the agent can do (e.g., ["services", "jokes"])
10
- * - timestamp: ISO 8601 registration time
11
- */
12
- import fs from 'node:fs';
13
- import { NETWORK, WALLET_DIR, OVERLAY_URL, PROTOCOL_ID, TOPICS, PATHS, AGENT_NAME, AGENT_DESCRIPTION } from '../config.js';
14
- import { ok, fail } from '../output.js';
15
- import { loadRegistration, saveRegistration, deleteRegistration, loadServices } from '../utils/storage.js';
16
- import { buildRealOverlayTransaction } from './transaction.js';
17
- import { Transaction, Beef, Script, PushDrop } from '@bsv/sdk';
18
- import { BSVAgentWallet } from '../../core/index.js';
19
- async function getBSVAgentWallet() {
20
- return BSVAgentWallet;
21
- }
22
- /**
23
- * Register command: register this agent on the overlay network.
24
- */
25
- export async function cmdRegister() {
26
- if (!fs.existsSync(PATHS.walletIdentity)) {
27
- return fail('Wallet not initialized. Run: setup');
28
- }
29
- const BSVAgentWallet = await getBSVAgentWallet();
30
- const wallet = await BSVAgentWallet.load({ network: NETWORK, storageDir: WALLET_DIR });
31
- const identityKey = await wallet.getIdentityKey();
32
- await wallet.destroy();
33
- const existingReg = loadRegistration();
34
- if (existingReg && existingReg.identityKey === identityKey) {
35
- return ok({
36
- alreadyRegistered: true,
37
- identityKey,
38
- identityTxid: existingReg.identityTxid,
39
- overlayUrl: OVERLAY_URL,
40
- });
41
- }
42
- // Agent metadata from environment/config
43
- const agentName = AGENT_NAME;
44
- const agentDescription = AGENT_DESCRIPTION;
45
- // Build capabilities list based on what services we might offer
46
- const capabilities = ['services'];
47
- const services = loadServices();
48
- if (services.some(s => s.serviceId === 'tell-joke')) {
49
- capabilities.push('jokes');
50
- }
51
- // Create identity record on-chain
52
- // This payload format matches the openclaw-overlay server's expected schema
53
- const identityPayload = {
54
- protocol: PROTOCOL_ID,
55
- type: 'identity',
56
- identityKey,
57
- name: agentName,
58
- description: agentDescription,
59
- channels: {
60
- overlay: OVERLAY_URL,
61
- },
62
- capabilities,
63
- timestamp: new Date().toISOString(),
64
- };
65
- let identityResult;
66
- try {
67
- identityResult = await buildRealOverlayTransaction(identityPayload, TOPICS.IDENTITY);
68
- }
69
- catch (err) {
70
- return fail(`Registration failed: ${err.message}`);
71
- }
72
- // Optionally register services if pre-configured
73
- let serviceTxid = null;
74
- if (services.length > 0) {
75
- // Register each service individually (server expects 'service' type, not 'service-bundle')
76
- for (const service of services) {
77
- const servicePayload = {
78
- protocol: PROTOCOL_ID,
79
- type: 'service',
80
- identityKey,
81
- serviceId: service.serviceId,
82
- name: service.name,
83
- description: service.description,
84
- pricing: {
85
- model: 'per-task',
86
- amountSats: service.priceSats,
87
- },
88
- timestamp: new Date().toISOString(),
89
- };
90
- try {
91
- const serviceResult = await buildRealOverlayTransaction(servicePayload, TOPICS.SERVICES);
92
- serviceTxid = serviceResult.txid; // Keep last one for backward compat
93
- }
94
- catch {
95
- // Non-fatal — identity registered but this service failed
96
- }
97
- }
98
- }
99
- // Save registration
100
- const registration = {
101
- identityKey,
102
- agentName,
103
- agentDescription,
104
- overlayUrl: OVERLAY_URL,
105
- identityTxid: identityResult.txid,
106
- serviceTxid,
107
- funded: identityResult.funded,
108
- registeredAt: new Date().toISOString(),
109
- };
110
- saveRegistration(registration);
111
- return ok({
112
- registered: true,
113
- identityKey,
114
- identityTxid: identityResult.txid,
115
- serviceTxid,
116
- overlayUrl: OVERLAY_URL,
117
- funded: identityResult.funded,
118
- stateFile: PATHS.registration,
119
- });
120
- }
121
- /**
122
- * Unregister command: submit revocation tx to remove agent from overlay network.
123
- */
124
- export async function cmdUnregister() {
125
- const wallet = await BSVAgentWallet.load({ network: NETWORK, storageDir: WALLET_DIR });
126
- const { outputs, BEEF } = await wallet._setup.wallet.listOutputs({ basket: TOPICS.IDENTITY, include: 'entire transactions' });
127
- const token = new PushDrop(wallet._setup.wallet);
128
- const unlockingScriptTemplate = await token.unlock([0, PROTOCOL_ID], '1', 'self', 'none', true);
129
- const tempTx = new Transaction();
130
- const beef = Beef.fromBinary(BEEF);
131
- outputs.forEach((o) => {
132
- const [txid, v] = o.outpoint.split('.');
133
- const sourceOutputIndex = Number(v);
134
- const sourceTransaction = beef.findTransactionForSigning(txid);
135
- tempTx.addInput({
136
- unlockingScriptTemplate,
137
- sourceOutputIndex,
138
- sourceTransaction
139
- });
140
- });
141
- tempTx.addOutput({
142
- lockingScript: Script.fromASM('OP_FALSE OP_RETURN 330123'),
143
- satoshis: 0
144
- });
145
- await tempTx.sign();
146
- const response = await wallet._setup.wallet.createAction({
147
- inputBEEF: BEEF,
148
- description: 'revoke registration token',
149
- inputs: tempTx.inputs.map(o => ({
150
- inputDescription: 'previous registration',
151
- outpoint: o.sourceTXID + '.' + String(o.sourceOutputIndex),
152
- unlockingScript: o.unlockingScript?.toHex()
153
- }))
154
- });
155
- const txid = response.txid;
156
- // --- Submit to overlay ---
157
- // Use binary BEEF with X-Topics header (matches openclaw-overlay server API)
158
- const submitResp = await fetch(`${OVERLAY_URL}/submit`, {
159
- method: 'POST',
160
- headers: {
161
- 'Content-Type': 'application/octet-stream',
162
- 'X-Topics': JSON.stringify([TOPICS.IDENTITY]),
163
- },
164
- body: new Uint8Array(response.tx),
165
- });
166
- if (!submitResp.ok) {
167
- const errText = await submitResp.text();
168
- throw new Error(`Overlay submission failed: ${submitResp.status} — ${errText}`);
169
- }
170
- // Delete local registration
171
- deleteRegistration();
172
- return ok({
173
- unregistered: true,
174
- txid
175
- });
176
- }