Skip to content

Commit

Permalink
feat(agent): the body on issue credential protocol messages can be null
Browse files Browse the repository at this point in the history
hyperledger-identus/identus#115
Signed-off-by: goncalo-frade-iohk <[email protected]>
  • Loading branch information
goncalo-frade-iohk committed Feb 7, 2025
1 parent 0598705 commit 8914e2e
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ public extension DIDCommAgent {

let requestCredential = RequestCredential3_0(
body: .init(
goalCode: offer.body.goalCode,
comment: offer.body.comment
goalCode: offer.body?.goalCode,
comment: offer.body?.comment
),
type: type.rawValue,
attachments: [.init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public struct IssueCredential {

public let id: String
public let type: String
public let body: Body
public let body: Body?
public let attachments: [AttachmentDescriptor]
public let thid: String?
public let from: DID
public let to: DID

init(
id: String = UUID().uuidString,
body: Body,
body: Body?,
type: String,
attachments: [AttachmentDescriptor],
thid: String?,
Expand Down Expand Up @@ -65,7 +65,7 @@ public struct IssueCredential {
shouldBe: [ProtocolTypes.didcommIssueCredential.rawValue]
) }

let body = try JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
let body = try? JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
self.init(
id: fromMessage.id,
body: body,
Expand Down Expand Up @@ -111,9 +111,9 @@ public struct IssueCredential {

return IssueCredential(
body: Body(
goalCode: request.body.goalCode,
comment: request.body.comment,
formats: request.body.formats
goalCode: request.body?.goalCode,
comment: request.body?.comment,
formats: request.body?.formats ?? []
),
type: type.rawValue,
attachments: request.attachments,
Expand Down Expand Up @@ -169,15 +169,15 @@ public struct IssueCredential3_0 {

public let id: String
public let type: String
public let body: Body
public let body: Body?
public let attachments: [AttachmentDescriptor]
public let thid: String?
public let from: DID
public let to: DID

init(
id: String = UUID().uuidString,
body: Body,
body: Body?,
type: String,
attachments: [AttachmentDescriptor],
thid: String?,
Expand All @@ -204,7 +204,7 @@ public struct IssueCredential3_0 {
shouldBe: [ProtocolTypes.didcommIssueCredential3_0.rawValue]
) }

let body = try JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
let body = try? JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
self.init(
id: fromMessage.id,
body: body,
Expand Down Expand Up @@ -247,8 +247,8 @@ public struct IssueCredential3_0 {

return IssueCredential3_0(
body: Body(
goalCode: request.body.goalCode,
comment: request.body.comment
goalCode: request.body?.goalCode,
comment: request.body?.comment
),
type: type.rawValue,
attachments: request.attachments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public struct OfferCredential {

public let id: String
public let type: String
public let body: Body
public let body: Body?
public let attachments: [AttachmentDescriptor]
public let thid: String?
public let from: DID
public let to: DID

public init(
id: String = UUID().uuidString,
body: Body,
body: Body?,
type: String,
attachments: [AttachmentDescriptor],
thid: String?,
Expand All @@ -67,10 +67,10 @@ public struct OfferCredential {
shouldBe: [ProtocolTypes.didcommOfferCredential.rawValue]
) }

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

return OfferCredential(
body: Body(
goalCode: proposed.body.goalCode,
comment: proposed.body.comment,
credentialPreview: proposed.body.credentialPreview,
formats: proposed.body.formats
goalCode: proposed.body?.goalCode,
comment: proposed.body?.comment,
credentialPreview: proposed.body?.credentialPreview ?? .init(attributes: []),
formats: proposed.body?.formats ?? []
),
type: type.rawValue,
attachments: proposed.attachments,
Expand Down Expand Up @@ -139,14 +139,14 @@ public struct OfferCredential3_0 {
public let comment: String?
public let replacementId: String?
public let multipleAvailable: String?
public let credentialPreview: CredentialPreview3_0
public let credentialPreview: CredentialPreview3_0?

public init(
goalCode: String? = nil,
comment: String? = nil,
replacementId: String? = nil,
multipleAvailable: String? = nil,
credentialPreview: CredentialPreview3_0
credentialPreview: CredentialPreview3_0?
) {
self.goalCode = goalCode
self.comment = comment
Expand All @@ -158,15 +158,15 @@ public struct OfferCredential3_0 {

public let id: String
public let type: String
public let body: Body
public let body: Body?
public let attachments: [AttachmentDescriptor]
public let thid: String?
public let from: DID
public let to: DID

public init(
id: String = UUID().uuidString,
body: Body,
body: Body?,
type: String,
attachments: [AttachmentDescriptor],
thid: String?,
Expand All @@ -193,7 +193,7 @@ public struct OfferCredential3_0 {
shouldBe: [ProtocolTypes.didcommOfferCredential.rawValue]
) }

let body = try JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
let body = try? JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
self.init(
id: fromMessage.id,
body: body,
Expand Down Expand Up @@ -236,9 +236,9 @@ public struct OfferCredential3_0 {

return OfferCredential3_0(
body: Body(
goalCode: proposed.body.goalCode,
comment: proposed.body.comment,
credentialPreview: proposed.body.credentialPreview
goalCode: proposed.body?.goalCode,
comment: proposed.body?.comment,
credentialPreview: proposed.body?.credentialPreview
),
type: type.rawValue,
attachments: proposed.attachments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import Foundation
// ALL parameterS are DIDCOMMV2 format and naming conventions and follows the protocol
// https://github.com/hyperledger/aries-rfcs/tree/main/features/0453-issue-credential-v2
public struct ProposeCredential {
struct Body: Codable, Equatable {
let goalCode: String?
let comment: String?
let credentialPreview: CredentialPreview
let formats: [CredentialFormat]
public struct Body: Codable, Equatable {
public let goalCode: String?
public let comment: String?
public let credentialPreview: CredentialPreview
public let formats: [CredentialFormat]

init(
public init(
goalCode: String? = nil,
comment: String? = nil,
credentialPreview: CredentialPreview,
Expand All @@ -26,15 +26,15 @@ public struct ProposeCredential {

public let id: String
public let type = ProtocolTypes.didcommProposeCredential.rawValue
let body: Body
let attachments: [AttachmentDescriptor]
public let body: Body?
public let attachments: [AttachmentDescriptor]
public let thid: String?
public let from: DID
public let to: DID

init(
id: String = UUID().uuidString,
body: Body,
body: Body?,
attachments: [AttachmentDescriptor],
thid: String?,
from: DID,
Expand All @@ -57,7 +57,7 @@ public struct ProposeCredential {
type: fromMessage.piuri,
shouldBe: [ProtocolTypes.didcommProposeCredential.rawValue]
) }
let body = try JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
let body = try? JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
self.init(
id: fromMessage.id,
body: body,
Expand Down Expand Up @@ -119,15 +119,15 @@ extension ProposeCredential: Equatable {
// ALL parameterS are DIDCOMMV2 format and naming conventions and follows the protocol
// https://github.com/hyperledger/aries-rfcs/tree/main/features/0453-issue-credential-v2
public struct ProposeCredential3_0 {
struct Body: Codable, Equatable {
let goalCode: String?
let comment: String?
let credentialPreview: CredentialPreview3_0
public struct Body: Codable, Equatable {
public let goalCode: String?
public let comment: String?
public let credentialPreview: CredentialPreview3_0?

init(
public init(
goalCode: String? = nil,
comment: String? = nil,
credentialPreview: CredentialPreview3_0
credentialPreview: CredentialPreview3_0?
) {
self.goalCode = goalCode
self.comment = comment
Expand All @@ -137,15 +137,15 @@ public struct ProposeCredential3_0 {

public let id: String
public let type = ProtocolTypes.didcommProposeCredential3_0.rawValue
let body: Body
let attachments: [AttachmentDescriptor]
public let body: Body?
public let attachments: [AttachmentDescriptor]
public let thid: String?
public let from: DID
public let to: DID

init(
id: String = UUID().uuidString,
body: Body,
body: Body?,
attachments: [AttachmentDescriptor],
thid: String?,
from: DID,
Expand All @@ -168,7 +168,7 @@ public struct ProposeCredential3_0 {
type: fromMessage.piuri,
shouldBe: [ProtocolTypes.didcommProposeCredential3_0.rawValue]
) }
let body = try JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
let body = try? JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
self.init(
id: fromMessage.id,
body: body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public struct RequestCredential {

public let id: String
public let type: String
public let body: Body
public let body: Body?
public let attachments: [AttachmentDescriptor]
public let thid: String?
public let from: DID
public let to: DID

init(
id: String = UUID().uuidString,
body: Body,
body: Body?,
type: String,
attachments: [AttachmentDescriptor],
thid: String?,
Expand Down Expand Up @@ -59,7 +59,7 @@ public struct RequestCredential {
shouldBe: [ProtocolTypes.didcommRequestCredential.rawValue]
) }

let body = try JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
let body = try? JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
self.init(
id: fromMessage.id,
body: body,
Expand Down Expand Up @@ -103,9 +103,9 @@ public struct RequestCredential {

return RequestCredential(
body: .init(
goalCode: offer.body.goalCode,
comment: offer.body.comment,
formats: offer.body.formats
goalCode: offer.body?.goalCode,
comment: offer.body?.comment,
formats: offer.body?.formats ?? []
),
type: type.rawValue,
attachments: offer.attachments,
Expand Down Expand Up @@ -144,15 +144,15 @@ public struct RequestCredential3_0 {

public let id: String
public let type: String
public let body: Body
public let body: Body?
public let attachments: [AttachmentDescriptor]
public let thid: String?
public let from: DID
public let to: DID

init(
id: String = UUID().uuidString,
body: Body,
body: Body?,
type: String,
attachments: [AttachmentDescriptor],
thid: String?,
Expand All @@ -179,7 +179,7 @@ public struct RequestCredential3_0 {
shouldBe: [ProtocolTypes.didcommRequestCredential3_0.rawValue]
) }

let body = try JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
let body = try? JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
self.init(
id: fromMessage.id,
body: body,
Expand Down Expand Up @@ -221,8 +221,8 @@ public struct RequestCredential3_0 {

return RequestCredential3_0(
body: .init(
goalCode: offer.body.goalCode,
comment: offer.body.comment
goalCode: offer.body?.goalCode,
comment: offer.body?.comment
),
type: type.rawValue,
attachments: offer.attachments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ public struct RevocationNotification {

return RequestCredential(
body: .init(
goalCode: offer.body.goalCode,
comment: offer.body.comment,
formats: offer.body.formats
goalCode: offer.body?.goalCode,
comment: offer.body?.comment,
formats: offer.body?.formats ?? []
),
type: ProtocolTypes.didcommRevocationNotification.rawValue,
attachments: offer.attachments,
Expand Down
4 changes: 2 additions & 2 deletions EdgeAgentSDK/EdgeAgent/Tests/IssueCredentialTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ final class IssueCredentialTests: XCTestCase {
XCTAssertEqual(validRequestCredential.to, testIssueCredential.from)
XCTAssertEqual(validRequestCredential.attachments, testIssueCredential.attachments)
XCTAssertEqual(validRequestCredential.id, testIssueCredential.thid)
XCTAssertEqual(validRequestCredential.body.goalCode, validRequestCredential.body.goalCode)
XCTAssertEqual(validRequestCredential.body.comment, validRequestCredential.body.comment)
XCTAssertEqual(validRequestCredential.body?.goalCode, validRequestCredential.body?.goalCode)
XCTAssertEqual(validRequestCredential.body?.comment, validRequestCredential.body?.comment)
}
}
Loading

0 comments on commit 8914e2e

Please sign in to comment.