• 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

29.51
/EdgeAgentSDK/Pollux/Sources/Operation/JWT/CreateJWTCredentialRequest.swift
1
import Combine
2
import Domain
3
import Foundation
4
import JSONWebAlgorithms
5
import JSONWebKey
6
import JSONWebToken
7
import JSONWebSignature
8

9
private struct Schema: Codable {
10
    let name: String
11
    let version: String
12
    let attrNames: [String]
13
    let issuerId: String
14
}
15

16
struct CreateJWTCredentialRequest {
NEW
17
    static func create(didStr: String, key: ExportableKey, offerData: Data) async throws -> String {
×
18
        let jsonObject = try JSONSerialization.jsonObject(with: offerData)
×
19
        guard
×
20
            let domain = findValue(forKey: "domain", in: jsonObject),
×
21
            let challenge = findValue(forKey: "challenge", in: jsonObject)
×
22
        else { throw PolluxError.offerDoesntProvideEnoughInformation }
×
23
        
×
24
        let keyJWK = key.jwk
×
NEW
25
        let claims = ClaimsRequestSignatureJWT(
×
NEW
26
            iss: didStr,
×
NEW
27
            sub: nil,
×
NEW
28
            aud: [domain],
×
NEW
29
            exp: nil,
×
NEW
30
            nbf: nil,
×
NEW
31
            iat: nil,
×
NEW
32
            jti: nil,
×
NEW
33
            nonce: challenge,
×
NEW
34
            vp: .init(context: .init([
×
NEW
35
                "https://www.w3.org/2018/presentations/v1"
×
NEW
36
            ]), type: .init([
×
NEW
37
                "VerifiablePresentation"
×
NEW
38
            ]))
×
NEW
39
        )
×
NEW
40

×
NEW
41
        ES256KSigner.invertedBytesR_S = true
×
NEW
42

×
43
        let jwt = try JWT.signed(
×
NEW
44
            payload: claims,
×
45
            protectedHeader: DefaultJWSHeaderImpl(algorithm: .ES256K),
×
NEW
46
            key: JSONWebKey.JWK(
×
47
                keyType: .init(rawValue: keyJWK.kty)!,
×
48
                keyID: keyJWK.kid,
×
49
                x: keyJWK.x.flatMap { Data(fromBase64URL: $0) },
×
50
                y: keyJWK.y.flatMap { Data(fromBase64URL: $0) },
×
51
                d: keyJWK.d.flatMap { Data(fromBase64URL: $0) }
×
52
            )
×
53
        )
×
54

×
NEW
55
        ES256KSigner.invertedBytesR_S = false
×
NEW
56
        return jwt.jwtString
×
UNCOV
57
    }
×
58
}
59

60
struct ClaimsRequestSignatureJWT: JWTRegisteredFieldsClaims, Codable {
61
    struct VerifiablePresentation: Codable {
62
        enum CodingKeys: String, CodingKey {
63
            case context = "@context"
64
            case type = "type"
65
        }
66

67
        let context: Set<String>
68
        let type: Set<String>
69
    }
70

71
    let iss: String?
72
    let sub: String?
73
    let aud: [String]?
74
    let exp: Date?
75
    let nbf: Date?
76
    let iat: Date?
77
    let jti: String?
78
    let nonce: String
79
    let vp: VerifiablePresentation
80

81
    func validateExtraClaims() throws {}
×
82
}
83

84

85
// TODO: This function is not the most appropriate but will do the job now to change later.
86
func findValue(forKey key: String, in json: Any) -> String? {
80✔
87
    if let dict = json as? [String: Any] {
80✔
88
        if let value = dict[key] {
36✔
89
            return value as? String
4✔
90
        }
32✔
91
        for (_, subJson) in dict {
60✔
92
            if let foundValue = findValue(forKey: key, in: subJson) {
60✔
93
                return foundValue
4✔
94
            }
56✔
95
        }
56✔
96
    } else if let array = json as? [Any] {
72✔
97
        for subJson in array {
16✔
98
            if let foundValue = findValue(forKey: key, in: subJson) {
16✔
99
                return foundValue
×
100
            }
16✔
101
        }
16✔
102
    }
72✔
103
    return nil
72✔
104
}
72✔
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