openclaw-simplesv-plugin 0.1.4 → 0.1.6

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 (53) hide show
  1. package/README.md +50 -10
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +61 -12
  5. package/dist/index.js.map +1 -1
  6. package/dist/src/actions.d.ts +19 -0
  7. package/dist/src/actions.d.ts.map +1 -0
  8. package/dist/src/actions.js +46 -0
  9. package/dist/src/actions.js.map +1 -0
  10. package/dist/src/core/config.d.ts +12 -0
  11. package/dist/src/core/config.d.ts.map +1 -0
  12. package/dist/src/core/config.js +14 -0
  13. package/dist/src/core/config.js.map +1 -0
  14. package/dist/src/core/index.d.ts +26 -0
  15. package/dist/src/core/index.d.ts.map +1 -0
  16. package/dist/src/core/index.js +27 -0
  17. package/dist/src/core/index.js.map +1 -0
  18. package/dist/src/core/payment.d.ts +17 -0
  19. package/dist/src/core/payment.d.ts.map +1 -0
  20. package/dist/src/core/payment.js +95 -0
  21. package/dist/src/core/payment.js.map +1 -0
  22. package/dist/src/core/types.d.ts +95 -0
  23. package/dist/src/core/types.d.ts.map +1 -0
  24. package/dist/src/core/types.js +5 -0
  25. package/dist/src/core/types.js.map +1 -0
  26. package/dist/src/core/verify.d.ts +29 -0
  27. package/dist/src/core/verify.d.ts.map +1 -0
  28. package/dist/src/core/verify.js +105 -0
  29. package/dist/src/core/verify.js.map +1 -0
  30. package/dist/src/core/wallet.d.ts +100 -0
  31. package/dist/src/core/wallet.d.ts.map +1 -0
  32. package/dist/src/core/wallet.js +225 -0
  33. package/dist/src/core/wallet.js.map +1 -0
  34. package/dist/src/wallet.d.ts +12 -0
  35. package/dist/src/wallet.d.ts.map +1 -0
  36. package/dist/src/wallet.js +16 -0
  37. package/dist/src/wallet.js.map +1 -0
  38. package/index.ts +73 -12
  39. package/openclaw.plugin.json +12 -1
  40. package/package.json +1 -1
  41. package/src/actions.ts +54 -0
  42. package/src/core/config.d.ts +12 -0
  43. package/src/core/config.ts +21 -0
  44. package/src/core/index.ts +42 -0
  45. package/src/core/payment.d.ts +17 -0
  46. package/src/core/payment.ts +111 -0
  47. package/src/core/types.d.ts +95 -0
  48. package/src/core/types.ts +102 -0
  49. package/src/core/verify.d.ts +29 -0
  50. package/src/core/verify.ts +119 -0
  51. package/src/core/wallet.d.ts +100 -0
  52. package/src/core/wallet.ts +289 -0
  53. package/src/wallet.ts +20 -0
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @a2a-bsv/core — Payment verification and acceptance helpers.
3
+ *
4
+ * Verification: parse the Atomic BEEF, validate structure.
5
+ * Acceptance: internalize the payment into the recipient wallet via BRC-29
6
+ * wallet payment protocol.
7
+ */
8
+ import type { SetupWallet } from '@bsv/wallet-toolbox';
9
+ import type { VerifyParams, VerifyResult, AcceptParams, AcceptResult } from './types.js';
10
+ /**
11
+ * Verify an incoming Atomic BEEF payment.
12
+ *
13
+ * This performs structural validation:
14
+ * - Decodes the base64 BEEF
15
+ * - Checks the BEEF is parseable
16
+ * - Checks there is at least one transaction
17
+ * - Runs SPV verification via tx.verify()
18
+ * - Optionally checks the sender identity key
19
+ */
20
+ export declare function verifyPayment(params: VerifyParams): Promise<VerifyResult>;
21
+ /**
22
+ * Accept (internalize) a verified BRC-29 payment into the recipient's wallet.
23
+ *
24
+ * This calls wallet.internalizeAction with the 'wallet payment' protocol,
25
+ * providing the BRC-29 derivation info so the wallet can derive the correct
26
+ * key and claim the output.
27
+ */
28
+ export declare function acceptPayment(setup: SetupWallet, params: AcceptParams): Promise<AcceptResult>;
29
+ //# sourceMappingURL=verify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../src/core/verify.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGzF;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAkD/E;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,YAAY,CAAC,CA2BvB"}
@@ -0,0 +1,105 @@
1
+ /**
2
+ * @a2a-bsv/core — Payment verification and acceptance helpers.
3
+ *
4
+ * Verification: parse the Atomic BEEF, validate structure.
5
+ * Acceptance: internalize the payment into the recipient wallet via BRC-29
6
+ * wallet payment protocol.
7
+ */
8
+ import { Beef, Utils } from '@bsv/sdk';
9
+ /**
10
+ * Verify an incoming Atomic BEEF payment.
11
+ *
12
+ * This performs structural validation:
13
+ * - Decodes the base64 BEEF
14
+ * - Checks the BEEF is parseable
15
+ * - Checks there is at least one transaction
16
+ * - Runs SPV verification via tx.verify()
17
+ * - Optionally checks the sender identity key
18
+ */
19
+ export async function verifyPayment(params) {
20
+ const errors = [];
21
+ let txid = '';
22
+ let outputCount = 0;
23
+ try {
24
+ const binary = Utils.toArray(params.beef, 'base64');
25
+ const beef = Beef.fromBinary(binary);
26
+ if (beef.txs.length === 0) {
27
+ errors.push('BEEF contains no transactions');
28
+ }
29
+ else {
30
+ const lastTx = beef.txs[beef.txs.length - 1];
31
+ txid = lastTx.txid;
32
+ // Parse the atomic transaction to count outputs
33
+ const tx = beef.findAtomicTransaction(txid);
34
+ if (tx) {
35
+ outputCount = tx.outputs.length;
36
+ // Run SPV verification
37
+ try {
38
+ await tx.verify();
39
+ }
40
+ catch (err) {
41
+ const message = err instanceof Error ? err.message : String(err);
42
+ errors.push(`SPV verification failed: ${message}`);
43
+ }
44
+ }
45
+ else {
46
+ errors.push('Could not find atomic transaction in BEEF');
47
+ }
48
+ }
49
+ }
50
+ catch (err) {
51
+ const message = err instanceof Error ? err.message : String(err);
52
+ errors.push(`BEEF parse error: ${message}`);
53
+ }
54
+ // Sender validation is independent of BEEF parsing
55
+ if (params.expectedSender) {
56
+ if (!/^0[23][0-9a-fA-F]{64}$/.test(params.expectedSender)) {
57
+ errors.push('expectedSender is not a valid compressed public key');
58
+ }
59
+ }
60
+ return {
61
+ valid: errors.length === 0,
62
+ txid,
63
+ outputCount,
64
+ errors,
65
+ };
66
+ }
67
+ /**
68
+ * Accept (internalize) a verified BRC-29 payment into the recipient's wallet.
69
+ *
70
+ * This calls wallet.internalizeAction with the 'wallet payment' protocol,
71
+ * providing the BRC-29 derivation info so the wallet can derive the correct
72
+ * key and claim the output.
73
+ */
74
+ export async function acceptPayment(setup, params) {
75
+ const desc = normalizeDescription(params.description ?? 'received payment');
76
+ const vout = params.vout ?? 0;
77
+ const binary = Utils.toArray(params.beef, 'base64');
78
+ const args = {
79
+ tx: binary,
80
+ outputs: [
81
+ {
82
+ outputIndex: vout,
83
+ protocol: 'wallet payment',
84
+ paymentRemittance: {
85
+ derivationPrefix: params.derivationPrefix,
86
+ derivationSuffix: params.derivationSuffix,
87
+ senderIdentityKey: params.senderIdentityKey,
88
+ },
89
+ },
90
+ ],
91
+ description: desc,
92
+ };
93
+ const result = await setup.wallet.internalizeAction(args);
94
+ return {
95
+ accepted: result.accepted,
96
+ };
97
+ }
98
+ function normalizeDescription(desc) {
99
+ if (desc.length < 5)
100
+ return desc.padEnd(5, ' ');
101
+ if (desc.length > 50)
102
+ return desc.slice(0, 50);
103
+ return desc;
104
+ }
105
+ //# sourceMappingURL=verify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.js","sourceRoot":"","sources":["../../../src/core/verify.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAKvC;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAAoB;IACtD,MAAM,MA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AAO;QACL,QAAQ,EAAE,MAAM,CAAC,QAAQ;KAC1B,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB,CAAC,IAAY;IACxC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAChD,IAAI,IAAI,CAAC,MAAM,GAAG,EAAE;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC/C,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,100 @@
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 type { SetupWallet } from '@bsv/wallet-toolbox';
9
+ import type { WalletConfig, PaymentParams, PaymentResult, VerifyParams, VerifyResult, AcceptParams, AcceptResult } from './types.js';
10
+ /**
11
+ * BSVAgentWallet — the primary class for agent-to-agent BSV payments.
12
+ *
13
+ * Usage:
14
+ * ```ts
15
+ * // Create a new wallet (generates keys)
16
+ * const wallet = await BSVAgentWallet.load({ network: 'testnet', storageDir: './agent-wallet' });
17
+ *
18
+ * // Load an existing wallet
19
+ * const wallet = await BSVAgentWallet.load({ network: 'testnet', storageDir: './agent-wallet' });
20
+ *
21
+ * // Make a payment
22
+ * const payment = await wallet.createPayment({ to: recipientPubKey, satoshis: 500 });
23
+ *
24
+ * // Verify and accept a payment
25
+ * const verification = wallet.verifyPayment({ beef: payment.beef });
26
+ * if (verification.valid) {
27
+ * await wallet.acceptPayment({ beef: payment.beef, ...derivationInfo });
28
+ * }
29
+ * ```
30
+ */
31
+ export declare class BSVAgentWallet {
32
+ /** @internal — exposed for advanced operations (e.g. direct internalizeAction) */
33
+ readonly _setup: SetupWallet;
34
+ private constructor();
35
+ /**
36
+ * Create a new agent wallet. Generates a fresh root key and persists it.
37
+ * The SQLite database and identity file are written to `config.storageDir`.
38
+ */
39
+ private static create;
40
+ /**
41
+ * Load an existing agent wallet from its storage directory.
42
+ * Reads the persisted identity file and re-initializes the wallet.
43
+ */
44
+ static load(config: WalletConfig): Promise<BSVAgentWallet>;
45
+ /**
46
+ * Get this wallet's public identity key (compressed hex, 33 bytes).
47
+ * This is the key other agents use to send payments to you.
48
+ */
49
+ getIdentityKey(): Promise<string>;
50
+ /**
51
+ * Get the wallet's current balance in satoshis.
52
+ *
53
+ * Uses the BRC-100 wallet's balance method which sums spendable outputs
54
+ * in the default basket.
55
+ */
56
+ getBalance(): Promise<number>;
57
+ /**
58
+ * Cleanly shut down the wallet, releasing database connections and
59
+ * stopping the background monitor.
60
+ */
61
+ destroy(): Promise<void>;
62
+ /**
63
+ * Build a BRC-29 payment to another agent.
64
+ *
65
+ * The transaction is created with `noSend: true` — the sender does NOT
66
+ * broadcast it. Instead, the Atomic BEEF and derivation metadata are
67
+ * returned so they can be transmitted to the recipient, who will
68
+ * verify and internalize (broadcast) the payment.
69
+ *
70
+ * @param params.to — Recipient's compressed public key (hex).
71
+ * @param params.satoshis — Amount in satoshis.
72
+ * @param params.description — Optional human-readable note.
73
+ */
74
+ createPayment(params: PaymentParams): Promise<PaymentResult>;
75
+ /**
76
+ * Verify an incoming Atomic BEEF payment.
77
+ *
78
+ * This performs structural validation and SPV verification via tx.verify().
79
+ */
80
+ verifyPayment(params: VerifyParams): Promise<VerifyResult>;
81
+ /**
82
+ * Accept (internalize) a verified payment into this wallet.
83
+ *
84
+ * Uses the BRC-29 wallet payment protocol to derive the correct key
85
+ * and claim the output. This triggers SPV verification and, if the
86
+ * transaction hasn't been broadcast yet, broadcasts it.
87
+ */
88
+ acceptPayment(params: AcceptParams): Promise<AcceptResult>;
89
+ /** Get the underlying wallet-toolbox SetupWallet for advanced operations. */
90
+ getSetup(): SetupWallet;
91
+ /**
92
+ * Internal: manually construct a BRC-100 wallet backed by SQLite.
93
+ *
94
+ * We build this by hand instead of using Setup.createWalletSQLite because
95
+ * the toolbox has a bug where its internal randomBytesHex is a stub.
96
+ * We use the same components but wire them up correctly.
97
+ */
98
+ private static buildSetup;
99
+ }
100
+ //# sourceMappingURL=wallet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../../src/core/wallet.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAKvD,OAAO,KAAK,EACV,YAAY,EAEZ,aAAa,EACb,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACb,MAAM,YAAY,CAAC;AAQpB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,cAAc;IACzB,kFAAkF;IAClF,SAAgB,MAAM,EAAE,WAAW,CAAC;IAEpC,OAAO;IAQP;;;OAGG;mBACkB,MAAM;IAwB3B;;;OAGG;WACU,IAAI,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC;IAoBhE;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAIvC;;;;;OAKG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAInC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ9B;;;;;;;;;;;OAWG;IACG,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAQlE;;;;OAIG;IACG,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAIhE;;;;;;OAMG;IACG,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAQhE,6EAA6E;IAC7E,QAAQ,IAAI,WAAW;IAQvB;;;;;;OAMG;mBACkB,UAAU;CAyEhC"}
@@ -0,0 +1,225 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../../src/core/wallet.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EACL,MAAM,EACN,oBAAoB,EACpB,QAAQ,EACR,OAAO,EACP,WAAW,EACX,cAAc,EACd,wBAAwB,GACzB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,OAAO,MAAM,MAAM,CAAC;AAC3B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAY9B,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE3D,uDAAuD;AACvD,MAAM,aAAa,GAAG,sBAAsB,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,cAAc;IACzB,kFAAkF;IAClE,MAAM,CAAc;IAEpC,YAAoB,KAAkB;QACpC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,8EAA8E;IAC9E,kBAAkB;IAClB,8EAA8E;IAE9E;;;OAGG;IACK,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAoB;QAC9C,0DAA0D;QAC1D,MAAM,UAAU,GAAG,MAAM,C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{ WalletCore } from '@bsv/simple';
3
+ import { BSVAgentWallet } from './core/wallet.js';
4
+ /**
5
+ * ClawWalletCore — bridges OpenClaw's shared wallet identity with @bsv/simple modules.
6
+ */
7
+ export declare class ClawWalletCore extends WalletCore {
8
+ private wallet;
9
+ constructor(wallet: BSVAgentWallet);
10
+ getClient(): WalletInterface;
11
+ }
12
+ //# sourceMappingURL=wallet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;GAEG;AACH,qBAAa,cAAe,SAAQ,UAAU;IAC5C,OAAO,CAAC,MAAM,CAAiB;gBAEnB,MAAM,EAAE,cAAc;IAKlC,SAAS,IAAI,eAAe;CAG7B"}
@@ -0,0 +1,16 @@
1
+ // @ts-ignore
2
+ import { WalletCore } from '@bsv/simple';
3
+ /**
4
+ * ClawWalletCore — bridges OpenClaw's shared wallet identity with @bsv/simple modules.
5
+ */
6
+ export class ClawWalletCore extends WalletCore {
7
+ wallet;
8
+ constructor(wallet) {
9
+ super(wallet._setup.identityKey);
10
+ this.wallet = wallet;
11
+ }
12
+ getClient() {
13
+ return this.wallet._setup.wallet;
14
+ }
15
+ }
16
+ //# sourceMappingURL=wallet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/wallet.ts"],"names":[],"mappings":"AACA,aAAa;AACb,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,UAAU;IACpC,MAAM,CAAiB;IAE/B,YAAY,MAAsB;QAChC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAoC,CAAC;IACjE,CAAC;CACF"}
package/index.ts CHANGED
@@ -1,21 +1,49 @@
1
1
  import path from "node:path";
