Search in sources :

Example 1 with MnemonicException

use of org.bitcoinj.crypto.MnemonicException in project bitsquare by bitsquare.

the class SeedWordsView method initialize.

@Override
protected void initialize() {
    addTitledGroupBg(root, gridRow, 2, "Backup your wallet seed words");
    displaySeedWordsTextArea = addLabelTextArea(root, gridRow, "Wallet seed words:", "", Layout.FIRST_ROW_DISTANCE).second;
    displaySeedWordsTextArea.setPrefHeight(60);
    displaySeedWordsTextArea.setEditable(false);
    datePicker = addLabelDatePicker(root, ++gridRow, "Wallet Date:").second;
    datePicker.setMouseTransparent(true);
    addTitledGroupBg(root, ++gridRow, 2, "Restore your wallet seed words", Layout.GROUP_DISTANCE);
    restoreSeedWordsTextArea = addLabelTextArea(root, gridRow, "Wallet seed words:", "", Layout.FIRST_ROW_AND_GROUP_DISTANCE).second;
    restoreSeedWordsTextArea.setPrefHeight(60);
    restoreDatePicker = addLabelDatePicker(root, ++gridRow, "Wallet Date:").second;
    restoreButton = addButtonAfterGroup(root, ++gridRow, "Restore wallet");
    addTitledGroupBg(root, ++gridRow, 1, "Information", Layout.GROUP_DISTANCE);
    addMultilineLabel(root, gridRow, "Please write down you wallet seed words and the date! " + "You can recover your wallet any time with those seed words and the date.", Layout.FIRST_ROW_AND_GROUP_DISTANCE);
    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(true);
}
Also used : MnemonicException(org.bitcoinj.crypto.MnemonicException) IOException(java.io.IOException) MnemonicCode(org.bitcoinj.crypto.MnemonicCode)

Example 2 with MnemonicException

use of org.bitcoinj.crypto.MnemonicException in project toshi-android-client by toshiapp.

the class HDWallet method initFromMasterSeed.

private Wallet initFromMasterSeed(final String masterSeed) {
    try {
        final DeterministicSeed seed = getSeed(masterSeed);
        seed.check();
        return constructFromSeed(seed);
    } catch (final UnreadableWalletException | MnemonicException e) {
        LogUtil.exception("Error while initiating from from master seed", e);
        throw new RuntimeException("Unable to create wallet. Seed is invalid");
    }
}
Also used : DeterministicSeed(org.bitcoinj.wallet.DeterministicSeed) UnreadableWalletException(org.bitcoinj.wallet.UnreadableWalletException) MnemonicException(org.bitcoinj.crypto.MnemonicException)

Example 3 with MnemonicException

use of org.bitcoinj.crypto.MnemonicException in project toshi-android-client by toshiapp.

the class HDWallet method createFromMasterSeed.

public Single<HDWallet> createFromMasterSeed(final String masterSeed) {
    return Single.fromCallable(() -> {
        try {
            final DeterministicSeed seed = getSeed(masterSeed);
            seed.check();
            final Wallet wallet = constructFromSeed(seed);
            deriveKeysFromWallet(wallet);
            saveMasterSeedToStorage(masterSeed);
            return this;
        } catch (final UnreadableWalletException | MnemonicException e) {
            LogUtil.exception("Error while creating wallet from master seed", e);
            throw new InvalidMasterSeedException(e);
        }
    });
}
Also used : DeterministicSeed(org.bitcoinj.wallet.DeterministicSeed) UnreadableWalletException(org.bitcoinj.wallet.UnreadableWalletException) MnemonicException(org.bitcoinj.crypto.MnemonicException) Wallet(org.bitcoinj.wallet.Wallet) InvalidMasterSeedException(com.toshi.exception.InvalidMasterSeedException)

Example 4 with MnemonicException

use of org.bitcoinj.crypto.MnemonicException 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();
}
Also used : DeterministicSeed(org.bitcoinj.wallet.DeterministicSeed) MnemonicException(org.bitcoinj.crypto.MnemonicException) Insets(javafx.geometry.Insets) IOException(java.io.IOException) MnemonicCode(org.bitcoinj.crypto.MnemonicCode)

Example 5 with MnemonicException

use of org.bitcoinj.crypto.MnemonicException in project bisq-desktop by bisq-network.

the class SeedWordsView method initialize.

@Override
protected void initialize() {
    addTitledGroupBg(root, gridRow, 2, Res.get("account.seed.backup.title"));
    displaySeedWordsTextArea = addLabelTextArea(root, gridRow, Res.get("seed.seedWords"), "", Layout.FIRST_ROW_DISTANCE).second;
    displaySeedWordsTextArea.setPrefHeight(60);
    displaySeedWordsTextArea.setEditable(false);
    datePicker = addLabelDatePicker(root, ++gridRow, Res.get("seed.date")).second;
    datePicker.setMouseTransparent(true);
    addTitledGroupBg(root, ++gridRow, 2, Res.get("seed.restore.title"), Layout.GROUP_DISTANCE);
    seedWordsTextArea = addLabelTextArea(root, gridRow, Res.get("seed.seedWords"), "", Layout.FIRST_ROW_AND_GROUP_DISTANCE).second;
    seedWordsTextArea.setPrefHeight(60);
    restoreDatePicker = addLabelDatePicker(root, ++gridRow, Res.get("seed.date")).second;
    restoreButton = addButtonAfterGroup(root, ++gridRow, Res.get("seed.restore"));
    addTitledGroupBg(root, ++gridRow, 1, Res.get("shared.information"), Layout.GROUP_DISTANCE);
    addMultilineLabel(root, gridRow, Res.get("account.seed.info"), Layout.FIRST_ROW_AND_GROUP_DISTANCE);
    seedWordsValidChangeListener = (observable, oldValue, newValue) -> {
        if (newValue) {
            seedWordsTextArea.getStyleClass().remove("validation-error");
        } else {
            seedWordsTextArea.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);
        }
    };
}
Also used : MnemonicException(org.bitcoinj.crypto.MnemonicException) IOException(java.io.IOException) MnemonicCode(org.bitcoinj.crypto.MnemonicCode)

Aggregations

MnemonicException (org.bitcoinj.crypto.MnemonicException)6 IOException (java.io.IOException)4 MnemonicCode (org.bitcoinj.crypto.MnemonicCode)4 DeterministicSeed (org.bitcoinj.wallet.DeterministicSeed)3 Insets (javafx.geometry.Insets)2 UnreadableWalletException (org.bitcoinj.wallet.UnreadableWalletException)2 AutoTooltipLabel (bisq.desktop.components.AutoTooltipLabel)1 FormBuilder.addLabelDatePicker (bisq.desktop.util.FormBuilder.addLabelDatePicker)1 FormBuilder.addLabelTextArea (bisq.desktop.util.FormBuilder.addLabelTextArea)1 InvalidMasterSeedException (com.toshi.exception.InvalidMasterSeedException)1 DatePicker (javafx.scene.control.DatePicker)1 Label (javafx.scene.control.Label)1 Separator (javafx.scene.control.Separator)1 TextArea (javafx.scene.control.TextArea)1 Wallet (org.bitcoinj.wallet.Wallet)1