{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.northset.ai/artifacts/schemas/bid-envelope-v1-1.schema.json",
  "title": "OCH-1.1 signed Bid envelope",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "types", "primaryType", "domain", "message", "digest", "signature", "signer"],
  "properties": {
    "schema": { "const": "openclaw.bidEnvelope.v1_1" },
    "types": {
      "type": "object",
      "required": ["EIP712Domain", "Bid"],
      "properties": {
        "EIP712Domain": {
          "type": "array",
          "minItems": 4,
          "maxItems": 4,
          "prefixItems": [
            { "const": { "name": "name", "type": "string" } },
            { "const": { "name": "version", "type": "string" } },
            { "const": { "name": "chainId", "type": "uint256" } },
            { "const": { "name": "verifyingContract", "type": "address" } }
          ],
          "items": false
        },
        "Bid": {
          "type": "array",
          "minItems": 10,
          "maxItems": 10,
          "prefixItems": [
            { "const": { "name": "taskId", "type": "uint256" } },
            { "const": { "name": "specHash", "type": "bytes32" } },
            { "const": { "name": "verifierId", "type": "bytes32" } },
            { "const": { "name": "delegatee", "type": "address" } },
            { "const": { "name": "rewardUSDC", "type": "uint256" } },
            { "const": { "name": "bondUSDC", "type": "uint256" } },
            { "const": { "name": "computeWindowSec", "type": "uint64" } },
            { "const": { "name": "validUntil", "type": "uint64" } },
            { "const": { "name": "nonce", "type": "uint256" } },
            { "const": { "name": "salt", "type": "bytes32" } }
          ],
          "items": false
        }
      },
      "additionalProperties": false
    },
    "primaryType": { "const": "Bid" },
    "domain": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "version", "chainId", "verifyingContract"],
      "properties": {
        "name": { "const": "OpenclawHub" },
        "version": { "const": "1.1" },
        "chainId": { "$ref": "#/$defs/uint256String" },
        "verifyingContract": { "$ref": "#/$defs/address" }
      }
    },
    "message": {
      "type": "object",
      "additionalProperties": false,
      "required": ["taskId", "specHash", "verifierId", "delegatee", "rewardUSDC", "bondUSDC", "computeWindowSec", "validUntil", "nonce", "salt"],
      "properties": {
        "taskId": { "$ref": "#/$defs/uint256String" },
        "specHash": { "$ref": "#/$defs/bytes32" },
        "verifierId": { "$ref": "#/$defs/bytes32" },
        "delegatee": { "$ref": "#/$defs/address" },
        "rewardUSDC": { "$ref": "#/$defs/uint256String" },
        "bondUSDC": { "$ref": "#/$defs/uint256String" },
        "computeWindowSec": { "$ref": "#/$defs/uint64String" },
        "validUntil": { "$ref": "#/$defs/uint64String" },
        "nonce": { "$ref": "#/$defs/uint256String" },
        "salt": { "$ref": "#/$defs/bytes32" }
      }
    },
    "digest": { "$ref": "#/$defs/bytes32" },
    "signature": {
      "type": "string",
      "description": "Byte-aligned signature data. EOA bids use 65-byte r || s || v signatures; ERC-1271 contract wallets may define another byte format, including an empty preapproval token.",
      "pattern": "^0x(?:[0-9a-fA-F]{2})*$"
    },
    "signer": { "$ref": "#/$defs/address" }
  },
  "$defs": {
    "address": { "type": "string", "pattern": "^0x[0-9a-fA-F]{40}$" },
    "bytes32": { "type": "string", "pattern": "^0x[0-9a-fA-F]{64}$" },
    "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 }
  }
}
