Exemplo n.º 1
0
        public async Task <EthereumAppGetPublicKeyResponse> GetPublicKeyResponse(string path, bool getChainCode, bool showDisplay)
        {
            byte[] data = Helpers.GetDerivationPathData(path);

            EthereumAppGetPublicKeyResponse response = await SendRequestAsync <EthereumAppGetPublicKeyResponse, EthereumAppGetPublicKeyRequest>(new EthereumAppGetPublicKeyRequest(showDisplay, getChainCode, data));

            return(response.IsSuccess ? response : null);
        }
Exemplo n.º 2
0
        public async Task <ECDSASignature> SignAsync(byte[] hash)
        {
            var ledgerManager = await GetLedger();

            ledgerManager.SetCoinNumber(60);
            var derivationData = Helpers.GetDerivationPathData(ledgerManager.CurrentCoin.App, ledgerManager.CurrentCoin.CoinNumber, 0, 0, false, ledgerManager.CurrentCoin.IsSegwit);

            // Create base class like GetPublicKeyResponseBase and make the method more like GetAddressAsync
            var firstRequest = new EthereumAppSignTransactionRequest(derivationData.Concat(hash).ToArray());

            var response = await ledgerManager.SendRequestAsync <EthereumAppSignTransactionResponse, EthereumAppSignTransactionRequest>(firstRequest);

            var signature = new ECDSASignature(new Org.BouncyCastle.Math.BigInteger(response.SignatureR), new Org.BouncyCastle.Math.BigInteger(response.SignatureS));

            signature.V = new BigInteger(response.SignatureV).ToBytesForRLPEncoding();
            return(signature);
        }
Exemplo n.º 3
0
        public async Task <string> GetAddressAsync(uint account, bool isChange, uint index, bool showDisplay)
        {
            byte[] data = Helpers.GetDerivationPathData(CurrentCoin.App, CurrentCoin.CoinNumber, account, index, isChange, CurrentCoin.IsSegwit);

            GetPublicKeyResponseBase response;

            if (CurrentCoin.App == App.Ethereum)
            {
                response = await SendRequestAsync <EthereumAppGetPublicKeyResponse, EthereumAppGetPublicKeyRequest>(new EthereumAppGetPublicKeyRequest(showDisplay, false, data));
            }
            else
            {
                //TODO: Should we use the Coin's IsSegwit here?
                response = await SendRequestAsync <BitcoinAppGetPublicKeyResponse, BitcoinAppGetPublicKeyRequest>(new BitcoinAppGetPublicKeyRequest(showDisplay, BitcoinAddressType.Segwit, data));
            }

            if (!response.IsSuccess)
            {
                HandleErrorResponse(response);
            }

            return(response.Address);
        }