diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2020-11-30 12:58:44 +0100 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2020-11-30 12:58:44 +0100 |
| commit | 678d45e7ae09510796d27a80ecd894f6a1ad8279 (patch) | |
| tree | 56e9dc6cc093faadd86da1edebc76334c00b6a74 /src/mnemonic/language.rs | |
| parent | bd7a6880f5dce74fd154f593a5a5f7034affeee4 (diff) | |
generate random mnemonic
Diffstat (limited to 'src/mnemonic/language.rs')
| -rw-r--r-- | src/mnemonic/language.rs | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/mnemonic/language.rs b/src/mnemonic/language.rs index 87950d8..9ed40ca 100644 --- a/src/mnemonic/language.rs +++ b/src/mnemonic/language.rs @@ -1,5 +1,6 @@ //! Mnemonic language for selecting word lists. +use crate::mnemonic::wordlist::{self, Wordlist}; use anyhow::{bail, Result}; use std::{ fmt::{self, Display, Formatter}, @@ -18,19 +19,31 @@ pub enum Language { impl Language { /// Splits a mnemonic phrase into its words, returning the detected language /// and a vector of **normalized** words. - pub fn split(phrase: impl AsRef<str>) -> Result<(Self, Vec<String>)> { + pub fn split(phrase: &str) -> Result<(Self, Vec<&str>)> { // TODO(nlordell): A lot to do here... + let language = Language::English; Ok(( - Language::English, + language, phrase - .as_ref() .trim() .split_whitespace() .filter(|word| !word.is_empty()) - .map(|word| word.to_lowercase()) .collect(), )) } + + /// Returns the language's wordlist. + pub fn wordlist(self) -> &'static Wordlist<'static> { + wordlist::for_language(self) + } + + /// Returns the whitespace separator character for the language. + pub fn separator(self) -> char { + // TODO(nlordell): Languages such as Chinese use a special Unicode + // whitepace character as a word separator for their BIP-0039 mnemonic + // phrase. + ' ' + } } impl Default for Language { @@ -43,7 +56,7 @@ impl Default for Language { impl Display for Language { fn fmt(&self, f: &mut Formatter) -> fmt::Result { f.write_str(match self { - Language::English => "english", + Language::English => "English", }) } } |
