{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/parametric-trigger-v1.json",
  "title": "Parametric Trigger Receipt, v1",
  "description": "Canonical schema for the Hive parametric trigger receipt, canonical type parametric.trigger.",
  "type": "object",
  "required": ["receipt_id", "payload_sha256", "sig_b64u", "key_id", "algorithm", "ts", "signed_body"],
  "additionalProperties": false,
  "properties": {
    "receipt_id": { "type": "string", "pattern": "^r_parametric\\.trigger_[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", "trigger_id", "tenant_id", "policy_ref", "attestation_ref", "budget_ref", "condition", "measuring_party", "trigger_state", "evaluated_at", "boundary"],
      "additionalProperties": false,
      "properties": {
        "receipt_type": { "type": "string", "const": "parametric.trigger" },
        "schema": { "type": "string", "const": "r1.0.0" },
        "trigger_id": { "type": "string", "minLength": 1, "maxLength": 256 },
        "tenant_id": { "type": "string", "minLength": 1, "maxLength": 256 },
        "policy_ref": {
          "type": "object",
          "required": ["policy_digest_sha256", "condition_index", "committed_at"],
          "additionalProperties": false,
          "properties": {
            "policy_digest_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "condition_index": { "type": "integer", "minimum": 0 },
            "committed_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$" }
          }
        },
        "attestation_ref": {
          "type": "object",
          "required": ["receipt_id", "payload_sha256"],
          "additionalProperties": false,
          "properties": {
            "receipt_id": { "type": "string", "pattern": "^r_perf\\.attestation_[0-9]{10,}_[0-9a-f]{12}$" },
            "payload_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
          }
        },
        "budget_ref": {
          "type": "object",
          "required": ["receipt_id", "payload_sha256"],
          "additionalProperties": false,
          "properties": {
            "receipt_id": { "type": "string", "pattern": "^r_perf\\.budget_[0-9]{10,}_[0-9a-f]{12}$" },
            "payload_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
          }
        },
        "condition": {
          "type": "object",
          "required": ["requires_outcome"],
          "additionalProperties": false,
          "properties": { "requires_outcome": { "type": "string", "enum": ["fail", "pass"] } }
        },
        "measuring_party": {
          "type": "object",
          "required": ["did", "role"],
          "additionalProperties": false,
          "properties": {
            "did": { "type": "string", "minLength": 1, "maxLength": 512 },
            "role": { "type": "string", "enum": ["insured", "insurer", "third_party", "undisclosed"] }
          }
        },
        "trigger_state": { "type": "string", "enum": ["satisfied", "not_satisfied", "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 a named parametric condition was evaluated against one specific Bonded Performance Attestation, that the policy terms digest was committed at or before the governing budget was declared and the budget was declared at or before its measurement window opened, and that trigger_state was recomputed by this service from the referenced attestation rather than supplied by the caller. It does not create, confirm, price, underwrite, or interpret any insurance policy, and this service never receives the policy terms. It does not establish that any claim is payable, does not effect or authorise any payment, and does not attest that the measured outputs were correct or that any loss occurred. The measuring party is recorded as declared and is not verified here. Whether this trigger state entitles any party to payment is determined solely by the parties' own contract." }
      }
    }
  }
}
