{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/Sharathvc23/forgetproof/main/schemas/forget-me/v1/receipt.schema.json",
  "title": "forget-me-receipt/1: the portable receipt",
  "description": "A signed projection of what one holder did for one operation. It carries no host path, no filename, no raw value, no cross-service identifier, no token and no value hash: counts, timestamps, vocabulary words and plain sentences only, coupled to the operation by the issuer's opaque owner-bound operation id. `signature` is Ed25519 over the canonical JSON (keys sorted by code point, no whitespace, non-ASCII raw, UTF-8) of the receipt without `signature`, the same rule as forgetproof-receipt/0.2. Every field is present; nothing else is allowed.",
  "type": "object",
  "properties": {
    "format": { "const": "forget-me-receipt/1" },
    "namespace": { "$ref": "common.schema.json#/$defs/namespace" },
    "version": { "$ref": "common.schema.json#/$defs/version" },
    "issuer": { "type": "string", "minLength": 1, "maxLength": 200 },
    "issued_at": { "$ref": "common.schema.json#/$defs/date-time" },
    "operation": { "$ref": "common.schema.json#/$defs/operation-id" },
    "holder": { "$ref": "common.schema.json#/$defs/holder-name" },
    "kind": { "type": "string", "minLength": 1, "maxLength": 64 },
    "scope": { "$ref": "common.schema.json#/$defs/scope" },
    "outcome": { "$ref": "common.schema.json#/$defs/outcome" },
    "verdict": {
      "description": "The word 0.2 receipts used, derived from the outcome: inspected-and-clear is CLEAN; intentionally-retained and bytes-still-found are RESIDUE_REMAINS; queued, unsupported and error are UNVERIFIABLE.",
      "type": "string",
      "enum": ["CLEAN", "RESIDUE_REMAINS", "UNVERIFIABLE"]
    },
    "coverage": {
      "description": "What the inspection covered. `checks` are check ids (for example sqlite.free_pages, exact-text), `scope` says whose records the statement is about, `limits` are plain sentences about what could not be covered (for example derived items written before provenance tracking).",
      "type": "object",
      "properties": {
        "inspected": { "type": "boolean" },
        "checks": { "type": "array", "maxItems": 64, "items": { "type": "string", "pattern": "^[a-z0-9][a-z0-9._-]{0,63}$" } },
        "scope": { "type": "string", "minLength": 1, "maxLength": 200 },
        "limits": { "type": "array", "maxItems": 16, "items": { "type": "string", "minLength": 1, "maxLength": 400 } }
      },
      "required": ["inspected", "checks", "scope", "limits"],
      "additionalProperties": false
    },
    "before": { "$ref": "#/$defs/counts" },
    "after": { "$ref": "#/$defs/counts" },
    "actions": {
      "description": "What was done, from a fixed vocabulary of sentences that name no file, path or value.",
      "type": "array",
      "maxItems": 16,
      "items": {
        "type": "string",
        "enum": [
          "record deleted through the holder's own API, by id",
          "derived items removed",
          "derived items rebuilt without the withdrawn record",
          "active retrieval of the record stopped",
          "residue the deletion left behind erased",
          "every byte of the holder scanned for the exact text afterwards",
          "exact text searched for in the holder",
          "scanned again after a restart; nothing erased again",
          "deletion requested through the holder's API and acknowledged",
          "record kept, as the person chose",
          "record kept under a retention the preview disclosed",
          "restore attempted through the holder's own path and refused",
          "nothing done: the holder was not reachable",
          "nothing done: the request lost its authority before this step ran",
          "nothing done: the holder could not be inspected from here"
        ]
      }
    },
    "subject_values": { "description": "How many exact values the subject had. Never the values.", "type": "integer", "minimum": 0 },
    "retrieval_stopped_at": { "description": "When the holder stopped returning the record, if it could before the physical cleanup.", "$ref": "common.schema.json#/$defs/nullable-date-time" },
    "physical_cleanup_at": { "description": "When the bytes were rewritten (separate from stopping retrieval).", "$ref": "common.schema.json#/$defs/nullable-date-time" },
    "restore": {
      "description": "Either one restore attempt through the holder's own path, and whether it was prevented, or that restore coverage is unsupported for this holder.",
      "oneOf": [
        {
          "type": "object",
          "properties": { "attempted": { "const": true }, "prevented": { "type": "boolean" } },
          "required": ["attempted", "prevented"],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": { "coverage": { "const": "unsupported" } },
          "required": ["coverage"],
          "additionalProperties": false
        }
      ]
    },
    "retained_until": { "description": "For intentionally-retained under a disclosed retention: when the holder erases it. Null otherwise.", "$ref": "common.schema.json#/$defs/nullable-date-time" },
    "source_receipt": {
      "description": "The host's own full receipt behind this projection, by format and SHA-256 of its canonical JSON, so the host can match them later without publishing its paths. Null when there is none.",
      "oneOf": [
        { "type": "null" },
        {
          "type": "object",
          "properties": {
            "format": { "type": "string", "minLength": 1, "maxLength": 64 },
            "digest": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
          },
          "required": ["format", "digest"],
          "additionalProperties": false
        }
      ]
    },
    "public_key": { "$ref": "common.schema.json#/$defs/public-key" },
    "signature": { "$ref": "common.schema.json#/$defs/signature" }
  },
  "required": [
    "format", "namespace", "version", "issuer", "issued_at", "operation", "holder", "kind", "scope", "outcome", "verdict",
    "coverage", "before", "after", "actions", "subject_values", "retrieval_stopped_at", "physical_cleanup_at", "restore",
    "retained_until", "source_receipt", "public_key", "signature"
  ],
  "additionalProperties": false,
  "allOf": [
    { "if": { "properties": { "outcome": { "const": "inspected-and-clear" } } }, "then": { "properties": { "verdict": { "const": "CLEAN" } } } },
    { "if": { "properties": { "outcome": { "enum": ["intentionally-retained", "bytes-still-found"] } } }, "then": { "properties": { "verdict": { "const": "RESIDUE_REMAINS" } } } },
    { "if": { "properties": { "outcome": { "enum": ["queued", "unsupported", "error"] } } }, "then": { "properties": { "verdict": { "const": "UNVERIFIABLE" } } } }
  ],
  "$defs": {
    "counts": {
      "description": "Counts only: how many residue findings the inspection saw, and whether the exact text was in any live record of the person's (other accounts' live records are outside the statement).",
      "type": "object",
      "properties": {
        "residue": { "type": "integer", "minimum": 0 },
        "exact_text_in_your_records": { "type": "boolean" }
      },
      "required": ["residue", "exact_text_in_your_records"],
      "additionalProperties": false
    }
  }
}
