-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pollux): add credential abstraction
ATL-4786 Besides adding the new credential abstraction this adds the following: - Changes on Pollux to use the new abstraction - Changes on PrismAgent to use new abstraction - Changes on Sample App to for new abstraction - Adds tests for new implementation - Adds Codable to Messages
- Loading branch information
1 parent
6dc434c
commit b13f899
Showing
65 changed files
with
1,196 additions
and
894 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,34 @@ | ||
import Foundation | ||
|
||
public enum CredentialOperationsOptions { | ||
case schema(json: Data) | ||
case link_secret(id: String, secret: String) | ||
case subjectDID(DID) | ||
case entropy(String) | ||
case signableKey(SignableKey) | ||
case exportableKey(ExportableKey) | ||
case custom(key: String, data: Data) | ||
} | ||
|
||
/// The Pollux protocol defines the set of credential operations that are used in the Atala PRISM architecture. | ||
public protocol Pollux { | ||
/// Parses a JWT-encoded verifiable credential and returns a `VerifiableCredential` object representing the credential. | ||
/// - Parameter jwtString: The JWT-encoded credential to parse. | ||
/// - Throws: An error if the JWT cannot be parsed or decoded, or if the resulting verifiable credential is invalid. | ||
/// - Returns: A `VerifiableCredential` object representing the parsed credential. | ||
func parseVerifiableCredential(jwtString: String) throws -> VerifiableCredential | ||
func parseCredential(data: Data) throws -> Credential | ||
func restoreCredential(restorationIdentifier: String, credentialData: Data) throws -> Credential | ||
func processCredentialRequest( | ||
offerMessage: Message, | ||
options: [CredentialOperationsOptions] | ||
) throws -> String | ||
} | ||
|
||
extension Pollux { | ||
func restoreCredential(storedCredential: StorableCredential) throws -> Credential { | ||
try restoreCredential( | ||
restorationIdentifier: storedCredential.recoveryId, | ||
credentialData: storedCredential.credentialData | ||
) | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
AtalaPrismSDK/Domain/Sources/Models/Credentials/Credential.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import Foundation | ||
|
||
public struct Claim { | ||
public enum ClaimType: Comparable { | ||
case string(String) | ||
case bool(Bool) | ||
case date(Date) | ||
case data(Data) | ||
case number(Double) | ||
|
||
public static func < (lhs: Claim.ClaimType, rhs: Claim.ClaimType) -> Bool { | ||
switch (lhs, rhs) { | ||
case let (.string(str1), .string(str2)): | ||
return str1 < str2 | ||
case let (.date(date1), .date(date2)): | ||
return date1 < date2 | ||
case let (.number(number1), .number(number2)): | ||
return number1 < number2 | ||
default: | ||
return false | ||
} | ||
} | ||
} | ||
|
||
public let key: String | ||
public let value: ClaimType | ||
|
||
public init(key: String, value: ClaimType) { | ||
self.key = key | ||
self.value = value | ||
} | ||
|
||
public func getValueAsString() -> String { | ||
switch value { | ||
case .string(let string): | ||
return string | ||
case .bool(let bool): | ||
return "\(bool)" | ||
case .date(let date): | ||
return date.formatted() | ||
case .data(let data): | ||
return data.base64EncodedString() | ||
case .number(let double): | ||
return "\(double)" | ||
} | ||
} | ||
} | ||
|
||
public protocol Credential { | ||
var id: String { get } | ||
var issuer: String { get } | ||
var subject: String? { get } | ||
var claims: [Claim] { get } | ||
var properties: [String: Any] { get } | ||
} | ||
|
||
public extension Credential { | ||
var isCodable: Bool { self is Codable } | ||
var codable: Codable? { self as? Codable } | ||
} |
10 changes: 10 additions & 0 deletions
10
AtalaPrismSDK/Domain/Sources/Models/Credentials/ProofableCredential.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Foundation | ||
|
||
public protocol ProofableCredential { | ||
func presentation(request: Message, options: [CredentialOperationsOptions]) throws -> String | ||
} | ||
|
||
public extension Credential { | ||
var isProofable: Bool { self is ProofableCredential } | ||
var proof: ProofableCredential? { self as? ProofableCredential } | ||
} |
20 changes: 20 additions & 0 deletions
20
AtalaPrismSDK/Domain/Sources/Models/Credentials/StorableCredential.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Foundation | ||
|
||
public protocol StorableCredential { | ||
var storingId: String { get } | ||
var recoveryId: String { get } | ||
var credentialData: Data { get } | ||
var queryIssuer: String? { get } | ||
var querySubject: String? { get } | ||
var queryCredentialCreated: Date? { get } | ||
var queryCredentialUpdated: Date? { get } | ||
var queryCredentialSchema: String? { get } | ||
var queryValidUntil: Date? { get } | ||
var queryRevoked: Bool? { get } | ||
var queryAvailableClaims: [String] { get } | ||
} | ||
|
||
public extension Credential { | ||
var isStorable: Bool { self is StorableCredential } | ||
var storable: StorableCredential? { self as? StorableCredential } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.