private string GetTransactionHash( string from, string to, string data, BigInteger txFee, BigInteger gasPrice, BigInteger gasLimit, BigInteger nonce, string relayHubAddress, string relayAddress) { var keccack256 = new Sha3Keccack(); var encoder = new IntTypeEncoder(); return(keccack256.CalculateHashFromHex( RelayPrefix.ToHexUTF8(), from, to, data, encoder.EncodeInt(txFee).ToHex(), encoder.EncodeInt(gasPrice).ToHex(), encoder.EncodeInt(gasLimit).ToHex(), encoder.EncodeInt(nonce).ToHex(), relayHubAddress, relayAddress)); }
public void ShouldCalculateHashFromHexForMultipleStrings() { var keccak = new Sha3Keccack(); var result = keccak.CalculateHashFromHex("0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae", "0x0d57c7d8b54ebf963f94cded8a57a1b109ac7465ada218575473648bf373b90d"); Assert.Equal("13265b3c8b785f6715b215cb1e6869312588a03afe0076beda8042c2ceb5603b", result); }
public static string GetChannelAddress(string aliceAddress, string bobAddress) { var sha3 = new Sha3Keccack(); var output = sha3.CalculateHashFromHex(aliceAddress, bobAddress); var resultHash = "0x" + output; return(resultHash); }
//extracted from latest Nethereum Util public static string CalculateCreate2Address(string address, string saltHex, string byteCodeHex) { if (string.IsNullOrEmpty(address)) { throw new System.ArgumentException($"'{nameof(address)}' cannot be null or empty.", nameof(address)); } if (string.IsNullOrEmpty(saltHex)) { throw new System.ArgumentException($"'{nameof(saltHex)}' cannot be null or empty.", nameof(saltHex)); } if (saltHex.EnsureHexPrefix().Length != 66) { throw new System.ArgumentException($"'{nameof(saltHex)}' needs to be 32 bytes", nameof(saltHex)); } var sha3 = new Sha3Keccack(); return(sha3.CalculateHashFromHex("0xff", address, saltHex, sha3.CalculateHashFromHex(byteCodeHex)).Substring(24).ConvertToEthereumChecksumAddress()); }
public static string Sha3ForCooperative(CooperativeSignDto cooperativeDto) { var sha3 = new Sha3Keccack(); var bob = new IntTypeEncoder() .Encode(StringToBigInteger(cooperativeDto.BobAmountWei)); var alice = new IntTypeEncoder() .Encode(StringToBigInteger(cooperativeDto.AliceAmountWei)); var output = sha3.CalculateHashFromHex(bob.ToHex(), alice.ToHex(), cooperativeDto.ChannelId); var resultHash = "0x" + output; return(resultHash); }
public static string Sha3ForReceipts(ReceiptDto receiptDto) { var sha3 = new Sha3Keccack(); var rec = new IntTypeEncoder() .Encode(receiptDto.ReceiptId); var epo = new IntTypeEncoder() .Encode(receiptDto.EpochId); var amo = new IntTypeEncoder() .Encode(StringToBigInteger(receiptDto.AmountWei)); var output = sha3.CalculateHashFromHex(rec.ToHex(), epo.ToHex(), amo.ToHex(), receiptDto.Address); var resultHash = "0x" + output; return(resultHash); }
public static string Sha3ForAudit(AuditSignDto auditDto) { var sha3 = new Sha3Keccack(); var bob = new IntTypeEncoder() .Encode(StringToBigInteger(auditDto.BobAmountWei)); var alice = new IntTypeEncoder() .Encode(StringToBigInteger(auditDto.AliceAmountWei)); var epoch = new IntTypeEncoder() .Encode(auditDto.EpochId); var output = sha3.CalculateHashFromHex(bob.ToHex(), alice.ToHex(), auditDto.ChannelId, epoch.ToHex()); var resultHash = "0x" + output; return(resultHash); }
public void ShouldSignHash() { var address1 = "0x6A849e2036A36EB4Cd37b9aFA3c770064899f1A2"; var address2 = "0x12890D2cce102216644c59daE5baed380d84830c"; var numberBytes = new IntTypeEncoder() .Encode(1); //Number is a big integer so we need 32 bytes if it was int32 it will be 4 bytes. Using the abi encoder it takes care of padding var sha3 = new Sha3Keccack(); var output = sha3.CalculateHashFromHex(address1, address2, numberBytes.ToHex()); Assert.Equal("0xc11d3d2b8e0c5b8b645b9e7502751352ecaf8c3fdf3a0124dae9c1556fb2ce37", output.EnsureHexPrefix()); var signer = new MessageSigner(); var signature = signer.Sign(output.HexToByteArray(), "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7"); var ethEcdsa = MessageSigner.ExtractEcdsaSignature(signature); var address = signer.EcRecover(output.HexToByteArray(), signature); Assert.Equal(address, new EthECKey("0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7".HexToByteArray(), true).GetPublicAddress()); }
public static string CalculateTransactionHash(string rawSignedTransaction) { var sha3 = new Sha3Keccack(); return(sha3.CalculateHashFromHex(rawSignedTransaction)); }