-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
var assert = require('assert'); | ||
var elliptic = require('../lib/elliptic'); | ||
var curves = elliptic.curves; | ||
var compare = assert.deepStrictEqual || assert.deepEqual; | ||
|
||
function exportPoint (p) { | ||
return JSON.parse(JSON.stringify(p.toJSON())); | ||
} | ||
|
||
describe('toJSON <-> pointFromJSON symmetry', function() { | ||
it('toJSON matches pointFromJSON', function () { | ||
for (var key in curves) { | ||
if (key === 'PresetCurve') continue; | ||
|
||
var curve = curves[key]; | ||
if (!curve.g.toJSON) continue; | ||
|
||
var exported = exportPoint(curve.g); | ||
var reimported = curve.curve.pointFromJSON(exported); | ||
var reexported = exportPoint(reimported); | ||
compare(exported, reexported, 'toJSON is the inverse of pointFromJSON'); | ||
} | ||
}); | ||
}); |