diff --git a/core/src/main/java/org/bitcoinj/wallet/DeterministicKeyChain.java b/core/src/main/java/org/bitcoinj/wallet/DeterministicKeyChain.java index 552dbe5b..5fd003ae 100644 --- a/core/src/main/java/org/bitcoinj/wallet/DeterministicKeyChain.java +++ b/core/src/main/java/org/bitcoinj/wallet/DeterministicKeyChain.java @@ -112,6 +112,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain { // is somewhat arbitrary but can be useful for audits. The first number is the "account number" but we don't use // that feature yet. In future we might hand out different accounts for cases where we wish to hand payers // a payment request that can generate lots of addresses independently. + // The account path may be overridden by subclasses. public static final ImmutableList ACCOUNT_ZERO_PATH = ImmutableList.of(ChildNumber.ZERO_HARDENED); public static final ImmutableList EXTERNAL_SUBPATH = ImmutableList.of(ChildNumber.ZERO); public static final ImmutableList INTERNAL_SUBPATH = ImmutableList.of(ChildNumber.ONE); @@ -366,6 +367,9 @@ public class DeterministicKeyChain implements EncryptableKeyChain { return new DeterministicKeyChain(accountKey, seedCreationTimeSecs); } + /** + * For use in {@link KeyChainFactory} during deserialization. + */ protected DeterministicKeyChain(DeterministicSeed seed, @Nullable KeyCrypter crypter) { this.seed = seed; basicKeyChain = new BasicKeyChain(crypter); @@ -430,6 +434,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain { } } + /** Override in subclasses to use a different account derivation path */ protected ImmutableList getAccountPath() { return ACCOUNT_ZERO_PATH; } @@ -1004,7 +1009,6 @@ public class DeterministicKeyChain implements EncryptableKeyChain { * Subclasses should override this to create an instance of the subclass instead of a plain DKC. * This is used in encryption/decryption. */ - protected DeterministicKeyChain makeKeyChainFromSeed(DeterministicSeed seed) { return new DeterministicKeyChain(seed); } diff --git a/core/src/main/java/org/bitcoinj/wallet/KeyChainGroup.java b/core/src/main/java/org/bitcoinj/wallet/KeyChainGroup.java index 7638bffa..f2900a69 100644 --- a/core/src/main/java/org/bitcoinj/wallet/KeyChainGroup.java +++ b/core/src/main/java/org/bitcoinj/wallet/KeyChainGroup.java @@ -764,15 +764,17 @@ public class KeyChainGroup implements KeyBag { // kinds of KeyPurpose are introduced. if (activeChain.getIssuedExternalKeys() > 0) { DeterministicKey currentExternalKey = activeChain.getKeyByPath( - Lists.newArrayList(ImmutableList.builder().addAll(activeChain.getAccountPath()).add(ChildNumber.ZERO, new ChildNumber(activeChain.getIssuedExternalKeys() - 1)).build()) - ); + HDUtils.append( + HDUtils.concat(activeChain.getAccountPath(), DeterministicKeyChain.EXTERNAL_SUBPATH), + new ChildNumber(activeChain.getIssuedExternalKeys() - 1))); currentKeys.put(KeyChain.KeyPurpose.RECEIVE_FUNDS, currentExternalKey); } if (activeChain.getIssuedInternalKeys() > 0) { DeterministicKey currentInternalKey = activeChain.getKeyByPath( - Lists.newArrayList(ImmutableList.builder().addAll(activeChain.getAccountPath()).add(new ChildNumber(1), new ChildNumber(activeChain.getIssuedInternalKeys() - 1)).build()) - ); + HDUtils.append( + HDUtils.concat(activeChain.getAccountPath(), DeterministicKeyChain.INTERNAL_SUBPATH), + new ChildNumber(activeChain.getIssuedInternalKeys() - 1))); currentKeys.put(KeyChain.KeyPurpose.CHANGE, currentInternalKey); } return currentKeys;