public async Task CanCreateChallengeConfigAsync() { var config = new EphemeralChallengeConfiguration { Name = "Test", Type = ChallengeType.Proof, Contents = new ProofRequestConfiguration { RequestedAttributes = new Dictionary <string, ProofAttributeInfo> { { "", new ProofAttributeInfo { Name = "Test" } } } } }; var id = await _ephemeralChallengeService.CreateChallengeConfigAsync(_issuerWallet, config); var record = await _ephemeralChallengeService.GetChallengeConfigAsync(_issuerWallet, id); var result = record.Contents.ToObject <ProofRequestConfiguration>(); Assert.True(result.RequestedAttributes.Count == 1); Assert.True(config.Type == record.Type); Assert.True(config.Name == record.Name); }
public async Task CanCreateChallengeAsync() { var config = new EphemeralChallengeConfiguration { Name = "Test", Type = ChallengeType.Proof, Contents = new ProofRequestConfiguration { RequestedAttributes = new Dictionary <string, ProofAttributeInfo> { { "", new ProofAttributeInfo { Name = "Test" } } } } }; var id = await _ephemeralChallengeService.CreateChallengeConfigAsync(_holderWallet, config); (var challenge, var record) = await _ephemeralChallengeService.CreateChallengeAsync(_holderWallet, id); Assert.True(!string.IsNullOrEmpty(record.Id)); Assert.True(challenge != null); }
/// <inheritdoc /> public virtual async Task <string> CreateChallengeConfigAsync(IAgentContext agentContext, EphemeralChallengeConfiguration config) { EphemeralChallengeConfigRecord configRecord = new EphemeralChallengeConfigRecord { Id = Guid.NewGuid().ToString(), Name = config.Name, Type = config.Type, Contents = JObject.FromObject(config.Contents) }; await RecordService.AddAsync(agentContext.Wallet, configRecord); return(configRecord.Id); }
public async Task CanConductChallengeFlow() { //Setup a connection and issue the credentials to the holder var(issuerConnection, holderConnection) = await Scenarios.EstablishConnectionAsync( _connectionService, _messages, _issuerWallet, _holderWallet); await Scenarios.IssueCredentialAsync( _schemaService, _credentialService, _messages, issuerConnection, holderConnection, _issuerWallet, _holderWallet, await _holderWallet.Pool, TestConstants.DefaultMasterSecret, true, new List <CredentialPreviewAttribute> { new CredentialPreviewAttribute("first_name", "Test"), new CredentialPreviewAttribute("last_name", "Holder") }); _messages.Clear(); // Challenger sends a challenge { var challengeConfig = new EphemeralChallengeConfiguration { Name = "Test", Type = ChallengeType.Proof, Contents = new ProofRequestConfiguration { RequestedAttributes = new Dictionary <string, ProofAttributeInfo> { { "first-name-requirement", new ProofAttributeInfo { Name = "first_name" } } } } }; var challengeConfigId = await _ephemeralChallengeService.CreateChallengeConfigAsync(_requestorWallet, challengeConfig); (var challenge, var record) = await _ephemeralChallengeService.CreateChallengeAsync(_requestorWallet, challengeConfigId); Assert.True(!string.IsNullOrEmpty(challenge.ChallengerName)); Assert.True(challenge.RecipientKeys.Count() == 1); Assert.True(challenge.RecipientKeys.First() == TestConstants.DefaultVerkey); Assert.True(challenge.ServiceEndpoint == TestConstants.DefaultMockUri); _messages.Add(challenge); var result = await _ephemeralChallengeService.GetChallengeStateAsync(_requestorWallet, record.Id); Assert.True(result == ChallengeState.Challenged); } //Challenge responder recieves challenge { var challengeMessage = _messages.OfType <EphemeralChallengeMessage>().First(); var proofRequest = challengeMessage.Challenge.Contents.ToObject <ProofRequest>(); var requestedCredentials = new RequestedCredentials(); foreach (var requestedAttribute in proofRequest.RequestedAttributes) { var credentials = await _proofService.ListCredentialsForProofRequestAsync(_holderWallet, proofRequest, requestedAttribute.Key); requestedCredentials.RequestedAttributes.Add(requestedAttribute.Key, new RequestedAttribute { CredentialId = credentials.First().CredentialInfo.Referent, Revealed = true }); } foreach (var requestedAttribute in proofRequest.RequestedPredicates) { var credentials = await _proofService.ListCredentialsForProofRequestAsync(_holderWallet, proofRequest, requestedAttribute.Key); requestedCredentials.RequestedPredicates.Add(requestedAttribute.Key, new RequestedAttribute { CredentialId = credentials.First().CredentialInfo.Referent, Revealed = true }); } var challenge = await _ephemeralChallengeService.CreateProofChallengeResponseAsync( _holderWallet, challengeMessage, requestedCredentials); _messages.Add(challenge); } //Challenger recieves challenge response and verifies it { var challengeResponseMessage = _messages.OfType <EphemeralChallengeResponseMessage>().First(); var id = await _ephemeralChallengeService.ProcessChallengeResponseAsync(_requestorWallet, challengeResponseMessage); var result = await _ephemeralChallengeService.GetChallengeStateAsync(_requestorWallet, id); Assert.True(result == ChallengeState.Accepted); } }