{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://mandateshield.com/schemas/execution-receipt-v1.json",
  "title": "MandateShield Terminal Execution Receipt JWT Claims v1",
  "description": "Strict decoded claims for an ES256 compact JWT whose protected header is alg=ES256, typ=MSE+JWT and contains a retained MandateShield JWKS kid. The receipt proves the terminal transition and recorded evidence classification, not more independent provider or settlement assurance than its evidence fields state.",
  "$comment": "Conforming validators additionally recompute the documented SHA-256 cross-field bindings and enforce timestamp chronology. JSON Schema cannot express every cryptographic or cross-field invariant.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "iss",
    "aud",
    "jti",
    "iat",
    "spec",
    "receipt_profile",
    "artifact_purpose",
    "execution_authorized",
    "authorization_ref",
    "decision_receipt_id",
    "decision_receipt_hash",
    "permit_id",
    "permit_hash",
    "transition_ref",
    "transition_digest",
    "input_digest",
    "attempt_digest",
    "protocol",
    "provider",
    "payee",
    "amount",
    "resource",
    "action",
    "from_state",
    "to_state",
    "outcome",
    "payment_reference",
    "transitioned_at",
    "outcome_occurred_at",
    "settlement_deadline",
    "evidence_class",
    "evidence_digest",
    "independent_verification"
  ],
  "properties": {
    "iss": {
      "const": "https://mandateshield.com"
    },
    "aud": {
      "type": "string",
      "minLength": 1,
      "maxLength": 240,
      "description": "One exact PROCESSOR audience. JWT audience arrays are not accepted."
    },
    "jti": {
      "type": "string",
      "pattern": "^mse_[a-f0-9]{32}$",
      "description": "Unique terminal execution-receipt identifier."
    },
    "iat": {
      "type": "integer",
      "minimum": 1,
      "description": "JWT NumericDate in whole seconds."
    },
    "spec": {
      "const": "https://mandateshield.com/specifications/execution-receipt/v1"
    },
    "receipt_profile": {
      "const": "cryptographic-execution-state-v1"
    },
    "artifact_purpose": {
      "const": "HISTORICAL_EXECUTION_EVIDENCE"
    },
    "execution_authorized": {
      "const": false,
      "description": "A historical execution receipt never grants a new provider submission."
    },
    "authorization_ref": {
      "type": "string",
      "pattern": "^[A-Za-z0-9._:~-]{1,256}$"
    },
    "decision_receipt_id": {
      "type": "string",
      "pattern": "^msr_[a-f0-9]{32}$"
    },
    "decision_receipt_hash": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    },
    "permit_id": {
      "anyOf": [
        {
          "type": "string",
          "pattern": "^msp_[a-f0-9]{32}$"
        },
        {
          "type": "null"
        }
      ]
    },
    "permit_hash": {
      "anyOf": [
        {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{64}$"
        },
        {
          "type": "null"
        }
      ]
    },
    "transition_ref": {
      "type": "string",
      "pattern": "^[A-Za-z0-9._:~-]{1,256}$"
    },
    "transition_digest": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    },
    "input_digest": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    },
    "attempt_digest": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    },
    "protocol": {
      "type": "string",
      "pattern": "^[A-Z][A-Z0-9_-]{0,31}$"
    },
    "provider": {
      "anyOf": [
        {
          "$ref": "#/$defs/provider"
        },
        {
          "type": "null"
        }
      ]
    },
    "payee": {
      "$ref": "#/$defs/payee"
    },
    "amount": {
      "$ref": "#/$defs/amount"
    },
    "resource": {
      "anyOf": [
        {
          "$ref": "#/$defs/resource"
        },
        {
          "type": "null"
        }
      ]
    },
    "action": {
      "type": "string",
      "enum": [
        "COMMIT",
        "RELEASE",
        "EXPIRE",
        "SETTLE_UNKNOWN"
      ]
    },
    "from_state": {
      "type": "string",
      "enum": [
        "RESERVED",
        "CONSUMED",
        "COMMITTED",
        "RELEASED",
        "EXPIRED",
        "SETTLEMENT_UNKNOWN"
      ]
    },
    "to_state": {
      "type": "string",
      "enum": [
        "COMMITTED",
        "RELEASED",
        "EXPIRED",
        "SETTLEMENT_UNKNOWN"
      ]
    },
    "outcome": {
      "type": "string",
      "enum": [
        "COMMITTED",
        "NOT_SUBMITTED",
        "FAILED",
        "EXPIRED",
        "SETTLEMENT_UNKNOWN"
      ]
    },
    "payment_reference": {
      "anyOf": [
        {
          "type": "string",
          "minLength": 1,
          "maxLength": 240
        },
        {
          "type": "null"
        }
      ]
    },
    "outcome_occurred_at": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": 1
        },
        {
          "type": "null"
        }
      ],
      "description": "Provider outcome time as a whole-second Unix timestamp when supplied by the processor adapter."
    },
    "transitioned_at": {
      "type": "integer",
      "minimum": 1,
      "description": "Authoritative MandateShield transition time as a whole-second Unix timestamp."
    },
    "settlement_deadline": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": 1
        },
        {
          "type": "null"
        }
      ]
    },
    "evidence_class": {
      "type": "string",
      "enum": [
        "CALLER_ASSERTED",
        "FACILITATOR_SIGNED",
        "PROVIDER_API_VERIFIED",
        "CHAIN_FINALIZED",
        "UNRESOLVED",
        "LEDGER_DERIVED"
      ]
    },
    "evidence_digest": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    },
    "independent_verification": {
      "type": "boolean",
      "description": "True only when MandateShield independently validated facilitator-signed, provider-API or canonical-chain evidence. Caller assertions, unresolved outcomes and ledger-only evidence are always false."
    }
  },
  "oneOf": [
    {
      "properties": {
        "permit_id": {
          "type": "null"
        },
        "permit_hash": {
          "type": "null"
        }
      }
    },
    {
      "properties": {
        "permit_id": {
          "type": "string",
          "pattern": "^msp_[a-f0-9]{32}$"
        },
        "permit_hash": {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{64}$"
        }
      }
    }
  ],
  "allOf": [
    {
      "if": {
        "properties": {
          "action": {
            "const": "COMMIT"
          }
        },
        "required": [
          "action"
        ]
      },
      "then": {
        "properties": {
          "from_state": {
            "enum": [
              "CONSUMED",
              "SETTLEMENT_UNKNOWN"
            ]
          },
          "to_state": {
            "const": "COMMITTED"
          },
          "outcome": {
            "const": "COMMITTED"
          },
          "payment_reference": {
            "type": "string",
            "minLength": 1,
            "maxLength": 240
          },
          "outcome_occurred_at": {
            "type": "integer",
            "minimum": 1
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "action": {
            "const": "RELEASE"
          }
        },
        "required": [
          "action"
        ]
      },
      "then": {
        "properties": {
          "from_state": {
            "enum": [
              "RESERVED",
              "CONSUMED"
            ]
          },
          "to_state": {
            "const": "RELEASED"
          },
          "outcome": {
            "enum": [
              "NOT_SUBMITTED",
              "FAILED"
            ]
          },
          "outcome_occurred_at": {
            "type": "integer",
            "minimum": 1
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "action": {
            "const": "EXPIRE"
          }
        },
        "required": [
          "action"
        ]
      },
      "then": {
        "properties": {
          "from_state": {
            "const": "RESERVED"
          },
          "to_state": {
            "const": "EXPIRED"
          },
          "outcome": {
            "const": "EXPIRED"
          },
          "outcome_occurred_at": {
            "type": "null"
          },
          "evidence_class": {
            "const": "LEDGER_DERIVED"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "action": {
            "const": "SETTLE_UNKNOWN"
          }
        },
        "required": [
          "action"
        ]
      },
      "then": {
        "properties": {
          "from_state": {
            "const": "CONSUMED"
          },
          "to_state": {
            "const": "SETTLEMENT_UNKNOWN"
          },
          "outcome": {
            "const": "SETTLEMENT_UNKNOWN"
          },
          "outcome_occurred_at": {
            "type": "null"
          },
          "evidence_class": {
            "const": "UNRESOLVED"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "independent_verification": {
            "const": true
          }
        },
        "required": [
          "independent_verification"
        ]
      },
      "then": {
        "properties": {
          "evidence_class": {
            "enum": [
              "FACILITATOR_SIGNED",
              "PROVIDER_API_VERIFIED",
              "CHAIN_FINALIZED"
            ]
          },
          "action": {
            "enum": [
              "COMMIT",
              "RELEASE"
            ]
          },
          "permit_id": {
            "type": "string",
            "pattern": "^msp_[a-f0-9]{32}$"
          },
          "provider": {
            "$ref": "#/$defs/provider"
          }
        }
      },
      "else": {
        "properties": {
          "evidence_class": {
            "enum": [
              "CALLER_ASSERTED",
              "UNRESOLVED",
              "LEDGER_DERIVED"
            ]
          }
        }
      }
    }
  ],
  "$defs": {
    "provider": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "profile",
        "environment",
        "account",
        "request_id",
        "request_digest",
        "idempotency_key"
      ],
      "properties": {
        "profile": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "environment": {
          "type": "string",
          "enum": [
            "test",
            "live"
          ]
        },
        "account": {
          "type": "string",
          "minLength": 1,
          "maxLength": 240
        },
        "request_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9._:~-]{1,256}$"
        },
        "request_digest": {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{64}$"
        },
        "idempotency_key": {
          "type": "string",
          "pattern": "^[A-Za-z0-9._:~-]{1,256}$"
        }
      }
    },
    "payee": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "merchant_id",
        "destination",
        "destination_digest"
      ],
      "properties": {
        "merchant_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 240
        },
        "destination": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        },
        "destination_digest": {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{64}$",
          "description": "SHA-256 of the exact UTF-8 destination string; validators must recompute it."
        }
      }
    },
    "amount": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "mode",
            "minor_units",
            "currency"
          ],
          "properties": {
            "mode": {
              "const": "ISO_4217"
            },
            "minor_units": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            },
            "currency": {
              "type": "string",
              "pattern": "^[A-Z]{3}$"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "mode",
            "atomic_units",
            "asset_decimals",
            "asset_id",
            "network"
          ],
          "properties": {
            "mode": {
              "const": "ATOMIC_ASSET"
            },
            "atomic_units": {
              "type": "string",
              "pattern": "^[1-9][0-9]{0,77}$"
            },
            "asset_decimals": {
              "type": "integer",
              "minimum": 0,
              "maximum": 30
            },
            "asset_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 500
            },
            "network": {
              "type": "string",
              "minLength": 1,
              "maxLength": 240
            }
          }
        }
      ]
    },
    "resource": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "method",
        "uri",
        "body_digest"
      ],
      "properties": {
        "method": {
          "type": "string",
          "pattern": "^[A-Z][A-Z0-9!#$%&'*+.^_`|~-]{0,31}$"
        },
        "uri": {
          "type": "string",
          "format": "uri",
          "pattern": "^https://",
          "maxLength": 2048
        },
        "body_digest": {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{64}$"
        }
      }
    }
  }
}
