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

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

20 Aug 2024 05:00PM UTC coverage: 43.414% (-0.2%) from 43.578%
10475918581

push

github

amagyar-iohk
test: add backup e2e scenario

Signed-off-by: Allain Magyar <allain.magyar@iohk.io>

test: refactor + revocation

Signed-off-by: Allain Magyar <allain.magyar@iohk.io>

test: adds pending validation for edge agent side

Signed-off-by: Allain Magyar <allain.magyar@iohk.io>

fix: jwt verification

Signed-off-by: Allain Magyar <allain.magyar@iohk.io>

test: more tests

Signed-off-by: Allain Magyar <allain.magyar@iohk.io>

test: zkp negative scenario

Signed-off-by: Allain Magyar <allain.magyar@iohk.io>

undo spaces removal

Signed-off-by: Allain Magyar <allain.magyar@iohk.io>

changes int to date

Signed-off-by: Allain Magyar <allain.magyar@iohk.io>

2 of 49 new or added lines in 4 files covered. (4.08%)

5092 of 11729 relevant lines covered (43.41%)

99.27 hits per line

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

29.82
/EdgeAgentSDK/Pollux/Sources/Models/JWT/JWTRevocationCheck.swift
1
import Domain
2
import Foundation
3
import Gzip
4
import JSONWebSignature
5

6
struct JWTRevocationCheck {
7
    let credential: JWTCredential
8

9
    init(credential: JWTCredential) {
2✔
10
        self.credential = credential
2✔
11
    }
2✔
12

13
    func checkIsRevoked() async throws -> Bool {
×
14
        guard let status = credential.jwtVerifiableCredential.verifiableCredential.credentialStatus else {
×
15
            return false
×
16
        }
×
17

×
18
        guard status.type == "StatusList2021Entry" else {
×
19
            throw UnknownError.somethingWentWrongError(customMessage: nil, underlyingErrors: nil)
×
20
        }
×
21

×
22
        let listData = try await DownloadDataWithResolver()
×
23
            .downloadFromEndpoint(urlOrDID: status.statusListCredential)
×
24
        let statusList = try JSONDecoder.didComm().decode(JWTRevocationStatusListCredential.self, from: listData)
×
25
        let encodedList = statusList.credentialSubject.encodedList
×
26
        let index = status.statusListIndex
×
NEW
27
        return try verifyRevocationOnEncodedList(Data(fromBase64URL: encodedList)!, index: index)
×
28
    }
×
29

30
    func verifyRevocationOnEncodedList(_ list: Data, index: Int) throws -> Bool {
2✔
31
        let encodedListData = try list.gunzipped()
2✔
32
        let bitList = encodedListData.flatMap { $0.toBits() }
32,768✔
33
        guard index < bitList.count else {
2✔
34
            throw UnknownError.somethingWentWrongError(customMessage: "Revocation index out of bounds", underlyingErrors: nil)
×
35
        }
2✔
36
        return bitList[index]
2✔
37
    }
2✔
38
}
39

40
extension UInt8 {
41
    func toBits() -> [Bool] {
32,768✔
42
        var bits = [Bool](repeating: false, count: 8)
32,768✔
43
        for i in 0..<8 {
262,144✔
44
            bits[7 - i] = (self & (1 << i)) != 0
262,144✔
45
        }
262,144✔
46
        return bits
32,768✔
47
    }
32,768✔
48
}
49

50
fileprivate struct DownloadDataWithResolver: Downloader {
51

52
    public func downloadFromEndpoint(urlOrDID: String) async throws -> Data {
×
53
        let url: URL
×
54

×
55
        if let validUrl = URL(string: urlOrDID.replacingOccurrences(of: "host.docker.internal", with: "localhost")) {
×
56
            url = validUrl
×
57
        } else {
×
58
            throw CommonError.invalidURLError(url: urlOrDID)
×
59
        }
×
60

×
61
        let (data, urlResponse) = try await URLSession.shared.data(from: url)
×
62

×
63
        guard
×
64
            let code = (urlResponse as? HTTPURLResponse)?.statusCode,
×
65
            200...299 ~= code
×
66
        else {
×
67
            throw CommonError.httpError(
×
68
                code: (urlResponse as? HTTPURLResponse)?.statusCode ?? 500,
×
69
                message: String(data: data, encoding: .utf8) ?? ""
×
70
            )
×
71
        }
×
72

×
73
        return data
×
74
    }
×
75
}
76

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