matja / bitcoin-tool

Tool for converting Bitcoin keys and addresses
215 stars 118 forks source link

bech32 address format added #36

Closed ghost closed 4 years ago

ghost commented 4 years ago

this adds an input/output format 'bech32' which enables the generation of p2wpkh addresses like bc1qhmc0vk4xzr37ayv7tlyhns7x4dk04tyvflk8ey. 3 new tests have been added:

example usage: ./bitcoin-tool --network bitcoin --input L3GzRAGwCqfSNFr6g1NQm7edn29DgAKZJ6owUBqYELpP6Kbim5kM --input-type private-key-wif --input-format base58check --output-type address --output-format bech32

matja commented 4 years ago

Nice work, thanks! In the updated prefix.c , where do the ".hrp" values come from? I found a few definitions in src/chainstate.cpp for various chains, but some I was not able to find. I'll update that file with the references that I could find.

matja commented 4 years ago

Fixed a small issue with extra NUL chars in bech32 output: 6fcafaf0489ab8b5eced8e3ac6223c6255d213d2

matja commented 4 years ago

Added references to prefixes that I could find: f19505408cbdf853523dc595679e7c93ffbcfb63

ghost commented 4 years ago

Hi @matja, the hrp values came from chainparams.cpp in some projects, others such as dogecoin don't yet support bech32; in those cases I guessed an appropriate hrp in preference to leaving it blank and possibly having an extra edge case to handle. Thanks for fixing the issue with extra NUL chars in output - I missed that as they did not show up on my console, so good catch!