Skip to content

Commit 5573ef4

Browse files
feat(agent): report problem message
Fixes ATL-6860 Signed-off-by: goncalo-frade-iohk <[email protected]>
1 parent 33d700b commit 5573ef4

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import Core
2+
import Domain
3+
import Foundation
4+
5+
public struct ReportProblemMessage {
6+
7+
public struct Body: Codable {
8+
public let code: String
9+
public let comment: String?
10+
public let args: [String]?
11+
public let escalateTo: String?
12+
13+
init(code: String, comment: String?, args: [String]?, escalateTo: String?) {
14+
self.code = code
15+
self.comment = comment
16+
self.args = args
17+
self.escalateTo = escalateTo
18+
}
19+
}
20+
21+
public let id: String
22+
public let type = ProtocolTypes.didcommReportProblem.rawValue
23+
public let from: DID
24+
public let to: DID
25+
public let date: Date
26+
public let body: Body
27+
28+
public init(
29+
id: String = UUID().uuidString,
30+
from: DID,
31+
to: DID,
32+
body: Body,
33+
date: Date = Date()
34+
) {
35+
self.id = id
36+
self.from = from
37+
self.to = to
38+
self.body = body
39+
self.date = date
40+
}
41+
42+
public init?(fromMessage: Message) throws {
43+
guard
44+
fromMessage.piuri == ProtocolTypes.didcommReportProblem.rawValue,
45+
let from = fromMessage.from,
46+
let to = fromMessage.to
47+
else {
48+
return nil
49+
}
50+
self.id = fromMessage.id
51+
self.from = from
52+
self.to = to
53+
self.body = try JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
54+
self.date = fromMessage.createdTime
55+
}
56+
57+
public func makeMessage() throws -> Message {
58+
return Message(
59+
id: id,
60+
piuri: type,
61+
from: from,
62+
to: to,
63+
body: try JSONEncoder.didComm().encode(body),
64+
createdTime: date,
65+
direction: .sent
66+
)
67+
}
68+
}

EdgeAgentSDK/EdgeAgent/Sources/Protocols/ProtocolTypes.swift

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public enum ProtocolTypes: String {
2424
case didcommconnectionResponse = "https://atalaprism.io/mercury/connections/1.0/response"
2525
case didcommRevocationNotification = "https://atalaprism.io/revocation_notification/1.0/revoke"
2626
case didcomminvitation = "https://didcomm.org/out-of-band/2.0/invitation"
27+
case didcommReportProblem = "https://didcomm.org/report-problem/2.0/problem-report"
2728
case prismOnboarding = "https://atalaprism.io/did-request"
2829
case pickupRequest = "https://didcomm.org/messagepickup/3.0/delivery-request"
2930
case pickupDelivery = "https://didcomm.org/messagepickup/3.0/delivery"

0 commit comments

Comments
 (0)