public async void ShouldSignCorrectly() { await Task.Yield(); string privateKey = "0xa07cb7889ab3a164dcc72cb6103f2573c7ef2d4a855810594d2bf25df60bc39e"; PlasmaCore.Transactions.Transaction transaction = new PlasmaCore.Transactions.Transaction(); transaction.AddInput(2000, 0, 1); transaction.AddOutput("0xf86b5b1c2c8de1ea4dc737c849272340fa3561c5", "0x0000000000000000000000000000000000000000", 123); transaction.AddOutput("0xf86b5b1c2c8de1ea4dc737c849272340fa3561c5", "0x0000000000000000000000000000000000000000", 5555308); TypedDataTransactionEncoder txEncoder = new TypedDataTransactionEncoder(omgDomain); byte[] encodedTx = txEncoder.EncodeRaw(transaction); var rawHash = new Sha3Keccack().CalculateHash(encodedTx); var ecKey = new Nethereum.Signer.EthECKey(privateKey); var ecdsaSignature = ecKey.SignAndCalculateV(rawHash); string signature = Nethereum.Signer.EthECDSASignature.CreateStringSignature(ecdsaSignature); Assert.Equal("0xed0ff5633cb85aa0f64684759185f8a9f94fd1b654be5942d562bf64f504e3a96a83b90a5e50e50b8a75d4f711d1c0e56066519237dbd94e564084a561b8ba2f1b", signature.EnsureHexPrefix()); transaction.SetSignature(0, signature.HexToByteArray()); var signedEncodedTx = txEncoder.EncodeSigned(transaction).ToHex(true); Assert.Equal("0xf9012ef843b841ed0ff5633cb85aa0f64684759185f8a9f94fd1b654be5942d562bf64f504e3a96a83b90a5e50e50b8a75d4f711d1c0e56066519237dbd94e564084a561b8ba2f1bd2c58207d08001c3808080c3808080c3808080f8b3eb94f86b5b1c2c8de1ea4dc737c849272340fa3561c59400000000000000000000000000000000000000007bee94f86b5b1c2c8de1ea4dc737c849272340fa3561c59400000000000000000000000000000000000000008354c46ceb94000000000000000000000000000000000000000094000000000000000000000000000000000000000080eb94000000000000000000000000000000000000000094000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000", signedEncodedTx.EnsureHexPrefix()); }
/// <summary> /// Sign transaction with the private key /// </summary> /// <param name="input">input arguments</param> /// <returns>transaction signature string</returns> public override Task <string> SignTransaction(byte[] input) { //CPU-bound var ecKey = new Nethereum.Signer.EthECKey(DecodeLocalKey(), true); var rawHash = new Sha3Keccack().CalculateHash(input); var signature = ecKey.SignAndCalculateV(rawHash); return(Task.FromResult(Nethereum.Signer.EthECDSASignature.CreateStringSignature(signature))); }
public static string Sign(ITransactionEncoder txEncoder, Transaction transaction, string address, string privateKey) { byte[] encodedTx = txEncoder.EncodeRaw(transaction); var rawHash = new Sha3Keccack().CalculateHash(encodedTx); var ecKey = new Nethereum.Signer.EthECKey(privateKey); var ecdsaSignature = ecKey.SignAndCalculateV(rawHash); string signature = Nethereum.Signer.EthECDSASignature.CreateStringSignature(ecdsaSignature); transaction.SetSignature(address, signature.HexToByteArray()); return(txEncoder.EncodeSigned(transaction).ToHex(true)); }