it is a "Compact" signature, not "Compressed"

This commit is contained in:
Ryan X. Charles 2014-08-22 16:34:45 -07:00
parent b342396731
commit 8e6a28162b
3 changed files with 6 additions and 6 deletions

View File

@ -46,7 +46,7 @@ Message.prototype.sign = function() {
Message.sign = function(messagebuf, key) {
var m = Message(messagebuf, key);
m.sign();
var sigbuf = m.sig.toCompressed();
var sigbuf = m.sig.toCompact();
var sigstr = sigbuf.toString('base64');
return sigstr;
};
@ -79,7 +79,7 @@ Message.verify = function(messagebuf, sigstr, address) {
var sigbuf = new Buffer(sigstr, 'base64');
var message = new Message();
message.messagebuf = messagebuf;
message.sig = Signature().fromCompressed(sigbuf);
message.sig = Signature().fromCompact(sigbuf);
message.address = address;
return message.verify().verified;

View File

@ -11,7 +11,7 @@ var Signature = function Signature(r, s, i) {
this.i = i; //public key recovery parameter in range [0, 3]
};
Signature.prototype.fromCompressed = function(buf) {
Signature.prototype.fromCompact = function(buf) {
var i = buf.slice(0, 1)[0] - 27 - 4; //TODO: handle uncompressed pubkeys
var b2 = buf.slice(1, 33);
var b3 = buf.slice(33, 65);
@ -102,7 +102,7 @@ Signature.parseDER = function(buf) {
return obj;
};
Signature.prototype.toCompressed = function(i) {
Signature.prototype.toCompact = function(i) {
i = typeof i === 'number' ? i : this.i;
if (!(i === 0 || i === 1 || i === 2 || i === 3))
throw new Error('i must be equal to 0, 1, 2, or 3');

View File

@ -9,7 +9,7 @@ describe('Signature', function() {
should.exist(sig);
});
describe('#fromCompressed', function() {
describe('#fromCompact', function() {
it('should create a signature from a compressed signature', function() {
var blank = new Buffer(32);
@ -20,7 +20,7 @@ describe('Signature', function() {
blank
]);
var sig = new Signature();
sig.fromCompressed(compressed);
sig.fromCompact(compressed);
sig.r.cmp(0).should.equal(0);
sig.s.cmp(0).should.equal(0);
});