fix PublicKey.toObject

This commit is contained in:
Manuel Araoz 2015-05-11 12:24:45 -03:00
parent 74b93e228c
commit 951a07c011
2 changed files with 8 additions and 2 deletions

View File

@ -343,8 +343,8 @@ PublicKey.isValid = function(data) {
*/
PublicKey.prototype.toObject = function toObject() {
return {
x: this.point.getX().toString('hex'),
y: this.point.getY().toString('hex'),
x: this.point.getX().toString('hex', 2),
y: this.point.getY().toString('hex', 2),
compressed: this.compressed
};
};

View File

@ -194,6 +194,12 @@ describe('PublicKey', function() {
}).to.throw();
});
it('works for X starting with 0x00', function() {
var a = new PublicKey('030589ee559348bd6a7325994f9c8eff12bd5d73cc683142bd0dd1a17abc99b0dc');
var b = new PublicKey('03'+a.toObject().x);
b.toString().should.equal(a.toString());
});
});
describe('#fromPrivateKey', function() {