How to use the fabric-network.Wallets.newFileSystemWallet 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.

github hyperledger / fabric-sdk-node / test / ts-scenario / steps / lib / gateway.ts View on Github external
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`);
		}
	}

	// Might already have a user@org in that wallet
	const userId: string = `${userName}@${orgName}`;
	const userIdentity: Identity | undefined = await wallet.get(userId);

	// Will always be adding a gateway
	const gateway: Gateway = new Gateway();
github hyperledger-labs / weaver-dlt-interoperability / tests / network-setups / fabric / dev / scripts / fabric-cli / src / helpers / fabric-functions.ts View on Github external
userPwd: string = '',
  register: boolean = false,
  logger: any = console
) => {
  // Create a new CA client for interacting with the CA.
  // Create a new CA client for interacting with the CA.
  const org = ccp.client['organization']
  const caName = ccp.organizations[org]['certificateAuthorities'][0]
  const caURL = ccp.certificateAuthorities[caName].url
  const ca = new FabricCAServices(caURL)
  const ident = ca.newIdentityService()

  const walletPath = process.env.WALLET_PATH
    ? process.env.WALLET_PATH
    : path.join(__dirname, '../', `wallet-${networkName}`)
  const wallet = await Wallets.newFileSystemWallet(walletPath)

  logger.info(`Wallet Setup: wallet path: ${walletPath}`)

  // build a user object for authenticating with the CA        // Check to see if we've already enrolled the admin user.
  let adminIdentity = await wallet.get('admin')

  if (adminIdentity) {
    logger.debug(
      'An identity for the admin user "admin" already exists in the wallet.'
    )
  } else {
    // Enroll the admin user, and import the new identity into the wallet.
    const enrollment = await ca.enroll({
      enrollmentID: 'admin',
      enrollmentSecret: 'adminpw'
    })
github hyperledger-labs / weaver-dlt-interoperability / core / drivers / fabric-driver / server / walletSetup.ts View on Github external
);
        return;
    }
    const ccp = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
    const config = getConfig();
    // Create a new CA client for interacting with the CA.
    const org = ccp.client["organization"];
    console.log('Org ', org);
    const caName =  ccp.organizations[org]["certificateAuthorities"][0];
    console.log('CA Name ', caName);
    const caURL = ccp.certificateAuthorities[config.caUrl ? config.caUrl : caName].url;
    console.log('CA URL', caURL);
    const ca = new FabricCAServices(caURL);
    const ident = ca.newIdentityService();

    const wallet = await Wallets.newFileSystemWallet(walletPath);
    const adminName = config.admin.name;
    const adminSecret = config.admin.secret;
    // build a user object for authenticating with the CA        // Check to see if we've already enrolled the admin user.
    let adminIdentity = await wallet.get(adminName);

    if (adminIdentity) {
        console.log('An identity for the admin user "admin" already exists in the wallet');
    } else {
        // Enroll the admin user, and import the new identity into the wallet.
        console.log('Enrolling Admin...', adminName, adminSecret);
        const enrollment = await ca.enroll({
            enrollmentID: adminName,
            enrollmentSecret: adminSecret,
        });
        const x509Identity = {
            credentials: {
github Zzocker / EHR-on-blockchain / Blockchain / node-api / api / contract.js View on Github external
const contract =  async (type,inputs,callback) =>{
   const gateway = new Gateway()
       try {
         const ccp = yaml.safeLoad(fs.readFileSync(CONNECTION_PROFILE_PATH))
         const wallet = await Wallets.newFileSystemWallet(WALLET_PATH)
         await gateway.connect(ccp,{wallet:wallet,identity:IDENTITY_NAME,discovery: { enabled: false, asLocalhost: true }})
         const network = await gateway.getNetwork(CHANNEL_NAME)
         const contract = network.getContract(CONTRACT_NAME)
         var res
         if (type == "INVOKE"){
            res = await contract.submitTransaction(...inputs)
         } else if (type == "QUERY"){
            res = await contract.evaluateTransaction(...inputs)
         }
         return callback(null,res)
      } catch (error) {
         //  callback(error,null)
          return callback(error.responses[0].response,null)
       } finally{
          gateway.disconnect()
       }
github Zzocker / EHR-on-blockchain / Blockchain / node-api / test-client / enrollAdmin.js View on Github external
const main = async ()=>{
    try {
        const wallet = await Wallets.newFileSystemWallet(WALLETPATH)
        const admin = await wallet.get('admin')
        if (admin){
            console.log("Admin is already enrolled")
            return
        }

        const ca = new fabricCAService("http://localhost:7054")
        
        const enrollment = await ca.enroll({enrollmentID:"admin",enrollmentSecret:'adminpw'},)
        const x509Identity = {
            credentials: {
                certificate: enrollment.certificate,
                privateKey: enrollment.key.toBytes(),
            },
            mspId: 'DevMSP',
            type: 'X.509',
github hyperledger / fabric-sdk-node / test / typescript / integration / network-e2e / invoke.ts View on Github external
test('\n\n***** Network End-to-end flow: invoke transaction to move money using in file system wallet *****\n\n', async (t: tape.Test) => {
	const tmpdir = await createTempDir();
	const gateway = new Gateway();

	try {
		const fileSystemWallet: Wallet = await Wallets.newFileSystemWallet(tmpdir);
		await identitySetup(fileSystemWallet);

		await gateway.connect(JSON.parse(ccp.toString()), {
			clientTlsIdentity: tlsIdentityName,
			discovery: {
				enabled: false,
			},
			identity: identityName,
			wallet: fileSystemWallet,
		});
		t.pass('Connected to the gateway');

		const network = await gateway.getNetwork(channelName);
		t.pass('Initialized the channel, ' + channelName);

		const contract = await network.getContract(chaincodeId);
github hyperledger-labs / weaver-dlt-interoperability / core / drivers / fabric-driver / server / fabric-code.ts View on Github external
const getWallet = (walletPath: string) => {
    return Wallets.newFileSystemWallet(walletPath);
};