"""Aliro IssuerAuth `kid` computation (spec \u00a77.2.1).

    kid = SHA256("key-identifier" || 0x04 || IssuerKey_PubK.x || IssuerKey_PubK.y)[:8]
"""

import hashlib

from cryptography.hazmat.primitives.asymmetric import ec


def compute_issuer_kid(public_key: ec.EllipticCurvePublicKey) -> bytes:
    numbers = public_key.public_numbers()
    x_bytes = numbers.x.to_bytes(32, "big")
    y_bytes = numbers.y.to_bytes(32, "big")
    payload = b"key-identifier" + b"\x04" + x_bytes + y_bytes
    return hashlib.sha256(payload).digest()[:8]
