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 = "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('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'); }

createWalletKey

Add a new cryptographic key to a Wallet.

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

Parameters

walletId [String]

ID of the Wallet to add the key to.

CreateWalletKeyInput [Object]

JSON object to provide the key type and verification relationships. 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 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('Error calling the method: $e'); }

listWalletKeys

List all cryptographic keys in a Wallet.

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

Parameters

walletId [String]

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

removeWalletKey

Remove a cryptographic key from a Wallet.

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

Parameters

walletId [String]

ID of the Wallet to remove the key from.

keyId [String]

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('Error calling the method: $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]

ID of the Wallet containing the key.

keyId [String]

Wallet-scoped key identifier to update.

UpdateWalletKeyInput [Object]

JSON object to provide the updated verification relationships. 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 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('Error calling the method: $e'); }

createServiceEndpoint

Add a service endpoint to a Wallet.

Parameters

walletId [String]

ID of the Wallet to add the service endpoint to.

ServiceEndpointInput [Object]

JSON object to provide the service endpoint details. 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 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('Error calling the method: $e'); }

listServiceEndpoints

List all service endpoints in a Wallet.

Parameters

walletId [String]

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

removeServiceEndpoint

Remove a service endpoint from a Wallet.

Parameters

walletId [String]

ID of the Wallet to remove the service endpoint from.

serviceId [String]

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

updateServiceEndpoint

Update an existing service endpoint in a Wallet.

Parameters

walletId [String]

ID of the Wallet containing the service endpoint.

serviceId [String]

ID of the service endpoint to update.

UpdateServiceEndpointInput [Object]

JSON object to provide the updated service endpoint details. 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 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('Error calling the method: $e'); }