Open zees-dev opened 3 weeks ago
Hi @zees-dev, Could you please assign this issue to me?
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! 👍
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
error: invalid utf-8 sequence of 1 bytes from index 0
NOTE: this functionality working correctly with mnemonics
:
Have any idea regarding this?
Hi @zees-dev, I'm working on this functionality
While passing hardcoded
private_key
ineth_keystore::encrypt_key
. It will save correctly without any errorlet 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
orpublic-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.
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
:Proposed behaviour:
This solution retains the simplicity of the current flow while supporting importing accounts via both mnemonic and private-key - without introducing additional flags.