From 2d638d288675c62f007b1fa545cb3ee4c233e111 Mon Sep 17 00:00:00 2001 From: John Melati Date: Sat, 19 Oct 2024 04:34:12 +0200 Subject: [PATCH] fix: refactor --- .../com/sphereon/oid/fed/client/crypto/Crypto.kt | 2 +- .../sphereon/oid/fed/client/trustchain/TrustChain.kt | 11 +---------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/crypto/Crypto.kt b/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/crypto/Crypto.kt index ff88500b..579c68d1 100644 --- a/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/crypto/Crypto.kt +++ b/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/crypto/Crypto.kt @@ -44,7 +44,7 @@ expect fun cryptoService(): ICryptoCallbackService expect suspend fun verifyImpl(jwt: String, key: Jwk): Boolean -private fun findKeyInJwks(keys: JsonArray, kid: String): Jwk? { +fun findKeyInJwks(keys: JsonArray, kid: String): Jwk? { val key = keys.firstOrNull { it.jsonObject["kid"]?.jsonPrimitive?.content?.trim() == kid.trim() } if (key == null) return null diff --git a/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/trustchain/TrustChain.kt b/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/trustchain/TrustChain.kt index b1d3d677..a3ee1c3c 100644 --- a/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/trustchain/TrustChain.kt +++ b/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/trustchain/TrustChain.kt @@ -1,6 +1,7 @@ package com.sphereon.oid.fed.client.trustchain import com.sphereon.oid.fed.client.crypto.ICryptoCallbackService +import com.sphereon.oid.fed.client.crypto.findKeyInJwks import com.sphereon.oid.fed.client.fetch.IFetchCallbackService import com.sphereon.oid.fed.client.helpers.getEntityConfigurationEndpoint import com.sphereon.oid.fed.client.helpers.getSubordinateStatementEndpoint @@ -9,8 +10,6 @@ import com.sphereon.oid.fed.client.mapper.mapEntityStatement import com.sphereon.oid.fed.openapi.models.EntityConfigurationStatement import com.sphereon.oid.fed.openapi.models.Jwk import com.sphereon.oid.fed.openapi.models.SubordinateStatement -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonArray import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.jsonArray import kotlinx.serialization.json.jsonObject @@ -41,14 +40,6 @@ class TrustChain(private val fetchService: IFetchCallbackService, private val cr } } - private fun findKeyInJwks(keys: JsonArray, kid: String): Jwk? { - val key = keys.firstOrNull { it.jsonObject["kid"]?.jsonPrimitive?.content == kid } - - if (key == null) return null - - return Json.decodeFromJsonElement(Jwk.serializer(), key) - } - private suspend fun buildTrustChainRecursive( entityIdentifier: String, trustAnchors: Array,