From d76150a2ed2cf0ba9bb61f02316c163b42c3e488 Mon Sep 17 00:00:00 2001 From: Filippos Sakellaropoulos Date: Tue, 5 Nov 2024 00:44:06 +0200 Subject: [PATCH 1/2] Update openid4vp to 0.6.0 and refactor OpenId4VP configuration types --- Package.resolved | 10 +++++----- Package.swift | 2 +- Sources/EudiWalletKit/EudiWallet.swift | 2 +- Sources/EudiWalletKit/Services/OpenId4VpService.swift | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Package.resolved b/Package.resolved index e6a8139..4ac6f82 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "b67feccbd1f8993b7daae2734ce787ff627abb69b550179cbe226a9574f98dda", + "originHash" : "ebf47c2682782005cbaf1f28ff387c17a3cad1d91fcba1d59b4cd31b98367167", "pins" : [ { "identity" : "blueecc", @@ -60,8 +60,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/eu-digital-identity-wallet/eudi-lib-ios-presentation-exchange-swift.git", "state" : { - "revision" : "bf9396b3bc9ed27a3b740759b045c31d10b0eb62", - "version" : "0.1.1" + "revision" : "4e1ac57b6772f7f6eac5ef24d977c42e94bc6565", + "version" : "0.2.0" } }, { @@ -69,8 +69,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/eu-digital-identity-wallet/eudi-lib-ios-siop-openid4vp-swift.git", "state" : { - "revision" : "1a6912fb79646dfaad393625e71aef427e4635b6", - "version" : "0.5.0" + "revision" : "f103311dd3bd975b12919d4c3c1e099b6cb40330", + "version" : "0.6.0" } }, { diff --git a/Package.swift b/Package.swift index 373ff09..a07b08c 100644 --- a/Package.swift +++ b/Package.swift @@ -17,7 +17,7 @@ let package = Package( .package(url: "https://github.com/crspybits/swift-log-file", from: "0.1.0"), .package(url: "https://github.com/eu-digital-identity-wallet/eudi-lib-ios-iso18013-data-transfer.git", exact: "0.3.3"), .package(url: "https://github.com/eu-digital-identity-wallet/eudi-lib-ios-wallet-storage.git", exact: "0.3.0"), - .package(url: "https://github.com/eu-digital-identity-wallet/eudi-lib-ios-siop-openid4vp-swift.git", exact: "0.5.0"), + .package(url: "https://github.com/eu-digital-identity-wallet/eudi-lib-ios-siop-openid4vp-swift.git", exact: "0.6.0"), .package(url: "https://github.com/eu-digital-identity-wallet/eudi-lib-ios-openid4vci-swift.git", exact: "0.7.0"), ], targets: [ diff --git a/Sources/EudiWalletKit/EudiWallet.swift b/Sources/EudiWalletKit/EudiWallet.swift index 7564ad6..ac5da84 100644 --- a/Sources/EudiWalletKit/EudiWallet.swift +++ b/Sources/EudiWalletKit/EudiWallet.swift @@ -205,7 +205,7 @@ public final class EudiWallet: ObservableObject, @unchecked Sendable { let issueReq = try IssueRequest(id: pendingDoc.id, docType: pendingDoc.docType, privateKeyType: pkt, keyData: pk) try await openId4VCIService.initSecurityKeys(pendingDoc.privateKeyType == .secureEnclaveP256) let outcome = try await openId4VCIService.resumePendingIssuance(pendingDoc: pendingDoc, webUrl: webUrl) - if case let .pending(_) = outcome { return pendingDoc } + if case .pending(_) = outcome { return pendingDoc } let res = try await finalizeIssuing(id: pendingDoc.id, data: outcome, docType: pendingDoc.docType, format: format, issueReq: issueReq, openId4VCIService: openId4VCIService) return res } diff --git a/Sources/EudiWalletKit/Services/OpenId4VpService.swift b/Sources/EudiWalletKit/Services/OpenId4VpService.swift index 851b18c..ffb9028 100644 --- a/Sources/EudiWalletKit/Services/OpenId4VpService.swift +++ b/Sources/EudiWalletKit/Services/OpenId4VpService.swift @@ -161,7 +161,7 @@ public final class OpenId4VpService: @unchecked Sendable, PresentationService { } /// OpenId4VP wallet configuration - func getWalletConf(verifierApiUrl: String?, verifierLegalName: String?) -> WalletOpenId4VPConfiguration? { + func getWalletConf(verifierApiUrl: String?, verifierLegalName: String?) -> SiopOpenId4VPConfiguration? { guard let rsaPrivateKey = try? KeyController.generateRSAPrivateKey(), let privateKey = try? KeyController.generateECDHPrivateKey(), let rsaPublicKey = try? KeyController.generateRSAPublicKey(from: rsaPrivateKey) else { return nil } guard let rsaJWK = try? RSAPublicKey(publicKey: rsaPublicKey, additionalParameters: ["use": "sig", "kid": UUID().uuidString, "alg": "RS256"]) else { return nil } @@ -171,7 +171,7 @@ public final class OpenId4VpService: @unchecked Sendable, PresentationService { let verifierMetaData = PreregisteredClient(clientId: "Verifier", legalName: verifierLegalName, jarSigningAlg: JWSAlgorithm(.RS256), jwkSetSource: WebKeySource.fetchByReference(url: URL(string: "\(verifierApiUrl)/wallet/public-keys.json")!)) supportedClientIdSchemes += [.preregistered(clients: [verifierMetaData.clientId: verifierMetaData])] } - let res = WalletOpenId4VPConfiguration(subjectSyntaxTypesSupported: [.decentralizedIdentifier, .jwkThumbprint], preferredSubjectSyntaxType: .jwkThumbprint, decentralizedIdentifier: try! DecentralizedIdentifier(rawValue: "did:example:123"), signingKey: privateKey, signingKeySet: keySet, supportedClientIdSchemes: supportedClientIdSchemes, vpFormatsSupported: [], session: urlSession) + let res = SiopOpenId4VPConfiguration(subjectSyntaxTypesSupported: [.decentralizedIdentifier, .jwkThumbprint], preferredSubjectSyntaxType: .jwkThumbprint, decentralizedIdentifier: try! DecentralizedIdentifier(rawValue: "did:example:123"), signingKey: privateKey, signingKeySet: keySet, supportedClientIdSchemes: supportedClientIdSchemes, vpFormatsSupported: [], session: urlSession) return res } From 18d994be535b5d8f8d51a760214d5c2f796ec9fa Mon Sep 17 00:00:00 2001 From: Filippos Sakellaropoulos Date: Tue, 5 Nov 2024 01:05:28 +0200 Subject: [PATCH 2/2] Refactor error handling to use async setError method in EudiWallet and StorageManager. Updates for error should occur in main actor --- Sources/EudiWalletKit/EudiWallet.swift | 2 +- Sources/EudiWalletKit/Services/StorageManager.swift | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/EudiWalletKit/EudiWallet.swift b/Sources/EudiWalletKit/EudiWallet.swift index ac5da84..36ba235 100644 --- a/Sources/EudiWalletKit/EudiWallet.swift +++ b/Sources/EudiWalletKit/EudiWallet.swift @@ -367,7 +367,7 @@ public final class EudiWallet: ObservableObject, @unchecked Sendable { } try await storage.loadDocuments(status: .issued) } catch { - storage.setError(error) + await storage.setError(error) throw WalletError(description: error.localizedDescription) } } diff --git a/Sources/EudiWalletKit/Services/StorageManager.swift b/Sources/EudiWalletKit/Services/StorageManager.swift index 7566f10..8b47f1c 100644 --- a/Sources/EudiWalletKit/Services/StorageManager.swift +++ b/Sources/EudiWalletKit/Services/StorageManager.swift @@ -144,7 +144,7 @@ public class StorageManager: ObservableObject, @unchecked Sendable { await refreshPublishedVars() return docs } catch { - setError(error) + await setError(error) throw error } } @@ -161,7 +161,7 @@ public class StorageManager: ObservableObject, @unchecked Sendable { await refreshPublishedVars() return doc } catch { - setError(error) + await setError(error) throw error } } @@ -221,7 +221,7 @@ public class StorageManager: ObservableObject, @unchecked Sendable { _ = await MainActor.run { deferredDocuments.remove(at: index) } } } catch { - setError(error) + await setError(error) throw error } } @@ -238,13 +238,13 @@ public class StorageManager: ObservableObject, @unchecked Sendable { await MainActor.run { deferredDocuments.removeAll(keepingCapacity:false) } } } catch { - setError(error) + await setError(error) throw error } } - func setError(_ error: Error) { - uiError = WalletError(description: error.localizedDescription, userInfo: (error as NSError).userInfo) + func setError(_ error: Error) async { + await MainActor.run { uiError = WalletError(description: error.localizedDescription, userInfo: (error as NSError).userInfo) } } }