import hashlib
import hmac


def check_signature(token: str, hash: str, **kwargs) -> bool:
    """
    Generate hexadecimal representation
    of the HMAC-SHA-256 signature of the data-check-string
    with the SHA256 hash of the bot's token used as a secret key

    :param token:
    :param hash:
    :param kwargs: all params received on auth
    :return:
    """
    secret = hashlib.sha256(token.encode("utf-8"))
    check_string = "\n".join(map(lambda k: f"{k}={kwargs[k]}", sorted(kwargs)))
    hmac_string = hmac.new(
        secret.digest(), check_string.encode("utf-8"), digestmod=hashlib.sha256
    ).hexdigest()
    return hmac_string == hash