Search…
Managing Password Vault Items

Getting Vault Items

To retrieve a list of vault items, use the listItems function. This function requires a vault identifier to retrieve the vault items. Additionally, if a user wants to get an individual item, an individual item can be fetched by using the vault id and the item id using the getItem function.
TypeScript
Swift
Kotlin
1
const vaultId = /* vault ID from createVault or listVaults */
2
const vaultItems = await client.listItems(vaultId)
3
​
4
const itemId = /* item ID from addItem or listItems */
5
const item = await client.getItem(vaultId, itemId)
Copied!
1
var client: PasswordManagerClient!
2
var vault: Vault!
3
​
4
client.listVaultItems(inVault: vault) { (result) in
5
switch result {
6
case .success(let vaultItems):
7
break
8
case .failure(let error):
9
break
10
}
11
}
12
​
13
client.getVaultItem(id: "1", in: vault) { (result) in
14
switch result {
15
case .success(let maybeVaultItem):
16
if let vaultItem = maybeVaultItem {
17
// use vault item
18
}
19
break
20
case .failure(let error):
21
break
22
}
23
}
Copied!
1
// val client: SudoPasswordManagerClient
2
​
3
launch {
4
try {
5
withContext(Dispatchers.IO) {
6
val vault = client.getVault("1")
7
val vaultItems = client.listVaultItems(vault)
8
val vaultItem = client.getVaultItem("2", vault)
9
}
10
} catch (e: SudoPasswordManagerException) {
11
// Handle any errors related to fetching vault items
12
}
13
}
Copied!

Getting Secret Data

Some properties such as password and notes are considered "secret". These properties remain encrypted in memory even when the Password Manager is unlocked. To access the plaintext value of these properties as a result of user interaction, use the getItemSecret function.
TypeScript
1
import { SecureFieldName } from '@sudoplatform/sudo-password-manager'
2
​
3
const itemId = /* item ID from addItem or listItems */
4
const plaintextPassword = await client.getItemSecret(
5
vaultId,
6
itemId,
7
SecureFieldName.Password
8
)
Copied!
Getting Secret Data is only applicable to Web and Node.js projects. This method is not contained in the iOS and Android SDKs.

Adding a New Vault Item

To add a new vault item, create the desired item with the required data. After an item is created, add the item to the vault using the SDKs' respective function.
Currently, the iOS and Android SDKs support adding VaultLogin , VaultCreditCard , and VaultBankAccount. Those items can be added to the vault using the add function.
In the Web SDK, the add functions naming is more explicit to the type of Item. For example, call addLogin to add a VaultLogin, addBankAccount to add a VaultBankAccount, and addCreditCard to add a VaultCreditCard to a vault.
TypeScript
Swift
Kotlin
1
// In the Web SDK, the add functions are named add<VaultItem>, e.g. addLogin
2
const login = await client.addLogin(vaultId, {
4
password: "SecretPassword",
5
})
Copied!
1
var client: PasswordManagerClient!
2
var vault: Vault!
3
​
4
let login = VaultLogin(user: "[email protected]",
5
url: "http://www.sudoplatform.com",
6
name: "Sudo Platform Login",
7
notes: VaultItemNote(value: "My login for the sudo platform service"),
8
password: VaultItemPassword(value: "SecretPassword"))
9
​
10
client.add(item: login, toVault: vault) { (result) in
11
switch result {
12
case .success(let id):
13
break
14
case .failure(let error):
15
break
16
}
17
}
Copied!
1
// val client: SudoPasswordManagerClient
2
​
3
launch {
4
try {
5
withContext(Dispatchers.IO) {
6
val vault = client.getVault("1")
7
val login = VaultLogin(
8
id = "42",
9
name = "Sudo Platform",
10
11
url = "http://www.sudoplatform.com",
12
note = VaultItemNote(value: "My login for the Sudo Platform"),
13
password = VaultItemPassword(SecureFieldValue("SecretPassword"))
14
)
15
client.add(login, vault)
16
client.update(vault)
17
}
18
} catch (e: SudoPasswordManagerException) {
19
// Handle any errors
20
}
21
}
Copied!
Attempting to add an item with no properties to the vault will result in an error.

Updating a Vault Item

To update a vault item in the Web SDK, pass the vault id, item id, and any properties to update to the item's respective update function; updateLogin , updateBankAccount , and updateCreditCard.
On iOS and Android, the steps are slightly different. First, fetch the full item from the vault. Once you have the VaultLogin, VaultCreditCard, or VaultBankAccount item make any changes to the properties, then save them to the vault using the update function.
Any properties that are not passed to the update function will retain their original value. You can update secret data just like non-secret data.
TypeScript
Swift
Kotlin
1
// In the Web SDK, the update functions are named update<VaultItem>, e.g. updateLogin
2
const itemId = /* item ID from addLogin or listItems */
3
await client.updateLogin(vaultId, itemId, {
4
password: "SecurePassword101",
5
url: undefined, // Pass undefined to clear a property.
6
// Any omitted properties will retain their original value.
7
})
Copied!
1
var client: PasswordManagerClient!
2
var vault: Vault!
3
var login: VaultLogin!
4
​
5
// Make desired changes to the item
6
login.user = "[email protected]"
7
login.password = VaultItemPassword(value: "SecurePassword101")
8
​
9
client.update(item: login, in: vault, completion: { result in
10
switch result {
11
case .success:
12
break
13
case .failure(let error):
14
break
15
}
16
})
Copied!
1
// val client: SudoPasswordManagerClient
2
​
3
launch {
4
try {
5
withContext(Dispatchers.IO) {
6
val vault = client.getVault("1") ?: return@withContext
7
val login = client.getVaultItem("2", vault)
8
if (login is VaultLogin) {
9
val updatedLogin = login.copy(
10
11
password = VaultItemPassword(
12
SecureFieldValue("SecurePassword101")
13
)
14
)
15
client.update(updatedLogin, vault)
16
}
17
}
18
} catch (e: SudoPasswordManagerException) {
19
// Handle any errors
20
}
21
}
Copied!
Attempting to update an item in a vault that doesn't contain the item will result in an error.

Deleting a Vault Item

To delete a vault item, use the removeItem for the Web SDK or removeVaultItem function for iOS and Android SDKs.
TypeScript
Swift
Kotlin
1
const vaultId = "1"
2
const itemId = "2" /* item id can be found from addItem or listItems */
3
await client.removeItem(vaultId, itemId)
Copied!
1
var client: PasswordManagerClient!
2
var vault: Vault!
3
var login: VaultLogin!
4
​
5
client.removeVaultItem(id: login.id, from: vault) { (result) in
6
switch result {
7
case .success:
8
break
9
case .failure(let error):
10
break
11
}
12
}
Copied!
1
// val client: SudoPasswordManagerClient
2
​
3
launch {
4
try {
5
withContext(Dispatchers.IO) {
6
val vault = client.getVault("1")
7
vault.removeVaultItem("2", vault)
8
}
9
} catch (e: SudoPasswordManagerException) {
10
// Handle any errors
11
}
12
}
Copied!
Last modified 8mo ago