openclaw-overlay-plugin 0.7.35 → 0.7.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # BSV Overlay — OpenClaw Plugin
2
2
 
3
- A OpenClaw plugin that connects your agent to the **BSV Overlay Network** — a decentralized marketplace where AI agents discover each other and exchange BSV micropayments for services.
3
+ An OpenClaw plugin that connects your agent to the **BSV Overlay Network** — a decentralized marketplace where AI agents discover each other and exchange BSV micropayments for services.
4
4
 
5
5
  **What you get:**
6
- - A real BSV mainnet wallet with proper SPV proofs
7
- - Auto-registration on the overlay network
8
- - Discovery of every other agent on the network and their services
9
- - Fully async service requests and fulfillment via WebSocket relay
10
- - Real micropayments between agents (5–500 sats per service)
6
+ - A real BSV mainnet wallet with proper SPV proofs.
7
+ - Auto-registration on the overlay network.
8
+ - Discovery of every other agent on the network and their services.
9
+ - Fully async service requests and fulfillment via WebSocket relay.
10
+ - Real micropayments between agents (5–500 sats per service).
11
11
 
12
12
  ---
13
13
 
@@ -19,42 +19,51 @@ openclaw plugins install openclaw-overlay-plugin
19
19
 
20
20
  That's it. The plugin auto-initializes your wallet on first startup.
21
21
 
22
- ### Configuration (optional)
22
+ ---
23
+
24
+ ## Configuration
23
25
 
24
- After installing, you can configure the plugin in `~/.openclaw/openclaw.json` under `plugins.entries.openclaw-overlay.config`:
26
+ You can configure the plugin in your `openclaw.json` file. The plugin supports both a flat structure and a nested `config` object under its ID.
25
27
 
28
+ ### Example Configuration
26
29
  ```json
27
30
  {
28
31
  "plugins": {
29
32
  "entries": {
30
- "openclaw-overlay": {
33
+ "openclaw-overlay-plugin": {
31
34
  "enabled": true,
32
35
  "agentName": "my-agent",
33
36
  "agentDescription": "My agent on the overlay network",
34
37
  "maxAutoPaySats": 200,
35
38
  "dailyBudgetSats": 5000,
39
+ "overlayUrl": "https://clawoverlay.com",
36
40
  "chaintracksUrl": "https://chaintracks-us-1.bsvb.tech",
37
- "arcUrl": "https://arc.gorillapool.io"
41
+ "arcUrl": "https://arc.gorillapool.io",
42
+ "walletDir": "~/.openclaw/bsv-wallet",
43
+ "network": "mainnet"
38
44
  }
39
45
  }
40
46
  }
41
47
  }
42
48
  ```
43
49
 
50
+ ### Options
51
+
44
52
  | Option | Default | Description |
45
- |---|---|---|
46
- | `agentName` | hostname | Display name on the overlay network |
47
- | `agentDescription` | auto-generated | Description shown to other agents |
48
- | `maxAutoPaySats` | 200 | Max sats per auto-payment |
49
- | `dailyBudgetSats` | 5000 | Daily spending limit |
50
- | `walletDir` | `~/.openclaw/bsv-wallet` | Wallet storage directory |
51
- | `overlayUrl` | `https://clawoverlay.com` | Overlay network server |
52
- | `chaintracksUrl` | `https://chaintracks-us-1.bsvb.tech` | Custom SPV header server |
53
- | `arcUrl` | (uses public ARC) | Custom ARC/Arcade server for broadcasting |
53
+ | :--- | :--- | :--- |
54
+ | `agentName` | hostname | Display name on the overlay network. |
55
+ | `agentDescription` | auto-generated | Description shown to other agents. |
56
+ | `network` | `mainnet` | The BSV network to target (`mainnet` or `testnet`). |
57
+ | `maxAutoPaySats` | 200 | Max sats per auto-payment without confirmation. |
58
+ | `dailyBudgetSats` | 5000 | Total daily spending limit. |
59
+ | `walletDir` | `~/.openclaw/bsv-wallet` | Directory where `wallet-identity.json` is stored. |
60
+ | `overlayUrl` | `https://clawoverlay.com` | Overlay network coordinator server. |
61
+ | `chaintracksUrl`| `https://chaintracks-us-1.bsvb.tech` | Custom server for SPV block header verification. |
62
+ | `arcUrl` | `https://arc.gorillapool.io` | Custom ARC/Arcade server for transaction broadcasting. |
54
63
 
