/** Imports the given keys into the basic chain, creating it if necessary. */ public int importKeys(List<ECKey> keys) { return basic.importKeys(keys); }
/** Imports the given keys into the basic chain, creating it if necessary. */ public int importKeys(List<ECKey> keys) { return basic.importKeys(keys); }
/** Imports the given keys into the basic chain, creating it if necessary. */ public int importKeys(List<ECKey> keys) { return basic.importKeys(keys); }
/** Imports the given keys into the basic chain, creating it if necessary. */ public int importKeys(List<ECKey> keys) { return basic.importKeys(keys); }
public int importKeys(ECKey... keys) { return importKeys(ImmutableList.copyOf(keys)); }
public int importKeys(ECKey... keys) { return importKeys(ImmutableList.copyOf(keys)); }
private void addToBasicChain(DeterministicKey key) { basicKeyChain.importKeys(ImmutableList.of(key)); }
public int importKeys(ECKey... keys) { return importKeys(ImmutableList.copyOf(keys)); }
public int importKeys(ECKey... keys) { return importKeys(ImmutableList.copyOf(keys)); }
private void addToBasicChain(DeterministicKey key) { basicKeyChain.importKeys(ImmutableList.of(key)); }
/** * Pre-generate enough keys to reach the lookahead size. You can call this if you need to explicitly invoke * the lookahead procedure, but it's normally unnecessary as it will be done automatically when needed. */ public void maybeLookAhead() { lock.lock(); try { List<DeterministicKey> keys = maybeLookAhead(externalParentKey, issuedExternalKeys); keys.addAll(maybeLookAhead(internalParentKey, issuedInternalKeys)); if (keys.isEmpty()) return; keyLookaheadEpoch++; // Batch add all keys at once so there's only one event listener invocation, as this will be listened to // by the wallet and used to rebuild/broadcast the Bloom filter. That's expensive so we don't want to do // it more often than necessary. basicKeyChain.importKeys(keys); } finally { lock.unlock(); } }
@Test(expected = KeyCrypterException.class) public void cannotImportEncryptedKey() { final ECKey key1 = new ECKey(); chain.importKeys(ImmutableList.of(key1)); chain = chain.toEncrypted("foobar"); ECKey encryptedKey = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertTrue(encryptedKey.isEncrypted()); BasicKeyChain chain2 = new BasicKeyChain(); chain2.importKeys(ImmutableList.of(encryptedKey)); }
@Test(expected = IllegalStateException.class) public void checkPasswordNotEncrypted() { final ArrayList<ECKey> keys = Lists.newArrayList(new ECKey(), new ECKey()); chain.importKeys(keys); chain.checkPassword("test"); }
@Test(expected = IllegalStateException.class) public void doubleEncryptFails() { final ArrayList<ECKey> keys = Lists.newArrayList(new ECKey(), new ECKey()); chain.importKeys(keys); chain = chain.toEncrypted("foo"); chain.toEncrypted("foo"); }
@Test public void serializationEncrypted() throws UnreadableWalletException { ECKey key1 = new ECKey(); chain.importKeys(key1); chain = chain.toEncrypted("foo bar"); key1 = chain.getKeys().get(0); List<Protos.Key> keys = chain.serializeToProtobuf(); assertEquals(1, keys.size()); assertArrayEquals(key1.getPubKey(), keys.get(0).getPublicKey().toByteArray()); assertFalse(keys.get(0).hasSecretBytes()); assertTrue(keys.get(0).hasEncryptedData()); chain = BasicKeyChain.fromProtobufEncrypted(keys, checkNotNull(chain.getKeyCrypter())); assertEquals(key1.getEncryptedPrivateKey(), chain.getKeys().get(0).getEncryptedPrivateKey()); assertTrue(chain.checkPassword("foo bar")); }
@Test(expected = KeyCrypterException.class) public void cannotMixParams() throws Exception { chain = chain.toEncrypted("foobar"); KeyCrypterScrypt scrypter = new KeyCrypterScrypt(2); // Some bogus params. ECKey key1 = new ECKey().encrypt(scrypter, scrypter.deriveKey("other stuff")); chain.importKeys(key1); }
@Test public void keysBeforeAndAfter() throws Exception { Utils.setMockClock(); long now = Utils.currentTimeSeconds(); final ECKey key1 = new ECKey(); Utils.rollMockClock(86400); final ECKey key2 = new ECKey(); final List<ECKey> keys = Lists.newArrayList(key1, key2); assertEquals(2, chain.importKeys(keys)); assertNull(chain.findOldestKeyAfter(now + 86400 * 2)); assertEquals(key1, chain.findOldestKeyAfter(now - 1)); assertEquals(key2, chain.findOldestKeyAfter(now + 86400 - 1)); assertEquals(2, chain.findKeysBefore(now + 86400 * 2).size()); assertEquals(1, chain.findKeysBefore(now + 1).size()); assertEquals(0, chain.findKeysBefore(now - 1).size()); } }
@Test public void watching() throws UnreadableWalletException { ECKey key1 = new ECKey(); ECKey pub = ECKey.fromPublicOnly(key1.getPubKeyPoint()); chain.importKeys(pub); assertEquals(1, chain.numKeys()); List<Protos.Key> keys = chain.serializeToProtobuf(); assertEquals(1, keys.size()); assertTrue(keys.get(0).hasPublicKey()); assertFalse(keys.get(0).hasSecretBytes()); chain = BasicKeyChain.fromProtobufUnencrypted(keys); assertEquals(1, chain.numKeys()); assertFalse(chain.findKeyFromPubKey(pub.getPubKey()).hasPrivKey()); }
@Test public void removeKey() { ECKey key = new ECKey(); chain.importKeys(key); assertEquals(1, chain.numKeys()); assertTrue(chain.removeKey(key)); assertEquals(0, chain.numKeys()); assertFalse(chain.removeKey(key)); }
@Test public void bloom() throws Exception { ECKey key1 = new ECKey(); ECKey key2 = new ECKey(); chain.importKeys(key1, key2); assertEquals(2, chain.numKeys()); assertEquals(4, chain.numBloomFilterEntries()); BloomFilter filter = chain.getFilter(4, 0.001, 100); assertTrue(filter.contains(key1.getPubKey())); assertTrue(filter.contains(key1.getPubKeyHash())); assertTrue(filter.contains(key2.getPubKey())); assertTrue(filter.contains(key2.getPubKeyHash())); ECKey key3 = new ECKey(); assertFalse(filter.contains(key3.getPubKey())); }