bandprotocol

0.5.11 • Public • Published

Band Protocol JS Library

Official Javascript Client for Band Chain

Code Style: prettier TypeScript MIT Licence Dependency Status devDependency Status

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

npm i --save bandprotocol

Basic Usage

import BandProtocolClient from 'bandprotocol'
import { secretKey } from './config'
 
const client = new BandProtocolClient({
  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.generateRandomKey()

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.

import BandProtocolClient from 'bandprotocol'
 
// Initialize client
const client = new BandProtocolClient({
  httpEndpoint: 'http://localhost:26657',
  keyProvider: '<secretKey>',
})
 
// Generate unsigned transaction from node
const unsignedTx = await client.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 transaction
const signedTx = client.key.sign(unsignedTx)
 
// Broadcast the signed transaction
const result = await client.blockchain.broadcastTxn(signedTx)

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 = new BandProtocolClient({ keyProvider: '<secretKey>' })
 
const secretbox = client.encrypt(passcode)

To restore client instance and secret key:

const client = new BandProtocolClient({
  keyProvider: {
    secretbox: '<encrypted_secretbox>',
    passcode: '<user_passcode>',
  },
})
 
const secretKey = client.getSecretKey()

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

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i bandprotocol

Weekly Downloads

77

Version

0.5.11

License

MIT

Unpacked Size

1.02 MB

Total Files

8

Last publish

Collaborators

  • smiled0g
  • classboxdev
  • norulex