Wallets

Manage Digital Wallet with Wallets Service.

Install Dependency

Package: affinidi_tdk_wallets_client


dart pub add affinidi_tdk_wallets_client

Check the latest version on pub.dev or view the source on GitHub.

Classes and Methods

Wallet API

Used to manage digital wallets for issuing credentials.

createWallet

Create a wallet by type.

Parameters

createWalletInput CreateWalletInput Required
Details for the wallet to create.

Example

import 'package:affinidi_tdk_auth_provider/affinidi_tdk_auth_provider.dart';
import 'package:affinidi_tdk_wallets_client/affinidi_tdk_wallets_client.dart';

try {
    late WalletApi walletApi;

    final dio = Dio(BaseOptions(
        baseUrl: AffinidiTdkWalletsClient.basePath,
        connectTimeout: const Duration(seconds: 5),
        receiveTimeout: const Duration(seconds: 5),
      ));
    final apiClient = AffinidiTdkWalletsClient(
        dio: dio, authTokenHook: authProvider.fetchProjectScopedToken);
    walletApi = apiClient.getWalletApi();

    final name = "Wallet Name";
    final description = "Description";
    
    final didKeyInputBuilder = DidKeyInputParamsBuilder()
      ..name = name
      ..description = description;

    final walletInputBuilder = CreateWalletInputBuilder()
      ..oneOf = OneOf2<DidKeyInputParams, DidWebInputParams>(
          value: didKeyInputBuilder.build(), typeIndex: 0);
          
    final createdWallet = (await walletApi.createWallet(
            createWalletInput: walletInputBuilder.build()))
        .data;

    print(createdWallet);
  } catch (e) {
    print('Exception: $e');
  }

deleteWallet

Delete a wallet by ID.

Parameters

walletId String Required
ID of the wallet to delete.

Example

import 'package:affinidi_tdk_auth_provider/affinidi_tdk_auth_provider.dart';
import 'package:affinidi_tdk_wallets_client/affinidi_tdk_wallets_client.dart';

try {
    late WalletApi walletApi;

    final dio = Dio(BaseOptions(
        baseUrl: AffinidiTdkWalletsClient.basePath,
        connectTimeout: const Duration(seconds: 5),
        receiveTimeout: const Duration(seconds: 5),
      ));
    final apiClient = AffinidiTdkWalletsClient(
        dio: dio, authTokenHook: authProvider.fetchProjectScopedToken);
    walletApi = apiClient.getWalletApi();

    final walletId = "<WALLET_ID-to-delete>";
    
    final result = (await walletApi.deleteWallet(
            walletId: walletId))
        .data;

    print(result);
  } catch (e) {
    print('Exception: $e');
  }

getWallet

Retrieves the details of the wallet.

Parameters

walletId String Required
ID of the wallet to retrieve.

Example

import 'package:affinidi_tdk_auth_provider/affinidi_tdk_auth_provider.dart';
import 'package:affinidi_tdk_wallets_client/affinidi_tdk_wallets_client.dart';

try {
    late WalletApi walletApi;

    final dio = Dio(BaseOptions(
        baseUrl: AffinidiTdkWalletsClient.basePath,
        connectTimeout: const Duration(seconds: 5),
        receiveTimeout: const Duration(seconds: 5),
      ));
      
    final apiClient = AffinidiTdkWalletsClient(
        dio: dio, authTokenHook: authProvider.fetchProjectScopedToken);
    walletApi = apiClient.getWalletApi();

    final walletId = "<WALLET_ID>";

    final walletDetails = (await walletApi.getWallet(
            walletId: walletId))
        .data;

    print(walletDetails);
  } catch (e) {
    print('Exception: $e');
  }

listWallets

Get the list of wallets.

No parameters required.

Example

import 'package:affinidi_tdk_auth_provider/affinidi_tdk_auth_provider.dart';
import 'package:affinidi_tdk_wallets_client/affinidi_tdk_wallets_client.dart';

