diff --git a/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/fetch/Fetch.kt b/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/fetch/Fetch.kt index 6dd53030..df296683 100644 --- a/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/fetch/Fetch.kt +++ b/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/fetch/Fetch.kt @@ -4,11 +4,6 @@ import io.ktor.client.* import io.ktor.client.call.* import io.ktor.client.request.* import io.ktor.http.* -import kotlinx.coroutines.Deferred -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.async -import kotlin.js.JsExport -import kotlin.jvm.JvmStatic interface ICallbackService { fun register(platformCallback: PlatformCallbackType?): ICallbackService @@ -19,27 +14,23 @@ interface IFetchService { } interface IFetchServiceInternal { - fun fetchStatement( + suspend fun fetchStatement( endpoint: String - ): Deferred + ): String } interface IFetchCallbackService : ICallbackService, IFetchService, IFetchServiceInternal -@JsExport object FetchServiceObject : IFetchCallbackService { - @JvmStatic private lateinit var platformCallback: IFetchService private lateinit var httpClient: HttpClient - override fun fetchStatement(endpoint: String): Deferred { - return GlobalScope.async { - httpClient.get(endpoint) { - headers { - append(HttpHeaders.Accept, "application/entity-statement+jwt") - } - }.body() - } + override suspend fun fetchStatement(endpoint: String): String { + return httpClient.get(endpoint) { + headers { + append(HttpHeaders.Accept, "application/entity-statement+jwt") + } + }.body() } override fun getHttpClient(): HttpClient { 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 f75a17e9..df898b69 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 @@ -36,11 +36,10 @@ class SimpleCache { ): MutableList? { val entityConfigurationJwt = - fetchService.fetchStatement(getEntityConfigurationEndpoint(entityIdentifier)).await() + fetchService.fetchStatement(getEntityConfigurationEndpoint(entityIdentifier)) val decodedEntityConfiguration = decodeJWTComponents(entityConfigurationJwt) - // need to verify JWT val entityStatement: EntityConfigurationStatement = @@ -88,7 +87,7 @@ class SimpleCache { if (cache.get(authorityConfigurationEndpoint) != null) return null val authorityEntityConfigurationJwt = - fetchService.fetchStatement(authorityConfigurationEndpoint).await() ?: return null + fetchService.fetchStatement(authorityConfigurationEndpoint) cache.put(authorityConfigurationEndpoint, authorityEntityConfigurationJwt) val authorityEntityConfiguration: EntityConfigurationStatement = @@ -105,7 +104,7 @@ class SimpleCache { val subordinateStatementEndpoint = getSubordinateStatementEndpoint(authorityEntityFetchEndpoint, entityIdentifier) - val subordinateStatementJwt = fetchService.fetchStatement(subordinateStatementEndpoint).await() + val subordinateStatementJwt = fetchService.fetchStatement(subordinateStatementEndpoint) val subordinateStatement: SubordinateStatement = mapEntityStatement(subordinateStatementJwt, SubordinateStatement::class) ?: return null