{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://dasp-protocol.github.io/dasp/schemas/draft-01/bindings/authority-grant.schema.json",
  "title": "Proposed DASP proof of authority grant",
  "description": "Closed grant structure. Also apply the selected scope schema, exact byte rules, trusted-key checks, and current permission.",
  "oneOf": [
    {
      "$ref": "#/$defs/standing"
    },
    {
      "$ref": "#/$defs/command"
    }
  ],
  "$defs": {
    "standing": {
      "type": "object",
      "properties": {
        "contract": {
          "const": "https://dasp-protocol.github.io/dasp/contracts/proof-of-authority"
        },
        "kind": {
          "const": "standing"
        },
        "grant_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9._:-]{1,128}$"
        },
        "issuer": {
          "type": "string",
          "format": "uri",
          "maxLength": 512
        },
        "signing_key": {
          "type": "string",
          "pattern": "^[A-Za-z0-9._:-]{1,128}$"
        },
        "agent": {
          "type": "string",
          "format": "uri",
          "maxLength": 512
        },
        "authority": {
          "type": "string",
          "format": "uri",
          "maxLength": 512
        },
        "not_before": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "expires_at": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "scope": {
          "type": "object",
          "properties": {
            "actor_id": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,128}$"
            },
            "profile": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uri",
                  "maxLength": 512
                },
                "version": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 128
                }
              },
              "required": [
                "id",
                "version"
              ],
              "additionalProperties": false
            },
            "sessions": {
              "oneOf": [
                {
                  "type": "object",
                  "properties": {
                    "mode": {
                      "const": "listed"
                    },
                    "ids": {
                      "type": "array",
                      "minItems": 1,
                      "maxItems": 64,
                      "uniqueItems": true,
                      "items": {
                        "type": "string",
                        "pattern": "^[A-Za-z0-9._:-]{1,128}$"
                      }
                    }
                  },
                  "required": [
                    "mode",
                    "ids"
                  ],
                  "additionalProperties": false
                },
                {
                  "type": "object",
                  "properties": {
                    "mode": {
                      "const": "actor-profile"
                    }
                  },
                  "required": [
                    "mode"
                  ],
                  "additionalProperties": false
                }
              ]
            },
            "commands": {
              "type": "array",
              "minItems": 1,
              "maxItems": 64,
              "items": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9_.-]{0,127}$"
                  },
                  "input_scope": {
                    "type": "object",
                    "maxProperties": 1024,
                    "additionalProperties": {
                      "$ref": "#/$defs/value"
                    }
                  }
                },
                "required": [
                  "name",
                  "input_scope"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "actor_id",
            "profile",
            "sessions",
            "commands"
          ],
          "additionalProperties": false
        },
        "max_admissions": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "contract",
        "kind",
        "grant_id",
        "issuer",
        "signing_key",
        "agent",
        "authority",
        "not_before",
        "expires_at",
        "scope"
      ],
      "additionalProperties": false
    },
    "command": {
      "type": "object",
      "properties": {
        "contract": {
          "const": "https://dasp-protocol.github.io/dasp/contracts/proof-of-authority"
        },
        "kind": {
          "const": "command"
        },
        "grant_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9._:-]{1,128}$"
        },
        "issuer": {
          "type": "string",
          "format": "uri",
          "maxLength": 512
        },
        "signing_key": {
          "type": "string",
          "pattern": "^[A-Za-z0-9._:-]{1,128}$"
        },
        "agent": {
          "type": "string",
          "format": "uri",
          "maxLength": 512
        },
        "authority": {
          "type": "string",
          "format": "uri",
          "maxLength": 512
        },
        "not_before": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "expires_at": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "target": {
          "type": "object",
          "properties": {
            "session_id": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,128}$"
            },
            "actor_id": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,128}$"
            },
            "profile": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uri",
                  "maxLength": 512
                },
                "version": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 128
                }
              },
              "required": [
                "id",
                "version"
              ],
              "additionalProperties": false
            },
            "command_id": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,128}$"
            },
            "name": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_.-]{0,127}$"
            },
            "input": {
              "type": "object",
              "maxProperties": 1024,
              "additionalProperties": {
                "$ref": "#/$defs/value"
              }
            }
          },
          "required": [
            "session_id",
            "actor_id",
            "profile",
            "command_id",
            "name",
            "input"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "contract",
        "kind",
        "grant_id",
        "issuer",
        "signing_key",
        "agent",
        "authority",
        "not_before",
        "expires_at",
        "target"
      ],
      "additionalProperties": false
    },
    "selection": {
      "type": "object",
      "properties": {
        "contract": {
          "const": "https://dasp-protocol.github.io/dasp/contracts/proof-of-authority"
        },
        "profile": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string",
              "format": "uri",
              "maxLength": 512
            },
            "version": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            }
          },
          "required": [
            "id",
            "version"
          ],
          "additionalProperties": false
        },
        "scope_schema": {
          "type": "string",
          "format": "uri",
          "maxLength": 512
        },
        "commands": {
          "type": "array",
          "minItems": 1,
          "maxItems": 64,
          "items": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_.-]{0,127}$"
              },
              "kind": {
                "enum": [
                  "standing",
                  "command"
                ]
              }
            },
            "required": [
              "name",
              "kind"
            ],
            "additionalProperties": false
          }
        },
        "grant_bytes": {
          "type": "integer",
          "minimum": 1,
          "maximum": 16384
        }
      },
      "required": [
        "contract",
        "profile",
        "scope_schema",
        "commands",
        "grant_bytes"
      ],
      "additionalProperties": false
    },
    "value": {
      "anyOf": [
        {
          "type": "null"
        },
        {
          "type": "boolean"
        },
        {
          "type": "string"
        },
        {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        {
          "type": "array",
          "maxItems": 1024,
          "items": {
            "$ref": "#/$defs/value"
          }
        },
        {
          "type": "object",
          "maxProperties": 1024,
          "additionalProperties": {
            "$ref": "#/$defs/value"
          }
        }
      ]
    },
    "extension": {
      "type": "string",
      "maxLength": 21933,
      "pattern": "^(recover|[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]{86})$"
    }
  }
}
