def extract_transaction_sender(transaction: BaseTransaction) -> Address: if is_eip_155_signed_transaction(transaction): if is_even(transaction.v): v = 28 else: v = 27 else: v = transaction.v r, s = transaction.r, transaction.s canonical_v = v - 27 vrs = (canonical_v, r, s) signature = keys.Signature(vrs=vrs) message = transaction.get_message_for_signing() public_key = signature.recover_public_key_from_msg(message) sender = public_key.to_canonical_address() return Address(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