def _validate_bindings(bindings: dict, files: dict[str, bytes]) -> None: if bindings.get("kind") == "reporting_attempt": if set(bindings) != {"kind", "packet_sha256", "reporting_record"}: raise ValueError("Archived attempt cannot carry publication authority") reference = _reference(bindings["reporting_record"], "reporting") if set(files) != _report_paths(reference): raise ValueError("Attempt proof contains missing or unrelated files") _validate_report_artifacts(reference, bindings["packet_sha256"], files) return if (bindings.get("kind") is not None or bindings.get("status") != "complete" or bindings.get("stage") != "published" or bindings.get("review_decision") != "approve" or type(bindings.get("issue")) is not int or bindings["issue"] < 1 or not isinstance(bindings.get("packet_sha256"), str) or not _HASH.fullmatch(bindings["packet_sha256"])): raise ValueError("Only completed, exactly reviewed publication evidence can be archived") packet_path = _reference(bindings.get("packet_path"), "packets") packet = _object(files[packet_path]) canonical = digest(json.dumps(packet, ensure_ascii=False, sort_keys=True).encode()) if canonical != bindings["packet_sha256"]: raise ValueError("Proof packet identity differs from completed state") manifest_path = _reference(bindings.get("reporting_record"), "reporting") manifest = _validate_report_artifacts(manifest_path, canonical, files) expected_paths = _report_paths(manifest_path) | {packet_path} if digest(files[packet_path]) != manifest["artifacts"]["packet.json"]["sha256"]: raise ValueError("Proof packet bytes differ from the reviewed packet") reports = bindings.get("review_paths") if not isinstance(reports, dict) or set(reports) != set(ROLES): raise ValueError("Proof requires both authorizing review paths") report_hashes = {} for role in ROLES: path = _reference(reports[role], "reviews") report = _object(files[path]) report_hashes[role] = digest(files[path]) if (report.get("role") != role or report.get("packet_sha256") != canonical or report.get("decision") != "approve" or report_hashes[role] != manifest["artifacts"][f"{role}.report.json"]["sha256"]): raise ValueError("Proof review differs from completed exact evidence") expected_paths.add(path) for reference_field, hash_field, prefix in ( ("external_review_path", "external_review_sha256", "reviews"), ("historical_context", "historical_context_sha256", "historical-context"), ("historical_rehearsal", "historical_rehearsal_sha256", "historical-rehearsals"), ): if bindings.get(reference_field) is not None: path = _reference(bindings[reference_field], prefix) if digest(files[path]) != bindings.get(hash_field): raise ValueError("Proof auxiliary evidence differs from its completed binding") expected_paths.add(path) if bindings.get("run_kind") == "retrospective": receipt_path = _reference(bindings.get("historical_rehearsal"), "historical-rehearsals") receipt = _object(files[receipt_path]) historical = receipt.get("bindings", {}) if (receipt.get("schema_version") != 1 or historical.get("packet_sha256") != canonical or historical.get("packet_file_sha256") != digest(files[packet_path]) or historical.get("reporting_sha256") != digest(files[manifest_path]) or historical.get("reviews") != report_hashes or historical.get("target_friday") != bindings.get("target_friday") or historical.get("historical_context_sha256") != bindings.get("historical_context_sha256") or historical.get("external_review_sha256") != bindings.get("external_review_sha256") or receipt.get("live", {}).get("verified_locales") != ["fr", "en"] or receipt.get("live", {}).get("issue") != bindings["issue"] or receipt.get("live", {}).get("packet_sha256") != canonical): raise ValueError("Proof historical receipt differs from completed publication evidence") if set(files) != expected_paths: raise ValueError("Proof contains missing or unrelated files")