Don't scan 49' or 84' if not segwit

This commit is contained in:
nicolas.dorier
2019-05-10 10:55:10 +09:00
parent 75f2749b19
commit 95e7d3dfc4
2 changed files with 12 additions and 5 deletions

View File

@@ -561,8 +561,8 @@ namespace BTCPayServer.Controllers
if (derivationSettings.AccountKeyPath == null)
{
// If the saved wallet key path is not present or incorrect, let's scan the wallet to see if it can sign strategy
var foundKeyPath = await hw.FindKeyPathFromPubkeys(network,
derivationSettings.AccountDerivation.GetExtPubKeys().Select(p => p.GetPublicKey()).ToArray(),
var foundKeyPath = await hw.FindKeyPathFromDerivation(network,
derivationSettings.AccountDerivation,
normalOperationTimeout.Token);
derivationSettings.AccountKeyPath = foundKeyPath ?? throw new HardwareWalletException($"This store is not configured to use this ledger");
storeData.SetSupportedPaymentMethod(derivationSettings);

View File

@@ -31,13 +31,20 @@ namespace BTCPayServer.Services
return (await GetExtPubKey(network, keyPath, cancellation)).GetPublicKey();
}
public async Task<KeyPath> FindKeyPathFromPubkeys(BTCPayNetwork network, PubKey[] pubKeys, CancellationToken cancellation)
public async Task<KeyPath> FindKeyPathFromDerivation(BTCPayNetwork network, DerivationStrategyBase derivationScheme, CancellationToken cancellation)
{
var pubKeys = derivationScheme.GetExtPubKeys().Select(k => k.GetPublicKey()).ToArray();
var derivation = derivationScheme.Derive(new KeyPath(0));
List<KeyPath> derivations = new List<KeyPath>();
if (network.NBitcoinNetwork.Consensus.SupportSegwit)
{
if (derivation.Redeem?.IsWitness is true ||
derivation.ScriptPubKey.IsWitness) // Native or p2sh segwit
derivations.Add(new KeyPath("49'"));
derivations.Add(new KeyPath("44'"));
if (derivation.Redeem == null && derivation.ScriptPubKey.IsWitness) // Native segwit
derivations.Add(new KeyPath("84'"));
}
derivations.Add(new KeyPath("44'"));
KeyPath foundKeyPath = null;
foreach (var account in
derivations