mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-05 05:46:44 +00:00
add trezor one passphrase toggle capability
This commit is contained in:
parent
08edc04c6d
commit
e524396aaf
2 changed files with 103 additions and 4 deletions
|
@ -325,12 +325,22 @@ public class DevicePane extends TitledDescriptionPane {
|
||||||
passphrase.bind(passphraseField.textProperty());
|
passphrase.bind(passphraseField.textProperty());
|
||||||
HBox.setHgrow(passphraseField, Priority.ALWAYS);
|
HBox.setHgrow(passphraseField, Priority.ALWAYS);
|
||||||
|
|
||||||
Button sendPassphraseButton = new Button("Send Passphrase");
|
SplitMenuButton sendPassphraseButton = new SplitMenuButton();
|
||||||
|
sendPassphraseButton.setText("Send Passphrase");
|
||||||
sendPassphraseButton.setOnAction(event -> {
|
sendPassphraseButton.setOnAction(event -> {
|
||||||
setExpanded(false);
|
setExpanded(false);
|
||||||
|
setDescription("Confirm passphrase on device...");
|
||||||
sendPassphrase(passphrase.get());
|
sendPassphrase(passphrase.get());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
MenuItem removePassphrase = new MenuItem("Toggle Passphrase Off");
|
||||||
|
removePassphrase.setOnAction(event -> {
|
||||||
|
setExpanded(false);
|
||||||
|
setDescription("Toggling passphrase off, check device...");
|
||||||
|
togglePassphraseOff();
|
||||||
|
});
|
||||||
|
sendPassphraseButton.getItems().add(removePassphrase);
|
||||||
|
|
||||||
HBox contentBox = new HBox();
|
HBox contentBox = new HBox();
|
||||||
contentBox.setAlignment(Pos.TOP_RIGHT);
|
contentBox.setAlignment(Pos.TOP_RIGHT);
|
||||||
contentBox.setSpacing(20);
|
contentBox.setSpacing(20);
|
||||||
|
@ -343,6 +353,35 @@ public class DevicePane extends TitledDescriptionPane {
|
||||||
return contentBox;
|
return contentBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Node getTogglePassphraseOn() {
|
||||||
|
CopyableLabel label = new CopyableLabel("Passphrase is currently disabled");
|
||||||
|
HBox.setHgrow(label, Priority.ALWAYS);
|
||||||
|
|
||||||
|
Button togglePassphraseOn = new Button("Toggle Passphrase On");
|
||||||
|
togglePassphraseOn.setOnAction(event -> {
|
||||||
|
setExpanded(false);
|
||||||
|
hideButtons(importButton, signButton, displayAddressButton, signMessageButton);
|
||||||
|
setDescription("Toggling passphrase on, check device...");
|
||||||
|
togglePassphraseOn();
|
||||||
|
});
|
||||||
|
|
||||||
|
HBox contentBox = new HBox();
|
||||||
|
contentBox.setSpacing(20);
|
||||||
|
contentBox.setAlignment(Pos.CENTER_LEFT);
|
||||||
|
contentBox.getChildren().addAll(label, togglePassphraseOn);
|
||||||
|
contentBox.setPadding(new Insets(10, 30, 10, 30));
|
||||||
|
|
||||||
|
return contentBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void hideButtons(Node... buttons) {
|
||||||
|
for(Node button : buttons) {
|
||||||
|
if(button != null) {
|
||||||
|
button.setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void promptPin() {
|
private void promptPin() {
|
||||||
Hwi.PromptPinService promptPinService = new Hwi.PromptPinService(device);
|
Hwi.PromptPinService promptPinService = new Hwi.PromptPinService(device);
|
||||||
promptPinService.setOnSucceeded(workerStateEvent -> {
|
promptPinService.setOnSucceeded(workerStateEvent -> {
|
||||||
|
@ -356,7 +395,7 @@ public class DevicePane extends TitledDescriptionPane {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
promptPinService.setOnFailed(workerStateEvent -> {
|
promptPinService.setOnFailed(workerStateEvent -> {
|
||||||
setError(promptPinService.getException().getMessage(), null);
|
setError("Error", promptPinService.getException().getMessage());
|
||||||
unlockButton.setDisable(false);
|
unlockButton.setDisable(false);
|
||||||
});
|
});
|
||||||
promptPinService.start();
|
promptPinService.start();
|
||||||
|
@ -379,6 +418,7 @@ public class DevicePane extends TitledDescriptionPane {
|
||||||
setExpanded(true);
|
setExpanded(true);
|
||||||
} else {
|
} else {
|
||||||
showOperationButton();
|
showOperationButton();
|
||||||
|
setContent(getTogglePassphraseOn());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setError("Incorrect PIN", null);
|
setError("Incorrect PIN", null);
|
||||||
|
@ -418,13 +458,43 @@ public class DevicePane extends TitledDescriptionPane {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
enumerateService.setOnFailed(workerStateEvent -> {
|
enumerateService.setOnFailed(workerStateEvent -> {
|
||||||
setError(enumerateService.getException().getMessage(), null);
|
setError("Error", enumerateService.getException().getMessage());
|
||||||
setPassphraseButton.setDisable(false);
|
setPassphraseButton.setDisable(false);
|
||||||
setPassphraseButton.setVisible(true);
|
setPassphraseButton.setVisible(true);
|
||||||
});
|
});
|
||||||
enumerateService.start();
|
enumerateService.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void togglePassphraseOff() {
|
||||||
|
Hwi.TogglePassphraseService togglePassphraseService = new Hwi.TogglePassphraseService(device);
|
||||||
|
togglePassphraseService.setOnSucceeded(workerStateEvent -> {
|
||||||
|
device.setNeedsPassphraseSent(false);
|
||||||
|
setPassphraseButton.setVisible(false);
|
||||||
|
setDescription("Unlocked");
|
||||||
|
showOperationButton();
|
||||||
|
});
|
||||||
|
togglePassphraseService.setOnFailed(workerStateEvent -> {
|
||||||
|
setError("Error", togglePassphraseService.getException().getMessage());
|
||||||
|
});
|
||||||
|
togglePassphraseService.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void togglePassphraseOn() {
|
||||||
|
Hwi.TogglePassphraseService togglePassphraseService = new Hwi.TogglePassphraseService(device);
|
||||||
|
togglePassphraseService.setOnSucceeded(workerStateEvent -> {
|
||||||
|
device.setNeedsPassphraseSent(true);
|
||||||
|
setPassphraseButton.setVisible(true);
|
||||||
|
setPassphraseButton.setDisable(true);
|
||||||
|
setDescription("Enter passphrase");
|
||||||
|
setContent(getPassphraseEntry());
|
||||||
|
setExpanded(true);
|
||||||
|
});
|
||||||
|
togglePassphraseService.setOnFailed(workerStateEvent -> {
|
||||||
|
setError("Error", togglePassphraseService.getException().getMessage());
|
||||||
|
});
|
||||||
|
togglePassphraseService.start();
|
||||||
|
}
|
||||||
|
|
||||||
private void importKeystore(List<ChildNumber> derivation) {
|
private void importKeystore(List<ChildNumber> derivation) {
|
||||||
if(device.getFingerprint() == null) {
|
if(device.getFingerprint() == null) {
|
||||||
Hwi.EnumerateService enumerateService = new Hwi.EnumerateService(passphrase.get());
|
Hwi.EnumerateService enumerateService = new Hwi.EnumerateService(passphrase.get());
|
||||||
|
@ -439,7 +509,7 @@ public class DevicePane extends TitledDescriptionPane {
|
||||||
importXpub(derivation);
|
importXpub(derivation);
|
||||||
});
|
});
|
||||||
enumerateService.setOnFailed(workerStateEvent -> {
|
enumerateService.setOnFailed(workerStateEvent -> {
|
||||||
setError(enumerateService.getException().getMessage(), null);
|
setError("Error", enumerateService.getException().getMessage());
|
||||||
importButton.setDisable(false);
|
importButton.setDisable(false);
|
||||||
});
|
});
|
||||||
enumerateService.start();
|
enumerateService.start();
|
||||||
|
|
|
@ -78,6 +78,16 @@ public class Hwi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean togglePassphrase(Device device) throws ImportException {
|
||||||
|
try {
|
||||||
|
String output = execute(getDeviceCommand(device, Command.TOGGLE_PASSPHRASE));
|
||||||
|
isPromptActive = false;
|
||||||
|
return wasSuccessful(output);
|
||||||
|
} catch(IOException e) {
|
||||||
|
throw new ImportException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String getXpub(Device device, String passphrase, String derivationPath) throws ImportException {
|
public String getXpub(Device device, String passphrase, String derivationPath) throws ImportException {
|
||||||
try {
|
try {
|
||||||
String output;
|
String output;
|
||||||
|
@ -468,6 +478,24 @@ public class Hwi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class TogglePassphraseService extends Service<Boolean> {
|
||||||
|
private final Device device;
|
||||||
|
|
||||||
|
public TogglePassphraseService(Device device) {
|
||||||
|
this.device = device;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Task<Boolean> createTask() {
|
||||||
|
return new Task<>() {
|
||||||
|
protected Boolean call() throws ImportException {
|
||||||
|
Hwi hwi = new Hwi();
|
||||||
|
return hwi.togglePassphrase(device);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class DisplayAddressService extends Service<String> {
|
public static class DisplayAddressService extends Service<String> {
|
||||||
private final Device device;
|
private final Device device;
|
||||||
private final String passphrase;
|
private final String passphrase;
|
||||||
|
@ -595,6 +623,7 @@ public class Hwi {
|
||||||
ENUMERATE("enumerate", true),
|
ENUMERATE("enumerate", true),
|
||||||
PROMPT_PIN("promptpin", true),
|
PROMPT_PIN("promptpin", true),
|
||||||
SEND_PIN("sendpin", false),
|
SEND_PIN("sendpin", false),
|
||||||
|
TOGGLE_PASSPHRASE("togglepassphrase", true),
|
||||||
DISPLAY_ADDRESS("displayaddress", true),
|
DISPLAY_ADDRESS("displayaddress", true),
|
||||||
SIGN_MESSAGE("signmessage", true),
|
SIGN_MESSAGE("signmessage", true),
|
||||||
GET_XPUB("getxpub", true),
|
GET_XPUB("getxpub", true),
|
||||||
|
|
Loading…
Reference in a new issue