/** * Returns a key that hasn't been seen in a transaction yet, and which is suitable for displaying in a wallet * user interface as "a convenient key to receive funds on" when the purpose parameter is * {@link org.bitcoinj.wallet.KeyChain.KeyPurpose#RECEIVE_FUNDS}. The returned key is stable until * it's actually seen in a pending or confirmed transaction, at which point this method will start returning * a different key (for each purpose independently). */ public DeterministicKey currentKey(KeyChain.KeyPurpose purpose) { keyChainGroupLock.lock(); try { maybeUpgradeToHD(); return keyChainGroup.currentKey(purpose); } finally { keyChainGroupLock.unlock(); } }
/** * Returns a key that hasn't been seen in a transaction yet, and which is suitable for displaying in a wallet * user interface as "a convenient key to receive funds on" when the purpose parameter is * {@link org.bitcoinj.wallet.KeyChain.KeyPurpose#RECEIVE_FUNDS}. The returned key is stable until * it's actually seen in a pending or confirmed transaction, at which point this method will start returning * a different key (for each purpose independently). */ public DeterministicKey currentKey(KeyChain.KeyPurpose purpose) { keyChainGroupLock.lock(); try { maybeUpgradeToHD(); return keyChainGroup.currentKey(purpose); } finally { keyChainGroupLock.unlock(); } }
/** * Returns a key that hasn't been seen in a transaction yet, and which is suitable for displaying in a wallet * user interface as "a convenient key to receive funds on" when the purpose parameter is * {@link org.bitcoinj.wallet.KeyChain.KeyPurpose#RECEIVE_FUNDS}. The returned key is stable until * it's actually seen in a pending or confirmed transaction, at which point this method will start returning * a different key (for each purpose independently). */ public DeterministicKey currentKey(KeyChain.KeyPurpose purpose) { keyChainGroupLock.lock(); try { maybeUpgradeToHD(); return keyChainGroup.currentKey(purpose); } finally { keyChainGroupLock.unlock(); } }
/** * Returns a key that hasn't been seen in a transaction yet, and which is suitable for displaying in a wallet * user interface as "a convenient key to receive funds on" when the purpose parameter is * {@link org.bitcoinj.wallet.KeyChain.KeyPurpose#RECEIVE_FUNDS}. The returned key is stable until * it's actually seen in a pending or confirmed transaction, at which point this method will start returning * a different key (for each purpose independently). */ public DeterministicKey currentKey(KeyChain.KeyPurpose purpose) { keyChainGroupLock.lock(); try { maybeUpgradeToHD(); return keyChainGroup.currentKey(purpose); } finally { keyChainGroupLock.unlock(); } }
/** * Returns address for a {@link #currentKey(KeyChain.KeyPurpose)} */ public Address currentAddress(KeyChain.KeyPurpose purpose) { DeterministicKeyChain chain = getActiveKeyChain(); if (chain.isMarried()) { Address current = currentAddresses.get(purpose); if (current == null) { current = freshAddress(purpose); currentAddresses.put(purpose, current); } return current; } else { return useSegwit ? currentKey(purpose).toSegwitAddress(params) : currentKey(purpose).toAddress(params); } }
/** * Returns address for a {@link #currentKey(KeyChain.KeyPurpose)} */ public Address currentAddress(KeyChain.KeyPurpose purpose) { DeterministicKeyChain chain = getActiveKeyChain(); if (chain.isMarried()) { Address current = currentAddresses.get(purpose); if (current == null) { current = freshAddress(purpose); currentAddresses.put(purpose, current); } return current; } else { return currentKey(purpose).toAddress(params); } }
/** * Returns address for a {@link #currentKey(KeyChain.KeyPurpose)} */ public Address currentAddress(KeyChain.KeyPurpose purpose) { DeterministicKeyChain chain = getActiveKeyChain(); if (chain.isMarried()) { Address current = currentAddresses.get(purpose); if (current == null) { current = freshAddress(purpose); currentAddresses.put(purpose, current); } return current; } else { return currentKey(purpose).toAddress(params); } }
/** * Returns address for a {@link #currentKey(KeyChain.KeyPurpose)} */ public Address currentAddress(KeyChain.KeyPurpose purpose) { DeterministicKeyChain chain = getActiveKeyChain(); if (chain.isMarried()) { Address current = currentAddresses.get(purpose); if (current == null) { current = freshAddress(purpose); currentAddresses.put(purpose, current); } return current; } else { return currentKey(purpose).toAddress(params); } }
@Test public void freshCurrentKeysForMarriedKeychain() throws Exception { group = createMarriedKeyChainGroup(); try { group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); fail(); } catch (UnsupportedOperationException e) { } try { group.currentKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); fail(); } catch (UnsupportedOperationException e) { } }
assertEquals(numKeys, group.numKeys()); assertEquals(2 * numKeys, group.getBloomFilterElementCount()); ECKey r1 = group.currentKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertEquals(numKeys, group.numKeys()); assertEquals(2 * numKeys, group.getBloomFilterElementCount()); assertEquals(2 * numKeys, group.getBloomFilterElementCount()); ECKey r2 = group.currentKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertEquals(r1, r2); ECKey c1 = group.currentKey(KeyChain.KeyPurpose.CHANGE); assertNotEquals(r1, c1); ECKey r3 = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertNotEquals(r3, c2); ECKey r4 = group.currentKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertEquals(r2, r4); ECKey c3 = group.currentKey(KeyChain.KeyPurpose.CHANGE); assertEquals(c1, c3); ECKey r5 = group.currentKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertNotEquals(r4, r5);
@Test public void encryptionWhilstEmpty() throws Exception { group = new KeyChainGroup(PARAMS); group.setLookaheadSize(5); KeyCrypterScrypt scrypt = new KeyCrypterScrypt(2); final KeyParameter aesKey = scrypt.deriveKey("password"); group.encrypt(scrypt, aesKey); assertTrue(group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS).isEncrypted()); final ECKey key = group.currentKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); group.decrypt(aesKey); assertFalse(checkNotNull(group.findKeyFromPubKey(key.getPubKey())).isEncrypted()); }
assertTrue(group.hasKey(key1)); assertTrue(group.hasKey(key2)); assertEquals(key2, group.currentKey(KeyChain.KeyPurpose.CHANGE)); assertEquals(key1, group.currentKey(KeyChain.KeyPurpose.RECEIVE_FUNDS)); group = KeyChainGroup.fromProtobufUnencrypted(PARAMS, protoKeys2); assertEquals(initialKeys + ((LOOKAHEAD_SIZE + 1) * 2) + 1 /* for the seed */ + 2, protoKeys2.size());