From 549a6c2116d6c201f8ef91d808ab9cad5e77804b Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 5 Feb 2015 11:53:13 -0300 Subject: [PATCH] remove extra Error --- lib/message.js | 12 ++++-------- test/message.js | 4 ++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/message.js b/lib/message.js index d020181..f9433c6 100644 --- a/lib/message.js +++ b/lib/message.js @@ -22,7 +22,7 @@ var Message = function Message(message) { if (!(this instanceof Message)) { return new Message(message); } - $.checkArgument(_.isString(message), new TypeError('First argument should be a string')); + $.checkArgument(_.isString(message), 'First argument should be a string'); this.message = message; return this; @@ -41,7 +41,7 @@ Message.prototype.magicHash = function magicHash() { Message.prototype._sign = function _sign(privateKey) { $.checkArgument(privateKey instanceof PrivateKey, - new TypeError('First argument should be an instance of PrivateKey')); + 'First argument should be an instance of PrivateKey'); var hash = this.magicHash(); var ecdsa = new ECDSA(); ecdsa.hashbuf = hash; @@ -64,12 +64,8 @@ Message.prototype.sign = function sign(privateKey) { }; Message.prototype._verify = function _verify(publicKey, signature) { - if (!(publicKey instanceof PublicKey)) { - throw new TypeError('First argument should be an instance of PublicKey'); - } - if (!(signature instanceof Signature)) { - throw new TypeError('Second argument should be an instance of Signature'); - } + $.checkArgument(publicKey instanceof PublicKey, 'First argument should be an instance of PublicKey'); + $.checkArgument(signature instanceof Signature, 'Second argument should be an instance of Signature'); var hash = this.magicHash(); var verified = ECDSA.verify(hash, signature, publicKey); if (!verified) { diff --git a/test/message.js b/test/message.js index 6a2f48c..7a51985 100644 --- a/test/message.js +++ b/test/message.js @@ -69,14 +69,14 @@ describe('Message', function() { expect(function() { var message6 = new Message(text); return message6._verify('not a public key', signature); - }).to.throw(TypeError); + }).to.throw('First argument should be an instance of PublicKey'); }); it('verify will error with incorrect signature argument', function() { expect(function() { var message7 = new Message(text); return message7._verify(publicKey, 'not a signature'); - }).to.throw(TypeError); + }).to.throw('Second argument should be an instance of Signature'); }); it('verify will correctly identify a bad signature', function() {