pub trait MnemonicBuilder {
    type Mnemonic;
    type Language;
    type MnemonicType;
    type ErrorType;

    // Required methods
    fn new() -> Self;
    fn mnemonic_seed(&mut self, seed: &Seed) -> &mut Self;
    fn mnemonic_phrase(&mut self, mnemonic_phrase: &str) -> &mut Self;
    fn language(&mut self, language: Self::Language) -> &mut Self;
    fn passphrase(&mut self, passphrase: &str) -> &mut Self;
    fn mnemonic_type(&mut self, mnemonic_type: Self::MnemonicType) -> &mut Self;
    fn detect_language(&mut self) -> &mut Self;
    fn build(&self) -> Result<Self::Mnemonic, Self::ErrorType>;
    fn restore(&self) -> Result<Self::Mnemonic, Self::ErrorType>;
    fn generate(&self) -> Result<Self::Mnemonic, Self::ErrorType>;
}
Expand description

Provides a builder pattern for creating a Mnemonic.

Required Associated Types§

type Mnemonic

The associated Mnemonic struct

type Language

The associated Language struct

type MnemonicType

The associated MnemonicType struct

type ErrorType

The type of error that can be returned by the builder

Required Methods§

fn new() -> Self

Creates a new builder struct with default values.

The default values depend on the implementation of the builder.

fn mnemonic_seed(&mut self, seed: &Seed) -> &mut Self

Specifies the seed from which the mnemonic struct is recovered.

If a passphrase is specified with the passphrase method, the seed recovered using the restore or build method will be the encrypted version of the seed which takes into account the passphrase value.

fn mnemonic_phrase(&mut self, mnemonic_phrase: &str) -> &mut Self

Specifies the mnemonic phrase from which the mnemonic struct is recovered.

fn language(&mut self, language: Self::Language) -> &mut Self

Specifies the language for the mnemonic phrase, can be used when recovering a mnemonic phrase or generating a new mnemonic phrase.

fn passphrase(&mut self, passphrase: &str) -> &mut Self

Specifies a passphrase to use to offset/encrypt the seed recovered from the mnemonic phrase.

fn mnemonic_type(&mut self, mnemonic_type: Self::MnemonicType) -> &mut Self

Specifies the mnemonic type to use when recovering or generating a mnemonic phrase.

fn detect_language(&mut self) -> &mut Self

Sets the specified language to None.

When used with mnemonic_phrase and build or restore, automatically detects the language of the mnemonic phrase and returns an error if the mnemonic phrase is invalid for every mnemonic language wordlist.

fn build(&self) -> Result<Self::Mnemonic, Self::ErrorType>

Builds a mnemonic struct given the specifications provided to the builder.

build() can be used in place of generate() or restore() and will emulate the appropriate behavior based on the specifications provided to the builder.

fn restore(&self) -> Result<Self::Mnemonic, Self::ErrorType>

Restore a previously used mnemonic based on the given specifications.

Will return an error in cases that not enough information was provided to restore the mnemonic or if any provided specifications conflict with each other.

fn generate(&self) -> Result<Self::Mnemonic, Self::ErrorType>

Generate a new mnemonic which follows the provided specifications.

Implementations on Foreign Types§

source§

impl MnemonicBuilder for Bip39MnemonicBuilder

source§

fn new() -> Bip39MnemonicBuilder

Creates a new Bip39MnemonicBuilder struct with default values.

source§

fn detect_language(&mut self) -> &mut Bip39MnemonicBuilder

Sets the specified language to None.

Useful for overriding the default English language assumption when using a mnemonic phrase in a non-English language without needing to specify which language the mnemonic phrase is in.

When used with mnemonic_phrase and build or restore, automatically detects the language of the mnemonic phrase and returns an error if the mnemonic phrase is invalid for every mnemonic language wordlist.

source§

fn generate( &self ) -> Result<<Bip39MnemonicBuilder as MnemonicBuilder>::Mnemonic, <Bip39MnemonicBuilder as MnemonicBuilder>::ErrorType>

Generate a new mnemonic which follows given specifications

source§

fn build( &self ) -> Result<<Bip39MnemonicBuilder as MnemonicBuilder>::Mnemonic, <Bip39MnemonicBuilder as MnemonicBuilder>::ErrorType>

Build a mnemonic struct based on the specifications provided

§

type ErrorType = Error

§

type Language = Bip39Language

§

type Mnemonic = Bip39Mnemonic

§

type MnemonicType = Bip39MnemonicType

source§

fn mnemonic_seed(&mut self, seed: &Seed) -> &mut Bip39MnemonicBuilder

source§

fn mnemonic_phrase( &mut self, mnemonic_phrase: &str ) -> &mut Bip39MnemonicBuilder

source§

fn language( &mut self, language: <Bip39MnemonicBuilder as MnemonicBuilder>::Language ) -> &mut Bip39MnemonicBuilder

source§

fn passphrase(&mut self, passphrase: &str) -> &mut Bip39MnemonicBuilder

source§

fn mnemonic_type( &mut self, mnemonic_type: <Bip39MnemonicBuilder as MnemonicBuilder>::MnemonicType ) -> &mut Bip39MnemonicBuilder

source§

fn restore( &self ) -> Result<<Bip39MnemonicBuilder as MnemonicBuilder>::Mnemonic, <Bip39MnemonicBuilder as MnemonicBuilder>::ErrorType>

Implementors§