mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2026-10-05 19:18:26 +00:00
refuse bitbox02 keystore import and discovery for legacy p2sh and p2pkh wallets it cannot sign for, and hide those script types from the device import menus
This commit is contained in:
+1
-1
Submodule lark updated: a34efcc647...b15a676e59
@@ -309,7 +309,9 @@ public class DevicePane extends TitledDescriptionPane {
|
||||
List<PolicyAndScriptType> types = new ArrayList<>();
|
||||
for(PolicyType policyType : List.of(PolicyType.SINGLE_HD, PolicyType.SINGLE_SP)) {
|
||||
for(ScriptType scriptType : ScriptType.getAddressableScriptTypes(policyType)) {
|
||||
types.add(new PolicyAndScriptType(policyType, scriptType));
|
||||
if(device.supportsScriptType(scriptType)) {
|
||||
types.add(new PolicyAndScriptType(policyType, scriptType));
|
||||
}
|
||||
}
|
||||
}
|
||||
for(PolicyAndScriptType type : types) {
|
||||
@@ -323,7 +325,7 @@ public class DevicePane extends TitledDescriptionPane {
|
||||
importMenuButton.getItems().add(item);
|
||||
}
|
||||
} else {
|
||||
List<ScriptType> scriptTypes = ScriptType.getScriptTypesForPolicyType(wallet.getPolicyType());
|
||||
List<ScriptType> scriptTypes = ScriptType.getScriptTypesForPolicyType(wallet.getPolicyType()).stream().filter(device::supportsScriptType).toList();
|
||||
for(ScriptType scriptType : scriptTypes) {
|
||||
MenuItem item = new MenuItem(scriptType.getDescription());
|
||||
final List<ChildNumber> derivation = scriptType.getDefaultDerivation();
|
||||
@@ -753,6 +755,9 @@ public class DevicePane extends TitledDescriptionPane {
|
||||
setError("Import Error", e.getMessage());
|
||||
importButton.setDisable(false);
|
||||
}
|
||||
} else if(wallet.getScriptType() != null && !device.supportsScriptType(wallet.getScriptType())) {
|
||||
setError("Unsupported script type", "The " + device.getModel().toDisplayString() + " cannot sign for " + wallet.getScriptType().getDescription() + " wallets.");
|
||||
importButton.setDisable(false);
|
||||
} else if(device.getFingerprint() == null) {
|
||||
Hwi.EnumerateService enumerateService = new Hwi.EnumerateService(passphrase.get());
|
||||
enumerateService.setOnSucceeded(workerStateEvent -> {
|
||||
@@ -997,10 +1002,7 @@ public class DevicePane extends TitledDescriptionPane {
|
||||
|
||||
List<StandardAccount> discoveryAccounts = new ArrayList<>(Arrays.asList(StandardAccount.values()).subList(0, optRange.get() + 1));
|
||||
Map<Hwi.WalletType, String> derivationPaths = new LinkedHashMap<>();
|
||||
List<ScriptType> scriptTypes = new ArrayList<>(ScriptType.getAddressableScriptTypes(PolicyType.SINGLE_HD));
|
||||
if(device.getModel() == WalletModel.BITBOX_02) {
|
||||
scriptTypes.remove(ScriptType.P2PKH);
|
||||
}
|
||||
List<ScriptType> scriptTypes = ScriptType.getAddressableScriptTypes(PolicyType.SINGLE_HD).stream().filter(device::supportsScriptType).toList();
|
||||
for(ScriptType scriptType : scriptTypes) {
|
||||
for(StandardAccount discoveryAccount : discoveryAccounts) {
|
||||
derivationPaths.put(new Hwi.WalletType(scriptType, discoveryAccount), KeyDerivation.writePath(scriptType.getDefaultDerivation(discoveryAccount.getAccountNumber())));
|
||||
@@ -1083,6 +1085,11 @@ public class DevicePane extends TitledDescriptionPane {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!device.supportsScriptType(wallet.getScriptType())) {
|
||||
setError("Unsupported script type", "The " + device.getModel().toDisplayString() + " cannot sign for " + wallet.getScriptType().getDescription() + " wallets.");
|
||||
return;
|
||||
}
|
||||
|
||||
discoverKeystoresButton.setDisable(true);
|
||||
discoverKeystoresButton.setMaxHeight(discoverKeystoresButton.getHeight());
|
||||
ProgressIndicator progressIndicator = new ProgressIndicator(0);
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.sparrowwallet.sparrow.io;
|
||||
|
||||
import com.sparrowwallet.drongo.protocol.ScriptType;
|
||||
import com.sparrowwallet.drongo.wallet.WalletModel;
|
||||
import com.sparrowwallet.lark.HardwareClient;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Device {
|
||||
@@ -15,6 +18,7 @@ public class Device {
|
||||
private boolean card;
|
||||
private String[][] warnings;
|
||||
private String error;
|
||||
private List<ScriptType> supportedScriptTypes;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
@@ -94,6 +98,10 @@ public class Device {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean supportsScriptType(ScriptType scriptType) {
|
||||
return supportedScriptTypes == null || supportedScriptTypes.contains(scriptType);
|
||||
}
|
||||
|
||||
public String getError() {
|
||||
return error;
|
||||
}
|
||||
@@ -135,6 +143,7 @@ public class Device {
|
||||
device.card = hardwareClient.card();
|
||||
device.warnings = hardwareClient.warnings();
|
||||
device.error = hardwareClient.error();
|
||||
device.supportedScriptTypes = Arrays.stream(ScriptType.values()).filter(hardwareClient::supportsScriptType).toList();
|
||||
return device;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user