/// <summary> /// Creates a <see cref="CredentialsRequest">credential registration request messages</see> /// for requesting `k` zero-value credentials. /// </summary> /// <remarks> /// The request messages created by CreateRequestForZeroAmount are called null requests. The first /// registration request message that has to be sent to the coordinator is a null request, in this /// way the coordinator issues `k` zero-value credentials that can be used in following requests. /// </remarks> public ZeroCredentialsRequestData CreateRequestForZeroAmount() { var credentialsToRequest = new IssuanceRequest[NumberOfCredentials]; var knowledge = new Knowledge[NumberOfCredentials]; var validationData = new IssuanceValidationData[NumberOfCredentials]; for (var i = 0; i < NumberOfCredentials; i++) { var randomness = RandomNumberGenerator.GetScalar(); var ma = randomness * Generators.Gh; knowledge[i] = ProofSystem.ZeroProofKnowledge(ma, randomness); credentialsToRequest[i] = new IssuanceRequest(ma, Enumerable.Empty <GroupElement>()); validationData[i] = new IssuanceValidationData(0, randomness, ma); } var transcript = BuildTransnscript(isNullRequest: true); return(new( new ZeroCredentialsRequest( credentialsToRequest, ProofSystem.Prove(transcript, knowledge, RandomNumberGenerator)), new CredentialsResponseValidation( transcript, Enumerable.Empty <Credential>(), validationData))); }
public Task <Response <RequestStatus> > IssuancePostAsync(IssuanceRequest body, string policyId) { var status = new RequestStatus { Id = "", Status = RequestState.Completed }; return(Task.FromResult(ResponseCodes.OK(status))); }
public void IssuanceRequestSerialization() { var converters = new JsonConverter[] { new GroupElementJsonConverter() }; // Serialization round test. var issuanceRequest = new IssuanceRequest(Generators.G, Enumerable.Range(0, 5).Select(i => Generators.FromText($"G{i}"))); var serializedIssuanceRequest = JsonConvert.SerializeObject(issuanceRequest, converters); var deserializedIssuanceRequest = JsonConvert.DeserializeObject <IssuanceRequest>(serializedIssuanceRequest, converters); Assert.Equal(issuanceRequest.Ma, deserializedIssuanceRequest.Ma); Assert.Equal(issuanceRequest.BitCommitments, deserializedIssuanceRequest.BitCommitments); }
/// <summary> /// Creates a <see cref="RealCredentialsRequest">credential registration request messages</see> /// for requesting `k` non-zero-value credentials. /// </summary> /// <param name="amountsToRequest">List of amounts requested in credentials.</param> /// <param name="credentialsToPresent">List of credentials to be presented to the coordinator.</param> /// <param name="cancellationToken">The cancellation token to be used in case shut down is in progress..</param> /// <returns> /// A tuple containing the registration request message instance and the registration validation data /// to be used to validate the coordinator response message (the issued credentials). /// </returns> private RealCredentialsRequestData InternalCreateRequest( IEnumerable <long> amountsToRequest, IEnumerable <Credential> credentialsToPresent, CancellationToken cancellationToken) { // Make sure we request always the same number of credentials var credentialAmountsToRequest = amountsToRequest.ToList(); var macsToPresent = credentialsToPresent.Select(x => x.Mac); if (macsToPresent.Distinct().Count() < macsToPresent.Count()) { throw new WabiSabiCryptoException(WabiSabiCryptoErrorCode.CredentialToPresentDuplicated); } var zs = new List <Scalar>(); var knowledgeToProve = new List <Knowledge>(); var presentations = new List <CredentialPresentation>(); foreach (var credential in credentialsToPresent) { var z = RandomNumberGenerator.GetScalar(); var presentation = credential.Present(z); presentations.Add(presentation); knowledgeToProve.Add(ProofSystem.ShowCredentialKnowledge(presentation, z, credential, CredentialIssuerParameters)); zs.Add(z); } // Generate RangeProofs (or ZeroProof) for each requested credential var expectedNumberOfCredentials = credentialAmountsToRequest.Count; var credentialsToRequest = new IssuanceRequest[expectedNumberOfCredentials]; var validationData = new IssuanceValidationData[expectedNumberOfCredentials]; for (var i = 0; i < expectedNumberOfCredentials; i++) { var value = credentialAmountsToRequest[i]; var scalar = new Scalar((ulong)value); var randomness = RandomNumberGenerator.GetScalar(); var ma = ProofSystem.PedersenCommitment(scalar, randomness); var(rangeKnowledge, bitCommitments) = ProofSystem.RangeProofKnowledge(scalar, randomness, RangeProofWidth, RandomNumberGenerator); knowledgeToProve.Add(rangeKnowledge); var credentialRequest = new IssuanceRequest(ma, bitCommitments); credentialsToRequest[i] = credentialRequest; validationData[i] = new IssuanceValidationData(value, randomness, ma); } // Generate Balance Proof var sumOfZ = zs.Sum(); var cr = credentialsToPresent.Select(x => x.Randomness).Sum(); var r = validationData.Select(x => x.Randomness).Sum(); var deltaR = cr + r.Negate(); var balanceKnowledge = ProofSystem.BalanceProofKnowledge(sumOfZ, deltaR); knowledgeToProve.Add(balanceKnowledge); var transcript = BuildTransnscript(isNullRequest: false); return(new( new RealCredentialsRequest( amountsToRequest.Sum() - credentialsToPresent.Sum(x => x.Value), presentations, credentialsToRequest, ProofSystem.Prove(transcript, knowledgeToProve, RandomNumberGenerator)), new CredentialsResponseValidation( transcript, credentialsToPresent, validationData))); }