First draft version for ConfirmConnectionAsync
MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Client/CoordinatorClientTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Client/CoordinatorClientTests.cs
@@ -38,8 +38,8 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Client
await using var coordinator = new PostRequestHandler(config, new Prison(), arena, mockRpc.Object);
var rnd = new InsecureRandom();
- var amountClient = new WabiSabiClient(round.AmountCredentialIssuerParameters, 2, rnd, 4300000000000ul);
- var weightClient = new WabiSabiClient(round.WeightCredentialIssuerParameters, 2, rnd, 2000ul);
+ var amountClient = new WabiSabiClient(round.AmountCredentialIssuerParameters, 2, rnd, 4_300_000_000_000ul); // TODO: remove hardcoded max value
+ var weightClient = new WabiSabiClient(round.WeightCredentialIssuerParameters, 2, rnd, 1_000ul); // TODO: remove hardcoded max value
var apiClient = new CoordinatorClient(amountClient, weightClient, coordinator);
@@ -47,6 +47,21 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Client
Assert.NotEqual(Guid.Empty, aliceId);
Assert.Empty(apiClient.WabiSabiClientAmount.Credentials.Valuable);
+
+ var reissuanceAmounts = new[] {
+ Money.Coins(.75m) - round.FeeRate.GetFee(/*Constants.P2wpkhInputVirtualSize*/ 68),
+ Money.Coins(.25m)
+ };
+
+ round.SetPhase(Phase.ConnectionConfirmation);
+ await apiClient.ConfirmConnectionAsync(
+ round.Id,
+ aliceId,
+ apiClient.WabiSabiClientAmount.Credentials.ZeroValue,
+ reissuanceAmounts);
+
+ Assert.Single(apiClient.WabiSabiClientAmount.Credentials.Valuable, x => x.Amount.ToMoney() == reissuanceAmounts.First());
+ Assert.Single(apiClient.WabiSabiClientAmount.Credentials.Valuable, x => x.Amount.ToMoney() == reissuanceAmounts.Last());
}
}
}
\ No newline at end of file

MODIFY
WalletWasabi/WabiSabi/Client/CoordinatorClient.cs
WalletWasabi/WabiSabi/Client/CoordinatorClient.cs
@@ -4,6 +4,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalletWasabi.Crypto;
+using WalletWasabi.Crypto.ZeroKnowledge;
+using WalletWasabi.Helpers;
using WalletWasabi.WabiSabi.Backend.PostRequests;
using WalletWasabi.WabiSabi.Crypto;
using WalletWasabi.WabiSabi.Models;
@@ -61,5 +63,38 @@ namespace WalletWasabi.WabiSabi.Client
return inputRegistrationResponse.AliceId;
}
+
+ public async Task ConfirmConnectionAsync(Guid roundId, Guid aliceId, IEnumerable<Credential> credentialsToPresent, IEnumerable<Money> newAmount)
+ {
+ var (realAmountCredentialRequest, realAmountCredentialResponseValidation) = WabiSabiClientAmount.CreateRequest(
+ newAmount.Select(x => x.Satoshi),
+ credentialsToPresent);
+
+ var inputsCount = 1; // ?
+ var (realWeightCredentialRequest, realWeightCredentialResponseValidation) = WabiSabiClientWeight.CreateRequest(
+ new[] { 1_000L - (inputsCount) * 4 * Constants.P2wpkhInputVirtualSize },
+ WabiSabiClientWeight.Credentials.ZeroValue.Take(2)
+ );
+
+ var (zeroAmountCredentialRequest, zeroAmountCredentialResponseValidation) = WabiSabiClientAmount.CreateRequestForZeroAmount();
+ var (zeroWeightCredentialRequest, zeroWeightCredentialResponseValidation) = WabiSabiClientWeight.CreateRequestForZeroAmount();
+
+ var confirmConnectionResponse = await RequestHandler.ConfirmConnectionAsync(
+ new ConnectionConfirmationRequest(
+ roundId,
+ aliceId,
+ zeroAmountCredentialRequest,
+ realAmountCredentialRequest,
+ zeroWeightCredentialRequest,
+ realWeightCredentialRequest));
+
+ if (confirmConnectionResponse is { RealAmountCredentials: {}, RealWeightCredentials: {} })
+ {
+ WabiSabiClientAmount.HandleResponse(confirmConnectionResponse.RealAmountCredentials, realAmountCredentialResponseValidation);
+ WabiSabiClientWeight.HandleResponse(confirmConnectionResponse.RealWeightCredentials, realWeightCredentialResponseValidation);
+ }
+ WabiSabiClientAmount.HandleResponse(confirmConnectionResponse.ZeroAmountCredentials, zeroAmountCredentialResponseValidation);
+ WabiSabiClientWeight.HandleResponse(confirmConnectionResponse.ZeroWeightCredentials, zeroWeightCredentialResponseValidation);
+ }
}
}

First draft version for ConfirmConnectionAsync