{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/afir-s3-v2.json",
  "title": "AFiR-S3 (Agentic Receipts) v1",
  "description": "AFiR-S3 agentic receipt. Attests that a segment_id, a caller declared lifecycle stage, and a caller held storage-reference digest were recorded and signed at recorded_at. It does not attest that the referenced tool scope, action, or reward attribution actually executed as declared; that determination remains with whatever system originated the underlying agent trajectory.",
  "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\\.s3_[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",
        "segment_id",
        "evidence_digest_sha256",
        "recorded_at",
        "verdict",
        "boundary",
        "lifecycle_stage",
        "scope_sha256",
        "input_sha256",
        "output_sha256",
        "tool_call_sha256",
        "memory_before_sha256",
        "memory_after_sha256",
        "stage_observed_at",
        "stage_ordinal",
        "transition_sha256",
        "elements",
        "outcome"
      ],
      "additionalProperties": false,
      "properties": {
        "receipt_type": {
          "type": "string",
          "const": "afir.s3"
        },
        "schema": {
          "type": "string",
          "const": "r2.0.0"
        },
        "segment_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": [
            "canon_anchor_fixed"
          ],
          "additionalProperties": false,
          "properties": {
            "canon_anchor_fixed": {
              "type": "boolean",
              "const": true
            }
          }
        },
        "boundary": {
          "type": "string",
          "const": "AFiR-S3 agentic receipt. Attests that a segment_id, a caller declared lifecycle stage, and a caller held storage-reference digest were recorded and signed at recorded_at. It does not attest that the referenced tool scope, action, or reward attribution actually executed as declared; that determination remains with whatever system originated the underlying agent trajectory."
        },
        "lifecycle_stage": {
          "type": "string",
          "enum": [
            "scope_declared",
            "action_executed",
            "memory_mutated",
            "reward_attributed"
          ]
        },
        "scope_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Digest of the declared stage scope."
        },
        "input_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Digest of the state entering this stage."
        },
        "output_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Digest of the state emitted by this stage."
        },
        "tool_call_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Digest of the declared tool call, or the zero digest when no tool call is observed."
        },
        "memory_before_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Digest of memory before the stage."
        },
        "memory_after_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Digest of memory after the stage."
        },
        "stage_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": "Instant this lifecycle stage was observed."
        },
        "parent_transition": {
          "type": "object",
          "required": [
            "receipt_id",
            "segment_id",
            "lifecycle_stage",
            "transition_sha256",
            "output_sha256",
            "memory_after_sha256"
          ],
          "additionalProperties": false,
          "properties": {
            "receipt_id": {
              "type": "string",
              "pattern": "^r_afir\\.s3_[0-9]{10,}_[0-9a-f]{12}$"
            },
            "segment_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256,
              "pattern": "^[A-Za-z0-9._:/-]{1,256}$",
              "description": "Identifier carried by the parent transition."
            },
            "lifecycle_stage": {
              "type": "string",
              "enum": [
                "scope_declared",
                "action_executed",
                "memory_mutated"
              ]
            },
            "transition_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$",
              "description": "Canonical transition digest carried by the parent receipt."
            },
            "output_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$",
              "description": "Output state digest carried by the parent receipt."
            },
            "memory_after_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$",
              "description": "Memory digest carried after the parent transition."
            }
          }
        },
        "stage_ordinal": {
          "type": "integer",
          "minimum": 0,
          "maximum": 3
        },
        "transition_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Canonical digest of this declared transition."
        },
        "elements": {
          "type": "array",
          "minItems": 0,
          "maxItems": 3,
          "items": {
            "type": "string",
            "enum": [
              "required_stage_evidence_missing",
              "parent_stage_mismatch",
              "state_link_mismatch"
            ]
          }
        },
        "outcome": {
          "type": "string",
          "enum": [
            "stage_consistent",
            "stage_incomplete",
            "chain_mismatch"
          ]
        }
      }
    }
  }
}
