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
Implemented segwit address types. Moved PrivKey into its own module. #62
Conversation
PrivKey isn't really "shadowing SecretKey". A private key represents the secret data associated with a Bitcoin address, which includes a secp secret key, a network ID a compression flag. You can't do anything Bitcoin-related without all three of those. |
@apoelstra I viewed network dependant serialization as purely UI concept and assumed that compressed/uncompressed is deprecated, hence I saw no reason for PrivKey. I go with your choice however and restored PrivKey. Changed however some signatures to unify their argument order and to support legacy address (so it has more reasons to exist). |
It's not "network dependent serialization", private keys on one network are really genuinely distinct from private keys on other networks and if it's possible to confuse them then I expect Bad Things will happen. If you want just an ECDSA secret key, the secp I could maybe be convinced that compressed keys are "deprecated". But this is a consensus system and for people who still have coins backed by uncompressed keys, their only way to upgrade is to move them, which requires using those keys. And support for uncompressed keys is not exactly a lot of code, it's just a couple I would support moving the uncompressed key support into separate _uncompressed functions, rather than a boolean argument, if you just want to use the API without being bothered by the distinction. |
As for the supported networks (Testnet and Bitcoin), the only difference of private keys is what was introduced through their serialization, certainly to avoid that people mix them up and bad things happen. PrivKey makes sense if one assumes additional networks in future or that e.g. testnet uses a signature algo not yet available on mainnet, I go with that. Similarly understand that e.g. Satoshi has coins on uncompressed keys, but wonder if he needs rust-bitcoin's help. This library does not have to promise the backward compatibility and consensus of Bitcoin Core (the second it can't), but could be a tool to create new software. It is your baby, therefore I respect your preference what it should aim for. As for the compressed flag, I would prefer having distinct API to emphasize that they are there is only for legacy reasons and also because bool flags are ugly. Should I rewrite the API like that or just drop this PR? |
Sure, I'd be happy with a distinct API for uncompressed keys. And testnet/mainnet have diverged in the past, consider how long Segwit signatures were valid on testnet but not on mainnet. |
@apoelstra added support also for segwit adresses |
A couple comments:
|
|
What does "help to differentiate" mean? The Run |
Run bitcoin-cli The reason to differentiate addresses (also with WithnessUse) that one is able to construct the correct redeem script to access the coins. |
Why doesn't Core differentiate addresses like this to avoid the incorrect Can you provide example code for rust-bitcoin constructing a redeem script from an |
that redeems script must have placeholders for signatures. Do you have a preference how this should be represented? |
the validateadress output is correct in the sense that it only uses the address as input and its output is a possible script for that address, which is however not what Satoshi used. The problem is that conversion to human readable address string is not reversible in some cases as the serialization drops this information. |
Actually it is a nice and necessary project (within rust-bitcoin) on its own to create a framework to compile and sign redeem scripts given an address and private keys. If you allow I would do that in an other PR. But I am sure WittnessUse will be needed for that. |
Thank you, this is what I trying to get at. You cannot represent this data in the
Sure, I'd appreciate that.
I highly doubt that. |
No problem, I remove it and re-introduce if you are wrong. |
removed WittnessUse and squashed everything into 1 commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your patience. Looks good now.
PrivKey was shadowing SecretKey only to implement a WIF, removed.
Implemented pay-to-pk address
unified parameter order as: key, compressed, network