Git Product home page Git Product logo

boa-sdk-ts's Introduction

boa-sdk-ts

SDK to interface with the BOSAGORA blockchain boa-sdk-ts is a TypeScript/JavaScript library for communicating with the Stoa API server. It also has utility functions such as hashing and pre-image validation.

Install

$ npm install --save boa-sdk-ts

Import the your library

import * as BoaSdk from "boa-sdk-ts";

Usage

TypeScript

// Create BOA Client
let boa_client = new BoaSdk.BOAClient("http://localhost:3836");

// Query
boa_client.getValidator("GA3DMXTREDC4AIUTHRFIXCKWKF7BDIXRWM2KLV74OPK2OKDM2VJ235GN", 10)
.then((validators: Array<BoaSdk.Validator>) =>
{
    // On Success
})
.catch((err: any) =>
{
    // On Error
});

In Browser

<script type="text/javascript" src="boa-sdk.js"></script>
<script>
    BoaSdk.SodiumHelper.init()
        .then(function()
        {
            console.log("[Test for Hash]");
            var hash_abc = BoaSdk.hash(Uint8Array.fromString('abc'));
            console.assert(hash_abc.toString() === '0x239900d4ed8623b95a92f1dba8' +
                                        '8ad31895cc3345ded552c22d79ab' +
                                        '2a39c5877dd1a2ffdb6fbb124bb7' +
                                        'c45a68142f214ce9f6129fb69727' +
                                        '6a0d4d1c983fa580ba');

            console.log("[Test for KeyPair.fromSeed]");
            var address =
                'GDD5RFGBIUAFCOXQA246BOUPHCK7ZL2NSHDU7DVAPNPTJJKVPJMNLQFW';
            var seed =
                `SBBUWIMSX5VL4KVFKY44GF6Q6R5LS2Z5B7CTAZBNCNPLS4UKFVDXC7TQ`;
            var kp = BoaSdk.KeyPair.fromSeed(BoaSdk.Seed.fromString(seed));
            console.assert(kp.address.toString() === address);
            var signature = kp.secret.sign(Uint8Array.fromString('Hello World'));
            console.assert(kp.address.verify(signature, Uint8Array.fromString('Hello World')));

            console.log("[Test for KeyPair.random]");
            var random_kp = BoaSdk.KeyPair.random();
            var random_kp_signature = random_kp.secret.sign(Uint8Array.fromString('Hello World'));
            console.assert(random_kp.address.verify(random_kp_signature, Uint8Array.fromString('Hello World')));
        });

    Uint8Array.fromString = function (str)
    {
        for (var arr = [], i = 0; i < str.length; i++)
            arr.push(str.charCodeAt(i));
        return new Uint8Array(arr);
    };
</script>

Documentation

BOA-SDK for TypeScript documentation

Testing

$ git clone https://github.com/bosagora/boa-sdk-ts.git
$ npm install
$ npm run build
$ npm test

boa-sdk-ts's People

Contributors

dependabot[bot] avatar geod24 avatar michaelkim20 avatar trusthenry avatar

Watchers

 avatar  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.