{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://eips.ethereum.org/assets/eip-8419/schemas/kya-scheme.schema.json",
  "title": "KYA Scheme Descriptor v1",
  "description": "Off-chain descriptor referenced by IKYASchemeRegistry.Scheme.schemeURI. Holds the KYA principle; the chain holds only its address, hash, mode and verifier. Semantics are immutable per schemeId: a changed descriptor is a new scheme with `predecessor` set.",
  "type": "object",
  "required": [
    "type",
    "name",
    "description",
    "version",
    "mode",
    "binding",
    "result",
    "dimensions"
  ],
  "additionalProperties": true,
  "properties": {
    "type": {
      "const": "https://eips.ethereum.org/EIPS/eip-8419#kya-scheme-v1"
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
    },
    "description": {
      "type": "string",
      "minLength": 1
    },
    "version": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
    },
    "mode": {
      "type": "string",
      "enum": [
        "attested",
        "proved"
      ]
    },
    "binding": {
      "type": "string",
      "enum": [
        "identity",
        "controller",
        "instance"
      ],
      "description": "What an assertion under this scheme attaches to: the subject record itself, the party controlling it at issuedAt (invalidated by a controller change / ERC-721 transfer), or a specific code/model/config instance committed to by claimDigest."
    },
    "result": {
      "type": "object",
      "required": [
        "kind"
      ],
      "additionalProperties": false,
      "properties": {
        "kind": {
          "type": "string",
          "enum": [
            "ordered-level",
            "categorical",
            "opaque"
          ],
          "description": "ordered-level: Ordered-Level Profile (level totally ordered, higher is stronger; minLevel and resolve's highest-wins apply). categorical: level is an opaque code from `codes`, compared by equality. opaque: level MUST be 0; the result is what claimDigest commits to. The kind is committed on-chain as Scheme.resultKind (0/1/2 in this order) and MUST match."
        },
        "codes": {
          "type": "object",
          "description": "categorical only: map from level code (decimal string 0-255) to meaning. The set of keys is the complete valid result domain and MUST equal the bits set in the on-chain Scheme.levelMask.",
          "propertyNames": {
            "pattern": "^([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
          },
          "additionalProperties": {
            "type": "string"
          }
        },
        "description": {
          "type": "string",
          "description": "opaque/categorical: what claimDigest commits to and how a relying party interprets it."
        }
      }
    },
    "dimensions": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "pattern": "^[a-z0-9][a-z0-9-]*$"
      },
      "description": "Open vocabulary. Registered initial values: controller-binding, provenance, capability, accountability, behavioral, compliance, runtime-integrity."
    },
    "levels": {
      "type": "object",
      "description": "Ordered-Level Profile only (result.kind == ordered-level). Map from level (decimal string 0-255) to semantics. Level 0 MUST be present and mean 'not verified / failed'. The set of keys is the complete valid result domain and MUST equal the bits set in the on-chain Scheme.levelMask; any other level is refused at admission.",
      "required": [
        "0"
      ],
      "propertyNames": {
        "pattern": "^([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
      },
      "additionalProperties": {
        "type": "object",
        "required": [
          "label"
        ],
        "properties": {
          "label": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "erc8004Response": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100,
            "description": "Value a KYA Bridge SHOULD mirror into the ERC-8004 Validation Registry for this level."
          }
        }
      }
    },
    "evidenceKinds": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "type": "string",
        "pattern": "^[a-z0-9][a-z0-9-]*$"
      },
      "description": "Open vocabulary. Registered initial values: erc8004-reputation, erc8004-validation, vc-jwt, vc-ld, tee-quote, zk-proof, domain-proof, payment-history."
    },
    "issuerPolicy": {
      "type": "object",
      "description": "Declares who may issue under this scheme. Declarative only — the framework does not enforce it.",
      "required": [
        "kind"
      ],
      "properties": {
        "kind": {
          "type": "string",
          "enum": [
            "open",
            "allowlist",
            "staked",
            "governed",
            "verifier-only"
          ]
        },
        "uri": {
          "type": "string",
          "format": "uri"
        },
        "issuers": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^eip155:[0-9]+:0x[0-9a-fA-F]{40}$"
          }
        }
      }
    },
    "circuit": {
      "type": [
        "object",
        "null"
      ],
      "description": "REQUIRED (non-null) when mode == proved.",
      "required": [
        "system",
        "vkHash",
        "publicInputLayout"
      ],
      "properties": {
        "system": {
          "type": "string",
          "examples": [
            "groth16",
            "plonk",
            "stark",
            "semaphore",
            "tee-quote"
          ]
        },
        "vkHash": {
          "type": "string",
          "pattern": "^0x[0-9a-fA-F]{64}$"
        },
        "publicInputLayout": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string"
          },
          "description": "Ordered names of ABI-encoded public inputs. MUST include subjectKey and nullifier. Canonical layout 'kya-public-v1': [subjectKey, nullifier, level, claimDigest, expiresAt, issuerSetRoot, epoch]."
        },
        "publicInputAbi": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Solidity ABI types matching publicInputLayout, e.g. [\"bytes32\",\"bytes32\",\"uint8\",\"bytes32\",\"uint64\",\"bytes32\",\"uint64\"]."
        },
        "nullifierScope": {
          "type": "string",
          "enum": [
            "scheme",
            "scheme-epoch"
          ],
          "default": "scheme",
          "description": "Both scopes are additionally bound to the admission domain the verifier is called with (Section 5): 'scheme' = (schemeId, admissionDomain), 'scheme-epoch' = (schemeId, admissionDomain, epoch)."
        },
        "proofBinding": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Context the PROOF (not the credential) is bound to via public inputs the caller supplies to verify(). MUST include schemeId and admissionDomain.",
          "default": [
            "schemeId",
            "admissionDomain"
          ]
        },
        "epochSeconds": {
          "type": "integer",
          "minimum": 1
        },
        "issuerHiding": {
          "type": "boolean",
          "default": false
        },
        "epochGrace": {
          "type": "integer",
          "minimum": 0,
          "default": 0,
          "description": "How many past epochs a verifier still accepts. The verifier enforces current-epochGrace <= epoch <= current from block.timestamp."
        },
        "issuerSetRoot": {
          "type": "string",
          "pattern": "^0x[0-9a-fA-F]{64}$",
          "description": "Trust anchor the verifier pins (issuer-hiding schemes). A different root is a different verifier and therefore a new scheme version."
        },
        "credentialBinding": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Fields the fact issuer's credential commits to. MUST include schemeId and subjectKey.",
          "default": [
            "subjectKey",
            "schemeId",
            "level",
            "claimDigest",
            "expiresAt",
            "proverCommitment"
          ]
        }
      }
    },
    "predecessor": {
      "type": "string",
      "pattern": "^0x[0-9a-fA-F]{64}$"
    },
    "documentation": {
      "type": "string",
      "format": "uri"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "mode": {
            "const": "proved"
          }
        }
      },
      "then": {
        "required": [
          "circuit"
        ],
        "properties": {
          "circuit": {
            "type": "object"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "result": {
            "properties": {
              "kind": {
                "const": "ordered-level"
              }
            }
          }
        }
      },
      "then": {
        "required": [
          "levels"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "result": {
            "properties": {
              "kind": {
                "const": "categorical"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "result": {
            "required": [
              "codes"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "circuit": {
            "type": "object",
            "properties": {
              "nullifierScope": {
                "const": "scheme-epoch"
              }
            },
            "required": [
              "nullifierScope"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "circuit": {
            "required": [
              "epochSeconds"
            ]
          }
        }
      }
    }
  ]
}
