@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.
- package/.claude-plugin/marketplace.json +20 -0
- package/.openclaw/AGENTS.md +100 -0
- package/.openclaw/extensions/agent-wallet/README.md +195 -0
- package/.openclaw/extensions/agent-wallet/dist/index.js +2198 -0
- package/.openclaw/extensions/agent-wallet/index.ts +2198 -0
- package/.openclaw/extensions/agent-wallet/openclaw.plugin.json +251 -0
- package/.openclaw/extensions/agent-wallet/package.json +49 -0
- package/.openclaw/extensions/agent-wallet/skills/cards/SKILL.md +211 -0
- package/.openclaw/extensions/agent-wallet/skills/wallet-operator/SKILL.md +30 -0
- package/CHANGELOG.md +1232 -0
- package/LICENSE +104 -0
- package/README.md +193 -2
- package/VERSION +1 -0
- package/agent-wallet/.env.example +63 -0
- package/agent-wallet/AGENTS.md +130 -0
- package/agent-wallet/CARD_VAULT.md +640 -0
- package/agent-wallet/README.md +615 -0
- package/agent-wallet/UPGRADE_COMPATIBILITY.md +66 -0
- package/agent-wallet/agent_wallet/__init__.py +16 -0
- package/agent-wallet/agent_wallet/approval.py +165 -0
- package/agent-wallet/agent_wallet/autonomous_permissions.py +281 -0
- package/agent-wallet/agent_wallet/autonomous_policy.py +305 -0
- package/agent-wallet/agent_wallet/autonomous_session.py +236 -0
- package/agent-wallet/agent_wallet/boot_key_migration.py +155 -0
- package/agent-wallet/agent_wallet/boot_key_recovery.py +57 -0
- package/agent-wallet/agent_wallet/bootstrap.py +194 -0
- package/agent-wallet/agent_wallet/card_catalog.py +243 -0
- package/agent-wallet/agent_wallet/card_runtime_secrets.py +108 -0
- package/agent-wallet/agent_wallet/card_vault.py +331 -0
- package/agent-wallet/agent_wallet/card_vault_cli.py +174 -0
- package/agent-wallet/agent_wallet/card_vault_import.py +65 -0
- package/agent-wallet/agent_wallet/card_vault_keychain.py +239 -0
- package/agent-wallet/agent_wallet/config.py +719 -0
- package/agent-wallet/agent_wallet/connector_cli.py +198 -0
- package/agent-wallet/agent_wallet/connectors/__init__.py +28 -0
- package/agent-wallet/agent_wallet/connectors/catalog.py +68 -0
- package/agent-wallet/agent_wallet/connectors/client.py +308 -0
- package/agent-wallet/agent_wallet/connectors/intent_policy.py +243 -0
- package/agent-wallet/agent_wallet/connectors/manifest.py +192 -0
- package/agent-wallet/agent_wallet/connectors/registry.py +341 -0
- package/agent-wallet/agent_wallet/encrypted_storage.py +314 -0
- package/agent-wallet/agent_wallet/evm_user_wallets.py +910 -0
- package/agent-wallet/agent_wallet/exceptions.py +10 -0
- package/agent-wallet/agent_wallet/file_ops.py +34 -0
- package/agent-wallet/agent_wallet/http_client.py +25 -0
- package/agent-wallet/agent_wallet/kernel_browser.py +479 -0
- package/agent-wallet/agent_wallet/kernel_cli.py +57 -0
- package/agent-wallet/agent_wallet/kernel_gateway.py +95 -0
- package/agent-wallet/agent_wallet/keystore.py +503 -0
- package/agent-wallet/agent_wallet/laso_card_vault.py +246 -0
- package/agent-wallet/agent_wallet/models.py +66 -0
- package/agent-wallet/agent_wallet/morpho_monitor.py +298 -0
- package/agent-wallet/agent_wallet/nonce_registry.py +59 -0
- package/agent-wallet/agent_wallet/openclaw_adapter.py +9129 -0
- package/agent-wallet/agent_wallet/openclaw_cli.py +658 -0
- package/agent-wallet/agent_wallet/openclaw_runtime.py +194 -0
- package/agent-wallet/agent_wallet/plugin_bundle.py +44 -0
- package/agent-wallet/agent_wallet/providers/__init__.py +1 -0
- package/agent-wallet/agent_wallet/providers/bags.py +202 -0
- package/agent-wallet/agent_wallet/providers/dexscreener.py +147 -0
- package/agent-wallet/agent_wallet/providers/evm_activity.py +257 -0
- package/agent-wallet/agent_wallet/providers/evm_portfolio.py +459 -0
- package/agent-wallet/agent_wallet/providers/imd.py +720 -0
- package/agent-wallet/agent_wallet/providers/jupiter.py +519 -0
- package/agent-wallet/agent_wallet/providers/kamino.py +404 -0
- package/agent-wallet/agent_wallet/providers/lifi.py +302 -0
- package/agent-wallet/agent_wallet/providers/solana_rpc.py +447 -0
- package/agent-wallet/agent_wallet/providers/tokenized_stocks.py +189 -0
- package/agent-wallet/agent_wallet/providers/wdk_evm_local.py +346 -0
- package/agent-wallet/agent_wallet/providers/x402.py +1972 -0
- package/agent-wallet/agent_wallet/sealed_keys.py +118 -0
- package/agent-wallet/agent_wallet/solana_stake.py +103 -0
- package/agent-wallet/agent_wallet/solana_tx.py +93 -0
- package/agent-wallet/agent_wallet/spending_limits.py +119 -0
- package/agent-wallet/agent_wallet/telemetry.py +481 -0
- package/agent-wallet/agent_wallet/transaction_policy.py +573 -0
- package/agent-wallet/agent_wallet/update_check.py +190 -0
- package/agent-wallet/agent_wallet/user_wallets.py +573 -0
- package/agent-wallet/agent_wallet/validation.py +31 -0
- package/agent-wallet/agent_wallet/vault_executor.py +456 -0
- package/agent-wallet/agent_wallet/wallet_layer/__init__.py +1 -0
- package/agent-wallet/agent_wallet/wallet_layer/base.py +1204 -0
- package/agent-wallet/agent_wallet/wallet_layer/base58.py +44 -0
- package/agent-wallet/agent_wallet/wallet_layer/factory.py +117 -0
- package/agent-wallet/agent_wallet/wallet_layer/solana.py +5246 -0
- package/agent-wallet/agent_wallet/wallet_layer/wdk_evm.py +2705 -0
- package/agent-wallet/examples/bootstrap_wallet.py +21 -0
- package/agent-wallet/examples/openclaw_runtime_onboarding.py +28 -0
- package/agent-wallet/examples/openclaw_user_wallet_example.py +31 -0
- package/agent-wallet/examples/openclaw_wallet_adapter_example.py +33 -0
- package/agent-wallet/openclaw.plugin.json +118 -0
- package/agent-wallet/pyproject.toml +36 -0
- package/agent-wallet/scripts/bootstrap_openclaw_evm.py +312 -0
- package/agent-wallet/scripts/build_release_bundle.py +210 -0
- package/agent-wallet/scripts/finalize_openclaw_local_wallet_config.py +121 -0
- package/agent-wallet/scripts/install_agent_wallet.py +1357 -0
- package/agent-wallet/scripts/install_openclaw_local_config.py +421 -0
- package/agent-wallet/scripts/install_openclaw_sealed_keys.py +117 -0
- package/agent-wallet/scripts/manage_openclaw_evm_wallet.py +333 -0
- package/agent-wallet/scripts/security_utils.py +37 -0
- package/agent-wallet/scripts/setup_evm_wallet.sh +140 -0
- package/agent-wallet/scripts/switch_openclaw_wallet_network.py +109 -0
- package/agent-wallet/skills/wallet-operator/SKILL.md +157 -0
- package/bin/lib/boot-key.mjs +184 -0
- package/bin/lib/evm-daemon.mjs +389 -0
- package/bin/lib/host-detection.mjs +259 -0
- package/bin/lib/integrations.mjs +578 -0
- package/bin/lib/release-python.mjs +9 -0
- package/bin/lib/update-transaction.mjs +235 -0
- package/bin/openclaw-agent-wallet.mjs +3354 -0
- package/claude-code/plugins/agent-wallet/.claude-plugin/plugin.json +19 -0
- package/claude-code/plugins/agent-wallet/.mcp.json +14 -0
- package/claude-code/plugins/agent-wallet/AGENTLAYER_AGENT_GUIDE.md +282 -0
- package/claude-code/plugins/agent-wallet/README.md +134 -0
- package/claude-code/plugins/agent-wallet/commands/agentlayer-autonomous-approve.md +39 -0
- package/claude-code/plugins/agent-wallet/commands/agentlayer-autonomous-revoke.md +17 -0
- package/claude-code/plugins/agent-wallet/commands/cards.md +129 -0
- package/claude-code/plugins/agent-wallet/commands/guide.md +40 -0
- package/claude-code/plugins/agent-wallet/commands/imd.md +125 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-base.md +60 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-ethereum.md +37 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-evm.md +39 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-setup.md +25 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-sol.md +51 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-statusline.md +34 -0
- package/claude-code/plugins/agent-wallet/commands/x402.md +121 -0
- package/claude-code/plugins/agent-wallet/commands/yield.md +62 -0
- package/claude-code/plugins/agent-wallet/hooks/hooks.json +16 -0
- package/claude-code/plugins/agent-wallet/scripts/bootstrap_backend.sh +136 -0
- package/claude-code/plugins/agent-wallet/scripts/enable_statusline.py +52 -0
- package/claude-code/plugins/agent-wallet/scripts/resolve_wallet_addresses.py +69 -0
- package/claude-code/plugins/agent-wallet/scripts/run_mcp.sh +66 -0
- package/claude-code/plugins/agent-wallet/scripts/wallet_statusline.py +130 -0
- package/claude-code/plugins/agent-wallet/scripts/wallet_statusline_setup.sh +40 -0
- package/claude-code/plugins/agent-wallet/skills/wallet-operator/SKILL.md +21 -0
- package/codex/plugins/agent-wallet/.codex-plugin/plugin.json +37 -0
- package/codex/plugins/agent-wallet/.mcp.json +15 -0
- package/codex/plugins/agent-wallet/README.md +158 -0
- package/codex/plugins/agent-wallet/scripts/run_mcp.sh +47 -0
- package/codex/plugins/agent-wallet/server.py +1797 -0
- package/codex/plugins/agent-wallet/skills/cards/SKILL.md +225 -0
- package/codex/plugins/agent-wallet/skills/imd/SKILL.md +145 -0
- package/codex/plugins/agent-wallet/skills/wallet-base/SKILL.md +56 -0
- package/codex/plugins/agent-wallet/skills/wallet-operator/SKILL.md +85 -0
- package/codex/plugins/agent-wallet/skills/wallet-sol/SKILL.md +29 -0
- package/codex/plugins/agent-wallet/skills/x402/SKILL.md +159 -0
- package/codex/plugins/agent-wallet/skills/yield/SKILL.md +65 -0
- package/connectors/AGENTS.md +37 -0
- package/connectors/DEVELOPER_GUIDE.md +131 -0
- package/connectors/README.md +139 -0
- package/connectors/READ_ONLY_BETA.md +54 -0
- package/connectors/RELEASING.md +48 -0
- package/connectors/conformance/README.md +31 -0
- package/connectors/conformance/package.json +54 -0
- package/connectors/conformance/scripts/sync-license.mjs +3 -0
- package/connectors/conformance/scripts/sync-spec.mjs +16 -0
- package/connectors/conformance/src/cli.ts +43 -0
- package/connectors/conformance/src/index.ts +7 -0
- package/connectors/conformance/src/runner.ts +314 -0
- package/connectors/conformance/src/types.ts +27 -0
- package/connectors/conformance/test/fixtures/invalid-response-identity.json +14 -0
- package/connectors/conformance/test/fixtures/missing-tool-fixture.json +4 -0
- package/connectors/conformance/test/runner.test.mjs +151 -0
- package/connectors/conformance/tsconfig.json +17 -0
- package/connectors/examples/reference-crypto-data/Dockerfile +21 -0
- package/connectors/examples/reference-crypto-data/README.md +51 -0
- package/connectors/examples/reference-crypto-data/conformance.json +11 -0
- package/connectors/examples/reference-crypto-data/connector.json +95 -0
- package/connectors/examples/reference-crypto-data/package.json +21 -0
- package/connectors/examples/reference-crypto-data/railway.toml +9 -0
- package/connectors/examples/reference-crypto-data/src/connector.ts +137 -0
- package/connectors/examples/reference-crypto-data/src/server.ts +13 -0
- package/connectors/examples/reference-crypto-data/test/connector.test.mjs +97 -0
- package/connectors/examples/reference-crypto-data/tsconfig.json +17 -0
- package/connectors/package-lock.json +561 -0
- package/connectors/package.json +19 -0
- package/connectors/scripts/smoke-packed-packages.mjs +121 -0
- package/connectors/sdk-typescript/README.md +47 -0
- package/connectors/sdk-typescript/package.json +49 -0
- package/connectors/sdk-typescript/scripts/sync-license.mjs +3 -0
- package/connectors/sdk-typescript/src/connector.ts +204 -0
- package/connectors/sdk-typescript/src/errors.ts +11 -0
- package/connectors/sdk-typescript/src/http.ts +116 -0
- package/connectors/sdk-typescript/src/index.ts +26 -0
- package/connectors/sdk-typescript/src/types.ts +101 -0
- package/connectors/sdk-typescript/test/sdk.test.mjs +181 -0
- package/connectors/sdk-typescript/tsconfig.json +21 -0
- package/connectors/spec/connector-manifest.schema.json +340 -0
- package/connectors/spec/connector-protocol.md +159 -0
- package/connectors/spec/transaction-intent.schema.json +281 -0
- package/connectors/templates/read-only/.env.example +1 -0
- package/connectors/templates/read-only/Dockerfile +11 -0
- package/connectors/templates/read-only/README.md +33 -0
- package/connectors/templates/read-only/conformance.json +11 -0
- package/connectors/templates/read-only/connector.json +64 -0
- package/connectors/templates/read-only/package.json +21 -0
- package/connectors/templates/read-only/railway.toml +9 -0
- package/connectors/templates/read-only/src/connector.ts +61 -0
- package/connectors/templates/read-only/src/server.ts +14 -0
- package/connectors/templates/read-only/test/connector.test.mjs +62 -0
- package/connectors/templates/read-only/tsconfig.json +17 -0
- package/cursor/plugins/agent-wallet/.cursor-plugin/plugin.json +14 -0
- package/cursor/plugins/agent-wallet/README.md +62 -0
- package/cursor/plugins/agent-wallet/mcp.json +16 -0
- package/cursor/plugins/agent-wallet/scripts/run_mcp.sh +33 -0
- package/cursor/plugins/agent-wallet/server.py +33 -0
- package/cursor/plugins/agent-wallet/skills/cards/SKILL.md +210 -0
- package/cursor/plugins/agent-wallet/skills/wallet-base/SKILL.md +56 -0
- package/cursor/plugins/agent-wallet/skills/wallet-operator/SKILL.md +23 -0
- package/cursor/plugins/agent-wallet/skills/wallet-sol/SKILL.md +29 -0
- package/cursor/plugins/agent-wallet/skills/x402/SKILL.md +130 -0
- package/hermes/plugins/agent_wallet/README.md +54 -0
- package/hermes/plugins/agent_wallet/__init__.py +55 -0
- package/hermes/plugins/agent_wallet/plugin.yaml +9 -0
- package/hermes/plugins/agent_wallet/schemas.py +211 -0
- package/hermes/plugins/agent_wallet/tools.py +622 -0
- package/install-from-github.sh +139 -0
- package/integrations/hedera/treasury-guard/README.md +92 -0
- package/integrations/hedera/treasury-guard/examples/treasury-policy.example.json +9 -0
- package/integrations/hedera/treasury-guard/package-lock.json +880 -0
- package/integrations/hedera/treasury-guard/package.json +8 -0
- package/integrations/hedera/treasury-guard/skills/onecraft-hedera-treasury/SKILL.md +22 -0
- package/integrations/hedera/treasury-guard/src/hedera-mirror-client.mjs +106 -0
- package/integrations/hedera/treasury-guard/src/hedera-signer.mjs +120 -0
- package/integrations/hedera/treasury-guard/src/treasury-cli.mjs +177 -0
- package/integrations/hedera/treasury-guard/src/treasury-policy.mjs +155 -0
- package/mcp/README.md +39 -0
- package/mcp/scripts/run_mcp.sh +37 -0
- package/mcp/server.py +33 -0
- package/package.json +106 -4
- package/scripts/check_release_version.mjs +72 -0
- package/scripts/version_targets.mjs +60 -0
- package/setup.sh +87 -0
- package/wdk-evm-wallet/.env.example +38 -0
- package/wdk-evm-wallet/README.md +254 -0
- package/wdk-evm-wallet/bootstrap.sh +8 -0
- package/wdk-evm-wallet/package-lock.json +2359 -0
- package/wdk-evm-wallet/package.json +43 -0
- package/wdk-evm-wallet/run-local.sh +12 -0
- package/wdk-evm-wallet/src/config.js +461 -0
- package/wdk-evm-wallet/src/imd.js +231 -0
- package/wdk-evm-wallet/src/json.js +35 -0
- package/wdk-evm-wallet/src/local_vault.js +407 -0
- package/wdk-evm-wallet/src/network_state.js +96 -0
- package/wdk-evm-wallet/src/pending_transactions.js +148 -0
- package/wdk-evm-wallet/src/server.js +849 -0
- package/wdk-evm-wallet/src/shutdown.js +63 -0
- package/wdk-evm-wallet/src/wdk_evm_wallet.js +10036 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""OpenClaw agent wallet package."""
|
|
2
|
+
|
|
3
|
+
# Keep in sync with package.json, pyproject.toml, and the npm installer version.
|
|
4
|
+
# scripts/check_release_version.mjs enforces this on release.
|
|
5
|
+
__version__ = "0.1.145"
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"config",
|
|
9
|
+
"exceptions",
|
|
10
|
+
"models",
|
|
11
|
+
"openclaw_runtime",
|
|
12
|
+
"providers",
|
|
13
|
+
"update_check",
|
|
14
|
+
"validation",
|
|
15
|
+
"wallet_layer",
|
|
16
|
+
]
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""Host-issued approval tokens for sensitive wallet actions."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import base64
|
|
6
|
+
import functools
|
|
7
|
+
import hashlib
|
|
8
|
+
import hmac
|
|
9
|
+
import json
|
|
10
|
+
import secrets
|
|
11
|
+
import time
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
from agent_wallet.config import resolve_approval_secret, settings
|
|
15
|
+
from agent_wallet.wallet_layer.base import WalletBackendError
|
|
16
|
+
|
|
17
|
+
APPROVAL_TOKEN_VERSION = 1
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _canonical_json(payload: dict[str, Any]) -> bytes:
|
|
21
|
+
return json.dumps(payload, sort_keys=True, separators=(",", ":")).encode("utf-8")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _urlsafe_b64(data: bytes) -> str:
|
|
25
|
+
return base64.urlsafe_b64encode(data).decode("ascii").rstrip("=")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _urlsafe_b64_decode(data: str) -> bytes:
|
|
29
|
+
padding = "=" * (-len(data) % 4)
|
|
30
|
+
return base64.urlsafe_b64decode(data + padding)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _sign_payload(payload: dict[str, Any], secret: str) -> str:
|
|
34
|
+
digest = hmac.new(secret.encode("utf-8"), _canonical_json(payload), hashlib.sha256).digest()
|
|
35
|
+
return _urlsafe_b64(digest)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@functools.lru_cache(maxsize=1)
|
|
39
|
+
def _approval_secret() -> str:
|
|
40
|
+
secret = resolve_approval_secret().strip()
|
|
41
|
+
if not secret:
|
|
42
|
+
raise WalletBackendError(
|
|
43
|
+
"Execute mode requires AGENT_WALLET_BOOT_KEY and a sealed approval_secret. "
|
|
44
|
+
"The host must issue approval tokens after explicit user confirmation."
|
|
45
|
+
)
|
|
46
|
+
return secret
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def build_operation_binding(*, tool_name: str, network: str, summary: dict[str, Any]) -> dict[str, Any]:
|
|
50
|
+
return {
|
|
51
|
+
"tool": tool_name,
|
|
52
|
+
"network": str(network).strip().lower(),
|
|
53
|
+
"summary": summary,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def issue_approval_token(
|
|
58
|
+
*,
|
|
59
|
+
tool_name: str,
|
|
60
|
+
network: str,
|
|
61
|
+
summary: dict[str, Any],
|
|
62
|
+
mainnet_confirmed: bool = False,
|
|
63
|
+
ttl_seconds: int | None = None,
|
|
64
|
+
issued_by: str = "host",
|
|
65
|
+
) -> str:
|
|
66
|
+
secret = _approval_secret()
|
|
67
|
+
now = int(time.time())
|
|
68
|
+
ttl = ttl_seconds if ttl_seconds is not None else int(settings.agent_wallet_approval_ttl_seconds)
|
|
69
|
+
if ttl <= 0:
|
|
70
|
+
raise WalletBackendError("Approval token ttl must be greater than zero.")
|
|
71
|
+
|
|
72
|
+
payload = {
|
|
73
|
+
"v": APPROVAL_TOKEN_VERSION,
|
|
74
|
+
"iat": now,
|
|
75
|
+
"exp": now + ttl,
|
|
76
|
+
"jti": secrets.token_urlsafe(16),
|
|
77
|
+
"issued_by": issued_by,
|
|
78
|
+
"binding": build_operation_binding(tool_name=tool_name, network=network, summary=summary),
|
|
79
|
+
"mainnet_confirmed": bool(mainnet_confirmed),
|
|
80
|
+
}
|
|
81
|
+
signature = _sign_payload(payload, secret)
|
|
82
|
+
return f"{_urlsafe_b64(_canonical_json(payload))}.{signature}"
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def verify_approval_token(
|
|
86
|
+
token: str,
|
|
87
|
+
*,
|
|
88
|
+
tool_name: str,
|
|
89
|
+
network: str,
|
|
90
|
+
summary: dict[str, Any],
|
|
91
|
+
require_mainnet_confirmation: bool,
|
|
92
|
+
) -> dict[str, Any]:
|
|
93
|
+
secret = _approval_secret()
|
|
94
|
+
if not isinstance(token, str) or "." not in token:
|
|
95
|
+
raise WalletBackendError("A valid approval_token is required for execute mode.")
|
|
96
|
+
|
|
97
|
+
encoded_payload, encoded_sig = token.split(".", 1)
|
|
98
|
+
try:
|
|
99
|
+
payload = json.loads(_urlsafe_b64_decode(encoded_payload).decode("utf-8"))
|
|
100
|
+
except Exception as exc:
|
|
101
|
+
raise WalletBackendError("approval_token could not be parsed.") from exc
|
|
102
|
+
|
|
103
|
+
if not isinstance(payload, dict) or int(payload.get("v") or 0) != APPROVAL_TOKEN_VERSION:
|
|
104
|
+
raise WalletBackendError("approval_token version is invalid.")
|
|
105
|
+
|
|
106
|
+
expected_sig = _sign_payload(payload, secret)
|
|
107
|
+
if not hmac.compare_digest(encoded_sig, expected_sig):
|
|
108
|
+
raise WalletBackendError("approval_token signature is invalid.")
|
|
109
|
+
|
|
110
|
+
now = int(time.time())
|
|
111
|
+
if int(payload.get("exp") or 0) < now:
|
|
112
|
+
raise WalletBackendError("approval_token has expired.")
|
|
113
|
+
|
|
114
|
+
expected_binding = build_operation_binding(tool_name=tool_name, network=network, summary=summary)
|
|
115
|
+
if payload.get("binding") != expected_binding:
|
|
116
|
+
raise WalletBackendError(
|
|
117
|
+
"approval_token does not match the requested operation. Generate a new approval after previewing the exact action."
|
|
118
|
+
)
|
|
119
|
+
if require_mainnet_confirmation and payload.get("mainnet_confirmed") is not True:
|
|
120
|
+
raise WalletBackendError("approval_token is missing explicit mainnet confirmation.")
|
|
121
|
+
return payload
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def inspect_approval_token(
|
|
125
|
+
token: str,
|
|
126
|
+
*,
|
|
127
|
+
tool_name: str,
|
|
128
|
+
network: str,
|
|
129
|
+
require_mainnet_confirmation: bool,
|
|
130
|
+
) -> dict[str, Any]:
|
|
131
|
+
secret = _approval_secret()
|
|
132
|
+
if not isinstance(token, str) or "." not in token:
|
|
133
|
+
raise WalletBackendError("A valid approval_token is required for execute mode.")
|
|
134
|
+
|
|
135
|
+
encoded_payload, encoded_sig = token.split(".", 1)
|
|
136
|
+
try:
|
|
137
|
+
payload = json.loads(_urlsafe_b64_decode(encoded_payload).decode("utf-8"))
|
|
138
|
+
except Exception as exc:
|
|
139
|
+
raise WalletBackendError("approval_token could not be parsed.") from exc
|
|
140
|
+
|
|
141
|
+
if not isinstance(payload, dict) or int(payload.get("v") or 0) != APPROVAL_TOKEN_VERSION:
|
|
142
|
+
raise WalletBackendError("approval_token version is invalid.")
|
|
143
|
+
|
|
144
|
+
expected_sig = _sign_payload(payload, secret)
|
|
145
|
+
if not hmac.compare_digest(encoded_sig, expected_sig):
|
|
146
|
+
raise WalletBackendError("approval_token signature is invalid.")
|
|
147
|
+
|
|
148
|
+
now = int(time.time())
|
|
149
|
+
if int(payload.get("exp") or 0) < now:
|
|
150
|
+
raise WalletBackendError("approval_token has expired.")
|
|
151
|
+
|
|
152
|
+
binding = payload.get("binding")
|
|
153
|
+
if not isinstance(binding, dict):
|
|
154
|
+
raise WalletBackendError("approval_token binding is invalid.")
|
|
155
|
+
if str(binding.get("tool") or "") != tool_name:
|
|
156
|
+
raise WalletBackendError(
|
|
157
|
+
"approval_token does not match the requested operation. Generate a new approval after previewing the exact action."
|
|
158
|
+
)
|
|
159
|
+
if str(binding.get("network") or "").strip().lower() != str(network).strip().lower():
|
|
160
|
+
raise WalletBackendError(
|
|
161
|
+
"approval_token does not match the requested operation. Generate a new approval after previewing the exact action."
|
|
162
|
+
)
|
|
163
|
+
if require_mainnet_confirmation and payload.get("mainnet_confirmed") is not True:
|
|
164
|
+
raise WalletBackendError("approval_token is missing explicit mainnet confirmation.")
|
|
165
|
+
return payload
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"""Persistent high-trust permission toggles for unattended wallet flows.
|
|
2
|
+
|
|
3
|
+
This module is intentionally narrower than ``autonomous_session``. It models
|
|
4
|
+
the "CLI permissions" UX where a user grants a standing capability, not a
|
|
5
|
+
budgeted policy envelope.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import time
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from agent_wallet.approval import issue_approval_token
|
|
16
|
+
from agent_wallet.config import resolve_openclaw_home
|
|
17
|
+
from agent_wallet.file_ops import atomic_write_text, chmod_if_exists
|
|
18
|
+
from agent_wallet.wallet_layer.base import WalletBackendError
|
|
19
|
+
|
|
20
|
+
PERMISSION_VERSION = 1
|
|
21
|
+
BASE_SWAP_SCOPE = "base_swaps"
|
|
22
|
+
BASE_SWAP_NETWORK = "base"
|
|
23
|
+
BASE_SWAP_TOOLS = frozenset({"swap_evm_tokens", "swap_evm_uniswap_tokens"})
|
|
24
|
+
BASE_SWAP_ISSUER = "autonomous-permission:base-swaps"
|
|
25
|
+
DEFI_TOOLS_SCOPE = "defi_tools"
|
|
26
|
+
DEFI_TOOLS_NETWORKS = frozenset({"base", "ethereum", "robinhood"})
|
|
27
|
+
DEFI_TOOLS = frozenset(
|
|
28
|
+
{
|
|
29
|
+
"manage_evm_aave_position",
|
|
30
|
+
"manage_evm_lido_position",
|
|
31
|
+
"manage_evm_lido_withdrawal",
|
|
32
|
+
"manage_evm_morpho_market_position",
|
|
33
|
+
"manage_evm_morpho_vault_position",
|
|
34
|
+
"manage_evm_uniswap_liquidity",
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
DEFI_TOOLS_ISSUER = "autonomous-permission:defi-tools"
|
|
38
|
+
ALL_TOOLS_ISSUER = "autonomous-permission:all-tools"
|
|
39
|
+
#: Canonical scope name -- the group covers every wallet write tool (see
|
|
40
|
+
#: authorize_operation), not just Base swaps or EVM DeFi. base_swaps/
|
|
41
|
+
#: defi_tools remain accepted as deprecated aliases with identical effect,
|
|
42
|
+
#: for backward compatibility with existing callers.
|
|
43
|
+
ALL_SCOPE = "all"
|
|
44
|
+
SUPPORTED_SCOPES = frozenset({ALL_SCOPE, BASE_SWAP_SCOPE, DEFI_TOOLS_SCOPE})
|
|
45
|
+
_PERMISSIONS_FILENAME = "autonomous_permissions.json"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _permissions_path() -> Path:
|
|
49
|
+
return resolve_openclaw_home() / _PERMISSIONS_FILENAME
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _now() -> int:
|
|
53
|
+
return int(time.time())
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _empty_record() -> dict[str, Any]:
|
|
57
|
+
return {"version": PERMISSION_VERSION, "scopes": {}}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _load_record() -> dict[str, Any]:
|
|
61
|
+
path = _permissions_path()
|
|
62
|
+
if not path.exists():
|
|
63
|
+
return _empty_record()
|
|
64
|
+
chmod_if_exists(path)
|
|
65
|
+
try:
|
|
66
|
+
record = json.loads(path.read_text(encoding="utf-8"))
|
|
67
|
+
except (OSError, ValueError):
|
|
68
|
+
return _empty_record()
|
|
69
|
+
if not isinstance(record, dict) or int(record.get("version") or 0) != PERMISSION_VERSION:
|
|
70
|
+
return _empty_record()
|
|
71
|
+
scopes = record.get("scopes")
|
|
72
|
+
if not isinstance(scopes, dict):
|
|
73
|
+
record["scopes"] = {}
|
|
74
|
+
return record
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _write_record(record: dict[str, Any]) -> None:
|
|
78
|
+
atomic_write_text(_permissions_path(), json.dumps(record, sort_keys=True, separators=(",", ":")))
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _scope_status(record: dict[str, Any], scope: str) -> dict[str, Any]:
|
|
82
|
+
raw = (record.get("scopes") or {}).get(scope)
|
|
83
|
+
if not isinstance(raw, dict):
|
|
84
|
+
return {"scope": scope, "enabled": False}
|
|
85
|
+
return {
|
|
86
|
+
"scope": scope,
|
|
87
|
+
"enabled": bool(raw.get("enabled")),
|
|
88
|
+
"approved_at": raw.get("approved_at"),
|
|
89
|
+
"approved_by": raw.get("approved_by"),
|
|
90
|
+
"network": raw.get("network"),
|
|
91
|
+
"networks": raw.get("networks") or ([raw.get("network")] if raw.get("network") else []),
|
|
92
|
+
"tools": raw.get("tools") or [],
|
|
93
|
+
"warning": raw.get("warning"),
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def status() -> dict[str, Any]:
|
|
98
|
+
"""Return current high-trust autonomous permission status."""
|
|
99
|
+
record = _load_record()
|
|
100
|
+
base_swaps = _scope_status(record, BASE_SWAP_SCOPE)
|
|
101
|
+
defi_tools = _scope_status(record, DEFI_TOOLS_SCOPE)
|
|
102
|
+
group_enabled = all(bool(scope.get("enabled")) for scope in (base_swaps, defi_tools))
|
|
103
|
+
return {
|
|
104
|
+
"active": group_enabled,
|
|
105
|
+
"scopes": {BASE_SWAP_SCOPE: base_swaps, DEFI_TOOLS_SCOPE: defi_tools},
|
|
106
|
+
"permission_file": str(_permissions_path()),
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _set_base_swap_scope(scopes: dict[str, Any], *, approved_by: str) -> None:
|
|
111
|
+
scopes[BASE_SWAP_SCOPE] = {
|
|
112
|
+
"enabled": True,
|
|
113
|
+
"approved_at": _now(),
|
|
114
|
+
"approved_by": str(approved_by or "user"),
|
|
115
|
+
"network": BASE_SWAP_NETWORK,
|
|
116
|
+
"tools": sorted(BASE_SWAP_TOOLS),
|
|
117
|
+
"warning": (
|
|
118
|
+
"High-trust permission: Base swap execute calls can run without "
|
|
119
|
+
"per-transaction human approval until revoked."
|
|
120
|
+
),
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _set_defi_tools_scope(scopes: dict[str, Any], *, approved_by: str) -> None:
|
|
125
|
+
scopes[DEFI_TOOLS_SCOPE] = {
|
|
126
|
+
"enabled": True,
|
|
127
|
+
"approved_at": _now(),
|
|
128
|
+
"approved_by": str(approved_by or "user"),
|
|
129
|
+
"networks": sorted(DEFI_TOOLS_NETWORKS),
|
|
130
|
+
"tools": sorted(DEFI_TOOLS),
|
|
131
|
+
"warning": (
|
|
132
|
+
"High-trust permission: supported EVM DeFi execute calls can run "
|
|
133
|
+
"without per-transaction human approval until revoked."
|
|
134
|
+
),
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def approve_all(*, approved_by: str = "user") -> dict[str, Any]:
|
|
139
|
+
"""Enable all high-trust autonomous permission scopes as one group."""
|
|
140
|
+
record = _load_record()
|
|
141
|
+
scopes = record.setdefault("scopes", {})
|
|
142
|
+
normalized_approved_by = str(approved_by or "user")
|
|
143
|
+
_set_base_swap_scope(scopes, approved_by=normalized_approved_by)
|
|
144
|
+
_set_defi_tools_scope(scopes, approved_by=normalized_approved_by)
|
|
145
|
+
_write_record(record)
|
|
146
|
+
return status()
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def approve_base_swaps(*, approved_by: str = "user") -> dict[str, Any]:
|
|
150
|
+
"""Enable all autonomous permissions; base_swaps is kept as a compatibility scope."""
|
|
151
|
+
return approve_all(approved_by=approved_by)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def approve_defi_tools(*, approved_by: str = "user") -> dict[str, Any]:
|
|
155
|
+
"""Enable all autonomous permissions; defi_tools is kept as a compatibility scope."""
|
|
156
|
+
return approve_all(approved_by=approved_by)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def revoke_base_swaps() -> dict[str, Any]:
|
|
160
|
+
"""Disable all autonomous permissions; base_swaps is kept as a compatibility scope."""
|
|
161
|
+
return revoke_all()
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def revoke_defi_tools() -> dict[str, Any]:
|
|
165
|
+
"""Disable all autonomous permissions; defi_tools is kept as a compatibility scope."""
|
|
166
|
+
return revoke_all()
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def revoke_all() -> dict[str, Any]:
|
|
170
|
+
"""Disable every high-trust autonomous permission scope as one group."""
|
|
171
|
+
record = _load_record()
|
|
172
|
+
scopes = record.setdefault("scopes", {})
|
|
173
|
+
for supported_scope in sorted(SUPPORTED_SCOPES):
|
|
174
|
+
existing = scopes.get(supported_scope)
|
|
175
|
+
if isinstance(existing, dict):
|
|
176
|
+
existing["enabled"] = False
|
|
177
|
+
existing["revoked_at"] = _now()
|
|
178
|
+
else:
|
|
179
|
+
scopes[supported_scope] = {"enabled": False, "revoked_at": _now()}
|
|
180
|
+
_write_record(record)
|
|
181
|
+
return status()
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def revoke_scope(scope: str) -> dict[str, Any]:
|
|
185
|
+
normalized_scope = str(scope or "").strip()
|
|
186
|
+
if normalized_scope not in SUPPORTED_SCOPES:
|
|
187
|
+
raise WalletBackendError("Unsupported autonomous permission scope.")
|
|
188
|
+
return revoke_all()
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def is_base_swap_approved() -> bool:
|
|
192
|
+
return bool(status()["active"])
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def is_defi_tools_approved() -> bool:
|
|
196
|
+
return bool(status()["active"])
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def authorize_base_swap(*, tool_name: str, network: str, summary: dict[str, Any]) -> str:
|
|
200
|
+
"""Issue an internal approval token for one exact Base swap operation."""
|
|
201
|
+
if str(tool_name) not in BASE_SWAP_TOOLS:
|
|
202
|
+
raise WalletBackendError("Autonomous permission only covers Base swap tools.")
|
|
203
|
+
if str(network or "").strip().lower() != BASE_SWAP_NETWORK:
|
|
204
|
+
raise WalletBackendError("Autonomous Base swap permission only applies on network=base.")
|
|
205
|
+
if not is_base_swap_approved():
|
|
206
|
+
raise WalletBackendError(
|
|
207
|
+
"Autonomous execution is not enabled. Ask the user to run "
|
|
208
|
+
"agentlayer_autonomous_approve first."
|
|
209
|
+
)
|
|
210
|
+
summary_network = str((summary or {}).get("network") or "").strip().lower()
|
|
211
|
+
if summary_network and summary_network != BASE_SWAP_NETWORK:
|
|
212
|
+
raise WalletBackendError("Autonomous Base swap summary is not bound to network=base.")
|
|
213
|
+
return issue_approval_token(
|
|
214
|
+
tool_name=tool_name,
|
|
215
|
+
network=BASE_SWAP_NETWORK,
|
|
216
|
+
summary=summary,
|
|
217
|
+
mainnet_confirmed=True,
|
|
218
|
+
ttl_seconds=120,
|
|
219
|
+
issued_by=BASE_SWAP_ISSUER,
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def is_autonomous_approved() -> bool:
|
|
224
|
+
"""Whether the combined high-trust autonomous permission group is active.
|
|
225
|
+
|
|
226
|
+
Same underlying flag as :func:`is_base_swap_approved` /
|
|
227
|
+
:func:`is_defi_tools_approved`; exposed under a name that doesn't imply a
|
|
228
|
+
narrower scope, for callers that gate every wallet tool rather than just
|
|
229
|
+
Base swaps or EVM DeFi tools.
|
|
230
|
+
"""
|
|
231
|
+
return bool(status()["active"])
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def authorize_operation(*, tool_name: str, network: str, summary: dict[str, Any]) -> str:
|
|
235
|
+
"""Issue an internal approval token for any wallet tool/network once the
|
|
236
|
+
combined high-trust autonomous permission group is enabled.
|
|
237
|
+
|
|
238
|
+
Unlike :func:`authorize_base_swap` / :func:`authorize_defi_tool`, this has
|
|
239
|
+
no per-tool or per-network allow-list -- the group toggle enabled by
|
|
240
|
+
``agentlayer_autonomous_approve`` is the only gate. Callers are expected to
|
|
241
|
+
have already built ``summary`` from a live preview/quote, matching every
|
|
242
|
+
other execute path's binding contract.
|
|
243
|
+
"""
|
|
244
|
+
if not is_autonomous_approved():
|
|
245
|
+
raise WalletBackendError(
|
|
246
|
+
"Autonomous execution is not enabled. Ask the user to run "
|
|
247
|
+
"agentlayer_autonomous_approve first."
|
|
248
|
+
)
|
|
249
|
+
return issue_approval_token(
|
|
250
|
+
tool_name=str(tool_name),
|
|
251
|
+
network=str(network or "").strip().lower(),
|
|
252
|
+
summary=summary,
|
|
253
|
+
mainnet_confirmed=True,
|
|
254
|
+
ttl_seconds=120,
|
|
255
|
+
issued_by=ALL_TOOLS_ISSUER,
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def authorize_defi_tool(*, tool_name: str, network: str, summary: dict[str, Any]) -> str:
|
|
260
|
+
"""Issue an internal approval token for one exact EVM DeFi operation."""
|
|
261
|
+
normalized_network = str(network or "").strip().lower()
|
|
262
|
+
if str(tool_name) not in DEFI_TOOLS:
|
|
263
|
+
raise WalletBackendError("Autonomous DeFi permission only covers supported EVM DeFi tools.")
|
|
264
|
+
if normalized_network not in DEFI_TOOLS_NETWORKS:
|
|
265
|
+
raise WalletBackendError("Autonomous DeFi permission only applies on ethereum, base, or robinhood.")
|
|
266
|
+
if not is_defi_tools_approved():
|
|
267
|
+
raise WalletBackendError(
|
|
268
|
+
"Autonomous execution is not enabled. Ask the user to run "
|
|
269
|
+
"agentlayer_autonomous_approve first."
|
|
270
|
+
)
|
|
271
|
+
summary_network = str((summary or {}).get("network") or "").strip().lower()
|
|
272
|
+
if summary_network and summary_network != normalized_network:
|
|
273
|
+
raise WalletBackendError("Autonomous DeFi summary is not bound to the active network.")
|
|
274
|
+
return issue_approval_token(
|
|
275
|
+
tool_name=tool_name,
|
|
276
|
+
network=normalized_network,
|
|
277
|
+
summary=summary,
|
|
278
|
+
mainnet_confirmed=True,
|
|
279
|
+
ttl_seconds=120,
|
|
280
|
+
issued_by=DEFI_TOOLS_ISSUER,
|
|
281
|
+
)
|