Thanks a lot.
How can I integrate m / 84 '/ 0' / 0 '/ 0/0 into my code? I just need to get the first 5 addresses. I looked at your program, but there is a whole class forming a complex configuration. Too difficult for a beginner. How can I just hardcode the derivation path into my method?
public class Main {
final static byte[] BITCOIN_SEED_BYTES = "Bitcoin seed".getBytes();
final static byte[] SALT = "mnemonic".getBytes(StandardCharsets.UTF_8);
public static void main(String[] args) throws IOException, MnemonicException, InterruptedException {
String seedCode = "tissue deliver beauty rare kind midnight focus indicate forum lawn this setup";
byte[] seed = PBKDF2SHA512.derive(seedCode.getBytes(StandardCharsets.UTF_8), SALT, 2048, 64);
DeterministicKey deterministicKey = createMasterPrivateKey(seed, createHmacSha512Digest());
deterministicKey = HDKeyDerivation.deriveChildKey(deterministicKey, new ChildNumber(84, true));
deterministicKey = HDKeyDerivation.deriveChildKey(deterministicKey, new ChildNumber(0, true));
deterministicKey = HDKeyDerivation.deriveChildKey(deterministicKey, new ChildNumber(0, true));
deterministicKey = HDKeyDerivation.deriveChildKey(deterministicKey, new ChildNumber(0, false));
for (int i = 0; i <= 5; i++) {
System.out.println(Address.fromKey(MainNetParams.get(), HDKeyDerivation.deriveChildKey(deterministicKey, new ChildNumber(i, false)), Script.ScriptType.P2WPKH));
}
}
private static DeterministicKey createMasterPrivateKey(byte[] seed, HMac SHA512DIGEST) throws HDDerivationException {
byte[] i = hmacSha512(SHA512DIGEST, seed);
byte[] il = Arrays.copyOfRange(i, 0, 32);
byte[] ir = Arrays.copyOfRange(i, 32, 64);
Arrays.fill(i, (byte)0);
DeterministicKey masterPrivKey = HDKeyDerivation.createMasterPrivKeyFromBytes(il, ir);
Arrays.fill(il, (byte)0);
Arrays.fill(ir, (byte)0);
masterPrivKey.setCreationTimeSeconds(System.currentTimeMillis());
return masterPrivKey;
}
private static byte[] hmacSha512(HMac hmacSha512, byte[] input) {
hmacSha512.reset();
hmacSha512.update(input, 0, input.length);
byte[] out = new byte[64];
hmacSha512.doFinal(out, 0);
return out;
}
private static HMac createHmacSha512Digest() {
SHA512Digest digest = new SHA512Digest();
HMac hMac = new HMac(digest);
hMac.init(new KeyParameter(BITCOIN_SEED_BYTES));
return hMac;
}
}