/// <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); }
public async Task SignAttachmentThrowsIfContentIsNull() { var content = new AttachmentContent(); var key = await Crypto.CreateKeyAsync(_agent.Wallet, "{}"); await Assert.ThrowsAsync <NullReferenceException>(async() => await content.SignWithJsonWebSignature(_agent.Wallet, key)); }
public async Task CanVerifySignedAttachmentContent() { var base64Content = "Hello World!".ToBase64Url(); var content = new AttachmentContent { Base64 = base64Content }; var key = await Crypto.CreateKeyAsync(_agent.Wallet, "{}"); await content.SignWithJsonWebSignature(_agent.Wallet, key); var result = await content.VerifyJsonWebSignature(); Assert.True(result); }
public async Task CanSignAttachmentContent() { var base64Content = "Hello World!".ToBase64Url(); var content = new AttachmentContent { Base64 = base64Content }; var key = await Crypto.CreateKeyAsync(_agent.Wallet, "{}"); await content.SignWithJsonWebSignature(_agent.Wallet, key); Assert.NotNull(content.JsonWebSignature); Assert.NotNull(content.JsonWebSignature.Header); Assert.NotNull(content.JsonWebSignature.Protected); Assert.NotNull(content.JsonWebSignature.Signature); }
public async Task VerifyReturnsFalseWithWrongSignature() { var base64Content = "Hello World!".ToBase64Url(); var content = new AttachmentContent { Base64 = base64Content }; var key = await Crypto.CreateKeyAsync(_agent.Wallet, "{}"); await content.SignWithJsonWebSignature(_agent.Wallet, key); content.Base64 = "Changed content".ToBase64Url(); var result = await content.VerifyJsonWebSignature(); Assert.False(result); }
/// <inheritdoc/> public async Task <(DidExchangeRequestMessage, ConnectionRecord)> CreateRequestAsync(IAgentContext agentContext, string did) { var key = await Did.KeyForDidAsync(await agentContext.Pool, agentContext.Wallet, did); var endpointResult = await _ledgerService.LookupServiceEndpointAsync(agentContext, did); var myDid = await Did.CreateAndStoreMyDidAsync(agentContext.Wallet, "{}"); var connection = new ConnectionRecord { Endpoint = new AgentEndpoint { Uri = endpointResult.Result.Endpoint }, MyDid = DidUtils.ConvertVerkeyToDidKey(myDid.VerKey), MyVk = myDid.VerKey, TheirDid = did, TheirVk = key, State = ConnectionState.Negotiating, }; await _recordService.AddAsync(agentContext.Wallet, connection); var provisioningRecord = await _provisioningService.GetProvisioningAsync(agentContext.Wallet); var didDoc = new AttachmentContent { Base64 = connection.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 request = new DidExchangeRequestMessage { Did = connection.MyDid, Label = provisioningRecord.Owner.Name, DidDoc = attachment }; return(request, connection); }