Remove globals

This commit is contained in:
Esteban Ordano 2014-12-16 17:06:01 -03:00
parent 4433bd422b
commit d4b8c4adc6
18 changed files with 166 additions and 56 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

36
.jsdoc.conf Normal file
View File

@ -0,0 +1,36 @@
{
"tags": {
"allowUnknownTags": true
},
"source": {
"include": ["docs/README.md"],
"exclude": [],
"includePattern": "lib/.+\\.js(doc)?$",
"excludePattern": "(^|\\/|\\\\)_"
},
"plugins": ["plugins/markdown"],
"templates": {
"cleverLinks": false,
"monospaceLinks": false
},
"opts": {
"template": "node_modules/ink-docstrap/template",
"encoding": "utf8",
"destination": "./apiref/",
"recurse": true,
"query": "value",
"private": true,
"lenient": true
},
"templates": {
"systemName": "bitcore",
"copyright": "© 2013-2014, BitPay Inc.",
"navType": "vertical",
"theme": "journal",
"linenums": true,
"collapseSymbols": false,
"inverseNav": false,
"outputSourceFiles": true
}
}

BIN
apiref.zip Normal file

Binary file not shown.

View File

@ -120,26 +120,12 @@ gulp.task('lint', function() {
.pipe(jshint.reporter('default'));
});
gulp.task('plato', shell.task[
'plato -d report -r -l .jshintrc -t bitcore lib'
]);
gulp.task('plato', shell.task['plato -d report -r -l .jshintrc -t bitcore lib']);
gulp.task('jsdoc', shell.task['jsdoc -c .jsdoc.conf lib']);
gulp.task('coverage', shell.task(['istanbul cover _mocha -- --recursive']));
gulp.task('jsdoc', function() {
return gulp.src(files.concat([jsdocReadme]))
.pipe(jsdoc.parser({
name: 'bitcore',
version: '0.8.0',
description: 'API Reference for the bitcore bitcoin javascript library',
plugins: ['plugins/markdown']
}))
.pipe(jsdoc.generator('./apiref', {
path: 'ink-docstrap',
theme: 'journal'
}));
});
/**
* Watch tasks
*/
@ -189,7 +175,7 @@ gulp.task('watch:browser', function() {
*/
gulp.task('default', function(callback) {
return runSequence(['lint', 'jsdoc'],
['browser:compressed', 'test'],
['coverage', 'minify'],
['browser:uncompressed', 'test'],
['coverage', 'browser:compressed'],
callback);
});

View File

@ -20,16 +20,12 @@ bitcore.encoding.Varint = require('./lib/encoding/varint');
// utilities
bitcore.util = {};
bitcore.util.bitcoin = require('./lib/util/bitcoin');
bitcore.util.buffer = require('./lib/util/buffer');
bitcore.util.js = require('./lib/util/js');
bitcore.util.preconditions = require('./lib/util/preconditions');
// transport
bitcore.transport = {};
bitcore.transport.Peer = require('./lib/transport/peer');
bitcore.transport.Messages = require('./lib/transport/messages');
bitcore.transport.Pool = require('./lib/transport/pool');
bitcore.transport = require('./lib/transport');
// errors thrown by the library
bitcore.errors = require('./lib/errors');

View File

@ -12,6 +12,7 @@ var Transaction = require('./transaction');
var Varint = require('./encoding/varint');
/**
* @class Block
* Instantiate a Block from a Buffer, JSON object, or Object with
* the properties of the Block
*
@ -42,10 +43,26 @@ Block._from = function _from(arg) {
info = Block._fromJSON(arg);
} else if (_.isObject(arg)) {
info = {
/**
* @name Block#magicnum
* @type number
*/
magicnum: arg.magicnum,
/**
* @name Block#blocksize
* @type number
*/
blocksize: arg.blocksize,
/**
* @name Block#blockheader
* @type {BlockHeader}
*/
blockheader: arg.blockheader,
txsvi: arg.txsvi,
/**
* @name Block#txs
* @type {Transaction[]}
*/
txs: arg.txs
};
} else {
@ -59,18 +76,35 @@ Block._from = function _from(arg) {
* easier access
*/
Block.prototype._setupProperties = function() {
/**
* @name Block#version
* @type {number}
*/
Object.defineProperty(this, 'version', {
configurable: false,
value: this.blockheader.version
});
/**
* @name Block#timestamp
* @type {number}
*/
Object.defineProperty(this, 'timestamp', {
configurable: false,
value: this.blockheader.timestamp
});
/**
* @name Block#nonce
* @type {number}
*/
Object.defineProperty(this, 'nonce', {
configurable: false,
value: this.blockheader.nonce
});
/**
* Amount of bytes of the serialized block
* @name Block#size
* @type {number}
*/
Object.defineProperty(this, 'size', {
configurable: false,
value: this.blockheader.size

View File

@ -35,7 +35,7 @@ var traverseRoot = function(errorsDefinition) {
var fullName = 'bitcore.Error';
var path = 'Error';
var generated = '\'use strict\';\n\nvar inherits = require(\'inherits\');\n\n';
generated += '/** AUTOGENERATED FILE. DON\'T EDIT, MODIFY "lib/errors/spec.js" INSTEAD */\n\n';
generated += '/* AUTOGENERATED FILE. DON\'T EDIT, MODIFY "lib/errors/spec.js" INSTEAD */\n\n';
generated += 'var bitcore = {};\n\n';
generated += defineElement(fullName, path, '\'Internal error\'');
generated += childDefinitions(fullName, errorsDefinition);

View File

@ -12,6 +12,9 @@ var Signature = require('../../crypto/signature');
var Sighash = require('../sighash');
var BufferUtil = require('../../util/buffer');
/**
* @constructor
*/
function MultiSigScriptHashInput(input, pubkeys, threshold) {
Input.apply(this, arguments);
var self = this;

View File

@ -14,6 +14,7 @@ var Signature = require('../../crypto/signature');
/**
* Represents a special kind of input of PayToPublicKeyHash kind.
* @constructor
*/
function PublicKeyHashInput() {
Input.apply(this, arguments);

View File

@ -19,6 +19,7 @@ var BITS_64_ON = 'ffffffffffffffff';
* Returns a buffer of length 32 bytes with the hash that needs to be signed
* for OP_CHECKSIG.
*
* @name Signing.sighash
* @param {Transaction} transaction the transaction to sign
* @param {number} sighashType the type of the hash
* @param {number} inputNumber the input index for the signature
@ -90,21 +91,46 @@ var sighash = function sighash(transaction, sighashType, inputNumber, subscript)
return ret;
};
var sign = function sign(transaction, keypair, nhashtype, nin, subscript) {
var hashbuf = sighash(transaction, nhashtype, nin, subscript);
var sig = ECDSA.sign(hashbuf, keypair, 'little').set({
nhashtype: nhashtype
/**
* Create a signature
*
* @name Signing.sign
* @param {Transaction} transaction
* @param {PrivateKey} privateKey
* @param {number} sighash
* @param {number} inputIndex
* @param {Script} subscript
* @return {Signature}
*/
function sign(transaction, privateKey, sighashType, inputIndex, subscript) {
var hashbuf = sighash(transaction, sighashType, inputIndex, subscript);
var sig = ECDSA.sign(hashbuf, privateKey, 'little').set({
nhashtype: sighashType
});
return sig;
};
}
var verify = function verify(transaction, sig, pubkey, nin, subscript) {
/**
* Verify a signature
*
* @name Signing.verify
* @param {Transaction} transaction
* @param {Signature} signature
* @param {PublicKey} publicKey
* @param {number} inputIndex
* @param {Script} subscript
* @return {boolean}
*/
function verify(transaction, signature, publicKey, inputIndex, subscript) {
$.checkArgument(transaction);
$.checkArgument(sig && sig.nhashtype);
var hashbuf = sighash(transaction, sig.nhashtype, nin, subscript);
return ECDSA.verify(hashbuf, sig, pubkey, 'little');
};
$.checkArgument(signature && signature.nhashtype);
var hashbuf = sighash(transaction, signature.nhashtype, inputIndex, subscript);
return ECDSA.verify(hashbuf, signature, publicKey, 'little');
}
/**
* @namespace Signing
*/
module.exports = {
sighash: sighash,
sign: sign,

View File

@ -31,6 +31,7 @@ var DEFAULT_SEQNUMBER = 0xFFFFFFFF;
* ownership of tokens
*
* @param {*} serialized
* @constructor
*/
function Transaction(serialized) {
if (!(this instanceof Transaction)) {

8
lib/transport/index.js Normal file
View File

@ -0,0 +1,8 @@
/**
* @namespace Transport
*/
module.exports = {
Peer: require('./peer'),
Messages: require('./messages'),
Pool: require('./pool')
};

View File

@ -1,4 +1,7 @@
'use strict';
/**
* @namespace Transport.Message
*/
/* jshint curly: false */
var Buffers = require('buffers');
@ -19,6 +22,7 @@ var PROTOCOL_VERSION = 70000;
/**
* Static helper for consuming a data buffer until the next message.
*
* @name Transport.Message#parseMessage
* @param{Network} network - the network object
* @param{Buffer} dataBuffer - the buffer to read from
* @returns{Message|undefined} A message or undefined if there is nothing to read.
@ -55,7 +59,8 @@ var parseMessage = function(network, dataBuffer) {
module.exports.parseMessage = parseMessage;
/**
* Internal function that discards data until founds the next message.
* @desc Internal function that discards data until founds the next message.
* @name Transport.Message#discardUntilNextMessage
*/
function discardUntilNextMessage(network, dataBuffer) {
var magicNumber = network.networkMagic;
@ -82,11 +87,20 @@ function discardUntilNextMessage(network, dataBuffer) {
/**
* Abstract Message that knows how to parse and serialize itself.
* Concret subclases should implement {fromBuffer} and {getPayload} methods.
* @name Transport.Message
*/
function Message() {}
/**
* @value
* @name Transport.Message.COMMANDS
*/
Message.COMMANDS = {};
/**
* Look up a message type by command name and instantiate the correct Message
* @name Transport.Message#buildMessage
*/
Message.buildMessage = function(command, payload) {
try {
var CommandClass = Message.COMMANDS[command];
@ -146,6 +160,7 @@ Message.prototype.serialize = function(network) {
/**
* Version Message
*
* @name Transport.Message.Version
* @param{string} subversion - version of the client
* @param{Buffer} nonce - a random 8 bytes buffer
*/
@ -191,6 +206,7 @@ module.exports.Version = Message.COMMANDS.version = Version;
/**
* Inv Message
*
* @name Transport.Message.Inventory
* @param{Array} inventory - reported elements
*/
function Inventory(inventory) {
@ -229,6 +245,7 @@ module.exports.Inventory = Message.COMMANDS.inv = Inventory;
/**
* Getdata Message
*
* @name Transport.Message.GetData
* @param{Array} inventory - requested elements
*/
function GetData(inventory) {
@ -242,6 +259,7 @@ module.exports.GetData = GetData;
/**
* Ping Message
*
* @name Transport.Message.Ping
* @param{Buffer} nonce - a random 8 bytes buffer
*/
function Ping(nonce) {
@ -264,6 +282,7 @@ module.exports.Ping = Message.COMMANDS.ping = Ping;
/**
* Pong Message
*
* @name Transport.Message.Pong
* @param{Buffer} nonce - a random 8 bytes buffer
*/
function Pong(nonce) {
@ -277,6 +296,7 @@ module.exports.Pong = Message.COMMANDS.pong = Pong;
/**
* Addr Message
*
* @name Transport.Message.Addressess
* @param{Array} addresses - array of know addresses
*/
function Addresses(addresses) {
@ -342,6 +362,7 @@ module.exports.Addresses = Message.COMMANDS.addr = Addresses;
/**
* GetAddr Message
*
* @name Transport.Message.GetAddresses
*/
function GetAddresses() {
this.command = 'getaddr';
@ -353,6 +374,7 @@ module.exports.GetAddresses = Message.COMMANDS.getaddr = GetAddresses;
/**
* Verack Message
*
* @name Transport.Message.VerAck
*/
function VerAck() {
this.command = 'verack';
@ -364,6 +386,7 @@ module.exports.VerAck = Message.COMMANDS.verack = VerAck;
/**
* Reject Message
*
* @name Transport.Message.Reject
*/
function Reject() {
this.command = 'reject';
@ -377,6 +400,7 @@ module.exports.Reject = Message.COMMANDS.reject = Reject;
/**
* Alert Message
*
* @name Transport.Message.Alert
*/
function Alert(payload, signature) {
this.command = 'alert';
@ -408,6 +432,7 @@ module.exports.Alert = Message.COMMANDS.alert = Alert;
/**
* Headers Message
*
* @name Transport.Message.Headers
* @param{Array} blockheaders - array of block headers
*/
function Headers(blockheaders) {
@ -446,6 +471,7 @@ module.exports.Headers = Message.COMMANDS.headers = Headers;
/**
* Block Message
*
* @name Transport.Message.Block
* @param{Block} block
*/
function Block(block) {
@ -468,6 +494,7 @@ module.exports.Block = Message.COMMANDS.block = Block;
/**
* Tx Message
*
* @name Transport.Message.Transaction
* @param{Transaction} transaction
*/
function Transaction(transaction) {
@ -490,6 +517,7 @@ module.exports.Transaction = Message.COMMANDS.tx = Transaction;
/**
* Getblocks Message
*
* @name Transport.Message.GetBlocks
* @param{Array} starts - array of buffers with the starting block hashes
* @param{Buffer} [stop] - hash of the last block
*/
@ -540,6 +568,7 @@ module.exports.GetBlocks = Message.COMMANDS.getblocks = GetBlocks;
/**
* Getheaders Message
*
* @name Transport.Message.GetHeaders
* @param{Array} starts - array of buffers with the starting block hashes
* @param{Buffer} [stop] - hash of the last block
*/

View File

@ -22,8 +22,8 @@ var JSUtil = require('./util/js');
* @param {Number} amount - The amount to be represented
* @param {String} code - The unit of the amount
* @returns {Unit} A new instance of an Unit
* @constructor
*/
function Unit(amount, code) {
if (!(this instanceof Unit)) {
return new Unit(amount, code);

View File

@ -29,6 +29,7 @@ var JSUtil = require('./util/js');
* @throws {TypeError} Invalid amount
* @throws {Error} Unknown required argument
* @returns {URI} A new valid and frozen instance of URI
* @constructor
*/
var URI = function(data, knownParams) {
this.extras = {};

View File

@ -1,18 +0,0 @@
/**
* @file util/bitcoin.js
* Contains utilities to handle magnitudes inside of bitcoin
*/
'use strict';
var SATOSHIS_PER_BTC = 1e8;
module.exports = {
/**
* @param number satoshis - amount of satoshis to convert
* @return string an exact representation of such amount, in form of a string
* (avoids duplicate representations in ieee756 of the same number)
*/
satoshisToBitcoin: function(satoshis) {
return satoshis / SATOSHIS_PER_BTC;
}
};

View File

@ -5,6 +5,7 @@ var _ = require('lodash');
/**
* Determines whether a string contains only hexadecimal values
*
* @name JSUtil.isHexa
* @param {string} value
* @return {boolean} true if the string is the hexa representation of a number
*/
@ -15,6 +16,9 @@ var isHexa = function isHexa(value) {
return /^[0-9a-fA-F]+$/.test(value);
};
/**
* @namespace JSUtil
*/
module.exports = {
/**
* Test if an argument is a valid JSON object. If it is, returns a truthy

View File

@ -6,7 +6,7 @@
"main": "index.js",
"scripts": {
"lint": "gulp lint",
"test": "gulp test-all",
"test": "gulp test",
"coverage": "gulp coverage",
"build": "gulp",
"postinstall": "node ./lib/errors/build.js"
@ -79,8 +79,11 @@
"elliptic": "=0.15.14",
"hash.js": "=0.3.2",
"inherits": "=2.0.1",
"ink-docstrap": "^0.4.12",
"jsdoc": "^3.3.0-alpha11",
"jsrsasign": "=0.0.3",
"lodash": "=2.4.1",
"plato": "^1.3.0",
"protobufjs": "=3.0.0",
"sha512": "=0.0.1",
"socks5-client": "^0.3.6"