{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/settlement-feed-v2.json",
  "title": "Hive Settlement Feed v1",
  "description": "Hive Settlement Feed checkpoint. It verifies canonical entry leaves, the entries root, count, currency and window relations, predecessor continuity, and debit and credit arithmetic in integer minor units. It does not prove that obligations are valid, that funds moved, or that settlement became final.",
  "type": "object",
  "required": [
    "receipt_id",
    "payload_sha256",
    "sig_b64u",
    "key_id",
    "algorithm",
    "ts",
    "signed_body"
  ],
  "additionalProperties": false,
  "properties": {
    "receipt_id": {
      "type": "string",
      "pattern": "^r_settlement\\.feed_[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",
        "settlement_id",
        "evidence_digest_sha256",
        "recorded_at",
        "verdict",
        "boundary",
        "feed_source_ref",
        "feed_sequence",
        "previous_feed_root_sha256",
        "currency",
        "window_start",
        "window_end",
        "entries",
        "entry_leaves",
        "entries_root_sha256",
        "entry_count",
        "debit_total_minor",
        "credit_total_minor",
        "balance_delta_minor",
        "elements",
        "outcome"
      ],
      "additionalProperties": false,
      "properties": {
        "receipt_type": {
          "type": "string",
          "const": "settlement.feed"
        },
        "schema": {
          "type": "string",
          "const": "r2.0.0"
        },
        "settlement_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": [
            "distinct_from_generic_signer",
            "funds_movement_confirmed",
            "settlement_finality_confirmed"
          ],
          "additionalProperties": false,
          "properties": {
            "distinct_from_generic_signer": {
              "type": "boolean",
              "const": false
            },
            "funds_movement_confirmed": {
              "type": "boolean",
              "const": false
            },
            "settlement_finality_confirmed": {
              "type": "boolean",
              "const": false
            }
          }
        },
        "boundary": {
          "type": "string",
          "const": "Hive Settlement Feed checkpoint. It verifies canonical entry leaves, the entries root, count, currency and window relations, predecessor continuity, and debit and credit arithmetic in integer minor units. It does not prove that obligations are valid, that funds moved, or that settlement became final."
        },
        "feed_source_ref": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256
        },
        "feed_sequence": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "previous_feed_root_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "prior_checkpoint": {
          "type": "object",
          "required": [
            "feed_sequence",
            "entries_root_sha256"
          ],
          "additionalProperties": false,
          "properties": {
            "feed_sequence": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "entries_root_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            }
          }
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "window_start": {
          "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$"
        },
        "window_end": {
          "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$"
        },
        "entries": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "entry_id",
              "obligation_ref",
              "amount_minor",
              "direction",
              "effective_at"
            ],
            "additionalProperties": false,
            "properties": {
              "entry_id": {
                "type": "string",
                "minLength": 1,
                "maxLength": 256
              },
              "obligation_ref": {
                "type": "string",
                "minLength": 1,
                "maxLength": 256
              },
              "amount_minor": {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991
              },
              "direction": {
                "type": "string",
                "enum": [
                  "debit",
                  "credit"
                ]
              },
              "effective_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$"
              },
              "currency": {
                "type": "string",
                "pattern": "^[A-Z]{3}$"
              }
            }
          },
          "minItems": 1,
          "maxItems": 4096
        },
        "entry_leaves": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "minItems": 1,
          "maxItems": 4096
        },
        "entries_root_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "entry_count": {
          "type": "integer",
          "minimum": 0,
          "maximum": 4096
        },
        "debit_total_minor": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "credit_total_minor": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "balance_delta_minor": {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        "elements": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "duplicate_entry",
              "mixed_currency",
              "sequence_gap",
              "debit_credit_mismatch"
            ]
          },
          "minItems": 0,
          "maxItems": 4
        },
        "outcome": {
          "type": "string",
          "enum": [
            "internally_balanced_checkpoint",
            "internally_unbalanced_checkpoint",
            "continuity_unresolved"
          ]
        }
      }
    }
  }
}
