From af7f39efa8b12dd13c4bead499d0f5c34b426786 Mon Sep 17 00:00:00 2001 From: goncalo-frade-iohk Date: Tue, 16 Jan 2024 15:30:49 +0000 Subject: [PATCH] feat(pollux): zkp verification --- AtalaPrismSDK/Domain/Sources/BBs/Pluto.swift | 7 +- .../Domain/Providers/LinkSecretProvider.swift | 2 +- ...DPrivateKeyDAO+DIDPrivateKeyProvider.swift | 8 +- ...DDIDPrivateKeyDAO+DIDPrivateKeyStore.swift | 6 +- .../DAO/CDDatabaseKeyDAO.swift | 10 +++ .../DAO/CDKeyDAO+LinkSecretProvider.swift | 8 +- .../DAO/CDKeyDAO+LinkSecretStore.swift | 28 +++---- .../PersistentStorage/DAO/CDKeyDAO.swift | 24 +++++- .../DAO/CDKeychainKeyDAO.swift | 12 +++ .../Pluto/Sources/PlutoImpl+Public.swift | 4 +- .../AnonCreds/AnonCredentialSchema.swift | 4 + .../ParseAnoncredsCredentialFromMessage.swift | 1 - .../Pollux/Tests/Mocks/MockPluto.swift | 4 +- .../Sources/PrismAgent+Credentials.swift | 8 +- .../PrismAgent/Sources/PrismAgent+Proof.swift | 77 ++++++++++++------- .../PrismAgent/Sources/PrismAgent.swift | 2 +- .../Connection/DownloadDataWithResolver.swift | 4 +- .../SetupPrismAgentViewModel.swift | 6 +- .../WalletDemo2/Main/Main2Router.swift | 2 +- .../MessageDetailViewModel.swift | 17 +--- 20 files changed, 150 insertions(+), 84 deletions(-) create mode 100644 AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDDatabaseKeyDAO.swift create mode 100644 AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDKeychainKeyDAO.swift diff --git a/AtalaPrismSDK/Domain/Sources/BBs/Pluto.swift b/AtalaPrismSDK/Domain/Sources/BBs/Pluto.swift index 6417a4e5..afc5c15f 100644 --- a/AtalaPrismSDK/Domain/Sources/BBs/Pluto.swift +++ b/AtalaPrismSDK/Domain/Sources/BBs/Pluto.swift @@ -81,6 +81,9 @@ public protocol Pluto { credential: StorableCredential ) -> AnyPublisher + /// Stores a link secret in the data store. + /// - Parameter secret: The storable key link secret. + /// - Returns: A publisher that completes when the operation finishes. func storeLinkSecret(secret: StorableKey) -> AnyPublisher /// Returns all stored PRISM DIDs, along with their associated key pair indices and aliases (if any). @@ -217,5 +220,7 @@ public protocol Pluto { /// - Returns: A publisher that emits an array of stored verifiable credentials. func getAllCredentials() -> AnyPublisher<[StorableCredential], Error> - func getLinkSecret() -> AnyPublisher<[StorableKey], Error> + /// Returns the stored link secret. + /// - Returns: A publisher that emits an optonal `StorableKey` that represents the link secret. + func getLinkSecret() -> AnyPublisher } diff --git a/AtalaPrismSDK/Pluto/Sources/Domain/Providers/LinkSecretProvider.swift b/AtalaPrismSDK/Pluto/Sources/Domain/Providers/LinkSecretProvider.swift index 3929f725..7ed0a4b1 100644 --- a/AtalaPrismSDK/Pluto/Sources/Domain/Providers/LinkSecretProvider.swift +++ b/AtalaPrismSDK/Pluto/Sources/Domain/Providers/LinkSecretProvider.swift @@ -3,5 +3,5 @@ import Domain import Foundation protocol LinkSecretProvider { - func getAll() -> AnyPublisher<[StorableKey], Error> + func getLinkSecret() -> AnyPublisher } diff --git a/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDDIDPrivateKeyDAO+DIDPrivateKeyProvider.swift b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDDIDPrivateKeyDAO+DIDPrivateKeyProvider.swift index 75ea0d5b..0c1dbedf 100644 --- a/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDDIDPrivateKeyDAO+DIDPrivateKeyProvider.swift +++ b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDDIDPrivateKeyDAO+DIDPrivateKeyProvider.swift @@ -10,7 +10,7 @@ extension CDDIDPrivateKeyDAO: DIDPrivateKeyProvider { try $0.map { ( DID(from: $0), - try $0.keys.map { try $0.parseToStorableKey(keychain: self.keyDao.keychain) }, + try $0.keys.map { try $0.parseToStorableKey(keychain: self.keyDao.keychainDao.keychain) }, $0.alias ) } @@ -24,7 +24,7 @@ extension CDDIDPrivateKeyDAO: DIDPrivateKeyProvider { try $0.map { ( DID(from: $0), - try $0.keys.map { try $0.parseToStorableKey(keychain: self.keyDao.keychain) }, + try $0.keys.map { try $0.parseToStorableKey(keychain: self.keyDao.keychainDao.keychain) }, $0.alias ) } @@ -41,7 +41,7 @@ extension CDDIDPrivateKeyDAO: DIDPrivateKeyProvider { try $0.map { ( DID(from: $0), - try $0.keys.map { try $0.parseToStorableKey(keychain: self.keyDao.keychain) }, + try $0.keys.map { try $0.parseToStorableKey(keychain: self.keyDao.keychainDao.keychain) }, $0.alias ) } @@ -52,7 +52,7 @@ extension CDDIDPrivateKeyDAO: DIDPrivateKeyProvider { func getPrivateKeys(did: DID) -> AnyPublisher<[StorableKey]?, Error> { fetchByIDsPublisher(did.string, context: readContext) .tryMap { - try $0?.keys.map { try $0.parseToStorableKey(keychain: self.keyDao.keychain) } + try $0?.keys.map { try $0.parseToStorableKey(keychain: self.keyDao.keychainDao.keychain) } } .eraseToAnyPublisher() } diff --git a/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDDIDPrivateKeyDAO+DIDPrivateKeyStore.swift b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDDIDPrivateKeyDAO+DIDPrivateKeyStore.swift index 0c311b3f..9fc4a8d4 100644 --- a/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDDIDPrivateKeyDAO+DIDPrivateKeyStore.swift +++ b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDDIDPrivateKeyDAO+DIDPrivateKeyStore.swift @@ -14,16 +14,16 @@ extension CDDIDPrivateKeyDAO: DIDPrivateKeyStore { try storeKeychainKey( did: did, keychainKey: keychainKey, - service: self.keyDao.keychainService, + service: self.keyDao.keychainDao.keychainService, account: identifier, - keychain: self.keyDao.keychain + keychain: self.keyDao.keychainDao.keychain ) let cdkey = CDKeychainKey(entity: CDKeychainKey.entity(), insertInto: context) cdkey.parseFromStorableKey( keychainKey, did: cdobj, identifier: identifier, - service: self.keyDao.keychainService + service: self.keyDao.keychainDao.keychainService ) return cdkey as CDKey default: diff --git a/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDDatabaseKeyDAO.swift b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDDatabaseKeyDAO.swift new file mode 100644 index 00000000..f7f7da00 --- /dev/null +++ b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDDatabaseKeyDAO.swift @@ -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" +} diff --git a/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDKeyDAO+LinkSecretProvider.swift b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDKeyDAO+LinkSecretProvider.swift index 1c6e78ce..a20c105a 100644 --- a/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDKeyDAO+LinkSecretProvider.swift +++ b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDKeyDAO+LinkSecretProvider.swift @@ -3,9 +3,11 @@ import Foundation import Domain extension CDKeyDAO: LinkSecretProvider { - func getAll() -> AnyPublisher<[StorableKey], Error> { - fetchController(context: readContext) - .tryMap { try $0.map { try $0.parseToStorableKey(keychain: self.keychain) } } + func getLinkSecret() -> AnyPublisher { + fetchByIDsPublisher("linkSecret", context: readContext) + .tryMap { + try $0?.parseToStorableKey(keychain: self.keychainDao.keychain) + } .eraseToAnyPublisher() } } diff --git a/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDKeyDAO+LinkSecretStore.swift b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDKeyDAO+LinkSecretStore.swift index 32b9fb31..c27bcccf 100644 --- a/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDKeyDAO+LinkSecretStore.swift +++ b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDKeyDAO+LinkSecretStore.swift @@ -4,31 +4,33 @@ import Domain extension CDKeyDAO: LinkSecretStore { func addLinkSecret(_ linkSecret: StorableKey) -> AnyPublisher { - updateOrCreate("linkSecret", context: writeContext) { cdobj, context in - switch linkSecret { - case let keychainKey as KeychainStorableKey: + switch linkSecret { + case let keychainKey as KeychainStorableKey: + return keychainDao.updateOrCreate("linkSecret", context: writeContext) { cdobj, context in try storeKeychainKey( keychainKey: keychainKey, - service: self.keychainService, + service: self.keychainDao.keychainService, account: "linkSecret", - keychain: self.keychain + keychain: self.keychainDao.keychain ) - let cdkey = CDKeychainKey(entity: CDKeychainKey.entity(), insertInto: context) - cdkey.parseFromStorableKey( + cdobj.parseFromStorableKey( keychainKey, identifier: "linkSecret", - service: self.keychainService + service: self.keychainDao.keychainService ) - default: - let cdkey = CDDatabaseKey(entity: CDDatabaseKey.entity(), insertInto: context) - cdkey.parseFromStorableKey( + } + .map { _ in } + .eraseToAnyPublisher() + default: + return databaseDAO.updateOrCreate("linkSecret", context: writeContext) { cdobj, context in + cdobj.parseFromStorableKey( linkSecret, identifier: "linkSecret" ) } + .map { _ in } + .eraseToAnyPublisher() } - .map { _ in } - .eraseToAnyPublisher() } } diff --git a/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDKeyDAO.swift b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDKeyDAO.swift index 1268ca77..81ca0b66 100644 --- a/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDKeyDAO.swift +++ b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDKeyDAO.swift @@ -4,11 +4,31 @@ import Domain struct CDKeyDAO: CoreDataDAO { typealias CoreDataObject = CDKey - let keychain: KeychainStore & KeychainProvider - let keychainService: String + let keychainDao: CDKeychainKeyDAO + let databaseDAO: CDDatabaseKeyDAO let readContext: NSManagedObjectContext let writeContext: NSManagedObjectContext let identifierKey: String? = "identifier" + + init( + keychain: KeychainStore & KeychainProvider, + keychainService: String, + readContext: NSManagedObjectContext, + writeContext: NSManagedObjectContext + ) { + self.keychainDao = CDKeychainKeyDAO( + keychain: keychain, + keychainService: keychainService, + readContext: readContext, + writeContext: writeContext + ) + self.databaseDAO = CDDatabaseKeyDAO( + readContext: readContext, + writeContext: writeContext + ) + self.readContext = readContext + self.writeContext = writeContext + } } extension CDKey { diff --git a/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDKeychainKeyDAO.swift b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDKeychainKeyDAO.swift new file mode 100644 index 00000000..1d6d8aaa --- /dev/null +++ b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDKeychainKeyDAO.swift @@ -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" +} diff --git a/AtalaPrismSDK/Pluto/Sources/PlutoImpl+Public.swift b/AtalaPrismSDK/Pluto/Sources/PlutoImpl+Public.swift index 01cf3bc2..4f4c550c 100644 --- a/AtalaPrismSDK/Pluto/Sources/PlutoImpl+Public.swift +++ b/AtalaPrismSDK/Pluto/Sources/PlutoImpl+Public.swift @@ -171,7 +171,7 @@ extension PlutoImpl: Pluto { keyDao.addLinkSecret(secret) } - public func getLinkSecret() -> AnyPublisher<[StorableKey], Error> { - keyDao.getAll() + public func getLinkSecret() -> AnyPublisher { + keyDao.getLinkSecret() } } diff --git a/AtalaPrismSDK/Pollux/Sources/Models/AnonCreds/AnonCredentialSchema.swift b/AtalaPrismSDK/Pollux/Sources/Models/AnonCreds/AnonCredentialSchema.swift index f4c38057..2e7e4ce0 100644 --- a/AtalaPrismSDK/Pollux/Sources/Models/AnonCreds/AnonCredentialSchema.swift +++ b/AtalaPrismSDK/Pollux/Sources/Models/AnonCreds/AnonCredentialSchema.swift @@ -6,3 +6,7 @@ struct AnonCredentialSchema: Codable { let attrNames: [String] let issuerId: String } + +struct SchemaAnonCredentialSchema: Codable { + let schema: AnonCredentialSchema +} diff --git a/AtalaPrismSDK/Pollux/Sources/Operation/Anoncreds/ParseAnoncredsCredentialFromMessage.swift b/AtalaPrismSDK/Pollux/Sources/Operation/Anoncreds/ParseAnoncredsCredentialFromMessage.swift index 4551267f..221555f2 100644 --- a/AtalaPrismSDK/Pollux/Sources/Operation/Anoncreds/ParseAnoncredsCredentialFromMessage.swift +++ b/AtalaPrismSDK/Pollux/Sources/Operation/Anoncreds/ParseAnoncredsCredentialFromMessage.swift @@ -44,7 +44,6 @@ struct ParseAnoncredsCredentialFromMessage { let processedCredentialJson = try processedCredential.getJson().tryData(using: .utf8) let finalCredential = try JSONDecoder().decode(AnonCredential.self, from: processedCredentialJson) - return AnoncredsCredentialStack( schema: try JSONDecoder.didComm().decode(AnonCredentialSchema.self, from: schemaData), definition: try JSONDecoder.didComm().decode(AnonCredentialDefinition.self, from: credentialDefinitionData), diff --git a/AtalaPrismSDK/Pollux/Tests/Mocks/MockPluto.swift b/AtalaPrismSDK/Pollux/Tests/Mocks/MockPluto.swift index 2063b113..af50b17b 100644 --- a/AtalaPrismSDK/Pollux/Tests/Mocks/MockPluto.swift +++ b/AtalaPrismSDK/Pollux/Tests/Mocks/MockPluto.swift @@ -154,7 +154,7 @@ class MockPluto: Pluto { self.credentials.publisher.collect().tryMap { $0 }.eraseToAnyPublisher() } - func getLinkSecret() -> AnyPublisher<[StorableKey], Error> { - return Just([]).tryMap { $0 }.eraseToAnyPublisher() + func getLinkSecret() -> AnyPublisher { + return Just(nil).tryMap { $0 }.eraseToAnyPublisher() } } diff --git a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Credentials.swift b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Credentials.swift index a81bd9bf..3346efc2 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Credentials.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Credentials.swift @@ -13,8 +13,8 @@ public extension PrismAgent { func verifiableCredentials() -> AnyPublisher<[Credential], Error> { let pollux = self.pollux return pluto.getAllCredentials().tryMap { - try $0.map { - try pollux.restoreCredential( + $0.compactMap { + try? pollux.restoreCredential( restorationIdentifier: $0.recoveryId, credentialData: $0.credentialData ) @@ -31,7 +31,7 @@ public extension PrismAgent { /// - Throws: PrismAgentError, if there is a problem parsing the credential. func processIssuedCredentialMessage(message: IssueCredential3_0) async throws -> Credential { guard - let linkSecret = try await pluto.getLinkSecret().first().await().first + let linkSecret = try await pluto.getLinkSecret().first().await() else { throw PrismAgentError.cannotFindDIDKeyPairIndex } let restored = try await self.apollo.restoreKey(linkSecret) @@ -79,7 +79,7 @@ public extension PrismAgent { guard let exporting = privateKey.exporting, - let linkSecret = try await pluto.getLinkSecret().first().await().first + let linkSecret = try await pluto.getLinkSecret().first().await() else { throw PrismAgentError.cannotFindDIDKeyPairIndex } let restored = try await self.apollo.restoreKey(linkSecret) diff --git a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Proof.swift b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Proof.swift index 7482a7f5..adc2ce6d 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Proof.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+Proof.swift @@ -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/proof-request@v1.0": + 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, diff --git a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent.swift b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent.swift index bb1a6eb6..02571fd6 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent.swift @@ -195,7 +195,7 @@ public class PrismAgent { } private func firstLinkSecretSetup() async throws { - if try await pluto.getLinkSecret().first().await().first == nil { + if try await pluto.getLinkSecret().first().await() == nil { let secret = try apollo.createNewLinkSecret() guard let storableSecret = secret.storable else { throw UnknownError diff --git a/AtalaPrismSDK/PrismAgent/Sources/Protocols/Connection/DownloadDataWithResolver.swift b/AtalaPrismSDK/PrismAgent/Sources/Protocols/Connection/DownloadDataWithResolver.swift index 392760bf..9326db29 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/Protocols/Connection/DownloadDataWithResolver.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/Protocols/Connection/DownloadDataWithResolver.swift @@ -10,7 +10,7 @@ public struct DownloadDataWithResolver: Downloader { public func downloadFromEndpoint(urlOrDID: String) async throws -> Data { let url: URL - + if let did = try? castor.parseDID(str: urlOrDID) { let document = try await castor.resolveDID(did: did) guard @@ -20,7 +20,7 @@ public struct DownloadDataWithResolver: Downloader { throw CommonError.invalidURLError(url: "Could not find any URL on DID") } url = validUrl - } else if let validUrl = URL(string: urlOrDID) { + } else if let validUrl = URL(string: urlOrDID.replacingOccurrences(of: "host.docker.internal", with: "localhost")) { url = validUrl } else { throw CommonError.invalidURLError(url: urlOrDID) diff --git a/Sample/AtalaPrismWalletDemo/AtalaPrismWalletDemo/Modules/SetupPrismAgent/SetupPrismAgentViewModel.swift b/Sample/AtalaPrismWalletDemo/AtalaPrismWalletDemo/Modules/SetupPrismAgent/SetupPrismAgentViewModel.swift index ab26b213..4e2cf4ce 100644 --- a/Sample/AtalaPrismWalletDemo/AtalaPrismWalletDemo/Modules/SetupPrismAgent/SetupPrismAgentViewModel.swift +++ b/Sample/AtalaPrismWalletDemo/AtalaPrismWalletDemo/Modules/SetupPrismAgent/SetupPrismAgentViewModel.swift @@ -78,11 +78,7 @@ final class SetupPrismAgentViewModelImpl: ObservableObject, SetupPrismAgentViewM _ = try issued.attachments.compactMap { switch $0.data { case let data as AttachmentBase64: - let b64 = Data(base64URLEncoded: data.base64)! - let apollo = ApolloBuilder().build() - let castor = CastorBuilder(apollo: apollo).build() - let pollux = PolluxBuilder().build() -// let credential = try pollux.parseCredential(data: b64) + break default: return } diff --git a/Sample/AtalaPrismWalletDemo/AtalaPrismWalletDemo/Modules/WalletDemo2/Main/Main2Router.swift b/Sample/AtalaPrismWalletDemo/AtalaPrismWalletDemo/Modules/WalletDemo2/Main/Main2Router.swift index a8d30580..b0677028 100644 --- a/Sample/AtalaPrismWalletDemo/AtalaPrismWalletDemo/Modules/WalletDemo2/Main/Main2Router.swift +++ b/Sample/AtalaPrismWalletDemo/AtalaPrismWalletDemo/Modules/WalletDemo2/Main/Main2Router.swift @@ -11,7 +11,7 @@ final class Main2RouterImpl: Main2ViewRouter { let apollo = ApolloBuilder().build() let castor = CastorBuilder(apollo: apollo).build() let pluto = PlutoBuilder().build() - let pollux = PolluxBuilder().build() + let pollux = PolluxBuilder(pluto: pluto).build() let mercury = MercuryBuilder( castor: castor, secretsStream: createSecretsStream( diff --git a/Sample/AtalaPrismWalletDemo/AtalaPrismWalletDemo/Modules/WalletDemo2/Messages/MessageDetail/MessageDetailViewModel.swift b/Sample/AtalaPrismWalletDemo/AtalaPrismWalletDemo/Modules/WalletDemo2/Messages/MessageDetail/MessageDetailViewModel.swift index 0ff14703..50213529 100644 --- a/Sample/AtalaPrismWalletDemo/AtalaPrismWalletDemo/Modules/WalletDemo2/Messages/MessageDetail/MessageDetailViewModel.swift +++ b/Sample/AtalaPrismWalletDemo/AtalaPrismWalletDemo/Modules/WalletDemo2/Messages/MessageDetail/MessageDetailViewModel.swift @@ -135,18 +135,13 @@ private func getSpecificByType(msg: Message) -> MessageDetailViewState.SpecificD } switch msgType { case .didcommRequestPresentation: - do { - let (domain, challenge) = try getDomainAndChallenge(msg: msg) - return .credentialDomainChallenge(domain: domain, challenge: challenge) - } catch { - return .finishedThreads - } + return .acceptRefuse case .didcommIssueCredential, .didcommIssueCredential3_0: return .finishedThreads case .didcommOfferCredential: do { let (domain, challenge) = try getDomainAndChallenge(msg: msg) - return .credentialDomainChallenge(domain: domain, challenge: challenge) + return .credentialDomainChallenge(domain: domain ?? "", challenge: challenge ?? "") } catch { return .acceptRefuse } @@ -163,7 +158,7 @@ private func getSpecificByType(msg: Message) -> MessageDetailViewState.SpecificD } } -private func getDomainAndChallenge(msg: Message) throws -> (domain: String, challenge: String) { +private func getDomainAndChallenge(msg: Message) throws -> (domain: String?, challenge: String?) { guard let offerData = msg .attachments .map({ @@ -178,11 +173,7 @@ private func getDomainAndChallenge(msg: Message) throws -> (domain: String, chal .first else { throw PolluxError.offerDoesntProvideEnoughInformation } let jsonObject = try JSONSerialization.jsonObject(with: offerData) - guard - let domain = findValue(forKey: "domain", in: jsonObject), - let challenge = findValue(forKey: "challenge", in: jsonObject) - else { throw PolluxError.offerDoesntProvideEnoughInformation } - return (domain, challenge) + return (findValue(forKey: "domain", in: jsonObject), findValue(forKey: "challenge", in: jsonObject)) } private func findValue(forKey key: String, in json: Any) -> String? {