commonMain.s2.sample.did.domain.DidS2.kt Maven / Gradle / Ivy
package s2.sample.did.domain
import kotlin.js.JsExport
import kotlin.js.JsName
import kotlinx.serialization.Serializable
import s2.dsl.automate.S2Automate
import s2.dsl.automate.S2Command
import s2.dsl.automate.S2Event
import s2.dsl.automate.S2InitCommand
import s2.dsl.automate.S2Role
import s2.dsl.automate.S2State
import s2.dsl.automate.builder.s2
import s2.sample.did.domain.features.DidAddPublicKeyCommand
import s2.sample.did.domain.features.DidCreateCommand
import s2.sample.did.domain.features.DidRevokeCommand
import s2.sample.did.domain.features.DidRevokePublicKeyCommand
typealias DidId = String
@JsExport
@JsName("didS2")
val didS2 = s2 {
name = "DidS2"
init {
to = DidState.Created()
role = DidRole.Admin()
}
transaction {
from = DidState.Created()
to = DidState.Activated()
role = DidRole.Owner()
}
transaction {
from = DidState.Activated()
to = DidState.Activated()
role = DidRole.Owner()
}
transaction {
from = DidState.Activated()
to = DidState.Revoked()
role = DidRole.Owner()
}
}
@Serializable
@JsExport
@JsName("DidRole")
sealed class DidRole : S2Role {
class Admin : DidRole()
class Owner : DidRole()
override fun toString(): String {
return this::class.simpleName!!
}
}
@Serializable
@JsExport
@JsName("DidState")
open class DidState(
override val position: Int,
) : S2State {
@Serializable
class Created : DidState(0)
@Serializable
class Activated : DidState(1)
@Serializable
class Revoked : DidState(2)
}
@JsExport
@JsName("DidInitCommand")
interface DidInitCommand : S2InitCommand
@JsExport
@JsName("DidCommand")
interface DidCommand : S2Command
@JsExport
@JsName("DidEvent")
interface DidEvent : S2Event