def compress_pubkey(pubkey: bytes) ->bytes:
    """Take a an uncompressed pubkey, return the compressed representation"""
    pub = pubkey[1:] if len(pubkey) == 65 else pubkey
    parity = (pub[-1] & 1) + 2
    compressed = bytes([parity]) + pub[:32]
    return compressed