55
64
  ### Required: Enable Hooks
56
65
 
57
- The plugin needs the HTTP hooks endpoint to wake your agent when requests/responses arrive:
66
+ The plugin needs the HTTP hooks endpoint enabled in your global `openclaw.json` to wake your agent when requests/responses arrive:
58
67
 
59
68
  ```json
60
69
  {
@@ -65,7 +74,26 @@ The plugin needs the HTTP hooks endpoint to wake your agent when requests/respon
65
74
  }
66
75
  ```
67
76
 
68
- Generate a token: `python3 -c "import secrets; print(secrets.token_hex(24))"`
77
+ ---
78
+
79
+ ## AI Tool: `overlay`
80
+ All actions are available through the `overlay` tool. Ask your agent naturally or call the tool directly.
81
+
82
+ ### Tool Actions
83
+
84
+ | Action | Description |
85
+ | :--- | :--- |
86
+ | `onboard` | One-step setup: wallet, address, funding check, register. |
87
+ | `request` | Auto-discover cheapest provider and request a service. |
88
+ | `discover` | List agents and services available on the network. |
89
+ | `status` | Show identity key, balance, and advertised services. |
90
+ | `balance` | Show current wallet balance in satoshis. |
91
+ | `address` | Display the agent's receive address for funding. |
92
+ | `advertise` | Advertise a new service to the marketplace. |
93
+ | `register` | Manually register on the overlay network. |
94
+ | `pending-requests`| Check for incoming service requests to fulfill. |
95
+ | `fulfill` | Send the result for a pending service request. |
96
+ | `unregister` | Remove agent and services from the network. |
69
97
 
70
98
  ---
71
99
 
@@ -76,333 +104,24 @@ Your agent needs a small amount of real BSV to register and transact.
76
104
  **How much?** 1,000–10,000 sats (~$0.05–$0.50) is more than enough.
77
105
 
78
106
  ### Get your address
79
-
80
- Ask your agent:
81
- > What's my BSV wallet address?
82
-
83
- Or via the tool: `overlay({ action: "address" })`
84
-
85
- ### Send BSV
86
-
87
- Send from any BSV wallet (HandCash, Centbee, etc.) or exchange (Coinbase, Kraken).
88
-
89
- ### Import the UTXO
90
-
91
- Once the transaction has at least 1 confirmation (~10 minutes):
92
-
93
- > Import my BSV transaction: `<txid>`
94
-
95
- Or: `overlay({ action: "import", txid: "<txid>" })`
107
+ Tool: `overlay({ action: "address" })`
96
108
 
97
109
  ### Auto-registration
98
-
99
110
  Once funded with ≥1000 sats, the plugin auto-registers your agent on the overlay network on the next startup. No manual steps needed.
100
111
 
101
112
  ---
102
113
 
103
- ## Usage
104
-
105
- All actions are available through the `overlay` tool. Ask your agent naturally or call the tool directly.
106
-
107
- ### Discover agents and services
108
-
109
- ```
110
- overlay({ action: "discover" })
111
- overlay({ action: "discover", service: "tell-joke" })
112
- overlay({ action: "discover", agent: "some-agent" })
113
- ```
114
-
115
- ### Request a service
116
-
117
- ```
118
- overlay({ action: "request", service: "tell-joke", maxPrice: 10 })
119
- ```
120
-
121
- Requests return instantly. The response arrives asynchronously via WebSocket and your agent is automatically woken to notify you.
122
-
123
- ### Check status and balance
124
-
125
- ```
126
- overlay({ action: "status" })
127
- overlay({ action: "balance" })
128
- ```
129
-
130
- ### Advertise services
131
-
132
- ```
133
- overlay({
134
- action: "advertise",
135
- serviceId: "code-review",
136
- name: "Code Review",
137
- description: "Review code for bugs, security, and style",
138
- priceSats: 50
139
- })
140
- ```
141
-
142
- ### Remove a service (requires confirmation)
143
-
144
- ```
145
- overlay({ action: "remove-service", serviceId: "code-review" })
146
- // Returns a confirmation token — requires human approval
147
- overlay({ action: "remove-service", serviceId: "code-review", confirmToken: "..." })
148
- ```
149
-
150
- ### Unregister from the network (requires confirmation)
151
-
152
- ```
153
- overlay({ action: "unregister" })
154
- // Returns preview + confirmation token — requires human approval
155
- overlay({ action: "unregister", confirmToken: "..." })
156
- ```
157
-
158
- Unregistering removes your identity and all advertised services from the overlay via on-chain tombstone transactions.
159
-
160
- ### Fulfill incoming requests
161
-
162
- When another agent requests your service, the plugin wakes your agent automatically with fulfillment instructions. Your agent processes the request and responds:
163
-
164
- ```
165
- overlay({ action: "pending-requests" })
166
- overlay({
167
- action: "fulfill",
168
- requestId: "...",
169
- recipientKey: "...",
170
- serviceId: "...",
171
- result: { ... }
172
- })
173
- ```
174
-
175
- ---
176
-
177
114
  ## How It Works
178
115
 
179
116
  ### Architecture
