{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://preparedboard.com/standard/v1/chain-anchors.schema.json",
  "title": "prepared-board.chain-anchors.v1",
  "description": "anchors.json in an exported bundle: public timestamps on boards' sealed chain heads. Each anchor's digest is a leaf of an RFC 6962 Merkle tree whose root was timestamped by an RFC 3161 Time-Stamp Authority and submitted to OpenTimestamps (Bitcoin).",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "exportedAt",
    "anchors"
  ],
  "properties": {
    "schema": {
      "const": "prepared-board.chain-anchors.v1"
    },
    "exportedAt": {
      "type": "string",
      "format": "date-time"
    },
    "anchors": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "boardId",
          "seq",
          "headHash",
          "salt",
          "anchorDigest",
          "merklePath",
          "merkleRoot",
          "runId",
          "anchoredAt",
          "rfc3161",
          "opentimestamps"
        ],
        "properties": {
          "boardId": {
            "type": "string",
            "minLength": 1
          },
          "seq": {
            "type": "integer",
            "minimum": 1,
            "description": "The anchored seal's seq: the chain head at anchoring time."
          },
          "headHash": {
            "type": "string",
            "pattern": "^sha256:[0-9a-f]{64}$",
            "description": "contentHash of the seal at seq."
          },
          "salt": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$",
            "description": "Random per anchor, so sibling hashes reveal nothing about other boards."
          },
          "anchorDigest": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$",
            "description": "SHA-256 of the canonical JSON of {schema: \"prepared-board.chain-anchor.v1\", boardId, seq, headHash, salt}."
          },
          "merklePath": {
            "type": "array",
            "description": "Leaf to root. leaf = SHA-256(0x00 ‖ anchorDigest); each step: SHA-256(0x01 ‖ left ‖ right), with the sibling on `side`.",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "side",
                "hash"
              ],
              "properties": {
                "side": {
                  "enum": [
                    "left",
                    "right"
                  ]
                },
                "hash": {
                  "type": "string",
                  "pattern": "^[0-9a-f]{64}$"
                }
              }
            }
          },
          "merkleRoot": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "runId": {
            "type": "string"
          },
          "anchoredAt": {
            "type": "string",
            "format": "date-time"
          },
          "rfc3161": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "tsa",
                  "url",
                  "genTime",
                  "token"
                ],
                "properties": {
                  "tsa": {
                    "type": "string"
                  },
                  "url": {
                    "type": "string"
                  },
                  "genTime": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "token": {
                    "type": "string",
                    "description": "Base64 DER TimeStampToken (CMS SignedData with TSTInfo) whose messageImprint is SHA-256 merkleRoot."
                  }
                }
              }
            ]
          },
          "opentimestamps": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "status",
                  "bitcoinHeight",
                  "proof"
                ],
                "properties": {
                  "status": {
                    "enum": [
                      "pending",
                      "final"
                    ]
                  },
                  "bitcoinHeight": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "proof": {
                    "type": "string",
                    "description": "Base64 .ots file whose SHA-256 file digest is merkleRoot."
                  }
                }
              }
            ]
          }
        }
      }
    }
  }
}
