Esempio n. 1
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);
                    }
                }
            }
        }