{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://sec.hypermedia.au/schemas/case-provenance/v1.schema.json",
  "title": "Case Provenance BOM v1 Schema",
  "description": "Validates one sealed version of an L1 Case Provenance BOM. Shape-only: version monotonicity across seals, corpus completeness, sidecar joins, Fulcio identity comparison and hash recomputation are verifier (adbom-cli) checks. Normative requirements: https://sec.hypermedia.au/standards/case-provenance/v1",
  "type": "object",
  "required": [
    "bomFormat",
    "specVersion",
    "serialNumber",
    "version",
    "metadata",
    "components",
    "signature"
  ],
  "properties": {
    "bomFormat": {
      "type": "string",
      "enum": [
        "CycloneDX"
      ]
    },
    "specVersion": {
      "type": "string",
      "const": "1.7"
    },
    "serialNumber": {
      "type": "string",
      "pattern": "^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
    },
    "version": {
      "type": "integer",
      "minimum": 1
    },
    "metadata": {
      "type": "object",
      "required": [
        "timestamp",
        "authors",
        "component",
        "properties"
      ],
      "properties": {
        "timestamp": {
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}"
        },
        "authors": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "name"
            ],
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1
              },
              "email": {
                "type": "string"
              }
            }
          }
        },
        "component": {
          "type": "object",
          "required": [
            "type",
            "name"
          ],
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "data"
              ]
            },
            "name": {
              "type": "string",
              "minLength": 1
            },
            "version": {
              "type": "string"
            }
          }
        },
        "properties": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/propertyEntry"
          },
          "allOf": [
            {
              "contains": {
                "type": "object",
                "properties": {
                  "name": {
                    "const": "cyberbench:caseId"
                  },
                  "value": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "required": [
                  "name",
                  "value"
                ]
              }
            },
            {
              "contains": {
                "type": "object",
                "properties": {
                  "name": {
                    "const": "cyberbench:sealType"
                  },
                  "value": {
                    "enum": [
                      "ingest",
                      "interim",
                      "finalisation"
                    ]
                  }
                },
                "required": [
                  "name",
                  "value"
                ]
              }
            },
            {
              "contains": {
                "type": "object",
                "properties": {
                  "name": {
                    "const": "cyberbench:custodyChainRef"
                  },
                  "value": {
                    "type": "string",
                    "pattern": "^urn:cdx:.+"
                  }
                },
                "required": [
                  "name",
                  "value"
                ]
              }
            },
            {
              "contains": {
                "type": "object",
                "properties": {
                  "name": {
                    "const": "cyberbench:transparencyReceiptRef"
                  },
                  "value": {
                    "type": "string"
                  }
                },
                "required": [
                  "name",
                  "value"
                ]
              }
            },
            {
              "not": {
                "contains": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "enum": [
                        "cyberbench:sealTsaTokenRef",
                        "cyberbench:evidenceRecordRef"
                      ]
                    }
                  },
                  "required": [
                    "name"
                  ]
                }
              },
              "description": "CPRV-006: post-seal refs live in the sidecar index, never inside the sealed document"
            }
          ]
        }
      }
    },
    "components": {
      "type": "array",
      "items": {
        "$ref": "https://sec.hypermedia.au/schemas/artifact-entry/v1.schema.json"
      },
      "description": "CPRV-003: every artifact entry in the corpus, each per artifact-entry/v1"
    },
    "dependencies": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "ref",
          "dependsOn"
        ],
        "properties": {
          "ref": {
            "type": "string",
            "minLength": 1
          },
          "dependsOn": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "string",
              "minLength": 1
            }
          }
        }
      },
      "description": "CPRV-004: derived dependsOn evidence (lineage mirror)"
    },
    "signature": {
      "$ref": "#/definitions/signature"
    }
  },
  "definitions": {
    "propertyEntry": {
      "type": "object",
      "required": [
        "name",
        "value"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "value": {
          "type": "string"
        }
      }
    },
    "signature": {
      "type": "object",
      "required": [
        "algorithm",
        "certificatePath",
        "value"
      ],
      "properties": {
        "algorithm": {
          "type": "string",
          "enum": [
            "ES256",
            "ES384",
            "ES512"
          ]
        },
        "certificatePath": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string"
          }
        },
        "value": {
          "type": "string",
          "minLength": 1
        }
      }
    }
  }
}
