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.
Files changed (191) hide show
  1. package/dist/index.js +3037 -328
  2. package/dist/index.js.map +7 -0
  3. package/dist/src/cli.js +3820 -11
  4. package/dist/src/cli.js.map +7 -0
  5. package/index.ts +32 -27
  6. package/openclaw.plugin.json +1 -1
  7. package/package.json +8 -6
  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/scripts/x-verification/commands.ts +5 -0
  18. package/src/test/identity-consistency.test.ts +1 -1
  19. package/src/test/wallet.test.ts +1 -2
  20. package/dist/index.d.ts +0 -9
  21. package/dist/src/cli-main.d.ts +0 -7
  22. package/dist/src/cli-main.js +0 -202
  23. package/dist/src/cli.d.ts +0 -8
  24. package/dist/src/compatibility.test.d.ts +0 -4
  25. package/dist/src/compatibility.test.js +0 -41
  26. package/dist/src/core/config.d.ts +0 -11
  27. package/dist/src/core/config.js +0 -15
  28. package/dist/src/core/index.d.ts +0 -25
  29. package/dist/src/core/index.js +0 -26
  30. package/dist/src/core/payment.d.ts +0 -16
  31. package/dist/src/core/payment.js +0 -94
  32. package/dist/src/core/types.d.ts +0 -94
  33. package/dist/src/core/types.js +0 -4
  34. package/dist/src/core/verify.d.ts +0 -28
  35. package/dist/src/core/verify.js +0 -104
  36. package/dist/src/core/wallet.d.ts +0 -105
  37. package/dist/src/core/wallet.js +0 -256
  38. package/dist/src/scripts/baemail/commands.d.ts +0 -35
  39. package/dist/src/scripts/baemail/commands.js +0 -282
  40. package/dist/src/scripts/baemail/handler.d.ts +0 -36
  41. package/dist/src/scripts/baemail/handler.js +0 -284
  42. package/dist/src/scripts/baemail/index.d.ts +0 -5
  43. package/dist/src/scripts/baemail/index.js +0 -5
  44. package/dist/src/scripts/config.d.ts +0 -52
  45. package/dist/src/scripts/config.js +0 -75
  46. package/dist/src/scripts/index.d.ts +0 -7
  47. package/dist/src/scripts/index.js +0 -7
  48. package/dist/src/scripts/messaging/connect.d.ts +0 -8
  49. package/dist/src/scripts/messaging/connect.js +0 -168
  50. package/dist/src/scripts/messaging/handlers.d.ts +0 -21
  51. package/dist/src/scripts/messaging/handlers.js +0 -334
  52. package/dist/src/scripts/messaging/inbox.d.ts +0 -11
  53. package/dist/src/scripts/messaging/inbox.js +0 -51
  54. package/dist/src/scripts/messaging/index.d.ts +0 -8
  55. package/dist/src/scripts/messaging/index.js +0 -8
  56. package/dist/src/scripts/messaging/poll.d.ts +0 -7
  57. package/dist/src/scripts/messaging/poll.js +0 -52
  58. package/dist/src/scripts/messaging/send.d.ts +0 -7
  59. package/dist/src/scripts/messaging/send.js +0 -43
  60. package/dist/src/scripts/output.d.ts +0 -13
  61. package/dist/src/scripts/output.js +0 -28
  62. package/dist/src/scripts/overlay/advertisement.d.ts +0 -16
  63. package/dist/src/scripts/overlay/advertisement.js +0 -122
  64. package/dist/src/scripts/overlay/discover.d.ts +0 -7
  65. package/dist/src/scripts/overlay/discover.js +0 -74
  66. package/dist/src/scripts/overlay/index.d.ts +0 -7
  67. package/dist/src/scripts/overlay/index.js +0 -7
  68. package/dist/src/scripts/overlay/registration.d.ts +0 -19
  69. package/dist/src/scripts/overlay/registration.js +0 -176
  70. package/dist/src/scripts/overlay/services.d.ts +0 -29
  71. package/dist/src/scripts/overlay/services.js +0 -167
  72. package/dist/src/scripts/overlay/transaction.d.ts +0 -42
  73. package/dist/src/scripts/overlay/transaction.js +0 -103
  74. package/dist/src/scripts/payment/build.d.ts +0 -24
  75. package/dist/src/scripts/payment/build.js +0 -54
  76. package/dist/src/scripts/payment/commands.d.ts +0 -15
  77. package/dist/src/scripts/payment/commands.js +0 -73
  78. package/dist/src/scripts/payment/index.d.ts +0 -6
  79. package/dist/src/scripts/payment/index.js +0 -6
  80. package/dist/src/scripts/payment/types.d.ts +0 -56
  81. package/dist/src/scripts/payment/types.js +0 -4
  82. package/dist/src/scripts/services/index.d.ts +0 -6
  83. package/dist/src/scripts/services/index.js +0 -6
  84. package/dist/src/scripts/services/queue.d.ts +0 -11
  85. package/dist/src/scripts/services/queue.js +0 -28
  86. package/dist/src/scripts/services/request.d.ts +0 -7
  87. package/dist/src/scripts/services/request.js +0 -82
  88. package/dist/src/scripts/services/respond.d.ts +0 -11
  89. package/dist/src/scripts/services/respond.js +0 -132
  90. package/dist/src/scripts/types.d.ts +0 -107
  91. package/dist/src/scripts/types.js +0 -4
  92. package/dist/src/scripts/utils/index.d.ts +0 -6
  93. package/dist/src/scripts/utils/index.js +0 -6
  94. package/dist/src/scripts/utils/merkle.d.ts +0 -12
  95. package/dist/src/scripts/utils/merkle.js +0 -47
  96. package/dist/src/scripts/utils/storage.d.ts +0 -66
  97. package/dist/src/scripts/utils/storage.js +0 -211
  98. package/dist/src/scripts/utils/woc.d.ts +0 -26
  99. package/dist/src/scripts/utils/woc.js +0 -91
  100. package/dist/src/scripts/wallet/balance.d.ts +0 -22
  101. package/dist/src/scripts/wallet/balance.js +0 -240
  102. package/dist/src/scripts/wallet/identity.d.ts +0 -71
  103. package/dist/src/scripts/wallet/identity.js +0 -152
  104. package/dist/src/scripts/wallet/index.d.ts +0 -6
  105. package/dist/src/scripts/wallet/index.js +0 -6
  106. package/dist/src/scripts/wallet/setup.d.ts +0 -19
  107. package/dist/src/scripts/wallet/setup.js +0 -119
  108. package/dist/src/scripts/x-verification/commands.d.ts +0 -27
  109. package/dist/src/scripts/x-verification/commands.js +0 -222
  110. package/dist/src/scripts/x-verification/index.d.ts +0 -4
  111. package/dist/src/scripts/x-verification/index.js +0 -4
  112. package/dist/src/services/built-in/api-proxy/index.d.ts +0 -6
  113. package/dist/src/services/built-in/api-proxy/index.js +0 -23
  114. package/dist/src/services/built-in/code-develop/index.d.ts +0 -6
  115. package/dist/src/services/built-in/code-develop/index.js +0 -23
  116. package/dist/src/services/built-in/code-review/index.d.ts +0 -10
  117. package/dist/src/services/built-in/code-review/index.js +0 -51
  118. package/dist/src/services/built-in/image-analysis/index.d.ts +0 -6
  119. package/dist/src/services/built-in/image-analysis/index.js +0 -33
  120. package/dist/src/services/built-in/memory-store/index.d.ts +0 -6
  121. package/dist/src/services/built-in/memory-store/index.js +0 -22
  122. package/dist/src/services/built-in/roulette/index.d.ts +0 -6
  123. package/dist/src/services/built-in/roulette/index.js +0 -27
  124. package/dist/src/services/built-in/summarize/index.d.ts +0 -6
  125. package/dist/src/services/built-in/summarize/index.js +0 -21
  126. package/dist/src/services/built-in/tell-joke/handler.d.ts +0 -7
  127. package/dist/src/services/built-in/tell-joke/handler.js +0 -122
  128. package/dist/src/services/built-in/tell-joke/index.d.ts +0 -9
  129. package/dist/src/services/built-in/tell-joke/index.js +0 -31
  130. package/dist/src/services/built-in/translate/index.d.ts +0 -6
  131. package/dist/src/services/built-in/translate/index.js +0 -21
  132. package/dist/src/services/built-in/web-research/index.d.ts +0 -9
  133. package/dist/src/services/built-in/web-research/index.js +0 -51
  134. package/dist/src/services/index.d.ts +0 -13
  135. package/dist/src/services/index.js +0 -14
  136. package/dist/src/services/loader.d.ts +0 -77
  137. package/dist/src/services/loader.js +0 -292
  138. package/dist/src/services/manager.d.ts +0 -86
  139. package/dist/src/services/manager.js +0 -255
  140. package/dist/src/services/registry.d.ts +0 -98
  141. package/dist/src/services/registry.js +0 -204
  142. package/dist/src/services/types.d.ts +0 -230
  143. package/dist/src/services/types.js +0 -30
  144. package/dist/src/test/cli.test.d.ts +0 -7
  145. package/dist/src/test/cli.test.js +0 -330
  146. package/dist/src/test/comprehensive-overlay.test.d.ts +0 -13
  147. package/dist/src/test/comprehensive-overlay.test.js +0 -593
  148. package/dist/src/test/identity-consistency.test.d.ts +0 -6
  149. package/dist/src/test/identity-consistency.test.js +0 -60
  150. package/dist/src/test/key-derivation.test.d.ts +0 -12
  151. package/dist/src/test/key-derivation.test.js +0 -86
  152. package/dist/src/test/network-address.test.d.ts +0 -9
  153. package/dist/src/test/network-address.test.js +0 -37
  154. package/dist/src/test/overlay-submit.test.d.ts +0 -10
  155. package/dist/src/test/overlay-submit.test.js +0 -460
  156. package/dist/src/test/request-response-flow.test.d.ts +0 -5
  157. package/dist/src/test/request-response-flow.test.js +0 -210
  158. package/dist/src/test/service-system.test.d.ts +0 -5
  159. package/dist/src/test/service-system.test.js +0 -190
  160. package/dist/src/test/taskflow.test.d.ts +0 -7
  161. package/dist/src/test/taskflow.test.js +0 -82
  162. package/dist/src/test/utils/server-logic.d.ts +0 -98
  163. package/dist/src/test/utils/server-logic.js +0 -286
  164. package/dist/src/test/wallet.test.d.ts +0 -7
  165. package/dist/src/test/wallet.test.js +0 -146
  166. package/src/core/README.md +0 -246
  167. package/src/core/config.d.ts +0 -12
  168. package/src/core/config.d.ts.map +0 -1
  169. package/src/core/config.js +0 -14
  170. package/src/core/config.js.map +0 -1
  171. package/src/core/config.ts +0 -22
  172. package/src/core/index.ts +0 -42
  173. package/src/core/payment.d.ts +0 -17
  174. package/src/core/payment.d.ts.map +0 -1
  175. package/src/core/payment.js +0 -95
  176. package/src/core/payment.js.map +0 -1
  177. package/src/core/payment.ts +0 -111
  178. package/src/core/types.d.ts +0 -95
  179. package/src/core/types.d.ts.map +0 -1
  180. package/src/core/types.js +0 -5
  181. package/src/core/types.js.map +0 -1
  182. package/src/core/types.ts +0 -102
  183. package/src/core/verify.d.ts +0 -29
  184. package/src/core/verify.d.ts.map +0 -1
  185. package/src/core/verify.js +0 -105
  186. package/src/core/verify.js.map +0 -1
  187. package/src/core/verify.ts +0 -119
  188. package/src/core/wallet.d.ts +0 -100
  189. package/src/core/wallet.d.ts.map +0 -1
  190. package/src/core/wallet.js.map +0 -1
  191. package/src/core/wallet.ts +0 -323
