#!/usr/bin/env python3 """ Read the scroll and say whether it is the scroll that was engraved. Hashes every file under l1/torah — path, then bytes, in the order build_l1.py hashed them — and compares the result with the hash recorded in l1/integrity.sha256 (and with an expected hash, if one is given). Comparing integrity.sha256 with a constant proves only that the two copies of the constant agree. This reads the verses. Usage: scripts/verify_l1.py # l1/ beside this script's repo scripts/verify_l1.py /mnt/torah # another L1 root scripts/verify_l1.py l1 # also require this exact hash Exit status 0 if everything agrees, 1 if anything does not. """ import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) from build_l1 import generate_integrity_hash # noqa: E402 def main(argv: list[str]) -> int: repo_root = Path(__file__).resolve().parent.parent l1_root = Path(argv[1]) if len(argv) > 1 else repo_root / "l1" expected = argv[2].strip().lower() if len(argv) > 2 else None torah = l1_root / "torah" if not torah.is_dir(): print(f"FAIL: {torah} is not a directory") return 1 computed = generate_integrity_hash(str(torah)) print(f"computed {computed}") ok = True record = l1_root / "integrity.sha256" if record.is_file(): recorded = record.read_text().strip() print(f"recorded {recorded}") ok = ok and recorded == computed else: print(f"recorded (no {record})") ok = False if expected is not None: print(f"expected {expected}") ok = ok and expected == computed print("OK: the scroll matches" if ok else "FAIL: the scroll does not match") return 0 if ok else 1 if __name__ == "__main__": sys.exit(main(sys.argv))