0.0.2 • Published 4 years ago

react-native-hlf-wrapper v0.0.2

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
4 years ago

react-native-hlf-wrapper

Github: https://github.com/bityoga/react-native-hlf-wrapper A react-native wrapper for Hyperledger Fabric 1.4+. Works only for android currently The native modules wrappers are written in golang and converted to relevant android and ios native modules using gomobile. Refer to project: https://github.com/bityoga/mysome_drivers

Provides client functionalities of

  • enrolling a user
  • invoking a chaincode function
  • querying a chaincode function

Doesnot provide admin services, as admin services needs to be handled from a backend server rather than from a mobile client

Dependencies

The client react-native project needs to have the following packages installed:

"react": "^16.8.1",
"react-native": ">=0.60.0-rc.0 <1.0.x",
"react-native-fs": "^2.16.6"

Installation

$ npm install react-native-hlf-wrapper --save or $ yarn add react-native-hlf-wrapper

Mostly automatic installation

The linking is handled automatically. However, if the react native module is not linked, the following command can be executed $ react-native link react-native-hlf-wrapper

Usage Example

In your react native project you can interact with the Hyperledger Fabric network as follows:

Setting up connection/configuration

In order to connect with the Hyperledger Fabric cluster, we need to set up a config/connection profile with which the client can communicate with the cluster. Currently, the connection_profile file is only tested in JSON format and not YAML format. Additionally, we also haven't yet tested TLS communication with either the CA, orderers or peers. Please get the file connection_profile.template.json from this project's root directory into your react-native app's root directory. Rename it as:connection_profile.json Inside the connection_profile.json file, change the required values as per your Hyperledger Fabric cluster configuration.

From react-native app

import HlfSdk from 'react-native-hlf-wrapper'; // Load the module
//Imports the connection/configuration to connect with a Hyperledger fabric sdk. Has to be JSON for now and needs to be present at your project root directory
let connection_profile = require('./connection_profile.json');  
... 
let response = await HlfSdk.hello(); //Returns a "hello world" message to show interaction with the native module
await HlfSdk.connectionProfileSetup(connection_profile); // Sets up the connection profile. This process needs to be performed
// Enrolls a user. Provide the username and password for an already registered user. It will be enrolled and its crypto material will be stored under: RNFS.DocumentDirectoryPath/msp
let response = await HlfSdk.enrollUser(username, secret); //Returns the publickey/cert, certName and private key as stringified JSON
// Invoke a chaincode function
let response = await HlfSdk.invoke(user, channelName, chaincodeName, fnc, args); //Gets the response as stringified JSON
// Query a chaincode function
let response = await HlfSdk.query(user, channelName, chaincodeName, fnc, args); //Gets the response as stringified JSON

Testing up the example app associated with this project Optional

  • navigate to the example folder under project: https://github.com/achak1987/react-native-hlf-wrapper
  • connection_profile.template.json file is already copied here as connection_profile.json
  • change the connection_profile.json as per your hyperledger fabric configuration
  • Install dependencies using YARN
yarn add react-native-fs@2.16.6
yarn add react-native-hlf-wrapper

or using NPM

npm install react-native-fs@2.16.6 --save
yarn install react-native-hlf-wrapper --save
  • Auto linking should be done. So we dont need to manually link them
  • Run the metro server by navigating to this project/example in your terminal and run: react-native start
  • Start the app by running yarn android in your terminal
