1200wd / bitcoinlib

Bitcoin and other Cryptocurrencies Library for Python. Includes a fully functional wallet, Mnemonic key generation and management and connection with various service providers to receive and send blockchain and transaction information.
http://bitcoinlib.readthedocs.io/
GNU General Public License v3.0
615 stars 203 forks source link

Unable to decode bech32m addresses #203

Closed zeevo closed 2 years ago

zeevo commented 3 years ago

Hello

I am seeing an EncodingError when trying to decode bech32m addresses. Bech32m is a new address format proposed in BIP-0350 and released in Bitcoin Core 0.21.1.

To recreate the EncodingError:

from bitcoinlib.encoding import addr_to_pubkeyhash

addr_to_pubkeyhash("bc1q23jjzgdmuf2kgt959jpjl5tsq3kaynn86qvrcf", True) # Real bech32 address

addr_to_pubkeyhash("abcdef1l7aum6echk45nj3s0wdvt2fg8x9yrzpqzd3ryx", True) # Valid bech32m address. Throws Exception.

Are there any plans to support bech32m decoding?

mccwdev commented 2 years ago

Commit https://github.com/1200wd/bitcoinlib/commit/2308c18a53d1db5fff9962f2b1077098fa891a35 adds support for bech32 addresses.

The second example still throws an exception, because the decoded data length is longer then 16 bytes. Address is a valid bech32 address, but I don't think it will be accepted by the bitcoin network.