'use strict' ; import { SettingConfigurations } from '../configurations' ; import { FileConfigurations , FileSystemUtil , FabricIdentity , FabricEnvironmentRegistryEntry , FabricWalletRegistryEntry , IFabricWalletGenerator , FabricWalletGeneratorFactory , IFabricWallet } from 'ibm-blockchain-platform-common' ; import * as path from 'path' ; import { LocalMicroEnvironment } from './environments/LocalMicroEnvironment' ; import { EnvironmentFactory } from './environments/EnvironmentFactory' ; export class FabricWalletHelper { static readonly LOCAL_WALLET_DISPLAY_NAME : string = 'Local Fabric Wallet' ; public static getWalletPath ( walletName ) { const extDir = SettingConfigurations . getExtensionDir ( ) ; const homeExtDir = FileSystemUtil . getDirPath ( extDir ) ; return path . join ( homeExtDir , FileConfigurations . FABRIC_WALLETS , walletName ) ; } public static async getVisibleIdentities ( environmentEntry , walletEntry ) { const walletName = walletEntry . name ; const fabricWalletGenerator = FabricWalletGeneratorFactory . getFabricWalletGenerator ( ) ; const wallet = await fabricWalletGenerator . getWallet ( walletEntry ) ; let allIdentities ; let visibleIdentities ; const environment = EnvironmentFactory . getEnvironment ( environmentEntry ) as LocalMicroEnvironment ; const _allIdentities = await environment . getIdentities ( walletName ) ; allIdentities = _allIdentities . map ( ( _id ) => _id . name ) ; const _visibleIdentities = await environment . getVisibleIdentities ( walletName ) ; visibleIdentities = _visibleIdentities . map ( ( _id ) => { return _id . name ; } ) ; let identities = await wallet . getIdentities ( ) ; identities = identities . filter ( ( identity ) => { return ( allIdentities . includes ( identity . name ) && visibleIdentities . includes ( identity . name ) ) || ! allIdentities . includes ( identity . name ) ; } ) ; return identities ; } }