{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://xcim.org/schemas/wd-02/0.2/issuer-metadata.schema.json",
  "title": "XCIM WD-02 Issuer Metadata Payload 0.2",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "xcim_version",
    "object_type",
    "issuer",
    "issuer_id",
    "metadata_epoch",
    "issued_at",
    "valid_from",
    "valid_until",
    "xcim_versions",
    "issuance_profiles_supported",
    "jwks_uri",
    "status_endpoint",
    "transparency_log",
    "batch_mirrors",
    "anchor_networks",
    "supported_identity_assurance",
    "policy_uri",
    "security_contact",
    "accreditation_reference"
  ],
  "properties": {
    "xcim_version": {
      "const": "0.2"
    },
    "object_type": {
      "const": "issuer_metadata"
    },
    "issuer": {
      "type": "string",
      "format": "uri",
      "pattern": "^https://"
    },
    "issuer_id": {
      "type": "string",
      "pattern": "^urn:xcim:issuer:[A-Za-z0-9._~:-]+$"
    },
    "metadata_epoch": {
      "$ref": "#/$defs/positive"
    },
    "issued_at": {
      "$ref": "#/$defs/dateTime"
    },
    "valid_from": {
      "$ref": "#/$defs/dateTime"
    },
    "valid_until": {
      "$ref": "#/$defs/dateTime"
    },
    "xcim_versions": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "enum": [
          "0.1",
          "0.2"
        ]
      }
    },
    "issuance_profiles_supported": {
      "type": "array",
      "minItems": 1,
      "maxItems": 2,
      "uniqueItems": true,
      "items": {
        "enum": [
          "oidc_hosted_consent",
          "evp_hosted_consent"
        ]
      }
    },
    "jwks_uri": {
      "$ref": "#/$defs/httpsUri"
    },
    "consent_endpoint": {
      "$ref": "#/$defs/httpsUri"
    },
    "revocation_endpoint": {
      "$ref": "#/$defs/httpsUri"
    },
    "status_endpoint": {
      "$ref": "#/$defs/httpsUri"
    },
    "transparency_log": {
      "$ref": "#/$defs/httpsUri"
    },
    "batch_mirrors": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "$ref": "#/$defs/httpsUri"
      }
    },
    "anchor_networks": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "network",
          "contract"
        ],
        "properties": {
          "network": {
            "type": "string",
            "pattern": "^eip155:[1-9][0-9]*$"
          },
          "contract": {
            "type": "string",
            "pattern": "^0x[0-9a-fA-F]{40}$"
          }
        }
      }
    },
    "supported_identity_assurance": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "pattern": "^[a-z][a-z0-9_]*$"
      }
    },
    "policy_uri": {
      "$ref": "#/$defs/httpsUri"
    },
    "security_contact": {
      "type": "string",
      "format": "uri",
      "pattern": "^mailto:"
    },
    "accreditation_reference": {
      "oneOf": [
        {
          "type": "null"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "registry",
            "accreditation_id",
            "accreditation_epoch",
            "entry_uri"
          ],
          "properties": {
            "registry": {
              "$ref": "#/$defs/httpsUri"
            },
            "accreditation_id": {
              "type": "string",
              "pattern": "^urn:xcim:accreditation:[A-Za-z0-9._~-]+$"
            },
            "accreditation_epoch": {
              "$ref": "#/$defs/positive"
            },
            "entry_uri": {
              "$ref": "#/$defs/httpsUri"
            }
          }
        }
      ],
      "description": "Null asserts no registry accreditation. Metadata never establishes initial trust; receivers use independently configured roots."
    }
  },
  "$defs": {
    "positive": {
      "type": "integer",
      "minimum": 1,
      "maximum": 9007199254740991
    },
    "dateTime": {
      "type": "string",
      "format": "date-time"
    },
    "httpsUri": {
      "type": "string",
      "format": "uri",
      "pattern": "^https://"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "issuance_profiles_supported": {
            "contains": {
              "const": "oidc_hosted_consent"
            }
          }
        }
      },
      "then": {
        "properties": {
          "xcim_versions": {
            "contains": {
              "const": "0.1"
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "issuance_profiles_supported": {
            "contains": {
              "const": "evp_hosted_consent"
            }
          }
        }
      },
      "then": {
        "properties": {
          "xcim_versions": {
            "contains": {
              "const": "0.2"
            }
          }
        }
      }
    }
  ]
}
