mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-23 14:40:40 +01:00
DeterministicKeyChain: add private putKey(key) method, and use it
To add a key it must be added to both the `hierarchy` and `basicKeyChain` this should be wrapped in a method and used whenever a key is addded.
This commit is contained in:
parent
184be16773
commit
79fbf5ab02
1 changed files with 9 additions and 8 deletions
|
@ -425,8 +425,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
|
|||
DeterministicKey parent = hierarchy.get(checkNotNull(key.getParent()).getPath(), false, false);
|
||||
// Clone the key to the new encrypted hierarchy.
|
||||
key = new DeterministicKey(key.dropPrivateBytes(), parent);
|
||||
hierarchy.putKey(key);
|
||||
basicKeyChain.importKey(key);
|
||||
putKey(key);
|
||||
}
|
||||
for (ListenerRegistration<KeyChainEventListener> listener : chain.basicKeyChain.getListeners()) {
|
||||
basicKeyChain.addEventListener(listener);
|
||||
|
@ -445,8 +444,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
|
|||
DeterministicKey parent, List<ChildNumber> path) {
|
||||
DeterministicKey key = chain.hierarchy.get(path, false, false);
|
||||
key = key.encrypt(checkNotNull(basicKeyChain.getKeyCrypter()), aesKey, parent);
|
||||
hierarchy.putKey(key);
|
||||
basicKeyChain.importKey(key);
|
||||
putKey(key);
|
||||
return key;
|
||||
}
|
||||
|
||||
|
@ -524,6 +522,11 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
|
|||
}
|
||||
}
|
||||
|
||||
private void putKey(DeterministicKey key) {
|
||||
hierarchy.putKey(key);
|
||||
basicKeyChain.importKey(key);
|
||||
}
|
||||
|
||||
private void checkForBitFlip(DeterministicKey k) {
|
||||
DeterministicKey parent = checkNotNull(k.getParent());
|
||||
byte[] rederived = HDKeyDerivation.deriveChildKeyBytesFromPublic(parent, k.getChildNumber(), HDKeyDerivation.PublicDeriveMode.WITH_INVERSION).keyBytes;
|
||||
|
@ -955,8 +958,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
|
|||
}
|
||||
}
|
||||
}
|
||||
chain.hierarchy.putKey(detkey);
|
||||
chain.basicKeyChain.importKey(detkey);
|
||||
chain.putKey(detkey);
|
||||
}
|
||||
}
|
||||
if (chain != null) {
|
||||
|
@ -1027,8 +1029,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
|
|||
DeterministicKey parent = chain.hierarchy.get(checkNotNull(key.getParent()).getPath(), false, false);
|
||||
// Clone the key to the new decrypted hierarchy.
|
||||
key = new DeterministicKey(key.dropPrivateBytes(), parent);
|
||||
chain.hierarchy.putKey(key);
|
||||
chain.basicKeyChain.importKey(key);
|
||||
chain.putKey(key);
|
||||
}
|
||||
chain.issuedExternalKeys = issuedExternalKeys;
|
||||
chain.issuedInternalKeys = issuedInternalKeys;
|
||||
|
|
Loading…
Add table
Reference in a new issue