@Test public void serializeTest() throws UnreadableWalletException { final NetworkParameters PARAMS = UnitTestParams.get(); Context.propagate(new Context(PARAMS, 100, Coin.ZERO, false)); Wallet wallet = new Wallet(PARAMS); Sha256Hash userAhash = Sha256Hash.wrap("c27eb14f698b32e9bb306dba7bbbee831263dcf658abeebb39930460ead117e5"); Sha256Hash userBhash = Sha256Hash.wrap("ee2052ff075c5ca3c16c3e20e9ac8223834475cc1324ab07889cb24ce6a62793"); EvolutionContact contact = new EvolutionContact(userAhash, 0, userBhash); wallet.addAndActivateHDChain(bip44chain); wallet.addReceivingFromFriendKeyChain(bip44chain.getSeed(), bip44chain.getKeyCrypter(), 0, userAhash, userBhash); DeterministicKey currentKey = wallet.receivingFromFriendsGroup.getFriendKeyChain(contact, FriendKeyChain.KeyChainType.RECEIVING_CHAIN).getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); Protos.Wallet protos = new WalletProtobufSerializer().walletToProto(wallet); Wallet walletReloaded = new WalletProtobufSerializer().readWallet(PARAMS, null, protos); assertTrue(walletReloaded.hasReceivingFriendKeyChains()); DeterministicKeyChain friendChain = walletReloaded.receivingFromFriendsGroup.getActiveKeyChain(); DeterministicKey key = friendChain.getWatchingKey(); DeterministicKey currentKeyAfterDeserialization = walletReloaded.receivingFromFriendsGroup.getFriendKeyChain(contact, FriendKeyChain.KeyChainType.RECEIVING_CHAIN).getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); ImmutableList<ChildNumber> accountPath = ImmutableList.of(ChildNumber.NINE_HARDENED, ChildNumber.ONE_HARDENED, DerivationPathFactory.FEATURE_PURPOSE_DASHPAY, ChildNumber.ZERO_HARDENED, new ExtendedChildNumber(userAhash), new ExtendedChildNumber(userBhash)); assertEquals(accountPath, key.getPath()); assertEquals(wallet.receivingFromFriendsGroup.freshKey(contact, FriendKeyChain.KeyChainType.RECEIVING_CHAIN), currentKeyAfterDeserialization); assertEquals(currentKey, walletReloaded.receivingFromFriendsGroup.findKeyFromPubKeyHash(currentKey.getPubKeyHash(), Script.ScriptType.P2PKH)); }
@Override public DeterministicKey getKey(KeyPurpose purpose) { return getKeys(purpose, 1).get(0); }
FriendKeyChain extends ExternalKeyChain { @Override public DeterministicKey getKey(KeyPurpose purpose) { return getKeys(purpose, 1).get(0); } }
FriendKeyChain extends ExternalKeyChain { @Override public DeterministicKey getKey(KeyPurpose purpose) { return getKeys(purpose, 1).get(0); } FriendKeyChain(DeterministicSeed seed, ImmutableList<ChildNumber> rootPath, int account, Sha256Hash myBlockchainUserId, Sha256Hash theirBlockchainUserId);  FriendKeyChain(DeterministicSeed seed, KeyCrypter keyCrypter, ImmutableList<ChildNumber> rootPath,  int account, Sha256Hash myBlockchainUserId, Sha256Hash theirBlockchainUserId);  FriendKeyChain(DeterministicSeed seed, ImmutableList<ChildNumber> path);  FriendKeyChain(DeterministicSeed seed, KeyCrypter keyCrypter, ImmutableList<ChildNumber> path);  FriendKeyChain(NetworkParameters params, String xpub, EvolutionContact contact);  FriendKeyChain(DeterministicKey watchingKey);  FriendKeyChain(DeterministicKey watchingKey, boolean isFollowing); protected  FriendKeyChain(KeyCrypter crypter, KeyParameter aesKey, FriendKeyChain chain); }
FriendKeyChain extends ExternalKeyChain { @Override public DeterministicKey getKey(KeyPurpose purpose) { return getKeys(purpose, 1).get(0); } FriendKeyChain(DeterministicSeed seed, ImmutableList<ChildNumber> rootPath, int account, Sha256Hash myBlockchainUserId, Sha256Hash theirBlockchainUserId);  FriendKeyChain(DeterministicSeed seed, KeyCrypter keyCrypter, ImmutableList<ChildNumber> rootPath,  int account, Sha256Hash myBlockchainUserId, Sha256Hash theirBlockchainUserId);  FriendKeyChain(DeterministicSeed seed, ImmutableList<ChildNumber> path);  FriendKeyChain(DeterministicSeed seed, KeyCrypter keyCrypter, ImmutableList<ChildNumber> path);  FriendKeyChain(NetworkParameters params, String xpub, EvolutionContact contact);  FriendKeyChain(DeterministicKey watchingKey);  FriendKeyChain(DeterministicKey watchingKey, boolean isFollowing); protected  FriendKeyChain(KeyCrypter crypter, KeyParameter aesKey, FriendKeyChain chain); static ImmutableList<ChildNumber> getRootPath(NetworkParameters params); static ImmutableList<ChildNumber> getContactPath(NetworkParameters params, EvolutionContact contact, KeyChainType type); @Override DeterministicKey getKey(KeyPurpose purpose); @Override List<DeterministicKey> getKeys(KeyPurpose purpose, int numberOfKeys); DeterministicKey getKey(int index); KeyChainType getType(); @Override FriendKeyChain toEncrypted(KeyCrypter keyCrypter, KeyParameter aesKey); }
FriendKeyChain extends ExternalKeyChain { @Override public DeterministicKey getKey(KeyPurpose purpose) { return getKeys(purpose, 1).get(0); } FriendKeyChain(DeterministicSeed seed, ImmutableList<ChildNumber> rootPath, int account, Sha256Hash myBlockchainUserId, Sha256Hash theirBlockchainUserId);  FriendKeyChain(DeterministicSeed seed, KeyCrypter keyCrypter, ImmutableList<ChildNumber> rootPath,  int account, Sha256Hash myBlockchainUserId, Sha256Hash theirBlockchainUserId);  FriendKeyChain(DeterministicSeed seed, ImmutableList<ChildNumber> path);  FriendKeyChain(DeterministicSeed seed, KeyCrypter keyCrypter, ImmutableList<ChildNumber> path);  FriendKeyChain(NetworkParameters params, String xpub, EvolutionContact contact);  FriendKeyChain(DeterministicKey watchingKey);  FriendKeyChain(DeterministicKey watchingKey, boolean isFollowing); protected  FriendKeyChain(KeyCrypter crypter, KeyParameter aesKey, FriendKeyChain chain); static ImmutableList<ChildNumber> getRootPath(NetworkParameters params); static ImmutableList<ChildNumber> getContactPath(NetworkParameters params, EvolutionContact contact, KeyChainType type); @Override DeterministicKey getKey(KeyPurpose purpose); @Override List<DeterministicKey> getKeys(KeyPurpose purpose, int numberOfKeys); DeterministicKey getKey(int index); KeyChainType getType(); @Override FriendKeyChain toEncrypted(KeyCrypter keyCrypter, KeyParameter aesKey); static final ImmutableList<ChildNumber> FRIEND_ROOT_PATH; static final ImmutableList<ChildNumber> FRIEND_ROOT_PATH_TESTNET; static final int PATH_INDEX_ACCOUNT; static final int PATH_INDEX_TO_ID; static final int PATH_INDEX_FROM_ID; }