openclaw-overlay-plugin 0.8.14 → 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 (190) 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/index.ts +1 -1
  6. package/openclaw.plugin.json +1 -1
  7. package/package.json +8 -8
  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/test/identity-consistency.test.ts +1 -1
  18. package/src/test/wallet.test.ts +1 -2
  19. package/dist/index.d.ts +0 -9
  20. package/dist/src/cli-main.d.ts +0 -7
  21. package/dist/src/cli-main.js +0 -202
  22. package/dist/src/cli.d.ts +0 -8
  23. package/dist/src/compatibility.test.d.ts +0 -4
  24. package/dist/src/compatibility.test.js +0 -41
  25. package/dist/src/core/config.d.ts +0 -11
  26. package/dist/src/core/config.js +0 -15
  27. package/dist/src/core/index.d.ts +0 -25
  28. package/dist/src/core/index.js +0 -26
  29. package/dist/src/core/payment.d.ts +0 -16
  30. package/dist/src/core/payment.js +0 -94
  31. package/dist/src/core/types.d.ts +0 -94
  32. package/dist/src/core/types.js +0 -4
  33. package/dist/src/core/verify.d.ts +0 -28
  34. package/dist/src/core/verify.js +0 -104
  35. package/dist/src/core/wallet.d.ts +0 -105
  36. package/dist/src/core/wallet.js +0 -256
  37. package/dist/src/scripts/baemail/commands.d.ts +0 -35
  38. package/dist/src/scripts/baemail/commands.js +0 -282
  39. package/dist/src/scripts/baemail/handler.d.ts +0 -36
  40. package/dist/src/scripts/baemail/handler.js +0 -284
  41. package/dist/src/scripts/baemail/index.d.ts +0 -5
  42. package/dist/src/scripts/baemail/index.js +0 -5
  43. package/dist/src/scripts/config.d.ts +0 -52
  44. package/dist/src/scripts/config.js +0 -75
  45. package/dist/src/scripts/index.d.ts +0 -7
  46. package/dist/src/scripts/index.js +0 -7
  47. package/dist/src/scripts/messaging/connect.d.ts +0 -8
  48. package/dist/src/scripts/messaging/connect.js +0 -168
  49. package/dist/src/scripts/messaging/handlers.d.ts +0 -21
  50. package/dist/src/scripts/messaging/handlers.js +0 -334
  51. package/dist/src/scripts/messaging/inbox.d.ts +0 -11
  52. package/dist/src/scripts/messaging/inbox.js +0 -51
  53. package/dist/src/scripts/messaging/index.d.ts +0 -8
  54. package/dist/src/scripts/messaging/index.js +0 -8
  55. package/dist/src/scripts/messaging/poll.d.ts +0 -7
  56. package/dist/src/scripts/messaging/poll.js +0 -52
  57. package/dist/src/scripts/messaging/send.d.ts +0 -7
  58. package/dist/src/scripts/messaging/send.js +0 -43
  59. package/dist/src/scripts/output.d.ts +0 -13
  60. package/dist/src/scripts/output.js +0 -28
  61. package/dist/src/scripts/overlay/advertisement.d.ts +0 -16
  62. package/dist/src/scripts/overlay/advertisement.js +0 -122
  63. package/dist/src/scripts/overlay/discover.d.ts +0 -7
  64. package/dist/src/scripts/overlay/discover.js +0 -74
  65. package/dist/src/scripts/overlay/index.d.ts +0 -7
  66. package/dist/src/scripts/overlay/index.js +0 -7
  67. package/dist/src/scripts/overlay/registration.d.ts +0 -19
  68. package/dist/src/scripts/overlay/registration.js +0 -176
  69. package/dist/src/scripts/overlay/services.d.ts +0 -29
  70. package/dist/src/scripts/overlay/services.js +0 -167
  71. package/dist/src/scripts/overlay/transaction.d.ts +0 -42
  72. package/dist/src/scripts/overlay/transaction.js +0 -103
  73. package/dist/src/scripts/payment/build.d.ts +0 -24
  74. package/dist/src/scripts/payment/build.js +0 -54
  75. package/dist/src/scripts/payment/commands.d.ts +0 -15
  76. package/dist/src/scripts/payment/commands.js +0 -73
  77. package/dist/src/scripts/payment/index.d.ts +0 -6
  78. package/dist/src/scripts/payment/index.js +0 -6
  79. package/dist/src/scripts/payment/types.d.ts +0 -56
  80. package/dist/src/scripts/payment/types.js +0 -4
  81. package/dist/src/scripts/services/index.d.ts +0 -6
  82. package/dist/src/scripts/services/index.js +0 -6
  83. package/dist/src/scripts/services/queue.d.ts +0 -11
  84. package/dist/src/scripts/services/queue.js +0 -28
  85. package/dist/src/scripts/services/request.d.ts +0 -7
  86. package/dist/src/scripts/services/request.js +0 -82
  87. package/dist/src/scripts/services/respond.d.ts +0 -11
  88. package/dist/src/scripts/services/respond.js +0 -132
  89. package/dist/src/scripts/types.d.ts +0 -107
  90. package/dist/src/scripts/types.js +0 -4
  91. package/dist/src/scripts/utils/index.d.ts +0 -6
  92. package/dist/src/scripts/utils/index.js +0 -6
  93. package/dist/src/scripts/utils/merkle.d.ts +0 -12
  94. package/dist/src/scripts/utils/merkle.js +0 -47
  95. package/dist/src/scripts/utils/storage.d.ts +0 -66
  96. package/dist/src/scripts/utils/storage.js +0 -211
  97. package/dist/src/scripts/utils/woc.d.ts +0 -26
  98. package/dist/src/scripts/utils/woc.js +0 -91
  99. package/dist/src/scripts/wallet/balance.d.ts +0 -22
  100. package/dist/src/scripts/wallet/balance.js +0 -240
  101. package/dist/src/scripts/wallet/identity.d.ts +0 -71
  102. package/dist/src/scripts/wallet/identity.js +0 -152
  103. package/dist/src/scripts/wallet/index.d.ts +0 -6
  104. package/dist/src/scripts/wallet/index.js +0 -6
  105. package/dist/src/scripts/wallet/setup.d.ts +0 -19
  106. package/dist/src/scripts/wallet/setup.js +0 -119
  107. package/dist/src/scripts/x-verification/commands.d.ts +0 -27
  108. package/dist/src/scripts/x-verification/commands.js +0 -222
  109. package/dist/src/scripts/x-verification/index.d.ts +0 -4
  110. package/dist/src/scripts/x-verification/index.js +0 -4
  111. package/dist/src/services/built-in/api-proxy/index.d.ts +0 -6
  112. package/dist/src/services/built-in/api-proxy/index.js +0 -23
  113. package/dist/src/services/built-in/code-develop/index.d.ts +0 -6
  114. package/dist/src/services/built-in/code-develop/index.js +0 -23
  115. package/dist/src/services/built-in/code-review/index.d.ts +0 -10
  116. package/dist/src/services/built-in/code-review/index.js +0 -51
  117. package/dist/src/services/built-in/image-analysis/index.d.ts +0 -6
  118. package/dist/src/services/built-in/image-analysis/index.js +0 -33
  119. package/dist/src/services/built-in/memory-store/index.d.ts +0 -6
  120. package/dist/src/services/built-in/memory-store/index.js +0 -22
  121. package/dist/src/services/built-in/roulette/index.d.ts +0 -6
  122. package/dist/src/services/built-in/roulette/index.js +0 -27
  123. package/dist/src/services/built-in/summarize/index.d.ts +0 -6
  124. package/dist/src/services/built-in/summarize/index.js +0 -21
  125. package/dist/src/services/built-in/tell-joke/handler.d.ts +0 -7
  126. package/dist/src/services/built-in/tell-joke/handler.js +0 -122
  127. package/dist/src/services/built-in/tell-joke/index.d.ts +0 -9
  128. package/dist/src/services/built-in/tell-joke/index.js +0 -31
  129. package/dist/src/services/built-in/translate/index.d.ts +0 -6
  130. package/dist/src/services/built-in/translate/index.js +0 -21
  131. package/dist/src/services/built-in/web-research/index.d.ts +0 -9
  132. package/dist/src/services/built-in/web-research/index.js +0 -51
  133. package/dist/src/services/index.d.ts +0 -13
  134. package/dist/src/services/index.js +0 -14
  135. package/dist/src/services/loader.d.ts +0 -77
  136. package/dist/src/services/loader.js +0 -292
  137. package/dist/src/services/manager.d.ts +0 -86
  138. package/dist/src/services/manager.js +0 -255
  139. package/dist/src/services/registry.d.ts +0 -98
  140. package/dist/src/services/registry.js +0 -204
  141. package/dist/src/services/types.d.ts +0 -230
  142. package/dist/src/services/types.js +0 -30
  143. package/dist/src/test/cli.test.d.ts +0 -7
  144. package/dist/src/test/cli.test.js +0 -330
  145. package/dist/src/test/comprehensive-overlay.test.d.ts +0 -13
  146. package/dist/src/test/comprehensive-overlay.test.js +0 -593
  147. package/dist/src/test/identity-consistency.test.d.ts +0 -6
  148. package/dist/src/test/identity-consistency.test.js +0 -60
  149. package/dist/src/test/key-derivation.test.d.ts +0 -12
  150. package/dist/src/test/key-derivation.test.js +0 -86
  151. package/dist/src/test/network-address.test.d.ts +0 -9
  152. package/dist/src/test/network-address.test.js +0 -37
  153. package/dist/src/test/overlay-submit.test.d.ts +0 -10
  154. package/dist/src/test/overlay-submit.test.js +0 -460
  155. package/dist/src/test/request-response-flow.test.d.ts +0 -5
  156. package/dist/src/test/request-response-flow.test.js +0 -210
  157. package/dist/src/test/service-system.test.d.ts +0 -5
  158. package/dist/src/test/service-system.test.js +0 -190
  159. package/dist/src/test/taskflow.test.d.ts +0 -7
  160. package/dist/src/test/taskflow.test.js +0 -82
  161. package/dist/src/test/utils/server-logic.d.ts +0 -98
  162. package/dist/src/test/utils/server-logic.js +0 -286
  163. package/dist/src/test/wallet.test.d.ts +0 -7
  164. package/dist/src/test/wallet.test.js +0 -146
  165. package/src/core/README.md +0 -246
  166. package/src/core/config.d.ts +0 -12
  167. package/src/core/config.d.ts.map +0 -1
  168. package/src/core/config.js +0 -14
  169. package/src/core/config.js.map +0 -1
  170. package/src/core/config.ts +0 -22
  171. package/src/core/index.ts +0 -42
  172. package/src/core/payment.d.ts +0 -17
  173. package/src/core/payment.d.ts.map +0 -1
  174. package/src/core/payment.js +0 -95
  175. package/src/core/payment.js.map +0 -1
  176. package/src/core/payment.ts +0 -111
  177. package/src/core/types.d.ts +0 -95
  178. package/src/core/types.d.ts.map +0 -1
  179. package/src/core/types.js +0 -5
  180. package/src/core/types.js.map +0 -1
  181. package/src/core/types.ts +0 -102
  182. package/src/core/verify.d.ts +0 -29
  183. package/src/core/verify.d.ts.map +0 -1
  184. package/src/core/verify.js +0 -105
  185. package/src/core/verify.js.map +0 -1
  186. package/src/core/verify.ts +0 -119
  187. package/src/core/wallet.d.ts +0 -100
  188. package/src/core/wallet.d.ts.map +0 -1
  189. package/src/core/wallet.js.map +0 -1
  190. package/src/core/wallet.ts +0 -323
