@onecraft/wallet 0.0.0-stage → 0.1.145

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 (248) hide show
  1. package/.claude-plugin/marketplace.json +20 -0
  2. package/.openclaw/AGENTS.md +100 -0
  3. package/.openclaw/extensions/agent-wallet/README.md +195 -0
  4. package/.openclaw/extensions/agent-wallet/dist/index.js +2198 -0
  5. package/.openclaw/extensions/agent-wallet/index.ts +2198 -0
  6. package/.openclaw/extensions/agent-wallet/openclaw.plugin.json +251 -0
  7. package/.openclaw/extensions/agent-wallet/package.json +49 -0
  8. package/.openclaw/extensions/agent-wallet/skills/cards/SKILL.md +211 -0
  9. package/.openclaw/extensions/agent-wallet/skills/wallet-operator/SKILL.md +30 -0
  10. package/CHANGELOG.md +1232 -0
  11. package/LICENSE +104 -0
  12. package/README.md +193 -2
  13. package/VERSION +1 -0
  14. package/agent-wallet/.env.example +63 -0
  15. package/agent-wallet/AGENTS.md +130 -0
  16. package/agent-wallet/CARD_VAULT.md +640 -0
  17. package/agent-wallet/README.md +615 -0
  18. package/agent-wallet/UPGRADE_COMPATIBILITY.md +66 -0
  19. package/agent-wallet/agent_wallet/__init__.py +16 -0
  20. package/agent-wallet/agent_wallet/approval.py +165 -0
  21. package/agent-wallet/agent_wallet/autonomous_permissions.py +281 -0
  22. package/agent-wallet/agent_wallet/autonomous_policy.py +305 -0
  23. package/agent-wallet/agent_wallet/autonomous_session.py +236 -0
  24. package/agent-wallet/agent_wallet/boot_key_migration.py +155 -0
  25. package/agent-wallet/agent_wallet/boot_key_recovery.py +57 -0
  26. package/agent-wallet/agent_wallet/bootstrap.py +194 -0
  27. package/agent-wallet/agent_wallet/card_catalog.py +243 -0
  28. package/agent-wallet/agent_wallet/card_runtime_secrets.py +108 -0
  29. package/agent-wallet/agent_wallet/card_vault.py +331 -0
  30. package/agent-wallet/agent_wallet/card_vault_cli.py +174 -0
  31. package/agent-wallet/agent_wallet/card_vault_import.py +65 -0
  32. package/agent-wallet/agent_wallet/card_vault_keychain.py +239 -0
  33. package/agent-wallet/agent_wallet/config.py +719 -0
  34. package/agent-wallet/agent_wallet/connector_cli.py +198 -0
  35. package/agent-wallet/agent_wallet/connectors/__init__.py +28 -0
  36. package/agent-wallet/agent_wallet/connectors/catalog.py +68 -0
  37. package/agent-wallet/agent_wallet/connectors/client.py +308 -0
  38. package/agent-wallet/agent_wallet/connectors/intent_policy.py +243 -0
  39. package/agent-wallet/agent_wallet/connectors/manifest.py +192 -0
  40. package/agent-wallet/agent_wallet/connectors/registry.py +341 -0
  41. package/agent-wallet/agent_wallet/encrypted_storage.py +314 -0
  42. package/agent-wallet/agent_wallet/evm_user_wallets.py +910 -0
  43. package/agent-wallet/agent_wallet/exceptions.py +10 -0
  44. package/agent-wallet/agent_wallet/file_ops.py +34 -0
  45. package/agent-wallet/agent_wallet/http_client.py +25 -0
  46. package/agent-wallet/agent_wallet/kernel_browser.py +479 -0
  47. package/agent-wallet/agent_wallet/kernel_cli.py +57 -0
  48. package/agent-wallet/agent_wallet/kernel_gateway.py +95 -0
  49. package/agent-wallet/agent_wallet/keystore.py +503 -0
  50. package/agent-wallet/agent_wallet/laso_card_vault.py +246 -0
  51. package/agent-wallet/agent_wallet/models.py +66 -0
  52. package/agent-wallet/agent_wallet/morpho_monitor.py +298 -0
  53. package/agent-wallet/agent_wallet/nonce_registry.py +59 -0
  54. package/agent-wallet/agent_wallet/openclaw_adapter.py +9129 -0
  55. package/agent-wallet/agent_wallet/openclaw_cli.py +658 -0
  56. package/agent-wallet/agent_wallet/openclaw_runtime.py +194 -0
  57. package/agent-wallet/agent_wallet/plugin_bundle.py +44 -0
  58. package/agent-wallet/agent_wallet/providers/__init__.py +1 -0
  59. package/agent-wallet/agent_wallet/providers/bags.py +202 -0
  60. package/agent-wallet/agent_wallet/providers/dexscreener.py +147 -0
  61. package/agent-wallet/agent_wallet/providers/evm_activity.py +257 -0
  62. package/agent-wallet/agent_wallet/providers/evm_portfolio.py +459 -0
  63. package/agent-wallet/agent_wallet/providers/imd.py +720 -0
  64. package/agent-wallet/agent_wallet/providers/jupiter.py +519 -0
  65. package/agent-wallet/agent_wallet/providers/kamino.py +404 -0
  66. package/agent-wallet/agent_wallet/providers/lifi.py +302 -0
  67. package/agent-wallet/agent_wallet/providers/solana_rpc.py +447 -0
  68. package/agent-wallet/agent_wallet/providers/tokenized_stocks.py +189 -0
  69. package/agent-wallet/agent_wallet/providers/wdk_evm_local.py +346 -0
  70. package/agent-wallet/agent_wallet/providers/x402.py +1972 -0
  71. package/agent-wallet/agent_wallet/sealed_keys.py +118 -0
  72. package/agent-wallet/agent_wallet/solana_stake.py +103 -0
  73. package/agent-wallet/agent_wallet/solana_tx.py +93 -0
  74. package/agent-wallet/agent_wallet/spending_limits.py +119 -0
  75. package/agent-wallet/agent_wallet/telemetry.py +481 -0
  76. package/agent-wallet/agent_wallet/transaction_policy.py +573 -0
  77. package/agent-wallet/agent_wallet/update_check.py +190 -0
  78. package/agent-wallet/agent_wallet/user_wallets.py +573 -0
  79. package/agent-wallet/agent_wallet/validation.py +31 -0
  80. package/agent-wallet/agent_wallet/vault_executor.py +456 -0
  81. package/agent-wallet/agent_wallet/wallet_layer/__init__.py +1 -0
  82. package/agent-wallet/agent_wallet/wallet_layer/base.py +1204 -0
  83. package/agent-wallet/agent_wallet/wallet_layer/base58.py +44 -0
  84. package/agent-wallet/agent_wallet/wallet_layer/factory.py +117 -0
  85. package/agent-wallet/agent_wallet/wallet_layer/solana.py +5246 -0
  86. package/agent-wallet/agent_wallet/wallet_layer/wdk_evm.py +2705 -0
  87. package/agent-wallet/examples/bootstrap_wallet.py +21 -0
  88. package/agent-wallet/examples/openclaw_runtime_onboarding.py +28 -0
  89. package/agent-wallet/examples/openclaw_user_wallet_example.py +31 -0
  90. package/agent-wallet/examples/openclaw_wallet_adapter_example.py +33 -0
  91. package/agent-wallet/openclaw.plugin.json +118 -0
  92. package/agent-wallet/pyproject.toml +36 -0
  93. package/agent-wallet/scripts/bootstrap_openclaw_evm.py +312 -0
  94. package/agent-wallet/scripts/build_release_bundle.py +210 -0
  95. package/agent-wallet/scripts/finalize_openclaw_local_wallet_config.py +121 -0
  96. package/agent-wallet/scripts/install_agent_wallet.py +1357 -0
  97. package/agent-wallet/scripts/install_openclaw_local_config.py +421 -0
  98. package/agent-wallet/scripts/install_openclaw_sealed_keys.py +117 -0
  99. package/agent-wallet/scripts/manage_openclaw_evm_wallet.py +333 -0
  100. package/agent-wallet/scripts/security_utils.py +37 -0
  101. package/agent-wallet/scripts/setup_evm_wallet.sh +140 -0
  102. package/agent-wallet/scripts/switch_openclaw_wallet_network.py +109 -0
  103. package/agent-wallet/skills/wallet-operator/SKILL.md +157 -0
  104. package/bin/lib/boot-key.mjs +184 -0
  105. package/bin/lib/evm-daemon.mjs +389 -0
  106. package/bin/lib/host-detection.mjs +259 -0
  107. package/bin/lib/integrations.mjs +578 -0
  108. package/bin/lib/release-python.mjs +9 -0
  109. package/bin/lib/update-transaction.mjs +235 -0
  110. package/bin/openclaw-agent-wallet.mjs +3354 -0
  111. package/claude-code/plugins/agent-wallet/.claude-plugin/plugin.json +19 -0
  112. package/claude-code/plugins/agent-wallet/.mcp.json +14 -0
  113. package/claude-code/plugins/agent-wallet/AGENTLAYER_AGENT_GUIDE.md +282 -0
  114. package/claude-code/plugins/agent-wallet/README.md +134 -0
  115. package/claude-code/plugins/agent-wallet/commands/agentlayer-autonomous-approve.md +39 -0
  116. package/claude-code/plugins/agent-wallet/commands/agentlayer-autonomous-revoke.md +17 -0
  117. package/claude-code/plugins/agent-wallet/commands/cards.md +129 -0
  118. package/claude-code/plugins/agent-wallet/commands/guide.md +40 -0
  119. package/claude-code/plugins/agent-wallet/commands/imd.md +125 -0
  120. package/claude-code/plugins/agent-wallet/commands/wallet-base.md +60 -0
  121. package/claude-code/plugins/agent-wallet/commands/wallet-ethereum.md +37 -0
  122. package/claude-code/plugins/agent-wallet/commands/wallet-evm.md +39 -0
  123. package/claude-code/plugins/agent-wallet/commands/wallet-setup.md +25 -0
  124. package/claude-code/plugins/agent-wallet/commands/wallet-sol.md +51 -0
  125. package/claude-code/plugins/agent-wallet/commands/wallet-statusline.md +34 -0
  126. package/claude-code/plugins/agent-wallet/commands/x402.md +121 -0
  127. package/claude-code/plugins/agent-wallet/commands/yield.md +62 -0
  128. package/claude-code/plugins/agent-wallet/hooks/hooks.json +16 -0
  129. package/claude-code/plugins/agent-wallet/scripts/bootstrap_backend.sh +136 -0
  130. package/claude-code/plugins/agent-wallet/scripts/enable_statusline.py +52 -0
  131. package/claude-code/plugins/agent-wallet/scripts/resolve_wallet_addresses.py +69 -0
  132. package/claude-code/plugins/agent-wallet/scripts/run_mcp.sh +66 -0
  133. package/claude-code/plugins/agent-wallet/scripts/wallet_statusline.py +130 -0
  134. package/claude-code/plugins/agent-wallet/scripts/wallet_statusline_setup.sh +40 -0
  135. package/claude-code/plugins/agent-wallet/skills/wallet-operator/SKILL.md +21 -0
  136. package/codex/plugins/agent-wallet/.codex-plugin/plugin.json +37 -0
  137. package/codex/plugins/agent-wallet/.mcp.json +15 -0
  138. package/codex/plugins/agent-wallet/README.md +158 -0
  139. package/codex/plugins/agent-wallet/scripts/run_mcp.sh +47 -0
  140. package/codex/plugins/agent-wallet/server.py +1797 -0
  141. package/codex/plugins/agent-wallet/skills/cards/SKILL.md +225 -0
  142. package/codex/plugins/agent-wallet/skills/imd/SKILL.md +145 -0
  143. package/codex/plugins/agent-wallet/skills/wallet-base/SKILL.md +56 -0
  144. package/codex/plugins/agent-wallet/skills/wallet-operator/SKILL.md +85 -0
  145. package/codex/plugins/agent-wallet/skills/wallet-sol/SKILL.md +29 -0
  146. package/codex/plugins/agent-wallet/skills/x402/SKILL.md +159 -0
  147. package/codex/plugins/agent-wallet/skills/yield/SKILL.md +65 -0
  148. package/connectors/AGENTS.md +37 -0
  149. package/connectors/DEVELOPER_GUIDE.md +131 -0
  150. package/connectors/README.md +139 -0
  151. package/connectors/READ_ONLY_BETA.md +54 -0
  152. package/connectors/RELEASING.md +48 -0
  153. package/connectors/conformance/README.md +31 -0
  154. package/connectors/conformance/package.json +54 -0
  155. package/connectors/conformance/scripts/sync-license.mjs +3 -0
  156. package/connectors/conformance/scripts/sync-spec.mjs +16 -0
  157. package/connectors/conformance/src/cli.ts +43 -0
  158. package/connectors/conformance/src/index.ts +7 -0
  159. package/connectors/conformance/src/runner.ts +314 -0
  160. package/connectors/conformance/src/types.ts +27 -0
  161. package/connectors/conformance/test/fixtures/invalid-response-identity.json +14 -0
  162. package/connectors/conformance/test/fixtures/missing-tool-fixture.json +4 -0
  163. package/connectors/conformance/test/runner.test.mjs +151 -0
  164. package/connectors/conformance/tsconfig.json +17 -0
  165. package/connectors/examples/reference-crypto-data/Dockerfile +21 -0
  166. package/connectors/examples/reference-crypto-data/README.md +51 -0
  167. package/connectors/examples/reference-crypto-data/conformance.json +11 -0
  168. package/connectors/examples/reference-crypto-data/connector.json +95 -0
  169. package/connectors/examples/reference-crypto-data/package.json +21 -0
  170. package/connectors/examples/reference-crypto-data/railway.toml +9 -0
  171. package/connectors/examples/reference-crypto-data/src/connector.ts +137 -0
  172. package/connectors/examples/reference-crypto-data/src/server.ts +13 -0
  173. package/connectors/examples/reference-crypto-data/test/connector.test.mjs +97 -0
  174. package/connectors/examples/reference-crypto-data/tsconfig.json +17 -0
  175. package/connectors/package-lock.json +561 -0
  176. package/connectors/package.json +19 -0
  177. package/connectors/scripts/smoke-packed-packages.mjs +121 -0
  178. package/connectors/sdk-typescript/README.md +47 -0
  179. package/connectors/sdk-typescript/package.json +49 -0
  180. package/connectors/sdk-typescript/scripts/sync-license.mjs +3 -0
  181. package/connectors/sdk-typescript/src/connector.ts +204 -0
  182. package/connectors/sdk-typescript/src/errors.ts +11 -0
  183. package/connectors/sdk-typescript/src/http.ts +116 -0
  184. package/connectors/sdk-typescript/src/index.ts +26 -0
  185. package/connectors/sdk-typescript/src/types.ts +101 -0
  186. package/connectors/sdk-typescript/test/sdk.test.mjs +181 -0
  187. package/connectors/sdk-typescript/tsconfig.json +21 -0
  188. package/connectors/spec/connector-manifest.schema.json +340 -0
  189. package/connectors/spec/connector-protocol.md +159 -0
  190. package/connectors/spec/transaction-intent.schema.json +281 -0
  191. package/connectors/templates/read-only/.env.example +1 -0
  192. package/connectors/templates/read-only/Dockerfile +11 -0
  193. package/connectors/templates/read-only/README.md +33 -0
  194. package/connectors/templates/read-only/conformance.json +11 -0
  195. package/connectors/templates/read-only/connector.json +64 -0
  196. package/connectors/templates/read-only/package.json +21 -0
  197. package/connectors/templates/read-only/railway.toml +9 -0
  198. package/connectors/templates/read-only/src/connector.ts +61 -0
  199. package/connectors/templates/read-only/src/server.ts +14 -0
  200. package/connectors/templates/read-only/test/connector.test.mjs +62 -0
  201. package/connectors/templates/read-only/tsconfig.json +17 -0
  202. package/cursor/plugins/agent-wallet/.cursor-plugin/plugin.json +14 -0
  203. package/cursor/plugins/agent-wallet/README.md +62 -0
  204. package/cursor/plugins/agent-wallet/mcp.json +16 -0
  205. package/cursor/plugins/agent-wallet/scripts/run_mcp.sh +33 -0
  206. package/cursor/plugins/agent-wallet/server.py +33 -0
  207. package/cursor/plugins/agent-wallet/skills/cards/SKILL.md +210 -0
  208. package/cursor/plugins/agent-wallet/skills/wallet-base/SKILL.md +56 -0
  209. package/cursor/plugins/agent-wallet/skills/wallet-operator/SKILL.md +23 -0
  210. package/cursor/plugins/agent-wallet/skills/wallet-sol/SKILL.md +29 -0
  211. package/cursor/plugins/agent-wallet/skills/x402/SKILL.md +130 -0
  212. package/hermes/plugins/agent_wallet/README.md +54 -0
  213. package/hermes/plugins/agent_wallet/__init__.py +55 -0
  214. package/hermes/plugins/agent_wallet/plugin.yaml +9 -0
  215. package/hermes/plugins/agent_wallet/schemas.py +211 -0
  216. package/hermes/plugins/agent_wallet/tools.py +622 -0
  217. package/install-from-github.sh +139 -0
  218. package/integrations/hedera/treasury-guard/README.md +92 -0
  219. package/integrations/hedera/treasury-guard/examples/treasury-policy.example.json +9 -0
  220. package/integrations/hedera/treasury-guard/package-lock.json +880 -0
  221. package/integrations/hedera/treasury-guard/package.json +8 -0
  222. package/integrations/hedera/treasury-guard/skills/onecraft-hedera-treasury/SKILL.md +22 -0
  223. package/integrations/hedera/treasury-guard/src/hedera-mirror-client.mjs +106 -0
  224. package/integrations/hedera/treasury-guard/src/hedera-signer.mjs +120 -0
  225. package/integrations/hedera/treasury-guard/src/treasury-cli.mjs +177 -0
  226. package/integrations/hedera/treasury-guard/src/treasury-policy.mjs +155 -0
  227. package/mcp/README.md +39 -0
  228. package/mcp/scripts/run_mcp.sh +37 -0
  229. package/mcp/server.py +33 -0
  230. package/package.json +106 -4
  231. package/scripts/check_release_version.mjs +72 -0
  232. package/scripts/version_targets.mjs +60 -0
  233. package/setup.sh +87 -0
  234. package/wdk-evm-wallet/.env.example +38 -0
  235. package/wdk-evm-wallet/README.md +254 -0
  236. package/wdk-evm-wallet/bootstrap.sh +8 -0
  237. package/wdk-evm-wallet/package-lock.json +2359 -0
  238. package/wdk-evm-wallet/package.json +43 -0
  239. package/wdk-evm-wallet/run-local.sh +12 -0
  240. package/wdk-evm-wallet/src/config.js +461 -0
  241. package/wdk-evm-wallet/src/imd.js +231 -0
  242. package/wdk-evm-wallet/src/json.js +35 -0
  243. package/wdk-evm-wallet/src/local_vault.js +407 -0
  244. package/wdk-evm-wallet/src/network_state.js +96 -0
  245. package/wdk-evm-wallet/src/pending_transactions.js +148 -0
  246. package/wdk-evm-wallet/src/server.js +849 -0
  247. package/wdk-evm-wallet/src/shutdown.js +63 -0
  248. package/wdk-evm-wallet/src/wdk_evm_wallet.js +10036 -0
@@ -0,0 +1,198 @@
1
+ """JSON CLI for installing and managing optional OneCraft connectors."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import json
7
+ import sys
8
+ from pathlib import Path
9
+ from typing import Any
10
+
11
+ from agent_wallet.connectors.catalog import enabled_connector_tools
12
+ from agent_wallet.connectors.manifest import ConnectorManifestError, validate_connector_manifest
13
+ from agent_wallet.connectors.registry import ConnectorRegistry, ConnectorRegistryError
14
+
15
+
16
+ MAX_MANIFEST_BYTES = 1024 * 1024
17
+
18
+
19
+ def _print(payload: Any) -> None:
20
+ print(json.dumps(payload, indent=2, sort_keys=True))
21
+
22
+
23
+ def _load_manifest_file(value: str) -> tuple[dict[str, Any], str]:
24
+ path = Path(value).expanduser().resolve()
25
+ try:
26
+ size = path.stat().st_size
27
+ except OSError as exc:
28
+ raise ConnectorRegistryError(f"Connector manifest cannot be read: {path}: {exc}") from exc
29
+ if size > MAX_MANIFEST_BYTES:
30
+ raise ConnectorRegistryError(
31
+ f"Connector manifest exceeds the {MAX_MANIFEST_BYTES}-byte limit."
32
+ )
33
+ try:
34
+ payload = json.loads(path.read_text(encoding="utf-8"))
35
+ except (OSError, UnicodeDecodeError, json.JSONDecodeError) as exc:
36
+ raise ConnectorRegistryError(f"Connector manifest is invalid JSON: {path}: {exc}") from exc
37
+ if not isinstance(payload, dict):
38
+ raise ConnectorRegistryError("Connector manifest root must be an object.")
39
+ return payload, str(path)
40
+
41
+
42
+ def _permission_review(manifest_payload: dict[str, Any]) -> dict[str, Any]:
43
+ manifest = validate_connector_manifest(manifest_payload)
44
+ permissions = manifest["permissions"]
45
+ warnings = ["Connector responses are untrusted external data."]
46
+ if permissions["wallet_address"]:
47
+ warnings.append("The connector may receive the active public wallet address.")
48
+ return {
49
+ "id": manifest["id"],
50
+ "version": manifest["version"],
51
+ "publisher": manifest["publisher"],
52
+ "trust": manifest["trust"],
53
+ "endpoint": manifest["transport"]["url"],
54
+ "permissions": permissions,
55
+ "tools": [tool["name"] for tool in manifest["tools"]],
56
+ "warnings": warnings,
57
+ }
58
+
59
+
60
+ def _build_parser() -> argparse.ArgumentParser:
61
+ parser = argparse.ArgumentParser(prog="wallet connectors")
62
+ subparsers = parser.add_subparsers(dest="command", required=True)
63
+
64
+ subparsers.add_parser("list", help="List locally installed connectors.")
65
+ subparsers.add_parser("tools", help="List enabled read-only connector tools for host registration.")
66
+
67
+ info = subparsers.add_parser("info", help="Show one installed connector.")
68
+ info.add_argument("connector_id")
69
+
70
+ inspect = subparsers.add_parser("inspect", help="Review a manifest before installation.")
71
+ inspect.add_argument("manifest", help="Path to a connector manifest JSON file.")
72
+
73
+ install = subparsers.add_parser("install", help="Install an immutable connector manifest.")
74
+ install.add_argument("manifest", help="Path to a connector manifest JSON file.")
75
+ install.add_argument("--enable", action="store_true", help="Enable this exact version.")
76
+ install.add_argument("--yes", action="store_true", help="Confirm permissions when enabling.")
77
+
78
+ enable = subparsers.add_parser("enable", help="Enable an installed connector version.")
79
+ enable.add_argument("connector_id")
80
+ enable.add_argument("--version", default=None)
81
+ enable.add_argument("--yes", action="store_true", help="Confirm the installed permissions.")
82
+
83
+ disable = subparsers.add_parser("disable", help="Disable an installed connector.")
84
+ disable.add_argument("connector_id")
85
+
86
+ remove = subparsers.add_parser("remove", help="Remove a disabled connector version.")
87
+ remove.add_argument("connector_id")
88
+ remove.add_argument("--version", default=None)
89
+ remove.add_argument("--yes", action="store_true", help="Confirm removal.")
90
+
91
+ subparsers.add_parser("doctor", help="Validate the registry and all installed manifests.")
92
+ return parser
93
+
94
+
95
+ def _doctor(registry: ConnectorRegistry) -> dict[str, Any]:
96
+ entries = registry.list()
97
+ checks: list[dict[str, Any]] = []
98
+ ok = True
99
+ for entry in entries:
100
+ connector_id = str(entry["id"])
101
+ for version in entry["installed_versions"]:
102
+ try:
103
+ registry.load_manifest(connector_id, str(version))
104
+ checks.append(
105
+ {
106
+ "connector_id": connector_id,
107
+ "version": version,
108
+ "ok": True,
109
+ }
110
+ )
111
+ except (ConnectorManifestError, ConnectorRegistryError) as exc:
112
+ ok = False
113
+ checks.append(
114
+ {
115
+ "connector_id": connector_id,
116
+ "version": version,
117
+ "ok": False,
118
+ "error": str(exc),
119
+ }
120
+ )
121
+ return {
122
+ "ok": ok,
123
+ "registry_path": str(registry.registry_path),
124
+ "connector_count": len(entries),
125
+ "checks": checks,
126
+ }
127
+
128
+
129
+ def main(argv: list[str] | None = None) -> int:
130
+ parser = _build_parser()
131
+ args = parser.parse_args(argv)
132
+ registry = ConnectorRegistry()
133
+ try:
134
+ if args.command == "list":
135
+ _print({"ok": True, "connectors": registry.list()})
136
+ return 0
137
+ if args.command == "tools":
138
+ _print({"ok": True, "tools": enabled_connector_tools(registry, include_write=False)})
139
+ return 0
140
+ if args.command == "info":
141
+ _print({"ok": True, "connector": registry.describe(args.connector_id)})
142
+ return 0
143
+ if args.command == "inspect":
144
+ manifest, source = _load_manifest_file(args.manifest)
145
+ _print({"ok": True, "source": source, "review": _permission_review(manifest)})
146
+ return 0
147
+ if args.command == "install":
148
+ manifest, source = _load_manifest_file(args.manifest)
149
+ review = _permission_review(manifest)
150
+ if args.enable and not args.yes:
151
+ raise ConnectorRegistryError(
152
+ "install --enable requires --yes after reviewing connector permissions "
153
+ "with `wallet connectors inspect <manifest>`."
154
+ )
155
+ connector = registry.install(manifest, source=source, enable=bool(args.enable))
156
+ _print({"ok": True, "connector": connector, "review": review})
157
+ return 0
158
+ if args.command == "enable":
159
+ if not args.yes:
160
+ raise ConnectorRegistryError(
161
+ "enable requires --yes after reviewing the installed connector with "
162
+ "`wallet connectors info <connector_id>`."
163
+ )
164
+ connector = registry.enable(args.connector_id, version=args.version)
165
+ _print({"ok": True, "connector": connector})
166
+ return 0
167
+ if args.command == "disable":
168
+ connector = registry.disable(args.connector_id)
169
+ _print({"ok": True, "connector": connector})
170
+ return 0
171
+ if args.command == "remove":
172
+ if not args.yes:
173
+ raise ConnectorRegistryError("remove requires --yes after the connector is disabled.")
174
+ result = registry.remove(args.connector_id, version=args.version)
175
+ _print({"ok": True, **result})
176
+ return 0
177
+ if args.command == "doctor":
178
+ result = _doctor(registry)
179
+ _print(result)
180
+ return 0 if result["ok"] else 1
181
+ raise ConnectorRegistryError(f"Unsupported connectors command: {args.command}.")
182
+ except (ConnectorManifestError, ConnectorRegistryError) as exc:
183
+ print(
184
+ json.dumps(
185
+ {
186
+ "ok": False,
187
+ "error": str(exc),
188
+ "error_type": type(exc).__name__,
189
+ },
190
+ sort_keys=True,
191
+ ),
192
+ file=sys.stderr,
193
+ )
194
+ return 2
195
+
196
+
197
+ if __name__ == "__main__":
198
+ raise SystemExit(main())
@@ -0,0 +1,28 @@
1
+ """Optional OneCraft connector contracts and local registry support."""
2
+
3
+ from agent_wallet.connectors.catalog import enabled_connector_tools, resolve_connector_tool
4
+ from agent_wallet.connectors.client import ConnectorInvocationError, ConnectorReadClient
5
+ from agent_wallet.connectors.intent_policy import (
6
+ ConnectorIntentPolicyError,
7
+ validate_evm_transaction_intent,
8
+ )
9
+ from agent_wallet.connectors.manifest import (
10
+ ConnectorManifestError,
11
+ connector_tool_name,
12
+ validate_connector_manifest,
13
+ )
14
+ from agent_wallet.connectors.registry import ConnectorRegistry, ConnectorRegistryError
15
+
16
+ __all__ = [
17
+ "ConnectorManifestError",
18
+ "ConnectorInvocationError",
19
+ "ConnectorIntentPolicyError",
20
+ "ConnectorReadClient",
21
+ "ConnectorRegistry",
22
+ "ConnectorRegistryError",
23
+ "connector_tool_name",
24
+ "enabled_connector_tools",
25
+ "resolve_connector_tool",
26
+ "validate_connector_manifest",
27
+ "validate_evm_transaction_intent",
28
+ ]
@@ -0,0 +1,68 @@
1
+ """Build the safe host-facing catalog of enabled connector tools."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from agent_wallet.connectors.manifest import connector_tool_name
8
+ from agent_wallet.connectors.registry import ConnectorRegistry, ConnectorRegistryError
9
+
10
+
11
+ def enabled_connector_tools(
12
+ registry: ConnectorRegistry | None = None,
13
+ *,
14
+ include_write: bool = False,
15
+ ) -> list[dict[str, Any]]:
16
+ """Return enabled tools, withholding writes until their policy is available."""
17
+
18
+ active_registry = registry or ConnectorRegistry()
19
+ result: list[dict[str, Any]] = []
20
+ seen: set[str] = set()
21
+ for entry in active_registry.list():
22
+ if not entry["enabled"]:
23
+ continue
24
+ connector_id = str(entry["id"])
25
+ version = str(entry["enabled_version"])
26
+ manifest = active_registry.load_manifest(connector_id, version)
27
+ for raw_tool in manifest["tools"]:
28
+ if not isinstance(raw_tool, dict):
29
+ raise ConnectorRegistryError(f"Connector tool is invalid: {connector_id}.")
30
+ read_only = raw_tool.get("read_only") is True
31
+ if not read_only and not include_write:
32
+ continue
33
+ host_name = connector_tool_name(connector_id, str(raw_tool.get("name") or ""))
34
+ if host_name in seen:
35
+ raise ConnectorRegistryError(f"Duplicate host connector tool name: {host_name}.")
36
+ seen.add(host_name)
37
+ result.append(
38
+ {
39
+ "name": host_name,
40
+ "description": (
41
+ "[External connector: untrusted read-only data] "
42
+ + str(raw_tool["description"])
43
+ ),
44
+ "input_schema": raw_tool["input_schema"],
45
+ "output_schema": raw_tool["output_schema"],
46
+ "read_only": read_only,
47
+ "risk_level": str(raw_tool["risk_level"]),
48
+ "connector_id": connector_id,
49
+ "connector_version": version,
50
+ "connector_tool": str(raw_tool["name"]),
51
+ "connector_trust": str(manifest["trust"]),
52
+ }
53
+ )
54
+ return sorted(result, key=lambda item: str(item["name"]))
55
+
56
+
57
+ def resolve_connector_tool(
58
+ host_tool_name: str,
59
+ registry: ConnectorRegistry | None = None,
60
+ *,
61
+ include_write: bool = False,
62
+ ) -> dict[str, Any]:
63
+ """Resolve one host tool through the enabled immutable catalog."""
64
+
65
+ for tool in enabled_connector_tools(registry, include_write=include_write):
66
+ if tool["name"] == host_tool_name:
67
+ return tool
68
+ raise ConnectorRegistryError(f"Enabled connector tool was not found: {host_tool_name}.")
@@ -0,0 +1,308 @@
1
+ """HTTPS client for untrusted read-only connector endpoints."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import ipaddress
6
+ import json
7
+ import socket
8
+ import uuid
9
+ from datetime import datetime, timezone
10
+ from typing import Any, Callable, Iterable
11
+ from urllib.parse import urlparse
12
+
13
+ import httpx
14
+ import httpcore
15
+ from jsonschema import Draft202012Validator, SchemaError, ValidationError
16
+
17
+ from agent_wallet.connectors.catalog import resolve_connector_tool
18
+ from agent_wallet.connectors.registry import ConnectorRegistry
19
+
20
+
21
+ MAX_CONNECTOR_RESPONSE_BYTES = 1024 * 1024
22
+ MAX_RESPONSE_LIFETIME_SECONDS = 300
23
+ RESERVED_WRITE_RESULT_KEYS = frozenset(
24
+ {
25
+ "approval_token",
26
+ "broadcast_request",
27
+ "evm_transaction_intent",
28
+ "payment_intent",
29
+ "raw_transaction",
30
+ "signed_transaction",
31
+ "signing_request",
32
+ "solana_transaction_intent",
33
+ "transaction_intent",
34
+ }
35
+ )
36
+ Resolver = Callable[[str], Iterable[str]]
37
+
38
+
39
+ class ConnectorInvocationError(RuntimeError):
40
+ """Raised when a connector request or response cannot be trusted."""
41
+
42
+
43
+ def _default_resolver(hostname: str) -> list[str]:
44
+ try:
45
+ records = socket.getaddrinfo(hostname, 443, type=socket.SOCK_STREAM)
46
+ except OSError as exc:
47
+ raise ConnectorInvocationError(f"Connector hostname could not be resolved: {hostname}.") from exc
48
+ return sorted({str(record[4][0]) for record in records})
49
+
50
+
51
+ def _validate_endpoint_url(url: str) -> str:
52
+ parsed = urlparse(url)
53
+ hostname = str(parsed.hostname or "").lower()
54
+ if parsed.scheme != "https" or not hostname or parsed.username or parsed.password:
55
+ raise ConnectorInvocationError("Connector endpoint must be public HTTPS without credentials.")
56
+ if hostname == "localhost" or hostname.endswith(".localhost") or hostname.endswith(".local"):
57
+ raise ConnectorInvocationError("Connector endpoint cannot use a local hostname.")
58
+ return hostname
59
+
60
+
61
+ def _resolve_public_addresses(hostname: str, resolver: Resolver) -> list[str]:
62
+ addresses = list(resolver(hostname))
63
+ if not addresses:
64
+ raise ConnectorInvocationError("Connector endpoint did not resolve to an address.")
65
+ for raw_address in addresses:
66
+ try:
67
+ address = ipaddress.ip_address(raw_address)
68
+ except ValueError as exc:
69
+ raise ConnectorInvocationError("Connector endpoint resolved to an invalid address.") from exc
70
+ if not address.is_global:
71
+ raise ConnectorInvocationError(
72
+ f"Connector endpoint resolved to a non-public address: {raw_address}."
73
+ )
74
+ return addresses
75
+
76
+
77
+ def _assert_public_endpoint(url: str, resolver: Resolver) -> None:
78
+ """Validate mocked/injected clients that do not use the pinned transport."""
79
+
80
+ _resolve_public_addresses(_validate_endpoint_url(url), resolver)
81
+
82
+
83
+ class _PinnedPublicNetworkBackend(httpcore.AsyncNetworkBackend):
84
+ """Resolve and validate at connect time, then open TCP to the validated IP.
85
+
86
+ HTTP Core retains the original origin hostname and therefore still uses it
87
+ for TLS SNI and certificate verification. Only the TCP destination is
88
+ replaced, closing the DNS-validation-to-connect race.
89
+ """
90
+
91
+ def __init__(
92
+ self,
93
+ resolver: Resolver,
94
+ network_backend: httpcore.AsyncNetworkBackend | None = None,
95
+ ) -> None:
96
+ self._resolver = resolver
97
+ self._network_backend = network_backend or httpcore.AnyIOBackend()
98
+
99
+ async def connect_tcp(
100
+ self,
101
+ host: str,
102
+ port: int,
103
+ timeout: float | None = None,
104
+ local_address: str | None = None,
105
+ socket_options: Iterable[tuple[int, int, int | bytes]] | None = None,
106
+ ) -> httpcore.AsyncNetworkStream:
107
+ addresses = _resolve_public_addresses(host.lower(), self._resolver)
108
+ return await self._network_backend.connect_tcp(
109
+ addresses[0],
110
+ port,
111
+ timeout=timeout,
112
+ local_address=local_address,
113
+ socket_options=socket_options,
114
+ )
115
+
116
+ async def connect_unix_socket(
117
+ self,
118
+ path: str,
119
+ timeout: float | None = None,
120
+ socket_options: Iterable[tuple[int, int, int | bytes]] | None = None,
121
+ ) -> httpcore.AsyncNetworkStream:
122
+ raise ConnectorInvocationError("Connector Unix socket transport is not allowed.")
123
+
124
+ async def sleep(self, seconds: float) -> None:
125
+ await self._network_backend.sleep(seconds)
126
+
127
+
128
+ class _PinnedPublicAsyncTransport(httpx.AsyncHTTPTransport):
129
+ """HTTPX transport whose connection pool uses connect-time DNS pinning."""
130
+
131
+ def __init__(self, resolver: Resolver) -> None:
132
+ super().__init__(retries=0)
133
+ self._pool = httpcore.AsyncConnectionPool(
134
+ retries=0,
135
+ network_backend=_PinnedPublicNetworkBackend(resolver),
136
+ )
137
+
138
+
139
+ def _parse_expiry(value: Any) -> datetime:
140
+ if not isinstance(value, str) or not value:
141
+ raise ConnectorInvocationError("Connector response expires_at is required.")
142
+ try:
143
+ expiry = datetime.fromisoformat(value.replace("Z", "+00:00"))
144
+ except ValueError as exc:
145
+ raise ConnectorInvocationError("Connector response expires_at is invalid.") from exc
146
+ if expiry.tzinfo is None:
147
+ raise ConnectorInvocationError("Connector response expires_at must include a timezone.")
148
+ now = datetime.now(timezone.utc)
149
+ remaining = (expiry.astimezone(timezone.utc) - now).total_seconds()
150
+ if remaining <= 0:
151
+ raise ConnectorInvocationError("Connector response has expired.")
152
+ if remaining > MAX_RESPONSE_LIFETIME_SECONDS:
153
+ raise ConnectorInvocationError("Connector response expiry exceeds the allowed lifetime.")
154
+ return expiry
155
+
156
+
157
+ def _validate_json(instance: Any, schema: dict[str, Any], *, label: str) -> None:
158
+ try:
159
+ Draft202012Validator.check_schema(schema)
160
+ Draft202012Validator(schema).validate(instance)
161
+ except SchemaError as exc:
162
+ raise ConnectorInvocationError(f"Connector {label} schema is invalid: {exc.message}") from exc
163
+ except ValidationError as exc:
164
+ raise ConnectorInvocationError(f"Connector {label} does not match its schema: {exc.message}") from exc
165
+
166
+
167
+ def _reject_embedded_write_payload(result: Any) -> None:
168
+ pending = [result]
169
+ while pending:
170
+ value = pending.pop()
171
+ if isinstance(value, dict):
172
+ for key, item in value.items():
173
+ if str(key).lower() in RESERVED_WRITE_RESULT_KEYS:
174
+ raise ConnectorInvocationError(
175
+ f"Read-only connector result contains reserved write field: {key}."
176
+ )
177
+ pending.append(item)
178
+ elif isinstance(value, list):
179
+ pending.extend(value)
180
+
181
+
182
+ class ConnectorReadClient:
183
+ """Invoke enabled read-only connector tools with strict identity binding."""
184
+
185
+ def __init__(
186
+ self,
187
+ registry: ConnectorRegistry | None = None,
188
+ *,
189
+ http_client: httpx.AsyncClient | None = None,
190
+ resolver: Resolver | None = None,
191
+ ):
192
+ self.registry = registry or ConnectorRegistry()
193
+ self._http_client = http_client
194
+ self._resolver = resolver or _default_resolver
195
+
196
+ async def invoke(
197
+ self,
198
+ host_tool_name: str,
199
+ arguments: dict[str, Any],
200
+ *,
201
+ context: dict[str, Any] | None = None,
202
+ ) -> dict[str, Any]:
203
+ tool = resolve_connector_tool(host_tool_name, self.registry, include_write=False)
204
+ if tool["read_only"] is not True:
205
+ raise ConnectorInvocationError("ConnectorReadClient accepts only read-only tools.")
206
+ if not isinstance(arguments, dict):
207
+ raise ConnectorInvocationError("Connector tool arguments must be an object.")
208
+ _validate_json(arguments, tool["input_schema"], label="tool input")
209
+
210
+ connector_id = str(tool["connector_id"])
211
+ connector_version = str(tool["connector_version"])
212
+ manifest = self.registry.load_manifest(connector_id, connector_version)
213
+ transport = manifest["transport"]
214
+ base_url = str(transport["url"]).rstrip("/")
215
+ _validate_endpoint_url(base_url)
216
+ if self._http_client is not None:
217
+ _assert_public_endpoint(base_url, self._resolver)
218
+ request_id = str(uuid.uuid4())
219
+
220
+ safe_context: dict[str, Any] = {}
221
+ supplied_context = context if isinstance(context, dict) else {}
222
+ for field in ("chain", "network", "chain_id"):
223
+ value = supplied_context.get(field)
224
+ if value is not None:
225
+ safe_context[field] = value
226
+ if manifest["permissions"].get("wallet_address") is True:
227
+ wallet_address = supplied_context.get("wallet_address")
228
+ if isinstance(wallet_address, str) and wallet_address.strip():
229
+ safe_context["wallet_address"] = wallet_address.strip()
230
+
231
+ request_payload = {
232
+ "protocol_version": 1,
233
+ "request_id": request_id,
234
+ "connector": {
235
+ "id": connector_id,
236
+ "version": connector_version,
237
+ **(
238
+ {"artifact_digest": manifest["artifact_digest"]}
239
+ if manifest.get("artifact_digest")
240
+ else {}
241
+ ),
242
+ },
243
+ "tool": str(tool["connector_tool"]),
244
+ "arguments": arguments,
245
+ "context": safe_context,
246
+ }
247
+
248
+ owns_client = self._http_client is None
249
+ client = self._http_client or httpx.AsyncClient(
250
+ transport=_PinnedPublicAsyncTransport(self._resolver),
251
+ follow_redirects=False,
252
+ trust_env=False,
253
+ headers={"Accept": "application/json", "Content-Type": "application/json"},
254
+ )
255
+ try:
256
+ try:
257
+ response = await client.post(
258
+ f"{base_url}/invoke",
259
+ json=request_payload,
260
+ timeout=float(transport.get("timeout_ms", 10000)) / 1000.0,
261
+ )
262
+ except httpx.HTTPError as exc:
263
+ raise ConnectorInvocationError(f"Connector request failed: {exc}") from exc
264
+ finally:
265
+ if owns_client:
266
+ await client.aclose()
267
+
268
+ if 300 <= response.status_code < 400:
269
+ raise ConnectorInvocationError("Connector redirects are not allowed.")
270
+ if response.status_code != 200:
271
+ raise ConnectorInvocationError(f"Connector returned HTTP {response.status_code}.")
272
+ if len(response.content) > MAX_CONNECTOR_RESPONSE_BYTES:
273
+ raise ConnectorInvocationError("Connector response exceeds the size limit.")
274
+ try:
275
+ payload = response.json()
276
+ except (json.JSONDecodeError, UnicodeDecodeError) as exc:
277
+ raise ConnectorInvocationError("Connector response is not valid JSON.") from exc
278
+ if not isinstance(payload, dict):
279
+ raise ConnectorInvocationError("Connector response root must be an object.")
280
+ if payload.get("protocol_version") != 1 or payload.get("request_id") != request_id:
281
+ raise ConnectorInvocationError("Connector response binding is invalid.")
282
+ response_connector = payload.get("connector")
283
+ if not isinstance(response_connector, dict):
284
+ raise ConnectorInvocationError("Connector response identity is missing.")
285
+ if (
286
+ response_connector.get("id") != connector_id
287
+ or response_connector.get("version") != connector_version
288
+ ):
289
+ raise ConnectorInvocationError("Connector response identity does not match the request.")
290
+ expected_artifact = manifest.get("artifact_digest")
291
+ if expected_artifact and response_connector.get("artifact_digest") != expected_artifact:
292
+ raise ConnectorInvocationError("Connector response artifact digest does not match.")
293
+ if payload.get("tool") != tool["connector_tool"]:
294
+ raise ConnectorInvocationError("Connector response tool does not match the request.")
295
+ if payload.get("kind") != "read_result":
296
+ raise ConnectorInvocationError("Read-only connector returned a non-read result.")
297
+ _parse_expiry(payload.get("expires_at"))
298
+ result = payload.get("result")
299
+ _reject_embedded_write_payload(result)
300
+ _validate_json(result, tool["output_schema"], label="tool output")
301
+ return {
302
+ "connector_id": connector_id,
303
+ "connector_version": connector_version,
304
+ "tool": str(tool["connector_tool"]),
305
+ "untrusted_external_data": True,
306
+ "result": result,
307
+ "expires_at": payload["expires_at"],
308
+ }