mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-24 14:50:57 +01:00
DeterministicKeyChain: Rename "externalKey" and "internalKey" attribute
names to "externalParentKey" and "internalParentKey".
This commit is contained in:
parent
fe7b703237
commit
6c3b545b0c
1 changed files with 22 additions and 22 deletions
|
@ -70,7 +70,7 @@ import static com.google.common.collect.Lists.newLinkedList;
|
|||
* {@link org.bitcoinj.crypto.DeterministicKey} by adding support for serialization to and from protobufs,
|
||||
* and encryption of parts of the key tree. Internally it arranges itself as per the BIP 32 spec, with the seed being
|
||||
* used to derive a master key, which is then used to derive an account key, the account key is used to derive two
|
||||
* child keys called the <i>internal</i> and <i>external</i> keys (for change and handing out addresses respectively)
|
||||
* child keys called the <i>internal</i> and <i>external</i> parent keys (for change and handing out addresses respectively)
|
||||
* and finally the actual leaf keys that users use hanging off the end. The leaf keys are special in that they don't
|
||||
* internally store the private part at all, instead choosing to rederive the private key from the parent when
|
||||
* needed for signing. This simplifies the design for encrypted key chains.</p>
|
||||
|
@ -137,7 +137,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
|
|||
}
|
||||
|
||||
// The parent keys for external keys (handed out to other people) and internal keys (used for change addresses).
|
||||
private DeterministicKey externalKey, internalKey;
|
||||
private DeterministicKey externalParentKey, internalParentKey;
|
||||
// How many keys on each path have actually been used. This may be fewer than the number that have been deserialized
|
||||
// or held in memory, because of the lookahead zone.
|
||||
private int issuedExternalKeys, issuedInternalKeys;
|
||||
|
@ -417,8 +417,8 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
|
|||
encryptNonLeaf(aesKey, chain, rootKey, getAccountPath().subList(0, i));
|
||||
}
|
||||
DeterministicKey account = encryptNonLeaf(aesKey, chain, rootKey, getAccountPath());
|
||||
externalKey = encryptNonLeaf(aesKey, chain, account, HDUtils.concat(getAccountPath(), EXTERNAL_SUBPATH));
|
||||
internalKey = encryptNonLeaf(aesKey, chain, account, HDUtils.concat(getAccountPath(), INTERNAL_SUBPATH));
|
||||
externalParentKey = encryptNonLeaf(aesKey, chain, account, HDUtils.concat(getAccountPath(), EXTERNAL_SUBPATH));
|
||||
internalParentKey = encryptNonLeaf(aesKey, chain, account, HDUtils.concat(getAccountPath(), INTERNAL_SUBPATH));
|
||||
|
||||
// Now copy the (pubkey only) leaf keys across to avoid rederiving them. The private key bytes are missing
|
||||
// anyway so there's nothing to encrypt.
|
||||
|
@ -450,10 +450,10 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
|
|||
// Derives the account path keys and inserts them into the basic key chain. This is important to preserve their
|
||||
// order for serialization, amongst other things.
|
||||
private void initializeHierarchyUnencrypted(DeterministicKey baseKey) {
|
||||
externalKey = hierarchy.deriveChild(getAccountPath(), false, false, ChildNumber.ZERO);
|
||||
internalKey = hierarchy.deriveChild(getAccountPath(), false, false, ChildNumber.ONE);
|
||||
addToBasicChain(externalKey);
|
||||
addToBasicChain(internalKey);
|
||||
externalParentKey = hierarchy.deriveChild(getAccountPath(), false, false, ChildNumber.ZERO);
|
||||
internalParentKey = hierarchy.deriveChild(getAccountPath(), false, false, ChildNumber.ONE);
|
||||
addToBasicChain(externalParentKey);
|
||||
addToBasicChain(internalParentKey);
|
||||
}
|
||||
|
||||
/** Returns a freshly derived key that has not been returned by this method before. */
|
||||
|
@ -479,13 +479,13 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
|
|||
case REFUND:
|
||||
issuedExternalKeys += numberOfKeys;
|
||||
index = issuedExternalKeys;
|
||||
parentKey = externalKey;
|
||||
parentKey = externalParentKey;
|
||||
break;
|
||||
case AUTHENTICATION:
|
||||
case CHANGE:
|
||||
issuedInternalKeys += numberOfKeys;
|
||||
index = issuedInternalKeys;
|
||||
parentKey = internalKey;
|
||||
parentKey = internalParentKey;
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
|
@ -541,12 +541,12 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
|
|||
public DeterministicKey markKeyAsUsed(DeterministicKey k) {
|
||||
int numChildren = k.getChildNumber().i() + 1;
|
||||
|
||||
if (k.getParent() == internalKey) {
|
||||
if (k.getParent() == internalParentKey) {
|
||||
if (issuedInternalKeys < numChildren) {
|
||||
issuedInternalKeys = numChildren;
|
||||
maybeLookAhead();
|
||||
}
|
||||
} else if (k.getParent() == externalKey) {
|
||||
} else if (k.getParent() == externalParentKey) {
|
||||
if (issuedExternalKeys < numChildren) {
|
||||
issuedExternalKeys = numChildren;
|
||||
maybeLookAhead();
|
||||
|
@ -755,11 +755,11 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
|
|||
detKey.setChainCode(ByteString.copyFrom(key.getChainCode()));
|
||||
for (ChildNumber num : key.getPath())
|
||||
detKey.addPath(num.i());
|
||||
if (key.equals(externalKey)) {
|
||||
if (key.equals(externalParentKey)) {
|
||||
detKey.setIssuedSubkeys(issuedExternalKeys);
|
||||
detKey.setLookaheadSize(lookaheadSize);
|
||||
detKey.setSigsRequiredToSpend(getSigsRequiredToSpend());
|
||||
} else if (key.equals(internalKey)) {
|
||||
} else if (key.equals(internalParentKey)) {
|
||||
detKey.setIssuedSubkeys(issuedInternalKeys);
|
||||
detKey.setLookaheadSize(lookaheadSize);
|
||||
detKey.setSigsRequiredToSpend(getSigsRequiredToSpend());
|
||||
|
@ -918,12 +918,12 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
|
|||
}
|
||||
} else if (path.size() == chain.getAccountPath().size() + 1) {
|
||||
if (detkey.getChildNumber().num() == 0) {
|
||||
chain.externalKey = detkey;
|
||||
chain.externalParentKey = detkey;
|
||||
chain.issuedExternalKeys = key.getDeterministicKey().getIssuedSubkeys();
|
||||
lookaheadSize = Math.max(lookaheadSize, key.getDeterministicKey().getLookaheadSize());
|
||||
sigsRequiredToSpend = key.getDeterministicKey().getSigsRequiredToSpend();
|
||||
} else if (detkey.getChildNumber().num() == 1) {
|
||||
chain.internalKey = detkey;
|
||||
chain.internalParentKey = detkey;
|
||||
chain.issuedInternalKeys = key.getDeterministicKey().getIssuedSubkeys();
|
||||
}
|
||||
}
|
||||
|
@ -1136,8 +1136,8 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
|
|||
public void maybeLookAhead() {
|
||||
lock.lock();
|
||||
try {
|
||||
List<DeterministicKey> keys = maybeLookAhead(externalKey, issuedExternalKeys);
|
||||
keys.addAll(maybeLookAhead(internalKey, issuedInternalKeys));
|
||||
List<DeterministicKey> keys = maybeLookAhead(externalParentKey, issuedExternalKeys);
|
||||
keys.addAll(maybeLookAhead(internalParentKey, issuedInternalKeys));
|
||||
if (keys.isEmpty())
|
||||
return;
|
||||
keyLookaheadEpoch++;
|
||||
|
@ -1231,15 +1231,15 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
|
|||
/* package */ List<ECKey> getKeys(boolean includeLookahead) {
|
||||
List<ECKey> keys = basicKeyChain.getKeys();
|
||||
if (!includeLookahead) {
|
||||
int treeSize = internalKey.getPath().size();
|
||||
int treeSize = internalParentKey.getPath().size();
|
||||
List<ECKey> issuedKeys = new LinkedList<ECKey>();
|
||||
for (ECKey key : keys) {
|
||||
DeterministicKey detkey = (DeterministicKey) key;
|
||||
DeterministicKey parent = detkey.getParent();
|
||||
if (parent == null) continue;
|
||||
if (detkey.getPath().size() <= treeSize) continue;
|
||||
if (parent.equals(internalKey) && detkey.getChildNumber().i() >= issuedInternalKeys) continue;
|
||||
if (parent.equals(externalKey) && detkey.getChildNumber().i() >= issuedExternalKeys) continue;
|
||||
if (parent.equals(internalParentKey) && detkey.getChildNumber().i() >= issuedInternalKeys) continue;
|
||||
if (parent.equals(externalParentKey) && detkey.getChildNumber().i() >= issuedExternalKeys) continue;
|
||||
issuedKeys.add(detkey);
|
||||
}
|
||||
return issuedKeys;
|
||||
|
@ -1254,7 +1254,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
|
|||
final List<ECKey> keys = new ArrayList<ECKey>(getKeys(false));
|
||||
for (Iterator<ECKey> i = keys.iterator(); i.hasNext();) {
|
||||
DeterministicKey parent = ((DeterministicKey) i.next()).getParent();
|
||||
if (parent == null || !externalKey.equals(parent))
|
||||
if (parent == null || !externalParentKey.equals(parent))
|
||||
i.remove();
|
||||
}
|
||||
return keys;
|
||||
|
|
Loading…
Add table
Reference in a new issue