Manage Wallets
Provides the abilities to allow users to create and manage their own secure wallets
A wallet manages the user's DI data, such as DIDs, their metadata and endpoints, and records. Essential wallet management capabilities are described below.
To effectively manage a user's DI data, a wallet must be created to securely store that data.
Each wallet must be created with a unique
id
along with a secure passphrase
. To create a new wallet on the user's device, call the createWallet
method with those parameters. The chosen unique id
should be saved in consuming apps, as it is required to open the wallet. The SDK will dispatch the
createWallet
call on a background thread by default.Swift
Kotlin
let client: SudoDIWalletClient = // Instantiated client
let walletId: String = // Unique wallet identifier
do {
try await client.createWallet(withId: walletId, passphrase: "[email protected]!")
} catch {
// Handle error
}
val client: SudoDIWalletClient = // Instantiated client
val walletId: String = // Unique wallet identifier
launch {
try {
client.createWallet(walletId, "[email protected]!")
} catch (e: DIWalletException) {
// Handle/notify user of exception
}
}
To access and manage the data within a wallet, it must first be opened successfully by calling
openWallet
with the correct id
and passphrase
used when the wallet was created. If the wallet is not successfully opened, an exception/error will be thrown.The SDK will dispatch the
openWallet
call on a background thread by default.Swift
Kotlin
let client: SudoDIWalletClient = // Instantiated client
let walletId: String = // Existing wallet identifier
do {
try await client.openWallet(withId: walletId, passphrase: "[email protected]!")
} catch {
// Handle error
}
val client: SudoDIWalletClient = // Instantiated client
val walletId: String = // Existing wallet identifier
launch {
try {
client.openWallet(walletId, "[email protected]!")
} catch (e: DIWalletException) {
// Handle/notify user of exception
}
}
A wallet must be open prior to performing operations inside the wallet. To check whether a wallet is open, call
walletOpened
with the unique identifier for the wallet, id
. This can be used to ensure wallet data is accessible or that the wallet may be deleted if closed.The SDK will dispatch the
walletOpened
call on a background thread by default.Swift
Kotlin
let client: SudoDIWalletClient = // Instantiated client
let walletId: String = // Existing wallet identifier
do {
let opened: Bool = try await client.walletOpened(withId: walletId)
if opened {
// Handle wallet being open
} else {
// Handle wallet being closed
}
} catch {
// Handle error
}
val client: SudoDIWalletClient = // Instantiated client
val walletId: String = // Existing wallet identifier
launch {
try {
val opened: Boolean = client.walletOpened(walletId)
if (opened) {
// Handle wallet being open
} else {
// Handle wallet being closed
}
} catch (e: DIWalletException) {
// Handle/notify user of exception
}
}
An opened wallet can be closed by calling
closeWallet
with the id
of the wallet used for creation via the createWallet
API. Closing a wallet will disallow read and write operations to the wallet until it is subsequently opened again. A wallet may be deleted once closed via the deleteWallet
API. The SDK will dispatch the
closeWallet
call on a background thread by default.Swift
Kotlin
let client: SudoDIWalletClient = // Instantiated client
let walletId: String = // Wallet identifier of an open wallet
do {
try await client.closeWallet(withId: walletId)
} catch {
// Handle error
}
val client: SudoDIWalletClient = // Instantiated client
val walletId: String = // Wallet identifier of an open wallet
launch {
try {
client.closeWallet(walletId)
} catch (e: DIWalletException) {
// Handle/notify user of exception
}
}
To delete a wallet from storage on the user's device, call
deleteWallet
with the id
and passphrase
that was used to originally create the wallet. Deleting the wallet will erase all of the user's DI data within that wallet. The wallet must be closed before deleting it.The SDK will dispatch the
deleteWallet
call on a background thread by default.Swift
Kotlin
let client: SudoDIWalletClient = // Instantiated client
let walletId: String = // Existing wallet identifier
do {
try await client.deleteWallet(withId: walletId, passphrase: "[email protected]!")
} catch {
// Handle error
}
val client: SudoDIWalletClient = // Instantiated client
val walletId: String = // Existing wallet identifier
launch {
try {
client.deleteWallet(walletId, "[email protected]!")
} catch (e: DIWalletException) {
// Handle/notify user of exception
}
}
The existence of a wallet identified by
id
can be checked using walletExists
.The SDK will dispatch the
walletExists
call on a background thread by default.Swift
Kotlin
let client: SudoDIWalletClient = // Instantiated client
let walletId: String = // Wallet identifier
do {
let exists: Bool = try await client.walletExists(withId: walletId)
if exists {
// Handle wallet existing
} else {
// Handle wallet not existing
}
} catch {
// Handle error
}
val client: SudoDIWalletClient = // Instantiated client
val walletId: String = // Wallet identifier
launch {
try {
val exists: Boolean = client.walletExists(walletId)
if (exists) {
// Handle wallet existing
} else {
// Handle wallet not existing
}
} catch (e: DIWalletException) {
// Handle/notify user of exception
}
}
Last modified 8mo ago