{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/mandate-aggregate-v1.json",
  "title": "Mandate Aggregate 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_mandate\\.aggregate_[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",
        "aggregate_id",
        "tenant_id",
        "mandate_ref",
        "window",
        "cumulative_constraint",
        "members",
        "totals",
        "outcome",
        "evaluated_at",
        "boundary"
      ],
      "additionalProperties": false,
      "properties": {
        "receipt_type": {
          "type": "string",
          "const": "mandate.aggregate"
        },
        "schema": {
          "type": "string",
          "const": "r1.0.0"
        },
        "aggregate_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
            }
          }
        },
        "window": {
          "type": "object",
          "required": [
            "opens_at",
            "closes_at"
          ],
          "additionalProperties": false,
          "properties": {
            "opens_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$"
            },
            "closes_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$"
            }
          }
        },
        "cumulative_constraint": {
          "type": "object",
          "required": [
            "max_total_minor",
            "currency",
            "max_count"
          ],
          "additionalProperties": false,
          "properties": {
            "max_total_minor": {
              "type": "integer",
              "minimum": 0
            },
            "currency": {
              "type": "string",
              "pattern": "^[A-Z]{3}$"
            },
            "max_count": {
              "type": "integer",
              "minimum": 1
            }
          }
        },
        "members": {
          "type": "array",
          "minItems": 1,
          "maxItems": 1000,
          "items": {
            "type": "object",
            "required": [
              "receipt_id",
              "payload_sha256",
              "amount_minor",
              "currency",
              "authorized_at"
            ],
            "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}$"
              },
              "amount_minor": {
                "type": "integer",
                "minimum": 0
              },
              "currency": {
                "type": "string",
                "pattern": "^[A-Z]{3}$"
              },
              "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$"
              }
            }
          }
        },
        "totals": {
          "type": "object",
          "required": [
            "total_minor",
            "count",
            "currency"
          ],
          "additionalProperties": false,
          "properties": {
            "total_minor": {
              "type": "integer",
              "minimum": 0
            },
            "count": {
              "type": "integer",
              "minimum": 0
            },
            "currency": {
              "type": "string",
              "pattern": "^[A-Z]{3}$"
            }
          }
        },
        "outcome": {
          "type": "string",
          "enum": [
            "within_cumulative",
            "exceeds_cumulative",
            "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 supplied set of mandate conformance receipts all reference the same delegated authority, all fall inside the stated window, share one currency, contain no duplicate, and that their cumulative total and count were recomputed by this service in integer minor units and compared against the stated cumulative constraint. This service cannot know whether the supplied set is complete. A transaction that was never presented here does not appear in these totals, so a within cumulative outcome is a statement about the receipts supplied and not a statement about everything the mandate holder spent. It performs no currency conversion, is not a payment authorisation, shifts no liability under any card network rule, and does not limit any right a consumer holds under Regulation E, Regulation Z, or any equivalent rule."
        }
      }
    }
  }
}
