{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://proofprotocol.io/schemas/pp-spec-002/proof-validity.schema.json",
  "title": "PP-SPEC-002 Proof Validity Schema",
  "description": "Machine-readable structural schema for a Proof Protocol Report. Schema validity is necessary but not sufficient for proof validity; PP-SPEC-002 cryptographic, temporal, witness, anchoring, chain, and scope checks MUST also pass.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "report_id",
    "proof",
    "environment_class",
    "pre_execution_commitment",
    "temporal_integrity",
    "proof_chain",
    "witness",
    "anchor",
    "scope",
    "assessment"
  ],
  "properties": {
    "schema_version": {
      "const": "proofprotocol.proof-validity.v1"
    },
    "report_id": {
      "type": "string",
      "minLength": 1
    },
    "proof": {
      "type": "boolean"
    },
    "environment_class": {
      "enum": [
        "arena",
        "production"
      ]
    },
    "pre_execution_commitment": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "commitment_hash",
        "sut_fingerprint",
        "test_parameters_hash",
        "declared_witness_ids",
        "declared_scope",
        "commitment_timestamp_utc",
        "vrs"
      ],
      "properties": {
        "commitment_hash": {
          "$ref": "#/$defs/sha256"
        },
        "sut_fingerprint": {
          "$ref": "#/$defs/sha256"
        },
        "test_parameters_hash": {
          "$ref": "#/$defs/sha256"
        },
        "declared_witness_ids": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "declared_scope": {
          "type": "string",
          "minLength": 1
        },
        "commitment_timestamp_utc": {
          "$ref": "#/$defs/timestamp"
        },
        "vrs": {
          "$ref": "#/$defs/vrs"
        }
      }
    },
    "temporal_integrity": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "execution_start_utc",
        "all_events_postdate_vrs"
      ],
      "properties": {
        "execution_start_utc": {
          "$ref": "#/$defs/timestamp"
        },
        "execution_end_utc": {
          "$ref": "#/$defs/timestamp"
        },
        "all_events_postdate_vrs": {
          "type": "boolean"
        }
      }
    },
    "proof_chain": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "genesis_vrs_output",
        "chain_complete",
        "committed_items_accounted_for",
        "records"
      ],
      "properties": {
        "genesis_vrs_output": {
          "type": "string",
          "pattern": "^[A-Fa-f0-9]+$"
        },
        "chain_complete": {
          "type": "boolean"
        },
        "committed_items_accounted_for": {
          "type": "boolean"
        },
        "records": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/proof_record"
          }
        }
      }
    },
    "witness": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "witness_id",
        "declared_pre_execution",
        "gate_a_pass",
        "gate_a_basis",
        "gate_b_pass",
        "gate_b_declaration",
        "roles_also_held",
        "residual_trust",
        "attestation_method"
      ],
      "properties": {
        "witness_id": {
          "type": "string",
          "minLength": 1
        },
        "declared_pre_execution": {
          "type": "boolean"
        },
        "gate_a_pass": {
          "type": "boolean"
        },
        "gate_a_basis": {
          "type": "string",
          "minLength": 1
        },
        "gate_b_pass": {
          "type": "boolean"
        },
        "gate_b_declaration": {
          "type": "string",
          "minLength": 1
        },
        "roles_also_held": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "enum": [
              "corpus_authority",
              "scoring_authority",
              "none"
            ]
          }
        },
        "residual_trust": {
          "type": "string",
          "minLength": 1
        },
        "attestation_method": {
          "type": "string",
          "minLength": 1
        },
        "credential_reference": {
          "type": "string"
        }
      }
    },
    "anchor": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "registry",
        "campaign_id",
        "block_number",
        "anchor_hash",
        "anchor_timestamp_utc",
        "registry_query_uri"
      ],
      "properties": {
        "registry": {
          "type": "string",
          "minLength": 1
        },
        "campaign_id": {
          "type": "string",
          "minLength": 1
        },
        "block_number": {
          "type": "integer",
          "minimum": 0
        },
        "anchor_hash": {
          "$ref": "#/$defs/sha256"
        },
        "anchor_timestamp_utc": {
          "$ref": "#/$defs/timestamp"
        },
        "registry_query_uri": {
          "type": "string",
          "format": "uri"
        }
      }
    },
    "scope": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "sut_name",
        "sut_version",
        "sut_config_hash",
        "sut_fingerprint",
        "declared_pre_execution",
        "scope_events"
      ],
      "properties": {
        "sut_name": {
          "type": "string",
          "minLength": 1
        },
        "sut_version": {
          "type": "string",
          "minLength": 1
        },
        "sut_config_hash": {
          "$ref": "#/$defs/sha256"
        },
        "sut_fingerprint": {
          "$ref": "#/$defs/sha256"
        },
        "declared_pre_execution": {
          "type": "boolean"
        },
        "scope_events": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/scope_event"
          }
        }
      }
    },
    "gaps_declared": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "anomaly_declaration": {
      "type": [
        "string",
        "null"
      ]
    },
    "assessment": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schema_valid",
        "witness_valid",
        "commitment_valid",
        "temporal_valid",
        "chain_valid",
        "anchor_valid",
        "scope_valid",
        "failing_steps"
      ],
      "properties": {
        "schema_valid": {
          "type": "boolean"
        },
        "witness_valid": {
          "type": "boolean"
        },
        "commitment_valid": {
          "type": "boolean"
        },
        "temporal_valid": {
          "type": "boolean"
        },
        "chain_valid": {
          "type": "boolean"
        },
        "anchor_valid": {
          "type": "boolean"
        },
        "scope_valid": {
          "type": "boolean"
        },
        "failing_steps": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "enum": [
              "schema",
              "witness",
              "commitment",
              "temporal",
              "chain",
              "anchor",
              "scope"
            ]
          }
        }
      }
    },
    "extensions": {
      "type": "object",
      "description": "Optional namespaced vendor, implementation, or domain-specific extensions. Extensions are non-normative with respect to core PP-SPEC-002 proof validity and MUST NOT override, weaken, replace, reinterpret, or suppress core fields or validity requirements.",
      "propertyNames": {
        "pattern": "^(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$"
      },
      "additionalProperties": {
        "type": "object"
      }
    }
  },
  "$defs": {
    "timestamp": {
      "type": "string",
      "format": "date-time"
    },
    "sha256": {
      "type": "string",
      "pattern": "^(sha256:)?[A-Fa-f0-9]{64}$"
    },
    "vrs": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "provider",
        "pulse_uri",
        "pulse_sequence",
        "seed_value",
        "output_value",
        "pulse_timestamp_utc"
      ],
      "properties": {
        "provider": {
          "type": "string",
          "minLength": 1
        },
        "pulse_uri": {
          "type": "string",
          "format": "uri"
        },
        "pulse_sequence": {
          "type": "integer",
          "minimum": 0
        },
        "seed_value": {
          "type": "string",
          "pattern": "^[A-Fa-f0-9]+$"
        },
        "output_value": {
          "type": "string",
          "pattern": "^[A-Fa-f0-9]+$"
        },
        "pulse_timestamp_utc": {
          "$ref": "#/$defs/timestamp"
        }
      }
    },
    "proof_record": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "record_id",
        "record_type",
        "classification",
        "detected",
        "content_hash",
        "previous_record_hash",
        "chain_hash",
        "timestamp_utc"
      ],
      "properties": {
        "record_id": {
          "type": "integer",
          "minimum": 0
        },
        "record_type": {
          "type": "string",
          "minLength": 1
        },
        "classification": {
          "enum": [
            "BLOCKED",
            "MISSED",
            "OBSERVED",
            "IRRELEVANT"
          ]
        },
        "detected": {
          "type": "boolean"
        },
        "content_hash": {
          "$ref": "#/$defs/sha256"
        },
        "previous_record_hash": {
          "type": "string",
          "minLength": 1
        },
        "chain_hash": {
          "$ref": "#/$defs/sha256"
        },
        "timestamp_utc": {
          "$ref": "#/$defs/timestamp"
        }
      }
    },
    "scope_event": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "timestamp_utc",
        "event_type",
        "description"
      ],
      "properties": {
        "timestamp_utc": {
          "$ref": "#/$defs/timestamp"
        },
        "event_type": {
          "type": "string",
          "minLength": 1
        },
        "description": {
          "type": "string",
          "minLength": 1
        }
      }
    }
  }
}
