{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://zambo.dev/aer-1/schema.json",
  "title": "AER-1 Live MCP Receipt",
  "description": "Raw MCP result._receipt shape for current AER-1 draft -26; validate the receipt object without normalizing its transport fields.",
  "$comment": "This schema applies directly to result._receipt in the JSON-RPC response from POST /api/mcp. It does not describe the outer JSON-RPC envelope.",
  "type": "object",
  "additionalProperties": true,
  "required": [
    "id",
    "tool",
    "timestamp",
    "provenance_class",
    "verification_status",
    "hash_algorithm",
    "canonical_bytes",
    "canonical_byte_length",
    "output_hash",
    "status"
  ],
  "allOf": [
    {
      "if": {
        "properties": {
          "receipt_schema_version": {
            "pattern": "^(?:0\\.(?:[4-9]|[1-9][0-9]+)|[1-9][0-9]*\\.[0-9]+)$"
          }
        },
        "required": [
          "receipt_schema_version"
        ]
      },
      "then": {
        "required": [
          "metadata_hash"
        ]
      }
    }
  ],
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "tool": {
      "type": "string",
      "minLength": 1
    },
    "timestamp": {
      "type": "string",
      "format": "date-time"
    },
    "receipt_schema_version": {
      "type": "string",
      "pattern": "^(?:0\\.(?:2|3|[4-9]|[1-9][0-9]+)|[1-9][0-9]*\\.[0-9]+)$",
      "description": "Schema 0.4 and later require metadata_hash. Version 0.2 and 0.3 receipts remain verifiable with a legacy notice."
    },
    "execution_context": {
      "type": "object",
      "description": "Optional descriptive context. It is outside canonical_bytes and does not affect verification.",
      "properties": {
        "model": {
          "type": "object",
          "required": [
            "name",
            "version"
          ],
          "properties": {
            "name": {
              "type": "string"
            },
            "version": {
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        "source": {
          "type": "string",
          "minLength": 1
        },
        "framework": {
          "type": "object",
          "required": [
            "name",
            "version"
          ],
          "properties": {
            "name": {
              "type": "string"
            },
            "version": {
              "type": "string"
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "tool_context": {
      "type": "object",
      "required": [
        "name",
        "version",
        "scope"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "version": {
          "type": "string",
          "minLength": 1
        },
        "scope": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": true
    },
    "provenance_class": {
      "type": "string",
      "enum": [
        "EXECUTED BY ZAMBO",
        "OBSERVED VIA GATEWAY",
        "LOGGED BY AGENT"
      ]
    },
    "metadata_hash": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$",
      "description": "SHA-256 of the canonical metadata block defined in AER-1 draft -26."
    },
    "canonical_bytes": {
      "type": "string",
      "contentEncoding": "base64",
      "description": "Exact UTF-8 output bytes hashed by output_hash. metadata_hash separately commits the receipt identity, timestamp, tool, schema version, output hash, and provenance claim. Neither hash authenticates the issuer."
    },
    "output_hash": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "canonical_byte_length": {
      "type": "integer",
      "minimum": 0
    },
    "hash_algorithm": {
      "type": "string",
      "const": "sha256"
    },
    "verification_status": {
      "type": "string",
      "minLength": 1,
      "description": "Verifier-computed status, not a committed claim; recompute it independently and never trust the transported value as evidence."
    },
    "status": {
      "type": "string",
      "minLength": 1
    },
    "anchor": {
      "type": [
        "object",
        "null"
      ]
    }
  }
}
