{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://specs.opena2a.org/schemas/atx/atx-credential-v1.1.schema.json",
  "title": "ATX credential (wire form, versions 1.0 and 1.1)",
  "description": "Structural schema for the ATX credential as it appears on the wire, derived from atx-spec core.md sections 1.1, 1.3a, and 1.5 with the atx-conformance fixture set as ground truth. Validates shape only: signature verification, canonical-form byte rules (section 1.3a), and revocation state are verifier concerns a schema cannot express.",
  "type": "object",
  "required": [
    "id",
    "atcVersion",
    "agentId",
    "agentDid",
    "publisher",
    "publisherDid",
    "version",
    "contentHash",
    "buildAttestation",
    "transparencyLogIndex",
    "capabilities",
    "scanSummary",
    "trustScore",
    "trustLevel",
    "issuedAt",
    "expiresAt",
    "issuerDid",
    "issuerChain",
    "signatures",
    "revoked",
    "createdAt"
  ],
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid",
      "description": "Issuance identifier. Excluded from the to-be-signed projection (section 1.3a.2)."
    },
    "atcVersion": {
      "enum": ["1.0", "1.1"],
      "description": "Wire name of the version field (section 1.1). Selects the canonical signing form: 1.0 legacy eleven-field string (section 1.3a.1), 1.1 JCS-canonicalized TBS object (section 1.3a.2). The registered version set is governed by section 14."
    },
    "agentId": { "type": "string", "minLength": 1 },
    "agentDid": { "$ref": "#/$defs/did" },
    "publisher": { "type": "string", "minLength": 1 },
    "publisherDid": { "$ref": "#/$defs/did" },
    "version": {
      "type": "string",
      "minLength": 1,
      "description": "Version of the agent artifact the credential attests, not of ATX itself."
    },
    "contentHash": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$",
      "description": "SHA-256 of the agent content, lowercase hex without a prefix (fixture-pinned wire form)."
    },
    "buildAttestation": {
      "type": "string",
      "minLength": 1,
      "description": "Build attestation reference; production issuance emits a provenance URI."
    },
    "transparencyLogIndex": {
      "type": "integer",
      "minimum": 0,
      "description": "Dead field, never populated with a live log position; excluded from the TBS (section 1.3a.2)."
    },
    "capabilities": {
      "type": "array",
      "items": { "type": "string", "pattern": "^[a-z0-9_-]+:[A-Za-z0-9_.*-]+$" },
      "description": "namespace:operation capability tokens (section 14 registry)."
    },
    "declaredPurpose": {
      "oneOf": [
        {
          "type": "object",
          "maxProperties": 0,
          "description": "Empty object: treated as absent (section 1.3a.2 rule 5) - tolerated on the wire, omitted from the TBS."
        },
        { "$ref": "#/$defs/declaredPurpose" }
      ]
    },
    "behavioralProfile": {
      "type": "object",
      "required": ["checksum", "generatedAt", "observationDays"],
      "properties": {
        "checksum": { "type": "string", "pattern": "^sha256:.+" },
        "generatedAt": { "type": "string", "format": "date-time" },
        "observationDays": { "type": "integer", "minimum": 0 }
      },
      "additionalProperties": false
    },
    "scanSummary": {
      "type": "object",
      "required": ["hma", "criticalFindings", "highFindings", "secretless", "cryptoServe", "oasbLevel"],
      "description": "All six members must be present, zero-valued where unknown (section 1.3a.2 rule 2).",
      "properties": {
        "hma": { "type": "string" },
        "criticalFindings": { "type": "integer", "minimum": 0 },
        "highFindings": { "type": "integer", "minimum": 0 },
        "secretless": { "type": "string" },
        "cryptoServe": { "type": "string" },
        "oasbLevel": { "type": "string", "pattern": "^L[0-9]$" }
      },
      "additionalProperties": false
    },
    "trustScore": {
      "type": "number",
      "minimum": 0,
      "maximum": 100,
      "description": "0-100 scale JSON number on the wire; string-encoded %.6f only inside the v1.1 TBS projection (section 1.3a.2 rule 3)."
    },
    "trustLevel": { "type": "integer", "minimum": 0, "maximum": 4 },
    "issuedAt": { "type": "string", "format": "date-time" },
    "expiresAt": { "type": "string", "format": "date-time" },
    "issuerDid": { "$ref": "#/$defs/did" },
    "issuerChain": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/did" },
      "description": "Root-first, order-significant (section 1.3a.2 rule 4)."
    },
    "signatures": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["keyId", "algorithm", "value"],
        "properties": {
          "keyId": { "type": "string", "minLength": 1 },
          "algorithm": { "enum": ["Ed25519", "ML-DSA-65"] },
          "value": { "type": "string", "pattern": "^[A-Za-z0-9+/]+={0,2}$" }
        },
        "additionalProperties": false
      }
    },
    "revoked": { "type": "boolean" },
    "revokedAt": { "type": "string", "format": "date-time" },
    "revocationReason": { "type": "string" },
    "createdAt": { "type": "string", "format": "date-time" }
  },
  "additionalProperties": false,
  "$defs": {
    "did": {
      "type": "string",
      "pattern": "^did:[a-z0-9]+:[A-Za-z0-9._:@/-]+(#[A-Za-z0-9._-]+)?$"
    },
    "declaredPurpose": {
      "type": "object",
      "description": "Optional ATX 1.1 field (section 1.5). Identity and attestation property, never an authorization input.",
      "required": ["vocabVersion", "statement", "category", "taskScopes", "capabilityJustification"],
      "properties": {
        "vocabVersion": { "type": "string", "minLength": 1 },
        "statement": { "type": "string", "minLength": 1, "maxLength": 280 },
        "category": {
          "anyOf": [
            {
              "enum": [
                "customer-support",
                "financial-operations",
                "data-analysis",
                "data-engineering",
                "software-development",
                "devops-automation",
                "security-operations",
                "content-generation",
                "research-assistant",
                "sales-marketing",
                "hr-people-ops",
                "legal-compliance",
                "healthcare-clinical",
                "device-control",
                "agent-orchestration"
              ]
            },
            {
              "type": "string",
              "pattern": "^[a-z0-9-]+\\.[a-z0-9-]+$",
              "description": "org.name custom category (section 1.5.3): defaults to the broadest, most sensitive class until reviewed."
            }
          ]
        },
        "taskScopes": {
          "type": "array",
          "minItems": 1,
          "items": { "type": "string", "pattern": "^[a-z0-9_-]+:[A-Za-z0-9_.-]+$" }
        },
        "capabilityJustification": {
          "type": "object",
          "description": "Keys must be a subset of the granted capability set (section 1.5.2) — a cross-field rule the verifier enforces.",
          "additionalProperties": {
            "type": "array",
            "minItems": 1,
            "items": { "type": "string" }
          }
        },
        "autonomy": { "enum": ["supervised", "human_in_loop", "autonomous"] },
        "dataScopes": { "type": "array", "items": { "type": "string" } },
        "egressScopes": { "type": "array", "items": { "type": "string" } }
      },
      "additionalProperties": false
    }
  }
}
