• 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

0.0
/EdgeAgentSDK/Mercury/Sources/DIDCommWrappers/DIDCommDIDResolverWrapper.swift
1
import Combine
2
import Core
3
import DIDCommSwift
4
import DIDCore
5
import Domain
6
import Foundation
7

8
class DIDCommDIDResolverWrapper {
9
    let logger: SDKLogger
10
    let castor: Castor
11
    var publisher = PassthroughSubject<Domain.DIDDocument, Error>()
×
12
    var cancellables = [AnyCancellable]()
×
13

14
    init(castor: Castor, logger: SDKLogger) {
×
15
        self.castor = castor
×
16
        self.logger = logger
×
17
    }
×
18

19
    fileprivate func resolve(did: String) {
×
20
        Task { [weak self] in
×
21
            let document = try await self?.castor.resolveDID(did: DID(string: did))
×
22
            document.map { self?.publisher.send($0) }
×
23
        }
×
24
    }
×
25
}
26

27
extension DIDCommDIDResolverWrapper: DIDResolver {
28
    func resolve(did: DIDCore.DID) async throws -> DIDCore.DIDDocument {
×
29
        let document = try await castor.resolveDID(did: DID(string: did.description))
×
30
        return try .init(from: document)
×
31
    }
×
32
}
33

34
extension DIDCore.DIDDocument {
35
    init(from: Domain.DIDDocument) throws {
×
36
        var authentications = [String]()
×
37
        var keyAgreements = [String]()
×
38
        let verificationMethods: [VerificationMethod] = try from.verificationMethods.compactMap {
×
39
            switch KnownVerificationMaterialType(rawValue: $0.type) {
×
40
            case .agreement:
×
41
                keyAgreements.append($0.id.string)
×
42
            case .authentication:
×
43
                authentications.append($0.id.string)
×
44
            default:
×
45
                return nil
×
46
            }
×
47

×
48
            if
×
49
                let jsonKeys = try $0.publicKeyJwk?.convertToJsonString()
×
50
            {
×
51
                return .init(
×
52
                    id: $0.id.string,
×
53
                    controller: $0.controller.string,
×
54
                    type: $0.type,
×
55
                    material: try .fromJWK(jwk: JSONDecoder().decode(JWK.self, from: jsonKeys.tryToData()))
×
56
                )
×
57
            } else if let multibase = $0.publicKeyMultibase {
×
58
                return .init(
×
59
                    id: $0.id.string,
×
60
                    controller: $0.controller.string,
×
61
                    type: $0.type,
×
62
                    material: .init(format: .multibase, value: try multibase.tryToData())
×
63
                )
×
64
            } else {
×
65
                return nil
×
66
            }
×
67
        }
×
68

×
69
        let services = from.services.flatMap { service in
×
70
            service.serviceEndpoint.map {
×
71
                return Service(
×
72
                    id: service.id,
×
73
                    type: service.type.first ?? "",
×
74
                    serviceEndpoint: AnyCodable(
×
75
                        dictionaryLiteral: 
×
76
                            ("uri", $0.uri),
×
77
                            ("accept", $0.accept),
×
78
                            ("routing_keys", $0.routingKeys)
×
79
                    )
×
80
                )
×
81
            }
×
82
        }
×
83
        self.init(
×
84
            id: from.id.string,
×
85
            verificationMethods: verificationMethods,
×
86
            authentication: authentications.map { .stringValue($0) },
×
87
            keyAgreement: keyAgreements.map { .stringValue($0) },
×
NEW
88
            services: services.map { $0.toAnyCodable() }
×
89
        )
×
90
    }
×
91
}
92

93
extension Dictionary where Key == String, Value == String {
94
    func convertToJsonString() throws -> String? {
×
95
        try Core.convertToJsonString(dic: self)
×
96
    }
×
97
}
98

99
extension DIDCore.DIDDocument.Service {
NEW
100
    init(from: DIDCore.AnyCodable) throws {
×
NEW
101
        guard
×
NEW
102
            let dic = from.value as? [String: Any],
×
NEW
103
            let id = dic["id"] as? String,
×
NEW
104
            let type = dic["type"] as? String,
×
NEW
105
            let serviceEndpoint = dic["serviceEndpoint"]
×
NEW
106
        else { throw CommonError.invalidCoding(message: "Could not decode service") }
×
NEW
107
        switch serviceEndpoint {
×
NEW
108
        case let value as DIDCore.AnyCodable:
×
NEW
109
            self = .init(
×
NEW
110
                id: id,
×
NEW
111
                type: type,
×
NEW
112
                serviceEndpoint: value
×
NEW
113
            )
×
NEW
114
        case let value as String:
×
NEW
115
            self = .init(
×
NEW
116
                id: id,
×
NEW
117
                type: type,
×
NEW
118
                serviceEndpoint: AnyCodable(value)
×
NEW
119
            )
×
NEW
120
        case let value as [String: Any]:
×
NEW
121
            self = .init(
×
NEW
122
                id: id,
×
NEW
123
                type: type,
×
NEW
124
                serviceEndpoint: AnyCodable(value)
×
NEW
125
            )
×
NEW
126
        case let value as [String]:
×
NEW
127
            self = .init(
×
NEW
128
                id: id,
×
NEW
129
                type: type,
×
NEW
130
                serviceEndpoint: AnyCodable(value)
×
NEW
131
            )
×
NEW
132
        default:
×
NEW
133
            throw CommonError.invalidCoding(message: "Could not decode service")
×
NEW
134
        }
×
NEW
135
    }
×
136

NEW
137
    func toAnyCodable() -> DIDCore.AnyCodable {
×
NEW
138
        AnyCodable(dictionaryLiteral:
×
NEW
139
            ("id", self.id),
×
NEW
140
            ("type", self.type),
×
NEW
141
            ("serviceEndpoint", self.serviceEndpoint.value)
×
NEW
142
        )
×
NEW
143
    }
×
144
}
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