Remove useless code (#6817)

* Remove unused code

* Obsolete SigningKey concept
This commit is contained in:
Nicolas Dorier
2025-06-30 19:28:01 +09:00
committed by GitHub
parent efc570a4f7
commit 9b64e90394
13 changed files with 65 additions and 101 deletions

View File

@@ -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 =

View File

@@ -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();
@@ -981,8 +981,8 @@ retry:
.BuildTransaction(true);
//Attempt 2: Create two transactions using different inputs and send them to the same invoice.
//Result: Second Tx should be rejected.
//Attempt 2: Create two transactions using different inputs and send them to the same invoice.
//Result: Second Tx should be rejected.
var Invoice1Coin1ResponseTx = await senderUser.SubmitPayjoin(invoice, Invoice1Coin1, btcPayNetwork);
await senderUser.SubmitPayjoin(invoice, Invoice1Coin1, btcPayNetwork, "already-paid");

View File

@@ -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);

View File

@@ -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",

View File

@@ -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

View File

@@ -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;

View File

@@ -997,7 +997,7 @@ namespace BTCPayServer.Controllers
Labels = _labelService.CreateTransactionTagModels(info, Request),
Link = _transactionLinkProviders.GetTransactionLink(pmi, coin.OutPoint.ToString()),
Confirmations = coin.Confirmations,
Timestamp = coin.Timestamp
Timestamp = coin.Timestamp
};
}).ToArray();
}
@@ -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();
}

View File

@@ -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; }
@@ -119,12 +118,12 @@ namespace BTCPayServer
#region MultiSig related settings
public bool IsMultiSigOnServer { get; set; }
// some hardware devices like Jade require sending full input transactions if there are multiple inputs
// https://github.com/Blockstream/Jade/blob/0d6ce77bf23ef2b5dc43cdae3967b4207e8cad52/main/process/sign_tx.c#L586
public bool DefaultIncludeNonWitnessUtxo { get; set; }
#endregion
#endregion
public override string ToString()
{
return AccountDerivation.ToString();

View File

@@ -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();

View File

@@ -21,20 +21,18 @@ 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();
public bool NBXSeedAvailable { get; set; }
public string StoreName { get; set; }
public string UriScheme { get; set; }
#region MultiSig related settings
public bool CanSetupMultiSig { get; set; }
[Display(Name = "Is MultiSig on Server")]
public bool IsMultiSigOnServer { get; set; }
// some hardware devices like Jade require sending full input transactions if there are multiple inputs
// https://github.com/Blockstream/Jade/blob/0d6ce77bf23ef2b5dc43cdae3967b4207e8cad52/main/process/sign_tx.c#L586
[Display(Name = "Default Include NonWitness Utxo in PSBTs")]

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -73,7 +73,7 @@
</form>
</div>
</div>
<a class="btn btn-secondary" asp-controller="UIWallets" asp-action="WalletLabels"
asp-route-walletId="@Model.WalletId" text-translate="true">Manage labels</a>
@@ -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>
@@ -190,14 +183,14 @@
<script>
const wallets = @Safe.Json(Model.AccountKeys.Select(model => Encoders.Hex.EncodeData(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(model, Formatting.None)))))
const qrApp = initQRShow({ title: "Wallet QR" })
delegate('click', '#Delete', event => { event.preventDefault() })
delegate('click', 'button[data-account-key]', event => {
const { accountKey } = event.target.dataset;
qrApp.showData(wallets[parseInt(accountKey)]);
})
if (navigator.registerProtocolHandler) {
document.getElementById('RegisterWallet').removeAttribute('hidden');
delegate('click', '#RegisterWallet', event => {
@@ -205,7 +198,7 @@
const uri = decodeURIComponent(url)
navigator.registerProtocolHandler(scheme, uri, `BTCPay Wallet: ${store}`)
})
}
}
</script>
<partial name="_ValidationScriptsPartial"/>
}