{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/Sharathvc23/forgetproof/main/schemas/receipt.schema.json",
  "title": "forgetproof erasure receipt",
  "description": "A signed record of what a scan found before and after an erasure: counts and file hashes only, never the erased values. `signature` is an Ed25519 signature over the canonical JSON (keys sorted by code point, no whitespace, non-ASCII raw, UTF-8) of the receipt with the `signature` key removed. The schema checks shape; verifying the signature needs the forgetproof CLI or the forgetproof-verify package.",
  "type": "object",
  "oneOf": [
    { "$ref": "#/$defs/receipt-0.1" },
    { "$ref": "#/$defs/receipt-0.2" }
  ],
  "$defs": {
    "count": {
      "type": "integer",
      "minimum": 0
    },
    "counts": {
      "description": "A map of names to non-negative counts.",
      "type": "object",
      "additionalProperties": { "$ref": "#/$defs/count" }
    },
    "verdict": {
      "type": "string",
      "enum": ["CLEAN", "RESIDUE_REMAINS", "UNVERIFIABLE"]
    },
    "tool": {
      "description": "The implementation and version that issued the receipt, e.g. \"forgetproof 0.1.0\".",
      "type": "string",
      "minLength": 1
    },
    "issued_at": {
      "description": "When the receipt was signed, ISO 8601 / RFC 3339 with a UTC offset.",
      "type": "string",
      "format": "date-time",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})$"
    },
    "target": {
      "description": "What was scanned: a path, or a database URL without its password.",
      "type": "string",
      "minLength": 1
    },
    "actions": {
      "description": "What the fix did, one line each.",
      "type": "array",
      "items": { "type": "string" }
    },
    "canaries": {
      "description": "Per canary, where (if anywhere) it was still found after the fix. The canary value itself is never recorded.",
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "canary": { "type": "integer", "minimum": 1, "description": "1-based position of the canary in the request" },
          "found_in": { "type": "array", "items": { "type": "string" } }
        },
        "required": ["canary", "found_in"],
        "additionalProperties": false
      }
    },
    "correlation_id": {
      "description": "An opaque caller-supplied label, carried through a queued forget too.",
      "type": ["string", "null"]
    },
    "files": {
      "description": "SHA-256 (lowercase hex) of every file in the store after the fix, by path relative to the target. For a database: fingerprints by relation.",
      "type": "object",
      "patternProperties": {
        "^.+$": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
      },
      "additionalProperties": false
    },
    "public_key": {
      "description": "The raw 32-byte Ed25519 public key, base64url without padding. Its fingerprint, shown to people, is the first 32 hex characters of SHA-256 over the raw bytes.",
      "type": "string",
      "pattern": "^[A-Za-z0-9_-]{43}$"
    },
    "signature": {
      "description": "The 64-byte Ed25519 signature, base64url without padding.",
      "type": "string",
      "pattern": "^[A-Za-z0-9_-]{86}$"
    },
    "scan": {
      "description": "A scan summary: counts only.",
      "type": "object",
      "properties": {
        "store": { "type": "string", "description": "The store type that was scanned, e.g. chroma, sqlite, postgres." },
        "clean": { "type": "boolean" },
        "findings": { "$ref": "#/$defs/counts", "description": "Leftover units by check id, e.g. {\"chroma.write_log\": 3}." },
        "pii": { "$ref": "#/$defs/counts", "description": "Distinct values by PII kind, e.g. {\"email\": 2}." },
        "canaries_found": { "$ref": "#/$defs/count" },
        "incomplete": { "type": ["string", "null"], "description": "Why the scan could not check everything; such a store is never clean." },
        "warnings": { "type": "array", "items": { "type": "string" } },
        "stats": { "$ref": "#/$defs/counts" }
      }
    },
    "scan-0.2": {
      "description": "A 0.2 scan summary: every field present, nothing else.",
      "type": "object",
      "$ref": "#/$defs/scan",
      "required": ["store", "clean", "findings", "pii", "canaries_found", "incomplete", "warnings", "stats"],
      "unevaluatedProperties": false
    },
    "copy": {
      "description": "A copy of the store the copies report found, and whether forgetproof could scan it.",
      "type": "object",
      "properties": {
        "kind": { "type": "string", "minLength": 1, "description": "e.g. sibling, backup, snapshot, replica, export" },
        "where": { "type": "string", "minLength": 1 },
        "note": { "type": "string" },
        "scannable": { "type": "boolean" }
      },
      "required": ["kind", "where", "note", "scannable"],
      "additionalProperties": false
    },
    "receipt-0.1": {
      "title": "forgetproof-receipt/0.1",
      "type": "object",
      "properties": {
        "format": { "const": "forgetproof-receipt/0.1" },
        "tool": { "$ref": "#/$defs/tool" },
        "issued_at": { "$ref": "#/$defs/issued_at" },
        "target": { "$ref": "#/$defs/target" },
        "verdict": { "$ref": "#/$defs/verdict" },
        "before": { "$ref": "#/$defs/scan" },
        "after": { "$ref": "#/$defs/scan" },
        "actions": { "$ref": "#/$defs/actions" },
        "canaries": { "$ref": "#/$defs/canaries" },
        "correlation_id": { "$ref": "#/$defs/correlation_id" },
        "files": { "$ref": "#/$defs/files" },
        "public_key": { "$ref": "#/$defs/public_key" },
        "signature": { "$ref": "#/$defs/signature" }
      },
      "required": [
        "format", "tool", "issued_at", "target", "verdict", "before", "after",
        "actions", "canaries", "correlation_id", "files", "public_key", "signature"
      ]
    },
    "receipt-0.2": {
      "title": "forgetproof-receipt/0.2",
      "type": "object",
      "properties": {
        "format": { "const": "forgetproof-receipt/0.2" },
        "tool": { "$ref": "#/$defs/tool" },
        "issuer": { "type": "string", "minLength": 1, "description": "Who signs: a hosted provider's name, or \"this machine\"." },
        "issued_at": { "$ref": "#/$defs/issued_at" },
        "target": { "$ref": "#/$defs/target" },
        "verdict": { "$ref": "#/$defs/verdict" },
        "before": { "$ref": "#/$defs/scan-0.2" },
        "after": { "$ref": "#/$defs/scan-0.2" },
        "actions": { "$ref": "#/$defs/actions" },
        "canaries": { "$ref": "#/$defs/canaries" },
        "subject_values": { "$ref": "#/$defs/count", "description": "How many exact values the subject had. Never the values." },
        "copies": { "type": "array", "items": { "$ref": "#/$defs/copy" } },
        "correlation_id": { "$ref": "#/$defs/correlation_id" },
        "files": { "$ref": "#/$defs/files" },
        "public_key": { "$ref": "#/$defs/public_key" },
        "signature": { "$ref": "#/$defs/signature" }
      },
      "required": [
        "format", "tool", "issuer", "issued_at", "target", "verdict", "before", "after",
        "actions", "canaries", "subject_values", "copies", "correlation_id", "files",
        "public_key", "signature"
      ],
      "additionalProperties": false
    }
  }
}
