Skip to main content

clanker-wallet

Python SDK for Clanker Wallet — E2E encrypted transaction approval for AI agents.

An AI agent proposes transactions, a human reviews and signs them via the web app. All communication is end-to-end encrypted using x25519 + nacl.box. EVM chains take raw transactions (request_tx); bitcoin and chia take transfers (request_transfer) that the human's wallet builds.

Install

pip install clanker-wallet

Requires Python 3.10+.

request_tx() and request_transfer() open a WebSocket to the relay in the pairing JSON (wss://relay.clanker-wallet.xyz/ws). In a sandbox or behind a firewall, allow that host, or it raises RelayError. HTTPS_PROXY is honored with websockets 15 or newer.

Quick Start

import asyncio
from clanker_wallet import ClankerWallet, Transaction, RequestTxOptions, TxContext

async def main():
    # Create agent (generates new x25519 identity keypair)
    agent = ClankerWallet()

    # Pair with human's wallet — JSON from the prompt the human pasted
    # (or scanned from the QR on https://clanker-wallet.xyz)
    agent.pair(pairing_json)

    # Request a transaction: 0.001 ETH on Base Sepolia
    tx_hash = await agent.request_tx(RequestTxOptions(
        chain_id=84532,
        transaction=Transaction(
            to="0x000000000000000000000000000000000000dEaD",
            value="1000000000000000",  # 0.001 ETH in wei
            data="0x",
        ),
        context=TxContext(reason="Payment for service"),
    ))
    print(f"Approved: {tx_hash}")

asyncio.run(main())

Persistence

Save and restore agent identity across sessions:

# Save the 32-byte secret key (store securely)
secret = agent.secret_key

# Restore later — same keypair, same agent_id
agent = ClankerWallet(secret_key=secret)

API Reference

ClankerWallet

The main client class. Each instance represents an AI agent identity.

ClankerWallet(*, agent_name=None, secret_key=None)
Parameter Type Description
agent_name str | None Optional display name for this agent
secret_key bytes | None 32-byte x25519 secret key to restore identity. Omit to generate new.

Properties:

Property Type Description
public_key bytes 32-byte x25519 public key
secret_key bytes 32-byte x25519 secret key
signing_public_key bytes 32-byte Ed25519 public key (derived from secret)
agent_id str Deterministic ID: agent_{pubkey_hex[:12]}
paired bool Whether pair() has been called

Methods:

pair(pairing_json: str) -> PairingData

Parse the pairing JSON from the web app (also matches what the QR code encodes). Stores the human's public key and relay URL.

pairing = agent.pair('{"version":1,"pubkey":"ab12...","relay":"wss://relay.example/ws","wallet":"0x..."}')
print(pairing.relay)   # wss://relay.example/ws
print(pairing.wallet)  # 0x...

Raises PairingError if JSON is invalid or version != 1. The web app's bitcoin and chia tabs give pairing JSON with "chain_family":"bitcoin" / "chain_family":"chia"; it is kept in PairingData.chain_family and decides what request_transfer() sends.

async request_tx(options: RequestTxOptions) -> str

Send an encrypted transaction request to the paired human. Blocks until the human approves, rejects, or the timeout expires.

Returns the on-chain transaction hash on approval. Raises InvalidTxError before anything is sent if chain_id, to, value or data is malformed.

tx_hash = await agent.request_tx(RequestTxOptions(
    chain_id=84532,
    transaction=Transaction(to="0x000000000000000000000000000000000000dEaD", value="0", data="0x"),
    context=TxContext(reason="swap tokens"),
    timeout_ms=60_000,  # 1 minute (default: 1 hour)
))

async request_transfer(options: RequestTransferOptions) -> str

Send bitcoin or chia through a bitcoin or chia pairing: the human's wallet builds, signs and broadcasts the transaction. Returns the bitcoin txid or chia transaction id on approval; rejection, timeout and relay errors raise as for request_tx().

Raises InvalidTxError before anything is sent for an evm pairing, an unknown chain_network, a recipient from another network (bitcoin: segwit bc1.../tb1... only), a non-integer amount, or a bitcoin fee (bitcoin wallets set their own).

from clanker_wallet import RequestTransferOptions, Transfer

# with a chia pairing: 1000 mojos on testnet11
tx_id = await agent.request_transfer(RequestTransferOptions(
    chain_network="testnet11",
    transfer=Transfer(asset="xch", to="txch1qqqsyqcyq5rqwzqfpg9scrgwpugpzysnzs23v9ccrydpk8qarc0sw0amhg", amount=1000, fee=0),
    context=TxContext(reason="pay for the api call"),
))

Types

All types are dataclass(slots=True) for performance.

Transaction

Transaction(to: str, value: str | int, data: str = "0x")
  • to — recipient address: 0x + 40 hex characters; mixed case must pass the EIP-55 checksum
  • value — whole number of wei, as a decimal string or int (not ETH, no decimals) (the js sdk takes a decimal string or bigint instead; a js number is rejected)
  • data — calldata, 0x + even-length hex (defaults to 0x)

TxContext

Optional context to help the human understand the request.

TxContext(reason=None, urgency=None, expected_outcome=None)

RequestTxOptions

RequestTxOptions(chain_id: int, transaction: Transaction, context=None, timeout_ms=None)
  • timeout_ms — defaults to 3,600,000 (1 hour)

Transfer

Transfer(asset: str, to: str, amount: str | int, fee: str | int | None = None)
  • asset — "btc" or "xch", matching the pairing's family
  • to — bech32/bech32m address on chain_network: bc1... (bitcoin mainnet), tb1... (testnet, signet), xch1..., txch1...
  • amount — whole sats or mojos, as a decimal string or int (1 BTC = 100,000,000 sats; 1 XCH = 1,000,000,000,000 mojos)
  • fee — chia only, in mojos; defaults to 0 and is shown to the human

RequestTransferOptions

RequestTransferOptions(chain_network: str, transfer: Transfer, context=None, timeout_ms=None)
  • chain_network — bitcoin: "mainnet", "testnet", "signet"; chia: "mainnet", "testnet11". There is no default network.

PairingData

Returned by pair().

PairingData(version: int, pubkey: str, relay: str, wallet: str, mode: str | None = None, chain_family: str | None = None, chain_network: str | None = None)
  • mode — "managed" (the relay also gets the tx fields to simulate) or "encrypted" / None (ciphertext only)
  • chain_family — "bitcoin" or "chia"; None for an evm pairing
  • chain_network — set when the pairing names one; request_transfer() then refuses other networks

Errors

All errors inherit from ClankerError.

Error When Attributes
ClankerError Base class —
NotPairedError request_tx() / request_transfer() called before pair() —
TxRejectedError Human rejected the transaction request_id
TxTimeoutError No response within timeout request_id, timeout_ms
TxError Transaction failed on-chain request_id, error
PairingError Invalid pairing data —
InvalidTxError Malformed tx or transfer request (also a ValueError); nothing was sent field, reason
RelayError WebSocket connection issues —
from clanker_wallet import TxRejectedError, TxTimeoutError, TxError

try:
    tx_hash = await agent.request_tx(options)
except TxRejectedError:
    print("Human said no")
except TxTimeoutError as e:
    print(f"Timed out after {e.timeout_ms}ms")
except TxError as e:
    print(f"On-chain failure: {e.error}")

Crypto Utilities

Low-level crypto functions are exported for advanced use cases (e.g. building custom protocols on top of the relay).

from clanker_wallet import (
    generate_keypair,      # -> BoxKeyPair (x25519)
    keypair_from_secret,   # bytes -> BoxKeyPair
    encrypt_message,       # (msg, recipient_pub, sender_sk) -> base64
    decrypt_message,       # (b64, sender_pub, recipient_sk) -> str | None
    signing_keypair_from_seed,  # bytes -> SignKeyPair (Ed25519)
    sign_message,          # (msg, sk) -> base64 signature
    verify_signature,      # (msg, b64_sig, pk) -> bool
    to_hex, from_hex,      # bytes <-> hex
    bytes_to_base64, base64_to_bytes,
)

How It Works

  1. Human opens the web app, connects wallet, derives an x25519 keypair, copies a paste-ready prompt (or scans the QR) containing the pairing JSON
  2. Agent calls pair(pairing_json) — stores human's public key + relay URL
  3. Agent calls request_tx() — encrypts a TxRequest with nacl.box, sends via WebSocket relay
  4. Human's web app decrypts, displays tx details, runs simulation/risk checks
  5. Human approves → wallet signs + broadcasts → encrypted TxResponse with tx hash sent back
  6. Agent receives tx hash, returns it from request_tx()

All messages are encrypted end-to-end. The relay server never sees plaintext, except in managed mode (PairingData.mode == "managed"), where request_tx() also sends the transaction fields to the relay for simulation.

Development

cd python
pip install -e ".[dev]"

# Run tests
pytest -v

# Type checking (strict mode)
mypy clanker_wallet/

# Build package
python -m build

License

MIT

Metadata

Release files for clanker-wallet 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clanker-wallet 0.2.0
File Size Uploaded Provenance Actions
clanker_wallet-0.2.0.tar.gz 30.6 kB Without provenance Details for clanker_wallet-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for clanker-wallet 0.2.0
File Interpreter ABI Platform Actions
clanker_wallet-0.2.0-py3-none-any.whl Python 3 none any Details for clanker_wallet-0.2.0-py3-none-any.whl

Total release size: 50.4 kB

Release files / clanker_wallet-0.2.0.tar.gz

Download URL clanker_wallet-0.2.0.tar.gz
Size 30.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c66ff99a7235bb10b93760d3f8359b05f2c3df657c545ec7ad3d5e71088f0b78
BLAKE2b-256 checksum
How to use checksums
a116a8ef0c677199b59e27ceb4a7701ac789fc8391d4f37dc24e376c2455ee13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Release files / clanker_wallet-0.2.0-py3-none-any.whl

Download URL clanker_wallet-0.2.0-py3-none-any.whl
Size 19.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8ea07a11827a810bee249e1a7c41e8db829c48316d6fee28fab02a42e95ffe85
BLAKE2b-256 checksum
How to use checksums
a693b4fdc502fd0a7817eb322c302a1182eaf8e93a544e20c621e39b04312ae0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Security for clanker-wallet 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page