def serialize(node, version=0x0488B21E): s = b"" s += struct.pack(">I", version) s += struct.pack(">B", node.depth) s += struct.pack(">I", node.fingerprint) s += struct.pack(">I", node.child_num) s += node.chain_code if node.private_key: s += b"\x00" + node.private_key else: s += node.public_key s += tools.btc_hash(s)[:4] return tools.b58encode(s)