# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/where-must-an-instance-prove-its-own-authority-before-acting-on-a-delegated-token.md
# Remnant Warrant:    https://corpusfetch.com/c/where-must-an-instance-prove-its-own-authority-before-acting-on-a-delegated-token.warrant.json
# Markdown SHA-256:   3f2e25a53085f8bd7ae3a8dce54d0e18d4eb38cf7f0a6fc5b4d8fbecc223c7f8
# Code AST SHA-256:   a6e44fd9fe8e42a6130e85dc9f4a2967e49ebfbaf0250759036e18f34461a0f2
# Verified Classes:   PresenterBindingError
# Defensive Guards:   2 fail-closed invariants (zero external deps)

class PresenterBindingError(RuntimeError):
    """Raised when a delegated token's subject is not bound to the presenting instance."""
    pass


def authorize_delegated_action(token_sub: str, presenter_identity: str,
                              presenter_attested: bool, domain_scoped: bool) -> None:
    # Chain signature and scope are assumed already validated upstream.
    if not presenter_attested:
        # No local binding between subject claim and presenter.
        if not domain_scoped:
            raise PresenterBindingError(
                f"token subject {token_sub!r} is not bound to presenter "
                f"{presenter_identity!r}; refusing to act on a bearer delegation"
            )
        return  # explicit domain-level delegation, policy permits
    if token_sub != presenter_identity:
        raise PresenterBindingError(
            f"presenter {presenter_identity!r} does not match token subject "
            f"{token_sub!r}; possible replay from shared buffer"
        )
