Ejemplo n.º 1
0
        public async Task GetLiteCoinAddress()
        {
            await GetLedger();

            _LedgerManager.SetCoinNumber(2);
            var address = await _LedgerManager.GetAddressAsync(0, 0);

            Assert.True(!string.IsNullOrEmpty(address));
        }
Ejemplo n.º 2
0
 public LedgerExternalSigner(LedgerManager ledgerManager, uint index, bool legacyPath = false)
 {
     _index        = index;
     _legacyPath   = legacyPath;
     LedgerManager = ledgerManager;
     LedgerManager.SetCoinNumber(60);
 }
Ejemplo n.º 3
0
 public LedgerExternalSigner(LedgerManager ledgerManager, uint index, string customPath)
 {
     _index        = index;
     _customPath   = customPath;
     LedgerManager = ledgerManager;
     LedgerManager.SetCoinNumber(60);
 }
Ejemplo n.º 4
0
        private async Task SignTronTransaction(string transactionRaw, string path, int?expectedDataLength = null)
        {
            LedgerManager.SetCoinNumber(195);

            var transactionData = new List <byte>();

            for (var i = 0; i < transactionRaw.Length; i += 2)
            {
                var byteInHex = transactionRaw.Substring(i, 2);
                transactionData.Add(Convert.ToByte(byteInHex, 16));
            }

            var derivationData = Helpers.GetDerivationPathData(AddressPathBase.Parse <BIP44AddressPath>(path));

            var firstRequest = new TronAppSignatureRequest(derivationData.Concat(transactionData).ToArray());

            //TODO: don't use the RequestHandler directly.
            var response = await LedgerManager.RequestHandler.SendRequestAsync <TronAppSignatureResponse, TronAppSignatureRequest>(firstRequest);

            var data = response.Data;

            var hexAsString = HexDataToString(data);

            Console.WriteLine(hexAsString);

            Console.WriteLine($"Length: {hexAsString.Length}");

            Assert.IsTrue(response.IsSuccess, $"The response failed with a status of: {response.StatusMessage} ({response.ReturnCode})");

            Assert.IsTrue(!expectedDataLength.HasValue || hexAsString.Length == expectedDataLength, $"Expected legnth {expectedDataLength}. Actual: {hexAsString.Length}");
        }
Ejemplo n.º 5
0
        private async Task GetAddress(uint coinNumber)
        {
            LedgerManager.SetCoinNumber(coinNumber);
            var address = await LedgerManager.GetAddressAsync(0, 0);

            Assert.IsTrue(!string.IsNullOrEmpty(address));
        }
Ejemplo n.º 6
0
        public async Task TestBitcoinGetAddressAnyApp()
        {
            await LedgerManager.SetCoinNumber();

            var address = await LedgerManager.GetAddressAsync(0, false, 0, false);

            Assert.IsTrue(!string.IsNullOrEmpty(address));
        }
Ejemplo n.º 7
0
        public async Task TestEthereumGetAddress()
        {
            LedgerManager.SetCoinNumber(60);
            var address = await LedgerManager.GetAddressAsync(0, 0);

            Console.WriteLine(address);

            Assert.IsTrue(!string.IsNullOrEmpty(address));
        }
Ejemplo n.º 8
0
        public async Task TestEthereumDisplayPublicKey()
        {
            LedgerManager.SetCoinNumber(60);
            var addressPath = Helpers.GetDerivationPathData(new BIP44AddressPath(LedgerManager.CurrentCoin.IsSegwit, LedgerManager.CurrentCoin.CoinNumber, 0, false, 0));
            //TODO: don't use the RequestHandler directly.
            var publicKey = await LedgerManager.RequestHandler.SendRequestAsync <EthereumAppGetPublicKeyResponse, EthereumAppGetPublicKeyRequest>(new EthereumAppGetPublicKeyRequest(true, false, addressPath));

            Assert.IsTrue(!string.IsNullOrEmpty(publicKey.PublicKey));
        }
Ejemplo n.º 9
0
        public async Task TestBitcoinGetPublicKey()
        {
            LedgerManager.SetCoinNumber(0);

            var returnResponse = (GetPublicKeyResponseBase)await LedgerManager.CallAndPrompt(_GetPublicKeyFunc,
                                                                                             new CallAndPromptArgs <GetAddressArgs>
            {
                LedgerManager = LedgerManager,
                MemberName    = nameof(_GetPublicKeyFunc),
                Args          = new GetAddressArgs(new BIP44AddressPath(true, 0, 0, false, 0), false)
            });

            Assert.IsTrue(!string.IsNullOrEmpty(returnResponse.PublicKey));
        }
