Generate the private key
MODIFY
WalletWasabi.Packager/Program.cs
WalletWasabi.Packager/Program.cs
@@ -63,6 +63,12 @@ public static class Program
return;
}
+ if (argsProcessor.IsGeneratePrivateKey())
+ {
+ await WasabiSignerHelpers.SavePrivateKeyToFileAsync().ConfigureAwait(false);
+ return;
+ }
+
// Only binaries mode is for deterministic builds.
OnlyBinaries = argsProcessor.IsOnlyBinariesMode();

ADD
WalletWasabi.Packager/Properties/launchSettings.json
+{
+ "profiles": {
+ "WalletWasabi.Packager": {
+ "commandName": "Project",
+ "commandLineArgs": "generateprivatekey"
+ }
+ }
+}
\ No newline at end of file

MODIFY
WalletWasabi/Helpers/WasabiSignerHelpers.cs
WalletWasabi/Helpers/WasabiSignerHelpers.cs
@@ -7,11 +7,15 @@ using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Security.Cryptography;
+using System.Diagnostics.CodeAnalysis;
namespace WalletWasabi.Helpers;
public class WasabiSignerHelpers
{
+ private const string WasabiKeyHeadline = "WASABI PRIVATE KEY";
+ private const string WasabiPrivateKeyFilePath = @"C:\wasabi\Wasabi.privkey";
+
public static async Task SignSha256SumsFileAsync(string sha256sumsFilePath, Key wasabiPrivateKey)
{
var bytes = await File.ReadAllBytesAsync(sha256sumsFilePath).ConfigureAwait(false);
@@ -25,4 +29,37 @@ public class WasabiSignerHelpers
await File.WriteAllTextAsync(wasabiSignatureFilePath, base64Signature).ConfigureAwait(false);
}
+
+ public static async Task SavePrivateKeyToFileAsync()
+ {
+ using Key key = new();
+ var destinationFilePath = WasabiPrivateKeyFilePath;
+ if (File.Exists(destinationFilePath))
+ {
+ throw new ArgumentException("Private key file already exists.");
+ }
+
+ IoHelpers.EnsureContainingDirectoryExists(destinationFilePath);
+ using StreamWriter streamWriter = new(destinationFilePath);
+ await streamWriter.WriteLineAsync($"-----BEGIN {WasabiKeyHeadline}-----").ConfigureAwait(false);
+ await streamWriter.WriteLineAsync(key.ToString(Network.Main)).ConfigureAwait(false);
+ await streamWriter.WriteLineAsync($"-----END {WasabiKeyHeadline}-----").ConfigureAwait(false);
+ }
+
+ public static Key GetPrivateKeyFromFile(string fileName)
+ {
+ string[] keyFileContent = File.ReadAllLines(fileName);
+ bool isHeadlineBeginValid = keyFileContent[0] == $"-----BEGIN {WasabiKeyHeadline}-----";
+ bool isHeadlineEndValid = keyFileContent[2] == $"-----END {WasabiKeyHeadline}-----";
+
+ if (!isHeadlineBeginValid || !isHeadlineEndValid)
+ {
+ throw new ArgumentException("Wasabi private key file's content was invalid.");
+ }
+
+ string wif = keyFileContent[1];
+ BitcoinSecret secret = new(wif, Network.Main);
+
+ return secret.PrivateKey;
+ }
}

Generate the private key