{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://zambo.dev/aer-1/hosted-profile.schema.json",
  "title": "Zambo Hosted Receipt Profile v1",
  "description": "The public JSON object returned as receipt by GET /api/receipt/{id} and GET /api/v2/receipt/{id}/verify. Version 0.4+ metadata_hash binds the receipt identity, time, tool, version, output hash, and provenance claim; it does not authenticate the issuer.",
  "type": "object",
  "additionalProperties": true,
  "required": [
    "id",
    "created_at",
    "receipt_schema_version",
    "output_hash",
    "hash_algorithm",
    "canonical_bytes",
    "canonical_byte_length",
    "verification_status",
    "provenance_class",
    "anchor",
    "checks"
  ],
  "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",
          "tool"
        ],
        "properties": {
          "checks": {
            "required": [
              "metadata_binding"
            ]
          }
        }
      }
    }
  ],
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "created_at": {
      "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]+)$"
    },
    "job_summary": {
      "type": "string"
    },
    "output_hash": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "hash_algorithm": {
      "type": "string",
      "const": "sha256"
    },
    "canonical_bytes": {
      "type": [
        "string",
        "null"
      ],
      "contentEncoding": "base64"
    },
    "canonical_byte_length": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 0
    },
    "verification_status": {
      "type": "string",
      "minLength": 1
    },
    "provenance_class": {
      "type": "string",
      "minLength": 1
    },
    "metadata_hash": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "input_hash": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$",
      "description": "Optional SHA-256 of the final MCP tool-argument object supplied to receipt construction, including _session_id when present. The gateway removes reserved caller/access metadata before hashing. This is outside canonical_bytes and metadata_hash. Exact rules and a worked example: https://zambo.dev/aer-1/input-hash-layout.md."
    },
    "input_hash_layout": {
      "type": "string",
      "const": "zambo-json-sorted-keys-utf8-v1",
      "description": "Recursively sort object keys in JavaScript default string-sort order, preserve array order, serialize as compact JSON without ASCII-escaping ordinary Unicode, encode as UTF-8, and hash with SHA-256. Output is sha256: plus 64 lowercase hex characters. Exact included-field rules and a worked example: https://zambo.dev/aer-1/input-hash-layout.md."
    },
    "execution_context": {
      "type": "object",
      "description": "Optional descriptive context, outside canonical_bytes and metadata_hash.",
      "properties": {
        "model": {
          "type": "object",
          "required": [
            "name",
            "version"
          ],
          "properties": {
            "name": {
              "type": "string"
            },
            "version": {
              "type": "string"
            },
            "digest": {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            }
          },
          "additionalProperties": false
        },
        "source": {
          "type": "string",
          "minLength": 1
        },
        "framework": {
          "type": "object",
          "required": [
            "name",
            "version"
          ],
          "properties": {
            "name": {
              "type": "string"
            },
            "version": {
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        "environment": {
          "oneOf": [
            {
              "type": "string",
              "minLength": 1
            },
            {
              "type": "object",
              "required": [
                "name"
              ],
              "properties": {
                "name": {
                  "type": "string",
                  "minLength": 1
                },
                "digest": {
                  "type": "string",
                  "pattern": "^sha256:[0-9a-f]{64}$"
                }
              },
              "additionalProperties": false
            }
          ]
        },
        "payment": {
          "type": "object",
          "required": [
            "method",
            "reference"
          ],
          "properties": {
            "method": {
              "type": "string",
              "minLength": 1
            },
            "reference": {
              "type": "string",
              "minLength": 1
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "tool": {
      "type": "object",
      "required": [
        "name",
        "scope",
        "version"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "scope": {
          "type": "string",
          "minLength": 1
        },
        "version": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "anchor": {
      "type": [
        "object",
        "null"
      ]
    },
    "checks": {
      "type": "object",
      "required": [
        "commitment_matches",
        "provenance_binding"
      ],
      "properties": {
        "commitment_matches": {
          "type": "object",
          "required": [
            "status",
            "passed"
          ],
          "properties": {
            "status": {
              "type": "string",
              "enum": [
                "pass",
                "fail",
                "not_checked"
              ]
            },
            "passed": {
              "type": "boolean"
            }
          }
        },
        "provenance_binding": {
          "type": "object",
          "required": [
            "status",
            "passed",
            "detail"
          ],
          "properties": {
            "status": {
              "type": "string",
              "enum": [
                "pass",
                "fail",
                "legacy",
                "not_checked"
              ]
            },
            "passed": {
              "type": "boolean"
            },
            "detail": {
              "type": "string"
            }
          }
        },
        "metadata_binding": {
          "type": "object",
          "required": [
            "status",
            "passed",
            "detail"
          ],
          "properties": {
            "status": {
              "type": "string",
              "enum": [
                "pass",
                "fail",
                "legacy",
                "not_checked"
              ]
            },
            "passed": {
              "type": "boolean"
            },
            "detail": {
              "type": "string"
            }
          }
        },
        "signature_valid": {
          "type": "object",
          "properties": {
            "passed": {
              "type": "boolean",
              "const": false
            },
            "status": {
              "type": "string",
              "const": "not_checked"
            }
          }
        },
        "chain_valid": {
          "type": "object",
          "properties": {
            "passed": {
              "type": "boolean",
              "const": false
            },
            "status": {
              "type": "string",
              "const": "not_checked"
            }
          }
        }
      }
    }
  }
}
