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.
Dependencies
Installation
npm i --save bandprotocol
Basic Usage
const client = httpEndpoint: 'http://localhost:26657' keyProvider: secretKey
Key Generation
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
Transaction Generation
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.
// Initialize clientconst client = httpEndpoint: 'http://localhost:26657' keyProvider: '<secretKey>' // Generate unsigned transaction from nodeconst unsignedTx = await clientblockchain // Sign the transactionconst signedTx = clientkey // Broadcast the signed transactionconst result = await clientblockchain
Encrypted Secret Key (SecretBox)
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:
const passcode = '<some_user_defined_passcode>'const client = keyProvider: '<secretKey>' const secretbox = client
To restore client instance and secret key:
const client = keyProvider: secretbox: '<encrypted_secretbox>' passcode: '<user_passcode>' const secretKey = client
Development
Make sure you have Node.js v8+ installed. Then run:
yarn install
Test
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
Build
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