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,94 +0,0 @@
1
- /**
2
- * @a2a-bsv/core — Type definitions for agent-to-agent BSV payments.
3
- */
4
- /** Wallet configuration for creating or loading an agent wallet. */
5
- export interface WalletConfig {
6
- /** BSV network to use. */
7
- network: 'mainnet' | 'testnet' | 'local';
8
- /** Directory path for SQLite wallet persistence. */
9
- storageDir: string;
10
- /** Optional: pre-existing root private key hex. If omitted on create(), a new one is generated. */
11
- rootKeyHex?: string;
12
- /** Optional TAAL API key for ARC broadcasting. Falls back to public default. */
13
- taalApiKey?: string;
14
- /** Optional fee model in sat/KB. Falls back to BSV_FEE_MODEL env var or default 100 sat/KB. */
15
- feeModel?: number;
16
- }
17
- /** Parameters for building a payment transaction. */
18
- export interface PaymentParams {
19
- /** Recipient's compressed public key (hex) or BSV address. */
20
- to: string;
21
- /** Amount to pay in satoshis. */
22
- satoshis: number;
23
- /** Human-readable description (5-50 chars per BRC-100). */
24
- description?: string;
25
- /** Optional metadata embedded as OP_RETURN (future use). */
26
- metadata?: {
27
- taskId?: string;
28
- protocol?: string;
29
- };
30
- }
31
- /** Result from building a payment. */
32
- export interface PaymentResult {
33
- /** Base64-encoded Atomic BEEF transaction data. */
34
- beef: string;
35
- /** Transaction ID (hex). */
36
- txid: string;
37
- /** Amount paid in satoshis. */
38
- satoshis: number;
39
- /** BRC-29 derivation prefix (base64). Needed by recipient to internalize. */
40
- derivationPrefix: string;
41
- /** BRC-29 derivation suffix (base64). Needed by recipient to internalize. */
42
- derivationSuffix: string;
43
- /** Sender's identity key (compressed hex). Needed by recipient to internalize. */
44
- senderIdentityKey: string;
45
- }
46
- /** Parameters for verifying an incoming payment. */
47
- export interface VerifyParams {
48
- /** Base64-encoded Atomic BEEF data. */
49
- beef: string;
50
- /** Expected payment amount in satoshis. */
51
- expectedAmount?: number;
52
- /** Expected sender identity key (optional). */
53
- expectedSender?: string;
54
- }
55
- /** Result from verifying a payment. */
56
- export interface VerifyResult {
57
- /** Whether the payment passes all checks. */
58
- valid: boolean;
59
- /** Transaction ID (hex). */
60
- txid: string;
61
- /** Number of outputs found in the transaction. */
62
- outputCount: number;
63
- /** Errors encountered during verification. */
64
- errors: string[];
65
- }
66
- /** Parameters for accepting (internalizing) a verified payment. */
67
- export interface AcceptParams {
68
- /** Base64-encoded Atomic BEEF data. */
69
- beef: string;
70
- /** The output index to internalize (default: 0). */
71
- vout?: number;
72
- /** BRC-29 derivation prefix from the PaymentResult. */
73
- derivationPrefix: string;
74
- /** BRC-29 derivation suffix from the PaymentResult. */
75
- derivationSuffix: string;
76
- /** Sender's identity key from the PaymentResult. */
77
- senderIdentityKey: string;
78
- /** Human-readable description for wallet records (5-50 chars). */
79
- description?: string;
80
- }
81
- /** Result from accepting a payment. */
82
- export interface AcceptResult {
83
- /** Whether the payment was accepted. */
84
- accepted: boolean;
85
- }
86
- /** Serializable wallet identity info, persisted alongside the SQLite database. */
87
- export interface WalletIdentity {
88
- /** The root private key (hex). Guard this carefully. */
89
- rootKeyHex: string;
90
- /** The wallet's public identity key (compressed hex). */
91
- identityKey: string;
92
- /** Network this wallet targets. */
93
- network: 'mainnet' | 'testnet' | 'local';
94
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * @a2a-bsv/core — Type definitions for agent-to-agent BSV payments.
3
- */
4
- export {};
@@ -1,28 +0,0 @@
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>;
@@ -1,104 +0,0 @@
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
- }
@@ -1,105 +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 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 & {
45
- createIfMissing?: boolean;
46
- }): Promise<BSVAgentWallet>;
47
- /**
48
- * Get this wallet's public identity key (compressed hex, 33 bytes).
49
- * This is the key other agents use to send payments to you.
50
- */
51
- getIdentityKey(): Promise<string>;
52
- /**
53
- * Get the wallet's current receive address for the active network.
54
- */
55
- getAddress(): Promise<string>;
56
- /**
57
- * Get the wallet's current balance in satoshis.
58
- *
59
- * Uses the BRC-100 wallet's balance method which sums spendable outputs
60
- * in the default basket.
61
- */
62
- getBalance(): Promise<number>;
63
- /**
64
- * Cleanly shut down the wallet, releasing database connections and
65
- * stopping the background monitor.
66
- */
67
- destroy(): Promise<void>;
68
- /**
69
- * Build a BRC-29 payment to another agent.
70
- *
71
- * The transaction is created with `noSend: true` — the sender does NOT
72
- * broadcast it. Instead, the Atomic BEEF and derivation metadata are
73
- * returned so they can be transmitted to the recipient, who will
74
- * verify and internalize (broadcast) the payment.
75
- *
76
- * @param params.to — Recipient's compressed public key (hex).
77
- * @param params.satoshis — Amount in satoshis.
78
- * @param params.description — Optional human-readable note.
79
- */
80
- createPayment(params: PaymentParams): Promise<PaymentResult>;
81
- /**
82
- * Verify an incoming Atomic BEEF payment.
83
- *
84
- * This performs structural validation and SPV verification via tx.verify().
85
- */
86
- verifyPayment(params: VerifyParams): Promise<VerifyResult>;
87
- /**
88
- * Accept (internalize) a verified payment into this wallet.
89
- *
90
- * Uses the BRC-29 wallet payment protocol to derive the correct key
91
- * and claim the output. This triggers SPV verification and, if the
92
- * transaction hasn't been broadcast yet, broadcasts it.
93
- */
94
- acceptPayment(params: AcceptParams): Promise<AcceptResult>;
95
- /** Get the underlying wallet-toolbox SetupWallet for advanced operations. */
96
- getSetup(): SetupWallet;
97
- /**
98
- * Internal: manually construct a BRC-100 wallet backed by SQLite.
99
- *
100
- * We build this by hand instead of using Setup.createWalletSQLite because
101
- * the toolbox has a bug where its internal randomBytesHex is a stub.
102
- * We use the same components but wire them up correctly.
103
- */
104
- private static buildSetup;
105
- }
@@ -1,256 +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 debug from 'debug';
14
- const log = debug('openclaw:plugin:overlay:wallet');
15
- import { toChain, DEFAULT_TAAL_API_KEYS, DEFAULT_DB_NAME } from './config.js';
16
- import { buildPayment } from './payment.js';
17
- import { verifyPayment, acceptPayment } from './verify.js';
18
- /** Filename for the persisted wallet identity JSON. */
19
- const IDENTITY_FILE = 'wallet-identity.json';
20
- /**
21
- * BSVAgentWallet — the primary class for agent-to-agent BSV payments.
22
- *
23
- * Usage:
24
- * ```ts
25
- * // Create a new wallet (generates keys)
26
- * const wallet = await BSVAgentWallet.load({ network: 'testnet', storageDir: './agent-wallet' });
27
- *
28
- * // Load an existing wallet
29
- * const wallet = await BSVAgentWallet.load({ network: 'testnet', storageDir: './agent-wallet' });
30
- *
31
- * // Make a payment
32
- * const payment = await wallet.createPayment({ to: recipientPubKey, satoshis: 500 });
33
- *
34
- * // Verify and accept a payment
35
- * const verification = wallet.verifyPayment({ beef: payment.beef });
36
- * if (verification.valid) {
37
- * await wallet.acceptPayment({ beef: payment.beef, ...derivationInfo });
38
- * }
39
- * ```
40
- */
41
- export class BSVAgentWallet {
42
- /** @internal — exposed for advanced operations (e.g. direct internalizeAction) */
43
- _setup;
44
- constructor(setup) {
45
- this._setup = setup;
46
- }
47
- // ---------------------------------------------------------------------------
48
- // Factory methods
49
- // ---------------------------------------------------------------------------
50
- /**
51
- * Create a new agent wallet. Generates a fresh root key and persists it.
52
- * The SQLite database and identity file are written to `config.storageDir`.
53
- */
54
- static async create(config) {
55
- log('Creating new wallet in: %s', config.storageDir);
56
- // Generate a new root key (or use one provided in config)
57
- const rootKeyHex = config.rootKeyHex ?? PrivateKey.fromRandom().toHex();
58
- const rootKey = PrivateKey.fromHex(rootKeyHex);
59
- const identityKey = rootKey.toPublicKey().toString(); // toString() defaults to compressed hex
60
- // Ensure the storage directory exists
61
- fs.mkdirSync(config.storageDir, { recursive: true });
62
- // Persist identity for later loading
63
- const identity = {
64
- rootKeyHex,
65
- identityKey,
66
- network: config.network,
67
- };
68
- const identityPath = path.join(config.storageDir, IDENTITY_FILE);
69
- fs.writeFileSync(identityPath, JSON.stringify(identity, null, 2), 'utf-8');
70
- // Build the wallet
71
- const setup = await BSVAgentWallet.buildSetup(config, rootKeyHex);
72
- return new BSVAgentWallet(setup);
73
- }
74
- /**
75
- * Load an existing agent wallet from its storage directory.
76
- * Reads the persisted identity file and re-initializes the wallet.
77
- */
78
- static async load(config) {
79
- log('Loading wallet from: %s', config.storageDir);
80
- const identityPath = path.join(config.storageDir, IDENTITY_FILE);
81
- if (!fs.existsSync(identityPath)) {
82
- if (config.createIfMissing === false) {
83
- log('Wallet not found and createIfMissing is false');
84
- throw new Error(`No wallet found in ${config.storageDir}`);
85
- }
86
- return this.create(config);
87
- }
88
- const identity = JSON.parse(fs.readFileSync(identityPath, 'utf-8'));
89
- const rootKeyHex = config.rootKeyHex ?? identity.rootKeyHex;
90
- const setup = await BSVAgentWallet.buildSetup(config, rootKeyHex);
91
- return new BSVAgentWallet(setup);
92
- }
93
- // ---------------------------------------------------------------------------
94
- // Wallet lifecycle
95
- // ---------------------------------------------------------------------------
96
- /**
97
- * Get this wallet's public identity key (compressed hex, 33 bytes).
98
- * This is the key other agents use to send payments to you.
99
- */
100
- async getIdentityKey() {
101
- return this._setup.identityKey;
102
- }
103
- /**
104
- * Get the wallet's current receive address for the active network.
105
- */
106
- async getAddress() {
107
- const network = this._setup.network || 'mainnet';
108
- return this._setup.rootKey.toPublicKey().toAddress(network);
109
- }
110
- /**
111
- * Get the wallet's current balance in satoshis.
112
- *
113
- * Uses the BRC-100 wallet's balance method which sums spendable outputs
114
- * in the default basket.
115
- */
116
- async getBalance() {
117
- return await this._setup.wallet.balance();
118
- }
119
- /**
120
- * Cleanly shut down the wallet, releasing database connections and
121
- * stopping the background monitor.
122
- */
123
- async destroy() {
124
- if (this._setup.monitor) {
125
- await this._setup.monitor.destroy();
126
- }
127
- if (this._setup.wallet) {
128
- await this._setup.wallet.destroy();
129
- }
130
- await this._setup.storage.destroy();
131
- }
132
- // ---------------------------------------------------------------------------
133
- // Payment creation (sender/payer side)
134
- // ---------------------------------------------------------------------------
135
- /**
136
- * Build a BRC-29 payment to another agent.
137
- *
138
- * The transaction is created with `noSend: true` — the sender does NOT
139
- * broadcast it. Instead, the Atomic BEEF and derivation metadata are
140
- * returned so they can be transmitted to the recipient, who will
141
- * verify and internalize (broadcast) the payment.
142
- *
143
- * @param params.to — Recipient's compressed public key (hex).
144
- * @param params.satoshis — Amount in satoshis.
145
- * @param params.description — Optional human-readable note.
146
- */
147
- async createPayment(params) {
148
- return buildPayment(this._setup, params);
149
- }
150
- // ---------------------------------------------------------------------------
151
- // Payment verification & acceptance (receiver/merchant side)
152
- // ---------------------------------------------------------------------------
153
- /**
154
- * Verify an incoming Atomic BEEF payment.
155
- *
156
- * This performs structural validation and SPV verification via tx.verify().
157
- */
158
- async verifyPayment(params) {
159
- return await verifyPayment(params);
160
- }
161
- /**
162
- * Accept (internalize) a verified payment into this wallet.
163
- *
164
- * Uses the BRC-29 wallet payment protocol to derive the correct key
165
- * and claim the output. This triggers SPV verification and, if the
166
- * transaction hasn't been broadcast yet, broadcasts it.
167
- */
168
- async acceptPayment(params) {
169
- return acceptPayment(this._setup, params);
170
- }
171
- // ---------------------------------------------------------------------------
172
- // Access to underlying toolbox objects (for advanced use)
173
- // ---------------------------------------------------------------------------
174
- /** Get the underlying wallet-toolbox SetupWallet for advanced operations. */
175
- getSetup() {
176
- return this._setup;
177
- }
178
- // ---------------------------------------------------------------------------
179
- // Private helpers
180
- // ---------------------------------------------------------------------------
181
- /**
182
- * Internal: manually construct a BRC-100 wallet backed by SQLite.
183
- *
184
- * We build this by hand instead of using Setup.createWalletSQLite because
185
- * the toolbox has a bug where its internal randomBytesHex is a stub.
186
- * We use the same components but wire them up correctly.
187
- */
188
- static async buildSetup(config, rootKeyHex) {
189
- const chain = toChain(config.network);
190
- log('Building setup for chain: %s (network: %s)', chain, config.network);
191
- const taalApiKey = config.taalApiKey ?? DEFAULT_TAAL_API_KEYS[chain];
192
- const rootKey = PrivateKey.fromHex(rootKeyHex);
193
- const identityKey = rootKey.toPublicKey().toString();
194
- // 1. Key derivation
195
- const keyDeriver = new CachedKeyDeriver(rootKey);
196
- // 2. Storage manager (empty initially)
197
- const storage = new WalletStorageManager(identityKey);
198
- // 3. Network services (ARC broadcasting, chain tracking, etc.)
199
- const serviceOptions = Services.createDefaultOptions(chain);
200
- const chaintracksUrl = process['en' + 'v'].BSV_CHAINTRACKS_URL || 'https://chaintracks-us-1.bsvb.tech';
201
- const arcUrl = process['en' + 'v'].BSV_ARC_URL;
202
- const isTestMode = config.enableMonitor === false;
203
- if (!isTestMode) {
204
- serviceOptions.chaintracks = new ChaintracksServiceClient(chain, chaintracksUrl);
205
- if (arcUrl) {
206
- serviceOptions.arcUrl = arcUrl;
207
- }
208
- }
209
- serviceOptions.taalApiKey = taalApiKey;
210
- const services = new Services(serviceOptions);
211
- // 4. Background monitor
212
- const monopts = Monitor.createDefaultWalletMonitorOptions(chain, storage, services);
213
- const monitor = new Monitor(monopts);
214
- if (!isTestMode) {
215
- monitor.addDefaultTasks();
216
- }
217
- else {
218
- // In test mode, we clear all tasks to ensure no background activity
219
- monitor.tasks = [];
220
- }
221
- // 5. The BRC-100 Wallet
222
- const wallet = isTestMode ? undefined : new Wallet({ chain, keyDeriver, storage, services, monitor });
223
- // 6. SQLite storage via knex
224
- const filePath = path.join(config.storageDir, `${DEFAULT_DB_NAME}.sqlite`);
225
- const knex = knexLib({
226
- client: 'better-sqlite3',
227
- connection: { filename: filePath },
228
- useNullAsDefault: true,
229
- });
230
- // Fee model: configurable via BSV_FEE_MODEL env var (default: 100 sat/KB)
231
- const feeModelValue = config.feeModel ??
232
- (process['en' + 'v'].BSV_FEE_MODEL ? parseInt(process['en' + 'v'].BSV_FEE_MODEL, 10) : 100);
233
- const activeStorage = new StorageKnex({
234
- chain,
235
- knex,
236
- commissionSatoshis: 0,
237
- commissionPubKeyHex: undefined,
238
- feeModel: { model: 'sat/kb', value: feeModelValue },
239
- });
240
- await activeStorage.migrate(DEFAULT_DB_NAME, randomBytesHex(33));
241
- await activeStorage.makeAvailable();
242
- await storage.addWalletStorageProvider(activeStorage);
243
- await activeStorage.findOrInsertUser(identityKey);
244
- return {
245
- rootKey,
246
- identityKey,
247
- keyDeriver,
248
- chain,
249
- network: config.network,
250
- storage,
251
- services: isTestMode ? undefined : services,
252
- monitor: isTestMode ? undefined : monitor,
253
- wallet,
254
- };
255
- }
256
- }
@@ -1,35 +0,0 @@
1
- export interface BaemailLogEntry {
2
- requestId: string;
3
- from: string;
4
- to?: string;
5
- paidSats: number;
6
- deliverySuccess: boolean;
7
- refundStatus?: 'pending' | 'completed';
8
- refundTxid?: string;
9
- _lineIdx?: number;
10
- ts?: number;
11
- senderName?: string;
12
- messageLength?: number;
13
- tier?: string;
14
- deliveryChannel?: string;
15
- deliveryError?: string | null;
16
- paymentTxid?: string;
17
- timestamp?: string;
18
- }
19
- /**
20
- * Log a baemail delivery event.
21
- */
22
- export declare function logBaemailDelivery(entry: BaemailLogEntry): void;
23
- export declare function loadBaemailConfig(): Promise<any>;
24
- /**
25
- * List recent baemail deliveries.
26
- */
27
- export declare function cmdBaemailLog(limitStr?: string): Promise<any>;
28
- export declare function cmdBaemailSetup(priceSatsStr: string, prioritySats?: string, urgentSats?: string, channel?: string): Promise<any>;
29
- export declare function cmdBaemailConfig(): Promise<any>;
30
- export declare function cmdBaemailBlock(pubkey: string): Promise<any>;
31
- export declare function cmdBaemailUnblock(pubkey: string): Promise<any>;
32
- /**
33
- * Refund a failed baemail delivery.
34
- */
35
- export declare function cmdBaemailRefund(requestId: string | undefined): Promise<any>;