@piggydoughnut/bitgo-komodo-cc-lib

0.1.10 • Public • Published

BitGo-utxo with Komodo Antara (Cryptoconditions) Support

A fork from BitGo javascript library bitgo-utxo-lib.
A javascript Bitcoin library for node.js and browsers. Written mostly in javascript, with the cryptoconditions (cc) library written in rust and built as a wasm module.
Added support for komodo messages including nSPV protocol and cc features along with the cryptoconditions lib (as a wasm module).
Komodo Antara (Cryptoconditions, CC) technology allows to create complex multisignature transactions and add custom consensus code to komodo based assets chains.
This javascript library allows to develop SPV clients using Antara (CC) technology.
More info: Antara Development Docs

Released under the terms of the MIT LICENSE.

Prerequisites

You need installed:

  • nodejs v.12+
  • rust and
  • wasm-pack, both to build wasm cryptoconditions module

If you are going to use this lib in browser you also need:

  • browserify package
  • a webserver app (for example, webpack dev server)
  • a wsproxy app (for example, webcoin-bridge)

What test app does

In the samples folder are included a several examples of CC usage.

  1. ccfaucetpoc.js file that allows to create cc faucet create and get transactions.
  2. cctokenstokelv2poc.js example of how to run tokensv2 cc functions

To test this you need a komodod chain with cc modules enabled (Note about the correct komodod repo with an nspv patch, see below)

Installation

Clone this git repository go to the new dir and checkout dev-kmd branch.

Install the bitgo-komodo-cc-lib dependency packages, inside the repo dir run:

npm install

You'll need a komodo asset chain to bitgo lib against. Pick a file from samples folder to work with.

  1. Setup network parameters for your komodo chain:

    Open config folder and rename index.sample.js to index.js and chage yourchainname and magic params for your chain.

  2. In the sample of your choice change mynetwork var to some yourchainname:

    const mynetwork = networks.yourchainname
    
  3. ccfaucetpoc.js -Set your funding faucet wif and address and a wif and address getting funds in ccfaucetpoc.js (set vars faucetcreatewif, faucetcreateaddress, faucetgetwif, faucetgetaddress).

    cctokenstokelv2poc.js - set values between comments in the sample file

Build test app to run in nodejs

Build the cryptoconditions wasm module:
Setup the rust nightly build to build cryptoconditions:

rustup toolchain install nightly
rustup default nightly

Change to cryptoconditions-js directory and build the cryptoconditions wasm module for nodejs target:

cd ./node_modules/cryptoconditions-js
wasm-pack build -t nodejs

Run the testapp in nodejs:

node ./ccfaucetpoc.js

How to use the test app in the browser:

To run the test app in the browser you will need a webserver to host an html sample page and the test app ccfaucetpocbr.js. Also you need a websocket proxy to convert websockets into nspv p2p protocol.

Setting up a web server

I use the webpack dev server running in nodejs.
To setup a webpack sample config make a dir like 'webpack' and create inside it two files with the following content:

package.json:

{
  "scripts": {
    "serve": "webpack-dev-server"
  },
  "dependencies": {
    "cryptoconditions-js": "git+https://github.com/dimxy/cryptoconditions-js.git#master"
  },
  "devDependencies": {
    "webpack": "^4.44.2",
    "webpack-cli": "^3.3.12",
    "webpack-dev-server": "^3.11.0"
  }
}

webpack.config.js:

const path = require('path');
module.exports = {
  entry: "./ccfaucetpocbr.js",
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "ccfaucetpocbr-bundle.js",
    library: 'myLibrary'
  },
  mode: "development",
  //to serve from any external address (do not add this devServer config to serve only locally):
  devServer: {
    port: 8080,
    host: '0.0.0.0'
  }
};

(Both those package.json and webpack.config.js files may be found in webpack-test subdir of bitgo-komodo-cc-lib dir) Inside the webpack dir run:

npm install

(ignore printed errors)

Set again the nightly rust version for this repo:

rustup default nightly

Change to ./node_modules/cryptoconditions-js subdir and run the following command to build cryptconditions lib wasm for browserify.

cd ./node_modules/cryptoconditions-js
wasm-pack build

Now go to bitgo-komodo-cc-lib repo dir.
Rebuild sources and build the test app for browser:

npm run build
browserify ./samples/ccfaucetpoc.js --standalone faucet -o ccfaucetpocbr.js

Copy created ccfaucetpocbr.js into your webpack dir. Copy the example of an index.html page from the webpack-test dir to your webpack dir. Inside your webpack dir run the web server with a command:

npm run serve

The web server should be available at http://localhost:8080 url (if you installed the webpack on the same PC).

Use the correct komodod version

The last thing is to make sure you run a komodod version with an extension to nSPV getutxos call (it should additionally return script for each utxo).
Use this komodod branch for this: https://github.com/dimxy/komodo/tree/nspv-utxo-ext

I recommed to run komodod with -debug=net to easily discover wrong magic errors and observe communication dynamic. Basically komodod should print ver/verack and ping/pong exchanges in the debug.log, if connection is okay

What should happen in the test

When you run the chain, webpack and webcoin-bridge, you might go to the test page url in browser (http://localhost:8080).
It allows first to connect to a peer and then create cc faucet transactions.

Info about new and updated packages

Some dependent packages were modified to add support for komodo:

  • bitcoin-protocol

Links to these packages in package.json are updated to load them from forked github repositories (see package.json).

Also added a new package cryptoconditions-js link that currently is loaded from a github repo.

Original Bitgo-utxo-lib readme

Read the original readme here.

LICENSE MIT

Package Sidebar

Install

npm i @piggydoughnut/bitgo-komodo-cc-lib

Weekly Downloads

1

Version

0.1.10

License

MIT

Unpacked Size

259 kB

Total Files

60

Last publish

Collaborators

  • piggydoughnut