Skip to content
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

[refactor] Remove credential response property "format" #72

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/Entities/Issuance/SubmittedRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
import Foundation

public struct SingleIssuanceSuccessResponse: Codable {
public let format: String?
public let credential: String?
public let transactionId: String?
public let notificationId: String?
public let cNonce: String?
public let cNonceExpiresInSeconds: Int?

enum CodingKeys: String, CodingKey {
case format
case credential
case transactionId = "transaction_id"
case notificationId = "notification_id"
Expand All @@ -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
Expand All @@ -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 {
Expand Down
19 changes: 4 additions & 15 deletions Sources/Entities/Types/DeferredCredentialIssuanceResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand All @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions Sources/Issuers/IssuanceRequester.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/Helpers/Wallet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ extension Wallet {
authorized: noProofRequiredState,
transactionId: transactionId
)
case .issued(_, let credential, _):
case .issued(let credential, _):
return credential
}
} else {
Expand Down Expand Up @@ -551,7 +551,7 @@ extension Wallet {
authorized: authorized,
transactionId: transactionId
)
case .issued(_, let credential, _):
case .issued(let credential, _):
return credential
}
} else {
Expand Down Expand Up @@ -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)")
Expand Down
6 changes: 3 additions & 3 deletions Tests/Issuance/IssuanceBatchRequestTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Issuance/IssuanceDeferredRequestTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Tests/Issuance/IssuanceNotificationTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions Tests/Issuance/IssuanceSingleRequestTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down