Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/oidf 65 2 #44

Merged
merged 148 commits into from
Nov 13, 2024
Merged
Changes from 1 commit
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
2105846
feat: Implemented KMS, JWKS generation and JWT sign
Jul 12, 2024
b3f03c1
fix: Test dependencies
Jul 12, 2024
14c6a80
feat: Created sign and verify jwt functions
Jul 17, 2024
6b0a610
refactor: Added trailing new line to the files
Jul 17, 2024
d5c34e9
fix: Removed some targets temporarily to fix build issues.
Jul 18, 2024
440300c
refactor: made the second paramenter of functions a Map without defau…
Jul 23, 2024
bfb9cd9
Merge branch 'develop' of github.com:Sphereon-Opensource/OpenID-Feder…
Jul 23, 2024
859d788
refactor: Fixed build issues and removed commented-out code
Jul 23, 2024
3fb5bb6
fix: Fixed failing test and null pointer exception
Jul 23, 2024
56ad998
chore: Removed redundant HTTPCache
Jul 30, 2024
7bd61ba
chore: Uncommented ios targets back
Jul 30, 2024
6aec24c
refactor: refactored serializeNullable()
Jul 30, 2024
3ed536d
refactor: refactored deserialize()
Jul 30, 2024
dc19f4c
refactor: refactored OutgoingEntityStatementContent.bytes()
Jul 30, 2024
c7537cd
refactor: refactored the tests to use assertEquals()
Jul 30, 2024
3321a0b
Merge branch 'develop' of github.com:/Sphereon-Opensource/OpenID-Fede…
Jul 30, 2024
4222e59
refactor: Fixed dependencies and made the protectedHeader a param
Jul 30, 2024
bc3ecc8
refactor: Fixed code formatting
Jul 30, 2024
fe0df4c
Merge branch 'develop' of github.com:/Sphereon-Opensource/OpenID-Fede…
Jul 30, 2024
8e55b2e
refactor: Changed the response body to jwt string
Jul 31, 2024
0354192
Merge branch 'refs/heads/develop' into feature/OIDF-7
Jul 31, 2024
c7b90d3
refactor: Removed unnecessary converter
Jul 31, 2024
db8e116
refactor: Made JWT payload and header classes to be used as input
Aug 2, 2024
4848ba3
fix: add missing repositories for windows (#22)
jcmelati Aug 5, 2024
44dbf40
feat: implement jwk persistence
jcmelati Aug 6, 2024
25c1752
fix: remove unused statement
jcmelati Aug 6, 2024
2346fb6
fix: github CI
jcmelati Aug 6, 2024
a4c56ff
Merge branch 'feature/OIDF-42' into feature/OIDF-54
jcmelati Aug 6, 2024
0052c3c
feat/OIDF-51 - Implement Persistence Module (#21)
jcmelati Aug 6, 2024
01c7152
fix: add missing entity to openapi spec
jcmelati Aug 6, 2024
8661c36
Merge branch 'feature/OIDF-54' of github.com:Sphereon-Opensource/Open…
jcmelati Aug 6, 2024
7fc6982
feat: persist generated keys
jcmelati Aug 6, 2024
9d0f0e8
fix: typo
jcmelati Aug 6, 2024
ce0d261
fix: missing deps
jcmelati Aug 7, 2024
3114595
fix: ci docker command
jcmelati Aug 7, 2024
e754b13
fix: dependency
jcmelati Aug 7, 2024
5091d9c
fix: remove unnecessary statement
jcmelati Aug 7, 2024
428401c
feat: abstract jwk to its own module
jcmelati Aug 7, 2024
f246023
Merge branch 'refs/heads/feature/OIDF-42' into feature/OIDF-53
Aug 7, 2024
b948001
chore: Trust Chain validation implementation
Aug 8, 2024
3321886
feat: encrypt private keys when saving to database
jcmelati Aug 12, 2024
a26cd53
feat: add note to README regarding usage of Local KMS in prod envs
jcmelati Aug 12, 2024
dd242a3
fix: adapt key encryption test cases for when APP_KEY is null
jcmelati Aug 12, 2024
979d4cf
fix: adjust function name
jcmelati Aug 12, 2024
aaa8914
fix: add kotlin-js-store to gitignore
jcmelati Aug 12, 2024
1787ee6
fix: clean common gradle file
jcmelati Aug 12, 2024
7a58f32
fix: disable android build
jcmelati Aug 12, 2024
168a824
merge feature/OIDF-7
jcmelati Aug 13, 2024
1337271
Merge branch 'feature/OIDF-54' of github.com:/Sphereon-Opensource/Ope…
Aug 13, 2024
75faa9e
fix: Fixed merging issues
Aug 13, 2024
8f2a3da
fix: Fixed coroutine issue
Aug 13, 2024
a278819
fix: Fixed build trust chain
Aug 14, 2024
97a4270
fix: Fixed response headers
Aug 14, 2024
66b7df2
chore: Build the trust chain
Aug 19, 2024
6f208d7
Merge remote-tracking branch 'origin/develop' into feature/OIDF-53
Sep 16, 2024
54485ae
refactor: Adjusted the trust chain validation to the models
Sep 17, 2024
7976c4f
refactor: Adjusted the trust chain validation with the local-kms and …
Sep 17, 2024
7d04028
refactor: Removed service jvm folders and files
Sep 17, 2024
a5876ea
chore: Added trust chain structure test
Sep 18, 2024
dea053c
refactor: Renamed op folder to validation
Sep 18, 2024
37f0d65
chore: Added trust chain validation test
Sep 18, 2024
5cffd45
chore: Added support to Subordinate Statements
Sep 19, 2024
599c984
chore: Trust Chain Validation refactoring - Separate Entity Configura…
Sep 25, 2024
7d2ce75
chore: Trust Chain Validation refactoring - Build Trust Chain for tes…
Sep 26, 2024
cceb968
chore: Trust Chain Validation refactoring - Enabled JS in local-kms m…
Sep 26, 2024
69f0fdd
chore: Trust Chain Validation refactoring - Moved client to its own m…
Sep 29, 2024
e004a3b
chore: Trust Chain Validation fixed broken tests -
Oct 1, 2024
bbeddd4
chore: Added jwk and jwt folder to openid-federation-common
Oct 1, 2024
616eb6c
chore: Fixed jsMain module and implemented tests
Oct 2, 2024
c2d31fc
chore: Moved most part of the code to the common module
Oct 3, 2024
a419a02
refactor: Moved retrieveJwk function to commonMain
Oct 3, 2024
1c90e8d
refactor: Created JWT service that accepts callbacks and adjusted the…
Oct 4, 2024
371223f
feat: implement resolve trust chain
jcmelati Oct 8, 2024
f5a9260
fix: clean object mapping
jcmelati Oct 8, 2024
ba07acf
fix: remove constraints temporarily
jcmelati Oct 8, 2024
5d203dd
fix: extend trust chain build test
jcmelati Oct 8, 2024
d7232ae
fix: trust chain resolve method
jcmelati Oct 8, 2024
bc98bd5
fix: get http engine automatically if none informed
jcmelati Oct 9, 2024
53783df
feat: extract helper functions
jcmelati Oct 10, 2024
e8c1526
feat: pass fetchservice as param
jcmelati Oct 10, 2024
8898326
fix: ci
jcmelati Oct 10, 2024
3f39adf
fix: js test
jcmelati Oct 10, 2024
dccc21e
fix: fetch initialization
jcmelati Oct 11, 2024
ee79d7a
feat: implement client class
jcmelati Oct 11, 2024
5a85d7b
fix: oid client js export
jcmelati Oct 12, 2024
1c32dee
fix: fetch class
jcmelati Oct 12, 2024
6ef465c
fix: indentation
jcmelati Oct 12, 2024
39e008c
fix: js validateTrustChain return type
jcmelati Oct 12, 2024
d19e7c9
fix: resolve trust chain method name
jcmelati Oct 12, 2024
846a333
feat: implement crypto module in client
jcmelati Oct 16, 2024
038d10d
feat: implement js verify function callback in test
jcmelati Oct 16, 2024
fa52718
fix: openapi jwk spec
jcmelati Oct 16, 2024
279b5ea
fix: implement reference time on verify test
jcmelati Oct 16, 2024
48ed622
fix: code cleanup
jcmelati Oct 16, 2024
3e58f4a
fix: clean tests
jcmelati Oct 16, 2024
ee1494c
fix: code cleanup
jcmelati Oct 16, 2024
a8b0733
fix: move logger to own module
jcmelati Oct 17, 2024
4c413c9
fix: make Trustchain a class to simplify dep injection
jcmelati Oct 17, 2024
2fa41b4
fix: verify function
jcmelati Oct 19, 2024
ae0d0f3
fix: refactor helpers
jcmelati Oct 19, 2024
80941c1
fix: refactor
jcmelati Oct 19, 2024
2d638d2
fix: refactor
jcmelati Oct 19, 2024
7830b0b
fix: reorder authority hints to process trust anchors first
jcmelati Oct 20, 2024
7ea3fd5
fix: add maxDepth parameter to trust chain resolution
jcmelati Oct 20, 2024
d768513
fix: merge develop
jcmelati Oct 20, 2024
9f1d298
fix: refactor jwk model structure
jcmelati Oct 20, 2024
ec4d470
fix: subordinate jwks
jcmelati Oct 20, 2024
9f4d181
fix: export ICryptoServiceCallback to JS
jcmelati Oct 21, 2024
f4d4a9f
fix: pass callback constructors to oidf client js
jcmelati Oct 22, 2024
2e339ef
chore: docker production updates
sanderPostma Oct 23, 2024
87aaf6c
chore: docker production updates
sanderPostma Oct 23, 2024
75f2585
chore: docker production updates
sanderPostma Oct 23, 2024
682bee6
chore: revert docker compose ports updates
sanderPostma Oct 23, 2024
bebef87
refactor: Refactored OIDF-Client according to mdoc-cbor-crypto-multip…
Oct 24, 2024
01c5248
fixed: Fixed general bugs
Oct 24, 2024
5b1a6f9
refactor: Picking common dependencies from libs.versions.toml
Oct 25, 2024
4befac1
refactor: Moved the trust chain to a callback
Oct 25, 2024
a987de5
refactor: Created js tests
Oct 27, 2024
88d43fb
refactor: Created tests for jvm and js in their respective folders
Oct 27, 2024
7b8df9f
fix: Libraries compatibility: openapi generator, kotlinx coroutines a…
Oct 27, 2024
441b090
fix: Fixed issues with the implementation of the Default Trust Chain …
Oct 28, 2024
cbcbad3
refactor: Removed println(...)
Oct 28, 2024
ea60a40
refactor: Added the rest of the libraries to libs.versions.toml
Oct 28, 2024
30918d1
chore: adding publishing configs
sanderPostma Oct 28, 2024
c4270bd
Merge branch 'feature/OIDF-65-2' into feature/ci-publishing
sanderPostma Oct 28, 2024
ed4136a
chore: adding publishing configs
sanderPostma Oct 28, 2024
4b8863b
chore: reverted db ports in compose
sanderPostma Oct 28, 2024
91916eb
chore: fixed NEXUS_USERNAME env var
sanderPostma Oct 28, 2024
ac0e765
chore: fixed NPM_TOKEN env var
sanderPostma Oct 28, 2024
104e03b
chore: open-api package rename due to npm issues
sanderPostma Oct 28, 2024
b20a846
fix: Fixed the mangled filed names in JS
Oct 28, 2024
2a3ea1d
chore: also publish openid-federation-client
sanderPostma Oct 28, 2024
9bc7453
chore: added Default fetch service
Oct 29, 2024
9519ad6
chore: added generateTypeScriptDefinitions
sanderPostma Oct 29, 2024
151480d
Merge remote-tracking branch 'origin/feature/OIDF-65-2' into feature/…
sanderPostma Oct 29, 2024
3655855
Merge pull request #41 from Sphereon-Opensource/feature/docker-prod
sanderPostma Oct 29, 2024
c12610c
Merge pull request #42 from Sphereon-Opensource/feature/ci-publishing
sanderPostma Oct 29, 2024
fb3fc6e
feat: adjust federation fetch endpoint to new spec without iss param
jcmelati Oct 30, 2024
659d514
fix: subordinate statement source endpoint
jcmelati Nov 1, 2024
df071b9
Merge remote-tracking branch 'origin/develop' into feature/OIDF-65-2
sanderPostma Nov 4, 2024
40e6ff4
chore: docker prod-deployment fixes
sanderPostma Nov 4, 2024
233a5b4
chore: Base64.UrlSafe.decode
sanderPostma Nov 5, 2024
1c47225
chore: debug version
sanderPostma Nov 5, 2024
d653be4
chore: revert test
sanderPostma Nov 5, 2024
287e36c
chore: AcceptCharset test version
sanderPostma Nov 5, 2024
c79dcb7
chore: log fetchStatement returned
sanderPostma Nov 5, 2024
8663d94
chore: cleanup
sanderPostma Nov 5, 2024
e0c56b5
fix merge conflicts
jcmelati Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: Refactored OIDF-Client according to mdoc-cbor-crypto-multip…
…latform
  • Loading branch information
Zoe Maas committed Oct 24, 2024
commit bebef87a314308d4959db0c6bc44e8ed6add5d4a
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
package com.sphereon.oid.fed.common.logging
package com.sphereon.oid.fed.logger

import co.touchlab.kermit.Logger
import co.touchlab.kermit.Severity

object Logger {

fun verbose(tag: String, message: String) {
class Logger(val tag: String = "") {
fun verbose(message: String, tag: String = this.tag) {
Logger.v(tag = tag, messageString = message)
}

fun debug(tag: String, message: String) {
fun debug(message: String, tag: String = this.tag) {
Logger.d(tag = tag, messageString = message)
}

fun info(tag: String, message: String) {
fun info(message: String, tag: String = this.tag) {
Logger.i(tag = tag, messageString = message)
}

fun warn(tag: String, message: String) {
fun warn(message: String, tag: String = this.tag) {
Logger.w(tag = tag, messageString = message)
}

fun error(tag: String, message: String, throwable: Throwable? = null) {
fun error(message: String, throwable: Throwable? = null, tag: String = this.tag) {
Logger.e(tag = tag, messageString = message, throwable = throwable)
}

fun setMinSeverity(severity: Severity) = Logger.setMinSeverity(severity)

object Static {
fun tag(tag: String = "", severity: Severity = Severity.Info) = Logger(tag).also { it.setMinSeverity(severity) }
}

}

val DefaultLogger = Logger("")
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package com.sphereon.oid.fed.client

import com.sphereon.oid.fed.client.crypto.CryptoServiceObject
import com.sphereon.oid.fed.client.crypto.ICryptoService
import com.sphereon.oid.fed.client.fetch.FetchServiceObject
import com.sphereon.oid.fed.client.fetch.IFetchService
import com.sphereon.oid.fed.client.crypto.ICryptoCallbackMarkerType
import com.sphereon.oid.fed.client.fetch.IFetchCallbackMarkerType
import com.sphereon.oid.fed.client.trustchain.TrustChain

class FederationClient(fetchServiceCallback: IFetchService?, cryptoServiceCallback: ICryptoService) {
private val fetchService = FetchServiceObject.register(fetchServiceCallback)
private val cryptoService = CryptoServiceObject.register(cryptoServiceCallback)
private val trustChainService = TrustChain(fetchService, cryptoService)
class FederationClient(fetchServiceCallback: IFetchCallbackMarkerType?, cryptoServiceCallback: ICryptoCallbackMarkerType) {
private val trustChainService = TrustChain(fetchServiceCallback, cryptoServiceCallback)

suspend fun resolveTrustChain(entityIdentifier: String, trustAnchors: Array<String>): MutableList<String>? {
return trustChainService.resolve(entityIdentifier, trustAnchors)
Original file line number Diff line number Diff line change
@@ -1,48 +1,102 @@
package com.sphereon.oid.fed.client.crypto

import com.sphereon.oid.fed.client.mapper.decodeJWTComponents
import com.sphereon.oid.fed.client.types.ICallbackService
import com.sphereon.oid.fed.client.service.DefaultCallbacks
import com.sphereon.oid.fed.client.service.ICallbackService
import com.sphereon.oid.fed.openapi.models.Jwk
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import kotlin.js.JsExport

interface ICryptoService {
expect interface ICryptoCallbackMarkerType
interface ICryptoMarkerType

@JsExport.Ignore
interface ICryptoCallbackService: ICryptoCallbackMarkerType {
suspend fun verify(
jwt: String,
key: Jwk,
): Boolean
}

interface ICryptoCallbackService : ICallbackService<ICryptoService>, ICryptoService
@JsExport.Ignore
interface ICryptoService: ICryptoMarkerType {
suspend fun verify(
jwt: String,
key: Jwk,
): Boolean
}

class DefaultPlatformCallback : ICryptoService {
override suspend fun verify(jwt: String, key: Jwk): Boolean {
return verifyImpl(jwt, key)
expect fun cryptoService(platformCallback: ICryptoCallbackMarkerType = DefaultCallbacks.jwtService()): ICryptoService

abstract class AbstractCryptoService<CallbackServiceType>(open val platformCallback: CallbackServiceType?): ICallbackService<CallbackServiceType> {
private var disabled = false

override fun isEnabled(): Boolean {
return !this.disabled
}
}

object CryptoServiceObject : ICryptoCallbackService {
private lateinit var platformCallback: ICryptoService
override fun disable() = apply {
this.disabled = true
}

override suspend fun verify(jwt: String, key: Jwk): Boolean {
if (!::platformCallback.isInitialized) {
throw IllegalStateException("CryptoServiceObject not initialized")
override fun enable() = apply {
this.disabled = false
}

protected fun assertEnabled() {
if (!isEnabled()) {
//CryptoConst.LOG.info("CRYPTO verify has been disabled")
throw IllegalStateException("CRYPTO service is disable; cannot verify")
} else if (this.platformCallback == null) {
//CryptoConst.LOG.error("CRYPTO callback is not registered")
throw IllegalStateException("CRYPTO has not been initialized. Please register your CryptoCallback implementation, or register a default implementation")
}
return platformCallback.verify(jwt, key)
}
}

class CryptoService(override val platformCallback: ICryptoCallbackService = DefaultCallbacks.jwtService()): AbstractCryptoService<ICryptoCallbackService>(platformCallback), ICryptoService {
override fun platform(): ICryptoCallbackService {
return this.platformCallback
}

override fun register(platformCallback: ICryptoService?): ICryptoCallbackService {
this.platformCallback = platformCallback ?: DefaultPlatformCallback()
return this
override suspend fun verify(jwt: String, key: Jwk): Boolean {
return this.platformCallback.verify(jwt, key)
}

}

expect fun cryptoService(): ICryptoCallbackService
// ###########################################################################


//class DefaultPlatformCallback : ICryptoCallbackService {
// override suspend fun verify(jwt: String, key: Jwk): Boolean {
// return verifyImpl(jwt, key)
// }
//}
//
//object CryptoServiceObject : ICryptoCallbackService {
// private lateinit var platformCallback: ICryptoCallbackService
//
// override suspend fun verify(jwt: String, key: Jwk): Boolean {
// if (!::platformCallback.isInitialized) {
// throw IllegalStateException("CryptoServiceObject not initialized")
// }
// return platformCallback.verify(jwt, key)
// }
//
// override fun register(platformCallback: ICryptoCallbackService?): ICryptoCallbackService {
// this.platformCallback = platformCallback ?: DefaultPlatformCallback()
// return this
// }
//}

expect suspend fun verifyImpl(jwt: String, key: Jwk): Boolean
//expect fun cryptoService(): ICryptoCallbackService
//
//expect suspend fun verifyImpl(jwt: String, key: Jwk): Boolean

fun findKeyInJwks(keys: JsonArray, kid: String): Jwk? {
val key = keys.firstOrNull { it.jsonObject["kid"]?.jsonPrimitive?.content?.trim() == kid.trim() }
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.sphereon.oid.fed.client.crypto

//import com.sphereon.oid.fed.logger

object CryptoConst {
// val LOG_NAMESPACE = "sphereon:oidf:client:crypto"
// val LOG = Logger.Static.tag(LOG_NAMESPACE)
// val CRYPTO_LITERAL = "CRYPTO"
}
Original file line number Diff line number Diff line change
@@ -1,50 +1,68 @@
package com.sphereon.oid.fed.client.fetch

import com.sphereon.oid.fed.client.types.ICallbackService
import com.sphereon.oid.fed.client.service.DefaultCallbacks
import com.sphereon.oid.fed.client.service.ICallbackService
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.request.*
import io.ktor.http.*
import kotlin.js.JsExport

expect interface IFetchCallbackMarkerType
interface IFetchMarkerType

interface IFetchService {
fun getHttpClient(): HttpClient
@JsExport.Ignore
interface IFetchCallbackService: IFetchCallbackMarkerType {
suspend fun fetchStatement(
endpoint: String
): String
suspend fun getHttpClient(): HttpClient
}

interface IFetchServiceInternal {
@JsExport.Ignore
interface IFetchService: IFetchMarkerType {
suspend fun fetchStatement(
endpoint: String
): String
suspend fun getHttpClient(): HttpClient
}

interface IFetchCallbackService : ICallbackService<IFetchService>, IFetchService, IFetchServiceInternal
expect fun fetchService(platformCallback: IFetchCallbackMarkerType = DefaultCallbacks.fetchService()): IFetchService

object FetchServiceObject : IFetchCallbackService {
private lateinit var platformCallback: IFetchService
private lateinit var httpClient: HttpClient
abstract class AbstractFetchService<CallbackServiceType>(open val platformCallback: CallbackServiceType): ICallbackService<CallbackServiceType> {
private var disabled = false

override suspend fun fetchStatement(endpoint: String): String {
return httpClient
.get(endpoint) {
headers {
append(HttpHeaders.Accept, "application/entity-statement+jwt")
}
}.body()
override fun isEnabled(): Boolean {
return !this.disabled
}

override fun getHttpClient(): HttpClient {
return this.platformCallback.getHttpClient()
override fun disable() = apply {
this.disabled = true
}

override fun enable() = apply {
this.disabled = false
}

class DefaultPlatformCallback : IFetchService {
override fun getHttpClient(): HttpClient {
return HttpClient()
protected fun assertEnabled() {
if (!isEnabled()) {
//FetchConst.LOG.info("CRYPTO verify has been disabled")
throw IllegalStateException("CRYPTO service is disable; cannot verify")
} else if (this.platformCallback == null) {
//FetchConst.LOG.error("CRYPTO callback is not registered")
throw IllegalStateException("CRYPTO has not been initialized. Please register your CryptoCallback implementation, or register a default implementation")
}
}
}

override fun register(platformCallback: IFetchService?): IFetchCallbackService {
this.platformCallback = platformCallback ?: DefaultPlatformCallback()
this.httpClient = this.platformCallback.getHttpClient()
return this
class FetchService(override val platformCallback: IFetchCallbackService = DefaultCallbacks.jwtService()): AbstractFetchService<IFetchCallbackService>(platformCallback), IFetchService {

override fun platform(): IFetchCallbackService {
return this.platformCallback
}

override suspend fun fetchStatement(endpoint: String): String {
return this.platformCallback.fetchStatement(endpoint)
}

override suspend fun getHttpClient(): HttpClient {
return this.platformCallback.getHttpClient()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.sphereon.oid.fed.client.fetch

//import com.sphereon.oid.fed.logger

object FetchConst {
// val LOG_NAMESPACE = "sphereon:oidf:client:crypto"
// val LOG = Logger.Static.tag(LOG_NAMESPACE)
// val FETCH_LITERAL = "FETCH"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.sphereon.oid.fed.client.service

import com.sphereon.oid.fed.client.crypto.ICryptoCallbackMarkerType
import com.sphereon.oid.fed.client.fetch.IFetchCallbackMarkerType
import kotlin.js.JsExport

@JsExport
object DefaultCallbacks {
private var cryptoCallbackService: ICryptoCallbackMarkerType? = null
private var fetchCallbackService: IFetchCallbackMarkerType? = null

fun <CallbackType: ICryptoCallbackMarkerType> jwtService(): CallbackType {
if (cryptoCallbackService == null) {
throw IllegalStateException("No default Crypto Platform Callback implementation was registered")
}
return cryptoCallbackService as CallbackType
}

fun setCryptoServiceDefault(cryptoCallbackService: ICryptoCallbackMarkerType?) {
this.cryptoCallbackService = cryptoCallbackService
}

fun <CallbackType: IFetchCallbackMarkerType> fetchService(): CallbackType {
if (fetchCallbackService == null) {
throw IllegalStateException("No default Crypto Platform Callback implementation was registered")
}
return fetchCallbackService as CallbackType
}

fun setFetchServiceDefault(fetchCallbackService: IFetchCallbackMarkerType?) {
this.fetchCallbackService = fetchCallbackService
}
}

/**
* The main entry point for platform validation, delegating to a platform specific callback implemented by external developers
*/

interface ICallbackService<PlatformCallbackType> {

/**
* Disable callback verification (be careful!)
*/
fun disable(): ICallbackService<PlatformCallbackType>

/**
* Enable the callback verification (default)
*/
fun enable(): ICallbackService<PlatformCallbackType>

/**
* Is the service enabled or not
*/
fun isEnabled(): Boolean

fun platform(): PlatformCallbackType
}
Loading