diff --git a/lib/publickey.js b/lib/publickey.js index 1635869..1ab0ba0 100644 --- a/lib/publickey.js +++ b/lib/publickey.js @@ -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 }; }; diff --git a/test/publickey.js b/test/publickey.js index ffaed78..35d0093 100644 --- a/test/publickey.js +++ b/test/publickey.js @@ -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() {