{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://zk-sbom-passport.org/spec/composite-passport-v1.schema.json",
  "title": "zk-sbom-composite-passport/v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema_version", "payload", "dual_signature"],
  "properties": {
    "schema_version": { "type": "string", "const": "zk-sbom-composite-passport/v1" },
    "payload": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "passport_id",
        "root_artifact_sha256",
        "product_name",
        "issued_at",
        "valid_until",
        "max_age_seconds",
        "policy",
        "children_merkle_root",
        "summary",
        "children",
        "aggregator_keys"
      ],
      "properties": {
        "passport_id": { "type": "string", "pattern": "^[0-9a-f]{32}$" },
        "root_artifact_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
        "product_name": { "type": "string", "minLength": 1, "maxLength": 128 },
        "issued_at": { "type": "string", "format": "date-time" },
        "valid_until": { "type": "string", "format": "date-time" },
        "max_age_seconds": { "type": "integer", "minimum": 60, "maximum": 31536000 },
        "policy": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "policy_id",
            "policy_root",
            "policy_issued_at",
            "policy_valid_until",
            "authority_key_id"
          ],
          "properties": {
            "policy_id": { "type": "string", "pattern": "^[a-zA-Z0-9._-]{3,64}$" },
            "policy_root": { "type": "string", "pattern": "^[0-9]{1,78}$" },
            "policy_issued_at": { "type": "string", "format": "date-time" },
            "policy_valid_until": { "type": "string", "format": "date-time" },
            "authority_key_id": { "type": "string", "pattern": "^[a-zA-Z0-9._-]{3,64}$" }
          }
        },
        "children_merkle_root": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
        "summary": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "child_count",
            "min_assurance_tier",
            "all_post_quantum_zk",
            "total_vex_exemptions",
            "aggregated_vex_histogram"
          ],
          "properties": {
            "child_count": { "type": "integer", "minimum": 1, "maximum": 256 },
            "min_assurance_tier": {
              "type": "string",
              "enum": ["T1-SelfAttested", "T2-TEE-Attested", "T3-Forensic-ZeroSource"]
            },
            "all_post_quantum_zk": { "type": "boolean" },
            "total_vex_exemptions": { "type": "integer", "minimum": 0, "maximum": 16384 },
            "aggregated_vex_histogram": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "component_not_present",
                "vulnerable_code_not_present",
                "vulnerable_code_not_in_execute_path",
                "vulnerable_code_cannot_be_controlled_by_adversary",
                "inline_mitigations_already_exist"
              ],
              "properties": {
                "component_not_present": { "type": "integer", "minimum": 0, "maximum": 16384 },
                "vulnerable_code_not_present": { "type": "integer", "minimum": 0, "maximum": 16384 },
                "vulnerable_code_not_in_execute_path": { "type": "integer", "minimum": 0, "maximum": 16384 },
                "vulnerable_code_cannot_be_controlled_by_adversary": { "type": "integer", "minimum": 0, "maximum": 16384 },
                "inline_mitigations_already_exist": { "type": "integer", "minimum": 0, "maximum": 16384 }
              }
            }
          }
        },
        "children": {
          "type": "array",
          "minItems": 1,
          "maxItems": 256,
          "items": { "type": "object" }
        },
        "aggregator_keys": {
          "oneOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["key_id", "ed25519_pk_b64u", "mldsa65_pk_b64u"],
              "properties": {
                "key_id": { "type": "string", "minLength": 3, "maxLength": 64 },
                "pq_alg": { "const": "ml-dsa-65" },
                "ed25519_pk_b64u": { "type": "string", "pattern": "^[A-Za-z0-9_-]{43}$" },
                "mldsa65_pk_b64u": { "type": "string", "minLength": 2000, "maxLength": 3000 }
              }
            },
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["key_id", "pq_alg", "ed25519_pk_b64u", "mldsa87_pk_b64u"],
              "properties": {
                "key_id": { "type": "string", "minLength": 3, "maxLength": 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}$" }
              }
            }
          ]
        }
      }
    },
    "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}$" }
          }
        }
      ]
    }
  }
}
