예제 #1
0
        public void DecodeChecked()
        {
            Base58.DecodeChecked("4stwEBjT6FYyVV");

            Assert.Throws <AddressFormatException>(() => Base58.DecodeChecked("yVv"));
            Assert.Throws <AddressFormatException>(() => Base58.DecodeChecked("4stwEBjT6FYyVv"));

            // Now check we can correctly decode the case where the high bit of the first byte is not zero, so BigInteger
            // sign extends. Fix for a bug that stopped us parsing keys exported using sipas patch.
            Base58.DecodeChecked("93VYUMzRG9DdbRP72uQXjaWibbQwygnvaCu9DumcqDjGybD864T");
        }
예제 #2
0
        // Visible for testing.
        internal static IList <EndPoint> ParseUserList(IEnumerable <string> userNames)
        {
            var addresses = new List <EndPoint>();

            foreach (var user in userNames)
            {
                // All BitCoin peers start their nicknames with a 'u' character.
                if (!user.StartsWith("u"))
                {
                    continue;
                }

                // After "u" is stripped from the beginning array contains unsigned chars of:
                // 4 byte IP address, 2 byte port, 4 byte hash check (ipv4)

                byte[] addressBytes;
                try
                {
                    // Strip off the "u" before decoding. Note that it's possible for anyone to join these IRC channels and
                    // so simply beginning with "u" does not imply this is a valid BitCoin encoded address.
                    //
                    // decodeChecked removes the checksum from the returned bytes.
                    addressBytes = Base58.DecodeChecked(user.Substring(1));
                }
                catch (AddressFormatException)
                {
                    _log.WarnFormat("IRC nick does not parse as base58: {0}", user);
                    continue;
                }

                // TODO: Handle IPv6 if one day the official client uses it. It may be that IRC discovery never does.
                if (addressBytes.Length != 6)
                {
                    continue;
                }

                var ipBytes = new[] { addressBytes[0], addressBytes[1], addressBytes[2], addressBytes[3] };
                var port    = Utils.ReadUint16Be(addressBytes, 4);

                var ip = new IPAddress(ipBytes);

                var address = new IPEndPoint(ip, port);
                addresses.Add(address);
            }

            return(addresses);
        }
예제 #3
0
        public void TestDecode()
        {
            var testbytes   = Encoding.UTF8.GetBytes("Hello World");
            var actualbytes = Base58.Decode("JxF12TrwUP45BMd");

            Assert.IsTrue(testbytes.SequenceEqual(actualbytes), Encoding.UTF8.GetString(actualbytes, 0, actualbytes.Length));

            try
            {
                Base58.Decode("This isn't valid base58");
                Assert.Fail();
            }
            catch (AddressFormatException)
            {
            }

            Base58.DecodeChecked("4stwEBjT6FYyVV");

            // Now check we can correctly decode the case where the high bit of the first byte is not zero, so BigInteger
            // sign extends. Fix for a bug that stopped us parsing keys exported using Sipa's patch.
            Base58.DecodeChecked("93VYUMzRG9DdbRP72uQXjaWibbQwygnvaCu9DumcqDjGybD864T");
        }