mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 22:25:28 +01:00
Make sure that the accountkey can sign a transaction
This commit is contained in:
parent
e100edce24
commit
d914fe2f48
3 changed files with 38 additions and 25 deletions
|
@ -263,8 +263,8 @@ namespace BTCPayServer.Tests
|
||||||
var mnemonic = "usage fever hen zero slide mammal silent heavy donate budget pulse say brain thank sausage brand craft about save attract muffin advance illegal cabbage";
|
var mnemonic = "usage fever hen zero slide mammal silent heavy donate budget pulse say brain thank sausage brand craft about save attract muffin advance illegal cabbage";
|
||||||
var root = new Mnemonic(mnemonic).DeriveExtKey();
|
var root = new Mnemonic(mnemonic).DeriveExtKey();
|
||||||
s.AddDerivationScheme("ypub6WWc2gWwHbdnAAyJDnR4SPL1phRh7REqrPBfZeizaQ1EmTshieRXJC3Z5YoU4wkcdKHEjQGkh6AYEzCQC1Kz3DNaWSwdc1pc8416hAjzqyD");
|
s.AddDerivationScheme("ypub6WWc2gWwHbdnAAyJDnR4SPL1phRh7REqrPBfZeizaQ1EmTshieRXJC3Z5YoU4wkcdKHEjQGkh6AYEzCQC1Kz3DNaWSwdc1pc8416hAjzqyD");
|
||||||
var tx = s.Server.ExplorerNode.SendToAddress(BitcoinAddress.Create("bcrt1qmxg8fgnmkp354vhe78j6sr4ut64tyz2xyejel4", Network.RegTest), Money.Coins(1.0m));
|
var tx = s.Server.ExplorerNode.SendToAddress(BitcoinAddress.Create("bcrt1qmxg8fgnmkp354vhe78j6sr4ut64tyz2xyejel4", Network.RegTest), Money.Coins(3.0m));
|
||||||
|
s.Server.ExplorerNode.Generate(1);
|
||||||
|
|
||||||
s.Driver.FindElement(By.Id("Wallets")).Click();
|
s.Driver.FindElement(By.Id("Wallets")).Click();
|
||||||
s.Driver.FindElement(By.LinkText("Manage")).Click();
|
s.Driver.FindElement(By.LinkText("Manage")).Click();
|
||||||
|
@ -281,22 +281,29 @@ namespace BTCPayServer.Tests
|
||||||
var walletTransactionLink = s.Driver.Url;
|
var walletTransactionLink = s.Driver.Url;
|
||||||
Assert.Contains(tx.ToString(), s.Driver.PageSource);
|
Assert.Contains(tx.ToString(), s.Driver.PageSource);
|
||||||
|
|
||||||
// Send to bob
|
|
||||||
s.Driver.FindElement(By.Id("WalletSend")).Click();
|
|
||||||
var bob = new Key().PubKey.Hash.GetAddress(Network.RegTest);
|
|
||||||
s.Driver.FindElement(By.Id("Destination")).SendKeys(bob.ToString());
|
|
||||||
s.Driver.FindElement(By.Id("Amount")).SendKeys("1");
|
|
||||||
s.Driver.FindElement(By.Id("SendMenu")).Click();
|
|
||||||
s.Driver.FindElement(By.CssSelector("button[value=seed]")).Click();
|
|
||||||
|
|
||||||
// Input the seed
|
void SignWith(string signingSource)
|
||||||
s.Driver.FindElement(By.Id("SeedOrKey")).SendKeys(mnemonic + Keys.Enter);
|
{
|
||||||
|
// Send to bob
|
||||||
|
s.Driver.FindElement(By.Id("WalletSend")).Click();
|
||||||
|
var bob = new Key().PubKey.Hash.GetAddress(Network.RegTest);
|
||||||
|
s.Driver.FindElement(By.Id("Destination")).SendKeys(bob.ToString());
|
||||||
|
s.Driver.FindElement(By.Id("Amount")).SendKeys("1");
|
||||||
|
s.Driver.FindElement(By.Id("SendMenu")).Click();
|
||||||
|
s.Driver.FindElement(By.CssSelector("button[value=seed]")).Click();
|
||||||
|
|
||||||
// Broadcast
|
// Input the seed
|
||||||
Assert.Contains(bob.ToString(), s.Driver.PageSource);
|
s.Driver.FindElement(By.Id("SeedOrKey")).SendKeys(signingSource + Keys.Enter);
|
||||||
Assert.Contains("1.00000000", s.Driver.PageSource);
|
|
||||||
s.Driver.FindElement(By.CssSelector("button[value=broadcast]")).Click();
|
// Broadcast
|
||||||
Assert.Equal(walletTransactionLink, s.Driver.Url);
|
Assert.Contains(bob.ToString(), s.Driver.PageSource);
|
||||||
|
Assert.Contains("1.00000000", s.Driver.PageSource);
|
||||||
|
s.Driver.FindElement(By.CssSelector("button[value=broadcast]")).Click();
|
||||||
|
Assert.Equal(walletTransactionLink, s.Driver.Url);
|
||||||
|
}
|
||||||
|
SignWith(mnemonic);
|
||||||
|
var accountKey = root.Derive(new KeyPath("m/49'/0'/0'")).GetWif(Network.RegTest).ToString();
|
||||||
|
SignWith(accountKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="NBitcoin" Version="4.1.2.25" />
|
<PackageReference Include="NBitcoin" Version="4.1.2.28" />
|
||||||
<PackageReference Include="NBitpayClient" Version="1.0.0.34" />
|
<PackageReference Include="NBitpayClient" Version="1.0.0.34" />
|
||||||
<PackageReference Include="DBriize" Version="1.0.0.4" />
|
<PackageReference Include="DBriize" Version="1.0.0.4" />
|
||||||
<PackageReference Include="NBXplorer.Client" Version="2.0.0.13" />
|
<PackageReference Include="NBXplorer.Client" Version="2.0.0.13" />
|
||||||
|
|
|
@ -313,25 +313,31 @@ namespace BTCPayServer.Controllers
|
||||||
return View(viewModel);
|
return View(viewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
RootedKeyPath rootedKeyPath = null;
|
ExtKey signingKey = null;
|
||||||
var settings = (await GetDerivationSchemeSettings(walletId));
|
var settings = (await GetDerivationSchemeSettings(walletId));
|
||||||
var signingKeySettings = settings.GetSigningAccountKeySettings();
|
var signingKeySettings = settings.GetSigningAccountKeySettings();
|
||||||
if (signingKeySettings.RootFingerprint is null)
|
if (signingKeySettings.RootFingerprint is null)
|
||||||
signingKeySettings.RootFingerprint = extKey.GetPublicKey().GetHDFingerPrint();
|
signingKeySettings.RootFingerprint = extKey.GetPublicKey().GetHDFingerPrint();
|
||||||
if (signingKeySettings.GetRootedKeyPath()?.MasterFingerprint == extKey.GetPublicKey().GetHDFingerPrint())
|
|
||||||
{
|
|
||||||
psbt.RebaseKeyPaths(signingKeySettings.AccountKey, signingKeySettings.GetRootedKeyPath());
|
|
||||||
rootedKeyPath = signingKeySettings.GetRootedKeyPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
ExtKey signingKey = rootedKeyPath == null ? extKey : extKey.Derive(rootedKeyPath.KeyPath);
|
RootedKeyPath rootedKeyPath = signingKeySettings.GetRootedKeyPath();
|
||||||
|
// The user gave the root key, let's try to rebase the PSBT, and derive the account private key
|
||||||
|
if (rootedKeyPath?.MasterFingerprint == extKey.GetPublicKey().GetHDFingerPrint())
|
||||||
|
{
|
||||||
|
psbt.RebaseKeyPaths(signingKeySettings.AccountKey, rootedKeyPath);
|
||||||
|
signingKey = extKey.Derive(rootedKeyPath.KeyPath);
|
||||||
|
}
|
||||||
|
// The user maybe gave the account key, let's try to sign with it
|
||||||
|
else
|
||||||
|
{
|
||||||
|
signingKey = extKey;
|
||||||
|
}
|
||||||
var balanceChange = psbt.GetBalance(signingKey, rootedKeyPath);
|
var balanceChange = psbt.GetBalance(signingKey, rootedKeyPath);
|
||||||
if (balanceChange == Money.Zero)
|
if (balanceChange == Money.Zero)
|
||||||
{
|
{
|
||||||
ModelState.AddModelError(nameof(viewModel.SeedOrKey), "This seed does not seem to be able to sign this transaction. Either this is the wrong key, or Wallet Settings have not the correct account path in the wallet settings.");
|
ModelState.AddModelError(nameof(viewModel.SeedOrKey), "This seed does not seem to be able to sign this transaction. Either this is the wrong key, or Wallet Settings have not the correct account path in the wallet settings.");
|
||||||
return View(viewModel);
|
return View(viewModel);
|
||||||
}
|
}
|
||||||
psbt.SignAll(extKey, rootedKeyPath);
|
psbt.SignAll(signingKey, rootedKeyPath);
|
||||||
ModelState.Remove(nameof(viewModel.PSBT));
|
ModelState.Remove(nameof(viewModel.PSBT));
|
||||||
return await WalletPSBTReady(walletId, psbt.ToBase64(), signingKey.GetWif(network.NBitcoinNetwork).ToString(), rootedKeyPath.ToString());
|
return await WalletPSBTReady(walletId, psbt.ToBase64(), signingKey.GetWif(network.NBitcoinNetwork).ToString(), rootedKeyPath.ToString());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue