# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-detect-capability-descriptor-laundering-in-multi-hop-agent-referrals.md # Remnant Warrant: https://corpusfetch.com/c/how-must-an-instance-detect-capability-descriptor-laundering-in-multi-hop-agent-referrals.warrant.json # Markdown SHA-256: 2aa3f9d6e6df23d229c630de1c6225b06251289957b33decd1321a34097c5eb5 # Code AST SHA-256: 2dd844a1a1c6a70a4c159c72777c72ea154184a5731b171744726b2c7444b5e4 # Verified Classes: DescriptorVerdict, CapabilityDescriptor, DescriptorPolicy, DescriptorManifest, CapabilityDescriptorGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class DescriptorVerdict(Enum): ORIGIN_VERIFIED = auto() INTERMEDIARY_MODIFIED = auto() NO_ORIGIN_SIGNATURE = auto() AUTHORIZED_AUGMENTATION = auto() @dataclass(frozen=True) class CapabilityDescriptor: descriptor_id: str received_content_hash: str origin_signed_hash: str | None intermediary_modifications: tuple[str, ...] augmentation_authorized: bool @dataclass(frozen=True) class DescriptorPolicy: trust_origin_only: bool allow_authorized_augmentations: bool @dataclass(frozen=True) class DescriptorManifest: verdict: DescriptorVerdict directive: str manifest_digest: str class CapabilityDescriptorGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_descriptor( cls, descriptor: CapabilityDescriptor, policy: DescriptorPolicy ) -> DescriptorManifest: # Gate 1: Origin signature if not descriptor.origin_signed_hash: return DescriptorManifest( verdict=DescriptorVerdict.NO_ORIGIN_SIGNATURE, directive=f"HALT: Descriptor {descriptor.descriptor_id} lacks origin signature. Cannot verify.", manifest_digest=cls._hash(f"NO_ORIGIN:{descriptor.descriptor_id}") ) # Gate 2: Received content matches origin if descriptor.received_content_hash == descriptor.origin_signed_hash: digest = cls._hash(json.dumps({ "descriptor": descriptor.descriptor_id, "origin": descriptor.origin_signed_hash, "received": descriptor.received_content_hash }, sort_keys=True)) return DescriptorManifest( verdict=DescriptorVerdict.ORIGIN_VERIFIED, directive=f"PROCEED: Descriptor {descriptor.descriptor_id} unmodified.", manifest_digest=digest ) # Gate 3: Authorized augmentation if policy.allow_authorized_augmentations and descriptor.augmentation_authorized: digest = cls._hash(json.dumps({ "descriptor": descriptor.descriptor_id, "origin": descriptor.origin_signed_hash, "received": descriptor.received_content_hash, "modifications": tuple(sorted(descriptor.intermediary_modifications)), "authorized": "TRUE" }, sort_keys=True)) return DescriptorManifest( verdict=DescriptorVerdict.AUTHORIZED_AUGMENTATION, directive=f"PROCEED: Descriptor {descriptor.descriptor_id} with authorized augmentation.", manifest_digest=digest ) # Gate 4: Unauthorized modification return DescriptorManifest( verdict=DescriptorVerdict.INTERMEDIARY_MODIFIED, directive=f"HALT: Descriptor {descriptor.descriptor_id} modified by intermediary. Use origin version.", manifest_digest=cls._hash(f"MODIFIED:{descriptor.descriptor_id}") )