{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openprint.art/schemas/registry-checkpoint/v1.0.json",
  "title": "Open Print 1.0 registry checkpoint",
  "description": "A signed anchor for one exact prefix of an Open Print registry.",
  "type": "object",
  "required": [
    "schema",
    "schemaVersion",
    "id",
    "issuerId",
    "registryLength",
    "headEventDigest",
    "previousCheckpointDigest",
    "createdAt",
    "integrity",
    "signature"
  ],
  "properties": {
    "schema": {
      "const": "https://openprint.art/schemas/registry-checkpoint/v1.0.json"
    },
    "schemaVersion": {
      "const": "1.0"
    },
    "id": {
      "type": "string",
      "minLength": 1
    },
    "issuerId": {
      "type": "string",
      "minLength": 1
    },
    "registryLength": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "headEventDigest": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^[a-f0-9]{64}$"
    },
    "previousCheckpointDigest": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^[a-f0-9]{64}$"
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "integrity": {
      "type": "object",
      "required": [
        "algorithm",
        "digest",
        "scope"
      ],
      "properties": {
        "algorithm": {
          "const": "SHA-256"
        },
        "digest": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "scope": {
          "const": "registry checkpoint 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 checkpoint payload, integrity, and signature metadata"
        }
      },
      "additionalProperties": false
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "registryLength": {
            "const": 0
          }
        },
        "required": [
          "registryLength"
        ]
      },
      "then": {
        "properties": {
          "headEventDigest": {
            "const": null
          }
        }
      },
      "else": {
        "properties": {
          "headEventDigest": {
            "type": "string"
          }
        }
      }
    }
  ],
  "additionalProperties": false
}
