def _validate_userid_signature(user: User) -> Optional[Address]: """ Validate a userId format and signature on displayName, and return its address""" # display_name should be an address in the self._userid_re format match = MatrixTransport._userid_re.match(user.user_id) if not match: return None encoded_address: str = match.group(1) address: Address = to_canonical_address(encoded_address) try: displayname = user.get_display_name() recovered = MatrixTransport._recover( user.user_id.encode(), decode_hex(displayname), ) if not (address and recovered and recovered == address): return None except ( DecodeError, TypeError, InvalidSignature, MatrixRequestError, json.decoder.JSONDecodeError, ): return None return address
def _validate_userid_signature(user: User) -> bool: # display_name should be an address present in the user_id recovered = signing.recover_address(user.user_id.encode(), signature=data_decoder( user.get_display_name()), hasher=eth_sign_sha3) return address_encoder(recovered).lower() in user.user_id
def _validate_userid_signature(user: User) -> Optional[Address]: """ Validate a userId format and signature on displayName, and return its address""" # display_name should be an address in the self._userid_re format match = MatrixTransport._userid_re.match(user.user_id) if not match: return encoded_address: str = match.group(1) address: Address = to_canonical_address(encoded_address) try: recovered = MatrixTransport._recover( user.user_id.encode(), decode_hex(user.get_display_name()), ) if not address or not recovered or recovered != address: return except (DecodeError, TypeError): return return address
try: client.login(username, password) except MatrixRequestError as e: print(e) if e.code == 403: print("Bad username or password.") sys.exit(4) else: print("Check your server details are correct.") sys.exit(2) except MissingSchema as e: print("Bad URL format.") print(e) sys.exit(3) user = User(client.api, client.user_id) if len(sys.argv) < 5: print("Current Display Name: %s" % user.get_display_name()) displayname = input("New Display Name: ") else: displayname = sys.argv[4] try: user.set_display_name(displayname) except MatrixRequestError as e: print(e) sys.exit(11)