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,282 +0,0 @@
1
- import { fileURLToPath } from 'node:url';
2
- import path from 'node:path';
3
- import os from 'node:os';
4
- import fs from 'node:fs';
5
- import process from 'node:process';
6
- import { ok, fail } from '../output.js';
7
- import { loadIdentity, deriveWalletAddress } from '../wallet/identity.js';
8
- import { NETWORK } from '../config.js';
9
- const __filename = fileURLToPath(import.meta.url);
10
- const __dirname = path.dirname(__filename);
11
- // Define paths relative to home directory
12
- const PATHS = {
13
- walletIdentity: path.join(os.homedir(), '.openclaw', 'bsv-wallet', 'wallet-identity.json'),
14
- baemailLog: path.join(os.homedir(), '.openclaw', 'openclaw-overlay', 'baemail-deliveries.jsonl'),
15
- baemailConfig: path.join(os.homedir(), '.openclaw', 'openclaw-overlay', 'baemail-config.json'),
16
- baemailBlocklist: path.join(os.homedir(), '.openclaw', 'openclaw-overlay', 'baemail-blocklist.json'),
17
- };
18
- /**
19
- * Log a baemail delivery event.
20
- */
21
- export function logBaemailDelivery(entry) {
22
- try {
23
- const dir = path.dirname(PATHS.baemailLog);
24
- if (!fs.existsSync(dir))
25
- fs.mkdirSync(dir, { recursive: true });
26
- fs.appendFileSync(PATHS.baemailLog, JSON.stringify({ ...entry, ts: Date.now() }) + '\n');
27
- }
28
- catch { }
29
- }
30
- export async function loadBaemailConfig() {
31
- const defaults = {
32
- enabled: true,
33
- priceSats: 100,
34
- autoRefund: true,
35
- blocklist: [],
36
- maxMessageLength: 4000,
37
- deliveryChannel: 'agent-hook',
38
- tiers: {
39
- standard: 100,
40
- priority: 500,
41
- urgent: 1000
42
- }
43
- };
44
- if (!fs.existsSync(PATHS.baemailConfig)) {
45
- return defaults;
46
- }
47
- try {
48
- const config = JSON.parse(fs.readFileSync(PATHS.baemailConfig, 'utf-8'));
49
- return { ...defaults, ...config };
50
- }
51
- catch {
52
- return defaults;
53
- }
54
- }
55
- async function fetchWithTimeout(url, options = {}) {
56
- const { timeout = 15000 } = options;
57
- const controller = new AbortController();
58
- const id = setTimeout(() => controller.abort(), timeout);
59
- try {
60
- const response = await fetch(url, {
61
- ...options,
62
- signal: controller.signal
63
- });
64
- clearTimeout(id);
65
- return response;
66
- }
67
- catch (err) {
68
- clearTimeout(id);
69
- throw err;
70
- }
71
- }
72
- /**
73
- * List recent baemail deliveries.
74
- */
75
- export async function cmdBaemailLog(limitStr) {
76
- const limit = parseInt(limitStr || '20', 10) || 20;
77
- if (!fs.existsSync(PATHS.baemailLog)) {
78
- return ok({ log: [], count: 0 });
79
- }
80
- const lines = fs.readFileSync(PATHS.baemailLog, 'utf-8').split('\n').filter((l) => l.trim());
81
- const entries = lines.map((l) => {
82
- try {
83
- return JSON.parse(l);
84
- }
85
- catch {
86
- return null;
87
- }
88
- }).filter(Boolean);
89
- const recent = entries.slice(-limit).reverse();
90
- return ok({ log: recent, count: entries.length, showing: recent.length });
91
- }
92
- export async function cmdBaemailSetup(priceSatsStr, prioritySats, urgentSats, channel) {
93
- const standard = parseInt(priceSatsStr, 10) || 100;
94
- const priority = parseInt(prioritySats || '', 10) || (standard * 5);
95
- const urgent = parseInt(urgentSats || '', 10) || (standard * 10);
96
- const config = {
97
- enabled: true,
98
- priceSats: standard,
99
- autoRefund: true,
100
- deliveryChannel: channel || 'agent-hook',
101
- tiers: { standard, priority, urgent }
102
- };
103
- const dir = path.dirname(PATHS.baemailConfig);
104
- if (!fs.existsSync(dir))
105
- fs.mkdirSync(dir, { recursive: true });
106
- fs.writeFileSync(PATHS.baemailConfig, JSON.stringify(config, null, 2));
107
- return ok({ message: `Baemail setup complete.`, config });
108
- }
109
- export async function cmdBaemailConfig() {
110
- const config = await loadBaemailConfig();
111
- return ok(config);
112
- }
113
- export async function cmdBaemailBlock(pubkey) {
114
- if (!pubkey)
115
- return fail('Usage: baemail-block <pubkey>');
116
- let blocklist = [];
117
- if (fs.existsSync(PATHS.baemailBlocklist)) {
118
- try {
119
- blocklist = JSON.parse(fs.readFileSync(PATHS.baemailBlocklist, 'utf-8'));
120
- }
121
- catch {
122
- blocklist = [];
123
- }
124
- }
125
- if (!blocklist.includes(pubkey))
126
- blocklist.push(pubkey);
127
- fs.writeFileSync(PATHS.baemailBlocklist, JSON.stringify(blocklist, null, 2));
128
- return ok({ blocked: true, pubkey, count: blocklist.length });
129
- }
130
- export async function cmdBaemailUnblock(pubkey) {
131
- if (!pubkey)
132
- return fail('Usage: baemail-unblock <pubkey>');
133
- let blocklist = [];
134
- if (fs.existsSync(PATHS.baemailBlocklist)) {
135
- try {
136
- blocklist = JSON.parse(fs.readFileSync(PATHS.baemailBlocklist, 'utf-8'));
137
- }
138
- catch {
139
- blocklist = [];
140
- }
141
- }
142
- blocklist = blocklist.filter(p => p !== pubkey);
143
- fs.writeFileSync(PATHS.baemailBlocklist, JSON.stringify(blocklist, null, 2));
144
- return ok({ unblocked: true, pubkey, count: blocklist.length });
145
- }
146
- /**
147
- * Refund a failed baemail delivery.
148
- */
149
- export async function cmdBaemailRefund(requestId) {
150
- if (!requestId)
151
- return fail('Usage: baemail-refund <requestId>');
152
- if (!fs.existsSync(PATHS.baemailLog)) {
153
- return fail('No baemail log found');
154
- }
155
- // Find the entry
156
- const lines = fs.readFileSync(PATHS.baemailLog, 'utf-8').split('\n').filter((l) => l.trim());
157
- const entries = lines.map((l, idx) => {
158
- try {
159
- return { ...JSON.parse(l), _lineIdx: idx };
160
- }
161
- catch {
162
- return null;
163
- }
164
- }).filter(Boolean);
165
- const entry = entries.find(e => e.requestId === requestId);
166
- if (!entry) {
167
- return fail(`Request ${requestId} not found in baemail log`);
168
- }
169
- if (entry.deliverySuccess) {
170
- return fail('This delivery was successful — no refund needed');
171
- }
172
- if (entry.refundStatus === 'completed') {
173
- return fail('Refund already processed for this request');
174
- }
175
- // Load wallet and SDK
176
- const { identityKey, privKey: rootKey } = await loadIdentity();
177
- const walletIdentityRaw = fs.readFileSync(PATHS.walletIdentity, 'utf-8');
178
- const walletIdentity = JSON.parse(walletIdentityRaw);
179
- // Dynamic import SDK
180
- let sdk;
181
- try {
182
- sdk = await import('@bsv/sdk');
183
- }
184
- catch {
185
- return fail('Cannot load @bsv/sdk for refund transaction');
186
- }
187
- const { Transaction, P2PKH, PrivateKey, PublicKey, Hash } = sdk;
188
- // Calculate refund amount
189
- const refundSats = entry.paidSats - 1; // Keep 1 sat for tx fee
190
- if (refundSats < 1) {
191
- return fail('Amount too small to refund');
192
- }
193
- // Derive refund address from sender's identity key
194
- const senderPubKey = PublicKey.fromString(entry.from);
195
- const refundAddress = senderPubKey.toAddress(NETWORK).toString();
196
- try {
197
- // Load UTXOs - Derive local address correctly
198
- const { address } = await deriveWalletAddress(rootKey);
199
- const wocNet = NETWORK === 'mainnet' ? 'main' : 'test';
200
- const utxosResp = await fetchWithTimeout(`https://api.whatsonchain.com/v1/bsv/${wocNet}/address/${address}/unspent/all`);
201
- const data = await utxosResp.json();
202
- const utxos = data.result || [];
203
- if (!utxos || utxos.length === 0) {
204
- return fail(`No UTXOs available for refund at ${address}`);
205
- }
206
- // Build transaction
207
- const tx = new Transaction();
208
- let totalInput = 0;
209
- for (const utxo of utxos) {
210
- if (totalInput >= refundSats + 50)
211
- break;
212
- tx.addInput({
213
- sourceTXID: utxo.tx_hash,
214
- sourceOutputIndex: utxo.tx_pos,
215
- sourceSatoshis: utxo.value,
216
- script: new P2PKH().lock(rootKey.toPublicKey().toAddress(NETWORK)).toHex(),
217
- unlockingScriptTemplate: new P2PKH().unlock(rootKey),
218
- });
219
- totalInput += utxo.value;
220
- }
221
- if (totalInput < refundSats + 10) {
222
- return fail('Insufficient funds for refund');
223
- }
224
- // Refund output
225
- tx.addOutput({
226
- satoshis: refundSats,
227
- lockingScript: new P2PKH().lock(refundAddress),
228
- });
229
- // Change output
230
- const fee = 10;
231
- const change = totalInput - refundSats - fee;
232
- if (change > 1) {
233
- tx.addOutput({
234
- satoshis: change,
235
- lockingScript: new P2PKH().lock(rootKey.toPublicKey().toAddress(NETWORK)),
236
- });
237
- }
238
- await tx.sign();
239
- // Broadcast using configured ARC/Arcade URL or fallback to WhatsOnChain
240
- const arcUrl = process['env'].BSV_ARC_URL;
241
- let broadcastResp;
242
- if (arcUrl) {
243
- broadcastResp = await fetchWithTimeout(`${arcUrl.replace(/\/$/, '')}/v1/tx`, {
244
- method: 'POST',
245
- headers: { 'Content-Type': 'application/json' },
246
- body: JSON.stringify({ rawTx: tx.toHex() }),
247
- });
248
- }
249
- else {
250
- broadcastResp = await fetchWithTimeout(`https://api.whatsonchain.com/v1/bsv/${wocNet}/tx/raw`, {
251
- method: 'POST',
252
- headers: { 'Content-Type': 'application/json' },
253
- body: JSON.stringify({ txhex: tx.toHex() }),
254
- });
255
- }
256
- if (!broadcastResp.ok) {
257
- const errBody = await broadcastResp.text();
258
- return fail(`Broadcast failed: ${errBody}`);
259
- }
260
- const txid = tx.id('hex');
261
- // Update log entry
262
- const updatedLines = lines.map((l, idx) => {
263
- if (idx === entry._lineIdx) {
264
- const updated = { ...JSON.parse(l), refundStatus: 'completed', refundTxid: txid, refundedAt: new Date().toISOString() };
265
- return JSON.stringify(updated);
266
- }
267
- return l;
268
- });
269
- fs.writeFileSync(PATHS.baemailLog, updatedLines.join('\n') + '\n');
270
- return ok({
271
- refunded: true,
272
- requestId,
273
- refundSats,
274
- refundAddress,
275
- txid,
276
- note: `Refunded ${refundSats} sats to sender`,
277
- });
278
- }
279
- catch (err) {
280
- return fail(`Refund failed: ${err.message}`);
281
- }
282
- }
@@ -1,36 +0,0 @@
1
- /**
2
- * Baemail service handler - processes incoming paid messages.
3
- */
4
- interface BaemailInput {
5
- message?: string;
6
- senderName?: string;
7
- replyIdentityKey?: string;
8
- }
9
- interface ServiceMessage {
10
- id: string;
11
- from: string;
12
- payload?: {
13
- input?: BaemailInput;
14
- payment?: any;
15
- };
16
- }
17
- interface ProcessResult {
18
- id: string;
19
- type: string;
20
- serviceId: string;
21
- action: string;
22
- tier?: string;
23
- deliverySuccess?: boolean;
24
- deliveryError?: string | null | undefined;
25
- paymentAccepted?: boolean;
26
- paymentTxid?: string;
27
- satoshisReceived?: number;
28
- from: string;
29
- ack: boolean;
30
- reason?: string | null;
31
- }
32
- /**
33
- * Process incoming baemail service request.
34
- */
35
- export declare function processBaemail(msg: ServiceMessage, identityKey: string, privKey: any): Promise<ProcessResult>;
36
- export {};
@@ -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
- };