ECDSA.prototype.set
This commit is contained in:
parent
0d9b54711e
commit
75c1503a92
20
lib/ecdsa.js
20
lib/ecdsa.js
|
@ -6,14 +6,20 @@ var Privkey = require('./privkey');
|
||||||
var Pubkey = require('./pubkey');
|
var Pubkey = require('./pubkey');
|
||||||
var Random = require('./random');
|
var Random = require('./random');
|
||||||
|
|
||||||
var ECDSA = function ECDSA(hashbuf, key, sig, k, verified) {
|
var ECDSA = function ECDSA(obj) {
|
||||||
if (!(this instanceof ECDSA))
|
if (!(this instanceof ECDSA))
|
||||||
return new ECDSA(hashbuf, key, sig, k, verified);
|
return new ECDSA(obj);
|
||||||
this.hashbuf = hashbuf;
|
if (obj)
|
||||||
this.key = key;
|
this.set(obj);
|
||||||
this.sig = sig;
|
};
|
||||||
this.k = k;
|
|
||||||
this.verified = verified;
|
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() {
|
ECDSA.prototype.calci = function() {
|
||||||
|
|
|
@ -54,7 +54,7 @@ Message.verify = function(messagebuf, sigstr, address) {
|
||||||
|
|
||||||
Message.prototype.sign = function() {
|
Message.prototype.sign = function() {
|
||||||
var hashbuf = Message.magicHash(this.messagebuf);
|
var hashbuf = Message.magicHash(this.messagebuf);
|
||||||
var ecdsa = ECDSA(hashbuf, this.key);
|
var ecdsa = ECDSA({hashbuf: hashbuf, key: this.key});
|
||||||
ecdsa.signRandomK();
|
ecdsa.signRandomK();
|
||||||
ecdsa.calci();
|
ecdsa.calci();
|
||||||
this.sig = ecdsa.sig;
|
this.sig = ecdsa.sig;
|
||||||
|
|
|
@ -21,6 +21,14 @@ describe("ECDSA", function() {
|
||||||
ecdsa.key.pubkey = new Pubkey(point(BN().fromBuffer(new Buffer('ac242d242d23be966085a2b2b893d989f824e06c9ad0395a8a52f055ba39abb2', 'hex')),
|
ecdsa.key.pubkey = new Pubkey(point(BN().fromBuffer(new Buffer('ac242d242d23be966085a2b2b893d989f824e06c9ad0395a8a52f055ba39abb2', 'hex')),
|
||||||
BN().fromBuffer(new Buffer('4836ab292c105a711ed10fcfd30999c31ff7c02456147747e03e739ad527c380', '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() {
|
describe('#calci', function() {
|
||||||
|
|
||||||
it('should calculate i', function() {
|
it('should calculate i', function() {
|
||||||
|
|
Loading…
Reference in New Issue