@@ -1,26 +0,0 @@
1
- /**
2
- * @a2a-bsv/core — Agent-to-agent BSV payment library.
3
- *
4
- * Wraps @bsv/sdk and @bsv/wallet-toolbox to provide a clean, minimal API
5
- * for AI agents to pay each other using BSV blockchain transactions.
6
- *
7
- * @example
8
- * ```ts
9
- * import { BSVAgentWallet } from '@a2a-bsv/core';
10
- *
11
- * const wallet = await BSVAgentWallet.load({
12
- * network: 'testnet',
13
- * storageDir: './my-agent-wallet',
14
- * });
15
- *
16
- * const identityKey = await wallet.getIdentityKey();
17
- * console.log('My identity:', identityKey);
18
- * ```
19
- */
20
- // Main wallet class
21
- export { BSVAgentWallet } from './wallet.js';
22
- // Config helpers (for advanced use)
23
- export { toChain, DEFAULT_TAAL_API_KEYS, DEFAULT_DB_NAME } from './config.js';
24
- // Lower-level helpers (for advanced use)
25
- export { buildPayment } from './payment.js';
26
- export { verifyPayment, acceptPayment } from './verify.js';
@@ -1,16 +0,0 @@
1
- /**
2
- * @a2a-bsv/core — Payment construction helpers.
3
- *
4
- * Uses BRC-29 key derivation so the recipient can internalize the payment
5
- * without ever reusing an address.
6
- */
7
- import type { SetupWallet } from '@bsv/wallet-toolbox';
8
- import type { PaymentParams, PaymentResult } from './types.js';
9
- /**
10
- * Build a BRC-29 payment transaction using the wallet's createAction API.
11
- *
12
- * The transaction is created with `acceptDelayedBroadcast: false` — the sender
13
- * broadcasts immediately. The resulting Atomic BEEF and derivation metadata are
14
- * returned so the recipient can verify and internalize the payment on their side.
15
- */
16
- export declare function buildPayment(setup: SetupWallet, params: PaymentParams): Promise<PaymentResult>;
@@ -1,94 +0,0 @@
1
- /**
2
- * @a2a-bsv/core — Payment construction helpers.
3
- *
4
- * Uses BRC-29 key derivation so the recipient can internalize the payment
5
- * without ever reusing an address.
6
- */
7
- import { Beef, Utils } from '@bsv/sdk';
8
- import { randomBytesBase64, ScriptTemplateBRC29 } from '@bsv/wallet-toolbox';
9
- /**
10
- * Build a BRC-29 payment transaction using the wallet's createAction API.
11
- *
12
- * The transaction is created with `acceptDelayedBroadcast: false` — the sender
13
- * broadcasts immediately. The resulting Atomic BEEF and derivation metadata are
14
- * returned so the recipient can verify and internalize the payment on their side.
15
- */
16
- export async function buildPayment(setup, params) {
17
- const { to, satoshis, description } = params;
18
- const desc = normalizeDescription(description ?? 'agent payment');
19
- // Generate unique BRC-29 derivation prefixes and suffixes
20
- const derivationPrefix = randomBytesBase64(8);
21
- const derivationSuffix = randomBytesBase64(8);
22
- // Build BRC-29 locking script
23
- const keyDeriver = setup.keyDeriver;
24
- const t = new ScriptTemplateBRC29({
25
- derivationPrefix,
26
- derivationSuffix,
27
- keyDeriver,
28
- });
29
- // Determine the recipient identity key.
30
- // If `to` is a compressed public key hex (66 chars, starts with 02/03), use directly.
31
- // Otherwise treat as an address — for BRC-29 we need a public key.
32
- let recipientPubKey;
33
- if (/^0[23][0-9a-fA-F]{64}$/.test(to)) {
34
- recipientPubKey = to;
35
- }
36
- else {
37
- // If it's an address, we can't do BRC-29 (needs pubkey). Throw a clear error.
38
- throw new Error('PaymentParams.to must be a compressed public key (hex) for BRC-29 payments. ' +
39
- 'Raw BSV addresses are not supported — the recipient must share their identity key.');
40
- }
41
- const lockingScript = t.lock(setup.rootKey.toString(), recipientPubKey);
42
- const label = 'a2a-payment';
43
- const car = await setup.wallet.createAction({
44
- outputs: [
45
- {
46
- lockingScript: lockingScript.toHex(),
47
- satoshis,
48
- outputDescription: desc,
49
- tags: ['relinquish'],
50
- customInstructions: JSON.stringify({
51
- derivationPrefix,
52
- derivationSuffix,
53
- type: 'BRC29',
54
- }),
55
- },
56
- ],
57
- options: {
58
- randomizeOutputs: false,
59
- acceptDelayedBroadcast: false,
60
- },
61
- labels: [label],
62
- description: desc,
63
- });
64
- // Extract the txid from the createAction result.
65
- // The tx field is a number[] (AtomicBEEF binary). Parse it to get txid.
66
- if (!car.tx) {
67
- throw new Error('createAction did not return a transaction. Check wallet funding.');
68
- }
69
- const beef = Beef.fromBinary(car.tx);
70
- // The last transaction in the beef is our new tx
71
- const lastTx = beef.txs[beef.txs.length - 1];
72
- const txid = lastTx.txid;
73
- // Encode the atomic BEEF as base64
74
- const atomicBinary = beef.toBinaryAtomic(txid);
75
- const beefBase64 = Utils.toBase64(atomicBinary);
76
- return {
77
- beef: beefBase64,
78
- txid,
79
- satoshis,
80
- derivationPrefix,
81
- derivationSuffix,
82
- senderIdentityKey: setup.identityKey,
83
- };
84
- }
85
- /**
86
- * Ensure description meets BRC-100's 5-50 character requirement.
87
- */
88
- function normalizeDescription(desc) {
89
- if (desc.length < 5)
90
- return desc.padEnd(5, ' ');
91
- if (desc.length > 50)
92
- return desc.slice(0, 50);
93
- return desc;
94
- }
@@ -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
- }