absolute-pathanseracceptsansi-cyanansi-colorsabort-controlleransi-escapesansi-fragmentsansi-redansi-grayansi-stylesansi-regexansi-wrapargparsearr-diffarr-flattenanymatcharr-unionarray-maparray-filterarray-sliceasaparray-uniquearray-reduceastral-regexassign-symbolsasyncatobbabel-plugin-dynamic-import-nodebase-64balanced-matchbasebabel-preset-fbjsbabel-plugin-syntax-trailing-function-commasbig-integerbase64-jsbindingsbplist-parserbplist-creatorbrace-expansionbserbracesbytesbuffer-fromcache-basecaller-pathcaller-callsitebuffer-crc32capture-exitcamelcasechalkchardetcallsitesci-infocli-cursorclass-utilscli-spinnerscliuicollection-visitclonecli-widthcolor-supportcode-point-atcolorettecolor-convertcommand-existscolor-namecommondircommandercompressiblecomponent-emittercompressionconnectcore-jsconcat-streamconcat-mapconvert-source-mapcreate-react-classcore-util-iscosmiconfigdayjsdebugcopy-descriptordeepmergecross-spawndecode-uri-componentdecamelizedefaultsdefine-propertiesdefine-propertydenodeifydepddestroyemoji-regexencodeurlencodingenvinfoerror-exend-of-streamerrorhandleree-firstescape-htmlesprimaeslint-plugin-relayescape-string-regexpetagexec-sheventemitter3expand-bracketsevent-target-shimextend-shallowexecaexternal-editorfancy-logfb-watchmanfbjsextglobfbjs-css-varsfiguresfbjs-scriptsfile-uri-to-pathfill-rangefinalhandlerfind-upfor-infind-cache-dirfs-extrafseventsfragment-cachefs.realpathfreshfunction-bindgensyncget-valueget-streamglobglobalsget-caller-filegraceful-fshas-symbolshas-valuehas-valueshas-flaggraphqlhttp-errorsiconv-liteimport-freshhermes-engineimage-sizeimurmurhashinquirerinflightinheritsinvert-kvis-arrayishinvariantis-accessor-descriptoris-bufferis-ciis-descriptoris-data-descriptoris-directoryis-fullwidth-code-pointis-numberis-extendableis-wslis-streamis-windowsisobjectisarrayisomorphic-fetchis-plain-objectisexeiteralljest-haste-mapjest-message-utiljest-get-typejest-serializerjs-tokensjest-mockjest-validatejest-workerjest-utiljetifierjs-yamljsc-androidjsescjson-stable-stringifyjson-parse-better-errorsjsonifyjson5jsonfilekind-ofklawlcidlodash.throttlelocate-pathlodashlog-symbolslevenlogkittymake-dirlru-cacheloose-envifymakeerrormap-age-cleanermap-cachemerge-streammap-visitmemmetrometro-babel-transformermetro-babel-registermetro-cachemetro-coremetro-configmetro-minify-uglifymetro-react-native-babel-transformermetro-inspector-proxymetro-react-native-babel-presetmetro-resolvermetro-symbolicatemetro-source-mapmicromatchmime-dbminimistmime-typesmimic-fnmixin-deepminimatchmkdirpmsmute-streamnannanomatchnegotiatornice-trynode-int64node-fetchnode-modules-regexpnullthrowsnode-stream-zipnpm-run-pathnormalize-pathob1number-is-nanobject-copyobject-assignobject-keysobject.pickobject-visiton-finishedon-headersonceoptionsobject.assignmimeoraos-localeos-tmpdiropenonetimep-deferp-limitp-finallyp-is-promisep-tryparseurlparse-node-versionp-locateparse-jsonpascalcasepath-keypath-existspath-parsepath-is-absolutepkg-dirpiratespifyplistplugin-errorposix-character-classespretty-formatprop-typesprivatepromisepseudomaprange-parserpumpreact-isreact-refreshreact-devtools-corereadable-streamregenerateregenerate-unicode-propertiesprocess-nextick-argsregenerator-runtimeregex-notregjsgenregenerator-transformregexpu-coreregjsparserremove-trailing-separatorrepeat-stringrepeat-elementrequire-main-filenameresolveresolve-urlresolve-fromrimrafretrestore-cursorrsvprx-literx-lite-aggregatesrun-asyncsafe-buffersafe-regexsafer-bufferrxjsrequire-directorysanesaxsemverserialize-errorsendschedulerserve-staticset-blockingset-valueshebang-commandsetprototypeofsetimmediatesignal-exitshell-quoteshebang-regexslashsimple-plistslideslice-ansisnapdragon-nodesnapdragon-utilsnapdragonsource-mapsplit-stringsource-map-resolvesource-map-urlsource-map-supportsprintf-jsstatic-extendstack-utilsstacktrace-parserstatusesstream-buffersstrip-ansistrip-eofstring_decoderstring-widthsymbol-observablesudo-promptsupports-colortempthroughthroattmptmplthrough2time-stampto-fast-propertiesto-object-pathto-regextoidentifierto-regex-rangetypedarrayua-parser-jsuglify-estype-festultronunicode-match-property-ecmascriptunicode-canonical-property-names-ecmascriptunicode-property-aliases-ecmascriptunicode-match-property-value-ecmascriptunion-valueuniversalifyutf8unpipeunset-valueurixuse-subscriptionutil-deprecateuseuuidwalkervaryutils-mergevlqwcwidthwhichwhich-modulewhatwg-fetchwordwrapwrap-ansiwswrite-file-atomicxcodewrappyxmlbuilderxmldocy18nxtendxpipeyargs-parserxmldomyallistyargs
0.0.3

4 years ago

0.0.1

4 years ago

0.0.2

4 years ago

1.0.0

4 years ago