Socket
Socket
Sign inDemoInstall

bitcore-lib

Package Overview
Dependencies
Maintainers
3
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitcore-lib - npm Package Compare versions

Comparing version 8.0.0 to 8.1.0

CHANGELOG.md

2

docs/examples.md

@@ -12,3 +12,3 @@ # Bitcore examples

```javascript
var value = new Buffer('correct horse battery staple');
var value = Buffer.from('correct horse battery staple');
var hash = bitcore.crypto.Hash.sha256(value);

@@ -15,0 +15,0 @@ var bn = bitcore.crypto.BN.fromBuffer(hash);

@@ -1,2 +0,2 @@

# Bitcore v0.15.0
# Bitcore v8.0.0

@@ -3,0 +3,0 @@ ## Principles

@@ -0,5 +1,4 @@

'use strict';
var bitcoreTasks = require('bitcore-build');
bitcoreTasks('lib');
var startGulp = require('bitcore-build');
module.exports = startGulp('lib');

@@ -7,31 +7,20 @@ 'use strict';

config.set({
browsers: ['Firefox'],
frameworks: ['mocha', 'detectBrowsers'],
detectBrowsers: {
enabled: true,
usePhantomJS: false,
postDetection: function(availableBrowser) {
// modify to enable additional browsers if available
var runBrowsers = ['Firefox', 'Chrome'];
var browsers = [];
for(var i = 0; i < runBrowsers.length; i++) {
if(~availableBrowser.indexOf(runBrowsers[i])) {
browsers.push(runBrowsers[i]);
}
}
return browsers;
}
},
singleRun: true,
browsers: ['ChromeHeadless'],
frameworks: ['mocha'],
singleRun: false,
reporters: ['progress'],
logLevel: config.LOG_INFO,
// port: 9876, // karma web server port
autoWatch: false,
files: [
'tests.js'
'../../tests.js'
],
plugins: [
'karma-mocha',
'karma-phantomjs-launcher',
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-detect-browsers'
]
],
browsers: ['PhantomJS', 'Chrome']
});
};

@@ -175,14 +175,2 @@ 'use strict';

BN.prototype.gt = function(b) {
return this.cmp(b) > 0;
};
BN.prototype.gte = function(b) {
return this.cmp(b) >= 0;
};
BN.prototype.lt = function(b) {
return this.cmp(b) < 0;
};
BN.trim = function(buf, natlen) {

@@ -189,0 +177,0 @@ return buf.slice(natlen - buf.length, buf.length);

@@ -38,3 +38,7 @@ 'use strict';

BufferReader.prototype.eof = function() {
return this.pos >= this.buf.length;
if(this.buf) {
return this.pos >= this.buf.length;
} else {
return true;
}
};

@@ -41,0 +45,0 @@

@@ -47,3 +47,7 @@ 'use strict';

}
return networkMaps[arg];
if(networkMaps[arg] && networkMaps[arg].length >= 1) {
return networkMaps[arg][0];
} else {
return networkMaps[arg];
}
}

@@ -101,3 +105,6 @@

if (!_.isUndefined(value) && !_.isObject(value)) {
networkMaps[value] = network;
if(!networkMaps[value]) {
networkMaps[value] = [];
}
networkMaps[value].push(network);
}

@@ -125,4 +132,5 @@ });

for (var key in networkMaps) {
if (networkMaps[key] === network) {
delete networkMaps[key];
const index = networkMaps[key].indexOf(network);
if (index >= 0) {
delete networkMaps[key][index];
}

@@ -160,3 +168,3 @@ }

name: 'testnet',
alias: 'regtest',
alias: 'test',
pubkeyhash: 0x6f,

@@ -166,3 +174,11 @@ privatekey: 0xef,

xpubkey: 0x043587cf,
xprivkey: 0x04358394
xprivkey: 0x04358394,
networkMagic: 0x0b110907,
port: 18333,
dnsSeeds: [
'testnet-seed.bitcoin.petertodd.org',
'testnet-seed.bluematt.me',
'testnet-seed.alexykot.me',
'testnet-seed.bitcoin.schildbach.de'
]
});

@@ -176,71 +192,24 @@

// Add configurable values for testnet/regtest
var TESTNET = {
PORT: 18333,
NETWORK_MAGIC: BufferUtil.integerAsBuffer(0x0b110907),
DNS_SEEDS: [
'testnet-seed.bitcoin.petertodd.org',
'testnet-seed.bluematt.me',
'testnet-seed.alexykot.me',
'testnet-seed.bitcoin.schildbach.de'
]
};
for (var key in TESTNET) {
if (!_.isObject(TESTNET[key])) {
networkMaps[TESTNET[key]] = testnet;
}
}
var REGTEST = {
PORT: 18444,
NETWORK_MAGIC: BufferUtil.integerAsBuffer(0xfabfb5da),
DNS_SEEDS: []
};
for (var key in REGTEST) {
if (!_.isObject(REGTEST[key])) {
networkMaps[REGTEST[key]] = testnet;
}
}
Object.defineProperty(testnet, 'port', {
enumerable: true,
configurable: false,
get: function() {
if (this.regtestEnabled) {
return REGTEST.PORT;
} else {
return TESTNET.PORT;
}
}
addNetwork({
name: 'regtest',
alias: 'dev',
pubkeyhash: 0x6f,
privatekey: 0xef,
scripthash: 0xc4,
xpubkey: 0x043587cf,
xprivkey: 0x04358394,
networkMagic: 0xfabfb5da,
port: 18444,
dnsSeeds: []
});
Object.defineProperty(testnet, 'networkMagic', {
enumerable: true,
configurable: false,
get: function() {
if (this.regtestEnabled) {
return REGTEST.NETWORK_MAGIC;
} else {
return TESTNET.NETWORK_MAGIC;
}
}
});
/**
* @instance
* @member Networks#testnet
*/
var regtest = get('regtest');
Object.defineProperty(testnet, 'dnsSeeds', {
enumerable: true,
configurable: false,
get: function() {
if (this.regtestEnabled) {
return REGTEST.DNS_SEEDS;
} else {
return TESTNET.DNS_SEEDS;
}
}
});
/**
* @function
* @deprecated
* @member Networks#enableRegtest

@@ -255,2 +224,3 @@ * Will enable regtest features for testnet

* @function
* @deprecated
* @member Networks#disableRegtest

@@ -273,2 +243,3 @@ * Will disable regtest features for testnet

testnet: testnet,
regtest: regtest,
get: get,

@@ -275,0 +246,0 @@ enableRegtest: enableRegtest,

@@ -200,2 +200,3 @@ 'use strict';

OP_CHECKLOCKTIMEVERIFY: 177,
OP_CHECKSEQUENCEVERIFY: 178,

@@ -202,0 +203,0 @@ // expansion

@@ -35,2 +35,3 @@ 'use strict';

Interpreter.prototype.verifyWitnessProgram = function(version, program, witness, satoshis, flags) {
var scriptPubKey = new Script();

@@ -86,3 +87,4 @@ var stack = [];

sigversion: 1,
satoshis: satoshis
satoshis: satoshis,
flags: flags,
});

@@ -195,3 +197,2 @@

var hadWitness = false;
if ((flags & Interpreter.SCRIPT_VERIFY_WITNESS)) {

@@ -204,4 +205,3 @@ var witnessValues = {};

}
if (!this.verifyWitnessProgram(witnessValues.version, witnessValues.program, witness, satoshis, flags)) {
if (!this.verifyWitnessProgram(witnessValues.version, witnessValues.program, witness, satoshis, this.flags)) {
return false;

@@ -265,15 +265,33 @@ }

if (!this.verifyWitnessProgram(p2shWitnessValues.version, p2shWitnessValues.program, witness, satoshis, flags)) {
if (!this.verifyWitnessProgram(p2shWitnessValues.version, p2shWitnessValues.program, witness, satoshis, this.flags)) {
return false;
}
// Bypass the cleanstack check at the end. The actual stack is obviously not clean
// for witness programs.
stack = [stack[0]];
}
}
}
if ((flags & Interpreter.SCRIPT_VERIFY_WITNESS)) {
if (!hadWitness && witness.length > 0) {
this.errstr = 'SCRIPT_ERR_WITNESS_UNEXPECTED';
// The CLEANSTACK check is only performed after potential P2SH evaluation,
// as the non-P2SH evaluation of a P2SH script will obviously not result in
// a clean stack (the P2SH inputs remain). The same holds for witness
// evaluation.
if ((this.flags & Interpreter.SCRIPT_VERIFY_CLEANSTACK) != 0) {
// Disallow CLEANSTACK without P2SH, as otherwise a switch
// CLEANSTACK->P2SH+CLEANSTACK would be possible, which is not a
// softfork (and P2SH should be one).
if ((this.flags & Interpreter.SCRIPT_VERIFY_P2SH) == 0)
throw 'flags & SCRIPT_VERIFY_P2SH';
if (stackCopy.length != 1) {
this.errstr = 'SCRIPT_ERR_CLEANSTACK';
return false;
}
}
if ((this.flags & Interpreter.SCRIPT_VERIFY_WITNESS)) {
if (!hadWitness && witness.length > 0) {
this.errstr = 'SCRIPT_ERR_WITNESS_UNEXPECTED';
return false;
}

@@ -369,2 +387,12 @@ }

// Require that only a single stack element remains after evaluation. This
// changes the success criterion from "At least one stack element must
// remain, and when interpreted as a boolean, it must be true" to "Exactly
// one stack element must remain, and when interpreted as a boolean, it must
// be true".
// (softfork safe, BIP62 rule 6)
// Note: CLEANSTACK should never be used without P2SH or WITNESS.
Interpreter.SCRIPT_VERIFY_CLEANSTACK = (1 << 8),
// CLTV See BIP65 for details.

@@ -375,2 +403,57 @@ Interpreter.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY = (1 << 9);

// support CHECKSEQUENCEVERIFY opcode
//
// See BIP112 for details
Interpreter.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY = (1 << 10);
//
// Segwit script only: Require the argument of OP_IF/NOTIF to be exactly
// 0x01 or empty vector
//
Interpreter.SCRIPT_VERIFY_MINIMALIF = (1 << 13);
// Signature(s) must be empty vector if an CHECK(MULTI)SIG operation failed
//
Interpreter.SCRIPT_VERIFY_NULLFAIL = (1 << 14);
// Public keys in scripts must be compressed
//
Interpreter.SCRIPT_VERIFY_WITNESS_PUBKEYTYPE = (1 << 15);
// Do we accept signature using SIGHASH_FORKID
//
Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID = (1 << 16);
// Do we accept activate replay protection using a different fork id.
//
Interpreter.SCRIPT_ENABLE_REPLAY_PROTECTION = (1 << 17);
// Enable new opcodes.
//
Interpreter.SCRIPT_ENABLE_MONOLITH_OPCODES = (1 << 18);
/* Below flags apply in the context of BIP 68*/
/**
* If this flag set, CTxIn::nSequence is NOT interpreted as a relative
* lock-time.
*/
Interpreter.SEQUENCE_LOCKTIME_DISABLE_FLAG = (1 << 31);
/**
* If CTxIn::nSequence encodes a relative lock-time and this flag is set,
* the relative lock-time has units of 512 seconds, otherwise it specifies
* blocks with a granularity of 1.
*/
Interpreter.SEQUENCE_LOCKTIME_TYPE_FLAG = (1 << 22);
/**
* If CTxIn::nSequence encodes a relative lock-time, this mask is applied to
* extract that lock-time from the sequence field.
*/
Interpreter.SEQUENCE_LOCKTIME_MASK = 0x0000ffff;
Interpreter.castToBool = function(buf) {

@@ -394,2 +477,9 @@ for (var i = 0; i < buf.length; i++) {

var sig;
// Empty signature. Not strictly DER encoded, but allowed to provide a
// compact way to provide an invalid signature for use with CHECK(MULTI)SIG
if (buf.length == 0) {
return true;
}
if ((this.flags & (Interpreter.SCRIPT_VERIFY_DERSIG | Interpreter.SCRIPT_VERIFY_LOW_S | Interpreter.SCRIPT_VERIFY_STRICTENC)) !== 0 && !Signature.isTxDER(buf)) {

@@ -411,2 +501,3 @@ this.errstr = 'SCRIPT_ERR_SIG_DER_INVALID_FORMAT';

}
return true;

@@ -423,2 +514,9 @@ };

}
// Only compressed keys are accepted in segwit
if ((this.flags & Interpreter.SCRIPT_VERIFY_WITNESS_PUBKEYTYPE) != 0 && this.sigversion == 1 && !PublicKey.fromBuffer(buf).compressed) {
this.errstr = 'SCRIPT_ERR_WITNESS_PUBKEYTYPE';
return false;
}
return true;

@@ -511,2 +609,60 @@ };

/**
* Checks a sequence parameter with the transaction's sequence.
* @param {BN} nSequence the sequence read from the script
* @return {boolean} true if the transaction's sequence is less than or equal to
* the transaction's sequence
*/
Interpreter.prototype.checkSequence = function(nSequence) {
// Relative lock times are supported by comparing the passed in operand to
// the sequence number of the input.
var txToSequence = this.tx.inputs[this.nin].sequenceNumber;
// Fail if the transaction's version number is not set high enough to
// trigger BIP 68 rules.
if (this.tx.version < 2) {
return false;
}
// Sequence numbers with their most significant bit set are not consensus
// constrained. Testing that the transaction's sequence number do not have
// this bit set prevents using this property to get around a
// CHECKSEQUENCEVERIFY check.
if (txToSequence & SEQUENCE_LOCKTIME_DISABLE_FLAG) {
return false;
}
// Mask off any bits that do not have consensus-enforced meaning before
// doing the integer comparisons
var nLockTimeMask =
Interpreter.SEQUENCE_LOCKTIME_TYPE_FLAG | Interpreter.SEQUENCE_LOCKTIME_MASK;
var txToSequenceMasked = new BN(txToSequence & nLockTimeMask);
var nSequenceMasked = nSequence.and(nLockTimeMask);
// There are two kinds of nSequence: lock-by-blockheight and
// lock-by-blocktime, distinguished by whether nSequenceMasked <
// CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG.
//
// We want to compare apples to apples, so fail the script unless the type
// of nSequenceMasked being tested is the same as the nSequenceMasked in the
// transaction.
var SEQUENCE_LOCKTIME_TYPE_FLAG_BN = new BN(Interpreter.SEQUENCE_LOCKTIME_TYPE_FLAG);
if (!((txToSequenceMasked.lt(SEQUENCE_LOCKTIME_TYPE_FLAG_BN) &&
nSequenceMasked.lt(SEQUENCE_LOCKTIME_TYPE_FLAG_BN)) ||
(txToSequenceMasked.gte(SEQUENCE_LOCKTIME_TYPE_FLAG_BN) &&
nSequenceMasked.gte(SEQUENCE_LOCKTIME_TYPE_FLAG_BN)))) {
return false;
}
// Now that we know we're comparing apples-to-apples, the comparison is a
// simple numeric one.
if (nSequenceMasked.gt(txToSequenceMasked)) {
return false;
}
return true;
}
/**

@@ -517,3 +673,2 @@ * Based on the inner loop of bitcoind's EvalScript function

Interpreter.prototype.step = function() {
var fRequireMinimal = (this.flags & Interpreter.SCRIPT_VERIFY_MINIMALDATA) !== 0;

@@ -664,4 +819,53 @@

case Opcode.OP_NOP3:
case Opcode.OP_CHECKSEQUENCEVERIFY:
if (!(this.flags & Interpreter.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY)) {
// not enabled; treat as a NOP3
if (this.flags & Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS) {
this.errstr = 'SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS';
return false;
}
break;
}
if (this.stack.length < 1) {
this.errstr = 'SCRIPT_ERR_INVALID_STACK_OPERATION';
return false;
}
// nSequence, like nLockTime, is a 32-bit unsigned
// integer field. See the comment in CHECKLOCKTIMEVERIFY
// regarding 5-byte numeric operands.
var nSequence = BN.fromScriptNumBuffer(this.stack[this.stack.length - 1], fRequireMinimal, 5);
// In the rare event that the argument may be < 0 due to
// some arithmetic being done first, you can always use
// 0 MAX CHECKSEQUENCEVERIFY.
if (nSequence.lt(new BN(0))) {
this.errstr = 'SCRIPT_ERR_NEGATIVE_LOCKTIME';
return false;
}
// To provide for future soft-fork extensibility, if the
// operand has the disabled lock-time flag set,
// CHECKSEQUENCEVERIFY behaves as a NOP.
if ((nSequence &
Interpreter.SEQUENCE_LOCKTIME_DISABLE_FLAG) != 0) {
break;
}
// Actually compare the specified lock time with the transaction.
if (!this.checkSequence(nSequence)) {
this.errstr = 'SCRIPT_ERR_UNSATISFIED_LOCKTIME';
return false;
}
break;
case Opcode.OP_NOP1:
case Opcode.OP_NOP3:
case Opcode.OP_NOP4:

@@ -693,3 +897,16 @@ case Opcode.OP_NOP5:

}
buf = this.stack.pop();
buf = this.stack[this.stack.length - 1];
if (this.flags & Interpreter.SCRIPT_VERIFY_MINIMALIF) {
buf = this.stack[this.stack.length - 1];
if (buf.length > 1) {
this.errstr = 'SCRIPT_ERR_MINIMALIF';
return false;
}
if (buf.length == 1 && buf[0]!=1) {
this.errstr = 'SCRIPT_ERR_MINIMALIF';
return false;
}
}
fValue = Interpreter.castToBool(buf);

@@ -699,2 +916,3 @@ if (opcodenum === Opcode.OP_NOTIF) {

}
this.stack.pop();
}

@@ -1245,2 +1463,5 @@ this.vfExec.push(fValue);

bufPubkey = this.stack[this.stack.length - 1];
if (!this.checkSignatureEncoding(bufSig) || !this.checkPubkeyEncoding(bufPubkey)) {
return false;
}

@@ -1257,6 +1478,2 @@ // Subset of script starting at the most recent codeseparator

if (!this.checkSignatureEncoding(bufSig) || !this.checkPubkeyEncoding(bufPubkey)) {
return false;
}
try {

@@ -1271,4 +1488,11 @@ sig = Signature.fromTxFormat(bufSig);

if (!fSuccess && (this.flags & Interpreter.SCRIPT_VERIFY_NULLFAIL) &&
bufSig.length) {
this.errstr = 'SCRIPT_ERR_NULLFAIL';
return false;
}
this.stack.pop();
this.stack.pop();
// stack.push_back(fSuccess ? vchTrue : vchFalse);

@@ -1311,2 +1535,9 @@ this.stack.push(fSuccess ? Interpreter.true : Interpreter.false);

i += nKeysCount;
// ikey2 is the position of last non-signature item in
// the stack. Top stack item = 1. With
// SCRIPT_VERIFY_NULLFAIL, this is used for cleanup if
// operation fails.
var ikey2 = nKeysCount + 2;
if (this.stack.length < i) {

@@ -1376,4 +1607,16 @@ this.errstr = 'SCRIPT_ERR_INVALID_STACK_OPERATION';

// Clean up stack of actual arguments
while (i-- > 1) {
if (!fSuccess && (this.flags & Interpreter.SCRIPT_VERIFY_NULLFAIL) &&
!ikey2 && this.stack[this.stack.length - 1].length) {
this.errstr = 'SCRIPT_ERR_NULLFAIL';
return false;
}
if (ikey2 > 0) {
ikey2--;
}
this.stack.pop();

@@ -1380,0 +1623,0 @@ }

@@ -20,3 +20,4 @@ 'use strict';

*/
function MultiSigInput(input, pubkeys, threshold, signatures) {
function MultiSigInput(input, pubkeys, threshold, signatures, opts) {
opts = opts || {};
Input.apply(this, arguments);

@@ -27,3 +28,7 @@ var self = this;

signatures = signatures || input.signatures;
this.publicKeys = _.sortBy(pubkeys, function(publicKey) { return publicKey.toString('hex'); });
if (opts.noSorting) {
this.publicKeys = pubkeys
} else {
this.publicKeys = _.sortBy(pubkeys, function(publicKey) { return publicKey.toString('hex'); });
}
$.checkState(Script.buildMultisigOut(this.publicKeys, threshold).equals(this.output.script),

@@ -30,0 +35,0 @@ 'Provided public keys don\'t match to the provided output script');

@@ -22,4 +22,5 @@ 'use strict';

*/
function MultiSigScriptHashInput(input, pubkeys, threshold, signatures, nestedWitness) {
function MultiSigScriptHashInput(input, pubkeys, threshold, signatures, nestedWitness, opts) {
/* jshint maxstatements:20 */
opts = opts || {};
Input.apply(this, arguments);

@@ -31,3 +32,7 @@ var self = this;

this.nestedWitness = nestedWitness ? true : false;
this.publicKeys = _.sortBy(pubkeys, function(publicKey) { return publicKey.toString('hex'); });
if (opts.noSorting) {
this.publicKeys = pubkeys
} else {
this.publicKeys = _.sortBy(pubkeys, function(publicKey) { return publicKey.toString('hex'); });
}
this.redeemScript = Script.buildMultisigOut(this.publicKeys, threshold);

@@ -34,0 +39,0 @@ if (this.nestedWitness) {

@@ -609,4 +609,7 @@ 'use strict';

* @param {boolean=} nestedWitness - Indicates that the utxo is nested witness p2sh
* @param {Object=} opts - Several options:
* - noSorting: defaults to false, if true and is multisig, don't
* sort the given public keys before creating the script
*/
Transaction.prototype.from = function(utxo, pubkeys, threshold, nestedWitness) {
Transaction.prototype.from = function(utxo, pubkeys, threshold, nestedWitness, opts) {
if (_.isArray(utxo)) {

@@ -627,3 +630,3 @@ var self = this;

if (pubkeys && threshold) {
this._fromMultisigUtxo(utxo, pubkeys, threshold, nestedWitness);
this._fromMultisigUtxo(utxo, pubkeys, threshold, nestedWitness, opts);
} else {

@@ -656,3 +659,3 @@ this._fromNonP2SH(utxo);

Transaction.prototype._fromMultisigUtxo = function(utxo, pubkeys, threshold, nestedWitness) {
Transaction.prototype._fromMultisigUtxo = function(utxo, pubkeys, threshold, nestedWitness, opts) {
$.checkArgument(threshold <= pubkeys.length,

@@ -677,3 +680,3 @@ 'Number of required signatures must be greater than the number of public keys');

script: Script.empty()
}, pubkeys, threshold, false, nestedWitness));
}, pubkeys, threshold, false, nestedWitness, opts));
};

@@ -763,2 +766,18 @@

/**
* Manually set the fee per Byte for this transaction. Beware that this resets all the signatures
* for inputs (in further versions, SIGHASH_SINGLE or SIGHASH_NONE signatures will not
* be reset).
* fee per Byte will be ignored if fee per KB is set
*
* @param {number} amount satoshis per Byte to be sent
* @return {Transaction} this, for chaining
*/
Transaction.prototype.feePerByte = function (amount) {
$.checkArgument(_.isNumber(amount), 'amount must be a number');
this._feePerByte = amount;
this._updateChangeOutput();
return this;
};
/* Output management */

@@ -907,9 +926,7 @@

if (_.isUndefined(this._inputAmount)) {
var self = this;
this._inputAmount = 0;
_.each(this.inputs, function(input) {
this._inputAmount = _.sumBy(this.inputs, function(input) {
if (_.isUndefined(input.output)) {
throw new errors.Transaction.Input.MissingPreviousOutput();
}
self._inputAmount += input.output.satoshis;
return input.output.satoshis;
});

@@ -976,6 +993,15 @@ }

*/
Transaction.prototype._estimateFee = function() {
Transaction.prototype._estimateFee = function () {
var estimatedSize = this._estimateSize();
var available = this._getUnspentValue();
return Transaction._estimateFee(estimatedSize, available, this._feePerKb);
var feeRate = this._feePerByte || (this._feePerKb || Transaction.FEE_PER_KB) / 1000;
function getFee(size) {
return size * feeRate;
}
var fee = Math.ceil(getFee(estimatedSize));
var feeWithChange = Math.ceil(getFee(estimatedSize) + getFee(Transaction.CHANGE_OUTPUT_MAX_SIZE));
if (!this._changeScript || available <= feeWithChange) {
return fee;
}
return feeWithChange;
};

@@ -993,10 +1019,2 @@

Transaction._estimateFee = function(size, amountAvailable, feePerKb) {
var fee = Math.ceil(size / 1000) * (feePerKb || Transaction.FEE_PER_KB);
if (amountAvailable > fee) {
size += Transaction.CHANGE_OUTPUT_MAX_SIZE;
}
return Math.ceil(size / 1000) * (feePerKb || Transaction.FEE_PER_KB);
};
Transaction.prototype._estimateSize = function() {

@@ -1003,0 +1021,0 @@ var result = Transaction.MAXIMUM_EXTRA_SIZE;

@@ -47,5 +47,5 @@ 'use strict';

var script = new Script(data.scriptPubKey || data.script);
$.checkArgument(!_.isUndefined(data.amount) || !_.isUndefined(data.satoshis),
'Must provide an amount for the output');
var amount = !_.isUndefined(data.amount) ? new Unit.fromBTC(data.amount).toSatoshis() : data.satoshis;
amount = amount || data.value;
$.checkArgument(amount, 'Must provide an amount for the output');
$.checkArgument(_.isNumber(amount), 'Amount must be a number');

@@ -52,0 +52,0 @@ JSUtil.defineImmutable(this, {

{
"name": "bitcore-lib",
"version": "8.0.0",
"version": "8.1.0",
"description": "A pure and powerful JavaScript Bitcoin library.",

@@ -10,2 +10,3 @@ "author": "BitPay <dev@bitpay.com>",

"test": "gulp test",
"test:ci": "npm run test",
"coverage": "gulp coverage",

@@ -39,16 +40,18 @@ "build": "gulp"

"bn.js": "=4.11.8",
"bs58": "=4.0.1",
"bs58": "^4.0.1",
"buffer-compare": "=1.1.1",
"elliptic": "=6.4.0",
"inherits": "=2.0.1",
"lodash": "=4.17.4"
"lodash": "=4.17.11"
},
"devDependencies": {
"bitcore-build": "https://github.com/bitpay/bitcore-build.git#d4e8b2b2f1e2c065c3a807dcb6a6250f61d67ab3",
"brfs": "^1.2.0",
"chai": "^1.10.0",
"gulp": "^3.8.10",
"sinon": "^1.13.0"
"bitcore-build": "^8.1.0",
"brfs": "^2.0.1",
"chai": "^4.2.0",
"gulp": "^4.0.0",
"karma-phantomjs-launcher": "^1.0.4",
"sinon": "^7.1.1"
},
"license": "MIT"
"license": "MIT",
"gitHead": "7446c100433e5a01c630497dea768e5c9af6d34c"
}

@@ -19,19 +19,30 @@ 'use strict';

describe('BlockHeader', function() {
var version;
var prevblockidbuf;
var merklerootbuf;
var time;
var bits;
var nonce;
var bh;
var bhhex;
var bhbuf;
var version = data.version;
var prevblockidbuf = new Buffer(data.prevblockidhex, 'hex');
var merklerootbuf = new Buffer(data.merkleroothex, 'hex');
var time = data.time;
var bits = data.bits;
var nonce = data.nonce;
var bh = new BlockHeader({
version: version,
prevHash: prevblockidbuf,
merkleRoot: merklerootbuf,
time: time,
bits: bits,
nonce: nonce
before(function () {
version = data.version;
prevblockidbuf = new Buffer(data.prevblockidhex, 'hex');
merklerootbuf = new Buffer(data.merkleroothex, 'hex');
time = data.time;
bits = data.bits;
nonce = data.nonce;
bh = new BlockHeader({
version: version,
prevHash: prevblockidbuf,
merkleRoot: merklerootbuf,
time: time,
bits: bits,
nonce: nonce
});
bhhex = data.blockheaderhex;
bhbuf = new Buffer(bhhex, 'hex');
});
var bhhex = data.blockheaderhex;
var bhbuf = new Buffer(bhhex, 'hex');

@@ -38,0 +49,0 @@ it('should make a new blockheader', function() {

@@ -15,7 +15,14 @@ 'use strict';

describe('MerkleBlock', function() {
var blockhex = data.HEX[0];
var blockbuf = new Buffer(blockhex,'hex');
var blockJSON = JSON.stringify(data.JSON[0]);
var blockObject = JSON.parse(JSON.stringify(data.JSON[0]));
var blockhex;
var blockbuf;
var blockJSON;
var blockObject;
before(function() {
blockhex = data.HEX[0];
blockbuf = new Buffer(blockhex,'hex');
blockJSON = JSON.stringify(data.JSON[0]);
blockObject = JSON.parse(JSON.stringify(data.JSON[0]));
});
describe('#constructor', function() {

@@ -64,3 +71,3 @@ it('should make a new merkleblock from buffer', function() {

var block = MerkleBlock(blockbuf);
MerkleBlock.fromObject(block.toObject()).should.exist();
should.exist(MerkleBlock.fromObject(block.toObject()));
});

@@ -160,3 +167,3 @@

it('should validate good merkleblocks', function() {
var hashOfFilteredTx = '6f64fd5aa9dd01f74c03656d376625cf80328d83d9afebe60cc68b8f0e245bd9'
var hashOfFilteredTx = '6f64fd5aa9dd01f74c03656d376625cf80328d83d9afebe60cc68b8f0e245bd9'
var b = MerkleBlock(data.JSON[3]);

@@ -233,2 +240,1 @@ b.filterdTxsHash()[0].should.equal(hashOfFilteredTx);

});

@@ -83,4 +83,4 @@ [

"sign", ["L4jFVcDaqZCkknP5KQWjCBgiLFxKxRxywNGTucm3jC3ozByZcbZv"],
"serialize", "010000000220c24f763536edb05ce8df2a4816d971be4f20b58451d71589db434aca98bfaf00000000fdfd0000473044022024b955f8bf6aaf0741da011e3214eaec7040cd12694303471cefc6ba0cc4ec290220124738015033a465636dec1524a6f956a229e69d31aef6c7a98b2a291f3cfc6701483045022100e6ae6c43240e8a11a6de2d034501c2a366c0ccdf069c7828de0791f05e68e787022028b80bd36c2b2ae63fe7afb491da6c0ce23fbbb982450962c817b20f0bb24075014c695221020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2210271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b2103a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd853aeffffffffa0644cd1606e081c59eb65fe69d4a83a3a822da423bc392c91712fb77a192edc00000000fc00483045022100ae7f136cf906dc37d34d5035b8d2001c6a783773b74507ba83080e73e903623f0220023baf7738395268f7097e5586130f682b911fd49b83b265f8fa481f2a6b1ee90146304302201d60f512a8b37663d85c123933053e0354f13d89daf699ca600defa03d4a1dab021f41042b6e4ba30311fc3a68c228c3725f3b0f05a4453ef19408e6a4ae30a2b0014c695221020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2210271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b2103a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd853aeffffffff03f04902000000000017a9144de752833233fe69a20064f29b2ca0f6399c8af387007102000000000017a9144de752833233fe69a20064f29b2ca0f6399c8af387ab2f03000000000017a9146c8d8b04c6a1e664b1ec20ec932760760c97688e8700000000"
"serialize", "010000000220c24f763536edb05ce8df2a4816d971be4f20b58451d71589db434aca98bfaf00000000fc004730440220658e8a9a15d05dc72f5ac59823bc82472fa8cdc7853910111dc4717850b4a6ca02201c2e3479704a6581cc8b233fd5533b8f19d093815d60e62b508716ea28010826014730440220054502b9dbf26a962b9b83e719b6c70a55ce6a931d977da0ad26bfcd483d438402205a4ae4193b502592b573bd995d3fa370ef56c6e381ee6356991d14173b0dc396014c695221020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2210271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b2103a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd853aeffffffffa0644cd1606e081c59eb65fe69d4a83a3a822da423bc392c91712fb77a192edc00000000fc0047304402207e1a40f986ee26942f780bb2f384d5425b84079149ee659e3ee8d243568cc02102200519928c0c1cd098d296a64316335db5f894f1ddf27453c4dc07e1cc4f4bbf6d014730440220760ef53cf380eeb6683999090577f9b644bf44039f4a887fdd44ccbd9ece72ba02206ad3cf8bb6c1433a203a818eaa43d89c657dc44f9ac514a02fcc295f3beb405e014c695221020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2210271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b2103a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd853aeffffffff03f04902000000000017a9144de752833233fe69a20064f29b2ca0f6399c8af387007102000000000017a9144de752833233fe69a20064f29b2ca0f6399c8af38723b203000000000017a9146c8d8b04c6a1e664b1ec20ec932760760c97688e8700000000"
]
]

@@ -284,3 +284,3 @@ 'use strict';

var count = 0;
var stub = sandbox.stub(bitcore.crypto.BN.prototype, 'toBuffer', function(args) {
var stub = sandbox.stub(bitcore.crypto.BN.prototype, 'toBuffer').callsFake(function (args) {
// On the fourth call to the function give back an invalid private key

@@ -287,0 +287,0 @@ // otherwise use the normal behavior.

@@ -18,18 +18,15 @@ 'use strict';

it('will enable/disable regtest Network', function() {
it('#DEPRECATED will enable/disable regtest Network', function() {
const beforeEnable = networks.testnet;
networks.enableRegtest();
networks.testnet.networkMagic.should.deep.equal(new Buffer('fabfb5da', 'hex'));
networks.testnet.port.should.equal(18444);
networks.testnet.dnsSeeds.should.deep.equal([]);
networks.testnet.regtestEnabled.should.equal(true);
/*
*networks.testnet.networkMagic.should.deep.equal(new Buffer('fabfb5da', 'hex'));
*networks.testnet.port.should.equal(18444);
*networks.testnet.dnsSeeds.should.deep.equal([]);
*networks.testnet.regtestEnabled.should.equal(true);
*/
networks.testnet.should.deep.equal(beforeEnable);
networks.disableRegtest();
networks.testnet.networkMagic.should.deep.equal(new Buffer('0b110907', 'hex'));
networks.testnet.port.should.equal(18333);
networks.testnet.dnsSeeds.should.deep.equal([
'testnet-seed.bitcoin.petertodd.org',
'testnet-seed.bluematt.me',
'testnet-seed.alexykot.me',
'testnet-seed.bitcoin.schildbach.de'
]);
networks.testnet.should.deep.equal(beforeEnable);
});

@@ -39,3 +36,3 @@

var network = networks.get('regtest');
network.should.equal(networks.testnet);
network.should.equal(networks.regtest);
});

@@ -42,0 +39,0 @@

@@ -88,4 +88,4 @@ 'use strict';

describe('@map', function() {
it('should have a map containing 117 elements', function() {
_.size(Opcode.map).should.equal(117);
it('should have a map containing 118 elements', function() {
_.size(Opcode.map).should.equal(118);
});

@@ -92,0 +92,0 @@ });

@@ -15,4 +15,3 @@ 'use strict';

var script_valid = require('../data/bitcoind/script_valid');
var script_invalid = require('../data/bitcoind/script_invalid');
var script_tests = require('../data/bitcoind/script_tests');
var tx_valid = require('../data/bitcoind/tx_valid');

@@ -295,2 +294,28 @@ var tx_invalid = require('../data/bitcoind/tx_invalid');

}
if (flagstr.indexOf('CHECKSEQUENCEVERIFY') !== -1) {
flags = flags | Interpreter.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY;
}
if (flagstr.indexOf('NULLFAIL') !== -1) {
flags = flags | Interpreter.SCRIPT_VERIFY_NULLFAIL;
}
if (flagstr.indexOf('WITNESS') !== -1) {
flags = flags | Interpreter.SCRIPT_VERIFY_WITNESS;
}
if (flagstr.indexOf('DISCOURAGE_UPGRADABLE_WITNESS') !== -1) {
flags = flags | Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM;
}
if (flagstr.indexOf('CLEANSTACK') !== -1) {
flags = flags | Interpreter.SCRIPT_VERIFY_CLEANSTACK;
}
if (flagstr.indexOf('WITNESS_PUBKEYTYPE') !== -1) {
flags = flags | Interpreter.SCRIPT_VERIFY_WITNESS_PUBKEYTYPE;
}
if (flagstr.indexOf('MINIMALIF') !== -1) {
flags = flags | Interpreter.SCRIPT_VERIFY_MINIMALIF;
}
return flags;

@@ -305,3 +330,4 @@ };

var testFixture = function(vector, expected) {
var testFixture = function(vector, expected, witness, amount) {
var amount = amount || 0;
var scriptSig = Script.fromBitcoindString(vector[0]);

@@ -322,3 +348,3 @@ var scriptPubkey = Script.fromBitcoindString(vector[1]);

script: scriptPubkey,
satoshis: 0
satoshis: amount,
}));

@@ -336,11 +362,12 @@ var idbuf = credtx.id;

script: new Script(),
satoshis: 0
satoshis: amount,
}));
var interp = new Interpreter();
var verified = interp.verify(scriptSig, scriptPubkey, spendtx, 0, flags);
var verified = interp.verify(scriptSig, scriptPubkey, spendtx, 0, flags, witness, amount);
verified.should.equal(expected);
};
describe('bitcoind script evaluation fixtures', function() {
var testAllFixtures = function(set, expected) {
var testAllFixtures = function(set) {
var c = 0;

@@ -352,14 +379,27 @@ set.forEach(function(vector) {

c++;
var descstr = vector[3];
var witness, amount;
if (_.isArray(vector[0])) {
var extra = vector.shift();
amount = extra.pop() * 1e8;
witness = extra.map(function(x) {
return Buffer.from(x,'hex');
});
} else {
return;
}
var fullScriptString = vector[0] + ' ' + vector[1];
var expected = vector[3] == 'OK';
var descstr = vector[4];
var comment = descstr ? (' (' + descstr + ')') : '';
it('should pass script_' + (expected ? '' : 'in') + 'valid ' +
it('should ' + vector[3] + ' script_tests ' +
'vector #' + c + ': ' + fullScriptString + comment,
function() {
testFixture(vector, expected);
testFixture(vector, expected, witness, amount);
});
});
};
testAllFixtures(script_valid, true);
testAllFixtures(script_invalid, false);
testAllFixtures(script_tests);

@@ -379,4 +419,4 @@ });

var txhex = vector[1];
var flags = getFlags(vector[2]);
var map = {};

@@ -383,0 +423,0 @@ inputs.forEach(function(input) {

@@ -932,3 +932,3 @@ 'use strict';

var script = Script.buildPublicKeyHashOut(address);
expect(BufferUtil.equal(script.getData(), address.hashBuffer)).to.be.true();
expect(BufferUtil.equal(script.getData(), address.hashBuffer)).to.be.equal(true);
});

@@ -938,6 +938,6 @@ it('for a P2SH address', function() {

var script = new Script(address);
expect(BufferUtil.equal(script.getData(), address.hashBuffer)).to.be.true();
expect(BufferUtil.equal(script.getData(), address.hashBuffer)).to.be.equal(true);
});
it('for a standard opreturn output', function() {
expect(BufferUtil.equal(Script('OP_RETURN 1 0xFF').getData(), new Buffer([255]))).to.be.true();
expect(BufferUtil.equal(Script('OP_RETURN 1 0xFF').getData(), new Buffer([255]))).to.be.equal(true);
});

@@ -944,0 +944,0 @@ it('fails if content is not recognized', function() {

@@ -20,10 +20,10 @@ 'use strict';

uri = URI.parse('bitcoin:');
expect(uri.address).to.be.undefined();
expect(uri.amount).to.be.undefined();
expect(uri.otherParam).to.be.undefined();
expect(uri.address).to.be.equal(undefined);
expect(uri.amount).to.be.equal(undefined);
expect(uri.otherParam).to.be.equal(undefined);
uri = URI.parse('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
uri.address.should.equal('1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
expect(uri.amount).to.be.undefined();
expect(uri.otherParam).to.be.undefined();
expect(uri.amount).to.be.equal(undefined);
expect(uri.otherParam).to.be.equal(undefined);

@@ -33,3 +33,3 @@ uri = URI.parse('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=123.22');

uri.amount.should.equal('123.22');
expect(uri.otherParam).to.be.undefined();
expect(uri.otherParam).to.be.equal(undefined);

@@ -92,3 +92,3 @@ uri = URI.parse('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=123.22' +

uri.amount.should.equal(12322000000);
expect(uri.otherParam).to.be.undefined();
expect(uri.otherParam).to.be.equal(undefined);
});

@@ -105,3 +105,3 @@

uri.address.should.be.instanceof(bitcore.Address);
expect(uri.other).to.be.undefined();
expect(uri.other).to.be.equal(undefined);
uri.extras.other.should.equal('param');

@@ -150,3 +150,3 @@ });

uri.amount.should.equal(120000000);
expect(uri.other).to.be.undefined();
expect(uri.other).to.be.equal(undefined);
uri.extras.other.should.equal('param');

@@ -153,0 +153,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc