Update NBXplorer and NBitcoin

This commit is contained in:
nicolas.dorier
2019-05-14 16:06:43 +09:00
parent 8ffb81cdf3
commit 522d745883
6 changed files with 20 additions and 13 deletions

View File

@@ -1648,9 +1648,9 @@ namespace BTCPayServer.Tests
Assert.All(psbt.PSBT.Inputs, input =>
{
var keyPath = input.HDKeyPaths.Single();
Assert.False(keyPath.Value.Item2.IsHardened);
Assert.Equal(account.Derive(keyPath.Value.Item2).GetPublicKey(), keyPath.Key);
Assert.Equal(keyPath.Value.Item1, onchainBTC.AccountKeySettings[0].AccountKey.GetPublicKey().GetHDFingerPrint());
Assert.False(keyPath.Value.KeyPath.IsHardened);
Assert.Equal(account.Derive(keyPath.Value.KeyPath).GetPublicKey(), keyPath.Key);
Assert.Equal(keyPath.Value.MasterFingerprint, onchainBTC.AccountKeySettings[0].AccountKey.GetPublicKey().GetHDFingerPrint());
});
}
}

View File

@@ -47,10 +47,10 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="NBitcoin" Version="4.1.2.22" />
<PackageReference Include="NBitcoin" Version="4.1.2.24" />
<PackageReference Include="NBitpayClient" Version="1.0.0.34" />
<PackageReference Include="DBriize" Version="1.0.0.4" />
<PackageReference Include="NBXplorer.Client" Version="2.0.0.12" />
<PackageReference Include="NBXplorer.Client" Version="2.0.0.13" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="NicolasDorier.CommandLine" Version="1.0.0.2" />
<PackageReference Include="NicolasDorier.CommandLine.Configuration" Version="1.0.0.3" />

View File

@@ -504,7 +504,7 @@ namespace BTCPayServer.Controllers
derivationSettings.RebaseKeyPaths(psbtResponse.PSBT);
signTimeout.CancelAfter(TimeSpan.FromMinutes(5));
psbtResponse.PSBT = await hw.SignTransactionAsync(psbtResponse.PSBT, accountKey.RootFingerprint, accountKey.AccountKey, psbtResponse.ChangeAddress?.ScriptPubKey, signTimeout.Token);
psbtResponse.PSBT = await hw.SignTransactionAsync(psbtResponse.PSBT, accountKey.GetRootedKeyPath(), accountKey.AccountKey, psbtResponse.ChangeAddress?.ScriptPubKey, signTimeout.Token);
result = new SendToAddressResult() { PSBT = psbtResponse.PSBT.ToBase64() };
}
}

View File

@@ -250,7 +250,7 @@ namespace BTCPayServer
{
foreach (var rebase in GetPSBTRebaseKeyRules())
{
psbt.RebaseKeyPaths(rebase.AccountKey, rebase.AccountKeyPath, rebase.MasterFingerprint);
psbt.RebaseKeyPaths(rebase.AccountKey, rebase.GetRootedKeyPath());
}
}
}
@@ -258,6 +258,13 @@ namespace BTCPayServer
{
public HDFingerprint? RootFingerprint { get; set; }
public KeyPath AccountKeyPath { get; set; }
public RootedKeyPath GetRootedKeyPath()
{
if (RootFingerprint is HDFingerprint fp && AccountKeyPath != null)
return new RootedKeyPath(fp, AccountKeyPath);
return null;
}
public BitcoinExtPubKey AccountKey { get; set; }
public bool IsFullySetup()
{

View File

@@ -62,7 +62,7 @@ namespace BTCPayServer.Services
return foundKeyPath;
}
public abstract Task<PSBT> SignTransactionAsync(PSBT psbt, HDFingerprint? rootFingerprint, BitcoinExtPubKey accountKey, Script changeHint, CancellationToken cancellationToken);
public abstract Task<PSBT> SignTransactionAsync(PSBT psbt, RootedKeyPath accountKeyPath, BitcoinExtPubKey accountKey, Script changeHint, CancellationToken cancellationToken);
public virtual void Dispose()
{

View File

@@ -115,23 +115,23 @@ namespace BTCPayServer.Services
return extpubkey;
}
public override async Task<PSBT> SignTransactionAsync(PSBT psbt, HDFingerprint? rootFingerprint, BitcoinExtPubKey accountKey, Script changeHint, CancellationToken cancellationToken)
public override async Task<PSBT> SignTransactionAsync(PSBT psbt, RootedKeyPath accountKeyPath, BitcoinExtPubKey accountKey, Script changeHint, CancellationToken cancellationToken)
{
var unsigned = psbt.GetGlobalTransaction();
var changeKeyPath = psbt.Outputs.HDKeysFor(rootFingerprint, accountKey)
var changeKeyPath = psbt.Outputs.HDKeysFor(accountKey, accountKeyPath)
.Where(o => changeHint == null ? true : changeHint == o.Coin.ScriptPubKey)
.Select(o => o.KeyPath)
.Select(o => o.RootedKeyPath.KeyPath)
.FirstOrDefault();
var signatureRequests = psbt
.Inputs
.HDKeysFor(rootFingerprint, accountKey)
.HDKeysFor(accountKey, accountKeyPath)
.Where(hd => !hd.Coin.PartialSigs.ContainsKey(hd.PubKey)) // Don't want to sign something twice
.GroupBy(hd => hd.Coin)
.Select(i => new SignatureRequest()
{
InputCoin = i.Key.GetSignableCoin(),
InputTransaction = i.Key.NonWitnessUtxo,
KeyPath = i.First().KeyPath,
KeyPath = i.First().RootedKeyPath.KeyPath,
PubKey = i.First().PubKey
}).ToArray();
await Ledger.SignTransactionAsync(signatureRequests, unsigned, changeKeyPath, cancellationToken);