matja / bitcoin-tool

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

--output-type all results in 5 errors #41

Open streamofstars opened 4 years ago

streamofstars commented 4 years ago

After adding Bech32 support in #36 the example from the README.md yields multiple errors.

./bitcoin-tool \
    --input-type private-key \
    --input-format raw \
    --input-file <(echo -n sausage|openssl dgst -sha256 -binary) \
    --public-key-compression uncompressed \
    --network bitcoin \
    --output-type all

output:

address.hex:000511096ab078473911e0222fcbc3375314e2bab1
address.base58:156T6Af12SKCQGbjEWNeTkADhJNk
address.base58check:1TnnhMEgic5g4ttrCQyDopwqTs4hheuNZ
address.bech32:bc1qq5gsj64s0prnjy0qyghuhseh2v2w9w43dqsgr5
address-checksum.hex:000511096ab078473911e0222fcbc3375314e2bab101490d3a
address-checksum.base58:1TnnhMEgic5g4ttrCQyDopwqTs4hheuNZ
Failed to encode raw output data (unknown result code)
address-checksum.bech32:public-key-ripemd160.hex:0511096ab078473911e0222fcbc3375314e2bab1
public-key-ripemd160.base58:56T6Af12SKCQGbjEWNeTkADhJNk
public-key-ripemd160.base58check:TnnhMEgic5g4ttrCQyDopwqTs4k6XbAK
Failed to encode raw output data (unknown result code)
public-key-ripemd160.bech32:public-key-sha256.hex:b17978b7528353483429a758fb9ec833882a5ddbb27c1fc2bb4a66436f7e342f
public-key-sha256.base58:CwnbNMmu9yCkXE32543pfPAgVSynE2wjGYv9Mip4yrb8
public-key-sha256.base58check:2MAMBCve8eVyrbxxBzqn5HLNqqyc8CysKPdfaKPzA81mHxPvyu
Failed to encode raw output data (unknown result code)
public-key-sha256.bech32:public-key.hex:04a32ed011213146495f58d3ed83a6cc3fc0fd107d5fa2887bbc2fcea81e8bc84f650e81f4ddc84424daab546945f0d7d9dfd4dce39ce3776ee6b8ba78e6eddc7a
public-key.base58:QjfX2h4LdAA21NTa2K5dVcxcuQVTtvT3dL5JFLvxAMuCGKY3t8yCKNzJid8MHWbYmoHSRXAS9hggkhQUDiwaaGAV
public-key.base58check:3gKQTqtZhdBHDDe1echja7ac39tup3SnNSzwZSrnHb417QbL7T8JcTfW7GgEQsvhYrPqLsiraabne6xDrSGZ6bBB4S5YGM
Failed to encode raw output data (unknown result code)
public-key.bech32:private-key-wif.hex:8030caae2fcb7c34ecadfddc45e0a27e9103bd7cfc87730d7818cc096b1266a683
private-key-wif.base58:f5g1GA5uH4gsfEU6ANnGCzoe1VZvnZ1mYh3frnVSPR1nJ
private-key-wif.base58check:5JBmuBc64pVrKLyDc8ktyXJmAeEwKQogn6jsk6taeq8zRMtGZrE
private-key-wif.bech32:bc1qxr92ut7t0s6wet0am3z7pgn7jypm6l8usaes67qcesykkynx56psr2ua62
private-key.hex:30caae2fcb7c34ecadfddc45e0a27e9103bd7cfc87730d7818cc096b1266a683
private-key.base58:4HTpd7gVSeVJDurhJKYGEYyFWMZRCNjSnXaEcan9K6Gz
private-key.base58check:NVKW9zzMvs4LawZwJztUZdx3R27Gwc4Hg6WvqqQxHMFkbn3Wz
Failed to encode raw output data (unknown result code)
private-key.bech32:

Also, there is some redirection order problem as Failed to encode raw output data (unknown result code) messages are thrown before the actual problematic line. Those lines are getting mixed with the next lines (no newline characters?). It should look more or less like this:

