| 1 | #!/usr/bin/env python3 |
| 2 | """Generate the launch binding with Python integers, independent of Go code.""" |
| 3 | import base64 |
| 4 | import hashlib |
| 5 | import json |
| 6 | from pathlib import Path |
| 7 | |
| 8 | root = Path(__file__).parent |
| 9 | identity = lambda n: base64.urlsafe_b64encode(bytes([n]) * 32).decode().rstrip('=') |
| 10 | c = { |
| 11 | 'version': 2, 'account': 'bds', 'app': 'home', |
| 12 | 'host': 'overnight-home.bds.oncarlos.com', |
| 13 | 'request_id': identity(1), 'attempt_id': identity(2), |
| 14 | 'request_digest': '1' * 64, 'record_identity': '2' * 64, |
| 15 | 'artifact_digest': '3' * 64, 'environment_envelope_digest': '4' * 64, |
| 16 | 'guard_generation': 9223372036854775807, 'input_sha256': '5' * 64, |
| 17 | 'database_path': '/data/<home>&/☃.db', |
| 18 | 'database_device': 18446744073709551615, 'database_inode': 9007199254740993, |
| 19 | 'execution_deadline': '2026-09-11T20:00:00.123456789Z', |
| 20 | 'execution_kind': 'compatibility-check', 'operation_id': identity(3), |
| 21 | 'expected_state_sha256': '6' * 64, |
| 22 | 'closed_checkpoint': { |
| 23 | 'version': 1, 'preparation_id': identity(4), |
| 24 | 'completed_at': '2026-09-11T19:59:59.123456789Z', |
| 25 | 'main_length': 268435456, 'main_sha256': '7' * 64, |
| 26 | 'evidence_sha256': '', |
| 27 | }, |
| 28 | } |
| 29 | p = c['closed_checkpoint'] |
| 30 | values = ['carlos/closed-checkpoint/v1'] + [c[k] for k in [ |
| 31 | 'account', 'app', 'host', 'operation_id', 'request_id', 'attempt_id', |
| 32 | 'request_digest', 'record_identity', 'artifact_digest', |
| 33 | 'environment_envelope_digest', 'guard_generation', 'input_sha256', |
| 34 | 'expected_state_sha256', 'database_path', 'database_device', |
| 35 | 'database_inode', 'execution_deadline', |
| 36 | ]] + [p[k] for k in ['preparation_id', 'completed_at', 'main_length', 'main_sha256']] |
| 37 | binding = json.dumps(values, ensure_ascii=False, separators=(',', ':')) |
| 38 | for char, escaped in [('<', '\\u003c'), ('>', '\\u003e'), ('&', '\\u0026'), |
| 39 | ('\u2028', '\\u2028'), ('\u2029', '\\u2029')]: |
| 40 | binding = binding.replace(char, escaped) |
| 41 | binding = binding.encode() |
| 42 | p['evidence_sha256'] = hashlib.sha256(binding).hexdigest() |
| 43 | (root / 'launch-v2.json').write_text(json.dumps(c, ensure_ascii=False, indent=2) + '\n') |
| 44 | (root / 'launch-v2-binding.json').write_bytes(binding) |
| 45 | |