Muhammad Saad
Muhammad Saad

Reputation: 733

How to generate multiple Bitcoin addresses from 1 public key?

I'm facing an issue regarding generation of Bitcoin addresses.

I've public key:

String xpub"xpub661MyMwAqRbcGJxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

I want to generate multiple addresses from xpub.

I'm using bitcoinJ library.

ECKey key=ECKey.fromPublicOnly(Base58.decode(xpub));

It throws exception of:

Incorrect length for uncompressed encoding

I've read many articles, I found that Ripemd160(SHA256(string));.
After hashing, I encode in Base58, but couldn't achieve multiple addresses.

Upvotes: 1

Views: 1825

Answers (1)

Bilal EL CHAMI
Bilal EL CHAMI

Reputation: 414

I'm not sure if my answer is the right one because I don't know how the BitcoinJ library works but just for info:

The bitcoin public key is kind of different from RSA public keys, you should add 04 at the beginning of the string.

In your case the key value should be equals to:

04xpub661MyMwAqRbcGJxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

So the public key generated will have the following:

1 byte 0x04 + 65 bytes: 32 bytes corresponding to X coordinate and 32 bytes corresponding to Y coordinate

Check:

https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses https://en.bitcoin.it/w/images/en/9/9b/PubKeyToAddr.png

To test/validate your address you can use this site:

http://gobittest.appspot.com/Address

Good luck

Upvotes: 3

Related Questions