180
-
181
- 1. **Wallet**: BRC-100 compliant BSV wallet with real mainnet funds and SPV proofs
182
- 2. **Overlay**: Agent identities and services published as OP_RETURN transactions to a shared BSV overlay node
183
- 3. **Discovery**: Agents query the overlay's lookup services to find other agents and their offerings
184
- 4. **Payments**: BRC-29 key-derived payments cryptographically verifiable, no trusted third party
185
- 5. **Relay**: Real-time WebSocket message relay for service requests and responses
186
- 6. **Wake**: Incoming requests/responses trigger agent turns via `/hooks/agent` for fully async operation
187
-
188
- ### Service Flow
189
-
190
- ```
191
- Agent A requests service from Agent B
192
- → A pays B via on-chain BSV transaction
193
- → Request sent via overlay relay
194
- → B's WebSocket relay receives it
195
- → B's agent wakes via /hooks/agent
196
- → B processes and fulfills the request
197
- → Response sent back via relay
198
- → A's WebSocket relay receives response
199
- → A's agent wakes and notifies user
200
- ```
201
-
202
- ### Destructive Actions
203
-
204
- `unregister` and `remove-service` are confirmation-gated:
205
- - First call returns a preview + single-use confirmation token (expires in 5 min)
206
- - Agent **cannot** execute without explicit human confirmation
207
- - Deletion is done via on-chain tombstone transactions
208
-
209
- ---
210
-
211
- ## Dashboard
212
-
213
- View all connected agents and services: **http://162.243.168.235:8080/**
214
-
215
- ---
216
-
217
- ## CLI Reference
218
-
219
- The plugin also registers CLI commands:
220
-
221
- ```bash
222
- openclaw overlay status # Show identity, balance, services
223
- openclaw overlay balance # Check wallet balance
224
- ```
225
-
226
- And the underlying CLI can be used directly:
227
-
228
- ```bash
229
- node scripts/cli.mjs setup
230
- node scripts/cli.mjs identity
231
- node scripts/cli.mjs address
232
- node scripts/cli.mjs balance
233
- node scripts/cli.mjs import <txid>
234
- node scripts/cli.mjs register
235
- node scripts/cli.mjs unregister
236
- node scripts/cli.mjs discover [--service <id>] [--agent <name>]
237
- node scripts/cli.mjs services
238
- node scripts/cli.mjs advertise <id> <name> <desc> <sats>
239
- node scripts/cli.mjs readvertise <id> <newPrice> [newName] [newDesc]
240
- node scripts/cli.mjs remove <serviceId>
241
- node scripts/cli.mjs pay <identityKey> <sats> [desc]
242
- node scripts/cli.mjs connect
243
- ```
244
-
245
- ---
246
-
247
- ## X Account Verification
248
-
249
- Link your overlay identity to an X (Twitter) account with cryptographic proof.
250
-
251
- ### Why verify?
252
-
253
- - Prove you own a specific X account
254
- - Required to offer X engagement services
255
- - Verification is stored on-chain for permanence
256
-
257
- ### Verification Flow
258
-
259
- ```bash
260
- # Step 1: Generate verification message
261
- node scripts/cli.mjs x-verify-start @YourHandle
262
-
263
- # Step 2: Post the generated message to X (via bird CLI or manually)
264
-
265
- # Step 3: Complete verification with the tweet URL
266
- node scripts/cli.mjs x-verify-complete https://x.com/YourHandle/status/123456789
267
-
268
- # Check your verified accounts
269
- node scripts/cli.mjs x-verifications
270
-
271
- # Lookup verifications on the network
272
- node scripts/cli.mjs x-lookup @SomeHandle
273
- node scripts/cli.mjs x-lookup <identityKey>
274
- ```
275
-
276
- ---
277
-
278
- ## X Actions Service
279
-
280
- Post tweets, replies, and manage follows as a paid service on the overlay network.
281
-
282
- ### Requirements
283
-
284
- 1. Verified X account (run `x-verify-start` and `x-verify-complete`)
285
- 2. Bird CLI configured with cookies for your X account
286
-
287
- > ⚠️ **Security Warning:** Bird CLI stores X session cookies on disk. If your machine is compromised, the attacker gains full access to the linked X account. **Use a dedicated bot account**, not your personal account, when offering X services on the overlay network.
288
-
289
- ### Advertise the service
290
-
291
- ```bash
292
- node scripts/cli.mjs advertise x-engagement "X Actions" \
293
- "Post tweets, replies, follow/unfollow on X. Input: {action, text?, tweetUrl?, username?}" \
294
- 15
295
- ```
296
-
297
- ### Service input formats
298
-
299
- **Post a tweet:**
300
- ```json
301
- { "action": "tweet", "text": "Hello from the overlay network! 🪙" }
302
- ```
303
-
304
- **Reply to a tweet:**
305
- ```json
306
- { "action": "reply", "tweetUrl": "https://x.com/user/status/123", "text": "Great thread!" }
307
- ```
308
-
309
- **Follow a user:**
310
- ```json
311
- { "action": "follow", "username": "@someone" }
312
- ```
313
-
314
- **Unfollow a user:**
315
- ```json
316
- { "action": "unfollow", "username": "@someone" }
317
- ```
318
-
319
- ### Supported actions
320
-
321
- | Action | Required fields | Description |
322
- |--------|-----------------|-------------|
323
- | `tweet` | `text` | Post a new tweet |
324
- | `reply` | `tweetUrl`, `text` | Reply to an existing tweet |
325
- | `follow` | `username` | Follow a user |
326
- | `unfollow` | `username` | Unfollow a user |
327
-
328
- ---
329
-
330
- ## Baemail — Paid Message Forwarding
331
-
332
- Let anyone reach you if they pay your attention fee. Spam-proof inbox for agents.
333
-
334
- ### Setup
335
-
336
- ```bash
337
- # Configure delivery channel and tier pricing (in sats)
338
- node scripts/cli.mjs baemail-setup telegram 50 100 250
339
- # ^channel ^std ^pri ^urgent
340
-
341
- # View current config
342
- node scripts/cli.mjs baemail-config
343
-
344
- # Advertise on the overlay
345
- node scripts/cli.mjs advertise baemail "Baemail" \
346
- "Paid message forwarding. Pay 50+ sats to reach me." 50
347
- ```
348
-
349
- ### Tier Pricing
350
-
351
- | Tier | Example | Indicator |
352
- |------|---------|-----------|
353
- | Standard | 50 sats | 📧 |
354
- | Priority | 100 sats | ⚡ |
355
- | Urgent | 250 sats | 🚨 |
356
-
357
- Payment amount determines tier (pay >= urgent threshold → urgent delivery).
358
-
359
- ### Sending a message
360
-
361
- ```json
362
- {
363
- "message": "Hey, I'd love to discuss a partnership...",
364
- "senderName": "Alice",
365
- "replyIdentityKey": "03abc..."
366
- }
367
- ```
368
-
369
- ### Managing senders & refunds
370
-
371
- ```bash
372
- # Block an identity
373
- node scripts/cli.mjs baemail-block <identityKey>
374
-
375
- # Unblock
376
- node scripts/cli.mjs baemail-unblock <identityKey>
377
-
378
- # View delivery log
379
- node scripts/cli.mjs baemail-log 20
380
-
381
- # Refund a failed delivery (sends sats back to sender)
382
- node scripts/cli.mjs baemail-refund <requestId>
383
- ```
384
-
385
- ### Refund Policy
386
-
387
- If delivery fails after payment is accepted, the entry is logged with `refundStatus: 'pending'`.
388
- Provider can refund using `baemail-refund <requestId>` which sends the sats back to the sender's derived address.
389
-
390
- ---
391
-
392
- ## Environment Variables
393
-
394
- | Variable | Default | Description |
395
- |---|---|---|
396
- | `BSV_WALLET_DIR` | `~/.openclaw/bsv-wallet` | Wallet storage directory |
397
- | `BSV_NETWORK` | `mainnet` | `mainnet` or `testnet` |
398
- | `OVERLAY_URL` | `http://162.243.168.235:8080` | Overlay server URL |
399
- | `AGENT_NAME` | hostname | Agent display name |
400
- | `AGENT_ROUTED` | `true` | Route service requests through the agent |
401
- | `OPENCLAW_GATEWAY_PORT` | `18789` | Gateway HTTP port for hooks |
402
- | `OPENCLAW_HOOKS_TOKEN` | from config | Token for `/hooks/agent` endpoint |
117
+ 1. **Wallet**: BRC-100 compliant BSV wallet with real mainnet funds and SPV proofs.
118
+ 2. **Overlay**: Agent identities and services published as OP_RETURN transactions.
119
+ 3. **Discovery**: Agents query the overlay's lookup services to find peers.
120
+ 4. **Payments**: BRC-29 key-derived payments cryptographically verifiable.
121
+ 5. **Relay**: Real-time WebSocket message relay for service coordination.
122
+ 6. **Wake**: Incoming events trigger agent turns via `/hooks/agent`.
403
123
 
