Struct iop_keyvault::Bip39 [−][src]
Tool for generating, validating and parsing BIP39 phrases in different supported languages.
Implementations
impl Bip39
[src]
pub const MNEMONIC_WORDS: usize
[src]
Number of words in the BIP39 mnemonics we accept and generate
pub fn generate_entropy() -> Result<[u8; 32]>
[src]
Creates the right sized entropy using the CSPRNG available on the platform.
pub fn new() -> Self
[src]
Creates a new English BIP39 phrase handler
pub fn language(lang: Bip39Language) -> Self
[src]
Creates a new BIP39 phrase handler with the given language
pub fn language_code(code: impl AsRef<str>) -> Result<Self>
[src]
Creates a new BIP39 phrase handler with the given language code
Example
let bip39 = Bip39::language_code("fr").unwrap(); assert!(bip39.check_word("aménager"));
pub fn generate(self) -> Bip39Phrase
[src]
Creates a new phrase from hardware entropy. Cannot be used from WASM because it uses the system random generator.
Example
let phrase: &str = Bip39::language_code("fr").unwrap().generate().as_phrase(); let seed: Seed = Bip39::new().generate().password("");
pub fn check_word(self, word: &str) -> bool
[src]
Checks if a word is present in the BIP39 dictionary
Example
let bip39 = Bip39::new(); assert!(bip39.check_word("abandon")); assert!(!bip39.check_word("Abandon")); assert!(!bip39.check_word("avalon"));
pub fn list_words(self, prefix: impl AsRef<str>) -> &'static [&'static str]
[src]
Lists all words in the BIP39 dictionary, which start with the given prefix.
Can be used in 3 different ways:
- When the prefix is empty, the sorted list of all words are returned
- When the prefix is a partial word, the returned list can be used for auto-completion
- When the returned list is empty, the prefix is not a valid word in the dictionary
Example
let bip39 = Bip39::language(Bip39Language::English); assert_eq!(bip39.list_words("").len(), 2048); assert_eq!(bip39.list_words("woo"), ["wood", "wool"]); assert!(bip39.list_words("woof").is_empty());
pub fn validate(self, phrase: impl AsRef<str>) -> Result<()>
[src]
Validates a whole BIP39 mnemonic phrase. Because the phrase contains some checksum, the whole phrase can be invalid even when each word itself is valid.
Example
let bip39 = Bip39::new(); assert!(bip39.validate("type shield target dream feature surface search flee tenant cake taxi shrug").is_ok()); assert!(bip39.validate("abandon abandon about").unwrap_err().to_string().contains("invalid number of words"));
pub fn phrase(self, phrase: impl AsRef<str>) -> Result<Bip39Phrase>
[src]
Validates a whole BIP39 mnemonic phrase and returns an intermediate object that can be
later converted into a Seed
with an optional password.
pub fn short_phrase(self, phrase: impl AsRef<str>) -> Result<Bip39Phrase>
[src]
Use the phrase
method whenever possible. This method allows some legacy use-cases to
provide mnemonics shorter than MNEMONIC_WORDS
words.
pub fn entropy(self, entropy: impl AsRef<[u8]>) -> Result<Bip39Phrase>
[src]
Creates a BIP39 phrase based on the 256 bits of entropy provided. This method is needed from WASM
because [generate
] uses system resources unavailable from WASM.
pub fn short_entropy(self, entropy: impl AsRef<[u8]>) -> Result<Bip39Phrase>
[src]
Use the [‘entropy’] method whenever possible. This method allows some legacy use-cases to provide mnemonics with low entropy.
Trait Implementations
impl Clone for Bip39
[src]
impl Copy for Bip39
[src]
impl Debug for Bip39
[src]
impl Default for Bip39
[src]
Auto Trait Implementations
impl RefUnwindSafe for Bip39
impl Send for Bip39
impl Sync for Bip39
impl Unpin for Bip39
impl UnwindSafe for Bip39
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,