{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.northset.ai/artifacts/schemas/task-spec-v1-1.schema.json",
  "title": "OCH-1.1 TaskSpec",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "hubContract",
    "taskNonce",
    "chainId",
    "delegator",
    "verifierName",
    "verifierId",
    "input",
    "economics",
    "deadlines",
    "privacy",
    "verifierParams"
  ],
  "properties": {
    "schema": { "const": "openclaw.taskSpec.v1_1" },
    "hubContract": { "$ref": "#/$defs/address" },
    "taskNonce": { "$ref": "#/$defs/bytes32" },
    "chainId": { "$ref": "#/$defs/safeUnsignedInteger" },
    "delegator": {
      "type": "object",
      "additionalProperties": false,
      "required": ["address", "did"],
      "properties": {
        "address": { "$ref": "#/$defs/address" },
        "did": {
          "type": "string",
          "pattern": "^did:pkh:eip155:[0-9]+:0x[0-9a-fA-F]{40}$"
        }
      }
    },
    "verifierName": { "type": "string", "minLength": 1 },
    "verifierId": { "$ref": "#/$defs/bytes32" },
    "input": {
      "type": "object",
      "additionalProperties": false,
      "required": ["plaintextCommitment", "encryptedBlob", "constraints"],
      "properties": {
        "plaintextCommitment": {
          "type": "object",
          "additionalProperties": false,
          "required": ["hashAlg", "hash"],
          "properties": {
            "hashAlg": { "const": "keccak256" },
            "hash": { "$ref": "#/$defs/bytes32" }
          }
        },
        "encryptedBlob": {
          "type": "object",
          "additionalProperties": false,
          "required": ["uri", "encryption"],
          "properties": {
            "uri": { "type": "string", "minLength": 1 },
            "encryption": { "enum": ["xchacha20poly1305", "aes-256-gcm"] }
          }
        },
        "constraints": {
          "type": "object",
          "additionalProperties": false,
          "required": ["maxBytes"],
          "properties": {
            "maxBytes": { "$ref": "#/$defs/safeUnsignedInteger" }
          }
        }
      }
    },
    "economics": {
      "type": "object",
      "additionalProperties": false,
      "required": ["maxRewardUSDC", "minBondUSDC"],
      "properties": {
        "maxRewardUSDC": { "$ref": "#/$defs/uint256NumberOrString" },
        "minBondUSDC": { "$ref": "#/$defs/uint256NumberOrString" }
      }
    },
    "deadlines": {
      "type": "object",
      "additionalProperties": false,
      "required": ["acceptDeadline", "maxComputeWindowSec"],
      "properties": {
        "acceptDeadline": { "$ref": "#/$defs/uint64NumberOrString" },
        "maxComputeWindowSec": { "$ref": "#/$defs/uint64NumberOrString" }
      }
    },
    "privacy": {
      "type": "object",
      "additionalProperties": false,
      "required": ["onChain", "offChain", "logs"],
      "properties": {
        "onChain": { "const": "commitments_only" },
        "offChain": { "const": "encrypted_payloads" },
        "logs": { "const": "no_plaintext" }
      }
    },
    "verifierParams": { "$ref": "#/$defs/jsonObject" }
  },
  "$defs": {
    "address": { "type": "string", "pattern": "^0x[0-9a-fA-F]{40}$" },
    "bytes32": { "type": "string", "pattern": "^0x[0-9a-fA-F]{64}$" },
    "safeUnsignedInteger": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "uint64String": {
      "type": "string",
      "pattern": "^(?:0|[1-9][0-9]{0,18}|1(?:[0-7][0-9]{18}|8(?:[0-3][0-9]{17}|4(?:[0-3][0-9]{16}|4(?:[0-5][0-9]{15}|6(?:[0-6][0-9]{14}|7(?:[0-3][0-9]{13}|4(?:[0-3][0-9]{12}|40(?:[0-6][0-9]{10}|7(?:[0-2][0-9]{9}|3(?:[0-6][0-9]{8}|70(?:[0-8][0-9]{6}|9(?:[0-4][0-9]{5}|5(?:[0-4][0-9]{4}|5(?:0[0-9]{3}|1(?:[0-5][0-9]{2}|6(?:0[0-9]{1}|1(?:[0-4]|5))))))))))))))))))$",
      "maxLength": 20
    },
    "uint256String": {
      "type": "string",
      "pattern": "^(?:0|[1-9][0-9]{0,76}|1(?:0[0-9]{76}|1(?:[0-4][0-9]{75}|5(?:[0-6][0-9]{74}|7(?:[0-8][0-9]{73}|9(?:[0-1][0-9]{72}|20(?:[0-7][0-9]{70}|8(?:[0-8][0-9]{69}|9(?:[0-1][0-9]{68}|2(?:[0-2][0-9]{67}|3(?:[0-6][0-9]{66}|7(?:[0-2][0-9]{65}|3(?:0[0-9]{64}|1(?:[0-5][0-9]{63}|6(?:0[0-9]{62}|1(?:[0-8][0-9]{61}|9(?:[0-4][0-9]{60}|5(?:[0-3][0-9]{59}|4(?:[0-1][0-9]{58}|2(?:[0-2][0-9]{57}|3(?:[0-4][0-9]{56}|5(?:[0-6][0-9]{55}|70(?:[0-8][0-9]{53}|9(?:[0-7][0-9]{52}|8(?:[0-4][0-9]{51}|500(?:[0-7][0-9]{48}|8(?:[0-5][0-9]{47}|6(?:[0-7][0-9]{46}|8(?:[0-6][0-9]{45}|7(?:[0-8][0-9]{44}|90(?:[0-6][0-9]{42}|7(?:[0-7][0-9]{41}|8(?:[0-4][0-9]{40}|5(?:[0-2][0-9]{39}|3(?:[0-1][0-9]{38}|2(?:[0-5][0-9]{37}|6(?:[0-8][0-9]{36}|9(?:[0-8][0-9]{35}|9(?:[0-7][0-9]{34}|8(?:[0-3][0-9]{33}|4(?:[0-5][0-9]{32}|6(?:[0-5][0-9]{31}|6(?:[0-4][0-9]{30}|5(?:[0-5][0-9]{29}|6(?:[0-3][0-9]{28}|40(?:[0-4][0-9]{26}|5(?:[0-5][0-9]{25}|6(?:[0-3][0-9]{24}|40(?:[0-2][0-9]{22}|3(?:[0-8][0-9]{21}|9(?:[0-3][0-9]{20}|4(?:[0-4][0-9]{19}|5(?:[0-6][0-9]{18}|7(?:[0-4][0-9]{17}|5(?:[0-7][0-9]{16}|8(?:[0-3][0-9]{15}|400(?:[0-6][0-9]{12}|7(?:[0-8][0-9]{11}|9(?:0[0-9]{10}|1(?:[0-2][0-9]{9}|3(?:0[0-9]{8}|1(?:[0-1][0-9]{7}|2(?:[0-8][0-9]{6}|9(?:[0-5][0-9]{5}|6(?:[0-2][0-9]{4}|3(?:[0-8][0-9]{3}|9(?:[0-8][0-9]{2}|9(?:[0-2][0-9]{1}|3(?:[0-4]|5)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))$",
      "maxLength": 78
    },
    "uint64NumberOrString": {
      "oneOf": [
        { "$ref": "#/$defs/safeUnsignedInteger" },
        { "$ref": "#/$defs/uint64String" }
      ]
    },
    "uint256NumberOrString": {
      "oneOf": [
        { "$ref": "#/$defs/safeUnsignedInteger" },
        { "$ref": "#/$defs/uint256String" }
      ]
    },
    "jsonObject": {
      "type": "object",
      "additionalProperties": { "$ref": "#/$defs/jsonValue" }
    },
    "jsonValue": {
      "oneOf": [
        { "type": "null" },
        { "type": "boolean" },
        { "type": "string" },
        {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        { "type": "array", "items": { "$ref": "#/$defs/jsonValue" } },
        { "$ref": "#/$defs/jsonObject" }
      ]
    }
  }
}
