Vault

Libraries to implement digital identity wallet into your Flutter/Dart applications.

Affinidi TDK - Vault for Dart provides the libraries and tools to implement digital identity wallet into your Flutter/Dart application for creating Decentralised Identity solution to securely manage Decentralised Identifiers (DIDs), Verifiable Credentials, and other data that represents the user’s identity based on different context, for example, you can create an identity for shopping, personal finance, and work.

Create and Initialise Vault

Initialise vault with wallet, storage, and profile interface. To create a wallet, you must generate a Seed to create the key pairs. The profile is created using a cloud or local storage option supported by the vault.

Refer to the published SSI Dart package to know more about different types of wallet supported.

Import

import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';
import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';

Example

// Initialise InMemory storage
final accountIndex = 32;
final vaultStore = InMemoryVaultStore();
await vaultStore.writeAccountIndex(accountIndex);

// Generate seed from the storage layer
final seed = vaultStore.getRandomSeed();
  await vaultStore.setSeed(seed);

// Initialise profile interface
const vfsRepositoryId = 'vfs';
final profileRepositories = <String, ProfileRepository>{
vfsRepositoryId: VfsProfileRepository(vfsRepositoryId),
};

// In this example, we are using Bip32 type wallet from SSI package
final vault = await Vault.fromVaultStore(
    vaultStore,
    profileRepositories: profileRepositories,
    defaultProfileRepositoryId: vfsRepositoryId,
  );

// Ensure vault is initialised before being able to access any of the repositories
await vault.ensureInitialized();

Manage Vault Profiles

Create and manage profiles associated with the vault.

Create Vault Profile

Create a profile to store credentials and documents. A profile represents a user’s identity.

Currently, vault only supports cloud profile from Affinidi Vault.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

// Create Profile
try {
    final profileRepository = vault.defaultProfileRepository;
    // alternatively can be accessed via profile repository identifier
    // final ProfileRepository profileRepository = vault.profileRepositories[vfsRepositoryId];
    await profileRepository.createProfile(name: 'Work Profile');
} on TdkException catch (error) {
    print([error.code, error.message, error.originalMessage].join('\n'));
}  catch (e) {
    print('Error: $e');
}

List Vault Profiles

Retrieve list of profiles associated with the vault.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

// Retrieve list of profiles from the vault
var profiles = await vault.listProfiles();

// Check if we have list of profiles
if (!profiles.isEmpty) {

    profiles.forEach((profile) {
      print('${profile.id} : ${profile.name}');
    });

} else {
    print('Vault profiles is empty.');
}

Update Vault Profile

Update a profile associated with the vault.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

// Get the list of available profiles from the vault
var profiles = await vault.listProfiles();
// For demonstration purposes, we always get the last profile from the list
var profile = profiles.lastOrNull;

if (profile != null) {
    // Update profile name
    profile.name = 'Test Profile 123';
    // Update profile
    await profileRepository.updateProfile(profile);
} else {
    print('Profile not found.');
}

Delete Vault Profile

Delete a profile associated with the vault.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

// Get the list of available profiles from the vault
var profiles = await vault.listProfiles();
// For demonstration purposes, we always get the last profile from the list
var profile = profiles.lastOrNull;

if (profile != null) {
    // Delete profile
    await profileRepository.deleteProfile(profile);
} else {
    print('Profile not found.');
}

Share Vault Profile

Share an entire profile with another user to grant access to all data within the profile.

Profile and item sharing requires the profile repository to implement the ProfileAccessSharing interface. The VfsProfileRepository from affinidi_tdk_vault_data_manager supports both profile and item-level sharing.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

// Owner shares their profile with a grantee
final granteeDid = 'did:key:recipient-did';
final sharedProfile = await vault.shareProfile(
    profileId: 'my-profile-id',
    toDid: granteeDid,
    permissions: Permissions.read  // or Permissions.write, Permissions.all
);

// Owner sends SharedProfileDto to grantee (via your application's communication channel)

Accept Shared Profile

Accept a shared profile that was granted by another user (grantee side).

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

try {
    // Grantee accepts the shared profile received from owner
    await vault.addSharedProfile(
        profileId: 'grantee-profile-id',
        sharedProfile: sharedProfile  // SharedProfileDto received from owner
    );
    
    print('Successfully accepted shared profile');
} on TdkException catch (error) {
    print([error.code, error.message, error.originalMessage].join('\n'));
} catch (e) {
    print('Error: $e');
}

