Browse Source

sign convenience function

patch-2
Ryan X. Charles 11 years ago
parent
commit
3b3ebb0458
  1. 5
      lib/ecdsa.js
  2. 10
      lib/message.js
  3. 12
      test/test.message.js

5
lib/ecdsa.js

@ -6,13 +6,14 @@ 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) { var ECDSA = function ECDSA(hashbuf, key, sig, k, verified) {
if (!(this instanceof ECDSA)) if (!(this instanceof ECDSA))
return new ECDSA(hashbuf, key, sig, k); return new ECDSA(hashbuf, key, sig, k, verified);
this.hashbuf = hashbuf; this.hashbuf = hashbuf;
this.key = key; this.key = key;
this.sig = sig; this.sig = sig;
this.k = k; this.k = k;
this.verified = verified;
}; };
ECDSA.prototype.calci = function() { ECDSA.prototype.calci = function() {

10
lib/message.js

@ -42,15 +42,13 @@ Message.prototype.sign = function() {
return this; return this;
}; };
/*
Message.sign = function(messagebuf, key) { Message.sign = function(messagebuf, key) {
var m = Message(messagebuf, key); var m = Message(messagebuf, key);
var sig = m.sign(); m.sign();
var sigbuf = sig.toCompressed(); var sigbuf = m.sig.toCompressed();
var base64 = sigbuf.toString('base64'); var sigstr = sigbuf.toString('base64');
return base64; return sigstr;
}; };
*/
Message.prototype.verify = function() { Message.prototype.verify = function() {
var hashbuf = Message.magicHash(this.messagebuf); var hashbuf = Message.magicHash(this.messagebuf);

12
test/test.message.js

@ -46,4 +46,16 @@ describe('Message', function() {
}); });
describe('@sign', function() {
var messagebuf = new Buffer('this is my message');
var key = Key().fromRandom();
it('should return a base64 string', function() {
var sigstr = Message.sign(messagebuf, key);
var sigbuf = new Buffer(sigstr, 'base64');
sigbuf.length.should.equal(1 + 32 + 32);
});
});
}); });

Loading…
Cancel
Save