/** * Returns a list of the non-deterministic keys that have been imported into the wallet, or the empty list if none. */ public List<ECKey> getImportedKeys() { return basic.getKeys(); }
/** * Returns a list of the non-deterministic keys that have been imported into the wallet, or the empty list if none. */ public List<ECKey> getImportedKeys() { return basic.getKeys(); }
/** * Returns a list of the non-deterministic keys that have been imported into the wallet, or the empty list if none. */ public List<ECKey> getImportedKeys() { return basic.getKeys(); }
/** * Returns a list of the non-deterministic keys that have been imported into the wallet, or the empty list if none. */ public List<ECKey> getImportedKeys() { return basic.getKeys(); }
public String toString(boolean includePrivateKeys, @Nullable KeyParameter aesKey) { final StringBuilder builder = new StringBuilder(); if (basic != null) { List<ECKey> keys = basic.getKeys(); Collections.sort(keys, ECKey.AGE_COMPARATOR); for (ECKey key : keys) key.formatKeyWithAddress(includePrivateKeys, aesKey, builder, params); } for (DeterministicKeyChain chain : chains) builder.append(chain.toString(includePrivateKeys, aesKey, params)).append('\n'); return builder.toString(); }
public String toString(boolean includePrivateKeys) { final StringBuilder builder = new StringBuilder(); if (basic != null) { List<ECKey> keys = basic.getKeys(); Collections.sort(keys, ECKey.AGE_COMPARATOR); for (ECKey key : keys) key.formatKeyWithAddress(includePrivateKeys, builder, params); } for (DeterministicKeyChain chain : chains) builder.append(chain.toString(includePrivateKeys, params)).append('\n'); return builder.toString(); }
public String toString(boolean includePrivateKeys) { final StringBuilder builder = new StringBuilder(); if (basic != null) { List<ECKey> keys = basic.getKeys(); Collections.sort(keys, ECKey.AGE_COMPARATOR); for (ECKey key : keys) key.formatKeyWithAddress(includePrivateKeys, builder, params); } for (DeterministicKeyChain chain : chains) builder.append(chain.toString(includePrivateKeys, params)).append('\n'); return builder.toString(); }
public String toString(boolean includePrivateKeys) { final StringBuilder builder = new StringBuilder(); if (basic != null) { List<ECKey> keys = basic.getKeys(); Collections.sort(keys, ECKey.AGE_COMPARATOR); for (ECKey key : keys) key.formatKeyWithAddress(includePrivateKeys, builder, params); } for (DeterministicKeyChain chain : chains) builder.append(chain.toString(includePrivateKeys, params)).append('\n'); return builder.toString(); }
/* package */ List<ECKey> getKeys(boolean includeLookahead) { List<ECKey> keys = basicKeyChain.getKeys(); if (!includeLookahead) { 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(internalParentKey) && detkey.getChildNumber().i() >= issuedInternalKeys) continue; if (parent.equals(externalParentKey) && detkey.getChildNumber().i() >= issuedExternalKeys) continue; issuedKeys.add(detkey); } return issuedKeys; } return keys; }
/* package */ List<ECKey> getKeys(boolean includeLookahead, boolean includeParents) { List<ECKey> keys = basicKeyChain.getKeys(); if (!includeLookahead) { int treeSize = internalParentKey.getPath().size(); List<ECKey> issuedKeys = new LinkedList<>(); for (ECKey key : keys) { DeterministicKey detkey = (DeterministicKey) key; DeterministicKey parent = detkey.getParent(); if (!includeParents && parent == null) continue; if (!includeParents && detkey.getPath().size() <= treeSize) continue; if (internalParentKey.equals(parent) && detkey.getChildNumber().i() >= issuedInternalKeys) continue; if (externalParentKey.equals(parent) && detkey.getChildNumber().i() >= issuedExternalKeys) continue; issuedKeys.add(detkey); } return issuedKeys; } return keys; }
/* package */ List<ECKey> getKeys(boolean includeLookahead, boolean includeParents) { List<ECKey> keys = basicKeyChain.getKeys(); if (!includeLookahead) { int treeSize = internalParentKey.getPath().size(); List<ECKey> issuedKeys = new LinkedList<>(); for (ECKey key : keys) { DeterministicKey detkey = (DeterministicKey) key; DeterministicKey parent = detkey.getParent(); if (!includeParents && parent == null) continue; if (!includeParents && detkey.getPath().size() <= treeSize) continue; if (internalParentKey.equals(parent) && detkey.getChildNumber().i() >= issuedInternalKeys) continue; if (externalParentKey.equals(parent) && detkey.getChildNumber().i() >= issuedExternalKeys) continue; issuedKeys.add(detkey); } return issuedKeys; } return keys; }
/* package */ List<ECKey> getKeys(boolean includeLookahead) { List<ECKey> keys = basicKeyChain.getKeys(); if (!includeLookahead) { 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(internalParentKey) && detkey.getChildNumber().i() >= issuedInternalKeys) continue; if (parent.equals(externalParentKey) && detkey.getChildNumber().i() >= issuedExternalKeys) continue; issuedKeys.add(detkey); } return issuedKeys; } return keys; }
@Override public DeterministicKeyChain toDecrypted(KeyParameter aesKey) { checkState(getKeyCrypter() != null, "Key chain not encrypted"); checkState(seed != null, "Can't decrypt a watching chain"); checkState(seed.isEncrypted()); String passphrase = DEFAULT_PASSPHRASE_FOR_MNEMONIC; // FIXME allow non-empty passphrase DeterministicSeed decSeed = seed.decrypt(getKeyCrypter(), passphrase, aesKey); DeterministicKeyChain chain = makeKeyChainFromSeed(decSeed); // Now double check that the keys match to catch the case where the key is wrong but padding didn't catch it. if (!chain.getWatchingKey().getPubKeyPoint().equals(getWatchingKey().getPubKeyPoint())) throw new KeyCrypterException("Provided AES key is wrong"); chain.lookaheadSize = lookaheadSize; // Now copy the (pubkey only) leaf keys across to avoid rederiving them. The private key bytes are missing // anyway so there's nothing to decrypt. for (ECKey eckey : basicKeyChain.getKeys()) { DeterministicKey key = (DeterministicKey) eckey; if (key.getPath().size() != getAccountPath().size() + 2) continue; // Not a leaf key. checkState(key.isEncrypted()); DeterministicKey parent = chain.hierarchy.get(checkNotNull(key.getParent()).getPath(), false, false); // Clone the key to the new decrypted hierarchy. key = new DeterministicKey(key.dropPrivateBytes(), parent); chain.hierarchy.putKey(key); chain.basicKeyChain.importKey(key); } chain.issuedExternalKeys = issuedExternalKeys; chain.issuedInternalKeys = issuedInternalKeys; return chain; }
@Override public DeterministicKeyChain toDecrypted(KeyParameter aesKey) { checkState(getKeyCrypter() != null, "Key chain not encrypted"); checkState(seed != null, "Can't decrypt a watching chain"); checkState(seed.isEncrypted()); String passphrase = DEFAULT_PASSPHRASE_FOR_MNEMONIC; // FIXME allow non-empty passphrase DeterministicSeed decSeed = seed.decrypt(getKeyCrypter(), passphrase, aesKey); DeterministicKeyChain chain = makeKeyChainFromSeed(decSeed, useSegwit); // Now double check that the keys match to catch the case where the key is wrong but padding didn't catch it. if (!chain.getWatchingKey().getPubKeyPoint().equals(getWatchingKey().getPubKeyPoint())) throw new KeyCrypterException("Provided AES key is wrong"); chain.lookaheadSize = lookaheadSize; // Now copy the (pubkey only) leaf keys across to avoid rederiving them. The private key bytes are missing // anyway so there's nothing to decrypt. for (ECKey eckey : basicKeyChain.getKeys()) { DeterministicKey key = (DeterministicKey) eckey; if (key.getPath().size() != getAccountPath().size() + 2) continue; // Not a leaf key. checkState(key.isEncrypted()); DeterministicKey parent = chain.hierarchy.get(checkNotNull(key.getParent()).getPath(), false, false); // Clone the key to the new decrypted hierarchy. key = new DeterministicKey(key.dropPrivateBytes(), parent); chain.hierarchy.putKey(key); chain.basicKeyChain.importKey(key); } chain.issuedExternalKeys = issuedExternalKeys; chain.issuedInternalKeys = issuedInternalKeys; return chain; }
@Override public DeterministicKeyChain toDecrypted(KeyParameter aesKey) { checkState(getKeyCrypter() != null, "Key chain not encrypted"); checkState(seed != null, "Can't decrypt a watching chain"); checkState(seed.isEncrypted()); String passphrase = DEFAULT_PASSPHRASE_FOR_MNEMONIC; // FIXME allow non-empty passphrase DeterministicSeed decSeed = seed.decrypt(getKeyCrypter(), passphrase, aesKey); DeterministicKeyChain chain = makeKeyChainFromSeed(decSeed); // Now double check that the keys match to catch the case where the key is wrong but padding didn't catch it. if (!chain.getWatchingKey().getPubKeyPoint().equals(getWatchingKey().getPubKeyPoint())) throw new KeyCrypterException("Provided AES key is wrong"); chain.lookaheadSize = lookaheadSize; // Now copy the (pubkey only) leaf keys across to avoid rederiving them. The private key bytes are missing // anyway so there's nothing to decrypt. for (ECKey eckey : basicKeyChain.getKeys()) { DeterministicKey key = (DeterministicKey) eckey; if (key.getPath().size() != getAccountPath().size() + 2) continue; // Not a leaf key. checkState(key.isEncrypted()); DeterministicKey parent = chain.hierarchy.get(checkNotNull(key.getParent()).getPath(), false, false); // Clone the key to the new decrypted hierarchy. key = new DeterministicKey(key.dropPrivateBytes(), parent); chain.hierarchy.putKey(key); chain.basicKeyChain.importKey(key); } chain.issuedExternalKeys = issuedExternalKeys; chain.issuedInternalKeys = issuedInternalKeys; return chain; }
@Override public DeterministicKeyChain toDecrypted(KeyParameter aesKey) { checkState(getKeyCrypter() != null, "Key chain not encrypted"); checkState(seed != null, "Can't decrypt a watching chain"); checkState(seed.isEncrypted()); String passphrase = DEFAULT_PASSPHRASE_FOR_MNEMONIC; // FIXME allow non-empty passphrase DeterministicSeed decSeed = seed.decrypt(getKeyCrypter(), passphrase, aesKey); DeterministicKeyChain chain = makeKeyChainFromSeed(decSeed, getAccountPath()); // Now double check that the keys match to catch the case where the key is wrong but padding didn't catch it. if (!chain.getWatchingKey().getPubKeyPoint().equals(getWatchingKey().getPubKeyPoint())) throw new KeyCrypterException("Provided AES key is wrong"); chain.lookaheadSize = lookaheadSize; // Now copy the (pubkey only) leaf keys across to avoid rederiving them. The private key bytes are missing // anyway so there's nothing to decrypt. for (ECKey eckey : basicKeyChain.getKeys()) { DeterministicKey key = (DeterministicKey) eckey; if (key.getPath().size() != getAccountPath().size() + 2) continue; // Not a leaf key. checkState(key.isEncrypted()); DeterministicKey parent = chain.hierarchy.get(checkNotNull(key.getParent()).getPath(), false, false); // Clone the key to the new decrypted hierarchy. key = new DeterministicKey(key.dropPrivateBytes(), parent); chain.hierarchy.putKey(key); chain.basicKeyChain.importKey(key); } chain.issuedExternalKeys = issuedExternalKeys; chain.issuedInternalKeys = issuedInternalKeys; return chain; }
@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 public void serializationUnencrypted() throws UnreadableWalletException { Utils.setMockClock(); Date now = Utils.now(); final ECKey key1 = new ECKey(); Utils.rollMockClock(5000); final ECKey key2 = new ECKey(); chain.importKeys(ImmutableList.of(key1, key2)); List<Protos.Key> keys = chain.serializeToProtobuf(); assertEquals(2, keys.size()); assertArrayEquals(key1.getPubKey(), keys.get(0).getPublicKey().toByteArray()); assertArrayEquals(key2.getPubKey(), keys.get(1).getPublicKey().toByteArray()); assertArrayEquals(key1.getPrivKeyBytes(), keys.get(0).getSecretBytes().toByteArray()); assertArrayEquals(key2.getPrivKeyBytes(), keys.get(1).getSecretBytes().toByteArray()); long normTime = (long) (Math.floor(now.getTime() / 1000) * 1000); assertEquals(normTime, keys.get(0).getCreationTimestamp()); assertEquals(normTime + 5000 * 1000, keys.get(1).getCreationTimestamp()); chain = BasicKeyChain.fromProtobufUnencrypted(keys); assertEquals(2, chain.getKeys().size()); assertEquals(key1, chain.getKeys().get(0)); assertEquals(key2, chain.getKeys().get(1)); }
for (ECKey eckey : chain.basicKeyChain.getKeys()) { DeterministicKey key = (DeterministicKey) eckey; if (key.getPath().size() != getAccountPath().size() + 2) continue; // Not a leaf key.
for (ECKey eckey : chain.basicKeyChain.getKeys()) { DeterministicKey key = (DeterministicKey) eckey; if (key.getPath().size() != getAccountPath().size() + 2) continue; // Not a leaf key.