diff --git a/drongo b/drongo index 5fd8e941..66ff275f 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit 5fd8e9416a81d71df1b2fe60fdea2f8264335800 +Subproject commit 66ff275f4641f650dc1cddf28e9b6ba683b16f04 diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index 951f1eae..552a5b16 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -1252,6 +1252,10 @@ public class AppController implements Initializable { } private void addImportedWallet(Wallet wallet) { + if(AppServices.disallowAnyInvalidDerivationPaths(wallet)) { + return; + } + WalletNameDialog nameDlg = new WalletNameDialog(wallet.getName(), true, wallet.getBirthDate()); nameDlg.initOwner(rootStack.getScene().getWindow()); Optional optNameAndBirthDate = nameDlg.showAndWait(); diff --git a/src/main/java/com/sparrowwallet/sparrow/AppServices.java b/src/main/java/com/sparrowwallet/sparrow/AppServices.java index ea719b55..04cf8d08 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppServices.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppServices.java @@ -1108,6 +1108,31 @@ public class AppServices { return wallet; } + public static boolean disallowAnyInvalidDerivationPaths(Wallet wallet) { + Optional optInvalidScriptType = wallet.getKeystores().stream() + .filter(keystore -> keystore.getKeyDerivation() != null) + .map(keystore -> wallet.getOtherScriptTypeMatchingDerivation(keystore.getKeyDerivation().getDerivationPath())) + .filter(Optional::isPresent).map(Optional::get).findFirst(); + if(optInvalidScriptType.isPresent()) { + ScriptType invalidScriptType = optInvalidScriptType.get(); + boolean includePolicyType = !wallet.getScriptType().getAllowedPolicyTypes().getFirst().equals(invalidScriptType.getAllowedPolicyTypes().getFirst()); + Optional optType = AppServices.showWarningDialog("Invalid derivation path", "This wallet is using the derivation path for " + + invalidScriptType.getDescription(includePolicyType) + ", instead of the derivation path for its defined script type of " + wallet.getScriptType().getDescription(includePolicyType) + + ". \n\nDisable derivation path validation to import this wallet?", ButtonType.NO, ButtonType.YES); + if(optType.isPresent()) { + if(optType.get() == ButtonType.YES) { + Config.get().setValidateDerivationPaths(false); + System.setProperty(Wallet.ALLOW_DERIVATIONS_MATCHING_OTHER_SCRIPT_TYPES_PROPERTY, Boolean.toString(true)); + System.setProperty(Wallet.ALLOW_DERIVATIONS_MATCHING_OTHER_NETWORKS_PROPERTY, Boolean.toString(true)); + } else { + return true; + } + } + } + + return false; + } + public static final List WHIRLPOOL_NETWORKS = List.of(Network.MAINNET, Network.TESTNET); public static boolean isWhirlpoolCompatible(Wallet wallet) { diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java index 0525f148..494d21ae 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java @@ -475,6 +475,10 @@ public class SettingsController extends WalletFormController implements Initiali return; } + if(AppServices.disallowAnyInvalidDerivationPaths(editedWallet)) { + return; + } + boolean rederive = false; for(Keystore keystore : editedWallet.getKeystores()) { Optional optExisting = walletForm.getWallet().getKeystores().stream()