Ejemplo n.º 1
0
        /// <summary>
        /// Sets hybrid Bip32 / Bip39 private key.
        /// Uses only a single Bip32 style use of HMACSHA512 starting with at least 32 bytes of Bip39 entropy from mnemonicWords.
        /// </summary>
        /// <param name="mnemonicWords">Must be at least 32 bytes of Bip39 mnemonic word entropy with valid checksum.</param>
        /// <param name="required">if not null, each key path will be verified as valid on the generated key or returns null.</param>
        /// <param name="hmacKey">Default is current global Kz.MasterBip32Key which may default to "Bitcoin seed".</param>
        /// <returns>Returns this key unless required key paths aren't valid for generated key.</returns>
        public ExtPrivateKey SetMasterBip32(string mnemonicWords, IEnumerable <KeyPath> required = null, string hmacKey = null)
        {
            var e = Mnemonic.FromWords(mnemonicWords).Entropy;

            if (e == null || e.Length < 32)
            {
                throw new ArgumentException($"{nameof(mnemonicWords)} must provide at least 32 bytes of BIP39 mnemonic entropy.");
            }
            return(SetMasterBip32(e, required, hmacKey));
        }
Ejemplo n.º 2
0
        public void Constructors()
        {
            var words = "afirmar diseño hielo fideo etapa ogro cambio fideo toalla pomelo número buscar";
            var m1    = new Mnemonic(words);

            Assert.Equal(Languages.Spanish, m1.Language);
            Assert.Equal(m1.Words, Mnemonic.FromWords(words).Words);

            var m2 = new Mnemonic(m1.Entropy, m1.Language);

            Assert.Equal(m1.Words, m2.Words);
            Assert.Equal(m2.Words, Mnemonic.FromEntropy(m1.Entropy, m1.Language).Words);

            var m3 = new Mnemonic(new byte[] { 5, 40, 161, 175, 172, 69, 19, 67, 74, 26, 196, 233, 87, 10, 119, 18 }, Languages.Spanish);

            Assert.Equal(m1.Words, m3.Words);

            var m4 = new Mnemonic(bitLength: 256);

            Assert.Equal(24, m4.Words.Split(' ').Length);
            Assert.Equal(24, Mnemonic.FromLength(256).Words.Split(' ').Length);
        }