mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2025-11-05 11:56:37 +00:00
show warning when importing a wallet with a derivation path matching another script type
This commit is contained in:
parent
5c9de07d48
commit
4239a56bc1
4 changed files with 34 additions and 1 deletions
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) {
|
private void addImportedWallet(Wallet wallet) {
|
||||||
|
if(AppServices.disallowAnyInvalidDerivationPaths(wallet)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
WalletNameDialog nameDlg = new WalletNameDialog(wallet.getName(), true, wallet.getBirthDate());
|
WalletNameDialog nameDlg = new WalletNameDialog(wallet.getName(), true, wallet.getBirthDate());
|
||||||
nameDlg.initOwner(rootStack.getScene().getWindow());
|
nameDlg.initOwner(rootStack.getScene().getWindow());
|
||||||
Optional<WalletNameDialog.NameAndBirthDate> optNameAndBirthDate = nameDlg.showAndWait();
|
Optional<WalletNameDialog.NameAndBirthDate> optNameAndBirthDate = nameDlg.showAndWait();
|
||||||
|
|
|
||||||
|
|
@ -1108,6 +1108,31 @@ public class AppServices {
|
||||||
return wallet;
|
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 final List<Network> WHIRLPOOL_NETWORKS = List.of(Network.MAINNET, Network.TESTNET);
|
||||||
|
|
||||||
public static boolean isWhirlpoolCompatible(Wallet wallet) {
|
public static boolean isWhirlpoolCompatible(Wallet wallet) {
|
||||||
|
|
|
||||||
|
|
@ -475,6 +475,10 @@ public class SettingsController extends WalletFormController implements Initiali
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(AppServices.disallowAnyInvalidDerivationPaths(editedWallet)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
boolean rederive = false;
|
boolean rederive = false;
|
||||||
for(Keystore keystore : editedWallet.getKeystores()) {
|
for(Keystore keystore : editedWallet.getKeystores()) {
|
||||||
Optional<Keystore> optExisting = walletForm.getWallet().getKeystores().stream()
|
Optional<Keystore> optExisting = walletForm.getWallet().getKeystores().stream()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue