-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: polymorphic hierarchy for ClaimsQuery and CredentialMetadataAndV…
…alidityConstraints
- Loading branch information
1 parent
656d003
commit 6652346
Showing
11 changed files
with
729 additions
and
344 deletions.
There are no files selected for viewing
791 changes: 561 additions & 230 deletions
791
vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLClaimsQuery.kt
Large diffs are not rendered by default.
Oops, something went wrong.
28 changes: 12 additions & 16 deletions
28
...mmonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLClaimsQuerySerializer.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 |
---|---|---|
@@ -1,20 +1,16 @@ | ||
package at.asitplus.wallet.lib.data.oidc.oid4vp.dcql | ||
|
||
import at.asitplus.signum.indispensable.io.TransformingSerializerTemplate | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.json.JsonObject | ||
import kotlinx.serialization.DeserializationStrategy | ||
import kotlinx.serialization.json.JsonContentPolymorphicSerializer | ||
import kotlinx.serialization.json.JsonElement | ||
import kotlinx.serialization.json.jsonObject | ||
|
||
object DCQLClaimsQuerySerializer : | ||
KSerializer<DCQLClaimsQuery> by TransformingSerializerTemplate<DCQLClaimsQuery, JsonObject>( | ||
parent = JsonObject.serializer(), | ||
encodeAs = { | ||
when (it) { | ||
is DCQLClaimsQuery.Reader -> it.jsonObject | ||
is DCQLClaimsQuery.Builder -> it.jsonObject | ||
is DCQLClaimsQuery.Extension -> throw IllegalStateException("Instance must be a reader or a builder.") | ||
} | ||
}, | ||
decodeAs = { | ||
DCQLClaimsQuery.Reader.Instance(it) | ||
object DCQLClaimsQuerySerializer : JsonContentPolymorphicSerializer<DCQLClaimsQuery>(DCQLClaimsQuery::class) { | ||
override fun selectDeserializer(element: JsonElement): DeserializationStrategy<DCQLClaimsQuery> { | ||
val parameters = element.jsonObject | ||
return when { | ||
DCQLIsoMdocClaimsQuery.SerialNames.NAMESPACE in parameters || DCQLIsoMdocClaimsQuery.SerialNames.CLAIM_NAME in parameters -> DCQLIsoMdocClaimsQuery.serializer() | ||
else -> DCQLJsonClaimsQuery.serializer() | ||
} | ||
) | ||
} | ||
} |
23 changes: 1 addition & 22 deletions
23
...asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLCredentialMetadataAndValidityConstraints.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
32 changes: 14 additions & 18 deletions
32
...allet/lib/data/oidc/oid4vp/dcql/DCQLCredentialMetadataAndValidityConstraintsSerializer.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 |
---|---|---|
@@ -1,23 +1,19 @@ | ||
package at.asitplus.wallet.lib.data.oidc.oid4vp.dcql | ||
|
||
import at.asitplus.signum.indispensable.io.TransformingSerializerTemplate | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.json.JsonObject | ||
import kotlinx.serialization.DeserializationStrategy | ||
import kotlinx.serialization.json.JsonContentPolymorphicSerializer | ||
import kotlinx.serialization.json.JsonElement | ||
import kotlinx.serialization.json.jsonObject | ||
|
||
object DCQLCredentialMetadataAndValidityConstraintsSerializer : | ||
KSerializer<DCQLCredentialMetadataAndValidityConstraints> by TransformingSerializerTemplate<DCQLCredentialMetadataAndValidityConstraints, JsonObject>( | ||
parent = JsonObject.serializer(), | ||
encodeAs = { | ||
when (it) { | ||
is DCQLCredentialMetadataAndValidityConstraints.Reader -> it.jsonObject | ||
is DCQLCredentialMetadataAndValidityConstraints.Builder -> it.jsonObject | ||
|
||
is DCQLCredentialMetadataAndValidityConstraints.Extension -> { | ||
throw IllegalStateException("Instance must be a reader or a builder.") | ||
} | ||
} | ||
}, | ||
decodeAs = { | ||
DCQLCredentialMetadataAndValidityConstraints.Reader.Instance(it) | ||
JsonContentPolymorphicSerializer<DCQLCredentialMetadataAndValidityConstraints>( | ||
DCQLCredentialMetadataAndValidityConstraints::class | ||
) { | ||
override fun selectDeserializer(element: JsonElement): DeserializationStrategy<DCQLCredentialMetadataAndValidityConstraints> { | ||
val parameters = element.jsonObject | ||
return when { | ||
DCQLIsoMdocCredentialMetadataAndValidityConstraints.SerialNames.DOCTYPE_VALUE in parameters -> DCQLIsoMdocCredentialMetadataAndValidityConstraints.serializer() | ||
else -> throw IllegalArgumentException("Deserializer not found") | ||
} | ||
) | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
.../commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLIsoMdocClaimsQuery.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,39 @@ | ||
package at.asitplus.wallet.lib.data.oidc.oid4vp.dcql | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable(with = DCQLIsoMdocClaimsQuerySerializer::class) | ||
sealed interface DCQLIsoMdocClaimsQuery : DCQLClaimsQuery { | ||
/** | ||
* OID4VP draft 23: namespace: REQUIRED if the Credential Format is based on the mdoc format | ||
* defined in [ISO.18013-5]; MUST NOT be present otherwise. The value MUST be a string that | ||
* specifies the namespace of the data element within the mdoc, e.g., org.iso.18013.5.1. | ||
*/ | ||
val namespace: String? | ||
|
||
/** | ||
* OID4VP draft 23: claim_name: REQUIRED if the Credential Format is based on mdoc format | ||
* defined in [ISO.18013-5]; MUST NOT be present otherwise. The value MUST be a string that | ||
* specifies the data element identifier of the data element within the provided namespace in | ||
* the mdoc, e.g., first_name. | ||
*/ | ||
val claimName: String? | ||
|
||
object SerialNames { | ||
const val NAMESPACE = "namespace" | ||
const val CLAIM_NAME = "claim_name" | ||
} | ||
|
||
@Serializable | ||
data class Instance( | ||
@SerialName(DCQLClaimsQuery.SerialNames.ID) | ||
override val id: DCQLCredentialQueryIdentifier?, | ||
@SerialName(DCQLClaimsQuery.SerialNames.VALUES) | ||
override val values: List<DCQLExpectedClaimValue>?, | ||
@SerialName(SerialNames.NAMESPACE) | ||
override val namespace: String? = null, | ||
@SerialName(SerialNames.CLAIM_NAME) | ||
override val claimName: String? = null, | ||
) : DCQLIsoMdocClaimsQuery | ||
} |
12 changes: 12 additions & 0 deletions
12
...n/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLIsoMdocClaimsQuerySerializer.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,12 @@ | ||
package at.asitplus.wallet.lib.data.oidc.oid4vp.dcql | ||
|
||
import kotlinx.serialization.DeserializationStrategy | ||
import kotlinx.serialization.json.JsonContentPolymorphicSerializer | ||
import kotlinx.serialization.json.JsonElement | ||
|
||
object DCQLIsoMdocClaimsQuerySerializer : | ||
JsonContentPolymorphicSerializer<DCQLIsoMdocClaimsQuery>(DCQLIsoMdocClaimsQuery::class) { | ||
override fun selectDeserializer(element: JsonElement): DeserializationStrategy<DCQLIsoMdocClaimsQuery> { | ||
return DCQLIsoMdocClaimsQuery.Instance.serializer() | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
...ib/data/oidc/oid4vp/dcql/DCQLIsoMdocCredentialMetadataAndValidityConstraintsSerializer.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,14 @@ | ||
package at.asitplus.wallet.lib.data.oidc.oid4vp.dcql | ||
|
||
import kotlinx.serialization.DeserializationStrategy | ||
import kotlinx.serialization.json.JsonContentPolymorphicSerializer | ||
import kotlinx.serialization.json.JsonElement | ||
|
||
object DCQLIsoMdocCredentialMetadataAndValidityConstraintsSerializer : | ||
JsonContentPolymorphicSerializer<DCQLIsoMdocCredentialMetadataAndValidityConstraints>( | ||
DCQLIsoMdocCredentialMetadataAndValidityConstraints::class | ||
) { | ||
override fun selectDeserializer(element: JsonElement): DeserializationStrategy<DCQLIsoMdocCredentialMetadataAndValidityConstraints> { | ||
return DCQLIsoMdocCredentialMetadataAndValidityConstraints.Instance.serializer() | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLJsonClaimsQuery.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,29 @@ | ||
package at.asitplus.wallet.lib.data.oidc.oid4vp.dcql | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable(with = DCQLJsonClaimsQuerySerializer::class) | ||
interface DCQLJsonClaimsQuery : DCQLClaimsQuery { | ||
/** | ||
* OID4VP draft 23: path: REQUIRED if the Credential Format uses a JSON-based claims structure | ||
* (e.g., IETF SD-JWT VC and W3C Verifiable Credentials); MUST NOT be present otherwise. The | ||
* value MUST be a non-empty array representing a claims path pointer that specifies the path | ||
* to a claim within the Verifiable Credential, as defined in Section 6.4. | ||
*/ | ||
val path: DCQLClaimsPathPointer? | ||
|
||
object SerialNames { | ||
const val PATH = "path" | ||
} | ||
|
||
@Serializable | ||
data class Instance( | ||
@SerialName(DCQLClaimsQuery.SerialNames.ID) | ||
override val id: DCQLCredentialQueryIdentifier?, | ||
@SerialName(DCQLClaimsQuery.SerialNames.VALUES) | ||
override val values: List<DCQLExpectedClaimValue>?, | ||
@SerialName(SerialNames.PATH) | ||
override val path: DCQLClaimsPathPointer?, | ||
) : DCQLJsonClaimsQuery | ||
} |
12 changes: 12 additions & 0 deletions
12
...Main/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLJsonClaimsQuerySerializer.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,12 @@ | ||
package at.asitplus.wallet.lib.data.oidc.oid4vp.dcql | ||
|
||
import kotlinx.serialization.DeserializationStrategy | ||
import kotlinx.serialization.json.JsonContentPolymorphicSerializer | ||
import kotlinx.serialization.json.JsonElement | ||
|
||
object DCQLJsonClaimsQuerySerializer : JsonContentPolymorphicSerializer<DCQLJsonClaimsQuery>( | ||
DCQLJsonClaimsQuery::class) { | ||
override fun selectDeserializer(element: JsonElement): DeserializationStrategy<DCQLJsonClaimsQuery> { | ||
return DCQLJsonClaimsQuery.Instance.serializer() | ||
} | ||
} |
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