Share Individual Items

Share specific files or folders (items) with another user instead of sharing the entire profile.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

try {
    final granteeDid = 'did:key:recipient-did';
    
    // 1. Get current permissions policy
    final policy = await vault.getItemPermissionsPolicy(
        profileId: 'my-profile-id',
        granteeDid: granteeDid
    );
    
    // 2. Add permission locally
    policy.addPermission(
        ['file-123'],  // List of item IDs (files or folders)
        [Permissions.read, Permissions.write]
    );
    
    // 3. Set the complete policy on the backend
    final kek = await vault.setItemAccess(
        profileId: 'my-profile-id',
        granteeDid: granteeDid,
        policy: policy
    );
    
    // 4. Create SharedItemsDto to send to grantee
    final sharedItem = SharedItemsDto(
        kek: kek,
        ownerProfileId: 'my-profile-id',
        ownerProfileDID: 'did:key:owner-did',
        itemIds: ['file-123']
    );
    
    // Owner sends SharedItemsDto to grantee (via your application's communication channel)
    
} on TdkException catch (error) {
    print([error.code, error.message, error.originalMessage].join('\n'));
} catch (e) {
    print('Error: $e');
}

Accept Shared Items

Accept shared items (files/folders) that were granted by another user (grantee side).

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

try {
    // Grantee accepts the shared items received from owner
    await vault.acceptSharedItems(
        profileId: 'grantee-profile-id',
        sharedItems: sharedItem  // SharedItemsDto received from owner
    );
    
    print('Successfully accepted shared items');
} on TdkException catch (error) {
    print([error.code, error.message, error.originalMessage].join('\n'));
} catch (e) {
    print('Error: $e');
}

Share Items with Time-Bound Access

Share items with automatic expiration by specifying an expiration date/time.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

try {
    final granteeDid = 'did:key:recipient-did';
    
    // Get current permissions policy
    final policy = await vault.getItemPermissionsPolicy(
        profileId: 'my-profile-id',
        granteeDid: granteeDid
    );
    
    // Add permission with expiration date
    policy.addPermission(
        ['file-123'],
        [Permissions.read],
        expiresAt: DateTime.now().add(Duration(hours: 1))  // Access valid for 1 hour
    );
    
    // Set the policy
    final kek = await vault.setItemAccess(
        profileId: 'my-profile-id',
        granteeDid: granteeDid,
        policy: policy
    );
    
    print('Time-bound access granted. Expires in 1 hour.');
    
    // After the expiresAt DateTime passes, access is automatically revoked by the backend
    // The grantee will no longer be able to access the shared item
    
} on TdkException catch (error) {
    print([error.code, error.message, error.originalMessage].join('\n'));
} catch (e) {
    print('Error: $e');
}

Get Item Access Permissions

Retrieve the current access permissions for shared items.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

try {
    final granteeDid = 'did:key:recipient-did';
    
    // Get current item access permissions
    final permissions = await vault.getItemAccess(
        profileId: 'my-profile-id',
        granteeDid: granteeDid
    );
    
    permissions.forEach((permission) {
        print('Item: ${permission.itemId}');
        print('Permissions: ${permission.permissions}');
        if (permission.expiresAt != null) {
            print('Expires at: ${permission.expiresAt}');
        }
    });
    
} on TdkException catch (error) {
    print([error.code, error.message, error.originalMessage].join('\n'));
} catch (e) {
    print('Error: $e');
}

Read Shared Item Content

Read the content of a shared item (file/folder) that another user has shared with you.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

try {
    // Read content from a shared item
    final content = await vault.readSharedItem(
        ownerProfileId: 'owner-profile-id',
        itemId: 'file-123'
    );
    
    print('Shared item content: $content');
    
} on TdkException catch (error) {
    print([error.code, error.message, error.originalMessage].join('\n'));
} catch (e) {
    print('Error: $e');
}

Revoke Profile Access

Revoke access to a profile for a specific user.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

