def compress_pub_key(pub_key: bytes) -> bytes:
    """Convert uncompressed to compressed public key."""
    if pub_key[-1] & 1:
        return b"\x03" + pub_key[1:33]

    return b"\x02" + pub_key[1:33]