-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Storage: implement keypair read/write #18
Conversation
src/storage/mod.rs
Outdated
use super::*; | ||
use crypto::generate_keypair; | ||
use sha2::Sha512; | ||
use ed25519_dalek::{Keypair}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seemed right to avoid an unused import, let me know if there's a better way!
src/storage/mod.rs
Outdated
let message: &[u8] = "Hello world".as_bytes(); | ||
let sig: Signature = keypair.sign::<Sha512>(&message); | ||
|
||
assert!(readen_keypair.verify::<Sha512>(&message, &sig), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that it'd be a good idea to verify
with a signature from the original keypair. What's weird is that rust tells me that this is a bool
although a test is done with is_ok
in the ed25519 library.
I also thought about comparing the two array of bytes ([u8; KEYPAIR_LENGTH]
) but I haven't found any elegant way of doing it!
@soyuka would you mind running |
@soyuka hmmm, bit of a bigger thing here - but did you see that a couple of weeks ago we moved from storing a single keypair to storing the Could we perhaps duplicate this code so we have 1 for the public key, and 1 for secret key. In the Node.js version of Dat, these are then stored on disk as Really liking the code so far though; looks like this is definitely the right direction! 😁 |
fa73d29
to
816a2e7
Compare
OMG sorry haha, this is the commit that lead me to read the code and find that todo 🤦♂️. Second commit is a cherry-pick from #19 :) I guess that we have to figure out of to use this feature inside the feed?
|
Yeah, sounds reasonable! :D |
2ef39dc
to
1ae4332
Compare
src/feed_builder.rs
Outdated
storage, | ||
public_key, | ||
secret_key: None, | ||
pub fn new(public_key: Option<PublicKey>, mut storage: Storage<T>) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really not sure if we'd want the logic here or directly in the Feed. It also feels weird to have an Option
as first argument but I wanted to avoid a BC break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is a BC break?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Backward compatibility break, but I then realized that I had change the public_key
signature so my code is breaking the backward compatibility promise. Anyway I think that it's a bit early into the project to care about such things 😅.
I changed the status to wip :p. I'll add more tests to the FeedBuilder if you agree with the implementation! |
src/feed_builder.rs
Outdated
public_key, | ||
secret_key: None, | ||
}, | ||
Err(_) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, do you think there's a way we can move this out to FeedBuilder
? Maybe it's just me, but I wouldn't expect the keys to be generated inside storage.rs
. I feel keeping the initialization logic strictly inside FeedBuilder
might make it the easiest to reason about, even if it adds a bit code. Does that... make sense?
I'm not sure what the right approach is instead. Perhaps an intermediate struct that can be "half-open" and tries to read the key, and then has a method to indicate whether or not it has a public key set on it? e.g.
- initialize instance
- check if it has a key on it
- if it doesn't have a key, set a key
- finalize initialization
- all operations are now available
I really don't know haha, I think it needs a little bit of experimentation. Or maybe I'm wrong here and it like doesn't make any sense at all? I'm really keen to hear your opinion on this because I'm very unsure, haha.
@soyuka also I wanted to mention I super appreciate all the work you're putting into this! This patch is shaping up to be really good; thanks for doing all this! ❤️ |
713145f
to
81e8cb1
Compare
I've moved out the code from the builder and it indeed looks cleaner. To go further, I'd like to propose the following signature for the FeedBuilder: /// Create a new instance.
#[inline]
pub fn new(storage: Storage<T>, public_key: PublicKey, secret_key: Option<SecretKey>) -> Self {
Self {
storage,
public_key,
secret_key
}
} I don't really understand the need for a
Kind words ❤️! I'm really enjoying this especially that I'm learning rust and reading/writing code is my way of doing it! Thanks to you for giving me the motivation/opportunity through this project :). |
I was thinking that we could specialize our struct based on which arguments are passed in. E.g. all optional arguments are called as methods on the builder. It's something I'd prefer to have for the resulting API because I think it's really clean. That said I'm cool with changing the API in the meantime. If this can help us get key storage faster, |
81e8cb1
to
2935cb1
Compare
d6847bc
to
4ac34a6
Compare
I think that the implementation is good now:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really really good! Thanks so much! :D
Signed-off-by: abluchet <[email protected]>
Signed-off-by: abluchet <[email protected]>
4ac34a6
to
adc5b1f
Compare
Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay!
🙋 feature
I've implemented two new functions:
read_keypair
andwrite_keypair
in the Storage implementation.As I'm fairly new to rust I have a few unsure things (see comments) and am open to corrections!
Notable change: I've remove the unimplemented
open_key
method as I guessed that you wanted to do what I did :).Checklist
generate and store
?)Context
#16
Semver Changes
patch