{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/usap-forensic-v2.json",
  "title": "Forensic Rail v1",
  "description": "Evaluates supplied run commitments and replay equality. It does not prove scientific validity, consortium recognition, or universal reproducibility.",
  "type": "object",
  "required": [
    "receipt_id",
    "payload_sha256",
    "sig_b64u",
    "key_id",
    "algorithm",
    "ts",
    "signed_body"
  ],
  "additionalProperties": false,
  "properties": {
    "receipt_id": {
      "type": "string",
      "pattern": "^r_usap\\.forensic_[0-9]{10,}_[0-9a-f]{12}$"
    },
    "payload_sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "sig_b64u": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_-]{86}$"
    },
    "key_id": {
      "type": "string",
      "pattern": "^did:(hive|web|key):[A-Za-z0-9._:%-]+$"
    },
    "algorithm": {
      "type": "string",
      "const": "Ed25519"
    },
    "ts": {
      "type": "integer",
      "minimum": 1000000000
    },
    "signed_body": {
      "type": "object",
      "required": [
        "receipt_type",
        "schema",
        "credential_id",
        "evidence_digest_sha256",
        "recorded_at",
        "verdict",
        "boundary",
        "analysis_input_sha256",
        "method_id",
        "method_version",
        "method_config_sha256",
        "method_committed_at",
        "first_run",
        "run_roots",
        "replay_relation",
        "credential_trust_class",
        "elements",
        "outcome"
      ],
      "additionalProperties": false,
      "properties": {
        "receipt_type": {
          "type": "string",
          "const": "usap.forensic"
        },
        "schema": {
          "type": "string",
          "const": "r2.0.0"
        },
        "credential_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256,
          "pattern": "^[A-Za-z0-9._:-]{1,256}$"
        },
        "evidence_digest_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "SHA-256 of the caller-held evidence bundle this receipt attests was recorded. The service never receives or inspects the underlying evidence, only its digest."
        },
        "recorded_at": {
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,9})?Z$"
        },
        "verdict": {
          "type": "object",
          "description": "Service-computed honesty boundary fields. Never caller overridable; recomputed and checked at verify time.",
          "required": [
            "outcome"
          ],
          "additionalProperties": false,
          "properties": {
            "outcome": {
              "type": "string",
              "enum": [
                "reproducible_under_declared_configuration",
                "divergence_observed",
                "indeterminate"
              ]
            }
          }
        },
        "boundary": {
          "type": "string",
          "const": "Evaluates supplied run commitments and replay equality. It does not prove scientific validity, consortium recognition, or universal reproducibility."
        },
        "analysis_input_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "method_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128,
          "pattern": "^[A-Za-z0-9._:/]+$"
        },
        "method_version": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64
        },
        "method_config_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "method_committed_at": {
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,9})?Z$"
        },
        "first_run": {
          "type": "object",
          "required": [
            "started_at",
            "method_id",
            "method_version",
            "method_config_sha256",
            "steps"
          ],
          "additionalProperties": false,
          "properties": {
            "started_at": {
              "type": "string",
              "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,9})?Z$"
            },
            "method_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9._:/]+$"
            },
            "method_version": {
              "type": "string",
              "minLength": 1,
              "maxLength": 64
            },
            "method_config_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "steps": {
              "type": "array",
              "items": {
                "type": "object",
                "required": [
                  "step_index",
                  "prior_step_sha256",
                  "output_sha256",
                  "step_sha256"
                ],
                "additionalProperties": false,
                "properties": {
                  "step_index": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9999
                  },
                  "prior_step_sha256": {
                    "type": "string",
                    "pattern": "^[0-9a-f]{64}$"
                  },
                  "output_sha256": {
                    "type": "string",
                    "pattern": "^[0-9a-f]{64}$"
                  },
                  "step_sha256": {
                    "type": "string",
                    "pattern": "^[0-9a-f]{64}$"
                  }
                }
              },
              "minItems": 1,
              "maxItems": 10000
            }
          }
        },
        "replay_run": {
          "type": "object",
          "required": [
            "started_at",
            "method_id",
            "method_version",
            "method_config_sha256",
            "steps"
          ],
          "additionalProperties": false,
          "properties": {
            "started_at": {
              "type": "string",
              "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,9})?Z$"
            },
            "method_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9._:/]+$"
            },
            "method_version": {
              "type": "string",
              "minLength": 1,
              "maxLength": 64
            },
            "method_config_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "steps": {
              "type": "array",
              "items": {
                "type": "object",
                "required": [
                  "step_index",
                  "prior_step_sha256",
                  "output_sha256",
                  "step_sha256"
                ],
                "additionalProperties": false,
                "properties": {
                  "step_index": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9999
                  },
                  "prior_step_sha256": {
                    "type": "string",
                    "pattern": "^[0-9a-f]{64}$"
                  },
                  "output_sha256": {
                    "type": "string",
                    "pattern": "^[0-9a-f]{64}$"
                  },
                  "step_sha256": {
                    "type": "string",
                    "pattern": "^[0-9a-f]{64}$"
                  }
                }
              },
              "minItems": 1,
              "maxItems": 10000
            }
          }
        },
        "run_roots": {
          "type": "object",
          "required": [
            "first_run",
            "replay_run"
          ],
          "additionalProperties": false,
          "properties": {
            "first_run": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "replay_run": {
              "type": [
                "string",
                "null"
              ],
              "pattern": "^[0-9a-f]{64}$"
            }
          }
        },
        "replay_relation": {
          "type": "string",
          "enum": [
            "replay_not_supplied",
            "matches",
            "diverges"
          ]
        },
        "credential_trust_class": {
          "type": "string",
          "enum": [
            "declared_did",
            "unresolved_identifier"
          ]
        },
        "elements": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "run_chain_gap",
              "replay_digest_mismatch",
              "credential_unresolved"
            ]
          },
          "minItems": 0,
          "maxItems": 3
        },
        "outcome": {
          "type": "string",
          "enum": [
            "reproducible_under_declared_configuration",
            "divergence_observed",
            "indeterminate"
          ]
        }
      }
    }
  }
}
