@Test public void freshAddress() throws Exception { group = createMarriedKeyChainGroup(); Address a1 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); Address a2 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertEquals(ScriptType.P2SH, a1.getOutputScriptType()); assertNotEquals(a1, a2); group.getBloomFilterElementCount(); assertEquals(((group.getLookaheadSize() + group.getLookaheadThreshold()) * 2) + (2 - group.getLookaheadThreshold()) + group.getActiveKeyChain().getAccountPath().size() + 3 , group.numKeys()); Address a3 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertEquals(a2, a3); }
public Address freshAddress(KeyChain.KeyPurpose purpose, Script.ScriptType outputScriptType, long keyRotationTimeSecs) { DeterministicKeyChain chain = getActiveKeyChain(outputScriptType, keyRotationTimeSecs); return Address.fromKey(params, chain.getKey(purpose), outputScriptType); }
KeyChainGroup implements KeyBag { public Address freshAddress(KeyChain.KeyPurpose purpose, Script.ScriptType outputScriptType, long keyRotationTimeSecs) { DeterministicKeyChain chain = getActiveKeyChain(outputScriptType, keyRotationTimeSecs); return Address.fromKey(params, chain.getKey(purpose), outputScriptType); } }
KeyChainGroup implements KeyBag { public Address freshAddress(KeyChain.KeyPurpose purpose, Script.ScriptType outputScriptType, long keyRotationTimeSecs) { DeterministicKeyChain chain = getActiveKeyChain(outputScriptType, keyRotationTimeSecs); return Address.fromKey(params, chain.getKey(purpose), outputScriptType); } private  KeyChainGroup(NetworkParameters params, @Nullable BasicKeyChain basicKeyChain,
            @Nullable List<DeterministicKeyChain> chains, int lookaheadSize, int lookaheadThreshold,
            @Nullable EnumMap<KeyChain.KeyPurpose, DeterministicKey> currentKeys, @Nullable KeyCrypter crypter); }
KeyChainGroup implements KeyBag { public Address freshAddress(KeyChain.KeyPurpose purpose, Script.ScriptType outputScriptType, long keyRotationTimeSecs) { DeterministicKeyChain chain = getActiveKeyChain(outputScriptType, keyRotationTimeSecs); return Address.fromKey(params, chain.getKey(purpose), outputScriptType); } private  KeyChainGroup(NetworkParameters params, @Nullable BasicKeyChain basicKeyChain,
            @Nullable List<DeterministicKeyChain> chains, int lookaheadSize, int lookaheadThreshold,
            @Nullable EnumMap<KeyChain.KeyPurpose, DeterministicKey> currentKeys, @Nullable KeyCrypter crypter); static KeyChainGroup createBasic(NetworkParameters params); static KeyChainGroup.Builder builder(NetworkParameters params); static KeyChainGroup.Builder builder(NetworkParameters params, KeyChainGroupStructure structure); boolean isSupportsDeterministicChains(); void addAndActivateHDChain(DeterministicKeyChain chain); DeterministicKey currentKey(KeyChain.KeyPurpose purpose); Address currentAddress(KeyChain.KeyPurpose purpose); DeterministicKey freshKey(KeyChain.KeyPurpose purpose); List<DeterministicKey> freshKeys(KeyChain.KeyPurpose purpose, int numberOfKeys); Address freshAddress(KeyChain.KeyPurpose purpose, Script.ScriptType outputScriptType, long keyRotationTimeSecs); Address freshAddress(KeyChain.KeyPurpose purpose); List<DeterministicKeyChain> getActiveKeyChains(long keyRotationTimeSecs); final DeterministicKeyChain getActiveKeyChain(Script.ScriptType outputScriptType, long keyRotationTimeSecs); final DeterministicKeyChain getActiveKeyChain(); final void mergeActiveKeyChains(KeyChainGroup from, long keyRotationTimeSecs); int getLookaheadSize(); int getLookaheadThreshold(); int importKeys(List<ECKey> keys); int importKeys(ECKey... keys); boolean checkPassword(CharSequence password); boolean checkAESKey(KeyParameter aesKey); int importKeysAndEncrypt(final List<ECKey> keys, KeyParameter aesKey); @Override @Nullable RedeemData findRedeemDataFromScriptHash(byte[] scriptHash); void markP2SHAddressAsUsed(LegacyAddress address); @Nullable @Override ECKey findKeyFromPubKeyHash(byte[] pubKeyHash, @Nullable Script.ScriptType scriptType); void markPubKeyHashAsUsed(byte[] pubKeyHash); boolean hasKey(ECKey key); @Nullable @Override ECKey findKeyFromPubKey(byte[] pubKey); void markPubKeyAsUsed(byte[] pubkey); int numKeys(); boolean removeImportedKey(ECKey key); final boolean isMarried(); void encrypt(KeyCrypter keyCrypter, KeyParameter aesKey); void decrypt(KeyParameter aesKey); boolean isEncrypted(); boolean isWatching(); @Nullable KeyCrypter getKeyCrypter(); List<ECKey> getImportedKeys(); long getEarliestKeyCreationTime(); int getBloomFilterElementCount(); BloomFilter getBloomFilter(int size, double falsePositiveRate, long nTweak); boolean isRequiringUpdateAllBloomFilter(); void addEventListener(KeyChainEventListener listener); void addEventListener(KeyChainEventListener listener, Executor executor); boolean removeEventListener(KeyChainEventListener listener); void addCurrentKeyChangeEventListener(CurrentKeyChangeEventListener listener); void addCurrentKeyChangeEventListener(CurrentKeyChangeEventListener listener, Executor executor); boolean removeCurrentKeyChangeEventListener(CurrentKeyChangeEventListener listener); List<Protos.Key> serializeToProtobuf(); static KeyChainGroup fromProtobufUnencrypted(NetworkParameters params, List<Protos.Key> keys, KeyChainFactory factory); static KeyChainGroup fromProtobufEncrypted(NetworkParameters params, List<Protos.Key> keys, KeyCrypter crypter, KeyChainFactory factory); void upgradeToDeterministic(Script.ScriptType preferredScriptType, KeyChainGroupStructure structure,
            long keyRotationTimeSecs, @Nullable KeyParameter aesKey); boolean isDeterministicUpgradeRequired(Script.ScriptType preferredScriptType, long keyRotationTimeSecs); String toString(boolean includeLookahead, boolean includePrivateKeys, @Nullable KeyParameter aesKey); List<DeterministicKeyChain> getDeterministicKeyChains(); int getCombinedKeyLookaheadEpochs(); }