try {
    final granteeDid = 'did:key:recipient-did';
    
    // Revoke profile access from grantee
    await vault.revokeProfileAccess(
        profileId: 'my-profile-id',
        granteeDid: granteeDid
    );
    
    print('Profile access revoked successfully');
    
} on TdkException catch (error) {
    print([error.code, error.message, error.originalMessage].join('\n'));
} catch (e) {
    print('Error: $e');
}

Revoke Item Access

Revoke access to specific items (files/folders) for a user.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

try {
    final granteeDid = 'did:key:recipient-did';
    
    // Get current permissions policy
    final policy = await vault.getItemPermissionsPolicy(
        profileId: 'my-profile-id',
        granteeDid: granteeDid
    );
    
    // Remove permission locally
    policy.removePermission(
        ['file-123'],
        []  // Empty list removes all permissions for the specified items
    );
    
    // Set the updated policy to revoke access
    await vault.setItemAccess(
        profileId: 'my-profile-id',
        granteeDid: granteeDid,
        policy: policy
    );
    
    print('Item access revoked successfully');
    
} on TdkException catch (error) {
    print([error.code, error.message, error.originalMessage].join('\n'));
} catch (e) {
    print('Error: $e');
}

Manage Vault Files

Create folders and upload files to manage documents associated with the vault.

Create Folder

Create a folder in the vault’s profile.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

// Get the list of available profiles from the vault
var profiles = await vault.listProfiles();
// For demonstration purposes, we always get the last profile from the list
var profile = profiles.lastOrNull;

if (profile != null) {
    // We'll create a folder under a profile (root folder)
    final rootFolderId = profile.id;

    await profile.defaultFileStorage!.createFolder(
        folderName: '<Folder_Name>',
        parentFolderId: rootFolderId,
    );

} else {
    print('Profile not found.');
}

Get Folder

Get the folder in the vault’s profile.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

// Get the list of available profiles from the vault
var profiles = await vault.listProfiles();
// For demonstration purposes, we always get the last profile from the list
var profile = profiles.lastOrNull;

if (profile != null) {
    // We'll retrieve the folders under a profile (root folder)
    final rootFolderId = profile.id;
    // List folders
    final files = await profile.defaultFileStorage?.getFolder(folderId: rootFolderId);

    files?.forEach((file) {
        print('${file.id} : ${file.name}');
    });

} else {
    print('Profile not found.');
}

Rename Folder

Rename a folder in the vault’s profile.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

// Get the list of available profiles from the vault
var profiles = await vault.listProfiles();
// For demonstration purposes, we always get the last profile from the list
var profile = profiles.lastOrNull;

if (profile != null) {
    // Rename the file object
    await profile.defaultFileStorage!.renameFolder(
          folderId: '<File_ID>',
          newName: '<File_Name>'
      );

} else {
    print('Profile not found.');
}

Delete Folder

Delete a folder in the vault’s profile.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

// Get the list of available profiles from the vault
var profiles = await vault.listProfiles();
// For demonstration purposes, we always get the last profile from the list
var profile = profiles.lastOrNull;

if (profile != null) {
    try {
        // We'll retrieve the folders under a profile (root folder)
        final rootFolderId = profile.id;
        // List folders
        await profile.defaultFileStorage?.deleteFolder(folderId: '<Folder_ID>');
    } on TdkException catch (error) {
        print([error.code, error.message, error.originalMessage].join('\n'));
    }  catch (e) {
        print('Error: $e');
    }

} else {
    print('Profile not found.');
}

Create File

Create a file in a folder in the vault’s profile.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

// Get the list of available profiles from the vault
var profiles = await vault.listProfiles();
// For demonstration purposes, we always get the last profile from the list
var profile = profiles.lastOrNull;

if (profile != null) {
    // We'll retrieve the folders under a profile (root folder)
    final rootFolderId = profile.id;
    // Create a dummy file
    final fileContent = Uint8List.fromList([1, 2, 3]);

    try {
        // create a file, we'll create a file in the root folder, instead of subfolder.
        await profile.defaultFileStorage!.createFile(
            fileName: 'Doc Test File 1',
            data: fileContent,
            parentFolderId: rootFolderId,
        );
    } on TdkException catch (error) {
        print([error.code, error.message, error.originalMessage].join('\n'));
    }  catch (e) {
        print('Error: $e');
    }

} else {
    print('Profile not found.');
}

