use of org.bitcoinj.crypto.HDDerivationException in project account-identity by cryptofiat.
the class HDKey method deriveAddressFromKey.
public static HdAddress deriveAddressFromKey(String pubkey, int index) {
while (index < 1 << 30) {
try {
DeterministicKey master = DeterministicKey.deserializeB58(null, pubkey, MainNetParams.get());
DeterministicKey child = HDKeyDerivation.deriveChildKey(master, index);
ECKey childkey = ECKey.fromPublicOnly(child.getPubKey());
HdAddress address = new HdAddress(index, "0x".concat(org.spongycastle.util.encoders.Hex.toHexString(childkey.getAddress())));
return address;
} catch (HDDerivationException e) {
index++;
}
}
throw new RuntimeException("Couldn't generate HD Key after max tries");
}
Aggregations