<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 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 USERID_RE format
    match = USERID_RE.match(user.user_id)
    if not match:
        return None

    encoded_address = match.group(1)
    address: Address = to_canonical_address(encoded_address)

    try:
        displayname = user.get_display_name()
        recovered = recover(
            data=user.user_id.encode(),
            signature=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