vbuterin / pybitcointools

SImple, common-sense Bitcoin-themed Python ECC library
1.3k stars 861 forks source link

testnet address from privkey is generated incorrectly #27

Closed themighty1 closed 10 years ago

themighty1 commented 10 years ago

While on testnet in bitcoind I dumpprivkey and do pubtoaddr(privtopub(dumped_privkey)) The resulting address is incorrect, in fact it starts with 1.

vbuterin commented 10 years ago

Can you give me an example (privkey, bitcoind's answer, pybitcointools' answer)?

On 14-05-16 05:11 PM, themighty1 wrote:

While on testnet in bitcoind I dumpprivkey and do pubtoaddr(privtopub(dumped_privkey)) The resulting address is incorrect, in fact it starts with 1.

— Reply to this email directly or view it on GitHub https://github.com/vbuterin/pybitcointools/issues/27.

themighty1 commented 10 years ago

in bitcoind: testnet address: mx7awLSCWExnQUCRQbbrEEKTvknbgSqoQ6 validateaddress mx7awLSCWExnQUCRQbbrEEKTvknbgSqoQ6 pubkey --> 02964eaf969236b4e03df36c03970e0a8c00cc2943c94c7642ad8fc0ea62684220 dumprivkey mx7awLSCWExnQUCRQbbrEEKTvknbgSqoQ6 privkey --> cSSBbV5tE4KCjwL3e1gAt1zihLGRpCmBTQJQfJunwDS9canNTtN2

in pybitcointools: privtopub('cSSBbV5tE4KCjwL3e1gAt1zihLGRpCmBTQJQfJunwDS9canNTtN2') '02964eaf969236b4e03df36c03970e0a8c00cc2943c94c7642ad8fc0ea62684220' <---correct pubtoaddr('02964eaf969236b4e03df36c03970e0a8c00cc2943c94c7642ad8fc0ea62684220') '1HbdeHMDhDXXdMioh2dUQK794mBtp9LQuN' <-- 'incorrect'

reiven commented 10 years ago

You need to add the "testnet magic byte" which is 111 (see https://en.bitcoin.it/wiki/List_of_address_prefixes):

>>> pubtoaddr('02964eaf969236b4e03df36c03970e0a8c00cc2943c94c7642ad8fc0ea62684220',111)
'mx7awLSCWExnQUCRQbbrEEKTvknbgSqoQ6'

@vbuterin maybe it will be a good idea to add a small section in the README for "testnet" parameters for functions which accepts parameters for addresses/multisig, etc. I can give you hand with that if you agree

themighty1 commented 10 years ago

Thank you reiven, that worked.