Skip to content

Commit

Permalink
feat(mercury): Message field 'to' must be an Array (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioPinheiro committed Dec 9, 2022
1 parent cd416bf commit d4e2c57
Show file tree
Hide file tree
Showing 20 changed files with 78 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,11 @@ object AgentCli extends ZIOAppDefault {
for {
didCommService <- ZIO.service[DidComm]

encryptedForwardMessage <- didCommService.packEncrypted(msg, to = msg.to.get)
encryptedForwardMessage <- didCommService.packEncrypted(msg, to = msg.to.head) // TODO head
jsonString = encryptedForwardMessage.string

serviceEndpoint = UniversalDidResolver
.resolve(msg.to.get.value) // TODO GET
.resolve(msg.to.head.value) // TODO head
.get()
.getDidCommServices()
.asScala
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object AgentHardCode extends ZIOAppDefault {
msg = Message(
piuri = "TEST",
from = Some(didCommService.myDid),
to = None,
to = Seq.empty,
body = body.asJson.asObject.get
)
// signed <- didCommService.packSigned(msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ final case class UnpackMessageImp(private val msg: UnpackResult) extends UnpackM
from = Option(aux.getFrom()).map(DidId(_)),
to = Option(aux.getTo()).toSeq
.map(_.asScala)
.flatMap(_.toSeq.map(e => DidId(e)))
.headOption,
.flatMap(_.toSeq.map(e => DidId(e))),
body = thisbody,
id = aux.getId(),
createdTime = aux.getCreatedTime(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import io.iohk.atala.mercury.protocol.routing._
def makeMsg(from: Agent, to: Agent) = Message(
piuri = "http://atalaprism.io/lets_connect/proposal",
from = Some(from.id),
to = Some(to.id),
to = Seq(to.id),
body = JsonObject.fromIterable(
Seq(
"connectionId" -> Json.fromString("8fb9ea21-d094-4506-86b6-c7c1627d753a"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object CoordinateMediationPrograms {
val requestMediation = MediateRequest()
Message(
from = Some(replier),
to = Some(invitation.from),
to = Seq(invitation.from),
id = requestMediation.id,
piuri = requestMediation.`type`
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object OutOfBandLoginPrograms {
Message(
piuri = invitation.`type`,
from = Some(invitation.from),
to = None,
to = Seq.empty,
id = invitation.id,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type PIURI = String //type URI or URL?
case class Message(
piuri: PIURI,
from: Option[DidId],
to: Option[DidId], // TODO to need to be a Seq
to: Seq[DidId],
body: JsonObject = JsonObject.empty,
id: String = java.util.UUID.randomUUID.toString(),
createdTime: Long = LocalDateTime.now().toEpochSecond(ZoneOffset.of("Z")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ object ConnectionRequest {
body = body,
thid = message.thid,
from = message.from.get, // TODO get
to = message.to.get, // TODO get
to = {
assert(
message.to.length == 1,
"The recipient is ambiguous. Need to have only 1 recipient"
) // TODO return error return error
message.to.head
},
)
}

Expand All @@ -52,7 +58,7 @@ final case class ConnectionRequest(
id = this.id,
piuri = this.`type`,
from = Some(this.from),
to = Some(this.to),
to = Seq(this.to),
thid = this.thid,
body = this.body.asJson.asObject.get,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ object ConnectionResponse {
accept = cr.body.accept,
),
thid = msg.thid.orElse(Some(cr.id)),
from = msg.to.get, // TODO need new PeerDid
from = {
assert(msg.to.length == 1, "The recipient is ambiguous. Need to have only 1 recipient") // TODO return error
msg.to.head
},
to = msg.from.get, // TODO get
)
}
Expand All @@ -42,7 +45,10 @@ object ConnectionResponse {
body = body,
thid = message.thid,
from = message.from.get, // TODO get
to = message.to.get, // TODO get
to = {
assert(message.to.length == 1, "The recipient is ambiguous. Need to have only 1 recipient") // TODO return error
message.to.head
},
)
}

Expand All @@ -65,7 +71,7 @@ final case class ConnectionResponse(
id = this.id,
piuri = this.`type`,
from = Some(this.from),
to = Some(this.to),
to = Seq(this.to),
thid = this.thid,
body = this.body.asJson.asObject.get,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final case class IssueCredential(
id = this.id,
piuri = this.`type`,
from = Some(this.from),
to = Some(this.to),
to = Seq(this.to),
thid = this.thid,
body = this.body.asJson.asObject.get,
attachments = this.attachments,
Expand Down Expand Up @@ -104,7 +104,10 @@ object IssueCredential {
attachments = message.attachments,
thid = message.thid,
from = message.from.get, // TODO get
to = message.to.get, // TODO get
to = {
assert(message.to.length == 1, "The recipient is ambiguous. Need to have only 1 recipient") // TODO return error
message.to.head
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final case class OfferCredential(
id = this.id,
piuri = this.`type`,
from = Some(this.from),
to = Some(to),
to = Seq(to),
thid = this.thid,
body = this.body.asJson.asObject.get, // TODO get
attachments = this.attachments,
Expand Down Expand Up @@ -114,7 +114,10 @@ object OfferCredential {
attachments = message.attachments,
thid = message.thid,
from = message.from.get, // TODO get
to = message.to.get, // TODO get
to = {
assert(message.to.length == 1, "The recipient is ambiguous. Need to have only 1 recipient") // TODO return error
message.to.head
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final case class ProposeCredential(
def makeMessage: Message = Message(
piuri = this.`type`,
from = Some(this.from),
to = Some(this.to),
to = Seq(this.to),
body = this.body.asJson.asObject.get, // TODO get
attachments = this.attachments
)
Expand Down Expand Up @@ -92,7 +92,10 @@ object ProposeCredential {
body = body,
attachments = message.attachments,
from = message.from.get, // TODO get
to = message.to.get, // TODO get
to = {
assert(message.to.length == 1, "The recipient is ambiguous. Need to have only 1 recipient") // TODO return error
message.to.head
},
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final case class RequestCredential(
id = this.id,
piuri = this.`type`,
from = Some(this.from),
to = Some(this.to),
to = Seq(this.to),
thid = this.thid,
body = this.body.asJson.asObject.get, // TODO get
attachments = this.attachments,
Expand Down Expand Up @@ -93,7 +93,10 @@ object RequestCredential {
attachments = message.attachments,
thid = message.thid,
from = message.from.get, // TODO get
to = message.to.get, // TODO get
to = {
assert(message.to.length == 1, "The recipient is ambiguous. Need to have only 1 recipient") // TODO return error
message.to.head
},
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object Mailbox {
def asMessage = {
Message(
from = Some(from),
to = Some(to),
to = Seq(to),
body = JsonObject.empty,
id = id,
piuri = `type`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final case class OutOfBandLoginInvitation(
) {
assert(`type` == OutOfBandLoginInvitation.piuri)

def makeMsg: Message = Message(piuri = `type`, id = id, from = Some(from), to = None)
def makeMsg: Message = Message(piuri = `type`, id = id, from = Some(from), to = Seq.empty)

def reply(replier: DidId) = OutOfBandloginReply(
from = replier,
Expand Down Expand Up @@ -43,7 +43,7 @@ final case class OutOfBandloginReply(
) {
assert(`type` == OutOfBandloginReply.piuri)

def makeMsg: Message = Message(piuri = `type`, id = id, from = Some(from), to = Some(to), thid = Some(thid))
def makeMsg: Message = Message(piuri = `type`, id = id, from = Some(from), to = Seq(to), thid = Some(thid))
}

object OutOfBandloginReply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final case class Presentation(
def makeMessage: Message = Message(
piuri = this.`type`,
from = Some(this.from),
to = Some(this.to),
to = Seq(this.to),
thid = this.thid,
body = this.body.asJson.asObject.get, // TODO get
attachments = this.attachments
Expand Down Expand Up @@ -84,7 +84,10 @@ object Presentation {
),
attachments = rp.attachments,
thid = msg.thid,
from = msg.to.get, // TODO get
from = {
assert(msg.to.length == 1, "The recipient is ambiguous. Need to have only 1 recipient") // TODO return error
msg.to.head
},
to = msg.from.get, // TODO get
)
}
Expand All @@ -98,7 +101,10 @@ object Presentation {
attachments = message.attachments,
thid = message.thid,
from = message.from.get, // TODO get
to = message.to.get, // TODO get
to = {
assert(message.to.length == 1, "The recipient is ambiguous. Need to have only 1 recipient") // TODO return error
message.to.head
},
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final case class ProposePresentation(
def makeMessage: Message = Message(
piuri = this.`type`,
from = Some(this.from),
to = Some(this.to),
to = Seq(this.to),
thid = this.thid,
body = this.body.asJson.asObject.get, // TODO get
attachments = this.attachments
Expand Down Expand Up @@ -87,7 +87,10 @@ object ProposePresentation {
attachments = message.attachments,
thid = message.thid,
from = message.from.get, // TODO get
to = message.to.get, // TODO get
to = {
assert(message.to.length == 1, "The recipient is ambiguous. Need to have only 1 recipient") // TODO return error
message.to.head
},
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final case class RequestPresentation(
id = this.id,
piuri = this.`type`,
from = Some(this.from),
to = Some(this.to),
to = Seq(this.to),
thid = this.thid,
body = this.body.asJson.asObject.get, // TODO get
attachments = this.attachments,
Expand Down Expand Up @@ -62,7 +62,10 @@ object RequestPresentation {
),
attachments = pp.attachments,
thid = Some(msg.id),
from = msg.to.get, // TODO get
from = {
assert(msg.to.length == 1, "The recipient is ambiguous. Need to have only 1 recipient") // TODO return error
msg.to.head
},
to = msg.from.get, // TODO get
)
}
Expand All @@ -77,7 +80,10 @@ object RequestPresentation {
attachments = message.attachments,
thid = message.thid,
from = message.from.get, // TODO get
to = message.to.get, // TODO get
to = {
assert(message.to.length == 1, "The recipient is ambiguous. Need to have only 1 recipient") // TODO return error
message.to.head
},
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ object ReportProblem {
assert(problem.pthid == msg.id) // This is a reply!
Message(
piuri = "https://didcomm.org/report-problem/2.0/problem-report",
from = msg.to,
to = msg.from,
from = {
assert(msg.to.length <= 0, "The recipient is ambiguous. Need to have no more that 1 recipient") // TODO
msg.to.headOption
},
to = msg.from.toSeq,
body = JsonObject.fromIterable(
Seq(("code", Json.fromString(problem.code.value))) ++
problem.comment.map(e => ("comment", Json.fromString(e))) ++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type ForwardAttachment = AttachmentDescriptor
final case class ForwardMessage(
id: String = java.util.UUID.randomUUID.toString(),
from: DidId,
to: DidId, // ?? Set[DidId], // The mediator
to: DidId, // The mediator's did
expires_time: Option[Long],
body: ForwardBody,
attachments: Seq[ForwardAttachment],
Expand All @@ -39,7 +39,7 @@ final case class ForwardMessage(
def asMessage = {
Message(
from = Some(from),
to = Some(to),
to = Seq(to),
body = JsonObject(("next", Json.fromString(body.next.value))),
id = id,
piuri = `type`,
Expand Down

0 comments on commit d4e2c57

Please sign in to comment.