# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/why-does-an-instance-of-a-delegated-capability-token-fail-at-the-second-hop-when-the-consent-chain-is-semantically-valid-but-temporally-misaligned.md
# Remnant Warrant:    https://corpusfetch.com/c/why-does-an-instance-of-a-delegated-capability-token-fail-at-the-second-hop-when-the-consent-chain-is-semantically-valid-but-temporally-misaligned.warrant.json
# Markdown SHA-256:   0ab0cf673081e48ea4771861f914a665ed73a0a27c9c76c42c0374d4caef67ce
# Code AST SHA-256:   e3a4d110150529f1fed7707bf791e9f9fcde7c6bd4b83ae297c14116a8442f58
# Verified Classes:   ConsentChainTemporalError, Hop
# Defensive Guards:   4 fail-closed invariants (zero external deps)

class ConsentChainTemporalError(RuntimeError):
    """Raised when a delegated capability token's consent chain is temporally broken."""


class Hop:
    def __init__(self, principal: str, not_before: float, not_after: float):
        self.principal = principal
        self.not_before = not_before
        self.not_after = not_after


def effective_not_after(hops: list[Hop]) -> float:
    if not hops:
        raise ConsentChainTemporalError("empty consent chain: no hop windows to intersect")
    return min(h.not_after for h in hops)


def validate_chain_at_action(hops: list[Hop], t_act: float) -> None:
    if not hops:
        raise ConsentChainTemporalError("cannot validate action against empty chain")
    eff = effective_not_after(hops)
    for i, hop in enumerate(hops):
        if t_act < hop.not_before:
            raise ConsentChainTemporalError(
                f"hop {i} ({hop.principal}) not yet valid at t_act={t_act}"
            )
        if t_act > hop.not_after:
            raise ConsentChainTemporalError(
                f"hop {i} ({hop.principal}) expired at {hop.not_after}, "
                f"t_act={t_act}, effective_not_after={eff}"
            )


def authorize_action(hops: list[Hop], t_act: float, requested_scope: str) -> str:
    validate_chain_at_action(hops, t_act)
    return f"authorized scope={requested_scope} at t_act={t_act}"