Get File

Get the file in the vault’s profile.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

// Get the list of available profiles from the vault
var profiles = await vault.listProfiles();
// For demonstration purposes, we always get the last profile from the list
var profile = profiles.lastOrNull;

if (profile != null) {
    // Retrieve the file object
    final file = await profile.defaultFileStorage!.getFile(
            fileId: '<File_ID>'
        );

    print(file.name);

} else {
    print('Profile not found.');
}

Get File Content

Get the content of the file in the vault’s profile.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

// Get the list of available profiles from the vault
var profiles = await vault.listProfiles();
// For demonstration purposes, we always get the last profile from the list
var profile = profiles.lastOrNull;

if (profile != null) {
    // Retrieve the file content
    final fileData = await profile.defaultFileStorage!.getFileContent(
            fileId: '<File_ID>'
        );

    print(fileData);

} else {
    print('Profile not found.');
}

Rename File

Rename a file in the vault’s profile.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

// Get the list of available profiles from the vault
var profiles = await vault.listProfiles();
// For demonstration purposes, we always get the last profile from the list
var profile = profiles.lastOrNull;

if (profile != null) {
    // Rename the file object
    await profile.defaultFileStorage!.renameFile(
          fileId: '<File_ID>',
          newName: '<File_Name>'
      );

} else {
    print('Profile not found.');
}

Delete File

Delete a file from the vault’s profile.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

// Get the list of available profiles from the vault
var profiles = await vault.listProfiles();
// For demonstration purposes, we always get the last profile from the list
var profile = profiles.lastOrNull;

if (profile != null) {

    try {
        // Rename the file object
        await profile.defaultFileStorage!.deleteFile(
            fileId: '<File_ID>'
        );
    } on TdkException catch (error) {
        print([error.code, error.message, error.originalMessage].join('\n'));
    }  catch (e) {
        print('Error: $e');
    }

} else {
    print('Profile not found.');
}

Manage Vault Credentials

Manage credentials claimed from credential issuers into the vault.

Claim Credential

Claim the credential from the issuer.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_claim_verifiable_credential/oid4vci_claim_verifiable_credential.dart';
import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

try {
    final keyDerivationPath = "m/44'/60'/0'/0/0";
    final keyPair = await wallet.deriveKey(derivationPath: keyDerivationPath);

    final didDocument = DidKey.generateDocument(keyPair.publicKey);
    final signer = DidSigner(
        didDocument: didDocument,
        didKeyId: didDocument.verificationMethod.first.id,
        keyPair: keyPair,
        signatureScheme: SignatureScheme.ecdsa_secp256k1_sha256,
    );

    // Create a new instance of ClaimVerifiableCredentialService
    final claimVerifiableCredentialService =
        OID4VCIClaimVerifiableCredentialService(
        didSigner: signer,
    );

    final uri = Uri.parse(
        'https://example.com/callback?credential_offer_uri=https://issuer.example.com/offer/123',
    );

    final context = await claimVerifiableCredentialService.loadCredentialOffer(uri);

    VerifiableCredential? credential;
    String? txCode = '<TX_CODE_FROM_ISSER>';

    // Check if the credential offer is issued with Transaction Code
    if (context.credentialOffer.isTxCodeRequired) {
        // Claim credential with Transaction Code
        // Transaction Code is generated and must be provided by the issuer
        credential = await claimVerifiableCredentialService.claimCredential(
                claimContext: context,
                txCode: txCode,
            );
    } else {
        // Claim credential without Transaction Code
        credential = await claimVerifiableCredentialService.claimCredential(
                claimContext: context,
            );
    }

    print('Credential: $credential');

}  on TdkException catch (error) {
    print([error.code, error.message, error.originalMessage].join('\n'));
}  catch (e) {
    print('Error: $e');
}

Save Credential

Store a claimed credential into the vault’s profile.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_claim_verifiable_credential/oid4vci_claim_verifiable_credential.dart';
import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

