mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
Fix: No need to select the Signing Key for signing through multi sig process (#6674)
This commit is contained in:
@@ -93,7 +93,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
request.ExistingMnemonic is null ? "NBXplorerGenerated" : "ImportedSeed";
|
||||
derivationSchemeSettings.IsHotWallet = request.SavePrivateKeys;
|
||||
derivationSchemeSettings.Label = request.Label;
|
||||
var accountSettings = derivationSchemeSettings.GetSigningAccountKeySettings();
|
||||
var accountSettings = derivationSchemeSettings.AccountKeySettings[0];
|
||||
accountSettings.AccountKeyPath = response.AccountKeyPath.KeyPath;
|
||||
accountSettings.RootFingerprint = response.AccountKeyPath.MasterFingerprint;
|
||||
derivationSchemeSettings.AccountOriginal = response.DerivationScheme.ToString();
|
||||
|
||||
@@ -582,9 +582,13 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
|
||||
var signingKey = ExtKey.Parse(signingKeyStr, network.NBitcoinNetwork);
|
||||
|
||||
var signingKeySettings = derivationScheme.GetSigningAccountKeySettings();
|
||||
signingKeySettings.RootFingerprint ??= signingKey.GetPublicKey().GetHDFingerPrint();
|
||||
RootedKeyPath rootedKeyPath = signingKeySettings.GetRootedKeyPath();
|
||||
var signingKeySettings = derivationScheme.GetSigningAccountKeySettings(signingKey);
|
||||
RootedKeyPath? rootedKeyPath = signingKeySettings?.GetRootedKeyPath();
|
||||
if (rootedKeyPath is null || signingKeySettings is null)
|
||||
{
|
||||
return this.CreateAPIError(503, "not-available",
|
||||
"The private key saved for this wallet doesn't match the derivation scheme");
|
||||
}
|
||||
psbt.PSBT.RebaseKeyPaths(signingKeySettings.AccountKey, rootedKeyPath);
|
||||
var accountKey = signingKey.Derive(rootedKeyPath.KeyPath);
|
||||
|
||||
|
||||
@@ -310,7 +310,7 @@ public partial class UIStoresController
|
||||
derivationSchemeSettings.IsHotWallet = method == WalletSetupMethod.HotWallet;
|
||||
}
|
||||
|
||||
var accountSettings = derivationSchemeSettings.GetSigningAccountKeySettings();
|
||||
var accountSettings = derivationSchemeSettings.AccountKeySettings[0];
|
||||
accountSettings.AccountKeyPath = response.AccountKeyPath.KeyPath;
|
||||
accountSettings.RootFingerprint = response.AccountKeyPath.MasterFingerprint;
|
||||
derivationSchemeSettings.AccountOriginal = response.DerivationScheme.ToString();
|
||||
|
||||
@@ -1476,29 +1476,26 @@ namespace BTCPayServer.Controllers
|
||||
var settings = GetDerivationSchemeSettings(walletId);
|
||||
if (settings is null)
|
||||
return NotFound();
|
||||
var signingKeySettings = settings.GetSigningAccountKeySettings();
|
||||
if (signingKeySettings.RootFingerprint is null)
|
||||
signingKeySettings.RootFingerprint = extKey.GetPublicKey().GetHDFingerPrint();
|
||||
|
||||
RootedKeyPath rootedKeyPath = signingKeySettings.GetRootedKeyPath();
|
||||
if (rootedKeyPath == null)
|
||||
var signingKeySettings = settings.GetSigningAccountKeySettings(extKey);
|
||||
if (signingKeySettings is null)
|
||||
{
|
||||
// Let's try best effort if RootFingerprint isn't configured, but AccountKeyPath is
|
||||
signingKeySettings = settings.AccountKeySettings
|
||||
.Where(a => a.RootFingerprint is null && a.AccountKeyPath is not null)
|
||||
.FirstOrDefault();
|
||||
if (signingKeySettings is not null)
|
||||
signingKeySettings.RootFingerprint = extKey.GetPublicKey().GetHDFingerPrint();
|
||||
}
|
||||
RootedKeyPath? rootedKeyPath = signingKeySettings?.GetRootedKeyPath();
|
||||
if (rootedKeyPath is null || signingKeySettings is null)
|
||||
{
|
||||
ModelState.AddModelError(nameof(viewModel.SeedOrKey),
|
||||
"The master fingerprint and/or account key path of your seed are not set in the wallet settings.");
|
||||
return View(nameof(SignWithSeed), viewModel);
|
||||
}
|
||||
// The user gave the root key, let's try to rebase the PSBT, and derive the account private key
|
||||
if (rootedKeyPath.MasterFingerprint == extKey.GetPublicKey().GetHDFingerPrint())
|
||||
{
|
||||
psbt.RebaseKeyPaths(signingKeySettings.AccountKey, rootedKeyPath);
|
||||
signingKey = extKey.Derive(rootedKeyPath.KeyPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
ModelState.AddModelError(nameof(viewModel.SeedOrKey),
|
||||
"The master fingerprint does not match the one set in your wallet settings. Probable causes are: wrong seed, wrong passphrase or wrong fingerprint in your wallet settings.");
|
||||
return View(nameof(SignWithSeed), viewModel);
|
||||
}
|
||||
psbt.RebaseKeyPaths(signingKeySettings.AccountKey, rootedKeyPath);
|
||||
signingKey = extKey.Derive(rootedKeyPath.KeyPath);
|
||||
|
||||
psbt.Settings.SigningOptions = new SigningOptions()
|
||||
{
|
||||
|
||||
@@ -78,16 +78,26 @@ namespace BTCPayServer
|
||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public BitcoinExtPubKey ExplicitAccountKey { get; set; }
|
||||
|
||||
#nullable enable
|
||||
public AccountKeySettings GetSigningAccountKeySettings()
|
||||
{
|
||||
return (AccountKeySettings ?? []).Single(a => a.AccountKey == SigningKey);
|
||||
}
|
||||
|
||||
public AccountKeySettings GetSigningAccountKeySettingsOrDefault()
|
||||
public AccountKeySettings? GetSigningAccountKeySettings(IHDKey rootKey)
|
||||
=> GetSigningAccountKeySettings(rootKey.GetPublicKey().GetHDFingerPrint());
|
||||
|
||||
public AccountKeySettings? GetSigningAccountKeySettings(HDFingerprint rootFingerprint)
|
||||
{
|
||||
return (AccountKeySettings ?? []).Where(a => a.RootFingerprint == rootFingerprint).FirstOrDefault();
|
||||
}
|
||||
|
||||
|
||||
public AccountKeySettings? GetSigningAccountKeySettingsOrDefault()
|
||||
{
|
||||
return (AccountKeySettings ?? []).SingleOrDefault(a => a.AccountKey == SigningKey);
|
||||
}
|
||||
|
||||
#nullable restore
|
||||
public AccountKeySettings[] AccountKeySettings { get; set; }
|
||||
|
||||
public IEnumerable<NBXplorer.Models.PSBTRebaseKeyRules> GetPSBTRebaseKeyRules()
|
||||
|
||||
Reference in New Issue
Block a user