mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-13 10:45:51 +00:00
DeterministicKey: override hasPrivKey and getSecretBytes to reflect the private key derivation strategy used.
This commit is contained in:
parent
9faa4a686b
commit
ef9e49d5e7
@ -304,6 +304,18 @@ public class DeterministicKey extends ECKey {
|
||||
return super.isPubKeyOnly() && (parent == null || parent.isPubKeyOnly());
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public boolean hasPrivKey() {
|
||||
return findOrDerivePrivateKey() != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public byte[] getSecretBytes() {
|
||||
return priv != null ? getPrivKeyBytes() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A deterministic key is considered to be encrypted if it has access to encrypted private key bytes, OR if its
|
||||
* parent does. The reason is because the parent would be encrypted under the same key and this key knows how to
|
||||
|
@ -61,18 +61,9 @@ public class RedeemData {
|
||||
* Returns the first key that has private bytes
|
||||
*/
|
||||
public ECKey getFullKey() {
|
||||
for (ECKey key : keys) {
|
||||
//TODO: don't use exception catching here to test. It's better to use hasPrivKey, but currently it's not working
|
||||
// as expected for DeterministicKeys (it doesn't test if it's possible to derive private key)
|
||||
try {
|
||||
if (key.getPrivKey() != null)
|
||||
for (ECKey key : keys)
|
||||
if (key.hasPrivKey())
|
||||
return key;
|
||||
} catch (IllegalStateException e) {
|
||||
// no private bytes. Proceed to the next key
|
||||
} catch (ECKey.MissingPrivateKeyException e) {
|
||||
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user