{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/input-sufficiency-level-v1.json",
  "title": "Input Sufficiency Level Receipt, v1",
  "description": "Canonical schema for the Hive input sufficiency level receipt, canonical type input.sufficiency.level. The instrument records committed input counts for one calculation period, a waterfall rule committed before that period began (for example at least six snapshots for level 1), the level or fallback that the rule called for given those counts as computed by the service, the level the publisher reported, and whether the two differ. The instrument and the publisher are presented as salted commitments.",
  "type": "object",
  "required": ["receipt_id", "payload_sha256", "sig_b64u", "key_id", "algorithm", "ts", "signed_body"],
  "additionalProperties": false,
  "properties": {
    "receipt_id": { "type": "string", "pattern": "^r_input[.]sufficiency[.]level_[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", "rule", "rule_digest", "period", "input_counts",
        "published_outcome", "computed_outcome", "finding", "instrument_commitment",
        "publisher_commitment", "salt_commitment", "recorded_at", "boundary"
      ],
      "additionalProperties": false,
      "properties": {
        "receipt_type": { "type": "string", "const": "input.sufficiency.level" },
        "schema": { "type": "string", "const": "r1.0.0" },
        "rule": {
          "type": "object",
          "required": ["rule_id", "rule_version", "levels", "fallback", "committed_at"],
          "additionalProperties": false,
          "properties": {
            "rule_id": { "type": "string", "pattern": "^rule_[0-9a-z][0-9a-z._-]{0,47}$" },
            "rule_version": { "type": "string", "pattern": "^[0-9a-zA-Z][0-9a-zA-Z._-]{0,31}$" },
            "levels": {
              "type": "array",
              "minItems": 1,
              "maxItems": 1000,
              "description": "Waterfall levels in the order they are tried. Level n is called for when its committed input count is at least min_inputs and no earlier level was.",
              "items": {
                "type": "object",
                "required": ["level", "min_inputs"],
                "additionalProperties": false,
                "properties": {
                  "level": { "type": "integer", "minimum": 1, "maximum": 9999 },
                  "min_inputs": { "type": "integer", "minimum": 1, "maximum": 1000000 }
                }
              }
            },
            "fallback": { "type": "string", "pattern": "^[a-z][a-z0-9_]{0,63}$", "description": "Label of the fallback the rule names when no level is met, for example insufficient_data_policy." },
            "committed_at": {
              "type": "object",
              "required": ["utc", "drift_seconds"],
              "additionalProperties": false,
              "properties": {
                "utc": { "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$" },
                "drift_seconds": { "type": "integer", "minimum": 0, "maximum": 86400 }
              }
            }
          }
        },
        "rule_digest": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
        "period": {
          "type": "object",
          "required": ["start", "end"],
          "additionalProperties": false,
          "properties": {
            "start": {
              "type": "object",
              "required": ["utc", "drift_seconds"],
              "additionalProperties": false,
              "properties": {
                "utc": { "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$" },
                "drift_seconds": { "type": "integer", "minimum": 0, "maximum": 86400 }
              }
            },
            "end": {
              "type": "object",
              "required": ["utc", "drift_seconds"],
              "additionalProperties": false,
              "properties": {
                "utc": { "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$" },
                "drift_seconds": { "type": "integer", "minimum": 0, "maximum": 86400 }
              }
            }
          }
        },
        "input_counts": {
          "type": "array",
          "minItems": 1,
          "maxItems": 1000,
          "description": "Committed count of eligible inputs available to each level for this period, one entry per rule level in rule order.",
          "items": {
            "type": "object",
            "required": ["level", "count"],
            "additionalProperties": false,
            "properties": {
              "level": { "type": "integer", "minimum": 1, "maximum": 9999 },
              "count": { "type": "integer", "minimum": 0, "maximum": 1000000 }
            }
          }
        },
        "published_outcome": { "type": "string", "pattern": "^(level_[1-9][0-9]{0,3}|fallback)$" },
        "computed_outcome": { "type": "string", "pattern": "^(level_[1-9][0-9]{0,3}|fallback)$" },
        "finding": { "type": "string", "enum": ["published_matches_rule", "published_differs_from_rule"] },
        "instrument_commitment": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
        "publisher_commitment": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
        "salt_commitment": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
        "recorded_at": {
          "type": "object",
          "required": ["utc", "drift_seconds"],
          "additionalProperties": false,
          "properties": {
            "utc": { "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$" },
            "drift_seconds": { "type": "integer", "minimum": 0, "maximum": 86400 }
          }
        },
        "boundary": {
          "type": "string",
          "minLength": 1,
          "const": "Hive records and checks; it does not decide, block, enforce or sit in the access path. This receipt shows that the recorded input counts, applied to a waterfall rule recorded before the calculation period began, call for the computed level or fallback, and whether the level the publisher reported differs from it. It shows what was recorded and when, not that it was correct: it does not establish that the counts are true, that the inputs were eligible, that the rule is adequate, or that any published value was right. The instrument and the publisher are presented as salted commitments."
        }
      }
    }
  }
}
