protected override async Task <ECDSASignature> SignExternallyAsync(byte[] hash) { var path = GetPath(); var firstRequest = new EthereumAppSignatureRequest(true, path.Concat(hash).ToArray()); var response = await LedgerManager.SendRequestAsync <EthereumAppSignatureResponse, EthereumAppSignatureRequest>(firstRequest); var signature = ECDSASignatureFactory.FromComponents(response.SignatureR, response.SignatureS); signature.V = new BigInteger(response.SignatureV).ToBytesForRLPEncoding(); return(signature); }
public async Task SignEthereumTransaction() { await GetLedger(); _LedgerManager.SetCoinNumber(60); byte[] rlpEncodedTransactionData = { 227, 128, 132, 59, 154, 202, 0, 130, 82, 8, 148, 139, 6, 158, 207, 123, 242, 48, 225, 83, 184, 237, 144, 59, 171, 242, 68, 3, 204, 162, 3, 128, 128, 4, 128, 128 }; var derivationData = Helpers.GetDerivationPathData(new AddressPath(_LedgerManager.CurrentCoin.IsSegwit, _LedgerManager.CurrentCoin.CoinNumber, 0, false, 0)); // Create base class like GetPublicKeyResponseBase and make the method more like GetAddressAsync var firstRequest = new EthereumAppSignatureRequest(true, derivationData.Concat(rlpEncodedTransactionData).ToArray()); var response = await _LedgerManager.SendRequestAsync <EthereumAppSignatureResponse, EthereumAppSignatureRequest>(firstRequest); Assert.True(response.IsSuccess, $"The response failed with a status of: {response.StatusMessage} ({response.ReturnCode})"); Assert.True(response.SignatureR?.Length == 32); Assert.True(response.SignatureS?.Length == 32); }
private async Task SignEtheremAsync(byte[] rlpEncodedTransactionData, bool isTransaction) { _LedgerManager.SetCoinNumber(60); var derivationData = Helpers.GetDerivationPathData(new BIP44AddressPath(_LedgerManager.CurrentCoin.IsSegwit, _LedgerManager.CurrentCoin.CoinNumber, 0, false, 0)); var concatenatedData = derivationData.Concat(rlpEncodedTransactionData).ToArray(); Console.WriteLine($"Input data: {HexDataToString(concatenatedData)}"); var firstRequest = new EthereumAppSignatureRequest(isTransaction, concatenatedData); var response = await _LedgerManager.SendRequestAsync <EthereumAppSignatureResponse, EthereumAppSignatureRequest>(firstRequest); Assert.IsTrue(response.IsSuccess, $"The response failed with a status of: {response.StatusMessage} ({response.ReturnCode})"); Assert.IsTrue(response.SignatureR?.Length == 32); Assert.IsTrue(response.SignatureS?.Length == 32); Console.WriteLine($"R:{HexDataToString(response.SignatureR)}\r\nS:{HexDataToString(response.SignatureS)}\r\nV:{response.SignatureV}"); }