private SimpleHDKeyChain(KeyCrypter crypter, KeyParameter aesKey, SimpleHDKeyChain chain) {
checkArgument(!chain.rootKey.isEncrypted(), "Chain already encrypted");
this.issuedExternalKeys = chain.issuedExternalKeys;
this.issuedInternalKeys = chain.issuedInternalKeys;
this.lookaheadSize = chain.lookaheadSize;
this.lookaheadThreshold = chain.lookaheadThreshold;
simpleKeyChain = new SimpleKeyChain(crypter);
rootKey = chain.rootKey.encrypt(crypter, aesKey, null);
hierarchy = new DeterministicHierarchy(rootKey);
simpleKeyChain.importKey(rootKey);
externalKey = encryptNonLeaf(aesKey, chain, rootKey, EXTERNAL_PATH);
internalKey = encryptNonLeaf(aesKey, chain, rootKey, INTERNAL_PATH);
for (ECKey eckey : chain.simpleKeyChain.getKeys()) {
DeterministicKey key = (DeterministicKey) eckey;
if (!isLeaf(key)) continue;
DeterministicKey parent = hierarchy.get(checkNotNull(key.getParent(), "Key has no parent").getPath(), false, false);
key = new DeterministicKey(key.getPubOnly(), parent);
hierarchy.putKey(key);
simpleKeyChain.importKey(key);
}
}