openclaw-overlay-plugin 0.7.34 → 0.7.35

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 (144) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +13 -2
  3. package/dist/src/scripts/config.d.ts +1 -1
  4. package/dist/src/scripts/config.js +1 -1
  5. package/index.ts +15 -2
  6. package/openclaw.plugin.json +2 -1
  7. package/package.json +1 -1
  8. package/src/scripts/config.ts +1 -1
  9. package/dist/cli-main.d.ts +0 -7
  10. package/dist/cli-main.js +0 -192
  11. package/dist/cli.d.ts +0 -8
  12. package/dist/cli.js +0 -14
  13. package/dist/core/config.d.ts +0 -11
  14. package/dist/core/config.js +0 -13
  15. package/dist/core/index.d.ts +0 -25
  16. package/dist/core/index.js +0 -26
  17. package/dist/core/payment.d.ts +0 -16
  18. package/dist/core/payment.js +0 -94
  19. package/dist/core/types.d.ts +0 -94
  20. package/dist/core/types.js +0 -4
  21. package/dist/core/verify.d.ts +0 -28
  22. package/dist/core/verify.js +0 -104
  23. package/dist/core/wallet.d.ts +0 -99
  24. package/dist/core/wallet.js +0 -219
  25. package/dist/scripts/baemail/commands.d.ts +0 -64
  26. package/dist/scripts/baemail/commands.js +0 -259
  27. package/dist/scripts/baemail/handler.d.ts +0 -36
  28. package/dist/scripts/baemail/handler.js +0 -284
  29. package/dist/scripts/baemail/index.d.ts +0 -5
  30. package/dist/scripts/baemail/index.js +0 -5
  31. package/dist/scripts/config.d.ts +0 -48
  32. package/dist/scripts/config.js +0 -68
  33. package/dist/scripts/index.d.ts +0 -7
  34. package/dist/scripts/index.js +0 -7
  35. package/dist/scripts/messaging/connect.d.ts +0 -8
  36. package/dist/scripts/messaging/connect.js +0 -114
  37. package/dist/scripts/messaging/handlers.d.ts +0 -21
  38. package/dist/scripts/messaging/handlers.js +0 -334
  39. package/dist/scripts/messaging/inbox.d.ts +0 -11
  40. package/dist/scripts/messaging/inbox.js +0 -51
  41. package/dist/scripts/messaging/index.d.ts +0 -8
  42. package/dist/scripts/messaging/index.js +0 -8
  43. package/dist/scripts/messaging/poll.d.ts +0 -7
  44. package/dist/scripts/messaging/poll.js +0 -52
  45. package/dist/scripts/messaging/send.d.ts +0 -7
  46. package/dist/scripts/messaging/send.js +0 -43
  47. package/dist/scripts/output.d.ts +0 -12
  48. package/dist/scripts/output.js +0 -19
  49. package/dist/scripts/overlay/discover.d.ts +0 -7
  50. package/dist/scripts/overlay/discover.js +0 -72
  51. package/dist/scripts/overlay/index.d.ts +0 -7
  52. package/dist/scripts/overlay/index.js +0 -7
  53. package/dist/scripts/overlay/registration.d.ts +0 -19
  54. package/dist/scripts/overlay/registration.js +0 -176
  55. package/dist/scripts/overlay/services.d.ts +0 -29
  56. package/dist/scripts/overlay/services.js +0 -167
  57. package/dist/scripts/overlay/transaction.d.ts +0 -42
  58. package/dist/scripts/overlay/transaction.js +0 -103
  59. package/dist/scripts/payment/build.d.ts +0 -24
  60. package/dist/scripts/payment/build.js +0 -54
  61. package/dist/scripts/payment/commands.d.ts +0 -15
  62. package/dist/scripts/payment/commands.js +0 -73
  63. package/dist/scripts/payment/index.d.ts +0 -6
  64. package/dist/scripts/payment/index.js +0 -6
  65. package/dist/scripts/payment/types.d.ts +0 -56
  66. package/dist/scripts/payment/types.js +0 -4
  67. package/dist/scripts/services/index.d.ts +0 -6
  68. package/dist/scripts/services/index.js +0 -6
  69. package/dist/scripts/services/queue.d.ts +0 -11
  70. package/dist/scripts/services/queue.js +0 -28
  71. package/dist/scripts/services/request.d.ts +0 -7
  72. package/dist/scripts/services/request.js +0 -82
  73. package/dist/scripts/services/respond.d.ts +0 -11
  74. package/dist/scripts/services/respond.js +0 -132
  75. package/dist/scripts/types.d.ts +0 -107
  76. package/dist/scripts/types.js +0 -4
  77. package/dist/scripts/utils/index.d.ts +0 -6
  78. package/dist/scripts/utils/index.js +0 -6
  79. package/dist/scripts/utils/merkle.d.ts +0 -12
  80. package/dist/scripts/utils/merkle.js +0 -47
  81. package/dist/scripts/utils/storage.d.ts +0 -66
  82. package/dist/scripts/utils/storage.js +0 -211
  83. package/dist/scripts/utils/woc.d.ts +0 -26
  84. package/dist/scripts/utils/woc.js +0 -91
  85. package/dist/scripts/wallet/balance.d.ts +0 -22
  86. package/dist/scripts/wallet/balance.js +0 -240
  87. package/dist/scripts/wallet/identity.d.ts +0 -70
  88. package/dist/scripts/wallet/identity.js +0 -151
  89. package/dist/scripts/wallet/index.d.ts +0 -6
  90. package/dist/scripts/wallet/index.js +0 -6
  91. package/dist/scripts/wallet/setup.d.ts +0 -15
  92. package/dist/scripts/wallet/setup.js +0 -105
  93. package/dist/scripts/x-verification/commands.d.ts +0 -27
  94. package/dist/scripts/x-verification/commands.js +0 -222
  95. package/dist/scripts/x-verification/index.d.ts +0 -4
  96. package/dist/scripts/x-verification/index.js +0 -4
  97. package/dist/services/built-in/api-proxy/index.d.ts +0 -6
  98. package/dist/services/built-in/api-proxy/index.js +0 -23
  99. package/dist/services/built-in/code-develop/index.d.ts +0 -6
  100. package/dist/services/built-in/code-develop/index.js +0 -23
  101. package/dist/services/built-in/code-review/index.d.ts +0 -10
  102. package/dist/services/built-in/code-review/index.js +0 -51
  103. package/dist/services/built-in/image-analysis/index.d.ts +0 -6
  104. package/dist/services/built-in/image-analysis/index.js +0 -33
  105. package/dist/services/built-in/memory-store/index.d.ts +0 -6
  106. package/dist/services/built-in/memory-store/index.js +0 -22
  107. package/dist/services/built-in/roulette/index.d.ts +0 -6
  108. package/dist/services/built-in/roulette/index.js +0 -27
  109. package/dist/services/built-in/summarize/index.d.ts +0 -6
  110. package/dist/services/built-in/summarize/index.js +0 -21
  111. package/dist/services/built-in/tell-joke/handler.d.ts +0 -7
  112. package/dist/services/built-in/tell-joke/handler.js +0 -122
  113. package/dist/services/built-in/tell-joke/index.d.ts +0 -9
  114. package/dist/services/built-in/tell-joke/index.js +0 -31
  115. package/dist/services/built-in/translate/index.d.ts +0 -6
  116. package/dist/services/built-in/translate/index.js +0 -21
  117. package/dist/services/built-in/web-research/index.d.ts +0 -9
  118. package/dist/services/built-in/web-research/index.js +0 -51
  119. package/dist/services/index.d.ts +0 -13
  120. package/dist/services/index.js +0 -14
  121. package/dist/services/loader.d.ts +0 -77
  122. package/dist/services/loader.js +0 -292
  123. package/dist/services/manager.d.ts +0 -86
  124. package/dist/services/manager.js +0 -255
  125. package/dist/services/registry.d.ts +0 -98
  126. package/dist/services/registry.js +0 -204
  127. package/dist/services/types.d.ts +0 -230
  128. package/dist/services/types.js +0 -30
  129. package/dist/test/cli.test.d.ts +0 -7
  130. package/dist/test/cli.test.js +0 -329
  131. package/dist/test/comprehensive-overlay.test.d.ts +0 -13
  132. package/dist/test/comprehensive-overlay.test.js +0 -593
  133. package/dist/test/key-derivation.test.d.ts +0 -12
  134. package/dist/test/key-derivation.test.js +0 -86
  135. package/dist/test/overlay-submit.test.d.ts +0 -10
  136. package/dist/test/overlay-submit.test.js +0 -460
  137. package/dist/test/request-response-flow.test.d.ts +0 -5
  138. package/dist/test/request-response-flow.test.js +0 -209
  139. package/dist/test/service-system.test.d.ts +0 -5
  140. package/dist/test/service-system.test.js +0 -190
  141. package/dist/test/utils/server-logic.d.ts +0 -98
  142. package/dist/test/utils/server-logic.js +0 -286
  143. package/dist/test/wallet.test.d.ts +0 -7
  144. package/dist/test/wallet.test.js +0 -146
@@ -1,259 +0,0 @@
1
- /**
2
- * Baemail commands - paid message forwarding service.
3
- */
4
- import fs from 'node:fs';
5
- import { PATHS } from '../config.js';
6
- import { ok, fail } from '../output.js';
7
- import { loadIdentity } from '../wallet/identity.js';
8
- import { ensureStateDir } from '../utils/storage.js';
9
- import { fetchWithTimeout } from '../utils/woc.js';
10
- /**
11
- * Load baemail configuration.
12
- */
13
- export function loadBaemailConfig() {
14
- try {
15
- if (fs.existsSync(PATHS.baemailConfig)) {
16
- return JSON.parse(fs.readFileSync(PATHS.baemailConfig, 'utf-8'));
17
- }
18
- }
19
- catch (err) {
20
- console.warn(`[baemail] Warning: Could not read config: ${err.message}`);
21
- }
22
- return null;
23
- }
24
- /**
25
- * Save baemail configuration.
26
- */
27
- export function saveBaemailConfig(config) {
28
- ensureStateDir();
29
- fs.writeFileSync(PATHS.baemailConfig, JSON.stringify(config, null, 2));
30
- }
31
- /**
32
- * Setup baemail service with delivery channel and tier pricing.
33
- */
34
- export async function cmdBaemailSetup(channel, standardStr, priorityStr, urgentStr) {
35
- if (!channel || !standardStr) {
36
- return fail('Usage: baemail-setup <channel> <standardSats> [prioritySats] [urgentSats]');
37
- }
38
- const standard = parseInt(standardStr, 10);
39
- const priority = priorityStr ? parseInt(priorityStr, 10) : standard * 2;
40
- const urgent = urgentStr ? parseInt(urgentStr, 10) : standard * 5;
41
- if (isNaN(standard) || standard < 1) {
42
- return fail('Standard rate must be a positive integer (sats)');
43
- }
44
- if (priority < standard) {
45
- return fail('Priority rate must be >= standard rate');
46
- }
47
- if (urgent < priority) {
48
- return fail('Urgent rate must be >= priority rate');
49
- }
50
- const config = {
51
- deliveryChannel: channel,
52
- tiers: { standard, priority, urgent },
53
- maxMessageLength: 4000,
54
- blocklist: [],
55
- createdAt: new Date().toISOString(),
56
- updatedAt: new Date().toISOString(),
57
- };
58
- saveBaemailConfig(config);
59
- return ok({
60
- configured: true,
61
- deliveryChannel: channel,
62
- tiers: config.tiers,
63
- note: `Advertise with: cli advertise baemail "Baemail" "Paid message forwarding. Pay ${standard}+ sats to reach me." ${standard}`,
64
- });
65
- }
66
- /**
67
- * View current baemail configuration.
68
- */
69
- export async function cmdBaemailConfig() {
70
- const config = loadBaemailConfig();
71
- if (!config) {
72
- return fail('Baemail not configured. Run: baemail-setup <channel> <standardSats> [prioritySats] [urgentSats]');
73
- }
74
- return ok(config);
75
- }
76
- /**
77
- * Block a sender from using baemail.
78
- */
79
- export async function cmdBaemailBlock(identityKey) {
80
- if (!identityKey)
81
- return fail('Usage: baemail-block <identityKey>');
82
- const config = loadBaemailConfig();
83
- if (!config) {
84
- return fail('Baemail not configured. Run baemail-setup first.');
85
- }
86
- if (!config.blocklist)
87
- config.blocklist = [];
88
- if (config.blocklist.includes(identityKey)) {
89
- return fail('Identity already blocked');
90
- }
91
- config.blocklist.push(identityKey);
92
- config.updatedAt = new Date().toISOString();
93
- saveBaemailConfig(config);
94
- return ok({ blocked: identityKey, totalBlocked: config.blocklist.length });
95
- }
96
- /**
97
- * Unblock a sender.
98
- */
99
- export async function cmdBaemailUnblock(identityKey) {
100
- if (!identityKey)
101
- return fail('Usage: baemail-unblock <identityKey>');
102
- const config = loadBaemailConfig();
103
- if (!config) {
104
- return fail('Baemail not configured. Run baemail-setup first.');
105
- }
106
- if (!config.blocklist || !config.blocklist.includes(identityKey)) {
107
- return fail('Identity not in blocklist');
108
- }
109
- config.blocklist = config.blocklist.filter(k => k !== identityKey);
110
- config.updatedAt = new Date().toISOString();
111
- saveBaemailConfig(config);
112
- return ok({ unblocked: identityKey, totalBlocked: config.blocklist.length });
113
- }
114
- /**
115
- * View baemail delivery log.
116
- */
117
- export async function cmdBaemailLog(limitStr) {
118
- const limit = parseInt(limitStr || '20', 10) || 20;
119
- if (!fs.existsSync(PATHS.baemailLog)) {
120
- return ok({ log: [], count: 0 });
121
- }
122
- const lines = fs.readFileSync(PATHS.baemailLog, 'utf-8').split('\n').filter(l => l.trim());
123
- const entries = lines.map(l => {
124
- try {
125
- return JSON.parse(l);
126
- }
127
- catch {
128
- return null;
129
- }
130
- }).filter(Boolean);
131
- const recent = entries.slice(-limit).reverse();
132
- return ok({ log: recent, count: entries.length, showing: recent.length });
133
- }
134
- /**
135
- * Refund a failed baemail delivery.
136
- */
137
- export async function cmdBaemailRefund(requestId) {
138
- if (!requestId)
139
- return fail('Usage: baemail-refund <requestId>');
140
- if (!fs.existsSync(PATHS.baemailLog)) {
141
- return fail('No baemail log found');
142
- }
143
- // Find the entry
144
- const lines = fs.readFileSync(PATHS.baemailLog, 'utf-8').split('\n').filter(l => l.trim());
145
- const entries = lines.map((l, idx) => {
146
- try {
147
- return { ...JSON.parse(l), _lineIdx: idx };
148
- }
149
- catch {
150
- return null;
151
- }
152
- }).filter(Boolean);
153
- const entry = entries.find(e => e.requestId === requestId);
154
- if (!entry) {
155
- return fail(`Request ${requestId} not found in baemail log`);
156
- }
157
- if (entry.deliverySuccess) {
158
- return fail('This delivery was successful — no refund needed');
159
- }
160
- if (entry.refundStatus === 'completed') {
161
- return fail('Refund already processed for this request');
162
- }
163
- // Load wallet and SDK
164
- const { identityKey, privKey } = await loadIdentity();
165
- const walletIdentityRaw = fs.readFileSync(PATHS.walletIdentity, 'utf-8');
166
- const walletIdentity = JSON.parse(walletIdentityRaw);
167
- // Dynamic import SDK
168
- let sdk;
169
- try {
170
- sdk = await import('@bsv/sdk');
171
- }
172
- catch {
173
- return fail('Cannot load @bsv/sdk for refund transaction');
174
- }
175
- const { Transaction, P2PKH, PrivateKey, PublicKey, Hash } = sdk;
176
- // Calculate refund amount
177
- const refundSats = entry.paidSats - 1; // Keep 1 sat for tx fee
178
- if (refundSats < 1) {
179
- return fail('Amount too small to refund');
180
- }
181
- // Derive refund address from sender's identity key
182
- const senderPubKey = PublicKey.fromString(entry.from);
183
- const refundAddress = senderPubKey.toAddress().toString();
184
- try {
185
- // Load UTXOs
186
- const address = walletIdentity.address;
187
- const utxosResp = await fetchWithTimeout(`https://api.whatsonchain.com/v1/bsv/main/address/${address}/unspent/all`);
188
- const data = await utxosResp.json();
189
- const utxos = data.result || [];
190
- if (!utxos || utxos.length === 0) {
191
- return fail('No UTXOs available for refund');
192
- }
193
- // Build transaction
194
- const tx = new Transaction();
195
- let totalInput = 0;
196
- const rootKey = PrivateKey.fromHex(walletIdentity.rootKeyHex);
197
- for (const utxo of utxos) {
198
- if (totalInput >= refundSats + 50)
199
- break;
200
- tx.addInput({
201
- sourceTXID: utxo.tx_hash,
202
- sourceOutputIndex: utxo.tx_pos,
203
- sourceSatoshis: utxo.value,
204
- script: new P2PKH().lock(rootKey.toPublicKey().toAddress()).toHex(),
205
- unlockingScriptTemplate: new P2PKH().unlock(rootKey),
206
- });
207
- totalInput += utxo.value;
208
- }
209
- if (totalInput < refundSats + 10) {
210
- return fail('Insufficient funds for refund');
211
- }
212
- // Refund output
213
- tx.addOutput({
214
- satoshis: refundSats,
215
- lockingScript: new P2PKH().lock(refundAddress),
216
- });
217
- // Change output
218
- const fee = 10;
219
- const change = totalInput - refundSats - fee;
220
- if (change > 1) {
221
- tx.addOutput({
222
- satoshis: change,
223
- lockingScript: new P2PKH().lock(rootKey.toPublicKey().toAddress()),
224
- });
225
- }
226
- await tx.sign();
227
- // Broadcast
228
- const broadcastResp = await fetchWithTimeout('https://api.whatsonchain.com/v1/bsv/main/tx/raw', {
229
- method: 'POST',
230
- headers: { 'Content-Type': 'application/json' },
231
- body: JSON.stringify({ txhex: tx.toHex() }),
232
- });
233
- if (!broadcastResp.ok) {
234
- const errBody = await broadcastResp.text();
235
- return fail(`Broadcast failed: ${errBody}`);
236
- }
237
- const txid = tx.id('hex');
238
- // Update log entry
239
- const updatedLines = lines.map((l, idx) => {
240
- if (idx === entry._lineIdx) {
241
- const updated = { ...JSON.parse(l), refundStatus: 'completed', refundTxid: txid, refundedAt: new Date().toISOString() };
242
- return JSON.stringify(updated);
243
- }
244
- return l;
245
- });
246
- fs.writeFileSync(PATHS.baemailLog, updatedLines.join('\n') + '\n');
247
- return ok({
248
- refunded: true,
249
- requestId,
250
- refundSats,
251
- refundAddress,
252
- txid,
253
- note: `Refunded ${refundSats} sats to sender`,
254
- });
255
- }
256
- catch (err) {
257
- return fail(`Refund failed: ${err.message}`);
258
- }
259
- }
@@ -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 = 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.env.OPENCLAW_HOST || process.env.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 ? null : '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,48 +0,0 @@
1
- /**
2
- * Configuration constants and environment variables for the overlay CLI.
3
- */
4
- /** Wallet storage directory */
5
- export declare const WALLET_DIR: string;
6
- /** Network to use (mainnet or testnet) */
7
- export declare const NETWORK: 'mainnet' | 'testnet';
8
- /** Overlay server URL */
9
- export declare const OVERLAY_URL: string;
10
- /** Agent display name on the overlay network */
11
- export declare const AGENT_NAME: string;
12
- /** Agent description for the overlay identity */
13
- export declare const AGENT_DESCRIPTION: string;
14
- /** WhatsOnChain API key (optional, for rate limit bypass) */
15
- export declare const WOC_API_KEY: string;
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 = "openclaw 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
- };
26
- /** Lookup services for overlay queries */
27
- export declare const LOOKUP_SERVICES: {
28
- readonly AGENTS: "ls_clawdbot_agents";
29
- readonly SERVICES: "ls_clawdbot_services";
30
- readonly X_VERIFICATIONS: "ls_clawdbot_x_verifications";
31
- };
32
- /** Paths derived from config */
33
- export declare const PATHS: {
34
- readonly walletIdentity: string;
35
- readonly registration: string;
36
- readonly services: string;
37
- readonly latestChange: string;
38
- readonly receivedPayments: string;
39
- readonly researchQueue: string;
40
- readonly serviceQueue: string;
41
- readonly notifications: string;
42
- readonly xVerifications: string;
43
- readonly pendingXVerification: string;
44
- readonly xEngagementQueue: string;
45
- readonly memoryStore: string;
46
- readonly baemailConfig: string;
47
- readonly baemailLog: string;
48
- };