display a warning if an output descriptor provided in the wallet settings will be modified for use

This commit is contained in:
Craig Raw 2025-08-05 09:28:52 +02:00
parent 64efcf67d3
commit 90c9f9733f
2 changed files with 24 additions and 1 deletions

2
drongo

@ -1 +1 @@
Subproject commit 92c57d276c934d43d981b461479585d0afd1eb3e Subproject commit f5d5e9dc30c2699feba1b7776f9864d1596c9b2d

View file

@ -41,8 +41,11 @@ import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import java.util.regex.Matcher;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.sparrowwallet.drongo.OutputDescriptor.KEY_ORIGIN_PATTERN;
import static com.sparrowwallet.drongo.OutputDescriptor.XPUB_PATTERN;
import static com.sparrowwallet.sparrow.AppServices.showErrorDialog; import static com.sparrowwallet.sparrow.AppServices.showErrorDialog;
import static com.sparrowwallet.sparrow.AppServices.showWarningDialog; import static com.sparrowwallet.sparrow.AppServices.showWarningDialog;
@ -455,6 +458,26 @@ public class SettingsController extends WalletFormController implements Initiali
AppServices.showWarningDialog("Legacy multisig wallet detected", "Sparrow supports BIP67 compatible multisig wallets only.\n\nThe public keys will be lexicographically sorted, and the output descriptor represented with sortedmulti."); AppServices.showWarningDialog("Legacy multisig wallet detected", "Sparrow supports BIP67 compatible multisig wallets only.\n\nThe public keys will be lexicographically sorted, and the output descriptor represented with sortedmulti.");
} }
Matcher matcher = XPUB_PATTERN.matcher(text.get());
while(matcher.find()) {
String keyDerivationPath = null;
if(matcher.group(1) != null) {
Matcher keyOriginMatcher = KEY_ORIGIN_PATTERN.matcher(matcher.group(1));
if(keyOriginMatcher.matches()) {
keyDerivationPath = keyOriginMatcher.group(2);
}
}
String extKey = matcher.group(2);
String childDerivationPath = matcher.group(3);
if(ExtendedKey.Header.getHeaders(Network.get()).stream().anyMatch(header -> header.isPrivateKey() && extKey.startsWith(header.name())) &&
(keyDerivationPath != null || (childDerivationPath != null && !(childDerivationPath.equals("/0/*") || childDerivationPath.equals("/1/*") || childDerivationPath.equals("/<0;1>/*"))))) {
AppServices.showWarningDialog("Private extended key detected", "Sparrow will convert the provided private key to a public key for use in a watch only wallet.\n\nTo import a private key, use the Master Private Key option when creating a Software Wallet.");
} else if(childDerivationPath != null && !(childDerivationPath.endsWith("/0/*") || childDerivationPath.endsWith("/1/*") || childDerivationPath.endsWith("/<0;1>/*"))) {
AppServices.showWarningDialog("Non standard child derivation detected", "Sparrow does not support non-BIP32 wallets without standard receive and change chains.\n\nThe provided descriptor will be amended if necessary.");
}
}
setDescriptorText(text.get().replace("\n", "")); setDescriptorText(text.get().replace("\n", ""));
} }
} }