# Managing Password Vaults

A `Vault` is a reference to vault data held internally by the Password Manager. To access the contents of a vault, the vault is passed to the Password Manager.

## Creating a Vault

To effectively manage a user's contents, a vault needs to be created. All vaults that will be created must have an association with a Sudo. A Sudo can be created and retrieved using the [Sudo Profiles SDK](/guides/sudos.md). After either creating or retrieving a Sudo, the Sudo's `id` will be passed to the `createVault` method to asynchronously create a vault. If the Password Manager is successful a vault will be returned.

{% tabs %}
{% tab title="TypeScript" %}

```typescript
try {
    const sudoId = ""
    const vaultId = await client.createVault(sudoId)
    // `vaultId` contains the identifier of the newly created vault object.
} catch (error) {
    // handle errors or throw the error
    throw error
}
```

{% endtab %}

{% tab title="Swift" %}

```swift
var client: PasswordManagerClient!

client.createVault(sudoId: "") { (result) in
    switch result {
    case .success(let vault):
        break
    case .failure(let error):
        break
    }
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
// val client: SudoPasswordManagerClient
// val sudoId: String

launch {
    try {
        val vault = withContext(Dispatchers.IO) {
            client.createVault(sudoId)
        }
    } catch (e: SudoPasswordManagerException) {
        // Handle/notify user of exception
    }
}
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
When creating vaults under a Sudo, be aware of [Password Entitlement limits](/guides/password-manager/password-entitlements.md).
{% endhint %}

## Retrieving Vaults

Use the `listVaults` method to retrieve a list of all the vaults owned by the user. Use the list to filter for vaults owned by a Sudo or access the contents of the vault by using the `id` of one of the vaults returned from the method.

{% tabs %}
{% tab title="TypeScript" %}

```typescript
try {
    const vaults = await client.listVaults()
    // each vault in the array of vaults has an `id`
    // which can be used to access its items.
} catch {
    // Handle/notify user of errors
}
```

{% endtab %}

{% tab title=" Swift" %}

```swift
var client: PasswordManagerClient!

client.listVaults { (result) in
    switch result {
    case .success(let vaults):
        break
    case .failure(let error):
        break
    }
}

client.getVault(withId: "1") { (result) in
    switch result {
    case .success(let vault):
        break
    case .failure(let error):
        break
    }
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
// val client: SudoPasswordManagerClient

launch {
    try {
        val vaults = withContext(Dispatchers.IO) {
            client.listVaults()
            client.getVault("1")
        }
    } catch (e: SudoPasswordManagerException) {
        // Handle any errors related to fetching vaults
    }
}
```

{% endtab %}
{% endtabs %}

## Deleting a Vault

To delete a vault, call the `deleteVault` method and pass in the `id` of the vault you wish to delete.

{% tabs %}
{% tab title="TypeScript" %}

```javascript
try {
    const vaultId = "1"
    await client.deleteVault(vaultId)
} catch {
    // Handle/notify user of errors 
}
```

{% endtab %}

{% tab title="Swift" %}

```swift
var client: PasswordManagerClient!

client.deleteVault(withId: "1") { (result) in
    switch result {
    case .success:
        break
    case .failure(let error):
        break
    }
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
// val client: SudoPasswordManagerClient

launch {
    try {
        withContext(Dispatchers.IO) {
            client.deleteVault("1")
        }
    } catch (e: SudoPasswordManagerException) {
        // Handle any errors related to vault deletion
    }
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
To learn more about key concepts surrounding Sudos, see [Sudo digital identities](/concepts/sudo-digital-identities.md).
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sudoplatform.com/guides/password-manager/managing-password-vaults.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
