From f5a3711da0de2ab2af50facb7e69680882920b6d Mon Sep 17 00:00:00 2001 From: Fabio Pinheiro Date: Fri, 16 Sep 2022 09:18:50 -0700 Subject: [PATCH] feat(mercury): Report Problem Protocol (#21) Initial commit for ATL-1776 Aries RFC 0035: Report Problem Protocol 1.0 DIF: Report Problem Protocol 2.0 New module protocol-report_problem Boilerplate code for ReportProblem case classes --- mercury/prism-mediator/README.md | 1 + .../io/iohk/atala/mercury/Conversions.scala | 8 +- mercury/prism-mediator/build.sbt | 8 +- .../io/iohk/atala/mercury/model/Message.scala | 3 + .../Report-Problem-Protocol.md | 29 +++ .../reportproblem/v1/ReportProblem.scala | 89 +++++++++ .../reportproblem/v2/ReportProblem.scala | 183 ++++++++++++++++++ 7 files changed, 318 insertions(+), 3 deletions(-) create mode 100644 mercury/prism-mediator/protocol-report-problem/Report-Problem-Protocol.md create mode 100644 mercury/prism-mediator/protocol-report-problem/src/main/scala/io/iohk/atala/mercury/protocol/reportproblem/v1/ReportProblem.scala create mode 100644 mercury/prism-mediator/protocol-report-problem/src/main/scala/io/iohk/atala/mercury/protocol/reportproblem/v2/ReportProblem.scala diff --git a/mercury/prism-mediator/README.md b/mercury/prism-mediator/README.md index 37ac1018a3..ac5a975397 100644 --- a/mercury/prism-mediator/README.md +++ b/mercury/prism-mediator/README.md @@ -6,6 +6,7 @@ - Protocols: - [Invitation-Protocol](./protocol-invitation/Invitation-Protocol.md) - [Mercury-Mailbox-Protocol](./protocol-mercury-mailbox/Mercury-Mailbox-Protocol.md) + - [Report-Problem-Protocol](protocol-report-problem/Report-Problem-Protocol.md) - [Routing-Protocol](./protocol-routing/Routing-Protocol.md) - [Quick start](./QuickStart.md) - [UseCases](./UseCases.md) diff --git a/mercury/prism-mediator/agent-didcommx/src/main/scala/io/iohk/atala/mercury/Conversions.scala b/mercury/prism-mediator/agent-didcommx/src/main/scala/io/iohk/atala/mercury/Conversions.scala index b523bda020..fad9c4669f 100644 --- a/mercury/prism-mediator/agent-didcommx/src/main/scala/io/iohk/atala/mercury/Conversions.scala +++ b/mercury/prism-mediator/agent-didcommx/src/main/scala/io/iohk/atala/mercury/Conversions.scala @@ -20,13 +20,17 @@ given Conversion[PackEncryptedResult, EncryptedMessage] with { given Conversion[Message, org.didcommx.didcomm.message.Message] with { def apply(msg: Message): org.didcommx.didcomm.message.Message = { val attachments = msg.attachments.map { e => e: XAttachment } // cast - new MessageBuilder(msg.id, msg.body.asJava, msg.piuri) + val aux = new MessageBuilder(msg.id, msg.body.asJava, msg.piuri) .from(msg.from.value) .to(Seq(msg.to.value).asJava) .createdTime(msg.createdTime) .expiresTime(msg.createdTime + msg.expiresTimePlus) .attachments(attachments.toList.asJava) // TODO test - .build() + + msg.ack.foreach(str => aux.ack(str)) + msg.thid.foreach(str => aux.thid(str)) + msg.pthid.foreach(str => aux.pthid(str)) + aux.build() } } diff --git a/mercury/prism-mediator/build.sbt b/mercury/prism-mediator/build.sbt index d143fb3fa8..c6af2b9b21 100644 --- a/mercury/prism-mediator/build.sbt +++ b/mercury/prism-mediator/build.sbt @@ -102,6 +102,11 @@ lazy val protocolMercuryMailbox = project .settings(libraryDependencies += D.zio.value) .dependsOn(models, protocolInvitation, protocolRouting) +lazy val protocolReportProblem = project + .in(file("protocol-report-problem")) + .settings(name := "protocol-report_problem", version := VERSION) + .dependsOn(models) + lazy val protocolRouting = project .in(file("protocol-routing")) .settings(name := "mercury-protocol-routing-2_0", version := VERSION) @@ -189,8 +194,9 @@ lazy val mediator = project ) .dependsOn(agentDidcommx, resolver) .dependsOn( - protocolInvitation, protocolConnection, + protocolInvitation, protocolMercuryMailbox, + protocolReportProblem, protocolRouting, ) diff --git a/mercury/prism-mediator/models/src/main/scala/io/iohk/atala/mercury/model/Message.scala b/mercury/prism-mediator/models/src/main/scala/io/iohk/atala/mercury/model/Message.scala index 2ff54e4ebc..03dbc59cb9 100644 --- a/mercury/prism-mediator/models/src/main/scala/io/iohk/atala/mercury/model/Message.scala +++ b/mercury/prism-mediator/models/src/main/scala/io/iohk/atala/mercury/model/Message.scala @@ -16,4 +16,7 @@ case class Message( createdTime: Long = LocalDateTime.now().toEpochSecond(ZoneOffset.of("Z")), expiresTimePlus: Long = 1000, attachments: Seq[Attachment] = Seq.empty, // id -> data (data is also a json) + thid: Option[String] = None, + pthid: Option[String] = None, + ack: Seq[String] = Seq.empty, ) {} diff --git a/mercury/prism-mediator/protocol-report-problem/Report-Problem-Protocol.md b/mercury/prism-mediator/protocol-report-problem/Report-Problem-Protocol.md new file mode 100644 index 0000000000..2381e41c17 --- /dev/null +++ b/mercury/prism-mediator/protocol-report-problem/Report-Problem-Protocol.md @@ -0,0 +1,29 @@ +# Report Problem Protocol 1.0 & 2.0 + +This Protocol is parte of Aries (RFC 0035). +Describes how to report errors and warnings in a powerful, interoperable way. + +- Version 1.0 - see [https://github.com/hyperledger/aries-rfcs/tree/main/features/0035-report-problem] +- Version 2.0: + - see [https://identity.foundation/didcomm-messaging/spec/#problem-reports] + - see [https://didcomm.org/report-problem/2.0/] + +NOTE: In this context never reference to `Error` or `Warning`. Always reference as `Problem`. + +TODO: Support [l10n](https://github.com/hyperledger/aries-rfcs/blob/main/features/0043-l10n/README.md) in the Future. + +## PIURI + +- Version 1.0: + - `https://didcomm.org/report-problem/1.0` +- Version 2.0: + - `https://didcomm.org/report-problem/2.0/problem-report` + +## Notes + +The protocol is one-way, a simple one-step notification protocol: + +## Roles + +- `notifier` - Who sends notification. +- `notified` - Who receive notification. diff --git a/mercury/prism-mediator/protocol-report-problem/src/main/scala/io/iohk/atala/mercury/protocol/reportproblem/v1/ReportProblem.scala b/mercury/prism-mediator/protocol-report-problem/src/main/scala/io/iohk/atala/mercury/protocol/reportproblem/v1/ReportProblem.scala new file mode 100644 index 0000000000..cd11c4e7ff --- /dev/null +++ b/mercury/prism-mediator/protocol-report-problem/src/main/scala/io/iohk/atala/mercury/protocol/reportproblem/v1/ReportProblem.scala @@ -0,0 +1,89 @@ +package io.iohk.atala.mercury.protocol.reportproblem.v1 + +import io.iohk.atala.mercury.model.Message +import io.iohk.atala.mercury.model.PIURI + +/** ReportProblem + * + * Example: + * @see + * https://github.com/hyperledger/aries-rfcs/tree/main/features/0035-report-problem#the-problem-report-message-type + * + * {{{ + * { + * "@type" : "https://didcomm.org/report-problem/1.0/problem-report", + * "@id" : "an identifier that can be used to discuss this error message", + * "~thread" : "info about the threading context in which the error occurred (if any)", + * "description" : { "en": "localized message", "code": "symbolic-name-for-error" }, + * "problem_items" : [ {"": "value"} ], + * "who_retries" : "enum: you | me | both | none", + * "fix_hint" : { "en": "localized error-instance-specific hint of how to fix issue"}, + * "impact" : "enum: message | thread | connection", + * "where" : "enum: you | me | other - enum: cloud | edge | wire | agency | ..", + * "noticed_time" : "