From 66523461bd582b2cefe82e647fe470fddae598f7 Mon Sep 17 00:00:00 2001 From: acrusage-iaik <139230478+acrusage-iaik@users.noreply.github.com> Date: Wed, 15 Jan 2025 13:37:04 +0100 Subject: [PATCH] Add: polymorphic hierarchy for ClaimsQuery and CredentialMetadataAndValidityConstraints --- .../data/oidc/oid4vp/dcql/DCQLClaimsQuery.kt | 791 +++++++++++++----- .../oid4vp/dcql/DCQLClaimsQuerySerializer.kt | 28 +- ...redentialMetadataAndValidityConstraints.kt | 23 +- ...etadataAndValidityConstraintsSerializer.kt | 32 +- .../oid4vp/dcql/DCQLIsoMdocClaimsQuery.kt | 39 + .../dcql/DCQLIsoMdocClaimsQuerySerializer.kt | 12 + ...redentialMetadataAndValidityConstraints.kt | 58 +- ...etadataAndValidityConstraintsSerializer.kt | 14 + .../oidc/oid4vp/dcql/DCQLJsonClaimsQuery.kt | 29 + .../dcql/DCQLJsonClaimsQuerySerializer.kt | 12 + .../data/oidc/oid4vp/dcql/ClaimsQueryTest.kt | 35 +- 11 files changed, 729 insertions(+), 344 deletions(-) create mode 100644 vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLIsoMdocClaimsQuery.kt create mode 100644 vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLIsoMdocClaimsQuerySerializer.kt create mode 100644 vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLIsoMdocCredentialMetadataAndValidityConstraintsSerializer.kt create mode 100644 vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLJsonClaimsQuery.kt create mode 100644 vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLJsonClaimsQuerySerializer.kt diff --git a/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLClaimsQuery.kt b/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLClaimsQuery.kt index 5dd34e23b..06d56f24a 100644 --- a/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLClaimsQuery.kt +++ b/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLClaimsQuery.kt @@ -1,17 +1,9 @@ package at.asitplus.wallet.lib.data.oidc.oid4vp.dcql -import at.asitplus.wallet.lib.data.oidc.oid4vp.dcql.DCQLClaimsQuery.Reader -import at.asitplus.wallet.lib.data.vckJsonSerializer -import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import kotlinx.serialization.json.JsonObject -import kotlinx.serialization.json.decodeFromJsonElement -import kotlinx.serialization.json.encodeToJsonElement -import kotlinx.serialization.json.jsonObject -import kotlin.jvm.JvmInline @Serializable(with = DCQLClaimsQuerySerializer::class) -sealed interface DCQLClaimsQuery { +interface DCQLClaimsQuery { /** * OID4VP draft 23: id: REQUIRED if claim_sets is present in the Credential Query; OPTIONAL * otherwise. A string identifying the particular claim. The value MUST be a non-empty string @@ -20,14 +12,6 @@ sealed interface DCQLClaimsQuery { */ val id: DCQLCredentialQueryIdentifier? - /** - * 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? - /** * OID4VP draft 23: values: OPTIONAL. An array of strings, integers or boolean values that * specifies the expected values of the claim. If the values property is present, the Wallet @@ -36,223 +20,570 @@ sealed interface DCQLClaimsQuery { */ val values: List? - - object SerialNames { const val ID = "id" - const val PATH = "path" const val VALUES = "values" } - - - - interface Extension : DCQLClaimsQuery - - @Serializable - sealed interface Reader : DCQLClaimsQuery { - val jsonObject: JsonObject - - @Serializable - @JvmInline - value class Instance(override val jsonObject: JsonObject) : Reader { - init { - validate(this) - } - - override val id: DCQLCredentialQueryIdentifier? - get() = jsonObject[SerialNames.ID]?.let { - vckJsonSerializer.decodeFromJsonElement(it) - } - - override val path: DCQLClaimsPathPointer? - get() = jsonObject[SerialNames.PATH]?.let { - vckJsonSerializer.decodeFromJsonElement(it) - } - - override val values: List? - get() = jsonObject[SerialNames.VALUES]?.let { - vckJsonSerializer.decodeFromJsonElement>(it) - } - } - } - - @Serializable - sealed interface Builder : DCQLClaimsQuery { - val jsonObject: JsonObject - - @Serializable - data class Instance( - @SerialName(SerialNames.ID) - override val id: DCQLCredentialQueryIdentifier?, - @SerialName(SerialNames.PATH) - override val path: DCQLClaimsPathPointer?, - @SerialName(SerialNames.VALUES) - override val values: List?, - ) : Builder { - init { - validate(this) - } - override val jsonObject: JsonObject - get() = vckJsonSerializer.encodeToJsonElement(this).jsonObject - } - } - - companion object { - fun validate(query: DCQLClaimsQuery) = query.run { - id - path - values - } - } -} - -sealed interface DCQLIsoMdocClaimsQuery : DCQLClaimsQuery.Extension { - /** - * 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" - } - - - - interface Extension : DCQLIsoMdocClaimsQuery - - @Serializable - sealed interface Reader : DCQLClaimsQuery.Reader, DCQLIsoMdocClaimsQuery { - @Serializable - @JvmInline - value class Instance( - val dcqlClaimsQueryReader: DCQLClaimsQuery.Reader, - ) : Reader, DCQLClaimsQuery.Reader by dcqlClaimsQueryReader { - init { - validate(this) - } - - constructor(jsonObject: JsonObject) : this(DCQLClaimsQuery.Reader.Instance(jsonObject)) - - override val namespace: String? - get() = jsonObject[SerialNames.NAMESPACE]?.let { - vckJsonSerializer.decodeFromJsonElement(it) - } - - override val claimName: String? - get() = jsonObject[SerialNames.CLAIM_NAME]?.let { - vckJsonSerializer.decodeFromJsonElement(it) - } - } - } - - @Serializable - sealed interface Builder : DCQLIsoMdocClaimsQuery, DCQLClaimsQuery.Builder { - @Serializable - data class Instance( - @SerialName(DCQLClaimsQuery.SerialNames.ID) - override val id: DCQLCredentialQueryIdentifier?, - @SerialName(DCQLClaimsQuery.SerialNames.PATH) - override val path: DCQLClaimsPathPointer?, - @SerialName(DCQLClaimsQuery.SerialNames.VALUES) - override val values: List?, - @SerialName(SerialNames.NAMESPACE) - override val namespace: String?, - @SerialName(SerialNames.CLAIM_NAME) - override val claimName: String?, - ) : Builder { - init { - validate(this) - } - override val jsonObject: JsonObject - get() = vckJsonSerializer.encodeToJsonElement(this).jsonObject - } - } - - companion object { - fun validate(query: DCQLIsoMdocClaimsQuery) = query.run { - DCQLClaimsQuery.validate(this) - namespace - claimName - } - } } -/* -interface DCQLIsoMdocClaimsQuery2 : 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: DCQLCredentialQueryIdentifier? - - /** - * 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 claim_name: DCQLClaimsPathPointer? - - @Serializable - data class Data( - @SerialName("id") - override val id: DCQLCredentialQueryIdentifier?, - @SerialName("path") - override val path: DCQLClaimsPathPointer?, - @SerialName("values") - override val values: List?, - @SerialName("namespace") - override val namespace: DCQLCredentialQueryIdentifier?, - @SerialName("claim_name") - override val claim_name: DCQLClaimsPathPointer?, - ) : DCQLIsoMdocClaimsQuery -} -/** - * Each entry in claims MUST be an object with the following properties: - * The ISO mdoc specific parameters to be used in the Claims Query are defined in Appendix B.3.1.2. - */ -@Serializable -data class DCQLGeneralClaimsQuery( - /** - * OID4VP draft 23: id: REQUIRED if claim_sets is present in the Credential Query; OPTIONAL - * otherwise. A string identifying the particular claim. The value MUST be a non-empty string - * consisting of alphanumeric, underscore (_) or hyphen (-) characters. Within the particular - * claims array, the same id MUST NOT be present more than once. - */ - @SerialName("id") - override val id: DCQLCredentialQueryIdentifier? = null, - - /** - * 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. - */ - @SerialName("path") - override val path: DCQLClaimsPathPointer? = null, - - /** - * OID4VP draft 23: values: OPTIONAL. An array of strings, integers or boolean values that - * specifies the expected values of the claim. If the values property is present, the Wallet - * SHOULD return the claim only if the type and value of the claim both match for at least one - * of the elements in the array. Details of the processing rules are defined in Section 6.3.1.1. - */ - @SerialName("values") - override val values: List? = null, -) : DCQLClaimsQuery - */ \ No newline at end of file +// +//@Serializable(with = DCQLClaimsQuery3Serializer::class) +//interface DCQLClaimsQuery3 { +// /** +// * Representation of originally deserialized values +// */ +// val jsonObject: JsonObject +// +// /** +// * OID4VP draft 23: id: REQUIRED if claim_sets is present in the Credential Query; OPTIONAL +// * otherwise. A string identifying the particular claim. The value MUST be a non-empty string +// * consisting of alphanumeric, underscore (_) or hyphen (-) characters. Within the particular +// * claims array, the same id MUST NOT be present more than once. +// */ +// val id: DCQLCredentialQueryIdentifier? +// get() = jsonObject[SerialNames.ID]?.let { +// vckJsonSerializer.decodeFromJsonElement(it) +// } +// +// /** +// * 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? +// get() = jsonObject[SerialNames.PATH]?.let { +// vckJsonSerializer.decodeFromJsonElement(it) +// } +// +// /** +// * OID4VP draft 23: values: OPTIONAL. An array of strings, integers or boolean values that +// * specifies the expected values of the claim. If the values property is present, the Wallet +// * SHOULD return the claim only if the type and value of the claim both match for at least one +// * of the elements in the array. Details of the processing rules are defined in Section 6.3.1.1. +// */ +// val values: List? +// get() = jsonObject[SerialNames.VALUES]?.let { +// vckJsonSerializer.decodeFromJsonElement>(it) +// } +// +// +// class Builder( +// @SerialName(SerialNames.ID) +// override val id: DCQLCredentialQueryIdentifier?, +// @SerialName(SerialNames.PATH) +// override val path: DCQLClaimsPathPointer?, +// @SerialName(SerialNames.VALUES) +// override val values: List?, +// ) : DCQLClaimsQuery3 { +// init { +// validate(this) +// } +// +// override val jsonObject: JsonObject +// get() = vckJsonSerializer.encodeToJsonElement(this).jsonObject +// } +// +// @Serializable +// @JvmInline +// value class Instance(override val jsonObject: JsonObject) : DCQLClaimsQuery3 { +// init { +// validate(this) +// } +// } +// +// companion object { +// fun validate(query: DCQLClaimsQuery3) = query.run { +// // make sure all of those are deserialized properly +// id +// path +// values +// } +// } +// +// object SerialNames { +// const val ID = "id" +// const val PATH = "path" +// const val VALUES = "values" +// } +//} +// +//object DCQLClaimsQuery3Serializer : +// JsonContentPolymorphicSerializer(DCQLClaimsQuery3::class) { +// override fun selectDeserializer(element: JsonElement): DeserializationStrategy { +// val parameters = element.jsonObject +// return when { +// DCQLIsoMdocClaimsQuery3.SerialNames.NAMESPACE in parameters -> DCQLIsoMdocClaimsQuery3.Instance.serializer() +// else -> DCQLClaimsQuery3.Instance.serializer() +// } +// } +//} +// +//sealed interface DCQLIsoMdocClaimsQuery3 : DCQLClaimsQuery3 { +// /** +// * 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? +// get() = jsonObject[SerialNames.NAMESPACE]?.let { +// vckJsonSerializer.decodeFromJsonElement(it) +// } +// +// /** +// * 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? +// get() = jsonObject[SerialNames.CLAIM_NAME]?.let { +// vckJsonSerializer.decodeFromJsonElement(it) +// } +// +// class Builder( +// @SerialName(DCQLClaimsQuery3.SerialNames.ID) +// val id: DCQLCredentialQueryIdentifier?, +// @SerialName(DCQLClaimsQuery3.SerialNames.PATH) +// val path: DCQLClaimsPathPointer?, +// @SerialName(DCQLClaimsQuery3.SerialNames.VALUES) +// val values: List?, +// @SerialName(SerialNames.NAMESPACE) +// val namespace: String? = null, +// @SerialName(SerialNames.CLAIM_NAME) +// val claimName: String? = null, +// ) { +// fun build() = DCQLClaimsQuery3.Instance( +// vckJsonSerializer.encodeToJsonElement(this).jsonObject +// ) +// } +// +// @Serializable +// @JvmInline +// value class Instance( +// override val jsonObject: JsonObject +// ) : DCQLIsoMdocClaimsQuery3 { +// init { +// validate(this) +// } +// } +// +// companion object { +// fun validate(query: DCQLIsoMdocClaimsQuery3) = query.run { +// DCQLClaimsQuery3.validate(this) +// namespace +// claimName +// } +// } +// +// object SerialNames { +// const val NAMESPACE = "namespace" +// const val CLAIM_NAME = "claim_name" +// } +//} +// +// +////@Serializable +////@JvmInline +////value class DCQLClaimsBaseQuery(override val jsonObject: JsonObject) : DCQLClaimsQuery3.Instance { +//// init { +//// validate(this) +//// } +//// +//// override val id: DCQLCredentialQueryIdentifier? +//// get() = jsonObject[SerialNames.ID]?.let { +//// vckJsonSerializer.decodeFromJsonElement(it) +//// } +//// +//// override val path: DCQLClaimsPathPointer? +//// get() = jsonObject[SerialNames.PATH]?.let { +//// vckJsonSerializer.decodeFromJsonElement(it) +//// } +//// +//// override val values: List? +//// get() = jsonObject[SerialNames.VALUES]?.let { +//// vckJsonSerializer.decodeFromJsonElement>(it) +//// } +//// +//// private class Builder( +//// @SerialName(SerialNames.ID) +//// val id: DCQLCredentialQueryIdentifier?, +//// @SerialName(SerialNames.PATH) +//// val path: DCQLClaimsPathPointer?, +//// @SerialName(SerialNames.VALUES) +//// val values: List?, +//// ) { +//// fun build() = DCQLClaimsQuery3( +//// vckJsonSerializer.encodeToJsonElement(this).jsonObject +//// ) +//// } +//// +//// companion object { +//// fun validate(query: DCQLClaimsQuery3) = query.run { +//// id +//// path +//// values +//// } +//// } +////} +//// +//// +//// @Serializable(with = DCQLClaimsQuerySerializer::class) +////sealed interface DCQLClaimsQuery { +//// /** +//// * OID4VP draft 23: id: REQUIRED if claim_sets is present in the Credential Query; OPTIONAL +//// * otherwise. A string identifying the particular claim. The value MUST be a non-empty string +//// * consisting of alphanumeric, underscore (_) or hyphen (-) characters. Within the particular +//// * claims array, the same id MUST NOT be present more than once. +//// */ +//// val id: DCQLCredentialQueryIdentifier? +//// +//// /** +//// * 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? +//// +//// /** +//// * OID4VP draft 23: values: OPTIONAL. An array of strings, integers or boolean values that +//// * specifies the expected values of the claim. If the values property is present, the Wallet +//// * SHOULD return the claim only if the type and value of the claim both match for at least one +//// * of the elements in the array. Details of the processing rules are defined in Section 6.3.1.1. +//// */ +//// val values: List? +//// +//// +//// +//// +//// object SerialNames { +//// const val ID = "id" +//// const val PATH = "path" +//// const val VALUES = "values" +//// } +//// +//// +//// +//// interface Extension : DCQLClaimsQuery +//// +//// @Serializable +//// sealed interface Reader : DCQLClaimsQuery { +//// val jsonObject: JsonObject +//// +//// @Serializable +//// @JvmInline +//// value class Instance(override val jsonObject: JsonObject) : Reader { +//// init { +//// validate(this) +//// } +//// +//// override val id: DCQLCredentialQueryIdentifier? +//// get() = jsonObject[SerialNames.ID]?.let { +//// vckJsonSerializer.decodeFromJsonElement(it) +//// } +//// +//// override val path: DCQLClaimsPathPointer? +//// get() = jsonObject[SerialNames.PATH]?.let { +//// vckJsonSerializer.decodeFromJsonElement(it) +//// } +//// +//// override val values: List? +//// get() = jsonObject[SerialNames.VALUES]?.let { +//// vckJsonSerializer.decodeFromJsonElement>(it) +//// } +//// } +//// } +//// +//// @Serializable +//// sealed interface Builder : DCQLClaimsQuery { +//// val jsonObject: JsonObject +//// +//// @Serializable +//// data class Instance( +//// @SerialName(SerialNames.ID) +//// override val id: DCQLCredentialQueryIdentifier?, +//// @SerialName(SerialNames.PATH) +//// override val path: DCQLClaimsPathPointer?, +//// @SerialName(SerialNames.VALUES) +//// override val values: List?, +//// ) : Builder { +//// init { +//// validate(this) +//// } +//// override val jsonObject: JsonObject +//// get() = vckJsonSerializer.encodeToJsonElement(this).jsonObject +//// } +//// } +//// +//// companion object { +//// fun validate(query: DCQLClaimsQuery) = query.run { +//// id +//// path +//// values +//// } +//// } +////} +//// +////sealed interface DCQLIsoMdocClaimsQuery : DCQLClaimsQuery.Extension { +//// /** +//// * 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" +//// } +//// +//// +//// +//// interface Extension : DCQLIsoMdocClaimsQuery +//// +//// @Serializable +//// sealed interface Reader : DCQLClaimsQuery.Reader, DCQLIsoMdocClaimsQuery { +//// @Serializable +//// @JvmInline +//// value class Instance( +//// val dcqlClaimsQueryReader: DCQLClaimsQuery.Reader, +//// ) : Reader, DCQLClaimsQuery.Reader by dcqlClaimsQueryReader { +//// init { +//// validate(this) +//// } +//// +//// constructor(jsonObject: JsonObject) : this(DCQLClaimsQuery.Reader.Instance(jsonObject)) +//// +//// override val namespace: String? +//// get() = jsonObject[SerialNames.NAMESPACE]?.let { +//// vckJsonSerializer.decodeFromJsonElement(it) +//// } +//// +//// override val claimName: String? +//// get() = jsonObject[SerialNames.CLAIM_NAME]?.let { +//// vckJsonSerializer.decodeFromJsonElement(it) +//// } +//// } +//// } +//// +//// @Serializable +//// sealed interface Builder : DCQLIsoMdocClaimsQuery, DCQLClaimsQuery.Builder { +//// @Serializable +//// data class Instance( +//// @SerialName(DCQLClaimsQuery.SerialNames.ID) +//// override val id: DCQLCredentialQueryIdentifier? = null, +//// @SerialName(DCQLClaimsQuery.SerialNames.PATH) +//// override val path: DCQLClaimsPathPointer? = null, +//// @SerialName(DCQLClaimsQuery.SerialNames.VALUES) +//// override val values: List? = null, +//// @SerialName(SerialNames.NAMESPACE) +//// override val namespace: String? = null, +//// @SerialName(SerialNames.CLAIM_NAME) +//// override val claimName: String? = null, +//// ) : Builder { +//// init { +//// validate(this) +//// } +//// override val jsonObject: JsonObject +//// get() = vckJsonSerializer.encodeToJsonElement(this).jsonObject +//// } +//// } +//// +//// companion object { +//// fun validate(query: DCQLIsoMdocClaimsQuery) = query.run { +//// DCQLClaimsQuery.validate(this) +//// namespace +//// claimName +//// } +//// } +////} +//// +/////* +////interface DCQLIsoMdocClaimsQuery2 : 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: DCQLCredentialQueryIdentifier? +//// +//// /** +//// * 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 claim_name: DCQLClaimsPathPointer? +//// +//// @Serializable +//// data class Data( +//// @SerialName("id") +//// override val id: DCQLCredentialQueryIdentifier?, +//// @SerialName("path") +//// override val path: DCQLClaimsPathPointer?, +//// @SerialName("values") +//// override val values: List?, +//// @SerialName("namespace") +//// override val namespace: DCQLCredentialQueryIdentifier?, +//// @SerialName("claim_name") +//// override val claim_name: DCQLClaimsPathPointer?, +//// ) : DCQLIsoMdocClaimsQuery +////} +//// +/////** +//// * Each entry in claims MUST be an object with the following properties: +//// * The ISO mdoc specific parameters to be used in the Claims Query are defined in Appendix B.3.1.2. +//// */ +////@Serializable +////data class DCQLGeneralClaimsQuery( +//// /** +//// * OID4VP draft 23: id: REQUIRED if claim_sets is present in the Credential Query; OPTIONAL +//// * otherwise. A string identifying the particular claim. The value MUST be a non-empty string +//// * consisting of alphanumeric, underscore (_) or hyphen (-) characters. Within the particular +//// * claims array, the same id MUST NOT be present more than once. +//// */ +//// @SerialName("id") +//// override val id: DCQLCredentialQueryIdentifier? = null, +//// +//// /** +//// * 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. +//// */ +//// @SerialName("path") +//// override val path: DCQLClaimsPathPointer? = null, +//// +//// /** +//// * OID4VP draft 23: values: OPTIONAL. An array of strings, integers or boolean values that +//// * specifies the expected values of the claim. If the values property is present, the Wallet +//// * SHOULD return the claim only if the type and value of the claim both match for at least one +//// * of the elements in the array. Details of the processing rules are defined in Section 6.3.1.1. +//// */ +//// @SerialName("values") +//// override val values: List? = null, +////) : DCQLClaimsQuery +//// */ +//// +////@Serializable(with = DCQLClaimsQuery2Serializer::class) +////sealed interface DCQLClaimsQuery2 { +//// val jsonObject: JsonObject +//// +//// /** +//// * OID4VP draft 23: id: REQUIRED if claim_sets is present in the Credential Query; OPTIONAL +//// * otherwise. A string identifying the particular claim. The value MUST be a non-empty string +//// * consisting of alphanumeric, underscore (_) or hyphen (-) characters. Within the particular +//// * claims array, the same id MUST NOT be present more than once. +//// */ +//// val id: DCQLCredentialQueryIdentifier? +//// +//// /** +//// * 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? +//// +//// /** +//// * OID4VP draft 23: values: OPTIONAL. An array of strings, integers or boolean values that +//// * specifies the expected values of the claim. If the values property is present, the Wallet +//// * SHOULD return the claim only if the type and value of the claim both match for at least one +//// * of the elements in the array. Details of the processing rules are defined in Section 6.3.1.1. +//// */ +//// val values: List? +//// +//// +//// +//// object SerialNames { +//// const val ID = "id" +//// const val PATH = "path" +//// const val VALUES = "values" +//// } +//// +//// +//// +//// interface Extension : DCQLClaimsQuery +//// +//// @Serializable +//// sealed interface Reader : DCQLClaimsQuery { +//// val jsonObject: JsonObject +//// +//// @Serializable +//// @JvmInline +//// value class Instance(override val jsonObject: JsonObject) : Reader { +//// init { +//// validate(this) +//// } +//// +//// override val id: DCQLCredentialQueryIdentifier? +//// get() = jsonObject[SerialNames.ID]?.let { +//// vckJsonSerializer.decodeFromJsonElement(it) +//// } +//// +//// override val path: DCQLClaimsPathPointer? +//// get() = jsonObject[SerialNames.PATH]?.let { +//// vckJsonSerializer.decodeFromJsonElement(it) +//// } +//// +//// override val values: List? +//// get() = jsonObject[SerialNames.VALUES]?.let { +//// vckJsonSerializer.decodeFromJsonElement>(it) +//// } +//// } +//// } +//// +//// @Serializable +//// sealed interface Builder : DCQLClaimsQuery { +//// val jsonObject: JsonObject +//// +//// @Serializable +//// data class Instance( +//// @SerialName(SerialNames.ID) +//// override val id: DCQLCredentialQueryIdentifier?, +//// @SerialName(SerialNames.PATH) +//// override val path: DCQLClaimsPathPointer?, +//// @SerialName(SerialNames.VALUES) +//// override val values: List?, +//// ) : Builder { +//// init { +//// validate(this) +//// } +//// override val jsonObject: JsonObject +//// get() = vckJsonSerializer.encodeToJsonElement(this).jsonObject +//// } +//// } +//// +//// companion object { +//// fun validate(query: DCQLClaimsQuery) = query.run { +//// id +//// path +//// values +//// } +//// } +////} +//// +////object DCQLClaimsQuery2Serializer : +//// KSerializer by TransformingSerializerTemplate( +//// parent = JsonObject.serializer(), +//// encodeAs = { +//// it.jsonObject +//// }, +//// decodeAs = { +//// DCQLClaimsQuery2.Reader(it) +//// DCQLClaimsQuery.Reader.Instance(it) +//// } +//// ) +// diff --git a/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLClaimsQuerySerializer.kt b/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLClaimsQuerySerializer.kt index f598ead31..2bd7d3d85 100644 --- a/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLClaimsQuerySerializer.kt +++ b/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLClaimsQuerySerializer.kt @@ -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 by TransformingSerializerTemplate( - 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::class) { + override fun selectDeserializer(element: JsonElement): DeserializationStrategy { + val parameters = element.jsonObject + return when { + DCQLIsoMdocClaimsQuery.SerialNames.NAMESPACE in parameters || DCQLIsoMdocClaimsQuery.SerialNames.CLAIM_NAME in parameters -> DCQLIsoMdocClaimsQuery.serializer() + else -> DCQLJsonClaimsQuery.serializer() } - ) \ No newline at end of file + } +} \ No newline at end of file diff --git a/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLCredentialMetadataAndValidityConstraints.kt b/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLCredentialMetadataAndValidityConstraints.kt index d4556b5b3..c6039a0fa 100644 --- a/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLCredentialMetadataAndValidityConstraints.kt +++ b/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLCredentialMetadataAndValidityConstraints.kt @@ -1,30 +1,9 @@ package at.asitplus.wallet.lib.data.oidc.oid4vp.dcql import kotlinx.serialization.Serializable -import kotlinx.serialization.json.JsonObject -import kotlin.jvm.JvmInline @Serializable(with = DCQLCredentialMetadataAndValidityConstraintsSerializer::class) -sealed interface DCQLCredentialMetadataAndValidityConstraints { - - - interface Extension : DCQLCredentialMetadataAndValidityConstraints - - sealed interface Reader : DCQLCredentialMetadataAndValidityConstraints { - val jsonObject: JsonObject - - @Serializable - @JvmInline - value class Instance(override val jsonObject: JsonObject) : Reader { - init { - validate(this) - } - } - } - - sealed interface Builder : DCQLCredentialMetadataAndValidityConstraints { - val jsonObject: JsonObject - } +interface DCQLCredentialMetadataAndValidityConstraints { companion object { fun validate(constraints: DCQLCredentialMetadataAndValidityConstraints) { diff --git a/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLCredentialMetadataAndValidityConstraintsSerializer.kt b/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLCredentialMetadataAndValidityConstraintsSerializer.kt index 63bf7d74f..6d9cff3db 100644 --- a/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLCredentialMetadataAndValidityConstraintsSerializer.kt +++ b/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLCredentialMetadataAndValidityConstraintsSerializer.kt @@ -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 by TransformingSerializerTemplate( - 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::class + ) { + override fun selectDeserializer(element: JsonElement): DeserializationStrategy { + val parameters = element.jsonObject + return when { + DCQLIsoMdocCredentialMetadataAndValidityConstraints.SerialNames.DOCTYPE_VALUE in parameters -> DCQLIsoMdocCredentialMetadataAndValidityConstraints.serializer() + else -> throw IllegalArgumentException("Deserializer not found") } - ) \ No newline at end of file + } +} \ No newline at end of file diff --git a/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLIsoMdocClaimsQuery.kt b/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLIsoMdocClaimsQuery.kt new file mode 100644 index 000000000..f5ed1243a --- /dev/null +++ b/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLIsoMdocClaimsQuery.kt @@ -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?, + @SerialName(SerialNames.NAMESPACE) + override val namespace: String? = null, + @SerialName(SerialNames.CLAIM_NAME) + override val claimName: String? = null, + ) : DCQLIsoMdocClaimsQuery +} \ No newline at end of file diff --git a/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLIsoMdocClaimsQuerySerializer.kt b/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLIsoMdocClaimsQuerySerializer.kt new file mode 100644 index 000000000..b902a97ad --- /dev/null +++ b/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLIsoMdocClaimsQuerySerializer.kt @@ -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::class) { + override fun selectDeserializer(element: JsonElement): DeserializationStrategy { + return DCQLIsoMdocClaimsQuery.Instance.serializer() + } +} \ No newline at end of file diff --git a/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLIsoMdocCredentialMetadataAndValidityConstraints.kt b/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLIsoMdocCredentialMetadataAndValidityConstraints.kt index 92953c27b..670af688c 100644 --- a/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLIsoMdocCredentialMetadataAndValidityConstraints.kt +++ b/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLIsoMdocCredentialMetadataAndValidityConstraints.kt @@ -1,17 +1,10 @@ package at.asitplus.wallet.lib.data.oidc.oid4vp.dcql -import at.asitplus.wallet.lib.data.vckJsonSerializer import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import kotlinx.serialization.json.JsonObject -import kotlinx.serialization.json.decodeFromJsonElement -import kotlinx.serialization.json.encodeToJsonElement -import kotlinx.serialization.json.jsonObject -import kotlin.jvm.JvmInline -@Serializable -sealed interface DCQLIsoMdocCredentialMetadataAndValidityConstraints : - DCQLCredentialMetadataAndValidityConstraints.Extension { +@Serializable(with = DCQLIsoMdocCredentialMetadataAndValidityConstraintsSerializer::class) +interface DCQLIsoMdocCredentialMetadataAndValidityConstraints : DCQLCredentialMetadataAndValidityConstraints { /** * OID4VP draft 23: doctype_value: OPTIONAL. String that specifies an allowed value for the * doctype of the requested Verifiable Credential. It MUST be a valid doctype identifier as @@ -23,45 +16,10 @@ sealed interface DCQLIsoMdocCredentialMetadataAndValidityConstraints : const val DOCTYPE_VALUE = "doctype_value" } + @Serializable + data class Instance( + @SerialName(SerialNames.DOCTYPE_VALUE) + override val doctypeValue: String? + ) : DCQLIsoMdocCredentialMetadataAndValidityConstraints +} - - interface Extension : DCQLIsoMdocCredentialMetadataAndValidityConstraints - - sealed interface Reader : DCQLIsoMdocCredentialMetadataAndValidityConstraints, - DCQLCredentialMetadataAndValidityConstraints.Reader { - @Serializable - @JvmInline - value class Instance(override val jsonObject: JsonObject) : Reader { - init { - validate(this) - } - - override val doctypeValue: String? - get() = jsonObject[SerialNames.DOCTYPE_VALUE]?.let { - vckJsonSerializer.decodeFromJsonElement(it) - } - } - } - - sealed interface Builder : DCQLIsoMdocCredentialMetadataAndValidityConstraints, - DCQLCredentialMetadataAndValidityConstraints.Builder { - @Serializable - data class Instance( - @SerialName(SerialNames.DOCTYPE_VALUE) - override val doctypeValue: String? - ) : Builder { - init { - validate(this) - } - override val jsonObject: JsonObject - get() = vckJsonSerializer.encodeToJsonElement(this).jsonObject - } - } - - companion object { - fun validate(constraints: DCQLIsoMdocCredentialMetadataAndValidityConstraints) = constraints.run { - DCQLCredentialMetadataAndValidityConstraints.validate(this) - doctypeValue - } - } -} \ No newline at end of file diff --git a/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLIsoMdocCredentialMetadataAndValidityConstraintsSerializer.kt b/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLIsoMdocCredentialMetadataAndValidityConstraintsSerializer.kt new file mode 100644 index 000000000..5c980e42a --- /dev/null +++ b/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLIsoMdocCredentialMetadataAndValidityConstraintsSerializer.kt @@ -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::class + ) { + override fun selectDeserializer(element: JsonElement): DeserializationStrategy { + return DCQLIsoMdocCredentialMetadataAndValidityConstraints.Instance.serializer() + } +} \ No newline at end of file diff --git a/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLJsonClaimsQuery.kt b/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLJsonClaimsQuery.kt new file mode 100644 index 000000000..8fc941553 --- /dev/null +++ b/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLJsonClaimsQuery.kt @@ -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?, + @SerialName(SerialNames.PATH) + override val path: DCQLClaimsPathPointer?, + ) : DCQLJsonClaimsQuery +} \ No newline at end of file diff --git a/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLJsonClaimsQuerySerializer.kt b/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLJsonClaimsQuerySerializer.kt new file mode 100644 index 000000000..5998e54e9 --- /dev/null +++ b/vck/src/commonMain/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/DCQLJsonClaimsQuerySerializer.kt @@ -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::class) { + override fun selectDeserializer(element: JsonElement): DeserializationStrategy { + return DCQLJsonClaimsQuery.Instance.serializer() + } +} \ No newline at end of file diff --git a/vck/src/commonTest/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/ClaimsQueryTest.kt b/vck/src/commonTest/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/ClaimsQueryTest.kt index 8ecf7ce07..2e72ad647 100644 --- a/vck/src/commonTest/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/ClaimsQueryTest.kt +++ b/vck/src/commonTest/kotlin/at/asitplus/wallet/lib/data/oidc/oid4vp/dcql/ClaimsQueryTest.kt @@ -2,16 +2,35 @@ package at.asitplus.wallet.lib.data.oidc.oid4vp.dcql import at.asitplus.wallet.lib.data.vckJsonSerializer import io.kotest.core.spec.style.FreeSpec +import io.kotest.matchers.collections.shouldHaveSize import io.kotest.matchers.shouldBe import kotlinx.serialization.json.encodeToJsonElement +import kotlinx.serialization.json.jsonObject class ClaimsQueryTest : FreeSpec({ - "building" - { - val value = DCQLIsoMdocCredentialMetadataAndValidityConstraints.Builder.Instance( - doctypeValue = "test" - ) + "building" - { + "iso" { + val value = DCQLIsoMdocClaimsQuery.Builder.Instance( + id = DCQLCredentialQueryIdentifier("test"), + path = DCQLClaimsPathPointer(listOf()), + namespace = "testNamespace", + claimName = "testClaimKey", + ) - val base: DCQLCredentialMetadataAndValidityConstraints = value - vckJsonSerializer.encodeToJsonElement(base) shouldBe vckJsonSerializer.encodeToJsonElement(value) - } -}) \ No newline at end of file + val base: DCQLClaimsQuery = value + val serialized = vckJsonSerializer.encodeToJsonElement(base) + serialized shouldBe vckJsonSerializer.encodeToJsonElement(value) + serialized.jsonObject.entries shouldHaveSize 4 + } + "sd-jwt" { + val value = DCQLSdJwtCredentialMetadataAndValidityConstraints.Builder.Instance( + vctValues = listOf("test") + ) + + val base: DCQLCredentialMetadataAndValidityConstraints = value + val serialized = vckJsonSerializer.encodeToJsonElement(base) + serialized shouldBe vckJsonSerializer.encodeToJsonElement(value) + serialized.jsonObject.entries shouldHaveSize 1 + } + } +})