0
I am reading through BIP32's documentation and its implementation in Java on GitHub in the file supernode/api/src/main/java/com/bitsofproof/supernode/api/ExtendedKey.java.
Luckily, I was able to follow the code, but there are areas I am not sure about.
I have 2 questions:
I know it is in BIP32.json file, but why are we doing
if ((sequence & 0x8000000)==0)? It is a condition for master public key to child public key or master private key to child private key... but what sequence does for?if ( (sequence & 0x80000000) == 0 )My second one is why we add 4 bytes. Is there any detail document source I can find?
extended = new byte[pub.length + 4]; System.arraycopy (pub, 0, extended, 0, pub.length); extended[pub.length] = (byte) ((sequence >>> 24) & 0xff); extended[pub.length + 1] = (byte) ((sequence >>> 16) & 0xff); extended[pub.length + 2] = (byte) ((sequence >>> 8) & 0xff); extended[pub.length + 3] = (byte) (sequence & 0xff); } else { byte[] priv = master.getPrivate (); extended = new byte[priv.length + 5]; System.arraycopy (priv, 0, extended, 1, priv.length); extended[priv.length + 1] = (byte) ((sequence >>> 24) & 0xff); extended[priv.length + 2] = (byte) ((sequence >>> 16) & 0xff); extended[priv.length + 3] = (byte) ((sequence >>> 8) & 0xff); extended[priv.length + 4] = (byte) (sequence & 0xff); }
Many thanks in advance.
Welcome to Bitcoin.SE! You can help the site by marking answers as accepted if they are correct and address your question so that the question does not remain as "unanswered". – Willtech – 2018-03-04T07:48:56.450