Clean models validation
MODIFY
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
@@ -126,7 +126,7 @@ namespace WalletWasabi.Backend.Controllers
// Do more checks.
try
{
- uint256[] blindedOutputs = request.BlindedOutputScripts.Select(x => new uint256(x)).ToArray();
+ uint256[] blindedOutputs = request.BlindedOutputScripts.ToArray();
int blindedOutputCount = blindedOutputs.Length;
int maxBlindedOutputCount = round.MixingLevels.Count();
if (blindedOutputCount > maxBlindedOutputCount)
@@ -306,7 +306,7 @@ namespace WalletWasabi.Backend.Controllers
var resp = new InputsResponse
{
UniqueId = alice.UniqueId,
- BlindedOutputSignatures = blindSignatures.Select(x => x.ToString()),
+ BlindedOutputSignatures = blindSignatures,
RoundId = round.RoundId
};
return Ok(resp);

MODIFY
WalletWasabi.Tests/ModelTests.cs
WalletWasabi.Tests/ModelTests.cs
@@ -209,7 +209,7 @@ namespace WalletWasabi.Tests
{
UniqueId = Guid.NewGuid(),
RoundId = 1,
- BlindedOutputSignatures = bigIntegers.Select(x => x.ToString())
+ BlindedOutputSignatures = bigIntegers
};
var serialized = JsonConvert.SerializeObject(resp);
@@ -218,7 +218,7 @@ namespace WalletWasabi.Tests
Assert.Equal(resp.UniqueId, deserialized.UniqueId);
for (int i = 0; i < bigIntegers.Length; i++)
{
- Assert.Equal(bigIntegers[i], deserialized.BlindedOutputSignatures.Select(x => new BigInteger(x)).ToArray()[i]);
+ Assert.Equal(bigIntegers[i], deserialized.BlindedOutputSignatures.ToArray()[i]);
}
}

MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -1751,7 +1751,7 @@ namespace WalletWasabi.Tests
Assert.Equal($"{HttpStatusCode.BadRequest.ToReasonString()}\nInvalid request.", httpRequestException.Message);
byte[] dummySignature = new byte[65];
- inputsRequest.BlindedOutputScripts = new string[] { uint256.Zero.ToString() };
+ inputsRequest.BlindedOutputScripts = new[] { uint256.Zero };
inputsRequest.ChangeOutputAddress = new Key().PubKey.GetAddress(network);
inputsRequest.Inputs = new List<InputProofModel> { new InputProofModel { Input = new TxoRef(uint256.One, 0), Proof = dummySignature } };
httpRequestException = await Assert.ThrowsAsync<HttpRequestException>(async () => await AliceClient.CreateNewAsync(network, inputsRequest, baseUri));
@@ -1796,8 +1796,8 @@ namespace WalletWasabi.Tests
var requester = new Requester();
uint256 msg = new uint256(Hashes.SHA256(network.Consensus.ConsensusFactory.CreateTransaction().ToBytes()));
uint256 blindedData = requester.BlindMessage(msg, round.MixingLevels.GetBaseLevel().SchnorrKey.SchnorrPubKey);
- inputsRequest.BlindedOutputScripts = new string[] { blindedData.ToString() };
- proof = key.SignCompact(new uint256(inputsRequest.BlindedOutputScripts.First()));
+ inputsRequest.BlindedOutputScripts = new[] { blindedData };
+ proof = key.SignCompact(inputsRequest.BlindedOutputScripts.First());
inputsRequest.Inputs.First().Proof = proof;
httpRequestException = await Assert.ThrowsAsync<HttpRequestException>(async () => await AliceClient.CreateNewAsync(network, inputsRequest, baseUri));
Assert.StartsWith($"{HttpStatusCode.BadRequest.ToReasonString()}\nNot enough inputs are provided. Fee to pay:", httpRequestException.Message);
@@ -1821,8 +1821,8 @@ namespace WalletWasabi.Tests
requester = new Requester();
msg = network.Consensus.ConsensusFactory.CreateTransaction().GetHash();
blindedData = requester.BlindMessage(msg, round.MixingLevels.GetBaseLevel().SchnorrKey.SchnorrPubKey);
- inputsRequest.BlindedOutputScripts = new string[] { blindedData.ToString() };
- proof = key.SignCompact(new uint256(inputsRequest.BlindedOutputScripts.First()));
+ inputsRequest.BlindedOutputScripts = new [] { blindedData };
+ proof = key.SignCompact(inputsRequest.BlindedOutputScripts.First());
inputsRequest.Inputs.First().Proof = proof;
coordinator.AbortAllRoundsInInputRegistration(nameof(RegTests), "");
using (var aliceClient = await AliceClient.CreateNewAsync(network, inputsRequest, baseUri))
@@ -1861,7 +1861,7 @@ namespace WalletWasabi.Tests
round = coordinator.GetCurrentInputRegisterableRound();
requester = new Requester();
blindedData = requester.BlindScript(round.MixingLevels.GetBaseLevel().SchnorrKey.SchnorrPubKey.SignerPubKey, round.MixingLevels.GetBaseLevel().SchnorrKey.SchnorrPubKey.RpubKey, key.ScriptPubKey);
- inputsRequest.BlindedOutputScripts = new string[] { blindedData.ToString() };
+ inputsRequest.BlindedOutputScripts = new[] { blindedData };
proof = key.SignCompact(new uint256(inputsRequest.BlindedOutputScripts.First()));
inputsRequest.Inputs.First().Proof = proof;
using (var aliceClient = await AliceClient.CreateNewAsync(network, inputsRequest, baseUri))
@@ -1875,7 +1875,7 @@ namespace WalletWasabi.Tests
Assert.Equal(1, roundState.RegisteredPeerCount);
}
- inputsRequest.BlindedOutputScripts = new string[] { uint256.One.ToString() };
+ inputsRequest.BlindedOutputScripts = new[] { uint256.One };
proof = key.SignCompact(new uint256(inputsRequest.BlindedOutputScripts.First()));
inputsRequest.Inputs.First().Proof = proof;
inputsRequest.Inputs = new List<InputProofModel> { inputsRequest.Inputs.First(), inputsRequest.Inputs.First() };

