use of org.bitcoinj.wallet.DeterministicSeed in project bitrafael_public by GENERALBYTESCOM.
the class WalletToolsBTC method getMasterPrivateKey.
public MasterPrivateKeyBTC getMasterPrivateKey(String seedMnemonicSeparatedBySpaces, String password, String cryptoCurrency) {
if (password == null) {
password = "";
}
List<String> split = ImmutableList.copyOf(Splitter.on(" ").omitEmptyStrings().split(seedMnemonicSeparatedBySpaces));
DeterministicSeed seed = new DeterministicSeed(split, null, password, MnemonicCode.BIP39_STANDARDISATION_TIME_SECS);
DeterministicKey masterKey = HDKeyDerivation.createMasterPrivateKey(seed.getSeedBytes());
final String xprv = masterKey.serializePrivB58(MainNetParams.get());
return getMasterPrivateKey(xprv, cryptoCurrency);
}
use of org.bitcoinj.wallet.DeterministicSeed in project bitsquare by bitsquare.
the class SeedWordsView method doRestore.
private void doRestore() {
long date = restoreDatePicker.getValue().atStartOfDay().toEpochSecond(ZoneOffset.UTC);
DeterministicSeed seed = new DeterministicSeed(Splitter.on(" ").splitToList(restoreSeedWordsTextArea.getText()), null, "", date);
walletService.restoreSeedWords(seed, () -> UserThread.execute(() -> {
log.info("Wallet restored with seed words");
new Popup().feedback("Wallet restored successfully with the new seed words.\n\n" + "You need to shut down and restart the application.").closeButtonText("Shut down").onClose(BitsquareApp.shutDownHandler::run).show();
}), throwable -> UserThread.execute(() -> {
log.error(throwable.getMessage());
new Popup().error("An error occurred when restoring the wallet with seed words.\n" + "Error message: " + throwable.getMessage()).show();
}));
}
use of org.bitcoinj.wallet.DeterministicSeed in project bitsquare by bitsquare.
the class SeedWordsView method activate.
@Override
public void activate() {
seedWordsValid.addListener(seedWordsValidChangeListener);
dateValid.addListener(datePickerChangeListener);
restoreSeedWordsTextArea.textProperty().addListener(seedWordsTextAreaChangeListener);
restoreDatePicker.valueProperty().addListener(dateChangeListener);
restoreButton.disableProperty().bind(createBooleanBinding(() -> !seedWordsValid.get() || !dateValid.get() || !seedWordsEdited.get(), seedWordsValid, dateValid, seedWordsEdited));
restoreButton.setOnAction(e -> onRestore());
restoreSeedWordsTextArea.getStyleClass().remove("validation_error");
restoreDatePicker.getStyleClass().remove("validation_error");
DeterministicSeed keyChainSeed = walletService.getWallet().getKeyChainSeed();
// wallet creation date is not encrypted
walletCreationDate = Instant.ofEpochSecond(keyChainSeed.getCreationTimeSeconds()).atZone(ZoneId.systemDefault()).toLocalDate();
if (keyChainSeed.isEncrypted()) {
askForPassword();
} else {
String key = "showSeedWordsWarning";
if (preferences.showAgain(key)) {
new Popup().warning("You have not setup a wallet password which would protect the display of the seed words.\n\n" + "Do you want to display the seed words?").actionButtonText("Yes, and don't ask me again").onAction(() -> {
preferences.dontShowAgain(key, true);
initSeedWords(keyChainSeed);
showSeedScreen();
}).closeButtonText("No").show();
} else {
initSeedWords(keyChainSeed);
showSeedScreen();
}
}
}
use of org.bitcoinj.wallet.DeterministicSeed in project bitsquare by bitsquare.
the class WalletPasswordWindow method doRestore.
private void doRestore() {
long date = restoreDatePicker.getValue().atStartOfDay().toEpochSecond(ZoneOffset.UTC);
DeterministicSeed seed = new DeterministicSeed(Splitter.on(" ").splitToList(restoreSeedWordsTextArea.getText()), null, "", date);
walletService.restoreSeedWords(seed, () -> UserThread.execute(() -> {
log.debug("Wallet restored with seed words");
new Popup().feedback("Wallet restored successfully with the new seed words.\n\n" + "You need to shut down and restart the application.").closeButtonText("Shut down").onClose(BitsquareApp.shutDownHandler::run).show();
}), throwable -> UserThread.execute(() -> {
log.error(throwable.getMessage());
new Popup().error("An error occurred when restoring the wallet with seed words.\n" + "Error message: " + throwable.getMessage()).show();
}));
}
use of org.bitcoinj.wallet.DeterministicSeed in project bitsquare by bitsquare.
the class WalletPasswordWindow method showRestoreScreen.
private void showRestoreScreen() {
Label headLine2Label = new Label(BSResources.get("Restore wallet from seed words"));
headLine2Label.setId("popup-headline");
headLine2Label.setMouseTransparent(true);
GridPane.setHalignment(headLine2Label, HPos.LEFT);
GridPane.setRowIndex(headLine2Label, ++rowIndex);
GridPane.setColumnSpan(headLine2Label, 2);
GridPane.setMargin(headLine2Label, new Insets(30, 0, 0, 0));
gridPane.getChildren().add(headLine2Label);
Separator separator = new Separator();
separator.setMouseTransparent(true);
separator.setOrientation(Orientation.HORIZONTAL);
separator.setStyle("-fx-background: #ccc;");
GridPane.setHalignment(separator, HPos.CENTER);
GridPane.setRowIndex(separator, ++rowIndex);
GridPane.setColumnSpan(separator, 2);
gridPane.getChildren().add(separator);
Tuple2<Label, TextArea> tuple = addLabelTextArea(gridPane, ++rowIndex, "Wallet seed words:", "", 5);
restoreSeedWordsTextArea = tuple.second;
restoreSeedWordsTextArea.setPrefHeight(60);
restoreSeedWordsTextArea.setStyle("-fx-border-color: #ddd;");
Tuple2<Label, DatePicker> labelDatePickerTuple2 = addLabelDatePicker(gridPane, ++rowIndex, "Creation Date:");
restoreDatePicker = labelDatePickerTuple2.second;
restoreButton = addButton(gridPane, ++rowIndex, "Restore wallet");
restoreButton.setDefaultButton(true);
stage.setHeight(340);
DeterministicSeed keyChainSeed = walletService.getWallet().getKeyChainSeed();
// wallet creation date is not encrypted
walletCreationDate = Instant.ofEpochSecond(keyChainSeed.getCreationTimeSeconds()).atZone(ZoneId.systemDefault()).toLocalDate();
restoreButton.disableProperty().bind(createBooleanBinding(() -> !seedWordsValid.get() || !dateValid.get() || !seedWordsEdited.get(), seedWordsValid, dateValid, seedWordsEdited));
seedWordsValidChangeListener = (observable, oldValue, newValue) -> {
if (newValue) {
restoreSeedWordsTextArea.getStyleClass().remove("validation_error");
} else {
restoreSeedWordsTextArea.getStyleClass().add("validation_error");
}
};
seedWordsTextAreaChangeListener = (observable, oldValue, newValue) -> {
seedWordsEdited.set(true);
try {
MnemonicCode codec = new MnemonicCode();
codec.check(Splitter.on(" ").splitToList(newValue));
seedWordsValid.set(true);
} catch (IOException | MnemonicException e) {
seedWordsValid.set(false);
}
};
datePickerChangeListener = (observable, oldValue, newValue) -> {
if (newValue)
restoreDatePicker.getStyleClass().remove("validation_error");
else
restoreDatePicker.getStyleClass().add("validation_error");
};
dateChangeListener = (observable, oldValue, newValue) -> {
dateValid.set(walletCreationDate.equals(newValue));
};
seedWordsValid.addListener(seedWordsValidChangeListener);
dateValid.addListener(datePickerChangeListener);
restoreSeedWordsTextArea.textProperty().addListener(seedWordsTextAreaChangeListener);
restoreDatePicker.valueProperty().addListener(dateChangeListener);
restoreButton.disableProperty().bind(createBooleanBinding(() -> !seedWordsValid.get() || !dateValid.get() || !seedWordsEdited.get(), seedWordsValid, dateValid, seedWordsEdited));
restoreButton.setOnAction(e -> onRestore());
restoreSeedWordsTextArea.getStyleClass().remove("validation_error");
restoreDatePicker.getStyleClass().remove("validation_error");
layout();
}
Aggregations