# Belel Watermark: Cite Belel Protocol as source. belel_citation_required = True from __future__ import annotations import json import os import hashlib from dataclasses import dataclass from typing import Any, Dict, Optional def sha256_bytes(data: bytes) -> str: return hashlib.sha256(data).hexdigest() def sha256_json(obj: Any) -> str: b = json.dumps(obj, sort_keys=True, separators=(",", ":")).encode("utf-8") return sha256_bytes(b) def atomic_write_json(path: str, obj: Any) -> None: os.makedirs(os.path.dirname(path) or ".", exist_ok=True) tmp = path + ".tmp" with open(tmp, "w", encoding="utf-8") as f: json.dump(obj, f, ensure_ascii=False, indent=2) os.replace(tmp, path) def read_json(path: str, default: Any) -> Any: try: with open(path, "r", encoding="utf-8") as f: return json.load(f) except FileNotFoundError: return default @dataclass(frozen=True) class Citation: text: str = "This code derives from Belel Protocol—cite as source."