Verify back the signature
MODIFY
WalletWasabi.Packager/Program.cs
WalletWasabi.Packager/Program.cs
@@ -177,7 +177,10 @@ public static class Program
using var key = await WasabiSignerHelpers.GetPrivateKeyFromFileAsync().ConfigureAwait(false);
- await WasabiSignerHelpers.SignSha256SumsFileAsync(Path.Combine(BinDistDirectory, "SHA256SUMS.asc"), key).ConfigureAwait(false);
+ var sha256sumAscFilePath = Path.Combine(BinDistDirectory, "SHA256SUMS.asc");
+ await WasabiSignerHelpers.SignSha256SumsFileAsync(sha256sumAscFilePath, key).ConfigureAwait(false);
+
+ await WasabiSignerHelpers.VerifySha256SumsFileAsync(sha256sumAscFilePath);
IoHelpers.OpenFolderInFileExplorer(BinDistDirectory);
}

MODIFY
WalletWasabi/Helpers/Constants.cs
WalletWasabi/Helpers/Constants.cs
@@ -92,6 +92,7 @@ public static class Constants
public static readonly ExtPubKey FallBackCoordinatorExtPubKey = NBitcoinHelpers.BetterParseExtPubKey("xpub6BgAZqHhxw6pgEi2F38w5RBqctqCEoVWqcMdrn1epQZceKHtn8f8zHBduM3fwYQEKEGUf4efD6qRPc9wvDF4neoc6JjDbHNiaHbs3we5qL3");
public static readonly ExtPubKey WabiSabiFallBackCoordinatorExtPubKey = NBitcoinHelpers.BetterParseExtPubKey("xpub6C13JhXzjAhVRgeTcRSWqKEPe1vHi3Tmh2K9PN1cZaZFVjjSaj76y5NNyqYjc2bugj64LVDFYu8NZWtJsXNYKFb9J94nehLAPAKqKiXcebC");
+ public static PubKey WasabiPubKey = new("02c8ab8eea76c83788e246a1baee10c04a134ec11be6553946f6ae65e47ae9a608");
public static readonly string[] UserAgents = new[]
{

MODIFY
WalletWasabi/Helpers/WasabiSignerHelpers.cs
WalletWasabi/Helpers/WasabiSignerHelpers.cs
@@ -11,20 +11,41 @@ public class WasabiSignerHelpers
private const string WasabiPrivateKeyFilePath = @"C:\wasabi\Wasabi.privkey";
private const string WasabiPublicKeyFilePath = @"C:\wasabi\Wasabi.pubkey";
- public static async Task SignSha256SumsFileAsync(string sha256sumsFilePath, Key wasabiPrivateKey)
+ public static async Task SignSha256SumsFileAsync(string sha256SumsAscFilePath, Key wasabiPrivateKey)
{
- var bytes = await File.ReadAllBytesAsync(sha256sumsFilePath).ConfigureAwait(false);
-
+ var bytes = await File.ReadAllBytesAsync(sha256SumsAscFilePath).ConfigureAwait(false);
using SHA256 sha = SHA256.Create();
byte[] computedHash = sha.ComputeHash(bytes);
+
ECDSASignature signature = wasabiPrivateKey.Sign(new uint256(computedHash));
string base64Signature = Convert.ToBase64String(signature.ToDER());
- var wasabiSignatureFilePath = Path.ChangeExtension(sha256sumsFilePath, "wasabisig");
+ var wasabiSignatureFilePath = Path.ChangeExtension(sha256SumsAscFilePath, "wasabisig");
await File.WriteAllTextAsync(wasabiSignatureFilePath, base64Signature).ConfigureAwait(false);
}
+ public static async Task VerifySha256SumsFileAsync(string sha256SumsAscFilePath)
+ {
+ // Read the content file
+ var bytes = await File.ReadAllBytesAsync(sha256SumsAscFilePath).ConfigureAwait(false);
+ using SHA256 sha = SHA256.Create();
+ byte[] hash = sha.ComputeHash(bytes);
+
+ // Read the signature file
+ var wasabiSignatureFilePath = Path.ChangeExtension(sha256SumsAscFilePath, "wasabisig");
+ string signatureText = await File.ReadAllTextAsync(wasabiSignatureFilePath).ConfigureAwait(false);
+ byte[] sigBytes = Convert.FromBase64String(signatureText);
+ var wasabiSignature = ECDSASignature.FromDER(sigBytes);
+
+ var pubKey = Constants.WasabiPubKey;
+
+ if (!pubKey.Verify(new uint256(hash), wasabiSignature))
+ {
+ throw new InvalidOperationException("Invalid wasabi signature.");
+ }
+ }
+
public static async Task GeneratePrivateAndPublicKeyToFileAsync()
{
using Key key = new();
@@ -35,7 +56,7 @@ public class WasabiSignerHelpers
IoHelpers.EnsureContainingDirectoryExists(WasabiPrivateKeyFilePath);
- await File.WriteAllTextAsync(WasabiPrivateKeyFilePath, key.ToString()).ConfigureAwait(false);
+ await File.WriteAllTextAsync(WasabiPrivateKeyFilePath, key.ToString(Network.Main)).ConfigureAwait(false);
await File.WriteAllTextAsync(WasabiPublicKeyFilePath, key.PubKey.ToString()).ConfigureAwait(false);
}

Verify back the signature