Skip to content

Commit

Permalink
feat: Update documentation (#898)
Browse files Browse the repository at this point in the history
Signed-off-by: Bassam Riman <bassam.riman@iohk.io>
  • Loading branch information
CryptoKnightIOG committed Feb 22, 2024
1 parent 1993d23 commit d221554
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 37 deletions.
110 changes: 108 additions & 2 deletions docs/docusaurus/credentials/present-proof.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# Present proof

The [Present Proof Protocol](/docs/concepts/glossary#present-proof-protocol) allows:
Expand Down Expand Up @@ -57,6 +60,9 @@ To do this, he makes a `POST` request to the [`/present-proof/presentations`](/a
1. `connectionId`: This field represents the unique identifier of an existing connection between the verifier and the Holder/prover. It is for exchanging messages related to the protocol flow execution.
2. `challenge` and `domain`: The Verifier provides the random seed challenge and operational domain, and the Holder/Prover must sign the generated proof to protect from replay attacks.

<Tabs groupId="vc-formats">
<TabItem value="jwt" label="JWT">

```bash
curl -X 'POST' 'http://localhost:8070/prism-agent/present-proof/presentations' \
-H 'accept: application/json' \
Expand All @@ -72,6 +78,56 @@ curl -X 'POST' 'http://localhost:8070/prism-agent/present-proof/presentations' \
}'
```

</TabItem>
<TabItem value="anoncreds" label="AnonCreds">

```bash
curl -X 'POST' 'http://localhost:8070/prism-agent/present-proof/presentations' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H "apikey: $API_KEY" \
-d '{
"connectionId": "872ddfa9-4115-46c2-8a1b-22c24c7431d7",
"anoncredPresentationRequest": {
"requested_attributes": {
"attribute1": {
"name": "Attribute 1",
"restrictions": [
{
"cred_def_id": "credential_definition_id_of_attribute1"
}
],
"non_revoked": {
"from": 1635734400,
"to": 1735734400
}
}
},
"requested_predicates": {
"predicate1": {
"name": "age",
"p_type": ">=",
"p_value": 18,
"restrictions": [
{
"schema_id": "schema_id_of_predicate1"
}
],
"non_revoked": {
"from": 1635734400
}
}
},
"name": "Example Presentation Request",
"nonce": "1234567890",
"version": "1.0"
},
"credentialFormat": "AnonCreds"
}'
```
</TabItem>
</Tabs>

Upon execution, a new presentation request record gets created with an initial state of `RequestPending`. The Verifier PRISM Agent will send the presentation request message to the PRISM Agent of the Holder/Prover through the specified DIDComm connection. The record state then is updated to `RequestSent`.

The Verifier can retrieve the list of presentation records by making a `GET` request to the [`/present-proof/presentations`](/agent-api/#tag/Present-Proof/operation/getAllPresentation) endpoint:
Expand Down Expand Up @@ -121,6 +177,9 @@ curl -X 'GET' 'http://localhost:8090/prism-agent/present-proof/presentations' \

The Holder/Prover can then accept a specific request, generate the proof, and send it to the Verifier PRISM Agent by making a `PATCH` request to the [`/present-proof/presentations/{id}`](/agent-api/#tag/Present-Proof/operation/updatePresentation) endpoint:

<Tabs groupId="vc-formats">
<TabItem value="jwt" label="JWT">

```bash
curl -X 'PATCH' 'http://localhost:8090/prism-agent/present-proof/presentations/{PRESENTATION_ID}' \
-H 'Content-Type: application/json' \
Expand All @@ -133,8 +192,39 @@ curl -X 'PATCH' 'http://localhost:8090/prism-agent/present-proof/presentations/{

The Holder/Prover will have to provide the following information:
1. `presentationId`: The unique identifier of the presentation record to accept.
2. `proofId`: The unique identifier of the verifiable credential record to use as proof.
2. `proofId`: The unique identifier of the verifiable credential record to use as proof.

</TabItem>
<TabItem value="anoncreds" label="AnonCreds">

```bash
curl -X 'PATCH' 'http://localhost:8090/prism-agent/present-proof/presentations/{PRESENTATION_ID}' \
-H 'Content-Type: application/json' \
-H "apikey: $API_KEY" \
-d '{
"action": "request-accept",
"anoncredPresentationRequest":{
"credentialProofs":[
{
"credential":"3e849b98-f0fd-4cb4-ae96-9ea527a76267",
"requestedAttribute":[
"age"
],
"requestedPredicate":[
"age"
]
}
]
}
}'
```
</TabItem>
</Tabs>

The Holder/Prover will have to provide the following information:
1. `presentationId`: The unique identifier of the presentation record to accept.
2. `anoncredPresentationRequest`: A list of credential unique identifier with the attribute and predicate the credential is answering for.

The record state is updated to `PresentationPending` and processed by the Holder/Prover PRISM Agent. The agent will automatically generate the proof presentation, change the state to `PresentationGenerated`, and will eventually send it to the Verifier Agent, and change the state to `PresentationSent`.

```mermaid
Expand All @@ -152,4 +242,20 @@ stateDiagram-v2

The following diagram shows the end-to-end flow for a verifier to request and verify a proof presentation from a Holder/prover.

![](present-proof-flow.png)
### JWT Present Proof Flow Diagram
![](present-proof-flow.png)
### Anoncreds Present Proof Flow Diagram
![](anoncreds-present-proof-flow.png)

<Tabs groupId="vc-formats">
<TabItem value="jwt" label="JWT">

![](present-proof-flow.png)

</TabItem>
<TabItem value="anoncreds" label="AnonCreds">

![](anoncreds-present-proof-flow.png)

</TabItem>
</Tabs>
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ final case class RequestPresentationAction(
anoncredPresentationRequest: Option[AnoncredCredentialProofsV1],
)

final case class AnoncredProof(
@description(annotations.credential.description)
@encodedExample(annotations.credential.example)
credential: String,
@description(annotations.requestedAttribute.description)
@encodedExample(annotations.requestedAttribute.example)
requestedAttribute: Seq[String],
@description(annotations.requestedPredicate.description)
@encodedExample(annotations.requestedPredicate.example)
requestedPredicate: Seq[String]
)

object RequestPresentationAction {
object annotations {
object action
Expand All @@ -55,7 +43,7 @@ object RequestPresentationAction {
)

object anoncredProof
extends Annotation[Option[Seq[AnoncredProof]]](
extends Annotation[Option[AnoncredCredentialProofsV1]](
description = "A list of proofs from the Anoncred library, each corresponding to a credential.",
example = None
)
Expand All @@ -66,18 +54,6 @@ object RequestPresentationAction {
"The unique identifier of the issue credential record - and hence VC - to use as the prover accepts the presentation request. Only applicable on the prover side when the action is `request-accept`.",
example = "id"
)

object requestedAttribute
extends Annotation[Seq[String]](
description = "The unique identifier of attribute that the credential is expected to provide.",
example = Seq("Attribute1", "Attribute2")
)

object requestedPredicate
extends Annotation[Seq[String]](
description = "The unique identifier of Predicate that the credential is expected to answer for.",
example = Seq("Predicate1", "Predicate2")
)
}

given RequestPresentationActionEncoder: JsonEncoder[RequestPresentationAction] =
Expand All @@ -86,16 +62,8 @@ object RequestPresentationAction {
given RequestPresentationActionDecoder: JsonDecoder[RequestPresentationAction] =
DeriveJsonDecoder.gen[RequestPresentationAction]

given AnoncredProofEncoder: JsonEncoder[AnoncredProof] =
DeriveJsonEncoder.gen[AnoncredProof]

given AnoncredProofDecoder: JsonDecoder[AnoncredProof] =
DeriveJsonDecoder.gen[AnoncredProof]

given RequestPresentationActionSchema: Schema[RequestPresentationAction] = Schema.derived

given AnoncredProofSchema: Schema[AnoncredProof] = Schema.derived

import AnoncredCredentialProofsV1.given

given Schema[AnoncredCredentialProofsV1] = Schema.derived
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ final case class RequestPresentationInput(
@description(annotations.proofs.description)
@encodedExample(annotations.proofs.example)
proofs: Seq[ProofRequestAux],
@description(annotations.proofs.description) // TODO
@encodedExample(annotations.proofs.example) // TODO
@description(annotations.anoncredPresentationRequest.description)
@encodedExample(annotations.anoncredPresentationRequest.example)
anoncredPresentationRequest: Option[AnoncredPresentationRequestV1],
@description(annotations.credentialFormat.description)
@encodedExample(annotations.credentialFormat.example)
Expand All @@ -46,6 +46,54 @@ object RequestPresentationInput {
example = Seq.empty
)

object anoncredPresentationRequest
extends Annotation[Option[AnoncredPresentationRequestV1]](
description = "Anoncred Presentation Request",
example = Some(
AnoncredPresentationRequestV1(
requested_attributes = Map(
"attribute1" -> AnoncredRequestedAttributeV1(
"Attribute 1",
List(
Map(
"cred_def_id" -> "credential_definition_id_of_attribute1"
)
),
Some(
AnoncredNonRevokedIntervalV1(
Some(1635734400),
Some(1735734400)
)
)
)
),
requested_predicates = Map(
"predicate1" ->
AnoncredRequestedPredicateV1(
"Predicate 1",
">=",
18,
List(
Map(
"schema_id" -> "schema_id_of_predicate1"
)
),
Some(
AnoncredNonRevokedIntervalV1(
Some(1635734400),
None
)
)
)
),
name = "Example Presentation Request",
nonce = "1234567890",
version = "1.0",
non_revoked = None
)
)
)

object credentialFormat
extends Annotation[Option[String]](
description = "The credential format (default to 'JWT')",
Expand Down

0 comments on commit d221554

Please sign in to comment.