Generate Ethereum addresses in HD Wallet using public key only bitcoinj web3j

0 votes

I try to generate Ethereum addresses for the HD Wallet keys implemented with the bitcoinj library, but I got confused:

DeterministicSeed seed = new DeterministicSeed("some seed code here", null, "", 1409478661L); DeterministicKeyChain chain = DeterministicKeyChain.builder().seed(seed).build(); DeterministicKey addrKey = chain.getKeyByPath(HDUtils.parsePath("M/44H/60H/0H/0/0"), true); System.out.println("address from pub=" + Keys.getAddress(Sign.publicKeyFromPrivate(addrKey.getPrivKey())));


this code prints a correct Ethereum address accordingly to https://iancoleman.io/bip39/. Everything is fine here.

But when I try to avoid private key usage and generate non-hardened keys using public keys only I get different results, i.e. the call returns another result:

System.out.println("address from pub=" + Keys.getAddress(addrKey.getPublicKeyAsHex()));


And it looks like the issue is in the "different public keys", i.e. result of the Sign.publicKeyFromPrivate(addrKey.getPrivKey()) and addrKey.getPublicKeyAsHex() are different. I'm not experienced with cryptography, thus it may be a silly question... but I would appreciate any advice here.

Apr 6, 2022 in Blockchain by Aditya
• 7,680 points
3,757 views

1 answer to this question.

0 votes

Like Bitcoin, Ethereum uses secp256k1. Ethereum addresses are derived as follows:

  • Step 1: The 32 bytes x and y coordinate of the public key are concatenated to 64 bytes (where both the x and y coordinate are padded with leading 0x00 values if necessary).

  • Step 2: From this the Keccak-256 hash is generated.

  • Step 3: The last 20 bytes are used as the Ethereum address.

For the examples used here, the key is generated with:

String mnemonic = "elevator dinosaur switch you armor vote black syrup fork onion nurse illegal trim rocket combine"; DeterministicSeed seed = new DeterministicSeed(mnemonic, null, "", 1409478661L); DeterministicKeyChain chain = DeterministicKeyChain.builder().seed(seed).build(); DeterministicKey addrKey = chain.getKeyByPath(HDUtils.parsePath("M/44H/60H/0H/0/0"), true);



This corresponds to the following public key and Ethereum address:

X: a35bf0fdf5df296cc3600422c3c8af480edb766ff6231521a517eb822dff52cd Y: 5440f87f5689c2929542e75e739ff30cd1e8cb0ef0beb77380d02cd7904978ca Address: 23ad59cc6afff2e508772f69d22b19ffebf579e7


As can also be verified with the website https://iancoleman.io/bip39/.

Learn more about Blockchain and its concepts from the Blockchain developer course.

answered Apr 12, 2022 by Soham
• 9,710 points

Related Questions In Blockchain

+1 vote
2 answers
0 votes
1 answer
+1 vote
1 answer
0 votes
1 answer

How to create light wallet in Web3J?

You can use this method to create ...READ MORE

answered Aug 10, 2018 in Blockchain by slayer
• 29,370 points
2,125 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,935 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,460 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,460 points
1,446 views
0 votes
1 answer

Generate new Ethereum Wallet in NodeJS

 In its simplest form, the Ethereum wallet ...READ MORE

answered Apr 12, 2022 in Blockchain by Soham
• 9,710 points
1,924 views
0 votes
1 answer

How can I import a Bitcoin paper wallet key into a bitcoinlib wallet?

Your code should work in the latest ...READ MORE

answered Apr 12, 2022 in Blockchain by Soham
• 9,710 points
1,389 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP