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

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

11 Jun 2024 01:48PM UTC coverage: 40.328% (-0.5%) from 40.822%
9466819027

Pull #145

github

web-flow
Merge 1399bca59 into 8e68386ce
Pull Request #145: feat(pollux): add support for sd-jwt

76 of 394 new or added lines in 20 files covered. (19.29%)

2 existing lines in 2 files now uncovered.

4518 of 11203 relevant lines covered (40.33%)

16.34 hits per line

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

45.65
/EdgeAgentSDK/Pollux/Sources/PolluxImpl+CredentialRequest.swift
1
import Domain
2
import Foundation
3
import JSONWebToken
4

5
extension PolluxImpl {
6
    
7
    private enum SupportedCredential: String {
8
        case jwt
9
        case anoncred
10
    }
11
    
12
    public func processCredentialRequest(
13
        offerMessage: Message,
14
        options: [CredentialOperationsOptions]
15
    ) async throws -> String {
2✔
16
        guard let offerAttachment = offerMessage.attachments.first else {
2✔
17
            throw PolluxError.offerDoesntProvideEnoughInformation
×
18
        }
2✔
19
        
2✔
20
        switch offerAttachment.format {
2✔
21
        case "jwt", "prism/jwt", .none:
2✔
22
            switch offerAttachment.data {
×
23
            case let json as AttachmentJsonData:
×
NEW
24
                return try await processJWTCredentialRequest(offerData: json.data, options: options)
×
NEW
25
            default:
×
NEW
26
                throw PolluxError.offerDoesntProvideEnoughInformation
×
NEW
27
            }
×
28
        case "vc+sd-jwt":
2✔
NEW
29
            switch offerAttachment.data {
×
NEW
30
            case let json as AttachmentJsonData:
×
NEW
31
                return try await processSDJWTCredentialRequest(offerData: json.data, options: options)
×
32
            default:
×
33
                throw PolluxError.offerDoesntProvideEnoughInformation
×
34
            }
×
35
        case "anoncreds/credential-offer@v1.0":
2✔
36
            switch offerAttachment.data {
2✔
37
            case let attachmentData as AttachmentJsonData:
2✔
38
                guard let thid = offerMessage.thid else {
×
39
                    throw PolluxError.messageDoesntProvideEnoughInformation
×
40
                }
×
41
                return try await processAnoncredsCredentialRequest(
×
42
                    offerData: attachmentData.data,
×
43
                    thid: thid,
×
44
                    options: options
×
45
                )
×
46
            case let attachmentData as AttachmentBase64:
2✔
47
                guard 
2✔
48
                    let thid = offerMessage.thid,
2✔
49
                    let data = Data(fromBase64URL: attachmentData.base64)
2✔
50
                else {
2✔
51
                    throw PolluxError.offerDoesntProvideEnoughInformation
×
52
                }
2✔
53
                return try await processAnoncredsCredentialRequest(
2✔
54
                    offerData: data,
2✔
55
                    thid: thid,
2✔
56
                    options: options
2✔
57
                )
2✔
58
            default:
2✔
59
                throw PolluxError.offerDoesntProvideEnoughInformation
×
60
            }
2✔
61
        default:
2✔
62
            break
×
63
        }
2✔
64
        throw PolluxError.invalidCredentialError
×
65
    }
2✔
66

NEW
67
    private func processJWTCredentialRequest(offerData: Data, options: [CredentialOperationsOptions]) async throws -> String {
×
68
        guard
×
69
            let subjectDIDOption = options.first(where: {
×
70
                if case .subjectDID = $0 { return true }
×
71
                return false
×
72
            }),
×
73
            case let CredentialOperationsOptions.subjectDID(did) = subjectDIDOption
×
74
        else {
×
75
            throw PolluxError.invalidPrismDID
×
76
        }
×
77
        
×
78
        guard
×
79
            let exportableKeyOption = options.first(where: {
×
80
                if case .exportableKey = $0 { return true }
×
81
                return false
×
82
            }),
×
83
            case let CredentialOperationsOptions.exportableKey(exportableKey) = exportableKeyOption
×
84
        else {
×
85
            throw PolluxError.requiresExportableKeyForOperation(operation: "Create Credential Request")
×
86
        }
×
87
        
×
NEW
88
        return try await CreateJWTCredentialRequest.create(didStr: did.string, key: exportableKey, offerData: offerData)
×
89
    }
×
90

NEW
91
    private func processSDJWTCredentialRequest(offerData: Data, options: [CredentialOperationsOptions]) async throws -> String {
×
NEW
92
        guard
×
NEW
93
            let subjectDIDOption = options.first(where: {
×
NEW
94
                if case .subjectDID = $0 { return true }
×
NEW
95
                return false
×
NEW
96
            }),
×
NEW
97
            case let CredentialOperationsOptions.subjectDID(did) = subjectDIDOption
×
NEW
98
        else {
×
NEW
99
            throw PolluxError.invalidPrismDID
×
NEW
100
        }
×
NEW
101

×
NEW
102
        guard
×
NEW
103
            let exportableKeyOption = options.first(where: {
×
NEW
104
                if case .exportableKey = $0 { return true }
×
NEW
105
                return false
×
NEW
106
            }),
×
NEW
107
            case let CredentialOperationsOptions.exportableKey(exportableKey) = exportableKeyOption
×
NEW
108
        else {
×
NEW
109
            throw PolluxError.requiresExportableKeyForOperation(operation: "Create Credential Request")
×
NEW
110
        }
×
NEW
111

×
NEW
112
        return try await CreateJWTCredentialRequest.create(didStr: did.string, key: exportableKey, offerData: offerData)
×
NEW
113
    }
×
114

115
    private func processAnoncredsCredentialRequest(
116
        offerData: Data,
117
        thid: String,
118
        options: [CredentialOperationsOptions]
119
    ) async throws -> String {
2✔
120
        guard
2✔
121
            let subjectDIDOption = options.first(where: {
6✔
122
                if case .subjectDID = $0 { return true }
6✔
123
                return false
4✔
124
            }),
6✔
125
            case let CredentialOperationsOptions.subjectDID(did) = subjectDIDOption
2✔
126
        else {
2✔
127
            throw PolluxError.invalidPrismDID
×
128
        }
2✔
129
        
2✔
130
        guard
2✔
131
            let linkSecretOption = options.first(where: {
2✔
132
                if case .linkSecret = $0 { return true }
2✔
133
                return false
×
134
            }),
2✔
135
            case let CredentialOperationsOptions.linkSecret(linkSecretId, secret: linkSecret) = linkSecretOption
2✔
136
        else {
2✔
137
            throw PolluxError.invalidPrismDID
×
138
        }
2✔
139
        
2✔
140
        guard
2✔
141
            let credDefinitionDownloaderOption = options.first(where: {
4✔
142
                if case .credentialDefinitionDownloader = $0 { return true }
4✔
143
                return false
2✔
144
            }),
4✔
145
            case let CredentialOperationsOptions.credentialDefinitionDownloader(downloader) = credDefinitionDownloaderOption
2✔
146
        else {
2✔
147
            throw PolluxError.invalidPrismDID
×
148
        }
2✔
149
        
2✔
150
        return try await CreateAnoncredCredentialRequest.create(
2✔
151
            did: did.string,
2✔
152
            linkSecret: linkSecret,
2✔
153
            linkSecretId: linkSecretId,
2✔
154
            offerData: offerData,
2✔
155
            credentialDefinitionDownloader: downloader,
2✔
156
            thid: thid,
2✔
157
            pluto: self.pluto
2✔
158
        )
2✔
159
    }
2✔
160
}
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

© 2025 Coveralls, Inc