lib: avoid circular dependency

This commit is contained in:
Thomas Wang
2019-06-25 21:02:31 -07:00
committed by Fedor Indutny
parent 523da1cf71
commit dbe8bc6c14
11 changed files with 29 additions and 36 deletions
+1 -2
View File
@@ -1,8 +1,7 @@
'use strict';
var BN = require('bn.js');
var elliptic = require('../../elliptic');
var utils = elliptic.utils;
var utils = require('../utils');
var getNAF = utils.getNAF;
var getJSF = utils.getJSF;
var assert = utils.assert;
+3 -4
View File
@@ -1,12 +1,11 @@
'use strict';
var curve = require('../curve');
var elliptic = require('../../elliptic');
var utils = require('../utils');
var BN = require('bn.js');
var inherits = require('inherits');
var Base = curve.base;
var Base = require('./base');
var assert = elliptic.utils.assert;
var assert = utils.assert;
function EdwardsCurve(conf) {
// NOTE: Important as we are creating point in Base.call()
+2 -4
View File
@@ -1,12 +1,10 @@
'use strict';
var curve = require('../curve');
var BN = require('bn.js');
var inherits = require('inherits');
var Base = curve.base;
var Base = require('./base');
var elliptic = require('../../elliptic');
var utils = elliptic.utils;
var utils = require('../utils');
function MontCurve(conf) {
Base.call(this, 'mont', conf);
+3 -4
View File
@@ -1,12 +1,11 @@
'use strict';
var curve = require('../curve');
var elliptic = require('../../elliptic');
var utils = require('../utils');
var BN = require('bn.js');
var inherits = require('inherits');
var Base = curve.base;
var Base = require('./base');
var assert = elliptic.utils.assert;
var assert = utils.assert;
function ShortCurve(conf) {
Base.call(this, 'short', conf);
+6 -5
View File
@@ -3,17 +3,18 @@
var curves = exports;
var hash = require('hash.js');
var elliptic = require('../elliptic');
var curve = require('./curve');
var utils = require('./utils');
var assert = elliptic.utils.assert;
var assert = utils.assert;
function PresetCurve(options) {
if (options.type === 'short')
this.curve = new elliptic.curve.short(options);
this.curve = new curve.short(options);
else if (options.type === 'edwards')
this.curve = new elliptic.curve.edwards(options);
this.curve = new curve.edwards(options);
else
this.curve = new elliptic.curve.mont(options);
this.curve = new curve.mont(options);
this.g = this.curve.g;
this.n = this.curve.n;
this.hash = options.hash;
+7 -6
View File
@@ -2,8 +2,9 @@
var BN = require('bn.js');
var HmacDRBG = require('hmac-drbg');
var elliptic = require('../../elliptic');
var utils = elliptic.utils;
var utils = require('../utils');
var curves = require('../curves');
var rand = require('brorand');
var assert = utils.assert;
var KeyPair = require('./key');
@@ -15,13 +16,13 @@ function EC(options) {
// Shortcut `elliptic.ec(curve-name)`
if (typeof options === 'string') {
assert(elliptic.curves.hasOwnProperty(options), 'Unknown curve ' + options);
assert(curves.hasOwnProperty(options), 'Unknown curve ' + options);
options = elliptic.curves[options];
options = curves[options];
}
// Shortcut for `elliptic.ec(elliptic.curves.curveName)`
if (options instanceof elliptic.curves.PresetCurve)
if (options instanceof curves.PresetCurve)
options = { curve: options };
this.curve = options.curve.curve;
@@ -59,7 +60,7 @@ EC.prototype.genKeyPair = function genKeyPair(options) {
hash: this.hash,
pers: options.pers,
persEnc: options.persEnc || 'utf8',
entropy: options.entropy || elliptic.rand(this.hash.hmacStrength),
entropy: options.entropy || rand(this.hash.hmacStrength),
entropyEnc: options.entropy && options.entropyEnc || 'utf8',
nonce: this.n.toArray()
});
+1 -2
View File
@@ -1,8 +1,7 @@
'use strict';
var BN = require('bn.js');
var elliptic = require('../../elliptic');
var utils = elliptic.utils;
var utils = require('../utils');
var assert = utils.assert;
function KeyPair(ec, options) {
+1 -2
View File
@@ -2,8 +2,7 @@
var BN = require('bn.js');
var elliptic = require('../../elliptic');
var utils = elliptic.utils;
var utils = require('../utils');
var assert = utils.assert;
function Signature(options, enc) {
+3 -3
View File
@@ -1,8 +1,8 @@
'use strict';
var hash = require('hash.js');
var elliptic = require('../../elliptic');
var utils = elliptic.utils;
var curves = require('../curves');
var utils = require('../utils');
var assert = utils.assert;
var parseBytes = utils.parseBytes;
var KeyPair = require('./key');
@@ -14,7 +14,7 @@ function EDDSA(curve) {
if (!(this instanceof EDDSA))
return new EDDSA(curve);
var curve = elliptic.curves[curve].curve;
var curve = curves[curve].curve;
this.curve = curve;
this.g = curve.g;
this.g.precompute(curve.n.bitLength() + 1);
+1 -2
View File
@@ -1,7 +1,6 @@
'use strict';
var elliptic = require('../../elliptic');
var utils = elliptic.utils;
var utils = require('../utils');
var assert = utils.assert;
var parseBytes = utils.parseBytes;
var cachedProperty = utils.cachedProperty;
+1 -2
View File
@@ -1,8 +1,7 @@
'use strict';
var BN = require('bn.js');
var elliptic = require('../../elliptic');
var utils = elliptic.utils;
var utils = require('../utils');
var assert = utils.assert;
var cachedProperty = utils.cachedProperty;
var parseBytes = utils.parseBytes;