/// <summary> /// Get an address from the Trezor /// //TODO: Move this back down to TrezorManagerBase /// </summary> public async Task <string> GetAddressAsync(string coinShortcut, uint coinNumber, uint account, bool isChange, uint index, bool showDisplay, AddressType addressType, bool?isSegwit) { try { ValidateInitialization(null); //ETH and ETC don't appear here so we have to hard code these not to be segwit //var coinType = Features.Coins.Find(c => string.Equals(c.CoinShortcut, coinShortcut, StringComparison.OrdinalIgnoreCase)); var coinType = GetCoinType(coinNumber); if (isSegwit == null) { isSegwit = coinType?.Segwit == true; } var path = ManagerHelpers.GetAddressPath(isSegwit.Value, account, isChange, index, coinNumber); switch (addressType) { case AddressType.Bitcoin: return((await SendMessageAsync <Address, GetAddress>(new GetAddress { ShowDisplay = showDisplay, AddressNs = path, CoinName = GetCoinType(coinShortcut)?.CoinName, ScriptType = isSegwit.Value ? InputScriptType.Spendp2shwitness : InputScriptType.Spendaddress })).address); case AddressType.Ethereum: var ethereumAddress = await SendMessageAsync <EthereumAddress, EthereumGetAddress>(new EthereumGetAddress { ShowDisplay = showDisplay, AddressNs = path }); var sb = new StringBuilder(); foreach (var b in ethereumAddress.Address) { sb.Append(b.ToString("X2").ToLower()); } var hexString = sb.ToString(); return($"0x{hexString}"); case AddressType.NEM: throw new NotImplementedException(); default: throw new NotImplementedException(); } } catch (Exception ex) { Logger.Log("Error Getting Trezor Address", ex, LogSection); throw; } }
public async Task SignEthereumTransaction() { await GetAndInitialize(); //Note: these are not reasonable values. They should not be used for a transaction. Looking for a better example here... var txMessage = new EthereumSignTx { Nonce = "0".ToHexBytes(), GasPrice = 1000000000.ToHexBytes(), GasLimit = 21000.ToHexBytes(), To = "689c56aef474df92d44a1b70850f808488f9769c".ToHexBytes(), Value = "de0b6b3a7640000".ToHexBytes(), AddressNs = ManagerHelpers.GetAddressPath(false, 0, false, 0, 60), ChainId = 1 }; var transaction = await TrezorManager.SendMessageAsync <EthereumTxRequest, EthereumSignTx>(txMessage); Assert.AreEqual(transaction.SignatureR.Length, 32); Assert.AreEqual(transaction.SignatureS.Length, 32); }