-
Notifications
You must be signed in to change notification settings - Fork 12
Credential Type Metadata Documents #566
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
Open
nodh
wants to merge
12
commits into
feature/typed-credential-schemes
Choose a base branch
from
feature/dynamic-credential-registry
base: feature/typed-credential-schemes
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
33e7a0b
Support extensions for SD JWT Type metadata documents
nodh c2dda27
Prepare to resolve remote type metadata documents into credential sch…
nodh a3154b9
Implement credential metadata registry
nodh 3e21cb2
Import data classes for credential schemes
nodh 546f250
Switch to dynamically defined credential schemes
nodh 8154646
Pre-load static credential scheme type metadata
nodh 37b195a
Remove submodule for mDL credential
nodh ec0274e
Fix concurrent registration of credential schemes
nodh 5af2394
Extract constants for credentials
nodh 3e3dfd2
Fix remote lookup
nodh 71b11cc
Honor integrity checks while preloading static metadata
nodh 88c16dd
Inherit VCK extensions when extending metadata
nodh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,6 +1,3 @@ | ||
| [submodule "conventions-vclib/gradle-conventions-plugin"] | ||
| path = conventions-vclib/gradle-conventions-plugin | ||
| url = https://github.com/a-sit-plus/gradle-conventions-plugin.git | ||
| [submodule "mobile-driving-licence-credential"] | ||
| path = mobile-driving-licence-credential | ||
| url = https://github.com/a-sit-plus/mobile-driving-licence-credential.git |
This file contains hidden or 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
This file contains hidden or 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
Submodule mobile-driving-licence-credential
deleted from
e7d8ac
This file contains hidden or 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
15 changes: 9 additions & 6 deletions
15
sd-jwt-type-metadata/src/commonMain/kotlin/at/asitplus/wallet/sdjwt/SdJwtTypeMetadata.kt
This file contains hidden or 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,18 +1,21 @@ | ||
| package at.asitplus.wallet.sdjwt | ||
|
|
||
| import at.asitplus.wallet.sdjwt.SdJwtTypeMetadataDefinition.SerialNames | ||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class SdJwtTypeMetadata( | ||
| @SerialName(SdJwtTypeMetadataDefinition.SerialNames.VCT) | ||
| @SerialName(SerialNames.VCT) | ||
| val vct: SdJwtVcType, | ||
| @SerialName(SdJwtTypeMetadataDefinition.SerialNames.NAME) | ||
| @SerialName(SerialNames.NAME) | ||
| val name: String? = null, | ||
| @SerialName(SdJwtTypeMetadataDefinition.SerialNames.DESCRIPTION) | ||
| @SerialName(SerialNames.DESCRIPTION) | ||
| val description: String? = null, | ||
| @SerialName(SdJwtTypeMetadataDefinition.SerialNames.DISPLAY) | ||
| @SerialName(SerialNames.DISPLAY) | ||
| val display: SdJwtTypeMetadataTypeDisplayInformationList? = null, | ||
| @SerialName(SdJwtTypeMetadataDefinition.SerialNames.CLAIMS) | ||
| @SerialName(SerialNames.CLAIMS) | ||
| val claims: SdJwtTypeMetadataClaimInformationList? = null, | ||
| ) | ||
| @SerialName(SerialNames.VCK) | ||
| val vckExtensions: SdJwtTypeMetadataVckExtensions? = null, | ||
| ) |
This file contains hidden or 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
58 changes: 58 additions & 0 deletions
58
...metadata/src/commonMain/kotlin/at/asitplus/wallet/sdjwt/SdJwtTypeMetadataVckExtensions.kt
This file contains hidden or 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,58 @@ | ||
| package at.asitplus.wallet.sdjwt | ||
|
|
||
| import kotlinx.serialization.KSerializer | ||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
| import kotlinx.serialization.descriptors.PrimitiveKind | ||
| import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
| import kotlinx.serialization.descriptors.SerialDescriptor | ||
| import kotlinx.serialization.encoding.Decoder | ||
| import kotlinx.serialization.encoding.Encoder | ||
|
|
||
| @Serializable | ||
| data class SdJwtTypeMetadataVckExtensions( | ||
| @SerialName(SerialNames.FORMAT) | ||
| val format: CredentialFormatEnum, | ||
| @SerialName(SerialNames.ISO_DOCTYPE) | ||
| val isoDocType: String? = null, | ||
| @SerialName(SerialNames.ISO_NAMESPACE) | ||
| val isoNamespace: String? = null, | ||
| @SerialName(SerialNames.VC_TYPE) | ||
| val vcType: String? = null, | ||
| ) { | ||
|
|
||
| object SerialNames { | ||
| const val ISO_DOCTYPE = "isoDocType" | ||
| const val ISO_NAMESPACE = "isoNamespace" | ||
| const val VC_TYPE = "vcType" | ||
| const val FORMAT = "format" | ||
| } | ||
|
|
||
| } | ||
|
|
||
| @Serializable(with = CredentialFormatEnum.Companion.Serializer::class) | ||
| enum class CredentialFormatEnum(val text: String) { | ||
| JWT_VC("jwt_vc_json"), | ||
| DC_SD_JWT("dc+sd-jwt"), | ||
| MSO_MDOC("mso_mdoc"); | ||
|
|
||
|
|
||
| companion object { | ||
| fun parse(text: String) = CredentialFormatEnum.entries.firstOrNull { it.text == text } | ||
|
|
||
| object Serializer : KSerializer<CredentialFormatEnum> { | ||
|
|
||
| override val descriptor: SerialDescriptor = | ||
| PrimitiveSerialDescriptor("CredentialFormatEnumSerializer", PrimitiveKind.STRING) | ||
|
|
||
| override fun serialize(encoder: Encoder, value: CredentialFormatEnum) { | ||
| encoder.encodeString(value.text) | ||
| } | ||
|
|
||
| override fun deserialize(decoder: Decoder): CredentialFormatEnum { | ||
| val text = decoder.decodeString() | ||
| return CredentialFormatEnum.parse(text) ?: throw IllegalArgumentException(text) | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
70 changes: 70 additions & 0 deletions
70
.../commonMain/kotlin/at/asitplus/wallet/lib/ktor/openid/RemoteCredentialMetadataRegistry.kt
This file contains hidden or 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,70 @@ | ||
| package at.asitplus.wallet.lib.ktor.openid | ||
|
|
||
| import at.asitplus.catching | ||
| import at.asitplus.wallet.lib.data.ConstantIndex.CredentialRepresentation | ||
| import at.asitplus.wallet.lib.data.ConstantIndex.CredentialRepresentation.SD_JWT | ||
| import at.asitplus.wallet.lib.data.CredentialMetadataLookup | ||
| import at.asitplus.wallet.lib.data.CredentialMetadataRegistry | ||
| import at.asitplus.wallet.lib.data.ResolvedCredentialMetadata | ||
| import at.asitplus.wallet.sdjwt.DelegatingSdJwtTypeMetadataDocumentResolver | ||
| import at.asitplus.wallet.sdjwt.SdJwtTypeMetadataDocumentIntegrityChecker | ||
| import at.asitplus.wallet.sdjwt.SdJwtVcType | ||
| import at.asitplus.wallet.sdjwt.W3cSubresourceIntegrityMetadata | ||
| import io.ktor.client.HttpClient | ||
| import kotlinx.serialization.json.Json | ||
| import kotlin.time.Clock | ||
|
|
||
| /** | ||
| * A [CredentialMetadataRegistry] that fetches metadata documents over HTTP, mirroring | ||
| * [at.asitplus.wallet.lib.data.StaticCredentialMetadataRegistry] but with remote retrieval. | ||
| * | ||
| * This registry **owns** the `vct -> URL` mapping ([documentUrls]); the underlying | ||
| * [KtorSdJwtTypeMetadataDocumentRetriever] is given only a lookup (`documentUrls::get`), so the mapping stays in the | ||
| * registry, not in the retriever. The same URL is reused as the resolved scheme's `schemaUri`. | ||
| * | ||
| * [documentUrls] is intentionally minimal — fill it with the known `vct`/URL pairs. The map is shared with the | ||
| * retriever, so later additions are picked up for both lookup and retrieval (incl. `extends` parents). | ||
| * | ||
| * Identifier resolution mirrors the static registry: an [aliases] entry wins; otherwise for [SD_JWT] the identifier is | ||
| * the `vct` directly. Mapping a decoupled W3C `vcType` / ISO `docType` to its `vct` needs an [aliases] entry until | ||
| * richer discovery is added. | ||
| */ | ||
| class RemoteCredentialMetadataRegistry( | ||
| httpClient: HttpClient, | ||
| clock: Clock, | ||
| /** `vct` -> hosted document URL. Owned here; fill in the known pairs. */ | ||
| val documentUrls: MutableMap<SdJwtVcType, String> = mutableMapOf(), | ||
| private val aliases: Map<CredentialMetadataLookup, SdJwtVcType> = emptyMap(), | ||
| private val integrityMetadata: Map<SdJwtVcType, W3cSubresourceIntegrityMetadata> = emptyMap(), | ||
| json: Json = Json.Default, | ||
| integrityChecker: SdJwtTypeMetadataDocumentIntegrityChecker = SdJwtTypeMetadataDocumentIntegrityChecker.DEFAULT, | ||
| ) : CredentialMetadataRegistry { | ||
|
|
||
| private val resolver = DelegatingSdJwtTypeMetadataDocumentResolver( | ||
| documentRetriever = KtorSdJwtTypeMetadataDocumentRetriever( | ||
| httpClient = httpClient, | ||
| clock = clock, | ||
| locateUrl = documentUrls::get, | ||
| json = json, | ||
| integrityChecker = integrityChecker, | ||
| ), | ||
| integrityChecker = integrityChecker, | ||
| ) | ||
|
|
||
| override suspend fun findEntry( | ||
| identifier: String, | ||
| representation: CredentialRepresentation, | ||
| ): ResolvedCredentialMetadata? { | ||
| val vct = aliases[CredentialMetadataLookup(representation, identifier)] | ||
| ?: SdJwtVcType(identifier).takeIf { representation == SD_JWT && documentUrls.containsKey(it) } | ||
| ?: return null | ||
| val loadedFrom = documentUrls[vct] ?: return null | ||
| // Return null on fetch/integrity failure so AttributeIndex can fall back to a fallback scheme. | ||
| val metadata = catching { resolver.resolve(vct, integrityMetadata[vct]) }.getOrNull() ?: return null | ||
| return ResolvedCredentialMetadata( | ||
| metadata = metadata, | ||
| loadedFrom = loadedFrom, | ||
| aliases = aliases.entries.filter { it.value == vct }.map { it.key.identifier }.toSet(), | ||
| ) | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.