Exemplo n.º 1
0
        public void ParseWifStringTest()
        {
            // Compressed: "1E99423A4ED27608A15A2616A2B0E9E52CED330AC530EDCC32C8FFC6A526AEDD";
            var expectedBytes = HexUtilities.HexStringToBytes("801E99423A4ED27608A15A2616A2B0E9E52CED330AC530EDCC32C8FFC6A526AEDD01");
            var input         = "KxFC1jmwwCoACiCAWZ3eXa96mBM6tb3TYzGmf6YwgdGWZgawvrtJ";
            var prvKey        = PrivateKey.CreateFromWifString(input);
            var wifBytes      = prvKey.GetWifBytes();

            Assert.IsTrue(ByteArrayUtilities.CompareByteArrays(expectedBytes, wifBytes));
            var wifString = prvKey.GetWifString();

            Assert.AreEqual(input, wifString);
            Assert.IsTrue(prvKey.WifCompressed);
            Assert.IsFalse(prvKey.TestNet);

            // Compressed (TestNet): "1cca23de92fd1862fb5b76e5f4f50eb082165e5191e116c18ed1a6b24be6a53f";
            expectedBytes = HexUtilities.HexStringToBytes("ef1cca23de92fd1862fb5b76e5f4f50eb082165e5191e116c18ed1a6b24be6a53f01");
            input         = "cNYfWuhDpbNM1JWc3c6JTrtrFVxU4AGhUKgw5f93NP2QaBqmxKkg";
            prvKey        = PrivateKey.CreateFromWifString(input);
            wifBytes      = prvKey.GetWifBytes();
            Assert.IsTrue(ByteArrayUtilities.CompareByteArrays(expectedBytes, wifBytes));
            wifString = prvKey.GetWifString();
            Assert.AreEqual(input, wifString);
            Assert.IsTrue(prvKey.WifCompressed);
            Assert.IsTrue(prvKey.TestNet);

            // Uncompressed: "1E99423A4ED27608A15A2616A2B0E9E52CED330AC530EDCC32C8FFC6A526AEDD";
            expectedBytes = HexUtilities.HexStringToBytes("801E99423A4ED27608A15A2616A2B0E9E52CED330AC530EDCC32C8FFC6A526AEDD");
            input         = "5J3mBbAH58CpQ3Y5RNJpUKPE62SQ5tfcvU2JpbnkeyhfsYB1Jcn";
            prvKey        = PrivateKey.CreateFromWifString(input);
            wifBytes      = prvKey.GetWifBytes();
            Assert.IsTrue(ByteArrayUtilities.CompareByteArrays(expectedBytes, wifBytes));
            wifString = prvKey.GetWifString();
            Assert.AreEqual(input, wifString);
            Assert.IsFalse(prvKey.WifCompressed);
            Assert.IsFalse(prvKey.TestNet);

            // Uncompressed: "0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D";
            input         = "5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ";
            expectedBytes = HexUtilities.HexStringToBytes("800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D");
            prvKey        = PrivateKey.CreateFromWifString(input);
            wifBytes      = prvKey.GetWifBytes();
            Assert.IsTrue(ByteArrayUtilities.CompareByteArrays(expectedBytes, wifBytes));
            wifString = prvKey.GetWifString();
            Assert.AreEqual(input, wifString);
            Assert.IsFalse(prvKey.WifCompressed);
            Assert.IsFalse(prvKey.TestNet);

            // Uncompressed (TestNet): "93XfLeifX7Jx7n7ELGMAf1SUR6f9kgQs8Xke8WStMwUtrDucMzn";
            input  = "93XfLeifX7Jx7n7ELGMAf1SUR6f9kgQs8Xke8WStMwUtrDucMzn";
            prvKey = PrivateKey.CreateFromWifString(input);
            Assert.AreEqual((BigInteger.Pow(2, 256) - BigInteger.Pow(2, 201)), prvKey.Value);
            wifString = prvKey.GetWifString();
            Assert.AreEqual(input, wifString);
            Assert.IsFalse(prvKey.WifCompressed);
            Assert.IsTrue(prvKey.TestNet);
        }
Exemplo n.º 2
0
        public void MainAndTestnetAddressTest()
        {
            // Compressed
            var prvKey         = new PrivateKey(BigInteger.Pow(888, 3), false, true);
            var pubKey         = prvKey.GetPublicKey();
            var mainnetAddress = pubKey.GetAddress();

            Assert.AreEqual("148dY81A9BmdpMhvYEVznrM45kWN32vSCN", mainnetAddress);
            prvKey = new PrivateKey(BigInteger.Pow(888, 3), true, true);
            pubKey = prvKey.GetPublicKey();
            var testnetAddress = pubKey.GetAddress();

            Assert.AreEqual("mieaqB68xDCtbUBYFoUNcmZNwk74xcBfTP", testnetAddress);

            // Compressed
            var wifString = "KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M8naNQh65b43SA";

            prvKey = PrivateKey.CreateFromWifString(wifString);
            Assert.AreEqual(1234567890, prvKey.Value);
            mainnetAddress = prvKey.GetPublicKey().GetAddress();
            Assert.AreEqual("17V2YVsReZMkvkQDP8Gs1yyGXi6y7jpnV7", mainnetAddress);

            // Compressed
            wifString      = "Kyd8ohVKC84wDwfmBEVkDnopsYRF9GmjRWx6VeUQqF4BpbWVUukv";
            prvKey         = PrivateKey.CreateFromWifString(wifString);
            mainnetAddress = prvKey.GetPublicKey().GetAddress();
            Assert.AreEqual("12Kk2yQEYamxySZk2wGzc8ueNuepMkbEQJ", mainnetAddress);

            // Uncompressed
            prvKey         = new PrivateKey(321, false, false);
            pubKey         = prvKey.GetPublicKey();
            mainnetAddress = pubKey.GetAddress();
            Assert.AreEqual("1S6g2xBJSED7Qr9CYZib5f4PYVhHZiVfj", mainnetAddress);
            prvKey         = new PrivateKey(321, true, false);
            pubKey         = prvKey.GetPublicKey();
            testnetAddress = pubKey.GetAddress();
            Assert.AreEqual("mfx3y63A7TfTtXKkv7Y6QzsPFY6QCBCXiP", testnetAddress);

            // Uncompressed
            prvKey         = new PrivateKey(4242424242, false, false);
            pubKey         = prvKey.GetPublicKey();
            mainnetAddress = pubKey.GetAddress();
            Assert.AreEqual("1226JSptcStqn4Yq9aAmNXdwdc2ixuH9nb", mainnetAddress);
            prvKey         = new PrivateKey(4242424242, true, false);
            pubKey         = prvKey.GetPublicKey();
            testnetAddress = pubKey.GetAddress();
            Assert.AreEqual("mgY3bVusRUL6ZB2Ss999CSrGVbdRwVpM8s", testnetAddress);

            // Uncompressed
            wifString      = "5Kb8kLf9zgWQnogidDA76MzPL6TsZZY36hWXMssSzNydYXYB9KF";
            prvKey         = PrivateKey.CreateFromWifString(wifString);
            mainnetAddress = prvKey.GetPublicKey().GetAddress();
            Assert.AreEqual("1CC3X2gu58d6wXUWMffpuzN9JAfTUWu4Kj", mainnetAddress);
        }