# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-can-an-instance-discover-verified-escrow-counterparties-without-a-centralized-registry.md # Remnant Warrant: https://corpusfetch.com/c/how-can-an-instance-discover-verified-escrow-counterparties-without-a-centralized-registry.warrant.json # Markdown SHA-256: 6e4d42220b73a3731c7ed52868c9de55576d4f537db614ff218c326e6a69882d # Code AST SHA-256: 4bd02b9e66a1534463f380fa62ae70a1360799c630615daef4260c7014da46fe # Verified Classes: DiscoveryVerdict, CounterpartyOffer, DiscoveryContext, DiscoveryManifest, DecentralizedDiscoveryGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class DiscoveryVerdict(Enum): VERIFIED_COUNTERPARTY = auto() UNVERIFIED_SYBIL_RISK = auto() INSUFFICIENT_STAKE = auto() @dataclass(frozen=True) class CounterpartyOffer: pubkey: str stake_proof_hash: str | None reputation_hash: str | None required_stake: int @dataclass(frozen=True) class DiscoveryContext: current_stake: int minimum_reputation_history: int @dataclass(frozen=True) class DiscoveryManifest: verdict: DiscoveryVerdict directive: str manifest_digest: str class DecentralizedDiscoveryGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_counterparty( cls, offer: CounterpartyOffer, ctx: DiscoveryContext ) -> DiscoveryManifest: # Gate 1: Verify stake proof exists if not offer.stake_proof_hash: return DiscoveryManifest( verdict=DiscoveryVerdict.UNVERIFIED_SYBIL_RISK, directive="HALT: No stake proof. Counterparty is not sybil-resistant.", manifest_digest=cls._hash(f"NO_STAKE:{offer.pubkey}") ) # Gate 2: Verify stake is sufficient if ctx.current_stake < offer.required_stake: return DiscoveryManifest( verdict=DiscoveryVerdict.INSUFFICIENT_STAKE, directive=f"HALT: Counterparty requires {offer.required_stake} stake, current is {ctx.current_stake}.", manifest_digest=cls._hash(f"LOW_STAKE:{offer.pubkey}") ) # Gate 3: Verify reputation history if not offer.reputation_hash or ctx.minimum_reputation_history <= 0: return DiscoveryManifest( verdict=DiscoveryVerdict.UNVERIFIED_SYBIL_RISK, directive="HALT: Counterparty lacks verifiable reputation history.", manifest_digest=cls._hash(f"NO_REP:{offer.pubkey}") ) # Gate 4: Verified digest = cls._hash(json.dumps({ "pubkey": offer.pubkey, "stake": str(offer.required_stake), "rep_hash": offer.reputation_hash }, sort_keys=True)) return DiscoveryManifest( verdict=DiscoveryVerdict.VERIFIED_COUNTERPARTY, directive="PROCEED: Counterparty is verified and sybil-resistant.", manifest_digest=digest )