diff --git a/lib/errors/spec.js b/lib/errors/spec.js index 6f45f95e4..a3e42bcf5 100644 --- a/lib/errors/spec.js +++ b/lib/errors/spec.js @@ -58,6 +58,9 @@ module.exports = [{ }, { name: 'NeedMoreInfo', message: format('{0}') + }, { + name: 'UnableToVerifySignature', + message: format('Unable to verify signature: {0}') }, { name: 'FeeError', message: format('Fees are not correctly set {0}'), diff --git a/lib/transaction/transaction.js b/lib/transaction/transaction.js index 588b68595..6b4ca35b0 100644 --- a/lib/transaction/transaction.js +++ b/lib/transaction/transaction.js @@ -657,6 +657,14 @@ Transaction.prototype.applySignature = function(signature) { }; Transaction.prototype.isFullySigned = function() { + _.each(this.inputs, function(input) { + if (input.isFullySigned === Input.prototype.isFullySigned) { + throw new errors.Transaction.UnableToVerifySignature( + 'Unrecognized script kind, or not enough information to execute script.' + + 'This usually happens when creating a transaction from a serialized transaction' + ); + } + }); return _.all(_.map(this.inputs, function(input) { return input.isFullySigned(); })); @@ -664,6 +672,12 @@ Transaction.prototype.isFullySigned = function() { Transaction.prototype.isValidSignature = function(signature) { var self = this; + if (this.inputs[signature.inputIndex].isValidSignature === Input.prototype.isValidSignature) { + throw new errors.Transaction.UnableToVerifySignature( + 'Unrecognized script kind, or not enough information to execute script.' + + 'This usually happens when creating a transaction from a serialized transaction' + ); + } return this.inputs[signature.inputIndex].isValidSignature(self, signature); }; diff --git a/test/transaction/transaction.js b/test/transaction/transaction.js index b9ae1e25b..742be1e26 100644 --- a/test/transaction/transaction.js +++ b/test/transaction/transaction.js @@ -197,6 +197,22 @@ describe('Transaction', function() { satoshis: 1e8 }; + describe('not enough information errors', function() { + it('fails when Inputs are not subclassed and isFullySigned is called', function() { + var tx = new Transaction(tx_1_hex); + expect(function() { + return tx.isFullySigned(); + }).to.throw(errors.Transaction.UnableToVerifySignature); + }); + + it('fails when Inputs are not subclassed and verifySignature is called', function() { + var tx = new Transaction(tx_1_hex); + expect(function() { + return tx.isValidSignature({inputIndex: 0}); + }).to.throw(errors.Transaction.UnableToVerifySignature); + }); + }); + describe('checked serialize', function() { it('fails if no change address was set', function() { var transaction = new Transaction()