Add basic checks
MODIFY
HiddenWallet.ChaumianTumbler/Configuration/Config.cs
HiddenWallet.ChaumianTumbler/Configuration/Config.cs
@@ -16,6 +16,10 @@ namespace HiddenWallet.ChaumianTumbler.Configuration
[JsonObject(MemberSerialization.OptIn)]
public class Config
{
+ [JsonProperty(PropertyName = "Network")]
+ [JsonConverter(typeof(NetworkConverter))]
+ public Network Network { get; private set; }
+
[JsonProperty(PropertyName = "DenominationAlgorithm")]
[JsonConverter(typeof(StringEnumConverter))]
public DenominationAlgorithm? DenominationAlgorithm { get; private set; }
@@ -68,6 +72,7 @@ namespace HiddenWallet.ChaumianTumbler.Configuration
{
if (path == null) throw new ArgumentNullException(nameof(path));
+ Network = Network.Main;
DenominationAlgorithm = Configuration.DenominationAlgorithm.FixedUSD;
DenominationUSD = 10000;
DenominationBTC = new Money(1m, MoneyUnit.BTC);
@@ -88,6 +93,7 @@ namespace HiddenWallet.ChaumianTumbler.Configuration
string jsonString = await File.ReadAllTextAsync(path, Encoding.UTF8, cancel);
var config = JsonConvert.DeserializeObject<Config>(jsonString);
+ Network = config.Network ?? Network;
DenominationAlgorithm = config.DenominationAlgorithm ?? DenominationAlgorithm;
DenominationUSD = config.DenominationUSD ?? DenominationUSD;
DenominationBTC = config.DenominationBTC ?? DenominationBTC;

MODIFY
HiddenWallet.ChaumianTumbler/Controllers/TumblerController.cs
HiddenWallet.ChaumianTumbler/Controllers/TumblerController.cs
@@ -7,6 +7,7 @@ using HiddenWallet.SharedApi.Models;
using HiddenWallet.ChaumianTumbler.Models;
using HiddenWallet.ChaumianCoinJoin;
using Org.BouncyCastle.Utilities.Encoders;
+using NBitcoin;
namespace HiddenWallet.ChaumianTumbler.Controllers
{
@@ -67,6 +68,19 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
{
try
{
+ if (request.BlindedOutput == null) return new BadRequestResult();
+ if (request.ChangeOutput == null) return new BadRequestResult();
+ if (request.Inputs == null || request.Inputs.Count() == 0) return new BadRequestResult();
+ byte[] blindedOutut = HexHelpers.GetBytes(request.BlindedOutput);
+ var changeOutput = new BitcoinWitPubKeyAddress(request.ChangeOutput, expectedNetwork: Global.Config.Network);
+ var inputs = new HashSet<OutPoint>();
+ foreach (var input in request.Inputs)
+ {
+ OutPoint op = new OutPoint();
+ op.FromHex(input.Input);
+ inputs.Add(op);
+ }
+
// Check format (parse everyting))
// Check if inputs are native segwit
// Check if proofs are valid
@@ -102,6 +116,8 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
{
try
{
+ if (request.UniqueId == null) return new BadRequestResult();
+
throw new NotImplementedException();
}
catch (Exception ex)
@@ -116,6 +132,8 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
{
try
{
+ if (request.SignedOutput == null) return new BadRequestResult();
+
throw new NotImplementedException();
}
catch (Exception ex)
@@ -144,6 +162,7 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
{
try
{
+ if (request.Signature == null) return new BadRequestResult();
throw new NotImplementedException();
}
catch (Exception ex)

MODIFY
HiddenWallet.ChaumianTumbler/Models/InputsRequest.cs
HiddenWallet.ChaumianTumbler/Models/InputsRequest.cs
@@ -8,7 +8,6 @@ namespace HiddenWallet.ChaumianTumbler.Models
public class InputsRequest
{
public InputProofModel[] Inputs { get; set; }
- //
public string BlindedOutput { get; set; }
public string ChangeOutput { get; set; }
}

MODIFY
HiddenWallet/Extensions/NBitcoinExtensions.cs
HiddenWallet/Extensions/NBitcoinExtensions.cs
@@ -9,5 +9,16 @@ namespace NBitcoin
{
public static ChainedBlock GetBlock(this ConcurrentChain me, Height height)
=> me.GetBlock(height.Value);
+
+ public static string ToHex(this IBitcoinSerializable me)
+ {
+ return HexHelpers.ToString(me.ToBytes());
+ }
+
+ public static void FromHex(this IBitcoinSerializable me, string hex)
+ {
+ if (me == null) throw new ArgumentNullException(nameof(me));
+ me.FromBytes(HexHelpers.GetBytes(hex));
+ }
}
}

Add basic checks