{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://hogarmas.net/content-credentials/collection-hash-audit-schema.json",
  "title": "H/M C2PA Collection Data Hash Audit",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "ruleset", "generatedAt", "auditId", "assertion", "execution", "result", "summary", "files", "boundaries"],
  "properties": {
    "schema": { "const": "hm.c2pa-collection-data-hash-audit.v1" },
    "ruleset": { "const": "2026-07-31.1" },
    "generatedAt": { "type": "string", "format": "date-time" },
    "auditId": { "type": "string", "pattern": "^urn:sha256:[a-f0-9]{64}$" },
    "assertion": { "$ref": "#/$defs/assertion" },
    "execution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["startedAt", "selectedFileCount", "listedFileCount", "processedFileCount", "syntheticSample", "sourceMediaUploaded"],
      "properties": {
        "startedAt": { "type": "string", "format": "date-time" },
        "selectedFileCount": { "type": "integer", "minimum": 1, "maximum": 4000 },
        "listedFileCount": { "type": "integer", "minimum": 1, "maximum": 2000 },
        "processedFileCount": { "type": "integer", "minimum": 0, "maximum": 2000 },
        "syntheticSample": { "type": "boolean" },
        "sourceMediaUploaded": { "const": false }
      }
    },
    "result": { "$ref": "#/$defs/result" },
    "summary": { "$ref": "#/$defs/summary" },
    "files": {
      "type": "array",
      "minItems": 1,
      "maxItems": 2000,
      "items": { "$ref": "#/$defs/file" }
    },
    "boundaries": { "$ref": "#/$defs/boundaries" }
  },
  "$defs": {
    "digest": { "type": "string", "pattern": "^(sha256:[a-f0-9]{64}|sha384:[a-f0-9]{96}|sha512:[a-f0-9]{128})$" },
    "assertion": {
      "type": "object",
      "additionalProperties": false,
      "required": ["label", "algorithm", "entryCount", "digest"],
      "properties": {
        "label": { "const": "c2pa.hash.collection.data" },
        "algorithm": { "enum": ["sha256", "sha384", "sha512"] },
        "entryCount": { "type": "integer", "minimum": 1, "maximum": 2000 },
        "digest": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" }
      }
    },
    "result": {
      "type": "object",
      "additionalProperties": false,
      "required": ["state", "codes"],
      "properties": {
        "state": { "enum": ["match", "failure", "incomplete"] },
        "codes": {
          "type": "array",
          "minItems": 1,
          "maxItems": 3,
          "uniqueItems": true,
          "items": {
            "enum": [
              "assertion.collectionHash.match",
              "assertion.collectionHash.mismatch",
              "assertion.collectionHash.incorrectFileCount",
              "hm.collectionHash.localAuditIncomplete"
            ]
          }
        }
      }
    },
    "summary": {
      "type": "object",
      "additionalProperties": false,
      "required": ["listedCount", "matchCount", "mismatchCount", "missingCount", "errorCount", "warningCount", "notCoveredSelectedCount"],
      "properties": {
        "listedCount": { "type": "integer", "minimum": 1, "maximum": 2000 },
        "matchCount": { "type": "integer", "minimum": 0, "maximum": 2000 },
        "mismatchCount": { "type": "integer", "minimum": 0, "maximum": 2000 },
        "missingCount": { "type": "integer", "minimum": 0, "maximum": 2000 },
        "errorCount": { "type": "integer", "minimum": 0, "maximum": 2000 },
        "warningCount": { "type": "integer", "minimum": 0, "maximum": 4000 },
        "notCoveredSelectedCount": { "type": "integer", "minimum": 0, "maximum": 4000 }
      }
    },
    "file": {
      "type": "object",
      "additionalProperties": false,
      "required": ["index", "uri", "state", "code", "expectedHash", "observedHash", "declaredSize", "observedSize", "declaredMediaType", "observedMediaType", "warnings", "error"],
      "properties": {
        "index": { "type": "integer", "minimum": 0, "maximum": 1999 },
        "uri": { "type": "string", "minLength": 1, "maxLength": 2048 },
        "state": { "enum": ["match", "mismatch", "missing", "error"] },
        "code": { "type": "string", "minLength": 1, "maxLength": 100 },
        "expectedHash": { "$ref": "#/$defs/digest" },
        "observedHash": { "anyOf": [{ "$ref": "#/$defs/digest" }, { "const": "" }] },
        "declaredSize": { "type": ["integer", "null"], "minimum": 0 },
        "observedSize": { "type": ["integer", "null"], "minimum": 0 },
        "declaredMediaType": { "type": "string", "maxLength": 200 },
        "observedMediaType": { "type": "string", "maxLength": 200 },
        "warnings": {
          "type": "array",
          "maxItems": 2,
          "uniqueItems": true,
          "items": { "enum": ["declared-size-mismatch", "declared-format-mismatch"] }
        },
        "error": { "type": "string", "maxLength": 100 }
      }
    },
    "boundaries": {
      "type": "object",
      "additionalProperties": false,
      "required": ["officialAssertionLabelValidated", "uriTraversalRejected", "listedFileBytesHashedLocally", "unlistedFilesInvalidateStandardResult", "collectionCompletenessProven", "signerIdentityVerifiedByThisAudit", "manifestSignatureVerifiedByThisAudit", "sourceCustodyProven", "authorshipProven", "licensingProven", "consentProven", "semanticTruthProven", "legalComplianceCertified", "sourceMediaUploaded"],
      "properties": {
        "officialAssertionLabelValidated": { "const": true },
        "uriTraversalRejected": { "const": true },
        "listedFileBytesHashedLocally": { "const": true },
        "unlistedFilesInvalidateStandardResult": { "const": false },
        "collectionCompletenessProven": { "const": false },
        "signerIdentityVerifiedByThisAudit": { "const": false },
        "manifestSignatureVerifiedByThisAudit": { "const": false },
        "sourceCustodyProven": { "const": false },
        "authorshipProven": { "const": false },
        "licensingProven": { "const": false },
        "consentProven": { "const": false },
        "semanticTruthProven": { "const": false },
        "legalComplianceCertified": { "const": false },
        "sourceMediaUploaded": { "const": false }
      }
    }
  }
}
