Search
⌃K

Manage DIDs

Provides the essentials to allow your users to create and manage local Decentralized Identifiers

Create a DID

A new local DID can be created within a wallet by calling the createDid API with a CreateDidInput object. Any string metadata can be assigned to a DID, such as a JSON object. Further, an endpoint can also be associated with the DID. On success, a DidData object will be returned containing the did and the verkey associated with that DID.
The SDK will dispatch the createDid call on a background thread by default.
Currently, the did:key DID Method is supported, with an Ed25519 key type. These DIDs are suitable for usage in DIDComm connections and much more.
Swift
Kotlin
The following code snippet is an example of how to create a DID in a wallet identified by walletId. The DID method is key and the type of associated key pair is ed25519. Metadata and an endpoint may also be provided.
let client: SudoDIWalletClient = // Instantiated client
let walletId: String = // Wallet identifier of an open wallet
​
let input = CreateDidInput(
walletId: walletId,
method: .key,
keyType: .ed25519,
metadata: "metadata",
endpoint: "example.com"
do {
let didData = try await client.createDid(input)
} catch {
// Handle error
}
The following code snippet is an example of how to create a DID in a wallet identified by walletId. The DID method is key and the type of associated key pair is ed25519. Metadata and an endpoint may also be provided.
val client: SudoDIWalletClient = // Instantiated client
val walletId: String = // Wallet identifier of an open wallet
​
val input = CreateDidInput(
walletId = openWalletId,
method = DidMethod.KEY,
keyType = KeyType.ED25519,
metadata = "metadata",
endpoint = "example.com"
)
​
launch {
try {
val didData: DidData = client.createDid(input)
} catch (e: DIWalletException) {
// Handle/notify user of exception
}
}

List DIDs Inside a Wallet

All DIDs stored inside an open wallet can be listed by using the listDids API.
The SDK will dispatch the listDids call on a background thread by default.
Swift
Kotlin
let client: SudoDIWalletClient = // Instantiated client
let walletId: String = // Wallet identifier of an open wallet
​
do {
let dids = try await client.listDids(fromWallet: walletId)
} catch {
// Handle error
}
val client: SudoDIWalletClient = // Instantiated client
val walletId: String = // Wallet identifier of an open wallet
​
launch {
try {
val walletDids: List<DidData> = client.listDids(walletId)
} catch (e: DIWalletException) {
// Handle/notify user of exception
}
}

Retrieving DID Data

Data associated with a specific DID, such as the verification key (verkey) and any assigned metadata (metadata) can be retrieved using getDidData. The data is represented in the DidData object.
The SDK will dispatch the getDidData call on a background thread by default.
Swift
Kotlin
let client: SudoDIWalletClient = // Instantiated client
let walletId: String = // Wallet identifier of an open wallet
let did: String = // Existing DID
​
do {
let didData = try await client.getDidData(fromWallet: walletId, forDid: did)
} catch {
// Handle error
}
val client: SudoDIWalletClient = // Instantiated client
val walletId: String = // Wallet identifier of an open wallet
val did: String = // Existing DID
​
launch {
try {
val walletDidData: DidData? = client.getDidData(walletId, did)
} catch (e: DIWalletException) {
// Handle/notify user of exception
}
}
The returned DidData data objects represent the state of the DID at the time of calling the API. Therefore, if the DID data within the wallet (e.g. the metadata) is updated, the listDids or getDidData API should be called again to fetch the updated state.

Update DID Data

To update the data associated with a DID, use the updateDidData API. It requires an UpdateDidInput object that can be populated with new data.
The SDK will dispatch the updateDidData call on a background thread by default.
The metadata and endpoint fields of the UpdateDidInput will override the existing values for the DID. Providing a null/nil value for metadata will result in no update occurring to the DID's metadata. Likewise for the endpoint field.
Swift
Kotlin
The following example demonstrates how to update a DID with a new endpoint and metadata. The walletId is the identifier of the wallet that contains the existing DID to update.
let client: SudoDIWalletClient = // Instantiated client
let walletId: String = // Wallet identifier of an open wallet
let did: String = // Existing DID to update
​
let input = UpdateDidInput {
walletId: walletId,
did: did,
metadata: "new metadata",
endpoint: "new endpoint"
}
do {
let updatedDidData = try await client.updateDidData(input)
} catch {
// Handle error
}
The following example demonstrates how to update a DID with a new endpoint and metadata. The walletId is the identifier of the wallet that contains the existing DID to update.
val client: SudoDIWalletClient = // Instantiated client
val walletId: String = // Wallet identifier of an open wallet
val did: String = // Existing DID to update
​
val input = UpdateDidInput(
walletId = walletId,
did = did,
metadata = "new metadata",
endpoint = "new endpoint"
)
​
launch {
try {
val updatedDidData: DidData = client.updateDidData(input)
} catch (e: DIWalletException) {
// Handle/notify user of exception
}
}
​