Skip to content

Commit

Permalink
Merge pull request #58 from axic/patch/use-bn-iszero
Browse files Browse the repository at this point in the history
Use BN.isZero() in the elliptic wrapper
  • Loading branch information
wanderer committed Jan 14, 2016
2 parents 9df019c + 6a29185 commit 60c7958
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/elliptic/publickey.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ exports.publicKeyTweakMul = function (publicKey, tweak) {
}

tweak = new BN(tweak)
if (util.isOverflow(tweak) || util.isZero(tweak)) {
if (util.isOverflow(tweak) || tweak.isZero()) {
throw new Error(messages.EC_PUBKEY_TWEAK_MUL_FAIL)
}

Expand Down
4 changes: 2 additions & 2 deletions lib/elliptic/secretkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ exports.secretKeyTweakAdd = function (secretKey, tweak) {
}

bn = util.bnReduce(bn.iadd(new BN(secretKey)))
if (util.isZero(bn)) {
if (bn.isZero()) {
throw new Error(messages.EC_PRIVKEY_TWEAK_ADD_FAIL)
}

Expand All @@ -187,7 +187,7 @@ exports.secretKeyTweakMul = function (secretKey, tweak) {
asserts.checkBufferLength(tweak, 32, messages.TWEAK_LENGTH_INVALID)

var bn = new BN(tweak)
if (util.isOverflow(bn) || util.isZero(bn)) {
if (util.isOverflow(bn) || bn.isZero()) {
throw new Error(messages.EC_PRIVKEY_TWEAK_MUL_FAIL)
}

Expand Down
12 changes: 1 addition & 11 deletions lib/elliptic/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ var BN = require('bn.js')

var ec = require('./ec')

var ZERO = new BN(0)

/**
* @param {Buffer} secretKey
* @return {boolean}
*/
exports.isValidSecretKey = function (secretKey) {
var bn = new BN(secretKey)
return !exports.isOverflow(bn) && !exports.isZero(bn)
return !exports.isOverflow(bn) && !bn.isZero()
}

/**
Expand Down Expand Up @@ -65,14 +63,6 @@ exports.isOverflow = function (bn) {
return bn.cmp(ec.curve.n) >= 0
}

/**
* @param {BN} bn
* @return {boolean}
*/
exports.isZero = function (bn) {
return bn.cmp(ZERO) === 0
}

/**
* @param {BN} bn
* @return {BN}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"dependencies": {
"bindings": "^1.2.1",
"bluebird": "^3.0.2",
"bn.js": "^4.2.0",
"bn.js": "^4.5.0",
"elliptic": "^6.0.2",
"nan": "^2.0.9",
"object-assign": "^4.0.1"
Expand Down

0 comments on commit 60c7958

Please sign in to comment.