/// <inheritdoc /> public virtual async Task <(ConnectionResponseMessage, ConnectionRecord)> CreateResponseAsync(IAgentContext agentContext, string connectionId) { Logger.LogInformation(LoggingEvents.AcceptConnectionRequest, "ConnectionId {0}", connectionId); var connection = await GetAsync(agentContext, connectionId); if (connection.State != ConnectionState.Negotiating) { throw new AgentFrameworkException(ErrorCode.RecordInInvalidState, $"Connection state was invalid. Expected '{ConnectionState.Negotiating}', found '{connection.State}'"); } await Pairwise.CreateAsync(agentContext.Wallet, connection.TheirDid, connection.MyDid, connection.Endpoint.ToJson()); await connection.TriggerAsync(ConnectionTrigger.Request); await RecordService.UpdateAsync(agentContext.Wallet, connection); // Send back response message var provisioning = await ProvisioningService.GetProvisioningAsync(agentContext.Wallet); string responseEndpoint = string.Empty; var records = await CloudAgentRegistrationService.GetAllCloudAgentAsync(agentContext.Wallet); if (records.Count > 0) { var record = CloudAgentRegistrationService.getRandomCloudAgent(records); responseEndpoint = record.Endpoint.ResponseEndpoint + "/" + record.MyConsumerId; } var connectionData = new Connection { Did = connection.MyDid, DidDoc = connection.MyDidDoc(provisioning, responseEndpoint) }; var sigData = await SignatureUtils.SignData(agentContext, connectionData, connection.GetTag(TagConstants.ConnectionKey)); var threadId = connection.GetTag(TagConstants.LastThreadId); var response = new ConnectionResponseMessage { ConnectionSig = sigData }; response.ThreadFrom(threadId); return(response, connection); }
/// <inheritdoc /> public virtual async Task <(ConnectionResponseMessage, ConnectionRecord)> CreateResponseAsync(IAgentContext agentContext, string connectionId) { Logger.LogTrace(LoggingEvents.AcceptConnectionRequest, "ConnectionId {0}", connectionId); var connection = await GetAsync(agentContext, connectionId); if (connection.State != ConnectionState.Negotiating) { throw new AriesFrameworkException(ErrorCode.RecordInInvalidState, $"Connection state was invalid. Expected '{ConnectionState.Negotiating}', found '{connection.State}'"); } await connection.TriggerAsync(ConnectionTrigger.Response); await RecordService.UpdateAsync(agentContext.Wallet, connection); // Send back response message var provisioning = await ProvisioningService.GetProvisioningAsync(agentContext.Wallet); var connectionData = new Common.Connection { Did = connection.MyDid, DidDoc = connection.MyDidDoc(provisioning) }; var sigData = await SignatureUtils.SignDataAsync(agentContext, connectionData, connection.GetTag(TagConstants.ConnectionKey)); var threadId = connection.GetTag(TagConstants.LastThreadId); var response = new ConnectionResponseMessage(agentContext.UseMessageTypesHttps) { ConnectionSig = sigData }; response.ThreadFrom(threadId); return(response, connection); }