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

hyperledger-identus / sdk-swift / 23133542414

16 Mar 2026 07:59AM UTC coverage: 41.035% (-0.4%) from 41.423%
23133542414

Pull #230

github

web-flow
Merge ffcda358a into 1c55818b1
Pull Request #230: feat: deterministic PRISM DID creation with CompressedECKeyData

4 of 39 new or added lines in 3 files covered. (10.26%)

45 existing lines in 2 files now uncovered.

6509 of 15862 relevant lines covered (41.04%)

223.98 hits per line

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

78.9
/EdgeAgentSDK/EdgeAgent/Sources/DIDCommAgent/DIDCommAgent+DIDs.swift
1
import Combine
2
import Domain
3
import Foundation
4

5
// MARK: DID High Level functionalities
6
public extension DIDCommAgent {
7

8
    /// This method create a new Prism DID, that can be used to identify the agent and interact with other agents.
9
    /// - Parameters:
10
    ///   - keyPathIndex: key path index used to identify the DID
11
    ///   - alias: An alias that can be used to identify the DID
12
    ///   - services: an array of services associated to the DID
13
    /// - Returns: The new created DID
14
    func createNewPrismDID(
15
        keys: [(KeyPurpose, PrivateKey)] = [],
16
        keyPathIndex: Int? = nil,
17
        alias: String? = nil,
18
        services: [DIDDocument.Service] = []
19
    ) async throws -> DID {
12✔
20
        try await edgeAgent.createNewPrismDID(
12✔
21
            keys: keys,
12✔
22
            keyPathIndex: keyPathIndex,
12✔
23
            alias: alias,
12✔
24
            services: services
12✔
25
        )
12✔
26
    }
12✔
27

28
    /// Creates a deterministic Prism DID from a BIP-39 mnemonic phrase.
29
    /// The same mnemonic + passphrase + didIndex always produces the same DID.
30
    ///
31
    /// - Parameters:
32
    ///   - mnemonic: BIP-39 mnemonic words
33
    ///   - passphrase: Optional BIP-39 passphrase (default: empty string)
34
    ///   - didIndex: DID index in the derivation path (default: 0)
35
    ///   - alias: An optional alias for the DID
36
    /// - Returns: The deterministic DID
37
    func createDeterministicPrismDID(
38
        mnemonic: [String],
39
        passphrase: String = "",
40
        didIndex: Int = 0,
41
        alias: String? = nil
NEW
42
    ) async throws -> DID {
×
NEW
43
        try await edgeAgent.createDeterministicPrismDID(
×
NEW
44
            mnemonic: mnemonic,
×
NEW
45
            passphrase: passphrase,
×
NEW
46
            didIndex: didIndex,
×
NEW
47
            alias: alias
×
NEW
48
        )
×
NEW
49
    }
×
50

51
    /// This method registers a Prism DID, that can be used to identify the agent and interact with other agents.
52
    /// - Parameters:
53
    ///   - did: the DID which will be registered.
54
    ///   - keyPathIndex: key path index used to identify the DID
55
    ///   - alias: An alias that can be used to identify the DID
56
    /// - Returns: The new created DID
57
    func registerPrismDID(
58
        did: DID,
59
        privateKey: PrivateKey,
60
        alias: String? = nil
61
    ) async throws {
×
62
        try await edgeAgent.registerPrismDID(
×
63
            did: did,
×
64
            privateKey: privateKey,
×
65
            alias: alias
×
66
        )
×
67
    }
×
68
    /// This function creates a new Peer DID, stores it in pluto database and updates the mediator if requested.
69
    ///
70
    /// - Parameters:
71
    ///   - services: The services associated to the new DID.
72
    ///   - updateMediator: Indicates if the new DID should be added to the mediator's list. It will as well add the mediator service.
73
    /// - Returns: A new DID
74
    /// - Throws: EdgeAgentError, if updateMediator is true and there is no mediator available or if storing the new DID failed
75
    func createNewPeerDID(
76
        services: [DIDDocument.Service] = [],
77
        alias: String? = "",
78
        updateMediator: Bool
79
    ) async throws -> DID {
4✔
80
        var keyAgreementPrivateKey = try apollo.createPrivateKey(parameters: [
4✔
81
            KeyProperties.type.rawValue: "EC",
4✔
82
            KeyProperties.curve.rawValue: KnownKeyCurves.x25519.rawValue
4✔
83
        ])
4✔
84

4✔
85
        var authenticationPrivateKey = try apollo.createPrivateKey(parameters: [
4✔
86
            KeyProperties.type.rawValue: "EC",
4✔
87
            KeyProperties.curve.rawValue: KnownKeyCurves.ed25519.rawValue
4✔
88
        ])
4✔
89

4✔
90
        let withServices: [DIDDocument.Service]
4✔
91
        if updateMediator, let routingDID = mediatorRoutingDID?.string {
4✔
92
            withServices = services + [.init(
4✔
93
                id: "#didcomm-1",
4✔
94
                type: .one("DIDCommMessaging"),
4✔
95
                serviceEndpoint: .one(.init(
4✔
96
                    uri: routingDID
4✔
97
                )))]
4✔
98
        } else {
4✔
99
            withServices = services
×
100
        }
×
101

4✔
102
        let newDID = try castor.createPeerDID(
4✔
103
            keyAgreementPublicKey: keyAgreementPrivateKey.publicKey(),
4✔
104
            authenticationPublicKey: authenticationPrivateKey.publicKey(),
4✔
105
            services: withServices
4✔
106
        )
4✔
107

4✔
108
        let didDocument = try await castor.resolveDID(did: newDID)
4✔
109
        didDocument.authenticate.first.map { authenticationPrivateKey.identifier = $0.id.string }
4✔
110
        didDocument.keyAgreement.first.map { keyAgreementPrivateKey.identifier = $0.id.string }
4✔
111

4✔
112
        logger.debug(message: "Created new Peer DID", metadata: [
4✔
113
            .maskedMetadataByLevel(key: "DID", value: newDID.string, level: .debug)
4✔
114
        ])
4✔
115

4✔
116
        try await registerPeerDID(
4✔
117
            did: newDID,
4✔
118
            privateKeys: [
4✔
119
                keyAgreementPrivateKey,
4✔
120
                authenticationPrivateKey
4✔
121
            ],
4✔
122
            alias: alias,
4✔
123
            updateMediator: updateMediator
4✔
124
        )
4✔
125

4✔
126
        return newDID
4✔
127
    }
4✔
128

129
    /// This function registers a Peer DID, stores it and his private key in pluto database and updates the mediator if requested.
130
    ///
131
    /// - Parameters:
132
    ///   - services: The services associated to the new DID.
133
    ///   - updateMediator: Indicates if the new DID should be added to the mediator's list.
134
    /// - Returns: A new DID
135
    /// - Throws: EdgeAgentError, if updateMediator is true and there is no mediator available or if storing the new DID failed
136
    func registerPeerDID(
137
        did: DID,
138
        privateKeys: [PrivateKey],
139
        alias: String?,
140
        updateMediator: Bool
141
    ) async throws {
4✔
142
        if updateMediator {
4✔
143
            try await updateMediatorWithDID(did: did)
4✔
144
        }
4✔
145
        logger.debug(message: "Register of DID in storage", metadata: [
4✔
146
            .maskedMetadataByLevel(key: "DID", value: did.string, level: .debug)
4✔
147
        ])
4✔
148

4✔
149
        let storablePrivateKeys = try privateKeys
4✔
150
            .map {
8✔
151
                guard let storablePrivateKey = $0 as? (PrivateKey & StorableKey) else {
8✔
152
                    throw KeyError.keyRequiresConformation(conformations: ["PrivateKey", "StorableKey"])
×
153
                }
8✔
154
                return storablePrivateKey
8✔
155
            }
8✔
156

4✔
157
        try await pluto
4✔
158
            .storePeerDID(
4✔
159
                did: did,
4✔
160
                privateKeys: storablePrivateKeys,
4✔
161
                alias: alias
4✔
162
            )
4✔
163
            .first()
4✔
164
            .await()
4✔
165
    }
4✔
166

167
    /// This function updates the mediator key list with a new DID.
168
    ///
169
    /// - Parameters:
170
    ///   - services: The services associated to the new DID.
171
    ///   - updateMediator: Indicates if the new DID should be added to the mediator's list.
172
    /// - Returns: A new DID
173
    /// - Throws: EdgeAgentError, if updateMediator is true and there is no mediator available
174
    func updateMediatorWithDID(did: DID) async throws {
4✔
175
        logger.debug(message: "Update mediator key list with DID", metadata: [
4✔
176
            .maskedMetadataByLevel(key: "DID", value: did.string, level: .debug)
4✔
177
        ])
4✔
178

4✔
179
        try await mediationHandler?.updateKeyListWithDIDs(dids: [did])
4✔
180
    }
4✔
181

182
    /// This function gets all the DID peers from the `pluto` store
183
    ///
184
    /// - Returns: A publisher that emits an array of tuples (`DID`, `String?`) objects, or an error if there was a problem getting the dids
185
    func getAllRegisteredPeerDIDs() -> AnyPublisher<[(did: DID, alias: String?)], Error> {
×
186
        pluto.getAllPeerDIDs()
×
187
            .map { $0.map { ($0.did, $0.alias) } }
×
188
            .eraseToAnyPublisher()
×
189
    }
×
190
}
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