{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openprint.art/schemas/registry-event/v1.0.json",
  "title": "Open Print 1.0 registry event",
  "description": "One event in an append-only certificate registry.",
  "type": "object",
  "required": [
    "schema",
    "schemaVersion",
    "id",
    "type",
    "certificateId",
    "issuerId",
    "occurredAt",
    "previousEventDigest",
    "integrity",
    "signature"
  ],
  "properties": {
    "schema": {
      "const": "https://openprint.art/schemas/registry-event/v1.0.json"
    },
    "schemaVersion": {
      "const": "1.0"
    },
    "id": {
      "type": "string",
      "minLength": 1
    },
    "type": {
      "enum": [
        "issued",
        "cancelled",
        "superseded"
      ]
    },
    "certificateId": {
      "type": "string",
      "minLength": 1
    },
    "editionId": {
      "type": "string",
      "minLength": 1
    },
    "workId": {
      "type": "string",
      "minLength": 1
    },
    "issuerId": {
      "type": "string",
      "minLength": 1
    },
    "sequence": {
      "type": "integer",
      "minimum": 1,
      "maximum": 9007199254740991
    },
    "fingerprint": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    },
    "replacementCertificateId": {
      "type": "string",
      "minLength": 1
    },
    "reason": {
      "type": "string",
      "minLength": 1
    },
    "occurredAt": {
      "type": "string",
      "format": "date-time"
    },
    "previousEventDigest": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^[a-f0-9]{64}$"
    },
    "integrity": {
      "type": "object",
      "required": [
        "algorithm",
        "digest",
        "scope"
      ],
      "properties": {
        "algorithm": {
          "const": "SHA-256"
        },
        "digest": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "scope": {
          "const": "registry event payload"
        }
      },
      "additionalProperties": false
    },
    "signature": {
      "type": "object",
      "required": [
        "algorithm",
        "keyId",
        "createdAt",
        "value",
        "scope"
      ],
      "properties": {
        "algorithm": {
          "const": "Ed25519"
        },
        "keyId": {
          "type": "string",
          "minLength": 1
        },
        "createdAt": {
          "type": "string",
          "format": "date-time"
        },
        "value": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]+$"
        },
        "scope": {
          "const": "registry event payload, integrity, and signature metadata"
        }
      },
      "additionalProperties": false
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "type": {
            "const": "issued"
          }
        }
      },
      "then": {
        "required": [
          "editionId",
          "workId",
          "sequence",
          "fingerprint"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "cancelled"
          }
        }
      },
      "then": {
        "required": [
          "reason"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "superseded"
          }
        }
      },
      "then": {
        "required": [
          "replacementCertificateId",
          "reason"
        ]
      }
    }
  ],
  "additionalProperties": false
}