address.hex:000511096ab078473911e0222fcbc3375314e2bab1
address.base58:156T6Af12SKCQGbjEWNeTkADhJNk
address.base58check:1TnnhMEgic5g4ttrCQyDopwqTs4hheuNZ
address.bech32:bc1qq5gsj64s0prnjy0qyghuhseh2v2w9w43dqsgr5
address-checksum.hex:000511096ab078473911e0222fcbc3375314e2bab101490d3a
address-checksum.base58:1TnnhMEgic5g4ttrCQyDopwqTs4hheuNZ
address-checksum.bech32:Failed to encode raw output data (unknown result code)
public-key-ripemd160.hex:0511096ab078473911e0222fcbc3375314e2bab1
public-key-ripemd160.base58:56T6Af12SKCQGbjEWNeTkADhJNk
public-key-ripemd160.base58check:TnnhMEgic5g4ttrCQyDopwqTs4k6XbAK
public-key-ripemd160.bech32:Failed to encode raw output data (unknown result code)
public-key-sha256.hex:b17978b7528353483429a758fb9ec833882a5ddbb27c1fc2bb4a66436f7e342f
public-key-sha256.base58:CwnbNMmu9yCkXE32543pfPAgVSynE2wjGYv9Mip4yrb8
public-key-sha256.base58check:2MAMBCve8eVyrbxxBzqn5HLNqqyc8CysKPdfaKPzA81mHxPvyu
public-key-sha256.bech32:Failed to encode raw output data (unknown result code)
public-key.hex:04a32ed011213146495f58d3ed83a6cc3fc0fd107d5fa2887bbc2fcea81e8bc84f650e81f4ddc84424daab546945f0d7d9dfd4dce39ce3776ee6b8ba78e6eddc7a
public-key.base58:QjfX2h4LdAA21NTa2K5dVcxcuQVTtvT3dL5JFLvxAMuCGKY3t8yCKNzJid8MHWbYmoHSRXAS9hggkhQUDiwaaGAV
public-key.base58check:3gKQTqtZhdBHDDe1echja7ac39tup3SnNSzwZSrnHb417QbL7T8JcTfW7GgEQsvhYrPqLsiraabne6xDrSGZ6bBB4S5YGM
public-key.bech32:Failed to encode raw output data (unknown result code)
private-key-wif.hex:8030caae2fcb7c34ecadfddc45e0a27e9103bd7cfc87730d7818cc096b1266a683
private-key-wif.base58:f5g1GA5uH4gsfEU6ANnGCzoe1VZvnZ1mYh3frnVSPR1nJ
private-key-wif.base58check:5JBmuBc64pVrKLyDc8ktyXJmAeEwKQogn6jsk6taeq8zRMtGZrE
private-key-wif.bech32:bc1qxr92ut7t0s6wet0am3z7pgn7jypm6l8usaes67qcesykkynx56psr2ua62
private-key.hex:30caae2fcb7c34ecadfddc45e0a27e9103bd7cfc87730d7818cc096b1266a683
private-key.base58:4HTpd7gVSeVJDurhJKYGEYyFWMZRCNjSnXaEcan9K6Gz
private-key.base58check:NVKW9zzMvs4LawZwJztUZdx3R27Gwc4Hg6WvqqQxHMFkbn3Wz
private-key.bech32:Failed to encode raw output data (unknown result code)

If it is hard to spot above, the following lines throw errors before them:

address-checksum.bech32:
public-key-ripemd160.bech32:
public-key-sha256.bech32:
public-key.bech32:
private-key.bech32:
matja commented 4 years ago

Good spot, thanks. I think it would be better to remove the invalid output lines entirely rather than output text which might be misinterpreted as valid input.

matja commented 4 years ago

Pushed a change which removes the errors from the output, but after looking into this some more, I'm not entirely sure why the errors are being returned - even though we don't want Bech32 addresses at all for uncompressed public keys (like #40). Leaving this open to investigate this some more.