How to prevent from persisting private keys

33 views
Skip to first unread message

Stanislaw Baranski

unread,
Oct 15, 2018, 6:27:14 AM10/15/18
to bitcoinj
Hello,
I'm creating the physical wallet (similar to Ledger Nano S), and I want to store private key in my own way. I don't want the BitcoinJ to store the private key in .wallet file. Is there some way to configure the library so it keep the private key in-memory and lost it after the session ? I would like to restore/import the private key after some process of authorization (button, pin, 2FA etc.).

Or maybe should I take use of wallet().encrypt() and wallet().encrypt() is it safer ?

Andreas Schildbach

unread,
Oct 16, 2018, 6:20:30 PM10/16/18
to bitc...@googlegroups.com
Yes, you either could encrypt the keys (and keep the decryption key just
in memory). Or you could use a read-only wallet that only has the public
keys to begin with.
> --
> You received this message because you are subscribed to the Google
> Groups "bitcoinj" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to bitcoinj+u...@googlegroups.com
> <mailto:bitcoinj+u...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.


Stanislaw Baranski

unread,
Oct 19, 2018, 5:05:39 PM10/19/18
to bitc...@googlegroups.com
Hello,
Thanks for the answer. I tried with wallet() .encryp/.decrypt, but there is a problem. I can not prevent the BitcoinJ from saving the decrypted wallet. 

Even if I set 
kit.setAutoSave(false)
the .wallet file is still saved.
I would like to save it only when it's encrypted like
bitcoin.kit.wallet().encrypt(keyCrypter, key);
bitcoin.kit.wallet().saveToFile(bitcoin.getWalletFile());
Is it possible ?


You received this message because you are subscribed to a topic in the Google Groups "bitcoinj" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bitcoinj/eCRiK0RBdjw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bitcoinj+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--

Stanisław Barański

Andreas Schildbach

unread,
Oct 20, 2018, 3:49:48 PM10/20/18
to bitc...@googlegroups.com
Can you write a unit test for this? Bitcoinj shouldn't persist a wallet
at all unless instructed.

Maybe try using the Wallet class without WalletAppKit?
> <mailto:bitcoinj%2Bunsu...@googlegroups.com>
> > <mailto:bitcoinj+u...@googlegroups.com
> <mailto:bitcoinj%2Bunsu...@googlegroups.com>>.
> > For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to a topic in
> the Google Groups "bitcoinj" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/bitcoinj/eCRiK0RBdjw/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> bitcoinj+u...@googlegroups.com
> <mailto:bitcoinj%2Bunsu...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.
>
> --
>
> Stanisław Barański

Stanislaw Baranski

unread,
Oct 21, 2018, 2:55:53 AM10/21/18
to bitc...@googlegroups.com
Ok, here is the unit tests that fails
public class BitcoinJTest {
private File rootDirectory = new File(".");
private NetworkParameters params = TestNet3Params.get();
private String walletFileName = "RaspberryWallet_" + params.getPaymentProtocolId();

@Test
void testWalletAppKit() {
File walletFile = getWalletFile()
;
if (walletFile.exists()) walletFile.delete();
assertFalse(walletFile.exists());

WalletAppKit kit = new WalletAppKit(params, rootDirectory, walletFileName) {
@Override
protected void onSetupCompleted() {
Logger.
info("Bitcoin setup complete");
assertFalse(walletFile.exists()); //AssertionFailedError
}
}
;

kit.setAutoSave(false);
kit.startAsync().awaitRunning();


}

public File getWalletFile() {
return new File(rootDirectory, walletFileName + ".wallet");
}
}
Exception in thread " STARTING" org.opentest4j.AssertionFailedError: expected: <false> but was: <true>
	at io.raspberrywallet.manager.bitcoin.BitcoinJTest$1.onSetupCompleted(BitcoinJTest.java:28)

What can I do with Wallet without WalletAppKit? How can I embed it into WalletAppKit? Or just how can I sync it?




To unsubscribe from this group and all its topics, send an email to bitcoinj+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
Best Regards,
Stanislaw Baranski

Andreas Schildbach

unread,
Oct 29, 2018, 6:12:26 AM10/29/18
to bitc...@googlegroups.com
Ah, I see, you're using WalletAppKit. That class is designed around
persisting the wallet and the chain.

