Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

scx1332
Copy link

@scx1332 scx1332 commented Jul 5, 2023

For some implementations it's useful feature, when you store your keys in keystore, but also you want possibility of getting plain private key.

@scx1332
Copy link
Author

scx1332 commented Jul 6, 2023

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.

Copy link
Owner

@tomusdrw tomusdrw left a 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.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//Do not print private key in that way in production code
// Do not print private key in that way in production code!

Comment on lines +125 to +126
/// Export stored, unencrypted, plain private key, use with caution
/// Do not expose this key in logs, etc. Use only if needed
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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] {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants