Skip to content

Commit

Permalink
Fix DidDocService decoding, pass testMessageForward()
Browse files Browse the repository at this point in the history
Signed-off-by: conanoc <conanoc@gmail.com>
  • Loading branch information
conanoc committed Feb 23, 2024
1 parent 9daf1a1 commit 8d8d8ba
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@ class AgentTest {
agent = alice
alice.initialize()

val faberConfig = TestHelper.getBaseConfig()
val faberConfig = TestHelper.getBaseConfig("faber")
faberConfig.mediatorPickupStrategy = MediatorPickupStrategy.Implicit
faberConfig.mediatorConnectionsInvite = publicMediatorUrl
faberConfig.mediatorPollingInterval = 1

val faber = Agent(context, faberConfig)
faber.initialize()

val (aliceConnection, faberConnection) = TestHelper.makeConnection(alice, faber, 2.seconds)
val (aliceConnection, faberConnection) = TestHelper.makeConnection(alice, faber, 3.seconds)
assertEquals(aliceConnection.state, ConnectionState.Complete)
assertEquals(faberConnection.state, ConnectionState.Complete)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class MessageSender(val agent: Agent) {
return listOf(service)
}
if (connection.outOfBandInvitation != null) {
return connection.outOfBandInvitation!!.services.mapNotNull { it.asDidDocService() as DidComm }
return connection.outOfBandInvitation!!.services.mapNotNull { it.asDidCommService() }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ class WsOutboundTransport(val agent: Agent) : OutboundTransport, WebSocketListen
}

override fun onMessage(webSocket: WebSocket, text: String) {
logger.debug("Received message: {}", text)
logger.debug("Agent ${agent.agentConfig.label} received a message string")
val encryptedMessage = Json.decodeFromString<EncryptedMessage>(text)
GlobalScope.launch {
agent.receiveMessage(encryptedMessage)
}
}

override fun onMessage(webSocket: WebSocket, bytes: ByteString) {
logger.debug("Received message: {}", bytes.utf8())
logger.debug("Agent ${agent.agentConfig.label} received a message bytes.")
val encryptedMessage = Json.decodeFromString<EncryptedMessage>(bytes.utf8())
GlobalScope.launch {
agent.receiveMessage(encryptedMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ open class DidCommService(
override val routingKeys: List<String>? = null,
override val priority: Int? = 0,
override val accept: List<String>? = null,
) : DidComm
) : DidDocService(), DidComm
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package org.hyperledger.ariesframework.connection.models.didauth

import kotlinx.serialization.Serializable
import kotlinx.serialization.modules.SerializersModule
import kotlinx.serialization.modules.polymorphic
import kotlinx.serialization.modules.subclass

interface DidDocService {
val id: String
val serviceEndpoint: String
@Serializable
sealed class DidDocService {
abstract val id: String
abstract val serviceEndpoint: String
}

interface DidComm : DidDocService {
interface DidComm {
val id: String
val serviceEndpoint: String
val recipientKeys: List<String>
val routingKeys: List<String>?
val priority: Int?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ import kotlinx.serialization.Serializable
class DidDocumentService(
override val id: String,
override val serviceEndpoint: String,
) : DidDocService
) : DidDocService()
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class IndyAgentService(
override val routingKeys: List<String>? = null,
override val priority: Int? = 0,
override val accept: List<String>? = null,
) : DidComm
) : DidDocService(), DidComm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.hyperledger.ariesframework.util.DIDParser

@Serializable(with = OutOfBandDidCommServiceSerializer::class)
abstract class OutOfBandDidCommService {
abstract fun asDidDocService(): DidDocService?
abstract fun asDidCommService(): DidCommService?
}

object OutOfBandDidCommServiceSerializer : JsonContentPolymorphicSerializer<OutOfBandDidCommService>(OutOfBandDidCommService::class) {
Expand All @@ -35,7 +35,7 @@ class OutOfBandDidDocumentService(
val routingKeys: List<String>? = null,
val accept: List<String>? = null,
) : OutOfBandDidCommService() {
override fun asDidDocService(): DidDocService? {
override fun asDidCommService(): DidCommService? {
return DidCommService(
id,
serviceEndpoint,
Expand All @@ -49,7 +49,7 @@ class OutOfBandDidDocumentService(
class PublicDidService(
val did: String,
) : OutOfBandDidCommService() {
override fun asDidDocService(): DidDocService? {
override fun asDidCommService(): DidCommService? {
return null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import kotlinx.serialization.json.jsonPrimitive
import kotlinx.serialization.modules.SerializersModule
import kotlinx.serialization.modules.polymorphic
import kotlinx.serialization.modules.subclass
import org.hyperledger.ariesframework.connection.models.didauth.DidDocService
import org.hyperledger.ariesframework.proofs.models.RequestedCredentials
import org.hyperledger.ariesframework.util.concurrentForEach
import org.hyperledger.ariesframework.util.concurrentMap
Expand All @@ -29,6 +30,14 @@ sealed class Service {
abstract val id: String
}

interface DidComm {
val id: String
val serviceEndpoint: String
val recipientKeys: List<String>
val routingKeys: List<String>?
val priority: Int?
}

@Serializable
@SerialName("DidDocumentService")
data class Service1(
Expand All @@ -40,11 +49,11 @@ data class Service1(
@SerialName("IndyAgent")
data class Service2(
override val id: String,
val serviceEndpoint: String,
val recipientKeys: List<String>,
val routingKeys: List<String>,
val priority: Int,
) : Service()
override val serviceEndpoint: String,
override val recipientKeys: List<String>,
override val routingKeys: List<String>,
override val priority: Int,
) : Service(), DidComm

@Serializable
@SerialName("did-communication")
Expand Down

0 comments on commit 8d8d8ba

Please sign in to comment.