{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:timevolt:receipt:v2",
  "title": "TIMEVOLT portable receipt v1",
  "description": "Frozen v1 wire profile. Staging emitter only. The production label is reserved and does not enable production issuance.",
  "type": "object",
  "properties": {
    "format": {
      "const": "timevolt.receipt"
    },
    "version": {
      "const": 2
    },
    "environment": {
      "enum": [
        "staging",
        "production"
      ]
    },
    "record_id": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "record": {
      "type": "object",
      "properties": {
        "profile": {
          "const": "timevolt.record.v1"
        },
        "subject": {
          "type": "object",
          "properties": {
            "algorithm": {
              "const": "sha256"
            },
            "digest": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            }
          },
          "required": [
            "algorithm",
            "digest"
          ],
          "additionalProperties": false
        },
        "references": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "maxItems": 256,
          "uniqueItems": true
        },
        "nonce": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        }
      },
      "required": [
        "profile",
        "subject",
        "references",
        "nonce"
      ],
      "additionalProperties": false
    },
    "application_manifest": {
      "type": "object",
      "properties": {
        "profile": {
          "const": "timevolt.recipe.release.alpha1"
        },
        "files": {
          "type": "array",
          "minItems": 1,
          "maxItems": 20,
          "items": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "bytes": {
                "type": "integer",
                "minimum": 0
              },
              "sha256": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              }
            },
            "required": [
              "name",
              "bytes",
              "sha256"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [
        "profile",
        "files"
      ],
      "additionalProperties": false
    },
    "membership": {
      "type": "object",
      "properties": {
        "algorithm": {
          "const": "timevolt-batch-v1"
        },
        "index": {
          "type": "integer",
          "minimum": 0,
          "maximum": 999998
        },
        "total": {
          "type": "integer",
          "minimum": 2,
          "maximum": 1000000
        },
        "siblings": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "minItems": 1,
          "maxItems": 20
        }
      },
      "required": [
        "algorithm",
        "index",
        "total",
        "siblings"
      ],
      "additionalProperties": false
    },
    "batch": {
      "type": "object",
      "properties": {
        "root": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "timestamps": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "provider": {
                "enum": [
                  "digicert",
                  "sectigo",
                  "freetsa",
                  "sigstore"
                ]
              },
              "nonce_hex": {
                "type": "string",
                "pattern": "^[a-f0-9]{1,64}$"
              },
              "response_der": {
                "type": "string",
                "pattern": "^[A-Za-z0-9+/]*={0,2}$",
                "maxLength": 1398104
              }
            },
            "required": [
              "provider",
              "nonce_hex",
              "response_der"
            ],
            "additionalProperties": false
          },
          "maxItems": 4
        },
        "calendar_submissions": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "url": {
                "enum": [
                  "https://alice.btc.calendar.opentimestamps.org",
                  "https://bob.btc.calendar.opentimestamps.org"
                ]
              },
              "accepted_at": {
                "type": "string",
                "format": "date-time"
              },
              "response_sha256": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              }
            },
            "required": [
              "url",
              "accepted_at",
              "response_sha256"
            ],
            "additionalProperties": false
          },
          "maxItems": 2
        },
        "ots": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[A-Za-z0-9+/]*={0,2}$",
              "maxLength": 1398104
            },
            {
              "type": "null"
            }
          ]
        },
        "bitcoin": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "network": {
                  "const": "mainnet"
                },
                "height": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 2147483647
                },
                "block_hash": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$"
                },
                "header": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{160}$"
                }
              },
              "required": [
                "network",
                "height",
                "block_hash",
                "header"
              ],
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "root",
        "timestamps",
        "calendar_submissions",
        "ots",
        "bitcoin"
      ],
      "additionalProperties": false
    },
    "issuer_public_key": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "snapshot": {
      "type": "object",
      "properties": {
        "body": {
          "type": "object",
          "properties": {
            "profile": {
              "const": "timevolt.evidence-snapshot.v1"
            },
            "record_id": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            },
            "sequence": {
              "type": "integer",
              "minimum": 1
            },
            "previous_snapshot_sha256": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            },
            "batch_sha256": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            },
            "status": {
              "enum": [
                "pending",
                "dated",
                "permanent"
              ]
            },
            "checked_at": {
              "type": "string",
              "format": "date-time"
            },
            "chain_checks": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "source": {
                    "enum": [
                      "mempool.space",
                      "blockstream.info"
                    ]
                  },
                  "source_url": {
                    "enum": [
                      "https://mempool.space/api",
                      "https://blockstream.info/api"
                    ]
                  },
                  "checked_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "block_hash": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  },
                  "block_height": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "active_hash_at_height": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  },
                  "in_best_chain": {
                    "type": "boolean"
                  },
                  "tip_hash": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  },
                  "tip_height": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "confirmations": {
                    "type": "integer",
                    "minimum": 0
                  }
                },
                "required": [
                  "source",
                  "source_url",
                  "checked_at",
                  "block_hash",
                  "block_height",
                  "active_hash_at_height",
                  "in_best_chain",
                  "tip_hash",
                  "tip_height",
                  "confirmations"
                ],
                "additionalProperties": false
              },
              "maxItems": 2
            },
            "correction_head": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            }
          },
          "required": [
            "profile",
            "record_id",
            "sequence",
            "previous_snapshot_sha256",
            "batch_sha256",
            "status",
            "checked_at",
            "chain_checks",
            "correction_head"
          ],
          "additionalProperties": false
        },
        "issuer_key_id": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "signature": {
          "type": "string",
          "pattern": "^[A-Za-z0-9+/]{86}==$"
        }
      },
      "required": [
        "body",
        "issuer_key_id",
        "signature"
      ],
      "additionalProperties": false
    },
    "corrections": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "body": {
            "type": "object",
            "properties": {
              "profile": {
                "const": "timevolt.status-correction.v1"
              },
              "record_id": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              },
              "sequence": {
                "type": "integer",
                "minimum": 1
              },
              "previous_sha256": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              },
              "from_status": {
                "enum": [
                  "pending",
                  "dated",
                  "permanent"
                ]
              },
              "to_status": {
                "enum": [
                  "pending",
                  "dated",
                  "permanent"
                ]
              },
              "reason": {
                "type": "string",
                "maxLength": 4096
              },
              "recorded_at": {
                "type": "string",
                "format": "date-time"
              },
              "observations_sha256": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              }
            },
            "required": [
              "profile",
              "record_id",
              "sequence",
              "previous_sha256",
              "from_status",
              "to_status",
              "reason",
              "recorded_at",
              "observations_sha256"
            ],
            "additionalProperties": false
          },
          "issuer_key_id": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "signature": {
            "type": "string",
            "pattern": "^[A-Za-z0-9+/]{86}==$"
          }
        },
        "required": [
          "body",
          "issuer_key_id",
          "signature"
        ],
        "additionalProperties": false
      },
      "maxItems": 10000
    }
  },
  "required": [
    "format",
    "version",
    "environment",
    "record_id",
    "membership",
    "batch",
    "issuer_public_key",
    "snapshot",
    "corrections"
  ],
  "additionalProperties": false
}
