Search in sources :

Example 16 with Keystore

use of com.sparrowwallet.drongo.wallet.Keystore in project sparrow by sparrowwallet.

the class KeystoreController method launchImportDialog.

private void launchImportDialog(KeystoreSource initialSource) {
    boolean restrictSource = keystoreSourceToggleGroup.getToggles().stream().anyMatch(toggle -> ((ToggleButton) toggle).isDisabled());
    KeyDerivation requiredDerivation = restrictSource ? keystore.getKeyDerivation() : null;
    WalletModel requiredModel = restrictSource ? keystore.getWalletModel() : null;
    KeystoreImportDialog dlg = new KeystoreImportDialog(getWalletForm().getWallet(), initialSource, requiredDerivation, requiredModel, restrictSource);
    Optional<Keystore> result = dlg.showAndWait();
    if (result.isPresent()) {
        selectSourcePane.setVisible(false);
        Keystore importedKeystore = result.get();
        walletForm.getWallet().makeLabelsUnique(importedKeystore);
        keystore.setSource(importedKeystore.getSource());
        keystore.setWalletModel(importedKeystore.getWalletModel());
        keystore.setLabel(importedKeystore.getLabel());
        keystore.setKeyDerivation(importedKeystore.getKeyDerivation());
        keystore.setExtendedPublicKey(importedKeystore.getExtendedPublicKey());
        keystore.setMasterPrivateExtendedKey(importedKeystore.getMasterPrivateExtendedKey());
        keystore.setSeed(importedKeystore.getSeed());
        keystore.setBip47ExtendedPrivateKey(importedKeystore.getBip47ExtendedPrivateKey());
        updateType();
        label.setText(keystore.getLabel());
        fingerprint.setText(keystore.getKeyDerivation().getMasterFingerprint());
        derivation.setText(keystore.getKeyDerivation().getDerivationPath());
        if (keystore.getExtendedPublicKey() != null) {
            xpub.setText(keystore.getExtendedPublicKey().toString());
            setXpubContext(keystore.getExtendedPublicKey());
        } else {
            xpub.setText("");
        }
    }
}
Also used : Keystore(com.sparrowwallet.drongo.wallet.Keystore) WalletModel(com.sparrowwallet.drongo.wallet.WalletModel) KeystoreImportDialog(com.sparrowwallet.sparrow.keystoreimport.KeystoreImportDialog)

Example 17 with Keystore

use of com.sparrowwallet.drongo.wallet.Keystore in project sparrow by sparrowwallet.

the class KeystoreController method scanXpubQR.

public void scanXpubQR(ActionEvent event) {
    QRScanDialog qrScanDialog = new QRScanDialog();
    Optional<QRScanDialog.Result> optionalResult = qrScanDialog.showAndWait();
    if (optionalResult.isPresent()) {
        QRScanDialog.Result result = optionalResult.get();
        if (result.extendedKey != null && result.extendedKey.getKey().isPubKeyOnly()) {
            xpub.setText(result.extendedKey.getExtendedKey());
        } else if (result.outputDescriptor != null && !result.outputDescriptor.getExtendedPublicKeys().isEmpty()) {
            ExtendedKey extendedKey = result.outputDescriptor.getExtendedPublicKeys().iterator().next();
            KeyDerivation keyDerivation = result.outputDescriptor.getKeyDerivation(extendedKey);
            fingerprint.setText(keyDerivation.getMasterFingerprint());
            derivation.setText(keyDerivation.getDerivationPath());
            xpub.setText(extendedKey.toString());
        } else if (result.wallets != null) {
            for (Wallet wallet : result.wallets) {
                if (getWalletForm().getWallet().getScriptType().equals(wallet.getScriptType()) && !wallet.getKeystores().isEmpty()) {
                    Keystore keystore = wallet.getKeystores().get(0);
                    fingerprint.setText(keystore.getKeyDerivation().getMasterFingerprint());
                    derivation.setText(keystore.getKeyDerivation().getDerivationPath());
                    xpub.setText(keystore.getExtendedPublicKey().toString());
                    return;
                }
            }
            AppServices.showErrorDialog("Missing Script Type", "QR Code did not contain any information for the " + getWalletForm().getWallet().getScriptType().getDescription() + " script type.");
        } else if (result.exception != null) {
            log.error("Error scanning QR", result.exception);
            AppServices.showErrorDialog("Error scanning QR", result.exception.getMessage());
        } else {
            AppServices.showErrorDialog("Invalid QR Code", "QR Code did not contain a valid " + Network.get().getXpubHeader().getDisplayName());
        }
    }
}
Also used : Keystore(com.sparrowwallet.drongo.wallet.Keystore) Wallet(com.sparrowwallet.drongo.wallet.Wallet) ValidationResult(org.controlsfx.validation.ValidationResult)

Example 18 with Keystore

use of com.sparrowwallet.drongo.wallet.Keystore in project sparrow by sparrowwallet.

the class ColdcardSinglesigTest method testImportWitness.

@Test
public void testImportWitness() throws ImportException {
    Network.set(Network.TESTNET);
    ColdcardSinglesig ccSingleSig = new ColdcardSinglesig();
    Keystore keystore = ccSingleSig.getKeystore(ScriptType.P2WPKH, getInputStream("cc-singlesig-keystore-1.json"), null);
    Assert.assertEquals("Coldcard", keystore.getLabel());
    Assert.assertEquals("m/84'/1'/123'", keystore.getKeyDerivation().getDerivationPath());
    Assert.assertEquals("0f056943", keystore.getKeyDerivation().getMasterFingerprint());
    Assert.assertEquals(ExtendedKey.fromDescriptor("tpubDC7jGaaSE66VDB6VhEDFYQSCAyugXmfnMnrMVyHNzW9wryyTxvha7TmfAHd7GRXrr2TaAn2HXn9T8ep4gyNX1bzGiieqcTUNcu2poyntrET"), keystore.getExtendedPublicKey());
    Assert.assertTrue(keystore.isValid());
}
Also used : Keystore(com.sparrowwallet.drongo.wallet.Keystore) Test(org.junit.Test)

Example 19 with Keystore

use of com.sparrowwallet.drongo.wallet.Keystore in project sparrow by sparrowwallet.

the class ColdcardSinglesigTest method testImport.

@Test
public void testImport() throws ImportException {
    Network.set(Network.TESTNET);
    ColdcardSinglesig ccSingleSig = new ColdcardSinglesig();
    Keystore keystore = ccSingleSig.getKeystore(ScriptType.P2SH_P2WPKH, getInputStream("cc-singlesig-keystore-1.json"), null);
    Assert.assertEquals("Coldcard", keystore.getLabel());
    Assert.assertEquals("m/49'/1'/123'", keystore.getKeyDerivation().getDerivationPath());
    Assert.assertEquals("0f056943", keystore.getKeyDerivation().getMasterFingerprint());
    Assert.assertEquals(ExtendedKey.fromDescriptor("tpubDCDqt7XXvhAdy1MpSze5nMJA9x8DrdRaKALRRPasfxyHpiqWWEAr9cbDBQ9BcX7cB3up98Pk97U2QQ3xrvQsi5dNPmRYYhdcsKY9wwEY87T"), keystore.getExtendedPublicKey());
    Assert.assertTrue(keystore.isValid());
}
Also used : Keystore(com.sparrowwallet.drongo.wallet.Keystore) Test(org.junit.Test)

Example 20 with Keystore

use of com.sparrowwallet.drongo.wallet.Keystore in project sparrow by sparrowwallet.

the class KeystoneSinglesigTest method testImport.

@Test
public void testImport() throws ImportException {
    KeystoneSinglesig keystoneSingleSig = new KeystoneSinglesig();
    Keystore keystore = keystoneSingleSig.getKeystore(ScriptType.P2WPKH, getInputStream("keystone-singlesig-keystore-1.txt"), null);
    Assert.assertEquals("Keystone", keystore.getLabel());
    Assert.assertEquals("m/84'/0'/0'", keystore.getKeyDerivation().getDerivationPath());
    Assert.assertEquals("5271c071", keystore.getKeyDerivation().getMasterFingerprint());
    Assert.assertEquals(ExtendedKey.fromDescriptor("zpub6rcabYFcdr41zyUNRWRyHYs2Sm86E5XV8RjjRzTFYsiCngteeZnkwaF2xuhjmM6kpHjuNpFW42BMhzPmFwXt48e1FhddMB7xidZzN4SF24K"), keystore.getExtendedPublicKey());
    Assert.assertTrue(keystore.isValid());
}
Also used : Keystore(com.sparrowwallet.drongo.wallet.Keystore) Test(org.junit.Test)

Aggregations

Keystore (com.sparrowwallet.drongo.wallet.Keystore)47 Wallet (com.sparrowwallet.drongo.wallet.Wallet)14 Test (org.junit.Test)12 KeyDerivation (com.sparrowwallet.drongo.KeyDerivation)5 ScriptType (com.sparrowwallet.drongo.protocol.ScriptType)5 ImportException (com.sparrowwallet.sparrow.io.ImportException)4 ECKey (com.sparrowwallet.drongo.crypto.ECKey)3 ArrayList (java.util.ArrayList)3 Subscribe (com.google.common.eventbus.Subscribe)2 com.sparrowwallet.drongo.protocol (com.sparrowwallet.drongo.protocol)2 PSBTInput (com.sparrowwallet.drongo.psbt.PSBTInput)2 BlockTransaction (com.sparrowwallet.drongo.wallet.BlockTransaction)2 DeterministicSeed (com.sparrowwallet.drongo.wallet.DeterministicSeed)2 MasterPrivateExtendedKey (com.sparrowwallet.drongo.wallet.MasterPrivateExtendedKey)2 WalletModel (com.sparrowwallet.drongo.wallet.WalletModel)2 EventManager (com.sparrowwallet.sparrow.EventManager)2 KeystoreImportEvent (com.sparrowwallet.sparrow.event.KeystoreImportEvent)2 URL (java.net.URL)2 Map (java.util.Map)2 ResourceBundle (java.util.ResourceBundle)2