Skip to content

Commit cdee8c9

Browse files
authored
Update dev dependencies (#220)
* update .gitignore * update .travis.yml config * update dev dependencies * adjust code for rules in new semistandard version * standardx with tweaks instead semistandard * style changes for latest standard * move bignum in benchmark to optionalDependencies * add lock file for benchmark
1 parent f953de2 commit cdee8c9

16 files changed

Lines changed: 2544 additions & 146 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
coverage/
22
node_modules/
3+
34
npm-debug.log
4-
1.js
5+
package-lock.json

.travis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
sudo: false
22
language: node_js
3+
cache:
4+
yarn: true
5+
directories:
6+
- node_modules
37
node_js:
4-
- "lts/*"
58
- "8"
69
- "10"
7-
- "node"
10+
- "12"
811
env:
912
matrix:
1013
- TEST_SUITE=unit

benchmarks/index.js

Lines changed: 72 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
/* eslint-disable new-cap, no-new */
1+
/* eslint-disable new-cap, no-new */
22

33
var benchmark = require('benchmark');
44
var crypto = require('crypto');
55
var bn = require('../');
6-
var bignum = require('bignum');
6+
var bignum;
7+
try {
8+
bignum = require('bignum');
9+
} catch (err) {
10+
console.log('Load bignum error: ' + err.message.split('\n')[0]);
11+
}
712
var sjcl = require('eccjs').sjcl.bn;
813
var bigi = require('bigi');
914
var BigInteger = require('js-big-integer').BigInteger;
@@ -31,6 +36,10 @@ function add (op, obj) {
3136
console.log('Benchmarking: ' + op);
3237

3338
Object.keys(obj).forEach(function (name) {
39+
if (name === 'bignum' && bignum === undefined) {
40+
return;
41+
}
42+
3443
if (!selfOnly || name === 'bn.js') {
3544
var testFn = obj[name];
3645
suite.add(name + '#' + op, function () {
@@ -99,10 +108,12 @@ while (fixtures.length < 25) {
99108
fixture.b1j = new bn(bj, 16);
100109

101110
// bignum
102-
fixture.a2 = new bignum(a, 16);
103-
fixture.b2 = new bignum(b, 16);
104-
fixture.a2j = new bignum(aj, 16);
105-
fixture.b2j = new bignum(bj, 16);
111+
if (bignum) {
112+
fixture.a2 = new bignum(a, 16);
113+
fixture.b2 = new bignum(b, 16);
114+
fixture.a2j = new bignum(aj, 16);
115+
fixture.b2j = new bignum(bj, 16);
116+
}
106117

107118
// bigi
108119
fixture.a4 = new bigi(a, 16);
@@ -131,13 +142,15 @@ while (fixtures.length < 25) {
131142

132143
//
133144
fixture.as1 = fixture.a1.mul(fixture.a1).iaddn(0x2adbeef);
134-
fixture.as2 = fixture.a2.mul(fixture.a2).add(0x2adbeef);
145+
if (bignum) {
146+
fixture.as2 = fixture.a2.mul(fixture.a2).add(0x2adbeef);
147+
}
135148
fixture.as4 = fixture.a4.multiply(fixture.a4).add(bigi.valueOf(0x2adbeef));
136149
// fixture.as5 = fixture.a5.mul(fixture.a5).add(0x2adbeef);
137150
fixture.as6 = fixture.a6.multiply(fixture.a6).add(
138-
new BigInteger('2adbeef', 16));
151+
new BigInteger('2adbeef', 16));
139152
fixture.as8 = fixture.a8.multiply(fixture.a8).add(
140-
SilentMattBigInteger.parse('2adbeef', 16));
153+
SilentMattBigInteger.parse('2adbeef', 16));
141154

142155
fixture.am1 = fixture.a1.toRed(bn.red('k256'));
143156
fixture.am5 = new sjcl.prime.p256k(fixture.a5);
@@ -152,13 +165,13 @@ add('create-10', {
152165
'bn.js': function (fixture) {
153166
new bn(fixture.a10base, 10);
154167
},
155-
'bignum': function (fixture) {
168+
bignum: function (fixture) {
156169
new bignum(fixture.a10base, 10);
157170
},
158-
'bigi': function (fixture) {
171+
bigi: function (fixture) {
159172
new bigi(fixture.a10base, 10);
160173
},
161-
'yaffle': function (fixture) {
174+
yaffle: function (fixture) {
162175
new BigInteger(fixture.a10base, 10);
163176
},
164177
'silentmatt-biginteger': function (fixture) {
@@ -170,16 +183,16 @@ add('create-hex', {
170183
'bn.js': function (fixture) {
171184
new bn(fixture.a16base, 16);
172185
},
173-
'bignum': function (fixture) {
186+
bignum: function (fixture) {
174187
new bignum(fixture.a16base, 16);
175188
},
176-
'bigi': function (fixture) {
189+
bigi: function (fixture) {
177190
new bigi(fixture.a16base, 16);
178191
},
179-
'sjcl': function (fixture) {
192+
sjcl: function (fixture) {
180193
new sjcl(fixture.a16base);
181194
},
182-
'yaffle': function (fixture) {
195+
yaffle: function (fixture) {
183196
new BigInteger(fixture.a16base, 16);
184197
},
185198
'silentmatt-biginteger': function (fixture) {
@@ -191,13 +204,13 @@ add('toString-10', {
191204
'bn.js': function (fixture) {
192205
fixture.a1.toString(10);
193206
},
194-
'bignum': function (fixture) {
207+
bignum: function (fixture) {
195208
fixture.a2.toString(10);
196209
},
197-
'bigi': function (fixture) {
210+
bigi: function (fixture) {
198211
fixture.a4.toString(10);
199212
},
200-
'yaffle': function (fixture) {
213+
yaffle: function (fixture) {
201214
fixture.a6.toString(10);
202215
},
203216
'silentmatt-biginteger': function (fixture) {
@@ -209,16 +222,16 @@ add('toString-hex', {
209222
'bn.js': function (fixture) {
210223
fixture.a1.toString(16);
211224
},
212-
'bignum': function (fixture) {
225+
bignum: function (fixture) {
213226
fixture.a2.toString(16);
214227
},
215-
'bigi': function (fixture) {
228+
bigi: function (fixture) {
216229
fixture.a4.toString(16);
217230
},
218-
'sjcl': function (fixture) {
231+
sjcl: function (fixture) {
219232
fixture.a5.toString(16);
220233
},
221-
'yaffle': function (fixture) {
234+
yaffle: function (fixture) {
222235
fixture.a6.toString(16);
223236
},
224237
'silentmatt-biginteger': function (fixture) {
@@ -230,16 +243,16 @@ add('add', {
230243
'bn.js': function (fixture) {
231244
fixture.a1.add(fixture.b1);
232245
},
233-
'bignum': function (fixture) {
246+
bignum: function (fixture) {
234247
fixture.a2.add(fixture.b2);
235248
},
236-
'bigi': function (fixture) {
249+
bigi: function (fixture) {
237250
fixture.a4.add(fixture.b4);
238251
},
239-
'sjcl': function (fixture) {
252+
sjcl: function (fixture) {
240253
fixture.a5.add(fixture.b5);
241254
},
242-
'yaffle': function (fixture) {
255+
yaffle: function (fixture) {
243256
fixture.a6.add(fixture.b6);
244257
},
245258
'silentmatt-biginteger': function (fixture) {
@@ -251,16 +264,16 @@ add('sub', {
251264
'bn.js': function (fixture) {
252265
fixture.b1.sub(fixture.a1);
253266
},
254-
'bignum': function (fixture) {
267+
bignum: function (fixture) {
255268
fixture.b2.sub(fixture.a2);
256269
},
257-
'bigi': function (fixture) {
270+
bigi: function (fixture) {
258271
fixture.b4.subtract(fixture.a4);
259272
},
260-
'sjcl': function (fixture) {
273+
sjcl: function (fixture) {
261274
fixture.b5.sub(fixture.a5);
262275
},
263-
'yaffle': function (fixture) {
276+
yaffle: function (fixture) {
264277
fixture.b6.subtract(fixture.a6);
265278
},
266279
'silentmatt-biginteger': function (fixture) {
@@ -275,16 +288,16 @@ add('mul', {
275288
'bn.js[FFT]': function (fixture) {
276289
fixture.a1.mulf(fixture.b1);
277290
},
278-
'bignum': function (fixture) {
291+
bignum: function (fixture) {
279292
fixture.a2.mul(fixture.b2);
280293
},
281-
'bigi': function (fixture) {
294+
bigi: function (fixture) {
282295
fixture.a4.multiply(fixture.b4);
283296
},
284-
'sjcl': function (fixture) {
297+
sjcl: function (fixture) {
285298
fixture.a5.mul(fixture.b5);
286299
},
287-
'yaffle': function (fixture) {
300+
yaffle: function (fixture) {
288301
fixture.a6.multiply(fixture.b6);
289302
},
290303
'silentmatt-biginteger': function (fixture) {
@@ -299,16 +312,16 @@ add('mul-jumbo', {
299312
'bn.js[FFT]': function (fixture) {
300313
fixture.a1j.mulf(fixture.b1j);
301314
},
302-
'bignum': function (fixture) {
315+
bignum: function (fixture) {
303316
fixture.a2j.mul(fixture.b2j);
304317
},
305-
'bigi': function (fixture) {
318+
bigi: function (fixture) {
306319
fixture.a4j.multiply(fixture.b4j);
307320
},
308-
'sjcl': function (fixture) {
321+
sjcl: function (fixture) {
309322
fixture.a5j.mul(fixture.b5j);
310323
},
311-
'yaffle': function (fixture) {
324+
yaffle: function (fixture) {
312325
fixture.a6j.multiply(fixture.b6j);
313326
},
314327
'silentmatt-biginteger': function (fixture) {
@@ -320,16 +333,16 @@ add('sqr', {
320333
'bn.js': function (fixture) {
321334
fixture.a1.mul(fixture.a1);
322335
},
323-
'bignum': function (fixture) {
336+
bignum: function (fixture) {
324337
fixture.a2.mul(fixture.a2);
325338
},
326-
'bigi': function (fixture) {
339+
bigi: function (fixture) {
327340
fixture.a4.square();
328341
},
329-
'sjcl': function (fixture) {
342+
sjcl: function (fixture) {
330343
fixture.a5.mul(fixture.a5);
331344
},
332-
'yaffle': function (fixture) {
345+
yaffle: function (fixture) {
333346
fixture.a6.multiply(fixture.a6);
334347
},
335348
'silentmatt-biginteger': function (fixture) {
@@ -341,13 +354,13 @@ add('div', {
341354
'bn.js': function (fixture) {
342355
fixture.as1.div(fixture.a1);
343356
},
344-
'bignum': function (fixture) {
357+
bignum: function (fixture) {
345358
fixture.as2.div(fixture.a2);
346359
},
347-
'bigi': function (fixture) {
360+
bigi: function (fixture) {
348361
fixture.as4.divide(fixture.a4);
349362
},
350-
'yaffle': function (fixture) {
363+
yaffle: function (fixture) {
351364
fixture.as6.divide(fixture.a6);
352365
},
353366
'silentmatt-biginteger': function (fixture) {
@@ -359,13 +372,13 @@ add('mod', {
359372
'bn.js': function (fixture) {
360373
fixture.as1.mod(fixture.a1);
361374
},
362-
'bignum': function (fixture) {
375+
bignum: function (fixture) {
363376
fixture.as2.mod(fixture.a2);
364377
},
365-
'bigi': function (fixture) {
378+
bigi: function (fixture) {
366379
fixture.as4.mod(fixture.a4);
367380
},
368-
'yaffle': function (fixture) {
381+
yaffle: function (fixture) {
369382
var remainder = fixture.as6.remainder(fixture.a6);
370383
return remainder.compareTo(BigInteger.ZERO) < 0
371384
? remainder.add(fixture.a6)
@@ -383,14 +396,17 @@ add('mul-mod k256', {
383396
'bn.js': function (fixture) {
384397
fixture.am1.redSqr();
385398
},
386-
'sjcl': function (fixture) {
399+
sjcl: function (fixture) {
387400
fixture.am5.square().fullReduce();
388401
}
389402
});
390403

391-
var prime1 = new bignum(
392-
'fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f',
393-
16);
404+
var prime1;
405+
if (bignum) {
406+
prime1 = new bignum(
407+
'fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f',
408+
16);
409+
}
394410
// var prime4 = new bigi(
395411
// 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f',
396412
// 16);
@@ -401,7 +417,7 @@ add('pow k256', {
401417
'bn.js': function (fixture) {
402418
fixture.am1.redPow(fixture.pow1);
403419
},
404-
'bignum': function (fixture) {
420+
bignum: function (fixture) {
405421
fixture.a2.powm(fixture.a2, prime1);
406422
}
407423
});
@@ -410,7 +426,7 @@ add('invm k256', {
410426
'bn.js': function (fixture) {
411427
fixture.am1.redInvm();
412428
},
413-
'sjcl': function (fixture) {
429+
sjcl: function (fixture) {
414430
fixture.am5.inverseMod(prime5);
415431
}
416432
});
@@ -419,7 +435,7 @@ add('gcd', {
419435
'bn.js': function (fixture) {
420436
fixture.a1.gcd(fixture.b1);
421437
},
422-
'bigi': function (fixture) {
438+
bigi: function (fixture) {
423439
fixture.a4.gcd(fixture.b4);
424440
}
425441
});

benchmarks/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
"benchmark": "^1.0.0",
1313
"bigi": "*",
1414
"biginteger": "*",
15-
"bignum": "^0.11.0",
1615
"eccjs": "^0.3.1",
17-
"js-big-integer": "*",
16+
"js-big-integer": "1.0.2",
1817
"xorshift.js": "^1.0.0"
18+
},
19+
"optionalDependencies": {
20+
"bignum": "^0.13.0"
1921
}
2022
}

0 commit comments

Comments
 (0)