From 66fdcd10a8f263ec74084daf2f516473124c8994 Mon Sep 17 00:00:00 2001 From: Rogelio Blanco Date: Fri, 23 Sep 2022 10:30:32 -0600 Subject: [PATCH] fix #50 - [publish] - Add support to create/receive an out-of-band invitation - Add new attributes to the didcomm connection interface - Add Accept enum --- .../didcomm/common/DidCommDataTypes.kt | 61 +++++++++++++++---- .../didcomm/model/DidCommConnection.kt | 6 +- .../document/DidCommConnectionDocument.kt | 6 +- 3 files changed, 58 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/com/rootsid/wal/library/didcomm/common/DidCommDataTypes.kt b/src/main/kotlin/com/rootsid/wal/library/didcomm/common/DidCommDataTypes.kt index 48d7a15..cf488fa 100644 --- a/src/main/kotlin/com/rootsid/wal/library/didcomm/common/DidCommDataTypes.kt +++ b/src/main/kotlin/com/rootsid/wal/library/didcomm/common/DidCommDataTypes.kt @@ -4,39 +4,78 @@ import com.fasterxml.jackson.annotation.JsonFormat import com.fasterxml.jackson.annotation.JsonValue sealed class DidCommDataTypes { + companion object { + inline fun findByStorageRepresentation(source: U): T where T : Enum, + T : StorageRepresentable = + enumValues().first { it.value == source } + } + /** + * Connection acceptance: manual or auto + * Values: manual, auto + */ + @JsonFormat(shape = JsonFormat.Shape.STRING) + enum class Accept(@JsonValue override val value: String) : StorageRepresentable { + MANUAL("manual"), + AUTO("auto") + } + + /** + * Connection protocol used + * Values: didcomm/2.0 + */ @JsonFormat(shape = JsonFormat.Shape.STRING) enum class ConnectionProtocol(@JsonValue override val value: String) : StorageRepresentable { DIDCOMM_2_0("didcomm/2.0") } + /** + * Connection state using rfc23_state + */ @JsonFormat(shape = JsonFormat.Shape.STRING) - enum class ConnectionStatus(@JsonValue override val value: String) : StorageRepresentable { - INVITATION("invitation"), - ACTIVE("active"), - REQUEST("request"), - RESPONSE("response"), + enum class ConnectionState(@JsonValue override val value: String) : StorageRepresentable { + START("start"), + INVITATION_SENT("invitation-sent"), + INVITATION_RECEIVED("invitation-received"), + REQUEST_SENT("request-sent"), + REQUEST_RECEIVED("request-received"), + RESPONSE_SENT("response-sent"), + RESPONSE_RECEIVED("response-received"), + ABANDONED("abandoned"), COMPLETED("completed") } + /** + * Their role in the connection protocol + * Values: invitee, requester, inviter, responder + */ @JsonFormat(shape = JsonFormat.Shape.STRING) enum class TheirRole(@JsonValue override val value: String) : StorageRepresentable { INVITEE("invitee"), - INVITER("inviter") + INVITER("inviter"), + REQUESTER("requester"), + RESPONDER("responder") } + /** + * Invitation mode + * Values: simple, multi + */ @JsonFormat(shape = JsonFormat.Shape.STRING) enum class InvitationMode(@JsonValue override val value: String) : StorageRepresentable { SIMPLE("simple"), MULTI("multi") } + /** + * Routing state of connection + * Values: none, request, active, error + */ @JsonFormat(shape = JsonFormat.Shape.STRING) enum class RoutingState(@JsonValue override val value: String) : StorageRepresentable { - NONE("none") + NONE("none"), + REQUEST("request"), + ACTIVE("active"), + ERROR("error") } } - -inline fun findBy(source: U): T where T : Enum, - T : StorageRepresentable = - enumValues().first { it.value == source } diff --git a/src/main/kotlin/com/rootsid/wal/library/didcomm/model/DidCommConnection.kt b/src/main/kotlin/com/rootsid/wal/library/didcomm/model/DidCommConnection.kt index 33a28b8..2857da1 100644 --- a/src/main/kotlin/com/rootsid/wal/library/didcomm/model/DidCommConnection.kt +++ b/src/main/kotlin/com/rootsid/wal/library/didcomm/model/DidCommConnection.kt @@ -7,14 +7,16 @@ import java.time.LocalDateTime interface DidCommConnection: Serializable { val _id: String val invitationMsgId: String + val invitationUrl: String? val alias: String - val accept: String - val state: DidCommDataTypes.ConnectionStatus + val accept: DidCommDataTypes.Accept + val state: DidCommDataTypes.ConnectionState val theirRole: DidCommDataTypes.TheirRole val invitationMode: DidCommDataTypes.InvitationMode val connectionProtocol: DidCommDataTypes.ConnectionProtocol val routingState: DidCommDataTypes.RoutingState val invitationKey: String + val myDid: String? val createdAt: LocalDateTime val updatedAt: LocalDateTime } diff --git a/src/main/kotlin/com/rootsid/wal/library/mongoimpl/document/DidCommConnectionDocument.kt b/src/main/kotlin/com/rootsid/wal/library/mongoimpl/document/DidCommConnectionDocument.kt index 867c4a9..48300c8 100644 --- a/src/main/kotlin/com/rootsid/wal/library/mongoimpl/document/DidCommConnectionDocument.kt +++ b/src/main/kotlin/com/rootsid/wal/library/mongoimpl/document/DidCommConnectionDocument.kt @@ -10,10 +10,12 @@ import java.util.* data class DidCommConnectionDocument( override val alias: String, override val invitationKey: String, - override val accept: String = "manual", + override val accept: DidCommDataTypes.Accept = DidCommDataTypes.Accept.MANUAL, override val _id: String = UUID.randomUUID().toString(), + override val myDid: String? = null, override val invitationMsgId: String = UUID.randomUUID().toString(), - override val state: DidCommDataTypes.ConnectionStatus = DidCommDataTypes.ConnectionStatus.INVITATION, + override val invitationUrl: String? = null, + override val state: DidCommDataTypes.ConnectionState = DidCommDataTypes.ConnectionState.START, override val theirRole: DidCommDataTypes.TheirRole = DidCommDataTypes.TheirRole.INVITEE, override val invitationMode: DidCommDataTypes.InvitationMode = DidCommDataTypes.InvitationMode.SIMPLE, override val connectionProtocol: DidCommDataTypes.ConnectionProtocol = DidCommDataTypes.ConnectionProtocol.DIDCOMM_2_0,