mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2025-11-05 11:56:37 +00:00
Satochip: remove debug logs, trailing whitespaces & clean code
This commit is contained in:
parent
cbcb40c973
commit
6f028d720b
13 changed files with 531 additions and 598 deletions
|
|
@ -1074,13 +1074,6 @@ public class DevicePane extends TitledDescriptionPane {
|
||||||
initializeButton.setDefaultButton(true);
|
initializeButton.setDefaultButton(true);
|
||||||
initializeButton.setOnAction(event -> {
|
initializeButton.setOnAction(event -> {
|
||||||
initializeButton.setDisable(true);
|
initializeButton.setDisable(true);
|
||||||
/*
|
|
||||||
log.trace("SATOCHIP DevicePane getCardInitializationPanel() pin.get(): " + pin.get());
|
|
||||||
log.trace("SATOCHIP DevicePane getCardInitializationPanel() repeatedPin.getText(): " + repeatedPin.getText());
|
|
||||||
log.trace("SATOCHIP DevicePane getCardInitializationPanel() mnemonic.getText(): "+ mnemonic.getText());
|
|
||||||
log.trace("SATOCHIP DevicePane getCardInitializationPanel() passphrase.getText(): "+ passphrase.getText());
|
|
||||||
*/
|
|
||||||
|
|
||||||
byte[] seedBytes;
|
byte[] seedBytes;
|
||||||
// check that pin and previous pin match
|
// check that pin and previous pin match
|
||||||
if ( !pin.get().equals(repeatedPin.getText()) ){
|
if ( !pin.get().equals(repeatedPin.getText()) ){
|
||||||
|
|
@ -1098,7 +1091,6 @@ public class DevicePane extends TitledDescriptionPane {
|
||||||
messageProperty.set("Failed to parse the seed with error: " + e);
|
messageProperty.set("Failed to parse the seed with error: " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Service<Void> cardInitializationService = cardApi.getInitializationService(seedBytes, messageProperty);
|
Service<Void> cardInitializationService = cardApi.getInitializationService(seedBytes, messageProperty);
|
||||||
cardInitializationService.setOnSucceeded(successEvent -> {
|
cardInitializationService.setOnSucceeded(successEvent -> {
|
||||||
log.debug("SATOCHIP DevicePane getCardInitializationPanel() Card initialized!");
|
log.debug("SATOCHIP DevicePane getCardInitializationPanel() Card initialized!");
|
||||||
|
|
@ -1112,17 +1104,9 @@ public class DevicePane extends TitledDescriptionPane {
|
||||||
setExpanded(false);
|
setExpanded(false);
|
||||||
});
|
});
|
||||||
cardInitializationService.setOnFailed(failEvent -> {
|
cardInitializationService.setOnFailed(failEvent -> {
|
||||||
log.error("SATOCHIP DevicePane getCardInitializationPanel() failed to initialize card!");
|
log.error("Error initializing card", failEvent.getSource().getException());
|
||||||
/*Throwable rootCause = Throwables.getRootCause(failEvent.getSource().getException());
|
AppServices.showErrorDialog("Card Initialization Failed", "The card was not initialized.\n\n" + failEvent.getSource().getException().getMessage());
|
||||||
if(rootCause instanceof CardAuthorizationException) {
|
initializeButton.setDisable(false);
|
||||||
setError(rootCause.getMessage(), null);
|
|
||||||
setContent(getCardPinEntry(operationButton));
|
|
||||||
operationButton.setDisable(false);
|
|
||||||
} else {*/
|
|
||||||
log.error("Error initializing card", failEvent.getSource().getException());
|
|
||||||
AppServices.showErrorDialog("Card Initialization Failed", "The card was not initialized.\n\n" + failEvent.getSource().getException().getMessage());
|
|
||||||
initializeButton.setDisable(false);
|
|
||||||
//}
|
|
||||||
});
|
});
|
||||||
cardInitializationService.start();
|
cardInitializationService.start();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -6,97 +6,97 @@ import java.util.StringTokenizer;
|
||||||
* Keypath object to be used with the SatochipCommandSet
|
* Keypath object to be used with the SatochipCommandSet
|
||||||
*/
|
*/
|
||||||
public class KeyPath {
|
public class KeyPath {
|
||||||
private byte[] data;
|
private byte[] data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a keypath into a byte array to be used with the SatochipCommandSet object.
|
* Parses a keypath into a byte array to be used with the SatochipCommandSet object.
|
||||||
*
|
*
|
||||||
* A valid string is composed of a minimum of one and a maximum of 11 components separated by "/".
|
* A valid string is composed of a minimum of one and a maximum of 11 components separated by "/".
|
||||||
*
|
*
|
||||||
* The first component should be "m", indicating the master key.
|
* The first component should be "m", indicating the master key.
|
||||||
*
|
*
|
||||||
* All other components are positive integers fitting in 31 bit, eventually suffixed by an apostrophe (') sign,
|
* All other components are positive integers fitting in 31 bit, eventually suffixed by an apostrophe (') sign,
|
||||||
* which indicates an hardened key.
|
* which indicates an hardened key.
|
||||||
*
|
*
|
||||||
* An example of a valid path is "m/44'/0'/0'/0/0"
|
* An example of a valid path is "m/44'/0'/0'/0/0"
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param keypath the keypath as a string
|
* @param keypath the keypath as a string
|
||||||
*/
|
*/
|
||||||
public KeyPath(String keypath) {
|
public KeyPath(String keypath) {
|
||||||
StringTokenizer tokenizer = new StringTokenizer(keypath, "/");
|
StringTokenizer tokenizer = new StringTokenizer(keypath, "/");
|
||||||
|
|
||||||
String sourceOrFirstElement = tokenizer.nextToken(); // m
|
String sourceOrFirstElement = tokenizer.nextToken(); // m
|
||||||
|
|
||||||
int componentCount = tokenizer.countTokens();
|
int componentCount = tokenizer.countTokens();
|
||||||
if (componentCount > 10) {
|
if (componentCount > 10) {
|
||||||
throw new IllegalArgumentException("Too many components");
|
throw new IllegalArgumentException("Too many components");
|
||||||
|
}
|
||||||
|
|
||||||
|
data = new byte[4 * componentCount];
|
||||||
|
|
||||||
|
for (int i = 0; i < componentCount; i++) {
|
||||||
|
long component = parseComponent(tokenizer.nextToken());
|
||||||
|
writeComponent(component, i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data = new byte[4 * componentCount];
|
public KeyPath(byte[] data) {
|
||||||
|
this.data = data;
|
||||||
for (int i = 0; i < componentCount; i++) {
|
|
||||||
long component = parseComponent(tokenizer.nextToken());
|
|
||||||
writeComponent(component, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public KeyPath(byte[] data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
private long parseComponent(String num) {
|
|
||||||
long sign;
|
|
||||||
|
|
||||||
if (num.endsWith("'")) {
|
|
||||||
sign = 0x80000000L;
|
|
||||||
num = num.substring(0, (num.length() - 1));
|
|
||||||
} else {
|
|
||||||
sign = 0L;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num.startsWith("+") || num.startsWith("-")) {
|
private long parseComponent(String num) {
|
||||||
throw new NumberFormatException("No sign allowed");
|
long sign;
|
||||||
}
|
|
||||||
return (sign | Long.parseLong(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeComponent(long component, int i) {
|
if (num.endsWith("'")) {
|
||||||
int off = (i*4);
|
sign = 0x80000000L;
|
||||||
data[off] = (byte)((component >> 24) & 0xff);
|
num = num.substring(0, (num.length() - 1));
|
||||||
data[off + 1] = (byte)((component >> 16) & 0xff);
|
} else {
|
||||||
data[off + 2] = (byte)((component >> 8) & 0xff);
|
sign = 0L;
|
||||||
data[off + 3] = (byte)(component & 0xff);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
if (num.startsWith("+") || num.startsWith("-")) {
|
||||||
* The byte encoded key path.
|
throw new NumberFormatException("No sign allowed");
|
||||||
*
|
}
|
||||||
* @return byte encoded key path
|
return (sign | Long.parseLong(num));
|
||||||
*/
|
|
||||||
public byte[] getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
sb.append('m');
|
|
||||||
|
|
||||||
for (int i = 0; i < this.data.length; i += 4) {
|
|
||||||
sb.append('/');
|
|
||||||
appendComponent(sb, i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.toString();
|
private void writeComponent(long component, int i) {
|
||||||
}
|
int off = (i*4);
|
||||||
|
data[off] = (byte)((component >> 24) & 0xff);
|
||||||
private void appendComponent(StringBuffer sb, int i) {
|
data[off + 1] = (byte)((component >> 16) & 0xff);
|
||||||
int num = ((this.data[i] & 0x7f) << 24) | ((this.data[i+1] & 0xff) << 16) | ((this.data[i+2] & 0xff) << 8) | (this.data[i+3] & 0xff);
|
data[off + 2] = (byte)((component >> 8) & 0xff);
|
||||||
sb.append(num);
|
data[off + 3] = (byte)(component & 0xff);
|
||||||
|
}
|
||||||
if ((this.data[i] & 0x80) == 0x80) {
|
|
||||||
sb.append('\'');
|
/**
|
||||||
|
* The byte encoded key path.
|
||||||
|
*
|
||||||
|
* @return byte encoded key path
|
||||||
|
*/
|
||||||
|
public byte[] getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
sb.append('m');
|
||||||
|
|
||||||
|
for (int i = 0; i < this.data.length; i += 4) {
|
||||||
|
sb.append('/');
|
||||||
|
appendComponent(sb, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendComponent(StringBuffer sb, int i) {
|
||||||
|
int num = ((this.data[i] & 0x7f) << 24) | ((this.data[i+1] & 0xff) << 16) | ((this.data[i+2] & 0xff) << 8) | (this.data[i+3] & 0xff);
|
||||||
|
sb.append(num);
|
||||||
|
|
||||||
|
if ((this.data[i] & 0x80) == 0x80) {
|
||||||
|
sb.append('\'');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -207,35 +207,6 @@ public class SatoCardApi extends CardApi {
|
||||||
log.debug("SATOCHIP SatoCardApi sign() wallet: " + wallet);
|
log.debug("SATOCHIP SatoCardApi sign() wallet: " + wallet);
|
||||||
log.debug("SATOCHIP SatoCardApi sign() psbt: " + psbt);
|
log.debug("SATOCHIP SatoCardApi sign() psbt: " + psbt);
|
||||||
|
|
||||||
// debug psbt
|
|
||||||
/*log.debug("SATOCHIP SatoCardApi sign() psbt.hasSignatures(): " + psbt.hasSignatures());
|
|
||||||
log.debug("SATOCHIP SatoCardApi sign() psbt.isSigned(): " + psbt.isSigned());
|
|
||||||
log.debug("SATOCHIP SatoCardApi sign() psbt.isFinalized(): " + psbt.isFinalized());
|
|
||||||
log.debug("SATOCHIP SatoCardApi sign() psbt.verifySignatures:");*/
|
|
||||||
/*try{
|
|
||||||
psbt.verifySignatures();
|
|
||||||
log.debug("SATOCHIP SatoCardApi sign() psbt signature verified!");
|
|
||||||
} catch(Exception e) {
|
|
||||||
log.debug("SATOCHIP SatoCardApi sign() failed to verify signatures with error: " + e);
|
|
||||||
}
|
|
||||||
log.debug("SATOCHIP SatoCardApi sign() psbt.parse(false):");
|
|
||||||
try{
|
|
||||||
psbt.parse(false);
|
|
||||||
log.debug("SATOCHIP SatoCardApi sign() psbt.parse(false) finished!");
|
|
||||||
} catch(Exception e) {
|
|
||||||
log.debug("SATOCHIP SatoCardApi sign() failed psbt.parse(false) with error: " + e);
|
|
||||||
}
|
|
||||||
log.debug("SATOCHIP SatoCardApi sign() psbt.parse(false) end:");
|
|
||||||
log.debug("SATOCHIP SatoCardApi sign() psbt.parse(true):");
|
|
||||||
try{
|
|
||||||
psbt.parse(true);
|
|
||||||
log.debug("SATOCHIP SatoCardApi sign() psbt.parse(true) finished!");
|
|
||||||
} catch(Exception e) {
|
|
||||||
log.debug("SATOCHIP SatoCardApi sign() failed psbt.parse(true) with error: " + e);
|
|
||||||
}
|
|
||||||
log.debug("SATOCHIP SatoCardApi sign() psbt.parse(true) end:");*/
|
|
||||||
// endbug psbt
|
|
||||||
|
|
||||||
Map<PSBTInput, WalletNode> signingNodes = wallet.getSigningNodes(psbt);
|
Map<PSBTInput, WalletNode> signingNodes = wallet.getSigningNodes(psbt);
|
||||||
//log.debug("SATOCHIP SatoCardApi sign() signingNodes: " + signingNodes);
|
//log.debug("SATOCHIP SatoCardApi sign() signingNodes: " + signingNodes);
|
||||||
for(PSBTInput psbtInput : psbt.getPsbtInputs()) {
|
for(PSBTInput psbtInput : psbt.getPsbtInputs()) {
|
||||||
|
|
@ -244,19 +215,6 @@ public class SatoCardApi extends CardApi {
|
||||||
log.debug("SATOCHIP SatoCardApi sign() signingNode: " + signingNode);
|
log.debug("SATOCHIP SatoCardApi sign() signingNode: " + signingNode);
|
||||||
log.debug("SATOCHIP SatoCardApi sign() signingNode.getDerivationPath(): " + signingNode.getDerivationPath()); // m/0/0
|
log.debug("SATOCHIP SatoCardApi sign() signingNode.getDerivationPath(): " + signingNode.getDerivationPath()); // m/0/0
|
||||||
try {
|
try {
|
||||||
/*// debug
|
|
||||||
Map<ECKey, KeyDerivation> mapPubKey = psbtInput.getDerivedPublicKeys();
|
|
||||||
log.debug("SATOCHIP SatoCardApi sign() mapPubKey.size(): " + mapPubKey.size());
|
|
||||||
log.debug("SATOCHIP SatoCardApi sign() mapPubKey: " + mapPubKey);
|
|
||||||
for (Map.Entry<ECKey, KeyDerivation> entry : mapPubKey.entrySet()) {
|
|
||||||
ECKey key = entry.getKey();
|
|
||||||
KeyDerivation value = entry.getValue();
|
|
||||||
log.debug("SATOCHIP SatoCardApi sign() mapPubKey pubkey: " + Utils.bytesToHex(key.getPubKey()));
|
|
||||||
log.debug("SATOCHIP SatoCardApi sign() mapPubKey derivation: " + value.getDerivationPath());
|
|
||||||
}
|
|
||||||
log.debug("SATOCHIP SatoCardApi sign() mapPubKey END");
|
|
||||||
// endbug*/
|
|
||||||
|
|
||||||
String fullPath= null;
|
String fullPath= null;
|
||||||
List<Keystore> keystores = wallet.getKeystores();
|
List<Keystore> keystores = wallet.getKeystores();
|
||||||
log.debug("SATOCHIP SatoCardApi sign() keystores.size(): " + keystores.size());
|
log.debug("SATOCHIP SatoCardApi sign() keystores.size(): " + keystores.size());
|
||||||
|
|
@ -282,17 +240,13 @@ public class SatoCardApi extends CardApi {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//psbtInput.printDebugInfo();
|
|
||||||
psbtInput.sign(new CardPSBTInputSigner(signingNode, fullPath));
|
psbtInput.sign(new CardPSBTInputSigner(signingNode, fullPath));
|
||||||
//psbtInput.printDebugInfo();
|
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
}
|
}
|
||||||
}// endif
|
}// endif
|
||||||
else {
|
else {
|
||||||
log.debug("SATOCHIP SatoCardApi sign() psbtInput already signed!");
|
log.debug("SATOCHIP SatoCardApi sign() psbtInput already signed!");
|
||||||
//psbtInput.printDebugInfo();
|
|
||||||
}
|
}
|
||||||
} // endfor
|
} // endfor
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ public class HwAirgappedController extends KeystoreImportDetailController {
|
||||||
private Accordion importAccordion;
|
private Accordion importAccordion;
|
||||||
|
|
||||||
public void initializeView() {
|
public void initializeView() {
|
||||||
log.debug("SATOCHIP HwAirgappedController START");
|
|
||||||
List<KeystoreFileImport> fileImporters = Collections.emptyList();
|
List<KeystoreFileImport> fileImporters = Collections.emptyList();
|
||||||
if(getMasterController().getWallet().getPolicyType().equals(PolicyType.SINGLE)) {
|
if(getMasterController().getWallet().getPolicyType().equals(PolicyType.SINGLE)) {
|
||||||
fileImporters = List.of(new ColdcardSinglesig(), new CoboVaultSinglesig(), new Jade(), new KeystoneSinglesig(), new PassportSinglesig(), new SeedSigner(), new GordianSeedTool(), new SpecterDIY());
|
fileImporters = List.of(new ColdcardSinglesig(), new CoboVaultSinglesig(), new Jade(), new KeystoneSinglesig(), new PassportSinglesig(), new SeedSigner(), new GordianSeedTool(), new SpecterDIY());
|
||||||
|
|
@ -40,7 +39,6 @@ public class HwAirgappedController extends KeystoreImportDetailController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("SATOCHIP HwAirgappedController initializeView() - BEFORE cardImporters");
|
|
||||||
List<KeystoreCardImport> cardImporters = List.of(new Tapsigner(), new Satochip());
|
List<KeystoreCardImport> cardImporters = List.of(new Tapsigner(), new Satochip());
|
||||||
for(KeystoreCardImport importer : cardImporters) {
|
for(KeystoreCardImport importer : cardImporters) {
|
||||||
if(!importer.isDeprecated() || Config.get().isShowDeprecatedImportExport()) {
|
if(!importer.isDeprecated() || Config.get().isShowDeprecatedImportExport()) {
|
||||||
|
|
@ -50,7 +48,6 @@ public class HwAirgappedController extends KeystoreImportDetailController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.debug("SATOCHIP HwAirgappedController initializeView() - AFTER cardImporters");
|
|
||||||
|
|
||||||
importAccordion.getPanes().sort(Comparator.comparing(o -> ((TitledDescriptionPane) o).getTitle()));
|
importAccordion.getPanes().sort(Comparator.comparing(o -> ((TitledDescriptionPane) o).getTitle()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,7 @@ public class HwUsbDevicesController extends KeystoreImportDetailController {
|
||||||
private Accordion deviceAccordion;
|
private Accordion deviceAccordion;
|
||||||
|
|
||||||
public void initializeView(List<Device> devices) {
|
public void initializeView(List<Device> devices) {
|
||||||
//log.debug("SATOCHIP HwUsbDevicesController initializeView START");
|
|
||||||
for(Device device : devices) {
|
for(Device device : devices) {
|
||||||
//log.debug("SATOCHIP HwUsbDevicesController initializeView device: " + device);
|
|
||||||
DevicePane devicePane = new DevicePane(getMasterController().getWallet(), device, devices.size() == 1, getMasterController().getRequiredDerivation());
|
DevicePane devicePane = new DevicePane(getMasterController().getWallet(), device, devices.size() == 1, getMasterController().getRequiredDerivation());
|
||||||
if(getMasterController().getRequiredModel() == null || getMasterController().getRequiredModel() == device.getModel()) {
|
if(getMasterController().getRequiredModel() == null || getMasterController().getRequiredModel() == device.getModel()) {
|
||||||
deviceAccordion.getPanes().add(devicePane);
|
deviceAccordion.getPanes().add(devicePane);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue