Skip to content

Commit

Permalink
fix(prism-agent): update didcomm peerdid library to support latest sp…
Browse files Browse the repository at this point in the history
…ec (#877)
  • Loading branch information
mineme0110 authored Feb 6, 2024
1 parent 0f52a2f commit 0c42a62
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 25 deletions.
1 change: 1 addition & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
castor:
- changed-files:
- any-glob-to-any-file:
Expand Down
6 changes: 4 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ inThisBuild(
githubOwner := "input-output-hk",
githubRepository := "atala-prism-building-blocks",
resolvers += "Local Maven Repository" at "file://" + Path.userHome.absolutePath + "/.m2/repository",
resolvers += "jitpack" at "https://jitpack.io",
)
)

Expand Down Expand Up @@ -57,7 +58,7 @@ lazy val V = new {
val zioMock = "1.0.0-RC11"
val mockito = "3.2.16.0"

// https://mvnrepository.com/artifact/io.circe/circe-core
// https://mvnrepository.com/artifact/io.circe/circe-core
val circe = "0.14.6"

val tapir = "1.6.4"
Expand Down Expand Up @@ -118,7 +119,7 @@ lazy val D = new {

// https://mvnrepository.com/artifact/org.didcommx/didcomm/0.3.2
val didcommx: ModuleID = "org.didcommx" % "didcomm" % "0.3.1"
val peerDidcommx: ModuleID = "org.didcommx" % "peerdid" % "0.3.0"
val peerDidcommx: ModuleID = "org.didcommx" % "peerdid" % "0.5.0"
val didScala: ModuleID = "app.fmgp" %% "did" % "0.0.0+113-61efa271-SNAPSHOT"

// Customized version of numbus jose jwt
Expand Down Expand Up @@ -413,6 +414,7 @@ val commonSetttings = Seq(
testFrameworks ++= Seq(new TestFramework("zio.test.sbt.ZTestFramework")),
// Needed for Kotlin coroutines that support new memory management mode
resolvers += "JetBrains Space Maven Repository" at "https://maven.pkg.jetbrains.space/public/p/kotlinx-coroutines/maven",
resolvers += "jitpack" at "https://jitpack.io",
// Override 'updateLicenses' for all project to inject custom DependencyResolution.
// https://github.com/sbt/sbt-license-report/blob/9675cedb19c794de1119cbcf46a255fc8dcd5d4e/src/main/scala/sbtlicensereport/SbtLicenseReport.scala#L84
updateLicenses := {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,26 @@ object AgentPeerService {

val keyIdAgreement = PeerDIDUtils.createMultibaseEncnumbasis(keyAgreement).drop(1)
val keyIdAuthentication = PeerDIDUtils.createMultibaseEncnumbasis(keyAuthentication).drop(1)
val keyIdAgreementIndex = agent.id.value.indexOf(keyIdAgreement)
val keyIdAuthenticationIndex = agent.id.value.indexOf(keyIdAuthentication)
val (keyAgreementId, keyAuthenticationId) =
if keyIdAgreementIndex < keyIdAuthenticationIndex then (1, 2) else (2, 1)

val secretKeyAgreement = new Secret(
s"${agent.id.value}#$keyIdAgreement",
s"${agent.id.value}#key-$keyAgreementId",
VerificationMethodType.JSON_WEB_KEY_2020,
new VerificationMaterial(VerificationMaterialFormat.JWK, agent.jwkForKeyAgreement.head.toJSONString)
)
val secretKeyAuthentication = new Secret(
s"${agent.id.value}#$keyIdAuthentication",
s"${agent.id.value}#key-$keyAuthenticationId",
VerificationMethodType.JSON_WEB_KEY_2020,
new VerificationMaterial(VerificationMaterialFormat.JWK, agent.jwkForKeyAuthentication.head.toJSONString)
)

new SecretResolverInMemory(
Map(
s"${agent.id.value}#$keyIdAgreement" -> secretKeyAgreement,
s"${agent.id.value}#$keyIdAuthentication" -> secretKeyAuthentication,
s"${agent.id.value}#key-$keyAgreementId" -> secretKeyAgreement,
s"${agent.id.value}#key-$keyAuthenticationId" -> secretKeyAuthentication,
).asJava
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,27 @@ object PeerDID {
* routingKeys are OPTIONAL. An ordered array of strings referencing keys to be used when preparing the message for
* transmission as specified in Sender Process to Enable Forwarding, above.
*/

case class ServiceEndpoint(uri: String, r: Seq[String] = Seq.empty, a: Seq[String] = Seq("didcomm/v2"))
object ServiceEndpoint {
implicit val encoder: Encoder[ServiceEndpoint] = deriveEncoder[ServiceEndpoint]
implicit val decoder: Decoder[ServiceEndpoint] = deriveDecoder[ServiceEndpoint]
def apply(endpoint: String) = new ServiceEndpoint(uri = endpoint)
}

case class Service(
t: String = "dm",
s: String,
r: Seq[String] = Seq.empty,
a: Seq[String] = Seq("didcomm/v2")
s: ServiceEndpoint
) {
def `type` = t
def serviceEndpoint = s
def routingKeys = r
def accept = a
def routingKeys = s.r
def accept = s.a
}
object Service {
implicit val encoder: Encoder[Service] = deriveEncoder[Service]
implicit val decoder: Decoder[Service] = deriveDecoder[Service]
def apply(endpoint: String) = new Service(s = endpoint)
def apply(endpoint: String) = new Service(s = ServiceEndpoint(endpoint))
}

def makeNewJwkKeyX25519: OctetKeyPair = new OctetKeyPairGenerator(Curve.X25519).generate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ object PeerDidResolver {
_.map { item =>
val id = item.hcursor.downField("id").as[String].getOrElse(???)
// val typ = item.hcursor.downField("type").as[String].getOrElse(???)
val serviceEndpoint = item.hcursor.downField("serviceEndpoint").as[String].getOrElse(???)
val routingKeys: Seq[String] = item.hcursor.downField("routingKeys").as[List[String]].getOrElse(Seq.empty)
val accept: Seq[String] = item.hcursor.downField("accept").as[List[String]].getOrElse(Seq.empty)
new DIDCommService(id, serviceEndpoint, routingKeys.asJava, accept.asJava)
val serviceEndpointJson = item.hcursor.downField("serviceEndpoint")
// val serviceEndpoint = item.hcursor.downField("serviceEndpoint").as[String].getOrElse(???)
val uri = serviceEndpointJson.downField("uri").as[String].getOrElse(???)
val routingKeys: Seq[String] =
serviceEndpointJson.downField("routingKeys").as[List[String]].getOrElse(Seq.empty)
val accept: Seq[String] = serviceEndpointJson.downField("accept").as[List[String]].getOrElse(Seq.empty)
new DIDCommService(id, uri, routingKeys.asJava, accept.asJava)
}
}
.getOrElse(List.empty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,39 @@ class PeerDidResolverSpec extends ZSuite {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2Vudj1yZmM1ODciXX0#key-2",
| "type": "Ed25519VerificationKey2020",
| "controller": "did:peer:2.Ez6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.Vz6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludCIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkiXSwiYSI6WyJkaWRjb21tL3YyIiwiZGlkY29tbS9haXAyO2Vudj1yZmM1ODciXX0",
| "publicKeyMultibase": "z6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V"
| },
| {
| "id": "did:peer:2.Ez6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.Vz6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludCIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkiXSwiYSI6WyJkaWRjb21tL3YyIiwiZGlkY29tbS9haXAyO2Vudj1yZmM1ODciXX0#6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg",
| "id": "did:peer:2.Ez6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.Vz6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludCIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkiXSwiYSI6WyJkaWRjb21tL3YyIiwiZGlkY29tbS9haXAyO2Vudj1yZmM1ODciXX0#key-3",
| "type": "Ed25519VerificationKey2020",
| "controller": "did:peer:2.Ez6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.Vz6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludCIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkiXSwiYSI6WyJkaWRjb21tL3YyIiwiZGlkY29tbS9haXAyO2Vudj1yZmM1ODciXX0",
| "publicKeyMultibase": "z6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg"
| }
| ],
| "keyAgreement": [
| {
| "id": "did:peer:2.Ez6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.Vz6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludCIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkiXSwiYSI6WyJkaWRjb21tL3YyIiwiZGlkY29tbS9haXAyO2Vudj1yZmM1ODciXX0#6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc",
| "id": "did:peer:2.Ez6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.Vz6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludCIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkiXSwiYSI6WyJkaWRjb21tL3YyIiwiZGlkY29tbS9haXAyO2Vudj1yZmM1ODciXX0#key-1",
| "type": "X25519KeyAgreementKey2020",
| "controller": "did:peer:2.Ez6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.Vz6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludCIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkiXSwiYSI6WyJkaWRjb21tL3YyIiwiZGlkY29tbS9haXAyO2Vudj1yZmM1ODciXX0",
| "publicKeyMultibase": "z6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc"
| }
| ],
| "service": [
| {
| "id": "did:peer:2.Ez6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.Vz6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludCIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkiXSwiYSI6WyJkaWRjb21tL3YyIiwiZGlkY29tbS9haXAyO2Vudj1yZmM1ODciXX0#didcommmessaging-0",
| "id": "#service",
| "type": "DIDCommMessaging",
| "serviceEndpoint": "https://example.com/endpoint",
| "routingKeys": [
| "serviceEndpoint": {
| "uri" : "https://example.com/endpoint",
| "routingKeys": [
| "did:example:somemediator#somekey"
| ],
| "accept": [
| ],
| "accept": [
| "didcomm/v2", "didcomm/aip2;env=rfc587"
| ]
| ]
| }
| }
| ]
|}""".stripMargin).toOption
Expand Down

0 comments on commit 0c42a62

Please sign in to comment.