• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / atala-prism-wallet-sdk-swift / 9109509334

15 May 2024 05:57PM UTC coverage: 38.446%. Remained the same
9109509334

push

github

goncalo-frade-iohk
feat!(sdk): renaming the sdk and its components

BREAKING CHANGE: There was a renaming of components

Signed-off-by: goncalo-frade-iohk <goncalo.frade@iohk.io>

24 of 61 new or added lines in 29 files covered. (39.34%)

3943 of 10256 relevant lines covered (38.45%)

14.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.82
/EdgeAgentSDK/EdgeAgent/Sources/Protocols/Connection/ConnectionRequest.swift
1
import Core
2
import Domain
3
import Foundation
4

5
/**
6
 A struct representing a connection request message in the DIDComm protocol.
7

8
 The ConnectionRequest struct defines properties and methods for encoding, decoding, and sending connection request messages in the DIDComm protocol.
9

10
 - Note: The ConnectionRequest struct is used to send connection request messages in the DIDComm protocol.
11

12
 */
13
public struct ConnectionRequest {
14

15
    // The body of the connection request message, which is the same as the body of the invitation message
16
    public struct Body: Codable {
17

18
        // The goal code of the connection request message
19
        public let goalCode: String?
20

21
        // The goal of the connection request message
22
        public let goal: String?
23

24
        // An array of strings representing the requested message types
25
        public let accept: [String]?
26

27
        /**
28
         Initializes a new instance of the Body struct with the specified parameters.
29

30
         - Parameter goalCode: The goal code of the connection request message.
31
         - Parameter goal: The goal of the connection request message.
32
         - Parameter accept: An array of strings representing the requested message types.
33

34
         */
35
        public init(
36
            goalCode: String? = nil,
37
            goal: String? = nil,
38
            accept: [String]? = nil
39
        ) {
6✔
40
            self.goalCode = goalCode
6✔
41
            self.goal = goal
6✔
42
            self.accept = accept
6✔
43
        }
6✔
44
    }
45

46
    // The type of the connection request message
47
    public let type: String = ProtocolTypes.didcommconnectionRequest.rawValue
4✔
48

49
    // The ID of the connection request message
50
    public let id: String
51

52
    // The DID of the sender of the connection request message
53
    public let from: DID
54

55
    // The DID of the recipient of the connection request message
56
    public let to: DID
57

58
    // The thread ID of the connection request message
59
    public let thid: String?
60

61
    // The body of the connection request message
62
    public let body: Body
63

64
    /**
65
     Initializes a new instance of the ConnectionRequest struct from the specified invitation message.
66

67
     - Parameter inviteMessage: The invitation message to use for initialization.
68
     - Parameter from: The DID of the sender of the connection request message.
69

70
     - Throws: An error if there was a problem decoding the invitation message.
71

72
     */
73
    public init(inviteMessage: Message, from: DID) throws {
2✔
74
        guard let toDID = inviteMessage.from else { throw EdgeAgentError.invitationIsInvalidError }
2✔
75
        let body = try JSONDecoder.didComm().decode(Body.self, from: inviteMessage.body)
2✔
76
        self.init(from: from, to: toDID, thid: inviteMessage.id, body: body)
2✔
77
    }
2✔
78

79
    /**
80
     Initializes a new instance of the ConnectionRequest struct from the specified out-of-band invitation.
81

82
     - Parameter inviteMessage: The out-of-band invitation to use for initialization.
83
     - Parameter from: The DID of the sender of the connection request message.
84

85
     - Throws: An error if there was a problem initializing the connection request.
86

87
     */
88
    public init(inviteMessage: OutOfBandInvitation, from: DID) throws {
×
89
        let toDID = try DID(string: inviteMessage.from)
×
90
        self.init(
×
91
            from: from,
×
92
            to: toDID,
×
93
            thid: inviteMessage.id,
×
94
            body: .init(
×
95
                goalCode: inviteMessage.body.goalCode,
×
96
                goal: inviteMessage.body.goal,
×
97
                accept: inviteMessage.body.accept
×
98
            )
×
99
        )
×
100
    }
×
101

102
    /**
103
     Initializes a new instance of the ConnectionRequest struct from the specified message.
104

105
     - Parameter fromMessage: The message to decode.
106

107
     - Throws: An error if there was a problem decoding the message.
108

109
     */
110
    public init(fromMessage: Message) throws {
×
111
        guard
×
112
            fromMessage.piuri == ProtocolTypes.didcommconnectionRequest.rawValue,
×
113
            let from = fromMessage.from,
×
114
            let to = fromMessage.to
×
NEW
115
        else { throw EdgeAgentError.invalidMessageType(
×
116
            type: fromMessage.piuri,
×
117
            shouldBe: [ProtocolTypes.didcommconnectionRequest.rawValue]
×
118
        ) }
×
119
        
×
120
        self.init(
×
121
            from: from,
×
122
            to: to,
×
123
            thid: fromMessage.id,
×
124
            body: try JSONDecoder.didComm().decode(Body.self, from: fromMessage.body)
×
125
        )
×
126
    }
×
127

128
    /**
129
     Initializes a new instance of the ConnectionRequest struct with the specified parameters.
130

131
     - Parameter id: The ID of the connection acceptance message.
132
     - Parameter from: The DID of the sender of the connection acceptance message.
133
     - Parameter to: The DID of the recipient of the connection acceptance message.
134
     - Parameter thid: The thread ID of the connection acceptance message.
135
     - Parameter body: The body of the connection acceptance message.
136

137
     */
138
    public init(
139
        id: String = UUID().uuidString,
140
        from: DID,
141
        to: DID,
142
        thid: String?,
143
        body: Body
144
    ) {
4✔
145
        self.id = id
4✔
146
        self.from = from
4✔
147
        self.to = to
4✔
148
        self.thid = thid
4✔
149
        self.body = body
4✔
150
    }
4✔
151
    
152
    /**
153
     Creates a new `Message` object from the `ConnectionRequest`.
154

155
     The `makeMessage()` method creates a new `Message` object from the current `ConnectionRequest` object.
156

157
     - Returns: A new `Message` object that can be used to send the connection request.
158

159
     - Throws: An error if there was a problem encoding the body of the `ConnectionRequest` message.
160

161
     */
162
    public func makeMessage() throws -> Message {
2✔
163

2✔
164
        // Creates a new Message object with the properties of the ConnectionRequest object
2✔
165
        Message(
2✔
166
            id: id,
2✔
167
            piuri: type,
2✔
168
            from: from,
2✔
169
            to: to,
2✔
170
            body: try JSONEncoder.didComm().encode(self.body),
2✔
171
            thid: thid,
2✔
172
            direction: .sent
2✔
173
        )
2✔
174
    }
2✔
175
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc