{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://schema.traceoriginal.com/trace-original-en-schema-v1.4.json",
  "title": "trace:original Schema v1.4",
  "maxWidth": "250",
  "HashAlg": "SHA-256",
  "definitions": {
    "Hex64": {
      "type": "string",
      "pattern": "^([a-f]|\\d){64}$"
    },
    "Hex66": {
      "type": "string",
      "pattern": "^([a-f]|\\d){66}$"
    },
    "Hex66Invalidated": {
      "type": "number",
      "pattern": "^0{66}$"
    },
    "ISO8601-Date": {
      "type": "string",
      "pattern": "^20(19|[2-9]\\d)-(0\\d|1[0-2])-([0-2]\\d|30|31)T([0-1]\\d|2[0-3])(:[0-5]\\d){2}\\.\\d{3}Z$"
    },
    "Base64_88": {
      "type": "string",
      "pattern": "^[A-Za-z0-9/+]{86}==$"
    },
    "TechnicalDetailsBody": {
      "properties": {
        "LedgerURL": {
          "type": "string",
          "format": "uri",
          "position": "1"
        },
        "ContentHash": {
          "$ref": "#/definitions/Hex64",
          "position": "2"
        },
        "OwnerKey": {
          "$ref": "#/definitions/Hex66",
          "position": "3"
        },
        "OwnerKeyId": {
          "$ref": "#/definitions/Base64_88",
          "position": "4"
        },
        "VersionKey": {
          "$ref": "#/definitions/Hex64",
          "position": "5"
        },
        "TraceOriginalId": {
          "$ref": "#/definitions/Hex64",
          "position": "6"
        },
        "DocumentTimestamp": {
          "$ref": "#/definitions/ISO8601-Date",
          "position": "7"
        },
        "DocumentSignature": {
          "$ref": "#/definitions/Base64_88",
          "position": "8"
        }
      },
      "required": [
        "ContentHash",
        "OwnerKey",
        "VersionKey",
        "TraceOriginalId",
        "LedgerURL"
      ],
      "additionalProperties": false
    },
    "TechnicalDetailsAmendment": {
      "properties": {
        "ContentHash": {
          "$ref": "#/definitions/Hex64",
          "position": "1"
        },
        "OwnerKey": {
          "oneOf": [
            {
              "$ref": "#/definitions/Hex66"
            },
            {
              "$ref": "#/definitions/Hex66Invalidated"
            }
          ],
          "position": "2"
        },
        "OwnerKeyId": {
          "$ref": "#/definitions/Base64_88",
          "position": "3"
        },
        "VersionKey": {
          "$ref": "#/definitions/Hex64",
          "position": "4"
        },
        "DocumentTimestamp": {
          "$ref": "#/definitions/ISO8601-Date",
          "position": "5"
        },
        "DocumentSignature": {
          "$ref": "#/definitions/Base64_88",
          "position": "6"
        }
      },
      "required": [
        "ContentHash",
        "OwnerKey",
        "VersionKey"
      ],
      "additionalProperties": false
    },
    "SignatureAmendmentBody": {
      "type": "object",
      "properties": {
        "Type": {
          "enum": [
            "Signature amendment",
            "Change to paper amendment"
          ]
        },
        "Content": {
          "type": "object",
          "properties": {
            "Subject" : {
              "type": "object",
              "properties": {
                "Name": {
                  "type": "string"
                },
                "ID": {
                  "oneOf": [{"type": "string"}, {"type": "number"}]
                },
                "ID Type": {
                  "type": "string"
                },
                "Capacity of signatory": {
                  "type": "string"
                },
                "Role": {
                  "type": "string"
                },
                "Organisation": {
                  "type": "string"
                }
              },
              "required": [
                "ID",
                "ID Type"
              ]
            },
            "Method" : {
              "type": "string"
            },
            "Format" : {
              "type": "string"
            },
            "Signature" : {
              "type": "object"
            }
          },
          "required": [
            "Subject",
            "Method",
            "Signature"
          ],
          "uniqueItems": true
        },
        "TechnicalDetails": {
          "$ref": "#/definitions/TechnicalDetailsAmendment"
        }
      },
      "required": [
        "Type",
        "Content",
        "TechnicalDetails"
      ],
      "additionalProperties": false
    },
    "AmendmentBody": {
      "type": "object",
      "properties": {
        "Type": {
          "enum": [
            "Amendment",
            "Transfer",
            "Invalidation"
          ]
        },
        "Content": {
          "type": [
            "object",
            "string"
          ]
        },
        "TechnicalDetails": {
          "$ref": "#/definitions/TechnicalDetailsAmendment"
        }
      },
      "required": [
        "Type",
        "Content",
        "TechnicalDetails"
      ],
      "additionalProperties": false
    },
    "VersionType": {
      "type": "object",
      "properties": {
        "Schema": {
          "type": "string",
          "pattern": "https://.*"
        },
        "ContentType": {
          "type": "array",
          "items": [
            {
              "properties": {
                "Schema": {
                  "type": "string",
                  "pattern": "https://.*"
                }
              },
              "additionalProperties": false
            }
          ],
          "uniqueItems": true
        }
      },
      "required": [
        "Schema"
      ],
      "additionalProperties": false
    }
  },
  "properties": {
    "Version": {
      "$ref": "#/definitions/VersionType"
    },
    "Content": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "Initial Pdf": {
              "type": "object",
              "properties": {
                "File name": {
                  "type": "string"
                },
                "Hash": {
                  "$ref": "#/definitions/Hex64"
                },
                "Description": {
                  "type": "string"
                },
                "Pdf form info": {
                  "oneOf": [{"type": "array"}, {"type": "object"}]
                },
                "Pdf form operation": {
                  "type": "string"
                }
              },
              "required": ["File name", "Hash"]
            }
          }
        },
        {
          "type": "string"
        }
      ]
    },
    "TechnicalDetails": {
      "$ref": "#/definitions/TechnicalDetailsBody"
    },
    "Amendments": {
      "type": "array",
      "items": {
        "oneOf": [{"$ref": "#/definitions/AmendmentBody"}, {"$ref": "#/definitions/SignatureAmendmentBody"}]
      },
      "uniqueItems": true
    }
  },
  "required": [
    "Version",
    "Content",
    "TechnicalDetails"
  ],
  "additionalProperties": false
}
