-
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.
- Loading branch information
1 parent
32bdfbd
commit af7f39e
Showing
20 changed files
with
150 additions
and
84 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
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
10 changes: 10 additions & 0 deletions
10
AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDDatabaseKeyDAO.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 Combine | ||
import CoreData | ||
import Domain | ||
|
||
struct CDDatabaseKeyDAO: CoreDataDAO { | ||
typealias CoreDataObject = CDDatabaseKey | ||
let readContext: NSManagedObjectContext | ||
let writeContext: NSManagedObjectContext | ||
let identifierKey: String? = "identifier" | ||
} |
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
12 changes: 12 additions & 0 deletions
12
AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDKeychainKeyDAO.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,12 @@ | ||
import Combine | ||
import CoreData | ||
import Domain | ||
|
||
struct CDKeychainKeyDAO: CoreDataDAO { | ||
typealias CoreDataObject = CDKeychainKey | ||
let keychain: KeychainStore & KeychainProvider | ||
let keychainService: String | ||
let readContext: NSManagedObjectContext | ||
let writeContext: NSManagedObjectContext | ||
let identifierKey: String? = "identifier" | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,40 +20,65 @@ public extension PrismAgent { | |
) async throws -> Presentation { | ||
guard let proofableCredential = credential.proof else { throw UnknownError.somethingWentWrongError() } | ||
|
||
guard | ||
let subjectDIDString = credential.subject | ||
else { | ||
throw PolluxError.invalidPrismDID | ||
guard let requestType = request.attachments.first?.format else { | ||
throw UnknownError.somethingWentWrongError(customMessage: nil, underlyingErrors: nil) | ||
} | ||
|
||
let subjectDID = try DID(string: subjectDIDString) | ||
let presentationString: String | ||
switch requestType { | ||
case "anoncreds/[email protected]": | ||
guard | ||
let linkSecret = try await pluto.getLinkSecret().first().await() | ||
else { throw PrismAgentError.cannotFindDIDKeyPairIndex } | ||
|
||
let didInfo = try await pluto | ||
.getDIDInfo(did: subjectDID) | ||
.first() | ||
.await() | ||
let restored = try await self.apollo.restoreKey(linkSecret) | ||
guard | ||
let linkSecretString = String(data: restored.raw, encoding: .utf8) | ||
else { throw PrismAgentError.cannotFindDIDKeyPairIndex } | ||
presentationString = try proofableCredential.presentation( | ||
request: request.makeMessage(), | ||
options: [ | ||
.linkSecret(id: "", secret: linkSecretString) | ||
] | ||
) | ||
case "prism/jwt": | ||
guard | ||
let subjectDIDString = credential.subject | ||
else { | ||
throw PolluxError.invalidPrismDID | ||
} | ||
|
||
guard | ||
let storedPrivateKey = didInfo?.privateKeys.first | ||
else { throw PrismAgentError.cannotFindDIDKeyPairIndex } | ||
let subjectDID = try DID(string: subjectDIDString) | ||
|
||
let privateKey = try await apollo.restorePrivateKey(storedPrivateKey) | ||
let didInfo = try await pluto | ||
.getDIDInfo(did: subjectDID) | ||
.first() | ||
.await() | ||
|
||
guard | ||
let storedPrivateKey = didInfo?.privateKeys.first | ||
else { throw PrismAgentError.cannotFindDIDKeyPairIndex } | ||
|
||
let privateKey = try await apollo.restorePrivateKey(storedPrivateKey) | ||
|
||
guard | ||
let exporting = privateKey.exporting | ||
else { throw PrismAgentError.cannotFindDIDKeyPairIndex } | ||
|
||
presentationString = try proofableCredential.presentation( | ||
request: request.makeMessage(), | ||
options: [ | ||
.exportableKey(exporting), | ||
.subjectDID(subjectDID) | ||
] | ||
) | ||
default: | ||
throw UnknownError.somethingWentWrongError(customMessage: nil, underlyingErrors: nil) | ||
} | ||
|
||
guard | ||
let exporting = privateKey.exporting | ||
else { throw PrismAgentError.cannotFindDIDKeyPairIndex } | ||
|
||
let presentationString = try proofableCredential.presentation( | ||
request: request.makeMessage(), | ||
options: [ | ||
.exportableKey(exporting), | ||
.subjectDID(subjectDID) | ||
] | ||
) | ||
|
||
guard let base64String = presentationString.data(using: .utf8)?.base64EncodedString() else { | ||
throw CommonError.invalidCoding(message: "Could not encode to base64") | ||
} | ||
|
||
return Presentation( | ||
body: .init( | ||
goalCode: request.body.goalCode, | ||
|
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.