{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:sitla:wire:1:schema:request-evidence",
  "title": "request-evidence",
  "$comment": "SPDX-License-Identifier: CC0-1.0; structural validity is not authorization",
  "type": "object",
  "properties": {
    "protocol": {
      "const": "sitla-wire/1"
    },
    "operation": {
      "const": "request-evidence"
    },
    "request_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 2048
    },
    "operator_id": {
      "type": "string",
      "pattern": "^https://[^/?#]+(?:/[^?#]*)?$"
    },
    "subject_reference": {
      "type": "string",
      "minLength": 1,
      "maxLength": 2048
    },
    "evidence_level": {
      "enum": [
        "service-json",
        "service-signed",
        "user-signed",
        "issuer-credential",
        "zkp"
      ]
    },
    "audience": {
      "type": "string",
      "minLength": 1,
      "maxLength": 2048
    },
    "purpose": {
      "type": "string",
      "minLength": 1,
      "maxLength": 2048
    },
    "challenge": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_-]+$",
      "minLength": 43,
      "maxLength": 86
    },
    "issued_at": {
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
    },
    "expires_at": {
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
    },
    "policy_digest": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "requirements": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "package_ref": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2048
          },
          "manifest_digest": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "circuit": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2048
          },
          "parameters": {
            "type": "object",
            "maxProperties": 32,
            "additionalProperties": {
              "anyOf": [
                {
                  "type": "string",
                  "maxLength": 2048
                },
                {
                  "type": "integer",
                  "minimum": -9007199254740991,
                  "maximum": 9007199254740991
                },
                {
                  "type": "boolean"
                },
                {
                  "type": "null"
                }
              ]
            }
          }
        },
        "required": [
          "package_ref",
          "manifest_digest",
          "circuit",
          "parameters"
        ],
        "additionalProperties": false
      },
      "maxItems": 16
    }
  },
  "required": [
    "protocol",
    "operation",
    "request_id",
    "operator_id",
    "subject_reference",
    "evidence_level",
    "audience",
    "purpose",
    "challenge",
    "issued_at",
    "expires_at",
    "policy_digest",
    "requirements"
  ],
  "additionalProperties": false,
  "allOf": [
    {
      "if": {
        "properties": {
          "evidence_level": {
            "const": "zkp"
          }
        }
      },
      "then": {
        "properties": {
          "requirements": {
            "minItems": 1,
            "type": "array"
          }
        }
      },
      "else": {
        "properties": {
          "requirements": {
            "maxItems": 0,
            "type": "array"
          }
        }
      }
    }
  ]
}
