python-bip380 icon indicating copy to clipboard operation
python-bip380 copied to clipboard

hash160 may not always work

Open Eunovo opened this issue 2 years ago • 2 comments

The hash160 implementation at https://github.com/darosior/python-bip380/blob/d2f5d8f5b41cba189bd793c1081e9d61d2d160c1/bip380/utils/hashes.py#L14-L17 uses hashlib to create a ripemd160 digest. The ripemd160 digest is not among hashlib's guaranteed algorigthms so this function may fail on some platforms with a ValueError: unsupported hash type ripemd message. I experienced this while trying to run liana's tests.

Would it be a bad idea to check for the presence of 'ripemd160' in hashlib.algorithms_available and output an appropriate error message before trying to create the ripemd160 digest?

Eunovo avatar May 10 '23 22:05 Eunovo

I think we should use Bitcoin Core's Python implementation from https://github.com/bitcoin/bitcoin/pull/23716.

darosior avatar May 12 '23 08:05 darosior

Also relevant, what we did for Python-bip32: https://github.com/darosior/python-bip32/pull/33 (link to the file: https://github.com/darosior/python-bip32/blob/master/bip32/ripemd160.py).

darosior avatar May 12 '23 08:05 darosior