import base64
import json


def gen_sig_claim_file(reference: str, digest: str, requested_by: str) -> str:
    """
    Generated a claim file to be signed based on given data.
    Args:
        reference: Docker reference for the signed content,
            e.g. registry.redhat.io/redhat/community-operator-index:v4.9
        digest: Manifest digest for the signed content, usually in the format sha256:xxx
        requested_by: Name of the user that requested the signing, for auditing purposes
    """
    claim = {
        "critical": {
            "image": {"docker-manifest-digest": digest},
            "type": "atomic container signature",
            "identity": {"docker-reference": reference},
        },
        "optional": {"creator": requested_by},
    }

    claim = base64.b64encode(json.dumps(claim).encode("utf-8"))
    return claim.decode("utf-8")