Skip to content

Commit

Permalink
Propose presentation (#101)
Browse files Browse the repository at this point in the history
Merged PR Propose presentation #101
Signed-off-by: Michael Boyd <[email protected]>
  • Loading branch information
michaeldboyd authored Jun 19, 2020
1 parent 3b50030 commit 44a0800
Show file tree
Hide file tree
Showing 19 changed files with 951 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bld/
[Bb]in/
[Oo]bj/
[Ll]og/

*.blob
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>1.2.11</Version>
<Version>1.2.12</Version>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<Company>Hyperledger</Company>
<Authors>Hyperledger Aries Dotnet Maintainers</Authors>
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,30 @@ docker-compose up
This will create an agent network with a pool of 4 indy nodes and 2 agents able to communicate with each other in the network.
Navigate to [http://localhost:7000](http://localhost:7000) and [http://localhost:8000](http://localhost:8000) to create and accept connection invitations between the different agents.


## Testing

To run the unit tests, the following dependencies also must be installed:
- Docker

### Install libindy library
Follow the build instructions for your OS on the [Hyperledger Indy SDK](https://github.com/hyperledger/indy-sdk) Readme.

For macOS, if you get a `'indy' DLL not found exception`, move the built `libindy.dylib` file to the `test/Hyperledger.Aries.Tests/bin/Debug/netcoreapp3.1/` directory to explicitly add it to the path.


### Run an indy node pool
```
docker build -f docker/indy-pool.dockerfile -t indy_pool docker/
docker run -itd -p 9701-9709:9701-9709 indy_pool
```

### Run the tests
First, edit the keyword in the `scripts/tester.sh` file to select the tests you want to run. Then, run the script
```
scripts/tester.sh
```

## License

[Apache License Version 2.0](https://github.com/hyperledger/aries-cloudagent-python/blob/master/LICENSE)
8 changes: 8 additions & 0 deletions scripts/tester.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/sh

# Will run any tests that have the Keyword in their name.
# Example: DisplayName~Aries will run all Tests
# Example: DisplayName~ProofTests will only run ProofTests

(cd test/Hyperledger.Aries.Tests && \
dotnet test --nologo --filter DisplayName~Aries --verbosity normal)
58 changes: 51 additions & 7 deletions src/Hyperledger.Aries.TestHarness/Scenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,40 @@ public static class Scenarios
return (issuerCredential, holderCredential);
}

public static async Task<(ProofRecord holderProofRecord, ProofRecord RequestorProofRecord)> ProofProtocolAsync(
public static async Task<(ProofRecord holderProofRecord, ProofRecord requestorProofRecord)> ProposerInitiatedProofProtocolAsync(
IProofService proofService,
IProducerConsumerCollection<AgentMessage> messages,
ConnectionRecord holderConnection, ConnectionRecord requestorConnection,
IAgentContext holderContext, IAgentContext requestorContext,
ProofProposal proofProposalObject)
{
// Holder sends a proof proposal
var (holderProposalMessage, holderProofProposalRecord) = await proofService.CreateProposalAsync(holderContext, proofProposalObject, holderConnection.Id);
messages.TryAdd(holderProposalMessage);

// Requestor accepts the proposal and builds a proofRequest
var requestorProposalMessage = FindContentMessage<ProposePresentationMessage>(messages);
Assert.NotNull(requestorProposalMessage);

//Requestor stores the proof proposal
var requestorProofProposalRecord = await proofService.ProcessProposalAsync(requestorContext, requestorProposalMessage, requestorConnection);


// Requestor sends a proof request
var (requestorRequestMessage, requestorProofRequestRecord) = await proofService.CreateRequestFromProposalAsync(
requestorContext,
new ProofRequestParameters
{
Name = "Test",
Version = "1.0"
},
requestorProofProposalRecord.Id, requestorConnection.Id);
messages.TryAdd(requestorRequestMessage);

return await ProofProtocolAsync(proofService, messages, holderConnection, requestorConnection, holderContext, requestorContext, requestorProofRequestRecord);
}

public static async Task<(ProofRecord holderProofRecord, ProofRecord requestorProofRecord)> RequestorInitiatedProofProtocolAsync(
IProofService proofService,
IProducerConsumerCollection<AgentMessage> messages,
ConnectionRecord holderConnection, ConnectionRecord requestorConnection,
Expand All @@ -174,13 +207,24 @@ public static class Scenarios
var (message, requestorProofRecord) = await proofService.CreateRequestAsync(requestorContext, proofRequestObject, requestorConnection.Id);
messages.TryAdd(message);

return await ProofProtocolAsync(proofService, messages, holderConnection, requestorConnection, holderContext, requestorContext, requestorProofRecord);
}

public static async Task<(ProofRecord holderProofRecord, ProofRecord RequestorProofRecord)> ProofProtocolAsync(
IProofService proofService,
IProducerConsumerCollection<AgentMessage> messages,
ConnectionRecord holderConnection, ConnectionRecord requestorConnection,
IAgentContext holderContext,
IAgentContext requestorContext, ProofRecord requestorProofRecord)
{

// Holder accepts the proof requests and builds a proof
var proofRequest = FindContentMessage<RequestPresentationMessage>(messages);
Assert.NotNull(proofRequest);
var holderRequestPresentationMessage = FindContentMessage<RequestPresentationMessage>(messages);
Assert.NotNull(holderRequestPresentationMessage);

//Holder stores the proof request
var holderProofRequestRecord = await proofService.ProcessRequestAsync(holderContext, proofRequest, holderConnection);
var holderProofRecord = await proofService.GetAsync(holderContext, holderProofRequestRecord.Id);
//Holder stores the proof request if they haven't created it already
var holderProofRecord = await proofService.ProcessRequestAsync(holderContext, holderRequestPresentationMessage, holderConnection);
Console.WriteLine(holderProofRecord.RequestJson);
var holderProofRequest = JsonConvert.DeserializeObject<ProofRequest>(holderProofRecord.RequestJson);

// Auto satify the proof with which ever credentials in the wallet are capable
Expand All @@ -191,7 +235,7 @@ await ProofServiceUtils.GetAutoRequestedCredentialsForProofCredentials(holderCon
//Holder accepts the proof request and sends a proof
(var proofMessage, _) = await proofService.CreatePresentationAsync(
holderContext,
holderProofRequestRecord.Id,
holderProofRecord.Id,
requestedCredentials);
messages.TryAdd(proofMessage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ Task<string> ProcessCredentialRequestAsync(IAgentContext agentContext,
CredentialRequestMessage credentialRequest, ConnectionRecord connection);

/// <summary>
/// Creates and sends a credential with the given credential identifier
/// Creates a credential with the given credential identifier
/// </summary>
/// <param name="agentContext">Agent Context.</param>
/// <param name="credentialId">The credential identifier.</param>
/// <returns>The response async.</returns>
Task<(CredentialIssueMessage, CredentialRecord)> CreateCredentialAsync(IAgentContext agentContext, string credentialId);

/// <summary>
/// Creates and sends a credential with the given credential identifier.
/// Creates a credential with the given credential identifier.
/// The credential is issued with the attributeValues provided.
/// </summary>
/// <param name="agentContext">Agent Context.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public DefaultProofHandler(IProofService proofService)
/// </value>
public IEnumerable<MessageType> SupportedMessageTypes => new MessageType[]
{
MessageTypes.PresentProofNames.ProposePresentation,
MessageTypes.PresentProofNames.Presentation,
MessageTypes.PresentProofNames.RequestPresentation
};
Expand All @@ -37,6 +38,14 @@ public async Task<AgentMessage> ProcessAsync(IAgentContext agentContext, Unpacke
switch (messageContext.GetMessageType())
{
// v1.0
case MessageTypes.PresentProofNames.ProposePresentation:
{
var message = messageContext.GetMessage<ProposePresentationMessage>();
var record = await _proofService.ProcessProposalAsync(agentContext, message, messageContext.Connection);

messageContext.ContextRecord = record;
break;
}
case MessageTypes.PresentProofNames.RequestPresentation:
{
var message = messageContext.GetMessage<RequestPresentationMessage>();
Expand Down
Loading

0 comments on commit 44a0800

Please sign in to comment.