{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "autonym_version": {
      "type": "string",
      "const": "1.0"
    },
    "provider": {
      "type": "string",
      "format": "uri"
    },
    "audience": {
      "type": "string",
      "format": "uri"
    },
    "client_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 2048
    },
    "handle": {
      "type": "string",
      "maxLength": 294,
      "pattern": "^autonym:[a-z2-7]{32}@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$"
    },
    "grant_id": {
      "type": "string",
      "pattern": "^gr_[0-7][0-9A-HJKMNP-TV-Z]{25}(?![\\s\\S])"
    },
    "grant_revision": {
      "type": "integer",
      "exclusiveMinimum": 0,
      "maximum": 9007199254740991
    },
    "read_id": {
      "type": "string",
      "pattern": "^rd_[0-7][0-9A-HJKMNP-TV-Z]{25}(?![\\s\\S])"
    },
    "purpose": {
      "type": "string",
      "enum": [
        "booking",
        "recommendation",
        "safety",
        "fulfilment",
        "personalisation",
        "research",
        "care",
        "medical",
        "employment",
        "advertising"
      ]
    },
    "issued_at": {
      "type": "string",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
    },
    "valid_until": {
      "type": "string",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
    },
    "ttl_seconds": {
      "type": "integer",
      "minimum": 0,
      "maximum": 300
    },
    "persist_until": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time",
          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
        },
        {
          "type": "null"
        }
      ]
    },
    "entries": {
      "maxItems": 1000,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^rent_[a-z2-7]{52}$"
          },
          "version": {
            "type": "integer",
            "exclusiveMinimum": 0,
            "maximum": 9007199254740991
          },
          "domain": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_.-]{0,63}$"
          },
          "key": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_.-]{0,63}$"
          },
          "level": {
            "type": "string",
            "enum": [
              "L0",
              "L1",
              "L2",
              "L3"
            ]
          },
          "value_type": {
            "type": "string",
            "enum": [
              "text",
              "number",
              "boolean",
              "enum",
              "list",
              "coded",
              "coded_list",
              "date",
              "date_range",
              "age_band",
              "person_ref",
              "structured",
              "credential"
            ]
          },
          "value": {
            "$ref": "#/$defs/__schema0"
          },
          "context_kind": {
            "type": "string",
            "enum": [
              "fact",
              "preference",
              "state"
            ]
          },
          "safety_critical": {
            "type": "boolean"
          },
          "provenance": {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string",
                "enum": [
                  "declared",
                  "observed",
                  "derived",
                  "attested"
                ]
              },
              "confirmed": {
                "type": "boolean"
              }
            },
            "required": [
              "kind",
              "confirmed"
            ],
            "additionalProperties": false
          },
          "stale": {
            "type": "boolean"
          }
        },
        "required": [
          "id",
          "version",
          "domain",
          "key",
          "level",
          "value_type",
          "value",
          "context_kind",
          "safety_critical",
          "provenance",
          "stale"
        ],
        "additionalProperties": false
      }
    },
    "proof": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "jws"
        },
        "alg": {
          "type": "string",
          "const": "ES256"
        },
        "kid": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$"
        },
        "jws": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]+\\.\\.[A-Za-z0-9_-]+$"
        }
      },
      "required": [
        "type",
        "alg",
        "kid",
        "jws"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "autonym_version",
    "provider",
    "audience",
    "client_id",
    "handle",
    "grant_id",
    "grant_revision",
    "read_id",
    "purpose",
    "issued_at",
    "valid_until",
    "ttl_seconds",
    "persist_until",
    "entries",
    "proof"
  ],
  "additionalProperties": false,
  "$defs": {
    "__schema0": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        },
        {
          "type": "boolean"
        },
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema0"
          }
        },
        {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/$defs/__schema0"
          }
        }
      ]
    }
  }
}
