/
wallets.ts
49 lines (44 loc) · 1.69 KB
/
wallets.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright 2019 IBM All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
import { CouchDBWalletStore } from './couchdbwalletstore';
import { FileSystemWalletStore } from './filesystemwalletstore';
import { InMemoryWalletStore } from './inmemorywalletstore';
import { Wallet } from './wallet';
import * as nano from 'nano';
/**
* Factory for creating wallets backed by default store implementations.
* @memberof module:fabric-network
*/
export class Wallets {
/**
* Create a wallet backed by an in-memory (non-persistent) store. Each wallet instance created will have its own
* private in-memory store.
* @returns {Promise<module:fabric-network.Wallet>} A wallet.
*/
public static async newInMemoryWallet(): Promise<Wallet> {
const store = new InMemoryWalletStore();
return new Wallet(store);
}
/**
* Create a wallet backed by the provided file system directory.
* @param {string} directory A directory path.
* @returns {Promise<module:fabric-network.Wallet>} A wallet.
*/
public static async newFileSystemWallet(directory: string): Promise<Wallet> {
const store = await FileSystemWalletStore.newInstance(directory);
return new Wallet(store);
}
/**
* Create a wallet backed by a CouchDB database.
* @param {string | nano.Configuration} config URL string or configuration for a CouchDB server.
* @param {string} [dbName=wallet] Name of a database hosted on the CouchDB server.
* @returns {Promise<module:fabric-network.Wallet>} A wallet.
*/
public static async newCouchDBWallet(config: string | nano.Configuration, dbName: string = 'wallet'): Promise<Wallet> {
const store = await CouchDBWalletStore.newInstance(config, dbName);
return new Wallet(store);
}
}