Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #50 - [publish] - Add support to create/receive an out-of-band in… #52

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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