From 9e409b395c1f8b9dedb896b81ced80fd04ed1896 Mon Sep 17 00:00:00 2001 From: Joseph Milan Date: Wed, 24 Jul 2024 14:14:34 +0530 Subject: [PATCH] Fix #30: issue in presentation submission --- .../Service/VerificationService.swift | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Sources/eudiWalletOidcIos/Service/VerificationService.swift b/Sources/eudiWalletOidcIos/Service/VerificationService.swift index bcb1fba..a368739 100644 --- a/Sources/eudiWalletOidcIos/Service/VerificationService.swift +++ b/Sources/eudiWalletOidcIos/Service/VerificationService.swift @@ -44,7 +44,6 @@ public class VerificationService: NSObject, VerificationServiceProtocol { guard let redirectURL = presentationRequest?.redirectUri else {return nil} return await sendVPRequest(vpToken: vpToken, presentationSubmission: presentationSubmission, redirectURI: presentationRequest?.redirectUri ?? "", state: presentationRequest?.state ?? "") } - private func generateJWKFromPrivateKey(secureKey: SecureKeyData, did: String) -> [String: Any] { let rawRepresentation = secureKey.publicKey @@ -58,7 +57,6 @@ public class VerificationService: NSObject, VerificationServiceProtocol { ] } - public func processAuthorisationRequest(data: String?) async -> PresentationRequest? { guard let _ = data else { return nil } @@ -138,11 +136,12 @@ public class VerificationService: NSObject, VerificationServiceProtocol { } private func generateJWTPayload(did: String, nonce: String, credentialsList: [String], state: String, clientID: String) -> String { + let uuid4 = UUID().uuidString let vp = ([ "@context": ["https://www.w3.org/2018/credentials/v1"], "holder": did, - "id": "urn:uuid:\(UUID().uuidString)", + "id": "urn:uuid:\(uuid4)", "type": [ "VerifiablePresentation" ], @@ -150,7 +149,6 @@ public class VerificationService: NSObject, VerificationServiceProtocol { ] as [String : Any]) let currentTime = Int(Date().timeIntervalSince1970) - let uuid4 = UUID().uuidString return ([ "aud": clientID, @@ -167,7 +165,6 @@ public class VerificationService: NSObject, VerificationServiceProtocol { private func generateVPToken(header: String, payload: String, secureKey: SecureKeyData) -> String { let headerData = Data(header.utf8) - //let payloadData = Data(payload.utf8) //let unsignedToken = "\(headerData.base64URLEncodedString()).\(payloadData.base64URLEncodedString())" //let signatureData = try? privateKey.signature(for: unsignedToken.data(using: .utf8)!) @@ -175,7 +172,6 @@ public class VerificationService: NSObject, VerificationServiceProtocol { guard let idToken = keyHandler.sign(payload: payload, header: headerData, withKey: secureKey.privateKey) else{return ""} //guard let signature = keyHandler.sign(data: unsignedToken.data(using: .utf8)!, withKey: secureKey.privateKey) else{return ""} return idToken//"\(unsignedToken).\(signature.base64URLEncodedString() ?? "")" - } private func preparePresentationSubmission( @@ -192,7 +188,7 @@ public class VerificationService: NSObject, VerificationServiceProtocol { if let inputDescriptors = presentationDefinition?.inputDescriptors { for index in 0.. InputDescriptor { return updatedDescriptor } } - extension VerificationService: URLSessionDelegate, URLSessionTaskDelegate { public func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping (URLRequest?) -> Void) { // Stops the redirection, and returns (internally) the response body.