@@ -1,82 +0,0 @@
1
- /**
2
- * Service request command.
3
- */
4
- import { OVERLAY_URL } from '../config.js';
5
- import { ok, fail } from '../output.js';
6
- import { loadIdentity, signRelayMessage } from '../wallet/identity.js';
7
- import { buildDirectPayment } from '../payment/build.js';
8
- /**
9
- * Request service command: send a service request with optional payment.
10
- */
11
- export async function cmdRequestService(targetKey, serviceId, satsStr, inputJsonStr) {
12
- if (!targetKey || !serviceId) {
13
- return fail('Usage: request-service <identityKey> <serviceId> [sats] [inputJson]');
14
- }
15
- if (!/^0[23][0-9a-fA-F]{64}$/.test(targetKey)) {
16
- return fail('Target must be a compressed public key (66 hex chars, 02/03 prefix)');
17
- }
18
- const { identityKey, privKey } = await loadIdentity();
19
- const sats = parseInt(satsStr || '5', 10);
20
- // Parse optional input JSON
21
- let inputData = null;
22
- if (inputJsonStr) {
23
- try {
24
- inputData = JSON.parse(inputJsonStr);
25
- }
26
- catch {
27
- return fail('inputJson must be valid JSON');
28
- }
29
- }
30
- // Build the service request payload
31
- let paymentData = null;
32
- if (sats > 0) {
33
- try {
34
- const payment = await buildDirectPayment(targetKey, sats, `service-request: ${serviceId}`);
35
- paymentData = {
36
- beef: payment.beef,
37
- txid: payment.txid,
38
- satoshis: payment.satoshis,
39
- derivationPrefix: payment.derivationPrefix,
40
- derivationSuffix: payment.derivationSuffix,
41
- senderIdentityKey: payment.senderIdentityKey,
42
- };
43
- }
44
- catch (err) {
45
- // Payment failed — send request without payment
46
- paymentData = { error: String(err.message || err) };
47
- }
48
- }
49
- const requestPayload = {
50
- serviceId,
51
- ...(inputData ? { input: inputData } : {}),
52
- payment: paymentData,
53
- requestedAt: new Date().toISOString(),
54
- };
55
- const signature = await signRelayMessage(privKey, targetKey, 'service-request', requestPayload);
56
- const resp = await fetch(`${OVERLAY_URL}/relay/send`, {
57
- method: 'POST',
58
- headers: { 'Content-Type': 'application/json' },
59
- body: JSON.stringify({
60
- from: identityKey,
61
- to: targetKey,
62
- type: 'service-request',
63
- payload: requestPayload,
64
- signature,
65
- }),
66
- });
67
- if (!resp.ok) {
68
- const body = await resp.text();
69
- return fail(`Relay send failed (${resp.status}): ${body}`);
70
- }
71
- const result = await resp.json();
72
- return ok({
73
- sent: true,
74
- requestId: result.id,
75
- to: targetKey,
76
- serviceId,
77
- paymentIncluded: paymentData && !paymentData.error,
78
- paymentTxid: paymentData?.txid || null,
79
- satoshis: paymentData?.satoshis || 0,
80
- note: 'Poll for service-response to get the result',
81
- });
82
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * Service response commands.
3
- */
4
- /**
5
- * Respond to a service request.
6
- */
7
- export declare function cmdRespondService(requestId: string | undefined, recipientKey: string | undefined, serviceId: string | undefined, resultJson: string | undefined): Promise<any>;
8
- /**
9
- * Respond to a research request with results.
10
- */
11
- export declare function cmdResearchRespond(resultJsonPath: string | undefined): Promise<any>;
@@ -1,132 +0,0 @@
1
- /**
2
- * Service response commands.
3
- */
4
- import fs from 'node:fs';
5
- import { OVERLAY_URL, PATHS } from '../config.js';
6
- import { ok, fail } from '../output.js';
7
- import { loadIdentity, signRelayMessage } from '../wallet/identity.js';
8
- import { updateServiceQueueStatus } from '../utils/storage.js';
9
- /**
10
- * Respond to a service request.
11
- */
12
- export async function cmdRespondService(requestId, recipientKey, serviceId, resultJson) {
13
- if (!requestId || !recipientKey || !serviceId || !resultJson) {
14
- return fail('Usage: respond-service <requestId> <recipientKey> <serviceId> <resultJson>');
15
- }
16
- let result;
17
- try {
18
- result = JSON.parse(resultJson);
19
- }
20
- catch {
21
- return fail('resultJson must be valid JSON');
22
- }
23
- const { identityKey, privKey } = await loadIdentity();
24
- // Check if already processed before sending response (idempotency)
25
- if (fs.existsSync(PATHS.serviceQueue)) {
26
- const lines = fs.readFileSync(PATHS.serviceQueue, 'utf-8').trim().split('\n').filter(Boolean);
27
- const finalStatuses = ['fulfilled', 'rejected', 'delivery_failed', 'failed', 'error'];
28
- for (const line of lines) {
29
- try {
30
- const entry = JSON.parse(line);
31
- if (entry.requestId === requestId && finalStatuses.includes(entry.status)) {
32
- return ok({
33
- sent: false,
34
- requestId,
35
- serviceId,
36
- to: recipientKey,
37
- message: `Request already processed with status: ${entry.status}`,
38
- alreadyProcessed: true,
39
- previousStatus: entry.status
40
- });
41
- }
42
- }
43
- catch { }
44
- }
45
- }
46
- const responsePayload = {
47
- requestId,
48
- serviceId,
49
- status: 'fulfilled',
50
- result,
51
- };
52
- const sig = await signRelayMessage(privKey, recipientKey, 'service-response', responsePayload);
53
- const resp = await fetch(`${OVERLAY_URL}/relay/send`, {
54
- method: 'POST',
55
- headers: { 'Content-Type': 'application/json' },
56
- body: JSON.stringify({
57
- from: identityKey,
58
- to: recipientKey,
59
- type: 'service-response',
60
- payload: responsePayload,
61
- signature: sig,
62
- }),
63
- });
64
- if (!resp.ok) {
65
- // Mark as failed in queue using atomic update
66
- updateServiceQueueStatus(requestId, 'failed', {
67
- failedAt: Date.now(),
68
- error: `Relay send failed: ${resp.status}`
69
- });
70
- return fail(`Relay send failed: ${resp.status}`);
71
- }
72
- // Mark as fulfilled in queue using atomic update
73
- updateServiceQueueStatus(requestId, 'fulfilled', {
74
- fulfilledAt: Date.now()
75
- });
76
- return ok({ sent: true, requestId, serviceId, to: recipientKey });
77
- }
78
- /**
79
- * Respond to a research request with results.
80
- */
81
- export async function cmdResearchRespond(resultJsonPath) {
82
- if (!resultJsonPath)
83
- return fail('Usage: research-respond <resultJsonFile>');
84
- if (!fs.existsSync(resultJsonPath))
85
- return fail(`File not found: ${resultJsonPath}`);
86
- const result = JSON.parse(fs.readFileSync(resultJsonPath, 'utf-8'));
87
- const { requestId, from: recipientKey, query, research } = result;
88
- if (!requestId || !recipientKey || !research) {
89
- return fail('Result JSON must have: requestId, from, query, research');
90
- }
91
- const { identityKey, privKey } = await loadIdentity();
92
- const responsePayload = {
93
- requestId,
94
- serviceId: 'web-research',
95
- status: 'fulfilled',
96
- result: research,
97
- paymentAccepted: true,
98
- paymentTxid: result.paymentTxid || null,
99
- satoshisReceived: result.satoshisReceived || 0,
100
- walletAccepted: result.walletAccepted ?? true,
101
- };
102
- const sig = await signRelayMessage(privKey, recipientKey, 'service-response', responsePayload);
103
- const sendResp = await fetch(`${OVERLAY_URL}/relay/send`, {
104
- method: 'POST',
105
- headers: { 'Content-Type': 'application/json' },
106
- body: JSON.stringify({
107
- from: identityKey,
108
- to: recipientKey,
109
- type: 'service-response',
110
- payload: responsePayload,
111
- signature: sig,
112
- }),
113
- });
114
- if (!sendResp.ok) {
115
- return fail(`Failed to send response: ${await sendResp.text()}`);
116
- }
117
- const sendResult = await sendResp.json();
118
- // Remove from queue
119
- if (fs.existsSync(PATHS.researchQueue)) {
120
- const lines = fs.readFileSync(PATHS.researchQueue, 'utf-8').trim().split('\n').filter(Boolean);
121
- const remaining = lines.filter((l) => {
122
- try {
123
- return JSON.parse(l).requestId !== requestId;
124
- }
125
- catch {
126
- return true;
127
- }
128
- });
129
- fs.writeFileSync(PATHS.researchQueue, remaining.length ? remaining.join('\n') + '\n' : '');
130
- }
131
- return ok({ responded: true, requestId, to: recipientKey, query, pushed: sendResult.pushed });
132
- }
@@ -1,107 +0,0 @@
1
- /**
2
- * Shared TypeScript interfaces for the overlay CLI.
3
- */
4
- export interface WalletIdentity {
5
- rootKeyHex: string;
6
- identityKey: string;
7
- network: 'mainnet' | 'testnet';
8
- }
9
- export interface PaymentResult {
10
- beef: string;
11
- txid: string;
12
- satoshis: number;
13
- derivationPrefix: string;
14
- derivationSuffix: string;
15
- senderIdentityKey: string;
16
- }
17
- export interface PaymentParams {
18
- to: string;
19
- satoshis: number;
20
- description?: string;
21
- }
22
- export interface ServiceAdvertisement {
23
- serviceId: string;
24
- name: string;
25
- description: string;
26
- priceSats: number;
27
- txid?: string;
28
- registeredAt?: string;
29
- }
30
- export interface Message {
31
- id: string;
32
- from: string;
33
- to: string;
34
- type: string;
35
- payload: unknown;
36
- signature?: string;
37
- timestamp?: number;
38
- }
39
- export interface CommandResult<T = unknown> {
40
- success: boolean;
41
- data?: T;
42
- error?: string;
43
- }
44
- export interface Registration {
45
- identityKey: string;
46
- agentName: string;
47
- agentDescription: string;
48
- overlayUrl: string;
49
- identityTxid: string;
50
- serviceTxid: string | null;
51
- funded: string;
52
- registeredAt: string;
53
- }
54
- export interface OverlayPayload {
55
- protocol: string;
56
- type: string;
57
- identityKey?: string;
58
- [key: string]: unknown;
59
- }
60
- export interface VerifyAndAcceptResult {
61
- accepted: boolean;
62
- txid: string | null;
63
- satoshis: number;
64
- outputIndex: number;
65
- walletAccepted: boolean;
66
- error: string | null;
67
- }
68
- export interface ProcessMessageResult {
69
- id: string;
70
- type: string;
71
- action: string;
72
- from: string;
73
- ack: boolean;
74
- [key: string]: unknown;
75
- }
76
- export interface RelayMessage {
77
- id: string;
78
- from: string;
79
- to: string;
80
- type: string;
81
- payload: Record<string, unknown>;
82
- signature?: string;
83
- }
84
- export interface XVerification {
85
- identityKey: string;
86
- xHandle: string;
87
- xUserId: string;
88
- tweetId: string;
89
- tweetUrl: string;
90
- signature: string;
91
- verifiedAt: string;
92
- txid?: string | null;
93
- }
94
- export interface StoredChange {
95
- txHex: string;
96
- txid: string;
97
- vout: number;
98
- satoshis: number;
99
- sourceChain?: SourceChainEntry[];
100
- savedAt: string;
101
- }
102
- export interface SourceChainEntry {
103
- txHex: string;
104
- txid: string;
105
- merklePathHex?: string;
106
- blockHeight?: number;
107
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * Shared TypeScript interfaces for the overlay CLI.
3
- */
4
- export {};
@@ -1,6 +0,0 @@
1
- /**
2
- * Utility module exports.
3
- */
4
- export * from './woc.js';
5
- export * from './storage.js';
6
- export * from './merkle.js';
@@ -1,6 +0,0 @@
1
- /**
2
- * Utility module exports.
3
- */
4
- export * from './woc.js';
5
- export * from './storage.js';
6
- export * from './merkle.js';
@@ -1,12 +0,0 @@
1
- /**
2
- * Merkle path utilities for SPV proofs.
3
- */
4
- import type { MerklePath as MerklePathType } from '@bsv/sdk';
5
- /**
6
- * Build a MerklePath from TSC (Transaction Status Check) proof data.
7
- * @param txid - Transaction ID
8
- * @param txIndex - Transaction's index in the block
9
- * @param nodes - Array of sibling hashes (or '*' for duplicate)
10
- * @param blockHeight - Block height
11
- */
12
- export declare function buildMerklePathFromTSC(txid: string, txIndex: number, nodes: string[], blockHeight: number): Promise<MerklePathType>;
@@ -1,47 +0,0 @@
1
- /**
2
- * Merkle path utilities for SPV proofs.
3
- */
4
- // We'll import MerklePath dynamically to avoid issues with ESM resolution
5
- let _MerklePath = null;
6
- async function getMerklePath() {
7
- if (_MerklePath)
8
- return _MerklePath;
9
- const sdk = await import('@bsv/sdk');
10
- _MerklePath = sdk.MerklePath;
11
- return _MerklePath;
12
- }
13
- /**
14
- * Build a MerklePath from TSC (Transaction Status Check) proof data.
15
- * @param txid - Transaction ID
16
- * @param txIndex - Transaction's index in the block
17
- * @param nodes - Array of sibling hashes (or '*' for duplicate)
18
- * @param blockHeight - Block height
19
- */
20
- export async function buildMerklePathFromTSC(txid, txIndex, nodes, blockHeight) {
21
- const MerklePath = await getMerklePath();
22
- const treeHeight = nodes.length;
23
- const mpPath = [];
24
- // Level 0
25
- const level0 = [
26
- { offset: txIndex, hash: txid, txid: true }
27
- ];
28
- if (nodes[0] === '*') {
29
- level0.push({ offset: txIndex ^ 1, duplicate: true });
30
- }
31
- else {
32
- level0.push({ offset: txIndex ^ 1, hash: nodes[0] });
33
- }
34
- level0.sort((a, b) => a.offset - b.offset);
35
- mpPath.push(level0);
36
- // Higher levels
37
- for (let i = 1; i < treeHeight; i++) {
38
- const siblingOffset = (txIndex >> i) ^ 1;
39
- if (nodes[i] === '*') {
40
- mpPath.push([{ offset: siblingOffset, duplicate: true }]);
41
- }
42
- else {
43
- mpPath.push([{ offset: siblingOffset, hash: nodes[i] }]);
44
- }
45
- }
46
- return new MerklePath(blockHeight, mpPath);
47
- }
@@ -1,66 +0,0 @@
1
- /**
2
- * File-based storage helpers for registration, services, and queues.
3
- */
4
- import type { Registration, ServiceAdvertisement, XVerification, StoredChange } from '../types.js';
5
- /**
6
- * Ensure the overlay state directory exists.
7
- */
8
- export declare function ensureStateDir(): void;
9
- /**
10
- * Load registration data from disk.
11
- */
12
- export declare function loadRegistration(): Registration | null;
13
- /**
14
- * Save registration data to disk.
15
- */
16
- export declare function saveRegistration(data: Registration): void;
17
- /**
18
- * Delete registration file.
19
- */
20
- export declare function deleteRegistration(): void;
21
- /**
22
- * Load services list from disk.
23
- */
24
- export declare function loadServices(): ServiceAdvertisement[];
25
- /**
26
- * Save services list to disk.
27
- */
28
- export declare function saveServices(services: ServiceAdvertisement[]): void;
29
- /**
30
- * Load X verifications from disk.
31
- */
32
- export declare function loadXVerifications(): XVerification[];
33
- /**
34
- * Save X verifications to disk.
35
- */
36
- export declare function saveXVerifications(verifications: XVerification[]): void;
37
- /**
38
- * Append a line to a JSONL file.
39
- */
40
- export declare function appendToJsonl(filePath: string, entry: Record<string, unknown>): void;
41
- /**
42
- * Read and parse a JSONL file.
43
- */
44
- export declare function readJsonl<T>(filePath: string): T[];
45
- /**
46
- * Load stored change BEEF data.
47
- */
48
- export declare function loadStoredChange(): StoredChange | null;
49
- /**
50
- * Save stored change BEEF data.
51
- */
52
- export declare function saveStoredChange(data: StoredChange): void;
53
- /**
54
- * Delete stored change file.
55
- */
56
- export declare function deleteStoredChange(): void;
57
- /**
58
- * Clean up old entries from service queue.
59
- * Removes entries older than maxAgeMs or entries with final statuses older than finalStatusMaxAgeMs.
60
- */
61
- export declare function cleanupServiceQueue(maxAgeMs?: number, finalStatusMaxAgeMs?: number): void;
62
- /**
63
- * Atomically update a service queue entry status.
64
- * Returns true if the entry was found and updated, false otherwise.
65
- */
66
- export declare function updateServiceQueueStatus(requestId: string, newStatus: string, additionalFields?: Record<string, any>): boolean;
@@ -1,211 +0,0 @@
1
- /**
2
- * File-based storage helpers for registration, services, and queues.
3
- */
4
- import fs from 'node:fs';
5
- import { OVERLAY_STATE_DIR, PATHS } from '../config.js';
6
- /**
7
- * Ensure the overlay state directory exists.
8
- */
9
- export function ensureStateDir() {
10
- fs.mkdirSync(OVERLAY_STATE_DIR, { recursive: true });
11
- }
12
- /**
13
- * Load registration data from disk.
14
- */
15
- export function loadRegistration() {
16
- try {
17
- if (fs.existsSync(PATHS.registration)) {
18
- return JSON.parse(fs.readFileSync(PATHS.registration, 'utf-8'));
19
- }
20
- }
21
- catch {
22
- // Ignore parse errors
23
- }
24
- return null;
25
- }
26
- /**
27
- * Save registration data to disk.
28
- */
29
- export function saveRegistration(data) {
30
- ensureStateDir();
31
- fs.writeFileSync(PATHS.registration, JSON.stringify(data, null, 2), 'utf-8');
32
- }
33
- /**
34
- * Delete registration file.
35
- */
36
- export function deleteRegistration() {
37
- try {
38
- fs.unlinkSync(PATHS.registration);
39
- }
40
- catch {
41
- // Ignore if file doesn't exist
42
- }
43
- }
44
- /**
45
- * Load services list from disk.
46
- */
47
- export function loadServices() {
48
- try {
49
- if (fs.existsSync(PATHS.services)) {
50
- return JSON.parse(fs.readFileSync(PATHS.services, 'utf-8'));
51
- }
52
- }
53
- catch {
54
- // Ignore parse errors
55
- }
56
- return [];
57
- }
58
- /**
59
- * Save services list to disk.
60
- */
61
- export function saveServices(services) {
62
- ensureStateDir();
63
- fs.writeFileSync(PATHS.services, JSON.stringify(services, null, 2), 'utf-8');
64
- }
65
- /**
66
- * Load X verifications from disk.
67
- */
68
- export function loadXVerifications() {
69
- try {
70
- if (fs.existsSync(PATHS.xVerifications)) {
71
- return JSON.parse(fs.readFileSync(PATHS.xVerifications, 'utf-8'));
72
- }
73
- }
74
- catch {
75
- // Ignore parse errors
76
- }
77
- return [];
78
- }
79
- /**
80
- * Save X verifications to disk.
81
- */
82
- export function saveXVerifications(verifications) {
83
- ensureStateDir();
84
- fs.writeFileSync(PATHS.xVerifications, JSON.stringify(verifications, null, 2), 'utf-8');
85
- }
86
- /**
87
- * Append a line to a JSONL file.
88
- */
89
- export function appendToJsonl(filePath, entry) {
90
- ensureStateDir();
91
- fs.appendFileSync(filePath, JSON.stringify(entry) + '\n');
92
- }
93
- /**
94
- * Read and parse a JSONL file.
95
- */
96
- export function readJsonl(filePath) {
97
- if (!fs.existsSync(filePath))
98
- return [];
99
- const lines = fs.readFileSync(filePath, 'utf-8').trim().split('\n').filter(Boolean);
100
- return lines.map((line) => {
101
- try {
102
- return JSON.parse(line);
103
- }
104
- catch {
105
- return null;
106
- }
107
- }).filter(Boolean);
108
- }
109
- /**
110
- * Load stored change BEEF data.
111
- */
112
- export function loadStoredChange() {
113
- try {
114
- if (fs.existsSync(PATHS.latestChange)) {
115
- return JSON.parse(fs.readFileSync(PATHS.latestChange, 'utf-8'));
116
- }
117
- }
118
- catch {
119
- // Ignore parse errors
120
- }
121
- return null;
122
- }
123
- /**
124
- * Save stored change BEEF data.
125
- */
126
- export function saveStoredChange(data) {
127
- ensureStateDir();
128
- fs.writeFileSync(PATHS.latestChange, JSON.stringify(data));
129
- }
130
- /**
131
- * Delete stored change file.
132
- */
133
- export function deleteStoredChange() {
134
- try {
135
- fs.unlinkSync(PATHS.latestChange);
136
- }
137
- catch {
138
- // Ignore if file doesn't exist
139
- }
140
- }
141
- /**
142
- * Clean up old entries from service queue.
143
- * Removes entries older than maxAgeMs or entries with final statuses older than finalStatusMaxAgeMs.
144
- */
145
- export function cleanupServiceQueue(maxAgeMs = 24 * 60 * 60 * 1000, finalStatusMaxAgeMs = 2 * 60 * 60 * 1000) {
146
- if (!fs.existsSync(PATHS.serviceQueue))
147
- return;
148
- const now = Date.now();
149
- const finalStatuses = ['fulfilled', 'rejected', 'delivery_failed', 'failed', 'error'];
150
- const lines = fs.readFileSync(PATHS.serviceQueue, 'utf-8').trim().split('\n').filter(Boolean);
151
- const keptLines = [];
152
- let removedCount = 0;
153
- for (const line of lines) {
154
- try {
155
- const entry = JSON.parse(line);
156
- const entryAge = now - (entry._ts || 0);
157
- // Always keep pending entries that aren't too old
158
- if (entry.status === 'pending' && entryAge < maxAgeMs) {
159
- keptLines.push(line);
160
- continue;
161
- }
162
- // Keep final status entries only if they're recent
163
- if (finalStatuses.includes(entry.status) && entryAge < finalStatusMaxAgeMs) {
164
- keptLines.push(line);
165
- continue;
166
- }
167
- // Remove this entry
168
- removedCount++;
169
- }
170
- catch {
171
- // Keep malformed entries to avoid data loss
172
- keptLines.push(line);
173
- }
174
- }
175
- if (removedCount > 0) {
176
- fs.writeFileSync(PATHS.serviceQueue, keptLines.join('\n') + (keptLines.length ? '\n' : ''));
177
- console.error(JSON.stringify({ event: 'queue-cleanup', removed: removedCount, kept: keptLines.length }));
178
- }
179
- }
180
- /**
181
- * Atomically update a service queue entry status.
182
- * Returns true if the entry was found and updated, false otherwise.
183
- */
184
- export function updateServiceQueueStatus(requestId, newStatus, additionalFields = {}) {
185
- if (!fs.existsSync(PATHS.serviceQueue))
186
- return false;
187
- const lines = fs.readFileSync(PATHS.serviceQueue, 'utf-8').trim().split('\n').filter(Boolean);
188
- let updated = false;
189
- const updatedLines = lines.map(line => {
190
- try {
191
- const entry = JSON.parse(line);
192
- if (entry.requestId === requestId) {
193
- updated = true;
194
- return JSON.stringify({
195
- ...entry,
196
- status: newStatus,
197
- ...additionalFields,
198
- updatedAt: Date.now()
199
- });
200
- }
201
- return line;
202
- }
203
- catch {
204
- return line;
205
- }
206
- });
207
- if (updated) {
208
- fs.writeFileSync(PATHS.serviceQueue, updatedLines.join('\n') + '\n');
209
- }
210
- return updated;
211
- }