-
Notifications
You must be signed in to change notification settings - Fork 22
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
Added optional export of private key #108
base: master
Are you sure you want to change the base?
Added optional export of private key #108
Conversation
Added possibility of exporting key by adding feature export-private-key
I've found that you can hack your key using encrypt and decrypt which returns Vec: let raw_key = secret.to_crypto(password, 1).unwrap().decrypt(password).unwrap(); Still that solution that I posted is more elegant. |
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.
Looks good! I'd appreciate if you could fix minor readme changes and comment on calling the method raw
instead of private
.
We could also change the feature name to expose-raw-private-key
or sth like that?
@@ -2,9 +2,12 @@ | |||
|
|||
A library to read JSON keyfiles and sign Ethereum stuff. | |||
|
|||
Library by defaults hide private key from access, | |||
but you can add --features export-private-key to export it. |
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.
but you can add --features export-private-key to export it. | |
but you can enable `export-private-key` feature to export it. |
@@ -2,9 +2,12 @@ | |||
|
|||
A library to read JSON keyfiles and sign Ethereum stuff. | |||
|
|||
Library by defaults hide private key from access, |
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.
Library by defaults hide private key from access, | |
Library by default hides raw private key from being accessed, |
@@ -21,6 +24,13 @@ fn main() { | |||
let public = signature.recover(&message).unwrap(); | |||
println!("{:?}", public); | |||
|
|||
#[cfg(feature = "export-private-key")] | |||
{ | |||
//Do not print private key in that way in production code |
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.
//Do not print private key in that way in production code | |
// Do not print private key in that way in production code! |
|
||
#[cfg(feature = "export-private-key")] | ||
{ | ||
//Do not print private key in that way in production code |
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.
//Do not print private key in that way in production code | |
// Do not print private key in that way in production code! |
/// Export stored, unencrypted, plain private key, use with caution | ||
/// Do not expose this key in logs, etc. Use only if needed |
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.
/// Export stored, unencrypted, plain private key, use with caution | |
/// Do not expose this key in logs, etc. Use only if needed | |
/// Export stored, unencrypted, plain private key. | |
/// | |
/// USE WITH CAUTION! Do not expose this key in logs, | |
/// etc. Use only if really needed. |
/// Export stored, unencrypted, plain private key, use with caution | ||
/// Do not expose this key in logs, etc. Use only if needed | ||
#[cfg(feature = "export-private-key")] | ||
pub fn private(&self) -> [u8; 32] { |
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.
pub fn private(&self) -> [u8; 32] { | |
pub fn raw(&self) -> [u8; 32] { |
WDYT about calling the function raw
instead of private
? I think it makes sense as it returns the raw key.
For some implementations it's useful feature, when you store your keys in keystore, but also you want possibility of getting plain private key.