From f4c8bfa48ced67dcf0c7177c9673bfd6817647f4 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 1 Aug 2022 14:17:46 +0200 Subject: [PATCH] avoid saving xpubs on bip47 wallets, restore from seed on opening --- drongo | 2 +- .../com/sparrowwallet/sparrow/AppController.java | 12 +++++++----- .../com/sparrowwallet/sparrow/io/db/KeystoreDao.java | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/drongo b/drongo index ca833fbf..ddaf698c 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit ca833fbf6807e9db30135562000329b7423b9fb7 +Subproject commit ddaf698c1011e5b01c7c3ed1e7693145ba5531ac diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index 96da5e5f..31d7f1c0 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -5,10 +5,7 @@ import com.google.common.base.Charsets; import com.google.common.eventbus.Subscribe; import com.google.common.io.ByteSource; import com.sparrowwallet.drongo.*; -import com.sparrowwallet.drongo.crypto.ECKey; -import com.sparrowwallet.drongo.crypto.EncryptionType; -import com.sparrowwallet.drongo.crypto.InvalidPasswordException; -import com.sparrowwallet.drongo.crypto.Key; +import com.sparrowwallet.drongo.crypto.*; import com.sparrowwallet.drongo.policy.PolicyType; import com.sparrowwallet.drongo.protocol.ScriptType; import com.sparrowwallet.drongo.protocol.Sha256Hash; @@ -1102,8 +1099,13 @@ public class AppController implements Initializable { for(Wallet childWallet : wallet.getChildWallets()) { if(childWallet.isBip47()) { try { + Keystore masterKeystore = wallet.getKeystores().get(0); Keystore keystore = childWallet.getKeystores().get(0); - keystore.setBip47ExtendedPrivateKey(wallet.getKeystores().get(0).getBip47ExtendedPrivateKey()); + keystore.setBip47ExtendedPrivateKey(masterKeystore.getBip47ExtendedPrivateKey()); + List derivation = keystore.getKeyDerivation().getDerivation(); + keystore.setKeyDerivation(new KeyDerivation(masterKeystore.getKeyDerivation().getMasterFingerprint(), derivation)); + DeterministicKey pubKey = keystore.getBip47ExtendedPrivateKey().getKey().dropPrivateBytes().dropParent(); + keystore.setExtendedPublicKey(new ExtendedKey(pubKey, keystore.getBip47ExtendedPrivateKey().getParentFingerprint(), derivation.get(derivation.size() - 1))); } catch(Exception e) { log.error("Cannot prepare BIP47 keystore", e); } diff --git a/src/main/java/com/sparrowwallet/sparrow/io/db/KeystoreDao.java b/src/main/java/com/sparrowwallet/sparrow/io/db/KeystoreDao.java index 68c66c85..0823b167 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/db/KeystoreDao.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/db/KeystoreDao.java @@ -69,9 +69,9 @@ public interface KeystoreDao { } long id = insert(truncate(keystore.getLabel()), keystore.getSource().ordinal(), keystore.getWalletModel().ordinal(), - keystore.hasMasterPrivateKey() ? null : keystore.getKeyDerivation().getMasterFingerprint(), + keystore.hasMasterPrivateKey() || wallet.isBip47() ? null : keystore.getKeyDerivation().getMasterFingerprint(), keystore.getKeyDerivation().getDerivationPath(), - keystore.hasMasterPrivateKey() ? null : keystore.getExtendedPublicKey().toString(), + keystore.hasMasterPrivateKey() || wallet.isBip47() ? 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);