try {
    late WalletApi walletApi;

    final dio = Dio(BaseOptions(
        baseUrl: AffinidiTdkWalletsClient.basePath,
        connectTimeout: const Duration(seconds: 5),
        receiveTimeout: const Duration(seconds: 5),
      ));

    final apiClient = AffinidiTdkWalletsClient(
        dio: dio, authTokenHook: authProvider.fetchProjectScopedToken);
    walletApi = apiClient.getWalletApi();

    final walletsList = (await walletApi.listWallets()).data;

    print(walletsList);
  } catch (e) {
    print('Exception: $e');
  }

signCredential

Sign a credential with the wallet details (DID document).

Parameters

walletId String Required
ID of the wallet used for signing the credential.
signCredentialInputDto SignCredentialInputDto Required
Credential data to sign.

Example

import 'package:affinidi_tdk_auth_provider/affinidi_tdk_auth_provider.dart';
import 'package:affinidi_tdk_wallets_client/affinidi_tdk_wallets_client.dart';

try {
    late WalletApi walletApi;

    final dio = Dio(BaseOptions(
        baseUrl: AffinidiTdkWalletsClient.basePath,
        connectTimeout: const Duration(seconds: 5),
        receiveTimeout: const Duration(seconds: 5),
      ));
    final apiClient = AffinidiTdkWalletsClient(
        dio: dio, authTokenHook: authProvider.fetchProjectScopedToken);
    walletApi = apiClient.getWalletApi();

    final jsonLdContextUrl = "";
    final jsonSchemaUrl = "";
    final typeName =  "";
    final credentialSubject = "",
    final holderDid= "";
    final expiresAt ="";

    final params = SignCredentialInputDtoUnsignedCredentialParamsBuilder()
        ..jsonLdContextUrl = jsonLdContextUrl
        ..jsonSchemaUrl = jsonSchemaUrl
        ..typeName = typeName
        ..credentialSubject = credentialSubject,
        ..holderDid = holderDid
        ..expiresAt = expiresAt;

    final revocable =  true;
    final credentialFormat = SignCredentialInputDtoCredentialFormatEnum.ldpVc;
    final unsignedCredentialParams = params;

    final walletId = "<WALLET_ID>";
    
    final signCredBuilder = SignCredentialInputDtoBuilder()
      ..revocable = revocable
      ..credentialFormat = credentialFormat
      ..unsignedCredentialParams = unsignedCredentialParams;

    final signCred = (await walletApi.signCredential(
            walletId: walletId,
            signCredentialInputDto: signCredBuilder.build(),))
        .data;

    print(signCred);
  } catch (e) {
    print('Exception: $e');
  }

signJwtToken

Sign the JSON Web Token with the wallet details (DID document).

Parameters

walletId String Required
ID of the wallet used for signing the JWT.
signJwtToken SignJwtToken Required
JWT data to sign.

Example

import 'package:affinidi_tdk_auth_provider/affinidi_tdk_auth_provider.dart';
import 'package:affinidi_tdk_wallets_client/affinidi_tdk_wallets_client.dart';
import 'dart:convert';
import 'package:built_value/json_object.dart';

try {
    late WalletApi walletApi;

    final dio = Dio(BaseOptions(
        baseUrl: AffinidiTdkWalletsClient.basePath,
        connectTimeout: const Duration(seconds: 5),
        receiveTimeout: const Duration(seconds: 5),
      ));
    final apiClient = AffinidiTdkWalletsClient(
        dio: dio, authTokenHook: authProvider.fetchProjectScopedToken);
    walletApi = apiClient.getWalletApi();

    final header = {
      "alg": "",
      "typ": ""
    };

    final payload = {
      "sub": "",
      "name": "",
      "iat": DateTime.now().millisecondsSinceEpoch ~/ 1000,
      "exp": (DateTime.now().add(Duration(hours: 1))).millisecondsSinceEpoch ~/ 1000 
    };

    final jsonHeader = JsonObject(header);
    final jsonPayload = JsonObject(payload);

    final walletId = env['<WALLET_ID>']!;
    
    final signTokenBuilder = SignJwtTokenBuilder()
      ..header = jsonHeader
      ..payload = jsonPayload;

    final signToken = (await walletApi.signJwtToken(
            walletId: walletId,
            signJwtToken: signTokenBuilder.build(),))
        .data;

    print(signToken);
  } catch (e) {
    print('Exception: $e');
  }

