Beispiel #1
0
 public void TestCases()
 {
     foreach (var tv in _testValues)
     {
         tv.Entropy.HexToBytes();
         var mnemonic = new Mnemonic(tv.Words, Languages.English);
         Assert.NotNull(mnemonic); // If checksum doesn't match returns null.
         var seed      = new UInt512(tv.Seed, true);
         var seedBip39 = ExtPrivateKey.Bip39Seed(tv.Words, "TREZOR");
         Assert.Equal(seed, seedBip39);
         var privkeyFromWords = ExtPrivateKey.MasterBip39(tv.Words, "TREZOR");
         var privkeyFromB58   = new Base58ExtPrivateKey(tv.B58Priv).GetKey();
         Assert.Equal(privkeyFromB58, privkeyFromWords);
     }
 }
Beispiel #2
0
        public void TestCases()
        {
            foreach (var tv in _testVectors)
            {
                var seed = tv.MasterSeed.HexToBytes();
                var m    = ExtPrivateKey.MasterBip32(seed);

                foreach (var d in tv.Derivations)
                {
                    var path = new KeyPath(d.Path);
                    var priv = m.Derive(path);
                    var pub  = priv.GetExtPublicKey();

                    var strPriv = priv.ToString();
                    var strPub  = pub.ToString();
                    Assert.Equal(d.PrivateKey, strPriv);
                    Assert.Equal(d.PublicKey, strPub);

                    var data = new byte[ExtKey.Bip32KeySize];
                    priv.Encode(data);
                    pub.Encode(data);

                    // Test private key
                    var b58Key = new Base58ExtPrivateKey();
                    b58Key.SetKey(priv);
                    Assert.Equal(d.PrivateKey, b58Key.ToString());

                    var b58KeyDecodeCheck = new Base58ExtPrivateKey(d.PrivateKey);
                    var checkKey          = b58KeyDecodeCheck.GetKey();
                    // ensure a base58 decoded pubkey also matches
                    Assert.Equal(checkKey, priv);

                    if (priv.Hardened == false && path.Parent != null)
                    {
                        // Compare with public derivation
                        var pubkeyNew2 = m.Derive(path.Parent).GetExtPublicKey().Derive((int)path.Last());
                        Assert.True(pubkeyNew2 != null);
                        Assert.Equal(pub, pubkeyNew2);
                    }
                }
            }
        }