public string SignTransaction(string key, string to, BigInteger amount, BigInteger nonce, string data)
        {
            var transaction = new Transaction(to, amount, nonce, data);

            transaction.Sign(new EthECKey(key.HexToByteArray(), true));
            return(transaction.GetRLPEncoded().ToHex());
        }
示例#2
0
    /// <summary>
    /// Gets the signed transaction data from the Ledger wallet.
    /// </summary>
    /// <param name="transaction"> The transaction to sign. </param>
    /// <param name="path"> The path of the address to sign the transaction with. </param>
    /// <param name="onSignatureRequestSent"> Action to call once the signature request has been sent. </param>
    /// <returns> Task returning the SignedTransactionDataHolder instance. </returns>
    protected override async Task <SignedTransactionDataHolder> GetSignedTransactionData(Transaction transaction, string path, Action onSignatureRequestSent)
    {
        var ledgerManager = LedgerConnector.GetWindowsConnectedLedger();
        var address       = ledgerManager == null
            ? null
            : (await ledgerManager.GetPublicKeyResponse(Wallet.ELECTRUM_LEDGER_PATH.Replace("x", "0"), false, false).ConfigureAwait(false))?.Address;

        // Don't sign transaction if app is not Ethereum, or if the first address doesn't match the first address of the opened Ledger wallet.
        if (string.IsNullOrEmpty(address) || !address.EqualsIgnoreCase(addresses[1][0]))
        {
            return(null);
        }

        var addressIndex   = path.Count(c => c == '/') - 1;
        var derivationData = Helpers.GetDerivationPathData(path);

        var request = new EthereumAppSignTransactionRequest(derivationData.Concat(transaction.GetRLPEncoded()).ToArray());

        onSignatureRequestSent?.Invoke();

        var response = await ledgerManager.SendRequestAsync <EthereumAppSignTransactionResponse, EthereumAppSignTransactionRequest>(request).ConfigureAwait(false);

        if (!response.IsSuccess)
        {
            return(new SignedTransactionDataHolder());
        }

        return(new SignedTransactionDataHolder {
            signed = true, v = response.SignatureV, r = response.SignatureR, s = response.SignatureS
        });
    }
示例#3
0
        public async Task <string> SignAndSendRawTransaction(Nethereum.Signer.Transaction transaction)
        {
            transaction.Sign(new EthECKey(_sender_private_key.HexToByteArray(), isPrivate: true));
            string signed_transaction_data = transaction.GetRLPEncoded().ToHex();
            string tx_hash = await _web3geth.Eth.Transactions.SendRawTransaction.SendRequestAsync(signed_transaction_data);

            return(tx_hash);
        }
        private string SignRawTransaction(string trHex, string privateKey)
        {
            var transaction = new Nethereum.Signer.Transaction(trHex.HexToByteArray());
            var secret      = new EthECKey(privateKey);

            transaction.Sign(secret);

            string signedHex = transaction.GetRLPEncoded().ToHex();

            return(signedHex);
        }
示例#5
0
        public async Task <string> SendTransactionAsync <T>(T transaction) where T : TransactionInput
        {
            var ethSendTransaction = new EthSendRawTransaction(Client);

            var nonce = await GetNonceAsync(transaction);

            var value    = transaction.Value?.Value ?? 0;
            var gasPrice = await EstimateGasPrice();

            var gasValue = transaction.Gas?.Value ?? Transaction.DEFAULT_GAS_LIMIT;

            var tr       = new Transaction(transaction.To, value, nonce, gasPrice, gasValue, transaction.Data);
            var hex      = tr.GetRLPEncoded().ToHex();
            var response = await _signatureApi.SignTransaction(new SignRequest { From = transaction.From, Transaction = hex });

            return(await ethSendTransaction.SendRequestAsync(response.SignedTransaction.EnsureHexPrefix()).ConfigureAwait(false));
        }
        public async Task <string> BuildTransactionAsync(
            string from,
            string to,
            BigInteger amount,
            BigInteger gasAmount,
            BigInteger gasPrice)
        {
            var transaction = new NethereumTransaction
                              (
                to: to,
                amount: amount,
                nonce: await GetNextNonceAsync(from),
                gasPrice: gasPrice,
                gasLimit: gasAmount,
                data: null
                              );

            return(transaction
                   .GetRLPEncoded()
                   .ToHex(prefix: true));
        }
示例#7
0
        public string SignTransaction(
            string transactionContext,
            string privateKey)
        {
            using (var eventHolder = _telemetryClient.StartEvent("TransactionSigned"))
            {
                try
                {
                    var transactionBytes = transactionContext.HexToByteArray();
                    var transactionDto   = MessagePackSerializer.Deserialize <UnsignedTransaction>(transactionBytes);

                    var transaction = new NethereumTransaction
                                      (
                        to: transactionDto.To,
                        amount: transactionDto.Amount,
                        nonce: transactionDto.Nonce,
                        gasPrice: transactionDto.GasPrice,
                        gasLimit: transactionDto.GasAmount,
                        data: null
                                      );

                    transaction.Sign
                    (
                        key: new EthECKey(privateKey)
                    );

                    return(transaction
                           .GetRLPEncoded()
                           .ToHex(prefix: true));
                }
                catch (Exception)
                {
                    eventHolder.TrackFailure("TransactionSigningFailed");

                    throw;
                }
            }
        }
 private string SignTransaction(byte[] privateKey, Transaction transaction)
 {
     transaction.Sign(new EthECKey(privateKey, true));
     return(transaction.GetRLPEncoded().ToHex());
 }
        private async Task <string> SignTransactionAsync(IEthECKeyExternalSigner externalSigner, Transaction transaction)
        {
            await transaction.SignExternallyAsync(externalSigner).ConfigureAwait(false);

            return(transaction.GetRLPEncoded().ToHex());
        }