{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/mandate-conformance-v1.json",
  "title": "Mandate Conformance Receipt, v1",
  "description": "Canonical schema for the Hive mandate conformance receipt, canonical type mandate.conformance.",
  "type": "object",
  "required": [
    "receipt_id",
    "payload_sha256",
    "sig_b64u",
    "key_id",
    "algorithm",
    "ts",
    "signed_body"
  ],
  "additionalProperties": false,
  "properties": {
    "receipt_id": {
      "type": "string",
      "pattern": "^r_mandate\\.conformance_[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",
        "conformance_id",
        "tenant_id",
        "mandate_ref",
        "initiator",
        "transaction",
        "conformance",
        "outcome",
        "evaluated_at",
        "boundary"
      ],
      "additionalProperties": false,
      "properties": {
        "receipt_type": {
          "type": "string",
          "const": "mandate.conformance"
        },
        "schema": {
          "type": "string",
          "const": "r1.0.0"
        },
        "conformance_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256
        },
        "tenant_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256
        },
        "mandate_ref": {
          "type": "object",
          "required": [
            "receipt_id",
            "payload_sha256",
            "delegation_id"
          ],
          "additionalProperties": false,
          "properties": {
            "receipt_id": {
              "type": "string",
              "pattern": "^r_authority\\.delegation_[0-9]{10,}_[0-9a-f]{12}$"
            },
            "payload_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "delegation_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            }
          }
        },
        "initiator": {
          "type": "object",
          "required": [
            "kind",
            "human_present",
            "cardholder_verification"
          ],
          "additionalProperties": false,
          "properties": {
            "kind": {
              "type": "string",
              "enum": [
                "agent",
                "human",
                "hybrid"
              ]
            },
            "agent_did": {
              "type": "string",
              "minLength": 1,
              "maxLength": 512
            },
            "human_present": {
              "type": "boolean"
            },
            "cardholder_verification": {
              "type": "string",
              "enum": [
                "none",
                "device_biometric",
                "device_passcode",
                "three_ds_challenge",
                "three_ds_frictionless",
                "out_of_band"
              ]
            }
          }
        },
        "transaction": {
          "type": "object",
          "required": [
            "amount_minor",
            "currency",
            "merchant_id",
            "merchant_category_code",
            "authorized_at",
            "transaction_fingerprint_sha256",
            "network"
          ],
          "additionalProperties": false,
          "properties": {
            "amount_minor": {
              "type": "integer",
              "minimum": 0
            },
            "currency": {
              "type": "string",
              "pattern": "^[A-Z]{3}$"
            },
            "merchant_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "merchant_category_code": {
              "type": "string",
              "pattern": "^[0-9]{4}$"
            },
            "authorized_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$"
            },
            "transaction_fingerprint_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "network": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            }
          }
        },
        "display_binding": {
          "type": "object",
          "required": [
            "terms_sha256",
            "presented_at",
            "presentation_kind"
          ],
          "additionalProperties": false,
          "properties": {
            "terms_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "presented_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$"
            },
            "presentation_kind": {
              "type": "string",
              "enum": [
                "checkout_summary",
                "terms_of_sale",
                "mandate_disclosure"
              ]
            }
          }
        },
        "evaluation_window": {
          "type": "object",
          "description": "Optional windowed aggregation extension. When present the receipt additionally evaluates a cumulative constraint accumulated over one declared accounting window. The ceiling and the running total appear only as keyed commitments. A receipt without this object is a per action receipt and is unchanged.",
          "required": [
            "window_id",
            "window_start",
            "window_end",
            "window_index",
            "aggregation_key",
            "limit_commitment",
            "aggregated_notional_commitment",
            "salt_commitment",
            "currency",
            "per_tx_checked",
            "per_tx_conforming",
            "window_verdict",
            "breach_class",
            "magnitude_class",
            "prior_window",
            "closed_by"
          ],
          "additionalProperties": false,
          "properties": {
            "window_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256
            },
            "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$"
            },
            "window_index": {
              "type": "integer",
              "minimum": 0
            },
            "aggregation_key": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "limit_commitment": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "aggregated_notional_commitment": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "salt_commitment": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "currency": {
              "type": "string",
              "pattern": "^[A-Z]{3}$"
            },
            "per_tx_checked": {
              "type": "integer",
              "minimum": 1
            },
            "per_tx_conforming": {
              "type": "integer",
              "minimum": 0
            },
            "window_verdict": {
              "type": "string",
              "enum": [
                "within_window",
                "breach"
              ]
            },
            "breach_class": {
              "type": [
                "string",
                "null"
              ],
              "enum": [
                "aggregate_limit",
                "count_limit",
                null
              ]
            },
            "magnitude_class": {
              "type": [
                "string",
                "null"
              ],
              "enum": [
                "at_or_under",
                "over_by_up_to_1_pct",
                "over_by_1_to_10_pct",
                "over_by_10_to_50_pct",
                "over_by_more_than_50_pct",
                null
              ]
            },
            "prior_window": {
              "type": [
                "object",
                "null"
              ],
              "required": [
                "receipt_id",
                "payload_sha256",
                "window_index"
              ],
              "additionalProperties": false,
              "properties": {
                "receipt_id": {
                  "type": "string",
                  "pattern": "^r_mandate\\.conformance_[0-9]{10,}_[0-9a-f]{12}$"
                },
                "payload_sha256": {
                  "type": "string",
                  "pattern": "^[0-9a-f]{64}$"
                },
                "window_index": {
                  "type": "integer",
                  "minimum": 0
                }
              }
            },
            "closed_by": {
              "type": "string",
              "pattern": "^did:(hive|web|key):[A-Za-z0-9._:%-]+$"
            }
          }
        },
        "boundary_window": {
          "type": "string",
          "const": "This receipt additionally evaluates the named action against a cumulative constraint accumulated over one declared accounting window, and the window verdict, the two counts and the severity class were recomputed by this service rather than supplied by the caller. It does not attest that the set of actions accumulated into this window is complete, because this service can only accumulate the actions it was given, and an action withheld from the accumulation is invisible to this receipt. It does not disclose the cumulative ceiling or the accumulated position, both of which appear only as keyed commitments, and the severity class reports an order of magnitude rather than a value. It does not attest that the declared ceiling is the ceiling the account holder agreed to, and it establishes only that the committed ceiling did not change across a linked chain of windows. A breach verdict is a record that a cumulative bound was exceeded and is not a payment decline, a reversal, a dispute, or any determination of fault."
        },
        "conformance": {
          "type": "array",
          "minItems": 1,
          "maxItems": 8,
          "items": {
            "type": "object",
            "required": [
              "constraint",
              "expected",
              "observed",
              "result"
            ],
            "additionalProperties": false,
            "properties": {
              "constraint": {
                "type": "string",
                "enum": [
                  "amount",
                  "currency",
                  "scope"
                ]
              },
              "expected": {
                "type": [
                  "string",
                  "integer"
                ]
              },
              "observed": {
                "type": [
                  "string",
                  "integer"
                ]
              },
              "result": {
                "type": "string",
                "enum": [
                  "pass",
                  "fail",
                  "indeterminate"
                ]
              }
            }
          }
        },
        "outcome": {
          "type": "string",
          "enum": [
            "within_mandate",
            "outside_mandate",
            "indeterminate"
          ]
        },
        "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 the named transaction's amount, currency, timing and scope were compared against the constraints of one specific delegated authority receipt that was signed before the transaction was authorised, and that the outcome was recomputed by this service from that comparison rather than supplied by the caller. It does not attest that the cardholder granted the delegation, that the declared agent identity is genuine, that the transaction was authorised or settled by any network, that goods or services were delivered, or that the displayed terms digest corresponds to anything a person actually read. It is not a payment authorisation and carries no cardholder credential. No card network, issuer, or regulator currently recognises this receipt as authentication data, as compelling evidence, or as a liability shift, and it does not create one. It does not deny, resolve, adjudicate or affect any dispute, and it does not limit any right a consumer holds under Regulation E, Regulation Z, or any equivalent rule. This receipt evaluates one transaction against a per transaction constraint and does not evaluate cumulative spend, transaction velocity, or any aggregate limit across multiple transactions under the same mandate, so a series of individually conforming transactions may still exceed a spending intent this receipt cannot see. It evaluates the delegated authority receipt as supplied and inherits that receipt's revocation limitation, so it does not attest that the mandate was still unrevoked at the moment the transaction was authorised."
        }
      }
    }
  }
}
