Vault Store
The Vault Store library provides the methods to manage the keys and seed data required to initialise a digital wallet and create a vault.
Supported Storage Option
VaultStore supports the following key storage options.
InMemoryVaultStore
Stores the keys and seed data in the device’s memory.
Important Note
The sample code usesInMemoryVaultStore
as the only storage option for demonstration purposes and must not be used in production; instead, use a secure storage option like FlutterSecureVaultStore
.Import
import 'package:affinidi_tdk_vault_storages/affinidi_tdk_vault_storages.dart';
Example
// Initialise storage
final vaultStore = InMemoryVaultStore();
FlutterSecureVaultStore
Uses Flutter’s secure storage to store keys and seed data from your Flutter applications.
Import
import 'package:affinidi_tdk_vault_flutter_utils/storages/flutter_secure_vault_store.dart';
Example
// Initialise storage
final vaultStore = FlutterSecureVaultStore();
Extending Vault Store
You can extend the Vault Store interface to implement an alternative storage option for seed management.
If you wish to extend the Vault Store to implement your storage layer, you may refer to this example of the FlutterSecureVaultStore
implementation.
Manage Keys and Seed
Manage keys and seed data to initialise the digital wallet supported by the SSI Dart package.
getSeed
Retrieves the seed from the storage. Returns null
if empty.
Import
import 'package:affinidi_tdk_vault_storages/affinidi_tdk_vault_storages.dart';
Example
// Initialise InMemory storage
final vaultStore = InMemoryVaultStore();
// Retrieve the seed from the storage layer
final seed = vaultStore.getSeed();
getRandomSeed
Generates a random seed to initialise a new digital wallet instance.
Import
import 'package:affinidi_tdk_vault_storages/affinidi_tdk_vault_storages.dart';
Example
// Initialise InMemory storage
final vaultStore = InMemoryVaultStore();
// Generate seed from the storage layer
final seed = vaultStore.getRandomSeed();
setSeed
Persists the seed data in the storage for later retrieval.
Import
import 'package:affinidi_tdk_vault_storages/affinidi_tdk_vault_storages.dart';
Example
// Initialise InMemory storage
final vaultStore = InMemoryVaultStore();
// Generate seed from the storage layer
final seed = vaultStore.setSeed('<Seed_Data>');
writeAccountIndex
Persists the account index to the storage for later retrieval.
Import
import 'package:affinidi_tdk_vault_storages/affinidi_tdk_vault_storages.dart';
Example
// Initialise InMemory storage
final vaultStore = InMemoryVaultStore();
final accountIndex = 32;
// Generate seed from the storage layer
await vaultStore.writeAccountIndex(accountIndex);
readAccountIndex
Retrieves the account index. Returns 0 if no account index exists.
Import
import 'package:affinidi_tdk_vault_storages/affinidi_tdk_vault_storages.dart';
Example
// Initialise InMemory storage
final vaultStore = InMemoryVaultStore();
// Generate seed from the storage layer
final accountIndex = vaultStore.readAccountIndex();
clear
Deletes account index and seed data from the storage.
Import
import 'package:affinidi_tdk_vault_storages/affinidi_tdk_vault_storages.dart';
Example
// Initialise InMemory storage
final vaultStore = InMemoryVaultStore();
// Generate seed from the storage layer
await vaultStore.clear();
contains
This method checks if a key pair exists in the storage for the given key.
Import
import 'package:affinidi_tdk_vault_storages/affinidi_tdk_vault_storages.dart';
Example
// Initialise InMemory storage
final vaultStore = InMemoryVaultStore();
// Generate seed from the storage layer
final valueExists = vaultStore.contains('<KEY_VALUE>');
get
Retrieves the value associated with the given key. Returns null
if the key does not exist.
Import
import 'package:affinidi_tdk_vault_storages/affinidi_tdk_vault_storages.dart';
Example
// Initialise InMemory storage
final vaultStore = InMemoryVaultStore();
// Generate seed from the storage layer
final keyValue = vaultStore.get('<KEY_VALUE>');
Glad to hear it! Please tell us how we can improve more.
Sorry to hear that. Please tell us how we can improve.
Thank you for sharing your feedback so we can improve your experience.