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

configtxlator.js

v0.1.1

Published

Hyperledger Fabric's configtxlator implemented in js as a library to use with fabric-sdk-node

Downloads

16

Readme

configtxlator.js

Hyperledger Fabric's configtxlator implemented as a js library

Motivation

If you are here you want to decode your block and convert it into a javascript object through fabric-sdk-node without using a local server of configtxlator in order to do it, then you came to the right place!

This first version will allow you to append a organization to a configblock given its json generated by configtxgen.

Install

You can install this lib by

npm i configtxlator.js

if you're using typescript

npm i @types/configtxlator.js

Adding an org to a channel

First get block.json from channel:


const block = await Channel.getChannelConfigFromOrderer()
//Replace snake_case to camelCase and sequence/version tags to int
//otherwise protobuf won't work
const channelBlock = JSON.parse(
    block.encodeJSON()
         .replace(/(_\w)\w+":/g, (match: String) => match[1].toUpperCase() + match.substring(2)),
    (key, value) =>
        key === "sequence" ? parseInt(value) : key === "version" ? parseInt(value) : value
);
// Create a replica that will be modified using same process
const newChannelBlock = JSON.parse(
    block.encodeJSON()
         .replace(/(_\w)\w+":/g, (match: String) => match[1].toUpperCase() + match.substring(2)),
    (key, value) =>
        key === "sequence" ? parseInt(value) : key === "version" ? parseInt(value) : value
);

Those parses are necessary once block.EncodeJSON() from fabric lib returns a json where all key entries are snake_case instead of camelCase (protobufjs doesn't recognizes snake_case entries).

Convert both channelBlock and newChannelBlock into common.Config protos:


const configBlock = fabProtos.common.Config.create({
    channelGroup: channelBlock.config.channelGroup,
    sequence: channelBlock.config.sequence
});
const newConfigBlock = fabProtos.common.Config.create({
    channelGroup: newChannelBlock.config.channelGroup,
    sequence: channelBlock.config.sequence
});

Convert new org's JSON got from configtxgen into a common.Config proto:


import configtxlator = require('configtxlator.js');
const translatedNewOrg = configtxlator.convertOrgJsonToConfigGroup(
    orgJson
);

Append new org config into application groups:


const orgs = newConfigBlock.channelGroup.groups.Application.groups;
newConfigBlock.channelGroup.groups.Application.groups = {
    ...orgs,
    [orgName]: translatedNewOrg
};

Create protos object back from protos interfaces:


const originalConfig = fabProtos.common.Config.create(configBlock);
const updatedConfig = fabProtos.common.Config.create(newConfigBlock);

Finally, compute delta set between both configs:


updatedBlock = await configtxlator.computeDeltaSet(originalConfig, updatedConfig);

updatedBlock.channelId = channelName; //Channel name is the channel you're trying to modify

//Convert updatedBlock into a Uint8Array
const updatedIntArray = fabProtos.common.ConfigUpdate.encode(updatedBlock).finish();

//Convert from Uint8Array to js Buffer
const updatedBuffer = Buffer.from(updatedIntArray, 0);

//Sign updatedChannelConfig buffer
const signatures = [Client.signChannelConfig(updatedBuffer)];

And then submit a updateChannel request proposal through fabric-sdk-node