GithubHelp home page GithubHelp logo

btcarver / bitsharesjs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bitshares/bitsharesjs

0.0 1.0 0.0 12.11 MB

JavaScript tools for BitShares Encryption and Serialization

Home Page: https://bitsharesjs.bitshares.org/

License: MIT License

JavaScript 99.97% Shell 0.03%

bitsharesjs's Introduction

BitsharesJS (bitsharesjs)

Pure JavaScript Bitshares library for node.js and browsers. Can be used to construct, sign and broadcast transactions in JavaScript, and to easily obtain data from the blockchain via public apis.

Most of this code was written by jcalfee, my work was mostly just repackaging to a discrete npm package.

npm version npm downloads

Setup

This library can be obtained through npm:

npm install bitsharesjs

Usage

Three sub-libraries are included: ECC, Chain and Serializer. Generally only the ECC and Chain libraries need to be used directly.

Chain

This library provides utility functions to handle blockchain state as well as a login class that can be used for simple login functionality using a specific key seed.

Login

The login class uses the following format for keys:

keySeed = accountName + role + password

Using this seed, private keys are generated for either the default roles active, owner, memo, or as specified. A minimum password length of 12 characters is enforced, but an even longer password is recommended. Three methods are provided:

generateKeys(account, password, [roles])
checkKeys(account, password, auths)
signTransaction(tr)

The auths object should contain the auth arrays from the account object. An example is this:

{
    active: [
        ["GPH5Abm5dCdy3hJ1C5ckXkqUH2Me7dXqi9Y7yjn9ACaiSJ9h8r8mL", 1]
    ]
}

If checkKeys is successful, you can use signTransaction to sign a TransactionBuilder transaction using the private keys for that account.

State container

The Chain library contains a complete state container called the ChainStore. The ChainStore will automatically configure the set_subscribe_callback and handle any incoming state changes appropriately. It uses Immutable.js for storing the state, so all objects are return as immutable objects. It has its own subscribe method that can be used to register a callback that will be called whenever a state change happens.

The ChainStore has several useful methods to retrieve, among other things, objects, assets and accounts using either object ids or asset/account names. These methods are synchronous and will return undefined to indicate fetching in progress, and null to indicate that the object does not exist.

import {Apis} from "bitsharesjs-ws";
var {ChainStore} = require("bitsharesjs");

Apis.instance("wss://eu.nodes.bitshares.ws", true).init_promise.then((res) => {
    console.log("connected to:", res[0].network);
    ChainStore.init().then(() => {
        ChainStore.subscribe(updateState);
    });
});

let dynamicGlobal = null;
function updateState(object) {
    dynamicGlobal = ChainStore.getObject("2.1.0");
    console.log("ChainStore object update\n", dynamicGlobal ? dynamicGlobal.toJS() : dynamicGlobal);
}

ECC

The ECC library contains all the crypto functions for private and public keys as well as transaction creation/signing.

Private keys

As a quick example, here's how to generate a new private key from a seed (a brainkey for example):

var {PrivateKey, key} = require("bitsharesjs");

let seed = "THIS IS A TERRIBLE BRAINKEY SEED WORD SEQUENCE";
let pkey = PrivateKey.fromSeed( key.normalize_brainKey(seed) );

console.log("\nPrivate key:", pkey.toWif());
console.log("Public key :", pkey.toPublicKey().toString(), "\n");

Transactions

TODO transaction signing example

ESDoc (beta)

npm i -g esdoc esdoc-es7-plugin
esdoc -c ./esdoc.json
open out/esdoc/index.html

Binaries / Browserified bundles

Please have a look here to find your desired release. If you want to build the binaries yourself you can clone this repository and run npm install. It will create

  • Browserified version build/bitsharesjs.js
  • Browserified and minified (babel) version build/bitsharesjs.min.js
  • CommonJS version using webpack build/bitsharesjs.cjs

bitsharesjs's People

Contributors

abitmore avatar clockworkgr avatar destenson avatar dot5enko avatar fgdfkgndj avatar hldzlk avatar lanhaoxiang avatar pluswave avatar ppitonak avatar sschiessl-bcp avatar startailcoon avatar svk31 avatar verevkinalexander avatar vikramrajkumar avatar xeroc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.