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

hyperledger / identus-edge-agent-sdk-swift / 11049785480

25 Sep 2024 02:40PM UTC coverage: 40.771% (-3.2%) from 43.981%
11049785480

push

github

goncalo-frade-iohk
feat!(agent): agent separation of concerns

BREAKING CHANGE: This is a refactor, from now on the EdgeAgent will not have any reference with DIDComm and a DIDCommAgent will replace this.
EdgeAgent now will scope all the logic that is inherent to it removing any transport layer association, and new agents like DIDCommAgent will scope the EdgeAgent functionalities for a transport layer.

With this Pollux also has some significant changes so it is not aggregated to the DIDComm Message.

OIDCAgent will take part of OIDC transport layer communication.

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

232 of 1063 new or added lines in 19 files covered. (21.83%)

187 existing lines in 14 files now uncovered.

5193 of 12737 relevant lines covered (40.77%)

97.25 hits per line

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

94.94
/EdgeAgentSDK/EdgeAgent/Sources/DIDCommAgent/DIDCommAgent+Proof.swift
1
import Core
2
import Combine
3
import Domain
4
import Foundation
5
import Logging
6
import JSONWebToken
7

8
public extension DIDCommAgent {
9
    
10
    /// This function creates a Presentation from a request verfication.
11
    ///
12
    /// - Parameters:
13
    ///   - request: Request message received.
14
    ///   - credential: Verifiable Credential to present.
15
    /// - Returns: Presentation message prepared to send.
16
    /// - Throws: EdgeAgentError, if there is a problem creating the presentation.
17
    func createPresentationForRequestProof(
18
        request: RequestPresentation,
19
        credential: Credential,
20
        options: [CredentialOperationsOptions] = []
21
    ) async throws -> Presentation {
8✔
22
        guard let proofableCredential = credential.proof else {
8✔
NEW
23
            throw EdgeAgentError.credentialCannotIssuePresentations
×
24
        }
8✔
25

8✔
26
        guard let requestType = request.attachments.first?.format else {
8✔
NEW
27
            throw EdgeAgentError.invalidAttachmentFormat(nil)
×
28
        }
8✔
29
        let presentationString: String
8✔
30
        let format: String
8✔
31
        switch requestType {
8✔
32
        case "anoncreds/proof-request@v1.0":
8✔
33
            guard
2✔
34
                let linkSecret = try await pluto.getLinkSecret().first().await()
2✔
35
            else { throw EdgeAgentError.cannotFindDIDKeyPairIndex }
2✔
36

2✔
37
            let restored = try await self.apollo.restoreKey(linkSecret)
2✔
38
            guard
2✔
39
                let linkSecretString = String(data: restored.raw, encoding: .utf8)
2✔
40
            else { throw EdgeAgentError.cannotFindDIDKeyPairIndex }
2✔
41
            format = "anoncreds/proof@v1.0"
2✔
42
            presentationString = try proofableCredential.presentation(
2✔
43
                request: request.makeMessage(),
2✔
44
                options: options + [
2✔
45
                    .linkSecret(id: "", secret: linkSecretString)
2✔
46
                ]
2✔
47
            )
2✔
48
        case "prism/jwt", "vc+sd-jwt", "dif/presentation-exchange/definitions@v1.0":
8✔
49
            guard
6✔
50
                let subjectDIDString = credential.subject
6✔
51
            else {
6✔
NEW
52
                throw PolluxError.invalidPrismDID
×
53
            }
6✔
54

6✔
55
            let subjectDID = try DID(string: subjectDIDString)
6✔
56

6✔
57
            let privateKeys = try await pluto.getDIDPrivateKeys(did: subjectDID).first().await()
6✔
58

6✔
59
            guard
6✔
60
                let storedPrivateKey = privateKeys?.first
6✔
61
            else { throw EdgeAgentError.cannotFindDIDKeyPairIndex }
6✔
62

6✔
63
            let privateKey = try await apollo.restorePrivateKey(storedPrivateKey)
6✔
64

6✔
65
            guard
6✔
66
                let exporting = privateKey.exporting
6✔
67
            else { throw EdgeAgentError.cannotFindDIDKeyPairIndex }
6✔
68

6✔
69
            format = requestType == "prism/jwt" ? "prism/jwt" : "dif/presentation-exchange/submission@v1.0"
6✔
70

6✔
71
            presentationString = try proofableCredential.presentation(
6✔
72
                request: request.makeMessage(),
6✔
73
                options: options + [
6✔
74
                    .exportableKey(exporting),
6✔
75
                    .subjectDID(subjectDID)
6✔
76
                ]
6✔
77
            )
6✔
78
        default:
8✔
NEW
79
            throw EdgeAgentError.invalidAttachmentFormat(requestType)
×
80
        }
8✔
81

8✔
82
        Logger(label: "").log(level: .info, "Presentation: \(presentationString)")
8✔
83

8✔
84
        let base64String = try presentationString.tryToData().base64URLEncoded()
8✔
85

8✔
86
        return Presentation(
8✔
87
            body: .init(
8✔
88
                goalCode: request.body.goalCode,
8✔
89
                comment: request.body.comment
8✔
90
            ),
8✔
91
            attachments: [.init(
8✔
92
                data: AttachmentBase64(base64: base64String),
8✔
93
                format: format
8✔
94
            )],
8✔
95
            thid: request.thid ?? request.id,
8✔
96
            from: request.to,
8✔
97
            to: request.from
8✔
98
        )
8✔
99
    }
8✔
100
}
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