Search…
Managing Password Vault Items
Provides the essentials to allow your users to manage their vault items within a vault

Retrieving Vault Items

To retrieve a list of vault items, use the listItems method. This method 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 method.
TypeScript
Swift
Kotlin
try {
const vaultId = /* vault ID from createVault or listVaults */
const vaultItems = await client.listItems(vaultId)
} catch {
// Handle/notify user of errors
}
try {
const itemId = /* item ID from addItem or listItems */
const item = await client.getItem(vaultId, itemId)
} catch {
// Handle/notify user of errors
}
var client: PasswordManagerClient!
var vault: Vault!
client.listVaultItems(inVault: vault) { (result) in
switch result {
case .success(let vaultItems):
break
case .failure(let error):
break
}
}
client.getVaultItem(id: "1", in: vault) { (result) in
switch result {
case .success(let maybeVaultItem):
if let vaultItem = maybeVaultItem {
// use vault item
}
break
case .failure(let error):
break
}
}
// val client: SudoPasswordManagerClient
launch {
try {
withContext(Dispatchers.IO) {
val vault = client.getVault("1")
val vaultItems = client.listVaultItems(vault)
val vaultItem = client.getVaultItem("2", vault)
}
} catch (e: SudoPasswordManagerException) {
// Handle any errors related to fetching vault items
}
}

Retrieving 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 method.
TypeScript
import { SecureFieldName } from '@sudoplatform/sudo-password-manager'
const itemId = /* item ID from addItem or listItems */
const plaintextPassword = await client.getItemSecret(
vaultId,
itemId,
SecureFieldName.Password
)
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 add method.
Currently, the iOS, Android, and web SDKs support adding VaultLogin, VaultCreditCard, VaultBankAccount, VaultContact, VaultDocument, VaultDriversLicense, VaultMembership, VaultPassport, and VaultSocialSecurityNumber. These items can be added to the vault using the add method.
TypeScript
Swift
Kotlin
try {
const login = await client.addItem(vaultId, {
url: 'anonyome.com',
password: "SecretPassword",
hexColor: "0xFF0000",
favorite: true,
type: 'login',
})
} catch {
// Handle/notify user of errors
}
var client: PasswordManagerClient!
var vault: Vault!
let login = VaultLogin(user: "[email protected]",
url: "http://www.sudoplatform.com",
name: "Sudo Platform Login",
notes: VaultItemNote(value: "My login for the sudo platform service"),
password: VaultItemPassword(value: "SecretPassword")
hexColor: "0xFF0000",
favorite: true)
client.add(item: login, toVault: vault) { (result) in
switch result {
case .success(let id):
break
case .failure(let error):
break
}
}
// val client: SudoPasswordManagerClient
launch {
try {
withContext(Dispatchers.IO) {
val vault = client.getVault("1")
val login = VaultLogin(
id = "42",
name = "Sudo Platform",
url = "http://www.sudoplatform.com",
note = SecureFieldValue("My login for the Sudo Platform"),
password = VaultItemPassword(SecureFieldValue("SecretPassword")),
hexcolor = "0xFF0000",
favorite = true,
)
client.add(login, vault)
client.update(vault)
}
} catch (e: SudoPasswordManagerException) {
// Handle any errors
}
}
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 JS SDK, pass the vault id, item id, and any properties to updateItem method. To remove a property's value, pass in the value undefined. Any omitted properties from the object will retain its original value.
On iOS and Android, the steps are slightly different. First, fetch the full item from the vault. Once you have the vault item (e.g. VaultLogin, VaultCreditCard, or VaultBankAccount) make any changes to the properties, then save them to the vault using the update method.
Any properties that are not passed to the update method will retain their original value. You can update secret data just like non-secret data.
TypeScript
Swift
Kotlin
try {
const itemId = /* item ID from addItem or listItems */
await client.updateItem(vaultId, itemId, {
type: 'login',
password: "SecurePassword101",
url: undefined, // Pass undefined to clear a property.
// Any omitted properties will retain its original value.
})
} catch {
// Handle/notify user of errors
}
var client: PasswordManagerClient!
var vault: Vault!
var login: VaultLogin!
// Make desired changes to the item
login.user = "[email protected]"
login.password = VaultItemPassword(value: "SecurePassword101")
client.update(item: login, in: vault, completion: { result in
switch result {
case .success:
break
case .failure(let error):
break
}
})
// val client: SudoPasswordManagerClient
launch {
try {
withContext(Dispatchers.IO) {
val vault = client.getVault("1") ?: return@withContext
val login = client.getVaultItem("2", vault)
if (login is VaultLogin) {
val updatedLogin = login.copy(
password = VaultItemPassword(
SecureFieldValue("SecurePassword101")
)
)
client.update(updatedLogin, vault)
}
}
} catch (e: SudoPasswordManagerException) {
// Handle any errors
}
}
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 method for the JS SDK or removeVaultItem method for iOS and Android SDKs.
TypeScript
Swift
Kotlin
try {
const vaultId = "1"
const itemId = "2" /* item id can be found from addItem or listItems */
await client.removeItem(vaultId, itemId)
} catch {
// Handle/notify user of errors
}
var client: PasswordManagerClient!
var vault: Vault!
var login: VaultLogin!
client.removeVaultItem(id: login.id, from: vault) { (result) in
switch result {
case .success:
break
case .failure(let error):
break
}
}
// val client: SudoPasswordManagerClient
launch {
try {
withContext(Dispatchers.IO) {
val vault = client.getVault("1")
vault.removeVaultItem("2", vault)
}
} catch (e: SudoPasswordManagerException) {
// Handle any errors
}
}