mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
View seed option if available (#1518)
This commit is contained in:
@@ -26,6 +26,7 @@ using Newtonsoft.Json.Linq;
|
|||||||
using BTCPayServer.Logging;
|
using BTCPayServer.Logging;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using BTCPayServer.Client;
|
using BTCPayServer.Client;
|
||||||
|
using NBXplorer;
|
||||||
|
|
||||||
namespace BTCPayServer.Controllers
|
namespace BTCPayServer.Controllers
|
||||||
{
|
{
|
||||||
@@ -53,6 +54,9 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
vm.DerivationScheme = derivation.AccountDerivation.ToString();
|
vm.DerivationScheme = derivation.AccountDerivation.ToString();
|
||||||
vm.Config = derivation.ToJson();
|
vm.Config = derivation.ToJson();
|
||||||
|
vm.NBXSeedAvailable = (await CanUseHotWallet() ).HotWallet && !string.IsNullOrEmpty(await _ExplorerProvider.GetExplorerClient(network)
|
||||||
|
.GetMetadataAsync<string>(derivation.AccountDerivation,
|
||||||
|
WellknownMetadataKeys.Mnemonic));
|
||||||
}
|
}
|
||||||
vm.Enabled = !store.GetStoreBlob().IsExcluded(new PaymentMethodId(vm.CryptoCode, PaymentTypes.BTCLike));
|
vm.Enabled = !store.GetStoreBlob().IsExcluded(new PaymentMethodId(vm.CryptoCode, PaymentTypes.BTCLike));
|
||||||
var hotWallet = await CanUseHotWallet();
|
var hotWallet = await CanUseHotWallet();
|
||||||
@@ -60,6 +64,50 @@ namespace BTCPayServer.Controllers
|
|||||||
vm.CanUseRPCImport = hotWallet.RPCImport;
|
vm.CanUseRPCImport = hotWallet.RPCImport;
|
||||||
return View(vm);
|
return View(vm);
|
||||||
}
|
}
|
||||||
|
[HttpPost]
|
||||||
|
[Route("{storeId}/derivations/{cryptoCode}/seed")]
|
||||||
|
[ApiExplorerSettings(IgnoreApi = true)]
|
||||||
|
public async Task<IActionResult> ViewSeed(string storeId, string cryptoCode)
|
||||||
|
{
|
||||||
|
var store = HttpContext.GetStoreData();
|
||||||
|
if (store == null)
|
||||||
|
return NotFound();
|
||||||
|
var network = cryptoCode == null ? null : _ExplorerProvider.GetNetwork(cryptoCode);
|
||||||
|
if (network == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
var derivation = GetExistingDerivationStrategy(cryptoCode, store);
|
||||||
|
if (derivation == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
var canExtract = (await CanUseHotWallet()).HotWallet;
|
||||||
|
|
||||||
|
var seed = await _ExplorerProvider.GetExplorerClient(network)
|
||||||
|
.GetMetadataAsync<string>(derivation.AccountDerivation,
|
||||||
|
WellknownMetadataKeys.Mnemonic);
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(seed))
|
||||||
|
{
|
||||||
|
TempData.SetStatusMessageModel(new StatusMessageModel()
|
||||||
|
{
|
||||||
|
Severity = StatusMessageModel.StatusSeverity.Error,
|
||||||
|
Message = "The seed was not found"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TempData.SetStatusMessageModel(new StatusMessageModel()
|
||||||
|
{
|
||||||
|
Severity = StatusMessageModel.StatusSeverity.Success,
|
||||||
|
Html = $"Please store your seed securely! <br/><code class=\"alert-link\">{seed}</code>"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return RedirectToAction(nameof(UpdateStore), new { storeId });
|
||||||
|
}
|
||||||
|
|
||||||
class GetXPubs
|
class GetXPubs
|
||||||
{
|
{
|
||||||
@@ -163,6 +211,7 @@ namespace BTCPayServer.Controllers
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vm.NBXSeedAvailable = false;
|
||||||
vm.Network = network;
|
vm.Network = network;
|
||||||
vm.RootKeyPath = network.GetRootKeyPath();
|
vm.RootKeyPath = network.GetRootKeyPath();
|
||||||
DerivationSchemeSettings strategy = null;
|
DerivationSchemeSettings strategy = null;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace BTCPayServer.Models.StoreViewModels
|
|||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
} = new List<(string KeyPath, string Address, RootedKeyPath RootedKeyPath)>();
|
} = new List<(string KeyPath, string Address, RootedKeyPath RootedKeyPath)>();
|
||||||
|
public bool NBXSeedAvailable { get; set; }
|
||||||
public string CryptoCode { get; set; }
|
public string CryptoCode { get; set; }
|
||||||
public string KeyPath { get; set; }
|
public string KeyPath { get; set; }
|
||||||
public string RootFingerprint { get; set; }
|
public string RootFingerprint { get; set; }
|
||||||
|
|||||||
@@ -55,14 +55,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@if (!Model.Confirmation)
|
||||||
|
{
|
||||||
<form method="post" asp-action="AddDerivationScheme"
|
<form method="post" asp-action="AddDerivationScheme"
|
||||||
asp-route-cryptoCode="@Model.CryptoCode"
|
asp-route-cryptoCode="@Model.CryptoCode"
|
||||||
asp-route-storeId="@this.Context.GetRouteValue("storeId")">
|
asp-route-storeId="@this.Context.GetRouteValue("storeId")">
|
||||||
|
|
||||||
<input id="Config" asp-for="Config" type="hidden"/>
|
<input id="Config" asp-for="Config" type="hidden"/>
|
||||||
|
|
||||||
@if (!Model.Confirmation)
|
|
||||||
{
|
|
||||||
<input id="CryptoCurrency" asp-for="CryptoCode" type="hidden"/>
|
<input id="CryptoCurrency" asp-for="CryptoCode" type="hidden"/>
|
||||||
<input id="DerivationSchemeFormat" asp-for="DerivationSchemeFormat" type="hidden"/>
|
<input id="DerivationSchemeFormat" asp-for="DerivationSchemeFormat" type="hidden"/>
|
||||||
<input id="AccountKey" asp-for="AccountKey" type="hidden"/>
|
<input id="AccountKey" asp-for="AccountKey" type="hidden"/>
|
||||||
@@ -155,9 +156,21 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button name="command" type="submit" class="btn btn-primary" value="save" id="Continue">Continue</button>
|
<button name="command" type="submit" class="btn btn-primary" value="save" id="Continue">Continue</button>
|
||||||
|
</form>
|
||||||
|
@if (Model.NBXSeedAvailable)
|
||||||
|
{
|
||||||
|
<form asp-action="ViewSeed" asp-route-cryptoCode="@Model.CryptoCode" asp-route-storeId="@Context.GetRouteValue("storeId")">
|
||||||
|
<button type="submit" class="btn btn-link">View seed</button>
|
||||||
|
</form>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
<form method="post" asp-action="AddDerivationScheme"
|
||||||
|
asp-route-cryptoCode="@Model.CryptoCode"
|
||||||
|
asp-route-storeId="@this.Context.GetRouteValue("storeId")">
|
||||||
|
|
||||||
|
<input id="Config" asp-for="Config" type="hidden"/>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<h5>Confirm the addresses (@Model.CryptoCode)</h5>
|
<h5>Confirm the addresses (@Model.CryptoCode)</h5>
|
||||||
<span>Please check that your @Model.CryptoCode wallet is generating the same addresses as below.</span>
|
<span>Please check that your @Model.CryptoCode wallet is generating the same addresses as below.</span>
|
||||||
@@ -185,7 +198,9 @@
|
|||||||
<td>@sample.Address</td>
|
<td>@sample.Address</td>
|
||||||
@if (Model.Source == "Vault")
|
@if (Model.Source == "Vault")
|
||||||
{
|
{
|
||||||
<td><a class="showaddress" href="#" onclick='showAddress(@Safe.Json(sample.RootedKeyPath.ToString()), @Safe.Json(sample.Address)); return false;'>Show on device</a></td>
|
<td>
|
||||||
|
<a class="showaddress" href="#" onclick='showAddress(@Safe.Json(sample.RootedKeyPath.ToString()), @Safe.Json(sample.Address)); return false;'>Show on device</a>
|
||||||
|
</td>
|
||||||
}
|
}
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
@@ -203,10 +218,11 @@
|
|||||||
<span asp-validation-for="HintAddress" class="text-danger"></span>
|
<span asp-validation-for="HintAddress" class="text-danger"></span>
|
||||||
</div>
|
</div>
|
||||||
<button name="command" type="submit" class="btn btn-primary" value="save" id="Confirm">Confirm</button>
|
<button name="command" type="submit" class="btn btn-primary" value="save" id="Confirm">Confirm</button>
|
||||||
}
|
|
||||||
</form>
|
</form>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@section Scripts {
|
@section Scripts {
|
||||||
@await Html.PartialAsync("_ValidationScriptsPartial")
|
@await Html.PartialAsync("_ValidationScriptsPartial")
|
||||||
<script src="~/js/ledgerwebsocket.js" type="text/javascript" defer="defer" asp-append-version="true"></script>
|
<script src="~/js/ledgerwebsocket.js" type="text/javascript" defer="defer" asp-append-version="true"></script>
|
||||||
|
|||||||
Reference in New Issue
Block a user