public async Task CanEstablishConnectionsWithMultiPartyInvitationAsync() { var invite = await _connectionService.CreateInvitationAsync(_issuerWallet, new InviteConfiguration { MultiPartyInvitation = true }); var(connectionIssuer, connectionHolderOne) = await Scenarios.EstablishConnectionAsync( _connectionService, _messages, _issuerWallet, _holderWallet, invite, invite.Connection.Id); var(connectionIssuerTwo, connectionHolderTwo) = await Scenarios.EstablishConnectionAsync( _connectionService, _messages, _issuerWallet, _holderWalletTwo, invite, invite.Connection.Id); Assert.Equal(ConnectionState.Connected, connectionIssuer.State); Assert.Equal(ConnectionState.Connected, connectionHolderOne.State); Assert.Equal(ConnectionState.Connected, connectionIssuerTwo.State); Assert.Equal(ConnectionState.Connected, connectionHolderTwo.State); Assert.Equal(connectionIssuer.MyDid, connectionHolderOne.TheirDid); Assert.Equal(connectionIssuer.TheirDid, connectionHolderOne.MyDid); Assert.Equal(connectionIssuerTwo.MyDid, connectionHolderTwo.TheirDid); Assert.Equal(connectionIssuerTwo.TheirDid, connectionHolderTwo.MyDid); Assert.Equal(connectionIssuer.Endpoint.Uri, MockEndpointUri); Assert.Equal(connectionIssuerTwo.Endpoint.Uri, MockEndpointUri); }
public async Task CanIssueCredential() { int events = 0; _eventAggregator.GetEventByType <ServiceMessageProcessingEvent>() .Where(_ => (_.MessageType == MessageTypes.CredentialOffer || _.MessageType == MessageTypes.CredentialRequest || _.MessageType == MessageTypes.Credential)) .Subscribe(_ => { events++; }); // Setup secure connection between issuer and holder var(issuerConnection, holderConnection) = await Scenarios.EstablishConnectionAsync( _connectionService, _messages, _issuerWallet, _holderWallet); var(issuerCredential, holderCredential) = await Scenarios.IssueCredentialAsync( _schemaService, _credentialService, _messages, issuerConnection, holderConnection, _issuerWallet, _holderWallet, _pool, MasterSecretId, false); Assert.True(events == 3); Assert.Equal(issuerCredential.State, holderCredential.State); Assert.Equal(CredentialState.Issued, issuerCredential.State); }
public async Task CanEstablishConnectionAsync() { int events = 0; _eventAggregator.GetEventByType <ServiceMessageProcessingEvent>() .Where(_ => (_.MessageType == MessageTypes.ConnectionRequest || _.MessageType == MessageTypes.ConnectionResponse)) .Subscribe(_ => { events++; }); var(connectionIssuer, connectionHolder) = await Scenarios.EstablishConnectionAsync( _connectionService, _messages, _issuerWallet, _holderWallet); Assert.True(events == 2); Assert.Equal(ConnectionState.Connected, connectionIssuer.State); Assert.Equal(ConnectionState.Connected, connectionHolder.State); Assert.Equal(connectionIssuer.MyDid, connectionHolder.TheirDid); Assert.Equal(connectionIssuer.TheirDid, connectionHolder.MyDid); Assert.Equal(connectionIssuer.Endpoint.Uri, MockEndpointUri); Assert.Equal(connectionIssuer.Endpoint.Uri, MockEndpointUri); }
public async Task IssueCredentialThrowsExceptionUnableToSendA2AMessage() { //Establish a connection between the two parties var(issuerConnection, holderConnection) = await Scenarios.EstablishConnectionAsync( _connectionService, _messages, _issuerWallet, _holderWallet); // Create an issuer DID/VK. Can also be created during provisioning var issuer = await Did.CreateAndStoreMyDidAsync(_issuerWallet.Wallet, new { seed = "000000000000000000000000Steward1" }.ToJson()); // Creata a schema and credential definition for this issuer (var definitionId, _) = await Scenarios.CreateDummySchemaAndNonRevokableCredDef(_issuerWallet, _schemaService, issuer.Did, new[] { "dummy_attr" }); var offerConfig = new OfferConfiguration() { IssuerDid = issuer.Did, CredentialDefinitionId = definitionId }; // Send an offer to the holder using the established connection channel await _credentialService.SendOfferAsync(_issuerWallet, issuerConnection.Id, offerConfig); // Holder retrives message from their cloud agent var credentialOffer = FindContentMessage <CredentialOfferMessage>(_messages); // Holder processes the credential offer by storing it var holderCredentialId = await _credentialService.ProcessOfferAsync(_holderWallet, credentialOffer, holderConnection); // Holder creates master secret. Will also be created during wallet agent provisioning await AnonCreds.ProverCreateMasterSecretAsync(_holderWallet.Wallet, MasterSecretId); // Holder accepts the credential offer and sends a credential request await _credentialService.AcceptOfferAsync(_holderWallet, holderCredentialId, new Dictionary <string, string> { { "dummy_attr", "dummyVal" } }); // Issuer retrieves credential request from cloud agent var credentialRequest = FindContentMessage <CredentialRequestMessage>(_messages); Assert.NotNull(credentialRequest); // Issuer processes the credential request by storing it var issuerCredentialId = await _credentialService.ProcessCredentialRequestAsync(_issuerWallet, credentialRequest, issuerConnection); //Try issue the credential with a credential service that has a bad routing service _routeMessage = false; var ex = await Assert.ThrowsAsync <AgentFrameworkException>(async() => await _credentialService.IssueCredentialAsync(_issuerWallet, issuer.Did, issuerCredentialId)); Assert.True(ex.ErrorCode == ErrorCode.A2AMessageTransmissionError); _routeMessage = true; }
public async Task ProcessCredentialRequestThrowsCredentialNotFound() { var(issuerConnection, _) = await Scenarios.EstablishConnectionAsync( _connectionService, _messages, _issuerWallet, _holderWallet); var ex = await Assert.ThrowsAsync <AgentFrameworkException>(async() => await _credentialService.ProcessCredentialRequestAsync(_issuerWallet, new CredentialRequestMessage { OfferJson = "{ \"nonce\":\"bad-nonce\" }" }, issuerConnection)); Assert.True(ex.ErrorCode == ErrorCode.RecordNotFound); }
public async Task RejectProofRequestCredentialInvalidState() { //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, _pool, MasterSecretId, true); _messages.Clear(); //Requestor initialize a connection with the holder var(_, requestorConnection) = await Scenarios.EstablishConnectionAsync( _connectionService, _messages, _holderWallet, _requestorWallet); // Verifier sends a proof request to prover { var proofRequestObject = new ProofRequest { Name = "ProofReq", Version = "1.0", Nonce = "123", RequestedAttributes = new Dictionary <string, ProofAttributeInfo> { { "first-name-requirement", new ProofAttributeInfo { Name = "first_name" } } } }; //Requestor sends a proof request await _proofService.SendProofRequestAsync(_requestorWallet, requestorConnection.Id, proofRequestObject); } //Holder retrives proof request message from their cloud agent var proofRequest = FindContentMessage <ProofRequestMessage>(); Assert.NotNull(proofRequest); _holderWallet.Connection = holderConnection; //Holder stores the proof request var holderProofRequestId = await _proofService.ProcessProofRequestAsync(_holderWallet, proofRequest); //Holder accepts the proof request and sends a proof await _proofService.RejectProofRequestAsync(_holderWallet, holderProofRequestId); var ex = await Assert.ThrowsAsync <AgentFrameworkException>(async() => await _proofService.RejectProofRequestAsync(_holderWallet, holderProofRequestId)); Assert.True(ex.ErrorCode == ErrorCode.RecordInInvalidState); }
public async Task ProcessProofRecordNotFound() { var(issuerConnection, _) = await Scenarios.EstablishConnectionAsync( _connectionService, _messages, _issuerWallet, _holderWallet); _issuerWallet.Connection = issuerConnection; var ex = await Assert.ThrowsAsync <AgentFrameworkException>(async() => await _proofService.ProcessProofAsync(_issuerWallet, new ProofMessage { RequestNonce = "123" })); Assert.True(ex.ErrorCode == ErrorCode.RecordNotFound); }
public async Task SendOfferAsyncThrowsExceptionUnableToSendA2AMessage() { var(issuerConnection, _) = await Scenarios.EstablishConnectionAsync( _connectionService, _messages, _issuerWallet, _holderWallet); var issuer = await Did.CreateAndStoreMyDidAsync(_issuerWallet.Wallet, new { seed = "000000000000000000000000Steward1" }.ToJson()); (var credId, _) = await Scenarios.CreateDummySchemaAndNonRevokableCredDef(_issuerWallet, _schemaService, issuer.Did, new[] { "dummy_attr" }); _routeMessage = false; var ex = await Assert.ThrowsAsync <AgentFrameworkException>(async() => await _credentialService.SendOfferAsync(_issuerWallet, issuerConnection.Id, new OfferConfiguration { CredentialDefinitionId = credId })); _routeMessage = true; Assert.True(ex.ErrorCode == ErrorCode.A2AMessageTransmissionError); }
public async Task SendProofRequestThrowsA2AMessageTransmissionFailure() { //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, _pool, MasterSecretId, true); _messages.Clear(); //Requestor initialize a connection with the holder var(_, requestorConnection) = await Scenarios.EstablishConnectionAsync( _connectionService, _messages, _holderWallet, _requestorWallet); // Verifier sends a proof request to prover { var proofRequestObject = new ProofRequest { Name = "ProofReq", Version = "1.0", Nonce = "123", RequestedAttributes = new Dictionary <string, ProofAttributeInfo> { { "first-name-requirement", new ProofAttributeInfo { Name = "first_name" } } } }; //Requestor sends a proof request _routeMessage = false; var ex = await Assert.ThrowsAsync <AgentFrameworkException>(async() => await _proofService.SendProofRequestAsync(_requestorWallet, requestorConnection.Id, proofRequestObject)); _routeMessage = true; Assert.True(ex.ErrorCode == ErrorCode.A2AMessageTransmissionError); } }
public async Task RejectOfferAsyncThrowsExeceptionCredentialOfferInvalidState() { //Establish a connection between the two parties var(issuerConnection, holderConnection) = await Scenarios.EstablishConnectionAsync( _connectionService, _messages, _issuerWallet, _holderWallet); // Create an issuer DID/VK. Can also be created during provisioning var issuer = await Did.CreateAndStoreMyDidAsync(_issuerWallet.Wallet, new { seed = "000000000000000000000000Steward1" }.ToJson()); // Creata a schema and credential definition for this issuer (var definitionId, _) = await Scenarios.CreateDummySchemaAndNonRevokableCredDef(_issuerWallet, _schemaService, issuer.Did, new[] { "dummy_attr" }); var offerConfig = new OfferConfiguration() { IssuerDid = issuer.Did, CredentialDefinitionId = definitionId }; // Send an offer to the holder using the established connection channel await _credentialService.SendOfferAsync(_issuerWallet, issuerConnection.Id, offerConfig); // Holder retrives message from their cloud agent var credentialOffer = FindContentMessage <CredentialOfferMessage>(_messages); // Holder processes the credential offer by storing it var holderCredentialId = await _credentialService.ProcessOfferAsync(_holderWallet, credentialOffer, holderConnection); //Reject the offer await _credentialService.RejectOfferAsync(_holderWallet, holderCredentialId); //Try reject the offer again var ex = await Assert.ThrowsAsync <AgentFrameworkException>(async() => await _credentialService.RejectOfferAsync(_holderWallet, holderCredentialId)); Assert.True(ex.ErrorCode == ErrorCode.RecordInInvalidState); }
public async Task AcceptProofRequestCredentialInvalidState() { //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, _pool, MasterSecretId, true); _messages.Clear(); //Requestor initialize a connection with the holder var(_, requestorConnection) = await Scenarios.EstablishConnectionAsync( _connectionService, _messages, _holderWallet, _requestorWallet); // Verifier sends a proof request to prover { var proofRequestObject = new ProofRequest { Name = "ProofReq", Version = "1.0", Nonce = "123", RequestedAttributes = new Dictionary <string, ProofAttributeInfo> { { "first-name-requirement", new ProofAttributeInfo { Name = "first_name" } } } }; //Requestor sends a proof request await _proofService.SendProofRequestAsync(_requestorWallet, requestorConnection.Id, proofRequestObject); } // Holder accepts the proof requests and builds a proof //Holder retrives proof request message from their cloud agent var proofRequest = FindContentMessage <ProofRequestMessage>(); Assert.NotNull(proofRequest); _holderWallet.Connection = holderConnection; //Holder stores the proof request var holderProofRequestId = await _proofService.ProcessProofRequestAsync(_holderWallet, proofRequest); var holderProofRecord = await _proofService.GetAsync(_holderWallet, holderProofRequestId); var holderProofObject = JsonConvert.DeserializeObject <ProofRequest>(holderProofRecord.RequestJson); var requestedCredentials = new RequestedCredentials(); foreach (var requestedAttribute in holderProofObject.RequestedAttributes) { var credentials = await _proofService.ListCredentialsForProofRequestAsync(_holderWallet, holderProofObject, requestedAttribute.Key); requestedCredentials.RequestedAttributes.Add(requestedAttribute.Key, new RequestedAttribute { CredentialId = credentials.First().CredentialInfo.Referent, Revealed = true, Timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds() }); } foreach (var requestedAttribute in holderProofObject.RequestedPredicates) { var credentials = await _proofService.ListCredentialsForProofRequestAsync(_holderWallet, holderProofObject, requestedAttribute.Key); requestedCredentials.RequestedPredicates.Add(requestedAttribute.Key, new RequestedAttribute { CredentialId = credentials.First().CredentialInfo.Referent, Revealed = true }); } //Holder accepts the proof request and sends a proof await _proofService.AcceptProofRequestAsync(_holderWallet, holderProofRequestId, requestedCredentials); var ex = await Assert.ThrowsAsync <AgentFrameworkException>(async() => await _proofService.AcceptProofRequestAsync(_holderWallet, holderProofRequestId, requestedCredentials)); Assert.True(ex.ErrorCode == ErrorCode.RecordInInvalidState); }
public async Task CredentialProofDemo() { int events = 0; _eventAggregator.GetEventByType <ServiceMessageProcessingEvent>() .Where(_ => (_.MessageType == MessageTypes.ProofRequest || _.MessageType == MessageTypes.DisclosedProof)) .Subscribe(_ => { events++; }); //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, _pool, MasterSecretId, true); _messages.Clear(); //Requestor initialize a connection with the holder var(_, requestorConnection) = await Scenarios.EstablishConnectionAsync( _connectionService, _messages, _holderWallet, _requestorWallet); // Verifier sends a proof request to prover { var proofRequestObject = new ProofRequest { Name = "ProofReq", Version = "1.0", Nonce = "123", RequestedAttributes = new Dictionary <string, ProofAttributeInfo> { { "first-name-requirement", new ProofAttributeInfo { Name = "first_name" } } } }; //Requestor sends a proof request await _proofService.SendProofRequestAsync(_requestorWallet, requestorConnection.Id, proofRequestObject); } // Holder accepts the proof requests and builds a proof { //Holder retrives proof request message from their cloud agent var proofRequest = FindContentMessage <ProofRequestMessage>(); Assert.NotNull(proofRequest); _holderWallet.Connection = holderConnection; //Holder stores the proof request var holderProofRequestId = await _proofService.ProcessProofRequestAsync(_holderWallet, proofRequest); var holderProofRecord = await _proofService.GetAsync(_holderWallet, holderProofRequestId); var holderProofObject = JsonConvert.DeserializeObject <ProofRequest>(holderProofRecord.RequestJson); var requestedCredentials = new RequestedCredentials(); foreach (var requestedAttribute in holderProofObject.RequestedAttributes) { var credentials = await _proofService.ListCredentialsForProofRequestAsync(_holderWallet, holderProofObject, requestedAttribute.Key); requestedCredentials.RequestedAttributes.Add(requestedAttribute.Key, new RequestedAttribute { CredentialId = credentials.First().CredentialInfo.Referent, Revealed = true, Timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds() }); } foreach (var requestedAttribute in holderProofObject.RequestedPredicates) { var credentials = await _proofService.ListCredentialsForProofRequestAsync(_holderWallet, holderProofObject, requestedAttribute.Key); requestedCredentials.RequestedPredicates.Add(requestedAttribute.Key, new RequestedAttribute { CredentialId = credentials.First().CredentialInfo.Referent, Revealed = true }); } //Holder accepts the proof request and sends a proof var proofMessage = await _proofService.AcceptProofRequestAsync(_holderWallet, holderProofRequestId, requestedCredentials); _messages.Add(proofMessage); } //Requestor retrives proof message from their cloud agent var proof = FindContentMessage <ProofMessage>(); Assert.NotNull(proof); _requestorWallet.Connection = requestorConnection; //Requestor stores proof var requestorProofId = await _proofService.ProcessProofAsync(_requestorWallet, proof); //Requestor verifies proof var requestorVerifyResult = await _proofService.VerifyProofAsync(_requestorWallet, requestorProofId); ////Verify the proof is valid Assert.True(requestorVerifyResult); Assert.True(events == 2); ////Get the proof from both parties wallets //var requestorProof = await _proofService.GetProof(_requestorWallet, requestorProofId); //var holderProof = await _proofService.GetProof(_holderWallet, holderProofRequestId); ////Verify that both parties have a copy of the proof //Assert.Equal(requestorProof, holderProof); }