{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://zk-sbom-passport.org/spec/policy-bundle-v1.schema.json",
  "title": "policy-bundle/v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema_version", "payload", "dual_signature"],
  "properties": {
    "schema_version": { "type": "string", "const": "policy-bundle/v1" },
    "payload": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "policy_id",
        "policy_root",
        "tree_depth",
        "interval_count",
        "issued_at",
        "valid_until",
        "source_hashes",
        "authority_keys",
        "intervals"
      ],
      "properties": {
        "policy_id": { "type": "string", "pattern": "^[a-zA-Z0-9._-]{3,64}$" },
        "policy_root": { "type": "string", "pattern": "^[0-9]{1,78}$" },
        "tree_depth": { "type": "integer", "const": 20 },
        "interval_count": { "type": "integer", "minimum": 0, "maximum": 1048575 },
        "issued_at": { "type": "string", "format": "date-time" },
        "valid_until": { "type": "string", "format": "date-time" },
        "source_hashes": {
          "type": "object",
          "additionalProperties": false,
          "required": ["cisa_kev_sha256", "osv_sha256", "license_rules_sha256"],
          "properties": {
            "cisa_kev_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "osv_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "license_rules_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "euvd_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "cbom_rules_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "aibom_rules_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
          }
        },
        "authority_keys": {
          "oneOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["key_id", "ed25519_pk_b64u", "mldsa65_pk_b64u"],
              "properties": {
                "key_id": { "type": "string", "pattern": "^[a-zA-Z0-9._-]{3,64}$" },
                "pq_alg": { "const": "ml-dsa-65" },
                "ed25519_pk_b64u": { "type": "string", "pattern": "^[A-Za-z0-9_-]{43}$" },
                "mldsa65_pk_b64u": { "type": "string", "pattern": "^[A-Za-z0-9_-]{2600,2610}$" }
              }
            },
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["key_id", "pq_alg", "ed25519_pk_b64u", "mldsa87_pk_b64u"],
              "properties": {
                "key_id": { "type": "string", "pattern": "^[a-zA-Z0-9._-]{3,64}$" },
                "pq_alg": { "const": "ml-dsa-87" },
                "ed25519_pk_b64u": { "type": "string", "pattern": "^[A-Za-z0-9_-]{43}$" },
                "mldsa87_pk_b64u": { "type": "string", "pattern": "^[A-Za-z0-9_-]{3456}$" }
              }
            }
          ]
        },
        "intervals": {
          "type": "array",
          "maxItems": 1048575,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["L", "H", "next_L", "rule_cve_set_hash", "cve_ids", "pkg_base", "kind"],
            "properties": {
              "L": { "type": "string", "pattern": "^[0-9]{1,78}$" },
              "H": { "type": "string", "pattern": "^[0-9]{1,78}$" },
              "next_L": { "type": "string", "pattern": "^[0-9]{1,78}$" },
              "rule_cve_set_hash": { "type": "string", "pattern": "^[0-9]{1,78}$" },
              "cve_ids": {
                "type": "array",
                "minItems": 1,
                "maxItems": 128,
                "items": { "type": "string", "pattern": "^(CVE-[0-9]{4}-[0-9]{4,7}|GHSA-[A-Za-z0-9-]{14}|EUVD-[0-9]{4}-[0-9]{4,7}|LIC-[A-Z0-9.+_-]{2,48}|CBOM-[A-Z0-9._-]{2,48}|AIBOM-[A-Z0-9._-]{2,48})$" }
              },
              "pkg_base": { "type": "string", "pattern": "^[a-zA-Z0-9:._/@+\\\\-]{3,160}$" },
              "kind": { "type": "string", "enum": ["cve-range", "cve-opaque-guard", "banned-license", "banned-cbom", "banned-aibom"] }
            }
          }
        }
      }
    },
    "dual_signature": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["digest_sha256", "ed25519_sig_b64u", "mldsa65_sig_b64u"],
          "properties": {
            "digest_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "pq_alg": { "const": "ml-dsa-65" },
            "ed25519_sig_b64u": { "type": "string", "pattern": "^[A-Za-z0-9_-]{86}$" },
            "mldsa65_sig_b64u": { "type": "string", "pattern": "^[A-Za-z0-9_-]{4410,4420}$" }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["digest_sha256", "pq_alg", "ed25519_sig_b64u", "mldsa87_sig_b64u"],
          "properties": {
            "digest_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "pq_alg": { "const": "ml-dsa-87" },
            "ed25519_sig_b64u": { "type": "string", "pattern": "^[A-Za-z0-9_-]{86}$" },
            "mldsa87_sig_b64u": { "type": "string", "pattern": "^[A-Za-z0-9_-]{6170}$" }
          }
        }
      ]
    }
  }
}
