Skip to content

Commit

Permalink
Merge branch 'main' into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
phisakel committed Jan 15, 2025
2 parents c2db0d1 + 885c4de commit a2e1486
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '16.0'
xcode-version: '16.2'
- uses: actions/checkout@v4
- name: Build
run: swift build
Expand Down
36 changes: 36 additions & 0 deletions Sources/MdocDataModel18013/DocumentClaims/DisplayMetadata.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright (c) 2023 European Commission

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import Foundation

public struct DisplayMetadata: Codable, Equatable, Sendable {
public let name: String?
public let localeIdentifier: String?
public let logo: LogoMetadata?
public let description: String?
public let backgroundColor: String?
public let textColor: String?
public var locale: Locale? { Locale(identifier: localeIdentifier ?? "en_US") }

public init(name: String? = nil, localeIdentifier: String? = nil, logo: LogoMetadata? = nil, description: String? = nil, backgroundColor: String? = nil, textColor: String? = nil) {
self.name = name
self.localeIdentifier = localeIdentifier
self.logo = logo
self.description = description
self.backgroundColor = backgroundColor
self.textColor = textColor
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,16 @@ public protocol DocClaimsDecodable: Sendable, AgeAttesting {
var createdAt: Date { get }
/// The date and time the document was last modified.
var modifiedAt: Date? { get }
/// The display name of the document.
/// The display name of the document (derived from `display`).
var displayName: String? { get }
/// The display properties of the document
var display: [DisplayMetadata]? { get }
/// The display properties of the issuer
var issuerDisplay: [DisplayMetadata]? { get }
/// The credential issuer identifier
var credentialIssuerIdentifier: String? { get }
/// The issuer configuration identifier
var configurationIdentifier: String? { get }
// The document type. For CBOR (mso_mdoc) documents is native, for SD-JWT (vc+sd-jwt) documents is the type of the document.
var docType: String? { get }
// document claims in a format agnostic way
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ import Foundation

/// A protocol to create a ``DocClaimsDecodable`` from a cbor encoded ``IssuerSigned`` struct
public protocol DocClaimsDecodableFactory: Sendable {
func makeClaimsDecodableFromCbor(id: String, createdAt: Date, issuerSigned: IssuerSigned, displayName: String?, claimDisplayNames: [NameSpace: [String: String]]?, mandatoryClaims: [NameSpace: [String: Bool]]?, claimValueTypes: [NameSpace: [String: String]]?) -> (any DocClaimsDecodable)?
func makeClaimsDecodableFromCbor(id: String, createdAt: Date, issuerSigned: IssuerSigned, displayName: String?, display: [DisplayMetadata]?, issuerDisplay: [DisplayMetadata]?, credentialIssuerIdentifier: String?, configurationIdentifier: String?, claimDisplayNames: [NameSpace: [String: String]]?, mandatoryClaims: [NameSpace: [String: Bool]]?, claimValueTypes: [NameSpace: [String: String]]?) -> (
any DocClaimsDecodable
)?
}
28 changes: 28 additions & 0 deletions Sources/MdocDataModel18013/DocumentClaims/LogoMetadata.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright (c) 2023 European Commission

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import Foundation

public struct LogoMetadata: Codable, Equatable, Sendable {
public let urlString: String?
public let alternativeText: String?
public var uri: URL? { urlString.flatMap(URL.init(string:)) }

public init(urlString: String? = nil, alternativeText: String? = nil) {
self.urlString = urlString
self.alternativeText = alternativeText
}
}
12 changes: 9 additions & 3 deletions Sources/MdocDataModel18013/MdocKnownDocTypes/EuPidModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ limitations under the License.
import Foundation

public struct EuPidModel: Decodable, DocClaimsDecodable, Sendable {
public var display: [DisplayMetadata]?
public var issuerDisplay: [DisplayMetadata]?
public static let euPidDocType: String = "eu.europa.ec.eudi.pid.1"
public var id: String = UUID().uuidString
public var createdAt: Date = Date()
Expand All @@ -27,7 +29,8 @@ public struct EuPidModel: Decodable, DocClaimsDecodable, Sendable {
public var displayName: String? = String("eu_pid_doctype_name")
public var modifiedAt: Date?
public var docDataFormat: DocDataFormat = .cbor

public var credentialIssuerIdentifier: String?
public var configurationIdentifier: String?
public let family_name: String?
public let given_name: String?
public let birth_date: String?
Expand Down Expand Up @@ -57,6 +60,8 @@ public struct EuPidModel: Decodable, DocClaimsDecodable, Sendable {
public let issuing_jurisdiction: String?

public enum CodingKeys: String, CodingKey, CaseIterable {
case credentialIssuerIdentifier
case configurationIdentifier
case family_name
case given_name
case birth_date
Expand Down Expand Up @@ -95,9 +100,10 @@ public struct EuPidModel: Decodable, DocClaimsDecodable, Sendable {
}

extension EuPidModel {
public init?(id: String, createdAt: Date, issuerSigned: IssuerSigned, displayName: String?, claimDisplayNames: [NameSpace: [String: String]]?, mandatoryClaims: [NameSpace: [String: Bool]]?, claimValueTypes: [NameSpace: [String: String]]?) {
public init?(id: String, createdAt: Date, issuerSigned: IssuerSigned, displayName: String?, display: [DisplayMetadata]?, issuerDisplay: [DisplayMetadata]?, credentialIssuerIdentifier: String?, configurationIdentifier: String?, claimDisplayNames: [NameSpace: [String: String]]?, mandatoryClaims: [NameSpace: [String: Bool]]?, claimValueTypes: [NameSpace: [String: String]]?) {
self.id = id
self.createdAt = createdAt; self.displayName = displayName
self.createdAt = createdAt; self.displayName = displayName; self.display = display; self.issuerDisplay = issuerDisplay
self.credentialIssuerIdentifier = credentialIssuerIdentifier; self.configurationIdentifier = configurationIdentifier
guard let nameSpaces = Self.getCborSignedItems(issuerSigned) else { return nil }
Self.extractCborClaims(nameSpaces, &docClaims, claimDisplayNames, mandatoryClaims, claimValueTypes)
Self.extractAgeOverValues(nameSpaces, &ageOverXX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import Foundation

public struct GenericMdocModel: DocClaimsDecodable, Sendable {
public var display: [DisplayMetadata]?
public var issuerDisplay: [DisplayMetadata]?
public var credentialIssuerIdentifier: String?
public var configurationIdentifier: String?
public var id: String = UUID().uuidString
public var createdAt: Date = Date()
public var docType: String?
Expand All @@ -12,12 +16,16 @@ public struct GenericMdocModel: DocClaimsDecodable, Sendable {
public var ageOverXX = [Int: Bool]()
public var docClaims = [DocClaim]()
public var docDataFormat: DocDataFormat
public var hashingAlg: String?

public init(id: String = UUID().uuidString, createdAt: Date = Date(), docType: String? = nil, displayName: String? = nil, modifiedAt: Date? = nil, ageOverXX: [Int : Bool] = [Int: Bool](), docClaims: [DocClaim] = [DocClaim](), docDataFormat: DocDataFormat = .cbor) {
public init(id: String = UUID().uuidString, createdAt: Date = Date(), docType: String?, displayName: String?, display: [DisplayMetadata]?, issuerDisplay: [DisplayMetadata]? = nil, credentialIssuerIdentifier: String?, configurationIdentifier: String?, modifiedAt: Date?, ageOverXX: [Int : Bool] = [Int: Bool](), docClaims: [DocClaim] = [DocClaim](), docDataFormat: DocDataFormat, hashingAlg: String?) {
self.id = id
self.createdAt = createdAt
self.docType = docType
self.displayName = displayName
self.display = display; self.issuerDisplay = issuerDisplay
self.credentialIssuerIdentifier = credentialIssuerIdentifier
self.configurationIdentifier = configurationIdentifier
self.modifiedAt = modifiedAt
self.ageOverXX = ageOverXX
self.docClaims = docClaims
Expand All @@ -27,8 +35,11 @@ public struct GenericMdocModel: DocClaimsDecodable, Sendable {

extension GenericMdocModel {

public init?(id: String, createdAt: Date, issuerSigned: IssuerSigned, docType: String, displayName: String?, claimDisplayNames: [NameSpace: [String: String]]?, mandatoryClaims: [NameSpace: [String: Bool]]?, claimValueTypes: [NameSpace: [String: String]]?) {
self.id = id; self.createdAt = createdAt; self.displayName = displayName; self.docType = docType; self.docDataFormat = .cbor
public init?(id: String, createdAt: Date, issuerSigned: IssuerSigned, docType: String, displayName: String?, display: [DisplayMetadata]?, issuerDisplay: [DisplayMetadata]?, credentialIssuerIdentifier: String?, configurationIdentifier: String?, claimDisplayNames: [NameSpace: [String: String]]?, mandatoryClaims: [NameSpace: [String: Bool]]?, claimValueTypes: [NameSpace: [String: String]]?) {
self.id = id; self.createdAt = createdAt; self.displayName = displayName
self.display = display; self.issuerDisplay = issuerDisplay
self.credentialIssuerIdentifier = credentialIssuerIdentifier; self.configurationIdentifier = configurationIdentifier
self.docType = docType; self.docDataFormat = .cbor
if let nameSpaces = Self.getCborSignedItems(issuerSigned) {
Self.extractCborClaims(nameSpaces, &docClaims, claimDisplayNames, mandatoryClaims, claimValueTypes)
}
Expand Down
11 changes: 9 additions & 2 deletions Sources/MdocDataModel18013/MdocKnownDocTypes/IsoMdlModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ limitations under the License.
import Foundation

public struct IsoMdlModel: Decodable, DocClaimsDecodable, Sendable {
public var display: [DisplayMetadata]?
public var issuerDisplay: [DisplayMetadata]?
public var credentialIssuerIdentifier: String?
public var configurationIdentifier: String?
public var id: String = UUID().uuidString
public var createdAt: Date = Date()
public var docType: String? = Self.isoDocType
Expand Down Expand Up @@ -70,6 +74,8 @@ public struct IsoMdlModel: Decodable, DocClaimsDecodable, Sendable {
let oidcInfo: ServerRetrievalOption?

public enum CodingKeys: String, CodingKey, CaseIterable {
case credentialIssuerIdentifier
case configurationIdentifier
case exp = "exp"
case iat = "iat"
case familyName = "family_name"
Expand Down Expand Up @@ -119,8 +125,9 @@ public struct IsoMdlModel: Decodable, DocClaimsDecodable, Sendable {


extension IsoMdlModel {
public init?(id: String, createdAt: Date, issuerSigned: IssuerSigned, displayName: String?, claimDisplayNames: [NameSpace: [String: String]]?, mandatoryClaims: [NameSpace: [String: Bool]]?, claimValueTypes: [NameSpace: [String: String]]?) {
self.id = id; self.createdAt = createdAt; self.displayName = displayName
public init?(id: String, createdAt: Date, issuerSigned: IssuerSigned, displayName: String?, display: [DisplayMetadata]?, issuerDisplay: [DisplayMetadata]?, credentialIssuerIdentifier: String?, configurationIdentifier: String?, claimDisplayNames: [NameSpace: [String: String]]?, mandatoryClaims: [NameSpace: [String: Bool]]?, claimValueTypes: [NameSpace: [String: String]]?) {
self.id = id; self.createdAt = createdAt; self.displayName = displayName; self.display = display; self.issuerDisplay = issuerDisplay
self.credentialIssuerIdentifier = credentialIssuerIdentifier; self.configurationIdentifier = configurationIdentifier
guard let nameSpaceItems = Self.getCborSignedItems(issuerSigned, nameSpaces) else { return nil }
Self.extractCborClaims(nameSpaceItems, &docClaims, claimDisplayNames, mandatoryClaims, claimValueTypes)
func getValue<T>(key: IsoMdlModel.CodingKeys) -> T? { Self.getCborItemValue(nameSpaceItems, string: key.rawValue) }
Expand Down

0 comments on commit a2e1486

Please sign in to comment.