public async Task SendProofRequestThrowsConnectionNotFound() { var ex = await Assert.ThrowsAsync <AgentFrameworkException>(async() => await _proofService.CreateProofRequestAsync(_issuerWallet, new ProofRequest { Name = "Test", Nonce = await AnonCreds.GenerateNonceAsync() }, "bad-proof-id")); Assert.True(ex.ErrorCode == ErrorCode.RecordNotFound); }
public static async Task <(ProofRecord holderProofRecord, ProofRecord RequestorProofRecord)> ProofProtocolAsync( IProofService proofService, IProducerConsumerCollection <AgentMessage> messages, ConnectionRecord holderConnection, ConnectionRecord requestorConnection, IAgentContext holderContext, IAgentContext requestorContext, ProofRequest proofRequestObject) { //Requestor sends a proof request var(message, requestorProofRecord) = await proofService.CreateProofRequestAsync(requestorContext, proofRequestObject, requestorConnection.Id); messages.TryAdd(message); // Holder accepts the proof requests and builds a proof var proofRequest = FindContentMessage <ProofRequestMessage>(messages); Assert.NotNull(proofRequest); //Holder stores the proof request var holderProofRequestId = await proofService.ProcessProofRequestAsync(holderContext, proofRequest, holderConnection); var holderProofRecord = await proofService.GetAsync(holderContext, holderProofRequestId); var holderProofRequest = JsonConvert.DeserializeObject <ProofRequest>(holderProofRecord.RequestJson); // Auto satify the proof with which ever credentials in the wallet are capable var requestedCredentials = await ProofServiceUtils.GetAutoRequestedCredentialsForProofCredentials(holderContext, proofService, holderProofRequest); //Holder accepts the proof request and sends a proof (var proofMessage, _) = await proofService.CreateProofAsync(holderContext, holderProofRequestId, requestedCredentials); messages.TryAdd(proofMessage); //Requestor retrives proof message from their cloud agent var proof = FindContentMessage <ProofMessage>(messages); Assert.NotNull(proof); //Requestor stores proof var requestorProofId = await proofService.ProcessProofAsync(requestorContext, proof); //Requestor verifies proof var requestorVerifyResult = await proofService.VerifyProofAsync(requestorContext, requestorProofId); ////Verify the proof is valid Assert.True(requestorVerifyResult); var requestorProofRecordResult = await proofService.GetAsync(requestorContext, requestorProofRecord.Id); var holderProofRecordResult = await proofService.GetAsync(holderContext, holderProofRecord.Id); return(holderProofRecordResult, requestorProofRecordResult); }
/// <inheritdoc /> public virtual async Task <(EphemeralChallengeMessage, EphemeralChallengeRecord)> CreateChallengeAsync(IAgentContext agentContext, string challengeConfigId) { var config = await GetChallengeConfigAsync(agentContext, challengeConfigId); EphemeralChallengeRecord challengeRecord = new EphemeralChallengeRecord { Id = Guid.NewGuid().ToString() }; EphemeralChallengeMessage challengeMessage = new EphemeralChallengeMessage(); var provisioning = await ProvisioningService.GetProvisioningAsync(agentContext.Wallet); challengeMessage.ChallengerName = provisioning.Owner?.Name; challengeMessage.ChallengerImageUrl = provisioning.Owner?.ImageUrl; challengeMessage.ServiceEndpoint = provisioning.Endpoint.Uri; challengeMessage.RecipientKeys = new[] { provisioning.Endpoint.Verkey }; if (config.Type == ChallengeType.Proof) { var proofRequestConfig = config.Contents.ToObject <ProofRequestConfiguration>(); (var proofRequest, var _) = await ProofService.CreateProofRequestAsync(agentContext, new ProofRequest { Name = config.Name, Version = "1.0", Nonce = $"0{Guid.NewGuid().ToString("N")}", RequestedAttributes = proofRequestConfig.RequestedAttributes, RequestedPredicates = proofRequestConfig.RequestedPredicates, NonRevoked = proofRequestConfig.NonRevoked }); challengeRecord.Challenge = new EphemeralChallengeContents { Type = ChallengeType.Proof, Contents = JsonConvert.DeserializeObject <JObject>(proofRequest.ProofRequestJson) }; challengeMessage.Challenge = challengeRecord.Challenge; } challengeRecord.SetTag(TagConstants.Role, TagConstants.Requestor); challengeRecord.SetTag(TagConstants.LastThreadId, challengeMessage.Id); await RecordService.AddAsync(agentContext.Wallet, challengeRecord); return(challengeMessage, challengeRecord); }
public async Task CreateProofRequestConnectionNotFound() { var ex = await Assert.ThrowsAsync <AgentFrameworkException>(async() => await _proofService.CreateProofRequestAsync(_issuerWallet, "bad-connection-id", new ProofRequest { Name = "Test", Nonce = "1234" })); Assert.True(ex.ErrorCode == ErrorCode.RecordNotFound); }