Esempio n. 1
0
        private static byte[] DeriveAddress(string hex)
        {
            if (hex == null)
            {
                throw new ArgumentNullException(nameof(hex));
            }

            if (hex.Length != 40)
            {
                throw new ArgumentException(
                          "address hex must be 40 bytes",
                          nameof(hex)
                          );
            }

            if (hex.ToLower() != hex && ToChecksumAddress(hex.ToLower()) != hex)
            {
                throw new ArgumentException(
                          "address checksum is invalid",
                          nameof(hex)
                          );
            }

            try
            {
                return(ByteUtil.ParseHex(hex));
            }
            catch (FormatException)
            {
                throw new ArgumentException(
                          "address hex must only consist of ASCII characters"
                          );
            }
        }
Esempio n. 2
0
        public static HashDigest <T> FromString(string hexDigest)
        {
            if (hexDigest == null)
            {
                throw new ArgumentNullException(nameof(hexDigest));
            }

            if (hexDigest.Length != Size * 2)
            {
                string message =
                    $"HashDigest<{typeof(T).Name}> requires {Size * 2} " +
                    $"hexadecimal letters, but {hexDigest.Length} was given";
                throw new ArgumentOutOfRangeException(
                          nameof(hexDigest),
                          message
                          );
            }

            return(new HashDigest <T>(ByteUtil.ParseHex(hexDigest)));
        }
Esempio n. 3
0
 public static HashDigest <T> FromString(string s)
 {
     return(new HashDigest <T>(ByteUtil.ParseHex(s)));
 }