try {
    final keyDerivationPath = "m/44'/60'/0'/0/0";
    final keyPair = await wallet.deriveKey(derivationPath: keyDerivationPath);

    final didDocument = DidKey.generateDocument(keyPair.publicKey);
    final signer = DidSigner(
        didDocument: didDocument,
        didKeyId: didDocument.verificationMethod.first.id,
        keyPair: keyPair,
        signatureScheme: SignatureScheme.ecdsa_secp256k1_sha256,
    );

    // Create a new instance of ClaimVerifiableCredentialService
    final claimVerifiableCredentialService =
        OID4VCIClaimVerifiableCredentialService(
        didSigner: signer,
    );

    final uri = Uri.parse(
        'https://example.com/callback?credential_offer_uri=https://issuer.example.com/offer/123',
    );

    final context = await claimVerifiableCredentialService.loadCredentialOffer(uri);

    VerifiableCredential? credential;
    String? txCode = '<TX_CODE_FROM_ISSER>';

    // Check if the credential offer is issued with Transaction Code
    if (context.credentialOffer.isTxCodeRequired) {
        // Claim credential with Transaction Code
        // Transaction Code is generated and must be provided by the issuer
        credential = await claimVerifiableCredentialService.claimCredential(
                claimContext: context,
                txCode: txCode,
            );
    } else {
        // Claim credential without Transaction Code
        credential = await claimVerifiableCredentialService.claimCredential(
                claimContext: context,
            );
    }
    // Did we claim successfully the credential from the issuer?
    if (credential.id != null) {
        // Get the list of available profiles from the vault
        var profiles = await vault.listProfiles();
        // For demonstration purposes, we always get the last profile from the list
        var profile = profiles.lastOrNull;
        // do we have a profile selected?
        if (profile != null) {
            // Save credential on the selected vault profile
            await profile.defaultCredentialStorage?.saveCredential(
                verifiableCredential: credential,
            );
        }
    }
}  on TdkException catch (error) {
    print([error.code, error.message, error.originalMessage].join('\n'));
}  catch (e) {
    print('Error: $e');
}

List Credentials

List credentials from the vault’s profile.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_claim_verifiable_credential/oid4vci_claim_verifiable_credential.dart';
import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

try {
    // Get the list of available profiles from the vault
    var profiles = await vault.listProfiles();
    // For demonstration purposes, we always get the last profile from the list
    var profile = profiles.lastOrNull;
    // do we have a profile selected?
    if (profile != null) {
        // List credentials from the selected vault profile
        final credentials = await profile.defaultCredentialStorage?.listCredentials();

        print('Credentials: $credentials');
    }
}  on TdkException catch (error) {
    print([error.code, error.message, error.originalMessage].join('\n'));
}  catch (e) {
    print('Error: $e');
}

Get Credential

Get a credential from the vault’s profile.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_claim_verifiable_credential/oid4vci_claim_verifiable_credential.dart';
import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

try {
    // Get the list of available profiles from the vault
    var profiles = await vault.listProfiles();
    // For demonstration purposes, we always get the last profile from the list
    var profile = profiles.lastOrNull;
    // do we have a profile selected?
    if (profile != null) {
        // Get credential from the selected vault profile
        final credential = await profile.defaultCredentialStorage?.getCredential(
                digitalCredentialId: '<Credential_ID>'
            );

        print('Credential: $credential');
    }
}  on TdkException catch (error) {
    print([error.code, error.message, error.originalMessage].join('\n'));
}  catch (e) {
    print('Error: $e');
}

Delete Credential

Delete a credential from the vault’s profile.

Import

import 'dart:typed_data';

import 'package:affinidi_tdk_claim_verifiable_credential/oid4vci_claim_verifiable_credential.dart';
import 'package:affinidi_tdk_vault_data_manager/affinidi_tdk_vault_data_manager.dart';
import 'package:affinidi_tdk_vault/affinidi_tdk_vault.dart';

Example

// Must initialize vault before being able to access any of the repositories
await vault.ensureInitialized();

try {
    // Get the list of available profiles from the vault
    var profiles = await vault.listProfiles();
    // For demonstration purposes, we always get the last profile from the list
    var profile = profiles.lastOrNull;
    // do we have a profile selected?
    if (profile != null) {
        // Delete credential from the selected vault profile
        await profile.defaultCredentialStorage?.deleteCredential(
                digitalCredentialId: '<Credential_ID>'
            );
    }
}  on TdkException catch (error) {
    print([error.code, error.message, error.originalMessage].join('\n'));
}  catch (e) {
    print('Error: $e');
}