Socket
Socket
Sign inDemoInstall

bitcore-lib-cash

Package Overview
Dependencies
Maintainers
3
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitcore-lib-cash - npm Package Compare versions

Comparing version 8.16.2 to 8.17.0

9

lib/errors/spec.js

@@ -69,3 +69,10 @@ 'use strict';

message: 'No previous output information.'
}]
}, {
name: 'BlockHeightOutOfRange',
message: 'Block Height can only be between 0 and 65535'
} , {
name: 'LockTimeRange',
message: 'Seconds needs to be more that 0 and less that 33553920'
}
]
}, {

@@ -72,0 +79,0 @@ name: 'NeedMoreInfo',

@@ -18,3 +18,11 @@ 'use strict';

var DEFAULT_LOCKTIME_SEQNUMBER = MAXINT - 1;
const SEQUENCE_LOCKTIME_DISABLE_FLAG = Math.pow(2,31); // (1 << 31);
const SEQUENCE_LOCKTIME_TYPE_FLAG = Math.pow(2,22); // (1 << 22);
const SEQUENCE_LOCKTIME_MASK = 0xffff;
const SEQUENCE_LOCKTIME_GRANULARITY = 512; // 512 seconds
const SEQUENCE_BLOCKDIFF_LIMIT = Math.pow(2,16)-1; // 16 bits
function Input(params) {

@@ -33,2 +41,3 @@ if (!(this instanceof Input)) {

Input.DEFAULT_RBF_SEQNUMBER = DEFAULT_RBF_SEQNUMBER;
Input.SEQUENCE_LOCKTIME_TYPE_FLAG = SEQUENCE_LOCKTIME_TYPE_FLAG;

@@ -206,2 +215,64 @@ Object.defineProperty(Input.prototype, 'script', {

/**
* Sets sequence number so that transaction is not valid until the desired seconds
* since the transaction is mined
*
* @param {Number} time in seconds
* @return {Transaction} this
*/
Input.prototype.lockForSeconds = function(seconds) {
$.checkArgument(_.isNumber(seconds));
if (seconds < 0 || seconds >= SEQUENCE_LOCKTIME_GRANULARITY * SEQUENCE_LOCKTIME_MASK) {
throw new errors.Transaction.Input.LockTimeRange();
}
seconds = parseInt(Math.floor(seconds / SEQUENCE_LOCKTIME_GRANULARITY));
// SEQUENCE_LOCKTIME_DISABLE_FLAG = 1
this.sequenceNumber = seconds | SEQUENCE_LOCKTIME_TYPE_FLAG ;
return this;
};
/**
* Sets sequence number so that transaction is not valid until the desired block height differnece since the tx is mined
*
* @param {Number} height
* @return {Transaction} this
*/
Input.prototype.lockUntilBlockHeight = function(heightDiff) {
$.checkArgument(_.isNumber(heightDiff));
if (heightDiff < 0 || heightDiff >= SEQUENCE_BLOCKDIFF_LIMIT) {
throw new errors.Transaction.Input.BlockHeightOutOfRange();
}
// SEQUENCE_LOCKTIME_TYPE_FLAG = 0
// SEQUENCE_LOCKTIME_DISABLE_FLAG = 0
this.sequenceNumber = heightDiff ;
return this;
};
/**
* Returns a semantic version of the input's sequence nLockTime.
* @return {Number|Date}
* If sequence lock is disabled it returns null,
* if is set to block height lock, returns a block height (number)
* else it returns a Date object.
*/
Input.prototype.getLockTime = function() {
if (this.sequenceNumber & SEQUENCE_LOCKTIME_DISABLE_FLAG) {
return null;
}
if (this.sequenceNumber & SEQUENCE_LOCKTIME_TYPE_FLAG) {
var seconds = SEQUENCE_LOCKTIME_GRANULARITY * (this.sequenceNumber & SEQUENCE_LOCKTIME_MASK);
return seconds;
} else {
var blockHeight = this.sequenceNumber & SEQUENCE_LOCKTIME_MASK;
return blockHeight;
}
};
module.exports = Input;

2

lib/transaction/input/multisigscripthash.js

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

}
this.redeemScript = Script.buildMultisigOut(this.publicKeys, threshold);
this.redeemScript = Script.buildMultisigOut(this.publicKeys, threshold, opts);
$.checkState(Script.buildScriptHashOut(this.redeemScript).equals(this.output.script),

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

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

var CURRENT_VERSION = 1;
var CURRENT_VERSION = 2;
var DEFAULT_NLOCKTIME = 0;

@@ -1231,2 +1231,12 @@ var MAX_BLOCK_SIZE = 1000000;

Transaction.prototype.setVersion = function(version) {
$.checkArgument(
JSUtil.isNaturalNumber(version) && version <= CURRENT_VERSION,
'Wrong version number');
this.version = version;
return this;
};
module.exports = Transaction;
{
"name": "bitcore-lib-cash",
"version": "8.16.2",
"version": "8.17.0",
"description": "A pure and powerful JavaScript Bitcoin Cash library.",

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

"dependencies": {
"bitcore-lib": "^8.16.2",
"bitcore-lib": "^8.17.0",
"bn.js": "=4.11.8",

@@ -49,3 +49,3 @@ "bs58": "^4.0.1",

"base-x": "=3.0.4",
"bitcore-build": "^8.16.2",
"bitcore-build": "^8.17.0",
"brfs": "^2.0.1",

@@ -52,0 +52,0 @@ "chai": "^4.2.0",

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

var credtx = new Transaction();
credtx.setVersion(1);
credtx.uncheckedAddInput(new Transaction.Input({

@@ -258,2 +259,3 @@ prevTxId: '0000000000000000000000000000000000000000000000000000000000000000',

var spendtx = new Transaction();
spendtx.setVersion(1);
spendtx.uncheckedAddInput(new Transaction.Input({

@@ -328,2 +330,3 @@ prevTxId: idbuf.toString('hex'),

var tx = new Transaction(txhex);
tx.setVersion(1);
var allInputsVerified = true;

@@ -330,0 +333,0 @@ tx.inputs.forEach(function(txin, j) {

@@ -99,2 +99,38 @@ 'use strict';

});
describe('handling the BIP68 (sequenceNumber locktime)', function() {
var blockHeight = 3434;
it('handles a null locktime', function() {
var input = new Input(output);
expect(input.getLockTime()).to.equal(null);
});
it('handles a simple seconds example', function() {
var input = new Input()
.lockForSeconds(1e5);
var expected = (parseInt(1e5 / 512) * 512) ;
input.getLockTime().should.deep.equal(expected);
expected = (Math.floor(expected/512) ) | Input.SEQUENCE_LOCKTIME_TYPE_FLAG;
input.sequenceNumber.should.equal(expected | Input.SEQUENCE_LOCKTIME_TYPE_FLAG);
});
it('accepts a block height', function() {
var input = new Input()
.lockUntilBlockHeight(blockHeight);
input.sequenceNumber.should.equal(blockHeight);
input.getLockTime().should.deep.equal(blockHeight);
});
it('fails if the block height is too high', function() {
expect(function() {
return new Input().lockUntilBlockHeight(5e8);
}).to.throw(errors.Transaction.Input.BlockHeightOutOfRange);
});
it('fails if the block height is negative', function() {
expect(function() {
return new Input().lockUntilBlockHeight(-1);
}).to.throw(errors.Transaction.Input.BlockHeightOutOfRange);
});
});
});

@@ -114,2 +114,22 @@ 'use strict';

});
it('can build a redeem script from non-sorted public keys with a noSorting option', function() {
var nonSortedPublicKeys = [public1, public2, public3];
var threshold = 2;
var opts = { noSorting: true };
var nonSortedRedeemScript = Script.buildMultisigOut(nonSortedPublicKeys, threshold, opts);
var nonSortedAddress = Address.payingTo(nonSortedRedeemScript);
nonSortedAddress.toLegacyAddress().should.equal('HLEAcJ3iYF5sRGR4oSowZx5fuqigfD5Ah7');
var nonSortedOutput = Object.assign({}, output, {
address: nonSortedAddress.toLegacyAddress(),
script: new Script(nonSortedAddress)
});
var transaction = new Transaction()
.from(nonSortedOutput, nonSortedPublicKeys, threshold, opts)
.to(address, 1000000);
var input = transaction.inputs[0];
input.redeemScript.equals(nonSortedRedeemScript).should.equal(true);
});
});

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

var i = 0;
var transaction = new Transaction();
var transaction = (new Transaction()).setVersion(1);
while (i < vector.length) {

@@ -1221,3 +1221,3 @@ var command = vector[i];

var tx_empty_hex = '01000000000000000000';
var tx_empty_hex = '02000000000000000000';

@@ -1224,0 +1224,0 @@ /* jshint maxlen: 1000 */

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