Skip to content

Commit

Permalink
ATL-1738-Aries-RFC-0023-DIDExchange-Protocol (#29)
Browse files Browse the repository at this point in the history
* Added the readme file for didexchange protocol updated the state digram

* Added the readme file for didexchange protocol updated the state digram

* Added the readme file for didexchange protocol updated the state digram

* added Didexchnage

* added Didexchnage

* code cleanup

* removed the unwanted import

Signed-off-by: Shailesh <shailesh.patil@iohk.io>

Signed-off-by: Shailesh <shailesh.patil@iohk.io>
  • Loading branch information
mineme0110 committed Oct 12, 2022
1 parent 12dd9c2 commit bb4dfe5
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 16 deletions.
10 changes: 9 additions & 1 deletion mercury/prism-mediator/build.sbt
Expand Up @@ -111,6 +111,13 @@ lazy val protocolInvitation = project
)
.dependsOn(models)

lazy val protocolDidExchange = project
.in(file("protocol-did-exchange"))
.settings(name := "mercury-protocol-did-exchange", version := VERSION)
.settings(libraryDependencies += D.zio.value)
.settings(libraryDependencies ++= Seq(D.circeCore.value, D.circeGeneric.value, D.circeParser.value))
.dependsOn(models, protocolInvitation)

lazy val protocolMercuryMailbox = project
.in(file("protocol-mercury-mailbox"))
.settings(name := "mercury-protocol-mailbox", version := VERSION)
Expand Down Expand Up @@ -228,8 +235,9 @@ lazy val mediator = project
// .enablePlugins(JavaAppPackaging, DockerPlugin)
.dependsOn(agentDidcommx, resolver)
.dependsOn(
protocolConnection,
protocolInvitation,
protocolConnection,
protocolDidExchange,
protocolMercuryMailbox,
protocolReportProblem,
protocolRouting,
Expand Down
Expand Up @@ -2,6 +2,8 @@ package io.iohk.atala.mercury.model

import io.circe._

//TDOD Attachment replace this with AttachmentDescriptor

/** https://identity.foundation/didcomm-messaging/spec/#attachments
*
* Example:
Expand All @@ -17,7 +19,7 @@ import io.circe._
* }}}
*/
final case class Attachment(
data: AttachmentData,
data: AttachData,
id: String = java.util.UUID.randomUUID.toString(), // id: Option[String], OPTIONAL ????
// description:Option[String],
// media_type:Option[String],
Expand All @@ -30,4 +32,4 @@ final case class Attachment(
// Json.obj("data" -> data, "id" -> Json.fromString(id))
}

type AttachmentData = JsonObject
type AttachData = JsonObject
@@ -1,11 +1,21 @@
package io.iohk.atala.mercury.protocol.invitation
package io.iohk.atala.mercury.model

import java.util.{Base64 => JBase64}
import io.circe.Encoder
import io.circe.generic.semiauto._
import io.circe.syntax._

/** @see
* data in attachments https://identity.foundation/didcomm-messaging/spec/#attachments
*/
sealed trait AttachmentData

final case class Header(kid: String)

final case class Jws(header: Header, `protected`: String, signature: String)

final case class JwsData(base64: String, jws: Jws) extends AttachmentData

final case class Base64(base64: String) extends AttachmentData

/** @see
Expand Down
@@ -0,0 +1,24 @@
package io.iohk.atala.mercury.model

import io.circe.{Decoder, Encoder}
import io.circe.generic.semiauto.*
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}

object AttachmentDescriptorCodec {

implicit val headerEncoder: Encoder[Header] = deriveEncoder[Header]
implicit val headerDecoder: Decoder[Header] = deriveDecoder[Header]

implicit val jwsEncoder: Encoder[Jws] = deriveEncoder[Jws]
implicit val jwsDecoder: Decoder[Jws] = deriveDecoder[Jws]

implicit val jwsDataEncoder: Encoder[JwsData] = deriveEncoder[JwsData]
implicit val jwsDataDecoder: Decoder[JwsData] = deriveDecoder[JwsData]

implicit val base64Encoder: Encoder[Base64] = deriveEncoder[Base64]
implicit val base64eDecoder: Decoder[Base64] = deriveDecoder[Base64]

implicit val attachmentDescriptorEncoder: Encoder[AttachmentDescriptor] = deriveEncoder[AttachmentDescriptor]
implicit val attachmentDescriptorDecoder: Decoder[AttachmentDescriptor] = deriveDecoder[AttachmentDescriptor]

}
@@ -0,0 +1,64 @@
# DidExchange Protocol

This Protocol is parte of the DIDComm Messaging Specification.

Protocol to exchange DIDs between agents when establishing a DID-based relationship

See [https://github.com/hyperledger/aries-rfcs/tree/main/features/0023-did-exchange]

## PIURI

`https://didcomm.org/didexchange/1.0/request`
`https://didcomm.org/didexchange/1.0/problem_report`
`https://didcomm.org/didexchange/1.0/response`
`https://didcomm.org/didexchange/1.0/complete`

### Roles

- Requester(Is the receiver in out-of-band protocol)
- Will initiate the did-exchange
- Responder (Is the invitation sender in out-of-band protocol)
- Will respond to did exchange



### Requester request did-exchange
step1-->step2-->step3 Is a happy path flow

error - error received or sent and state transition

```mermaid
stateDiagram-v2
[*] --> invitation_received:out-of-band Invitation
invitation_received --> request_sent:step1-send did-exchange request
invitation_received --> abandoned:eror1 unable send problem report
request_sent --> response_received: step2-received did-exchange Response
request_sent --> invitation_received: eror2 received problem report
request_sent --> abandoned:eror2 unable continue after problem report
response_received --> completed:step3-send complete
response_received --> request_sent:eror3 send problem report
response_received --> abandoned:eror3 unable send problem report
abandoned --> [*]
completed --> [*]
```


### Responder responds to did-exchange
step1-->step2-->step3 Is a happy path flow

error received or sent and state transition
```mermaid
stateDiagram-v2
[*] --> invitation_sent:out-of-band send Invitation
invitation_sent --> request_received:step1. received did-exchange request
invitation_sent --> abandoned:eror1 unable send problem report
request_received --> response_sent: step2. send did-exchange Response
request_received --> abandoned:eror2 unable send problem report
request_received --> invitation_sent: error2 send problem report
response_sent --> completed: step3. received complete
response_sent --> request_received: error3 receive problem report
response_sent --> abandoned:eror3 unable continue after received problem report
abandoned --> [*]
completed --> [*]
```
@@ -0,0 +1,3 @@
package io.iohk.atala.mercury.protocol.didexchange.v1

object DIDExchange {}
@@ -0,0 +1,15 @@
package io.iohk.atala.mercury.protocol.didexchange.v1

import io.iohk.atala.mercury.model.{AttachmentDescriptor, PIURI}

final case class Thread(thid: String, pthid: String)

final case class DidExchangeRequest(
`@id`: String,
`@type`: PIURI,
`~thread`: Thread,
label: String,
goal_code: String,
goal: String,
`did_doc~attach`: Option[AttachmentDescriptor]
)
Expand Up @@ -5,6 +5,7 @@ import io.circe.generic.semiauto._
import io.circe.{Decoder, Encoder, HCursor, Json}
import io.iohk.atala.mercury.protocol.invitation.v1.{Invitation => InvitationV1}
import io.iohk.atala.mercury.protocol.invitation.v2.{Invitation => InvitationV2}
import io.iohk.atala.mercury.model.AttachmentDescriptorCodec._

object InvitationCodec {

Expand All @@ -25,12 +26,6 @@ object InvitationCodec {
Decoder[Did].widen
).reduceLeft(_ or _)

implicit val base64Encoder: Encoder[Base64] = deriveEncoder[Base64]
implicit val base64eDecoder: Decoder[Base64] = deriveDecoder[Base64]

implicit val attachmentDescriptorEncoder: Encoder[AttachmentDescriptor] = deriveEncoder[AttachmentDescriptor]
implicit val attachmentDescriptorDecoder: Decoder[AttachmentDescriptor] = deriveDecoder[AttachmentDescriptor]

implicit val invitationEncoderV1: Encoder[InvitationV1] = (entity: InvitationV1) =>
Json.obj(
"@id" -> Json.fromString(entity.`@id`),
Expand Down
Expand Up @@ -6,7 +6,7 @@ import io.circe.{Encoder, Json}
import io.iohk.atala.mercury.model.PIURI

import scala.annotation.targetName
import io.iohk.atala.mercury.protocol.invitation.AttachmentDescriptor
import io.iohk.atala.mercury.model.AttachmentDescriptor
import io.iohk.atala.mercury.protocol.invitation.ServiceType

/** Out-Of-Band invitation Example
Expand Down
Expand Up @@ -4,9 +4,7 @@ import io.circe.syntax._
import io.circe.generic.semiauto._
import io.circe.{Encoder, Json}
import io.iohk.atala.mercury.model.PIURI

import scala.annotation.targetName
import io.iohk.atala.mercury.protocol.invitation.AttachmentDescriptor
import io.iohk.atala.mercury.model.AttachmentDescriptor

/** Out-Of-Band invitation
* @see
Expand Down
Expand Up @@ -10,6 +10,7 @@ import io.circe.parser._

import io.iohk.atala.mercury.protocol.invitation._
import io.iohk.atala.mercury.protocol.invitation.InvitationCodec._
import io.iohk.atala.mercury.model.AttachmentDescriptor

class InvitationV1Spec extends ZSuite {

Expand Down
@@ -1,8 +1,8 @@
package io.iohk.atala.mercury.protocol.invitation
package io.iohk.atala.mercury.protocol.invitation.v2

import munit.*
import io.iohk.atala.mercury.protocol.invitation.v2._

import io.iohk.atala.mercury.protocol.invitation.OutOfBand
class OutOfBandSpec extends FunSuite {

test("out-of-band (_oob URL) messagem parsing into Invitation") {
Expand Down

0 comments on commit bb4dfe5

Please sign in to comment.