DeterministicKeyChain: Inline addToBasicChain() method.

This commit is contained in:
Andreas Schildbach
2016-09-29 23:18:22 +02:00
parent c6418dc06d
commit 7a1613a48d

View File

@@ -320,8 +320,8 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
checkArgument(watchingKey.getPath().size() == getAccountPath().size(), "You can only watch an account key currently");
basicKeyChain = new BasicKeyChain();
this.seed = null;
rootKey = null;
addToBasicChain(watchingKey);
this.rootKey = null;
basicKeyChain.importKey(watchingKey);
hierarchy = new DeterministicHierarchy(watchingKey);
initializeHierarchyUnencrypted(watchingKey);
}
@@ -361,10 +361,10 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
if (!seed.isEncrypted()) {
rootKey = HDKeyDerivation.createMasterPrivateKey(checkNotNull(seed.getSeedBytes()));
rootKey.setCreationTimeSeconds(seed.getCreationTimeSeconds());
addToBasicChain(rootKey);
basicKeyChain.importKey(rootKey);
hierarchy = new DeterministicHierarchy(rootKey);
for (int i = 1; i <= getAccountPath().size(); i++) {
addToBasicChain(hierarchy.get(getAccountPath().subList(0, i), false, true));
basicKeyChain.importKey(hierarchy.get(getAccountPath().subList(0, i), false, true));
}
initializeHierarchyUnencrypted(rootKey);
}
@@ -438,8 +438,8 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
private void initializeHierarchyUnencrypted(DeterministicKey baseKey) {
externalParentKey = hierarchy.deriveChild(getAccountPath(), false, false, ChildNumber.ZERO);
internalParentKey = hierarchy.deriveChild(getAccountPath(), false, false, ChildNumber.ONE);
addToBasicChain(externalParentKey);
addToBasicChain(internalParentKey);
basicKeyChain.importKey(externalParentKey);
basicKeyChain.importKey(internalParentKey);
}
/** Returns a freshly derived key that has not been returned by this method before. */
@@ -515,10 +515,6 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
throw new IllegalStateException(String.format(Locale.US, "Bit-flip check failed: %s vs %s", Arrays.toString(rederived), Arrays.toString(actual)));
}
private void addToBasicChain(DeterministicKey key) {
basicKeyChain.importKeys(ImmutableList.of(key));
}
/**
* Mark the DeterministicKey as used.
* Also correct the issued{Internal|External}Keys counter, because all lower children seem to be requested already.