Search in sources :

Example 26 with Keystore

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

the class SettingsWalletForm method isRefreshNecessary.

// Returns true for any change, other than a keystore label change, to trigger a full wallet refresh
// Even though this is not strictly necessary for some changes, it it better to refresh on saving so background transaction history updates on the old wallet have no effect/are not lost
private boolean isRefreshNecessary(Wallet original, Wallet changed) {
    if (!original.isValid() || !changed.isValid()) {
        return true;
    }
    if (isAddressChange(original, changed)) {
        return true;
    }
    for (int i = 0; i < original.getKeystores().size(); i++) {
        Keystore originalKeystore = original.getKeystores().get(i);
        Keystore changedKeystore = changed.getKeystores().get(i);
        if (originalKeystore.getSource() != changedKeystore.getSource()) {
            return true;
        }
        if (originalKeystore.getWalletModel() != changedKeystore.getWalletModel()) {
            return true;
        }
        if ((originalKeystore.getSeed() == null && changedKeystore.getSeed() != null) || (originalKeystore.getSeed() != null && changedKeystore.getSeed() == null)) {
            return true;
        }
        if ((originalKeystore.getMasterPrivateExtendedKey() == null && changedKeystore.getMasterPrivateExtendedKey() != null) || (originalKeystore.getMasterPrivateExtendedKey() != null && changedKeystore.getMasterPrivateExtendedKey() == null)) {
            return true;
        }
    }
    if (original.getGapLimit() != changed.getGapLimit()) {
        return true;
    }
    if (!Objects.equals(original.getBirthDate(), changed.getBirthDate())) {
        return true;
    }
    return false;
}
Also used : Keystore(com.sparrowwallet.drongo.wallet.Keystore)

Example 27 with Keystore

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

the class CoboVaultSinglesigTest method testImport.

@Test
public void testImport() throws ImportException {
    CoboVaultSinglesig coboSingleSig = new CoboVaultSinglesig();
    Keystore keystore = coboSingleSig.getKeystore(ScriptType.P2WPKH, getInputStream("cobo-singlesig-keystore-1.json"), null);
    Assert.assertEquals("Cobo Vault", keystore.getLabel());
    Assert.assertEquals("m/84'/0'/0'", keystore.getKeyDerivation().getDerivationPath());
    Assert.assertEquals("73c5da0a", keystore.getKeyDerivation().getMasterFingerprint());
    Assert.assertEquals(ExtendedKey.fromDescriptor("zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs"), keystore.getExtendedPublicKey());
    Assert.assertTrue(keystore.isValid());
}
Also used : Keystore(com.sparrowwallet.drongo.wallet.Keystore) Test(org.junit.Test)

Example 28 with Keystore

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

the class CoboVaultSinglesigTest method testIncorrectScriptType.

@Test(expected = ImportException.class)
public void testIncorrectScriptType() throws ImportException {
    CoboVaultSinglesig coboSingleSig = new CoboVaultSinglesig();
    Keystore keystore = coboSingleSig.getKeystore(ScriptType.P2SH_P2WPKH, getInputStream("cobo-singlesig-keystore-1.json"), null);
    Assert.assertEquals("Cobo Vault", keystore.getLabel());
    Assert.assertEquals("m/84'/0'/0'", keystore.getKeyDerivation().getDerivationPath());
    Assert.assertEquals("73c5da0a", keystore.getKeyDerivation().getMasterFingerprint());
    Assert.assertEquals(ExtendedKey.fromDescriptor("zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs"), keystore.getExtendedPublicKey());
    Assert.assertTrue(keystore.isValid());
}
Also used : Keystore(com.sparrowwallet.drongo.wallet.Keystore) Test(org.junit.Test)

Example 29 with Keystore

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

the class ColdcardMultisigTest method importKeystore1IncorrectScriptType.

@Test(expected = ImportException.class)
public void importKeystore1IncorrectScriptType() throws ImportException {
    ColdcardMultisig ccMultisig = new ColdcardMultisig();
    Keystore keystore = ccMultisig.getKeystore(ScriptType.P2SH_P2WPKH, getInputStream("cc-multisig-keystore-1.json"), null);
}
Also used : Keystore(com.sparrowwallet.drongo.wallet.Keystore) Test(org.junit.Test)

Example 30 with Keystore

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

the class ColdcardMultisigTest method importKeystore2b.

@Test
public void importKeystore2b() throws ImportException {
    Network.set(Network.TESTNET);
    ColdcardMultisig ccMultisig = new ColdcardMultisig();
    Keystore keystore = ccMultisig.getKeystore(ScriptType.P2WSH, getInputStream("cc-multisig-keystore-2.json"), null);
    Assert.assertEquals("Coldcard", keystore.getLabel());
    Assert.assertEquals("m/48'/1'/0'/2'", keystore.getKeyDerivation().getDerivationPath());
    Assert.assertEquals("6ba6cfd0", keystore.getKeyDerivation().getMasterFingerprint());
    Assert.assertEquals(ExtendedKey.fromDescriptor("Vpub5nUnvPehg1VYQh13dGznx1P9moac3SNUrn3qhU9r85RhXabYbSSBNsNNwyR7akozAZJw1SZmRRjry1zY8PWMuw8Ga1vQZ5qzPjKyTDQwtzs"), 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