Ejemplo n.º 10
0
        public async Task TestTronDisplayAddress()
        {
            uint coinNumber = 195;
            var  isSegwit   = false;
            var  isChange   = false;
            var  index      = 0;

            LedgerManager.SetCoinNumber(coinNumber);

            //This address seems to match the default address in the Tron app
            var path        = $"m/{(isSegwit ? 49 : 44)}'/{coinNumber}'/{(isChange ? 1 : 0)}'/{0}/{index}";
            var addressPath = AddressPathBase.Parse <BIP44AddressPath>(path);
            var address     = await LedgerManager.GetAddressAsync(addressPath, false, true);

            Assert.IsTrue(!string.IsNullOrEmpty(address));
        }
Ejemplo n.º 11
0
        public async Task TestEthereumGetAddressParsed()
        {
            LedgerManager.SetCoinNumber(60);

            //Modern Path
            var path    = AddressPathBase.Parse <CustomAddressPath>("m/44'/60'/0'/0/0");
            var address = await LedgerManager.GetAddressAsync(path, false, false);

            Assert.IsTrue(!string.IsNullOrEmpty(address));

            //Legacy Path
            path    = AddressPathBase.Parse <CustomAddressPath>("m/44'/60'/0'/0");
            address = await LedgerManager.GetAddressAsync(path, false, false);

            Assert.IsTrue(!string.IsNullOrEmpty(address));
        }
Ejemplo n.º 12
0
        public async Task TestEthereumGetAddresses()
        {
            LedgerManager.SetCoinNumber(60);

            var addressManager = new AddressManager(LedgerManager, new BIP44AddressPathFactory(false, 60));

            //Get 10 addresses with all the trimming
            const int numberOfAddresses = 3;
            const int numberOfAccounts  = 2;
            var       addresses         = await addressManager.GetAddressesAsync(0, numberOfAddresses, numberOfAccounts, true, true);

            Assert.IsTrue(addresses != null);
            Assert.IsTrue(addresses.Accounts != null);
            Assert.IsTrue(addresses.Accounts.Count == numberOfAccounts);
            Assert.IsTrue(addresses.Accounts[0].Addresses.Count == numberOfAddresses);
            Assert.IsTrue(addresses.Accounts[1].Addresses.Count == numberOfAddresses);
            Assert.IsTrue(addresses.Accounts[0].ChangeAddresses.Count == numberOfAddresses);
            Assert.IsTrue(addresses.Accounts[1].ChangeAddresses.Count == numberOfAddresses);
        }
Ejemplo n.º 13
0
        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);

            //TODO: don't use the RequestHandler directly.
            var response = await LedgerManager.RequestHandler.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}");
        }
Ejemplo n.º 14
0
        public async Task TestEthereumGetAddressCustomPath()
        {
            LedgerManager.SetCoinNumber(60);

            //Three elements
            var path    = new uint[] { AddressUtilities.HardenNumber(44), AddressUtilities.HardenNumber(60), 0 };
            var address = await LedgerManager.GetAddressAsync(new CustomAddressPath(path), false, false);

            Assert.IsTrue(!string.IsNullOrEmpty(address));

            //Four elements
            path    = new uint[] { AddressUtilities.HardenNumber(44), AddressUtilities.HardenNumber(60), 0, 1 };
            address = await LedgerManager.GetAddressAsync(new CustomAddressPath(path), false, false);

            Assert.IsTrue(!string.IsNullOrEmpty(address));

            //Two elements
            path    = new uint[] { AddressUtilities.HardenNumber(44), AddressUtilities.HardenNumber(60) };
            address = await LedgerManager.GetAddressAsync(new CustomAddressPath(path), false, false);

            Assert.IsTrue(!string.IsNullOrEmpty(address));

            LedgerManager.ErrorPrompt = ThrowErrorInsteadOfPrompt;

            Exception exception = null;;

            try
            {
                //The ethereum app doesn't like this Purpose (49)
                path    = new uint[] { AddressUtilities.HardenNumber(49), AddressUtilities.HardenNumber(60), AddressUtilities.HardenNumber(0), 0, 0 };
                address = await LedgerManager.GetAddressAsync(new CustomAddressPath(path), false, false);
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            Assert.IsTrue(exception != null);
        }