{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://sec.hypermedia.au/schemas/artifact-entry/v1.schema.json",
  "title": "Artifact Entry v1 Schema",
  "description": "Validates one L0 artifact entry: a hash-only CycloneDX component (evidence or derived artifact) as enumerated inside a Case Provenance BOM's components array. Normative requirements: https://sec.hypermedia.au/standards/artifact-entry/v1 This is a component fragment schema: it deliberately carries no BOM envelope (bomFormat/specVersion/serialNumber) because it validates one entry inside a Case Provenance BOM, not a document.",
  "type": "object",
  "required": [
    "bom-ref",
    "type",
    "name",
    "hashes",
    "properties"
  ],
  "properties": {
    "bom-ref": {
      "type": "string",
      "pattern": "^(evidence-[0-9]+-[0-9a-f]+|derived-[0-9]+-[A-Za-z0-9_-]+)$",
      "description": "ART-002: evidence-<ordinal>-<hashPrefix> or derived-<sourceOrdinal>-<kind>; never urn:cdx:"
    },
    "type": {
      "type": "string",
      "enum": [
        "file",
        "data",
        "machine-learning-model"
      ],
      "description": "ART-001: file = raw evidence, data = derived artifact"
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "description": "Filename as received (evidence) or as persisted (derived)"
    },
    "hashes": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/definitions/hashEntry"
      },
      "contains": {
        "type": "object",
        "properties": {
          "alg": {
            "const": "SHA-256"
          }
        },
        "required": [
          "alg"
        ]
      },
      "description": "ART-003: at least one SHA-256 entry; stronger algorithms may be added"
    },
    "data": {
      "type": "array",
      "description": "Optional CycloneDX data classification for derived artifacts"
    },
    "properties": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/propertyEntry"
      },
      "contains": {
        "type": "object",
        "properties": {
          "name": {
            "const": "cyberbench:artifactClass"
          },
          "value": {
            "enum": [
              "evidence",
              "derived"
            ]
          }
        },
        "required": [
          "name",
          "value"
        ]
      },
      "description": "ART-004: exactly one cyberbench:artifactClass of evidence | derived (closed set)"
    }
  },
  "not": {
    "required": [
      "signature"
    ],
    "description": "ART-010: an artifact entry must not carry a signature of its own"
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "properties": {
            "contains": {
              "type": "object",
              "properties": {
                "name": {
                  "const": "cyberbench:artifactClass"
                },
                "value": {
                  "const": "evidence"
                }
              },
              "required": [
                "name",
                "value"
              ]
            }
          }
        },
        "required": [
          "properties"
        ]
      },
      "then": {
        "properties": {
          "properties": {
            "allOf": [
              {
                "contains": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "const": "cyberbench:evidenceId"
                    },
                    "value": {
                      "type": "string",
                      "pattern": "^[a-f0-9]{64}$"
                    }
                  },
                  "required": [
                    "name",
                    "value"
                  ]
                }
              },
              {
                "contains": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "const": "cyberbench:ordinal"
                    },
                    "value": {
                      "type": "string",
                      "pattern": "^[1-9][0-9]*$"
                    }
                  },
                  "required": [
                    "name",
                    "value"
                  ]
                }
              },
              {
                "contains": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "const": "cyberbench:immutable"
                    },
                    "value": {
                      "const": "true"
                    }
                  },
                  "required": [
                    "name",
                    "value"
                  ]
                }
              }
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "properties": {
            "contains": {
              "type": "object",
              "properties": {
                "name": {
                  "const": "cyberbench:artifactClass"
                },
                "value": {
                  "const": "derived"
                }
              },
              "required": [
                "name",
                "value"
              ]
            }
          }
        },
        "required": [
          "properties"
        ]
      },
      "then": {
        "properties": {
          "properties": {
            "allOf": [
              {
                "contains": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "const": "cyberbench:sourceEvidenceRef"
                    },
                    "value": {
                      "type": "string",
                      "pattern": "^evidence-[0-9]+-[0-9a-f]+$"
                    }
                  },
                  "required": [
                    "name",
                    "value"
                  ]
                }
              },
              {
                "contains": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "const": "cyberbench:sourceEvidenceHash"
                    },
                    "value": {
                      "type": "string",
                      "pattern": "^[a-f0-9]{64}$"
                    }
                  },
                  "required": [
                    "name",
                    "value"
                  ]
                }
              },
              {
                "contains": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "const": "cyberbench:reproducible"
                    },
                    "value": {
                      "const": "false"
                    }
                  },
                  "required": [
                    "name",
                    "value"
                  ]
                }
              },
              {
                "contains": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "const": "cyberbench:integrity"
                    },
                    "value": {
                      "const": "hash-at-rest"
                    }
                  },
                  "required": [
                    "name",
                    "value"
                  ]
                }
              }
            ]
          }
        }
      }
    }
  ],
  "definitions": {
    "hashEntry": {
      "type": "object",
      "required": [
        "alg",
        "content"
      ],
      "properties": {
        "alg": {
          "type": "string",
          "enum": [
            "SHA-256",
            "SHA-512",
            "SHA3-256",
            "SHA3-512",
            "BLAKE3"
          ]
        },
        "content": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$|^[a-f0-9]{128}$"
        }
      }
    },
    "propertyEntry": {
      "type": "object",
      "required": [
        "name",
        "value"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "value": {
          "type": "string"
        }
      }
    }
  }
}
