示例#1
0
        /// <summary>
        /// Generate a mnemonic
        /// </summary>
        /// <param name="wordList"></param>
        /// <param name="entropy"></param>
        public Mnemonic(Wordlist wordList, byte[] entropy = null)
        {
            wordList  = wordList ?? Wordlist.English;
            _WordList = wordList;
            if (entropy == null)
            {
                entropy = RandomUtils.GetBytes(32);
            }

            var i = Array.IndexOf(entArray, entropy.Length * 8);

            if (i == -1)
            {
                throw new ArgumentException("The length for entropy should be : " + String.Join(",", entArray), "entropy");
            }

            int cs = csArray[i];

            byte[]    checksum    = Hashes.SHA256(entropy);
            BitWriter entcsResult = new BitWriter();

            entcsResult.Write(entropy);
            entcsResult.Write(checksum, cs);
            _Indices  = entcsResult.ToIntegers();
            _Words    = _WordList.GetWords(_Indices);
            _Mnemonic = _WordList.GetSentence(_Indices);
        }
示例#2
0
		/// <summary>
		/// Generate a mnemonic
		/// </summary>
		/// <param name="wordList"></param>
		/// <param name="entropy"></param>
		public Mnemonic(Wordlist wordList, byte[] entropy = null)
		{
			wordList = wordList ?? Wordlist.English;
			_WordList = wordList;
			if(entropy == null)
				entropy = RandomUtils.GetBytes(32);

			var i = Array.IndexOf(entArray, entropy.Length * 8);
			if(i == -1)
				throw new ArgumentException("The length for entropy should be : " + String.Join(",", entArray), "entropy");

			int cs = csArray[i];
			byte[] checksum = Hashes.SHA256(entropy);
			BitWriter entcsResult = new BitWriter();

			entcsResult.Write(entropy);
			entcsResult.Write(checksum, cs);
			_Indices = entcsResult.ToIntegers();
			_Words = _WordList.GetWords(_Indices);
			_Mnemonic = _WordList.GetSentence(_Indices);
		}
示例#3
0
		public string ToString(Wordlist wordlist)
		{
			return wordlist.GetSentence(WordIndices);
		}
示例#4
0
 public string ToString(Wordlist wordlist)
 {
     return(wordlist.GetSentence(WordIndices));
 }