{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.cleoanka.com/court/check/certificate.schema.json",
  "title": "cleoanka Causality Certificate, schema 1",
  "description": "A self-issued record of one run of the court checker (https://www.cleoanka.com/court/check/), produced in the visitor's browser. It names the exact inputs by SHA-256 and the checker version; it does not prove the inputs are honest. audit_sha256 is the SHA-256 of the UTF-8 bytes of canonical(results.audit): object keys sorted recursively, arrays kept in order, JSON.stringify with no whitespace.",
  "type": "object",
  "required": ["kind", "schema", "issued_at", "self_issued", "checker", "inputs", "results", "limits"],
  "additionalProperties": false,
  "properties": {
    "kind": { "const": "cleoanka-causality-certificate" },
    "schema": { "const": 1 },
    "issued_at": {
      "description": "ISO-8601 UTC time from the visitor's clock; nobody verifies it.",
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$"
    },
    "self_issued": { "const": true },
    "checker": {
      "type": "object",
      "required": ["url", "auditor_version", "auditor_sha256", "pyodide"],
      "additionalProperties": false,
      "properties": {
        "url": { "const": "https://www.cleoanka.com/court/check/" },
        "auditor_version": { "description": "The 'version' field of the auditor's JSON.", "type": "string" },
        "auditor_sha256": { "description": "SHA-256 of the auditor.py bytes the worker loaded; null where the browser offered no Web Crypto.", "type": ["string", "null"], "pattern": "^[0-9a-f]{64}$" },
        "pyodide": { "description": "Pyodide version the worker ran; null if the worker did not report one.", "type": ["string", "null"] }
      }
    },
    "inputs": {
      "type": "object",
      "required": ["strategy", "data", "params"],
      "additionalProperties": false,
      "properties": {
        "strategy": { "$ref": "#/$defs/file" },
        "data": { "$ref": "#/$defs/file" },
        "params": {
          "type": "object",
          "required": ["trials", "max_lag", "seed"],
          "additionalProperties": false,
          "properties": {
            "trials": { "type": ["integer", "null"], "minimum": 1 },
            "max_lag": { "type": "integer", "minimum": 0 },
            "seed": { "type": "integer" }
          }
        }
      }
    },
    "results": {
      "type": "object",
      "required": ["verdict", "audit_sha256", "audit"],
      "additionalProperties": false,
      "properties": {
        "verdict": { "enum": ["convicted", "suspect", "acquitted"] },
        "audit_sha256": { "$ref": "#/$defs/sha256" },
        "audit": {
          "description": "The auditor's JSON exactly as the checker returned it.",
          "type": "object",
          "required": ["version", "tests", "lint", "errors"]
        }
      }
    },
    "limits": {
      "description": "What the certificate does not prove, in Turkish and English, five lines each.",
      "type": "object",
      "required": ["tr", "en"],
      "additionalProperties": false,
      "properties": {
        "tr": { "$ref": "#/$defs/limits" },
        "en": { "$ref": "#/$defs/limits" }
      }
    }
  },
  "$defs": {
    "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
    "file": {
      "type": "object",
      "required": ["name", "bytes", "sha256"],
      "additionalProperties": false,
      "properties": {
        "name": { "description": "The file name as loaded; empty when the code was typed or edited on the page.", "type": "string" },
        "bytes": { "type": "integer", "minimum": 0 },
        "sha256": { "$ref": "#/$defs/sha256" }
      }
    },
    "limits": { "type": "array", "items": { "type": "string" }, "minItems": 5, "maxItems": 5 }
  }
}
