import hmac
import hashlib


def hmac_sha512(key: bytes, data: bytes) -> bytes:
    """
    Return the SHA512 HMAC for the byte sequence ``data`` generated with the
    secret key ``key``.

    Corresponds directly to the "HMAC-SHA512(Key = ..., Data = ...)" function
    in BIP32
    (https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#conventions).

    :param key: The secret key used for HMAC calculation.
    :param data: The data for which an HMAC should be calculated.

    :return: A byte sequence containing the HMAC of ``data`` generated with the
        secret key ``key``.
    """
    h = hmac.new(key, data, hashlib.sha512)
    return h.digest()