From 951a07c011e100b1c3ffd26f7c44cbef5f62674e Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Mon, 11 May 2015 12:24:45 -0300 Subject: [PATCH] fix PublicKey.toObject --- lib/publickey.js | 4 ++-- test/publickey.js | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) 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() {