add documentations, jsdoc

This commit is contained in:
Matias Alejo Garcia 2016-03-28 17:07:13 -03:00
parent e2aad8c200
commit 2996e9b60f
No known key found for this signature in database
GPG Key ID: 02470DB551277AB3
5 changed files with 1072 additions and 232 deletions

View File

@ -2,30 +2,9 @@ module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jsdox: {
generate: {
options: {
contentsEnabled: true,
contentsTitle: 'Bitcore Wallet Client Documentation',
contentsFile: 'readme.md'
},
src: ['lib/*.js'],
dest: 'docs'
},
publish: {
enabled: true,
path: '.',
message: 'Markdown Auto-Generated for version <%= pkg.version %>',
remoteName: 'b',
remoteBranch: 'gh-pages2'
}
}
pkg: grunt.file.readJSON('package.json')
});
grunt.loadNpmTasks('grunt-jsdox');
// Default task(s).
grunt.registerTask('default', []);
};

View File

137
README.header.md Normal file
View File

@ -0,0 +1,137 @@
# bitcore-wallet-client
[![NPM Package](https://img.shields.io/npm/v/bitcore-wallet-client.svg?style=flat-square)](https://www.npmjs.org/package/bitcore-wallet-client)
[![Build Status](https://img.shields.io/travis/bitpay/bitcore-wallet-client.svg?branch=master&style=flat-square)](https://travis-ci.org/bitpay/bitcore-wallet-client)
[![Coverage Status](https://coveralls.io/repos/bitpay/bitcore-wallet-client/badge.svg)](https://coveralls.io/r/bitpay/bitcore-wallet-client)
The *official* client library for [bitcore-wallet-service] (https://github.com/bitpay/bitcore-wallet-service).
## Description
This package communicates with BWS [Bitcore wallet service](https://github.com/bitpay/bitcore-wallet-service) using the REST API. All REST endpoints are wrapped as simple async methods. All relevant responses from BWS are checked independently by the peers, thus the importance of using this library when talking to a third party BWS instance.
See [Bitcore-wallet] (https://github.com/bitpay/bitcore-wallet) for a simple CLI wallet implementation that relays on BWS and uses bitcore-wallet-client.
## Get Started
You can start using bitcore-wallet-client in any of these two ways:
* via [Bower](http://bower.io/): by running `bower install bitcore-wallet-client` from your console
* or via [NPM](https://www.npmjs.com/package/bitcore-wallet-client): by running `npm install bitcore-wallet-client` from your console.
## Example
Start your own local [Bitcore wallet service](https://github.com/bitpay/bitcore-wallet-service) instance. In this example we assume you have `bitcore-wallet-service` running on your `localhost:3232`.
Then create two files `irene.js` and `tomas.js` with the content below:
**irene.js**
``` javascript
var Client = require('bitcore-wallet-client');
var fs = require('fs');
var BWS_INSTANCE_URL = 'https://bws.bitpay.com/bws/api'
var client = new Client({
baseUrl: BWS_INSTANCE_URL,
verbose: false,
});
client.createWallet("My Wallet", "Irene", 2, 2, {network: 'testnet'}, function(err, secret) {
if (err) {
console.log('error: ',err);
return
};
// Handle err
console.log('Wallet Created. Share this secret with your copayers: ' + secret);
fs.writeFileSync('irene.dat', client.export());
});
```
**tomas.js**
``` javascript
var Client = require('bitcore-wallet-client');
var fs = require('fs');
var BWS_INSTANCE_URL = 'https://bws.bitpay.com/bws/api'
var secret = process.argv[2];
if (!secret) {
console.log('./tomas.js <Secret>')
process.exit(0);
}
var client = new Client({
baseUrl: BWS_INSTANCE_URL,
verbose: false,
});
client.joinWallet(secret, "Tomas", {}, function(err, wallet) {
if (err) {
console.log('error: ', err);
return
};
console.log('Joined ' + wallet.name + '!');
fs.writeFileSync('tomas.dat', client.export());
client.openWallet(function(err, ret) {
if (err) {
console.log('error: ', err);
return
};
console.log('\n\n** Wallet Info', ret); //TODO
console.log('\n\nCreating first address:', ret); //TODO
if (ret.wallet.status == 'complete') {
client.createAddress({}, function(err,addr){
if (err) {
console.log('error: ', err);
return;
};
console.log('\nReturn:', addr)
});
}
});
});
```
Install `bitcore-wallet-client` before start:
```
npm i bitcore-wallet-client
```
Create a new wallet with the first script:
```
$ node irene.js
info Generating new keys
Wallet Created. Share this secret with your copayers: JbTDjtUkvWS4c3mgAtJf4zKyRGzdQzZacfx2S7gRqPLcbeAWaSDEnazFJF6mKbzBvY1ZRwZCbvT
```
Join to this wallet with generated secret:
```
$ node tomas.js JbTDjtUkvWS4c3mgAtJf4zKyRGzdQzZacfx2S7gRqPLcbeAWaSDEnazFJF6mKbzBvY1ZRwZCbvT
Joined My Wallet!
Wallet Info: [...]
Creating first address:
Return: [...]
```
Note that the scripts created two files named `irene.dat` and `tomas.dat`. With these files you can get status, generate addresses, create proposals, sign transactions, etc.

1141
README.md

File diff suppressed because it is too large Load Diff

View File

@ -55,7 +55,8 @@
"start": "node app.js",
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --reporter spec test",
"test": "./node_modules/.bin/mocha",
"coveralls": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
"coveralls": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
"docs": "./node_modules/.bin/jsdox lib/* lib/common lib/errors -o docs && cat README.header.md docs/*.md LICENSE > README.md"
},
"contributors": [
{