{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://verify.cloakapps.com/schemas/receipt-v1.json",
  "title": "Cloakapps Receipt v1 — Payload Schema",
  "description": "Schema for the inner payload of a cloakapps receipt JWS. The outer envelope follows JWS JSON Serialization (RFC 7515).",
  "type": "object",
  "required": ["_type", "id", "issuer", "operation", "actor", "resource", "timestamp", "result"],
  "additionalProperties": true,
  "properties": {
    "_type": {
      "type": "string",
      "const": "https://cloakapps.com/receipt/v1"
    },
    "id": {
      "type": "string",
      "pattern": "^rcpt_[0-9A-HJKMNP-TV-Z]{26}$",
      "description": "ULID with the rcpt_ prefix"
    },
    "issuer": {
      "type": "string",
      "format": "uri"
    },
    "operation": {
      "type": "string"
    },
    "actor": {
      "type": "object",
      "required": ["type", "id"],
      "properties": {
        "type":              { "type": "string", "enum": ["user", "agent"] },
        "id":                { "type": "string" },
        "agentCredentialId": { "type": "string" },
        "host":              { "type": "string" }
      }
    },
    "resource": {
      "type": "object",
      "required": ["type", "id", "fingerprint"],
      "properties": {
        "type":        { "type": "string" },
        "id":          { "type": "string" },
        "fingerprint": {
          "type": "object",
          "minProperties": 1,
          "additionalProperties": { "type": "string" }
        }
      }
    },
    "policy": {
      "type": "object"
    },
    "keyRef": {
      "type": "object",
      "properties": {
        "alias":   { "type": "string" },
        "keyId":   { "type": "string" },
        "keyType": { "type": "string" }
      }
    },
    "timestamp": {
      "type": "string",
      "format": "date-time"
    },
    "result": {
      "type": "string",
      "enum": ["success", "failure"]
    },
    "extensions": {
      "type": "object"
    },
    "linkedReceiptIds": {
      "type": "array",
      "items": { "type": "string" }
    }
  }
}
