BitcoinPublicKey("wrong")
result: ValueError: Public key is not in proper format
BitcoinPrivateKey("wrong")
result: AssertionError
Explanation:
Unless there are some reasons why this has been implemented this way, I believe BitcoinPrivateKey should follow the same behavior of BitcoinPublicKey.
try/exception of invalid keys should look the same, while (as it is now) different exceptions are being presented.
Reason:
While the file publickey.py presents a get_public_key_format function (which handles invalid formats with a ValueError), its counterpart get_privkey_format in main.py leaves this job to the function b58check_to_bin.
Possible solution:
the call to b58check_to_bin in get_privkey_format should be wrapped in a try block, the AssertionError should be caught and a ValueError should be raised instead.
Impact:
I have not considered the impact of such a change nor possible regressions.
BitcoinPublicKey("wrong")
result:ValueError: Public key is not in proper format
BitcoinPrivateKey("wrong")
result:AssertionError
Explanation: Unless there are some reasons why this has been implemented this way, I believe
BitcoinPrivateKey
should follow the same behavior ofBitcoinPublicKey
.try/exception of invalid keys should look the same, while (as it is now) different exceptions are being presented.
Reason: While the file
publickey.py
presents aget_public_key_format
function (which handles invalid formats with a ValueError), its counterpartget_privkey_format
inmain.py
leaves this job to the functionb58check_to_bin
.Possible solution: the call to
b58check_to_bin
inget_privkey_format
should be wrapped in a try block, theAssertionError
should be caught and aValueError
should be raised instead.Impact: I have not considered the impact of such a change nor possible regressions.