from typing import Union


def hex256(x: Union[int, str]) -> str:
    """Hex encodes values up to 256 bits into a fixed length

    By including this amount of leading zeros in the hex string, lexicographic
    and numeric ordering are identical. This facilitates working with these
    numbers in the database without native uint256 support.
    """
    if isinstance(x, str):
        x = int(x)
    return "0x{:064x}".format(x)