private async Task <string> RelayTransaction( Relay relay, TransactionInput transaction, string hubAddress) { var nonce = await _relayHubManager .GetNonceAsync(hubAddress, transaction.From) .ConfigureAwait(false); var hash = GetTransactionHash( transaction.From, transaction.To, transaction.Data, relay.Fee, transaction.GasPrice.Value, transaction.Gas.Value, nonce, hubAddress, relay.Address); var signer = new EthereumMessageSigner(); var signature = signer.Sign(hash.HexToByteArray(), _privateKey); var approvalDataSig = signer.Sign( GetApprovalData( transaction, relay.Fee, transaction.GasPrice.Value, transaction.Gas.Value, nonce, hubAddress, relay.Address), _privateKey); var transactionCount = await _ethApiContractService.Transactions.GetTransactionCount .SendRequestAsync(relay.Address) .ConfigureAwait(false); var relayMaxNonce = transactionCount.Value + new BigInteger(_options.AllowedRelayNonceGap); var txHash = await SendViaRelay( relay.Url, transaction, relay.Fee, transaction.GasPrice.Value, transaction.Gas.Value, nonce, hubAddress, relay.Address, signature, approvalDataSig, relayMaxNonce) .ConfigureAwait(false); return(txHash); }
public void ShouldRecover() { var signature = "0x0976a177078198a261faf206287b8bb93ebb233347ab09a57c8691733f5772f67f398084b30fc6379ffee2cc72d510fd0f8a7ac2ee0162b95dc5d61146b40ffa1c"; var text = "test"; var hasher = new Sha3Keccack(); var hash = hasher.CalculateHash(text); var signer = new EthereumMessageSigner(); var account = signer.EcRecover(hash.HexToByteArray(), signature); Assert.Equal("0x12890d2cce102216644c59dae5baed380d84830c", account.EnsureHexPrefix().ToLower()); signature = signer.Sign(hash.HexToByteArray(), "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7"); account = signer.EcRecover(hash.HexToByteArray(), signature); Assert.Equal("0x12890d2cce102216644c59dae5baed380d84830c".ToLower(), account.EnsureHexPrefix().ToLower()); }
public void test4() { var signature = "0xdb46c6be4b1ee0ef670625630d38899213ea5d63d749954d82a4651b81f7d44f6d16e2e4903038c022b71d11baa26b08142c6b9f5db106d7b96b57d1836ce10e1b"; var text = "test"; var hasher = new Sha3Keccack(); var hash = hasher.CalculateHash(text); var signer = new EthereumMessageSigner(); var account = signer.EncodeUTF8AndEcRecover(text, signature); Assert.Equal("0xe77992311815D6961cBB231CFd2009990203385F".ToLower(), account.EnsureHexPrefix().ToLower()); signature = signer.Sign(hash.HexToByteArray(), "0xd3a7d42d881a9b59ccefcac0f5bcc69f85e68fdf0bfb6fcbbe42373320de420f"); account = signer.EcRecover(hash.HexToByteArray(), signature); Assert.Equal("0x12890d2cce102216644c59dae5baed380d84830c".ToLower(), account.EnsureHexPrefix().ToLower()); }
private string getGluwacoinReserveTxnSignature( ECurrency currency, string address, string amount, string fee, string target, string executor, BigInteger nonce, BigInteger expiryBlockNumber, string privateKey) { BigInteger convertAmount = BigInteger.Zero; BigInteger convertFee = BigInteger.Zero; if (currency.IsGluwacoinSideChainCurrency()) { convertAmount = GluwacoinConverter.ConvertToGluwacoinSideChainBigInteger(amount, currency); convertFee = GluwacoinConverter.ConvertToGluwacoinSideChainBigInteger(fee, currency); } else { convertAmount = GluwacoinConverter.ConvertToGluwacoinBigInteger(amount); convertFee = GluwacoinConverter.ConvertToGluwacoinBigInteger(fee); } ABIEncode abiEncode = new ABIEncode(); byte[] messageHash = abiEncode.GetSha3ABIEncodedPacked( new ABIValue("address", GluwaService.getGluwacoinContractAddress(currency, mEnv)), new ABIValue("address", address), new ABIValue("address", target), new ABIValue("address", executor), new ABIValue("uint256", convertAmount), new ABIValue("uint256", convertFee), new ABIValue("uint256", nonce), new ABIValue("uint256", expiryBlockNumber) ); EthereumMessageSigner signer = new EthereumMessageSigner(); string signature = signer.Sign(messageHash, privateKey); return(signature); }
private string getGluwacoinTransactionSignature(ECurrency currency, string amount, string fee, string nonce, string address, string target, string privateKey) { BigInteger convertAmount = BigInteger.Zero; BigInteger convertFee = BigInteger.Zero; if (currency.IsGluwacoinSideChainCurrency()) { if (currency == ECurrency.sNGNG) { convertAmount = GluwacoinConverter.ConvertToGluwacoinSideChainBigInteger(amount, currency); convertFee = GluwacoinConverter.ConvertToGluwacoinSideChainBigInteger(fee.ToString(), currency); } else if (currency == ECurrency.sUSDCG) { convertAmount = GluwacoinConverter.ConvertToGluwacoinSideChainBigInteger(amount, currency); convertFee = GluwacoinConverter.ConvertToGluwacoinSideChainBigInteger(fee.ToString(), currency); } } else { convertAmount = GluwacoinConverter.ConvertToGluwacoinBigInteger(amount); convertFee = GluwacoinConverter.ConvertToGluwacoinBigInteger(fee.ToString()); } ABIEncode abiEncode = new ABIEncode(); byte[] messageHash = abiEncode.GetSha3ABIEncodedPacked( new ABIValue("address", GluwaService.getGluwacoinContractAddress(currency, mEnv)), new ABIValue("address", address), new ABIValue("address", target), new ABIValue("uint256", convertAmount), new ABIValue("uint256", convertFee), new ABIValue("uint256", BigInteger.Parse(nonce)) ); EthereumMessageSigner signer = new EthereumMessageSigner(); string signature = signer.Sign(messageHash, privateKey); return(signature); }
public string Sign(string privateKey, byte[] message) { return(_signer.Sign(message, privateKey)); }