Thanks for your time, Danny.
I have this two outstanding questions:
2) After the creation of the MasterPrivateKey I call to .derive(1). What's the reason behind not using .derive(0)?
To complete the information: If I remove .derive(1) and add the xpub here:
http://webhdwallet.github.io/It shows the next legend:
"Non-standard key depth: should be 1, and it is 0, are you sure you want to use that?"
There's a security reason behind don't use a depth != 1? Maybe it is only a "standard"?
3) After getting the xpub, check how I managed to code a "plane" of addresses (the function getAddressFromCoords). It it fine to make another child of child if the coordinate is negative?
For the game that I'm making, I need a plane of fresh new addresses for every x,z values; negative coordinates are acceptable too.
And because I can't have a negative ChildNumber, I end up with this trick to re-do a child with the positive value again if the number is negative.
static String getAddressFromCoords(String serialized_x, int x, int z, boolean priv){
NetworkParameters params = MainNetParams.get();
DeterministicKey root_xpub = DeterministicKey.deserializeB58(null,serialized_x);
int x_positive=x>0?x:x*-1, z_positive=z>0?z:z*-1;
DeterministicKey key = HDKeyDerivation.deriveChildKey(root_xpub, new ChildNumber(x_positive, false));
key = HDKeyDerivation.deriveChildKey(key, new ChildNumber(z_positive, false));
if(x<0)
key = HDKeyDerivation.deriveChildKey(key, new ChildNumber(x_positive, false));
if(z<0)
key = HDKeyDerivation.deriveChildKey(key, new ChildNumber(z_positive, false));
if(priv)return key.getPrivateKeyEncoded(params).toString();
else return key.toAddress(params).toString();
}
I end up with a tree like this:
/-------------
/-Z
/-------/-------
/-X /
/--------/-------/----
/Z
/------/-----------
xpub /X
------/
EDIT:
So I found a bug in my function getAddressFromCoords():
------- derived public address from points -1,1 public: 1LUCtto3T8e4jdUHmZK7ThU6X6pGQ4czKE / private: KxugeoYxhzBnbAbxdL7unXv1LskqbAccwHhEjh1KMykrT19RcTEj
------- derived public address from points 1,-1 public: 1LUCtto3T8e4jdUHmZK7ThU6X6pGQ4czKE / private: KxugeoYxhzBnbAbxdL7unXv1LskqbAccwHhEjh1KMykrT19RcTEj
-1,1 and 1,-1 returns the SAME address. Fuck.