Instantiate a Wallet
There are several types of wallets supported by the Hyperledger Fabric SDK. They differ in the way they store user identities. Thus, you should first choose an appropriate wallet type to instantiate a wallet.
FileSystemWallet
Filesystem is the most common place to create wallets. Filesystems are pervasive, easy to understand, and can be network-mounted. They are a good default choice for wallets.
InMemoryWallet
The in-memory wallet stores identities in application memory. This type of wallet should be used when the application is running in a constrained environment without access to a filesystem (typically, a web browser). It is worth remembering that this type of wallet is volatile: identities will be lost after the application ends normally or crashes.
CouchDBWallet
CouchDBWallet uses a CouchDB instance to store the identities. CouchDB wallets can provide a useful option to simplify disaster recovery because of the database backup and restore mechanisms.
Wallets of any type can be used with a hardware security module (HSM) to provide a sufficient level of security. This ultra-secure, tamper-proof device stores digital identity information, particularly, private keys. HSMs can be locally attached to your computer or network with ease of access. Most HSMs provide the ability to perform on-board encryption with private keys, so that a private key never leaves an HSM. To learn more about HSM implications in the context of Hyperledger Fabric applications, see the wallet tutorial in the official documentation.
To create a wallet, use the Wallets class that contains a factory method for each out-of-box wallet type. For educational purposes, we will utilize FileSystemWallet, as this type of wallet is sufficient for our goals. In the application folder, let’s create the addToWallet.js file. This file is responsible for the wallet initialization and identities import.
To create a FileSystemWallet object, simply use the corresponding factory method specifying a file system path. If the path does not exist, then it will be created at runtime.
const { Wallets } = require('fabric-network'); const wallet = await Wallets.newFileSystemWallet('./wallet');
Now, you can manage the identities via the newly-created object.
Last updated
Was this helpful?