Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Inconsistent management of invalid values in BitcoinPrivateKey #48

@Saturnix

Description

@Saturnix

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions