{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/ledger-parity-v1.json",
  "title": "Ledger Parity Receipt, v1",
  "type": "object",
  "required": [
    "receipt_id",
    "payload_sha256",
    "sig_b64u",
    "key_id",
    "algorithm",
    "ts",
    "signed_body"
  ],
  "additionalProperties": false,
  "properties": {
    "receipt_id": {
      "type": "string",
      "pattern": "^r_ledger\\.parity_[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",
        "parity_id",
        "tenant_id",
        "subject",
        "commitment",
        "agreed_fields",
        "ledger_a",
        "ledger_b",
        "comparison",
        "attestors",
        "anchor",
        "sequence",
        "evaluated_at",
        "boundary"
      ],
      "additionalProperties": false,
      "properties": {
        "receipt_type": {
          "type": "string",
          "const": "ledger.parity"
        },
        "schema": {
          "type": "string",
          "const": "r1.0.0"
        },
        "parity_id": {
          "type": "string",
          "maxLength": 128,
          "pattern": "^p_[a-z0-9_]{1,32}_[0-9]{10,}_[0-9a-f]{8}$"
        },
        "tenant_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256
        },
        "subject": {
          "type": "object",
          "required": [
            "instrument_label",
            "identifier_scheme",
            "identifier_digest_sha256"
          ],
          "additionalProperties": false,
          "properties": {
            "instrument_label": {
              "type": "string",
              "pattern": "^[A-Z0-9][A-Z0-9._:-]{0,63}$"
            },
            "identifier_scheme": {
              "type": "string",
              "enum": [
                "national_numbering",
                "internal_registry",
                "contract_address",
                "composite",
                "undisclosed"
              ]
            },
            "identifier_digest_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "asset_class": {
              "type": "string",
              "enum": [
                "equity",
                "debt",
                "fund_unit",
                "commodity_receipt",
                "other"
              ]
            }
          }
        },
        "commitment": {
          "type": "object",
          "required": [
            "method",
            "function",
            "commitment_key_id",
            "window_salt_digest_sha256",
            "encoding_profile"
          ],
          "additionalProperties": false,
          "properties": {
            "method": {
              "type": "string",
              "enum": [
                "keyed_commitment_equality",
                "unkeyed_digest_equality",
                "zero_knowledge_equality"
              ]
            },
            "function": {
              "type": "string",
              "enum": [
                "hmac-sha256",
                "hmac-sha512",
                "kmac128",
                "kmac256"
              ]
            },
            "commitment_key_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            },
            "window_salt_digest_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "encoding_profile": {
              "type": "string",
              "const": "sorted-keys-no-whitespace-utf8"
            }
          }
        },
        "agreed_fields": {
          "type": "array",
          "minItems": 1,
          "maxItems": 32,
          "items": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          }
        },
        "ledger_a": {
          "type": "object",
          "required": [
            "name",
            "record_kind",
            "cursor_kind",
            "cursor_value",
            "state_digest_sha256",
            "observed_at",
            "attestor_key_id",
            "attestor_sig_b64u",
            "attestor_algorithm"
          ],
          "additionalProperties": false,
          "properties": {
            "name": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,63}$"
            },
            "record_kind": {
              "type": "string",
              "enum": [
                "distributed_ledger",
                "book_entry_register",
                "transfer_agent_register",
                "custodial_subledger",
                "internal_ledger",
                "other"
              ]
            },
            "cursor_kind": {
              "type": "string",
              "enum": [
                "block_height",
                "block_hash",
                "snapshot_id",
                "sequence_number",
                "log_offset",
                "transaction_id"
              ]
            },
            "cursor_value": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256,
              "pattern": "^[A-Za-z0-9_.:-]{1,256}$"
            },
            "state_digest_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "observed_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$"
            },
            "attestor_key_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "attestor_sig_b64u": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,512}$"
            },
            "attestor_algorithm": {
              "type": "string",
              "enum": [
                "ed25519"
              ]
            }
          }
        },
        "ledger_b": {
          "type": "object",
          "required": [
            "name",
            "record_kind",
            "cursor_kind",
            "cursor_value",
            "state_digest_sha256",
            "observed_at",
            "attestor_key_id",
            "attestor_sig_b64u",
            "attestor_algorithm"
          ],
          "additionalProperties": false,
          "properties": {
            "name": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,63}$"
            },
            "record_kind": {
              "type": "string",
              "enum": [
                "distributed_ledger",
                "book_entry_register",
                "transfer_agent_register",
                "custodial_subledger",
                "internal_ledger",
                "other"
              ]
            },
            "cursor_kind": {
              "type": "string",
              "enum": [
                "block_height",
                "block_hash",
                "snapshot_id",
                "sequence_number",
                "log_offset",
                "transaction_id"
              ]
            },
            "cursor_value": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256,
              "pattern": "^[A-Za-z0-9_.:-]{1,256}$"
            },
            "state_digest_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "observed_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$"
            },
            "attestor_key_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "attestor_sig_b64u": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,512}$"
            },
            "attestor_algorithm": {
              "type": "string",
              "enum": [
                "ed25519"
              ]
            }
          }
        },
        "comparison": {
          "type": "object",
          "required": [
            "window_tolerance_ms",
            "observed_gap_ms",
            "result",
            "divergence"
          ],
          "additionalProperties": false,
          "properties": {
            "window_tolerance_ms": {
              "type": "integer",
              "minimum": 0,
              "maximum": 86400000
            },
            "observed_gap_ms": {
              "type": "integer",
              "minimum": 0,
              "maximum": 86400000
            },
            "result": {
              "type": "string",
              "enum": [
                "match",
                "divergence",
                "window_exceeded"
              ]
            },
            "divergence": {
              "type": [
                "object",
                "null"
              ],
              "required": [
                "field",
                "magnitude_basis",
                "magnitude_class",
                "direction",
                "additional_fields_differ"
              ],
              "additionalProperties": false,
              "properties": {
                "field": {
                  "type": "string",
                  "pattern": "^[a-z][a-z0-9_]{0,63}$"
                },
                "magnitude_basis": {
                  "type": "string",
                  "enum": [
                    "absolute_count",
                    "absolute_minor_units",
                    "relative_parts_per_million",
                    "set_symmetric_difference",
                    "not_quantified"
                  ]
                },
                "magnitude_class": {
                  "type": "string",
                  "enum": [
                    "0",
                    "1-10",
                    "11-100",
                    "101-1000",
                    "1001-10000",
                    "10001-100000",
                    "100001-1000000",
                    "gt-1000000",
                    "unquantified"
                  ]
                },
                "direction": {
                  "type": "string",
                  "enum": [
                    "a_greater",
                    "b_greater",
                    "incomparable"
                  ]
                },
                "additional_fields_differ": {
                  "type": "boolean"
                }
              }
            }
          }
        },
        "attestors": {
          "type": "object",
          "required": [
            "required",
            "signed"
          ],
          "additionalProperties": false,
          "properties": {
            "required": {
              "type": "integer",
              "minimum": 2,
              "maximum": 16
            },
            "signed": {
              "type": "integer",
              "minimum": 0,
              "maximum": 16
            }
          }
        },
        "anchor": {
          "type": "object",
          "required": [
            "time_source",
            "anchor_time",
            "drift_bound_ms"
          ],
          "additionalProperties": false,
          "properties": {
            "time_source": {
              "type": "string",
              "enum": [
                "satellite_disciplined_clock",
                "precision_time_protocol",
                "network_time_protocol",
                "institutional_time_service",
                "undisclosed"
              ]
            },
            "anchor_time": {
              "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_bound_ms": {
              "type": "integer",
              "minimum": 0,
              "maximum": 60000
            }
          }
        },
        "sequence": {
          "type": "object",
          "required": [
            "prev_hash_sha256",
            "ledger_seq"
          ],
          "additionalProperties": false,
          "properties": {
            "prev_hash_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "ledger_seq": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "evaluated_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$"
        },
        "boundary": {
          "type": "string",
          "const": "This receipt attests that two named records, each observed at a named cursor and at a named instant, and each committed by a distinct registered attestor key to a keyed digest computed over the same declared list of fields, produced the comparison outcome that this service recomputed from those two committed digests and those two instants against the declared window tolerance. It does not disclose any position, balance, holder identity, or account identifier. It does not attest that either committed digest is a correct digest of the record it names, because confirming that requires read access which this receipt does not confer. It does not decide which record is correct when the two records diverge, assigns no fault to either operator, does not decide whether the underlying settlement, transfer, or register update was proper, and does not effect or reverse any settlement. A window_exceeded outcome records only that the two observations were too far apart for the comparison to be decisive."
        }
      }
    }
  }
}
