示例#1
0
 def ecdsa_raw_sign(self, msg_hash, private_key):
     signature = self.keys.PrivateKey(private_key).sign_recoverable(
         msg_hash, hasher=None)
     v = safe_ord(signature[64]) + 27
     r = big_endian_to_int(signature[0:32])
     s = big_endian_to_int(signature[32:64])
     return v, r, s
示例#2
0
def _unpack(message: AnyStr) -> Tuple[datatypes.PublicKey, int, List[Any], AnyStr]:
    """Unpack a UDP message received from a remote node.

    Returns the public key used to sign the message, the cmd ID, payload and hash.
    """
    message_hash = message[:MAC_SIZE]
    if message_hash != keccak(message[MAC_SIZE:]):
        raise WrongMAC("Wrong msg mac")
    signature = keys.Signature(message[MAC_SIZE:HEAD_SIZE])
    signed_data = message[HEAD_SIZE:]
    remote_pubkey = signature.recover_public_key_from_msg(signed_data)
    cmd_id = safe_ord(message[HEAD_SIZE])
    cmd = CMD_ID_MAP[cmd_id]
    payload = rlp.decode(message[HEAD_SIZE + 1:], strict=False)
    # Ignore excessive list elements as required by EIP-8.
    payload = payload[:cmd.elem_count]
    return remote_pubkey, cmd_id, payload, message_hash
示例#3
0
def remove_chars(s, chars):
    d = {safe_ord(c): None for c in chars}
    return s.translate(d)