The library allows Web, Node.js and React Native environment to connect with Band Chain. The code itself is written in TypeScript, but deployed as older ES5 ia Browserify to support older browser and React Native environments.
npm i --save bandprotocol
importBandProtocolClientfrom'bandprotocol'import{secretKey}from'./config'constclient=newBandProtocolClient({httpEndpoint: 'http://localhost:26657',keyProvider: secretKey,})This library supports secure key generations using ED25519 algorithm.
const{
mnemonic,// Array<string x 12> of Mnemonic phrase
secretKey,// 64-byte hex string secret key
verifyKey,// 32-byte hex string public key
address,// IBAN-style address}=BandProtocolClient.generateRandomKey()Every transaction is created on the remote node via JSON-RPC protocol and signed on the client. This design allows higher portability comparing to client-generated transactions, while the client keeps its secret keys secured.
See BandProtocol's Gitbook for documentation on transaction formats.
importBandProtocolClientfrom'bandprotocol'// Initialize clientconstclient=newBandProtocolClient({httpEndpoint: 'http://localhost:26657',keyProvider: '<secretKey>',})// Generate unsigned transaction from nodeconstunsignedTx=awaitclient.blockchain.txgen({msgid: 1,vk: '6ddb22994b551f4da5818e7a257d467e9af753348194f31dddc5f9aa489d3da1',dest: 'AX62 ECTZ WZZ5 XVTG N8NL 6EVB 9TPH TELJ ZBRL',token: 'BX63 AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA',value: '200000',})// Sign the transactionconstsignedTx=client.key.sign(unsignedTx)// Broadcast the signed transactionconstresult=awaitclient.blockchain.broadcastTxn(signedTx)The client supports secret key encryption via Libsodium's Secret-key encryption. Application server can store the secretbox without exposing the risk of leaking user's secret keys, given that the passcodes are strong enough.
To create secretbox from secret key, you'll need to initialize the client with secret key:
constpasscode='<some_user_defined_passcode>'constclient=newBandProtocolClient({keyProvider: '<secretKey>'})constsecretbox=client.encrypt(passcode)To restore client instance and secret key:
constclient=newBandProtocolClient({keyProvider: {secretbox: '<encrypted_secretbox>',passcode: '<user_passcode>',},})constsecretKey=client.getSecretKey()Make sure you have Node.js v8+ installed. Then run:
yarn install
Only Unit Tests are implemented for now. Integration tests with testnet can be possible, and we highly encourage you to contribute to make this happen.
yarn test
To make it compatible with React Native, the TypeScript code is compiled and shimmed to avoid direct call of Node.js libraries. compile.js takes care of compilation process using Browserify.
yarn build
