mcdallas / cryptotools

MIT License
206 stars 80 forks source link

Litecoin support? Get address from Ltub? #29

Closed jensb89 closed 2 years ago

jensb89 commented 2 years ago

Just a question and not an issue: is it possible to also obtain the litecoin addresses from an Ltub key? Should be very similar to the Xpub right?

I tried to overwrite some network settings like this:

cryptotools.BTC.network.main["extended_pub"]["P2PKH"] = b'\x01\x9d\xa4\x62'  #Ltub
cryptotools.BTC.network.main["hrp"] = 'ltc' 

and then

extended = Xpub.decode('Ltub...')
child = extended/0/0
print(child.key.to_address('P2WPKH')) #native segwit
print(child.key.to_address('P2PKH')) #Pay-to-Pubkey Hash - legacy  
print(child.key.to_address('P2WPKH-P2SH')) #segwit

... but I guess I'm still missing something. For starters I guess the derivation path is still wrong and must be M/x/x/1/0/0 instead of 0/0/0. But I can't change it and didn't find the hard coded 0 for bitcoin?! Where is the coin type (0 for bitcoin) defined?

Any idea? Would it even work like that? :D Thanks :)

mcdallas commented 2 years ago

Should be doable but I don’t think setting the values like that works, probably better to fork it and change the magic bytes in network.py. You might also need to change the network bytes for the address generation for example setting cryptotools.BTC.network.main[‘keyhash’] to b’\x30’(from this SE answer)

jensb89 commented 2 years ago

Thanks for the fast reply, I will give it a try.

jensb89 commented 2 years ago

Update for everyone else reading this: It seems to work by just overwriting the main network settings like this:

cryptotools.BTC.network.main["extended_pub"]["P2PKH"] = b'\x01\x9d\xa4\x62' #Ltub
cryptotools.BTC.network.main["hrp"] = 'ltc'
cryptotools.BTC.network.main["keyhash"] = b'\x30'
cryptotools.BTC.network.main["scripthash"] = b'\x32' #for the new M-addresses
cryptotools.BTC.network.main["wif"] = b'\x37' #not important?

Thanks again for the link :)