3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-13 10:45:51 +00:00

Don't derive private keys just to check if they exist

This commit is contained in:
Devrandom 2015-07-19 11:02:08 -07:00 committed by Andreas Schildbach
parent a293b09ef5
commit 4411eb8702

View File

@ -320,7 +320,7 @@ public class DeterministicKey extends ECKey {
/** {@inheritDoc} */
@Override
public boolean hasPrivKey() {
return findOrDerivePrivateKey() != null;
return findParentWithPrivKey() != null;
}
@Nullable
@ -407,13 +407,18 @@ public class DeterministicKey extends ECKey {
return derivePrivateKeyDownwards(cursor, parentalPrivateKeyBytes);
}
@Nullable
private BigInteger findOrDerivePrivateKey() {
private DeterministicKey findParentWithPrivKey() {
DeterministicKey cursor = this;
while (cursor != null) {
if (cursor.priv != null) break;
cursor = cursor.parent;
}
return cursor;
}
@Nullable
private BigInteger findOrDerivePrivateKey() {
DeterministicKey cursor = findParentWithPrivKey();
if (cursor == null)
return null;
return derivePrivateKeyDownwards(cursor, cursor.priv.toByteArray());