Wallets

Manage Digital Wallet with Wallets Service.

Install Dependency

Package: @affinidi-tdk/wallets-client

npm install @affinidi-tdk/wallets-client --save

You can check the latest version of this module on the NPM repository 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 { WalletApi, Configuration, CreateWalletInput } from '@affinidi-tdk/wallets-client'
// Pass the projectScopedToken generated from AuthProvider package const authConfiguration = new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) }) const WalletApi = new WalletApi(authConfiguration) const createWalletRequest : CreateWalletInput = { name: "Wallet Name", description: "Description", didMethod: "key" } // create a did:key wallet const { data } = await WalletApi.createWallet(createWalletRequest) // create a did:web wallet - didWebUrl is mandatory const { data } = await WalletApi.createWallet({didMethod: "web", didWebUrl: "https://<DOMAIN>"})

deleteWallet

Delete a Wallet by ID.

Parameters

walletId [String]

ID of the Wallet to delete.

Example
import { WalletApi, Configuration } from '@affinidi-tdk/wallets-client'
// Pass the projectScopedToken generated from AuthProvider package const authConfiguration = new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) }) const WalletApi = new WalletApi(authConfiguration) const walletId= "<WALLET_ID-to-delete>" const result = await WalletApi.deleteWallet(walletId)

getWallet

Retrieves the details of the Wallet.

Parameters

walletId [String]

ID of the Wallet to retrieve.

Example
import { WalletApi, Configuration } from '@affinidi-tdk/wallets-client'
// Pass the projectScopedToken generated from AuthProvider package const authConfiguration = new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) }) const WalletApi = new WalletApi(authConfiguration) const walletId= "<WALLET_ID>" const result = await WalletApi.getWallet(walletId)

listWallets

Get the list of the Wallets.

Parameters

No Parameters Required

Example
import { WalletApi, Configuration } from '@affinidi-tdk/wallets-client'
// Pass the projectScopedToken generated from AuthProvider package const authConfiguration = new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) }) const WalletApi = new WalletApi(authConfiguration) const result = await WalletApi.listWallets()

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 { WalletApi, Configuration, SignCredentialInputDto } from '@affinidi-tdk/wallets-client'
// Pass the projectScopedToken generated from AuthProvider package const authConfiguration = new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) }) const WalletApi = new WalletApi(authConfiguration) const walletId= "<WALLET_ID>" const credentialRequest : SignCredentialInputDto = { unsignedCredential: {}, revocable: true, unsignedCredentialParams: { jsonLdContextUrl: "", jsonSchemaUrl: "", typeName: "", credentialSubject: "", holderDid: "", expiresAt: "" } } const result = await WalletApi.signCredential(walletId, credentialRequest)

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 { WalletApi, Configuration, SignJwtToken } from '@affinidi-tdk/wallets-client'
// Pass the projectScopedToken generated from AuthProvider package const authConfiguration = new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) }) const WalletApi = new WalletApi(authConfiguration) const walletId= "<WALLET_ID>" const signJwtTokenRequest : SignJwtToken = { header: {}, payload: {} } const result = await WalletApi.signJwtToken(walletId, signJwtTokenRequest)

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 { WalletApi, Configuration, UpdateWalletInput } from '@affinidi-tdk/wallets-client'
// Pass the projectScopedToken generated from AuthProvider package const authConfiguration = new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) }) const WalletApi = new WalletApi(authConfiguration) const walletId= "<WALLET_ID>" const updateWalletRequest : UpdateWalletInput = { name: "", description: "" } const result = await WalletApi.updateWallet(walletId, updateWalletRequest)

createWalletKey

Add a cryptographic key to an existing wallet.

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

Parameters

walletId [String]

ID of the Wallet to add a key to.

CreateWalletKeyInput [Object]

JSON object to provide the key details. See more here.

Example
import { WalletApi, Configuration, CreateWalletKeyInput } from '@affinidi-tdk/wallets-client'
// Pass the projectScopedToken generated from AuthProvider package const authConfiguration = new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) }) const WalletApi = new WalletApi(authConfiguration) const createKeyRequest : CreateWalletKeyInput = { keyType: "ed25519", relationships: ["authentication", "assertionMethod"] } const result = await WalletApi.createWalletKey("<WALLET_ID>", createKeyRequest)

