@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,346 @@
1
+ """Client helpers for the local wdk-evm-wallet service."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from pathlib import Path
7
+ from typing import Any
8
+ from urllib.parse import urlparse
9
+
10
+ import httpx
11
+
12
+ from agent_wallet.config import resolve_evm_wallet_password, resolve_openclaw_home, settings
13
+ from agent_wallet.wallet_layer.base import WalletBackendError
14
+
15
+ LOCAL_WDK_EVM_HOSTS = {"127.0.0.1", "localhost", "::1"}
16
+ # The local service may decrypt the sealed vault and make several upstream RPC
17
+ # calls for a single wallet operation (for example, token metadata plus a gas
18
+ # quote). The global HTTP default is deliberately short for ordinary external
19
+ # providers, but it is too short for this local wallet boundary.
20
+ MIN_LOCAL_WDK_EVM_TIMEOUT_SECONDS = 60.0
21
+ LONG_RUNNING_POST_PATHS = {
22
+ "/v1/evm/imd/approve/send",
23
+ "/v1/evm/aave/supply/send",
24
+ "/v1/evm/aave/withdraw/send",
25
+ "/v1/evm/aave/borrow/send",
26
+ "/v1/evm/aave/repay/send",
27
+ "/v1/evm/morpho/vault/supply/quote",
28
+ "/v1/evm/morpho/vault/supply/send",
29
+ "/v1/evm/morpho/vault/withdraw/quote",
30
+ "/v1/evm/morpho/vault/withdraw/send",
31
+ "/v1/evm/morpho/market/supply_collateral/quote",
32
+ "/v1/evm/morpho/market/supply_collateral/send",
33
+ "/v1/evm/morpho/market/borrow/quote",
34
+ "/v1/evm/morpho/market/borrow/send",
35
+ "/v1/evm/morpho/market/repay/quote",
36
+ "/v1/evm/morpho/market/repay/send",
37
+ "/v1/evm/morpho/market/withdraw_collateral/quote",
38
+ "/v1/evm/morpho/market/withdraw_collateral/send",
39
+ "/v1/evm/lido/stake_eth_for_wsteth/send",
40
+ "/v1/evm/lido/wrap_steth/send",
41
+ "/v1/evm/lido/unwrap_wsteth/send",
42
+ "/v1/evm/lido/request_withdrawal_steth/send",
43
+ "/v1/evm/lido/request_withdrawal_wsteth/send",
44
+ "/v1/evm/lido/claim_withdrawal/send",
45
+ "/v1/evm/swap/quote",
46
+ "/v1/evm/swap/send",
47
+ "/v1/evm/uniswap/swap/quote",
48
+ "/v1/evm/uniswap/swap/send",
49
+ "/v1/evm/uniswap/liquidity/quote",
50
+ "/v1/evm/uniswap/liquidity/send",
51
+ "/v1/evm/lifi/quote",
52
+ "/v1/evm/lifi/send",
53
+ "/v1/evm/transfer/send",
54
+ "/v1/evm/token-transfer/send",
55
+ }
56
+ LONG_RUNNING_SEND_TIMEOUT_SECONDS = 120.0
57
+
58
+
59
+ def _error_details_from_payload(payload: dict[str, Any]) -> dict[str, Any] | None:
60
+ details = payload.get("error_details")
61
+ return dict(details) if isinstance(details, dict) else None
62
+
63
+
64
+ def _normalize_base_url(value: str) -> str:
65
+ text = str(value or "").strip()
66
+ if not text:
67
+ raise WalletBackendError("WDK EVM service URL is not configured.")
68
+ parsed = urlparse(text)
69
+ if parsed.scheme == "unix":
70
+ if not parsed.path:
71
+ raise WalletBackendError("WDK EVM unix socket URL must include a path.")
72
+ return text
73
+ if parsed.scheme not in {"http", "https"} or parsed.hostname not in LOCAL_WDK_EVM_HOSTS:
74
+ raise WalletBackendError("WDK EVM service URL must point to a localhost HTTP endpoint.")
75
+ return text.rstrip("/")
76
+
77
+
78
+ def _httpx_target(base_url: str, path: str) -> tuple[str, dict[str, Any]]:
79
+ """Return (url, extra_httpx_client_kwargs) for either transport."""
80
+ parsed = urlparse(base_url)
81
+ if parsed.scheme == "unix":
82
+ return (
83
+ f"http://wdk-evm-wallet.local{path}",
84
+ {"transport": httpx.HTTPTransport(uds=parsed.path)},
85
+ )
86
+ return (f"{base_url}{path}", {})
87
+
88
+
89
+ def _async_httpx_target(base_url: str, path: str) -> tuple[str, dict[str, Any]]:
90
+ parsed = urlparse(base_url)
91
+ if parsed.scheme == "unix":
92
+ return (
93
+ f"http://wdk-evm-wallet.local{path}",
94
+ {"transport": httpx.AsyncHTTPTransport(uds=parsed.path)},
95
+ )
96
+ return (f"{base_url}{path}", {})
97
+
98
+
99
+ def _resolve_local_token_path() -> Path:
100
+ configured = os.getenv("WDK_EVM_LOCAL_TOKEN_PATH", "").strip()
101
+ if configured:
102
+ return Path(configured).expanduser()
103
+ return resolve_openclaw_home() / "wdk-evm-wallet" / "local-auth-token"
104
+
105
+
106
+ def _load_local_token() -> str:
107
+ direct = os.getenv("WDK_EVM_LOCAL_TOKEN", "").strip()
108
+ if direct:
109
+ return direct
110
+ token_path = _resolve_local_token_path()
111
+ if not token_path.exists():
112
+ raise WalletBackendError(
113
+ f"WDK EVM local auth token file not found: {token_path}. Start the local wdk-evm-wallet service first."
114
+ )
115
+ token = token_path.read_text(encoding="utf-8").strip()
116
+ if not token:
117
+ raise WalletBackendError(f"WDK EVM local auth token file is empty: {token_path}")
118
+ return token
119
+
120
+
121
+ def _timeout_for_path(path: str) -> float:
122
+ normalized = str(path or "").strip()
123
+ base_timeout = max(float(settings.http_timeout), MIN_LOCAL_WDK_EVM_TIMEOUT_SECONDS)
124
+ if normalized in LONG_RUNNING_POST_PATHS:
125
+ return max(base_timeout, LONG_RUNNING_SEND_TIMEOUT_SECONDS)
126
+ return base_timeout
127
+
128
+
129
+ def _unwrap_payload(response: httpx.Response) -> dict[str, Any]:
130
+ try:
131
+ payload = response.json()
132
+ except Exception as exc: # pragma: no cover - defensive
133
+ raise WalletBackendError(
134
+ f"wdk-evm-wallet returned a non-JSON response ({response.status_code}).",
135
+ code="network_unavailable",
136
+ details={
137
+ "service": "wdk-evm-wallet",
138
+ "http_status": response.status_code,
139
+ },
140
+ ) from exc
141
+ if response.status_code >= 400 or payload.get("ok") is False:
142
+ detail = payload.get("error") or f"HTTP {response.status_code}"
143
+ raise WalletBackendError(
144
+ str(detail),
145
+ code=str(payload.get("error_code") or "").strip() or None,
146
+ details=_error_details_from_payload(payload),
147
+ )
148
+ data = payload.get("data")
149
+ if not isinstance(data, dict):
150
+ raise WalletBackendError("wdk-evm-wallet returned an invalid response payload.")
151
+ return data
152
+
153
+
154
+ def _unwrap_list_payload(response: httpx.Response) -> list[dict[str, Any]]:
155
+ try:
156
+ payload = response.json()
157
+ except Exception as exc: # pragma: no cover - defensive
158
+ raise WalletBackendError(
159
+ f"wdk-evm-wallet returned a non-JSON response ({response.status_code}).",
160
+ code="network_unavailable",
161
+ details={
162
+ "service": "wdk-evm-wallet",
163
+ "http_status": response.status_code,
164
+ },
165
+ ) from exc
166
+ if response.status_code >= 400 or payload.get("ok") is False:
167
+ detail = payload.get("error") or f"HTTP {response.status_code}"
168
+ raise WalletBackendError(
169
+ str(detail),
170
+ code=str(payload.get("error_code") or "").strip() or None,
171
+ details=_error_details_from_payload(payload),
172
+ )
173
+ data = payload.get("data")
174
+ if not isinstance(data, list):
175
+ raise WalletBackendError("wdk-evm-wallet returned an invalid list response payload.")
176
+ wallets: list[dict[str, Any]] = []
177
+ for item in data:
178
+ if isinstance(item, dict):
179
+ wallets.append(dict(item))
180
+ return wallets
181
+
182
+
183
+ class WdkEvmLocalClient:
184
+ """Small client for the local EVM wallet service."""
185
+
186
+ def __init__(self, base_url: str):
187
+ self.base_url = _normalize_base_url(base_url)
188
+ self._headers = {
189
+ "Accept": "application/json",
190
+ "Authorization": f"Bearer {_load_local_token()}",
191
+ }
192
+ self._wallet_password: str | None = None
193
+
194
+ def _resolve_wallet_password(self) -> str:
195
+ """Resolve the sealed local EVM vault password once per client instance.
196
+
197
+ The decrypt-on-demand vault needs the password on every signing request.
198
+ Resolving (and unsealing) it once per client keeps the Argon2id unseal off
199
+ the per-request path. The agent already holds the boot key, so caching the
200
+ derived password here adds no exposure beyond what the boot key grants.
201
+ """
202
+ if self._wallet_password is None:
203
+ try:
204
+ self._wallet_password = resolve_evm_wallet_password() or ""
205
+ except Exception:
206
+ self._wallet_password = ""
207
+ return self._wallet_password
208
+
209
+ def _with_credentials(self, payload: dict[str, Any]) -> dict[str, Any]:
210
+ """Attach the sealed vault password unless the caller supplied one.
211
+
212
+ Read endpoints that resolve via a stored address ignore the field; only
213
+ seed-requiring (signing) endpoints consume it. Injecting it uniformly means
214
+ no signing path can accidentally be missed.
215
+ """
216
+ if not isinstance(payload, dict) or payload.get("password"):
217
+ return payload
218
+ password = self._resolve_wallet_password()
219
+ if not password:
220
+ return payload
221
+ return {**payload, "password": password}
222
+
223
+ async def post(self, path: str, payload: dict[str, Any]) -> dict[str, Any]:
224
+ url, transport_kwargs = _async_httpx_target(self.base_url, path)
225
+ try:
226
+ async with httpx.AsyncClient(
227
+ timeout=_timeout_for_path(path),
228
+ headers=self._headers,
229
+ follow_redirects=False,
230
+ trust_env=False,
231
+ **transport_kwargs,
232
+ ) as client:
233
+ response = await client.post(url, json=self._with_credentials(payload))
234
+ except httpx.TimeoutException as exc:
235
+ raise WalletBackendError(
236
+ "wdk-evm-wallet request timed out.",
237
+ code="network_unavailable",
238
+ details={"service": "wdk-evm-wallet", "path": path},
239
+ ) from exc
240
+ except httpx.RequestError as exc:
241
+ raise WalletBackendError(
242
+ f"wdk-evm-wallet request failed: {exc}",
243
+ code="network_unavailable",
244
+ details={"service": "wdk-evm-wallet", "path": path},
245
+ ) from exc
246
+ return _unwrap_payload(response)
247
+
248
+ async def get(self, path: str) -> dict[str, Any]:
249
+ url, transport_kwargs = _async_httpx_target(self.base_url, path)
250
+ try:
251
+ async with httpx.AsyncClient(
252
+ timeout=_timeout_for_path(path),
253
+ headers=self._headers,
254
+ follow_redirects=False,
255
+ trust_env=False,
256
+ **transport_kwargs,
257
+ ) as client:
258
+ response = await client.get(url)
259
+ except httpx.TimeoutException as exc:
260
+ raise WalletBackendError(
261
+ "wdk-evm-wallet request timed out.",
262
+ code="network_unavailable",
263
+ details={"service": "wdk-evm-wallet", "path": path},
264
+ ) from exc
265
+ except httpx.RequestError as exc:
266
+ raise WalletBackendError(
267
+ f"wdk-evm-wallet request failed: {exc}",
268
+ code="network_unavailable",
269
+ details={"service": "wdk-evm-wallet", "path": path},
270
+ ) from exc
271
+ return _unwrap_payload(response)
272
+
273
+ def post_sync(self, path: str, payload: dict[str, Any]) -> dict[str, Any]:
274
+ url, transport_kwargs = _httpx_target(self.base_url, path)
275
+ try:
276
+ with httpx.Client(
277
+ timeout=_timeout_for_path(path),
278
+ headers=self._headers,
279
+ follow_redirects=False,
280
+ trust_env=False,
281
+ **transport_kwargs,
282
+ ) as client:
283
+ response = client.post(url, json=self._with_credentials(payload))
284
+ except httpx.TimeoutException as exc:
285
+ raise WalletBackendError(
286
+ "wdk-evm-wallet request timed out.",
287
+ code="network_unavailable",
288
+ details={"service": "wdk-evm-wallet", "path": path},
289
+ ) from exc
290
+ except httpx.RequestError as exc:
291
+ raise WalletBackendError(
292
+ f"wdk-evm-wallet request failed: {exc}",
293
+ code="network_unavailable",
294
+ details={"service": "wdk-evm-wallet", "path": path},
295
+ ) from exc
296
+ return _unwrap_payload(response)
297
+
298
+ def get_sync(self, path: str) -> dict[str, Any]:
299
+ url, transport_kwargs = _httpx_target(self.base_url, path)
300
+ try:
301
+ with httpx.Client(
302
+ timeout=_timeout_for_path(path),
303
+ headers=self._headers,
304
+ follow_redirects=False,
305
+ trust_env=False,
306
+ **transport_kwargs,
307
+ ) as client:
308
+ response = client.get(url)
309
+ except httpx.TimeoutException as exc:
310
+ raise WalletBackendError(
311
+ "wdk-evm-wallet request timed out.",
312
+ code="network_unavailable",
313
+ details={"service": "wdk-evm-wallet", "path": path},
314
+ ) from exc
315
+ except httpx.RequestError as exc:
316
+ raise WalletBackendError(
317
+ f"wdk-evm-wallet request failed: {exc}",
318
+ code="network_unavailable",
319
+ details={"service": "wdk-evm-wallet", "path": path},
320
+ ) from exc
321
+ return _unwrap_payload(response)
322
+
323
+ def list_wallets_sync(self) -> list[dict[str, Any]]:
324
+ url, transport_kwargs = _httpx_target(self.base_url, "/v1/evm/wallets")
325
+ try:
326
+ with httpx.Client(
327
+ timeout=_timeout_for_path("/v1/evm/wallets"),
328
+ headers=self._headers,
329
+ follow_redirects=False,
330
+ trust_env=False,
331
+ **transport_kwargs,
332
+ ) as client:
333
+ response = client.get(url)
334
+ except httpx.TimeoutException as exc:
335
+ raise WalletBackendError(
336
+ "wdk-evm-wallet request timed out.",
337
+ code="network_unavailable",
338
+ details={"service": "wdk-evm-wallet", "path": "/v1/evm/wallets"},
339
+ ) from exc
340
+ except httpx.RequestError as exc:
341
+ raise WalletBackendError(
342
+ f"wdk-evm-wallet request failed: {exc}",
343
+ code="network_unavailable",
344
+ details={"service": "wdk-evm-wallet", "path": "/v1/evm/wallets"},
345
+ ) from exc
346
+ return _unwrap_list_payload(response)