Use Wasabi Schnorr blinding signature from Wasabi
MODIFY
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
@@ -24,7 +24,7 @@ using WalletWasabi.CoinJoin.Coordinator.Rounds;
using WalletWasabi.Crypto;
using WalletWasabi.Helpers;
using WalletWasabi.Logging;
-using static NBitcoin.Crypto.SchnorrBlinding;
+using static WalletWasabi.Crypto.SchnorrBlinding;
namespace WalletWasabi.Backend.Controllers
{

MODIFY
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
using NBitcoin;
-using NBitcoin.BouncyCastle.Math;
-using NBitcoin.Crypto;
using NBitcoin.Protocol;
using NBitcoin.RPC;
using System;
@@ -48,7 +46,7 @@ using WalletWasabi.TorSocks5;
using WalletWasabi.Wallets;
using WalletWasabi.WebClients.Wasabi;
using Xunit;
-using static NBitcoin.Crypto.SchnorrBlinding;
+using static WalletWasabi.Crypto.SchnorrBlinding;
namespace WalletWasabi.Tests.RegressionTests
{
@@ -223,10 +221,10 @@ namespace WalletWasabi.Tests.RegressionTests
round = coordinator.GetCurrentInputRegisterableRoundOrDefault();
var requester = new Requester();
- uint256 msg = new uint256(Hashes.SHA256(network.Consensus.ConsensusFactory.CreateTransaction().ToBytes()));
+ uint256 msg = new uint256(NBitcoin.Crypto.Hashes.SHA256(network.Consensus.ConsensusFactory.CreateTransaction().ToBytes()));
uint256 blindedData = requester.BlindMessage(msg, round.MixingLevels.GetBaseLevel().SchnorrKey.SchnorrPubKey);
inputsRequest.BlindedOutputScripts = new[] { blindedData };
- uint256 blindedOutputScriptsHash = new uint256(Hashes.SHA256(blindedData.ToBytes()));
+ uint256 blindedOutputScriptsHash = new uint256(NBitcoin.Crypto.Hashes.SHA256(blindedData.ToBytes()));
proof = key.SignCompact(blindedOutputScriptsHash);
inputsRequest.Inputs.First().Proof = proof;
@@ -266,7 +264,7 @@ namespace WalletWasabi.Tests.RegressionTests
msg = network.Consensus.ConsensusFactory.CreateTransaction().GetHash();
blindedData = requester.BlindMessage(msg, round.MixingLevels.GetBaseLevel().SchnorrKey.SchnorrPubKey);
inputsRequest.BlindedOutputScripts = new[] { blindedData };
- blindedOutputScriptsHash = new uint256(Hashes.SHA256(blindedData.ToBytes()));
+ blindedOutputScriptsHash = new uint256(NBitcoin.Crypto.Hashes.SHA256(blindedData.ToBytes()));
proof = key.SignCompact(blindedOutputScriptsHash);
inputsRequest.Inputs.First().Proof = proof;
using (var aliceClient = await AliceClient.CreateNewAsync(roundId, registeredAddresses, schnorrPubKeys, requesters, network, inputsRequest, baseUri, null))
@@ -305,7 +303,7 @@ namespace WalletWasabi.Tests.RegressionTests
requester = new Requester();
blindedData = requester.BlindScript(round.MixingLevels.GetBaseLevel().SchnorrKey.SchnorrPubKey.SignerPubKey, round.MixingLevels.GetBaseLevel().SchnorrKey.SchnorrPubKey.RpubKey, key.ScriptPubKey);
inputsRequest.BlindedOutputScripts = new[] { blindedData };
- blindedOutputScriptsHash = new uint256(Hashes.SHA256(blindedData.ToBytes()));
+ blindedOutputScriptsHash = new uint256(NBitcoin.Crypto.Hashes.SHA256(blindedData.ToBytes()));
proof = key.SignCompact(blindedOutputScriptsHash);
inputsRequest.Inputs.First().Proof = proof;
@@ -329,7 +327,7 @@ namespace WalletWasabi.Tests.RegressionTests
}
inputsRequest.BlindedOutputScripts = new[] { uint256.One };
- blindedOutputScriptsHash = new uint256(Hashes.SHA256(uint256.One.ToBytes()));
+ blindedOutputScriptsHash = new uint256(NBitcoin.Crypto.Hashes.SHA256(uint256.One.ToBytes()));
proof = key.SignCompact(blindedOutputScriptsHash);
inputsRequest.Inputs.First().Proof = proof;
inputsRequest.Inputs = new List<InputProofModel> { inputsRequest.Inputs.First(), inputsRequest.Inputs.First() };
@@ -439,7 +437,7 @@ namespace WalletWasabi.Tests.RegressionTests
registeredAddresses = new[] { bitcoinWitPubKeyAddress };
Script script = bitcoinWitPubKeyAddress.ScriptPubKey;
blindedData = requester.BlindScript(round.MixingLevels.GetBaseLevel().Signer.Key.PubKey, round.MixingLevels.GetBaseLevel().Signer.R.PubKey, script);
- blindedOutputScriptsHash = new uint256(Hashes.SHA256(blindedData.ToBytes()));
+ blindedOutputScriptsHash = new uint256(NBitcoin.Crypto.Hashes.SHA256(blindedData.ToBytes()));
using (var aliceClient = await AliceClient.CreateNewAsync(roundId, registeredAddresses, schnorrPubKeys, requesters, network, new Key().PubKey.GetAddress(ScriptPubKeyType.Segwit, network), new[] { blindedData }, new InputProofModel[] { new InputProofModel { Input = coin.Outpoint.ToTxoRef(), Proof = key.SignCompact(blindedOutputScriptsHash) } }, baseUri, null))
{
@@ -536,9 +534,9 @@ namespace WalletWasabi.Tests.RegressionTests
var requester2 = new Requester();
uint256 blinded1 = requester1.BlindScript(round.MixingLevels.GetBaseLevel().Signer.Key.PubKey, round.MixingLevels.GetBaseLevel().Signer.R.PubKey, outputAddress1.ScriptPubKey);
- uint256 blindedOutputScriptsHash1 = new uint256(Hashes.SHA256(blinded1.ToBytes()));
+ uint256 blindedOutputScriptsHash1 = new uint256(NBitcoin.Crypto.Hashes.SHA256(blinded1.ToBytes()));
uint256 blinded2 = requester2.BlindScript(round.MixingLevels.GetBaseLevel().Signer.Key.PubKey, round.MixingLevels.GetBaseLevel().Signer.R.PubKey, outputAddress2.ScriptPubKey);
- uint256 blindedOutputScriptsHash2 = new uint256(Hashes.SHA256(blinded2.ToBytes()));
+ uint256 blindedOutputScriptsHash2 = new uint256(NBitcoin.Crypto.Hashes.SHA256(blinded2.ToBytes()));
var input1 = new OutPoint(hash1, index1);
var input2 = new OutPoint(hash2, index2);
@@ -689,7 +687,7 @@ namespace WalletWasabi.Tests.RegressionTests
// Calculate the SHA256( blind1 || blind2 || .....|| blindN )
var blindedOutputScriptList = outputs.Select(x => x.blindedScript);
var blindedOutputScriptListBytes = ByteHelpers.Combine(blindedOutputScriptList.Select(x => x.ToBytes()));
- var blindedOutputScriptsHash = new uint256(Hashes.SHA256(blindedOutputScriptListBytes));
+ var blindedOutputScriptsHash = new uint256(NBitcoin.Crypto.Hashes.SHA256(blindedOutputScriptListBytes));
// Create 4 new coins that we want to mix
var inputs = new List<(TxoRef input, byte[] proof, Coin coin, Key key)>();
@@ -816,7 +814,7 @@ namespace WalletWasabi.Tests.RegressionTests
CoordinatorRound round = coordinator.GetCurrentInputRegisterableRoundOrDefault();
var requester = new Requester();
uint256 blinded = requester.BlindScript(round.MixingLevels.GetBaseLevel().Signer.Key.PubKey, round.MixingLevels.GetBaseLevel().Signer.R.PubKey, activeOutputAddress.ScriptPubKey);
- uint256 blindedOutputScriptsHash = new uint256(Hashes.SHA256(blinded.ToBytes()));
+ uint256 blindedOutputScriptsHash = new uint256(NBitcoin.Crypto.Hashes.SHA256(blinded.ToBytes()));
var inputProofModels = new List<InputProofModel>();
int numberOfInputs = new Random().Next(1, 7);

MODIFY
WalletWasabi.Tests/RegressionTests/DosTests.cs
WalletWasabi.Tests/RegressionTests/DosTests.cs
@@ -48,7 +48,8 @@ using WalletWasabi.TorSocks5;
using WalletWasabi.Wallets;
using WalletWasabi.WebClients.Wasabi;
using Xunit;
-using static NBitcoin.Crypto.SchnorrBlinding;
+using static WalletWasabi.Crypto.SchnorrBlinding;
+using UnblindedSignature = WalletWasabi.Crypto.UnblindedSignature;
namespace WalletWasabi.Tests.RegressionTests
{

MODIFY
WalletWasabi/CoinJoin/Client/Clients/AliceClient.cs
WalletWasabi/CoinJoin/Client/Clients/AliceClient.cs
using NBitcoin;
using NBitcoin.BouncyCastle.Math;
-using NBitcoin.Crypto;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
@@ -15,7 +14,8 @@ using WalletWasabi.CoinJoin.Common.Crypto;
using WalletWasabi.CoinJoin.Common.Models;
using WalletWasabi.Exceptions;
using WalletWasabi.Logging;
-using static NBitcoin.Crypto.SchnorrBlinding;
+using static WalletWasabi.Crypto.SchnorrBlinding;
+using UnblindedSignature = WalletWasabi.Crypto.UnblindedSignature;
namespace WalletWasabi.CoinJoin.Client.Clients
{
@@ -169,7 +169,7 @@ namespace WalletWasabi.CoinJoin.Client.Clients
var address = RegisteredAddresses[i];
- uint256 outputScriptHash = new uint256(Hashes.SHA256(address.ScriptPubKey.ToBytes()));
+ uint256 outputScriptHash = new uint256(NBitcoin.Crypto.Hashes.SHA256(address.ScriptPubKey.ToBytes()));
PubKey signerPubKey = SchnorrPubKeys[i].SignerPubKey;
if (!VerifySignature(outputScriptHash, unblindedSignature, signerPubKey))
{

MODIFY
WalletWasabi/CoinJoin/Client/Clients/CoinJoinClient.cs
WalletWasabi/CoinJoin/Client/Clients/CoinJoinClient.cs
using NBitcoin;
-using NBitcoin.BouncyCastle.Math;
-using NBitcoin.Crypto;
using Nito.AsyncEx;
using System;
using System.Collections.Concurrent;
@@ -24,7 +22,7 @@ using WalletWasabi.Crypto;
using WalletWasabi.Helpers;
using WalletWasabi.Logging;
using WalletWasabi.Services;
-using static NBitcoin.Crypto.SchnorrBlinding;
+using static WalletWasabi.Crypto.SchnorrBlinding;
namespace WalletWasabi.CoinJoin.Client.Clients
{
@@ -496,7 +494,7 @@ namespace WalletWasabi.CoinJoin.Client.Clients
BitcoinAddress address = outputAddresses.actives.Select(x => x.GetP2wpkhAddress(Network)).ElementAt(i);
SchnorrPubKey schnorrPubKey = schnorrPubKeys[i];
- var outputScriptHash = new uint256(Hashes.SHA256(address.ScriptPubKey.ToBytes()));
+ var outputScriptHash = new uint256(NBitcoin.Crypto.Hashes.SHA256(address.ScriptPubKey.ToBytes()));
var requester = new Requester();
uint256 blindedOutputScriptHash = requester.BlindMessage(outputScriptHash, schnorrPubKey);
requesters.Add(requester);
@@ -505,7 +503,7 @@ namespace WalletWasabi.CoinJoin.Client.Clients
}
byte[] blindedOutputScriptHashesByte = ByteHelpers.Combine(blindedOutputScriptHashes.Select(x => x.ToBytes()));
- uint256 blindedOutputScriptsHash = new uint256(Hashes.SHA256(blindedOutputScriptHashesByte));
+ uint256 blindedOutputScriptsHash = new uint256(NBitcoin.Crypto.Hashes.SHA256(blindedOutputScriptHashesByte));
var inputProofs = new List<InputProofModel>();
foreach (TxoRef coinReference in registrableCoins)

MODIFY
WalletWasabi/CoinJoin/Common/Crypto/SchnorrPubKey.cs
WalletWasabi/CoinJoin/Common/Crypto/SchnorrPubKey.cs
@@ -5,7 +5,7 @@ using System.Collections.Generic;
using System.Text;
using WalletWasabi.Helpers;
using WalletWasabi.JsonConverters;
-using static NBitcoin.Crypto.SchnorrBlinding;
+using static WalletWasabi.Crypto.SchnorrBlinding;
namespace WalletWasabi.CoinJoin.Common.Crypto
{

MODIFY
WalletWasabi/CoinJoin/Common/Models/ActiveOutput.cs
WalletWasabi/CoinJoin/Common/Models/ActiveOutput.cs
using NBitcoin;
-using NBitcoin.Crypto;
using System;
using System.Collections.Generic;
using System.Text;
+using WalletWasabi.Crypto;
using WalletWasabi.Helpers;
namespace WalletWasabi.CoinJoin.Common.Models

MODIFY
WalletWasabi/CoinJoin/Common/Models/OutputRequest.cs
WalletWasabi/CoinJoin/Common/Models/OutputRequest.cs
using NBitcoin;
-using NBitcoin.Crypto;
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using System.Net.Http;
using System.Text;
+using WalletWasabi.Crypto;
using WalletWasabi.JsonConverters;
namespace WalletWasabi.CoinJoin.Common.Models

MODIFY
WalletWasabi/CoinJoin/Coordinator/MixingLevels/MixingLevel.cs
WalletWasabi/CoinJoin/Coordinator/MixingLevels/MixingLevel.cs
@@ -6,7 +6,7 @@ using System.Text;
using WalletWasabi.CoinJoin.Common.Crypto;
using WalletWasabi.Helpers;
using WalletWasabi.JsonConverters;
-using static NBitcoin.Crypto.SchnorrBlinding;
+using static WalletWasabi.Crypto.SchnorrBlinding;
namespace WalletWasabi.CoinJoin.Coordinator.MixingLevels
{

MODIFY
WalletWasabi/CoinJoin/Coordinator/MixingLevels/MixingLevelCollection.cs
WalletWasabi/CoinJoin/Coordinator/MixingLevels/MixingLevelCollection.cs
@@ -6,7 +6,7 @@ using System.Linq;
using System.Text;
using WalletWasabi.CoinJoin.Common.Crypto;
using WalletWasabi.Helpers;
-using static NBitcoin.Crypto.SchnorrBlinding;
+using static WalletWasabi.Crypto.SchnorrBlinding;
namespace WalletWasabi.CoinJoin.Coordinator.MixingLevels
{

MODIFY
WalletWasabi/CoinJoin/Coordinator/Rounds/CoordinatorRound.cs
WalletWasabi/CoinJoin/Coordinator/Rounds/CoordinatorRound.cs
using NBitcoin;
-using NBitcoin.Crypto;
using NBitcoin.RPC;
using Newtonsoft.Json.Linq;
using Nito.AsyncEx;
@@ -14,9 +13,10 @@ using WalletWasabi.CoinJoin.Common.Models;
using WalletWasabi.CoinJoin.Coordinator.Banning;
using WalletWasabi.CoinJoin.Coordinator.MixingLevels;
using WalletWasabi.CoinJoin.Coordinator.Participants;
+using WalletWasabi.Crypto;
using WalletWasabi.Helpers;
using WalletWasabi.Logging;
-using static NBitcoin.Crypto.SchnorrBlinding;
+using static WalletWasabi.Crypto.SchnorrBlinding;
namespace WalletWasabi.CoinJoin.Coordinator.Rounds
{

MODIFY
WalletWasabi/Extensions/NBitcoinExtensions.cs
WalletWasabi/Extensions/NBitcoinExtensions.cs
@@ -13,7 +13,7 @@ using WalletWasabi.Blockchain.Transactions;
using WalletWasabi.CoinJoin.Common.Crypto;
using WalletWasabi.Helpers;
using WalletWasabi.Models;
-using static NBitcoin.Crypto.SchnorrBlinding;
+using static WalletWasabi.Crypto.SchnorrBlinding;
namespace NBitcoin
{
@@ -166,23 +166,6 @@ namespace NBitcoin
return pubKey.WitHash == address.Hash;
}
- public static bool VerifyUnblindedSignature(this Signer signer, UnblindedSignature signature, byte[] data)
- {
- uint256 hash = new uint256(Hashes.SHA256(data));
- return VerifySignature(hash, signature, signer.Key.PubKey);
- }
-
- public static bool VerifyUnblindedSignature(this Signer signer, UnblindedSignature signature, uint256 dataHash)
- {
- return VerifySignature(dataHash, signature, signer.Key.PubKey);
- }
-
- public static uint256 BlindScript(this Requester requester, PubKey signerPubKey, PubKey rPubKey, Script script)
- {
- var msg = new uint256(Hashes.SHA256(script.ToBytes()));
- return requester.BlindMessage(msg, rPubKey, signerPubKey);
- }
-
public static Signer CreateSigner(this SchnorrKey schnorrKey)
{
var k = Guard.NotNull(nameof(schnorrKey.SignerKey), schnorrKey.SignerKey);

Use Wasabi Schnorr blinding signature from Wasabi