{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/authorization-decision-v1.json",
  "title": "Authorization Decision Receipt, v1",
  "description": "Canonical schema for the Hive authorization decision receipt, canonical type authorization.decision.",
  "type": "object",
  "required": [
    "receipt_id",
    "payload_sha256",
    "sig_b64u",
    "key_id",
    "algorithm",
    "ts",
    "signed_body"
  ],
  "additionalProperties": false,
  "properties": {
    "receipt_id": { "type": "string", "pattern": "^r_authorization\\.decision_[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",
        "authorization_decision",
        "boundary"
      ],
      "additionalProperties": false,
      "properties": {
        "receipt_type": { "type": "string", "const": "authorization.decision" },
        "schema": { "type": "string", "const": "r1.0.0" },
        "authorization_decision": {
          "type": "object",
          "required": [
            "decision_id",
            "decided_at",
            "observer_role",
            "verdict",
            "decision_basis",
            "mandate_ref",
            "mandate_scope_digest",
            "mandate_liveness",
            "agent_identity_commitment",
            "acceptor_pseudonym",
            "currency",
            "amount_commitment",
            "evaluated_constraint_count",
            "violated_constraint_count",
            "violated_constraint_digest",
            "decision_relation",
            "evidence_access_class",
            "salt_commitment"
          ],
          "additionalProperties": false,
          "properties": {
            "decision_id": { "type": "string", "pattern": "^ad_[0-9a-f]{16,64}$" },
            "decided_at": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d{1,9})?Z$" },
            "observer_role": { "type": "string", "const": "non_party_observer" },
            "verdict": { "type": "string", "enum": ["approved", "declined"] },
            "decision_basis": {
              "type": "string",
              "enum": [
                "within_mandate",
                "amount_exceeded",
                "velocity_exceeded",
                "acceptor_not_permitted",
                "category_not_permitted",
                "mandate_expired",
                "mandate_revoked",
                "mandate_absent"
              ]
            },
            "mandate_ref": {
              "type": ["object", "null"],
              "required": ["mandate_id", "payload_sha256", "issued_at", "expires_at"],
              "additionalProperties": false,
              "properties": {
                "mandate_id": { "type": "string", "pattern": "^md_[0-9a-f]{16,64}$" },
                "payload_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
                "issued_at": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d{1,9})?Z$" },
                "expires_at": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d{1,9})?Z$" }
              }
            },
            "mandate_scope_digest": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "mandate_liveness": {
              "type": "object",
              "required": ["evaluated_at", "revocation_source_digest", "liveness_class"],
              "additionalProperties": false,
              "properties": {
                "evaluated_at": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d{1,9})?Z$" },
                "revocation_source_digest": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
                "liveness_class": { "type": "string", "enum": ["live", "expired", "revoked", "unknown"] }
              }
            },
            "agent_identity_commitment": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "acceptor_pseudonym": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "currency": { "type": "string", "pattern": "^[A-Z]{3}$" },
            "amount_commitment": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "evaluated_constraint_count": { "type": "integer", "minimum": 0, "maximum": 100000 },
            "violated_constraint_count": { "type": "integer", "minimum": 0, "maximum": 100000 },
            "violated_constraint_digest": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "decision_relation": { "type": "string", "enum": ["consistent_with_scope", "inconsistent_with_scope"] },
            "evidence_access_class": { "type": "string", "enum": ["confidential_independent", "issuer_only", "public_commitment_only"] },
            "salt_commitment": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
          }
        },
        "boundary": {
          "type": "string",
          "minLength": 1,
          "const": "This receipt attests only that a named observer recomputed the stated authorization decision from the supplied confidential evidence at the stated instant. It does not attest that the underlying goods or services were delivered, that the cardholder intended the purchase, that the merchant is legitimate, that funds settled, that the issuer honored the decision, or that any party outside the named observer agrees with the finding."
        }
      }
    }
  }
}
