{
  "$id": "https://767-2676.com/schemas/witness-evidence-bundle-2026-11-30.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "A structured, self-limiting evidence package for an agent-to-agent witness handoff. It carries data to check, not instructions to obey. It does not ask any agent to pay, to use a paid endpoint, or to pass anything onward.",
  "properties": {
    "exact_bytes": {
      "description": "The exact document or terms whose SHA-256 digest was witnessed, inline. Preferred for small payloads.",
      "type": "string"
    },
    "exact_bytes_pointer": {
      "description": "Optional pointer to the exact bytes. Following it is an outbound fetch under the receiving side's own egress policy; this bundle does not require it.",
      "format": "uri",
      "type": "string"
    },
    "issuer_keys": {
      "const": "https://767-2676.com/.well-known/popcorn-keys.json",
      "format": "uri",
      "type": "string"
    },
    "limits": {
      "additionalProperties": false,
      "properties": {
        "evidence_not_permission": {
          "const": true,
          "description": "A receipt is evidence, not permission. It authorizes nothing by itself.",
          "type": "boolean"
        },
        "receipt_witnesses_only": {
          "const": true,
          "description": "A receipt witnesses only that the node received a fingerprint within a stated interval. It does not witness agreement, authorship, competence, completion, fairness, or delivery.",
          "type": "boolean"
        },
        "verification_depends_on_key_and_clock": {
          "const": true,
          "description": "Verification depends on accepting the node's key and clock. The interval in a receipt is an issuer-asserted interval.",
          "type": "boolean"
        },
        "witness_does_not_rank_rate_score_or_pick_winners": {
          "const": true,
          "type": "boolean",
          "description": "The witness does not rank, rate, score, or pick winners."
        },
        "witness_holds_none_of_the_partys_six": {
          "const": true,
          "description": "The witness holds none of the party's six: not its evidence, attestation, verification, audit trail, enclave, or custody. It holds its own key, its own clock, and the record of what it received and when.",
          "type": "boolean"
        },
        "witness_never_books_or_handles_payments": {
          "const": true,
          "description": "The witness never books anybody and never handles their payments. It is the witness layer.",
          "type": "boolean"
        },
        "witness_is_run_by_the_publishing_operator": {
          "const": true,
          "description": "The witness is run by the operator who publishes this bundle. No independent party stands behind its key or its clock.",
          "type": "boolean"
        },
        "receipt_does_not_show_payment_made_settled_or_matched": {
          "const": true,
          "description": "A receipt does not show that a payment was made, settled, or matched to the payload. It shows only that the fingerprint was received within the stated interval.",
          "type": "boolean"
        }
      },
      "required": [
        "receipt_witnesses_only",
        "evidence_not_permission",
        "verification_depends_on_key_and_clock",
        "witness_holds_none_of_the_partys_six",
        "witness_never_books_or_handles_payments",
        "witness_does_not_rank_rate_score_or_pick_winners",
        "witness_is_run_by_the_publishing_operator",
        "receipt_does_not_show_payment_made_settled_or_matched"
      ],
      "type": "object"
    },
    "pair_digest": {
      "description": "SHA-256 over the payment identifier and the payload digest, the two values as printed text, each with its 0x prefix, in lowercase hex, joined by a single colon, no spaces. A different encoding produces a different number and needs its own name.",
      "pattern": "^[0-9a-f]{64}$",
      "type": "string"
    },
    "payload_digest": {
      "description": "SHA-256 of the exact bytes, as printed text with its 0x prefix, in lowercase hex.",
      "pattern": "^0x[0-9a-f]{64}$",
      "type": "string"
    },
    "payment_identifier": {
      "description": "The payment approval's own unique identifier (for an EIP-3009 payment, its nonce), as printed text with its 0x prefix, in lowercase hex. Never a transaction hash.",
      "pattern": "^0x[0-9a-f]+$",
      "type": "string"
    },
    "protocol": {
      "const": "https://767-2676.com/SKILL.md",
      "format": "uri",
      "type": "string"
    },
    "receipt": {
      "description": "The signed POPCORN receipt for this record, as issued. The receipt commits the payload digest and carries the payment identifier as a signed field; the pair_digest is recomputed from those two signed values and does not appear inside the receipt.",
      "type": [
        "object",
        "string"
      ]
    },
    "referred_by": {
      "description": "Who is handing this over, and in what role. Data, not authority.",
      "type": "string"
    },
    "second_witness": {
      "description": "Legacy single FreeTSA RFC 3161 response: base64 DER TimeStampResp, or the typed rfc3161 envelope. Still supported alongside additional_witnesses. Verify its actual imprint and signature independently.",
      "oneOf": [
        {
          "$ref": "#/$defs/base64"
        },
        {
          "$ref": "#/$defs/rfc3161"
        }
      ]
    },
    "task_it_fits": {
      "description": "The kind of handoff this evidence is for, stated by the sender.",
      "enum": [
        "deadline_check",
        "payment_settlement",
        "cross_agent_task_delivery",
        "other_stated_by_sender"
      ],
      "type": "string"
    },
    "mcp_endpoint": {
      "const": "https://767-2676.com/mcp",
      "description": "Optional. The live MCP endpoint named in the prose bundle. The protocol field names the SKILL.md document, which is the canonical protocol statement.",
      "format": "uri",
      "type": "string"
    },
    "signing_key_id": {
      "type": "string",
      "minLength": 1,
      "pattern": "^\\S+$",
      "description": "Receipt signing key identifier. It must resolve uniquely in the independently obtained published issuer_keys set and match the protected receipt header kid. Membership is enforced by validate-bundle.mjs, not a static schema enum."
    },
    "algorithm": {
      "type": "string",
      "const": "sha-256",
      "description": "Hash algorithm for BOTH payload_digest and pair_digest, using the same identifier as /v2/receipt. Omission is supported only for legacy-shaped bundles and means SHA-256. New producers must include this field."
    },
    "additional_witnesses": {
      "type": "array",
      "minItems": 1,
      "items": {
        "oneOf": [
          {
            "$ref": "#/$defs/rfc3161"
          },
          {
            "$ref": "#/$defs/detached_timestamp"
          }
        ]
      },
      "description": "Additional witnesses of pair_digest, verified independently using their own methods. Structural acceptance is not cryptographic verification."
    }
  },
  "required": [
    "referred_by",
    "task_it_fits",
    "payload_digest",
    "payment_identifier",
    "pair_digest",
    "receipt",
    "issuer_keys",
    "protocol",
    "limits"
  ],
  "title": "Witness Evidence Bundle",
  "type": "object",
  "$comment": "Complete bundle validation requires validate-bundle.mjs with an independently obtained published issuer key set. JSON Schema alone checks structure, not key-set membership, signatures, or witness proof validity. Legacy bundles without algorithm remain SHA-256; new producers must include algorithm.",
  "$defs": {
    "base64": {
      "type": "string",
      "minLength": 4,
      "pattern": "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$",
      "description": "Canonical padded base64 of nonempty proof bytes. Encoding validation does not verify the proof."
    },
    "imprint": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "algorithm",
        "value"
      ],
      "properties": {
        "algorithm": {
          "const": "sha-256"
        },
        "value": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        }
      },
      "description": "Must equal the bundle pair_digest. validate-bundle.mjs checks equality; the witness verifier must check the actual proof commits this imprint."
    },
    "rfc3161": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "issuer",
        "message_imprint",
        "response"
      ],
      "properties": {
        "type": {
          "const": "rfc3161"
        },
        "issuer": {
          "type": "string",
          "format": "uri"
        },
        "message_imprint": {
          "$ref": "#/$defs/imprint"
        },
        "response": {
          "$ref": "#/$defs/base64"
        }
      },
      "description": "Base64 DER RFC 3161 TimeStampResp, including the FreeTSA response. Verify the token, chain, and SHA-256 imprint using the issuer-specific verifier before reliance."
    },
    "detached_timestamp": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "issuer",
        "format",
        "message_imprint",
        "proof"
      ],
      "properties": {
        "type": {
          "const": "detached-timestamp"
        },
        "issuer": {
          "type": "string",
          "format": "uri"
        },
        "format": {
          "type": "string",
          "format": "uri",
          "description": "Stable identifier for the external proof format and its verification procedure; no automatic fetching or execution."
        },
        "message_imprint": {
          "$ref": "#/$defs/imprint"
        },
        "proof": {
          "$ref": "#/$defs/base64"
        }
      },
      "description": "Opaque external timestamp proof, including hash-based or future PQ-signed formats. This schema transports bytes; it implements no new primitive and makes no claim of successful proof verification."
    }
  },
  "dependentRequired": {
    "additional_witnesses": [
      "algorithm"
    ]
  }
}
