From 3a118d621117c058bfd68ddb9ae3fcfdb0d3ed09 Mon Sep 17 00:00:00 2001 From: waltkb <68587968+waltkb@users.noreply.github.com> Date: Wed, 29 Nov 2023 01:09:08 +0100 Subject: [PATCH] Updated IDs in models to be able to remove all the conversions --- build.gradle.kts | 11 ++++++----- src/main/kotlin/id/walt/db/Db.kt | 16 ++++++++++++++-- src/main/kotlin/id/walt/db/models/Accounts.kt | 11 +++++------ .../id/walt/db/models/WalletCredentials.kt | 3 +-- .../walt/db/models/WalletOperationHistories.kt | 11 +++++------ src/main/kotlin/id/walt/db/models/Wallets.kt | 7 +++---- src/main/kotlin/id/walt/db/models/Web3Wallets.kt | 4 +++- .../id/walt/db/models/todo/AccountIssuers.kt | 4 ++-- .../kotlin/id/walt/db/models/todo/Issuers.kt | 7 +++---- .../id/walt/service/SSIKit2WalletService.kt | 14 +++++++------- .../id/walt/service/WalletKitWalletService.kt | 9 ++++----- .../id/walt/service/WalletServiceManager.kt | 12 +++++------- .../kotlin/id/walt/service/Web3WalletService.kt | 14 ++++++-------- .../id/walt/service/account/AccountsService.kt | 10 ++++------ .../walt/service/account/EmailAccountStrategy.kt | 7 +++---- .../service/account/Web3WalletAccountStrategy.kt | 6 ++---- .../service/credentials/CredentialsService.kt | 9 ++++----- .../kotlin/id/walt/service/dids/DidService.kt | 15 +++++++-------- .../dto/LinkedWalletDataTransferObject.kt | 3 +-- .../kotlin/id/walt/service/keys/KeysService.kt | 9 ++++----- .../id/walt/service/nft/NftKitNftService.kt | 3 +-- .../walt/service/oidc4vc/TestCredentialWallet.kt | 2 +- .../id/walt/web/controllers/AuthController.kt | 5 ++--- 23 files changed, 93 insertions(+), 99 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 5a138e6..3abfbf7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -85,6 +85,7 @@ dependencies { // UUID implementation("app.softwork:kotlinx-uuid-core:0.0.22") + implementation("app.softwork:kotlinx-uuid-exposed:0.0.22") /* -- Security -- */ // Bouncy Castle @@ -106,11 +107,11 @@ dependencies { implementation("io.github.reactivecircus.cache4k:cache4k:0.11.0") // DB - implementation("org.jetbrains.exposed:exposed-core:0.44.0") - implementation("org.jetbrains.exposed:exposed-jdbc:0.44.0") - implementation("org.jetbrains.exposed:exposed-dao:0.44.0") - implementation("org.jetbrains.exposed:exposed-java-time:0.44.0") - implementation("org.jetbrains.exposed:exposed-json:0.44.0") + implementation("org.jetbrains.exposed:exposed-core:0.44.1") + implementation("org.jetbrains.exposed:exposed-jdbc:0.44.1") + implementation("org.jetbrains.exposed:exposed-dao:0.44.1") + implementation("org.jetbrains.exposed:exposed-java-time:0.44.1") + implementation("org.jetbrains.exposed:exposed-json:0.44.1") implementation("org.xerial:sqlite-jdbc:3.42.0.0") implementation("org.postgresql:postgresql:42.6.0") // migration diff --git a/src/main/kotlin/id/walt/db/Db.kt b/src/main/kotlin/id/walt/db/Db.kt index 31c408d..9a6e576 100644 --- a/src/main/kotlin/id/walt/db/Db.kt +++ b/src/main/kotlin/id/walt/db/Db.kt @@ -61,7 +61,7 @@ object Db { Accounts, Web3Wallets ) - SchemaUtils.create( + /*SchemaUtils.create( Web3Wallets, Accounts, //AccountWeb3WalletMappings, @@ -72,7 +72,19 @@ object Db { WalletDids, WalletOperationHistories, Issuers - ) + )*/ + + SchemaUtils.create(Web3Wallets) + SchemaUtils.create(Accounts) + //AccountWeb3WalletMappings, + SchemaUtils.create(Wallets) + SchemaUtils.create(AccountWalletMappings) + SchemaUtils.create(WalletCredentials) + SchemaUtils.create(WalletKeys) + SchemaUtils.create(WalletDids) + SchemaUtils.create(WalletOperationHistories) + SchemaUtils.create(Issuers) + runBlocking { AccountsService.register(EmailAccountRequest("Max Mustermann", "string@string.string", "string")) diff --git a/src/main/kotlin/id/walt/db/models/Accounts.kt b/src/main/kotlin/id/walt/db/models/Accounts.kt index d6af215..72b91b2 100644 --- a/src/main/kotlin/id/walt/db/models/Accounts.kt +++ b/src/main/kotlin/id/walt/db/models/Accounts.kt @@ -4,18 +4,17 @@ import kotlinx.datetime.Instant import kotlinx.datetime.toKotlinInstant import kotlinx.serialization.Serializable import kotlinx.uuid.UUID -import kotlinx.uuid.toKotlinUUID -import org.jetbrains.exposed.dao.id.UUIDTable +import kotlinx.uuid.exposed.KotlinxUUIDTable import org.jetbrains.exposed.sql.ResultRow import org.jetbrains.exposed.sql.javatime.timestamp -object Accounts : UUIDTable("accounts") { +object Accounts : KotlinxUUIDTable("accounts") { val name = varchar("name", 128).nullable() val email = varchar("email", 128).nullable().uniqueIndex() val password = varchar("password", 200).nullable() - // val loginWeb3Wallet = uuid("web3wallet").nullable() + // val loginWeb3Wallet = kotlinxUUID("web3wallet").nullable() val createdOn = timestamp("createdOn") @@ -38,10 +37,10 @@ data class Account( val createdOn: Instant ) { constructor(result: ResultRow) : this( - id = result[Accounts.id].value.toKotlinUUID(), + id = result[Accounts.id].value, name = result[Accounts.name], email = result[Accounts.email], - //loginWeb3Wallet = result[Accounts.loginWeb3Wallet]?.toKotlinUUID(), + //loginWeb3Wallet = result[Accounts.loginWeb3Wallet]?, createdOn = result[Accounts.createdOn].toKotlinInstant() ) } diff --git a/src/main/kotlin/id/walt/db/models/WalletCredentials.kt b/src/main/kotlin/id/walt/db/models/WalletCredentials.kt index dbd22ed..af10d07 100644 --- a/src/main/kotlin/id/walt/db/models/WalletCredentials.kt +++ b/src/main/kotlin/id/walt/db/models/WalletCredentials.kt @@ -9,7 +9,6 @@ import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.JsonPrimitive import kotlinx.serialization.json.jsonObject import kotlinx.uuid.UUID -import kotlinx.uuid.toKotlinUUID import org.jetbrains.exposed.sql.ResultRow import org.jetbrains.exposed.sql.Table import org.jetbrains.exposed.sql.javatime.timestamp @@ -75,7 +74,7 @@ data class WalletCredential( constructor(result: ResultRow) : this( - wallet = result[WalletCredentials.wallet].value.toKotlinUUID(), + wallet = result[WalletCredentials.wallet].value, id = result[WalletCredentials.id], document = result[WalletCredentials.document], disclosures = result[WalletCredentials.disclosures], diff --git a/src/main/kotlin/id/walt/db/models/WalletOperationHistories.kt b/src/main/kotlin/id/walt/db/models/WalletOperationHistories.kt index 4d14d66..4be7d16 100644 --- a/src/main/kotlin/id/walt/db/models/WalletOperationHistories.kt +++ b/src/main/kotlin/id/walt/db/models/WalletOperationHistories.kt @@ -8,13 +8,12 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import kotlinx.uuid.UUID +import kotlinx.uuid.exposed.KotlinxUUIDTable import kotlinx.uuid.generateUUID -import kotlinx.uuid.toKotlinUUID -import org.jetbrains.exposed.dao.id.UUIDTable import org.jetbrains.exposed.sql.ResultRow import org.jetbrains.exposed.sql.javatime.timestamp -object WalletOperationHistories : UUIDTable("wallet_operation_histories") { +object WalletOperationHistories : KotlinxUUIDTable("wallet_operation_histories") { val account = reference("account", Accounts) val wallet = reference("wallet", Wallets) val timestamp = timestamp("timestamp") @@ -32,9 +31,9 @@ data class WalletOperationHistory( val data: String, ) { constructor(result: ResultRow) : this( - id = result[WalletOperationHistories.id].value.toKotlinUUID(), - account = result[WalletOperationHistories.account].value.toKotlinUUID(), - wallet = result[WalletOperationHistories.wallet].value.toKotlinUUID(), + id = result[WalletOperationHistories.id].value, + account = result[WalletOperationHistories.account].value, + wallet = result[WalletOperationHistories.wallet].value, timestamp = result[WalletOperationHistories.timestamp].toKotlinInstant(), operation = result[WalletOperationHistories.operation], data = result[WalletOperationHistories.data], diff --git a/src/main/kotlin/id/walt/db/models/Wallets.kt b/src/main/kotlin/id/walt/db/models/Wallets.kt index d7ecd70..807272c 100644 --- a/src/main/kotlin/id/walt/db/models/Wallets.kt +++ b/src/main/kotlin/id/walt/db/models/Wallets.kt @@ -4,12 +4,11 @@ import kotlinx.datetime.Instant import kotlinx.datetime.toKotlinInstant import kotlinx.serialization.Serializable import kotlinx.uuid.UUID -import kotlinx.uuid.toKotlinUUID -import org.jetbrains.exposed.dao.id.UUIDTable +import kotlinx.uuid.exposed.KotlinxUUIDTable import org.jetbrains.exposed.sql.ResultRow import org.jetbrains.exposed.sql.javatime.timestamp -object Wallets : UUIDTable("wallets") { +object Wallets : KotlinxUUIDTable("wallets") { val name = varchar("name", 128) val createdOn = timestamp("createdOn") } @@ -21,7 +20,7 @@ data class Wallet( val createdOn: Instant ) { constructor(result: ResultRow) : this( - id = result[Wallets.id].value.toKotlinUUID(), + id = result[Wallets.id].value, name = result[Wallets.name], createdOn = result[Wallets.createdOn].toKotlinInstant() ) diff --git a/src/main/kotlin/id/walt/db/models/Web3Wallets.kt b/src/main/kotlin/id/walt/db/models/Web3Wallets.kt index bea133d..e2360f4 100644 --- a/src/main/kotlin/id/walt/db/models/Web3Wallets.kt +++ b/src/main/kotlin/id/walt/db/models/Web3Wallets.kt @@ -1,10 +1,12 @@ package id.walt.db.models +import kotlinx.uuid.exposed.autoGenerate +import kotlinx.uuid.exposed.kotlinxUUID import org.jetbrains.exposed.sql.Table object Web3Wallets : Table("web3wallets") { val account = reference("account", Accounts) - val id = uuid("id").autoGenerate() + val id = kotlinxUUID("id").autoGenerate() val address = varchar("address", 256).uniqueIndex() val ecosystem = varchar("ecosystem", 128) diff --git a/src/main/kotlin/id/walt/db/models/todo/AccountIssuers.kt b/src/main/kotlin/id/walt/db/models/todo/AccountIssuers.kt index 6c7ae21..1a62dbb 100644 --- a/src/main/kotlin/id/walt/db/models/todo/AccountIssuers.kt +++ b/src/main/kotlin/id/walt/db/models/todo/AccountIssuers.kt @@ -1,9 +1,9 @@ package id.walt.db.models.todo import id.walt.db.models.Accounts -import org.jetbrains.exposed.dao.id.UUIDTable +import kotlinx.uuid.exposed.KotlinxUUIDTable -object AccountIssuers : UUIDTable("account_issuers") { +object AccountIssuers : KotlinxUUIDTable("account_issuers") { val account = reference("account", Accounts) val issuer = reference("issuer", Issuers) diff --git a/src/main/kotlin/id/walt/db/models/todo/Issuers.kt b/src/main/kotlin/id/walt/db/models/todo/Issuers.kt index ec0bc2b..11bb6aa 100644 --- a/src/main/kotlin/id/walt/db/models/todo/Issuers.kt +++ b/src/main/kotlin/id/walt/db/models/todo/Issuers.kt @@ -1,11 +1,10 @@ package id.walt.db.models.todo import kotlinx.uuid.UUID -import kotlinx.uuid.toKotlinUUID -import org.jetbrains.exposed.dao.id.UUIDTable +import kotlinx.uuid.exposed.KotlinxUUIDTable import org.jetbrains.exposed.sql.ResultRow -object Issuers : UUIDTable("issuers") { +object Issuers : KotlinxUUIDTable("issuers") { val name = varchar("name", 128).uniqueIndex() val description = text("description").nullable().default("no description") val uiEndpoint = varchar("ui", 128) @@ -20,7 +19,7 @@ data class Issuer( val configurationEndpoint: String, ) { constructor(result: ResultRow) : this( - id = result[Issuers.id].value.toKotlinUUID(), + id = result[Issuers.id].value, name = result[Issuers.name], description = result[Issuers.description], uiEndpoint = result[Issuers.uiEndpoint], diff --git a/src/main/kotlin/id/walt/service/SSIKit2WalletService.kt b/src/main/kotlin/id/walt/service/SSIKit2WalletService.kt index 942f1dc..5c5760a 100644 --- a/src/main/kotlin/id/walt/service/SSIKit2WalletService.kt +++ b/src/main/kotlin/id/walt/service/SSIKit2WalletService.kt @@ -51,7 +51,6 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.encodeToString import kotlinx.serialization.json.* import kotlinx.uuid.UUID -import kotlinx.uuid.toJavaUUID import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.transactions.transaction @@ -201,8 +200,9 @@ class SSIKit2WalletService(accountId: UUID, walletId: UUID) : WalletService(acco println("Resolved presentation definition: ${presentationSession.authorizationRequest!!.presentationDefinition!!.toJSONString()}") - val tokenResponse = credentialWallet.processImplicitFlowAuthorization(presentationSession.authorizationRequest!!) - val resp = ktorClient.submitForm(presentationSession.authorizationRequest!!.responseUri!!, + val tokenResponse = credentialWallet.processImplicitFlowAuthorization(presentationSession.authorizationRequest) + val resp = ktorClient.submitForm( + presentationSession.authorizationRequest.responseUri!!, parameters { tokenResponse.toHttpParameters().forEach { entry -> entry.value.forEach { append(entry.key, it) } @@ -504,7 +504,7 @@ class SSIKit2WalletService(accountId: UUID, walletId: UUID) : WalletService(acco transaction { WalletKeys.insert { it[WalletKeys.keyId] = keyId - it[wallet] = walletId.toJavaUUID() + it[wallet] = walletId it[document] = KeySerialization.serializeKey(key) it[createdOn] = Clock.System.now().toJavaInstant() } @@ -547,7 +547,7 @@ class SSIKit2WalletService(accountId: UUID, walletId: UUID) : WalletService(acco override fun getHistory(limit: Int, offset: Int): List = WalletOperationHistories - .select { WalletOperationHistories.wallet eq walletId.toJavaUUID() } + .select { WalletOperationHistories.wallet eq walletId } .orderBy(WalletOperationHistories.timestamp) .limit(10) .map { row -> @@ -557,8 +557,8 @@ class SSIKit2WalletService(accountId: UUID, walletId: UUID) : WalletService(acco override suspend fun addOperationHistory(operationHistory: WalletOperationHistory) { transaction { WalletOperationHistories.insert { - it[account] = operationHistory.account.toJavaUUID() - it[wallet] = operationHistory.wallet.toJavaUUID() + it[account] = operationHistory.account + it[wallet] = operationHistory.wallet it[timestamp] = operationHistory.timestamp.toJavaInstant() it[operation] = operationHistory.operation it[data] = Json.encodeToString(operationHistory.data) diff --git a/src/main/kotlin/id/walt/service/WalletKitWalletService.kt b/src/main/kotlin/id/walt/service/WalletKitWalletService.kt index 4aeb084..db3c36a 100644 --- a/src/main/kotlin/id/walt/service/WalletKitWalletService.kt +++ b/src/main/kotlin/id/walt/service/WalletKitWalletService.kt @@ -27,7 +27,6 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.encodeToString import kotlinx.serialization.json.* import kotlinx.uuid.UUID -import kotlinx.uuid.toJavaUUID import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.transactions.transaction @@ -60,7 +59,7 @@ class WalletKitWalletService(accountId: UUID, walletId: UUID) : WalletService(ac private val userEmail: String by lazy { transaction { - Accounts.select { Accounts.id eq this@WalletKitWalletService.walletId.toJavaUUID() } + Accounts.select { Accounts.id eq this@WalletKitWalletService.walletId } .single()[Accounts.email] } ?: throw IllegalArgumentException("No such account: ${this.walletId}") } @@ -339,7 +338,7 @@ class WalletKitWalletService(accountId: UUID, walletId: UUID) : WalletService(ac override fun getHistory(limit: Int, offset: Int): List = transaction { WalletOperationHistories - .select { WalletOperationHistories.account eq walletId.toJavaUUID() } + .select { WalletOperationHistories.account eq walletId } .orderBy(WalletOperationHistories.timestamp) .limit(10) .map { WalletOperationHistory(it) } @@ -348,8 +347,8 @@ class WalletKitWalletService(accountId: UUID, walletId: UUID) : WalletService(ac override suspend fun addOperationHistory(operationHistory: WalletOperationHistory) { transaction { WalletOperationHistories.insert { - it[wallet] = walletId.toJavaUUID() - it[account] = accountId.toJavaUUID() + it[wallet] = walletId + it[account] = accountId it[timestamp] = operationHistory.timestamp.toJavaInstant() it[operation] = operationHistory.operation it[data] = Json.encodeToString(operationHistory.data) diff --git a/src/main/kotlin/id/walt/service/WalletServiceManager.kt b/src/main/kotlin/id/walt/service/WalletServiceManager.kt index 1a03afd..fa9b98c 100644 --- a/src/main/kotlin/id/walt/service/WalletServiceManager.kt +++ b/src/main/kotlin/id/walt/service/WalletServiceManager.kt @@ -9,8 +9,6 @@ import id.walt.service.nft.NftService import kotlinx.datetime.Clock import kotlinx.datetime.toJavaInstant import kotlinx.uuid.UUID -import kotlinx.uuid.toJavaUUID -import kotlinx.uuid.toKotlinUUID import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.select import java.util.concurrent.ConcurrentHashMap @@ -31,12 +29,12 @@ object WalletServiceManager { val walletId = Wallets.insert { it[name] = "Wallet of $accountName" it[createdOn] = Clock.System.now().toJavaInstant() - }[Wallets.id].value.toKotlinUUID() + }[Wallets.id].value println("Creating wallet mapping: $forAccount -> $walletId") AccountWalletMappings.insert { - it[account] = forAccount.toJavaUUID() - it[wallet] = walletId.toJavaUUID() + it[account] = forAccount + it[wallet] = walletId it[permissions] = AccountWalletPermissions.ADMINISTRATE it[addedOn] = Clock.System.now().toJavaInstant() } @@ -46,8 +44,8 @@ object WalletServiceManager { @Deprecated(replaceWith = ReplaceWith("AccountsService.getAccountWalletMappings(account)", "id.walt.service.account.AccountsService"), message = "depreacted") fun listWallets(account: UUID): List = - AccountWalletMappings.innerJoin(Wallets).select { AccountWalletMappings.account eq account.toJavaUUID() }.map { - it[Wallets.id].value.toKotlinUUID() + AccountWalletMappings.innerJoin(Wallets).select { AccountWalletMappings.account eq account }.map { + it[Wallets.id].value } fun getNftService(): NftService = NftKitNftService() diff --git a/src/main/kotlin/id/walt/service/Web3WalletService.kt b/src/main/kotlin/id/walt/service/Web3WalletService.kt index 201095d..a14bd78 100644 --- a/src/main/kotlin/id/walt/service/Web3WalletService.kt +++ b/src/main/kotlin/id/walt/service/Web3WalletService.kt @@ -5,8 +5,6 @@ import id.walt.service.dto.LinkedWalletDataTransferObject import id.walt.service.dto.WalletDataTransferObject import kotlinx.uuid.UUID import kotlinx.uuid.generateUUID -import kotlinx.uuid.toJavaUUID -import kotlinx.uuid.toKotlinUUID import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.transactions.transaction @@ -20,8 +18,8 @@ object Web3WalletService { */ fun link(accountId: UUID, wallet: WalletDataTransferObject): LinkedWalletDataTransferObject = Web3Wallets.insert { - it[account] = accountId.toJavaUUID() - it[id] = UUID.generateUUID().toJavaUUID() + it[account] = accountId + it[id] = UUID.generateUUID() it[address] = wallet.address it[ecosystem] = wallet.ecosystem it[owner] = false @@ -34,7 +32,7 @@ object Web3WalletService { * @return true - if operation succeeded, false - otherwise */ fun unlink(accountId: UUID, walletId: UUID): Boolean = transaction { - Web3Wallets.deleteWhere { (account eq accountId.toJavaUUID()) and (id eq walletId.toJavaUUID()) } + Web3Wallets.deleteWhere { (account eq accountId) and (id eq walletId) } } == 1 /** @@ -71,9 +69,9 @@ object Web3WalletService { * === 2 different accounts exist, which the user should have access to (merged) when logging in with web3-address */ transaction { - Web3Wallets.select { Web3Wallets.account eq accountId.toJavaUUID() }.map { + Web3Wallets.select { Web3Wallets.account eq accountId }.map { LinkedWalletDataTransferObject( - it[Web3Wallets.id].toKotlinUUID(), + it[Web3Wallets.id], it[Web3Wallets.address], it[Web3Wallets.ecosystem], it[Web3Wallets.owner] @@ -83,7 +81,7 @@ object Web3WalletService { private fun setIsOwner(accountId: UUID, walletId: UUID, isOwner: Boolean) = transaction { Web3Wallets.update( - { (Web3Wallets.account eq accountId.toJavaUUID()) and (Web3Wallets.id eq walletId.toJavaUUID()) } + { (Web3Wallets.account eq accountId) and (Web3Wallets.id eq walletId) } ) { it[owner] = isOwner } diff --git a/src/main/kotlin/id/walt/service/account/AccountsService.kt b/src/main/kotlin/id/walt/service/account/AccountsService.kt index 523f7e6..311c509 100644 --- a/src/main/kotlin/id/walt/service/account/AccountsService.kt +++ b/src/main/kotlin/id/walt/service/account/AccountsService.kt @@ -12,8 +12,6 @@ import kotlinx.datetime.toKotlinInstant import kotlinx.serialization.Serializable import kotlinx.serialization.json.JsonPrimitive import kotlinx.uuid.UUID -import kotlinx.uuid.toJavaUUID -import kotlinx.uuid.toKotlinUUID import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.select @@ -40,7 +38,7 @@ object AccountsService { transaction { queryDefaultIssuer("walt.id")?.let { defaultIssuer -> AccountIssuers.insert { - it[account] = registeredUserId.toJavaUUID() + it[account] = registeredUserId it[issuer] = defaultIssuer } } @@ -75,10 +73,10 @@ object AccountsService { AccountWalletListing(account, wallets = transaction { AccountWalletMappings.innerJoin(Wallets) - .select { AccountWalletMappings.account eq account.toJavaUUID() } + .select { AccountWalletMappings.account eq account } .map { AccountWalletListing.WalletListing( - id = it[AccountWalletMappings.wallet].value.toKotlinUUID(), + id = it[AccountWalletMappings.wallet].value, name = it[Wallets.name], createdOn = it[Wallets.createdOn].toKotlinInstant(), addedOn = it[AccountWalletMappings.addedOn].toKotlinInstant(), @@ -104,7 +102,7 @@ object AccountsService { .map { Account(it) } } - fun getNameFor(account: UUID) = Accounts.select { Accounts.id eq account.toJavaUUID() }.single()[Accounts.email] + fun getNameFor(account: UUID) = Accounts.select { Accounts.id eq account }.single()[Accounts.email] } @Serializable diff --git a/src/main/kotlin/id/walt/service/account/EmailAccountStrategy.kt b/src/main/kotlin/id/walt/service/account/EmailAccountStrategy.kt index 75f1583..d7d45eb 100644 --- a/src/main/kotlin/id/walt/service/account/EmailAccountStrategy.kt +++ b/src/main/kotlin/id/walt/service/account/EmailAccountStrategy.kt @@ -2,12 +2,11 @@ package id.walt.service.account import de.mkammerer.argon2.Argon2Factory import id.walt.db.models.Accounts -import id.walt.web.controllers.ByteLoginRequest import id.walt.web.UnauthorizedException +import id.walt.web.controllers.ByteLoginRequest import id.walt.web.model.EmailAccountRequest import kotlinx.datetime.Clock import kotlinx.datetime.toJavaInstant -import kotlinx.uuid.toKotlinUUID import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.transactions.transaction @@ -29,7 +28,7 @@ object EmailAccountStrategy : AccountStrategy { it[Accounts.email] = email it[password] = hash it[createdOn] = Clock.System.now().toJavaInstant() - }[Accounts.id].value.toKotlinUUID() + }[Accounts.id].value } RegistrationResult(createdAccountId) @@ -58,7 +57,7 @@ object EmailAccountStrategy : AccountStrategy { } if (passwordMatches) { - val id = matchedAccount[Accounts.id].value.toKotlinUUID() + val id = matchedAccount[Accounts.id].value return AuthenticatedUser(id, req.username) } else { throw UnauthorizedException("Invalid password for \"${req.username}\"!") diff --git a/src/main/kotlin/id/walt/service/account/Web3WalletAccountStrategy.kt b/src/main/kotlin/id/walt/service/account/Web3WalletAccountStrategy.kt index ffacbcf..2a36f48 100644 --- a/src/main/kotlin/id/walt/service/account/Web3WalletAccountStrategy.kt +++ b/src/main/kotlin/id/walt/service/account/Web3WalletAccountStrategy.kt @@ -5,8 +5,6 @@ import id.walt.db.models.Web3Wallets import id.walt.web.model.AddressAccountRequest import kotlinx.datetime.Clock import kotlinx.datetime.toJavaInstant -import kotlinx.uuid.toJavaUUID -import kotlinx.uuid.toKotlinUUID import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.transactions.transaction @@ -22,10 +20,10 @@ object Web3WalletAccountStrategy : AccountStrategy { val accountId = Accounts.insert { it[Accounts.name] = name it[createdOn] = Clock.System.now().toJavaInstant() - }[Accounts.id].value.toKotlinUUID() + }[Accounts.id].value Web3Wallets.insert { - it[account] = accountId.toJavaUUID() + it[account] = accountId it[address] = request.address it[ecosystem] = request.ecosystem it[owner] = false diff --git a/src/main/kotlin/id/walt/service/credentials/CredentialsService.kt b/src/main/kotlin/id/walt/service/credentials/CredentialsService.kt index 344dc66..f51d4b0 100644 --- a/src/main/kotlin/id/walt/service/credentials/CredentialsService.kt +++ b/src/main/kotlin/id/walt/service/credentials/CredentialsService.kt @@ -5,7 +5,6 @@ import id.walt.db.models.WalletCredentials import kotlinx.datetime.Clock import kotlinx.datetime.toJavaInstant import kotlinx.uuid.UUID -import kotlinx.uuid.toJavaUUID import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.batchInsert @@ -15,19 +14,19 @@ import org.jetbrains.exposed.sql.transactions.transaction object CredentialsService { fun get(wallet: UUID, credentialId: String): WalletCredential? = transaction { - WalletCredentials.select { (WalletCredentials.wallet eq wallet.toJavaUUID()) and (WalletCredentials.id eq credentialId) } + WalletCredentials.select { (WalletCredentials.wallet eq wallet) and (WalletCredentials.id eq credentialId) } .singleOrNull()?.let { WalletCredential(it) } } fun list(wallet: UUID) = transaction { - WalletCredentials.select { WalletCredentials.wallet eq wallet.toJavaUUID() } + WalletCredentials.select { WalletCredentials.wallet eq wallet } .map { WalletCredential(it) } } fun add(wallet: UUID, vararg credentials: WalletCredential) = addAll(wallet, credentials.toList()) fun addAll(wallet: UUID, credentials: List): List = WalletCredentials.batchInsert(credentials) { credential: WalletCredential -> - this[WalletCredentials.wallet] = wallet.toJavaUUID() + this[WalletCredentials.wallet] = wallet this[WalletCredentials.id] = credential.id this[WalletCredentials.document] = credential.document this[WalletCredentials.disclosures] = credential.disclosures @@ -35,7 +34,7 @@ object CredentialsService { }.map { it[WalletCredentials.id] } fun delete(wallet: UUID, credentialId: String): Boolean = - WalletCredentials.deleteWhere { (WalletCredentials.wallet eq wallet.toJavaUUID()) and (id eq credentialId) } > 0 + WalletCredentials.deleteWhere { (WalletCredentials.wallet eq wallet) and (id eq credentialId) } > 0 /*fun update(account: UUID, did: DidUpdateDataObject): Boolean { TO-DO diff --git a/src/main/kotlin/id/walt/service/dids/DidService.kt b/src/main/kotlin/id/walt/service/dids/DidService.kt index 125501a..35e7c23 100644 --- a/src/main/kotlin/id/walt/service/dids/DidService.kt +++ b/src/main/kotlin/id/walt/service/dids/DidService.kt @@ -5,24 +5,23 @@ import id.walt.db.models.WalletDids import kotlinx.datetime.Clock import kotlinx.datetime.toJavaInstant import kotlinx.uuid.UUID -import kotlinx.uuid.toJavaUUID import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.transactions.transaction object DidsService { fun get(wallet: UUID, did: String): WalletDid? = transaction { - WalletDids.select { (WalletDids.wallet eq wallet.toJavaUUID()) and (WalletDids.did eq did) } + WalletDids.select { (WalletDids.wallet eq wallet) and (WalletDids.did eq did) } .singleOrNull()?.let { WalletDid(it) } } - fun list(wallet: UUID): List = WalletDids.select { WalletDids.wallet eq wallet.toJavaUUID() }.map { WalletDid(it) } + fun list(wallet: UUID): List = WalletDids.select { WalletDids.wallet eq wallet }.map { WalletDid(it) } fun add(wallet: UUID, did: String, document: String, keyId: String, alias: String? = null) { val now = Clock.System.now() WalletDids.insert { - it[WalletDids.wallet] = wallet.toJavaUUID() + it[WalletDids.wallet] = wallet it[WalletDids.did] = did it[WalletDids.document] = document it[WalletDids.keyId] = keyId @@ -32,23 +31,23 @@ object DidsService { } fun delete(wallet: UUID, did: String): Boolean = - WalletDids.deleteWhere { (WalletDids.wallet eq wallet.toJavaUUID()) and (WalletDids.did eq did) } > 0 + WalletDids.deleteWhere { (WalletDids.wallet eq wallet) and (WalletDids.did eq did) } > 0 fun makeDidDefault(wallet: UUID, newDefaultDid: String) { transaction { - WalletDids.update({ (WalletDids.wallet eq wallet.toJavaUUID()) and (WalletDids.default eq true) }) { + WalletDids.update({ (WalletDids.wallet eq wallet) and (WalletDids.default eq true) }) { it[default] = false } - WalletDids.update({ (WalletDids.wallet eq wallet.toJavaUUID()) and (WalletDids.did eq newDefaultDid) }) { + WalletDids.update({ (WalletDids.wallet eq wallet) and (WalletDids.did eq newDefaultDid) }) { it[default] = true } } } fun renameDid(wallet: UUID, did: String, newName: String) = - WalletDids.update({ (WalletDids.wallet eq wallet.toJavaUUID()) and (WalletDids.did eq did) }) { + WalletDids.update({ (WalletDids.wallet eq wallet) and (WalletDids.did eq did) }) { it[alias] = newName } > 0 } diff --git a/src/main/kotlin/id/walt/service/dto/LinkedWalletDataTransferObject.kt b/src/main/kotlin/id/walt/service/dto/LinkedWalletDataTransferObject.kt index 5a35e62..5e95af4 100644 --- a/src/main/kotlin/id/walt/service/dto/LinkedWalletDataTransferObject.kt +++ b/src/main/kotlin/id/walt/service/dto/LinkedWalletDataTransferObject.kt @@ -3,7 +3,6 @@ package id.walt.service.dto import id.walt.db.models.Web3Wallets import kotlinx.serialization.Serializable import kotlinx.uuid.UUID -import kotlinx.uuid.toKotlinUUID import org.jetbrains.exposed.sql.ResultRow @Serializable @@ -15,7 +14,7 @@ data class LinkedWalletDataTransferObject( ) { constructor(result: ResultRow) : this( - id = result[Web3Wallets.id].toKotlinUUID(), + id = result[Web3Wallets.id], address = result[Web3Wallets.address], ecosystem = result[Web3Wallets.ecosystem], owner = result[Web3Wallets.owner], diff --git a/src/main/kotlin/id/walt/service/keys/KeysService.kt b/src/main/kotlin/id/walt/service/keys/KeysService.kt index 5f268dc..106a5d0 100644 --- a/src/main/kotlin/id/walt/service/keys/KeysService.kt +++ b/src/main/kotlin/id/walt/service/keys/KeysService.kt @@ -5,7 +5,6 @@ import id.walt.db.models.WalletKeys import kotlinx.datetime.Clock import kotlinx.datetime.toJavaInstant import kotlinx.uuid.UUID -import kotlinx.uuid.toJavaUUID import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.deleteWhere @@ -15,22 +14,22 @@ import org.jetbrains.exposed.sql.transactions.transaction object KeysService { fun get(wallet: UUID, keyId: String): WalletKey? = transaction { - WalletKeys.select { (WalletKeys.wallet eq wallet.toJavaUUID()) and (WalletKeys.keyId eq keyId) } + WalletKeys.select { (WalletKeys.wallet eq wallet) and (WalletKeys.keyId eq keyId) } .singleOrNull()?.let { WalletKey(it) } } - fun list(wallet: UUID): List = WalletKeys.select { WalletKeys.wallet eq wallet.toJavaUUID() }.map { WalletKey(it) } + fun list(wallet: UUID): List = WalletKeys.select { WalletKeys.wallet eq wallet }.map { WalletKey(it) } fun add(wallet: UUID, keyId: String, document: String) = WalletKeys.insert { - it[WalletKeys.wallet] = wallet.toJavaUUID() + it[WalletKeys.wallet] = wallet it[WalletKeys.keyId] = keyId it[WalletKeys.document] = document it[createdOn] = Clock.System.now().toJavaInstant() }[WalletKeys.keyId] fun delete(wallet: UUID, keyId: String): Boolean = - WalletKeys.deleteWhere { (WalletKeys.wallet eq wallet.toJavaUUID()) and (WalletKeys.keyId eq keyId) } > 0 + WalletKeys.deleteWhere { (WalletKeys.wallet eq wallet) and (WalletKeys.keyId eq keyId) } > 0 /*fun update(wallet: UUID, key: DbKey): Boolean { TO-DO diff --git a/src/main/kotlin/id/walt/service/nft/NftKitNftService.kt b/src/main/kotlin/id/walt/service/nft/NftKitNftService.kt index b3b058a..29fce68 100644 --- a/src/main/kotlin/id/walt/service/nft/NftKitNftService.kt +++ b/src/main/kotlin/id/walt/service/nft/NftKitNftService.kt @@ -9,7 +9,6 @@ import id.walt.service.dto.* import id.walt.service.nft.fetchers.DataFetcher import id.walt.service.nft.fetchers.parameters.* import kotlinx.uuid.UUID -import kotlinx.uuid.toJavaUUID import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.transactions.transaction @@ -83,7 +82,7 @@ class NftKitNftService : NftService { private fun getWalletById(accountId: String) = getWalletById(UUID(accountId)) private fun getWalletById(accountId: UUID) = - transaction { Web3Wallets.select { Web3Wallets.account eq accountId.toJavaUUID() }.firstOrNull() }?.let { + transaction { Web3Wallets.select { Web3Wallets.account eq accountId }.firstOrNull() }?.let { WalletDataTransferObject(address = it[Web3Wallets.address], ecosystem = it[Web3Wallets.ecosystem]) } } diff --git a/src/main/kotlin/id/walt/service/oidc4vc/TestCredentialWallet.kt b/src/main/kotlin/id/walt/service/oidc4vc/TestCredentialWallet.kt index 6a1ded5..e99d9c1 100644 --- a/src/main/kotlin/id/walt/service/oidc4vc/TestCredentialWallet.kt +++ b/src/main/kotlin/id/walt/service/oidc4vc/TestCredentialWallet.kt @@ -111,7 +111,7 @@ class TestCredentialWallet( val selectedCredentials = HACK_outsideMappedSelectedCredentialsPerSession[session.authorizationRequest!!.state + session.authorizationRequest.presentationDefinition]!! val selectedDisclosures = - HACK_outsideMappedSelectedDisclosuresPerSession[session.authorizationRequest!!.state + session.authorizationRequest.presentationDefinition] + HACK_outsideMappedSelectedDisclosuresPerSession[session.authorizationRequest.state + session.authorizationRequest.presentationDefinition] println("Selected credentials: $selectedCredentials") val matchedCredentials = walletService.getCredentialsByIds(selectedCredentials) diff --git a/src/main/kotlin/id/walt/web/controllers/AuthController.kt b/src/main/kotlin/id/walt/web/controllers/AuthController.kt index f748078..2cd2bab 100644 --- a/src/main/kotlin/id/walt/web/controllers/AuthController.kt +++ b/src/main/kotlin/id/walt/web/controllers/AuthController.kt @@ -29,7 +29,6 @@ import kotlinx.serialization.json.JsonPrimitive import kotlinx.serialization.json.buildJsonObject import kotlinx.uuid.SecureRandom import kotlinx.uuid.UUID -import kotlinx.uuid.toJavaUUID import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.transactions.transaction @@ -248,8 +247,8 @@ fun PipelineContext.getUsersSessionToken(): String? = fun getNftService() = WalletServiceManager.getNftService() fun PipelineContext.ensurePermissionsForWallet(required: AccountWalletPermissions): Boolean { - val userId = getUserUUID().toJavaUUID() - val walletId = getWalletId().toJavaUUID() + val userId = getUserUUID() + val walletId = getWalletId() val permissions = transaction { (AccountWalletMappings.select { (AccountWalletMappings.account eq userId) and (AccountWalletMappings.wallet eq walletId) }