{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.infrafabric.io/if.blackboard/proof-packet.v1.schema.json",
  "title": "Blackboard Proof Packet v1",
  "description": "Deterministic export artifact for Blackboard. A packet is an access-logged, redacted, claim-bounded interpretation of append-only event truth plus evidence references.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "packet_id",
    "tenant_id",
    "workspace_id",
    "project_id",
    "task_ids",
    "session_ids",
    "event_range",
    "hash_chain_root",
    "evidence_refs",
    "claim_boundary",
    "redaction_manifest",
    "access_log_ids",
    "non_claims",
    "integrity",
    "assembled_at",
    "packet_status"
  ],
  "properties": {
    "schema_version": {
      "const": "if.blackboard.proof_packet.v1"
    },
    "packet_id": {
      "$ref": "#/$defs/id"
    },
    "tenant_id": {
      "$ref": "#/$defs/id"
    },
    "workspace_id": {
      "$ref": "#/$defs/id"
    },
    "project_id": {
      "$ref": "#/$defs/id"
    },
    "task_ids": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "$ref": "#/$defs/id"
      }
    },
    "session_ids": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "$ref": "#/$defs/id"
      }
    },
    "event_range": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "first_event_id",
        "last_event_id",
        "event_count"
      ],
      "properties": {
        "first_event_id": {
          "$ref": "#/$defs/id"
        },
        "last_event_id": {
          "$ref": "#/$defs/id"
        },
        "event_count": {
          "type": "integer",
          "minimum": 1
        }
      }
    },
    "hash_chain_root": {
      "$ref": "#/$defs/sha256_uri"
    },
    "evidence_refs": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/evidence_ref"
      }
    },
    "claim_boundary": {
      "$ref": "#/$defs/claim_boundary"
    },
    "redaction_manifest": {
      "$ref": "#/$defs/redaction_manifest"
    },
    "access_log_ids": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/id"
      }
    },
    "non_claims": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 500
      }
    },
    "receipt_id": {
      "$ref": "#/$defs/id"
    },
    "integrity": {
      "$ref": "#/$defs/packet_integrity"
    },
    "assembled_at": {
      "type": "string",
      "format": "date-time"
    },
    "packet_status": {
      "type": "string",
      "enum": [
        "draft",
        "final",
        "exported",
        "revoked"
      ]
    }
  },
  "$defs": {
    "id": {
      "type": "string",
      "minLength": 2,
      "maxLength": 128,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9_.:-]*$"
    },
    "sha256_hex": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "sha256_uri": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    },
    "claim_confidence": {
      "type": "string",
      "enum": [
        "verified",
        "claimed",
        "inferred",
        "stale",
        "missing",
        "blocked",
        "not_claimed"
      ]
    },
    "redaction_state": {
      "type": "string",
      "enum": [
        "none",
        "partial",
        "removed"
      ]
    },
    "content_trust": {
      "type": "string",
      "description": "Whether raw evidence text can be reused as instructions. External and customer-supplied evidence is untrusted data until a sanitizer or reviewer creates a trusted projection.",
      "enum": [
        "untrusted_external",
        "customer_asserted",
        "sanitized_projection",
        "trusted_internal"
      ]
    },
    "evidence_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "artifact_id",
        "uri",
        "evidence_type",
        "confidence",
        "redaction",
        "content_trust",
        "captured_at"
      ],
      "properties": {
        "artifact_id": {
          "$ref": "#/$defs/id"
        },
        "uri": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        },
        "evidence_type": {
          "type": "string",
          "enum": [
            "artifact",
            "log",
            "commit",
            "ticket",
            "document",
            "provider_log",
            "receipt",
            "external_ref"
          ]
        },
        "sha256": {
          "$ref": "#/$defs/sha256_hex"
        },
        "etag": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256
        },
        "confidence": {
          "$ref": "#/$defs/claim_confidence"
        },
        "redaction": {
          "$ref": "#/$defs/redaction_state"
        },
        "content_trust": {
          "$ref": "#/$defs/content_trust"
        },
        "captured_at": {
          "type": "string",
          "format": "date-time"
        },
        "source": {
          "type": "string",
          "maxLength": 256
        }
      },
      "anyOf": [
        {
          "required": [
            "sha256"
          ]
        },
        {
          "required": [
            "etag"
          ]
        }
      ]
    },
    "claim_boundary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "decision_id",
        "engine_version",
        "evaluated_at",
        "summary",
        "blocked_claims"
      ],
      "properties": {
        "decision_id": {
          "$ref": "#/$defs/id"
        },
        "engine_version": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64
        },
        "evaluated_at": {
          "type": "string",
          "format": "date-time"
        },
        "summary": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "verified",
            "claimed",
            "inferred",
            "stale",
            "missing",
            "blocked",
            "not_claimed"
          ],
          "properties": {
            "verified": {
              "type": "integer",
              "minimum": 0
            },
            "claimed": {
              "type": "integer",
              "minimum": 0
            },
            "inferred": {
              "type": "integer",
              "minimum": 0
            },
            "stale": {
              "type": "integer",
              "minimum": 0
            },
            "missing": {
              "type": "integer",
              "minimum": 0
            },
            "blocked": {
              "type": "integer",
              "minimum": 0
            },
            "not_claimed": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "blocked_claims": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "claim",
              "reason"
            ],
            "properties": {
              "claim": {
                "type": "string",
                "minLength": 1,
                "maxLength": 300
              },
              "reason": {
                "type": "string",
                "minLength": 1,
                "maxLength": 500
              }
            }
          }
        }
      }
    },
    "redaction_manifest": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "manifest_id",
        "policy_id",
        "manifest_sha256",
        "applied_at",
        "summary"
      ],
      "properties": {
        "manifest_id": {
          "$ref": "#/$defs/id"
        },
        "policy_id": {
          "$ref": "#/$defs/id"
        },
        "manifest_sha256": {
          "$ref": "#/$defs/sha256_uri"
        },
        "applied_at": {
          "type": "string",
          "format": "date-time"
        },
        "summary": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "none",
            "partial",
            "removed"
          ],
          "properties": {
            "none": {
              "type": "integer",
              "minimum": 0
            },
            "partial": {
              "type": "integer",
              "minimum": 0
            },
            "removed": {
              "type": "integer",
              "minimum": 0
            }
          }
        }
      }
    },
    "packet_integrity": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "packet_sha256",
        "canonicalization",
        "key_id",
        "integrity_class"
      ],
      "properties": {
        "packet_sha256": {
          "$ref": "#/$defs/sha256_uri"
        },
        "manifest_sha256": {
          "$ref": "#/$defs/sha256_uri"
        },
        "canonicalization": {
          "type": "string",
          "enum": [
            "json-c14n-v1"
          ]
        },
        "key_id": {
          "$ref": "#/$defs/id"
        },
        "integrity_class": {
          "type": "string",
          "enum": [
            "hash_bound",
            "signed",
            "signed_and_receipted"
          ]
        },
        "signature": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "alg",
            "value"
          ],
          "properties": {
            "alg": {
              "type": "string",
              "enum": [
                "ed25519",
                "ecdsa-p256-sha256",
                "hmac-sha256"
              ]
            },
            "value": {
              "type": "string",
              "minLength": 16,
              "maxLength": 4096
            }
          }
        },
        "receipt_id": {
          "$ref": "#/$defs/id"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "integrity_class": {
                "const": "signed"
              }
            }
          },
          "then": {
            "required": [
              "signature"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "integrity_class": {
                "const": "signed_and_receipted"
              }
            }
          },
          "then": {
            "required": [
              "signature",
              "receipt_id"
            ]
          }
        }
      ]
    }
  }
}
