Skip to content

affinidi/affinidi-tdk-dart

Affinidi Trust Development Kit for Dart

The Affinidi Trust Development Kit (Affinidi TDK) for Dart provides a suite of libraries and tools to implement decentralised identity solutions and to integrate with Affinidi Elements services to issue, share, and verify Verifiable Credentials (VCs) and Verifiable Presentations (VPs).

It provides various packages to implement a secure vault to manage Decentralised Identifiers (DIDs), cryptographic keys, and store Verifiable Credentials in your Flutter/Dart applications. The secure vault uses the Affinidi SSI, an open-source project for implementing Self-Sovereign Identity (SSI).

Table of Contents

Requirements

  • Dart SDK version ^3.8.0 or higher.

Installation

To install the Dart packages, run:

dart pub add <package_name>

Alternatively, manually add the package to your pubspec.yaml file:

dependencies:
  <package_name>: ^<version_number>

Then run the following command to install the package:

dart pub get

Refer to the available clients and packages for package names and relevant references.

Usage

Implement Secure Vault

Sample usage for implementing and initialising a secure vault using the affinidi_tdk_vault package:

import 'dart:typed_data';

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

void main() async {
  // 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();
}

Issue Verifiable Credentials

Sample usage for issuing Verifiable Credentials (VCs) using the affinidi_tdk_credential_issuance_client client:

import 'package:built_collection/built_collection.dart';
import 'package:dio/dio.dart';
import 'package:affinidi_tdk_auth_provider/affinidi_tdk_auth_provider.dart';
import 'package:affinidi_tdk_credential_issuance_client/affinidi_tdk_credential_issuance_client.dart';
import 'package:built_value/json_object.dart';


try {

  // NOTE: Set your variables for PAT
  final privateKey = '<PAT_PRIVATE_KEY_STRING>';
  final passphrase = '<PAT_KEY_PAIR_PASSPHRASE>';
  final tokenId = '<PAT_ID>';
  final projectId = '<PROJECT_ID>';

  final authProvider = AuthProvider(
    privateKey: privateKey,
    passphrase: passphrase,
    tokenId: tokenId,
    projectId: projectId,
  );


  late IssuanceApi issuanceApi;

  final issuanceClient = AffinidiTdkCredentialIssuanceClient(
    dio: Dio(BaseOptions(
      baseUrl: AffinidiTdkCredentialIssuanceClient.basePath,
      connectTimeout: const Duration(seconds: 10),
      receiveTimeout: const Duration(seconds: 10),
    )),
    authTokenHook: authProvider.fetchProjectScopedToken,
  );

  issuanceApi = issuanceClient.getIssuanceApi();

  final credentialTypeId = 'SchemaOne';

  final credentialData = {
    'first_name': 'FirstName',
    'last_name': 'LastName',
    'dob': '1970-01-01',
  };

  final credentialDataBuilder = MapBuilder<String, JsonObject>(
    credentialData.map((key, value) => MapEntry(key, JsonObject(value))),
  );


  final data = StartIssuanceInputDataInnerBuilder()
    ..credentialTypeId = credentialTypeId
    ..credentialData.replace(credentialDataBuilder.build());

  final startIssuanceInput = StartIssuanceInputBuilder()
    ..holderDid = 'did:key:holder-did-value'
    ..claimMode = StartIssuanceInputClaimModeEnum.FIXED_HOLDER
    ..data = ListBuilder<StartIssuanceInputDataInner>([data.build()]);

  final response = await issuanceApi.startIssuance(
    projectId: projectId,
    startIssuanceInput: startIssuanceInput.build(),
  );

  print(response);
} catch (e) {
  print('Error obtaining token: $e');
}

Available Packages and Clients

Affinidi TDK for Dart provides two types of components:

  • Packages: Self-contained, reusable utilities and helpers for implementing identity and credential management features.
  • Clients: API clients for integrating with Affinidi Elements services.

Packages

Packages provide core functionality for building decentralised identity solutions, vault and credential management.

Description Package Name Source Code Status
Project-scoped authentication provider for integrating with Affinidi Elements services. affinidi_tdk_auth_provider Source ◯
Consumer-scoped authentication provider for Affinidi services. Used together with vault implementation. affinidi_tdk_consumer_auth_provider Source ◯
Utilities for claiming and handling Verifiable Credentials. affinidi_tdk_claim_verifiable_credential Source ◯
Common utilities and shared functionality across packages. affinidi_tdk_common Source ◯
Cryptographic operations and key management. affinidi_tdk_cryptography Source ◯
Secure vault for managing DIDs, keys, and credentials. affinidi_tdk_vault Source ◯
Data management utilities for the vault. affinidi_tdk_vault_data_manager Source ◯
Flutter-specific utilities for vault integration. affinidi_tdk_vault_flutter_utils Source ◯
Testing utilities and helpers for development. affinidi_tdk_test_utilities Source ◯
Create token and generate Iota Framework credentials. affinidi_tdk_iota_core [Not published] Source ◯

Clients

Clients provide type-safe API wrappers for integrating with Affinidi Elements services, including credential issuance, verification, and sharing.

Description Package Name Source Code Status
Issue Verifiable Credentials using Affinidi Credential Issuance service. affinidi_tdk_credential_issuance_client Source ◯
Verify Verifiable Credentials and Presentations. affinidi_tdk_credential_verification_client Source ◯
Identity and Access Management (IAM) operations. affinidi_tdk_iam_client Source ◯
Iota Framework for requesting and sharing credentials. affinidi_tdk_iota_client Source ◯
Configure and manage Affinidi Login settings. affinidi_tdk_login_configuration_client Source ◯
Manage vault data and operations via API. affinidi_tdk_vault_data_manager_client Source ◯
Wallet management and DID operations. affinidi_tdk_wallets_client Source ◯

Status Legend:

Each package and client has a status indicator:

◯ - Stable and production-ready.

◯ - Under active development, API may change.

◯ - Deprecated or no longer maintained.

Documentation

For comprehensive integration guides and API references, visit our official documentation.

Support & Feedback

If you face any issues or have suggestions, please don't hesitate to contact us using this link.

Reporting Technical Issues

If you have a technical issue with the Affinidi TDK for Dart's codebase, you can create an issue directly in GitHub:

  1. Ensure the bug was not already reported by searching on GitHub under Issues.

  2. If you're unable to find an open issue addressing the problem, open a new one. Be sure to include a title and clear description, as much relevant information as possible, and a code sample or an executable test case demonstrating the expected behaviour that is not occurring.

Contributing

We welcome contributions! Please read our CONTRIBUTING guidelines to get started.

Changelog

See CHANGELOG for release notes.

Migration Note: This project was migrated from the original Affinidi TDK repository to a dedicated repository Affinidi Trust Development Kit (TDK) for Dart, as part of ongoing improvements to Affinidi’s open‑source ecosystem and development workflow.

If you need to access the previous versions of the source code, refer to the following locations:

The libraries from the previous structure have now been consolidated into the packages folder in this repository.


About

TDK for dart

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors