From 3481ae838d7bdd3ea1070379d1d0cce3b8f2cc21 Mon Sep 17 00:00:00 2001 From: Rosendahl Sami Date: Tue, 6 Aug 2024 15:04:20 +0300 Subject: [PATCH] Remove credential response property "format"; It is not a specified parameter of OpenID4VCI Credential Response: https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html#name-credential-response. --- .../Entities/Issuance/SubmittedRequest.swift | 4 ++-- .../SingleIssuanceSuccessResponse.swift | 6 +----- .../DeferredCredentialIssuanceResponse.swift | 19 ++++--------------- Sources/Issuers/IssuanceRequester.swift | 6 +++--- Tests/Helpers/Wallet.swift | 6 +++--- Tests/Issuance/IssuanceBatchRequestTest.swift | 6 +++--- .../IssuanceDeferredRequestTest.swift | 2 +- Tests/Issuance/IssuanceNotificationTest.swift | 4 ++-- .../Issuance/IssuanceSingleRequestTest.swift | 6 +++--- 9 files changed, 22 insertions(+), 37 deletions(-) diff --git a/Sources/Entities/Issuance/SubmittedRequest.swift b/Sources/Entities/Issuance/SubmittedRequest.swift index 82d5fe6..a68b6d8 100644 --- a/Sources/Entities/Issuance/SubmittedRequest.swift +++ b/Sources/Entities/Issuance/SubmittedRequest.swift @@ -21,7 +21,7 @@ public struct CredentialIssuanceResponse: Codable { public enum Result: Codable { case deferred(transactionId: TransactionId) - case issued(format: String?, credential: String, notificationId: NotificationId?) + case issued(credential: String, notificationId: NotificationId?) } public init(credentialResponses: [Result], cNonce: CNonce?) { @@ -40,7 +40,7 @@ public enum SubmittedRequest { case .success(let response): response.credentialResponses.compactMap { result in switch result { - case .issued(_, let credential, _): + case .issued(let credential, _): credential default: nil diff --git a/Sources/Entities/Profiles/SingleIssuanceSuccessResponse.swift b/Sources/Entities/Profiles/SingleIssuanceSuccessResponse.swift index 758bd5f..6b10c8c 100644 --- a/Sources/Entities/Profiles/SingleIssuanceSuccessResponse.swift +++ b/Sources/Entities/Profiles/SingleIssuanceSuccessResponse.swift @@ -16,7 +16,6 @@ import Foundation public struct SingleIssuanceSuccessResponse: Codable { - public let format: String? public let credential: String? public let transactionId: String? public let notificationId: String? @@ -24,7 +23,6 @@ public struct SingleIssuanceSuccessResponse: Codable { public let cNonceExpiresInSeconds: Int? enum CodingKeys: String, CodingKey { - case format case credential case transactionId = "transaction_id" case notificationId = "notification_id" @@ -33,14 +31,12 @@ public struct SingleIssuanceSuccessResponse: Codable { } public init( - format: String?, credential: String?, transactionId: String?, notificationId: String?, cNonce: String?, cNonceExpiresInSeconds: Int? ) { - self.format = format self.credential = credential self.transactionId = transactionId self.notificationId = notificationId @@ -59,7 +55,7 @@ public extension SingleIssuanceSuccessResponse { ) } else if let credential = credential { return CredentialIssuanceResponse( - credentialResponses: [.issued(format: format ?? "", credential: credential, notificationId: nil)], + credentialResponses: [.issued(credential: credential, notificationId: nil)], cNonce: CNonce(value: cNonce, expiresInSeconds: cNonceExpiresInSeconds) ) } else { diff --git a/Sources/Entities/Types/DeferredCredentialIssuanceResponse.swift b/Sources/Entities/Types/DeferredCredentialIssuanceResponse.swift index b4bc8d9..400399a 100644 --- a/Sources/Entities/Types/DeferredCredentialIssuanceResponse.swift +++ b/Sources/Entities/Types/DeferredCredentialIssuanceResponse.swift @@ -16,13 +16,12 @@ import Foundation public enum DeferredCredentialIssuanceResponse: Codable { - case issued(format: String?, credential: String) + case issued(credential: String) case issuancePending(transactionId: TransactionId) case errored(error: String?, errorDescription: String?) private enum CodingKeys: String, CodingKey { case type - case format case credential case transactionId = "transaction_id" case error @@ -31,19 +30,10 @@ public enum DeferredCredentialIssuanceResponse: Codable { public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) - if let format = try? container.decode(String.self, forKey: .format), - let credential = try? container.decode(String.self, forKey: .credential) { - self = .issued(format: format, credential: credential) - - } else if let transactionId = try? container.decode(String.self, forKey: .transactionId) { + if let transactionId = try? container.decode(String.self, forKey: .transactionId) { self = .issuancePending(transactionId: try .init(value: transactionId)) - } else if let credential = try? container.decode(String.self, forKey: .credential) { - self = .issued( - format: nil, - credential: credential - ) - + self = .issued(credential: credential) } else { self = .errored( error: try? container.decode(String.self, forKey: .error), @@ -56,9 +46,8 @@ public enum DeferredCredentialIssuanceResponse: Codable { var container = encoder.container(keyedBy: CodingKeys.self) switch self { - case let .issued(format, credential): + case let .issued(credential): try container.encode("issued", forKey: .type) - try container.encode(format, forKey: .format) try container.encode(credential, forKey: .credential) case let .issuancePending(transactionId): diff --git a/Sources/Issuers/IssuanceRequester.swift b/Sources/Issuers/IssuanceRequester.swift index 947d8ed..53b74bf 100644 --- a/Sources/Issuers/IssuanceRequester.swift +++ b/Sources/Issuers/IssuanceRequester.swift @@ -357,7 +357,7 @@ private extension SingleIssuanceSuccessResponse { func toSingleIssuanceResponse() throws -> CredentialIssuanceResponse { if let credential = credential { return CredentialIssuanceResponse( - credentialResponses: [.issued(format: format ?? "", credential: credential, notificationId: nil)], + credentialResponses: [.issued(credential: credential, notificationId: nil)], cNonce: CNonce(value: cNonce, expiresInSeconds: cNonceExpiresInSeconds) ) } else if let transactionId = transactionId { @@ -376,9 +376,9 @@ private extension BatchIssuanceSuccessResponse { func mapResults() throws -> [CredentialIssuanceResponse.Result] { return try credentialResponses.map { response in if let transactionId = response.transactionId { - return CredentialIssuanceResponse.Result.deferred(transactionId: try .init(value: transactionId)) + return .deferred(transactionId: try .init(value: transactionId)) } else if let credential = response.credential { - return CredentialIssuanceResponse.Result.issued(format: nil, credential: credential, notificationId: nil) + return .issued(credential: credential, notificationId: nil) } else { throw CredentialIssuanceError.responseUnparsable("Got success response for issuance but response misses 'transaction_id' and 'certificate' parameters") } diff --git a/Tests/Helpers/Wallet.swift b/Tests/Helpers/Wallet.swift index 34ebef9..88029dc 100644 --- a/Tests/Helpers/Wallet.swift +++ b/Tests/Helpers/Wallet.swift @@ -491,7 +491,7 @@ extension Wallet { authorized: noProofRequiredState, transactionId: transactionId ) - case .issued(_, let credential, _): + case .issued(let credential, _): return credential } } else { @@ -551,7 +551,7 @@ extension Wallet { authorized: authorized, transactionId: transactionId ) - case .issued(_, let credential, _): + case .issued(let credential, _): return credential } } else { @@ -581,7 +581,7 @@ extension Wallet { switch deferredRequestResponse { case .success(let response): switch response { - case .issued(_, let credential): + case .issued(let credential): return credential case .issuancePending(let transactionId): throw ValidationError.error(reason: "Credential not ready yet. Try after \(transactionId.interval ?? 0)") diff --git a/Tests/Issuance/IssuanceBatchRequestTest.swift b/Tests/Issuance/IssuanceBatchRequestTest.swift index b212fc0..18e5656 100644 --- a/Tests/Issuance/IssuanceBatchRequestTest.swift +++ b/Tests/Issuance/IssuanceBatchRequestTest.swift @@ -152,7 +152,7 @@ class IssuanceBatchRequestTest: XCTestCase { switch result { case .deferred: XCTAssert(false, "Unexpected deferred") - case .issued(_, let credential, _): + case .issued(let credential, _): XCTAssert(true, "credential: \(credential)") return } @@ -307,7 +307,7 @@ class IssuanceBatchRequestTest: XCTestCase { switch result { case .deferred: XCTAssert(false, "Unexpected deferred") - case .issued(_, let credential, _): + case .issued(let credential, _): XCTAssert(true, "credential: \(credential)") return } @@ -350,7 +350,7 @@ class IssuanceBatchRequestTest: XCTestCase { switch result { case .deferred: XCTAssert(false, "Unexpected deferred") - case .issued(_, let credential, _): + case .issued(let credential, _): XCTAssert(true, "credential: \(credential)") return } diff --git a/Tests/Issuance/IssuanceDeferredRequestTest.swift b/Tests/Issuance/IssuanceDeferredRequestTest.swift index 9f06f8a..648b1a1 100644 --- a/Tests/Issuance/IssuanceDeferredRequestTest.swift +++ b/Tests/Issuance/IssuanceDeferredRequestTest.swift @@ -128,7 +128,7 @@ class IssuanceDeferredRequestTest: XCTestCase { case .deferred(let transactionId): XCTAssert(true, "transaction_id: \(transactionId)") return - case .issued(_, let credential, _): + case .issued(let credential, _): XCTAssert(false, "credential: \(credential)") } } else { diff --git a/Tests/Issuance/IssuanceNotificationTest.swift b/Tests/Issuance/IssuanceNotificationTest.swift index 2a1e422..91a9cec 100644 --- a/Tests/Issuance/IssuanceNotificationTest.swift +++ b/Tests/Issuance/IssuanceNotificationTest.swift @@ -134,7 +134,7 @@ class IssuanceNotificationTest: XCTestCase { switch result { case .deferred: XCTAssert(false, "Unexpected deferred") - case .issued(_, let credential, _): + case .issued(let credential, _): XCTAssert(true, "credential: \(credential)") let result = try await issuer.notify( @@ -277,7 +277,7 @@ class IssuanceNotificationTest: XCTestCase { switch result { case .deferred: XCTAssert(false, "Unexpected deferred") - case .issued(_, let credential, _): + case .issued(let credential, _): XCTAssert(true, "credential: \(credential)") let result = try await issuer.notify( diff --git a/Tests/Issuance/IssuanceSingleRequestTest.swift b/Tests/Issuance/IssuanceSingleRequestTest.swift index 4b32d22..b23cdf8 100644 --- a/Tests/Issuance/IssuanceSingleRequestTest.swift +++ b/Tests/Issuance/IssuanceSingleRequestTest.swift @@ -137,7 +137,7 @@ class IssuanceSingleRequestTest: XCTestCase { switch result { case .deferred: XCTAssert(false, "Unexpected deferred") - case .issued(_, let credential, _): + case .issued(let credential, _): XCTAssert(true, "credential: \(credential)") return } @@ -270,7 +270,7 @@ class IssuanceSingleRequestTest: XCTestCase { switch result { case .deferred: XCTAssert(false, "Unexpected deferred") - case .issued(_, let credential, _): + case .issued(let credential, _): XCTAssert(true, "credential: \(credential)") return } @@ -398,7 +398,7 @@ class IssuanceSingleRequestTest: XCTestCase { switch result { case .deferred: XCTAssert(false, "Unexpected deferred") - case .issued(_, let credential, _): + case .issued(let credential, _): XCTAssert(true, "credential: \(credential)") return }