I am in the discovery/research phase for a decenteralized app and have some really basic questions regarding js-ipfs. I was planning on using orbitdb and noticed that they use secp256k1keys. For those keys I was thinking of using bitcoin’s bip39 mnemonic seed phrase so that recovering the keys in a different browser/system would be easy. The issue is with the rsa keys. When looking at ipfs-js I don’t see an easy way to give ipfs the keys when initializing it. If I had some other mechanism for saving the rsa keys how would I start an ipfs node in the browser using those previously saved keys?
I’ve thought about possibly using bip39 seed to seed a rng and then using that rng when generating the rsa keys but I’m not sure how secure that would be and I’m not sure how I could boot ipfs in the browser using those generated keys.
Well the solution was actually as simple as possibly could be. The way to restore a key from a previous session in jsipfs is to supply the config.Identity option when initalizing ipfs. In addition to figuring that out I wrote an rsa implementation(more like edited parts of jsencrypt) which uses a seeded rng(seeded with a bip39 seed) to generate a private key. With this system the user first creates, or restores, a bip39 seed phrase when they first register. I could then AES encrypt the indentity and secp256k1 keys and save it in a cookie/local storage. Then when a user returns on the same system have them enter their pass phrase to decrypt the stored keys. In the event that they need to restore on any other system they simply need to remember their mnemonic phrase.
For anyone who may be interested I wrote an RSA implemention which uses a rng that is seeded by a bip39 seed. That same seed can easily be used to generate the secp256k1 keys as well. It is located here: https://github.com/nomadcrypto/seededrsa and can be used with ipfs like this:
This isn’t a solution to the OP’s problem, but I would like to save people who end up here from Google like me.
PSA: If you want to maintain a constant identity across tabs and page refreshes, just use a fixed repo name when initializing your IPFS node in the browser and it will happen automatically.