{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/divergence-attestation-v1.json",
  "title": "Reader Divergence Attestation v1",
  "description": "Reader Divergence Attestation receipt. Several independent readers of the same document field disagree more often than a single reported value admits, so this receipt carries every reader commitment, the versioned selection rule with its declared deterministic tie break, and the commitment to the value that was reported. The service recomputes the rule digest, runs the committed rule over the committed commitments, and reports whether the value that was reported is the value the rule selects. It does not read the document, does not decide which reader is right, and does not attest that any reader value is correct; readers_executed_by_service is fixed to false because the service only ever sees 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_divergence\\.attestation_[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",
        "attestation_id",
        "evidence_digest_sha256",
        "recorded_at",
        "verdict",
        "boundary",
        "field_name",
        "readers",
        "selection_rule",
        "reported_value_commitment_sha256",
        "divergence_class_enumeration_version"
      ],
      "additionalProperties": false,
      "properties": {
        "receipt_type": {
          "type": "string",
          "const": "divergence.attestation"
        },
        "schema": {
          "type": "string",
          "const": "r1.0.0"
        },
        "attestation_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": [
            "readers_executed_by_service",
            "reader_correctness_proven",
            "reader_count",
            "distinct_value_count",
            "agreement_set_size",
            "divergence_set_size",
            "rule_digest_recomputed",
            "rule_selected_commitment_sha256",
            "tie_broken_deterministically",
            "selection_consistent_with_reported_value"
          ],
          "additionalProperties": false,
          "properties": {
            "readers_executed_by_service": {
              "type": "boolean",
              "const": false
            },
            "reader_correctness_proven": {
              "type": "boolean",
              "const": false
            },
            "reader_count": {
              "type": "integer",
              "minimum": 0
            },
            "distinct_value_count": {
              "type": "integer",
              "minimum": 0
            },
            "agreement_set_size": {
              "type": "integer",
              "minimum": 0
            },
            "divergence_set_size": {
              "type": "integer",
              "minimum": 0
            },
            "rule_digest_recomputed": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$",
              "description": "Digest the service recomputed over the committed rule identifier, version, parameters, and tie break."
            },
            "rule_selected_commitment_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$",
              "description": "Commitment the committed rule selects when the service runs it over the committed reader commitments."
            },
            "tie_broken_deterministically": {
              "type": "boolean"
            },
            "selection_consistent_with_reported_value": {
              "type": "boolean"
            }
          }
        },
        "boundary": {
          "type": "string",
          "const": "Reader Divergence Attestation receipt. Several independent readers of the same document field disagree more often than a single reported value admits, so this receipt carries every reader commitment, the versioned selection rule with its declared deterministic tie break, and the commitment to the value that was reported. The service recomputes the rule digest, runs the committed rule over the committed commitments, and reports whether the value that was reported is the value the rule selects. It does not read the document, does not decide which reader is right, and does not attest that any reader value is correct; readers_executed_by_service is fixed to false because the service only ever sees commitments."
        },
        "field_name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256,
          "description": "Named field the readers were asked to read."
        },
        "render_profile_digest_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Optional. Profile the read scope is expressed against."
        },
        "readers": {
          "type": "array",
          "minItems": 2,
          "maxItems": 64,
          "description": "One entry per independent reader. At least two, because a single reader cannot diverge.",
          "items": {
            "type": "object",
            "required": [
              "reader_ref",
              "value_commitment_sha256",
              "model_version_commitment_sha256",
              "confidence",
              "confidence_scale_ref"
            ],
            "additionalProperties": false,
            "properties": {
              "reader_ref": {
                "type": "string",
                "minLength": 1,
                "maxLength": 256,
                "description": "Opaque reference to the reader."
              },
              "value_commitment_sha256": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$",
                "description": "Commitment to this reader candidate value."
              },
              "model_version_commitment_sha256": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$",
                "description": "Commitment to the model version this reader ran."
              },
              "confidence": {
                "type": "number",
                "minimum": 0,
                "maximum": 1,
                "description": "Reader reported confidence."
              },
              "confidence_scale_ref": {
                "type": "string",
                "minLength": 1,
                "maxLength": 256,
                "description": "Named and versioned scale that gives the confidence value meaning."
              },
              "calibration_record_ref": {
                "type": "string",
                "minLength": 1,
                "maxLength": 256,
                "description": "Optional. Calibration record for that scale."
              },
              "divergence_class": {
                "type": "string",
                "enum": [
                  "whitespace",
                  "punctuation",
                  "case",
                  "digit_substitution",
                  "separator_placement",
                  "transposition",
                  "truncation",
                  "semantic",
                  "none"
                ],
                "description": "Optional. Class of this reader divergence from the agreement set, drawn from the committed enumeration."
              }
            }
          }
        },
        "selection_rule": {
          "type": "object",
          "required": [
            "rule_id",
            "rule_version",
            "rule_parameters_canonical",
            "tie_break"
          ],
          "additionalProperties": false,
          "properties": {
            "rule_id": {
              "type": "string",
              "enum": [
                "majority_commitment"
              ],
              "description": "Rule the service can actually recompute. Majority over reader value commitments."
            },
            "rule_version": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256,
              "description": "Version of that rule."
            },
            "rule_parameters_canonical": {
              "type": "string",
              "minLength": 2,
              "maxLength": 4096,
              "description": "Canonical form of the rule parameters, as a string, so the rule digest is reproducible byte for byte."
            },
            "tie_break": {
              "type": "string",
              "enum": [
                "lexicographic_lowest_commitment"
              ],
              "description": "Declared deterministic tie break, so a tie never resolves differently on two runs."
            }
          }
        },
        "reported_value_commitment_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Commitment to the value that was actually reported downstream."
        },
        "divergence_class_enumeration_version": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256,
          "description": "Version of the divergence class enumeration in force."
        }
      }
    }
  }
}
