iceland2k14/secp256k1

BTC Address : [Segwit ] Wrong

Closed this issue · 5 comments

import secp256k1_lib
bip44_h160_c = secp256k1_lib.privatekey_to_h160(0, True, 0xe0353e2293a63769802b1e3d0d9affdedfda4d4486ed300428eadac4620427bf)

secp256k1_lib.hash_to_address(1, False, bip44_h160_c)
'32Q5Sa9pTezVeBYBZitidknwTs1Gd9HmPJ' False
secp256k1_lib.hash_to_address(1, True, bip44_h160_c)
'32Q5Sa9pTezVeBYBZitidknwTs1Gd9HmPJ' False

PVK1 BTC Address : [Segwit ] 33eYbdrqZcxSXvPb26fj8KBqW4xxofzRpC True

why does the privatekey_to_h160 function need addr_type

if you do so : bip44_h160_c = secp256k1_lib.privatekey_to_h160(1, True, 0xe0353e2293a63769802b1e3d0d9affdedfda4d4486ed300428eadac4620427bf)
then the address will be correct

but what does the address type have to do with hash160?

Thanks in advance.
Thank you so much for your work.

Thanks @Noname400
Actually the reason to keep addr_type was just function reuse of same code.

For Legacy or bech32 address the hash160 is same so there is no difference in these 2. But for P2SH address situation is complicated as it needs double hash. (A hash160 of 0014+hash160.) That is the reason by decoding back p2sh address you can only go back 1 level up of hash160 and not the second level.

Let me think about if i can reorganise my functions any different. Currently i just kept the same so that they are equivalent with address to avoid confusion.

thx