updateWallet

Update an existing wallet by ID.

Parameters

walletId String Required
ID of the wallet to update.
updateWalletInput UpdateWalletInput Required
Details for the wallet to update.

Example

import 'package:affinidi_tdk_auth_provider/affinidi_tdk_auth_provider.dart';
import 'package:affinidi_tdk_wallets_client/affinidi_tdk_wallets_client.dart';

try {
    late WalletApi walletApi;

    final dio = Dio(BaseOptions(
        baseUrl: AffinidiTdkWalletsClient.basePath,
        connectTimeout: const Duration(seconds: 5),
        receiveTimeout: const Duration(seconds: 5),
      ));
    final apiClient = AffinidiTdkWalletsClient(
        dio: dio, authTokenHook: authProvider.fetchProjectScopedToken);
    walletApi = apiClient.getWalletApi();

    final name = "";
    final description = "";
    final walletId = "<WALLET_ID>";
    
    final walletInputBuilder = UpdateWalletInputBuilder()
      ..name = name
      ..description = description;

    final updatedWallet = (await walletApi.updateWallet(
            walletId: walletId,
            updateWalletInput: walletInputBuilder.build(),))
        .data;

    print(updatedWallet);
  } catch (e) {
    print('Exception: $e');
  }

createWalletKey

Add a new cryptographic key to a wallet.

Note: Multiple keys are only supported for did:web wallets.

Parameters

walletId String Required
ID of the wallet to add the key to.
createWalletKeyInput CreateWalletKeyInput Required
Key type and verification relationships.

Example

import 'package:affinidi_tdk_auth_provider/affinidi_tdk_auth_provider.dart';
import 'package:affinidi_tdk_wallets_client/affinidi_tdk_wallets_client.dart';

try {
    late WalletApi walletApi;

    final dio = Dio(BaseOptions(
        baseUrl: AffinidiTdkWalletsClient.basePath,
        connectTimeout: const Duration(seconds: 5),
        receiveTimeout: const Duration(seconds: 5),
      ));
    final apiClient = AffinidiTdkWalletsClient(
        dio: dio, authTokenHook: authProvider.fetchProjectScopedToken);
    walletApi = apiClient.getWalletApi();

    final walletId = "<WALLET_ID>";

    final createWalletKeyInputBuilder = CreateWalletKeyInputBuilder()
      ..keyType = CreateWalletKeyInputKeyTypeEnum.ed25519
      ..relationships.replace([
          VerificationRelationship.authentication,
          VerificationRelationship.assertionMethod,
        ]);

    final result = (await walletApi.createWalletKey(
            walletId: walletId,
            createWalletKeyInput: createWalletKeyInputBuilder.build()))
        .data;

    print(result);
  } catch (e) {
    print('Exception: $e');
  }

listWalletKeys

List all cryptographic keys in a wallet.

Note: Multiple keys are only supported for did:web wallets.

Parameters

walletId String Required
ID of the wallet to list keys for.

Example

import 'package:affinidi_tdk_auth_provider/affinidi_tdk_auth_provider.dart';
import 'package:affinidi_tdk_wallets_client/affinidi_tdk_wallets_client.dart';

try {
    late WalletApi walletApi;

    final dio = Dio(BaseOptions(
        baseUrl: AffinidiTdkWalletsClient.basePath,
        connectTimeout: const Duration(seconds: 5),
        receiveTimeout: const Duration(seconds: 5),
      ));
    final apiClient = AffinidiTdkWalletsClient(
        dio: dio, authTokenHook: authProvider.fetchProjectScopedToken);
    walletApi = apiClient.getWalletApi();

    final walletId = "<WALLET_ID>";

    final result = (await walletApi.listWalletKeys(
            walletId: walletId))
        .data;

    print(result);
  } catch (e) {
    print('Exception: $e');
  }

