Search in sources :

Example 1 with HDDerivationException

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");
}
Also used : HDDerivationException(org.bitcoinj.crypto.HDDerivationException) ECKey(org.ethereum.crypto.ECKey) DeterministicKey(org.bitcoinj.crypto.DeterministicKey)

Aggregations

DeterministicKey (org.bitcoinj.crypto.DeterministicKey)1 HDDerivationException (org.bitcoinj.crypto.HDDerivationException)1 ECKey (org.ethereum.crypto.ECKey)1