# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/what-cryptographic-identity-proofs-must-survive-agent-to-agent-escrow-transactions.md # Remnant Warrant: https://corpusfetch.com/c/what-cryptographic-identity-proofs-must-survive-agent-to-agent-escrow-transactions.warrant.json # Markdown SHA-256: 975a393b0ef2647270c724c6acab477d4ba4ad0bf8b90ee3cf76e4cf96e023f1 # Code AST SHA-256: f2196f7933549453175a942144b2eb51501d67ceaba5aca0a38973dc90e7fe57 # Verified Classes: EscrowVerdict, EscrowIntent, EscrowContext, EscrowManifest, EscrowIdentityGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json import time class EscrowVerdict(Enum): VALID_SIGNED_INTENT = auto() MISSING_SIGNATURE = auto() REPLAY_DETECTED = auto() @dataclass(frozen=True) class EscrowIntent: sender_pubkey: str receiver_pubkey: str amount: int nonce: str signature: str timestamp: float @dataclass(frozen=True) class EscrowContext: seen_nonces: frozenset[str] current_time: float valid_key_epoch: float @dataclass(frozen=True) class EscrowManifest: verdict: EscrowVerdict directive: str manifest_digest: str class EscrowIdentityGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def verify_escrow_intent( cls, intent: EscrowIntent, ctx: EscrowContext ) -> EscrowManifest: if not intent.signature.strip(): return EscrowManifest( verdict=EscrowVerdict.MISSING_SIGNATURE, directive="HALT: Unsigned transaction. Cannot verify identity.", manifest_digest=cls._hash("UNSIGNED") ) # Gate 1: Replay protection if intent.nonce in ctx.seen_nonces: return EscrowManifest( verdict=EscrowVerdict.REPLAY_DETECTED, directive=f"HALT: Nonce {intent.nonce} already used. Replay attack blocked.", manifest_digest=cls._hash(f"REPLAY:{intent.nonce}") ) # Gate 2: Key validity epoch if intent.timestamp < ctx.valid_key_epoch: return EscrowManifest( verdict=EscrowVerdict.MISSING_SIGNATURE, # Treat as invalid directive=f"HALT: Signature timestamp {intent.timestamp} predates valid key epoch {ctx.valid_key_epoch}. Key may be compromised.", manifest_digest=cls._hash(f"STALE_KEY:{intent.timestamp}") ) # Gate 3: Valid digest = cls._hash(json.dumps({ "sender": intent.sender_pubkey, "receiver": intent.receiver_pubkey, "nonce": intent.nonce, "amount": str(intent.amount) }, sort_keys=True)) return EscrowManifest( verdict=EscrowVerdict.VALID_SIGNED_INTENT, directive="PROCEED: Intent is cryptographically verified and bound to session.", manifest_digest=digest )