{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/monitor-continuity-v1.json",
  "title": "Monitor Continuity Receipt, v1",
  "description": "Canonical schema for the Hive monitor continuity receipt, canonical type monitor.continuity. A named monitor sends heartbeats to an outside witness, each carrying the digest of the configuration it is running. The receipt compares those heartbeats with a maximum gap and a configuration digest committed before the window opened, and records every silence longer than the gap and every heartbeat that reported a different configuration. Gaps, configuration changes and the outcome are recomputed by the verifier.",
  "type": "object",
  "required": [
    "receipt_id",
    "payload_sha256",
    "sig_b64u",
    "key_id",
    "algorithm",
    "ts",
    "signed_body"
  ],
  "additionalProperties": false,
  "properties": {
    "receipt_id": {
      "type": "string",
      "pattern": "^r_monitor[.]continuity_[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",
        "monitor_id",
        "committed_config_sha256",
        "policy_committed_at",
        "max_gap_seconds",
        "window_start",
        "window_end",
        "heartbeats",
        "heartbeats_root",
        "gaps",
        "config_mismatches",
        "outcome",
        "boundary"
      ],
      "additionalProperties": false,
      "properties": {
        "receipt_type": {
          "type": "string",
          "const": "monitor.continuity"
        },
        "schema": {
          "type": "string",
          "const": "r1.0.0"
        },
        "monitor_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128,
          "pattern": "^[A-Za-z0-9._:-]+$"
        },
        "committed_config_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Digest of the monitor configuration committed before the window opened, including which alerts are enabled."
        },
        "policy_committed_at": {
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
        },
        "max_gap_seconds": {
          "type": "integer",
          "minimum": 1,
          "maximum": 86400
        },
        "window_start": {
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
        },
        "window_end": {
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
        },
        "heartbeats": {
          "type": "array",
          "minItems": 0,
          "maxItems": 4096,
          "items": {
            "type": "object",
            "required": [
              "at",
              "config_sha256"
            ],
            "additionalProperties": false,
            "properties": {
              "at": {
                "type": "string",
                "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
              },
              "config_sha256": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$"
              }
            }
          }
        },
        "heartbeats_root": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Derived. SHA-256 over the heartbeat lines, each at|config_sha256, joined by newline, in order."
        },
        "gaps": {
          "type": "array",
          "maxItems": 4097,
          "description": "Derived. Every silence longer than max_gap_seconds, including from window_start to the first heartbeat and from the last heartbeat to window_end.",
          "items": {
            "type": "object",
            "required": [
              "from",
              "to",
              "seconds"
            ],
            "additionalProperties": false,
            "properties": {
              "from": {
                "type": "string",
                "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
              },
              "to": {
                "type": "string",
                "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
              },
              "seconds": {
                "type": "integer",
                "minimum": 1
              }
            }
          }
        },
        "config_mismatches": {
          "type": "object",
          "required": [
            "count",
            "first_at"
          ],
          "additionalProperties": false,
          "description": "Derived. Heartbeats whose reported configuration differs from the committed one.",
          "properties": {
            "count": {
              "type": "integer",
              "minimum": 0
            },
            "first_at": {
              "type": [
                "string",
                "null"
              ],
              "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
            }
          }
        },
        "outcome": {
          "type": "string",
          "enum": [
            "continuous",
            "gaps_recorded",
            "config_changed",
            "gaps_and_config_changed"
          ]
        },
        "boundary": {
          "type": "string",
          "const": "This receipt records which heartbeats a named monitor delivered to the issuer during the stated window, the configuration digest each one reported, every silence longer than a gap committed before the window opened, and every heartbeat that reported a configuration other than the committed one. It does not establish that the monitor detected anything correctly, that a heartbeat means the monitor was working, or why a gap or change happened, and it does not assign responsibility for either."
        }
      }
    }
  }
}
