#!/usr/bin/env python3 """Generate the launch binding with Python integers, independent of Go code.""" import base64 import hashlib import json from pathlib import Path root = Path(__file__).parent identity = lambda n: base64.urlsafe_b64encode(bytes([n]) * 32).decode().rstrip('=') c = { 'version': 2, 'account': 'bds', 'app': 'home', 'host': 'overnight-home.bds.oncarlos.com', 'request_id': identity(1), 'attempt_id': identity(2), 'request_digest': '1' * 64, 'record_identity': '2' * 64, 'artifact_digest': '3' * 64, 'environment_envelope_digest': '4' * 64, 'guard_generation': 9223372036854775807, 'input_sha256': '5' * 64, 'database_path': '/data/&/☃.db', 'database_device': 18446744073709551615, 'database_inode': 9007199254740993, 'execution_deadline': '2026-09-11T20:00:00.123456789Z', 'execution_kind': 'compatibility-check', 'operation_id': identity(3), 'expected_state_sha256': '6' * 64, 'closed_checkpoint': { 'version': 1, 'preparation_id': identity(4), 'completed_at': '2026-09-11T19:59:59.123456789Z', 'main_length': 268435456, 'main_sha256': '7' * 64, 'evidence_sha256': '', }, } p = c['closed_checkpoint'] values = ['carlos/closed-checkpoint/v1'] + [c[k] for k in [ 'account', 'app', 'host', 'operation_id', 'request_id', 'attempt_id', 'request_digest', 'record_identity', 'artifact_digest', 'environment_envelope_digest', 'guard_generation', 'input_sha256', 'expected_state_sha256', 'database_path', 'database_device', 'database_inode', 'execution_deadline', ]] + [p[k] for k in ['preparation_id', 'completed_at', 'main_length', 'main_sha256']] binding = json.dumps(values, ensure_ascii=False, separators=(',', ':')) for char, escaped in [('<', '\\u003c'), ('>', '\\u003e'), ('&', '\\u0026'), ('\u2028', '\\u2028'), ('\u2029', '\\u2029')]: binding = binding.replace(char, escaped) binding = binding.encode() p['evidence_sha256'] = hashlib.sha256(binding).hexdigest() (root / 'launch-v2.json').write_text(json.dumps(c, ensure_ascii=False, indent=2) + '\n') (root / 'launch-v2-binding.json').write_bytes(binding)