Skip to content

Commit

Permalink
Upodate addMDoc method
Browse files Browse the repository at this point in the history
  • Loading branch information
Juliano1612 committed Aug 27, 2024
1 parent 2e750b5 commit 3953d74
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions Sources/MobileSdk/CredentialPack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]] {
Expand Down

0 comments on commit 3953d74

Please sign in to comment.