Skip to content

Commit

Permalink
Merge pull request #52 from roots-id/50-add-support-to-createreceive-…
Browse files Browse the repository at this point in the history
…an-out-of-band-invitation

fix #50 - [publish] - Add support to create/receive an out-of-band in…
  • Loading branch information
rogelio-blanco authored Sep 24, 2022
2 parents 7b68746 + 66fdcd1 commit d5b5bb2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,78 @@ import com.fasterxml.jackson.annotation.JsonFormat
import com.fasterxml.jackson.annotation.JsonValue

sealed class DidCommDataTypes {
companion object {
inline fun <reified T, U> findByStorageRepresentation(source: U): T where T : Enum<T>,
T : StorageRepresentable<U> =
enumValues<T>().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<String> {
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<String> {
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<String> {
INVITATION("invitation"),
ACTIVE("active"),
REQUEST("request"),
RESPONSE("response"),
enum class ConnectionState(@JsonValue override val value: String) : StorageRepresentable<String> {
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<String> {
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<String> {
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<String> {
NONE("none")
NONE("none"),
REQUEST("request"),
ACTIVE("active"),
ERROR("error")
}
}

inline fun <reified T, U> findBy(source: U): T where T : Enum<T>,
T : StorageRepresentable<U> =
enumValues<T>().first { it.value == source }
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d5b5bb2

Please sign in to comment.