From 62654fdab4e924330b4e687151e0b8b3d0a8c8f6 Mon Sep 17 00:00:00 2001 From: Goncalo-FradeIOHK Date: Wed, 1 Mar 2023 18:55:21 +0000 Subject: [PATCH] feat(mercury): fix mercury issues --- .../Domain/Sources/Models/Errors.swift | 7 ++ .../PackEncryptedOperation.swift | 5 +- .../DIDCommWrappers/UnpackOperation.swift | 1 - .../Sources/MecuryImpl+SendMessage.swift | 46 ++++++++-- .../Mercury/Sources/MercuryImpl+Public.swift | 4 +- .../Mercury/Sources/MercuryImpl.swift | 6 +- ...DDIDPrivateKeyDAO+DIDPrivateKeyStore.swift | 2 +- .../Model.xcdatamodel/contents | 2 - .../PrismAgent+DIDHigherFucntions.swift | 15 ++-- .../Sources/PrismAgent+MessageEvents.swift | 39 +-------- .../PrismAgent/Sources/PrismAgent.swift | 84 +++++++++---------- .../Mediation/MediationKeysUpdateList.swift | 1 - .../Protocols/Others/BasicMessage.swift | 61 ++++++++++++++ .../Sources/Protocols/ProtocolTypes.swift | 1 + .../DIDChat/Modules/ChatView/ChatView.swift | 1 + .../Modules/ChatView/ChatViewModel.swift | 1 + .../Modules/ContactsView/ContactsView.swift | 2 +- .../ContactsView/ContactsViewState.swift | 10 +++ .../MediatorView/MediatorViewModel.swift | 3 +- Sample/DIDChat/DIDChat/PrismChatMessage.swift | 53 ------------ 20 files changed, 188 insertions(+), 156 deletions(-) delete mode 100644 AtalaPrismSDK/Pluto/Sources/Resources/PrismPluto.xcdatamodeld/Model.xcdatamodel/contents create mode 100644 AtalaPrismSDK/PrismAgent/Sources/Protocols/Others/BasicMessage.swift delete mode 100644 Sample/DIDChat/DIDChat/PrismChatMessage.swift diff --git a/AtalaPrismSDK/Domain/Sources/Models/Errors.swift b/AtalaPrismSDK/Domain/Sources/Models/Errors.swift index cde54293..440416f3 100644 --- a/AtalaPrismSDK/Domain/Sources/Models/Errors.swift +++ b/AtalaPrismSDK/Domain/Sources/Models/Errors.swift @@ -383,6 +383,13 @@ public enum MercuryError: KnownPrismError { /// An error case representing invalid body data in a message. case messageInvalidBodyDataError + + /** + An error case representing a DIDComm error. + - Parameters: + - msg: The message describing the error. + - underlyingErrors: An array of underlying errors that may have contributed to this error, if provided. + */ case didcommError(msg: String, underlyingErrors: [Error]? = nil) /// The error code returned by the server. diff --git a/AtalaPrismSDK/Mercury/Sources/DIDCommWrappers/PackEncryptedOperation.swift b/AtalaPrismSDK/Mercury/Sources/DIDCommWrappers/PackEncryptedOperation.swift index d3cc957c..07925b66 100644 --- a/AtalaPrismSDK/Mercury/Sources/DIDCommWrappers/PackEncryptedOperation.swift +++ b/AtalaPrismSDK/Mercury/Sources/DIDCommWrappers/PackEncryptedOperation.swift @@ -44,7 +44,10 @@ final class PackEncryptedOperation: OnPackEncryptedResult { continuation.resume(returning: result) }) do { - print("Packing message \(message.piuri) sender:\(fromDID) \nto:\(toDID)") + logger.debug(message: "Packing message \(message.piuri)", metadata: [ + .maskedMetadataByLevel(key: "Sender", value: fromDID.string, level: .debug), + .maskedMetadataByLevel(key: "Receiver", value: toDID.string, level: .debug) + ]) let status = didcomm.packEncrypted( msg: try DIDCommxSwift.Message(domain: message, mediaType: .contentTypePlain), to: toDID.string, diff --git a/AtalaPrismSDK/Mercury/Sources/DIDCommWrappers/UnpackOperation.swift b/AtalaPrismSDK/Mercury/Sources/DIDCommWrappers/UnpackOperation.swift index 82f5b047..5fa78939 100644 --- a/AtalaPrismSDK/Mercury/Sources/DIDCommWrappers/UnpackOperation.swift +++ b/AtalaPrismSDK/Mercury/Sources/DIDCommWrappers/UnpackOperation.swift @@ -84,7 +84,6 @@ Error on parsing DIDComm library model message to Domain message : \(error.local } func error(err: DIDCommxSwift.ErrorKind, msg: String) { - print(err.localizedDescription) let error = MercuryError.didcommError( msg: """ diff --git a/AtalaPrismSDK/Mercury/Sources/MecuryImpl+SendMessage.swift b/AtalaPrismSDK/Mercury/Sources/MecuryImpl+SendMessage.swift index de98ad3e..5742078e 100644 --- a/AtalaPrismSDK/Mercury/Sources/MecuryImpl+SendMessage.swift +++ b/AtalaPrismSDK/Mercury/Sources/MecuryImpl+SendMessage.swift @@ -10,7 +10,6 @@ extension MercuryImpl { public func sendMessage(_ msg: Message) async throws -> Data? { guard let toDID = msg.to else { throw MercuryError.noRecipientDIDSetError } guard let fromDID = msg.from else { throw MercuryError.noRecipientDIDSetError } - print("Send message \(msg.piuri) sender:\(fromDID.string) \nto:\(toDID.string)") let document = try await castor.resolveDID(did: toDID) let originalPackedMessage = try await packMessage(msg: msg) @@ -24,8 +23,23 @@ extension MercuryImpl { encrypted: encryptedData, mediatorDID: mediatorDID ) - print("Send message \(forwardMessage.piuri) sender:\(forwardMessage.from?.string) \nto:\(forwardMessage.to?.string)") - let forwardPackedMessage = try await packMessage(msg: forwardMessage) + + logger.debug( + message: "Sending forward message with internal message type \(msg.piuri)", + metadata: [ + .maskedMetadataByLevel( + key: "Sender", + value: forwardMessage.from.string, + level: .debug + ), + .maskedMetadataByLevel( + key: "Receiver", + value: forwardMessage.to.string, + level: .debug + ) + ] + ) + let forwardPackedMessage = try await packMessage(msg: forwardMessage.makeMessage()) let mediatorDocument = try await castor.resolveDID(did: mediatorDID) guard let url = getDIDCommURL(document: mediatorDocument), @@ -41,6 +55,21 @@ extension MercuryImpl { else { throw MercuryError.noValidServiceFoundError(did: toDID.string) } + logger.debug( + message: "Sending message with type \(msg.piuri)", + metadata: [ + .maskedMetadataByLevel( + key: "Sender", + value: fromDID.string, + level: .debug + ), + .maskedMetadataByLevel( + key: "Receiver", + value: toDID.string, + level: .debug + ) + ] + ) return try await sendHTTPMessage(url: url, packedMessage: data) } } @@ -56,7 +85,6 @@ extension MercuryImpl { let msgStr = String(data: msgData, encoding: .utf8), msgStr != "null" else { return nil } - print("Data returned: \(msgStr)") return try? await self.unpackMessage(msg: msgStr) } @@ -67,15 +95,19 @@ extension MercuryImpl { headers: ["content-type": MediaType.contentTypeEncrypted.rawValue] ) } - private func prepareForwardMessage(msg: Message, encrypted: Data, mediatorDID: DID) throws -> Message { + private func prepareForwardMessage( + msg: Message, + encrypted: Data, + mediatorDID: DID + ) throws -> ForwardMessage { guard let fromDID = msg.from else { throw MercuryError.noSenderDIDSetError } guard let toDID = msg.to else { throw MercuryError.noRecipientDIDSetError } - return try ForwardMessage( + return ForwardMessage( from: fromDID, to: mediatorDID, body: .init(next: toDID.string), encryptedJsonMessage: encrypted - ).makeMessage() + ) } private func getDIDCommURL(document: DIDDocument) -> URL? { diff --git a/AtalaPrismSDK/Mercury/Sources/MercuryImpl+Public.swift b/AtalaPrismSDK/Mercury/Sources/MercuryImpl+Public.swift index 8cc5bb86..d54c3a6c 100644 --- a/AtalaPrismSDK/Mercury/Sources/MercuryImpl+Public.swift +++ b/AtalaPrismSDK/Mercury/Sources/MercuryImpl+Public.swift @@ -10,7 +10,7 @@ extension MercuryImpl: Mercury { /// - Returns: The string representation of the packed message /// - Throws: An error if the message object is invalid public func packMessage(msg: Domain.Message) async throws -> String { - try await PackEncryptedOperation(didcomm: didcomm, message: msg, logger: logger).packEncrypted() + try await PackEncryptedOperation(didcomm: getDidcomm(), message: msg, logger: logger).packEncrypted() } /// unpackMessage asynchronously unpacks a given string representation of a message into a message object. This function may throw an error if the string is not a valid message representation. @@ -19,6 +19,6 @@ extension MercuryImpl: Mercury { /// - Returns: The message object /// - Throws: An error if the string is not a valid message representation public func unpackMessage(msg: String) async throws -> Domain.Message { - try await UnpackOperation(didcomm: didcomm, castor: castor, logger: logger).unpackEncrypted(messageString: msg) + try await UnpackOperation(didcomm: getDidcomm(), castor: castor, logger: logger).unpackEncrypted(messageString: msg) } } diff --git a/AtalaPrismSDK/Mercury/Sources/MercuryImpl.swift b/AtalaPrismSDK/Mercury/Sources/MercuryImpl.swift index 3100b54b..b46f5e2e 100644 --- a/AtalaPrismSDK/Mercury/Sources/MercuryImpl.swift +++ b/AtalaPrismSDK/Mercury/Sources/MercuryImpl.swift @@ -8,7 +8,6 @@ public struct MercuryImpl { let castor: Castor let apollo: Apollo let pluto: Pluto - let didcomm: DidComm let logger: PrismLogger public init( @@ -24,6 +23,9 @@ public struct MercuryImpl { self.castor = castor self.apollo = apollo self.pluto = pluto + } + + func getDidcomm() -> DidComm { let didResolver = DIDCommDIDResolverWrapper(castor: castor, logger: logger) let secretsResolver = DIDCommSecretsResolverWrapper( apollo: apollo, @@ -31,7 +33,7 @@ public struct MercuryImpl { castor: castor, logger: logger ) - self.didcomm = DidComm( + return DidComm( didResolver: didResolver, secretResolver: secretsResolver ) diff --git a/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDDIDPrivateKeyDAO+DIDPrivateKeyStore.swift b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDDIDPrivateKeyDAO+DIDPrivateKeyStore.swift index 4d181909..feea0bfd 100644 --- a/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDDIDPrivateKeyDAO+DIDPrivateKeyStore.swift +++ b/AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDDIDPrivateKeyDAO+DIDPrivateKeyStore.swift @@ -21,6 +21,7 @@ extension CDDIDPrivateKeyDAO: DIDPrivateKeyStore { private extension CDDIDPrivateKey { func parseFrom(did: DID, privateKeys: [PrivateKey], alias: String?) { + self.alias = alias self.did = did.string self.schema = did.schema self.method = did.method @@ -37,7 +38,6 @@ private extension CDDIDPrivateKey { break } } - self.alias = alias } } diff --git a/AtalaPrismSDK/Pluto/Sources/Resources/PrismPluto.xcdatamodeld/Model.xcdatamodel/contents b/AtalaPrismSDK/Pluto/Sources/Resources/PrismPluto.xcdatamodeld/Model.xcdatamodel/contents deleted file mode 100644 index e47a122d..00000000 --- a/AtalaPrismSDK/Pluto/Sources/Resources/PrismPluto.xcdatamodeld/Model.xcdatamodel/contents +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+DIDHigherFucntions.swift b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+DIDHigherFucntions.swift index 4227c348..f86a93c1 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+DIDHigherFucntions.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+DIDHigherFucntions.swift @@ -231,12 +231,6 @@ Could not find key in storage please use Castor instead and provide the private } } - func getAllRegisteredPeerDIDs() -> AnyPublisher<[(did: DID, alias: String?)], Error> { - pluto.getAllPeerDIDs() - .map { $0.map { ($0.did, $0.alias) } } - .eraseToAnyPublisher() - } - /// This function registers a DID pair in the `pluto` store /// /// - Parameter pair: The DID pair to register @@ -253,4 +247,13 @@ Could not find key in storage please use Castor instead and provide the private func getAllDIDPairs() -> AnyPublisher<[DIDPair], Error> { pluto.getAllDidPairs() } + + /// This function gets all the DID peers from the `pluto` store + /// + /// - Returns: A publisher that emits an array of tuples (`DID`, `String?`) objects, or an error if there was a problem getting the dids + func getAllRegisteredPeerDIDs() -> AnyPublisher<[(did: DID, alias: String?)], Error> { + pluto.getAllPeerDIDs() + .map { $0.map { ($0.did, $0.alias) } } + .eraseToAnyPublisher() + } } diff --git a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+MessageEvents.swift b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+MessageEvents.swift index 6a9b9145..7f153e36 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+MessageEvents.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent+MessageEvents.swift @@ -5,8 +5,8 @@ import Foundation // MARK: Messaging events funcionalities public extension PrismAgent { /// Start fetching the messages from the mediator - func startFetchingMessages() { - // Check if messagesStreamTask is nil + func startFetchingMessages(timeBetweenRequests: Int = 5) { + let timeInterval = max(timeBetweenRequests, 5) guard messagesStreamTask == nil else { return } logger.info(message: "Start streaming new unread messages") @@ -22,7 +22,7 @@ public extension PrismAgent { // Handle errors that occur during the message fetching process logger.error(error: error) } - sleep(90) + sleep(UInt32(timeInterval)) } } } @@ -56,39 +56,6 @@ public extension PrismAgent { func handleReceivedMessagesEvents() -> AnyPublisher { pluto.getAllMessagesReceived() .flatMap { $0.publisher } - .print() .eraseToAnyPublisher() -// .flatMap { message -> AnyPublisher in -// if let issueCredential = try? IssueCredential(fromMessage: message) { -// let credentials = try? issueCredential.getCredentialStrings().map { -// try pollux.parseVerifiableCredential(jwtString: $0) -// } -// guard let credential = credentials?.first else { -// return Just(message) -// .tryMap { $0 } -// .eraseToAnyPublisher() -// } -// return pluto -// .storeCredential(credential: credential) -// .map { message } -// .eraseToAnyPublisher() -// } -// return Just(message) -// .tryMap { $0 } -// .eraseToAnyPublisher() -// } -// .flatMap { [weak self] message -> AnyPublisher in -// if -// let self, -// let request = try? RequestPresentation(fromMessage: message), -// !self.requestedPresentations.value.contains(where: { $0.0.id == request.id }) -// { -// self.requestedPresentations.value = self.requestedPresentations.value + [(request, false)] -// } -// return Just(message) -// .tryMap { $0 } -// .eraseToAnyPublisher() -// } -// .eraseToAnyPublisher() } } diff --git a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent.swift b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent.swift index d6e9cf76..fb840622 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/PrismAgent.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/PrismAgent.swift @@ -160,48 +160,48 @@ public class PrismAgent { logger.info(message: "Agent not running") } - // TODO: This is to be deleted in the future. For now it helps with proof of request logic - public func presentCredentialProof( - request: RequestPresentation, - credential: VerifiableCredential - ) async throws { - guard let jwtBase64 = credential.id.data(using: .utf8)?.base64UrlEncodedString() else { - throw UnknownError.somethingWentWrongError( - customMessage: "Could not decode JWT Credential", - underlyingErrors: nil - ) - } - let presentation = Presentation( - body: .init(goalCode: request.body.goalCode, comment: request.body.comment), - attachments: [try .build( - payload: AttachmentBase64(base64: jwtBase64), - mediaType: "prism/jwt" - )], - thid: request.id, - from: request.to, - to: request.from - ) - _ = try await connectionManager.sendMessage(presentation.makeMessage()) - } - - // TODO: This is to be deleted in the future. For now it helps with issue credentials logic - public func issueCredentialProtocol() { - startFetchingMessages() - Task { - do { - for try await offer in handleReceivedMessagesEvents() - .drop(while: { (try? OfferCredential(fromMessage: $0)) != nil }) - .values - { - if let issueProtocol = try? IssueCredentialProtocol(offer, connector: connectionManager) { - try? await issueProtocol.nextStage() - } - } - } catch { - print(error.localizedDescription) - } - } - } +// // TODO: This is to be deleted in the future. For now it helps with proof of request logic +// public func presentCredentialProof( +// request: RequestPresentation, +// credential: VerifiableCredential +// ) async throws { +// guard let jwtBase64 = credential.id.data(using: .utf8)?.base64UrlEncodedString() else { +// throw UnknownError.somethingWentWrongError( +// customMessage: "Could not decode JWT Credential", +// underlyingErrors: nil +// ) +// } +// let presentation = Presentation( +// body: .init(goalCode: request.body.goalCode, comment: request.body.comment), +// attachments: [try .build( +// payload: AttachmentBase64(base64: jwtBase64), +// mediaType: "prism/jwt" +// )], +// thid: request.id, +// from: request.to, +// to: request.from +// ) +// _ = try await connectionManager.sendMessage(presentation.makeMessage()) +// } +// +// // TODO: This is to be deleted in the future. For now it helps with issue credentials logic +// public func issueCredentialProtocol() { +// startFetchingMessages() +// Task { +// do { +// for try await offer in handleReceivedMessagesEvents() +// .drop(while: { (try? OfferCredential(fromMessage: $0)) != nil }) +// .values +// { +// if let issueProtocol = try? IssueCredentialProtocol(offer, connector: connectionManager) { +// try? await issueProtocol.nextStage() +// } +// } +// } catch { +// print(error.localizedDescription) +// } +// } +// } } extension DID { diff --git a/AtalaPrismSDK/PrismAgent/Sources/Protocols/Mediation/MediationKeysUpdateList.swift b/AtalaPrismSDK/PrismAgent/Sources/Protocols/Mediation/MediationKeysUpdateList.swift index dadd5910..f0a626e9 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/Protocols/Mediation/MediationKeysUpdateList.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/Protocols/Mediation/MediationKeysUpdateList.swift @@ -26,7 +26,6 @@ struct MediationKeysUpdateList { self.id = id self.from = from self.to = to - print(recipientDids.map { $0.string }) self.body = .init( updates: recipientDids.map { Body.Update(recipientDid: $0.string) diff --git a/AtalaPrismSDK/PrismAgent/Sources/Protocols/Others/BasicMessage.swift b/AtalaPrismSDK/PrismAgent/Sources/Protocols/Others/BasicMessage.swift new file mode 100644 index 00000000..131e51ba --- /dev/null +++ b/AtalaPrismSDK/PrismAgent/Sources/Protocols/Others/BasicMessage.swift @@ -0,0 +1,61 @@ +import Core +import Domain +import Foundation + +public struct BasicMessage { + + public struct Body: Codable { + public let content: String + + public init(content: String) { + self.content = content + } + } + + public let id: String + public let type = ProtocolTypes.didcommBasicMessage.rawValue + public let from: DID + public let to: DID + public let date: Date + public let body: Body + + public init( + id: String = UUID().uuidString, + from: DID, + to: DID, + body: Body, + date: Date = Date() + ) { + self.id = id + self.from = from + self.to = to + self.body = body + self.date = date + } + + public init?(fromMessage: Message) throws { + guard + fromMessage.piuri == ProtocolTypes.didcommBasicMessage.rawValue, + let from = fromMessage.from, + let to = fromMessage.to + else { + return nil + } + self.id = fromMessage.id + self.from = from + self.to = to + self.body = try JSONDecoder.didComm().decode(Body.self, from: fromMessage.body) + self.date = fromMessage.createdTime + } + + public func makeMessage() throws -> Message { + return Message( + id: id, + piuri: type, + from: from, + to: to, + body: try JSONEncoder.didComm().encode(body), + createdTime: date + ) + } +} diff --git a/AtalaPrismSDK/PrismAgent/Sources/Protocols/ProtocolTypes.swift b/AtalaPrismSDK/PrismAgent/Sources/Protocols/ProtocolTypes.swift index a99478df..3a338a04 100644 --- a/AtalaPrismSDK/PrismAgent/Sources/Protocols/ProtocolTypes.swift +++ b/AtalaPrismSDK/PrismAgent/Sources/Protocols/ProtocolTypes.swift @@ -1,6 +1,7 @@ import Foundation enum ProtocolTypes: String { + case didcommBasicMessage = "https://didcomm.org/basicmessage/2.0/message" case didcommMediationRequest = "https://didcomm.org/coordinate-mediation/2.0/mediate-request" case didcommMediationGrant = "https://didcomm.org/coordinate-mediation/2.0/mediate-grant" case didcommMediationDeny = "https://didcomm.org/coordinate-mediation/2.0/mediate-deny" diff --git a/Sample/DIDChat/DIDChat/Modules/ChatView/ChatView.swift b/Sample/DIDChat/DIDChat/Modules/ChatView/ChatView.swift index 8e5e50fd..f5dba425 100644 --- a/Sample/DIDChat/DIDChat/Modules/ChatView/ChatView.swift +++ b/Sample/DIDChat/DIDChat/Modules/ChatView/ChatView.swift @@ -24,6 +24,7 @@ struct ChatView: View { MessageView(text: message.text, isSent: message.sent) } } + .padding() HStack { TextField("Type your message...", text: $viewModel.sendingText) diff --git a/Sample/DIDChat/DIDChat/Modules/ChatView/ChatViewModel.swift b/Sample/DIDChat/DIDChat/Modules/ChatView/ChatViewModel.swift index 4d121e26..0e3209df 100644 --- a/Sample/DIDChat/DIDChat/Modules/ChatView/ChatViewModel.swift +++ b/Sample/DIDChat/DIDChat/Modules/ChatView/ChatViewModel.swift @@ -61,6 +61,7 @@ final class ChatViewModelImpl: ChatViewModel { )) self.messages = self.messageList.sorted { $0.date < $1.date } + self.sendingText = "" } } } diff --git a/Sample/DIDChat/DIDChat/Modules/ContactsView/ContactsView.swift b/Sample/DIDChat/DIDChat/Modules/ContactsView/ContactsView.swift index 67b06537..317d992d 100644 --- a/Sample/DIDChat/DIDChat/Modules/ContactsView/ContactsView.swift +++ b/Sample/DIDChat/DIDChat/Modules/ContactsView/ContactsView.swift @@ -62,7 +62,7 @@ struct AddContactView: View { @EnvironmentObject var viewModel: ViewModel @Environment(\.presentationMode) var presentationMode @State var newContactName: String = "Bob" - @State var newContactPeerDID: String = "did:peer:2.Ez6LSpAMSF7BxhxJEqWApn258toZ3RYFD5Bp6TaCCE1JkSNZW.Vz6MkmSoU3wZ1TfXEmrC8nzm5WvHvxrg8mmxe1BnGAZPXzTpR.SeyJyIjpbXSwicyI6ImRpZDpwZWVyOjIuRXo2TFNtaWJDSkxkeHFTc21hYUJ1c1NrUXdYek1ZUnFVTHRCWEdaWDd1dERKSE5HbS5WejZNa293a0Vxd1dEVVM0TUNOTG50UFpHVGV0YWM3dGtKbk1HWVB2eDlnZmh1N2RyLlNleUpwWkNJNkltNWxkeTFwWkNJc0luUWlPaUprYlNJc0luTWlPaUpvZEhSd2N6b3ZMMjFsWkdsaGRHOXlMbkp2YjNSemFXUXVZMnh2ZFdRaUxDSmhJanBiSW1ScFpHTnZiVzB2ZGpJaVhYMCIsImEiOltdLCJ0IjoiZG0ifQ" + @State var newContactPeerDID: String = "did:peer:2.Ez6LSc9cZDE5ioLyEV9WKtcpejzr7GvzcWHHP8rwnWeZwYyaV.Vz6MkkbB59SstKEkTLfLhGmc5iyesyMzCgmNuZqgMz3c4sLgy.SeyJyIjpbXSwicyI6ImRpZDpwZWVyOjIuRXo2TFNjUGI0ZG1GbUR3RXd2aGpLTXphN1p0TnhDRlVGeWkxb0xKSHF0REZDWWhTVC5WejZNa3J2TWFjV0daa3RiWk16UFdDQ2dCYUs1VEdYdGJSUlNWZk1rZmtROWlrTER0LlNleUpwWkNJNkltNWxkeTFwWkNJc0luUWlPaUprYlNJc0luTWlPaUpvZEhSd2N6b3ZMMjFsWkdsaGRHOXlMbkp2YjNSemFXUXVZMnh2ZFdRaUxDSmhJanBiSW1ScFpHTnZiVzB2ZGpJaVhYMCIsImEiOltdLCJ0IjoiZG0ifQ" @State var newPeerDIDAlias: String = "" var body: some View { diff --git a/Sample/DIDChat/DIDChat/Modules/ContactsView/ContactsViewState.swift b/Sample/DIDChat/DIDChat/Modules/ContactsView/ContactsViewState.swift index bdc525f2..6dad13eb 100644 --- a/Sample/DIDChat/DIDChat/Modules/ContactsView/ContactsViewState.swift +++ b/Sample/DIDChat/DIDChat/Modules/ContactsView/ContactsViewState.swift @@ -12,4 +12,14 @@ struct ContactsViewState { hasher.combine(name) } } + + struct PossibleContact: Identifiable, Hashable { + let id: String + let name: String + + func hash(into hasher: inout Hasher) { + hasher.combine(id) + hasher.combine(name) + } + } } diff --git a/Sample/DIDChat/DIDChat/Modules/MediatorView/MediatorViewModel.swift b/Sample/DIDChat/DIDChat/Modules/MediatorView/MediatorViewModel.swift index f4eabbe4..a3a584e0 100644 --- a/Sample/DIDChat/DIDChat/Modules/MediatorView/MediatorViewModel.swift +++ b/Sample/DIDChat/DIDChat/Modules/MediatorView/MediatorViewModel.swift @@ -29,7 +29,8 @@ class MediatorViewModelImpl: MediatorViewModel { do { PrismAgent.setupLogging(logLevels: [ .prismAgent: .debug, - .mercury: .debug + .mercury: .debug, + .castor: .debug ]) let agent = PrismAgent(mediatorDID: did) try await agent.start() diff --git a/Sample/DIDChat/DIDChat/PrismChatMessage.swift b/Sample/DIDChat/DIDChat/PrismChatMessage.swift deleted file mode 100644 index 7d42a45c..00000000 --- a/Sample/DIDChat/DIDChat/PrismChatMessage.swift +++ /dev/null @@ -1,53 +0,0 @@ -import Domain -import Foundation - -private let CHAT_MESSAGE_TYPE = "https://atalaprism.io/chat/message/1.0/send" - -struct PrismChatMessage { - let id: String - let type = CHAT_MESSAGE_TYPE - let from: DID - let to: DID - let date: Date - let text: String - - init( - id: String = UUID().uuidString, - from: DID, - to: DID, - text: String, - date: Date = Date() - ) { - self.id = id - self.from = from - self.to = to - self.text = text - self.date = date - } - - init?(fromMessage: Message) { - guard - fromMessage.piuri == CHAT_MESSAGE_TYPE, - let from = fromMessage.from, - let to = fromMessage.to - else { - return nil - } - self.id = fromMessage.id - self.from = from - self.to = to - self.text = String(data: fromMessage.body, encoding: .utf8) ?? "" - self.date = fromMessage.createdTime - } - - func makeMessage() -> Message { - return Message( - id: id, - piuri: type, - from: from, - to: to, - body: text.data(using: .utf8)!, - createdTime: date - ) - } -}