• 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

46.15
/EdgeAgentSDK/EdgeAgent/Sources/EdgeAgent+Invitations.swift
1
import Domain
2
import Foundation
3

4
// MARK: Invitation funcionalities
5
public extension EdgeAgent {
6
    /// Enumeration representing the type of invitation
7
    enum InvitationType {
8
        /// Struct representing a Prism Onboarding invitation
9
        public struct PrismOnboarding {
10
            /// Sender of the invitation
11
            public let from: String
12
            /// Onboarding endpoint
13
            public let endpoint: URL
14
            /// The own DID of the user
15
            public let ownDID: DID
16
        }
17

18
        /// Case representing a Prism Onboarding invitation
19
        case onboardingPrism(PrismOnboarding)
20
        /// Case representing a DIDComm Out-of-Band invitation
21
        case onboardingDIDComm(OutOfBandInvitation)
22
    }
23

24
    /// Parses the given string as an invitation
25
    /// - Parameter str: The string to parse
26
    /// - Returns: The parsed invitation
27
    /// - Throws: `EdgeAgentError` if the invitation is not a valid Prism or OOB type
28
    func parseInvitation(str: String) async throws -> InvitationType {
2✔
29
        if let prismOnboarding = try? await parsePrismInvitation(str: str) {
2✔
30
            return .onboardingPrism(prismOnboarding)
×
31
        } else if let message = try? parseOOBInvitation(url: str) {
2✔
32
            return .onboardingDIDComm(message)
2✔
33
        }
2✔
NEW
34
        throw EdgeAgentError.unknownInvitationTypeError
×
35
    }
2✔
36

37
    /// Parses the given string as a Prism Onboarding invitation
38
    /// - Parameter str: The string to parse
39
    /// - Returns: The parsed Prism Onboarding invitation
40
    /// - Throws: `EdgeAgentError` if the string is not a valid Prism Onboarding invitation
41
    func parsePrismInvitation(
42
        str: String
43
    ) async throws -> InvitationType.PrismOnboarding {
2✔
44
        let prismOnboarding = try PrismOnboardingInvitation(jsonString: str)
2✔
45
        guard
2✔
46
            let url = URL(string: prismOnboarding.body.onboardEndpoint)
2✔
47
        else { throw CommonError.invalidURLError(url: prismOnboarding.body.onboardEndpoint) }
2✔
48

2✔
49
        let ownDID = try await createNewPeerDID(
2✔
50
            services: [.init(
2✔
51
                id: "#didcomm-1",
2✔
52
                type: ["DIDCommMessaging"],
2✔
53
                serviceEndpoint: [.init(
2✔
54
                    uri: "https://localhost:8080/didcomm"
2✔
55
                )]
2✔
56
            )],
2✔
57
            updateMediator: false
2✔
58
        )
2✔
59

2✔
60
        return .init(
2✔
61
            from: prismOnboarding.body.from,
2✔
62
            endpoint: url,
2✔
63
            ownDID: ownDID
2✔
64
        )
2✔
65
    }
2✔
66

67
    /// Parses the given string as an Out-of-Band invitation
68
    /// - Parameter url: The string to parse
69
    /// - Returns: The parsed Out-of-Band invitation
70
    /// - Throws: `EdgeAgentError` if the string is not a valid URL
71
    func parseOOBInvitation(url: String) throws -> OutOfBandInvitation {
2✔
72
        guard let url = URL(string: url) else { throw CommonError.invalidURLError(url: url) }
2✔
73
        return try parseOOBInvitation(url: url)
2✔
74
    }
2✔
75

76
    /// Parses the given URL as an Out-of-Band invitation
77
    /// - Parameter url: The URL to parse
78
    /// - Returns: The parsed Out-of-Band invitation
79
    /// - Throws: `EdgeAgentError` if the URL is not a valid Out-of-Band invitation
80
    func parseOOBInvitation(url: URL) throws -> OutOfBandInvitation {
2✔
81
        return try DIDCommInvitationRunner(url: url).run()
2✔
82
    }
2✔
83

84
    /// Accepts an Out-of-Band (DIDComm) invitation and establishes a new connection
85
    /// - Parameter invitation: The Out-of-Band invitation to accept
86
    /// - Throws: `EdgeAgentError` if there is no mediator available or other errors occur during the acceptance process
87
    func acceptDIDCommInvitation(invitation: OutOfBandInvitation) async throws {
×
88
        guard
×
89
            let connectionManager
×
NEW
90
        else { throw EdgeAgentError.noMediatorAvailableError }
×
91
        logger.info(message: "Start accept DIDComm invitation")
×
92
        let ownDID = try await createNewPeerDID(updateMediator: true)
×
93

×
94
        logger.info(message: "Sending DIDComm Connection message")
×
95

×
96
        let pair = try await DIDCommConnectionRunner(
×
97
            invitationMessage: invitation,
×
98
            pluto: pluto,
×
99
            ownDID: ownDID,
×
100
            connection: connectionManager
×
101
        ).run()
×
102
        try await connectionManager.addConnection(pair)
×
103
    }
×
104

105
    /// Accepts a Prism Onboarding invitation and performs the onboarding process
106
    /// - Parameter invitation: The Prism Onboarding invitation to accept
107
    /// - Throws: `EdgeAgentError` if the onboarding process fails
108
    func acceptPrismInvitation(invitation: InvitationType.PrismOnboarding) async throws {
×
109
        struct SendDID: Encodable {
×
110
            let did: String
×
111
        }
×
112
        var request = URLRequest(url: invitation.endpoint)
×
113
        request.httpMethod = "POST"
×
114
        request.httpBody = try JSONEncoder().encode(SendDID(did: invitation.ownDID.string))
×
115
        request.setValue("application/json", forHTTPHeaderField: "content-type")
×
116
        do {
×
117
            let response = try await URLSession.shared.data(for: request)
×
118
            guard let urlResponse = response.1 as? HTTPURLResponse else {
×
119
                throw CommonError.invalidCoding(
×
120
                    message: "This should not happen cannot convert URLResponse to HTTPURLResponse"
×
121
                )
×
122
            }
×
123
            guard urlResponse.statusCode == 200 else {
×
124
                throw CommonError.httpError(
×
125
                    code: urlResponse.statusCode,
×
126
                    message: String(data: response.0, encoding: .utf8) ?? ""
×
127
                )
×
128
            }
×
129
        }
×
130
    }
×
131
}
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