listWalletKeys

Retrieve all keys associated with a wallet.

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

Parameters

walletId [String]

ID of the Wallet.

Example
import { WalletApi, Configuration } from '@affinidi-tdk/wallets-client'
// Pass the projectScopedToken generated from AuthProvider package const authConfiguration = new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) }) const WalletApi = new WalletApi(authConfiguration) const result = await WalletApi.listWalletKeys("<WALLET_ID>")

removeWalletKey

Remove a key from a wallet.

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

Parameters

walletId [String]

ID of the Wallet.

keyId [String]

Wallet-scoped key identifier (e.g. "key-1").

Example
import { WalletApi, Configuration } from '@affinidi-tdk/wallets-client'
// Pass the projectScopedToken generated from AuthProvider package const authConfiguration = new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) }) const WalletApi = new WalletApi(authConfiguration) await WalletApi.removeWalletKey("<WALLET_ID>", "key-1")

updateWalletKey

Update the verification relationships of an existing wallet key.

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

Parameters

walletId [String]

ID of the Wallet.

keyId [String]

Wallet-scoped key identifier (e.g. "key-1").

UpdateWalletKeyInput [Object]

JSON object to provide the updated key relationships. See more here.

Example
import { WalletApi, Configuration, UpdateWalletKeyInput } from '@affinidi-tdk/wallets-client'
// Pass the projectScopedToken generated from AuthProvider package const authConfiguration = new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) }) const WalletApi = new WalletApi(authConfiguration) const updateKeyRequest : UpdateWalletKeyInput = { relationships: ["authentication", "keyAgreement"] } const result = await WalletApi.updateWalletKey("<WALLET_ID>", "key-1", updateKeyRequest)

createServiceEndpoint

Add a DID service endpoint to a wallet’s DID document.

Parameters

walletId [String]

ID of the Wallet.

ServiceEndpointInput [Object]

JSON object to provide the service endpoint details. See more here.

Example
import { WalletApi, Configuration, ServiceEndpointInput } from '@affinidi-tdk/wallets-client'
// Pass the projectScopedToken generated from AuthProvider package const authConfiguration = new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) }) const WalletApi = new WalletApi(authConfiguration) const serviceRequest : ServiceEndpointInput = { url: "https://example.com/messaging", name: "My Messaging Service", serviceType: "DIDCommMessaging" } const result = await WalletApi.createServiceEndpoint("<WALLET_ID>", serviceRequest)

listServiceEndpoints

Retrieve all service endpoints associated with a wallet.

Parameters

walletId [String]

ID of the Wallet.

Example
import { WalletApi, Configuration } from '@affinidi-tdk/wallets-client'
// Pass the projectScopedToken generated from AuthProvider package const authConfiguration = new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) }) const WalletApi = new WalletApi(authConfiguration) const result = await WalletApi.listServiceEndpoints("<WALLET_ID>")

removeServiceEndpoint

Remove a service endpoint from a wallet’s DID document.

Parameters

walletId [String]

ID of the Wallet.

serviceId [String]

ID of the service endpoint to remove.

Example
import { WalletApi, Configuration } from '@affinidi-tdk/wallets-client'
// Pass the projectScopedToken generated from AuthProvider package const authConfiguration = new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) }) const WalletApi = new WalletApi(authConfiguration) await WalletApi.removeServiceEndpoint("<WALLET_ID>", "<SERVICE_ID>")

updateServiceEndpoint

Update an existing service endpoint on a wallet.

Parameters

walletId [String]

ID of the Wallet.

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 { WalletApi, Configuration, UpdateServiceEndpointInput } from '@affinidi-tdk/wallets-client'
// Pass the projectScopedToken generated from AuthProvider package const authConfiguration = new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) }) const WalletApi = new WalletApi(authConfiguration) const updateServiceRequest : UpdateServiceEndpointInput = { name: "Updated Service Name", url: "https://new-endpoint.example.com" } const result = await WalletApi.updateServiceEndpoint("<WALLET_ID>", "<SERVICE_ID>", updateServiceRequest)