From f590794589bdae1ec8ae3ca106b7bfc6ea9b97b9 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 21 Nov 2023 10:06:32 +0200 Subject: [PATCH] add qr display (with save to pdf) to output descriptor wallet export options --- .../sparrow/control/FileWalletExportPane.java | 9 +++++++++ .../java/com/sparrowwallet/sparrow/io/Descriptor.java | 2 +- .../sparrowwallet/sparrow/wallet/SettingsController.java | 8 ++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/control/FileWalletExportPane.java b/src/main/java/com/sparrowwallet/sparrow/control/FileWalletExportPane.java index 7085f5f6..8474b400 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/FileWalletExportPane.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/FileWalletExportPane.java @@ -1,7 +1,10 @@ package com.sparrowwallet.sparrow.control; +import com.sparrowwallet.drongo.KeyPurpose; +import com.sparrowwallet.drongo.OutputDescriptor; import com.sparrowwallet.drongo.SecureString; import com.sparrowwallet.drongo.wallet.Wallet; +import com.sparrowwallet.hummingbird.registry.CryptoOutput; import com.sparrowwallet.hummingbird.registry.RegistryType; import com.sparrowwallet.sparrow.AppServices; import com.sparrowwallet.sparrow.EventManager; @@ -26,6 +29,8 @@ import java.nio.charset.StandardCharsets; import java.util.Locale; import java.util.Optional; +import static com.sparrowwallet.sparrow.wallet.SettingsController.getCryptoOutput; + public class FileWalletExportPane extends TitledDescriptionPane { private final Wallet wallet; private final WalletExport exporter; @@ -164,6 +169,10 @@ public class FileWalletExportPane extends TitledDescriptionPane { qrDisplayDialog = new QRDisplayDialog(RegistryType.BYTES.toString(), outputStream.toByteArray(), true); } else if(exporter instanceof PassportMultisig || exporter instanceof KeystoneMultisig || exporter instanceof JadeMultisig || exporter instanceof Bip129) { qrDisplayDialog = new QRDisplayDialog(RegistryType.BYTES.toString(), outputStream.toByteArray(), false); + } else if(exporter instanceof Descriptor) { + OutputDescriptor outputDescriptor = OutputDescriptor.getOutputDescriptor(exportWallet, KeyPurpose.DEFAULT_PURPOSES, null); + CryptoOutput cryptoOutput = getCryptoOutput(exportWallet); + qrDisplayDialog = new DescriptorQRDisplayDialog(exportWallet.getFullDisplayName(), outputDescriptor.toString(true), cryptoOutput.toUR()); } else { qrDisplayDialog = new QRDisplayDialog(outputStream.toString(StandardCharsets.UTF_8)); } diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Descriptor.java b/src/main/java/com/sparrowwallet/sparrow/io/Descriptor.java index 1bea7d5a..0bbb699a 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Descriptor.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Descriptor.java @@ -65,7 +65,7 @@ public class Descriptor implements WalletImport, WalletExport { @Override public boolean isWalletExportScannable() { - return false; + return true; } @Override diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java index 9bcef974..40f50853 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java @@ -381,7 +381,7 @@ public class SettingsController extends WalletFormController implements Initiali qrDisplayDialog.showAndWait(); } - private CryptoOutput getCryptoOutput(Wallet wallet) { + public static CryptoOutput getCryptoOutput(Wallet wallet) { List scriptExpressions = getScriptExpressions(wallet.getScriptType()); CryptoOutput cryptoOutput = null; @@ -392,7 +392,7 @@ public class SettingsController extends WalletFormController implements Initiali Utils.LexicographicByteArrayComparator lexicographicByteArrayComparator = new Utils.LexicographicByteArrayComparator(); List cryptoHDKeys = wallet.getKeystores().stream().sorted((keystore1, keystore2) -> { return lexicographicByteArrayComparator.compare(keystore1.getPubKey(firstReceive).getPubKey(), keystore2.getPubKey(firstReceive).getPubKey()); - }).map(this::getCryptoHDKey).collect(Collectors.toList()); + }).map(SettingsController::getCryptoHDKey).collect(Collectors.toList()); MultiKey multiKey = new MultiKey(wallet.getDefaultPolicy().getNumSignaturesRequired(), null, cryptoHDKeys); List multiScriptExpressions = new ArrayList<>(scriptExpressions); multiScriptExpressions.add(ScriptExpression.SORTED_MULTISIG); @@ -402,7 +402,7 @@ public class SettingsController extends WalletFormController implements Initiali return cryptoOutput; } - private List getScriptExpressions(ScriptType scriptType) { + private static List getScriptExpressions(ScriptType scriptType) { if(scriptType == ScriptType.P2PK) { return List.of(ScriptExpression.PUBLIC_KEY); } else if(scriptType == ScriptType.P2PKH) { @@ -424,7 +424,7 @@ public class SettingsController extends WalletFormController implements Initiali throw new IllegalArgumentException("Unknown script type of " + scriptType); } - private CryptoHDKey getCryptoHDKey(Keystore keystore) { + private static CryptoHDKey getCryptoHDKey(Keystore keystore) { ExtendedKey extendedKey = keystore.getExtendedPublicKey(); CryptoCoinInfo cryptoCoinInfo = new CryptoCoinInfo(CryptoCoinInfo.Type.BITCOIN.ordinal(), Network.get() == Network.MAINNET ? CryptoCoinInfo.Network.MAINNET.ordinal() : CryptoCoinInfo.Network.TESTNET.ordinal()); List pathComponents = keystore.getKeyDerivation().getDerivation().stream().map(cNum -> new IndexPathComponent(cNum.num(), cNum.isHardened())).collect(Collectors.toList());