From 7231a9ce93c4e6e56876c0612bd6f6c1fbbf83bb Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Mon, 17 Dec 2018 23:20:10 +0000 Subject: [PATCH 1/4] fix: reduce bundle size --- .gitignore | 1 + appveyor.yml | 29 ----------------------------- package.json | 16 +++++++++------- src/cms.js | 20 +++++++++++++------- src/keychain.js | 18 ++++++++---------- src/util.js | 3 ++- test/browser.js | 6 +++--- test/node.js | 6 +++--- 8 files changed, 39 insertions(+), 60 deletions(-) delete mode 100644 appveyor.yml diff --git a/.gitignore b/.gitignore index 1c73b37..b64f085 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ test/test-data/go-ipfs-repo/LOG.old # while testing npm5 package-lock.json +yarn.lock \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 046bf91..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,29 +0,0 @@ -# Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories. -version: "{build}" - -environment: - matrix: - - nodejs_version: "6" - - nodejs_version: "8" - -matrix: - fast_finish: true - -install: - # Install Node.js - - ps: Install-Product node $env:nodejs_version - - # Upgrade npm - - npm install -g npm - - # Output our current versions for debugging - - node --version - - npm --version - - # Install our package dependencies - - npm install - -test_script: - - npm run test:node - -build: off diff --git a/package.json b/package.json index 9cd9fed..e51311d 100644 --- a/package.json +++ b/package.json @@ -44,22 +44,24 @@ "dependencies": { "async": "^2.6.1", "interface-datastore": "~0.6.0", - "libp2p-crypto": "~0.15.0", - "lodash": "^4.17.11", - "pull-stream": "^3.6.9", + "libp2p-crypto": "libp2p/js-libp2p-crypto#feat/bundle-size", + "merge-options": "^1.0.1", + "node-forge": "^0.7.6", + "pull-stream": "^3.6.8", "sanitize-filename": "^1.6.1" }, "devDependencies": { - "aegir": "^18.0.2", + "aegir": "github:ipfs/aegir#feat/make-exp-build-test-default", "chai": "^4.2.0", - "chai-string": "^1.5.0", + "chai-string": "^1.4.0", "datastore-fs": "~0.7.0", "datastore-level": "~0.10.0", "dirty-chai": "^2.0.1", "level-js": "^4.0.0", "mocha": "^5.2.0", - "peer-id": "~0.12.1", - "rimraf": "^2.6.3" + "multihashes": "^0.4.14", + "peer-id": "~0.10.7", + "rimraf": "^2.6.2" }, "contributors": [ "Alan Shaw ", diff --git a/src/cms.js b/src/cms.js index 937063c..e3dac6f 100644 --- a/src/cms.js +++ b/src/cms.js @@ -1,7 +1,13 @@ 'use strict' -const async = require('async') -const forge = require('node-forge') +const setImmediate = require('async/setImmediate') +const series = require('async/series') +const detect = require('async/detect') +const waterfall = require('async/waterfall') +// const forge = require('node-forge') +require('node-forge/lib/pkcs7') +require('node-forge/lib/pbe') +const forge = require('node-forge/lib/forge') const util = require('./util') /** @@ -39,13 +45,13 @@ class CMS { */ encrypt (name, plain, callback) { const self = this - const done = (err, result) => async.setImmediate(() => callback(err, result)) + const done = (err, result) => setImmediate(() => callback(err, result)) if (!Buffer.isBuffer(plain)) { return done(new Error('Plain data must be a Buffer')) } - async.series([ + series([ (cb) => self.keychain.findKeyByName(name, cb), (cb) => self.keychain._getPrivateKey(name, cb) ], (err, results) => { @@ -85,7 +91,7 @@ class CMS { * @returns {undefined} */ decrypt (cmsData, callback) { - const done = (err, result) => async.setImmediate(() => callback(err, result)) + const done = (err, result) => setImmediate(() => callback(err, result)) if (!Buffer.isBuffer(cmsData)) { return done(new Error('CMS data is required')) @@ -112,7 +118,7 @@ class CMS { keyId: r.issuer.find(a => a.shortName === 'CN').value } }) - async.detect( + detect( recipients, (r, cb) => self.keychain.findKeyById(r.keyId, (err, info) => cb(null, !err && info)), (err, r) => { @@ -124,7 +130,7 @@ class CMS { return done(err) } - async.waterfall([ + waterfall([ (cb) => self.keychain.findKeyById(r.keyId, cb), (key, cb) => self.keychain._getPrivateKey(key.name, cb) ], (err, pem) => { diff --git a/src/keychain.js b/src/keychain.js index a9619fd..cecc320 100644 --- a/src/keychain.js +++ b/src/keychain.js @@ -2,12 +2,11 @@ 'use strict' const sanitize = require('sanitize-filename') -const deepmerge = require('lodash/merge') +const mergeOptions = require('merge-options') const crypto = require('libp2p-crypto') const DS = require('interface-datastore') -const pull = require('pull-stream') -const isString = require('lodash/isString') -const isSafeInteger = require('lodash/isSafeInteger') +const collect = require('pull-stream/sinks/collect') +const pull = require('pull-stream/pull') const CMS = require('./cms') const keyPrefix = '/pkcs8/' @@ -32,7 +31,7 @@ const defaultOptions = { function validateKeyName (name) { if (!name) return false - if (!isString(name)) return false + if (typeof name !== 'string') return false return name === sanitize(name.trim()) } @@ -107,8 +106,7 @@ class Keychain { } this.store = store - const opts = {} - deepmerge(opts, defaultOptions, options) + const opts = mergeOptions(defaultOptions, options) // Enforce NIST SP 800-132 if (!opts.passPhrase || opts.passPhrase.length < 20) { @@ -186,11 +184,11 @@ class Keychain { return _error(callback, `Invalid key name '${name}'`) } - if (!isString(type)) { + if (typeof type !== 'string') { return _error(callback, `Invalid key type '${type}'`) } - if (!isSafeInteger(size)) { + if (!Number.isSafeInteger(size)) { return _error(callback, `Invalid key size '${size}'`) } @@ -246,7 +244,7 @@ class Keychain { } pull( self.store.query(query), - pull.collect((err, res) => { + collect((err, res) => { if (err) return _error(callback, err) const info = res.map(r => JSON.parse(r.value)) diff --git a/src/util.js b/src/util.js index 9aa248f..bc61c5b 100644 --- a/src/util.js +++ b/src/util.js @@ -1,6 +1,7 @@ 'use strict' -const forge = require('node-forge') +require('node-forge/lib/x509') +const forge = require('node-forge/lib/forge') const pki = forge.pki exports = module.exports diff --git a/test/browser.js b/test/browser.js index 374ce6d..0a37bed 100644 --- a/test/browser.js +++ b/test/browser.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ 'use strict' -const async = require('async') +const series = require('async/series') const LevelStore = require('datastore-level') describe('browser', () => { @@ -9,14 +9,14 @@ describe('browser', () => { const datastore2 = new LevelStore('test-keystore-2', { db: require('level-js') }) before((done) => { - async.series([ + series([ (cb) => datastore1.open(cb), (cb) => datastore2.open(cb) ], done) }) after((done) => { - async.series([ + series([ (cb) => datastore1.close(cb), (cb) => datastore2.close(cb) ], done) diff --git a/test/node.js b/test/node.js index 6ca293e..e11d074 100644 --- a/test/node.js +++ b/test/node.js @@ -4,7 +4,7 @@ const os = require('os') const path = require('path') const rimraf = require('rimraf') -const async = require('async') +const series = require('async/series') const FsStore = require('datastore-fs') describe('node', () => { @@ -14,14 +14,14 @@ describe('node', () => { const datastore2 = new FsStore(store2) before((done) => { - async.series([ + series([ (cb) => datastore1.open(cb), (cb) => datastore2.open(cb) ], done) }) after((done) => { - async.series([ + series([ (cb) => datastore1.close(cb), (cb) => datastore2.close(cb), (cb) => rimraf(store1, cb), From 2b33e3735007fc7006fca4896e31ab7d26bbf920 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Tue, 18 Dec 2018 10:19:51 +0000 Subject: [PATCH 2/4] fix: remove commented line --- src/cms.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cms.js b/src/cms.js index e3dac6f..90d7d85 100644 --- a/src/cms.js +++ b/src/cms.js @@ -4,7 +4,6 @@ const setImmediate = require('async/setImmediate') const series = require('async/series') const detect = require('async/detect') const waterfall = require('async/waterfall') -// const forge = require('node-forge') require('node-forge/lib/pkcs7') require('node-forge/lib/pbe') const forge = require('node-forge/lib/forge') From 87304e00e2196db20b511227591bc470e93d9cc7 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Tue, 18 Dec 2018 10:20:40 +0000 Subject: [PATCH 3/4] fix: fix semver --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e51311d..183fa81 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "interface-datastore": "~0.6.0", "libp2p-crypto": "libp2p/js-libp2p-crypto#feat/bundle-size", "merge-options": "^1.0.1", - "node-forge": "^0.7.6", + "node-forge": "~0.7.6", "pull-stream": "^3.6.8", "sanitize-filename": "^1.6.1" }, @@ -59,7 +59,7 @@ "dirty-chai": "^2.0.1", "level-js": "^4.0.0", "mocha": "^5.2.0", - "multihashes": "^0.4.14", + "multihashes": "~0.4.14", "peer-id": "~0.10.7", "rimraf": "^2.6.2" }, From 4f1b5f1997e683d810006a3aee72067543d2f89b Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Thu, 10 Jan 2019 10:54:52 +0000 Subject: [PATCH 4/4] chore: update deps --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 183fa81..3b97528 100644 --- a/package.json +++ b/package.json @@ -44,14 +44,14 @@ "dependencies": { "async": "^2.6.1", "interface-datastore": "~0.6.0", - "libp2p-crypto": "libp2p/js-libp2p-crypto#feat/bundle-size", + "libp2p-crypto": "~0.16.0", "merge-options": "^1.0.1", "node-forge": "~0.7.6", "pull-stream": "^3.6.8", "sanitize-filename": "^1.6.1" }, "devDependencies": { - "aegir": "github:ipfs/aegir#feat/make-exp-build-test-default", + "aegir": "^18.0.3", "chai": "^4.2.0", "chai-string": "^1.4.0", "datastore-fs": "~0.7.0", @@ -60,8 +60,8 @@ "level-js": "^4.0.0", "mocha": "^5.2.0", "multihashes": "~0.4.14", - "peer-id": "~0.10.7", - "rimraf": "^2.6.2" + "peer-id": "~0.12.2", + "rimraf": "^2.6.3" }, "contributors": [ "Alan Shaw ",