Git Product home page Git Product logo

cyphernode-js-sdk's Introduction

An Isomorphic Javascript SDK for Bitcoin, C-lightning and Opentimestamp Vis-à-vis CypherNode.

Why ?

Cyphernode simplifies to a large extent the historically cumbersome process for an individual to run a full-node and thus participate in the Bitcoin value network. The aim of the SDK is to further help access by bridging the gap between the "systems software" technological stack and the "product space" where product developers can start easily building apps for the future.

This SDK aims to abstract complications and offer a clean and friendly way to access the value proposition these systems offer with a value add of a modular transport.

Usage,Tests and Examples

Requirements

  1. You need to have Cyphernode running on an HTTP accessible PC
  2. You must have a valid Cyphernode admin api key to run the tests and you must pass the key to the SDK tests. The easiest way to do so is using environment variables. Make sure the following enviroment variables are set when using the sdk:
CYPHERNODE_API_KEY=
CYPHER_GATEWAY_URL=https://localhost:2009/v0/

Example using the BTC client:

const {btcClient} = require('cyphernode-js-sdk');
const client = btcClient();
const balance = client.getBalance();
console.log(`Your balance is ${balance} bitcoins`);

Example using the Lightining client:

const {lnClient} = require('cyphernode-js-sdk');
const client = lnClient();
const makeInvoicePayload = {
   msatoshi: 10,
   label: "much-ease-invoice",
   description: "This rocks",
   expiry: 900,
   callback_url: "http://url.to/call/when/invoice/paid"
 };
const invoice = await createInvoice(makeInvoicePayload);
// Show qrCode(invoice)

Documentation of this SDK is WIP in the meantime client tests serve as 'how-to' examples. Futhermore the SDK is written in typescript which should help give a better understanding of parameters and return types for the functions being called.

Transport Stacks

This SDK ships with a default HTTP transport stack, IE it will forward all your requests to the cyphernode endpoint via 'regular' GET and POST http requests. The HTTP transport stack is automatically initilaized by default when a client is instantiated and uses the isomorphic package 'superagent' to send HTTP requests and is in fact the only depedency this sdk has. This is in the name of ease of use for both node and browser users.

You can easily drop that dependancy from the sdk by modifiying ./transports/cypherNodeHTTPTransport.ts (or creating a new one in our transports repo !).

Distritbued and custom transports

A big part of this SDK seeks to help integrate Bitcoin into other communication protocols via the notion of transport architecture. Please check the Cyphernode transport repo for more information on how to reach your Cyphernode via different communication protocols

Client Tests

/clients/

Contains the individual clients that can be instaniated to access each of Cyphernode's services, at this time these are:

  • btcClient.js : All things bitcoin
  • lncClient.js : All things lighting
  • otsClient.js : (WIP) All this opentimestamp

Test files for each client are included that showcase the usage of functionality

Client test requirements and steps:

  1. All tests need to have Cyphernode running on your PC
  2. You must have a valid Cyphernode admin api key to run the tests and you must pass the key to the SDK tests. The easiest way to do so is using environment variables. Simply create a
.env

file in the root directory of this repo and add the following enviroment variables:

CYPHERNODE_API_KEY=
CYPHER_GATEWAY_URL=https://localhost:2009/v0/

then run

yarn test:clients

TODOs

  1. JSDoc this puppy
  2. Test coverage for all functions
  3. Fix OTS functions
  4. Add remaining LN functions
  5. Add link to MVP app

cyphernode-js-sdk's People

Contributors

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