Skip to main content

Authentication

The Cloud Wallet SDK requires authentication before you can create wallets, issue credentials, or perform wallet operations. You can authenticate using Wallet API key.

  • API Key – You can get an api key from Hovi Studio. Use this to create wallet.
  • Wallet Access Token – Scoped to a specific wallet. Use this when you need to act on behalf of that specific wallet, like accepting a credential offer or submitting a proof presentation

Initialization​

import { CloudWallet } from '@hovi/cloud-wallet-sdk';

const wallet = new CloudWallet({
apiKey: 'your-ecosystem-api-key',
});
note

You can create an instance of CloudWallet and use it from anywhere in your application instead of creating multiple instance.

Authentication Methods​

The SDK provides methods to set or update authentication credentials after initialization:

setApiKey(apiKey: string)​

Updates the API key for the wallet instance. This is useful when you need to switch between different ecosystem API keys or update the key at runtime.

await wallet.setApiKey('your-new-api-key');

setWalletAccessToken(walletAccessToken: string)​

Sets the wallet access token to perform operations on a specific wallet. Each wallet created under an ecosystem has a unique access token that grants permission to perform wallet-specific operations.

await wallet.setWalletAccessToken('wallet-specific-access-token');

Understanding the Authentication Flow​

An ecosystem operates with a single Cloud Wallet API key but can create multiple wallets. Here's how authentication works:

  1. Initialize with API Key: Create a CloudWallet instance with your ecosystem API key
  2. Create Wallets: Use the API key to create multiple wallets via .createWallet()
  3. Switch Between Wallets: Each wallet receives a unique walletAccessToken upon creation
  4. Perform Wallet Operations: Set the specific wallet's access token using setWalletAccessToken() to perform operations on that wallet

Example Workflow​

import { CloudWallet } from '@hovi/cloud-wallet-sdk';

// Step 1: Initialize with ecosystem API key
const wallet = new CloudWallet({
apiKey: 'your-ecosystem-api-key',
});

// Step 2: Create multiple wallets
const wallet1 = await wallet.createWallet({
/* ... */
});
const wallet2 = await wallet.createWallet({
/* ... */
});

// Step 3: Perform operations on wallet1
await wallet.setWalletAccessToken(wallet1.accessToken);
// Now you can accept credentials, create presentations, etc. for wallet1
await wallet.acceptCredentialOffer(/* ... */);

// Step 4: Switch to wallet2
await wallet.setWalletAccessToken(wallet2.accessToken);
// Now operations will be performed on wallet2
await wallet.acceptCredentialOffer(/* ... */);
tip

Store wallet access tokens securely and associate them with your users. This allows you to quickly switch between wallets by calling setWalletAccessToken() with the appropriate token.