pycoin icon indicating copy to clipboard operation
pycoin copied to clipboard

Unable to derive public address for Bitcoin Cash ABC (BCH)

Open nandubatchu opened this issue 5 years ago • 3 comments

@richardkiss Not working for both mainnet (BCH) and testnet (XCH).

rand = codecs.encode(os.urandom(32), 'hex').decode()
key = Key(secret_exponent=int('0x' + rand, 0), netcode="XCH")

in create_account
    address = key.address()
in address
    return hash160_sec_to_bitcoin_address(hash160, address_prefix=address_prefix)
in hash160_sec_to_bitcoin_address
    return b2a_hashed_base58(address_prefix + hash160_sec)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'bytes'

nandubatchu avatar Jan 31 '19 07:01 nandubatchu

@richardkiss I see that BCH and XCH are missing in the _NETWORK_PREFIXES variable.

I guess this part of code is not release to pypi package version 0.80. Can you validate?

nandubatchu avatar Jan 31 '19 07:01 nandubatchu

Try now. I get

>>> from pycoin.symbols.xch import network
>>> network.keys.private(1).wif()
'cMahea7zqjxrtgAbB7LSGbcQUr1uX1ojuat9jZodMN87JcbXMTcA'
>>> network.keys.private(1).address()
'mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r'

>>> from pycoin.symbols.bch import network
>>> network.keys.private(1).address()
'1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH'
>>> network.keys.private(1).wif()
'KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn'

Are XCH and BCH still using base58 or have they switched to bech32?

richardkiss avatar Jul 08 '19 17:07 richardkiss

Hi,

Thank you for making this package.

Bitcoin Cash uses a variant of bech32 called CashAddress. The specification can be found, for example, here: https://flowee.org/docs/spec/blockchain/encoding/cashaddr/

A Python implementation handling conversion between base58 and CashAddress can be found here: https://github.com/oskyk/cashaddress

Using those resources as reference, implementing CashAddress in pycoin should be fairly straightforward.

Thanks again, and looking forward towards using your package in my future projects!

simon-v avatar Oct 17 '21 17:10 simon-v