Wallets

Manage Digital Wallet with Wallets Service.

Install Dependency

Package: affinidi_tdk_wallets_client

dart pub add affinidi_tdk_wallets_client

You can check the latest version of this module on the pub.dev or view the source code at the GitHub repository.

Classes and Methods

Wallet API

Used to manage digital wallets for issuing credentials.

createWallet

Create a wallet by type.

Parameters

CreateWalletInput [Object]

JSON object to provide details for the wallet to create. See more here.

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 = "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('Error calling the method: $e'); }

deleteWallet

Delete a Wallet by ID.

Parameters

walletId [String]

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('Error calling the method: $e'); }

getWallet

Retrieves the details of the Wallet.

Parameters

walletId [String]

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('Error calling the method: $e'); }

listWallets

Get the list of the Wallets.

Parameters

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('Error calling the method: $e'); }

signCredential

Sign a credentials with the Wallet details (DID document).

Parameters

walletId [String]

ID of the Wallet used for signing the credential.

SignCredentialInputDto [Object]

JSON object to provide the credential data to sign. See more here.

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('Error calling the method: $e'); }

signJwtToken

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

Parameters

walletId [String]

ID of the Wallet used for signing the JWT.

SignCredentialInputDto [Object]

JSON object to provide the JWT data to sign. See more here.

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(signCred); } catch (e) { print('Error calling the method: $e'); }

updateWallet

Update an existing Wallet by ID.

Parameters

walletId [String]

ID of the Wallet to update.

UpdateWalletInput [Object]

JSON object to provide details for the wallet to update. See more here.

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('Error calling the method: $e'); }