removeWalletKey

Remove a cryptographic key from a wallet.

Note: Multiple keys are only supported for did:web wallets.

Parameters

walletId String Required
ID of the wallet to remove the key from.
keyId String Required
ID of the key to remove.

Example

import 'package:affinidi_tdk_auth_provider/affinidi_tdk_auth_provider.dart';
import 'package:affinidi_tdk_wallets_client/affinidi_tdk_wallets_client.dart';

try {
    late WalletApi walletApi;

    final dio = Dio(BaseOptions(
        baseUrl: AffinidiTdkWalletsClient.basePath,
        connectTimeout: const Duration(seconds: 5),
        receiveTimeout: const Duration(seconds: 5),
      ));
    final apiClient = AffinidiTdkWalletsClient(
        dio: dio, authTokenHook: authProvider.fetchProjectScopedToken);
    walletApi = apiClient.getWalletApi();

    final walletId = "<WALLET_ID>";
    final keyId = "<KEY_ID>";

    final result = (await walletApi.removeWalletKey(
            walletId: walletId,
            keyId: keyId))
        .data;

    print(result);
  } catch (e) {
    print('Exception: $e');
  }

updateWalletKey

Update the verification relationships of a cryptographic key in a wallet.

Note: Multiple keys are only supported for did:web wallets.

Parameters

walletId String Required
ID of the wallet containing the key.
keyId String Required
Wallet-scoped key identifier to update.
updateWalletKeyInput UpdateWalletKeyInput Required
Updated verification relationships.

Example

import 'package:affinidi_tdk_auth_provider/affinidi_tdk_auth_provider.dart';
import 'package:affinidi_tdk_wallets_client/affinidi_tdk_wallets_client.dart';

try {
    late WalletApi walletApi;

    final dio = Dio(BaseOptions(
        baseUrl: AffinidiTdkWalletsClient.basePath,
        connectTimeout: const Duration(seconds: 5),
        receiveTimeout: const Duration(seconds: 5),
      ));
    final apiClient = AffinidiTdkWalletsClient(
        dio: dio, authTokenHook: authProvider.fetchProjectScopedToken);
    walletApi = apiClient.getWalletApi();

    final walletId = "<WALLET_ID>";
    final keyId = "<KEY_ID>";

    final updateWalletKeyInputBuilder = UpdateWalletKeyInputBuilder()
      ..relationships.replace([
          VerificationRelationship.authentication,
          VerificationRelationship.assertionMethod,
        ]);

    final result = (await walletApi.updateWalletKey(
            walletId: walletId,
            keyId: keyId,
            updateWalletKeyInput: updateWalletKeyInputBuilder.build()))
        .data;

    print(result);
  } catch (e) {
    print('Exception: $e');
  }

createServiceEndpoint

Add a service endpoint to a wallet.

Parameters

walletId String Required
ID of the wallet to add the service endpoint to.
serviceEndpointInput ServiceEndpointInput Required
Service endpoint details.

Example

import 'package:affinidi_tdk_auth_provider/affinidi_tdk_auth_provider.dart';
import 'package:affinidi_tdk_wallets_client/affinidi_tdk_wallets_client.dart';

try {
    late WalletApi walletApi;

    final dio = Dio(BaseOptions(
        baseUrl: AffinidiTdkWalletsClient.basePath,
        connectTimeout: const Duration(seconds: 5),
        receiveTimeout: const Duration(seconds: 5),
      ));
    final apiClient = AffinidiTdkWalletsClient(
        dio: dio, authTokenHook: authProvider.fetchProjectScopedToken);
    walletApi = apiClient.getWalletApi();

    final walletId = "<WALLET_ID>";

    final serviceEndpointInputBuilder = ServiceEndpointInputBuilder()
      ..url = "https://example.com/service"
      ..serviceType = ServiceEndpointInputServiceTypeEnum.dIDCommMessaging
      ..name = "My Service"
      ..description = "Service description";

    final result = (await walletApi.createServiceEndpoint(
            walletId: walletId,
            serviceEndpointInput: serviceEndpointInputBuilder.build()))
        .data;

    print(result);
  } catch (e) {
    print('Exception: $e');
  }

