from __future__ import annotations

import base64
import hashlib


def hash_api_key(api_key: str) -> str:
    """
    Hash *api_key* using SHA-384 + base64url, matching the JS client.
    """
    digest = hashlib.sha384(api_key.encode("utf-8")).digest()
    return base64.urlsafe_b64encode(digest).decode("utf-8")


def extract_bearer_token(authorization: str) -> str:
    """
    Strip the ``Bearer`` prefix from an Authorization header value.
    """
    if authorization.startswith("Bearer "):
        return authorization[7:]
    return authorization
