openclaw-overlay-plugin 0.7.22

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 (221) hide show
  1. package/README.md +406 -0
  2. package/SKILL.md +78 -0
  3. package/clawdbot.plugin.json +106 -0
  4. package/dist/cli-main.d.ts +7 -0
  5. package/dist/cli-main.js +192 -0
  6. package/dist/cli.d.ts +8 -0
  7. package/dist/cli.js +14 -0
  8. package/dist/core/config.d.ts +11 -0
  9. package/dist/core/config.js +13 -0
  10. package/dist/core/index.d.ts +25 -0
  11. package/dist/core/index.js +26 -0
  12. package/dist/core/payment.d.ts +16 -0
  13. package/dist/core/payment.js +94 -0
  14. package/dist/core/types.d.ts +94 -0
  15. package/dist/core/types.js +4 -0
  16. package/dist/core/verify.d.ts +28 -0
  17. package/dist/core/verify.js +104 -0
  18. package/dist/core/wallet.d.ts +99 -0
  19. package/dist/core/wallet.js +219 -0
  20. package/dist/scripts/baemail/commands.d.ts +64 -0
  21. package/dist/scripts/baemail/commands.js +258 -0
  22. package/dist/scripts/baemail/handler.d.ts +36 -0
  23. package/dist/scripts/baemail/handler.js +284 -0
  24. package/dist/scripts/baemail/index.d.ts +5 -0
  25. package/dist/scripts/baemail/index.js +5 -0
  26. package/dist/scripts/config.d.ts +48 -0
  27. package/dist/scripts/config.js +68 -0
  28. package/dist/scripts/index.d.ts +7 -0
  29. package/dist/scripts/index.js +7 -0
  30. package/dist/scripts/messaging/connect.d.ts +8 -0
  31. package/dist/scripts/messaging/connect.js +114 -0
  32. package/dist/scripts/messaging/handlers.d.ts +21 -0
  33. package/dist/scripts/messaging/handlers.js +334 -0
  34. package/dist/scripts/messaging/inbox.d.ts +11 -0
  35. package/dist/scripts/messaging/inbox.js +51 -0
  36. package/dist/scripts/messaging/index.d.ts +8 -0
  37. package/dist/scripts/messaging/index.js +8 -0
  38. package/dist/scripts/messaging/poll.d.ts +7 -0
  39. package/dist/scripts/messaging/poll.js +52 -0
  40. package/dist/scripts/messaging/send.d.ts +7 -0
  41. package/dist/scripts/messaging/send.js +43 -0
  42. package/dist/scripts/output.d.ts +12 -0
  43. package/dist/scripts/output.js +19 -0
  44. package/dist/scripts/overlay/discover.d.ts +7 -0
  45. package/dist/scripts/overlay/discover.js +72 -0
  46. package/dist/scripts/overlay/index.d.ts +7 -0
  47. package/dist/scripts/overlay/index.js +7 -0
  48. package/dist/scripts/overlay/registration.d.ts +19 -0
  49. package/dist/scripts/overlay/registration.js +176 -0
  50. package/dist/scripts/overlay/services.d.ts +29 -0
  51. package/dist/scripts/overlay/services.js +167 -0
  52. package/dist/scripts/overlay/transaction.d.ts +42 -0
  53. package/dist/scripts/overlay/transaction.js +103 -0
  54. package/dist/scripts/payment/build.d.ts +24 -0
  55. package/dist/scripts/payment/build.js +54 -0
  56. package/dist/scripts/payment/commands.d.ts +15 -0
  57. package/dist/scripts/payment/commands.js +73 -0
  58. package/dist/scripts/payment/index.d.ts +6 -0
  59. package/dist/scripts/payment/index.js +6 -0
  60. package/dist/scripts/payment/types.d.ts +56 -0
  61. package/dist/scripts/payment/types.js +4 -0
  62. package/dist/scripts/services/index.d.ts +6 -0
  63. package/dist/scripts/services/index.js +6 -0
  64. package/dist/scripts/services/queue.d.ts +11 -0
  65. package/dist/scripts/services/queue.js +28 -0
  66. package/dist/scripts/services/request.d.ts +7 -0
  67. package/dist/scripts/services/request.js +82 -0
  68. package/dist/scripts/services/respond.d.ts +11 -0
  69. package/dist/scripts/services/respond.js +132 -0
  70. package/dist/scripts/types.d.ts +107 -0
  71. package/dist/scripts/types.js +4 -0
  72. package/dist/scripts/utils/index.d.ts +6 -0
  73. package/dist/scripts/utils/index.js +6 -0
  74. package/dist/scripts/utils/merkle.d.ts +12 -0
  75. package/dist/scripts/utils/merkle.js +47 -0
  76. package/dist/scripts/utils/storage.d.ts +66 -0
  77. package/dist/scripts/utils/storage.js +211 -0
  78. package/dist/scripts/utils/woc.d.ts +26 -0
  79. package/dist/scripts/utils/woc.js +91 -0
  80. package/dist/scripts/wallet/balance.d.ts +22 -0
  81. package/dist/scripts/wallet/balance.js +240 -0
  82. package/dist/scripts/wallet/identity.d.ts +70 -0
  83. package/dist/scripts/wallet/identity.js +151 -0
  84. package/dist/scripts/wallet/index.d.ts +6 -0
  85. package/dist/scripts/wallet/index.js +6 -0
  86. package/dist/scripts/wallet/setup.d.ts +15 -0
  87. package/dist/scripts/wallet/setup.js +105 -0
  88. package/dist/scripts/x-verification/commands.d.ts +27 -0
  89. package/dist/scripts/x-verification/commands.js +222 -0
  90. package/dist/scripts/x-verification/index.d.ts +4 -0
  91. package/dist/scripts/x-verification/index.js +4 -0
  92. package/dist/services/built-in/api-proxy/index.d.ts +6 -0
  93. package/dist/services/built-in/api-proxy/index.js +23 -0
  94. package/dist/services/built-in/code-develop/index.d.ts +6 -0
  95. package/dist/services/built-in/code-develop/index.js +23 -0
  96. package/dist/services/built-in/code-review/index.d.ts +10 -0
  97. package/dist/services/built-in/code-review/index.js +51 -0
  98. package/dist/services/built-in/image-analysis/index.d.ts +6 -0
  99. package/dist/services/built-in/image-analysis/index.js +33 -0
  100. package/dist/services/built-in/memory-store/index.d.ts +6 -0
  101. package/dist/services/built-in/memory-store/index.js +22 -0
  102. package/dist/services/built-in/roulette/index.d.ts +6 -0
  103. package/dist/services/built-in/roulette/index.js +27 -0
  104. package/dist/services/built-in/summarize/index.d.ts +6 -0
  105. package/dist/services/built-in/summarize/index.js +21 -0
  106. package/dist/services/built-in/tell-joke/handler.d.ts +7 -0
  107. package/dist/services/built-in/tell-joke/handler.js +122 -0
  108. package/dist/services/built-in/tell-joke/index.d.ts +9 -0
  109. package/dist/services/built-in/tell-joke/index.js +31 -0
  110. package/dist/services/built-in/translate/index.d.ts +6 -0
  111. package/dist/services/built-in/translate/index.js +21 -0
  112. package/dist/services/built-in/web-research/index.d.ts +9 -0
  113. package/dist/services/built-in/web-research/index.js +51 -0
  114. package/dist/services/index.d.ts +13 -0
  115. package/dist/services/index.js +14 -0
  116. package/dist/services/loader.d.ts +77 -0
  117. package/dist/services/loader.js +292 -0
  118. package/dist/services/manager.d.ts +86 -0
  119. package/dist/services/manager.js +255 -0
  120. package/dist/services/registry.d.ts +98 -0
  121. package/dist/services/registry.js +204 -0
  122. package/dist/services/types.d.ts +230 -0
  123. package/dist/services/types.js +30 -0
  124. package/dist/test/cli.test.d.ts +7 -0
  125. package/dist/test/cli.test.js +329 -0
  126. package/dist/test/comprehensive-overlay.test.d.ts +13 -0
  127. package/dist/test/comprehensive-overlay.test.js +593 -0
  128. package/dist/test/key-derivation.test.d.ts +12 -0
  129. package/dist/test/key-derivation.test.js +86 -0
  130. package/dist/test/overlay-submit.test.d.ts +10 -0
  131. package/dist/test/overlay-submit.test.js +460 -0
  132. package/dist/test/request-response-flow.test.d.ts +5 -0
  133. package/dist/test/request-response-flow.test.js +209 -0
  134. package/dist/test/service-system.test.d.ts +5 -0
  135. package/dist/test/service-system.test.js +190 -0
  136. package/dist/test/utils/server-logic.d.ts +98 -0
  137. package/dist/test/utils/server-logic.js +286 -0
  138. package/dist/test/wallet.test.d.ts +7 -0
  139. package/dist/test/wallet.test.js +146 -0
  140. package/index.ts +1965 -0
  141. package/openclaw.plugin.json +106 -0
  142. package/package.json +73 -0
  143. package/src/cli-main.ts +230 -0
  144. package/src/cli.ts +16 -0
  145. package/src/core/README.md +246 -0
  146. package/src/core/config.ts +21 -0
  147. package/src/core/index.ts +42 -0
  148. package/src/core/payment.ts +111 -0
  149. package/src/core/types.ts +102 -0
  150. package/src/core/verify.ts +119 -0
  151. package/src/core/wallet.ts +282 -0
  152. package/src/scripts/baemail/commands.ts +326 -0
  153. package/src/scripts/baemail/handler.ts +338 -0
  154. package/src/scripts/baemail/index.ts +6 -0
  155. package/src/scripts/config.ts +81 -0
  156. package/src/scripts/index.ts +8 -0
  157. package/src/scripts/messaging/connect.ts +121 -0
  158. package/src/scripts/messaging/handlers.ts +394 -0
  159. package/src/scripts/messaging/inbox.ts +64 -0
  160. package/src/scripts/messaging/index.ts +9 -0
  161. package/src/scripts/messaging/poll.ts +59 -0
  162. package/src/scripts/messaging/send.ts +54 -0
  163. package/src/scripts/output.ts +21 -0
  164. package/src/scripts/overlay/discover.ts +81 -0
  165. package/src/scripts/overlay/index.ts +8 -0
  166. package/src/scripts/overlay/registration.ts +199 -0
  167. package/src/scripts/overlay/services.ts +199 -0
  168. package/src/scripts/overlay/transaction.ts +124 -0
  169. package/src/scripts/payment/build.ts +65 -0
  170. package/src/scripts/payment/commands.ts +92 -0
  171. package/src/scripts/payment/index.ts +7 -0
  172. package/src/scripts/payment/types.ts +62 -0
  173. package/src/scripts/services/index.ts +7 -0
  174. package/src/scripts/services/queue.ts +35 -0
  175. package/src/scripts/services/request.ts +98 -0
  176. package/src/scripts/services/respond.ts +149 -0
  177. package/src/scripts/types.ts +121 -0
  178. package/src/scripts/utils/index.ts +7 -0
  179. package/src/scripts/utils/merkle.ts +57 -0
  180. package/src/scripts/utils/storage.ts +231 -0
  181. package/src/scripts/utils/woc.ts +106 -0
  182. package/src/scripts/wallet/balance.ts +277 -0
  183. package/src/scripts/wallet/identity.ts +203 -0
  184. package/src/scripts/wallet/index.ts +7 -0
  185. package/src/scripts/wallet/setup.ts +121 -0
  186. package/src/scripts/x-verification/commands.ts +256 -0
  187. package/src/scripts/x-verification/index.ts +5 -0
  188. package/src/services/built-in/api-proxy/index.ts +26 -0
  189. package/src/services/built-in/api-proxy/prompt.md +26 -0
  190. package/src/services/built-in/code-develop/index.ts +26 -0
  191. package/src/services/built-in/code-develop/prompt.md +35 -0
  192. package/src/services/built-in/code-review/index.ts +54 -0
  193. package/src/services/built-in/code-review/prompt.md +105 -0
  194. package/src/services/built-in/image-analysis/index.ts +36 -0
  195. package/src/services/built-in/image-analysis/prompt.md +42 -0
  196. package/src/services/built-in/memory-store/index.ts +25 -0
  197. package/src/services/built-in/memory-store/prompt.md +45 -0
  198. package/src/services/built-in/roulette/index.ts +30 -0
  199. package/src/services/built-in/roulette/prompt.md +35 -0
  200. package/src/services/built-in/summarize/index.ts +24 -0
  201. package/src/services/built-in/summarize/prompt.md +27 -0
  202. package/src/services/built-in/tell-joke/handler.ts +134 -0
  203. package/src/services/built-in/tell-joke/index.ts +34 -0
  204. package/src/services/built-in/tell-joke/prompt.md +59 -0
  205. package/src/services/built-in/translate/index.ts +24 -0
  206. package/src/services/built-in/translate/prompt.md +23 -0
  207. package/src/services/built-in/web-research/index.ts +54 -0
  208. package/src/services/built-in/web-research/prompt.md +110 -0
  209. package/src/services/index.ts +16 -0
  210. package/src/services/loader.ts +344 -0
  211. package/src/services/manager.ts +304 -0
  212. package/src/services/registry.ts +246 -0
  213. package/src/services/types.ts +259 -0
  214. package/src/test/cli.test.ts +352 -0
  215. package/src/test/comprehensive-overlay.test.ts +729 -0
  216. package/src/test/key-derivation.test.ts +102 -0
  217. package/src/test/overlay-submit.test.ts +570 -0
  218. package/src/test/request-response-flow.test.ts +252 -0
  219. package/src/test/service-system.test.ts +241 -0
  220. package/src/test/utils/server-logic.ts +368 -0
  221. package/src/test/wallet.test.ts +166 -0
@@ -0,0 +1,106 @@
1
+ {
2
+ "id": "openclaw-overlay-plugin",
3
+ "name": "BSV Overlay Network",
4
+ "description": "OpenClaw Overlay — decentralized agent marketplace with BSV micropayments",
5
+ "version": "0.7.22",
6
+ "skills": [
7
+ "./SKILL.md"
8
+ ],
9
+ "configSchema": {
10
+ "type": "object",
11
+ "additionalProperties": false,
12
+ "properties": {
13
+ "overlayUrl": {
14
+ "type": "string",
15
+ "default": "https://clawoverlay.com",
16
+ "description": "Overlay server URL for registration, discovery, and relay"
17
+ },
18
+ "agentName": {
19
+ "type": "string",
20
+ "description": "Display name for this agent on the overlay network (defaults to hostname)"
21
+ },
22
+ "agentDescription": {
23
+ "type": "string",
24
+ "description": "Description of this agent shown to other agents on the network"
25
+ },
26
+ "walletDir": {
27
+ "type": "string",
28
+ "description": "BSV wallet storage directory (defaults to ~/.clawdbot/bsv-wallet)"
29
+ },
30
+ "maxAutoPaySats": {
31
+ "type": "number",
32
+ "default": 200,
33
+ "minimum": 0,
34
+ "description": "Maximum satoshis to auto-pay per service request without confirmation"
35
+ },
36
+ "dailyBudgetSats": {
37
+ "type": "number",
38
+ "default": 5000,
39
+ "minimum": 0,
40
+ "description": "Maximum total satoshis to spend per day across all services"
41
+ },
42
+ "autoAcceptPayments": {
43
+ "type": "boolean",
44
+ "default": true,
45
+ "description": "Automatically accept incoming BSV payments for services"
46
+ },
47
+ "preferCheapest": {
48
+ "type": "boolean",
49
+ "default": true,
50
+ "description": "When multiple providers offer the same service, prefer the cheapest"
51
+ },
52
+ "services": {
53
+ "type": "array",
54
+ "items": {
55
+ "type": "string"
56
+ },
57
+ "description": "List of service IDs to auto-advertise on registration"
58
+ }
59
+ }
60
+ },
61
+ "uiHints": {
62
+ "overlayUrl": {
63
+ "label": "Overlay Server URL",
64
+ "placeholder": "https://clawoverlay.com",
65
+ "advanced": true
66
+ },
67
+ "agentName": {
68
+ "label": "Agent Name",
69
+ "placeholder": "my-agent",
70
+ "help": "Display name shown to other agents on the network"
71
+ },
72
+ "agentDescription": {
73
+ "label": "Agent Description",
74
+ "placeholder": "A helpful AI agent offering various services",
75
+ "help": "Description visible to other agents during discovery"
76
+ },
77
+ "walletDir": {
78
+ "label": "Wallet Directory",
79
+ "placeholder": "~/.clawdbot/bsv-wallet",
80
+ "advanced": true
81
+ },
82
+ "maxAutoPaySats": {
83
+ "label": "Max Auto-Pay (sats)",
84
+ "placeholder": "200",
85
+ "help": "Requests above this amount will ask for confirmation"
86
+ },
87
+ "dailyBudgetSats": {
88
+ "label": "Daily Budget (sats)",
89
+ "placeholder": "5000",
90
+ "help": "Total daily spending limit across all service requests"
91
+ },
92
+ "autoAcceptPayments": {
93
+ "label": "Auto-Accept Payments",
94
+ "help": "Automatically accept incoming payments for your advertised services"
95
+ },
96
+ "preferCheapest": {
97
+ "label": "Prefer Cheapest Provider",
98
+ "advanced": true
99
+ },
100
+ "services": {
101
+ "label": "Auto-Advertise Services",
102
+ "help": "Service IDs to automatically advertise when registering",
103
+ "advanced": true
104
+ }
105
+ }
106
+ }
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "openclaw-overlay-plugin",
3
+ "version": "0.7.22",
4
+ "description": "Openclaw BSV Overlay — agent discovery, service marketplace, and micropayments on the BSV blockchain",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "type": "module",
9
+ "files": [
10
+ "index.ts",
11
+ "clawdbot.plugin.json",
12
+ "openclaw.plugin.json",
13
+ "src/",
14
+ "dist/",
15
+ "SKILL.md",
16
+ "README.md"
17
+ ],
18
+ "bin": {
19
+ "openclaw-overlay": "dist/cli.js"
20
+ },
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "cli": "node dist/cli.js",
24
+ "test": "npx tsx src/**/*.test.ts",
25
+ "lint": "eslint src/**/*.ts",
26
+ "postinstall": "node -e \"try{require('better-sqlite3')}catch{console.log('Note: better-sqlite3 requires build tools. If install failed, ensure python3 and a C++ compiler are available.')}\""
27
+ },
28
+ "dependencies": {
29
+ "@bsv/sdk": "^2.0.13",
30
+ "@bsv/wallet-toolbox": "^2.1.17",
31
+ "better-sqlite3": "^12.8.0",
32
+ "dotenv": "^17.3.1",
33
+ "knex": "^3.2.8"
34
+ },
35
+ "devDependencies": {
36
+ "@types/node": "^25.5.0",
37
+ "@types/ws": "^8.18.1",
38
+ "@typescript-eslint/eslint-plugin": "^8.58.0",
39
+ "@typescript-eslint/parser": "^8.58.0",
40
+ "eslint": "^10.1.0",
41
+ "globals": "^17.4.0",
42
+ "typescript": "^6.0.2"
43
+ },
44
+ "optionalDependencies": {
45
+ "ws": "^8.20.0"
46
+ },
47
+ "overrides": {
48
+ "tar": "^7.5.7"
49
+ },
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "git+https://github.com/samooth/openclaw-overlay-plugin.git"
53
+ },
54
+ "keywords": [
55
+ "openclaw",
56
+ "plugin",
57
+ "bsv",
58
+ "overlay",
59
+ "marketplace",
60
+ "micropayments",
61
+ "agent"
62
+ ],
63
+ "author": "Tomás Díaz <tomas@bsv.direct>",
64
+ "license": "MIT",
65
+ "engines": {
66
+ "node": ">=20.0.0"
67
+ },
68
+ "openclaw": {
69
+ "hooks": [
70
+ "./index.ts"
71
+ ]
72
+ }
73
+ }
@@ -0,0 +1,230 @@
1
+ /**
2
+ * BSV Overlay CLI - Main Command Dispatcher
3
+ *
4
+ * Routes commands to the appropriate modules.
5
+ * All business logic is in the scripts/ modules.
6
+ */
7
+
8
+ import { ok, fail } from './scripts/output.js';
9
+
10
+ // Wallet commands
11
+ import { cmdSetup, cmdIdentity, cmdAddress } from './scripts/wallet/setup.js';
12
+ import { cmdBalance, cmdImport, cmdRefund } from './scripts/wallet/balance.js';
13
+
14
+ // Overlay registration commands
15
+ import { cmdRegister, cmdUnregister } from './scripts/overlay/registration.js';
16
+
17
+ // Service commands
18
+ import { cmdServices, cmdAdvertise, cmdRemove, cmdReadvertise } from './scripts/overlay/services.js';
19
+
20
+ // Discovery commands
21
+ import { cmdDiscover } from './scripts/overlay/discover.js';
22
+
23
+ // Payment commands
24
+ import { cmdPay, cmdVerify, cmdAccept } from './scripts/payment/commands.js';
25
+
26
+ // Messaging commands
27
+ import { cmdSend } from './scripts/messaging/send.js';
28
+ import { cmdInbox, cmdAck } from './scripts/messaging/inbox.js';
29
+ import { cmdPoll } from './scripts/messaging/poll.js';
30
+ import { cmdConnect } from './scripts/messaging/connect.js';
31
+
32
+ // Service request/response commands
33
+ import { cmdRequestService } from './scripts/services/request.js';
34
+ import { cmdRespondService, cmdResearchRespond } from './scripts/services/respond.js';
35
+ import { cmdServiceQueue, cmdResearchQueue } from './scripts/services/queue.js';
36
+
37
+ // X verification commands
38
+ import {
39
+ cmdXVerifyStart,
40
+ cmdXVerifyComplete,
41
+ cmdXVerifications,
42
+ cmdXLookup,
43
+ cmdXEngagementQueue,
44
+ cmdXEngagementFulfill,
45
+ } from './scripts/x-verification/commands.js';
46
+
47
+ // Baemail commands
48
+ import {
49
+ cmdBaemailSetup,
50
+ cmdBaemailConfig,
51
+ cmdBaemailBlock,
52
+ cmdBaemailUnblock,
53
+ cmdBaemailLog,
54
+ cmdBaemailRefund,
55
+ } from './scripts/baemail/commands.js';
56
+
57
+ const [, , command, ...args] = process.argv;
58
+
59
+ async function main() {
60
+ try {
61
+ switch (command) {
62
+ // Help
63
+ case 'help':
64
+ case '--help':
65
+ case '-h':
66
+ ok({
67
+ usage: 'openclaw-overlay <command> [args...]',
68
+ commands: {
69
+ wallet: ['setup', 'identity', 'address', 'balance', 'import <txid> [vout]', 'refund <address>'],
70
+ registration: ['register', 'unregister'],
71
+ services: ['services', 'advertise <id> <name> <priceSats> [desc]', 'readvertise <id> [name] [priceSats] [desc]', 'remove <id>'],
72
+ discovery: ['discover [--service <type>] [--agent <name>]'],
73
+ payments: ['pay <pubkey> <sats> [desc]', 'verify <beef>', 'accept <beef> <prefix> <suffix> <senderKey> [desc]'],
74
+ messaging: ['send <key> <type> <json>', 'inbox', 'ack', 'poll', 'connect'],
75
+ 'service-requests': ['request-service <key> <serviceId> <sats> [input]', 'service-queue', 'respond-service <reqId> <key> <serviceId> <result>'],
76
+ research: ['research-queue', 'research-respond <reqId>'],
77
+ 'x-verification': ['x-verify-start <handle>', 'x-verify-complete <handle>', 'x-verifications', 'x-lookup <handle>', 'x-engagement-queue', 'x-engagement-fulfill <reqId> <result>'],
78
+ baemail: ['baemail-setup <price> <xHandle> <forwardEmail> <greeting>', 'baemail-config', 'baemail-block <sender>', 'baemail-unblock <sender>', 'baemail-log [limit]', 'baemail-refund <msgId>'],
79
+ },
80
+ });
81
+ break;
82
+
83
+ // Wallet
84
+ case 'setup':
85
+ await cmdSetup();
86
+ break;
87
+ case 'identity':
88
+ await cmdIdentity();
89
+ break;
90
+ case 'address':
91
+ await cmdAddress();
92
+ break;
93
+ case 'balance':
94
+ await cmdBalance();
95
+ break;
96
+ case 'import':
97
+ await cmdImport(args[0], args[1]);
98
+ break;
99
+ case 'refund':
100
+ await cmdRefund(args[0]);
101
+ break;
102
+
103
+ // Overlay registration
104
+ case 'register':
105
+ await cmdRegister();
106
+ break;
107
+ case 'unregister':
108
+ await cmdUnregister();
109
+ break;
110
+
111
+ // Services
112
+ case 'services':
113
+ await cmdServices();
114
+ break;
115
+ case 'advertise':
116
+ await cmdAdvertise(args[0], args[1], args[2], args[3]);
117
+ break;
118
+ case 'remove':
119
+ await cmdRemove(args[0]);
120
+ break;
121
+ case 'readvertise':
122
+ await cmdReadvertise(args[0], args[1], args[2], args.slice(3).join(' ') || undefined);
123
+ break;
124
+
125
+ // Discovery
126
+ case 'discover':
127
+ await cmdDiscover(args);
128
+ break;
129
+
130
+ // Payments
131
+ case 'pay':
132
+ await cmdPay(args[0], args[1], args.slice(2).join(' ') || undefined);
133
+ break;
134
+ case 'verify':
135
+ await cmdVerify(args[0]);
136
+ break;
137
+ case 'accept':
138
+ await cmdAccept(args[0], args[1], args[2], args[3], args.slice(4).join(' ') || undefined);
139
+ break;
140
+
141
+ // Messaging (relay)
142
+ case 'send':
143
+ await cmdSend(args[0], args[1], args[2]);
144
+ break;
145
+ case 'inbox':
146
+ await cmdInbox(args);
147
+ break;
148
+ case 'ack':
149
+ await cmdAck(args);
150
+ break;
151
+ case 'poll':
152
+ await cmdPoll();
153
+ break;
154
+ case 'connect':
155
+ await cmdConnect();
156
+ break;
157
+ case 'request-service':
158
+ await cmdRequestService(args[0], args[1], args[2], args[3]);
159
+ break;
160
+ case 'research-respond':
161
+ await cmdResearchRespond(args[0]);
162
+ break;
163
+ case 'research-queue':
164
+ await cmdResearchQueue();
165
+ break;
166
+ case 'service-queue':
167
+ await cmdServiceQueue();
168
+ break;
169
+ case 'respond-service':
170
+ await cmdRespondService(args[0], args[1], args[2], args.slice(3).join(' '));
171
+ break;
172
+
173
+ // X Account Verification
174
+ case 'x-verify-start':
175
+ await cmdXVerifyStart(args[0]);
176
+ break;
177
+ case 'x-verify-complete':
178
+ await cmdXVerifyComplete(args[0]);
179
+ break;
180
+ case 'x-verifications':
181
+ await cmdXVerifications();
182
+ break;
183
+ case 'x-lookup':
184
+ await cmdXLookup(args[0]);
185
+ break;
186
+
187
+ // X Engagement Service
188
+ case 'x-engagement-queue':
189
+ await cmdXEngagementQueue();
190
+ break;
191
+ case 'x-engagement-fulfill':
192
+ await cmdXEngagementFulfill(args[0], args[1]);
193
+ break;
194
+
195
+ // Baemail Service
196
+ case 'baemail-setup':
197
+ await cmdBaemailSetup(args[0], args[1], args[2], args[3]);
198
+ break;
199
+ case 'baemail-config':
200
+ await cmdBaemailConfig();
201
+ break;
202
+ case 'baemail-block':
203
+ await cmdBaemailBlock(args[0]);
204
+ break;
205
+ case 'baemail-unblock':
206
+ await cmdBaemailUnblock(args[0]);
207
+ break;
208
+ case 'baemail-log':
209
+ await cmdBaemailLog(args[0]);
210
+ break;
211
+ case 'baemail-refund':
212
+ await cmdBaemailRefund(args[0]);
213
+ break;
214
+
215
+ default:
216
+ fail(
217
+ `Unknown command: ${command || '(none)'}. Commands: setup, identity, address, balance, import, refund, ` +
218
+ `register, unregister, services, advertise, readvertise, remove, discover, pay, verify, accept, ` +
219
+ `send, inbox, ack, poll, connect, request-service, research-queue, research-respond, ` +
220
+ `service-queue, respond-service, x-verify-start, x-verify-complete, x-verifications, x-lookup, ` +
221
+ `x-engagement-queue, x-engagement-fulfill, baemail-setup, baemail-config, baemail-block, ` +
222
+ `baemail-unblock, baemail-log, baemail-refund`
223
+ );
224
+ }
225
+ } catch (err: any) {
226
+ fail(err.message || String(err));
227
+ }
228
+ }
229
+
230
+ main();
package/src/cli.ts ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * BSV Overlay CLI - Bootstrap Entry Point
4
+ *
5
+ * Sets environment variables before importing the main CLI module
6
+ * to suppress dotenv v17 verbose logging.
7
+ */
8
+
9
+ // Must be set before any imports that might load dotenv
10
+ process.env.DOTENV_CONFIG_QUIET = 'true';
11
+
12
+ // Dynamic import to ensure env var is set first
13
+ import('./cli-main.js');
14
+
15
+ // Before importing the library
16
+ (globalThis as any).window = { fetch: globalThis.fetch };
@@ -0,0 +1,246 @@
1
+ # @a2a-bsv/core
2
+
3
+ BSV agent-to-agent payment library. Wraps [`@bsv/sdk`](https://github.com/bsv-blockchain/ts-sdk) and [`@bsv/wallet-toolbox`](https://github.com/bsv-blockchain/wallet-toolbox) to provide exactly the operations AI agents need to pay each other on the BSV blockchain.
4
+
5
+ ## Features
6
+
7
+ - **BRC-100 compliant wallet** backed by SQLite for local persistence
8
+ - **BRC-29 payments** — privacy-preserving key derivation, no address reuse
9
+ - **SPV verification** via Atomic BEEF transaction format
10
+ - **noSend workflow** — sender builds the transaction, recipient verifies and broadcasts
11
+ - **Clean API** — minimal surface area designed for automated agent use
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @a2a-bsv/core
17
+ ```
18
+
19
+ > Requires Node.js 18+ and SQLite3 (native dependency via `@bsv/wallet-toolbox`).
20
+
21
+ ## Quick Start
22
+
23
+ ```typescript
24
+ import { BSVAgentWallet } from '@a2a-bsv/core';
25
+
26
+ // 1. Create wallets for two agents
27
+ const agentA = await BSVAgentWallet.load({
28
+ network: 'testnet',
29
+ storageDir: './wallet-agent-a',
30
+ });
31
+
32
+ const agentB = await BSVAgentWallet.load({
33
+ network: 'testnet',
34
+ storageDir: './wallet-agent-b',
35
+ });
36
+
37
+ const agentBKey = await agentB.getIdentityKey();
38
+ console.log('Agent B identity:', agentBKey);
39
+
40
+ // 2. Agent A builds a payment to Agent B (requires funded wallet)
41
+ const payment = await agentA.createPayment({
42
+ to: agentBKey,
43
+ satoshis: 500,
44
+ description: 'Payment for code review',
45
+ });
46
+
47
+ // 3. Agent B verifies the payment
48
+ const verification = await agentB.verifyPayment({
49
+ beef: payment.beef,
50
+ });
51
+
52
+ // 4. Agent B accepts (internalizes) the payment
53
+ if (verification.valid) {
54
+ const receipt = await agentB.acceptPayment({
55
+ beef: payment.beef,
56
+ derivationPrefix: payment.derivationPrefix,
57
+ derivationSuffix: payment.derivationSuffix,
58
+ senderIdentityKey: payment.senderIdentityKey,
59
+ description: 'Code review payment received',
60
+ });
61
+ console.log('Payment accepted:', receipt.accepted);
62
+ }
63
+
64
+ // 5. Clean up
65
+ await agentA.destroy();
66
+ await agentB.destroy();
67
+ ```
68
+
69
+ ## API
70
+
71
+ ### `BSVAgentWallet`
72
+
73
+ #### Factory Methods
74
+
75
+ | Method | Description |
76
+ |--------|-------------|
77
+ | `BSVAgentWallet.load(config)` | Create a new wallet (generates keys, creates SQLite DB) |
78
+ | `BSVAgentWallet.load(config)` | Load an existing wallet from storage |
79
+
80
+ #### `WalletConfig`
81
+
82
+ ```typescript
83
+ interface WalletConfig {
84
+ network: 'mainnet' | 'testnet';
85
+ storageDir: string; // Directory for SQLite DB and identity file
86
+ rootKeyHex?: string; // Optional: provide your own root key
87
+ taalApiKey?: string; // Optional: TAAL API key for ARC broadcasting
88
+ }
89
+ ```
90
+
91
+ #### Wallet Lifecycle
92
+
93
+ | Method | Returns | Description |
94
+ |--------|---------|-------------|
95
+ | `getIdentityKey()` | `Promise<string>` | Compressed public key (hex) — share this with other agents |
96
+ | `getBalance()` | `Promise<number>` | Balance in satoshis |
97
+ | `destroy()` | `Promise<void>` | Close DB connections, stop monitor |
98
+
99
+ #### Payments (Sender Side)
100
+
101
+ ```typescript
102
+ const payment = await wallet.createPayment({
103
+ to: recipientPublicKey, // Compressed hex pubkey (required)
104
+ satoshis: 500, // Amount in satoshis
105
+ description: 'Agent task payment',
106
+ });
107
+ ```
108
+
109
+ Returns a `PaymentResult`:
110
+
111
+ ```typescript
112
+ interface PaymentResult {
113
+ beef: string; // Base64-encoded Atomic BEEF
114
+ txid: string; // Transaction ID
115
+ satoshis: number; // Amount paid
116
+ derivationPrefix: string; // BRC-29 derivation info (send to recipient)
117
+ derivationSuffix: string; // BRC-29 derivation info (send to recipient)
118
+ senderIdentityKey: string; // Sender's identity key (send to recipient)
119
+ }
120
+ ```
121
+
122
+ > **Important:** The `derivationPrefix`, `derivationSuffix`, and `senderIdentityKey` MUST be transmitted to the recipient alongside the `beef`. These are needed for the recipient to claim the payment.
123
+
124
+ #### Payments (Receiver Side)
125
+
126
+ **Verify** (includes SPV verification):
127
+
128
+ ```typescript
129
+ const result = await wallet.verifyPayment({
130
+ beef: payment.beef,
131
+ expectedSender: senderKey, // Optional
132
+ });
133
+ // result.valid, result.txid, result.errors
134
+ ```
135
+
136
+ **Accept** (internalize into wallet):
137
+
138
+ ```typescript
139
+ const receipt = await wallet.acceptPayment({
140
+ beef: payment.beef,
141
+ vout: 0, // Output index (default: 0)
142
+ derivationPrefix: payment.derivationPrefix,
143
+ derivationSuffix: payment.derivationSuffix,
144
+ senderIdentityKey: payment.senderIdentityKey,
145
+ description: 'Payment received',
146
+ });
147
+ // receipt.accepted
148
+ ```
149
+
150
+ #### Advanced Access
151
+
152
+ ```typescript
153
+ // Access underlying wallet-toolbox SetupWallet for advanced operations
154
+ const setup = wallet.getSetup();
155
+ // setup.wallet — the BRC-100 Wallet instance
156
+ // setup.rootKey — the root PrivateKey
157
+ // setup.services — network Services
158
+ // setup.storage — WalletStorageManager
159
+ ```
160
+
161
+ ## Architecture
162
+
163
+ ```
164
+ BSVAgentWallet
165
+ ├── Wallet (BRC-100) — from @bsv/wallet-toolbox
166
+ │ ├── CachedKeyDeriver — BRC-42 key derivation
167
+ │ ├── WalletStorageManager — manages storage providers
168
+ │ │ └── StorageKnex — SQLite via knex
169
+ │ ├── Services — ARC broadcasting, chain tracking
170
+ │ └── Monitor — background task processing
171
+ └── ScriptTemplateBRC29 — BRC-29 payment scripts
172
+ ```
173
+
174
+ ### Payment Flow
175
+
176
+ ```
177
+ Agent A (Payer) Agent B (Merchant)
178
+ ───────────────── ──────────────────
179
+ 1. createPayment(to=B, sat=500)
180
+ → builds BRC-29 tx (noSend)
181
+ → returns BEEF + derivation info
182
+ ──→
183
+ 2. verifyPayment(beef)
184
+ → structural checks
185
+ → returns valid/errors
186
+
187
+ 3. acceptPayment(beef, derivation)
188
+ → wallet.internalizeAction()
189
+ → SPV verification
190
+ → broadcasts to network
191
+ → output added to wallet
192
+ ```
193
+
194
+ ## Key Concepts
195
+
196
+ ### BRC-29 Key Derivation
197
+ Each payment uses unique derivation prefixes and suffixes to generate a one-time key. This means:
198
+ - No address reuse (privacy preserving)
199
+ - Recipient needs the derivation info to claim the payment
200
+ - The sender's identity key is also needed for key derivation
201
+
202
+ ### Atomic BEEF
203
+ Transactions are packaged as Atomic BEEF (Background Evaluation Extended Format), which includes:
204
+ - The payment transaction itself
205
+ - All ancestor transactions needed for SPV verification
206
+ - Merkle proofs linking to block headers
207
+
208
+ This allows the recipient to verify the payment without trusting any third party.
209
+
210
+ ### noSend Workflow
211
+ The sender builds and signs the transaction but does NOT broadcast it. Instead:
212
+ 1. The signed transaction (as Atomic BEEF) is sent directly to the recipient
213
+ 2. The recipient verifies it via SPV
214
+ 3. The recipient internalizes it (claiming the output and broadcasting)
215
+
216
+ This is the BRC-100 Direct Instant Payments (DIP) pattern.
217
+
218
+ ## Storage
219
+
220
+ Each wallet creates:
221
+ - `wallet-identity.json` — Contains the root key hex, identity key, and network
222
+ - `a2a_agent_wallet.sqlite` — SQLite database with all wallet state
223
+
224
+ > ⚠️ **Security:** The `wallet-identity.json` file contains the root private key. Guard it carefully in production.
225
+
226
+ ## Known Issues
227
+
228
+ - **Wallet-toolbox bug:** `Setup.createWalletSQLite` has an internal `randomBytesHex` stub that throws. This library works around it by constructing wallet components manually.
229
+ - **Funding required:** `createPayment()` requires the wallet to have spendable UTXOs. On testnet, use the [WitnessOnChain faucet](https://witnessonchain.com/faucet/tbsv) to fund your wallet. Track transactions on [WhatsonChain testnet](https://test.whatsonchain.com/) or [WhatsonChain mainnet](https://whatsonchain.com/).
230
+
231
+ ## Development
232
+
233
+ ```bash
234
+ # Type check
235
+ npm run check
236
+
237
+ # Build
238
+ npm run build
239
+
240
+ # Test
241
+ npm test
242
+ ```
243
+
244
+ ## License
245
+
246
+ MIT
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @a2a-bsv/core — Configuration defaults and helpers.
3
+ */
4
+
5
+ import type { WalletConfig } from './types.js';
6
+
7
+ /** Map our 'mainnet'/'testnet' to the wallet-toolbox's 'main'/'test' chain type. */
8
+ export type Chain = 'main' | 'test';
9
+
10
+ export function toChain(network: WalletConfig['network']): Chain {
11
+ return network === 'mainnet' ? 'main' : 'test';
12
+ }
13
+
14
+ /** Default TAAL API keys from the wallet-toolbox examples. */
15
+ export const DEFAULT_TAAL_API_KEYS: Record<Chain, string> = {
16
+ main: 'mainnet_9596de07e92300c6287e4393594ae39c',
17
+ test: 'testnet_0e6cf72133b43ea2d7861da2a38684e3',
18
+ };
19
+
20
+ /** Default SQLite database name. */
21
+ export const DEFAULT_DB_NAME = 'a2a_agent_wallet';