{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://attestedintelligence.com/schema/v1",
  "title": "Attested Intelligence Protocol Schema",
  "description": "Schema for attestation artifacts, policy artifacts, and enforcement receipts",
  "type": "object",
  "definitions": {
    "AttestationArtifact": {
      "type": "object",
      "required": [
        "protocol_version",
        "artifact_hash",
        "signature",
        "timestamp"
      ],
      "properties": {
        "protocol_version": {
          "const": "1.0",
          "description": "Protocol version identifier"
        },
        "artifact_hash": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$",
          "description": "BLAKE2b-256 hash of the artifact"
        },
        "signature": {
          "type": "string",
          "description": "Ed25519 signature of the artifact hash"
        },
        "timestamp": {
          "type": "string",
          "format": "date-time",
          "description": "RFC 3339 timestamp of attestation"
        },
        "artifact_type": {
          "enum": [
            "MODEL_WEIGHTS",
            "TRAINING_RUN",
            "INFERENCE_LOG",
            "DATASET",
            "SOFTWARE_ARTIFACT",
            "POLICY_DOCUMENT",
            "AGENT_EXECUTION"
          ],
          "description": "Classification of the attested artifact"
        },
        "metadata": {
          "type": "object",
          "description": "Optional metadata about the artifact",
          "properties": {
            "name": {
              "type": "string"
            },
            "version": {
              "type": "string"
            },
            "issuer": {
              "type": "string"
            }
          }
        }
      }
    },
    "PolicyArtifact": {
      "type": "object",
      "required": [
        "protocol_version",
        "policy_hash",
        "signature",
        "timestamp",
        "policy_content"
      ],
      "properties": {
        "protocol_version": {
          "const": "1.0"
        },
        "policy_hash": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$",
          "description": "BLAKE2b-256 hash of canonical policy content"
        },
        "signature": {
          "type": "string",
          "description": "Ed25519 signature of the policy hash"
        },
        "timestamp": {
          "type": "string",
          "format": "date-time"
        },
        "policy_content": {
          "type": "object",
          "description": "The sealed policy definition",
          "properties": {
            "version": {
              "type": "string"
            },
            "subject": {
              "type": "string"
            },
            "permissions": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "constraints": {
              "type": "object"
            },
            "issuer": {
              "type": "string"
            }
          }
        },
        "sealed": {
          "type": "boolean",
          "const": true
        }
      }
    },
    "EnforcementReceipt": {
      "type": "object",
      "required": [
        "sequence_number",
        "timestamp",
        "action_type",
        "action_hash",
        "policy_ref",
        "prev_hash",
        "signature"
      ],
      "properties": {
        "sequence_number": {
          "type": "integer",
          "minimum": 0
        },
        "timestamp": {
          "type": "string",
          "format": "date-time"
        },
        "action_type": {
          "enum": [
            "ALLOWED",
            "BLOCKED",
            "ATTESTED"
          ],
          "description": "Result of policy enforcement"
        },
        "action_hash": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$",
          "description": "Hash of the action data"
        },
        "policy_ref": {
          "type": "string",
          "description": "Reference to the active policy artifact"
        },
        "prev_hash": {
          "type": [
            "string",
            "null"
          ],
          "description": "Hash of the previous receipt (null for genesis)"
        },
        "signature": {
          "type": "string",
          "description": "Ed25519 signature of the receipt"
        }
      }
    }
  },
  "oneOf": [
    {
      "$ref": "#/definitions/AttestationArtifact"
    },
    {
      "$ref": "#/definitions/PolicyArtifact"
    },
    {
      "$ref": "#/definitions/EnforcementReceipt"
    }
  ]
}