mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2025-03-17 13:22:40 +01:00
show warning when importing a wallet with a derivation path matching another script type
This commit is contained in:
parent
5c9de07d48
commit
4239a56bc1
2
drongo
2
drongo
@ -1 +1 @@
|
||||
Subproject commit 5fd8e9416a81d71df1b2fe60fdea2f8264335800
|
||||
Subproject commit 66ff275f4641f650dc1cddf28e9b6ba683b16f04
|
@ -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<WalletNameDialog.NameAndBirthDate> optNameAndBirthDate = nameDlg.showAndWait();
|
||||
|
@ -1108,6 +1108,31 @@ public class AppServices {
|
||||
return wallet;
|
||||
}
|
||||
|
||||
public static boolean disallowAnyInvalidDerivationPaths(Wallet wallet) {
|
||||
Optional<ScriptType> 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<ButtonType> 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<Network> WHIRLPOOL_NETWORKS = List.of(Network.MAINNET, Network.TESTNET);
|
||||
|
||||
public static boolean isWhirlpoolCompatible(Wallet wallet) {
|
||||
|
@ -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<Keystore> optExisting = walletForm.getWallet().getKeystores().stream()
|
||||
|
Loading…
x
Reference in New Issue
Block a user