Remove `delegate` from CredentialIssuer
MODIFY
WalletWasabi/WabiSabi/Backend/PostRequests/InputRegistrationHandler.cs
WalletWasabi/WabiSabi/Backend/PostRequests/InputRegistrationHandler.cs
@@ -136,7 +136,9 @@ namespace WalletWasabi.WabiSabi.Backend.PostRequests
alice.SetDeadlineRelativeTo(round.ConnectionConfirmationTimeout);
round.Alices.Add(alice);
- return new(alice.Id, commitAmountCredentialResponse(), commitWeightCredentialResponse());
+ return new(alice.Id,
+ commitAmountCredentialResponse.Commit(),
+ commitWeightCredentialResponse.Commit());
}
private static void RemoveDuplicateAlices(IDictionary<Guid, Round> rounds, Alice alice)

MODIFY
WalletWasabi/WabiSabi/Backend/Rounds/Arena.cs
WalletWasabi/WabiSabi/Backend/Rounds/Arena.cs
@@ -331,8 +331,8 @@ namespace WalletWasabi.WabiSabi.Backend.Rounds
{
alice.SetDeadlineRelativeTo(round.ConnectionConfirmationTimeout);
return new(
- commitAmountZeroCredentialResponse(),
- commitWeightZeroCredentialResponse());
+ commitAmountZeroCredentialResponse.Commit(),
+ commitWeightZeroCredentialResponse.Commit());
}
else if (round.Phase == Phase.ConnectionConfirmation)
{
@@ -341,10 +341,10 @@ namespace WalletWasabi.WabiSabi.Backend.Rounds
alice.ConfirmedConnetion = true;
return new(
- commitAmountZeroCredentialResponse(),
- commitWeightZeroCredentialResponse(),
- commitAmountRealCredentialResponse(),
- commitWeightRealCredentialResponse());
+ commitAmountZeroCredentialResponse.Commit(),
+ commitWeightZeroCredentialResponse.Commit(),
+ commitAmountRealCredentialResponse.Commit(),
+ commitWeightRealCredentialResponse.Commit());
}
else
{
@@ -403,8 +403,8 @@ namespace WalletWasabi.WabiSabi.Backend.Rounds
round.Bobs.Add(bob);
return new(
- commitAmountCredentialResponse(),
- commitWeightCredentialResponse());
+ commitAmountCredentialResponse.Commit(),
+ commitWeightCredentialResponse.Commit());
}
}

MODIFY
WalletWasabi/WabiSabi/Crypto/CredentialIssuer.cs
WalletWasabi/WabiSabi/Crypto/CredentialIssuer.cs
@@ -63,8 +63,6 @@ namespace WalletWasabi.WabiSabi.Crypto
RandomNumberGenerator = Guard.NotNull(nameof(randomNumberGenerator), randomNumberGenerator);
}
- public delegate CredentialsResponse CommitResponse();
-
public ulong MaxAmount { get; }
public int RangeProofWidth { get; }
@@ -96,16 +94,16 @@ namespace WalletWasabi.WabiSabi.Crypto
/// <returns>The <see cref="CredentialsResponse">registration response</see> containing the issued credentials and the proofs.</returns>
/// <exception cref="WabiSabiCryptoException">Error code: <see cref="WabiSabiCryptoErrorCode">WabiSabiErrorCode</see></exception>
public CredentialsResponse HandleRequest(CredentialsRequest registrationRequest)
- => PrepareResponse(registrationRequest)();
+ => PrepareResponse(registrationRequest).Commit();
/// <summary>
/// Validate the <see cref="CredentialsRequest">credentials registration requests</see> and
/// prepare to mark the serial numbers as used and issue the credentials.
/// </summary>
/// <param name="registrationRequest">The request containing the credentials presentations, credential requests and the proofs.</param>
- /// <returns>The <see cref="CommitResponse">delegate</see> which returns the <see cref="CredentialsResponse">response</see> with the issued credentials and the proofs.</returns>
+ /// <returns>The <see cref="ICommitableCredentialsResponse">The response ready to be committed to</see> which returns the <see cref="ICommitableCredentialsResponse">response</see> with the issued credentials and the proofs.</returns>
/// <exception cref="WabiSabiCryptoException">Error code: <see cref="WabiSabiCryptoErrorCode">WabiSabiErrorCode</see></exception>
- public CommitResponse PrepareResponse(CredentialsRequest registrationRequest)
+ public ICommitableCredentialsResponse PrepareResponse(CredentialsRequest registrationRequest)
{
Guard.NotNull(nameof(registrationRequest), registrationRequest);
@@ -212,17 +210,46 @@ namespace WalletWasabi.WabiSabi.Crypto
var macs = credentials.Select(x => x.Mac);
var response = new CredentialsResponse(macs, proofs);
- return () =>
+ var serialNumbers = presented.Select(x => x.S);
+ return new PreparedCredentialsResponse(this, response, registrationRequest.Delta, serialNumbers);
+ }
+
+ private CredentialsResponse Commit(CredentialsResponse response, long delta, IEnumerable<GroupElement> serialNumbers)
{
// Register the serial numbers to prevent credential reuse.
- foreach (var presentation in presented)
+ foreach (var serialNumber in serialNumbers)
{
- SerialNumbers.Add(presentation.S);
+ SerialNumbers.Add(serialNumber);
}
- Balance += registrationRequest.Delta;
+ Balance += delta;
return response;
- };
+ }
+
+ public interface ICommitableCredentialsResponse
+ {
+ CredentialsResponse Commit();
+ }
+
+ private class PreparedCredentialsResponse : ICommitableCredentialsResponse
+ {
+ private readonly CredentialIssuer _issuer;
+ private readonly CredentialsResponse _response;
+ private readonly long _delta;
+ private readonly IEnumerable<GroupElement> _serialNumbers;
+
+ public PreparedCredentialsResponse(CredentialIssuer issuer, CredentialsResponse response, long delta, IEnumerable<GroupElement> serialNumbers)
+ {
+ _issuer = issuer;
+ _response = response;
+ _delta = delta;
+ _serialNumbers = serialNumbers;
+ }
+
+ public CredentialsResponse Commit()
+ {
+ return _issuer.Commit(_response, _delta, _serialNumbers);
+ }
}
private (MAC Mac, Knowledge Knowledge) IssueCredential(GroupElement ma, Scalar t)

Remove `delegate` from CredentialIssuer