{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/afir-stream-v2.json",
  "title": "AFiR-Stream v1",
  "description": "AFiR-Stream receipt. Attests that a stream_session_id and a caller held audio segment digest were recorded and signed at recorded_at, using Ed25519 today. It does not attest that post quantum signing covers this stream; pq_enabled is fixed to false because this deployment signs with Ed25519, not a post quantum algorithm, and that must never be caller overridable.",
  "type": "object",
  "required": [
    "receipt_id",
    "payload_sha256",
    "sig_b64u",
    "key_id",
    "algorithm",
    "ts",
    "signed_body"
  ],
  "additionalProperties": false,
  "properties": {
    "receipt_id": {
      "type": "string",
      "pattern": "^r_afir\\.stream_[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",
        "stream_session_id",
        "evidence_digest_sha256",
        "recorded_at",
        "verdict",
        "boundary",
        "stream_profile",
        "segments",
        "segment_leaf_sha256_values",
        "stream_root_sha256",
        "segment_count",
        "duration_ms",
        "elements",
        "outcome"
      ],
      "additionalProperties": false,
      "properties": {
        "receipt_type": {
          "type": "string",
          "const": "afir.stream"
        },
        "schema": {
          "type": "string",
          "const": "r2.0.0"
        },
        "stream_session_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256,
          "pattern": "^[A-Za-z0-9._:-]{1,256}$"
        },
        "evidence_digest_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "SHA-256 of the caller-held evidence bundle this receipt attests was recorded. The service never receives or inspects the underlying evidence, only its digest."
        },
        "recorded_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$"
        },
        "verdict": {
          "type": "object",
          "description": "Service-computed honesty boundary fields. Never caller overridable; recomputed and checked at verify time.",
          "required": [
            "pq_enabled",
            "algorithm_in_use"
          ],
          "additionalProperties": false,
          "properties": {
            "pq_enabled": {
              "type": "boolean",
              "const": false
            },
            "algorithm_in_use": {
              "type": "string",
              "const": "Ed25519"
            }
          }
        },
        "boundary": {
          "type": "string",
          "const": "AFiR-Stream receipt. Attests that a stream_session_id and a caller held audio segment digest were recorded and signed at recorded_at, using Ed25519 today. It does not attest that post quantum signing covers this stream; pq_enabled is fixed to false because this deployment signs with Ed25519, not a post quantum algorithm, and that must never be caller overridable."
        },
        "stream_profile": {
          "type": "object",
          "required": [
            "codec",
            "sample_rate_hz",
            "channels"
          ],
          "additionalProperties": false,
          "properties": {
            "codec": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256,
              "pattern": "^[A-Za-z0-9._:/-]{1,256}$",
              "description": "Declared stream codec."
            },
            "sample_rate_hz": {
              "type": "integer",
              "minimum": 1,
              "maximum": 768000
            },
            "channels": {
              "type": "integer",
              "minimum": 1,
              "maximum": 64
            }
          }
        },
        "segments": {
          "type": "array",
          "minItems": 1,
          "maxItems": 4096,
          "items": {
            "type": "object",
            "required": [
              "sequence",
              "start_ms",
              "end_ms",
              "content_sha256",
              "previous_segment_sha256"
            ],
            "additionalProperties": false,
            "properties": {
              "sequence": {
                "type": "integer",
                "minimum": 0,
                "maximum": 4294967295
              },
              "start_ms": {
                "type": "integer",
                "minimum": 0
              },
              "end_ms": {
                "type": "integer",
                "minimum": 1
              },
              "content_sha256": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$",
                "description": "Digest of the committed segment content."
              },
              "previous_segment_sha256": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$",
                "description": "Prior canonical segment leaf, or the zero digest for the first segment."
              }
            }
          }
        },
        "segment_leaf_sha256_values": {
          "type": "array",
          "minItems": 1,
          "maxItems": 4096,
          "items": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$",
            "description": "One canonical leaf digest."
          },
          "description": "Canonical leaf digest for each segment in supplied order."
        },
        "stream_root_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Canonical root over the ordered segment leaf digests."
        },
        "segment_count": {
          "type": "integer",
          "minimum": 0,
          "maximum": 4096
        },
        "duration_ms": {
          "type": "integer",
          "minimum": 0
        },
        "elements": {
          "type": "array",
          "minItems": 0,
          "maxItems": 3,
          "items": {
            "type": "string",
            "enum": [
              "sequence_gap",
              "time_overlap",
              "chain_break"
            ]
          }
        },
        "outcome": {
          "type": "string",
          "enum": [
            "sealed_contiguous",
            "sealed_with_declared_gaps",
            "inconsistent_stream"
          ]
        }
      }
    }
  }
}
