import json
import hashlib


def metadata_hash(metadata: dict, hash_length: int = 20):
    """Compute hash from metadata dictionary.
    """
    encoded = json.dumps(metadata, sort_keys=True).encode()
    return hashlib.sha256(encoded).hexdigest()[:hash_length]