private async Task GetAddress(uint coinNumber) { LedgerManager.SetCoinNumber(coinNumber); var address = await LedgerManager.GetAddressAsync(0, 0); Assert.IsTrue(!string.IsNullOrEmpty(address)); }
public LedgerExternalSigner(LedgerManager ledgerManager, uint index, string customPath) { _index = index; _customPath = customPath; LedgerManager = ledgerManager; LedgerManager.SetCoinNumber(60); }
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}"); }
private void BackgroundWorkerOnRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs args) { var result = (string)args.Result; if (result.StartsWith("ftpregistry:")) { result = result.Split(':')[1].Replace("/", ""); var ledger = LedgerManager.GetLedger(); var settings = SettingsLoader.LoadSettings(); var ledgerRowModel = ledger.FirstOrDefault(e => string.Equals(e.FileIdentifier, result, StringComparison.CurrentCultureIgnoreCase)); if (ledgerRowModel != null) { var ftpFullPath = settings.FtpTargetPath + "//" + ledgerRowModel.FileName; new Downloader("C://", ftpFullPath, true).Start(); } } else { new Uploader(result).Start(); } _backgroundWorker.RunWorkerAsync(); }
public LedgerExternalSigner(LedgerManager ledgerManager, uint index, bool legacyPath = false) { _index = index; _legacyPath = legacyPath; LedgerManager = ledgerManager; LedgerManager.SetCoinNumber(60); }
private async Task GetLedger(ErrorPromptDelegate errorPrompt = null) { var devices = new List <DeviceInformation>(); var collection = WindowsHidDevice.GetConnectedDeviceInformations(); foreach (var ids in WellKnownLedgerWallets) { if (ids.ProductId == null) { devices.AddRange(collection.Where(c => c.VendorId == ids.VendorId)); } else { devices.AddRange(collection.Where(c => c.VendorId == ids.VendorId && c.ProductId == ids.ProductId)); } } var retVal = devices .FirstOrDefault(d => _UsageSpecification == null || _UsageSpecification.Length == 0 || _UsageSpecification.Any(u => d.UsagePage == u.UsagePage && d.Usage == u.Usage)); var ledgerHidDevice = new WindowsHidDevice(retVal); await ledgerHidDevice.InitializeAsync(); _LedgerManager = new LedgerManager(ledgerHidDevice, null, Prompt); }
private void Application_Startup(object sender, StartupEventArgs e) { var applicationPath = System.Reflection.Assembly.GetEntryAssembly()?.Location; var applicationName = Path.GetFileNameWithoutExtension(applicationPath); var isAlreadyRunning = Process.GetProcessesByName(applicationName).Length > 1; if (isAlreadyRunning) { if (e.Args.Length == 0) { return; } NotifyRunningProcess(e.Args.ElementAt(0)); Process.GetCurrentProcess().Kill(); } ContextMenuRegister.Register(); UriRegister.Register(); var settings = SettingsLoader.LoadSettings(); if (!string.IsNullOrEmpty(settings.FtpTargetPath)) { LedgerManager.LoadLedger(); } }
//public class Ledger { // public string cms { get; set; } // public int invoiceNumber { get; set; } // public DateTime date { get; set; } // public int leadID { get; set; } // public DateTime clientPaidDate { get; set; } // public int adjusterID { get; set; } // public DateTime adjusterPaidDate { get; set; } // public decimal totalCommision { get; set; } // public decimal totalExpenses { get; set; } // public decimal adjusterNetAmount { get; set; } // public decimal invoiceTotal { get; set; } // public Ledger(); // public Ledger(string cms, int invoiceNumber, DateTime date, int leadID, DateTime clientPaidDate, int adjusterID, DateTime adjusterPaidDatem, // decimal totalCommision, decimal totalExpenses, decimal adjusterNetAmount, decimal invoiceTotal); //} protected void Page_Load(object sender, EventArgs e) { List <Ledger> ledger = LedgerManager.GetAll(); gvInvoices.DataSource = ledger; gvInvoices.DataBind(); }
/// <summary> /// Sell an amount of the selected item to the merchant /// </summary> /// <param name="amount">The amount to sell</param> public void SellItem(int amount = 1) { if (LedgerManager.ProcessSell(_ship, _warehouse, GameState.assets, _itemList[_selectedItem].ware.id, amount)) { UpdateDisplay(); } }
public async Task TestBitcoinGetAddressAnyApp() { await LedgerManager.SetCoinNumber(); var address = await LedgerManager.GetAddressAsync(0, false, 0, false); Assert.IsTrue(!string.IsNullOrEmpty(address)); }
public async Task TestEthereumGetAddress() { LedgerManager.SetCoinNumber(60); var address = await LedgerManager.GetAddressAsync(0, 0); Console.WriteLine(address); Assert.IsTrue(!string.IsNullOrEmpty(address)); }
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)); }
protected override async Task <byte[]> GetPublicKeyAsync() { var path = GetPath(); var publicKeyResponse = await LedgerManager.SendRequestAsync <EthereumAppGetPublicKeyResponse, EthereumAppGetPublicKeyRequest>(new EthereumAppGetPublicKeyRequest(true, false, path)); if (publicKeyResponse.IsSuccess) { return(publicKeyResponse.PublicKeyData); } throw new Exception(publicKeyResponse.StatusMessage); }
public static ILedgerManager GetLedgerManager() { if (RecordRepository != null && ProjectRepository != null) { LedgerManager ledgerManager = new LedgerManager(RecordRepository, GetParameterManager()); ledgerManager.ManagerEvent += MessageService.Instance.ManagerEventHandler; //ledgerManager.LedgerEvent += LogService.Instance.ManagerEventHandler; return(ledgerManager); } throw new ArgumentNullException("message"); }
public override async Task Initialize() { if (AddressDeriver != null) { return; } var ledgerDevice = await Connect(); var ledgerManager = new LedgerManager(ledgerDevice); AddressDeriver = ledgerManager; }
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); }
protected override void OnStart() { LiveService.StartedHandle.WaitOne(); SignedTransactionManager.Initialize(); var needSetInitial = InitializeLedgerManager(); State.SetAndWait(LedgerStatus.Updated); // TODO initialize if (needSetInitial) { LedgerService.LedgerManager.SetNextLedger(LedgerManager.GetSignedLedger(), null); } }
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)); }
private void UpdateLedger() { FileInfo file = new FileInfo(_localFullPath); var settings = SettingsLoader.LoadSettings(); var ledgerRowModel = new LedgerRowModel { UploadDateTime = DateTime.Now, FileIdentifier = FileIdGenerator.GetIdentifier(), FileName = file.Name, LastDownloadDateTime = DateTime.MinValue, Username = settings.FtpUsername }; LedgerManager.GetManager().AddDatabaseToLedger(ledgerRowModel); LedgerManager.SaveLedger(); }
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)); }
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)); }
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); }
private bool InitializeLedgerManager() { var last = GetLastLedger(); var needSetInitial = false; if (last == null) { last = LoadInitialLedger(); needSetInitial = true; } LedgerManager.Initialize(last, needSetInitial); if (!needSetInitial) { CheckMerkleRoot(); } return(needSetInitial); }
public async Task TestBitcoinDashboardTooManyPrompts() { var lastState = MockLedgerManagerFactory.MockLedgerManagerTransport.CurrentState; Exception lastException = null; try { MockLedgerManagerFactory.MockLedgerManagerTransport.CurrentState = CurrentState.Dashboard; var address = await LedgerManager.GetAddressAsync(0, 0); Assert.IsTrue(!string.IsNullOrEmpty(address)); } catch (TooManyPromptsException tex) { lastException = tex; } Assert.IsTrue(lastException is TooManyPromptsException); MockLedgerManagerFactory.MockLedgerManagerTransport.CurrentState = lastState; }
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}"); }
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); }
public LedgerService(Network network) { LedgerManager = new LedgerManager(network, Logger); commands = new LedgerCommandProcessor(); }
public async Task TestBitcoinDisplayAddress() { var address = await LedgerManager.GetAddressAsync(0, false, 0, true); Assert.IsTrue(!string.IsNullOrEmpty(address)); }
private async Task GetLedgerBase(ErrorPromptDelegate errorPrompt = null) { var ledgerManagerBroker = new LedgerManagerBroker(3000, null, Prompt); _LedgerManager = await ledgerManagerBroker.WaitForFirstDeviceAsync(); }