"""Creates the REAL eddycoin-mainnet-1 genesis (GENESIS_DESIGN.md). Run ONCE. Signs with the offline emission-signing key (env EDDY_SIGNING_KEY_DIR; the private key is never published). Outputs: genesis/genesis.json (exact canonical bytes, no newline), genesis.json.sha256, genesis.json.sig (hex Ed25519), emission-signing.pub.""" import json, hashlib, os, subprocess, sys, time, tempfile HERE = os.path.dirname(os.path.abspath(__file__)); OUT = os.path.join(HERE, "genesis") KEYDIR = os.environ.get("EDDY_SIGNING_KEY_DIR", "signing-key") ART = os.environ.get("EDDY_EMISSION_DIR", "emission") if os.path.exists(os.path.join(OUT, "genesis.json")): sys.exit("genesis already exists - refusing to overwrite") spec = open(os.path.join(ART, "kompromis-120b.json"), "rb").read() spec_sha = hashlib.sha256(spec).hexdigest() assert spec_sha == "0a70d671ca52094d7eaa82c7b43122bce4f9bba1281f79d0ca1211b99c27cfb7" pubraw = open(os.path.join(KEYDIR, "emission-signing.pub.raw"), "rb").read(); assert len(pubraw) == 32 fp = hashlib.sha256(pubraw).hexdigest(); assert fp == "b62ce8abf98a9c3d2416bee74766ed4d847afb5f3a9cd999bf4f07c4f3d591a5" assert open(os.path.join(ART, "emission-signing.pub")).read().strip() == pubraw.hex() G = {"format": "eddycoin-genesis", "version": 1, "network": "eddycoin-mainnet-1", "chain_id": "EDDY1", "timestamp_ms": int(time.time() * 1000), "emission": {"name": "Kompromis-120b", "spec_sha256": spec_sha}, "emission_signing_pubkey_fingerprint": "sha256:" + fp, "allocations": [], "max_supply": "90000000000000000", "message": "Eddycoin mainnet: every coin is mined. 900,000,000 EDDY cap.", "genesis_bits": {"E": 27, "D": 32}, "domains": {"checkpoint": "EDDY1-CHECKPOINT-v1", "candidate": "EDDY1-Y-CANDIDATE|v1", "state": "EDDY1-Y-STATE|v1", "txroot": "EDDY1-TXROOT|v1", "tx": "EDDY1-TX|v1", "sig": "EDDY1-TX-SIG|v1", "address": "EDDY-ADDR|v1"}} body = json.dumps(G, sort_keys=True, separators=(",", ":"), ensure_ascii=True).encode("ascii") os.makedirs(OUT, exist_ok=True) p = os.path.join(OUT, "genesis.json"); open(p, "wb").write(body) h = hashlib.sha256(body).hexdigest() open(p + ".sha256", "w").write("%s genesis.json\n" % h) sig = subprocess.run(["openssl", "pkeyutl", "-sign", "-rawin", "-inkey", KEYDIR + "/emission-signing.key", "-in", p], check=True, capture_output=True).stdout assert len(sig) == 64 with tempfile.NamedTemporaryFile(delete=False) as f: f.write(sig); sf = f.name subprocess.run(["openssl", "pkeyutl", "-verify", "-rawin", "-pubin", "-inkey", KEYDIR + "/emission-signing.pub.pem", "-in", p, "-sigfile", sf], check=True, capture_output=True) os.unlink(sf) open(p + ".sig", "w").write(sig.hex() + "\n") open(os.path.join(OUT, "emission-signing.pub"), "w").write(pubraw.hex() + "\n") print("genesis.json sha256", h, "timestamp_ms", G["timestamp_ms"], "signature verified (openssl)")