Search in sources :

Example 1 with MasterPrivateExtendedKey

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

the class KeystoreDao method updateKeystoreEncryption.

default void updateKeystoreEncryption(Keystore keystore) {
    if (keystore.hasMasterPrivateExtendedKey()) {
        MasterPrivateExtendedKey mpek = keystore.getMasterPrivateExtendedKey();
        if (mpek.isEncrypted()) {
            EncryptedData data = mpek.getEncryptedData();
            updateMasterPrivateExtendedKey(null, null, data.getInitialisationVector(), data.getEncryptedBytes(), data.getKeySalt(), data.getEncryptionType().getDeriver().ordinal(), data.getEncryptionType().getCrypter().ordinal(), mpek.getCreationTimeSeconds(), mpek.getId());
        } else {
            updateMasterPrivateExtendedKey(mpek.getPrivateKey().getPrivKeyBytes(), mpek.getPrivateKey().getChainCode(), null, null, null, null, null, mpek.getCreationTimeSeconds(), mpek.getId());
        }
    }
    if (keystore.hasSeed()) {
        DeterministicSeed seed = keystore.getSeed();
        if (seed.isEncrypted()) {
            EncryptedData data = seed.getEncryptedData();
            updateSeed(seed.getType().ordinal(), null, data.getInitialisationVector(), data.getEncryptedBytes(), data.getKeySalt(), data.getEncryptionType().getDeriver().ordinal(), data.getEncryptionType().getCrypter().ordinal(), seed.needsPassphrase(), seed.getCreationTimeSeconds(), seed.getId());
        } else {
            updateSeed(seed.getType().ordinal(), seed.getMnemonicString().asString(), null, null, null, null, null, seed.needsPassphrase(), seed.getCreationTimeSeconds(), seed.getId());
        }
    }
}
Also used : DeterministicSeed(com.sparrowwallet.drongo.wallet.DeterministicSeed) EncryptedData(com.sparrowwallet.drongo.crypto.EncryptedData) MasterPrivateExtendedKey(com.sparrowwallet.drongo.wallet.MasterPrivateExtendedKey)

Example 2 with MasterPrivateExtendedKey

use of com.sparrowwallet.drongo.wallet.MasterPrivateExtendedKey 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)

Example 3 with MasterPrivateExtendedKey

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

the class KeystoreDao method addKeystores.

default void addKeystores(Wallet wallet) {
    for (int i = 0; i < wallet.getKeystores().size(); i++) {
        Keystore keystore = wallet.getKeystores().get(i);
        if (keystore.hasMasterPrivateExtendedKey()) {
            MasterPrivateExtendedKey mpek = keystore.getMasterPrivateExtendedKey();
            if (mpek.isEncrypted()) {
                EncryptedData data = mpek.getEncryptedData();
                long id = insertMasterPrivateExtendedKey(null, null, data.getInitialisationVector(), data.getEncryptedBytes(), data.getKeySalt(), data.getEncryptionType().getDeriver().ordinal(), data.getEncryptionType().getCrypter().ordinal(), mpek.getCreationTimeSeconds());
                mpek.setId(id);
            } else {
                long id = insertMasterPrivateExtendedKey(mpek.getPrivateKey().getPrivKeyBytes(), mpek.getPrivateKey().getChainCode(), null, null, null, null, null, mpek.getCreationTimeSeconds());
                mpek.setId(id);
            }
        }
        if (keystore.hasSeed()) {
            DeterministicSeed seed = keystore.getSeed();
            if (seed.isEncrypted()) {
                EncryptedData data = seed.getEncryptedData();
                long id = insertSeed(seed.getType().ordinal(), null, data.getInitialisationVector(), data.getEncryptedBytes(), data.getKeySalt(), data.getEncryptionType().getDeriver().ordinal(), data.getEncryptionType().getCrypter().ordinal(), seed.needsPassphrase(), seed.getCreationTimeSeconds());
                seed.setId(id);
            } else {
                long id = insertSeed(seed.getType().ordinal(), seed.getMnemonicString().asString(), null, null, null, null, null, seed.needsPassphrase(), seed.getCreationTimeSeconds());
                seed.setId(id);
            }
        }
        long id = insert(truncate(keystore.getLabel()), keystore.getSource().ordinal(), keystore.getWalletModel().ordinal(), keystore.hasMasterPrivateKey() ? null : keystore.getKeyDerivation().getMasterFingerprint(), keystore.getKeyDerivation().getDerivationPath(), keystore.hasMasterPrivateKey() ? null : keystore.getExtendedPublicKey().toString(), keystore.getExternalPaymentCode() == null ? null : keystore.getExternalPaymentCode().toString(), keystore.getMasterPrivateExtendedKey() == null ? null : keystore.getMasterPrivateExtendedKey().getId(), keystore.getSeed() == null ? null : keystore.getSeed().getId(), wallet.getId(), i);
        keystore.setId(id);
    }
}
Also used : Keystore(com.sparrowwallet.drongo.wallet.Keystore) DeterministicSeed(com.sparrowwallet.drongo.wallet.DeterministicSeed) EncryptedData(com.sparrowwallet.drongo.crypto.EncryptedData) MasterPrivateExtendedKey(com.sparrowwallet.drongo.wallet.MasterPrivateExtendedKey)

Aggregations

DeterministicSeed (com.sparrowwallet.drongo.wallet.DeterministicSeed)3 MasterPrivateExtendedKey (com.sparrowwallet.drongo.wallet.MasterPrivateExtendedKey)3 EncryptedData (com.sparrowwallet.drongo.crypto.EncryptedData)2 Keystore (com.sparrowwallet.drongo.wallet.Keystore)2 ArrayList (java.util.ArrayList)1