Commit Graph

4 Commits

Author SHA1 Message Date
Shannon Sands
253c7abbe9 fix(wallet): harden keystore fallback, persist policy/history, wire gateway injection
Addresses review findings:
- Remove insecure automatic encrypted-file credential-store fallback.
   now only uses real OS/keyctl-backed stores,
  or remains unavailable. Headless users must use explicit
  HERMES_KEYSTORE_PASSPHRASE if desired.
- Add shared wallet runtime so tools/CLI/approval use the same configured
  providers and persisted policy state.
- Inject keystore-backed secrets into gateway/headless startup too, so
  migrated .env stubs don't break messaging deployments.
- Persist wallet policy state (freeze, daily totals, rate-limit timestamps,
  cooldown timestamps) across invocations.
- Persist transaction history to disk across invocations.
- Make owner-approved sends execute through the same runtime/policy path and
  record policy state after successful approved sends.
- Fix wallet export by allowing explicit CLI export reads of sealed keys via
  dedicated requester path () instead of generic CLI reads.
- Make CLI wallet sends evaluate policy before execution and honor freeze.
- Align docs with actual crypto primitive (XSalsa20-Poly1305 via SecretBox)
  and current policy-config scope.

Validation:
- 129 tests passing
- freeze persistence verified manually
- wallet export verified manually
2026-03-29 08:38:29 +10:00
Shannon Sands
7e1a05b475 feat: wallet approval flow, export command, improved create/import UX
Approval system:
- wallet/approval.py: PendingWalletTx stash, submit_pending(), pop_pending(),
  execute_approved() — mirrors the dangerous-command approval pattern
- tools/wallet_tool.py: wallet_send now stashes pending txs when policy
  returns require_approval (using task_id as session key)
- cli.py: Post-agent-loop check for pending wallet approvals, invokes
  wallet_approval_callback for interactive TUI prompt, executes on approve
- hermes_cli/callbacks.py: wallet_approval_callback — TUI prompt showing
  tx details with approve/deny choices (matches approval_callback pattern)
- gateway/run.py: Picks up pending wallet txs after agent response, shows
  approval hint with /approve /deny. /approve handler dispatches wallet tx
  execution via execute_approved().

Export/Import:
- wallet/manager.py: export_private_key() — CLI-only, never agent-exposed
- wallet/cli.py: 'hermes wallet export' with passphrase re-entry confirmation,
  safety warnings, import instructions. Import updated with --type flag and
  migration-focused messaging.

UX improvements:
- Create messaging emphasizes fresh wallets + funding over personal wallet import
- Import framed as migration tool, not personal wallet onboarding

Tested: approval stash/execute path confirmed on Solana mainnet
2026-03-29 08:38:29 +10:00
Shannon Sands
53acc4c238 feat: add wallet_address + wallet_networks tools, config.yaml RPC overrides
New agent-facing tools:
- wallet_address: Get a wallet's deposit address for receiving funds
- wallet_networks: List all supported chains (mainnet + testnet) and
  which ones have active wallets

Improvements:
- RPC endpoint overrides from config.yaml (wallet.rpc_endpoints section)
- Better module docstring with full tool inventory
- Toolset updated with all 7 tools

Tested end-to-end with Hermes agent on Solana mainnet:
- Agent correctly discovers and uses all 7 wallet tools
- Policy engine properly gates user wallet sends (require_approval)
- Balance checks, address sharing, network listing all working
2026-03-29 08:38:29 +10:00
Shannon Sands
ffefd57719 feat: add wallet module — manager, policy engine, chain providers, tools, CLI
Phase 2 of the wallet architecture — crypto wallet functionality built
on top of the keystore.

Core components:
- wallet/manager.py: Wallet CRUD, balance checks, transaction execution.
  Private keys stored as sealed keystore secrets — only the manager reads
  them, and only to pass to chain providers for signing.
- wallet/policy.py: Transaction policy engine with spending limits, daily
  limits, rate limits, cooldown, recipient allow/blocklists, approval
  thresholds, and a kill switch (freeze/unfreeze).
- wallet/chains/: Abstract ChainProvider interface + EVM and Solana impls.
  EVM supports Ethereum, Base, Polygon, Arbitrum, Optimism + testnets.
  Solana supports mainnet + devnet.

Agent integration:
- tools/wallet_tool.py: 5 agent-facing tools (wallet_list, wallet_balance,
  wallet_send, wallet_history, wallet_estimate_gas). All return JSON,
  none expose private keys. wallet_send goes through the policy engine.
- toolsets.py: New 'wallet' toolset
- model_tools.py: wallet_tool added to discovery list

CLI:
- wallet/cli.py: Full CLI — create, create-agent, import, list, balance,
  send (with interactive confirmation), fund, history, freeze, unfreeze, status
- hermes_cli/main.py: 'hermes wallet' subcommand registered

Policy defaults:
- Agent wallets: 1.0 native/tx max, 5.0/day, 5 txns/hour, 30s cooldown,
  approval required above 0.5 native
- User wallets: owner approval required for all transactions

Tests: 100 passing (28 wallet + 72 keystore)
2026-03-29 08:38:21 +10:00