docs: get jsdoc compiling again.
This commit is contained in:
parent
b4a21cad2d
commit
4e7df6ef87
2
LICENSE
2
LICENSE
@ -2,7 +2,7 @@ This software is licensed under the MIT License.
|
||||
|
||||
Copyright (c) 2014-2015, Fedor Indutny (https://github.com/indutny)
|
||||
|
||||
Copyright (c) 2014-2016, Christopher Jeffrey (https://github.com/chjj)
|
||||
Copyright (c) 2014-2017, Christopher Jeffrey (https://github.com/chjj)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
20
README.md
20
README.md
@ -31,7 +31,7 @@ $ npm install
|
||||
$ bcoin --fast
|
||||
```
|
||||
|
||||
Note that the latest BCoin has not been published to NPM yet, as it is still
|
||||
Note that the latest Bcoin has not been published to NPM yet, as it is still
|
||||
under fairly heavy development (which may involve changing serialization
|
||||
formats for the database).
|
||||
|
||||
@ -373,7 +373,7 @@ Normal transactions in bcoin are immutable. The primary TX object contains a
|
||||
bunch of consensus and policy checking methods. A lot of it is for internal use
|
||||
and pretty boring for users of this library.
|
||||
|
||||
BCoin also offers a mutable transaction object (MTX). Mutable transactions
|
||||
Bcoin also offers a mutable transaction object (MTX). Mutable transactions
|
||||
inherit from the TX object, but can also be signed and modified.
|
||||
|
||||
``` js
|
||||
@ -446,7 +446,7 @@ assert(tx.getFee(mtx.view) === 40000);
|
||||
|
||||
The above method works, but is pretty contrived. In reality, you probably
|
||||
wouldn't select inputs and calculate the fee by hand. You would want a
|
||||
change output added. BCoin has a nice method of dealing with this.
|
||||
change output added. Bcoin has a nice method of dealing with this.
|
||||
|
||||
Let's try it more realistically:
|
||||
|
||||
@ -575,7 +575,7 @@ output.execute(stack);
|
||||
|
||||
## Wallet usage
|
||||
|
||||
BCoin maintains a wallet database which contains every wallet. Wallets are _not
|
||||
Bcoin maintains a wallet database which contains every wallet. Wallets are _not
|
||||
usable_ without also using a wallet database. For testing, the wallet database
|
||||
can be in-memory, but it must be there.
|
||||
|
||||
@ -584,7 +584,7 @@ but support was removed to reduce code complexity, and also because bip45
|
||||
doesn't seem to add any benefit in practice.
|
||||
|
||||
The wallet database can contain many different wallets, with many different
|
||||
accounts, with many different addresses for each account. BCoin should
|
||||
accounts, with many different addresses for each account. Bcoin should
|
||||
theoretically be able to scale to hundreds of thousands of
|
||||
wallets/accounts/addresses.
|
||||
|
||||
@ -602,7 +602,7 @@ TODO
|
||||
|
||||
## Design
|
||||
|
||||
BCoin is thoroughly event driven. It has a fullnode object, but BCoin was
|
||||
Bcoin is thoroughly event driven. It has a fullnode object, but Bcoin was
|
||||
specifically designed so the mempool, blockchain, p2p pool, and wallet database
|
||||
could all be used separately. All the fullnode object does is tie these things
|
||||
together. It's essentially a huge proxying of events. The general communication
|
||||
@ -638,7 +638,7 @@ well-written.
|
||||
|
||||
#### Concurrency
|
||||
|
||||
BCoin runs in node.js, so the javascript code is limited to one thread. We
|
||||
Bcoin runs in node.js, so the javascript code is limited to one thread. We
|
||||
solve this limitation by spinning up persistent worker processes for
|
||||
transaction verification (webworkers when in the browser). This ensures the
|
||||
blockchain and mempool do not block the master process very much. It also means
|
||||
@ -652,7 +652,7 @@ data to another process.
|
||||
But of course, there is a benefit to having a multi-process architecture: the
|
||||
worker processes can die on their own without disturbing the master process.
|
||||
|
||||
BCoin uses [secp256k1-node][secp256k1-node] for ecdsa verification, which is a
|
||||
Bcoin uses [secp256k1-node][secp256k1-node] for ecdsa verification, which is a
|
||||
node.js binding to Pieter Wuille's blazingly fast [libsecp256k1][libsecp256k1]
|
||||
library.
|
||||
|
||||
@ -669,7 +669,7 @@ visiting a webpage.
|
||||
|
||||
## Disclaimer
|
||||
|
||||
BCoin does not guarantee you against theft or lost funds due to bugs, mishaps,
|
||||
Bcoin does not guarantee you against theft or lost funds due to bugs, mishaps,
|
||||
or your own incompetence. You and you alone are responsible for securing your
|
||||
money.
|
||||
|
||||
@ -683,7 +683,7 @@ all code is your original work. `</legalese>`
|
||||
|
||||
Copyright (c) 2014-2015, Fedor Indutny (MIT License).
|
||||
|
||||
Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
|
||||
See LICENSE for more info.
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ cmd='node'
|
||||
|
||||
if ! type perl > /dev/null 2>& 1; then
|
||||
if uname | grep -i 'darwin' > /dev/null; then
|
||||
echo 'BCoin requires perl to start.' >& 2
|
||||
echo 'Bcoin requires perl to start.' >& 2
|
||||
exit 1
|
||||
fi
|
||||
rl=1
|
||||
@ -51,7 +51,7 @@ done
|
||||
|
||||
if test $daemon -eq 1; then
|
||||
if ! type setsid > /dev/null 2>& 1; then
|
||||
echo 'BCoin requires setsid to start as a daemon.' >& 2
|
||||
echo 'Bcoin requires setsid to start as a daemon.' >& 2
|
||||
exit 1
|
||||
fi
|
||||
(
|
||||
|
||||
@ -72,7 +72,7 @@
|
||||
<script src="/bcoin.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>BCoin, the browser full node</h1>
|
||||
<h1>Bcoin, the browser full node</h1>
|
||||
<small>Welcome. Your machine is currently validating the blockchain.
|
||||
The blocks and wallet are stored on your local disk with indexed DB. You are
|
||||
connecting to the actual bitcoin P2P network via a websocket->tcp proxy.
|
||||
|
||||
24
lib/bcoin.js
24
lib/bcoin.js
@ -1,15 +1,23 @@
|
||||
/**
|
||||
* Javascript bitcoin library. Exposes the global environment.
|
||||
* @module bcoin
|
||||
* @see {Environment}
|
||||
* @license
|
||||
/*!
|
||||
* bcoin.js - a javascript bitcoin library.
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License).
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/indutny/bcoin
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Exposes the global environment.
|
||||
* An instance of {@link Environment}.
|
||||
* @module bcoin
|
||||
* @see {Environment}
|
||||
* @license
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/indutny/bcoin
|
||||
*/
|
||||
|
||||
var env = require('./env');
|
||||
var util = require('./utils/util');
|
||||
var global = util.global;
|
||||
@ -22,4 +30,8 @@ var global = util.global;
|
||||
if (util.isBrowser)
|
||||
global.bcoin = env;
|
||||
|
||||
/*
|
||||
* Expose
|
||||
*/
|
||||
|
||||
module.exports = env;
|
||||
|
||||
@ -1,11 +1,15 @@
|
||||
/*!
|
||||
* bip70.js - bip70 for bcoin
|
||||
* Copyright (c) 2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module bip70
|
||||
*/
|
||||
|
||||
exports.PaymentRequest = require('./paymentrequest');
|
||||
exports.PaymentDetails = require('./paymentdetails');
|
||||
exports.Payment = require('./payment');
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* payment.js - bip70 payment for bcoin
|
||||
* Copyright (c) 2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -17,6 +17,7 @@ var ProtoWriter = protobuf.ProtoWriter;
|
||||
|
||||
/**
|
||||
* Represents a BIP70 payment.
|
||||
* @alias module:bip70.Payment
|
||||
* @constructor
|
||||
* @param {Object?} options
|
||||
* @property {Buffer} merchantData
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* paymentack.js - bip70 paymentack for bcoin
|
||||
* Copyright (c) 2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -14,6 +14,8 @@ var ProtoWriter = protobuf.ProtoWriter;
|
||||
|
||||
/**
|
||||
* Represents a BIP70 payment ack.
|
||||
* @alias module:bip70.PaymentACK
|
||||
* @constructor
|
||||
* @param {Object?} options
|
||||
* @property {Payment} payment
|
||||
* @property {String|null} memo
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* paymentdetails.js - bip70 paymentdetails for bcoin
|
||||
* Copyright (c) 2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -15,6 +15,8 @@ var ProtoWriter = protobuf.ProtoWriter;
|
||||
|
||||
/**
|
||||
* Represents BIP70 payment details.
|
||||
* @alias module:bip70.PaymentDetails
|
||||
* @constructor
|
||||
* @param {Object?} options
|
||||
* @property {String|null} network
|
||||
* @property {Output[]} outputs
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* paymentrequest.js - bip70 paymentrequest for bcoin
|
||||
* Copyright (c) 2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -18,6 +18,8 @@ var ProtoWriter = protobuf.ProtoWriter;
|
||||
|
||||
/**
|
||||
* Represents a BIP70 payment request.
|
||||
* @alias module:bip70.PaymentRequest
|
||||
* @constructor
|
||||
* @param {Object?} options
|
||||
* @property {Number} version
|
||||
* @property {String|null} pkiType
|
||||
@ -332,6 +334,7 @@ PaymentRequest.prototype.getCA = function getCA() {
|
||||
/**
|
||||
* Algorithm
|
||||
* @constructor
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
function Algorithm(key, hash) {
|
||||
@ -342,6 +345,7 @@ function Algorithm(key, hash) {
|
||||
/**
|
||||
* CA
|
||||
* @constructor
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
function CA(root) {
|
||||
|
||||
@ -1,13 +1,27 @@
|
||||
/*!
|
||||
* pk.js - public key algorithms for bcoin
|
||||
* Copyright (c) 2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module bip70/pk
|
||||
*/
|
||||
|
||||
var pk = require('../crypto/pk');
|
||||
|
||||
/**
|
||||
* Verify signature with public key.
|
||||
* @private
|
||||
* @param {String} hash - Hash algorithm.
|
||||
* @param {Buffer} msg
|
||||
* @param {Buffer} sig
|
||||
* @param {Object} key
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
exports._verify = function verify(hash, msg, sig, key) {
|
||||
switch (key.alg) {
|
||||
case 'rsa':
|
||||
@ -19,6 +33,15 @@ exports._verify = function verify(hash, msg, sig, key) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Verify signature with public key.
|
||||
* @param {String} hash - Hash algorithm.
|
||||
* @param {Buffer} msg
|
||||
* @param {Buffer} sig
|
||||
* @param {Object} key
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
exports.verify = function verify(hash, msg, sig, key) {
|
||||
try {
|
||||
return exports._verify(hash, msg, sig, key);
|
||||
@ -27,6 +50,14 @@ exports.verify = function verify(hash, msg, sig, key) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sign message with private key.
|
||||
* @param {String} hash - Hash algorithm.
|
||||
* @param {Buffer} msg
|
||||
* @param {Object} key
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
exports.sign = function sign(hash, msg, key) {
|
||||
switch (key.alg) {
|
||||
case 'rsa':
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* x509.js - x509 handling for bcoin
|
||||
* Copyright (c) 2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -12,6 +12,11 @@ var PEM = require('../utils/pem');
|
||||
var util = require('../utils/util');
|
||||
var crypto = require('../crypto/crypto');
|
||||
var pk = require('./pk');
|
||||
|
||||
/**
|
||||
* @exports bip70/x509
|
||||
*/
|
||||
|
||||
var x509 = exports;
|
||||
|
||||
/**
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* chain.js - blockchain management for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -27,7 +27,7 @@ var VerifyResult = errors.VerifyResult;
|
||||
|
||||
/**
|
||||
* Represents a blockchain.
|
||||
* @exports Chain
|
||||
* @alias module:blockchain.Chain
|
||||
* @constructor
|
||||
* @param {Object} options
|
||||
* @param {String?} options.name - Database name.
|
||||
@ -168,6 +168,7 @@ Chain.prototype._init = function _init() {
|
||||
|
||||
/**
|
||||
* Open the chain, wait for the database to load.
|
||||
* @method
|
||||
* @alias Chain#open
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -219,6 +220,7 @@ Chain.prototype._close = function close() {
|
||||
|
||||
/**
|
||||
* Perform all necessary contextual verification on a block.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Block} block
|
||||
* @param {ChainEntry} prev
|
||||
@ -254,6 +256,7 @@ Chain.prototype.isGenesis = function isGenesis(block) {
|
||||
* Contextual verification for a block, including
|
||||
* version deployments (IsSuperMajority), versionbits,
|
||||
* coinbase height, finality checks.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Block} block
|
||||
* @param {ChainEntry} prev
|
||||
@ -407,6 +410,7 @@ Chain.prototype.verify = co(function* verify(block, prev) {
|
||||
|
||||
/**
|
||||
* Check all deployments on a chain, ranging from p2sh to segwit.
|
||||
* @method
|
||||
* @param {Block} block
|
||||
* @param {ChainEntry} prev
|
||||
* @returns {Promise} - Returns [{@link VerifyError}, {@link DeploymentState}].
|
||||
@ -507,6 +511,7 @@ Chain.prototype.setDeploymentState = function setDeploymentState(state) {
|
||||
* Determine whether to check block for duplicate txids in blockchain
|
||||
* history (BIP30). If we're on a chain that has bip34 activated, we
|
||||
* can skip this.
|
||||
* @method
|
||||
* @private
|
||||
* @see https://github.com/bitcoin/bips/blob/master/bip-0030.mediawiki
|
||||
* @param {Block} block
|
||||
@ -556,6 +561,7 @@ Chain.prototype.verifyDuplicates = co(function* verifyDuplicates(block, prev, st
|
||||
* will attempt to do this on the worker pool). If
|
||||
* `checkpoints` is enabled, it will skip verification
|
||||
* for historical data.
|
||||
* @method
|
||||
* @private
|
||||
* @see TX#checkInputs
|
||||
* @param {Block} block
|
||||
@ -678,6 +684,7 @@ Chain.prototype.checkHeight = function checkHeight(hash) {
|
||||
/**
|
||||
* Find the block at which a fork ocurred.
|
||||
* @private
|
||||
* @method
|
||||
* @param {ChainEntry} fork - The current chain.
|
||||
* @param {ChainEntry} longer - The competing chain.
|
||||
* @returns {Promise}
|
||||
@ -707,6 +714,7 @@ Chain.prototype.findFork = co(function* findFork(fork, longer) {
|
||||
* Reorganize the blockchain (connect and disconnect inputs).
|
||||
* Called when a competing chain with a higher chainwork
|
||||
* is received.
|
||||
* @method
|
||||
* @private
|
||||
* @param {ChainEntry} competitor - The competing chain's tip.
|
||||
* @param {Block} block - The being being added.
|
||||
@ -758,6 +766,7 @@ Chain.prototype.reorganize = co(function* reorganize(competitor, block) {
|
||||
/**
|
||||
* Reorganize the blockchain for SPV. This
|
||||
* will reset the chain to the fork block.
|
||||
* @method
|
||||
* @private
|
||||
* @param {ChainEntry} competitor - The competing chain's tip.
|
||||
* @param {Block} block - The being being added.
|
||||
@ -800,6 +809,7 @@ Chain.prototype.reorganizeSPV = co(function* reorganizeSPV(competitor, block) {
|
||||
|
||||
/**
|
||||
* Disconnect an entry from the chain (updates the tip).
|
||||
* @method
|
||||
* @param {ChainEntry} entry
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -831,6 +841,7 @@ Chain.prototype.disconnect = co(function* disconnect(entry) {
|
||||
* This will do contextual-verification on the block
|
||||
* (necessary because we cannot validate the inputs
|
||||
* in alternate chains when they come in).
|
||||
* @method
|
||||
* @param {ChainEntry} entry
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -875,6 +886,7 @@ Chain.prototype.reconnect = co(function* reconnect(entry) {
|
||||
* that comes in. It may add and connect the block (main chain),
|
||||
* save the block without connection (alternate chain), or
|
||||
* reorganize the chain (a higher fork).
|
||||
* @method
|
||||
* @private
|
||||
* @param {ChainEntry} entry
|
||||
* @param {Block} block
|
||||
@ -935,6 +947,7 @@ Chain.prototype.setBestChain = co(function* setBestChain(entry, block, prev) {
|
||||
|
||||
/**
|
||||
* Save block on an alternate chain.
|
||||
* @method
|
||||
* @private
|
||||
* @param {ChainEntry} entry
|
||||
* @param {Block} block
|
||||
@ -973,6 +986,7 @@ Chain.prototype.saveAlternate = co(function* saveAlternate(entry, block, prev) {
|
||||
* Reset the chain to the desired block. This
|
||||
* is useful for replaying the blockchain download
|
||||
* for SPV.
|
||||
* @method
|
||||
* @param {Hash|Number} block
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -988,6 +1002,7 @@ Chain.prototype.reset = co(function* reset(block) {
|
||||
|
||||
/**
|
||||
* Reset the chain to the desired block without a lock.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Hash|Number} block
|
||||
* @returns {Promise}
|
||||
@ -1022,6 +1037,7 @@ Chain.prototype._reset = co(function* reset(block, silent) {
|
||||
/**
|
||||
* Reset the chain to a height or hash. Useful for replaying
|
||||
* the blockchain download for SPV.
|
||||
* @method
|
||||
* @param {Hash|Number} block - hash/height
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -1037,6 +1053,7 @@ Chain.prototype.replay = co(function* replay(block) {
|
||||
|
||||
/**
|
||||
* Reset the chain without a lock.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Hash|Number} block - hash/height
|
||||
* @returns {Promise}
|
||||
@ -1059,6 +1076,7 @@ Chain.prototype._replay = co(function* replay(block) {
|
||||
|
||||
/**
|
||||
* Scan the blockchain for transactions containing specified address hashes.
|
||||
* @method
|
||||
* @param {Hash} start - Block hash to start at.
|
||||
* @param {Bloom} filter - Bloom filter containing tx and address hashes.
|
||||
* @param {Function} iter - Iterator.
|
||||
@ -1078,6 +1096,7 @@ Chain.prototype.scan = co(function* scan(start, filter, iter) {
|
||||
* Reset the chain to the desired timestamp (within 2
|
||||
* hours). This is useful for replaying the blockchain
|
||||
* download for SPV.
|
||||
* @method
|
||||
* @param {Number} ts - Timestamp.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -1094,6 +1113,7 @@ Chain.prototype.resetTime = co(function* resetTime(ts) {
|
||||
/**
|
||||
* Reset the chain to the desired timestamp without a lock.
|
||||
* @private
|
||||
* @method
|
||||
* @param {Number} ts - Timestamp.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -1109,6 +1129,7 @@ Chain.prototype._resetTime = co(function* resetTime(ts) {
|
||||
|
||||
/**
|
||||
* Add a block to the chain, perform all necessary verification.
|
||||
* @method
|
||||
* @param {Block} block
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -1125,6 +1146,7 @@ Chain.prototype.add = co(function* add(block) {
|
||||
|
||||
/**
|
||||
* Add a block to the chain without a lock.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Block} block
|
||||
* @returns {Promise}
|
||||
@ -1557,6 +1579,7 @@ Chain.prototype.removeInvalid = function removeInvalid(hash) {
|
||||
/**
|
||||
* Test the chain to see if it contains
|
||||
* a block, or has recently seen a block.
|
||||
* @method
|
||||
* @param {Hash} hash
|
||||
* @returns {Promise} - Returns Boolean.
|
||||
*/
|
||||
@ -1626,6 +1649,7 @@ Chain.prototype.hasPending = function hasPending(hash) {
|
||||
|
||||
/**
|
||||
* Get coin viewpoint.
|
||||
* @method
|
||||
* @param {TX} tx
|
||||
* @returns {Promise} - Returns {@link CoinView}.
|
||||
*/
|
||||
@ -1700,6 +1724,7 @@ Chain.prototype.getProgress = function getProgress() {
|
||||
|
||||
/**
|
||||
* Calculate chain locator (an array of hashes).
|
||||
* @method
|
||||
* @param {Hash} start - Height or hash to treat as the tip.
|
||||
* The current tip will be used if not present. Note that this can be a
|
||||
* non-existent hash, which is useful for headers-first locators.
|
||||
@ -1717,6 +1742,7 @@ Chain.prototype.getLocator = co(function* getLocator(start) {
|
||||
|
||||
/**
|
||||
* Calculate chain locator without a lock.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Hash} start
|
||||
* @returns {Promise}
|
||||
@ -1826,6 +1852,7 @@ Chain.prototype.getProofTime = function getProofTime(to, from) {
|
||||
|
||||
/**
|
||||
* Calculate the next target based on the chain tip.
|
||||
* @method
|
||||
* @returns {Promise} - returns Number
|
||||
* (target is in compact/mantissa form).
|
||||
*/
|
||||
@ -1836,6 +1863,7 @@ Chain.prototype.getCurrentTarget = co(function* getCurrentTarget() {
|
||||
|
||||
/**
|
||||
* Calculate the target based on the passed-in chain entry.
|
||||
* @method
|
||||
* @param {ChainEntry} prev - Previous entry.
|
||||
* @param {Block} - Current block.
|
||||
* @returns {Promise} - returns Number
|
||||
@ -1936,6 +1964,7 @@ Chain.prototype.retarget = function retarget(prev, first) {
|
||||
|
||||
/**
|
||||
* Find a locator. Analagous to bitcoind's `FindForkInGlobalIndex()`.
|
||||
* @method
|
||||
* @param {Hash[]} locator - Hashes.
|
||||
* @returns {Promise} - Returns {@link Hash} (the
|
||||
* hash of the latest known block).
|
||||
@ -1957,6 +1986,7 @@ Chain.prototype.findLocator = co(function* findLocator(locator) {
|
||||
* Check whether a versionbits deployment is active (BIP9: versionbits).
|
||||
* @example
|
||||
* yield chain.isActive(tip, deployments.segwit);
|
||||
* @method
|
||||
* @see https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki
|
||||
* @param {ChainEntry} prev - Previous chain entry.
|
||||
* @param {String} id - Deployment id.
|
||||
@ -1970,6 +2000,7 @@ Chain.prototype.isActive = co(function* isActive(prev, deployment) {
|
||||
|
||||
/**
|
||||
* Get chain entry state for a deployment (BIP9: versionbits).
|
||||
* @method
|
||||
* @example
|
||||
* yield chain.getState(tip, deployments.segwit);
|
||||
* @see https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki
|
||||
@ -2087,6 +2118,7 @@ Chain.prototype.getState = co(function* getState(prev, deployment) {
|
||||
|
||||
/**
|
||||
* Compute the version for a new block (BIP9: versionbits).
|
||||
* @method
|
||||
* @see https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki
|
||||
* @param {ChainEntry} prev - Previous chain entry (usually the tip).
|
||||
* @returns {Promise} - Returns Number.
|
||||
@ -2114,6 +2146,7 @@ Chain.prototype.computeBlockVersion = co(function* computeBlockVersion(prev) {
|
||||
|
||||
/**
|
||||
* Get the current deployment state of the chain. Called on load.
|
||||
* @method
|
||||
* @private
|
||||
* @returns {Promise} - Returns {@link DeploymentState}.
|
||||
*/
|
||||
@ -2135,6 +2168,7 @@ Chain.prototype.getDeploymentState = co(function* getDeploymentState() {
|
||||
/**
|
||||
* Check transaction finality, taking into account MEDIAN_TIME_PAST
|
||||
* if it is present in the lock flags.
|
||||
* @method
|
||||
* @param {ChainEntry} prev - Previous chain entry.
|
||||
* @param {TX} tx
|
||||
* @param {LockFlags} flags
|
||||
@ -2159,6 +2193,7 @@ Chain.prototype.verifyFinal = co(function* verifyFinal(prev, tx, flags) {
|
||||
|
||||
/**
|
||||
* Get the necessary minimum time and height sequence locks for a transaction.
|
||||
* @method
|
||||
* @param {ChainEntry} prev
|
||||
* @param {TX} tx
|
||||
* @param {CoinView} view
|
||||
@ -2212,6 +2247,7 @@ Chain.prototype.getLocks = co(function* getLocks(prev, tx, view, flags) {
|
||||
|
||||
/**
|
||||
* Verify sequence locks.
|
||||
* @method
|
||||
* @param {ChainEntry} prev
|
||||
* @param {TX} tx
|
||||
* @param {CoinView} view
|
||||
@ -2241,6 +2277,7 @@ Chain.prototype.verifyLocks = co(function* verifyLocks(prev, tx, view, flags) {
|
||||
|
||||
/**
|
||||
* ChainOptions
|
||||
* @alias module:blockchain.ChainOptions
|
||||
* @constructor
|
||||
* @param {Object} options
|
||||
*/
|
||||
@ -2375,6 +2412,7 @@ ChainOptions.fromOptions = function fromOptions(options) {
|
||||
|
||||
/**
|
||||
* Represents the deployment state of the chain.
|
||||
* @alias module:blockchain.DeploymentState
|
||||
* @constructor
|
||||
* @property {VerifyFlags} flags
|
||||
* @property {LockFlags} lockFlags
|
||||
@ -2457,6 +2495,7 @@ DeploymentState.prototype.hasWitness = function hasWitness() {
|
||||
/**
|
||||
* LockTimes
|
||||
* @constructor
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
function LockTimes(height, time) {
|
||||
@ -2467,6 +2506,7 @@ function LockTimes(height, time) {
|
||||
/**
|
||||
* ContextResult
|
||||
* @constructor
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
function ContextResult(view, state) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* chaindb.js - blockchain data management for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -33,7 +33,7 @@ var DUMMY = new Buffer([0]);
|
||||
|
||||
/**
|
||||
* The database backend for the {@link Chain} object.
|
||||
* @exports ChainDB
|
||||
* @alias module:blockchain.ChainDB
|
||||
* @constructor
|
||||
* @param {Chain} chain
|
||||
* @param {Boolean?} options.prune - Whether to prune the chain.
|
||||
@ -80,6 +80,7 @@ ChainDB.layout = layout;
|
||||
|
||||
/**
|
||||
* Open the chain db, wait for the database to load.
|
||||
* @method
|
||||
* @alias ChainDB#open
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -210,6 +211,7 @@ ChainDB.prototype.drop = function drop() {
|
||||
|
||||
/**
|
||||
* Commit current batch.
|
||||
* @method
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -277,6 +279,7 @@ ChainDB.prototype.getCache = function getCache(block) {
|
||||
|
||||
/**
|
||||
* Get the height of a block by hash.
|
||||
* @method
|
||||
* @param {Hash} hash
|
||||
* @returns {Promise} - Returns Number.
|
||||
*/
|
||||
@ -308,6 +311,7 @@ ChainDB.prototype.getHeight = co(function* getHeight(hash) {
|
||||
/**
|
||||
* Get the hash of a block by height. Note that this
|
||||
* will only return hashes in the main chain.
|
||||
* @method
|
||||
* @param {Number} height
|
||||
* @returns {Promise} - Returns {@link Hash}.
|
||||
*/
|
||||
@ -338,6 +342,7 @@ ChainDB.prototype.getHash = co(function* getHash(height) {
|
||||
|
||||
/**
|
||||
* Retrieve a chain entry by height.
|
||||
* @method
|
||||
* @param {Number} height
|
||||
* @returns {Promise} - Returns {@link ChainEntry}.
|
||||
*/
|
||||
@ -379,6 +384,7 @@ ChainDB.prototype.getEntryByHeight = co(function* getEntryByHeight(height) {
|
||||
|
||||
/**
|
||||
* Retrieve a chain entry by hash.
|
||||
* @method
|
||||
* @param {Hash} hash
|
||||
* @returns {Promise} - Returns {@link ChainEntry}.
|
||||
*/
|
||||
@ -425,6 +431,7 @@ ChainDB.prototype.getEntry = function getEntry(block) {
|
||||
|
||||
/**
|
||||
* Test whether the chain contains a block.
|
||||
* @method
|
||||
* @param {Hash} hash
|
||||
* @returns {Promise} - Returns Boolean.
|
||||
*/
|
||||
@ -445,6 +452,7 @@ ChainDB.prototype.getTip = function getTip() {
|
||||
|
||||
/**
|
||||
* Retrieve the tip entry from the tip record.
|
||||
* @method
|
||||
* @returns {Promise} - Returns {@link ChainState}.
|
||||
*/
|
||||
|
||||
@ -459,6 +467,7 @@ ChainDB.prototype.getState = co(function* getState() {
|
||||
|
||||
/**
|
||||
* Write genesis block to database.
|
||||
* @method
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -474,6 +483,7 @@ ChainDB.prototype.saveGenesis = co(function* saveGenesis() {
|
||||
|
||||
/**
|
||||
* Retrieve the database flags.
|
||||
* @method
|
||||
* @returns {Promise} - Returns {@link ChainFlags}.
|
||||
*/
|
||||
|
||||
@ -488,6 +498,7 @@ ChainDB.prototype.getFlags = co(function* getFlags() {
|
||||
|
||||
/**
|
||||
* Verify current options against db options.
|
||||
* @method
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -504,6 +515,7 @@ ChainDB.prototype.verifyFlags = co(function* verifyFlags() {
|
||||
|
||||
/**
|
||||
* Get state caches.
|
||||
* @method
|
||||
* @returns {Promise} - Returns {@link StateCache}.
|
||||
*/
|
||||
|
||||
@ -563,6 +575,7 @@ ChainDB.prototype.writeDeployments = function writeDeployments(batch) {
|
||||
|
||||
/**
|
||||
* Check for outdated deployments.
|
||||
* @method
|
||||
* @private
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -599,6 +612,7 @@ ChainDB.prototype.checkDeployments = co(function* checkDeployments() {
|
||||
|
||||
/**
|
||||
* Potentially invalidate state cache.
|
||||
* @method
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -627,6 +641,7 @@ ChainDB.prototype.verifyDeployments = co(function* verifyDeployments() {
|
||||
|
||||
/**
|
||||
* Invalidate state cache.
|
||||
* @method
|
||||
* @private
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -647,6 +662,7 @@ ChainDB.prototype.invalidateCache = co(function* invalidateCache(bit, batch) {
|
||||
|
||||
/**
|
||||
* Get the _next_ block hash (does not work by height).
|
||||
* @method
|
||||
* @param {Hash} hash
|
||||
* @returns {Promise} - Returns {@link Hash}.
|
||||
*/
|
||||
@ -662,6 +678,7 @@ ChainDB.prototype.getNextHash = co(function* getNextHash(hash) {
|
||||
|
||||
/**
|
||||
* Check to see if a block is on the main chain.
|
||||
* @method
|
||||
* @param {ChainEntry|Hash} hash
|
||||
* @returns {Promise} - Returns Boolean.
|
||||
*/
|
||||
@ -724,6 +741,7 @@ ChainDB.prototype.getTips = function getTips() {
|
||||
|
||||
/**
|
||||
* Get a coin (unspents only).
|
||||
* @method
|
||||
* @param {Hash} hash
|
||||
* @param {Number} index
|
||||
* @returns {Promise} - Returns {@link Coin}.
|
||||
@ -754,6 +772,7 @@ ChainDB.prototype.getCoin = co(function* getCoin(hash, index) {
|
||||
|
||||
/**
|
||||
* Get coins (unspents only).
|
||||
* @method
|
||||
* @param {Hash} hash
|
||||
* @returns {Promise} - Returns {@link Coins}.
|
||||
*/
|
||||
@ -790,6 +809,7 @@ ChainDB.prototype.hasCoins = function hasCoins(hash) {
|
||||
|
||||
/**
|
||||
* Get coin viewpoint.
|
||||
* @method
|
||||
* @param {TX} tx
|
||||
* @returns {Promise} - Returns {@link CoinView}.
|
||||
*/
|
||||
@ -818,6 +838,7 @@ ChainDB.prototype.getCoinView = co(function* getCoinView(tx) {
|
||||
|
||||
/**
|
||||
* Get coin viewpoint (historical).
|
||||
* @method
|
||||
* @param {TX} tx
|
||||
* @returns {Promise} - Returns {@link CoinView}.
|
||||
*/
|
||||
@ -846,6 +867,7 @@ ChainDB.prototype.getSpentView = co(function* getSpentView(tx) {
|
||||
|
||||
/**
|
||||
* Get coins necessary to be resurrected during a reorg.
|
||||
* @method
|
||||
* @param {Hash} hash
|
||||
* @returns {Promise} - Returns {@link Coin}[].
|
||||
*/
|
||||
@ -859,6 +881,7 @@ ChainDB.prototype.getUndoCoins = co(function* getUndoCoins(hash) {
|
||||
|
||||
/**
|
||||
* Retrieve a block from the database (not filled with coins).
|
||||
* @method
|
||||
* @param {Hash} hash
|
||||
* @returns {Promise} - Returns {@link Block}.
|
||||
*/
|
||||
@ -874,6 +897,7 @@ ChainDB.prototype.getBlock = co(function* getBlock(hash) {
|
||||
|
||||
/**
|
||||
* Retrieve a block from the database (not filled with coins).
|
||||
* @method
|
||||
* @param {Hash} hash
|
||||
* @returns {Promise} - Returns {@link Block}.
|
||||
*/
|
||||
@ -894,6 +918,7 @@ ChainDB.prototype.getRawBlock = co(function* getRawBlock(block) {
|
||||
|
||||
/**
|
||||
* Get a historical block coin viewpoint.
|
||||
* @method
|
||||
* @param {Block} hash
|
||||
* @returns {Promise} - Returns {@link CoinView}.
|
||||
*/
|
||||
@ -936,6 +961,7 @@ ChainDB.prototype.getBlockView = co(function* getBlockView(block) {
|
||||
|
||||
/**
|
||||
* Get a transaction with metadata.
|
||||
* @method
|
||||
* @param {Hash} hash
|
||||
* @returns {Promise} - Returns {@link TXMeta}.
|
||||
*/
|
||||
@ -956,6 +982,7 @@ ChainDB.prototype.getMeta = co(function* getMeta(hash) {
|
||||
|
||||
/**
|
||||
* Retrieve a transaction.
|
||||
* @method
|
||||
* @param {Hash} hash
|
||||
* @returns {Promise} - Returns {@link TX}.
|
||||
*/
|
||||
@ -981,6 +1008,7 @@ ChainDB.prototype.hasTX = function hasTX(hash) {
|
||||
|
||||
/**
|
||||
* Get all coins pertinent to an address.
|
||||
* @method
|
||||
* @param {Address[]} addresses
|
||||
* @returns {Promise} - Returns {@link Coin}[].
|
||||
*/
|
||||
@ -1022,6 +1050,7 @@ ChainDB.prototype.getCoinsByAddress = co(function* getCoinsByAddress(addresses)
|
||||
|
||||
/**
|
||||
* Get all transaction hashes to an address.
|
||||
* @method
|
||||
* @param {Address[]} addresses
|
||||
* @returns {Promise} - Returns {@link Hash}[].
|
||||
*/
|
||||
@ -1055,6 +1084,7 @@ ChainDB.prototype.getHashesByAddress = co(function* getHashesByAddress(addresses
|
||||
|
||||
/**
|
||||
* Get all transactions pertinent to an address.
|
||||
* @method
|
||||
* @param {Address[]} addresses
|
||||
* @returns {Promise} - Returns {@link TX}[].
|
||||
*/
|
||||
@ -1074,6 +1104,7 @@ ChainDB.prototype.getTXByAddress = co(function* getTXByAddress(addresses) {
|
||||
|
||||
/**
|
||||
* Get all transactions pertinent to an address.
|
||||
* @method
|
||||
* @param {Address[]} addresses
|
||||
* @returns {Promise} - Returns {@link TXMeta}[].
|
||||
*/
|
||||
@ -1102,6 +1133,7 @@ ChainDB.prototype.getMetaByAddress = co(function* getTXByAddress(addresses) {
|
||||
|
||||
/**
|
||||
* Scan the blockchain for transactions containing specified address hashes.
|
||||
* @method
|
||||
* @param {Hash} start - Block hash to start at.
|
||||
* @param {Bloom} filter - Bloom filter containing tx and address hashes.
|
||||
* @param {Function} iter - Iterator.
|
||||
@ -1196,6 +1228,7 @@ ChainDB.prototype.scan = co(function* scan(start, filter, iter) {
|
||||
* connect it as the tip. Note that this method
|
||||
* does _not_ perform any verification which is
|
||||
* instead performed in {@link Chain#add}.
|
||||
* @method
|
||||
* @param {ChainEntry} entry
|
||||
* @param {Block} block
|
||||
* @param {CoinView?} view - Will not connect if null.
|
||||
@ -1215,6 +1248,7 @@ ChainDB.prototype.save = co(function* save(entry, block, view) {
|
||||
|
||||
/**
|
||||
* Save an entry without a batch.
|
||||
* @method
|
||||
* @private
|
||||
* @param {ChainEntry} entry
|
||||
* @param {Block} block
|
||||
@ -1261,6 +1295,7 @@ ChainDB.prototype._save = co(function* save(entry, block, view) {
|
||||
|
||||
/**
|
||||
* Reconnect the block to the chain.
|
||||
* @method
|
||||
* @param {ChainEntry} entry
|
||||
* @param {Block} block
|
||||
* @param {CoinView} view
|
||||
@ -1280,6 +1315,7 @@ ChainDB.prototype.reconnect = co(function* reconnect(entry, block, view) {
|
||||
|
||||
/**
|
||||
* Reconnect block without a batch.
|
||||
* @method
|
||||
* @private
|
||||
* @param {ChainEntry} entry
|
||||
* @param {Block} block
|
||||
@ -1312,6 +1348,7 @@ ChainDB.prototype._reconnect = co(function* reconnect(entry, block, view) {
|
||||
|
||||
/**
|
||||
* Disconnect block from the chain.
|
||||
* @method
|
||||
* @param {ChainEntry} entry
|
||||
* @param {Block} block
|
||||
* @returns {Promise}
|
||||
@ -1337,6 +1374,7 @@ ChainDB.prototype.disconnect = co(function* disconnect(entry, block) {
|
||||
/**
|
||||
* Disconnect block without a batch.
|
||||
* @private
|
||||
* @method
|
||||
* @param {ChainEntry} entry
|
||||
* @param {Block} block
|
||||
* @returns {Promise} - Returns {@link CoinView}.
|
||||
@ -1387,6 +1425,7 @@ ChainDB.prototype.saveUpdates = function saveUpdates() {
|
||||
/**
|
||||
* Reset the chain to a height or hash. Useful for replaying
|
||||
* the blockchain download for SPV.
|
||||
* @method
|
||||
* @param {Hash|Number} block - hash/height
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -1464,6 +1503,7 @@ ChainDB.prototype.reset = co(function* reset(block) {
|
||||
|
||||
/**
|
||||
* Remove all alternate chains.
|
||||
* @method
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -1488,6 +1528,7 @@ ChainDB.prototype.removeChains = co(function* removeChains() {
|
||||
|
||||
/**
|
||||
* Remove an alternate chain.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Hash} hash - Alternate chain tip.
|
||||
* @returns {Promise}
|
||||
@ -1525,6 +1566,7 @@ ChainDB.prototype._removeChain = co(function* removeChain(hash) {
|
||||
/**
|
||||
* Save a block (not an entry) to the
|
||||
* database and potentially connect the inputs.
|
||||
* @method
|
||||
* @param {ChainEntry} entry
|
||||
* @param {Block} block
|
||||
* @param {CoinView?} view
|
||||
@ -1550,6 +1592,7 @@ ChainDB.prototype.saveBlock = co(function* saveBlock(entry, block, view) {
|
||||
/**
|
||||
* Remove a block (not an entry) to the database.
|
||||
* Disconnect inputs.
|
||||
* @method
|
||||
* @param {ChainEntry} entry
|
||||
* @returns {Promise} - Returns {@link Block}.
|
||||
*/
|
||||
@ -1596,6 +1639,7 @@ ChainDB.prototype.saveView = function saveView(view) {
|
||||
|
||||
/**
|
||||
* Connect block inputs.
|
||||
* @method
|
||||
* @param {ChainEntry} entry
|
||||
* @param {Block} block
|
||||
* @param {CoinView} view
|
||||
@ -1652,6 +1696,7 @@ ChainDB.prototype.connectBlock = co(function* connectBlock(entry, block, view) {
|
||||
|
||||
/**
|
||||
* Disconnect block inputs.
|
||||
* @method
|
||||
* @param {ChainEntry} entry
|
||||
* @param {Block} block
|
||||
* @returns {Promise} - Returns {@link CoinView}.
|
||||
@ -1714,6 +1759,7 @@ ChainDB.prototype.disconnectBlock = co(function* disconnectBlock(entry, block) {
|
||||
/**
|
||||
* Prune a block from the chain and
|
||||
* add current block to the prune queue.
|
||||
* @method
|
||||
* @private
|
||||
* @param {ChainEntry} entry
|
||||
* @returns {Promise}
|
||||
@ -1857,7 +1903,8 @@ ChainDB.prototype.unindexTX = function unindexTX(tx, view) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Chain Options
|
||||
* Chain Flags
|
||||
* @alias module:blockchain.ChainFlags
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
@ -1989,6 +2036,7 @@ ChainFlags.fromRaw = function fromRaw(data) {
|
||||
|
||||
/**
|
||||
* Chain State
|
||||
* @alias module:blockchain.ChainState
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
@ -2064,6 +2112,7 @@ ChainState.fromRaw = function fromRaw(data) {
|
||||
|
||||
/**
|
||||
* StateCache
|
||||
* @alias module:blockchain.StateCache
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
@ -2138,6 +2187,7 @@ StateCache.prototype.insert = function insert(bit, hash, state) {
|
||||
/**
|
||||
* CacheUpdate
|
||||
* @constructor
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
function CacheUpdate(bit, hash, state) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* chainentry.js - chainentry object for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -25,13 +25,13 @@ var co = require('../utils/co');
|
||||
* chainwork _with_ the entry in order to
|
||||
* avoid reading the entire chain index on
|
||||
* boot and recalculating the chainworks.
|
||||
* @exports ChainEntry
|
||||
* @alias module:blockchain.ChainEntry
|
||||
* @constructor
|
||||
* @param {Chain} chain
|
||||
* @param {Object} options
|
||||
* @param {ChainEntry} prev
|
||||
* @property {Hash} hash
|
||||
* @property {Number} version - Transaction version. Note that BCoin reads
|
||||
* @property {Number} version - Transaction version. Note that Bcoin reads
|
||||
* versions as unsigned even though they are signed at the protocol level.
|
||||
* This value will never be negative.
|
||||
* @property {Hash} prevBlock
|
||||
@ -182,6 +182,7 @@ ChainEntry.prototype.getRetargetAncestors = function getRetargetAncestors() {
|
||||
|
||||
/**
|
||||
* Collect ancestors.
|
||||
* @method
|
||||
* @param {Number} max - Number of ancestors.
|
||||
* @returns {Promise} - Returns ChainEntry[].
|
||||
*/
|
||||
@ -224,6 +225,7 @@ ChainEntry.prototype.getAncestors = co(function* getAncestors(max) {
|
||||
|
||||
/**
|
||||
* Test whether the entry is in the main chain.
|
||||
* @method
|
||||
* @returns {Promise} - Return Boolean.
|
||||
*/
|
||||
|
||||
@ -251,6 +253,7 @@ ChainEntry.prototype.isMainChain = co(function* isMainChain() {
|
||||
|
||||
/**
|
||||
* Get ancestor by `height`.
|
||||
* @method
|
||||
* @param {Number} height
|
||||
* @returns {Promise} - Returns ChainEntry[].
|
||||
*/
|
||||
@ -286,6 +289,7 @@ ChainEntry.prototype.getPrevious = function getPrevious() {
|
||||
|
||||
/**
|
||||
* Get next entry.
|
||||
* @method
|
||||
* @returns {Promise} - Returns ChainEntry.
|
||||
*/
|
||||
|
||||
@ -298,6 +302,7 @@ ChainEntry.prototype.getNext = co(function* getNext() {
|
||||
|
||||
/**
|
||||
* Get next entry.
|
||||
* @method
|
||||
* @returns {Promise} - Returns ChainEntry.
|
||||
*/
|
||||
|
||||
@ -337,6 +342,7 @@ ChainEntry.prototype.getMedianTime = function getMedianTime(ancestors) {
|
||||
|
||||
/**
|
||||
* Get median time past asynchronously (see {@link ChainEntry#getMedianTime}).
|
||||
* @method
|
||||
* @returns {Promise} - Returns Number.
|
||||
*/
|
||||
|
||||
|
||||
@ -1,12 +1,16 @@
|
||||
/*!
|
||||
* common.js - bitcoin constants for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module blockchain/common
|
||||
*/
|
||||
|
||||
/**
|
||||
* Locktime flags.
|
||||
* @enum {Number}
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module blockchain
|
||||
*/
|
||||
|
||||
exports.common = require('./common');
|
||||
exports.Chain = require('./chain');
|
||||
exports.ChainDB = require('./chaindb');
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* layout-browser.js - chaindb layout for browser.
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* layout.js - blockchain data layout for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* amount.js - amount object for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -11,6 +11,7 @@ var util = require('../utils/util');
|
||||
|
||||
/**
|
||||
* Represents a bitcoin amount (satoshis internally).
|
||||
* @alias module:btc.Amount
|
||||
* @constructor
|
||||
* @param {(String|Number)?} value
|
||||
* @param {String?} unit
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module btc
|
||||
*/
|
||||
|
||||
exports.Amount = require('./amount');
|
||||
exports.URI = require('./uri');
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* uri.js - bitcoin uri parsing for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -13,6 +13,7 @@ var assert = require('assert');
|
||||
|
||||
/**
|
||||
* Represents a bitcoin URI.
|
||||
* @alias module:btc.URI
|
||||
* @constructor
|
||||
* @param {Object|String} options
|
||||
* @property {Address} address
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* coins.js - coins object for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -19,6 +19,7 @@ var decompress = compressor.decompress;
|
||||
|
||||
/**
|
||||
* Represents the outputs for a single transaction.
|
||||
* @alias module:coins.Coins
|
||||
* @constructor
|
||||
* @param {Object?} options - Options object.
|
||||
* @property {Hash} hash - Transaction hash.
|
||||
@ -611,8 +612,8 @@ Coins.fromTX = function fromTX(tx, height) {
|
||||
* pointer to that coin in the Coins buffer, as
|
||||
* well as a size. Parsing and decompression
|
||||
* is done only if that coin is being redeemed.
|
||||
* @alias module:coins.CoinEntry
|
||||
* @constructor
|
||||
* @private
|
||||
* @property {Number} offset
|
||||
* @property {Number} size
|
||||
* @property {Buffer} raw
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* coinview.js - coin viewpoint object for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -15,10 +15,10 @@ var BufferWriter = require('../utils/writer');
|
||||
var CoinEntry = Coins.CoinEntry;
|
||||
|
||||
/**
|
||||
* A collection of {@link Coins} objects.
|
||||
* Represents a coin viewpoint:
|
||||
* a snapshot of {@link Coins} objects.
|
||||
* @alias module:coins.CoinView
|
||||
* @constructor
|
||||
* @param {Object} map - A hash-to-coins map.
|
||||
* @param {UndoCoins} undo - Spent coins.
|
||||
* @property {Object} map
|
||||
* @property {UndoCoins} undo
|
||||
*/
|
||||
@ -298,6 +298,7 @@ CoinView.prototype.isCoinbase = function isCoinbase(input) {
|
||||
|
||||
/**
|
||||
* Retrieve coins from database.
|
||||
* @method
|
||||
* @param {ChainDB} db
|
||||
* @param {TX} tx
|
||||
* @returns {Promise} - Returns {@link Coins}.
|
||||
@ -320,6 +321,7 @@ CoinView.prototype.readCoins = co(function* readCoins(db, hash) {
|
||||
|
||||
/**
|
||||
* Read all input coins into unspent map.
|
||||
* @method
|
||||
* @param {ChainDB} db
|
||||
* @param {TX} tx
|
||||
* @returns {Promise} - Returns {Boolean}.
|
||||
@ -340,6 +342,7 @@ CoinView.prototype.ensureInputs = co(function* ensureInputs(db, tx) {
|
||||
|
||||
/**
|
||||
* Spend coins for transaction.
|
||||
* @method
|
||||
* @param {ChainDB} db
|
||||
* @param {TX} tx
|
||||
* @returns {Promise} - Returns {Boolean}.
|
||||
|
||||
@ -1,11 +1,16 @@
|
||||
/*!
|
||||
* compress.js - coin compressor for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module coins/compress
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
var assert = require('assert');
|
||||
var ec = require('../crypto/ec');
|
||||
var encoding = require('../utils/encoding');
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module coins
|
||||
*/
|
||||
|
||||
exports.Coins = require('./coins');
|
||||
exports.CoinView = require('./coinview');
|
||||
exports.compress = require('./compress');
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* undocoins.js - undocoins object for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -22,6 +22,7 @@ var decompress = compressor.decompress;
|
||||
* during a reorg. The undo coins store all
|
||||
* spent coins in a single record per block
|
||||
* (in a compressed format).
|
||||
* @alias module:coins.UndoCoins
|
||||
* @constructor
|
||||
* @property {UndoCoin[]} items
|
||||
*/
|
||||
@ -176,6 +177,7 @@ UndoCoins.prototype.apply = function apply(view, outpoint) {
|
||||
|
||||
/**
|
||||
* UndoCoin
|
||||
* @alias module:coins.UndoCoin
|
||||
* @constructor
|
||||
* @property {CoinEntry|null} entry
|
||||
* @property {Output|null} output
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* aes.js - aes128/192/256 for bcoin
|
||||
* Copyright (c) 2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*
|
||||
* Ported from:
|
||||
@ -14,12 +14,18 @@
|
||||
|
||||
var assert = require('assert');
|
||||
var U32Array = typeof Uint32Array === 'function' ? Uint32Array : Array;
|
||||
|
||||
/**
|
||||
* @exports crypto/aes
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
var AES = exports;
|
||||
|
||||
/**
|
||||
* An AES key object for encrypting
|
||||
* and decrypting blocks.
|
||||
* @exports AESKey
|
||||
* @alias module:crypto/aes.AESKey
|
||||
* @constructor
|
||||
* @param {Buffer} key
|
||||
* @param {Number} bits
|
||||
@ -467,7 +473,7 @@ AESKey.prototype.decryptBlock = function decryptBlock(input) {
|
||||
|
||||
/**
|
||||
* AES cipher.
|
||||
* @exports AESCipher
|
||||
* @alias module:crypto/aes.AESCipher
|
||||
* @constructor
|
||||
* @param {Buffer} key
|
||||
* @param {Buffer} iv
|
||||
@ -554,7 +560,7 @@ AESCipher.prototype.final = function final() {
|
||||
|
||||
/**
|
||||
* AES decipher.
|
||||
* @exports AESDecipher
|
||||
* @alias module:crypto/aes.AESDecipher
|
||||
* @constructor
|
||||
* @param {Buffer} key
|
||||
* @param {Buffer} iv
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* backend-browser.js - browser crypto backend for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* backend.js - crypto backend for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* chachapoly.js - chacha20/poly1305 for bcoin
|
||||
* Copyright (c) 2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -11,10 +11,14 @@ var native = require('../utils/native').binding;
|
||||
|
||||
var BIG_ENDIAN = new Int8Array(new Int16Array([1]).buffer)[0] === 0;
|
||||
|
||||
/**
|
||||
* @module crypto/chachapoly
|
||||
*/
|
||||
|
||||
/**
|
||||
* ChaCha20 (used for bip151)
|
||||
* @see https://tools.ietf.org/html/rfc7539#section-2
|
||||
* @exports ChaCha20
|
||||
* @alias module:crypto/chachapoly.ChaCha20
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
@ -206,7 +210,7 @@ function rotl32(w, b) {
|
||||
* Poly1305 (used for bip151)
|
||||
* @see https://github.com/floodyberry/poly1305-donna
|
||||
* @see https://tools.ietf.org/html/rfc7539#section-2.5
|
||||
* @exports Poly1305
|
||||
* @alias module:crypto/chachapoly.Poly1305
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
@ -501,6 +505,7 @@ if (native)
|
||||
* @exports AEAD
|
||||
* @see https://github.com/openssh/openssh-portable
|
||||
* @see https://tools.ietf.org/html/rfc7539#section-2.8
|
||||
* @alias module:crypto/chachapoly.AEAD
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* crypto.js - crypto for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -10,6 +10,12 @@
|
||||
var backend = require('./backend');
|
||||
var native = require('../utils/native').binding;
|
||||
var scrypt = require('./scrypt');
|
||||
|
||||
/**
|
||||
* @exports crypto/crypto
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
var crypto = exports;
|
||||
|
||||
/**
|
||||
@ -418,8 +424,12 @@ crypto.randomRange = function randomRange(min, max) {
|
||||
return Math.floor((num / 0x100000000) * (max - min) + min);
|
||||
};
|
||||
|
||||
/*
|
||||
* Helpers
|
||||
/**
|
||||
* Merkle Tree
|
||||
* @constructor
|
||||
* @ignore
|
||||
* @param {Buffer[]} nodes
|
||||
* @param {Boolean} malleated
|
||||
*/
|
||||
|
||||
function MerkleTree(nodes, malleated) {
|
||||
@ -427,6 +437,14 @@ function MerkleTree(nodes, malleated) {
|
||||
this.malleated = malleated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merkle Root
|
||||
* @constructor
|
||||
* @ignore
|
||||
* @param {Buffer} hash
|
||||
* @param {Boolean} malleated
|
||||
*/
|
||||
|
||||
function MerkleRoot(hash, malleated) {
|
||||
this.hash = hash;
|
||||
this.malleated = malleated;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* ec.js - ecdsa wrapper for elliptic
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -15,7 +15,8 @@ var curve = secp256k1.curve;
|
||||
var BN = require('bn.js');
|
||||
|
||||
/**
|
||||
* @exports ec
|
||||
* @exports crypto/ec-elliptic
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
var ec = exports;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* ec-secp256k1.js - ecdsa wrapper for secp256k1
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -12,6 +12,12 @@ var util = require('../utils/util');
|
||||
var backend = require('./backend');
|
||||
var secp256k1 = require('secp256k1');
|
||||
|
||||
/**
|
||||
* @exports crypto/ec
|
||||
*/
|
||||
|
||||
var ec = exports;
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
@ -25,15 +31,10 @@ var HALF_ORDER = new Buffer(
|
||||
'7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0',
|
||||
'hex');
|
||||
|
||||
/**
|
||||
* @exports ec
|
||||
*/
|
||||
|
||||
var ec = exports;
|
||||
|
||||
/**
|
||||
* Whether we're using native bindings.
|
||||
* @const {Boolean}
|
||||
* @private
|
||||
*/
|
||||
|
||||
ec.binding = true;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* ec.js - ecdsa wrapper for secp256k1 and elliptic
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
|
||||
@ -1,49 +1,349 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module crypto
|
||||
*/
|
||||
|
||||
var crypto = require('./crypto');
|
||||
|
||||
/**
|
||||
* Crypto module.
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
exports.crypto = crypto;
|
||||
|
||||
/**
|
||||
* Hash with chosen algorithm.
|
||||
* @function
|
||||
* @param {String} alg
|
||||
* @param {Buffer} data
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
exports.hash = crypto.hash;
|
||||
exports.hashAsync = crypto.hashAsync;
|
||||
|
||||
/**
|
||||
* Hash with ripemd160.
|
||||
* @function
|
||||
* @param {Buffer} data
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
exports.ripemd160 = crypto.ripemd160;
|
||||
|
||||
/**
|
||||
* Hash with sha1.
|
||||
* @function
|
||||
* @param {Buffer} data
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
exports.sha1 = crypto.sha1;
|
||||
|
||||
/**
|
||||
* Hash with sha256.
|
||||
* @function
|
||||
* @param {Buffer} data
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
exports.sha256 = crypto.sha256;
|
||||
|
||||
/**
|
||||
* Hash with sha256 and ripemd160 (OP_HASH160).
|
||||
* @function
|
||||
* @param {Buffer} data
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
exports.hash160 = crypto.hash160;
|
||||
|
||||
/**
|
||||
* Hash with sha256 twice (OP_HASH256).
|
||||
* @function
|
||||
* @param {Buffer} data
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
exports.hash256 = crypto.hash256;
|
||||
exports.hash256Async = crypto.hash256Async;
|
||||
|
||||
/**
|
||||
* Create an HMAC.
|
||||
* @function
|
||||
* @param {String} alg
|
||||
* @param {Buffer} data
|
||||
* @param {Buffer} key
|
||||
* @returns {Buffer} HMAC
|
||||
*/
|
||||
|
||||
exports.hmac = crypto.hmac;
|
||||
exports.hmacAsync = crypto.hmacAsync;
|
||||
|
||||
/**
|
||||
* Perform key derivation using PBKDF2.
|
||||
* @function
|
||||
* @param {Buffer} key
|
||||
* @param {Buffer} salt
|
||||
* @param {Number} iter
|
||||
* @param {Number} len
|
||||
* @param {String} alg
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
exports.pbkdf2 = crypto.pbkdf2;
|
||||
|
||||
/**
|
||||
* Execute pbkdf2 asynchronously.
|
||||
* @function
|
||||
* @param {Buffer} key
|
||||
* @param {Buffer} salt
|
||||
* @param {Number} iter
|
||||
* @param {Number} len
|
||||
* @param {String} alg
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
exports.pbkdf2Async = crypto.pbkdf2Async;
|
||||
|
||||
/**
|
||||
* Perform key derivation using scrypt.
|
||||
* @function
|
||||
* @param {Buffer} passwd
|
||||
* @param {Buffer} salt
|
||||
* @param {Number} N
|
||||
* @param {Number} r
|
||||
* @param {Number} p
|
||||
* @param {Number} len
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
exports.scrypt = crypto.scrypt;
|
||||
|
||||
/**
|
||||
* Execute scrypt asynchronously.
|
||||
* @function
|
||||
* @param {Buffer} passwd
|
||||
* @param {Buffer} salt
|
||||
* @param {Number} N
|
||||
* @param {Number} r
|
||||
* @param {Number} p
|
||||
* @param {Number} len
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
exports.scryptAsync = crypto.scryptAsync;
|
||||
|
||||
/**
|
||||
* Perform hkdf extraction.
|
||||
* @function
|
||||
* @param {Buffer} ikm
|
||||
* @param {Buffer} key
|
||||
* @param {String} alg
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
exports.hkdfExtract = crypto.hkdfExtract;
|
||||
|
||||
/**
|
||||
* Perform hkdf expansion.
|
||||
* @function
|
||||
* @param {Buffer} prk
|
||||
* @param {Buffer} info
|
||||
* @param {Number} len
|
||||
* @param {String} alg
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
exports.hkdfExpand = crypto.hkdfExpand;
|
||||
|
||||
/**
|
||||
* Build a merkle tree from leaves.
|
||||
* Note that this will mutate the `leaves` array!
|
||||
* @function
|
||||
* @param {Buffer[]} leaves
|
||||
* @returns {MerkleTree}
|
||||
*/
|
||||
|
||||
exports.createMerkleTree = crypto.createMerkleTree;
|
||||
|
||||
/**
|
||||
* Calculate merkle root from leaves.
|
||||
* @function
|
||||
* @param {Buffer[]} leaves
|
||||
* @returns {MerkleRoot}
|
||||
*/
|
||||
|
||||
exports.createMerkleRoot = crypto.createMerkleRoot;
|
||||
|
||||
/**
|
||||
* Collect a merkle branch at vector index.
|
||||
* @function
|
||||
* @param {Number} index
|
||||
* @param {Buffer[]} leaves
|
||||
* @returns {Buffer[]} branch
|
||||
*/
|
||||
|
||||
exports.createMerkleBranch = crypto.createMerkleBranch;
|
||||
|
||||
/**
|
||||
* Check a merkle branch at vector index.
|
||||
* @function
|
||||
* @param {Buffer} hash
|
||||
* @param {Buffer[]} branch
|
||||
* @param {Number} index
|
||||
* @returns {Buffer} Hash.
|
||||
*/
|
||||
|
||||
exports.verifyMerkleBranch = crypto.verifyMerkleBranch;
|
||||
|
||||
/**
|
||||
* Encrypt with aes-256-cbc.
|
||||
* @function
|
||||
* @param {Buffer} data
|
||||
* @param {Buffer} key - 256 bit key.
|
||||
* @param {Buffer} iv - 128 bit initialization vector.
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
exports.encipher = crypto.encipher;
|
||||
|
||||
/**
|
||||
* Decrypt with aes-256-cbc.
|
||||
* @function
|
||||
* @param {Buffer} data
|
||||
* @param {Buffer} key - 256 bit key.
|
||||
* @param {Buffer} iv - 128 bit initialization vector.
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
exports.decipher = crypto.decipher;
|
||||
|
||||
/**
|
||||
* memcmp in constant time (can only return true or false).
|
||||
* This protects us against timing attacks when
|
||||
* comparing an input against a secret string.
|
||||
* @function
|
||||
* @see https://cryptocoding.net/index.php/Coding_rules
|
||||
* @see `$ man 3 memcmp` (NetBSD's consttime_memequal)
|
||||
* @param {Buffer} a
|
||||
* @param {Buffer} b
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
exports.ccmp = crypto.ccmp;
|
||||
|
||||
/**
|
||||
* A maybe-secure memzero.
|
||||
* @function
|
||||
* @param {Buffer} data
|
||||
*/
|
||||
|
||||
exports.cleanse = crypto.cleanse;
|
||||
|
||||
/**
|
||||
* Generate some random bytes.
|
||||
* @function
|
||||
* @param {Number} size
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
exports.randomBytes = crypto.randomBytes;
|
||||
|
||||
/**
|
||||
* Generate a random uint32.
|
||||
* Probably more cryptographically sound than
|
||||
* `Math.random()`.
|
||||
* @function
|
||||
* @returns {Number}
|
||||
*/
|
||||
|
||||
exports.randomInt = crypto.randomInt;
|
||||
|
||||
/**
|
||||
* Generate a random number within a range.
|
||||
* Probably more cryptographically sound than
|
||||
* `Math.random()`.
|
||||
* @function
|
||||
* @param {Number} min - Inclusive.
|
||||
* @param {Number} max - Exclusive.
|
||||
* @returns {Number}
|
||||
*/
|
||||
|
||||
exports.randomRange = crypto.randomRange;
|
||||
|
||||
/**
|
||||
* chachapoly module
|
||||
* @see module:crypto/chachapoly
|
||||
*/
|
||||
|
||||
exports.chachapoly = require('./chachapoly');
|
||||
|
||||
/**
|
||||
* ChaCha20
|
||||
* @see module:crypto/chachapoly.ChaCha20
|
||||
*/
|
||||
|
||||
exports.ChaCha20 = exports.chachapoly.ChaCha20;
|
||||
|
||||
/**
|
||||
* Poly1305
|
||||
* @see module:crypto/chachapoly.Poly1305
|
||||
*/
|
||||
|
||||
exports.Poly1305 = exports.chachapoly.Poly1305;
|
||||
|
||||
/**
|
||||
* AEAD
|
||||
* @see module:crypto/chachapoly.AEAD
|
||||
*/
|
||||
|
||||
exports.AEAD = exports.chachapoly.AEAD;
|
||||
|
||||
/**
|
||||
* pk module
|
||||
* @see module:crypto/pk
|
||||
*/
|
||||
|
||||
exports.pk = require('./pk');
|
||||
exports.dsa = exports.pk.rsa;
|
||||
exports.rsa = exports.pk.dsa;
|
||||
|
||||
/**
|
||||
* RSA
|
||||
* @see module:crypto/pk.rsa
|
||||
*/
|
||||
|
||||
exports.rsa = exports.pk.rsa;
|
||||
|
||||
/**
|
||||
* ECDSA
|
||||
* @see module:crypto/pk.ecdsa
|
||||
*/
|
||||
|
||||
exports.ecdsa = exports.pk.ecdsa;
|
||||
|
||||
/**
|
||||
* ec module
|
||||
* @see module:crypto/ec
|
||||
*/
|
||||
|
||||
exports.ec = require('./ec');
|
||||
|
||||
/**
|
||||
* schnorr module
|
||||
* @see module:crypto/schnorr
|
||||
*/
|
||||
|
||||
exports.schnorr = require('./schnorr');
|
||||
|
||||
/**
|
||||
* siphash module
|
||||
* @see module:crypto/siphash
|
||||
*/
|
||||
|
||||
exports.siphash = require('./siphash');
|
||||
|
||||
/**
|
||||
* siphash256
|
||||
* @see module:crypto/siphash.siphash256
|
||||
*/
|
||||
|
||||
exports.siphash256 = exports.siphash.siphash256;
|
||||
|
||||
@ -1,11 +1,16 @@
|
||||
/*!
|
||||
* pk-browser.js - public key algorithms for bcoin
|
||||
* Copyright (c) 2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module crypto/pk-browser
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
var assert = require('assert');
|
||||
var BN = require('bn.js');
|
||||
var elliptic = require('elliptic');
|
||||
@ -13,12 +18,20 @@ var ASN1 = require('../utils/asn1');
|
||||
var backend = require('./backend');
|
||||
var rsa, ecdsa;
|
||||
|
||||
/*
|
||||
/**
|
||||
* RSA
|
||||
* @namespace module:crypto/pk-browser.rsa
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
rsa = {};
|
||||
|
||||
/**
|
||||
* PKCS signature prefixes.
|
||||
* @type {Object}
|
||||
* @memberof module:crypto/pk-browser.rsa
|
||||
*/
|
||||
|
||||
rsa.prefixes = {
|
||||
md5: new Buffer('3020300c06082a864886f70d020505000410', 'hex'),
|
||||
sha1: new Buffer('3021300906052b0e03021a05000414', 'hex'),
|
||||
@ -29,6 +42,16 @@ rsa.prefixes = {
|
||||
ripemd160: new Buffer('30203008060628cf060300310414', 'hex')
|
||||
};
|
||||
|
||||
/**
|
||||
* Verify RSA signature.
|
||||
* @memberof module:crypto/pk-browser.rsa
|
||||
* @param {String} alg - Hash algorithm.
|
||||
* @param {Buffer} msg - Signed message.
|
||||
* @param {Buffer} sig - Signature.
|
||||
* @param {Buffer} key - ASN1 serialized RSA key.
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
rsa.verify = function verify(alg, msg, sig, key) {
|
||||
var prefix = rsa.prefixes[alg];
|
||||
var hash, len, pub;
|
||||
@ -63,6 +86,15 @@ rsa.verify = function verify(alg, msg, sig, key) {
|
||||
return ok === 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sign message with RSA key.
|
||||
* @memberof module:crypto/pk-browser.rsa
|
||||
* @param {String} alg - Hash algorithm.
|
||||
* @param {Buffer} msg - Signed message.
|
||||
* @param {Buffer} key - ASN1 serialized RSA key.
|
||||
* @returns {Buffer} Signature (DER)
|
||||
*/
|
||||
|
||||
rsa.sign = function sign(alg, msg, key) {
|
||||
var prefix = rsa.prefixes[alg];
|
||||
var hash, len, priv;
|
||||
@ -95,6 +127,15 @@ rsa.sign = function sign(alg, msg, key) {
|
||||
return rsa.decrypt(N, D, em);
|
||||
};
|
||||
|
||||
/**
|
||||
* Decrypt with modulus and exponent.
|
||||
* @memberof module:crypto/pk-browser.rsa
|
||||
* @param {BN} N
|
||||
* @param {BN} D
|
||||
* @param {Buffer} m
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
rsa.decrypt = function decrypt(N, D, m) {
|
||||
var c = new BN(m);
|
||||
|
||||
@ -108,6 +149,15 @@ rsa.decrypt = function decrypt(N, D, m) {
|
||||
.toArrayLike(Buffer, 'be');
|
||||
};
|
||||
|
||||
/**
|
||||
* Encrypt with modulus and exponent.
|
||||
* @memberof module:crypto/pk-browser.rsa
|
||||
* @param {BN} N
|
||||
* @param {BN} e
|
||||
* @param {Buffer} m
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
rsa.encrypt = function encrypt(N, e, m) {
|
||||
return new BN(m)
|
||||
.toRed(BN.red(N))
|
||||
@ -116,13 +166,26 @@ rsa.encrypt = function encrypt(N, e, m) {
|
||||
.toArrayLike(Buffer, 'be');
|
||||
};
|
||||
|
||||
/*
|
||||
/**
|
||||
* ECDSA
|
||||
* @namespace module:crypto/pk.ecdsa
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
ecdsa = {};
|
||||
|
||||
ecdsa.verify = function verify(curve, alg, msg, key, sig) {
|
||||
/**
|
||||
* Verify ECDSA signature.
|
||||
* @memberof module:crypto/pk-browser.ecdsa
|
||||
* @param {String} curve - Curve name.
|
||||
* @param {String} alg - Hash algorithm.
|
||||
* @param {Buffer} msg - Signed message.
|
||||
* @param {Buffer} sig - Signature.
|
||||
* @param {Buffer} key - ASN1 serialized ECDSA key.
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
ecdsa.verify = function verify(curve, alg, msg, sig, key) {
|
||||
var ec, hash;
|
||||
|
||||
assert(curve, 'No curve selected.');
|
||||
@ -133,6 +196,16 @@ ecdsa.verify = function verify(curve, alg, msg, key, sig) {
|
||||
return ec.verify(hash, sig, key);
|
||||
};
|
||||
|
||||
/**
|
||||
* Sign message with ECDSA key.
|
||||
* @memberof module:crypto/pk-browser.ecdsa
|
||||
* @param {String} curve - Curve name.
|
||||
* @param {String} alg - Hash algorithm.
|
||||
* @param {Buffer} msg - Signed message.
|
||||
* @param {Buffer} key - ASN1 serialized ECDSA key.
|
||||
* @returns {Buffer} Signature (DER)
|
||||
*/
|
||||
|
||||
ecdsa.sign = function sign(curve, alg, msg, key) {
|
||||
var ec, hash;
|
||||
|
||||
|
||||
@ -1,11 +1,15 @@
|
||||
/*!
|
||||
* pk.js - public key algorithms for bcoin
|
||||
* Copyright (c) 2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module crypto/pk
|
||||
*/
|
||||
|
||||
var assert = require('assert');
|
||||
var nodeCrypto = require('crypto');
|
||||
var elliptic = require('elliptic');
|
||||
@ -13,29 +17,61 @@ var PEM = require('../utils/pem');
|
||||
var backend = require('./backend');
|
||||
var rsa, ecdsa;
|
||||
|
||||
/*
|
||||
/**
|
||||
* RSA
|
||||
* @namespace module:crypto/pk.rsa
|
||||
*/
|
||||
|
||||
rsa = {};
|
||||
|
||||
/**
|
||||
* Verify RSA signature.
|
||||
* @memberof module:crypto/pk.rsa
|
||||
* @param {String} alg - Hash algorithm.
|
||||
* @param {Buffer} msg - Signed message.
|
||||
* @param {Buffer} sig - Signature.
|
||||
* @param {Buffer} key - ASN1 serialized RSA key.
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
rsa.verify = function _verify(alg, msg, sig, key) {
|
||||
var pem = toPEM('rsa', key, null, 'public key');
|
||||
return verify('rsa', alg, msg, sig, pem);
|
||||
};
|
||||
|
||||
/**
|
||||
* Sign message with RSA key.
|
||||
* @memberof module:crypto/pk.rsa
|
||||
* @param {String} alg - Hash algorithm.
|
||||
* @param {Buffer} msg - Signed message.
|
||||
* @param {Buffer} key - ASN1 serialized RSA key.
|
||||
* @returns {Buffer} Signature (DER)
|
||||
*/
|
||||
|
||||
rsa.sign = function _sign(alg, msg, key) {
|
||||
var pem = toPEM('rsa', key, null, 'private key');
|
||||
return sign('rsa', alg, msg, pem);
|
||||
};
|
||||
|
||||
/*
|
||||
/**
|
||||
* ECDSA
|
||||
* @namespace module:crypto/pk.ecdsa
|
||||
*/
|
||||
|
||||
ecdsa = {};
|
||||
|
||||
ecdsa.verify = function verify(curve, msg, alg, key, sig) {
|
||||
/**
|
||||
* Verify ECDSA signature.
|
||||
* @memberof module:crypto/pk.ecdsa
|
||||
* @param {String} curve - Curve name.
|
||||
* @param {String} alg - Hash algorithm.
|
||||
* @param {Buffer} msg - Signed message.
|
||||
* @param {Buffer} sig - Signature.
|
||||
* @param {Buffer} key - ASN1 serialized ECDSA key.
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
ecdsa.verify = function verify(curve, alg, msg, sig, key) {
|
||||
var ec, hash;
|
||||
|
||||
assert(curve, 'No curve selected.');
|
||||
@ -46,7 +82,17 @@ ecdsa.verify = function verify(curve, msg, alg, key, sig) {
|
||||
return ec.verify(hash, sig, key);
|
||||
};
|
||||
|
||||
ecdsa.sign = function sign(curve, msg, alg, key) {
|
||||
/**
|
||||
* Sign message with ECDSA key.
|
||||
* @memberof module:crypto/pk.ecdsa
|
||||
* @param {String} curve - Curve name.
|
||||
* @param {String} alg - Hash algorithm.
|
||||
* @param {Buffer} msg - Signed message.
|
||||
* @param {Buffer} key - ASN1 serialized ECDSA key.
|
||||
* @returns {Buffer} Signature (DER)
|
||||
*/
|
||||
|
||||
ecdsa.sign = function sign(curve, alg, msg, key) {
|
||||
var ec, hash;
|
||||
|
||||
assert(curve, 'No curve selected.');
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* schnorr.js - schnorr signatures for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -17,7 +17,7 @@ var curves = elliptic.curves;
|
||||
var hash = curves.secp256k1.hash;
|
||||
|
||||
/**
|
||||
* @exports schnorr
|
||||
* @exports crypto/schnorr
|
||||
*/
|
||||
|
||||
var schnorr = exports;
|
||||
@ -47,6 +47,7 @@ schnorr.hash = function _hash(msg, r, hash) {
|
||||
|
||||
/**
|
||||
* Sign message.
|
||||
* @private
|
||||
* @param {Buffer} msg
|
||||
* @param {BN} priv
|
||||
* @param {BN} k
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* scrypt.js - scrypt for bcoin
|
||||
* Copyright (c) 2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*
|
||||
* Ported from:
|
||||
@ -33,6 +33,11 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module crypto/scrypt
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
var co = require('../utils/co');
|
||||
var backend = require('./backend');
|
||||
var native = require('../utils/native').binding;
|
||||
@ -41,8 +46,9 @@ var scryptAsync, smixAsync;
|
||||
|
||||
/**
|
||||
* Javascript scrypt implementation. Scrypt is
|
||||
* used in bip38. BCoin doesn't support bip38
|
||||
* used in bip38. Bcoin doesn't support bip38
|
||||
* yet, but here it is, just in case.
|
||||
* @alias module:crypto/scrypt.scrypt
|
||||
* @param {Buffer} passwd
|
||||
* @param {Buffer} salt
|
||||
* @param {Number} N
|
||||
@ -198,6 +204,8 @@ function blkxor(dest, src, s1, s2, len) {
|
||||
|
||||
/**
|
||||
* Asynchronous scrypt implementation.
|
||||
* @alias module:crypto/scrypt.scryptAsync
|
||||
* @function
|
||||
* @param {Buffer} passwd
|
||||
* @param {Buffer} salt
|
||||
* @param {Number} N
|
||||
|
||||
@ -1,12 +1,17 @@
|
||||
/*!
|
||||
* sha256.js - SHA256 implementation for bcoin
|
||||
* Copyright (c) 2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
* Parts of this software based on hash.js.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module crypto/sha256
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
@ -41,6 +46,7 @@ K = [
|
||||
|
||||
/**
|
||||
* SHA256
|
||||
* @alias module:crypto/sha256.SHA256
|
||||
* @constructor
|
||||
* @property {Number[]} s
|
||||
* @property {Number[]} w
|
||||
@ -225,6 +231,7 @@ SHA256.prototype.transform = function transform(chunk, pos) {
|
||||
|
||||
/**
|
||||
* SHA256Hmac
|
||||
* @alias module:crypto/sha256.SHA256Hmac
|
||||
* @constructor
|
||||
* @property {SHA256} inner
|
||||
* @property {SHA256} outer
|
||||
@ -339,12 +346,26 @@ function readU32(buf, offset) {
|
||||
ctx = new SHA256();
|
||||
mctx = new SHA256Hmac();
|
||||
|
||||
/**
|
||||
* Hash buffer with sha256.
|
||||
* @alias module:crypto/sha256.sha256
|
||||
* @param {Buffer} data
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
function sha256(data) {
|
||||
ctx.init();
|
||||
ctx.update(data);
|
||||
return ctx.finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash buffer with double sha256.
|
||||
* @alias module:crypto/sha256.hash256
|
||||
* @param {Buffer} data
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
function hash256(data) {
|
||||
var out = new Buffer(32);
|
||||
ctx.init();
|
||||
@ -356,6 +377,14 @@ function hash256(data) {
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a sha256 HMAC from buffer and key.
|
||||
* @alias module:crypto/sha256.hmac
|
||||
* @param {Buffer} data
|
||||
* @param {Buffer} key
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
function hmac(data, key) {
|
||||
mctx.init(key);
|
||||
mctx.update(data);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* siphash.js - siphash for bcoin
|
||||
* Copyright (c) 2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*
|
||||
* Ported from:
|
||||
@ -9,10 +9,15 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module crypto/siphash
|
||||
*/
|
||||
|
||||
var native = require('../utils/native').binding;
|
||||
|
||||
/**
|
||||
* Javascript siphash implementation. Used for compact block relay.
|
||||
* @alias module:crypto/siphash.siphash24
|
||||
* @param {Buffer} data
|
||||
* @param {Buffer} key - 128 bit key.
|
||||
* @returns {Buffer} uint64le
|
||||
@ -110,10 +115,26 @@ function sipround(v0, v1, v2, v3) {
|
||||
v2.rotl(32);
|
||||
}
|
||||
|
||||
/**
|
||||
* Javascript siphash implementation. Used for compact block relay.
|
||||
* @alias module:crypto/siphash.siphash
|
||||
* @param {Buffer} data
|
||||
* @param {Buffer} key - 128 bit key.
|
||||
* @returns {Buffer} uint64le
|
||||
*/
|
||||
|
||||
function siphash(data, key) {
|
||||
return siphash24(data, key, 56);
|
||||
}
|
||||
|
||||
/**
|
||||
* Javascript siphash implementation. Used for compact block relay.
|
||||
* @alias module:crypto/siphash.siphash256
|
||||
* @param {Buffer} data
|
||||
* @param {Buffer} key - 128 bit key.
|
||||
* @returns {Buffer} uint64le
|
||||
*/
|
||||
|
||||
function siphash256(data, key) {
|
||||
return siphash24(data, key, 59);
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* backends-browser.js - database backends for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* backends.js - database backends for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module db
|
||||
*/
|
||||
|
||||
exports.LDB = require('./ldb');
|
||||
exports.LowlevelUp = require('./lowlevelup');
|
||||
exports.RBT = require('./rbt');
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* ldb.js - database backend for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -13,6 +13,8 @@ var util = require('../utils/util');
|
||||
var backends = require('./backends');
|
||||
|
||||
/**
|
||||
* Create a database.
|
||||
* @alias module:db.LDB
|
||||
* @param {Object} options
|
||||
* @param {Boolean} options.compression
|
||||
* @param {Number} options.cacheSize
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
/**
|
||||
* LevelUP module for bcoin
|
||||
* @module lowlevelup
|
||||
* @license
|
||||
/*!
|
||||
* lowlevelup.js - LevelUP module for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -25,7 +23,7 @@ var VERSION_ERROR;
|
||||
* This avoids pulling in extra deps and
|
||||
* lowers memory usage.
|
||||
*
|
||||
* @expose LowlevelUp
|
||||
* @alias module:db.LowlevelUp
|
||||
* @constructor
|
||||
* @param {String} file - Location.
|
||||
* @param {Object} options - Leveldown options.
|
||||
@ -286,6 +284,7 @@ LowlevelUp.prototype.approximateSize = function approximateSize(start, end) {
|
||||
|
||||
/**
|
||||
* Test whether a key exists.
|
||||
* @method
|
||||
* @param {String} key
|
||||
* @returns {Promise} - Returns Boolean.
|
||||
*/
|
||||
@ -297,6 +296,7 @@ LowlevelUp.prototype.has = co(function* has(key) {
|
||||
|
||||
/**
|
||||
* Collect all keys from iterator options.
|
||||
* @method
|
||||
* @param {Object} options - Iterator options.
|
||||
* @returns {Promise} - Returns Array.
|
||||
*/
|
||||
@ -337,6 +337,7 @@ LowlevelUp.prototype.range = co(function* range(options) {
|
||||
|
||||
/**
|
||||
* Collect all keys from iterator options.
|
||||
* @method
|
||||
* @param {Object} options - Iterator options.
|
||||
* @returns {Promise} - Returns Array.
|
||||
*/
|
||||
@ -379,6 +380,7 @@ LowlevelUp.prototype.keys = co(function* keys(options) {
|
||||
|
||||
/**
|
||||
* Collect all keys from iterator options.
|
||||
* @method
|
||||
* @param {Object} options - Iterator options.
|
||||
* @returns {Promise} - Returns Array.
|
||||
*/
|
||||
@ -421,6 +423,7 @@ LowlevelUp.prototype.values = co(function* values(options) {
|
||||
|
||||
/**
|
||||
* Dump database (for debugging).
|
||||
* @method
|
||||
* @returns {Promise} - Returns Object.
|
||||
*/
|
||||
|
||||
@ -445,6 +448,7 @@ LowlevelUp.prototype.dump = co(function* dump() {
|
||||
|
||||
/**
|
||||
* Write and assert a version number for the database.
|
||||
* @method
|
||||
* @param {Number} version
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -467,6 +471,7 @@ LowlevelUp.prototype.checkVersion = co(function* checkVersion(key, version) {
|
||||
|
||||
/**
|
||||
* Clone the database.
|
||||
* @method
|
||||
* @param {String} path
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -524,6 +529,7 @@ LowlevelUp.prototype.clone = co(function* clone(path) {
|
||||
/**
|
||||
* Batch
|
||||
* @constructor
|
||||
* @ignore
|
||||
* @param {LowlevelUp} db
|
||||
*/
|
||||
|
||||
@ -576,6 +582,7 @@ Batch.prototype.clear = function clear() {
|
||||
/**
|
||||
* Iterator
|
||||
* @constructor
|
||||
* @ignore
|
||||
* @param {LowlevelUp} db
|
||||
* @param {Object} options
|
||||
*/
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* rbt.js - iterative red black tree for bcoin
|
||||
* Copyright (c) 2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -18,7 +18,7 @@ var SENTINEL;
|
||||
* Many of its options, parameters,
|
||||
* and methods mimic the leveldown
|
||||
* interface.
|
||||
* @exports RBT
|
||||
* @alias module:db.RBT
|
||||
* @constructor
|
||||
* @param {String?} location - Phony location.
|
||||
* @param {Object?} options
|
||||
@ -769,6 +769,7 @@ RBT.repair = function repair(location, callback) {
|
||||
/**
|
||||
* RBT Node
|
||||
* @constructor
|
||||
* @ignore
|
||||
* @private
|
||||
* @param {Buffer} key
|
||||
* @param {Buffer} value
|
||||
@ -840,6 +841,7 @@ RBTNode.prototype.isNull = function isNull() {
|
||||
/**
|
||||
* RBT Sentinel Node
|
||||
* @constructor
|
||||
* @ignore
|
||||
* @property {null} key
|
||||
* @property {null} value
|
||||
* @property {Number} [color=BLACK]
|
||||
@ -879,6 +881,7 @@ RBTSentinel.prototype.isNull = function isNull() {
|
||||
/**
|
||||
* RBT key/value pair
|
||||
* @constructor
|
||||
* @ignore
|
||||
* @param {Buffer} key
|
||||
* @param {Buffer} value
|
||||
* @property {Buffer} key
|
||||
@ -905,6 +908,7 @@ RBTData.prototype.inspect = function inspect() {
|
||||
/**
|
||||
* Batch
|
||||
* @constructor
|
||||
* @ignore
|
||||
* @private
|
||||
* @param {RBT} tree
|
||||
* @param {Object?} options
|
||||
@ -994,6 +998,7 @@ Batch.prototype.clear = function clear() {
|
||||
/**
|
||||
* Batch Operation
|
||||
* @constructor
|
||||
* @ignore
|
||||
* @private
|
||||
* @param {String} type
|
||||
* @param {Buffer} key
|
||||
@ -1009,6 +1014,7 @@ function BatchOp(type, key, value) {
|
||||
/**
|
||||
* Iterator
|
||||
* @constructor
|
||||
* @ignore
|
||||
* @private
|
||||
* @param {RBT} tree
|
||||
* @param {Object?} options
|
||||
|
||||
114
lib/env.js
114
lib/env.js
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* env.js - environment for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License).
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -10,11 +10,120 @@
|
||||
var lazy = require('./utils/lazy');
|
||||
|
||||
/**
|
||||
* A BCoin "environment" which exposes all
|
||||
* A bcoin "environment" which exposes all
|
||||
* constructors for primitives, the blockchain,
|
||||
* mempool, wallet, etc. It also exposes a
|
||||
* global worker pool.
|
||||
* @exports Environment
|
||||
* @constructor
|
||||
* @property {Function} env - See {@link Environment}.
|
||||
* @property {Function} require - See {@link module:utils/lazy}.
|
||||
*
|
||||
* @property {Function} bn - See {@url https://github.com/indutny/bn.js}.
|
||||
* @property {Object} elliptic - See {@url https://github.com/indutny/elliptic}.
|
||||
*
|
||||
* @property {Object} bip70 - See {@link module:bip70}.
|
||||
*
|
||||
* @property {Object} blockchain - See {@link module:blockchain}.
|
||||
* @property {Function} chain - See {@link module:blockchain.Chain}.
|
||||
* @property {Function} chaindb - See {@link module:blockchain.ChainDB}.
|
||||
* @property {Function} chainentry - See {@link module:blockchain.ChainEntry}.
|
||||
*
|
||||
* @property {Object} btc
|
||||
* @property {Function} amount
|
||||
* @property {Function} uri
|
||||
*
|
||||
* @property {Object} coins
|
||||
* @property {Function} coinview
|
||||
*
|
||||
* @property {Object} crypto
|
||||
* @property {Object} ec
|
||||
* @property {Object} pk
|
||||
* @property {Object} schnorr
|
||||
*
|
||||
* @property {Object} db
|
||||
* @property {Object} ldb
|
||||
*
|
||||
* @property {Object} hd
|
||||
*
|
||||
* @property {Object} http
|
||||
* @property {Object} rpc
|
||||
*
|
||||
* @property {Object} txmempool
|
||||
* @property {Object} fees
|
||||
* @property {Object} mempool
|
||||
* @property {Object} mempoolentry
|
||||
*
|
||||
* @property {Object} mining
|
||||
* @property {Object} miner
|
||||
* @property {Object} minerblock
|
||||
*
|
||||
* @property {Object} net
|
||||
* @property {Object} bip150
|
||||
* @property {Object} bip151
|
||||
* @property {Object} bip152
|
||||
* @property {Object} dns
|
||||
* @property {Object} packets
|
||||
* @property {Object} peer
|
||||
* @property {Object} pool
|
||||
* @property {Object} tcp
|
||||
*
|
||||
* @property {Object} node
|
||||
* @property {Object} config
|
||||
* @property {Object} fullnode
|
||||
* @property {Object} logger
|
||||
* @property {Object} spvnode
|
||||
*
|
||||
* @property {Object} primitives
|
||||
* @property {Object} address
|
||||
* @property {Object} block
|
||||
* @property {Object} coin
|
||||
* @property {Object} headers
|
||||
* @property {Object} input
|
||||
* @property {Object} invitem
|
||||
* @property {Object} keyring
|
||||
* @property {Object} merkleblock
|
||||
* @property {Object} mtx
|
||||
* @property {Object} netaddress
|
||||
* @property {Object} outpoint
|
||||
* @property {Object} output
|
||||
* @property {Object} tx
|
||||
*
|
||||
* @property {Object} protocol
|
||||
* @property {Object} consensus
|
||||
* @property {Object} errors
|
||||
* @property {Object} network
|
||||
* @property {Object} networks
|
||||
* @property {Object} policy
|
||||
* @property {Object} timedata
|
||||
*
|
||||
* @property {Object} txscript
|
||||
* @property {Object} opcodes
|
||||
* @property {Object} program
|
||||
* @property {Object} script
|
||||
* @property {Object} sigcache
|
||||
* @property {Object} stack
|
||||
* @property {Object} witness
|
||||
*
|
||||
* @property {Object} utils
|
||||
* @property {Object} base32
|
||||
* @property {Object} base58
|
||||
* @property {Object} bloom
|
||||
* @property {Object} co
|
||||
* @property {Object} encoding
|
||||
* @property {Object} lock
|
||||
* @property {Object} reader
|
||||
* @property {Object} staticwriter
|
||||
* @property {Object} util
|
||||
* @property {Object} writer
|
||||
*
|
||||
* @property {Object} wallet
|
||||
* @property {Object} path
|
||||
* @property {Object} walletkey
|
||||
* @property {Object} walletdb
|
||||
*
|
||||
* @property {Object} workers
|
||||
* @property {Object} workerpool
|
||||
*/
|
||||
|
||||
function Environment() {
|
||||
@ -125,6 +234,7 @@ function Environment() {
|
||||
|
||||
// Utils
|
||||
this.require('utils', './utils');
|
||||
this.require('base32', './utils/base32');
|
||||
this.require('base58', './utils/base58');
|
||||
this.require('bloom', './utils/bloom');
|
||||
this.require('co', './utils/co');
|
||||
|
||||
@ -12,7 +12,7 @@ var HDPrivateKey = require('./private');
|
||||
var HDPublicKey = require('./public');
|
||||
|
||||
/**
|
||||
* @exports HD
|
||||
* @exports hd
|
||||
*/
|
||||
|
||||
var HD = exports;
|
||||
|
||||
@ -18,7 +18,7 @@ var nfkd = require('../utils/nfkd');
|
||||
|
||||
/**
|
||||
* HD Mnemonic
|
||||
* @exports Mnemonic
|
||||
* @alias module:hd.Mnemonic
|
||||
* @constructor
|
||||
* @param {Object} options
|
||||
* @param {Number?} options.bit - Bits of entropy (Must
|
||||
|
||||
@ -23,7 +23,7 @@ var HDPublicKey = require('./public');
|
||||
|
||||
/**
|
||||
* HDPrivateKey
|
||||
* @exports HDPrivateKey
|
||||
* @alias module:hd.PrivateKey
|
||||
* @constructor
|
||||
* @param {Object|Base58String} options
|
||||
* @param {Base58String?} options.xkey - Serialized base58 key.
|
||||
|
||||
@ -20,7 +20,7 @@ var common = require('./common');
|
||||
|
||||
/**
|
||||
* HDPublicKey
|
||||
* @exports HDPublicKey
|
||||
* @alias module:hd.PublicKey
|
||||
* @constructor
|
||||
* @param {Object|Base58String} options
|
||||
* @param {Base58String?} options.xkey - Serialized base58 key.
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* http.js - http server for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -15,7 +15,7 @@ var co = require('../utils/co');
|
||||
|
||||
/**
|
||||
* HTTPBase
|
||||
* @exports HTTPBase
|
||||
* @alias module:http.Base
|
||||
* @constructor
|
||||
* @param {Object?} options
|
||||
* @emits HTTPBase#websocket
|
||||
@ -486,6 +486,7 @@ HTTPBase.prototype.listen = function listen(port, host) {
|
||||
|
||||
/**
|
||||
* HTTP Base Options
|
||||
* @alias module:http.HTTPBaseOptions
|
||||
* @constructor
|
||||
* @param {Object} options
|
||||
*/
|
||||
@ -611,6 +612,7 @@ HTTPBaseOptions.prototype.toHTTP = function toHTTP() {
|
||||
/**
|
||||
* Route
|
||||
* @constructor
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
function Route(ctx, path, handler) {
|
||||
@ -711,6 +713,7 @@ Route.prototype.call = co(function* call(req, res) {
|
||||
/**
|
||||
* Routes
|
||||
* @constructor
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
function Routes() {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* client.js - http client for wallets
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -16,8 +16,8 @@ var co = require('../utils/co');
|
||||
var request = require('./request');
|
||||
|
||||
/**
|
||||
* BCoin HTTP client.
|
||||
* @exports HTTPClient
|
||||
* Bcoin HTTP client.
|
||||
* @alias module:http.Client
|
||||
* @constructor
|
||||
* @param {String} uri
|
||||
* @param {Object?} options
|
||||
|
||||
@ -1,12 +1,16 @@
|
||||
/*!
|
||||
* http/index.js - http for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module http
|
||||
*/
|
||||
|
||||
exports.request = require('./request');
|
||||
exports.Client = require('./client');
|
||||
exports.RPCClient = require('./rpcclient');
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* request.js - http request for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -22,6 +22,7 @@ var USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1)'
|
||||
/**
|
||||
* Request Options
|
||||
* @constructor
|
||||
* @ignore
|
||||
* @param {Object} options
|
||||
*/
|
||||
|
||||
@ -254,6 +255,7 @@ RequestOptions.prototype.toHTTP = function toHTTP() {
|
||||
/**
|
||||
* Request
|
||||
* @constructor
|
||||
* @private
|
||||
* @param {Object} options
|
||||
*/
|
||||
|
||||
@ -490,6 +492,7 @@ Request.prototype._onEnd = function _onEnd(err) {
|
||||
|
||||
/**
|
||||
* Make an HTTP request.
|
||||
* @alias module:http.request
|
||||
* @param {Object} options
|
||||
* @param {String} options.uri
|
||||
* @param {Object?} options.query
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* rpc.js - bitcoind-compatible json rpc for bcoin.
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -36,8 +36,10 @@ var consensus = require('../protocol/consensus');
|
||||
var pkg = require('../../package.json');
|
||||
|
||||
/**
|
||||
* RPC
|
||||
* Bitcoin Core RPC
|
||||
* @alias module:http.RPC
|
||||
* @constructor
|
||||
* @param {Node} node
|
||||
*/
|
||||
|
||||
function RPC(node) {
|
||||
@ -2762,7 +2764,7 @@ RPC.prototype.dumpwallet = co(function* dumpwallet(args) {
|
||||
file = toString(args[0]);
|
||||
time = util.date();
|
||||
out = [
|
||||
util.fmt('# Wallet Dump created by BCoin %s', pkg.version),
|
||||
util.fmt('# Wallet Dump created by Bcoin %s', pkg.version),
|
||||
util.fmt('# * Created on %s', time),
|
||||
util.fmt('# * Best block at time of backup was %d (%s),',
|
||||
this.chain.height, this.chain.tip.rhash()),
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* rpcclient.js - json rpc client for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -11,8 +11,8 @@ var request = require('./request');
|
||||
var co = require('../utils/co');
|
||||
|
||||
/**
|
||||
* BCoin RPC client.
|
||||
* @exports RPCClient
|
||||
* Bcoin RPC client.
|
||||
* @alias module:http.RPCClient
|
||||
* @constructor
|
||||
* @param {String} uri
|
||||
* @param {Object?} options
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* server.js - http server for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -33,7 +33,7 @@ var RPC;
|
||||
|
||||
/**
|
||||
* HTTPServer
|
||||
* @exports HTTPServer
|
||||
* @alias module:http.Server
|
||||
* @constructor
|
||||
* @param {Object} options
|
||||
* @param {Fullnode} options.node
|
||||
@ -1691,6 +1691,7 @@ HTTPServer.prototype.listen = function listen(port, host) {
|
||||
|
||||
/**
|
||||
* HTTPOptions
|
||||
* @alias module:http.HTTPOptions
|
||||
* @constructor
|
||||
* @param {Object} options
|
||||
*/
|
||||
@ -1820,6 +1821,7 @@ HTTPOptions.fromOptions = function fromOptions(options) {
|
||||
/**
|
||||
* ClientSocket
|
||||
* @constructor
|
||||
* @ignore
|
||||
* @param {HTTPServer} server
|
||||
* @param {SocketIO.Socket}
|
||||
*/
|
||||
@ -2230,6 +2232,7 @@ function getMemory() {
|
||||
/**
|
||||
* TimedCB
|
||||
* @constructor
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
function TimedCB(resolve, reject) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* wallet.js - http wallet for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -16,7 +16,7 @@ var Client = require('./client');
|
||||
|
||||
/**
|
||||
* HTTPWallet
|
||||
* @exports HTTPWallet
|
||||
* @alias module:http.Wallet
|
||||
* @constructor
|
||||
* @param {String} uri
|
||||
*/
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* fees.js - fee estimation for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
* Ported from:
|
||||
* https://github.com/bitcoin/bitcoin/blob/master/src/policy/fees.cpp
|
||||
@ -43,7 +43,7 @@ var FREE_THRESHOLD = policy.FREE_THRESHOLD;
|
||||
|
||||
/**
|
||||
* Confirmation stats.
|
||||
* @exports ConfirmStats
|
||||
* @alias module:mempool.ConfirmStats
|
||||
* @constructor
|
||||
* @param {String} type
|
||||
* @param {Logger} logger
|
||||
@ -398,7 +398,7 @@ ConfirmStats.fromRaw = function fromRaw(data, type, logger) {
|
||||
|
||||
/**
|
||||
* Estimator for fees and priority.
|
||||
* @exports PolicyEstimator
|
||||
* @alias module:mempool.PolicyEstimator
|
||||
* @constructor
|
||||
* @param {Rate} minRelay
|
||||
* @param {Network|NetworkType} network
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module mempool
|
||||
*/
|
||||
|
||||
exports.Mempool = require('./mempool');
|
||||
exports.MempoolEntry = require('./mempoolentry');
|
||||
exports.Fees = require('./fees');
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* mempool.js - mempool for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -29,7 +29,7 @@ var VerifyResult = errors.VerifyResult;
|
||||
|
||||
/**
|
||||
* Represents a mempool.
|
||||
* @exports Mempool
|
||||
* @alias module:mempool.Mempool
|
||||
* @constructor
|
||||
* @param {Object} options
|
||||
* @param {String?} options.name - Database name.
|
||||
@ -93,6 +93,7 @@ util.inherits(Mempool, AsyncObject);
|
||||
|
||||
/**
|
||||
* Open the chain, wait for the database to load.
|
||||
* @method
|
||||
* @alias Mempool#open
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -117,6 +118,7 @@ Mempool.prototype._close = function close() {
|
||||
* Notify the mempool that a new block has come
|
||||
* in (removes all transactions contained in the
|
||||
* block from the mempool).
|
||||
* @method
|
||||
* @param {ChainEntry} block
|
||||
* @param {TX[]} txs
|
||||
* @returns {Promise}
|
||||
@ -181,6 +183,7 @@ Mempool.prototype._addBlock = function addBlock(block, txs) {
|
||||
/**
|
||||
* Notify the mempool that a block has been disconnected
|
||||
* from the main chain (reinserts transactions into the mempool).
|
||||
* @method
|
||||
* @param {ChainEntry} block
|
||||
* @param {TX[]} txs
|
||||
* @returns {Promise}
|
||||
@ -198,6 +201,7 @@ Mempool.prototype.removeBlock = co(function* removeBlock(block, txs) {
|
||||
/**
|
||||
* Notify the mempool that a block
|
||||
* has been disconnected without a lock.
|
||||
* @method
|
||||
* @private
|
||||
* @param {ChainEntry} block
|
||||
* @param {TX[]} txs
|
||||
@ -238,6 +242,7 @@ Mempool.prototype._removeBlock = co(function* removeBlock(block, txs) {
|
||||
|
||||
/**
|
||||
* Reset the mempool.
|
||||
* @method
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -605,6 +610,7 @@ Mempool.prototype.hasReject = function hasReject(hash) {
|
||||
* Add a transaction to the mempool. Note that this
|
||||
* will lock the mempool until the transaction is
|
||||
* fully processed.
|
||||
* @method
|
||||
* @param {TX} tx
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -627,6 +633,7 @@ Mempool.prototype.addTX = co(function* addTX(tx) {
|
||||
|
||||
/**
|
||||
* Add a transaction to the mempool without a lock.
|
||||
* @method
|
||||
* @private
|
||||
* @param {TX} tx
|
||||
* @returns {Promise}
|
||||
@ -765,6 +772,7 @@ Mempool.prototype._addTX = co(function* _addTX(tx) {
|
||||
|
||||
/**
|
||||
* Verify a transaction with mempool standards.
|
||||
* @method
|
||||
* @param {TX} tx
|
||||
* @param {CoinView} view
|
||||
* @returns {Promise}
|
||||
@ -905,6 +913,7 @@ Mempool.prototype.verify = co(function* verify(entry, view) {
|
||||
/**
|
||||
* Verify inputs, return a boolean
|
||||
* instead of an error based on success.
|
||||
* @method
|
||||
* @param {TX} tx
|
||||
* @param {CoinView} view
|
||||
* @param {VerifyFlags} flags
|
||||
@ -925,6 +934,7 @@ Mempool.prototype.verifyResult = co(function* verifyResult(tx, view, flags) {
|
||||
/**
|
||||
* Verify inputs for standard
|
||||
* _and_ mandatory flags on failure.
|
||||
* @method
|
||||
* @param {TX} tx
|
||||
* @param {CoinView} view
|
||||
* @param {VerifyFlags} flags
|
||||
@ -958,6 +968,7 @@ Mempool.prototype.verifyInputs = co(function* verifyInputs(tx, view, flags) {
|
||||
* and may lend itself to race conditions if used unwisely.
|
||||
* This function will also resolve orphans if possible (the
|
||||
* resolved orphans _will_ be validated).
|
||||
* @method
|
||||
* @param {MempoolEntry} entry
|
||||
* @param {CoinView} view
|
||||
* @returns {Promise}
|
||||
@ -1328,6 +1339,7 @@ Mempool.prototype.storeOrphan = function storeOrphan(tx, missing) {
|
||||
|
||||
/**
|
||||
* Resolve orphans and attempt to add to mempool.
|
||||
* @method
|
||||
* @param {TX} tx
|
||||
* @returns {Promise} - Returns {@link TX}[].
|
||||
*/
|
||||
@ -1478,6 +1490,7 @@ Mempool.prototype.isDoubleSpend = function isDoubleSpend(tx) {
|
||||
|
||||
/**
|
||||
* Get coin viewpoint (lock).
|
||||
* @method
|
||||
* @param {TX} tx
|
||||
* @param {CoinView} view
|
||||
* @returns {Promise} - Returns {@link CoinView}.
|
||||
@ -1802,6 +1815,7 @@ Mempool.prototype.getSize = function getSize() {
|
||||
|
||||
/**
|
||||
* MempoolOptions
|
||||
* @alias module:mempool.MempoolOptions
|
||||
* @constructor
|
||||
* @param {Object}
|
||||
*/
|
||||
@ -1942,6 +1956,9 @@ MempoolOptions.fromOptions = function fromOptions(options) {
|
||||
|
||||
/**
|
||||
* TX Address Index
|
||||
* @constructor
|
||||
* @ignore
|
||||
* @param {Mempool} mempool
|
||||
*/
|
||||
|
||||
function TXIndex(mempool) {
|
||||
@ -2041,6 +2058,9 @@ TXIndex.prototype.remove = function remove(tx) {
|
||||
|
||||
/**
|
||||
* Coin Address Index
|
||||
* @constructor
|
||||
* @ignore
|
||||
* @param {Mempool} mempool
|
||||
*/
|
||||
|
||||
function CoinIndex(mempool) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* mempoolentry.js - mempool entry object for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -12,7 +12,7 @@ var Script = require('../script/script');
|
||||
|
||||
/**
|
||||
* Represents a mempool entry.
|
||||
* @exports MempoolEntry
|
||||
* @alias module:mempool.MempoolEntry
|
||||
* @constructor
|
||||
* @param {Object} options
|
||||
* @param {TX} options.tx - Transaction in mempool.
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module mining
|
||||
*/
|
||||
|
||||
exports.mine = require('./mine');
|
||||
exports.Miner = require('./miner');
|
||||
exports.MinerBlock = require('./minerblock');
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* mine.js - mining function for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -9,6 +9,7 @@ var crypto = require('../crypto/crypto');
|
||||
|
||||
/**
|
||||
* Hash until the nonce overflows.
|
||||
* @alias module:mining.mine
|
||||
* @param {Buffer} data
|
||||
* @param {Buffer} target - Big endian.
|
||||
* @param {Number} min
|
||||
@ -27,11 +28,10 @@ function mine(data, target, min, max) {
|
||||
if (rcmp(crypto.hash256(data), target) <= 0)
|
||||
return nonce;
|
||||
|
||||
// Increment the nonce to get a different hash
|
||||
// Increment the nonce to get a different hash.
|
||||
nonce++;
|
||||
|
||||
// Update the raw buffer (faster than
|
||||
// constantly serializing the headers).
|
||||
// Update the raw buffer.
|
||||
data.writeUInt32LE(nonce, 76, true);
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ function mine(data, target, min, max) {
|
||||
/**
|
||||
* "Reverse" comparison so we don't have
|
||||
* to waste time reversing the block hash.
|
||||
* @memberof Miner
|
||||
* @ignore
|
||||
* @param {Buffer} a
|
||||
* @param {Buffer} b
|
||||
* @returns {Number}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* miner.js - inefficient miner for bcoin (because we can)
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -20,11 +20,11 @@ var BlockEntry = MinerBlock.BlockEntry;
|
||||
|
||||
/**
|
||||
* A bitcoin miner (supports mining witness blocks).
|
||||
* @exports Miner
|
||||
* @alias module:mining.Miner
|
||||
* @constructor
|
||||
* @param {Object} options
|
||||
* @param {Base58Address} options.address - Payout address.
|
||||
* @param {String?} [options.coinbaseFlags="mined by bcoin"]
|
||||
* @param {Address} options.address - Payout address.
|
||||
* @param {String} [options.coinbaseFlags="mined by bcoin"]
|
||||
* @property {Boolean} running
|
||||
* @property {MinerBlock} attempt
|
||||
* @emits Miner#block
|
||||
@ -92,7 +92,8 @@ Miner.prototype._init = function _init() {
|
||||
|
||||
/**
|
||||
* Open the miner, wait for the chain and mempool to load.
|
||||
* @alias Miner#open
|
||||
* @method
|
||||
* @alias module:mining.Miner#open
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -108,7 +109,8 @@ Miner.prototype._open = co(function* open() {
|
||||
|
||||
/**
|
||||
* Close the miner.
|
||||
* @alias Miner#close
|
||||
* @method
|
||||
* @alias module:mining.Miner#close
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -126,7 +128,9 @@ Miner.prototype._close = co(function* close() {
|
||||
|
||||
/**
|
||||
* Start mining.
|
||||
* @method
|
||||
* @param {Number?} version - Custom block version.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
Miner.prototype.start = co(function* start() {
|
||||
@ -192,6 +196,8 @@ Miner.prototype.start = co(function* start() {
|
||||
|
||||
/**
|
||||
* Stop mining.
|
||||
* @method
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
Miner.prototype.stop = co(function* stop() {
|
||||
@ -214,6 +220,8 @@ Miner.prototype.stop = co(function* stop() {
|
||||
|
||||
/**
|
||||
* Wait for `done` event.
|
||||
* @private
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
Miner.prototype._onDone = function _onDone() {
|
||||
@ -225,6 +233,8 @@ Miner.prototype._onDone = function _onDone() {
|
||||
|
||||
/**
|
||||
* Wait for `stop` event.
|
||||
* @private
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
Miner.prototype._onStop = function _onStop() {
|
||||
@ -236,6 +246,7 @@ Miner.prototype._onStop = function _onStop() {
|
||||
|
||||
/**
|
||||
* Create a block "attempt".
|
||||
* @method
|
||||
* @param {ChainEntry} tip
|
||||
* @returns {Promise} - Returns {@link MinerBlock}.
|
||||
*/
|
||||
@ -251,6 +262,8 @@ Miner.prototype.createBlock = co(function* createBlock(tip, address) {
|
||||
|
||||
/**
|
||||
* Create a block "attempt" (without a lock).
|
||||
* @method
|
||||
* @private
|
||||
* @param {ChainEntry} tip
|
||||
* @returns {Promise} - Returns {@link MinerBlock}.
|
||||
*/
|
||||
@ -297,6 +310,7 @@ Miner.prototype._createBlock = co(function* createBlock(tip, address) {
|
||||
|
||||
/**
|
||||
* Mine a single block.
|
||||
* @method
|
||||
* @param {ChainEntry} tip
|
||||
* @returns {Promise} - Returns [{@link Block}].
|
||||
*/
|
||||
@ -456,6 +470,7 @@ Miner.prototype.build = function build(attempt) {
|
||||
|
||||
/**
|
||||
* MinerOptions
|
||||
* @alias module:mining.MinerOptions
|
||||
* @constructor
|
||||
* @param {Object}
|
||||
*/
|
||||
@ -580,6 +595,7 @@ MinerOptions.fromOptions = function fromOptions(options) {
|
||||
/**
|
||||
* Queue
|
||||
* @constructor
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
function Queue(cmp) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* minerblock.js - miner block object for bcoin (because we can)
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -24,8 +24,8 @@ var consensus = require('../protocol/consensus');
|
||||
var encoding = require('../utils/encoding');
|
||||
|
||||
/**
|
||||
* MinerBlock
|
||||
* @exports MinerBlock
|
||||
* MinerBlock (block attempt)
|
||||
* @alias module:mining.MinerBlock
|
||||
* @constructor
|
||||
* @param {Object} options
|
||||
* @param {ChainEntry} options.tip
|
||||
@ -356,7 +356,8 @@ MinerBlock.prototype.findNonce = function findNonce() {
|
||||
|
||||
/**
|
||||
* Hash until the nonce overflows.
|
||||
* @returns {Boolean} Whether the nonce was found.
|
||||
* @method
|
||||
* @returns {Promise} - Returns Boolean.
|
||||
*/
|
||||
|
||||
MinerBlock.prototype.findNonceAsync = co(function* findNonceAsync() {
|
||||
@ -415,6 +416,7 @@ MinerBlock.prototype.mine = function mine() {
|
||||
|
||||
/**
|
||||
* Mine asynchronously until the block is found.
|
||||
* @method
|
||||
* @returns {Promise} - Returns {@link Block}.
|
||||
*/
|
||||
|
||||
@ -495,7 +497,17 @@ MinerBlock.prototype.destroy = function destroy() {
|
||||
|
||||
/**
|
||||
* BlockEntry
|
||||
* @alias module:mining.BlockEntry
|
||||
* @constructor
|
||||
* @param {TX} tx
|
||||
* @property {TX} tx
|
||||
* @property {Hash} hash
|
||||
* @property {Amount} fee
|
||||
* @property {Rate} rate
|
||||
* @property {Number} priority
|
||||
* @property {Boolean} free
|
||||
* @property {Sigops} sigops
|
||||
* @property {Number} depCount
|
||||
*/
|
||||
|
||||
function BlockEntry(tx) {
|
||||
@ -509,6 +521,14 @@ function BlockEntry(tx) {
|
||||
this.depCount = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate block entry from transaction.
|
||||
* @param {TX} tx
|
||||
* @param {CoinView} view
|
||||
* @param {MinerBlock} attempt
|
||||
* @returns {BlockEntry}
|
||||
*/
|
||||
|
||||
BlockEntry.fromTX = function fromTX(tx, view, attempt) {
|
||||
var entry = new BlockEntry(tx);
|
||||
entry.fee = tx.getFee(view);
|
||||
@ -519,6 +539,13 @@ BlockEntry.fromTX = function fromTX(tx, view, attempt) {
|
||||
return entry;
|
||||
};
|
||||
|
||||
/**
|
||||
* Instantiate block entry from mempool entry.
|
||||
* @param {MempoolEntry} entry
|
||||
* @param {MinerBlock} attempt
|
||||
* @returns {BlockEntry}
|
||||
*/
|
||||
|
||||
BlockEntry.fromEntry = function fromEntry(entry, attempt) {
|
||||
var item = new BlockEntry(entry.tx);
|
||||
item.fee = entry.getFee();
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* bip150.js - peer auth.
|
||||
* Copyright (c) 2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
* Resources:
|
||||
* https://github.com/bitcoin/bips/blob/master/bip-0150.mediawiki
|
||||
@ -23,7 +23,7 @@ var dns = require('./dns');
|
||||
|
||||
/**
|
||||
* Represents a BIP150 input/output stream.
|
||||
* @exports BIP150
|
||||
* @alias module:net.BIP150
|
||||
* @constructor
|
||||
* @param {BIP151} bip151
|
||||
* @param {String} host
|
||||
@ -458,7 +458,7 @@ BIP150.address = function address(key) {
|
||||
|
||||
/**
|
||||
* AuthDB
|
||||
* @exports AuthDB
|
||||
* @alias module:net.AuthDB
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
@ -597,7 +597,7 @@ AuthDB.prototype.getKnown = function getKnown(hostname) {
|
||||
|
||||
/**
|
||||
* Lookup known peers.
|
||||
* @private
|
||||
* @method
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -617,6 +617,7 @@ AuthDB.prototype.discover = co(function* discover() {
|
||||
|
||||
/**
|
||||
* Populate known peers with hosts.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Object} addr
|
||||
* @param {Buffer} key
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* bip151.js - peer-to-peer communication encryption.
|
||||
* Copyright (c) 2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
* Resources:
|
||||
* https://github.com/bitcoin/bips/blob/master/bip-0151.mediawiki
|
||||
@ -38,7 +38,7 @@ var HIGH_WATERMARK = 1024 * (1 << 20);
|
||||
|
||||
/**
|
||||
* Represents a BIP151 input or output stream.
|
||||
* @exports BIP151Stream
|
||||
* @alias module:net.BIP151Stream
|
||||
* @constructor
|
||||
* @param {Number} cipher
|
||||
* @property {Buffer} publicKey
|
||||
@ -285,7 +285,7 @@ BIP151Stream.prototype.verify = function verify(tag) {
|
||||
/**
|
||||
* Represents a BIP151 input and output stream.
|
||||
* Holds state for peer communication.
|
||||
* @exports BIP151
|
||||
* @alias module:net.BIP151
|
||||
* @constructor
|
||||
* @param {Number} cipher
|
||||
* @property {BIP151Stream} input
|
||||
|
||||
@ -1,11 +1,15 @@
|
||||
/*!
|
||||
* bip152.js - compact block object for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module net/bip152
|
||||
*/
|
||||
|
||||
var util = require('../utils/util');
|
||||
var BufferReader = require('../utils/reader');
|
||||
var BufferWriter = require('../utils/writer');
|
||||
@ -23,7 +27,6 @@ var Block = require('../primitives/block');
|
||||
/**
|
||||
* Represents a compact block (bip152): `cmpctblock` packet.
|
||||
* @see https://github.com/bitcoin/bips/blob/master/bip-0152.mediawiki
|
||||
* @exports CompactBlock
|
||||
* @constructor
|
||||
* @extends AbstractBlock
|
||||
* @param {Object} options
|
||||
|
||||
@ -1,12 +1,16 @@
|
||||
/*!
|
||||
* common.js - p2p constants for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module net/common
|
||||
*/
|
||||
|
||||
var pkg = require('../../package.json');
|
||||
|
||||
/**
|
||||
@ -98,7 +102,7 @@ exports.services = {
|
||||
};
|
||||
|
||||
/**
|
||||
* BCoin's services (we support everything).
|
||||
* Bcoin's services (we support everything).
|
||||
* @const {Number}
|
||||
* @default
|
||||
*/
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* dns.js - dns backend for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -9,6 +9,15 @@
|
||||
var ProxySocket = require('./proxysocket');
|
||||
var socket;
|
||||
|
||||
/**
|
||||
* Resolve host (no getaddrinfo).
|
||||
* @ignore
|
||||
* @param {String} host
|
||||
* @param {String?} proxy
|
||||
* @param {Boolean?} onion
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
exports.resolve = function resolve(host, proxy, onion) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (!socket)
|
||||
@ -30,6 +39,15 @@ exports.resolve = function resolve(host, proxy, onion) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Resolve host (getaddrinfo).
|
||||
* @ignore
|
||||
* @param {String} host
|
||||
* @param {String?} proxy
|
||||
* @param {Boolean?} onion
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
exports.lookup = function lookup(host, proxy, onion) {
|
||||
return exports.resolve(host, proxy, onion);
|
||||
};
|
||||
|
||||
@ -1,11 +1,15 @@
|
||||
/*!
|
||||
* dns.js - dns backend for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module net/dns
|
||||
*/
|
||||
|
||||
var dns = require('dns');
|
||||
var socks = require('./socks');
|
||||
|
||||
@ -15,6 +19,14 @@ var options = {
|
||||
all: true
|
||||
};
|
||||
|
||||
/**
|
||||
* Resolve host (no getaddrinfo).
|
||||
* @param {String} host
|
||||
* @param {String?} proxy
|
||||
* @param {Boolean?} onion
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
exports.resolve = function resolve(host, proxy, onion) {
|
||||
if (proxy && onion)
|
||||
return socks.resolve(proxy, host);
|
||||
@ -36,6 +48,14 @@ exports.resolve = function resolve(host, proxy, onion) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Resolve host (getaddrinfo).
|
||||
* @param {String} host
|
||||
* @param {String?} proxy
|
||||
* @param {Boolean?} onion
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
exports.lookup = function lookup(host, proxy, onion) {
|
||||
if (proxy && onion)
|
||||
return socks.resolve(proxy, host);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* framer.js - packet framer for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -13,7 +13,7 @@ var crypto = require('../crypto/crypto');
|
||||
|
||||
/**
|
||||
* Protocol packet framer
|
||||
* @exports Framer
|
||||
* @alias module:net.Framer
|
||||
* @constructor
|
||||
* @param {Network} network
|
||||
*/
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* hostlist.js - address management for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -20,6 +20,7 @@ var dns = require('./dns');
|
||||
|
||||
/**
|
||||
* Host List
|
||||
* @alias module:net.HostList
|
||||
* @constructor
|
||||
* @param {Object} options
|
||||
*/
|
||||
@ -722,6 +723,7 @@ HostList.prototype.setNodes = function setNodes(nodes) {
|
||||
|
||||
/**
|
||||
* Discover hosts from seeds and nodes.
|
||||
* @method
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -746,6 +748,7 @@ HostList.prototype.discover = co(function* discover() {
|
||||
|
||||
/**
|
||||
* Lookup node's domain.
|
||||
* @method
|
||||
* @param {Object} addr
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -762,6 +765,7 @@ HostList.prototype.populateNode = co(function* populateNode(addr) {
|
||||
|
||||
/**
|
||||
* Populate from seed.
|
||||
* @method
|
||||
* @param {Object} seed
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -778,6 +782,7 @@ HostList.prototype.populateSeed = co(function* populateSeed(seed) {
|
||||
|
||||
/**
|
||||
* Lookup hosts from dns host.
|
||||
* @method
|
||||
* @param {Object} target
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -940,6 +945,7 @@ HostList.fromJSON = function fromJSON(options, json) {
|
||||
|
||||
/**
|
||||
* HostEntry
|
||||
* @alias module:net.HostEntry
|
||||
* @constructor
|
||||
* @param {NetAddress} addr
|
||||
* @param {NetAddress} src
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module net
|
||||
*/
|
||||
|
||||
exports.BIP150 = require('./bip150');
|
||||
exports.BIP151 = require('./bip151');
|
||||
exports.bip152 = require('./bip152');
|
||||
|
||||
@ -1,12 +1,16 @@
|
||||
/*!
|
||||
* packets.js - packets for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module net/packets
|
||||
*/
|
||||
|
||||
var common = require('./common');
|
||||
var util = require('../utils/util');
|
||||
var assert = require('assert');
|
||||
@ -133,7 +137,6 @@ Packet.prototype.fromRaw = function fromRaw(data) {
|
||||
/**
|
||||
* Version Packet
|
||||
* @constructor
|
||||
* @exports VersionPacket
|
||||
* @param {Object?} options
|
||||
* @param {Number} options.version - Protocol version.
|
||||
* @param {Number} options.services - Service bits.
|
||||
@ -353,7 +356,6 @@ VersionPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `verack` packet.
|
||||
* @exports VerackPacket
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
@ -394,7 +396,6 @@ VerackPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `ping` packet.
|
||||
* @exports PingPacket
|
||||
* @constructor
|
||||
* @param {BN?} nonce
|
||||
* @property {BN|null} nonce
|
||||
@ -491,7 +492,6 @@ PingPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `pong` packet.
|
||||
* @exports PongPacket
|
||||
* @constructor
|
||||
* @param {BN?} nonce
|
||||
* @property {BN} nonce
|
||||
@ -585,7 +585,6 @@ PongPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `getaddr` packet.
|
||||
* @exports GetAddrPacket
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
@ -626,7 +625,6 @@ GetAddrPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `addr` packet.
|
||||
* @exports AddrPacket
|
||||
* @constructor
|
||||
* @param {(NetAddress[])?} items
|
||||
* @property {NetAddress[]} items
|
||||
@ -729,7 +727,6 @@ AddrPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `inv` packet.
|
||||
* @exports InvPacket
|
||||
* @constructor
|
||||
* @param {(InvItem[])?} items
|
||||
* @property {InvItem[]} items
|
||||
@ -845,7 +842,6 @@ InvPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `getdata` packet.
|
||||
* @exports GetDataPacket
|
||||
* @extends InvPacket
|
||||
* @constructor
|
||||
* @param {(InvItem[])?} items
|
||||
@ -888,7 +884,6 @@ GetDataPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `notfound` packet.
|
||||
* @exports NotFoundPacket
|
||||
* @extends InvPacket
|
||||
* @constructor
|
||||
* @param {(InvItem[])?} items
|
||||
@ -931,7 +926,6 @@ NotFoundPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `getblocks` packet.
|
||||
* @exports GetBlocksPacket
|
||||
* @constructor
|
||||
* @param {Hash[]} locator
|
||||
* @param {Hash?} stop
|
||||
@ -1051,7 +1045,6 @@ GetBlocksPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `getheaders` packet.
|
||||
* @exports GetHeadersPacket
|
||||
* @extends GetBlocksPacket
|
||||
* @constructor
|
||||
* @param {Hash[]} locator
|
||||
@ -1095,7 +1088,6 @@ GetHeadersPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `headers` packet.
|
||||
* @exports HeadersPacket
|
||||
* @constructor
|
||||
* @param {(Headers[])?} items
|
||||
* @property {Headers[]} items
|
||||
@ -1207,7 +1199,6 @@ HeadersPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `sendheaders` packet.
|
||||
* @exports SendHeadersPacket
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
@ -1248,7 +1239,6 @@ SendHeadersPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `block` packet.
|
||||
* @exports BlockPacket
|
||||
* @constructor
|
||||
* @param {Block|null} block
|
||||
* @param {Boolean?} witness
|
||||
@ -1351,7 +1341,6 @@ BlockPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `tx` packet.
|
||||
* @exports TXPacket
|
||||
* @constructor
|
||||
* @param {TX|null} tx
|
||||
* @param {Boolean?} witness
|
||||
@ -1454,7 +1443,6 @@ TXPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Reject Packet
|
||||
* @exports RejectPacket
|
||||
* @constructor
|
||||
* @property {(Number|String)?} code - Code
|
||||
* (see {@link RejectPacket.codes}).
|
||||
@ -1750,7 +1738,6 @@ RejectPacket.prototype.inspect = function inspect() {
|
||||
|
||||
/**
|
||||
* Represents a `mempool` packet.
|
||||
* @exports MempoolPacket
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
@ -1791,7 +1778,6 @@ MempoolPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `filterload` packet.
|
||||
* @exports FilterLoadPacket
|
||||
* @constructor
|
||||
* @param {Bloom|null} filter
|
||||
*/
|
||||
@ -1893,7 +1879,6 @@ FilterLoadPacket.prototype.isWithinConstraints = function isWithinConstraints()
|
||||
|
||||
/**
|
||||
* Represents a `filteradd` packet.
|
||||
* @exports FilterAddPacket
|
||||
* @constructor
|
||||
* @param {Buffer?} data
|
||||
* @property {Buffer} data
|
||||
@ -1978,7 +1963,6 @@ FilterAddPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `filterclear` packet.
|
||||
* @exports FilterClearPacket
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
@ -2009,7 +1993,6 @@ FilterClearPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `merkleblock` packet.
|
||||
* @exports MerkleBlockPacket
|
||||
* @constructor
|
||||
* @param {MerkleBlock?} block
|
||||
* @property {MerkleBlock} block
|
||||
@ -2093,7 +2076,6 @@ MerkleBlockPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `feefilter` packet.
|
||||
* @exports FeeFilterPacket
|
||||
* @constructor
|
||||
* @param {Rate?} rate
|
||||
* @property {Rate} rate
|
||||
@ -2187,7 +2169,6 @@ FeeFilterPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `sendcmpct` packet.
|
||||
* @exports SendCmpctPacket
|
||||
* @constructor
|
||||
* @param {Number|null} mode
|
||||
* @param {Number|null} version
|
||||
@ -2296,7 +2277,6 @@ SendCmpctPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `cmpctblock` packet.
|
||||
* @exports CmpctBlockPacket
|
||||
* @constructor
|
||||
* @param {Block|null} block
|
||||
* @param {Boolean|null} witness
|
||||
@ -2399,7 +2379,6 @@ CmpctBlockPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `getblocktxn` packet.
|
||||
* @exports GetBlockTxnPacket
|
||||
* @constructor
|
||||
* @param {TXRequest?} request
|
||||
* @property {TXRequest} request
|
||||
@ -2493,7 +2472,6 @@ GetBlockTxnPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `blocktxn` packet.
|
||||
* @exports BlockTxnPacket
|
||||
* @constructor
|
||||
* @param {TXResponse?} response
|
||||
* @param {Boolean?} witness
|
||||
@ -2596,7 +2574,6 @@ BlockTxnPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `encinit` packet.
|
||||
* @exports EncinitPacket
|
||||
* @constructor
|
||||
* @param {Buffer|null} publicKey
|
||||
* @param {Number|null} cipher
|
||||
@ -2695,7 +2672,6 @@ EncinitPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `encack` packet.
|
||||
* @exports EncackPacket
|
||||
* @constructor
|
||||
* @param {Buffer?} publicKey
|
||||
* @property {Buffer} publicKey
|
||||
@ -2789,7 +2765,6 @@ EncackPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `authchallenge` packet.
|
||||
* @exports AuthChallengePacket
|
||||
* @constructor
|
||||
* @param {Buffer?} hash
|
||||
* @property {Buffer} hash
|
||||
@ -2883,7 +2858,6 @@ AuthChallengePacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `authreply` packet.
|
||||
* @exports AuthReplyPacket
|
||||
* @constructor
|
||||
* @param {Buffer?} signature
|
||||
* @property {Buffer} signature
|
||||
@ -2977,7 +2951,6 @@ AuthReplyPacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents a `authpropose` packet.
|
||||
* @exports AuthProposePacket
|
||||
* @constructor
|
||||
* @param {Hash?} hash
|
||||
* @property {Hash} hash
|
||||
@ -3071,7 +3044,6 @@ AuthProposePacket.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
/**
|
||||
* Represents an unknown packet.
|
||||
* @exports UnknownPacket
|
||||
* @constructor
|
||||
* @param {String|null} cmd
|
||||
* @param {Buffer|null} data
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* parser.js - packet parser for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -17,7 +17,7 @@ var packets = require('./packets');
|
||||
|
||||
/**
|
||||
* Protocol packet parser
|
||||
* @exports Parser
|
||||
* @alias module:net.Parser
|
||||
* @constructor
|
||||
* @param {Network} network
|
||||
* @emits Parser#error
|
||||
@ -177,7 +177,7 @@ Parser.prototype.parsePayload = function parsePayload(cmd, data) {
|
||||
/**
|
||||
* Packet Header
|
||||
* @constructor
|
||||
* @private
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
function Header(cmd, size, checksum) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* peer.js - peer object for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -36,7 +36,7 @@ var packetTypes = packets.types;
|
||||
|
||||
/**
|
||||
* Represents a remote peer.
|
||||
* @exports Peer
|
||||
* @alias module:net.Peer
|
||||
* @constructor
|
||||
* @param {PeerOptions} options
|
||||
* @property {net.Socket} socket
|
||||
@ -437,6 +437,7 @@ Peer.prototype.connect = function connect(addr) {
|
||||
|
||||
/**
|
||||
* Open and perform initial handshake (without rejection).
|
||||
* @method
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -450,6 +451,7 @@ Peer.prototype.tryOpen = co(function* tryOpen() {
|
||||
|
||||
/**
|
||||
* Open and perform initial handshake.
|
||||
* @method
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -465,6 +467,7 @@ Peer.prototype.open = co(function* open() {
|
||||
|
||||
/**
|
||||
* Open and perform initial handshake.
|
||||
* @method
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -552,6 +555,7 @@ Peer.prototype.initStall = function initStall() {
|
||||
/**
|
||||
* Handle `connect` event (called immediately
|
||||
* if a socket was passed into peer).
|
||||
* @method
|
||||
* @private
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -588,6 +592,7 @@ Peer.prototype.initBIP151 = co(function* initBIP151() {
|
||||
|
||||
/**
|
||||
* Handle post bip151-handshake.
|
||||
* @method
|
||||
* @private
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -626,6 +631,7 @@ Peer.prototype.initBIP150 = co(function* initBIP150() {
|
||||
|
||||
/**
|
||||
* Handle post handshake.
|
||||
* @method
|
||||
* @private
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -662,6 +668,7 @@ Peer.prototype.initVersion = co(function* initVersion() {
|
||||
|
||||
/**
|
||||
* Finalize peer after handshake.
|
||||
* @method
|
||||
* @private
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -1481,6 +1488,7 @@ Peer.prototype.getTX = function getTX(hashes) {
|
||||
|
||||
/**
|
||||
* Handle a packet payload.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Packet} packet
|
||||
*/
|
||||
@ -1526,6 +1534,7 @@ Peer.prototype.readPacket = co(function* readPacket(packet) {
|
||||
|
||||
/**
|
||||
* Handle a packet payload without a lock.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Packet} packet
|
||||
*/
|
||||
@ -1614,6 +1623,7 @@ Peer.prototype.handlePacket = co(function* handlePacket(packet) {
|
||||
|
||||
/**
|
||||
* Handle `version` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {VersionPacket} packet
|
||||
*/
|
||||
@ -1669,6 +1679,7 @@ Peer.prototype.handleVersion = co(function* handleVersion(packet) {
|
||||
|
||||
/**
|
||||
* Handle `verack` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {VerackPacket} packet
|
||||
*/
|
||||
@ -1685,6 +1696,7 @@ Peer.prototype.handleVerack = co(function* handleVerack(packet) {
|
||||
|
||||
/**
|
||||
* Handle `ping` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {PingPacket} packet
|
||||
*/
|
||||
@ -1698,6 +1710,7 @@ Peer.prototype.handlePing = co(function* handlePing(packet) {
|
||||
|
||||
/**
|
||||
* Handle `pong` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {PongPacket} packet
|
||||
*/
|
||||
@ -1735,6 +1748,7 @@ Peer.prototype.handlePong = co(function* handlePong(packet) {
|
||||
|
||||
/**
|
||||
* Handle `sendheaders` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {SendHeadersPacket} packet
|
||||
*/
|
||||
@ -1752,6 +1766,7 @@ Peer.prototype.handleSendHeaders = co(function* handleSendHeaders(packet) {
|
||||
|
||||
/**
|
||||
* Handle `filterload` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {FilterLoadPacket} packet
|
||||
*/
|
||||
@ -1768,6 +1783,7 @@ Peer.prototype.handleFilterLoad = co(function* handleFilterLoad(packet) {
|
||||
|
||||
/**
|
||||
* Handle `filteradd` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {FilterAddPacket} packet
|
||||
*/
|
||||
@ -1788,6 +1804,7 @@ Peer.prototype.handleFilterAdd = co(function* handleFilterAdd(packet) {
|
||||
|
||||
/**
|
||||
* Handle `filterclear` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {FilterClearPacket} packet
|
||||
*/
|
||||
@ -1801,6 +1818,7 @@ Peer.prototype.handleFilterClear = co(function* handleFilterClear(packet) {
|
||||
|
||||
/**
|
||||
* Handle `feefilter` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {FeeFilterPacket} packet
|
||||
*/
|
||||
@ -1818,6 +1836,7 @@ Peer.prototype.handleFeeFilter = co(function* handleFeeFilter(packet) {
|
||||
|
||||
/**
|
||||
* Handle `sendcmpct` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {SendCmpctPacket}
|
||||
*/
|
||||
@ -1855,6 +1874,7 @@ Peer.prototype.handleSendCmpct = co(function* handleSendCmpct(packet) {
|
||||
|
||||
/**
|
||||
* Handle `encinit` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {EncinitPacket} packet
|
||||
*/
|
||||
@ -1870,6 +1890,7 @@ Peer.prototype.handleEncinit = co(function* handleEncinit(packet) {
|
||||
|
||||
/**
|
||||
* Handle `encack` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {EncackPacket} packet
|
||||
*/
|
||||
@ -1883,6 +1904,7 @@ Peer.prototype.handleEncack = co(function* handleEncack(packet) {
|
||||
|
||||
/**
|
||||
* Handle `authchallenge` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {AuthChallengePacket} packet
|
||||
*/
|
||||
@ -1900,6 +1922,7 @@ Peer.prototype.handleAuthChallenge = co(function* handleAuthChallenge(packet) {
|
||||
|
||||
/**
|
||||
* Handle `authreply` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {AuthReplyPacket} packet
|
||||
*/
|
||||
@ -1918,6 +1941,7 @@ Peer.prototype.handleAuthReply = co(function* handleAuthReply(packet) {
|
||||
|
||||
/**
|
||||
* Handle `authpropose` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {AuthProposePacket} packet
|
||||
*/
|
||||
@ -2023,10 +2047,10 @@ Peer.prototype.sendReject = function sendReject(code, reason, msg) {
|
||||
var reject = packets.RejectPacket.fromReason(code, reason, msg);
|
||||
|
||||
if (msg) {
|
||||
this.logger.debug('Rejecting %s %s (%s): ccode=%s reason=%s.',
|
||||
this.logger.debug('Rejecting %s %s (%s): code=%s reason=%s.',
|
||||
reject.message, msg.rhash(), this.hostname(), code, reason);
|
||||
} else {
|
||||
this.logger.debug('Rejecting packet from %s: ccode=%s reason=%s.',
|
||||
this.logger.debug('Rejecting packet from %s: code=%s reason=%s.',
|
||||
this.hostname(), code, reason);
|
||||
}
|
||||
|
||||
@ -2149,6 +2173,7 @@ Peer.prototype.inspect = function inspect() {
|
||||
|
||||
/**
|
||||
* PeerOptions
|
||||
* @alias module:net.PeerOptions
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
@ -2358,6 +2383,7 @@ PeerOptions.getRate = function getRate(hash) {
|
||||
/**
|
||||
* RequestEntry
|
||||
* @constructor
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
function RequestEntry() {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* pool.js - peer management for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -38,7 +38,7 @@ var packetTypes = packets.types;
|
||||
|
||||
/**
|
||||
* A pool of peers for handling all network activity.
|
||||
* @exports Pool
|
||||
* @alias module:net.Pool
|
||||
* @constructor
|
||||
* @param {Object} options
|
||||
* @param {Chain} options.chain
|
||||
@ -62,25 +62,12 @@ var packetTypes = packets.types;
|
||||
* @param {Function?} options.createServer - Custom function to create a server.
|
||||
* Must return a node-like server.
|
||||
* @emits Pool#block
|
||||
* @emits Pool#block
|
||||
* @emits Pool#tx
|
||||
* @emits Pool#peer
|
||||
* @emits Pool#open
|
||||
* @emits Pool#close
|
||||
* @emits Pool#error
|
||||
* @emits Pool#fork
|
||||
* @emits Pool#invalid
|
||||
* @emits Pool#exists
|
||||
* @emits Pool#orphan
|
||||
* @emits Pool#full
|
||||
* @emits Pool#blocks
|
||||
* @emits Pool#txs
|
||||
* @emits Pool#chain-progress
|
||||
* @emits Pool#reject
|
||||
* @emits Pool#addr
|
||||
* @emits Pool#version
|
||||
* @emits Pool#ack
|
||||
* @emits Pool#watched
|
||||
*/
|
||||
|
||||
function Pool(options) {
|
||||
@ -202,6 +189,7 @@ Pool.prototype._init = function _init() {
|
||||
|
||||
/**
|
||||
* Open the pool, wait for the chain to load.
|
||||
* @method
|
||||
* @alias Pool#open
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -254,6 +242,7 @@ Pool.prototype.resetChain = function resetChain() {
|
||||
|
||||
/**
|
||||
* Close and destroy the pool.
|
||||
* @method
|
||||
* @alias Pool#close
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -265,6 +254,7 @@ Pool.prototype._close = co(function* close() {
|
||||
|
||||
/**
|
||||
* Connect to the network.
|
||||
* @method
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -279,6 +269,7 @@ Pool.prototype.connect = co(function* connect() {
|
||||
|
||||
/**
|
||||
* Connect to the network (no lock).
|
||||
* @method
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -320,6 +311,7 @@ Pool.prototype._connect = co(function* connect() {
|
||||
|
||||
/**
|
||||
* Disconnect from the network.
|
||||
* @method
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -334,6 +326,7 @@ Pool.prototype.disconnect = co(function* disconnect() {
|
||||
|
||||
/**
|
||||
* Disconnect from the network.
|
||||
* @method
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -384,6 +377,7 @@ Pool.prototype._disconnect = co(function* disconnect() {
|
||||
|
||||
/**
|
||||
* Start listening on a server socket.
|
||||
* @method
|
||||
* @private
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -402,6 +396,7 @@ Pool.prototype.listen = co(function* listen() {
|
||||
|
||||
/**
|
||||
* Stop listening on server socket.
|
||||
* @method
|
||||
* @private
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -588,6 +583,7 @@ Pool.prototype.stopSync = function stopSync() {
|
||||
|
||||
/**
|
||||
* Start syncing from peer.
|
||||
* @method
|
||||
* @param {Peer} peer
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -776,6 +772,7 @@ Pool.prototype.getBroadcasted = function getBroadcasted(peer, item) {
|
||||
|
||||
/**
|
||||
* Get a block/tx either from the broadcast map, mempool, or blockchain.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {InvItem} item
|
||||
@ -808,6 +805,7 @@ Pool.prototype.getItem = co(function* getItem(peer, item) {
|
||||
|
||||
/**
|
||||
* Send a block from the broadcast list or chain.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {InvItem} item
|
||||
@ -942,6 +940,7 @@ Pool.prototype.bindPeer = function bindPeer(peer) {
|
||||
|
||||
/**
|
||||
* Handle peer packet event.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {Packet} packet
|
||||
@ -1056,6 +1055,7 @@ Pool.prototype.handlePacket = co(function* handlePacket(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle peer connect event.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
*/
|
||||
@ -1071,6 +1071,7 @@ Pool.prototype.handleConnect = co(function* handleConnect(peer) {
|
||||
|
||||
/**
|
||||
* Handle peer open event.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
*/
|
||||
@ -1132,6 +1133,7 @@ Pool.prototype.handleOpen = co(function* handleOpen(peer) {
|
||||
|
||||
/**
|
||||
* Handle peer close event.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {Boolean} connected
|
||||
@ -1167,6 +1169,7 @@ Pool.prototype.handleClose = co(function* handleClose(peer, connected) {
|
||||
|
||||
/**
|
||||
* Handle ban event.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
*/
|
||||
@ -1178,6 +1181,7 @@ Pool.prototype.handleBan = co(function* handleBan(peer) {
|
||||
|
||||
/**
|
||||
* Handle peer version event.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {VersionPacket} packet
|
||||
@ -1198,6 +1202,7 @@ Pool.prototype.handleVersion = co(function* handleVersion(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `verack` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {VerackPacket} packet
|
||||
@ -1209,6 +1214,7 @@ Pool.prototype.handleVerack = co(function* handleVerack(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `ping` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {PingPacket} packet
|
||||
@ -1220,6 +1226,7 @@ Pool.prototype.handlePing = co(function* handlePing(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `pong` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {PongPacket} packet
|
||||
@ -1231,6 +1238,7 @@ Pool.prototype.handlePong = co(function* handlePong(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `getaddr` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {GetAddrPacket} packet
|
||||
@ -1279,6 +1287,7 @@ Pool.prototype.handleGetAddr = co(function* handleGetAddr(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle peer addr event.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {AddrPacket} packet
|
||||
@ -1319,6 +1328,7 @@ Pool.prototype.handleAddr = co(function* handleAddr(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `inv` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {InvPacket} packet
|
||||
@ -1335,6 +1345,7 @@ Pool.prototype.handleInv = co(function* handleInv(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `inv` packet (without a lock).
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {InvPacket} packet
|
||||
@ -1387,6 +1398,7 @@ Pool.prototype._handleInv = co(function* handleInv(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `inv` packet from peer (containing only BLOCK types).
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {Hash[]} hashes
|
||||
@ -1450,6 +1462,7 @@ Pool.prototype.handleBlockInv = co(function* handleBlockInv(peer, hashes) {
|
||||
|
||||
/**
|
||||
* Handle peer inv packet (txs).
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {Hash[]} hashes
|
||||
@ -1476,6 +1489,7 @@ Pool.prototype.handleTXInv = co(function* handleTXInv(peer, hashes) {
|
||||
|
||||
/**
|
||||
* Handle `getdata` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {GetDataPacket} packet
|
||||
@ -1636,6 +1650,7 @@ Pool.prototype.handleGetData = co(function* handleGetData(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle peer notfound packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {NotFoundPacket} packet
|
||||
@ -1653,6 +1668,7 @@ Pool.prototype.handleNotFound = co(function* handleNotFound(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `getblocks` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {GetBlocksPacket} packet
|
||||
@ -1698,6 +1714,7 @@ Pool.prototype.handleGetBlocks = co(function* handleGetBlocks(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `getheaders` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {GetHeadersPacket} packet
|
||||
@ -1747,6 +1764,7 @@ Pool.prototype.handleGetHeaders = co(function* handleGetHeaders(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `headers` packet from a given peer.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {HeadersPacket} packet
|
||||
@ -1765,6 +1783,7 @@ Pool.prototype.handleHeaders = co(function* handleHeaders(peer, packet) {
|
||||
/**
|
||||
* Handle `headers` packet from
|
||||
* a given peer without a lock.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {HeadersPacket} packet
|
||||
@ -1875,6 +1894,7 @@ Pool.prototype._handleHeaders = co(function* handleHeaders(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `sendheaders` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {SendHeadersPacket} packet
|
||||
@ -1887,6 +1907,7 @@ Pool.prototype.handleSendHeaders = co(function* handleSendHeaders(peer, packet)
|
||||
|
||||
/**
|
||||
* Handle `block` packet. Attempt to add to chain.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {BlockPacket} packet
|
||||
@ -1906,6 +1927,7 @@ Pool.prototype.handleBlock = co(function* handleBlock(peer, packet) {
|
||||
|
||||
/**
|
||||
* Attempt to add block to chain.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {Block} block
|
||||
@ -1924,6 +1946,7 @@ Pool.prototype.addBlock = co(function* addBlock(peer, block) {
|
||||
|
||||
/**
|
||||
* Attempt to add block to chain (without a lock).
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {Block} block
|
||||
@ -1974,6 +1997,7 @@ Pool.prototype._addBlock = co(function* addBlock(peer, block) {
|
||||
|
||||
/**
|
||||
* Resolve header chain.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {Hash} hash
|
||||
@ -2034,6 +2058,7 @@ Pool.prototype.resolveChain = co(function* resolveChain(peer, hash) {
|
||||
|
||||
/**
|
||||
* Switch to getblocks.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {Hash} hash
|
||||
@ -2085,6 +2110,7 @@ Pool.prototype.logStatus = function logStatus(block) {
|
||||
|
||||
/**
|
||||
* Handle a transaction. Attempt to add to mempool.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {TXPacket} packet
|
||||
@ -2103,6 +2129,7 @@ Pool.prototype.handleTX = co(function* handleTX(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle a transaction. Attempt to add to mempool (without a lock).
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {TXPacket} packet
|
||||
@ -2163,6 +2190,7 @@ Pool.prototype._handleTX = co(function* handleTX(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle peer reject event.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {RejectPacket} packet
|
||||
@ -2192,6 +2220,7 @@ Pool.prototype.handleReject = co(function* handleReject(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `mempool` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {MempoolPacket} packet
|
||||
@ -2234,6 +2263,7 @@ Pool.prototype.handleMempool = co(function* handleMempool(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `filterload` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {FilterLoadPacket} packet
|
||||
@ -2245,6 +2275,7 @@ Pool.prototype.handleFilterLoad = co(function* handleFilterLoad(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `filteradd` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {FilterAddPacket} packet
|
||||
@ -2256,6 +2287,7 @@ Pool.prototype.handleFilterAdd = co(function* handleFilterAdd(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `filterclear` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {FilterClearPacket} packet
|
||||
@ -2267,6 +2299,7 @@ Pool.prototype.handleFilterClear = co(function* handleFilterClear(peer, packet)
|
||||
|
||||
/**
|
||||
* Handle `merkleblock` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {MerkleBlockPacket} block
|
||||
@ -2284,6 +2317,7 @@ Pool.prototype.handleMerkleBlock = co(function* handleMerkleBlock(peer, packet)
|
||||
|
||||
/**
|
||||
* Handle `merkleblock` packet (without a lock).
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {MerkleBlockPacket} block
|
||||
@ -2341,6 +2375,7 @@ Pool.prototype._handleMerkleBlock = co(function* handleMerkleBlock(peer, packet)
|
||||
|
||||
/**
|
||||
* Handle `sendcmpct` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {FeeFilterPacket} packet
|
||||
@ -2352,6 +2387,7 @@ Pool.prototype.handleFeeFilter = co(function* handleFeeFilter(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `sendcmpct` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {SendCmpctPacket} packet
|
||||
@ -2363,6 +2399,7 @@ Pool.prototype.handleSendCmpct = co(function* handleSendCmpct(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `cmpctblock` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {CompactBlockPacket} packet
|
||||
@ -2456,6 +2493,7 @@ Pool.prototype.handleCmpctBlock = co(function* handleCmpctBlock(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `getblocktxn` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {GetBlockTxnPacket} packet
|
||||
@ -2502,6 +2540,7 @@ Pool.prototype.handleGetBlockTxn = co(function* handleGetBlockTxn(peer, packet)
|
||||
|
||||
/**
|
||||
* Handle `blocktxn` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {BlockTxnPacket} packet
|
||||
@ -2540,6 +2579,7 @@ Pool.prototype.handleBlockTxn = co(function* handleBlockTxn(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `encinit` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {EncinitPacket} packet
|
||||
@ -2551,6 +2591,7 @@ Pool.prototype.handleEncinit = co(function* handleEncinit(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `encack` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {EncackPacket} packet
|
||||
@ -2562,6 +2603,7 @@ Pool.prototype.handleEncack = co(function* handleEncack(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `authchallenge` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {AuthChallengePacket} packet
|
||||
@ -2573,6 +2615,7 @@ Pool.prototype.handleAuthChallenge = co(function* handleAuthChallenge(peer, pack
|
||||
|
||||
/**
|
||||
* Handle `authreply` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {AuthReplyPacket} packet
|
||||
@ -2584,6 +2627,7 @@ Pool.prototype.handleAuthReply = co(function* handleAuthReply(peer, packet) {
|
||||
|
||||
/**
|
||||
* Handle `authpropose` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {AuthProposePacket} packet
|
||||
@ -2595,6 +2639,7 @@ Pool.prototype.handleAuthPropose = co(function* handleAuthPropose(peer, packet)
|
||||
|
||||
/**
|
||||
* Handle `unknown` packet.
|
||||
* @method
|
||||
* @private
|
||||
* @param {Peer} peer
|
||||
* @param {UnknownPacket} packet
|
||||
@ -2904,6 +2949,7 @@ Pool.prototype.watchOutpoint = function watchOutpoint(outpoint) {
|
||||
/**
|
||||
* Send `getblocks` to peer after building
|
||||
* locator and resolving orphan root.
|
||||
* @method
|
||||
* @param {Peer} peer
|
||||
* @param {Hash} orphan - Orphan hash to resolve.
|
||||
* @returns {Promise}
|
||||
@ -2920,6 +2966,7 @@ Pool.prototype.resolveOrphan = co(function* resolveOrphan(peer, orphan) {
|
||||
|
||||
/**
|
||||
* Send `getheaders` to peer after building locator.
|
||||
* @method
|
||||
* @param {Peer} peer
|
||||
* @param {Hash} tip - Tip to build chain locator from.
|
||||
* @param {Hash?} stop
|
||||
@ -2933,6 +2980,7 @@ Pool.prototype.getHeaders = co(function* getHeaders(peer, tip, stop) {
|
||||
|
||||
/**
|
||||
* Send `getblocks` to peer after building locator.
|
||||
* @method
|
||||
* @param {Peer} peer
|
||||
* @param {Hash} tip - Tip hash to build chain locator from.
|
||||
* @param {Hash?} stop
|
||||
@ -3032,6 +3080,7 @@ Pool.prototype.getTX = function getTX(peer, hashes) {
|
||||
|
||||
/**
|
||||
* Test whether the chain has or has seen an item.
|
||||
* @method
|
||||
* @param {Hash} hash
|
||||
* @returns {Promise} - Returns Boolean.
|
||||
*/
|
||||
@ -3148,6 +3197,7 @@ Pool.prototype.announceTX = function announceTX(msg) {
|
||||
|
||||
/**
|
||||
* Attempt to retrieve external IP from icanhazip.com.
|
||||
* @method
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -3181,6 +3231,7 @@ Pool.prototype.getIP = co(function* getIP() {
|
||||
|
||||
/**
|
||||
* Attempt to retrieve external IP from dyndns.org.
|
||||
* @method
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
@ -3209,6 +3260,7 @@ Pool.prototype.getIP2 = co(function* getIP2() {
|
||||
|
||||
/**
|
||||
* PoolOptions
|
||||
* @alias module:net.PoolOptions
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
@ -3624,6 +3676,7 @@ PoolOptions.prototype._resolve = function resolve(name) {
|
||||
|
||||
/**
|
||||
* Peer List
|
||||
* @alias module:net.PeerList
|
||||
* @constructor
|
||||
* @param {Object} options
|
||||
*/
|
||||
@ -3738,7 +3791,7 @@ PeerList.prototype.destroy = function destroy() {
|
||||
|
||||
/**
|
||||
* Represents an item that is broadcasted via an inv/getdata cycle.
|
||||
* @exports BroadcastItem
|
||||
* @alias module:net.BroadcastItem
|
||||
* @constructor
|
||||
* @private
|
||||
* @param {Pool} pool
|
||||
@ -3930,6 +3983,7 @@ BroadcastItem.prototype.inspect = function inspect() {
|
||||
/**
|
||||
* NonceList
|
||||
* @constructor
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
function NonceList() {
|
||||
@ -3976,6 +4030,7 @@ NonceList.prototype.remove = function remove(hostname) {
|
||||
/**
|
||||
* HeaderEntry
|
||||
* @constructor
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
function HeaderEntry(hash, height) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* socks.js - socks proxy for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -15,6 +15,10 @@ var IP = require('../utils/ip');
|
||||
var StaticWriter = require('../utils/staticwriter');
|
||||
var BufferReader = require('../utils/reader');
|
||||
|
||||
/**
|
||||
* @module net/socks
|
||||
*/
|
||||
|
||||
/**
|
||||
* SOCKS state machine
|
||||
* @constructor
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* tcp.js - tcp backend for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* tcp.js - tcp backend for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -9,14 +9,32 @@
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var net = require('net');
|
||||
var socks = require('./socks');
|
||||
|
||||
/**
|
||||
* @exports net/tcp
|
||||
*/
|
||||
|
||||
var tcp = exports;
|
||||
|
||||
/**
|
||||
* Create a TCP socket and connect.
|
||||
* @param {Number} port
|
||||
* @param {String} host
|
||||
* @param {String?} proxy
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
tcp.createSocket = function createSocket(port, host, proxy) {
|
||||
if (proxy)
|
||||
return socks.connect(proxy, port, host);
|
||||
return net.connect(port, host);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a TCP server.
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
tcp.createServer = function createServer() {
|
||||
var server = new net.Server();
|
||||
var ee = new EventEmitter();
|
||||
@ -61,6 +79,10 @@ tcp.createServer = function createServer() {
|
||||
return ee;
|
||||
};
|
||||
|
||||
/*
|
||||
* Helpers
|
||||
*/
|
||||
|
||||
function wrap(resolve, reject) {
|
||||
return function(err, result) {
|
||||
if (err) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* config.js - bcoin configuration
|
||||
* Copyright (c) 2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -12,7 +12,7 @@ var util = require('../utils/util');
|
||||
var global = util.global;
|
||||
|
||||
/**
|
||||
* @exports config
|
||||
* @exports node/config
|
||||
*/
|
||||
|
||||
function config(options) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* fullnode.js - full node for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -22,7 +22,7 @@ var policy = require('../protocol/policy');
|
||||
/**
|
||||
* Create a fullnode complete with a chain,
|
||||
* mempool, miner, wallet, etc.
|
||||
* @exports FullNode
|
||||
* @alias module:node.FullNode
|
||||
* @extends Node
|
||||
* @constructor
|
||||
* @param {Object?} options
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module node
|
||||
*/
|
||||
|
||||
exports.config = require('./config');
|
||||
exports.FullNode = require('./fullnode');
|
||||
exports.Logger = require('./logger');
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* logger.js - basic logger for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -12,7 +12,7 @@ var util = require('../utils/util');
|
||||
|
||||
/**
|
||||
* Basic stdout and file logger.
|
||||
* @exports Logger
|
||||
* @alias module:node.Logger
|
||||
* @constructor
|
||||
* @param {(String|Object)?} options/level
|
||||
* @param {String?} options.level
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* node.js - node object for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -21,7 +21,7 @@ var native = require('../utils/native');
|
||||
/**
|
||||
* Base class from which every other
|
||||
* Node-like object inherits.
|
||||
* @exports Node
|
||||
* @alias module:node.Node
|
||||
* @constructor
|
||||
* @abstract
|
||||
* @param {Object} options
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* nodeclient.js - node client for bcoin
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -13,6 +13,7 @@ var AsyncObject = require('../utils/async');
|
||||
/**
|
||||
* NodeClient
|
||||
* Sort of a fake local client for separation of concerns.
|
||||
* @alias module:node.NodeClient
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* spvnode.js - spv node for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -19,7 +19,7 @@ var HTTPServer = require('../http/server');
|
||||
/**
|
||||
* Create an spv node which only maintains
|
||||
* a chain, a pool, and a wallet database.
|
||||
* @exports SPVNode
|
||||
* @alias module:node.SPVNode
|
||||
* @extends Node
|
||||
* @constructor
|
||||
* @param {Object?} options
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* abstractblock.js - abstract block object for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -18,11 +18,11 @@ var consensus = require('../protocol/consensus');
|
||||
|
||||
/**
|
||||
* The class which all block-like objects inherit from.
|
||||
* @exports AbstractBlock
|
||||
* @alias module:primitives.AbstractBlock
|
||||
* @constructor
|
||||
* @abstract
|
||||
* @property {Number} version - Block version. Note
|
||||
* that BCoin reads versions as unsigned despite
|
||||
* that Bcoin reads versions as unsigned despite
|
||||
* them being signed on the protocol level. This
|
||||
* number will never be negative.
|
||||
* @property {Hash} prevBlock - Previous block hash.
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* address.js - address object for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -20,7 +20,7 @@ var base58 = require('../utils/base58');
|
||||
|
||||
/**
|
||||
* Represents an address.
|
||||
* @exports Address
|
||||
* @alias module:primitives.Address
|
||||
* @constructor
|
||||
* @param {Object} options
|
||||
* @param {Buffer|Hash} options.hash - Address hash.
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* block.js - block object for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -23,7 +23,7 @@ var Network = require('../protocol/network');
|
||||
|
||||
/**
|
||||
* Represents a full block.
|
||||
* @exports Block
|
||||
* @alias module:primitives.Block
|
||||
* @constructor
|
||||
* @extends AbstractBlock
|
||||
* @param {NakedBlock} options
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* coin.js - coin object for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -20,7 +20,7 @@ var encoding = require('../utils/encoding');
|
||||
|
||||
/**
|
||||
* Represents an unspent output.
|
||||
* @exports Coin
|
||||
* @alias module:primitives.Coin
|
||||
* @constructor
|
||||
* @extends Output
|
||||
* @param {NakedCoin|Coin} options
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* headers.js - headers object for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -15,7 +15,7 @@ var BufferReader = require('../utils/reader');
|
||||
|
||||
/**
|
||||
* Represents block headers obtained from the network via `headers`.
|
||||
* @exports Headers
|
||||
* @alias module:primitives.Headers
|
||||
* @constructor
|
||||
* @extends AbstractBlock
|
||||
* @param {NakedBlock} options
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module primitives
|
||||
*/
|
||||
|
||||
exports.AbstractBlock = require('./abstractblock');
|
||||
exports.Address = require('./address');
|
||||
exports.Block = require('./block');
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* input.js - input object for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -18,7 +18,7 @@ var BufferReader = require('../utils/reader');
|
||||
|
||||
/**
|
||||
* Represents a transaction input.
|
||||
* @exports Input
|
||||
* @alias module:primitives.Input
|
||||
* @constructor
|
||||
* @param {NakedInput} options
|
||||
* @property {Outpoint} prevout - Outpoint.
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* invitem.js - inv item object for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* Copyright (c) 2014-2016, Christopher Jeffrey (MIT License).
|
||||
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
@ -13,6 +13,8 @@ var util = require('../utils/util');
|
||||
|
||||
/**
|
||||
* Inv Item
|
||||
* @alias module:primitives.InvItem
|
||||
* @constructor
|
||||
* @param {Number} type
|
||||
* @param {Hash} hash
|
||||
* @property {InvType} type
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user