-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c2f4b0
commit e69e763
Showing
5 changed files
with
141 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
waltid-wallet-api/src/main/kotlin/id/walt/webwallet/service/DidWebRegistryService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package id.walt.webwallet.service | ||
|
||
import id.walt.webwallet.db.models.WalletDid | ||
import id.walt.webwallet.db.models.WalletDids | ||
import kotlinx.serialization.json.Json | ||
import kotlinx.serialization.json.JsonObject | ||
import kotlinx.serialization.json.jsonObject | ||
import org.jetbrains.exposed.sql.select | ||
import org.jetbrains.exposed.sql.transactions.transaction | ||
|
||
object DidWebRegistryService { | ||
|
||
fun listRegisteredDids(): List<String> { | ||
return transaction { | ||
WalletDids.select { | ||
WalletDids.did like "did:web:%" | ||
}.map { WalletDid(it).did } | ||
} | ||
} | ||
|
||
fun loadRegisteredDid(id: String): JsonObject { | ||
return transaction { | ||
Json.parseToJsonElement( | ||
WalletDids.select { | ||
WalletDids.did like "%:$id" | ||
}.single().let { | ||
WalletDid(it).document | ||
}).jsonObject | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...-wallet-api/src/main/kotlin/id/walt/webwallet/web/controllers/DidWebRegistryController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package id.walt.webwallet.web.controllers | ||
|
||
import id.walt.webwallet.service.DidWebRegistryService | ||
import io.github.smiley4.ktorswaggerui.dsl.get | ||
import io.github.smiley4.ktorswaggerui.dsl.route | ||
import io.ktor.http.* | ||
import io.ktor.server.application.* | ||
import io.ktor.server.response.* | ||
import io.ktor.server.routing.* | ||
import kotlinx.coroutines.runBlocking | ||
import kotlinx.serialization.json.JsonObject | ||
|
||
fun Application.didRegistry() = routing { | ||
route("did-registry", { | ||
tags = listOf("DID Web Registry") | ||
}) { | ||
get({ | ||
summary = "List registered DIDs" | ||
response { | ||
HttpStatusCode.OK to { | ||
description = "Array of (DID) strings" | ||
body<List<String>>() | ||
} | ||
} | ||
}) { | ||
context.respond(runBlocking { | ||
DidWebRegistryService.listRegisteredDids() | ||
}) | ||
} | ||
|
||
route("{id}/did.json", { | ||
tags = listOf("DID Web Registry") | ||
request { | ||
pathParameter<String>("id") { | ||
description = "ID" | ||
} | ||
} | ||
}) { | ||
get({ | ||
summary = "Show a specific DID" | ||
|
||
response { | ||
HttpStatusCode.OK to { | ||
description = "The DID document" | ||
body<JsonObject>() | ||
} | ||
} | ||
}) { | ||
|
||
val id = context.parameters["id"] ?: throw IllegalArgumentException("No ID supplied") | ||
|
||
context.respond( | ||
DidWebRegistryService.loadRegisteredDid(id) | ||
) | ||
} | ||
} | ||
} | ||
} |