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 mnemonic generation for new wallets #1635

Merged
merged 22 commits into from
Apr 29, 2024
Merged

Add mnemonic generation for new wallets #1635

merged 22 commits into from
Apr 29, 2024

Conversation

joshuef
Copy link
Contributor

@joshuef joshuef commented Apr 22, 2024

Description

reviewpad:summary

@@ -591,15 +591,31 @@
}

/// Loads a serialized wallet from a path.
// TODO: what's the behaviour here if path has stored key and we pass one in?

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
@joshuef
Copy link
Contributor Author

joshuef commented Apr 22, 2024

Rebased #1438 atop main and then linked it in to wallet generation w/ optional passphrase.

I think this gets us going and we can improve things atop this.

@joshuef joshuef force-pushed the mnemonic branch 2 times, most recently from 4057b2b to 6b120d0 Compare April 22, 2024 03:30
@joshuef joshuef changed the title feat(cli): eip2333 helpers for accounts Add mnemonic generation for new wallets Apr 22, 2024
@JasonPaulGithub JasonPaulGithub added the Large Large sized PR label Apr 22, 2024
@joshuef joshuef force-pushed the mnemonic branch 5 times, most recently from acf661f to 18a2b2a Compare April 23, 2024 05:38
@maqi maqi force-pushed the mnemonic branch 2 times, most recently from a46b58b to 0546831 Compare April 23, 2024 15:34
@joshuef joshuef force-pushed the mnemonic branch 2 times, most recently from 89b52ef to 24d158c Compare April 24, 2024 02:44
@joshuef
Copy link
Contributor Author

joshuef commented Apr 24, 2024

This is not working on initial testnets, so some debugging to do here

#[allow(dead_code)] // as yet unused, will be used soon
/// Derive an xorname from the mnemonic for the account to store data.
pub(crate) fn account_root_xorname(mnemonic: bip39::Mnemonic, passphrase: &str) -> Result<XorName> {
let seed = mnemonic.to_seed(passphrase);
Copy link
Member

Choose a reason for hiding this comment

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

shall put the following block of code into a separate private helper function, then be used by both account_wallet_secret_key and account_root_xorname functions:

fn derived_key_bytes(mnemonic, passphrase) -> {
    let seed = mnemonic.to_seed(passphrase);
    let root_sk =
        eip2333::derive_master_sk(&seed).map_err(|_err| Error::InvalidMnemonicSeedPhrase)?;
    let derived_key = eip2333::derive_child_sk(root_sk, ACCOUNT_WALLET_DERIVATION);
    derived_key.serialize()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

honestly not sure on this, purely because the return type is... large.

sn_client/src/event.rs Show resolved Hide resolved
sn_faucet/src/faucet_server.rs Show resolved Hide resolved
sn_faucet/src/faucet_server.rs Show resolved Hide resolved
sn_faucet/src/faucet_server.rs Outdated Show resolved Hide resolved
@@ -203,6 +216,19 @@ async fn respond_to_gift_request(
key: String,
semaphore: Arc<Semaphore>,
) -> std::result::Result<impl Reply, std::convert::Infallible> {
let faucet_root = get_faucet_data_dir();
Copy link
Member

Choose a reason for hiding this comment

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

maybe this block of loading wallet code can be a separate private helper function?
seems appeared duplicatedly couple of times

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's only twice in that file, not sure it's necessary atm.

Ok(key) => {
if let Some(passed_key) = main_key {
if key.secret_key() != passed_key.secret_key() {
warn!("main_key passed to load_from_path_and_key, but a key was found in the wallet dir. Using the one found in the wallet dir.");
Copy link
Member

Choose a reason for hiding this comment

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

sounds bit risky.
shall we raise an error and terminate the work instead ?
if user do forgot main_key, he can still continue by passing down a None ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was debating this, I think it's a follow up. Changing the internal load fn to not do this and error is like 80% of this PR, so not super keen to start in on more in this :D

@maqi maqi enabled auto-merge April 29, 2024 09:29
@maqi maqi added this pull request to the merge queue Apr 29, 2024
Merged via the queue into maidsafe:main with commit 1cc37d4 Apr 29, 2024
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Large Large sized PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants