-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mercury): ATL-2287 Connection Protocol (#140)
Added Connection Protocol Refactoring and removing the todos Co-authored-by: FabioPinheiro <[email protected]>
- Loading branch information
1 parent
46ef902
commit 402248b
Showing
16 changed files
with
364 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
mercury/mercury-library/protocol-connection/Connection-Protocol.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Connection Protocol | ||
|
||
This Protocol is for DID base connection | ||
|
||
|
||
The protocol is used when you wish to create a connection with another agent. | ||
|
||
|
||
## PIURI | ||
|
||
Version 1.0: `https://atalaprism.io/mercury/connections/1.0/request` | ||
|
||
Version 1.0: `https://atalaprism.io/mercury/connections/1.0/response` | ||
|
||
### Roles | ||
|
||
- Inviter | ||
- Will create the message `https://didcomm.org/out-of-band/2.0/invitation` | ||
- will accept the Connection request and create new did peer and reply Connection response | ||
- Invitee | ||
- Will accept the invitation | ||
- Will create a did peer and reply to the Invitee with Connection Request | ||
|
||
### Notes | ||
|
||
|
||
|
||
### Inviter create invitation message for connection (Flow Diagram) | ||
|
||
```mermaid | ||
stateDiagram-v2 | ||
[*] --> Initial | ||
Initial --> await_response:Send out-of-band invitation message | ||
await_response --> connection_request:receive DIDCOMM Connection Request message | ||
connection_request --> connection_response:send DIDCOMM Connection Response message | ||
connection_response --> done | ||
await_response --> error:recieve problem report response | ||
done --> [*] | ||
``` | ||
|
||
### Invitee accepting invitation message for connection (Flow Diagram) | ||
|
||
```mermaid | ||
stateDiagram-v2 | ||
[*] --> Initial: out-of-band invitation connection message | ||
Initial --> connection_request:Create Connection Request | ||
connection_request --> await_response: Send Connection Request DIDCOMM message | ||
await_response --> connection_response:receive DIDCOMM Connection Response message | ||
await_response --> error:recieve problem report response | ||
connection_response --> done:send ACK | ||
done --> [*] | ||
``` |
59 changes: 59 additions & 0 deletions
59
...nnection/src/main/scala/io/iohk/atala/mercury/protocol/connection/ConnectionRequest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package io.iohk.atala.mercury.protocol.connection | ||
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} | ||
import io.circe.{Decoder, Encoder} | ||
import io.iohk.atala.mercury.model.{AttachmentDescriptor, DidId, Message, PIURI} | ||
import io.circe.syntax.* | ||
import io.iohk.atala.mercury.protocol.connection.ConnectionRequest.Body | ||
|
||
object ConnectionRequest { | ||
def `type`: PIURI = "https://atalaprism.io/mercury/connections/1.0/request" | ||
|
||
case class Body( | ||
goal_code: Option[String] = None, | ||
goal: Option[String] = None, | ||
accept: Seq[String] = Seq.empty | ||
) | ||
|
||
object Body { | ||
given Encoder[Body] = deriveEncoder[Body] | ||
|
||
given Decoder[Body] = deriveDecoder[Body] | ||
} | ||
|
||
given Encoder[ConnectionRequest] = deriveEncoder[ConnectionRequest] | ||
|
||
given Decoder[ConnectionRequest] = deriveDecoder[ConnectionRequest] | ||
|
||
def readFromMessage(message: Message): ConnectionRequest = { | ||
val body = message.body.asJson.as[ConnectionRequest.Body].toOption.get // TODO get | ||
ConnectionRequest( | ||
id = message.id, | ||
`type` = message.piuri, | ||
body = body, | ||
thid = message.thid, | ||
from = message.from.get, // TODO get | ||
to = message.to.get, // TODO get | ||
) | ||
} | ||
|
||
} | ||
|
||
final case class ConnectionRequest( | ||
`type`: PIURI = ConnectionRequest.`type`, | ||
id: String = java.util.UUID.randomUUID().toString, | ||
from: DidId, | ||
to: DidId, | ||
thid: Option[String], | ||
body: Body, | ||
) { | ||
assert(`type` == "https://atalaprism.io/mercury/connections/1.0/request") | ||
|
||
def makeMessage: Message = Message( | ||
id = this.id, | ||
piuri = this.`type`, | ||
from = Some(this.from), | ||
to = Some(this.to), | ||
thid = this.thid, | ||
body = this.body.asJson.asObject.get, | ||
) | ||
} |
72 changes: 72 additions & 0 deletions
72
...nection/src/main/scala/io/iohk/atala/mercury/protocol/connection/ConnectionResponse.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package io.iohk.atala.mercury.protocol.connection | ||
|
||
import io.circe.{Decoder, Encoder} | ||
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} | ||
import io.iohk.atala.mercury.model.{DidId, Message, PIURI} | ||
import io.circe.syntax.* | ||
|
||
object ConnectionResponse { | ||
def `type`: PIURI = "https://atalaprism.io/mercury/connections/1.0/response" | ||
|
||
final case class Body( | ||
goal_code: Option[String] = None, | ||
goal: Option[String] = None, | ||
accept: Seq[String] = Seq.empty | ||
) | ||
|
||
object Body { | ||
given Encoder[Body] = deriveEncoder[Body] | ||
given Decoder[Body] = deriveDecoder[Body] | ||
} | ||
|
||
def makeResponseFromRequest(msg: Message): ConnectionResponse = { | ||
val cr: ConnectionRequest = ConnectionRequest.readFromMessage(msg) | ||
|
||
ConnectionResponse( | ||
body = ConnectionResponse.Body( | ||
goal_code = cr.body.goal_code, | ||
goal = cr.body.goal, | ||
accept = cr.body.accept, | ||
), | ||
thid = msg.thid.orElse(Some(cr.id)), | ||
from = msg.to.get, // TODO need new PeerDid | ||
to = msg.from.get, // TODO get | ||
) | ||
} | ||
|
||
def readFromMessage(message: Message): ConnectionResponse = { | ||
val body = message.body.asJson.as[ConnectionResponse.Body].toOption.get // TODO get | ||
ConnectionResponse( | ||
id = message.id, | ||
`type` = message.piuri, | ||
body = body, | ||
thid = message.thid, | ||
from = message.from.get, // TODO get | ||
to = message.to.get, // TODO get | ||
) | ||
} | ||
|
||
given Encoder[ConnectionResponse] = deriveEncoder[ConnectionResponse] | ||
|
||
given Decoder[ConnectionResponse] = deriveDecoder[ConnectionResponse] | ||
} | ||
|
||
final case class ConnectionResponse( | ||
`type`: PIURI = ConnectionResponse.`type`, | ||
id: String = java.util.UUID.randomUUID().toString, | ||
from: DidId, | ||
to: DidId, | ||
thid: Option[String], | ||
body: ConnectionResponse.Body, | ||
) { | ||
assert(`type` == "https://atalaprism.io/mercury/connections/1.0/response") | ||
|
||
def makeMessage: Message = Message( | ||
id = this.id, | ||
piuri = this.`type`, | ||
from = Some(this.from), | ||
to = Some(this.to), | ||
thid = this.thid, | ||
body = this.body.asJson.asObject.get, | ||
) | ||
} |
14 changes: 14 additions & 0 deletions
14
...ection/src/main/scala/io/iohk/atala/mercury/protocol/connection/OutOfBandConnection.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.iohk.atala.mercury.protocol.connection | ||
|
||
import io.iohk.atala.mercury.model.DidId | ||
import io.iohk.atala.mercury.protocol.invitation.v2.Invitation | ||
import io.iohk.atala.mercury.protocol.invitation.v2.Invitation.Body | ||
|
||
object OutOfBandConnection { | ||
|
||
def createInvitation(from: DidId): Invitation = { | ||
val body = Body("connect", "Start relationship", Seq("didcomm/v2")) | ||
Invitation(`type` = Invitation.`type`, from, body) | ||
} | ||
|
||
} |
7 changes: 0 additions & 7 deletions
7
...rotocol-connection/src/main/scala/io/iohk/atala/mercury/protocol/connection/Request.scala
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
...otocol-connection/src/main/scala/io/iohk/atala/mercury/protocol/connection/Response.scala
This file was deleted.
Oops, something went wrong.
45 changes: 0 additions & 45 deletions
45
...invitation/src/main/scala/io/iohk/atala/mercury/protocol/invitation/InvitationCodec.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.