ranaroussi / pywallet

Dead-simple BIP32 (HD) wallet creation for BTC, BTG, BCH, LTC, DASH, USDT, QTUM and DOGE
MIT License
453 stars 180 forks source link

Bitcoin Cash addresses not valid #31

Closed merc1er closed 5 years ago

merc1er commented 6 years ago

Addresses generated using the Bitcoin Cash (BCH) network are not valid, while they are when using the Bitcoin Core (BTC) network.

Here is an example of returned addresses running the following code:

from pywallet import wallet
import pprint as pp

# generate 24 word mnemonic seed
seed = wallet.generate_mnemonic(strength=256)

w = wallet.create_wallet(network='BCH', seed=seed, children=10)

pp.pprint(w)

Returns:

...
{'address': 'CNzDhHkL3B5ubi5439mi57HgQD8UKQKFvA',
 'children': [{'address': 'CPFDNsRBFDqRKBqx3v1oqtya9NcdoaJaVr',
              {'address': 'CHwdg1ud5UGEGH5zPdSFTDNqq8yL8WoqZZ',
              {'address': 'CSKzN9vteXumbeLLtmuqxS1GYLMfBwxd6N',
              {'address': 'CTmbWvsnc6MSJ7t2Zi7WhJ3oxptE76GFJJ',
              {'address': 'Cb1CuvHuEdPVKYVfMRXzoxe18EYLtg76vF',
              {'address': 'CfmWPcgkLR56N4XwHYaEhXVEhMiXoaSvuw',
              {'address': 'CaQEjsCHHMy7mWmkFMvwCu1Ma13nd1tybL',
              {'address': 'CZQ5KpGKc5ubjWQ2GN8ScKizkpKXRdnfhP',
              {'address': 'CYpSm7iWdapD8aWuXecBVpn8cSWr57mfRY',
              {'address': 'CdqVNvBWK4BC6EPVQZ54A4pvGxGpQVs6Re',
...

Which are not valid Bitcoin addresses.

merc1er commented 6 years ago

Okay so I dug deeper and I found out that the version bytes are incorrect for the BCH network in pywallet/network.py. See https://github.com/Bitcoin-ABC/bitcoin-abc/blob/master/src/chainparams.cpp

hurlenko commented 5 years ago

These are valid bitcoin cash addresses, though I don't recommend using this address format as it is not supported by most of the wallets. You can use this converter to convert between any of the 3 supported address types. Switch your application to CashAddr addresses, bitcoincash: prefixed