{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/fault-attribution-v1.json",
  "title": "Fault Attribution Receipt, v1",
  "description": "Canonical schema for the Hive fault attribution receipt, canonical type fault.attribution.",
  "type": "object",
  "required": [
    "receipt_id",
    "payload_sha256",
    "sig_b64u",
    "key_id",
    "algorithm",
    "ts",
    "signed_body"
  ],
  "additionalProperties": false,
  "properties": {
    "receipt_id": { "type": "string", "pattern": "^r_fault\\.attribution_[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",
        "fault_attribution",
        "boundary"
      ],
      "additionalProperties": false,
      "properties": {
        "receipt_type": { "type": "string", "const": "fault.attribution" },
        "schema": { "type": "string", "const": "r1.0.0" },
        "fault_attribution": {
          "type": "object",
          "required": [
            "attribution_id",
            "attributed_at",
            "loss_event_ref",
            "party_role_digest",
            "party_count",
            "precommitment_set_digest",
            "precommitment_count",
            "observation_set_digest",
            "observation_count",
            "violation_set_digest",
            "violated_party_count",
            "attribution_class",
            "attributed_role",
            "precedence_class",
            "evidence_access_class",
            "salt_commitment"
          ],
          "additionalProperties": false,
          "properties": {
            "attribution_id": { "type": "string", "pattern": "^fa_[0-9a-f]{16,64}$" },
            "attributed_at": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d{1,9})?Z$" },
            "loss_event_ref": {
              "type": "object",
              "required": ["event_id", "payload_sha256", "occurred_at"],
              "additionalProperties": false,
              "properties": {
                "event_id": { "type": "string", "pattern": "^le_[0-9a-f]{16,64}$" },
                "payload_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
                "occurred_at": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d{1,9})?Z$" }
              }
            },
            "party_role_digest": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "party_count": { "type": "integer", "minimum": 2, "maximum": 4 },
            "precommitment_set_digest": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "precommitment_count": { "type": "integer", "minimum": 0, "maximum": 100000 },
            "observation_set_digest": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "observation_count": { "type": "integer", "minimum": 0, "maximum": 100000 },
            "violation_set_digest": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "violated_party_count": { "type": "integer", "minimum": 0, "maximum": 4 },
            "attribution_class": { "type": "string", "enum": ["single_party", "shared", "no_violation_found", "indeterminate"] },
            "attributed_role": { "type": ["string", "null"], "enum": ["principal", "agent_operator", "acceptor", "issuer", null] },
            "precedence_class": { "type": "string", "enum": ["all_precommitments_precede_loss", "some_precommitments_follow_loss"] },
            "evidence_access_class": { "type": "string", "enum": ["confidential_independent", "issuer_only", "public_commitment_only"] },
            "salt_commitment": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
          }
        },
        "boundary": {
          "type": "string",
          "minLength": 1,
          "const": "This receipt attests only that a named observer recomputed which precommitted constraints the supplied observations violated, and which parties had made those precommitments before the loss instant. It does not attest that the loss occurred, that the observations are complete, that any party acted with intent, that any legal duty was breached, or that any amount is owed."
        }
      }
    }
  }
}
