@dashevo/dashcore-lib
Advanced tools
Comparing version 0.19.19 to 0.19.20
@@ -264,2 +264,3 @@ /* eslint-disable */ | ||
OP_CHECKLOCKTIMEVERIFY: 177, | ||
OP_CHECKSEQUENCEVERIFY: 178, | ||
@@ -266,0 +267,0 @@ // expansion |
@@ -238,2 +238,28 @@ /* eslint-disable */ | ||
// support CHECKSEQUENCEVERIFY opcode | ||
// | ||
// See BIP112 for details | ||
Interpreter.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY = (1 << 10); | ||
/* 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) { | ||
@@ -257,2 +283,3 @@ for (var i = 0; i < buf.length; i++) { | ||
var sig; | ||
if ((this.flags & (Interpreter.SCRIPT_VERIFY_DERSIG | Interpreter.SCRIPT_VERIFY_LOW_S | Interpreter.SCRIPT_VERIFY_STRICTENC)) !== 0 && !Signature.isTxDER(buf)) { | ||
@@ -373,2 +400,57 @@ this.errstr = 'SCRIPT_ERR_SIG_DER_INVALID_FORMAT'; | ||
/** | ||
* 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 & Interpreter.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 = txToSequence & nLockTimeMask; | ||
var nSequenceMasked = nSequence & 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. | ||
if (!((txToSequenceMasked < Interpreter.SEQUENCE_LOCKTIME_TYPE_FLAG | ||
&& nSequenceMasked < Interpreter.SEQUENCE_LOCKTIME_TYPE_FLAG) | ||
|| (txToSequenceMasked >= Interpreter.SEQUENCE_LOCKTIME_TYPE_FLAG | ||
&& nSequenceMasked >= Interpreter.SEQUENCE_LOCKTIME_TYPE_FLAG) | ||
)) { | ||
return false; | ||
} | ||
// Now that we know we're comparing apples-to-apples, the comparison is a | ||
// simple numeric one. | ||
if (nSequenceMasked > txToSequenceMasked) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
/** | ||
* Based on the inner loop of bitcoind's EvalScript function | ||
@@ -524,4 +606,49 @@ * bitcoind commit: b5d1b1092998bc95313856d535c632ea5a8f9104 | ||
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: | ||
@@ -528,0 +655,0 @@ case Opcode.OP_NOP5: |
{ | ||
"name": "@dashevo/dashcore-lib", | ||
"version": "0.19.19", | ||
"version": "0.19.20", | ||
"description": "A pure and powerful JavaScript Dash library.", | ||
@@ -117,3 +117,3 @@ "author": "Dash Core Group, Inc. <dev@dash.org>", | ||
"bloom-filter": "^0.2.0", | ||
"bls-signatures": "^0.2.4", | ||
"bls-signatures": "^0.2.5", | ||
"bn.js": "=4.11.8", | ||
@@ -120,0 +120,0 @@ "bs58": "=4.0.1", |
@@ -125,3 +125,3 @@ # Dashcore Library | ||
* [Transaction](docs/usage/transaction.md) | ||
* [Transaction Iput](docs/usage/transaction_input.md) | ||
* [Transaction Input](docs/usage/transaction_input.md) | ||
* [Transaction Output](docs/usage/transaction_output.md) | ||
@@ -128,0 +128,0 @@ * [URI](docs/usage/uri.md) |
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
2768781
22533
Updatedbls-signatures@^0.2.5