Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bitcore-lib-dash

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitcore-lib-dash - npm Package Compare versions

Comparing version 0.13.16 to 0.13.17

2

bower.json
{
"name": "bitcore-lib",
"main": "./bitcore-lib.min.js",
"version": "0.13.16",
"version": "0.13.17",
"homepage": "http://bitcore.io",

@@ -6,0 +6,0 @@ "authors": [

'use strict';
var sha512 = require('sha512');
var x11hash = require('x11-hash');
var x11hash = require('x11-hash-js');
var crypto = require('crypto');

@@ -32,3 +32,3 @@ var BufferUtil = require('../util/buffer');

$.checkArgument(BufferUtil.isBuffer(buf));
return x11hash.digest(buf);
return new Buffer(x11hash.digest(buf, 1, 2));
};

@@ -35,0 +35,0 @@

@@ -503,13 +503,24 @@ 'use strict';

Script.identifiers = {};
Script.identifiers.PUBKEY_OUT = Script.prototype.isPublicKeyOut;
Script.identifiers.PUBKEY_IN = Script.prototype.isPublicKeyIn;
Script.identifiers.PUBKEYHASH_OUT = Script.prototype.isPublicKeyHashOut;
Script.identifiers.PUBKEYHASH_IN = Script.prototype.isPublicKeyHashIn;
Script.identifiers.MULTISIG_OUT = Script.prototype.isMultisigOut;
Script.identifiers.MULTISIG_IN = Script.prototype.isMultisigIn;
Script.identifiers.SCRIPTHASH_OUT = Script.prototype.isScriptHashOut;
Script.identifiers.SCRIPTHASH_IN = Script.prototype.isScriptHashIn;
Script.identifiers.DATA_OUT = Script.prototype.isDataOut;
/**
* @returns {object} The Script type if it is a known form,
* or Script.UNKNOWN if it isn't
*/
Script.prototype.classify = function() {
if (this._isInput) {
return this.classifyInput();
} else if (this._isOutput) {
return this.classifyOutput();
} else {
var outputType = this.classifyOutput();
return outputType != Script.types.UNKNOWN ? outputType : this.classifyInput();
}
};
Script.outputIdentifiers = {};
Script.outputIdentifiers.PUBKEY_OUT = Script.prototype.isPublicKeyOut;
Script.outputIdentifiers.PUBKEYHASH_OUT = Script.prototype.isPublicKeyHashOut;
Script.outputIdentifiers.MULTISIG_OUT = Script.prototype.isMultisigOut;
Script.outputIdentifiers.SCRIPTHASH_OUT = Script.prototype.isScriptHashOut;
Script.outputIdentifiers.DATA_OUT = Script.prototype.isDataOut;
/**

@@ -519,5 +530,5 @@ * @returns {object} The Script type if it is a known form,

*/
Script.prototype.classify = function() {
for (var type in Script.identifiers) {
if (Script.identifiers[type].bind(this)()) {
Script.prototype.classifyOutput = function() {
for (var type in Script.outputIdentifiers) {
if (Script.outputIdentifiers[type].bind(this)()) {
return Script.types[type];

@@ -529,4 +540,23 @@ }

Script.inputIdentifiers = {};
Script.inputIdentifiers.PUBKEY_IN = Script.prototype.isPublicKeyIn;
Script.inputIdentifiers.PUBKEYHASH_IN = Script.prototype.isPublicKeyHashIn;
Script.inputIdentifiers.MULTISIG_IN = Script.prototype.isMultisigIn;
Script.inputIdentifiers.SCRIPTHASH_IN = Script.prototype.isScriptHashIn;
/**
* @returns {object} The Script type if it is a known form,
* or Script.UNKNOWN if it isn't
*/
Script.prototype.classifyInput = function() {
for (var type in Script.inputIdentifiers) {
if (Script.inputIdentifiers[type].bind(this)()) {
return Script.types[type];
}
}
return Script.types.UNKNOWN;
};
/**
* @returns {boolean} if script is one of the known types

@@ -533,0 +563,0 @@ */

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

var MAXINT = 0xffffffff; // Math.pow(2, 32) - 1;
var DEFAULT_RBF_SEQNUMBER = MAXINT - 2;
var DEFAULT_SEQNUMBER = MAXINT;
var DEFAULT_LOCKTIME_SEQNUMBER = MAXINT - 1;
var DEFAULT_SEQNUMBER = 0xFFFFFFFF;
var DEFAULT_LOCKTIME_SEQNUMBER = 0x00000000;
function Input(params) {

@@ -28,4 +29,6 @@ if (!(this instanceof Input)) {

Input.MAXINT = MAXINT;
Input.DEFAULT_SEQNUMBER = DEFAULT_SEQNUMBER;
Input.DEFAULT_LOCKTIME_SEQNUMBER = DEFAULT_LOCKTIME_SEQNUMBER;
Input.DEFAULT_RBF_SEQNUMBER = DEFAULT_RBF_SEQNUMBER;

@@ -32,0 +35,0 @@ Object.defineProperty(Input.prototype, 'script', {

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

if (exists) {
return;
return this;
}

@@ -1201,3 +1201,32 @@ if (pubkeys && threshold) {

/**
* Determines if this transaction can be replaced in the mempool with another
* transaction that provides a sufficiently higher fee (RBF).
*/
Transaction.prototype.isRBF = function() {
for (var i = 0; i < this.inputs.length; i++) {
var input = this.inputs[i];
if (input.sequenceNumber < Input.MAXINT - 1) {
return true;
}
}
return false;
};
/**
* Enable this transaction to be replaced in the mempool (RBF) if a transaction
* includes a sufficiently higher fee. It will set the sequenceNumber to
* DEFAULT_RBF_SEQNUMBER for all inputs if the sequence number does not
* already enable RBF.
*/
Transaction.prototype.enableRBF = function() {
for (var i = 0; i < this.inputs.length; i++) {
var input = this.inputs[i];
if (input.sequenceNumber >= Input.MAXINT - 1) {
input.sequenceNumber = Input.DEFAULT_RBF_SEQNUMBER;
}
}
return this;
};
module.exports = Transaction;
{
"name": "bitcore-lib-dash",
"version": "0.13.16",
"version": "0.13.17",
"dependencies": {

@@ -52,8 +52,8 @@ "bn.js": {

},
"x11-hash": {
"version": "0.0.3",
"from": "git://github.com/zone117x/node-x11-hash.git#c7b65aa08ea44861d5739e2d5404cfc939ede55b",
"resolved": "git://github.com/zone117x/node-x11-hash.git#c7b65aa08ea44861d5739e2d5404cfc939ede55b"
"x11-hash-js": {
"version": "1.0.0",
"from": "x11-hash-js@*",
"resolved": "https://registry.npmjs.org/x11-hash-js/-/x11-hash-js-1.0.0.tgz"
}
}
}
{
"name": "bitcore-lib-dash",
"version": "0.13.16",
"version": "0.13.17",
"description": "A pure and powerful JavaScript Dash library.",

@@ -94,6 +94,6 @@ "author": "BitPay <dev@bitpay.com>",

"sha512": "=0.0.1",
"x11-hash": "git://github.com/zone117x/node-x11-hash.git#c7b65aa08ea44861d5739e2d5404cfc939ede55b"
"x11-hash-js": "^1.0.0"
},
"devDependencies": {
"bitcore-build-dash": "dashpay/bitcore-build",
"bitcore-build-dash": "dashpay/bitcore-build-dash",
"browserify": "latest",

@@ -100,0 +100,0 @@ "brfs": "^1.2.0",

@@ -416,2 +416,74 @@ 'use strict';

describe('#classifyInput', function() {
it('shouldn\'t classify public key hash out', function() {
Script('OP_DUP OP_HASH160 20 0x0000000000000000000000000000000000000000 OP_EQUALVERIFY OP_CHECKSIG').classifyInput().should.equal(Script.types.UNKNOWN);
});
it('should classify public key hash in', function() {
Script('47 0x3044022077a8d81e656c4a1c1721e68ce35fa0b27f13c342998e75854858c12396a15ffa02206378a8c6959283c008c87a14a9c0ada5cf3934ac5ee29f1fef9cac6969783e9801 21 0x03993c230da7dabb956292851ae755f971c50532efc095a16bee07f83ab9d262df').classifyInput().should.equal(Script.types.PUBKEYHASH_IN);
});
it('shouldn\'t classify script hash out', function() {
Script('OP_HASH160 20 0x0000000000000000000000000000000000000000 OP_EQUAL').classifyInput().should.equal(Script.types.UNKNOWN);
});
it('should classify script hash in', function() {
Script('OP_0 73 0x30460221008ca148504190c10eea7f5f9c283c719a37be58c3ad617928011a1bb9570901d2022100ced371a23e86af6f55ff4ce705c57d2721a09c4d192ca39d82c4239825f75a9801 72 0x30450220357011fd3b3ad2b8f2f2d01e05dc6108b51d2a245b4ef40c112d6004596f0475022100a8208c93a39e0c366b983f9a80bfaf89237fcd64ca543568badd2d18ee2e1d7501 OP_PUSHDATA1 105 0x5221024c02dff2f0b8263a562a69ec875b2c95ffad860f428acf2f9e8c6492bd067d362103546324a1351a6b601c623b463e33b6103ca444707d5b278ece1692f1aa7724a42103b1ad3b328429450069cc3f9fa80d537ee66ba1120e93f3f185a5bf686fb51e0a53ae').classifyInput().should.equal(Script.types.SCRIPTHASH_IN);
});
it('shouldn\'t classify MULTISIG out', function() {
Script('OP_2 21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 OP_2 OP_CHECKMULTISIG').classifyInput().should.equal(Script.types.UNKNOWN);
});
it('should classify MULTISIG in', function() {
Script('OP_0 0x47 0x3044022002a27769ee33db258bdf7a3792e7da4143ec4001b551f73e6a190b8d1bde449d02206742c56ccd94a7a2e16ca52fc1ae4a0aa122b0014a867a80de104f9cb18e472c01').classifyInput().should.equal(Script.types.MULTISIG_IN);
});
it('shouldn\'t classify OP_RETURN data out', function() {
Script('OP_RETURN 1 0x01').classifyInput().should.equal(Script.types.UNKNOWN);
});
it('shouldn\'t classify public key out', function() {
Script('41 0x0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 OP_CHECKSIG').classifyInput().should.equal(Script.types.UNKNOWN);
});
it('should classify public key in', function() {
Script('47 0x3044022007415aa37ce7eaa6146001ac8bdefca0ddcba0e37c5dc08c4ac99392124ebac802207d382307fd53f65778b07b9c63b6e196edeadf0be719130c5db21ff1e700d67501').classifyInput().should.equal(Script.types.PUBKEY_IN);
});
it('should classify unknown', function() {
Script('OP_TRUE OP_FALSE').classifyInput().should.equal(Script.types.UNKNOWN);
});
it('should classify scriptHashIn, eventhough it\'s opreturn', function() {
Script('6a1c3630fd3792f7e847ae5e27985dfb127542ef37ac2a5147c3b9cec7ba').classifyInput().should.equal(Script.types.SCRIPTHASH_IN);
});
});
describe('#classifyOutput', function() {
it('should classify public key hash out', function() {
Script('OP_DUP OP_HASH160 20 0x0000000000000000000000000000000000000000 OP_EQUALVERIFY OP_CHECKSIG').classifyOutput().should.equal(Script.types.PUBKEYHASH_OUT);
});
it('shouldn\'t classify public key hash in', function() {
Script('47 0x3044022077a8d81e656c4a1c1721e68ce35fa0b27f13c342998e75854858c12396a15ffa02206378a8c6959283c008c87a14a9c0ada5cf3934ac5ee29f1fef9cac6969783e9801 21 0x03993c230da7dabb956292851ae755f971c50532efc095a16bee07f83ab9d262df').classifyOutput().should.equal(Script.types.UNKNOWN);
});
it('should classify script hash out', function() {
Script('OP_HASH160 20 0x0000000000000000000000000000000000000000 OP_EQUAL').classifyOutput().should.equal(Script.types.SCRIPTHASH_OUT);
});
it('shouldn\'t classify script hash in', function() {
Script('OP_0 73 0x30460221008ca148504190c10eea7f5f9c283c719a37be58c3ad617928011a1bb9570901d2022100ced371a23e86af6f55ff4ce705c57d2721a09c4d192ca39d82c4239825f75a9801 72 0x30450220357011fd3b3ad2b8f2f2d01e05dc6108b51d2a245b4ef40c112d6004596f0475022100a8208c93a39e0c366b983f9a80bfaf89237fcd64ca543568badd2d18ee2e1d7501 OP_PUSHDATA1 105 0x5221024c02dff2f0b8263a562a69ec875b2c95ffad860f428acf2f9e8c6492bd067d362103546324a1351a6b601c623b463e33b6103ca444707d5b278ece1692f1aa7724a42103b1ad3b328429450069cc3f9fa80d537ee66ba1120e93f3f185a5bf686fb51e0a53ae').classifyOutput().should.equal(Script.types.UNKNOWN);
});
it('should classify MULTISIG out', function() {
Script('OP_2 21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 OP_2 OP_CHECKMULTISIG').classifyOutput().should.equal(Script.types.MULTISIG_OUT);
});
it('shouldn\'t classify MULTISIG in', function() {
Script('OP_0 0x47 0x3044022002a27769ee33db258bdf7a3792e7da4143ec4001b551f73e6a190b8d1bde449d02206742c56ccd94a7a2e16ca52fc1ae4a0aa122b0014a867a80de104f9cb18e472c01').classifyOutput().should.equal(Script.types.UNKNOWN);
});
it('should classify OP_RETURN data out', function() {
Script('OP_RETURN 1 0x01').classifyOutput().should.equal(Script.types.DATA_OUT);
});
it('should classify public key out', function() {
Script('41 0x0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 OP_CHECKSIG').classifyOutput().should.equal(Script.types.PUBKEY_OUT);
});
it('shouldn\'t classify public key in', function() {
Script('47 0x3044022007415aa37ce7eaa6146001ac8bdefca0ddcba0e37c5dc08c4ac99392124ebac802207d382307fd53f65778b07b9c63b6e196edeadf0be719130c5db21ff1e700d67501').classifyOutput().should.equal(Script.types.UNKNOWN);
});
it('should classify unknown', function() {
Script('OP_TRUE OP_FALSE').classifyOutput().should.equal(Script.types.UNKNOWN);
});
it('should classify opreturn eventhough it also looks like a scriptHashIn', function() {
Script('6a1c3630fd3792f7e847ae5e27985dfb127542ef37ac2a5147c3b9cec7ba').classifyOutput().should.equal(Script.types.DATA_OUT);
});
});
describe('#classify', function() {

@@ -448,2 +520,24 @@ it('should classify public key hash out', function() {

});
it('should classify opreturn eventhough it also looks like a scriptHashIn', function() {
Script('6a1c3630fd3792f7e847ae5e27985dfb127542ef37ac2a5147c3b9cec7ba').classifyInput().should.equal(Script.types.SCRIPTHASH_IN);
Script('6a1c3630fd3792f7e847ae5e27985dfb127542ef37ac2a5147c3b9cec7ba').classify().should.equal(Script.types.DATA_OUT);
});
it('should classify scriptHashIn eventhough it is opreturn when script is marked is input', function() {
Script('6a1c3630fd3792f7e847ae5e27985dfb127542ef37ac2a5147c3b9cec7ba').classify().should.equal(Script.types.DATA_OUT);
var s = Script('6a1c3630fd3792f7e847ae5e27985dfb127542ef37ac2a5147c3b9cec7ba');
s._isInput = true; // this is normally set by when Script is initiated as part if Input or Output objects
s.classify().should.equal(Script.types.SCRIPTHASH_IN);
});
it('should classify unknown eventhough it is public key hash when marked as input', function() {
Script('OP_DUP OP_HASH160 20 0x0000000000000000000000000000000000000000 OP_EQUALVERIFY OP_CHECKSIG').classify().should.equal(Script.types.PUBKEYHASH_OUT);
var s = Script('OP_DUP OP_HASH160 20 0x0000000000000000000000000000000000000000 OP_EQUALVERIFY OP_CHECKSIG');
s._isInput = true; // this is normally set by when Script is initiated as part if Input or Output objects
s.classify().should.equal(Script.types.UNKNOWN);
});
it('should classify unknown eventhough it is public key hash in when marked as output', function() {
var s = Script('47 0x3044022077a8d81e656c4a1c1721e68ce35fa0b27f13c342998e75854858c12396a15ffa02206378a8c6959283c008c87a14a9c0ada5cf3934ac5ee29f1fef9cac6969783e9801 21 0x03993c230da7dabb956292851ae755f971c50532efc095a16bee07f83ab9d262df');
s.classify().should.equal(Script.types.PUBKEYHASH_IN);
s._isOutput = true; // this is normally set by when Script is initiated as part if Input or Output objects
s.classify().should.equal(Script.types.UNKNOWN);
});
});

@@ -450,0 +544,0 @@

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

txId: 'a477af6b2667c29670467e4e0728b685ee07b240235771862318e29ddbe58458',
outputIndex: 0,
outputIndex: 1,
script: Script.buildPublicKeyHashOut(fromAddress).toString(),

@@ -1124,2 +1124,102 @@ satoshis: 1e8

});
describe('Replace-by-fee', function() {
describe('#enableRBF', function() {
it('only enable inputs not already enabled (0xffffffff)', function() {
var tx = new Transaction()
.from(simpleUtxoWith1BTC)
.from(simpleUtxoWith100000Satoshis)
.to([{address: toAddress, satoshis: 50000}])
.fee(15000)
.change(changeAddress)
.sign(privateKey);
tx.inputs[0].sequenceNumber = 0x00000000;
tx.enableRBF();
tx.inputs[0].sequenceNumber.should.equal(0x00000000);
tx.inputs[1].sequenceNumber.should.equal(0xfffffffd);
});
it('enable for inputs with 0xffffffff and 0xfffffffe', function() {
var tx = new Transaction()
.from(simpleUtxoWith1BTC)
.from(simpleUtxoWith100000Satoshis)
.to([{address: toAddress, satoshis: 50000}])
.fee(15000)
.change(changeAddress)
.sign(privateKey);
tx.inputs[0].sequenceNumber = 0xffffffff;
tx.inputs[1].sequenceNumber = 0xfffffffe;
tx.enableRBF();
tx.inputs[0].sequenceNumber.should.equal(0xfffffffd);
tx.inputs[1].sequenceNumber.should.equal(0xfffffffd);
});
});
describe('#isRBF', function() {
it('enable and determine opt-in', function() {
var tx = new Transaction()
.from(simpleUtxoWith100000Satoshis)
.to([{address: toAddress, satoshis: 50000}])
.fee(15000)
.change(changeAddress)
.enableRBF()
.sign(privateKey);
tx.isRBF().should.equal(true);
});
it('determine opt-out with default sequence number', function() {
var tx = new Transaction()
.from(simpleUtxoWith100000Satoshis)
.to([{address: toAddress, satoshis: 50000}])
.fee(15000)
.change(changeAddress)
.sign(privateKey);
tx.isRBF().should.equal(false);
});
it('determine opt-out with 0xfffffffe', function() {
var tx = new Transaction()
.from(simpleUtxoWith1BTC)
.from(simpleUtxoWith100000Satoshis)
.to([{address: toAddress, satoshis: 50000 + 1e8}])
.fee(15000)
.change(changeAddress)
.sign(privateKey);
tx.inputs[0].sequenceNumber = 0xfffffffe;
tx.inputs[1].sequenceNumber = 0xfffffffe;
tx.isRBF().should.equal(false);
});
it('determine opt-out with 0xffffffff', function() {
var tx = new Transaction()
.from(simpleUtxoWith1BTC)
.from(simpleUtxoWith100000Satoshis)
.to([{address: toAddress, satoshis: 50000 + 1e8}])
.fee(15000)
.change(changeAddress)
.sign(privateKey);
tx.inputs[0].sequenceNumber = 0xffffffff;
tx.inputs[1].sequenceNumber = 0xffffffff;
tx.isRBF().should.equal(false);
});
it('determine opt-in with 0xfffffffd (first input)', function() {
var tx = new Transaction()
.from(simpleUtxoWith1BTC)
.from(simpleUtxoWith100000Satoshis)
.to([{address: toAddress, satoshis: 50000 + 1e8}])
.fee(15000)
.change(changeAddress)
.sign(privateKey);
tx.inputs[0].sequenceNumber = 0xfffffffd;
tx.inputs[1].sequenceNumber = 0xffffffff;
tx.isRBF().should.equal(true);
});
it('determine opt-in with 0xfffffffd (second input)', function() {
var tx = new Transaction()
.from(simpleUtxoWith1BTC)
.from(simpleUtxoWith100000Satoshis)
.to([{address: toAddress, satoshis: 50000 + 1e8}])
.fee(15000)
.change(changeAddress)
.sign(privateKey);
tx.inputs[0].sequenceNumber = 0xffffffff;
tx.inputs[1].sequenceNumber = 0xfffffffd;
tx.isRBF().should.equal(true);
});
});
});
});

@@ -1126,0 +1226,0 @@

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