The Cloud Wallet feature allows secure storage and synchronization of wallet documents via an Encrypted Data Vault (EDV).
File Path: @docknetwork/wallet-sdk-core/src/cloud-wallet
The Cloud Wallet integrates with an Encrypted Data Vault (EDV) to securely store, sync, and manage documents. Once initialized, it automatically synchronizes documents between the EDV and the wallet, allowing you to add, update, remove, without dealing with the synchronization logic.
The example below demonstrates how to initialize and use the Cloud Wallet for managing documents.
import {createDataStore} from '@docknetwork/wallet-sdk-data-store-typeorm/lib';
const dataStore = await createDataStore({
databasePath: 'dock-wallet',
dbType: 'sqlite',
defaultNetwork: 'testnet',
});
import {createDataStore} from '@docknetwork/wallet-sdk-data-store-web/lib';
const dataStore = await createDataStore({
databasePath: 'dock-wallet',
defaultNetwork: 'testnet',
});
Use the same Cloud Wallet keys across multiple devices to access the same documents. These keys are used to encrypt, decrypt, and locate documents in the EDV.
const {verificationKey, agreementKey, hmacKey} = await edvService.generateKeys();
The key generation returns an object with agreementKey
, verificationKey
, and hmacKey
. You will use these keys to initialize the Cloud Wallet.
Note: Encryption keys can be derived from biometric data through a third-party service, offering enhanced security by linking the keys to a user's unique biometric profile
After setting up the data store and generating keys, initialize the Cloud Wallet. This ensures continuous synchronization between the EDV and the wallet.
import {initializeCloudWallet} from '@docknetwork/wallet-sdk-core/lib/cloud-wallet';
const {pullDocuments} = await initializeCloudWallet({
dataStore,
edvUrl: EDV_URL,
authKey: EDV_AUTH_KEY,
agreementKey,
verificationKey,
hmacKey,
});
// Pull documents from the EDV and sync with the wallet
await pullDocuments();
The pullDocuments
function synchronizes the EDV and the wallet by comparing documents and updating the data store accordingly.
Now, create a wallet to manage your documents. This will allow you to add, update, and remove documents.
import {createWallet} from '@docknetwork/wallet-sdk-core/lib/wallet';
const wallet = await createWallet({
dataStore,
});
You can add a document to the wallet using the following code:
const document = {
id: 'document-id',
type: 'document-type',
someData: 'any-data-you-want',
};
await wallet.addDocument(document);
import {createDataStore} from '@docknetwork/wallet-sdk-data-store-web/lib';
import {initializeCloudWallet} from '@docknetwork/wallet-sdk-core/lib/cloud-wallet';
import {createWallet} from '@docknetwork/wallet-sdk-core/lib/wallet';
async function example() {
const dataStore = await createDataStore({
databasePath: 'dock-wallet',
defaultNetwork: 'testnet',
});
const {pullDocuments} = await initializeCloudWallet({
dataStore,
edvUrl: EDV_URL,
authKey: EDV_AUTH_KEY,
agreementKey,
verificationKey,
hmacKey,
});
// Pull documents from the EDV and sync with the wallet
await pullDocuments();
const wallet = await createWallet({
dataStore,
});
const document = {
id: 'document-id',
type: 'document-type',
someData: 'any-data-you-want',
};
await wallet.addDocument(document);
}
example();