put static methods at the top
This commit is contained in:
parent
ea0ee1b687
commit
b81e4c75fb
|
@ -34,6 +34,24 @@ Message.magicHash = function(messagebuf) {
|
|||
return hashbuf;
|
||||
};
|
||||
|
||||
Message.sign = function(messagebuf, key) {
|
||||
var m = Message(messagebuf, key);
|
||||
m.sign();
|
||||
var sigbuf = m.sig.toCompact();
|
||||
var sigstr = sigbuf.toString('base64');
|
||||
return sigstr;
|
||||
};
|
||||
|
||||
Message.verify = function(messagebuf, sigstr, address) {
|
||||
var sigbuf = new Buffer(sigstr, 'base64');
|
||||
var message = new Message();
|
||||
message.messagebuf = messagebuf;
|
||||
message.sig = Signature().fromCompact(sigbuf);
|
||||
message.address = address;
|
||||
|
||||
return message.verify().verified;
|
||||
};
|
||||
|
||||
Message.prototype.sign = function() {
|
||||
var hashbuf = Message.magicHash(this.messagebuf);
|
||||
var ecdsa = ECDSA(hashbuf, this.key);
|
||||
|
@ -43,14 +61,6 @@ Message.prototype.sign = function() {
|
|||
return this;
|
||||
};
|
||||
|
||||
Message.sign = function(messagebuf, key) {
|
||||
var m = Message(messagebuf, key);
|
||||
m.sign();
|
||||
var sigbuf = m.sig.toCompact();
|
||||
var sigstr = sigbuf.toString('base64');
|
||||
return sigstr;
|
||||
};
|
||||
|
||||
Message.prototype.verify = function() {
|
||||
var hashbuf = Message.magicHash(this.messagebuf);
|
||||
|
||||
|
@ -75,14 +85,4 @@ Message.prototype.verify = function() {
|
|||
return this;
|
||||
};
|
||||
|
||||
Message.verify = function(messagebuf, sigstr, address) {
|
||||
var sigbuf = new Buffer(sigstr, 'base64');
|
||||
var message = new Message();
|
||||
message.messagebuf = messagebuf;
|
||||
message.sig = Signature().fromCompact(sigbuf);
|
||||
message.address = address;
|
||||
|
||||
return message.verify().verified;
|
||||
};
|
||||
|
||||
module.exports = Message;
|
||||
|
|
|
@ -15,37 +15,6 @@ describe('Message', function() {
|
|||
should.exist(message);
|
||||
});
|
||||
|
||||
describe('#sign', function() {
|
||||
var messagebuf = new Buffer('this is my message');
|
||||
var key = Key().fromRandom();
|
||||
|
||||
it('should sign a message', function() {
|
||||
var message = new Message();
|
||||
message.messagebuf = messagebuf;
|
||||
message.key = key;
|
||||
message.sign();
|
||||
var sig = message.sig;
|
||||
should.exist(sig);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#verify', function() {
|
||||
var messagebuf = new Buffer('this is my message');
|
||||
var key = Key().fromRandom();
|
||||
|
||||
it('should verify a message that was just signed', function() {
|
||||
var message = new Message();
|
||||
message.messagebuf = messagebuf;
|
||||
message.key = key;
|
||||
message.address = Address().fromPubkey(key.pubkey);
|
||||
message.sign();
|
||||
message.verify();
|
||||
message.verified.should.equal(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('@sign', function() {
|
||||
var messagebuf = new Buffer('this is my message');
|
||||
var key = Key().fromRandom();
|
||||
|
@ -95,4 +64,35 @@ describe('Message', function() {
|
|||
|
||||
});
|
||||
|
||||
describe('#sign', function() {
|
||||
var messagebuf = new Buffer('this is my message');
|
||||
var key = Key().fromRandom();
|
||||
|
||||
it('should sign a message', function() {
|
||||
var message = new Message();
|
||||
message.messagebuf = messagebuf;
|
||||
message.key = key;
|
||||
message.sign();
|
||||
var sig = message.sig;
|
||||
should.exist(sig);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#verify', function() {
|
||||
var messagebuf = new Buffer('this is my message');
|
||||
var key = Key().fromRandom();
|
||||
|
||||
it('should verify a message that was just signed', function() {
|
||||
var message = new Message();
|
||||
message.messagebuf = messagebuf;
|
||||
message.key = key;
|
||||
message.address = Address().fromPubkey(key.pubkey);
|
||||
message.sign();
|
||||
message.verify();
|
||||
message.verified.should.equal(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue