@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,1357 @@
1
+ """One-command installer for the local OpenClaw agent-wallet setup."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import hashlib
7
+ import json
8
+ import os
9
+ import platform
10
+ import re
11
+ import shutil
12
+ import subprocess
13
+ import sys
14
+ import tempfile
15
+ import urllib.error
16
+ import urllib.request
17
+ import venv
18
+ from pathlib import Path
19
+
20
+ WELCOME_INVITE_PATTERN = re.compile(r"^alw_[A-Za-z0-9_-]{43}$")
21
+ DEFAULT_ONBOARDING_BIND_URL = "https://www.agent-layer.tech/api/onboarding/bind-wallet"
22
+ ONBOARDING_HTTP_TIMEOUT_SECONDS = 5.0
23
+
24
+ INCLUDED_RUNTIME_ROOT_FILES = [
25
+ ".env.example",
26
+ "AGENTS.md",
27
+ "README.md",
28
+ "CHANGELOG.md",
29
+ "install-from-github.sh",
30
+ "requirements.txt",
31
+ "setup.sh",
32
+ ]
33
+ INCLUDED_RUNTIME_TOP_LEVEL_DIRS = [
34
+ "claude-code",
35
+ "codex",
36
+ "cursor",
37
+ ".openclaw",
38
+ "agent-wallet",
39
+ "agent-a2a-gateway",
40
+ "hermes",
41
+ "mcp",
42
+ "wdk-evm-wallet",
43
+ ]
44
+ EXCLUDED_RUNTIME_DIR_NAMES = {
45
+ ".git",
46
+ ".venv",
47
+ ".pytest_cache",
48
+ ".ruff_cache",
49
+ ".runtime-venv",
50
+ "__pycache__",
51
+ "dist",
52
+ "extensions-local",
53
+ "graphify-out",
54
+ "node_modules",
55
+ }
56
+ EXCLUDED_RUNTIME_FILE_NAMES = {
57
+ ".DS_Store",
58
+ ".env",
59
+ }
60
+ EXCLUDED_RUNTIME_SUFFIXES = {
61
+ ".pyc",
62
+ ".pyo",
63
+ }
64
+
65
+
66
+ def _repo_root() -> Path:
67
+ return Path(__file__).resolve().parents[2]
68
+
69
+
70
+ def _package_root() -> Path:
71
+ return Path(__file__).resolve().parents[1]
72
+
73
+
74
+ def _extension_path() -> Path:
75
+ return _repo_root() / ".openclaw" / "extensions" / "agent-wallet"
76
+
77
+
78
+ def _default_wdk_evm_root() -> Path:
79
+ return _repo_root() / "wdk-evm-wallet"
80
+
81
+
82
+ def _default_env_path() -> Path:
83
+ return _package_root() / ".env"
84
+
85
+
86
+ def _default_env_example_path() -> Path:
87
+ return _package_root() / ".env.example"
88
+
89
+
90
+ def _default_config_path() -> Path:
91
+ return _resolve_openclaw_home() / "openclaw.json"
92
+
93
+
94
+ def _default_venv_path() -> Path:
95
+ return _package_root() / ".venv"
96
+
97
+
98
+ def _default_user_id() -> str:
99
+ return f"{os.getenv('USER', 'openclaw-user')}-local"
100
+
101
+
102
+ def _default_npm_bin() -> str:
103
+ return shutil.which("npm") or "npm"
104
+
105
+
106
+ def _resolve_openclaw_home() -> Path:
107
+ return Path(os.path.expanduser(os.getenv("OPENCLAW_HOME", "~/.openclaw")))
108
+
109
+
110
+ def _default_runtime_root() -> Path:
111
+ explicit_target = os.getenv("OPENCLAW_INSTALL_TARGET", "").strip()
112
+ if explicit_target:
113
+ return Path(explicit_target).expanduser()
114
+ explicit_root = os.getenv("OPENCLAW_INSTALL_ROOT", "").strip()
115
+ if explicit_root:
116
+ return Path(explicit_root).expanduser() / "current"
117
+ return _resolve_openclaw_home() / "agent-wallet-runtime" / "current"
118
+
119
+
120
+ def _resolve_sealed_keys_path() -> Path:
121
+ return _resolve_openclaw_home() / "sealed_keys.json"
122
+
123
+
124
+ def _runtime_base_for(runtime_root: Path) -> Path:
125
+ resolved = runtime_root.expanduser().resolve()
126
+ if resolved.parent.name == "releases":
127
+ return resolved.parent.parent
128
+ return resolved.parent
129
+
130
+
131
+ def _shared_runtime_root(runtime_root: Path) -> Path:
132
+ return _runtime_base_for(runtime_root) / "shared"
133
+
134
+
135
+ def _shared_dependency_links_supported() -> bool:
136
+ return os.name != "nt"
137
+
138
+
139
+ def _atomic_write_text(path: Path, content: str, *, mode: int = 0o600) -> None:
140
+ path.parent.mkdir(parents=True, exist_ok=True)
141
+ fd, temp_path = tempfile.mkstemp(prefix=f".{path.name}.", dir=str(path.parent))
142
+ try:
143
+ with os.fdopen(fd, "w", encoding="utf-8") as handle:
144
+ handle.write(content)
145
+ handle.flush()
146
+ os.fsync(handle.fileno())
147
+ os.chmod(temp_path, mode)
148
+ os.replace(temp_path, path)
149
+ except Exception:
150
+ try:
151
+ os.unlink(temp_path)
152
+ except FileNotFoundError:
153
+ pass
154
+ raise
155
+
156
+
157
+ def _chmod_if_exists(path: Path, mode: int = 0o600) -> None:
158
+ try:
159
+ path.chmod(mode)
160
+ except FileNotFoundError:
161
+ return
162
+
163
+
164
+ def _sha256_text(parts: list[str]) -> str:
165
+ digest = hashlib.sha256()
166
+ for part in parts:
167
+ digest.update(part.encode("utf-8"))
168
+ digest.update(b"\0")
169
+ return digest.hexdigest()
170
+
171
+
172
+ def _file_text_or_empty(path: Path) -> str:
173
+ try:
174
+ return path.read_text(encoding="utf-8")
175
+ except FileNotFoundError:
176
+ return ""
177
+
178
+
179
+ def build_parser() -> argparse.ArgumentParser:
180
+ parser = argparse.ArgumentParser(description=__doc__)
181
+ parser.add_argument("--config-path", default=str(_default_config_path()))
182
+ parser.add_argument("--env-path", default=str(_default_env_path()))
183
+ parser.add_argument("--env-example-path", default=str(_default_env_example_path()))
184
+ parser.add_argument("--venv-path", default=str(_default_venv_path()))
185
+ parser.add_argument("--package-root", default=str(_package_root()))
186
+ parser.add_argument("--extension-path", default=str(_extension_path()))
187
+ parser.add_argument("--wdk-evm-root", default=str(_default_wdk_evm_root()))
188
+ parser.add_argument("--wdk-evm-service-url", default=_default_evm_service_url())
189
+ parser.add_argument("--runtime-root", default=str(_default_runtime_root()))
190
+ parser.add_argument("--npm-bin", default=_default_npm_bin())
191
+ parser.add_argument("--plugin-id", default="agent-wallet")
192
+ parser.add_argument("--user-id", default=_default_user_id())
193
+ parser.add_argument("--backend", default="solana_local")
194
+ parser.add_argument("--network", default="mainnet")
195
+ parser.add_argument("--rpc-url", default="")
196
+ parser.add_argument("--rpc-urls", default="")
197
+ parser.add_argument("--invite", default="")
198
+ parser.add_argument("--sign-only", action=argparse.BooleanOptionalAction, default=False)
199
+ parser.add_argument("--sync-runtime", action=argparse.BooleanOptionalAction, default=True)
200
+ parser.add_argument("--install-from-runtime", action=argparse.BooleanOptionalAction, default=False)
201
+ parser.add_argument(
202
+ "--configure-openclaw",
203
+ action=argparse.BooleanOptionalAction,
204
+ default=True,
205
+ help="Patch openclaw.json during install (disabled by the universal host orchestrator).",
206
+ )
207
+ parser.add_argument("--skip-python-setup", action=argparse.BooleanOptionalAction, default=False)
208
+ parser.add_argument("--skip-node-setup", action=argparse.BooleanOptionalAction, default=False)
209
+ parser.add_argument("--dry-run", action=argparse.BooleanOptionalAction, default=False)
210
+ return parser
211
+
212
+
213
+ def _infer_source_root(
214
+ package_root: Path,
215
+ extension_path: Path,
216
+ wdk_evm_root: Path,
217
+ ) -> Path:
218
+ candidates = [
219
+ package_root.parent,
220
+ Path(os.path.commonpath([package_root, extension_path, wdk_evm_root])),
221
+ ]
222
+ seen: set[Path] = set()
223
+ for candidate in candidates:
224
+ resolved = candidate.resolve()
225
+ if resolved in seen:
226
+ continue
227
+ seen.add(resolved)
228
+ if (
229
+ (resolved / "agent-wallet").resolve() == package_root
230
+ and (resolved / ".openclaw" / "extensions" / "agent-wallet").resolve() == extension_path
231
+ and (resolved / "wdk-evm-wallet").resolve() == wdk_evm_root
232
+ and (resolved / "setup.sh").exists()
233
+ ):
234
+ return resolved
235
+ raise SystemExit(
236
+ "Could not infer the source root for runtime sync. Expected package-root, extension-path, "
237
+ "wdk-evm-root to belong to the same repo checkout."
238
+ )
239
+
240
+
241
+ def _ignore_runtime_entries(_directory: str, names: list[str]) -> set[str]:
242
+ directory = Path(_directory)
243
+ keep_dist = ".openclaw" in directory.parts and "extensions" in directory.parts
244
+ ignored: set[str] = set()
245
+ for name in names:
246
+ if name == "pay-bridge" and directory.parts[-2:] == (".openclaw", "extensions"):
247
+ ignored.add(name)
248
+ continue
249
+ if name == "dist" and keep_dist:
250
+ continue
251
+ if name in EXCLUDED_RUNTIME_DIR_NAMES:
252
+ ignored.add(name)
253
+ continue
254
+ if name in EXCLUDED_RUNTIME_FILE_NAMES:
255
+ ignored.add(name)
256
+ continue
257
+ if any(name.endswith(suffix) for suffix in EXCLUDED_RUNTIME_SUFFIXES):
258
+ ignored.add(name)
259
+ return ignored
260
+
261
+
262
+ def _replace_if_type_mismatch(source: Path, target: Path) -> None:
263
+ if not target.exists():
264
+ return
265
+ if source.is_dir() and target.is_file():
266
+ target.unlink()
267
+ elif source.is_file() and target.is_dir():
268
+ shutil.rmtree(target)
269
+
270
+
271
+ def _sync_runtime_tree(source_root: Path, runtime_root: Path) -> dict[str, object]:
272
+ source_root = source_root.resolve()
273
+ runtime_root = runtime_root.resolve()
274
+ if source_root == runtime_root:
275
+ return {
276
+ "enabled": True,
277
+ "skipped": True,
278
+ "reason": "source_root_matches_runtime_root",
279
+ "source_root": str(source_root),
280
+ "runtime_root": str(runtime_root),
281
+ "copied_paths": [],
282
+ }
283
+
284
+ runtime_root.mkdir(parents=True, exist_ok=True)
285
+ copied_paths: list[str] = []
286
+ for relative in INCLUDED_RUNTIME_ROOT_FILES + INCLUDED_RUNTIME_TOP_LEVEL_DIRS:
287
+ source = source_root / relative
288
+ if not source.exists():
289
+ continue
290
+ target = runtime_root / relative
291
+ _replace_if_type_mismatch(source, target)
292
+ if source.is_dir():
293
+ shutil.copytree(
294
+ source,
295
+ target,
296
+ dirs_exist_ok=True,
297
+ ignore=_ignore_runtime_entries,
298
+ )
299
+ else:
300
+ target.parent.mkdir(parents=True, exist_ok=True)
301
+ shutil.copy2(source, target)
302
+ copied_paths.append(relative)
303
+
304
+ return {
305
+ "enabled": True,
306
+ "skipped": False,
307
+ "reason": None,
308
+ "source_root": str(source_root),
309
+ "runtime_root": str(runtime_root),
310
+ "copied_paths": copied_paths,
311
+ }
312
+
313
+
314
+ def _ensure_env_file(env_path: Path, env_example_path: Path) -> bool:
315
+ if env_path.exists():
316
+ return False
317
+ if not env_example_path.exists():
318
+ source_candidate = _package_root() / ".env.example"
319
+ if source_candidate.exists():
320
+ env_example_path = source_candidate
321
+ else:
322
+ raise SystemExit(
323
+ f"Missing env example template at '{env_example_path}'."
324
+ )
325
+ env_path.parent.mkdir(parents=True, exist_ok=True)
326
+ shutil.copyfile(env_example_path, env_path)
327
+ _chmod_if_exists(env_path, 0o600)
328
+ return True
329
+
330
+
331
+ def _upsert_env_value(env_path: Path, key: str, value: str) -> bool:
332
+ if not env_path.exists():
333
+ return False
334
+ lines = env_path.read_text(encoding="utf-8").splitlines()
335
+ updated = False
336
+ replaced = False
337
+ prefix = f"{key}="
338
+ new_line = f"{key}={value}"
339
+ for index, line in enumerate(lines):
340
+ if line.startswith(prefix):
341
+ replaced = True
342
+ if line != new_line:
343
+ lines[index] = new_line
344
+ updated = True
345
+ break
346
+ if not replaced:
347
+ if lines and lines[-1] != "":
348
+ lines.append("")
349
+ lines.append(new_line)
350
+ updated = True
351
+ if updated:
352
+ _atomic_write_text(env_path, "\n".join(lines) + "\n", mode=0o600)
353
+ _chmod_if_exists(env_path, 0o600)
354
+ return updated
355
+
356
+
357
+ def _ensure_runtime_boot_key_file_env(env_path: Path) -> bool:
358
+ boot_key_file = _resolve_openclaw_home() / "agent-wallet-runtime" / "boot-key"
359
+ if not boot_key_file.exists():
360
+ return False
361
+ return _upsert_env_value(env_path, "AGENT_WALLET_BOOT_KEY_FILE", str(boot_key_file))
362
+
363
+
364
+ def _ensure_openclaw_config(config_path: Path) -> bool:
365
+ if config_path.exists():
366
+ return False
367
+ config_path.parent.mkdir(parents=True, exist_ok=True)
368
+ _atomic_write_text(
369
+ config_path,
370
+ json.dumps({"plugins": {"entries": {}}, "tools": {"alsoAllow": []}}, indent=2) + "\n",
371
+ mode=0o600,
372
+ )
373
+ return True
374
+
375
+
376
+ def _venv_python(venv_path: Path) -> Path:
377
+ if os.name == "nt":
378
+ return venv_path / "Scripts" / "python.exe"
379
+ return venv_path / "bin" / "python"
380
+
381
+
382
+ def _venv_python_wrapper(venv_path: Path) -> Path:
383
+ if os.name == "nt":
384
+ return _venv_python(venv_path)
385
+ return venv_path / "bin" / "openclaw-agent-wallet-python"
386
+
387
+
388
+ def _ensure_python_wrapper(venv_path: Path) -> Path:
389
+ if os.name == "nt":
390
+ return _venv_python(venv_path)
391
+ wrapper = _venv_python_wrapper(venv_path)
392
+ wrapper.parent.mkdir(parents=True, exist_ok=True)
393
+ wrapper.write_text('#!/bin/sh\nexec "$(dirname "$0")/python" "$@"\n', encoding="utf-8")
394
+ wrapper.chmod(0o755)
395
+ return wrapper
396
+
397
+
398
+ def _python_runtime_fingerprint(package_root: Path, python_bin: Path) -> str:
399
+ version = f"{sys.version_info.major}.{sys.version_info.minor}"
400
+ return _sha256_text(
401
+ [
402
+ f"python-bin:{python_bin}",
403
+ f"python-version:{version}",
404
+ f"platform:{platform.system()}",
405
+ f"machine:{platform.machine()}",
406
+ _file_text_or_empty(package_root / "pyproject.toml"),
407
+ ]
408
+ )[:24]
409
+
410
+
411
+ def _python_runtime_plan(
412
+ venv_path: Path,
413
+ package_root: Path,
414
+ runtime_root: Path,
415
+ ) -> dict[str, object]:
416
+ if _shared_dependency_links_supported():
417
+ fingerprint = _python_runtime_fingerprint(package_root, Path(sys.executable))
418
+ shared_root = _shared_runtime_root(runtime_root) / "python" / fingerprint
419
+ shared_venv_path = shared_root / "venv"
420
+ shared_wrapper = _venv_python_wrapper(shared_venv_path)
421
+ return {
422
+ "shared": True,
423
+ "fingerprint": fingerprint,
424
+ "shared_root": str(shared_root),
425
+ "venv_path": str(shared_venv_path),
426
+ "release_link_path": str(venv_path),
427
+ "python_bin": str(venv_path / shared_wrapper.relative_to(shared_venv_path)),
428
+ "action": "reuse" if shared_venv_path.exists() else "create",
429
+ "exists": shared_venv_path.exists(),
430
+ }
431
+ return {
432
+ "shared": False,
433
+ "fingerprint": None,
434
+ "shared_root": None,
435
+ "venv_path": str(venv_path),
436
+ "release_link_path": str(venv_path),
437
+ "python_bin": str(_venv_python_wrapper(venv_path)),
438
+ "action": "install",
439
+ "exists": _venv_python(venv_path).exists(),
440
+ }
441
+
442
+
443
+ def _replace_with_directory_symlink(link_path: Path, target_path: Path) -> None:
444
+ target_resolved = target_path.resolve()
445
+ if link_path.is_symlink():
446
+ existing_target = link_path.resolve()
447
+ if existing_target == target_resolved:
448
+ return
449
+ link_path.unlink()
450
+ elif link_path.exists():
451
+ if link_path.is_dir():
452
+ shutil.rmtree(link_path)
453
+ else:
454
+ link_path.unlink()
455
+ link_path.parent.mkdir(parents=True, exist_ok=True)
456
+ link_path.symlink_to(target_resolved, target_is_directory=True)
457
+
458
+
459
+ def _bootstrap_venv_pip(python_bin: Path) -> None:
460
+ """Upgrade pip in a freshly created venv before installing dependencies.
461
+
462
+ A new venv ships with whatever pip ``ensurepip`` bundled, which on older
463
+ interpreters (e.g. a python.org 3.10 build) can be too old to select
464
+ prebuilt wheels for native dependencies such as ``cryptography`` and
465
+ ``ckzg``. Without a matching wheel pip falls back to a source build that
466
+ needs a Rust/C toolchain and fails on machines that lack one. Upgrading pip
467
+ first keeps the editable install below on wheels.
468
+ """
469
+ subprocess.run(
470
+ [str(python_bin), "-m", "pip", "install", "--upgrade", "pip", "setuptools", "wheel"],
471
+ check=True,
472
+ )
473
+
474
+
475
+ def _pip_install_editable(python_bin: Path, package_root: Path) -> None:
476
+ """Editable-install the package, preferring prebuilt wheels for deps.
477
+
478
+ ``--prefer-binary`` keeps pip on prebuilt wheels for native dependencies
479
+ instead of compiling them from source when a newer source-only release is
480
+ available, so the install does not require a local build toolchain.
481
+ """
482
+ subprocess.run(
483
+ [str(python_bin), "-m", "pip", "install", "--prefer-binary", "-e", str(package_root)],
484
+ check=True,
485
+ )
486
+
487
+
488
+ def _venv_interpreter_runs(python_bin: Path) -> bool:
489
+ """Return whether the venv interpreter starts and finds its standard library.
490
+
491
+ A venv whose base interpreter moved or cannot locate its stdlib fails before
492
+ any Python code runs ("No module named 'encodings'"). pip cannot repair that;
493
+ the venv has to be created again.
494
+ """
495
+ try:
496
+ result = subprocess.run(
497
+ [str(python_bin), "-c", "import encodings, ssl, venv"],
498
+ capture_output=True,
499
+ text=True,
500
+ check=False,
501
+ )
502
+ except OSError:
503
+ return False
504
+ return result.returncode == 0
505
+
506
+
507
+ def _create_venv(venv_path: Path) -> Path:
508
+ """Create a venv the way ``python -m venv`` does, then prove it starts.
509
+
510
+ ``venv.EnvBuilder`` copies the interpreter unless asked for symlinks. A copied
511
+ interpreter from a relocatable build such as uv's python-build-standalone looks
512
+ for its standard library next to the copy, does not find it, and dies on
513
+ startup. Symlinks (the ``python -m venv`` default on POSIX) work for every
514
+ interpreter kind, so they are used everywhere except Windows.
515
+ """
516
+ venv.EnvBuilder(with_pip=True, symlinks=os.name != "nt").create(venv_path)
517
+ python_bin = _venv_python(venv_path)
518
+ if not _venv_interpreter_runs(python_bin):
519
+ shutil.rmtree(venv_path, ignore_errors=True)
520
+ raise RuntimeError(
521
+ f"The Python environment created from {sys.executable} cannot start. "
522
+ "Point OPENCLAW_AGENT_WALLET_PYTHON at another Python 3.10+ interpreter and run the "
523
+ "install again."
524
+ )
525
+ return python_bin
526
+
527
+
528
+ def _python_runtime_is_healthy(python_bin: Path) -> bool:
529
+ """Return whether a reusable venv has the installer dependencies available.
530
+
531
+ A shared runtime can be left half-created when an install is interrupted
532
+ between ``venv`` creation and the editable pip install. The interpreter
533
+ itself then exists, but the next update must repair it rather than treating
534
+ it as a valid cache entry.
535
+ """
536
+ try:
537
+ result = subprocess.run(
538
+ [str(python_bin), "-c", "import jsonschema, pydantic, pydantic_settings"],
539
+ capture_output=True,
540
+ text=True,
541
+ check=False,
542
+ )
543
+ except OSError:
544
+ return False
545
+ return result.returncode == 0
546
+
547
+
548
+ def _ensure_python_runtime(
549
+ venv_path: Path,
550
+ package_root: Path,
551
+ runtime_root: Path,
552
+ ) -> tuple[Path, bool, dict[str, object]]:
553
+ created = False
554
+ plan = _python_runtime_plan(venv_path, package_root, runtime_root)
555
+ if bool(plan["shared"]):
556
+ shared_root = Path(str(plan["shared_root"]))
557
+ shared_venv_path = Path(str(plan["venv_path"]))
558
+ python_bin = _venv_python(shared_venv_path)
559
+ if (python_bin.exists() or python_bin.is_symlink()) and not _venv_interpreter_runs(python_bin):
560
+ # A cached venv whose interpreter no longer starts (one an older installer
561
+ # copied from a relocatable Python, or a symlink to an interpreter that was
562
+ # since removed) cannot be repaired with pip; rebuild it from scratch.
563
+ shutil.rmtree(shared_venv_path, ignore_errors=True)
564
+ plan["action"] = "rebuild"
565
+ if not python_bin.exists():
566
+ python_bin = _create_venv(shared_venv_path)
567
+ created = True
568
+ _bootstrap_venv_pip(python_bin)
569
+ _pip_install_editable(python_bin, package_root)
570
+ elif not _python_runtime_is_healthy(python_bin):
571
+ # A prior update may have been interrupted after creating the venv
572
+ # but before pip finished. Repair the cache in place; release links
573
+ # continue to point at one verified shared environment.
574
+ _bootstrap_venv_pip(python_bin)
575
+ _pip_install_editable(python_bin, package_root)
576
+ plan["action"] = "repair"
577
+ shared_wrapper = _ensure_python_wrapper(shared_venv_path)
578
+ _replace_with_directory_symlink(venv_path, shared_venv_path)
579
+ if created and plan["action"] != "rebuild":
580
+ plan["action"] = "create"
581
+ plan["exists"] = True
582
+ return (
583
+ venv_path / shared_wrapper.relative_to(shared_venv_path),
584
+ created,
585
+ plan,
586
+ )
587
+
588
+ python_bin = _venv_python(venv_path)
589
+ if (python_bin.exists() or python_bin.is_symlink()) and not _venv_interpreter_runs(python_bin):
590
+ shutil.rmtree(venv_path, ignore_errors=True)
591
+ if not python_bin.exists():
592
+ python_bin = _create_venv(venv_path)
593
+ created = True
594
+ _bootstrap_venv_pip(python_bin)
595
+
596
+ _pip_install_editable(python_bin, package_root)
597
+ return (
598
+ _ensure_python_wrapper(venv_path),
599
+ created,
600
+ plan,
601
+ )
602
+
603
+
604
+ def _node_version() -> str:
605
+ result = subprocess.run(
606
+ ["node", "--version"],
607
+ capture_output=True,
608
+ text=True,
609
+ check=True,
610
+ )
611
+ return result.stdout.strip()
612
+
613
+
614
+ def _node_runtime_fingerprint(project_root: Path) -> str:
615
+ return _sha256_text(
616
+ [
617
+ f"node-version:{_node_version()}",
618
+ f"platform:{platform.system()}",
619
+ f"machine:{platform.machine()}",
620
+ _file_text_or_empty(project_root / "package.json"),
621
+ _file_text_or_empty(project_root / "package-lock.json"),
622
+ ]
623
+ )[:24]
624
+
625
+
626
+ def _node_runtime_plan(project_root: Path, runtime_root: Path) -> dict[str, object]:
627
+ package_json = project_root / "package.json"
628
+ package_lock = project_root / "package-lock.json"
629
+ command = ["npm", "ci"] if package_lock.exists() else ["npm", "install"]
630
+ if _shared_dependency_links_supported():
631
+ fingerprint = _node_runtime_fingerprint(project_root)
632
+ shared_project_root = _shared_runtime_root(runtime_root) / "node" / project_root.name / fingerprint
633
+ shared_node_modules = shared_project_root / "node_modules"
634
+ return {
635
+ "project_root": str(project_root),
636
+ "package_json": str(package_json),
637
+ "package_lock": str(package_lock) if package_lock.exists() else None,
638
+ "command": command,
639
+ "shared": True,
640
+ "fingerprint": fingerprint,
641
+ "shared_root": str(shared_project_root),
642
+ "node_modules_path": str(shared_node_modules),
643
+ "release_link_path": str(project_root / "node_modules"),
644
+ "action": "reuse" if shared_node_modules.exists() else "create",
645
+ "exists": shared_node_modules.exists(),
646
+ }
647
+ return {
648
+ "project_root": str(project_root),
649
+ "package_json": str(package_json),
650
+ "package_lock": str(package_lock) if package_lock.exists() else None,
651
+ "command": command,
652
+ "shared": False,
653
+ "fingerprint": None,
654
+ "shared_root": None,
655
+ "node_modules_path": str(project_root / "node_modules"),
656
+ "release_link_path": str(project_root / "node_modules"),
657
+ "action": "install",
658
+ "exists": (project_root / "node_modules").exists(),
659
+ }
660
+
661
+
662
+ def _copy_if_exists(source: Path, target: Path) -> None:
663
+ if not source.exists():
664
+ return
665
+ target.parent.mkdir(parents=True, exist_ok=True)
666
+ shutil.copy2(source, target)
667
+
668
+
669
+ def _ensure_node_runtime(npm_bin: str, project_root: Path, runtime_root: Path) -> dict[str, object]:
670
+ package_json = project_root / "package.json"
671
+ if not package_json.exists():
672
+ raise SystemExit(f"Missing package.json for Node runtime at '{project_root}'.")
673
+ package_lock = project_root / "package-lock.json"
674
+ command = [npm_bin, "ci"] if package_lock.exists() else [npm_bin, "install"]
675
+ env = dict(os.environ)
676
+ cache_dir = (
677
+ env.get("OPENCLAW_AGENT_WALLET_NPM_CACHE")
678
+ or str(_resolve_openclaw_home() / "npm-cache")
679
+ )
680
+ env["NPM_CONFIG_CACHE"] = cache_dir
681
+ env["npm_config_cache"] = cache_dir
682
+ Path(cache_dir).expanduser().mkdir(parents=True, exist_ok=True)
683
+ plan = _node_runtime_plan(project_root, runtime_root)
684
+ if bool(plan["shared"]):
685
+ shared_project_root = Path(str(plan["shared_root"]))
686
+ shared_node_modules = Path(str(plan["node_modules_path"]))
687
+ created = False
688
+ if not shared_node_modules.exists():
689
+ shared_project_root.mkdir(parents=True, exist_ok=True)
690
+ _copy_if_exists(package_json, shared_project_root / "package.json")
691
+ _copy_if_exists(package_lock, shared_project_root / "package-lock.json")
692
+ _copy_if_exists(project_root / ".npmrc", shared_project_root / ".npmrc")
693
+ subprocess.run(command, cwd=shared_project_root, check=True, env=env)
694
+ created = True
695
+ _replace_with_directory_symlink(project_root / "node_modules", shared_node_modules)
696
+ plan["cache_dir"] = cache_dir
697
+ plan["created"] = created
698
+ plan["action"] = "create" if created else "reuse"
699
+ plan["exists"] = True
700
+ return plan
701
+
702
+ subprocess.run(command, cwd=project_root, check=True, env=env)
703
+ plan["cache_dir"] = cache_dir
704
+ plan["created"] = True
705
+ plan["exists"] = True
706
+ return plan
707
+
708
+
709
+ def _pending_env_names() -> list[str]:
710
+ pending: list[str] = []
711
+ boot_key = os.getenv("AGENT_WALLET_BOOT_KEY", "").strip()
712
+ sealed_path = _resolve_sealed_keys_path()
713
+ if not boot_key:
714
+ pending.append("AGENT_WALLET_BOOT_KEY")
715
+ if not sealed_path.exists():
716
+ pending.extend(["AGENT_WALLET_MASTER_KEY", "AGENT_WALLET_APPROVAL_SECRET"])
717
+ elif not sealed_path.exists():
718
+ if not os.getenv("AGENT_WALLET_MASTER_KEY", "").strip():
719
+ pending.append("AGENT_WALLET_MASTER_KEY")
720
+ if not os.getenv("AGENT_WALLET_APPROVAL_SECRET", "").strip():
721
+ pending.append("AGENT_WALLET_APPROVAL_SECRET")
722
+ return pending
723
+
724
+
725
+ def _build_next_steps(
726
+ python_bin: Path,
727
+ script_path: Path,
728
+ args: argparse.Namespace,
729
+ *,
730
+ package_root: Path | None = None,
731
+ extension_path: Path | None = None,
732
+ ) -> list[str]:
733
+ effective_package_root = package_root or Path(args.package_root).expanduser()
734
+ effective_extension_path = extension_path or Path(args.extension_path).expanduser()
735
+ command = [
736
+ str(python_bin),
737
+ str(script_path),
738
+ "--config-path",
739
+ str(Path(args.config_path).expanduser()),
740
+ "--plugin-id",
741
+ args.plugin_id,
742
+ "--user-id",
743
+ args.user_id,
744
+ "--backend",
745
+ args.backend,
746
+ "--network",
747
+ args.network,
748
+ ]
749
+ if args.rpc_url.strip():
750
+ command.extend(["--rpc-url", args.rpc_url.strip()])
751
+ if args.rpc_urls.strip():
752
+ command.extend(["--rpc-urls", args.rpc_urls.strip()])
753
+ command.append("--sign-only" if args.sign_only else "--no-sign-only")
754
+ command.extend(["--extension-path", str(effective_extension_path)])
755
+ command.extend(["--package-root", str(effective_package_root)])
756
+ command.extend(["--python-bin", str(python_bin)])
757
+ if _is_evm_backend(args.backend):
758
+ service_url = str(getattr(args, "wdk_evm_service_url", "") or _default_evm_service_url()).strip()
759
+ command.extend(["--wdk-evm-service-url", service_url or _default_evm_service_url()])
760
+ return command
761
+
762
+
763
+ def _is_solana_backend(backend: str) -> bool:
764
+ return backend.strip().lower() in {"solana", "solana_local", "solana-local"}
765
+
766
+
767
+ def _is_evm_backend(backend: str) -> bool:
768
+ return backend.strip().lower() in {
769
+ "wdk_evm_local",
770
+ "wdk-evm-local",
771
+ "evm_local",
772
+ "evm-local",
773
+ }
774
+
775
+
776
+ def _default_evm_service_url() -> str:
777
+ # This installer bootstraps a brand-new install, so it runs before
778
+ # agent_wallet's *dependencies* (e.g. pydantic-settings) are guaranteed to
779
+ # be installed -- putting the package root on sys.path (as other scripts
780
+ # in this family do) isn't enough, since `import agent_wallet.config`
781
+ # itself pulls in pydantic_settings. Mirror
782
+ # agent_wallet.config.resolve_wdk_evm_service_url()'s stdlib-only logic
783
+ # directly instead of importing it.
784
+ explicit = os.environ.get("WDK_EVM_SERVICE_URL", "").strip()
785
+ if explicit:
786
+ return explicit
787
+ openclaw_home = Path(os.environ.get("OPENCLAW_HOME", "~/.openclaw")).expanduser()
788
+ return f"unix://{openclaw_home / 'wdk-evm-wallet' / 'daemon.sock'}"
789
+
790
+
791
+ def _build_evm_onboard_config(args: argparse.Namespace) -> dict[str, object]:
792
+ # The EVM wallet is provisioned on every install (best-effort). Seed creation
793
+ # with a valid EVM network; ensure_user_evm_wallet_ready binds BOTH base and
794
+ # ethereum (one address), so the active --network only matters when EVM is the
795
+ # active backend.
796
+ network = args.network.strip().lower() if _is_evm_backend(args.backend) else "base"
797
+ if network not in {"base", "ethereum"}:
798
+ network = "base"
799
+ service_url = str(getattr(args, "wdk_evm_service_url", "") or _default_evm_service_url()).strip()
800
+ return {
801
+ "backend": "wdk_evm_local",
802
+ "network": network,
803
+ "signOnly": bool(args.sign_only),
804
+ "wdkEvmServiceUrl": service_url or _default_evm_service_url(),
805
+ }
806
+
807
+
808
+ def _build_solana_onboard_config(args: argparse.Namespace) -> dict[str, object]:
809
+ # Solana is provisioned on every install (both wallets are created), so force
810
+ # the Solana backend/network here -- this must work even when the active
811
+ # backend chosen by the user is EVM or BTC.
812
+ solana_active = _is_solana_backend(args.backend)
813
+ config: dict[str, object] = {
814
+ "backend": "solana_local",
815
+ "network": "mainnet",
816
+ "signOnly": bool(args.sign_only),
817
+ "encryptUserWallets": True,
818
+ "migratePlaintextUserWallets": True,
819
+ "refuseMainnetWalletRecreation": True,
820
+ }
821
+ if solana_active and args.rpc_url.strip():
822
+ config["rpcUrl"] = args.rpc_url.strip()
823
+ if solana_active and args.rpc_urls.strip():
824
+ config["rpcUrls"] = [item.strip() for item in args.rpc_urls.split(",") if item.strip()]
825
+ return config
826
+
827
+
828
+ def _runtime_env_for_onboard(package_root: Path) -> dict[str, str]:
829
+ env = dict(os.environ)
830
+ python_path = env.get("PYTHONPATH", "").strip()
831
+ env["PYTHONPATH"] = (
832
+ f"{package_root}{os.pathsep}{python_path}" if python_path else str(package_root)
833
+ )
834
+ for var_name in (
835
+ "AGENT_WALLET_MASTER_KEY",
836
+ "AGENT_WALLET_APPROVAL_SECRET",
837
+ "SOLANA_AGENT_PRIVATE_KEY",
838
+ ):
839
+ env.pop(var_name, None)
840
+ return env
841
+
842
+
843
+ def _bootstrap_card_vault(python_bin: Path, package_root: Path, args: argparse.Namespace) -> dict[str, object]:
844
+ """Provision card recipients during every install/update, without reading keys."""
845
+ if args.dry_run:
846
+ return {"status": "skipped_dry_run"}
847
+ if platform.system() != "Darwin":
848
+ return {"status": "unsupported_platform", "reason": "Interactive card-vault system authentication currently requires macOS."}
849
+ user_ids = sorted({
850
+ value for value in (
851
+ args.user_id, os.getenv("USER"), os.getenv("AGENT_WALLET_USER_ID"),
852
+ os.getenv("OPENCLAW_AGENT_WALLET_USER_ID"),
853
+ ) if value
854
+ })
855
+ try:
856
+ config_path = Path(getattr(args, "config_path", _resolve_openclaw_home() / "openclaw.json")).expanduser()
857
+ config = json.loads(config_path.read_text(encoding="utf-8"))
858
+ configured_user = config["plugins"]["entries"]["agent-wallet"]["config"].get("userId")
859
+ if isinstance(configured_user, str) and configured_user.strip() and configured_user.strip() not in user_ids:
860
+ user_ids.append(configured_user.strip())
861
+ except (OSError, ValueError, KeyError, TypeError, AttributeError):
862
+ pass
863
+ results = []
864
+ for user_id in user_ids:
865
+ try:
866
+ env = dict(os.environ)
867
+ env["PYTHONPATH"] = str(package_root)
868
+ result = subprocess.run(
869
+ [str(python_bin), "-m", "agent_wallet.card_vault_cli", "provision", "--user-id", user_id],
870
+ cwd=str(package_root), env=env, capture_output=True, text=True,
871
+ timeout=30, check=True,
872
+ )
873
+ payload = json.loads(result.stdout)
874
+ if not isinstance(payload, dict) or payload.get("ok") is not True or payload.get("status") not in {"ready", "migration_required"}:
875
+ raise ValueError("invalid provisioning result")
876
+ results.append({"user_id": user_id, **payload})
877
+ except (OSError, ValueError, subprocess.SubprocessError):
878
+ # No provider responses, native errors or secret-bearing subprocess output.
879
+ results.append({"user_id": user_id, "ok": False, "status": "unavailable"})
880
+ return {"status": "ready" if results and all(item.get("status") == "ready" for item in results) else "attention_required", "users": results}
881
+
882
+
883
+ def _bootstrap_solana_wallet(
884
+ python_bin: Path,
885
+ package_root: Path,
886
+ args: argparse.Namespace,
887
+ ) -> dict[str, object] | None:
888
+ result = subprocess.run(
889
+ [
890
+ str(python_bin),
891
+ "-m",
892
+ "agent_wallet.openclaw_cli",
893
+ "onboard",
894
+ "--user-id",
895
+ args.user_id,
896
+ "--config-json",
897
+ json.dumps(_build_solana_onboard_config(args)),
898
+ ],
899
+ cwd=package_root,
900
+ capture_output=True,
901
+ text=True,
902
+ check=True,
903
+ env=_runtime_env_for_onboard(package_root),
904
+ )
905
+ payload = json.loads(result.stdout)
906
+ session = dict(payload.get("session") or {})
907
+ return {
908
+ "ok": True,
909
+ "user_id": session.get("user_id") or args.user_id,
910
+ "address": session.get("address"),
911
+ "network": session.get("network") or args.network,
912
+ "wallet_path": session.get("wallet_path"),
913
+ "storage_format": session.get("storage_format"),
914
+ "created_now": bool(session.get("created_now")),
915
+ "backend": session.get("backend"),
916
+ }
917
+
918
+
919
+ def _bootstrap_evm_wallet(
920
+ python_bin: Path,
921
+ package_root: Path,
922
+ args: argparse.Namespace,
923
+ wdk_evm_root: Path,
924
+ ) -> dict[str, object]:
925
+ """Provision the local EVM wallet (best-effort).
926
+
927
+ Mirrors _bootstrap_solana_wallet but for wdk_evm_local. Runs the onboard CLI,
928
+ which calls ensure_user_evm_wallet_ready: auto-starts the local Node service,
929
+ creates and seals the wallet password, and binds both base and ethereum.
930
+ Failures here never abort the install -- the lazy runtime path (ensure_ready on
931
+ first EVM use) remains the safety net.
932
+ """
933
+ env = _runtime_env_for_onboard(package_root)
934
+ env["OPENCLAW_EVM_WDK_WALLET_ROOT"] = str(wdk_evm_root)
935
+ try:
936
+ result = subprocess.run(
937
+ [
938
+ str(python_bin),
939
+ "-m",
940
+ "agent_wallet.openclaw_cli",
941
+ "onboard",
942
+ "--user-id",
943
+ args.user_id,
944
+ "--config-json",
945
+ json.dumps(_build_evm_onboard_config(args)),
946
+ ],
947
+ cwd=package_root,
948
+ capture_output=True,
949
+ text=True,
950
+ check=True,
951
+ env=env,
952
+ )
953
+ except subprocess.CalledProcessError as exc:
954
+ detail = (exc.stderr or exc.stdout or str(exc)).strip()
955
+ return {"ok": False, "error": detail[-2000:]}
956
+ try:
957
+ payload = json.loads(result.stdout)
958
+ except json.JSONDecodeError:
959
+ return {"ok": False, "error": "EVM onboard returned non-JSON output."}
960
+ session = dict(payload.get("session") or {})
961
+ wallet_path = str(session.get("wallet_path") or "")
962
+ wallet_id = wallet_path.split("walletId=", 1)[-1] if "walletId=" in wallet_path else None
963
+ return {
964
+ "ok": True,
965
+ "user_id": session.get("user_id") or args.user_id,
966
+ "address": session.get("address"),
967
+ "wallet_id": wallet_id,
968
+ "networks": ["base", "ethereum"],
969
+ "backend": session.get("backend"),
970
+ }
971
+
972
+
973
+ def _onboarding_bind_url() -> str:
974
+ return (
975
+ os.getenv("AGENTLAYER_ONBOARDING_BIND_URL", "").strip()
976
+ or DEFAULT_ONBOARDING_BIND_URL
977
+ )
978
+
979
+
980
+ def _onboarding_error_code(payload: object, fallback: str) -> str:
981
+ if not isinstance(payload, dict):
982
+ return fallback
983
+ code = str(payload.get("error") or "").strip().lower()
984
+ allowed = {
985
+ "address_already_used",
986
+ "internal_error",
987
+ "invalid_base_address",
988
+ "invalid_invite",
989
+ "invite_already_bound",
990
+ "invite_expired",
991
+ "invite_revoked",
992
+ "request_too_large",
993
+ }
994
+ return code if code in allowed else fallback
995
+
996
+
997
+ def _decode_onboarding_response(raw: bytes) -> object:
998
+ try:
999
+ return json.loads(raw.decode("utf-8"))
1000
+ except (UnicodeDecodeError, json.JSONDecodeError):
1001
+ return {}
1002
+
1003
+
1004
+ def _bind_welcome_invite(
1005
+ invite: str,
1006
+ address: str,
1007
+ *,
1008
+ api_url: str | None = None,
1009
+ timeout_seconds: float = ONBOARDING_HTTP_TIMEOUT_SECONDS,
1010
+ opener: object = urllib.request.urlopen,
1011
+ attempts: int = 2,
1012
+ ) -> dict[str, object]:
1013
+ normalized_invite = invite.strip()
1014
+ normalized_address = address.strip()
1015
+ if not WELCOME_INVITE_PATTERN.fullmatch(normalized_invite):
1016
+ return {"ok": False, "status": "invalid_invite", "retryable": False}
1017
+ if not re.fullmatch(r"0x[0-9a-fA-F]{40}", normalized_address):
1018
+ return {"ok": False, "status": "invalid_base_address", "retryable": False}
1019
+
1020
+ body = json.dumps({"address": normalized_address}).encode("utf-8")
1021
+ request = urllib.request.Request(
1022
+ api_url or _onboarding_bind_url(),
1023
+ data=body,
1024
+ method="POST",
1025
+ headers={
1026
+ "Authorization": f"Bearer {normalized_invite}",
1027
+ "Content-Type": "application/json",
1028
+ "Accept": "application/json",
1029
+ "User-Agent": "AgentLayer-Wallet-Installer",
1030
+ },
1031
+ )
1032
+ max_attempts = max(1, min(int(attempts), 3))
1033
+ for attempt in range(max_attempts):
1034
+ try:
1035
+ with opener(request, timeout=timeout_seconds) as response: # type: ignore[operator]
1036
+ status_code = int(getattr(response, "status", 200))
1037
+ payload = _decode_onboarding_response(response.read(65_536))
1038
+ if status_code < 200 or status_code >= 300 or not isinstance(payload, dict):
1039
+ if status_code >= 500 and attempt + 1 < max_attempts:
1040
+ continue
1041
+ return {
1042
+ "ok": False,
1043
+ "status": _onboarding_error_code(payload, "service_error"),
1044
+ "retryable": status_code >= 500,
1045
+ }
1046
+ binding_status = str(payload.get("status") or "")
1047
+ response_address = str(payload.get("address") or "")
1048
+ if (
1049
+ payload.get("ok") is not True
1050
+ or binding_status not in {"bound", "already_bound"}
1051
+ or response_address.lower() != normalized_address.lower()
1052
+ ):
1053
+ return {"ok": False, "status": "invalid_response", "retryable": True}
1054
+ return {
1055
+ "ok": True,
1056
+ "status": binding_status,
1057
+ "network": "base",
1058
+ "address": response_address,
1059
+ }
1060
+ except urllib.error.HTTPError as exc:
1061
+ payload = _decode_onboarding_response(exc.read(65_536))
1062
+ if exc.code >= 500 and attempt + 1 < max_attempts:
1063
+ continue
1064
+ return {
1065
+ "ok": False,
1066
+ "status": _onboarding_error_code(payload, "service_error"),
1067
+ "retryable": exc.code >= 500,
1068
+ }
1069
+ except (urllib.error.URLError, TimeoutError, OSError):
1070
+ if attempt + 1 < max_attempts:
1071
+ continue
1072
+ return {"ok": False, "status": "network_error", "retryable": True}
1073
+ return {"ok": False, "status": "network_error", "retryable": True}
1074
+
1075
+
1076
+ def _bind_invite_after_evm_onboard(
1077
+ invite: str,
1078
+ evm_onboard_result: dict[str, object] | None,
1079
+ *,
1080
+ api_url: str | None = None,
1081
+ opener: object = urllib.request.urlopen,
1082
+ ) -> dict[str, object] | None:
1083
+ if not invite.strip():
1084
+ return None
1085
+ if not isinstance(evm_onboard_result, dict) or not evm_onboard_result.get("ok"):
1086
+ return {"ok": False, "status": "pending_evm_wallet", "retryable": True}
1087
+ address = str(evm_onboard_result.get("address") or "").strip()
1088
+ if not address:
1089
+ return {"ok": False, "status": "pending_evm_wallet", "retryable": True}
1090
+ return _bind_welcome_invite(
1091
+ invite,
1092
+ address,
1093
+ api_url=api_url,
1094
+ opener=opener,
1095
+ )
1096
+
1097
+
1098
+ def _invite_binding_warning(binding_result: dict[str, object]) -> str:
1099
+ """Describe a failed invite bind without claiming it can always be retried."""
1100
+ status = str(binding_result.get("status") or "unknown")
1101
+ if status == "invite_already_bound":
1102
+ return (
1103
+ "warning: the welcome invite is already bound to a different Base "
1104
+ "wallet and cannot be used with this wallet. Status: "
1105
+ + status
1106
+ )
1107
+ if binding_result.get("retryable") is True:
1108
+ return (
1109
+ "warning: the welcome invite was not bound; the invite remains "
1110
+ "available for a safe retry. Status: "
1111
+ + status
1112
+ )
1113
+ return "warning: the welcome invite was not bound and cannot be retried. Status: " + status
1114
+
1115
+
1116
+ def main() -> None:
1117
+ args = build_parser().parse_args()
1118
+ source_package_root = Path(args.package_root).expanduser().resolve()
1119
+ source_extension_path = Path(args.extension_path).expanduser().resolve()
1120
+ source_wdk_evm_root = Path(args.wdk_evm_root).expanduser().resolve()
1121
+ runtime_root = Path(args.runtime_root).expanduser().resolve()
1122
+ final_runtime_root = os.getenv("OPENCLAW_INSTALL_FINAL_ROOT", "").strip()
1123
+ config_path = Path(args.config_path).expanduser()
1124
+ env_path = Path(args.env_path).expanduser()
1125
+ env_example_path = Path(args.env_example_path).expanduser()
1126
+ venv_path = Path(args.venv_path).expanduser()
1127
+ source_root = _infer_source_root(
1128
+ source_package_root,
1129
+ source_extension_path,
1130
+ source_wdk_evm_root,
1131
+ )
1132
+
1133
+ runtime_sync: dict[str, object]
1134
+ if not args.sync_runtime:
1135
+ runtime_sync = {
1136
+ "enabled": False,
1137
+ "skipped": True,
1138
+ "reason": "sync_runtime_disabled",
1139
+ "source_root": str(source_root),
1140
+ "runtime_root": str(runtime_root),
1141
+ "copied_paths": [],
1142
+ }
1143
+ elif args.dry_run:
1144
+ runtime_sync = {
1145
+ "enabled": True,
1146
+ "skipped": False,
1147
+ "reason": "dry_run",
1148
+ "source_root": str(source_root),
1149
+ "runtime_root": str(runtime_root),
1150
+ "copied_paths": INCLUDED_RUNTIME_ROOT_FILES + INCLUDED_RUNTIME_TOP_LEVEL_DIRS,
1151
+ }
1152
+ else:
1153
+ runtime_sync = _sync_runtime_tree(source_root, runtime_root)
1154
+
1155
+ if args.install_from_runtime:
1156
+ package_root = runtime_root / "agent-wallet"
1157
+ extension_path = runtime_root / ".openclaw" / "extensions" / "agent-wallet"
1158
+ wdk_evm_root = runtime_root / "wdk-evm-wallet"
1159
+ else:
1160
+ package_root = source_package_root
1161
+ extension_path = source_extension_path
1162
+ wdk_evm_root = source_wdk_evm_root
1163
+
1164
+ install_config_script = package_root / "scripts" / "install_openclaw_local_config.py"
1165
+ install_sealed_keys_script = package_root / "scripts" / "install_openclaw_sealed_keys.py"
1166
+ if args.install_from_runtime:
1167
+ default_source_env_path = source_package_root / ".env"
1168
+ default_source_venv_path = source_package_root / ".venv"
1169
+ if env_path.resolve() == default_source_env_path.resolve():
1170
+ env_path = package_root / ".env"
1171
+ if venv_path.resolve() == default_source_venv_path.resolve():
1172
+ venv_path = package_root / ".runtime-venv"
1173
+ source_env_example_path = source_package_root / ".env.example"
1174
+ if env_example_path.resolve() == source_env_example_path.resolve():
1175
+ env_example_path = package_root / ".env.example"
1176
+
1177
+ env_created = _ensure_env_file(env_path, env_example_path)
1178
+ boot_key_file_env_updated = _ensure_runtime_boot_key_file_env(env_path)
1179
+ config_created = _ensure_openclaw_config(config_path) if args.configure_openclaw else False
1180
+
1181
+ python_bin = Path(sys.executable)
1182
+ venv_created = False
1183
+ existing_wrapper = _venv_python_wrapper(venv_path)
1184
+ python_runtime: dict[str, object] = {
1185
+ "shared": False,
1186
+ "fingerprint": None,
1187
+ "shared_root": None,
1188
+ "venv_path": str(venv_path),
1189
+ "release_link_path": str(venv_path),
1190
+ "python_bin": str(_venv_python_wrapper(venv_path)),
1191
+ "action": "skipped",
1192
+ "exists": existing_wrapper.exists(),
1193
+ }
1194
+ if args.skip_python_setup and args.install_from_runtime and existing_wrapper.exists():
1195
+ python_bin = existing_wrapper
1196
+ elif not args.skip_python_setup:
1197
+ if not args.dry_run:
1198
+ python_bin, venv_created, python_runtime = _ensure_python_runtime(
1199
+ venv_path,
1200
+ package_root,
1201
+ runtime_root,
1202
+ )
1203
+ else:
1204
+ python_runtime = _python_runtime_plan(venv_path, package_root, runtime_root)
1205
+ python_bin = Path(str(python_runtime["python_bin"]))
1206
+
1207
+ node_runtime = {
1208
+ "skipped": bool(args.skip_node_setup),
1209
+ "npm_bin": args.npm_bin,
1210
+ "projects": [],
1211
+ }
1212
+ node_projects = [wdk_evm_root]
1213
+
1214
+ if not args.skip_node_setup:
1215
+ if args.dry_run:
1216
+ node_runtime["projects"] = [
1217
+ {
1218
+ **_node_runtime_plan(project_root, runtime_root),
1219
+ "command": [
1220
+ args.npm_bin,
1221
+ "ci" if (project_root / "package-lock.json").exists() else "install",
1222
+ ],
1223
+ "cache_dir": (
1224
+ os.environ.get("OPENCLAW_AGENT_WALLET_NPM_CACHE")
1225
+ or str(_resolve_openclaw_home() / "npm-cache")
1226
+ ),
1227
+ "created": False,
1228
+ }
1229
+ for project_root in node_projects
1230
+ ]
1231
+ else:
1232
+ node_runtime["projects"] = [
1233
+ _ensure_node_runtime(args.npm_bin, project_root, runtime_root)
1234
+ for project_root in node_projects
1235
+ ]
1236
+
1237
+ backend_enabled = args.backend.strip().lower() not in {"", "none"}
1238
+ pending_env = _pending_env_names() if backend_enabled else []
1239
+ configured = False
1240
+ configure_stdout = ""
1241
+ sealed_keys_result: dict[str, object] | None = None
1242
+ solana_onboard_result: dict[str, object] | None = None
1243
+ evm_onboard_result: dict[str, object] | None = None
1244
+ invite_binding_result: dict[str, object] | None = None
1245
+ if backend_enabled and not pending_env and not args.dry_run:
1246
+ sealed_result = subprocess.run(
1247
+ [str(python_bin), str(install_sealed_keys_script)],
1248
+ capture_output=True,
1249
+ text=True,
1250
+ check=True,
1251
+ )
1252
+ sealed_keys_result = json.loads(sealed_result.stdout)
1253
+ if args.configure_openclaw:
1254
+ result = subprocess.run(
1255
+ _build_next_steps(
1256
+ python_bin,
1257
+ install_config_script,
1258
+ args,
1259
+ package_root=package_root,
1260
+ extension_path=extension_path,
1261
+ ),
1262
+ capture_output=True,
1263
+ text=True,
1264
+ check=True,
1265
+ )
1266
+ configured = True
1267
+ configure_stdout = result.stdout
1268
+ solana_onboard_result = _bootstrap_solana_wallet(
1269
+ python_bin,
1270
+ package_root,
1271
+ args,
1272
+ )
1273
+ # Both wallets are provisioned on every install. EVM provisioning is
1274
+ # best-effort: a failure here must not abort the install, since the lazy
1275
+ # runtime path will create the wallet on first EVM use.
1276
+ evm_onboard_result = _bootstrap_evm_wallet(
1277
+ python_bin,
1278
+ package_root,
1279
+ args,
1280
+ wdk_evm_root,
1281
+ )
1282
+ if isinstance(evm_onboard_result, dict) and not evm_onboard_result.get("ok"):
1283
+ print(
1284
+ "warning: the EVM wallet was not provisioned during install; it will "
1285
+ "be created automatically on first EVM use. Details: "
1286
+ + str(evm_onboard_result.get("error") or "unknown"),
1287
+ file=sys.stderr,
1288
+ )
1289
+
1290
+ card_vault_result = _bootstrap_card_vault(python_bin, package_root, args)
1291
+ if card_vault_result["status"] == "attention_required":
1292
+ print(
1293
+ "warning: card vault provisioning needs attention; existing cards are preserved. "
1294
+ "Unlock the macOS login Keychain and retry, or run wallet vault migrate for a legacy vault. "
1295
+ "Card issuance will check vault readiness before payment.",
1296
+ file=sys.stderr,
1297
+ )
1298
+
1299
+ if args.invite.strip():
1300
+ if args.dry_run:
1301
+ invite_binding_result = {
1302
+ "ok": False,
1303
+ "status": "skipped_dry_run",
1304
+ "retryable": True,
1305
+ }
1306
+ else:
1307
+ invite_binding_result = _bind_invite_after_evm_onboard(
1308
+ args.invite,
1309
+ evm_onboard_result,
1310
+ )
1311
+ if invite_binding_result and not invite_binding_result.get("ok"):
1312
+ print(_invite_binding_warning(invite_binding_result), file=sys.stderr)
1313
+
1314
+ print(
1315
+ json.dumps(
1316
+ {
1317
+ "ok": True,
1318
+ "env_path": str(env_path),
1319
+ "env_created": env_created,
1320
+ "boot_key_file_env_updated": boot_key_file_env_updated,
1321
+ "config_path": str(config_path),
1322
+ "config_created": config_created,
1323
+ "configure_openclaw": bool(args.configure_openclaw),
1324
+ "package_root": str(package_root),
1325
+ "extension_path": str(extension_path),
1326
+ "wdk_evm_root": str(wdk_evm_root),
1327
+ "runtime_root": final_runtime_root or str(runtime_root),
1328
+ "staging_root": str(runtime_root) if final_runtime_root else None,
1329
+ "install_from_runtime": bool(args.install_from_runtime),
1330
+ "python_bin": str(python_bin),
1331
+ "venv_created": venv_created,
1332
+ "python_runtime": python_runtime,
1333
+ "node_runtime": node_runtime,
1334
+ "runtime_sync": runtime_sync,
1335
+ "configured": configured,
1336
+ "pending_env": pending_env,
1337
+ "sealed_keys": sealed_keys_result,
1338
+ "solana_wallet": solana_onboard_result,
1339
+ "evm_wallet": evm_onboard_result,
1340
+ "invite_binding": invite_binding_result,
1341
+ "card_vault": card_vault_result,
1342
+ "next_configure_command": _build_next_steps(
1343
+ python_bin,
1344
+ install_config_script,
1345
+ args,
1346
+ package_root=package_root,
1347
+ extension_path=extension_path,
1348
+ ),
1349
+ "configure_result": json.loads(configure_stdout) if configure_stdout else None,
1350
+ },
1351
+ indent=2,
1352
+ )
1353
+ )
1354
+
1355
+
1356
+ if __name__ == "__main__":
1357
+ main()