From 5571413a78da773d7495fed1fbd6f8f21bba5a1c Mon Sep 17 00:00:00 2001 From: Andrew Camilleri Date: Sat, 25 May 2019 02:45:36 +0000 Subject: [PATCH] Put Ledger Wallet pairing in a popup, prepare code for Trezor pairing (#836) * Allowing for POS to be displayed at website root * Switching to asp attributes for form post action * Applying default formatting rules on HTML * The destination pays mining fees => Subtract fees from amount * small cleanup (#851) * Part2: Openiddict: Init OpenIddict & Database Migration & Auth Policies (#567) * Part 1: OpenIddict - Minor Changes & Config prep * Part 1: OpenIddict - Minor Changes & Config prep * Part2: Openiddict: Init OpenIddict & Database Migration & Auth Policies * pr changes * pr changes * fix merge * pr fixes * remove config for openid -- no need for it for now * fix compile * fix compile #2 * remove extra ns using * Update Startup.cs * compile * adjust settings a bit * remove duplicate * remove external login provider placeholder html * remove unused directives * regenerate db snapshot model * Remove dynamic policy * Provide Pretty descriptions for payment methods from their handlers (#852) * small cleanup * Provide Pretty descriptions for payment methods from their handlers * remove PrettyMethod() * integration with trezor * rough load xpub from trezor * update deriv scheme trezor * move ledger import to dialog * add import from hw wallet dropdown * Support temporary links for local file system provider (#848) * wip * Support temporary links for local file system provider * pass base url to file services * fix test * do not crash on errors with local filesystem * remove console * fix paranthesis * work on trezor.net integration * pushed non compiling sign wallet code * comment out wallet code * abstract ledger ws in add deriv * Auto stash before merge of "trezor" and "btcpayserver/master" * final add changes * cleanup * improve connectivity and fix e2e tests * fix selenium * add experimental warning for trezor * move import button to right and convert to text link * switch to defer and async scripts in add deriv scheme * make defer not async * more elaborate import trezor dialog * Fix small issues * hide trezor for now --- BTCPayServer.Common/BTCPayNetwork.cs | 28 +++ BTCPayServer.Tests/SeleniumTester.cs | 2 +- .../Controllers/StoresController.BTCLike.cs | 4 + BTCPayServer/Models/StatusMessageModel.cs | 7 +- .../DerivationSchemeViewModel.cs | 1 + .../Views/Shared/_StatusMessage.cshtml | 11 +- .../Views/Stores/AddDerivationScheme.cshtml | 79 +++----- ...vationSchemes_HardwareWalletDialogs.cshtml | 171 ++++++++++++++++++ .../wwwroot/js/StoreAddDerivationScheme.js | 17 +- .../js/trezor/trezor-add-derivation-scheme.js | 81 +++++++++ .../wwwroot/js/trezor/trezor-client.js | 73 ++++++++ BTCPayServer/wwwroot/vendor/trezor/README.md | 1 + .../vendor/trezor/trezor.js-umd.min.js | 64 +++++++ 13 files changed, 475 insertions(+), 64 deletions(-) create mode 100644 BTCPayServer/Views/Stores/AddDerivationSchemes_HardwareWalletDialogs.cshtml create mode 100644 BTCPayServer/wwwroot/js/trezor/trezor-add-derivation-scheme.js create mode 100644 BTCPayServer/wwwroot/js/trezor/trezor-client.js create mode 100644 BTCPayServer/wwwroot/vendor/trezor/README.md create mode 100644 BTCPayServer/wwwroot/vendor/trezor/trezor.js-umd.min.js diff --git a/BTCPayServer.Common/BTCPayNetwork.cs b/BTCPayServer.Common/BTCPayNetwork.cs index 6b2e41099..6cceb9363 100644 --- a/BTCPayServer.Common/BTCPayNetwork.cs +++ b/BTCPayServer.Common/BTCPayNetwork.cs @@ -73,6 +73,34 @@ namespace BTCPayServer { return CryptoCode; } + + public KeyPath GetRootKeyPath(DerivationType type) + { + KeyPath baseKey; + if (!NBitcoinNetwork.Consensus.SupportSegwit) + { + baseKey = new KeyPath("44'"); + } + else + { + switch (type) + { + case DerivationType.Legacy: + baseKey = new KeyPath("44'"); + break; + case DerivationType.SegwitP2SH: + baseKey = new KeyPath("49'"); + break; + case DerivationType.Segwit: + baseKey = new KeyPath("84'"); + break; + default: + throw new ArgumentOutOfRangeException(nameof(type), type, null); + } + } + return baseKey + .Derive(CoinType); + } public KeyPath GetRootKeyPath() { diff --git a/BTCPayServer.Tests/SeleniumTester.cs b/BTCPayServer.Tests/SeleniumTester.cs index 2bcf20365..ac2343a0c 100644 --- a/BTCPayServer.Tests/SeleniumTester.cs +++ b/BTCPayServer.Tests/SeleniumTester.cs @@ -80,7 +80,7 @@ namespace BTCPayServer.Tests public void AddDerivationScheme(string derivationScheme = "xpub661MyMwAqRbcGABgHMUXDzPzH1tU7eZaAaJQXhDXsSxsqyQzQeU6kznNfSuAyqAK9UaWSaZaMFdNiY5BCF4zBPAzSnwfUAwUhwttuAKwfRX-[legacy]") { Driver.FindElement(By.Id("ModifyBTC")).ForceClick(); - Driver.FindElement(By.Id("DerivationScheme")).SendKeys(derivationScheme); + Driver.FindElement(By.ClassName("store-derivation-scheme")).SendKeys(derivationScheme); Driver.FindElement(By.Id("Continue")).ForceClick(); Driver.FindElement(By.Id("Confirm")).ForceClick(); Driver.FindElement(By.Id("Save")).ForceClick(); diff --git a/BTCPayServer/Controllers/StoresController.BTCLike.cs b/BTCPayServer/Controllers/StoresController.BTCLike.cs index 80bfefc3f..5aed76201 100644 --- a/BTCPayServer/Controllers/StoresController.BTCLike.cs +++ b/BTCPayServer/Controllers/StoresController.BTCLike.cs @@ -39,6 +39,7 @@ namespace BTCPayServer.Controllers DerivationSchemeViewModel vm = new DerivationSchemeViewModel(); vm.CryptoCode = cryptoCode; vm.RootKeyPath = network.GetRootKeyPath(); + vm.Network = network; SetExistingValues(store, vm); return View(vm); } @@ -119,6 +120,8 @@ namespace BTCPayServer.Controllers return new EmptyResult(); } + + private void SetExistingValues(StoreData store, DerivationSchemeViewModel vm) { var derivation = GetExistingDerivationStrategy(vm.CryptoCode, store); @@ -157,6 +160,7 @@ namespace BTCPayServer.Controllers return NotFound(); } + vm.Network = network; vm.RootKeyPath = network.GetRootKeyPath(); DerivationSchemeSettings strategy = null; diff --git a/BTCPayServer/Models/StatusMessageModel.cs b/BTCPayServer/Models/StatusMessageModel.cs index 9c70d3818..2b63fece6 100644 --- a/BTCPayServer/Models/StatusMessageModel.cs +++ b/BTCPayServer/Models/StatusMessageModel.cs @@ -23,6 +23,7 @@ namespace BTCPayServer.Models Html = model.Html; Message = model.Message; Severity = model.Severity; + AllowDismiss = model.AllowDismiss; } else { @@ -38,6 +39,7 @@ namespace BTCPayServer.Models public string Message { get; set; } public string Html { get; set; } public StatusSeverity Severity { get; set; } + public bool AllowDismiss { get; set; } = true; public string SeverityCSS { @@ -51,6 +53,8 @@ namespace BTCPayServer.Models return "danger"; case StatusSeverity.Success: return "success"; + case StatusSeverity.Warning: + return "warning"; default: throw new ArgumentOutOfRangeException(); } @@ -74,7 +78,8 @@ namespace BTCPayServer.Models { Info, Error, - Success + Success, + Warning } } } diff --git a/BTCPayServer/Models/StoreViewModels/DerivationSchemeViewModel.cs b/BTCPayServer/Models/StoreViewModels/DerivationSchemeViewModel.cs index 44cb24a75..e176c691e 100644 --- a/BTCPayServer/Models/StoreViewModels/DerivationSchemeViewModel.cs +++ b/BTCPayServer/Models/StoreViewModels/DerivationSchemeViewModel.cs @@ -40,5 +40,6 @@ namespace BTCPayServer.Models.StoreViewModels public string Config { get; set; } public string Source { get; set; } public string AccountKey { get; set; } + public BTCPayNetwork Network { get; set; } } } diff --git a/BTCPayServer/Views/Shared/_StatusMessage.cshtml b/BTCPayServer/Views/Shared/_StatusMessage.cshtml index 84a26635d..2d86ab5af 100644 --- a/BTCPayServer/Views/Shared/_StatusMessage.cshtml +++ b/BTCPayServer/Views/Shared/_StatusMessage.cshtml @@ -1,10 +1,15 @@ @model string -@if(!string.IsNullOrEmpty(Model)) +@if (!string.IsNullOrEmpty(Model)) { var parsedModel = new StatusMessageModel(Model); -