def extract_chain_id(v: int) -> int: if is_even(v): chain_id = (v - EIP155_CHAIN_ID_OFFSET - 1) // 2 else: chain_id = (v - EIP155_CHAIN_ID_OFFSET) // 2 if chain_id < 0: raise ValidationError( 'Cannot extract chain id from object. Invalid signature or chain id.' ) return chain_id
def extract_block_header_sender(block_header: BaseBlockHeader) -> bytes: if is_even(block_header.v): v = 28 else: v = 27 r, s = block_header.r, block_header.s canonical_v = v - 27 vrs = (canonical_v, r, s) signature = keys.Signature(vrs=vrs) message = block_header.get_message_for_signing() public_key = signature.recover_public_key_from_msg(message) sender = public_key.to_canonical_address() return sender
def extract_signature_v(v: int) -> int: if is_even(v): return V_OFFSET + 1 else: return V_OFFSET
def extract_chain_id(v: int) -> int: if is_even(v): return (v - EIP155_CHAIN_ID_OFFSET - 1) // 2 else: return (v - EIP155_CHAIN_ID_OFFSET) // 2