In this case I suggest using the Wallet class directly. There are
numerous examples and unit tests that show how to work with a Wallet
without actually persisting it.
> <mailto:and...@schildbach.de>> napisał(a):
>
> Can you write a unit test for this? Bitcoinj shouldn't persist a wallet
> at all unless instructed.
>
> Maybe try using the Wallet class without WalletAppKit?
>
>
> On 19/10/2018 23.05, Stanislaw Baranski wrote:
> > Hello,
> > Thanks for the answer. I tried with wallet() .encryp/.decrypt, but
> there
> > is a problem. I can not prevent the BitcoinJ from saving the decrypted
> > wallet. 
> >
> > Even if I set 
> >
> > kit.setAutoSave(false)
> >
> > the .wallet file is still saved.
> > I would like to save it only when it's encrypted like
> >
> > bitcoin.kit.wallet().encrypt(keyCrypter, key);
> > bitcoin.kit.wallet().saveToFile(bitcoin.getWalletFile());
> >
> > Is it possible ?
> >
> >
> > On Wed, Oct 17, 2018 at 12:20 AM Andreas Schildbach
> > <and...@schildbach.de <mailto:and...@schildbach.de>
> >     <mailto:bitcoinj%2Bunsu...@googlegroups.com
> <mailto:bitcoinj%252Buns...@googlegroups.com>>
> >     > <mailto:bitcoinj+u...@googlegroups.com
> <mailto:bitcoinj%2Bunsu...@googlegroups.com>
> >     <mailto:bitcoinj%2Bunsu...@googlegroups.com
> <mailto:bitcoinj%252Buns...@googlegroups.com>>>.
> >     > For more options, visit https://groups.google.com/d/optout.
> >
> >
> >     --
> >     You received this message because you are subscribed to a topic in
> >     the Google Groups "bitcoinj" group.
> >     To unsubscribe from this topic, visit
> >   
>  https://groups.google.com/d/topic/bitcoinj/eCRiK0RBdjw/unsubscribe.
> >     To unsubscribe from this group and all its topics, send an
> email to
> >     bitcoinj+u...@googlegroups.com
> <mailto:bitcoinj%2Bunsu...@googlegroups.com>
> >     <mailto:bitcoinj%2Bunsu...@googlegroups.com
> <mailto:bitcoinj%252Buns...@googlegroups.com>>.
> >     For more options, visit https://groups.google.com/d/optout.
> >
> > --
> >
> > Stanisław Barański
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "bitcoinj" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> > an email to bitcoinj+u...@googlegroups.com
> <mailto:bitcoinj%2Bunsu...@googlegroups.com>
> > <mailto:bitcoinj+u...@googlegroups.com
> <mailto:bitcoinj%2Bunsu...@googlegroups.com>>.
> > For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to a topic in
> the Google Groups "bitcoinj" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/bitcoinj/eCRiK0RBdjw/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> bitcoinj+u...@googlegroups.com
> <mailto:bitcoinj%2Bunsu...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> Best Regards,
> Stanislaw Baranski

Stanislaw Baranski

unread,
Dec 3, 2018, 6:53:12 PM12/3/18
to bitcoinj
Thank you very much for help. I resolved the problem using Wallet class directly :)
>     >     > <mailto:bitcoinj+u...@googlegroups.com
>     <mailto:bitcoinj%2Bunsu...@googlegroups.com>
>     >     <mailto:bitcoinj%2Bunsu...@googlegroups.com
>     >     > For more options, visit https://groups.google.com/d/optout.
>     >
>     >
>     >     --
>     >     You received this message because you are subscribed to a topic in
>     >     the Google Groups "bitcoinj" group.
>     >     To unsubscribe from this topic, visit
>     >   
>      https://groups.google.com/d/topic/bitcoinj/eCRiK0RBdjw/unsubscribe.
>     >     To unsubscribe from this group and all its topics, send an
>     email to
>     >     bitcoinj+u...@googlegroups.com
>     <mailto:bitcoinj%2Bunsu...@googlegroups.com>
>     >     <mailto:bitcoinj%2Bunsu...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages