Fix DefaultAccountKeyPath occurences
MODIFY
WalletWasabi.Fluent/ViewModels/Dialogs/AdvancedRecoveryOptionsViewModel.cs
WalletWasabi.Fluent/ViewModels/Dialogs/AdvancedRecoveryOptionsViewModel.cs
@@ -70,7 +70,7 @@ namespace WalletWasabi.Fluent.ViewModels.Dialogs
{
var accountKeyPath = keyPath.GetAccountKeyPath();
if (keyPath.Length != accountKeyPath.Length ||
- accountKeyPath.Length != KeyManager.DefaultAccountKeyPath.Length)
+ accountKeyPath.Length != KeyManager.GetAccountKeyPath(Network.Main).Length)
{
errors.Add(ErrorSeverity.Error, "Path is not a compatible account derivation path.");
}

MODIFY
WalletWasabi.Tests/AcceptanceTests/HwiKatas.cs
WalletWasabi.Tests/AcceptanceTests/HwiKatas.cs
@@ -174,8 +174,8 @@ namespace WalletWasabi.Tests.AcceptanceTests
// ColdCard doesn't support it.
await Assert.ThrowsAsync<HwiException>(async () => await client.SendPinAsync(deviceType, devicePath, 1111, cts.Token));
- KeyPath keyPath1 = KeyManager.DefaultAccountKeyPath;
- KeyPath keyPath2 = KeyManager.DefaultAccountKeyPath.Derive(1);
+ KeyPath keyPath1 = KeyManager.GetAccountKeyPath(network);
+ KeyPath keyPath2 = KeyManager.GetAccountKeyPath(network).Derive(1);
ExtPubKey xpub1 = await client.GetXpubAsync(deviceType, devicePath, keyPath1, cts.Token);
ExtPubKey xpub2 = await client.GetXpubAsync(deviceType, devicePath, keyPath2, cts.Token);
Assert.NotNull(xpub1);
@@ -254,8 +254,8 @@ namespace WalletWasabi.Tests.AcceptanceTests
await Assert.ThrowsAsync<HwiException>(async () => await client.SendPinAsync(deviceType, devicePath, 1111, cts.Token));
- KeyPath keyPath1 = KeyManager.DefaultAccountKeyPath;
- KeyPath keyPath2 = KeyManager.DefaultAccountKeyPath.Derive(1);
+ KeyPath keyPath1 = KeyManager.GetAccountKeyPath(network);
+ KeyPath keyPath2 = KeyManager.GetAccountKeyPath(network).Derive(1);
ExtPubKey xpub1 = await client.GetXpubAsync(deviceType, devicePath, keyPath1, cts.Token);
ExtPubKey xpub2 = await client.GetXpubAsync(deviceType, devicePath, keyPath2, cts.Token);
Assert.NotNull(xpub1);
@@ -337,8 +337,8 @@ namespace WalletWasabi.Tests.AcceptanceTests
await Assert.ThrowsAsync<HwiException>(async () => await client.SendPinAsync(deviceType, devicePath, 1111, cts.Token));
- KeyPath keyPath1 = KeyManager.DefaultAccountKeyPath;
- KeyPath keyPath2 = KeyManager.DefaultAccountKeyPath.Derive(1);
+ KeyPath keyPath1 = KeyManager.GetAccountKeyPath(network);
+ KeyPath keyPath2 = KeyManager.GetAccountKeyPath(network).Derive(1);
ExtPubKey xpub1 = await client.GetXpubAsync(deviceType, devicePath, keyPath1, cts.Token);
ExtPubKey xpub2 = await client.GetXpubAsync(deviceType, devicePath, keyPath2, cts.Token);
Assert.NotNull(xpub1);

