public static KeyChainGroup fromProtobufUnencrypted(NetworkParameters params, List<Protos.Key> keys, KeyChainFactory factory, boolean useSegwit) throws UnreadableWalletException { BasicKeyChain basicKeyChain = BasicKeyChain.fromProtobufUnencrypted(keys, useSegwit); List<DeterministicKeyChain> chains = DeterministicKeyChain.fromProtobuf(keys, null, factory, useSegwit); EnumMap<KeyChain.KeyPurpose, DeterministicKey> currentKeys = null; if (!chains.isEmpty()) currentKeys = createCurrentKeysMap(chains); extractFollowingKeychains(chains); return new KeyChainGroup(params, basicKeyChain, chains, currentKeys, null, useSegwit); }
public static KeyChainGroup fromProtobufUnencrypted(NetworkParameters params, List<Protos.Key> keys, KeyChainFactory factory) throws UnreadableWalletException { BasicKeyChain basicKeyChain = BasicKeyChain.fromProtobufUnencrypted(keys); List<DeterministicKeyChain> chains = DeterministicKeyChain.fromProtobuf(keys, null, factory); EnumMap<KeyChain.KeyPurpose, DeterministicKey> currentKeys = null; if (!chains.isEmpty()) currentKeys = createCurrentKeysMap(chains); extractFollowingKeychains(chains); return new KeyChainGroup(params, basicKeyChain, chains, currentKeys, null); }
public static KeyChainGroup fromProtobufUnencrypted(NetworkParameters params, List<Protos.Key> keys, KeyChainFactory factory) throws UnreadableWalletException { BasicKeyChain basicKeyChain = BasicKeyChain.fromProtobufUnencrypted(keys); List<DeterministicKeyChain> chains = DeterministicKeyChain.fromProtobuf(keys, null, factory); EnumMap<KeyChain.KeyPurpose, DeterministicKey> currentKeys = null; if (!chains.isEmpty()) currentKeys = createCurrentKeysMap(chains); extractFollowingKeychains(chains); return new KeyChainGroup(params, basicKeyChain, chains, currentKeys, null); }
public static KeyChainGroup fromProtobufUnencrypted(NetworkParameters params, List<Protos.Key> keys, KeyChainFactory factory) throws UnreadableWalletException { BasicKeyChain basicKeyChain = BasicKeyChain.fromProtobufUnencrypted(keys); List<DeterministicKeyChain> chains = DeterministicKeyChain.fromProtobuf(keys, null, factory); EnumMap<KeyChain.KeyPurpose, DeterministicKey> currentKeys = null; if (!chains.isEmpty()) currentKeys = createCurrentKeysMap(chains); extractFollowingKeychains(chains); return new KeyChainGroup(params, basicKeyChain, chains, currentKeys, null); }
@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)); }
@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()); }