matja / bitcoin-tool

Tool for converting Bitcoin keys and addresses
206 stars 116 forks source link

is it possible to add --input-format int ? #20

Closed ghost closed 6 years ago

ghost commented 6 years ago

which will take int and convert it to hex

thanks

matja commented 6 years ago

To clarify, do you mean a decimal representation of a number?

Is there a common use-case for accepting decimal inputs? I haven't come across any need to use decimal input yet. Regardless, it is a simple change and I'll look into it - thanks for the suggestion.

ghost commented 6 years ago

please ignore my last message. as i had just started to learn about it.

but as i learn more., and i feel there is this app or script missing., which will take bitcoin address and convert it to hash160 format and other way around. it would be great if this could be implemented. input file with addresses and output file with hash160 or other way around.

thanks

matja commented 6 years ago

Conversion between address and hash160 format is possible with this tool. It is actually one of the tests in tests.sh : 11 - convert 'Hash 160' to address

The 'Hash 160' format is called public-key-rmd (rmd = RIPEMD160) in this tool.

Example to convert from address to public-key-rmd :

./bitcoin-tool \
--input-type address \
--output-type public-key-rmd \
--input-format base58check \
--network bitcoin \
--output-format hex \
--input 12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX

output: 119b098e2e980a229e139a9ed01a469e518e6f26

Example to convert from public-key-rmd to address :

./bitcoin-tool \
--input-type public-key-rmd \
--output-type address \
--input-format hex \
--network bitcoin \
--output-format base58check \
--input 119b098e2e980a229e139a9ed01a469e518e6f26

output: 12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX

Example to convert a file containing addresses to public-key-rmd : (I created 4 random addresses using the instructions at "Generate address from random private key" in README.md)

cat > addrs << EOF
1ArxEhBam1ThtTKC1oZMCSsouQZRW5W9r
14H8y3nHnRUTw63C28FzYSria7B4n6n4eW
1N8BuoWoWSWPa6h4yVo3xiKQJmYE3iu7aV
1wZWNAyjQc5xUBGEPFfwbhcRo2DCMhcNZ
EOF

./bitcoin-tool \
--batch \
--input-type address \
--output-type public-key-rmd \
--input-format base58check \
--network bitcoin \
--output-format hex \
--input-file addrs

output:

01dd7118282788012ded71f41b50419d3e724eea
23f5aec6038c5a52d1459b255ea37d2f05bcd956
e7b6a924c50d8a18d439f504e764cb4ca3cb092d
0a5198c976edf3994bfd95f04bb0b58e91062d33

I think that accomplishes what you describe, please tell me if you believe otherwise.

ghost commented 6 years ago

this is it, my quest is over. this is what i have been looking for, from last few days. thanks

agoora commented 6 years ago

Hi matja,

From input-file btcaddress.txt, I have this error message : "Failed to decode Base58Check input (checksum failure)." Please help me. Thanks.

matja commented 6 years ago

Does btcaddress.txt end with a newline character? For example, if you cat the file is the address output on its own line? If so, that is by design, to be strict about input decoding, although the error message could be better. Try adding --batch to the options, then the newline will be ignored, and used to delimit inputs instead.