npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fabric-client-wrapper

v1.1.1

Published

A wrapper around the Fabric Node SDK

Downloads

5

Readme

Hyperledger Fabric Client Wrapper

This is a wrapper over the Hyperledger Fabric Node SDK, that simplifies setting up the network and making transactions

Node Versions

Node runtime version 6.9.x or higher, and 8.4.0 or higher ( Node v7+ is not supported )

Running Tests

See Here

Fabric Client Wrapper Documentation

See here

Examples

Example project

Not opensourced yet, but coming soon

Load a user from a public/private key pair

import fs from "fs"
import path from "path"
import fcw from "fabric-client-wrapper"

async function foo() {
    const mspId = "Org1MSP"
    const keystorePath = path.join(__dirname, "keystore")
    const { cryptoSuite, store } = await fcw.createFileKeyValueStoreAndCryptoSuite(
        keystorePath
    )
    const privateKeyPath = path.join(__dirname, "./123_sk")
    const publicKeyPath = path.join(__dirname, "./123.pem")
    const privateKeyPEM = fs.readFileSync(privateKeyPath).toString()
    const signedCertPEM = fs.readFileSync(publicKeyPath).toString()
    const gregClient = await createUserClientFromKeys(
        {
            username,
            cryptoContent: {
                privateKeyPEM,
                signedCertPEM
            },
            store,
            cryptoSuite
        }
    )
}

foo()

Load a user from the CA

import fs from "fs"
import path from "path"
import fabricCAClient from "fabric-ca-client"
import fcw from "fabric-client-wrapper"

async function foo() {
    const mspId = "Org1MSP"
    const keystorePath = path.join(__dirname, "keystore")
    const { cryptoSuite, store } = await fcw.createFileKeyValueStoreAndCryptoSuite(
        keystorePath
    )
    const fabricCAClient = new FabricCAClient(
        "https://localhost:7054",
        null,
        "",
        cryptoSuite
    )
    const bobClient = await fcw.createUserClientFromCAEnroll({
        fabricCAClient,
        enrollmentID: "bob",
        enrollmentSecret: "password123"
    })
}

foo()

Create a new channel object

import fs from 'fs'
import path from 'path'
import fcw from 'fabric-client-wrapper'
import Orderer from 'fabric-client/lib/Orderer'

async function foo() {
    const gregClient = ...
    const peerPem = fs.readFileSync(path.join(__dirname, "./peer1.pem")).toString()
    const connectionOpts = { pem: peerPem }
    const peers = [
      gregClient.createEventHubPeer({
          requestUrl: "grpcs://peer0.org1.example.com:7051",
          eventUrl: "grpcs://peer0.org1.example.com:7053",
          peerOpts: connectionOpts,
          eventHubOpts: connectionOpts
      })
    ]
    await Promise.all(peers.map(peer => peer.waitEventHubConnected()))

    const orderer = new Orderer(
        "grpcs://orderer.example.com:7050",
        {
            pem: fs.readFileSync(path.join(__dirname, "./orderer.pem")).toString()
        }
    )

    const channel = new fcw.FcwChannel({
        client: gregClient,
        channelName: "mychannel",
        peers,
        orderer
    })
    await channel.initialize()
}

foo()

Setup a channel+chaincode on the network

import fs from 'fs'
import path from 'path'
import fcw from 'fabric-client-wrapper'

async function foo() {
    const gregClient = ...
    const channel = ...
    const channelTxPath = path.join(__dirname, './channel.tx')
    const channelEnvelope = fs.readFileSync(channelTxPath)
    const chaincodeId = 'awesomecc'
    const chaincodePath = 'github.com/my_awesome_cc'
    const chaincodeVersion = 'v1'
    await fcw.setupChannel(gregClient, channel)
      .withCreateChannel({ channelEnvelope })
      .withJoinChannel()
      .withInstallChaincode({ chaincodeId, chaincodePath, chaincodeVersion })
      .withInstantiateChaincode({
          chaincodeId,
          chaincodeVersion,
          fcn: 'init',
          args: ["a", "100", "b", "200"],
      })
      .run()
}

foo()

Perform an invoke+query

import fcw from 'fabric-client-wrapper'

async function foo() {
    const gregClient = ...
    const channel = ...
    const transactor = fcw(gregClient, channel, 'awesomecc')
    const invokeResponse = await transactor.invoke('move', ['a', 'b', '10'])
    console.log("Invoke payload", invokeResponse.data.proposalResponse.payload.toString())
    await invokeResponse.wait() // wait for peers to write transaction to state
    const queryResponse = await transactor.query('query', ['a'])
    console.log("Query payload", queryResponse.data.payload.toString())
}

foo()