-
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(pluto): add persistence to connection data and messages
Fixes ATL-2495
- Loading branch information
1 parent
e9e5bb2
commit b2b10d3
Showing
49 changed files
with
1,545 additions
and
182 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public struct DIDPair: Equatable { | ||
public let holder: DID | ||
public let other: DID | ||
public let name: String? | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Combine | ||
import Domain | ||
import Foundation | ||
|
||
protocol DIDPairProvider { | ||
func getAll() -> AnyPublisher<[(holder: DID, other: DID, name: String?)], Error> | ||
func getPair(otherDID: DID) -> AnyPublisher<(holder: DID, other: DID, name: String?)?, Error> | ||
func getPair(name: String) -> AnyPublisher<(holder: DID, other: DID, name: String?)?, Error> | ||
func getPair(holderDID: DID) -> AnyPublisher<(holder: DID, other: DID, name: String?)?, Error> | ||
} |
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,9 @@ | ||
import Combine | ||
import Domain | ||
import Foundation | ||
|
||
protocol DIDPrivateKeyProvider { | ||
func getAll() -> AnyPublisher<[(did: DID, privateKey: PrivateKey)], Error> | ||
func getDIDInfo(did: DID) -> AnyPublisher<(did: DID, privateKey: PrivateKey)?, Error> | ||
func getPrivateKey(did: DID) -> AnyPublisher<PrivateKey?, Error> | ||
} |
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,7 @@ | ||
import Combine | ||
import Domain | ||
import Foundation | ||
|
||
protocol MediatorProvider { | ||
func getAll() -> AnyPublisher<[(did: DID, routingDID: DID, url: URL)], Error> | ||
} |
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,13 @@ | ||
import Combine | ||
import Domain | ||
import Foundation | ||
|
||
protocol MessageProvider { | ||
func getAll() -> AnyPublisher<[Message], Error> | ||
func getAllFor(did: DID) -> AnyPublisher<[Message], Error> | ||
func getAllSentTo(did: DID) -> AnyPublisher<[Message], Error> | ||
func getAllReceivedFrom(did: DID) -> AnyPublisher<[Message], Error> | ||
func getAllOfType(type: String, relatedWithDID: DID?) -> AnyPublisher<[Message], Error> | ||
func getAll(from: DID, to: DID) -> AnyPublisher<[Message], Error> | ||
func getMessage(id: String) -> AnyPublisher<Message?, Error> | ||
} |
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,9 @@ | ||
import Combine | ||
import Domain | ||
import Foundation | ||
|
||
protocol DIDPairStore { | ||
func addDIDPair(holder: DID, other: DID, name: String) -> AnyPublisher<Void, Error> | ||
func removeDIDPair(holder: DID, other: DID) -> AnyPublisher<Void, Error> | ||
func removeAll() -> AnyPublisher<Void, Error> | ||
} |
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,9 @@ | ||
import Combine | ||
import Domain | ||
import Foundation | ||
|
||
protocol DIDPrivateKeyStore { | ||
func addDID(did: DID, privateKey: PrivateKey) -> AnyPublisher<Void, Error> | ||
func removeDID(did: DID) -> AnyPublisher<Void, Error> | ||
func removeAll() -> AnyPublisher<Void, Error> | ||
} |
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,8 @@ | ||
import Combine | ||
import Domain | ||
import Foundation | ||
|
||
protocol MediatorStore { | ||
func addMediator(peer: DID, routingDID: DID, url: URL) -> AnyPublisher<Void, Error> | ||
func removeMediator(peer: DID) -> AnyPublisher<Void, Error> | ||
} |
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,9 @@ | ||
import Combine | ||
import Domain | ||
import Foundation | ||
|
||
protocol MessageStore { | ||
func addMessage(msg: Message) -> AnyPublisher<Void, Error> | ||
func removeMessage(id: String) -> AnyPublisher<Void, Error> | ||
func removeAll() -> AnyPublisher<Void, Error> | ||
} |
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,73 @@ | ||
import Domain | ||
import Foundation | ||
|
||
extension AttachmentDescriptor: Codable { | ||
enum CodingKeys: String, CodingKey { | ||
case id | ||
case mediaType | ||
case data | ||
case filename | ||
case lastmodTime | ||
case byteCount | ||
case description | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encode(id, forKey: .id) | ||
try mediaType.map { try container.encode($0, forKey: .mediaType) } | ||
try filename.map { try container.encode($0, forKey: .filename) } | ||
try lastmodTime.map { try container.encode($0, forKey: .lastmodTime) } | ||
try byteCount.map { try container.encode($0, forKey: .byteCount) } | ||
try description.map { try container.encode($0, forKey: .description) } | ||
|
||
if let attachment = data as? AttachmentBase64 { | ||
try container.encode(attachment, forKey: .data) | ||
} else if let attachment = data as? AttachmentJws { | ||
try container.encode(attachment, forKey: .data) | ||
} else if let attachment = data as? AttachmentHeader { | ||
try container.encode(attachment, forKey: .data) | ||
} else if let attachment = data as? AttachmentJwsData { | ||
try container.encode(attachment, forKey: .data) | ||
} else if let attachment = data as? AttachmentJsonData { | ||
try container.encode(attachment, forKey: .data) | ||
} else if let attachment = data as? AttachmentLinkData { | ||
try container.encode(attachment, forKey: .data) | ||
} else { fatalError("Cannot do this") } | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
let id = try container.decode(String.self, forKey: .id) | ||
let mediaType = try? container.decode(String.self, forKey: .mediaType) | ||
let filename = try? container.decode([String].self, forKey: .filename) | ||
let lastmodTime = try? container.decode(Date.self, forKey: .lastmodTime) | ||
let byteCount = try? container.decode(Int.self, forKey: .byteCount) | ||
let description = try? container.decode([String].self, forKey: .description) | ||
|
||
let data: AttachmentData | ||
if let attachment = try? container.decode(AttachmentBase64.self, forKey: .data) { | ||
data = attachment | ||
} else if let attachment = try? container.decode(AttachmentJws.self, forKey: .data) { | ||
data = attachment | ||
} else if let attachment = try? container.decode(AttachmentHeader.self, forKey: .data) { | ||
data = attachment | ||
} else if let attachment = try? container.decode(AttachmentJwsData.self, forKey: .data) { | ||
data = attachment | ||
} else if let attachment = try? container.decode(AttachmentJsonData.self, forKey: .data) { | ||
data = attachment | ||
} else if let attachment = try? container.decode(AttachmentLinkData.self, forKey: .data) { | ||
data = attachment | ||
} else { fatalError("Cannot do this") } | ||
|
||
self.init( | ||
id: id, | ||
mediaType: mediaType, | ||
data: data, | ||
filename: filename, | ||
lastmodTime: lastmodTime, | ||
byteCount: byteCount, | ||
description: description | ||
) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Domain | ||
import Foundation | ||
|
||
extension DID: Codable { | ||
enum CodingKeys: String, CodingKey { | ||
case schema | ||
case method | ||
case methodId | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encode(schema, forKey: .schema) | ||
try container.encode(method, forKey: .method) | ||
try container.encode(methodId, forKey: .methodId) | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
let schema = try container.decode(String.self, forKey: .schema) | ||
let method = try container.decode(DIDMethod.self, forKey: .method) | ||
let methodId = try container.decode(DIDMethodId.self, forKey: .methodId) | ||
|
||
self.init(schema: schema, method: method, methodId: methodId) | ||
} | ||
} |
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,70 @@ | ||
import Domain | ||
import Foundation | ||
|
||
extension Message: Codable { | ||
enum CodingKeys: String, CodingKey { | ||
case id | ||
case piuri | ||
case from | ||
case to | ||
case fromPrior | ||
case extraHeaders | ||
case createdTime | ||
case expiresTimePlus | ||
case attachments | ||
case thid | ||
case pthid | ||
case ack | ||
case body | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encode(id, forKey: .id) | ||
try container.encode(piuri, forKey: .piuri) | ||
try container.encode(body, forKey: .body) | ||
try container.encode(extraHeaders, forKey: .extraHeaders) | ||
try container.encode(createdTime, forKey: .createdTime) | ||
try container.encode(expiresTimePlus, forKey: .expiresTimePlus) | ||
try container.encode(attachments, forKey: .attachments) | ||
try container.encode(ack, forKey: .ack) | ||
try from.map { try container.encode($0, forKey: .from) } | ||
try to.map { try container.encode($0, forKey: .to) } | ||
try fromPrior.map { try container.encode($0, forKey: .fromPrior) } | ||
try thid.map { try container.encode($0, forKey: .thid) } | ||
try pthid.map { try container.encode($0, forKey: .pthid) } | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
let id = try container.decode(String.self, forKey: .id) | ||
let piuri = try container.decode(String.self, forKey: .piuri) | ||
let body = try container.decode(Data.self, forKey: .body) | ||
let extraHeaders = try container.decode([String: String].self, forKey: .extraHeaders) | ||
let createdTime = try container.decode(Date.self, forKey: .createdTime) | ||
let expiresTimePlus = try container.decode(Date.self, forKey: .expiresTimePlus) | ||
let attachments = try container.decode([AttachmentDescriptor].self, forKey: .attachments) | ||
let ack = try container.decode([String].self, forKey: .ack) | ||
let from = try? container.decode(DID.self, forKey: .from) | ||
let to = try? container.decode(DID.self, forKey: .to) | ||
let fromPrior = try? container.decode(String.self, forKey: .fromPrior) | ||
let thid = try? container.decode(String.self, forKey: .thid) | ||
let pthid = try? container.decode(String.self, forKey: .pthid) | ||
|
||
self.init( | ||
id: id, | ||
piuri: piuri, | ||
from: from, | ||
to: to, | ||
fromPrior: fromPrior, | ||
body: body, | ||
extraHeaders: extraHeaders, | ||
createdTime: createdTime, | ||
expiresTimePlus: expiresTimePlus, | ||
attachments: attachments, | ||
thid: thid, | ||
pthid: pthid, | ||
ack: ack | ||
) | ||
} | ||
} |
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,19 @@ | ||
import Combine | ||
import CoreData | ||
import Domain | ||
|
||
struct CDDIDDAO: CoreDataDAO { | ||
typealias CoreDataObject = CDDID | ||
let readContext: NSManagedObjectContext | ||
let writeContext: NSManagedObjectContext | ||
let identifierKey: String? = "did" | ||
} | ||
|
||
extension CDDID { | ||
func parseFrom(did: DID) { | ||
self.did = did.string | ||
self.schema = did.schema | ||
self.method = did.method | ||
self.methodId = did.methodId | ||
} | ||
} |
Oops, something went wrong.