diff --git a/lib/ecdsa.js b/lib/ecdsa.js index 6c90e162d..c5fe9082c 100644 --- a/lib/ecdsa.js +++ b/lib/ecdsa.js @@ -6,14 +6,20 @@ var Privkey = require('./privkey'); var Pubkey = require('./pubkey'); var Random = require('./random'); -var ECDSA = function ECDSA(hashbuf, key, sig, k, verified) { +var ECDSA = function ECDSA(obj) { if (!(this instanceof ECDSA)) - return new ECDSA(hashbuf, key, sig, k, verified); - this.hashbuf = hashbuf; - this.key = key; - this.sig = sig; - this.k = k; - this.verified = verified; + return new ECDSA(obj); + if (obj) + this.set(obj); +}; + +ECDSA.prototype.set = function(obj) { + this.hashbuf = obj.hashbuf || this.hashbuf || undefined; + this.key = obj.key || this.key || undefined; + this.sig = obj.sig || this.sig || undefined; + this.k = obj.k || this.k || undefined; + this.verified = obj.verified || this.verified || undefined; + return this; }; ECDSA.prototype.calci = function() { diff --git a/lib/message.js b/lib/message.js index c345dfb3d..6e4bcb914 100644 --- a/lib/message.js +++ b/lib/message.js @@ -54,7 +54,7 @@ Message.verify = function(messagebuf, sigstr, address) { Message.prototype.sign = function() { var hashbuf = Message.magicHash(this.messagebuf); - var ecdsa = ECDSA(hashbuf, this.key); + var ecdsa = ECDSA({hashbuf: hashbuf, key: this.key}); ecdsa.signRandomK(); ecdsa.calci(); this.sig = ecdsa.sig; diff --git a/test/test.ecdsa.js b/test/test.ecdsa.js index 76886f4c5..f17a8a43f 100644 --- a/test/test.ecdsa.js +++ b/test/test.ecdsa.js @@ -21,6 +21,14 @@ describe("ECDSA", function() { ecdsa.key.pubkey = new Pubkey(point(BN().fromBuffer(new Buffer('ac242d242d23be966085a2b2b893d989f824e06c9ad0395a8a52f055ba39abb2', 'hex')), BN().fromBuffer(new Buffer('4836ab292c105a711ed10fcfd30999c31ff7c02456147747e03e739ad527c380', 'hex')))); + describe('#set', function() { + + it('should set hashbuf', function() { + should.exist(ECDSA().set({hashbuf: ecdsa.hashbuf}).hashbuf); + }); + + }); + describe('#calci', function() { it('should calculate i', function() {