From be6ecc7b0596ea83fabf5442b0420c4ea6b9ef87 Mon Sep 17 00:00:00 2001 From: Mark Vayngrib Date: Tue, 13 Aug 2019 12:21:35 -0400 Subject: [PATCH] fix Point.prototype.toJSON for short curves --- lib/elliptic/curve/short.js | 4 ++-- test/toJSON-test.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/elliptic/curve/short.js b/lib/elliptic/curve/short.js index b631e7c..32b77e6 100644 --- a/lib/elliptic/curve/short.js +++ b/lib/elliptic/curve/short.js @@ -311,9 +311,9 @@ Point.prototype._getBeta = function _getBeta() { Point.prototype.toJSON = function toJSON() { if (!this.precomputed) - return [ this.x, this.y ]; + return [ this.x.fromRed(), this.y.fromRed() ]; - return [ this.x, this.y, this.precomputed && { + return [ this.x.fromRed(), this.y.fromRed(), this.precomputed && { doubles: this.precomputed.doubles && { step: this.precomputed.doubles.step, points: this.precomputed.doubles.points.slice(1) diff --git a/test/toJSON-test.js b/test/toJSON-test.js index 2a4046e..4527b7d 100644 --- a/test/toJSON-test.js +++ b/test/toJSON-test.js @@ -12,7 +12,7 @@ function exportPoint (p) { } describe('toJSON <-> pointFromJSON symmetry', function() { - it('toJSON matches pointFromJSON', function () { + it('toJSON is the inverse of pointFromJSON', function () { for (var key in curves) { if (key === 'PresetCurve') continue;