listServiceEndpoints

List all service endpoints in a wallet.

Parameters

walletId String Required
ID of the wallet to list service endpoints for.

Example

import 'package:affinidi_tdk_auth_provider/affinidi_tdk_auth_provider.dart';
import 'package:affinidi_tdk_wallets_client/affinidi_tdk_wallets_client.dart';

try {
    late WalletApi walletApi;

    final dio = Dio(BaseOptions(
        baseUrl: AffinidiTdkWalletsClient.basePath,
        connectTimeout: const Duration(seconds: 5),
        receiveTimeout: const Duration(seconds: 5),
      ));
    final apiClient = AffinidiTdkWalletsClient(
        dio: dio, authTokenHook: authProvider.fetchProjectScopedToken);
    walletApi = apiClient.getWalletApi();

    final walletId = "<WALLET_ID>";

    final result = (await walletApi.listServiceEndpoints(
            walletId: walletId))
        .data;

    print(result);
  } catch (e) {
    print('Exception: $e');
  }

removeServiceEndpoint

Remove a service endpoint from a wallet.

Parameters

walletId String Required
ID of the wallet to remove the service endpoint from.
serviceId String Required
ID of the service endpoint to remove.

Example

import 'package:affinidi_tdk_auth_provider/affinidi_tdk_auth_provider.dart';
import 'package:affinidi_tdk_wallets_client/affinidi_tdk_wallets_client.dart';

try {
    late WalletApi walletApi;

    final dio = Dio(BaseOptions(
        baseUrl: AffinidiTdkWalletsClient.basePath,
        connectTimeout: const Duration(seconds: 5),
        receiveTimeout: const Duration(seconds: 5),
      ));
    final apiClient = AffinidiTdkWalletsClient(
        dio: dio, authTokenHook: authProvider.fetchProjectScopedToken);
    walletApi = apiClient.getWalletApi();

    final walletId = "<WALLET_ID>";
    final serviceId = "<SERVICE_ID>";

    final result = (await walletApi.removeServiceEndpoint(
            walletId: walletId,
            serviceId: serviceId))
        .data;

    print(result);
  } catch (e) {
    print('Exception: $e');
  }

updateServiceEndpoint

Update an existing service endpoint in a wallet.

Parameters

walletId String Required
ID of the wallet containing the service endpoint.
serviceId String Required
ID of the service endpoint to update.
updateServiceEndpointInput UpdateServiceEndpointInput Required
Updated service endpoint details.

Example

import 'package:affinidi_tdk_auth_provider/affinidi_tdk_auth_provider.dart';
import 'package:affinidi_tdk_wallets_client/affinidi_tdk_wallets_client.dart';

try {
    late WalletApi walletApi;

    final dio = Dio(BaseOptions(
        baseUrl: AffinidiTdkWalletsClient.basePath,
        connectTimeout: const Duration(seconds: 5),
        receiveTimeout: const Duration(seconds: 5),
      ));
    final apiClient = AffinidiTdkWalletsClient(
        dio: dio, authTokenHook: authProvider.fetchProjectScopedToken);
    walletApi = apiClient.getWalletApi();

    final walletId = "<WALLET_ID>";
    final serviceId = "<SERVICE_ID>";

    final updateServiceEndpointInputBuilder = UpdateServiceEndpointInputBuilder()
      ..url = "https://example.com/service/updated"
      ..name = "Updated Service"
      ..description = "Updated description";

    final result = (await walletApi.updateServiceEndpoint(
            walletId: walletId,
            serviceId: serviceId,
            updateServiceEndpointInput: updateServiceEndpointInputBuilder.build()))
        .data;

    print(result);
  } catch (e) {
    print('Exception: $e');
  }