From 3953d746b93b90becde3665ab38dda3e76a7b475 Mon Sep 17 00:00:00 2001 From: Juliano Cezar Chagas Tavares Date: Tue, 27 Aug 2024 10:15:15 -0300 Subject: [PATCH] Upodate addMDoc method --- Sources/MobileSdk/CredentialPack.swift | 28 +++++--------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/Sources/MobileSdk/CredentialPack.swift b/Sources/MobileSdk/CredentialPack.swift index 8024c66..6bc6449 100644 --- a/Sources/MobileSdk/CredentialPack.swift +++ b/Sources/MobileSdk/CredentialPack.swift @@ -23,29 +23,11 @@ public class CredentialPack { } } - public func addMDoc(mdocBase64: String, keyPEM: String) throws -> [Credential]? { - do { - let mdocData = Data(base64Encoded: mdocBase64)! - let key = try P256.Signing.PrivateKey(pemRepresentation: keyPEM) - let attributes = [kSecAttrKeyType: kSecAttrKeyTypeECSECPrimeRandom, - kSecAttrKeyClass: kSecAttrKeyClassPrivate] as [String: Any] - let secKey = SecKeyCreateWithData(key.x963Representation as CFData, - attributes as CFDictionary, - nil)! - let query = [kSecClass: kSecClassKey, - kSecAttrApplicationLabel: "mdoc_key", - kSecAttrAccessible: kSecAttrAccessibleWhenUnlocked, - kSecUseDataProtectionKeychain: true, - kSecValueRef: secKey] as [String: Any] - SecItemDelete(query as CFDictionary) - let status = SecItemAdd(query as CFDictionary, nil) - print("Status store item: \(status.description)") - let credential = MDoc(fromMDoc: mdocData, namespaces: [:], keyAlias: "mdoc_key")! - self.credentials.append(credential) - return self.credentials - } catch { - throw error - } + public func addMDoc(mdocBase64: String, keyAlias: String = UUID().uuidString) throws -> [Credential]? { + let mdocData = Data(base64Encoded: mdocBase64)! + let credential = MDoc(fromMDoc: mdocData, namespaces: [:], keyAlias: keyAlias)! + self.credentials.append(credential) + return self.credentials } public func get(keys: [String]) -> [String: [String: GenericJSON]] {