diff --git a/src/transaction.js b/src/transaction.js index d80966b..0ed10c2 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -9,11 +9,11 @@ var ECKey = require('./eckey') var ECSignature = require('./ecsignature') var Script = require('./script') -var DEFAULT_SEQUENCE = 0xffffffff -var SIGHASH_ALL = 0x01 -var SIGHASH_NONE = 0x02 -var SIGHASH_SINGLE = 0x03 -var SIGHASH_ANYONECANPAY = 0x80 +Transaction.DEFAULT_SEQUENCE = 0xffffffff +Transaction.SIGHASH_ALL = 0x01 +Transaction.SIGHASH_NONE = 0x02 +Transaction.SIGHASH_SINGLE = 0x03 +Transaction.SIGHASH_ANYONECANPAY = 0x80 function Transaction() { this.version = 1 @@ -33,7 +33,7 @@ function Transaction() { * Note that this method does not sign the created input. */ Transaction.prototype.addInput = function(tx, index, sequence) { - if (sequence == undefined) sequence = DEFAULT_SEQUENCE + if (sequence == undefined) sequence = Transaction.DEFAULT_SEQUENCE var hash @@ -175,15 +175,15 @@ Transaction.prototype.hashForSignature = function(prevOutScript, inIndex, hashTy txTmp.ins[inIndex].script = hashScript var hashTypeModifier = hashType & 0x1f - if (hashTypeModifier === SIGHASH_NONE) { + if (hashTypeModifier === Transaction.SIGHASH_NONE) { assert(false, 'SIGHASH_NONE not yet supported') - } else if (hashTypeModifier === SIGHASH_SINGLE) { + } else if (hashTypeModifier === Transaction.SIGHASH_SINGLE) { assert(false, 'SIGHASH_SINGLE not yet supported') } - if (hashType & SIGHASH_ANYONECANPAY) { + if (hashType & Transaction.SIGHASH_ANYONECANPAY) { assert(false, 'SIGHASH_ANYONECANPAY not yet supported') } @@ -307,7 +307,7 @@ Transaction.prototype.sign = function(index, privKey, hashType) { } Transaction.prototype.signInput = function(index, prevOutScript, privKey, hashType) { - hashType = hashType || SIGHASH_ALL + hashType = hashType || Transaction.SIGHASH_ALL var hash = this.hashForSignature(prevOutScript, index, hashType) var signature = privKey.sign(hash) diff --git a/test/transaction.js b/test/transaction.js index 6ac97f3..0288ed7 100644 --- a/test/transaction.js +++ b/test/transaction.js @@ -93,7 +93,7 @@ describe('Transaction', function() { var tx = new Transaction() tx.addInput(prevTxHash, 0) - assert.equal(tx.ins[0].sequence, 0xffffffff) + assert.equal(tx.ins[0].sequence, Transaction.DEFAULT_SEQUENCE) }) fixtures.valid.forEach(function(f) {