How to use the fabric-network.Wallets.newInMemoryWallet function in fabric-network

To help you get started, we’ve selected a few fabric-network examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hyperledger / fabric-sdk-node / test / ts-scenario / steps / lib / gateway.ts View on Github external
export async function createGateway(ccp: CommonConnectionProfileHelper, tls: boolean, userName: string, orgName: string, gatewayName: string, useDiscovery: boolean, walletType: string): Promise {

	// Might already have a wallet to use, but sanitize the passed walletType
	if (!walletType || !supportedWallets.includes(walletType)) {
		BaseUtils.logAndThrow(`Passed wallet type [${walletType}] is not supported, must be one of: ${supportedWallets}`);
	}

	const myWalletReference: string = `${Constants.WALLET}_walletType`;
	let wallet: Wallet = stateStore.get(myWalletReference);
	if (!wallet) {
		BaseUtils.logMsg(`Creating wallet of type ${walletType}`);
		switch (walletType) {
			case Constants.MEMORY_WALLET:
				wallet = await Wallets.newInMemoryWallet();
				break;
			case Constants.FILE_WALLET:
				const tempDir: string = path.join(__dirname, Constants.LIB_TO_TEMP, Constants.FILE_WALLET);
				if (fs.existsSync(tempDir)) {
					BaseUtils.recursiveDirDelete(tempDir);
				}
				await fs.mkdirSync(tempDir);
				wallet = await Wallets.newFileSystemWallet(tempDir);
				break;
			case Constants.COUCH_WALLET:
				wallet = await Wallets.newCouchDBWallet({url: Constants.COUCH_WALLET_URL as string});
				break;
			default:
				BaseUtils.logAndThrow(`Unmatched wallet backing store`);
		}
	}
github hyperledger / fabric-sdk-node / test / typescript / integration / network-e2e / query.ts View on Github external
async function createWallet(t: tape.Test): Promise {
	// define the identity to use
	const credPath = fixtures + '/crypto-material/crypto-config/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp';
	const cert = fs.readFileSync(credPath + '/signcerts/User1@org1.example.com-cert.pem').toString();
	const key = fs.readFileSync(credPath + '/keystore/key.pem').toString();

	const wallet = await Wallets.newInMemoryWallet();

	// prep wallet and test it at the same time
	const identity: X509Identity = {
		credentials: {
			certificate: cert,
			privateKey: key,
		},
		mspId: 'Org1MSP',
		type: 'X.509',
	};
	await wallet.put(identityLabel, identity);
	const savedIdentity = await wallet.get(identityLabel);
	t.ok(savedIdentity, 'Successfully imported User1@org1.example.com into wallet');

	const tlsInfo = await e2eUtils.tlsEnroll('org1');
	const tlsIdentity: X509Identity = {
github hyperledger / fabric-sdk-node / test / scenario / features / lib / network.js View on Github external
async function connectGateway(ccp, tls, userName, orgName, gatewayName, useDiscovery) {

	const gateway = new Gateway();
	const wallet = await Wallets.newInMemoryWallet();

	// import specified user to wallet
	const userIdentity = await identitySetup(wallet, ccp, orgName, userName);

	if (tls) {
		const caName = ccp.getCertificatAuthoritiesForOrg(orgName)[0];
		const fabricCAEndpoint = ccp.getCertificateAuthority(caName).url;
		const tlsInfo = await testUtil.tlsEnroll(fabricCAEndpoint, caName);
		const caOrg = ccp.getOrganization(orgName);

		const tlsIdentity = {
			credentials: {
				certificate: tlsInfo.certificate,
				privateKey: tlsInfo.key
			},
			mspId: caOrg.mspid,
github hyperledger / fabric-sdk-node / test / typescript / integration / network-e2e / invoke.ts View on Github external
async function getWallet(): Promise {
	if (!inMemoryWallet) {
		inMemoryWallet = await Wallets.newInMemoryWallet();
		await identitySetup(inMemoryWallet);
	}
	return inMemoryWallet;
}
github hyperledger / fabric-sdk-node / test / integration / network-e2e / invoke-hsm.js View on Github external
const walletPromise = (async () => {
	const wallet = await Wallets.newInMemoryWallet();
	const hsmOptions = {
		lib: pkcsLibPath,
		pin: PKCS11_PIN,
		slot: PKCS11_SLOT
	};
	const hsmProvider = new HsmX509Provider(hsmOptions);
	wallet.getProviderRegistry().addProvider(hsmProvider);

	const idManager = new IDManager(JSON.parse(ccp.toString()), hsmOptions);
	await idManager.initialize();

	const adminEnrollment = await idManager.enroll(adminUser, adminSecret);
	const adminIdentity = {
		credentials: {
			certificate: adminEnrollment.certificate,
			privateKey: adminEnrollment.key.toBytes()