Skip to content

[Feature] Enable MnenomicBuilder to use default source of randomness (rand) #294

@zerosnacks

Description

@zerosnacks

Component

signers

Describe the feature you would like

As rand is not exported by Alloy - nor do I think it should - users are now required to import it themselves to use as source of randomness for build_random(&mut rng) as there is no default implementation.

// NOTE: `rand` is not exported anymore, now private.
use rand;

// Generate a random wallet (24 word phrase) at custom derivation path
let mut rng = rand::thread_rng();
let wallet = MnemonicBuilder::<English>::default()
.word_count(24)
.derivation_path("m/44'/60'/0'/2/1")?
// Optionally add this if you want the generated mnemonic to be written
// to a file
// .write_to(path)
.build_random(&mut rng)?;

Preferable would be a syntax like:

/// Creates a new random keypair seeded with [`rand::thread_rng()`].
#[inline]
pub fn random() -> Self {
Self::random_with(&mut rand::thread_rng())
}
/// Creates a new random keypair seeded with the provided RNG.
#[inline]
pub fn random_with<R: Rng + CryptoRng>(rng: &mut R) -> Self {
Self::from_signing_key(SigningKey::random(rng))
}

With rand being the default.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions