From f1414b0d2f7edcd9b801bde13b13afdfa3508d1a Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Tue, 25 Mar 2014 02:44:43 +1100 Subject: [PATCH] Adds verify to ECPubKey --- src/eckey.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/eckey.js b/src/eckey.js index dc4cc17..1acb475 100644 --- a/src/eckey.js +++ b/src/eckey.js @@ -11,8 +11,8 @@ var Network = require('./network') var ecparams = sec("secp256k1"); // input can be nothing, array of bytes, hex string, or base58 string -var ECKey = function (input,compressed) { - if (!(this instanceof ECKey)) { return new ECKey(input,compressed); } +var ECKey = function (input, compressed) { + if (!(this instanceof ECKey)) { return new ECKey(input, compressed); } if (!input) { // Generate new key var n = ecparams.getN(); @@ -110,8 +110,16 @@ ECKey.prototype.multiply = function(key) { return ECKey(this.priv.multiply(ECKey(key).priv),this.compressed) } -var ECPubKey = function(input,compressed) { - if (!(this instanceof ECPubKey)) { return new ECPubKey(input,compressed); } +ECKey.prototype.sign = function(hash) { + return ecdsa.sign(hash, this.priv); +} + +ECKey.prototype.verify = function(hash, sig) { + return this.getPub().verify(hash, sig) +} + +var ECPubKey = function(input, compressed) { + if (!(this instanceof ECPubKey)) { return new ECPubKey(input, compressed); } if (!input) { // Generate new key var n = ecparams.getN(); @@ -178,18 +186,11 @@ ECPubKey.prototype.getAddress = function(version) { return new Address(util.sha256ripe160(this.toBytes()), version); } -ECKey.prototype.sign = function (hash) { - return ecdsa.sign(hash, this.priv); -}; - -ECKey.prototype.verify = function (hash, sig) { - return ecdsa.verify(hash, sig, this.getPub()['export']('bytes')); -}; +ECPubKey.prototype.verify = function(hash, sig) { + return ecdsa.verify(hash, sig, this.toBytes()) +} -/** - * Parse an exported private key contained in a string. - */ module.exports = { ECKey: ECKey, ECPubKey: ECPubKey -}; +}