MODIFY
WalletWasabi.Tests/UnitTests/Hwi/MockedDeviceTests.cs
WalletWasabi.Tests/UnitTests/Hwi/MockedDeviceTests.cs
@@ -61,8 +61,8 @@ namespace WalletWasabi.Tests.UnitTests.Hwi
Assert.Equal("The PIN has already been sent to this device", sendpin.Message);
Assert.Equal(HwiErrorCode.DeviceAlreadyUnlocked, sendpin.ErrorCode);
- KeyPath keyPath1 = KeyManager.DefaultAccountKeyPath;
- KeyPath keyPath2 = KeyManager.DefaultAccountKeyPath.Derive(1);
+ KeyPath keyPath1 = KeyManager.GetAccountKeyPath(network);
+ KeyPath keyPath2 = KeyManager.GetAccountKeyPath(network).Derive(1);
ExtPubKey xpub1 = await client.GetXpubAsync(deviceType, devicePath, keyPath1, cts.Token);
ExtPubKey xpub2 = await client.GetXpubAsync(deviceType, devicePath, keyPath2, cts.Token);
var expecteXpub1 = NBitcoinHelpers.BetterParseExtPubKey("xpub6DHjDx4gzLV37gJWMxYJAqyKRGN46MT61RHVizdU62cbVUYu9L95cXKzX62yJ2hPbN11EeprS8sSn8kj47skQBrmycCMzFEYBQSntVKFQ5M");
@@ -135,8 +135,8 @@ namespace WalletWasabi.Tests.UnitTests.Hwi
Assert.Equal("The PIN has already been sent to this device", sendpin.Message);
Assert.Equal(HwiErrorCode.DeviceAlreadyUnlocked, sendpin.ErrorCode);
- KeyPath keyPath1 = KeyManager.DefaultAccountKeyPath;
- KeyPath keyPath2 = KeyManager.DefaultAccountKeyPath.Derive(1);
+ KeyPath keyPath1 = KeyManager.GetAccountKeyPath(network);
+ KeyPath keyPath2 = KeyManager.GetAccountKeyPath(network).Derive(1);
ExtPubKey xpub1 = await client.GetXpubAsync(deviceType, devicePath, keyPath1, cts.Token);
ExtPubKey xpub2 = await client.GetXpubAsync(deviceType, devicePath, keyPath2, cts.Token);
var expecteXpub1 = NBitcoinHelpers.BetterParseExtPubKey("xpub6DHjDx4gzLV37gJWMxYJAqyKRGN46MT61RHVizdU62cbVUYu9L95cXKzX62yJ2hPbN11EeprS8sSn8kj47skQBrmycCMzFEYBQSntVKFQ5M");
@@ -221,8 +221,8 @@ namespace WalletWasabi.Tests.UnitTests.Hwi
Assert.Equal("The Coldcard does not need a PIN sent from the host", sendpin.Message);
Assert.Equal(HwiErrorCode.UnavailableAction, sendpin.ErrorCode);
- KeyPath keyPath1 = KeyManager.DefaultAccountKeyPath;
- KeyPath keyPath2 = KeyManager.DefaultAccountKeyPath.Derive(1);
+ KeyPath keyPath1 = KeyManager.GetAccountKeyPath(network);
+ KeyPath keyPath2 = KeyManager.GetAccountKeyPath(network).Derive(1);
ExtPubKey xpub1 = await client.GetXpubAsync(deviceType, devicePath, keyPath1, cts.Token);
ExtPubKey xpub2 = await client.GetXpubAsync(deviceType, devicePath, keyPath2, cts.Token);
var expecteXpub1 = NBitcoinHelpers.BetterParseExtPubKey("xpub6DHjDx4gzLV37gJWMxYJAqyKRGN46MT61RHVizdU62cbVUYu9L95cXKzX62yJ2hPbN11EeprS8sSn8kj47skQBrmycCMzFEYBQSntVKFQ5M");
@@ -301,8 +301,8 @@ namespace WalletWasabi.Tests.UnitTests.Hwi
Assert.Equal("The Ledger Nano S does not need a PIN sent from the host", sendpin.Message);
Assert.Equal(HwiErrorCode.UnavailableAction, sendpin.ErrorCode);
- KeyPath keyPath1 = KeyManager.DefaultAccountKeyPath;
- KeyPath keyPath2 = KeyManager.DefaultAccountKeyPath.Derive(1);
+ KeyPath keyPath1 = KeyManager.GetAccountKeyPath(network);
+ KeyPath keyPath2 = KeyManager.GetAccountKeyPath(network).Derive(1);
ExtPubKey xpub1 = await client.GetXpubAsync(deviceType, devicePath, keyPath1, cts.Token);
ExtPubKey xpub2 = await client.GetXpubAsync(deviceType, devicePath, keyPath2, cts.Token);
var expecteXpub1 = NBitcoinHelpers.BetterParseExtPubKey("xpub6DHjDx4gzLV37gJWMxYJAqyKRGN46MT61RHVizdU62cbVUYu9L95cXKzX62yJ2hPbN11EeprS8sSn8kj47skQBrmycCMzFEYBQSntVKFQ5M");
@@ -381,8 +381,8 @@ namespace WalletWasabi.Tests.UnitTests.Hwi
Assert.Equal("The Ledger Nano X does not need a PIN sent from the host", sendpin.Message);
Assert.Equal(HwiErrorCode.UnavailableAction, sendpin.ErrorCode);
- KeyPath keyPath1 = KeyManager.DefaultAccountKeyPath;
- KeyPath keyPath2 = KeyManager.DefaultAccountKeyPath.Derive(1);
+ KeyPath keyPath1 = KeyManager.GetAccountKeyPath(network);
+ KeyPath keyPath2 = KeyManager.GetAccountKeyPath(network).Derive(1);
ExtPubKey xpub1 = await client.GetXpubAsync(deviceType, devicePath, keyPath1, cts.Token);
ExtPubKey xpub2 = await client.GetXpubAsync(deviceType, devicePath, keyPath2, cts.Token);
var expecteXpub1 = NBitcoinHelpers.BetterParseExtPubKey("xpub6DHjDx4gzLV37gJWMxYJAqyKRGN46MT61RHVizdU62cbVUYu9L95cXKzX62yJ2hPbN11EeprS8sSn8kj47skQBrmycCMzFEYBQSntVKFQ5M");

