it is a "Compact" signature, not "Compressed"
This commit is contained in:
parent
b342396731
commit
8e6a28162b
|
@ -46,7 +46,7 @@ Message.prototype.sign = function() {
|
||||||
Message.sign = function(messagebuf, key) {
|
Message.sign = function(messagebuf, key) {
|
||||||
var m = Message(messagebuf, key);
|
var m = Message(messagebuf, key);
|
||||||
m.sign();
|
m.sign();
|
||||||
var sigbuf = m.sig.toCompressed();
|
var sigbuf = m.sig.toCompact();
|
||||||
var sigstr = sigbuf.toString('base64');
|
var sigstr = sigbuf.toString('base64');
|
||||||
return sigstr;
|
return sigstr;
|
||||||
};
|
};
|
||||||
|
@ -79,7 +79,7 @@ Message.verify = function(messagebuf, sigstr, address) {
|
||||||
var sigbuf = new Buffer(sigstr, 'base64');
|
var sigbuf = new Buffer(sigstr, 'base64');
|
||||||
var message = new Message();
|
var message = new Message();
|
||||||
message.messagebuf = messagebuf;
|
message.messagebuf = messagebuf;
|
||||||
message.sig = Signature().fromCompressed(sigbuf);
|
message.sig = Signature().fromCompact(sigbuf);
|
||||||
message.address = address;
|
message.address = address;
|
||||||
|
|
||||||
return message.verify().verified;
|
return message.verify().verified;
|
||||||
|
|
|
@ -11,7 +11,7 @@ var Signature = function Signature(r, s, i) {
|
||||||
this.i = i; //public key recovery parameter in range [0, 3]
|
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 i = buf.slice(0, 1)[0] - 27 - 4; //TODO: handle uncompressed pubkeys
|
||||||
var b2 = buf.slice(1, 33);
|
var b2 = buf.slice(1, 33);
|
||||||
var b3 = buf.slice(33, 65);
|
var b3 = buf.slice(33, 65);
|
||||||
|
@ -102,7 +102,7 @@ Signature.parseDER = function(buf) {
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
Signature.prototype.toCompressed = function(i) {
|
Signature.prototype.toCompact = function(i) {
|
||||||
i = typeof i === 'number' ? i : this.i;
|
i = typeof i === 'number' ? i : this.i;
|
||||||
if (!(i === 0 || i === 1 || i === 2 || i === 3))
|
if (!(i === 0 || i === 1 || i === 2 || i === 3))
|
||||||
throw new Error('i must be equal to 0, 1, 2, or 3');
|
throw new Error('i must be equal to 0, 1, 2, or 3');
|
||||||
|
|
|
@ -9,7 +9,7 @@ describe('Signature', function() {
|
||||||
should.exist(sig);
|
should.exist(sig);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#fromCompressed', function() {
|
describe('#fromCompact', function() {
|
||||||
|
|
||||||
it('should create a signature from a compressed signature', function() {
|
it('should create a signature from a compressed signature', function() {
|
||||||
var blank = new Buffer(32);
|
var blank = new Buffer(32);
|
||||||
|
@ -20,7 +20,7 @@ describe('Signature', function() {
|
||||||
blank
|
blank
|
||||||
]);
|
]);
|
||||||
var sig = new Signature();
|
var sig = new Signature();
|
||||||
sig.fromCompressed(compressed);
|
sig.fromCompact(compressed);
|
||||||
sig.r.cmp(0).should.equal(0);
|
sig.r.cmp(0).should.equal(0);
|
||||||
sig.s.cmp(0).should.equal(0);
|
sig.s.cmp(0).should.equal(0);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue