{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://complyedge.io/rulebook/0.1.0/export.schema.json",
  "title": "ADCR export 0.1.0",
  "description": "An export file: an envelope and the records it carries, the structural part of classes Anchor and Export of the ADCR rulebook 0.1.0. SPEC.md governs; the checks on an anchor's timestamp token and the agreement between an export and its producer profile are made by the verifier, not by this schema. Licensed Apache-2.0.",
  "type": "object",
  "required": [
    "envelope",
    "records"
  ],
  "properties": {
    "envelope": {
      "type": "object",
      "required": [
        "rulebook",
        "account_id",
        "producer_id",
        "period",
        "clock_source",
        "chain_summary",
        "anchors",
        "anchor_coverage",
        "retention_profile_url",
        "interpretation_guide_url"
      ],
      "properties": {
        "rulebook": {
          "type": "string",
          "const": "https://complyedge.io/rulebook/0.1.0"
        },
        "account_id": {
          "type": "string"
        },
        "producer_id": {
          "type": "string"
        },
        "period": {
          "type": "object",
          "required": [
            "from",
            "to"
          ],
          "properties": {
            "from": {
              "type": "string"
            },
            "to": {
              "type": "string"
            }
          }
        },
        "clock_source": {
          "type": "object",
          "required": [
            "reference",
            "tolerance_ms"
          ],
          "properties": {
            "reference": {
              "type": "string"
            },
            "tolerance_ms": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "chain_summary": {
          "type": "object",
          "required": [
            "alg",
            "first_seq",
            "last_seq",
            "chained_rows",
            "pre_chain_rows"
          ],
          "properties": {
            "alg": {
              "type": "string",
              "const": "sha256-chain-1"
            },
            "first_seq": {
              "type": "integer",
              "minimum": 0
            },
            "last_seq": {
              "type": "integer",
              "minimum": 0
            },
            "chained_rows": {
              "type": "integer",
              "minimum": 0
            },
            "pre_chain_rows": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "anchors": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "statement",
              "token_b64",
              "provider_url",
              "stored_at"
            ],
            "properties": {
              "statement": {
                "type": "object",
                "required": [
                  "account_id",
                  "chain_alg",
                  "chain_hash",
                  "chain_seq"
                ],
                "properties": {
                  "account_id": {
                    "type": "string"
                  },
                  "chain_alg": {
                    "type": "string"
                  },
                  "chain_hash": {
                    "type": "string",
                    "pattern": "^[0-9a-f]{64}$"
                  },
                  "chain_seq": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "additionalProperties": false
              },
              "token_b64": {
                "type": "string",
                "$comment": "ANC-02: the RFC 3161 TimeStampResp as returned by the provider, or the bare TimeStampToken, base64"
              },
              "provider_url": {
                "type": "string"
              },
              "stored_at": {
                "type": "string"
              }
            }
          }
        },
        "anchor_coverage": {
          "type": "object",
          "required": [
            "newest_anchored_seq",
            "unanchored_rows"
          ],
          "properties": {
            "newest_anchored_seq": {
              "type": "integer",
              "minimum": 0
            },
            "unanchored_rows": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "retention_profile_url": {
          "type": "string"
        },
        "signatures": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "alg",
              "key_ref",
              "value"
            ],
            "properties": {
              "alg": {
                "type": "string"
              },
              "key_ref": {
                "type": "string"
              },
              "value": {
                "type": "string"
              }
            }
          },
          "$comment": "CHN-05"
        },
        "interpretation_guide_url": {
          "type": "string"
        },
        "export_purpose": {
          "type": "string",
          "$comment": "OVS-05: oversight_evaluation is the only purpose under which per-reviewer counts may appear"
        }
      }
    },
    "records": {
      "type": "array",
      "items": {
        "$ref": "decision-record.schema.json"
      }
    }
  }
}
