-
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
refactor: move authentication outside the Client
#718
base: next
Are you sure you want to change the base?
Conversation
Client
Client
2d0d0d2
to
7e67c79
Compare
dad3b1b
to
8b87cef
Compare
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.
Nice! Cool that this results in a net loss of lines of code, too.
I left some minor comments, related to docs and naming mostly. I also wonder if we should generalize the CliAuthenticator
into a Keystore
struct to which we are implementing TransactionAuthenticator
. This is because it seems like it handles more responsibilities than just authenticating, and also we might want to add new functionalities to it in the future (such as listing keys, removing them, encrypting/decrypting them, etc.).
bin/miden-cli/src/commands/export.rs
Outdated
Word::from( | ||
account | ||
.storage() | ||
.get_item(1) |
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.
Wouldn't this be index 0 for any non-faucet account?
&account_data.auth_secret_key, | ||
overwrite, | ||
) | ||
.add_account(&account_data.account, account_data.account_seed, overwrite) | ||
.await?; |
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 fine for now but maybe we could add a TODO
here to address potential cases where adding the secret key succeeds, but adding the account fails.
Alternatively, maybe in the future we want to have some sort of "keystore" command that adds/removes keys separately from accounts.
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.
Created an issue for this
authenticator | ||
.add_key(AuthSecretKey::RpoFalcon512(key_pair)) | ||
.map_err(CliError::Authentication)?; |
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.
Same here
bin/miden-cli/src/config.rs
Outdated
@@ -22,6 +22,8 @@ pub struct CliConfig { | |||
pub rpc: RpcConfig, | |||
/// Path to the sqlite store file. |
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.
nit: Not from this PR but while we are at this, let's write this line as follows
/// Path to the sqlite store file. | |
/// Path to the SQLite store file. |
bin/miden-cli/src/config.rs
Outdated
@@ -22,6 +22,8 @@ pub struct CliConfig { | |||
pub rpc: RpcConfig, | |||
/// Path to the sqlite store file. | |||
pub store_filepath: PathBuf, | |||
/// Path to secret keys file. |
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.
nit: Would this be better?
/// Path to secret keys file. | |
/// Path to the directory that contains the secret key files. |
bin/miden-cli/src/errors.rs
Outdated
@@ -21,6 +21,9 @@ pub enum CliError { | |||
#[error("asset error")] | |||
#[diagnostic(code(cli::asset_error))] | |||
Asset(#[source] AssetError), | |||
#[error("authentication error")] |
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.
nit: Maybe I'd generalize this as key store error
, since this is not always authentication-related (for instance, it also manages adding keys to the filesystem)
} | ||
|
||
impl<R: Rng> ClientAuthenticator<R> { | ||
/// Creates a new instance of the authenticator. |
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.
nit: We should mention that this creates the directory if it does not exist (or alternatively we could do it on the doc comments for pub struct ClientAuthenticator<R>
.
}; | ||
use rand::Rng; | ||
|
||
/// An account authenticator that stores keys in the filesystem. |
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.
Could we expand this doc comment mentioning the way that it stores and looks up files? For instance, saying that it's one file per AuthSecretKey
, with a filename that corresponds to the pub key for easy lookups when signatures are requested, etc.
use web_sys::wasm_bindgen::JsValue; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct WebAuthenticator<R> { |
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.
nit: A brief description of what this authenticator uses to store files would be cool.
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.
Also, I think eventually we probably want to add password encryption to the keystore so we might want to add an issue to discuss this (or maybe it's more in the domain of the wallet itself? cc @dagarcia7)
Should we rebase this PR from the latest |
I reviewed the diff again just to be sure but I couldn't find the extraneous changes you mention. There are a lot of changes that were necessary because of the shift in responsibility in public key tracking. Mainly the tests had to be updated so that they have access to the authenticator in case they need to add new keys (which some of them need). |
194f903
to
82a7f31
Compare
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.
minor: we can get rid of this file now. It used to be how I tested things, but now with more formal integration tests for the web client, this is obsolete 👍
Looks great! 💯 Thanks for taking care of the web client changes. I have a quick question. Are there any plans to encrypt the Secret Key before it's put in local storage? And subsequently handle the decryption when retrieving it? I was also wondering if local storage was the best way to store the keys on the web side, but I think given the limitation that the |
I think in the future we will probably make this upgrades. This PR is meant to be a first PoC to see how we could move the keystore responsability out of the client. To upgrade we would only need to change the
Before this PR we used |
closes #637
This PR refactors authentication out of the
Client
. The main idea is that now key tracking is responsability of the authenticator and the addition of new keys is done by the user of the client and not by theClient
itself. TheClient
will only have access to theTransactionAuthenticator::get_signature
function that will be used to sign transactions when needed. If the keys were not added by the client user to the authenticator then this will fail.Authenticator
The authenticator now uses a new
KeyStore
instead of the client'sStore
to get the secret key. This keystore now is created outside the client and is responsability of the client's user to keep it updated with every new key.Keystore
The PR adds two implementations for the keystore:
FilesystemKeyStore
: based on the filesystem. It stores keys as individual files where the name is the public key and the contents are a serializedAuthSecretKey
. It's used by the CLI and by the tests.WebKeySTore
: based on the browser local storage. It stores keys as entries using the Web Storage API. It's used in the web client.Other changes
Store
.TODOs: