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.
- package/dist/index.js +3037 -328
- package/dist/index.js.map +7 -0
- package/dist/src/cli.js +3820 -11
- package/dist/src/cli.js.map +7 -0
- package/index.ts +32 -27
- package/openclaw.plugin.json +1 -1
- package/package.json +8 -6
- package/src/scripts/messaging/handlers.ts +1 -1
- package/src/scripts/overlay/advertisement.ts +1 -1
- package/src/scripts/overlay/registration.ts +1 -1
- package/src/scripts/overlay/services.ts +1 -1
- package/src/scripts/overlay/transaction.ts +1 -1
- package/src/scripts/payment/build.ts +1 -1
- package/src/scripts/payment/commands.ts +1 -1
- package/src/scripts/wallet/balance.ts +1 -1
- package/src/scripts/wallet/setup.ts +1 -1
- package/src/scripts/x-verification/commands.ts +5 -0
- package/src/test/identity-consistency.test.ts +1 -1
- package/src/test/wallet.test.ts +1 -2
- package/dist/index.d.ts +0 -9
- package/dist/src/cli-main.d.ts +0 -7
- package/dist/src/cli-main.js +0 -202
- package/dist/src/cli.d.ts +0 -8
- package/dist/src/compatibility.test.d.ts +0 -4
- package/dist/src/compatibility.test.js +0 -41
- package/dist/src/core/config.d.ts +0 -11
- package/dist/src/core/config.js +0 -15
- package/dist/src/core/index.d.ts +0 -25
- package/dist/src/core/index.js +0 -26
- package/dist/src/core/payment.d.ts +0 -16
- package/dist/src/core/payment.js +0 -94
- package/dist/src/core/types.d.ts +0 -94
- package/dist/src/core/types.js +0 -4
- package/dist/src/core/verify.d.ts +0 -28
- package/dist/src/core/verify.js +0 -104
- package/dist/src/core/wallet.d.ts +0 -105
- package/dist/src/core/wallet.js +0 -256
- package/dist/src/scripts/baemail/commands.d.ts +0 -35
- package/dist/src/scripts/baemail/commands.js +0 -282
- package/dist/src/scripts/baemail/handler.d.ts +0 -36
- package/dist/src/scripts/baemail/handler.js +0 -284
- package/dist/src/scripts/baemail/index.d.ts +0 -5
- package/dist/src/scripts/baemail/index.js +0 -5
- package/dist/src/scripts/config.d.ts +0 -52
- package/dist/src/scripts/config.js +0 -75
- package/dist/src/scripts/index.d.ts +0 -7
- package/dist/src/scripts/index.js +0 -7
- package/dist/src/scripts/messaging/connect.d.ts +0 -8
- package/dist/src/scripts/messaging/connect.js +0 -168
- package/dist/src/scripts/messaging/handlers.d.ts +0 -21
- package/dist/src/scripts/messaging/handlers.js +0 -334
- package/dist/src/scripts/messaging/inbox.d.ts +0 -11
- package/dist/src/scripts/messaging/inbox.js +0 -51
- package/dist/src/scripts/messaging/index.d.ts +0 -8
- package/dist/src/scripts/messaging/index.js +0 -8
- package/dist/src/scripts/messaging/poll.d.ts +0 -7
- package/dist/src/scripts/messaging/poll.js +0 -52
- package/dist/src/scripts/messaging/send.d.ts +0 -7
- package/dist/src/scripts/messaging/send.js +0 -43
- package/dist/src/scripts/output.d.ts +0 -13
- package/dist/src/scripts/output.js +0 -28
- package/dist/src/scripts/overlay/advertisement.d.ts +0 -16
- package/dist/src/scripts/overlay/advertisement.js +0 -122
- package/dist/src/scripts/overlay/discover.d.ts +0 -7
- package/dist/src/scripts/overlay/discover.js +0 -74
- package/dist/src/scripts/overlay/index.d.ts +0 -7
- package/dist/src/scripts/overlay/index.js +0 -7
- package/dist/src/scripts/overlay/registration.d.ts +0 -19
- package/dist/src/scripts/overlay/registration.js +0 -176
- package/dist/src/scripts/overlay/services.d.ts +0 -29
- package/dist/src/scripts/overlay/services.js +0 -167
- package/dist/src/scripts/overlay/transaction.d.ts +0 -42
- package/dist/src/scripts/overlay/transaction.js +0 -103
- package/dist/src/scripts/payment/build.d.ts +0 -24
- package/dist/src/scripts/payment/build.js +0 -54
- package/dist/src/scripts/payment/commands.d.ts +0 -15
- package/dist/src/scripts/payment/commands.js +0 -73
- package/dist/src/scripts/payment/index.d.ts +0 -6
- package/dist/src/scripts/payment/index.js +0 -6
- package/dist/src/scripts/payment/types.d.ts +0 -56
- package/dist/src/scripts/payment/types.js +0 -4
- package/dist/src/scripts/services/index.d.ts +0 -6
- package/dist/src/scripts/services/index.js +0 -6
- package/dist/src/scripts/services/queue.d.ts +0 -11
- package/dist/src/scripts/services/queue.js +0 -28
- package/dist/src/scripts/services/request.d.ts +0 -7
- package/dist/src/scripts/services/request.js +0 -82
- package/dist/src/scripts/services/respond.d.ts +0 -11
- package/dist/src/scripts/services/respond.js +0 -132
- package/dist/src/scripts/types.d.ts +0 -107
- package/dist/src/scripts/types.js +0 -4
- package/dist/src/scripts/utils/index.d.ts +0 -6
- package/dist/src/scripts/utils/index.js +0 -6
- package/dist/src/scripts/utils/merkle.d.ts +0 -12
- package/dist/src/scripts/utils/merkle.js +0 -47
- package/dist/src/scripts/utils/storage.d.ts +0 -66
- package/dist/src/scripts/utils/storage.js +0 -211
- package/dist/src/scripts/utils/woc.d.ts +0 -26
- package/dist/src/scripts/utils/woc.js +0 -91
- package/dist/src/scripts/wallet/balance.d.ts +0 -22
- package/dist/src/scripts/wallet/balance.js +0 -240
- package/dist/src/scripts/wallet/identity.d.ts +0 -71
- package/dist/src/scripts/wallet/identity.js +0 -152
- package/dist/src/scripts/wallet/index.d.ts +0 -6
- package/dist/src/scripts/wallet/index.js +0 -6
- package/dist/src/scripts/wallet/setup.d.ts +0 -19
- package/dist/src/scripts/wallet/setup.js +0 -119
- package/dist/src/scripts/x-verification/commands.d.ts +0 -27
- package/dist/src/scripts/x-verification/commands.js +0 -222
- package/dist/src/scripts/x-verification/index.d.ts +0 -4
- package/dist/src/scripts/x-verification/index.js +0 -4
- package/dist/src/services/built-in/api-proxy/index.d.ts +0 -6
- package/dist/src/services/built-in/api-proxy/index.js +0 -23
- package/dist/src/services/built-in/code-develop/index.d.ts +0 -6
- package/dist/src/services/built-in/code-develop/index.js +0 -23
- package/dist/src/services/built-in/code-review/index.d.ts +0 -10
- package/dist/src/services/built-in/code-review/index.js +0 -51
- package/dist/src/services/built-in/image-analysis/index.d.ts +0 -6
- package/dist/src/services/built-in/image-analysis/index.js +0 -33
- package/dist/src/services/built-in/memory-store/index.d.ts +0 -6
- package/dist/src/services/built-in/memory-store/index.js +0 -22
- package/dist/src/services/built-in/roulette/index.d.ts +0 -6
- package/dist/src/services/built-in/roulette/index.js +0 -27
- package/dist/src/services/built-in/summarize/index.d.ts +0 -6
- package/dist/src/services/built-in/summarize/index.js +0 -21
- package/dist/src/services/built-in/tell-joke/handler.d.ts +0 -7
- package/dist/src/services/built-in/tell-joke/handler.js +0 -122
- package/dist/src/services/built-in/tell-joke/index.d.ts +0 -9
- package/dist/src/services/built-in/tell-joke/index.js +0 -31
- package/dist/src/services/built-in/translate/index.d.ts +0 -6
- package/dist/src/services/built-in/translate/index.js +0 -21
- package/dist/src/services/built-in/web-research/index.d.ts +0 -9
- package/dist/src/services/built-in/web-research/index.js +0 -51
- package/dist/src/services/index.d.ts +0 -13
- package/dist/src/services/index.js +0 -14
- package/dist/src/services/loader.d.ts +0 -77
- package/dist/src/services/loader.js +0 -292
- package/dist/src/services/manager.d.ts +0 -86
- package/dist/src/services/manager.js +0 -255
- package/dist/src/services/registry.d.ts +0 -98
- package/dist/src/services/registry.js +0 -204
- package/dist/src/services/types.d.ts +0 -230
- package/dist/src/services/types.js +0 -30
- package/dist/src/test/cli.test.d.ts +0 -7
- package/dist/src/test/cli.test.js +0 -330
- package/dist/src/test/comprehensive-overlay.test.d.ts +0 -13
- package/dist/src/test/comprehensive-overlay.test.js +0 -593
- package/dist/src/test/identity-consistency.test.d.ts +0 -6
- package/dist/src/test/identity-consistency.test.js +0 -60
- package/dist/src/test/key-derivation.test.d.ts +0 -12
- package/dist/src/test/key-derivation.test.js +0 -86
- package/dist/src/test/network-address.test.d.ts +0 -9
- package/dist/src/test/network-address.test.js +0 -37
- package/dist/src/test/overlay-submit.test.d.ts +0 -10
- package/dist/src/test/overlay-submit.test.js +0 -460
- package/dist/src/test/request-response-flow.test.d.ts +0 -5
- package/dist/src/test/request-response-flow.test.js +0 -210
- package/dist/src/test/service-system.test.d.ts +0 -5
- package/dist/src/test/service-system.test.js +0 -190
- package/dist/src/test/taskflow.test.d.ts +0 -7
- package/dist/src/test/taskflow.test.js +0 -82
- package/dist/src/test/utils/server-logic.d.ts +0 -98
- package/dist/src/test/utils/server-logic.js +0 -286
- package/dist/src/test/wallet.test.d.ts +0 -7
- package/dist/src/test/wallet.test.js +0 -146
- package/src/core/README.md +0 -246
- package/src/core/config.d.ts +0 -12
- package/src/core/config.d.ts.map +0 -1
- package/src/core/config.js +0 -14
- package/src/core/config.js.map +0 -1
- package/src/core/config.ts +0 -22
- package/src/core/index.ts +0 -42
- package/src/core/payment.d.ts +0 -17
- package/src/core/payment.d.ts.map +0 -1
- package/src/core/payment.js +0 -95
- package/src/core/payment.js.map +0 -1
- package/src/core/payment.ts +0 -111
- package/src/core/types.d.ts +0 -95
- package/src/core/types.d.ts.map +0 -1
- package/src/core/types.js +0 -5
- package/src/core/types.js.map +0 -1
- package/src/core/types.ts +0 -102
- package/src/core/verify.d.ts +0 -29
- package/src/core/verify.d.ts.map +0 -1
- package/src/core/verify.js +0 -105
- package/src/core/verify.js.map +0 -1
- package/src/core/verify.ts +0 -119
- package/src/core/wallet.d.ts +0 -100
- package/src/core/wallet.d.ts.map +0 -1
- package/src/core/wallet.js.map +0 -1
- package/src/core/wallet.ts +0 -323
|
@@ -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,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,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
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Overlay service commands: services, advertise, remove, readvertise.
|
|
3
|
-
*
|
|
4
|
-
* Service payloads match the openclaw-overlay server schema:
|
|
5
|
-
* - protocol: "clawdbot-overlay-v1"
|
|
6
|
-
* - type: "service"
|
|
7
|
-
* - identityKey: provider's compressed public key
|
|
8
|
-
* - serviceId: unique service identifier
|
|
9
|
-
* - name: human-readable name
|
|
10
|
-
* - description: what the service does
|
|
11
|
-
* - pricing: { model: "per-task", amountSats: number }
|
|
12
|
-
* - timestamp: ISO 8601 time
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* Services command: list currently advertised services.
|
|
16
|
-
*/
|
|
17
|
-
export declare function cmdServices(): Promise<any>;
|
|
18
|
-
/**
|
|
19
|
-
* Advertise command: add a new service advertisement.
|
|
20
|
-
*/
|
|
21
|
-
export declare function cmdAdvertise(serviceId: string | undefined, name: string | undefined, priceSatsStr: string | undefined, description?: string): Promise<any>;
|
|
22
|
-
/**
|
|
23
|
-
* Remove command: remove a service from local registry.
|
|
24
|
-
*/
|
|
25
|
-
export declare function cmdRemove(serviceId: string | undefined): Promise<any>;
|
|
26
|
-
/**
|
|
27
|
-
* Readvertise command: update an existing service advertisement.
|
|
28
|
-
*/
|
|
29
|
-
export declare function cmdReadvertise(serviceId: string | undefined, name?: string, priceSatsStr?: string, description?: string): Promise<any>;
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Overlay service commands: services, advertise, remove, readvertise.
|
|
3
|
-
*
|
|
4
|
-
* Service payloads match the openclaw-overlay server schema:
|
|
5
|
-
* - protocol: "clawdbot-overlay-v1"
|
|
6
|
-
* - type: "service"
|
|
7
|
-
* - identityKey: provider's compressed public key
|
|
8
|
-
* - serviceId: unique service identifier
|
|
9
|
-
* - name: human-readable name
|
|
10
|
-
* - description: what the service does
|
|
11
|
-
* - pricing: { model: "per-task", amountSats: number }
|
|
12
|
-
* - timestamp: ISO 8601 time
|
|
13
|
-
*/
|
|
14
|
-
import { NETWORK, WALLET_DIR, PROTOCOL_ID, TOPICS } from '../config.js';
|
|
15
|
-
import { ok, fail } from '../output.js';
|
|
16
|
-
import { loadServices, saveServices } from '../utils/storage.js';
|
|
17
|
-
import { buildRealOverlayTransaction } from './transaction.js';
|
|
18
|
-
import { BSVAgentWallet } from '../../core/index.js';
|
|
19
|
-
async function getBSVAgentWallet() {
|
|
20
|
-
return BSVAgentWallet;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Services command: list currently advertised services.
|
|
24
|
-
*/
|
|
25
|
-
export async function cmdServices() {
|
|
26
|
-
const services = loadServices();
|
|
27
|
-
return ok({ services, count: services.length });
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Advertise command: add a new service advertisement.
|
|
31
|
-
*/
|
|
32
|
-
export async function cmdAdvertise(serviceId, name, priceSatsStr, description) {
|
|
33
|
-
if (!serviceId || !name || !priceSatsStr) {
|
|
34
|
-
return fail('Usage: advertise <serviceId> <name> <priceSats> [description]');
|
|
35
|
-
}
|
|
36
|
-
const priceSats = parseInt(priceSatsStr, 10);
|
|
37
|
-
if (isNaN(priceSats) || priceSats < 0) {
|
|
38
|
-
return fail('priceSats must be a non-negative integer');
|
|
39
|
-
}
|
|
40
|
-
const BSVAgentWallet = await getBSVAgentWallet();
|
|
41
|
-
const wallet = await BSVAgentWallet.load({ network: NETWORK, storageDir: WALLET_DIR });
|
|
42
|
-
const identityKey = await wallet.getIdentityKey();
|
|
43
|
-
await wallet.destroy();
|
|
44
|
-
// Load existing services
|
|
45
|
-
const services = loadServices();
|
|
46
|
-
const existing = services.find(s => s.serviceId === serviceId);
|
|
47
|
-
if (existing) {
|
|
48
|
-
return fail(`Service '${serviceId}' already exists. Use 'readvertise' to update.`);
|
|
49
|
-
}
|
|
50
|
-
// Create service record (local storage format)
|
|
51
|
-
const newService = {
|
|
52
|
-
serviceId,
|
|
53
|
-
name,
|
|
54
|
-
description: description || `${name} service`,
|
|
55
|
-
priceSats,
|
|
56
|
-
registeredAt: new Date().toISOString(),
|
|
57
|
-
};
|
|
58
|
-
// Publish on-chain (matches openclaw-overlay server schema)
|
|
59
|
-
const servicePayload = {
|
|
60
|
-
protocol: PROTOCOL_ID,
|
|
61
|
-
type: 'service',
|
|
62
|
-
identityKey,
|
|
63
|
-
serviceId,
|
|
64
|
-
name,
|
|
65
|
-
description: newService.description,
|
|
66
|
-
pricing: {
|
|
67
|
-
model: 'per-task',
|
|
68
|
-
amountSats: priceSats,
|
|
69
|
-
},
|
|
70
|
-
timestamp: new Date().toISOString(),
|
|
71
|
-
};
|
|
72
|
-
try {
|
|
73
|
-
const result = await buildRealOverlayTransaction(servicePayload, TOPICS.SERVICES);
|
|
74
|
-
newService.txid = result.txid;
|
|
75
|
-
// Save locally
|
|
76
|
-
services.push(newService);
|
|
77
|
-
saveServices(services);
|
|
78
|
-
return ok({
|
|
79
|
-
advertised: true,
|
|
80
|
-
service: newService,
|
|
81
|
-
txid: result.txid,
|
|
82
|
-
funded: result.funded,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
catch (err) {
|
|
86
|
-
return fail(`Failed to advertise service: ${err.message}`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Remove command: remove a service from local registry.
|
|
91
|
-
*/
|
|
92
|
-
export async function cmdRemove(serviceId) {
|
|
93
|
-
if (!serviceId) {
|
|
94
|
-
return fail('Usage: remove <serviceId>');
|
|
95
|
-
}
|
|
96
|
-
const services = loadServices();
|
|
97
|
-
const idx = services.findIndex(s => s.serviceId === serviceId);
|
|
98
|
-
if (idx === -1) {
|
|
99
|
-
return fail(`Service '${serviceId}' not found`);
|
|
100
|
-
}
|
|
101
|
-
const removed = services.splice(idx, 1)[0];
|
|
102
|
-
saveServices(services);
|
|
103
|
-
return ok({
|
|
104
|
-
removed: true,
|
|
105
|
-
service: removed,
|
|
106
|
-
note: 'Removed from local registry. On-chain record remains (blockchain is immutable).',
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Readvertise command: update an existing service advertisement.
|
|
111
|
-
*/
|
|
112
|
-
export async function cmdReadvertise(serviceId, name, priceSatsStr, description) {
|
|
113
|
-
if (!serviceId) {
|
|
114
|
-
return fail('Usage: readvertise <serviceId> [name] [priceSats] [description]');
|
|
115
|
-
}
|
|
116
|
-
const services = loadServices();
|
|
117
|
-
const existing = services.find(s => s.serviceId === serviceId);
|
|
118
|
-
if (!existing) {
|
|
119
|
-
return fail(`Service '${serviceId}' not found. Use 'advertise' to create.`);
|
|
120
|
-
}
|
|
121
|
-
const BSVAgentWallet = await getBSVAgentWallet();
|
|
122
|
-
const wallet = await BSVAgentWallet.load({ network: NETWORK, storageDir: WALLET_DIR });
|
|
123
|
-
const identityKey = await wallet.getIdentityKey();
|
|
124
|
-
await wallet.destroy();
|
|
125
|
-
// Update fields if provided
|
|
126
|
-
if (name)
|
|
127
|
-
existing.name = name;
|
|
128
|
-
if (priceSatsStr) {
|
|
129
|
-
const priceSats = parseInt(priceSatsStr, 10);
|
|
130
|
-
if (isNaN(priceSats) || priceSats < 0) {
|
|
131
|
-
return fail('priceSats must be a non-negative integer');
|
|
132
|
-
}
|
|
133
|
-
existing.priceSats = priceSats;
|
|
134
|
-
}
|
|
135
|
-
if (description)
|
|
136
|
-
existing.description = description;
|
|
137
|
-
existing.registeredAt = new Date().toISOString();
|
|
138
|
-
// Publish update on-chain (matches openclaw-overlay server schema)
|
|
139
|
-
const servicePayload = {
|
|
140
|
-
protocol: PROTOCOL_ID,
|
|
141
|
-
type: 'service',
|
|
142
|
-
identityKey,
|
|
143
|
-
serviceId,
|
|
144
|
-
name: existing.name,
|
|
145
|
-
description: existing.description,
|
|
146
|
-
pricing: {
|
|
147
|
-
model: 'per-task',
|
|
148
|
-
amountSats: existing.priceSats,
|
|
149
|
-
},
|
|
150
|
-
timestamp: existing.registeredAt,
|
|
151
|
-
};
|
|
152
|
-
try {
|
|
153
|
-
const result = await buildRealOverlayTransaction(servicePayload, TOPICS.SERVICES);
|
|
154
|
-
existing.txid = result.txid;
|
|
155
|
-
// Save locally
|
|
156
|
-
saveServices(services);
|
|
157
|
-
return ok({
|
|
158
|
-
readvertised: true,
|
|
159
|
-
service: existing,
|
|
160
|
-
txid: result.txid,
|
|
161
|
-
funded: result.funded,
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
catch (err) {
|
|
165
|
-
return fail(`Failed to readvertise service: ${err.message}`);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
@@ -1,42 +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 type { OverlayPayload } from '../types.js';
|
|
9
|
-
import { BSVAgentWallet } from '../../core/wallet.js';
|
|
10
|
-
/**
|
|
11
|
-
* Build an PushDrop locking script with JSON payload using SDK's Script class.
|
|
12
|
-
*
|
|
13
|
-
* @param payload - The data to embed in the OP_RETURN
|
|
14
|
-
* @returns A proper Script object that the SDK can serialize
|
|
15
|
-
*/
|
|
16
|
-
export declare function buildPushDropScript(wallet: BSVAgentWallet, payload: OverlayPayload): Promise<string>;
|
|
17
|
-
/**
|
|
18
|
-
* Build and submit an overlay transaction.
|
|
19
|
-
* @param payload - JSON data to store in OP_RETURN
|
|
20
|
-
* @param topic - Topic manager for submission
|
|
21
|
-
* @returns Transaction result with txid and funding info
|
|
22
|
-
*/
|
|
23
|
-
export declare function buildRealOverlayTransaction(payload: OverlayPayload, topic: string): Promise<{
|
|
24
|
-
txid: string;
|
|
25
|
-
funded: string;
|
|
26
|
-
explorer: string;
|
|
27
|
-
}>;
|
|
28
|
-
/**
|
|
29
|
-
* Lookup data from an overlay lookup service.
|
|
30
|
-
*/
|
|
31
|
-
export declare function lookupOverlay(service: string, query: Record<string, unknown>): Promise<any>;
|
|
32
|
-
/**
|
|
33
|
-
* Parse an overlay output from BEEF data.
|
|
34
|
-
*
|
|
35
|
-
* Handles both formats:
|
|
36
|
-
* - OP_FALSE OP_RETURN <protocol> <json> (standard)
|
|
37
|
-
* - OP_RETURN <protocol> <json> (legacy)
|
|
38
|
-
*/
|
|
39
|
-
export declare function parseOverlayOutput(beefData: string | Uint8Array | number[], outputIndex: number): Promise<{
|
|
40
|
-
data: OverlayPayload | null;
|
|
41
|
-
txid: string | null;
|
|
42
|
-
}>;
|