mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 21:26:43 +00:00
add qr display (with save to pdf) to output descriptor wallet export options
This commit is contained in:
parent
1e3ce7eb88
commit
f590794589
3 changed files with 14 additions and 5 deletions
|
@ -1,7 +1,10 @@
|
||||||
package com.sparrowwallet.sparrow.control;
|
package com.sparrowwallet.sparrow.control;
|
||||||
|
|
||||||
|
import com.sparrowwallet.drongo.KeyPurpose;
|
||||||
|
import com.sparrowwallet.drongo.OutputDescriptor;
|
||||||
import com.sparrowwallet.drongo.SecureString;
|
import com.sparrowwallet.drongo.SecureString;
|
||||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||||
|
import com.sparrowwallet.hummingbird.registry.CryptoOutput;
|
||||||
import com.sparrowwallet.hummingbird.registry.RegistryType;
|
import com.sparrowwallet.hummingbird.registry.RegistryType;
|
||||||
import com.sparrowwallet.sparrow.AppServices;
|
import com.sparrowwallet.sparrow.AppServices;
|
||||||
import com.sparrowwallet.sparrow.EventManager;
|
import com.sparrowwallet.sparrow.EventManager;
|
||||||
|
@ -26,6 +29,8 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static com.sparrowwallet.sparrow.wallet.SettingsController.getCryptoOutput;
|
||||||
|
|
||||||
public class FileWalletExportPane extends TitledDescriptionPane {
|
public class FileWalletExportPane extends TitledDescriptionPane {
|
||||||
private final Wallet wallet;
|
private final Wallet wallet;
|
||||||
private final WalletExport exporter;
|
private final WalletExport exporter;
|
||||||
|
@ -164,6 +169,10 @@ public class FileWalletExportPane extends TitledDescriptionPane {
|
||||||
qrDisplayDialog = new QRDisplayDialog(RegistryType.BYTES.toString(), outputStream.toByteArray(), true);
|
qrDisplayDialog = new QRDisplayDialog(RegistryType.BYTES.toString(), outputStream.toByteArray(), true);
|
||||||
} else if(exporter instanceof PassportMultisig || exporter instanceof KeystoneMultisig || exporter instanceof JadeMultisig || exporter instanceof Bip129) {
|
} else if(exporter instanceof PassportMultisig || exporter instanceof KeystoneMultisig || exporter instanceof JadeMultisig || exporter instanceof Bip129) {
|
||||||
qrDisplayDialog = new QRDisplayDialog(RegistryType.BYTES.toString(), outputStream.toByteArray(), false);
|
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 {
|
} else {
|
||||||
qrDisplayDialog = new QRDisplayDialog(outputStream.toString(StandardCharsets.UTF_8));
|
qrDisplayDialog = new QRDisplayDialog(outputStream.toString(StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class Descriptor implements WalletImport, WalletExport {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWalletExportScannable() {
|
public boolean isWalletExportScannable() {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -381,7 +381,7 @@ public class SettingsController extends WalletFormController implements Initiali
|
||||||
qrDisplayDialog.showAndWait();
|
qrDisplayDialog.showAndWait();
|
||||||
}
|
}
|
||||||
|
|
||||||
private CryptoOutput getCryptoOutput(Wallet wallet) {
|
public static CryptoOutput getCryptoOutput(Wallet wallet) {
|
||||||
List<ScriptExpression> scriptExpressions = getScriptExpressions(wallet.getScriptType());
|
List<ScriptExpression> scriptExpressions = getScriptExpressions(wallet.getScriptType());
|
||||||
|
|
||||||
CryptoOutput cryptoOutput = null;
|
CryptoOutput cryptoOutput = null;
|
||||||
|
@ -392,7 +392,7 @@ public class SettingsController extends WalletFormController implements Initiali
|
||||||
Utils.LexicographicByteArrayComparator lexicographicByteArrayComparator = new Utils.LexicographicByteArrayComparator();
|
Utils.LexicographicByteArrayComparator lexicographicByteArrayComparator = new Utils.LexicographicByteArrayComparator();
|
||||||
List<CryptoHDKey> cryptoHDKeys = wallet.getKeystores().stream().sorted((keystore1, keystore2) -> {
|
List<CryptoHDKey> cryptoHDKeys = wallet.getKeystores().stream().sorted((keystore1, keystore2) -> {
|
||||||
return lexicographicByteArrayComparator.compare(keystore1.getPubKey(firstReceive).getPubKey(), keystore2.getPubKey(firstReceive).getPubKey());
|
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);
|
MultiKey multiKey = new MultiKey(wallet.getDefaultPolicy().getNumSignaturesRequired(), null, cryptoHDKeys);
|
||||||
List<ScriptExpression> multiScriptExpressions = new ArrayList<>(scriptExpressions);
|
List<ScriptExpression> multiScriptExpressions = new ArrayList<>(scriptExpressions);
|
||||||
multiScriptExpressions.add(ScriptExpression.SORTED_MULTISIG);
|
multiScriptExpressions.add(ScriptExpression.SORTED_MULTISIG);
|
||||||
|
@ -402,7 +402,7 @@ public class SettingsController extends WalletFormController implements Initiali
|
||||||
return cryptoOutput;
|
return cryptoOutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ScriptExpression> getScriptExpressions(ScriptType scriptType) {
|
private static List<ScriptExpression> getScriptExpressions(ScriptType scriptType) {
|
||||||
if(scriptType == ScriptType.P2PK) {
|
if(scriptType == ScriptType.P2PK) {
|
||||||
return List.of(ScriptExpression.PUBLIC_KEY);
|
return List.of(ScriptExpression.PUBLIC_KEY);
|
||||||
} else if(scriptType == ScriptType.P2PKH) {
|
} else if(scriptType == ScriptType.P2PKH) {
|
||||||
|
@ -424,7 +424,7 @@ public class SettingsController extends WalletFormController implements Initiali
|
||||||
throw new IllegalArgumentException("Unknown script type of " + scriptType);
|
throw new IllegalArgumentException("Unknown script type of " + scriptType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CryptoHDKey getCryptoHDKey(Keystore keystore) {
|
private static CryptoHDKey getCryptoHDKey(Keystore keystore) {
|
||||||
ExtendedKey extendedKey = keystore.getExtendedPublicKey();
|
ExtendedKey extendedKey = keystore.getExtendedPublicKey();
|
||||||
CryptoCoinInfo cryptoCoinInfo = new CryptoCoinInfo(CryptoCoinInfo.Type.BITCOIN.ordinal(), Network.get() == Network.MAINNET ? CryptoCoinInfo.Network.MAINNET.ordinal() : CryptoCoinInfo.Network.TESTNET.ordinal());
|
CryptoCoinInfo cryptoCoinInfo = new CryptoCoinInfo(CryptoCoinInfo.Type.BITCOIN.ordinal(), Network.get() == Network.MAINNET ? CryptoCoinInfo.Network.MAINNET.ordinal() : CryptoCoinInfo.Network.TESTNET.ordinal());
|
||||||
List<PathComponent> pathComponents = keystore.getKeyDerivation().getDerivation().stream().map(cNum -> new IndexPathComponent(cNum.num(), cNum.isHardened())).collect(Collectors.toList());
|
List<PathComponent> pathComponents = keystore.getKeyDerivation().getDerivation().stream().map(cNum -> new IndexPathComponent(cNum.num(), cNum.isHardened())).collect(Collectors.toList());
|
||||||
|
|
Loading…
Reference in a new issue