diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Descriptor.java b/src/main/java/com/sparrowwallet/sparrow/io/Descriptor.java index 44a25fb5..ee43e0b8 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Descriptor.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Descriptor.java @@ -66,13 +66,18 @@ public class Descriptor implements WalletImport, WalletExport { @Override public Wallet importWallet(InputStream inputStream, String password) throws ImportException { try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + inputStream.transferTo(baos); + InputStream firstClone = new ByteArrayInputStream(baos.toByteArray()); + InputStream secondClone = new ByteArrayInputStream(baos.toByteArray()); + try { - return PdfUtils.getOutputDescriptor(inputStream).toWallet(); + return PdfUtils.getOutputDescriptor(firstClone).toWallet(); } catch(Exception e) { //ignore } - String outputDescriptor = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n")); + String outputDescriptor = new BufferedReader(new InputStreamReader(secondClone, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n")); OutputDescriptor descriptor = OutputDescriptor.getOutputDescriptor(outputDescriptor.trim()); return descriptor.toWallet(); } catch(Exception e) { diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java index 46e0e4b3..8f10c36f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java @@ -404,6 +404,10 @@ public class SettingsController extends WalletFormController implements Initiali (walletForm.getWallet().getPolicyType() == PolicyType.MULTI ? "\nKey expressions are shown in canonical order." : "")); Optional text = dialog.showAndWait(); if(text.isPresent() && !text.get().isEmpty() && !text.get().equals(outputDescriptorString)) { + if(text.get().contains("(multi(")) { + 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."); + } + setDescriptorText(text.get().replace("\n", "")); } }