import java.util.ArrayList;
import java.util.Arrays;
import com.google.bitcoin.core.Base58;
import com.google.bitcoin.crypto.ChildNumber;
import com.google.bitcoin.crypto.DeterministicHierarchy;
import com.google.bitcoin.crypto.DeterministicKey;
import com.google.bitcoin.crypto.HDKeyDerivation;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
/**August 22, 2013 with bitcoinJ 0.10 */
public class Main {
/**compare public keys of 0'/0'/0' and and 0'/0'/0
* @param args none used*/
public static void main(String[] args) {
System.out.println("start");
DeterministicHierarchy masterHrchy = new DeterministicHierarchy(
HDKeyDerivation.createMasterPrivateKey("BitcoinJRulez".getBytes()));
// builder for /0/0
ArrayList<ChildNumber> zeroZero = new ArrayList<ChildNumber>();
zeroZero.add(new ChildNumber(0, true));
zeroZero.add(new ChildNumber(0, true));
// builders for public and private nodes at /0/0/0
Builder<ChildNumber> privateNode = new ImmutableList.Builder<ChildNumber>();
privateNode.addAll(zeroZero);
privateNode.add(new ChildNumber(0, true /* private */));
DeterministicKey priv = masterHrchy.get(privateNode.build(), false, true);
Builder<ChildNumber> pubNode = new ImmutableList.Builder<ChildNumber>();
pubNode.addAll(zeroZero);
pubNode.add(new ChildNumber(0, false /* public */));
DeterministicKey pub = masterHrchy.get(pubNode.build(), false, true);
assert Arrays.equals(priv.getPubKeyBytes(), pub.getPubKeyBytes()) :
Base58.encode(priv.getPubKeyBytes()) + " vs. " + Base58.encode(pub.getPubKeyBytes());
System.out.println("end");
}
}