{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://pactverity.com/specs/pactverity-assurance-receipt-v1.schema.json",
  "title": "PactVerity Assurance Receipt v1",
  "description": "Public schema for receipts produced by PactVerity Proof Engine 1.0.0.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "engineVersion", "issuedAt", "agreement", "evidence", "checks", "outcome", "payloadHash"],
  "properties": {
    "schema": { "const": "pactverity.assurance-receipt.v1" },
    "engineVersion": { "const": "1.0.0" },
    "issuedAt": { "type": "string", "format": "date-time", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}Z$" },
    "agreement": {
      "type": "object",
      "additionalProperties": false,
      "required": ["agreementId", "serviceName", "providerReference", "buyerReference", "criteria"],
      "properties": {
        "agreementId": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$" },
        "serviceName": { "type": "string", "minLength": 1, "maxLength": 120 },
        "providerReference": { "type": "string", "minLength": 1, "maxLength": 120 },
        "buyerReference": { "type": "string", "maxLength": 120 },
        "criteria": {
          "type": "object",
          "additionalProperties": false,
          "required": ["maxLatencyMs", "minUptimeBps", "maxFreshnessSeconds", "expectedOutputSha256"],
          "properties": {
            "maxLatencyMs": { "type": "integer", "minimum": 1, "maximum": 10000000 },
            "minUptimeBps": { "type": "integer", "minimum": 0, "maximum": 10000 },
            "maxFreshnessSeconds": { "type": "integer", "minimum": 0, "maximum": 31536000 },
            "expectedOutputSha256": { "type": "string", "pattern": "^$|^[0-9a-f]{64}$" }
          }
        }
      }
    },
    "evidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["measuredLatencyMs", "uptimeBps", "freshnessSeconds", "observedOutputSha256", "observedAt"],
      "properties": {
        "measuredLatencyMs": { "type": "integer", "minimum": 0, "maximum": 10000000 },
        "uptimeBps": { "type": "integer", "minimum": 0, "maximum": 10000 },
        "freshnessSeconds": { "type": "integer", "minimum": 0, "maximum": 31536000 },
        "observedOutputSha256": { "type": "string", "pattern": "^$|^[0-9a-f]{64}$" },
        "observedAt": { "type": "string", "format": "date-time", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}Z$" }
      }
    },
    "checks": {
      "type": "array",
      "minItems": 4,
      "maxItems": 4,
      "prefixItems": [
        { "$ref": "#/$defs/latencyCheck" },
        { "$ref": "#/$defs/uptimeCheck" },
        { "$ref": "#/$defs/freshnessCheck" },
        { "$ref": "#/$defs/outputHashCheck" }
      ],
      "items": false
    },
    "outcome": { "enum": ["pass", "fail"] },
    "payloadHash": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
    "walletSignature": {
      "type": "object",
      "additionalProperties": false,
      "required": ["algorithm", "chain", "address", "message", "signatureBase64"],
      "properties": {
        "algorithm": { "const": "Ed25519" },
        "chain": { "const": "solana" },
        "address": { "type": "string", "minLength": 32, "maxLength": 44, "pattern": "^[1-9A-HJ-NP-Za-km-z]+$" },
        "message": { "type": "string", "pattern": "^PACTVERITY-RECEIPT-V1\\n[0-9a-f]{64}$" },
        "signatureBase64": { "type": "string", "pattern": "^[A-Za-z0-9+/]{86}==$" }
      }
    }
  },
  "$defs": {
    "latencyCheck": {
      "type": "object", "additionalProperties": false,
      "required": ["key", "status", "operator", "expected", "actual"],
      "properties": {
        "key": { "const": "latency" }, "status": { "enum": ["pass", "fail"] }, "operator": { "const": "lte" },
        "expected": { "type": "integer", "minimum": 1, "maximum": 10000000 }, "actual": { "type": "integer", "minimum": 0, "maximum": 10000000 }
      }
    },
    "uptimeCheck": {
      "type": "object", "additionalProperties": false,
      "required": ["key", "status", "operator", "expected", "actual"],
      "properties": {
        "key": { "const": "uptime" }, "status": { "enum": ["pass", "fail"] }, "operator": { "const": "gte" },
        "expected": { "type": "integer", "minimum": 0, "maximum": 10000 }, "actual": { "type": "integer", "minimum": 0, "maximum": 10000 }
      }
    },
    "freshnessCheck": {
      "type": "object", "additionalProperties": false,
      "required": ["key", "status", "operator", "expected", "actual"],
      "properties": {
        "key": { "const": "freshness" }, "status": { "enum": ["pass", "fail"] }, "operator": { "const": "lte" },
        "expected": { "type": "integer", "minimum": 0, "maximum": 31536000 }, "actual": { "type": "integer", "minimum": 0, "maximum": 31536000 }
      }
    },
    "outputHashCheck": {
      "type": "object", "additionalProperties": false,
      "required": ["key", "status", "operator", "expected", "actual"],
      "properties": {
        "key": { "const": "output_hash" }, "status": { "enum": ["pass", "fail", "not_evaluated"] }, "operator": { "const": "eq" },
        "expected": { "anyOf": [{ "type": "string", "pattern": "^[0-9a-f]{64}$" }, { "type": "null" }] },
        "actual": { "anyOf": [{ "type": "string", "pattern": "^[0-9a-f]{64}$" }, { "type": "null" }] }
      }
    }
  }
}