2
2
  import os from "node:os";
3
+ import { SimpleSVManager } from "./src/actions.js";
4
+ import { ClawWalletCore } from "./src/wallet.js";
5
+ import { BSVAgentWallet } from "./src/core/wallet.js";
6
+
7
+ // Ambient declaration for optional dependencies
8
+ declare module "@bsv/simple-mcp";
3
9
 
4
10
  /**
5
11
  * OpenClaw SimpleSV Plugin
6
12
  * High-level blockchain utility belt (DIDs, Tokens, Inscriptions).
7
13
  */
8
14
  export default function register(api: any) {
9
- const entry = api.getConfig?.()?.plugins?.entries?.['openclaw-simplesv'] || {};
15
+ const entries = api.getConfig?.()?.plugins?.entries || {};
16
+ const entry = entries['openclaw-simplesv']
17
+ || entries['openclaw-simplesv-plugin']
18
+ || entries['bsv-simple']
19
+ || {};
20
+
10
21
  const pluginConfig = { ...entry, ...(entry.config || {}), ...(api.config || {}) };
11
22
  const network = pluginConfig.network || 'mainnet';
12
23
  const chaintracksUrl = pluginConfig.chaintracksUrl || 'https://chaintracks-us-1.bsvb.tech';
24
+ const arcUrl = pluginConfig.arcUrl || (network === 'testnet' ? 'https://testnet.arc.gorillapool.io' : 'https://arc.gorillapool.io');
13
25
  const walletDir = pluginConfig.walletDir || path.join(os.homedir(), '.openclaw', 'bsv-wallet');
14
26
  const enableMcp = pluginConfig.enableMcp === true;
15
27
 
16
- api.logger.info(`[simplesv] Initializing SimpleSV Plugin (network: ${network}, chaintracks: ${chaintracksUrl})`);
28
+ let manager: SimpleSVManager | null = null;
29
+
30
+ api.logger.info(`[simplesv] Initializing SimpleSV Plugin (network: ${network}, host: ${chaintracksUrl}, arc: ${arcUrl})`);
31
+
32
+ async function ensureInitialized() {
33
+ if (manager) return manager;
34
+
35
+ // Initialize shared wallet
36
+ const wallet = await BSVAgentWallet.load({
37
+ network: network as any,
38
+ storageDir: walletDir
39
+ });
40
+
41
+ const core = new ClawWalletCore(wallet);
42
+ manager = new SimpleSVManager(core);
43
+ return manager;
44
+ }
17
45
 
18
- // Register the base simplesv tool
46
+ // Register the simplesv tool
19
47
  api.registerTool({
20
48
  name: "simplesv",
21
49
  description: "High-level BSV utility belt: DIDs, Tokens, and Inscriptions",
@@ -61,19 +89,54 @@ export default function register(api: any) {
61
89
  basket: {
62
90
  type: "string",
63
91
  description: "Basket name for tokens"
92
+ },
93
+ tokenId: {
94
+ type: "string",
95
+ description: "ID of the token to transfer"
64
96
  }
65
97
  },
66
98
  required: ["action"]
67
99
  },
68
100
  async execute(_id: string, params: any) {
69
101
  try {
70
- // Implementation logic using @bsv/simple will go here
71
- return {
72
- content: [{
73
- type: "text",
74
- text: `SimpleSV action '${params.action}' received. (Logic implementation pending)`
75
- }]
76
- };
102
+ const m = await ensureInitialized();
103
+
104
+ switch (params.action) {
105
+ case "inscribe":
106
+ const insResult = await m.inscribe(params.data, params.text);
107
+ return { content: [{ type: "text", text: `✅ Inscription created! TXID: ${insResult.txid}` }] };
108
+
109
+ case "resolve_did":
110
+ if (!params.did) throw new Error("did is required");
111
+ const didDoc = await m.resolveDid(params.did);
112
+ return { content: [{ type: "text", text: `Decoded DID Document:\n${JSON.stringify(didDoc, null, 2)}` }] };
113
+
114
+ case "token_issue":
115
+ if (!params.basket || !params.data) throw new Error("basket and data required");
116
+ const tokenResult = await m.issueToken(params.basket, params.data);
117
+ return { content: [{ type: "text", text: `✅ Token issued! ID: ${tokenResult.tokenId}\nTXID: ${tokenResult.txid}` }] };
118
+
119
+ case "token_transfer":
120
+ if (!params.tokenId || !params.recipientKey) throw new Error("tokenId and recipientKey required");
121
+ const transResult = await m.transferToken(params.tokenId, params.recipientKey);
122
+ return { content: [{ type: "text", text: `✅ Token transferred!\nTXID: ${transResult.txid}` }] };
123
+
124
+ case "status":
125
+ const status = m.getStatus();
126
+ const myDid = await m.getMyDid();
127
+ // @ts-ignore
128
+ const balance = status.status.balance ?? "unknown";
129
+ return { content: [{ type: "text", text: `SimpleSV Status:\nIdentity Key: ${status.identityKey}\nDID: ${JSON.stringify(myDid)}\nAddress: ${status.address}\nBalance: ${balance} sats` }] };
130
+
131
+ case "pay_p2p":
132
+ return { content: [{ type: "text", text: "Standard P2P payment logic integration pending." }] };
133
+
134
+ case "vc_issue":
135
+ return { content: [{ type: "text", text: "Verifiable Credential logic integration pending." }] };
136
+
137
+ default:
138
+ throw new Error(`Unknown action: ${params.action}`);
139
+ }
77
140
  } catch (error: any) {
78
141
  return {
79
142
  content: [{
@@ -92,8 +155,6 @@ export default function register(api: any) {
92
155
  import('@bsv/simple-mcp').then((mcp) => {
93
156
  api.logger.info("[simplesv] @bsv/simple-mcp detected! Mounting advanced blockchain tools...");
94
157
 
95
- // Loop through all tools provided by the MCP library and register them
96
- // Note: This logic depends on the specific export structure of @bsv/simple-mcp
97
158
  if (mcp.tools) {
98
159
  Object.values(mcp.tools).forEach((tool: any) => {
99
160
  api.registerTool({