Bitcoin Forum
May 11, 2024, 01:09:28 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Generating Litecoin Addresses from Electrum-LTC MPK  (Read 111 times)
xilcho (OP)
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
December 12, 2017, 11:11:29 PM
 #1

I have created code that generates BTC addresses from an Electrum MPK. I am trying to build something similar that generates LTC addresses instead of BTC addresses. Obviously, the addresses are different, but I am struggling to determine what needs to be changed. Can my code from the BTC address generation be repurposed to generate LTC addresses since they are both hashed with ECDSHA algorithm? If so, what do I need to modify in order to generate LTC addresses instead of BTC addresses? If anyone has any existing code samples or any other information regarding this topic, I would be very appreciative. I can't seem to find any information on generating LTC addresses from an Electrum-LTC mpk.

Thanks!
1715432968
Hero Member
*
Offline Offline

Posts: 1715432968

View Profile Personal Message (Offline)

Ignore
1715432968
Reply with quote  #2

1715432968
Report to moderator
1715432968
Hero Member
*
Offline Offline

Posts: 1715432968

View Profile Personal Message (Offline)

Ignore
1715432968
Reply with quote  #2

1715432968
Report to moderator
"Bitcoin: the cutting edge of begging technology." -- Giraffe.BTC
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715432968
Hero Member
*
Offline Offline

Posts: 1715432968

View Profile Personal Message (Offline)

Ignore
1715432968
Reply with quote  #2

1715432968
Report to moderator
1715432968
Hero Member
*
Offline Offline

Posts: 1715432968

View Profile Personal Message (Offline)

Ignore
1715432968
Reply with quote  #2

1715432968
Report to moderator
1715432968
Hero Member
*
Offline Offline

Posts: 1715432968

View Profile Personal Message (Offline)

Ignore
1715432968
Reply with quote  #2

1715432968
Report to moderator
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4316

<insert witty quote here>


View Profile
December 13, 2017, 06:51:09 AM
 #2

I think it uses the same hex private keys etc, so you probably just need to adjust the "network bytes" when generating the addresses...

I'd suggest that you check the code for liteaddress.org (https://github.com/litecoin-project/liteaddress.org) or maybe the BIP39 mnemonic code convertor which can generate the addresses (https://github.com/iancoleman/bip39)

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
alivespirit
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
January 11, 2018, 10:43:54 PM
 #3

Does anyone have a solution to this?  Does a library exist?

There is a solution library in PHP for this in Bitcoin.  It's here:  https://plugins.svn.wordpress.org/bitcoin-address/

It would need to be updated to support Litecoin.

Any takers to develop this?  Let me know!
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4316

<insert witty quote here>


View Profile
January 12, 2018, 10:49:35 AM
 #4

As per my PM...

You need to change the part where it adds the "version" bytes to the beginning of the address and then hashes it... Bitcoin version is 0x00 and Litecoin is 0x30

I *THINK* it is in ElectrumHelper.php file... in the hash_160_to_bc_address() function:

unfortunately, I cannot include the exact code here... as it seems when I try to do that, the website thinks I am trying to inject PHP code and blocks me with a big security warning! Tongue

So, please DO NOT just copy paste this! Wink

    public static function hash_160_to_bc_address($h160, $addrtype = 0) {
        $vh160 = chr ($addrtype) . $h160;
...


Edited Code:
Quote
    public static function hash_160_to_bc_address($h160, $addrtype = 30) {
        $vh160 = hex2bin("30") . $h160;
...
    }

Basically... all I did was set the default addrtype to  hex value of "30"... and then convert this from "hex" to binary and prepend it to the $hash160 instead of the "chr"(0)... that it was using for Bitcoin.

This seems to start spitting out the LTC addresses that match the xpub from Electrum-LTC... and the addresses that match my xpub from my Ledger Nano S LTC wallet. So, while I am fairly confident it works, I would test it with some small amounts first! Wink


█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!