{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://cainstudio.online/schemas/sovereign-evidence.v1.json",
  "title": "CAIN-42 Sovereign Evidence Record Schema",
  "description": "Authoritative contract for verification evidence across all 10 evaluation dimensions.",
  "type": "object",
  "required": [
    "schema_version",
    "evidence_id",
    "evolution",
    "invariant_id",
    "claim",
    "source_provenance",
    "environment",
    "dimensions",
    "artifact",
    "classification",
    "limitations"
  ],
  "properties": {
    "schema_version": {
      "type": "string",
      "const": "cain42.sovereign.evidence.v1"
    },
    "evidence_id": {
      "type": "string",
      "pattern": "^evo[0-9]{2}-evi-[a-f0-9]{8,16}$"
    },
    "evolution": {
      "type": "integer",
      "minimum": 1,
      "maximum": 42
    },
    "invariant_id": {
      "type": "string"
    },
    "check_id": {
      "type": "string"
    },
    "claim": {
      "type": "string"
    },
    "scope": {
      "type": "string"
    },
    "source_provenance": {
      "type": "object",
      "required": ["commit", "branch", "working_tree_clean"],
      "properties": {
        "commit": { "type": "string", "pattern": "^[0-9a-f]{40}$" },
        "branch": { "type": "string" },
        "working_tree_clean": { "type": "boolean" },
        "remote": { "type": ["string", "null"] }
      }
    },
    "environment": {
      "type": "object",
      "required": ["os", "kernel"],
      "properties": {
        "os": { "type": "string" },
        "kernel": { "type": "string" },
        "arch": { "type": "string" },
        "landlock_abi": { "type": "integer" },
        "python_version": { "type": "string" },
        "tool_versions": { "type": "object" }
      }
    },
    "execution": {
      "type": "object",
      "properties": {
        "start_utc": { "type": "string" },
        "end_utc": { "type": "string" },
        "duration_seconds": { "type": "number" },
        "command": { "type": "string" },
        "exit_code": { "type": "integer" },
        "passed": { "type": "integer" },
        "failed": { "type": "integer" },
        "skipped": { "type": "integer" },
        "error": { "type": "integer" }
      }
    },
    "dimensions": {
      "type": "object",
      "required": [
        "source_verified",
        "local_test_verified",
        "formal_model_verified",
        "artifact_integrity_verified",
        "signature_verified",
        "hosted_ci_verified",
        "live_endpoint_checked",
        "deployed_revision_verified",
        "production_traffic_path_verified",
        "independent_human_reviewed"
      ],
      "properties": {
        "source_verified": { "$ref": "#/$defs/dimension_status" },
        "local_test_verified": { "$ref": "#/$defs/dimension_status" },
        "formal_model_verified": { "$ref": "#/$defs/dimension_status" },
        "artifact_integrity_verified": { "$ref": "#/$defs/dimension_status" },
        "signature_verified": { "$ref": "#/$defs/dimension_status" },
        "hosted_ci_verified": { "$ref": "#/$defs/dimension_status" },
        "live_endpoint_checked": { "$ref": "#/$defs/dimension_status" },
        "deployed_revision_verified": { "$ref": "#/$defs/dimension_status" },
        "production_traffic_path_verified": { "$ref": "#/$defs/dimension_status" },
        "independent_human_reviewed": { "$ref": "#/$defs/dimension_status" }
      }
    },
    "artifact": {
      "type": "object",
      "required": ["path", "bytes", "sha256", "content_type"],
      "properties": {
        "path": { "type": "string" },
        "bytes": { "type": "integer" },
        "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
        "content_type": { "type": "string" }
      }
    },
    "signature": {
      "type": "object",
      "properties": {
        "algorithm": { "type": "string" },
        "signer_key_id": { "type": "string" },
        "signature_b64": { "type": "string" }
      }
    },
    "classification": {
      "type": "string",
      "enum": ["PUBLIC_SAFE", "RESTRICTED_INTERNAL", "PROPRIETARY_MODEL"]
    },
    "limitations": {
      "type": "array",
      "items": { "type": "string" }
    }
  },
  "$defs": {
    "dimension_status": {
      "type": "object",
      "required": ["status"],
      "properties": {
        "status": {
          "type": "string",
          "enum": ["PASS", "FAIL", "PARTIAL", "BLOCKED", "NOT_RUN", "UNKNOWN"]
        },
        "evidence": { "type": "string" },
        "checked_at": { "type": "string" }
      }
    }
  }
}
