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

WIP: descriptor request using "getkeys" #73

Closed
wants to merge 3 commits into from

Conversation

Sjors
Copy link
Member

@Sjors Sjors commented Dec 3, 2018

Todo:

Implements getkeys as proposed here.

Update 2019/02/02: this used to include #117, which I've moved to a new PR

@Sjors Sjors changed the title 2018/11/getkeys Add getkeys, require descriptor for displayaddress Dec 4, 2018
@achow101
Copy link
Member

achow101 commented Dec 4, 2018

Needs rebase as #66 has been merged.

@Sjors
Copy link
Member Author

Sjors commented Dec 4, 2018

@achow101 rebased, but I'm not happy with signtransaction just yet. Right now it requires a fingerprint argument. Ideally this should be inferred from the PSBT, but I have no idea how. Also it currently hardcodes Testnet, which I would also like to infer from the PSBT.

@Sjors Sjors changed the title Add getkeys, require descriptor for displayaddress Add getkeys, support descriptor for displayaddress Dec 5, 2018
@Sjors
Copy link
Member Author

Sjors commented Dec 5, 2018

I removed the code that inferred Testnet from the BIP32 derivation, instead relying on --testnet being set.

I'm just leaving the --fingerprint argument required for signtransaction for now.

@Sjors Sjors changed the title Add getkeys, support descriptor for displayaddress Add getkeys, displayaddress descriptors, rename signtx, use named arguments Dec 13, 2018
hwilib/descriptor.py Outdated Show resolved Hide resolved
hwilib/descriptor.py Show resolved Hide resolved
hwilib/commands.py Outdated Show resolved Hide resolved
hwilib/commands.py Outdated Show resolved Hide resolved
hwilib/commands.py Outdated Show resolved Hide resolved
hwilib/commands.py Outdated Show resolved Hide resolved
hwilib/commands.py Outdated Show resolved Hide resolved
hwilib/commands.py Outdated Show resolved Hide resolved
hwilib/commands.py Outdated Show resolved Hide resolved
@Sjors
Copy link
Member Author

Sjors commented Dec 21, 2018

Regarding global variables, I'm not sure what the right approach is.

I guess if we translate this to gRPC we could use POST /:fingerprint/signtransaction with {psbt: ....} as the payload.

However some methods don't need the fingerprint argument because it's in the descriptor. Unless we just require this redundantly: POST /:fingerprint/displayaddress with {descriptor: "wpkh([fingerprint]/84'/1/'/0'....)", "testnet": true}

Do we also want testnet to be global?

@instagibbs
Copy link
Collaborator

Can we mark this as WIP if the Core branch is unmerged?

@Sjors Sjors changed the title Add getkeys, displayaddress descriptors, rename signtx, use named arguments WIP: Add getkeys, displayaddress descriptors, rename signtx, use named arguments Jan 14, 2019
@Sjors Sjors changed the title WIP: Add getkeys, displayaddress descriptors, rename signtx, use named arguments Descriptor support for getkeys & displayaddress, use named psbt argument Jan 14, 2019
@Sjors Sjors changed the title Descriptor support for getkeys & displayaddress, use named psbt argument Add getkeys, add descriptor support to displayaddress, use named psbt argument Jan 14, 2019
@Sjors
Copy link
Member Author

Sjors commented Jan 14, 2019

I narrowed the scope a bit, so hopefully it doesn't have to stay in WIP limbo:

  • no longer supporting redundant ability to put global params at the end
  • no longer renaming signtransaction to signtx

The only backwards incompatible changes are:

  • psbt is now a named argument. If necessary I can change that so the position argument is optional but still possible.
  • displayaddress no longer uses a positional argument; use --path or --descriptor. Again, I could make this backwards compatible.

getkeys usage:

$ ./hwi.py --testnet --fingerprint 00000000 getkeys --desc "wpkh(00000000/84'/1'/0'/0/*)"
["wpkh([00000000/84'/1'/0']tpub.../0/*"]

displayaddress usage with descriptor:

./hwi.py --testnet --fingerprint 00000000 displayaddress --desc "wpkh(00000000/84'/1'/0'/0/0)"

