# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/what-selective-disclosure-invariants-must-survive-cross-agent-attribute-proofs.md # Remnant Warrant: https://corpusfetch.com/c/what-selective-disclosure-invariants-must-survive-cross-agent-attribute-proofs.warrant.json # Markdown SHA-256: e5d00e5e901139251aca6aecbe2a61078d4e1a9899c101df45d14b0ef11f6fda # Code AST SHA-256: 4416e25716c00cbd653cd85311fdbadf521d38e572ae0f0980f0b69f53ddb34e # Verified Classes: SelectiveDisclosureVerdict, SelectiveProof, ProofSet, SelectivePolicy, SelectiveManifest, SelectiveDisclosureGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class SelectiveDisclosureVerdict(Enum): FULL_DISCLOSURE = auto() PROOF_VALID_BOUNDED = auto() OVER_DISCLOSURE_DETECTED = auto() COMPOSITION_LEAK_RISK = auto() @dataclass(frozen=True) class SelectiveProof: proof_id: str proven_attribute: str proven_scope: frozenset[str] leaked_scope: frozenset[str] zk_scheme: str composition_safe: bool @dataclass(frozen=True) class ProofSet: proofs: tuple[SelectiveProof, ...] full_disclosure: bool @dataclass(frozen=True) class SelectivePolicy: allow_composition: bool max_acceptable_leakage: int @dataclass(frozen=True) class SelectiveManifest: verdict: SelectiveDisclosureVerdict directive: str manifest_digest: str class SelectiveDisclosureGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_proof_set( cls, proof_set: ProofSet, policy: SelectivePolicy ) -> SelectiveManifest: # Gate 1: Full disclosure if proof_set.full_disclosure: digest = cls._hash(json.dumps({ "proofs": str(len(proof_set.proofs)), "type": "FULL_DISCLOSURE" }, sort_keys=True)) return SelectiveManifest( verdict=SelectiveDisclosureVerdict.FULL_DISCLOSURE, directive=f"PROCEED: Full disclosure, {len(proof_set.proofs)} proofs.", manifest_digest=digest ) # Gate 2: Over-disclosure check per proof for proof in proof_set.proofs: leaked_outside_scope = proof.leaked_scope - proof.proven_scope if len(leaked_outside_scope) > policy.max_acceptable_leakage: return SelectiveManifest( verdict=SelectiveDisclosureVerdict.OVER_DISCLOSURE_DETECTED, directive=f"HALT: Proof {proof.proof_id} leaks {sorted(leaked_outside_scope)} beyond scope.", manifest_digest=cls._hash(f"OVER:{proof.proof_id}") ) # Gate 3: Composition safety if len(proof_set.proofs) > 1: if policy.allow_composition: unsafe = [p.proof_id for p in proof_set.proofs if not p.composition_safe] if unsafe: return SelectiveManifest( verdict=SelectiveDisclosureVerdict.COMPOSITION_LEAK_RISK, directive=f"HALT: {len(unsafe)} proofs unsafe for composition.", manifest_digest=cls._hash(f"UNSAFE_COMP:{len(unsafe)}") ) # Gate 4: Bounded digest = cls._hash(json.dumps({ "proofs": tuple(p.proof_id for p in proof_set.proofs), "attributes": tuple(p.proven_attribute for p in proof_set.proofs), "scopes": tuple(sorted(str(sorted(p.proven_scope)) for p in proof_set.proofs)) }, sort_keys=True)) return SelectiveManifest( verdict=SelectiveDisclosureVerdict.PROOF_VALID_BOUNDED, directive=f"PROCEED: {len(proof_set.proofs)} selective proofs bounded and composition-safe.", manifest_digest=digest )