from typing import Callable
import hmac
import hashlib


def generate_hash_key(chain_url: str, privkey: bytes, strategy: Callable):
    """Generate a hash key to use as `client_id`, using the :mod:`hmac` library.

    The message is the concatenation of `chain_url` plus the `__name__` attribute of the
    `strategy`.

    The `privkey` is used to sign it using `sha256`.

    The result is hexdigested before we return it.
    """
    k = hmac.new(privkey, (chain_url + strategy.__name__).encode("UTF-8"), hashlib.sha256)
    return k.hexdigest()