diff --git a/lib/ScriptInterpreter.js b/lib/ScriptInterpreter.js index d5738b3f7..ac9912b34 100644 --- a/lib/ScriptInterpreter.js +++ b/lib/ScriptInterpreter.js @@ -8,11 +8,6 @@ var Util = require('../util'); var Script = require('./Script'); var Key = require('./Key'); -var SIGHASH_ALL = 1; -var SIGHASH_NONE = 2; -var SIGHASH_SINGLE = 3; -var SIGHASH_ANYONECANPAY = 80; - var intToBufferSM = Util.intToBufferSM var bufferSMToInt = Util.bufferSMToInt; @@ -22,6 +17,11 @@ function ScriptInterpreter(opts) { this.disableUnsafeOpcodes = true; }; +var SIGHASH_ALL = ScriptInterpreter.SIGHASH_ALL = 1; +var SIGHASH_NONE = ScriptInterpreter.SIGHASH_NONE = 2; +var SIGHASH_SINGLE = ScriptInterpreter.SIGHASH_SINGLE = 3; +var SIGHASH_ANYONECANPAY = ScriptInterpreter.SIGHASH_ANYONECANPAY = 0x80; + ScriptInterpreter.prototype.eval = function eval(script, tx, inIndex, hashType, callback) { if ("function" !== typeof callback) { throw new Error("ScriptInterpreter.eval() requires a callback"); diff --git a/lib/Transaction.js b/lib/Transaction.js index eeb1f8be1..067562473 100644 --- a/lib/Transaction.js +++ b/lib/Transaction.js @@ -299,15 +299,10 @@ Transaction.prototype.getAffectedKeys = function getAffectedKeys(txCache) { var OP_CODESEPARATOR = 171; -var SIGHASH_ALL = 1; -var SIGHASH_NONE = 2; -var SIGHASH_SINGLE = 3; -var SIGHASH_ANYONECANPAY = 0x80; - -Transaction.SIGHASH_ALL = SIGHASH_ALL; -Transaction.SIGHASH_NONE = SIGHASH_NONE; -Transaction.SIGHASH_SINGLE = SIGHASH_SINGLE; -Transaction.SIGHASH_ANYONECANPAY = SIGHASH_ANYONECANPAY; +var SIGHASH_ALL = Transaction.SIGHASH_ALL = ScriptInterpreter.SIGHASH_ALL; +var SIGHASH_NONE = Transaction.SIGHASH_NONE = ScriptInterpreter.SIGHASH_NONE; +var SIGHASH_SINGLE = Transaction.SIGHASH_SINGLE = ScriptInterpreter.SIGHASH_SINGLE; +var SIGHASH_ANYONECANPAY = Transaction.SIGHASH_ANYONECANPAY = ScriptInterpreter.SIGHASH_ANYONECANPAY; var TransactionSignatureSerializer = function(txTo, scriptCode, nIn, nHashType) { this.txTo = txTo; diff --git a/test/test.ScriptInterpreter.js b/test/test.ScriptInterpreter.js index 78864feb7..0cac123b5 100644 --- a/test/test.ScriptInterpreter.js +++ b/test/test.ScriptInterpreter.js @@ -18,6 +18,16 @@ describe('ScriptInterpreter', function() { var si = new ScriptInterpreter(); should.exist(si); }); + + describe('SIGHASH constants', function() { + it('should equal the values from bitcoin core', function() { + ScriptInterpreter.SIGHASH_ALL.should.equal(1); + ScriptInterpreter.SIGHASH_NONE.should.equal(2); + ScriptInterpreter.SIGHASH_SINGLE.should.equal(3); + ScriptInterpreter.SIGHASH_ANYONECANPAY.should.equal(0x80); + }); + }); + var testScripts = function(data, valid) { data.forEach(function(datum) { if (datum.length < 2) throw new Error('Invalid test data');