mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
Limit the number of time the wallet need to export the xpub
This commit is contained in:
@@ -410,8 +410,8 @@ namespace BTCPayServer.Controllers
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
var cryptoCode = walletId.CryptoCode;
|
var cryptoCode = walletId.CryptoCode;
|
||||||
var storeBlob = (await Repository.FindStore(walletId.StoreId, GetUserId()));
|
var storeData = (await Repository.FindStore(walletId.StoreId, GetUserId()));
|
||||||
var derivationScheme = GetPaymentMethod(walletId, storeBlob).DerivationStrategyBase;
|
var derivationScheme = GetPaymentMethod(walletId, storeData).DerivationStrategyBase;
|
||||||
|
|
||||||
var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync();
|
var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync();
|
||||||
|
|
||||||
@@ -505,10 +505,24 @@ namespace BTCPayServer.Controllers
|
|||||||
throw new ArgumentOutOfRangeException(nameof(element.amount), "The amount should be above zero");
|
throw new ArgumentOutOfRangeException(nameof(element.amount), "The amount should be above zero");
|
||||||
}
|
}
|
||||||
|
|
||||||
var foundKeyPath = await hw.GetKeyPath(network, strategy, normalOperationTimeout.Token);
|
var storeBlob = storeData.GetStoreBlob();
|
||||||
|
var paymentId = new Payments.PaymentMethodId(cryptoCode, Payments.PaymentTypes.BTCLike);
|
||||||
|
var foundKeyPath = storeBlob.GetWalletKeyPathRoot(paymentId);
|
||||||
if (foundKeyPath == null)
|
if (foundKeyPath == null)
|
||||||
{
|
{
|
||||||
|
foundKeyPath = await hw.FindKeyPath(network, strategy, normalOperationTimeout.Token);
|
||||||
|
if (foundKeyPath == null)
|
||||||
throw new HardwareWalletException($"This store is not configured to use this ledger");
|
throw new HardwareWalletException($"This store is not configured to use this ledger");
|
||||||
|
storeBlob.SetWalletKeyPathRoot(paymentId, foundKeyPath);
|
||||||
|
storeData.SetStoreBlob(storeBlob);
|
||||||
|
await Repository.UpdateStore(storeData);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(!await hw.CanSign(network, strategy, foundKeyPath, normalOperationTimeout.Token))
|
||||||
|
{
|
||||||
|
throw new HardwareWalletException($"This store is not configured to use this ledger");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TransactionBuilder builder = network.NBitcoinNetwork.CreateTransactionBuilder();
|
TransactionBuilder builder = network.NBitcoinNetwork.CreateTransactionBuilder();
|
||||||
|
|||||||
@@ -372,11 +372,11 @@ namespace BTCPayServer.Data
|
|||||||
if (keyPath == null)
|
if (keyPath == null)
|
||||||
WalletKeyPathRoots.Remove(paymentMethodId.ToString());
|
WalletKeyPathRoots.Remove(paymentMethodId.ToString());
|
||||||
else
|
else
|
||||||
WalletKeyPathRoots.AddOrReplace(paymentMethodId.ToString(), keyPath.ToString());
|
WalletKeyPathRoots.AddOrReplace(paymentMethodId.ToString().ToLowerInvariant(), keyPath.ToString());
|
||||||
}
|
}
|
||||||
public KeyPath GetWalletKeyPathRoot(PaymentMethodId paymentMethodId)
|
public KeyPath GetWalletKeyPathRoot(PaymentMethodId paymentMethodId)
|
||||||
{
|
{
|
||||||
if (WalletKeyPathRoots.TryGetValue(paymentMethodId.ToString(), out var k))
|
if (WalletKeyPathRoots.TryGetValue(paymentMethodId.ToString().ToLowerInvariant(), out var k))
|
||||||
return KeyPath.Parse(k);
|
return KeyPath.Parse(k);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,7 +128,13 @@ namespace BTCPayServer.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<KeyPath> GetKeyPath(BTCPayNetwork network, DirectDerivationStrategy directStrategy, CancellationToken cancellation)
|
public async Task<bool> CanSign(BTCPayNetwork network, DirectDerivationStrategy strategy, KeyPath keyPath, CancellationToken cancellation)
|
||||||
|
{
|
||||||
|
var hwKey = await GetExtPubKey(Ledger, network, keyPath, true, cancellation);
|
||||||
|
return hwKey.ExtPubKey.PubKey == strategy.Root.PubKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<KeyPath> FindKeyPath(BTCPayNetwork network, DirectDerivationStrategy directStrategy, CancellationToken cancellation)
|
||||||
{
|
{
|
||||||
List<KeyPath> derivations = new List<KeyPath>();
|
List<KeyPath> derivations = new List<KeyPath>();
|
||||||
if (network.NBitcoinNetwork.Consensus.SupportSegwit)
|
if (network.NBitcoinNetwork.Consensus.SupportSegwit)
|
||||||
@@ -163,7 +169,17 @@ namespace BTCPayServer.Services
|
|||||||
KeyPath changeKeyPath,
|
KeyPath changeKeyPath,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return await Ledger.SignTransactionAsync(signatureRequests, unsigned, changeKeyPath, cancellationToken);
|
try
|
||||||
|
{
|
||||||
|
var signedTransaction = await Ledger.SignTransactionAsync(signatureRequests, unsigned, changeKeyPath, cancellationToken);
|
||||||
|
if (signedTransaction == null)
|
||||||
|
throw new Exception("The ledger failed to sign the transaction");
|
||||||
|
return signedTransaction;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception("The ledger failed to sign the transaction", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|||||||
Reference in New Issue
Block a user