{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://cainstudio.online/verification/e82/e82_external_attestation.schema.json",
  "title": "CAIN-42 E82 external reproduction attestation",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema", "nonce", "attestor", "environment", "artifact", "commands",
    "result", "timestamp_utc", "public_key_b64", "signature_b64", "independence"
  ],
  "properties": {
    "schema": {"const": "cain42.external_reproduction.v1"},
    "nonce": {"type": "string", "minLength": 16, "maxLength": 128},
    "attestor": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "organization", "email"],
      "properties": {
        "name": {"type": "string", "minLength": 1, "maxLength": 160},
        "organization": {"type": "string", "minLength": 1, "maxLength": 200},
        "email": {"type": "string", "minLength": 3, "maxLength": 254},
        "role": {"type": "string", "maxLength": 200}
      }
    },
    "independence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["no_cain_code_imported", "project_affiliation", "statement"],
      "properties": {
        "no_cain_code_imported": {"type": "boolean"},
        "project_affiliation": {"type": "boolean"},
        "statement": {"type": "string", "minLength": 10, "maxLength": 2000}
      }
    },
    "environment": {
      "type": "object",
      "additionalProperties": false,
      "required": ["os", "python", "cryptography"],
      "properties": {
        "os": {"type": "string", "minLength": 1, "maxLength": 200},
        "kernel": {"type": "string", "maxLength": 200},
        "python": {"type": "string", "minLength": 1, "maxLength": 40},
        "cryptography": {"type": "string", "minLength": 1, "maxLength": 40},
        "machine": {"type": "string", "maxLength": 200},
        "container_image": {"type": "string", "maxLength": 200}
      }
    },
    "artifact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["bundle_zip_sha256", "merkle_root", "manifest_sha256"],
      "properties": {
        "bundle_zip_sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
        "merkle_root": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
        "manifest_sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
        "file_count": {"type": "integer", "minimum": 1}
      }
    },
    "commands": {
      "type": "array",
      "minItems": 1,
      "maxItems": 20,
      "items": {"type": "string", "minLength": 1, "maxLength": 2000}
    },
    "result": {
      "type": "object",
      "additionalProperties": false,
      "required": ["ok", "checks_passed", "checks_total", "merkle_root"],
      "properties": {
        "ok": {"type": "boolean"},
        "checks_passed": {"type": "integer", "minimum": 0},
        "checks_total": {"type": "integer", "minimum": 1},
        "merkle_root": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
        "failures": {"type": "array", "maxItems": 50, "items": {"type": "string", "maxLength": 500}},
        "raw_output_sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"}
      }
    },
    "timestamp_utc": {"type": "string", "minLength": 20, "maxLength": 40},
    "public_key_b64": {"type": "string", "minLength": 40, "maxLength": 100},
    "signature_b64": {"type": "string", "minLength": 80, "maxLength": 100},
    "notes": {"type": "string", "maxLength": 4000}
  }
}
