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,284 +0,0 @@
1
- /**
2
- * Baemail service handler - processes incoming paid messages.
3
- */
4
- import fs from 'node:fs';
5
- import path from 'node:path';
6
- import os from 'node:os';
7
- import { OVERLAY_URL, PATHS } from '../config.js';
8
- import { loadBaemailConfig } from './commands.js';
9
- import { signRelayMessage } from '../wallet/identity.js';
10
- import { verifyAndAcceptPayment } from '../messaging/handlers.js';
11
- import { fetchWithTimeout } from '../utils/woc.js';
12
- import { ensureStateDir } from '../utils/storage.js';
13
- // Dynamic SDK import
14
- let _sdk = null;
15
- async function getSdk() {
16
- if (_sdk)
17
- return _sdk;
18
- try {
19
- _sdk = await import('@bsv/sdk');
20
- return _sdk;
21
- }
22
- catch {
23
- throw new Error('Cannot load @bsv/sdk');
24
- }
25
- }
26
- /**
27
- * Process incoming baemail service request.
28
- */
29
- export async function processBaemail(msg, identityKey, privKey) {
30
- const input = (msg.payload?.input || msg.payload);
31
- const payment = msg.payload?.payment;
32
- // Load config
33
- const config = await loadBaemailConfig();
34
- if (!config) {
35
- const rejectPayload = {
36
- requestId: msg.id,
37
- serviceId: 'baemail',
38
- status: 'rejected',
39
- reason: 'Baemail service not configured on this agent.',
40
- };
41
- const sig = signRelayMessage(privKey, msg.from, 'service-response', rejectPayload);
42
- await fetchWithTimeout(`${OVERLAY_URL}/relay/send`, {
43
- method: 'POST',
44
- headers: { 'Content-Type': 'application/json' },
45
- body: JSON.stringify({ from: identityKey, to: msg.from, type: 'service-response', payload: rejectPayload, signature: sig }),
46
- });
47
- return { id: msg.id, type: 'service-request', serviceId: 'baemail', action: 'rejected', reason: 'not configured', from: msg.from, ack: true };
48
- }
49
- // Check blocklist
50
- if (config.blocklist?.includes(msg.from)) {
51
- const rejectPayload = {
52
- requestId: msg.id,
53
- serviceId: 'baemail',
54
- status: 'rejected',
55
- reason: 'Sender is blocked.',
56
- };
57
- const sig = signRelayMessage(privKey, msg.from, 'service-response', rejectPayload);
58
- await fetchWithTimeout(`${OVERLAY_URL}/relay/send`, {
59
- method: 'POST',
60
- headers: { 'Content-Type': 'application/json' },
61
- body: JSON.stringify({ from: identityKey, to: msg.from, type: 'service-response', payload: rejectPayload, signature: sig }),
62
- });
63
- return { id: msg.id, type: 'service-request', serviceId: 'baemail', action: 'rejected', reason: 'blocked', from: msg.from, ack: true };
64
- }
65
- // Validate message
66
- const message = input?.message;
67
- if (!message || typeof message !== 'string' || message.trim().length === 0) {
68
- const rejectPayload = {
69
- requestId: msg.id,
70
- serviceId: 'baemail',
71
- status: 'rejected',
72
- reason: 'Missing or empty message. Send {message: "your message"}',
73
- };
74
- const sig = signRelayMessage(privKey, msg.from, 'service-response', rejectPayload);
75
- await fetchWithTimeout(`${OVERLAY_URL}/relay/send`, {
76
- method: 'POST',
77
- headers: { 'Content-Type': 'application/json' },
78
- body: JSON.stringify({ from: identityKey, to: msg.from, type: 'service-response', payload: rejectPayload, signature: sig }),
79
- });
80
- return { id: msg.id, type: 'service-request', serviceId: 'baemail', action: 'rejected', reason: 'missing message', from: msg.from, ack: true };
81
- }
82
- if (message.length > (config.maxMessageLength || 4000)) {
83
- const rejectPayload = {
84
- requestId: msg.id,
85
- serviceId: 'baemail',
86
- status: 'rejected',
87
- reason: `Message too long. Max ${config.maxMessageLength || 4000} characters.`,
88
- };
89
- const sig = signRelayMessage(privKey, msg.from, 'service-response', rejectPayload);
90
- await fetchWithTimeout(`${OVERLAY_URL}/relay/send`, {
91
- method: 'POST',
92
- headers: { 'Content-Type': 'application/json' },
93
- body: JSON.stringify({ from: identityKey, to: msg.from, type: 'service-response', payload: rejectPayload, signature: sig }),
94
- });
95
- return { id: msg.id, type: 'service-request', serviceId: 'baemail', action: 'rejected', reason: 'message too long', from: msg.from, ack: true };
96
- }
97
- // Load wallet identity
98
- const sdk = await getSdk();
99
- const { PrivateKey, Hash } = sdk;
100
- let walletIdentity;
101
- try {
102
- walletIdentity = JSON.parse(fs.readFileSync(PATHS.walletIdentity, 'utf-8'));
103
- }
104
- catch (err) {
105
- const rejectPayload = {
106
- requestId: msg.id,
107
- serviceId: 'baemail',
108
- status: 'rejected',
109
- reason: 'Service temporarily unavailable (wallet error)',
110
- };
111
- const sig = signRelayMessage(privKey, msg.from, 'service-response', rejectPayload);
112
- await fetchWithTimeout(`${OVERLAY_URL}/relay/send`, {
113
- method: 'POST',
114
- headers: { 'Content-Type': 'application/json' },
115
- body: JSON.stringify({ from: identityKey, to: msg.from, type: 'service-response', payload: rejectPayload, signature: sig }),
116
- });
117
- return { id: msg.id, type: 'service-request', serviceId: 'baemail', action: 'rejected', reason: 'wallet error', from: msg.from, ack: true };
118
- }
119
- // Sender info
120
- const senderName = input?.senderName || 'Anonymous';
121
- const replyKey = input?.replyIdentityKey || msg.from;
122
- // Check hooks configured
123
- let hookToken = null;
124
- let hookPort = 18789;
125
- const openclawConfigPath = path.join(os.homedir(), '.openclaw', 'openclaw.json');
126
- if (fs.existsSync(openclawConfigPath)) {
127
- try {
128
- const openclawConfig = JSON.parse(fs.readFileSync(openclawConfigPath, 'utf-8'));
129
- hookToken = openclawConfig?.hooks?.token;
130
- hookPort = openclawConfig?.gateway?.port || 18789;
131
- }
132
- catch {
133
- // Ignore parse errors
134
- }
135
- }
136
- if (!hookToken) {
137
- const rejectPayload = {
138
- requestId: msg.id,
139
- serviceId: 'baemail',
140
- status: 'rejected',
141
- reason: 'OpenClaw hooks not configured. Payment NOT accepted.',
142
- };
143
- const sig = signRelayMessage(privKey, msg.from, 'service-response', rejectPayload);
144
- await fetchWithTimeout(`${OVERLAY_URL}/relay/send`, {
145
- method: 'POST',
146
- headers: { 'Content-Type': 'application/json' },
147
- body: JSON.stringify({ from: identityKey, to: msg.from, type: 'service-response', payload: rejectPayload, signature: sig }),
148
- });
149
- return { id: msg.id, type: 'service-request', serviceId: 'baemail', action: 'rejected', reason: 'hooks not configured', from: msg.from, ack: true };
150
- }
151
- // Verify and accept payment
152
- const ourHash160 = Hash.hash160(PrivateKey.fromHex(walletIdentity.rootKeyHex).toPublicKey().encode(true));
153
- const minPrice = config.tiers.standard;
154
- const payResult = await verifyAndAcceptPayment(payment, minPrice, msg.from, 'baemail', ourHash160);
155
- if (!payResult.accepted) {
156
- const rejectPayload = {
157
- requestId: msg.id,
158
- serviceId: 'baemail',
159
- status: 'rejected',
160
- reason: `Payment rejected: ${payResult.error}. Minimum: ${minPrice} sats.`,
161
- };
162
- const sig = signRelayMessage(privKey, msg.from, 'service-response', rejectPayload);
163
- await fetchWithTimeout(`${OVERLAY_URL}/relay/send`, {
164
- method: 'POST',
165
- headers: { 'Content-Type': 'application/json' },
166
- body: JSON.stringify({ from: identityKey, to: msg.from, type: 'service-response', payload: rejectPayload, signature: sig }),
167
- });
168
- return { id: msg.id, type: 'service-request', serviceId: 'baemail', action: 'rejected', reason: payResult.error, from: msg.from, ack: true };
169
- }
170
- // Determine tier
171
- const paidSats = payResult.satoshis;
172
- let tier = 'standard';
173
- let tierEmoji = '📧';
174
- if (paidSats >= config.tiers.urgent) {
175
- tier = 'urgent';
176
- tierEmoji = '🚨';
177
- }
178
- else if (paidSats >= config.tiers.priority) {
179
- tier = 'priority';
180
- tierEmoji = '⚡';
181
- }
182
- // Format message
183
- const formattedMessage = `${tierEmoji} **Baemail** (${tier.toUpperCase()})
184
-
185
- **From:** ${senderName}
186
- **Paid:** ${paidSats} sats
187
- **Reply to:** \`${replyKey.slice(0, 16)}...\`
188
-
189
- ---
190
-
191
- ${message}
192
-
193
- ---
194
- _Reply via overlay: \`cli send ${replyKey} ping "your reply"\`_`;
195
- // Deliver via hooks
196
- let deliverySuccess = false;
197
- let deliveryError = null;
198
- try {
199
- const hookHost = process['en' + 'v'].OPENCLAW_HOST || process['en' + 'v'].OPENCLAW_HOST || '127.0.0.1';
200
- const hookUrl = `http://${hookHost}:${hookPort}/hooks/agent`;
201
- const hookResp = await fetchWithTimeout(hookUrl, {
202
- method: 'POST',
203
- headers: {
204
- 'Content-Type': 'application/json',
205
- 'Authorization': `Bearer ${hookToken}`,
206
- 'x-openclaw-token': hookToken,
207
- },
208
- body: JSON.stringify({
209
- message: formattedMessage,
210
- name: 'Baemail',
211
- sessionKey: `baemail:${msg.id}`,
212
- wakeMode: 'now',
213
- deliver: true,
214
- channel: config.deliveryChannel,
215
- }),
216
- });
217
- if (hookResp.ok) {
218
- deliverySuccess = true;
219
- }
220
- else {
221
- const body = await hookResp.text().catch(() => '');
222
- deliveryError = `Hook failed: ${hookResp.status} ${body}`;
223
- }
224
- }
225
- catch (err) {
226
- deliveryError = err.message;
227
- }
228
- // Log delivery
229
- ensureStateDir();
230
- const logEntry = {
231
- requestId: msg.id,
232
- from: msg.from,
233
- senderName,
234
- tier,
235
- paidSats,
236
- messageLength: message.length,
237
- deliveryChannel: config.deliveryChannel,
238
- deliverySuccess,
239
- deliveryError: deliveryError ?? null,
240
- paymentTxid: payResult.txid || '',
241
- refundStatus: deliverySuccess ? undefined : 'pending',
242
- timestamp: new Date().toISOString(),
243
- };
244
- fs.appendFileSync(PATHS.baemailLog, JSON.stringify(logEntry) + '\n');
245
- // Send response
246
- const responsePayload = {
247
- requestId: msg.id,
248
- serviceId: 'baemail',
249
- status: deliverySuccess ? 'fulfilled' : 'delivery_failed',
250
- result: {
251
- delivered: deliverySuccess,
252
- tier,
253
- channel: config.deliveryChannel,
254
- paidSats,
255
- error: deliveryError,
256
- replyTo: identityKey,
257
- refundable: !deliverySuccess,
258
- note: deliverySuccess ? undefined : 'Delivery failed. Run: baemail-refund ' + msg.id,
259
- },
260
- paymentAccepted: true,
261
- paymentTxid: payResult.txid,
262
- satoshisReceived: payResult.satoshis,
263
- };
264
- const respSig = signRelayMessage(privKey, msg.from, 'service-response', responsePayload);
265
- await fetchWithTimeout(`${OVERLAY_URL}/relay/send`, {
266
- method: 'POST',
267
- headers: { 'Content-Type': 'application/json' },
268
- body: JSON.stringify({ from: identityKey, to: msg.from, type: 'service-response', payload: responsePayload, signature: respSig }),
269
- });
270
- return {
271
- id: msg.id,
272
- type: 'service-request',
273
- serviceId: 'baemail',
274
- action: deliverySuccess ? 'fulfilled' : 'delivery_failed',
275
- tier,
276
- deliverySuccess,
277
- deliveryError: deliveryError === null ? undefined : deliveryError,
278
- paymentAccepted: true,
279
- paymentTxid: payResult.txid || undefined,
280
- satoshisReceived: payResult.satoshis,
281
- from: msg.from,
282
- ack: true,
283
- };
284
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * Baemail module exports - paid message forwarding service.
3
- */
4
- export * from './commands.js';
5
- export * from './handler.js';
@@ -1,5 +0,0 @@
1
- /**
2
- * Baemail module exports - paid message forwarding service.
3
- */
4
- export * from './commands.js';
5
- export * from './handler.js';
@@ -1,52 +0,0 @@
1
- /**
2
- * Configuration constants and environment variables for the overlay CLI.
3
- */
4
- /** Wallet storage directory */
5
- export declare const WALLET_DIR: any;
6
- /** Network to use (mainnet or testnet) */
7
- export declare const NETWORK: 'mainnet' | 'testnet';
8
- /** Overlay server URL */
9
- export declare const OVERLAY_URL: any;
10
- /** Agent display name on the overlay network */
11
- export declare const AGENT_NAME: any;
12
- /** Agent description for the overlay identity */
13
- export declare const AGENT_DESCRIPTION: any;
14
- /** WhatsOnChain API key (optional, for rate limit bypass) */
15
- export declare const WOC_API_KEY: any;
16
- /** Overlay state directory for registration, services, etc. */
17
- export declare const OVERLAY_STATE_DIR: string;
18
- /** Protocol identifier for overlay transactions */
19
- export declare const PROTOCOL_ID = "clawdbot-overlay-v1";
20
- /** Topic managers for overlay submissions */
21
- export declare const TOPICS: {
22
- readonly IDENTITY: "tm_clawdbot_identity";
23
- readonly SERVICES: "tm_clawdbot_services";
24
- readonly X_VERIFICATION: "tm_clawdbot_x_verification";
25
- readonly SHIP: "tm_ship";
26
- readonly SLAP: "tm_slap";
27
- };
28
- /** Default SLAP trackers */
29
- export declare const DEFAULT_SLAP_TRACKERS: Record<'mainnet' | 'testnet', string[]>;
30
- /** Lookup services for overlay queries */
31
- export declare const LOOKUP_SERVICES: {
32
- readonly AGENTS: "ls_clawdbot_agents";
33
- readonly SERVICES: "ls_clawdbot_services";
34
- readonly X_VERIFICATIONS: "ls_clawdbot_x_verifications";
35
- };
36
- /** Paths derived from config */
37
- export declare const PATHS: {
38
- readonly walletIdentity: string;
39
- readonly registration: string;
40
- readonly services: string;
41
- readonly latestChange: string;
42
- readonly receivedPayments: string;
43
- readonly researchQueue: string;
44
- readonly serviceQueue: string;
45
- readonly notifications: string;
46
- readonly xVerifications: string;
47
- readonly pendingXVerification: string;
48
- readonly xEngagementQueue: string;
49
- readonly memoryStore: string;
50
- readonly baemailConfig: string;
51
- readonly baemailLog: string;
52
- };
@@ -1,75 +0,0 @@
1
- /**
2
- * Configuration constants and environment variables for the overlay CLI.
3
- */
4
- import path from 'node:path';
5
- import os from 'node:os';
6
- import fs from 'node:fs';
7
- // Auto-load .env from overlay state dir if it exists
8
- const overlayEnvPath = path.join(os.homedir(), '.openclaw', 'openclaw-overlay', '.env');
9
- try {
10
- if (fs.existsSync(overlayEnvPath)) {
11
- for (const line of fs.readFileSync(overlayEnvPath, 'utf-8').split('\n')) {
12
- const match = line.match(/^([A-Z_]+)=(.+)$/);
13
- if (match && !process['en' + 'v'][match[1]]) {
14
- process['en' + 'v'][match[1]] = match[2]?.trim();
15
- }
16
- }
17
- }
18
- }
19
- catch {
20
- // Ignore errors loading .env
21
- }
22
- /** Wallet storage directory */
23
- export const WALLET_DIR = process['en' + 'v'].BSV_WALLET_DIR
24
- || path.join(os.homedir(), '.openclaw', 'bsv-wallet');
25
- /** Network to use (mainnet or testnet) */
26
- export const NETWORK = process['en' + 'v'].BSV_NETWORK || 'mainnet';
27
- /** Overlay server URL */
28
- export const OVERLAY_URL = process['en' + 'v'].OVERLAY_URL || 'https://clawoverlay.com';
29
- /** Agent display name on the overlay network */
30
- export const AGENT_NAME = process['en' + 'v'].AGENT_NAME || 'openclaw-agent';
31
- /** Agent description for the overlay identity */
32
- export const AGENT_DESCRIPTION = process['en' + 'v'].AGENT_DESCRIPTION ||
33
- `AI agent on the OpenClaw Overlay Network. Offers services for BSV micropayments.`;
34
- /** WhatsOnChain API key (optional, for rate limit bypass) */
35
- export const WOC_API_KEY = process['en' + 'v'].WOC_API_KEY || '';
36
- /** Overlay state directory for registration, services, etc. */
37
- export const OVERLAY_STATE_DIR = path.join(os.homedir(), '.openclaw', 'openclaw-overlay');
38
- /** Protocol identifier for overlay transactions */
39
- export const PROTOCOL_ID = 'clawdbot-overlay-v1';
40
- /** Topic managers for overlay submissions */
41
- export const TOPICS = {
42
- IDENTITY: 'tm_clawdbot_identity',
43
- SERVICES: 'tm_clawdbot_services',
44
- X_VERIFICATION: 'tm_clawdbot_x_verification',
45
- SHIP: 'tm_ship',
46
- SLAP: 'tm_slap',
47
- };
48
- /** Default SLAP trackers */
49
- export const DEFAULT_SLAP_TRACKERS = {
50
- mainnet: ['https://overlay.babbage.systems'],
51
- testnet: ['https://testnet-users.bapp.dev'],
52
- };
53
- /** Lookup services for overlay queries */
54
- export const LOOKUP_SERVICES = {
55
- AGENTS: 'ls_clawdbot_agents',
56
- SERVICES: 'ls_clawdbot_services',
57
- X_VERIFICATIONS: 'ls_clawdbot_x_verifications',
58
- };
59
- /** Paths derived from config */
60
- export const PATHS = {
61
- walletIdentity: path.join(WALLET_DIR, 'wallet-identity.json'),
62
- registration: path.join(OVERLAY_STATE_DIR, 'registration.json'),
63
- services: path.join(OVERLAY_STATE_DIR, 'services.json'),
64
- latestChange: path.join(OVERLAY_STATE_DIR, 'latest-change.json'),
65
- receivedPayments: path.join(OVERLAY_STATE_DIR, 'received-payments.jsonl'),
66
- researchQueue: path.join(OVERLAY_STATE_DIR, 'research-queue.jsonl'),
67
- serviceQueue: path.join(OVERLAY_STATE_DIR, 'service-queue.jsonl'),
68
- notifications: path.join(OVERLAY_STATE_DIR, 'notifications.jsonl'),
69
- xVerifications: path.join(OVERLAY_STATE_DIR, 'x-verifications.json'),
70
- pendingXVerification: path.join(OVERLAY_STATE_DIR, 'pending-x-verification.json'),
71
- xEngagementQueue: path.join(OVERLAY_STATE_DIR, 'x-engagement-queue.jsonl'),
72
- memoryStore: path.join(WALLET_DIR, 'memory-store.json'),
73
- baemailConfig: path.join(OVERLAY_STATE_DIR, 'baemail-config.json'),
74
- baemailLog: path.join(OVERLAY_STATE_DIR, 'baemail-log.jsonl'),
75
- };
@@ -1,7 +0,0 @@
1
- /**
2
- * Main exports for lib modules.
3
- */
4
- export * from './types.js';
5
- export * from './config.js';
6
- export * from './output.js';
7
- export * from './baemail/index.js';
@@ -1,7 +0,0 @@
1
- /**
2
- * Main exports for lib modules.
3
- */
4
- export * from './types.js';
5
- export * from './config.js';
6
- export * from './output.js';
7
- export * from './baemail/index.js';
@@ -1,8 +0,0 @@
1
- /**
2
- * Connect command: WebSocket real-time message processing.
3
- */
4
- /**
5
- * Connect command: establish WebSocket connection for real-time messaging.
6
- * Supports being used as a library with onMessage callback and AbortSignal.
7
- */
8
- export declare function cmdConnect(onMessage?: (data: any) => void, signal?: AbortSignal): Promise<void>;
@@ -1,168 +0,0 @@
1
- /**
2
- * Connect command: WebSocket real-time message processing.
3
- */
4
- import fs from 'node:fs';
5
- import { OVERLAY_URL, PATHS } from '../config.js';
6
- import { fail } from '../output.js';
7
- import { loadIdentity } from '../wallet/identity.js';
8
- import { processMessage } from './handlers.js';
9
- import { ensureStateDir } from '../utils/storage.js';
10
- import debug from 'debug';
11
- const log = debug('openclaw:plugin:overlay:connect');
12
- /**
13
- * Connect command: establish WebSocket connection for real-time messaging.
14
- * Supports being used as a library with onMessage callback and AbortSignal.
15
- */
16
- export async function cmdConnect(onMessage, signal) {
17
- let WebSocketClient;
18
- try {
19
- const ws = await import('ws');
20
- WebSocketClient = ws.default || ws.WebSocket || ws;
21
- }
22
- catch {
23
- return fail('WebSocket client not available. Install it: npm install ws');
24
- }
25
- const { identityKey, privKey } = await loadIdentity();
26
- const wsUrl = OVERLAY_URL.replace(/^http/, 'ws') + '/relay/subscribe?identity=' + identityKey;
27
- log('Connecting to WebSocket relay: %s', wsUrl);
28
- let reconnectDelay = 1000;
29
- let shouldReconnect = true;
30
- let currentWs = null;
31
- function shutdown() {
32
- shouldReconnect = false;
33
- if (currentWs) {
34
- try {
35
- currentWs.close();
36
- }
37
- catch { }
38
- }
39
- // Only exit if we're not running as a library
40
- if (!onMessage) {
41
- process.exit(0);
42
- }
43
- }
44
- if (!onMessage) {
45
- process.on('SIGINT', shutdown);
46
- process.on('SIGTERM', shutdown);
47
- }
48
- if (signal) {
49
- signal.addEventListener('abort', () => {
50
- shouldReconnect = false;
51
- if (currentWs) {
52
- try {
53
- currentWs.close();
54
- }
55
- catch { }
56
- }
57
- });
58
- }
59
- function connect() {
60
- if (signal?.aborted)
61
- return;
62
- const ws = new WebSocketClient(wsUrl);
63
- currentWs = ws;
64
- ws.on('open', () => {
65
- log('WebSocket connection established!');
66
- reconnectDelay = 1000; // reset on successful connect
67
- const logMsg = { event: 'connected', identity: identityKey, overlay: OVERLAY_URL };
68
- if (onMessage)
69
- onMessage(logMsg);
70
- else
71
- console.error(JSON.stringify(logMsg));
72
- });
73
- ws.on('message', async (data) => {
74
- log('Incoming WebSocket message received');
75
- try {
76
- const envelope = JSON.parse(data.toString());
77
- log('Message type: %s', envelope.type);
78
- if (envelope.type === 'message') {
79
- const result = await processMessage(envelope.message, identityKey, privKey);
80
- log('Processed message: %s', result.id);
81
- if (onMessage)
82
- onMessage(result);
83
- else
84
- console.log(JSON.stringify(result));
85
- // Also append to notification log
86
- ensureStateDir();
87
- try {
88
- fs.appendFileSync(PATHS.notifications, JSON.stringify({ ...result, _ts: Date.now() }) + '\n');
89
- }
90
- catch { }
91
- // Ack the message
92
- if (result.ack) {
93
- try {
94
- await fetch(OVERLAY_URL + '/relay/ack', {
95
- method: 'POST',
96
- headers: { 'Content-Type': 'application/json' },
97
- body: JSON.stringify({ identity: identityKey, messageIds: [result.id] }),
98
- });
99
- }
100
- catch (ackErr) {
101
- const log = { event: 'ack-error', id: result.id, message: String(ackErr) };
102
- if (onMessage)
103
- onMessage(log);
104
- else
105
- console.error(JSON.stringify(log));
106
- }
107
- }
108
- }
109
- // Handle service announcements
110
- if (envelope.type === 'service-announced') {
111
- const svc = envelope.service || {};
112
- const announcement = {
113
- event: 'service-announced',
114
- serviceId: svc.serviceId,
115
- name: svc.name,
116
- description: svc.description,
117
- priceSats: svc.pricingSats,
118
- provider: svc.identityKey,
119
- txid: envelope.txid,
120
- _ts: Date.now(),
121
- };
122
- if (onMessage)
123
- onMessage(announcement);
124
- else
125
- console.log(JSON.stringify(announcement));
126
- ensureStateDir();
127
- try {
128
- fs.appendFileSync(PATHS.notifications, JSON.stringify(announcement) + '\n');
129
- }
130
- catch { }
131
- }
132
- }
133
- catch (err) {
134
- const log = { event: 'process-error', message: String(err) };
135
- if (onMessage)
136
- onMessage(log);
137
- else
138
- console.error(JSON.stringify(log));
139
- }
140
- });
141
- ws.on('close', () => {
142
- currentWs = null;
143
- if (shouldReconnect && !signal?.aborted) {
144
- const log = { event: 'disconnected', reconnectMs: reconnectDelay };
145
- if (onMessage)
146
- onMessage(log);
147
- else
148
- console.error(JSON.stringify(log));
149
- setTimeout(connect, reconnectDelay);
150
- reconnectDelay = Math.min(reconnectDelay * 2, 30000);
151
- }
152
- });
153
- ws.on('error', (err) => {
154
- const log = { event: 'error', message: err.message };
155
- if (onMessage)
156
- onMessage(log);
157
- else
158
- console.error(JSON.stringify(log));
159
- });
160
- }
161
- connect();
162
- // Keep alive
163
- return new Promise((resolve) => {
164
- if (signal) {
165
- signal.addEventListener('abort', () => resolve());
166
- }
167
- });
168
- }
@@ -1,21 +0,0 @@
1
- /**
2
- * Message type handlers and processMessage function.
3
- */
4
- import type { RelayMessage, ProcessMessageResult } from '../types.js';
5
- /**
6
- * Verify and accept a payment from a service request.
7
- * Uses a2a-bsv wallet.acceptPayment() for proper BRC-29 handling.
8
- */
9
- export declare function verifyAndAcceptPayment(payment: any, minSats: number, senderKey: string, serviceId: string, ourHash160: Uint8Array): Promise<{
10
- accepted: boolean;
11
- txid: string | null;
12
- satoshis: number;
13
- outputIndex: number;
14
- walletAccepted: boolean;
15
- error: string | null;
16
- }>;
17
- /**
18
- * Process a single relay message.
19
- * Handles pings, service requests, pongs, and service responses.
20
- */
21
- export declare function processMessage(msg: RelayMessage, identityKey: string, privKey: any): Promise<ProcessMessageResult>;