Search
⌃K

Manage Keys

Essential key management capabilities for the DI wallet
Key pairs are generated when DIDs are created. Stand-alone key pairs can also be generated without being associated with a DID. Information about DID-associated and DID-less keys can be requested.

Create Verification Key

Key pairs not associated with a DID can be generated via the createVerificationKey API with the given key type.
The SDK will dispatch the createVerificationKey call on a background thread by default.
Swift
Kotlin
The following example demonstrates how to generate an Ed25519 key pair without being associated with a DID.
let client: SudoDIWalletClient = // Instantiated client
let walletId: String = // Wallet identifier of an open wallet
let keyType: KeyType = .ed25519
do {
let verkey = try await client.createVerificationKey(withWallet: walletId, keyType: keyType)
} catch {
// Handle error
}
The following example demonstrates how to generate an Ed25519 key pair without being associated with a DID.
val client: SudoDIWalletClient = // Instantiated client
val walletId: String = // Wallet identifier of an open wallet
val keyType: KeyType = KeyType.ED25519
launch {
try {
val verkey: String = client.createVerificationKey(walletId, keyType)
} catch (e: DIWalletException) {
// Handle/notify user of exception
}
}

Get Key Information

Information about a key pair, whether they are or are not associated with a DID, can be requested by using the getKeyInfo API. The secret key will only be returned if requested via the withSecretKey flag.
The SDK will dispatch the getKeyInfo call on a background thread by default.
As with all private keys, the private key of a DID/key should be handled extremely carefully. A leaked private key would allow for a DID/key to be cloned and impersonated by a malicious party.
Swift
Kotlin
The following code gets the key information for a verification key, verkey, that has been stored inside the wallet identified by walletId. Firstly the information is requested with the secret key, and then without.
let client: SudoDIWalletClient = // Instantiated client
let walletId: String = // Wallet identifier of an open wallet
let verkey: String = // Existing verification key of a key or DID
do {
// with secret key
let infoSk = try await client.getKeyInfo(
fromWallet: walletId,
withVerificationKey: verkey,
withSecretKey: true
)
// without secret key
let info = try await client.getKeyInfo(
fromWallet: walletId,
withVerificationKey: verkey
)
} catch {
// Handle error
}
The following code gets the key information for a verification key, verkey, that has been stored inside the wallet identified by walletId. Firstly the information is requested with the secret key, and then without.
val client: SudoDIWalletClient = // Instantiated client
val walletId: String = // Wallet identifier of an open wallet
val verkey: String = // Existing verification key of a key or DID
launch {
try {
// without secret key
val keyInfo: KeyInfo? = client.getKeyInfo(walletId, verkey)
// with secret key
val keyInfoSk: KeyInfo? = client.getKeyInfo(walletId, verkey, withSecretKey = true)
} catch (e: DIWalletException) {
// Handle/notify user of exception
}
}