{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://mobius.systems/schemas/authority/companion-attestation-v1.0.0.json",
  "title": "Mobius Companion Attestation",
  "description": "Schema for AI Companion attestations in the Mobius Authority Verification flow. Companions act as epistemic witnesses, generating EPICON-compliant justifications for authority requests.",
  "type": "object",
  "required": [
    "version",
    "ledger_id",
    "wallet_signature",
    "epicon_ej_hash",
    "scope",
    "expires_at",
    "risk_level",
    "attested_by",
    "attested_at",
    "signature"
  ],
  "properties": {
    "version": {
      "type": "string",
      "const": "1.0.0",
      "description": "Schema version"
    },
    "ledger_id": {
      "type": "string",
      "format": "uuid",
      "description": "Unique identifier of the entity requesting authority, registered on the Mobius Ledger"
    },
    "wallet_signature": {
      "type": "string",
      "pattern": "^0x[a-fA-F0-9]+$",
      "description": "Hexadecimal signature from the bonded wallet proving economic stake"
    },
    "epicon_ej_hash": {
      "type": "string",
      "pattern": "^sha256:[a-fA-F0-9]{64}$",
      "description": "SHA-256 hash of the EPICON-01 Epistemic Justification document"
    },
    "epicon_ej": {
      "type": "object",
      "description": "Optional: Full EPICON-01 Epistemic Justification object (can be omitted if only hash is needed)",
      "properties": {
        "values": {
          "type": "array",
          "items": { "type": "string" },
          "minItems": 1,
          "description": "Principles invoked for this authority request"
        },
        "reasoning": {
          "type": "string",
          "minLength": 10,
          "description": "Why this authority makes sense in context"
        },
        "anchors": {
          "type": "array",
          "minItems": 2,
          "items": {
            "type": "object",
            "required": ["type", "source", "confidence"],
            "properties": {
              "type": {
                "type": "string",
                "enum": ["policy", "practice", "empirical", "user_values", "domain_norm"],
                "description": "Category of epistemic anchor"
              },
              "source": {
                "type": "string",
                "description": "Reference for this anchor"
              },
              "confidence": {
                "type": "number",
                "minimum": 0,
                "maximum": 1,
                "description": "Confidence score (0-1)"
              }
            }
          },
          "description": "Independent epistemic anchors supporting the request (minimum 2 required)"
        },
        "boundaries": {
          "type": "object",
          "required": ["applies_when", "fails_when"],
          "properties": {
            "applies_when": {
              "type": "array",
              "items": { "type": "string" },
              "minItems": 1,
              "description": "Conditions under which this authority is valid"
            },
            "fails_when": {
              "type": "array",
              "items": { "type": "string" },
              "minItems": 1,
              "description": "Conditions under which this authority should be revoked"
            }
          },
          "description": "Explicit boundaries for authority application"
        },
        "counterfactual": {
          "type": "object",
          "required": ["if_changed", "then"],
          "properties": {
            "if_changed": {
              "type": "string",
              "description": "Alternative state of the world"
            },
            "then": {
              "type": "string",
              "description": "How the authority recommendation would change"
            }
          },
          "description": "Falsifiability statement"
        }
      }
    },
    "scope": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^[a-z]+\\.[a-z]+(\\.[a-z]+)*$"
      },
      "minItems": 1,
      "description": "Permission scopes being attested (e.g., 'api.read', 'api.deploy.staging')",
      "examples": [
        ["api.read"],
        ["api.read", "api.write"],
        ["api.read", "api.deploy.staging"]
      ]
    },
    "expires_at": {
      "type": "string",
      "format": "date-time",
      "description": "ISO-8601 timestamp when this attestation expires (maximum 90 days from creation)"
    },
    "risk_level": {
      "type": "string",
      "enum": ["low", "medium", "high", "critical"],
      "description": "Risk classification for the requested authority"
    },
    "risk_justification": {
      "type": "string",
      "description": "Optional: Explanation of the risk level assessment"
    },
    "attested_by": {
      "type": "string",
      "description": "Identifier of the AI Companion providing this attestation"
    },
    "attested_at": {
      "type": "string",
      "format": "date-time",
      "description": "ISO-8601 timestamp when this attestation was created"
    },
    "signature": {
      "type": "string",
      "pattern": "^[a-zA-Z0-9+/=]+$",
      "description": "Ed25519 or ECDSA signature of the attestation content"
    },
    "signature_algorithm": {
      "type": "string",
      "enum": ["ed25519", "ecdsa-secp256k1"],
      "default": "ed25519",
      "description": "Algorithm used for the signature"
    },
    "ccr_score": {
      "type": "number",
      "minimum": 0,
      "maximum": 1,
      "description": "Cross-Context Robustness score from EPICON-01 validation"
    },
    "drift_monitoring": {
      "type": "object",
      "properties": {
        "enabled": {
          "type": "boolean",
          "default": true,
          "description": "Whether drift monitoring is active for this authority grant"
        },
        "threshold": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "default": 0.1,
          "description": "Drift score threshold that triggers automatic revocation"
        },
        "check_interval": {
          "type": "string",
          "default": "P1D",
          "description": "ISO-8601 duration between drift checks"
        }
      },
      "description": "Drift monitoring configuration"
    },
    "metadata": {
      "type": "object",
      "properties": {
        "request_context": {
          "type": "string",
          "description": "Brief description of why authority is being requested"
        },
        "previous_attestation": {
          "type": "string",
          "format": "uuid",
          "description": "Reference to previous attestation if this is a renewal"
        },
        "audit_trail_id": {
          "type": "string",
          "description": "Reference to audit trail entry"
        }
      },
      "additionalProperties": true,
      "description": "Optional metadata for audit and tracking purposes"
    }
  },
  "additionalProperties": false,
  "examples": [
    {
      "version": "1.0.0",
      "ledger_id": "550e8400-e29b-41d4-a716-446655440000",
      "wallet_signature": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
      "epicon_ej_hash": "sha256:a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2",
      "scope": ["api.read", "api.deploy.staging"],
      "expires_at": "2025-03-20T00:00:00Z",
      "risk_level": "medium",
      "risk_justification": "Staging deployment access with read permissions, no production impact",
      "attested_by": "atlas-companion-001",
      "attested_at": "2024-12-20T12:00:00Z",
      "signature": "SGVsbG8gV29ybGQhIFRoaXMgaXMgYSBzYW1wbGUgc2lnbmF0dXJl",
      "signature_algorithm": "ed25519",
      "ccr_score": 0.92,
      "drift_monitoring": {
        "enabled": true,
        "threshold": 0.1,
        "check_interval": "P1D"
      },
      "metadata": {
        "request_context": "Feature deployment to staging environment for testing",
        "audit_trail_id": "audit-2024-12-20-001"
      }
    }
  ]
}
