{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/jurisdictional-clearance-v1.json",
  "title": "Jurisdictional Clearance Receipt, v1",
  "description": "Canonical schema for the Hive jurisdictional clearance receipt, canonical type jurisdictional.clearance. The receipt records which named rule set a machine was operating under at a stated place and time, which registry version that rule set was resolved from, and whether the declared configuration satisfied the constraints that registry recorded. does_not_prove: this receipt is not a legal opinion, does not prove the rule registry is current or complete, does not prove any regulator accepts this mapping, and never reports a machine as compliant.",
  "type": "object",
  "required": [
    "receipt_id",
    "payload_sha256",
    "sig_b64u",
    "key_id",
    "algorithm",
    "ts",
    "signed_body"
  ],
  "additionalProperties": false,
  "properties": {
    "receipt_id": { "type": "string", "pattern": "^r_jurisdictional\\.clearance_[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",
        "clearance_id",
        "machine_commitment",
        "operating_at",
        "jurisdiction",
        "rule_registry",
        "rule_set_digest",
        "constraints_evaluated",
        "evaluated_count",
        "satisfied_count",
        "not_evaluable_count",
        "coverage_class",
        "clearance_class",
        "verdict",
        "salt_commitment",
        "boundary"
      ],
      "additionalProperties": false,
      "properties": {
        "receipt_type": { "type": "string", "const": "jurisdictional.clearance" },
        "schema": { "type": "string", "const": "r1.0.0" },
        "clearance_id": { "type": "string", "pattern": "^jc_[0-9a-f]{16,64}$" },
        "machine_commitment": {
          "type": "string",
          "description": "Salted HMAC over the machine serial. The serial itself never enters the receipt.",
          "pattern": "^[0-9a-f]{64}$"
        },
        "operating_at": {
          "type": "string",
          "description": "The instant the machine was operating under the resolved rule set.",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d{1,9})?Z$"
        },
        "jurisdiction": {
          "type": "object",
          "description": "The place, as a jurisdiction code, together with how that code was resolved.",
          "required": ["code", "resolution_class"],
          "additionalProperties": false,
          "properties": {
            "code": {
              "type": "string",
              "description": "ISO 3166-1 alpha-2 country code with an optional subdivision suffix.",
              "pattern": "^[A-Z]{2}(-[A-Z0-9]{1,3})?$"
            },
            "resolution_class": {
              "type": "string",
              "description": "How the jurisdiction code was arrived at. geofence_derived and gnss_derived both require a location_commitment, because a location derived claim with no location binding is an operator declaration wearing a better label.",
              "enum": [
                "operator_declared",
                "geofence_derived",
                "gnss_derived",
                "unresolved"
              ]
            }
          }
        },
        "location_commitment": {
          "type": "string",
          "description": "Optional. Salted HMAC over the precise coordinates, so the exact site stays private while the location binding stays checkable.",
          "pattern": "^[0-9a-f]{64}$"
        },
        "rule_registry": {
          "type": "object",
          "description": "The registry this service resolved the rule set from, at a named version.",
          "required": ["registry_version", "registry_commitment", "rule_set_ids"],
          "additionalProperties": false,
          "properties": {
            "registry_version": { "type": "string", "pattern": "^rr_[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
            "registry_commitment": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "rule_set_ids": {
              "type": "array",
              "description": "The rule sets the registry resolved for this jurisdiction code.",
              "minItems": 1,
              "maxItems": 32,
              "items": { "type": "string", "pattern": "^rs_[a-z0-9_.-]{3,64}$" }
            }
          }
        },
        "rule_set_digest": {
          "type": "string",
          "description": "RFC 6962 Merkle root over the sorted rule_set_ids, so the applied set cannot be edited after signing.",
          "pattern": "^[0-9a-f]{64}$"
        },
        "constraints_evaluated": {
          "type": "array",
          "description": "One entry per constraint the resolved rule set carries in the registry.",
          "minItems": 1,
          "maxItems": 64,
          "items": {
            "type": "object",
            "required": ["constraint_id", "outcome", "evidence_class"],
            "additionalProperties": false,
            "properties": {
              "constraint_id": { "type": "string", "pattern": "^cn_[a-z0-9_.-]{3,64}$" },
              "outcome": {
                "type": "string",
                "enum": ["satisfied", "not_satisfied", "not_evaluable"]
              },
              "evidence_class": {
                "type": "string",
                "description": "What backed the outcome. receipt_bound means a receipt carried the evidence, operator_declared means the operator asserted it, absent means nothing backed it.",
                "enum": ["receipt_bound", "operator_declared", "absent"]
              }
            }
          }
        },
        "evaluated_count": {
          "type": "integer",
          "description": "Recomputed by the service from constraints_evaluated.length.",
          "minimum": 1,
          "maximum": 64
        },
        "satisfied_count": {
          "type": "integer",
          "description": "Recomputed by the service from the constraints whose outcome is satisfied.",
          "minimum": 0,
          "maximum": 64
        },
        "not_evaluable_count": {
          "type": "integer",
          "description": "Recomputed by the service from the constraints whose outcome is not_evaluable.",
          "minimum": 0,
          "maximum": 64
        },
        "coverage_class": {
          "type": "string",
          "description": "Recomputed by the service from how many constraints could be evaluated at all.",
          "enum": ["fully_evaluated", "partially_evaluated", "not_evaluated"]
        },
        "clearance_class": {
          "type": "string",
          "description": "Recomputed by the service from the resolution class and the constraint outcomes.",
          "enum": [
            "all_constraints_satisfied",
            "constraints_unsatisfied",
            "coverage_insufficient",
            "jurisdiction_unresolved"
          ]
        },
        "verdict": {
          "type": "string",
          "description": "Recomputed by the service from the clearance class. The ceiling is rule_set_resolved_and_constraints_met. There is no verdict that says compliant.",
          "enum": [
            "rule_set_resolved_and_constraints_met",
            "rule_set_resolved_constraints_unmet",
            "rule_set_resolved_evidence_incomplete",
            "rule_set_not_resolved"
          ]
        },
        "salt_commitment": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
        "boundary": {
          "type": "string",
          "minLength": 1,
          "const": "This receipt records which named rule set a machine was operating under at a stated place and time, and whether the machine's declared configuration satisfied the constraints that rule set carries in this service's rule registry. It does not constitute a legal opinion, does not prove the rule registry is current or complete, and does not prove any regulator accepts this mapping."
        }
      }
    }
  }
}
