{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://xcim.org/schemas/c01/consent.schema.json",
  "$comment": "Local draft candidate. Structural validation is insufficient; see CONTRACT.txt.",
  "$defs": {
    "jws": {
      "type": "object",
      "properties": {
        "protected": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]+$"
        },
        "payload": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]+$"
        },
        "signature": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{86}$"
        }
      },
      "required": [
        "protected",
        "payload",
        "signature"
      ],
      "additionalProperties": false
    },
    "protected": {
      "type": "object",
      "properties": {
        "alg": {
          "const": "Ed25519"
        },
        "kid": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200,
          "pattern": "^[\\x20-\\x7e]+$"
        },
        "typ": {
          "const": "application/xcim-consent+json"
        }
      },
      "required": [
        "alg",
        "kid",
        "typ"
      ],
      "additionalProperties": false
    },
    "sender": {
      "type": "object",
      "properties": {
        "profile": {
          "const": "xcim-consent-01"
        },
        "kind": {
          "const": "sender"
        },
        "issuer": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "^https://[!-~]+$"
        },
        "sender_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "^https://[!-~]+$"
        },
        "sender_epoch": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 4096
        },
        "scope": {
          "type": "string",
          "minLength": 1,
          "maxLength": 4096
        },
        "entity_evidence_commitment": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{43}$"
        },
        "issued_at": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "expires_at": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "profile",
        "kind",
        "issuer",
        "sender_id",
        "sender_epoch",
        "name",
        "scope",
        "entity_evidence_commitment",
        "issued_at",
        "expires_at"
      ],
      "additionalProperties": false
    },
    "consent": {
      "type": "object",
      "properties": {
        "profile": {
          "const": "xcim-consent-01"
        },
        "kind": {
          "const": "consent"
        },
        "issuer": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "^https://[!-~]+$"
        },
        "consent_id": {
          "type": "string",
          "pattern": "^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
        },
        "sender_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "^https://[!-~]+$"
        },
        "sender_epoch": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991
        },
        "sender_binding_commitment": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{43}$"
        },
        "address_profile": {
          "const": "ascii-idna15-1"
        },
        "recipient_salt": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{43}$"
        },
        "recipient_commitment": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{43}$"
        },
        "types": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "type_id": {
                "type": "string",
                "minLength": 1,
                "maxLength": 512,
                "pattern": "^https://[!-~]+$"
              },
              "version": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              },
              "title": {
                "type": "string",
                "minLength": 1,
                "maxLength": 4096
              },
              "description": {
                "type": "string",
                "minLength": 1,
                "maxLength": 4096
              }
            },
            "required": [
              "type_id",
              "version",
              "title",
              "description"
            ],
            "additionalProperties": false
          },
          "minItems": 1,
          "maxItems": 64,
          "uniqueItems": true
        },
        "notice": {
          "type": "object",
          "properties": {
            "language": {
              "type": "string",
              "minLength": 1,
              "maxLength": 35,
              "pattern": "^[\\x20-\\x7e]+$"
            },
            "text": {
              "type": "string",
              "minLength": 1,
              "maxLength": 4096
            }
          },
          "required": [
            "language",
            "text"
          ],
          "additionalProperties": false
        },
        "control": {
          "type": "object",
          "properties": {
            "method": {
              "const": "oidc-01"
            },
            "policy_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 512,
              "pattern": "^https://[!-~]+$"
            },
            "observed_at": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "evidence_commitment": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{43}$"
            }
          },
          "required": [
            "method",
            "policy_id",
            "observed_at",
            "evidence_commitment"
          ],
          "additionalProperties": false
        },
        "decision": {
          "const": "explicit_consent"
        },
        "accepted_at": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "issued_at": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "expires_at": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "profile",
        "kind",
        "issuer",
        "consent_id",
        "sender_id",
        "sender_epoch",
        "sender_binding_commitment",
        "address_profile",
        "recipient_salt",
        "recipient_commitment",
        "types",
        "notice",
        "control",
        "decision",
        "accepted_at",
        "issued_at",
        "expires_at"
      ],
      "additionalProperties": false
    },
    "revocation": {
      "type": "object",
      "properties": {
        "profile": {
          "const": "xcim-consent-01"
        },
        "kind": {
          "const": "revocation"
        },
        "issuer": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "^https://[!-~]+$"
        },
        "event_id": {
          "type": "string",
          "pattern": "^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
        },
        "consent_id": {
          "type": "string",
          "pattern": "^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
        },
        "consent_commitment": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{43}$"
        },
        "sequence": {
          "type": "integer",
          "minimum": 1,
          "maximum": 64
        },
        "previous_event_commitment": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{43}$"
        },
        "type_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 512,
            "pattern": "^https://[!-~]+$"
          },
          "minItems": 1,
          "maxItems": 64,
          "uniqueItems": true
        },
        "actor": {
          "enum": [
            "recipient",
            "sender",
            "attester"
          ]
        },
        "method": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64,
          "pattern": "^[A-Za-z0-9._-]+$"
        },
        "evidence_commitment": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{43}$"
        },
        "requested_at": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "effective_at": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "issued_at": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "profile",
        "kind",
        "issuer",
        "event_id",
        "consent_id",
        "consent_commitment",
        "sequence",
        "previous_event_commitment",
        "type_ids",
        "actor",
        "method",
        "evidence_commitment",
        "requested_at",
        "effective_at",
        "issued_at"
      ],
      "additionalProperties": false
    },
    "status": {
      "type": "object",
      "properties": {
        "profile": {
          "const": "xcim-consent-01"
        },
        "kind": {
          "const": "status"
        },
        "issuer": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "^https://[!-~]+$"
        },
        "consent_id": {
          "type": "string",
          "pattern": "^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
        },
        "consent_commitment": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{43}$"
        },
        "sender_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "^https://[!-~]+$"
        },
        "sender_epoch": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991
        },
        "sequence": {
          "type": "integer",
          "minimum": 0,
          "maximum": 64
        },
        "event_head": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{43}$"
        },
        "active_type_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 512,
            "pattern": "^https://[!-~]+$"
          },
          "minItems": 0,
          "maxItems": 64,
          "uniqueItems": true
        },
        "this_update": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "next_update": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "profile",
        "kind",
        "issuer",
        "consent_id",
        "consent_commitment",
        "sender_id",
        "sender_epoch",
        "sequence",
        "event_head",
        "active_type_ids",
        "this_update",
        "next_update"
      ],
      "additionalProperties": false
    },
    "anchor_batch": {
      "type": "object",
      "properties": {
        "profile": {
          "const": "xcim-consent-01"
        },
        "kind": {
          "const": "anchor_batch"
        },
        "issuer": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "^https://[!-~]+$"
        },
        "log_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "^https://[!-~]+$"
        },
        "sequence": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991
        },
        "previous_batch_commitment": {
          "oneOf": [
            {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{43}$"
            },
            {
              "type": "null"
            }
          ]
        },
        "created_at": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "leaves": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{43}$"
          },
          "minItems": 1,
          "maxItems": 4096,
          "uniqueItems": true
        }
      },
      "required": [
        "profile",
        "kind",
        "issuer",
        "log_id",
        "sequence",
        "previous_batch_commitment",
        "created_at",
        "leaves"
      ],
      "additionalProperties": false
    },
    "anchor_evidence": {
      "type": "object",
      "properties": {
        "profile_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "^https://[!-~]+$"
        },
        "network_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "^[\\x20-\\x7e]+$"
        },
        "genesis_hash": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "^[\\x20-\\x7e]+$"
        },
        "anchor_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "^[\\x20-\\x7e]+$"
        },
        "block_hash": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "^[\\x20-\\x7e]+$"
        },
        "transaction_hash": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "^[\\x20-\\x7e]+$"
        },
        "record_index": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "batch_commitment": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{43}$"
        },
        "proof": {
          "type": "object"
        }
      },
      "required": [
        "profile_id",
        "network_id",
        "genesis_hash",
        "anchor_id",
        "block_hash",
        "transaction_hash",
        "record_index",
        "batch_commitment",
        "proof"
      ],
      "additionalProperties": false
    },
    "anchor": {
      "type": "object",
      "properties": {
        "batch": {
          "$ref": "#/$defs/jws"
        },
        "evidence": {
          "$ref": "#/$defs/anchor_evidence"
        }
      },
      "required": [
        "batch",
        "evidence"
      ],
      "additionalProperties": false
    },
    "evidence": {
      "type": "object",
      "properties": {
        "profile": {
          "const": "xcim-consent-01"
        },
        "sender": {
          "$ref": "#/$defs/jws"
        },
        "consent": {
          "$ref": "#/$defs/jws"
        },
        "revocations": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/jws"
          },
          "minItems": 0,
          "maxItems": 64,
          "uniqueItems": true
        },
        "status": {
          "$ref": "#/$defs/jws"
        },
        "consent_anchor": {
          "$ref": "#/$defs/anchor"
        },
        "revocation_anchors": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "event_id": {
                "type": "string",
                "pattern": "^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
              },
              "batch": {
                "$ref": "#/$defs/jws"
              },
              "evidence": {
                "$ref": "#/$defs/anchor_evidence"
              }
            },
            "required": [
              "event_id",
              "batch",
              "evidence"
            ],
            "additionalProperties": false
          },
          "minItems": 0,
          "maxItems": 64,
          "uniqueItems": true
        }
      },
      "required": [
        "profile",
        "sender",
        "consent",
        "revocations",
        "status",
        "consent_anchor",
        "revocation_anchors"
      ],
      "additionalProperties": false
    }
  },
  "$ref": "#/$defs/evidence"
}
