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

Add support for wallet import via private key #215

Open
zees-dev opened this issue Oct 23, 2024 · 4 comments
Open

Add support for wallet import via private key #215

zees-dev opened this issue Oct 23, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request forc-wallet good first issue Good for newcomers

Comments

@zees-dev
Copy link
Contributor

Context

Currently forc wallet import only supports importing wallet(s) via mnemonic.
Private keys are commonly used to more easily transfer accounts across wallets; hence it should also be supported here.

Current behaviour of forc wallet import:

> forc wallet import

Please enter your mnemonic phrase:  

Proposed behaviour:

> forc wallet import

Please enter your mnemonic phrase or private key:

This solution retains the simplicity of the current flow while supporting importing accounts via both mnemonic and private-key - without introducing additional flags.

@zees-dev zees-dev self-assigned this Oct 23, 2024
@zees-dev zees-dev added enhancement New feature or request good first issue Good for newcomers forc-wallet labels Oct 23, 2024
@tusharnagar17
Copy link

Hi @zees-dev,
Could you please assign this issue to me?

@zees-dev zees-dev assigned tusharnagar17 and unassigned zees-dev Oct 24, 2024
@zees-dev
Copy link
Contributor Author

Hi @zees-dev, Could you please assign this issue to me?

This seems to be quite useful functionality; hence will be revisited in ~1-2 weeks for checking progress.
Nevertheless thanks for picking this up! 👍

@tusharnagar17
Copy link

Hi @zees-dev,
I'm working on this functionality

While passing hardcoded private_key in eth_keystore::encrypt_key.
It will save correctly without any error

let hex_string = "bb01503b7133531412c7f0f7bc040d5c7ae2377dc772c2b020d010651f4a4f3a";
   let private_key_bytes = hex::decode(hex_string).expect("Invalid hex string");

   // Encrypt and write the wallet file.
   eth_keystore::encrypt_key(
       wallet_dir,
       &mut rand::thread_rng(),
       &private_key_bytes,
       password,
       Some(wallet_file_name),
   )
   .with_context(|| format!("failed to create keystore at {wallet_path:?}"))
   .map(|_| ())
}

but while accessing private-key or public-key

cargo run -- account 0 public-key
  • getting this error
error: invalid utf-8 sequence of 1 bytes from index 0

NOTE: this functionality working correctly with mnemonics:

Have any idea regarding this?

@zees-dev
Copy link
Contributor Author

zees-dev commented Nov 3, 2024

Hi @zees-dev, I'm working on this functionality

While passing hardcoded private_key in eth_keystore::encrypt_key. It will save correctly without any error

let hex_string = "bb01503b7133531412c7f0f7bc040d5c7ae2377dc772c2b020d010651f4a4f3a";
   let private_key_bytes = hex::decode(hex_string).expect("Invalid hex string");

   // Encrypt and write the wallet file.
   eth_keystore::encrypt_key(
       wallet_dir,
       &mut rand::thread_rng(),
       &private_key_bytes,
       password,
       Some(wallet_file_name),
   )
   .with_context(|| format!("failed to create keystore at {wallet_path:?}"))
   .map(|_| ())
}

but while accessing private-key or public-key

cargo run -- account 0 public-key
  • getting this error
error: invalid utf-8 sequence of 1 bytes from index 0

NOTE: this functionality working correctly with mnemonics:

Have any idea regarding this?

Unfortunately don't have an answer to this at the moment since this would most likely entail changes to other parts of the codebase.

When using mnemonic based account creation/import; a single mnemonic generates a master seed following BIP-39 - which can then be used to derive multiple child keys/accounts; this is the account index param you will see being used.

When using private key for importing; it's not designed to be used as a seed for generating other accounts/keys.
A single private key generates a single account.

^ Due to this; the task is most likely not a good first issue and requires additional planning to retain a good UX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request forc-wallet good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants