public string Hash(string message) { var hasher = new Nethereum.Util.Sha3Keccack(); var hash = hasher.CalculateHash(message); return(hash); }
public static string SignMessage(Dictionary <string, object> message) { var web3 = new Nethereum.Web3.Web3(); var stringed = Helpers.StringifyDictionary(message); var hashed = Nethereum.Web3.Web3.Sha3(stringed); var salted = new Nethereum.Util.Sha3Keccack().CalculateHash(hashed).HexToByteArray(); return(string.Empty); }
/// <summary> /// Returns HoardID that signed this transaction /// </summary> /// <param name="signatureStr"></param> /// <param name="rlpEncodedTransaction"></param> /// <returns>Signer of this transaction</returns> public static HoardID RecoverHoardIdFromTransaction(string signatureStr, byte[] rlpEncodedTransaction) { if (string.IsNullOrEmpty(signatureStr)) { return(null); } var signature = EthECDSASignatureFactory.ExtractECDSASignature(signatureStr); var rawHash = new Nethereum.Util.Sha3Keccack().CalculateHash(rlpEncodedTransaction); return(new HoardID(EthECKey.RecoverFromSignature(signature, rawHash).GetPublicAddress())); }
public IActionResult Validate(Guid token, string signature) { var message = Encoding.ASCII.GetBytes(token.ToString()); var prefix = Encoding.ASCII.GetBytes("\u0019Ethereum Signed Message:\n" + message.Length.ToString()); var fullmessage = prefix.Concat(message).ToArray(); var hash = new Nethereum.Util.Sha3Keccack().CalculateHash(fullmessage); var sigParams = Nethereum.Signer.MessageSigner.ExtractEcdsaSignature(signature); var publicKey = Nethereum.Signer.EthECKey.RecoverFromSignature(sigParams, hash); var addr = publicKey.GetPublicAddress(); if (!_data.ValidateAccessToken(token, addr.ToLower())) { return(Unauthorized()); } return(Ok(new { success = true })); }
//Referenced By: https://github.com/MetacoSA/NBitcoin/issues/565 public string GenerateAddress(byte[] pubKeyBytes) { var ETH_publickKey = new PubKey(pubKeyBytes); byte[] byte_ETH_publicKey = ETH_publickKey.Decompress().ToBytes(); var PubKeyNoPrefix = new byte[byte_ETH_publicKey.Length - 1]; Array.Copy(byte_ETH_publicKey, 1, PubKeyNoPrefix, 0, PubKeyNoPrefix.Length); var initaddr = new Nethereum.Util.Sha3Keccack().CalculateHash(PubKeyNoPrefix); var addr = new byte[initaddr.Length - 12]; Array.Copy(initaddr, 12, addr, 0, initaddr.Length - 12); var hex_addr = BitConverter.ToString(addr).Replace("-", ""); string public_address = new Nethereum.Util.AddressUtil().ConvertToChecksumAddress(hex_addr); return(public_address); }
public static String GetETHLedgerAddress(ExtPubKey pubkey, int index) { var pkd = pubkey; PubKey ETH_publickKey = pkd.PubKey; byte[] byte_ETH_publicKey = ETH_publickKey.Decompress().ToBytes(); var PubKeyNoPrefix = new byte[byte_ETH_publicKey.Length - 1]; Array.Copy(byte_ETH_publicKey, 1, PubKeyNoPrefix, 0, PubKeyNoPrefix.Length); var initaddr = new Nethereum.Util.Sha3Keccack().CalculateHash(PubKeyNoPrefix); var addr = new byte[initaddr.Length - 12]; Array.Copy(initaddr, 12, addr, 0, initaddr.Length - 12); var hex_addr = BitConverter.ToString(addr).Replace("-", ""); string public_address = new Nethereum.Util.AddressUtil().ConvertToChecksumAddress(hex_addr); return(public_address); }