@Override protected Void doInBackground(Void... params) { KeyParameter key = null; exception = null; try { if (wallet.isEncrypted() && wallet.getKeyCrypter() != null) { key = wallet.getKeyCrypter().deriveKey(password); } newAccount = wallet.createAccount(type, true, key); if (description != null && !description.trim().isEmpty()) { newAccount.setDescription(description); } wallet.saveNow(); } catch (Exception e) { exception = e; } return null; }
public WalletAccount createAccount(CoinType coin, boolean generateAllKeys, @Nullable KeyParameter key) { return createAccounts(Lists.newArrayList(coin), generateAllKeys, key).get(0); }
public WalletAccount refresh(String accountIdToReset) { lock.lock(); try { WalletAccount account = getAccount(accountIdToReset); if (account != null) { account.refresh(); saveLater(); } return account; } finally { lock.unlock(); } }
KeyParameter aesKey = null; DeterministicKey masterKey = null; DeterministicSeed seed = wallet.getSeed(); if (seed != null) { try { if (wallet.getKeyCrypter() != null) { KeyCrypter crypter = wallet.getKeyCrypter(); aesKey = crypter.deriveKey(password); seed = wallet.getSeed().decrypt(crypter, password.toString(), aesKey); masterKey = wallet.getMasterKey().decrypt(crypter, aesKey); } else { masterKey = wallet.getMasterKey(); seedInfo.seedString = Wallet.mnemonicToString(seed.getMnemonicCode()); DeterministicKey testMasterKey = HDKeyDerivation.createMasterPrivateKey(seed.getSeedBytes()); seedInfo.isSeedPasswordProtected = !masterKey.getPrivKey().equals(testMasterKey.getPrivKey());
@Test public void serializeEncryptedNormal() throws Exception { wallet.maybeInitializeAllPockets(); wallet.encrypt(crypter, aesKey); assertNull(wallet.getSeed().getMnemonicCode()); Protos.Wallet walletProto = wallet.toProtobuf(); Wallet newWallet = WalletProtobufSerializer.readWallet(walletProto); assertEquals(walletProto.toString(), newWallet.toProtobuf().toString()); wallet.decrypt(aesKey); // One is encrypted, so they should not match assertNotEquals(wallet.toProtobuf().toString(), newWallet.toProtobuf().toString()); newWallet.decrypt(aesKey); assertEquals(wallet.toProtobuf().toString(), newWallet.toProtobuf().toString()); assertArrayEquals(MNEMONIC.toArray(), newWallet.getMnemonicCode().toArray()); }
List<WalletAccount> currentAccount = getAccounts(coinType); if (currentAccount.size() > 0) { return currentAccount.get(0); if (isEncrypted()) { hierarchy = new DeterministicHierarchy(masterKey.decrypt(getKeyCrypter(), key)); } else { hierarchy= new DeterministicHierarchy(masterKey); int newIndex = getLastAccountIndex(coinType) + 1; DeterministicKey rootKey = hierarchy.get(coinType.getBip44Path(newIndex), false, true); newPocket = new WalletPocketHD(rootKey, coinType, getKeyCrypter(), key); } else if (coinType instanceof NxtFamily) { newPocket = new NxtFamilyWallet(rootKey, coinType, getKeyCrypter(), key); } else { throw new UnsupportedCoinTypeException(coinType); if (isEncrypted() && !newPocket.isEncrypted()) { newPocket.encrypt(getKeyCrypter(), key); addAccount(newPocket); return newPocket;
this.publishProgress(""); walletApplication.setEmptyWallet(); wallet = new Wallet(seedWords, seedPassword); KeyParameter aesKey = null; if (password != null && !password.isEmpty()) { KeyCrypterScrypt crypter = new KeyCrypterScrypt(); aesKey = crypter.deriveKey(password); wallet.encrypt(crypter, aesKey); wallet.createAccount(type, false, aesKey);
walletBuilder.setVersion(wallet.getVersion()); if (wallet.getSeed() != null) { Protos.Key.Builder mnemonicEntry = KeyUtils.serializeEncryptableItem(wallet.getSeed()); mnemonicEntry.setType(Protos.Key.Type.DETERMINISTIC_MNEMONIC); walletBuilder.setSeed(mnemonicEntry.build()); KeyCrypter keyCrypter = wallet.getKeyCrypter(); if (keyCrypter == null) { for (WalletAccount account : wallet.getAllAccounts()) { Protos.WalletPocket pocketProto; if (account instanceof WalletPocketHD) {
try { if (sourceAccount != null) { if (wallet.isEncrypted()) { KeyCrypter crypter = checkNotNull(wallet.getKeyCrypter()); request.aesKey = crypter.deriveKey(password); wallet.getAccounts(request.tx.getSentTo().get(0).getAddress()).get(0); if (!account.broadcastTxSync(request.tx)) { throw new Exception("Error broadcasting transaction: " + request.tx.getHashAsString());
@Before public void setup() throws MnemonicException, UnreadableWalletException { DeterministicSeed seed = new DeterministicSeed(recoveryPhrase, null, "", 0); DeterministicKey masterKey = HDKeyDerivation.createMasterPrivateKey(seed.getSeedBytes()); hierarchy = new DeterministicHierarchy(masterKey); wallet = new Wallet(recoveryPhrase); nxtAccount = (NxtFamilyWallet)wallet.createAccount(NXT, null); otherAccount = new NxtFamilyWallet(hierarchy.get(NXT.getBip44Path(1), false, true), NXT); }
/* package */ void decrypt(KeyParameter aesKey) { checkNotNull(aesKey, "Attemting to decrypt with a null KeyParameter"); lock.lock(); try { checkState(isEncrypted(), "Wallet is already decrypted"); if (seed != null) { checkState(seed.isEncrypted(), "Seed is already decrypted"); List<String> mnemonic = null; try { mnemonic = decodeMnemonicCode(getKeyCrypter().decrypt(seed.getEncryptedData(), aesKey)); } catch (UnreadableWalletException e) { throw new RuntimeException(e); } seed = new DeterministicSeed(new byte[16], mnemonic, 0); } masterKey = masterKey.decrypt(getKeyCrypter(), aesKey); for (WalletAccount account : accounts.values()) { if (account.isEncryptable()) { account.decrypt(aesKey); } } } finally { lock.unlock(); } }
@Before public void setup() throws IOException, MnemonicException { BriefLogFormatter.init(); wallet = new Wallet(MNEMONIC); ImmutableList<CoinType> typesToCreate = ImmutableList.of(BitcoinMain.get(), LitecoinMain.get(), DogecoinMain.get()); wallet.createAccounts(typesToCreate, true, aesKey); }
KeyUtils.getDeterministicKey(walletProto.getMasterKey(), null, crypter); Wallet wallet = new Wallet(masterKey, seed); wallet.setVersion(walletProto.getVersion()); wallet.addAccount(pocket);
public List<WalletAccount> getAllAccounts() { if (wallet != null) { return wallet.getAllAccounts(); } else { return ImmutableList.of(); } }
private static void updateV1toV2(Wallet wallet) { checkState(wallet.getVersion() < 2, "Can update only from version < 2"); wallet.setVersion(2); for (WalletAccount walletAccount : wallet.getAllAccounts()) { if (walletAccount instanceof WalletPocketHD) { WalletPocketHD account = (WalletPocketHD) walletAccount;
if (intent.hasExtra(Constants.ARG_ACCOUNT_ID)) { String accountId = intent.getStringExtra(Constants.ARG_ACCOUNT_ID); WalletAccount account = wallet.getAccount(accountId); if (account != null) { account.refresh(); for (WalletAccount account : wallet.getAllAccounts()) { account.refresh(); if (intent.hasExtra(Constants.ARG_ACCOUNT_ID)) { lastAccount = intent.getStringExtra(Constants.ARG_ACCOUNT_ID); WalletAccount account = wallet.getAccount(lastAccount); if (account != null) { if (clients == null && connHelper.isConnected()) { for (WalletAccount account : wallet.getAllAccounts()) { clients.startAsync(account);
public WalletAccount createAccount(CoinType coin, @Nullable KeyParameter key) { return createAccount(coin, false, key); }
public List<WalletAccount> getAccounts(CoinType type) { if (wallet != null) { return wallet.getAccounts(type); } else { return ImmutableList.of(); } }
private void updateView() { if (seedInfo != null) { seedLayout.setVisibility(View.VISIBLE); seedEncryptedLayout.setVisibility(View.GONE); seedView.setText(seedInfo.seedString); QrUtils.setQr(qrView, getResources(), seedInfo.seedString); if (seedInfo.isSeedPasswordProtected) { seedPasswordProtectedView.setVisibility(View.VISIBLE); } else { seedPasswordProtectedView.setVisibility(View.GONE); } } else if (wallet != null) { if (wallet.getSeed() == null) { if (listener != null) listener.onSeedNotAvailable(); } else if (wallet.getSeed().isEncrypted()) { seedEncryptedLayout.setVisibility(View.VISIBLE); if (password == null) { showUnlockDialog(); } else { maybeStartDecryptTask(); } } else { seedEncryptedLayout.setVisibility(View.GONE); maybeStartDecryptTask(); } } }
@Override protected Void doInBackground(Void... params) { DeterministicKey masterKey = wallet.getMasterKey(); tryDecrypt(masterKey, password, result); return null; }