def create_output(item, key, subkey_path=None): output_dict = {} output_order = [] def add_output(json_key, value=None, human_readable_key=None): if human_readable_key is None: human_readable_key = json_key.replace("_", " ") if value: output_dict[json_key.strip().lower()] = value output_order.append((json_key.lower(), human_readable_key)) network_name = network_name_for_netcode(key._netcode) full_network_name = full_network_name_for_netcode(key._netcode) add_output("input", item) add_output("network", full_network_name) add_output("netcode", key._netcode) create_wallet_key_output(key, subkey_path, add_output) secret_exponent = key.secret_exponent() if secret_exponent: add_output("secret_exponent", '%d' % secret_exponent) add_output("secret_exponent_hex", '%x' % secret_exponent, " hex") add_output("wif", key.wif(use_uncompressed=False)) add_output("wif_uncompressed", key.wif(use_uncompressed=True), " uncompressed") create_public_pair_output(key, add_output) hash160_c = key.hash160(use_uncompressed=False) if hash160_c: add_output("hash160", b2h(hash160_c)) hash160_u = key.hash160(use_uncompressed=True) if hash160_u: add_output("hash160_uncompressed", b2h(hash160_u), " uncompressed") if hash160_c: address = key.address(use_uncompressed=False) add_output("address", address, "%s address" % network_name) output_dict["%s_address" % key._netcode] = address if hash160_u: address = key.address(use_uncompressed=True) add_output("address_uncompressed", address, "%s address uncompressed" % network_name) output_dict["%s_address_uncompressed" % key._netcode] = address if hash160_c and address_wit_prefix_for_netcode(key._netcode): address = ScriptPayToAddressWit(b'\0', hash160_c).info()["address_f"]( key._netcode) add_output("address segwit", address, "%s segwit address" % network_name) output_dict["%s_address_segwit" % key._netcode] = address return output_dict, output_order
def create_hash160_output(key, add_output, output_dict): network_name = network_name_for_netcode(key._netcode) hash160_c = key.hash160(use_uncompressed=False) hash160_u = key.hash160(use_uncompressed=True) hash160 = hash160_c or hash160_u if hash160: add_output("hash160", b2h(hash160)) if hash160_c and hash160_u: add_output("hash160_uncompressed", b2h(hash160_u), " uncompressed") if hash160: address = key.address(use_uncompressed=hash160_c is None) add_output("address", address, "%s address" % network_name) output_dict["%s_address" % key._netcode] = address if hash160_c and hash160_u: address = key.address(use_uncompressed=True) add_output("address_uncompressed", address, "%s address uncompressed" % network_name) output_dict["%s_address_uncompressed" % key._netcode] = address # don't print segwit addresses unless we're sure we have a compressed key if hash160_c: p2aw_script = ScriptPayToAddressWit(b'\0', hash160_c) address_segwit = p2aw_script.info()["address_f"](key._netcode) if address_segwit: # this network seems to support segwit add_output("address_segwit", address_segwit, "%s segwit address" % network_name) output_dict["%s_address_segwit" % key._netcode] = address_segwit p2sh_script = p2aw_script.script() p2s_address = address_for_pay_to_script(p2aw_script.script(), key._netcode) if p2s_address: add_output("p2sh_segwit", p2s_address) p2sh_script_hex = b2h(p2sh_script) add_output("p2sh_segwit_script", p2sh_script_hex, " corresponding p2sh script")
def create_hash160_output(key, add_output, output_dict): network_name = network_name_for_netcode(key._netcode) hash160_c = key.hash160(use_uncompressed=False) hash160_u = key.hash160(use_uncompressed=True) hash160 = hash160_c or hash160_u if hash160: add_output("hash160", b2h(hash160)) if hash160_c and hash160_u: add_output("hash160_uncompressed", b2h(hash160_u), " uncompressed") if hash160: address = key.address(use_uncompressed=hash160_c is None) add_output("address", address, "%s address" % network_name) output_dict["%s_address" % key._netcode] = address if hash160_c and hash160_u: address = key.address(use_uncompressed=True) add_output("address_uncompressed", address, "%s address uncompressed" % network_name) output_dict["%s_address_uncompressed" % key._netcode] = address # don't print segwit addresses unless we're sure we have a compressed key if hash160_c: p2aw_script = ScriptPayToAddressWit(b'\0', hash160_c) address_segwit = p2aw_script.info()["address_f"](key._netcode) if address_segwit: # this network seems to support segwit add_output("address_segwit", address_segwit, "%s segwit address" % network_name) output_dict["%s_address_segwit" % key._netcode] = address_segwit p2sh_script = p2aw_script.script() p2s_address = address_for_pay_to_script(p2aw_script.script(), key._netcode) if p2s_address: add_output("p2sh_segwit", p2s_address) p2sh_script_hex = b2h(p2sh_script) add_output("p2sh_segwit_script", p2sh_script_hex, " corresponding p2sh script")
def create_output(item, key, subkey_path=None): output_dict = {} output_order = [] def add_output(json_key, value=None, human_readable_key=None): if human_readable_key is None: human_readable_key = json_key.replace("_", " ") if value: output_dict[json_key.strip().lower()] = value output_order.append((json_key.lower(), human_readable_key)) network_name = network_name_for_netcode(key._netcode) full_network_name = full_network_name_for_netcode(key._netcode) add_output("input", item) add_output("network", full_network_name) add_output("netcode", key._netcode) if hasattr(key, "wallet_key"): if subkey_path: add_output("subkey_path", subkey_path) add_output("wallet_key", key.wallet_key(as_private=key.is_private())) if key.is_private(): add_output("public_version", key.wallet_key(as_private=False)) child_number = key.child_index() if child_number >= 0x80000000: wc = child_number - 0x80000000 child_index = "%dH (%d)" % (wc, child_number) else: child_index = "%d" % child_number add_output("tree_depth", "%d" % key.tree_depth()) add_output("fingerprint", b2h(key.fingerprint())) add_output("parent_fingerprint", b2h(key.parent_fingerprint()), "parent f'print") add_output("child_index", child_index) add_output("chain_code", b2h(key.chain_code())) add_output("private_key", "yes" if key.is_private() else "no") secret_exponent = key.secret_exponent() if secret_exponent: add_output("secret_exponent", '%d' % secret_exponent) add_output("secret_exponent_hex", '%x' % secret_exponent, " hex") add_output("wif", key.wif(use_uncompressed=False)) add_output("wif_uncompressed", key.wif(use_uncompressed=True), " uncompressed") public_pair = key.public_pair() if public_pair: add_output("public_pair_x", '%d' % public_pair[0]) add_output("public_pair_y", '%d' % public_pair[1]) add_output("public_pair_x_hex", '%x' % public_pair[0], " x as hex") add_output("public_pair_y_hex", '%x' % public_pair[1], " y as hex") add_output("y_parity", "odd" if (public_pair[1] & 1) else "even") add_output("key_pair_as_sec", b2h(key.sec(use_uncompressed=False))) add_output("key_pair_as_sec_uncompressed", b2h(key.sec(use_uncompressed=True)), " uncompressed") hash160_c = key.hash160(use_uncompressed=False) if hash160_c: add_output("hash160", b2h(hash160_c)) hash160_u = key.hash160(use_uncompressed=True) if hash160_u: add_output("hash160_uncompressed", b2h(hash160_u), " uncompressed") if hash160_c: address = key.address(use_uncompressed=False) add_output("address", address, "%s address" % network_name) output_dict["%s_address" % key._netcode] = address if hash160_u: address = key.address(use_uncompressed=True) add_output("address_uncompressed", address, "%s address uncompressed" % network_name) output_dict["%s_address_uncompressed" % key._netcode] = address return output_dict, output_order
def create_output(item, key, subkey_path=None): output_dict = {} output_order = [] def add_output(json_key, value=None, human_readable_key=None): if human_readable_key is None: human_readable_key = json_key.replace("_", " ") if value: output_dict[json_key.strip().lower()] = value output_order.append((json_key.lower(), human_readable_key)) network_name = network_name_for_netcode(key._netcode) full_network_name = full_network_name_for_netcode(key._netcode) add_output("input", item) add_output("network", full_network_name) add_output("netcode", key._netcode) if hasattr(key, "wallet_key"): if subkey_path: add_output("subkey_path", subkey_path) add_output("wallet_key", key.wallet_key(as_private=key.is_private())) if key.is_private(): add_output("public_version", key.wallet_key(as_private=False)) child_number = key.child_index() if child_number >= 0x80000000: wc = child_number - 0x80000000 child_index = "%dH (%d)" % (wc, child_number) else: child_index = "%d" % child_number add_output("tree_depth", "%d" % key.tree_depth()) add_output("fingerprint", b2h(key.fingerprint())) add_output("parent_fingerprint", b2h(key.parent_fingerprint()), "parent f'print") add_output("child_index", child_index) add_output("chain_code", b2h(key.chain_code())) add_output("private_key", "yes" if key.is_private() else "no") secret_exponent = key.secret_exponent() if secret_exponent: add_output("secret_exponent", '%d' % secret_exponent) add_output("secret_exponent_hex", '%x' % secret_exponent, " hex") add_output("wif", key.wif(use_uncompressed=False)) add_output("wif_uncompressed", key.wif(use_uncompressed=True), " uncompressed") public_pair = key.public_pair() if public_pair: add_output("public_pair_x", '%d' % public_pair[0]) add_output("public_pair_y", '%d' % public_pair[1]) add_output("public_pair_x_hex", '%x' % public_pair[0], " x as hex") add_output("public_pair_y_hex", '%x' % public_pair[1], " y as hex") add_output("y_parity", "odd" if (public_pair[1] & 1) else "even") add_output("key_pair_as_sec", b2h(key.sec(use_uncompressed=False))) add_output("key_pair_as_sec_uncompressed", b2h(key.sec(use_uncompressed=True)), " uncompressed") hash160_c = key.hash160(use_uncompressed=False) if hash160_c: add_output("hash160", b2h(hash160_c)) hash160_u = key.hash160(use_uncompressed=True) if hash160_u: add_output("hash160_uncompressed", b2h(hash160_u), " uncompressed") if hash160_c: address = key.address(use_uncompressed=False) add_output("address", address, "%s address" % network_name) output_dict["%s_address" % key._netcode] = address if hash160_u: address = key.address(use_uncompressed=True) add_output("address_uncompressed", address, "%s address uncompressed" % network_name) output_dict["%s_address_uncompressed" % key._netcode] = address return output_dict, output_order