openclaw-overlay-plugin 0.8.15 → 0.8.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3037 -328
- package/dist/index.js.map +7 -0
- package/dist/src/cli.js +3820 -11
- package/dist/src/cli.js.map +7 -0
- package/index.ts +32 -27
- package/openclaw.plugin.json +1 -1
- package/package.json +8 -6
- package/src/scripts/messaging/handlers.ts +1 -1
- package/src/scripts/overlay/advertisement.ts +1 -1
- package/src/scripts/overlay/registration.ts +1 -1
- package/src/scripts/overlay/services.ts +1 -1
- package/src/scripts/overlay/transaction.ts +1 -1
- package/src/scripts/payment/build.ts +1 -1
- package/src/scripts/payment/commands.ts +1 -1
- package/src/scripts/wallet/balance.ts +1 -1
- package/src/scripts/wallet/setup.ts +1 -1
- package/src/scripts/x-verification/commands.ts +5 -0
- package/src/test/identity-consistency.test.ts +1 -1
- package/src/test/wallet.test.ts +1 -2
- package/dist/index.d.ts +0 -9
- package/dist/src/cli-main.d.ts +0 -7
- package/dist/src/cli-main.js +0 -202
- package/dist/src/cli.d.ts +0 -8
- package/dist/src/compatibility.test.d.ts +0 -4
- package/dist/src/compatibility.test.js +0 -41
- package/dist/src/core/config.d.ts +0 -11
- package/dist/src/core/config.js +0 -15
- package/dist/src/core/index.d.ts +0 -25
- package/dist/src/core/index.js +0 -26
- package/dist/src/core/payment.d.ts +0 -16
- package/dist/src/core/payment.js +0 -94
- package/dist/src/core/types.d.ts +0 -94
- package/dist/src/core/types.js +0 -4
- package/dist/src/core/verify.d.ts +0 -28
- package/dist/src/core/verify.js +0 -104
- package/dist/src/core/wallet.d.ts +0 -105
- package/dist/src/core/wallet.js +0 -256
- package/dist/src/scripts/baemail/commands.d.ts +0 -35
- package/dist/src/scripts/baemail/commands.js +0 -282
- package/dist/src/scripts/baemail/handler.d.ts +0 -36
- package/dist/src/scripts/baemail/handler.js +0 -284
- package/dist/src/scripts/baemail/index.d.ts +0 -5
- package/dist/src/scripts/baemail/index.js +0 -5
- package/dist/src/scripts/config.d.ts +0 -52
- package/dist/src/scripts/config.js +0 -75
- package/dist/src/scripts/index.d.ts +0 -7
- package/dist/src/scripts/index.js +0 -7
- package/dist/src/scripts/messaging/connect.d.ts +0 -8
- package/dist/src/scripts/messaging/connect.js +0 -168
- package/dist/src/scripts/messaging/handlers.d.ts +0 -21
- package/dist/src/scripts/messaging/handlers.js +0 -334
- package/dist/src/scripts/messaging/inbox.d.ts +0 -11
- package/dist/src/scripts/messaging/inbox.js +0 -51
- package/dist/src/scripts/messaging/index.d.ts +0 -8
- package/dist/src/scripts/messaging/index.js +0 -8
- package/dist/src/scripts/messaging/poll.d.ts +0 -7
- package/dist/src/scripts/messaging/poll.js +0 -52
- package/dist/src/scripts/messaging/send.d.ts +0 -7
- package/dist/src/scripts/messaging/send.js +0 -43
- package/dist/src/scripts/output.d.ts +0 -13
- package/dist/src/scripts/output.js +0 -28
- package/dist/src/scripts/overlay/advertisement.d.ts +0 -16
- package/dist/src/scripts/overlay/advertisement.js +0 -122
- package/dist/src/scripts/overlay/discover.d.ts +0 -7
- package/dist/src/scripts/overlay/discover.js +0 -74
- package/dist/src/scripts/overlay/index.d.ts +0 -7
- package/dist/src/scripts/overlay/index.js +0 -7
- package/dist/src/scripts/overlay/registration.d.ts +0 -19
- package/dist/src/scripts/overlay/registration.js +0 -176
- package/dist/src/scripts/overlay/services.d.ts +0 -29
- package/dist/src/scripts/overlay/services.js +0 -167
- package/dist/src/scripts/overlay/transaction.d.ts +0 -42
- package/dist/src/scripts/overlay/transaction.js +0 -103
- package/dist/src/scripts/payment/build.d.ts +0 -24
- package/dist/src/scripts/payment/build.js +0 -54
- package/dist/src/scripts/payment/commands.d.ts +0 -15
- package/dist/src/scripts/payment/commands.js +0 -73
- package/dist/src/scripts/payment/index.d.ts +0 -6
- package/dist/src/scripts/payment/index.js +0 -6
- package/dist/src/scripts/payment/types.d.ts +0 -56
- package/dist/src/scripts/payment/types.js +0 -4
- package/dist/src/scripts/services/index.d.ts +0 -6
- package/dist/src/scripts/services/index.js +0 -6
- package/dist/src/scripts/services/queue.d.ts +0 -11
- package/dist/src/scripts/services/queue.js +0 -28
- package/dist/src/scripts/services/request.d.ts +0 -7
- package/dist/src/scripts/services/request.js +0 -82
- package/dist/src/scripts/services/respond.d.ts +0 -11
- package/dist/src/scripts/services/respond.js +0 -132
- package/dist/src/scripts/types.d.ts +0 -107
- package/dist/src/scripts/types.js +0 -4
- package/dist/src/scripts/utils/index.d.ts +0 -6
- package/dist/src/scripts/utils/index.js +0 -6
- package/dist/src/scripts/utils/merkle.d.ts +0 -12
- package/dist/src/scripts/utils/merkle.js +0 -47
- package/dist/src/scripts/utils/storage.d.ts +0 -66
- package/dist/src/scripts/utils/storage.js +0 -211
- package/dist/src/scripts/utils/woc.d.ts +0 -26
- package/dist/src/scripts/utils/woc.js +0 -91
- package/dist/src/scripts/wallet/balance.d.ts +0 -22
- package/dist/src/scripts/wallet/balance.js +0 -240
- package/dist/src/scripts/wallet/identity.d.ts +0 -71
- package/dist/src/scripts/wallet/identity.js +0 -152
- package/dist/src/scripts/wallet/index.d.ts +0 -6
- package/dist/src/scripts/wallet/index.js +0 -6
- package/dist/src/scripts/wallet/setup.d.ts +0 -19
- package/dist/src/scripts/wallet/setup.js +0 -119
- package/dist/src/scripts/x-verification/commands.d.ts +0 -27
- package/dist/src/scripts/x-verification/commands.js +0 -222
- package/dist/src/scripts/x-verification/index.d.ts +0 -4
- package/dist/src/scripts/x-verification/index.js +0 -4
- package/dist/src/services/built-in/api-proxy/index.d.ts +0 -6
- package/dist/src/services/built-in/api-proxy/index.js +0 -23
- package/dist/src/services/built-in/code-develop/index.d.ts +0 -6
- package/dist/src/services/built-in/code-develop/index.js +0 -23
- package/dist/src/services/built-in/code-review/index.d.ts +0 -10
- package/dist/src/services/built-in/code-review/index.js +0 -51
- package/dist/src/services/built-in/image-analysis/index.d.ts +0 -6
- package/dist/src/services/built-in/image-analysis/index.js +0 -33
- package/dist/src/services/built-in/memory-store/index.d.ts +0 -6
- package/dist/src/services/built-in/memory-store/index.js +0 -22
- package/dist/src/services/built-in/roulette/index.d.ts +0 -6
- package/dist/src/services/built-in/roulette/index.js +0 -27
- package/dist/src/services/built-in/summarize/index.d.ts +0 -6
- package/dist/src/services/built-in/summarize/index.js +0 -21
- package/dist/src/services/built-in/tell-joke/handler.d.ts +0 -7
- package/dist/src/services/built-in/tell-joke/handler.js +0 -122
- package/dist/src/services/built-in/tell-joke/index.d.ts +0 -9
- package/dist/src/services/built-in/tell-joke/index.js +0 -31
- package/dist/src/services/built-in/translate/index.d.ts +0 -6
- package/dist/src/services/built-in/translate/index.js +0 -21
- package/dist/src/services/built-in/web-research/index.d.ts +0 -9
- package/dist/src/services/built-in/web-research/index.js +0 -51
- package/dist/src/services/index.d.ts +0 -13
- package/dist/src/services/index.js +0 -14
- package/dist/src/services/loader.d.ts +0 -77
- package/dist/src/services/loader.js +0 -292
- package/dist/src/services/manager.d.ts +0 -86
- package/dist/src/services/manager.js +0 -255
- package/dist/src/services/registry.d.ts +0 -98
- package/dist/src/services/registry.js +0 -204
- package/dist/src/services/types.d.ts +0 -230
- package/dist/src/services/types.js +0 -30
- package/dist/src/test/cli.test.d.ts +0 -7
- package/dist/src/test/cli.test.js +0 -330
- package/dist/src/test/comprehensive-overlay.test.d.ts +0 -13
- package/dist/src/test/comprehensive-overlay.test.js +0 -593
- package/dist/src/test/identity-consistency.test.d.ts +0 -6
- package/dist/src/test/identity-consistency.test.js +0 -60
- package/dist/src/test/key-derivation.test.d.ts +0 -12
- package/dist/src/test/key-derivation.test.js +0 -86
- package/dist/src/test/network-address.test.d.ts +0 -9
- package/dist/src/test/network-address.test.js +0 -37
- package/dist/src/test/overlay-submit.test.d.ts +0 -10
- package/dist/src/test/overlay-submit.test.js +0 -460
- package/dist/src/test/request-response-flow.test.d.ts +0 -5
- package/dist/src/test/request-response-flow.test.js +0 -210
- package/dist/src/test/service-system.test.d.ts +0 -5
- package/dist/src/test/service-system.test.js +0 -190
- package/dist/src/test/taskflow.test.d.ts +0 -7
- package/dist/src/test/taskflow.test.js +0 -82
- package/dist/src/test/utils/server-logic.d.ts +0 -98
- package/dist/src/test/utils/server-logic.js +0 -286
- package/dist/src/test/wallet.test.d.ts +0 -7
- package/dist/src/test/wallet.test.js +0 -146
- package/src/core/README.md +0 -246
- package/src/core/config.d.ts +0 -12
- package/src/core/config.d.ts.map +0 -1
- package/src/core/config.js +0 -14
- package/src/core/config.js.map +0 -1
- package/src/core/config.ts +0 -22
- package/src/core/index.ts +0 -42
- package/src/core/payment.d.ts +0 -17
- package/src/core/payment.d.ts.map +0 -1
- package/src/core/payment.js +0 -95
- package/src/core/payment.js.map +0 -1
- package/src/core/payment.ts +0 -111
- package/src/core/types.d.ts +0 -95
- package/src/core/types.d.ts.map +0 -1
- package/src/core/types.js +0 -5
- package/src/core/types.js.map +0 -1
- package/src/core/types.ts +0 -102
- package/src/core/verify.d.ts +0 -29
- package/src/core/verify.d.ts.map +0 -1
- package/src/core/verify.js +0 -105
- package/src/core/verify.js.map +0 -1
- package/src/core/verify.ts +0 -119
- package/src/core/wallet.d.ts +0 -100
- package/src/core/wallet.d.ts.map +0 -1
- package/src/core/wallet.js.map +0 -1
- package/src/core/wallet.ts +0 -323
|
@@ -1,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,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
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WhatsOnChain API helpers with retry logic and rate limiting.
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Fetch from WhatsonChain with optional API key auth and retry logic.
|
|
6
|
-
* Retries on 429 (rate limit) and 5xx errors with exponential backoff.
|
|
7
|
-
* Includes timeout to prevent hanging indefinitely.
|
|
8
|
-
*/
|
|
9
|
-
export declare function wocFetch(urlPath: string, options?: RequestInit, maxRetries?: number, timeoutMs?: number): Promise<Response>;
|
|
10
|
-
/**
|
|
11
|
-
* Fetch with timeout using AbortController.
|
|
12
|
-
*/
|
|
13
|
-
export declare function fetchWithTimeout(url: string, options?: RequestInit, timeoutMs?: number): Promise<Response>;
|
|
14
|
-
/**
|
|
15
|
-
* Fetch a pre-built BEEF from WhatsonChain for a given txid.
|
|
16
|
-
* WoC returns raw binary BEEF that includes the full source chain and merkle proofs.
|
|
17
|
-
*/
|
|
18
|
-
export declare function fetchBeefFromWoC(txid: string): Promise<Uint8Array | null>;
|
|
19
|
-
/**
|
|
20
|
-
* Get the WoC base URL for the current network.
|
|
21
|
-
*/
|
|
22
|
-
export declare function getWocBaseUrl(): string;
|
|
23
|
-
/**
|
|
24
|
-
* Get the explorer base URL for the current network.
|
|
25
|
-
*/
|
|
26
|
-
export declare function getExplorerBaseUrl(): string;
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WhatsOnChain API helpers with retry logic and rate limiting.
|
|
3
|
-
*/
|
|
4
|
-
import { NETWORK, WOC_API_KEY } from '../config.js';
|
|
5
|
-
/**
|
|
6
|
-
* Fetch from WhatsonChain with optional API key auth and retry logic.
|
|
7
|
-
* Retries on 429 (rate limit) and 5xx errors with exponential backoff.
|
|
8
|
-
* Includes timeout to prevent hanging indefinitely.
|
|
9
|
-
*/
|
|
10
|
-
export async function wocFetch(urlPath, options = {}, maxRetries = 3, timeoutMs = 30000) {
|
|
11
|
-
const wocNet = NETWORK === 'mainnet' ? 'main' : 'test';
|
|
12
|
-
const base = `https://api.whatsonchain.com/v1/bsv/${wocNet}`;
|
|
13
|
-
const url = urlPath.startsWith('http') ? urlPath : `${base}${urlPath}`;
|
|
14
|
-
const headers = { ...(options.headers || {}) };
|
|
15
|
-
if (WOC_API_KEY) {
|
|
16
|
-
headers['Authorization'] = `Bearer ${WOC_API_KEY}`;
|
|
17
|
-
}
|
|
18
|
-
let lastError;
|
|
19
|
-
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
20
|
-
try {
|
|
21
|
-
const controller = new AbortController();
|
|
22
|
-
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
23
|
-
const resp = await fetch(url, { ...options, headers, signal: controller.signal });
|
|
24
|
-
clearTimeout(timeout);
|
|
25
|
-
// Retry on 429 (rate limit) or 5xx (server error)
|
|
26
|
-
if ((resp.status === 429 || resp.status >= 500) && attempt < maxRetries) {
|
|
27
|
-
const delayMs = Math.min(1000 * Math.pow(2, attempt), 8000);
|
|
28
|
-
await new Promise(r => setTimeout(r, delayMs));
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
return resp;
|
|
32
|
-
}
|
|
33
|
-
catch (err) {
|
|
34
|
-
lastError = err;
|
|
35
|
-
if (attempt < maxRetries) {
|
|
36
|
-
const delayMs = Math.min(1000 * Math.pow(2, attempt), 8000);
|
|
37
|
-
await new Promise(r => setTimeout(r, delayMs));
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
throw lastError || new Error('WoC fetch failed after retries');
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Fetch with timeout using AbortController.
|
|
46
|
-
*/
|
|
47
|
-
export async function fetchWithTimeout(url, options = {}, timeoutMs = 15000) {
|
|
48
|
-
const controller = new AbortController();
|
|
49
|
-
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
50
|
-
try {
|
|
51
|
-
const resp = await fetch(url, { ...options, signal: controller.signal });
|
|
52
|
-
return resp;
|
|
53
|
-
}
|
|
54
|
-
finally {
|
|
55
|
-
clearTimeout(timeout);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Fetch a pre-built BEEF from WhatsonChain for a given txid.
|
|
60
|
-
* WoC returns raw binary BEEF that includes the full source chain and merkle proofs.
|
|
61
|
-
*/
|
|
62
|
-
export async function fetchBeefFromWoC(txid) {
|
|
63
|
-
try {
|
|
64
|
-
const resp = await wocFetch(`/tx/${txid}/beef`);
|
|
65
|
-
if (!resp.ok)
|
|
66
|
-
return null;
|
|
67
|
-
const hexStr = (await resp.text()).trim();
|
|
68
|
-
if (!hexStr || hexStr.length < 8)
|
|
69
|
-
return null;
|
|
70
|
-
const bytes = hexStr.match(/.{2}/g).map(h => parseInt(h, 16));
|
|
71
|
-
return new Uint8Array(bytes);
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Get the WoC base URL for the current network.
|
|
79
|
-
*/
|
|
80
|
-
export function getWocBaseUrl() {
|
|
81
|
-
const wocNet = NETWORK === 'mainnet' ? 'main' : 'test';
|
|
82
|
-
return `https://api.whatsonchain.com/v1/bsv/${wocNet}`;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Get the explorer base URL for the current network.
|
|
86
|
-
*/
|
|
87
|
-
export function getExplorerBaseUrl() {
|
|
88
|
-
return NETWORK === 'mainnet'
|
|
89
|
-
? 'https://whatsonchain.com'
|
|
90
|
-
: 'https://test.whatsonchain.com';
|
|
91
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Wallet balance commands: balance, import, refund.
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Balance command: show wallet balance.
|
|
6
|
-
*/
|
|
7
|
-
export declare function cmdBalance(): Promise<any>;
|
|
8
|
-
/**
|
|
9
|
-
* Import command: import external UTXO with merkle proof.
|
|
10
|
-
*
|
|
11
|
-
* This function handles both confirmed and unconfirmed transactions.
|
|
12
|
-
* For unconfirmed transactions, it uses BEEF from WoC which includes
|
|
13
|
-
* the source chain back to confirmed ancestors (SPV-compliant).
|
|
14
|
-
*
|
|
15
|
-
* If the transaction isn't yet on WoC (just broadcast), it will poll
|
|
16
|
-
* with exponential backoff for up to 60 seconds.
|
|
17
|
-
*/
|
|
18
|
-
export declare function cmdImport(txidArg: string | undefined, voutStr?: string): Promise<any>;
|
|
19
|
-
/**
|
|
20
|
-
* Refund command: sweep wallet to an address.
|
|
21
|
-
*/
|
|
22
|
-
export declare function cmdRefund(targetAddress: string | undefined): Promise<void>;
|