{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://eips.ethereum.org/assets/eip-8419/schemas/kya-policy.schema.json",
  "title": "KYA Policy Descriptor v1",
  "description": "A relying party's requirement over (scheme, level, issuers, anchors) combinations. Referenced by IKYAPolicyRegistry policyURI and by KYAChallenge.policyId.",
  "type": "object",
  "required": [
    "type",
    "require"
  ],
  "properties": {
    "type": {
      "const": "https://eips.ethereum.org/EIPS/eip-8419#kya-policy-v1"
    },
    "name": {
      "type": "string"
    },
    "description": {
      "type": "string"
    },
    "kyaRegistry": {
      "type": "string",
      "pattern": "^eip155:[0-9]+:0x[0-9a-fA-F]{40}$",
      "description": "Registry against which rules are evaluated."
    },
    "require": {
      "$ref": "#/$defs/node"
    },
    "onchain": {
      "type": "object",
      "required": [
        "rulesHash"
      ],
      "additionalProperties": false,
      "description": "Present iff the policy is registered with an executable projection (IKYAPolicyEvaluator). rulesHash MUST equal keccak256(abi.encode(Rule[] allOf)) of the registered projection, and the projection MUST be the document's top-level allOf restricted to ordered-level rules with minLevel and issuers. If the document contains conditions the projection cannot express (anyOf, level equality, anchors), `sufficient` MUST be false.",
      "properties": {
        "evaluator": {
          "type": "string",
          "pattern": "^eip155:[0-9]+:0x[0-9a-fA-F]{40}$"
        },
        "rulesHash": {
          "type": "string",
          "pattern": "^0x[0-9a-fA-F]{64}$"
        },
        "sufficient": {
          "type": "boolean",
          "default": true,
          "description": "true iff on-chain evaluate() of the projection is equivalent to evaluating the whole document."
        }
      }
    }
  },
  "$defs": {
    "rule": {
      "type": "object",
      "required": [
        "schemeId",
        "issuers"
      ],
      "additionalProperties": false,
      "properties": {
        "schemeId": {
          "type": "string",
          "pattern": "^0x[0-9a-fA-F]{64}$"
        },
        "minLevel": {
          "type": "integer",
          "minimum": 0,
          "maximum": 255,
          "description": "ordered-level schemes: minimum acceptable level."
        },
        "issuers": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "pattern": "^0x[0-9a-fA-F]{40}$"
          },
          "description": "Trusted issuer addresses (attesters, or verifier contracts for proved schemes). MUST be non-empty."
        },
        "allowEphemeral": {
          "type": "boolean",
          "default": true,
          "description": "Whether an unrecorded ZK presentation satisfies this rule."
        },
        "level": {
          "type": "integer",
          "minimum": 0,
          "maximum": 255,
          "description": "categorical schemes: the exact code required."
        },
        "anchors": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "pattern": "^0x[0-9a-fA-F]{64}$"
          },
          "description": "Proved schemes: accepted trust anchors (e.g. issuer-set roots). When present, an assertion whose anchor is not listed does not satisfy the rule."
        }
      },
      "oneOf": [
        {
          "required": [
            "minLevel"
          ]
        },
        {
          "required": [
            "level"
          ]
        }
      ]
    },
    "node": {
      "oneOf": [
        {
          "$ref": "#/$defs/rule"
        },
        {
          "type": "object",
          "required": [
            "allOf"
          ],
          "additionalProperties": false,
          "properties": {
            "allOf": {
              "type": "array",
              "minItems": 1,
              "items": {
                "$ref": "#/$defs/node"
              }
            }
          }
        },
        {
          "type": "object",
          "required": [
            "anyOf"
          ],
          "additionalProperties": false,
          "properties": {
            "anyOf": {
              "type": "array",
              "minItems": 1,
              "items": {
                "$ref": "#/$defs/node"
              }
            }
          }
        }
      ]
    }
  }
}
