diff --git a/drongo b/drongo index 92c57d27..f5d5e9dc 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit 92c57d276c934d43d981b461479585d0afd1eb3e +Subproject commit f5d5e9dc30c2699feba1b7776f9864d1596c9b2d diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java index 494d21ae..adc9713b 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java @@ -41,8 +41,11 @@ import java.io.IOException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.*; +import java.util.regex.Matcher; 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.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."); } + 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", "")); } }