degenbot.crypto =============== .. py:module:: degenbot.crypto .. autoapi-nested-parse:: EVM hashing + selector helpers — the stable mirror home for crypto surfaces. Provides three public functions: - :func:`function_selector` — the 4-byte Solidity selector for a function signature. Delegates to :func:`degenbot.contract.get_function_selector` (alloy ``keccak256`` under the hood) so the selector computation is owned by Rust, not by a Python keccak re-export. - :func:`keccak256` — the full 32-byte keccak digest of a byte string. Delegates to the Rust FFI ``keccak256`` pyfunction; parity with the pre-removal eth_utils vectors is pinned in ``tests/test_crypto_parity.py``. - :func:`event_topic` — the 32-byte event topic hash for an ABI event entry. Computes ``keccak256(canonical_event_signature)`` in Rust from the ABI entry dict. Package Contents ---------------- .. py:function:: function_selector(signature: str) -> bytes Return the 4-byte Solidity function selector for ``signature``. :param signature: A Solidity function signature, e.g. ``"transfer(address,uint256)"``. :returns: The 4-byte selector (e.g. ``b"\\xa9\\x05\\x9c\\xbb"``). .. py:function:: keccak256(data: bytes) -> bytes Return the 32-byte keccak256 digest of ``data``. :param data: The input bytes to hash. :returns: The 32-byte digest as plain ``bytes`` (callers wanting the 0x-prefixed string use :func:`degenbot.utils.bytes.to_0x_hex`). .. py:function:: event_topic(event_abi_entry: degenbot.types.chain.ABIEvent) -> bytes Return the 32-byte event topic hash for an ABI event entry. Replaces ``Web3().eth.contract(abi=...).events.().topic``. Computes ``keccak256(canonical_event_signature)`` from the ABI entry (the canonical signature omits ``indexed`` markers and uses the parameter types in order), so the result is byte-identical to the web3-derived topic without importing web3. :param event_abi_entry: A single ABI dict with ``"type": "event"``. :returns: The 32-byte topic as plain ``bytes``.