diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Device.java b/src/main/java/com/sparrowwallet/sparrow/io/Device.java index f417a372..3cb35bae 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Device.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Device.java @@ -11,6 +11,7 @@ public class Device { private Boolean needsPinSent; private Boolean needsPassphraseSent; private String fingerprint; + private String[][] warnings; private String error; public String getType() { @@ -69,6 +70,20 @@ public class Device { this.fingerprint = fingerprint; } + public boolean containsWarning(String warning) { + if(warnings != null) { + for(String[] warns : warnings) { + for(String warn : warns) { + if(warn.contains(warning)) { + return true; + } + } + } + } + + return false; + } + public String getError() { return error; } diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java b/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java index 06200714..99ffff16 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java @@ -34,7 +34,7 @@ public class Hwi { private static final Logger log = LoggerFactory.getLogger(Hwi.class); private static final String HWI_HOME_DIR = "hwi"; private static final String HWI_VERSION_PREFIX = "hwi-"; - private static final String HWI_VERSION = "2.1.1"; + private static final String HWI_VERSION = "2.2.0"; private static final String HWI_VERSION_DIR = HWI_VERSION_PREFIX + HWI_VERSION; private static boolean isPromptActive = false; @@ -43,18 +43,26 @@ public class Hwi { String output = null; try { List command; - if(passphrase != null && !passphrase.isEmpty()) { - command = List.of(getHwiExecutable(Command.ENUMERATE).getAbsolutePath(), "--password", escape(passphrase), Command.ENUMERATE.toString()); + if(passphrase != null) { + command = new ArrayList<>(List.of(getHwiExecutable(Command.ENUMERATE).getAbsolutePath(), "--password", escape(passphrase), Command.ENUMERATE.toString())); } else { - command = List.of(getHwiExecutable(Command.ENUMERATE).getAbsolutePath(), Command.ENUMERATE.toString()); + command = new ArrayList<>(List.of(getHwiExecutable(Command.ENUMERATE).getAbsolutePath(), Command.ENUMERATE.toString())); } + addChainType(command, true); + isPromptActive = true; output = execute(command); Device[] devices = getGson().fromJson(output, Device[].class); if(devices == null) { throw new ImportException("Error scanning, check devices are ready"); } + //Restore previous (pre v2.2.0) behaviour for Trezor One - don't default to an empty passphrase if one is not supplied + Arrays.stream(devices).filter(device -> device.containsWarning("Using default passphrase of the empty string")).forEach(device -> { + device.setFingerprint(null); + device.setNeedsPassphraseSent(true); + device.setError("Passphrase needs to be specified before the fingerprint information can be retrieved"); + }); return Arrays.stream(devices).filter(device -> device != null && device.getModel() != null).collect(Collectors.toList()); } catch(IOException e) { log.error("Error executing " + HWI_VERSION_DIR, e); @@ -67,7 +75,7 @@ public class Hwi { throw new ImportException(error.getAsString()); } catch(Exception ex) { log.error("Error parsing JSON: " + output, e); - throw new ImportException("Error parsing JSON: " + output, e); + throw new ImportException("Error scanning" + (output.isEmpty() ? ", check devices are ready" : ": " + output), e); } } throw e; @@ -118,7 +126,7 @@ public class Hwi { public String getXpub(Device device, String passphrase, String derivationPath) throws ImportException { try { String output; - if(passphrase != null && !passphrase.isEmpty() && device.getModel().externalPassphraseEntry()) { + if(passphrase != null && device.getModel().externalPassphraseEntry()) { output = execute(getDeviceCommand(device, passphrase, Command.GET_XPUB, derivationPath)); } else { output = execute(getDeviceCommand(device, Command.GET_XPUB, derivationPath)); @@ -151,7 +159,7 @@ public class Hwi { isPromptActive = true; String output; - if(passphrase != null && !passphrase.isEmpty() && device.getModel().externalPassphraseEntry()) { + if(passphrase != null && device.getModel().externalPassphraseEntry()) { output = execute(getDeviceCommand(device, passphrase, Command.DISPLAY_ADDRESS, "--desc", descriptor)); } else { output = execute(getDeviceCommand(device, Command.DISPLAY_ADDRESS, "--desc", descriptor)); @@ -179,7 +187,7 @@ public class Hwi { try { isPromptActive = true; String output; - if(passphrase != null && !passphrase.isEmpty() && device.getModel().externalPassphraseEntry()) { + if(passphrase != null && device.getModel().externalPassphraseEntry()) { output = execute(getDeviceArguments(device, passphrase, Command.SIGN_MESSAGE), Command.SIGN_MESSAGE, message, derivationPath); } else { output = execute(getDeviceArguments(device, Command.SIGN_MESSAGE), Command.SIGN_MESSAGE, message, derivationPath); @@ -209,7 +217,7 @@ public class Hwi { isPromptActive = true; String output; - if(passphrase != null && !passphrase.isEmpty() && device.getModel().externalPassphraseEntry()) { + if(passphrase != null && device.getModel().externalPassphraseEntry()) { output = execute(getDeviceArguments(device, passphrase, Command.SIGN_TX), Command.SIGN_TX, psbtBase64); } else { output = execute(getDeviceArguments(device, Command.SIGN_TX), Command.SIGN_TX, psbtBase64); diff --git a/src/main/resources/native/linux/aarch64/hwi b/src/main/resources/native/linux/aarch64/hwi index 0a191861..1d36aa2d 100755 Binary files a/src/main/resources/native/linux/aarch64/hwi and b/src/main/resources/native/linux/aarch64/hwi differ diff --git a/src/main/resources/native/linux/x64/hwi b/src/main/resources/native/linux/x64/hwi index bdb0d158..169b8579 100755 Binary files a/src/main/resources/native/linux/x64/hwi and b/src/main/resources/native/linux/x64/hwi differ diff --git a/src/main/resources/native/osx/aarch64/hwi-2.1.1-mac-aarch64-signed.zip b/src/main/resources/native/osx/aarch64/hwi-2.2.0-mac-aarch64-signed.zip similarity index 54% rename from src/main/resources/native/osx/aarch64/hwi-2.1.1-mac-aarch64-signed.zip rename to src/main/resources/native/osx/aarch64/hwi-2.2.0-mac-aarch64-signed.zip index 70df65d2..a738d00d 100644 Binary files a/src/main/resources/native/osx/aarch64/hwi-2.1.1-mac-aarch64-signed.zip and b/src/main/resources/native/osx/aarch64/hwi-2.2.0-mac-aarch64-signed.zip differ diff --git a/src/main/resources/native/osx/x64/hwi-2.1.1-mac-amd64-signed.zip b/src/main/resources/native/osx/x64/hwi-2.2.0-mac-amd64-signed.zip old mode 100755 new mode 100644 similarity index 64% rename from src/main/resources/native/osx/x64/hwi-2.1.1-mac-amd64-signed.zip rename to src/main/resources/native/osx/x64/hwi-2.2.0-mac-amd64-signed.zip index 61a03b21..8f2fcc50 Binary files a/src/main/resources/native/osx/x64/hwi-2.1.1-mac-amd64-signed.zip and b/src/main/resources/native/osx/x64/hwi-2.2.0-mac-amd64-signed.zip differ diff --git a/src/main/resources/native/windows/x64/hwi.exe b/src/main/resources/native/windows/x64/hwi.exe index 37625fd1..7e793b64 100755 Binary files a/src/main/resources/native/windows/x64/hwi.exe and b/src/main/resources/native/windows/x64/hwi.exe differ