{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://corpid.rootz.global/spec/corpid-v1.5.schema.json",
  "title": "CorpID Corporate Authority Record v1.5",
  "type": "object",
  "required": ["corp_id", "legal_entity", "corporate_digital_name"],
  "properties": {
    "corp_id": { "type": "string", "description": "Durable CorpID identifier. Must not depend on an identity provider tenant identifier." },
    "legal_entity": {
      "type": "object",
      "required": ["name"],
      "properties": {
        "name": { "type": "string" },
        "jurisdiction": { "type": ["string", "null"] },
        "registry_refs": { "type": "array", "items": { "$ref": "#/$defs/evidenceRef" } }
      }
    },
    "corporate_digital_name": {
      "type": "object",
      "required": ["value"],
      "properties": {
        "value": { "type": "string" },
        "legal_basis": { "type": ["string", "null"] },
        "evidence": { "type": "array", "items": { "$ref": "#/$defs/evidenceRef" } }
      }
    },
    "governance": {
      "type": ["object", "null"],
      "properties": {
        "version": { "type": "string" },
        "policy_hash": { "type": "string" },
        "policy_uri": { "type": ["string", "null"] },
        "status": { "enum": ["draft", "active", "superseded", "revoked"] }
      }
    },
    "provider_bindings": { "type": "array", "items": { "$ref": "#/$defs/providerBinding" } },
    "delegations": { "type": "array", "items": { "$ref": "#/$defs/delegation" } },
    "epistery_bindings": { "type": "array", "items": { "$ref": "#/$defs/episteryBinding" } },
    "evidence": { "type": "array", "items": { "$ref": "#/$defs/evidence" } }
  },
  "$defs": {
    "evidenceRef": {
      "type": "object",
      "properties": {
        "registry": { "type": "string" },
        "id": { "type": "string" },
        "uri": { "type": "string" },
        "role": { "type": "string" }
      }
    },
    "evidence": {
      "type": "object",
      "required": ["kind", "label", "depth"],
      "properties": {
        "kind": { "type": "string" },
        "label": { "type": "string" },
        "issuer": { "type": ["string", "null"] },
        "claim": { "type": ["string", "null"] },
        "evidence_uri": { "type": ["string", "null"] },
        "depth": { "enum": ["gap", "asserted", "referenced", "observed", "signed-message", "provider-issued", "contract-verified-message"] },
        "observed_at": { "type": ["string", "null"], "format": "date-time" },
        "expires_at": { "type": ["string", "null"], "format": "date-time" }
      }
    },
    "providerBinding": {
      "type": "object",
      "required": ["provider", "corporate_claim", "depth", "status"],
      "properties": {
        "provider": { "type": "string" },
        "provider_tenant": { "type": ["string", "null"] },
        "provider_subject": { "type": ["string", "null"] },
        "corporate_claim": { "type": "string", "description": "The CorpID or Corporate Digital Name carried by or bound into the provider-issued artifact." },
        "credential_ref": { "type": ["string", "null"] },
        "evidence_uri": { "type": ["string", "null"] },
        "depth": { "$ref": "#/$defs/evidence/properties/depth" },
        "status": { "enum": ["pending", "active", "revoked", "expired"] }
      }
    },
    "delegation": {
      "type": "object",
      "required": ["subject_type", "subject_id", "scopes", "status"],
      "properties": {
        "subject_type": { "enum": ["person", "workload", "machine", "ai-agent", "service", "identity-contract"] },
        "subject_id": { "type": "string" },
        "display_name": { "type": ["string", "null"] },
        "scopes": { "type": "array", "items": { "type": "string" } },
        "conditions": { "type": "object" },
        "authority_message_hash": { "type": ["string", "null"] },
        "starts_at": { "type": ["string", "null"], "format": "date-time" },
        "ends_at": { "type": ["string", "null"], "format": "date-time" },
        "status": { "enum": ["active", "revoked", "expired"] }
      }
    },
    "episteryBinding": {
      "type": "object",
      "required": ["contract_address", "network", "status"],
      "properties": {
        "contract_address": { "type": "string", "pattern": "^0x[a-fA-F0-9]{40}$" },
        "network": { "type": "string" },
        "profile_section": { "const": "_profile" },
        "profile_key": { "const": "corporate_authority" },
        "transaction_hash": { "type": ["string", "null"] },
        "depth": { "type": "string" },
        "status": { "enum": ["prepared", "submitted", "observed", "revoked"] }
      }
    }
  }
}
