{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://syngraphe.org/schemas/internal/receipt-profile-v1/receipt",
  "title": "Syngraphe AI Interaction Receipt profile v1 receipt structural schema",
  "$comment": "Structural envelope only. Runtime parsing and verification are mandatory; cross-field, temporal, ordering, uniqueness, serialized-size, and statistical invariants are runtime-only.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "endpoint",
    "model_id",
    "receipt_id",
    "request_digest",
    "response_digest",
    "retention_class",
    "timestamp",
    "trust_statement"
  ],
  "properties": {
    "endpoint": {
      "type": "string",
      "maxLength": 2048,
      "pattern": "^https://[^?#]+$"
    },
    "model_id": { "$ref": "#/$defs/identifier" },
    "receipt_id": { "$ref": "#/$defs/identifier" },
    "request_digest": { "$ref": "#/$defs/digest" },
    "response_digest": { "$ref": "#/$defs/digest" },
    "retention_class": {
      "enum": [
        "anthropic-covered-model-30d",
        "anthropic-feature-specific",
        "anthropic-zero-data-retention",
        "google-approved-zero-data-retention",
        "google-feature-specific",
        "google-paid-service-limited-abuse-monitoring",
        "openai-abuse-monitoring-30d",
        "openai-application-state-30d",
        "openai-modified-abuse-monitoring",
        "openai-zero-data-retention",
        "undeclared"
      ]
    },
    "timestamp": { "$ref": "#/$defs/timestamp" },
    "trust_statement": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "notaries",
        "notary_trust_model",
        "quorum",
        "terminating_party",
        "witness_mode"
      ],
      "properties": {
        "notaries": {
          "type": "array",
          "maxItems": 16,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["id", "jurisdiction", "key_ref", "operator"],
            "properties": {
              "id": { "$ref": "#/$defs/identifier" },
              "jurisdiction": {
                "type": "string",
                "pattern": "^[A-Z]{2}(?:-[A-Z0-9]{1,3})?$"
              },
              "key_ref": { "$ref": "#/$defs/identifier" },
              "operator": { "$ref": "#/$defs/identifier" }
            }
          }
        },
        "notary_trust_model": {
          "enum": ["counterparty", "none", "tee", "threshold"]
        },
        "quorum": {
          "type": "object",
          "additionalProperties": false,
          "required": ["k", "n"],
          "properties": {
            "k": { "$ref": "#/$defs/count" },
            "n": { "$ref": "#/$defs/count" }
          }
        },
        "terminating_party": {
          "enum": ["cloudflare", "google-fe", "provider"]
        },
        "witness_mode": {
          "enum": ["mpc-tls", "provider-signature", "proxy-tls", "tee-quote"]
        }
      }
    }
  },
  "$defs": {
    "count": {
      "type": "integer",
      "minimum": 0,
      "maximum": 65535
    },
    "digest": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    },
    "identifier": {
      "type": "string",
      "minLength": 1,
      "maxLength": 256,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:/-]*$"
    },
    "timestamp": {
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
    }
  }
}
