confirm the passphrase in the wallet-level and terminal seed imports

This commit is contained in:
Craig Raw
2026-08-26 11:10:56 +02:00
parent 12d45a8c20
commit d8ea42643a
3 changed files with 40 additions and 2 deletions
@@ -218,6 +218,15 @@ public class MnemonicWalletKeystoreImportPane extends MnemonicKeystorePane {
try {
PolicyAndScriptType type = comboBox.getValue();
Wallet wallet = getWallet(type.policyType(), type.scriptType(), type.scriptType().getDefaultDerivation());
if(passphraseProperty.get() != null && !passphraseProperty.get().isEmpty()) {
KeystorePassphraseDialog keystorePassphraseDialog = new KeystorePassphraseDialog(null, wallet.getKeystores().getFirst(), true);
keystorePassphraseDialog.initOwner(this.getScene().getWindow());
Optional<String> optPassphrase = keystorePassphraseDialog.showAndWait();
if(optPassphrase.isEmpty() || !optPassphrase.get().equals(passphraseProperty.get())) {
throw new ImportException("Re-entered passphrase did not match");
}
}
EventManager.get().post(new WalletImportEvent(wallet));
} catch(ImportException e) {
log.error("Error importing mnemonic", e);
@@ -15,7 +15,11 @@ public class PassphraseDialog extends DialogWindow {
private String result;
public PassphraseDialog(String walletName, Keystore keystore) {
super("Passphrase for " + walletName);
this(walletName, keystore, false);
}
public PassphraseDialog(String walletName, Keystore keystore, boolean confirm) {
super((confirm ? "Confirm Passphrase for " : "Passphrase for ") + walletName);
setHints(Collections.singleton(Window.Hint.CENTERED));
@@ -30,7 +34,7 @@ public class PassphraseDialog extends DialogWindow {
Panel mainPanel = new Panel();
mainPanel.setLayoutManager(new GridLayout(1).setLeftMarginSize(1).setRightMarginSize(1));
mainPanel.addComponent(new Label("Enter the BIP39 passphrase for keystore:\n" + keystore.getLabel()));
mainPanel.addComponent(new Label(confirm ? "Re-enter the BIP39 passphrase\nto confirm:" : "Enter the BIP39 passphrase for keystore:\n" + keystore.getLabel()));
mainPanel.addComponent(new EmptySpace(TerminalSize.ONE));
passphrase.setLayoutData(GridLayout.createLayoutData(GridLayout.Alignment.FILL, GridLayout.Alignment.CENTER, true, false)).addTo(mainPanel);
mainPanel.addComponent(new EmptySpace(TerminalSize.ONE));
@@ -12,6 +12,7 @@ import com.sparrowwallet.drongo.wallet.Keystore;
import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.sparrow.io.Bip39;
import com.sparrowwallet.sparrow.io.ImportException;
import com.sparrowwallet.sparrow.terminal.PassphraseDialog;
import com.sparrowwallet.sparrow.terminal.SparrowTerminal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -23,6 +24,8 @@ import java.util.Arrays;
import java.util.Date;
import java.util.List;
import static com.sparrowwallet.sparrow.AppServices.showErrorDialog;
public class Bip39Dialog extends NewWalletDialog {
private static final Logger log = LoggerFactory.getLogger(Bip39Dialog.class);
public static final int MAX_COLUMNS = 40;
@@ -100,6 +103,28 @@ public class Bip39Dialog extends NewWalletDialog {
});
}
@Override
protected void createWallet() {
if(!passphrase.getText().isEmpty()) {
try {
PolicyAndScriptType type = scriptType.getSelectedItem();
Keystore keystore = importer.getKeystore(type.policyType(), type.scriptType().getDefaultDerivation(), getWords(), passphrase.getText());
PassphraseDialog passphraseDialog = new PassphraseDialog(walletName, keystore, true);
String confirmation = passphraseDialog.showDialog(SparrowTerminal.get().getGui());
if(confirmation == null || !confirmation.equals(passphrase.getText())) {
showErrorDialog("Error Creating Wallet", "Re-entered passphrase did not match.");
return;
}
} catch(ImportException e) {
log.error("Cannot create keystore", e);
showErrorDialog("Error Creating Wallet", e.getMessage());
return;
}
}
super.createWallet();
}
private void generateNew() {
WordNumberDialog wordNumberDialog = new WordNumberDialog();
Integer numberOfWords = wordNumberDialog.showDialog(SparrowTerminal.get().getGui());