{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/afir-ocr-docproof-v2.json",
  "title": "AFiR-OCR DocProof v1",
  "description": "AFiR-OCR DocProof receipt. Scoped to extraction provenance only: what an OCR engine read, from where, and under what confidence metadata. It does not attest that the extracted value is correct, and it does not share AFIR fragment routing infrastructure; shares_afir_route_backend is fixed to false because this contract has no dependency on the afir.route Modal backend.",
  "type": "object",
  "required": [
    "receipt_id",
    "payload_sha256",
    "sig_b64u",
    "key_id",
    "algorithm",
    "ts",
    "signed_body"
  ],
  "additionalProperties": false,
  "properties": {
    "receipt_id": {
      "type": "string",
      "pattern": "^r_afir\\.ocr\\.docproof_[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",
        "document_id",
        "evidence_digest_sha256",
        "recorded_at",
        "verdict",
        "boundary",
        "document_sha256",
        "render_profile_sha256",
        "engine_id",
        "engine_version",
        "engine_config_sha256",
        "confidence_policy",
        "fields",
        "field_leaf_sha256_values",
        "fields_root_sha256",
        "field_count",
        "elements",
        "outcome"
      ],
      "additionalProperties": false,
      "properties": {
        "receipt_type": {
          "type": "string",
          "const": "afir.ocr.docproof"
        },
        "schema": {
          "type": "string",
          "const": "r2.0.0"
        },
        "document_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": [
            "shares_afir_route_backend",
            "extraction_correctness_proven"
          ],
          "additionalProperties": false,
          "properties": {
            "shares_afir_route_backend": {
              "type": "boolean",
              "const": false
            },
            "extraction_correctness_proven": {
              "type": "boolean",
              "const": false
            }
          }
        },
        "boundary": {
          "type": "string",
          "const": "AFiR-OCR DocProof receipt. Scoped to extraction provenance only: what an OCR engine read, from where, and under what confidence metadata. It does not attest that the extracted value is correct, and it does not share AFIR fragment routing infrastructure; shares_afir_route_backend is fixed to false because this contract has no dependency on the afir.route Modal backend."
        },
        "document_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Digest of the source document."
        },
        "render_profile_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Digest of the render profile used for page coordinates."
        },
        "engine_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256,
          "pattern": "^[A-Za-z0-9._:/-]{1,256}$",
          "description": "OCR engine identifier."
        },
        "engine_version": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256,
          "pattern": "^[A-Za-z0-9._:/-]{1,256}$",
          "description": "OCR engine version."
        },
        "engine_config_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Digest of the OCR engine configuration."
        },
        "confidence_policy": {
          "type": "object",
          "required": [
            "minimum_confidence"
          ],
          "additionalProperties": false,
          "properties": {
            "minimum_confidence": {
              "type": "number",
              "minimum": 0,
              "maximum": 1
            },
            "page_count": {
              "type": "integer",
              "minimum": 1,
              "maximum": 65536
            }
          }
        },
        "fields": {
          "type": "array",
          "minItems": 1,
          "maxItems": 4096,
          "items": {
            "type": "object",
            "required": [
              "field_name",
              "value_commitment_sha256",
              "page_index",
              "normalized_bbox",
              "block_type",
              "confidence"
            ],
            "additionalProperties": false,
            "properties": {
              "field_name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 256,
                "pattern": "^[A-Za-z0-9._:/-]{1,256}$",
                "description": "Stable field name within this extraction bundle."
              },
              "value_commitment_sha256": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$",
                "description": "Commitment to the extracted value."
              },
              "page_index": {
                "type": "integer",
                "minimum": 0,
                "maximum": 65535
              },
              "normalized_bbox": {
                "type": "object",
                "required": [
                  "x",
                  "y",
                  "width",
                  "height"
                ],
                "additionalProperties": false,
                "properties": {
                  "x": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1
                  },
                  "y": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1
                  },
                  "width": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1
                  },
                  "height": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1
                  }
                }
              },
              "block_type": {
                "type": "string",
                "enum": [
                  "text",
                  "table_cell",
                  "key_value",
                  "checkbox",
                  "signature_mark",
                  "other"
                ]
              },
              "confidence": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              }
            }
          }
        },
        "field_leaf_sha256_values": {
          "type": "array",
          "minItems": 1,
          "maxItems": 4096,
          "items": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$",
            "description": "One canonical leaf digest."
          },
          "description": "Canonical leaf digest for each field in supplied order."
        },
        "fields_root_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Canonical root over the ordered field leaf digests."
        },
        "field_count": {
          "type": "integer",
          "minimum": 0,
          "maximum": 4096
        },
        "elements": {
          "type": "array",
          "minItems": 0,
          "maxItems": 2,
          "items": {
            "type": "string",
            "enum": [
              "low_confidence_present",
              "page_scope_unresolved"
            ]
          }
        },
        "outcome": {
          "type": "string",
          "enum": [
            "extraction_bundle_bound",
            "review_required"
          ]
        }
      }
    }
  }
}
