{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/sigr-cachesign-v1.json",
  "title": "SiGR CacheSign v1, KV cache prefix signing receipt",
  "description": "Canonical schema for the Hive SiGR CacheSign receipt, canonical type sigr.cachesign. Signs a vLLM style KV cache prefix entry at write time: the model, the prefix digest, the token span it covers, and an optional parent cache receipt reference, into one Ed25519 signature over a recomputable payload_sha256. The receipt attests that this exact prefix_sha256 and token_span were sealed at write time for the named model, and, when parent_ref is present, that this entry extends a specific prior sealed entry. It does not attest that the cached content is correct or that it was actually reused by any later inference.",
  "type": "object",
  "required": [
    "receipt_id",
    "payload_sha256",
    "sig_b64u",
    "key_id",
    "algorithm",
    "ts",
    "signed_body"
  ],
  "additionalProperties": false,
  "properties": {
    "receipt_id": {
      "type": "string",
      "pattern": "^r_sigr\\.cachesign_[0-9]{10,}_[0-9a-f]{12}$"
    },
    "payload_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
    "sig_b64u": { "type": "string", "pattern": "^[A-Za-z0-9_-]{86}$" },
    "key_id": { "type": "string", "pattern": "^did:(hive|web|key):[A-Za-z0-9._:%-]+$" },
    "algorithm": { "type": "string", "const": "Ed25519" },
    "ts": { "type": "integer", "minimum": 1000000000 },
    "signed_body": {
      "type": "object",
      "required": [
        "receipt_type",
        "schema",
        "cache_id",
        "tenant_id",
        "model_id",
        "prefix_sha256",
        "token_span",
        "sealed_at",
        "boundary"
      ],
      "additionalProperties": false,
      "properties": {
        "receipt_type": { "type": "string", "const": "sigr.cachesign" },
        "schema": { "type": "string", "const": "r1.0.0" },
        "cache_id": { "type": "string", "minLength": 1, "maxLength": 256 },
        "tenant_id": { "type": "string", "minLength": 1, "maxLength": 256 },
        "model_id": { "type": "string", "minLength": 1, "maxLength": 256 },
        "prefix_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Digest of the KV cache prefix content. The signer never receives or stores the raw cache tensors, only this digest."
        },
        "token_span": {
          "type": "object",
          "required": ["start", "end"],
          "additionalProperties": false,
          "properties": {
            "start": { "type": "integer", "minimum": 0, "maximum": 100000000 },
            "end": { "type": "integer", "minimum": 0, "maximum": 100000000 }
          }
        },
        "parent_ref": {
          "type": "object",
          "description": "Optional. Present when this prefix extends a previously sealed cache entry.",
          "required": ["receipt_id", "payload_sha256"],
          "additionalProperties": false,
          "properties": {
            "receipt_id": { "type": "string", "minLength": 1, "maxLength": 300 },
            "payload_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
          }
        },
        "sealed_at": {
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,9})?Z$"
        },
        "boundary": {
          "type": "string",
          "const": "This receipt attests that prefix_sha256 and token_span were sealed at sealed_at for the named model_id, and, when parent_ref is present, that this entry extends the exact prior sealed entry it names. It does not attest that the cached content is correct, was computed deterministically, or was actually reused by any later inference."
        }
      }
    }
  }
}
