diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index 32df3a015..21f7a500b 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -2,7 +2,7 @@ Exe netcoreapp2.0 - 1.0.1.50 + 1.0.1.51 NU1701,CA1816,CA1308,CA1810,CA2208 diff --git a/BTCPayServer/Controllers/StoresController.BTCLike.cs b/BTCPayServer/Controllers/StoresController.BTCLike.cs index 8ad036521..03d307930 100644 --- a/BTCPayServer/Controllers/StoresController.BTCLike.cs +++ b/BTCPayServer/Controllers/StoresController.BTCLike.cs @@ -129,6 +129,8 @@ namespace BTCPayServer.Controllers string command, // getinfo string cryptoCode = null, + // getxpub + int account = 0, // sendtoaddress string destination = null, string amount = null, string feeRate = null, string substractFees = null ) @@ -204,7 +206,9 @@ namespace BTCPayServer.Controllers } if (command == "getxpub") { - result = await hw.GetExtPubKey(network); + var getxpubResult = await hw.GetExtPubKey(network, account); ; + getxpubResult.CoinType = (int)(getxpubResult.KeyPath.Indexes[1] - 0x80000000); + result = getxpubResult; } if (command == "getinfo") { diff --git a/BTCPayServer/Services/HardwareWalletService.cs b/BTCPayServer/Services/HardwareWalletService.cs index e30fa5cf5..922403108 100644 --- a/BTCPayServer/Services/HardwareWalletService.cs +++ b/BTCPayServer/Services/HardwareWalletService.cs @@ -8,6 +8,7 @@ using BTCPayServer.Services.Wallets; using LedgerWallet; using NBitcoin; using NBXplorer.DerivationStrategy; +using Newtonsoft.Json; namespace BTCPayServer.Services { @@ -76,18 +77,19 @@ namespace BTCPayServer.Services return new LedgerTestResult() { Success = true }; } - public async Task GetExtPubKey(BTCPayNetwork network) + public async Task GetExtPubKey(BTCPayNetwork network, int account) { if (network == null) throw new ArgumentNullException(nameof(network)); - var pubkey = await GetExtPubKey(_Ledger, network, new KeyPath("49'").Derive(network.CoinType).Derive(0, true), false); + var path = new KeyPath("49'").Derive(network.CoinType).Derive(account, true); + var pubkey = await GetExtPubKey(_Ledger, network, path, false); var derivation = new DerivationStrategyFactory(network.NBitcoinNetwork).CreateDirectDerivationStrategy(pubkey, new DerivationStrategyOptions() { P2SH = true, Legacy = false }); - return new GetXPubResult() { ExtPubKey = derivation.ToString() }; + return new GetXPubResult() { ExtPubKey = derivation.ToString(), KeyPath = path }; } private static async Task GetExtPubKey(LedgerClient ledger, BTCPayNetwork network, KeyPath account, bool onlyChaincode) @@ -231,5 +233,8 @@ namespace BTCPayServer.Services public class GetXPubResult { public string ExtPubKey { get; set; } + [JsonConverter(typeof(NBitcoin.JsonConverters.KeyPathJsonConverter))] + public KeyPath KeyPath { get; set; } + public int CoinType { get; internal set; } } } diff --git a/BTCPayServer/Views/Stores/AddDerivationScheme.cshtml b/BTCPayServer/Views/Stores/AddDerivationScheme.cshtml index 6be492c03..1fcdac6da 100644 --- a/BTCPayServer/Views/Stores/AddDerivationScheme.cshtml +++ b/BTCPayServer/Views/Stores/AddDerivationScheme.cshtml @@ -16,101 +16,107 @@ @if(!Model.Confirmation) - { - - Derivation Scheme - The DerivationScheme represents the destination of the funds received by your invoice. It is generated by your wallet software. Please, verify that you are generating the right addresses by clicking on 'Check ExtPubKey' - - - - - - - - - - - - No ledger wallet detected. If you own one, use chrome, open the app, and refresh this page. - - - A ledger wallet is detected, please use our recommended choice - - - - - - - - BTCPay format memo - - - - Address type - Example - - - - - P2WPKH - xpub - - - P2SH-P2WPKH - xpub-[p2sh] - - - P2PKH - xpub-[legacy] - - - Multi-sig P2WSH - 2-of-xpub1-xpub2 - - - Multi-sig P2SH-P2WSH - 2-of-xpub1-xpub2-[p2sh] - - - Multi-sig P2SH - 2-of-xpub1-xpub2-[legacy] - - - - - Continue -} -else -{ - - Confirm the addresses (@Model.CryptoCurrency) - Please check that your @Model.CryptoCurrency wallet is generating the same addresses as below. - - - - - - - - - - Key path - Address - - - - @foreach(var sample in Model.AddressSamples) { - - @sample.KeyPath - @sample.Address - - } - - - - Confirm -} + + Derivation Scheme + The DerivationScheme represents the destination of the funds received by your invoice. It is generated by your wallet software. Please, verify that you are generating the right addresses by clicking on 'Check ExtPubKey' + + + + + + + + + + + + No ledger wallet detected. If you own one, use chrome, open the app, and refresh this page. + + + A ledger wallet is detected, which account do you want to use? + + @for(int i = 0; i < 4; i++) + { + Account @i (49'/0'/@i') + } + + + + + + + + + BTCPay format memo + + + + Address type + Example + + + + + P2WPKH + xpub + + + P2SH-P2WPKH + xpub-[p2sh] + + + P2PKH + xpub-[legacy] + + + Multi-sig P2WSH + 2-of-xpub1-xpub2 + + + Multi-sig P2SH-P2WSH + 2-of-xpub1-xpub2-[p2sh] + + + Multi-sig P2SH + 2-of-xpub1-xpub2-[legacy] + + + + + Continue + } + else + { + + Confirm the addresses (@Model.CryptoCurrency) + Please check that your @Model.CryptoCurrency wallet is generating the same addresses as below. + + + + + + + + + + Key path + Address + + + + @foreach(var sample in Model.AddressSamples) + { + + @sample.KeyPath + @sample.Address + + } + + + + Confirm + } diff --git a/BTCPayServer/wwwroot/js/StoreAddDerivationScheme.js b/BTCPayServer/wwwroot/js/StoreAddDerivationScheme.js index 5dd495e8a..0a5d3c86c 100644 --- a/BTCPayServer/wwwroot/js/StoreAddDerivationScheme.js +++ b/BTCPayServer/wwwroot/js/StoreAddDerivationScheme.js @@ -1,8 +1,12 @@ $(function () { var ledgerDetected = false; - var recommendedPubKey = ""; var bridge = new ledgerwebsocket.LedgerWebSocketBridge(srvModel + "ws/ledger"); + var cryptoSelector = $("#CryptoCurrency"); + function GetSelectedCryptoCode() { + return cryptoSelector.val(); + } + function WriteAlert(type, message) { } @@ -14,10 +18,18 @@ } } - $("#ledger-info-recommended").on("click", function (elem) { + $(".ledger-info-recommended").on("click", function (elem) { elem.preventDefault(); - $("#DerivationScheme").val(recommendedPubKey); - $("#DerivationSchemeFormat").val("BTCPay"); + var account = elem.currentTarget.getAttribute("data-ledgeraccount"); + var cryptoCode = GetSelectedCryptoCode(); + bridge.sendCommand("getxpub", "cryptoCode=" + cryptoCode + "&account=" + account) + .then(function (result) { + if (cryptoCode !== GetSelectedCryptoCode()) + return; + $("#DerivationScheme").val(result.extPubKey); + $("#DerivationSchemeFormat").val("BTCPay"); + }) + .catch(function (reason) { Write('check', 'error', reason); }); return false; }); @@ -30,21 +42,23 @@ var updateInfo = function () { if (!ledgerDetected) return false; - var cryptoCode = $("#CryptoCurrency").val(); + var cryptoCode = GetSelectedCryptoCode(); bridge.sendCommand("getxpub", "cryptoCode=" + cryptoCode) .catch(function (reason) { Write('check', 'error', reason); }) .then(function (result) { if (!result) return; + if (cryptoCode !== GetSelectedCryptoCode()) + return; if (result.error) { Write('check', 'error', result.error); return; } else { Write('check', 'success', 'This store is configured to use your ledger'); - recommendedPubKey = result.extPubKey; $("#no-ledger-info").css("display", "none"); $("#ledger-info").css("display", "block"); + $(".ledger-info-cointype").text(result.coinType); } }); };
- No ledger wallet detected. If you own one, use chrome, open the app, and refresh this page. -
- A ledger wallet is detected, please use our recommended choice -
+ No ledger wallet detected. If you own one, use chrome, open the app, and refresh this page. +