{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/sequence-attestation-v1.json",
  "title": "Sequence Attestation v1",
  "description": "Canonical schema for the Hive Sequence Attestation receipt, canonical type sequence.attestation, brand SA. Binds an ordered set of event digests to a time bracket whose endpoints are produced outside Hive. The lower bound is a public blockchain block hash folded into the sequence root, so the root cannot have been constructed before that block existed. The upper bound is an RFC 3161 timestamp token whose message imprint is the sequence root, so an authority outside Hive recorded that root at the stated time. Every other ordering contract in the Hive canon orders against internal chain state or against the signer's own clock; this contract exists because a disputed detection or notification timeline cannot be settled by the clock of the system whose timeline is in dispute. It does not attest that any event is true, does not attest that the producer's own timestamps are honest, does not attest that the event set is complete, and does not itself validate the timestamp authority's certificate chain.",
  "type": "object",
  "required": [
    "receipt_id",
    "payload_sha256",
    "sig_b64u",
    "key_id",
    "algorithm",
    "ts",
    "signed_body"
  ],
  "additionalProperties": false,
  "properties": {
    "receipt_id": {
      "type": "string",
      "pattern": "^r_sequence\\.attestation_[0-9]{10,}_[0-9a-f]{12}$"
    },
    "payload_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
    "sig_b64u": { "type": "string", "pattern": "^[A-Za-z0-9_-]{86}$" },
    "key_id": { "type": "string", "pattern": "^did:(hive|web|key):[A-Za-z0-9._:%-]+$" },
    "algorithm": { "type": "string", "const": "Ed25519" },
    "ts": { "type": "integer", "minimum": 1000000000 },
    "signed_body": {
      "type": "object",
      "required": [
        "receipt_type",
        "schema",
        "sequence_id",
        "tenant_id",
        "events",
        "sequence_root",
        "anchor_state",
        "boundary"
      ],
      "additionalProperties": false,
      "properties": {
        "receipt_type": { "type": "string", "const": "sequence.attestation" },
        "schema": { "type": "string", "const": "r1.0.0" },
        "sequence_id": { "type": "string", "minLength": 1, "maxLength": 256 },
        "tenant_id": { "type": "string", "minLength": 1, "maxLength": 256 },
        "events": {
          "type": "array",
          "minItems": 1,
          "maxItems": 4096,
          "description": "The ordered event set, as digests. Array order is the attested order and the fold consumes it in exactly that order, so a reordered array produces a different sequence_root and fails the SEQUENCE_ROOT gate.",
          "items": {
            "type": "object",
            "required": ["index", "event_sha256"],
            "additionalProperties": false,
            "properties": {
              "index": {
                "type": "integer",
                "minimum": 0,
                "description": "Position in the sequence. Must start at 0 and increase by exactly one, so a gap or a repeat cannot be signed as a contiguous sequence."
              },
              "event_sha256": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$",
                "description": "Digest of the event content, never the content itself. The signer never receives the underlying event."
              },
              "label": {
                "type": "string",
                "maxLength": 128,
                "description": "Optional opaque label for the event, carried for the reader's benefit. It is folded into the root, so it cannot be edited after the fact, but this receipt makes no claim about whether the label is accurate."
              },
              "producer_observed_at": {
                "type": "string",
                "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,9})?Z$",
                "description": "Optional. The time the producing system says it saw this event. Recorded because a reader usually wants it, and folded into the root so it cannot be edited after the fact. This receipt explicitly does not attest that this value is honest; that is the entire reason the external bracket exists."
              }
            }
          }
        },
        "sequence_root": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Computed by the service, never accepted from the caller. Sequential fold over the canonical form of each event in array order, seeded from the lower bound when one is present so the block hash is inside the root rather than merely alongside it."
        },
        "lower_bound": {
          "type": "object",
          "description": "A public blockchain block, folded into sequence_root as the fold seed. Because the block hash is unpredictable before the block is produced, a root containing it cannot have been constructed earlier. This is the floor of the bracket.",
          "required": ["kind", "chain", "block_number", "block_hash", "block_time"],
          "additionalProperties": false,
          "properties": {
            "kind": { "type": "string", "const": "blockchain_block" },
            "chain": {
              "type": "string",
              "minLength": 1,
              "maxLength": 64,
              "description": "Chain identifier, for example base-mainnet. Opaque to this schema; a verifier resolves the block against the named chain itself."
            },
            "block_number": { "type": "integer", "minimum": 0 },
            "block_hash": {
              "type": "string",
              "pattern": "^0x[0-9a-f]{64}$",
              "description": "The block hash, as published by the chain. A verifier can fetch this block independently and confirm both the hash and the time."
            },
            "block_time": {
              "type": "string",
              "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,9})?Z$",
              "description": "The block's own timestamp, as published by the chain. This value comes from the chain, not from Hive and not from the caller's system."
            }
          }
        },
        "upper_bound": {
          "type": "object",
          "description": "An RFC 3161 timestamp token issued over sequence_root by a timestamp authority outside Hive. Because the token's message imprint is the root, the root demonstrably existed no later than the authority's stated time. This is the ceiling of the bracket.",
          "required": ["kind", "tsa_url", "hash_algorithm", "imprint_sha256", "timestamp", "token_sha256", "token_b64"],
          "additionalProperties": false,
          "properties": {
            "kind": { "type": "string", "const": "rfc3161" },
            "tsa_url": {
              "type": "string",
              "minLength": 1,
              "maxLength": 512,
              "description": "The timestamp authority that issued the token. Recorded so a reader knows whose clock this is and can fetch that authority's published root certificate to check the token themselves."
            },
            "hash_algorithm": { "type": "string", "const": "sha256" },
            "imprint_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$",
              "description": "The message imprint carried inside the token, extracted from the token bytes by the service. The UPPER_BOUND_BINDING gate fails unless this equals sequence_root, which is what stops a token issued over unrelated content from being presented as a timestamp for this sequence."
            },
            "serial": {
              "type": "string",
              "maxLength": 128,
              "description": "Optional. The token serial number, as issued by the authority."
            },
            "timestamp": {
              "type": "string",
              "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,9})?Z$",
              "description": "The authority's stated time, extracted from the token's genTime field by the service rather than accepted from the caller."
            },
            "token_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "token_b64": {
              "type": "string",
              "minLength": 1,
              "maxLength": 32768,
              "description": "The complete DER timestamp token, base64 encoded. Carried in full and deliberately, because it is the only thing that lets a reader verify the upper bound against the authority directly instead of taking Hive's word for it."
            }
          }
        },
        "anchor_state": {
          "type": "string",
          "enum": ["two_sided", "upper_bound_only", "lower_bound_only"],
          "description": "Computed by the service from which bounds are actually present, so a one sided anchor can never be read as a full bracket. two_sided: both a floor and a ceiling, from two independent outside sources. upper_bound_only: the root existed no later than the stated time, with no floor. lower_bound_only: the root was built no earlier than the named block, with no ceiling. A receipt with no external anchor at all cannot be minted."
        },
        "bracket": {
          "type": "object",
          "description": "Present only when anchor_state is two_sided. The closed interval within which the sequence root demonstrably came into existence, with both endpoints set by parties other than Hive and other than the system being examined.",
          "required": ["opens_at", "closes_at", "width_seconds"],
          "additionalProperties": false,
          "properties": {
            "opens_at": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,9})?Z$" },
            "closes_at": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,9})?Z$" },
            "width_seconds": {
              "type": "integer",
              "minimum": 0,
              "description": "closes_at minus opens_at, in whole seconds. A narrow bracket is a stronger claim than a wide one, and stating the width plainly stops a very wide bracket from being read as precision it does not have."
            }
          }
        },
        "boundary": {
          "type": "string",
          "const": "This receipt attests that the recorded events fold to sequence_root in exactly the recorded order, that when a lower bound is present the named public block hash was folded into that root so the root cannot have been constructed before that block existed, that when an upper bound is present the RFC 3161 token's message imprint equals sequence_root so an authority outside Hive held that root at the stated time, and that anchor_state and bracket recompute from the bounds actually present. It does not attest that any event is true, that any event set is complete, or that the producing system's own observed times are honest. It does not itself validate the timestamp authority's certificate chain; the complete token is carried in the receipt so an independent verifier can check that chain against the authority's published root."
        }
      }
    }
  }
}
