How to store and load Keypairs?
Hi!
If I understand correctly, I need to save and store Keypairs when writing an application that uses an ipfs node internally. But how do I do that? I do not see any way to encode the keypair to save it to disk and later load it again?
Hope you can help!
To be honest I haven't kept up at what facilities are already implemented in latest rust-libp2p -- I would suspect there are some. We implemented it for the RSA keys for the format used by go-ipfs when this project was last active under the http/. However, RSA keys are no longer the popular ones and very difficult to generate.
While providing tools for at least the en/decoding of secrets makes a lot of sense, or even semi-reasonable higher level secret management, it was not part of the grant work done on this project for it being needed near of "escaping the alpha stage" after having become useful as a library, which I don't think it is at the moment. And as such, not a priority on the quite short list of things we could do.
For development purposes the random keys work just fine, and should be preferred not to risk anyone using any keys they use elsewhere accidentially.
it was not part of the grant work done on this project for it being needed near of "escaping the alpha stage" after having become useful as a library, which I don't think it is at the moment.
Do you mean this library is not ready for usage yet? That'd be sad because it seems that this is the only IPFS library that actually seems to be usabe (ipfs-api is not usable at all and ipfs-embed is really hard to use).
Do you mean this library is not ready for usage yet?
Yes, this is the case. We try to be forthcoming with this in the repository README. If you are not interested in developing rust implementation of ipfs but only using an ipfs implementation, you should look into ipfs-api and go-ipfs. I haven't been keeping up on the latest developments on the HTTP API front so I cannot comment on ipfs-api's usability. However, if some API functionality has changed drastically fixing them might not be a huge amount of work.
Go is not an option because it is go and ipfs-api is not usable because its futures are not Send which makes the crate unusable, sadly. Maybe I will have to try out ipfs-embed once more,...
Hi there, rust-libp2p maintainer here.
The story on storing and loading key material is not ideal in rust-libp2p quite yet.
In case you want to load the keymaterial generated from a go-ipfs node, you can use:
https://github.com/mxinden/rust-libp2p-server/blob/7b8dcca6af6c8538785b2ba65b3c3169aa04204f/src/main.rs#L54-L76
I would like to replace https://github.com/libp2p/rust-libp2p/tree/master/misc/peer-id-generator with a command line tool to store and load key material in a go-ipfs style, though I have not yet found the time. Contributions are most welcome.
Hi @mxinden I just stumbled on the necessity of such tool, lol. I'm happy to implement it if you can guide me a bit through the specs and how the current Go tool works.
Great @fabricio7p.
For decoding you would basically just copy the logic here and wrap it in a CLI tool which takes the config path as an input.
https://github.com/mxinden/rust-libp2p-server/blob/7b8dcca6af6c8538785b2ba65b3c3169aa04204f/src/main.rs#L54-L76
Want to create a draft pull request on rust-libp2p? We can discuss encoding over there then.
For the record @demfabris has implemented a keygen tool, see https://github.com/libp2p/rust-libp2p/pull/2453.