@Sjors Sjors force-pushed the 2018/11/getkeys branch 2 times, most recently from 1ffe395 to 6b645b3 Compare January 14, 2019 17:30
displayaddr_parser.add_argument('--sh_wpkh', action='store_true', help='Display the p2sh-nested segwit address associated with this key path')
displayaddr_parser.add_argument('--wpkh', action='store_true', help='Display the bech32 version of the address associated with this key path')
group = displayaddr_parser.add_mutually_exclusive_group()
group.add_argument('--desc', help='Pseudo-descriptor for which to return a descriptor with keys, e.g. wpkh(00000000/84h/1h/0h/0/*). Alternatively, use --path with --sh_wpkh / --wpkh')
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is "psuedo" about the option?

Copy link
Member Author

@Sjors Sjors Jan 15, 2019

Choose a reason for hiding this comment

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

I'm calling it a pseudo-descriptor, because there's no public key in it. The goal of a pseudo-descriptor like wpkh(00000000/84h/1h/0h/0/*) is to ask for an actual descriptor wpkh(00000000/84h/1h/0h/tpub..../0/*) with a public key inserted in the right place. That's not covered in @sipa's document: https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md

Ideally I would just call that a descriptor as well, but I don't know if that makes sense in the scheme of things.

Copy link
Collaborator

Choose a reason for hiding this comment

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

On further thought, I think these are ok. Might want to call them something like "descriptor requests" or something, and say exactly what info must reside in the requests, and what's missing.

@achow101
Copy link
Member

I don't follow why signtx needs psbt to be a named argument.

@Sjors
Copy link
Member Author

Sjors commented Jan 16, 2019

@achow101 I made everything a named argument, because it's easier to translate to an RPC.

@achow101
Copy link
Member

How does that make it easier to translate to an RPC?

I really dislike having command line switches for things that are required. It implies that the parameter is optional and has a default value, but it's actually required. It's an extra couple of characters that you now have to always type.

@Sjors
Copy link
Member Author

Sjors commented Jan 21, 2019

I'm still trying to figure out how this mapping would work. I see it's still possible to use a special purpose value field in the JSON payload to deal with a positional argument: https://grpc.io/blog/coreos

So I'll change psbt back to positional, same with --desc for getkeys. That's not possible for displayaddress --path / --descriptor though, unless we try to guess based on the format of the positional argument.

@instagibbs
Copy link
Collaborator

just leaving this here since I went to the stale branch: bitcoin/bitcoin#14912

@Sjors
Copy link
Member Author

Sjors commented Jan 21, 2019

Thanks, I closed that PR and updated the description above.

The branch wasn't stale by the way, but the PR discussion and description was out of date.

@Sjors
Copy link
Member Author

Sjors commented Jan 24, 2019

  • renamed "pseudo descriptor" to "descriptor request" (which now requires square brackets around the origin part, so it's exactly like a descriptor with origin info, but without the public key)
  • cleaned op the descriptor.py and added tests
    (I also pushed the corresponding changes to bitcoind)

@Sjors Sjors changed the title Add getkeys, add descriptor support to displayaddress, use named psbt argument WIP: descriptor request using "getkeys" Feb 2, 2019
@Sjors
Copy link
Member Author

Sjors commented Feb 2, 2019

I extracted the descriptor class and displayaddress changes into a new PR #117.

I'm no longer sure if descriptor requests are the right approach. Ultimately we're only asking the device for a key at a certain derivation path. That key is the same regardless of what descriptor it's used in. So it makes more sense for Bitcoin Core to just directly ask for the key using getxpub, and then it can construct the descriptor. It won't need getkeypool in any case.

It's still important for Bitcoin Core to know which kinds of things the device can sign, especially if we start adding more complicated stuff like multisig. Perhaps enumerate is the right place for that. That would still require some standard way of expressing these capabilities.

Something similar to descriptors, but perhaps with wildcards, e.g.: ["pkh("44'/1'/$'/{0,1}/*"), sh(wpkh("49'/1'/$'/{0,1}/*")), wpkh("84'/1'/$'/{0,1}/*")] would be returned by a device that supports legacy, wrapped segwit and segwit native, when called with --testnet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants