Exemplo n.º 1
0
        private static (Languages language, string[] wordList) GetWordList(string words)
        {
            foreach (var language in EnumExtensions.GetEnumValues <Languages>())
            {
                if (language == Languages.Unknown)
                {
                    continue;
                }
                var wl = WordLists.GetWords(language);
                if (BelongsToWordList(words, wl))
                {
                    return(language, wl);
                }
            }

            return(Languages.Unknown, null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a new KzMnemonic from a sequence of words.
        /// </summary>
        /// <param name="words"></param>
        /// <param name="wordList"></param>
        /// <param name="language"></param>
        public Mnemonic(string words, string[] wordList, Languages language = Languages.Unknown)
        {
            Words = words.Normalize(NormalizationForm.FormKD);
            if (wordList != null)
            {
                Language = language;
                WordList = wordList;
            }
            else if (language != Languages.Unknown)
            {
                Language = language;
                WordList = WordLists.GetWords(Language);
            }
            else
            {
                (Language, WordList) = GetWordList(words);
            }

            Entropy = GetEntropy(Words, WordList);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Create a new KzMnemonic from given Entropy.
 /// </summary>
 /// <param name="entropy">Binary data to encode.</param>
 /// <param name="language">Optional language key to select WordList from WordLists. Defaults to English.</param>
 public Mnemonic(IEnumerable <byte> entropy, Languages language = Languages.English)
     : this(entropy, WordLists.GetWords(language), language)
 {
 }
Exemplo n.º 4
0
 /// <summary>
 /// Create a new KzMnemonic from a desired entropy length in bits.
 /// length should be a multiple of 32.
 /// </summary>
 /// <param name="bitLength">Optional length in bits, default is 128. Should be a multiple of 32.</param>
 /// <param name="language">Optional language to use, default is english.</param>
 public Mnemonic(int bitLength = 128, Languages language = Languages.English)
     : this(bitLength, WordLists.GetWords(language), language)
 {
 }