Skip to content

Commit 8914e2e

Browse files
committedFeb 7, 2025·
feat(agent): the body on issue credential protocol messages can be null
hyperledger-identus/identus#115 Signed-off-by: goncalo-frade-iohk <goncalo.frade@iohk.io>
1 parent 0598705 commit 8914e2e

8 files changed

+67
-67
lines changed
 

‎EdgeAgentSDK/EdgeAgent/Sources/DIDCommAgent/DIDCommAgent+Credentials.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ public extension DIDCommAgent {
265265

266266
let requestCredential = RequestCredential3_0(
267267
body: .init(
268-
goalCode: offer.body.goalCode,
269-
comment: offer.body.comment
268+
goalCode: offer.body?.goalCode,
269+
comment: offer.body?.comment
270270
),
271271
type: type.rawValue,
272272
attachments: [.init(

‎EdgeAgentSDK/EdgeAgent/Sources/Protocols/IssueCredential/IssueCredential.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ public struct IssueCredential {
2929

3030
public let id: String
3131
public let type: String
32-
public let body: Body
32+
public let body: Body?
3333
public let attachments: [AttachmentDescriptor]
3434
public let thid: String?
3535
public let from: DID
3636
public let to: DID
3737

3838
init(
3939
id: String = UUID().uuidString,
40-
body: Body,
40+
body: Body?,
4141
type: String,
4242
attachments: [AttachmentDescriptor],
4343
thid: String?,
@@ -65,7 +65,7 @@ public struct IssueCredential {
6565
shouldBe: [ProtocolTypes.didcommIssueCredential.rawValue]
6666
) }
6767

68-
let body = try JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
68+
let body = try? JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
6969
self.init(
7070
id: fromMessage.id,
7171
body: body,
@@ -111,9 +111,9 @@ public struct IssueCredential {
111111

112112
return IssueCredential(
113113
body: Body(
114-
goalCode: request.body.goalCode,
115-
comment: request.body.comment,
116-
formats: request.body.formats
114+
goalCode: request.body?.goalCode,
115+
comment: request.body?.comment,
116+
formats: request.body?.formats ?? []
117117
),
118118
type: type.rawValue,
119119
attachments: request.attachments,
@@ -169,15 +169,15 @@ public struct IssueCredential3_0 {
169169

170170
public let id: String
171171
public let type: String
172-
public let body: Body
172+
public let body: Body?
173173
public let attachments: [AttachmentDescriptor]
174174
public let thid: String?
175175
public let from: DID
176176
public let to: DID
177177

178178
init(
179179
id: String = UUID().uuidString,
180-
body: Body,
180+
body: Body?,
181181
type: String,
182182
attachments: [AttachmentDescriptor],
183183
thid: String?,
@@ -204,7 +204,7 @@ public struct IssueCredential3_0 {
204204
shouldBe: [ProtocolTypes.didcommIssueCredential3_0.rawValue]
205205
) }
206206

207-
let body = try JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
207+
let body = try? JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
208208
self.init(
209209
id: fromMessage.id,
210210
body: body,
@@ -247,8 +247,8 @@ public struct IssueCredential3_0 {
247247

248248
return IssueCredential3_0(
249249
body: Body(
250-
goalCode: request.body.goalCode,
251-
comment: request.body.comment
250+
goalCode: request.body?.goalCode,
251+
comment: request.body?.comment
252252
),
253253
type: type.rawValue,
254254
attachments: request.attachments,

‎EdgeAgentSDK/EdgeAgent/Sources/Protocols/IssueCredential/OfferCredential.swift

+16-16
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ public struct OfferCredential {
3232

3333
public let id: String
3434
public let type: String
35-
public let body: Body
35+
public let body: Body?
3636
public let attachments: [AttachmentDescriptor]
3737
public let thid: String?
3838
public let from: DID
3939
public let to: DID
4040

4141
public init(
4242
id: String = UUID().uuidString,
43-
body: Body,
43+
body: Body?,
4444
type: String,
4545
attachments: [AttachmentDescriptor],
4646
thid: String?,
@@ -67,10 +67,10 @@ public struct OfferCredential {
6767
shouldBe: [ProtocolTypes.didcommOfferCredential.rawValue]
6868
) }
6969

70-
let body = try JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
70+
let body = try? JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
7171
self.init(
7272
id: fromMessage.id,
73-
body: .init(credentialPreview: .init(attributes: []), formats: []), // TODO: [Anoncreds] when they fix on the agent put this back
73+
body: body,
7474
type: piuri.rawValue,
7575
attachments: fromMessage.attachments,
7676
thid: fromMessage.thid,
@@ -108,10 +108,10 @@ public struct OfferCredential {
108108

109109
return OfferCredential(
110110
body: Body(
111-
goalCode: proposed.body.goalCode,
112-
comment: proposed.body.comment,
113-
credentialPreview: proposed.body.credentialPreview,
114-
formats: proposed.body.formats
111+
goalCode: proposed.body?.goalCode,
112+
comment: proposed.body?.comment,
113+
credentialPreview: proposed.body?.credentialPreview ?? .init(attributes: []),
114+
formats: proposed.body?.formats ?? []
115115
),
116116
type: type.rawValue,
117117
attachments: proposed.attachments,
@@ -139,14 +139,14 @@ public struct OfferCredential3_0 {
139139
public let comment: String?
140140
public let replacementId: String?
141141
public let multipleAvailable: String?
142-
public let credentialPreview: CredentialPreview3_0
142+
public let credentialPreview: CredentialPreview3_0?
143143

144144
public init(
145145
goalCode: String? = nil,
146146
comment: String? = nil,
147147
replacementId: String? = nil,
148148
multipleAvailable: String? = nil,
149-
credentialPreview: CredentialPreview3_0
149+
credentialPreview: CredentialPreview3_0?
150150
) {
151151
self.goalCode = goalCode
152152
self.comment = comment
@@ -158,15 +158,15 @@ public struct OfferCredential3_0 {
158158

159159
public let id: String
160160
public let type: String
161-
public let body: Body
161+
public let body: Body?
162162
public let attachments: [AttachmentDescriptor]
163163
public let thid: String?
164164
public let from: DID
165165
public let to: DID
166166

167167
public init(
168168
id: String = UUID().uuidString,
169-
body: Body,
169+
body: Body?,
170170
type: String,
171171
attachments: [AttachmentDescriptor],
172172
thid: String?,
@@ -193,7 +193,7 @@ public struct OfferCredential3_0 {
193193
shouldBe: [ProtocolTypes.didcommOfferCredential.rawValue]
194194
) }
195195

196-
let body = try JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
196+
let body = try? JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
197197
self.init(
198198
id: fromMessage.id,
199199
body: body,
@@ -236,9 +236,9 @@ public struct OfferCredential3_0 {
236236

237237
return OfferCredential3_0(
238238
body: Body(
239-
goalCode: proposed.body.goalCode,
240-
comment: proposed.body.comment,
241-
credentialPreview: proposed.body.credentialPreview
239+
goalCode: proposed.body?.goalCode,
240+
comment: proposed.body?.comment,
241+
credentialPreview: proposed.body?.credentialPreview
242242
),
243243
type: type.rawValue,
244244
attachments: proposed.attachments,

‎EdgeAgentSDK/EdgeAgent/Sources/Protocols/IssueCredential/ProposeCredential.swift

+20-20
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import Foundation
55
// ALL parameterS are DIDCOMMV2 format and naming conventions and follows the protocol
66
// https://github.com/hyperledger/aries-rfcs/tree/main/features/0453-issue-credential-v2
77
public struct ProposeCredential {
8-
struct Body: Codable, Equatable {
9-
let goalCode: String?
10-
let comment: String?
11-
let credentialPreview: CredentialPreview
12-
let formats: [CredentialFormat]
8+
public struct Body: Codable, Equatable {
9+
public let goalCode: String?
10+
public let comment: String?
11+
public let credentialPreview: CredentialPreview
12+
public let formats: [CredentialFormat]
1313

14-
init(
14+
public init(
1515
goalCode: String? = nil,
1616
comment: String? = nil,
1717
credentialPreview: CredentialPreview,
@@ -26,15 +26,15 @@ public struct ProposeCredential {
2626

2727
public let id: String
2828
public let type = ProtocolTypes.didcommProposeCredential.rawValue
29-
let body: Body
30-
let attachments: [AttachmentDescriptor]
29+
public let body: Body?
30+
public let attachments: [AttachmentDescriptor]
3131
public let thid: String?
3232
public let from: DID
3333
public let to: DID
3434

3535
init(
3636
id: String = UUID().uuidString,
37-
body: Body,
37+
body: Body?,
3838
attachments: [AttachmentDescriptor],
3939
thid: String?,
4040
from: DID,
@@ -57,7 +57,7 @@ public struct ProposeCredential {
5757
type: fromMessage.piuri,
5858
shouldBe: [ProtocolTypes.didcommProposeCredential.rawValue]
5959
) }
60-
let body = try JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
60+
let body = try? JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
6161
self.init(
6262
id: fromMessage.id,
6363
body: body,
@@ -119,15 +119,15 @@ extension ProposeCredential: Equatable {
119119
// ALL parameterS are DIDCOMMV2 format and naming conventions and follows the protocol
120120
// https://github.com/hyperledger/aries-rfcs/tree/main/features/0453-issue-credential-v2
121121
public struct ProposeCredential3_0 {
122-
struct Body: Codable, Equatable {
123-
let goalCode: String?
124-
let comment: String?
125-
let credentialPreview: CredentialPreview3_0
122+
public struct Body: Codable, Equatable {
123+
public let goalCode: String?
124+
public let comment: String?
125+
public let credentialPreview: CredentialPreview3_0?
126126

127-
init(
127+
public init(
128128
goalCode: String? = nil,
129129
comment: String? = nil,
130-
credentialPreview: CredentialPreview3_0
130+
credentialPreview: CredentialPreview3_0?
131131
) {
132132
self.goalCode = goalCode
133133
self.comment = comment
@@ -137,15 +137,15 @@ public struct ProposeCredential3_0 {
137137

138138
public let id: String
139139
public let type = ProtocolTypes.didcommProposeCredential3_0.rawValue
140-
let body: Body
141-
let attachments: [AttachmentDescriptor]
140+
public let body: Body?
141+
public let attachments: [AttachmentDescriptor]
142142
public let thid: String?
143143
public let from: DID
144144
public let to: DID
145145

146146
init(
147147
id: String = UUID().uuidString,
148-
body: Body,
148+
body: Body?,
149149
attachments: [AttachmentDescriptor],
150150
thid: String?,
151151
from: DID,
@@ -168,7 +168,7 @@ public struct ProposeCredential3_0 {
168168
type: fromMessage.piuri,
169169
shouldBe: [ProtocolTypes.didcommProposeCredential3_0.rawValue]
170170
) }
171-
let body = try JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
171+
let body = try? JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
172172
self.init(
173173
id: fromMessage.id,
174174
body: body,

‎EdgeAgentSDK/EdgeAgent/Sources/Protocols/IssueCredential/RequestCredential.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ public struct RequestCredential {
2323

2424
public let id: String
2525
public let type: String
26-
public let body: Body
26+
public let body: Body?
2727
public let attachments: [AttachmentDescriptor]
2828
public let thid: String?
2929
public let from: DID
3030
public let to: DID
3131

3232
init(
3333
id: String = UUID().uuidString,
34-
body: Body,
34+
body: Body?,
3535
type: String,
3636
attachments: [AttachmentDescriptor],
3737
thid: String?,
@@ -59,7 +59,7 @@ public struct RequestCredential {
5959
shouldBe: [ProtocolTypes.didcommRequestCredential.rawValue]
6060
) }
6161

62-
let body = try JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
62+
let body = try? JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
6363
self.init(
6464
id: fromMessage.id,
6565
body: body,
@@ -103,9 +103,9 @@ public struct RequestCredential {
103103

104104
return RequestCredential(
105105
body: .init(
106-
goalCode: offer.body.goalCode,
107-
comment: offer.body.comment,
108-
formats: offer.body.formats
106+
goalCode: offer.body?.goalCode,
107+
comment: offer.body?.comment,
108+
formats: offer.body?.formats ?? []
109109
),
110110
type: type.rawValue,
111111
attachments: offer.attachments,
@@ -144,15 +144,15 @@ public struct RequestCredential3_0 {
144144

145145
public let id: String
146146
public let type: String
147-
public let body: Body
147+
public let body: Body?
148148
public let attachments: [AttachmentDescriptor]
149149
public let thid: String?
150150
public let from: DID
151151
public let to: DID
152152

153153
init(
154154
id: String = UUID().uuidString,
155-
body: Body,
155+
body: Body?,
156156
type: String,
157157
attachments: [AttachmentDescriptor],
158158
thid: String?,
@@ -179,7 +179,7 @@ public struct RequestCredential3_0 {
179179
shouldBe: [ProtocolTypes.didcommRequestCredential3_0.rawValue]
180180
) }
181181

182-
let body = try JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
182+
let body = try? JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
183183
self.init(
184184
id: fromMessage.id,
185185
body: body,
@@ -221,8 +221,8 @@ public struct RequestCredential3_0 {
221221

222222
return RequestCredential3_0(
223223
body: .init(
224-
goalCode: offer.body.goalCode,
225-
comment: offer.body.comment
224+
goalCode: offer.body?.goalCode,
225+
comment: offer.body?.comment
226226
),
227227
type: type.rawValue,
228228
attachments: offer.attachments,

‎EdgeAgentSDK/EdgeAgent/Sources/Protocols/IssueCredential/RevocationNotification.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ public struct RevocationNotification {
9494

9595
return RequestCredential(
9696
body: .init(
97-
goalCode: offer.body.goalCode,
98-
comment: offer.body.comment,
99-
formats: offer.body.formats
97+
goalCode: offer.body?.goalCode,
98+
comment: offer.body?.comment,
99+
formats: offer.body?.formats ?? []
100100
),
101101
type: ProtocolTypes.didcommRevocationNotification.rawValue,
102102
attachments: offer.attachments,

‎EdgeAgentSDK/EdgeAgent/Tests/IssueCredentialTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ final class IssueCredentialTests: XCTestCase {
4949
XCTAssertEqual(validRequestCredential.to, testIssueCredential.from)
5050
XCTAssertEqual(validRequestCredential.attachments, testIssueCredential.attachments)
5151
XCTAssertEqual(validRequestCredential.id, testIssueCredential.thid)
52-
XCTAssertEqual(validRequestCredential.body.goalCode, validRequestCredential.body.goalCode)
53-
XCTAssertEqual(validRequestCredential.body.comment, validRequestCredential.body.comment)
52+
XCTAssertEqual(validRequestCredential.body?.goalCode, validRequestCredential.body?.goalCode)
53+
XCTAssertEqual(validRequestCredential.body?.comment, validRequestCredential.body?.comment)
5454
}
5555
}

‎EdgeAgentSDK/EdgeAgent/Tests/RequestCredentialTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ final class RequestCredentialTests: XCTestCase {
5858
XCTAssertEqual(validOfferCredential.to, testRequestCredential.from)
5959
XCTAssertEqual(validOfferCredential.attachments, testRequestCredential.attachments)
6060
XCTAssertEqual(validOfferCredential.thid, testRequestCredential.thid)
61-
XCTAssertEqual(validOfferCredential.body.goalCode, testRequestCredential.body.goalCode)
62-
XCTAssertEqual(validOfferCredential.body.comment, testRequestCredential.body.comment)
61+
XCTAssertEqual(validOfferCredential.body?.goalCode, testRequestCredential.body?.goalCode)
62+
XCTAssertEqual(validOfferCredential.body?.comment, testRequestCredential.body?.comment)
6363
}
6464
}

0 commit comments

Comments
 (0)
Please sign in to comment.