Search in sources :

Example 21 with Keystore

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

the class KeystoneSinglesigTest method testIncorrectScriptType.

@Test(expected = ImportException.class)
public void testIncorrectScriptType() throws ImportException {
    KeystoneSinglesig keystoneSingleSig = new KeystoneSinglesig();
    Keystore keystore = keystoneSingleSig.getKeystore(ScriptType.P2SH_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)

Example 22 with Keystore

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

the class InputsController method initialiseView.

private void initialiseView() {
    Transaction tx = inputsForm.getTransaction();
    count.setText(Integer.toString(tx.getInputs().size()));
    signatures.setText("Unknown");
    if (inputsForm.getPsbt() != null) {
        updatePSBTInputs(inputsForm.getPsbt());
        inputsForm.getSignatureKeystoreMap().addListener((MapChangeListener<TransactionSignature, Keystore>) c -> {
            updatePSBTInputs(inputsForm.getPsbt());
        });
    } else if (inputsForm.getInputTransactions() != null) {
        updateBlockTransactionInputs(inputsForm.getInputTransactions());
    }
}
Also used : Keystore(com.sparrowwallet.drongo.wallet.Keystore) Initializable(javafx.fxml.Initializable) BitcoinUnitChangedEvent(com.sparrowwallet.sparrow.event.BitcoinUnitChangedEvent) PSBT(com.sparrowwallet.drongo.psbt.PSBT) BlockTransactionFetchedEvent(com.sparrowwallet.sparrow.event.BlockTransactionFetchedEvent) URL(java.net.URL) MapChangeListener(javafx.collections.MapChangeListener) CopyableCoinLabel(com.sparrowwallet.sparrow.control.CopyableCoinLabel) ArrayList(java.util.ArrayList) FXML(javafx.fxml.FXML) PieChart(javafx.scene.chart.PieChart) PSBTCombinedEvent(com.sparrowwallet.sparrow.event.PSBTCombinedEvent) List(java.util.List) BlockTransaction(com.sparrowwallet.drongo.wallet.BlockTransaction) ResourceBundle(java.util.ResourceBundle) CopyableLabel(com.sparrowwallet.sparrow.control.CopyableLabel) PSBTInput(com.sparrowwallet.drongo.psbt.PSBTInput) Map(java.util.Map) com.sparrowwallet.drongo.protocol(com.sparrowwallet.drongo.protocol) EventManager(com.sparrowwallet.sparrow.EventManager) Subscribe(com.google.common.eventbus.Subscribe) PSBTFinalizedEvent(com.sparrowwallet.sparrow.event.PSBTFinalizedEvent) Keystore(com.sparrowwallet.drongo.wallet.Keystore) BlockTransaction(com.sparrowwallet.drongo.wallet.BlockTransaction)

Example 23 with Keystore

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

the class SettingsWalletForm method saveAndRefresh.

@Override
public void saveAndRefresh() throws IOException, StorageException {
    Wallet pastWallet = wallet.copy();
    if (isRefreshNecessary(wallet, walletCopy)) {
        boolean addressChange = isAddressChange();
        if (wallet.isValid()) {
            // Clear transaction history cache before we clear the nodes
            AppServices.clearTransactionHistoryCache(wallet);
        }
        // Clear node tree, detaching and saving any labels from the existing wallet
        walletCopy.clearNodes(wallet);
        Integer childIndex = wallet.isMasterWallet() ? null : wallet.getMasterWallet().getChildWallets().indexOf(wallet);
        // Replace the SettingsWalletForm wallet reference - note that this reference is only shared with the WalletForm wallet with WalletAddressesChangedEvent below
        wallet = walletCopy.copy();
        if (wallet.isMasterWallet()) {
            wallet.getChildWallets().forEach(childWallet -> childWallet.setMasterWallet(wallet));
        } else if (childIndex != null) {
            wallet.getMasterWallet().getChildWallets().set(childIndex, wallet);
        }
        save();
        EventManager.get().post(new WalletAddressesChangedEvent(wallet, addressChange ? null : pastWallet, getWalletId()));
    } else {
        List<Keystore> labelChangedKeystores = getLabelChangedKeystores(wallet, walletCopy);
        if (!labelChangedKeystores.isEmpty()) {
            EventManager.get().post(new KeystoreLabelsChangedEvent(wallet, pastWallet, getWalletId(), labelChangedKeystores));
        }
        if (!Objects.equals(wallet.getWatchLast(), walletCopy.getWatchLast())) {
            EventManager.get().post(new WalletWatchLastChangedEvent(wallet, pastWallet, getWalletId(), walletCopy.getWatchLast()));
        }
        List<Keystore> encryptionChangedKeystores = getEncryptionChangedKeystores(wallet, walletCopy);
        if (!encryptionChangedKeystores.isEmpty()) {
            EventManager.get().post(new KeystoreEncryptionChangedEvent(wallet, pastWallet, getWalletId(), encryptionChangedKeystores));
        }
        for (Wallet childWallet : wallet.getChildWallets()) {
            Wallet childWalletCopy = walletCopy.getChildWallet(childWallet.getName());
            if (childWalletCopy != null) {
                Wallet pastChildWallet = childWallet.copy();
                List<Keystore> childEncryptionChangedKeystores = getEncryptionChangedKeystores(childWallet, childWalletCopy);
                if (!childEncryptionChangedKeystores.isEmpty()) {
                    EventManager.get().post(new KeystoreEncryptionChangedEvent(childWallet, pastChildWallet, getStorage().getWalletId(childWallet), childEncryptionChangedKeystores));
                }
            }
        }
        if (labelChangedKeystores.isEmpty() && encryptionChangedKeystores.isEmpty()) {
            // Can only be a wallet password change on a wallet without private keys
            EventManager.get().post(new WalletPasswordChangedEvent(wallet, pastWallet, getWalletId()));
        }
    }
}
Also used : Keystore(com.sparrowwallet.drongo.wallet.Keystore) Wallet(com.sparrowwallet.drongo.wallet.Wallet)

Example 24 with Keystore

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

the class SettingsWalletForm method getLabelChangedKeystores.

private List<Keystore> getLabelChangedKeystores(Wallet original, Wallet changed) {
    List<Keystore> changedKeystores = new ArrayList<>();
    for (int i = 0; i < original.getKeystores().size(); i++) {
        Keystore originalKeystore = original.getKeystores().get(i);
        Keystore changedKeystore = changed.getKeystores().get(i);
        if (!Objects.equals(originalKeystore.getLabel(), changedKeystore.getLabel())) {
            originalKeystore.setLabel(changedKeystore.getLabel());
            changedKeystores.add(originalKeystore);
        }
    }
    return changedKeystores;
}
Also used : Keystore(com.sparrowwallet.drongo.wallet.Keystore) ArrayList(java.util.ArrayList)

Example 25 with Keystore

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

the class SettingsWalletForm method getEncryptionChangedKeystores.

private List<Keystore> getEncryptionChangedKeystores(Wallet original, Wallet changed) {
    List<Keystore> changedKeystores = new ArrayList<>();
    for (int i = 0; i < original.getKeystores().size(); i++) {
        Keystore originalKeystore = original.getKeystores().get(i);
        Keystore changedKeystore = changed.getKeystores().get(i);
        if (originalKeystore.hasSeed() && changedKeystore.hasSeed()) {
            if (!Objects.equals(originalKeystore.getSeed().getEncryptedData(), changedKeystore.getSeed().getEncryptedData())) {
                DeterministicSeed changedSeed = changedKeystore.getSeed().copy();
                changedSeed.setId(originalKeystore.getSeed().getId());
                originalKeystore.setSeed(changedSeed);
                changedKeystores.add(originalKeystore);
            }
        }
        if (originalKeystore.hasMasterPrivateExtendedKey() && changedKeystore.hasMasterPrivateExtendedKey()) {
            if (!Objects.equals(originalKeystore.getMasterPrivateExtendedKey().getEncryptedData(), changedKeystore.getMasterPrivateExtendedKey().getEncryptedData())) {
                MasterPrivateExtendedKey changedMpek = changedKeystore.getMasterPrivateExtendedKey().copy();
                changedMpek.setId(originalKeystore.getMasterPrivateExtendedKey().getId());
                originalKeystore.setMasterPrivateExtendedKey(changedMpek);
                changedKeystores.add(originalKeystore);
            }
        }
    }
    return changedKeystores;
}
Also used : Keystore(com.sparrowwallet.drongo.wallet.Keystore) DeterministicSeed(com.sparrowwallet.drongo.wallet.DeterministicSeed) ArrayList(java.util.ArrayList) MasterPrivateExtendedKey(com.sparrowwallet.drongo.wallet.MasterPrivateExtendedKey)

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