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());
}
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());
}
}
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()));
}
}
}
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;
}
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;
}
Aggregations