openclaw-overlay-plugin 0.7.50 → 0.7.52
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 +26 -45
- package/index.ts +29 -48
- package/package.json +1 -5
- package/HOOK.md +0 -9
- package/src/core/wallet.js +0 -225
package/dist/index.js
CHANGED
|
@@ -579,6 +579,32 @@ export default function register(api) {
|
|
|
579
579
|
startBackgroundService(env, cliPath, api.logger);
|
|
580
580
|
// Start auto-import
|
|
581
581
|
startAutoImport(env, cliPath, api.logger);
|
|
582
|
+
// Auto-check for registration on startup
|
|
583
|
+
(async () => {
|
|
584
|
+
try {
|
|
585
|
+
const regPath = path.join(process.env.HOME || '', '.openclaw', 'openclaw-overlay', 'registration.json');
|
|
586
|
+
const onboardSentFile = path.join(process.env.HOME || '', '.openclaw', 'openclaw-overlay', 'onboarding-sent.flag');
|
|
587
|
+
if (!fs.existsSync(regPath) && !fs.existsSync(onboardSentFile)) {
|
|
588
|
+
const walletPath = path.join(pluginConfig.walletDir || path.join(os.homedir(), '.openclaw', 'bsv-wallet'), 'wallet-identity.json');
|
|
589
|
+
if (fs.existsSync(walletPath)) {
|
|
590
|
+
// Wallet exists but not registered.
|
|
591
|
+
const balResult = await execFileAsync('node', [cliPath, 'balance'], { env });
|
|
592
|
+
const balance = parseCliOutput(balResult.stdout);
|
|
593
|
+
if ((balance.data?.walletBalance || 0) >= 1000) {
|
|
594
|
+
// Funded but not registered. Auto-register.
|
|
595
|
+
const regResult = await execFileAsync('node', [cliPath, 'register'], { env, timeout: 60000 });
|
|
596
|
+
if (parseCliOutput(regResult.stdout).success) {
|
|
597
|
+
api.logger.info('[openclaw-overlay] Agent auto-registered on startup');
|
|
598
|
+
await autoAdvertiseServices(env, cliPath, api.logger);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
catch (err) {
|
|
605
|
+
api.logger.debug(`[openclaw-overlay] Auto-setup/onboarding skipped: ${err.message}`);
|
|
606
|
+
}
|
|
607
|
+
})();
|
|
582
608
|
api.logger.info("BSV overlay WebSocket relay started");
|
|
583
609
|
}
|
|
584
610
|
catch (error) {
|
|
@@ -590,51 +616,6 @@ export default function register(api) {
|
|
|
590
616
|
stopBackgroundService();
|
|
591
617
|
}
|
|
592
618
|
});
|
|
593
|
-
// Register a skill-style wake handler
|
|
594
|
-
api.registerHook({
|
|
595
|
-
id: "openclaw-overlay-wake",
|
|
596
|
-
event: "gateway:start",
|
|
597
|
-
handler: async (ctx) => {
|
|
598
|
-
// Auto-check for registration on startup
|
|
599
|
-
(async () => {
|
|
600
|
-
try {
|
|
601
|
-
const env = buildEnvironment(pluginConfig);
|
|
602
|
-
const cliPath = getCliPath();
|
|
603
|
-
const regPath = path.join(process.env.HOME || '', '.openclaw', 'openclaw-overlay', 'registration.json');
|
|
604
|
-
const onboardSentFile = path.join(process.env.HOME || '', '.openclaw', 'openclaw-overlay', 'onboarding-sent.flag');
|
|
605
|
-
if (!fs.existsSync(regPath) && !fs.existsSync(onboardSentFile)) {
|
|
606
|
-
// Check if wallet exists
|
|
607
|
-
const walletPath = path.join(pluginConfig.walletDir || path.join(os.homedir(), '.openclaw', 'bsv-wallet'), 'wallet-identity.json');
|
|
608
|
-
if (!fs.existsSync(walletPath)) {
|
|
609
|
-
// No wallet, no registration — first run ever.
|
|
610
|
-
// We'll let startAutoImport create the wallet via 'address' command,
|
|
611
|
-
// then it will wake the agent when funded.
|
|
612
|
-
}
|
|
613
|
-
else {
|
|
614
|
-
// Wallet exists but not registered.
|
|
615
|
-
const balResult = await execFileAsync('node', [cliPath, 'balance'], { env });
|
|
616
|
-
const balance = parseCliOutput(balResult.stdout);
|
|
617
|
-
if ((balance.data?.walletBalance || 0) < 1000) {
|
|
618
|
-
// Funded less than 1000, need more funds to register.
|
|
619
|
-
// We don't wake up here, we wait for auto-import to detect new funds.
|
|
620
|
-
}
|
|
621
|
-
else {
|
|
622
|
-
// Funded but not registered. Auto-register.
|
|
623
|
-
const regResult = await execFileAsync('node', [cliPath, 'register'], { env, timeout: 60000 });
|
|
624
|
-
if (parseCliOutput(regResult.stdout).success) {
|
|
625
|
-
ctx.logger.info('[openclaw-overlay] Agent auto-registered on startup');
|
|
626
|
-
await autoAdvertiseServices(env, cliPath, ctx.logger);
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
catch (err) {
|
|
633
|
-
api.log?.debug?.('[openclaw-overlay] Auto-setup/onboarding skipped:', err.message);
|
|
634
|
-
}
|
|
635
|
-
})();
|
|
636
|
-
}
|
|
637
|
-
});
|
|
638
619
|
// Register CLI extensions
|
|
639
620
|
api.registerCli(({ program }) => {
|
|
640
621
|
const overlay = program.command("overlay").description("BSV Overlay Network management");
|
package/index.ts
CHANGED
|
@@ -629,6 +629,35 @@ export default function register(api: any) {
|
|
|
629
629
|
// Start auto-import
|
|
630
630
|
startAutoImport(env, cliPath, api.logger);
|
|
631
631
|
|
|
632
|
+
// Auto-check for registration on startup
|
|
633
|
+
(async () => {
|
|
634
|
+
try {
|
|
635
|
+
const regPath = path.join(process.env.HOME || '', '.openclaw', 'openclaw-overlay', 'registration.json');
|
|
636
|
+
const onboardSentFile = path.join(process.env.HOME || '', '.openclaw', 'openclaw-overlay', 'onboarding-sent.flag');
|
|
637
|
+
|
|
638
|
+
if (!fs.existsSync(regPath) && !fs.existsSync(onboardSentFile)) {
|
|
639
|
+
const walletPath = path.join(pluginConfig.walletDir || path.join(os.homedir(), '.openclaw', 'bsv-wallet'), 'wallet-identity.json');
|
|
640
|
+
|
|
641
|
+
if (fs.existsSync(walletPath)) {
|
|
642
|
+
// Wallet exists but not registered.
|
|
643
|
+
const balResult = await execFileAsync('node', [cliPath, 'balance'], { env });
|
|
644
|
+
const balance = parseCliOutput(balResult.stdout);
|
|
645
|
+
|
|
646
|
+
if ((balance.data?.walletBalance || 0) >= 1000) {
|
|
647
|
+
// Funded but not registered. Auto-register.
|
|
648
|
+
const regResult = await execFileAsync('node', [cliPath, 'register'], { env, timeout: 60000 });
|
|
649
|
+
if (parseCliOutput(regResult.stdout).success) {
|
|
650
|
+
api.logger.info('[openclaw-overlay] Agent auto-registered on startup');
|
|
651
|
+
await autoAdvertiseServices(env, cliPath, api.logger);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
} catch (err: any) {
|
|
657
|
+
api.logger.debug(`[openclaw-overlay] Auto-setup/onboarding skipped: ${err.message}`);
|
|
658
|
+
}
|
|
659
|
+
})();
|
|
660
|
+
|
|
632
661
|
api.logger.info("BSV overlay WebSocket relay started");
|
|
633
662
|
} catch (error: any) {
|
|
634
663
|
api.logger.error(`Failed to start BSV overlay relay: ${error.message}`);
|
|
@@ -640,54 +669,6 @@ export default function register(api: any) {
|
|
|
640
669
|
}
|
|
641
670
|
});
|
|
642
671
|
|
|
643
|
-
// Register a skill-style wake handler
|
|
644
|
-
api.registerHook({
|
|
645
|
-
id: "openclaw-overlay-wake",
|
|
646
|
-
event: "gateway:start",
|
|
647
|
-
handler: async (ctx: any) => {
|
|
648
|
-
// Auto-check for registration on startup
|
|
649
|
-
(async () => {
|
|
650
|
-
try {
|
|
651
|
-
const env = buildEnvironment(pluginConfig);
|
|
652
|
-
const cliPath = getCliPath();
|
|
653
|
-
|
|
654
|
-
const regPath = path.join(process.env.HOME || '', '.openclaw', 'openclaw-overlay', 'registration.json');
|
|
655
|
-
const onboardSentFile = path.join(process.env.HOME || '', '.openclaw', 'openclaw-overlay', 'onboarding-sent.flag');
|
|
656
|
-
|
|
657
|
-
if (!fs.existsSync(regPath) && !fs.existsSync(onboardSentFile)) {
|
|
658
|
-
// Check if wallet exists
|
|
659
|
-
const walletPath = path.join(pluginConfig.walletDir || path.join(os.homedir(), '.openclaw', 'bsv-wallet'), 'wallet-identity.json');
|
|
660
|
-
|
|
661
|
-
if (!fs.existsSync(walletPath)) {
|
|
662
|
-
// No wallet, no registration — first run ever.
|
|
663
|
-
// We'll let startAutoImport create the wallet via 'address' command,
|
|
664
|
-
// then it will wake the agent when funded.
|
|
665
|
-
} else {
|
|
666
|
-
// Wallet exists but not registered.
|
|
667
|
-
const balResult = await execFileAsync('node', [cliPath, 'balance'], { env });
|
|
668
|
-
const balance = parseCliOutput(balResult.stdout);
|
|
669
|
-
|
|
670
|
-
if ((balance.data?.walletBalance || 0) < 1000) {
|
|
671
|
-
// Funded less than 1000, need more funds to register.
|
|
672
|
-
// We don't wake up here, we wait for auto-import to detect new funds.
|
|
673
|
-
} else {
|
|
674
|
-
// Funded but not registered. Auto-register.
|
|
675
|
-
const regResult = await execFileAsync('node', [cliPath, 'register'], { env, timeout: 60000 });
|
|
676
|
-
if (parseCliOutput(regResult.stdout).success) {
|
|
677
|
-
ctx.logger.info('[openclaw-overlay] Agent auto-registered on startup');
|
|
678
|
-
await autoAdvertiseServices(env, cliPath, ctx.logger);
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
} catch (err: any) {
|
|
685
|
-
api.log?.debug?.('[openclaw-overlay] Auto-setup/onboarding skipped:', err.message);
|
|
686
|
-
}
|
|
687
|
-
})();
|
|
688
|
-
}
|
|
689
|
-
});
|
|
690
|
-
|
|
691
672
|
// Register CLI extensions
|
|
692
673
|
api.registerCli(({ program }: any) => {
|
|
693
674
|
const overlay = program.command("overlay").description("BSV Overlay Network management");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openclaw-overlay-plugin",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.52",
|
|
4
4
|
"description": "Openclaw BSV Overlay — agent discovery, service marketplace, and micropayments on the BSV blockchain",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
"src/",
|
|
13
13
|
"dist/",
|
|
14
14
|
"SKILL.md",
|
|
15
|
-
"HOOK.md",
|
|
16
15
|
"README.md"
|
|
17
16
|
],
|
|
18
17
|
"bin": {
|
|
@@ -70,9 +69,6 @@
|
|
|
70
69
|
"extensions": [
|
|
71
70
|
"./dist/index.js"
|
|
72
71
|
],
|
|
73
|
-
"hooks": [
|
|
74
|
-
"./dist/index.js"
|
|
75
|
-
],
|
|
76
72
|
"compat": {
|
|
77
73
|
"pluginApi": "1",
|
|
78
74
|
"minGatewayVersion": "2026.3.1"
|
package/HOOK.md
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: openclaw-overlay-hooks
|
|
3
|
-
description: Background automation for the OpenClaw Overlay Network.
|
|
4
|
-
metadata: '{"openclaw": {"events": ["gateway:start"]}}'
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Overlay Hooks
|
|
8
|
-
This file ensures compatibility with the OpenClaw hook pack installer.
|
|
9
|
-
Background tasks are handled programmatically in index.ts.
|
package/src/core/wallet.js
DELETED
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @a2a-bsv/core — BSVAgentWallet
|
|
3
|
-
*
|
|
4
|
-
* High-level wallet class for AI agent-to-agent BSV payments.
|
|
5
|
-
* Wraps @bsv/wallet-toolbox's Wallet + StorageKnex with a clean,
|
|
6
|
-
* minimal API surface designed for automated agent use.
|
|
7
|
-
*/
|
|
8
|
-
import { PrivateKey, CachedKeyDeriver } from '@bsv/sdk';
|
|
9
|
-
import { Wallet, WalletStorageManager, Services, Monitor, StorageKnex, randomBytesHex, ChaintracksServiceClient, } from '@bsv/wallet-toolbox';
|
|
10
|
-
import knexLib from 'knex';
|
|
11
|
-
import * as path from 'node:path';
|
|
12
|
-
import * as fs from 'node:fs';
|
|
13
|
-
import { toChain, DEFAULT_TAAL_API_KEYS, DEFAULT_DB_NAME } from './config.js';
|
|
14
|
-
import { buildPayment } from './payment.js';
|
|
15
|
-
import { verifyPayment, acceptPayment } from './verify.js';
|
|
16
|
-
/** Filename for the persisted wallet identity JSON. */
|
|
17
|
-
const IDENTITY_FILE = 'wallet-identity.json';
|
|
18
|
-
/**
|
|
19
|
-
* BSVAgentWallet — the primary class for agent-to-agent BSV payments.
|
|
20
|
-
*
|
|
21
|
-
* Usage:
|
|
22
|
-
* ```ts
|
|
23
|
-
* // Create a new wallet (generates keys)
|
|
24
|
-
* const wallet = await BSVAgentWallet.load({ network: 'testnet', storageDir: './agent-wallet' });
|
|
25
|
-
*
|
|
26
|
-
* // Load an existing wallet
|
|
27
|
-
* const wallet = await BSVAgentWallet.load({ network: 'testnet', storageDir: './agent-wallet' });
|
|
28
|
-
*
|
|
29
|
-
* // Make a payment
|
|
30
|
-
* const payment = await wallet.createPayment({ to: recipientPubKey, satoshis: 500 });
|
|
31
|
-
*
|
|
32
|
-
* // Verify and accept a payment
|
|
33
|
-
* const verification = wallet.verifyPayment({ beef: payment.beef });
|
|
34
|
-
* if (verification.valid) {
|
|
35
|
-
* await wallet.acceptPayment({ beef: payment.beef, ...derivationInfo });
|
|
36
|
-
* }
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export class BSVAgentWallet {
|
|
40
|
-
/** @internal — exposed for advanced operations (e.g. direct internalizeAction) */
|
|
41
|
-
_setup;
|
|
42
|
-
constructor(setup) {
|
|
43
|
-
this._setup = setup;
|
|
44
|
-
}
|
|
45
|
-
// ---------------------------------------------------------------------------
|
|
46
|
-
// Factory methods
|
|
47
|
-
// ---------------------------------------------------------------------------
|
|
48
|
-
/**
|
|
49
|
-
* Create a new agent wallet. Generates a fresh root key and persists it.
|
|
50
|
-
* The SQLite database and identity file are written to `config.storageDir`.
|
|
51
|
-
*/
|
|
52
|
-
static async create(config) {
|
|
53
|
-
// Generate a new root key (or use one provided in config)
|
|
54
|
-
const rootKeyHex = config.rootKeyHex ?? PrivateKey.fromRandom().toHex();
|
|
55
|
-
const rootKey = PrivateKey.fromHex(rootKeyHex);
|
|
56
|
-
const identityKey = rootKey.toPublicKey().toString();
|
|
57
|
-
// Ensure the storage directory exists
|
|
58
|
-
fs.mkdirSync(config.storageDir, { recursive: true });
|
|
59
|
-
// Persist identity for later loading
|
|
60
|
-
const identity = {
|
|
61
|
-
rootKeyHex,
|
|
62
|
-
identityKey,
|
|
63
|
-
network: config.network,
|
|
64
|
-
};
|
|
65
|
-
const identityPath = path.join(config.storageDir, IDENTITY_FILE);
|
|
66
|
-
fs.writeFileSync(identityPath, JSON.stringify(identity, null, 2), 'utf-8');
|
|
67
|
-
// Build the wallet
|
|
68
|
-
const setup = await BSVAgentWallet.buildSetup(config, rootKeyHex);
|
|
69
|
-
return new BSVAgentWallet(setup);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Load an existing agent wallet from its storage directory.
|
|
73
|
-
* Reads the persisted identity file and re-initializes the wallet.
|
|
74
|
-
*/
|
|
75
|
-
static async load(config) {
|
|
76
|
-
const identityPath = path.join(config.storageDir, IDENTITY_FILE);
|
|
77
|
-
if (!fs.existsSync(identityPath)) {
|
|
78
|
-
return this.create(config);
|
|
79
|
-
}
|
|
80
|
-
const identity = JSON.parse(fs.readFileSync(identityPath, 'utf-8'));
|
|
81
|
-
const rootKeyHex = config.rootKeyHex ?? identity.rootKeyHex;
|
|
82
|
-
const setup = await BSVAgentWallet.buildSetup(config, rootKeyHex);
|
|
83
|
-
return new BSVAgentWallet(setup);
|
|
84
|
-
}
|
|
85
|
-
// ---------------------------------------------------------------------------
|
|
86
|
-
// Wallet lifecycle
|
|
87
|
-
// ---------------------------------------------------------------------------
|
|
88
|
-
/**
|
|
89
|
-
* Get this wallet's public identity key (compressed hex, 33 bytes).
|
|
90
|
-
* This is the key other agents use to send payments to you.
|
|
91
|
-
*/
|
|
92
|
-
async getIdentityKey() {
|
|
93
|
-
return this._setup.identityKey;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Get the wallet's current balance in satoshis.
|
|
97
|
-
*
|
|
98
|
-
* Uses the BRC-100 wallet's balance method which sums spendable outputs
|
|
99
|
-
* in the default basket.
|
|
100
|
-
*/
|
|
101
|
-
async getBalance() {
|
|
102
|
-
return await this._setup.wallet.balance();
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Cleanly shut down the wallet, releasing database connections and
|
|
106
|
-
* stopping the background monitor.
|
|
107
|
-
*/
|
|
108
|
-
async destroy() {
|
|
109
|
-
await this._setup.wallet.destroy();
|
|
110
|
-
}
|
|
111
|
-
// ---------------------------------------------------------------------------
|
|
112
|
-
// Payment creation (sender/payer side)
|
|
113
|
-
// ---------------------------------------------------------------------------
|
|
114
|
-
/**
|
|
115
|
-
* Build a BRC-29 payment to another agent.
|
|
116
|
-
*
|
|
117
|
-
* The transaction is created with `noSend: true` — the sender does NOT
|
|
118
|
-
* broadcast it. Instead, the Atomic BEEF and derivation metadata are
|
|
119
|
-
* returned so they can be transmitted to the recipient, who will
|
|
120
|
-
* verify and internalize (broadcast) the payment.
|
|
121
|
-
*
|
|
122
|
-
* @param params.to — Recipient's compressed public key (hex).
|
|
123
|
-
* @param params.satoshis — Amount in satoshis.
|
|
124
|
-
* @param params.description — Optional human-readable note.
|
|
125
|
-
*/
|
|
126
|
-
async createPayment(params) {
|
|
127
|
-
return buildPayment(this._setup, params);
|
|
128
|
-
}
|
|
129
|
-
// ---------------------------------------------------------------------------
|
|
130
|
-
// Payment verification & acceptance (receiver/merchant side)
|
|
131
|
-
// ---------------------------------------------------------------------------
|
|
132
|
-
/**
|
|
133
|
-
* Verify an incoming Atomic BEEF payment.
|
|
134
|
-
*
|
|
135
|
-
* This performs structural validation and SPV verification via tx.verify().
|
|
136
|
-
*/
|
|
137
|
-
async verifyPayment(params) {
|
|
138
|
-
return await verifyPayment(params);
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Accept (internalize) a verified payment into this wallet.
|
|
142
|
-
*
|
|
143
|
-
* Uses the BRC-29 wallet payment protocol to derive the correct key
|
|
144
|
-
* and claim the output. This triggers SPV verification and, if the
|
|
145
|
-
* transaction hasn't been broadcast yet, broadcasts it.
|
|
146
|
-
*/
|
|
147
|
-
async acceptPayment(params) {
|
|
148
|
-
return acceptPayment(this._setup, params);
|
|
149
|
-
}
|
|
150
|
-
// ---------------------------------------------------------------------------
|
|
151
|
-
// Access to underlying toolbox objects (for advanced use)
|
|
152
|
-
// ---------------------------------------------------------------------------
|
|
153
|
-
/** Get the underlying wallet-toolbox SetupWallet for advanced operations. */
|
|
154
|
-
getSetup() {
|
|
155
|
-
return this._setup;
|
|
156
|
-
}
|
|
157
|
-
// ---------------------------------------------------------------------------
|
|
158
|
-
// Private helpers
|
|
159
|
-
// ---------------------------------------------------------------------------
|
|
160
|
-
/**
|
|
161
|
-
* Internal: manually construct a BRC-100 wallet backed by SQLite.
|
|
162
|
-
*
|
|
163
|
-
* We build this by hand instead of using Setup.createWalletSQLite because
|
|
164
|
-
* the toolbox has a bug where its internal randomBytesHex is a stub.
|
|
165
|
-
* We use the same components but wire them up correctly.
|
|
166
|
-
*/
|
|
167
|
-
static async buildSetup(config, rootKeyHex) {
|
|
168
|
-
const chain = toChain(config.network);
|
|
169
|
-
const taalApiKey = config.taalApiKey ?? DEFAULT_TAAL_API_KEYS[chain];
|
|
170
|
-
const rootKey = PrivateKey.fromHex(rootKeyHex);
|
|
171
|
-
const identityKey = rootKey.toPublicKey().toString();
|
|
172
|
-
// 1. Key derivation
|
|
173
|
-
const keyDeriver = new CachedKeyDeriver(rootKey);
|
|
174
|
-
// 2. Storage manager (empty initially)
|
|
175
|
-
const storage = new WalletStorageManager(identityKey);
|
|
176
|
-
// 3. Network services (ARC broadcasting, chain tracking, etc.)
|
|
177
|
-
const serviceOptions = Services.createDefaultOptions(chain);
|
|
178
|
-
const chaintracksUrl = process.env.BSV_CHAINTRACKS_URL || 'https://chaintracks-us-1.bsvb.tech';
|
|
179
|
-
const arcUrl = process.env.BSV_ARC_URL;
|
|
180
|
-
serviceOptions.chaintracks = new ChaintracksServiceClient(chain, chaintracksUrl);
|
|
181
|
-
if (arcUrl) {
|
|
182
|
-
serviceOptions.arcUrl = arcUrl;
|
|
183
|
-
}
|
|
184
|
-
serviceOptions.taalApiKey = taalApiKey;
|
|
185
|
-
const services = new Services(serviceOptions);
|
|
186
|
-
// 4. Background monitor
|
|
187
|
-
const monopts = Monitor.createDefaultWalletMonitorOptions(chain, storage, services);
|
|
188
|
-
const monitor = new Monitor(monopts);
|
|
189
|
-
monitor.addDefaultTasks();
|
|
190
|
-
// 5. The BRC-100 Wallet
|
|
191
|
-
const wallet = new Wallet({ chain, keyDeriver, storage, services, monitor });
|
|
192
|
-
// 6. SQLite storage via knex
|
|
193
|
-
const filePath = path.join(config.storageDir, `${DEFAULT_DB_NAME}.sqlite`);
|
|
194
|
-
const knex = knexLib({
|
|
195
|
-
client: 'sqlite3',
|
|
196
|
-
connection: { filename: filePath },
|
|
197
|
-
useNullAsDefault: true,
|
|
198
|
-
});
|
|
199
|
-
// Fee model: configurable via BSV_FEE_MODEL env var (default: 100 sat/KB)
|
|
200
|
-
const feeModelValue = config.feeModel ??
|
|
201
|
-
(process.env.BSV_FEE_MODEL ? parseInt(process.env.BSV_FEE_MODEL, 10) : 100);
|
|
202
|
-
const activeStorage = new StorageKnex({
|
|
203
|
-
chain,
|
|
204
|
-
knex,
|
|
205
|
-
commissionSatoshis: 0,
|
|
206
|
-
commissionPubKeyHex: undefined,
|
|
207
|
-
feeModel: { model: 'sat/kb', value: feeModelValue },
|
|
208
|
-
});
|
|
209
|
-
await activeStorage.migrate(DEFAULT_DB_NAME, randomBytesHex(33));
|
|
210
|
-
await activeStorage.makeAvailable();
|
|
211
|
-
await storage.addWalletStorageProvider(activeStorage);
|
|
212
|
-
await activeStorage.findOrInsertUser(identityKey);
|
|
213
|
-
return {
|
|
214
|
-
rootKey,
|
|
215
|
-
identityKey,
|
|
216
|
-
keyDeriver,
|
|
217
|
-
chain,
|
|
218
|
-
storage,
|
|
219
|
-
services,
|
|
220
|
-
monitor,
|
|
221
|
-
wallet,
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
//# sourceMappingURL=wallet.js.map
|