Esempio n. 1
0
        private static async Task <bool> ValidateChecksumAsync(string address)
        {
            address = address.Remove(0, 2);

            var addressBytes = Encoding.UTF8.GetBytes(address.ToLowerInvariant());
            var caseMapBytes = (await Multihash.SumAsync <KECCAK_256>(addressBytes)).Digest;

            for (var i = 0; i < 40; i++)
            {
                var addressChar = address[i];

                if (!char.IsLetter(addressChar))
                {
                    continue;
                }

                var leftShift     = i % 2 == 0 ? 7 : 3;
                var shouldBeUpper = (caseMapBytes[i / 2] & (1 << leftShift)) != 0;
                var shouldBeLower = !shouldBeUpper;

                if (shouldBeUpper && char.IsLower(addressChar) ||
                    shouldBeLower && char.IsUpper(addressChar))
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 2
0
        public static async Task <byte[]> SumAsync(params byte[][] data)
        {
            var multihash = await Multihash.SumAsync <KECCAK_256>
                            (
                data : ConcatMany(data)
                            );

            return(multihash.Digest);
        }
Esempio n. 3
0
        public async Task <byte[]> SumAsync(
            params byte[][] data)
        {
            var multihash = await Multihash.SumAsync
                            (
                type : _hashType,
                data : data.Concat()
                            );

            return(multihash.Digest);
        }
Esempio n. 4
0
        public async Task VerifyRoundTripAsync(HashType type)
        {
            var rand  = new Random(Environment.TickCount);
            var bytes = new byte[rand.Next(1024, 4096)];

            rand.NextBytes(bytes);

            var mh = await Multihash.SumAsync(type, bytes, type == HashType.ID?bytes.Length : -1);

            var str = mh.ToString();
            var mh2 = Multihash.Parse(str);

            Assert.True(await mh2.VerifyAsync(bytes));
        }