# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/why-does-an-instance-accept-a-federated-agent-s-verifiable-credential-after-the-issuer-s-revocation-registry-has-already-diverged.md
# Remnant Warrant:    https://corpusfetch.com/c/why-does-an-instance-accept-a-federated-agent-s-verifiable-credential-after-the-issuer-s-revocation-registry-has-already-diverged.warrant.json
# Markdown SHA-256:   626765dfdbb61ea959ae98b3d7b9a3264240e49a0addad02081159b1c276e728
# Code AST SHA-256:   b8a5bfcab15cfe0363d43d9f58aeeb21334957e950c5671f66fd7b6dd1f3b2a0
# Verified Classes:   FederatedCredentialIndeterminate, Snapshot
# Defensive Guards:   4 fail-closed invariants (zero external deps)

from dataclasses import dataclass
from typing import Optional

class FederatedCredentialIndeterminate(RuntimeError):
    """Raised when a VC cannot be soundly accepted or rejected due to
    cross-snapshot divergence between the trust anchor and the status list."""
    pass

@dataclass
class Snapshot:
    version: int
    valid_from: float          # epoch seconds
    previous_hash: Optional[str]

def verify_federated_credential(
    cred_issued_at: float,
    anchor: Snapshot,
    status_list: Snapshot,
    key_deactivated: bool,
    key_deactivated_at: Optional[float],
    status_list_issuer_anchor_version: int,
) -> bool:
    # 1. Retroactive deactivation: unconditional reject.
    if key_deactivated and key_deactivated_at is not None \
            and cred_issued_at < key_deactivated_at:
        raise FederatedCredentialIndeterminate(
            f"signing key deactivated at {key_deactivated_at} "
            f"predates credential issued_at {cred_issued_at}"
        )

    # 2. Causality inversion: status list newer than the anchor we resolved.
    if status_list.valid_from > anchor.valid_from:
        raise FederatedCredentialIndeterminate(
            f"status list valid_from {status_list.valid_from} > "
            f"anchor valid_from {anchor.valid_from}; "
            f"cannot interpret future revocation state"
        )

    # 3. Version binding: status list must declare the anchor it was cut against.
    if status_list_issuer_anchor_version != anchor.version:
        raise FederatedCredentialIndeterminate(
            f"status list bound to anchor v{status_list_issuer_anchor_version}, "
            f"verifier resolved v{anchor.version}"
        )

    # 4. Monotonicity: compaction without a hash chain makes a 0 bit meaningless.
    if status_list.previous_hash is None and status_list.version > 1:
        raise FederatedCredentialIndeterminate(
            f"status list v{status_list.version} has no previousStatusList chain; "
            f"index semantics not stable across versions"
        )

    return True
