{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "swarm-spec.schema.json",
  "title": "SwarmSpec",
  "description": "Off-chain mirror of the on-chain SwarmSpec struct for tooling. The on-chain identifier is specHash = keccak256(abi.encode(spec)); this document is a convenience view and never a substitute for the struct. Field order follows the struct.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "roles",
    "phases",
    "authorities",
    "activation",
    "contributions",
    "minMembers",
    "maxMembers",
    "recruitmentWindow",
    "maxDuration",
    "inactivityTimeout",
    "ineligibleGrace",
    "settlementWindow",
    "amendmentExitWindow",
    "descriptorHash"
  ],
  "properties": {
    "roles": {
      "type": "array",
      "minItems": 1,
      "maxItems": 32,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "roleId",
          "min",
          "max",
          "eligibility",
          "selfJoin"
        ],
        "properties": {
          "roleId": {
            "$ref": "#/$defs/bytes32",
            "description": "Unique within the spec. keccak256 of a dotted name by convention; sai.role.* names are reserved conventions, sai.role.initiator is the initiator's role when the spec has one"
          },
          "roleName": {
            "type": "string",
            "description": "Informative; roleId SHOULD equal keccak256 of this name"
          },
          "min": {
            "$ref": "#/$defs/uint32",
            "description": "Active members required for activation; 0 = none"
          },
          "max": {
            "$ref": "#/$defs/uint32",
            "description": "Seats (active + suspended); 0 = unbounded"
          },
          "eligibility": {
            "$ref": "#/$defs/address",
            "description": "IEligibility module consulted at admission and on challenge; zero = none"
          },
          "selfJoin": {
            "type": "boolean",
            "description": "May an eligible account join without the ADMIT authority during an OPEN phase"
          }
        }
      }
    },
    "phases": {
      "type": "array",
      "minItems": 1,
      "maxItems": 32,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "payoff",
          "topology",
          "coordination",
          "boundary",
          "admission",
          "inputWindow",
          "descriptorHash"
        ],
        "properties": {
          "name": {
            "$ref": "#/$defs/bytes32",
            "description": "Label (a short string left-aligned in bytes32)"
          },
          "payoff": {
            "$ref": "#/$defs/bytes32",
            "description": "A registered term under keccak256(\"sai.dimension.payoff\"). Base terms: keccak256 of sai.payoff.shared | sai.payoff.exclusive | sai.payoff.mixed"
          },
          "topology": {
            "$ref": "#/$defs/bytes32",
            "description": "A registered term under keccak256(\"sai.dimension.topology\"). Base terms: keccak256 of sai.topology.redundant | partitioned | sequential | hierarchical | iterative | free"
          },
          "coordination": {
            "$ref": "#/$defs/bytes32",
            "description": "A registered term under keccak256(\"sai.dimension.coordination\"). Base terms: keccak256 of sai.coordination.leader | collective | market | automated | none"
          },
          "payoffName": {
            "type": "string",
            "description": "Informative; the dotted name whose keccak256 is payoff"
          },
          "topologyName": {
            "type": "string",
            "description": "Informative; the dotted name whose keccak256 is topology"
          },
          "coordinationName": {
            "type": "string",
            "description": "Informative; the dotted name whose keccak256 is coordination"
          },
          "boundary": {
            "enum": [
              "OPEN",
              "GATED",
              "CLOSED"
            ]
          },
          "admission": {
            "enum": [
              "RECRUIT",
              "INHERIT",
              "SELECT"
            ],
            "description": "Phase 0 MUST be RECRUIT"
          },
          "inputWindow": {
            "$ref": "#/$defs/uint64",
            "description": "Seconds from phase start during which admissions and contributions are accepted; 0 = unbounded"
          },
          "descriptorHash": {
            "$ref": "#/$defs/bytes32",
            "description": "Informative; SHA-256 of the JCS form of the phase descriptor in the Swarm Pack, or zero"
          }
        }
      }
    },
    "authorities": {
      "type": "array",
      "minItems": 16,
      "maxItems": 16,
      "description": "Indexed by DecisionPoint: ACTIVATE, ABORT, SUSPEND, RESUME, ADVANCE, CONCLUDE, DISSOLVE, SUCCEED, ADMIT, REMOVE, REINSTATE, AMEND, ATTACH, DETACH, SET_ACCOUNT, REPRESENT",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "kind",
          "target",
          "roleId"
        ],
        "properties": {
          "kind": {
            "enum": [
              "NONE",
              "ADDRESS",
              "ROLE",
              "ANY_MEMBER",
              "INITIATOR"
            ]
          },
          "target": {
            "$ref": "#/$defs/address",
            "description": "ADDRESS: the holder at formation; otherwise zero"
          },
          "roleId": {
            "$ref": "#/$defs/bytes32",
            "description": "ROLE: the role; otherwise zero"
          }
        }
      }
    },
    "activation": {
      "enum": [
        "ROSTER_MET",
        "AUTHORITY",
        "BOTH"
      ]
    },
    "contributions": {
      "enum": [
        "DISABLED",
        "MEMBERS",
        "OPEN"
      ],
      "description": "Who may record contributions: nobody, active and suspended members, or anyone (non-member records are flagged)"
    },
    "minMembers": {
      "$ref": "#/$defs/uint32",
      "minimum": 1
    },
    "maxMembers": {
      "$ref": "#/$defs/uint32",
      "description": "Seats (active + suspended); 0 = unbounded"
    },
    "recruitmentWindow": {
      "$ref": "#/$defs/uint64",
      "minimum": 1,
      "description": "Seconds after formation (and after a phase start in a RECRUIT phase) before anyone may enforce the roster; MUST be > 0"
    },
    "maxDuration": {
      "$ref": "#/$defs/uint64",
      "description": "Hard cap from activation; 0 = none. At least one of maxDuration and inactivityTimeout MUST be > 0"
    },
    "inactivityTimeout": {
      "$ref": "#/$defs/uint64",
      "description": "Anyone may suspend, then conclude, after this much inactivity; 0 = disabled"
    },
    "ineligibleGrace": {
      "$ref": "#/$defs/uint64",
      "description": "After this long in SUSPENDED(INELIGIBLE), anyone may expel"
    },
    "settlementWindow": {
      "$ref": "#/$defs/uint64",
      "description": "After this long in CONCLUDING, anyone may dissolve"
    },
    "amendmentExitWindow": {
      "$ref": "#/$defs/uint64",
      "description": "Members may leave without consequence for this long after a material amendment"
    },
    "descriptorHash": {
      "$ref": "#/$defs/bytes32",
      "description": "Informative; SHA-256 of the JCS form of the spec description in the Swarm Pack, or zero"
    }
  },
  "$defs": {
    "bytes32": {
      "type": "string",
      "pattern": "^0x[0-9a-f]{64}$"
    },
    "address": {
      "type": "string",
      "pattern": "^0x[0-9a-fA-F]{40}$"
    },
    "uint32": {
      "type": "integer",
      "minimum": 0,
      "maximum": 4294967295
    },
    "uint64": {
      "type": "integer",
      "minimum": 0,
      "maximum": 18446744073709551615
    }
  }
}
