Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
replaced ssikit2 dependency with waltid-did
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeplotean committed Oct 11, 2023
1 parent 7edebe1 commit cd347ee
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 58 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ dependencies {


// SSI Kit 2
implementation("id.walt:waltid-ssikit2:1.0.4-SNAPSHOT")
implementation("id.walt.did:waltid-did:1.0.0")
// implementation("id.walt:waltid-ssikit2:1.0.4-SNAPSHOT")
// implementation id.walt:core-crypto -> provided by id.walt:waltid-ssikit2

// OIDC
Expand Down
9 changes: 4 additions & 5 deletions src/main/kotlin/id/walt/db/Db.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import id.walt.config.ConfigManager
import id.walt.config.DatabaseConfiguration
import id.walt.config.DatasourceConfiguration
import id.walt.db.models.*
import id.walt.service.WalletServiceManager
import id.walt.service.account.AccountsService
import id.walt.ssikit.did.DidService
import id.walt.web.model.EmailLoginRequest
import id.walt.web.model.LoginRequest
import io.github.oshai.kotlinlogging.KotlinLogging
import org.flywaydb.core.Flyway
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.StdOutSqlLogger
import org.jetbrains.exposed.sql.addLogger
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.transactions.transaction
import org.slf4j.bridge.SLF4JBridgeHandler
Expand Down
28 changes: 17 additions & 11 deletions src/main/kotlin/id/walt/service/SSIKit2WalletService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import id.walt.core.crypto.keys.KeySerialization
import id.walt.core.crypto.keys.KeyType
import id.walt.core.crypto.keys.LocalKey
import id.walt.db.models.*
import id.walt.did.dids.DidService
import id.walt.did.dids.registrar.dids.DidCheqdCreateOptions
import id.walt.did.dids.registrar.dids.DidJwkCreateOptions
import id.walt.did.dids.registrar.dids.DidKeyCreateOptions
import id.walt.did.dids.registrar.dids.DidWebCreateOptions
import id.walt.did.helpers.WaltidServices
import id.walt.did.utils.EnumUtils.enumValueIgnoreCase
import id.walt.oid4vc.data.GrantType
import id.walt.oid4vc.data.OpenIDProviderMetadata
import id.walt.oid4vc.providers.OpenIDClientConfig
Expand All @@ -20,11 +27,6 @@ import id.walt.service.dto.LinkedWalletDataTransferObject
import id.walt.service.dto.WalletDataTransferObject
import id.walt.service.keys.KeysService
import id.walt.service.oidc4vc.TestCredentialWallet
import id.walt.ssikit.did.DidService
import id.walt.ssikit.did.registrar.dids.DidJwkCreateOptions
import id.walt.ssikit.did.registrar.dids.DidKeyCreateOptions
import id.walt.ssikit.helpers.WaltidServices
import id.walt.ssikit.utils.EnumUtils.enumValueIgnoreCase
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.engine.cio.*
Expand All @@ -46,7 +48,6 @@ import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.transactions.transaction
import java.net.URLDecoder
import java.util.*
import kotlin.collections.HashMap
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi
import kotlin.time.Duration.Companion.seconds
Expand Down Expand Up @@ -309,20 +310,19 @@ class SSIKit2WalletService(accountId: UUID) : WalletService(accountId) {
override suspend fun createDid(method: String, args: Map<String, JsonPrimitive>): String {
// TODO: other DIDs
val key = args["keyId"]?.content?.let { getKey(it) }?.getOrNull() ?: LocalKey.generate(KeyType.Ed25519)

val newKeyId = key.getKeyId()
val keyId = key.getKeyId()
val options = getDidOptions(method, args)

val result = DidService.registerByKey(method, key, options)
KeysService.insert(accountId, key.getKeyId(), KeySerialization.serializeKey(key))
KeysService.insert(accountId, keyId, KeySerialization.serializeKey(key))

transaction {

WalletDids.insert {
it[account] = accountId
it[did] = result.did
it[this.alias] = args["alias"]?.content ?: ""
it[keyId] = newKeyId
it[alias] = args["alias"]?.content ?: ""
it[WalletDids.keyId] = keyId
it[document] = Json.encodeToString(result.didDocument)
}
}
Expand Down Expand Up @@ -494,6 +494,12 @@ class SSIKit2WalletService(accountId: UUID) : WalletService(accountId) {
args["key"]?.let { enumValueIgnoreCase<KeyType>(it.content) } ?: KeyType.Ed25519,
args["useJwkJcsPub"]?.let { it.content.toBoolean() } ?: false
)
"jwk" -> DidJwkCreateOptions()
"web" -> DidWebCreateOptions(domain = args["domain"]?.content ?: "", path = args["path"]?.content ?: "")
"cheqd" -> DidCheqdCreateOptions(
network = args["network"]?.content ?: "test",
document = Json.decodeFromString<JsonObject>(args["document"]?.content ?: "")
)
else -> DidJwkCreateOptions()
}
}
2 changes: 0 additions & 2 deletions src/main/kotlin/id/walt/service/WalletKitWalletService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import id.walt.config.RemoteWalletConfig
import id.walt.db.models.*
import id.walt.service.dto.LinkedWalletDataTransferObject
import id.walt.service.dto.WalletDataTransferObject
import id.walt.ssikit.utils.JsonUtils.toJsonElement
import id.walt.utils.JsonUtils.toJsonPrimitive
import io.ktor.client.*
import io.ktor.client.call.*
Expand All @@ -24,7 +23,6 @@ import kotlinx.datetime.toKotlinInstant
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package id.walt.service.oidc4vc
import id.walt.core.crypto.keys.Key
import id.walt.core.crypto.utils.JsonUtils.toJsonElement
import id.walt.core.crypto.utils.JwsUtils.decodeJws
import id.walt.did.dids.DidService
import id.walt.oid4vc.data.OpenIDProviderMetadata
import id.walt.oid4vc.data.dif.DescriptorMapping
import id.walt.oid4vc.data.dif.PresentationDefinition
Expand All @@ -12,13 +13,11 @@ import id.walt.oid4vc.errors.PresentationError
import id.walt.oid4vc.interfaces.PresentationResult
import id.walt.oid4vc.providers.SIOPCredentialProvider
import id.walt.oid4vc.providers.SIOPProviderConfig
import id.walt.oid4vc.providers.SIOPSession
import id.walt.oid4vc.providers.TokenTarget
import id.walt.oid4vc.requests.AuthorizationRequest
import id.walt.oid4vc.requests.TokenRequest
import id.walt.oid4vc.responses.TokenErrorCode
import id.walt.service.SSIKit2WalletService
import id.walt.ssikit.did.DidService
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.engine.cio.*
Expand Down
70 changes: 35 additions & 35 deletions src/main/kotlin/id/walt/web/DidCreation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,36 @@ package id.walt.web
import io.github.smiley4.ktorswaggerui.dsl.post
import io.ktor.server.response.*
import io.ktor.server.routing.*
import kotlinx.serialization.json.JsonPrimitive

object DidCreation {

fun Route.didCreate() {
post("key", {
summary = "Create a did:key"
}) {
val alias = context.request.queryParameters["alias"] ?: ""
val useJwkJcsPub = context.request.queryParameters["useJwkJcsPub"]?.toBoolean() ?: false
context.respond(
getWalletService().createDidWithParameters(
"key", mapOf(
"useJwkJcsPub" to useJwkJcsPub
),alias
getWalletService().createDid(
"key",
mapOf(
"useJwkJcsPub" to JsonPrimitive(
context.request.queryParameters["useJwkJcsPub"]?.toBoolean() ?: false
),
"alias" to JsonPrimitive(context.request.queryParameters["alias"])
)
)
)
}

post("jwk", {
summary = "Create a did:jwk"
}) {
val alias = context.request.queryParameters["alias"] ?: ""
context.respond(getWalletService().createDid("jwk", alias=alias))
context.respond(
getWalletService().createDid(
"jwk",
mapOf("alias" to JsonPrimitive(context.request.queryParameters["alias"]))
)
)
}

post("web", {
Expand All @@ -35,17 +42,13 @@ object DidCreation {
queryParameter<String>("path")
}
}) {
val domain = context.request.queryParameters["domain"]
val path = context.request.queryParameters["path"]

val alias = context.request.queryParameters["alias"] ?: ""

context.respond(
getWalletService().createDidWithParameters(
getWalletService().createDid(
"web", mapOf(
"domain" to domain,
"path" to path
),alias
"domain" to JsonPrimitive(context.request.queryParameters["domain"]),
"path" to JsonPrimitive(context.request.queryParameters["path"]),
"alias" to JsonPrimitive(context.request.queryParameters["alias"])
)
)
)
}
Expand All @@ -57,18 +60,13 @@ object DidCreation {
queryParameter<String>("bearerToken") { description = "Required for v1 (LegalEntity)" }
}
}) {
val version = context.request.queryParameters["version"]?.toInt()
val bearerToken = context.request.queryParameters["bearerToken"]
var alias = context.request.queryParameters["alias"]
if (alias == null){
alias =""
}
context.respond(
getWalletService().createDidWithParameters(
getWalletService().createDid(
"ebsi", mapOf(
"bearerToken" to bearerToken,
"version" to version
),alias
"bearerToken" to JsonPrimitive(context.request.queryParameters["bearerToken"]),
"version" to JsonPrimitive(context.request.queryParameters["version"]?.toInt()),
"alias" to JsonPrimitive(context.request.queryParameters["alias"])
)
)
)
}
Expand All @@ -79,24 +77,26 @@ object DidCreation {
queryParameter<String>("network") { description = "testnet or mainnet" }
}
}) {
val network = context.request.queryParameters["network"]
val alias = context.request.queryParameters["alias"] ?: ""

context.respond(
getWalletService().createDidWithParameters(
getWalletService().createDid(
"cheqd", mapOf(
"network" to network
),alias
"network" to JsonPrimitive(context.request.queryParameters["network"]),
"alias" to JsonPrimitive(context.request.queryParameters["alias"])
)
)
)
}

post("iota", {
summary = "Create a did:iota"
}) {
val alias = context.request.queryParameters["alias"] ?: ""

context.respond(getWalletService().createDid("iota", alias = alias))
context.respond(
getWalletService().createDid(
"iota",
mapOf("alias" to JsonPrimitive(context.request.queryParameters["alias"]))
)
)
}
}

Expand Down
4 changes: 2 additions & 2 deletions web/src/pages/settings/dids/create/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const methods = new Map([
["key", ["useJwkJcsPub"]],
["jwk", []],
["web", ["domain", "path"]],
["ebsi", ["bearer token", "version"]],
["cheqd", ["network"]],
["iota", []]
// ["ebsi", ["bearer token", "version"]],
// ["iota", []]
])
useHead({
Expand Down

0 comments on commit cd347ee

Please sign in to comment.