MODIFY
WalletWasabi.Tests/UnitTests/KeyManagementTests.cs
WalletWasabi.Tests/UnitTests/KeyManagementTests.cs
@@ -144,7 +144,8 @@ namespace WalletWasabi.Tests.UnitTests
public void CanGenerateKeys()
{
string password = "password";
- var manager = KeyManager.CreateNew(out _, password, Network.Main);
+ var network = Network.Main;
+ var manager = KeyManager.CreateNew(out _, password, network);
var random = new Random();
@@ -163,7 +164,7 @@ namespace WalletWasabi.Tests.UnitTests
Assert.Equal(isInternal, generatedKey.IsInternal);
Assert.Equal(label, generatedKey.Label);
Assert.Equal(keyState, generatedKey.KeyState);
- Assert.StartsWith(KeyManager.DefaultAccountKeyPath.ToString(), generatedKey.FullKeyPath.ToString());
+ Assert.StartsWith(KeyManager.GetAccountKeyPath(network).ToString(), generatedKey.FullKeyPath.ToString());
}
}

MODIFY
WalletWasabi.Tests/UnitTests/Transactions/PayjoinTests.cs
WalletWasabi.Tests/UnitTests/Transactions/PayjoinTests.cs
@@ -227,6 +227,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
var walletCoins = new[] { ("Pablo", 0, 0.1m, confirmed: true, anonymitySet: 1) };
var amountToPay = Money.Coins(0.001m);
var payment = new PaymentIntent(BitcoinFactory.CreateScript(), amountToPay);
+ var network = Network.Main;
// This tests the scenario where the payjoin server does not clean GloablXPubs.
var mockHttpClient = new Mock<IHttpClient>();
@@ -234,7 +235,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
.Returns((HttpRequestMessage req, CancellationToken _) => PayjoinServerOkAsync(req, psbt =>
{
var extPubkey = new ExtKey().Neuter().GetWif(Network.Main);
- psbt.GlobalXPubs.Add(extPubkey, new RootedKeyPath(extPubkey.GetPublicKey().GetHDFingerPrint(), KeyManager.DefaultAccountKeyPath));
+ psbt.GlobalXPubs.Add(extPubkey, new RootedKeyPath(extPubkey.GetPublicKey().GetHDFingerPrint(), KeyManager.GetAccountKeyPath(network)));
return psbt;
}));
@@ -248,7 +249,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
.Returns((HttpRequestMessage req, CancellationToken _) => PayjoinServerOkAsync(req, psbt =>
{
var extPubkey = new ExtKey().Neuter().GetWif(Network.Main);
- psbt.Inputs[0].AddKeyPath(new Key().PubKey, new RootedKeyPath(extPubkey.GetPublicKey().GetHDFingerPrint(), KeyManager.DefaultAccountKeyPath));
+ psbt.Inputs[0].AddKeyPath(new Key().PubKey, new RootedKeyPath(extPubkey.GetPublicKey().GetHDFingerPrint(), KeyManager.GetAccountKeyPath(network)));
return psbt;
}));
@@ -301,7 +302,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
.Returns((HttpRequestMessage req, CancellationToken _) => PayjoinServerOkAsync(req, psbt =>
{
var extPubkey = new ExtKey().Neuter().GetWif(Network.Main);
- psbt.Outputs[0].AddKeyPath(new Key().PubKey, new RootedKeyPath(extPubkey.GetPublicKey().GetHDFingerPrint(), KeyManager.DefaultAccountKeyPath));
+ psbt.Outputs[0].AddKeyPath(new Key().PubKey, new RootedKeyPath(extPubkey.GetPublicKey().GetHDFingerPrint(), KeyManager.GetAccountKeyPath(network)));
return psbt;
}));

