{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://trustaccept.com/wire-evidence/schema.json",
  "title": "TrustAccept Wire Evidence Manifest",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "evidenceId",
    "observedAt",
    "exchange",
    "transport",
    "context",
    "source",
    "chain",
    "redaction",
    "claimBoundary"
  ],
  "properties": {
    "schema": {
      "const": "trustaccept.wire-evidence.v1"
    },
    "evidenceId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "observedAt": {
      "type": "string",
      "format": "date-time"
    },
    "exchange": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "request",
        "response",
        "pairSha256"
      ],
      "properties": {
        "request": {
          "$ref": "#/$defs/byteFingerprint"
        },
        "response": {
          "$ref": "#/$defs/byteFingerprint"
        },
        "pairSha256": {
          "$ref": "#/$defs/sha256"
        }
      }
    },
    "transport": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "protocol",
        "method",
        "authority",
        "path",
        "statusCode"
      ],
      "properties": {
        "protocol": {
          "enum": [
            "http/1.1",
            "http/2",
            "grpc",
            "websocket",
            "other"
          ]
        },
        "method": {
          "type": "string",
          "pattern": "^[A-Z]{1,20}$"
        },
        "authority": {
          "type": "string",
          "minLength": 1,
          "maxLength": 253
        },
        "path": {
          "type": "string",
          "pattern": "^/[^?#]*$",
          "maxLength": 512
        },
        "statusCode": {
          "type": "integer",
          "minimum": 100,
          "maximum": 599
        },
        "tlsVersion": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 40
        }
      }
    },
    "context": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "organizationId",
        "environment"
      ],
      "properties": {
        "organizationId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "environment": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "actionId": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 128
        },
        "actorId": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 128
        },
        "targetId": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 128
        },
        "policyId": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 128
        }
      }
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "captureSha256",
        "analyzerReportSha256",
        "frameNumbers"
      ],
      "properties": {
        "captureSha256": {
          "$ref": "#/$defs/sha256"
        },
        "analyzerReportSha256": {
          "anyOf": [
            {
              "$ref": "#/$defs/sha256"
            },
            {
              "type": "null"
            }
          ]
        },
        "frameNumbers": {
          "type": "array",
          "items": {
            "type": "integer",
            "minimum": 1
          },
          "uniqueItems": true,
          "maxItems": 256
        }
      }
    },
    "chain": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "previousReceiptHash"
      ],
      "properties": {
        "previousReceiptHash": {
          "anyOf": [
            {
              "$ref": "#/$defs/sha256"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "redaction": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "rawRequestStoredInReceipt",
        "rawResponseStoredInReceipt",
        "credentialValuesStoredInReceipt"
      ],
      "properties": {
        "rawRequestStoredInReceipt": {
          "const": false
        },
        "rawResponseStoredInReceipt": {
          "const": false
        },
        "credentialValuesStoredInReceipt": {
          "const": false
        }
      }
    },
    "claimBoundary": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "minItems": 3
    }
  },
  "$defs": {
    "sha256": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "byteFingerprint": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "sha256",
        "byteLength"
      ],
      "properties": {
        "sha256": {
          "$ref": "#/$defs/sha256"
        },
        "byteLength": {
          "type": "integer",
          "minimum": 1
        }
      }
    }
  }
}