From be0e066d0b759af0f55a236011407024543af945 Mon Sep 17 00:00:00 2001 From: Colton Rushton Date: Tue, 2 Feb 2021 14:33:06 -0400 Subject: [PATCH] Update dependencies and fix Travis CI builds --- .gitignore | 1 + .npmignore | 3 +++ browser.js | 11 ++++++----- package.json | 9 +++++---- 4 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bca51b3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/.npmignore b/.npmignore index daa6029..7295430 100644 --- a/.npmignore +++ b/.npmignore @@ -1 +1,4 @@ +node_modules/ +.travis.yml +.gitignore test.js diff --git a/browser.js b/browser.js index 3613b45..011329d 100644 --- a/browser.js +++ b/browser.js @@ -1,5 +1,6 @@ var elliptic = require('elliptic') var BN = require('bn.js') +var Buffer = require('safe-buffer').Buffer module.exports = function createECDH (curve) { return new ECDH(curve) @@ -61,7 +62,7 @@ ECDH.prototype.generateKeys = function (enc, format) { ECDH.prototype.computeSecret = function (other, inenc, enc) { inenc = inenc || 'utf8' if (!Buffer.isBuffer(other)) { - other = new Buffer(other, inenc) + other = Buffer.from(other, inenc) } var otherPub = this.curve.keyFromPublic(other).getPublic() var out = otherPub.mul(this.keys.getPrivate()).getX() @@ -87,7 +88,7 @@ ECDH.prototype.getPrivateKey = function (enc) { ECDH.prototype.setPublicKey = function (pub, enc) { enc = enc || 'utf8' if (!Buffer.isBuffer(pub)) { - pub = new Buffer(pub, enc) + pub = Buffer.from(pub, enc) } this.keys._importPublic(pub) return this @@ -96,7 +97,7 @@ ECDH.prototype.setPublicKey = function (pub, enc) { ECDH.prototype.setPrivateKey = function (priv, enc) { enc = enc || 'utf8' if (!Buffer.isBuffer(priv)) { - priv = new Buffer(priv, enc) + priv = Buffer.from(priv, enc) } var _priv = new BN(priv) @@ -110,9 +111,9 @@ function formatReturnValue (bn, enc, len) { if (!Array.isArray(bn)) { bn = bn.toArray() } - var buf = new Buffer(bn) + var buf = Buffer.from(bn) if (len && buf.length < len) { - var zeros = new Buffer(len - buf.length) + var zeros = Buffer.alloc(len - buf.length) zeros.fill(0) buf = Buffer.concat([zeros, buf]) } diff --git a/package.json b/package.json index 9ef2ca7..c23e0bb 100644 --- a/package.json +++ b/package.json @@ -24,12 +24,13 @@ }, "homepage": "https://github.com/crypto-browserify/createECDH", "dependencies": { - "bn.js": "^4.1.0", - "elliptic": "^6.5.3" + "bn.js": "^5.1.3", + "elliptic": "^6.5.4", + "safe-buffer": "^5.2.1" }, "devDependencies": { - "tap-spec": "^1.0.1", - "tape": "^3.0.1", + "tap-spec": "^5.0.0", + "tape": "^5.1.1", "standard": "^5.4.1" } }