Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add segwit xpub to ku #384

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions pycoin/cmds/ku.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of making it an option, can you simply look to see if the network supports bip49 and/or bip84, and always print it if so?

This will break a lot of tests because it will add output. Go ahead and eyeball the diffs, and if they look okay, I can quickly repair them after I commit your fix (using this REPAIR_TESTS=1 py.test tests trick – it will rewrite the broken tests. If you can't figure out what I'm talking about, I'm happy to repair the tests, since it takes just a minute).

output_dict = {}
output_order = []

Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions pycoin/networks/bitcoinish.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down