MODIFY
WalletWasabi/Blockchain/Keys/KeyManager.cs
WalletWasabi/Blockchain/Keys/KeyManager.cs
@@ -28,9 +28,9 @@ namespace WalletWasabi.Blockchain.Keys
// BIP84-ish derivation scheme
// m / purpose' / coin_type' / account' / change / address_index
// https://github.com/bitcoin/bips/blob/master/bip-0084.mediawiki
- public static readonly KeyPath DefaultAccountKeyPath = new("m/84h/0h/0h");
+ private static readonly KeyPath DefaultAccountKeyPath = new("m/84h/0h/0h");
- public static readonly KeyPath TestNetAccountKeyPath = new("m/84h/1h/0h");
+ private static readonly KeyPath TestNetAccountKeyPath = new("m/84h/1h/0h");
[JsonConstructor]
public KeyManager(BitcoinEncryptedSecretNoEC encryptedSecret, byte[] chainCode, HDFingerprint? masterFingerprint, ExtPubKey extPubKey, bool? passwordVerified, int? minGapLimit, BlockchainState blockchainState, string? filePath = null, KeyPath? accountKeyPath = null)

MODIFY
WalletWasabi/Blockchain/Transactions/TransactionFactory.cs
WalletWasabi/Blockchain/Transactions/TransactionFactory.cs
@@ -318,7 +318,7 @@ namespace WalletWasabi.Blockchain.Transactions
psbt = payjoinClient.RequestPayjoin(
psbt,
KeyManager.ExtPubKey,
- new RootedKeyPath(KeyManager.MasterFingerprint.Value, KeyManager.DefaultAccountKeyPath),
+ new RootedKeyPath(KeyManager.MasterFingerprint.Value, KeyManager.GetAccountKeyPath(Network)),
changeHdPubKey,
CancellationToken.None).GetAwaiter().GetResult(); // WTF??!
builder.SignPSBT(psbt);

Fix DefaultAccountKeyPath occurences