Exemple #1
0
        public static string CalculateContractAddress(string address, BigInteger nonce)
        {
            var sha3 = new Sha3Keccack();

            return
                (sha3.CalculateHash(RLP.RLP.EncodeList(RLP.RLP.EncodeElement(address.HexToByteArray()),
                                                       RLP.RLP.EncodeElement(nonce.ToBytesForRLPEncoding()))).ToHex().Substring(24));
        }
        public string ConvertToChecksumAddress(string address)
        {
            address = address.ToLower().RemoveHexPrefix();
            var addressHash     = new Sha3Keccack().CalculateHash(address);
            var checksumAddress = "0x";

            for (var i = 0; i < address.Length; i++)
            {
                if (int.Parse(addressHash[i].ToString(), NumberStyles.HexNumber) > 7)
                {
                    checksumAddress += address[i].ToString().ToUpper();
                }
                else
                {
                    checksumAddress += address[i];
                }
            }
            return(checksumAddress);
        }
        public bool IsChecksumAddress(string address)
        {
            if (string.IsNullOrEmpty(address))
            {
                return(false);
            }
            address = address.RemoveHexPrefix();
            var addressHash = new Sha3Keccack().CalculateHash(address.ToLower());

            for (var i = 0; i < 40; i++)
            {
                var value = int.Parse(addressHash[i].ToString(), NumberStyles.HexNumber);
                // the nth letter should be uppercase if the nth digit of casemap is 1
                if (value > 7 && address[i].ToString().ToUpper() != address[i].ToString() ||
                    value <= 7 && address[i].ToString().ToLower() != address[i].ToString())
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #4
0
        public static string CalculateTransactionHash(string rawSignedTransaction)
        {
            var sha3 = new Sha3Keccack();

            return(sha3.CalculateHashFromHex(rawSignedTransaction));
        }