bitcore-lib-cash
Advanced tools
Comparing version 8.25.40 to 8.25.46
@@ -190,2 +190,32 @@ 'use strict'; | ||
BN.prototype.getSize = function() { | ||
const bin = this.toString(2).replace('-', ''); | ||
const numBits = bin.length + 1; | ||
return numBits / 8; | ||
}; | ||
BN.prototype.checkOperationForOverflow = function (operand, result, maxSize) { | ||
if (this.getSize() > maxSize || operand.getSize() > maxSize || result.getSize() > 8) { | ||
throw new Error('overflow'); | ||
} | ||
}; | ||
BN.prototype.safeAdd = function(bigNumToAdd, maxSize) { | ||
const sum = this.add(bigNumToAdd); | ||
this.checkOperationForOverflow(bigNumToAdd, sum, maxSize); | ||
return sum; | ||
}; | ||
BN.prototype.safeSub = function(bigNumToSubtract, maxSize) { | ||
const difference = this.sub(bigNumToSubtract); | ||
this.checkOperationForOverflow(bigNumToSubtract, difference, maxSize); | ||
return difference; | ||
}; | ||
BN.prototype.safeMul = function(bigNumToMultiply, maxSize) { | ||
const product = this.mul(bigNumToMultiply); | ||
this.checkOperationForOverflow(bigNumToMultiply, product, maxSize); | ||
return product; | ||
}; | ||
module.exports = BN; |
@@ -228,3 +228,22 @@ 'use strict'; | ||
OP_PUBKEY: 254, | ||
OP_INVALIDOPCODE: 255 | ||
OP_INVALIDOPCODE: 255, | ||
// introspection | ||
OP_INPUTINDEX: 192, | ||
OP_ACTIVEBYTECODE: 193, | ||
OP_TXVERSION: 194, | ||
OP_TXINPUTCOUNT: 195, | ||
OP_TXOUTPUTCOUNT: 196, | ||
OP_TXLOCKTIME: 197, | ||
OP_UTXOVALUE: 198, | ||
OP_UTXOBYTECODE: 199, | ||
OP_OUTPOINTTXHASH: 200, | ||
OP_OUTPOINTINDEX: 201, | ||
OP_INPUTBYTECODE: 202, | ||
OP_INPUTSEQUENCENUMBER: 203, | ||
OP_OUTPUTVALUE: 204, | ||
OP_OUTPUTBYTECODE: 205, | ||
OP_RESERVED3: 206, | ||
OP_RESERVED4: 207 | ||
}; | ||
@@ -231,0 +250,0 @@ |
@@ -397,2 +397,29 @@ var Address = require('../address'); | ||
/** | ||
* @param {Object=} values - The return values | ||
* @param {Number} values.version - Set with the witness version | ||
* @param {Buffer} values.program - Set with the witness program | ||
* @returns {boolean} if this is a p2wpkh output script | ||
*/ | ||
Script.prototype.isWitnessProgram = function(values) { | ||
if (!values) { | ||
values = {}; | ||
} | ||
var buf = this.toBuffer(); | ||
if (buf.length < 4 || buf.length > 42) { | ||
return false; | ||
} | ||
if (buf[0] !== Opcode.OP_0 && !(buf[0] >= Opcode.OP_1 && buf[0] <= Opcode.OP_16)) { | ||
return false; | ||
} | ||
if (buf.length === buf[1] + 2) { | ||
values.version = buf[0]; | ||
values.program = buf.slice(2, buf.length); | ||
return true; | ||
} | ||
return false; | ||
}; | ||
/** | ||
* @returns {boolean} if this is a p2sh output script | ||
@@ -399,0 +426,0 @@ */ |
{ | ||
"name": "bitcore-lib-cash", | ||
"version": "8.25.40", | ||
"version": "8.25.46", | ||
"description": "A pure and powerful JavaScript Bitcoin Cash library.", | ||
@@ -38,3 +38,3 @@ "author": "BitPay <dev@bitpay.com>", | ||
"dependencies": { | ||
"bitcore-lib": "^8.25.40", | ||
"bitcore-lib": "^8.25.46", | ||
"bn.js": "=4.11.8", | ||
@@ -49,3 +49,3 @@ "bs58": "^4.0.1", | ||
"base-x": "=3.0.4", | ||
"bitcore-build": "^8.25.40", | ||
"bitcore-build": "^8.25.46", | ||
"brfs": "^2.0.1", | ||
@@ -57,3 +57,3 @@ "chai": "^4.2.0", | ||
"license": "MIT", | ||
"gitHead": "8e85cb3233fade87e809ac4ef6852b9917f51d4a" | ||
"gitHead": "17c02f181ba8f96b408951bb511549b0b41b4607" | ||
} |
@@ -96,4 +96,4 @@ 'use strict'; | ||
describe('@map', function() { | ||
it('should have a map containing 125 elements', function() { | ||
_.size(Opcode.map).should.equal(125); | ||
it('should have a map containing 141 elements', function() { | ||
_.size(Opcode.map).should.equal(141); | ||
}); | ||
@@ -100,0 +100,0 @@ }); |
@@ -7,5 +7,7 @@ 'use strict'; | ||
var Transaction = bitcore.Transaction; | ||
var Output = bitcore.Transaction.Output; | ||
var PrivateKey = bitcore.PrivateKey; | ||
var Script = bitcore.Script; | ||
var BN = bitcore.crypto.BN; | ||
var BufferReader = bitcore.encoding.BufferReader; | ||
var BufferWriter = bitcore.encoding.BufferWriter; | ||
@@ -18,2 +20,3 @@ var Opcode = bitcore.Opcode; | ||
var tx_invalid = require('../data/bitcoind/tx_invalid'); | ||
var vmb_tests = require('../data/libauth/vmb_tests'); | ||
@@ -29,3 +32,5 @@ //the script string format used in bitcoind data tests | ||
} | ||
if (token === '-1') { | ||
token = '1NEGATE'; | ||
} | ||
var opstr; | ||
@@ -225,2 +230,15 @@ var opcodenum; | ||
} | ||
if (flagstr.indexOf('64_BIT_INTEGERS') !== -1) { | ||
flags = flags | Interpreter.SCRIPT_64_BIT_INTEGERS; | ||
} | ||
if (flagstr.indexOf('INPUT_SIGCHECKS') !== -1) { | ||
flags = flags | Interpreter.SCRIPT_VERIFY_INPUT_SIGCHECKS; | ||
} | ||
if (flagstr.indexOf('NATIVE_INTROSPECTION') !== -1) { | ||
flags = flags | Interpreter.SCRIPT_NATIVE_INTROSPECTION; | ||
} | ||
return flags; | ||
@@ -257,3 +275,3 @@ }; | ||
script: scriptPubkey, | ||
satoshis: inputAmount, | ||
satoshis: inputAmount, | ||
})); | ||
@@ -307,2 +325,28 @@ var idbuf = credtx.id; | ||
}); | ||
describe('libauth vmb evaluation fixtures', () => { | ||
const flags = getFlags('P2SH CLEANSTACK MINIMALDATA VERIFY_CHECKLOCKTIMEVERIFY NATIVE_INTROSPECTION 64_BIT_INTEGERS'); | ||
const getOutputsFromHex = outputsHex => { | ||
const reader = new BufferReader(Buffer.from(outputsHex,'hex')); | ||
const numOutputs = reader.readVarintNum(); | ||
const outputs = new Array(numOutputs).fill(1).map(() => Output.fromBufferReader(reader)); | ||
return outputs; | ||
}; | ||
vmb_tests.forEach(test => { | ||
const testId = test[0]; | ||
const txHex = test[4]; | ||
const sourceOutputsHex = test[5]; | ||
const labels = test[6]; | ||
const inputIndex = test[7] || 0; | ||
const tx = new Transaction(txHex); | ||
const outputs = getOutputsFromHex(sourceOutputsHex); | ||
tx.inputs.forEach((input, index) => input.output = outputs[index]); | ||
const scriptSig = tx.inputs[inputIndex].script; | ||
const scriptPubkey = tx.inputs[inputIndex].output.script; | ||
it(`should pass vmb_tests vector ${testId}`, () => { | ||
const valid = Interpreter().verify(scriptSig, scriptPubkey, tx, inputIndex, flags); | ||
const expectedValidity = !labels[0].endsWith('invalid'); | ||
valid.should.equal(expectedValidity); | ||
}); | ||
}); | ||
}); | ||
describe('bitcoind transaction evaluation fixtures', function() { | ||
@@ -309,0 +353,0 @@ var test_txs = function(set, expected) { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3104637
150
36361
Updatedbitcore-lib@^8.25.46