From 3a03618ffd869fc05d2a67aa26806a8e9260b919 Mon Sep 17 00:00:00 2001 From: Juha Siivikko Date: Fri, 18 Jun 2021 14:54:01 +0300 Subject: [PATCH 1/3] Added missing definiton --- pycoin/networks/bitcoinish.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pycoin/networks/bitcoinish.py b/pycoin/networks/bitcoinish.py index caa43428..22e72096 100644 --- a/pycoin/networks/bitcoinish.py +++ b/pycoin/networks/bitcoinish.py @@ -235,6 +235,7 @@ def electrum_public(master_public_key): network.bip32_as_string = bip32_as_string network.bip49_as_string = bip49_as_string + network.bip84_as_string = bip84_as_string network.sec_text_for_blob = sec_text_for_blob network.wif_for_blob = wif_for_blob From bd384aaa4fd077bb8281af22154d32c412268504 Mon Sep 17 00:00:00 2001 From: Juha Siivikko Date: Fri, 18 Jun 2021 15:10:55 +0300 Subject: [PATCH 2/3] Add args to get key ouput for bitcoin segwit and p2sh-segwit xpubs --- pycoin/cmds/ku.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pycoin/cmds/ku.py b/pycoin/cmds/ku.py index 799f5afb..a6ec00cc 100755 --- a/pycoin/cmds/ku.py +++ b/pycoin/cmds/ku.py @@ -43,7 +43,7 @@ def get_entropy(): return entropy -def create_output(item, key, output_key_set, subkey_path=None): +def create_output(item, key, output_key_set, args, subkey_path=None): output_dict = {} output_order = [] @@ -67,6 +67,18 @@ def add_output(json_key, value=None, human_readable_key=None): if subkey_path: add_output("subkey_path", subkey_path) + if args.p2sh_segwit: + add_output("p2sh_segwit wallet key", + key._network.bip49_as_string(key.serialize(as_private=True), as_private=True)) + add_output("p2sh_segwit public version", + key._network.bip49_as_string(key.serialize(as_private=False), as_private=False)) + + if args.segwit: + add_output("segwit wallet key", + key._network.bip84_as_string(key.serialize(as_private=True), as_private=True)) + add_output("segwit public version", + key._network.bip84_as_string(key.serialize(as_private=False), as_private=False)) + for k, v, text in key.ku_output(): add_output(k, v, text) @@ -108,6 +120,8 @@ def create_parser(): parser.add_argument('-b', "--brief", nargs="*", help='brief output; display a single field') parser.add_argument('-s', "--subkey", help='subkey path (example: 0H/2/15-20)', default="") + parser.add_argument("--p2sh-segwit", help='output bitcoin non-native segwit xpub', action='store_true') + parser.add_argument("--segwit", help='output bitcoin segwit xpub', action='store_true') parser.add_argument('-n', "--network", help='specify network', choices=codes) parser.add_argument( "--override-network", help='override detected network type', default=None, choices=codes) @@ -218,7 +232,7 @@ def parse_stdin(): if args.public: key = key.public_copy() - output_dict, output_order = create_output(item, key, output_key_set) + output_dict, output_order = create_output(item, key, output_key_set, args) generate_output(args, output_dict, output_order) From d6fd6169e952531704775a40c17d2b03c4815483 Mon Sep 17 00:00:00 2001 From: Juha Siivikko Date: Tue, 10 Aug 2021 16:36:27 +0300 Subject: [PATCH 3/3] Detect if we are in a segwit supported network and that the item provided is a bip node. Remove args from cmd use --- pycoin/cmds/ku.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/pycoin/cmds/ku.py b/pycoin/cmds/ku.py index a6ec00cc..990bd8c3 100755 --- a/pycoin/cmds/ku.py +++ b/pycoin/cmds/ku.py @@ -13,7 +13,6 @@ from pycoin.networks.default import get_current_netcode from pycoin.networks.registry import network_codes, network_for_netcode - HASH160_RE = re.compile(r"^([0-9a-fA-F]{40})$") @@ -43,7 +42,7 @@ def get_entropy(): return entropy -def create_output(item, key, output_key_set, args, subkey_path=None): +def create_output(item, key, output_key_set, subkey_path=None): output_dict = {} output_order = [] @@ -67,17 +66,20 @@ def add_output(json_key, value=None, human_readable_key=None): if subkey_path: add_output("subkey_path", subkey_path) - if args.p2sh_segwit: - add_output("p2sh_segwit wallet key", - key._network.bip49_as_string(key.serialize(as_private=True), as_private=True)) - add_output("p2sh_segwit public version", - key._network.bip49_as_string(key.serialize(as_private=False), as_private=False)) - - if args.segwit: - add_output("segwit wallet key", - key._network.bip84_as_string(key.serialize(as_private=True), as_private=True)) - add_output("segwit public version", - key._network.bip84_as_string(key.serialize(as_private=False), as_private=False)) + if isinstance(key, BIP32Node): + if(key._network.parse._bip49_pub_prefix and key._network.parse._bip49_prv_prefix): + if key._secret_exponent: + add_output("p2sh_segwit wallet key", + key._network.bip49_as_string(key.serialize(as_private=True), as_private=True)) + add_output("p2sh_segwit public version", + key._network.bip49_as_string(key.serialize(as_private=False), as_private=False)) + + if(key._network.parse._bip84_pub_prefix and key._network.parse._bip84_prv_prefix): + if key._secret_exponent: + add_output("segwit wallet key", + key._network.bip84_as_string(key.serialize(as_private=True), as_private=True)) + add_output("segwit public version", + key._network.bip84_as_string(key.serialize(as_private=False), as_private=False)) for k, v, text in key.ku_output(): add_output(k, v, text) @@ -120,8 +122,6 @@ def create_parser(): parser.add_argument('-b', "--brief", nargs="*", help='brief output; display a single field') parser.add_argument('-s', "--subkey", help='subkey path (example: 0H/2/15-20)', default="") - parser.add_argument("--p2sh-segwit", help='output bitcoin non-native segwit xpub', action='store_true') - parser.add_argument("--segwit", help='output bitcoin segwit xpub', action='store_true') parser.add_argument('-n', "--network", help='specify network', choices=codes) parser.add_argument( "--override-network", help='override detected network type', default=None, choices=codes) @@ -232,7 +232,7 @@ def parse_stdin(): if args.public: key = key.public_copy() - output_dict, output_order = create_output(item, key, output_key_set, args) + output_dict, output_order = create_output(item, key, output_key_set) generate_output(args, output_dict, output_order)