KeyChainGroup implements KeyBag { public Address freshAddress(KeyChain.KeyPurpose purpose, Script.ScriptType outputScriptType, long keyRotationTimeSecs) { DeterministicKeyChain chain = getActiveKeyChain(outputScriptType, keyRotationTimeSecs); return Address.fromKey(params, chain.getKey(purpose), outputScriptType); } private  KeyChainGroup(NetworkParameters params, @Nullable BasicKeyChain basicKeyChain,
            @Nullable List<DeterministicKeyChain> chains, int lookaheadSize, int lookaheadThreshold,
            @Nullable EnumMap<KeyChain.KeyPurpose, DeterministicKey> currentKeys, @Nullable KeyCrypter crypter); static KeyChainGroup createBasic(NetworkParameters params); static KeyChainGroup.Builder builder(NetworkParameters params); static KeyChainGroup.Builder builder(NetworkParameters params, KeyChainGroupStructure structure); boolean isSupportsDeterministicChains(); void addAndActivateHDChain(DeterministicKeyChain chain); DeterministicKey currentKey(KeyChain.KeyPurpose purpose); Address currentAddress(KeyChain.KeyPurpose purpose); DeterministicKey freshKey(KeyChain.KeyPurpose purpose); List<DeterministicKey> freshKeys(KeyChain.KeyPurpose purpose, int numberOfKeys); Address freshAddress(KeyChain.KeyPurpose purpose, Script.ScriptType outputScriptType, long keyRotationTimeSecs); Address freshAddress(KeyChain.KeyPurpose purpose); List<DeterministicKeyChain> getActiveKeyChains(long keyRotationTimeSecs); final DeterministicKeyChain getActiveKeyChain(Script.ScriptType outputScriptType, long keyRotationTimeSecs); final DeterministicKeyChain getActiveKeyChain(); final void mergeActiveKeyChains(KeyChainGroup from, long keyRotationTimeSecs); int getLookaheadSize(); int getLookaheadThreshold(); int importKeys(List<ECKey> keys); int importKeys(ECKey... keys); boolean checkPassword(CharSequence password); boolean checkAESKey(KeyParameter aesKey); int importKeysAndEncrypt(final List<ECKey> keys, KeyParameter aesKey); @Override @Nullable RedeemData findRedeemDataFromScriptHash(byte[] scriptHash); void markP2SHAddressAsUsed(LegacyAddress address); @Nullable @Override ECKey findKeyFromPubKeyHash(byte[] pubKeyHash, @Nullable Script.ScriptType scriptType); void markPubKeyHashAsUsed(byte[] pubKeyHash); boolean hasKey(ECKey key); @Nullable @Override ECKey findKeyFromPubKey(byte[] pubKey); void markPubKeyAsUsed(byte[] pubkey); int numKeys(); boolean removeImportedKey(ECKey key); final boolean isMarried(); void encrypt(KeyCrypter keyCrypter, KeyParameter aesKey); void decrypt(KeyParameter aesKey); boolean isEncrypted(); boolean isWatching(); @Nullable KeyCrypter getKeyCrypter(); List<ECKey> getImportedKeys(); long getEarliestKeyCreationTime(); int getBloomFilterElementCount(); BloomFilter getBloomFilter(int size, double falsePositiveRate, long nTweak); boolean isRequiringUpdateAllBloomFilter(); void addEventListener(KeyChainEventListener listener); void addEventListener(KeyChainEventListener listener, Executor executor); boolean removeEventListener(KeyChainEventListener listener); void addCurrentKeyChangeEventListener(CurrentKeyChangeEventListener listener); void addCurrentKeyChangeEventListener(CurrentKeyChangeEventListener listener, Executor executor); boolean removeCurrentKeyChangeEventListener(CurrentKeyChangeEventListener listener); List<Protos.Key> serializeToProtobuf(); static KeyChainGroup fromProtobufUnencrypted(NetworkParameters params, List<Protos.Key> keys, KeyChainFactory factory); static KeyChainGroup fromProtobufEncrypted(NetworkParameters params, List<Protos.Key> keys, KeyCrypter crypter, KeyChainFactory factory); void upgradeToDeterministic(Script.ScriptType preferredScriptType, KeyChainGroupStructure structure,
            long keyRotationTimeSecs, @Nullable KeyParameter aesKey); boolean isDeterministicUpgradeRequired(Script.ScriptType preferredScriptType, long keyRotationTimeSecs); String toString(boolean includeLookahead, boolean includePrivateKeys, @Nullable KeyParameter aesKey); List<DeterministicKeyChain> getDeterministicKeyChains(); int getCombinedKeyLookaheadEpochs();  }