{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://getzero.dev/contracts/zero.proof_surface.v1.schema.json",
  "title": "Proof surface packet",
  "description": "The typed reading of the /proof URL: the same signed journal-root state the HTML page renders, served to an explicit Accept: application/json preference. Absence is rendered as absence — an unreachable feed is state \"unavailable\", never a fabricated green state. Field semantics mirror app/src/lib/proof-surface.ts and are kept in lockstep by unit test.",
  "type": "object",
  "required": ["schema", "url", "door", "state", "fetchedAt", "commands"],
  "properties": {
    "schema": {
      "type": "string",
      "pattern": "/contracts/zero\\.proof_surface\\.v1\\.schema\\.json$",
      "description": "Absolute URL of this schema on the serving origin."
    },
    "url": {
      "type": "string",
      "pattern": "/proof$",
      "description": "The negotiated URL this packet is the object reading of."
    },
    "door": {
      "type": "string",
      "pattern": "/\\.well-known/(deed|zero)\\.json$",
      "description": "The discovery manifest — every negotiated object carries the door. Points at the manifest that resolves at the current stage."
    },
    "state": {
      "enum": ["unavailable", "empty", "ready"],
      "description": "unavailable — the evidence feed did not answer; empty — the feed answered with no signed roots; ready — a latest root is present."
    },
    "fetchedAt": {
      "type": "string",
      "format": "date-time",
      "description": "When this packet's evidence was read."
    },
    "commands": {
      "type": "object",
      "required": ["index", "root", "anchor"],
      "additionalProperties": false,
      "properties": {
        "index": { "type": "string", "description": "Re-perform the root-index check yourself." },
        "root": { "type": "string", "description": "Fetch the hash-linked root artifact." },
        "anchor": { "type": "string", "description": "Fetch the public timestamp receipt for the same hash." }
      }
    },
    "ledger": {
      "type": "object",
      "required": [
        "totalRoots",
        "calendarAttestedRoots",
        "publicChainConfirmedRoots",
        "pendingPublicChainRoots",
        "asOf"
      ],
      "additionalProperties": false,
      "properties": {
        "totalRoots": { "type": "number" },
        "calendarAttestedRoots": { "type": "number" },
        "publicChainConfirmedRoots": { "type": "number" },
        "pendingPublicChainRoots": { "type": "number" },
        "asOf": { "type": ["string", "null"] }
      }
    },
    "latestRoot": {
      "type": "object",
      "required": [
        "rootHash",
        "rootSlug",
        "rootDate",
        "entryCount",
        "anchor",
        "signature",
        "rootArtifactPath",
        "anchorArtifactPath"
      ],
      "additionalProperties": false,
      "properties": {
        "rootHash": { "type": "string" },
        "rootSlug": { "type": "string" },
        "rootDate": { "type": ["string", "null"] },
        "entryCount": { "type": ["number", "null"] },
        "anchor": {
          "type": "object",
          "required": ["tone", "provider", "label", "detail", "bitcoinAttestations", "pendingAttestations"],
          "additionalProperties": false,
          "properties": {
            "tone": { "enum": ["confirmed", "pending", "unavailable"] },
            "provider": { "enum": ["opentimestamps", "local", null] },
            "label": { "type": "string" },
            "detail": { "type": "string" },
            "bitcoinAttestations": { "type": "number" },
            "pendingAttestations": { "type": "number" }
          }
        },
        "signature": {
          "type": "object",
          "required": ["algorithm", "assertedByFeed", "note"],
          "additionalProperties": false,
          "properties": {
            "algorithm": { "const": "Ed25519" },
            "assertedByFeed": {
              "const": false,
              "description": "The public feed does not republish the signature, so this packet makes no signature claim — verify with the commands instead."
            },
            "note": { "type": "string" }
          }
        },
        "rootArtifactPath": { "type": "string" },
        "anchorArtifactPath": { "type": "string" }
      }
    }
  },
  "allOf": [
    {
      "if": { "properties": { "state": { "const": "ready" } } },
      "then": { "required": ["ledger", "latestRoot"] }
    },
    {
      "if": { "properties": { "state": { "const": "empty" } } },
      "then": { "required": ["ledger"] }
    }
  ],
  "additionalProperties": false
}
