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

Enable rust-bip39 "rand" feature on bip39 (optional) dependency. #1546

Open
NicolaLS opened this issue Aug 9, 2024 · 2 comments
Open

Enable rust-bip39 "rand" feature on bip39 (optional) dependency. #1546

NicolaLS opened this issue Aug 9, 2024 · 2 comments
Labels
new feature New feature or request

Comments

@NicolaLS
Copy link

NicolaLS commented Aug 9, 2024

Describe the enhancement
Enable rust-bip39 rand feature by default or using another feature on bdk_wallet. This will make generate_with_in method available.

Use case
Provide the full API of rust-bip39 for developers that want to use bdk_wallet to crate bip39 mnemonics and don't want to worry about creating the entropy themselves. Instead of having to implement logic to create some entropy from 12-24 words, developers could use bdk_wallet::keys::bip39::Mnemonic::generate_in_with(&mut rng, Language::English, 24).

Additional context

  • bdk_wallet re-exports rust-bip39 but does not provide its full functionality because rust-bip39 made rand_core and rand optional dependencies in this commit.
  • bdk_wallet already depends on rand_core (0.6.0)

Suggested solution
Either enable rand per default:

# Optional dependencies
bip39 = { version = "2.0", optional = true features = ["rand"]}

Or enable it with another feature:

[features]
keys-bip39 = ["bip39"]
keys-bip39-rand = ["bip39/rand"]
@NicolaLS NicolaLS added the new feature New feature or request label Aug 9, 2024
@storopoli
Copy link
Contributor

Related to #1395.

@ValuedMammal
Copy link
Contributor

ValuedMammal commented Aug 29, 2024

I think it's possible to have the equivalent of generate_in_with currently in BDK (assuming "keys-bip39" and "std" features are enabled)

fn main() {
    use bdk_wallet::bip39::Mnemonic;
    use bdk_wallet::bitcoin::key::rand::thread_rng;
    use bdk_wallet::keys::bip39::{Language, WordCount};
    use bdk_wallet::keys::{GeneratableKey, GeneratedKey};
    use bdk_wallet::miniscript::Tap;

    let mnemonic: GeneratedKey<Mnemonic, Tap> = Mnemonic::generate_with_aux_rand(
        (WordCount::Words12, Language::English),
        &mut thread_rng(),
    )
    .expect("should work");

    println!("{}", *mnemonic);
}

But since this is not immediately obvious, I'm also in favor of enabling bip39/rand_core by default, so something like

[features]
keys-bip39 = ["bip39/rand_core"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request
Projects
Status: Discussion
Development

No branches or pull requests

3 participants