{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.dharma-ai.io/signing-upgrade-source/v1",
  "title": "Device-signed owner or original-client consumer upgrade source",
  "$defs": {
    "id": { "type": "string", "minLength": 1, "maxLength": 200 },
    "hash": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" },
    "version": { "type": "string", "pattern": "^(0|[1-9][0-9]{0,8})\\.(0|[1-9][0-9]{0,8})\\.(0|[1-9][0-9]{0,8})$" },
    "consumer": { "type": "object", "additionalProperties": false, "required": ["name", "version"], "properties": {
      "name": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,99}$" }, "version": { "$ref": "#/$defs/version" } } },
    "consumers": { "type": "array", "minItems": 2, "maxItems": 20, "items": { "$ref": "#/$defs/consumer" } },
    "common": { "type": "object", "required": ["schema", "organizationId", "globalEpoch", "predecessorHash", "candidateHash", "principalId", "observedAt", "expiresAt", "signature", "sourceHash"],
      "properties": {
        "schema": { "enum": ["dharma.signing-consumer-approval/v1", "dharma.signing-client-upgrade-proof/v1"] },
        "organizationId": { "$ref": "#/$defs/id" }, "globalEpoch": { "type": "string", "minLength": 1, "maxLength": 160 },
        "predecessorHash": { "$ref": "#/$defs/hash" }, "candidateHash": { "$ref": "#/$defs/hash" }, "principalId": { "$ref": "#/$defs/id" },
        "observedAt": { "type": "string", "format": "date-time" }, "expiresAt": { "type": "string", "format": "date-time" },
        "signature": { "type": "string", "pattern": "^[A-Za-z0-9_-]{86}$" }, "sourceHash": { "$ref": "#/$defs/hash" }
      } }
  },
  "oneOf": [
    { "allOf": [{ "$ref": "#/$defs/common" }], "type": "object", "unevaluatedProperties": false,
      "required": ["cliVersion", "contractVersion", "installedKeysetHash"],
      "properties": { "schema": { "const": "dharma.signing-client-upgrade-proof/v1" },
        "cliVersion": { "$ref": "#/$defs/version" }, "contractVersion": { "$ref": "#/$defs/version" }, "installedKeysetHash": { "$ref": "#/$defs/hash" } } },
    { "allOf": [{ "$ref": "#/$defs/common" }], "type": "object", "unevaluatedProperties": false,
      "required": ["baselineConsumers", "requiredConsumers", "requiredClientIds"],
      "properties": { "schema": { "const": "dharma.signing-consumer-approval/v1" },
        "baselineConsumers": { "$ref": "#/$defs/consumers" }, "requiredConsumers": { "$ref": "#/$defs/consumers" },
        "requiredClientIds": { "type": "array", "minItems": 1, "maxItems": 100, "items": { "$ref": "#/$defs/id" } } } }
  ]
}
