/// <inheritdoc/> public async Task <(DidExchangeResponseMessage, ConnectionRecord)> CreateResponseAsync(IAgentContext agentContext, ConnectionRecord connectionRecord) { await connectionRecord.TriggerAsync(ConnectionTrigger.Response); var myDid = await Did.CreateAndStoreMyDidAsync(agentContext.Wallet, "{}"); connectionRecord.MyDid = DidUtils.ConvertVerkeyToDidKey(myDid.VerKey); connectionRecord.MyVk = myDid.VerKey; var provisioningRecord = await _provisioningService.GetProvisioningAsync(agentContext.Wallet); var didDoc = new AttachmentContent { Base64 = connectionRecord.MyDidDoc(provisioningRecord).ToJson().ToBase64Url() }; await didDoc.SignWithJsonWebSignature(agentContext.Wallet, myDid.VerKey); var attachment = new Attachment { Id = Guid.NewGuid().ToString(), MimeType = "application/json", Data = didDoc }; var response = new DidExchangeResponseMessage { Id = Guid.NewGuid().ToString(), Did = connectionRecord.MyDid, DidDoc = attachment }; await _recordService.UpdateAsync(agentContext.Wallet, connectionRecord); return(response, connectionRecord); }
/// <inheritdoc/> public async Task <ConnectionRecord> ProcessResponseAsync(IAgentContext agentContext, DidExchangeResponseMessage responseMessage, ConnectionRecord connectionRecord) { await connectionRecord.TriggerAsync(ConnectionTrigger.Response); DidDoc didDoc = null; if (responseMessage.DidDoc.Data.Base64 is { } data) { var isValidSignature = await responseMessage.DidDoc.Data.VerifyJsonWebSignature(); if (isValidSignature == false) { throw new AriesFrameworkException(ErrorCode.InvalidSignatureEncoding, "The given JSON web signature is invalid"); } var json = data.FromBase64Url(); didDoc = json.ToObject <DidDoc>(); } if (didDoc == null) { throw new NotImplementedException("Response message must provide an attached did document"); } if (didDoc.Keys.All(key => key.Type == DidDocExtensions.DefaultKeyType) == false) { throw new NotImplementedException($"Only {DidDocExtensions.DefaultKeyType} is supported"); } var indyService = (IndyAgentDidDocService)didDoc.Services.First(service => service is IndyAgentDidDocService); var agentEndpoint = new AgentEndpoint(indyService.ServiceEndpoint, null, indyService.RoutingKeys.ToArray()); connectionRecord.TheirDid = responseMessage.Did; connectionRecord.TheirVk = didDoc.Keys.FirstOrDefault(key => key.Controller == responseMessage.Did)?.PublicKeyBase58 ?? throw new NullReferenceException("Missing public key for controller"); connectionRecord.Endpoint = agentEndpoint; await _recordService.UpdateAsync(agentContext.Wallet, connectionRecord); _eventAggregator.Publish(new ServiceMessageProcessingEvent() { MessageType = responseMessage.Type, RecordId = connectionRecord.Id, ThreadId = responseMessage.GetThreadId() }); return(connectionRecord); }