{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://flow.jig.md/schemas/invocation-contract-0.schema.json",
  "title": "FLOW Invocation Contract/0 descriptor",
  "description": "Structural validator for optional anonymous or exact named invocation contracts. Both disjoint descriptor forms validate, but the initial execution profile supports only the single form. Supplemental JSON/0, schema-graph, offline closure, package and authority checks remain required.",
  "$comment": "Copyright 2026 Victor Duarte and contributors. Licensed under Apache-2.0. Every validation $ref is document-local; identifier URLs are not fetch instructions.",
  "oneOf": [
    {
      "$ref": "#/$defs/singleDescriptor"
    },
    {
      "$ref": "#/$defs/namedDescriptor"
    }
  ],
  "$defs": {
    "contractId": {
      "type": "string",
      "pattern": "^https://(?!(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])(?:/|$))[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+/(?!\\.{1,2}(?:/|$))[a-z0-9._~-]+(?:/(?!\\.{1,2}(?:/|$))[a-z0-9._~-]+)*$(?![\\s\\S])"
    },
    "localName": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$(?![\\s\\S])",
      "maxLength": 64
    },
    "definitionName": {
      "type": "string",
      "pattern": "^[A-Za-z][A-Za-z0-9]{0,63}$(?![\\s\\S])"
    },
    "jsonScalar": {
      "type": ["null", "boolean", "number", "string"]
    },
    "schemaArray": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/flowSchema"
      },
      "minItems": 1
    },
    "stringArray": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "uniqueItems": true
    },
    "flowSchema": {
      "oneOf": [
        {
          "type": "boolean"
        },
        {
          "$ref": "#/$defs/schemaObject"
        }
      ]
    },
    "schemaObject": {
      "type": "object",
      "properties": {
        "$ref": {
          "type": "string",
          "pattern": "^#/\\$defs/[A-Za-z][A-Za-z0-9]{0,63}$(?![\\s\\S])"
        },
        "$comment": {
          "type": "string"
        },
        "title": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "examples": {
          "type": "array"
        },
        "type": {
          "oneOf": [
            {
              "enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
            },
            {
              "type": "array",
              "items": {
                "enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
              },
              "minItems": 1,
              "maxItems": 7,
              "uniqueItems": true
            }
          ]
        },
        "enum": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/jsonScalar"
          }
        },
        "const": {
          "$ref": "#/$defs/jsonScalar"
        },
        "allOf": {
          "$ref": "#/$defs/schemaArray"
        },
        "anyOf": {
          "$ref": "#/$defs/schemaArray"
        },
        "oneOf": {
          "$ref": "#/$defs/schemaArray"
        },
        "not": {
          "$ref": "#/$defs/flowSchema"
        },
        "if": {
          "$ref": "#/$defs/flowSchema"
        },
        "then": {
          "$ref": "#/$defs/flowSchema"
        },
        "else": {
          "$ref": "#/$defs/flowSchema"
        },
        "properties": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/flowSchema"
          }
        },
        "required": {
          "$ref": "#/$defs/stringArray"
        },
        "additionalProperties": {
          "$ref": "#/$defs/flowSchema"
        },
        "minProperties": {
          "type": "integer",
          "minimum": 0
        },
        "maxProperties": {
          "type": "integer",
          "minimum": 0
        },
        "dependentRequired": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/stringArray"
          }
        },
        "dependentSchemas": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/flowSchema"
          }
        },
        "prefixItems": {
          "$ref": "#/$defs/schemaArray"
        },
        "items": {
          "$ref": "#/$defs/flowSchema"
        },
        "contains": {
          "$ref": "#/$defs/flowSchema"
        },
        "minContains": {
          "type": "integer",
          "minimum": 0
        },
        "maxContains": {
          "type": "integer",
          "minimum": 0
        },
        "minItems": {
          "type": "integer",
          "minimum": 0
        },
        "maxItems": {
          "type": "integer",
          "minimum": 0
        },
        "minLength": {
          "type": "integer",
          "minimum": 0
        },
        "maxLength": {
          "type": "integer",
          "minimum": 0
        },
        "minimum": {
          "type": "number"
        },
        "exclusiveMinimum": {
          "type": "number"
        },
        "maximum": {
          "type": "number"
        },
        "exclusiveMaximum": {
          "type": "number"
        }
      },
      "additionalProperties": false
    },
    "inlineFlowSchema": {
      "oneOf": [
        {
          "type": "boolean"
        },
        {
          "$ref": "#/$defs/inlineSchemaObject"
        }
      ]
    },
    "inlineSchemaObject": {
      "type": "object",
      "properties": {
        "$comment": {
          "type": "string"
        },
        "title": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "examples": {
          "type": "array"
        },
        "type": {
          "oneOf": [
            {
              "enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
            },
            {
              "type": "array",
              "items": {
                "enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
              },
              "minItems": 1,
              "maxItems": 7,
              "uniqueItems": true
            }
          ]
        },
        "enum": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/jsonScalar"
          }
        },
        "const": {
          "$ref": "#/$defs/jsonScalar"
        },
        "allOf": {
          "$ref": "#/$defs/inlineSchemaArray"
        },
        "anyOf": {
          "$ref": "#/$defs/inlineSchemaArray"
        },
        "oneOf": {
          "$ref": "#/$defs/inlineSchemaArray"
        },
        "not": {
          "$ref": "#/$defs/inlineFlowSchema"
        },
        "if": {
          "$ref": "#/$defs/inlineFlowSchema"
        },
        "then": {
          "$ref": "#/$defs/inlineFlowSchema"
        },
        "else": {
          "$ref": "#/$defs/inlineFlowSchema"
        },
        "properties": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/inlineFlowSchema"
          }
        },
        "required": {
          "$ref": "#/$defs/stringArray"
        },
        "additionalProperties": {
          "$ref": "#/$defs/inlineFlowSchema"
        },
        "minProperties": {
          "type": "integer",
          "minimum": 0
        },
        "maxProperties": {
          "type": "integer",
          "minimum": 0
        },
        "dependentRequired": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/stringArray"
          }
        },
        "dependentSchemas": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/inlineFlowSchema"
          }
        },
        "prefixItems": {
          "$ref": "#/$defs/inlineSchemaArray"
        },
        "items": {
          "$ref": "#/$defs/inlineFlowSchema"
        },
        "contains": {
          "$ref": "#/$defs/inlineFlowSchema"
        },
        "minContains": {
          "type": "integer",
          "minimum": 0
        },
        "maxContains": {
          "type": "integer",
          "minimum": 0
        },
        "minItems": {
          "type": "integer",
          "minimum": 0
        },
        "maxItems": {
          "type": "integer",
          "minimum": 0
        },
        "minLength": {
          "type": "integer",
          "minimum": 0
        },
        "maxLength": {
          "type": "integer",
          "minimum": 0
        },
        "minimum": {
          "type": "number"
        },
        "exclusiveMinimum": {
          "type": "number"
        },
        "maximum": {
          "type": "number"
        },
        "exclusiveMaximum": {
          "type": "number"
        }
      },
      "additionalProperties": false
    },
    "inlineSchemaArray": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/inlineFlowSchema"
      },
      "minItems": 1
    },
    "contractReference": {
      "type": "string",
      "pattern": "^\\./(?!\\.{1,2}(?:/|$))[^/\\\\\\u0000-\\u001f\\u007f]{1,255}(?:/(?!\\.{1,2}(?:/|$))[^/\\\\\\u0000-\\u001f\\u007f]{1,255}){0,63}$(?![\\s\\S])",
      "maxLength": 1026,
      "$comment": "Descriptor-relative downward path; Unicode 15.1 NFC, UTF-8 byte bounds, immutable package confinement and exact target existence need supplemental checks. Never decode or normalize author references."
    },
    "channelDeclaration": {
      "type": "object",
      "properties": {
        "direction": {
          "enum": ["send", "receive"]
        },
        "required": {
          "type": "boolean"
        },
        "schema": {
          "$ref": "#/$defs/inlineFlowSchema"
        },
        "contract": {
          "$ref": "#/$defs/contractReference"
        },
        "delivery": {
          "enum": ["direct", "broadcast"]
        },
        "start": {
          "enum": ["beginning", "suffix"]
        }
      },
      "required": ["direction"],
      "additionalProperties": false,
      "allOf": [
        {
          "not": {
            "type": "object",
            "properties": {
              "schema": true,
              "contract": true
            },
            "required": ["schema", "contract"]
          }
        },
        {
          "if": {
            "type": "object",
            "properties": {
              "start": true
            },
            "required": ["start"]
          },
          "then": {
            "type": "object",
            "properties": {
              "direction": {
                "const": "receive"
              }
            }
          }
        }
      ]
    },
    "channelDeclarations": {
      "type": "object",
      "propertyNames": {
        "$ref": "#/$defs/localName"
      },
      "additionalProperties": {
        "$ref": "#/$defs/channelDeclaration"
      },
      "maxProperties": 256
    },
    "outcomes": {
      "type": "object",
      "propertyNames": {
        "allOf": [
          {
            "$ref": "#/$defs/localName"
          },
          {
            "not": {
              "enum": ["done", "failed", "cancelled", "error"]
            }
          }
        ]
      },
      "additionalProperties": {
        "type": "string",
        "minLength": 1,
        "maxLength": 16384
      },
      "maxProperties": 256
    },
    "features": {
      "type": "object",
      "propertyNames": {
        "$ref": "#/$defs/localName"
      },
      "additionalProperties": {
        "type": "string",
        "minLength": 1,
        "maxLength": 16384
      },
      "maxProperties": 256
    },
    "attachments": {
      "type": "object",
      "propertyNames": {
        "$ref": "#/$defs/localName"
      },
      "additionalProperties": {
        "enum": ["read", "read-write"]
      },
      "maxProperties": 256
    },
    "definitions": {
      "type": "object",
      "propertyNames": {
        "$ref": "#/$defs/definitionName"
      },
      "additionalProperties": {
        "$ref": "#/$defs/flowSchema"
      },
      "maxProperties": 1024
    },
    "operation": {
      "type": "object",
      "properties": {
        "input": {
          "$ref": "#/$defs/flowSchema"
        },
        "result": {
          "$ref": "#/$defs/flowSchema"
        },
        "outcomes": {
          "$ref": "#/$defs/outcomes"
        },
        "channels": {
          "$ref": "#/$defs/channelDeclarations"
        },
        "attachments": {
          "$ref": "#/$defs/attachments"
        }
      },
      "additionalProperties": false
    },
    "singleDescriptor": {
      "type": "object",
      "properties": {
        "$schema": {
          "const": "https://flow.jig.md/schemas/invocation-contract-0.schema.json"
        },
        "id": {
          "$ref": "#/$defs/contractId"
        },
        "version": {
          "type": "string",
          "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$(?![\\s\\S])"
        },
        "$defs": {
          "$ref": "#/$defs/definitions"
        },
        "features": {
          "$ref": "#/$defs/features"
        },
        "input": {
          "$ref": "#/$defs/flowSchema"
        },
        "result": {
          "$ref": "#/$defs/flowSchema"
        },
        "outcomes": {
          "$ref": "#/$defs/outcomes"
        },
        "channels": {
          "$ref": "#/$defs/channelDeclarations"
        },
        "attachments": {
          "$ref": "#/$defs/attachments"
        }
      },
      "required": ["$schema"],
      "dependentRequired": {
        "id": ["version"],
        "version": ["id"],
        "features": ["id", "version"]
      },
      "additionalProperties": false
    },
    "namedDescriptor": {
      "type": "object",
      "properties": {
        "$schema": {
          "const": "https://flow.jig.md/schemas/invocation-contract-0.schema.json"
        },
        "id": {
          "$ref": "#/$defs/contractId"
        },
        "version": {
          "type": "string",
          "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$(?![\\s\\S])"
        },
        "$defs": {
          "$ref": "#/$defs/definitions"
        },
        "operations": {
          "type": "object",
          "propertyNames": {
            "$ref": "#/$defs/localName"
          },
          "additionalProperties": {
            "$ref": "#/$defs/operation"
          },
          "minProperties": 1,
          "maxProperties": 256
        }
      },
      "required": ["$schema", "operations"],
      "dependentRequired": {
        "id": ["version"],
        "version": ["id"]
      },
      "additionalProperties": false
    }
  }
}
