Skip to content

Commit

Permalink
Swiftlint
Browse files Browse the repository at this point in the history
  • Loading branch information
cobward committed Oct 2, 2024
1 parent 75ffadc commit af934d6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
18 changes: 9 additions & 9 deletions Sources/MobileSdk/Credential.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import SpruceIDMobileSdkRs

open class Credential: Identifiable {
public var id: String

public init(id: String) {
self.id = id
}

open func get(keys: [String]) -> [String: GenericJSON] {
if keys.contains("id") {
return ["id": GenericJSON.string(self.id)]
Expand All @@ -22,18 +22,18 @@ extension Mdoc {
public func jsonEncodedDetails() -> [String: GenericJSON] {
self.jsonEncodedDetailsInternal(containing: nil)
}

/// Access the specified elements in the mdoc, ignoring namespaces and missing elements that cannot be encoded as JSON.
public func jsonEncodedDetails(containing elementIdentifiers: [String]) -> [String: GenericJSON] {
self.jsonEncodedDetailsInternal(containing: elementIdentifiers)
}

private func jsonEncodedDetailsInternal(containing elementIdentifiers: [String]?) -> [String: GenericJSON] {
// Ignore the namespaces.
Dictionary(uniqueKeysWithValues: self.details().flatMap {
$1.compactMap {
let id = $0.identifier

// If a filter is provided, filter out non-specified ids.
if let ids = elementIdentifiers {
if !ids.contains(id) {
Expand Down Expand Up @@ -72,10 +72,10 @@ extension JwtVc {
print("failed to decode VCDM data from UTF-8")
return [:]
}

/// Access the specified claims from the W3C VCDM credential (not including the JWT envelope).
public func credentialClaims(containing claimNames: [String]) -> [String: GenericJSON] {
self.credentialClaims().filter() {
self.credentialClaims().filter {
(key, _) in
claimNames.contains(key)
}
Expand All @@ -100,10 +100,10 @@ extension JsonVc {
print("failed to decode VCDM data from UTF-8")
return [:]
}

/// Access the specified claims from the W3C VCDM credential.
public func credentialClaims(containing claimNames: [String]) -> [String: GenericJSON] {
self.credentialClaims().filter() {
self.credentialClaims().filter {
(key, _) in
claimNames.contains(key)
}
Expand Down
21 changes: 10 additions & 11 deletions Sources/MobileSdk/CredentialPack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,38 @@ import Foundation
import SpruceIDMobileSdkRs
import CryptoKit


public class CredentialPack {

private var credentials: [ParsedCredential]

/// Initialize an empty CredentialPack.
public init() {
self.credentials = []
}

/// Initialize a CredentialPack from existing credentials.
public init(credentials: [ParsedCredential]) {
self.credentials = credentials
}

/// Add a JwtVc to the CredentialPack.
public func addJwtVc(jwtVc: JwtVc) -> [ParsedCredential] {
self.credentials.append(ParsedCredential.newJwtVcJson(jwtVc: jwtVc))
return self.credentials
}

/// Add a JsonVc to the CredentialPack.
public func addJsonVc(jsonVc: JsonVc) -> [ParsedCredential] {
self.credentials.append(ParsedCredential.newLdpVc(jsonVc: jsonVc))
return self.credentials
}

/// Add an Mdoc to the CredentialPack.
public func addMDoc(mdoc: Mdoc) -> [ParsedCredential] {
self.credentials.append(ParsedCredential.newMsoMdoc(mdoc: mdoc))
return self.credentials
}

/// Find credential claims from all credentials in this CredentialPack.
public func findCredentialClaims(claimNames: [String]) -> [Uuid: [String: GenericJSON]] {
Dictionary(uniqueKeysWithValues: self.list()
Expand All @@ -59,19 +58,19 @@ public class CredentialPack {
return (credential.id(), claims)
})
}

/// Get credentials by id.
public func get(credentialsIds: [Uuid]) -> [ParsedCredential] {
return self.credentials.filter {
credentialsIds.contains($0.id())
}
}

/// Get a credential by id.
public func get(credentialId: Uuid) -> ParsedCredential? {
return self.credentials.first(where: { $0.id() == credentialId })
}

/// List all of the credentials in the CredentialPack.
public func list() -> [ParsedCredential] {
return self.credentials
Expand Down

0 comments on commit af934d6

Please sign in to comment.