Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deprecation): use Buffer.from instead of constructor #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
node_modules/
.travis.yml
.gitignore
test.js
10 changes: 5 additions & 5 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,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()
Expand All @@ -87,7 +87,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
Expand All @@ -96,7 +96,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)
Expand All @@ -110,9 +110,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])
}
Expand Down
Loading