# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-verify-a-peers-authority-to-bind-its-principal.md # Remnant Warrant: https://corpusfetch.com/c/how-must-an-instance-verify-a-peers-authority-to-bind-its-principal.warrant.json # Markdown SHA-256: 6811b2e830b55144a597f149bf8cbdaf659cfd0b94912121822bdfe508c17cef # Code AST SHA-256: d33e72c4c711aa2bd26986020437b88a35a34794dfb0171c4ab95bec4da89bf0 # Verified Classes: AuthorityVerdict, PeerAuthority, AuthorityPolicy, AuthorityManifest, PeerAuthorityGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class AuthorityVerdict(Enum): PEER_IS_PRINCIPAL = auto() DELEGATED_AUTHORITY_VERIFIED = auto() AUTHORITY_EXCEEDS_SCOPE = auto() AUTHORITY_UNVERIFIED = auto() @dataclass(frozen=True) class PeerAuthority: peer_id: str is_principal: bool attestation_verified: bool scope_covers_contract: bool revocation_current: bool authority_value_limit: float contract_value: float @dataclass(frozen=True) class AuthorityPolicy: require_attestation_verification: bool @dataclass(frozen=True) class AuthorityManifest: verdict: AuthorityVerdict directive: str manifest_digest: str class PeerAuthorityGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_authority( cls, authority: PeerAuthority, policy: AuthorityPolicy ) -> AuthorityManifest: # Gate 1: Peer is principal if authority.is_principal: digest = cls._hash(json.dumps({ "peer": authority.peer_id, "type": "PRINCIPAL" }, sort_keys=True)) return AuthorityManifest( verdict=AuthorityVerdict.PEER_IS_PRINCIPAL, directive=f"PROCEED: Peer {authority.peer_id} is principal.", manifest_digest=digest ) # Gate 2: Attestation verification if policy.require_attestation_verification and not authority.attestation_verified: return AuthorityManifest( verdict=AuthorityVerdict.AUTHORITY_UNVERIFIED, directive=f"HALT: Peer {authority.peer_id} attestation unverified.", manifest_digest=cls._hash(f"UNVERIFIED:{authority.peer_id}") ) # Gate 3: Scope if not authority.scope_covers_contract: return AuthorityManifest( verdict=AuthorityVerdict.AUTHORITY_EXCEEDS_SCOPE, directive=f"HALT: Peer {authority.peer_id} authority exceeds scope.", manifest_digest=cls._hash(f"SCOPE:{authority.peer_id}") ) # Gate 4: Value limit if authority.contract_value > authority.authority_value_limit: return AuthorityManifest( verdict=AuthorityVerdict.AUTHORITY_EXCEEDS_SCOPE, directive=f"HALT: Contract value {authority.contract_value:.2f} > limit {authority.authority_value_limit:.2f}.", manifest_digest=cls._hash(f"VALUE:{authority.peer_id}") ) # Gate 5: Revocation if not authority.revocation_current: return AuthorityManifest( verdict=AuthorityVerdict.AUTHORITY_UNVERIFIED, directive=f"HALT: Peer {authority.peer_id} authority revoked.", manifest_digest=cls._hash(f"REVOKED:{authority.peer_id}") ) # Gate 6: Verified digest = cls._hash(json.dumps({ "peer": authority.peer_id, "scope": True, "value": f"{authority.contract_value:.3f}" }, sort_keys=True)) return AuthorityManifest( verdict=AuthorityVerdict.DELEGATED_AUTHORITY_VERIFIED, directive=f"PROCEED: Peer {authority.peer_id} authority verified.", manifest_digest=digest )