{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://cavemansecurity.xyz/schema/rock-v0.schema.json",
  "title": "Rock",
  "description": "Caveman Security attested-capture proof pack (v0).",
  "type": "object",
  "additionalProperties": false,
  "required": ["v", "id", "media", "capture", "device", "witnesses", "edit", "created_at"],
  "properties": {
    "v": { "const": 0, "description": "Rock format version." },
    "id": {
      "type": "string",
      "pattern": "^rock_[a-zA-Z0-9_-]{8,64}$",
      "description": "Public Rock id."
    },
    "demo": {
      "type": "boolean",
      "description": "True only for simulated Rocks. Production verifiers must fail closed if demo is true unless explicitly in demo mode."
    },
    "created_at": {
      "type": "string",
      "format": "date-time",
      "description": "When this Rock package was assembled (ISO-8601)."
    },
    "media": {
      "type": "object",
      "additionalProperties": false,
      "required": ["hash_alg", "hash", "content_type"],
      "properties": {
        "hash_alg": { "enum": ["sha256"] },
        "hash": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$",
          "description": "Hex digest of the published media bytes."
        },
        "content_type": {
          "type": "string",
          "examples": ["image/jpeg", "video/mp4"]
        },
        "bytes": {
          "type": "integer",
          "minimum": 1,
          "description": "Published media size in bytes."
        },
        "uri": {
          "type": "string",
          "description": "Optional locator for the published media."
        }
      }
    },
    "capture": {
      "type": "object",
      "additionalProperties": false,
      "required": ["commitment_alg", "commitment", "captured_at"],
      "properties": {
        "commitment_alg": { "enum": ["sha256", "poseidon", "pedersen"] },
        "commitment": {
          "type": "string",
          "minLength": 16,
          "description": "C0 — commitment to raw sensor data (or GOP root for video)."
        },
        "captured_at": {
          "type": "string",
          "format": "date-time",
          "description": "Shutter / capture time window start."
        },
        "captured_until": {
          "type": "string",
          "format": "date-time",
          "description": "Optional end of capture window (video)."
        },
        "sensor": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "make": { "type": "string" },
            "model": { "type": "string" },
            "mode": { "enum": ["still", "video"] }
          }
        }
      }
    },
    "device": {
      "type": "object",
      "additionalProperties": false,
      "required": ["pubkey", "sig_alg", "signature", "signed_payload"],
      "properties": {
        "device_id": { "type": "string" },
        "pubkey": {
          "type": "string",
          "description": "Device public key (hex or multibase)."
        },
        "sig_alg": { "enum": ["ed25519"] },
        "signature": {
          "type": "string",
          "description": "Sign_dev over signed_payload."
        },
        "signed_payload": {
          "type": "string",
          "description": "Canonical bytes or hex of commitment || captured_at || sensor_config that were signed."
        }
      }
    },
    "witnesses": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["kind", "status", "observed_at"],
        "properties": {
          "kind": {
            "enum": [
              "starlink_dishy_telemetry",
              "starlink_sdr_doppler",
              "power_line_flicker",
              "acoustic_print",
              "rf_quorum"
            ]
          },
          "status": { "enum": ["valid", "unverified", "invalid"] },
          "observed_at": { "type": "string", "format": "date-time" },
          "location_grade": {
            "enum": ["hidden", "city", "precise"]
          },
          "location_label": {
            "type": ["string", "null"],
            "description": "Human place label when grade is city or precise."
          },
          "evidence": {
            "type": "object",
            "description": "Kind-specific fields (ephemeris id, Doppler summary, etc.).",
            "additionalProperties": true
          }
        }
      }
    },
    "edit": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "allowed_transforms"],
      "properties": {
        "status": { "enum": ["valid", "rejected", "absent"] },
        "proof_system": {
          "type": "string",
          "description": "e.g. halo2-stub, picozk, none-v0"
        },
        "proof": {
          "type": ["string", "null"],
          "description": "Serialized proof or URI; null in v0 software stubs."
        },
        "allowed_transforms": {
          "type": "array",
          "items": {
            "enum": ["identity", "jpeg_compress", "resize", "crop", "transcode"]
          }
        },
        "note": { "type": "string" }
      }
    },
    "privacy": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "mode": { "enum": ["public", "selective"] },
        "reveals_location": { "type": "boolean" }
      }
    }
  }
}
