1 Commits
Author SHA1 Message Date
Abhishek Krishna 849764ccc4 feat(web3): src/ tree MPC-wallet parity (closes #3, unblocks #4)
Ports the MPC-signing integration shape from PR #4 (sdk/python tree)
into the parallel src/agents/extensions/web3 tree so issue #3 is closed
on both code paths.

Adds:
  * src/agents/extensions/web3/mpc_client.py — async, pydantic-typed
    HTTP client for a hanzoai/mpc bridge (mirrors the sdk/python
    interface introduced in PR #4 byte-for-byte: same MpcConfig,
    KeygenResult, SignResult, VerifyResult, same /v1/{keygen,sign,verify}
    wire protocol, same retry/backoff semantics, same MpcError).
  * src/agents/extensions/web3/tests/test_wallet_mpc.py — 20 tests
    covering the MPC client (happy paths, 4xx no-retry, 5xx retry &
    exhaust, api-key header, hex validation), EIP-191 sign/verify
    round-trip on AgentWallet, MPC routing only when configured, and
    Web3Wallet.call_contract calldata forwarding.

Changes:
  * src/agents/extensions/web3/wallet.py
      - call_contract: replaces NotImplementedError with a real
        web3.py ABI-driven call. Supports read (eth_call) and write
        (sign + send) paths. Accepts an explicit ABI or synthesizes a
        minimal one from a Solidity-style signature.
      - verify_signature: replaces return True placeholder TODO with
        eth_account.Account.recover_message + encode_defunct (EIP-191).
        Returns False on malformed input rather than raising.
      - sign_message: now produces EIP-191 signatures (matches
        Account.sign_message), so the verify side round-trips. Adds
        sign_digest for raw-hash signing.
      - MockWallet: backed by a real eth_account.Account so signing
        round-trips through verify_signature in tests.
      - AgentWallet: optional mpc_client= constructor arg, has_mpc
        property, async sign_via_mpc() routes a digest through the
        cluster when configured.
  * src/agents/extensions/web3/__init__.py — re-exports the new MPC
    symbols and Web3Wallet/MockWallet; documents why Web3Agent /
    Web3Network are deferred (they reference Agent.InferenceResult /
    State which moved during the src/agents refactor — out of scope
    here, follow-up).

Verification:
  * pytest src/agents/extensions/web3/tests/ -v  ->  20 passed
  * pytest tests/  ->  316 passed (no regression)
  * ruff check src/agents/extensions/web3/{mpc_client,wallet,__init__}.py
    src/agents/extensions/web3/tests/  ->  all checks passed

Refs:
  * Issue #3 — web3 extension: implement MPC-signing integration
  * PR #4 — sdk/python parallel: feat(web3): MPC-signing integration
2026-06-01 11:34:42 +00:00