MODIFY
WalletWasabi/Backend/Models/Requests/InputsRequest.cs
WalletWasabi/Backend/Models/Requests/InputsRequest.cs
@@ -10,11 +10,12 @@ namespace WalletWasabi.Backend.Models.Requests
{
public class InputsRequest
{
- [Required]
+ [Required, MinLength(1)]
public IEnumerable<InputProofModel> Inputs { get; set; }
- [Required]
- public IEnumerable<string> BlindedOutputScripts { get; set; }
+ [Required, MinLength(1)]
+ [JsonProperty (ItemConverterType = typeof(Uint256JsonConverter))]
+ public IEnumerable<uint256> BlindedOutputScripts { get; set; }
[Required]
[JsonConverter(typeof(BitcoinAddressJsonConverter))]

MODIFY
WalletWasabi/Backend/Models/Responses/InputsResponse.cs
WalletWasabi/Backend/Models/Responses/InputsResponse.cs
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
using WalletWasabi.JsonConverters;
namespace WalletWasabi.Backend.Models.Responses
{
public class InputsResponse
{
- public IEnumerable<string> BlindedOutputSignatures { get; set; }
+ [Required, MinLength(1)]
+ [JsonProperty (ItemConverterType = typeof(BigIntegerJsonConverter))]
+ public IEnumerable<BigInteger> BlindedOutputSignatures { get; set; }
[JsonConverter(typeof(GuidJsonConverter))]
public Guid UniqueId { get; set; }

MODIFY
WalletWasabi/Models/TxoRef.cs
WalletWasabi/Models/TxoRef.cs
@@ -3,6 +3,7 @@ using WalletWasabi.Helpers;
using NBitcoin;
using Newtonsoft.Json;
using System;
+using System.ComponentModel.DataAnnotations;
namespace WalletWasabi.Models
{
@@ -12,6 +13,7 @@ namespace WalletWasabi.Models
[JsonObject(MemberSerialization.OptIn)]
public class TxoRef : IEquatable<TxoRef>, IEquatable<OutPoint>
{
+ [Required]
[JsonProperty(Order = 1)]
[JsonConverter(typeof(Uint256JsonConverter))]
public uint256 TransactionId { get; }

MODIFY
WalletWasabi/WebClients/Wasabi/ChaumianCoinJoin/AliceClient.cs
WalletWasabi/WebClients/Wasabi/ChaumianCoinJoin/AliceClient.cs
@@ -48,7 +48,7 @@ namespace WalletWasabi.WebClients.Wasabi.ChaumianCoinJoin
client.RoundId = inputsResponse.RoundId;
client.UniqueId = inputsResponse.UniqueId;
- client.BlindedOutputSignatures = inputsResponse.BlindedOutputSignatures.Select(x => new BigInteger(x)).ToArray();
+ client.BlindedOutputSignatures = inputsResponse.BlindedOutputSignatures.ToArray();
Logger.LogInfo<AliceClient>($"Round ({client.RoundId}), Alice ({client.UniqueId}): Registered {request.Inputs.Count()} inputs.");
return client;
@@ -65,7 +65,7 @@ namespace WalletWasabi.WebClients.Wasabi.ChaumianCoinJoin
{
var request = new InputsRequest
{
- BlindedOutputScripts = blindedOutputScriptHashes.Select(x => x.ToString()),
+ BlindedOutputScripts = blindedOutputScriptHashes,
ChangeOutputAddress = changeOutput,
Inputs = inputs
};

Clean models validation