@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,243 @@
|
|
|
1
|
+
"""Fail-closed local policy for unsigned write-capable connector intents."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from datetime import datetime, timezone
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from agent_wallet.connectors.manifest import DIGEST_PATTERN, validate_connector_manifest
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
EVM_ADDRESS_PATTERN = re.compile(r"^0x[0-9a-fA-F]{40}$")
|
|
13
|
+
HEX_DATA_PATTERN = re.compile(r"^0x(?:[0-9a-fA-F]{2})*$")
|
|
14
|
+
UINT_PATTERN = re.compile(r"^(0|[1-9][0-9]*)$")
|
|
15
|
+
ERC20_APPROVE_SELECTOR = "0x095ea7b3"
|
|
16
|
+
MAX_UINT256 = (1 << 256) - 1
|
|
17
|
+
MAX_INTENT_LIFETIME_SECONDS = 300
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ConnectorIntentPolicyError(ValueError):
|
|
21
|
+
"""Raised when a connector write intent is unsafe or incorrectly bound."""
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _require_object(value: Any, field: str) -> dict[str, Any]:
|
|
25
|
+
if not isinstance(value, dict):
|
|
26
|
+
raise ConnectorIntentPolicyError(f"{field} must be an object.")
|
|
27
|
+
return value
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _require_uint(value: Any, field: str, *, positive: bool = False) -> int:
|
|
31
|
+
if not isinstance(value, str) or not UINT_PATTERN.fullmatch(value):
|
|
32
|
+
raise ConnectorIntentPolicyError(f"{field} must be an unsigned integer string.")
|
|
33
|
+
number = int(value)
|
|
34
|
+
if number >= 1 << 256:
|
|
35
|
+
raise ConnectorIntentPolicyError(f"{field} exceeds uint256.")
|
|
36
|
+
if positive and number <= 0:
|
|
37
|
+
raise ConnectorIntentPolicyError(f"{field} must be greater than zero.")
|
|
38
|
+
return number
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _require_address(value: Any, field: str) -> str:
|
|
42
|
+
if not isinstance(value, str) or not EVM_ADDRESS_PATTERN.fullmatch(value):
|
|
43
|
+
raise ConnectorIntentPolicyError(f"{field} must be an EVM address.")
|
|
44
|
+
return value.lower()
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _validate_expiry(value: Any) -> str:
|
|
48
|
+
if not isinstance(value, str) or not value:
|
|
49
|
+
raise ConnectorIntentPolicyError("expires_at is required.")
|
|
50
|
+
try:
|
|
51
|
+
expiry = datetime.fromisoformat(value.replace("Z", "+00:00"))
|
|
52
|
+
except ValueError as exc:
|
|
53
|
+
raise ConnectorIntentPolicyError("expires_at is invalid.") from exc
|
|
54
|
+
if expiry.tzinfo is None:
|
|
55
|
+
raise ConnectorIntentPolicyError("expires_at must include a timezone.")
|
|
56
|
+
remaining = (expiry.astimezone(timezone.utc) - datetime.now(timezone.utc)).total_seconds()
|
|
57
|
+
if remaining <= 0:
|
|
58
|
+
raise ConnectorIntentPolicyError("Connector intent has expired.")
|
|
59
|
+
if remaining > MAX_INTENT_LIFETIME_SECONDS:
|
|
60
|
+
raise ConnectorIntentPolicyError("Connector intent expiry exceeds the allowed lifetime.")
|
|
61
|
+
return value
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _evm_contract_policy(manifest: dict[str, Any], chain_id: int) -> dict[str, set[str]]:
|
|
65
|
+
result: dict[str, set[str]] = {}
|
|
66
|
+
for raw_policy in manifest.get("chains") or []:
|
|
67
|
+
if not isinstance(raw_policy, dict) or raw_policy.get("chain") != "evm":
|
|
68
|
+
continue
|
|
69
|
+
chain_ids = raw_policy.get("chain_ids")
|
|
70
|
+
if not isinstance(chain_ids, list) or chain_id not in chain_ids:
|
|
71
|
+
continue
|
|
72
|
+
for raw_contract in raw_policy.get("contracts") or []:
|
|
73
|
+
if not isinstance(raw_contract, dict) or raw_contract.get("chain_id") != chain_id:
|
|
74
|
+
continue
|
|
75
|
+
address = _require_address(raw_contract.get("address"), "manifest contract address")
|
|
76
|
+
selectors = raw_contract.get("selectors")
|
|
77
|
+
if not isinstance(selectors, list) or not selectors:
|
|
78
|
+
raise ConnectorIntentPolicyError("Manifest contract selectors are missing.")
|
|
79
|
+
result[address] = {str(selector).lower() for selector in selectors}
|
|
80
|
+
if not result:
|
|
81
|
+
raise ConnectorIntentPolicyError(f"Connector is not allowed on EVM chain {chain_id}.")
|
|
82
|
+
return result
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _write_tool(manifest: dict[str, Any], tool_name: Any) -> dict[str, Any]:
|
|
86
|
+
if not isinstance(tool_name, str):
|
|
87
|
+
raise ConnectorIntentPolicyError("tool is required.")
|
|
88
|
+
for tool in manifest["tools"]:
|
|
89
|
+
if isinstance(tool, dict) and tool.get("name") == tool_name:
|
|
90
|
+
if tool.get("read_only") is True:
|
|
91
|
+
raise ConnectorIntentPolicyError("A read-only connector tool cannot return an intent.")
|
|
92
|
+
return tool
|
|
93
|
+
raise ConnectorIntentPolicyError(f"Connector write tool is not declared: {tool_name}.")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def validate_evm_transaction_intent(
|
|
97
|
+
manifest_payload: dict[str, Any],
|
|
98
|
+
intent_payload: dict[str, Any],
|
|
99
|
+
*,
|
|
100
|
+
wallet_address: str,
|
|
101
|
+
) -> dict[str, Any]:
|
|
102
|
+
"""Validate an unsigned EVM intent and return an approval-safe summary.
|
|
103
|
+
|
|
104
|
+
This function does not simulate, sign, approve, or broadcast. Its output is
|
|
105
|
+
suitable as input to the later simulation and preview binding layers.
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
manifest = validate_connector_manifest(manifest_payload)
|
|
109
|
+
intent = _require_object(intent_payload, "intent")
|
|
110
|
+
if manifest["trust"] != "verified_write":
|
|
111
|
+
raise ConnectorIntentPolicyError("Only verified_write connectors may return intents.")
|
|
112
|
+
if manifest["permissions"].get("transaction_intents") is not True:
|
|
113
|
+
raise ConnectorIntentPolicyError("Connector is not permitted to return transaction intents.")
|
|
114
|
+
if intent.get("protocol_version") != 1 or intent.get("kind") != "evm_transaction_intent":
|
|
115
|
+
raise ConnectorIntentPolicyError("Unsupported EVM connector intent version or kind.")
|
|
116
|
+
if intent.get("connector_id") != manifest["id"]:
|
|
117
|
+
raise ConnectorIntentPolicyError("Connector intent id does not match the manifest.")
|
|
118
|
+
if intent.get("connector_version") != manifest["version"]:
|
|
119
|
+
raise ConnectorIntentPolicyError("Connector intent version does not match the manifest.")
|
|
120
|
+
if intent.get("artifact_digest") != manifest.get("artifact_digest"):
|
|
121
|
+
raise ConnectorIntentPolicyError("Connector intent artifact digest does not match.")
|
|
122
|
+
quote_fingerprint = intent.get("quote_fingerprint")
|
|
123
|
+
if not isinstance(quote_fingerprint, str) or not DIGEST_PATTERN.fullmatch(quote_fingerprint):
|
|
124
|
+
raise ConnectorIntentPolicyError("quote_fingerprint must be a lowercase sha256 digest.")
|
|
125
|
+
tool = _write_tool(manifest, intent.get("tool"))
|
|
126
|
+
expires_at = _validate_expiry(intent.get("expires_at"))
|
|
127
|
+
|
|
128
|
+
chain_id = intent.get("chain_id")
|
|
129
|
+
if not isinstance(chain_id, int) or isinstance(chain_id, bool) or chain_id <= 0:
|
|
130
|
+
raise ConnectorIntentPolicyError("chain_id must be a positive integer.")
|
|
131
|
+
contract_policy = _evm_contract_policy(manifest, chain_id)
|
|
132
|
+
expected_wallet = _require_address(wallet_address, "wallet_address")
|
|
133
|
+
intent_from = _require_address(intent.get("from"), "from")
|
|
134
|
+
if intent_from != expected_wallet:
|
|
135
|
+
raise ConnectorIntentPolicyError("Connector intent from address does not match the wallet.")
|
|
136
|
+
|
|
137
|
+
calls = intent.get("calls")
|
|
138
|
+
if not isinstance(calls, list) or not 1 <= len(calls) <= 16:
|
|
139
|
+
raise ConnectorIntentPolicyError("calls must contain between 1 and 16 entries.")
|
|
140
|
+
normalized_calls: list[dict[str, Any]] = []
|
|
141
|
+
for index, raw_call in enumerate(calls):
|
|
142
|
+
call = _require_object(raw_call, f"calls[{index}]")
|
|
143
|
+
target = _require_address(call.get("to"), f"calls[{index}].to")
|
|
144
|
+
selectors = contract_policy.get(target)
|
|
145
|
+
if selectors is None:
|
|
146
|
+
raise ConnectorIntentPolicyError(f"calls[{index}] targets an unapproved contract.")
|
|
147
|
+
data = call.get("data")
|
|
148
|
+
if not isinstance(data, str) or not HEX_DATA_PATTERN.fullmatch(data) or len(data) < 10:
|
|
149
|
+
raise ConnectorIntentPolicyError(f"calls[{index}].data must contain EVM calldata.")
|
|
150
|
+
selector = data[:10].lower()
|
|
151
|
+
if selector == ERC20_APPROVE_SELECTOR:
|
|
152
|
+
raise ConnectorIntentPolicyError(
|
|
153
|
+
"Connector intents must declare approvals separately from protocol calls."
|
|
154
|
+
)
|
|
155
|
+
if selector not in selectors:
|
|
156
|
+
raise ConnectorIntentPolicyError(f"calls[{index}] uses an unapproved selector.")
|
|
157
|
+
value_wei = _require_uint(call.get("value_wei"), f"calls[{index}].value_wei")
|
|
158
|
+
normalized_calls.append(
|
|
159
|
+
{
|
|
160
|
+
"to": target,
|
|
161
|
+
"selector": selector,
|
|
162
|
+
"value_wei": str(value_wei),
|
|
163
|
+
"calldata_bytes": (len(data) - 2) // 2,
|
|
164
|
+
}
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
approvals = intent.get("approvals")
|
|
168
|
+
if not isinstance(approvals, list) or len(approvals) > 16:
|
|
169
|
+
raise ConnectorIntentPolicyError("approvals must be an array of at most 16 entries.")
|
|
170
|
+
normalized_approvals: list[dict[str, str]] = []
|
|
171
|
+
for index, raw_approval in enumerate(approvals):
|
|
172
|
+
approval = _require_object(raw_approval, f"approvals[{index}]")
|
|
173
|
+
token = _require_address(approval.get("token"), f"approvals[{index}].token")
|
|
174
|
+
spender = _require_address(approval.get("spender"), f"approvals[{index}].spender")
|
|
175
|
+
if spender not in contract_policy:
|
|
176
|
+
raise ConnectorIntentPolicyError(f"approvals[{index}] uses an unapproved spender.")
|
|
177
|
+
amount = _require_uint(
|
|
178
|
+
approval.get("amount_raw"), f"approvals[{index}].amount_raw", positive=True
|
|
179
|
+
)
|
|
180
|
+
if amount == MAX_UINT256:
|
|
181
|
+
raise ConnectorIntentPolicyError("Unlimited connector token approvals are prohibited.")
|
|
182
|
+
normalized_approvals.append(
|
|
183
|
+
{
|
|
184
|
+
"token": token,
|
|
185
|
+
"spender": spender,
|
|
186
|
+
"amount_raw": str(amount),
|
|
187
|
+
}
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
effects = intent.get("expected_effects")
|
|
191
|
+
if not isinstance(effects, list) or not 1 <= len(effects) <= 64:
|
|
192
|
+
raise ConnectorIntentPolicyError("expected_effects must contain between 1 and 64 entries.")
|
|
193
|
+
normalized_effects: list[dict[str, Any]] = []
|
|
194
|
+
for index, raw_effect in enumerate(effects):
|
|
195
|
+
effect = _require_object(raw_effect, f"expected_effects[{index}]")
|
|
196
|
+
effect_type = effect.get("type")
|
|
197
|
+
if effect_type not in {"asset", "debt", "position", "protocol_fee", "network_fee"}:
|
|
198
|
+
raise ConnectorIntentPolicyError(f"expected_effects[{index}].type is unsupported.")
|
|
199
|
+
direction = effect.get("direction")
|
|
200
|
+
if direction not in {"debit", "credit", "increase", "decrease"}:
|
|
201
|
+
raise ConnectorIntentPolicyError(f"expected_effects[{index}].direction is unsupported.")
|
|
202
|
+
asset = effect.get("asset")
|
|
203
|
+
if not isinstance(asset, str) or not asset.strip() or len(asset) > 128:
|
|
204
|
+
raise ConnectorIntentPolicyError(f"expected_effects[{index}].asset is invalid.")
|
|
205
|
+
amount = _require_uint(effect.get("amount"), f"expected_effects[{index}].amount")
|
|
206
|
+
normalized_effects.append(
|
|
207
|
+
{
|
|
208
|
+
"type": effect_type,
|
|
209
|
+
"asset": asset.strip(),
|
|
210
|
+
"direction": direction,
|
|
211
|
+
"amount": str(amount),
|
|
212
|
+
**(
|
|
213
|
+
{"recipient": str(effect["recipient"])}
|
|
214
|
+
if isinstance(effect.get("recipient"), str) and effect["recipient"]
|
|
215
|
+
else {}
|
|
216
|
+
),
|
|
217
|
+
}
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
return {
|
|
221
|
+
"operation": "AgentLayer connector EVM transaction",
|
|
222
|
+
"connector_id": str(manifest["id"]),
|
|
223
|
+
"connector_version": str(manifest["version"]),
|
|
224
|
+
"artifact_digest": str(manifest["artifact_digest"]),
|
|
225
|
+
"tool": str(tool["name"]),
|
|
226
|
+
"chain": "evm",
|
|
227
|
+
"chain_id": chain_id,
|
|
228
|
+
"from": expected_wallet,
|
|
229
|
+
"quote_fingerprint": quote_fingerprint,
|
|
230
|
+
"expires_at": expires_at,
|
|
231
|
+
"calls": normalized_calls,
|
|
232
|
+
"approvals": normalized_approvals,
|
|
233
|
+
"expected_effects": normalized_effects,
|
|
234
|
+
"validation": {
|
|
235
|
+
"verified_connector": True,
|
|
236
|
+
"wallet_bound": True,
|
|
237
|
+
"targets_allowlisted": True,
|
|
238
|
+
"selectors_allowlisted": True,
|
|
239
|
+
"approvals_bounded": True,
|
|
240
|
+
"simulated": False,
|
|
241
|
+
},
|
|
242
|
+
}
|
|
243
|
+
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"""Fail-closed validation for OneCraft Connector manifests."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import copy
|
|
6
|
+
import re
|
|
7
|
+
from typing import Any
|
|
8
|
+
from urllib.parse import urlparse
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
CONNECTOR_ID_PATTERN = re.compile(r"^[a-z0-9]+(?:[._-][a-z0-9]+)+$")
|
|
12
|
+
TOOL_NAME_PATTERN = re.compile(r"^[a-z][a-z0-9_]{1,63}$")
|
|
13
|
+
SEMVER_PATTERN = re.compile(
|
|
14
|
+
r"^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)"
|
|
15
|
+
r"(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$"
|
|
16
|
+
)
|
|
17
|
+
DIGEST_PATTERN = re.compile(r"^sha256:[0-9a-f]{64}$")
|
|
18
|
+
|
|
19
|
+
TRUST_CLASSES = frozenset(
|
|
20
|
+
{
|
|
21
|
+
"community_read_only",
|
|
22
|
+
"verified_read_only",
|
|
23
|
+
"verified_write",
|
|
24
|
+
"local_development",
|
|
25
|
+
}
|
|
26
|
+
)
|
|
27
|
+
READ_ONLY_TRUST_CLASSES = frozenset({"community_read_only", "verified_read_only"})
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class ConnectorManifestError(ValueError):
|
|
31
|
+
"""Raised when a connector manifest violates the public contract."""
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _require_dict(value: Any, field: str) -> dict[str, Any]:
|
|
35
|
+
if not isinstance(value, dict):
|
|
36
|
+
raise ConnectorManifestError(f"{field} must be an object.")
|
|
37
|
+
return value
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _require_nonempty_string(value: Any, field: str, *, max_length: int) -> str:
|
|
41
|
+
if not isinstance(value, str) or not value.strip():
|
|
42
|
+
raise ConnectorManifestError(f"{field} must be a non-empty string.")
|
|
43
|
+
normalized = value.strip()
|
|
44
|
+
if len(normalized) > max_length:
|
|
45
|
+
raise ConnectorManifestError(f"{field} exceeds the maximum length of {max_length}.")
|
|
46
|
+
return normalized
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _require_https_url(value: Any, field: str) -> str:
|
|
50
|
+
url = _require_nonempty_string(value, field, max_length=2048)
|
|
51
|
+
parsed = urlparse(url)
|
|
52
|
+
if parsed.scheme != "https" or not parsed.hostname or parsed.username or parsed.password:
|
|
53
|
+
raise ConnectorManifestError(f"{field} must be an HTTPS URL without embedded credentials.")
|
|
54
|
+
if parsed.fragment:
|
|
55
|
+
raise ConnectorManifestError(f"{field} must not contain a fragment.")
|
|
56
|
+
return url
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _validate_tools(manifest: dict[str, Any]) -> None:
|
|
60
|
+
tools = manifest.get("tools")
|
|
61
|
+
if not isinstance(tools, list) or not tools:
|
|
62
|
+
raise ConnectorManifestError("tools must be a non-empty array.")
|
|
63
|
+
if len(tools) > 64:
|
|
64
|
+
raise ConnectorManifestError("tools cannot contain more than 64 entries.")
|
|
65
|
+
|
|
66
|
+
names: set[str] = set()
|
|
67
|
+
read_only_trust = manifest["trust"] in READ_ONLY_TRUST_CLASSES
|
|
68
|
+
for index, raw_tool in enumerate(tools):
|
|
69
|
+
tool = _require_dict(raw_tool, f"tools[{index}]")
|
|
70
|
+
name = _require_nonempty_string(tool.get("name"), f"tools[{index}].name", max_length=64)
|
|
71
|
+
if not TOOL_NAME_PATTERN.fullmatch(name):
|
|
72
|
+
raise ConnectorManifestError(f"tools[{index}].name has an invalid format.")
|
|
73
|
+
if name in names:
|
|
74
|
+
raise ConnectorManifestError(f"Duplicate connector tool name: {name}.")
|
|
75
|
+
names.add(name)
|
|
76
|
+
_require_nonempty_string(
|
|
77
|
+
tool.get("description"), f"tools[{index}].description", max_length=500
|
|
78
|
+
)
|
|
79
|
+
if not isinstance(tool.get("read_only"), bool):
|
|
80
|
+
raise ConnectorManifestError(f"tools[{index}].read_only must be boolean.")
|
|
81
|
+
if read_only_trust and tool["read_only"] is not True:
|
|
82
|
+
raise ConnectorManifestError(
|
|
83
|
+
f"{manifest['trust']} connectors may expose only read-only tools."
|
|
84
|
+
)
|
|
85
|
+
if tool.get("risk_level") not in {"low", "medium", "high"}:
|
|
86
|
+
raise ConnectorManifestError(
|
|
87
|
+
f"tools[{index}].risk_level must be low, medium, or high."
|
|
88
|
+
)
|
|
89
|
+
_require_dict(tool.get("input_schema"), f"tools[{index}].input_schema")
|
|
90
|
+
_require_dict(tool.get("output_schema"), f"tools[{index}].output_schema")
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _validate_permissions(manifest: dict[str, Any]) -> None:
|
|
94
|
+
permissions = _require_dict(manifest.get("permissions"), "permissions")
|
|
95
|
+
for field in ("wallet_address", "transaction_intents"):
|
|
96
|
+
if not isinstance(permissions.get(field), bool):
|
|
97
|
+
raise ConnectorManifestError(f"permissions.{field} must be boolean.")
|
|
98
|
+
network_hosts = permissions.get("network_hosts")
|
|
99
|
+
if not isinstance(network_hosts, list) or len(network_hosts) > 32:
|
|
100
|
+
raise ConnectorManifestError("permissions.network_hosts must be an array of at most 32 hosts.")
|
|
101
|
+
normalized_hosts: set[str] = set()
|
|
102
|
+
for index, host in enumerate(network_hosts):
|
|
103
|
+
normalized = _require_nonempty_string(
|
|
104
|
+
host, f"permissions.network_hosts[{index}]", max_length=253
|
|
105
|
+
).lower()
|
|
106
|
+
if "://" in normalized or "/" in normalized or "@" in normalized:
|
|
107
|
+
raise ConnectorManifestError(
|
|
108
|
+
f"permissions.network_hosts[{index}] must be a hostname, not a URL."
|
|
109
|
+
)
|
|
110
|
+
normalized_hosts.add(normalized)
|
|
111
|
+
if len(normalized_hosts) != len(network_hosts):
|
|
112
|
+
raise ConnectorManifestError("permissions.network_hosts must not contain duplicates.")
|
|
113
|
+
|
|
114
|
+
trust = manifest["trust"]
|
|
115
|
+
if trust in READ_ONLY_TRUST_CLASSES and permissions["transaction_intents"] is not False:
|
|
116
|
+
raise ConnectorManifestError(f"{trust} connectors cannot request transaction intents.")
|
|
117
|
+
if trust == "verified_write" and permissions["transaction_intents"] is not True:
|
|
118
|
+
raise ConnectorManifestError(
|
|
119
|
+
"verified_write connectors must explicitly request transaction_intents."
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def validate_connector_manifest(payload: Any) -> dict[str, Any]:
|
|
124
|
+
"""Validate and return a detached connector manifest.
|
|
125
|
+
|
|
126
|
+
JSON Schema remains the public contract. This validator intentionally
|
|
127
|
+
duplicates the security-sensitive invariants needed before registry writes,
|
|
128
|
+
avoiding a runtime dependency on a general-purpose schema engine.
|
|
129
|
+
"""
|
|
130
|
+
|
|
131
|
+
manifest = copy.deepcopy(_require_dict(payload, "manifest"))
|
|
132
|
+
if manifest.get("schema_version") != 1:
|
|
133
|
+
raise ConnectorManifestError("schema_version must be 1.")
|
|
134
|
+
|
|
135
|
+
connector_id = _require_nonempty_string(manifest.get("id"), "id", max_length=128)
|
|
136
|
+
if not CONNECTOR_ID_PATTERN.fullmatch(connector_id):
|
|
137
|
+
raise ConnectorManifestError("id has an invalid format.")
|
|
138
|
+
_require_nonempty_string(manifest.get("name"), "name", max_length=80)
|
|
139
|
+
|
|
140
|
+
version = _require_nonempty_string(manifest.get("version"), "version", max_length=64)
|
|
141
|
+
if not SEMVER_PATTERN.fullmatch(version):
|
|
142
|
+
raise ConnectorManifestError("version must be valid semantic version text.")
|
|
143
|
+
|
|
144
|
+
trust = manifest.get("trust")
|
|
145
|
+
if trust not in TRUST_CLASSES:
|
|
146
|
+
raise ConnectorManifestError(f"Unsupported connector trust class: {trust!r}.")
|
|
147
|
+
|
|
148
|
+
publisher = _require_dict(manifest.get("publisher"), "publisher")
|
|
149
|
+
_require_nonempty_string(publisher.get("id"), "publisher.id", max_length=64)
|
|
150
|
+
_require_nonempty_string(publisher.get("name"), "publisher.name", max_length=80)
|
|
151
|
+
|
|
152
|
+
agentlayer = _require_dict(manifest.get("agentlayer"), "agentlayer")
|
|
153
|
+
if agentlayer.get("protocol_version") != 1:
|
|
154
|
+
raise ConnectorManifestError("agentlayer.protocol_version must be 1.")
|
|
155
|
+
_require_nonempty_string(
|
|
156
|
+
agentlayer.get("runtime_range"), "agentlayer.runtime_range", max_length=100
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
transport = _require_dict(manifest.get("transport"), "transport")
|
|
160
|
+
if transport.get("type") != "https":
|
|
161
|
+
raise ConnectorManifestError("transport.type must be https.")
|
|
162
|
+
_require_https_url(transport.get("url"), "transport.url")
|
|
163
|
+
timeout_ms = transport.get("timeout_ms", 10000)
|
|
164
|
+
if (
|
|
165
|
+
not isinstance(timeout_ms, int)
|
|
166
|
+
or isinstance(timeout_ms, bool)
|
|
167
|
+
or not 100 <= timeout_ms <= 30000
|
|
168
|
+
):
|
|
169
|
+
raise ConnectorManifestError("transport.timeout_ms must be an integer from 100 to 30000.")
|
|
170
|
+
|
|
171
|
+
digest = manifest.get("artifact_digest")
|
|
172
|
+
if digest is not None and (
|
|
173
|
+
not isinstance(digest, str) or not DIGEST_PATTERN.fullmatch(digest)
|
|
174
|
+
):
|
|
175
|
+
raise ConnectorManifestError("artifact_digest must be a lowercase sha256 digest.")
|
|
176
|
+
if trust == "verified_write" and not digest:
|
|
177
|
+
raise ConnectorManifestError("verified_write connectors require artifact_digest.")
|
|
178
|
+
|
|
179
|
+
_validate_permissions(manifest)
|
|
180
|
+
_validate_tools(manifest)
|
|
181
|
+
return manifest
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def connector_tool_name(connector_id: str, tool_name: str) -> str:
|
|
185
|
+
"""Return the stable host-facing tool namespace for a connector tool."""
|
|
186
|
+
|
|
187
|
+
if not CONNECTOR_ID_PATTERN.fullmatch(connector_id):
|
|
188
|
+
raise ConnectorManifestError("id has an invalid format.")
|
|
189
|
+
if not TOOL_NAME_PATTERN.fullmatch(tool_name):
|
|
190
|
+
raise ConnectorManifestError("tool name has an invalid format.")
|
|
191
|
+
normalized_id = re.sub(r"[^a-z0-9]+", "_", connector_id).strip("_")
|
|
192
|
+
return f"connector__{normalized_id}__{tool_name}"
|