public static string GetPublicAddress(this ECKey key) { var initaddr = new Sha3Keccack().CalculateHash(key.GetPubKeyNoPrefix()); var addr = new byte[initaddr.Length - 12]; Array.Copy(initaddr, 12, addr, 0, initaddr.Length - 12); return addr.ToHex(); }
public void ShouldEncodeATransactionUsingKeccak256() { var txRaw = "F89D80809400000000000000000000000000000000000000008609184E72A000822710B3606956330C0D630000003359366000530A0D630000003359602060005301356000533557604060005301600054630000000C5884336069571CA07F6EB94576346488C6253197BDE6A7E59DDC36F2773672C849402AA9C402C3C4A06D254E662BF7450DD8D835160CBB053463FED0B53F2CDD7F3EA8731919C8E8CC"; var txHashB = new Sha3Keccack().CalculateHash(txRaw.HexToByteArray()); var txHash = txHashB.ToHex(); Assert.Equal("4b7d9670a92bf120d5b43400543b69304a14d767cf836a7f6abff4edde092895", txHash); }
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; }
private void InitialiseInnerServices() { Eth = new Eth(Client); Shh = new Shh(Client); Net = new Net(Client); Personal = new Personal(Client); Miner = new Miner(Client); DebugGeth = new DebugGeth(Client); Admin = new Admin(Client); Convert = new UnitConversion(); sha3Keccack = new Sha3Keccack(); OfflineTransactionSigning = new TransactionSigning(); addressUtil = new AddressUtil(); }
public string GetEnsNameHash(string name) { var node = "0x0000000000000000000000000000000000000000000000000000000000000000"; var kecckak = new Sha3Keccack(); if (!string.IsNullOrEmpty(name)) { var labels = name.Split('.'); for (var i = labels.Length - 1; i >= 0; i--) { var byteInput = (node + kecckak.CalculateHash(labels[i])).HexToByteArray(); node = kecckak.CalculateHash(byteInput).ToHex(); } } return node.EnsureHexPrefix(); }
public bool IsChecksumAddress(string address) { 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; }
public bool IsChecksumAddress(string address) { 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); }
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 SignatureEncoder() { sha3Keccack = new Sha3Keccack(); }