|
|
@ -12,7 +12,7 @@ var Signature = function Signature(r, s, i) { |
|
|
|
}; |
|
|
|
|
|
|
|
Signature.prototype.fromCompressed = function(buf) { |
|
|
|
var i = buf.slice(0, 1)[0]; |
|
|
|
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); |
|
|
|
|
|
|
@ -26,17 +26,23 @@ Signature.prototype.fromCompressed = function(buf) { |
|
|
|
this.i = i; |
|
|
|
this.r = BN().fromBuffer(b2); |
|
|
|
this.s = BN().fromBuffer(b3); |
|
|
|
|
|
|
|
return this; |
|
|
|
}; |
|
|
|
|
|
|
|
Signature.prototype.fromDER = function(buf) { |
|
|
|
var obj = Signature.parseDER(buf); |
|
|
|
this.r = obj.r; |
|
|
|
this.s = obj.s; |
|
|
|
|
|
|
|
return this; |
|
|
|
}; |
|
|
|
|
|
|
|
Signature.prototype.fromString = function(str) { |
|
|
|
var buf = new Buffer(str, 'hex'); |
|
|
|
this.fromDER(buf); |
|
|
|
|
|
|
|
return this; |
|
|
|
}; |
|
|
|
|
|
|
|
Signature.parseDER = function(buf) { |
|
|
@ -101,7 +107,7 @@ Signature.prototype.toCompressed = function(i) { |
|
|
|
if (!(i === 0 || i === 1 || i === 2 || i === 3)) |
|
|
|
throw new Error('i must be equal to 0, 1, 2, or 3'); |
|
|
|
|
|
|
|
var b1 = new Buffer([i]); |
|
|
|
var b1 = new Buffer([i + 27 + 4]); //TODO: handle uncompressed pubkeys
|
|
|
|
var b2 = this.r.toBuffer({size: 32}); |
|
|
|
var b3 = this.s.toBuffer({size: 32}); |
|
|
|
return Buffer.concat([b1, b2, b3]); |
|
|
|