Ejemplo n.º 1
0
        public void CanDetectBadChecksum()
        {
            var mnemonic = new MnemonicSequence("turtle front uncle idea crush write shrug there lottery flower risk shell", WordList.English);

            Assert.True(mnemonic.IsValidChecksum);
            mnemonic = new MnemonicSequence("front front uncle idea crush write shrug there lottery flower risk shell", WordList.English);
            Assert.False(mnemonic.IsValidChecksum);
        }
Ejemplo n.º 2
0
        private void CanCheckBIP39TestVectorsCore(string file, WordList wordList)
        {
            var tests = JArray.Parse(File.ReadAllText($"Data/bip39_vectors.{file}.json"));

            foreach (var test in tests.Children().OfType <JObject>())
            {
                var mnemonic = new MnemonicSequence(test["mnemonic"].Value <string>(), wordList);
                var actual   = mnemonic.DeriveExtKey(test["passphrase"].Value <string>()).GetWif(Network.Main);
                var expected = new BitcoinExtKey(test["bip32_xprv"].Value <string>(), Network.Main);
                Assert.Equal(actual, expected);
            }
        }
Ejemplo n.º 3
0
        public void EngTest()
        {
            var test = JObject.Parse(File.ReadAllText("Data/bip39_vectors.json"));

            foreach (var language in test.Properties())
            {
                var lang = GetList(language.Name);
                foreach (var langTest in ((JArray)language.Value).OfType <JArray>().Take(2))
                {
                    var    entropy     = Encoders.Hex.DecodeData(langTest[0].ToString());
                    string mnemonicStr = langTest[1].ToString();
                    string seed        = langTest[2].ToString();
                    var    mnemonic    = new MnemonicSequence(mnemonicStr, lang);
                    Assert.True(mnemonic.IsValidChecksum);
                    Assert.Equal(seed, Encoders.Hex.EncodeData(mnemonic.DeriveSeed("TREZOR")));

                    mnemonic = new MnemonicSequence(lang, entropy);
                    Assert.True(mnemonic.IsValidChecksum);
                    Assert.Equal(seed, Encoders.Hex.EncodeData(mnemonic.DeriveSeed("TREZOR")));
                }
            }
        }
Ejemplo n.º 4
0
        public void JapTest()
        {
            var test = JArray.Parse(File.ReadAllText("Data/bip39_JP.json", Encoding.UTF32));

            foreach (var unitTest in test.OfType <JObject>())
            {
                var    entropy     = Encoders.Hex.DecodeData(unitTest["entropy"].ToString());
                string mnemonicStr = unitTest["mnemonic"].ToString();
                string seed        = unitTest["seed"].ToString();
                string passphrase  = unitTest["passphrase"].ToString();
                var    mnemonic    = new MnemonicSequence(mnemonicStr, WordList.Japanese);
                Assert.True(mnemonic.IsValidChecksum);
                Assert.Equal(seed, Encoders.Hex.EncodeData(mnemonic.DeriveSeed(passphrase)));
                var bip32       = unitTest["bip32_xprv"].ToString();
                var bip32Actual = mnemonic.DeriveExtKey(passphrase).ToString(Network.Main);
                Assert.Equal(bip32, bip32Actual.ToString());
                mnemonic = new MnemonicSequence(WordList.Japanese, entropy);
                Assert.True(mnemonic.IsValidChecksum);
                bip32Actual = mnemonic.DeriveExtKey(passphrase).ToString(Network.Main);
                Assert.Equal(bip32, bip32Actual.ToString());
            }
        }