mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 06:24:24 +01:00
Remove useless code (#6817)
* Remove unused code * Obsolete SigningKey concept
This commit is contained in:
@@ -1166,11 +1166,11 @@ bc1qfzu57kgu5jthl934f9xrdzzx8mmemx7gn07tf0grnvz504j6kzusu2v0ku
|
||||
""";
|
||||
Assert.True(parsers.TryParseWalletFile(electrumText, mainnet, out electrum, out _));
|
||||
Assert.Equal("ElectrumFile", electrum.Source);
|
||||
Assert.Equal("0'", electrum.GetSigningAccountKeySettings().AccountKeyPath.ToString());
|
||||
Assert.Equal("0'", electrum.GetFirstAccountKeySettings().AccountKeyPath.ToString());
|
||||
Assert.True(electrum.AccountDerivation is DirectDerivationStrategy { Segwit: true });
|
||||
Assert.Equal("fbb5b37d", electrum.GetSigningAccountKeySettings().RootFingerprint.ToString());
|
||||
Assert.Equal("fbb5b37d", electrum.GetFirstAccountKeySettings().RootFingerprint.ToString());
|
||||
Assert.Equal("zpub6oQLDcJLztdMD29C8D8eyZKdKVfX9txB4BxZsMif9avJZBdVWPg1wmK3Uh3VxU7KXon1wm1xzvjyqmKWguYMqyjKP5f5Cho9f7uLfmRt2Br", electrum.AccountOriginal);
|
||||
Assert.Equal(((DirectDerivationStrategy)electrum.AccountDerivation).GetExtPubKeys().First().ParentFingerprint.ToString(), electrum.GetSigningAccountKeySettings().RootFingerprint.ToString());
|
||||
Assert.Equal(((DirectDerivationStrategy)electrum.AccountDerivation).GetExtPubKeys().First().ParentFingerprint.ToString(), electrum.GetFirstAccountKeySettings().RootFingerprint.ToString());
|
||||
|
||||
// Electrum with strange garbage at the end caused by the lightning support
|
||||
electrumText =
|
||||
|
||||
@@ -471,7 +471,7 @@ namespace BTCPayServer.Tests
|
||||
}
|
||||
|
||||
var derivationSchemeSettings = alice.GetController<UIWalletsController>().GetDerivationSchemeSettings(new WalletId(alice.StoreId, "BTC"));
|
||||
var signingAccount = derivationSchemeSettings.GetSigningAccountKeySettings();
|
||||
var signingAccount = derivationSchemeSettings.GetFirstAccountKeySettings();
|
||||
psbt.SignAll(derivationSchemeSettings.AccountDerivation, alice.GenerateWalletResponseV.AccountHDKey, signingAccount.GetRootedKeyPath());
|
||||
using var fakeServer = new FakeServer();
|
||||
await fakeServer.Start();
|
||||
@@ -940,7 +940,7 @@ retry:
|
||||
});
|
||||
|
||||
|
||||
var signingKeySettings = derivationSchemeSettings.GetSigningAccountKeySettings();
|
||||
var signingKeySettings = derivationSchemeSettings.GetFirstAccountKeySettings();
|
||||
signingKeySettings.RootFingerprint =
|
||||
senderUser.GenerateWalletResponseV.MasterHDKey.GetPublicKey().GetHDFingerPrint();
|
||||
|
||||
|
||||
@@ -2828,8 +2828,7 @@ namespace BTCPayServer.Tests
|
||||
var v = store.GetPaymentMethodConfig<DerivationSchemeSettings>(pmi, handlers);
|
||||
Assert.Equal(derivation, v.AccountDerivation.ToString());
|
||||
Assert.Equal(derivation, v.AccountOriginal);
|
||||
Assert.Equal(xpub, v.SigningKey.ToString());
|
||||
Assert.Equal(xpub, v.GetSigningAccountKeySettings().AccountKey.ToString());
|
||||
Assert.Equal(xpub, v.GetFirstAccountKeySettings().AccountKey.ToString());
|
||||
|
||||
await acc.RegisterLightningNodeAsync("BTC", LightningConnectionType.CLightning, true);
|
||||
store = await tester.PayTester.StoreRepository.FindStore(acc.StoreId);
|
||||
|
||||
@@ -580,8 +580,8 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
|
||||
var signingKey = ExtKey.Parse(signingKeyStr, network.NBitcoinNetwork);
|
||||
|
||||
var signingKeySettings = derivationScheme.GetSigningAccountKeySettings(signingKey);
|
||||
RootedKeyPath? rootedKeyPath = signingKeySettings?.GetRootedKeyPath();
|
||||
var signingKeySettings = derivationScheme.GetAccountKeySettingsFromRoot(signingKey);
|
||||
var rootedKeyPath = signingKeySettings?.GetRootedKeyPath();
|
||||
if (rootedKeyPath is null || signingKeySettings is null)
|
||||
{
|
||||
return this.CreateAPIError(503, "not-available",
|
||||
|
||||
@@ -407,13 +407,12 @@ public partial class UIStoresController
|
||||
Network = network,
|
||||
IsHotWallet = derivation.IsHotWallet,
|
||||
Source = derivation.Source,
|
||||
RootFingerprint = derivation.GetSigningAccountKeySettingsOrDefault()?.RootFingerprint.ToString(),
|
||||
RootFingerprint = derivation.GetFirstAccountKeySettings().RootFingerprint.ToString(),
|
||||
DerivationScheme = derivation.AccountDerivation?.ToString(),
|
||||
DerivationSchemeInput = derivation.AccountOriginal,
|
||||
KeyPath = derivation.GetSigningAccountKeySettingsOrDefault()?.AccountKeyPath?.ToString(),
|
||||
KeyPath = derivation.GetFirstAccountKeySettings().AccountKeyPath?.ToString(),
|
||||
UriScheme = network.NBitcoinNetwork.UriScheme,
|
||||
Label = derivation.Label,
|
||||
SelectedSigningKey = derivation.SigningKey?.ToString(),
|
||||
NBXSeedAvailable = derivation.IsHotWallet &&
|
||||
perm.CanCreateHotWallet &&
|
||||
!string.IsNullOrEmpty(await client.GetMetadataAsync<string>(derivation.AccountDerivation,
|
||||
@@ -480,15 +479,6 @@ public partial class UIStoresController
|
||||
derivation.DefaultIncludeNonWitnessUtxo = vm.DefaultIncludeNonWitnessUtxo;
|
||||
}
|
||||
|
||||
var signingKey = string.IsNullOrEmpty(vm.SelectedSigningKey)
|
||||
? null
|
||||
: new BitcoinExtPubKey(vm.SelectedSigningKey, network.NBitcoinNetwork);
|
||||
if (derivation.SigningKey != signingKey && signingKey != null)
|
||||
{
|
||||
needUpdate = true;
|
||||
derivation.SigningKey = signingKey;
|
||||
}
|
||||
|
||||
for (int i = 0; i < derivation.AccountKeySettings.Length; i++)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -269,7 +269,7 @@ namespace BTCPayServer.Controllers
|
||||
|
||||
if (signingKey == null || signingKeyPath == null)
|
||||
{
|
||||
var signingKeySettings = derivationSchemeSettings.GetSigningAccountKeySettings();
|
||||
var signingKeySettings = derivationSchemeSettings.GetFirstAccountKeySettings();
|
||||
if (signingKey == null)
|
||||
{
|
||||
signingKey = signingKeySettings.AccountKey;
|
||||
|
||||
@@ -1479,13 +1479,12 @@ namespace BTCPayServer.Controllers
|
||||
var settings = GetDerivationSchemeSettings(walletId);
|
||||
if (settings is null)
|
||||
return NotFound();
|
||||
var signingKeySettings = settings.GetSigningAccountKeySettings(extKey);
|
||||
var signingKeySettings = settings.GetAccountKeySettingsFromRoot(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();
|
||||
.FirstOrDefault(a => a.RootFingerprint is null && a.AccountKeyPath is not null);
|
||||
if (signingKeySettings is not null)
|
||||
signingKeySettings.RootFingerprint = extKey.GetPublicKey().GetHDFingerPrint();
|
||||
}
|
||||
|
||||
@@ -47,56 +47,55 @@ namespace BTCPayServer
|
||||
}
|
||||
|
||||
|
||||
private BitcoinExtPubKey _signingKey;
|
||||
[JsonIgnore]
|
||||
[Obsolete("Use AccountKeySettings[0].AccountKey instead")]
|
||||
public BitcoinExtPubKey SigningKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return _signingKey ?? AccountKeySettings?.Select(k => k.AccountKey).FirstOrDefault();
|
||||
// There should always be at least one account key
|
||||
return AccountKeySettings[0].AccountKey;
|
||||
}
|
||||
set
|
||||
{
|
||||
_signingKey = value;
|
||||
// Ignored, this is legacy stuff that should disappear
|
||||
}
|
||||
}
|
||||
|
||||
public string Source { get; set; }
|
||||
|
||||
public bool IsHotWallet { get; set; }
|
||||
|
||||
[Obsolete("Use GetSigningAccountKeySettings().AccountKeyPath instead")]
|
||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public KeyPath AccountKeyPath { get; set; }
|
||||
|
||||
public DerivationStrategyBase AccountDerivation { get; set; }
|
||||
public string AccountOriginal { get; set; }
|
||||
|
||||
[Obsolete("Use GetSigningAccountKeySettings().RootFingerprint instead")]
|
||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public HDFingerprint? RootFingerprint { get; set; }
|
||||
|
||||
[Obsolete("Use GetSigningAccountKeySettings().AccountKey instead")]
|
||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public BitcoinExtPubKey ExplicitAccountKey { get; set; }
|
||||
|
||||
#nullable enable
|
||||
[Obsolete("Use GetFirstAccountKeySettings isntead")]
|
||||
public AccountKeySettings GetSigningAccountKeySettings()
|
||||
{
|
||||
return (AccountKeySettings ?? []).Single(a => a.AccountKey == SigningKey);
|
||||
}
|
||||
// There should always be at least one account key
|
||||
=> (AccountKeySettings ?? []).First();
|
||||
|
||||
public AccountKeySettings GetFirstAccountKeySettings()
|
||||
// There should always be at least one account key
|
||||
=> (AccountKeySettings ?? []).First();
|
||||
|
||||
public AccountKeySettings? GetAccountKeySettingsFromRoot(IHDKey rootKey)
|
||||
=> GetAccountKeySettingsFromRoot(rootKey.GetPublicKey().GetHDFingerPrint());
|
||||
|
||||
public AccountKeySettings? GetAccountKeySettingsFromRoot(HDFingerprint rootFingerprint)
|
||||
=> (AccountKeySettings ?? []).FirstOrDefault(a => a.RootFingerprint == rootFingerprint);
|
||||
|
||||
[Obsolete("Use GetAccountKeySettingsFromRoot instead")]
|
||||
public AccountKeySettings? GetSigningAccountKeySettings(IHDKey rootKey)
|
||||
=> GetSigningAccountKeySettings(rootKey.GetPublicKey().GetHDFingerPrint());
|
||||
=> GetAccountKeySettingsFromRoot(rootKey.GetPublicKey().GetHDFingerPrint());
|
||||
|
||||
[Obsolete("Use GetAccountKeySettingsFromRoot instead")]
|
||||
public AccountKeySettings? GetSigningAccountKeySettings(HDFingerprint rootFingerprint)
|
||||
{
|
||||
return (AccountKeySettings ?? []).Where(a => a.RootFingerprint == rootFingerprint).FirstOrDefault();
|
||||
}
|
||||
=> GetAccountKeySettingsFromRoot(rootFingerprint);
|
||||
|
||||
|
||||
public AccountKeySettings? GetSigningAccountKeySettingsOrDefault()
|
||||
{
|
||||
return (AccountKeySettings ?? []).SingleOrDefault(a => a.AccountKey == SigningKey);
|
||||
}
|
||||
[Obsolete("Use AccountKeySettings[0] instead")]
|
||||
// There should always be at least one account key
|
||||
public AccountKeySettings? GetSigningAccountKeySettingsOrDefault() => this.AccountKeySettings[0];
|
||||
#nullable restore
|
||||
public AccountKeySettings[] AccountKeySettings { get; set; }
|
||||
|
||||
|
||||
@@ -964,23 +964,6 @@ retry:
|
||||
}
|
||||
}
|
||||
|
||||
void MigrateDerivationSettings(DerivationSchemeSettings s, BTCPayNetwork network)
|
||||
{
|
||||
if (network == null || s.AccountKeySettings is not (null or { Length: 1 }))
|
||||
return;
|
||||
s.AccountKeySettings = s.AccountDerivation.GetExtPubKeys().Select(e => new AccountKeySettings()
|
||||
{
|
||||
AccountKey = e.GetWif(network.NBitcoinNetwork),
|
||||
}).ToArray();
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
s.AccountKeySettings[0].AccountKeyPath = s.AccountKeyPath;
|
||||
s.AccountKeySettings[0].RootFingerprint = s.RootFingerprint;
|
||||
s.ExplicitAccountKey = null;
|
||||
s.AccountKeyPath = null;
|
||||
s.RootFingerprint = null;
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
}
|
||||
|
||||
private async Task MigratePaymentMethodCriteria()
|
||||
{
|
||||
using var ctx = _DBContextFactory.CreateContext();
|
||||
|
||||
@@ -21,8 +21,6 @@ namespace BTCPayServer.Models.StoreViewModels
|
||||
public string Label { get; set; }
|
||||
|
||||
public string DerivationSchemeInput { get; set; }
|
||||
[Display(Name = "Is signing key")]
|
||||
public string SelectedSigningKey { get; set; }
|
||||
public bool IsMultiSig => AccountKeys.Count > 1;
|
||||
|
||||
public List<WalletSettingsAccountKeyViewModel> AccountKeys { get; set; } = new();
|
||||
|
||||
@@ -261,7 +261,7 @@ namespace BTCPayServer.Payments.Bitcoin
|
||||
public Task ValidatePaymentMethodConfig(PaymentMethodConfigValidationContext validationContext)
|
||||
{
|
||||
var parser = Network.GetDerivationSchemeParser();
|
||||
DerivationSchemeSettings settings = new DerivationSchemeSettings();
|
||||
var settings = new DerivationSchemeSettings();
|
||||
if (validationContext.Config is JValue { Type: JTokenType.String, Value: string config }
|
||||
&& parser.TryParseXpub(config, ref settings))
|
||||
{
|
||||
@@ -287,17 +287,15 @@ namespace BTCPayServer.Payments.Bitcoin
|
||||
{
|
||||
validationContext.ModelState.AddModelError(nameof(res.AccountDerivation), "Invalid account derivation");
|
||||
}
|
||||
if (res.AccountKeySettings is null)
|
||||
if (res.AccountKeySettings is null || res.AccountKeySettings.Length == 0)
|
||||
{
|
||||
validationContext.ModelState.AddModelError(nameof(res.AccountKeySettings), "Invalid AccountKeySettings");
|
||||
}
|
||||
if (res.SigningKey is null)
|
||||
|
||||
foreach (var acc in res.AccountKeySettings ?? [])
|
||||
{
|
||||
validationContext.ModelState.AddModelError(nameof(res.SigningKey), "Invalid SigningKey");
|
||||
}
|
||||
if (res.GetSigningAccountKeySettingsOrDefault() is null)
|
||||
{
|
||||
validationContext.ModelState.AddModelError(nameof(res.AccountKeySettings), "AccountKeySettings doesn't include the SigningKey");
|
||||
if (acc.AccountKey is null)
|
||||
validationContext.ModelState.AddModelError(nameof(res.AccountKeySettings), "Missing AccountKey");
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using BTCPayServer.BIP78.Sender;
|
||||
using NBitcoin;
|
||||
|
||||
@@ -10,7 +11,11 @@ namespace BTCPayServer.Payments.PayJoin.Sender
|
||||
public PayjoinWallet(DerivationSchemeSettings derivationSchemeSettings)
|
||||
{
|
||||
_derivationSchemeSettings = derivationSchemeSettings;
|
||||
AccountSettings = _derivationSchemeSettings.AccountKeySettings.Single();
|
||||
}
|
||||
|
||||
public AccountKeySettings AccountSettings { get; set; }
|
||||
|
||||
public IHDScriptPubKey Derive(KeyPath keyPath)
|
||||
{
|
||||
return ((IHDScriptPubKey)_derivationSchemeSettings.AccountDerivation).Derive(keyPath);
|
||||
@@ -25,8 +30,8 @@ namespace BTCPayServer.Payments.PayJoin.Sender
|
||||
public ScriptPubKeyType ScriptPubKeyType => _derivationSchemeSettings.AccountDerivation.ScriptPubKeyType();
|
||||
|
||||
public RootedKeyPath RootedKeyPath =>
|
||||
_derivationSchemeSettings.GetSigningAccountKeySettings().GetRootedKeyPath();
|
||||
AccountSettings.GetRootedKeyPath();
|
||||
|
||||
public IHDKey AccountKey => _derivationSchemeSettings.GetSigningAccountKeySettings().AccountKey;
|
||||
public IHDKey AccountKey => AccountSettings.AccountKey;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,13 +173,6 @@
|
||||
<input asp-for="@Model.AccountKeys[i].AccountKeyPath" class="form-control" style="max-width:16ch;" />
|
||||
</div>
|
||||
</div>
|
||||
@if (Model is { IsMultiSig: true, IsMultiSigOnServer: false })
|
||||
{
|
||||
<div class="form-check">
|
||||
<input asp-for="SelectedSigningKey" class="form-check-input" type="radio" value="@Model.AccountKeys[i].AccountKey" />
|
||||
<label asp-for="SelectedSigningKey" class="form-check-label"></label>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</form>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user