{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:http6:review-objects:v1",
  "title": "HTTP6 review objects: illustrative typed representations",
  "description": "Review profile only. Semantic and cryptographic checks are independent.",
  "$defs": {
    "rule": {
      "type": "object",
      "properties": {
        "operation": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$"
        },
        "destination": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$"
        },
        "resource": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$"
        },
        "data_class": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$"
        }
      },
      "required": [
        "operation",
        "destination",
        "resource",
        "data_class"
      ],
      "additionalProperties": false
    },
    "allowRule": {
      "type": "object",
      "properties": {
        "operation": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$",
          "not": {
            "const": "*"
          }
        },
        "destination": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$",
          "not": {
            "const": "*"
          }
        },
        "resource": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$",
          "not": {
            "const": "*"
          }
        },
        "data_class": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$",
          "not": {
            "const": "*"
          }
        }
      },
      "required": [
        "operation",
        "destination",
        "resource",
        "data_class"
      ],
      "additionalProperties": false
    },
    "policy": {
      "type": "object",
      "properties": {
        "version": {
          "const": "http6.review-policy.v1"
        },
        "tenant": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$"
        },
        "allow": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/allowRule"
          }
        },
        "deny": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/rule"
          }
        },
        "role_snapshot": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "can_mint": {
          "type": "boolean"
        },
        "max_depth": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "templates": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "pattern": "^[ -~]+$"
          }
        },
        "budget": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "version",
        "tenant",
        "allow",
        "deny",
        "role_snapshot",
        "can_mint",
        "max_depth",
        "templates",
        "budget"
      ],
      "additionalProperties": false
    },
    "request": {
      "type": "object",
      "properties": {
        "tenant": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$"
        },
        "operation": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$"
        },
        "destination": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$"
        },
        "resource": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$"
        },
        "data_class": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$"
        },
        "payload_digest": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "cost": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "tenant",
        "operation",
        "destination",
        "resource",
        "data_class",
        "payload_digest",
        "cost"
      ],
      "additionalProperties": false
    },
    "grant": {
      "type": "object",
      "properties": {
        "version": {
          "const": "http6.review-grant.v1"
        },
        "instance": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "public_key": {
          "type": "string",
          "pattern": "^04[0-9a-f]{128}$"
        },
        "birth_nonce": {
          "type": "string",
          "pattern": "^[0-9a-f]{32}$"
        },
        "parent": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            {
              "type": "null"
            }
          ]
        },
        "root": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "epoch": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "profile": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "issued": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "expires": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "measurement": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$"
        },
        "policy": {
          "$ref": "#/$defs/policy"
        },
        "policy_digest": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        }
      },
      "required": [
        "version",
        "instance",
        "public_key",
        "birth_nonce",
        "parent",
        "root",
        "epoch",
        "profile",
        "issued",
        "expires",
        "measurement",
        "policy",
        "policy_digest"
      ],
      "additionalProperties": false
    },
    "signedGrant": {
      "type": "object",
      "properties": {
        "body": {
          "$ref": "#/$defs/grant"
        },
        "signature": {
          "type": "string",
          "pattern": "^[0-9a-f]+$",
          "minLength": 2
        }
      },
      "required": [
        "body",
        "signature"
      ],
      "additionalProperties": false
    },
    "action": {
      "type": "object",
      "properties": {
        "instance": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "epoch": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "profile": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "policy_digest": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "lineage_digest": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "channel": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$"
        },
        "sequence": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "geometry_digest": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "nonce": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$"
        },
        "expires": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "direction": {
          "const": "request"
        },
        "request": {
          "$ref": "#/$defs/request"
        }
      },
      "required": [
        "instance",
        "epoch",
        "profile",
        "policy_digest",
        "lineage_digest",
        "channel",
        "sequence",
        "geometry_digest",
        "nonce",
        "expires",
        "direction",
        "request"
      ],
      "additionalProperties": false
    },
    "signedAction": {
      "type": "object",
      "properties": {
        "body": {
          "$ref": "#/$defs/action"
        },
        "signature": {
          "type": "string",
          "pattern": "^[0-9a-f]+$",
          "minLength": 2
        }
      },
      "required": [
        "body",
        "signature"
      ],
      "additionalProperties": false
    },
    "assessmentRecord": {
      "type": "object",
      "properties": {
        "requirement_id": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$"
        },
        "scope_id": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$"
        },
        "source_locator": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$"
        },
        "implementation_owner": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$"
        },
        "implementation_ref": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$"
        },
        "methods": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "enum": [
              "examine",
              "interview",
              "test"
            ]
          }
        },
        "expected": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[ -~]+$"
        },
        "observed": {
          "type": [
            "string",
            "null"
          ]
        },
        "evidence_digests": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          }
        },
        "status": {
          "enum": [
            "designed",
            "not_assessed",
            "reviewed"
          ]
        },
        "reviewer": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "requirement_id",
        "scope_id",
        "source_locator",
        "implementation_owner",
        "implementation_ref",
        "methods",
        "expected",
        "observed",
        "evidence_digests",
        "status",
        "reviewer"
      ],
      "additionalProperties": false
    }
  },
  "oneOf": [
    {
      "$ref": "#/$defs/policy"
    },
    {
      "$ref": "#/$defs/request"
    },
    {
      "$ref": "#/$defs/signedGrant"
    },
    {
      "$ref": "#/$defs/signedAction"
    },
    {
      "$ref": "#/$defs/assessmentRecord"
    }
  ]
}