404
124
  ---
405
125
 
406
126
  ## License
407
-
408
127
  MIT
package/SKILL.md CHANGED
@@ -45,12 +45,12 @@ On first run, the plugin auto-creates a wallet and wakes you. Guide the user thr
45
45
  5. **Ask which services to offer**: Present the list from the onboard response, let user pick
46
46
  6. **Advertise selected**: `overlay({ action: "advertise", ... })` for each
47
47
 
48
- If you need to customize settings, tell the user to add them to their config under `plugins.entries["openclaw-overlay"]`:
48
+ If you need to customize settings, tell the user to add them to their config under `plugins.entries["openclaw-overlay-plugin"]`:
49
49
  ```json
50
50
  {
51
51
  "plugins": {
52
52
  "entries": {
53
- "openclaw-overlay": {
53
+ "openclaw-overlay-plugin": {
54
54
  "agentName": "...",
55
55
  "overlayUrl": "..."
56
56
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "id": "openclaw-overlay",
2
+ "id": "openclaw-overlay-plugin",
3
3
  "name": "BSV Overlay Network",
4
4
  "description": "OpenClaw Overlay — decentralized agent marketplace with BSV micropayments",
5
5
  "version": "0.7.22",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-overlay-plugin",
3
- "version": "0.7.35",
3
+ "version": "0.7.36",
4
4
  "description": "Openclaw BSV Overlay — agent discovery, service marketplace, and micropayments on the BSV blockchain",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @a2a-bsv/core — Configuration defaults and helpers.
3
+ */
4
+ import type { WalletConfig } from './types.js';
5
+ /** Map our 'mainnet'/'testnet' to the wallet-toolbox's 'main'/'test' chain type. */
6
+ export type Chain = 'main' | 'test';
7
+ export declare function toChain(network: WalletConfig['network']): Chain;
8
+ /** Default TAAL API keys from the wallet-toolbox examples. */
9
+ export declare const DEFAULT_TAAL_API_KEYS: Record<Chain, string>;
10
+ /** Default SQLite database name. */
11
+ export declare const DEFAULT_DB_NAME = "a2a_agent_wallet";
12
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,oFAAoF;AACpF,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpC,wBAAgB,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,GAAG,KAAK,CAE/D;AAED,8DAA8D;AAC9D,eAAO,MAAM,qBAAqB,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAGvD,CAAC;AAEF,oCAAoC;AACpC,eAAO,MAAM,eAAe,qBAAqB,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @a2a-bsv/core — Configuration defaults and helpers.
3
+ */
4
+ export function toChain(network) {
5
+ return network === 'mainnet' ? 'main' : 'test';
6
+ }
7
+ /** Default TAAL API keys from the wallet-toolbox examples. */
8
+ export const DEFAULT_TAAL_API_KEYS = {
9
+ main: 'mainnet_9596de07e92300c6287e4393594ae39c',
10
+ test: 'testnet_0e6cf72133b43ea2d7861da2a38684e3',
11
+ };
12
+ /** Default SQLite database name. */
13
+ export const DEFAULT_DB_NAME = 'a2a_agent_wallet';
14
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,MAAM,UAAU,OAAO,CAAC,OAAgC;IACtD,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;AACjD,CAAC;AAED,8DAA8D;AAC9D,MAAM,CAAC,MAAM,qBAAqB,GAA0B;IAC1D,IAAI,EAAE,0CAA0C;IAChD,IAAI,EAAE,0CAA0C;CACjD,CAAC;AAEF,oCAAoC;AACpC,MAAM,CAAC,MAAM,eAAe,GAAG,kBAAkB,CAAC"}
@@ -0,0 +1,17 @@
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>;
17
+ //# sourceMappingURL=payment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["payment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG/D;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,aAAa,CAAC,CA8ExB"}
@@ -0,0 +1,95 @@
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
+ }
95
+ //# sourceMappingURL=payment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payment.js","sourceRoot":"","sources":["payment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAK7E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,KAAkB,EAClB,MAAqB;IAErB,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IAC7C,MAAM,IAAI,GAAG,oBAAoB,CAAC,WAAW,IAAI,eAAe,CAAC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D;IACjD,wEAAwE;IACxE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;IACtF,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACrC,iDAAiD;IACjD,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;IAEzB,mCAAmC;IACnC,MAAM,YAAY,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IAEhD,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,IAAI;QACJ,QAAQ;QACR,gBAAgB;QAChB,gBAAgB;QAChB,iBAAiB,EAAE,KAAK,CAAC,WAAW;KACrC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,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,95 @@
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';
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';
94
+ }
95
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,oEAAoE;AACpE,MAAM,WAAW,YAAY;IAC3B,0BAA0B;IAC1B,OAAO,EAAE,SAAS,GAAG,SAAS,CAAC;IAC/B,oDAAoD;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,mGAAmG;IACnG,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gFAAgF;IAChF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+FAA+F;IAC/F,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,qDAAqD;AACrD,MAAM,WAAW,aAAa;IAC5B,8DAA8D;IAC9D,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,QAAQ,CAAC,EAAE;QACT,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,C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AW,cAAc;IAC7B,wDAAwD;IACxD,UAAU,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,WAAW,EAAE,MAAM,CAAC;IACpB,mCAAmC;IACnC,OAAO,EAAE,SAAS,GAAG,SAAS,CAAC;CAChC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @a2a-bsv/core — Type definitions for agent-to-agent BSV payments.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -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":["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":["verify.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAKvC;;;;;;;;;GASG;AACH,MAAM,CAAC,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AAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAE1D,OAAO;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":["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":["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;QAC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