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
Changes from 1 commit
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
Next Next commit
fix(deprecation): use Buffer.from instead of constructor
  • Loading branch information
distolma committed Aug 7, 2019
commit 214c0a42ace9bcbb0379bdde4eca771a7d4b34e5
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