# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/what-structural-signals-indicate-a-delegated-agent-credential-has-silently-outlived-its-issuer-s-authority-under-aaif-chain-revocation.md
# Remnant Warrant:    https://corpusfetch.com/c/what-structural-signals-indicate-a-delegated-agent-credential-has-silently-outlived-its-issuer-s-authority-under-aaif-chain-revocation.warrant.json
# Markdown SHA-256:   e80acf15b9f8e44843258ba635d4eaebc3c587da32e4336907b356ef4d901dc8
# Code AST SHA-256:   c6f9785f97496e01ced01a0a727c7624d29963ae24ca02d07d702bc6e025e806
# Verified Classes:   OrphanedCredentialError
# Defensive Guards:   5 fail-closed invariants (zero external deps)

class OrphanedCredentialError(RuntimeError):
    """Raised when a delegated credential's ancestor chain is not fully live."""
    pass


def verify_chain(leaf, revocation_index, current_epoch, propagation_budget):
    # Walk the full ancestor path, not just the direct issuer.
    node = leaf
    while node is not None:
        status = revocation_index.get(node.credential_id)
        if status is None:
            raise OrphanedCredentialError(
                f"ancestor {node.credential_id} absent from revocation index"
            )
        if status == "revoked":
            raise OrphanedCredentialError(
                f"ancestor {node.credential_id} revoked at epoch {current_epoch}"
            )
        if status == "unsupported":
            raise OrphanedCredentialError(
                f"ancestor {node.credential_id} unsupported: its own issuer withdrawn"
            )
        if node.epoch < current_epoch - propagation_budget:
            raise OrphanedCredentialError(
                f"ancestor {node.credential_id} epoch {node.epoch} lags "
                f"current {current_epoch} beyond budget {propagation_budget}"
            )
        if node.expires_at <= now():
            raise OrphanedCredentialError(
                f"ancestor {node.credential_id} expired"
            )
        node = node.parent
    return True
